1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 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/ctype.h>
34 #include <linux/aer.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/msi.h>
40 #include <linux/irq.h>
41 #include <linux/bitops.h>
42 #include <linux/crash_dump.h>
43 #include <linux/cpu.h>
44 #include <linux/cpuhotplug.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_transport_fc.h>
50 #include <scsi/scsi_tcq.h>
51 #include <scsi/fc/fc_fs.h>
56 #include "lpfc_sli4.h"
58 #include "lpfc_disc.h"
60 #include "lpfc_scsi.h"
61 #include "lpfc_nvme.h"
62 #include "lpfc_logmsg.h"
63 #include "lpfc_crtn.h"
64 #include "lpfc_vport.h"
65 #include "lpfc_version.h"
68 static enum cpuhp_state lpfc_cpuhp_state;
69 /* Used when mapping IRQ vectors in a driver centric manner */
70 static uint32_t lpfc_present_cpu;
71 static bool lpfc_pldv_detect;
73 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
74 static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
75 static void lpfc_cpuhp_add(struct lpfc_hba *phba);
76 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
77 static int lpfc_post_rcv_buf(struct lpfc_hba *);
78 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
79 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
80 static int lpfc_setup_endian_order(struct lpfc_hba *);
81 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
82 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
83 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
84 static void lpfc_init_sgl_list(struct lpfc_hba *);
85 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
86 static void lpfc_free_active_sgl(struct lpfc_hba *);
87 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
88 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
89 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
90 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
91 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
92 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
93 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
94 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
95 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
96 static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
97 static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
99 static struct scsi_transport_template *lpfc_transport_template = NULL;
100 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
101 static DEFINE_IDR(lpfc_hba_index);
102 #define LPFC_NVMET_BUF_POST 254
103 static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
106 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
107 * @phba: pointer to lpfc hba data structure.
109 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
110 * mailbox command. It retrieves the revision information from the HBA and
111 * collects the Vital Product Data (VPD) about the HBA for preparing the
112 * configuration of the HBA.
116 * -ERESTART - requests the SLI layer to reset the HBA and try again.
117 * Any other value - indicates an error.
120 lpfc_config_port_prep(struct lpfc_hba *phba)
122 lpfc_vpd_t *vp = &phba->vpd;
126 char *lpfc_vpd_data = NULL;
128 static char licensed[56] =
129 "key unlock for use with gnu public licensed code only\0";
130 static int init_key = 1;
132 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
134 phba->link_state = LPFC_HBA_ERROR;
139 phba->link_state = LPFC_INIT_MBX_CMDS;
141 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
143 uint32_t *ptext = (uint32_t *) licensed;
145 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
146 *ptext = cpu_to_be32(*ptext);
150 lpfc_read_nv(phba, pmb);
151 memset((char*)mb->un.varRDnvp.rsvd3, 0,
152 sizeof (mb->un.varRDnvp.rsvd3));
153 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
156 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
158 if (rc != MBX_SUCCESS) {
159 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
160 "0324 Config Port initialization "
161 "error, mbxCmd x%x READ_NVPARM, "
163 mb->mbxCommand, mb->mbxStatus);
164 mempool_free(pmb, phba->mbox_mem_pool);
167 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
169 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
174 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
175 * which was already set in lpfc_get_cfgparam()
177 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
179 /* Setup and issue mailbox READ REV command */
180 lpfc_read_rev(phba, pmb);
181 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
182 if (rc != MBX_SUCCESS) {
183 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
184 "0439 Adapter failed to init, mbxCmd x%x "
185 "READ_REV, mbxStatus x%x\n",
186 mb->mbxCommand, mb->mbxStatus);
187 mempool_free( pmb, phba->mbox_mem_pool);
193 * The value of rr must be 1 since the driver set the cv field to 1.
194 * This setting requires the FW to set all revision fields.
196 if (mb->un.varRdRev.rr == 0) {
198 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
199 "0440 Adapter failed to init, READ_REV has "
200 "missing revision information.\n");
201 mempool_free(pmb, phba->mbox_mem_pool);
205 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
206 mempool_free(pmb, phba->mbox_mem_pool);
210 /* Save information as VPD data */
212 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
213 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
214 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
215 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
216 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
217 vp->rev.biuRev = mb->un.varRdRev.biuRev;
218 vp->rev.smRev = mb->un.varRdRev.smRev;
219 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
220 vp->rev.endecRev = mb->un.varRdRev.endecRev;
221 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
222 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
223 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
224 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
225 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
226 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
228 /* If the sli feature level is less then 9, we must
229 * tear down all RPIs and VPIs on link down if NPIV
232 if (vp->rev.feaLevelHigh < 9)
233 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
235 if (lpfc_is_LC_HBA(phba->pcidev->device))
236 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
237 sizeof (phba->RandomData));
239 /* Get adapter VPD information */
240 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
244 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
245 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
247 if (rc != MBX_SUCCESS) {
248 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
249 "0441 VPD not present on adapter, "
250 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
251 mb->mbxCommand, mb->mbxStatus);
252 mb->un.varDmp.word_cnt = 0;
254 /* dump mem may return a zero when finished or we got a
255 * mailbox error, either way we are done.
257 if (mb->un.varDmp.word_cnt == 0)
260 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
261 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
262 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
263 lpfc_vpd_data + offset,
264 mb->un.varDmp.word_cnt);
265 offset += mb->un.varDmp.word_cnt;
266 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
268 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
270 kfree(lpfc_vpd_data);
272 mempool_free(pmb, phba->mbox_mem_pool);
277 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
278 * @phba: pointer to lpfc hba data structure.
279 * @pmboxq: pointer to the driver internal queue element for mailbox command.
281 * This is the completion handler for driver's configuring asynchronous event
282 * mailbox command to the device. If the mailbox command returns successfully,
283 * it will set internal async event support flag to 1; otherwise, it will
284 * set internal async event support flag to 0.
287 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
289 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
290 phba->temp_sensor_support = 1;
292 phba->temp_sensor_support = 0;
293 mempool_free(pmboxq, phba->mbox_mem_pool);
298 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
299 * @phba: pointer to lpfc hba data structure.
300 * @pmboxq: pointer to the driver internal queue element for mailbox command.
302 * This is the completion handler for dump mailbox command for getting
303 * wake up parameters. When this command complete, the response contain
304 * Option rom version of the HBA. This function translate the version number
305 * into a human readable string and store it in OptionROMVersion.
308 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
311 uint32_t prog_id_word;
313 /* character array used for decoding dist type. */
314 char dist_char[] = "nabx";
316 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
317 mempool_free(pmboxq, phba->mbox_mem_pool);
321 prg = (struct prog_id *) &prog_id_word;
323 /* word 7 contain option rom version */
324 prog_id_word = pmboxq->u.mb.un.varWords[7];
326 /* Decode the Option rom version word to a readable string */
328 dist = dist_char[prg->dist];
330 if ((prg->dist == 3) && (prg->num == 0))
331 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
332 prg->ver, prg->rev, prg->lev);
334 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
335 prg->ver, prg->rev, prg->lev,
337 mempool_free(pmboxq, phba->mbox_mem_pool);
342 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
343 * cfg_soft_wwnn, cfg_soft_wwpn
344 * @vport: pointer to lpfc vport data structure.
351 lpfc_update_vport_wwn(struct lpfc_vport *vport)
353 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
354 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
356 /* If the soft name exists then update it using the service params */
357 if (vport->phba->cfg_soft_wwnn)
358 u64_to_wwn(vport->phba->cfg_soft_wwnn,
359 vport->fc_sparam.nodeName.u.wwn);
360 if (vport->phba->cfg_soft_wwpn)
361 u64_to_wwn(vport->phba->cfg_soft_wwpn,
362 vport->fc_sparam.portName.u.wwn);
365 * If the name is empty or there exists a soft name
366 * then copy the service params name, otherwise use the fc name
368 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
369 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
370 sizeof(struct lpfc_name));
372 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
373 sizeof(struct lpfc_name));
376 * If the port name has changed, then set the Param changes flag
379 if (vport->fc_portname.u.wwn[0] != 0 &&
380 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
381 sizeof(struct lpfc_name)))
382 vport->vport_flag |= FAWWPN_PARAM_CHG;
384 if (vport->fc_portname.u.wwn[0] == 0 ||
385 vport->phba->cfg_soft_wwpn ||
386 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
387 vport->vport_flag & FAWWPN_SET) {
388 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
389 sizeof(struct lpfc_name));
390 vport->vport_flag &= ~FAWWPN_SET;
391 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
392 vport->vport_flag |= FAWWPN_SET;
395 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
396 sizeof(struct lpfc_name));
400 * lpfc_config_port_post - Perform lpfc initialization after config port
401 * @phba: pointer to lpfc hba data structure.
403 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
404 * command call. It performs all internal resource and state setups on the
405 * port: post IOCB buffers, enable appropriate host interrupt attentions,
406 * ELS ring timers, etc.
410 * Any other value - error.
413 lpfc_config_port_post(struct lpfc_hba *phba)
415 struct lpfc_vport *vport = phba->pport;
416 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
419 struct lpfc_dmabuf *mp;
420 struct lpfc_sli *psli = &phba->sli;
421 uint32_t status, timeout;
425 spin_lock_irq(&phba->hbalock);
427 * If the Config port completed correctly the HBA is not
428 * over heated any more.
430 if (phba->over_temp_state == HBA_OVER_TEMP)
431 phba->over_temp_state = HBA_NORMAL_TEMP;
432 spin_unlock_irq(&phba->hbalock);
434 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
436 phba->link_state = LPFC_HBA_ERROR;
441 /* Get login parameters for NID. */
442 rc = lpfc_read_sparam(phba, pmb, 0);
444 mempool_free(pmb, phba->mbox_mem_pool);
449 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
450 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
451 "0448 Adapter failed init, mbxCmd x%x "
452 "READ_SPARM mbxStatus x%x\n",
453 mb->mbxCommand, mb->mbxStatus);
454 phba->link_state = LPFC_HBA_ERROR;
455 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
456 mempool_free(pmb, phba->mbox_mem_pool);
457 lpfc_mbuf_free(phba, mp->virt, mp->phys);
462 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
464 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
465 lpfc_mbuf_free(phba, mp->virt, mp->phys);
468 lpfc_update_vport_wwn(vport);
470 /* Update the fc_host data structures with new wwn. */
471 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
472 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
473 fc_host_max_npiv_vports(shost) = phba->max_vpi;
475 /* If no serial number in VPD data, use low 6 bytes of WWNN */
476 /* This should be consolidated into parse_vpd ? - mr */
477 if (phba->SerialNumber[0] == 0) {
480 outptr = &vport->fc_nodename.u.s.IEEE[0];
481 for (i = 0; i < 12; i++) {
483 j = ((status & 0xf0) >> 4);
485 phba->SerialNumber[i] =
486 (char)((uint8_t) 0x30 + (uint8_t) j);
488 phba->SerialNumber[i] =
489 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
493 phba->SerialNumber[i] =
494 (char)((uint8_t) 0x30 + (uint8_t) j);
496 phba->SerialNumber[i] =
497 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
501 lpfc_read_config(phba, pmb);
503 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
504 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
505 "0453 Adapter failed to init, mbxCmd x%x "
506 "READ_CONFIG, mbxStatus x%x\n",
507 mb->mbxCommand, mb->mbxStatus);
508 phba->link_state = LPFC_HBA_ERROR;
509 mempool_free( pmb, phba->mbox_mem_pool);
513 /* Check if the port is disabled */
514 lpfc_sli_read_link_ste(phba);
516 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
517 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
518 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
519 "3359 HBA queue depth changed from %d to %d\n",
520 phba->cfg_hba_queue_depth,
521 mb->un.varRdConfig.max_xri);
522 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
525 phba->lmt = mb->un.varRdConfig.lmt;
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
530 phba->link_state = LPFC_LINK_DOWN;
532 /* Only process IOCBs on ELS ring till hba_state is READY */
533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
538 /* Post receive buffers for desired rings */
539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
548 mempool_free(pmb, phba->mbox_mem_pool);
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
558 mempool_free(pmb, phba->mbox_mem_pool);
563 spin_lock_irq(&phba->hbalock);
564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
567 /* Enable appropriate host interrupts */
568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
584 status &= ~(HC_R0INT_ENA);
586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
588 spin_unlock_irq(&phba->hbalock);
590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
594 /* Set up heart beat (HB) timer */
595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
597 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
598 phba->last_completion_time = jiffies;
599 /* Set up error attention (ERATT) polling timer */
600 mod_timer(&phba->eratt_poll,
601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
605 "2598 Adapter Link is disabled.\n");
606 lpfc_down_link(phba, pmb);
607 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
608 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
609 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
610 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
611 "2599 Adapter failed to issue DOWN_LINK"
612 " mbox command rc 0x%x\n", rc);
614 mempool_free(pmb, phba->mbox_mem_pool);
617 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
618 mempool_free(pmb, phba->mbox_mem_pool);
619 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
623 /* MBOX buffer will be freed in mbox compl */
624 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
626 phba->link_state = LPFC_HBA_ERROR;
630 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
631 pmb->mbox_cmpl = lpfc_config_async_cmpl;
632 pmb->vport = phba->pport;
633 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
635 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
636 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
637 "0456 Adapter failed to issue "
638 "ASYNCEVT_ENABLE mbox status x%x\n",
640 mempool_free(pmb, phba->mbox_mem_pool);
643 /* Get Option rom version */
644 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
646 phba->link_state = LPFC_HBA_ERROR;
650 lpfc_dump_wakeup_param(phba, pmb);
651 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
652 pmb->vport = phba->pport;
653 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
655 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
656 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
657 "0435 Adapter failed "
658 "to get Option ROM version status x%x\n", rc);
659 mempool_free(pmb, phba->mbox_mem_pool);
666 * lpfc_sli4_refresh_params - update driver copy of params.
667 * @phba: Pointer to HBA context object.
669 * This is called to refresh driver copy of dynamic fields from the
670 * common_get_sli4_parameters descriptor.
673 lpfc_sli4_refresh_params(struct lpfc_hba *phba)
676 struct lpfc_mqe *mqe;
677 struct lpfc_sli4_parameters *mbx_sli4_parameters;
680 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
685 /* Read the port's SLI4 Config Parameters */
686 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
687 sizeof(struct lpfc_sli4_cfg_mhdr));
688 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
689 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
690 length, LPFC_SLI4_MBX_EMBED);
692 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
694 mempool_free(mboxq, phba->mbox_mem_pool);
697 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
698 phba->sli4_hba.pc_sli4_params.mi_ver =
699 bf_get(cfg_mi_ver, mbx_sli4_parameters);
700 phba->sli4_hba.pc_sli4_params.cmf =
701 bf_get(cfg_cmf, mbx_sli4_parameters);
702 phba->sli4_hba.pc_sli4_params.pls =
703 bf_get(cfg_pvl, mbx_sli4_parameters);
705 mempool_free(mboxq, phba->mbox_mem_pool);
710 * lpfc_hba_init_link - Initialize the FC link
711 * @phba: pointer to lpfc hba data structure.
712 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
714 * This routine will issue the INIT_LINK mailbox command call.
715 * It is available to other drivers through the lpfc_hba data
716 * structure for use as a delayed link up mechanism with the
717 * module parameter lpfc_suppress_link_up.
721 * Any other value - error
724 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
726 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
730 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
731 * @phba: pointer to lpfc hba data structure.
732 * @fc_topology: desired fc topology.
733 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
735 * This routine will issue the INIT_LINK mailbox command call.
736 * It is available to other drivers through the lpfc_hba data
737 * structure for use as a delayed link up mechanism with the
738 * module parameter lpfc_suppress_link_up.
742 * Any other value - error
745 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
748 struct lpfc_vport *vport = phba->pport;
753 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
755 phba->link_state = LPFC_HBA_ERROR;
761 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
762 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
763 !(phba->lmt & LMT_1Gb)) ||
764 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
765 !(phba->lmt & LMT_2Gb)) ||
766 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
767 !(phba->lmt & LMT_4Gb)) ||
768 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
769 !(phba->lmt & LMT_8Gb)) ||
770 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
771 !(phba->lmt & LMT_10Gb)) ||
772 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
773 !(phba->lmt & LMT_16Gb)) ||
774 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
775 !(phba->lmt & LMT_32Gb)) ||
776 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
777 !(phba->lmt & LMT_64Gb))) {
778 /* Reset link speed to auto */
779 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
780 "1302 Invalid speed for this board:%d "
781 "Reset link speed to auto.\n",
782 phba->cfg_link_speed);
783 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
785 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
786 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
787 if (phba->sli_rev < LPFC_SLI_REV4)
788 lpfc_set_loopback_flag(phba);
789 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
790 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
791 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
792 "0498 Adapter failed to init, mbxCmd x%x "
793 "INIT_LINK, mbxStatus x%x\n",
794 mb->mbxCommand, mb->mbxStatus);
795 if (phba->sli_rev <= LPFC_SLI_REV3) {
796 /* Clear all interrupt enable conditions */
797 writel(0, phba->HCregaddr);
798 readl(phba->HCregaddr); /* flush */
799 /* Clear all pending interrupts */
800 writel(0xffffffff, phba->HAregaddr);
801 readl(phba->HAregaddr); /* flush */
803 phba->link_state = LPFC_HBA_ERROR;
804 if (rc != MBX_BUSY || flag == MBX_POLL)
805 mempool_free(pmb, phba->mbox_mem_pool);
808 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
809 if (flag == MBX_POLL)
810 mempool_free(pmb, phba->mbox_mem_pool);
816 * lpfc_hba_down_link - this routine downs the FC link
817 * @phba: pointer to lpfc hba data structure.
818 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
820 * This routine will issue the DOWN_LINK mailbox command call.
821 * It is available to other drivers through the lpfc_hba data
822 * structure for use to stop the link.
826 * Any other value - error
829 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
834 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
836 phba->link_state = LPFC_HBA_ERROR;
840 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
841 "0491 Adapter Link is disabled.\n");
842 lpfc_down_link(phba, pmb);
843 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
844 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
845 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
846 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
847 "2522 Adapter failed to issue DOWN_LINK"
848 " mbox command rc 0x%x\n", rc);
850 mempool_free(pmb, phba->mbox_mem_pool);
853 if (flag == MBX_POLL)
854 mempool_free(pmb, phba->mbox_mem_pool);
860 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
861 * @phba: pointer to lpfc HBA data structure.
863 * This routine will do LPFC uninitialization before the HBA is reset when
864 * bringing down the SLI Layer.
868 * Any other value - error.
871 lpfc_hba_down_prep(struct lpfc_hba *phba)
873 struct lpfc_vport **vports;
876 if (phba->sli_rev <= LPFC_SLI_REV3) {
877 /* Disable interrupts */
878 writel(0, phba->HCregaddr);
879 readl(phba->HCregaddr); /* flush */
882 if (phba->pport->load_flag & FC_UNLOADING)
883 lpfc_cleanup_discovery_resources(phba->pport);
885 vports = lpfc_create_vport_work_array(phba);
887 for (i = 0; i <= phba->max_vports &&
888 vports[i] != NULL; i++)
889 lpfc_cleanup_discovery_resources(vports[i]);
890 lpfc_destroy_vport_work_array(phba, vports);
896 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
897 * rspiocb which got deferred
899 * @phba: pointer to lpfc HBA data structure.
901 * This routine will cleanup completed slow path events after HBA is reset
902 * when bringing down the SLI Layer.
909 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
911 struct lpfc_iocbq *rspiocbq;
912 struct hbq_dmabuf *dmabuf;
913 struct lpfc_cq_event *cq_event;
915 spin_lock_irq(&phba->hbalock);
916 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
917 spin_unlock_irq(&phba->hbalock);
919 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
920 /* Get the response iocb from the head of work queue */
921 spin_lock_irq(&phba->hbalock);
922 list_remove_head(&phba->sli4_hba.sp_queue_event,
923 cq_event, struct lpfc_cq_event, list);
924 spin_unlock_irq(&phba->hbalock);
926 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
927 case CQE_CODE_COMPL_WQE:
928 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
930 lpfc_sli_release_iocbq(phba, rspiocbq);
932 case CQE_CODE_RECEIVE:
933 case CQE_CODE_RECEIVE_V1:
934 dmabuf = container_of(cq_event, struct hbq_dmabuf,
936 lpfc_in_buf_free(phba, &dmabuf->dbuf);
942 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
943 * @phba: pointer to lpfc HBA data structure.
945 * This routine will cleanup posted ELS buffers after the HBA is reset
946 * when bringing down the SLI Layer.
953 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
955 struct lpfc_sli *psli = &phba->sli;
956 struct lpfc_sli_ring *pring;
957 struct lpfc_dmabuf *mp, *next_mp;
961 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
962 lpfc_sli_hbqbuf_free_all(phba);
964 /* Cleanup preposted buffers on the ELS ring */
965 pring = &psli->sli3_ring[LPFC_ELS_RING];
966 spin_lock_irq(&phba->hbalock);
967 list_splice_init(&pring->postbufq, &buflist);
968 spin_unlock_irq(&phba->hbalock);
971 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
974 lpfc_mbuf_free(phba, mp->virt, mp->phys);
978 spin_lock_irq(&phba->hbalock);
979 pring->postbufq_cnt -= count;
980 spin_unlock_irq(&phba->hbalock);
985 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
986 * @phba: pointer to lpfc HBA data structure.
988 * This routine will cleanup the txcmplq after the HBA is reset when bringing
989 * down the SLI Layer.
995 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
997 struct lpfc_sli *psli = &phba->sli;
998 struct lpfc_queue *qp = NULL;
999 struct lpfc_sli_ring *pring;
1000 LIST_HEAD(completions);
1002 struct lpfc_iocbq *piocb, *next_iocb;
1004 if (phba->sli_rev != LPFC_SLI_REV4) {
1005 for (i = 0; i < psli->num_rings; i++) {
1006 pring = &psli->sli3_ring[i];
1007 spin_lock_irq(&phba->hbalock);
1008 /* At this point in time the HBA is either reset or DOA
1009 * Nothing should be on txcmplq as it will
1012 list_splice_init(&pring->txcmplq, &completions);
1013 pring->txcmplq_cnt = 0;
1014 spin_unlock_irq(&phba->hbalock);
1016 lpfc_sli_abort_iocb_ring(phba, pring);
1018 /* Cancel all the IOCBs from the completions list */
1019 lpfc_sli_cancel_iocbs(phba, &completions,
1020 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1023 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1027 spin_lock_irq(&pring->ring_lock);
1028 list_for_each_entry_safe(piocb, next_iocb,
1029 &pring->txcmplq, list)
1030 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
1031 list_splice_init(&pring->txcmplq, &completions);
1032 pring->txcmplq_cnt = 0;
1033 spin_unlock_irq(&pring->ring_lock);
1034 lpfc_sli_abort_iocb_ring(phba, pring);
1036 /* Cancel all the IOCBs from the completions list */
1037 lpfc_sli_cancel_iocbs(phba, &completions,
1038 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1042 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1043 * @phba: pointer to lpfc HBA data structure.
1045 * This routine will do uninitialization after the HBA is reset when bring
1046 * down the SLI Layer.
1050 * Any other value - error.
1053 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1055 lpfc_hba_free_post_buf(phba);
1056 lpfc_hba_clean_txcmplq(phba);
1061 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1062 * @phba: pointer to lpfc HBA data structure.
1064 * This routine will do uninitialization after the HBA is reset when bring
1065 * down the SLI Layer.
1069 * Any other value - error.
1072 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1074 struct lpfc_io_buf *psb, *psb_next;
1075 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
1076 struct lpfc_sli4_hdw_queue *qp;
1078 LIST_HEAD(nvme_aborts);
1079 LIST_HEAD(nvmet_aborts);
1080 struct lpfc_sglq *sglq_entry = NULL;
1084 lpfc_sli_hbqbuf_free_all(phba);
1085 lpfc_hba_clean_txcmplq(phba);
1087 /* At this point in time the HBA is either reset or DOA. Either
1088 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1089 * on the lpfc_els_sgl_list so that it can either be freed if the
1090 * driver is unloading or reposted if the driver is restarting
1094 /* sgl_list_lock required because worker thread uses this
1097 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
1098 list_for_each_entry(sglq_entry,
1099 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1100 sglq_entry->state = SGL_FREED;
1102 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1103 &phba->sli4_hba.lpfc_els_sgl_list);
1106 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
1108 /* abts_xxxx_buf_list_lock required because worker thread uses this
1111 spin_lock_irq(&phba->hbalock);
1113 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1114 qp = &phba->sli4_hba.hdwq[idx];
1116 spin_lock(&qp->abts_io_buf_list_lock);
1117 list_splice_init(&qp->lpfc_abts_io_buf_list,
1120 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1122 psb->status = IOSTAT_SUCCESS;
1125 spin_lock(&qp->io_buf_list_put_lock);
1126 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1127 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1128 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1129 qp->abts_scsi_io_bufs = 0;
1130 qp->abts_nvme_io_bufs = 0;
1131 spin_unlock(&qp->io_buf_list_put_lock);
1132 spin_unlock(&qp->abts_io_buf_list_lock);
1134 spin_unlock_irq(&phba->hbalock);
1136 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1137 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1138 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1140 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1141 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1142 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
1143 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1147 lpfc_sli4_free_sp_events(phba);
1152 * lpfc_hba_down_post - Wrapper func for hba down post routine
1153 * @phba: pointer to lpfc HBA data structure.
1155 * This routine wraps the actual SLI3 or SLI4 routine for performing
1156 * uninitialization after the HBA is reset when bring down the SLI Layer.
1160 * Any other value - error.
1163 lpfc_hba_down_post(struct lpfc_hba *phba)
1165 return (*phba->lpfc_hba_down_post)(phba);
1169 * lpfc_hb_timeout - The HBA-timer timeout handler
1170 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1172 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1173 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1174 * work-port-events bitmap and the worker thread is notified. This timeout
1175 * event will be used by the worker thread to invoke the actual timeout
1176 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1177 * be performed in the timeout handler and the HBA timeout event bit shall
1178 * be cleared by the worker thread after it has taken the event bitmap out.
1181 lpfc_hb_timeout(struct timer_list *t)
1183 struct lpfc_hba *phba;
1184 uint32_t tmo_posted;
1185 unsigned long iflag;
1187 phba = from_timer(phba, t, hb_tmofunc);
1189 /* Check for heart beat timeout conditions */
1190 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1191 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1193 phba->pport->work_port_events |= WORKER_HB_TMO;
1194 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1196 /* Tell the worker thread there is work to do */
1198 lpfc_worker_wake_up(phba);
1203 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1204 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1206 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1207 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1208 * work-port-events bitmap and the worker thread is notified. This timeout
1209 * event will be used by the worker thread to invoke the actual timeout
1210 * handler routine, lpfc_rrq_handler. Any periodical operations will
1211 * be performed in the timeout handler and the RRQ timeout event bit shall
1212 * be cleared by the worker thread after it has taken the event bitmap out.
1215 lpfc_rrq_timeout(struct timer_list *t)
1217 struct lpfc_hba *phba;
1218 unsigned long iflag;
1220 phba = from_timer(phba, t, rrq_tmr);
1221 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1222 if (!(phba->pport->load_flag & FC_UNLOADING))
1223 phba->hba_flag |= HBA_RRQ_ACTIVE;
1225 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1226 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1228 if (!(phba->pport->load_flag & FC_UNLOADING))
1229 lpfc_worker_wake_up(phba);
1233 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1234 * @phba: pointer to lpfc hba data structure.
1235 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1237 * This is the callback function to the lpfc heart-beat mailbox command.
1238 * If configured, the lpfc driver issues the heart-beat mailbox command to
1239 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1240 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1241 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1242 * heart-beat outstanding state. Once the mailbox command comes back and
1243 * no error conditions detected, the heart-beat mailbox command timer is
1244 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1245 * state is cleared for the next heart-beat. If the timer expired with the
1246 * heart-beat outstanding state set, the driver will put the HBA offline.
1249 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1251 unsigned long drvr_flag;
1253 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1254 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
1255 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1257 /* Check and reset heart-beat timer if necessary */
1258 mempool_free(pmboxq, phba->mbox_mem_pool);
1259 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1260 !(phba->link_state == LPFC_HBA_ERROR) &&
1261 !(phba->pport->load_flag & FC_UNLOADING))
1262 mod_timer(&phba->hb_tmofunc,
1264 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1269 * lpfc_idle_stat_delay_work - idle_stat tracking
1271 * This routine tracks per-cq idle_stat and determines polling decisions.
1277 lpfc_idle_stat_delay_work(struct work_struct *work)
1279 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1281 idle_stat_delay_work);
1282 struct lpfc_queue *cq;
1283 struct lpfc_sli4_hdw_queue *hdwq;
1284 struct lpfc_idle_stat *idle_stat;
1285 u32 i, idle_percent;
1286 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1288 if (phba->pport->load_flag & FC_UNLOADING)
1291 if (phba->link_state == LPFC_HBA_ERROR ||
1292 phba->pport->fc_flag & FC_OFFLINE_MODE ||
1293 phba->cmf_active_mode != LPFC_CFG_OFF)
1296 for_each_present_cpu(i) {
1297 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1300 /* Skip if we've already handled this cq's primary CPU */
1304 idle_stat = &phba->sli4_hba.idle_stat[i];
1306 /* get_cpu_idle_time returns values as running counters. Thus,
1307 * to know the amount for this period, the prior counter values
1308 * need to be subtracted from the current counter values.
1309 * From there, the idle time stat can be calculated as a
1310 * percentage of 100 - the sum of the other consumption times.
1312 wall_idle = get_cpu_idle_time(i, &wall, 1);
1313 diff_idle = wall_idle - idle_stat->prev_idle;
1314 diff_wall = wall - idle_stat->prev_wall;
1316 if (diff_wall <= diff_idle)
1319 busy_time = diff_wall - diff_idle;
1321 idle_percent = div64_u64(100 * busy_time, diff_wall);
1322 idle_percent = 100 - idle_percent;
1324 if (idle_percent < 15)
1325 cq->poll_mode = LPFC_QUEUE_WORK;
1327 cq->poll_mode = LPFC_IRQ_POLL;
1329 idle_stat->prev_idle = wall_idle;
1330 idle_stat->prev_wall = wall;
1334 schedule_delayed_work(&phba->idle_stat_delay_work,
1335 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1339 lpfc_hb_eq_delay_work(struct work_struct *work)
1341 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1342 struct lpfc_hba, eq_delay_work);
1343 struct lpfc_eq_intr_info *eqi, *eqi_new;
1344 struct lpfc_queue *eq, *eq_next;
1345 unsigned char *ena_delay = NULL;
1349 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1352 if (phba->link_state == LPFC_HBA_ERROR ||
1353 phba->pport->fc_flag & FC_OFFLINE_MODE)
1356 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1361 for (i = 0; i < phba->cfg_irq_chann; i++) {
1362 /* Get the EQ corresponding to the IRQ vector */
1363 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1366 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1367 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1368 ena_delay[eq->last_cpu] = 1;
1372 for_each_present_cpu(i) {
1373 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1375 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1376 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1377 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1384 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1385 if (unlikely(eq->last_cpu != i)) {
1386 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1388 list_move_tail(&eq->cpu_list, &eqi_new->list);
1391 if (usdelay != eq->q_mode)
1392 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1400 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1401 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1405 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1406 * @phba: pointer to lpfc hba data structure.
1408 * For each heartbeat, this routine does some heuristic methods to adjust
1409 * XRI distribution. The goal is to fully utilize free XRIs.
1411 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1416 hwq_count = phba->cfg_hdw_queue;
1417 for (i = 0; i < hwq_count; i++) {
1418 /* Adjust XRIs in private pool */
1419 lpfc_adjust_pvt_pool_count(phba, i);
1421 /* Adjust high watermark */
1422 lpfc_adjust_high_watermark(phba, i);
1424 #ifdef LPFC_MXP_STAT
1425 /* Snapshot pbl, pvt and busy count */
1426 lpfc_snapshot_mxp(phba, i);
1432 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1433 * @phba: pointer to lpfc hba data structure.
1435 * If a HB mbox is not already in progrees, this routine will allocate
1436 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1437 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1440 lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1442 LPFC_MBOXQ_t *pmboxq;
1445 /* Is a Heartbeat mbox already in progress */
1446 if (phba->hba_flag & HBA_HBEAT_INP)
1449 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1453 lpfc_heart_beat(phba, pmboxq);
1454 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1455 pmboxq->vport = phba->pport;
1456 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1458 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1459 mempool_free(pmboxq, phba->mbox_mem_pool);
1462 phba->hba_flag |= HBA_HBEAT_INP;
1468 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1469 * @phba: pointer to lpfc hba data structure.
1471 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1472 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1473 * of the value of lpfc_enable_hba_heartbeat.
1474 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1475 * try to issue a MBX_HEARTBEAT mbox command.
1478 lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1480 if (phba->cfg_enable_hba_heartbeat)
1482 phba->hba_flag |= HBA_HBEAT_TMO;
1486 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1487 * @phba: pointer to lpfc hba data structure.
1489 * This is the actual HBA-timer timeout handler to be invoked by the worker
1490 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1491 * handler performs any periodic operations needed for the device. If such
1492 * periodic event has already been attended to either in the interrupt handler
1493 * or by processing slow-ring or fast-ring events within the HBA-timer
1494 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1495 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1496 * is configured and there is no heart-beat mailbox command outstanding, a
1497 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1498 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1502 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1504 struct lpfc_vport **vports;
1505 struct lpfc_dmabuf *buf_ptr;
1508 struct lpfc_sli *psli = &phba->sli;
1509 LIST_HEAD(completions);
1511 if (phba->cfg_xri_rebalancing) {
1512 /* Multi-XRI pools handler */
1513 lpfc_hb_mxp_handler(phba);
1516 vports = lpfc_create_vport_work_array(phba);
1518 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1519 lpfc_rcv_seq_check_edtov(vports[i]);
1520 lpfc_fdmi_change_check(vports[i]);
1522 lpfc_destroy_vport_work_array(phba, vports);
1524 if ((phba->link_state == LPFC_HBA_ERROR) ||
1525 (phba->pport->load_flag & FC_UNLOADING) ||
1526 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1529 if (phba->elsbuf_cnt &&
1530 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1531 spin_lock_irq(&phba->hbalock);
1532 list_splice_init(&phba->elsbuf, &completions);
1533 phba->elsbuf_cnt = 0;
1534 phba->elsbuf_prev_cnt = 0;
1535 spin_unlock_irq(&phba->hbalock);
1537 while (!list_empty(&completions)) {
1538 list_remove_head(&completions, buf_ptr,
1539 struct lpfc_dmabuf, list);
1540 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1544 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1546 /* If there is no heart beat outstanding, issue a heartbeat command */
1547 if (phba->cfg_enable_hba_heartbeat) {
1548 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1549 spin_lock_irq(&phba->pport->work_port_lock);
1550 if (time_after(phba->last_completion_time +
1551 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1553 spin_unlock_irq(&phba->pport->work_port_lock);
1554 if (phba->hba_flag & HBA_HBEAT_INP)
1555 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1557 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1560 spin_unlock_irq(&phba->pport->work_port_lock);
1562 /* Check if a MBX_HEARTBEAT is already in progress */
1563 if (phba->hba_flag & HBA_HBEAT_INP) {
1565 * If heart beat timeout called with HBA_HBEAT_INP set
1566 * we need to give the hb mailbox cmd a chance to
1569 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1570 "0459 Adapter heartbeat still outstanding: "
1571 "last compl time was %d ms.\n",
1572 jiffies_to_msecs(jiffies
1573 - phba->last_completion_time));
1574 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1576 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1577 (list_empty(&psli->mboxq))) {
1579 retval = lpfc_issue_hb_mbox(phba);
1581 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1584 phba->skipped_hb = 0;
1585 } else if (time_before_eq(phba->last_completion_time,
1586 phba->skipped_hb)) {
1587 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1588 "2857 Last completion time not "
1589 " updated in %d ms\n",
1590 jiffies_to_msecs(jiffies
1591 - phba->last_completion_time));
1593 phba->skipped_hb = jiffies;
1595 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1599 /* Check to see if we want to force a MBX_HEARTBEAT */
1600 if (phba->hba_flag & HBA_HBEAT_TMO) {
1601 retval = lpfc_issue_hb_mbox(phba);
1603 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1605 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1608 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1611 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
1615 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1616 * @phba: pointer to lpfc hba data structure.
1618 * This routine is called to bring the HBA offline when HBA hardware error
1619 * other than Port Error 6 has been detected.
1622 lpfc_offline_eratt(struct lpfc_hba *phba)
1624 struct lpfc_sli *psli = &phba->sli;
1626 spin_lock_irq(&phba->hbalock);
1627 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1628 spin_unlock_irq(&phba->hbalock);
1629 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1632 lpfc_reset_barrier(phba);
1633 spin_lock_irq(&phba->hbalock);
1634 lpfc_sli_brdreset(phba);
1635 spin_unlock_irq(&phba->hbalock);
1636 lpfc_hba_down_post(phba);
1637 lpfc_sli_brdready(phba, HS_MBRDY);
1638 lpfc_unblock_mgmt_io(phba);
1639 phba->link_state = LPFC_HBA_ERROR;
1644 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1645 * @phba: pointer to lpfc hba data structure.
1647 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1648 * other than Port Error 6 has been detected.
1651 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1653 spin_lock_irq(&phba->hbalock);
1654 if (phba->link_state == LPFC_HBA_ERROR &&
1655 phba->hba_flag & HBA_PCI_ERR) {
1656 spin_unlock_irq(&phba->hbalock);
1659 phba->link_state = LPFC_HBA_ERROR;
1660 spin_unlock_irq(&phba->hbalock);
1662 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1663 lpfc_sli_flush_io_rings(phba);
1665 lpfc_hba_down_post(phba);
1666 lpfc_unblock_mgmt_io(phba);
1670 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1671 * @phba: pointer to lpfc hba data structure.
1673 * This routine is invoked to handle the deferred HBA hardware error
1674 * conditions. This type of error is indicated by HBA by setting ER1
1675 * and another ER bit in the host status register. The driver will
1676 * wait until the ER1 bit clears before handling the error condition.
1679 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1681 uint32_t old_host_status = phba->work_hs;
1682 struct lpfc_sli *psli = &phba->sli;
1684 /* If the pci channel is offline, ignore possible errors,
1685 * since we cannot communicate with the pci card anyway.
1687 if (pci_channel_offline(phba->pcidev)) {
1688 spin_lock_irq(&phba->hbalock);
1689 phba->hba_flag &= ~DEFER_ERATT;
1690 spin_unlock_irq(&phba->hbalock);
1694 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1695 "0479 Deferred Adapter Hardware Error "
1696 "Data: x%x x%x x%x\n",
1697 phba->work_hs, phba->work_status[0],
1698 phba->work_status[1]);
1700 spin_lock_irq(&phba->hbalock);
1701 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1702 spin_unlock_irq(&phba->hbalock);
1706 * Firmware stops when it triggred erratt. That could cause the I/Os
1707 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1708 * SCSI layer retry it after re-establishing link.
1710 lpfc_sli_abort_fcp_rings(phba);
1713 * There was a firmware error. Take the hba offline and then
1714 * attempt to restart it.
1716 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1719 /* Wait for the ER1 bit to clear.*/
1720 while (phba->work_hs & HS_FFER1) {
1722 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1723 phba->work_hs = UNPLUG_ERR ;
1726 /* If driver is unloading let the worker thread continue */
1727 if (phba->pport->load_flag & FC_UNLOADING) {
1734 * This is to ptrotect against a race condition in which
1735 * first write to the host attention register clear the
1736 * host status register.
1738 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1739 phba->work_hs = old_host_status & ~HS_FFER1;
1741 spin_lock_irq(&phba->hbalock);
1742 phba->hba_flag &= ~DEFER_ERATT;
1743 spin_unlock_irq(&phba->hbalock);
1744 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1745 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1749 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1751 struct lpfc_board_event_header board_event;
1752 struct Scsi_Host *shost;
1754 board_event.event_type = FC_REG_BOARD_EVENT;
1755 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1756 shost = lpfc_shost_from_vport(phba->pport);
1757 fc_host_post_vendor_event(shost, fc_get_event_number(),
1758 sizeof(board_event),
1759 (char *) &board_event,
1764 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1765 * @phba: pointer to lpfc hba data structure.
1767 * This routine is invoked to handle the following HBA hardware error
1769 * 1 - HBA error attention interrupt
1770 * 2 - DMA ring index out of range
1771 * 3 - Mailbox command came back as unknown
1774 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1776 struct lpfc_vport *vport = phba->pport;
1777 struct lpfc_sli *psli = &phba->sli;
1778 uint32_t event_data;
1779 unsigned long temperature;
1780 struct temp_event temp_event_data;
1781 struct Scsi_Host *shost;
1783 /* If the pci channel is offline, ignore possible errors,
1784 * since we cannot communicate with the pci card anyway.
1786 if (pci_channel_offline(phba->pcidev)) {
1787 spin_lock_irq(&phba->hbalock);
1788 phba->hba_flag &= ~DEFER_ERATT;
1789 spin_unlock_irq(&phba->hbalock);
1793 /* If resets are disabled then leave the HBA alone and return */
1794 if (!phba->cfg_enable_hba_reset)
1797 /* Send an internal error event to mgmt application */
1798 lpfc_board_errevt_to_mgmt(phba);
1800 if (phba->hba_flag & DEFER_ERATT)
1801 lpfc_handle_deferred_eratt(phba);
1803 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1804 if (phba->work_hs & HS_FFER6)
1805 /* Re-establishing Link */
1806 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1807 "1301 Re-establishing Link "
1808 "Data: x%x x%x x%x\n",
1809 phba->work_hs, phba->work_status[0],
1810 phba->work_status[1]);
1811 if (phba->work_hs & HS_FFER8)
1812 /* Device Zeroization */
1813 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1814 "2861 Host Authentication device "
1815 "zeroization Data:x%x x%x x%x\n",
1816 phba->work_hs, phba->work_status[0],
1817 phba->work_status[1]);
1819 spin_lock_irq(&phba->hbalock);
1820 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1821 spin_unlock_irq(&phba->hbalock);
1824 * Firmware stops when it triggled erratt with HS_FFER6.
1825 * That could cause the I/Os dropped by the firmware.
1826 * Error iocb (I/O) on txcmplq and let the SCSI layer
1827 * retry it after re-establishing link.
1829 lpfc_sli_abort_fcp_rings(phba);
1832 * There was a firmware error. Take the hba offline and then
1833 * attempt to restart it.
1835 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1837 lpfc_sli_brdrestart(phba);
1838 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1839 lpfc_unblock_mgmt_io(phba);
1842 lpfc_unblock_mgmt_io(phba);
1843 } else if (phba->work_hs & HS_CRIT_TEMP) {
1844 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1845 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1846 temp_event_data.event_code = LPFC_CRIT_TEMP;
1847 temp_event_data.data = (uint32_t)temperature;
1849 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1850 "0406 Adapter maximum temperature exceeded "
1851 "(%ld), taking this port offline "
1852 "Data: x%x x%x x%x\n",
1853 temperature, phba->work_hs,
1854 phba->work_status[0], phba->work_status[1]);
1856 shost = lpfc_shost_from_vport(phba->pport);
1857 fc_host_post_vendor_event(shost, fc_get_event_number(),
1858 sizeof(temp_event_data),
1859 (char *) &temp_event_data,
1860 SCSI_NL_VID_TYPE_PCI
1861 | PCI_VENDOR_ID_EMULEX);
1863 spin_lock_irq(&phba->hbalock);
1864 phba->over_temp_state = HBA_OVER_TEMP;
1865 spin_unlock_irq(&phba->hbalock);
1866 lpfc_offline_eratt(phba);
1869 /* The if clause above forces this code path when the status
1870 * failure is a value other than FFER6. Do not call the offline
1871 * twice. This is the adapter hardware error path.
1873 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1874 "0457 Adapter Hardware Error "
1875 "Data: x%x x%x x%x\n",
1877 phba->work_status[0], phba->work_status[1]);
1879 event_data = FC_REG_DUMP_EVENT;
1880 shost = lpfc_shost_from_vport(vport);
1881 fc_host_post_vendor_event(shost, fc_get_event_number(),
1882 sizeof(event_data), (char *) &event_data,
1883 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1885 lpfc_offline_eratt(phba);
1891 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1892 * @phba: pointer to lpfc hba data structure.
1893 * @mbx_action: flag for mailbox shutdown action.
1894 * @en_rn_msg: send reset/port recovery message.
1895 * This routine is invoked to perform an SLI4 port PCI function reset in
1896 * response to port status register polling attention. It waits for port
1897 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1898 * During this process, interrupt vectors are freed and later requested
1899 * for handling possible port resource change.
1902 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1907 LPFC_MBOXQ_t *mboxq;
1909 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1910 LPFC_SLI_INTF_IF_TYPE_2) {
1912 * On error status condition, driver need to wait for port
1913 * ready before performing reset.
1915 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1920 /* need reset: attempt for port recovery */
1922 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1923 "2887 Reset Needed: Attempting Port "
1926 /* If we are no wait, the HBA has been reset and is not
1927 * functional, thus we should clear
1928 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
1930 if (mbx_action == LPFC_MBX_NO_WAIT) {
1931 spin_lock_irq(&phba->hbalock);
1932 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
1933 if (phba->sli.mbox_active) {
1934 mboxq = phba->sli.mbox_active;
1935 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1936 __lpfc_mbox_cmpl_put(phba, mboxq);
1937 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1938 phba->sli.mbox_active = NULL;
1940 spin_unlock_irq(&phba->hbalock);
1943 lpfc_offline_prep(phba, mbx_action);
1944 lpfc_sli_flush_io_rings(phba);
1946 /* release interrupt for possible resource change */
1947 lpfc_sli4_disable_intr(phba);
1948 rc = lpfc_sli_brdrestart(phba);
1950 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1951 "6309 Failed to restart board\n");
1954 /* request and enable interrupt */
1955 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1956 if (intr_mode == LPFC_INTR_ERROR) {
1957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1958 "3175 Failed to enable interrupt\n");
1961 phba->intr_mode = intr_mode;
1962 rc = lpfc_online(phba);
1964 lpfc_unblock_mgmt_io(phba);
1970 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1971 * @phba: pointer to lpfc hba data structure.
1973 * This routine is invoked to handle the SLI4 HBA hardware error attention
1977 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1979 struct lpfc_vport *vport = phba->pport;
1980 uint32_t event_data;
1981 struct Scsi_Host *shost;
1983 struct lpfc_register portstat_reg = {0};
1984 uint32_t reg_err1, reg_err2;
1985 uint32_t uerrlo_reg, uemasklo_reg;
1986 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1987 bool en_rn_msg = true;
1988 struct temp_event temp_event_data;
1989 struct lpfc_register portsmphr_reg;
1992 /* If the pci channel is offline, ignore possible errors, since
1993 * we cannot communicate with the pci card anyway.
1995 if (pci_channel_offline(phba->pcidev)) {
1996 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1997 "3166 pci channel is offline\n");
2001 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
2002 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2004 case LPFC_SLI_INTF_IF_TYPE_0:
2005 pci_rd_rc1 = lpfc_readl(
2006 phba->sli4_hba.u.if_type0.UERRLOregaddr,
2008 pci_rd_rc2 = lpfc_readl(
2009 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
2011 /* consider PCI bus read error as pci_channel_offline */
2012 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
2014 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
2015 lpfc_sli4_offline_eratt(phba);
2018 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2019 "7623 Checking UE recoverable");
2021 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
2022 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2023 &portsmphr_reg.word0))
2026 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
2028 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2029 LPFC_PORT_SEM_UE_RECOVERABLE)
2031 /*Sleep for 1Sec, before checking SEMAPHORE */
2035 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2036 "4827 smphr_port_status x%x : Waited %dSec",
2037 smphr_port_status, i);
2039 /* Recoverable UE, reset the HBA device */
2040 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2041 LPFC_PORT_SEM_UE_RECOVERABLE) {
2042 for (i = 0; i < 20; i++) {
2044 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2045 &portsmphr_reg.word0) &&
2046 (LPFC_POST_STAGE_PORT_READY ==
2047 bf_get(lpfc_port_smphr_port_status,
2049 rc = lpfc_sli4_port_sta_fn_reset(phba,
2050 LPFC_MBX_NO_WAIT, en_rn_msg);
2053 lpfc_printf_log(phba, KERN_ERR,
2055 "4215 Failed to recover UE");
2060 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2061 "7624 Firmware not ready: Failing UE recovery,"
2062 " waited %dSec", i);
2063 phba->link_state = LPFC_HBA_ERROR;
2066 case LPFC_SLI_INTF_IF_TYPE_2:
2067 case LPFC_SLI_INTF_IF_TYPE_6:
2068 pci_rd_rc1 = lpfc_readl(
2069 phba->sli4_hba.u.if_type2.STATUSregaddr,
2070 &portstat_reg.word0);
2071 /* consider PCI bus read error as pci_channel_offline */
2072 if (pci_rd_rc1 == -EIO) {
2073 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2074 "3151 PCI bus read access failure: x%x\n",
2075 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
2076 lpfc_sli4_offline_eratt(phba);
2079 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2080 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
2081 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
2082 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2083 "2889 Port Overtemperature event, "
2084 "taking port offline Data: x%x x%x\n",
2085 reg_err1, reg_err2);
2087 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
2088 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2089 temp_event_data.event_code = LPFC_CRIT_TEMP;
2090 temp_event_data.data = 0xFFFFFFFF;
2092 shost = lpfc_shost_from_vport(phba->pport);
2093 fc_host_post_vendor_event(shost, fc_get_event_number(),
2094 sizeof(temp_event_data),
2095 (char *)&temp_event_data,
2096 SCSI_NL_VID_TYPE_PCI
2097 | PCI_VENDOR_ID_EMULEX);
2099 spin_lock_irq(&phba->hbalock);
2100 phba->over_temp_state = HBA_OVER_TEMP;
2101 spin_unlock_irq(&phba->hbalock);
2102 lpfc_sli4_offline_eratt(phba);
2105 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2106 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
2107 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2108 "3143 Port Down: Firmware Update "
2111 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2112 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2113 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2114 "3144 Port Down: Debug Dump\n");
2115 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2116 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
2117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2118 "3145 Port Down: Provisioning\n");
2120 /* If resets are disabled then leave the HBA alone and return */
2121 if (!phba->cfg_enable_hba_reset)
2124 /* Check port status register for function reset */
2125 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2128 /* don't report event on forced debug dump */
2129 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2130 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2135 /* fall through for not able to recover */
2136 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2137 "3152 Unrecoverable error\n");
2138 phba->link_state = LPFC_HBA_ERROR;
2140 case LPFC_SLI_INTF_IF_TYPE_1:
2144 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2145 "3123 Report dump event to upper layer\n");
2146 /* Send an internal error event to mgmt application */
2147 lpfc_board_errevt_to_mgmt(phba);
2149 event_data = FC_REG_DUMP_EVENT;
2150 shost = lpfc_shost_from_vport(vport);
2151 fc_host_post_vendor_event(shost, fc_get_event_number(),
2152 sizeof(event_data), (char *) &event_data,
2153 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2157 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2158 * @phba: pointer to lpfc HBA data structure.
2160 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2161 * routine from the API jump table function pointer from the lpfc_hba struct.
2165 * Any other value - error.
2168 lpfc_handle_eratt(struct lpfc_hba *phba)
2170 (*phba->lpfc_handle_eratt)(phba);
2174 * lpfc_handle_latt - The HBA link event handler
2175 * @phba: pointer to lpfc hba data structure.
2177 * This routine is invoked from the worker thread to handle a HBA host
2178 * attention link event. SLI3 only.
2181 lpfc_handle_latt(struct lpfc_hba *phba)
2183 struct lpfc_vport *vport = phba->pport;
2184 struct lpfc_sli *psli = &phba->sli;
2186 volatile uint32_t control;
2187 struct lpfc_dmabuf *mp;
2190 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2193 goto lpfc_handle_latt_err_exit;
2196 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2199 goto lpfc_handle_latt_free_pmb;
2202 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2205 goto lpfc_handle_latt_free_mp;
2208 /* Cleanup any outstanding ELS commands */
2209 lpfc_els_flush_all_cmd(phba);
2211 psli->slistat.link_event++;
2212 lpfc_read_topology(phba, pmb, mp);
2213 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2215 /* Block ELS IOCBs until we have processed this mbox command */
2216 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2217 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2218 if (rc == MBX_NOT_FINISHED) {
2220 goto lpfc_handle_latt_free_mbuf;
2223 /* Clear Link Attention in HA REG */
2224 spin_lock_irq(&phba->hbalock);
2225 writel(HA_LATT, phba->HAregaddr);
2226 readl(phba->HAregaddr); /* flush */
2227 spin_unlock_irq(&phba->hbalock);
2231 lpfc_handle_latt_free_mbuf:
2232 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2234 lpfc_handle_latt_free_mp:
2236 lpfc_handle_latt_free_pmb:
2237 mempool_free(pmb, phba->mbox_mem_pool);
2238 lpfc_handle_latt_err_exit:
2239 /* Enable Link attention interrupts */
2240 spin_lock_irq(&phba->hbalock);
2241 psli->sli_flag |= LPFC_PROCESS_LA;
2242 control = readl(phba->HCregaddr);
2243 control |= HC_LAINT_ENA;
2244 writel(control, phba->HCregaddr);
2245 readl(phba->HCregaddr); /* flush */
2247 /* Clear Link Attention in HA REG */
2248 writel(HA_LATT, phba->HAregaddr);
2249 readl(phba->HAregaddr); /* flush */
2250 spin_unlock_irq(&phba->hbalock);
2251 lpfc_linkdown(phba);
2252 phba->link_state = LPFC_HBA_ERROR;
2254 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2255 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2261 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2262 * @phba: pointer to lpfc hba data structure.
2263 * @vpd: pointer to the vital product data.
2264 * @len: length of the vital product data in bytes.
2266 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2267 * an array of characters. In this routine, the ModelName, ProgramType, and
2268 * ModelDesc, etc. fields of the phba data structure will be populated.
2271 * 0 - pointer to the VPD passed in is NULL
2275 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2277 uint8_t lenlo, lenhi;
2287 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2288 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2289 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2291 while (!finished && (index < (len - 4))) {
2292 switch (vpd[index]) {
2300 i = ((((unsigned short)lenhi) << 8) + lenlo);
2309 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2310 if (Length > len - index)
2311 Length = len - index;
2312 while (Length > 0) {
2313 /* Look for Serial Number */
2314 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2321 phba->SerialNumber[j++] = vpd[index++];
2325 phba->SerialNumber[j] = 0;
2328 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2329 phba->vpd_flag |= VPD_MODEL_DESC;
2336 phba->ModelDesc[j++] = vpd[index++];
2340 phba->ModelDesc[j] = 0;
2343 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2344 phba->vpd_flag |= VPD_MODEL_NAME;
2351 phba->ModelName[j++] = vpd[index++];
2355 phba->ModelName[j] = 0;
2358 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2359 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2366 phba->ProgramType[j++] = vpd[index++];
2370 phba->ProgramType[j] = 0;
2373 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2374 phba->vpd_flag |= VPD_PORT;
2381 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2382 (phba->sli4_hba.pport_name_sta ==
2383 LPFC_SLI4_PPNAME_GET)) {
2387 phba->Port[j++] = vpd[index++];
2391 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2392 (phba->sli4_hba.pport_name_sta ==
2393 LPFC_SLI4_PPNAME_NON))
2420 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2421 * @phba: pointer to lpfc hba data structure.
2422 * @mdp: pointer to the data structure to hold the derived model name.
2423 * @descp: pointer to the data structure to hold the derived description.
2425 * This routine retrieves HBA's description based on its registered PCI device
2426 * ID. The @descp passed into this function points to an array of 256 chars. It
2427 * shall be returned with the model name, maximum speed, and the host bus type.
2428 * The @mdp passed into this function points to an array of 80 chars. When the
2429 * function returns, the @mdp will be filled with the model name.
2432 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2435 uint16_t dev_id = phba->pcidev->device;
2438 int oneConnect = 0; /* default is not a oneConnect */
2443 } m = {"<Unknown>", "", ""};
2445 if (mdp && mdp[0] != '\0'
2446 && descp && descp[0] != '\0')
2449 if (phba->lmt & LMT_64Gb)
2451 else if (phba->lmt & LMT_32Gb)
2453 else if (phba->lmt & LMT_16Gb)
2455 else if (phba->lmt & LMT_10Gb)
2457 else if (phba->lmt & LMT_8Gb)
2459 else if (phba->lmt & LMT_4Gb)
2461 else if (phba->lmt & LMT_2Gb)
2463 else if (phba->lmt & LMT_1Gb)
2471 case PCI_DEVICE_ID_FIREFLY:
2472 m = (typeof(m)){"LP6000", "PCI",
2473 "Obsolete, Unsupported Fibre Channel Adapter"};
2475 case PCI_DEVICE_ID_SUPERFLY:
2476 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2477 m = (typeof(m)){"LP7000", "PCI", ""};
2479 m = (typeof(m)){"LP7000E", "PCI", ""};
2480 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2482 case PCI_DEVICE_ID_DRAGONFLY:
2483 m = (typeof(m)){"LP8000", "PCI",
2484 "Obsolete, Unsupported Fibre Channel Adapter"};
2486 case PCI_DEVICE_ID_CENTAUR:
2487 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2488 m = (typeof(m)){"LP9002", "PCI", ""};
2490 m = (typeof(m)){"LP9000", "PCI", ""};
2491 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2493 case PCI_DEVICE_ID_RFLY:
2494 m = (typeof(m)){"LP952", "PCI",
2495 "Obsolete, Unsupported Fibre Channel Adapter"};
2497 case PCI_DEVICE_ID_PEGASUS:
2498 m = (typeof(m)){"LP9802", "PCI-X",
2499 "Obsolete, Unsupported Fibre Channel Adapter"};
2501 case PCI_DEVICE_ID_THOR:
2502 m = (typeof(m)){"LP10000", "PCI-X",
2503 "Obsolete, Unsupported Fibre Channel Adapter"};
2505 case PCI_DEVICE_ID_VIPER:
2506 m = (typeof(m)){"LPX1000", "PCI-X",
2507 "Obsolete, Unsupported Fibre Channel Adapter"};
2509 case PCI_DEVICE_ID_PFLY:
2510 m = (typeof(m)){"LP982", "PCI-X",
2511 "Obsolete, Unsupported Fibre Channel Adapter"};
2513 case PCI_DEVICE_ID_TFLY:
2514 m = (typeof(m)){"LP1050", "PCI-X",
2515 "Obsolete, Unsupported Fibre Channel Adapter"};
2517 case PCI_DEVICE_ID_HELIOS:
2518 m = (typeof(m)){"LP11000", "PCI-X2",
2519 "Obsolete, Unsupported Fibre Channel Adapter"};
2521 case PCI_DEVICE_ID_HELIOS_SCSP:
2522 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2523 "Obsolete, Unsupported Fibre Channel Adapter"};
2525 case PCI_DEVICE_ID_HELIOS_DCSP:
2526 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2527 "Obsolete, Unsupported Fibre Channel Adapter"};
2529 case PCI_DEVICE_ID_NEPTUNE:
2530 m = (typeof(m)){"LPe1000", "PCIe",
2531 "Obsolete, Unsupported Fibre Channel Adapter"};
2533 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2534 m = (typeof(m)){"LPe1000-SP", "PCIe",
2535 "Obsolete, Unsupported Fibre Channel Adapter"};
2537 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2538 m = (typeof(m)){"LPe1002-SP", "PCIe",
2539 "Obsolete, Unsupported Fibre Channel Adapter"};
2541 case PCI_DEVICE_ID_BMID:
2542 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2544 case PCI_DEVICE_ID_BSMB:
2545 m = (typeof(m)){"LP111", "PCI-X2",
2546 "Obsolete, Unsupported Fibre Channel Adapter"};
2548 case PCI_DEVICE_ID_ZEPHYR:
2549 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2551 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2552 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2554 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2555 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2558 case PCI_DEVICE_ID_ZMID:
2559 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2561 case PCI_DEVICE_ID_ZSMB:
2562 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2564 case PCI_DEVICE_ID_LP101:
2565 m = (typeof(m)){"LP101", "PCI-X",
2566 "Obsolete, Unsupported Fibre Channel Adapter"};
2568 case PCI_DEVICE_ID_LP10000S:
2569 m = (typeof(m)){"LP10000-S", "PCI",
2570 "Obsolete, Unsupported Fibre Channel Adapter"};
2572 case PCI_DEVICE_ID_LP11000S:
2573 m = (typeof(m)){"LP11000-S", "PCI-X2",
2574 "Obsolete, Unsupported Fibre Channel Adapter"};
2576 case PCI_DEVICE_ID_LPE11000S:
2577 m = (typeof(m)){"LPe11000-S", "PCIe",
2578 "Obsolete, Unsupported Fibre Channel Adapter"};
2580 case PCI_DEVICE_ID_SAT:
2581 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2583 case PCI_DEVICE_ID_SAT_MID:
2584 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2586 case PCI_DEVICE_ID_SAT_SMB:
2587 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2589 case PCI_DEVICE_ID_SAT_DCSP:
2590 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2592 case PCI_DEVICE_ID_SAT_SCSP:
2593 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2595 case PCI_DEVICE_ID_SAT_S:
2596 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2598 case PCI_DEVICE_ID_HORNET:
2599 m = (typeof(m)){"LP21000", "PCIe",
2600 "Obsolete, Unsupported FCoE Adapter"};
2603 case PCI_DEVICE_ID_PROTEUS_VF:
2604 m = (typeof(m)){"LPev12000", "PCIe IOV",
2605 "Obsolete, Unsupported Fibre Channel Adapter"};
2607 case PCI_DEVICE_ID_PROTEUS_PF:
2608 m = (typeof(m)){"LPev12000", "PCIe IOV",
2609 "Obsolete, Unsupported Fibre Channel Adapter"};
2611 case PCI_DEVICE_ID_PROTEUS_S:
2612 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2613 "Obsolete, Unsupported Fibre Channel Adapter"};
2615 case PCI_DEVICE_ID_TIGERSHARK:
2617 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2619 case PCI_DEVICE_ID_TOMCAT:
2621 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2623 case PCI_DEVICE_ID_FALCON:
2624 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2625 "EmulexSecure Fibre"};
2627 case PCI_DEVICE_ID_BALIUS:
2628 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2629 "Obsolete, Unsupported Fibre Channel Adapter"};
2631 case PCI_DEVICE_ID_LANCER_FC:
2632 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2634 case PCI_DEVICE_ID_LANCER_FC_VF:
2635 m = (typeof(m)){"LPe16000", "PCIe",
2636 "Obsolete, Unsupported Fibre Channel Adapter"};
2638 case PCI_DEVICE_ID_LANCER_FCOE:
2640 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2642 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2644 m = (typeof(m)){"OCe15100", "PCIe",
2645 "Obsolete, Unsupported FCoE"};
2647 case PCI_DEVICE_ID_LANCER_G6_FC:
2648 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2650 case PCI_DEVICE_ID_LANCER_G7_FC:
2651 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2653 case PCI_DEVICE_ID_LANCER_G7P_FC:
2654 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2656 case PCI_DEVICE_ID_SKYHAWK:
2657 case PCI_DEVICE_ID_SKYHAWK_VF:
2659 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2662 m = (typeof(m)){"Unknown", "", ""};
2666 if (mdp && mdp[0] == '\0')
2667 snprintf(mdp, 79,"%s", m.name);
2669 * oneConnect hba requires special processing, they are all initiators
2670 * and we put the port number on the end
2672 if (descp && descp[0] == '\0') {
2674 snprintf(descp, 255,
2675 "Emulex OneConnect %s, %s Initiator %s",
2678 else if (max_speed == 0)
2679 snprintf(descp, 255,
2681 m.name, m.bus, m.function);
2683 snprintf(descp, 255,
2684 "Emulex %s %d%s %s %s",
2685 m.name, max_speed, (GE) ? "GE" : "Gb",
2691 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2692 * @phba: pointer to lpfc hba data structure.
2693 * @pring: pointer to a IOCB ring.
2694 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2696 * This routine posts a given number of IOCBs with the associated DMA buffer
2697 * descriptors specified by the cnt argument to the given IOCB ring.
2700 * The number of IOCBs NOT able to be posted to the IOCB ring.
2703 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2706 struct lpfc_iocbq *iocb;
2707 struct lpfc_dmabuf *mp1, *mp2;
2709 cnt += pring->missbufcnt;
2711 /* While there are buffers to post */
2713 /* Allocate buffer for command iocb */
2714 iocb = lpfc_sli_get_iocbq(phba);
2716 pring->missbufcnt = cnt;
2721 /* 2 buffers can be posted per command */
2722 /* Allocate buffer to post */
2723 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2725 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2726 if (!mp1 || !mp1->virt) {
2728 lpfc_sli_release_iocbq(phba, iocb);
2729 pring->missbufcnt = cnt;
2733 INIT_LIST_HEAD(&mp1->list);
2734 /* Allocate buffer to post */
2736 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2738 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2740 if (!mp2 || !mp2->virt) {
2742 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2744 lpfc_sli_release_iocbq(phba, iocb);
2745 pring->missbufcnt = cnt;
2749 INIT_LIST_HEAD(&mp2->list);
2754 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2755 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2756 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2757 icmd->ulpBdeCount = 1;
2760 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2761 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2762 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2764 icmd->ulpBdeCount = 2;
2767 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2770 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2772 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2776 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2780 lpfc_sli_release_iocbq(phba, iocb);
2781 pring->missbufcnt = cnt;
2784 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2786 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2788 pring->missbufcnt = 0;
2793 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2794 * @phba: pointer to lpfc hba data structure.
2796 * This routine posts initial receive IOCB buffers to the ELS ring. The
2797 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2798 * set to 64 IOCBs. SLI3 only.
2801 * 0 - success (currently always success)
2804 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2806 struct lpfc_sli *psli = &phba->sli;
2808 /* Ring 0, ELS / CT buffers */
2809 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2810 /* Ring 2 - FCP no buffers needed */
2815 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2818 * lpfc_sha_init - Set up initial array of hash table entries
2819 * @HashResultPointer: pointer to an array as hash table.
2821 * This routine sets up the initial values to the array of hash table entries
2825 lpfc_sha_init(uint32_t * HashResultPointer)
2827 HashResultPointer[0] = 0x67452301;
2828 HashResultPointer[1] = 0xEFCDAB89;
2829 HashResultPointer[2] = 0x98BADCFE;
2830 HashResultPointer[3] = 0x10325476;
2831 HashResultPointer[4] = 0xC3D2E1F0;
2835 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2836 * @HashResultPointer: pointer to an initial/result hash table.
2837 * @HashWorkingPointer: pointer to an working hash table.
2839 * This routine iterates an initial hash table pointed by @HashResultPointer
2840 * with the values from the working hash table pointeed by @HashWorkingPointer.
2841 * The results are putting back to the initial hash table, returned through
2842 * the @HashResultPointer as the result hash table.
2845 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2849 uint32_t A, B, C, D, E;
2852 HashWorkingPointer[t] =
2854 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2856 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2857 } while (++t <= 79);
2859 A = HashResultPointer[0];
2860 B = HashResultPointer[1];
2861 C = HashResultPointer[2];
2862 D = HashResultPointer[3];
2863 E = HashResultPointer[4];
2867 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2868 } else if (t < 40) {
2869 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2870 } else if (t < 60) {
2871 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2873 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2875 TEMP += S(5, A) + E + HashWorkingPointer[t];
2881 } while (++t <= 79);
2883 HashResultPointer[0] += A;
2884 HashResultPointer[1] += B;
2885 HashResultPointer[2] += C;
2886 HashResultPointer[3] += D;
2887 HashResultPointer[4] += E;
2892 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2893 * @RandomChallenge: pointer to the entry of host challenge random number array.
2894 * @HashWorking: pointer to the entry of the working hash array.
2896 * This routine calculates the working hash array referred by @HashWorking
2897 * from the challenge random numbers associated with the host, referred by
2898 * @RandomChallenge. The result is put into the entry of the working hash
2899 * array and returned by reference through @HashWorking.
2902 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2904 *HashWorking = (*RandomChallenge ^ *HashWorking);
2908 * lpfc_hba_init - Perform special handling for LC HBA initialization
2909 * @phba: pointer to lpfc hba data structure.
2910 * @hbainit: pointer to an array of unsigned 32-bit integers.
2912 * This routine performs the special handling for LC HBA initialization.
2915 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2918 uint32_t *HashWorking;
2919 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2921 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2925 HashWorking[0] = HashWorking[78] = *pwwnn++;
2926 HashWorking[1] = HashWorking[79] = *pwwnn;
2928 for (t = 0; t < 7; t++)
2929 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2931 lpfc_sha_init(hbainit);
2932 lpfc_sha_iterate(hbainit, HashWorking);
2937 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2938 * @vport: pointer to a virtual N_Port data structure.
2940 * This routine performs the necessary cleanups before deleting the @vport.
2941 * It invokes the discovery state machine to perform necessary state
2942 * transitions and to release the ndlps associated with the @vport. Note,
2943 * the physical port is treated as @vport 0.
2946 lpfc_cleanup(struct lpfc_vport *vport)
2948 struct lpfc_hba *phba = vport->phba;
2949 struct lpfc_nodelist *ndlp, *next_ndlp;
2952 if (phba->link_state > LPFC_LINK_DOWN)
2953 lpfc_port_link_failure(vport);
2955 /* Clean up VMID resources */
2956 if (lpfc_is_vmid_enabled(phba))
2957 lpfc_vmid_vport_cleanup(vport);
2959 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2960 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2961 ndlp->nlp_DID == Fabric_DID) {
2962 /* Just free up ndlp with Fabric_DID for vports */
2967 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
2968 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2973 /* Fabric Ports not in UNMAPPED state are cleaned up in the
2976 if (ndlp->nlp_type & NLP_FABRIC &&
2977 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
2978 lpfc_disc_state_machine(vport, ndlp, NULL,
2979 NLP_EVT_DEVICE_RECOVERY);
2981 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
2982 lpfc_disc_state_machine(vport, ndlp, NULL,
2986 /* At this point, ALL ndlp's should be gone
2987 * because of the previous NLP_EVT_DEVICE_RM.
2988 * Lets wait for this to happen, if needed.
2990 while (!list_empty(&vport->fc_nodes)) {
2992 lpfc_printf_vlog(vport, KERN_ERR,
2994 "0233 Nodelist not empty\n");
2995 list_for_each_entry_safe(ndlp, next_ndlp,
2996 &vport->fc_nodes, nlp_listp) {
2997 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2999 "0282 did:x%x ndlp:x%px "
3000 "refcnt:%d xflags x%x nflag x%x\n",
3001 ndlp->nlp_DID, (void *)ndlp,
3002 kref_read(&ndlp->kref),
3003 ndlp->fc4_xpt_flags,
3009 /* Wait for any activity on ndlps to settle */
3012 lpfc_cleanup_vports_rrqs(vport, NULL);
3016 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
3017 * @vport: pointer to a virtual N_Port data structure.
3019 * This routine stops all the timers associated with a @vport. This function
3020 * is invoked before disabling or deleting a @vport. Note that the physical
3021 * port is treated as @vport 0.
3024 lpfc_stop_vport_timers(struct lpfc_vport *vport)
3026 del_timer_sync(&vport->els_tmofunc);
3027 del_timer_sync(&vport->delayed_disc_tmo);
3028 lpfc_can_disctmo(vport);
3033 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3034 * @phba: pointer to lpfc hba data structure.
3036 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
3037 * caller of this routine should already hold the host lock.
3040 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3042 /* Clear pending FCF rediscovery wait flag */
3043 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3045 /* Now, try to stop the timer */
3046 del_timer(&phba->fcf.redisc_wait);
3050 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3051 * @phba: pointer to lpfc hba data structure.
3053 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3054 * checks whether the FCF rediscovery wait timer is pending with the host
3055 * lock held before proceeding with disabling the timer and clearing the
3056 * wait timer pendig flag.
3059 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3061 spin_lock_irq(&phba->hbalock);
3062 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3063 /* FCF rediscovery timer already fired or stopped */
3064 spin_unlock_irq(&phba->hbalock);
3067 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3068 /* Clear failover in progress flags */
3069 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
3070 spin_unlock_irq(&phba->hbalock);
3074 * lpfc_cmf_stop - Stop CMF processing
3075 * @phba: pointer to lpfc hba data structure.
3077 * This is called when the link goes down or if CMF mode is turned OFF.
3078 * It is also called when going offline or unloaded just before the
3079 * congestion info buffer is unregistered.
3082 lpfc_cmf_stop(struct lpfc_hba *phba)
3085 struct lpfc_cgn_stat *cgs;
3087 /* We only do something if CMF is enabled */
3088 if (!phba->sli4_hba.pc_sli4_params.cmf)
3091 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3092 "6221 Stop CMF / Cancel Timer\n");
3094 /* Cancel the CMF timer */
3095 hrtimer_cancel(&phba->cmf_timer);
3097 /* Zero CMF counters */
3098 atomic_set(&phba->cmf_busy, 0);
3099 for_each_present_cpu(cpu) {
3100 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3101 atomic64_set(&cgs->total_bytes, 0);
3102 atomic64_set(&cgs->rcv_bytes, 0);
3103 atomic_set(&cgs->rx_io_cnt, 0);
3104 atomic64_set(&cgs->rx_latency, 0);
3106 atomic_set(&phba->cmf_bw_wait, 0);
3108 /* Resume any blocked IO - Queue unblock on workqueue */
3109 queue_work(phba->wq, &phba->unblock_request_work);
3112 static inline uint64_t
3113 lpfc_get_max_line_rate(struct lpfc_hba *phba)
3115 uint64_t rate = lpfc_sli_port_speed_get(phba);
3117 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3121 lpfc_cmf_signal_init(struct lpfc_hba *phba)
3123 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3124 "6223 Signal CMF init\n");
3126 /* Use the new fc_linkspeed to recalculate */
3127 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3128 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3129 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3130 phba->cmf_interval_rate, 1000);
3131 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3133 /* This is a signal to firmware to sync up CMF BW with link speed */
3134 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3138 * lpfc_cmf_start - Start CMF processing
3139 * @phba: pointer to lpfc hba data structure.
3141 * This is called when the link comes up or if CMF mode is turned OFF
3142 * to Monitor or Managed.
3145 lpfc_cmf_start(struct lpfc_hba *phba)
3147 struct lpfc_cgn_stat *cgs;
3150 /* We only do something if CMF is enabled */
3151 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3152 phba->cmf_active_mode == LPFC_CFG_OFF)
3155 /* Reinitialize congestion buffer info */
3156 lpfc_init_congestion_buf(phba);
3158 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3159 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3160 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3161 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3163 atomic_set(&phba->cmf_busy, 0);
3164 for_each_present_cpu(cpu) {
3165 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3166 atomic64_set(&cgs->total_bytes, 0);
3167 atomic64_set(&cgs->rcv_bytes, 0);
3168 atomic_set(&cgs->rx_io_cnt, 0);
3169 atomic64_set(&cgs->rx_latency, 0);
3171 phba->cmf_latency.tv_sec = 0;
3172 phba->cmf_latency.tv_nsec = 0;
3174 lpfc_cmf_signal_init(phba);
3176 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3177 "6222 Start CMF / Timer\n");
3179 phba->cmf_timer_cnt = 0;
3180 hrtimer_start(&phba->cmf_timer,
3181 ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
3183 /* Setup for latency check in IO cmpl routines */
3184 ktime_get_real_ts64(&phba->cmf_latency);
3186 atomic_set(&phba->cmf_bw_wait, 0);
3187 atomic_set(&phba->cmf_stop_io, 0);
3191 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
3192 * @phba: pointer to lpfc hba data structure.
3194 * This routine stops all the timers associated with a HBA. This function is
3195 * invoked before either putting a HBA offline or unloading the driver.
3198 lpfc_stop_hba_timers(struct lpfc_hba *phba)
3201 lpfc_stop_vport_timers(phba->pport);
3202 cancel_delayed_work_sync(&phba->eq_delay_work);
3203 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
3204 del_timer_sync(&phba->sli.mbox_tmo);
3205 del_timer_sync(&phba->fabric_block_timer);
3206 del_timer_sync(&phba->eratt_poll);
3207 del_timer_sync(&phba->hb_tmofunc);
3208 if (phba->sli_rev == LPFC_SLI_REV4) {
3209 del_timer_sync(&phba->rrq_tmr);
3210 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
3212 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
3214 switch (phba->pci_dev_grp) {
3215 case LPFC_PCI_DEV_LP:
3216 /* Stop any LightPulse device specific driver timers */
3217 del_timer_sync(&phba->fcp_poll_timer);
3219 case LPFC_PCI_DEV_OC:
3220 /* Stop any OneConnect device specific driver timers */
3221 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3224 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3225 "0297 Invalid device group (x%x)\n",
3233 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3234 * @phba: pointer to lpfc hba data structure.
3235 * @mbx_action: flag for mailbox no wait action.
3237 * This routine marks a HBA's management interface as blocked. Once the HBA's
3238 * management interface is marked as blocked, all the user space access to
3239 * the HBA, whether they are from sysfs interface or libdfc interface will
3240 * all be blocked. The HBA is set to block the management interface when the
3241 * driver prepares the HBA interface for online or offline.
3244 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
3246 unsigned long iflag;
3247 uint8_t actcmd = MBX_HEARTBEAT;
3248 unsigned long timeout;
3250 spin_lock_irqsave(&phba->hbalock, iflag);
3251 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
3252 spin_unlock_irqrestore(&phba->hbalock, iflag);
3253 if (mbx_action == LPFC_MBX_NO_WAIT)
3255 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3256 spin_lock_irqsave(&phba->hbalock, iflag);
3257 if (phba->sli.mbox_active) {
3258 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3259 /* Determine how long we might wait for the active mailbox
3260 * command to be gracefully completed by firmware.
3262 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3263 phba->sli.mbox_active) * 1000) + jiffies;
3265 spin_unlock_irqrestore(&phba->hbalock, iflag);
3267 /* Wait for the outstnading mailbox command to complete */
3268 while (phba->sli.mbox_active) {
3269 /* Check active mailbox complete status every 2ms */
3271 if (time_after(jiffies, timeout)) {
3272 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3273 "2813 Mgmt IO is Blocked %x "
3274 "- mbox cmd %x still active\n",
3275 phba->sli.sli_flag, actcmd);
3282 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3283 * @phba: pointer to lpfc hba data structure.
3285 * Allocate RPIs for all active remote nodes. This is needed whenever
3286 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3287 * is to fixup the temporary rpi assignments.
3290 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3292 struct lpfc_nodelist *ndlp, *next_ndlp;
3293 struct lpfc_vport **vports;
3296 if (phba->sli_rev != LPFC_SLI_REV4)
3299 vports = lpfc_create_vport_work_array(phba);
3303 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3304 if (vports[i]->load_flag & FC_UNLOADING)
3307 list_for_each_entry_safe(ndlp, next_ndlp,
3308 &vports[i]->fc_nodes,
3310 rpi = lpfc_sli4_alloc_rpi(phba);
3311 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3312 /* TODO print log? */
3315 ndlp->nlp_rpi = rpi;
3316 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3317 LOG_NODE | LOG_DISCOVERY,
3318 "0009 Assign RPI x%x to ndlp x%px "
3319 "DID:x%06x flg:x%x\n",
3320 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3324 lpfc_destroy_vport_work_array(phba, vports);
3328 * lpfc_create_expedite_pool - create expedite pool
3329 * @phba: pointer to lpfc hba data structure.
3331 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3332 * to expedite pool. Mark them as expedite.
3334 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3336 struct lpfc_sli4_hdw_queue *qp;
3337 struct lpfc_io_buf *lpfc_ncmd;
3338 struct lpfc_io_buf *lpfc_ncmd_next;
3339 struct lpfc_epd_pool *epd_pool;
3340 unsigned long iflag;
3342 epd_pool = &phba->epd_pool;
3343 qp = &phba->sli4_hba.hdwq[0];
3345 spin_lock_init(&epd_pool->lock);
3346 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3347 spin_lock(&epd_pool->lock);
3348 INIT_LIST_HEAD(&epd_pool->list);
3349 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3350 &qp->lpfc_io_buf_list_put, list) {
3351 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3352 lpfc_ncmd->expedite = true;
3355 if (epd_pool->count >= XRI_BATCH)
3358 spin_unlock(&epd_pool->lock);
3359 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3363 * lpfc_destroy_expedite_pool - destroy expedite pool
3364 * @phba: pointer to lpfc hba data structure.
3366 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3367 * of HWQ 0. Clear the mark.
3369 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3371 struct lpfc_sli4_hdw_queue *qp;
3372 struct lpfc_io_buf *lpfc_ncmd;
3373 struct lpfc_io_buf *lpfc_ncmd_next;
3374 struct lpfc_epd_pool *epd_pool;
3375 unsigned long iflag;
3377 epd_pool = &phba->epd_pool;
3378 qp = &phba->sli4_hba.hdwq[0];
3380 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3381 spin_lock(&epd_pool->lock);
3382 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3383 &epd_pool->list, list) {
3384 list_move_tail(&lpfc_ncmd->list,
3385 &qp->lpfc_io_buf_list_put);
3386 lpfc_ncmd->flags = false;
3390 spin_unlock(&epd_pool->lock);
3391 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3395 * lpfc_create_multixri_pools - create multi-XRI pools
3396 * @phba: pointer to lpfc hba data structure.
3398 * This routine initialize public, private per HWQ. Then, move XRIs from
3399 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3402 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3407 struct lpfc_io_buf *lpfc_ncmd;
3408 struct lpfc_io_buf *lpfc_ncmd_next;
3409 unsigned long iflag;
3410 struct lpfc_sli4_hdw_queue *qp;
3411 struct lpfc_multixri_pool *multixri_pool;
3412 struct lpfc_pbl_pool *pbl_pool;
3413 struct lpfc_pvt_pool *pvt_pool;
3415 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3416 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3417 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3418 phba->sli4_hba.io_xri_cnt);
3420 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3421 lpfc_create_expedite_pool(phba);
3423 hwq_count = phba->cfg_hdw_queue;
3424 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3426 for (i = 0; i < hwq_count; i++) {
3427 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3429 if (!multixri_pool) {
3430 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3431 "1238 Failed to allocate memory for "
3434 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3435 lpfc_destroy_expedite_pool(phba);
3439 qp = &phba->sli4_hba.hdwq[j];
3440 kfree(qp->p_multixri_pool);
3443 phba->cfg_xri_rebalancing = 0;
3447 qp = &phba->sli4_hba.hdwq[i];
3448 qp->p_multixri_pool = multixri_pool;
3450 multixri_pool->xri_limit = count_per_hwq;
3451 multixri_pool->rrb_next_hwqid = i;
3453 /* Deal with public free xri pool */
3454 pbl_pool = &multixri_pool->pbl_pool;
3455 spin_lock_init(&pbl_pool->lock);
3456 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3457 spin_lock(&pbl_pool->lock);
3458 INIT_LIST_HEAD(&pbl_pool->list);
3459 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3460 &qp->lpfc_io_buf_list_put, list) {
3461 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3465 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3466 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3467 pbl_pool->count, i);
3468 spin_unlock(&pbl_pool->lock);
3469 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3471 /* Deal with private free xri pool */
3472 pvt_pool = &multixri_pool->pvt_pool;
3473 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3474 pvt_pool->low_watermark = XRI_BATCH;
3475 spin_lock_init(&pvt_pool->lock);
3476 spin_lock_irqsave(&pvt_pool->lock, iflag);
3477 INIT_LIST_HEAD(&pvt_pool->list);
3478 pvt_pool->count = 0;
3479 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3484 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3485 * @phba: pointer to lpfc hba data structure.
3487 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3489 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3493 struct lpfc_io_buf *lpfc_ncmd;
3494 struct lpfc_io_buf *lpfc_ncmd_next;
3495 unsigned long iflag;
3496 struct lpfc_sli4_hdw_queue *qp;
3497 struct lpfc_multixri_pool *multixri_pool;
3498 struct lpfc_pbl_pool *pbl_pool;
3499 struct lpfc_pvt_pool *pvt_pool;
3501 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3502 lpfc_destroy_expedite_pool(phba);
3504 if (!(phba->pport->load_flag & FC_UNLOADING))
3505 lpfc_sli_flush_io_rings(phba);
3507 hwq_count = phba->cfg_hdw_queue;
3509 for (i = 0; i < hwq_count; i++) {
3510 qp = &phba->sli4_hba.hdwq[i];
3511 multixri_pool = qp->p_multixri_pool;
3515 qp->p_multixri_pool = NULL;
3517 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3519 /* Deal with public free xri pool */
3520 pbl_pool = &multixri_pool->pbl_pool;
3521 spin_lock(&pbl_pool->lock);
3523 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3524 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3525 pbl_pool->count, i);
3527 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3528 &pbl_pool->list, list) {
3529 list_move_tail(&lpfc_ncmd->list,
3530 &qp->lpfc_io_buf_list_put);
3535 INIT_LIST_HEAD(&pbl_pool->list);
3536 pbl_pool->count = 0;
3538 spin_unlock(&pbl_pool->lock);
3540 /* Deal with private free xri pool */
3541 pvt_pool = &multixri_pool->pvt_pool;
3542 spin_lock(&pvt_pool->lock);
3544 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3545 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3546 pvt_pool->count, i);
3548 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3549 &pvt_pool->list, list) {
3550 list_move_tail(&lpfc_ncmd->list,
3551 &qp->lpfc_io_buf_list_put);
3556 INIT_LIST_HEAD(&pvt_pool->list);
3557 pvt_pool->count = 0;
3559 spin_unlock(&pvt_pool->lock);
3560 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3562 kfree(multixri_pool);
3567 * lpfc_online - Initialize and bring a HBA online
3568 * @phba: pointer to lpfc hba data structure.
3570 * This routine initializes the HBA and brings a HBA online. During this
3571 * process, the management interface is blocked to prevent user space access
3572 * to the HBA interfering with the driver initialization.
3579 lpfc_online(struct lpfc_hba *phba)
3581 struct lpfc_vport *vport;
3582 struct lpfc_vport **vports;
3584 bool vpis_cleared = false;
3588 vport = phba->pport;
3590 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3593 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3594 "0458 Bring Adapter online\n");
3596 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3598 if (phba->sli_rev == LPFC_SLI_REV4) {
3599 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3600 lpfc_unblock_mgmt_io(phba);
3603 spin_lock_irq(&phba->hbalock);
3604 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3605 vpis_cleared = true;
3606 spin_unlock_irq(&phba->hbalock);
3608 /* Reestablish the local initiator port.
3609 * The offline process destroyed the previous lport.
3611 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3612 !phba->nvmet_support) {
3613 error = lpfc_nvme_create_localport(phba->pport);
3615 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3616 "6132 NVME restore reg failed "
3617 "on nvmei error x%x\n", error);
3620 lpfc_sli_queue_init(phba);
3621 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3622 lpfc_unblock_mgmt_io(phba);
3627 vports = lpfc_create_vport_work_array(phba);
3628 if (vports != NULL) {
3629 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3630 struct Scsi_Host *shost;
3631 shost = lpfc_shost_from_vport(vports[i]);
3632 spin_lock_irq(shost->host_lock);
3633 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3634 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3635 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3636 if (phba->sli_rev == LPFC_SLI_REV4) {
3637 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3638 if ((vpis_cleared) &&
3639 (vports[i]->port_type !=
3640 LPFC_PHYSICAL_PORT))
3643 spin_unlock_irq(shost->host_lock);
3646 lpfc_destroy_vport_work_array(phba, vports);
3648 if (phba->cfg_xri_rebalancing)
3649 lpfc_create_multixri_pools(phba);
3651 lpfc_cpuhp_add(phba);
3653 lpfc_unblock_mgmt_io(phba);
3658 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3659 * @phba: pointer to lpfc hba data structure.
3661 * This routine marks a HBA's management interface as not blocked. Once the
3662 * HBA's management interface is marked as not blocked, all the user space
3663 * access to the HBA, whether they are from sysfs interface or libdfc
3664 * interface will be allowed. The HBA is set to block the management interface
3665 * when the driver prepares the HBA interface for online or offline and then
3666 * set to unblock the management interface afterwards.
3669 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3671 unsigned long iflag;
3673 spin_lock_irqsave(&phba->hbalock, iflag);
3674 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3675 spin_unlock_irqrestore(&phba->hbalock, iflag);
3679 * lpfc_offline_prep - Prepare a HBA to be brought offline
3680 * @phba: pointer to lpfc hba data structure.
3681 * @mbx_action: flag for mailbox shutdown action.
3683 * This routine is invoked to prepare a HBA to be brought offline. It performs
3684 * unregistration login to all the nodes on all vports and flushes the mailbox
3685 * queue to make it ready to be brought offline.
3688 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3690 struct lpfc_vport *vport = phba->pport;
3691 struct lpfc_nodelist *ndlp, *next_ndlp;
3692 struct lpfc_vport **vports;
3693 struct Scsi_Host *shost;
3697 if (vport->fc_flag & FC_OFFLINE_MODE)
3700 lpfc_block_mgmt_io(phba, mbx_action);
3702 lpfc_linkdown(phba);
3704 offline = pci_channel_offline(phba->pcidev);
3706 /* Issue an unreg_login to all nodes on all vports */
3707 vports = lpfc_create_vport_work_array(phba);
3708 if (vports != NULL) {
3709 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3710 if (vports[i]->load_flag & FC_UNLOADING)
3712 shost = lpfc_shost_from_vport(vports[i]);
3713 spin_lock_irq(shost->host_lock);
3714 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3715 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3716 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3717 spin_unlock_irq(shost->host_lock);
3719 shost = lpfc_shost_from_vport(vports[i]);
3720 list_for_each_entry_safe(ndlp, next_ndlp,
3721 &vports[i]->fc_nodes,
3724 spin_lock_irq(&ndlp->lock);
3725 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3726 spin_unlock_irq(&ndlp->lock);
3729 spin_lock_irq(&ndlp->lock);
3730 ndlp->nlp_flag &= ~(NLP_UNREG_INP |
3731 NLP_RPI_REGISTERED);
3732 spin_unlock_irq(&ndlp->lock);
3734 lpfc_unreg_rpi(vports[i], ndlp);
3737 * Whenever an SLI4 port goes offline, free the
3738 * RPI. Get a new RPI when the adapter port
3739 * comes back online.
3741 if (phba->sli_rev == LPFC_SLI_REV4) {
3742 lpfc_printf_vlog(vports[i], KERN_INFO,
3743 LOG_NODE | LOG_DISCOVERY,
3744 "0011 Free RPI x%x on "
3745 "ndlp: x%px did x%x\n",
3746 ndlp->nlp_rpi, ndlp,
3748 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3749 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3752 if (ndlp->nlp_type & NLP_FABRIC) {
3753 lpfc_disc_state_machine(vports[i], ndlp,
3754 NULL, NLP_EVT_DEVICE_RECOVERY);
3756 /* Don't remove the node unless the node
3757 * has been unregistered with the
3758 * transport, and we're not in recovery
3759 * before dev_loss_tmo triggered.
3760 * Otherwise, let dev_loss take care of
3763 if (!(ndlp->save_flags &
3764 NLP_IN_RECOV_POST_DEV_LOSS) &&
3765 !(ndlp->fc4_xpt_flags &
3766 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3767 lpfc_disc_state_machine
3775 lpfc_destroy_vport_work_array(phba, vports);
3777 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3780 flush_workqueue(phba->wq);
3784 * lpfc_offline - Bring a HBA offline
3785 * @phba: pointer to lpfc hba data structure.
3787 * This routine actually brings a HBA offline. It stops all the timers
3788 * associated with the HBA, brings down the SLI layer, and eventually
3789 * marks the HBA as in offline state for the upper layer protocol.
3792 lpfc_offline(struct lpfc_hba *phba)
3794 struct Scsi_Host *shost;
3795 struct lpfc_vport **vports;
3798 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3801 /* stop port and all timers associated with this hba */
3802 lpfc_stop_port(phba);
3804 /* Tear down the local and target port registrations. The
3805 * nvme transports need to cleanup.
3807 lpfc_nvmet_destroy_targetport(phba);
3808 lpfc_nvme_destroy_localport(phba->pport);
3810 vports = lpfc_create_vport_work_array(phba);
3812 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3813 lpfc_stop_vport_timers(vports[i]);
3814 lpfc_destroy_vport_work_array(phba, vports);
3815 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3816 "0460 Bring Adapter offline\n");
3817 /* Bring down the SLI Layer and cleanup. The HBA is offline
3819 lpfc_sli_hba_down(phba);
3820 spin_lock_irq(&phba->hbalock);
3822 spin_unlock_irq(&phba->hbalock);
3823 vports = lpfc_create_vport_work_array(phba);
3825 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3826 shost = lpfc_shost_from_vport(vports[i]);
3827 spin_lock_irq(shost->host_lock);
3828 vports[i]->work_port_events = 0;
3829 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3830 spin_unlock_irq(shost->host_lock);
3832 lpfc_destroy_vport_work_array(phba, vports);
3833 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3836 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3837 __lpfc_cpuhp_remove(phba);
3839 if (phba->cfg_xri_rebalancing)
3840 lpfc_destroy_multixri_pools(phba);
3844 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3845 * @phba: pointer to lpfc hba data structure.
3847 * This routine is to free all the SCSI buffers and IOCBs from the driver
3848 * list back to kernel. It is called from lpfc_pci_remove_one to free
3849 * the internal resources before the device is removed from the system.
3852 lpfc_scsi_free(struct lpfc_hba *phba)
3854 struct lpfc_io_buf *sb, *sb_next;
3856 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3859 spin_lock_irq(&phba->hbalock);
3861 /* Release all the lpfc_scsi_bufs maintained by this host. */
3863 spin_lock(&phba->scsi_buf_list_put_lock);
3864 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3866 list_del(&sb->list);
3867 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3870 phba->total_scsi_bufs--;
3872 spin_unlock(&phba->scsi_buf_list_put_lock);
3874 spin_lock(&phba->scsi_buf_list_get_lock);
3875 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3877 list_del(&sb->list);
3878 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3881 phba->total_scsi_bufs--;
3883 spin_unlock(&phba->scsi_buf_list_get_lock);
3884 spin_unlock_irq(&phba->hbalock);
3888 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3889 * @phba: pointer to lpfc hba data structure.
3891 * This routine is to free all the IO buffers and IOCBs from the driver
3892 * list back to kernel. It is called from lpfc_pci_remove_one to free
3893 * the internal resources before the device is removed from the system.
3896 lpfc_io_free(struct lpfc_hba *phba)
3898 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
3899 struct lpfc_sli4_hdw_queue *qp;
3902 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3903 qp = &phba->sli4_hba.hdwq[idx];
3904 /* Release all the lpfc_nvme_bufs maintained by this host. */
3905 spin_lock(&qp->io_buf_list_put_lock);
3906 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3907 &qp->lpfc_io_buf_list_put,
3909 list_del(&lpfc_ncmd->list);
3911 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3912 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3913 if (phba->cfg_xpsgl && !phba->nvmet_support)
3914 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3915 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3917 qp->total_io_bufs--;
3919 spin_unlock(&qp->io_buf_list_put_lock);
3921 spin_lock(&qp->io_buf_list_get_lock);
3922 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3923 &qp->lpfc_io_buf_list_get,
3925 list_del(&lpfc_ncmd->list);
3927 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3928 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3929 if (phba->cfg_xpsgl && !phba->nvmet_support)
3930 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3931 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3933 qp->total_io_bufs--;
3935 spin_unlock(&qp->io_buf_list_get_lock);
3940 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3941 * @phba: pointer to lpfc hba data structure.
3943 * This routine first calculates the sizes of the current els and allocated
3944 * scsi sgl lists, and then goes through all sgls to updates the physical
3945 * XRIs assigned due to port function reset. During port initialization, the
3946 * current els and allocated scsi sgl lists are 0s.
3949 * 0 - successful (for now, it always returns 0)
3952 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3954 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3955 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3956 LIST_HEAD(els_sgl_list);
3960 * update on pci function's els xri-sgl list
3962 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3964 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3965 /* els xri-sgl expanded */
3966 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3967 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3968 "3157 ELS xri-sgl count increased from "
3969 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3971 /* allocate the additional els sgls */
3972 for (i = 0; i < xri_cnt; i++) {
3973 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3975 if (sglq_entry == NULL) {
3976 lpfc_printf_log(phba, KERN_ERR,
3978 "2562 Failure to allocate an "
3979 "ELS sgl entry:%d\n", i);
3983 sglq_entry->buff_type = GEN_BUFF_TYPE;
3984 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3986 if (sglq_entry->virt == NULL) {
3988 lpfc_printf_log(phba, KERN_ERR,
3990 "2563 Failure to allocate an "
3991 "ELS mbuf:%d\n", i);
3995 sglq_entry->sgl = sglq_entry->virt;
3996 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3997 sglq_entry->state = SGL_FREED;
3998 list_add_tail(&sglq_entry->list, &els_sgl_list);
4000 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4001 list_splice_init(&els_sgl_list,
4002 &phba->sli4_hba.lpfc_els_sgl_list);
4003 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4004 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
4005 /* els xri-sgl shrinked */
4006 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
4007 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4008 "3158 ELS xri-sgl count decreased from "
4009 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4011 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4012 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
4014 /* release extra els sgls from list */
4015 for (i = 0; i < xri_cnt; i++) {
4016 list_remove_head(&els_sgl_list,
4017 sglq_entry, struct lpfc_sglq, list);
4019 __lpfc_mbuf_free(phba, sglq_entry->virt,
4024 list_splice_init(&els_sgl_list,
4025 &phba->sli4_hba.lpfc_els_sgl_list);
4026 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4028 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4029 "3163 ELS xri-sgl count unchanged: %d\n",
4031 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
4033 /* update xris to els sgls on the list */
4035 sglq_entry_next = NULL;
4036 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4037 &phba->sli4_hba.lpfc_els_sgl_list, list) {
4038 lxri = lpfc_sli4_next_xritag(phba);
4039 if (lxri == NO_XRI) {
4040 lpfc_printf_log(phba, KERN_ERR,
4042 "2400 Failed to allocate xri for "
4047 sglq_entry->sli4_lxritag = lxri;
4048 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4053 lpfc_free_els_sgl_list(phba);
4058 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
4059 * @phba: pointer to lpfc hba data structure.
4061 * This routine first calculates the sizes of the current els and allocated
4062 * scsi sgl lists, and then goes through all sgls to updates the physical
4063 * XRIs assigned due to port function reset. During port initialization, the
4064 * current els and allocated scsi sgl lists are 0s.
4067 * 0 - successful (for now, it always returns 0)
4070 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4072 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4073 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4074 uint16_t nvmet_xri_cnt;
4075 LIST_HEAD(nvmet_sgl_list);
4079 * update on pci function's nvmet xri-sgl list
4081 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4083 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4084 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4085 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4086 /* els xri-sgl expanded */
4087 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4088 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4089 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4090 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4091 /* allocate the additional nvmet sgls */
4092 for (i = 0; i < xri_cnt; i++) {
4093 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4095 if (sglq_entry == NULL) {
4096 lpfc_printf_log(phba, KERN_ERR,
4098 "6303 Failure to allocate an "
4099 "NVMET sgl entry:%d\n", i);
4103 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4104 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4106 if (sglq_entry->virt == NULL) {
4108 lpfc_printf_log(phba, KERN_ERR,
4110 "6304 Failure to allocate an "
4111 "NVMET buf:%d\n", i);
4115 sglq_entry->sgl = sglq_entry->virt;
4116 memset(sglq_entry->sgl, 0,
4117 phba->cfg_sg_dma_buf_size);
4118 sglq_entry->state = SGL_FREED;
4119 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4121 spin_lock_irq(&phba->hbalock);
4122 spin_lock(&phba->sli4_hba.sgl_list_lock);
4123 list_splice_init(&nvmet_sgl_list,
4124 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4125 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4126 spin_unlock_irq(&phba->hbalock);
4127 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4128 /* nvmet xri-sgl shrunk */
4129 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4130 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4131 "6305 NVMET xri-sgl count decreased from "
4132 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4134 spin_lock_irq(&phba->hbalock);
4135 spin_lock(&phba->sli4_hba.sgl_list_lock);
4136 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4138 /* release extra nvmet sgls from list */
4139 for (i = 0; i < xri_cnt; i++) {
4140 list_remove_head(&nvmet_sgl_list,
4141 sglq_entry, struct lpfc_sglq, list);
4143 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4148 list_splice_init(&nvmet_sgl_list,
4149 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4150 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4151 spin_unlock_irq(&phba->hbalock);
4153 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4154 "6306 NVMET xri-sgl count unchanged: %d\n",
4156 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4158 /* update xris to nvmet sgls on the list */
4160 sglq_entry_next = NULL;
4161 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4162 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4163 lxri = lpfc_sli4_next_xritag(phba);
4164 if (lxri == NO_XRI) {
4165 lpfc_printf_log(phba, KERN_ERR,
4167 "6307 Failed to allocate xri for "
4172 sglq_entry->sli4_lxritag = lxri;
4173 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4178 lpfc_free_nvmet_sgl_list(phba);
4183 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4186 struct lpfc_sli4_hdw_queue *qp;
4187 struct lpfc_io_buf *lpfc_cmd;
4188 struct lpfc_io_buf *iobufp, *prev_iobufp;
4189 int idx, cnt, xri, inserted;
4192 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4193 qp = &phba->sli4_hba.hdwq[idx];
4194 spin_lock_irq(&qp->io_buf_list_get_lock);
4195 spin_lock(&qp->io_buf_list_put_lock);
4197 /* Take everything off the get and put lists */
4198 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4199 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4200 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4201 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4202 cnt += qp->get_io_bufs + qp->put_io_bufs;
4203 qp->get_io_bufs = 0;
4204 qp->put_io_bufs = 0;
4205 qp->total_io_bufs = 0;
4206 spin_unlock(&qp->io_buf_list_put_lock);
4207 spin_unlock_irq(&qp->io_buf_list_get_lock);
4211 * Take IO buffers off blist and put on cbuf sorted by XRI.
4212 * This is because POST_SGL takes a sequential range of XRIs
4213 * to post to the firmware.
4215 for (idx = 0; idx < cnt; idx++) {
4216 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
4220 list_add_tail(&lpfc_cmd->list, cbuf);
4223 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4226 list_for_each_entry(iobufp, cbuf, list) {
4227 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4229 list_add(&lpfc_cmd->list,
4230 &prev_iobufp->list);
4232 list_add(&lpfc_cmd->list, cbuf);
4236 prev_iobufp = iobufp;
4239 list_add_tail(&lpfc_cmd->list, cbuf);
4245 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4247 struct lpfc_sli4_hdw_queue *qp;
4248 struct lpfc_io_buf *lpfc_cmd;
4251 qp = phba->sli4_hba.hdwq;
4253 while (!list_empty(cbuf)) {
4254 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4255 list_remove_head(cbuf, lpfc_cmd,
4256 struct lpfc_io_buf, list);
4260 qp = &phba->sli4_hba.hdwq[idx];
4261 lpfc_cmd->hdwq_no = idx;
4262 lpfc_cmd->hdwq = qp;
4263 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
4264 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
4265 spin_lock(&qp->io_buf_list_put_lock);
4266 list_add_tail(&lpfc_cmd->list,
4267 &qp->lpfc_io_buf_list_put);
4269 qp->total_io_bufs++;
4270 spin_unlock(&qp->io_buf_list_put_lock);
4277 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4278 * @phba: pointer to lpfc hba data structure.
4280 * This routine first calculates the sizes of the current els and allocated
4281 * scsi sgl lists, and then goes through all sgls to updates the physical
4282 * XRIs assigned due to port function reset. During port initialization, the
4283 * current els and allocated scsi sgl lists are 0s.
4286 * 0 - successful (for now, it always returns 0)
4289 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
4291 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
4292 uint16_t i, lxri, els_xri_cnt;
4293 uint16_t io_xri_cnt, io_xri_max;
4294 LIST_HEAD(io_sgl_list);
4298 * update on pci function's allocated nvme xri-sgl list
4301 /* maximum number of xris available for nvme buffers */
4302 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4303 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4304 phba->sli4_hba.io_xri_max = io_xri_max;
4306 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4307 "6074 Current allocated XRI sgl count:%d, "
4308 "maximum XRI count:%d\n",
4309 phba->sli4_hba.io_xri_cnt,
4310 phba->sli4_hba.io_xri_max);
4312 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4314 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4315 /* max nvme xri shrunk below the allocated nvme buffers */
4316 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4317 phba->sli4_hba.io_xri_max;
4318 /* release the extra allocated nvme buffers */
4319 for (i = 0; i < io_xri_cnt; i++) {
4320 list_remove_head(&io_sgl_list, lpfc_ncmd,
4321 struct lpfc_io_buf, list);
4323 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4325 lpfc_ncmd->dma_handle);
4329 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4332 /* update xris associated to remaining allocated nvme buffers */
4334 lpfc_ncmd_next = NULL;
4335 phba->sli4_hba.io_xri_cnt = cnt;
4336 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4337 &io_sgl_list, list) {
4338 lxri = lpfc_sli4_next_xritag(phba);
4339 if (lxri == NO_XRI) {
4340 lpfc_printf_log(phba, KERN_ERR,
4342 "6075 Failed to allocate xri for "
4347 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4348 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4350 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4359 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4360 * @phba: Pointer to lpfc hba data structure.
4361 * @num_to_alloc: The requested number of buffers to allocate.
4363 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4364 * the nvme buffer contains all the necessary information needed to initiate
4365 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4366 * them on a list, it post them to the port by using SGL block post.
4369 * int - number of IO buffers that were allocated and posted.
4370 * 0 = failure, less than num_to_alloc is a partial failure.
4373 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4375 struct lpfc_io_buf *lpfc_ncmd;
4376 struct lpfc_iocbq *pwqeq;
4377 uint16_t iotag, lxri = 0;
4378 int bcnt, num_posted;
4379 LIST_HEAD(prep_nblist);
4380 LIST_HEAD(post_nblist);
4381 LIST_HEAD(nvme_nblist);
4383 phba->sli4_hba.io_xri_cnt = 0;
4384 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4385 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4389 * Get memory from the pci pool to map the virt space to
4390 * pci bus space for an I/O. The DMA buffer includes the
4391 * number of SGE's necessary to support the sg_tablesize.
4393 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4395 &lpfc_ncmd->dma_handle);
4396 if (!lpfc_ncmd->data) {
4401 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4402 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4405 * 4K Page alignment is CRITICAL to BlockGuard, double
4408 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4409 (((unsigned long)(lpfc_ncmd->data) &
4410 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4411 lpfc_printf_log(phba, KERN_ERR,
4413 "3369 Memory alignment err: "
4415 (unsigned long)lpfc_ncmd->data);
4416 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4418 lpfc_ncmd->dma_handle);
4424 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4426 lxri = lpfc_sli4_next_xritag(phba);
4427 if (lxri == NO_XRI) {
4428 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4429 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4433 pwqeq = &lpfc_ncmd->cur_iocbq;
4435 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4436 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4438 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4439 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4441 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4442 "6121 Failed to allocate IOTAG for"
4443 " XRI:0x%x\n", lxri);
4444 lpfc_sli4_free_xri(phba, lxri);
4447 pwqeq->sli4_lxritag = lxri;
4448 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4449 pwqeq->context1 = lpfc_ncmd;
4451 /* Initialize local short-hand pointers. */
4452 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4453 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4454 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
4455 spin_lock_init(&lpfc_ncmd->buf_lock);
4457 /* add the nvme buffer to a post list */
4458 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4459 phba->sli4_hba.io_xri_cnt++;
4461 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4462 "6114 Allocate %d out of %d requested new NVME "
4463 "buffers\n", bcnt, num_to_alloc);
4465 /* post the list of nvme buffer sgls to port if available */
4466 if (!list_empty(&post_nblist))
4467 num_posted = lpfc_sli4_post_io_sgl_list(
4468 phba, &post_nblist, bcnt);
4476 lpfc_get_wwpn(struct lpfc_hba *phba)
4480 LPFC_MBOXQ_t *mboxq;
4483 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4486 return (uint64_t)-1;
4488 /* First get WWN of HBA instance */
4489 lpfc_read_nv(phba, mboxq);
4490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4491 if (rc != MBX_SUCCESS) {
4492 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4493 "6019 Mailbox failed , mbxCmd x%x "
4494 "READ_NV, mbxStatus x%x\n",
4495 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4496 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4497 mempool_free(mboxq, phba->mbox_mem_pool);
4498 return (uint64_t) -1;
4501 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4502 /* wwn is WWPN of HBA instance */
4503 mempool_free(mboxq, phba->mbox_mem_pool);
4504 if (phba->sli_rev == LPFC_SLI_REV4)
4505 return be64_to_cpu(wwn);
4507 return rol64(wwn, 32);
4511 * lpfc_vmid_res_alloc - Allocates resources for VMID
4512 * @phba: pointer to lpfc hba data structure.
4513 * @vport: pointer to vport data structure
4515 * This routine allocated the resources needed for the VMID.
4522 lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4524 /* VMID feature is supported only on SLI4 */
4525 if (phba->sli_rev == LPFC_SLI_REV3) {
4526 phba->cfg_vmid_app_header = 0;
4527 phba->cfg_vmid_priority_tagging = 0;
4530 if (lpfc_is_vmid_enabled(phba)) {
4532 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4537 rwlock_init(&vport->vmid_lock);
4539 /* Set the VMID parameters for the vport */
4540 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4541 vport->vmid_inactivity_timeout =
4542 phba->cfg_vmid_inactivity_timeout;
4543 vport->max_vmid = phba->cfg_max_vmid;
4544 vport->cur_vmid_cnt = 0;
4546 vport->vmid_priority_range = bitmap_zalloc
4547 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4549 if (!vport->vmid_priority_range) {
4554 hash_init(vport->hash_table);
4560 * lpfc_create_port - Create an FC port
4561 * @phba: pointer to lpfc hba data structure.
4562 * @instance: a unique integer ID to this FC port.
4563 * @dev: pointer to the device data structure.
4565 * This routine creates a FC port for the upper layer protocol. The FC port
4566 * can be created on top of either a physical port or a virtual port provided
4567 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4568 * and associates the FC port created before adding the shost into the SCSI
4572 * @vport - pointer to the virtual N_Port data structure.
4573 * NULL - port create failed.
4576 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4578 struct lpfc_vport *vport;
4579 struct Scsi_Host *shost = NULL;
4580 struct scsi_host_template *template;
4584 bool use_no_reset_hba = false;
4587 if (lpfc_no_hba_reset_cnt) {
4588 if (phba->sli_rev < LPFC_SLI_REV4 &&
4589 dev == &phba->pcidev->dev) {
4590 /* Reset the port first */
4591 lpfc_sli_brdrestart(phba);
4592 rc = lpfc_sli_chipset_init(phba);
4596 wwn = lpfc_get_wwpn(phba);
4599 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4600 if (wwn == lpfc_no_hba_reset[i]) {
4601 lpfc_printf_log(phba, KERN_ERR,
4603 "6020 Setting use_no_reset port=%llx\n",
4605 use_no_reset_hba = true;
4610 /* Seed template for SCSI host registration */
4611 if (dev == &phba->pcidev->dev) {
4612 template = &phba->port_template;
4614 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4615 /* Seed physical port template */
4616 memcpy(template, &lpfc_template, sizeof(*template));
4618 if (use_no_reset_hba)
4619 /* template is for a no reset SCSI Host */
4620 template->eh_host_reset_handler = NULL;
4622 /* Template for all vports this physical port creates */
4623 memcpy(&phba->vport_template, &lpfc_template,
4625 phba->vport_template.shost_groups = lpfc_vport_groups;
4626 phba->vport_template.eh_bus_reset_handler = NULL;
4627 phba->vport_template.eh_host_reset_handler = NULL;
4628 phba->vport_template.vendor_id = 0;
4630 /* Initialize the host templates with updated value */
4631 if (phba->sli_rev == LPFC_SLI_REV4) {
4632 template->sg_tablesize = phba->cfg_scsi_seg_cnt;
4633 phba->vport_template.sg_tablesize =
4634 phba->cfg_scsi_seg_cnt;
4636 template->sg_tablesize = phba->cfg_sg_seg_cnt;
4637 phba->vport_template.sg_tablesize =
4638 phba->cfg_sg_seg_cnt;
4642 /* NVMET is for physical port only */
4643 memcpy(template, &lpfc_template_nvme,
4647 template = &phba->vport_template;
4650 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
4654 vport = (struct lpfc_vport *) shost->hostdata;
4656 vport->load_flag |= FC_LOADING;
4657 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4658 vport->fc_rscn_flush = 0;
4659 lpfc_get_vport_cfgparam(vport);
4661 /* Adjust value in vport */
4662 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4664 shost->unique_id = instance;
4665 shost->max_id = LPFC_MAX_TARGET;
4666 shost->max_lun = vport->cfg_max_luns;
4667 shost->this_id = -1;
4668 shost->max_cmd_len = 16;
4670 if (phba->sli_rev == LPFC_SLI_REV4) {
4671 if (!phba->cfg_fcp_mq_threshold ||
4672 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4673 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4675 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4676 phba->cfg_fcp_mq_threshold);
4678 shost->dma_boundary =
4679 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4681 if (phba->cfg_xpsgl && !phba->nvmet_support)
4682 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4684 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
4686 /* SLI-3 has a limited number of hardware queues (3),
4687 * thus there is only one for FCP processing.
4689 shost->nr_hw_queues = 1;
4692 * Set initial can_queue value since 0 is no longer supported and
4693 * scsi_add_host will fail. This will be adjusted later based on the
4694 * max xri value determined in hba setup.
4696 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4697 if (dev != &phba->pcidev->dev) {
4698 shost->transportt = lpfc_vport_transport_template;
4699 vport->port_type = LPFC_NPIV_PORT;
4701 shost->transportt = lpfc_transport_template;
4702 vport->port_type = LPFC_PHYSICAL_PORT;
4705 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4706 "9081 CreatePort TMPLATE type %x TBLsize %d "
4708 vport->port_type, shost->sg_tablesize,
4709 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4711 /* Allocate the resources for VMID */
4712 rc = lpfc_vmid_res_alloc(phba, vport);
4717 /* Initialize all internally managed lists. */
4718 INIT_LIST_HEAD(&vport->fc_nodes);
4719 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4720 spin_lock_init(&vport->work_port_lock);
4722 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4724 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4726 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4728 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4729 lpfc_setup_bg(phba, shost);
4731 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4735 spin_lock_irq(&phba->port_list_lock);
4736 list_add_tail(&vport->listentry, &phba->port_list);
4737 spin_unlock_irq(&phba->port_list_lock);
4742 bitmap_free(vport->vmid_priority_range);
4743 scsi_host_put(shost);
4749 * destroy_port - destroy an FC port
4750 * @vport: pointer to an lpfc virtual N_Port data structure.
4752 * This routine destroys a FC port from the upper layer protocol. All the
4753 * resources associated with the port are released.
4756 destroy_port(struct lpfc_vport *vport)
4758 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4759 struct lpfc_hba *phba = vport->phba;
4761 lpfc_debugfs_terminate(vport);
4762 fc_remove_host(shost);
4763 scsi_remove_host(shost);
4765 spin_lock_irq(&phba->port_list_lock);
4766 list_del_init(&vport->listentry);
4767 spin_unlock_irq(&phba->port_list_lock);
4769 lpfc_cleanup(vport);
4774 * lpfc_get_instance - Get a unique integer ID
4776 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4777 * uses the kernel idr facility to perform the task.
4780 * instance - a unique integer ID allocated as the new instance.
4781 * -1 - lpfc get instance failed.
4784 lpfc_get_instance(void)
4788 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4789 return ret < 0 ? -1 : ret;
4793 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4794 * @shost: pointer to SCSI host data structure.
4795 * @time: elapsed time of the scan in jiffies.
4797 * This routine is called by the SCSI layer with a SCSI host to determine
4798 * whether the scan host is finished.
4800 * Note: there is no scan_start function as adapter initialization will have
4801 * asynchronously kicked off the link initialization.
4804 * 0 - SCSI host scan is not over yet.
4805 * 1 - SCSI host scan is over.
4807 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4810 struct lpfc_hba *phba = vport->phba;
4813 spin_lock_irq(shost->host_lock);
4815 if (vport->load_flag & FC_UNLOADING) {
4819 if (time >= msecs_to_jiffies(30 * 1000)) {
4820 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4821 "0461 Scanning longer than 30 "
4822 "seconds. Continuing initialization\n");
4826 if (time >= msecs_to_jiffies(15 * 1000) &&
4827 phba->link_state <= LPFC_LINK_DOWN) {
4828 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4829 "0465 Link down longer than 15 "
4830 "seconds. Continuing initialization\n");
4835 if (vport->port_state != LPFC_VPORT_READY)
4837 if (vport->num_disc_nodes || vport->fc_prli_sent)
4839 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4841 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4847 spin_unlock_irq(shost->host_lock);
4851 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4853 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4854 struct lpfc_hba *phba = vport->phba;
4856 fc_host_supported_speeds(shost) = 0;
4858 * Avoid reporting supported link speed for FCoE as it can't be
4859 * controlled via FCoE.
4861 if (phba->hba_flag & HBA_FCOE_MODE)
4864 if (phba->lmt & LMT_256Gb)
4865 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
4866 if (phba->lmt & LMT_128Gb)
4867 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4868 if (phba->lmt & LMT_64Gb)
4869 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4870 if (phba->lmt & LMT_32Gb)
4871 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4872 if (phba->lmt & LMT_16Gb)
4873 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4874 if (phba->lmt & LMT_10Gb)
4875 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4876 if (phba->lmt & LMT_8Gb)
4877 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4878 if (phba->lmt & LMT_4Gb)
4879 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4880 if (phba->lmt & LMT_2Gb)
4881 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4882 if (phba->lmt & LMT_1Gb)
4883 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4887 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4888 * @shost: pointer to SCSI host data structure.
4890 * This routine initializes a given SCSI host attributes on a FC port. The
4891 * SCSI host can be either on top of a physical port or a virtual port.
4893 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4895 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4896 struct lpfc_hba *phba = vport->phba;
4898 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4901 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4902 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4903 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4905 memset(fc_host_supported_fc4s(shost), 0,
4906 sizeof(fc_host_supported_fc4s(shost)));
4907 fc_host_supported_fc4s(shost)[2] = 1;
4908 fc_host_supported_fc4s(shost)[7] = 1;
4910 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4911 sizeof fc_host_symbolic_name(shost));
4913 lpfc_host_supported_speeds_set(shost);
4915 fc_host_maxframe_size(shost) =
4916 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4917 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4919 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4921 /* This value is also unchanging */
4922 memset(fc_host_active_fc4s(shost), 0,
4923 sizeof(fc_host_active_fc4s(shost)));
4924 fc_host_active_fc4s(shost)[2] = 1;
4925 fc_host_active_fc4s(shost)[7] = 1;
4927 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4928 spin_lock_irq(shost->host_lock);
4929 vport->load_flag &= ~FC_LOADING;
4930 spin_unlock_irq(shost->host_lock);
4934 * lpfc_stop_port_s3 - Stop SLI3 device port
4935 * @phba: pointer to lpfc hba data structure.
4937 * This routine is invoked to stop an SLI3 device port, it stops the device
4938 * from generating interrupts and stops the device driver's timers for the
4942 lpfc_stop_port_s3(struct lpfc_hba *phba)
4944 /* Clear all interrupt enable conditions */
4945 writel(0, phba->HCregaddr);
4946 readl(phba->HCregaddr); /* flush */
4947 /* Clear all pending interrupts */
4948 writel(0xffffffff, phba->HAregaddr);
4949 readl(phba->HAregaddr); /* flush */
4951 /* Reset some HBA SLI setup states */
4952 lpfc_stop_hba_timers(phba);
4953 phba->pport->work_port_events = 0;
4957 * lpfc_stop_port_s4 - Stop SLI4 device port
4958 * @phba: pointer to lpfc hba data structure.
4960 * This routine is invoked to stop an SLI4 device port, it stops the device
4961 * from generating interrupts and stops the device driver's timers for the
4965 lpfc_stop_port_s4(struct lpfc_hba *phba)
4967 /* Reset some HBA SLI4 setup states */
4968 lpfc_stop_hba_timers(phba);
4970 phba->pport->work_port_events = 0;
4971 phba->sli4_hba.intr_enable = 0;
4975 * lpfc_stop_port - Wrapper function for stopping hba port
4976 * @phba: Pointer to HBA context object.
4978 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4979 * the API jump table function pointer from the lpfc_hba struct.
4982 lpfc_stop_port(struct lpfc_hba *phba)
4984 phba->lpfc_stop_port(phba);
4987 flush_workqueue(phba->wq);
4991 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4992 * @phba: Pointer to hba for which this call is being executed.
4994 * This routine starts the timer waiting for the FCF rediscovery to complete.
4997 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4999 unsigned long fcf_redisc_wait_tmo =
5000 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
5001 /* Start fcf rediscovery wait period timer */
5002 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
5003 spin_lock_irq(&phba->hbalock);
5004 /* Allow action to new fcf asynchronous event */
5005 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
5006 /* Mark the FCF rediscovery pending state */
5007 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
5008 spin_unlock_irq(&phba->hbalock);
5012 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
5013 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5015 * This routine is invoked when waiting for FCF table rediscover has been
5016 * timed out. If new FCF record(s) has (have) been discovered during the
5017 * wait period, a new FCF event shall be added to the FCOE async event
5018 * list, and then worker thread shall be waked up for processing from the
5019 * worker thread context.
5022 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
5024 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
5026 /* Don't send FCF rediscovery event if timer cancelled */
5027 spin_lock_irq(&phba->hbalock);
5028 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
5029 spin_unlock_irq(&phba->hbalock);
5032 /* Clear FCF rediscovery timer pending flag */
5033 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
5034 /* FCF rediscovery event to worker thread */
5035 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
5036 spin_unlock_irq(&phba->hbalock);
5037 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
5038 "2776 FCF rediscover quiescent timer expired\n");
5039 /* wake up worker thread */
5040 lpfc_worker_wake_up(phba);
5044 * lpfc_vmid_poll - VMID timeout detection
5045 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5047 * This routine is invoked when there is no I/O on by a VM for the specified
5048 * amount of time. When this situation is detected, the VMID has to be
5049 * deregistered from the switch and all the local resources freed. The VMID
5050 * will be reassigned to the VM once the I/O begins.
5053 lpfc_vmid_poll(struct timer_list *t)
5055 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
5058 /* check if there is a need to issue QFPA */
5059 if (phba->pport->vmid_priority_tagging) {
5061 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5064 /* Is the vmid inactivity timer enabled */
5065 if (phba->pport->vmid_inactivity_timeout ||
5066 phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
5068 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5072 lpfc_worker_wake_up(phba);
5074 /* restart the timer for the next iteration */
5075 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5080 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5081 * @phba: pointer to lpfc hba data structure.
5082 * @acqe_link: pointer to the async link completion queue entry.
5084 * This routine is to parse the SLI4 link-attention link fault code.
5087 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5088 struct lpfc_acqe_link *acqe_link)
5090 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5091 case LPFC_ASYNC_LINK_FAULT_NONE:
5092 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5093 case LPFC_ASYNC_LINK_FAULT_REMOTE:
5094 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
5097 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5098 "0398 Unknown link fault code: x%x\n",
5099 bf_get(lpfc_acqe_link_fault, acqe_link));
5105 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5106 * @phba: pointer to lpfc hba data structure.
5107 * @acqe_link: pointer to the async link completion queue entry.
5109 * This routine is to parse the SLI4 link attention type and translate it
5110 * into the base driver's link attention type coding.
5112 * Return: Link attention type in terms of base driver's coding.
5115 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5116 struct lpfc_acqe_link *acqe_link)
5120 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5121 case LPFC_ASYNC_LINK_STATUS_DOWN:
5122 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
5123 att_type = LPFC_ATT_LINK_DOWN;
5125 case LPFC_ASYNC_LINK_STATUS_UP:
5126 /* Ignore physical link up events - wait for logical link up */
5127 att_type = LPFC_ATT_RESERVED;
5129 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
5130 att_type = LPFC_ATT_LINK_UP;
5133 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5134 "0399 Invalid link attention type: x%x\n",
5135 bf_get(lpfc_acqe_link_status, acqe_link));
5136 att_type = LPFC_ATT_RESERVED;
5143 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5144 * @phba: pointer to lpfc hba data structure.
5146 * This routine is to get an SLI3 FC port's link speed in Mbps.
5148 * Return: link speed in terms of Mbps.
5151 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5153 uint32_t link_speed;
5155 if (!lpfc_is_link_up(phba))
5158 if (phba->sli_rev <= LPFC_SLI_REV3) {
5159 switch (phba->fc_linkspeed) {
5160 case LPFC_LINK_SPEED_1GHZ:
5163 case LPFC_LINK_SPEED_2GHZ:
5166 case LPFC_LINK_SPEED_4GHZ:
5169 case LPFC_LINK_SPEED_8GHZ:
5172 case LPFC_LINK_SPEED_10GHZ:
5175 case LPFC_LINK_SPEED_16GHZ:
5182 if (phba->sli4_hba.link_state.logical_speed)
5184 phba->sli4_hba.link_state.logical_speed;
5186 link_speed = phba->sli4_hba.link_state.speed;
5192 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5193 * @phba: pointer to lpfc hba data structure.
5194 * @evt_code: asynchronous event code.
5195 * @speed_code: asynchronous event link speed code.
5197 * This routine is to parse the giving SLI4 async event link speed code into
5198 * value of Mbps for the link speed.
5200 * Return: link speed in terms of Mbps.
5203 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5206 uint32_t port_speed;
5209 case LPFC_TRAILER_CODE_LINK:
5210 switch (speed_code) {
5211 case LPFC_ASYNC_LINK_SPEED_ZERO:
5214 case LPFC_ASYNC_LINK_SPEED_10MBPS:
5217 case LPFC_ASYNC_LINK_SPEED_100MBPS:
5220 case LPFC_ASYNC_LINK_SPEED_1GBPS:
5223 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5226 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5229 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5232 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5235 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5236 port_speed = 100000;
5242 case LPFC_TRAILER_CODE_FC:
5243 switch (speed_code) {
5244 case LPFC_FC_LA_SPEED_UNKNOWN:
5247 case LPFC_FC_LA_SPEED_1G:
5250 case LPFC_FC_LA_SPEED_2G:
5253 case LPFC_FC_LA_SPEED_4G:
5256 case LPFC_FC_LA_SPEED_8G:
5259 case LPFC_FC_LA_SPEED_10G:
5262 case LPFC_FC_LA_SPEED_16G:
5265 case LPFC_FC_LA_SPEED_32G:
5268 case LPFC_FC_LA_SPEED_64G:
5271 case LPFC_FC_LA_SPEED_128G:
5272 port_speed = 128000;
5274 case LPFC_FC_LA_SPEED_256G:
5275 port_speed = 256000;
5288 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
5289 * @phba: pointer to lpfc hba data structure.
5290 * @acqe_link: pointer to the async link completion queue entry.
5292 * This routine is to handle the SLI4 asynchronous FCoE link event.
5295 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5296 struct lpfc_acqe_link *acqe_link)
5298 struct lpfc_dmabuf *mp;
5301 struct lpfc_mbx_read_top *la;
5305 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
5306 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
5308 phba->fcoe_eventtag = acqe_link->event_tag;
5309 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5311 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5312 "0395 The mboxq allocation failed\n");
5315 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5317 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5318 "0396 The lpfc_dmabuf allocation failed\n");
5321 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5323 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5324 "0397 The mbuf allocation failed\n");
5325 goto out_free_dmabuf;
5328 /* Cleanup any outstanding ELS commands */
5329 lpfc_els_flush_all_cmd(phba);
5331 /* Block ELS IOCBs until we have done process link event */
5332 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5334 /* Update link event statistics */
5335 phba->sli.slistat.link_event++;
5337 /* Create lpfc_handle_latt mailbox command from link ACQE */
5338 lpfc_read_topology(phba, pmb, mp);
5339 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5340 pmb->vport = phba->pport;
5342 /* Keep the link status for extra SLI4 state machine reference */
5343 phba->sli4_hba.link_state.speed =
5344 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5345 bf_get(lpfc_acqe_link_speed, acqe_link));
5346 phba->sli4_hba.link_state.duplex =
5347 bf_get(lpfc_acqe_link_duplex, acqe_link);
5348 phba->sli4_hba.link_state.status =
5349 bf_get(lpfc_acqe_link_status, acqe_link);
5350 phba->sli4_hba.link_state.type =
5351 bf_get(lpfc_acqe_link_type, acqe_link);
5352 phba->sli4_hba.link_state.number =
5353 bf_get(lpfc_acqe_link_number, acqe_link);
5354 phba->sli4_hba.link_state.fault =
5355 bf_get(lpfc_acqe_link_fault, acqe_link);
5356 phba->sli4_hba.link_state.logical_speed =
5357 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5359 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5360 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5361 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5362 "Logical speed:%dMbps Fault:%d\n",
5363 phba->sli4_hba.link_state.speed,
5364 phba->sli4_hba.link_state.topology,
5365 phba->sli4_hba.link_state.status,
5366 phba->sli4_hba.link_state.type,
5367 phba->sli4_hba.link_state.number,
5368 phba->sli4_hba.link_state.logical_speed,
5369 phba->sli4_hba.link_state.fault);
5371 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5372 * topology info. Note: Optional for non FC-AL ports.
5374 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5375 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5376 if (rc == MBX_NOT_FINISHED) {
5377 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5378 goto out_free_dmabuf;
5383 * For FCoE Mode: fill in all the topology information we need and call
5384 * the READ_TOPOLOGY completion routine to continue without actually
5385 * sending the READ_TOPOLOGY mailbox command to the port.
5387 /* Initialize completion status */
5389 mb->mbxStatus = MBX_SUCCESS;
5391 /* Parse port fault information field */
5392 lpfc_sli4_parse_latt_fault(phba, acqe_link);
5394 /* Parse and translate link attention fields */
5395 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5396 la->eventTag = acqe_link->event_tag;
5397 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5398 bf_set(lpfc_mbx_read_top_link_spd, la,
5399 (bf_get(lpfc_acqe_link_speed, acqe_link)));
5401 /* Fake the the following irrelvant fields */
5402 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5403 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5404 bf_set(lpfc_mbx_read_top_il, la, 0);
5405 bf_set(lpfc_mbx_read_top_pb, la, 0);
5406 bf_set(lpfc_mbx_read_top_fa, la, 0);
5407 bf_set(lpfc_mbx_read_top_mm, la, 0);
5409 /* Invoke the lpfc_handle_latt mailbox command callback function */
5410 lpfc_mbx_cmpl_read_topology(phba, pmb);
5417 mempool_free(pmb, phba->mbox_mem_pool);
5421 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5423 * @phba: pointer to lpfc hba data structure.
5424 * @speed_code: asynchronous event link speed code.
5426 * This routine is to parse the giving SLI4 async event link speed code into
5427 * value of Read topology link speed.
5429 * Return: link speed in terms of Read topology.
5432 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5436 switch (speed_code) {
5437 case LPFC_FC_LA_SPEED_1G:
5438 port_speed = LPFC_LINK_SPEED_1GHZ;
5440 case LPFC_FC_LA_SPEED_2G:
5441 port_speed = LPFC_LINK_SPEED_2GHZ;
5443 case LPFC_FC_LA_SPEED_4G:
5444 port_speed = LPFC_LINK_SPEED_4GHZ;
5446 case LPFC_FC_LA_SPEED_8G:
5447 port_speed = LPFC_LINK_SPEED_8GHZ;
5449 case LPFC_FC_LA_SPEED_16G:
5450 port_speed = LPFC_LINK_SPEED_16GHZ;
5452 case LPFC_FC_LA_SPEED_32G:
5453 port_speed = LPFC_LINK_SPEED_32GHZ;
5455 case LPFC_FC_LA_SPEED_64G:
5456 port_speed = LPFC_LINK_SPEED_64GHZ;
5458 case LPFC_FC_LA_SPEED_128G:
5459 port_speed = LPFC_LINK_SPEED_128GHZ;
5461 case LPFC_FC_LA_SPEED_256G:
5462 port_speed = LPFC_LINK_SPEED_256GHZ;
5473 lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
5475 struct rxtable_entry *entry;
5476 int cnt = 0, head, tail, last, start;
5478 head = atomic_read(&phba->rxtable_idx_head);
5479 tail = atomic_read(&phba->rxtable_idx_tail);
5480 if (!phba->rxtable || head == tail) {
5481 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
5482 "4411 Rxtable is empty\n");
5488 /* Display the last LPFC_MAX_RXMONITOR_DUMP entries from the rxtable */
5489 while (start != last) {
5493 start = LPFC_MAX_RXMONITOR_ENTRY - 1;
5494 entry = &phba->rxtable[start];
5495 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5496 "4410 %02d: MBPI %lld Xmit %lld Cmpl %lld "
5497 "Lat %lld ASz %lld Info %02d BWUtil %d "
5499 cnt, entry->max_bytes_per_interval,
5500 entry->total_bytes, entry->rcv_bytes,
5501 entry->avg_io_latency, entry->avg_io_size,
5502 entry->cmf_info, entry->timer_utilization,
5503 entry->timer_interval, start);
5505 if (cnt >= LPFC_MAX_RXMONITOR_DUMP)
5511 * lpfc_cgn_update_stat - Save data into congestion stats buffer
5512 * @phba: pointer to lpfc hba data structure.
5513 * @dtag: FPIN descriptor received
5515 * Increment the FPIN received counter/time when it happens.
5518 lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
5520 struct lpfc_cgn_info *cp;
5522 struct timespec64 cur_time;
5526 /* Make sure we have a congestion info buffer */
5529 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5530 ktime_get_real_ts64(&cur_time);
5531 time64_to_tm(cur_time.tv_sec, 0, &broken);
5533 /* Update congestion statistics */
5535 case ELS_DTAG_LNK_INTEGRITY:
5536 cnt = le32_to_cpu(cp->link_integ_notification);
5538 cp->link_integ_notification = cpu_to_le32(cnt);
5540 cp->cgn_stat_lnk_month = broken.tm_mon + 1;
5541 cp->cgn_stat_lnk_day = broken.tm_mday;
5542 cp->cgn_stat_lnk_year = broken.tm_year - 100;
5543 cp->cgn_stat_lnk_hour = broken.tm_hour;
5544 cp->cgn_stat_lnk_min = broken.tm_min;
5545 cp->cgn_stat_lnk_sec = broken.tm_sec;
5547 case ELS_DTAG_DELIVERY:
5548 cnt = le32_to_cpu(cp->delivery_notification);
5550 cp->delivery_notification = cpu_to_le32(cnt);
5552 cp->cgn_stat_del_month = broken.tm_mon + 1;
5553 cp->cgn_stat_del_day = broken.tm_mday;
5554 cp->cgn_stat_del_year = broken.tm_year - 100;
5555 cp->cgn_stat_del_hour = broken.tm_hour;
5556 cp->cgn_stat_del_min = broken.tm_min;
5557 cp->cgn_stat_del_sec = broken.tm_sec;
5559 case ELS_DTAG_PEER_CONGEST:
5560 cnt = le32_to_cpu(cp->cgn_peer_notification);
5562 cp->cgn_peer_notification = cpu_to_le32(cnt);
5564 cp->cgn_stat_peer_month = broken.tm_mon + 1;
5565 cp->cgn_stat_peer_day = broken.tm_mday;
5566 cp->cgn_stat_peer_year = broken.tm_year - 100;
5567 cp->cgn_stat_peer_hour = broken.tm_hour;
5568 cp->cgn_stat_peer_min = broken.tm_min;
5569 cp->cgn_stat_peer_sec = broken.tm_sec;
5571 case ELS_DTAG_CONGESTION:
5572 cnt = le32_to_cpu(cp->cgn_notification);
5574 cp->cgn_notification = cpu_to_le32(cnt);
5576 cp->cgn_stat_cgn_month = broken.tm_mon + 1;
5577 cp->cgn_stat_cgn_day = broken.tm_mday;
5578 cp->cgn_stat_cgn_year = broken.tm_year - 100;
5579 cp->cgn_stat_cgn_hour = broken.tm_hour;
5580 cp->cgn_stat_cgn_min = broken.tm_min;
5581 cp->cgn_stat_cgn_sec = broken.tm_sec;
5583 if (phba->cgn_fpin_frequency &&
5584 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5585 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5586 cp->cgn_stat_npm = value;
5588 value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5589 LPFC_CGN_CRC32_SEED);
5590 cp->cgn_info_crc = cpu_to_le32(value);
5594 * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer
5595 * @phba: pointer to lpfc hba data structure.
5597 * Save the congestion event data every minute.
5598 * On the hour collapse all the minute data into hour data. Every day
5599 * collapse all the hour data into daily data. Separate driver
5600 * and fabrc congestion event counters that will be saved out
5601 * to the registered congestion buffer every minute.
5604 lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba)
5606 struct lpfc_cgn_info *cp;
5608 struct timespec64 cur_time;
5610 uint16_t value, mvalue;
5613 uint32_t dvalue, wvalue, lvalue, avalue;
5619 /* Make sure we have a congestion info buffer */
5622 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5624 if (time_before(jiffies, phba->cgn_evt_timestamp))
5626 phba->cgn_evt_timestamp = jiffies +
5627 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
5628 phba->cgn_evt_minute++;
5630 /* We should get to this point in the routine on 1 minute intervals */
5632 ktime_get_real_ts64(&cur_time);
5633 time64_to_tm(cur_time.tv_sec, 0, &broken);
5635 if (phba->cgn_fpin_frequency &&
5636 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5637 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5638 cp->cgn_stat_npm = value;
5641 /* Read and clear the latency counters for this minute */
5642 lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
5643 latsum = atomic64_read(&phba->cgn_latency_evt);
5644 atomic_set(&phba->cgn_latency_evt_cnt, 0);
5645 atomic64_set(&phba->cgn_latency_evt, 0);
5647 /* We need to store MB/sec bandwidth in the congestion information.
5648 * block_cnt is count of 512 byte blocks for the entire minute,
5649 * bps will get bytes per sec before finally converting to MB/sec.
5651 bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
5652 phba->rx_block_cnt = 0;
5653 mvalue = bps / (1024 * 1024); /* convert to MB/sec */
5656 /* cgn parameters */
5657 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
5658 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
5659 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
5660 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
5662 /* Fill in default LUN qdepth */
5663 value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
5664 cp->cgn_lunq = cpu_to_le16(value);
5666 /* Record congestion buffer info - every minute
5667 * cgn_driver_evt_cnt (Driver events)
5668 * cgn_fabric_warn_cnt (Congestion Warnings)
5669 * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
5670 * cgn_fabric_alarm_cnt (Congestion Alarms)
5672 index = ++cp->cgn_index_minute;
5673 if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
5674 cp->cgn_index_minute = 0;
5678 /* Get the number of driver events in this sample and reset counter */
5679 dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
5680 atomic_set(&phba->cgn_driver_evt_cnt, 0);
5682 /* Get the number of warning events - FPIN and Signal for this minute */
5684 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
5685 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5686 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5687 wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
5688 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
5690 /* Get the number of alarm events - FPIN and Signal for this minute */
5692 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
5693 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5694 avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
5695 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
5697 /* Collect the driver, warning, alarm and latency counts for this
5698 * minute into the driver congestion buffer.
5700 ptr = &cp->cgn_drvr_min[index];
5701 value = (uint16_t)dvalue;
5702 *ptr = cpu_to_le16(value);
5704 ptr = &cp->cgn_warn_min[index];
5705 value = (uint16_t)wvalue;
5706 *ptr = cpu_to_le16(value);
5708 ptr = &cp->cgn_alarm_min[index];
5709 value = (uint16_t)avalue;
5710 *ptr = cpu_to_le16(value);
5712 lptr = &cp->cgn_latency_min[index];
5714 lvalue = (uint32_t)div_u64(latsum, lvalue);
5715 *lptr = cpu_to_le32(lvalue);
5720 /* Collect the bandwidth value into the driver's congesion buffer. */
5721 mptr = &cp->cgn_bw_min[index];
5722 *mptr = cpu_to_le16(mvalue);
5724 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5725 "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
5726 index, dvalue, wvalue, *lptr, mvalue, avalue);
5729 if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
5730 /* Record congestion buffer info - every hour
5731 * Collapse all minutes into an hour
5733 index = ++cp->cgn_index_hour;
5734 if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
5735 cp->cgn_index_hour = 0;
5745 for (i = 0; i < LPFC_MIN_HOUR; i++) {
5746 dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
5747 wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
5748 lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
5749 mbps += le16_to_cpu(cp->cgn_bw_min[i]);
5750 avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
5752 if (lvalue) /* Avg of latency averages */
5753 lvalue /= LPFC_MIN_HOUR;
5754 if (mbps) /* Avg of Bandwidth averages */
5755 mvalue = mbps / LPFC_MIN_HOUR;
5757 lptr = &cp->cgn_drvr_hr[index];
5758 *lptr = cpu_to_le32(dvalue);
5759 lptr = &cp->cgn_warn_hr[index];
5760 *lptr = cpu_to_le32(wvalue);
5761 lptr = &cp->cgn_latency_hr[index];
5762 *lptr = cpu_to_le32(lvalue);
5763 mptr = &cp->cgn_bw_hr[index];
5764 *mptr = cpu_to_le16(mvalue);
5765 lptr = &cp->cgn_alarm_hr[index];
5766 *lptr = cpu_to_le32(avalue);
5768 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5769 "2419 Congestion Info - hour "
5770 "(%d): %d %d %d %d %d\n",
5771 index, dvalue, wvalue, lvalue, mvalue, avalue);
5775 if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
5776 /* Record congestion buffer info - every hour
5777 * Collapse all hours into a day. Rotate days
5778 * after LPFC_MAX_CGN_DAYS.
5780 index = ++cp->cgn_index_day;
5781 if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
5782 cp->cgn_index_day = 0;
5786 /* Anytime we overwrite daily index 0, after we wrap,
5787 * we will be overwriting the oldest day, so we must
5788 * update the congestion data start time for that day.
5789 * That start time should have previously been saved after
5790 * we wrote the last days worth of data.
5792 if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) {
5793 time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken);
5795 cp->cgn_info_month = broken.tm_mon + 1;
5796 cp->cgn_info_day = broken.tm_mday;
5797 cp->cgn_info_year = broken.tm_year - 100;
5798 cp->cgn_info_hour = broken.tm_hour;
5799 cp->cgn_info_minute = broken.tm_min;
5800 cp->cgn_info_second = broken.tm_sec;
5803 (phba, KERN_INFO, LOG_CGN_MGMT,
5804 "2646 CGNInfo idx0 Start Time: "
5805 "%d/%d/%d %d:%d:%d\n",
5806 cp->cgn_info_day, cp->cgn_info_month,
5807 cp->cgn_info_year, cp->cgn_info_hour,
5808 cp->cgn_info_minute, cp->cgn_info_second);
5817 for (i = 0; i < LPFC_HOUR_DAY; i++) {
5818 dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
5819 wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
5820 lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
5821 mbps += le16_to_cpu(cp->cgn_bw_hr[i]);
5822 avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
5824 if (lvalue) /* Avg of latency averages */
5825 lvalue /= LPFC_HOUR_DAY;
5826 if (mbps) /* Avg of Bandwidth averages */
5827 mvalue = mbps / LPFC_HOUR_DAY;
5829 lptr = &cp->cgn_drvr_day[index];
5830 *lptr = cpu_to_le32(dvalue);
5831 lptr = &cp->cgn_warn_day[index];
5832 *lptr = cpu_to_le32(wvalue);
5833 lptr = &cp->cgn_latency_day[index];
5834 *lptr = cpu_to_le32(lvalue);
5835 mptr = &cp->cgn_bw_day[index];
5836 *mptr = cpu_to_le16(mvalue);
5837 lptr = &cp->cgn_alarm_day[index];
5838 *lptr = cpu_to_le32(avalue);
5840 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5841 "2420 Congestion Info - daily (%d): "
5843 index, dvalue, wvalue, lvalue, mvalue, avalue);
5845 /* We just wrote LPFC_MAX_CGN_DAYS of data,
5846 * so we are wrapped on any data after this.
5847 * Save this as the start time for the next day.
5849 if (index == (LPFC_MAX_CGN_DAYS - 1)) {
5850 phba->hba_flag |= HBA_CGN_DAY_WRAP;
5851 ktime_get_real_ts64(&phba->cgn_daily_ts);
5855 /* Use the frequency found in the last rcv'ed FPIN */
5856 value = phba->cgn_fpin_frequency;
5857 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN)
5858 cp->cgn_warn_freq = cpu_to_le16(value);
5859 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM)
5860 cp->cgn_alarm_freq = cpu_to_le16(value);
5862 /* Frequency (in ms) Signal Warning/Signal Congestion Notifications
5863 * are received by the HBA
5865 value = phba->cgn_sig_freq;
5867 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5868 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5869 cp->cgn_warn_freq = cpu_to_le16(value);
5870 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5871 cp->cgn_alarm_freq = cpu_to_le16(value);
5873 lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5874 LPFC_CGN_CRC32_SEED);
5875 cp->cgn_info_crc = cpu_to_le32(lvalue);
5879 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5880 * @phba: The Hba for which this call is being executed.
5882 * The routine calculates the latency from the beginning of the CMF timer
5883 * interval to the current point in time. It is called from IO completion
5884 * when we exceed our Bandwidth limitation for the time interval.
5887 lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5889 struct timespec64 cmpl_time;
5892 ktime_get_real_ts64(&cmpl_time);
5894 /* This routine works on a ms granularity so sec and usec are
5895 * converted accordingly.
5897 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5898 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5901 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5902 msec = (cmpl_time.tv_sec -
5903 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5904 msec += ((cmpl_time.tv_nsec -
5905 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5907 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5909 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5910 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5917 * lpfc_cmf_timer - This is the timer function for one congestion
5919 * @timer: Pointer to the high resolution timer that expired
5921 static enum hrtimer_restart
5922 lpfc_cmf_timer(struct hrtimer *timer)
5924 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5926 struct rxtable_entry *entry;
5928 uint32_t head, tail;
5929 uint32_t busy, max_read;
5930 uint64_t total, rcv, lat, mbpi, extra;
5931 int timer_interval = LPFC_CMF_INTERVAL;
5933 struct lpfc_cgn_stat *cgs;
5936 /* Only restart the timer if congestion mgmt is on */
5937 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5938 !phba->cmf_latency.tv_sec) {
5939 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5940 "6224 CMF timer exit: %d %lld\n",
5941 phba->cmf_active_mode,
5942 (uint64_t)phba->cmf_latency.tv_sec);
5943 return HRTIMER_NORESTART;
5946 /* If pport is not ready yet, just exit and wait for
5947 * the next timer cycle to hit.
5952 /* Do not block SCSI IO while in the timer routine since
5953 * total_bytes will be cleared
5955 atomic_set(&phba->cmf_stop_io, 1);
5957 /* First we need to calculate the actual ms between
5958 * the last timer interrupt and this one. We ask for
5959 * LPFC_CMF_INTERVAL, however the actual time may
5960 * vary depending on system overhead.
5962 ms = lpfc_calc_cmf_latency(phba);
5965 /* Immediately after we calculate the time since the last
5966 * timer interrupt, set the start time for the next
5969 ktime_get_real_ts64(&phba->cmf_latency);
5971 phba->cmf_link_byte_count =
5972 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
5974 /* Collect all the stats from the prior timer interval */
5979 for_each_present_cpu(cpu) {
5980 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
5981 total += atomic64_xchg(&cgs->total_bytes, 0);
5982 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
5983 lat += atomic64_xchg(&cgs->rx_latency, 0);
5984 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
5987 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
5988 * returned from the last CMF_SYNC_WQE issued, from
5989 * cmf_last_sync_bw. This will be the target BW for
5990 * this next timer interval.
5992 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
5993 phba->link_state != LPFC_LINK_DOWN &&
5994 phba->hba_flag & HBA_SETUP) {
5995 mbpi = phba->cmf_last_sync_bw;
5996 phba->cmf_last_sync_bw = 0;
5999 /* Calculate any extra bytes needed to account for the
6000 * timer accuracy. If we are less than LPFC_CMF_INTERVAL
6001 * add an extra 3% slop factor, equal to LPFC_CMF_INTERVAL
6002 * add an extra 2%. The goal is to equalize total with a
6003 * time > LPFC_CMF_INTERVAL or <= LPFC_CMF_INTERVAL + 1
6005 if (ms == LPFC_CMF_INTERVAL)
6006 extra = div_u64(total, 50);
6007 else if (ms < LPFC_CMF_INTERVAL)
6008 extra = div_u64(total, 33);
6009 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
6011 /* For Monitor mode or link down we want mbpi
6012 * to be the full link speed
6014 mbpi = phba->cmf_link_byte_count;
6016 phba->cmf_timer_cnt++;
6019 /* Update congestion info buffer latency in us */
6020 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
6021 atomic64_add(lat, &phba->cgn_latency_evt);
6023 busy = atomic_xchg(&phba->cmf_busy, 0);
6024 max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
6026 /* Calculate MBPI for the next timer interval */
6028 if (mbpi > phba->cmf_link_byte_count ||
6029 phba->cmf_active_mode == LPFC_CFG_MONITOR)
6030 mbpi = phba->cmf_link_byte_count;
6032 /* Change max_bytes_per_interval to what the prior
6033 * CMF_SYNC_WQE cmpl indicated.
6035 if (mbpi != phba->cmf_max_bytes_per_interval)
6036 phba->cmf_max_bytes_per_interval = mbpi;
6039 /* Save rxmonitor information for debug */
6040 if (phba->rxtable) {
6041 head = atomic_xchg(&phba->rxtable_idx_head,
6042 LPFC_RXMONITOR_TABLE_IN_USE);
6043 entry = &phba->rxtable[head];
6044 entry->total_bytes = total;
6045 entry->rcv_bytes = rcv;
6046 entry->cmf_busy = busy;
6047 entry->cmf_info = phba->cmf_active_info;
6049 entry->avg_io_latency = div_u64(lat, io_cnt);
6050 entry->avg_io_size = div_u64(rcv, io_cnt);
6052 entry->avg_io_latency = 0;
6053 entry->avg_io_size = 0;
6055 entry->max_read_cnt = max_read;
6056 entry->io_cnt = io_cnt;
6057 entry->max_bytes_per_interval = mbpi;
6058 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
6059 entry->timer_utilization = phba->cmf_last_ts;
6061 entry->timer_utilization = ms;
6062 entry->timer_interval = ms;
6063 phba->cmf_last_ts = 0;
6065 /* Increment rxtable index */
6066 head = (head + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6067 tail = atomic_read(&phba->rxtable_idx_tail);
6069 tail = (tail + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6070 atomic_set(&phba->rxtable_idx_tail, tail);
6072 atomic_set(&phba->rxtable_idx_head, head);
6075 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
6076 /* If Monitor mode, check if we are oversubscribed
6077 * against the full line rate.
6079 if (mbpi && total > mbpi)
6080 atomic_inc(&phba->cgn_driver_evt_cnt);
6082 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
6084 /* Each minute save Fabric and Driver congestion information */
6085 lpfc_cgn_save_evt_cnt(phba);
6087 /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the
6088 * minute, adjust our next timer interval, if needed, to ensure a
6089 * 1 minute granularity when we get the next timer interrupt.
6091 if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL),
6092 phba->cgn_evt_timestamp)) {
6093 timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp -
6095 if (timer_interval <= 0)
6096 timer_interval = LPFC_CMF_INTERVAL;
6098 /* If we adjust timer_interval, max_bytes_per_interval
6099 * needs to be adjusted as well.
6101 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
6102 timer_interval, 1000);
6103 if (phba->cmf_active_mode == LPFC_CFG_MONITOR)
6104 phba->cmf_max_bytes_per_interval =
6105 phba->cmf_link_byte_count;
6108 /* Since total_bytes has already been zero'ed, its okay to unblock
6109 * after max_bytes_per_interval is setup.
6111 if (atomic_xchg(&phba->cmf_bw_wait, 0))
6112 queue_work(phba->wq, &phba->unblock_request_work);
6114 /* SCSI IO is now unblocked */
6115 atomic_set(&phba->cmf_stop_io, 0);
6118 hrtimer_forward_now(timer,
6119 ktime_set(0, timer_interval * NSEC_PER_MSEC));
6120 return HRTIMER_RESTART;
6123 #define trunk_link_status(__idx)\
6124 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6125 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
6126 "Link up" : "Link down") : "NA"
6127 /* Did port __idx reported an error */
6128 #define trunk_port_fault(__idx)\
6129 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6130 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
6133 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
6134 struct lpfc_acqe_fc_la *acqe_fc)
6136 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
6137 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
6139 phba->sli4_hba.link_state.speed =
6140 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6141 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6143 phba->sli4_hba.link_state.logical_speed =
6144 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6145 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
6146 phba->fc_linkspeed =
6147 lpfc_async_link_speed_to_read_top(
6149 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6151 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
6152 phba->trunk_link.link0.state =
6153 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
6154 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6155 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
6157 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
6158 phba->trunk_link.link1.state =
6159 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
6160 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6161 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
6163 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
6164 phba->trunk_link.link2.state =
6165 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
6166 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6167 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
6169 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
6170 phba->trunk_link.link3.state =
6171 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
6172 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6173 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
6176 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6177 "2910 Async FC Trunking Event - Speed:%d\n"
6178 "\tLogical speed:%d "
6179 "port0: %s port1: %s port2: %s port3: %s\n",
6180 phba->sli4_hba.link_state.speed,
6181 phba->sli4_hba.link_state.logical_speed,
6182 trunk_link_status(0), trunk_link_status(1),
6183 trunk_link_status(2), trunk_link_status(3));
6185 if (phba->cmf_active_mode != LPFC_CFG_OFF)
6186 lpfc_cmf_signal_init(phba);
6189 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6190 "3202 trunk error:0x%x (%s) seen on port0:%s "
6192 * SLI-4: We have only 0xA error codes
6193 * defined as of now. print an appropriate
6194 * message in case driver needs to be updated.
6196 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
6197 "UNDEFINED. update driver." : trunk_errmsg[err],
6198 trunk_port_fault(0), trunk_port_fault(1),
6199 trunk_port_fault(2), trunk_port_fault(3));
6204 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
6205 * @phba: pointer to lpfc hba data structure.
6206 * @acqe_fc: pointer to the async fc completion queue entry.
6208 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
6209 * that the event was received and then issue a read_topology mailbox command so
6210 * that the rest of the driver will treat it the same as SLI3.
6213 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
6215 struct lpfc_dmabuf *mp;
6218 struct lpfc_mbx_read_top *la;
6221 if (bf_get(lpfc_trailer_type, acqe_fc) !=
6222 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
6223 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6224 "2895 Non FC link Event detected.(%d)\n",
6225 bf_get(lpfc_trailer_type, acqe_fc));
6229 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6230 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
6231 lpfc_update_trunk_link_status(phba, acqe_fc);
6235 /* Keep the link status for extra SLI4 state machine reference */
6236 phba->sli4_hba.link_state.speed =
6237 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6238 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6239 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
6240 phba->sli4_hba.link_state.topology =
6241 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
6242 phba->sli4_hba.link_state.status =
6243 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
6244 phba->sli4_hba.link_state.type =
6245 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
6246 phba->sli4_hba.link_state.number =
6247 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
6248 phba->sli4_hba.link_state.fault =
6249 bf_get(lpfc_acqe_link_fault, acqe_fc);
6251 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6252 LPFC_FC_LA_TYPE_LINK_DOWN)
6253 phba->sli4_hba.link_state.logical_speed = 0;
6254 else if (!phba->sli4_hba.conf_trunk)
6255 phba->sli4_hba.link_state.logical_speed =
6256 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6258 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6259 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
6260 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
6261 "%dMbps Fault:%d\n",
6262 phba->sli4_hba.link_state.speed,
6263 phba->sli4_hba.link_state.topology,
6264 phba->sli4_hba.link_state.status,
6265 phba->sli4_hba.link_state.type,
6266 phba->sli4_hba.link_state.number,
6267 phba->sli4_hba.link_state.logical_speed,
6268 phba->sli4_hba.link_state.fault);
6269 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6271 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6272 "2897 The mboxq allocation failed\n");
6275 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6277 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6278 "2898 The lpfc_dmabuf allocation failed\n");
6281 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
6283 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6284 "2899 The mbuf allocation failed\n");
6285 goto out_free_dmabuf;
6288 /* Cleanup any outstanding ELS commands */
6289 lpfc_els_flush_all_cmd(phba);
6291 /* Block ELS IOCBs until we have done process link event */
6292 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
6294 /* Update link event statistics */
6295 phba->sli.slistat.link_event++;
6297 /* Create lpfc_handle_latt mailbox command from link ACQE */
6298 lpfc_read_topology(phba, pmb, mp);
6299 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
6300 pmb->vport = phba->pport;
6302 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
6303 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
6305 switch (phba->sli4_hba.link_state.status) {
6306 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
6307 phba->link_flag |= LS_MDS_LINK_DOWN;
6309 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
6310 phba->link_flag |= LS_MDS_LOOPBACK;
6316 /* Initialize completion status */
6318 mb->mbxStatus = MBX_SUCCESS;
6320 /* Parse port fault information field */
6321 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
6323 /* Parse and translate link attention fields */
6324 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
6325 la->eventTag = acqe_fc->event_tag;
6327 if (phba->sli4_hba.link_state.status ==
6328 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
6329 bf_set(lpfc_mbx_read_top_att_type, la,
6330 LPFC_FC_LA_TYPE_UNEXP_WWPN);
6332 bf_set(lpfc_mbx_read_top_att_type, la,
6333 LPFC_FC_LA_TYPE_LINK_DOWN);
6335 /* Invoke the mailbox command callback function */
6336 lpfc_mbx_cmpl_read_topology(phba, pmb);
6341 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
6342 if (rc == MBX_NOT_FINISHED) {
6343 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6344 goto out_free_dmabuf;
6351 mempool_free(pmb, phba->mbox_mem_pool);
6355 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
6356 * @phba: pointer to lpfc hba data structure.
6357 * @acqe_sli: pointer to the async SLI completion queue entry.
6359 * This routine is to handle the SLI4 asynchronous SLI events.
6362 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
6368 uint8_t operational = 0;
6369 struct temp_event temp_event_data;
6370 struct lpfc_acqe_misconfigured_event *misconfigured;
6371 struct lpfc_acqe_cgn_signal *cgn_signal;
6372 struct Scsi_Host *shost;
6373 struct lpfc_vport **vports;
6376 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
6378 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6379 "2901 Async SLI event - Type:%d, Event Data: x%08x "
6380 "x%08x x%08x x%08x\n", evt_type,
6381 acqe_sli->event_data1, acqe_sli->event_data2,
6382 acqe_sli->reserved, acqe_sli->trailer);
6384 port_name = phba->Port[0];
6385 if (port_name == 0x00)
6386 port_name = '?'; /* get port name is empty */
6389 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
6390 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6391 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6392 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6394 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6395 "3190 Over Temperature:%d Celsius- Port Name %c\n",
6396 acqe_sli->event_data1, port_name);
6398 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
6399 shost = lpfc_shost_from_vport(phba->pport);
6400 fc_host_post_vendor_event(shost, fc_get_event_number(),
6401 sizeof(temp_event_data),
6402 (char *)&temp_event_data,
6403 SCSI_NL_VID_TYPE_PCI
6404 | PCI_VENDOR_ID_EMULEX);
6406 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
6407 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6408 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6409 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6411 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6412 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
6413 acqe_sli->event_data1, port_name);
6415 shost = lpfc_shost_from_vport(phba->pport);
6416 fc_host_post_vendor_event(shost, fc_get_event_number(),
6417 sizeof(temp_event_data),
6418 (char *)&temp_event_data,
6419 SCSI_NL_VID_TYPE_PCI
6420 | PCI_VENDOR_ID_EMULEX);
6422 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
6423 misconfigured = (struct lpfc_acqe_misconfigured_event *)
6424 &acqe_sli->event_data1;
6426 /* fetch the status for this port */
6427 switch (phba->sli4_hba.lnk_info.lnk_no) {
6428 case LPFC_LINK_NUMBER_0:
6429 status = bf_get(lpfc_sli_misconfigured_port0_state,
6430 &misconfigured->theEvent);
6431 operational = bf_get(lpfc_sli_misconfigured_port0_op,
6432 &misconfigured->theEvent);
6434 case LPFC_LINK_NUMBER_1:
6435 status = bf_get(lpfc_sli_misconfigured_port1_state,
6436 &misconfigured->theEvent);
6437 operational = bf_get(lpfc_sli_misconfigured_port1_op,
6438 &misconfigured->theEvent);
6440 case LPFC_LINK_NUMBER_2:
6441 status = bf_get(lpfc_sli_misconfigured_port2_state,
6442 &misconfigured->theEvent);
6443 operational = bf_get(lpfc_sli_misconfigured_port2_op,
6444 &misconfigured->theEvent);
6446 case LPFC_LINK_NUMBER_3:
6447 status = bf_get(lpfc_sli_misconfigured_port3_state,
6448 &misconfigured->theEvent);
6449 operational = bf_get(lpfc_sli_misconfigured_port3_op,
6450 &misconfigured->theEvent);
6453 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6455 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
6456 "event: Invalid link %d",
6457 phba->sli4_hba.lnk_info.lnk_no);
6461 /* Skip if optic state unchanged */
6462 if (phba->sli4_hba.lnk_info.optic_state == status)
6466 case LPFC_SLI_EVENT_STATUS_VALID:
6467 sprintf(message, "Physical Link is functional");
6469 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
6470 sprintf(message, "Optics faulted/incorrectly "
6471 "installed/not installed - Reseat optics, "
6472 "if issue not resolved, replace.");
6474 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
6476 "Optics of two types installed - Remove one "
6477 "optic or install matching pair of optics.");
6479 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
6480 sprintf(message, "Incompatible optics - Replace with "
6481 "compatible optics for card to function.");
6483 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
6484 sprintf(message, "Unqualified optics - Replace with "
6485 "Avago optics for Warranty and Technical "
6486 "Support - Link is%s operational",
6487 (operational) ? " not" : "");
6489 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
6490 sprintf(message, "Uncertified optics - Replace with "
6491 "Avago-certified optics to enable link "
6492 "operation - Link is%s operational",
6493 (operational) ? " not" : "");
6496 /* firmware is reporting a status we don't know about */
6497 sprintf(message, "Unknown event status x%02x", status);
6501 /* Issue READ_CONFIG mbox command to refresh supported speeds */
6502 rc = lpfc_sli4_read_config(phba);
6505 lpfc_printf_log(phba, KERN_ERR,
6507 "3194 Unable to retrieve supported "
6508 "speeds, rc = 0x%x\n", rc);
6510 rc = lpfc_sli4_refresh_params(phba);
6512 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6513 "3174 Unable to update pls support, "
6516 vports = lpfc_create_vport_work_array(phba);
6517 if (vports != NULL) {
6518 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6520 shost = lpfc_shost_from_vport(vports[i]);
6521 lpfc_host_supported_speeds_set(shost);
6524 lpfc_destroy_vport_work_array(phba, vports);
6526 phba->sli4_hba.lnk_info.optic_state = status;
6527 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6528 "3176 Port Name %c %s\n", port_name, message);
6530 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
6531 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6532 "3192 Remote DPort Test Initiated - "
6533 "Event Data1:x%08x Event Data2: x%08x\n",
6534 acqe_sli->event_data1, acqe_sli->event_data2);
6536 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
6537 /* Call FW to obtain active parms */
6538 lpfc_sli4_cgn_parm_chg_evt(phba);
6540 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
6541 /* Misconfigured WWN. Reports that the SLI Port is configured
6542 * to use FA-WWN, but the attached device doesn’t support it.
6543 * No driver action is required.
6544 * Event Data1 - N.A, Event Data2 - N.A
6546 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI,
6547 "2699 Misconfigured FA-WWN - Attached device does "
6548 "not support FA-WWN\n");
6550 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
6551 /* EEPROM failure. No driver action is required */
6552 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6553 "2518 EEPROM failure - "
6554 "Event Data1: x%08x Event Data2: x%08x\n",
6555 acqe_sli->event_data1, acqe_sli->event_data2);
6557 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
6558 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6560 cgn_signal = (struct lpfc_acqe_cgn_signal *)
6561 &acqe_sli->event_data1;
6562 phba->cgn_acqe_cnt++;
6564 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6565 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6566 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6568 /* no threshold for CMF, even 1 signal will trigger an event */
6570 /* Alarm overrides warning, so check that first */
6571 if (cgn_signal->alarm_cnt) {
6572 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6573 /* Keep track of alarm cnt for cgn_info */
6574 atomic_add(cgn_signal->alarm_cnt,
6575 &phba->cgn_fabric_alarm_cnt);
6576 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6577 atomic_add(cgn_signal->alarm_cnt,
6578 &phba->cgn_sync_alarm_cnt);
6581 /* signal action needs to be taken */
6582 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6583 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6584 /* Keep track of warning cnt for cgn_info */
6585 atomic_add(cnt, &phba->cgn_fabric_warn_cnt);
6586 /* Keep track of warning cnt for CMF_SYNC_WQE */
6587 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6592 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6593 "3193 Unrecognized SLI event, type: 0x%x",
6600 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6601 * @vport: pointer to vport data structure.
6603 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6604 * response to a CVL event.
6606 * Return the pointer to the ndlp with the vport if successful, otherwise
6609 static struct lpfc_nodelist *
6610 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6612 struct lpfc_nodelist *ndlp;
6613 struct Scsi_Host *shost;
6614 struct lpfc_hba *phba;
6621 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6623 /* Cannot find existing Fabric ndlp, so allocate a new one */
6624 ndlp = lpfc_nlp_init(vport, Fabric_DID);
6627 /* Set the node type */
6628 ndlp->nlp_type |= NLP_FABRIC;
6629 /* Put ndlp onto node list */
6630 lpfc_enqueue_node(vport, ndlp);
6632 if ((phba->pport->port_state < LPFC_FLOGI) &&
6633 (phba->pport->port_state != LPFC_VPORT_FAILED))
6635 /* If virtual link is not yet instantiated ignore CVL */
6636 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6637 && (vport->port_state != LPFC_VPORT_FAILED))
6639 shost = lpfc_shost_from_vport(vport);
6642 lpfc_linkdown_port(vport);
6643 lpfc_cleanup_pending_mbox(vport);
6644 spin_lock_irq(shost->host_lock);
6645 vport->fc_flag |= FC_VPORT_CVL_RCVD;
6646 spin_unlock_irq(shost->host_lock);
6652 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
6653 * @phba: pointer to lpfc hba data structure.
6655 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6656 * response to a FCF dead event.
6659 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6661 struct lpfc_vport **vports;
6664 vports = lpfc_create_vport_work_array(phba);
6666 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6667 lpfc_sli4_perform_vport_cvl(vports[i]);
6668 lpfc_destroy_vport_work_array(phba, vports);
6672 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
6673 * @phba: pointer to lpfc hba data structure.
6674 * @acqe_fip: pointer to the async fcoe completion queue entry.
6676 * This routine is to handle the SLI4 asynchronous fcoe event.
6679 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
6680 struct lpfc_acqe_fip *acqe_fip)
6682 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
6684 struct lpfc_vport *vport;
6685 struct lpfc_nodelist *ndlp;
6686 int active_vlink_present;
6687 struct lpfc_vport **vports;
6690 phba->fc_eventTag = acqe_fip->event_tag;
6691 phba->fcoe_eventtag = acqe_fip->event_tag;
6692 switch (event_type) {
6693 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6694 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6695 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
6696 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6697 "2546 New FCF event, evt_tag:x%x, "
6699 acqe_fip->event_tag,
6702 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6704 "2788 FCF param modified event, "
6705 "evt_tag:x%x, index:x%x\n",
6706 acqe_fip->event_tag,
6708 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6710 * During period of FCF discovery, read the FCF
6711 * table record indexed by the event to update
6712 * FCF roundrobin failover eligible FCF bmask.
6714 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6716 "2779 Read FCF (x%x) for updating "
6717 "roundrobin FCF failover bmask\n",
6719 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
6722 /* If the FCF discovery is in progress, do nothing. */
6723 spin_lock_irq(&phba->hbalock);
6724 if (phba->hba_flag & FCF_TS_INPROG) {
6725 spin_unlock_irq(&phba->hbalock);
6728 /* If fast FCF failover rescan event is pending, do nothing */
6729 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
6730 spin_unlock_irq(&phba->hbalock);
6734 /* If the FCF has been in discovered state, do nothing. */
6735 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
6736 spin_unlock_irq(&phba->hbalock);
6739 spin_unlock_irq(&phba->hbalock);
6741 /* Otherwise, scan the entire FCF table and re-discover SAN */
6742 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6743 "2770 Start FCF table scan per async FCF "
6744 "event, evt_tag:x%x, index:x%x\n",
6745 acqe_fip->event_tag, acqe_fip->index);
6746 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6747 LPFC_FCOE_FCF_GET_FIRST);
6749 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6750 "2547 Issue FCF scan read FCF mailbox "
6751 "command failed (x%x)\n", rc);
6754 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
6755 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6756 "2548 FCF Table full count 0x%x tag 0x%x\n",
6757 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6758 acqe_fip->event_tag);
6761 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
6762 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6763 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6764 "2549 FCF (x%x) disconnected from network, "
6765 "tag:x%x\n", acqe_fip->index,
6766 acqe_fip->event_tag);
6768 * If we are in the middle of FCF failover process, clear
6769 * the corresponding FCF bit in the roundrobin bitmap.
6771 spin_lock_irq(&phba->hbalock);
6772 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6773 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
6774 spin_unlock_irq(&phba->hbalock);
6775 /* Update FLOGI FCF failover eligible FCF bmask */
6776 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
6779 spin_unlock_irq(&phba->hbalock);
6781 /* If the event is not for currently used fcf do nothing */
6782 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
6786 * Otherwise, request the port to rediscover the entire FCF
6787 * table for a fast recovery from case that the current FCF
6788 * is no longer valid as we are not in the middle of FCF
6789 * failover process already.
6791 spin_lock_irq(&phba->hbalock);
6792 /* Mark the fast failover process in progress */
6793 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6794 spin_unlock_irq(&phba->hbalock);
6796 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6797 "2771 Start FCF fast failover process due to "
6798 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6799 "\n", acqe_fip->event_tag, acqe_fip->index);
6800 rc = lpfc_sli4_redisc_fcf_table(phba);
6802 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6804 "2772 Issue FCF rediscover mailbox "
6805 "command failed, fail through to FCF "
6807 spin_lock_irq(&phba->hbalock);
6808 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6809 spin_unlock_irq(&phba->hbalock);
6811 * Last resort will fail over by treating this
6812 * as a link down to FCF registration.
6814 lpfc_sli4_fcf_dead_failthrough(phba);
6816 /* Reset FCF roundrobin bmask for new discovery */
6817 lpfc_sli4_clear_fcf_rr_bmask(phba);
6819 * Handling fast FCF failover to a DEAD FCF event is
6820 * considered equalivant to receiving CVL to all vports.
6822 lpfc_sli4_perform_all_vport_cvl(phba);
6825 case LPFC_FIP_EVENT_TYPE_CVL:
6826 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6827 lpfc_printf_log(phba, KERN_ERR,
6829 "2718 Clear Virtual Link Received for VPI 0x%x"
6830 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
6832 vport = lpfc_find_vport_by_vpid(phba,
6834 ndlp = lpfc_sli4_perform_vport_cvl(vport);
6837 active_vlink_present = 0;
6839 vports = lpfc_create_vport_work_array(phba);
6841 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6843 if ((!(vports[i]->fc_flag &
6844 FC_VPORT_CVL_RCVD)) &&
6845 (vports[i]->port_state > LPFC_FDISC)) {
6846 active_vlink_present = 1;
6850 lpfc_destroy_vport_work_array(phba, vports);
6854 * Don't re-instantiate if vport is marked for deletion.
6855 * If we are here first then vport_delete is going to wait
6856 * for discovery to complete.
6858 if (!(vport->load_flag & FC_UNLOADING) &&
6859 active_vlink_present) {
6861 * If there are other active VLinks present,
6862 * re-instantiate the Vlink using FDISC.
6864 mod_timer(&ndlp->nlp_delayfunc,
6865 jiffies + msecs_to_jiffies(1000));
6866 spin_lock_irq(&ndlp->lock);
6867 ndlp->nlp_flag |= NLP_DELAY_TMO;
6868 spin_unlock_irq(&ndlp->lock);
6869 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6870 vport->port_state = LPFC_FDISC;
6873 * Otherwise, we request port to rediscover
6874 * the entire FCF table for a fast recovery
6875 * from possible case that the current FCF
6876 * is no longer valid if we are not already
6877 * in the FCF failover process.
6879 spin_lock_irq(&phba->hbalock);
6880 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6881 spin_unlock_irq(&phba->hbalock);
6884 /* Mark the fast failover process in progress */
6885 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
6886 spin_unlock_irq(&phba->hbalock);
6887 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6889 "2773 Start FCF failover per CVL, "
6890 "evt_tag:x%x\n", acqe_fip->event_tag);
6891 rc = lpfc_sli4_redisc_fcf_table(phba);
6893 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6895 "2774 Issue FCF rediscover "
6896 "mailbox command failed, "
6897 "through to CVL event\n");
6898 spin_lock_irq(&phba->hbalock);
6899 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
6900 spin_unlock_irq(&phba->hbalock);
6902 * Last resort will be re-try on the
6903 * the current registered FCF entry.
6905 lpfc_retry_pport_discovery(phba);
6908 * Reset FCF roundrobin bmask for new
6911 lpfc_sli4_clear_fcf_rr_bmask(phba);
6915 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6916 "0288 Unknown FCoE event type 0x%x event tag "
6917 "0x%x\n", event_type, acqe_fip->event_tag);
6923 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
6924 * @phba: pointer to lpfc hba data structure.
6925 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
6927 * This routine is to handle the SLI4 asynchronous dcbx event.
6930 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
6931 struct lpfc_acqe_dcbx *acqe_dcbx)
6933 phba->fc_eventTag = acqe_dcbx->event_tag;
6934 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6935 "0290 The SLI4 DCBX asynchronous event is not "
6940 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
6941 * @phba: pointer to lpfc hba data structure.
6942 * @acqe_grp5: pointer to the async grp5 completion queue entry.
6944 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
6945 * is an asynchronous notified of a logical link speed change. The Port
6946 * reports the logical link speed in units of 10Mbps.
6949 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
6950 struct lpfc_acqe_grp5 *acqe_grp5)
6952 uint16_t prev_ll_spd;
6954 phba->fc_eventTag = acqe_grp5->event_tag;
6955 phba->fcoe_eventtag = acqe_grp5->event_tag;
6956 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
6957 phba->sli4_hba.link_state.logical_speed =
6958 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
6959 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6960 "2789 GRP5 Async Event: Updating logical link speed "
6961 "from %dMbps to %dMbps\n", prev_ll_spd,
6962 phba->sli4_hba.link_state.logical_speed);
6966 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
6967 * @phba: pointer to lpfc hba data structure.
6969 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
6970 * is an asynchronous notification of a request to reset CM stats.
6973 lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
6977 lpfc_init_congestion_stat(phba);
6981 * lpfc_cgn_params_val - Validate FW congestion parameters.
6982 * @phba: pointer to lpfc hba data structure.
6983 * @p_cfg_param: pointer to FW provided congestion parameters.
6985 * This routine validates the congestion parameters passed
6986 * by the FW to the driver via an ACQE event.
6989 lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
6991 spin_lock_irq(&phba->hbalock);
6993 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
6994 LPFC_CFG_MONITOR)) {
6995 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
6996 "6225 CMF mode param out of range: %d\n",
6997 p_cfg_param->cgn_param_mode);
6998 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
7001 spin_unlock_irq(&phba->hbalock);
7005 * lpfc_cgn_params_parse - Process a FW cong parm change event
7006 * @phba: pointer to lpfc hba data structure.
7007 * @p_cgn_param: pointer to a data buffer with the FW cong params.
7008 * @len: the size of pdata in bytes.
7010 * This routine validates the congestion management buffer signature
7011 * from the FW, validates the contents and makes corrections for
7012 * valid, in-range values. If the signature magic is correct and
7013 * after parameter validation, the contents are copied to the driver's
7014 * @phba structure. If the magic is incorrect, an error message is
7018 lpfc_cgn_params_parse(struct lpfc_hba *phba,
7019 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
7021 struct lpfc_cgn_info *cp;
7022 uint32_t crc, oldmode;
7024 /* Make sure the FW has encoded the correct magic number to
7025 * validate the congestion parameter in FW memory.
7027 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
7028 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7029 "4668 FW cgn parm buffer data: "
7030 "magic 0x%x version %d mode %d "
7031 "level0 %d level1 %d "
7032 "level2 %d byte13 %d "
7033 "byte14 %d byte15 %d "
7034 "byte11 %d byte12 %d activeMode %d\n",
7035 p_cgn_param->cgn_param_magic,
7036 p_cgn_param->cgn_param_version,
7037 p_cgn_param->cgn_param_mode,
7038 p_cgn_param->cgn_param_level0,
7039 p_cgn_param->cgn_param_level1,
7040 p_cgn_param->cgn_param_level2,
7041 p_cgn_param->byte13,
7042 p_cgn_param->byte14,
7043 p_cgn_param->byte15,
7044 p_cgn_param->byte11,
7045 p_cgn_param->byte12,
7046 phba->cmf_active_mode);
7048 oldmode = phba->cmf_active_mode;
7050 /* Any parameters out of range are corrected to defaults
7051 * by this routine. No need to fail.
7053 lpfc_cgn_params_val(phba, p_cgn_param);
7055 /* Parameters are verified, move them into driver storage */
7056 spin_lock_irq(&phba->hbalock);
7057 memcpy(&phba->cgn_p, p_cgn_param,
7058 sizeof(struct lpfc_cgn_param));
7060 /* Update parameters in congestion info buffer now */
7062 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
7063 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
7064 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
7065 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
7066 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
7067 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
7068 LPFC_CGN_CRC32_SEED);
7069 cp->cgn_info_crc = cpu_to_le32(crc);
7071 spin_unlock_irq(&phba->hbalock);
7073 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
7077 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
7078 /* Turning CMF on */
7079 lpfc_cmf_start(phba);
7081 if (phba->link_state >= LPFC_LINK_UP) {
7082 phba->cgn_reg_fpin =
7083 phba->cgn_init_reg_fpin;
7084 phba->cgn_reg_signal =
7085 phba->cgn_init_reg_signal;
7086 lpfc_issue_els_edc(phba->pport, 0);
7090 case LPFC_CFG_MANAGED:
7091 switch (phba->cgn_p.cgn_param_mode) {
7093 /* Turning CMF off */
7094 lpfc_cmf_stop(phba);
7095 if (phba->link_state >= LPFC_LINK_UP)
7096 lpfc_issue_els_edc(phba->pport, 0);
7098 case LPFC_CFG_MONITOR:
7099 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7100 "4661 Switch from MANAGED to "
7102 phba->cmf_max_bytes_per_interval =
7103 phba->cmf_link_byte_count;
7105 /* Resume blocked IO - unblock on workqueue */
7106 queue_work(phba->wq,
7107 &phba->unblock_request_work);
7111 case LPFC_CFG_MONITOR:
7112 switch (phba->cgn_p.cgn_param_mode) {
7114 /* Turning CMF off */
7115 lpfc_cmf_stop(phba);
7116 if (phba->link_state >= LPFC_LINK_UP)
7117 lpfc_issue_els_edc(phba->pport, 0);
7119 case LPFC_CFG_MANAGED:
7120 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7121 "4662 Switch from MONITOR to "
7123 lpfc_cmf_signal_init(phba);
7129 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7130 "4669 FW cgn parm buf wrong magic 0x%x "
7131 "version %d\n", p_cgn_param->cgn_param_magic,
7132 p_cgn_param->cgn_param_version);
7137 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
7138 * @phba: pointer to lpfc hba data structure.
7140 * This routine issues a read_object mailbox command to
7141 * get the congestion management parameters from the FW
7142 * parses it and updates the driver maintained values.
7145 * 0 if the object was empty
7146 * -Eval if an error was encountered
7147 * Count if bytes were read from object
7150 lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
7153 struct lpfc_cgn_param *p_cgn_param = NULL;
7157 /* Find out if the FW has a new set of congestion parameters. */
7158 len = sizeof(struct lpfc_cgn_param);
7159 pdata = kzalloc(len, GFP_KERNEL);
7160 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
7163 /* 0 means no data. A negative means error. A positive means
7164 * bytes were copied.
7167 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7168 "4670 CGN RD OBJ returns no data\n");
7170 } else if (ret < 0) {
7171 /* Some error. Just exit and return it to the caller.*/
7175 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7176 "6234 READ CGN PARAMS Successful %d\n", len);
7178 /* Parse data pointer over len and update the phba congestion
7179 * parameters with values passed back. The receive rate values
7180 * may have been altered in FW, but take no action here.
7182 p_cgn_param = (struct lpfc_cgn_param *)pdata;
7183 lpfc_cgn_params_parse(phba, p_cgn_param, len);
7191 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
7192 * @phba: pointer to lpfc hba data structure.
7194 * The FW generated Async ACQE SLI event calls this routine when
7195 * the event type is an SLI Internal Port Event and the Event Code
7196 * indicates a change to the FW maintained congestion parameters.
7198 * This routine executes a Read_Object mailbox call to obtain the
7199 * current congestion parameters maintained in FW and corrects
7200 * the driver's active congestion parameters.
7202 * The acqe event is not passed because there is no further data
7205 * Returns nonzero error if event processing encountered an error.
7206 * Zero otherwise for success.
7209 lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
7213 if (!phba->sli4_hba.pc_sli4_params.cmf) {
7214 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7215 "4664 Cgn Evt when E2E off. Drop event\n");
7219 /* If the event is claiming an empty object, it's ok. A write
7220 * could have cleared it. Only error is a negative return
7223 ret = lpfc_sli4_cgn_params_read(phba);
7225 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7226 "4667 Error reading Cgn Params (%d)\n",
7229 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7230 "4673 CGN Event empty object.\n");
7236 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
7237 * @phba: pointer to lpfc hba data structure.
7239 * This routine is invoked by the worker thread to process all the pending
7240 * SLI4 asynchronous events.
7242 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
7244 struct lpfc_cq_event *cq_event;
7245 unsigned long iflags;
7247 /* First, declare the async event has been handled */
7248 spin_lock_irqsave(&phba->hbalock, iflags);
7249 phba->hba_flag &= ~ASYNC_EVENT;
7250 spin_unlock_irqrestore(&phba->hbalock, iflags);
7252 /* Now, handle all the async events */
7253 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7254 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
7255 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
7256 cq_event, struct lpfc_cq_event, list);
7257 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
7260 /* Process the asynchronous event */
7261 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
7262 case LPFC_TRAILER_CODE_LINK:
7263 lpfc_sli4_async_link_evt(phba,
7264 &cq_event->cqe.acqe_link);
7266 case LPFC_TRAILER_CODE_FCOE:
7267 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
7269 case LPFC_TRAILER_CODE_DCBX:
7270 lpfc_sli4_async_dcbx_evt(phba,
7271 &cq_event->cqe.acqe_dcbx);
7273 case LPFC_TRAILER_CODE_GRP5:
7274 lpfc_sli4_async_grp5_evt(phba,
7275 &cq_event->cqe.acqe_grp5);
7277 case LPFC_TRAILER_CODE_FC:
7278 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
7280 case LPFC_TRAILER_CODE_SLI:
7281 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
7283 case LPFC_TRAILER_CODE_CMSTAT:
7284 lpfc_sli4_async_cmstat_evt(phba);
7287 lpfc_printf_log(phba, KERN_ERR,
7289 "1804 Invalid asynchronous event code: "
7290 "x%x\n", bf_get(lpfc_trailer_code,
7291 &cq_event->cqe.mcqe_cmpl));
7295 /* Free the completion event processed to the free pool */
7296 lpfc_sli4_cq_event_release(phba, cq_event);
7297 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7299 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
7303 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
7304 * @phba: pointer to lpfc hba data structure.
7306 * This routine is invoked by the worker thread to process FCF table
7307 * rediscovery pending completion event.
7309 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
7313 spin_lock_irq(&phba->hbalock);
7314 /* Clear FCF rediscovery timeout event */
7315 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
7316 /* Clear driver fast failover FCF record flag */
7317 phba->fcf.failover_rec.flag = 0;
7318 /* Set state for FCF fast failover */
7319 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
7320 spin_unlock_irq(&phba->hbalock);
7322 /* Scan FCF table from the first entry to re-discover SAN */
7323 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
7324 "2777 Start post-quiescent FCF table scan\n");
7325 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
7327 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7328 "2747 Issue FCF scan read FCF mailbox "
7329 "command failed 0x%x\n", rc);
7333 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
7334 * @phba: pointer to lpfc hba data structure.
7335 * @dev_grp: The HBA PCI-Device group number.
7337 * This routine is invoked to set up the per HBA PCI-Device group function
7338 * API jump table entries.
7340 * Return: 0 if success, otherwise -ENODEV
7343 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7347 /* Set up lpfc PCI-device group */
7348 phba->pci_dev_grp = dev_grp;
7350 /* The LPFC_PCI_DEV_OC uses SLI4 */
7351 if (dev_grp == LPFC_PCI_DEV_OC)
7352 phba->sli_rev = LPFC_SLI_REV4;
7354 /* Set up device INIT API function jump table */
7355 rc = lpfc_init_api_table_setup(phba, dev_grp);
7358 /* Set up SCSI API function jump table */
7359 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
7362 /* Set up SLI API function jump table */
7363 rc = lpfc_sli_api_table_setup(phba, dev_grp);
7366 /* Set up MBOX API function jump table */
7367 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
7375 * lpfc_log_intr_mode - Log the active interrupt mode
7376 * @phba: pointer to lpfc hba data structure.
7377 * @intr_mode: active interrupt mode adopted.
7379 * This routine it invoked to log the currently used active interrupt mode
7382 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
7384 switch (intr_mode) {
7386 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7387 "0470 Enable INTx interrupt mode.\n");
7390 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7391 "0481 Enabled MSI interrupt mode.\n");
7394 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7395 "0480 Enabled MSI-X interrupt mode.\n");
7398 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7399 "0482 Illegal interrupt mode.\n");
7406 * lpfc_enable_pci_dev - Enable a generic PCI device.
7407 * @phba: pointer to lpfc hba data structure.
7409 * This routine is invoked to enable the PCI device that is common to all
7414 * other values - error
7417 lpfc_enable_pci_dev(struct lpfc_hba *phba)
7419 struct pci_dev *pdev;
7421 /* Obtain PCI device reference */
7425 pdev = phba->pcidev;
7426 /* Enable PCI device */
7427 if (pci_enable_device_mem(pdev))
7429 /* Request PCI resource for the device */
7430 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
7431 goto out_disable_device;
7432 /* Set up device as PCI master and save state for EEH */
7433 pci_set_master(pdev);
7434 pci_try_set_mwi(pdev);
7435 pci_save_state(pdev);
7437 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
7438 if (pci_is_pcie(pdev))
7439 pdev->needs_freset = 1;
7444 pci_disable_device(pdev);
7446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7447 "1401 Failed to enable pci device\n");
7452 * lpfc_disable_pci_dev - Disable a generic PCI device.
7453 * @phba: pointer to lpfc hba data structure.
7455 * This routine is invoked to disable the PCI device that is common to all
7459 lpfc_disable_pci_dev(struct lpfc_hba *phba)
7461 struct pci_dev *pdev;
7463 /* Obtain PCI device reference */
7467 pdev = phba->pcidev;
7468 /* Release PCI resource and disable PCI device */
7469 pci_release_mem_regions(pdev);
7470 pci_disable_device(pdev);
7476 * lpfc_reset_hba - Reset a hba
7477 * @phba: pointer to lpfc hba data structure.
7479 * This routine is invoked to reset a hba device. It brings the HBA
7480 * offline, performs a board restart, and then brings the board back
7481 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
7482 * on outstanding mailbox commands.
7485 lpfc_reset_hba(struct lpfc_hba *phba)
7487 /* If resets are disabled then set error state and return. */
7488 if (!phba->cfg_enable_hba_reset) {
7489 phba->link_state = LPFC_HBA_ERROR;
7493 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
7494 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
7495 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
7497 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
7498 lpfc_sli_flush_io_rings(phba);
7501 lpfc_sli_brdrestart(phba);
7503 lpfc_unblock_mgmt_io(phba);
7507 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
7508 * @phba: pointer to lpfc hba data structure.
7510 * This function enables the PCI SR-IOV virtual functions to a physical
7511 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7512 * enable the number of virtual functions to the physical function. As
7513 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7514 * API call does not considered as an error condition for most of the device.
7517 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
7519 struct pci_dev *pdev = phba->pcidev;
7523 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
7527 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
7532 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
7533 * @phba: pointer to lpfc hba data structure.
7534 * @nr_vfn: number of virtual functions to be enabled.
7536 * This function enables the PCI SR-IOV virtual functions to a physical
7537 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7538 * enable the number of virtual functions to the physical function. As
7539 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7540 * API call does not considered as an error condition for most of the device.
7543 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
7545 struct pci_dev *pdev = phba->pcidev;
7546 uint16_t max_nr_vfn;
7549 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
7550 if (nr_vfn > max_nr_vfn) {
7551 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7552 "3057 Requested vfs (%d) greater than "
7553 "supported vfs (%d)", nr_vfn, max_nr_vfn);
7557 rc = pci_enable_sriov(pdev, nr_vfn);
7559 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7560 "2806 Failed to enable sriov on this device "
7561 "with vfn number nr_vf:%d, rc:%d\n",
7564 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7565 "2807 Successful enable sriov on this device "
7566 "with vfn number nr_vf:%d\n", nr_vfn);
7571 lpfc_unblock_requests_work(struct work_struct *work)
7573 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
7574 unblock_request_work);
7576 lpfc_unblock_requests(phba);
7580 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
7581 * @phba: pointer to lpfc hba data structure.
7583 * This routine is invoked to set up the driver internal resources before the
7584 * device specific resource setup to support the HBA device it attached to.
7588 * other values - error
7591 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
7593 struct lpfc_sli *psli = &phba->sli;
7596 * Driver resources common to all SLI revisions
7598 atomic_set(&phba->fast_event_count, 0);
7599 atomic_set(&phba->dbg_log_idx, 0);
7600 atomic_set(&phba->dbg_log_cnt, 0);
7601 atomic_set(&phba->dbg_log_dmping, 0);
7602 spin_lock_init(&phba->hbalock);
7604 /* Initialize port_list spinlock */
7605 spin_lock_init(&phba->port_list_lock);
7606 INIT_LIST_HEAD(&phba->port_list);
7608 INIT_LIST_HEAD(&phba->work_list);
7609 init_waitqueue_head(&phba->wait_4_mlo_m_q);
7611 /* Initialize the wait queue head for the kernel thread */
7612 init_waitqueue_head(&phba->work_waitq);
7614 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7615 "1403 Protocols supported %s %s %s\n",
7616 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7618 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
7620 (phba->nvmet_support ? "NVMET" : " "));
7622 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7623 spin_lock_init(&phba->scsi_buf_list_get_lock);
7624 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7625 spin_lock_init(&phba->scsi_buf_list_put_lock);
7626 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
7628 /* Initialize the fabric iocb list */
7629 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7631 /* Initialize list to save ELS buffers */
7632 INIT_LIST_HEAD(&phba->elsbuf);
7634 /* Initialize FCF connection rec list */
7635 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7637 /* Initialize OAS configuration list */
7638 spin_lock_init(&phba->devicelock);
7639 INIT_LIST_HEAD(&phba->luns);
7641 /* MBOX heartbeat timer */
7642 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
7643 /* Fabric block timer */
7644 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
7645 /* EA polling mode timer */
7646 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
7647 /* Heartbeat timer */
7648 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
7650 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7652 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7653 lpfc_idle_stat_delay_work);
7654 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
7659 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7660 * @phba: pointer to lpfc hba data structure.
7662 * This routine is invoked to set up the driver internal resources specific to
7663 * support the SLI-3 HBA device it attached to.
7667 * other values - error
7670 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7675 * Initialize timers used by driver
7678 /* FCP polling mode timer */
7679 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
7681 /* Host attention work mask setup */
7682 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7683 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7685 /* Get all the module params for configuring this host */
7686 lpfc_get_cfgparam(phba);
7687 /* Set up phase-1 common device driver resources */
7689 rc = lpfc_setup_driver_resource_phase1(phba);
7693 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
7694 phba->menlo_flag |= HBA_MENLO_SUPPORT;
7695 /* check for menlo minimum sg count */
7696 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
7697 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
7700 if (!phba->sli.sli3_ring)
7701 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7702 sizeof(struct lpfc_sli_ring),
7704 if (!phba->sli.sli3_ring)
7708 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
7709 * used to create the sg_dma_buf_pool must be dynamically calculated.
7712 if (phba->sli_rev == LPFC_SLI_REV4)
7713 entry_sz = sizeof(struct sli4_sge);
7715 entry_sz = sizeof(struct ulp_bde64);
7717 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7718 if (phba->cfg_enable_bg) {
7720 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7721 * the FCP rsp, and a BDE for each. Sice we have no control
7722 * over how many protection data segments the SCSI Layer
7723 * will hand us (ie: there could be one for every block
7724 * in the IO), we just allocate enough BDEs to accomidate
7725 * our max amount and we need to limit lpfc_sg_seg_cnt to
7726 * minimize the risk of running out.
7728 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7729 sizeof(struct fcp_rsp) +
7730 (LPFC_MAX_SG_SEG_CNT * entry_sz);
7732 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7733 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7735 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7736 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7739 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7740 * the FCP rsp, a BDE for each, and a BDE for up to
7741 * cfg_sg_seg_cnt data segments.
7743 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7744 sizeof(struct fcp_rsp) +
7745 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
7747 /* Total BDEs in BPL for scsi_sg_list */
7748 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7751 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7752 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
7753 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7754 phba->cfg_total_seg_cnt);
7756 phba->max_vpi = LPFC_MAX_VPI;
7757 /* This will be set to correct value after config_port mbox */
7758 phba->max_vports = 0;
7761 * Initialize the SLI Layer to run with lpfc HBAs.
7763 lpfc_sli_setup(phba);
7764 lpfc_sli_queue_init(phba);
7766 /* Allocate device driver memory */
7767 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7770 phba->lpfc_sg_dma_buf_pool =
7771 dma_pool_create("lpfc_sg_dma_buf_pool",
7772 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7775 if (!phba->lpfc_sg_dma_buf_pool)
7778 phba->lpfc_cmd_rsp_buf_pool =
7779 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7781 sizeof(struct fcp_cmnd) +
7782 sizeof(struct fcp_rsp),
7785 if (!phba->lpfc_cmd_rsp_buf_pool)
7786 goto fail_free_dma_buf_pool;
7789 * Enable sr-iov virtual functions if supported and configured
7790 * through the module parameter.
7792 if (phba->cfg_sriov_nr_virtfn > 0) {
7793 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7794 phba->cfg_sriov_nr_virtfn);
7796 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7797 "2808 Requested number of SR-IOV "
7798 "virtual functions (%d) is not "
7800 phba->cfg_sriov_nr_virtfn);
7801 phba->cfg_sriov_nr_virtfn = 0;
7807 fail_free_dma_buf_pool:
7808 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7809 phba->lpfc_sg_dma_buf_pool = NULL;
7811 lpfc_mem_free(phba);
7816 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7817 * @phba: pointer to lpfc hba data structure.
7819 * This routine is invoked to unset the driver internal resources set up
7820 * specific for supporting the SLI-3 HBA device it attached to.
7823 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7825 /* Free device driver memory allocated */
7826 lpfc_mem_free_all(phba);
7832 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7833 * @phba: pointer to lpfc hba data structure.
7835 * This routine is invoked to set up the driver internal resources specific to
7836 * support the SLI-4 HBA device it attached to.
7840 * other values - error
7843 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7845 LPFC_MBOXQ_t *mboxq;
7847 int rc, i, max_buf_size;
7854 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7855 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
7856 phba->sli4_hba.curr_disp_cpu = 0;
7858 /* Get all the module params for configuring this host */
7859 lpfc_get_cfgparam(phba);
7861 /* Set up phase-1 common device driver resources */
7862 rc = lpfc_setup_driver_resource_phase1(phba);
7866 /* Before proceed, wait for POST done and device ready */
7867 rc = lpfc_sli4_post_status_check(phba);
7871 /* Allocate all driver workqueues here */
7873 /* The lpfc_wq workqueue for deferred irq use */
7874 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7877 * Initialize timers used by driver
7880 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
7882 /* FCF rediscover timer */
7883 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
7885 /* CMF congestion timer */
7886 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7887 phba->cmf_timer.function = lpfc_cmf_timer;
7890 * Control structure for handling external multi-buffer mailbox
7891 * command pass-through.
7893 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
7894 sizeof(struct lpfc_mbox_ext_buf_ctx));
7895 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
7897 phba->max_vpi = LPFC_MAX_VPI;
7899 /* This will be set to correct value after the read_config mbox */
7900 phba->max_vports = 0;
7902 /* Program the default value of vlan_id and fc_map */
7903 phba->valid_vlan = 0;
7904 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
7905 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
7906 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
7909 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
7910 * we will associate a new ring, for each EQ/CQ/WQ tuple.
7911 * The WQ create will allocate the ring.
7914 /* Initialize buffer queue management fields */
7915 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
7916 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
7917 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
7919 /* for VMID idle timeout if VMID is enabled */
7920 if (lpfc_is_vmid_enabled(phba))
7921 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
7924 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
7926 /* Initialize the Abort buffer list used by driver */
7927 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
7928 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
7930 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7931 /* Initialize the Abort nvme buffer list used by driver */
7932 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
7933 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
7934 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
7935 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
7936 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
7939 /* This abort list used by worker thread */
7940 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
7941 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
7942 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
7943 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
7946 * Initialize driver internal slow-path work queues
7949 /* Driver internel slow-path CQ Event pool */
7950 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
7951 /* Response IOCB work queue list */
7952 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
7953 /* Asynchronous event CQ Event work queue list */
7954 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
7955 /* Slow-path XRI aborted CQ Event work queue list */
7956 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
7957 /* Receive queue CQ Event work queue list */
7958 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
7960 /* Initialize extent block lists. */
7961 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
7962 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
7963 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
7964 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
7966 /* Initialize mboxq lists. If the early init routines fail
7967 * these lists need to be correctly initialized.
7969 INIT_LIST_HEAD(&phba->sli.mboxq);
7970 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
7972 /* initialize optic_state to 0xFF */
7973 phba->sli4_hba.lnk_info.optic_state = 0xff;
7975 /* Allocate device driver memory */
7976 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
7980 /* IF Type 2 ports get initialized now. */
7981 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
7982 LPFC_SLI_INTF_IF_TYPE_2) {
7983 rc = lpfc_pci_function_reset(phba);
7988 phba->temp_sensor_support = 1;
7991 /* Create the bootstrap mailbox command */
7992 rc = lpfc_create_bootstrap_mbox(phba);
7996 /* Set up the host's endian order with the device. */
7997 rc = lpfc_setup_endian_order(phba);
7999 goto out_free_bsmbx;
8001 /* Set up the hba's configuration parameters. */
8002 rc = lpfc_sli4_read_config(phba);
8004 goto out_free_bsmbx;
8005 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
8007 goto out_free_bsmbx;
8009 /* IF Type 0 ports get initialized now. */
8010 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8011 LPFC_SLI_INTF_IF_TYPE_0) {
8012 rc = lpfc_pci_function_reset(phba);
8014 goto out_free_bsmbx;
8017 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8021 goto out_free_bsmbx;
8024 /* Check for NVMET being configured */
8025 phba->nvmet_support = 0;
8026 if (lpfc_enable_nvmet_cnt) {
8028 /* First get WWN of HBA instance */
8029 lpfc_read_nv(phba, mboxq);
8030 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8031 if (rc != MBX_SUCCESS) {
8032 lpfc_printf_log(phba, KERN_ERR,
8034 "6016 Mailbox failed , mbxCmd x%x "
8035 "READ_NV, mbxStatus x%x\n",
8036 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8037 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
8038 mempool_free(mboxq, phba->mbox_mem_pool);
8040 goto out_free_bsmbx;
8043 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
8045 wwn = cpu_to_be64(wwn);
8046 phba->sli4_hba.wwnn.u.name = wwn;
8047 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
8049 /* wwn is WWPN of HBA instance */
8050 wwn = cpu_to_be64(wwn);
8051 phba->sli4_hba.wwpn.u.name = wwn;
8053 /* Check to see if it matches any module parameter */
8054 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
8055 if (wwn == lpfc_enable_nvmet[i]) {
8056 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
8057 if (lpfc_nvmet_mem_alloc(phba))
8060 phba->nvmet_support = 1; /* a match */
8062 lpfc_printf_log(phba, KERN_ERR,
8064 "6017 NVME Target %016llx\n",
8067 lpfc_printf_log(phba, KERN_ERR,
8069 "6021 Can't enable NVME Target."
8070 " NVME_TARGET_FC infrastructure"
8071 " is not in kernel\n");
8073 /* Not supported for NVMET */
8074 phba->cfg_xri_rebalancing = 0;
8075 if (phba->irq_chann_mode == NHT_MODE) {
8076 phba->cfg_irq_chann =
8077 phba->sli4_hba.num_present_cpu;
8078 phba->cfg_hdw_queue =
8079 phba->sli4_hba.num_present_cpu;
8080 phba->irq_chann_mode = NORMAL_MODE;
8087 lpfc_nvme_mod_param_dep(phba);
8090 * Get sli4 parameters that override parameters from Port capabilities.
8091 * If this call fails, it isn't critical unless the SLI4 parameters come
8094 rc = lpfc_get_sli4_parameters(phba, mboxq);
8096 if_type = bf_get(lpfc_sli_intf_if_type,
8097 &phba->sli4_hba.sli_intf);
8098 if_fam = bf_get(lpfc_sli_intf_sli_family,
8099 &phba->sli4_hba.sli_intf);
8100 if (phba->sli4_hba.extents_in_use &&
8101 phba->sli4_hba.rpi_hdrs_in_use) {
8102 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8103 "2999 Unsupported SLI4 Parameters "
8104 "Extents and RPI headers enabled.\n");
8105 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8106 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
8107 mempool_free(mboxq, phba->mbox_mem_pool);
8109 goto out_free_bsmbx;
8112 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8113 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
8114 mempool_free(mboxq, phba->mbox_mem_pool);
8116 goto out_free_bsmbx;
8121 * 1 for cmd, 1 for rsp, NVME adds an extra one
8122 * for boundary conditions in its max_sgl_segment template.
8125 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
8129 * It doesn't matter what family our adapter is in, we are
8130 * limited to 2 Pages, 512 SGEs, for our SGL.
8131 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
8133 max_buf_size = (2 * SLI4_PAGE_SIZE);
8136 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
8137 * used to create the sg_dma_buf_pool must be calculated.
8139 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8140 /* Both cfg_enable_bg and cfg_external_dif code paths */
8143 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
8144 * the FCP rsp, and a SGE. Sice we have no control
8145 * over how many protection segments the SCSI Layer
8146 * will hand us (ie: there could be one for every block
8147 * in the IO), just allocate enough SGEs to accomidate
8148 * our max amount and we need to limit lpfc_sg_seg_cnt
8149 * to minimize the risk of running out.
8151 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8152 sizeof(struct fcp_rsp) + max_buf_size;
8154 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
8155 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
8158 * If supporting DIF, reduce the seg count for scsi to
8159 * allow room for the DIF sges.
8161 if (phba->cfg_enable_bg &&
8162 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
8163 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
8165 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8169 * The scsi_buf for a regular I/O holds the FCP cmnd,
8170 * the FCP rsp, a SGE for each, and a SGE for up to
8171 * cfg_sg_seg_cnt data segments.
8173 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8174 sizeof(struct fcp_rsp) +
8175 ((phba->cfg_sg_seg_cnt + extra) *
8176 sizeof(struct sli4_sge));
8178 /* Total SGEs for scsi_sg_list */
8179 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
8180 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8183 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
8184 * need to post 1 page for the SGL.
8188 if (phba->cfg_xpsgl && !phba->nvmet_support)
8189 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
8190 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
8191 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
8193 phba->cfg_sg_dma_buf_size =
8194 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
8196 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
8197 sizeof(struct sli4_sge);
8199 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
8200 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8201 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
8202 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
8203 "6300 Reducing NVME sg segment "
8205 LPFC_MAX_NVME_SEG_CNT);
8206 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
8208 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
8211 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
8212 "9087 sg_seg_cnt:%d dmabuf_size:%d "
8213 "total:%d scsi:%d nvme:%d\n",
8214 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
8215 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
8216 phba->cfg_nvme_seg_cnt);
8218 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
8219 i = phba->cfg_sg_dma_buf_size;
8223 phba->lpfc_sg_dma_buf_pool =
8224 dma_pool_create("lpfc_sg_dma_buf_pool",
8226 phba->cfg_sg_dma_buf_size,
8228 if (!phba->lpfc_sg_dma_buf_pool)
8229 goto out_free_bsmbx;
8231 phba->lpfc_cmd_rsp_buf_pool =
8232 dma_pool_create("lpfc_cmd_rsp_buf_pool",
8234 sizeof(struct fcp_cmnd) +
8235 sizeof(struct fcp_rsp),
8237 if (!phba->lpfc_cmd_rsp_buf_pool)
8238 goto out_free_sg_dma_buf;
8240 mempool_free(mboxq, phba->mbox_mem_pool);
8242 /* Verify OAS is supported */
8243 lpfc_sli4_oas_verify(phba);
8245 /* Verify RAS support on adapter */
8246 lpfc_sli4_ras_init(phba);
8248 /* Verify all the SLI4 queues */
8249 rc = lpfc_sli4_queue_verify(phba);
8251 goto out_free_cmd_rsp_buf;
8253 /* Create driver internal CQE event pool */
8254 rc = lpfc_sli4_cq_event_pool_create(phba);
8256 goto out_free_cmd_rsp_buf;
8258 /* Initialize sgl lists per host */
8259 lpfc_init_sgl_list(phba);
8261 /* Allocate and initialize active sgl array */
8262 rc = lpfc_init_active_sgl_array(phba);
8264 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8265 "1430 Failed to initialize sgl list.\n");
8266 goto out_destroy_cq_event_pool;
8268 rc = lpfc_sli4_init_rpi_hdrs(phba);
8270 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8271 "1432 Failed to initialize rpi headers.\n");
8272 goto out_free_active_sgl;
8275 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
8276 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
8277 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
8279 if (!phba->fcf.fcf_rr_bmask) {
8280 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8281 "2759 Failed allocate memory for FCF round "
8282 "robin failover bmask\n");
8284 goto out_remove_rpi_hdrs;
8287 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
8288 sizeof(struct lpfc_hba_eq_hdl),
8290 if (!phba->sli4_hba.hba_eq_hdl) {
8291 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8292 "2572 Failed allocate memory for "
8293 "fast-path per-EQ handle array\n");
8295 goto out_free_fcf_rr_bmask;
8298 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
8299 sizeof(struct lpfc_vector_map_info),
8301 if (!phba->sli4_hba.cpu_map) {
8302 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8303 "3327 Failed allocate memory for msi-x "
8304 "interrupt vector mapping\n");
8306 goto out_free_hba_eq_hdl;
8309 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
8310 if (!phba->sli4_hba.eq_info) {
8311 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8312 "3321 Failed allocation for per_cpu stats\n");
8314 goto out_free_hba_cpu_map;
8317 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
8318 sizeof(*phba->sli4_hba.idle_stat),
8320 if (!phba->sli4_hba.idle_stat) {
8321 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8322 "3390 Failed allocation for idle_stat\n");
8324 goto out_free_hba_eq_info;
8327 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8328 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
8329 if (!phba->sli4_hba.c_stat) {
8330 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8331 "3332 Failed allocating per cpu hdwq stats\n");
8333 goto out_free_hba_idle_stat;
8337 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
8338 if (!phba->cmf_stat) {
8339 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8340 "3331 Failed allocating per cpu cgn stats\n");
8342 goto out_free_hba_hdwq_info;
8346 * Enable sr-iov virtual functions if supported and configured
8347 * through the module parameter.
8349 if (phba->cfg_sriov_nr_virtfn > 0) {
8350 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
8351 phba->cfg_sriov_nr_virtfn);
8353 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8354 "3020 Requested number of SR-IOV "
8355 "virtual functions (%d) is not "
8357 phba->cfg_sriov_nr_virtfn);
8358 phba->cfg_sriov_nr_virtfn = 0;
8364 out_free_hba_hdwq_info:
8365 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8366 free_percpu(phba->sli4_hba.c_stat);
8367 out_free_hba_idle_stat:
8369 kfree(phba->sli4_hba.idle_stat);
8370 out_free_hba_eq_info:
8371 free_percpu(phba->sli4_hba.eq_info);
8372 out_free_hba_cpu_map:
8373 kfree(phba->sli4_hba.cpu_map);
8374 out_free_hba_eq_hdl:
8375 kfree(phba->sli4_hba.hba_eq_hdl);
8376 out_free_fcf_rr_bmask:
8377 kfree(phba->fcf.fcf_rr_bmask);
8378 out_remove_rpi_hdrs:
8379 lpfc_sli4_remove_rpi_hdrs(phba);
8380 out_free_active_sgl:
8381 lpfc_free_active_sgl(phba);
8382 out_destroy_cq_event_pool:
8383 lpfc_sli4_cq_event_pool_destroy(phba);
8384 out_free_cmd_rsp_buf:
8385 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
8386 phba->lpfc_cmd_rsp_buf_pool = NULL;
8387 out_free_sg_dma_buf:
8388 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
8389 phba->lpfc_sg_dma_buf_pool = NULL;
8391 lpfc_destroy_bootstrap_mbox(phba);
8393 lpfc_mem_free(phba);
8398 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
8399 * @phba: pointer to lpfc hba data structure.
8401 * This routine is invoked to unset the driver internal resources set up
8402 * specific for supporting the SLI-4 HBA device it attached to.
8405 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
8407 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
8409 free_percpu(phba->sli4_hba.eq_info);
8410 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8411 free_percpu(phba->sli4_hba.c_stat);
8413 free_percpu(phba->cmf_stat);
8414 kfree(phba->sli4_hba.idle_stat);
8416 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
8417 kfree(phba->sli4_hba.cpu_map);
8418 phba->sli4_hba.num_possible_cpu = 0;
8419 phba->sli4_hba.num_present_cpu = 0;
8420 phba->sli4_hba.curr_disp_cpu = 0;
8421 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
8423 /* Free memory allocated for fast-path work queue handles */
8424 kfree(phba->sli4_hba.hba_eq_hdl);
8426 /* Free the allocated rpi headers. */
8427 lpfc_sli4_remove_rpi_hdrs(phba);
8428 lpfc_sli4_remove_rpis(phba);
8430 /* Free eligible FCF index bmask */
8431 kfree(phba->fcf.fcf_rr_bmask);
8433 /* Free the ELS sgl list */
8434 lpfc_free_active_sgl(phba);
8435 lpfc_free_els_sgl_list(phba);
8436 lpfc_free_nvmet_sgl_list(phba);
8438 /* Free the completion queue EQ event pool */
8439 lpfc_sli4_cq_event_release_all(phba);
8440 lpfc_sli4_cq_event_pool_destroy(phba);
8442 /* Release resource identifiers. */
8443 lpfc_sli4_dealloc_resource_identifiers(phba);
8445 /* Free the bsmbx region. */
8446 lpfc_destroy_bootstrap_mbox(phba);
8448 /* Free the SLI Layer memory with SLI4 HBAs */
8449 lpfc_mem_free_all(phba);
8451 /* Free the current connect table */
8452 list_for_each_entry_safe(conn_entry, next_conn_entry,
8453 &phba->fcf_conn_rec_list, list) {
8454 list_del_init(&conn_entry->list);
8462 * lpfc_init_api_table_setup - Set up init api function jump table
8463 * @phba: The hba struct for which this call is being executed.
8464 * @dev_grp: The HBA PCI-Device group number.
8466 * This routine sets up the device INIT interface API function jump table
8469 * Returns: 0 - success, -ENODEV - failure.
8472 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8474 phba->lpfc_hba_init_link = lpfc_hba_init_link;
8475 phba->lpfc_hba_down_link = lpfc_hba_down_link;
8476 phba->lpfc_selective_reset = lpfc_selective_reset;
8478 case LPFC_PCI_DEV_LP:
8479 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
8480 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
8481 phba->lpfc_stop_port = lpfc_stop_port_s3;
8483 case LPFC_PCI_DEV_OC:
8484 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
8485 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
8486 phba->lpfc_stop_port = lpfc_stop_port_s4;
8489 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8490 "1431 Invalid HBA PCI-device group: 0x%x\n",
8498 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
8499 * @phba: pointer to lpfc hba data structure.
8501 * This routine is invoked to set up the driver internal resources after the
8502 * device specific resource setup to support the HBA device it attached to.
8506 * other values - error
8509 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
8513 /* Startup the kernel thread for this host adapter. */
8514 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8515 "lpfc_worker_%d", phba->brd_no);
8516 if (IS_ERR(phba->worker_thread)) {
8517 error = PTR_ERR(phba->worker_thread);
8525 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
8526 * @phba: pointer to lpfc hba data structure.
8528 * This routine is invoked to unset the driver internal resources set up after
8529 * the device specific resource setup for supporting the HBA device it
8533 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
8536 flush_workqueue(phba->wq);
8537 destroy_workqueue(phba->wq);
8541 /* Stop kernel worker thread */
8542 if (phba->worker_thread)
8543 kthread_stop(phba->worker_thread);
8547 * lpfc_free_iocb_list - Free iocb list.
8548 * @phba: pointer to lpfc hba data structure.
8550 * This routine is invoked to free the driver's IOCB list and memory.
8553 lpfc_free_iocb_list(struct lpfc_hba *phba)
8555 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
8557 spin_lock_irq(&phba->hbalock);
8558 list_for_each_entry_safe(iocbq_entry, iocbq_next,
8559 &phba->lpfc_iocb_list, list) {
8560 list_del(&iocbq_entry->list);
8562 phba->total_iocbq_bufs--;
8564 spin_unlock_irq(&phba->hbalock);
8570 * lpfc_init_iocb_list - Allocate and initialize iocb list.
8571 * @phba: pointer to lpfc hba data structure.
8572 * @iocb_count: number of requested iocbs
8574 * This routine is invoked to allocate and initizlize the driver's IOCB
8575 * list and set up the IOCB tag array accordingly.
8579 * other values - error
8582 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8584 struct lpfc_iocbq *iocbq_entry = NULL;
8588 /* Initialize and populate the iocb list per host. */
8589 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
8590 for (i = 0; i < iocb_count; i++) {
8591 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
8592 if (iocbq_entry == NULL) {
8593 printk(KERN_ERR "%s: only allocated %d iocbs of "
8594 "expected %d count. Unloading driver.\n",
8595 __func__, i, iocb_count);
8596 goto out_free_iocbq;
8599 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8602 printk(KERN_ERR "%s: failed to allocate IOTAG. "
8603 "Unloading driver.\n", __func__);
8604 goto out_free_iocbq;
8606 iocbq_entry->sli4_lxritag = NO_XRI;
8607 iocbq_entry->sli4_xritag = NO_XRI;
8609 spin_lock_irq(&phba->hbalock);
8610 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8611 phba->total_iocbq_bufs++;
8612 spin_unlock_irq(&phba->hbalock);
8618 lpfc_free_iocb_list(phba);
8624 * lpfc_free_sgl_list - Free a given sgl list.
8625 * @phba: pointer to lpfc hba data structure.
8626 * @sglq_list: pointer to the head of sgl list.
8628 * This routine is invoked to free a give sgl list and memory.
8631 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
8633 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8635 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8636 list_del(&sglq_entry->list);
8637 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8643 * lpfc_free_els_sgl_list - Free els sgl list.
8644 * @phba: pointer to lpfc hba data structure.
8646 * This routine is invoked to free the driver's els sgl list and memory.
8649 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8651 LIST_HEAD(sglq_list);
8653 /* Retrieve all els sgls from driver list */
8654 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
8655 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
8656 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
8658 /* Now free the sgl list */
8659 lpfc_free_sgl_list(phba, &sglq_list);
8663 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8664 * @phba: pointer to lpfc hba data structure.
8666 * This routine is invoked to free the driver's nvmet sgl list and memory.
8669 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8671 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8672 LIST_HEAD(sglq_list);
8674 /* Retrieve all nvmet sgls from driver list */
8675 spin_lock_irq(&phba->hbalock);
8676 spin_lock(&phba->sli4_hba.sgl_list_lock);
8677 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8678 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8679 spin_unlock_irq(&phba->hbalock);
8681 /* Now free the sgl list */
8682 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8683 list_del(&sglq_entry->list);
8684 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8688 /* Update the nvmet_xri_cnt to reflect no current sgls.
8689 * The next initialization cycle sets the count and allocates
8690 * the sgls over again.
8692 phba->sli4_hba.nvmet_xri_cnt = 0;
8696 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8697 * @phba: pointer to lpfc hba data structure.
8699 * This routine is invoked to allocate the driver's active sgl memory.
8700 * This array will hold the sglq_entry's for active IOs.
8703 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8706 size = sizeof(struct lpfc_sglq *);
8707 size *= phba->sli4_hba.max_cfg_param.max_xri;
8709 phba->sli4_hba.lpfc_sglq_active_list =
8710 kzalloc(size, GFP_KERNEL);
8711 if (!phba->sli4_hba.lpfc_sglq_active_list)
8717 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8718 * @phba: pointer to lpfc hba data structure.
8720 * This routine is invoked to walk through the array of active sglq entries
8721 * and free all of the resources.
8722 * This is just a place holder for now.
8725 lpfc_free_active_sgl(struct lpfc_hba *phba)
8727 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8731 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8732 * @phba: pointer to lpfc hba data structure.
8734 * This routine is invoked to allocate and initizlize the driver's sgl
8735 * list and set up the sgl xritag tag array accordingly.
8739 lpfc_init_sgl_list(struct lpfc_hba *phba)
8741 /* Initialize and populate the sglq list per host/VF. */
8742 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
8743 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8744 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
8745 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8747 /* els xri-sgl book keeping */
8748 phba->sli4_hba.els_xri_cnt = 0;
8750 /* nvme xri-buffer book keeping */
8751 phba->sli4_hba.io_xri_cnt = 0;
8755 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8756 * @phba: pointer to lpfc hba data structure.
8758 * This routine is invoked to post rpi header templates to the
8759 * port for those SLI4 ports that do not support extents. This routine
8760 * posts a PAGE_SIZE memory region to the port to hold up to
8761 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8762 * and should be called only when interrupts are disabled.
8766 * -ERROR - otherwise.
8769 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8772 struct lpfc_rpi_hdr *rpi_hdr;
8774 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
8775 if (!phba->sli4_hba.rpi_hdrs_in_use)
8777 if (phba->sli4_hba.extents_in_use)
8780 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8782 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8783 "0391 Error during rpi post operation\n");
8784 lpfc_sli4_remove_rpis(phba);
8792 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8793 * @phba: pointer to lpfc hba data structure.
8795 * This routine is invoked to allocate a single 4KB memory region to
8796 * support rpis and stores them in the phba. This single region
8797 * provides support for up to 64 rpis. The region is used globally
8801 * A valid rpi hdr on success.
8802 * A NULL pointer on any failure.
8804 struct lpfc_rpi_hdr *
8805 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8807 uint16_t rpi_limit, curr_rpi_range;
8808 struct lpfc_dmabuf *dmabuf;
8809 struct lpfc_rpi_hdr *rpi_hdr;
8812 * If the SLI4 port supports extents, posting the rpi header isn't
8813 * required. Set the expected maximum count and let the actual value
8814 * get set when extents are fully allocated.
8816 if (!phba->sli4_hba.rpi_hdrs_in_use)
8818 if (phba->sli4_hba.extents_in_use)
8821 /* The limit on the logical index is just the max_rpi count. */
8822 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
8824 spin_lock_irq(&phba->hbalock);
8826 * Establish the starting RPI in this header block. The starting
8827 * rpi is normalized to a zero base because the physical rpi is
8830 curr_rpi_range = phba->sli4_hba.next_rpi;
8831 spin_unlock_irq(&phba->hbalock);
8833 /* Reached full RPI range */
8834 if (curr_rpi_range == rpi_limit)
8838 * First allocate the protocol header region for the port. The
8839 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8841 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8845 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8846 LPFC_HDR_TEMPLATE_SIZE,
8847 &dmabuf->phys, GFP_KERNEL);
8848 if (!dmabuf->virt) {
8850 goto err_free_dmabuf;
8853 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
8855 goto err_free_coherent;
8858 /* Save the rpi header data for cleanup later. */
8859 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
8861 goto err_free_coherent;
8863 rpi_hdr->dmabuf = dmabuf;
8864 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
8865 rpi_hdr->page_count = 1;
8866 spin_lock_irq(&phba->hbalock);
8868 /* The rpi_hdr stores the logical index only. */
8869 rpi_hdr->start_rpi = curr_rpi_range;
8870 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
8871 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
8873 spin_unlock_irq(&phba->hbalock);
8877 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
8878 dmabuf->virt, dmabuf->phys);
8885 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
8886 * @phba: pointer to lpfc hba data structure.
8888 * This routine is invoked to remove all memory resources allocated
8889 * to support rpis for SLI4 ports not supporting extents. This routine
8890 * presumes the caller has released all rpis consumed by fabric or port
8891 * logins and is prepared to have the header pages removed.
8894 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
8896 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
8898 if (!phba->sli4_hba.rpi_hdrs_in_use)
8901 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
8902 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
8903 list_del(&rpi_hdr->list);
8904 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
8905 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
8906 kfree(rpi_hdr->dmabuf);
8910 /* There are no rpis available to the port now. */
8911 phba->sli4_hba.next_rpi = 0;
8915 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
8916 * @pdev: pointer to pci device data structure.
8918 * This routine is invoked to allocate the driver hba data structure for an
8919 * HBA device. If the allocation is successful, the phba reference to the
8920 * PCI device data structure is set.
8923 * pointer to @phba - successful
8926 static struct lpfc_hba *
8927 lpfc_hba_alloc(struct pci_dev *pdev)
8929 struct lpfc_hba *phba;
8931 /* Allocate memory for HBA structure */
8932 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
8934 dev_err(&pdev->dev, "failed to allocate hba struct\n");
8938 /* Set reference to PCI device in HBA structure */
8939 phba->pcidev = pdev;
8941 /* Assign an unused board number */
8942 phba->brd_no = lpfc_get_instance();
8943 if (phba->brd_no < 0) {
8947 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
8949 spin_lock_init(&phba->ct_ev_lock);
8950 INIT_LIST_HEAD(&phba->ct_ev_waiters);
8956 * lpfc_hba_free - Free driver hba data structure with a device.
8957 * @phba: pointer to lpfc hba data structure.
8959 * This routine is invoked to free the driver hba data structure with an
8963 lpfc_hba_free(struct lpfc_hba *phba)
8965 if (phba->sli_rev == LPFC_SLI_REV4)
8966 kfree(phba->sli4_hba.hdwq);
8968 /* Release the driver assigned board number */
8969 idr_remove(&lpfc_hba_index, phba->brd_no);
8971 /* Free memory allocated with sli3 rings */
8972 kfree(phba->sli.sli3_ring);
8973 phba->sli.sli3_ring = NULL;
8980 * lpfc_create_shost - Create hba physical port with associated scsi host.
8981 * @phba: pointer to lpfc hba data structure.
8983 * This routine is invoked to create HBA physical port and associate a SCSI
8988 * other values - error
8991 lpfc_create_shost(struct lpfc_hba *phba)
8993 struct lpfc_vport *vport;
8994 struct Scsi_Host *shost;
8996 /* Initialize HBA FC structure */
8997 phba->fc_edtov = FF_DEF_EDTOV;
8998 phba->fc_ratov = FF_DEF_RATOV;
8999 phba->fc_altov = FF_DEF_ALTOV;
9000 phba->fc_arbtov = FF_DEF_ARBTOV;
9002 atomic_set(&phba->sdev_cnt, 0);
9003 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
9007 shost = lpfc_shost_from_vport(vport);
9008 phba->pport = vport;
9010 if (phba->nvmet_support) {
9011 /* Only 1 vport (pport) will support NVME target */
9012 phba->targetport = NULL;
9013 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
9014 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
9015 "6076 NVME Target Found\n");
9018 lpfc_debugfs_initialize(vport);
9019 /* Put reference to SCSI host to driver's device private data */
9020 pci_set_drvdata(phba->pcidev, shost);
9023 * At this point we are fully registered with PSA. In addition,
9024 * any initial discovery should be completed.
9026 vport->load_flag |= FC_ALLOW_FDMI;
9027 if (phba->cfg_enable_SmartSAN ||
9028 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
9030 /* Setup appropriate attribute masks */
9031 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
9032 if (phba->cfg_enable_SmartSAN)
9033 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
9035 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
9041 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
9042 * @phba: pointer to lpfc hba data structure.
9044 * This routine is invoked to destroy HBA physical port and the associated
9048 lpfc_destroy_shost(struct lpfc_hba *phba)
9050 struct lpfc_vport *vport = phba->pport;
9052 /* Destroy physical port that associated with the SCSI host */
9053 destroy_port(vport);
9059 * lpfc_setup_bg - Setup Block guard structures and debug areas.
9060 * @phba: pointer to lpfc hba data structure.
9061 * @shost: the shost to be used to detect Block guard settings.
9063 * This routine sets up the local Block guard protocol settings for @shost.
9064 * This routine also allocates memory for debugging bg buffers.
9067 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
9072 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9073 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9074 "1478 Registering BlockGuard with the "
9077 old_mask = phba->cfg_prot_mask;
9078 old_guard = phba->cfg_prot_guard;
9080 /* Only allow supported values */
9081 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
9082 SHOST_DIX_TYPE0_PROTECTION |
9083 SHOST_DIX_TYPE1_PROTECTION);
9084 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
9085 SHOST_DIX_GUARD_CRC);
9087 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
9088 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
9089 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
9091 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9092 if ((old_mask != phba->cfg_prot_mask) ||
9093 (old_guard != phba->cfg_prot_guard))
9094 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9095 "1475 Registering BlockGuard with the "
9096 "SCSI layer: mask %d guard %d\n",
9097 phba->cfg_prot_mask,
9098 phba->cfg_prot_guard);
9100 scsi_host_set_prot(shost, phba->cfg_prot_mask);
9101 scsi_host_set_guard(shost, phba->cfg_prot_guard);
9103 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9104 "1479 Not Registering BlockGuard with the SCSI "
9105 "layer, Bad protection parameters: %d %d\n",
9106 old_mask, old_guard);
9111 * lpfc_post_init_setup - Perform necessary device post initialization setup.
9112 * @phba: pointer to lpfc hba data structure.
9114 * This routine is invoked to perform all the necessary post initialization
9115 * setup for the device.
9118 lpfc_post_init_setup(struct lpfc_hba *phba)
9120 struct Scsi_Host *shost;
9121 struct lpfc_adapter_event_header adapter_event;
9123 /* Get the default values for Model Name and Description */
9124 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9127 * hba setup may have changed the hba_queue_depth so we need to
9128 * adjust the value of can_queue.
9130 shost = pci_get_drvdata(phba->pcidev);
9131 shost->can_queue = phba->cfg_hba_queue_depth - 10;
9133 lpfc_host_attrib_init(shost);
9135 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9136 spin_lock_irq(shost->host_lock);
9137 lpfc_poll_start_timer(phba);
9138 spin_unlock_irq(shost->host_lock);
9141 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9142 "0428 Perform SCSI scan\n");
9143 /* Send board arrival event to upper layer */
9144 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
9145 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
9146 fc_host_post_vendor_event(shost, fc_get_event_number(),
9147 sizeof(adapter_event),
9148 (char *) &adapter_event,
9154 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
9155 * @phba: pointer to lpfc hba data structure.
9157 * This routine is invoked to set up the PCI device memory space for device
9158 * with SLI-3 interface spec.
9162 * other values - error
9165 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
9167 struct pci_dev *pdev = phba->pcidev;
9168 unsigned long bar0map_len, bar2map_len;
9176 /* Set the device DMA mask size */
9177 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9179 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9184 /* Get the bus address of Bar0 and Bar2 and the number of bytes
9185 * required by each mapping.
9187 phba->pci_bar0_map = pci_resource_start(pdev, 0);
9188 bar0map_len = pci_resource_len(pdev, 0);
9190 phba->pci_bar2_map = pci_resource_start(pdev, 2);
9191 bar2map_len = pci_resource_len(pdev, 2);
9193 /* Map HBA SLIM to a kernel virtual address. */
9194 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
9195 if (!phba->slim_memmap_p) {
9196 dev_printk(KERN_ERR, &pdev->dev,
9197 "ioremap failed for SLIM memory.\n");
9201 /* Map HBA Control Registers to a kernel virtual address. */
9202 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
9203 if (!phba->ctrl_regs_memmap_p) {
9204 dev_printk(KERN_ERR, &pdev->dev,
9205 "ioremap failed for HBA control registers.\n");
9206 goto out_iounmap_slim;
9209 /* Allocate memory for SLI-2 structures */
9210 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9211 &phba->slim2p.phys, GFP_KERNEL);
9212 if (!phba->slim2p.virt)
9215 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
9216 phba->mbox_ext = (phba->slim2p.virt +
9217 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
9218 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
9219 phba->IOCBs = (phba->slim2p.virt +
9220 offsetof(struct lpfc_sli2_slim, IOCBs));
9222 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
9223 lpfc_sli_hbq_size(),
9224 &phba->hbqslimp.phys,
9226 if (!phba->hbqslimp.virt)
9229 hbq_count = lpfc_sli_hbq_count();
9230 ptr = phba->hbqslimp.virt;
9231 for (i = 0; i < hbq_count; ++i) {
9232 phba->hbqs[i].hbq_virt = ptr;
9233 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
9234 ptr += (lpfc_hbq_defs[i]->entry_count *
9235 sizeof(struct lpfc_hbq_entry));
9237 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
9238 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
9240 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
9242 phba->MBslimaddr = phba->slim_memmap_p;
9243 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
9244 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
9245 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
9246 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
9251 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9252 phba->slim2p.virt, phba->slim2p.phys);
9254 iounmap(phba->ctrl_regs_memmap_p);
9256 iounmap(phba->slim_memmap_p);
9262 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
9263 * @phba: pointer to lpfc hba data structure.
9265 * This routine is invoked to unset the PCI device memory space for device
9266 * with SLI-3 interface spec.
9269 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
9271 struct pci_dev *pdev;
9273 /* Obtain PCI device reference */
9277 pdev = phba->pcidev;
9279 /* Free coherent DMA memory allocated */
9280 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9281 phba->hbqslimp.virt, phba->hbqslimp.phys);
9282 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9283 phba->slim2p.virt, phba->slim2p.phys);
9285 /* I/O memory unmap */
9286 iounmap(phba->ctrl_regs_memmap_p);
9287 iounmap(phba->slim_memmap_p);
9293 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
9294 * @phba: pointer to lpfc hba data structure.
9296 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
9297 * done and check status.
9299 * Return 0 if successful, otherwise -ENODEV.
9302 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
9304 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
9305 struct lpfc_register reg_data;
9306 int i, port_error = 0;
9309 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
9310 memset(®_data, 0, sizeof(reg_data));
9311 if (!phba->sli4_hba.PSMPHRregaddr)
9314 /* Wait up to 30 seconds for the SLI Port POST done and ready */
9315 for (i = 0; i < 3000; i++) {
9316 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9317 &portsmphr_reg.word0) ||
9318 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
9319 /* Port has a fatal POST error, break out */
9320 port_error = -ENODEV;
9323 if (LPFC_POST_STAGE_PORT_READY ==
9324 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
9330 * If there was a port error during POST, then don't proceed with
9331 * other register reads as the data may not be valid. Just exit.
9334 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9335 "1408 Port Failed POST - portsmphr=0x%x, "
9336 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
9337 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
9338 portsmphr_reg.word0,
9339 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
9340 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
9341 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
9342 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
9343 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
9344 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
9345 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
9346 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
9348 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9349 "2534 Device Info: SLIFamily=0x%x, "
9350 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
9351 "SLIHint_2=0x%x, FT=0x%x\n",
9352 bf_get(lpfc_sli_intf_sli_family,
9353 &phba->sli4_hba.sli_intf),
9354 bf_get(lpfc_sli_intf_slirev,
9355 &phba->sli4_hba.sli_intf),
9356 bf_get(lpfc_sli_intf_if_type,
9357 &phba->sli4_hba.sli_intf),
9358 bf_get(lpfc_sli_intf_sli_hint1,
9359 &phba->sli4_hba.sli_intf),
9360 bf_get(lpfc_sli_intf_sli_hint2,
9361 &phba->sli4_hba.sli_intf),
9362 bf_get(lpfc_sli_intf_func_type,
9363 &phba->sli4_hba.sli_intf));
9365 * Check for other Port errors during the initialization
9366 * process. Fail the load if the port did not come up
9369 if_type = bf_get(lpfc_sli_intf_if_type,
9370 &phba->sli4_hba.sli_intf);
9372 case LPFC_SLI_INTF_IF_TYPE_0:
9373 phba->sli4_hba.ue_mask_lo =
9374 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
9375 phba->sli4_hba.ue_mask_hi =
9376 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
9378 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
9380 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
9381 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
9382 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
9383 lpfc_printf_log(phba, KERN_ERR,
9385 "1422 Unrecoverable Error "
9386 "Detected during POST "
9387 "uerr_lo_reg=0x%x, "
9388 "uerr_hi_reg=0x%x, "
9389 "ue_mask_lo_reg=0x%x, "
9390 "ue_mask_hi_reg=0x%x\n",
9393 phba->sli4_hba.ue_mask_lo,
9394 phba->sli4_hba.ue_mask_hi);
9395 port_error = -ENODEV;
9398 case LPFC_SLI_INTF_IF_TYPE_2:
9399 case LPFC_SLI_INTF_IF_TYPE_6:
9400 /* Final checks. The port status should be clean. */
9401 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9403 (bf_get(lpfc_sliport_status_err, ®_data) &&
9404 !bf_get(lpfc_sliport_status_rn, ®_data))) {
9405 phba->work_status[0] =
9406 readl(phba->sli4_hba.u.if_type2.
9408 phba->work_status[1] =
9409 readl(phba->sli4_hba.u.if_type2.
9411 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9412 "2888 Unrecoverable port error "
9413 "following POST: port status reg "
9414 "0x%x, port_smphr reg 0x%x, "
9415 "error 1=0x%x, error 2=0x%x\n",
9417 portsmphr_reg.word0,
9418 phba->work_status[0],
9419 phba->work_status[1]);
9420 port_error = -ENODEV;
9424 if (lpfc_pldv_detect &&
9425 bf_get(lpfc_sli_intf_sli_family,
9426 &phba->sli4_hba.sli_intf) ==
9427 LPFC_SLI_INTF_FAMILY_G6)
9428 pci_write_config_byte(phba->pcidev,
9429 LPFC_SLI_INTF, CFG_PLD);
9431 case LPFC_SLI_INTF_IF_TYPE_1:
9440 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
9441 * @phba: pointer to lpfc hba data structure.
9442 * @if_type: The SLI4 interface type getting configured.
9444 * This routine is invoked to set up SLI4 BAR0 PCI config space register
9448 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9451 case LPFC_SLI_INTF_IF_TYPE_0:
9452 phba->sli4_hba.u.if_type0.UERRLOregaddr =
9453 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
9454 phba->sli4_hba.u.if_type0.UERRHIregaddr =
9455 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
9456 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
9457 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
9458 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
9459 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
9460 phba->sli4_hba.SLIINTFregaddr =
9461 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9463 case LPFC_SLI_INTF_IF_TYPE_2:
9464 phba->sli4_hba.u.if_type2.EQDregaddr =
9465 phba->sli4_hba.conf_regs_memmap_p +
9466 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9467 phba->sli4_hba.u.if_type2.ERR1regaddr =
9468 phba->sli4_hba.conf_regs_memmap_p +
9469 LPFC_CTL_PORT_ER1_OFFSET;
9470 phba->sli4_hba.u.if_type2.ERR2regaddr =
9471 phba->sli4_hba.conf_regs_memmap_p +
9472 LPFC_CTL_PORT_ER2_OFFSET;
9473 phba->sli4_hba.u.if_type2.CTRLregaddr =
9474 phba->sli4_hba.conf_regs_memmap_p +
9475 LPFC_CTL_PORT_CTL_OFFSET;
9476 phba->sli4_hba.u.if_type2.STATUSregaddr =
9477 phba->sli4_hba.conf_regs_memmap_p +
9478 LPFC_CTL_PORT_STA_OFFSET;
9479 phba->sli4_hba.SLIINTFregaddr =
9480 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9481 phba->sli4_hba.PSMPHRregaddr =
9482 phba->sli4_hba.conf_regs_memmap_p +
9483 LPFC_CTL_PORT_SEM_OFFSET;
9484 phba->sli4_hba.RQDBregaddr =
9485 phba->sli4_hba.conf_regs_memmap_p +
9486 LPFC_ULP0_RQ_DOORBELL;
9487 phba->sli4_hba.WQDBregaddr =
9488 phba->sli4_hba.conf_regs_memmap_p +
9489 LPFC_ULP0_WQ_DOORBELL;
9490 phba->sli4_hba.CQDBregaddr =
9491 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
9492 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9493 phba->sli4_hba.MQDBregaddr =
9494 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
9495 phba->sli4_hba.BMBXregaddr =
9496 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9498 case LPFC_SLI_INTF_IF_TYPE_6:
9499 phba->sli4_hba.u.if_type2.EQDregaddr =
9500 phba->sli4_hba.conf_regs_memmap_p +
9501 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9502 phba->sli4_hba.u.if_type2.ERR1regaddr =
9503 phba->sli4_hba.conf_regs_memmap_p +
9504 LPFC_CTL_PORT_ER1_OFFSET;
9505 phba->sli4_hba.u.if_type2.ERR2regaddr =
9506 phba->sli4_hba.conf_regs_memmap_p +
9507 LPFC_CTL_PORT_ER2_OFFSET;
9508 phba->sli4_hba.u.if_type2.CTRLregaddr =
9509 phba->sli4_hba.conf_regs_memmap_p +
9510 LPFC_CTL_PORT_CTL_OFFSET;
9511 phba->sli4_hba.u.if_type2.STATUSregaddr =
9512 phba->sli4_hba.conf_regs_memmap_p +
9513 LPFC_CTL_PORT_STA_OFFSET;
9514 phba->sli4_hba.PSMPHRregaddr =
9515 phba->sli4_hba.conf_regs_memmap_p +
9516 LPFC_CTL_PORT_SEM_OFFSET;
9517 phba->sli4_hba.BMBXregaddr =
9518 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9520 case LPFC_SLI_INTF_IF_TYPE_1:
9522 dev_printk(KERN_ERR, &phba->pcidev->dev,
9523 "FATAL - unsupported SLI4 interface type - %d\n",
9530 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
9531 * @phba: pointer to lpfc hba data structure.
9532 * @if_type: sli if type to operate on.
9534 * This routine is invoked to set up SLI4 BAR1 register memory map.
9537 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9540 case LPFC_SLI_INTF_IF_TYPE_0:
9541 phba->sli4_hba.PSMPHRregaddr =
9542 phba->sli4_hba.ctrl_regs_memmap_p +
9543 LPFC_SLIPORT_IF0_SMPHR;
9544 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9546 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9548 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9551 case LPFC_SLI_INTF_IF_TYPE_6:
9552 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9553 LPFC_IF6_RQ_DOORBELL;
9554 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9555 LPFC_IF6_WQ_DOORBELL;
9556 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9557 LPFC_IF6_CQ_DOORBELL;
9558 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9559 LPFC_IF6_EQ_DOORBELL;
9560 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9561 LPFC_IF6_MQ_DOORBELL;
9563 case LPFC_SLI_INTF_IF_TYPE_2:
9564 case LPFC_SLI_INTF_IF_TYPE_1:
9566 dev_err(&phba->pcidev->dev,
9567 "FATAL - unsupported SLI4 interface type - %d\n",
9574 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
9575 * @phba: pointer to lpfc hba data structure.
9576 * @vf: virtual function number
9578 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
9579 * based on the given viftual function number, @vf.
9581 * Return 0 if successful, otherwise -ENODEV.
9584 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9586 if (vf > LPFC_VIR_FUNC_MAX)
9589 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9590 vf * LPFC_VFR_PAGE_SIZE +
9591 LPFC_ULP0_RQ_DOORBELL);
9592 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9593 vf * LPFC_VFR_PAGE_SIZE +
9594 LPFC_ULP0_WQ_DOORBELL);
9595 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9596 vf * LPFC_VFR_PAGE_SIZE +
9597 LPFC_EQCQ_DOORBELL);
9598 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9599 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9600 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9601 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9602 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9607 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9608 * @phba: pointer to lpfc hba data structure.
9610 * This routine is invoked to create the bootstrap mailbox
9611 * region consistent with the SLI-4 interface spec. This
9612 * routine allocates all memory necessary to communicate
9613 * mailbox commands to the port and sets up all alignment
9614 * needs. No locks are expected to be held when calling
9619 * -ENOMEM - could not allocated memory.
9622 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9625 struct lpfc_dmabuf *dmabuf;
9626 struct dma_address *dma_address;
9630 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9635 * The bootstrap mailbox region is comprised of 2 parts
9636 * plus an alignment restriction of 16 bytes.
9638 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
9639 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9640 &dmabuf->phys, GFP_KERNEL);
9641 if (!dmabuf->virt) {
9647 * Initialize the bootstrap mailbox pointers now so that the register
9648 * operations are simple later. The mailbox dma address is required
9649 * to be 16-byte aligned. Also align the virtual memory as each
9650 * maibox is copied into the bmbx mailbox region before issuing the
9651 * command to the port.
9653 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9654 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9656 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9657 LPFC_ALIGN_16_BYTE);
9658 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9659 LPFC_ALIGN_16_BYTE);
9662 * Set the high and low physical addresses now. The SLI4 alignment
9663 * requirement is 16 bytes and the mailbox is posted to the port
9664 * as two 30-bit addresses. The other data is a bit marking whether
9665 * the 30-bit address is the high or low address.
9666 * Upcast bmbx aphys to 64bits so shift instruction compiles
9667 * clean on 32 bit machines.
9669 dma_address = &phba->sli4_hba.bmbx.dma_address;
9670 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9671 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9672 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9673 LPFC_BMBX_BIT1_ADDR_HI);
9675 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9676 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9677 LPFC_BMBX_BIT1_ADDR_LO);
9682 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9683 * @phba: pointer to lpfc hba data structure.
9685 * This routine is invoked to teardown the bootstrap mailbox
9686 * region and release all host resources. This routine requires
9687 * the caller to ensure all mailbox commands recovered, no
9688 * additional mailbox comands are sent, and interrupts are disabled
9689 * before calling this routine.
9693 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9695 dma_free_coherent(&phba->pcidev->dev,
9696 phba->sli4_hba.bmbx.bmbx_size,
9697 phba->sli4_hba.bmbx.dmabuf->virt,
9698 phba->sli4_hba.bmbx.dmabuf->phys);
9700 kfree(phba->sli4_hba.bmbx.dmabuf);
9701 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9704 static const char * const lpfc_topo_to_str[] = {
9714 #define LINK_FLAGS_DEF 0x0
9715 #define LINK_FLAGS_P2P 0x1
9716 #define LINK_FLAGS_LOOP 0x2
9718 * lpfc_map_topology - Map the topology read from READ_CONFIG
9719 * @phba: pointer to lpfc hba data structure.
9720 * @rd_config: pointer to read config data
9722 * This routine is invoked to map the topology values as read
9723 * from the read config mailbox command. If the persistent
9724 * topology feature is supported, the firmware will provide the
9725 * saved topology information to be used in INIT_LINK
9728 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9732 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9733 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9734 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9736 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9737 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9740 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9741 "2019 FW does not support persistent topology "
9742 "Using driver parameter defined value [%s]",
9743 lpfc_topo_to_str[phba->cfg_topology]);
9746 /* FW supports persistent topology - override module parameter value */
9747 phba->hba_flag |= HBA_PERSISTENT_TOPO;
9749 /* if ASIC_GEN_NUM >= 0xC) */
9750 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9751 LPFC_SLI_INTF_IF_TYPE_6) ||
9752 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9753 LPFC_SLI_INTF_FAMILY_G6)) {
9755 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9756 ? FLAGS_TOPOLOGY_MODE_LOOP
9757 : FLAGS_TOPOLOGY_MODE_PT_PT);
9759 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
9763 /* If topology failover set - pt is '0' or '1' */
9764 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9765 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9767 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9768 ? FLAGS_TOPOLOGY_MODE_PT_PT
9769 : FLAGS_TOPOLOGY_MODE_LOOP);
9772 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
9773 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9774 "2020 Using persistent topology value [%s]",
9775 lpfc_topo_to_str[phba->cfg_topology]);
9777 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9778 "2021 Invalid topology values from FW "
9779 "Using driver parameter defined value [%s]",
9780 lpfc_topo_to_str[phba->cfg_topology]);
9785 * lpfc_sli4_read_config - Get the config parameters.
9786 * @phba: pointer to lpfc hba data structure.
9788 * This routine is invoked to read the configuration parameters from the HBA.
9789 * The configuration parameters are used to set the base and maximum values
9790 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9791 * allocation for the port.
9795 * -ENOMEM - No available memory
9796 * -EIO - The mailbox failed to complete successfully.
9799 lpfc_sli4_read_config(struct lpfc_hba *phba)
9802 struct lpfc_mbx_read_config *rd_config;
9803 union lpfc_sli4_cfg_shdr *shdr;
9804 uint32_t shdr_status, shdr_add_status;
9805 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9806 struct lpfc_rsrc_desc_fcfcoe *desc;
9808 uint16_t forced_link_speed;
9809 uint32_t if_type, qmin;
9810 int length, i, rc = 0, rc2;
9812 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9814 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9815 "2011 Unable to allocate memory for issuing "
9816 "SLI_CONFIG_SPECIAL mailbox command\n");
9820 lpfc_read_config(phba, pmb);
9822 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9823 if (rc != MBX_SUCCESS) {
9824 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9825 "2012 Mailbox failed , mbxCmd x%x "
9826 "READ_CONFIG, mbxStatus x%x\n",
9827 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9828 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9831 rd_config = &pmb->u.mqe.un.rd_config;
9832 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9833 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
9834 phba->sli4_hba.lnk_info.lnk_tp =
9835 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
9836 phba->sli4_hba.lnk_info.lnk_no =
9837 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
9838 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9839 "3081 lnk_type:%d, lnk_numb:%d\n",
9840 phba->sli4_hba.lnk_info.lnk_tp,
9841 phba->sli4_hba.lnk_info.lnk_no);
9843 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9844 "3082 Mailbox (x%x) returned ldv:x0\n",
9845 bf_get(lpfc_mqe_command, &pmb->u.mqe));
9846 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
9847 phba->bbcredit_support = 1;
9848 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
9851 phba->sli4_hba.conf_trunk =
9852 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
9853 phba->sli4_hba.extents_in_use =
9854 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
9855 phba->sli4_hba.max_cfg_param.max_xri =
9856 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
9857 /* Reduce resource usage in kdump environment */
9858 if (is_kdump_kernel() &&
9859 phba->sli4_hba.max_cfg_param.max_xri > 512)
9860 phba->sli4_hba.max_cfg_param.max_xri = 512;
9861 phba->sli4_hba.max_cfg_param.xri_base =
9862 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
9863 phba->sli4_hba.max_cfg_param.max_vpi =
9864 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
9865 /* Limit the max we support */
9866 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
9867 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
9868 phba->sli4_hba.max_cfg_param.vpi_base =
9869 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
9870 phba->sli4_hba.max_cfg_param.max_rpi =
9871 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
9872 phba->sli4_hba.max_cfg_param.rpi_base =
9873 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
9874 phba->sli4_hba.max_cfg_param.max_vfi =
9875 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
9876 phba->sli4_hba.max_cfg_param.vfi_base =
9877 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
9878 phba->sli4_hba.max_cfg_param.max_fcfi =
9879 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
9880 phba->sli4_hba.max_cfg_param.max_eq =
9881 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
9882 phba->sli4_hba.max_cfg_param.max_rq =
9883 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
9884 phba->sli4_hba.max_cfg_param.max_wq =
9885 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
9886 phba->sli4_hba.max_cfg_param.max_cq =
9887 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
9888 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
9889 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
9890 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
9891 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
9892 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
9893 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
9894 phba->max_vports = phba->max_vpi;
9896 /* Next decide on FPIN or Signal E2E CGN support
9897 * For congestion alarms and warnings valid combination are:
9898 * 1. FPIN alarms / FPIN warnings
9899 * 2. Signal alarms / Signal warnings
9900 * 3. FPIN alarms / Signal warnings
9901 * 4. Signal alarms / FPIN warnings
9903 * Initialize the adapter frequency to 100 mSecs
9905 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9906 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9907 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9909 if (lpfc_use_cgn_signal) {
9910 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
9911 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
9912 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
9914 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
9915 /* MUST support both alarm and warning
9916 * because EDC does not support alarm alone.
9918 if (phba->cgn_reg_signal !=
9919 EDC_CG_SIG_WARN_ONLY) {
9920 /* Must support both or none */
9921 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9922 phba->cgn_reg_signal =
9923 EDC_CG_SIG_NOTSUPPORTED;
9925 phba->cgn_reg_signal =
9926 EDC_CG_SIG_WARN_ALARM;
9927 phba->cgn_reg_fpin =
9933 /* Set the congestion initial signal and fpin values. */
9934 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
9935 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
9937 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
9938 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
9939 phba->cgn_reg_signal, phba->cgn_reg_fpin);
9941 lpfc_map_topology(phba, rd_config);
9942 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9943 "2003 cfg params Extents? %d "
9948 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
9949 phba->sli4_hba.extents_in_use,
9950 phba->sli4_hba.max_cfg_param.xri_base,
9951 phba->sli4_hba.max_cfg_param.max_xri,
9952 phba->sli4_hba.max_cfg_param.vpi_base,
9953 phba->sli4_hba.max_cfg_param.max_vpi,
9954 phba->sli4_hba.max_cfg_param.vfi_base,
9955 phba->sli4_hba.max_cfg_param.max_vfi,
9956 phba->sli4_hba.max_cfg_param.rpi_base,
9957 phba->sli4_hba.max_cfg_param.max_rpi,
9958 phba->sli4_hba.max_cfg_param.max_fcfi,
9959 phba->sli4_hba.max_cfg_param.max_eq,
9960 phba->sli4_hba.max_cfg_param.max_cq,
9961 phba->sli4_hba.max_cfg_param.max_wq,
9962 phba->sli4_hba.max_cfg_param.max_rq,
9966 * Calculate queue resources based on how
9967 * many WQ/CQ/EQs are available.
9969 qmin = phba->sli4_hba.max_cfg_param.max_wq;
9970 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
9971 qmin = phba->sli4_hba.max_cfg_param.max_cq;
9972 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
9973 qmin = phba->sli4_hba.max_cfg_param.max_eq;
9975 * Whats left after this can go toward NVME / FCP.
9976 * The minus 4 accounts for ELS, NVME LS, MBOX
9977 * plus one extra. When configured for
9978 * NVMET, FCP io channel WQs are not created.
9982 /* Check to see if there is enough for NVME */
9983 if ((phba->cfg_irq_chann > qmin) ||
9984 (phba->cfg_hdw_queue > qmin)) {
9985 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9986 "2005 Reducing Queues - "
9987 "FW resource limitation: "
9988 "WQ %d CQ %d EQ %d: min %d: "
9990 phba->sli4_hba.max_cfg_param.max_wq,
9991 phba->sli4_hba.max_cfg_param.max_cq,
9992 phba->sli4_hba.max_cfg_param.max_eq,
9993 qmin, phba->cfg_irq_chann,
9994 phba->cfg_hdw_queue);
9996 if (phba->cfg_irq_chann > qmin)
9997 phba->cfg_irq_chann = qmin;
9998 if (phba->cfg_hdw_queue > qmin)
9999 phba->cfg_hdw_queue = qmin;
10006 /* Update link speed if forced link speed is supported */
10007 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10008 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10009 forced_link_speed =
10010 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
10011 if (forced_link_speed) {
10012 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
10014 switch (forced_link_speed) {
10015 case LINK_SPEED_1G:
10016 phba->cfg_link_speed =
10017 LPFC_USER_LINK_SPEED_1G;
10019 case LINK_SPEED_2G:
10020 phba->cfg_link_speed =
10021 LPFC_USER_LINK_SPEED_2G;
10023 case LINK_SPEED_4G:
10024 phba->cfg_link_speed =
10025 LPFC_USER_LINK_SPEED_4G;
10027 case LINK_SPEED_8G:
10028 phba->cfg_link_speed =
10029 LPFC_USER_LINK_SPEED_8G;
10031 case LINK_SPEED_10G:
10032 phba->cfg_link_speed =
10033 LPFC_USER_LINK_SPEED_10G;
10035 case LINK_SPEED_16G:
10036 phba->cfg_link_speed =
10037 LPFC_USER_LINK_SPEED_16G;
10039 case LINK_SPEED_32G:
10040 phba->cfg_link_speed =
10041 LPFC_USER_LINK_SPEED_32G;
10043 case LINK_SPEED_64G:
10044 phba->cfg_link_speed =
10045 LPFC_USER_LINK_SPEED_64G;
10048 phba->cfg_link_speed =
10049 LPFC_USER_LINK_SPEED_AUTO;
10052 lpfc_printf_log(phba, KERN_ERR,
10054 "0047 Unrecognized link "
10056 forced_link_speed);
10057 phba->cfg_link_speed =
10058 LPFC_USER_LINK_SPEED_AUTO;
10063 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
10064 length = phba->sli4_hba.max_cfg_param.max_xri -
10065 lpfc_sli4_get_els_iocb_cnt(phba);
10066 if (phba->cfg_hba_queue_depth > length) {
10067 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10068 "3361 HBA queue depth changed from %d to %d\n",
10069 phba->cfg_hba_queue_depth, length);
10070 phba->cfg_hba_queue_depth = length;
10073 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
10074 LPFC_SLI_INTF_IF_TYPE_2)
10077 /* get the pf# and vf# for SLI4 if_type 2 port */
10078 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
10079 sizeof(struct lpfc_sli4_cfg_mhdr));
10080 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
10081 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
10082 length, LPFC_SLI4_MBX_EMBED);
10084 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10085 shdr = (union lpfc_sli4_cfg_shdr *)
10086 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
10087 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10088 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10089 if (rc2 || shdr_status || shdr_add_status) {
10090 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10091 "3026 Mailbox failed , mbxCmd x%x "
10092 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
10093 bf_get(lpfc_mqe_command, &pmb->u.mqe),
10094 bf_get(lpfc_mqe_status, &pmb->u.mqe));
10098 /* search for fc_fcoe resrouce descriptor */
10099 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
10101 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
10102 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
10103 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
10104 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
10105 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
10106 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
10109 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
10110 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
10111 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
10112 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
10113 phba->sli4_hba.iov.pf_number =
10114 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
10115 phba->sli4_hba.iov.vf_number =
10116 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
10121 if (i < LPFC_RSRC_DESC_MAX_NUM)
10122 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10123 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
10124 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
10125 phba->sli4_hba.iov.vf_number);
10127 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10128 "3028 GET_FUNCTION_CONFIG: failed to find "
10129 "Resource Descriptor:x%x\n",
10130 LPFC_RSRC_DESC_TYPE_FCFCOE);
10133 mempool_free(pmb, phba->mbox_mem_pool);
10138 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
10139 * @phba: pointer to lpfc hba data structure.
10141 * This routine is invoked to setup the port-side endian order when
10142 * the port if_type is 0. This routine has no function for other
10147 * -ENOMEM - No available memory
10148 * -EIO - The mailbox failed to complete successfully.
10151 lpfc_setup_endian_order(struct lpfc_hba *phba)
10153 LPFC_MBOXQ_t *mboxq;
10154 uint32_t if_type, rc = 0;
10155 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
10156 HOST_ENDIAN_HIGH_WORD1};
10158 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10160 case LPFC_SLI_INTF_IF_TYPE_0:
10161 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10164 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10165 "0492 Unable to allocate memory for "
10166 "issuing SLI_CONFIG_SPECIAL mailbox "
10172 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
10173 * two words to contain special data values and no other data.
10175 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
10176 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
10177 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10178 if (rc != MBX_SUCCESS) {
10179 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10180 "0493 SLI_CONFIG_SPECIAL mailbox "
10181 "failed with status x%x\n",
10185 mempool_free(mboxq, phba->mbox_mem_pool);
10187 case LPFC_SLI_INTF_IF_TYPE_6:
10188 case LPFC_SLI_INTF_IF_TYPE_2:
10189 case LPFC_SLI_INTF_IF_TYPE_1:
10197 * lpfc_sli4_queue_verify - Verify and update EQ counts
10198 * @phba: pointer to lpfc hba data structure.
10200 * This routine is invoked to check the user settable queue counts for EQs.
10201 * After this routine is called the counts will be set to valid values that
10202 * adhere to the constraints of the system's interrupt vectors and the port's
10207 * -ENOMEM - No available memory
10210 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
10213 * Sanity check for configured queue parameters against the run-time
10214 * device parameters
10217 if (phba->nvmet_support) {
10218 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
10219 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
10220 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
10221 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
10224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10225 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
10226 phba->cfg_hdw_queue, phba->cfg_irq_chann,
10227 phba->cfg_nvmet_mrq);
10229 /* Get EQ depth from module parameter, fake the default for now */
10230 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10231 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10233 /* Get CQ depth from module parameter, fake the default for now */
10234 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10235 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10240 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
10242 struct lpfc_queue *qdesc;
10246 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
10247 /* Create Fast Path IO CQs */
10248 if (phba->enab_exp_wqcq_pages)
10249 /* Increase the CQ size when WQEs contain an embedded cdb */
10250 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10251 phba->sli4_hba.cq_esize,
10252 LPFC_CQE_EXP_COUNT, cpu);
10255 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10256 phba->sli4_hba.cq_esize,
10257 phba->sli4_hba.cq_ecount, cpu);
10259 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10260 "0499 Failed allocate fast-path IO CQ (%d)\n",
10264 qdesc->qe_valid = 1;
10266 qdesc->chann = cpu;
10267 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
10269 /* Create Fast Path IO WQs */
10270 if (phba->enab_exp_wqcq_pages) {
10271 /* Increase the WQ size when WQEs contain an embedded cdb */
10272 wqesize = (phba->fcp_embed_io) ?
10273 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
10274 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10276 LPFC_WQE_EXP_COUNT, cpu);
10278 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10279 phba->sli4_hba.wq_esize,
10280 phba->sli4_hba.wq_ecount, cpu);
10283 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10284 "0503 Failed allocate fast-path IO WQ (%d)\n",
10289 qdesc->chann = cpu;
10290 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
10291 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10296 * lpfc_sli4_queue_create - Create all the SLI4 queues
10297 * @phba: pointer to lpfc hba data structure.
10299 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
10300 * operation. For each SLI4 queue type, the parameters such as queue entry
10301 * count (queue depth) shall be taken from the module parameter. For now,
10302 * we just use some constant number as place holder.
10306 * -ENOMEM - No availble memory
10307 * -EIO - The mailbox failed to complete successfully.
10310 lpfc_sli4_queue_create(struct lpfc_hba *phba)
10312 struct lpfc_queue *qdesc;
10313 int idx, cpu, eqcpu;
10314 struct lpfc_sli4_hdw_queue *qp;
10315 struct lpfc_vector_map_info *cpup;
10316 struct lpfc_vector_map_info *eqcpup;
10317 struct lpfc_eq_intr_info *eqi;
10320 * Create HBA Record arrays.
10321 * Both NVME and FCP will share that same vectors / EQs
10323 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
10324 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
10325 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
10326 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
10327 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
10328 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
10329 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10330 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10331 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10332 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10334 if (!phba->sli4_hba.hdwq) {
10335 phba->sli4_hba.hdwq = kcalloc(
10336 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
10338 if (!phba->sli4_hba.hdwq) {
10339 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10340 "6427 Failed allocate memory for "
10341 "fast-path Hardware Queue array\n");
10344 /* Prepare hardware queues to take IO buffers */
10345 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10346 qp = &phba->sli4_hba.hdwq[idx];
10347 spin_lock_init(&qp->io_buf_list_get_lock);
10348 spin_lock_init(&qp->io_buf_list_put_lock);
10349 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
10350 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
10351 qp->get_io_bufs = 0;
10352 qp->put_io_bufs = 0;
10353 qp->total_io_bufs = 0;
10354 spin_lock_init(&qp->abts_io_buf_list_lock);
10355 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
10356 qp->abts_scsi_io_bufs = 0;
10357 qp->abts_nvme_io_bufs = 0;
10358 INIT_LIST_HEAD(&qp->sgl_list);
10359 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
10360 spin_lock_init(&qp->hdwq_lock);
10364 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10365 if (phba->nvmet_support) {
10366 phba->sli4_hba.nvmet_cqset = kcalloc(
10367 phba->cfg_nvmet_mrq,
10368 sizeof(struct lpfc_queue *),
10370 if (!phba->sli4_hba.nvmet_cqset) {
10371 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10372 "3121 Fail allocate memory for "
10373 "fast-path CQ set array\n");
10376 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
10377 phba->cfg_nvmet_mrq,
10378 sizeof(struct lpfc_queue *),
10380 if (!phba->sli4_hba.nvmet_mrq_hdr) {
10381 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10382 "3122 Fail allocate memory for "
10383 "fast-path RQ set hdr array\n");
10386 phba->sli4_hba.nvmet_mrq_data = kcalloc(
10387 phba->cfg_nvmet_mrq,
10388 sizeof(struct lpfc_queue *),
10390 if (!phba->sli4_hba.nvmet_mrq_data) {
10391 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10392 "3124 Fail allocate memory for "
10393 "fast-path RQ set data array\n");
10399 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10401 /* Create HBA Event Queues (EQs) */
10402 for_each_present_cpu(cpu) {
10403 /* We only want to create 1 EQ per vector, even though
10404 * multiple CPUs might be using that vector. so only
10405 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
10407 cpup = &phba->sli4_hba.cpu_map[cpu];
10408 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10411 /* Get a ptr to the Hardware Queue associated with this CPU */
10412 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10414 /* Allocate an EQ */
10415 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10416 phba->sli4_hba.eq_esize,
10417 phba->sli4_hba.eq_ecount, cpu);
10419 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10420 "0497 Failed allocate EQ (%d)\n",
10424 qdesc->qe_valid = 1;
10425 qdesc->hdwq = cpup->hdwq;
10426 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
10427 qdesc->last_cpu = qdesc->chann;
10429 /* Save the allocated EQ in the Hardware Queue */
10430 qp->hba_eq = qdesc;
10432 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
10433 list_add(&qdesc->cpu_list, &eqi->list);
10436 /* Now we need to populate the other Hardware Queues, that share
10437 * an IRQ vector, with the associated EQ ptr.
10439 for_each_present_cpu(cpu) {
10440 cpup = &phba->sli4_hba.cpu_map[cpu];
10442 /* Check for EQ already allocated in previous loop */
10443 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
10446 /* Check for multiple CPUs per hdwq */
10447 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10451 /* We need to share an EQ for this hdwq */
10452 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
10453 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
10454 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
10457 /* Allocate IO Path SLI4 CQ/WQs */
10458 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10459 if (lpfc_alloc_io_wq_cq(phba, idx))
10463 if (phba->nvmet_support) {
10464 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10465 cpu = lpfc_find_cpu_handle(phba, idx,
10466 LPFC_FIND_BY_HDWQ);
10467 qdesc = lpfc_sli4_queue_alloc(phba,
10468 LPFC_DEFAULT_PAGE_SIZE,
10469 phba->sli4_hba.cq_esize,
10470 phba->sli4_hba.cq_ecount,
10473 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10474 "3142 Failed allocate NVME "
10475 "CQ Set (%d)\n", idx);
10478 qdesc->qe_valid = 1;
10480 qdesc->chann = cpu;
10481 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
10486 * Create Slow Path Completion Queues (CQs)
10489 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
10490 /* Create slow-path Mailbox Command Complete Queue */
10491 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10492 phba->sli4_hba.cq_esize,
10493 phba->sli4_hba.cq_ecount, cpu);
10495 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10496 "0500 Failed allocate slow-path mailbox CQ\n");
10499 qdesc->qe_valid = 1;
10500 phba->sli4_hba.mbx_cq = qdesc;
10502 /* Create slow-path ELS Complete Queue */
10503 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10504 phba->sli4_hba.cq_esize,
10505 phba->sli4_hba.cq_ecount, cpu);
10507 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10508 "0501 Failed allocate slow-path ELS CQ\n");
10511 qdesc->qe_valid = 1;
10512 qdesc->chann = cpu;
10513 phba->sli4_hba.els_cq = qdesc;
10517 * Create Slow Path Work Queues (WQs)
10520 /* Create Mailbox Command Queue */
10522 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10523 phba->sli4_hba.mq_esize,
10524 phba->sli4_hba.mq_ecount, cpu);
10526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10527 "0505 Failed allocate slow-path MQ\n");
10530 qdesc->chann = cpu;
10531 phba->sli4_hba.mbx_wq = qdesc;
10534 * Create ELS Work Queues
10537 /* Create slow-path ELS Work Queue */
10538 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10539 phba->sli4_hba.wq_esize,
10540 phba->sli4_hba.wq_ecount, cpu);
10542 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10543 "0504 Failed allocate slow-path ELS WQ\n");
10546 qdesc->chann = cpu;
10547 phba->sli4_hba.els_wq = qdesc;
10548 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10550 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10551 /* Create NVME LS Complete Queue */
10552 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10553 phba->sli4_hba.cq_esize,
10554 phba->sli4_hba.cq_ecount, cpu);
10556 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10557 "6079 Failed allocate NVME LS CQ\n");
10560 qdesc->chann = cpu;
10561 qdesc->qe_valid = 1;
10562 phba->sli4_hba.nvmels_cq = qdesc;
10564 /* Create NVME LS Work Queue */
10565 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10566 phba->sli4_hba.wq_esize,
10567 phba->sli4_hba.wq_ecount, cpu);
10569 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10570 "6080 Failed allocate NVME LS WQ\n");
10573 qdesc->chann = cpu;
10574 phba->sli4_hba.nvmels_wq = qdesc;
10575 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10579 * Create Receive Queue (RQ)
10582 /* Create Receive Queue for header */
10583 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10584 phba->sli4_hba.rq_esize,
10585 phba->sli4_hba.rq_ecount, cpu);
10587 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10588 "0506 Failed allocate receive HRQ\n");
10591 phba->sli4_hba.hdr_rq = qdesc;
10593 /* Create Receive Queue for data */
10594 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10595 phba->sli4_hba.rq_esize,
10596 phba->sli4_hba.rq_ecount, cpu);
10598 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10599 "0507 Failed allocate receive DRQ\n");
10602 phba->sli4_hba.dat_rq = qdesc;
10604 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10605 phba->nvmet_support) {
10606 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10607 cpu = lpfc_find_cpu_handle(phba, idx,
10608 LPFC_FIND_BY_HDWQ);
10609 /* Create NVMET Receive Queue for header */
10610 qdesc = lpfc_sli4_queue_alloc(phba,
10611 LPFC_DEFAULT_PAGE_SIZE,
10612 phba->sli4_hba.rq_esize,
10613 LPFC_NVMET_RQE_DEF_COUNT,
10616 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10617 "3146 Failed allocate "
10622 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10624 /* Only needed for header of RQ pair */
10625 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10628 if (qdesc->rqbp == NULL) {
10629 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10630 "6131 Failed allocate "
10635 /* Put list in known state in case driver load fails. */
10636 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10638 /* Create NVMET Receive Queue for data */
10639 qdesc = lpfc_sli4_queue_alloc(phba,
10640 LPFC_DEFAULT_PAGE_SIZE,
10641 phba->sli4_hba.rq_esize,
10642 LPFC_NVMET_RQE_DEF_COUNT,
10645 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10646 "3156 Failed allocate "
10651 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10655 /* Clear NVME stats */
10656 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10657 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10658 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10659 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10663 /* Clear SCSI stats */
10664 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10665 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10666 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10667 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10674 lpfc_sli4_queue_destroy(phba);
10679 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
10682 lpfc_sli4_queue_free(*qp);
10688 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10695 for (idx = 0; idx < max; idx++)
10696 __lpfc_sli4_release_queue(&(*qs)[idx]);
10703 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
10705 struct lpfc_sli4_hdw_queue *hdwq;
10706 struct lpfc_queue *eq;
10709 hdwq = phba->sli4_hba.hdwq;
10711 /* Loop thru all Hardware Queues */
10712 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10713 /* Free the CQ/WQ corresponding to the Hardware Queue */
10714 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10715 lpfc_sli4_queue_free(hdwq[idx].io_wq);
10716 hdwq[idx].hba_eq = NULL;
10717 hdwq[idx].io_cq = NULL;
10718 hdwq[idx].io_wq = NULL;
10719 if (phba->cfg_xpsgl && !phba->nvmet_support)
10720 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10721 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
10723 /* Loop thru all IRQ vectors */
10724 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10725 /* Free the EQ corresponding to the IRQ vector */
10726 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10727 lpfc_sli4_queue_free(eq);
10728 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10733 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10734 * @phba: pointer to lpfc hba data structure.
10736 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10741 * -ENOMEM - No available memory
10742 * -EIO - The mailbox failed to complete successfully.
10745 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10748 * Set FREE_INIT before beginning to free the queues.
10749 * Wait until the users of queues to acknowledge to
10750 * release queues by clearing FREE_WAIT.
10752 spin_lock_irq(&phba->hbalock);
10753 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10754 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10755 spin_unlock_irq(&phba->hbalock);
10757 spin_lock_irq(&phba->hbalock);
10759 spin_unlock_irq(&phba->hbalock);
10761 lpfc_sli4_cleanup_poll_list(phba);
10763 /* Release HBA eqs */
10764 if (phba->sli4_hba.hdwq)
10765 lpfc_sli4_release_hdwq(phba);
10767 if (phba->nvmet_support) {
10768 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10769 phba->cfg_nvmet_mrq);
10771 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10772 phba->cfg_nvmet_mrq);
10773 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10774 phba->cfg_nvmet_mrq);
10777 /* Release mailbox command work queue */
10778 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
10780 /* Release ELS work queue */
10781 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10783 /* Release ELS work queue */
10784 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
10786 /* Release unsolicited receive queue */
10787 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10788 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
10790 /* Release ELS complete queue */
10791 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10793 /* Release NVME LS complete queue */
10794 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
10796 /* Release mailbox command complete queue */
10797 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10799 /* Everything on this list has been freed */
10800 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10802 /* Done with freeing the queues */
10803 spin_lock_irq(&phba->hbalock);
10804 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10805 spin_unlock_irq(&phba->hbalock);
10809 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10811 struct lpfc_rqb *rqbp;
10812 struct lpfc_dmabuf *h_buf;
10813 struct rqb_dmabuf *rqb_buffer;
10816 while (!list_empty(&rqbp->rqb_buffer_list)) {
10817 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10818 struct lpfc_dmabuf, list);
10820 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10821 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
10822 rqbp->buffer_count--;
10828 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
10829 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
10830 int qidx, uint32_t qtype)
10832 struct lpfc_sli_ring *pring;
10835 if (!eq || !cq || !wq) {
10836 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10837 "6085 Fast-path %s (%d) not allocated\n",
10838 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
10842 /* create the Cq first */
10843 rc = lpfc_cq_create(phba, cq, eq,
10844 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
10846 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10847 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
10848 qidx, (uint32_t)rc);
10852 if (qtype != LPFC_MBOX) {
10853 /* Setup cq_map for fast lookup */
10855 *cq_map = cq->queue_id;
10857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10858 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
10859 qidx, cq->queue_id, qidx, eq->queue_id);
10861 /* create the wq */
10862 rc = lpfc_wq_create(phba, wq, cq, qtype);
10864 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10865 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
10866 qidx, (uint32_t)rc);
10867 /* no need to tear down cq - caller will do so */
10871 /* Bind this CQ/WQ to the NVME ring */
10873 pring->sli.sli4.wqp = (void *)wq;
10876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10877 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
10878 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
10880 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
10882 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10883 "0539 Failed setup of slow-path MQ: "
10884 "rc = 0x%x\n", rc);
10885 /* no need to tear down cq - caller will do so */
10889 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10890 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
10891 phba->sli4_hba.mbx_wq->queue_id,
10892 phba->sli4_hba.mbx_cq->queue_id);
10899 * lpfc_setup_cq_lookup - Setup the CQ lookup table
10900 * @phba: pointer to lpfc hba data structure.
10902 * This routine will populate the cq_lookup table by all
10903 * available CQ queue_id's.
10906 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
10908 struct lpfc_queue *eq, *childq;
10911 memset(phba->sli4_hba.cq_lookup, 0,
10912 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
10913 /* Loop thru all IRQ vectors */
10914 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10915 /* Get the EQ corresponding to the IRQ vector */
10916 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
10919 /* Loop through all CQs associated with that EQ */
10920 list_for_each_entry(childq, &eq->child_list, list) {
10921 if (childq->queue_id > phba->sli4_hba.cq_max)
10923 if (childq->subtype == LPFC_IO)
10924 phba->sli4_hba.cq_lookup[childq->queue_id] =
10931 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
10932 * @phba: pointer to lpfc hba data structure.
10934 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
10939 * -ENOMEM - No available memory
10940 * -EIO - The mailbox failed to complete successfully.
10943 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
10945 uint32_t shdr_status, shdr_add_status;
10946 union lpfc_sli4_cfg_shdr *shdr;
10947 struct lpfc_vector_map_info *cpup;
10948 struct lpfc_sli4_hdw_queue *qp;
10949 LPFC_MBOXQ_t *mboxq;
10951 uint32_t length, usdelay;
10954 /* Check for dual-ULP support */
10955 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10958 "3249 Unable to allocate memory for "
10959 "QUERY_FW_CFG mailbox command\n");
10962 length = (sizeof(struct lpfc_mbx_query_fw_config) -
10963 sizeof(struct lpfc_sli4_cfg_mhdr));
10964 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10965 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
10966 length, LPFC_SLI4_MBX_EMBED);
10968 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10970 shdr = (union lpfc_sli4_cfg_shdr *)
10971 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10972 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10973 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10974 if (shdr_status || shdr_add_status || rc) {
10975 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10976 "3250 QUERY_FW_CFG mailbox failed with status "
10977 "x%x add_status x%x, mbx status x%x\n",
10978 shdr_status, shdr_add_status, rc);
10979 mempool_free(mboxq, phba->mbox_mem_pool);
10984 phba->sli4_hba.fw_func_mode =
10985 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
10986 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
10987 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
10988 phba->sli4_hba.physical_port =
10989 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
10990 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10991 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
10992 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
10993 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
10995 mempool_free(mboxq, phba->mbox_mem_pool);
10998 * Set up HBA Event Queues (EQs)
11000 qp = phba->sli4_hba.hdwq;
11002 /* Set up HBA event queue */
11004 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11005 "3147 Fast-path EQs not allocated\n");
11010 /* Loop thru all IRQ vectors */
11011 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11012 /* Create HBA Event Queues (EQs) in order */
11013 for_each_present_cpu(cpu) {
11014 cpup = &phba->sli4_hba.cpu_map[cpu];
11016 /* Look for the CPU thats using that vector with
11017 * LPFC_CPU_FIRST_IRQ set.
11019 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11021 if (qidx != cpup->eq)
11024 /* Create an EQ for that vector */
11025 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
11026 phba->cfg_fcp_imax);
11028 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11029 "0523 Failed setup of fast-path"
11030 " EQ (%d), rc = 0x%x\n",
11031 cpup->eq, (uint32_t)rc);
11035 /* Save the EQ for that vector in the hba_eq_hdl */
11036 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
11037 qp[cpup->hdwq].hba_eq;
11039 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11040 "2584 HBA EQ setup: queue[%d]-id=%d\n",
11042 qp[cpup->hdwq].hba_eq->queue_id);
11046 /* Loop thru all Hardware Queues */
11047 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11048 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
11049 cpup = &phba->sli4_hba.cpu_map[cpu];
11051 /* Create the CQ/WQ corresponding to the Hardware Queue */
11052 rc = lpfc_create_wq_cq(phba,
11053 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
11056 &phba->sli4_hba.hdwq[qidx].io_cq_map,
11060 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11061 "0535 Failed to setup fastpath "
11062 "IO WQ/CQ (%d), rc = 0x%x\n",
11063 qidx, (uint32_t)rc);
11069 * Set up Slow Path Complete Queues (CQs)
11072 /* Set up slow-path MBOX CQ/MQ */
11074 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
11075 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11076 "0528 %s not allocated\n",
11077 phba->sli4_hba.mbx_cq ?
11078 "Mailbox WQ" : "Mailbox CQ");
11083 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11084 phba->sli4_hba.mbx_cq,
11085 phba->sli4_hba.mbx_wq,
11086 NULL, 0, LPFC_MBOX);
11088 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11089 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
11093 if (phba->nvmet_support) {
11094 if (!phba->sli4_hba.nvmet_cqset) {
11095 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11096 "3165 Fast-path NVME CQ Set "
11097 "array not allocated\n");
11101 if (phba->cfg_nvmet_mrq > 1) {
11102 rc = lpfc_cq_create_set(phba,
11103 phba->sli4_hba.nvmet_cqset,
11105 LPFC_WCQ, LPFC_NVMET);
11107 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11108 "3164 Failed setup of NVME CQ "
11109 "Set, rc = 0x%x\n",
11114 /* Set up NVMET Receive Complete Queue */
11115 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
11117 LPFC_WCQ, LPFC_NVMET);
11119 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11120 "6089 Failed setup NVMET CQ: "
11121 "rc = 0x%x\n", (uint32_t)rc);
11124 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
11126 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11127 "6090 NVMET CQ setup: cq-id=%d, "
11128 "parent eq-id=%d\n",
11129 phba->sli4_hba.nvmet_cqset[0]->queue_id,
11130 qp[0].hba_eq->queue_id);
11134 /* Set up slow-path ELS WQ/CQ */
11135 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
11136 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11137 "0530 ELS %s not allocated\n",
11138 phba->sli4_hba.els_cq ? "WQ" : "CQ");
11142 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11143 phba->sli4_hba.els_cq,
11144 phba->sli4_hba.els_wq,
11145 NULL, 0, LPFC_ELS);
11147 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11148 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
11152 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11153 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
11154 phba->sli4_hba.els_wq->queue_id,
11155 phba->sli4_hba.els_cq->queue_id);
11157 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11158 /* Set up NVME LS Complete Queue */
11159 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
11160 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11161 "6091 LS %s not allocated\n",
11162 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
11166 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11167 phba->sli4_hba.nvmels_cq,
11168 phba->sli4_hba.nvmels_wq,
11169 NULL, 0, LPFC_NVME_LS);
11171 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11172 "0526 Failed setup of NVVME LS WQ/CQ: "
11173 "rc = 0x%x\n", (uint32_t)rc);
11177 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11178 "6096 ELS WQ setup: wq-id=%d, "
11179 "parent cq-id=%d\n",
11180 phba->sli4_hba.nvmels_wq->queue_id,
11181 phba->sli4_hba.nvmels_cq->queue_id);
11185 * Create NVMET Receive Queue (RQ)
11187 if (phba->nvmet_support) {
11188 if ((!phba->sli4_hba.nvmet_cqset) ||
11189 (!phba->sli4_hba.nvmet_mrq_hdr) ||
11190 (!phba->sli4_hba.nvmet_mrq_data)) {
11191 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11192 "6130 MRQ CQ Queues not "
11197 if (phba->cfg_nvmet_mrq > 1) {
11198 rc = lpfc_mrq_create(phba,
11199 phba->sli4_hba.nvmet_mrq_hdr,
11200 phba->sli4_hba.nvmet_mrq_data,
11201 phba->sli4_hba.nvmet_cqset,
11204 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11205 "6098 Failed setup of NVMET "
11206 "MRQ: rc = 0x%x\n",
11212 rc = lpfc_rq_create(phba,
11213 phba->sli4_hba.nvmet_mrq_hdr[0],
11214 phba->sli4_hba.nvmet_mrq_data[0],
11215 phba->sli4_hba.nvmet_cqset[0],
11218 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11219 "6057 Failed setup of NVMET "
11220 "Receive Queue: rc = 0x%x\n",
11226 phba, KERN_INFO, LOG_INIT,
11227 "6099 NVMET RQ setup: hdr-rq-id=%d, "
11228 "dat-rq-id=%d parent cq-id=%d\n",
11229 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
11230 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
11231 phba->sli4_hba.nvmet_cqset[0]->queue_id);
11236 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
11237 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11238 "0540 Receive Queue not allocated\n");
11243 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
11244 phba->sli4_hba.els_cq, LPFC_USOL);
11246 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11247 "0541 Failed setup of Receive Queue: "
11248 "rc = 0x%x\n", (uint32_t)rc);
11252 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11253 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
11254 "parent cq-id=%d\n",
11255 phba->sli4_hba.hdr_rq->queue_id,
11256 phba->sli4_hba.dat_rq->queue_id,
11257 phba->sli4_hba.els_cq->queue_id);
11259 if (phba->cfg_fcp_imax)
11260 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
11264 for (qidx = 0; qidx < phba->cfg_irq_chann;
11265 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
11266 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
11269 if (phba->sli4_hba.cq_max) {
11270 kfree(phba->sli4_hba.cq_lookup);
11271 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
11272 sizeof(struct lpfc_queue *), GFP_KERNEL);
11273 if (!phba->sli4_hba.cq_lookup) {
11274 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11275 "0549 Failed setup of CQ Lookup table: "
11276 "size 0x%x\n", phba->sli4_hba.cq_max);
11280 lpfc_setup_cq_lookup(phba);
11285 lpfc_sli4_queue_unset(phba);
11291 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
11292 * @phba: pointer to lpfc hba data structure.
11294 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
11299 * -ENOMEM - No available memory
11300 * -EIO - The mailbox failed to complete successfully.
11303 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
11305 struct lpfc_sli4_hdw_queue *qp;
11306 struct lpfc_queue *eq;
11309 /* Unset mailbox command work queue */
11310 if (phba->sli4_hba.mbx_wq)
11311 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
11313 /* Unset NVME LS work queue */
11314 if (phba->sli4_hba.nvmels_wq)
11315 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
11317 /* Unset ELS work queue */
11318 if (phba->sli4_hba.els_wq)
11319 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
11321 /* Unset unsolicited receive queue */
11322 if (phba->sli4_hba.hdr_rq)
11323 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
11324 phba->sli4_hba.dat_rq);
11326 /* Unset mailbox command complete queue */
11327 if (phba->sli4_hba.mbx_cq)
11328 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
11330 /* Unset ELS complete queue */
11331 if (phba->sli4_hba.els_cq)
11332 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
11334 /* Unset NVME LS complete queue */
11335 if (phba->sli4_hba.nvmels_cq)
11336 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
11338 if (phba->nvmet_support) {
11339 /* Unset NVMET MRQ queue */
11340 if (phba->sli4_hba.nvmet_mrq_hdr) {
11341 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11344 phba->sli4_hba.nvmet_mrq_hdr[qidx],
11345 phba->sli4_hba.nvmet_mrq_data[qidx]);
11348 /* Unset NVMET CQ Set complete queue */
11349 if (phba->sli4_hba.nvmet_cqset) {
11350 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11352 phba, phba->sli4_hba.nvmet_cqset[qidx]);
11356 /* Unset fast-path SLI4 queues */
11357 if (phba->sli4_hba.hdwq) {
11358 /* Loop thru all Hardware Queues */
11359 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11360 /* Destroy the CQ/WQ corresponding to Hardware Queue */
11361 qp = &phba->sli4_hba.hdwq[qidx];
11362 lpfc_wq_destroy(phba, qp->io_wq);
11363 lpfc_cq_destroy(phba, qp->io_cq);
11365 /* Loop thru all IRQ vectors */
11366 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11367 /* Destroy the EQ corresponding to the IRQ vector */
11368 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11369 lpfc_eq_destroy(phba, eq);
11373 kfree(phba->sli4_hba.cq_lookup);
11374 phba->sli4_hba.cq_lookup = NULL;
11375 phba->sli4_hba.cq_max = 0;
11379 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
11380 * @phba: pointer to lpfc hba data structure.
11382 * This routine is invoked to allocate and set up a pool of completion queue
11383 * events. The body of the completion queue event is a completion queue entry
11384 * CQE. For now, this pool is used for the interrupt service routine to queue
11385 * the following HBA completion queue events for the worker thread to process:
11386 * - Mailbox asynchronous events
11387 * - Receive queue completion unsolicited events
11388 * Later, this can be used for all the slow-path events.
11392 * -ENOMEM - No available memory
11395 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
11397 struct lpfc_cq_event *cq_event;
11400 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
11401 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
11403 goto out_pool_create_fail;
11404 list_add_tail(&cq_event->list,
11405 &phba->sli4_hba.sp_cqe_event_pool);
11409 out_pool_create_fail:
11410 lpfc_sli4_cq_event_pool_destroy(phba);
11415 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
11416 * @phba: pointer to lpfc hba data structure.
11418 * This routine is invoked to free the pool of completion queue events at
11419 * driver unload time. Note that, it is the responsibility of the driver
11420 * cleanup routine to free all the outstanding completion-queue events
11421 * allocated from this pool back into the pool before invoking this routine
11422 * to destroy the pool.
11425 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
11427 struct lpfc_cq_event *cq_event, *next_cq_event;
11429 list_for_each_entry_safe(cq_event, next_cq_event,
11430 &phba->sli4_hba.sp_cqe_event_pool, list) {
11431 list_del(&cq_event->list);
11437 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11438 * @phba: pointer to lpfc hba data structure.
11440 * This routine is the lock free version of the API invoked to allocate a
11441 * completion-queue event from the free pool.
11443 * Return: Pointer to the newly allocated completion-queue event if successful
11446 struct lpfc_cq_event *
11447 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11449 struct lpfc_cq_event *cq_event = NULL;
11451 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
11452 struct lpfc_cq_event, list);
11457 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11458 * @phba: pointer to lpfc hba data structure.
11460 * This routine is the lock version of the API invoked to allocate a
11461 * completion-queue event from the free pool.
11463 * Return: Pointer to the newly allocated completion-queue event if successful
11466 struct lpfc_cq_event *
11467 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11469 struct lpfc_cq_event *cq_event;
11470 unsigned long iflags;
11472 spin_lock_irqsave(&phba->hbalock, iflags);
11473 cq_event = __lpfc_sli4_cq_event_alloc(phba);
11474 spin_unlock_irqrestore(&phba->hbalock, iflags);
11479 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11480 * @phba: pointer to lpfc hba data structure.
11481 * @cq_event: pointer to the completion queue event to be freed.
11483 * This routine is the lock free version of the API invoked to release a
11484 * completion-queue event back into the free pool.
11487 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11488 struct lpfc_cq_event *cq_event)
11490 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
11494 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11495 * @phba: pointer to lpfc hba data structure.
11496 * @cq_event: pointer to the completion queue event to be freed.
11498 * This routine is the lock version of the API invoked to release a
11499 * completion-queue event back into the free pool.
11502 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11503 struct lpfc_cq_event *cq_event)
11505 unsigned long iflags;
11506 spin_lock_irqsave(&phba->hbalock, iflags);
11507 __lpfc_sli4_cq_event_release(phba, cq_event);
11508 spin_unlock_irqrestore(&phba->hbalock, iflags);
11512 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
11513 * @phba: pointer to lpfc hba data structure.
11515 * This routine is to free all the pending completion-queue events to the
11516 * back into the free pool for device reset.
11519 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
11521 LIST_HEAD(cq_event_list);
11522 struct lpfc_cq_event *cq_event;
11523 unsigned long iflags;
11525 /* Retrieve all the pending WCQEs from pending WCQE lists */
11527 /* Pending ELS XRI abort events */
11528 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11529 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11531 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11533 /* Pending asynnc events */
11534 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
11535 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
11537 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
11539 while (!list_empty(&cq_event_list)) {
11540 list_remove_head(&cq_event_list, cq_event,
11541 struct lpfc_cq_event, list);
11542 lpfc_sli4_cq_event_release(phba, cq_event);
11547 * lpfc_pci_function_reset - Reset pci function.
11548 * @phba: pointer to lpfc hba data structure.
11550 * This routine is invoked to request a PCI function reset. It will destroys
11551 * all resources assigned to the PCI function which originates this request.
11555 * -ENOMEM - No available memory
11556 * -EIO - The mailbox failed to complete successfully.
11559 lpfc_pci_function_reset(struct lpfc_hba *phba)
11561 LPFC_MBOXQ_t *mboxq;
11562 uint32_t rc = 0, if_type;
11563 uint32_t shdr_status, shdr_add_status;
11565 uint32_t port_reset = 0;
11566 union lpfc_sli4_cfg_shdr *shdr;
11567 struct lpfc_register reg_data;
11570 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11572 case LPFC_SLI_INTF_IF_TYPE_0:
11573 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
11576 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11577 "0494 Unable to allocate memory for "
11578 "issuing SLI_FUNCTION_RESET mailbox "
11583 /* Setup PCI function reset mailbox-ioctl command */
11584 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11585 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11586 LPFC_SLI4_MBX_EMBED);
11587 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11588 shdr = (union lpfc_sli4_cfg_shdr *)
11589 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11590 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11591 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11593 mempool_free(mboxq, phba->mbox_mem_pool);
11594 if (shdr_status || shdr_add_status || rc) {
11595 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11596 "0495 SLI_FUNCTION_RESET mailbox "
11597 "failed with status x%x add_status x%x,"
11598 " mbx status x%x\n",
11599 shdr_status, shdr_add_status, rc);
11603 case LPFC_SLI_INTF_IF_TYPE_2:
11604 case LPFC_SLI_INTF_IF_TYPE_6:
11607 * Poll the Port Status Register and wait for RDY for
11608 * up to 30 seconds. If the port doesn't respond, treat
11611 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
11612 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11613 STATUSregaddr, ®_data.word0)) {
11617 if (bf_get(lpfc_sliport_status_rdy, ®_data))
11622 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
11623 phba->work_status[0] = readl(
11624 phba->sli4_hba.u.if_type2.ERR1regaddr);
11625 phba->work_status[1] = readl(
11626 phba->sli4_hba.u.if_type2.ERR2regaddr);
11627 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11628 "2890 Port not ready, port status reg "
11629 "0x%x error 1=0x%x, error 2=0x%x\n",
11631 phba->work_status[0],
11632 phba->work_status[1]);
11637 if (bf_get(lpfc_sliport_status_pldv, ®_data))
11638 lpfc_pldv_detect = true;
11642 * Reset the port now
11644 reg_data.word0 = 0;
11645 bf_set(lpfc_sliport_ctrl_end, ®_data,
11646 LPFC_SLIPORT_LITTLE_ENDIAN);
11647 bf_set(lpfc_sliport_ctrl_ip, ®_data,
11648 LPFC_SLIPORT_INIT_PORT);
11649 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11652 pci_read_config_word(phba->pcidev,
11653 PCI_DEVICE_ID, &devid);
11658 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
11664 case LPFC_SLI_INTF_IF_TYPE_1:
11670 /* Catch the not-ready port failure after a port reset. */
11672 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11673 "3317 HBA not functional: IP Reset Failed "
11674 "try: echo fw_reset > board_mode\n");
11682 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11683 * @phba: pointer to lpfc hba data structure.
11685 * This routine is invoked to set up the PCI device memory space for device
11686 * with SLI-4 interface spec.
11690 * other values - error
11693 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11695 struct pci_dev *pdev = phba->pcidev;
11696 unsigned long bar0map_len, bar1map_len, bar2map_len;
11703 /* Set the device DMA mask size */
11704 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11706 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11711 * The BARs and register set definitions and offset locations are
11712 * dependent on the if_type.
11714 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11715 &phba->sli4_hba.sli_intf.word0)) {
11719 /* There is no SLI3 failback for SLI4 devices. */
11720 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11721 LPFC_SLI_INTF_VALID) {
11722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11723 "2894 SLI_INTF reg contents invalid "
11724 "sli_intf reg 0x%x\n",
11725 phba->sli4_hba.sli_intf.word0);
11729 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11731 * Get the bus address of SLI4 device Bar regions and the
11732 * number of bytes required by each mapping. The mapping of the
11733 * particular PCI BARs regions is dependent on the type of
11736 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11737 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11738 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
11741 * Map SLI4 PCI Config Space Register base to a kernel virtual
11744 phba->sli4_hba.conf_regs_memmap_p =
11745 ioremap(phba->pci_bar0_map, bar0map_len);
11746 if (!phba->sli4_hba.conf_regs_memmap_p) {
11747 dev_printk(KERN_ERR, &pdev->dev,
11748 "ioremap failed for SLI4 PCI config "
11752 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
11753 /* Set up BAR0 PCI config space register memory map */
11754 lpfc_sli4_bar0_register_memmap(phba, if_type);
11756 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11757 bar0map_len = pci_resource_len(pdev, 1);
11758 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
11759 dev_printk(KERN_ERR, &pdev->dev,
11760 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
11763 phba->sli4_hba.conf_regs_memmap_p =
11764 ioremap(phba->pci_bar0_map, bar0map_len);
11765 if (!phba->sli4_hba.conf_regs_memmap_p) {
11766 dev_printk(KERN_ERR, &pdev->dev,
11767 "ioremap failed for SLI4 PCI config "
11771 lpfc_sli4_bar0_register_memmap(phba, if_type);
11774 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11775 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11777 * Map SLI4 if type 0 HBA Control Register base to a
11778 * kernel virtual address and setup the registers.
11780 phba->pci_bar1_map = pci_resource_start(pdev,
11782 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11783 phba->sli4_hba.ctrl_regs_memmap_p =
11784 ioremap(phba->pci_bar1_map,
11786 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11787 dev_err(&pdev->dev,
11788 "ioremap failed for SLI4 HBA "
11789 "control registers.\n");
11791 goto out_iounmap_conf;
11793 phba->pci_bar2_memmap_p =
11794 phba->sli4_hba.ctrl_regs_memmap_p;
11795 lpfc_sli4_bar1_register_memmap(phba, if_type);
11798 goto out_iounmap_conf;
11802 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11803 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11805 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11806 * virtual address and setup the registers.
11808 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11809 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11810 phba->sli4_hba.drbl_regs_memmap_p =
11811 ioremap(phba->pci_bar1_map, bar1map_len);
11812 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11813 dev_err(&pdev->dev,
11814 "ioremap failed for SLI4 HBA doorbell registers.\n");
11816 goto out_iounmap_conf;
11818 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11819 lpfc_sli4_bar1_register_memmap(phba, if_type);
11822 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11823 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11825 * Map SLI4 if type 0 HBA Doorbell Register base to
11826 * a kernel virtual address and setup the registers.
11828 phba->pci_bar2_map = pci_resource_start(pdev,
11830 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11831 phba->sli4_hba.drbl_regs_memmap_p =
11832 ioremap(phba->pci_bar2_map,
11834 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11835 dev_err(&pdev->dev,
11836 "ioremap failed for SLI4 HBA"
11837 " doorbell registers.\n");
11839 goto out_iounmap_ctrl;
11841 phba->pci_bar4_memmap_p =
11842 phba->sli4_hba.drbl_regs_memmap_p;
11843 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
11845 goto out_iounmap_all;
11848 goto out_iounmap_all;
11852 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
11853 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11855 * Map SLI4 if type 6 HBA DPP Register base to a kernel
11856 * virtual address and setup the registers.
11858 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
11859 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11860 phba->sli4_hba.dpp_regs_memmap_p =
11861 ioremap(phba->pci_bar2_map, bar2map_len);
11862 if (!phba->sli4_hba.dpp_regs_memmap_p) {
11863 dev_err(&pdev->dev,
11864 "ioremap failed for SLI4 HBA dpp registers.\n");
11866 goto out_iounmap_ctrl;
11868 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
11871 /* Set up the EQ/CQ register handeling functions now */
11873 case LPFC_SLI_INTF_IF_TYPE_0:
11874 case LPFC_SLI_INTF_IF_TYPE_2:
11875 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
11876 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
11877 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
11879 case LPFC_SLI_INTF_IF_TYPE_6:
11880 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
11881 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
11882 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
11891 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11893 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11895 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11901 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
11902 * @phba: pointer to lpfc hba data structure.
11904 * This routine is invoked to unset the PCI device memory space for device
11905 * with SLI-4 interface spec.
11908 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
11911 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11914 case LPFC_SLI_INTF_IF_TYPE_0:
11915 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11916 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11917 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11919 case LPFC_SLI_INTF_IF_TYPE_2:
11920 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11922 case LPFC_SLI_INTF_IF_TYPE_6:
11923 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11924 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11925 if (phba->sli4_hba.dpp_regs_memmap_p)
11926 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
11928 case LPFC_SLI_INTF_IF_TYPE_1:
11930 dev_printk(KERN_ERR, &phba->pcidev->dev,
11931 "FATAL - unsupported SLI4 interface type - %d\n",
11938 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
11939 * @phba: pointer to lpfc hba data structure.
11941 * This routine is invoked to enable the MSI-X interrupt vectors to device
11942 * with SLI-3 interface specs.
11946 * other values - error
11949 lpfc_sli_enable_msix(struct lpfc_hba *phba)
11954 /* Set up MSI-X multi-message vectors */
11955 rc = pci_alloc_irq_vectors(phba->pcidev,
11956 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
11958 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11959 "0420 PCI enable MSI-X failed (%d)\n", rc);
11964 * Assign MSI-X vectors to interrupt handlers
11967 /* vector-0 is associated to slow-path handler */
11968 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
11969 &lpfc_sli_sp_intr_handler, 0,
11970 LPFC_SP_DRIVER_HANDLER_NAME, phba);
11972 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11973 "0421 MSI-X slow-path request_irq failed "
11978 /* vector-1 is associated to fast-path handler */
11979 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
11980 &lpfc_sli_fp_intr_handler, 0,
11981 LPFC_FP_DRIVER_HANDLER_NAME, phba);
11984 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11985 "0429 MSI-X fast-path request_irq failed "
11991 * Configure HBA MSI-X attention conditions to messages
11993 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11997 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11998 "0474 Unable to allocate memory for issuing "
11999 "MBOX_CONFIG_MSI command\n");
12002 rc = lpfc_config_msi(phba, pmb);
12005 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
12006 if (rc != MBX_SUCCESS) {
12007 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
12008 "0351 Config MSI mailbox command failed, "
12009 "mbxCmd x%x, mbxStatus x%x\n",
12010 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
12014 /* Free memory allocated for mailbox command */
12015 mempool_free(pmb, phba->mbox_mem_pool);
12019 /* Free memory allocated for mailbox command */
12020 mempool_free(pmb, phba->mbox_mem_pool);
12023 /* free the irq already requested */
12024 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
12027 /* free the irq already requested */
12028 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
12031 /* Unconfigure MSI-X capability structure */
12032 pci_free_irq_vectors(phba->pcidev);
12039 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
12040 * @phba: pointer to lpfc hba data structure.
12042 * This routine is invoked to enable the MSI interrupt mode to device with
12043 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
12044 * enable the MSI vector. The device driver is responsible for calling the
12045 * request_irq() to register MSI vector with a interrupt the handler, which
12046 * is done in this function.
12050 * other values - error
12053 lpfc_sli_enable_msi(struct lpfc_hba *phba)
12057 rc = pci_enable_msi(phba->pcidev);
12059 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12060 "0462 PCI enable MSI mode success.\n");
12062 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12063 "0471 PCI enable MSI mode failed (%d)\n", rc);
12067 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12068 0, LPFC_DRIVER_NAME, phba);
12070 pci_disable_msi(phba->pcidev);
12071 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12072 "0478 MSI request_irq failed (%d)\n", rc);
12078 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
12079 * @phba: pointer to lpfc hba data structure.
12080 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
12082 * This routine is invoked to enable device interrupt and associate driver's
12083 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
12084 * spec. Depends on the interrupt mode configured to the driver, the driver
12085 * will try to fallback from the configured interrupt mode to an interrupt
12086 * mode which is supported by the platform, kernel, and device in the order
12088 * MSI-X -> MSI -> IRQ.
12092 * other values - error
12095 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12097 uint32_t intr_mode = LPFC_INTR_ERROR;
12100 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
12101 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
12104 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
12106 if (cfg_mode == 2) {
12107 /* Now, try to enable MSI-X interrupt mode */
12108 retval = lpfc_sli_enable_msix(phba);
12110 /* Indicate initialization to MSI-X mode */
12111 phba->intr_type = MSIX;
12116 /* Fallback to MSI if MSI-X initialization failed */
12117 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12118 retval = lpfc_sli_enable_msi(phba);
12120 /* Indicate initialization to MSI mode */
12121 phba->intr_type = MSI;
12126 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12127 if (phba->intr_type == NONE) {
12128 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12129 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12131 /* Indicate initialization to INTx mode */
12132 phba->intr_type = INTx;
12140 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
12141 * @phba: pointer to lpfc hba data structure.
12143 * This routine is invoked to disable device interrupt and disassociate the
12144 * driver's interrupt handler(s) from interrupt vector(s) to device with
12145 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
12146 * release the interrupt vector(s) for the message signaled interrupt.
12149 lpfc_sli_disable_intr(struct lpfc_hba *phba)
12153 if (phba->intr_type == MSIX)
12154 nr_irqs = LPFC_MSIX_VECTORS;
12158 for (i = 0; i < nr_irqs; i++)
12159 free_irq(pci_irq_vector(phba->pcidev, i), phba);
12160 pci_free_irq_vectors(phba->pcidev);
12162 /* Reset interrupt management states */
12163 phba->intr_type = NONE;
12164 phba->sli.slistat.sli_intr = 0;
12168 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
12169 * @phba: pointer to lpfc hba data structure.
12170 * @id: EQ vector index or Hardware Queue index
12171 * @match: LPFC_FIND_BY_EQ = match by EQ
12172 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
12173 * Return the CPU that matches the selection criteria
12176 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
12178 struct lpfc_vector_map_info *cpup;
12181 /* Loop through all CPUs */
12182 for_each_present_cpu(cpu) {
12183 cpup = &phba->sli4_hba.cpu_map[cpu];
12185 /* If we are matching by EQ, there may be multiple CPUs using
12186 * using the same vector, so select the one with
12187 * LPFC_CPU_FIRST_IRQ set.
12189 if ((match == LPFC_FIND_BY_EQ) &&
12190 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
12194 /* If matching by HDWQ, select the first CPU that matches */
12195 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
12203 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
12204 * @phba: pointer to lpfc hba data structure.
12205 * @cpu: CPU map index
12206 * @phys_id: CPU package physical id
12207 * @core_id: CPU core id
12210 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
12211 uint16_t phys_id, uint16_t core_id)
12213 struct lpfc_vector_map_info *cpup;
12216 for_each_present_cpu(idx) {
12217 cpup = &phba->sli4_hba.cpu_map[idx];
12218 /* Does the cpup match the one we are looking for */
12219 if ((cpup->phys_id == phys_id) &&
12220 (cpup->core_id == core_id) &&
12229 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
12230 * @phba: pointer to lpfc hba data structure.
12231 * @eqidx: index for eq and irq vector
12232 * @flag: flags to set for vector_map structure
12233 * @cpu: cpu used to index vector_map structure
12235 * The routine assigns eq info into vector_map structure
12238 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
12241 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
12242 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
12245 cpup->flag |= flag;
12247 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12248 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
12249 cpu, eqhdl->irq, cpup->eq, cpup->flag);
12253 * lpfc_cpu_map_array_init - Initialize cpu_map structure
12254 * @phba: pointer to lpfc hba data structure.
12256 * The routine initializes the cpu_map array structure
12259 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
12261 struct lpfc_vector_map_info *cpup;
12262 struct lpfc_eq_intr_info *eqi;
12265 for_each_possible_cpu(cpu) {
12266 cpup = &phba->sli4_hba.cpu_map[cpu];
12267 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
12268 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
12269 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
12270 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
12272 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
12273 INIT_LIST_HEAD(&eqi->list);
12279 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
12280 * @phba: pointer to lpfc hba data structure.
12282 * The routine initializes the hba_eq_hdl array structure
12285 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
12287 struct lpfc_hba_eq_hdl *eqhdl;
12290 for (i = 0; i < phba->cfg_irq_chann; i++) {
12291 eqhdl = lpfc_get_eq_hdl(i);
12292 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
12293 eqhdl->phba = phba;
12298 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
12299 * @phba: pointer to lpfc hba data structure.
12300 * @vectors: number of msix vectors allocated.
12302 * The routine will figure out the CPU affinity assignment for every
12303 * MSI-X vector allocated for the HBA.
12304 * In addition, the CPU to IO channel mapping will be calculated
12305 * and the phba->sli4_hba.cpu_map array will reflect this.
12308 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
12310 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
12311 int max_phys_id, min_phys_id;
12312 int max_core_id, min_core_id;
12313 struct lpfc_vector_map_info *cpup;
12314 struct lpfc_vector_map_info *new_cpup;
12316 struct cpuinfo_x86 *cpuinfo;
12318 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12319 struct lpfc_hdwq_stat *c_stat;
12323 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
12325 min_core_id = LPFC_VECTOR_MAP_EMPTY;
12327 /* Update CPU map with physical id and core id of each CPU */
12328 for_each_present_cpu(cpu) {
12329 cpup = &phba->sli4_hba.cpu_map[cpu];
12331 cpuinfo = &cpu_data(cpu);
12332 cpup->phys_id = cpuinfo->phys_proc_id;
12333 cpup->core_id = cpuinfo->cpu_core_id;
12334 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
12335 cpup->flag |= LPFC_CPU_MAP_HYPER;
12337 /* No distinction between CPUs for other platforms */
12339 cpup->core_id = cpu;
12342 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12343 "3328 CPU %d physid %d coreid %d flag x%x\n",
12344 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
12346 if (cpup->phys_id > max_phys_id)
12347 max_phys_id = cpup->phys_id;
12348 if (cpup->phys_id < min_phys_id)
12349 min_phys_id = cpup->phys_id;
12351 if (cpup->core_id > max_core_id)
12352 max_core_id = cpup->core_id;
12353 if (cpup->core_id < min_core_id)
12354 min_core_id = cpup->core_id;
12357 /* After looking at each irq vector assigned to this pcidev, its
12358 * possible to see that not ALL CPUs have been accounted for.
12359 * Next we will set any unassigned (unaffinitized) cpu map
12360 * entries to a IRQ on the same phys_id.
12362 first_cpu = cpumask_first(cpu_present_mask);
12363 start_cpu = first_cpu;
12365 for_each_present_cpu(cpu) {
12366 cpup = &phba->sli4_hba.cpu_map[cpu];
12368 /* Is this CPU entry unassigned */
12369 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12370 /* Mark CPU as IRQ not assigned by the kernel */
12371 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12373 /* If so, find a new_cpup thats on the the SAME
12374 * phys_id as cpup. start_cpu will start where we
12375 * left off so all unassigned entries don't get assgined
12376 * the IRQ of the first entry.
12378 new_cpu = start_cpu;
12379 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12380 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12381 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12382 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
12383 (new_cpup->phys_id == cpup->phys_id))
12385 new_cpu = cpumask_next(
12386 new_cpu, cpu_present_mask);
12387 if (new_cpu == nr_cpumask_bits)
12388 new_cpu = first_cpu;
12390 /* At this point, we leave the CPU as unassigned */
12393 /* We found a matching phys_id, so copy the IRQ info */
12394 cpup->eq = new_cpup->eq;
12396 /* Bump start_cpu to the next slot to minmize the
12397 * chance of having multiple unassigned CPU entries
12398 * selecting the same IRQ.
12400 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12401 if (start_cpu == nr_cpumask_bits)
12402 start_cpu = first_cpu;
12404 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12405 "3337 Set Affinity: CPU %d "
12406 "eq %d from peer cpu %d same "
12408 cpu, cpup->eq, new_cpu,
12413 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
12414 start_cpu = first_cpu;
12416 for_each_present_cpu(cpu) {
12417 cpup = &phba->sli4_hba.cpu_map[cpu];
12419 /* Is this entry unassigned */
12420 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12421 /* Mark it as IRQ not assigned by the kernel */
12422 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12424 /* If so, find a new_cpup thats on ANY phys_id
12425 * as the cpup. start_cpu will start where we
12426 * left off so all unassigned entries don't get
12427 * assigned the IRQ of the first entry.
12429 new_cpu = start_cpu;
12430 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12431 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12432 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12433 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
12435 new_cpu = cpumask_next(
12436 new_cpu, cpu_present_mask);
12437 if (new_cpu == nr_cpumask_bits)
12438 new_cpu = first_cpu;
12440 /* We should never leave an entry unassigned */
12441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12442 "3339 Set Affinity: CPU %d "
12443 "eq %d UNASSIGNED\n",
12444 cpup->hdwq, cpup->eq);
12447 /* We found an available entry, copy the IRQ info */
12448 cpup->eq = new_cpup->eq;
12450 /* Bump start_cpu to the next slot to minmize the
12451 * chance of having multiple unassigned CPU entries
12452 * selecting the same IRQ.
12454 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12455 if (start_cpu == nr_cpumask_bits)
12456 start_cpu = first_cpu;
12458 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12459 "3338 Set Affinity: CPU %d "
12460 "eq %d from peer cpu %d (%d/%d)\n",
12461 cpu, cpup->eq, new_cpu,
12462 new_cpup->phys_id, new_cpup->core_id);
12466 /* Assign hdwq indices that are unique across all cpus in the map
12467 * that are also FIRST_CPUs.
12470 for_each_present_cpu(cpu) {
12471 cpup = &phba->sli4_hba.cpu_map[cpu];
12473 /* Only FIRST IRQs get a hdwq index assignment. */
12474 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12477 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
12480 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12481 "3333 Set Affinity: CPU %d (phys %d core %d): "
12482 "hdwq %d eq %d flg x%x\n",
12483 cpu, cpup->phys_id, cpup->core_id,
12484 cpup->hdwq, cpup->eq, cpup->flag);
12486 /* Associate a hdwq with each cpu_map entry
12487 * This will be 1 to 1 - hdwq to cpu, unless there are less
12488 * hardware queues then CPUs. For that case we will just round-robin
12489 * the available hardware queues as they get assigned to CPUs.
12490 * The next_idx is the idx from the FIRST_CPU loop above to account
12491 * for irq_chann < hdwq. The idx is used for round-robin assignments
12492 * and needs to start at 0.
12497 for_each_present_cpu(cpu) {
12498 cpup = &phba->sli4_hba.cpu_map[cpu];
12500 /* FIRST cpus are already mapped. */
12501 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
12504 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
12505 * of the unassigned cpus to the next idx so that all
12506 * hdw queues are fully utilized.
12508 if (next_idx < phba->cfg_hdw_queue) {
12509 cpup->hdwq = next_idx;
12514 /* Not a First CPU and all hdw_queues are used. Reuse a
12515 * Hardware Queue for another CPU, so be smart about it
12516 * and pick one that has its IRQ/EQ mapped to the same phys_id
12517 * (CPU package) and core_id.
12519 new_cpu = start_cpu;
12520 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12521 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12522 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12523 new_cpup->phys_id == cpup->phys_id &&
12524 new_cpup->core_id == cpup->core_id) {
12527 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12528 if (new_cpu == nr_cpumask_bits)
12529 new_cpu = first_cpu;
12532 /* If we can't match both phys_id and core_id,
12533 * settle for just a phys_id match.
12535 new_cpu = start_cpu;
12536 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12537 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12538 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12539 new_cpup->phys_id == cpup->phys_id)
12542 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12543 if (new_cpu == nr_cpumask_bits)
12544 new_cpu = first_cpu;
12547 /* Otherwise just round robin on cfg_hdw_queue */
12548 cpup->hdwq = idx % phba->cfg_hdw_queue;
12552 /* We found an available entry, copy the IRQ info */
12553 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12554 if (start_cpu == nr_cpumask_bits)
12555 start_cpu = first_cpu;
12556 cpup->hdwq = new_cpup->hdwq;
12558 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12559 "3335 Set Affinity: CPU %d (phys %d core %d): "
12560 "hdwq %d eq %d flg x%x\n",
12561 cpu, cpup->phys_id, cpup->core_id,
12562 cpup->hdwq, cpup->eq, cpup->flag);
12566 * Initialize the cpu_map slots for not-present cpus in case
12567 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
12570 for_each_possible_cpu(cpu) {
12571 cpup = &phba->sli4_hba.cpu_map[cpu];
12572 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12573 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
12574 c_stat->hdwq_no = cpup->hdwq;
12576 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
12579 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
12580 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12581 c_stat->hdwq_no = cpup->hdwq;
12583 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12584 "3340 Set Affinity: not present "
12585 "CPU %d hdwq %d\n",
12589 /* The cpu_map array will be used later during initialization
12590 * when EQ / CQ / WQs are allocated and configured.
12596 * lpfc_cpuhp_get_eq
12598 * @phba: pointer to lpfc hba data structure.
12599 * @cpu: cpu going offline
12600 * @eqlist: eq list to append to
12603 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12604 struct list_head *eqlist)
12606 const struct cpumask *maskp;
12607 struct lpfc_queue *eq;
12608 struct cpumask *tmp;
12611 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12615 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12616 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12620 * if irq is not affinitized to the cpu going
12621 * then we don't need to poll the eq attached
12624 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
12626 /* get the cpus that are online and are affini-
12627 * tized to this irq vector. If the count is
12628 * more than 1 then cpuhp is not going to shut-
12629 * down this vector. Since this cpu has not
12630 * gone offline yet, we need >1.
12632 cpumask_and(tmp, maskp, cpu_online_mask);
12633 if (cpumask_weight(tmp) > 1)
12636 /* Now that we have an irq to shutdown, get the eq
12637 * mapped to this irq. Note: multiple hdwq's in
12638 * the software can share an eq, but eventually
12639 * only eq will be mapped to this vector
12641 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12642 list_add(&eq->_poll_list, eqlist);
12648 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12650 if (phba->sli_rev != LPFC_SLI_REV4)
12653 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12656 * unregistering the instance doesn't stop the polling
12657 * timer. Wait for the poll timer to retire.
12660 del_timer_sync(&phba->cpuhp_poll_timer);
12663 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12665 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
12668 __lpfc_cpuhp_remove(phba);
12671 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12673 if (phba->sli_rev != LPFC_SLI_REV4)
12678 if (!list_empty(&phba->poll_list))
12679 mod_timer(&phba->cpuhp_poll_timer,
12680 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
12684 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12688 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12690 if (phba->pport->load_flag & FC_UNLOADING) {
12695 if (phba->sli_rev != LPFC_SLI_REV4) {
12700 /* proceed with the hotplug */
12705 * lpfc_irq_set_aff - set IRQ affinity
12706 * @eqhdl: EQ handle
12707 * @cpu: cpu to set affinity
12711 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12713 cpumask_clear(&eqhdl->aff_mask);
12714 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12715 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12716 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
12720 * lpfc_irq_clear_aff - clear IRQ affinity
12721 * @eqhdl: EQ handle
12725 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12727 cpumask_clear(&eqhdl->aff_mask);
12728 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12732 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12733 * @phba: pointer to HBA context object.
12734 * @cpu: cpu going offline/online
12735 * @offline: true, cpu is going offline. false, cpu is coming online.
12737 * If cpu is going offline, we'll try our best effort to find the next
12738 * online cpu on the phba's original_mask and migrate all offlining IRQ
12741 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
12743 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
12744 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12748 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12750 struct lpfc_vector_map_info *cpup;
12751 struct cpumask *aff_mask;
12752 unsigned int cpu_select, cpu_next, idx;
12753 const struct cpumask *orig_mask;
12755 if (phba->irq_chann_mode == NORMAL_MODE)
12758 orig_mask = &phba->sli4_hba.irq_aff_mask;
12760 if (!cpumask_test_cpu(cpu, orig_mask))
12763 cpup = &phba->sli4_hba.cpu_map[cpu];
12765 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12769 /* Find next online CPU on original mask */
12770 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12771 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
12773 /* Found a valid CPU */
12774 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12775 /* Go through each eqhdl and ensure offlining
12776 * cpu aff_mask is migrated
12778 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12779 aff_mask = lpfc_get_aff_mask(idx);
12781 /* Migrate affinity */
12782 if (cpumask_test_cpu(cpu, aff_mask))
12783 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12787 /* Rely on irqbalance if no online CPUs left on NUMA */
12788 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12789 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12792 /* Migrate affinity back to this CPU */
12793 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12797 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12799 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12800 struct lpfc_queue *eq, *next;
12805 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12809 if (__lpfc_cpuhp_checks(phba, &retval))
12812 lpfc_irq_rebalance(phba, cpu, true);
12814 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12818 /* start polling on these eq's */
12819 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12820 list_del_init(&eq->_poll_list);
12821 lpfc_sli4_start_polling(eq);
12827 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
12829 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12830 struct lpfc_queue *eq, *next;
12835 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12839 if (__lpfc_cpuhp_checks(phba, &retval))
12842 lpfc_irq_rebalance(phba, cpu, false);
12844 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
12845 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
12847 lpfc_sli4_stop_polling(eq);
12854 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
12855 * @phba: pointer to lpfc hba data structure.
12857 * This routine is invoked to enable the MSI-X interrupt vectors to device
12858 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
12859 * to cpus on the system.
12861 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
12862 * the number of cpus on the same numa node as this adapter. The vectors are
12863 * allocated without requesting OS affinity mapping. A vector will be
12864 * allocated and assigned to each online and offline cpu. If the cpu is
12865 * online, then affinity will be set to that cpu. If the cpu is offline, then
12866 * affinity will be set to the nearest peer cpu within the numa node that is
12867 * online. If there are no online cpus within the numa node, affinity is not
12868 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
12869 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
12872 * If numa mode is not enabled and there is more than 1 vector allocated, then
12873 * the driver relies on the managed irq interface where the OS assigns vector to
12874 * cpu affinity. The driver will then use that affinity mapping to setup its
12875 * cpu mapping table.
12879 * other values - error
12882 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
12884 int vectors, rc, index;
12886 const struct cpumask *aff_mask = NULL;
12887 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
12888 struct lpfc_vector_map_info *cpup;
12889 struct lpfc_hba_eq_hdl *eqhdl;
12890 const struct cpumask *maskp;
12891 unsigned int flags = PCI_IRQ_MSIX;
12893 /* Set up MSI-X multi-message vectors */
12894 vectors = phba->cfg_irq_chann;
12896 if (phba->irq_chann_mode != NORMAL_MODE)
12897 aff_mask = &phba->sli4_hba.irq_aff_mask;
12900 cpu_cnt = cpumask_weight(aff_mask);
12901 vectors = min(phba->cfg_irq_chann, cpu_cnt);
12903 /* cpu: iterates over aff_mask including offline or online
12904 * cpu_select: iterates over online aff_mask to set affinity
12906 cpu = cpumask_first(aff_mask);
12907 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12909 flags |= PCI_IRQ_AFFINITY;
12912 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
12914 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12915 "0484 PCI enable MSI-X failed (%d)\n", rc);
12920 /* Assign MSI-X vectors to interrupt handlers */
12921 for (index = 0; index < vectors; index++) {
12922 eqhdl = lpfc_get_eq_hdl(index);
12923 name = eqhdl->handler_name;
12924 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
12925 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
12926 LPFC_DRIVER_HANDLER_NAME"%d", index);
12928 eqhdl->idx = index;
12929 rc = request_irq(pci_irq_vector(phba->pcidev, index),
12930 &lpfc_sli4_hba_intr_handler, 0,
12933 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12934 "0486 MSI-X fast-path (%d) "
12935 "request_irq failed (%d)\n", index, rc);
12939 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
12942 /* If found a neighboring online cpu, set affinity */
12943 if (cpu_select < nr_cpu_ids)
12944 lpfc_irq_set_aff(eqhdl, cpu_select);
12946 /* Assign EQ to cpu_map */
12947 lpfc_assign_eq_map_info(phba, index,
12948 LPFC_CPU_FIRST_IRQ,
12951 /* Iterate to next offline or online cpu in aff_mask */
12952 cpu = cpumask_next(cpu, aff_mask);
12954 /* Find next online cpu in aff_mask to set affinity */
12955 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12956 } else if (vectors == 1) {
12957 cpu = cpumask_first(cpu_present_mask);
12958 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
12961 maskp = pci_irq_get_affinity(phba->pcidev, index);
12963 /* Loop through all CPUs associated with vector index */
12964 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
12965 cpup = &phba->sli4_hba.cpu_map[cpu];
12967 /* If this is the first CPU thats assigned to
12968 * this vector, set LPFC_CPU_FIRST_IRQ.
12970 * With certain platforms its possible that irq
12971 * vectors are affinitized to all the cpu's.
12972 * This can result in each cpu_map.eq to be set
12973 * to the last vector, resulting in overwrite
12974 * of all the previous cpu_map.eq. Ensure that
12975 * each vector receives a place in cpu_map.
12976 * Later call to lpfc_cpu_affinity_check will
12977 * ensure we are nicely balanced out.
12979 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
12981 lpfc_assign_eq_map_info(phba, index,
12982 LPFC_CPU_FIRST_IRQ,
12989 if (vectors != phba->cfg_irq_chann) {
12990 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12991 "3238 Reducing IO channels to match number of "
12992 "MSI-X vectors, requested %d got %d\n",
12993 phba->cfg_irq_chann, vectors);
12994 if (phba->cfg_irq_chann > vectors)
12995 phba->cfg_irq_chann = vectors;
13001 /* free the irq already requested */
13002 for (--index; index >= 0; index--) {
13003 eqhdl = lpfc_get_eq_hdl(index);
13004 lpfc_irq_clear_aff(eqhdl);
13005 irq_set_affinity_hint(eqhdl->irq, NULL);
13006 free_irq(eqhdl->irq, eqhdl);
13009 /* Unconfigure MSI-X capability structure */
13010 pci_free_irq_vectors(phba->pcidev);
13017 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
13018 * @phba: pointer to lpfc hba data structure.
13020 * This routine is invoked to enable the MSI interrupt mode to device with
13021 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
13022 * called to enable the MSI vector. The device driver is responsible for
13023 * calling the request_irq() to register MSI vector with a interrupt the
13024 * handler, which is done in this function.
13028 * other values - error
13031 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
13035 struct lpfc_hba_eq_hdl *eqhdl;
13037 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
13038 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
13040 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13041 "0487 PCI enable MSI mode success.\n");
13043 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13044 "0488 PCI enable MSI mode failed (%d)\n", rc);
13045 return rc ? rc : -1;
13048 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13049 0, LPFC_DRIVER_NAME, phba);
13051 pci_free_irq_vectors(phba->pcidev);
13052 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13053 "0490 MSI request_irq failed (%d)\n", rc);
13057 eqhdl = lpfc_get_eq_hdl(0);
13058 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
13060 cpu = cpumask_first(cpu_present_mask);
13061 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
13063 for (index = 0; index < phba->cfg_irq_chann; index++) {
13064 eqhdl = lpfc_get_eq_hdl(index);
13065 eqhdl->idx = index;
13072 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
13073 * @phba: pointer to lpfc hba data structure.
13074 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
13076 * This routine is invoked to enable device interrupt and associate driver's
13077 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
13078 * interface spec. Depends on the interrupt mode configured to the driver,
13079 * the driver will try to fallback from the configured interrupt mode to an
13080 * interrupt mode which is supported by the platform, kernel, and device in
13082 * MSI-X -> MSI -> IRQ.
13086 * other values - error
13089 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
13091 uint32_t intr_mode = LPFC_INTR_ERROR;
13094 if (cfg_mode == 2) {
13095 /* Preparation before conf_msi mbox cmd */
13098 /* Now, try to enable MSI-X interrupt mode */
13099 retval = lpfc_sli4_enable_msix(phba);
13101 /* Indicate initialization to MSI-X mode */
13102 phba->intr_type = MSIX;
13108 /* Fallback to MSI if MSI-X initialization failed */
13109 if (cfg_mode >= 1 && phba->intr_type == NONE) {
13110 retval = lpfc_sli4_enable_msi(phba);
13112 /* Indicate initialization to MSI mode */
13113 phba->intr_type = MSI;
13118 /* Fallback to INTx if both MSI-X/MSI initalization failed */
13119 if (phba->intr_type == NONE) {
13120 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13121 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
13123 struct lpfc_hba_eq_hdl *eqhdl;
13126 /* Indicate initialization to INTx mode */
13127 phba->intr_type = INTx;
13130 eqhdl = lpfc_get_eq_hdl(0);
13131 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
13133 cpu = cpumask_first(cpu_present_mask);
13134 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
13136 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
13137 eqhdl = lpfc_get_eq_hdl(idx);
13146 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
13147 * @phba: pointer to lpfc hba data structure.
13149 * This routine is invoked to disable device interrupt and disassociate
13150 * the driver's interrupt handler(s) from interrupt vector(s) to device
13151 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
13152 * will release the interrupt vector(s) for the message signaled interrupt.
13155 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
13157 /* Disable the currently initialized interrupt mode */
13158 if (phba->intr_type == MSIX) {
13160 struct lpfc_hba_eq_hdl *eqhdl;
13162 /* Free up MSI-X multi-message vectors */
13163 for (index = 0; index < phba->cfg_irq_chann; index++) {
13164 eqhdl = lpfc_get_eq_hdl(index);
13165 lpfc_irq_clear_aff(eqhdl);
13166 irq_set_affinity_hint(eqhdl->irq, NULL);
13167 free_irq(eqhdl->irq, eqhdl);
13170 free_irq(phba->pcidev->irq, phba);
13173 pci_free_irq_vectors(phba->pcidev);
13175 /* Reset interrupt management states */
13176 phba->intr_type = NONE;
13177 phba->sli.slistat.sli_intr = 0;
13181 * lpfc_unset_hba - Unset SLI3 hba device initialization
13182 * @phba: pointer to lpfc hba data structure.
13184 * This routine is invoked to unset the HBA device initialization steps to
13185 * a device with SLI-3 interface spec.
13188 lpfc_unset_hba(struct lpfc_hba *phba)
13190 struct lpfc_vport *vport = phba->pport;
13191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
13193 spin_lock_irq(shost->host_lock);
13194 vport->load_flag |= FC_UNLOADING;
13195 spin_unlock_irq(shost->host_lock);
13197 kfree(phba->vpi_bmask);
13198 kfree(phba->vpi_ids);
13200 lpfc_stop_hba_timers(phba);
13202 phba->pport->work_port_events = 0;
13204 lpfc_sli_hba_down(phba);
13206 lpfc_sli_brdrestart(phba);
13208 lpfc_sli_disable_intr(phba);
13214 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
13215 * @phba: Pointer to HBA context object.
13217 * This function is called in the SLI4 code path to wait for completion
13218 * of device's XRIs exchange busy. It will check the XRI exchange busy
13219 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
13220 * that, it will check the XRI exchange busy on outstanding FCP and ELS
13221 * I/Os every 30 seconds, log error message, and wait forever. Only when
13222 * all XRI exchange busy complete, the driver unload shall proceed with
13223 * invoking the function reset ioctl mailbox command to the CNA and the
13224 * the rest of the driver unload resource release.
13227 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
13229 struct lpfc_sli4_hdw_queue *qp;
13232 int io_xri_cmpl = 1;
13233 int nvmet_xri_cmpl = 1;
13234 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13236 /* Driver just aborted IOs during the hba_unset process. Pause
13237 * here to give the HBA time to complete the IO and get entries
13238 * into the abts lists.
13240 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
13242 /* Wait for NVME pending IO to flush back to transport. */
13243 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13244 lpfc_nvme_wait_for_io_drain(phba);
13247 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13248 qp = &phba->sli4_hba.hdwq[idx];
13249 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
13250 if (!io_xri_cmpl) /* if list is NOT empty */
13256 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13258 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13261 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
13262 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
13263 if (!nvmet_xri_cmpl)
13264 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13265 "6424 NVMET XRI exchange busy "
13266 "wait time: %d seconds.\n",
13269 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13270 "6100 IO XRI exchange busy "
13271 "wait time: %d seconds.\n",
13274 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13275 "2878 ELS XRI exchange busy "
13276 "wait time: %d seconds.\n",
13278 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
13279 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
13281 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
13282 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
13286 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13287 qp = &phba->sli4_hba.hdwq[idx];
13288 io_xri_cmpl = list_empty(
13289 &qp->lpfc_abts_io_buf_list);
13290 if (!io_xri_cmpl) /* if list is NOT empty */
13296 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13297 nvmet_xri_cmpl = list_empty(
13298 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13301 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13307 * lpfc_sli4_hba_unset - Unset the fcoe hba
13308 * @phba: Pointer to HBA context object.
13310 * This function is called in the SLI4 code path to reset the HBA's FCoE
13311 * function. The caller is not required to hold any lock. This routine
13312 * issues PCI function reset mailbox command to reset the FCoE function.
13313 * At the end of the function, it calls lpfc_hba_down_post function to
13314 * free any pending commands.
13317 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
13320 LPFC_MBOXQ_t *mboxq;
13321 struct pci_dev *pdev = phba->pcidev;
13323 lpfc_stop_hba_timers(phba);
13324 hrtimer_cancel(&phba->cmf_timer);
13327 phba->sli4_hba.intr_enable = 0;
13330 * Gracefully wait out the potential current outstanding asynchronous
13334 /* First, block any pending async mailbox command from posted */
13335 spin_lock_irq(&phba->hbalock);
13336 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13337 spin_unlock_irq(&phba->hbalock);
13338 /* Now, trying to wait it out if we can */
13339 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13341 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
13344 /* Forcefully release the outstanding mailbox command if timed out */
13345 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13346 spin_lock_irq(&phba->hbalock);
13347 mboxq = phba->sli.mbox_active;
13348 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
13349 __lpfc_mbox_cmpl_put(phba, mboxq);
13350 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13351 phba->sli.mbox_active = NULL;
13352 spin_unlock_irq(&phba->hbalock);
13355 /* Abort all iocbs associated with the hba */
13356 lpfc_sli_hba_iocb_abort(phba);
13358 /* Wait for completion of device XRI exchange busy */
13359 lpfc_sli4_xri_exchange_busy_wait(phba);
13361 /* per-phba callback de-registration for hotplug event */
13363 lpfc_cpuhp_remove(phba);
13365 /* Disable PCI subsystem interrupt */
13366 lpfc_sli4_disable_intr(phba);
13368 /* Disable SR-IOV if enabled */
13369 if (phba->cfg_sriov_nr_virtfn)
13370 pci_disable_sriov(pdev);
13372 /* Stop kthread signal shall trigger work_done one more time */
13373 kthread_stop(phba->worker_thread);
13375 /* Disable FW logging to host memory */
13376 lpfc_ras_stop_fwlog(phba);
13378 /* Unset the queues shared with the hardware then release all
13379 * allocated resources.
13381 lpfc_sli4_queue_unset(phba);
13382 lpfc_sli4_queue_destroy(phba);
13384 /* Reset SLI4 HBA FCoE function */
13385 lpfc_pci_function_reset(phba);
13387 /* Free RAS DMA memory */
13388 if (phba->ras_fwlog.ras_enabled)
13389 lpfc_sli4_ras_dma_free(phba);
13391 /* Stop the SLI4 device port */
13393 phba->pport->work_port_events = 0;
13397 lpfc_cgn_crc32(uint32_t crc, u8 byte)
13402 for (bit = 0; bit < 8; bit++) {
13403 msb = (crc >> 31) & 1;
13406 if (msb ^ (byte & 1)) {
13407 crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
13416 lpfc_cgn_reverse_bits(uint32_t wd)
13418 uint32_t result = 0;
13421 for (i = 0; i < 32; i++) {
13423 result |= (1 & (wd >> i));
13429 * The routine corresponds with the algorithm the HBA firmware
13430 * uses to validate the data integrity.
13433 lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
13437 uint8_t *data = (uint8_t *)ptr;
13439 for (i = 0; i < byteLen; ++i)
13440 crc = lpfc_cgn_crc32(crc, data[i]);
13442 result = ~lpfc_cgn_reverse_bits(crc);
13447 lpfc_init_congestion_buf(struct lpfc_hba *phba)
13449 struct lpfc_cgn_info *cp;
13450 struct timespec64 cmpl_time;
13455 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13456 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
13460 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13462 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
13463 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
13464 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
13465 atomic_set(&phba->cgn_sync_warn_cnt, 0);
13467 atomic_set(&phba->cgn_driver_evt_cnt, 0);
13468 atomic_set(&phba->cgn_latency_evt_cnt, 0);
13469 atomic64_set(&phba->cgn_latency_evt, 0);
13470 phba->cgn_evt_minute = 0;
13471 phba->hba_flag &= ~HBA_CGN_DAY_WRAP;
13473 memset(cp, 0xff, LPFC_CGN_DATA_SIZE);
13474 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
13475 cp->cgn_info_version = LPFC_CGN_INFO_V3;
13477 /* cgn parameters */
13478 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
13479 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
13480 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
13481 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
13483 ktime_get_real_ts64(&cmpl_time);
13484 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13486 cp->cgn_info_month = broken.tm_mon + 1;
13487 cp->cgn_info_day = broken.tm_mday;
13488 cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */
13489 cp->cgn_info_hour = broken.tm_hour;
13490 cp->cgn_info_minute = broken.tm_min;
13491 cp->cgn_info_second = broken.tm_sec;
13493 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13494 "2643 CGNInfo Init: Start Time "
13495 "%d/%d/%d %d:%d:%d\n",
13496 cp->cgn_info_day, cp->cgn_info_month,
13497 cp->cgn_info_year, cp->cgn_info_hour,
13498 cp->cgn_info_minute, cp->cgn_info_second);
13500 /* Fill in default LUN qdepth */
13502 size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
13503 cp->cgn_lunq = cpu_to_le16(size);
13506 /* last used Index initialized to 0xff already */
13508 cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13509 cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13510 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13511 cp->cgn_info_crc = cpu_to_le32(crc);
13513 phba->cgn_evt_timestamp = jiffies +
13514 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
13518 lpfc_init_congestion_stat(struct lpfc_hba *phba)
13520 struct lpfc_cgn_info *cp;
13521 struct timespec64 cmpl_time;
13525 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13526 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
13531 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13532 memset(&cp->cgn_stat_npm, 0, LPFC_CGN_STAT_SIZE);
13534 ktime_get_real_ts64(&cmpl_time);
13535 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13537 cp->cgn_stat_month = broken.tm_mon + 1;
13538 cp->cgn_stat_day = broken.tm_mday;
13539 cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */
13540 cp->cgn_stat_hour = broken.tm_hour;
13541 cp->cgn_stat_minute = broken.tm_min;
13543 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13544 "2647 CGNstat Init: Start Time "
13545 "%d/%d/%d %d:%d\n",
13546 cp->cgn_stat_day, cp->cgn_stat_month,
13547 cp->cgn_stat_year, cp->cgn_stat_hour,
13548 cp->cgn_stat_minute);
13550 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13551 cp->cgn_info_crc = cpu_to_le32(crc);
13555 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
13556 * @phba: Pointer to hba context object.
13557 * @reg: flag to determine register or unregister.
13560 __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
13562 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
13563 union lpfc_sli4_cfg_shdr *shdr;
13564 uint32_t shdr_status, shdr_add_status;
13565 LPFC_MBOXQ_t *mboxq;
13571 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13573 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13574 "2641 REG_CONGESTION_BUF mbox allocation fail: "
13575 "HBA state x%x reg %d\n",
13576 phba->pport->port_state, reg);
13580 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
13581 sizeof(struct lpfc_sli4_cfg_mhdr));
13582 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13583 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
13584 LPFC_SLI4_MBX_EMBED);
13585 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
13586 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
13588 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
13590 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
13591 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
13592 reg_congestion_buf->addr_lo =
13593 putPaddrLow(phba->cgn_i->phys);
13594 reg_congestion_buf->addr_hi =
13595 putPaddrHigh(phba->cgn_i->phys);
13597 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13598 shdr = (union lpfc_sli4_cfg_shdr *)
13599 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
13600 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13601 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13603 mempool_free(mboxq, phba->mbox_mem_pool);
13604 if (shdr_status || shdr_add_status || rc) {
13605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13606 "2642 REG_CONGESTION_BUF mailbox "
13607 "failed with status x%x add_status x%x,"
13608 " mbx status x%x reg %d\n",
13609 shdr_status, shdr_add_status, rc, reg);
13616 lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
13618 lpfc_cmf_stop(phba);
13619 return __lpfc_reg_congestion_buf(phba, 0);
13623 lpfc_reg_congestion_buf(struct lpfc_hba *phba)
13625 return __lpfc_reg_congestion_buf(phba, 1);
13629 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
13630 * @phba: Pointer to HBA context object.
13631 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
13633 * This function is called in the SLI4 code path to read the port's
13634 * sli4 capabilities.
13636 * This function may be be called from any context that can block-wait
13637 * for the completion. The expectation is that this routine is called
13638 * typically from probe_one or from the online routine.
13641 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
13644 struct lpfc_mqe *mqe = &mboxq->u.mqe;
13645 struct lpfc_pc_sli4_params *sli4_params;
13648 bool exp_wqcq_pages = true;
13649 struct lpfc_sli4_parameters *mbx_sli4_parameters;
13652 * By default, the driver assumes the SLI4 port requires RPI
13653 * header postings. The SLI4_PARAM response will correct this
13656 phba->sli4_hba.rpi_hdrs_in_use = 1;
13658 /* Read the port's SLI4 Config Parameters */
13659 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
13660 sizeof(struct lpfc_sli4_cfg_mhdr));
13661 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13662 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
13663 length, LPFC_SLI4_MBX_EMBED);
13664 if (!phba->sli4_hba.intr_enable)
13665 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13667 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
13668 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
13672 sli4_params = &phba->sli4_hba.pc_sli4_params;
13673 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
13674 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
13675 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
13676 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
13677 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
13678 mbx_sli4_parameters);
13679 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
13680 mbx_sli4_parameters);
13681 if (bf_get(cfg_phwq, mbx_sli4_parameters))
13682 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
13684 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
13685 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
13686 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
13687 mbx_sli4_parameters);
13688 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
13689 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
13690 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
13691 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
13692 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
13693 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
13694 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
13695 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
13696 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
13697 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
13698 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
13699 mbx_sli4_parameters);
13700 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
13701 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
13702 mbx_sli4_parameters);
13703 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
13704 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
13706 /* Check for Extended Pre-Registered SGL support */
13707 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
13709 /* Check for firmware nvme support */
13710 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13711 bf_get(cfg_xib, mbx_sli4_parameters));
13714 /* Save this to indicate the Firmware supports NVME */
13715 sli4_params->nvme = 1;
13717 /* Firmware NVME support, check driver FC4 NVME support */
13718 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13719 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13720 "6133 Disabling NVME support: "
13721 "FC4 type not supported: x%x\n",
13722 phba->cfg_enable_fc4_type);
13726 /* No firmware NVME support, check driver FC4 NVME support */
13727 sli4_params->nvme = 0;
13728 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13730 "6101 Disabling NVME support: Not "
13731 "supported by firmware (%d %d) x%x\n",
13732 bf_get(cfg_nvme, mbx_sli4_parameters),
13733 bf_get(cfg_xib, mbx_sli4_parameters),
13734 phba->cfg_enable_fc4_type);
13736 phba->nvmet_support = 0;
13737 phba->cfg_nvmet_mrq = 0;
13738 phba->cfg_nvme_seg_cnt = 0;
13740 /* If no FC4 type support, move to just SCSI support */
13741 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13743 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13747 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
13748 * accommodate 512K and 1M IOs in a single nvme buf.
13750 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13751 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
13753 /* Enable embedded Payload BDE if support is indicated */
13754 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13755 phba->cfg_enable_pbde = 1;
13757 phba->cfg_enable_pbde = 0;
13760 * To support Suppress Response feature we must satisfy 3 conditions.
13761 * lpfc_suppress_rsp module parameter must be set (default).
13762 * In SLI4-Parameters Descriptor:
13763 * Extended Inline Buffers (XIB) must be supported.
13764 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13765 * (double negative).
13767 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13768 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
13769 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
13771 phba->cfg_suppress_rsp = 0;
13773 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13774 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13776 /* Make sure that sge_supp_len can be handled by the driver */
13777 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13778 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13781 * Check whether the adapter supports an embedded copy of the
13782 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13783 * to use this option, 128-byte WQEs must be used.
13785 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13786 phba->fcp_embed_io = 1;
13788 phba->fcp_embed_io = 0;
13790 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13791 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
13792 bf_get(cfg_xib, mbx_sli4_parameters),
13793 phba->cfg_enable_pbde,
13794 phba->fcp_embed_io, sli4_params->nvme,
13795 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
13797 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
13798 LPFC_SLI_INTF_IF_TYPE_2) &&
13799 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
13800 LPFC_SLI_INTF_FAMILY_LNCR_A0))
13801 exp_wqcq_pages = false;
13803 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
13804 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
13806 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
13807 phba->enab_exp_wqcq_pages = 1;
13809 phba->enab_exp_wqcq_pages = 0;
13811 * Check if the SLI port supports MDS Diagnostics
13813 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
13814 phba->mds_diags_support = 1;
13816 phba->mds_diags_support = 0;
13819 * Check if the SLI port supports NSLER
13821 if (bf_get(cfg_nsler, mbx_sli4_parameters))
13830 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
13831 * @pdev: pointer to PCI device
13832 * @pid: pointer to PCI device identifier
13834 * This routine is to be called to attach a device with SLI-3 interface spec
13835 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13836 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13837 * information of the device and driver to see if the driver state that it can
13838 * support this kind of device. If the match is successful, the driver core
13839 * invokes this routine. If this routine determines it can claim the HBA, it
13840 * does all the initialization that it needs to do to handle the HBA properly.
13843 * 0 - driver can claim the device
13844 * negative value - driver can not claim the device
13847 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
13849 struct lpfc_hba *phba;
13850 struct lpfc_vport *vport = NULL;
13851 struct Scsi_Host *shost = NULL;
13853 uint32_t cfg_mode, intr_mode;
13855 /* Allocate memory for HBA structure */
13856 phba = lpfc_hba_alloc(pdev);
13860 /* Perform generic PCI device enabling operation */
13861 error = lpfc_enable_pci_dev(phba);
13863 goto out_free_phba;
13865 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
13866 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
13868 goto out_disable_pci_dev;
13870 /* Set up SLI-3 specific device PCI memory space */
13871 error = lpfc_sli_pci_mem_setup(phba);
13873 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13874 "1402 Failed to set up pci memory space.\n");
13875 goto out_disable_pci_dev;
13878 /* Set up SLI-3 specific device driver resources */
13879 error = lpfc_sli_driver_resource_setup(phba);
13881 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13882 "1404 Failed to set up driver resource.\n");
13883 goto out_unset_pci_mem_s3;
13886 /* Initialize and populate the iocb list per host */
13888 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
13890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13891 "1405 Failed to initialize iocb list.\n");
13892 goto out_unset_driver_resource_s3;
13895 /* Set up common device driver resources */
13896 error = lpfc_setup_driver_resource_phase2(phba);
13898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13899 "1406 Failed to set up driver resource.\n");
13900 goto out_free_iocb_list;
13903 /* Get the default values for Model Name and Description */
13904 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13906 /* Create SCSI host to the physical port */
13907 error = lpfc_create_shost(phba);
13909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13910 "1407 Failed to create scsi host.\n");
13911 goto out_unset_driver_resource;
13914 /* Configure sysfs attributes */
13915 vport = phba->pport;
13916 error = lpfc_alloc_sysfs_attr(vport);
13918 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13919 "1476 Failed to allocate sysfs attr\n");
13920 goto out_destroy_shost;
13923 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
13924 /* Now, trying to enable interrupt and bring up the device */
13925 cfg_mode = phba->cfg_use_msi;
13927 /* Put device to a known state before enabling interrupt */
13928 lpfc_stop_port(phba);
13929 /* Configure and enable interrupt */
13930 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
13931 if (intr_mode == LPFC_INTR_ERROR) {
13932 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13933 "0431 Failed to enable interrupt.\n");
13935 goto out_free_sysfs_attr;
13937 /* SLI-3 HBA setup */
13938 if (lpfc_sli_hba_setup(phba)) {
13939 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13940 "1477 Failed to set up hba\n");
13942 goto out_remove_device;
13945 /* Wait 50ms for the interrupts of previous mailbox commands */
13947 /* Check active interrupts on message signaled interrupts */
13948 if (intr_mode == 0 ||
13949 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
13950 /* Log the current active interrupt mode */
13951 phba->intr_mode = intr_mode;
13952 lpfc_log_intr_mode(phba, intr_mode);
13955 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13956 "0447 Configure interrupt mode (%d) "
13957 "failed active interrupt test.\n",
13959 /* Disable the current interrupt mode */
13960 lpfc_sli_disable_intr(phba);
13961 /* Try next level of interrupt mode */
13962 cfg_mode = --intr_mode;
13966 /* Perform post initialization setup */
13967 lpfc_post_init_setup(phba);
13969 /* Check if there are static vports to be created. */
13970 lpfc_create_static_vport(phba);
13975 lpfc_unset_hba(phba);
13976 out_free_sysfs_attr:
13977 lpfc_free_sysfs_attr(vport);
13979 lpfc_destroy_shost(phba);
13980 out_unset_driver_resource:
13981 lpfc_unset_driver_resource_phase2(phba);
13982 out_free_iocb_list:
13983 lpfc_free_iocb_list(phba);
13984 out_unset_driver_resource_s3:
13985 lpfc_sli_driver_resource_unset(phba);
13986 out_unset_pci_mem_s3:
13987 lpfc_sli_pci_mem_unset(phba);
13988 out_disable_pci_dev:
13989 lpfc_disable_pci_dev(phba);
13991 scsi_host_put(shost);
13993 lpfc_hba_free(phba);
13998 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
13999 * @pdev: pointer to PCI device
14001 * This routine is to be called to disattach a device with SLI-3 interface
14002 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
14003 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14004 * device to be removed from the PCI subsystem properly.
14007 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
14009 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14011 struct lpfc_vport **vports;
14012 struct lpfc_hba *phba = vport->phba;
14015 spin_lock_irq(&phba->hbalock);
14016 vport->load_flag |= FC_UNLOADING;
14017 spin_unlock_irq(&phba->hbalock);
14019 lpfc_free_sysfs_attr(vport);
14021 /* Release all the vports against this physical port */
14022 vports = lpfc_create_vport_work_array(phba);
14023 if (vports != NULL)
14024 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14025 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14027 fc_vport_terminate(vports[i]->fc_vport);
14029 lpfc_destroy_vport_work_array(phba, vports);
14031 /* Remove FC host with the physical port */
14032 fc_remove_host(shost);
14033 scsi_remove_host(shost);
14035 /* Clean up all nodes, mailboxes and IOs. */
14036 lpfc_cleanup(vport);
14039 * Bring down the SLI Layer. This step disable all interrupts,
14040 * clears the rings, discards all mailbox commands, and resets
14044 /* HBA interrupt will be disabled after this call */
14045 lpfc_sli_hba_down(phba);
14046 /* Stop kthread signal shall trigger work_done one more time */
14047 kthread_stop(phba->worker_thread);
14048 /* Final cleanup of txcmplq and reset the HBA */
14049 lpfc_sli_brdrestart(phba);
14051 kfree(phba->vpi_bmask);
14052 kfree(phba->vpi_ids);
14054 lpfc_stop_hba_timers(phba);
14055 spin_lock_irq(&phba->port_list_lock);
14056 list_del_init(&vport->listentry);
14057 spin_unlock_irq(&phba->port_list_lock);
14059 lpfc_debugfs_terminate(vport);
14061 /* Disable SR-IOV if enabled */
14062 if (phba->cfg_sriov_nr_virtfn)
14063 pci_disable_sriov(pdev);
14065 /* Disable interrupt */
14066 lpfc_sli_disable_intr(phba);
14068 scsi_host_put(shost);
14071 * Call scsi_free before mem_free since scsi bufs are released to their
14072 * corresponding pools here.
14074 lpfc_scsi_free(phba);
14075 lpfc_free_iocb_list(phba);
14077 lpfc_mem_free_all(phba);
14079 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
14080 phba->hbqslimp.virt, phba->hbqslimp.phys);
14082 /* Free resources associated with SLI2 interface */
14083 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
14084 phba->slim2p.virt, phba->slim2p.phys);
14086 /* unmap adapter SLIM and Control Registers */
14087 iounmap(phba->ctrl_regs_memmap_p);
14088 iounmap(phba->slim_memmap_p);
14090 lpfc_hba_free(phba);
14092 pci_release_mem_regions(pdev);
14093 pci_disable_device(pdev);
14097 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
14098 * @dev_d: pointer to device
14100 * This routine is to be called from the kernel's PCI subsystem to support
14101 * system Power Management (PM) to device with SLI-3 interface spec. When
14102 * PM invokes this method, it quiesces the device by stopping the driver's
14103 * worker thread for the device, turning off device's interrupt and DMA,
14104 * and bring the device offline. Note that as the driver implements the
14105 * minimum PM requirements to a power-aware driver's PM support for the
14106 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14107 * to the suspend() method call will be treated as SUSPEND and the driver will
14108 * fully reinitialize its device during resume() method call, the driver will
14109 * set device to PCI_D3hot state in PCI config space instead of setting it
14110 * according to the @msg provided by the PM.
14113 * 0 - driver suspended the device
14116 static int __maybe_unused
14117 lpfc_pci_suspend_one_s3(struct device *dev_d)
14119 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14120 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14122 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14123 "0473 PCI device Power Management suspend.\n");
14125 /* Bring down the device */
14126 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14127 lpfc_offline(phba);
14128 kthread_stop(phba->worker_thread);
14130 /* Disable interrupt from device */
14131 lpfc_sli_disable_intr(phba);
14137 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
14138 * @dev_d: pointer to device
14140 * This routine is to be called from the kernel's PCI subsystem to support
14141 * system Power Management (PM) to device with SLI-3 interface spec. When PM
14142 * invokes this method, it restores the device's PCI config space state and
14143 * fully reinitializes the device and brings it online. Note that as the
14144 * driver implements the minimum PM requirements to a power-aware driver's
14145 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
14146 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
14147 * driver will fully reinitialize its device during resume() method call,
14148 * the device will be set to PCI_D0 directly in PCI config space before
14149 * restoring the state.
14152 * 0 - driver suspended the device
14155 static int __maybe_unused
14156 lpfc_pci_resume_one_s3(struct device *dev_d)
14158 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14159 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14160 uint32_t intr_mode;
14163 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14164 "0452 PCI device Power Management resume.\n");
14166 /* Startup the kernel thread for this host adapter. */
14167 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14168 "lpfc_worker_%d", phba->brd_no);
14169 if (IS_ERR(phba->worker_thread)) {
14170 error = PTR_ERR(phba->worker_thread);
14171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14172 "0434 PM resume failed to start worker "
14173 "thread: error=x%x.\n", error);
14177 /* Init cpu_map array */
14178 lpfc_cpu_map_array_init(phba);
14179 /* Init hba_eq_hdl array */
14180 lpfc_hba_eq_hdl_array_init(phba);
14181 /* Configure and enable interrupt */
14182 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14183 if (intr_mode == LPFC_INTR_ERROR) {
14184 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14185 "0430 PM resume Failed to enable interrupt\n");
14188 phba->intr_mode = intr_mode;
14190 /* Restart HBA and bring it online */
14191 lpfc_sli_brdrestart(phba);
14194 /* Log the current active interrupt mode */
14195 lpfc_log_intr_mode(phba, phba->intr_mode);
14201 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
14202 * @phba: pointer to lpfc hba data structure.
14204 * This routine is called to prepare the SLI3 device for PCI slot recover. It
14205 * aborts all the outstanding SCSI I/Os to the pci device.
14208 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
14210 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14211 "2723 PCI channel I/O abort preparing for recovery\n");
14214 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14215 * and let the SCSI mid-layer to retry them to recover.
14217 lpfc_sli_abort_fcp_rings(phba);
14221 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
14222 * @phba: pointer to lpfc hba data structure.
14224 * This routine is called to prepare the SLI3 device for PCI slot reset. It
14225 * disables the device interrupt and pci device, and aborts the internal FCP
14229 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
14231 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14232 "2710 PCI channel disable preparing for reset\n");
14234 /* Block any management I/Os to the device */
14235 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
14237 /* Block all SCSI devices' I/Os on the host */
14238 lpfc_scsi_dev_block(phba);
14240 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
14241 lpfc_sli_flush_io_rings(phba);
14243 /* stop all timers */
14244 lpfc_stop_hba_timers(phba);
14246 /* Disable interrupt and pci device */
14247 lpfc_sli_disable_intr(phba);
14248 pci_disable_device(phba->pcidev);
14252 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
14253 * @phba: pointer to lpfc hba data structure.
14255 * This routine is called to prepare the SLI3 device for PCI slot permanently
14256 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14260 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
14262 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14263 "2711 PCI channel permanent disable for failure\n");
14264 /* Block all SCSI devices' I/Os on the host */
14265 lpfc_scsi_dev_block(phba);
14267 /* stop all timers */
14268 lpfc_stop_hba_timers(phba);
14270 /* Clean up all driver's outstanding SCSI I/Os */
14271 lpfc_sli_flush_io_rings(phba);
14275 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
14276 * @pdev: pointer to PCI device.
14277 * @state: the current PCI connection state.
14279 * This routine is called from the PCI subsystem for I/O error handling to
14280 * device with SLI-3 interface spec. This function is called by the PCI
14281 * subsystem after a PCI bus error affecting this device has been detected.
14282 * When this function is invoked, it will need to stop all the I/Os and
14283 * interrupt(s) to the device. Once that is done, it will return
14284 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
14288 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
14289 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14290 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14292 static pci_ers_result_t
14293 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
14295 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14296 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14299 case pci_channel_io_normal:
14300 /* Non-fatal error, prepare for recovery */
14301 lpfc_sli_prep_dev_for_recover(phba);
14302 return PCI_ERS_RESULT_CAN_RECOVER;
14303 case pci_channel_io_frozen:
14304 /* Fatal error, prepare for slot reset */
14305 lpfc_sli_prep_dev_for_reset(phba);
14306 return PCI_ERS_RESULT_NEED_RESET;
14307 case pci_channel_io_perm_failure:
14308 /* Permanent failure, prepare for device down */
14309 lpfc_sli_prep_dev_for_perm_failure(phba);
14310 return PCI_ERS_RESULT_DISCONNECT;
14312 /* Unknown state, prepare and request slot reset */
14313 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14314 "0472 Unknown PCI error state: x%x\n", state);
14315 lpfc_sli_prep_dev_for_reset(phba);
14316 return PCI_ERS_RESULT_NEED_RESET;
14321 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
14322 * @pdev: pointer to PCI device.
14324 * This routine is called from the PCI subsystem for error handling to
14325 * device with SLI-3 interface spec. This is called after PCI bus has been
14326 * reset to restart the PCI card from scratch, as if from a cold-boot.
14327 * During the PCI subsystem error recovery, after driver returns
14328 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14329 * recovery and then call this routine before calling the .resume method
14330 * to recover the device. This function will initialize the HBA device,
14331 * enable the interrupt, but it will just put the HBA to offline state
14332 * without passing any I/O traffic.
14335 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14336 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14338 static pci_ers_result_t
14339 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
14341 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14342 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14343 struct lpfc_sli *psli = &phba->sli;
14344 uint32_t intr_mode;
14346 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
14347 if (pci_enable_device_mem(pdev)) {
14348 printk(KERN_ERR "lpfc: Cannot re-enable "
14349 "PCI device after reset.\n");
14350 return PCI_ERS_RESULT_DISCONNECT;
14353 pci_restore_state(pdev);
14356 * As the new kernel behavior of pci_restore_state() API call clears
14357 * device saved_state flag, need to save the restored state again.
14359 pci_save_state(pdev);
14361 if (pdev->is_busmaster)
14362 pci_set_master(pdev);
14364 spin_lock_irq(&phba->hbalock);
14365 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
14366 spin_unlock_irq(&phba->hbalock);
14368 /* Configure and enable interrupt */
14369 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14370 if (intr_mode == LPFC_INTR_ERROR) {
14371 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14372 "0427 Cannot re-enable interrupt after "
14374 return PCI_ERS_RESULT_DISCONNECT;
14376 phba->intr_mode = intr_mode;
14378 /* Take device offline, it will perform cleanup */
14379 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14380 lpfc_offline(phba);
14381 lpfc_sli_brdrestart(phba);
14383 /* Log the current active interrupt mode */
14384 lpfc_log_intr_mode(phba, phba->intr_mode);
14386 return PCI_ERS_RESULT_RECOVERED;
14390 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
14391 * @pdev: pointer to PCI device
14393 * This routine is called from the PCI subsystem for error handling to device
14394 * with SLI-3 interface spec. It is called when kernel error recovery tells
14395 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14396 * error recovery. After this call, traffic can start to flow from this device
14400 lpfc_io_resume_s3(struct pci_dev *pdev)
14402 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14403 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14405 /* Bring device online, it will be no-op for non-fatal error resume */
14410 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
14411 * @phba: pointer to lpfc hba data structure.
14413 * returns the number of ELS/CT IOCBs to reserve
14416 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
14418 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
14420 if (phba->sli_rev == LPFC_SLI_REV4) {
14421 if (max_xri <= 100)
14423 else if (max_xri <= 256)
14425 else if (max_xri <= 512)
14427 else if (max_xri <= 1024)
14429 else if (max_xri <= 1536)
14431 else if (max_xri <= 2048)
14440 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
14441 * @phba: pointer to lpfc hba data structure.
14443 * returns the number of ELS/CT + NVMET IOCBs to reserve
14446 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
14448 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
14450 if (phba->nvmet_support)
14451 max_xri += LPFC_NVMET_BUF_POST;
14457 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
14458 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
14459 const struct firmware *fw)
14464 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
14465 /* Three cases: (1) FW was not supported on the detected adapter.
14466 * (2) FW update has been locked out administratively.
14467 * (3) Some other error during FW update.
14468 * In each case, an unmaskable message is written to the console
14469 * for admin diagnosis.
14471 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
14472 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
14473 magic_number != MAGIC_NUMBER_G6) ||
14474 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
14475 magic_number != MAGIC_NUMBER_G7) ||
14476 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
14477 magic_number != MAGIC_NUMBER_G7P)) {
14478 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14479 "3030 This firmware version is not supported on"
14480 " this HBA model. Device:%x Magic:%x Type:%x "
14481 "ID:%x Size %d %zd\n",
14482 phba->pcidev->device, magic_number, ftype, fid,
14485 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
14486 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14487 "3021 Firmware downloads have been prohibited "
14488 "by a system configuration setting on "
14489 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14491 phba->pcidev->device, magic_number, ftype, fid,
14495 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14496 "3022 FW Download failed. Add Status x%x "
14497 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14499 offset, phba->pcidev->device, magic_number,
14500 ftype, fid, fsize, fw->size);
14507 * lpfc_write_firmware - attempt to write a firmware image to the port
14508 * @fw: pointer to firmware image returned from request_firmware.
14509 * @context: pointer to firmware image returned from request_firmware.
14513 lpfc_write_firmware(const struct firmware *fw, void *context)
14515 struct lpfc_hba *phba = (struct lpfc_hba *)context;
14516 char fwrev[FW_REV_STR_SIZE];
14517 struct lpfc_grp_hdr *image;
14518 struct list_head dma_buffer_list;
14520 struct lpfc_dmabuf *dmabuf, *next;
14521 uint32_t offset = 0, temp_offset = 0;
14522 uint32_t magic_number, ftype, fid, fsize;
14524 /* It can be null in no-wait mode, sanity check */
14529 image = (struct lpfc_grp_hdr *)fw->data;
14531 magic_number = be32_to_cpu(image->magic_number);
14532 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
14533 fid = bf_get_be32(lpfc_grp_hdr_id, image);
14534 fsize = be32_to_cpu(image->size);
14536 INIT_LIST_HEAD(&dma_buffer_list);
14537 lpfc_decode_firmware_rev(phba, fwrev, 1);
14538 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
14539 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14540 "3023 Updating Firmware, Current Version:%s "
14541 "New Version:%s\n",
14542 fwrev, image->revision);
14543 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
14544 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
14550 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14554 if (!dmabuf->virt) {
14559 list_add_tail(&dmabuf->list, &dma_buffer_list);
14561 while (offset < fw->size) {
14562 temp_offset = offset;
14563 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
14564 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
14565 memcpy(dmabuf->virt,
14566 fw->data + temp_offset,
14567 fw->size - temp_offset);
14568 temp_offset = fw->size;
14571 memcpy(dmabuf->virt, fw->data + temp_offset,
14573 temp_offset += SLI4_PAGE_SIZE;
14575 rc = lpfc_wr_object(phba, &dma_buffer_list,
14576 (fw->size - offset), &offset);
14578 rc = lpfc_log_write_firmware_error(phba, offset,
14589 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14590 "3029 Skipped Firmware update, Current "
14591 "Version:%s New Version:%s\n",
14592 fwrev, image->revision);
14595 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
14596 list_del(&dmabuf->list);
14597 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
14598 dmabuf->virt, dmabuf->phys);
14601 release_firmware(fw);
14604 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14605 "3062 Firmware update error, status %d.\n", rc);
14607 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14608 "3024 Firmware update success: size %d.\n", rc);
14612 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
14613 * @phba: pointer to lpfc hba data structure.
14614 * @fw_upgrade: which firmware to update.
14616 * This routine is called to perform Linux generic firmware upgrade on device
14617 * that supports such feature.
14620 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
14622 uint8_t file_name[ELX_MODEL_NAME_SIZE];
14624 const struct firmware *fw;
14626 /* Only supported on SLI4 interface type 2 for now */
14627 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
14628 LPFC_SLI_INTF_IF_TYPE_2)
14631 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
14633 if (fw_upgrade == INT_FW_UPGRADE) {
14634 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
14635 file_name, &phba->pcidev->dev,
14636 GFP_KERNEL, (void *)phba,
14637 lpfc_write_firmware);
14638 } else if (fw_upgrade == RUN_FW_UPGRADE) {
14639 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
14641 lpfc_write_firmware(fw, (void *)phba);
14650 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
14651 * @pdev: pointer to PCI device
14652 * @pid: pointer to PCI device identifier
14654 * This routine is called from the kernel's PCI subsystem to device with
14655 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14656 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14657 * information of the device and driver to see if the driver state that it
14658 * can support this kind of device. If the match is successful, the driver
14659 * core invokes this routine. If this routine determines it can claim the HBA,
14660 * it does all the initialization that it needs to do to handle the HBA
14664 * 0 - driver can claim the device
14665 * negative value - driver can not claim the device
14668 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
14670 struct lpfc_hba *phba;
14671 struct lpfc_vport *vport = NULL;
14672 struct Scsi_Host *shost = NULL;
14674 uint32_t cfg_mode, intr_mode;
14676 /* Allocate memory for HBA structure */
14677 phba = lpfc_hba_alloc(pdev);
14681 INIT_LIST_HEAD(&phba->poll_list);
14683 /* Perform generic PCI device enabling operation */
14684 error = lpfc_enable_pci_dev(phba);
14686 goto out_free_phba;
14688 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
14689 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
14691 goto out_disable_pci_dev;
14693 /* Set up SLI-4 specific device PCI memory space */
14694 error = lpfc_sli4_pci_mem_setup(phba);
14696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14697 "1410 Failed to set up pci memory space.\n");
14698 goto out_disable_pci_dev;
14701 /* Set up SLI-4 Specific device driver resources */
14702 error = lpfc_sli4_driver_resource_setup(phba);
14704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14705 "1412 Failed to set up driver resource.\n");
14706 goto out_unset_pci_mem_s4;
14709 INIT_LIST_HEAD(&phba->active_rrq_list);
14710 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
14712 /* Set up common device driver resources */
14713 error = lpfc_setup_driver_resource_phase2(phba);
14715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14716 "1414 Failed to set up driver resource.\n");
14717 goto out_unset_driver_resource_s4;
14720 /* Get the default values for Model Name and Description */
14721 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14723 /* Now, trying to enable interrupt and bring up the device */
14724 cfg_mode = phba->cfg_use_msi;
14726 /* Put device to a known state before enabling interrupt */
14727 phba->pport = NULL;
14728 lpfc_stop_port(phba);
14730 /* Init cpu_map array */
14731 lpfc_cpu_map_array_init(phba);
14733 /* Init hba_eq_hdl array */
14734 lpfc_hba_eq_hdl_array_init(phba);
14736 /* Configure and enable interrupt */
14737 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14738 if (intr_mode == LPFC_INTR_ERROR) {
14739 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14740 "0426 Failed to enable interrupt.\n");
14742 goto out_unset_driver_resource;
14744 /* Default to single EQ for non-MSI-X */
14745 if (phba->intr_type != MSIX) {
14746 phba->cfg_irq_chann = 1;
14747 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14748 if (phba->nvmet_support)
14749 phba->cfg_nvmet_mrq = 1;
14752 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
14754 /* Create SCSI host to the physical port */
14755 error = lpfc_create_shost(phba);
14757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14758 "1415 Failed to create scsi host.\n");
14759 goto out_disable_intr;
14761 vport = phba->pport;
14762 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14764 /* Configure sysfs attributes */
14765 error = lpfc_alloc_sysfs_attr(vport);
14767 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14768 "1416 Failed to allocate sysfs attr\n");
14769 goto out_destroy_shost;
14772 /* Set up SLI-4 HBA */
14773 if (lpfc_sli4_hba_setup(phba)) {
14774 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14775 "1421 Failed to set up hba\n");
14777 goto out_free_sysfs_attr;
14780 /* Log the current active interrupt mode */
14781 phba->intr_mode = intr_mode;
14782 lpfc_log_intr_mode(phba, intr_mode);
14784 /* Perform post initialization setup */
14785 lpfc_post_init_setup(phba);
14787 /* NVME support in FW earlier in the driver load corrects the
14788 * FC4 type making a check for nvme_support unnecessary.
14790 if (phba->nvmet_support == 0) {
14791 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14792 /* Create NVME binding with nvme_fc_transport. This
14793 * ensures the vport is initialized. If the localport
14794 * create fails, it should not unload the driver to
14795 * support field issues.
14797 error = lpfc_nvme_create_localport(vport);
14799 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14800 "6004 NVME registration "
14801 "failed, error x%x\n",
14807 /* check for firmware upgrade or downgrade */
14808 if (phba->cfg_request_firmware_upgrade)
14809 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
14811 /* Check if there are static vports to be created. */
14812 lpfc_create_static_vport(phba);
14814 /* Enable RAS FW log support */
14815 lpfc_sli4_ras_setup(phba);
14817 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
14818 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
14822 out_free_sysfs_attr:
14823 lpfc_free_sysfs_attr(vport);
14825 lpfc_destroy_shost(phba);
14827 lpfc_sli4_disable_intr(phba);
14828 out_unset_driver_resource:
14829 lpfc_unset_driver_resource_phase2(phba);
14830 out_unset_driver_resource_s4:
14831 lpfc_sli4_driver_resource_unset(phba);
14832 out_unset_pci_mem_s4:
14833 lpfc_sli4_pci_mem_unset(phba);
14834 out_disable_pci_dev:
14835 lpfc_disable_pci_dev(phba);
14837 scsi_host_put(shost);
14839 lpfc_hba_free(phba);
14844 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
14845 * @pdev: pointer to PCI device
14847 * This routine is called from the kernel's PCI subsystem to device with
14848 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14849 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14850 * device to be removed from the PCI subsystem properly.
14853 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
14855 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14856 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14857 struct lpfc_vport **vports;
14858 struct lpfc_hba *phba = vport->phba;
14861 /* Mark the device unloading flag */
14862 spin_lock_irq(&phba->hbalock);
14863 vport->load_flag |= FC_UNLOADING;
14864 spin_unlock_irq(&phba->hbalock);
14866 lpfc_unreg_congestion_buf(phba);
14868 lpfc_free_sysfs_attr(vport);
14870 /* Release all the vports against this physical port */
14871 vports = lpfc_create_vport_work_array(phba);
14872 if (vports != NULL)
14873 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14874 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14876 fc_vport_terminate(vports[i]->fc_vport);
14878 lpfc_destroy_vport_work_array(phba, vports);
14880 /* Remove FC host with the physical port */
14881 fc_remove_host(shost);
14882 scsi_remove_host(shost);
14884 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
14885 * localports are destroyed after to cleanup all transport memory.
14887 lpfc_cleanup(vport);
14888 lpfc_nvmet_destroy_targetport(phba);
14889 lpfc_nvme_destroy_localport(vport);
14891 /* De-allocate multi-XRI pools */
14892 if (phba->cfg_xri_rebalancing)
14893 lpfc_destroy_multixri_pools(phba);
14896 * Bring down the SLI Layer. This step disables all interrupts,
14897 * clears the rings, discards all mailbox commands, and resets
14898 * the HBA FCoE function.
14900 lpfc_debugfs_terminate(vport);
14902 lpfc_stop_hba_timers(phba);
14903 spin_lock_irq(&phba->port_list_lock);
14904 list_del_init(&vport->listentry);
14905 spin_unlock_irq(&phba->port_list_lock);
14907 /* Perform scsi free before driver resource_unset since scsi
14908 * buffers are released to their corresponding pools here.
14910 lpfc_io_free(phba);
14911 lpfc_free_iocb_list(phba);
14912 lpfc_sli4_hba_unset(phba);
14914 lpfc_unset_driver_resource_phase2(phba);
14915 lpfc_sli4_driver_resource_unset(phba);
14917 /* Unmap adapter Control and Doorbell registers */
14918 lpfc_sli4_pci_mem_unset(phba);
14920 /* Release PCI resources and disable device's PCI function */
14921 scsi_host_put(shost);
14922 lpfc_disable_pci_dev(phba);
14924 /* Finally, free the driver's device data structure */
14925 lpfc_hba_free(phba);
14931 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
14932 * @dev_d: pointer to device
14934 * This routine is called from the kernel's PCI subsystem to support system
14935 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
14936 * this method, it quiesces the device by stopping the driver's worker
14937 * thread for the device, turning off device's interrupt and DMA, and bring
14938 * the device offline. Note that as the driver implements the minimum PM
14939 * requirements to a power-aware driver's PM support for suspend/resume -- all
14940 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
14941 * method call will be treated as SUSPEND and the driver will fully
14942 * reinitialize its device during resume() method call, the driver will set
14943 * device to PCI_D3hot state in PCI config space instead of setting it
14944 * according to the @msg provided by the PM.
14947 * 0 - driver suspended the device
14950 static int __maybe_unused
14951 lpfc_pci_suspend_one_s4(struct device *dev_d)
14953 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14954 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14956 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14957 "2843 PCI device Power Management suspend.\n");
14959 /* Bring down the device */
14960 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14961 lpfc_offline(phba);
14962 kthread_stop(phba->worker_thread);
14964 /* Disable interrupt from device */
14965 lpfc_sli4_disable_intr(phba);
14966 lpfc_sli4_queue_destroy(phba);
14972 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
14973 * @dev_d: pointer to device
14975 * This routine is called from the kernel's PCI subsystem to support system
14976 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
14977 * this method, it restores the device's PCI config space state and fully
14978 * reinitializes the device and brings it online. Note that as the driver
14979 * implements the minimum PM requirements to a power-aware driver's PM for
14980 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14981 * to the suspend() method call will be treated as SUSPEND and the driver
14982 * will fully reinitialize its device during resume() method call, the device
14983 * will be set to PCI_D0 directly in PCI config space before restoring the
14987 * 0 - driver suspended the device
14990 static int __maybe_unused
14991 lpfc_pci_resume_one_s4(struct device *dev_d)
14993 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14994 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14995 uint32_t intr_mode;
14998 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14999 "0292 PCI device Power Management resume.\n");
15001 /* Startup the kernel thread for this host adapter. */
15002 phba->worker_thread = kthread_run(lpfc_do_work, phba,
15003 "lpfc_worker_%d", phba->brd_no);
15004 if (IS_ERR(phba->worker_thread)) {
15005 error = PTR_ERR(phba->worker_thread);
15006 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15007 "0293 PM resume failed to start worker "
15008 "thread: error=x%x.\n", error);
15012 /* Configure and enable interrupt */
15013 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15014 if (intr_mode == LPFC_INTR_ERROR) {
15015 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15016 "0294 PM resume Failed to enable interrupt\n");
15019 phba->intr_mode = intr_mode;
15021 /* Restart HBA and bring it online */
15022 lpfc_sli_brdrestart(phba);
15025 /* Log the current active interrupt mode */
15026 lpfc_log_intr_mode(phba, phba->intr_mode);
15032 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
15033 * @phba: pointer to lpfc hba data structure.
15035 * This routine is called to prepare the SLI4 device for PCI slot recover. It
15036 * aborts all the outstanding SCSI I/Os to the pci device.
15039 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
15041 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15042 "2828 PCI channel I/O abort preparing for recovery\n");
15044 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
15045 * and let the SCSI mid-layer to retry them to recover.
15047 lpfc_sli_abort_fcp_rings(phba);
15051 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
15052 * @phba: pointer to lpfc hba data structure.
15054 * This routine is called to prepare the SLI4 device for PCI slot reset. It
15055 * disables the device interrupt and pci device, and aborts the internal FCP
15059 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
15061 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15062 "2826 PCI channel disable preparing for reset\n");
15064 /* Block any management I/Os to the device */
15065 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
15067 /* Block all SCSI devices' I/Os on the host */
15068 lpfc_scsi_dev_block(phba);
15070 /* Flush all driver's outstanding I/Os as we are to reset */
15071 lpfc_sli_flush_io_rings(phba);
15073 /* stop all timers */
15074 lpfc_stop_hba_timers(phba);
15076 /* Disable interrupt and pci device */
15077 lpfc_sli4_disable_intr(phba);
15078 lpfc_sli4_queue_destroy(phba);
15079 pci_disable_device(phba->pcidev);
15083 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
15084 * @phba: pointer to lpfc hba data structure.
15086 * This routine is called to prepare the SLI4 device for PCI slot permanently
15087 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
15091 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
15093 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15094 "2827 PCI channel permanent disable for failure\n");
15096 /* Block all SCSI devices' I/Os on the host */
15097 lpfc_scsi_dev_block(phba);
15099 /* stop all timers */
15100 lpfc_stop_hba_timers(phba);
15102 /* Clean up all driver's outstanding I/Os */
15103 lpfc_sli_flush_io_rings(phba);
15107 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
15108 * @pdev: pointer to PCI device.
15109 * @state: the current PCI connection state.
15111 * This routine is called from the PCI subsystem for error handling to device
15112 * with SLI-4 interface spec. This function is called by the PCI subsystem
15113 * after a PCI bus error affecting this device has been detected. When this
15114 * function is invoked, it will need to stop all the I/Os and interrupt(s)
15115 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
15116 * for the PCI subsystem to perform proper recovery as desired.
15119 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15120 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15122 static pci_ers_result_t
15123 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
15125 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15126 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15129 case pci_channel_io_normal:
15130 /* Non-fatal error, prepare for recovery */
15131 lpfc_sli4_prep_dev_for_recover(phba);
15132 return PCI_ERS_RESULT_CAN_RECOVER;
15133 case pci_channel_io_frozen:
15134 phba->hba_flag |= HBA_PCI_ERR;
15135 /* Fatal error, prepare for slot reset */
15136 lpfc_sli4_prep_dev_for_reset(phba);
15137 return PCI_ERS_RESULT_NEED_RESET;
15138 case pci_channel_io_perm_failure:
15139 phba->hba_flag |= HBA_PCI_ERR;
15140 /* Permanent failure, prepare for device down */
15141 lpfc_sli4_prep_dev_for_perm_failure(phba);
15142 return PCI_ERS_RESULT_DISCONNECT;
15144 phba->hba_flag |= HBA_PCI_ERR;
15145 /* Unknown state, prepare and request slot reset */
15146 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15147 "2825 Unknown PCI error state: x%x\n", state);
15148 lpfc_sli4_prep_dev_for_reset(phba);
15149 return PCI_ERS_RESULT_NEED_RESET;
15154 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
15155 * @pdev: pointer to PCI device.
15157 * This routine is called from the PCI subsystem for error handling to device
15158 * with SLI-4 interface spec. It is called after PCI bus has been reset to
15159 * restart the PCI card from scratch, as if from a cold-boot. During the
15160 * PCI subsystem error recovery, after the driver returns
15161 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
15162 * recovery and then call this routine before calling the .resume method to
15163 * recover the device. This function will initialize the HBA device, enable
15164 * the interrupt, but it will just put the HBA to offline state without
15165 * passing any I/O traffic.
15168 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15169 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15171 static pci_ers_result_t
15172 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
15174 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15175 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15176 struct lpfc_sli *psli = &phba->sli;
15177 uint32_t intr_mode;
15179 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
15180 if (pci_enable_device_mem(pdev)) {
15181 printk(KERN_ERR "lpfc: Cannot re-enable "
15182 "PCI device after reset.\n");
15183 return PCI_ERS_RESULT_DISCONNECT;
15186 pci_restore_state(pdev);
15188 phba->hba_flag &= ~HBA_PCI_ERR;
15190 * As the new kernel behavior of pci_restore_state() API call clears
15191 * device saved_state flag, need to save the restored state again.
15193 pci_save_state(pdev);
15195 if (pdev->is_busmaster)
15196 pci_set_master(pdev);
15198 spin_lock_irq(&phba->hbalock);
15199 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
15200 spin_unlock_irq(&phba->hbalock);
15202 /* Configure and enable interrupt */
15203 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15204 if (intr_mode == LPFC_INTR_ERROR) {
15205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15206 "2824 Cannot re-enable interrupt after "
15208 return PCI_ERS_RESULT_DISCONNECT;
15210 phba->intr_mode = intr_mode;
15211 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
15213 /* Log the current active interrupt mode */
15214 lpfc_log_intr_mode(phba, phba->intr_mode);
15216 return PCI_ERS_RESULT_RECOVERED;
15220 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
15221 * @pdev: pointer to PCI device
15223 * This routine is called from the PCI subsystem for error handling to device
15224 * with SLI-4 interface spec. It is called when kernel error recovery tells
15225 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
15226 * error recovery. After this call, traffic can start to flow from this device
15230 lpfc_io_resume_s4(struct pci_dev *pdev)
15232 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15233 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15236 * In case of slot reset, as function reset is performed through
15237 * mailbox command which needs DMA to be enabled, this operation
15238 * has to be moved to the io resume phase. Taking device offline
15239 * will perform the necessary cleanup.
15241 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
15242 /* Perform device reset */
15243 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
15244 lpfc_offline(phba);
15245 lpfc_sli_brdrestart(phba);
15246 /* Bring the device back online */
15252 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
15253 * @pdev: pointer to PCI device
15254 * @pid: pointer to PCI device identifier
15256 * This routine is to be registered to the kernel's PCI subsystem. When an
15257 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
15258 * at PCI device-specific information of the device and driver to see if the
15259 * driver state that it can support this kind of device. If the match is
15260 * successful, the driver core invokes this routine. This routine dispatches
15261 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
15262 * do all the initialization that it needs to do to handle the HBA device
15266 * 0 - driver can claim the device
15267 * negative value - driver can not claim the device
15270 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
15273 struct lpfc_sli_intf intf;
15275 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
15278 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
15279 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
15280 rc = lpfc_pci_probe_one_s4(pdev, pid);
15282 rc = lpfc_pci_probe_one_s3(pdev, pid);
15288 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
15289 * @pdev: pointer to PCI device
15291 * This routine is to be registered to the kernel's PCI subsystem. When an
15292 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
15293 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
15294 * remove routine, which will perform all the necessary cleanup for the
15295 * device to be removed from the PCI subsystem properly.
15298 lpfc_pci_remove_one(struct pci_dev *pdev)
15300 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15301 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15303 switch (phba->pci_dev_grp) {
15304 case LPFC_PCI_DEV_LP:
15305 lpfc_pci_remove_one_s3(pdev);
15307 case LPFC_PCI_DEV_OC:
15308 lpfc_pci_remove_one_s4(pdev);
15311 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15312 "1424 Invalid PCI device group: 0x%x\n",
15313 phba->pci_dev_grp);
15320 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
15321 * @dev: pointer to device
15323 * This routine is to be registered to the kernel's PCI subsystem to support
15324 * system Power Management (PM). When PM invokes this method, it dispatches
15325 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
15326 * suspend the device.
15329 * 0 - driver suspended the device
15332 static int __maybe_unused
15333 lpfc_pci_suspend_one(struct device *dev)
15335 struct Scsi_Host *shost = dev_get_drvdata(dev);
15336 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15339 switch (phba->pci_dev_grp) {
15340 case LPFC_PCI_DEV_LP:
15341 rc = lpfc_pci_suspend_one_s3(dev);
15343 case LPFC_PCI_DEV_OC:
15344 rc = lpfc_pci_suspend_one_s4(dev);
15347 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15348 "1425 Invalid PCI device group: 0x%x\n",
15349 phba->pci_dev_grp);
15356 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
15357 * @dev: pointer to device
15359 * This routine is to be registered to the kernel's PCI subsystem to support
15360 * system Power Management (PM). When PM invokes this method, it dispatches
15361 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
15362 * resume the device.
15365 * 0 - driver suspended the device
15368 static int __maybe_unused
15369 lpfc_pci_resume_one(struct device *dev)
15371 struct Scsi_Host *shost = dev_get_drvdata(dev);
15372 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15375 switch (phba->pci_dev_grp) {
15376 case LPFC_PCI_DEV_LP:
15377 rc = lpfc_pci_resume_one_s3(dev);
15379 case LPFC_PCI_DEV_OC:
15380 rc = lpfc_pci_resume_one_s4(dev);
15383 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15384 "1426 Invalid PCI device group: 0x%x\n",
15385 phba->pci_dev_grp);
15392 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
15393 * @pdev: pointer to PCI device.
15394 * @state: the current PCI connection state.
15396 * This routine is registered to the PCI subsystem for error handling. This
15397 * function is called by the PCI subsystem after a PCI bus error affecting
15398 * this device has been detected. When this routine is invoked, it dispatches
15399 * the action to the proper SLI-3 or SLI-4 device error detected handling
15400 * routine, which will perform the proper error detected operation.
15403 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15404 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15406 static pci_ers_result_t
15407 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
15409 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15410 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15411 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15413 if (phba->link_state == LPFC_HBA_ERROR &&
15414 phba->hba_flag & HBA_IOQ_FLUSH)
15415 return PCI_ERS_RESULT_NEED_RESET;
15417 switch (phba->pci_dev_grp) {
15418 case LPFC_PCI_DEV_LP:
15419 rc = lpfc_io_error_detected_s3(pdev, state);
15421 case LPFC_PCI_DEV_OC:
15422 rc = lpfc_io_error_detected_s4(pdev, state);
15425 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15426 "1427 Invalid PCI device group: 0x%x\n",
15427 phba->pci_dev_grp);
15434 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
15435 * @pdev: pointer to PCI device.
15437 * This routine is registered to the PCI subsystem for error handling. This
15438 * function is called after PCI bus has been reset to restart the PCI card
15439 * from scratch, as if from a cold-boot. When this routine is invoked, it
15440 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
15441 * routine, which will perform the proper device reset.
15444 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15445 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15447 static pci_ers_result_t
15448 lpfc_io_slot_reset(struct pci_dev *pdev)
15450 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15451 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15452 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15454 switch (phba->pci_dev_grp) {
15455 case LPFC_PCI_DEV_LP:
15456 rc = lpfc_io_slot_reset_s3(pdev);
15458 case LPFC_PCI_DEV_OC:
15459 rc = lpfc_io_slot_reset_s4(pdev);
15462 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15463 "1428 Invalid PCI device group: 0x%x\n",
15464 phba->pci_dev_grp);
15471 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
15472 * @pdev: pointer to PCI device
15474 * This routine is registered to the PCI subsystem for error handling. It
15475 * is called when kernel error recovery tells the lpfc driver that it is
15476 * OK to resume normal PCI operation after PCI bus error recovery. When
15477 * this routine is invoked, it dispatches the action to the proper SLI-3
15478 * or SLI-4 device io_resume routine, which will resume the device operation.
15481 lpfc_io_resume(struct pci_dev *pdev)
15483 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15484 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15486 switch (phba->pci_dev_grp) {
15487 case LPFC_PCI_DEV_LP:
15488 lpfc_io_resume_s3(pdev);
15490 case LPFC_PCI_DEV_OC:
15491 lpfc_io_resume_s4(pdev);
15494 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15495 "1429 Invalid PCI device group: 0x%x\n",
15496 phba->pci_dev_grp);
15503 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
15504 * @phba: pointer to lpfc hba data structure.
15506 * This routine checks to see if OAS is supported for this adapter. If
15507 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
15508 * the enable oas flag is cleared and the pool created for OAS device data
15513 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
15516 if (!phba->cfg_EnableXLane)
15519 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
15523 mempool_destroy(phba->device_data_mem_pool);
15524 phba->device_data_mem_pool = NULL;
15531 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
15532 * @phba: pointer to lpfc hba data structure.
15534 * This routine checks to see if RAS is supported by the adapter. Check the
15535 * function through which RAS support enablement is to be done.
15538 lpfc_sli4_ras_init(struct lpfc_hba *phba)
15540 /* if ASIC_GEN_NUM >= 0xC) */
15541 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
15542 LPFC_SLI_INTF_IF_TYPE_6) ||
15543 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
15544 LPFC_SLI_INTF_FAMILY_G6)) {
15545 phba->ras_fwlog.ras_hwsupport = true;
15546 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
15547 phba->cfg_ras_fwlog_buffsize)
15548 phba->ras_fwlog.ras_enabled = true;
15550 phba->ras_fwlog.ras_enabled = false;
15552 phba->ras_fwlog.ras_hwsupport = false;
15557 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
15559 static const struct pci_error_handlers lpfc_err_handler = {
15560 .error_detected = lpfc_io_error_detected,
15561 .slot_reset = lpfc_io_slot_reset,
15562 .resume = lpfc_io_resume,
15565 static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
15566 lpfc_pci_suspend_one,
15567 lpfc_pci_resume_one);
15569 static struct pci_driver lpfc_driver = {
15570 .name = LPFC_DRIVER_NAME,
15571 .id_table = lpfc_id_table,
15572 .probe = lpfc_pci_probe_one,
15573 .remove = lpfc_pci_remove_one,
15574 .shutdown = lpfc_pci_remove_one,
15575 .driver.pm = &lpfc_pci_pm_ops_one,
15576 .err_handler = &lpfc_err_handler,
15579 static const struct file_operations lpfc_mgmt_fop = {
15580 .owner = THIS_MODULE,
15583 static struct miscdevice lpfc_mgmt_dev = {
15584 .minor = MISC_DYNAMIC_MINOR,
15585 .name = "lpfcmgmt",
15586 .fops = &lpfc_mgmt_fop,
15590 * lpfc_init - lpfc module initialization routine
15592 * This routine is to be invoked when the lpfc module is loaded into the
15593 * kernel. The special kernel macro module_init() is used to indicate the
15594 * role of this routine to the kernel as lpfc module entry point.
15598 * -ENOMEM - FC attach transport failed
15599 * all others - failed
15606 pr_info(LPFC_MODULE_DESC "\n");
15607 pr_info(LPFC_COPYRIGHT "\n");
15609 error = misc_register(&lpfc_mgmt_dev);
15611 printk(KERN_ERR "Could not register lpfcmgmt device, "
15612 "misc_register returned with status %d", error);
15615 lpfc_transport_functions.vport_create = lpfc_vport_create;
15616 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
15617 lpfc_transport_template =
15618 fc_attach_transport(&lpfc_transport_functions);
15619 if (lpfc_transport_template == NULL)
15621 lpfc_vport_transport_template =
15622 fc_attach_transport(&lpfc_vport_transport_functions);
15623 if (lpfc_vport_transport_template == NULL) {
15624 fc_release_transport(lpfc_transport_template);
15627 lpfc_wqe_cmd_template();
15628 lpfc_nvmet_cmd_template();
15630 /* Initialize in case vector mapping is needed */
15631 lpfc_present_cpu = num_present_cpus();
15633 lpfc_pldv_detect = false;
15635 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
15636 "lpfc/sli4:online",
15637 lpfc_cpu_online, lpfc_cpu_offline);
15639 goto cpuhp_failure;
15640 lpfc_cpuhp_state = error;
15642 error = pci_register_driver(&lpfc_driver);
15649 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15651 fc_release_transport(lpfc_transport_template);
15652 fc_release_transport(lpfc_vport_transport_template);
15654 misc_deregister(&lpfc_mgmt_dev);
15659 void lpfc_dmp_dbg(struct lpfc_hba *phba)
15661 unsigned int start_idx;
15662 unsigned int dbg_cnt;
15663 unsigned int temp_idx;
15666 unsigned long rem_nsec, iflags;
15667 bool log_verbose = false;
15668 struct lpfc_vport *port_iterator;
15670 /* Don't dump messages if we explicitly set log_verbose for the
15671 * physical port or any vport.
15673 if (phba->cfg_log_verbose)
15676 spin_lock_irqsave(&phba->port_list_lock, iflags);
15677 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
15678 if (port_iterator->load_flag & FC_UNLOADING)
15680 if (scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
15681 if (port_iterator->cfg_log_verbose)
15682 log_verbose = true;
15684 scsi_host_put(lpfc_shost_from_vport(port_iterator));
15687 spin_unlock_irqrestore(&phba->port_list_lock,
15693 spin_unlock_irqrestore(&phba->port_list_lock, iflags);
15695 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
15698 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
15699 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
15702 temp_idx = start_idx;
15703 if (dbg_cnt >= DBG_LOG_SZ) {
15704 dbg_cnt = DBG_LOG_SZ;
15707 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
15708 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
15710 if (start_idx < dbg_cnt)
15711 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
15713 start_idx -= dbg_cnt;
15716 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
15717 start_idx, temp_idx, dbg_cnt);
15719 for (i = 0; i < dbg_cnt; i++) {
15720 if ((start_idx + i) < DBG_LOG_SZ)
15721 temp_idx = (start_idx + i) % DBG_LOG_SZ;
15724 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
15725 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15727 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15729 phba->dbg_log[temp_idx].log);
15732 atomic_set(&phba->dbg_log_cnt, 0);
15733 atomic_set(&phba->dbg_log_dmping, 0);
15737 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15741 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15742 struct va_format vaf;
15745 va_start(args, fmt);
15746 if (unlikely(dbg_dmping)) {
15749 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15753 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15756 atomic_inc(&phba->dbg_log_cnt);
15758 vscnprintf(phba->dbg_log[idx].log,
15759 sizeof(phba->dbg_log[idx].log), fmt, args);
15762 phba->dbg_log[idx].t_ns = local_clock();
15766 * lpfc_exit - lpfc module removal routine
15768 * This routine is invoked when the lpfc module is removed from the kernel.
15769 * The special kernel macro module_exit() is used to indicate the role of
15770 * this routine to the kernel as lpfc module exit point.
15775 misc_deregister(&lpfc_mgmt_dev);
15776 pci_unregister_driver(&lpfc_driver);
15777 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15778 fc_release_transport(lpfc_transport_template);
15779 fc_release_transport(lpfc_vport_transport_template);
15780 idr_destroy(&lpfc_hba_index);
15783 module_init(lpfc_init);
15784 module_exit(lpfc_exit);
15785 MODULE_LICENSE("GPL");
15786 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
15787 MODULE_AUTHOR("Broadcom");
15788 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);