1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/kthread.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/sched/clock.h>
34 #include <linux/ctype.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/irq.h>
40 #include <linux/bitops.h>
41 #include <linux/crash_dump.h>
42 #include <linux/cpu.h>
43 #include <linux/cpuhotplug.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_device.h>
47 #include <scsi/scsi_host.h>
48 #include <scsi/scsi_transport_fc.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/fc/fc_fs.h>
55 #include "lpfc_sli4.h"
57 #include "lpfc_disc.h"
59 #include "lpfc_scsi.h"
60 #include "lpfc_nvme.h"
61 #include "lpfc_logmsg.h"
62 #include "lpfc_crtn.h"
63 #include "lpfc_vport.h"
64 #include "lpfc_version.h"
67 static enum cpuhp_state lpfc_cpuhp_state;
68 /* Used when mapping IRQ vectors in a driver centric manner */
69 static uint32_t lpfc_present_cpu;
70 static bool lpfc_pldv_detect;
72 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
73 static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
74 static void lpfc_cpuhp_add(struct lpfc_hba *phba);
75 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
76 static int lpfc_post_rcv_buf(struct lpfc_hba *);
77 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
78 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
79 static int lpfc_setup_endian_order(struct lpfc_hba *);
80 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
81 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
82 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
83 static void lpfc_init_sgl_list(struct lpfc_hba *);
84 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
85 static void lpfc_free_active_sgl(struct lpfc_hba *);
86 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
87 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
88 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
89 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
90 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
91 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
92 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
93 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
94 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
95 static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
96 static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
97 static void lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba);
98 static void lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba);
100 static struct scsi_transport_template *lpfc_transport_template = NULL;
101 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
102 static DEFINE_IDR(lpfc_hba_index);
103 #define LPFC_NVMET_BUF_POST 254
104 static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
105 static void lpfc_cgn_update_tstamp(struct lpfc_hba *phba, struct lpfc_cgn_ts *ts);
108 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
109 * @phba: pointer to lpfc hba data structure.
111 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
112 * mailbox command. It retrieves the revision information from the HBA and
113 * collects the Vital Product Data (VPD) about the HBA for preparing the
114 * configuration of the HBA.
118 * -ERESTART - requests the SLI layer to reset the HBA and try again.
119 * Any other value - indicates an error.
122 lpfc_config_port_prep(struct lpfc_hba *phba)
124 lpfc_vpd_t *vp = &phba->vpd;
128 char *lpfc_vpd_data = NULL;
130 static char licensed[56] =
131 "key unlock for use with gnu public licensed code only\0";
132 static int init_key = 1;
134 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
136 phba->link_state = LPFC_HBA_ERROR;
141 phba->link_state = LPFC_INIT_MBX_CMDS;
143 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
145 uint32_t *ptext = (uint32_t *) licensed;
147 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
148 *ptext = cpu_to_be32(*ptext);
152 lpfc_read_nv(phba, pmb);
153 memset((char*)mb->un.varRDnvp.rsvd3, 0,
154 sizeof (mb->un.varRDnvp.rsvd3));
155 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
158 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
160 if (rc != MBX_SUCCESS) {
161 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
162 "0324 Config Port initialization "
163 "error, mbxCmd x%x READ_NVPARM, "
165 mb->mbxCommand, mb->mbxStatus);
166 mempool_free(pmb, phba->mbox_mem_pool);
169 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
171 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
176 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
177 * which was already set in lpfc_get_cfgparam()
179 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
181 /* Setup and issue mailbox READ REV command */
182 lpfc_read_rev(phba, pmb);
183 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
184 if (rc != MBX_SUCCESS) {
185 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
186 "0439 Adapter failed to init, mbxCmd x%x "
187 "READ_REV, mbxStatus x%x\n",
188 mb->mbxCommand, mb->mbxStatus);
189 mempool_free( pmb, phba->mbox_mem_pool);
195 * The value of rr must be 1 since the driver set the cv field to 1.
196 * This setting requires the FW to set all revision fields.
198 if (mb->un.varRdRev.rr == 0) {
200 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
201 "0440 Adapter failed to init, READ_REV has "
202 "missing revision information.\n");
203 mempool_free(pmb, phba->mbox_mem_pool);
207 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
208 mempool_free(pmb, phba->mbox_mem_pool);
212 /* Save information as VPD data */
214 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
215 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
216 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
217 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
218 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
219 vp->rev.biuRev = mb->un.varRdRev.biuRev;
220 vp->rev.smRev = mb->un.varRdRev.smRev;
221 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
222 vp->rev.endecRev = mb->un.varRdRev.endecRev;
223 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
224 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
225 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
226 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
227 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
228 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
230 /* If the sli feature level is less then 9, we must
231 * tear down all RPIs and VPIs on link down if NPIV
234 if (vp->rev.feaLevelHigh < 9)
235 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
237 if (lpfc_is_LC_HBA(phba->pcidev->device))
238 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
239 sizeof (phba->RandomData));
241 /* Get adapter VPD information */
242 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
246 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
247 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
249 if (rc != MBX_SUCCESS) {
250 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
251 "0441 VPD not present on adapter, "
252 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
253 mb->mbxCommand, mb->mbxStatus);
254 mb->un.varDmp.word_cnt = 0;
256 /* dump mem may return a zero when finished or we got a
257 * mailbox error, either way we are done.
259 if (mb->un.varDmp.word_cnt == 0)
262 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
263 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
264 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
265 lpfc_vpd_data + offset,
266 mb->un.varDmp.word_cnt);
267 offset += mb->un.varDmp.word_cnt;
268 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
270 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
272 kfree(lpfc_vpd_data);
274 mempool_free(pmb, phba->mbox_mem_pool);
279 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
280 * @phba: pointer to lpfc hba data structure.
281 * @pmboxq: pointer to the driver internal queue element for mailbox command.
283 * This is the completion handler for driver's configuring asynchronous event
284 * mailbox command to the device. If the mailbox command returns successfully,
285 * it will set internal async event support flag to 1; otherwise, it will
286 * set internal async event support flag to 0.
289 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
291 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
292 phba->temp_sensor_support = 1;
294 phba->temp_sensor_support = 0;
295 mempool_free(pmboxq, phba->mbox_mem_pool);
300 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
301 * @phba: pointer to lpfc hba data structure.
302 * @pmboxq: pointer to the driver internal queue element for mailbox command.
304 * This is the completion handler for dump mailbox command for getting
305 * wake up parameters. When this command complete, the response contain
306 * Option rom version of the HBA. This function translate the version number
307 * into a human readable string and store it in OptionROMVersion.
310 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
313 uint32_t prog_id_word;
315 /* character array used for decoding dist type. */
316 char dist_char[] = "nabx";
318 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
319 mempool_free(pmboxq, phba->mbox_mem_pool);
323 prg = (struct prog_id *) &prog_id_word;
325 /* word 7 contain option rom version */
326 prog_id_word = pmboxq->u.mb.un.varWords[7];
328 /* Decode the Option rom version word to a readable string */
329 dist = dist_char[prg->dist];
331 if ((prg->dist == 3) && (prg->num == 0))
332 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
333 prg->ver, prg->rev, prg->lev);
335 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
336 prg->ver, prg->rev, prg->lev,
338 mempool_free(pmboxq, phba->mbox_mem_pool);
343 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
344 * @vport: pointer to lpfc vport data structure.
351 lpfc_update_vport_wwn(struct lpfc_vport *vport)
353 struct lpfc_hba *phba = vport->phba;
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
359 if (vport->fc_nodename.u.wwn[0] == 0)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
367 * If the port name has changed, then set the Param changes flag
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name))) {
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
375 if (phba->sli_rev == LPFC_SLI_REV4 &&
376 vport->port_type == LPFC_PHYSICAL_PORT &&
377 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_FABRIC) {
378 if (!(phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG))
379 phba->sli4_hba.fawwpn_flag &=
381 lpfc_printf_log(phba, KERN_INFO,
382 LOG_SLI | LOG_DISCOVERY | LOG_ELS,
383 "2701 FA-PWWN change WWPN from %llx to "
384 "%llx: vflag x%x fawwpn_flag x%x\n",
385 wwn_to_u64(vport->fc_portname.u.wwn),
387 (vport->fc_sparam.portName.u.wwn),
389 phba->sli4_hba.fawwpn_flag);
390 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
391 sizeof(struct lpfc_name));
395 if (vport->fc_portname.u.wwn[0] == 0)
396 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
397 sizeof(struct lpfc_name));
399 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
400 sizeof(struct lpfc_name));
404 * lpfc_config_port_post - Perform lpfc initialization after config port
405 * @phba: pointer to lpfc hba data structure.
407 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
408 * command call. It performs all internal resource and state setups on the
409 * port: post IOCB buffers, enable appropriate host interrupt attentions,
410 * ELS ring timers, etc.
414 * Any other value - error.
417 lpfc_config_port_post(struct lpfc_hba *phba)
419 struct lpfc_vport *vport = phba->pport;
420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
423 struct lpfc_dmabuf *mp;
424 struct lpfc_sli *psli = &phba->sli;
425 uint32_t status, timeout;
429 spin_lock_irq(&phba->hbalock);
431 * If the Config port completed correctly the HBA is not
432 * over heated any more.
434 if (phba->over_temp_state == HBA_OVER_TEMP)
435 phba->over_temp_state = HBA_NORMAL_TEMP;
436 spin_unlock_irq(&phba->hbalock);
438 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
440 phba->link_state = LPFC_HBA_ERROR;
445 /* Get login parameters for NID. */
446 rc = lpfc_read_sparam(phba, pmb, 0);
448 mempool_free(pmb, phba->mbox_mem_pool);
453 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
454 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
455 "0448 Adapter failed init, mbxCmd x%x "
456 "READ_SPARM mbxStatus x%x\n",
457 mb->mbxCommand, mb->mbxStatus);
458 phba->link_state = LPFC_HBA_ERROR;
459 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
465 /* This dmabuf was allocated by lpfc_read_sparam. The dmabuf is no
466 * longer needed. Prevent unintended ctx_buf access as the mbox is
469 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
470 lpfc_mbuf_free(phba, mp->virt, mp->phys);
473 lpfc_update_vport_wwn(vport);
475 /* Update the fc_host data structures with new wwn. */
476 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
477 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
478 fc_host_max_npiv_vports(shost) = phba->max_vpi;
480 /* If no serial number in VPD data, use low 6 bytes of WWNN */
481 /* This should be consolidated into parse_vpd ? - mr */
482 if (phba->SerialNumber[0] == 0) {
485 outptr = &vport->fc_nodename.u.s.IEEE[0];
486 for (i = 0; i < 12; i++) {
488 j = ((status & 0xf0) >> 4);
490 phba->SerialNumber[i] =
491 (char)((uint8_t) 0x30 + (uint8_t) j);
493 phba->SerialNumber[i] =
494 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
498 phba->SerialNumber[i] =
499 (char)((uint8_t) 0x30 + (uint8_t) j);
501 phba->SerialNumber[i] =
502 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
506 lpfc_read_config(phba, pmb);
508 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
509 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
510 "0453 Adapter failed to init, mbxCmd x%x "
511 "READ_CONFIG, mbxStatus x%x\n",
512 mb->mbxCommand, mb->mbxStatus);
513 phba->link_state = LPFC_HBA_ERROR;
514 mempool_free( pmb, phba->mbox_mem_pool);
518 /* Check if the port is disabled */
519 lpfc_sli_read_link_ste(phba);
521 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
522 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
523 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
524 "3359 HBA queue depth changed from %d to %d\n",
525 phba->cfg_hba_queue_depth,
526 mb->un.varRdConfig.max_xri);
527 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
530 phba->lmt = mb->un.varRdConfig.lmt;
532 /* Get the default values for Model Name and Description */
533 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
535 phba->link_state = LPFC_LINK_DOWN;
537 /* Only process IOCBs on ELS ring till hba_state is READY */
538 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
539 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
540 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
541 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
543 /* Post receive buffers for desired rings */
544 if (phba->sli_rev != 3)
545 lpfc_post_rcv_buf(phba);
548 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
550 if (phba->intr_type == MSIX) {
551 rc = lpfc_config_msi(phba, pmb);
553 mempool_free(pmb, phba->mbox_mem_pool);
556 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
557 if (rc != MBX_SUCCESS) {
558 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
559 "0352 Config MSI mailbox command "
560 "failed, mbxCmd x%x, mbxStatus x%x\n",
561 pmb->u.mb.mbxCommand,
562 pmb->u.mb.mbxStatus);
563 mempool_free(pmb, phba->mbox_mem_pool);
568 spin_lock_irq(&phba->hbalock);
569 /* Initialize ERATT handling flag */
570 clear_bit(HBA_ERATT_HANDLED, &phba->hba_flag);
572 /* Enable appropriate host interrupts */
573 if (lpfc_readl(phba->HCregaddr, &status)) {
574 spin_unlock_irq(&phba->hbalock);
577 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
578 if (psli->num_rings > 0)
579 status |= HC_R0INT_ENA;
580 if (psli->num_rings > 1)
581 status |= HC_R1INT_ENA;
582 if (psli->num_rings > 2)
583 status |= HC_R2INT_ENA;
584 if (psli->num_rings > 3)
585 status |= HC_R3INT_ENA;
587 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
588 (phba->cfg_poll & DISABLE_FCP_RING_INT))
589 status &= ~(HC_R0INT_ENA);
591 writel(status, phba->HCregaddr);
592 readl(phba->HCregaddr); /* flush */
593 spin_unlock_irq(&phba->hbalock);
595 /* Set up ring-0 (ELS) timer */
596 timeout = phba->fc_ratov * 2;
597 mod_timer(&vport->els_tmofunc,
598 jiffies + msecs_to_jiffies(1000 * timeout));
599 /* Set up heart beat (HB) timer */
600 mod_timer(&phba->hb_tmofunc,
601 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
602 clear_bit(HBA_HBEAT_INP, &phba->hba_flag);
603 clear_bit(HBA_HBEAT_TMO, &phba->hba_flag);
604 phba->last_completion_time = jiffies;
605 /* Set up error attention (ERATT) polling timer */
606 mod_timer(&phba->eratt_poll,
607 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
609 if (test_bit(LINK_DISABLED, &phba->hba_flag)) {
610 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
611 "2598 Adapter Link is disabled.\n");
612 lpfc_down_link(phba, pmb);
613 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
614 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
615 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
616 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
617 "2599 Adapter failed to issue DOWN_LINK"
618 " mbox command rc 0x%x\n", rc);
620 mempool_free(pmb, phba->mbox_mem_pool);
623 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
624 mempool_free(pmb, phba->mbox_mem_pool);
625 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
629 /* MBOX buffer will be freed in mbox compl */
630 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
632 phba->link_state = LPFC_HBA_ERROR;
636 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
637 pmb->mbox_cmpl = lpfc_config_async_cmpl;
638 pmb->vport = phba->pport;
639 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
641 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
642 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
643 "0456 Adapter failed to issue "
644 "ASYNCEVT_ENABLE mbox status x%x\n",
646 mempool_free(pmb, phba->mbox_mem_pool);
649 /* Get Option rom version */
650 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
652 phba->link_state = LPFC_HBA_ERROR;
656 lpfc_dump_wakeup_param(phba, pmb);
657 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
658 pmb->vport = phba->pport;
659 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
661 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
663 "0435 Adapter failed "
664 "to get Option ROM version status x%x\n", rc);
665 mempool_free(pmb, phba->mbox_mem_pool);
672 * lpfc_sli4_refresh_params - update driver copy of params.
673 * @phba: Pointer to HBA context object.
675 * This is called to refresh driver copy of dynamic fields from the
676 * common_get_sli4_parameters descriptor.
679 lpfc_sli4_refresh_params(struct lpfc_hba *phba)
682 struct lpfc_mqe *mqe;
683 struct lpfc_sli4_parameters *mbx_sli4_parameters;
686 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
691 /* Read the port's SLI4 Config Parameters */
692 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
693 sizeof(struct lpfc_sli4_cfg_mhdr));
694 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
695 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
696 length, LPFC_SLI4_MBX_EMBED);
698 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
700 mempool_free(mboxq, phba->mbox_mem_pool);
703 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
704 phba->sli4_hba.pc_sli4_params.mi_cap =
705 bf_get(cfg_mi_ver, mbx_sli4_parameters);
707 /* Are we forcing MI off via module parameter? */
708 if (phba->cfg_enable_mi)
709 phba->sli4_hba.pc_sli4_params.mi_ver =
710 bf_get(cfg_mi_ver, mbx_sli4_parameters);
712 phba->sli4_hba.pc_sli4_params.mi_ver = 0;
714 phba->sli4_hba.pc_sli4_params.cmf =
715 bf_get(cfg_cmf, mbx_sli4_parameters);
716 phba->sli4_hba.pc_sli4_params.pls =
717 bf_get(cfg_pvl, mbx_sli4_parameters);
719 mempool_free(mboxq, phba->mbox_mem_pool);
724 * lpfc_hba_init_link - Initialize the FC link
725 * @phba: pointer to lpfc hba data structure.
726 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
728 * This routine will issue the INIT_LINK mailbox command call.
729 * It is available to other drivers through the lpfc_hba data
730 * structure for use as a delayed link up mechanism with the
731 * module parameter lpfc_suppress_link_up.
735 * Any other value - error
738 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
740 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
744 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
745 * @phba: pointer to lpfc hba data structure.
746 * @fc_topology: desired fc topology.
747 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
749 * This routine will issue the INIT_LINK mailbox command call.
750 * It is available to other drivers through the lpfc_hba data
751 * structure for use as a delayed link up mechanism with the
752 * module parameter lpfc_suppress_link_up.
756 * Any other value - error
759 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
762 struct lpfc_vport *vport = phba->pport;
767 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
769 phba->link_state = LPFC_HBA_ERROR;
775 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
776 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
777 !(phba->lmt & LMT_1Gb)) ||
778 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
779 !(phba->lmt & LMT_2Gb)) ||
780 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
781 !(phba->lmt & LMT_4Gb)) ||
782 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
783 !(phba->lmt & LMT_8Gb)) ||
784 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
785 !(phba->lmt & LMT_10Gb)) ||
786 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
787 !(phba->lmt & LMT_16Gb)) ||
788 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
789 !(phba->lmt & LMT_32Gb)) ||
790 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
791 !(phba->lmt & LMT_64Gb))) {
792 /* Reset link speed to auto */
793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
794 "1302 Invalid speed for this board:%d "
795 "Reset link speed to auto.\n",
796 phba->cfg_link_speed);
797 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
799 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
800 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
801 if (phba->sli_rev < LPFC_SLI_REV4)
802 lpfc_set_loopback_flag(phba);
803 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
804 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
805 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
806 "0498 Adapter failed to init, mbxCmd x%x "
807 "INIT_LINK, mbxStatus x%x\n",
808 mb->mbxCommand, mb->mbxStatus);
809 if (phba->sli_rev <= LPFC_SLI_REV3) {
810 /* Clear all interrupt enable conditions */
811 writel(0, phba->HCregaddr);
812 readl(phba->HCregaddr); /* flush */
813 /* Clear all pending interrupts */
814 writel(0xffffffff, phba->HAregaddr);
815 readl(phba->HAregaddr); /* flush */
817 phba->link_state = LPFC_HBA_ERROR;
818 if (rc != MBX_BUSY || flag == MBX_POLL)
819 mempool_free(pmb, phba->mbox_mem_pool);
822 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
823 if (flag == MBX_POLL)
824 mempool_free(pmb, phba->mbox_mem_pool);
830 * lpfc_hba_down_link - this routine downs the FC link
831 * @phba: pointer to lpfc hba data structure.
832 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
834 * This routine will issue the DOWN_LINK mailbox command call.
835 * It is available to other drivers through the lpfc_hba data
836 * structure for use to stop the link.
840 * Any other value - error
843 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
848 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
850 phba->link_state = LPFC_HBA_ERROR;
854 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
855 "0491 Adapter Link is disabled.\n");
856 lpfc_down_link(phba, pmb);
857 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
858 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
859 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
860 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
861 "2522 Adapter failed to issue DOWN_LINK"
862 " mbox command rc 0x%x\n", rc);
864 mempool_free(pmb, phba->mbox_mem_pool);
867 if (flag == MBX_POLL)
868 mempool_free(pmb, phba->mbox_mem_pool);
874 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
875 * @phba: pointer to lpfc HBA data structure.
877 * This routine will do LPFC uninitialization before the HBA is reset when
878 * bringing down the SLI Layer.
882 * Any other value - error.
885 lpfc_hba_down_prep(struct lpfc_hba *phba)
887 struct lpfc_vport **vports;
890 if (phba->sli_rev <= LPFC_SLI_REV3) {
891 /* Disable interrupts */
892 writel(0, phba->HCregaddr);
893 readl(phba->HCregaddr); /* flush */
896 if (test_bit(FC_UNLOADING, &phba->pport->load_flag))
897 lpfc_cleanup_discovery_resources(phba->pport);
899 vports = lpfc_create_vport_work_array(phba);
901 for (i = 0; i <= phba->max_vports &&
902 vports[i] != NULL; i++)
903 lpfc_cleanup_discovery_resources(vports[i]);
904 lpfc_destroy_vport_work_array(phba, vports);
910 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
911 * rspiocb which got deferred
913 * @phba: pointer to lpfc HBA data structure.
915 * This routine will cleanup completed slow path events after HBA is reset
916 * when bringing down the SLI Layer.
923 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
925 struct lpfc_iocbq *rspiocbq;
926 struct hbq_dmabuf *dmabuf;
927 struct lpfc_cq_event *cq_event;
929 clear_bit(HBA_SP_QUEUE_EVT, &phba->hba_flag);
931 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
932 /* Get the response iocb from the head of work queue */
933 spin_lock_irq(&phba->hbalock);
934 list_remove_head(&phba->sli4_hba.sp_queue_event,
935 cq_event, struct lpfc_cq_event, list);
936 spin_unlock_irq(&phba->hbalock);
938 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
939 case CQE_CODE_COMPL_WQE:
940 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
942 lpfc_sli_release_iocbq(phba, rspiocbq);
944 case CQE_CODE_RECEIVE:
945 case CQE_CODE_RECEIVE_V1:
946 dmabuf = container_of(cq_event, struct hbq_dmabuf,
948 lpfc_in_buf_free(phba, &dmabuf->dbuf);
954 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
955 * @phba: pointer to lpfc HBA data structure.
957 * This routine will cleanup posted ELS buffers after the HBA is reset
958 * when bringing down the SLI Layer.
965 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
967 struct lpfc_sli *psli = &phba->sli;
968 struct lpfc_sli_ring *pring;
969 struct lpfc_dmabuf *mp, *next_mp;
973 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
974 lpfc_sli_hbqbuf_free_all(phba);
976 /* Cleanup preposted buffers on the ELS ring */
977 pring = &psli->sli3_ring[LPFC_ELS_RING];
978 spin_lock_irq(&phba->hbalock);
979 list_splice_init(&pring->postbufq, &buflist);
980 spin_unlock_irq(&phba->hbalock);
983 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
986 lpfc_mbuf_free(phba, mp->virt, mp->phys);
990 spin_lock_irq(&phba->hbalock);
991 pring->postbufq_cnt -= count;
992 spin_unlock_irq(&phba->hbalock);
997 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
998 * @phba: pointer to lpfc HBA data structure.
1000 * This routine will cleanup the txcmplq after the HBA is reset when bringing
1001 * down the SLI Layer.
1007 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
1009 struct lpfc_sli *psli = &phba->sli;
1010 struct lpfc_queue *qp = NULL;
1011 struct lpfc_sli_ring *pring;
1012 LIST_HEAD(completions);
1014 struct lpfc_iocbq *piocb, *next_iocb;
1016 if (phba->sli_rev != LPFC_SLI_REV4) {
1017 for (i = 0; i < psli->num_rings; i++) {
1018 pring = &psli->sli3_ring[i];
1019 spin_lock_irq(&phba->hbalock);
1020 /* At this point in time the HBA is either reset or DOA
1021 * Nothing should be on txcmplq as it will
1024 list_splice_init(&pring->txcmplq, &completions);
1025 pring->txcmplq_cnt = 0;
1026 spin_unlock_irq(&phba->hbalock);
1028 lpfc_sli_abort_iocb_ring(phba, pring);
1030 /* Cancel all the IOCBs from the completions list */
1031 lpfc_sli_cancel_iocbs(phba, &completions,
1032 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1035 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1039 spin_lock_irq(&pring->ring_lock);
1040 list_for_each_entry_safe(piocb, next_iocb,
1041 &pring->txcmplq, list)
1042 piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
1043 list_splice_init(&pring->txcmplq, &completions);
1044 pring->txcmplq_cnt = 0;
1045 spin_unlock_irq(&pring->ring_lock);
1046 lpfc_sli_abort_iocb_ring(phba, pring);
1048 /* Cancel all the IOCBs from the completions list */
1049 lpfc_sli_cancel_iocbs(phba, &completions,
1050 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1054 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1055 * @phba: pointer to lpfc HBA data structure.
1057 * This routine will do uninitialization after the HBA is reset when bring
1058 * down the SLI Layer.
1062 * Any other value - error.
1065 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1067 lpfc_hba_free_post_buf(phba);
1068 lpfc_hba_clean_txcmplq(phba);
1073 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1074 * @phba: pointer to lpfc HBA data structure.
1076 * This routine will do uninitialization after the HBA is reset when bring
1077 * down the SLI Layer.
1081 * Any other value - error.
1084 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1086 struct lpfc_io_buf *psb, *psb_next;
1087 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
1088 struct lpfc_sli4_hdw_queue *qp;
1090 LIST_HEAD(nvme_aborts);
1091 LIST_HEAD(nvmet_aborts);
1092 struct lpfc_sglq *sglq_entry = NULL;
1096 lpfc_sli_hbqbuf_free_all(phba);
1097 lpfc_hba_clean_txcmplq(phba);
1099 /* At this point in time the HBA is either reset or DOA. Either
1100 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1101 * on the lpfc_els_sgl_list so that it can either be freed if the
1102 * driver is unloading or reposted if the driver is restarting
1106 /* sgl_list_lock required because worker thread uses this
1109 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
1110 list_for_each_entry(sglq_entry,
1111 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1112 sglq_entry->state = SGL_FREED;
1114 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1115 &phba->sli4_hba.lpfc_els_sgl_list);
1118 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
1120 /* abts_xxxx_buf_list_lock required because worker thread uses this
1123 spin_lock_irq(&phba->hbalock);
1125 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1126 qp = &phba->sli4_hba.hdwq[idx];
1128 spin_lock(&qp->abts_io_buf_list_lock);
1129 list_splice_init(&qp->lpfc_abts_io_buf_list,
1132 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1134 psb->status = IOSTAT_SUCCESS;
1137 spin_lock(&qp->io_buf_list_put_lock);
1138 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1139 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1140 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1141 qp->abts_scsi_io_bufs = 0;
1142 qp->abts_nvme_io_bufs = 0;
1143 spin_unlock(&qp->io_buf_list_put_lock);
1144 spin_unlock(&qp->abts_io_buf_list_lock);
1146 spin_unlock_irq(&phba->hbalock);
1148 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1149 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1150 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1152 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1153 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1154 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
1155 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1159 lpfc_sli4_free_sp_events(phba);
1164 * lpfc_hba_down_post - Wrapper func for hba down post routine
1165 * @phba: pointer to lpfc HBA data structure.
1167 * This routine wraps the actual SLI3 or SLI4 routine for performing
1168 * uninitialization after the HBA is reset when bring down the SLI Layer.
1172 * Any other value - error.
1175 lpfc_hba_down_post(struct lpfc_hba *phba)
1177 return (*phba->lpfc_hba_down_post)(phba);
1181 * lpfc_hb_timeout - The HBA-timer timeout handler
1182 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1184 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1185 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1186 * work-port-events bitmap and the worker thread is notified. This timeout
1187 * event will be used by the worker thread to invoke the actual timeout
1188 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1189 * be performed in the timeout handler and the HBA timeout event bit shall
1190 * be cleared by the worker thread after it has taken the event bitmap out.
1193 lpfc_hb_timeout(struct timer_list *t)
1195 struct lpfc_hba *phba;
1196 uint32_t tmo_posted;
1197 unsigned long iflag;
1199 phba = from_timer(phba, t, hb_tmofunc);
1201 /* Check for heart beat timeout conditions */
1202 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1203 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1205 phba->pport->work_port_events |= WORKER_HB_TMO;
1206 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1208 /* Tell the worker thread there is work to do */
1210 lpfc_worker_wake_up(phba);
1215 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1216 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1218 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1219 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1220 * work-port-events bitmap and the worker thread is notified. This timeout
1221 * event will be used by the worker thread to invoke the actual timeout
1222 * handler routine, lpfc_rrq_handler. Any periodical operations will
1223 * be performed in the timeout handler and the RRQ timeout event bit shall
1224 * be cleared by the worker thread after it has taken the event bitmap out.
1227 lpfc_rrq_timeout(struct timer_list *t)
1229 struct lpfc_hba *phba;
1231 phba = from_timer(phba, t, rrq_tmr);
1232 if (test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
1233 clear_bit(HBA_RRQ_ACTIVE, &phba->hba_flag);
1237 set_bit(HBA_RRQ_ACTIVE, &phba->hba_flag);
1238 lpfc_worker_wake_up(phba);
1242 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1243 * @phba: pointer to lpfc hba data structure.
1244 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1246 * This is the callback function to the lpfc heart-beat mailbox command.
1247 * If configured, the lpfc driver issues the heart-beat mailbox command to
1248 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1249 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1250 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1251 * heart-beat outstanding state. Once the mailbox command comes back and
1252 * no error conditions detected, the heart-beat mailbox command timer is
1253 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1254 * state is cleared for the next heart-beat. If the timer expired with the
1255 * heart-beat outstanding state set, the driver will put the HBA offline.
1258 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1260 clear_bit(HBA_HBEAT_INP, &phba->hba_flag);
1261 clear_bit(HBA_HBEAT_TMO, &phba->hba_flag);
1263 /* Check and reset heart-beat timer if necessary */
1264 mempool_free(pmboxq, phba->mbox_mem_pool);
1265 if (!test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag) &&
1266 !(phba->link_state == LPFC_HBA_ERROR) &&
1267 !test_bit(FC_UNLOADING, &phba->pport->load_flag))
1268 mod_timer(&phba->hb_tmofunc,
1270 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1275 * lpfc_idle_stat_delay_work - idle_stat tracking
1277 * This routine tracks per-eq idle_stat and determines polling decisions.
1283 lpfc_idle_stat_delay_work(struct work_struct *work)
1285 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1287 idle_stat_delay_work);
1288 struct lpfc_queue *eq;
1289 struct lpfc_sli4_hdw_queue *hdwq;
1290 struct lpfc_idle_stat *idle_stat;
1291 u32 i, idle_percent;
1292 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1294 if (test_bit(FC_UNLOADING, &phba->pport->load_flag))
1297 if (phba->link_state == LPFC_HBA_ERROR ||
1298 test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag) ||
1299 phba->cmf_active_mode != LPFC_CFG_OFF)
1302 for_each_present_cpu(i) {
1303 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1306 /* Skip if we've already handled this eq's primary CPU */
1310 idle_stat = &phba->sli4_hba.idle_stat[i];
1312 /* get_cpu_idle_time returns values as running counters. Thus,
1313 * to know the amount for this period, the prior counter values
1314 * need to be subtracted from the current counter values.
1315 * From there, the idle time stat can be calculated as a
1316 * percentage of 100 - the sum of the other consumption times.
1318 wall_idle = get_cpu_idle_time(i, &wall, 1);
1319 diff_idle = wall_idle - idle_stat->prev_idle;
1320 diff_wall = wall - idle_stat->prev_wall;
1322 if (diff_wall <= diff_idle)
1325 busy_time = diff_wall - diff_idle;
1327 idle_percent = div64_u64(100 * busy_time, diff_wall);
1328 idle_percent = 100 - idle_percent;
1330 if (idle_percent < 15)
1331 eq->poll_mode = LPFC_QUEUE_WORK;
1333 eq->poll_mode = LPFC_THREADED_IRQ;
1335 idle_stat->prev_idle = wall_idle;
1336 idle_stat->prev_wall = wall;
1340 schedule_delayed_work(&phba->idle_stat_delay_work,
1341 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1345 lpfc_hb_eq_delay_work(struct work_struct *work)
1347 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1348 struct lpfc_hba, eq_delay_work);
1349 struct lpfc_eq_intr_info *eqi, *eqi_new;
1350 struct lpfc_queue *eq, *eq_next;
1351 unsigned char *ena_delay = NULL;
1355 if (!phba->cfg_auto_imax ||
1356 test_bit(FC_UNLOADING, &phba->pport->load_flag))
1359 if (phba->link_state == LPFC_HBA_ERROR ||
1360 test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
1363 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1368 for (i = 0; i < phba->cfg_irq_chann; i++) {
1369 /* Get the EQ corresponding to the IRQ vector */
1370 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1373 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1374 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1375 ena_delay[eq->last_cpu] = 1;
1379 for_each_present_cpu(i) {
1380 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1382 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1383 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1384 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1391 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1392 if (unlikely(eq->last_cpu != i)) {
1393 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1395 list_move_tail(&eq->cpu_list, &eqi_new->list);
1398 if (usdelay != eq->q_mode)
1399 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1407 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1408 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1412 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1413 * @phba: pointer to lpfc hba data structure.
1415 * For each heartbeat, this routine does some heuristic methods to adjust
1416 * XRI distribution. The goal is to fully utilize free XRIs.
1418 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1423 hwq_count = phba->cfg_hdw_queue;
1424 for (i = 0; i < hwq_count; i++) {
1425 /* Adjust XRIs in private pool */
1426 lpfc_adjust_pvt_pool_count(phba, i);
1428 /* Adjust high watermark */
1429 lpfc_adjust_high_watermark(phba, i);
1431 #ifdef LPFC_MXP_STAT
1432 /* Snapshot pbl, pvt and busy count */
1433 lpfc_snapshot_mxp(phba, i);
1439 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1440 * @phba: pointer to lpfc hba data structure.
1442 * If a HB mbox is not already in progrees, this routine will allocate
1443 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1444 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1447 lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1449 LPFC_MBOXQ_t *pmboxq;
1452 /* Is a Heartbeat mbox already in progress */
1453 if (test_bit(HBA_HBEAT_INP, &phba->hba_flag))
1456 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1460 lpfc_heart_beat(phba, pmboxq);
1461 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1462 pmboxq->vport = phba->pport;
1463 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1465 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1466 mempool_free(pmboxq, phba->mbox_mem_pool);
1469 set_bit(HBA_HBEAT_INP, &phba->hba_flag);
1475 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1476 * @phba: pointer to lpfc hba data structure.
1478 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1479 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1480 * of the value of lpfc_enable_hba_heartbeat.
1481 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1482 * try to issue a MBX_HEARTBEAT mbox command.
1485 lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1487 if (phba->cfg_enable_hba_heartbeat)
1489 set_bit(HBA_HBEAT_TMO, &phba->hba_flag);
1493 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1494 * @phba: pointer to lpfc hba data structure.
1496 * This is the actual HBA-timer timeout handler to be invoked by the worker
1497 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1498 * handler performs any periodic operations needed for the device. If such
1499 * periodic event has already been attended to either in the interrupt handler
1500 * or by processing slow-ring or fast-ring events within the HBA-timer
1501 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1502 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1503 * is configured and there is no heart-beat mailbox command outstanding, a
1504 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1505 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1509 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1511 struct lpfc_vport **vports;
1512 struct lpfc_dmabuf *buf_ptr;
1515 struct lpfc_sli *psli = &phba->sli;
1516 LIST_HEAD(completions);
1518 if (phba->cfg_xri_rebalancing) {
1519 /* Multi-XRI pools handler */
1520 lpfc_hb_mxp_handler(phba);
1523 vports = lpfc_create_vport_work_array(phba);
1525 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1526 lpfc_rcv_seq_check_edtov(vports[i]);
1527 lpfc_fdmi_change_check(vports[i]);
1529 lpfc_destroy_vport_work_array(phba, vports);
1531 if (phba->link_state == LPFC_HBA_ERROR ||
1532 test_bit(FC_UNLOADING, &phba->pport->load_flag) ||
1533 test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
1536 if (phba->elsbuf_cnt &&
1537 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1538 spin_lock_irq(&phba->hbalock);
1539 list_splice_init(&phba->elsbuf, &completions);
1540 phba->elsbuf_cnt = 0;
1541 phba->elsbuf_prev_cnt = 0;
1542 spin_unlock_irq(&phba->hbalock);
1544 while (!list_empty(&completions)) {
1545 list_remove_head(&completions, buf_ptr,
1546 struct lpfc_dmabuf, list);
1547 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1551 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1553 /* If there is no heart beat outstanding, issue a heartbeat command */
1554 if (phba->cfg_enable_hba_heartbeat) {
1555 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1556 spin_lock_irq(&phba->pport->work_port_lock);
1557 if (time_after(phba->last_completion_time +
1558 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1560 spin_unlock_irq(&phba->pport->work_port_lock);
1561 if (test_bit(HBA_HBEAT_INP, &phba->hba_flag))
1562 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1564 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1567 spin_unlock_irq(&phba->pport->work_port_lock);
1569 /* Check if a MBX_HEARTBEAT is already in progress */
1570 if (test_bit(HBA_HBEAT_INP, &phba->hba_flag)) {
1572 * If heart beat timeout called with HBA_HBEAT_INP set
1573 * we need to give the hb mailbox cmd a chance to
1576 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1577 "0459 Adapter heartbeat still outstanding: "
1578 "last compl time was %d ms.\n",
1579 jiffies_to_msecs(jiffies
1580 - phba->last_completion_time));
1581 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1583 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1584 (list_empty(&psli->mboxq))) {
1586 retval = lpfc_issue_hb_mbox(phba);
1588 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1591 phba->skipped_hb = 0;
1592 } else if (time_before_eq(phba->last_completion_time,
1593 phba->skipped_hb)) {
1594 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1595 "2857 Last completion time not "
1596 " updated in %d ms\n",
1597 jiffies_to_msecs(jiffies
1598 - phba->last_completion_time));
1600 phba->skipped_hb = jiffies;
1602 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1606 /* Check to see if we want to force a MBX_HEARTBEAT */
1607 if (test_bit(HBA_HBEAT_TMO, &phba->hba_flag)) {
1608 retval = lpfc_issue_hb_mbox(phba);
1610 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1612 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1615 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1618 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
1622 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1623 * @phba: pointer to lpfc hba data structure.
1625 * This routine is called to bring the HBA offline when HBA hardware error
1626 * other than Port Error 6 has been detected.
1629 lpfc_offline_eratt(struct lpfc_hba *phba)
1631 struct lpfc_sli *psli = &phba->sli;
1633 spin_lock_irq(&phba->hbalock);
1634 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1635 spin_unlock_irq(&phba->hbalock);
1636 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1639 lpfc_reset_barrier(phba);
1640 spin_lock_irq(&phba->hbalock);
1641 lpfc_sli_brdreset(phba);
1642 spin_unlock_irq(&phba->hbalock);
1643 lpfc_hba_down_post(phba);
1644 lpfc_sli_brdready(phba, HS_MBRDY);
1645 lpfc_unblock_mgmt_io(phba);
1646 phba->link_state = LPFC_HBA_ERROR;
1651 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1652 * @phba: pointer to lpfc hba data structure.
1654 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1655 * other than Port Error 6 has been detected.
1658 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1660 spin_lock_irq(&phba->hbalock);
1661 if (phba->link_state == LPFC_HBA_ERROR &&
1662 test_bit(HBA_PCI_ERR, &phba->bit_flags)) {
1663 spin_unlock_irq(&phba->hbalock);
1666 phba->link_state = LPFC_HBA_ERROR;
1667 spin_unlock_irq(&phba->hbalock);
1669 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1670 lpfc_sli_flush_io_rings(phba);
1672 lpfc_hba_down_post(phba);
1673 lpfc_unblock_mgmt_io(phba);
1677 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1678 * @phba: pointer to lpfc hba data structure.
1680 * This routine is invoked to handle the deferred HBA hardware error
1681 * conditions. This type of error is indicated by HBA by setting ER1
1682 * and another ER bit in the host status register. The driver will
1683 * wait until the ER1 bit clears before handling the error condition.
1686 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1688 uint32_t old_host_status = phba->work_hs;
1689 struct lpfc_sli *psli = &phba->sli;
1691 /* If the pci channel is offline, ignore possible errors,
1692 * since we cannot communicate with the pci card anyway.
1694 if (pci_channel_offline(phba->pcidev)) {
1695 clear_bit(DEFER_ERATT, &phba->hba_flag);
1699 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1700 "0479 Deferred Adapter Hardware Error "
1701 "Data: x%x x%x x%x\n",
1702 phba->work_hs, phba->work_status[0],
1703 phba->work_status[1]);
1705 spin_lock_irq(&phba->hbalock);
1706 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1707 spin_unlock_irq(&phba->hbalock);
1711 * Firmware stops when it triggred erratt. That could cause the I/Os
1712 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1713 * SCSI layer retry it after re-establishing link.
1715 lpfc_sli_abort_fcp_rings(phba);
1718 * There was a firmware error. Take the hba offline and then
1719 * attempt to restart it.
1721 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1724 /* Wait for the ER1 bit to clear.*/
1725 while (phba->work_hs & HS_FFER1) {
1727 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1728 phba->work_hs = UNPLUG_ERR ;
1731 /* If driver is unloading let the worker thread continue */
1732 if (test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
1739 * This is to ptrotect against a race condition in which
1740 * first write to the host attention register clear the
1741 * host status register.
1743 if (!phba->work_hs && !test_bit(FC_UNLOADING, &phba->pport->load_flag))
1744 phba->work_hs = old_host_status & ~HS_FFER1;
1746 clear_bit(DEFER_ERATT, &phba->hba_flag);
1747 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1748 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1752 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1754 struct lpfc_board_event_header board_event;
1755 struct Scsi_Host *shost;
1757 board_event.event_type = FC_REG_BOARD_EVENT;
1758 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1759 shost = lpfc_shost_from_vport(phba->pport);
1760 fc_host_post_vendor_event(shost, fc_get_event_number(),
1761 sizeof(board_event),
1762 (char *) &board_event,
1767 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1768 * @phba: pointer to lpfc hba data structure.
1770 * This routine is invoked to handle the following HBA hardware error
1772 * 1 - HBA error attention interrupt
1773 * 2 - DMA ring index out of range
1774 * 3 - Mailbox command came back as unknown
1777 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1779 struct lpfc_vport *vport = phba->pport;
1780 struct lpfc_sli *psli = &phba->sli;
1781 uint32_t event_data;
1782 unsigned long temperature;
1783 struct temp_event temp_event_data;
1784 struct Scsi_Host *shost;
1786 /* If the pci channel is offline, ignore possible errors,
1787 * since we cannot communicate with the pci card anyway.
1789 if (pci_channel_offline(phba->pcidev)) {
1790 clear_bit(DEFER_ERATT, &phba->hba_flag);
1794 /* If resets are disabled then leave the HBA alone and return */
1795 if (!phba->cfg_enable_hba_reset)
1798 /* Send an internal error event to mgmt application */
1799 lpfc_board_errevt_to_mgmt(phba);
1801 if (test_bit(DEFER_ERATT, &phba->hba_flag))
1802 lpfc_handle_deferred_eratt(phba);
1804 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1805 if (phba->work_hs & HS_FFER6)
1806 /* Re-establishing Link */
1807 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1808 "1301 Re-establishing Link "
1809 "Data: x%x x%x x%x\n",
1810 phba->work_hs, phba->work_status[0],
1811 phba->work_status[1]);
1812 if (phba->work_hs & HS_FFER8)
1813 /* Device Zeroization */
1814 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1815 "2861 Host Authentication device "
1816 "zeroization Data:x%x x%x x%x\n",
1817 phba->work_hs, phba->work_status[0],
1818 phba->work_status[1]);
1820 spin_lock_irq(&phba->hbalock);
1821 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1822 spin_unlock_irq(&phba->hbalock);
1825 * Firmware stops when it triggled erratt with HS_FFER6.
1826 * That could cause the I/Os dropped by the firmware.
1827 * Error iocb (I/O) on txcmplq and let the SCSI layer
1828 * retry it after re-establishing link.
1830 lpfc_sli_abort_fcp_rings(phba);
1833 * There was a firmware error. Take the hba offline and then
1834 * attempt to restart it.
1836 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1838 lpfc_sli_brdrestart(phba);
1839 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1840 lpfc_unblock_mgmt_io(phba);
1843 lpfc_unblock_mgmt_io(phba);
1844 } else if (phba->work_hs & HS_CRIT_TEMP) {
1845 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1846 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1847 temp_event_data.event_code = LPFC_CRIT_TEMP;
1848 temp_event_data.data = (uint32_t)temperature;
1850 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1851 "0406 Adapter maximum temperature exceeded "
1852 "(%ld), taking this port offline "
1853 "Data: x%x x%x x%x\n",
1854 temperature, phba->work_hs,
1855 phba->work_status[0], phba->work_status[1]);
1857 shost = lpfc_shost_from_vport(phba->pport);
1858 fc_host_post_vendor_event(shost, fc_get_event_number(),
1859 sizeof(temp_event_data),
1860 (char *) &temp_event_data,
1861 SCSI_NL_VID_TYPE_PCI
1862 | PCI_VENDOR_ID_EMULEX);
1864 spin_lock_irq(&phba->hbalock);
1865 phba->over_temp_state = HBA_OVER_TEMP;
1866 spin_unlock_irq(&phba->hbalock);
1867 lpfc_offline_eratt(phba);
1870 /* The if clause above forces this code path when the status
1871 * failure is a value other than FFER6. Do not call the offline
1872 * twice. This is the adapter hardware error path.
1874 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1875 "0457 Adapter Hardware Error "
1876 "Data: x%x x%x x%x\n",
1878 phba->work_status[0], phba->work_status[1]);
1880 event_data = FC_REG_DUMP_EVENT;
1881 shost = lpfc_shost_from_vport(vport);
1882 fc_host_post_vendor_event(shost, fc_get_event_number(),
1883 sizeof(event_data), (char *) &event_data,
1884 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1886 lpfc_offline_eratt(phba);
1892 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1893 * @phba: pointer to lpfc hba data structure.
1894 * @mbx_action: flag for mailbox shutdown action.
1895 * @en_rn_msg: send reset/port recovery message.
1896 * This routine is invoked to perform an SLI4 port PCI function reset in
1897 * response to port status register polling attention. It waits for port
1898 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1899 * During this process, interrupt vectors are freed and later requested
1900 * for handling possible port resource change.
1903 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1908 LPFC_MBOXQ_t *mboxq;
1910 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1911 LPFC_SLI_INTF_IF_TYPE_2) {
1913 * On error status condition, driver need to wait for port
1914 * ready before performing reset.
1916 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1921 /* need reset: attempt for port recovery */
1923 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1924 "2887 Reset Needed: Attempting Port "
1927 /* If we are no wait, the HBA has been reset and is not
1928 * functional, thus we should clear
1929 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
1931 if (mbx_action == LPFC_MBX_NO_WAIT) {
1932 spin_lock_irq(&phba->hbalock);
1933 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
1934 if (phba->sli.mbox_active) {
1935 mboxq = phba->sli.mbox_active;
1936 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1937 __lpfc_mbox_cmpl_put(phba, mboxq);
1938 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1939 phba->sli.mbox_active = NULL;
1941 spin_unlock_irq(&phba->hbalock);
1944 lpfc_offline_prep(phba, mbx_action);
1945 lpfc_sli_flush_io_rings(phba);
1947 /* release interrupt for possible resource change */
1948 lpfc_sli4_disable_intr(phba);
1949 rc = lpfc_sli_brdrestart(phba);
1951 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1952 "6309 Failed to restart board\n");
1955 /* request and enable interrupt */
1956 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1957 if (intr_mode == LPFC_INTR_ERROR) {
1958 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1959 "3175 Failed to enable interrupt\n");
1962 phba->intr_mode = intr_mode;
1963 rc = lpfc_online(phba);
1965 lpfc_unblock_mgmt_io(phba);
1971 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1972 * @phba: pointer to lpfc hba data structure.
1974 * This routine is invoked to handle the SLI4 HBA hardware error attention
1978 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1980 struct lpfc_vport *vport = phba->pport;
1981 uint32_t event_data;
1982 struct Scsi_Host *shost;
1984 struct lpfc_register portstat_reg = {0};
1985 uint32_t reg_err1, reg_err2;
1986 uint32_t uerrlo_reg, uemasklo_reg;
1987 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1988 bool en_rn_msg = true;
1989 struct temp_event temp_event_data;
1990 struct lpfc_register portsmphr_reg;
1993 /* If the pci channel is offline, ignore possible errors, since
1994 * we cannot communicate with the pci card anyway.
1996 if (pci_channel_offline(phba->pcidev)) {
1997 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1998 "3166 pci channel is offline\n");
1999 lpfc_sli_flush_io_rings(phba);
2003 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
2004 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2006 case LPFC_SLI_INTF_IF_TYPE_0:
2007 pci_rd_rc1 = lpfc_readl(
2008 phba->sli4_hba.u.if_type0.UERRLOregaddr,
2010 pci_rd_rc2 = lpfc_readl(
2011 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
2013 /* consider PCI bus read error as pci_channel_offline */
2014 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
2016 if (!test_bit(HBA_RECOVERABLE_UE, &phba->hba_flag)) {
2017 lpfc_sli4_offline_eratt(phba);
2020 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2021 "7623 Checking UE recoverable");
2023 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
2024 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2025 &portsmphr_reg.word0))
2028 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
2030 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2031 LPFC_PORT_SEM_UE_RECOVERABLE)
2033 /*Sleep for 1Sec, before checking SEMAPHORE */
2037 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2038 "4827 smphr_port_status x%x : Waited %dSec",
2039 smphr_port_status, i);
2041 /* Recoverable UE, reset the HBA device */
2042 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2043 LPFC_PORT_SEM_UE_RECOVERABLE) {
2044 for (i = 0; i < 20; i++) {
2046 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2047 &portsmphr_reg.word0) &&
2048 (LPFC_POST_STAGE_PORT_READY ==
2049 bf_get(lpfc_port_smphr_port_status,
2051 rc = lpfc_sli4_port_sta_fn_reset(phba,
2052 LPFC_MBX_NO_WAIT, en_rn_msg);
2055 lpfc_printf_log(phba, KERN_ERR,
2057 "4215 Failed to recover UE");
2062 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2063 "7624 Firmware not ready: Failing UE recovery,"
2064 " waited %dSec", i);
2065 phba->link_state = LPFC_HBA_ERROR;
2068 case LPFC_SLI_INTF_IF_TYPE_2:
2069 case LPFC_SLI_INTF_IF_TYPE_6:
2070 pci_rd_rc1 = lpfc_readl(
2071 phba->sli4_hba.u.if_type2.STATUSregaddr,
2072 &portstat_reg.word0);
2073 /* consider PCI bus read error as pci_channel_offline */
2074 if (pci_rd_rc1 == -EIO) {
2075 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2076 "3151 PCI bus read access failure: x%x\n",
2077 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
2078 lpfc_sli4_offline_eratt(phba);
2081 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2082 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
2083 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
2084 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2085 "2889 Port Overtemperature event, "
2086 "taking port offline Data: x%x x%x\n",
2087 reg_err1, reg_err2);
2089 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
2090 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2091 temp_event_data.event_code = LPFC_CRIT_TEMP;
2092 temp_event_data.data = 0xFFFFFFFF;
2094 shost = lpfc_shost_from_vport(phba->pport);
2095 fc_host_post_vendor_event(shost, fc_get_event_number(),
2096 sizeof(temp_event_data),
2097 (char *)&temp_event_data,
2098 SCSI_NL_VID_TYPE_PCI
2099 | PCI_VENDOR_ID_EMULEX);
2101 spin_lock_irq(&phba->hbalock);
2102 phba->over_temp_state = HBA_OVER_TEMP;
2103 spin_unlock_irq(&phba->hbalock);
2104 lpfc_sli4_offline_eratt(phba);
2107 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2108 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
2109 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2110 "3143 Port Down: Firmware Update "
2113 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2114 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2115 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2116 "3144 Port Down: Debug Dump\n");
2117 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2118 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
2119 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2120 "3145 Port Down: Provisioning\n");
2122 /* If resets are disabled then leave the HBA alone and return */
2123 if (!phba->cfg_enable_hba_reset)
2126 /* Check port status register for function reset */
2127 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2130 /* don't report event on forced debug dump */
2131 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2132 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2137 /* fall through for not able to recover */
2138 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2139 "3152 Unrecoverable error\n");
2140 lpfc_sli4_offline_eratt(phba);
2142 case LPFC_SLI_INTF_IF_TYPE_1:
2146 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2147 "3123 Report dump event to upper layer\n");
2148 /* Send an internal error event to mgmt application */
2149 lpfc_board_errevt_to_mgmt(phba);
2151 event_data = FC_REG_DUMP_EVENT;
2152 shost = lpfc_shost_from_vport(vport);
2153 fc_host_post_vendor_event(shost, fc_get_event_number(),
2154 sizeof(event_data), (char *) &event_data,
2155 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2159 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2160 * @phba: pointer to lpfc HBA data structure.
2162 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2163 * routine from the API jump table function pointer from the lpfc_hba struct.
2167 * Any other value - error.
2170 lpfc_handle_eratt(struct lpfc_hba *phba)
2172 (*phba->lpfc_handle_eratt)(phba);
2176 * lpfc_handle_latt - The HBA link event handler
2177 * @phba: pointer to lpfc hba data structure.
2179 * This routine is invoked from the worker thread to handle a HBA host
2180 * attention link event. SLI3 only.
2183 lpfc_handle_latt(struct lpfc_hba *phba)
2185 struct lpfc_vport *vport = phba->pport;
2186 struct lpfc_sli *psli = &phba->sli;
2188 volatile uint32_t control;
2191 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2194 goto lpfc_handle_latt_err_exit;
2197 rc = lpfc_mbox_rsrc_prep(phba, pmb);
2200 mempool_free(pmb, phba->mbox_mem_pool);
2201 goto lpfc_handle_latt_err_exit;
2204 /* Cleanup any outstanding ELS commands */
2205 lpfc_els_flush_all_cmd(phba);
2206 psli->slistat.link_event++;
2207 lpfc_read_topology(phba, pmb, pmb->ctx_buf);
2208 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2210 /* Block ELS IOCBs until we have processed this mbox command */
2211 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2212 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2213 if (rc == MBX_NOT_FINISHED) {
2215 goto lpfc_handle_latt_free_mbuf;
2218 /* Clear Link Attention in HA REG */
2219 spin_lock_irq(&phba->hbalock);
2220 writel(HA_LATT, phba->HAregaddr);
2221 readl(phba->HAregaddr); /* flush */
2222 spin_unlock_irq(&phba->hbalock);
2226 lpfc_handle_latt_free_mbuf:
2227 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2228 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
2229 lpfc_handle_latt_err_exit:
2230 /* Enable Link attention interrupts */
2231 spin_lock_irq(&phba->hbalock);
2232 psli->sli_flag |= LPFC_PROCESS_LA;
2233 control = readl(phba->HCregaddr);
2234 control |= HC_LAINT_ENA;
2235 writel(control, phba->HCregaddr);
2236 readl(phba->HCregaddr); /* flush */
2238 /* Clear Link Attention in HA REG */
2239 writel(HA_LATT, phba->HAregaddr);
2240 readl(phba->HAregaddr); /* flush */
2241 spin_unlock_irq(&phba->hbalock);
2242 lpfc_linkdown(phba);
2243 phba->link_state = LPFC_HBA_ERROR;
2245 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2246 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2252 lpfc_fill_vpd(struct lpfc_hba *phba, uint8_t *vpd, int length, int *pindex)
2256 while (length > 0) {
2257 /* Look for Serial Number */
2258 if ((vpd[*pindex] == 'S') && (vpd[*pindex + 1] == 'N')) {
2265 phba->SerialNumber[j++] = vpd[(*pindex)++];
2269 phba->SerialNumber[j] = 0;
2271 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '1')) {
2272 phba->vpd_flag |= VPD_MODEL_DESC;
2279 phba->ModelDesc[j++] = vpd[(*pindex)++];
2283 phba->ModelDesc[j] = 0;
2285 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '2')) {
2286 phba->vpd_flag |= VPD_MODEL_NAME;
2293 phba->ModelName[j++] = vpd[(*pindex)++];
2297 phba->ModelName[j] = 0;
2299 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '3')) {
2300 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2307 phba->ProgramType[j++] = vpd[(*pindex)++];
2311 phba->ProgramType[j] = 0;
2313 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '4')) {
2314 phba->vpd_flag |= VPD_PORT;
2321 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2322 (phba->sli4_hba.pport_name_sta ==
2323 LPFC_SLI4_PPNAME_GET)) {
2327 phba->Port[j++] = vpd[(*pindex)++];
2331 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2332 (phba->sli4_hba.pport_name_sta ==
2333 LPFC_SLI4_PPNAME_NON))
2347 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2348 * @phba: pointer to lpfc hba data structure.
2349 * @vpd: pointer to the vital product data.
2350 * @len: length of the vital product data in bytes.
2352 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2353 * an array of characters. In this routine, the ModelName, ProgramType, and
2354 * ModelDesc, etc. fields of the phba data structure will be populated.
2357 * 0 - pointer to the VPD passed in is NULL
2361 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2363 uint8_t lenlo, lenhi;
2373 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2374 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2375 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2377 while (!finished && (index < (len - 4))) {
2378 switch (vpd[index]) {
2386 i = ((((unsigned short)lenhi) << 8) + lenlo);
2395 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2396 if (Length > len - index)
2397 Length = len - index;
2399 lpfc_fill_vpd(phba, vpd, Length, &index);
2415 * lpfc_get_atto_model_desc - Retrieve ATTO HBA device model name and description
2416 * @phba: pointer to lpfc hba data structure.
2417 * @mdp: pointer to the data structure to hold the derived model name.
2418 * @descp: pointer to the data structure to hold the derived description.
2420 * This routine retrieves HBA's description based on its registered PCI device
2421 * ID. The @descp passed into this function points to an array of 256 chars. It
2422 * shall be returned with the model name, maximum speed, and the host bus type.
2423 * The @mdp passed into this function points to an array of 80 chars. When the
2424 * function returns, the @mdp will be filled with the model name.
2427 lpfc_get_atto_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2429 uint16_t sub_dev_id = phba->pcidev->subsystem_device;
2430 char *model = "<Unknown>";
2433 switch (sub_dev_id) {
2434 case PCI_DEVICE_ID_CLRY_161E:
2437 case PCI_DEVICE_ID_CLRY_162E:
2440 case PCI_DEVICE_ID_CLRY_164E:
2443 case PCI_DEVICE_ID_CLRY_161P:
2446 case PCI_DEVICE_ID_CLRY_162P:
2449 case PCI_DEVICE_ID_CLRY_164P:
2452 case PCI_DEVICE_ID_CLRY_321E:
2455 case PCI_DEVICE_ID_CLRY_322E:
2458 case PCI_DEVICE_ID_CLRY_324E:
2461 case PCI_DEVICE_ID_CLRY_321P:
2464 case PCI_DEVICE_ID_CLRY_322P:
2467 case PCI_DEVICE_ID_CLRY_324P:
2470 case PCI_DEVICE_ID_TLFC_2XX2:
2474 case PCI_DEVICE_ID_TLFC_3162:
2478 case PCI_DEVICE_ID_TLFC_3322:
2487 if (mdp && mdp[0] == '\0')
2488 snprintf(mdp, 79, "%s", model);
2490 if (descp && descp[0] == '\0')
2491 snprintf(descp, 255,
2492 "ATTO %s%s, Fibre Channel Adapter Initiator, Port %s",
2493 (tbolt) ? "ThunderLink FC " : "Celerity FC-",
2499 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2500 * @phba: pointer to lpfc hba data structure.
2501 * @mdp: pointer to the data structure to hold the derived model name.
2502 * @descp: pointer to the data structure to hold the derived description.
2504 * This routine retrieves HBA's description based on its registered PCI device
2505 * ID. The @descp passed into this function points to an array of 256 chars. It
2506 * shall be returned with the model name, maximum speed, and the host bus type.
2507 * The @mdp passed into this function points to an array of 80 chars. When the
2508 * function returns, the @mdp will be filled with the model name.
2511 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2514 uint16_t dev_id = phba->pcidev->device;
2517 int oneConnect = 0; /* default is not a oneConnect */
2522 } m = {"<Unknown>", "", ""};
2524 if (mdp && mdp[0] != '\0'
2525 && descp && descp[0] != '\0')
2528 if (phba->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
2529 lpfc_get_atto_model_desc(phba, mdp, descp);
2533 if (phba->lmt & LMT_64Gb)
2535 else if (phba->lmt & LMT_32Gb)
2537 else if (phba->lmt & LMT_16Gb)
2539 else if (phba->lmt & LMT_10Gb)
2541 else if (phba->lmt & LMT_8Gb)
2543 else if (phba->lmt & LMT_4Gb)
2545 else if (phba->lmt & LMT_2Gb)
2547 else if (phba->lmt & LMT_1Gb)
2555 case PCI_DEVICE_ID_FIREFLY:
2556 m = (typeof(m)){"LP6000", "PCI",
2557 "Obsolete, Unsupported Fibre Channel Adapter"};
2559 case PCI_DEVICE_ID_SUPERFLY:
2560 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2561 m = (typeof(m)){"LP7000", "PCI", ""};
2563 m = (typeof(m)){"LP7000E", "PCI", ""};
2564 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2566 case PCI_DEVICE_ID_DRAGONFLY:
2567 m = (typeof(m)){"LP8000", "PCI",
2568 "Obsolete, Unsupported Fibre Channel Adapter"};
2570 case PCI_DEVICE_ID_CENTAUR:
2571 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2572 m = (typeof(m)){"LP9002", "PCI", ""};
2574 m = (typeof(m)){"LP9000", "PCI", ""};
2575 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2577 case PCI_DEVICE_ID_RFLY:
2578 m = (typeof(m)){"LP952", "PCI",
2579 "Obsolete, Unsupported Fibre Channel Adapter"};
2581 case PCI_DEVICE_ID_PEGASUS:
2582 m = (typeof(m)){"LP9802", "PCI-X",
2583 "Obsolete, Unsupported Fibre Channel Adapter"};
2585 case PCI_DEVICE_ID_THOR:
2586 m = (typeof(m)){"LP10000", "PCI-X",
2587 "Obsolete, Unsupported Fibre Channel Adapter"};
2589 case PCI_DEVICE_ID_VIPER:
2590 m = (typeof(m)){"LPX1000", "PCI-X",
2591 "Obsolete, Unsupported Fibre Channel Adapter"};
2593 case PCI_DEVICE_ID_PFLY:
2594 m = (typeof(m)){"LP982", "PCI-X",
2595 "Obsolete, Unsupported Fibre Channel Adapter"};
2597 case PCI_DEVICE_ID_TFLY:
2598 m = (typeof(m)){"LP1050", "PCI-X",
2599 "Obsolete, Unsupported Fibre Channel Adapter"};
2601 case PCI_DEVICE_ID_HELIOS:
2602 m = (typeof(m)){"LP11000", "PCI-X2",
2603 "Obsolete, Unsupported Fibre Channel Adapter"};
2605 case PCI_DEVICE_ID_HELIOS_SCSP:
2606 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2607 "Obsolete, Unsupported Fibre Channel Adapter"};
2609 case PCI_DEVICE_ID_HELIOS_DCSP:
2610 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2611 "Obsolete, Unsupported Fibre Channel Adapter"};
2613 case PCI_DEVICE_ID_NEPTUNE:
2614 m = (typeof(m)){"LPe1000", "PCIe",
2615 "Obsolete, Unsupported Fibre Channel Adapter"};
2617 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2618 m = (typeof(m)){"LPe1000-SP", "PCIe",
2619 "Obsolete, Unsupported Fibre Channel Adapter"};
2621 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2622 m = (typeof(m)){"LPe1002-SP", "PCIe",
2623 "Obsolete, Unsupported Fibre Channel Adapter"};
2625 case PCI_DEVICE_ID_BMID:
2626 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2628 case PCI_DEVICE_ID_BSMB:
2629 m = (typeof(m)){"LP111", "PCI-X2",
2630 "Obsolete, Unsupported Fibre Channel Adapter"};
2632 case PCI_DEVICE_ID_ZEPHYR:
2633 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2635 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2636 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2638 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2639 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2642 case PCI_DEVICE_ID_ZMID:
2643 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2645 case PCI_DEVICE_ID_ZSMB:
2646 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2648 case PCI_DEVICE_ID_LP101:
2649 m = (typeof(m)){"LP101", "PCI-X",
2650 "Obsolete, Unsupported Fibre Channel Adapter"};
2652 case PCI_DEVICE_ID_LP10000S:
2653 m = (typeof(m)){"LP10000-S", "PCI",
2654 "Obsolete, Unsupported Fibre Channel Adapter"};
2656 case PCI_DEVICE_ID_LP11000S:
2657 m = (typeof(m)){"LP11000-S", "PCI-X2",
2658 "Obsolete, Unsupported Fibre Channel Adapter"};
2660 case PCI_DEVICE_ID_LPE11000S:
2661 m = (typeof(m)){"LPe11000-S", "PCIe",
2662 "Obsolete, Unsupported Fibre Channel Adapter"};
2664 case PCI_DEVICE_ID_SAT:
2665 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2667 case PCI_DEVICE_ID_SAT_MID:
2668 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2670 case PCI_DEVICE_ID_SAT_SMB:
2671 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2673 case PCI_DEVICE_ID_SAT_DCSP:
2674 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2676 case PCI_DEVICE_ID_SAT_SCSP:
2677 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2679 case PCI_DEVICE_ID_SAT_S:
2680 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2682 case PCI_DEVICE_ID_PROTEUS_VF:
2683 m = (typeof(m)){"LPev12000", "PCIe IOV",
2684 "Obsolete, Unsupported Fibre Channel Adapter"};
2686 case PCI_DEVICE_ID_PROTEUS_PF:
2687 m = (typeof(m)){"LPev12000", "PCIe IOV",
2688 "Obsolete, Unsupported Fibre Channel Adapter"};
2690 case PCI_DEVICE_ID_PROTEUS_S:
2691 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2692 "Obsolete, Unsupported Fibre Channel Adapter"};
2694 case PCI_DEVICE_ID_TIGERSHARK:
2696 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2698 case PCI_DEVICE_ID_TOMCAT:
2700 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2702 case PCI_DEVICE_ID_FALCON:
2703 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2704 "EmulexSecure Fibre"};
2706 case PCI_DEVICE_ID_BALIUS:
2707 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2708 "Obsolete, Unsupported Fibre Channel Adapter"};
2710 case PCI_DEVICE_ID_LANCER_FC:
2711 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2713 case PCI_DEVICE_ID_LANCER_FC_VF:
2714 m = (typeof(m)){"LPe16000", "PCIe",
2715 "Obsolete, Unsupported Fibre Channel Adapter"};
2717 case PCI_DEVICE_ID_LANCER_FCOE:
2719 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2721 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2723 m = (typeof(m)){"OCe15100", "PCIe",
2724 "Obsolete, Unsupported FCoE"};
2726 case PCI_DEVICE_ID_LANCER_G6_FC:
2727 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2729 case PCI_DEVICE_ID_LANCER_G7_FC:
2730 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2732 case PCI_DEVICE_ID_LANCER_G7P_FC:
2733 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2735 case PCI_DEVICE_ID_SKYHAWK:
2736 case PCI_DEVICE_ID_SKYHAWK_VF:
2738 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2741 m = (typeof(m)){"Unknown", "", ""};
2745 if (mdp && mdp[0] == '\0')
2746 snprintf(mdp, 79,"%s", m.name);
2748 * oneConnect hba requires special processing, they are all initiators
2749 * and we put the port number on the end
2751 if (descp && descp[0] == '\0') {
2753 snprintf(descp, 255,
2754 "Emulex OneConnect %s, %s Initiator %s",
2757 else if (max_speed == 0)
2758 snprintf(descp, 255,
2760 m.name, m.bus, m.function);
2762 snprintf(descp, 255,
2763 "Emulex %s %d%s %s %s",
2764 m.name, max_speed, (GE) ? "GE" : "Gb",
2770 * lpfc_sli3_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2771 * @phba: pointer to lpfc hba data structure.
2772 * @pring: pointer to a IOCB ring.
2773 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2775 * This routine posts a given number of IOCBs with the associated DMA buffer
2776 * descriptors specified by the cnt argument to the given IOCB ring.
2779 * The number of IOCBs NOT able to be posted to the IOCB ring.
2782 lpfc_sli3_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2785 struct lpfc_iocbq *iocb;
2786 struct lpfc_dmabuf *mp1, *mp2;
2788 cnt += pring->missbufcnt;
2790 /* While there are buffers to post */
2792 /* Allocate buffer for command iocb */
2793 iocb = lpfc_sli_get_iocbq(phba);
2795 pring->missbufcnt = cnt;
2800 /* 2 buffers can be posted per command */
2801 /* Allocate buffer to post */
2802 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2804 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2805 if (!mp1 || !mp1->virt) {
2807 lpfc_sli_release_iocbq(phba, iocb);
2808 pring->missbufcnt = cnt;
2812 INIT_LIST_HEAD(&mp1->list);
2813 /* Allocate buffer to post */
2815 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2817 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2819 if (!mp2 || !mp2->virt) {
2821 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2823 lpfc_sli_release_iocbq(phba, iocb);
2824 pring->missbufcnt = cnt;
2828 INIT_LIST_HEAD(&mp2->list);
2833 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2834 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2835 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2836 icmd->ulpBdeCount = 1;
2839 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2840 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2841 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2843 icmd->ulpBdeCount = 2;
2846 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2849 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2851 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2855 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2859 lpfc_sli_release_iocbq(phba, iocb);
2860 pring->missbufcnt = cnt;
2863 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2865 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2867 pring->missbufcnt = 0;
2872 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2873 * @phba: pointer to lpfc hba data structure.
2875 * This routine posts initial receive IOCB buffers to the ELS ring. The
2876 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2877 * set to 64 IOCBs. SLI3 only.
2880 * 0 - success (currently always success)
2883 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2885 struct lpfc_sli *psli = &phba->sli;
2887 /* Ring 0, ELS / CT buffers */
2888 lpfc_sli3_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2889 /* Ring 2 - FCP no buffers needed */
2894 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2897 * lpfc_sha_init - Set up initial array of hash table entries
2898 * @HashResultPointer: pointer to an array as hash table.
2900 * This routine sets up the initial values to the array of hash table entries
2904 lpfc_sha_init(uint32_t * HashResultPointer)
2906 HashResultPointer[0] = 0x67452301;
2907 HashResultPointer[1] = 0xEFCDAB89;
2908 HashResultPointer[2] = 0x98BADCFE;
2909 HashResultPointer[3] = 0x10325476;
2910 HashResultPointer[4] = 0xC3D2E1F0;
2914 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2915 * @HashResultPointer: pointer to an initial/result hash table.
2916 * @HashWorkingPointer: pointer to an working hash table.
2918 * This routine iterates an initial hash table pointed by @HashResultPointer
2919 * with the values from the working hash table pointeed by @HashWorkingPointer.
2920 * The results are putting back to the initial hash table, returned through
2921 * the @HashResultPointer as the result hash table.
2924 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2928 uint32_t A, B, C, D, E;
2931 HashWorkingPointer[t] =
2933 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2935 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2936 } while (++t <= 79);
2938 A = HashResultPointer[0];
2939 B = HashResultPointer[1];
2940 C = HashResultPointer[2];
2941 D = HashResultPointer[3];
2942 E = HashResultPointer[4];
2946 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2947 } else if (t < 40) {
2948 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2949 } else if (t < 60) {
2950 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2952 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2954 TEMP += S(5, A) + E + HashWorkingPointer[t];
2960 } while (++t <= 79);
2962 HashResultPointer[0] += A;
2963 HashResultPointer[1] += B;
2964 HashResultPointer[2] += C;
2965 HashResultPointer[3] += D;
2966 HashResultPointer[4] += E;
2971 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2972 * @RandomChallenge: pointer to the entry of host challenge random number array.
2973 * @HashWorking: pointer to the entry of the working hash array.
2975 * This routine calculates the working hash array referred by @HashWorking
2976 * from the challenge random numbers associated with the host, referred by
2977 * @RandomChallenge. The result is put into the entry of the working hash
2978 * array and returned by reference through @HashWorking.
2981 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2983 *HashWorking = (*RandomChallenge ^ *HashWorking);
2987 * lpfc_hba_init - Perform special handling for LC HBA initialization
2988 * @phba: pointer to lpfc hba data structure.
2989 * @hbainit: pointer to an array of unsigned 32-bit integers.
2991 * This routine performs the special handling for LC HBA initialization.
2994 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2997 uint32_t *HashWorking;
2998 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
3000 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
3004 HashWorking[0] = HashWorking[78] = *pwwnn++;
3005 HashWorking[1] = HashWorking[79] = *pwwnn;
3007 for (t = 0; t < 7; t++)
3008 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
3010 lpfc_sha_init(hbainit);
3011 lpfc_sha_iterate(hbainit, HashWorking);
3016 * lpfc_cleanup - Performs vport cleanups before deleting a vport
3017 * @vport: pointer to a virtual N_Port data structure.
3019 * This routine performs the necessary cleanups before deleting the @vport.
3020 * It invokes the discovery state machine to perform necessary state
3021 * transitions and to release the ndlps associated with the @vport. Note,
3022 * the physical port is treated as @vport 0.
3025 lpfc_cleanup(struct lpfc_vport *vport)
3027 struct lpfc_hba *phba = vport->phba;
3028 struct lpfc_nodelist *ndlp, *next_ndlp;
3031 if (phba->link_state > LPFC_LINK_DOWN)
3032 lpfc_port_link_failure(vport);
3034 /* Clean up VMID resources */
3035 if (lpfc_is_vmid_enabled(phba))
3036 lpfc_vmid_vport_cleanup(vport);
3038 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3039 if (vport->port_type != LPFC_PHYSICAL_PORT &&
3040 ndlp->nlp_DID == Fabric_DID) {
3041 /* Just free up ndlp with Fabric_DID for vports */
3046 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
3047 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3052 /* Fabric Ports not in UNMAPPED state are cleaned up in the
3055 if (ndlp->nlp_type & NLP_FABRIC &&
3056 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
3057 lpfc_disc_state_machine(vport, ndlp, NULL,
3058 NLP_EVT_DEVICE_RECOVERY);
3060 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
3061 lpfc_disc_state_machine(vport, ndlp, NULL,
3065 /* This is a special case flush to return all
3066 * IOs before entering this loop. There are
3067 * two points in the code where a flush is
3068 * avoided if the FC_UNLOADING flag is set.
3069 * one is in the multipool destroy,
3070 * (this prevents a crash) and the other is
3071 * in the nvme abort handler, ( also prevents
3072 * a crash). Both of these exceptions are
3073 * cases where the slot is still accessible.
3074 * The flush here is only when the pci slot
3077 if (test_bit(FC_UNLOADING, &vport->load_flag) &&
3078 pci_channel_offline(phba->pcidev))
3079 lpfc_sli_flush_io_rings(vport->phba);
3081 /* At this point, ALL ndlp's should be gone
3082 * because of the previous NLP_EVT_DEVICE_RM.
3083 * Lets wait for this to happen, if needed.
3085 while (!list_empty(&vport->fc_nodes)) {
3087 lpfc_printf_vlog(vport, KERN_ERR,
3089 "0233 Nodelist not empty\n");
3090 list_for_each_entry_safe(ndlp, next_ndlp,
3091 &vport->fc_nodes, nlp_listp) {
3092 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
3094 "0282 did:x%x ndlp:x%px "
3095 "refcnt:%d xflags x%x nflag x%x\n",
3096 ndlp->nlp_DID, (void *)ndlp,
3097 kref_read(&ndlp->kref),
3098 ndlp->fc4_xpt_flags,
3104 /* Wait for any activity on ndlps to settle */
3107 lpfc_cleanup_vports_rrqs(vport, NULL);
3111 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
3112 * @vport: pointer to a virtual N_Port data structure.
3114 * This routine stops all the timers associated with a @vport. This function
3115 * is invoked before disabling or deleting a @vport. Note that the physical
3116 * port is treated as @vport 0.
3119 lpfc_stop_vport_timers(struct lpfc_vport *vport)
3121 del_timer_sync(&vport->els_tmofunc);
3122 del_timer_sync(&vport->delayed_disc_tmo);
3123 lpfc_can_disctmo(vport);
3128 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3129 * @phba: pointer to lpfc hba data structure.
3131 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
3132 * caller of this routine should already hold the host lock.
3135 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3137 /* Clear pending FCF rediscovery wait flag */
3138 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3140 /* Now, try to stop the timer */
3141 del_timer(&phba->fcf.redisc_wait);
3145 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3146 * @phba: pointer to lpfc hba data structure.
3148 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3149 * checks whether the FCF rediscovery wait timer is pending with the host
3150 * lock held before proceeding with disabling the timer and clearing the
3151 * wait timer pendig flag.
3154 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3156 spin_lock_irq(&phba->hbalock);
3157 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3158 /* FCF rediscovery timer already fired or stopped */
3159 spin_unlock_irq(&phba->hbalock);
3162 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3163 /* Clear failover in progress flags */
3164 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
3165 spin_unlock_irq(&phba->hbalock);
3169 * lpfc_cmf_stop - Stop CMF processing
3170 * @phba: pointer to lpfc hba data structure.
3172 * This is called when the link goes down or if CMF mode is turned OFF.
3173 * It is also called when going offline or unloaded just before the
3174 * congestion info buffer is unregistered.
3177 lpfc_cmf_stop(struct lpfc_hba *phba)
3180 struct lpfc_cgn_stat *cgs;
3182 /* We only do something if CMF is enabled */
3183 if (!phba->sli4_hba.pc_sli4_params.cmf)
3186 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3187 "6221 Stop CMF / Cancel Timer\n");
3189 /* Cancel the CMF timer */
3190 hrtimer_cancel(&phba->cmf_stats_timer);
3191 hrtimer_cancel(&phba->cmf_timer);
3193 /* Zero CMF counters */
3194 atomic_set(&phba->cmf_busy, 0);
3195 for_each_present_cpu(cpu) {
3196 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3197 atomic64_set(&cgs->total_bytes, 0);
3198 atomic64_set(&cgs->rcv_bytes, 0);
3199 atomic_set(&cgs->rx_io_cnt, 0);
3200 atomic64_set(&cgs->rx_latency, 0);
3202 atomic_set(&phba->cmf_bw_wait, 0);
3204 /* Resume any blocked IO - Queue unblock on workqueue */
3205 queue_work(phba->wq, &phba->unblock_request_work);
3208 static inline uint64_t
3209 lpfc_get_max_line_rate(struct lpfc_hba *phba)
3211 uint64_t rate = lpfc_sli_port_speed_get(phba);
3213 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3217 lpfc_cmf_signal_init(struct lpfc_hba *phba)
3219 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3220 "6223 Signal CMF init\n");
3222 /* Use the new fc_linkspeed to recalculate */
3223 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3224 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3225 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3226 phba->cmf_interval_rate, 1000);
3227 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3229 /* This is a signal to firmware to sync up CMF BW with link speed */
3230 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3234 * lpfc_cmf_start - Start CMF processing
3235 * @phba: pointer to lpfc hba data structure.
3237 * This is called when the link comes up or if CMF mode is turned OFF
3238 * to Monitor or Managed.
3241 lpfc_cmf_start(struct lpfc_hba *phba)
3243 struct lpfc_cgn_stat *cgs;
3246 /* We only do something if CMF is enabled */
3247 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3248 phba->cmf_active_mode == LPFC_CFG_OFF)
3251 /* Reinitialize congestion buffer info */
3252 lpfc_init_congestion_buf(phba);
3254 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3255 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3256 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3257 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3259 atomic_set(&phba->cmf_busy, 0);
3260 for_each_present_cpu(cpu) {
3261 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3262 atomic64_set(&cgs->total_bytes, 0);
3263 atomic64_set(&cgs->rcv_bytes, 0);
3264 atomic_set(&cgs->rx_io_cnt, 0);
3265 atomic64_set(&cgs->rx_latency, 0);
3267 phba->cmf_latency.tv_sec = 0;
3268 phba->cmf_latency.tv_nsec = 0;
3270 lpfc_cmf_signal_init(phba);
3272 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3273 "6222 Start CMF / Timer\n");
3275 phba->cmf_timer_cnt = 0;
3276 hrtimer_start(&phba->cmf_timer,
3277 ktime_set(0, LPFC_CMF_INTERVAL * NSEC_PER_MSEC),
3279 hrtimer_start(&phba->cmf_stats_timer,
3280 ktime_set(0, LPFC_SEC_MIN * NSEC_PER_SEC),
3282 /* Setup for latency check in IO cmpl routines */
3283 ktime_get_real_ts64(&phba->cmf_latency);
3285 atomic_set(&phba->cmf_bw_wait, 0);
3286 atomic_set(&phba->cmf_stop_io, 0);
3290 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
3291 * @phba: pointer to lpfc hba data structure.
3293 * This routine stops all the timers associated with a HBA. This function is
3294 * invoked before either putting a HBA offline or unloading the driver.
3297 lpfc_stop_hba_timers(struct lpfc_hba *phba)
3300 lpfc_stop_vport_timers(phba->pport);
3301 cancel_delayed_work_sync(&phba->eq_delay_work);
3302 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
3303 del_timer_sync(&phba->sli.mbox_tmo);
3304 del_timer_sync(&phba->fabric_block_timer);
3305 del_timer_sync(&phba->eratt_poll);
3306 del_timer_sync(&phba->hb_tmofunc);
3307 if (phba->sli_rev == LPFC_SLI_REV4) {
3308 del_timer_sync(&phba->rrq_tmr);
3309 clear_bit(HBA_RRQ_ACTIVE, &phba->hba_flag);
3311 clear_bit(HBA_HBEAT_INP, &phba->hba_flag);
3312 clear_bit(HBA_HBEAT_TMO, &phba->hba_flag);
3314 switch (phba->pci_dev_grp) {
3315 case LPFC_PCI_DEV_LP:
3316 /* Stop any LightPulse device specific driver timers */
3317 del_timer_sync(&phba->fcp_poll_timer);
3319 case LPFC_PCI_DEV_OC:
3320 /* Stop any OneConnect device specific driver timers */
3321 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3324 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3325 "0297 Invalid device group (x%x)\n",
3333 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3334 * @phba: pointer to lpfc hba data structure.
3335 * @mbx_action: flag for mailbox no wait action.
3337 * This routine marks a HBA's management interface as blocked. Once the HBA's
3338 * management interface is marked as blocked, all the user space access to
3339 * the HBA, whether they are from sysfs interface or libdfc interface will
3340 * all be blocked. The HBA is set to block the management interface when the
3341 * driver prepares the HBA interface for online or offline.
3344 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
3346 unsigned long iflag;
3347 uint8_t actcmd = MBX_HEARTBEAT;
3348 unsigned long timeout;
3350 spin_lock_irqsave(&phba->hbalock, iflag);
3351 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
3352 spin_unlock_irqrestore(&phba->hbalock, iflag);
3353 if (mbx_action == LPFC_MBX_NO_WAIT)
3355 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3356 spin_lock_irqsave(&phba->hbalock, iflag);
3357 if (phba->sli.mbox_active) {
3358 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3359 /* Determine how long we might wait for the active mailbox
3360 * command to be gracefully completed by firmware.
3362 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3363 phba->sli.mbox_active) * 1000) + jiffies;
3365 spin_unlock_irqrestore(&phba->hbalock, iflag);
3367 /* Wait for the outstnading mailbox command to complete */
3368 while (phba->sli.mbox_active) {
3369 /* Check active mailbox complete status every 2ms */
3371 if (time_after(jiffies, timeout)) {
3372 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3373 "2813 Mgmt IO is Blocked %x "
3374 "- mbox cmd %x still active\n",
3375 phba->sli.sli_flag, actcmd);
3382 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3383 * @phba: pointer to lpfc hba data structure.
3385 * Allocate RPIs for all active remote nodes. This is needed whenever
3386 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3387 * is to fixup the temporary rpi assignments.
3390 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3392 struct lpfc_nodelist *ndlp, *next_ndlp;
3393 struct lpfc_vport **vports;
3396 if (phba->sli_rev != LPFC_SLI_REV4)
3399 vports = lpfc_create_vport_work_array(phba);
3403 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3404 if (test_bit(FC_UNLOADING, &vports[i]->load_flag))
3407 list_for_each_entry_safe(ndlp, next_ndlp,
3408 &vports[i]->fc_nodes,
3410 rpi = lpfc_sli4_alloc_rpi(phba);
3411 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3412 /* TODO print log? */
3415 ndlp->nlp_rpi = rpi;
3416 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3417 LOG_NODE | LOG_DISCOVERY,
3418 "0009 Assign RPI x%x to ndlp x%px "
3419 "DID:x%06x flg:x%x\n",
3420 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3424 lpfc_destroy_vport_work_array(phba, vports);
3428 * lpfc_create_expedite_pool - create expedite pool
3429 * @phba: pointer to lpfc hba data structure.
3431 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3432 * to expedite pool. Mark them as expedite.
3434 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3436 struct lpfc_sli4_hdw_queue *qp;
3437 struct lpfc_io_buf *lpfc_ncmd;
3438 struct lpfc_io_buf *lpfc_ncmd_next;
3439 struct lpfc_epd_pool *epd_pool;
3440 unsigned long iflag;
3442 epd_pool = &phba->epd_pool;
3443 qp = &phba->sli4_hba.hdwq[0];
3445 spin_lock_init(&epd_pool->lock);
3446 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3447 spin_lock(&epd_pool->lock);
3448 INIT_LIST_HEAD(&epd_pool->list);
3449 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3450 &qp->lpfc_io_buf_list_put, list) {
3451 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3452 lpfc_ncmd->expedite = true;
3455 if (epd_pool->count >= XRI_BATCH)
3458 spin_unlock(&epd_pool->lock);
3459 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3463 * lpfc_destroy_expedite_pool - destroy expedite pool
3464 * @phba: pointer to lpfc hba data structure.
3466 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3467 * of HWQ 0. Clear the mark.
3469 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3471 struct lpfc_sli4_hdw_queue *qp;
3472 struct lpfc_io_buf *lpfc_ncmd;
3473 struct lpfc_io_buf *lpfc_ncmd_next;
3474 struct lpfc_epd_pool *epd_pool;
3475 unsigned long iflag;
3477 epd_pool = &phba->epd_pool;
3478 qp = &phba->sli4_hba.hdwq[0];
3480 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3481 spin_lock(&epd_pool->lock);
3482 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3483 &epd_pool->list, list) {
3484 list_move_tail(&lpfc_ncmd->list,
3485 &qp->lpfc_io_buf_list_put);
3486 lpfc_ncmd->flags = false;
3490 spin_unlock(&epd_pool->lock);
3491 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3495 * lpfc_create_multixri_pools - create multi-XRI pools
3496 * @phba: pointer to lpfc hba data structure.
3498 * This routine initialize public, private per HWQ. Then, move XRIs from
3499 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3502 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3507 struct lpfc_io_buf *lpfc_ncmd;
3508 struct lpfc_io_buf *lpfc_ncmd_next;
3509 unsigned long iflag;
3510 struct lpfc_sli4_hdw_queue *qp;
3511 struct lpfc_multixri_pool *multixri_pool;
3512 struct lpfc_pbl_pool *pbl_pool;
3513 struct lpfc_pvt_pool *pvt_pool;
3515 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3516 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3517 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3518 phba->sli4_hba.io_xri_cnt);
3520 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3521 lpfc_create_expedite_pool(phba);
3523 hwq_count = phba->cfg_hdw_queue;
3524 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3526 for (i = 0; i < hwq_count; i++) {
3527 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3529 if (!multixri_pool) {
3530 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3531 "1238 Failed to allocate memory for "
3534 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3535 lpfc_destroy_expedite_pool(phba);
3539 qp = &phba->sli4_hba.hdwq[j];
3540 kfree(qp->p_multixri_pool);
3543 phba->cfg_xri_rebalancing = 0;
3547 qp = &phba->sli4_hba.hdwq[i];
3548 qp->p_multixri_pool = multixri_pool;
3550 multixri_pool->xri_limit = count_per_hwq;
3551 multixri_pool->rrb_next_hwqid = i;
3553 /* Deal with public free xri pool */
3554 pbl_pool = &multixri_pool->pbl_pool;
3555 spin_lock_init(&pbl_pool->lock);
3556 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3557 spin_lock(&pbl_pool->lock);
3558 INIT_LIST_HEAD(&pbl_pool->list);
3559 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3560 &qp->lpfc_io_buf_list_put, list) {
3561 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3565 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3566 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3567 pbl_pool->count, i);
3568 spin_unlock(&pbl_pool->lock);
3569 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3571 /* Deal with private free xri pool */
3572 pvt_pool = &multixri_pool->pvt_pool;
3573 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3574 pvt_pool->low_watermark = XRI_BATCH;
3575 spin_lock_init(&pvt_pool->lock);
3576 spin_lock_irqsave(&pvt_pool->lock, iflag);
3577 INIT_LIST_HEAD(&pvt_pool->list);
3578 pvt_pool->count = 0;
3579 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3584 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3585 * @phba: pointer to lpfc hba data structure.
3587 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3589 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3593 struct lpfc_io_buf *lpfc_ncmd;
3594 struct lpfc_io_buf *lpfc_ncmd_next;
3595 unsigned long iflag;
3596 struct lpfc_sli4_hdw_queue *qp;
3597 struct lpfc_multixri_pool *multixri_pool;
3598 struct lpfc_pbl_pool *pbl_pool;
3599 struct lpfc_pvt_pool *pvt_pool;
3601 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3602 lpfc_destroy_expedite_pool(phba);
3604 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
3605 lpfc_sli_flush_io_rings(phba);
3607 hwq_count = phba->cfg_hdw_queue;
3609 for (i = 0; i < hwq_count; i++) {
3610 qp = &phba->sli4_hba.hdwq[i];
3611 multixri_pool = qp->p_multixri_pool;
3615 qp->p_multixri_pool = NULL;
3617 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3619 /* Deal with public free xri pool */
3620 pbl_pool = &multixri_pool->pbl_pool;
3621 spin_lock(&pbl_pool->lock);
3623 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3624 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3625 pbl_pool->count, i);
3627 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3628 &pbl_pool->list, list) {
3629 list_move_tail(&lpfc_ncmd->list,
3630 &qp->lpfc_io_buf_list_put);
3635 INIT_LIST_HEAD(&pbl_pool->list);
3636 pbl_pool->count = 0;
3638 spin_unlock(&pbl_pool->lock);
3640 /* Deal with private free xri pool */
3641 pvt_pool = &multixri_pool->pvt_pool;
3642 spin_lock(&pvt_pool->lock);
3644 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3645 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3646 pvt_pool->count, i);
3648 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3649 &pvt_pool->list, list) {
3650 list_move_tail(&lpfc_ncmd->list,
3651 &qp->lpfc_io_buf_list_put);
3656 INIT_LIST_HEAD(&pvt_pool->list);
3657 pvt_pool->count = 0;
3659 spin_unlock(&pvt_pool->lock);
3660 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3662 kfree(multixri_pool);
3667 * lpfc_online - Initialize and bring a HBA online
3668 * @phba: pointer to lpfc hba data structure.
3670 * This routine initializes the HBA and brings a HBA online. During this
3671 * process, the management interface is blocked to prevent user space access
3672 * to the HBA interfering with the driver initialization.
3679 lpfc_online(struct lpfc_hba *phba)
3681 struct lpfc_vport *vport;
3682 struct lpfc_vport **vports;
3684 bool vpis_cleared = false;
3688 vport = phba->pport;
3690 if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
3693 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3694 "0458 Bring Adapter online\n");
3696 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3698 if (phba->sli_rev == LPFC_SLI_REV4) {
3699 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3700 lpfc_unblock_mgmt_io(phba);
3703 spin_lock_irq(&phba->hbalock);
3704 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3705 vpis_cleared = true;
3706 spin_unlock_irq(&phba->hbalock);
3708 /* Reestablish the local initiator port.
3709 * The offline process destroyed the previous lport.
3711 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3712 !phba->nvmet_support) {
3713 error = lpfc_nvme_create_localport(phba->pport);
3715 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3716 "6132 NVME restore reg failed "
3717 "on nvmei error x%x\n", error);
3720 lpfc_sli_queue_init(phba);
3721 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3722 lpfc_unblock_mgmt_io(phba);
3727 vports = lpfc_create_vport_work_array(phba);
3728 if (vports != NULL) {
3729 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3730 clear_bit(FC_OFFLINE_MODE, &vports[i]->fc_flag);
3731 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3732 set_bit(FC_VPORT_NEEDS_REG_VPI,
3733 &vports[i]->fc_flag);
3734 if (phba->sli_rev == LPFC_SLI_REV4) {
3735 set_bit(FC_VPORT_NEEDS_INIT_VPI,
3736 &vports[i]->fc_flag);
3737 if ((vpis_cleared) &&
3738 (vports[i]->port_type !=
3739 LPFC_PHYSICAL_PORT))
3744 lpfc_destroy_vport_work_array(phba, vports);
3746 if (phba->cfg_xri_rebalancing)
3747 lpfc_create_multixri_pools(phba);
3749 lpfc_cpuhp_add(phba);
3751 lpfc_unblock_mgmt_io(phba);
3756 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3757 * @phba: pointer to lpfc hba data structure.
3759 * This routine marks a HBA's management interface as not blocked. Once the
3760 * HBA's management interface is marked as not blocked, all the user space
3761 * access to the HBA, whether they are from sysfs interface or libdfc
3762 * interface will be allowed. The HBA is set to block the management interface
3763 * when the driver prepares the HBA interface for online or offline and then
3764 * set to unblock the management interface afterwards.
3767 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3769 unsigned long iflag;
3771 spin_lock_irqsave(&phba->hbalock, iflag);
3772 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3773 spin_unlock_irqrestore(&phba->hbalock, iflag);
3777 * lpfc_offline_prep - Prepare a HBA to be brought offline
3778 * @phba: pointer to lpfc hba data structure.
3779 * @mbx_action: flag for mailbox shutdown action.
3781 * This routine is invoked to prepare a HBA to be brought offline. It performs
3782 * unregistration login to all the nodes on all vports and flushes the mailbox
3783 * queue to make it ready to be brought offline.
3786 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3788 struct lpfc_vport *vport = phba->pport;
3789 struct lpfc_nodelist *ndlp, *next_ndlp;
3790 struct lpfc_vport **vports;
3791 struct Scsi_Host *shost;
3796 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
3799 lpfc_block_mgmt_io(phba, mbx_action);
3801 lpfc_linkdown(phba);
3803 offline = pci_channel_offline(phba->pcidev);
3804 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
3806 /* Issue an unreg_login to all nodes on all vports */
3807 vports = lpfc_create_vport_work_array(phba);
3808 if (vports != NULL) {
3809 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3810 if (test_bit(FC_UNLOADING, &vports[i]->load_flag))
3812 shost = lpfc_shost_from_vport(vports[i]);
3813 spin_lock_irq(shost->host_lock);
3814 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3815 spin_unlock_irq(shost->host_lock);
3816 set_bit(FC_VPORT_NEEDS_REG_VPI, &vports[i]->fc_flag);
3817 clear_bit(FC_VFI_REGISTERED, &vports[i]->fc_flag);
3819 list_for_each_entry_safe(ndlp, next_ndlp,
3820 &vports[i]->fc_nodes,
3823 spin_lock_irq(&ndlp->lock);
3824 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3825 spin_unlock_irq(&ndlp->lock);
3827 if (offline || hba_pci_err) {
3828 spin_lock_irq(&ndlp->lock);
3829 ndlp->nlp_flag &= ~(NLP_UNREG_INP |
3830 NLP_RPI_REGISTERED);
3831 spin_unlock_irq(&ndlp->lock);
3832 if (phba->sli_rev == LPFC_SLI_REV4)
3833 lpfc_sli_rpi_release(vports[i],
3836 lpfc_unreg_rpi(vports[i], ndlp);
3839 * Whenever an SLI4 port goes offline, free the
3840 * RPI. Get a new RPI when the adapter port
3841 * comes back online.
3843 if (phba->sli_rev == LPFC_SLI_REV4) {
3844 lpfc_printf_vlog(vports[i], KERN_INFO,
3845 LOG_NODE | LOG_DISCOVERY,
3846 "0011 Free RPI x%x on "
3847 "ndlp: x%px did x%x\n",
3848 ndlp->nlp_rpi, ndlp,
3850 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3851 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3854 if (ndlp->nlp_type & NLP_FABRIC) {
3855 lpfc_disc_state_machine(vports[i], ndlp,
3856 NULL, NLP_EVT_DEVICE_RECOVERY);
3858 /* Don't remove the node unless the node
3859 * has been unregistered with the
3860 * transport, and we're not in recovery
3861 * before dev_loss_tmo triggered.
3862 * Otherwise, let dev_loss take care of
3865 if (!(ndlp->save_flags &
3866 NLP_IN_RECOV_POST_DEV_LOSS) &&
3867 !(ndlp->fc4_xpt_flags &
3868 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3869 lpfc_disc_state_machine
3877 lpfc_destroy_vport_work_array(phba, vports);
3879 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3882 flush_workqueue(phba->wq);
3886 * lpfc_offline - Bring a HBA offline
3887 * @phba: pointer to lpfc hba data structure.
3889 * This routine actually brings a HBA offline. It stops all the timers
3890 * associated with the HBA, brings down the SLI layer, and eventually
3891 * marks the HBA as in offline state for the upper layer protocol.
3894 lpfc_offline(struct lpfc_hba *phba)
3896 struct Scsi_Host *shost;
3897 struct lpfc_vport **vports;
3900 if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
3903 /* stop port and all timers associated with this hba */
3904 lpfc_stop_port(phba);
3906 /* Tear down the local and target port registrations. The
3907 * nvme transports need to cleanup.
3909 lpfc_nvmet_destroy_targetport(phba);
3910 lpfc_nvme_destroy_localport(phba->pport);
3912 vports = lpfc_create_vport_work_array(phba);
3914 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3915 lpfc_stop_vport_timers(vports[i]);
3916 lpfc_destroy_vport_work_array(phba, vports);
3917 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3918 "0460 Bring Adapter offline\n");
3919 /* Bring down the SLI Layer and cleanup. The HBA is offline
3921 lpfc_sli_hba_down(phba);
3922 spin_lock_irq(&phba->hbalock);
3924 spin_unlock_irq(&phba->hbalock);
3925 vports = lpfc_create_vport_work_array(phba);
3927 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3928 shost = lpfc_shost_from_vport(vports[i]);
3929 spin_lock_irq(shost->host_lock);
3930 vports[i]->work_port_events = 0;
3931 spin_unlock_irq(shost->host_lock);
3932 set_bit(FC_OFFLINE_MODE, &vports[i]->fc_flag);
3934 lpfc_destroy_vport_work_array(phba, vports);
3935 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3938 if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
3939 __lpfc_cpuhp_remove(phba);
3941 if (phba->cfg_xri_rebalancing)
3942 lpfc_destroy_multixri_pools(phba);
3946 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3947 * @phba: pointer to lpfc hba data structure.
3949 * This routine is to free all the SCSI buffers and IOCBs from the driver
3950 * list back to kernel. It is called from lpfc_pci_remove_one to free
3951 * the internal resources before the device is removed from the system.
3954 lpfc_scsi_free(struct lpfc_hba *phba)
3956 struct lpfc_io_buf *sb, *sb_next;
3958 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3961 spin_lock_irq(&phba->hbalock);
3963 /* Release all the lpfc_scsi_bufs maintained by this host. */
3965 spin_lock(&phba->scsi_buf_list_put_lock);
3966 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3968 list_del(&sb->list);
3969 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3972 phba->total_scsi_bufs--;
3974 spin_unlock(&phba->scsi_buf_list_put_lock);
3976 spin_lock(&phba->scsi_buf_list_get_lock);
3977 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3979 list_del(&sb->list);
3980 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3983 phba->total_scsi_bufs--;
3985 spin_unlock(&phba->scsi_buf_list_get_lock);
3986 spin_unlock_irq(&phba->hbalock);
3990 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3991 * @phba: pointer to lpfc hba data structure.
3993 * This routine is to free all the IO buffers and IOCBs from the driver
3994 * list back to kernel. It is called from lpfc_pci_remove_one to free
3995 * the internal resources before the device is removed from the system.
3998 lpfc_io_free(struct lpfc_hba *phba)
4000 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
4001 struct lpfc_sli4_hdw_queue *qp;
4004 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4005 qp = &phba->sli4_hba.hdwq[idx];
4006 /* Release all the lpfc_nvme_bufs maintained by this host. */
4007 spin_lock(&qp->io_buf_list_put_lock);
4008 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4009 &qp->lpfc_io_buf_list_put,
4011 list_del(&lpfc_ncmd->list);
4013 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4014 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4015 if (phba->cfg_xpsgl && !phba->nvmet_support)
4016 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
4017 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
4019 qp->total_io_bufs--;
4021 spin_unlock(&qp->io_buf_list_put_lock);
4023 spin_lock(&qp->io_buf_list_get_lock);
4024 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4025 &qp->lpfc_io_buf_list_get,
4027 list_del(&lpfc_ncmd->list);
4029 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4030 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4031 if (phba->cfg_xpsgl && !phba->nvmet_support)
4032 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
4033 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
4035 qp->total_io_bufs--;
4037 spin_unlock(&qp->io_buf_list_get_lock);
4042 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
4043 * @phba: pointer to lpfc hba data structure.
4045 * This routine first calculates the sizes of the current els and allocated
4046 * scsi sgl lists, and then goes through all sgls to updates the physical
4047 * XRIs assigned due to port function reset. During port initialization, the
4048 * current els and allocated scsi sgl lists are 0s.
4051 * 0 - successful (for now, it always returns 0)
4054 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
4056 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4057 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4058 LIST_HEAD(els_sgl_list);
4062 * update on pci function's els xri-sgl list
4064 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4066 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
4067 /* els xri-sgl expanded */
4068 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
4069 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4070 "3157 ELS xri-sgl count increased from "
4071 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4073 /* allocate the additional els sgls */
4074 for (i = 0; i < xri_cnt; i++) {
4075 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4077 if (sglq_entry == NULL) {
4078 lpfc_printf_log(phba, KERN_ERR,
4080 "2562 Failure to allocate an "
4081 "ELS sgl entry:%d\n", i);
4085 sglq_entry->buff_type = GEN_BUFF_TYPE;
4086 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
4088 if (sglq_entry->virt == NULL) {
4090 lpfc_printf_log(phba, KERN_ERR,
4092 "2563 Failure to allocate an "
4093 "ELS mbuf:%d\n", i);
4097 sglq_entry->sgl = sglq_entry->virt;
4098 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
4099 sglq_entry->state = SGL_FREED;
4100 list_add_tail(&sglq_entry->list, &els_sgl_list);
4102 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4103 list_splice_init(&els_sgl_list,
4104 &phba->sli4_hba.lpfc_els_sgl_list);
4105 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4106 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
4107 /* els xri-sgl shrinked */
4108 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
4109 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4110 "3158 ELS xri-sgl count decreased from "
4111 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4113 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4114 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
4116 /* release extra els sgls from list */
4117 for (i = 0; i < xri_cnt; i++) {
4118 list_remove_head(&els_sgl_list,
4119 sglq_entry, struct lpfc_sglq, list);
4121 __lpfc_mbuf_free(phba, sglq_entry->virt,
4126 list_splice_init(&els_sgl_list,
4127 &phba->sli4_hba.lpfc_els_sgl_list);
4128 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4130 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4131 "3163 ELS xri-sgl count unchanged: %d\n",
4133 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
4135 /* update xris to els sgls on the list */
4137 sglq_entry_next = NULL;
4138 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4139 &phba->sli4_hba.lpfc_els_sgl_list, list) {
4140 lxri = lpfc_sli4_next_xritag(phba);
4141 if (lxri == NO_XRI) {
4142 lpfc_printf_log(phba, KERN_ERR,
4144 "2400 Failed to allocate xri for "
4149 sglq_entry->sli4_lxritag = lxri;
4150 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4155 lpfc_free_els_sgl_list(phba);
4160 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
4161 * @phba: pointer to lpfc hba data structure.
4163 * This routine first calculates the sizes of the current els and allocated
4164 * scsi sgl lists, and then goes through all sgls to updates the physical
4165 * XRIs assigned due to port function reset. During port initialization, the
4166 * current els and allocated scsi sgl lists are 0s.
4169 * 0 - successful (for now, it always returns 0)
4172 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4174 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4175 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4176 uint16_t nvmet_xri_cnt;
4177 LIST_HEAD(nvmet_sgl_list);
4181 * update on pci function's nvmet xri-sgl list
4183 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4185 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4186 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4187 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4188 /* els xri-sgl expanded */
4189 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4190 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4191 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4192 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4193 /* allocate the additional nvmet sgls */
4194 for (i = 0; i < xri_cnt; i++) {
4195 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4197 if (sglq_entry == NULL) {
4198 lpfc_printf_log(phba, KERN_ERR,
4200 "6303 Failure to allocate an "
4201 "NVMET sgl entry:%d\n", i);
4205 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4206 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4208 if (sglq_entry->virt == NULL) {
4210 lpfc_printf_log(phba, KERN_ERR,
4212 "6304 Failure to allocate an "
4213 "NVMET buf:%d\n", i);
4217 sglq_entry->sgl = sglq_entry->virt;
4218 memset(sglq_entry->sgl, 0,
4219 phba->cfg_sg_dma_buf_size);
4220 sglq_entry->state = SGL_FREED;
4221 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4223 spin_lock_irq(&phba->hbalock);
4224 spin_lock(&phba->sli4_hba.sgl_list_lock);
4225 list_splice_init(&nvmet_sgl_list,
4226 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4227 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4228 spin_unlock_irq(&phba->hbalock);
4229 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4230 /* nvmet xri-sgl shrunk */
4231 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4232 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4233 "6305 NVMET xri-sgl count decreased from "
4234 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4236 spin_lock_irq(&phba->hbalock);
4237 spin_lock(&phba->sli4_hba.sgl_list_lock);
4238 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4240 /* release extra nvmet sgls from list */
4241 for (i = 0; i < xri_cnt; i++) {
4242 list_remove_head(&nvmet_sgl_list,
4243 sglq_entry, struct lpfc_sglq, list);
4245 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4250 list_splice_init(&nvmet_sgl_list,
4251 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4252 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4253 spin_unlock_irq(&phba->hbalock);
4255 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4256 "6306 NVMET xri-sgl count unchanged: %d\n",
4258 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4260 /* update xris to nvmet sgls on the list */
4262 sglq_entry_next = NULL;
4263 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4264 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4265 lxri = lpfc_sli4_next_xritag(phba);
4266 if (lxri == NO_XRI) {
4267 lpfc_printf_log(phba, KERN_ERR,
4269 "6307 Failed to allocate xri for "
4274 sglq_entry->sli4_lxritag = lxri;
4275 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4280 lpfc_free_nvmet_sgl_list(phba);
4285 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4288 struct lpfc_sli4_hdw_queue *qp;
4289 struct lpfc_io_buf *lpfc_cmd;
4290 struct lpfc_io_buf *iobufp, *prev_iobufp;
4291 int idx, cnt, xri, inserted;
4294 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4295 qp = &phba->sli4_hba.hdwq[idx];
4296 spin_lock_irq(&qp->io_buf_list_get_lock);
4297 spin_lock(&qp->io_buf_list_put_lock);
4299 /* Take everything off the get and put lists */
4300 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4301 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4302 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4303 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4304 cnt += qp->get_io_bufs + qp->put_io_bufs;
4305 qp->get_io_bufs = 0;
4306 qp->put_io_bufs = 0;
4307 qp->total_io_bufs = 0;
4308 spin_unlock(&qp->io_buf_list_put_lock);
4309 spin_unlock_irq(&qp->io_buf_list_get_lock);
4313 * Take IO buffers off blist and put on cbuf sorted by XRI.
4314 * This is because POST_SGL takes a sequential range of XRIs
4315 * to post to the firmware.
4317 for (idx = 0; idx < cnt; idx++) {
4318 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
4322 list_add_tail(&lpfc_cmd->list, cbuf);
4325 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4328 list_for_each_entry(iobufp, cbuf, list) {
4329 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4331 list_add(&lpfc_cmd->list,
4332 &prev_iobufp->list);
4334 list_add(&lpfc_cmd->list, cbuf);
4338 prev_iobufp = iobufp;
4341 list_add_tail(&lpfc_cmd->list, cbuf);
4347 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4349 struct lpfc_sli4_hdw_queue *qp;
4350 struct lpfc_io_buf *lpfc_cmd;
4352 unsigned long iflags;
4354 qp = phba->sli4_hba.hdwq;
4356 while (!list_empty(cbuf)) {
4357 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4358 list_remove_head(cbuf, lpfc_cmd,
4359 struct lpfc_io_buf, list);
4363 qp = &phba->sli4_hba.hdwq[idx];
4364 lpfc_cmd->hdwq_no = idx;
4365 lpfc_cmd->hdwq = qp;
4366 lpfc_cmd->cur_iocbq.cmd_cmpl = NULL;
4367 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflags);
4368 list_add_tail(&lpfc_cmd->list,
4369 &qp->lpfc_io_buf_list_put);
4371 qp->total_io_bufs++;
4372 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
4380 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4381 * @phba: pointer to lpfc hba data structure.
4383 * This routine first calculates the sizes of the current els and allocated
4384 * scsi sgl lists, and then goes through all sgls to updates the physical
4385 * XRIs assigned due to port function reset. During port initialization, the
4386 * current els and allocated scsi sgl lists are 0s.
4389 * 0 - successful (for now, it always returns 0)
4392 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
4394 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
4395 uint16_t i, lxri, els_xri_cnt;
4396 uint16_t io_xri_cnt, io_xri_max;
4397 LIST_HEAD(io_sgl_list);
4401 * update on pci function's allocated nvme xri-sgl list
4404 /* maximum number of xris available for nvme buffers */
4405 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4406 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4407 phba->sli4_hba.io_xri_max = io_xri_max;
4409 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4410 "6074 Current allocated XRI sgl count:%d, "
4411 "maximum XRI count:%d els_xri_cnt:%d\n\n",
4412 phba->sli4_hba.io_xri_cnt,
4413 phba->sli4_hba.io_xri_max,
4416 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4418 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4419 /* max nvme xri shrunk below the allocated nvme buffers */
4420 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4421 phba->sli4_hba.io_xri_max;
4422 /* release the extra allocated nvme buffers */
4423 for (i = 0; i < io_xri_cnt; i++) {
4424 list_remove_head(&io_sgl_list, lpfc_ncmd,
4425 struct lpfc_io_buf, list);
4427 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4429 lpfc_ncmd->dma_handle);
4433 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4436 /* update xris associated to remaining allocated nvme buffers */
4438 lpfc_ncmd_next = NULL;
4439 phba->sli4_hba.io_xri_cnt = cnt;
4440 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4441 &io_sgl_list, list) {
4442 lxri = lpfc_sli4_next_xritag(phba);
4443 if (lxri == NO_XRI) {
4444 lpfc_printf_log(phba, KERN_ERR,
4446 "6075 Failed to allocate xri for "
4451 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4452 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4454 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4463 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4464 * @phba: Pointer to lpfc hba data structure.
4465 * @num_to_alloc: The requested number of buffers to allocate.
4467 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4468 * the nvme buffer contains all the necessary information needed to initiate
4469 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4470 * them on a list, it post them to the port by using SGL block post.
4473 * int - number of IO buffers that were allocated and posted.
4474 * 0 = failure, less than num_to_alloc is a partial failure.
4477 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4479 struct lpfc_io_buf *lpfc_ncmd;
4480 struct lpfc_iocbq *pwqeq;
4481 uint16_t iotag, lxri = 0;
4482 int bcnt, num_posted;
4483 LIST_HEAD(prep_nblist);
4484 LIST_HEAD(post_nblist);
4485 LIST_HEAD(nvme_nblist);
4487 phba->sli4_hba.io_xri_cnt = 0;
4488 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4489 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4493 * Get memory from the pci pool to map the virt space to
4494 * pci bus space for an I/O. The DMA buffer includes the
4495 * number of SGE's necessary to support the sg_tablesize.
4497 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4499 &lpfc_ncmd->dma_handle);
4500 if (!lpfc_ncmd->data) {
4505 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4506 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4509 * 4K Page alignment is CRITICAL to BlockGuard, double
4512 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4513 (((unsigned long)(lpfc_ncmd->data) &
4514 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4515 lpfc_printf_log(phba, KERN_ERR,
4517 "3369 Memory alignment err: "
4519 (unsigned long)lpfc_ncmd->data);
4520 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4522 lpfc_ncmd->dma_handle);
4528 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4530 lxri = lpfc_sli4_next_xritag(phba);
4531 if (lxri == NO_XRI) {
4532 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4533 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4537 pwqeq = &lpfc_ncmd->cur_iocbq;
4539 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4540 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4542 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4543 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4545 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4546 "6121 Failed to allocate IOTAG for"
4547 " XRI:0x%x\n", lxri);
4548 lpfc_sli4_free_xri(phba, lxri);
4551 pwqeq->sli4_lxritag = lxri;
4552 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4554 /* Initialize local short-hand pointers. */
4555 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4556 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4557 lpfc_ncmd->cur_iocbq.io_buf = lpfc_ncmd;
4558 spin_lock_init(&lpfc_ncmd->buf_lock);
4560 /* add the nvme buffer to a post list */
4561 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4562 phba->sli4_hba.io_xri_cnt++;
4564 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4565 "6114 Allocate %d out of %d requested new NVME "
4566 "buffers of size x%zu bytes\n", bcnt, num_to_alloc,
4567 sizeof(*lpfc_ncmd));
4570 /* post the list of nvme buffer sgls to port if available */
4571 if (!list_empty(&post_nblist))
4572 num_posted = lpfc_sli4_post_io_sgl_list(
4573 phba, &post_nblist, bcnt);
4581 lpfc_get_wwpn(struct lpfc_hba *phba)
4585 LPFC_MBOXQ_t *mboxq;
4588 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4591 return (uint64_t)-1;
4593 /* First get WWN of HBA instance */
4594 lpfc_read_nv(phba, mboxq);
4595 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4596 if (rc != MBX_SUCCESS) {
4597 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4598 "6019 Mailbox failed , mbxCmd x%x "
4599 "READ_NV, mbxStatus x%x\n",
4600 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4601 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4602 mempool_free(mboxq, phba->mbox_mem_pool);
4603 return (uint64_t) -1;
4606 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4607 /* wwn is WWPN of HBA instance */
4608 mempool_free(mboxq, phba->mbox_mem_pool);
4609 if (phba->sli_rev == LPFC_SLI_REV4)
4610 return be64_to_cpu(wwn);
4612 return rol64(wwn, 32);
4615 static unsigned short lpfc_get_sg_tablesize(struct lpfc_hba *phba)
4617 if (phba->sli_rev == LPFC_SLI_REV4)
4618 if (phba->cfg_xpsgl && !phba->nvmet_support)
4619 return LPFC_MAX_SG_TABLESIZE;
4621 return phba->cfg_scsi_seg_cnt;
4623 return phba->cfg_sg_seg_cnt;
4627 * lpfc_vmid_res_alloc - Allocates resources for VMID
4628 * @phba: pointer to lpfc hba data structure.
4629 * @vport: pointer to vport data structure
4631 * This routine allocated the resources needed for the VMID.
4638 lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4640 /* VMID feature is supported only on SLI4 */
4641 if (phba->sli_rev == LPFC_SLI_REV3) {
4642 phba->cfg_vmid_app_header = 0;
4643 phba->cfg_vmid_priority_tagging = 0;
4646 if (lpfc_is_vmid_enabled(phba)) {
4648 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4653 rwlock_init(&vport->vmid_lock);
4655 /* Set the VMID parameters for the vport */
4656 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4657 vport->vmid_inactivity_timeout =
4658 phba->cfg_vmid_inactivity_timeout;
4659 vport->max_vmid = phba->cfg_max_vmid;
4660 vport->cur_vmid_cnt = 0;
4662 vport->vmid_priority_range = bitmap_zalloc
4663 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4665 if (!vport->vmid_priority_range) {
4670 hash_init(vport->hash_table);
4676 * lpfc_create_port - Create an FC port
4677 * @phba: pointer to lpfc hba data structure.
4678 * @instance: a unique integer ID to this FC port.
4679 * @dev: pointer to the device data structure.
4681 * This routine creates a FC port for the upper layer protocol. The FC port
4682 * can be created on top of either a physical port or a virtual port provided
4683 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4684 * and associates the FC port created before adding the shost into the SCSI
4688 * @vport - pointer to the virtual N_Port data structure.
4689 * NULL - port create failed.
4692 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4694 struct lpfc_vport *vport;
4695 struct Scsi_Host *shost = NULL;
4696 struct scsi_host_template *template;
4700 bool use_no_reset_hba = false;
4703 if (lpfc_no_hba_reset_cnt) {
4704 if (phba->sli_rev < LPFC_SLI_REV4 &&
4705 dev == &phba->pcidev->dev) {
4706 /* Reset the port first */
4707 lpfc_sli_brdrestart(phba);
4708 rc = lpfc_sli_chipset_init(phba);
4712 wwn = lpfc_get_wwpn(phba);
4715 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4716 if (wwn == lpfc_no_hba_reset[i]) {
4717 lpfc_printf_log(phba, KERN_ERR,
4719 "6020 Setting use_no_reset port=%llx\n",
4721 use_no_reset_hba = true;
4726 /* Seed template for SCSI host registration */
4727 if (dev == &phba->pcidev->dev) {
4728 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4729 /* Seed physical port template */
4730 template = &lpfc_template;
4732 if (use_no_reset_hba)
4733 /* template is for a no reset SCSI Host */
4734 template->eh_host_reset_handler = NULL;
4736 /* Seed updated value of sg_tablesize */
4737 template->sg_tablesize = lpfc_get_sg_tablesize(phba);
4739 /* NVMET is for physical port only */
4740 template = &lpfc_template_nvme;
4743 /* Seed vport template */
4744 template = &lpfc_vport_template;
4746 /* Seed updated value of sg_tablesize */
4747 template->sg_tablesize = lpfc_get_sg_tablesize(phba);
4750 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
4754 vport = (struct lpfc_vport *) shost->hostdata;
4756 set_bit(FC_LOADING, &vport->load_flag);
4757 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
4758 vport->fc_rscn_flush = 0;
4759 atomic_set(&vport->fc_plogi_cnt, 0);
4760 atomic_set(&vport->fc_adisc_cnt, 0);
4761 atomic_set(&vport->fc_reglogin_cnt, 0);
4762 atomic_set(&vport->fc_prli_cnt, 0);
4763 atomic_set(&vport->fc_unmap_cnt, 0);
4764 atomic_set(&vport->fc_map_cnt, 0);
4765 atomic_set(&vport->fc_npr_cnt, 0);
4766 atomic_set(&vport->fc_unused_cnt, 0);
4767 lpfc_get_vport_cfgparam(vport);
4769 /* Adjust value in vport */
4770 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4772 shost->unique_id = instance;
4773 shost->max_id = LPFC_MAX_TARGET;
4774 shost->max_lun = vport->cfg_max_luns;
4775 shost->this_id = -1;
4776 if (phba->sli_rev == LPFC_SLI_REV4)
4777 shost->max_cmd_len = LPFC_FCP_CDB_LEN_32;
4779 shost->max_cmd_len = LPFC_FCP_CDB_LEN;
4781 if (phba->sli_rev == LPFC_SLI_REV4) {
4782 if (!phba->cfg_fcp_mq_threshold ||
4783 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4784 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4786 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4787 phba->cfg_fcp_mq_threshold);
4789 shost->dma_boundary =
4790 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4792 /* SLI-3 has a limited number of hardware queues (3),
4793 * thus there is only one for FCP processing.
4795 shost->nr_hw_queues = 1;
4798 * Set initial can_queue value since 0 is no longer supported and
4799 * scsi_add_host will fail. This will be adjusted later based on the
4800 * max xri value determined in hba setup.
4802 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4803 if (dev != &phba->pcidev->dev) {
4804 shost->transportt = lpfc_vport_transport_template;
4805 vport->port_type = LPFC_NPIV_PORT;
4807 shost->transportt = lpfc_transport_template;
4808 vport->port_type = LPFC_PHYSICAL_PORT;
4811 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4812 "9081 CreatePort TMPLATE type %x TBLsize %d "
4814 vport->port_type, shost->sg_tablesize,
4815 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4817 /* Allocate the resources for VMID */
4818 rc = lpfc_vmid_res_alloc(phba, vport);
4823 /* Initialize all internally managed lists. */
4824 INIT_LIST_HEAD(&vport->fc_nodes);
4825 spin_lock_init(&vport->fc_nodes_list_lock);
4826 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4827 spin_lock_init(&vport->work_port_lock);
4829 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4831 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4833 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4835 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4836 lpfc_setup_bg(phba, shost);
4838 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4842 spin_lock_irq(&phba->port_list_lock);
4843 list_add_tail(&vport->listentry, &phba->port_list);
4844 spin_unlock_irq(&phba->port_list_lock);
4849 bitmap_free(vport->vmid_priority_range);
4851 scsi_host_put(shost);
4857 * destroy_port - destroy an FC port
4858 * @vport: pointer to an lpfc virtual N_Port data structure.
4860 * This routine destroys a FC port from the upper layer protocol. All the
4861 * resources associated with the port are released.
4864 destroy_port(struct lpfc_vport *vport)
4866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4867 struct lpfc_hba *phba = vport->phba;
4869 lpfc_debugfs_terminate(vport);
4870 fc_remove_host(shost);
4871 scsi_remove_host(shost);
4873 spin_lock_irq(&phba->port_list_lock);
4874 list_del_init(&vport->listentry);
4875 spin_unlock_irq(&phba->port_list_lock);
4877 lpfc_cleanup(vport);
4882 * lpfc_get_instance - Get a unique integer ID
4884 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4885 * uses the kernel idr facility to perform the task.
4888 * instance - a unique integer ID allocated as the new instance.
4889 * -1 - lpfc get instance failed.
4892 lpfc_get_instance(void)
4896 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4897 return ret < 0 ? -1 : ret;
4901 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4902 * @shost: pointer to SCSI host data structure.
4903 * @time: elapsed time of the scan in jiffies.
4905 * This routine is called by the SCSI layer with a SCSI host to determine
4906 * whether the scan host is finished.
4908 * Note: there is no scan_start function as adapter initialization will have
4909 * asynchronously kicked off the link initialization.
4912 * 0 - SCSI host scan is not over yet.
4913 * 1 - SCSI host scan is over.
4915 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4917 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4918 struct lpfc_hba *phba = vport->phba;
4921 spin_lock_irq(shost->host_lock);
4923 if (test_bit(FC_UNLOADING, &vport->load_flag)) {
4927 if (time >= msecs_to_jiffies(30 * 1000)) {
4928 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4929 "0461 Scanning longer than 30 "
4930 "seconds. Continuing initialization\n");
4934 if (time >= msecs_to_jiffies(15 * 1000) &&
4935 phba->link_state <= LPFC_LINK_DOWN) {
4936 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4937 "0465 Link down longer than 15 "
4938 "seconds. Continuing initialization\n");
4943 if (vport->port_state != LPFC_VPORT_READY)
4945 if (vport->num_disc_nodes || vport->fc_prli_sent)
4947 if (!atomic_read(&vport->fc_map_cnt) &&
4948 time < msecs_to_jiffies(2 * 1000))
4950 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4956 spin_unlock_irq(shost->host_lock);
4960 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4962 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4963 struct lpfc_hba *phba = vport->phba;
4965 fc_host_supported_speeds(shost) = 0;
4967 * Avoid reporting supported link speed for FCoE as it can't be
4968 * controlled via FCoE.
4970 if (test_bit(HBA_FCOE_MODE, &phba->hba_flag))
4973 if (phba->lmt & LMT_256Gb)
4974 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
4975 if (phba->lmt & LMT_128Gb)
4976 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4977 if (phba->lmt & LMT_64Gb)
4978 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4979 if (phba->lmt & LMT_32Gb)
4980 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4981 if (phba->lmt & LMT_16Gb)
4982 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4983 if (phba->lmt & LMT_10Gb)
4984 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4985 if (phba->lmt & LMT_8Gb)
4986 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4987 if (phba->lmt & LMT_4Gb)
4988 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4989 if (phba->lmt & LMT_2Gb)
4990 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4991 if (phba->lmt & LMT_1Gb)
4992 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4996 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4997 * @shost: pointer to SCSI host data structure.
4999 * This routine initializes a given SCSI host attributes on a FC port. The
5000 * SCSI host can be either on top of a physical port or a virtual port.
5002 void lpfc_host_attrib_init(struct Scsi_Host *shost)
5004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5005 struct lpfc_hba *phba = vport->phba;
5007 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
5010 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
5011 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
5012 fc_host_supported_classes(shost) = FC_COS_CLASS3;
5014 memset(fc_host_supported_fc4s(shost), 0,
5015 sizeof(fc_host_supported_fc4s(shost)));
5016 fc_host_supported_fc4s(shost)[2] = 1;
5017 fc_host_supported_fc4s(shost)[7] = 1;
5019 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5020 sizeof fc_host_symbolic_name(shost));
5022 lpfc_host_supported_speeds_set(shost);
5024 fc_host_maxframe_size(shost) =
5025 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
5026 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
5028 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
5030 /* This value is also unchanging */
5031 memset(fc_host_active_fc4s(shost), 0,
5032 sizeof(fc_host_active_fc4s(shost)));
5033 fc_host_active_fc4s(shost)[2] = 1;
5034 fc_host_active_fc4s(shost)[7] = 1;
5036 fc_host_max_npiv_vports(shost) = phba->max_vpi;
5037 clear_bit(FC_LOADING, &vport->load_flag);
5041 * lpfc_stop_port_s3 - Stop SLI3 device port
5042 * @phba: pointer to lpfc hba data structure.
5044 * This routine is invoked to stop an SLI3 device port, it stops the device
5045 * from generating interrupts and stops the device driver's timers for the
5049 lpfc_stop_port_s3(struct lpfc_hba *phba)
5051 /* Clear all interrupt enable conditions */
5052 writel(0, phba->HCregaddr);
5053 readl(phba->HCregaddr); /* flush */
5054 /* Clear all pending interrupts */
5055 writel(0xffffffff, phba->HAregaddr);
5056 readl(phba->HAregaddr); /* flush */
5058 /* Reset some HBA SLI setup states */
5059 lpfc_stop_hba_timers(phba);
5060 phba->pport->work_port_events = 0;
5064 * lpfc_stop_port_s4 - Stop SLI4 device port
5065 * @phba: pointer to lpfc hba data structure.
5067 * This routine is invoked to stop an SLI4 device port, it stops the device
5068 * from generating interrupts and stops the device driver's timers for the
5072 lpfc_stop_port_s4(struct lpfc_hba *phba)
5074 /* Reset some HBA SLI4 setup states */
5075 lpfc_stop_hba_timers(phba);
5077 phba->pport->work_port_events = 0;
5078 phba->sli4_hba.intr_enable = 0;
5082 * lpfc_stop_port - Wrapper function for stopping hba port
5083 * @phba: Pointer to HBA context object.
5085 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
5086 * the API jump table function pointer from the lpfc_hba struct.
5089 lpfc_stop_port(struct lpfc_hba *phba)
5091 phba->lpfc_stop_port(phba);
5094 flush_workqueue(phba->wq);
5098 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
5099 * @phba: Pointer to hba for which this call is being executed.
5101 * This routine starts the timer waiting for the FCF rediscovery to complete.
5104 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
5106 unsigned long fcf_redisc_wait_tmo =
5107 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
5108 /* Start fcf rediscovery wait period timer */
5109 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
5110 spin_lock_irq(&phba->hbalock);
5111 /* Allow action to new fcf asynchronous event */
5112 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
5113 /* Mark the FCF rediscovery pending state */
5114 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
5115 spin_unlock_irq(&phba->hbalock);
5119 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
5120 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5122 * This routine is invoked when waiting for FCF table rediscover has been
5123 * timed out. If new FCF record(s) has (have) been discovered during the
5124 * wait period, a new FCF event shall be added to the FCOE async event
5125 * list, and then worker thread shall be waked up for processing from the
5126 * worker thread context.
5129 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
5131 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
5133 /* Don't send FCF rediscovery event if timer cancelled */
5134 spin_lock_irq(&phba->hbalock);
5135 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
5136 spin_unlock_irq(&phba->hbalock);
5139 /* Clear FCF rediscovery timer pending flag */
5140 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
5141 /* FCF rediscovery event to worker thread */
5142 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
5143 spin_unlock_irq(&phba->hbalock);
5144 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
5145 "2776 FCF rediscover quiescent timer expired\n");
5146 /* wake up worker thread */
5147 lpfc_worker_wake_up(phba);
5151 * lpfc_vmid_poll - VMID timeout detection
5152 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5154 * This routine is invoked when there is no I/O on by a VM for the specified
5155 * amount of time. When this situation is detected, the VMID has to be
5156 * deregistered from the switch and all the local resources freed. The VMID
5157 * will be reassigned to the VM once the I/O begins.
5160 lpfc_vmid_poll(struct timer_list *t)
5162 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
5165 /* check if there is a need to issue QFPA */
5166 if (phba->pport->vmid_priority_tagging) {
5168 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5171 /* Is the vmid inactivity timer enabled */
5172 if (phba->pport->vmid_inactivity_timeout ||
5173 test_bit(FC_DEREGISTER_ALL_APP_ID, &phba->pport->load_flag)) {
5175 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5179 lpfc_worker_wake_up(phba);
5181 /* restart the timer for the next iteration */
5182 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5187 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5188 * @phba: pointer to lpfc hba data structure.
5189 * @acqe_link: pointer to the async link completion queue entry.
5191 * This routine is to parse the SLI4 link-attention link fault code.
5194 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5195 struct lpfc_acqe_link *acqe_link)
5197 switch (bf_get(lpfc_acqe_fc_la_att_type, acqe_link)) {
5198 case LPFC_FC_LA_TYPE_LINK_DOWN:
5199 case LPFC_FC_LA_TYPE_TRUNKING_EVENT:
5200 case LPFC_FC_LA_TYPE_ACTIVATE_FAIL:
5201 case LPFC_FC_LA_TYPE_LINK_RESET_PRTCL_EVT:
5204 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5205 case LPFC_ASYNC_LINK_FAULT_NONE:
5206 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5207 case LPFC_ASYNC_LINK_FAULT_REMOTE:
5208 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
5211 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5212 "0398 Unknown link fault code: x%x\n",
5213 bf_get(lpfc_acqe_link_fault, acqe_link));
5221 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5222 * @phba: pointer to lpfc hba data structure.
5223 * @acqe_link: pointer to the async link completion queue entry.
5225 * This routine is to parse the SLI4 link attention type and translate it
5226 * into the base driver's link attention type coding.
5228 * Return: Link attention type in terms of base driver's coding.
5231 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5232 struct lpfc_acqe_link *acqe_link)
5236 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5237 case LPFC_ASYNC_LINK_STATUS_DOWN:
5238 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
5239 att_type = LPFC_ATT_LINK_DOWN;
5241 case LPFC_ASYNC_LINK_STATUS_UP:
5242 /* Ignore physical link up events - wait for logical link up */
5243 att_type = LPFC_ATT_RESERVED;
5245 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
5246 att_type = LPFC_ATT_LINK_UP;
5249 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5250 "0399 Invalid link attention type: x%x\n",
5251 bf_get(lpfc_acqe_link_status, acqe_link));
5252 att_type = LPFC_ATT_RESERVED;
5259 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5260 * @phba: pointer to lpfc hba data structure.
5262 * This routine is to get an SLI3 FC port's link speed in Mbps.
5264 * Return: link speed in terms of Mbps.
5267 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5269 uint32_t link_speed;
5271 if (!lpfc_is_link_up(phba))
5274 if (phba->sli_rev <= LPFC_SLI_REV3) {
5275 switch (phba->fc_linkspeed) {
5276 case LPFC_LINK_SPEED_1GHZ:
5279 case LPFC_LINK_SPEED_2GHZ:
5282 case LPFC_LINK_SPEED_4GHZ:
5285 case LPFC_LINK_SPEED_8GHZ:
5288 case LPFC_LINK_SPEED_10GHZ:
5291 case LPFC_LINK_SPEED_16GHZ:
5298 if (phba->sli4_hba.link_state.logical_speed)
5300 phba->sli4_hba.link_state.logical_speed;
5302 link_speed = phba->sli4_hba.link_state.speed;
5308 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5309 * @phba: pointer to lpfc hba data structure.
5310 * @evt_code: asynchronous event code.
5311 * @speed_code: asynchronous event link speed code.
5313 * This routine is to parse the giving SLI4 async event link speed code into
5314 * value of Mbps for the link speed.
5316 * Return: link speed in terms of Mbps.
5319 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5322 uint32_t port_speed;
5325 case LPFC_TRAILER_CODE_LINK:
5326 switch (speed_code) {
5327 case LPFC_ASYNC_LINK_SPEED_ZERO:
5330 case LPFC_ASYNC_LINK_SPEED_10MBPS:
5333 case LPFC_ASYNC_LINK_SPEED_100MBPS:
5336 case LPFC_ASYNC_LINK_SPEED_1GBPS:
5339 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5342 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5345 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5348 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5351 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5352 port_speed = 100000;
5358 case LPFC_TRAILER_CODE_FC:
5359 switch (speed_code) {
5360 case LPFC_FC_LA_SPEED_UNKNOWN:
5363 case LPFC_FC_LA_SPEED_1G:
5366 case LPFC_FC_LA_SPEED_2G:
5369 case LPFC_FC_LA_SPEED_4G:
5372 case LPFC_FC_LA_SPEED_8G:
5375 case LPFC_FC_LA_SPEED_10G:
5378 case LPFC_FC_LA_SPEED_16G:
5381 case LPFC_FC_LA_SPEED_32G:
5384 case LPFC_FC_LA_SPEED_64G:
5387 case LPFC_FC_LA_SPEED_128G:
5388 port_speed = 128000;
5390 case LPFC_FC_LA_SPEED_256G:
5391 port_speed = 256000;
5404 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
5405 * @phba: pointer to lpfc hba data structure.
5406 * @acqe_link: pointer to the async link completion queue entry.
5408 * This routine is to handle the SLI4 asynchronous FCoE link event.
5411 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5412 struct lpfc_acqe_link *acqe_link)
5416 struct lpfc_mbx_read_top *la;
5420 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
5421 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
5423 phba->fcoe_eventtag = acqe_link->event_tag;
5424 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5426 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5427 "0395 The mboxq allocation failed\n");
5431 rc = lpfc_mbox_rsrc_prep(phba, pmb);
5433 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5434 "0396 mailbox allocation failed\n");
5438 /* Cleanup any outstanding ELS commands */
5439 lpfc_els_flush_all_cmd(phba);
5441 /* Block ELS IOCBs until we have done process link event */
5442 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5444 /* Update link event statistics */
5445 phba->sli.slistat.link_event++;
5447 /* Create lpfc_handle_latt mailbox command from link ACQE */
5448 lpfc_read_topology(phba, pmb, pmb->ctx_buf);
5449 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5450 pmb->vport = phba->pport;
5452 /* Keep the link status for extra SLI4 state machine reference */
5453 phba->sli4_hba.link_state.speed =
5454 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5455 bf_get(lpfc_acqe_link_speed, acqe_link));
5456 phba->sli4_hba.link_state.duplex =
5457 bf_get(lpfc_acqe_link_duplex, acqe_link);
5458 phba->sli4_hba.link_state.status =
5459 bf_get(lpfc_acqe_link_status, acqe_link);
5460 phba->sli4_hba.link_state.type =
5461 bf_get(lpfc_acqe_link_type, acqe_link);
5462 phba->sli4_hba.link_state.number =
5463 bf_get(lpfc_acqe_link_number, acqe_link);
5464 phba->sli4_hba.link_state.fault =
5465 bf_get(lpfc_acqe_link_fault, acqe_link);
5466 phba->sli4_hba.link_state.logical_speed =
5467 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5469 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5470 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5471 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5472 "Logical speed:%dMbps Fault:%d\n",
5473 phba->sli4_hba.link_state.speed,
5474 phba->sli4_hba.link_state.topology,
5475 phba->sli4_hba.link_state.status,
5476 phba->sli4_hba.link_state.type,
5477 phba->sli4_hba.link_state.number,
5478 phba->sli4_hba.link_state.logical_speed,
5479 phba->sli4_hba.link_state.fault);
5481 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5482 * topology info. Note: Optional for non FC-AL ports.
5484 if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
5485 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5486 if (rc == MBX_NOT_FINISHED)
5491 * For FCoE Mode: fill in all the topology information we need and call
5492 * the READ_TOPOLOGY completion routine to continue without actually
5493 * sending the READ_TOPOLOGY mailbox command to the port.
5495 /* Initialize completion status */
5497 mb->mbxStatus = MBX_SUCCESS;
5499 /* Parse port fault information field */
5500 lpfc_sli4_parse_latt_fault(phba, acqe_link);
5502 /* Parse and translate link attention fields */
5503 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5504 la->eventTag = acqe_link->event_tag;
5505 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5506 bf_set(lpfc_mbx_read_top_link_spd, la,
5507 (bf_get(lpfc_acqe_link_speed, acqe_link)));
5509 /* Fake the following irrelevant fields */
5510 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5511 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5512 bf_set(lpfc_mbx_read_top_il, la, 0);
5513 bf_set(lpfc_mbx_read_top_pb, la, 0);
5514 bf_set(lpfc_mbx_read_top_fa, la, 0);
5515 bf_set(lpfc_mbx_read_top_mm, la, 0);
5517 /* Invoke the lpfc_handle_latt mailbox command callback function */
5518 lpfc_mbx_cmpl_read_topology(phba, pmb);
5523 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5527 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5529 * @phba: pointer to lpfc hba data structure.
5530 * @speed_code: asynchronous event link speed code.
5532 * This routine is to parse the giving SLI4 async event link speed code into
5533 * value of Read topology link speed.
5535 * Return: link speed in terms of Read topology.
5538 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5542 switch (speed_code) {
5543 case LPFC_FC_LA_SPEED_1G:
5544 port_speed = LPFC_LINK_SPEED_1GHZ;
5546 case LPFC_FC_LA_SPEED_2G:
5547 port_speed = LPFC_LINK_SPEED_2GHZ;
5549 case LPFC_FC_LA_SPEED_4G:
5550 port_speed = LPFC_LINK_SPEED_4GHZ;
5552 case LPFC_FC_LA_SPEED_8G:
5553 port_speed = LPFC_LINK_SPEED_8GHZ;
5555 case LPFC_FC_LA_SPEED_16G:
5556 port_speed = LPFC_LINK_SPEED_16GHZ;
5558 case LPFC_FC_LA_SPEED_32G:
5559 port_speed = LPFC_LINK_SPEED_32GHZ;
5561 case LPFC_FC_LA_SPEED_64G:
5562 port_speed = LPFC_LINK_SPEED_64GHZ;
5564 case LPFC_FC_LA_SPEED_128G:
5565 port_speed = LPFC_LINK_SPEED_128GHZ;
5567 case LPFC_FC_LA_SPEED_256G:
5568 port_speed = LPFC_LINK_SPEED_256GHZ;
5579 lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
5581 if (!phba->rx_monitor) {
5582 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5583 "4411 Rx Monitor Info is empty.\n");
5585 lpfc_rx_monitor_report(phba, phba->rx_monitor, NULL, 0,
5586 LPFC_MAX_RXMONITOR_DUMP);
5591 * lpfc_cgn_update_stat - Save data into congestion stats buffer
5592 * @phba: pointer to lpfc hba data structure.
5593 * @dtag: FPIN descriptor received
5595 * Increment the FPIN received counter/time when it happens.
5598 lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
5600 struct lpfc_cgn_info *cp;
5603 /* Make sure we have a congestion info buffer */
5606 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5608 /* Update congestion statistics */
5610 case ELS_DTAG_LNK_INTEGRITY:
5611 le32_add_cpu(&cp->link_integ_notification, 1);
5612 lpfc_cgn_update_tstamp(phba, &cp->stat_lnk);
5614 case ELS_DTAG_DELIVERY:
5615 le32_add_cpu(&cp->delivery_notification, 1);
5616 lpfc_cgn_update_tstamp(phba, &cp->stat_delivery);
5618 case ELS_DTAG_PEER_CONGEST:
5619 le32_add_cpu(&cp->cgn_peer_notification, 1);
5620 lpfc_cgn_update_tstamp(phba, &cp->stat_peer);
5622 case ELS_DTAG_CONGESTION:
5623 le32_add_cpu(&cp->cgn_notification, 1);
5624 lpfc_cgn_update_tstamp(phba, &cp->stat_fpin);
5626 if (phba->cgn_fpin_frequency &&
5627 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5628 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5629 cp->cgn_stat_npm = value;
5632 value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5633 LPFC_CGN_CRC32_SEED);
5634 cp->cgn_info_crc = cpu_to_le32(value);
5638 * lpfc_cgn_update_tstamp - Update cmf timestamp
5639 * @phba: pointer to lpfc hba data structure.
5640 * @ts: structure to write the timestamp to.
5643 lpfc_cgn_update_tstamp(struct lpfc_hba *phba, struct lpfc_cgn_ts *ts)
5645 struct timespec64 cur_time;
5648 ktime_get_real_ts64(&cur_time);
5649 time64_to_tm(cur_time.tv_sec, 0, &tm_val);
5651 ts->month = tm_val.tm_mon + 1;
5652 ts->day = tm_val.tm_mday;
5653 ts->year = tm_val.tm_year - 100;
5654 ts->hour = tm_val.tm_hour;
5655 ts->minute = tm_val.tm_min;
5656 ts->second = tm_val.tm_sec;
5658 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5659 "2646 Updated CMF timestamp : "
5660 "%u/%u/%u %u:%u:%u\n",
5663 ts->minute, ts->second);
5667 * lpfc_cmf_stats_timer - Save data into registered congestion buffer
5668 * @timer: Timer cookie to access lpfc private data
5670 * Save the congestion event data every minute.
5671 * On the hour collapse all the minute data into hour data. Every day
5672 * collapse all the hour data into daily data. Separate driver
5673 * and fabrc congestion event counters that will be saved out
5674 * to the registered congestion buffer every minute.
5676 static enum hrtimer_restart
5677 lpfc_cmf_stats_timer(struct hrtimer *timer)
5679 struct lpfc_hba *phba;
5680 struct lpfc_cgn_info *cp;
5682 uint16_t value, mvalue;
5685 uint32_t dvalue, wvalue, lvalue, avalue;
5691 phba = container_of(timer, struct lpfc_hba, cmf_stats_timer);
5692 /* Make sure we have a congestion info buffer */
5694 return HRTIMER_NORESTART;
5695 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5697 phba->cgn_evt_timestamp = jiffies +
5698 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
5699 phba->cgn_evt_minute++;
5701 /* We should get to this point in the routine on 1 minute intervals */
5702 lpfc_cgn_update_tstamp(phba, &cp->base_time);
5704 if (phba->cgn_fpin_frequency &&
5705 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5706 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5707 cp->cgn_stat_npm = value;
5710 /* Read and clear the latency counters for this minute */
5711 lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
5712 latsum = atomic64_read(&phba->cgn_latency_evt);
5713 atomic_set(&phba->cgn_latency_evt_cnt, 0);
5714 atomic64_set(&phba->cgn_latency_evt, 0);
5716 /* We need to store MB/sec bandwidth in the congestion information.
5717 * block_cnt is count of 512 byte blocks for the entire minute,
5718 * bps will get bytes per sec before finally converting to MB/sec.
5720 bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
5721 phba->rx_block_cnt = 0;
5722 mvalue = bps / (1024 * 1024); /* convert to MB/sec */
5725 /* cgn parameters */
5726 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
5727 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
5728 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
5729 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
5731 /* Fill in default LUN qdepth */
5732 value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
5733 cp->cgn_lunq = cpu_to_le16(value);
5735 /* Record congestion buffer info - every minute
5736 * cgn_driver_evt_cnt (Driver events)
5737 * cgn_fabric_warn_cnt (Congestion Warnings)
5738 * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
5739 * cgn_fabric_alarm_cnt (Congestion Alarms)
5741 index = ++cp->cgn_index_minute;
5742 if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
5743 cp->cgn_index_minute = 0;
5747 /* Get the number of driver events in this sample and reset counter */
5748 dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
5749 atomic_set(&phba->cgn_driver_evt_cnt, 0);
5751 /* Get the number of warning events - FPIN and Signal for this minute */
5753 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
5754 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5755 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5756 wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
5757 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
5759 /* Get the number of alarm events - FPIN and Signal for this minute */
5761 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
5762 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5763 avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
5764 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
5766 /* Collect the driver, warning, alarm and latency counts for this
5767 * minute into the driver congestion buffer.
5769 ptr = &cp->cgn_drvr_min[index];
5770 value = (uint16_t)dvalue;
5771 *ptr = cpu_to_le16(value);
5773 ptr = &cp->cgn_warn_min[index];
5774 value = (uint16_t)wvalue;
5775 *ptr = cpu_to_le16(value);
5777 ptr = &cp->cgn_alarm_min[index];
5778 value = (uint16_t)avalue;
5779 *ptr = cpu_to_le16(value);
5781 lptr = &cp->cgn_latency_min[index];
5783 lvalue = (uint32_t)div_u64(latsum, lvalue);
5784 *lptr = cpu_to_le32(lvalue);
5789 /* Collect the bandwidth value into the driver's congesion buffer. */
5790 mptr = &cp->cgn_bw_min[index];
5791 *mptr = cpu_to_le16(mvalue);
5793 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5794 "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
5795 index, dvalue, wvalue, *lptr, mvalue, avalue);
5798 if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
5799 /* Record congestion buffer info - every hour
5800 * Collapse all minutes into an hour
5802 index = ++cp->cgn_index_hour;
5803 if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
5804 cp->cgn_index_hour = 0;
5814 for (i = 0; i < LPFC_MIN_HOUR; i++) {
5815 dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
5816 wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
5817 lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
5818 mbps += le16_to_cpu(cp->cgn_bw_min[i]);
5819 avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
5821 if (lvalue) /* Avg of latency averages */
5822 lvalue /= LPFC_MIN_HOUR;
5823 if (mbps) /* Avg of Bandwidth averages */
5824 mvalue = mbps / LPFC_MIN_HOUR;
5826 lptr = &cp->cgn_drvr_hr[index];
5827 *lptr = cpu_to_le32(dvalue);
5828 lptr = &cp->cgn_warn_hr[index];
5829 *lptr = cpu_to_le32(wvalue);
5830 lptr = &cp->cgn_latency_hr[index];
5831 *lptr = cpu_to_le32(lvalue);
5832 mptr = &cp->cgn_bw_hr[index];
5833 *mptr = cpu_to_le16(mvalue);
5834 lptr = &cp->cgn_alarm_hr[index];
5835 *lptr = cpu_to_le32(avalue);
5837 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5838 "2419 Congestion Info - hour "
5839 "(%d): %d %d %d %d %d\n",
5840 index, dvalue, wvalue, lvalue, mvalue, avalue);
5844 if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
5845 /* Record congestion buffer info - every hour
5846 * Collapse all hours into a day. Rotate days
5847 * after LPFC_MAX_CGN_DAYS.
5849 index = ++cp->cgn_index_day;
5850 if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
5851 cp->cgn_index_day = 0;
5861 for (i = 0; i < LPFC_HOUR_DAY; i++) {
5862 dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
5863 wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
5864 lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
5865 mbps += le16_to_cpu(cp->cgn_bw_hr[i]);
5866 avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
5868 if (lvalue) /* Avg of latency averages */
5869 lvalue /= LPFC_HOUR_DAY;
5870 if (mbps) /* Avg of Bandwidth averages */
5871 mvalue = mbps / LPFC_HOUR_DAY;
5873 lptr = &cp->cgn_drvr_day[index];
5874 *lptr = cpu_to_le32(dvalue);
5875 lptr = &cp->cgn_warn_day[index];
5876 *lptr = cpu_to_le32(wvalue);
5877 lptr = &cp->cgn_latency_day[index];
5878 *lptr = cpu_to_le32(lvalue);
5879 mptr = &cp->cgn_bw_day[index];
5880 *mptr = cpu_to_le16(mvalue);
5881 lptr = &cp->cgn_alarm_day[index];
5882 *lptr = cpu_to_le32(avalue);
5884 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5885 "2420 Congestion Info - daily (%d): "
5887 index, dvalue, wvalue, lvalue, mvalue, avalue);
5890 /* Use the frequency found in the last rcv'ed FPIN */
5891 value = phba->cgn_fpin_frequency;
5892 cp->cgn_warn_freq = cpu_to_le16(value);
5893 cp->cgn_alarm_freq = cpu_to_le16(value);
5895 lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5896 LPFC_CGN_CRC32_SEED);
5897 cp->cgn_info_crc = cpu_to_le32(lvalue);
5899 hrtimer_forward_now(timer, ktime_set(0, LPFC_SEC_MIN * NSEC_PER_SEC));
5901 return HRTIMER_RESTART;
5905 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5906 * @phba: The Hba for which this call is being executed.
5908 * The routine calculates the latency from the beginning of the CMF timer
5909 * interval to the current point in time. It is called from IO completion
5910 * when we exceed our Bandwidth limitation for the time interval.
5913 lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5915 struct timespec64 cmpl_time;
5918 ktime_get_real_ts64(&cmpl_time);
5920 /* This routine works on a ms granularity so sec and usec are
5921 * converted accordingly.
5923 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5924 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5927 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5928 msec = (cmpl_time.tv_sec -
5929 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5930 msec += ((cmpl_time.tv_nsec -
5931 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5933 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5935 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5936 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5943 * lpfc_cmf_timer - This is the timer function for one congestion
5945 * @timer: Pointer to the high resolution timer that expired
5947 static enum hrtimer_restart
5948 lpfc_cmf_timer(struct hrtimer *timer)
5950 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5952 struct rx_info_entry entry;
5954 uint32_t busy, max_read;
5955 uint64_t total, rcv, lat, mbpi, extra, cnt;
5956 int timer_interval = LPFC_CMF_INTERVAL;
5958 struct lpfc_cgn_stat *cgs;
5961 /* Only restart the timer if congestion mgmt is on */
5962 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5963 !phba->cmf_latency.tv_sec) {
5964 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5965 "6224 CMF timer exit: %d %lld\n",
5966 phba->cmf_active_mode,
5967 (uint64_t)phba->cmf_latency.tv_sec);
5968 return HRTIMER_NORESTART;
5971 /* If pport is not ready yet, just exit and wait for
5972 * the next timer cycle to hit.
5977 /* Do not block SCSI IO while in the timer routine since
5978 * total_bytes will be cleared
5980 atomic_set(&phba->cmf_stop_io, 1);
5982 /* First we need to calculate the actual ms between
5983 * the last timer interrupt and this one. We ask for
5984 * LPFC_CMF_INTERVAL, however the actual time may
5985 * vary depending on system overhead.
5987 ms = lpfc_calc_cmf_latency(phba);
5990 /* Immediately after we calculate the time since the last
5991 * timer interrupt, set the start time for the next
5994 ktime_get_real_ts64(&phba->cmf_latency);
5996 phba->cmf_link_byte_count =
5997 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
5999 /* Collect all the stats from the prior timer interval */
6004 for_each_present_cpu(cpu) {
6005 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
6006 total += atomic64_xchg(&cgs->total_bytes, 0);
6007 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
6008 lat += atomic64_xchg(&cgs->rx_latency, 0);
6009 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
6012 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
6013 * returned from the last CMF_SYNC_WQE issued, from
6014 * cmf_last_sync_bw. This will be the target BW for
6015 * this next timer interval.
6017 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
6018 phba->link_state != LPFC_LINK_DOWN &&
6019 test_bit(HBA_SETUP, &phba->hba_flag)) {
6020 mbpi = phba->cmf_last_sync_bw;
6021 phba->cmf_last_sync_bw = 0;
6024 /* Calculate any extra bytes needed to account for the
6025 * timer accuracy. If we are less than LPFC_CMF_INTERVAL
6026 * calculate the adjustment needed for total to reflect
6027 * a full LPFC_CMF_INTERVAL.
6029 if (ms && ms < LPFC_CMF_INTERVAL) {
6030 cnt = div_u64(total, ms); /* bytes per ms */
6031 cnt *= LPFC_CMF_INTERVAL; /* what total should be */
6032 extra = cnt - total;
6034 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
6036 /* For Monitor mode or link down we want mbpi
6037 * to be the full link speed
6039 mbpi = phba->cmf_link_byte_count;
6042 phba->cmf_timer_cnt++;
6045 /* Update congestion info buffer latency in us */
6046 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
6047 atomic64_add(lat, &phba->cgn_latency_evt);
6049 busy = atomic_xchg(&phba->cmf_busy, 0);
6050 max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
6052 /* Calculate MBPI for the next timer interval */
6054 if (mbpi > phba->cmf_link_byte_count ||
6055 phba->cmf_active_mode == LPFC_CFG_MONITOR)
6056 mbpi = phba->cmf_link_byte_count;
6058 /* Change max_bytes_per_interval to what the prior
6059 * CMF_SYNC_WQE cmpl indicated.
6061 if (mbpi != phba->cmf_max_bytes_per_interval)
6062 phba->cmf_max_bytes_per_interval = mbpi;
6065 /* Save rxmonitor information for debug */
6066 if (phba->rx_monitor) {
6067 entry.total_bytes = total;
6068 entry.cmf_bytes = total + extra;
6069 entry.rcv_bytes = rcv;
6070 entry.cmf_busy = busy;
6071 entry.cmf_info = phba->cmf_active_info;
6073 entry.avg_io_latency = div_u64(lat, io_cnt);
6074 entry.avg_io_size = div_u64(rcv, io_cnt);
6076 entry.avg_io_latency = 0;
6077 entry.avg_io_size = 0;
6079 entry.max_read_cnt = max_read;
6080 entry.io_cnt = io_cnt;
6081 entry.max_bytes_per_interval = mbpi;
6082 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
6083 entry.timer_utilization = phba->cmf_last_ts;
6085 entry.timer_utilization = ms;
6086 entry.timer_interval = ms;
6087 phba->cmf_last_ts = 0;
6089 lpfc_rx_monitor_record(phba->rx_monitor, &entry);
6092 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
6093 /* If Monitor mode, check if we are oversubscribed
6094 * against the full line rate.
6096 if (mbpi && total > mbpi)
6097 atomic_inc(&phba->cgn_driver_evt_cnt);
6099 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
6101 /* Since total_bytes has already been zero'ed, its okay to unblock
6102 * after max_bytes_per_interval is setup.
6104 if (atomic_xchg(&phba->cmf_bw_wait, 0))
6105 queue_work(phba->wq, &phba->unblock_request_work);
6107 /* SCSI IO is now unblocked */
6108 atomic_set(&phba->cmf_stop_io, 0);
6111 hrtimer_forward_now(timer,
6112 ktime_set(0, timer_interval * NSEC_PER_MSEC));
6113 return HRTIMER_RESTART;
6116 #define trunk_link_status(__idx)\
6117 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6118 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
6119 "Link up" : "Link down") : "NA"
6120 /* Did port __idx reported an error */
6121 #define trunk_port_fault(__idx)\
6122 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6123 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
6126 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
6127 struct lpfc_acqe_fc_la *acqe_fc)
6129 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
6130 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
6133 phba->sli4_hba.link_state.speed =
6134 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6135 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6137 phba->sli4_hba.link_state.logical_speed =
6138 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6139 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
6140 phba->fc_linkspeed =
6141 lpfc_async_link_speed_to_read_top(
6143 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6145 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
6146 phba->trunk_link.link0.state =
6147 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
6148 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6149 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
6152 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
6153 phba->trunk_link.link1.state =
6154 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
6155 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6156 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
6159 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
6160 phba->trunk_link.link2.state =
6161 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
6162 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6163 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
6166 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
6167 phba->trunk_link.link3.state =
6168 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
6169 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6170 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
6175 phba->trunk_link.phy_lnk_speed =
6176 phba->sli4_hba.link_state.logical_speed / (cnt * 1000);
6178 phba->trunk_link.phy_lnk_speed = LPFC_LINK_SPEED_UNKNOWN;
6180 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6181 "2910 Async FC Trunking Event - Speed:%d\n"
6182 "\tLogical speed:%d "
6183 "port0: %s port1: %s port2: %s port3: %s\n",
6184 phba->sli4_hba.link_state.speed,
6185 phba->sli4_hba.link_state.logical_speed,
6186 trunk_link_status(0), trunk_link_status(1),
6187 trunk_link_status(2), trunk_link_status(3));
6189 if (phba->cmf_active_mode != LPFC_CFG_OFF)
6190 lpfc_cmf_signal_init(phba);
6193 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6194 "3202 trunk error:0x%x (%s) seen on port0:%s "
6196 * SLI-4: We have only 0xA error codes
6197 * defined as of now. print an appropriate
6198 * message in case driver needs to be updated.
6200 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
6201 "UNDEFINED. update driver." : trunk_errmsg[err],
6202 trunk_port_fault(0), trunk_port_fault(1),
6203 trunk_port_fault(2), trunk_port_fault(3));
6208 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
6209 * @phba: pointer to lpfc hba data structure.
6210 * @acqe_fc: pointer to the async fc completion queue entry.
6212 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
6213 * that the event was received and then issue a read_topology mailbox command so
6214 * that the rest of the driver will treat it the same as SLI3.
6217 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
6221 struct lpfc_mbx_read_top *la;
6225 if (bf_get(lpfc_trailer_type, acqe_fc) !=
6226 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
6227 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6228 "2895 Non FC link Event detected.(%d)\n",
6229 bf_get(lpfc_trailer_type, acqe_fc));
6233 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6234 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
6235 lpfc_update_trunk_link_status(phba, acqe_fc);
6239 /* Keep the link status for extra SLI4 state machine reference */
6240 phba->sli4_hba.link_state.speed =
6241 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6242 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6243 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
6244 phba->sli4_hba.link_state.topology =
6245 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
6246 phba->sli4_hba.link_state.status =
6247 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
6248 phba->sli4_hba.link_state.type =
6249 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
6250 phba->sli4_hba.link_state.number =
6251 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
6252 phba->sli4_hba.link_state.fault =
6253 bf_get(lpfc_acqe_link_fault, acqe_fc);
6254 phba->sli4_hba.link_state.link_status =
6255 bf_get(lpfc_acqe_fc_la_link_status, acqe_fc);
6258 * Only select attention types need logical speed modification to what
6259 * was previously set.
6261 if (phba->sli4_hba.link_state.status >= LPFC_FC_LA_TYPE_LINK_UP &&
6262 phba->sli4_hba.link_state.status < LPFC_FC_LA_TYPE_ACTIVATE_FAIL) {
6263 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6264 LPFC_FC_LA_TYPE_LINK_DOWN)
6265 phba->sli4_hba.link_state.logical_speed = 0;
6266 else if (!phba->sli4_hba.conf_trunk)
6267 phba->sli4_hba.link_state.logical_speed =
6268 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6271 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6272 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
6273 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
6274 "%dMbps Fault:x%x Link Status:x%x\n",
6275 phba->sli4_hba.link_state.speed,
6276 phba->sli4_hba.link_state.topology,
6277 phba->sli4_hba.link_state.status,
6278 phba->sli4_hba.link_state.type,
6279 phba->sli4_hba.link_state.number,
6280 phba->sli4_hba.link_state.logical_speed,
6281 phba->sli4_hba.link_state.fault,
6282 phba->sli4_hba.link_state.link_status);
6285 * The following attention types are informational only, providing
6286 * further details about link status. Overwrite the value of
6287 * link_state.status appropriately. No further action is required.
6289 if (phba->sli4_hba.link_state.status >= LPFC_FC_LA_TYPE_ACTIVATE_FAIL) {
6290 switch (phba->sli4_hba.link_state.status) {
6291 case LPFC_FC_LA_TYPE_ACTIVATE_FAIL:
6292 log_level = KERN_WARNING;
6293 phba->sli4_hba.link_state.status =
6294 LPFC_FC_LA_TYPE_LINK_DOWN;
6296 case LPFC_FC_LA_TYPE_LINK_RESET_PRTCL_EVT:
6298 * During bb credit recovery establishment, receiving
6299 * this attention type is normal. Link Up attention
6300 * type is expected to occur before this informational
6301 * attention type so keep the Link Up status.
6303 log_level = KERN_INFO;
6304 phba->sli4_hba.link_state.status =
6305 LPFC_FC_LA_TYPE_LINK_UP;
6308 log_level = KERN_INFO;
6311 lpfc_log_msg(phba, log_level, LOG_SLI,
6312 "2992 Async FC event - Informational Link "
6313 "Attention Type x%x\n",
6314 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc));
6318 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6320 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6321 "2897 The mboxq allocation failed\n");
6324 rc = lpfc_mbox_rsrc_prep(phba, pmb);
6326 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6327 "2898 The mboxq prep failed\n");
6331 /* Cleanup any outstanding ELS commands */
6332 lpfc_els_flush_all_cmd(phba);
6334 /* Block ELS IOCBs until we have done process link event */
6335 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
6337 /* Update link event statistics */
6338 phba->sli.slistat.link_event++;
6340 /* Create lpfc_handle_latt mailbox command from link ACQE */
6341 lpfc_read_topology(phba, pmb, pmb->ctx_buf);
6342 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
6343 pmb->vport = phba->pport;
6345 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
6346 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
6348 switch (phba->sli4_hba.link_state.status) {
6349 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
6350 phba->link_flag |= LS_MDS_LINK_DOWN;
6352 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
6353 phba->link_flag |= LS_MDS_LOOPBACK;
6359 /* Initialize completion status */
6361 mb->mbxStatus = MBX_SUCCESS;
6363 /* Parse port fault information field */
6364 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
6366 /* Parse and translate link attention fields */
6367 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
6368 la->eventTag = acqe_fc->event_tag;
6370 if (phba->sli4_hba.link_state.status ==
6371 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
6372 bf_set(lpfc_mbx_read_top_att_type, la,
6373 LPFC_FC_LA_TYPE_UNEXP_WWPN);
6375 bf_set(lpfc_mbx_read_top_att_type, la,
6376 LPFC_FC_LA_TYPE_LINK_DOWN);
6378 /* Invoke the mailbox command callback function */
6379 lpfc_mbx_cmpl_read_topology(phba, pmb);
6384 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
6385 if (rc == MBX_NOT_FINISHED)
6390 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6394 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
6395 * @phba: pointer to lpfc hba data structure.
6396 * @acqe_sli: pointer to the async SLI completion queue entry.
6398 * This routine is to handle the SLI4 asynchronous SLI events.
6401 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
6407 uint8_t operational = 0;
6408 struct temp_event temp_event_data;
6409 struct lpfc_acqe_misconfigured_event *misconfigured;
6410 struct lpfc_acqe_cgn_signal *cgn_signal;
6411 struct Scsi_Host *shost;
6412 struct lpfc_vport **vports;
6415 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
6417 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6418 "2901 Async SLI event - Type:%d, Event Data: x%08x "
6419 "x%08x x%08x x%08x\n", evt_type,
6420 acqe_sli->event_data1, acqe_sli->event_data2,
6421 acqe_sli->event_data3, acqe_sli->trailer);
6423 port_name = phba->Port[0];
6424 if (port_name == 0x00)
6425 port_name = '?'; /* get port name is empty */
6428 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
6429 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6430 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6431 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6433 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6434 "3190 Over Temperature:%d Celsius- Port Name %c\n",
6435 acqe_sli->event_data1, port_name);
6437 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
6438 shost = lpfc_shost_from_vport(phba->pport);
6439 fc_host_post_vendor_event(shost, fc_get_event_number(),
6440 sizeof(temp_event_data),
6441 (char *)&temp_event_data,
6442 SCSI_NL_VID_TYPE_PCI
6443 | PCI_VENDOR_ID_EMULEX);
6445 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
6446 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6447 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6448 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6450 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_LDS_EVENT,
6451 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
6452 acqe_sli->event_data1, port_name);
6454 shost = lpfc_shost_from_vport(phba->pport);
6455 fc_host_post_vendor_event(shost, fc_get_event_number(),
6456 sizeof(temp_event_data),
6457 (char *)&temp_event_data,
6458 SCSI_NL_VID_TYPE_PCI
6459 | PCI_VENDOR_ID_EMULEX);
6461 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
6462 misconfigured = (struct lpfc_acqe_misconfigured_event *)
6463 &acqe_sli->event_data1;
6465 /* fetch the status for this port */
6466 switch (phba->sli4_hba.lnk_info.lnk_no) {
6467 case LPFC_LINK_NUMBER_0:
6468 status = bf_get(lpfc_sli_misconfigured_port0_state,
6469 &misconfigured->theEvent);
6470 operational = bf_get(lpfc_sli_misconfigured_port0_op,
6471 &misconfigured->theEvent);
6473 case LPFC_LINK_NUMBER_1:
6474 status = bf_get(lpfc_sli_misconfigured_port1_state,
6475 &misconfigured->theEvent);
6476 operational = bf_get(lpfc_sli_misconfigured_port1_op,
6477 &misconfigured->theEvent);
6479 case LPFC_LINK_NUMBER_2:
6480 status = bf_get(lpfc_sli_misconfigured_port2_state,
6481 &misconfigured->theEvent);
6482 operational = bf_get(lpfc_sli_misconfigured_port2_op,
6483 &misconfigured->theEvent);
6485 case LPFC_LINK_NUMBER_3:
6486 status = bf_get(lpfc_sli_misconfigured_port3_state,
6487 &misconfigured->theEvent);
6488 operational = bf_get(lpfc_sli_misconfigured_port3_op,
6489 &misconfigured->theEvent);
6492 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6494 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
6495 "event: Invalid link %d",
6496 phba->sli4_hba.lnk_info.lnk_no);
6500 /* Skip if optic state unchanged */
6501 if (phba->sli4_hba.lnk_info.optic_state == status)
6505 case LPFC_SLI_EVENT_STATUS_VALID:
6506 sprintf(message, "Physical Link is functional");
6508 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
6509 sprintf(message, "Optics faulted/incorrectly "
6510 "installed/not installed - Reseat optics, "
6511 "if issue not resolved, replace.");
6513 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
6515 "Optics of two types installed - Remove one "
6516 "optic or install matching pair of optics.");
6518 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
6519 sprintf(message, "Incompatible optics - Replace with "
6520 "compatible optics for card to function.");
6522 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
6523 sprintf(message, "Unqualified optics - Replace with "
6524 "Avago optics for Warranty and Technical "
6525 "Support - Link is%s operational",
6526 (operational) ? " not" : "");
6528 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
6529 sprintf(message, "Uncertified optics - Replace with "
6530 "Avago-certified optics to enable link "
6531 "operation - Link is%s operational",
6532 (operational) ? " not" : "");
6535 /* firmware is reporting a status we don't know about */
6536 sprintf(message, "Unknown event status x%02x", status);
6540 /* Issue READ_CONFIG mbox command to refresh supported speeds */
6541 rc = lpfc_sli4_read_config(phba);
6544 lpfc_printf_log(phba, KERN_ERR,
6546 "3194 Unable to retrieve supported "
6547 "speeds, rc = 0x%x\n", rc);
6549 rc = lpfc_sli4_refresh_params(phba);
6551 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6552 "3174 Unable to update pls support, "
6555 vports = lpfc_create_vport_work_array(phba);
6556 if (vports != NULL) {
6557 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6559 shost = lpfc_shost_from_vport(vports[i]);
6560 lpfc_host_supported_speeds_set(shost);
6563 lpfc_destroy_vport_work_array(phba, vports);
6565 phba->sli4_hba.lnk_info.optic_state = status;
6566 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6567 "3176 Port Name %c %s\n", port_name, message);
6569 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
6570 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6571 "3192 Remote DPort Test Initiated - "
6572 "Event Data1:x%08x Event Data2: x%08x\n",
6573 acqe_sli->event_data1, acqe_sli->event_data2);
6575 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
6576 /* Call FW to obtain active parms */
6577 lpfc_sli4_cgn_parm_chg_evt(phba);
6579 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
6580 /* Misconfigured WWN. Reports that the SLI Port is configured
6581 * to use FA-WWN, but the attached device doesn’t support it.
6582 * Event Data1 - N.A, Event Data2 - N.A
6583 * This event only happens on the physical port.
6585 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI | LOG_DISCOVERY,
6586 "2699 Misconfigured FA-PWWN - Attached device "
6587 "does not support FA-PWWN\n");
6588 phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_FABRIC;
6589 memset(phba->pport->fc_portname.u.wwn, 0,
6590 sizeof(struct lpfc_name));
6592 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
6593 /* EEPROM failure. No driver action is required */
6594 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6595 "2518 EEPROM failure - "
6596 "Event Data1: x%08x Event Data2: x%08x\n",
6597 acqe_sli->event_data1, acqe_sli->event_data2);
6599 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
6600 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6602 cgn_signal = (struct lpfc_acqe_cgn_signal *)
6603 &acqe_sli->event_data1;
6604 phba->cgn_acqe_cnt++;
6606 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6607 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6608 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6610 /* no threshold for CMF, even 1 signal will trigger an event */
6612 /* Alarm overrides warning, so check that first */
6613 if (cgn_signal->alarm_cnt) {
6614 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6615 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6616 atomic_add(cgn_signal->alarm_cnt,
6617 &phba->cgn_sync_alarm_cnt);
6620 /* signal action needs to be taken */
6621 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6622 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6623 /* Keep track of warning cnt for CMF_SYNC_WQE */
6624 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6628 case LPFC_SLI_EVENT_TYPE_RD_SIGNAL:
6629 /* May be accompanied by a temperature event */
6630 lpfc_printf_log(phba, KERN_INFO,
6631 LOG_SLI | LOG_LINK_EVENT | LOG_LDS_EVENT,
6632 "2902 Remote Degrade Signaling: x%08x x%08x "
6634 acqe_sli->event_data1, acqe_sli->event_data2,
6635 acqe_sli->event_data3);
6637 case LPFC_SLI_EVENT_TYPE_RESET_CM_STATS:
6638 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
6639 "2905 Reset CM statistics\n");
6640 lpfc_sli4_async_cmstat_evt(phba);
6643 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6644 "3193 Unrecognized SLI event, type: 0x%x",
6651 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6652 * @vport: pointer to vport data structure.
6654 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6655 * response to a CVL event.
6657 * Return the pointer to the ndlp with the vport if successful, otherwise
6660 static struct lpfc_nodelist *
6661 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6663 struct lpfc_nodelist *ndlp;
6664 struct Scsi_Host *shost;
6665 struct lpfc_hba *phba;
6672 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6674 /* Cannot find existing Fabric ndlp, so allocate a new one */
6675 ndlp = lpfc_nlp_init(vport, Fabric_DID);
6678 /* Set the node type */
6679 ndlp->nlp_type |= NLP_FABRIC;
6680 /* Put ndlp onto node list */
6681 lpfc_enqueue_node(vport, ndlp);
6683 if ((phba->pport->port_state < LPFC_FLOGI) &&
6684 (phba->pport->port_state != LPFC_VPORT_FAILED))
6686 /* If virtual link is not yet instantiated ignore CVL */
6687 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6688 && (vport->port_state != LPFC_VPORT_FAILED))
6690 shost = lpfc_shost_from_vport(vport);
6693 lpfc_linkdown_port(vport);
6694 lpfc_cleanup_pending_mbox(vport);
6695 set_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag);
6701 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
6702 * @phba: pointer to lpfc hba data structure.
6704 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6705 * response to a FCF dead event.
6708 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6710 struct lpfc_vport **vports;
6713 vports = lpfc_create_vport_work_array(phba);
6715 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6716 lpfc_sli4_perform_vport_cvl(vports[i]);
6717 lpfc_destroy_vport_work_array(phba, vports);
6721 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
6722 * @phba: pointer to lpfc hba data structure.
6723 * @acqe_fip: pointer to the async fcoe completion queue entry.
6725 * This routine is to handle the SLI4 asynchronous fcoe event.
6728 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
6729 struct lpfc_acqe_fip *acqe_fip)
6731 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
6733 struct lpfc_vport *vport;
6734 struct lpfc_nodelist *ndlp;
6735 int active_vlink_present;
6736 struct lpfc_vport **vports;
6739 phba->fc_eventTag = acqe_fip->event_tag;
6740 phba->fcoe_eventtag = acqe_fip->event_tag;
6741 switch (event_type) {
6742 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6743 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6744 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
6745 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6746 "2546 New FCF event, evt_tag:x%x, "
6748 acqe_fip->event_tag,
6751 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6753 "2788 FCF param modified event, "
6754 "evt_tag:x%x, index:x%x\n",
6755 acqe_fip->event_tag,
6757 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6759 * During period of FCF discovery, read the FCF
6760 * table record indexed by the event to update
6761 * FCF roundrobin failover eligible FCF bmask.
6763 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6765 "2779 Read FCF (x%x) for updating "
6766 "roundrobin FCF failover bmask\n",
6768 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
6771 /* If the FCF discovery is in progress, do nothing. */
6772 if (test_bit(FCF_TS_INPROG, &phba->hba_flag))
6774 spin_lock_irq(&phba->hbalock);
6775 /* If fast FCF failover rescan event is pending, do nothing */
6776 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
6777 spin_unlock_irq(&phba->hbalock);
6781 /* If the FCF has been in discovered state, do nothing. */
6782 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
6783 spin_unlock_irq(&phba->hbalock);
6786 spin_unlock_irq(&phba->hbalock);
6788 /* Otherwise, scan the entire FCF table and re-discover SAN */
6789 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6790 "2770 Start FCF table scan per async FCF "
6791 "event, evt_tag:x%x, index:x%x\n",
6792 acqe_fip->event_tag, acqe_fip->index);
6793 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6794 LPFC_FCOE_FCF_GET_FIRST);
6796 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6797 "2547 Issue FCF scan read FCF mailbox "
6798 "command failed (x%x)\n", rc);
6801 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
6802 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6803 "2548 FCF Table full count 0x%x tag 0x%x\n",
6804 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6805 acqe_fip->event_tag);
6808 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
6809 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6810 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6811 "2549 FCF (x%x) disconnected from network, "
6812 "tag:x%x\n", acqe_fip->index,
6813 acqe_fip->event_tag);
6815 * If we are in the middle of FCF failover process, clear
6816 * the corresponding FCF bit in the roundrobin bitmap.
6818 spin_lock_irq(&phba->hbalock);
6819 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6820 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
6821 spin_unlock_irq(&phba->hbalock);
6822 /* Update FLOGI FCF failover eligible FCF bmask */
6823 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
6826 spin_unlock_irq(&phba->hbalock);
6828 /* If the event is not for currently used fcf do nothing */
6829 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
6833 * Otherwise, request the port to rediscover the entire FCF
6834 * table for a fast recovery from case that the current FCF
6835 * is no longer valid as we are not in the middle of FCF
6836 * failover process already.
6838 spin_lock_irq(&phba->hbalock);
6839 /* Mark the fast failover process in progress */
6840 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6841 spin_unlock_irq(&phba->hbalock);
6843 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6844 "2771 Start FCF fast failover process due to "
6845 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6846 "\n", acqe_fip->event_tag, acqe_fip->index);
6847 rc = lpfc_sli4_redisc_fcf_table(phba);
6849 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6851 "2772 Issue FCF rediscover mailbox "
6852 "command failed, fail through to FCF "
6854 spin_lock_irq(&phba->hbalock);
6855 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6856 spin_unlock_irq(&phba->hbalock);
6858 * Last resort will fail over by treating this
6859 * as a link down to FCF registration.
6861 lpfc_sli4_fcf_dead_failthrough(phba);
6863 /* Reset FCF roundrobin bmask for new discovery */
6864 lpfc_sli4_clear_fcf_rr_bmask(phba);
6866 * Handling fast FCF failover to a DEAD FCF event is
6867 * considered equalivant to receiving CVL to all vports.
6869 lpfc_sli4_perform_all_vport_cvl(phba);
6872 case LPFC_FIP_EVENT_TYPE_CVL:
6873 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6874 lpfc_printf_log(phba, KERN_ERR,
6876 "2718 Clear Virtual Link Received for VPI 0x%x"
6877 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
6879 vport = lpfc_find_vport_by_vpid(phba,
6881 ndlp = lpfc_sli4_perform_vport_cvl(vport);
6884 active_vlink_present = 0;
6886 vports = lpfc_create_vport_work_array(phba);
6888 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6890 if (!test_bit(FC_VPORT_CVL_RCVD,
6891 &vports[i]->fc_flag) &&
6892 vports[i]->port_state > LPFC_FDISC) {
6893 active_vlink_present = 1;
6897 lpfc_destroy_vport_work_array(phba, vports);
6901 * Don't re-instantiate if vport is marked for deletion.
6902 * If we are here first then vport_delete is going to wait
6903 * for discovery to complete.
6905 if (!test_bit(FC_UNLOADING, &vport->load_flag) &&
6906 active_vlink_present) {
6908 * If there are other active VLinks present,
6909 * re-instantiate the Vlink using FDISC.
6911 mod_timer(&ndlp->nlp_delayfunc,
6912 jiffies + msecs_to_jiffies(1000));
6913 spin_lock_irq(&ndlp->lock);
6914 ndlp->nlp_flag |= NLP_DELAY_TMO;
6915 spin_unlock_irq(&ndlp->lock);
6916 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6917 vport->port_state = LPFC_FDISC;
6920 * Otherwise, we request port to rediscover
6921 * the entire FCF table for a fast recovery
6922 * from possible case that the current FCF
6923 * is no longer valid if we are not already
6924 * in the FCF failover process.
6926 spin_lock_irq(&phba->hbalock);
6927 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6928 spin_unlock_irq(&phba->hbalock);
6931 /* Mark the fast failover process in progress */
6932 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
6933 spin_unlock_irq(&phba->hbalock);
6934 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6936 "2773 Start FCF failover per CVL, "
6937 "evt_tag:x%x\n", acqe_fip->event_tag);
6938 rc = lpfc_sli4_redisc_fcf_table(phba);
6940 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6942 "2774 Issue FCF rediscover "
6943 "mailbox command failed, "
6944 "through to CVL event\n");
6945 spin_lock_irq(&phba->hbalock);
6946 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
6947 spin_unlock_irq(&phba->hbalock);
6949 * Last resort will be re-try on the
6950 * the current registered FCF entry.
6952 lpfc_retry_pport_discovery(phba);
6955 * Reset FCF roundrobin bmask for new
6958 lpfc_sli4_clear_fcf_rr_bmask(phba);
6962 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6963 "0288 Unknown FCoE event type 0x%x event tag "
6964 "0x%x\n", event_type, acqe_fip->event_tag);
6970 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
6971 * @phba: pointer to lpfc hba data structure.
6972 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
6974 * This routine is to handle the SLI4 asynchronous dcbx event.
6977 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
6978 struct lpfc_acqe_dcbx *acqe_dcbx)
6980 phba->fc_eventTag = acqe_dcbx->event_tag;
6981 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6982 "0290 The SLI4 DCBX asynchronous event is not "
6987 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
6988 * @phba: pointer to lpfc hba data structure.
6989 * @acqe_grp5: pointer to the async grp5 completion queue entry.
6991 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
6992 * is an asynchronous notified of a logical link speed change. The Port
6993 * reports the logical link speed in units of 10Mbps.
6996 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
6997 struct lpfc_acqe_grp5 *acqe_grp5)
6999 uint16_t prev_ll_spd;
7001 phba->fc_eventTag = acqe_grp5->event_tag;
7002 phba->fcoe_eventtag = acqe_grp5->event_tag;
7003 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
7004 phba->sli4_hba.link_state.logical_speed =
7005 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
7006 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7007 "2789 GRP5 Async Event: Updating logical link speed "
7008 "from %dMbps to %dMbps\n", prev_ll_spd,
7009 phba->sli4_hba.link_state.logical_speed);
7013 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
7014 * @phba: pointer to lpfc hba data structure.
7016 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
7017 * is an asynchronous notification of a request to reset CM stats.
7020 lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
7024 lpfc_init_congestion_stat(phba);
7028 * lpfc_cgn_params_val - Validate FW congestion parameters.
7029 * @phba: pointer to lpfc hba data structure.
7030 * @p_cfg_param: pointer to FW provided congestion parameters.
7032 * This routine validates the congestion parameters passed
7033 * by the FW to the driver via an ACQE event.
7036 lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
7038 spin_lock_irq(&phba->hbalock);
7040 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
7041 LPFC_CFG_MONITOR)) {
7042 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
7043 "6225 CMF mode param out of range: %d\n",
7044 p_cfg_param->cgn_param_mode);
7045 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
7048 spin_unlock_irq(&phba->hbalock);
7051 static const char * const lpfc_cmf_mode_to_str[] = {
7058 * lpfc_cgn_params_parse - Process a FW cong parm change event
7059 * @phba: pointer to lpfc hba data structure.
7060 * @p_cgn_param: pointer to a data buffer with the FW cong params.
7061 * @len: the size of pdata in bytes.
7063 * This routine validates the congestion management buffer signature
7064 * from the FW, validates the contents and makes corrections for
7065 * valid, in-range values. If the signature magic is correct and
7066 * after parameter validation, the contents are copied to the driver's
7067 * @phba structure. If the magic is incorrect, an error message is
7071 lpfc_cgn_params_parse(struct lpfc_hba *phba,
7072 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
7074 struct lpfc_cgn_info *cp;
7075 uint32_t crc, oldmode;
7076 char acr_string[4] = {0};
7078 /* Make sure the FW has encoded the correct magic number to
7079 * validate the congestion parameter in FW memory.
7081 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
7082 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7083 "4668 FW cgn parm buffer data: "
7084 "magic 0x%x version %d mode %d "
7085 "level0 %d level1 %d "
7086 "level2 %d byte13 %d "
7087 "byte14 %d byte15 %d "
7088 "byte11 %d byte12 %d activeMode %d\n",
7089 p_cgn_param->cgn_param_magic,
7090 p_cgn_param->cgn_param_version,
7091 p_cgn_param->cgn_param_mode,
7092 p_cgn_param->cgn_param_level0,
7093 p_cgn_param->cgn_param_level1,
7094 p_cgn_param->cgn_param_level2,
7095 p_cgn_param->byte13,
7096 p_cgn_param->byte14,
7097 p_cgn_param->byte15,
7098 p_cgn_param->byte11,
7099 p_cgn_param->byte12,
7100 phba->cmf_active_mode);
7102 oldmode = phba->cmf_active_mode;
7104 /* Any parameters out of range are corrected to defaults
7105 * by this routine. No need to fail.
7107 lpfc_cgn_params_val(phba, p_cgn_param);
7109 /* Parameters are verified, move them into driver storage */
7110 spin_lock_irq(&phba->hbalock);
7111 memcpy(&phba->cgn_p, p_cgn_param,
7112 sizeof(struct lpfc_cgn_param));
7114 /* Update parameters in congestion info buffer now */
7116 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
7117 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
7118 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
7119 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
7120 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
7121 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
7122 LPFC_CGN_CRC32_SEED);
7123 cp->cgn_info_crc = cpu_to_le32(crc);
7125 spin_unlock_irq(&phba->hbalock);
7127 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
7131 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
7132 /* Turning CMF on */
7133 lpfc_cmf_start(phba);
7135 if (phba->link_state >= LPFC_LINK_UP) {
7136 phba->cgn_reg_fpin =
7137 phba->cgn_init_reg_fpin;
7138 phba->cgn_reg_signal =
7139 phba->cgn_init_reg_signal;
7140 lpfc_issue_els_edc(phba->pport, 0);
7144 case LPFC_CFG_MANAGED:
7145 switch (phba->cgn_p.cgn_param_mode) {
7147 /* Turning CMF off */
7148 lpfc_cmf_stop(phba);
7149 if (phba->link_state >= LPFC_LINK_UP)
7150 lpfc_issue_els_edc(phba->pport, 0);
7152 case LPFC_CFG_MONITOR:
7153 phba->cmf_max_bytes_per_interval =
7154 phba->cmf_link_byte_count;
7156 /* Resume blocked IO - unblock on workqueue */
7157 queue_work(phba->wq,
7158 &phba->unblock_request_work);
7162 case LPFC_CFG_MONITOR:
7163 switch (phba->cgn_p.cgn_param_mode) {
7165 /* Turning CMF off */
7166 lpfc_cmf_stop(phba);
7167 if (phba->link_state >= LPFC_LINK_UP)
7168 lpfc_issue_els_edc(phba->pport, 0);
7170 case LPFC_CFG_MANAGED:
7171 lpfc_cmf_signal_init(phba);
7176 if (oldmode != LPFC_CFG_OFF ||
7177 oldmode != phba->cgn_p.cgn_param_mode) {
7178 if (phba->cgn_p.cgn_param_mode == LPFC_CFG_MANAGED)
7179 scnprintf(acr_string, sizeof(acr_string), "%u",
7180 phba->cgn_p.cgn_param_level0);
7182 scnprintf(acr_string, sizeof(acr_string), "NA");
7184 dev_info(&phba->pcidev->dev, "%d: "
7185 "4663 CMF: Mode %s acr %s\n",
7187 lpfc_cmf_mode_to_str
7188 [phba->cgn_p.cgn_param_mode],
7192 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7193 "4669 FW cgn parm buf wrong magic 0x%x "
7194 "version %d\n", p_cgn_param->cgn_param_magic,
7195 p_cgn_param->cgn_param_version);
7200 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
7201 * @phba: pointer to lpfc hba data structure.
7203 * This routine issues a read_object mailbox command to
7204 * get the congestion management parameters from the FW
7205 * parses it and updates the driver maintained values.
7208 * 0 if the object was empty
7209 * -Eval if an error was encountered
7210 * Count if bytes were read from object
7213 lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
7216 struct lpfc_cgn_param *p_cgn_param = NULL;
7220 /* Find out if the FW has a new set of congestion parameters. */
7221 len = sizeof(struct lpfc_cgn_param);
7222 pdata = kzalloc(len, GFP_KERNEL);
7225 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
7228 /* 0 means no data. A negative means error. A positive means
7229 * bytes were copied.
7232 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7233 "4670 CGN RD OBJ returns no data\n");
7235 } else if (ret < 0) {
7236 /* Some error. Just exit and return it to the caller.*/
7240 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7241 "6234 READ CGN PARAMS Successful %d\n", len);
7243 /* Parse data pointer over len and update the phba congestion
7244 * parameters with values passed back. The receive rate values
7245 * may have been altered in FW, but take no action here.
7247 p_cgn_param = (struct lpfc_cgn_param *)pdata;
7248 lpfc_cgn_params_parse(phba, p_cgn_param, len);
7256 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
7257 * @phba: pointer to lpfc hba data structure.
7259 * The FW generated Async ACQE SLI event calls this routine when
7260 * the event type is an SLI Internal Port Event and the Event Code
7261 * indicates a change to the FW maintained congestion parameters.
7263 * This routine executes a Read_Object mailbox call to obtain the
7264 * current congestion parameters maintained in FW and corrects
7265 * the driver's active congestion parameters.
7267 * The acqe event is not passed because there is no further data
7270 * Returns nonzero error if event processing encountered an error.
7271 * Zero otherwise for success.
7274 lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
7278 if (!phba->sli4_hba.pc_sli4_params.cmf) {
7279 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7280 "4664 Cgn Evt when E2E off. Drop event\n");
7284 /* If the event is claiming an empty object, it's ok. A write
7285 * could have cleared it. Only error is a negative return
7288 ret = lpfc_sli4_cgn_params_read(phba);
7290 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7291 "4667 Error reading Cgn Params (%d)\n",
7294 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7295 "4673 CGN Event empty object.\n");
7301 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
7302 * @phba: pointer to lpfc hba data structure.
7304 * This routine is invoked by the worker thread to process all the pending
7305 * SLI4 asynchronous events.
7307 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
7309 struct lpfc_cq_event *cq_event;
7310 unsigned long iflags;
7312 /* First, declare the async event has been handled */
7313 clear_bit(ASYNC_EVENT, &phba->hba_flag);
7315 /* Now, handle all the async events */
7316 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7317 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
7318 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
7319 cq_event, struct lpfc_cq_event, list);
7320 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
7323 /* Process the asynchronous event */
7324 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
7325 case LPFC_TRAILER_CODE_LINK:
7326 lpfc_sli4_async_link_evt(phba,
7327 &cq_event->cqe.acqe_link);
7329 case LPFC_TRAILER_CODE_FCOE:
7330 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
7332 case LPFC_TRAILER_CODE_DCBX:
7333 lpfc_sli4_async_dcbx_evt(phba,
7334 &cq_event->cqe.acqe_dcbx);
7336 case LPFC_TRAILER_CODE_GRP5:
7337 lpfc_sli4_async_grp5_evt(phba,
7338 &cq_event->cqe.acqe_grp5);
7340 case LPFC_TRAILER_CODE_FC:
7341 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
7343 case LPFC_TRAILER_CODE_SLI:
7344 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
7347 lpfc_printf_log(phba, KERN_ERR,
7349 "1804 Invalid asynchronous event code: "
7350 "x%x\n", bf_get(lpfc_trailer_code,
7351 &cq_event->cqe.mcqe_cmpl));
7355 /* Free the completion event processed to the free pool */
7356 lpfc_sli4_cq_event_release(phba, cq_event);
7357 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7359 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
7363 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
7364 * @phba: pointer to lpfc hba data structure.
7366 * This routine is invoked by the worker thread to process FCF table
7367 * rediscovery pending completion event.
7369 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
7373 spin_lock_irq(&phba->hbalock);
7374 /* Clear FCF rediscovery timeout event */
7375 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
7376 /* Clear driver fast failover FCF record flag */
7377 phba->fcf.failover_rec.flag = 0;
7378 /* Set state for FCF fast failover */
7379 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
7380 spin_unlock_irq(&phba->hbalock);
7382 /* Scan FCF table from the first entry to re-discover SAN */
7383 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
7384 "2777 Start post-quiescent FCF table scan\n");
7385 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
7387 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7388 "2747 Issue FCF scan read FCF mailbox "
7389 "command failed 0x%x\n", rc);
7393 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
7394 * @phba: pointer to lpfc hba data structure.
7395 * @dev_grp: The HBA PCI-Device group number.
7397 * This routine is invoked to set up the per HBA PCI-Device group function
7398 * API jump table entries.
7400 * Return: 0 if success, otherwise -ENODEV
7403 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7407 /* Set up lpfc PCI-device group */
7408 phba->pci_dev_grp = dev_grp;
7410 /* The LPFC_PCI_DEV_OC uses SLI4 */
7411 if (dev_grp == LPFC_PCI_DEV_OC)
7412 phba->sli_rev = LPFC_SLI_REV4;
7414 /* Set up device INIT API function jump table */
7415 rc = lpfc_init_api_table_setup(phba, dev_grp);
7418 /* Set up SCSI API function jump table */
7419 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
7422 /* Set up SLI API function jump table */
7423 rc = lpfc_sli_api_table_setup(phba, dev_grp);
7426 /* Set up MBOX API function jump table */
7427 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
7435 * lpfc_log_intr_mode - Log the active interrupt mode
7436 * @phba: pointer to lpfc hba data structure.
7437 * @intr_mode: active interrupt mode adopted.
7439 * This routine it invoked to log the currently used active interrupt mode
7442 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
7444 switch (intr_mode) {
7446 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7447 "0470 Enable INTx interrupt mode.\n");
7450 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7451 "0481 Enabled MSI interrupt mode.\n");
7454 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7455 "0480 Enabled MSI-X interrupt mode.\n");
7458 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7459 "0482 Illegal interrupt mode.\n");
7466 * lpfc_enable_pci_dev - Enable a generic PCI device.
7467 * @phba: pointer to lpfc hba data structure.
7469 * This routine is invoked to enable the PCI device that is common to all
7474 * other values - error
7477 lpfc_enable_pci_dev(struct lpfc_hba *phba)
7479 struct pci_dev *pdev;
7481 /* Obtain PCI device reference */
7485 pdev = phba->pcidev;
7486 /* Enable PCI device */
7487 if (pci_enable_device_mem(pdev))
7489 /* Request PCI resource for the device */
7490 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
7491 goto out_disable_device;
7492 /* Set up device as PCI master and save state for EEH */
7493 pci_set_master(pdev);
7494 pci_try_set_mwi(pdev);
7495 pci_save_state(pdev);
7497 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
7498 if (pci_is_pcie(pdev))
7499 pdev->needs_freset = 1;
7504 pci_disable_device(pdev);
7506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7507 "1401 Failed to enable pci device\n");
7512 * lpfc_disable_pci_dev - Disable a generic PCI device.
7513 * @phba: pointer to lpfc hba data structure.
7515 * This routine is invoked to disable the PCI device that is common to all
7519 lpfc_disable_pci_dev(struct lpfc_hba *phba)
7521 struct pci_dev *pdev;
7523 /* Obtain PCI device reference */
7527 pdev = phba->pcidev;
7528 /* Release PCI resource and disable PCI device */
7529 pci_release_mem_regions(pdev);
7530 pci_disable_device(pdev);
7536 * lpfc_reset_hba - Reset a hba
7537 * @phba: pointer to lpfc hba data structure.
7539 * This routine is invoked to reset a hba device. It brings the HBA
7540 * offline, performs a board restart, and then brings the board back
7541 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
7542 * on outstanding mailbox commands.
7545 lpfc_reset_hba(struct lpfc_hba *phba)
7549 /* If resets are disabled then set error state and return. */
7550 if (!phba->cfg_enable_hba_reset) {
7551 phba->link_state = LPFC_HBA_ERROR;
7555 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
7556 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
7557 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
7559 if (test_bit(MBX_TMO_ERR, &phba->bit_flags)) {
7560 /* Perform a PCI function reset to start from clean */
7561 rc = lpfc_pci_function_reset(phba);
7562 lpfc_els_flush_all_cmd(phba);
7564 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
7565 lpfc_sli_flush_io_rings(phba);
7568 clear_bit(MBX_TMO_ERR, &phba->bit_flags);
7570 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7571 "8888 PCI function reset failed rc %x\n",
7574 lpfc_sli_brdrestart(phba);
7576 lpfc_unblock_mgmt_io(phba);
7581 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
7582 * @phba: pointer to lpfc hba data structure.
7584 * This function enables the PCI SR-IOV virtual functions to a physical
7585 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7586 * enable the number of virtual functions to the physical function. As
7587 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7588 * API call does not considered as an error condition for most of the device.
7591 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
7593 struct pci_dev *pdev = phba->pcidev;
7597 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
7601 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
7606 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
7607 * @phba: pointer to lpfc hba data structure.
7608 * @nr_vfn: number of virtual functions to be enabled.
7610 * This function enables the PCI SR-IOV virtual functions to a physical
7611 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7612 * enable the number of virtual functions to the physical function. As
7613 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7614 * API call does not considered as an error condition for most of the device.
7617 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
7619 struct pci_dev *pdev = phba->pcidev;
7620 uint16_t max_nr_vfn;
7623 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
7624 if (nr_vfn > max_nr_vfn) {
7625 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7626 "3057 Requested vfs (%d) greater than "
7627 "supported vfs (%d)", nr_vfn, max_nr_vfn);
7631 rc = pci_enable_sriov(pdev, nr_vfn);
7633 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7634 "2806 Failed to enable sriov on this device "
7635 "with vfn number nr_vf:%d, rc:%d\n",
7638 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7639 "2807 Successful enable sriov on this device "
7640 "with vfn number nr_vf:%d\n", nr_vfn);
7645 lpfc_unblock_requests_work(struct work_struct *work)
7647 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
7648 unblock_request_work);
7650 lpfc_unblock_requests(phba);
7654 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
7655 * @phba: pointer to lpfc hba data structure.
7657 * This routine is invoked to set up the driver internal resources before the
7658 * device specific resource setup to support the HBA device it attached to.
7662 * other values - error
7665 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
7667 struct lpfc_sli *psli = &phba->sli;
7670 * Driver resources common to all SLI revisions
7672 atomic_set(&phba->fast_event_count, 0);
7673 atomic_set(&phba->dbg_log_idx, 0);
7674 atomic_set(&phba->dbg_log_cnt, 0);
7675 atomic_set(&phba->dbg_log_dmping, 0);
7676 spin_lock_init(&phba->hbalock);
7678 /* Initialize port_list spinlock */
7679 spin_lock_init(&phba->port_list_lock);
7680 INIT_LIST_HEAD(&phba->port_list);
7682 INIT_LIST_HEAD(&phba->work_list);
7684 /* Initialize the wait queue head for the kernel thread */
7685 init_waitqueue_head(&phba->work_waitq);
7687 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7688 "1403 Protocols supported %s %s %s\n",
7689 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7691 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
7693 (phba->nvmet_support ? "NVMET" : " "));
7695 /* ras_fwlog state */
7696 spin_lock_init(&phba->ras_fwlog_lock);
7698 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7699 spin_lock_init(&phba->scsi_buf_list_get_lock);
7700 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7701 spin_lock_init(&phba->scsi_buf_list_put_lock);
7702 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
7704 /* Initialize the fabric iocb list */
7705 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7707 /* Initialize list to save ELS buffers */
7708 INIT_LIST_HEAD(&phba->elsbuf);
7710 /* Initialize FCF connection rec list */
7711 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7713 /* Initialize OAS configuration list */
7714 spin_lock_init(&phba->devicelock);
7715 INIT_LIST_HEAD(&phba->luns);
7717 /* MBOX heartbeat timer */
7718 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
7719 /* Fabric block timer */
7720 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
7721 /* EA polling mode timer */
7722 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
7723 /* Heartbeat timer */
7724 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
7726 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7728 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7729 lpfc_idle_stat_delay_work);
7730 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
7735 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7736 * @phba: pointer to lpfc hba data structure.
7738 * This routine is invoked to set up the driver internal resources specific to
7739 * support the SLI-3 HBA device it attached to.
7743 * other values - error
7746 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7751 * Initialize timers used by driver
7754 /* FCP polling mode timer */
7755 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
7757 /* Host attention work mask setup */
7758 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7759 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7761 /* Get all the module params for configuring this host */
7762 lpfc_get_cfgparam(phba);
7763 /* Set up phase-1 common device driver resources */
7765 rc = lpfc_setup_driver_resource_phase1(phba);
7769 if (!phba->sli.sli3_ring)
7770 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7771 sizeof(struct lpfc_sli_ring),
7773 if (!phba->sli.sli3_ring)
7777 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
7778 * used to create the sg_dma_buf_pool must be dynamically calculated.
7781 if (phba->sli_rev == LPFC_SLI_REV4)
7782 entry_sz = sizeof(struct sli4_sge);
7784 entry_sz = sizeof(struct ulp_bde64);
7786 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7787 if (phba->cfg_enable_bg) {
7789 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7790 * the FCP rsp, and a BDE for each. Sice we have no control
7791 * over how many protection data segments the SCSI Layer
7792 * will hand us (ie: there could be one for every block
7793 * in the IO), we just allocate enough BDEs to accomidate
7794 * our max amount and we need to limit lpfc_sg_seg_cnt to
7795 * minimize the risk of running out.
7797 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7798 sizeof(struct fcp_rsp) +
7799 (LPFC_MAX_SG_SEG_CNT * entry_sz);
7801 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7802 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7804 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7805 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7808 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7809 * the FCP rsp, a BDE for each, and a BDE for up to
7810 * cfg_sg_seg_cnt data segments.
7812 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7813 sizeof(struct fcp_rsp) +
7814 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
7816 /* Total BDEs in BPL for scsi_sg_list */
7817 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7820 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7821 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
7822 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7823 phba->cfg_total_seg_cnt);
7825 phba->max_vpi = LPFC_MAX_VPI;
7826 /* This will be set to correct value after config_port mbox */
7827 phba->max_vports = 0;
7830 * Initialize the SLI Layer to run with lpfc HBAs.
7832 lpfc_sli_setup(phba);
7833 lpfc_sli_queue_init(phba);
7835 /* Allocate device driver memory */
7836 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7839 phba->lpfc_sg_dma_buf_pool =
7840 dma_pool_create("lpfc_sg_dma_buf_pool",
7841 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7844 if (!phba->lpfc_sg_dma_buf_pool)
7847 phba->lpfc_cmd_rsp_buf_pool =
7848 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7850 sizeof(struct fcp_cmnd) +
7851 sizeof(struct fcp_rsp),
7854 if (!phba->lpfc_cmd_rsp_buf_pool)
7855 goto fail_free_dma_buf_pool;
7858 * Enable sr-iov virtual functions if supported and configured
7859 * through the module parameter.
7861 if (phba->cfg_sriov_nr_virtfn > 0) {
7862 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7863 phba->cfg_sriov_nr_virtfn);
7865 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7866 "2808 Requested number of SR-IOV "
7867 "virtual functions (%d) is not "
7869 phba->cfg_sriov_nr_virtfn);
7870 phba->cfg_sriov_nr_virtfn = 0;
7876 fail_free_dma_buf_pool:
7877 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7878 phba->lpfc_sg_dma_buf_pool = NULL;
7880 lpfc_mem_free(phba);
7885 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7886 * @phba: pointer to lpfc hba data structure.
7888 * This routine is invoked to unset the driver internal resources set up
7889 * specific for supporting the SLI-3 HBA device it attached to.
7892 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7894 /* Free device driver memory allocated */
7895 lpfc_mem_free_all(phba);
7901 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7902 * @phba: pointer to lpfc hba data structure.
7904 * This routine is invoked to set up the driver internal resources specific to
7905 * support the SLI-4 HBA device it attached to.
7909 * other values - error
7912 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7914 LPFC_MBOXQ_t *mboxq;
7916 int rc, i, max_buf_size;
7923 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7924 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
7925 phba->sli4_hba.curr_disp_cpu = 0;
7927 /* Get all the module params for configuring this host */
7928 lpfc_get_cfgparam(phba);
7930 /* Set up phase-1 common device driver resources */
7931 rc = lpfc_setup_driver_resource_phase1(phba);
7935 /* Before proceed, wait for POST done and device ready */
7936 rc = lpfc_sli4_post_status_check(phba);
7940 /* Allocate all driver workqueues here */
7942 /* The lpfc_wq workqueue for deferred irq use */
7943 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7948 * Initialize timers used by driver
7951 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
7953 /* FCF rediscover timer */
7954 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
7956 /* CMF congestion timer */
7957 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7958 phba->cmf_timer.function = lpfc_cmf_timer;
7959 /* CMF 1 minute stats collection timer */
7960 hrtimer_init(&phba->cmf_stats_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7961 phba->cmf_stats_timer.function = lpfc_cmf_stats_timer;
7964 * Control structure for handling external multi-buffer mailbox
7965 * command pass-through.
7967 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
7968 sizeof(struct lpfc_mbox_ext_buf_ctx));
7969 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
7971 phba->max_vpi = LPFC_MAX_VPI;
7973 /* This will be set to correct value after the read_config mbox */
7974 phba->max_vports = 0;
7976 /* Program the default value of vlan_id and fc_map */
7977 phba->valid_vlan = 0;
7978 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
7979 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
7980 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
7983 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
7984 * we will associate a new ring, for each EQ/CQ/WQ tuple.
7985 * The WQ create will allocate the ring.
7988 /* Initialize buffer queue management fields */
7989 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
7990 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
7991 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
7993 /* for VMID idle timeout if VMID is enabled */
7994 if (lpfc_is_vmid_enabled(phba))
7995 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
7998 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
8000 /* Initialize the Abort buffer list used by driver */
8001 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
8002 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
8004 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8005 /* Initialize the Abort nvme buffer list used by driver */
8006 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
8007 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8008 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
8009 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
8010 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
8013 /* This abort list used by worker thread */
8014 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
8015 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
8016 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
8017 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
8020 * Initialize driver internal slow-path work queues
8023 /* Driver internel slow-path CQ Event pool */
8024 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
8025 /* Response IOCB work queue list */
8026 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
8027 /* Asynchronous event CQ Event work queue list */
8028 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
8029 /* Slow-path XRI aborted CQ Event work queue list */
8030 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
8031 /* Receive queue CQ Event work queue list */
8032 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
8034 /* Initialize extent block lists. */
8035 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
8036 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
8037 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
8038 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
8040 /* Initialize mboxq lists. If the early init routines fail
8041 * these lists need to be correctly initialized.
8043 INIT_LIST_HEAD(&phba->sli.mboxq);
8044 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
8046 /* initialize optic_state to 0xFF */
8047 phba->sli4_hba.lnk_info.optic_state = 0xff;
8049 /* Allocate device driver memory */
8050 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
8052 goto out_destroy_workqueue;
8054 /* IF Type 2 ports get initialized now. */
8055 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
8056 LPFC_SLI_INTF_IF_TYPE_2) {
8057 rc = lpfc_pci_function_reset(phba);
8062 phba->temp_sensor_support = 1;
8065 /* Create the bootstrap mailbox command */
8066 rc = lpfc_create_bootstrap_mbox(phba);
8070 /* Set up the host's endian order with the device. */
8071 rc = lpfc_setup_endian_order(phba);
8073 goto out_free_bsmbx;
8075 /* Set up the hba's configuration parameters. */
8076 rc = lpfc_sli4_read_config(phba);
8078 goto out_free_bsmbx;
8080 if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
8081 /* Right now the link is down, if FA-PWWN is configured the
8082 * firmware will try FLOGI before the driver gets a link up.
8083 * If it fails, the driver should get a MISCONFIGURED async
8084 * event which will clear this flag. The only notification
8085 * the driver gets is if it fails, if it succeeds there is no
8086 * notification given. Assume success.
8088 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
8091 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
8093 goto out_free_bsmbx;
8095 /* IF Type 0 ports get initialized now. */
8096 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8097 LPFC_SLI_INTF_IF_TYPE_0) {
8098 rc = lpfc_pci_function_reset(phba);
8100 goto out_free_bsmbx;
8103 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8107 goto out_free_bsmbx;
8110 /* Check for NVMET being configured */
8111 phba->nvmet_support = 0;
8112 if (lpfc_enable_nvmet_cnt) {
8114 /* First get WWN of HBA instance */
8115 lpfc_read_nv(phba, mboxq);
8116 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8117 if (rc != MBX_SUCCESS) {
8118 lpfc_printf_log(phba, KERN_ERR,
8120 "6016 Mailbox failed , mbxCmd x%x "
8121 "READ_NV, mbxStatus x%x\n",
8122 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8123 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
8124 mempool_free(mboxq, phba->mbox_mem_pool);
8126 goto out_free_bsmbx;
8129 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
8131 wwn = cpu_to_be64(wwn);
8132 phba->sli4_hba.wwnn.u.name = wwn;
8133 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
8135 /* wwn is WWPN of HBA instance */
8136 wwn = cpu_to_be64(wwn);
8137 phba->sli4_hba.wwpn.u.name = wwn;
8139 /* Check to see if it matches any module parameter */
8140 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
8141 if (wwn == lpfc_enable_nvmet[i]) {
8142 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
8143 if (lpfc_nvmet_mem_alloc(phba))
8146 phba->nvmet_support = 1; /* a match */
8148 lpfc_printf_log(phba, KERN_ERR,
8150 "6017 NVME Target %016llx\n",
8153 lpfc_printf_log(phba, KERN_ERR,
8155 "6021 Can't enable NVME Target."
8156 " NVME_TARGET_FC infrastructure"
8157 " is not in kernel\n");
8159 /* Not supported for NVMET */
8160 phba->cfg_xri_rebalancing = 0;
8161 if (phba->irq_chann_mode == NHT_MODE) {
8162 phba->cfg_irq_chann =
8163 phba->sli4_hba.num_present_cpu;
8164 phba->cfg_hdw_queue =
8165 phba->sli4_hba.num_present_cpu;
8166 phba->irq_chann_mode = NORMAL_MODE;
8173 lpfc_nvme_mod_param_dep(phba);
8176 * Get sli4 parameters that override parameters from Port capabilities.
8177 * If this call fails, it isn't critical unless the SLI4 parameters come
8180 rc = lpfc_get_sli4_parameters(phba, mboxq);
8182 if_type = bf_get(lpfc_sli_intf_if_type,
8183 &phba->sli4_hba.sli_intf);
8184 if_fam = bf_get(lpfc_sli_intf_sli_family,
8185 &phba->sli4_hba.sli_intf);
8186 if (phba->sli4_hba.extents_in_use &&
8187 phba->sli4_hba.rpi_hdrs_in_use) {
8188 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8189 "2999 Unsupported SLI4 Parameters "
8190 "Extents and RPI headers enabled.\n");
8191 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8192 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
8193 mempool_free(mboxq, phba->mbox_mem_pool);
8195 goto out_free_bsmbx;
8198 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8199 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
8200 mempool_free(mboxq, phba->mbox_mem_pool);
8202 goto out_free_bsmbx;
8207 * 1 for cmd, 1 for rsp, NVME adds an extra one
8208 * for boundary conditions in its max_sgl_segment template.
8211 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
8215 * It doesn't matter what family our adapter is in, we are
8216 * limited to 2 Pages, 512 SGEs, for our SGL.
8217 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
8219 max_buf_size = (2 * SLI4_PAGE_SIZE);
8222 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
8223 * used to create the sg_dma_buf_pool must be calculated.
8225 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8226 /* Both cfg_enable_bg and cfg_external_dif code paths */
8229 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
8230 * the FCP rsp, and a SGE. Sice we have no control
8231 * over how many protection segments the SCSI Layer
8232 * will hand us (ie: there could be one for every block
8233 * in the IO), just allocate enough SGEs to accomidate
8234 * our max amount and we need to limit lpfc_sg_seg_cnt
8235 * to minimize the risk of running out.
8237 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd32) +
8238 sizeof(struct fcp_rsp) + max_buf_size;
8240 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
8241 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
8244 * If supporting DIF, reduce the seg count for scsi to
8245 * allow room for the DIF sges.
8247 if (phba->cfg_enable_bg &&
8248 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
8249 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
8251 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8255 * The scsi_buf for a regular I/O holds the FCP cmnd,
8256 * the FCP rsp, a SGE for each, and a SGE for up to
8257 * cfg_sg_seg_cnt data segments.
8259 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd32) +
8260 sizeof(struct fcp_rsp) +
8261 ((phba->cfg_sg_seg_cnt + extra) *
8262 sizeof(struct sli4_sge));
8264 /* Total SGEs for scsi_sg_list */
8265 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
8266 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8269 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
8270 * need to post 1 page for the SGL.
8274 if (phba->cfg_xpsgl && !phba->nvmet_support)
8275 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
8276 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
8277 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
8279 phba->cfg_sg_dma_buf_size =
8280 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
8282 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
8283 sizeof(struct sli4_sge);
8285 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
8286 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8287 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
8288 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
8289 "6300 Reducing NVME sg segment "
8291 LPFC_MAX_NVME_SEG_CNT);
8292 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
8294 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
8297 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
8298 "9087 sg_seg_cnt:%d dmabuf_size:%d "
8299 "total:%d scsi:%d nvme:%d\n",
8300 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
8301 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
8302 phba->cfg_nvme_seg_cnt);
8304 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
8305 i = phba->cfg_sg_dma_buf_size;
8309 phba->lpfc_sg_dma_buf_pool =
8310 dma_pool_create("lpfc_sg_dma_buf_pool",
8312 phba->cfg_sg_dma_buf_size,
8314 if (!phba->lpfc_sg_dma_buf_pool) {
8316 goto out_free_bsmbx;
8319 phba->lpfc_cmd_rsp_buf_pool =
8320 dma_pool_create("lpfc_cmd_rsp_buf_pool",
8322 sizeof(struct fcp_cmnd32) +
8323 sizeof(struct fcp_rsp),
8325 if (!phba->lpfc_cmd_rsp_buf_pool) {
8327 goto out_free_sg_dma_buf;
8330 mempool_free(mboxq, phba->mbox_mem_pool);
8332 /* Verify OAS is supported */
8333 lpfc_sli4_oas_verify(phba);
8335 /* Verify RAS support on adapter */
8336 lpfc_sli4_ras_init(phba);
8338 /* Verify all the SLI4 queues */
8339 rc = lpfc_sli4_queue_verify(phba);
8341 goto out_free_cmd_rsp_buf;
8343 /* Create driver internal CQE event pool */
8344 rc = lpfc_sli4_cq_event_pool_create(phba);
8346 goto out_free_cmd_rsp_buf;
8348 /* Initialize sgl lists per host */
8349 lpfc_init_sgl_list(phba);
8351 /* Allocate and initialize active sgl array */
8352 rc = lpfc_init_active_sgl_array(phba);
8354 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8355 "1430 Failed to initialize sgl list.\n");
8356 goto out_destroy_cq_event_pool;
8358 rc = lpfc_sli4_init_rpi_hdrs(phba);
8360 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8361 "1432 Failed to initialize rpi headers.\n");
8362 goto out_free_active_sgl;
8365 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
8366 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
8367 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
8369 if (!phba->fcf.fcf_rr_bmask) {
8370 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8371 "2759 Failed allocate memory for FCF round "
8372 "robin failover bmask\n");
8374 goto out_remove_rpi_hdrs;
8377 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
8378 sizeof(struct lpfc_hba_eq_hdl),
8380 if (!phba->sli4_hba.hba_eq_hdl) {
8381 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8382 "2572 Failed allocate memory for "
8383 "fast-path per-EQ handle array\n");
8385 goto out_free_fcf_rr_bmask;
8388 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
8389 sizeof(struct lpfc_vector_map_info),
8391 if (!phba->sli4_hba.cpu_map) {
8392 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8393 "3327 Failed allocate memory for msi-x "
8394 "interrupt vector mapping\n");
8396 goto out_free_hba_eq_hdl;
8399 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
8400 if (!phba->sli4_hba.eq_info) {
8401 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8402 "3321 Failed allocation for per_cpu stats\n");
8404 goto out_free_hba_cpu_map;
8407 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
8408 sizeof(*phba->sli4_hba.idle_stat),
8410 if (!phba->sli4_hba.idle_stat) {
8411 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8412 "3390 Failed allocation for idle_stat\n");
8414 goto out_free_hba_eq_info;
8417 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8418 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
8419 if (!phba->sli4_hba.c_stat) {
8420 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8421 "3332 Failed allocating per cpu hdwq stats\n");
8423 goto out_free_hba_idle_stat;
8427 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
8428 if (!phba->cmf_stat) {
8429 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8430 "3331 Failed allocating per cpu cgn stats\n");
8432 goto out_free_hba_hdwq_info;
8436 * Enable sr-iov virtual functions if supported and configured
8437 * through the module parameter.
8439 if (phba->cfg_sriov_nr_virtfn > 0) {
8440 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
8441 phba->cfg_sriov_nr_virtfn);
8443 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8444 "3020 Requested number of SR-IOV "
8445 "virtual functions (%d) is not "
8447 phba->cfg_sriov_nr_virtfn);
8448 phba->cfg_sriov_nr_virtfn = 0;
8454 out_free_hba_hdwq_info:
8455 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8456 free_percpu(phba->sli4_hba.c_stat);
8457 out_free_hba_idle_stat:
8459 kfree(phba->sli4_hba.idle_stat);
8460 out_free_hba_eq_info:
8461 free_percpu(phba->sli4_hba.eq_info);
8462 out_free_hba_cpu_map:
8463 kfree(phba->sli4_hba.cpu_map);
8464 out_free_hba_eq_hdl:
8465 kfree(phba->sli4_hba.hba_eq_hdl);
8466 out_free_fcf_rr_bmask:
8467 kfree(phba->fcf.fcf_rr_bmask);
8468 out_remove_rpi_hdrs:
8469 lpfc_sli4_remove_rpi_hdrs(phba);
8470 out_free_active_sgl:
8471 lpfc_free_active_sgl(phba);
8472 out_destroy_cq_event_pool:
8473 lpfc_sli4_cq_event_pool_destroy(phba);
8474 out_free_cmd_rsp_buf:
8475 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
8476 phba->lpfc_cmd_rsp_buf_pool = NULL;
8477 out_free_sg_dma_buf:
8478 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
8479 phba->lpfc_sg_dma_buf_pool = NULL;
8481 lpfc_destroy_bootstrap_mbox(phba);
8483 lpfc_mem_free(phba);
8484 out_destroy_workqueue:
8485 destroy_workqueue(phba->wq);
8491 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
8492 * @phba: pointer to lpfc hba data structure.
8494 * This routine is invoked to unset the driver internal resources set up
8495 * specific for supporting the SLI-4 HBA device it attached to.
8498 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
8500 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
8502 free_percpu(phba->sli4_hba.eq_info);
8503 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8504 free_percpu(phba->sli4_hba.c_stat);
8506 free_percpu(phba->cmf_stat);
8507 kfree(phba->sli4_hba.idle_stat);
8509 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
8510 kfree(phba->sli4_hba.cpu_map);
8511 phba->sli4_hba.num_possible_cpu = 0;
8512 phba->sli4_hba.num_present_cpu = 0;
8513 phba->sli4_hba.curr_disp_cpu = 0;
8514 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
8516 /* Free memory allocated for fast-path work queue handles */
8517 kfree(phba->sli4_hba.hba_eq_hdl);
8519 /* Free the allocated rpi headers. */
8520 lpfc_sli4_remove_rpi_hdrs(phba);
8521 lpfc_sli4_remove_rpis(phba);
8523 /* Free eligible FCF index bmask */
8524 kfree(phba->fcf.fcf_rr_bmask);
8526 /* Free the ELS sgl list */
8527 lpfc_free_active_sgl(phba);
8528 lpfc_free_els_sgl_list(phba);
8529 lpfc_free_nvmet_sgl_list(phba);
8531 /* Free the completion queue EQ event pool */
8532 lpfc_sli4_cq_event_release_all(phba);
8533 lpfc_sli4_cq_event_pool_destroy(phba);
8535 /* Release resource identifiers. */
8536 lpfc_sli4_dealloc_resource_identifiers(phba);
8538 /* Free the bsmbx region. */
8539 lpfc_destroy_bootstrap_mbox(phba);
8541 /* Free the SLI Layer memory with SLI4 HBAs */
8542 lpfc_mem_free_all(phba);
8544 /* Free the current connect table */
8545 list_for_each_entry_safe(conn_entry, next_conn_entry,
8546 &phba->fcf_conn_rec_list, list) {
8547 list_del_init(&conn_entry->list);
8555 * lpfc_init_api_table_setup - Set up init api function jump table
8556 * @phba: The hba struct for which this call is being executed.
8557 * @dev_grp: The HBA PCI-Device group number.
8559 * This routine sets up the device INIT interface API function jump table
8562 * Returns: 0 - success, -ENODEV - failure.
8565 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8567 phba->lpfc_hba_init_link = lpfc_hba_init_link;
8568 phba->lpfc_hba_down_link = lpfc_hba_down_link;
8569 phba->lpfc_selective_reset = lpfc_selective_reset;
8571 case LPFC_PCI_DEV_LP:
8572 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
8573 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
8574 phba->lpfc_stop_port = lpfc_stop_port_s3;
8576 case LPFC_PCI_DEV_OC:
8577 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
8578 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
8579 phba->lpfc_stop_port = lpfc_stop_port_s4;
8582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8583 "1431 Invalid HBA PCI-device group: 0x%x\n",
8591 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
8592 * @phba: pointer to lpfc hba data structure.
8594 * This routine is invoked to set up the driver internal resources after the
8595 * device specific resource setup to support the HBA device it attached to.
8599 * other values - error
8602 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
8606 /* Startup the kernel thread for this host adapter. */
8607 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8608 "lpfc_worker_%d", phba->brd_no);
8609 if (IS_ERR(phba->worker_thread)) {
8610 error = PTR_ERR(phba->worker_thread);
8618 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
8619 * @phba: pointer to lpfc hba data structure.
8621 * This routine is invoked to unset the driver internal resources set up after
8622 * the device specific resource setup for supporting the HBA device it
8626 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
8629 destroy_workqueue(phba->wq);
8633 /* Stop kernel worker thread */
8634 if (phba->worker_thread)
8635 kthread_stop(phba->worker_thread);
8639 * lpfc_free_iocb_list - Free iocb list.
8640 * @phba: pointer to lpfc hba data structure.
8642 * This routine is invoked to free the driver's IOCB list and memory.
8645 lpfc_free_iocb_list(struct lpfc_hba *phba)
8647 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
8649 spin_lock_irq(&phba->hbalock);
8650 list_for_each_entry_safe(iocbq_entry, iocbq_next,
8651 &phba->lpfc_iocb_list, list) {
8652 list_del(&iocbq_entry->list);
8654 phba->total_iocbq_bufs--;
8656 spin_unlock_irq(&phba->hbalock);
8662 * lpfc_init_iocb_list - Allocate and initialize iocb list.
8663 * @phba: pointer to lpfc hba data structure.
8664 * @iocb_count: number of requested iocbs
8666 * This routine is invoked to allocate and initizlize the driver's IOCB
8667 * list and set up the IOCB tag array accordingly.
8671 * other values - error
8674 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8676 struct lpfc_iocbq *iocbq_entry = NULL;
8680 /* Initialize and populate the iocb list per host. */
8681 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
8682 for (i = 0; i < iocb_count; i++) {
8683 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
8684 if (iocbq_entry == NULL) {
8685 printk(KERN_ERR "%s: only allocated %d iocbs of "
8686 "expected %d count. Unloading driver.\n",
8687 __func__, i, iocb_count);
8688 goto out_free_iocbq;
8691 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8694 printk(KERN_ERR "%s: failed to allocate IOTAG. "
8695 "Unloading driver.\n", __func__);
8696 goto out_free_iocbq;
8698 iocbq_entry->sli4_lxritag = NO_XRI;
8699 iocbq_entry->sli4_xritag = NO_XRI;
8701 spin_lock_irq(&phba->hbalock);
8702 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8703 phba->total_iocbq_bufs++;
8704 spin_unlock_irq(&phba->hbalock);
8710 lpfc_free_iocb_list(phba);
8716 * lpfc_free_sgl_list - Free a given sgl list.
8717 * @phba: pointer to lpfc hba data structure.
8718 * @sglq_list: pointer to the head of sgl list.
8720 * This routine is invoked to free a give sgl list and memory.
8723 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
8725 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8727 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8728 list_del(&sglq_entry->list);
8729 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8735 * lpfc_free_els_sgl_list - Free els sgl list.
8736 * @phba: pointer to lpfc hba data structure.
8738 * This routine is invoked to free the driver's els sgl list and memory.
8741 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8743 LIST_HEAD(sglq_list);
8745 /* Retrieve all els sgls from driver list */
8746 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
8747 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
8748 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
8750 /* Now free the sgl list */
8751 lpfc_free_sgl_list(phba, &sglq_list);
8755 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8756 * @phba: pointer to lpfc hba data structure.
8758 * This routine is invoked to free the driver's nvmet sgl list and memory.
8761 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8763 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8764 LIST_HEAD(sglq_list);
8766 /* Retrieve all nvmet sgls from driver list */
8767 spin_lock_irq(&phba->hbalock);
8768 spin_lock(&phba->sli4_hba.sgl_list_lock);
8769 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8770 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8771 spin_unlock_irq(&phba->hbalock);
8773 /* Now free the sgl list */
8774 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8775 list_del(&sglq_entry->list);
8776 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8780 /* Update the nvmet_xri_cnt to reflect no current sgls.
8781 * The next initialization cycle sets the count and allocates
8782 * the sgls over again.
8784 phba->sli4_hba.nvmet_xri_cnt = 0;
8788 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8789 * @phba: pointer to lpfc hba data structure.
8791 * This routine is invoked to allocate the driver's active sgl memory.
8792 * This array will hold the sglq_entry's for active IOs.
8795 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8798 size = sizeof(struct lpfc_sglq *);
8799 size *= phba->sli4_hba.max_cfg_param.max_xri;
8801 phba->sli4_hba.lpfc_sglq_active_list =
8802 kzalloc(size, GFP_KERNEL);
8803 if (!phba->sli4_hba.lpfc_sglq_active_list)
8809 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8810 * @phba: pointer to lpfc hba data structure.
8812 * This routine is invoked to walk through the array of active sglq entries
8813 * and free all of the resources.
8814 * This is just a place holder for now.
8817 lpfc_free_active_sgl(struct lpfc_hba *phba)
8819 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8823 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8824 * @phba: pointer to lpfc hba data structure.
8826 * This routine is invoked to allocate and initizlize the driver's sgl
8827 * list and set up the sgl xritag tag array accordingly.
8831 lpfc_init_sgl_list(struct lpfc_hba *phba)
8833 /* Initialize and populate the sglq list per host/VF. */
8834 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
8835 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8836 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
8837 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8839 /* els xri-sgl book keeping */
8840 phba->sli4_hba.els_xri_cnt = 0;
8842 /* nvme xri-buffer book keeping */
8843 phba->sli4_hba.io_xri_cnt = 0;
8847 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8848 * @phba: pointer to lpfc hba data structure.
8850 * This routine is invoked to post rpi header templates to the
8851 * port for those SLI4 ports that do not support extents. This routine
8852 * posts a PAGE_SIZE memory region to the port to hold up to
8853 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8854 * and should be called only when interrupts are disabled.
8858 * -ERROR - otherwise.
8861 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8864 struct lpfc_rpi_hdr *rpi_hdr;
8866 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
8867 if (!phba->sli4_hba.rpi_hdrs_in_use)
8869 if (phba->sli4_hba.extents_in_use)
8872 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8874 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8875 "0391 Error during rpi post operation\n");
8876 lpfc_sli4_remove_rpis(phba);
8884 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8885 * @phba: pointer to lpfc hba data structure.
8887 * This routine is invoked to allocate a single 4KB memory region to
8888 * support rpis and stores them in the phba. This single region
8889 * provides support for up to 64 rpis. The region is used globally
8893 * A valid rpi hdr on success.
8894 * A NULL pointer on any failure.
8896 struct lpfc_rpi_hdr *
8897 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8899 uint16_t rpi_limit, curr_rpi_range;
8900 struct lpfc_dmabuf *dmabuf;
8901 struct lpfc_rpi_hdr *rpi_hdr;
8904 * If the SLI4 port supports extents, posting the rpi header isn't
8905 * required. Set the expected maximum count and let the actual value
8906 * get set when extents are fully allocated.
8908 if (!phba->sli4_hba.rpi_hdrs_in_use)
8910 if (phba->sli4_hba.extents_in_use)
8913 /* The limit on the logical index is just the max_rpi count. */
8914 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
8916 spin_lock_irq(&phba->hbalock);
8918 * Establish the starting RPI in this header block. The starting
8919 * rpi is normalized to a zero base because the physical rpi is
8922 curr_rpi_range = phba->sli4_hba.next_rpi;
8923 spin_unlock_irq(&phba->hbalock);
8925 /* Reached full RPI range */
8926 if (curr_rpi_range == rpi_limit)
8930 * First allocate the protocol header region for the port. The
8931 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8933 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8937 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8938 LPFC_HDR_TEMPLATE_SIZE,
8939 &dmabuf->phys, GFP_KERNEL);
8940 if (!dmabuf->virt) {
8942 goto err_free_dmabuf;
8945 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
8947 goto err_free_coherent;
8950 /* Save the rpi header data for cleanup later. */
8951 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
8953 goto err_free_coherent;
8955 rpi_hdr->dmabuf = dmabuf;
8956 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
8957 rpi_hdr->page_count = 1;
8958 spin_lock_irq(&phba->hbalock);
8960 /* The rpi_hdr stores the logical index only. */
8961 rpi_hdr->start_rpi = curr_rpi_range;
8962 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
8963 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
8965 spin_unlock_irq(&phba->hbalock);
8969 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
8970 dmabuf->virt, dmabuf->phys);
8977 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
8978 * @phba: pointer to lpfc hba data structure.
8980 * This routine is invoked to remove all memory resources allocated
8981 * to support rpis for SLI4 ports not supporting extents. This routine
8982 * presumes the caller has released all rpis consumed by fabric or port
8983 * logins and is prepared to have the header pages removed.
8986 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
8988 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
8990 if (!phba->sli4_hba.rpi_hdrs_in_use)
8993 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
8994 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
8995 list_del(&rpi_hdr->list);
8996 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
8997 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
8998 kfree(rpi_hdr->dmabuf);
9002 /* There are no rpis available to the port now. */
9003 phba->sli4_hba.next_rpi = 0;
9007 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
9008 * @pdev: pointer to pci device data structure.
9010 * This routine is invoked to allocate the driver hba data structure for an
9011 * HBA device. If the allocation is successful, the phba reference to the
9012 * PCI device data structure is set.
9015 * pointer to @phba - successful
9018 static struct lpfc_hba *
9019 lpfc_hba_alloc(struct pci_dev *pdev)
9021 struct lpfc_hba *phba;
9023 /* Allocate memory for HBA structure */
9024 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
9026 dev_err(&pdev->dev, "failed to allocate hba struct\n");
9030 /* Set reference to PCI device in HBA structure */
9031 phba->pcidev = pdev;
9033 /* Assign an unused board number */
9034 phba->brd_no = lpfc_get_instance();
9035 if (phba->brd_no < 0) {
9039 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
9041 spin_lock_init(&phba->ct_ev_lock);
9042 INIT_LIST_HEAD(&phba->ct_ev_waiters);
9048 * lpfc_hba_free - Free driver hba data structure with a device.
9049 * @phba: pointer to lpfc hba data structure.
9051 * This routine is invoked to free the driver hba data structure with an
9055 lpfc_hba_free(struct lpfc_hba *phba)
9057 if (phba->sli_rev == LPFC_SLI_REV4)
9058 kfree(phba->sli4_hba.hdwq);
9060 /* Release the driver assigned board number */
9061 idr_remove(&lpfc_hba_index, phba->brd_no);
9063 /* Free memory allocated with sli3 rings */
9064 kfree(phba->sli.sli3_ring);
9065 phba->sli.sli3_ring = NULL;
9072 * lpfc_setup_fdmi_mask - Setup initial FDMI mask for HBA and Port attributes
9073 * @vport: pointer to lpfc vport data structure.
9075 * This routine is will setup initial FDMI attribute masks for
9076 * FDMI2 or SmartSAN depending on module parameters. The driver will attempt
9077 * to get these attributes first before falling back, the attribute
9078 * fallback hierarchy is SmartSAN -> FDMI2 -> FMDI1
9081 lpfc_setup_fdmi_mask(struct lpfc_vport *vport)
9083 struct lpfc_hba *phba = vport->phba;
9085 set_bit(FC_ALLOW_FDMI, &vport->load_flag);
9086 if (phba->cfg_enable_SmartSAN ||
9087 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) {
9088 /* Setup appropriate attribute masks */
9089 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
9090 if (phba->cfg_enable_SmartSAN)
9091 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
9093 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
9096 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
9097 "6077 Setup FDMI mask: hba x%x port x%x\n",
9098 vport->fdmi_hba_mask, vport->fdmi_port_mask);
9102 * lpfc_create_shost - Create hba physical port with associated scsi host.
9103 * @phba: pointer to lpfc hba data structure.
9105 * This routine is invoked to create HBA physical port and associate a SCSI
9110 * other values - error
9113 lpfc_create_shost(struct lpfc_hba *phba)
9115 struct lpfc_vport *vport;
9116 struct Scsi_Host *shost;
9118 /* Initialize HBA FC structure */
9119 phba->fc_edtov = FF_DEF_EDTOV;
9120 phba->fc_ratov = FF_DEF_RATOV;
9121 phba->fc_altov = FF_DEF_ALTOV;
9122 phba->fc_arbtov = FF_DEF_ARBTOV;
9124 atomic_set(&phba->sdev_cnt, 0);
9125 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
9129 shost = lpfc_shost_from_vport(vport);
9130 phba->pport = vport;
9132 if (phba->nvmet_support) {
9133 /* Only 1 vport (pport) will support NVME target */
9134 phba->targetport = NULL;
9135 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
9136 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
9137 "6076 NVME Target Found\n");
9140 lpfc_debugfs_initialize(vport);
9141 /* Put reference to SCSI host to driver's device private data */
9142 pci_set_drvdata(phba->pcidev, shost);
9144 lpfc_setup_fdmi_mask(vport);
9147 * At this point we are fully registered with PSA. In addition,
9148 * any initial discovery should be completed.
9154 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
9155 * @phba: pointer to lpfc hba data structure.
9157 * This routine is invoked to destroy HBA physical port and the associated
9161 lpfc_destroy_shost(struct lpfc_hba *phba)
9163 struct lpfc_vport *vport = phba->pport;
9165 /* Destroy physical port that associated with the SCSI host */
9166 destroy_port(vport);
9172 * lpfc_setup_bg - Setup Block guard structures and debug areas.
9173 * @phba: pointer to lpfc hba data structure.
9174 * @shost: the shost to be used to detect Block guard settings.
9176 * This routine sets up the local Block guard protocol settings for @shost.
9177 * This routine also allocates memory for debugging bg buffers.
9180 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
9185 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9186 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9187 "1478 Registering BlockGuard with the "
9190 old_mask = phba->cfg_prot_mask;
9191 old_guard = phba->cfg_prot_guard;
9193 /* Only allow supported values */
9194 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
9195 SHOST_DIX_TYPE0_PROTECTION |
9196 SHOST_DIX_TYPE1_PROTECTION);
9197 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
9198 SHOST_DIX_GUARD_CRC);
9200 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
9201 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
9202 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
9204 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9205 if ((old_mask != phba->cfg_prot_mask) ||
9206 (old_guard != phba->cfg_prot_guard))
9207 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9208 "1475 Registering BlockGuard with the "
9209 "SCSI layer: mask %d guard %d\n",
9210 phba->cfg_prot_mask,
9211 phba->cfg_prot_guard);
9213 scsi_host_set_prot(shost, phba->cfg_prot_mask);
9214 scsi_host_set_guard(shost, phba->cfg_prot_guard);
9216 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9217 "1479 Not Registering BlockGuard with the SCSI "
9218 "layer, Bad protection parameters: %d %d\n",
9219 old_mask, old_guard);
9224 * lpfc_post_init_setup - Perform necessary device post initialization setup.
9225 * @phba: pointer to lpfc hba data structure.
9227 * This routine is invoked to perform all the necessary post initialization
9228 * setup for the device.
9231 lpfc_post_init_setup(struct lpfc_hba *phba)
9233 struct Scsi_Host *shost;
9234 struct lpfc_adapter_event_header adapter_event;
9236 /* Get the default values for Model Name and Description */
9237 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9240 * hba setup may have changed the hba_queue_depth so we need to
9241 * adjust the value of can_queue.
9243 shost = pci_get_drvdata(phba->pcidev);
9244 shost->can_queue = phba->cfg_hba_queue_depth - 10;
9246 lpfc_host_attrib_init(shost);
9248 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9249 spin_lock_irq(shost->host_lock);
9250 lpfc_poll_start_timer(phba);
9251 spin_unlock_irq(shost->host_lock);
9254 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9255 "0428 Perform SCSI scan\n");
9256 /* Send board arrival event to upper layer */
9257 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
9258 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
9259 fc_host_post_vendor_event(shost, fc_get_event_number(),
9260 sizeof(adapter_event),
9261 (char *) &adapter_event,
9267 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
9268 * @phba: pointer to lpfc hba data structure.
9270 * This routine is invoked to set up the PCI device memory space for device
9271 * with SLI-3 interface spec.
9275 * other values - error
9278 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
9280 struct pci_dev *pdev = phba->pcidev;
9281 unsigned long bar0map_len, bar2map_len;
9289 /* Set the device DMA mask size */
9290 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9292 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9297 /* Get the bus address of Bar0 and Bar2 and the number of bytes
9298 * required by each mapping.
9300 phba->pci_bar0_map = pci_resource_start(pdev, 0);
9301 bar0map_len = pci_resource_len(pdev, 0);
9303 phba->pci_bar2_map = pci_resource_start(pdev, 2);
9304 bar2map_len = pci_resource_len(pdev, 2);
9306 /* Map HBA SLIM to a kernel virtual address. */
9307 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
9308 if (!phba->slim_memmap_p) {
9309 dev_printk(KERN_ERR, &pdev->dev,
9310 "ioremap failed for SLIM memory.\n");
9314 /* Map HBA Control Registers to a kernel virtual address. */
9315 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
9316 if (!phba->ctrl_regs_memmap_p) {
9317 dev_printk(KERN_ERR, &pdev->dev,
9318 "ioremap failed for HBA control registers.\n");
9319 goto out_iounmap_slim;
9322 /* Allocate memory for SLI-2 structures */
9323 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9324 &phba->slim2p.phys, GFP_KERNEL);
9325 if (!phba->slim2p.virt)
9328 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
9329 phba->mbox_ext = (phba->slim2p.virt +
9330 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
9331 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
9332 phba->IOCBs = (phba->slim2p.virt +
9333 offsetof(struct lpfc_sli2_slim, IOCBs));
9335 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
9336 lpfc_sli_hbq_size(),
9337 &phba->hbqslimp.phys,
9339 if (!phba->hbqslimp.virt)
9342 hbq_count = lpfc_sli_hbq_count();
9343 ptr = phba->hbqslimp.virt;
9344 for (i = 0; i < hbq_count; ++i) {
9345 phba->hbqs[i].hbq_virt = ptr;
9346 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
9347 ptr += (lpfc_hbq_defs[i]->entry_count *
9348 sizeof(struct lpfc_hbq_entry));
9350 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
9351 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
9353 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
9355 phba->MBslimaddr = phba->slim_memmap_p;
9356 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
9357 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
9358 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
9359 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
9364 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9365 phba->slim2p.virt, phba->slim2p.phys);
9367 iounmap(phba->ctrl_regs_memmap_p);
9369 iounmap(phba->slim_memmap_p);
9375 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
9376 * @phba: pointer to lpfc hba data structure.
9378 * This routine is invoked to unset the PCI device memory space for device
9379 * with SLI-3 interface spec.
9382 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
9384 struct pci_dev *pdev;
9386 /* Obtain PCI device reference */
9390 pdev = phba->pcidev;
9392 /* Free coherent DMA memory allocated */
9393 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9394 phba->hbqslimp.virt, phba->hbqslimp.phys);
9395 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9396 phba->slim2p.virt, phba->slim2p.phys);
9398 /* I/O memory unmap */
9399 iounmap(phba->ctrl_regs_memmap_p);
9400 iounmap(phba->slim_memmap_p);
9406 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
9407 * @phba: pointer to lpfc hba data structure.
9409 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
9410 * done and check status.
9412 * Return 0 if successful, otherwise -ENODEV.
9415 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
9417 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
9418 struct lpfc_register reg_data;
9419 int i, port_error = 0;
9422 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
9423 memset(®_data, 0, sizeof(reg_data));
9424 if (!phba->sli4_hba.PSMPHRregaddr)
9427 /* Wait up to 30 seconds for the SLI Port POST done and ready */
9428 for (i = 0; i < 3000; i++) {
9429 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9430 &portsmphr_reg.word0) ||
9431 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
9432 /* Port has a fatal POST error, break out */
9433 port_error = -ENODEV;
9436 if (LPFC_POST_STAGE_PORT_READY ==
9437 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
9443 * If there was a port error during POST, then don't proceed with
9444 * other register reads as the data may not be valid. Just exit.
9447 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9448 "1408 Port Failed POST - portsmphr=0x%x, "
9449 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
9450 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
9451 portsmphr_reg.word0,
9452 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
9453 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
9454 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
9455 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
9456 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
9457 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
9458 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
9459 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
9461 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9462 "2534 Device Info: SLIFamily=0x%x, "
9463 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
9464 "SLIHint_2=0x%x, FT=0x%x\n",
9465 bf_get(lpfc_sli_intf_sli_family,
9466 &phba->sli4_hba.sli_intf),
9467 bf_get(lpfc_sli_intf_slirev,
9468 &phba->sli4_hba.sli_intf),
9469 bf_get(lpfc_sli_intf_if_type,
9470 &phba->sli4_hba.sli_intf),
9471 bf_get(lpfc_sli_intf_sli_hint1,
9472 &phba->sli4_hba.sli_intf),
9473 bf_get(lpfc_sli_intf_sli_hint2,
9474 &phba->sli4_hba.sli_intf),
9475 bf_get(lpfc_sli_intf_func_type,
9476 &phba->sli4_hba.sli_intf));
9478 * Check for other Port errors during the initialization
9479 * process. Fail the load if the port did not come up
9482 if_type = bf_get(lpfc_sli_intf_if_type,
9483 &phba->sli4_hba.sli_intf);
9485 case LPFC_SLI_INTF_IF_TYPE_0:
9486 phba->sli4_hba.ue_mask_lo =
9487 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
9488 phba->sli4_hba.ue_mask_hi =
9489 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
9491 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
9493 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
9494 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
9495 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
9496 lpfc_printf_log(phba, KERN_ERR,
9498 "1422 Unrecoverable Error "
9499 "Detected during POST "
9500 "uerr_lo_reg=0x%x, "
9501 "uerr_hi_reg=0x%x, "
9502 "ue_mask_lo_reg=0x%x, "
9503 "ue_mask_hi_reg=0x%x\n",
9506 phba->sli4_hba.ue_mask_lo,
9507 phba->sli4_hba.ue_mask_hi);
9508 port_error = -ENODEV;
9511 case LPFC_SLI_INTF_IF_TYPE_2:
9512 case LPFC_SLI_INTF_IF_TYPE_6:
9513 /* Final checks. The port status should be clean. */
9514 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9516 lpfc_sli4_unrecoverable_port(®_data)) {
9517 phba->work_status[0] =
9518 readl(phba->sli4_hba.u.if_type2.
9520 phba->work_status[1] =
9521 readl(phba->sli4_hba.u.if_type2.
9523 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9524 "2888 Unrecoverable port error "
9525 "following POST: port status reg "
9526 "0x%x, port_smphr reg 0x%x, "
9527 "error 1=0x%x, error 2=0x%x\n",
9529 portsmphr_reg.word0,
9530 phba->work_status[0],
9531 phba->work_status[1]);
9532 port_error = -ENODEV;
9536 if (lpfc_pldv_detect &&
9537 bf_get(lpfc_sli_intf_sli_family,
9538 &phba->sli4_hba.sli_intf) ==
9539 LPFC_SLI_INTF_FAMILY_G6)
9540 pci_write_config_byte(phba->pcidev,
9541 LPFC_SLI_INTF, CFG_PLD);
9543 case LPFC_SLI_INTF_IF_TYPE_1:
9552 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
9553 * @phba: pointer to lpfc hba data structure.
9554 * @if_type: The SLI4 interface type getting configured.
9556 * This routine is invoked to set up SLI4 BAR0 PCI config space register
9560 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9563 case LPFC_SLI_INTF_IF_TYPE_0:
9564 phba->sli4_hba.u.if_type0.UERRLOregaddr =
9565 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
9566 phba->sli4_hba.u.if_type0.UERRHIregaddr =
9567 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
9568 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
9569 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
9570 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
9571 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
9572 phba->sli4_hba.SLIINTFregaddr =
9573 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9575 case LPFC_SLI_INTF_IF_TYPE_2:
9576 phba->sli4_hba.u.if_type2.EQDregaddr =
9577 phba->sli4_hba.conf_regs_memmap_p +
9578 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9579 phba->sli4_hba.u.if_type2.ERR1regaddr =
9580 phba->sli4_hba.conf_regs_memmap_p +
9581 LPFC_CTL_PORT_ER1_OFFSET;
9582 phba->sli4_hba.u.if_type2.ERR2regaddr =
9583 phba->sli4_hba.conf_regs_memmap_p +
9584 LPFC_CTL_PORT_ER2_OFFSET;
9585 phba->sli4_hba.u.if_type2.CTRLregaddr =
9586 phba->sli4_hba.conf_regs_memmap_p +
9587 LPFC_CTL_PORT_CTL_OFFSET;
9588 phba->sli4_hba.u.if_type2.STATUSregaddr =
9589 phba->sli4_hba.conf_regs_memmap_p +
9590 LPFC_CTL_PORT_STA_OFFSET;
9591 phba->sli4_hba.SLIINTFregaddr =
9592 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9593 phba->sli4_hba.PSMPHRregaddr =
9594 phba->sli4_hba.conf_regs_memmap_p +
9595 LPFC_CTL_PORT_SEM_OFFSET;
9596 phba->sli4_hba.RQDBregaddr =
9597 phba->sli4_hba.conf_regs_memmap_p +
9598 LPFC_ULP0_RQ_DOORBELL;
9599 phba->sli4_hba.WQDBregaddr =
9600 phba->sli4_hba.conf_regs_memmap_p +
9601 LPFC_ULP0_WQ_DOORBELL;
9602 phba->sli4_hba.CQDBregaddr =
9603 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
9604 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9605 phba->sli4_hba.MQDBregaddr =
9606 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
9607 phba->sli4_hba.BMBXregaddr =
9608 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9610 case LPFC_SLI_INTF_IF_TYPE_6:
9611 phba->sli4_hba.u.if_type2.EQDregaddr =
9612 phba->sli4_hba.conf_regs_memmap_p +
9613 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9614 phba->sli4_hba.u.if_type2.ERR1regaddr =
9615 phba->sli4_hba.conf_regs_memmap_p +
9616 LPFC_CTL_PORT_ER1_OFFSET;
9617 phba->sli4_hba.u.if_type2.ERR2regaddr =
9618 phba->sli4_hba.conf_regs_memmap_p +
9619 LPFC_CTL_PORT_ER2_OFFSET;
9620 phba->sli4_hba.u.if_type2.CTRLregaddr =
9621 phba->sli4_hba.conf_regs_memmap_p +
9622 LPFC_CTL_PORT_CTL_OFFSET;
9623 phba->sli4_hba.u.if_type2.STATUSregaddr =
9624 phba->sli4_hba.conf_regs_memmap_p +
9625 LPFC_CTL_PORT_STA_OFFSET;
9626 phba->sli4_hba.PSMPHRregaddr =
9627 phba->sli4_hba.conf_regs_memmap_p +
9628 LPFC_CTL_PORT_SEM_OFFSET;
9629 phba->sli4_hba.BMBXregaddr =
9630 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9632 case LPFC_SLI_INTF_IF_TYPE_1:
9634 dev_printk(KERN_ERR, &phba->pcidev->dev,
9635 "FATAL - unsupported SLI4 interface type - %d\n",
9642 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
9643 * @phba: pointer to lpfc hba data structure.
9644 * @if_type: sli if type to operate on.
9646 * This routine is invoked to set up SLI4 BAR1 register memory map.
9649 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9652 case LPFC_SLI_INTF_IF_TYPE_0:
9653 phba->sli4_hba.PSMPHRregaddr =
9654 phba->sli4_hba.ctrl_regs_memmap_p +
9655 LPFC_SLIPORT_IF0_SMPHR;
9656 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9658 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9660 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9663 case LPFC_SLI_INTF_IF_TYPE_6:
9664 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9665 LPFC_IF6_RQ_DOORBELL;
9666 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9667 LPFC_IF6_WQ_DOORBELL;
9668 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9669 LPFC_IF6_CQ_DOORBELL;
9670 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9671 LPFC_IF6_EQ_DOORBELL;
9672 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9673 LPFC_IF6_MQ_DOORBELL;
9675 case LPFC_SLI_INTF_IF_TYPE_2:
9676 case LPFC_SLI_INTF_IF_TYPE_1:
9678 dev_err(&phba->pcidev->dev,
9679 "FATAL - unsupported SLI4 interface type - %d\n",
9686 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
9687 * @phba: pointer to lpfc hba data structure.
9688 * @vf: virtual function number
9690 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
9691 * based on the given viftual function number, @vf.
9693 * Return 0 if successful, otherwise -ENODEV.
9696 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9698 if (vf > LPFC_VIR_FUNC_MAX)
9701 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9702 vf * LPFC_VFR_PAGE_SIZE +
9703 LPFC_ULP0_RQ_DOORBELL);
9704 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9705 vf * LPFC_VFR_PAGE_SIZE +
9706 LPFC_ULP0_WQ_DOORBELL);
9707 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9708 vf * LPFC_VFR_PAGE_SIZE +
9709 LPFC_EQCQ_DOORBELL);
9710 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9711 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9712 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9713 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9714 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9719 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9720 * @phba: pointer to lpfc hba data structure.
9722 * This routine is invoked to create the bootstrap mailbox
9723 * region consistent with the SLI-4 interface spec. This
9724 * routine allocates all memory necessary to communicate
9725 * mailbox commands to the port and sets up all alignment
9726 * needs. No locks are expected to be held when calling
9731 * -ENOMEM - could not allocated memory.
9734 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9737 struct lpfc_dmabuf *dmabuf;
9738 struct dma_address *dma_address;
9742 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9747 * The bootstrap mailbox region is comprised of 2 parts
9748 * plus an alignment restriction of 16 bytes.
9750 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
9751 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9752 &dmabuf->phys, GFP_KERNEL);
9753 if (!dmabuf->virt) {
9759 * Initialize the bootstrap mailbox pointers now so that the register
9760 * operations are simple later. The mailbox dma address is required
9761 * to be 16-byte aligned. Also align the virtual memory as each
9762 * maibox is copied into the bmbx mailbox region before issuing the
9763 * command to the port.
9765 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9766 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9768 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9769 LPFC_ALIGN_16_BYTE);
9770 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9771 LPFC_ALIGN_16_BYTE);
9774 * Set the high and low physical addresses now. The SLI4 alignment
9775 * requirement is 16 bytes and the mailbox is posted to the port
9776 * as two 30-bit addresses. The other data is a bit marking whether
9777 * the 30-bit address is the high or low address.
9778 * Upcast bmbx aphys to 64bits so shift instruction compiles
9779 * clean on 32 bit machines.
9781 dma_address = &phba->sli4_hba.bmbx.dma_address;
9782 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9783 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9784 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9785 LPFC_BMBX_BIT1_ADDR_HI);
9787 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9788 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9789 LPFC_BMBX_BIT1_ADDR_LO);
9794 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9795 * @phba: pointer to lpfc hba data structure.
9797 * This routine is invoked to teardown the bootstrap mailbox
9798 * region and release all host resources. This routine requires
9799 * the caller to ensure all mailbox commands recovered, no
9800 * additional mailbox comands are sent, and interrupts are disabled
9801 * before calling this routine.
9805 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9807 dma_free_coherent(&phba->pcidev->dev,
9808 phba->sli4_hba.bmbx.bmbx_size,
9809 phba->sli4_hba.bmbx.dmabuf->virt,
9810 phba->sli4_hba.bmbx.dmabuf->phys);
9812 kfree(phba->sli4_hba.bmbx.dmabuf);
9813 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9816 static const char * const lpfc_topo_to_str[] = {
9826 #define LINK_FLAGS_DEF 0x0
9827 #define LINK_FLAGS_P2P 0x1
9828 #define LINK_FLAGS_LOOP 0x2
9830 * lpfc_map_topology - Map the topology read from READ_CONFIG
9831 * @phba: pointer to lpfc hba data structure.
9832 * @rd_config: pointer to read config data
9834 * This routine is invoked to map the topology values as read
9835 * from the read config mailbox command. If the persistent
9836 * topology feature is supported, the firmware will provide the
9837 * saved topology information to be used in INIT_LINK
9840 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9844 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9845 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9846 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9848 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9849 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9852 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9853 "2019 FW does not support persistent topology "
9854 "Using driver parameter defined value [%s]",
9855 lpfc_topo_to_str[phba->cfg_topology]);
9858 /* FW supports persistent topology - override module parameter value */
9859 set_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag);
9861 /* if ASIC_GEN_NUM >= 0xC) */
9862 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9863 LPFC_SLI_INTF_IF_TYPE_6) ||
9864 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9865 LPFC_SLI_INTF_FAMILY_G6)) {
9867 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9868 ? FLAGS_TOPOLOGY_MODE_LOOP
9869 : FLAGS_TOPOLOGY_MODE_PT_PT);
9871 clear_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag);
9874 /* If topology failover set - pt is '0' or '1' */
9875 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9876 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9878 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9879 ? FLAGS_TOPOLOGY_MODE_PT_PT
9880 : FLAGS_TOPOLOGY_MODE_LOOP);
9882 if (test_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag))
9883 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9884 "2020 Using persistent topology value [%s]",
9885 lpfc_topo_to_str[phba->cfg_topology]);
9887 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9888 "2021 Invalid topology values from FW "
9889 "Using driver parameter defined value [%s]",
9890 lpfc_topo_to_str[phba->cfg_topology]);
9894 * lpfc_sli4_read_config - Get the config parameters.
9895 * @phba: pointer to lpfc hba data structure.
9897 * This routine is invoked to read the configuration parameters from the HBA.
9898 * The configuration parameters are used to set the base and maximum values
9899 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9900 * allocation for the port.
9904 * -ENOMEM - No available memory
9905 * -EIO - The mailbox failed to complete successfully.
9908 lpfc_sli4_read_config(struct lpfc_hba *phba)
9911 struct lpfc_mbx_read_config *rd_config;
9912 union lpfc_sli4_cfg_shdr *shdr;
9913 uint32_t shdr_status, shdr_add_status;
9914 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9915 struct lpfc_rsrc_desc_fcfcoe *desc;
9917 uint16_t forced_link_speed;
9918 uint32_t if_type, qmin, fawwpn;
9919 int length, i, rc = 0, rc2;
9921 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9923 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9924 "2011 Unable to allocate memory for issuing "
9925 "SLI_CONFIG_SPECIAL mailbox command\n");
9929 lpfc_read_config(phba, pmb);
9931 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9932 if (rc != MBX_SUCCESS) {
9933 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9934 "2012 Mailbox failed , mbxCmd x%x "
9935 "READ_CONFIG, mbxStatus x%x\n",
9936 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9937 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9940 rd_config = &pmb->u.mqe.un.rd_config;
9941 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9942 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
9943 phba->sli4_hba.lnk_info.lnk_tp =
9944 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
9945 phba->sli4_hba.lnk_info.lnk_no =
9946 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
9947 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9948 "3081 lnk_type:%d, lnk_numb:%d\n",
9949 phba->sli4_hba.lnk_info.lnk_tp,
9950 phba->sli4_hba.lnk_info.lnk_no);
9952 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9953 "3082 Mailbox (x%x) returned ldv:x0\n",
9954 bf_get(lpfc_mqe_command, &pmb->u.mqe));
9955 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
9956 phba->bbcredit_support = 1;
9957 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
9960 fawwpn = bf_get(lpfc_mbx_rd_conf_fawwpn, rd_config);
9963 lpfc_printf_log(phba, KERN_INFO,
9964 LOG_INIT | LOG_DISCOVERY,
9965 "2702 READ_CONFIG: FA-PWWN is "
9967 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_CONFIG;
9969 /* Clear FW configured flag, preserve driver flag */
9970 phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_CONFIG;
9973 phba->sli4_hba.conf_trunk =
9974 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
9975 phba->sli4_hba.extents_in_use =
9976 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
9978 phba->sli4_hba.max_cfg_param.max_xri =
9979 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
9980 /* Reduce resource usage in kdump environment */
9981 if (is_kdump_kernel() &&
9982 phba->sli4_hba.max_cfg_param.max_xri > 512)
9983 phba->sli4_hba.max_cfg_param.max_xri = 512;
9984 phba->sli4_hba.max_cfg_param.xri_base =
9985 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
9986 phba->sli4_hba.max_cfg_param.max_vpi =
9987 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
9988 /* Limit the max we support */
9989 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
9990 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
9991 phba->sli4_hba.max_cfg_param.vpi_base =
9992 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
9993 phba->sli4_hba.max_cfg_param.max_rpi =
9994 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
9995 phba->sli4_hba.max_cfg_param.rpi_base =
9996 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
9997 phba->sli4_hba.max_cfg_param.max_vfi =
9998 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
9999 phba->sli4_hba.max_cfg_param.vfi_base =
10000 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
10001 phba->sli4_hba.max_cfg_param.max_fcfi =
10002 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
10003 phba->sli4_hba.max_cfg_param.max_eq =
10004 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
10005 phba->sli4_hba.max_cfg_param.max_rq =
10006 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
10007 phba->sli4_hba.max_cfg_param.max_wq =
10008 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
10009 phba->sli4_hba.max_cfg_param.max_cq =
10010 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
10011 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
10012 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
10013 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
10014 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
10015 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
10016 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
10017 phba->max_vports = phba->max_vpi;
10019 /* Next decide on FPIN or Signal E2E CGN support
10020 * For congestion alarms and warnings valid combination are:
10021 * 1. FPIN alarms / FPIN warnings
10022 * 2. Signal alarms / Signal warnings
10023 * 3. FPIN alarms / Signal warnings
10024 * 4. Signal alarms / FPIN warnings
10026 * Initialize the adapter frequency to 100 mSecs
10028 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
10029 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
10030 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
10032 if (lpfc_use_cgn_signal) {
10033 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
10034 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
10035 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
10037 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
10038 /* MUST support both alarm and warning
10039 * because EDC does not support alarm alone.
10041 if (phba->cgn_reg_signal !=
10042 EDC_CG_SIG_WARN_ONLY) {
10043 /* Must support both or none */
10044 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
10045 phba->cgn_reg_signal =
10046 EDC_CG_SIG_NOTSUPPORTED;
10048 phba->cgn_reg_signal =
10049 EDC_CG_SIG_WARN_ALARM;
10050 phba->cgn_reg_fpin =
10051 LPFC_CGN_FPIN_NONE;
10056 /* Set the congestion initial signal and fpin values. */
10057 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
10058 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
10060 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
10061 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
10062 phba->cgn_reg_signal, phba->cgn_reg_fpin);
10064 lpfc_map_topology(phba, rd_config);
10065 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10066 "2003 cfg params Extents? %d "
10071 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
10072 phba->sli4_hba.extents_in_use,
10073 phba->sli4_hba.max_cfg_param.xri_base,
10074 phba->sli4_hba.max_cfg_param.max_xri,
10075 phba->sli4_hba.max_cfg_param.vpi_base,
10076 phba->sli4_hba.max_cfg_param.max_vpi,
10077 phba->sli4_hba.max_cfg_param.vfi_base,
10078 phba->sli4_hba.max_cfg_param.max_vfi,
10079 phba->sli4_hba.max_cfg_param.rpi_base,
10080 phba->sli4_hba.max_cfg_param.max_rpi,
10081 phba->sli4_hba.max_cfg_param.max_fcfi,
10082 phba->sli4_hba.max_cfg_param.max_eq,
10083 phba->sli4_hba.max_cfg_param.max_cq,
10084 phba->sli4_hba.max_cfg_param.max_wq,
10085 phba->sli4_hba.max_cfg_param.max_rq,
10089 * Calculate queue resources based on how
10090 * many WQ/CQ/EQs are available.
10092 qmin = phba->sli4_hba.max_cfg_param.max_wq;
10093 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
10094 qmin = phba->sli4_hba.max_cfg_param.max_cq;
10096 * Reserve 4 (ELS, NVME LS, MBOX, plus one extra) and
10097 * the remainder can be used for NVME / FCP.
10100 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
10101 qmin = phba->sli4_hba.max_cfg_param.max_eq;
10103 /* Check to see if there is enough for default cfg */
10104 if ((phba->cfg_irq_chann > qmin) ||
10105 (phba->cfg_hdw_queue > qmin)) {
10106 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10107 "2005 Reducing Queues - "
10108 "FW resource limitation: "
10109 "WQ %d CQ %d EQ %d: min %d: "
10110 "IRQ %d HDWQ %d\n",
10111 phba->sli4_hba.max_cfg_param.max_wq,
10112 phba->sli4_hba.max_cfg_param.max_cq,
10113 phba->sli4_hba.max_cfg_param.max_eq,
10114 qmin, phba->cfg_irq_chann,
10115 phba->cfg_hdw_queue);
10117 if (phba->cfg_irq_chann > qmin)
10118 phba->cfg_irq_chann = qmin;
10119 if (phba->cfg_hdw_queue > qmin)
10120 phba->cfg_hdw_queue = qmin;
10127 /* Update link speed if forced link speed is supported */
10128 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10129 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10130 forced_link_speed =
10131 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
10132 if (forced_link_speed) {
10133 set_bit(HBA_FORCED_LINK_SPEED, &phba->hba_flag);
10135 switch (forced_link_speed) {
10136 case LINK_SPEED_1G:
10137 phba->cfg_link_speed =
10138 LPFC_USER_LINK_SPEED_1G;
10140 case LINK_SPEED_2G:
10141 phba->cfg_link_speed =
10142 LPFC_USER_LINK_SPEED_2G;
10144 case LINK_SPEED_4G:
10145 phba->cfg_link_speed =
10146 LPFC_USER_LINK_SPEED_4G;
10148 case LINK_SPEED_8G:
10149 phba->cfg_link_speed =
10150 LPFC_USER_LINK_SPEED_8G;
10152 case LINK_SPEED_10G:
10153 phba->cfg_link_speed =
10154 LPFC_USER_LINK_SPEED_10G;
10156 case LINK_SPEED_16G:
10157 phba->cfg_link_speed =
10158 LPFC_USER_LINK_SPEED_16G;
10160 case LINK_SPEED_32G:
10161 phba->cfg_link_speed =
10162 LPFC_USER_LINK_SPEED_32G;
10164 case LINK_SPEED_64G:
10165 phba->cfg_link_speed =
10166 LPFC_USER_LINK_SPEED_64G;
10169 phba->cfg_link_speed =
10170 LPFC_USER_LINK_SPEED_AUTO;
10173 lpfc_printf_log(phba, KERN_ERR,
10175 "0047 Unrecognized link "
10177 forced_link_speed);
10178 phba->cfg_link_speed =
10179 LPFC_USER_LINK_SPEED_AUTO;
10184 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
10185 length = phba->sli4_hba.max_cfg_param.max_xri -
10186 lpfc_sli4_get_els_iocb_cnt(phba);
10187 if (phba->cfg_hba_queue_depth > length) {
10188 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10189 "3361 HBA queue depth changed from %d to %d\n",
10190 phba->cfg_hba_queue_depth, length);
10191 phba->cfg_hba_queue_depth = length;
10194 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
10195 LPFC_SLI_INTF_IF_TYPE_2)
10198 /* get the pf# and vf# for SLI4 if_type 2 port */
10199 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
10200 sizeof(struct lpfc_sli4_cfg_mhdr));
10201 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
10202 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
10203 length, LPFC_SLI4_MBX_EMBED);
10205 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10206 shdr = (union lpfc_sli4_cfg_shdr *)
10207 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
10208 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10209 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10210 if (rc2 || shdr_status || shdr_add_status) {
10211 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10212 "3026 Mailbox failed , mbxCmd x%x "
10213 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
10214 bf_get(lpfc_mqe_command, &pmb->u.mqe),
10215 bf_get(lpfc_mqe_status, &pmb->u.mqe));
10219 /* search for fc_fcoe resrouce descriptor */
10220 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
10222 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
10223 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
10224 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
10225 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
10226 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
10227 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
10230 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
10231 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
10232 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
10233 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
10234 phba->sli4_hba.iov.pf_number =
10235 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
10236 phba->sli4_hba.iov.vf_number =
10237 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
10242 if (i < LPFC_RSRC_DESC_MAX_NUM)
10243 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10244 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
10245 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
10246 phba->sli4_hba.iov.vf_number);
10248 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10249 "3028 GET_FUNCTION_CONFIG: failed to find "
10250 "Resource Descriptor:x%x\n",
10251 LPFC_RSRC_DESC_TYPE_FCFCOE);
10254 mempool_free(pmb, phba->mbox_mem_pool);
10259 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
10260 * @phba: pointer to lpfc hba data structure.
10262 * This routine is invoked to setup the port-side endian order when
10263 * the port if_type is 0. This routine has no function for other
10268 * -ENOMEM - No available memory
10269 * -EIO - The mailbox failed to complete successfully.
10272 lpfc_setup_endian_order(struct lpfc_hba *phba)
10274 LPFC_MBOXQ_t *mboxq;
10275 uint32_t if_type, rc = 0;
10276 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
10277 HOST_ENDIAN_HIGH_WORD1};
10279 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10281 case LPFC_SLI_INTF_IF_TYPE_0:
10282 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10285 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10286 "0492 Unable to allocate memory for "
10287 "issuing SLI_CONFIG_SPECIAL mailbox "
10293 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
10294 * two words to contain special data values and no other data.
10296 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
10297 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
10298 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10299 if (rc != MBX_SUCCESS) {
10300 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10301 "0493 SLI_CONFIG_SPECIAL mailbox "
10302 "failed with status x%x\n",
10306 mempool_free(mboxq, phba->mbox_mem_pool);
10308 case LPFC_SLI_INTF_IF_TYPE_6:
10309 case LPFC_SLI_INTF_IF_TYPE_2:
10310 case LPFC_SLI_INTF_IF_TYPE_1:
10318 * lpfc_sli4_queue_verify - Verify and update EQ counts
10319 * @phba: pointer to lpfc hba data structure.
10321 * This routine is invoked to check the user settable queue counts for EQs.
10322 * After this routine is called the counts will be set to valid values that
10323 * adhere to the constraints of the system's interrupt vectors and the port's
10328 * -ENOMEM - No available memory
10331 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
10334 * Sanity check for configured queue parameters against the run-time
10335 * device parameters
10338 if (phba->nvmet_support) {
10339 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
10340 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
10341 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
10342 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
10345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10346 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
10347 phba->cfg_hdw_queue, phba->cfg_irq_chann,
10348 phba->cfg_nvmet_mrq);
10350 /* Get EQ depth from module parameter, fake the default for now */
10351 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10352 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10354 /* Get CQ depth from module parameter, fake the default for now */
10355 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10356 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10361 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
10363 struct lpfc_queue *qdesc;
10367 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
10368 /* Create Fast Path IO CQs */
10369 if (phba->enab_exp_wqcq_pages)
10370 /* Increase the CQ size when WQEs contain an embedded cdb */
10371 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10372 phba->sli4_hba.cq_esize,
10373 LPFC_CQE_EXP_COUNT, cpu);
10376 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10377 phba->sli4_hba.cq_esize,
10378 phba->sli4_hba.cq_ecount, cpu);
10380 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10381 "0499 Failed allocate fast-path IO CQ (%d)\n",
10385 qdesc->qe_valid = 1;
10387 qdesc->chann = cpu;
10388 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
10390 /* Create Fast Path IO WQs */
10391 if (phba->enab_exp_wqcq_pages) {
10392 /* Increase the WQ size when WQEs contain an embedded cdb */
10393 wqesize = (phba->fcp_embed_io) ?
10394 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
10395 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10397 LPFC_WQE_EXP_COUNT, cpu);
10399 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10400 phba->sli4_hba.wq_esize,
10401 phba->sli4_hba.wq_ecount, cpu);
10404 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10405 "0503 Failed allocate fast-path IO WQ (%d)\n",
10410 qdesc->chann = cpu;
10411 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
10412 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10417 * lpfc_sli4_queue_create - Create all the SLI4 queues
10418 * @phba: pointer to lpfc hba data structure.
10420 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
10421 * operation. For each SLI4 queue type, the parameters such as queue entry
10422 * count (queue depth) shall be taken from the module parameter. For now,
10423 * we just use some constant number as place holder.
10427 * -ENOMEM - No availble memory
10428 * -EIO - The mailbox failed to complete successfully.
10431 lpfc_sli4_queue_create(struct lpfc_hba *phba)
10433 struct lpfc_queue *qdesc;
10434 int idx, cpu, eqcpu;
10435 struct lpfc_sli4_hdw_queue *qp;
10436 struct lpfc_vector_map_info *cpup;
10437 struct lpfc_vector_map_info *eqcpup;
10438 struct lpfc_eq_intr_info *eqi;
10441 * Create HBA Record arrays.
10442 * Both NVME and FCP will share that same vectors / EQs
10444 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
10445 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
10446 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
10447 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
10448 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
10449 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
10450 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10451 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10452 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10453 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10455 if (!phba->sli4_hba.hdwq) {
10456 phba->sli4_hba.hdwq = kcalloc(
10457 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
10459 if (!phba->sli4_hba.hdwq) {
10460 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10461 "6427 Failed allocate memory for "
10462 "fast-path Hardware Queue array\n");
10465 /* Prepare hardware queues to take IO buffers */
10466 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10467 qp = &phba->sli4_hba.hdwq[idx];
10468 spin_lock_init(&qp->io_buf_list_get_lock);
10469 spin_lock_init(&qp->io_buf_list_put_lock);
10470 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
10471 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
10472 qp->get_io_bufs = 0;
10473 qp->put_io_bufs = 0;
10474 qp->total_io_bufs = 0;
10475 spin_lock_init(&qp->abts_io_buf_list_lock);
10476 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
10477 qp->abts_scsi_io_bufs = 0;
10478 qp->abts_nvme_io_bufs = 0;
10479 INIT_LIST_HEAD(&qp->sgl_list);
10480 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
10481 spin_lock_init(&qp->hdwq_lock);
10485 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10486 if (phba->nvmet_support) {
10487 phba->sli4_hba.nvmet_cqset = kcalloc(
10488 phba->cfg_nvmet_mrq,
10489 sizeof(struct lpfc_queue *),
10491 if (!phba->sli4_hba.nvmet_cqset) {
10492 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10493 "3121 Fail allocate memory for "
10494 "fast-path CQ set array\n");
10497 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
10498 phba->cfg_nvmet_mrq,
10499 sizeof(struct lpfc_queue *),
10501 if (!phba->sli4_hba.nvmet_mrq_hdr) {
10502 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10503 "3122 Fail allocate memory for "
10504 "fast-path RQ set hdr array\n");
10507 phba->sli4_hba.nvmet_mrq_data = kcalloc(
10508 phba->cfg_nvmet_mrq,
10509 sizeof(struct lpfc_queue *),
10511 if (!phba->sli4_hba.nvmet_mrq_data) {
10512 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10513 "3124 Fail allocate memory for "
10514 "fast-path RQ set data array\n");
10520 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10522 /* Create HBA Event Queues (EQs) */
10523 for_each_present_cpu(cpu) {
10524 /* We only want to create 1 EQ per vector, even though
10525 * multiple CPUs might be using that vector. so only
10526 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
10528 cpup = &phba->sli4_hba.cpu_map[cpu];
10529 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10532 /* Get a ptr to the Hardware Queue associated with this CPU */
10533 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10535 /* Allocate an EQ */
10536 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10537 phba->sli4_hba.eq_esize,
10538 phba->sli4_hba.eq_ecount, cpu);
10540 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10541 "0497 Failed allocate EQ (%d)\n",
10545 qdesc->qe_valid = 1;
10546 qdesc->hdwq = cpup->hdwq;
10547 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
10548 qdesc->last_cpu = qdesc->chann;
10550 /* Save the allocated EQ in the Hardware Queue */
10551 qp->hba_eq = qdesc;
10553 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
10554 list_add(&qdesc->cpu_list, &eqi->list);
10557 /* Now we need to populate the other Hardware Queues, that share
10558 * an IRQ vector, with the associated EQ ptr.
10560 for_each_present_cpu(cpu) {
10561 cpup = &phba->sli4_hba.cpu_map[cpu];
10563 /* Check for EQ already allocated in previous loop */
10564 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
10567 /* Check for multiple CPUs per hdwq */
10568 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10572 /* We need to share an EQ for this hdwq */
10573 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
10574 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
10575 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
10578 /* Allocate IO Path SLI4 CQ/WQs */
10579 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10580 if (lpfc_alloc_io_wq_cq(phba, idx))
10584 if (phba->nvmet_support) {
10585 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10586 cpu = lpfc_find_cpu_handle(phba, idx,
10587 LPFC_FIND_BY_HDWQ);
10588 qdesc = lpfc_sli4_queue_alloc(phba,
10589 LPFC_DEFAULT_PAGE_SIZE,
10590 phba->sli4_hba.cq_esize,
10591 phba->sli4_hba.cq_ecount,
10594 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10595 "3142 Failed allocate NVME "
10596 "CQ Set (%d)\n", idx);
10599 qdesc->qe_valid = 1;
10601 qdesc->chann = cpu;
10602 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
10607 * Create Slow Path Completion Queues (CQs)
10610 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
10611 /* Create slow-path Mailbox Command Complete Queue */
10612 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10613 phba->sli4_hba.cq_esize,
10614 phba->sli4_hba.cq_ecount, cpu);
10616 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10617 "0500 Failed allocate slow-path mailbox CQ\n");
10620 qdesc->qe_valid = 1;
10621 phba->sli4_hba.mbx_cq = qdesc;
10623 /* Create slow-path ELS Complete Queue */
10624 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10625 phba->sli4_hba.cq_esize,
10626 phba->sli4_hba.cq_ecount, cpu);
10628 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10629 "0501 Failed allocate slow-path ELS CQ\n");
10632 qdesc->qe_valid = 1;
10633 qdesc->chann = cpu;
10634 phba->sli4_hba.els_cq = qdesc;
10638 * Create Slow Path Work Queues (WQs)
10641 /* Create Mailbox Command Queue */
10643 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10644 phba->sli4_hba.mq_esize,
10645 phba->sli4_hba.mq_ecount, cpu);
10647 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10648 "0505 Failed allocate slow-path MQ\n");
10651 qdesc->chann = cpu;
10652 phba->sli4_hba.mbx_wq = qdesc;
10655 * Create ELS Work Queues
10658 /* Create slow-path ELS Work Queue */
10659 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10660 phba->sli4_hba.wq_esize,
10661 phba->sli4_hba.wq_ecount, cpu);
10663 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10664 "0504 Failed allocate slow-path ELS WQ\n");
10667 qdesc->chann = cpu;
10668 phba->sli4_hba.els_wq = qdesc;
10669 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10671 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10672 /* Create NVME LS Complete Queue */
10673 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10674 phba->sli4_hba.cq_esize,
10675 phba->sli4_hba.cq_ecount, cpu);
10677 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10678 "6079 Failed allocate NVME LS CQ\n");
10681 qdesc->chann = cpu;
10682 qdesc->qe_valid = 1;
10683 phba->sli4_hba.nvmels_cq = qdesc;
10685 /* Create NVME LS Work Queue */
10686 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10687 phba->sli4_hba.wq_esize,
10688 phba->sli4_hba.wq_ecount, cpu);
10690 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10691 "6080 Failed allocate NVME LS WQ\n");
10694 qdesc->chann = cpu;
10695 phba->sli4_hba.nvmels_wq = qdesc;
10696 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10700 * Create Receive Queue (RQ)
10703 /* Create Receive Queue for header */
10704 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10705 phba->sli4_hba.rq_esize,
10706 phba->sli4_hba.rq_ecount, cpu);
10708 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10709 "0506 Failed allocate receive HRQ\n");
10712 phba->sli4_hba.hdr_rq = qdesc;
10714 /* Create Receive Queue for data */
10715 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10716 phba->sli4_hba.rq_esize,
10717 phba->sli4_hba.rq_ecount, cpu);
10719 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10720 "0507 Failed allocate receive DRQ\n");
10723 phba->sli4_hba.dat_rq = qdesc;
10725 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10726 phba->nvmet_support) {
10727 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10728 cpu = lpfc_find_cpu_handle(phba, idx,
10729 LPFC_FIND_BY_HDWQ);
10730 /* Create NVMET Receive Queue for header */
10731 qdesc = lpfc_sli4_queue_alloc(phba,
10732 LPFC_DEFAULT_PAGE_SIZE,
10733 phba->sli4_hba.rq_esize,
10734 LPFC_NVMET_RQE_DEF_COUNT,
10737 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10738 "3146 Failed allocate "
10743 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10745 /* Only needed for header of RQ pair */
10746 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10749 if (qdesc->rqbp == NULL) {
10750 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10751 "6131 Failed allocate "
10756 /* Put list in known state in case driver load fails. */
10757 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10759 /* Create NVMET Receive Queue for data */
10760 qdesc = lpfc_sli4_queue_alloc(phba,
10761 LPFC_DEFAULT_PAGE_SIZE,
10762 phba->sli4_hba.rq_esize,
10763 LPFC_NVMET_RQE_DEF_COUNT,
10766 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10767 "3156 Failed allocate "
10772 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10776 /* Clear NVME stats */
10777 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10778 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10779 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10780 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10784 /* Clear SCSI stats */
10785 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10786 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10787 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10788 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10795 lpfc_sli4_queue_destroy(phba);
10800 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
10803 lpfc_sli4_queue_free(*qp);
10809 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10816 for (idx = 0; idx < max; idx++)
10817 __lpfc_sli4_release_queue(&(*qs)[idx]);
10824 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
10826 struct lpfc_sli4_hdw_queue *hdwq;
10827 struct lpfc_queue *eq;
10830 hdwq = phba->sli4_hba.hdwq;
10832 /* Loop thru all Hardware Queues */
10833 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10834 /* Free the CQ/WQ corresponding to the Hardware Queue */
10835 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10836 lpfc_sli4_queue_free(hdwq[idx].io_wq);
10837 hdwq[idx].hba_eq = NULL;
10838 hdwq[idx].io_cq = NULL;
10839 hdwq[idx].io_wq = NULL;
10840 if (phba->cfg_xpsgl && !phba->nvmet_support)
10841 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10842 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
10844 /* Loop thru all IRQ vectors */
10845 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10846 /* Free the EQ corresponding to the IRQ vector */
10847 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10848 lpfc_sli4_queue_free(eq);
10849 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10854 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10855 * @phba: pointer to lpfc hba data structure.
10857 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10862 * -ENOMEM - No available memory
10863 * -EIO - The mailbox failed to complete successfully.
10866 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10869 * Set FREE_INIT before beginning to free the queues.
10870 * Wait until the users of queues to acknowledge to
10871 * release queues by clearing FREE_WAIT.
10873 spin_lock_irq(&phba->hbalock);
10874 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10875 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10876 spin_unlock_irq(&phba->hbalock);
10878 spin_lock_irq(&phba->hbalock);
10880 spin_unlock_irq(&phba->hbalock);
10882 lpfc_sli4_cleanup_poll_list(phba);
10884 /* Release HBA eqs */
10885 if (phba->sli4_hba.hdwq)
10886 lpfc_sli4_release_hdwq(phba);
10888 if (phba->nvmet_support) {
10889 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10890 phba->cfg_nvmet_mrq);
10892 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10893 phba->cfg_nvmet_mrq);
10894 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10895 phba->cfg_nvmet_mrq);
10898 /* Release mailbox command work queue */
10899 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
10901 /* Release ELS work queue */
10902 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10904 /* Release ELS work queue */
10905 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
10907 /* Release unsolicited receive queue */
10908 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10909 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
10911 /* Release ELS complete queue */
10912 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10914 /* Release NVME LS complete queue */
10915 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
10917 /* Release mailbox command complete queue */
10918 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10920 /* Everything on this list has been freed */
10921 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10923 /* Done with freeing the queues */
10924 spin_lock_irq(&phba->hbalock);
10925 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10926 spin_unlock_irq(&phba->hbalock);
10930 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10932 struct lpfc_rqb *rqbp;
10933 struct lpfc_dmabuf *h_buf;
10934 struct rqb_dmabuf *rqb_buffer;
10937 while (!list_empty(&rqbp->rqb_buffer_list)) {
10938 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10939 struct lpfc_dmabuf, list);
10941 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10942 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
10943 rqbp->buffer_count--;
10949 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
10950 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
10951 int qidx, uint32_t qtype)
10953 struct lpfc_sli_ring *pring;
10956 if (!eq || !cq || !wq) {
10957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10958 "6085 Fast-path %s (%d) not allocated\n",
10959 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
10963 /* create the Cq first */
10964 rc = lpfc_cq_create(phba, cq, eq,
10965 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
10967 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10968 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
10969 qidx, (uint32_t)rc);
10973 if (qtype != LPFC_MBOX) {
10974 /* Setup cq_map for fast lookup */
10976 *cq_map = cq->queue_id;
10978 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10979 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
10980 qidx, cq->queue_id, qidx, eq->queue_id);
10982 /* create the wq */
10983 rc = lpfc_wq_create(phba, wq, cq, qtype);
10985 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10986 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
10987 qidx, (uint32_t)rc);
10988 /* no need to tear down cq - caller will do so */
10992 /* Bind this CQ/WQ to the NVME ring */
10994 pring->sli.sli4.wqp = (void *)wq;
10997 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10998 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
10999 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
11001 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
11003 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11004 "0539 Failed setup of slow-path MQ: "
11005 "rc = 0x%x\n", rc);
11006 /* no need to tear down cq - caller will do so */
11010 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11011 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
11012 phba->sli4_hba.mbx_wq->queue_id,
11013 phba->sli4_hba.mbx_cq->queue_id);
11020 * lpfc_setup_cq_lookup - Setup the CQ lookup table
11021 * @phba: pointer to lpfc hba data structure.
11023 * This routine will populate the cq_lookup table by all
11024 * available CQ queue_id's.
11027 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
11029 struct lpfc_queue *eq, *childq;
11032 memset(phba->sli4_hba.cq_lookup, 0,
11033 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
11034 /* Loop thru all IRQ vectors */
11035 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11036 /* Get the EQ corresponding to the IRQ vector */
11037 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11040 /* Loop through all CQs associated with that EQ */
11041 list_for_each_entry(childq, &eq->child_list, list) {
11042 if (childq->queue_id > phba->sli4_hba.cq_max)
11044 if (childq->subtype == LPFC_IO)
11045 phba->sli4_hba.cq_lookup[childq->queue_id] =
11052 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
11053 * @phba: pointer to lpfc hba data structure.
11055 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
11060 * -ENOMEM - No available memory
11061 * -EIO - The mailbox failed to complete successfully.
11064 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
11066 uint32_t shdr_status, shdr_add_status;
11067 union lpfc_sli4_cfg_shdr *shdr;
11068 struct lpfc_vector_map_info *cpup;
11069 struct lpfc_sli4_hdw_queue *qp;
11070 LPFC_MBOXQ_t *mboxq;
11072 uint32_t length, usdelay;
11075 /* Check for dual-ULP support */
11076 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11078 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11079 "3249 Unable to allocate memory for "
11080 "QUERY_FW_CFG mailbox command\n");
11083 length = (sizeof(struct lpfc_mbx_query_fw_config) -
11084 sizeof(struct lpfc_sli4_cfg_mhdr));
11085 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11086 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
11087 length, LPFC_SLI4_MBX_EMBED);
11089 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11091 shdr = (union lpfc_sli4_cfg_shdr *)
11092 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11093 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11094 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11095 if (shdr_status || shdr_add_status || rc) {
11096 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11097 "3250 QUERY_FW_CFG mailbox failed with status "
11098 "x%x add_status x%x, mbx status x%x\n",
11099 shdr_status, shdr_add_status, rc);
11100 mempool_free(mboxq, phba->mbox_mem_pool);
11105 phba->sli4_hba.fw_func_mode =
11106 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
11107 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
11108 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
11109 phba->sli4_hba.physical_port =
11110 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
11111 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11112 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
11113 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
11114 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
11116 mempool_free(mboxq, phba->mbox_mem_pool);
11119 * Set up HBA Event Queues (EQs)
11121 qp = phba->sli4_hba.hdwq;
11123 /* Set up HBA event queue */
11125 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11126 "3147 Fast-path EQs not allocated\n");
11131 /* Loop thru all IRQ vectors */
11132 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11133 /* Create HBA Event Queues (EQs) in order */
11134 for_each_present_cpu(cpu) {
11135 cpup = &phba->sli4_hba.cpu_map[cpu];
11137 /* Look for the CPU thats using that vector with
11138 * LPFC_CPU_FIRST_IRQ set.
11140 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11142 if (qidx != cpup->eq)
11145 /* Create an EQ for that vector */
11146 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
11147 phba->cfg_fcp_imax);
11149 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11150 "0523 Failed setup of fast-path"
11151 " EQ (%d), rc = 0x%x\n",
11152 cpup->eq, (uint32_t)rc);
11156 /* Save the EQ for that vector in the hba_eq_hdl */
11157 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
11158 qp[cpup->hdwq].hba_eq;
11160 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11161 "2584 HBA EQ setup: queue[%d]-id=%d\n",
11163 qp[cpup->hdwq].hba_eq->queue_id);
11167 /* Loop thru all Hardware Queues */
11168 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11169 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
11170 cpup = &phba->sli4_hba.cpu_map[cpu];
11172 /* Create the CQ/WQ corresponding to the Hardware Queue */
11173 rc = lpfc_create_wq_cq(phba,
11174 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
11177 &phba->sli4_hba.hdwq[qidx].io_cq_map,
11181 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11182 "0535 Failed to setup fastpath "
11183 "IO WQ/CQ (%d), rc = 0x%x\n",
11184 qidx, (uint32_t)rc);
11190 * Set up Slow Path Complete Queues (CQs)
11193 /* Set up slow-path MBOX CQ/MQ */
11195 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
11196 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11197 "0528 %s not allocated\n",
11198 phba->sli4_hba.mbx_cq ?
11199 "Mailbox WQ" : "Mailbox CQ");
11204 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11205 phba->sli4_hba.mbx_cq,
11206 phba->sli4_hba.mbx_wq,
11207 NULL, 0, LPFC_MBOX);
11209 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11210 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
11214 if (phba->nvmet_support) {
11215 if (!phba->sli4_hba.nvmet_cqset) {
11216 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11217 "3165 Fast-path NVME CQ Set "
11218 "array not allocated\n");
11222 if (phba->cfg_nvmet_mrq > 1) {
11223 rc = lpfc_cq_create_set(phba,
11224 phba->sli4_hba.nvmet_cqset,
11226 LPFC_WCQ, LPFC_NVMET);
11228 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11229 "3164 Failed setup of NVME CQ "
11230 "Set, rc = 0x%x\n",
11235 /* Set up NVMET Receive Complete Queue */
11236 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
11238 LPFC_WCQ, LPFC_NVMET);
11240 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11241 "6089 Failed setup NVMET CQ: "
11242 "rc = 0x%x\n", (uint32_t)rc);
11245 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
11247 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11248 "6090 NVMET CQ setup: cq-id=%d, "
11249 "parent eq-id=%d\n",
11250 phba->sli4_hba.nvmet_cqset[0]->queue_id,
11251 qp[0].hba_eq->queue_id);
11255 /* Set up slow-path ELS WQ/CQ */
11256 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
11257 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11258 "0530 ELS %s not allocated\n",
11259 phba->sli4_hba.els_cq ? "WQ" : "CQ");
11263 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11264 phba->sli4_hba.els_cq,
11265 phba->sli4_hba.els_wq,
11266 NULL, 0, LPFC_ELS);
11268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11269 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
11273 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11274 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
11275 phba->sli4_hba.els_wq->queue_id,
11276 phba->sli4_hba.els_cq->queue_id);
11278 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11279 /* Set up NVME LS Complete Queue */
11280 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
11281 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11282 "6091 LS %s not allocated\n",
11283 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
11287 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11288 phba->sli4_hba.nvmels_cq,
11289 phba->sli4_hba.nvmels_wq,
11290 NULL, 0, LPFC_NVME_LS);
11292 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11293 "0526 Failed setup of NVVME LS WQ/CQ: "
11294 "rc = 0x%x\n", (uint32_t)rc);
11298 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11299 "6096 ELS WQ setup: wq-id=%d, "
11300 "parent cq-id=%d\n",
11301 phba->sli4_hba.nvmels_wq->queue_id,
11302 phba->sli4_hba.nvmels_cq->queue_id);
11306 * Create NVMET Receive Queue (RQ)
11308 if (phba->nvmet_support) {
11309 if ((!phba->sli4_hba.nvmet_cqset) ||
11310 (!phba->sli4_hba.nvmet_mrq_hdr) ||
11311 (!phba->sli4_hba.nvmet_mrq_data)) {
11312 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11313 "6130 MRQ CQ Queues not "
11318 if (phba->cfg_nvmet_mrq > 1) {
11319 rc = lpfc_mrq_create(phba,
11320 phba->sli4_hba.nvmet_mrq_hdr,
11321 phba->sli4_hba.nvmet_mrq_data,
11322 phba->sli4_hba.nvmet_cqset,
11325 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11326 "6098 Failed setup of NVMET "
11327 "MRQ: rc = 0x%x\n",
11333 rc = lpfc_rq_create(phba,
11334 phba->sli4_hba.nvmet_mrq_hdr[0],
11335 phba->sli4_hba.nvmet_mrq_data[0],
11336 phba->sli4_hba.nvmet_cqset[0],
11339 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11340 "6057 Failed setup of NVMET "
11341 "Receive Queue: rc = 0x%x\n",
11347 phba, KERN_INFO, LOG_INIT,
11348 "6099 NVMET RQ setup: hdr-rq-id=%d, "
11349 "dat-rq-id=%d parent cq-id=%d\n",
11350 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
11351 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
11352 phba->sli4_hba.nvmet_cqset[0]->queue_id);
11357 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
11358 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11359 "0540 Receive Queue not allocated\n");
11364 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
11365 phba->sli4_hba.els_cq, LPFC_USOL);
11367 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11368 "0541 Failed setup of Receive Queue: "
11369 "rc = 0x%x\n", (uint32_t)rc);
11373 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11374 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
11375 "parent cq-id=%d\n",
11376 phba->sli4_hba.hdr_rq->queue_id,
11377 phba->sli4_hba.dat_rq->queue_id,
11378 phba->sli4_hba.els_cq->queue_id);
11380 if (phba->cfg_fcp_imax)
11381 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
11385 for (qidx = 0; qidx < phba->cfg_irq_chann;
11386 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
11387 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
11390 if (phba->sli4_hba.cq_max) {
11391 kfree(phba->sli4_hba.cq_lookup);
11392 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
11393 sizeof(struct lpfc_queue *), GFP_KERNEL);
11394 if (!phba->sli4_hba.cq_lookup) {
11395 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11396 "0549 Failed setup of CQ Lookup table: "
11397 "size 0x%x\n", phba->sli4_hba.cq_max);
11401 lpfc_setup_cq_lookup(phba);
11406 lpfc_sli4_queue_unset(phba);
11412 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
11413 * @phba: pointer to lpfc hba data structure.
11415 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
11420 * -ENOMEM - No available memory
11421 * -EIO - The mailbox failed to complete successfully.
11424 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
11426 struct lpfc_sli4_hdw_queue *qp;
11427 struct lpfc_queue *eq;
11430 /* Unset mailbox command work queue */
11431 if (phba->sli4_hba.mbx_wq)
11432 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
11434 /* Unset NVME LS work queue */
11435 if (phba->sli4_hba.nvmels_wq)
11436 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
11438 /* Unset ELS work queue */
11439 if (phba->sli4_hba.els_wq)
11440 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
11442 /* Unset unsolicited receive queue */
11443 if (phba->sli4_hba.hdr_rq)
11444 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
11445 phba->sli4_hba.dat_rq);
11447 /* Unset mailbox command complete queue */
11448 if (phba->sli4_hba.mbx_cq)
11449 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
11451 /* Unset ELS complete queue */
11452 if (phba->sli4_hba.els_cq)
11453 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
11455 /* Unset NVME LS complete queue */
11456 if (phba->sli4_hba.nvmels_cq)
11457 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
11459 if (phba->nvmet_support) {
11460 /* Unset NVMET MRQ queue */
11461 if (phba->sli4_hba.nvmet_mrq_hdr) {
11462 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11465 phba->sli4_hba.nvmet_mrq_hdr[qidx],
11466 phba->sli4_hba.nvmet_mrq_data[qidx]);
11469 /* Unset NVMET CQ Set complete queue */
11470 if (phba->sli4_hba.nvmet_cqset) {
11471 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11473 phba, phba->sli4_hba.nvmet_cqset[qidx]);
11477 /* Unset fast-path SLI4 queues */
11478 if (phba->sli4_hba.hdwq) {
11479 /* Loop thru all Hardware Queues */
11480 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11481 /* Destroy the CQ/WQ corresponding to Hardware Queue */
11482 qp = &phba->sli4_hba.hdwq[qidx];
11483 lpfc_wq_destroy(phba, qp->io_wq);
11484 lpfc_cq_destroy(phba, qp->io_cq);
11486 /* Loop thru all IRQ vectors */
11487 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11488 /* Destroy the EQ corresponding to the IRQ vector */
11489 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11490 lpfc_eq_destroy(phba, eq);
11494 kfree(phba->sli4_hba.cq_lookup);
11495 phba->sli4_hba.cq_lookup = NULL;
11496 phba->sli4_hba.cq_max = 0;
11500 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
11501 * @phba: pointer to lpfc hba data structure.
11503 * This routine is invoked to allocate and set up a pool of completion queue
11504 * events. The body of the completion queue event is a completion queue entry
11505 * CQE. For now, this pool is used for the interrupt service routine to queue
11506 * the following HBA completion queue events for the worker thread to process:
11507 * - Mailbox asynchronous events
11508 * - Receive queue completion unsolicited events
11509 * Later, this can be used for all the slow-path events.
11513 * -ENOMEM - No available memory
11516 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
11518 struct lpfc_cq_event *cq_event;
11521 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
11522 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
11524 goto out_pool_create_fail;
11525 list_add_tail(&cq_event->list,
11526 &phba->sli4_hba.sp_cqe_event_pool);
11530 out_pool_create_fail:
11531 lpfc_sli4_cq_event_pool_destroy(phba);
11536 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
11537 * @phba: pointer to lpfc hba data structure.
11539 * This routine is invoked to free the pool of completion queue events at
11540 * driver unload time. Note that, it is the responsibility of the driver
11541 * cleanup routine to free all the outstanding completion-queue events
11542 * allocated from this pool back into the pool before invoking this routine
11543 * to destroy the pool.
11546 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
11548 struct lpfc_cq_event *cq_event, *next_cq_event;
11550 list_for_each_entry_safe(cq_event, next_cq_event,
11551 &phba->sli4_hba.sp_cqe_event_pool, list) {
11552 list_del(&cq_event->list);
11558 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11559 * @phba: pointer to lpfc hba data structure.
11561 * This routine is the lock free version of the API invoked to allocate a
11562 * completion-queue event from the free pool.
11564 * Return: Pointer to the newly allocated completion-queue event if successful
11567 struct lpfc_cq_event *
11568 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11570 struct lpfc_cq_event *cq_event = NULL;
11572 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
11573 struct lpfc_cq_event, list);
11578 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11579 * @phba: pointer to lpfc hba data structure.
11581 * This routine is the lock version of the API invoked to allocate a
11582 * completion-queue event from the free pool.
11584 * Return: Pointer to the newly allocated completion-queue event if successful
11587 struct lpfc_cq_event *
11588 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11590 struct lpfc_cq_event *cq_event;
11591 unsigned long iflags;
11593 spin_lock_irqsave(&phba->hbalock, iflags);
11594 cq_event = __lpfc_sli4_cq_event_alloc(phba);
11595 spin_unlock_irqrestore(&phba->hbalock, iflags);
11600 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11601 * @phba: pointer to lpfc hba data structure.
11602 * @cq_event: pointer to the completion queue event to be freed.
11604 * This routine is the lock free version of the API invoked to release a
11605 * completion-queue event back into the free pool.
11608 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11609 struct lpfc_cq_event *cq_event)
11611 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
11615 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11616 * @phba: pointer to lpfc hba data structure.
11617 * @cq_event: pointer to the completion queue event to be freed.
11619 * This routine is the lock version of the API invoked to release a
11620 * completion-queue event back into the free pool.
11623 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11624 struct lpfc_cq_event *cq_event)
11626 unsigned long iflags;
11627 spin_lock_irqsave(&phba->hbalock, iflags);
11628 __lpfc_sli4_cq_event_release(phba, cq_event);
11629 spin_unlock_irqrestore(&phba->hbalock, iflags);
11633 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
11634 * @phba: pointer to lpfc hba data structure.
11636 * This routine is to free all the pending completion-queue events to the
11637 * back into the free pool for device reset.
11640 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
11642 LIST_HEAD(cq_event_list);
11643 struct lpfc_cq_event *cq_event;
11644 unsigned long iflags;
11646 /* Retrieve all the pending WCQEs from pending WCQE lists */
11648 /* Pending ELS XRI abort events */
11649 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11650 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11652 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11654 /* Pending asynnc events */
11655 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
11656 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
11658 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
11660 while (!list_empty(&cq_event_list)) {
11661 list_remove_head(&cq_event_list, cq_event,
11662 struct lpfc_cq_event, list);
11663 lpfc_sli4_cq_event_release(phba, cq_event);
11668 * lpfc_pci_function_reset - Reset pci function.
11669 * @phba: pointer to lpfc hba data structure.
11671 * This routine is invoked to request a PCI function reset. It will destroys
11672 * all resources assigned to the PCI function which originates this request.
11676 * -ENOMEM - No available memory
11677 * -EIO - The mailbox failed to complete successfully.
11680 lpfc_pci_function_reset(struct lpfc_hba *phba)
11682 LPFC_MBOXQ_t *mboxq;
11683 uint32_t rc = 0, if_type;
11684 uint32_t shdr_status, shdr_add_status;
11686 uint32_t port_reset = 0;
11687 union lpfc_sli4_cfg_shdr *shdr;
11688 struct lpfc_register reg_data;
11691 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11693 case LPFC_SLI_INTF_IF_TYPE_0:
11694 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
11697 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11698 "0494 Unable to allocate memory for "
11699 "issuing SLI_FUNCTION_RESET mailbox "
11704 /* Setup PCI function reset mailbox-ioctl command */
11705 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11706 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11707 LPFC_SLI4_MBX_EMBED);
11708 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11709 shdr = (union lpfc_sli4_cfg_shdr *)
11710 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11711 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11712 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11714 mempool_free(mboxq, phba->mbox_mem_pool);
11715 if (shdr_status || shdr_add_status || rc) {
11716 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11717 "0495 SLI_FUNCTION_RESET mailbox "
11718 "failed with status x%x add_status x%x,"
11719 " mbx status x%x\n",
11720 shdr_status, shdr_add_status, rc);
11724 case LPFC_SLI_INTF_IF_TYPE_2:
11725 case LPFC_SLI_INTF_IF_TYPE_6:
11728 * Poll the Port Status Register and wait for RDY for
11729 * up to 30 seconds. If the port doesn't respond, treat
11732 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
11733 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11734 STATUSregaddr, ®_data.word0)) {
11738 if (bf_get(lpfc_sliport_status_rdy, ®_data))
11743 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
11744 phba->work_status[0] = readl(
11745 phba->sli4_hba.u.if_type2.ERR1regaddr);
11746 phba->work_status[1] = readl(
11747 phba->sli4_hba.u.if_type2.ERR2regaddr);
11748 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11749 "2890 Port not ready, port status reg "
11750 "0x%x error 1=0x%x, error 2=0x%x\n",
11752 phba->work_status[0],
11753 phba->work_status[1]);
11758 if (bf_get(lpfc_sliport_status_pldv, ®_data))
11759 lpfc_pldv_detect = true;
11763 * Reset the port now
11765 reg_data.word0 = 0;
11766 bf_set(lpfc_sliport_ctrl_end, ®_data,
11767 LPFC_SLIPORT_LITTLE_ENDIAN);
11768 bf_set(lpfc_sliport_ctrl_ip, ®_data,
11769 LPFC_SLIPORT_INIT_PORT);
11770 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11773 pci_read_config_word(phba->pcidev,
11774 PCI_DEVICE_ID, &devid);
11779 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
11785 case LPFC_SLI_INTF_IF_TYPE_1:
11791 /* Catch the not-ready port failure after a port reset. */
11793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11794 "3317 HBA not functional: IP Reset Failed "
11795 "try: echo fw_reset > board_mode\n");
11803 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11804 * @phba: pointer to lpfc hba data structure.
11806 * This routine is invoked to set up the PCI device memory space for device
11807 * with SLI-4 interface spec.
11811 * other values - error
11814 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11816 struct pci_dev *pdev = phba->pcidev;
11817 unsigned long bar0map_len, bar1map_len, bar2map_len;
11824 /* Set the device DMA mask size */
11825 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11827 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11832 * The BARs and register set definitions and offset locations are
11833 * dependent on the if_type.
11835 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11836 &phba->sli4_hba.sli_intf.word0)) {
11840 /* There is no SLI3 failback for SLI4 devices. */
11841 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11842 LPFC_SLI_INTF_VALID) {
11843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11844 "2894 SLI_INTF reg contents invalid "
11845 "sli_intf reg 0x%x\n",
11846 phba->sli4_hba.sli_intf.word0);
11850 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11852 * Get the bus address of SLI4 device Bar regions and the
11853 * number of bytes required by each mapping. The mapping of the
11854 * particular PCI BARs regions is dependent on the type of
11857 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11858 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11859 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
11862 * Map SLI4 PCI Config Space Register base to a kernel virtual
11865 phba->sli4_hba.conf_regs_memmap_p =
11866 ioremap(phba->pci_bar0_map, bar0map_len);
11867 if (!phba->sli4_hba.conf_regs_memmap_p) {
11868 dev_printk(KERN_ERR, &pdev->dev,
11869 "ioremap failed for SLI4 PCI config "
11873 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
11874 /* Set up BAR0 PCI config space register memory map */
11875 lpfc_sli4_bar0_register_memmap(phba, if_type);
11877 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11878 bar0map_len = pci_resource_len(pdev, 1);
11879 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
11880 dev_printk(KERN_ERR, &pdev->dev,
11881 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
11884 phba->sli4_hba.conf_regs_memmap_p =
11885 ioremap(phba->pci_bar0_map, bar0map_len);
11886 if (!phba->sli4_hba.conf_regs_memmap_p) {
11887 dev_printk(KERN_ERR, &pdev->dev,
11888 "ioremap failed for SLI4 PCI config "
11892 lpfc_sli4_bar0_register_memmap(phba, if_type);
11895 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11896 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11898 * Map SLI4 if type 0 HBA Control Register base to a
11899 * kernel virtual address and setup the registers.
11901 phba->pci_bar1_map = pci_resource_start(pdev,
11903 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11904 phba->sli4_hba.ctrl_regs_memmap_p =
11905 ioremap(phba->pci_bar1_map,
11907 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11908 dev_err(&pdev->dev,
11909 "ioremap failed for SLI4 HBA "
11910 "control registers.\n");
11912 goto out_iounmap_conf;
11914 phba->pci_bar2_memmap_p =
11915 phba->sli4_hba.ctrl_regs_memmap_p;
11916 lpfc_sli4_bar1_register_memmap(phba, if_type);
11919 goto out_iounmap_conf;
11923 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11924 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11926 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11927 * virtual address and setup the registers.
11929 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11930 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11931 phba->sli4_hba.drbl_regs_memmap_p =
11932 ioremap(phba->pci_bar1_map, bar1map_len);
11933 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11934 dev_err(&pdev->dev,
11935 "ioremap failed for SLI4 HBA doorbell registers.\n");
11937 goto out_iounmap_conf;
11939 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11940 lpfc_sli4_bar1_register_memmap(phba, if_type);
11943 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11944 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11946 * Map SLI4 if type 0 HBA Doorbell Register base to
11947 * a kernel virtual address and setup the registers.
11949 phba->pci_bar2_map = pci_resource_start(pdev,
11951 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11952 phba->sli4_hba.drbl_regs_memmap_p =
11953 ioremap(phba->pci_bar2_map,
11955 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11956 dev_err(&pdev->dev,
11957 "ioremap failed for SLI4 HBA"
11958 " doorbell registers.\n");
11960 goto out_iounmap_ctrl;
11962 phba->pci_bar4_memmap_p =
11963 phba->sli4_hba.drbl_regs_memmap_p;
11964 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
11966 goto out_iounmap_all;
11969 goto out_iounmap_ctrl;
11973 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
11974 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11976 * Map SLI4 if type 6 HBA DPP Register base to a kernel
11977 * virtual address and setup the registers.
11979 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
11980 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11981 phba->sli4_hba.dpp_regs_memmap_p =
11982 ioremap(phba->pci_bar2_map, bar2map_len);
11983 if (!phba->sli4_hba.dpp_regs_memmap_p) {
11984 dev_err(&pdev->dev,
11985 "ioremap failed for SLI4 HBA dpp registers.\n");
11987 goto out_iounmap_all;
11989 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
11992 /* Set up the EQ/CQ register handeling functions now */
11994 case LPFC_SLI_INTF_IF_TYPE_0:
11995 case LPFC_SLI_INTF_IF_TYPE_2:
11996 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
11997 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
11998 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
12000 case LPFC_SLI_INTF_IF_TYPE_6:
12001 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
12002 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
12003 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
12012 if (phba->sli4_hba.drbl_regs_memmap_p)
12013 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12015 if (phba->sli4_hba.ctrl_regs_memmap_p)
12016 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
12018 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12024 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
12025 * @phba: pointer to lpfc hba data structure.
12027 * This routine is invoked to unset the PCI device memory space for device
12028 * with SLI-4 interface spec.
12031 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
12034 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
12037 case LPFC_SLI_INTF_IF_TYPE_0:
12038 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12039 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
12040 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12042 case LPFC_SLI_INTF_IF_TYPE_2:
12043 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12045 case LPFC_SLI_INTF_IF_TYPE_6:
12046 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12047 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12048 if (phba->sli4_hba.dpp_regs_memmap_p)
12049 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
12051 case LPFC_SLI_INTF_IF_TYPE_1:
12054 dev_printk(KERN_ERR, &phba->pcidev->dev,
12055 "FATAL - unsupported SLI4 interface type - %d\n",
12062 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
12063 * @phba: pointer to lpfc hba data structure.
12065 * This routine is invoked to enable the MSI-X interrupt vectors to device
12066 * with SLI-3 interface specs.
12070 * other values - error
12073 lpfc_sli_enable_msix(struct lpfc_hba *phba)
12078 /* Set up MSI-X multi-message vectors */
12079 rc = pci_alloc_irq_vectors(phba->pcidev,
12080 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
12082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12083 "0420 PCI enable MSI-X failed (%d)\n", rc);
12088 * Assign MSI-X vectors to interrupt handlers
12091 /* vector-0 is associated to slow-path handler */
12092 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
12093 &lpfc_sli_sp_intr_handler, 0,
12094 LPFC_SP_DRIVER_HANDLER_NAME, phba);
12096 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12097 "0421 MSI-X slow-path request_irq failed "
12102 /* vector-1 is associated to fast-path handler */
12103 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
12104 &lpfc_sli_fp_intr_handler, 0,
12105 LPFC_FP_DRIVER_HANDLER_NAME, phba);
12108 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12109 "0429 MSI-X fast-path request_irq failed "
12115 * Configure HBA MSI-X attention conditions to messages
12117 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12121 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12122 "0474 Unable to allocate memory for issuing "
12123 "MBOX_CONFIG_MSI command\n");
12126 rc = lpfc_config_msi(phba, pmb);
12129 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
12130 if (rc != MBX_SUCCESS) {
12131 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
12132 "0351 Config MSI mailbox command failed, "
12133 "mbxCmd x%x, mbxStatus x%x\n",
12134 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
12138 /* Free memory allocated for mailbox command */
12139 mempool_free(pmb, phba->mbox_mem_pool);
12143 /* Free memory allocated for mailbox command */
12144 mempool_free(pmb, phba->mbox_mem_pool);
12147 /* free the irq already requested */
12148 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
12151 /* free the irq already requested */
12152 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
12155 /* Unconfigure MSI-X capability structure */
12156 pci_free_irq_vectors(phba->pcidev);
12163 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
12164 * @phba: pointer to lpfc hba data structure.
12166 * This routine is invoked to enable the MSI interrupt mode to device with
12167 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
12168 * enable the MSI vector. The device driver is responsible for calling the
12169 * request_irq() to register MSI vector with a interrupt the handler, which
12170 * is done in this function.
12174 * other values - error
12177 lpfc_sli_enable_msi(struct lpfc_hba *phba)
12181 rc = pci_enable_msi(phba->pcidev);
12183 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12184 "0012 PCI enable MSI mode success.\n");
12186 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12187 "0471 PCI enable MSI mode failed (%d)\n", rc);
12191 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12192 0, LPFC_DRIVER_NAME, phba);
12194 pci_disable_msi(phba->pcidev);
12195 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12196 "0478 MSI request_irq failed (%d)\n", rc);
12202 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
12203 * @phba: pointer to lpfc hba data structure.
12204 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
12206 * This routine is invoked to enable device interrupt and associate driver's
12207 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
12208 * spec. Depends on the interrupt mode configured to the driver, the driver
12209 * will try to fallback from the configured interrupt mode to an interrupt
12210 * mode which is supported by the platform, kernel, and device in the order
12212 * MSI-X -> MSI -> IRQ.
12216 * other values - error
12219 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12221 uint32_t intr_mode = LPFC_INTR_ERROR;
12224 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
12225 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
12228 clear_bit(HBA_NEEDS_CFG_PORT, &phba->hba_flag);
12230 if (cfg_mode == 2) {
12231 /* Now, try to enable MSI-X interrupt mode */
12232 retval = lpfc_sli_enable_msix(phba);
12234 /* Indicate initialization to MSI-X mode */
12235 phba->intr_type = MSIX;
12240 /* Fallback to MSI if MSI-X initialization failed */
12241 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12242 retval = lpfc_sli_enable_msi(phba);
12244 /* Indicate initialization to MSI mode */
12245 phba->intr_type = MSI;
12250 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12251 if (phba->intr_type == NONE) {
12252 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12253 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12255 /* Indicate initialization to INTx mode */
12256 phba->intr_type = INTx;
12264 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
12265 * @phba: pointer to lpfc hba data structure.
12267 * This routine is invoked to disable device interrupt and disassociate the
12268 * driver's interrupt handler(s) from interrupt vector(s) to device with
12269 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
12270 * release the interrupt vector(s) for the message signaled interrupt.
12273 lpfc_sli_disable_intr(struct lpfc_hba *phba)
12277 if (phba->intr_type == MSIX)
12278 nr_irqs = LPFC_MSIX_VECTORS;
12282 for (i = 0; i < nr_irqs; i++)
12283 free_irq(pci_irq_vector(phba->pcidev, i), phba);
12284 pci_free_irq_vectors(phba->pcidev);
12286 /* Reset interrupt management states */
12287 phba->intr_type = NONE;
12288 phba->sli.slistat.sli_intr = 0;
12292 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
12293 * @phba: pointer to lpfc hba data structure.
12294 * @id: EQ vector index or Hardware Queue index
12295 * @match: LPFC_FIND_BY_EQ = match by EQ
12296 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
12297 * Return the CPU that matches the selection criteria
12300 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
12302 struct lpfc_vector_map_info *cpup;
12305 /* Loop through all CPUs */
12306 for_each_present_cpu(cpu) {
12307 cpup = &phba->sli4_hba.cpu_map[cpu];
12309 /* If we are matching by EQ, there may be multiple CPUs using
12310 * using the same vector, so select the one with
12311 * LPFC_CPU_FIRST_IRQ set.
12313 if ((match == LPFC_FIND_BY_EQ) &&
12314 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
12318 /* If matching by HDWQ, select the first CPU that matches */
12319 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
12327 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
12328 * @phba: pointer to lpfc hba data structure.
12329 * @cpu: CPU map index
12330 * @phys_id: CPU package physical id
12331 * @core_id: CPU core id
12334 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
12335 uint16_t phys_id, uint16_t core_id)
12337 struct lpfc_vector_map_info *cpup;
12340 for_each_present_cpu(idx) {
12341 cpup = &phba->sli4_hba.cpu_map[idx];
12342 /* Does the cpup match the one we are looking for */
12343 if ((cpup->phys_id == phys_id) &&
12344 (cpup->core_id == core_id) &&
12353 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
12354 * @phba: pointer to lpfc hba data structure.
12355 * @eqidx: index for eq and irq vector
12356 * @flag: flags to set for vector_map structure
12357 * @cpu: cpu used to index vector_map structure
12359 * The routine assigns eq info into vector_map structure
12362 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
12365 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
12366 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
12369 cpup->flag |= flag;
12371 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12372 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
12373 cpu, eqhdl->irq, cpup->eq, cpup->flag);
12377 * lpfc_cpu_map_array_init - Initialize cpu_map structure
12378 * @phba: pointer to lpfc hba data structure.
12380 * The routine initializes the cpu_map array structure
12383 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
12385 struct lpfc_vector_map_info *cpup;
12386 struct lpfc_eq_intr_info *eqi;
12389 for_each_possible_cpu(cpu) {
12390 cpup = &phba->sli4_hba.cpu_map[cpu];
12391 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
12392 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
12393 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
12394 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
12396 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
12397 INIT_LIST_HEAD(&eqi->list);
12403 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
12404 * @phba: pointer to lpfc hba data structure.
12406 * The routine initializes the hba_eq_hdl array structure
12409 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
12411 struct lpfc_hba_eq_hdl *eqhdl;
12414 for (i = 0; i < phba->cfg_irq_chann; i++) {
12415 eqhdl = lpfc_get_eq_hdl(i);
12416 eqhdl->irq = LPFC_IRQ_EMPTY;
12417 eqhdl->phba = phba;
12422 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
12423 * @phba: pointer to lpfc hba data structure.
12424 * @vectors: number of msix vectors allocated.
12426 * The routine will figure out the CPU affinity assignment for every
12427 * MSI-X vector allocated for the HBA.
12428 * In addition, the CPU to IO channel mapping will be calculated
12429 * and the phba->sli4_hba.cpu_map array will reflect this.
12432 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
12434 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
12435 int max_phys_id, min_phys_id;
12436 int max_core_id, min_core_id;
12437 struct lpfc_vector_map_info *cpup;
12438 struct lpfc_vector_map_info *new_cpup;
12439 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12440 struct lpfc_hdwq_stat *c_stat;
12444 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
12446 min_core_id = LPFC_VECTOR_MAP_EMPTY;
12448 /* Update CPU map with physical id and core id of each CPU */
12449 for_each_present_cpu(cpu) {
12450 cpup = &phba->sli4_hba.cpu_map[cpu];
12452 cpup->phys_id = topology_physical_package_id(cpu);
12453 cpup->core_id = topology_core_id(cpu);
12454 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
12455 cpup->flag |= LPFC_CPU_MAP_HYPER;
12457 /* No distinction between CPUs for other platforms */
12459 cpup->core_id = cpu;
12462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12463 "3328 CPU %d physid %d coreid %d flag x%x\n",
12464 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
12466 if (cpup->phys_id > max_phys_id)
12467 max_phys_id = cpup->phys_id;
12468 if (cpup->phys_id < min_phys_id)
12469 min_phys_id = cpup->phys_id;
12471 if (cpup->core_id > max_core_id)
12472 max_core_id = cpup->core_id;
12473 if (cpup->core_id < min_core_id)
12474 min_core_id = cpup->core_id;
12477 /* After looking at each irq vector assigned to this pcidev, its
12478 * possible to see that not ALL CPUs have been accounted for.
12479 * Next we will set any unassigned (unaffinitized) cpu map
12480 * entries to a IRQ on the same phys_id.
12482 first_cpu = cpumask_first(cpu_present_mask);
12483 start_cpu = first_cpu;
12485 for_each_present_cpu(cpu) {
12486 cpup = &phba->sli4_hba.cpu_map[cpu];
12488 /* Is this CPU entry unassigned */
12489 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12490 /* Mark CPU as IRQ not assigned by the kernel */
12491 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12493 /* If so, find a new_cpup that is on the SAME
12494 * phys_id as cpup. start_cpu will start where we
12495 * left off so all unassigned entries don't get assgined
12496 * the IRQ of the first entry.
12498 new_cpu = start_cpu;
12499 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12500 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12501 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12502 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
12503 (new_cpup->phys_id == cpup->phys_id))
12505 new_cpu = lpfc_next_present_cpu(new_cpu);
12507 /* At this point, we leave the CPU as unassigned */
12510 /* We found a matching phys_id, so copy the IRQ info */
12511 cpup->eq = new_cpup->eq;
12513 /* Bump start_cpu to the next slot to minmize the
12514 * chance of having multiple unassigned CPU entries
12515 * selecting the same IRQ.
12517 start_cpu = lpfc_next_present_cpu(new_cpu);
12519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12520 "3337 Set Affinity: CPU %d "
12521 "eq %d from peer cpu %d same "
12523 cpu, cpup->eq, new_cpu,
12528 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
12529 start_cpu = first_cpu;
12531 for_each_present_cpu(cpu) {
12532 cpup = &phba->sli4_hba.cpu_map[cpu];
12534 /* Is this entry unassigned */
12535 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12536 /* Mark it as IRQ not assigned by the kernel */
12537 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12539 /* If so, find a new_cpup thats on ANY phys_id
12540 * as the cpup. start_cpu will start where we
12541 * left off so all unassigned entries don't get
12542 * assigned the IRQ of the first entry.
12544 new_cpu = start_cpu;
12545 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12546 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12547 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12548 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
12550 new_cpu = lpfc_next_present_cpu(new_cpu);
12552 /* We should never leave an entry unassigned */
12553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12554 "3339 Set Affinity: CPU %d "
12555 "eq %d UNASSIGNED\n",
12556 cpup->hdwq, cpup->eq);
12559 /* We found an available entry, copy the IRQ info */
12560 cpup->eq = new_cpup->eq;
12562 /* Bump start_cpu to the next slot to minmize the
12563 * chance of having multiple unassigned CPU entries
12564 * selecting the same IRQ.
12566 start_cpu = lpfc_next_present_cpu(new_cpu);
12568 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12569 "3338 Set Affinity: CPU %d "
12570 "eq %d from peer cpu %d (%d/%d)\n",
12571 cpu, cpup->eq, new_cpu,
12572 new_cpup->phys_id, new_cpup->core_id);
12576 /* Assign hdwq indices that are unique across all cpus in the map
12577 * that are also FIRST_CPUs.
12580 for_each_present_cpu(cpu) {
12581 cpup = &phba->sli4_hba.cpu_map[cpu];
12583 /* Only FIRST IRQs get a hdwq index assignment. */
12584 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12587 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
12590 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12591 "3333 Set Affinity: CPU %d (phys %d core %d): "
12592 "hdwq %d eq %d flg x%x\n",
12593 cpu, cpup->phys_id, cpup->core_id,
12594 cpup->hdwq, cpup->eq, cpup->flag);
12596 /* Associate a hdwq with each cpu_map entry
12597 * This will be 1 to 1 - hdwq to cpu, unless there are less
12598 * hardware queues then CPUs. For that case we will just round-robin
12599 * the available hardware queues as they get assigned to CPUs.
12600 * The next_idx is the idx from the FIRST_CPU loop above to account
12601 * for irq_chann < hdwq. The idx is used for round-robin assignments
12602 * and needs to start at 0.
12607 for_each_present_cpu(cpu) {
12608 cpup = &phba->sli4_hba.cpu_map[cpu];
12610 /* FIRST cpus are already mapped. */
12611 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
12614 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
12615 * of the unassigned cpus to the next idx so that all
12616 * hdw queues are fully utilized.
12618 if (next_idx < phba->cfg_hdw_queue) {
12619 cpup->hdwq = next_idx;
12624 /* Not a First CPU and all hdw_queues are used. Reuse a
12625 * Hardware Queue for another CPU, so be smart about it
12626 * and pick one that has its IRQ/EQ mapped to the same phys_id
12627 * (CPU package) and core_id.
12629 new_cpu = start_cpu;
12630 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12631 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12632 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12633 new_cpup->phys_id == cpup->phys_id &&
12634 new_cpup->core_id == cpup->core_id) {
12637 new_cpu = lpfc_next_present_cpu(new_cpu);
12640 /* If we can't match both phys_id and core_id,
12641 * settle for just a phys_id match.
12643 new_cpu = start_cpu;
12644 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12645 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12646 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12647 new_cpup->phys_id == cpup->phys_id)
12649 new_cpu = lpfc_next_present_cpu(new_cpu);
12652 /* Otherwise just round robin on cfg_hdw_queue */
12653 cpup->hdwq = idx % phba->cfg_hdw_queue;
12657 /* We found an available entry, copy the IRQ info */
12658 start_cpu = lpfc_next_present_cpu(new_cpu);
12659 cpup->hdwq = new_cpup->hdwq;
12661 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12662 "3335 Set Affinity: CPU %d (phys %d core %d): "
12663 "hdwq %d eq %d flg x%x\n",
12664 cpu, cpup->phys_id, cpup->core_id,
12665 cpup->hdwq, cpup->eq, cpup->flag);
12669 * Initialize the cpu_map slots for not-present cpus in case
12670 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
12673 for_each_possible_cpu(cpu) {
12674 cpup = &phba->sli4_hba.cpu_map[cpu];
12675 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12676 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
12677 c_stat->hdwq_no = cpup->hdwq;
12679 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
12682 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
12683 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12684 c_stat->hdwq_no = cpup->hdwq;
12686 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12687 "3340 Set Affinity: not present "
12688 "CPU %d hdwq %d\n",
12692 /* The cpu_map array will be used later during initialization
12693 * when EQ / CQ / WQs are allocated and configured.
12699 * lpfc_cpuhp_get_eq
12701 * @phba: pointer to lpfc hba data structure.
12702 * @cpu: cpu going offline
12703 * @eqlist: eq list to append to
12706 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12707 struct list_head *eqlist)
12709 const struct cpumask *maskp;
12710 struct lpfc_queue *eq;
12711 struct cpumask *tmp;
12714 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12718 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12719 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12723 * if irq is not affinitized to the cpu going
12724 * then we don't need to poll the eq attached
12727 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
12729 /* get the cpus that are online and are affini-
12730 * tized to this irq vector. If the count is
12731 * more than 1 then cpuhp is not going to shut-
12732 * down this vector. Since this cpu has not
12733 * gone offline yet, we need >1.
12735 cpumask_and(tmp, maskp, cpu_online_mask);
12736 if (cpumask_weight(tmp) > 1)
12739 /* Now that we have an irq to shutdown, get the eq
12740 * mapped to this irq. Note: multiple hdwq's in
12741 * the software can share an eq, but eventually
12742 * only eq will be mapped to this vector
12744 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12745 list_add(&eq->_poll_list, eqlist);
12751 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12753 if (phba->sli_rev != LPFC_SLI_REV4)
12756 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12759 * unregistering the instance doesn't stop the polling
12760 * timer. Wait for the poll timer to retire.
12763 del_timer_sync(&phba->cpuhp_poll_timer);
12766 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12769 test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
12772 __lpfc_cpuhp_remove(phba);
12775 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12777 if (phba->sli_rev != LPFC_SLI_REV4)
12782 if (!list_empty(&phba->poll_list))
12783 mod_timer(&phba->cpuhp_poll_timer,
12784 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
12788 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12792 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12794 if (test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
12799 if (phba->sli_rev != LPFC_SLI_REV4) {
12804 /* proceed with the hotplug */
12809 * lpfc_irq_set_aff - set IRQ affinity
12810 * @eqhdl: EQ handle
12811 * @cpu: cpu to set affinity
12815 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12817 cpumask_clear(&eqhdl->aff_mask);
12818 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12819 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12820 irq_set_affinity(eqhdl->irq, &eqhdl->aff_mask);
12824 * lpfc_irq_clear_aff - clear IRQ affinity
12825 * @eqhdl: EQ handle
12829 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12831 cpumask_clear(&eqhdl->aff_mask);
12832 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12836 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12837 * @phba: pointer to HBA context object.
12838 * @cpu: cpu going offline/online
12839 * @offline: true, cpu is going offline. false, cpu is coming online.
12841 * If cpu is going offline, we'll try our best effort to find the next
12842 * online cpu on the phba's original_mask and migrate all offlining IRQ
12845 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
12847 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
12848 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12852 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12854 struct lpfc_vector_map_info *cpup;
12855 struct cpumask *aff_mask;
12856 unsigned int cpu_select, cpu_next, idx;
12857 const struct cpumask *orig_mask;
12859 if (phba->irq_chann_mode == NORMAL_MODE)
12862 orig_mask = &phba->sli4_hba.irq_aff_mask;
12864 if (!cpumask_test_cpu(cpu, orig_mask))
12867 cpup = &phba->sli4_hba.cpu_map[cpu];
12869 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12873 /* Find next online CPU on original mask */
12874 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12875 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
12877 /* Found a valid CPU */
12878 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12879 /* Go through each eqhdl and ensure offlining
12880 * cpu aff_mask is migrated
12882 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12883 aff_mask = lpfc_get_aff_mask(idx);
12885 /* Migrate affinity */
12886 if (cpumask_test_cpu(cpu, aff_mask))
12887 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12891 /* Rely on irqbalance if no online CPUs left on NUMA */
12892 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12893 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12896 /* Migrate affinity back to this CPU */
12897 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12901 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12903 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12904 struct lpfc_queue *eq, *next;
12909 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12913 if (__lpfc_cpuhp_checks(phba, &retval))
12916 lpfc_irq_rebalance(phba, cpu, true);
12918 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12922 /* start polling on these eq's */
12923 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12924 list_del_init(&eq->_poll_list);
12925 lpfc_sli4_start_polling(eq);
12931 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
12933 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12934 struct lpfc_queue *eq, *next;
12939 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12943 if (__lpfc_cpuhp_checks(phba, &retval))
12946 lpfc_irq_rebalance(phba, cpu, false);
12948 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
12949 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
12951 lpfc_sli4_stop_polling(eq);
12958 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
12959 * @phba: pointer to lpfc hba data structure.
12961 * This routine is invoked to enable the MSI-X interrupt vectors to device
12962 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
12963 * to cpus on the system.
12965 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
12966 * the number of cpus on the same numa node as this adapter. The vectors are
12967 * allocated without requesting OS affinity mapping. A vector will be
12968 * allocated and assigned to each online and offline cpu. If the cpu is
12969 * online, then affinity will be set to that cpu. If the cpu is offline, then
12970 * affinity will be set to the nearest peer cpu within the numa node that is
12971 * online. If there are no online cpus within the numa node, affinity is not
12972 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
12973 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
12976 * If numa mode is not enabled and there is more than 1 vector allocated, then
12977 * the driver relies on the managed irq interface where the OS assigns vector to
12978 * cpu affinity. The driver will then use that affinity mapping to setup its
12979 * cpu mapping table.
12983 * other values - error
12986 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
12988 int vectors, rc, index;
12990 const struct cpumask *aff_mask = NULL;
12991 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
12992 struct lpfc_vector_map_info *cpup;
12993 struct lpfc_hba_eq_hdl *eqhdl;
12994 const struct cpumask *maskp;
12995 unsigned int flags = PCI_IRQ_MSIX;
12997 /* Set up MSI-X multi-message vectors */
12998 vectors = phba->cfg_irq_chann;
13000 if (phba->irq_chann_mode != NORMAL_MODE)
13001 aff_mask = &phba->sli4_hba.irq_aff_mask;
13004 cpu_cnt = cpumask_weight(aff_mask);
13005 vectors = min(phba->cfg_irq_chann, cpu_cnt);
13007 /* cpu: iterates over aff_mask including offline or online
13008 * cpu_select: iterates over online aff_mask to set affinity
13010 cpu = cpumask_first(aff_mask);
13011 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
13013 flags |= PCI_IRQ_AFFINITY;
13016 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
13018 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13019 "0484 PCI enable MSI-X failed (%d)\n", rc);
13024 /* Assign MSI-X vectors to interrupt handlers */
13025 for (index = 0; index < vectors; index++) {
13026 eqhdl = lpfc_get_eq_hdl(index);
13027 name = eqhdl->handler_name;
13028 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
13029 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
13030 LPFC_DRIVER_HANDLER_NAME"%d", index);
13032 eqhdl->idx = index;
13033 rc = pci_irq_vector(phba->pcidev, index);
13035 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13036 "0489 MSI-X fast-path (%d) "
13037 "pci_irq_vec failed (%d)\n", index, rc);
13042 rc = request_threaded_irq(eqhdl->irq,
13043 &lpfc_sli4_hba_intr_handler,
13044 &lpfc_sli4_hba_intr_handler_th,
13047 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13048 "0486 MSI-X fast-path (%d) "
13049 "request_irq failed (%d)\n", index, rc);
13054 /* If found a neighboring online cpu, set affinity */
13055 if (cpu_select < nr_cpu_ids)
13056 lpfc_irq_set_aff(eqhdl, cpu_select);
13058 /* Assign EQ to cpu_map */
13059 lpfc_assign_eq_map_info(phba, index,
13060 LPFC_CPU_FIRST_IRQ,
13063 /* Iterate to next offline or online cpu in aff_mask */
13064 cpu = cpumask_next(cpu, aff_mask);
13066 /* Find next online cpu in aff_mask to set affinity */
13067 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
13068 } else if (vectors == 1) {
13069 cpu = cpumask_first(cpu_present_mask);
13070 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
13073 maskp = pci_irq_get_affinity(phba->pcidev, index);
13075 /* Loop through all CPUs associated with vector index */
13076 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
13077 cpup = &phba->sli4_hba.cpu_map[cpu];
13079 /* If this is the first CPU thats assigned to
13080 * this vector, set LPFC_CPU_FIRST_IRQ.
13082 * With certain platforms its possible that irq
13083 * vectors are affinitized to all the cpu's.
13084 * This can result in each cpu_map.eq to be set
13085 * to the last vector, resulting in overwrite
13086 * of all the previous cpu_map.eq. Ensure that
13087 * each vector receives a place in cpu_map.
13088 * Later call to lpfc_cpu_affinity_check will
13089 * ensure we are nicely balanced out.
13091 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
13093 lpfc_assign_eq_map_info(phba, index,
13094 LPFC_CPU_FIRST_IRQ,
13101 if (vectors != phba->cfg_irq_chann) {
13102 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13103 "3238 Reducing IO channels to match number of "
13104 "MSI-X vectors, requested %d got %d\n",
13105 phba->cfg_irq_chann, vectors);
13106 if (phba->cfg_irq_chann > vectors)
13107 phba->cfg_irq_chann = vectors;
13113 /* free the irq already requested */
13114 for (--index; index >= 0; index--) {
13115 eqhdl = lpfc_get_eq_hdl(index);
13116 lpfc_irq_clear_aff(eqhdl);
13117 free_irq(eqhdl->irq, eqhdl);
13120 /* Unconfigure MSI-X capability structure */
13121 pci_free_irq_vectors(phba->pcidev);
13128 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
13129 * @phba: pointer to lpfc hba data structure.
13131 * This routine is invoked to enable the MSI interrupt mode to device with
13132 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
13133 * called to enable the MSI vector. The device driver is responsible for
13134 * calling the request_irq() to register MSI vector with a interrupt the
13135 * handler, which is done in this function.
13139 * other values - error
13142 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
13146 struct lpfc_hba_eq_hdl *eqhdl;
13148 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
13149 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
13151 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13152 "0487 PCI enable MSI mode success.\n");
13154 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13155 "0488 PCI enable MSI mode failed (%d)\n", rc);
13156 return rc ? rc : -1;
13159 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13160 0, LPFC_DRIVER_NAME, phba);
13162 pci_free_irq_vectors(phba->pcidev);
13163 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13164 "0490 MSI request_irq failed (%d)\n", rc);
13168 eqhdl = lpfc_get_eq_hdl(0);
13169 rc = pci_irq_vector(phba->pcidev, 0);
13171 pci_free_irq_vectors(phba->pcidev);
13172 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13173 "0496 MSI pci_irq_vec failed (%d)\n", rc);
13178 cpu = cpumask_first(cpu_present_mask);
13179 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
13181 for (index = 0; index < phba->cfg_irq_chann; index++) {
13182 eqhdl = lpfc_get_eq_hdl(index);
13183 eqhdl->idx = index;
13190 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
13191 * @phba: pointer to lpfc hba data structure.
13192 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
13194 * This routine is invoked to enable device interrupt and associate driver's
13195 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
13196 * interface spec. Depends on the interrupt mode configured to the driver,
13197 * the driver will try to fallback from the configured interrupt mode to an
13198 * interrupt mode which is supported by the platform, kernel, and device in
13200 * MSI-X -> MSI -> IRQ.
13203 * Interrupt mode (2, 1, 0) - successful
13204 * LPFC_INTR_ERROR - error
13207 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
13209 uint32_t intr_mode = LPFC_INTR_ERROR;
13212 if (cfg_mode == 2) {
13213 /* Preparation before conf_msi mbox cmd */
13216 /* Now, try to enable MSI-X interrupt mode */
13217 retval = lpfc_sli4_enable_msix(phba);
13219 /* Indicate initialization to MSI-X mode */
13220 phba->intr_type = MSIX;
13226 /* Fallback to MSI if MSI-X initialization failed */
13227 if (cfg_mode >= 1 && phba->intr_type == NONE) {
13228 retval = lpfc_sli4_enable_msi(phba);
13230 /* Indicate initialization to MSI mode */
13231 phba->intr_type = MSI;
13236 /* Fallback to INTx if both MSI-X/MSI initalization failed */
13237 if (phba->intr_type == NONE) {
13238 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13239 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
13241 struct lpfc_hba_eq_hdl *eqhdl;
13244 /* Indicate initialization to INTx mode */
13245 phba->intr_type = INTx;
13248 eqhdl = lpfc_get_eq_hdl(0);
13249 retval = pci_irq_vector(phba->pcidev, 0);
13251 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13252 "0502 INTR pci_irq_vec failed (%d)\n",
13254 return LPFC_INTR_ERROR;
13256 eqhdl->irq = retval;
13258 cpu = cpumask_first(cpu_present_mask);
13259 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
13261 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
13262 eqhdl = lpfc_get_eq_hdl(idx);
13271 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
13272 * @phba: pointer to lpfc hba data structure.
13274 * This routine is invoked to disable device interrupt and disassociate
13275 * the driver's interrupt handler(s) from interrupt vector(s) to device
13276 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
13277 * will release the interrupt vector(s) for the message signaled interrupt.
13280 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
13282 /* Disable the currently initialized interrupt mode */
13283 if (phba->intr_type == MSIX) {
13285 struct lpfc_hba_eq_hdl *eqhdl;
13287 /* Free up MSI-X multi-message vectors */
13288 for (index = 0; index < phba->cfg_irq_chann; index++) {
13289 eqhdl = lpfc_get_eq_hdl(index);
13290 lpfc_irq_clear_aff(eqhdl);
13291 free_irq(eqhdl->irq, eqhdl);
13294 free_irq(phba->pcidev->irq, phba);
13297 pci_free_irq_vectors(phba->pcidev);
13299 /* Reset interrupt management states */
13300 phba->intr_type = NONE;
13301 phba->sli.slistat.sli_intr = 0;
13305 * lpfc_unset_hba - Unset SLI3 hba device initialization
13306 * @phba: pointer to lpfc hba data structure.
13308 * This routine is invoked to unset the HBA device initialization steps to
13309 * a device with SLI-3 interface spec.
13312 lpfc_unset_hba(struct lpfc_hba *phba)
13314 set_bit(FC_UNLOADING, &phba->pport->load_flag);
13316 kfree(phba->vpi_bmask);
13317 kfree(phba->vpi_ids);
13319 lpfc_stop_hba_timers(phba);
13321 phba->pport->work_port_events = 0;
13323 lpfc_sli_hba_down(phba);
13325 lpfc_sli_brdrestart(phba);
13327 lpfc_sli_disable_intr(phba);
13333 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
13334 * @phba: Pointer to HBA context object.
13336 * This function is called in the SLI4 code path to wait for completion
13337 * of device's XRIs exchange busy. It will check the XRI exchange busy
13338 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
13339 * that, it will check the XRI exchange busy on outstanding FCP and ELS
13340 * I/Os every 30 seconds, log error message, and wait forever. Only when
13341 * all XRI exchange busy complete, the driver unload shall proceed with
13342 * invoking the function reset ioctl mailbox command to the CNA and the
13343 * the rest of the driver unload resource release.
13346 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
13348 struct lpfc_sli4_hdw_queue *qp;
13351 int io_xri_cmpl = 1;
13352 int nvmet_xri_cmpl = 1;
13353 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13355 /* Driver just aborted IOs during the hba_unset process. Pause
13356 * here to give the HBA time to complete the IO and get entries
13357 * into the abts lists.
13359 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
13361 /* Wait for NVME pending IO to flush back to transport. */
13362 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13363 lpfc_nvme_wait_for_io_drain(phba);
13366 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13367 qp = &phba->sli4_hba.hdwq[idx];
13368 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
13369 if (!io_xri_cmpl) /* if list is NOT empty */
13375 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13377 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13380 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
13381 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
13382 if (!nvmet_xri_cmpl)
13383 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13384 "6424 NVMET XRI exchange busy "
13385 "wait time: %d seconds.\n",
13388 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13389 "6100 IO XRI exchange busy "
13390 "wait time: %d seconds.\n",
13393 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13394 "2878 ELS XRI exchange busy "
13395 "wait time: %d seconds.\n",
13397 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
13398 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
13400 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
13401 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
13405 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13406 qp = &phba->sli4_hba.hdwq[idx];
13407 io_xri_cmpl = list_empty(
13408 &qp->lpfc_abts_io_buf_list);
13409 if (!io_xri_cmpl) /* if list is NOT empty */
13415 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13416 nvmet_xri_cmpl = list_empty(
13417 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13420 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13426 * lpfc_sli4_hba_unset - Unset the fcoe hba
13427 * @phba: Pointer to HBA context object.
13429 * This function is called in the SLI4 code path to reset the HBA's FCoE
13430 * function. The caller is not required to hold any lock. This routine
13431 * issues PCI function reset mailbox command to reset the FCoE function.
13432 * At the end of the function, it calls lpfc_hba_down_post function to
13433 * free any pending commands.
13436 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
13439 LPFC_MBOXQ_t *mboxq;
13440 struct pci_dev *pdev = phba->pcidev;
13442 lpfc_stop_hba_timers(phba);
13443 hrtimer_cancel(&phba->cmf_stats_timer);
13444 hrtimer_cancel(&phba->cmf_timer);
13447 phba->sli4_hba.intr_enable = 0;
13450 * Gracefully wait out the potential current outstanding asynchronous
13454 /* First, block any pending async mailbox command from posted */
13455 spin_lock_irq(&phba->hbalock);
13456 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13457 spin_unlock_irq(&phba->hbalock);
13458 /* Now, trying to wait it out if we can */
13459 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13461 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
13464 /* Forcefully release the outstanding mailbox command if timed out */
13465 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13466 spin_lock_irq(&phba->hbalock);
13467 mboxq = phba->sli.mbox_active;
13468 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
13469 __lpfc_mbox_cmpl_put(phba, mboxq);
13470 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13471 phba->sli.mbox_active = NULL;
13472 spin_unlock_irq(&phba->hbalock);
13475 /* Abort all iocbs associated with the hba */
13476 lpfc_sli_hba_iocb_abort(phba);
13478 if (!pci_channel_offline(phba->pcidev))
13479 /* Wait for completion of device XRI exchange busy */
13480 lpfc_sli4_xri_exchange_busy_wait(phba);
13482 /* per-phba callback de-registration for hotplug event */
13484 lpfc_cpuhp_remove(phba);
13486 /* Disable PCI subsystem interrupt */
13487 lpfc_sli4_disable_intr(phba);
13489 /* Disable SR-IOV if enabled */
13490 if (phba->cfg_sriov_nr_virtfn)
13491 pci_disable_sriov(pdev);
13493 /* Stop kthread signal shall trigger work_done one more time */
13494 kthread_stop(phba->worker_thread);
13496 /* Disable FW logging to host memory */
13497 lpfc_ras_stop_fwlog(phba);
13499 /* Reset SLI4 HBA FCoE function */
13500 lpfc_pci_function_reset(phba);
13502 /* release all queue allocated resources. */
13503 lpfc_sli4_queue_destroy(phba);
13505 /* Free RAS DMA memory */
13506 if (phba->ras_fwlog.ras_enabled)
13507 lpfc_sli4_ras_dma_free(phba);
13509 /* Stop the SLI4 device port */
13511 phba->pport->work_port_events = 0;
13515 lpfc_cgn_crc32(uint32_t crc, u8 byte)
13520 for (bit = 0; bit < 8; bit++) {
13521 msb = (crc >> 31) & 1;
13524 if (msb ^ (byte & 1)) {
13525 crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
13534 lpfc_cgn_reverse_bits(uint32_t wd)
13536 uint32_t result = 0;
13539 for (i = 0; i < 32; i++) {
13541 result |= (1 & (wd >> i));
13547 * The routine corresponds with the algorithm the HBA firmware
13548 * uses to validate the data integrity.
13551 lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
13555 uint8_t *data = (uint8_t *)ptr;
13557 for (i = 0; i < byteLen; ++i)
13558 crc = lpfc_cgn_crc32(crc, data[i]);
13560 result = ~lpfc_cgn_reverse_bits(crc);
13565 lpfc_init_congestion_buf(struct lpfc_hba *phba)
13567 struct lpfc_cgn_info *cp;
13571 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13572 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
13576 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13578 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
13579 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
13580 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
13581 atomic_set(&phba->cgn_sync_warn_cnt, 0);
13583 atomic_set(&phba->cgn_driver_evt_cnt, 0);
13584 atomic_set(&phba->cgn_latency_evt_cnt, 0);
13585 atomic64_set(&phba->cgn_latency_evt, 0);
13586 phba->cgn_evt_minute = 0;
13588 memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat));
13589 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
13590 cp->cgn_info_version = LPFC_CGN_INFO_V4;
13592 /* cgn parameters */
13593 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
13594 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
13595 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
13596 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
13598 lpfc_cgn_update_tstamp(phba, &cp->base_time);
13600 /* Fill in default LUN qdepth */
13602 size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
13603 cp->cgn_lunq = cpu_to_le16(size);
13606 /* last used Index initialized to 0xff already */
13608 cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13609 cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13610 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13611 cp->cgn_info_crc = cpu_to_le32(crc);
13613 phba->cgn_evt_timestamp = jiffies +
13614 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
13618 lpfc_init_congestion_stat(struct lpfc_hba *phba)
13620 struct lpfc_cgn_info *cp;
13623 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13624 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
13629 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13630 memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));
13632 lpfc_cgn_update_tstamp(phba, &cp->stat_start);
13633 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13634 cp->cgn_info_crc = cpu_to_le32(crc);
13638 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
13639 * @phba: Pointer to hba context object.
13640 * @reg: flag to determine register or unregister.
13643 __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
13645 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
13646 union lpfc_sli4_cfg_shdr *shdr;
13647 uint32_t shdr_status, shdr_add_status;
13648 LPFC_MBOXQ_t *mboxq;
13654 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13656 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13657 "2641 REG_CONGESTION_BUF mbox allocation fail: "
13658 "HBA state x%x reg %d\n",
13659 phba->pport->port_state, reg);
13663 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
13664 sizeof(struct lpfc_sli4_cfg_mhdr));
13665 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13666 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
13667 LPFC_SLI4_MBX_EMBED);
13668 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
13669 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
13671 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
13673 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
13674 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
13675 reg_congestion_buf->addr_lo =
13676 putPaddrLow(phba->cgn_i->phys);
13677 reg_congestion_buf->addr_hi =
13678 putPaddrHigh(phba->cgn_i->phys);
13680 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13681 shdr = (union lpfc_sli4_cfg_shdr *)
13682 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
13683 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13684 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13686 mempool_free(mboxq, phba->mbox_mem_pool);
13687 if (shdr_status || shdr_add_status || rc) {
13688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13689 "2642 REG_CONGESTION_BUF mailbox "
13690 "failed with status x%x add_status x%x,"
13691 " mbx status x%x reg %d\n",
13692 shdr_status, shdr_add_status, rc, reg);
13699 lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
13701 lpfc_cmf_stop(phba);
13702 return __lpfc_reg_congestion_buf(phba, 0);
13706 lpfc_reg_congestion_buf(struct lpfc_hba *phba)
13708 return __lpfc_reg_congestion_buf(phba, 1);
13712 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
13713 * @phba: Pointer to HBA context object.
13714 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
13716 * This function is called in the SLI4 code path to read the port's
13717 * sli4 capabilities.
13719 * This function may be be called from any context that can block-wait
13720 * for the completion. The expectation is that this routine is called
13721 * typically from probe_one or from the online routine.
13724 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
13727 struct lpfc_mqe *mqe = &mboxq->u.mqe;
13728 struct lpfc_pc_sli4_params *sli4_params;
13731 bool exp_wqcq_pages = true;
13732 struct lpfc_sli4_parameters *mbx_sli4_parameters;
13735 * By default, the driver assumes the SLI4 port requires RPI
13736 * header postings. The SLI4_PARAM response will correct this
13739 phba->sli4_hba.rpi_hdrs_in_use = 1;
13741 /* Read the port's SLI4 Config Parameters */
13742 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
13743 sizeof(struct lpfc_sli4_cfg_mhdr));
13744 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13745 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
13746 length, LPFC_SLI4_MBX_EMBED);
13747 if (!phba->sli4_hba.intr_enable)
13748 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13750 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
13751 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
13755 sli4_params = &phba->sli4_hba.pc_sli4_params;
13756 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
13757 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
13758 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
13759 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
13760 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
13761 mbx_sli4_parameters);
13762 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
13763 mbx_sli4_parameters);
13764 if (bf_get(cfg_phwq, mbx_sli4_parameters))
13765 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
13767 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
13768 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
13769 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
13770 mbx_sli4_parameters);
13771 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
13772 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
13773 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
13774 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
13775 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
13776 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
13777 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
13778 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
13779 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
13780 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
13781 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
13782 mbx_sli4_parameters);
13783 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
13784 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
13785 mbx_sli4_parameters);
13786 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
13787 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
13788 sli4_params->mi_cap = bf_get(cfg_mi_ver, mbx_sli4_parameters);
13790 /* Check for Extended Pre-Registered SGL support */
13791 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
13793 /* Check for firmware nvme support */
13794 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13795 bf_get(cfg_xib, mbx_sli4_parameters));
13798 /* Save this to indicate the Firmware supports NVME */
13799 sli4_params->nvme = 1;
13801 /* Firmware NVME support, check driver FC4 NVME support */
13802 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13803 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13804 "6133 Disabling NVME support: "
13805 "FC4 type not supported: x%x\n",
13806 phba->cfg_enable_fc4_type);
13810 /* No firmware NVME support, check driver FC4 NVME support */
13811 sli4_params->nvme = 0;
13812 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13814 "6101 Disabling NVME support: Not "
13815 "supported by firmware (%d %d) x%x\n",
13816 bf_get(cfg_nvme, mbx_sli4_parameters),
13817 bf_get(cfg_xib, mbx_sli4_parameters),
13818 phba->cfg_enable_fc4_type);
13820 phba->nvmet_support = 0;
13821 phba->cfg_nvmet_mrq = 0;
13822 phba->cfg_nvme_seg_cnt = 0;
13824 /* If no FC4 type support, move to just SCSI support */
13825 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13827 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13831 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
13832 * accommodate 512K and 1M IOs in a single nvme buf.
13834 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13835 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
13837 /* Enable embedded Payload BDE if support is indicated */
13838 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13839 phba->cfg_enable_pbde = 1;
13841 phba->cfg_enable_pbde = 0;
13844 * To support Suppress Response feature we must satisfy 3 conditions.
13845 * lpfc_suppress_rsp module parameter must be set (default).
13846 * In SLI4-Parameters Descriptor:
13847 * Extended Inline Buffers (XIB) must be supported.
13848 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13849 * (double negative).
13851 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13852 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
13853 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
13855 phba->cfg_suppress_rsp = 0;
13857 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13858 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13860 /* Make sure that sge_supp_len can be handled by the driver */
13861 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13862 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13864 rc = dma_set_max_seg_size(&phba->pcidev->dev, sli4_params->sge_supp_len);
13865 if (unlikely(rc)) {
13866 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13867 "6400 Can't set dma maximum segment size\n");
13872 * Check whether the adapter supports an embedded copy of the
13873 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13874 * to use this option, 128-byte WQEs must be used.
13876 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13877 phba->fcp_embed_io = 1;
13879 phba->fcp_embed_io = 0;
13881 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13882 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
13883 bf_get(cfg_xib, mbx_sli4_parameters),
13884 phba->cfg_enable_pbde,
13885 phba->fcp_embed_io, sli4_params->nvme,
13886 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
13888 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
13889 LPFC_SLI_INTF_IF_TYPE_2) &&
13890 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
13891 LPFC_SLI_INTF_FAMILY_LNCR_A0))
13892 exp_wqcq_pages = false;
13894 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
13895 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
13897 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
13898 phba->enab_exp_wqcq_pages = 1;
13900 phba->enab_exp_wqcq_pages = 0;
13902 * Check if the SLI port supports MDS Diagnostics
13904 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
13905 phba->mds_diags_support = 1;
13907 phba->mds_diags_support = 0;
13910 * Check if the SLI port supports NSLER
13912 if (bf_get(cfg_nsler, mbx_sli4_parameters))
13921 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
13922 * @pdev: pointer to PCI device
13923 * @pid: pointer to PCI device identifier
13925 * This routine is to be called to attach a device with SLI-3 interface spec
13926 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13927 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13928 * information of the device and driver to see if the driver state that it can
13929 * support this kind of device. If the match is successful, the driver core
13930 * invokes this routine. If this routine determines it can claim the HBA, it
13931 * does all the initialization that it needs to do to handle the HBA properly.
13934 * 0 - driver can claim the device
13935 * negative value - driver can not claim the device
13938 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
13940 struct lpfc_hba *phba;
13941 struct lpfc_vport *vport = NULL;
13942 struct Scsi_Host *shost = NULL;
13944 uint32_t cfg_mode, intr_mode;
13946 /* Allocate memory for HBA structure */
13947 phba = lpfc_hba_alloc(pdev);
13951 /* Perform generic PCI device enabling operation */
13952 error = lpfc_enable_pci_dev(phba);
13954 goto out_free_phba;
13956 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
13957 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
13959 goto out_disable_pci_dev;
13961 /* Set up SLI-3 specific device PCI memory space */
13962 error = lpfc_sli_pci_mem_setup(phba);
13964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13965 "1402 Failed to set up pci memory space.\n");
13966 goto out_disable_pci_dev;
13969 /* Set up SLI-3 specific device driver resources */
13970 error = lpfc_sli_driver_resource_setup(phba);
13972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13973 "1404 Failed to set up driver resource.\n");
13974 goto out_unset_pci_mem_s3;
13977 /* Initialize and populate the iocb list per host */
13979 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
13981 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13982 "1405 Failed to initialize iocb list.\n");
13983 goto out_unset_driver_resource_s3;
13986 /* Set up common device driver resources */
13987 error = lpfc_setup_driver_resource_phase2(phba);
13989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13990 "1406 Failed to set up driver resource.\n");
13991 goto out_free_iocb_list;
13994 /* Get the default values for Model Name and Description */
13995 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13997 /* Create SCSI host to the physical port */
13998 error = lpfc_create_shost(phba);
14000 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14001 "1407 Failed to create scsi host.\n");
14002 goto out_unset_driver_resource;
14005 /* Configure sysfs attributes */
14006 vport = phba->pport;
14007 error = lpfc_alloc_sysfs_attr(vport);
14009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14010 "1476 Failed to allocate sysfs attr\n");
14011 goto out_destroy_shost;
14014 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14015 /* Now, trying to enable interrupt and bring up the device */
14016 cfg_mode = phba->cfg_use_msi;
14018 /* Put device to a known state before enabling interrupt */
14019 lpfc_stop_port(phba);
14020 /* Configure and enable interrupt */
14021 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
14022 if (intr_mode == LPFC_INTR_ERROR) {
14023 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14024 "0431 Failed to enable interrupt.\n");
14026 goto out_free_sysfs_attr;
14028 /* SLI-3 HBA setup */
14029 if (lpfc_sli_hba_setup(phba)) {
14030 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14031 "1477 Failed to set up hba\n");
14033 goto out_remove_device;
14036 /* Wait 50ms for the interrupts of previous mailbox commands */
14038 /* Check active interrupts on message signaled interrupts */
14039 if (intr_mode == 0 ||
14040 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
14041 /* Log the current active interrupt mode */
14042 phba->intr_mode = intr_mode;
14043 lpfc_log_intr_mode(phba, intr_mode);
14046 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14047 "0447 Configure interrupt mode (%d) "
14048 "failed active interrupt test.\n",
14050 /* Disable the current interrupt mode */
14051 lpfc_sli_disable_intr(phba);
14052 /* Try next level of interrupt mode */
14053 cfg_mode = --intr_mode;
14057 /* Perform post initialization setup */
14058 lpfc_post_init_setup(phba);
14060 /* Check if there are static vports to be created. */
14061 lpfc_create_static_vport(phba);
14066 lpfc_unset_hba(phba);
14067 out_free_sysfs_attr:
14068 lpfc_free_sysfs_attr(vport);
14070 lpfc_destroy_shost(phba);
14071 out_unset_driver_resource:
14072 lpfc_unset_driver_resource_phase2(phba);
14073 out_free_iocb_list:
14074 lpfc_free_iocb_list(phba);
14075 out_unset_driver_resource_s3:
14076 lpfc_sli_driver_resource_unset(phba);
14077 out_unset_pci_mem_s3:
14078 lpfc_sli_pci_mem_unset(phba);
14079 out_disable_pci_dev:
14080 lpfc_disable_pci_dev(phba);
14082 scsi_host_put(shost);
14084 lpfc_hba_free(phba);
14089 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
14090 * @pdev: pointer to PCI device
14092 * This routine is to be called to disattach a device with SLI-3 interface
14093 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
14094 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14095 * device to be removed from the PCI subsystem properly.
14098 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
14100 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14102 struct lpfc_vport **vports;
14103 struct lpfc_hba *phba = vport->phba;
14106 set_bit(FC_UNLOADING, &vport->load_flag);
14108 lpfc_free_sysfs_attr(vport);
14110 /* Release all the vports against this physical port */
14111 vports = lpfc_create_vport_work_array(phba);
14112 if (vports != NULL)
14113 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14114 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14116 fc_vport_terminate(vports[i]->fc_vport);
14118 lpfc_destroy_vport_work_array(phba, vports);
14120 /* Remove FC host with the physical port */
14121 fc_remove_host(shost);
14122 scsi_remove_host(shost);
14124 /* Clean up all nodes, mailboxes and IOs. */
14125 lpfc_cleanup(vport);
14128 * Bring down the SLI Layer. This step disable all interrupts,
14129 * clears the rings, discards all mailbox commands, and resets
14133 /* HBA interrupt will be disabled after this call */
14134 lpfc_sli_hba_down(phba);
14135 /* Stop kthread signal shall trigger work_done one more time */
14136 kthread_stop(phba->worker_thread);
14137 /* Final cleanup of txcmplq and reset the HBA */
14138 lpfc_sli_brdrestart(phba);
14140 kfree(phba->vpi_bmask);
14141 kfree(phba->vpi_ids);
14143 lpfc_stop_hba_timers(phba);
14144 spin_lock_irq(&phba->port_list_lock);
14145 list_del_init(&vport->listentry);
14146 spin_unlock_irq(&phba->port_list_lock);
14148 lpfc_debugfs_terminate(vport);
14150 /* Disable SR-IOV if enabled */
14151 if (phba->cfg_sriov_nr_virtfn)
14152 pci_disable_sriov(pdev);
14154 /* Disable interrupt */
14155 lpfc_sli_disable_intr(phba);
14157 scsi_host_put(shost);
14160 * Call scsi_free before mem_free since scsi bufs are released to their
14161 * corresponding pools here.
14163 lpfc_scsi_free(phba);
14164 lpfc_free_iocb_list(phba);
14166 lpfc_mem_free_all(phba);
14168 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
14169 phba->hbqslimp.virt, phba->hbqslimp.phys);
14171 /* Free resources associated with SLI2 interface */
14172 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
14173 phba->slim2p.virt, phba->slim2p.phys);
14175 /* unmap adapter SLIM and Control Registers */
14176 iounmap(phba->ctrl_regs_memmap_p);
14177 iounmap(phba->slim_memmap_p);
14179 lpfc_hba_free(phba);
14181 pci_release_mem_regions(pdev);
14182 pci_disable_device(pdev);
14186 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
14187 * @dev_d: pointer to device
14189 * This routine is to be called from the kernel's PCI subsystem to support
14190 * system Power Management (PM) to device with SLI-3 interface spec. When
14191 * PM invokes this method, it quiesces the device by stopping the driver's
14192 * worker thread for the device, turning off device's interrupt and DMA,
14193 * and bring the device offline. Note that as the driver implements the
14194 * minimum PM requirements to a power-aware driver's PM support for the
14195 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14196 * to the suspend() method call will be treated as SUSPEND and the driver will
14197 * fully reinitialize its device during resume() method call, the driver will
14198 * set device to PCI_D3hot state in PCI config space instead of setting it
14199 * according to the @msg provided by the PM.
14202 * 0 - driver suspended the device
14205 static int __maybe_unused
14206 lpfc_pci_suspend_one_s3(struct device *dev_d)
14208 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14209 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14211 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14212 "0473 PCI device Power Management suspend.\n");
14214 /* Bring down the device */
14215 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14216 lpfc_offline(phba);
14217 kthread_stop(phba->worker_thread);
14219 /* Disable interrupt from device */
14220 lpfc_sli_disable_intr(phba);
14226 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
14227 * @dev_d: pointer to device
14229 * This routine is to be called from the kernel's PCI subsystem to support
14230 * system Power Management (PM) to device with SLI-3 interface spec. When PM
14231 * invokes this method, it restores the device's PCI config space state and
14232 * fully reinitializes the device and brings it online. Note that as the
14233 * driver implements the minimum PM requirements to a power-aware driver's
14234 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
14235 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
14236 * driver will fully reinitialize its device during resume() method call,
14237 * the device will be set to PCI_D0 directly in PCI config space before
14238 * restoring the state.
14241 * 0 - driver suspended the device
14244 static int __maybe_unused
14245 lpfc_pci_resume_one_s3(struct device *dev_d)
14247 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14248 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14249 uint32_t intr_mode;
14252 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14253 "0452 PCI device Power Management resume.\n");
14255 /* Startup the kernel thread for this host adapter. */
14256 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14257 "lpfc_worker_%d", phba->brd_no);
14258 if (IS_ERR(phba->worker_thread)) {
14259 error = PTR_ERR(phba->worker_thread);
14260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14261 "0434 PM resume failed to start worker "
14262 "thread: error=x%x.\n", error);
14266 /* Init cpu_map array */
14267 lpfc_cpu_map_array_init(phba);
14268 /* Init hba_eq_hdl array */
14269 lpfc_hba_eq_hdl_array_init(phba);
14270 /* Configure and enable interrupt */
14271 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14272 if (intr_mode == LPFC_INTR_ERROR) {
14273 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14274 "0430 PM resume Failed to enable interrupt\n");
14277 phba->intr_mode = intr_mode;
14279 /* Restart HBA and bring it online */
14280 lpfc_sli_brdrestart(phba);
14283 /* Log the current active interrupt mode */
14284 lpfc_log_intr_mode(phba, phba->intr_mode);
14290 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
14291 * @phba: pointer to lpfc hba data structure.
14293 * This routine is called to prepare the SLI3 device for PCI slot recover. It
14294 * aborts all the outstanding SCSI I/Os to the pci device.
14297 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
14299 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14300 "2723 PCI channel I/O abort preparing for recovery\n");
14303 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14304 * and let the SCSI mid-layer to retry them to recover.
14306 lpfc_sli_abort_fcp_rings(phba);
14310 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
14311 * @phba: pointer to lpfc hba data structure.
14313 * This routine is called to prepare the SLI3 device for PCI slot reset. It
14314 * disables the device interrupt and pci device, and aborts the internal FCP
14318 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
14320 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14321 "2710 PCI channel disable preparing for reset\n");
14323 /* Block any management I/Os to the device */
14324 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
14326 /* Block all SCSI devices' I/Os on the host */
14327 lpfc_scsi_dev_block(phba);
14329 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
14330 lpfc_sli_flush_io_rings(phba);
14332 /* stop all timers */
14333 lpfc_stop_hba_timers(phba);
14335 /* Disable interrupt and pci device */
14336 lpfc_sli_disable_intr(phba);
14337 pci_disable_device(phba->pcidev);
14341 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
14342 * @phba: pointer to lpfc hba data structure.
14344 * This routine is called to prepare the SLI3 device for PCI slot permanently
14345 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14349 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
14351 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14352 "2711 PCI channel permanent disable for failure\n");
14353 /* Block all SCSI devices' I/Os on the host */
14354 lpfc_scsi_dev_block(phba);
14355 lpfc_sli4_prep_dev_for_reset(phba);
14357 /* stop all timers */
14358 lpfc_stop_hba_timers(phba);
14360 /* Clean up all driver's outstanding SCSI I/Os */
14361 lpfc_sli_flush_io_rings(phba);
14365 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
14366 * @pdev: pointer to PCI device.
14367 * @state: the current PCI connection state.
14369 * This routine is called from the PCI subsystem for I/O error handling to
14370 * device with SLI-3 interface spec. This function is called by the PCI
14371 * subsystem after a PCI bus error affecting this device has been detected.
14372 * When this function is invoked, it will need to stop all the I/Os and
14373 * interrupt(s) to the device. Once that is done, it will return
14374 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
14378 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
14379 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14380 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14382 static pci_ers_result_t
14383 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
14385 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14386 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14389 case pci_channel_io_normal:
14390 /* Non-fatal error, prepare for recovery */
14391 lpfc_sli_prep_dev_for_recover(phba);
14392 return PCI_ERS_RESULT_CAN_RECOVER;
14393 case pci_channel_io_frozen:
14394 /* Fatal error, prepare for slot reset */
14395 lpfc_sli_prep_dev_for_reset(phba);
14396 return PCI_ERS_RESULT_NEED_RESET;
14397 case pci_channel_io_perm_failure:
14398 /* Permanent failure, prepare for device down */
14399 lpfc_sli_prep_dev_for_perm_failure(phba);
14400 return PCI_ERS_RESULT_DISCONNECT;
14402 /* Unknown state, prepare and request slot reset */
14403 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14404 "0472 Unknown PCI error state: x%x\n", state);
14405 lpfc_sli_prep_dev_for_reset(phba);
14406 return PCI_ERS_RESULT_NEED_RESET;
14411 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
14412 * @pdev: pointer to PCI device.
14414 * This routine is called from the PCI subsystem for error handling to
14415 * device with SLI-3 interface spec. This is called after PCI bus has been
14416 * reset to restart the PCI card from scratch, as if from a cold-boot.
14417 * During the PCI subsystem error recovery, after driver returns
14418 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14419 * recovery and then call this routine before calling the .resume method
14420 * to recover the device. This function will initialize the HBA device,
14421 * enable the interrupt, but it will just put the HBA to offline state
14422 * without passing any I/O traffic.
14425 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14426 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14428 static pci_ers_result_t
14429 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
14431 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14432 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14433 struct lpfc_sli *psli = &phba->sli;
14434 uint32_t intr_mode;
14436 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
14437 if (pci_enable_device_mem(pdev)) {
14438 printk(KERN_ERR "lpfc: Cannot re-enable "
14439 "PCI device after reset.\n");
14440 return PCI_ERS_RESULT_DISCONNECT;
14443 pci_restore_state(pdev);
14446 * As the new kernel behavior of pci_restore_state() API call clears
14447 * device saved_state flag, need to save the restored state again.
14449 pci_save_state(pdev);
14451 if (pdev->is_busmaster)
14452 pci_set_master(pdev);
14454 spin_lock_irq(&phba->hbalock);
14455 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
14456 spin_unlock_irq(&phba->hbalock);
14458 /* Configure and enable interrupt */
14459 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14460 if (intr_mode == LPFC_INTR_ERROR) {
14461 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14462 "0427 Cannot re-enable interrupt after "
14464 return PCI_ERS_RESULT_DISCONNECT;
14466 phba->intr_mode = intr_mode;
14468 /* Take device offline, it will perform cleanup */
14469 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14470 lpfc_offline(phba);
14471 lpfc_sli_brdrestart(phba);
14473 /* Log the current active interrupt mode */
14474 lpfc_log_intr_mode(phba, phba->intr_mode);
14476 return PCI_ERS_RESULT_RECOVERED;
14480 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
14481 * @pdev: pointer to PCI device
14483 * This routine is called from the PCI subsystem for error handling to device
14484 * with SLI-3 interface spec. It is called when kernel error recovery tells
14485 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14486 * error recovery. After this call, traffic can start to flow from this device
14490 lpfc_io_resume_s3(struct pci_dev *pdev)
14492 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14493 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14495 /* Bring device online, it will be no-op for non-fatal error resume */
14500 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
14501 * @phba: pointer to lpfc hba data structure.
14503 * returns the number of ELS/CT IOCBs to reserve
14506 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
14508 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
14510 if (phba->sli_rev == LPFC_SLI_REV4) {
14511 if (max_xri <= 100)
14513 else if (max_xri <= 256)
14515 else if (max_xri <= 512)
14517 else if (max_xri <= 1024)
14519 else if (max_xri <= 1536)
14521 else if (max_xri <= 2048)
14530 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
14531 * @phba: pointer to lpfc hba data structure.
14533 * returns the number of ELS/CT + NVMET IOCBs to reserve
14536 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
14538 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
14540 if (phba->nvmet_support)
14541 max_xri += LPFC_NVMET_BUF_POST;
14547 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
14548 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
14549 const struct firmware *fw)
14554 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
14555 /* Three cases: (1) FW was not supported on the detected adapter.
14556 * (2) FW update has been locked out administratively.
14557 * (3) Some other error during FW update.
14558 * In each case, an unmaskable message is written to the console
14559 * for admin diagnosis.
14561 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
14562 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
14563 magic_number != MAGIC_NUMBER_G6) ||
14564 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
14565 magic_number != MAGIC_NUMBER_G7) ||
14566 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
14567 magic_number != MAGIC_NUMBER_G7P)) {
14568 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14569 "3030 This firmware version is not supported on"
14570 " this HBA model. Device:%x Magic:%x Type:%x "
14571 "ID:%x Size %d %zd\n",
14572 phba->pcidev->device, magic_number, ftype, fid,
14575 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
14576 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14577 "3021 Firmware downloads have been prohibited "
14578 "by a system configuration setting on "
14579 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14581 phba->pcidev->device, magic_number, ftype, fid,
14585 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14586 "3022 FW Download failed. Add Status x%x "
14587 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14589 offset, phba->pcidev->device, magic_number,
14590 ftype, fid, fsize, fw->size);
14597 * lpfc_write_firmware - attempt to write a firmware image to the port
14598 * @fw: pointer to firmware image returned from request_firmware.
14599 * @context: pointer to firmware image returned from request_firmware.
14603 lpfc_write_firmware(const struct firmware *fw, void *context)
14605 struct lpfc_hba *phba = (struct lpfc_hba *)context;
14606 char fwrev[FW_REV_STR_SIZE];
14607 struct lpfc_grp_hdr *image;
14608 struct list_head dma_buffer_list;
14610 struct lpfc_dmabuf *dmabuf, *next;
14611 uint32_t offset = 0, temp_offset = 0;
14612 uint32_t magic_number, ftype, fid, fsize;
14614 /* It can be null in no-wait mode, sanity check */
14619 image = (struct lpfc_grp_hdr *)fw->data;
14621 magic_number = be32_to_cpu(image->magic_number);
14622 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
14623 fid = bf_get_be32(lpfc_grp_hdr_id, image);
14624 fsize = be32_to_cpu(image->size);
14626 INIT_LIST_HEAD(&dma_buffer_list);
14627 lpfc_decode_firmware_rev(phba, fwrev, 1);
14628 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
14629 lpfc_log_msg(phba, KERN_NOTICE, LOG_INIT | LOG_SLI,
14630 "3023 Updating Firmware, Current Version:%s "
14631 "New Version:%s\n",
14632 fwrev, image->revision);
14633 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
14634 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
14640 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14644 if (!dmabuf->virt) {
14649 list_add_tail(&dmabuf->list, &dma_buffer_list);
14651 while (offset < fw->size) {
14652 temp_offset = offset;
14653 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
14654 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
14655 memcpy(dmabuf->virt,
14656 fw->data + temp_offset,
14657 fw->size - temp_offset);
14658 temp_offset = fw->size;
14661 memcpy(dmabuf->virt, fw->data + temp_offset,
14663 temp_offset += SLI4_PAGE_SIZE;
14665 rc = lpfc_wr_object(phba, &dma_buffer_list,
14666 (fw->size - offset), &offset);
14668 rc = lpfc_log_write_firmware_error(phba, offset,
14679 lpfc_log_msg(phba, KERN_NOTICE, LOG_INIT | LOG_SLI,
14680 "3029 Skipped Firmware update, Current "
14681 "Version:%s New Version:%s\n",
14682 fwrev, image->revision);
14685 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
14686 list_del(&dmabuf->list);
14687 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
14688 dmabuf->virt, dmabuf->phys);
14691 release_firmware(fw);
14694 lpfc_log_msg(phba, KERN_ERR, LOG_INIT | LOG_SLI,
14695 "3062 Firmware update error, status %d.\n", rc);
14697 lpfc_log_msg(phba, KERN_NOTICE, LOG_INIT | LOG_SLI,
14698 "3024 Firmware update success: size %d.\n", rc);
14702 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
14703 * @phba: pointer to lpfc hba data structure.
14704 * @fw_upgrade: which firmware to update.
14706 * This routine is called to perform Linux generic firmware upgrade on device
14707 * that supports such feature.
14710 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
14712 char file_name[ELX_FW_NAME_SIZE] = {0};
14714 const struct firmware *fw;
14716 /* Only supported on SLI4 interface type 2 for now */
14717 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
14718 LPFC_SLI_INTF_IF_TYPE_2)
14721 scnprintf(file_name, sizeof(file_name), "%s.grp", phba->ModelName);
14723 if (fw_upgrade == INT_FW_UPGRADE) {
14724 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
14725 file_name, &phba->pcidev->dev,
14726 GFP_KERNEL, (void *)phba,
14727 lpfc_write_firmware);
14728 } else if (fw_upgrade == RUN_FW_UPGRADE) {
14729 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
14731 lpfc_write_firmware(fw, (void *)phba);
14740 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
14741 * @pdev: pointer to PCI device
14742 * @pid: pointer to PCI device identifier
14744 * This routine is called from the kernel's PCI subsystem to device with
14745 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14746 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14747 * information of the device and driver to see if the driver state that it
14748 * can support this kind of device. If the match is successful, the driver
14749 * core invokes this routine. If this routine determines it can claim the HBA,
14750 * it does all the initialization that it needs to do to handle the HBA
14754 * 0 - driver can claim the device
14755 * negative value - driver can not claim the device
14758 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
14760 struct lpfc_hba *phba;
14761 struct lpfc_vport *vport = NULL;
14762 struct Scsi_Host *shost = NULL;
14764 uint32_t cfg_mode, intr_mode;
14766 /* Allocate memory for HBA structure */
14767 phba = lpfc_hba_alloc(pdev);
14771 INIT_LIST_HEAD(&phba->poll_list);
14773 /* Perform generic PCI device enabling operation */
14774 error = lpfc_enable_pci_dev(phba);
14776 goto out_free_phba;
14778 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
14779 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
14781 goto out_disable_pci_dev;
14783 /* Set up SLI-4 specific device PCI memory space */
14784 error = lpfc_sli4_pci_mem_setup(phba);
14786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14787 "1410 Failed to set up pci memory space.\n");
14788 goto out_disable_pci_dev;
14791 /* Set up SLI-4 Specific device driver resources */
14792 error = lpfc_sli4_driver_resource_setup(phba);
14794 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14795 "1412 Failed to set up driver resource.\n");
14796 goto out_unset_pci_mem_s4;
14799 spin_lock_init(&phba->rrq_list_lock);
14800 INIT_LIST_HEAD(&phba->active_rrq_list);
14801 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
14803 /* Set up common device driver resources */
14804 error = lpfc_setup_driver_resource_phase2(phba);
14806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14807 "1414 Failed to set up driver resource.\n");
14808 goto out_unset_driver_resource_s4;
14811 /* Get the default values for Model Name and Description */
14812 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14814 /* Now, trying to enable interrupt and bring up the device */
14815 cfg_mode = phba->cfg_use_msi;
14817 /* Put device to a known state before enabling interrupt */
14818 phba->pport = NULL;
14819 lpfc_stop_port(phba);
14821 /* Init cpu_map array */
14822 lpfc_cpu_map_array_init(phba);
14824 /* Init hba_eq_hdl array */
14825 lpfc_hba_eq_hdl_array_init(phba);
14827 /* Configure and enable interrupt */
14828 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14829 if (intr_mode == LPFC_INTR_ERROR) {
14830 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14831 "0426 Failed to enable interrupt.\n");
14833 goto out_unset_driver_resource;
14835 /* Default to single EQ for non-MSI-X */
14836 if (phba->intr_type != MSIX) {
14837 phba->cfg_irq_chann = 1;
14838 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14839 if (phba->nvmet_support)
14840 phba->cfg_nvmet_mrq = 1;
14843 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
14845 /* Create SCSI host to the physical port */
14846 error = lpfc_create_shost(phba);
14848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14849 "1415 Failed to create scsi host.\n");
14850 goto out_disable_intr;
14852 vport = phba->pport;
14853 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14855 /* Configure sysfs attributes */
14856 error = lpfc_alloc_sysfs_attr(vport);
14858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14859 "1416 Failed to allocate sysfs attr\n");
14860 goto out_destroy_shost;
14863 /* Set up SLI-4 HBA */
14864 if (lpfc_sli4_hba_setup(phba)) {
14865 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14866 "1421 Failed to set up hba\n");
14868 goto out_free_sysfs_attr;
14871 /* Log the current active interrupt mode */
14872 phba->intr_mode = intr_mode;
14873 lpfc_log_intr_mode(phba, intr_mode);
14875 /* Perform post initialization setup */
14876 lpfc_post_init_setup(phba);
14878 /* NVME support in FW earlier in the driver load corrects the
14879 * FC4 type making a check for nvme_support unnecessary.
14881 if (phba->nvmet_support == 0) {
14882 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14883 /* Create NVME binding with nvme_fc_transport. This
14884 * ensures the vport is initialized. If the localport
14885 * create fails, it should not unload the driver to
14886 * support field issues.
14888 error = lpfc_nvme_create_localport(vport);
14890 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14891 "6004 NVME registration "
14892 "failed, error x%x\n",
14898 /* check for firmware upgrade or downgrade */
14899 if (phba->cfg_request_firmware_upgrade)
14900 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
14902 /* Check if there are static vports to be created. */
14903 lpfc_create_static_vport(phba);
14905 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
14906 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
14910 out_free_sysfs_attr:
14911 lpfc_free_sysfs_attr(vport);
14913 lpfc_destroy_shost(phba);
14915 lpfc_sli4_disable_intr(phba);
14916 out_unset_driver_resource:
14917 lpfc_unset_driver_resource_phase2(phba);
14918 out_unset_driver_resource_s4:
14919 lpfc_sli4_driver_resource_unset(phba);
14920 out_unset_pci_mem_s4:
14921 lpfc_sli4_pci_mem_unset(phba);
14922 out_disable_pci_dev:
14923 lpfc_disable_pci_dev(phba);
14925 scsi_host_put(shost);
14927 lpfc_hba_free(phba);
14932 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
14933 * @pdev: pointer to PCI device
14935 * This routine is called from the kernel's PCI subsystem to device with
14936 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14937 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14938 * device to be removed from the PCI subsystem properly.
14941 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
14943 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14944 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14945 struct lpfc_vport **vports;
14946 struct lpfc_hba *phba = vport->phba;
14949 /* Mark the device unloading flag */
14950 set_bit(FC_UNLOADING, &vport->load_flag);
14952 lpfc_unreg_congestion_buf(phba);
14954 lpfc_free_sysfs_attr(vport);
14956 /* Release all the vports against this physical port */
14957 vports = lpfc_create_vport_work_array(phba);
14958 if (vports != NULL)
14959 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14960 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14962 fc_vport_terminate(vports[i]->fc_vport);
14964 lpfc_destroy_vport_work_array(phba, vports);
14966 /* Remove FC host with the physical port */
14967 fc_remove_host(shost);
14968 scsi_remove_host(shost);
14970 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
14971 * localports are destroyed after to cleanup all transport memory.
14973 lpfc_cleanup(vport);
14974 lpfc_nvmet_destroy_targetport(phba);
14975 lpfc_nvme_destroy_localport(vport);
14977 /* De-allocate multi-XRI pools */
14978 if (phba->cfg_xri_rebalancing)
14979 lpfc_destroy_multixri_pools(phba);
14982 * Bring down the SLI Layer. This step disables all interrupts,
14983 * clears the rings, discards all mailbox commands, and resets
14984 * the HBA FCoE function.
14986 lpfc_debugfs_terminate(vport);
14988 lpfc_stop_hba_timers(phba);
14989 spin_lock_irq(&phba->port_list_lock);
14990 list_del_init(&vport->listentry);
14991 spin_unlock_irq(&phba->port_list_lock);
14993 /* Perform scsi free before driver resource_unset since scsi
14994 * buffers are released to their corresponding pools here.
14996 lpfc_io_free(phba);
14997 lpfc_free_iocb_list(phba);
14998 lpfc_sli4_hba_unset(phba);
15000 lpfc_unset_driver_resource_phase2(phba);
15001 lpfc_sli4_driver_resource_unset(phba);
15003 /* Unmap adapter Control and Doorbell registers */
15004 lpfc_sli4_pci_mem_unset(phba);
15006 /* Release PCI resources and disable device's PCI function */
15007 scsi_host_put(shost);
15008 lpfc_disable_pci_dev(phba);
15010 /* Finally, free the driver's device data structure */
15011 lpfc_hba_free(phba);
15017 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
15018 * @dev_d: pointer to device
15020 * This routine is called from the kernel's PCI subsystem to support system
15021 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
15022 * this method, it quiesces the device by stopping the driver's worker
15023 * thread for the device, turning off device's interrupt and DMA, and bring
15024 * the device offline. Note that as the driver implements the minimum PM
15025 * requirements to a power-aware driver's PM support for suspend/resume -- all
15026 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
15027 * method call will be treated as SUSPEND and the driver will fully
15028 * reinitialize its device during resume() method call, the driver will set
15029 * device to PCI_D3hot state in PCI config space instead of setting it
15030 * according to the @msg provided by the PM.
15033 * 0 - driver suspended the device
15036 static int __maybe_unused
15037 lpfc_pci_suspend_one_s4(struct device *dev_d)
15039 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
15040 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15043 "2843 PCI device Power Management suspend.\n");
15045 /* Bring down the device */
15046 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
15047 lpfc_offline(phba);
15048 kthread_stop(phba->worker_thread);
15050 /* Disable interrupt from device */
15051 lpfc_sli4_disable_intr(phba);
15052 lpfc_sli4_queue_destroy(phba);
15058 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
15059 * @dev_d: pointer to device
15061 * This routine is called from the kernel's PCI subsystem to support system
15062 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
15063 * this method, it restores the device's PCI config space state and fully
15064 * reinitializes the device and brings it online. Note that as the driver
15065 * implements the minimum PM requirements to a power-aware driver's PM for
15066 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
15067 * to the suspend() method call will be treated as SUSPEND and the driver
15068 * will fully reinitialize its device during resume() method call, the device
15069 * will be set to PCI_D0 directly in PCI config space before restoring the
15073 * 0 - driver suspended the device
15076 static int __maybe_unused
15077 lpfc_pci_resume_one_s4(struct device *dev_d)
15079 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
15080 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15081 uint32_t intr_mode;
15084 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15085 "0292 PCI device Power Management resume.\n");
15087 /* Startup the kernel thread for this host adapter. */
15088 phba->worker_thread = kthread_run(lpfc_do_work, phba,
15089 "lpfc_worker_%d", phba->brd_no);
15090 if (IS_ERR(phba->worker_thread)) {
15091 error = PTR_ERR(phba->worker_thread);
15092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15093 "0293 PM resume failed to start worker "
15094 "thread: error=x%x.\n", error);
15098 /* Configure and enable interrupt */
15099 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15100 if (intr_mode == LPFC_INTR_ERROR) {
15101 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15102 "0294 PM resume Failed to enable interrupt\n");
15105 phba->intr_mode = intr_mode;
15107 /* Restart HBA and bring it online */
15108 lpfc_sli_brdrestart(phba);
15111 /* Log the current active interrupt mode */
15112 lpfc_log_intr_mode(phba, phba->intr_mode);
15118 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
15119 * @phba: pointer to lpfc hba data structure.
15121 * This routine is called to prepare the SLI4 device for PCI slot recover. It
15122 * aborts all the outstanding SCSI I/Os to the pci device.
15125 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
15127 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15128 "2828 PCI channel I/O abort preparing for recovery\n");
15130 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
15131 * and let the SCSI mid-layer to retry them to recover.
15133 lpfc_sli_abort_fcp_rings(phba);
15137 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
15138 * @phba: pointer to lpfc hba data structure.
15140 * This routine is called to prepare the SLI4 device for PCI slot reset. It
15141 * disables the device interrupt and pci device, and aborts the internal FCP
15145 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
15147 int offline = pci_channel_offline(phba->pcidev);
15149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15150 "2826 PCI channel disable preparing for reset offline"
15153 /* Block any management I/Os to the device */
15154 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
15157 /* HBA_PCI_ERR was set in io_error_detect */
15158 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
15159 /* Flush all driver's outstanding I/Os as we are to reset */
15160 lpfc_sli_flush_io_rings(phba);
15161 lpfc_offline(phba);
15163 /* stop all timers */
15164 lpfc_stop_hba_timers(phba);
15166 lpfc_sli4_queue_destroy(phba);
15167 /* Disable interrupt and pci device */
15168 lpfc_sli4_disable_intr(phba);
15169 pci_disable_device(phba->pcidev);
15173 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
15174 * @phba: pointer to lpfc hba data structure.
15176 * This routine is called to prepare the SLI4 device for PCI slot permanently
15177 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
15181 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
15183 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15184 "2827 PCI channel permanent disable for failure\n");
15186 /* Block all SCSI devices' I/Os on the host */
15187 lpfc_scsi_dev_block(phba);
15189 /* stop all timers */
15190 lpfc_stop_hba_timers(phba);
15192 /* Clean up all driver's outstanding I/Os */
15193 lpfc_sli_flush_io_rings(phba);
15197 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
15198 * @pdev: pointer to PCI device.
15199 * @state: the current PCI connection state.
15201 * This routine is called from the PCI subsystem for error handling to device
15202 * with SLI-4 interface spec. This function is called by the PCI subsystem
15203 * after a PCI bus error affecting this device has been detected. When this
15204 * function is invoked, it will need to stop all the I/Os and interrupt(s)
15205 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
15206 * for the PCI subsystem to perform proper recovery as desired.
15209 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15210 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15212 static pci_ers_result_t
15213 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
15215 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15216 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15220 case pci_channel_io_normal:
15221 /* Non-fatal error, prepare for recovery */
15222 lpfc_sli4_prep_dev_for_recover(phba);
15223 return PCI_ERS_RESULT_CAN_RECOVER;
15224 case pci_channel_io_frozen:
15225 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15226 /* Fatal error, prepare for slot reset */
15228 lpfc_sli4_prep_dev_for_reset(phba);
15230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15231 "2832 Already handling PCI error "
15232 "state: x%x\n", state);
15233 return PCI_ERS_RESULT_NEED_RESET;
15234 case pci_channel_io_perm_failure:
15235 set_bit(HBA_PCI_ERR, &phba->bit_flags);
15236 /* Permanent failure, prepare for device down */
15237 lpfc_sli4_prep_dev_for_perm_failure(phba);
15238 return PCI_ERS_RESULT_DISCONNECT;
15240 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15242 lpfc_sli4_prep_dev_for_reset(phba);
15243 /* Unknown state, prepare and request slot reset */
15244 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15245 "2825 Unknown PCI error state: x%x\n", state);
15246 lpfc_sli4_prep_dev_for_reset(phba);
15247 return PCI_ERS_RESULT_NEED_RESET;
15252 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
15253 * @pdev: pointer to PCI device.
15255 * This routine is called from the PCI subsystem for error handling to device
15256 * with SLI-4 interface spec. It is called after PCI bus has been reset to
15257 * restart the PCI card from scratch, as if from a cold-boot. During the
15258 * PCI subsystem error recovery, after the driver returns
15259 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
15260 * recovery and then call this routine before calling the .resume method to
15261 * recover the device. This function will initialize the HBA device, enable
15262 * the interrupt, but it will just put the HBA to offline state without
15263 * passing any I/O traffic.
15266 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15267 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15269 static pci_ers_result_t
15270 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
15272 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15273 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15274 struct lpfc_sli *psli = &phba->sli;
15275 uint32_t intr_mode;
15278 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
15279 if (pci_enable_device_mem(pdev)) {
15280 printk(KERN_ERR "lpfc: Cannot re-enable "
15281 "PCI device after reset.\n");
15282 return PCI_ERS_RESULT_DISCONNECT;
15285 pci_restore_state(pdev);
15287 hba_pci_err = test_and_clear_bit(HBA_PCI_ERR, &phba->bit_flags);
15289 dev_info(&pdev->dev,
15290 "hba_pci_err was not set, recovering slot reset.\n");
15292 * As the new kernel behavior of pci_restore_state() API call clears
15293 * device saved_state flag, need to save the restored state again.
15295 pci_save_state(pdev);
15297 if (pdev->is_busmaster)
15298 pci_set_master(pdev);
15300 spin_lock_irq(&phba->hbalock);
15301 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
15302 spin_unlock_irq(&phba->hbalock);
15304 /* Init cpu_map array */
15305 lpfc_cpu_map_array_init(phba);
15306 /* Configure and enable interrupt */
15307 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15308 if (intr_mode == LPFC_INTR_ERROR) {
15309 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15310 "2824 Cannot re-enable interrupt after "
15312 return PCI_ERS_RESULT_DISCONNECT;
15314 phba->intr_mode = intr_mode;
15315 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
15317 /* Log the current active interrupt mode */
15318 lpfc_log_intr_mode(phba, phba->intr_mode);
15320 return PCI_ERS_RESULT_RECOVERED;
15324 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
15325 * @pdev: pointer to PCI device
15327 * This routine is called from the PCI subsystem for error handling to device
15328 * with SLI-4 interface spec. It is called when kernel error recovery tells
15329 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
15330 * error recovery. After this call, traffic can start to flow from this device
15334 lpfc_io_resume_s4(struct pci_dev *pdev)
15336 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15337 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15340 * In case of slot reset, as function reset is performed through
15341 * mailbox command which needs DMA to be enabled, this operation
15342 * has to be moved to the io resume phase. Taking device offline
15343 * will perform the necessary cleanup.
15345 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
15346 /* Perform device reset */
15347 lpfc_sli_brdrestart(phba);
15348 /* Bring the device back online */
15354 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
15355 * @pdev: pointer to PCI device
15356 * @pid: pointer to PCI device identifier
15358 * This routine is to be registered to the kernel's PCI subsystem. When an
15359 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
15360 * at PCI device-specific information of the device and driver to see if the
15361 * driver state that it can support this kind of device. If the match is
15362 * successful, the driver core invokes this routine. This routine dispatches
15363 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
15364 * do all the initialization that it needs to do to handle the HBA device
15368 * 0 - driver can claim the device
15369 * negative value - driver can not claim the device
15372 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
15375 struct lpfc_sli_intf intf;
15377 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
15380 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
15381 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
15382 rc = lpfc_pci_probe_one_s4(pdev, pid);
15384 rc = lpfc_pci_probe_one_s3(pdev, pid);
15390 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
15391 * @pdev: pointer to PCI device
15393 * This routine is to be registered to the kernel's PCI subsystem. When an
15394 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
15395 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
15396 * remove routine, which will perform all the necessary cleanup for the
15397 * device to be removed from the PCI subsystem properly.
15400 lpfc_pci_remove_one(struct pci_dev *pdev)
15402 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15403 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15405 switch (phba->pci_dev_grp) {
15406 case LPFC_PCI_DEV_LP:
15407 lpfc_pci_remove_one_s3(pdev);
15409 case LPFC_PCI_DEV_OC:
15410 lpfc_pci_remove_one_s4(pdev);
15413 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15414 "1424 Invalid PCI device group: 0x%x\n",
15415 phba->pci_dev_grp);
15422 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
15423 * @dev: pointer to device
15425 * This routine is to be registered to the kernel's PCI subsystem to support
15426 * system Power Management (PM). When PM invokes this method, it dispatches
15427 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
15428 * suspend the device.
15431 * 0 - driver suspended the device
15434 static int __maybe_unused
15435 lpfc_pci_suspend_one(struct device *dev)
15437 struct Scsi_Host *shost = dev_get_drvdata(dev);
15438 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15441 switch (phba->pci_dev_grp) {
15442 case LPFC_PCI_DEV_LP:
15443 rc = lpfc_pci_suspend_one_s3(dev);
15445 case LPFC_PCI_DEV_OC:
15446 rc = lpfc_pci_suspend_one_s4(dev);
15449 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15450 "1425 Invalid PCI device group: 0x%x\n",
15451 phba->pci_dev_grp);
15458 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
15459 * @dev: pointer to device
15461 * This routine is to be registered to the kernel's PCI subsystem to support
15462 * system Power Management (PM). When PM invokes this method, it dispatches
15463 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
15464 * resume the device.
15467 * 0 - driver suspended the device
15470 static int __maybe_unused
15471 lpfc_pci_resume_one(struct device *dev)
15473 struct Scsi_Host *shost = dev_get_drvdata(dev);
15474 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15477 switch (phba->pci_dev_grp) {
15478 case LPFC_PCI_DEV_LP:
15479 rc = lpfc_pci_resume_one_s3(dev);
15481 case LPFC_PCI_DEV_OC:
15482 rc = lpfc_pci_resume_one_s4(dev);
15485 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15486 "1426 Invalid PCI device group: 0x%x\n",
15487 phba->pci_dev_grp);
15494 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
15495 * @pdev: pointer to PCI device.
15496 * @state: the current PCI connection state.
15498 * This routine is registered to the PCI subsystem for error handling. This
15499 * function is called by the PCI subsystem after a PCI bus error affecting
15500 * this device has been detected. When this routine is invoked, it dispatches
15501 * the action to the proper SLI-3 or SLI-4 device error detected handling
15502 * routine, which will perform the proper error detected operation.
15505 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15506 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15508 static pci_ers_result_t
15509 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
15511 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15512 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15513 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15515 if (phba->link_state == LPFC_HBA_ERROR &&
15516 test_bit(HBA_IOQ_FLUSH, &phba->hba_flag))
15517 return PCI_ERS_RESULT_NEED_RESET;
15519 switch (phba->pci_dev_grp) {
15520 case LPFC_PCI_DEV_LP:
15521 rc = lpfc_io_error_detected_s3(pdev, state);
15523 case LPFC_PCI_DEV_OC:
15524 rc = lpfc_io_error_detected_s4(pdev, state);
15527 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15528 "1427 Invalid PCI device group: 0x%x\n",
15529 phba->pci_dev_grp);
15536 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
15537 * @pdev: pointer to PCI device.
15539 * This routine is registered to the PCI subsystem for error handling. This
15540 * function is called after PCI bus has been reset to restart the PCI card
15541 * from scratch, as if from a cold-boot. When this routine is invoked, it
15542 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
15543 * routine, which will perform the proper device reset.
15546 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15547 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15549 static pci_ers_result_t
15550 lpfc_io_slot_reset(struct pci_dev *pdev)
15552 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15553 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15554 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15556 switch (phba->pci_dev_grp) {
15557 case LPFC_PCI_DEV_LP:
15558 rc = lpfc_io_slot_reset_s3(pdev);
15560 case LPFC_PCI_DEV_OC:
15561 rc = lpfc_io_slot_reset_s4(pdev);
15564 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15565 "1428 Invalid PCI device group: 0x%x\n",
15566 phba->pci_dev_grp);
15573 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
15574 * @pdev: pointer to PCI device
15576 * This routine is registered to the PCI subsystem for error handling. It
15577 * is called when kernel error recovery tells the lpfc driver that it is
15578 * OK to resume normal PCI operation after PCI bus error recovery. When
15579 * this routine is invoked, it dispatches the action to the proper SLI-3
15580 * or SLI-4 device io_resume routine, which will resume the device operation.
15583 lpfc_io_resume(struct pci_dev *pdev)
15585 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15586 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15588 switch (phba->pci_dev_grp) {
15589 case LPFC_PCI_DEV_LP:
15590 lpfc_io_resume_s3(pdev);
15592 case LPFC_PCI_DEV_OC:
15593 lpfc_io_resume_s4(pdev);
15596 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15597 "1429 Invalid PCI device group: 0x%x\n",
15598 phba->pci_dev_grp);
15605 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
15606 * @phba: pointer to lpfc hba data structure.
15608 * This routine checks to see if OAS is supported for this adapter. If
15609 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
15610 * the enable oas flag is cleared and the pool created for OAS device data
15615 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
15618 if (!phba->cfg_EnableXLane)
15621 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
15625 mempool_destroy(phba->device_data_mem_pool);
15626 phba->device_data_mem_pool = NULL;
15633 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
15634 * @phba: pointer to lpfc hba data structure.
15636 * This routine checks to see if RAS is supported by the adapter. Check the
15637 * function through which RAS support enablement is to be done.
15640 lpfc_sli4_ras_init(struct lpfc_hba *phba)
15642 /* if ASIC_GEN_NUM >= 0xC) */
15643 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
15644 LPFC_SLI_INTF_IF_TYPE_6) ||
15645 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
15646 LPFC_SLI_INTF_FAMILY_G6)) {
15647 phba->ras_fwlog.ras_hwsupport = true;
15648 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
15649 phba->cfg_ras_fwlog_buffsize)
15650 phba->ras_fwlog.ras_enabled = true;
15652 phba->ras_fwlog.ras_enabled = false;
15654 phba->ras_fwlog.ras_hwsupport = false;
15659 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
15661 static const struct pci_error_handlers lpfc_err_handler = {
15662 .error_detected = lpfc_io_error_detected,
15663 .slot_reset = lpfc_io_slot_reset,
15664 .resume = lpfc_io_resume,
15667 static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
15668 lpfc_pci_suspend_one,
15669 lpfc_pci_resume_one);
15671 static struct pci_driver lpfc_driver = {
15672 .name = LPFC_DRIVER_NAME,
15673 .id_table = lpfc_id_table,
15674 .probe = lpfc_pci_probe_one,
15675 .remove = lpfc_pci_remove_one,
15676 .shutdown = lpfc_pci_remove_one,
15677 .driver.pm = &lpfc_pci_pm_ops_one,
15678 .err_handler = &lpfc_err_handler,
15681 static const struct file_operations lpfc_mgmt_fop = {
15682 .owner = THIS_MODULE,
15685 static struct miscdevice lpfc_mgmt_dev = {
15686 .minor = MISC_DYNAMIC_MINOR,
15687 .name = "lpfcmgmt",
15688 .fops = &lpfc_mgmt_fop,
15692 * lpfc_init - lpfc module initialization routine
15694 * This routine is to be invoked when the lpfc module is loaded into the
15695 * kernel. The special kernel macro module_init() is used to indicate the
15696 * role of this routine to the kernel as lpfc module entry point.
15700 * -ENOMEM - FC attach transport failed
15701 * all others - failed
15708 pr_info(LPFC_MODULE_DESC "\n");
15709 pr_info(LPFC_COPYRIGHT "\n");
15711 error = misc_register(&lpfc_mgmt_dev);
15713 printk(KERN_ERR "Could not register lpfcmgmt device, "
15714 "misc_register returned with status %d", error);
15717 lpfc_transport_functions.vport_create = lpfc_vport_create;
15718 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
15719 lpfc_transport_template =
15720 fc_attach_transport(&lpfc_transport_functions);
15721 if (lpfc_transport_template == NULL)
15723 lpfc_vport_transport_template =
15724 fc_attach_transport(&lpfc_vport_transport_functions);
15725 if (lpfc_vport_transport_template == NULL) {
15726 fc_release_transport(lpfc_transport_template);
15729 lpfc_wqe_cmd_template();
15730 lpfc_nvmet_cmd_template();
15732 /* Initialize in case vector mapping is needed */
15733 lpfc_present_cpu = num_present_cpus();
15735 lpfc_pldv_detect = false;
15737 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
15738 "lpfc/sli4:online",
15739 lpfc_cpu_online, lpfc_cpu_offline);
15741 goto cpuhp_failure;
15742 lpfc_cpuhp_state = error;
15744 error = pci_register_driver(&lpfc_driver);
15751 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15753 fc_release_transport(lpfc_transport_template);
15754 fc_release_transport(lpfc_vport_transport_template);
15756 misc_deregister(&lpfc_mgmt_dev);
15761 void lpfc_dmp_dbg(struct lpfc_hba *phba)
15763 unsigned int start_idx;
15764 unsigned int dbg_cnt;
15765 unsigned int temp_idx;
15768 unsigned long rem_nsec;
15770 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
15773 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
15774 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
15777 temp_idx = start_idx;
15778 if (dbg_cnt >= DBG_LOG_SZ) {
15779 dbg_cnt = DBG_LOG_SZ;
15782 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
15783 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
15785 if (start_idx < dbg_cnt)
15786 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
15788 start_idx -= dbg_cnt;
15791 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
15792 start_idx, temp_idx, dbg_cnt);
15794 for (i = 0; i < dbg_cnt; i++) {
15795 if ((start_idx + i) < DBG_LOG_SZ)
15796 temp_idx = (start_idx + i) % DBG_LOG_SZ;
15799 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
15800 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15802 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15804 phba->dbg_log[temp_idx].log);
15807 atomic_set(&phba->dbg_log_cnt, 0);
15808 atomic_set(&phba->dbg_log_dmping, 0);
15812 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15816 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15817 struct va_format vaf;
15820 va_start(args, fmt);
15821 if (unlikely(dbg_dmping)) {
15824 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15828 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15831 atomic_inc(&phba->dbg_log_cnt);
15833 vscnprintf(phba->dbg_log[idx].log,
15834 sizeof(phba->dbg_log[idx].log), fmt, args);
15837 phba->dbg_log[idx].t_ns = local_clock();
15841 * lpfc_exit - lpfc module removal routine
15843 * This routine is invoked when the lpfc module is removed from the kernel.
15844 * The special kernel macro module_exit() is used to indicate the role of
15845 * this routine to the kernel as lpfc module exit point.
15850 misc_deregister(&lpfc_mgmt_dev);
15851 pci_unregister_driver(&lpfc_driver);
15852 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15853 fc_release_transport(lpfc_transport_template);
15854 fc_release_transport(lpfc_vport_transport_template);
15855 idr_destroy(&lpfc_hba_index);
15858 module_init(lpfc_init);
15859 module_exit(lpfc_exit);
15860 MODULE_LICENSE("GPL");
15861 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
15862 MODULE_AUTHOR("Broadcom");
15863 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);