1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 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>
53 #include <linux/nvme-fc-driver.h>
58 #include "lpfc_sli4.h"
60 #include "lpfc_disc.h"
62 #include "lpfc_scsi.h"
63 #include "lpfc_nvme.h"
64 #include "lpfc_nvmet.h"
65 #include "lpfc_logmsg.h"
66 #include "lpfc_crtn.h"
67 #include "lpfc_vport.h"
68 #include "lpfc_version.h"
71 static enum cpuhp_state lpfc_cpuhp_state;
72 /* Used when mapping IRQ vectors in a driver centric manner */
73 static uint32_t lpfc_present_cpu;
75 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
76 static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
77 static void lpfc_cpuhp_add(struct lpfc_hba *phba);
78 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
79 static int lpfc_post_rcv_buf(struct lpfc_hba *);
80 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
81 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
82 static int lpfc_setup_endian_order(struct lpfc_hba *);
83 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
84 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
85 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
86 static void lpfc_init_sgl_list(struct lpfc_hba *);
87 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
88 static void lpfc_free_active_sgl(struct lpfc_hba *);
89 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
90 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
91 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
92 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
93 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
94 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
95 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
96 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
97 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
98 static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
100 static struct scsi_transport_template *lpfc_transport_template = NULL;
101 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
102 static DEFINE_IDR(lpfc_hba_index);
103 #define LPFC_NVMET_BUF_POST 254
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_MBOX,
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_INIT,
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_INIT,
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)
259 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
260 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
261 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
262 lpfc_vpd_data + offset,
263 mb->un.varDmp.word_cnt);
264 offset += mb->un.varDmp.word_cnt;
265 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
266 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
268 kfree(lpfc_vpd_data);
270 mempool_free(pmb, phba->mbox_mem_pool);
275 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
276 * @phba: pointer to lpfc hba data structure.
277 * @pmboxq: pointer to the driver internal queue element for mailbox command.
279 * This is the completion handler for driver's configuring asynchronous event
280 * mailbox command to the device. If the mailbox command returns successfully,
281 * it will set internal async event support flag to 1; otherwise, it will
282 * set internal async event support flag to 0.
285 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
287 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
288 phba->temp_sensor_support = 1;
290 phba->temp_sensor_support = 0;
291 mempool_free(pmboxq, phba->mbox_mem_pool);
296 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
297 * @phba: pointer to lpfc hba data structure.
298 * @pmboxq: pointer to the driver internal queue element for mailbox command.
300 * This is the completion handler for dump mailbox command for getting
301 * wake up parameters. When this command complete, the response contain
302 * Option rom version of the HBA. This function translate the version number
303 * into a human readable string and store it in OptionROMVersion.
306 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
309 uint32_t prog_id_word;
311 /* character array used for decoding dist type. */
312 char dist_char[] = "nabx";
314 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
315 mempool_free(pmboxq, phba->mbox_mem_pool);
319 prg = (struct prog_id *) &prog_id_word;
321 /* word 7 contain option rom version */
322 prog_id_word = pmboxq->u.mb.un.varWords[7];
324 /* Decode the Option rom version word to a readable string */
326 dist = dist_char[prg->dist];
328 if ((prg->dist == 3) && (prg->num == 0))
329 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
330 prg->ver, prg->rev, prg->lev);
332 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
333 prg->ver, prg->rev, prg->lev,
335 mempool_free(pmboxq, phba->mbox_mem_pool);
340 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
341 * cfg_soft_wwnn, cfg_soft_wwpn
342 * @vport: pointer to lpfc vport data structure.
349 lpfc_update_vport_wwn(struct lpfc_vport *vport)
351 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
352 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
354 /* If the soft name exists then update it using the service params */
355 if (vport->phba->cfg_soft_wwnn)
356 u64_to_wwn(vport->phba->cfg_soft_wwnn,
357 vport->fc_sparam.nodeName.u.wwn);
358 if (vport->phba->cfg_soft_wwpn)
359 u64_to_wwn(vport->phba->cfg_soft_wwpn,
360 vport->fc_sparam.portName.u.wwn);
363 * If the name is empty or there exists a soft name
364 * then copy the service params name, otherwise use the fc name
366 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
367 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
368 sizeof(struct lpfc_name));
370 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
371 sizeof(struct lpfc_name));
374 * If the port name has changed, then set the Param changes flag
377 if (vport->fc_portname.u.wwn[0] != 0 &&
378 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
379 sizeof(struct lpfc_name)))
380 vport->vport_flag |= FAWWPN_PARAM_CHG;
382 if (vport->fc_portname.u.wwn[0] == 0 ||
383 vport->phba->cfg_soft_wwpn ||
384 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
385 vport->vport_flag & FAWWPN_SET) {
386 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
387 sizeof(struct lpfc_name));
388 vport->vport_flag &= ~FAWWPN_SET;
389 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
390 vport->vport_flag |= FAWWPN_SET;
393 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
394 sizeof(struct lpfc_name));
398 * lpfc_config_port_post - Perform lpfc initialization after config port
399 * @phba: pointer to lpfc hba data structure.
401 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
402 * command call. It performs all internal resource and state setups on the
403 * port: post IOCB buffers, enable appropriate host interrupt attentions,
404 * ELS ring timers, etc.
408 * Any other value - error.
411 lpfc_config_port_post(struct lpfc_hba *phba)
413 struct lpfc_vport *vport = phba->pport;
414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
417 struct lpfc_dmabuf *mp;
418 struct lpfc_sli *psli = &phba->sli;
419 uint32_t status, timeout;
423 spin_lock_irq(&phba->hbalock);
425 * If the Config port completed correctly the HBA is not
426 * over heated any more.
428 if (phba->over_temp_state == HBA_OVER_TEMP)
429 phba->over_temp_state = HBA_NORMAL_TEMP;
430 spin_unlock_irq(&phba->hbalock);
432 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
434 phba->link_state = LPFC_HBA_ERROR;
439 /* Get login parameters for NID. */
440 rc = lpfc_read_sparam(phba, pmb, 0);
442 mempool_free(pmb, phba->mbox_mem_pool);
447 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
449 "0448 Adapter failed init, mbxCmd x%x "
450 "READ_SPARM mbxStatus x%x\n",
451 mb->mbxCommand, mb->mbxStatus);
452 phba->link_state = LPFC_HBA_ERROR;
453 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
454 mempool_free(pmb, phba->mbox_mem_pool);
455 lpfc_mbuf_free(phba, mp->virt, mp->phys);
460 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
462 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
463 lpfc_mbuf_free(phba, mp->virt, mp->phys);
466 lpfc_update_vport_wwn(vport);
468 /* Update the fc_host data structures with new wwn. */
469 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
470 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
471 fc_host_max_npiv_vports(shost) = phba->max_vpi;
473 /* If no serial number in VPD data, use low 6 bytes of WWNN */
474 /* This should be consolidated into parse_vpd ? - mr */
475 if (phba->SerialNumber[0] == 0) {
478 outptr = &vport->fc_nodename.u.s.IEEE[0];
479 for (i = 0; i < 12; i++) {
481 j = ((status & 0xf0) >> 4);
483 phba->SerialNumber[i] =
484 (char)((uint8_t) 0x30 + (uint8_t) j);
486 phba->SerialNumber[i] =
487 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x30 + (uint8_t) j);
494 phba->SerialNumber[i] =
495 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
499 lpfc_read_config(phba, pmb);
501 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
503 "0453 Adapter failed to init, mbxCmd x%x "
504 "READ_CONFIG, mbxStatus x%x\n",
505 mb->mbxCommand, mb->mbxStatus);
506 phba->link_state = LPFC_HBA_ERROR;
507 mempool_free( pmb, phba->mbox_mem_pool);
511 /* Check if the port is disabled */
512 lpfc_sli_read_link_ste(phba);
514 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
515 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
516 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
517 "3359 HBA queue depth changed from %d to %d\n",
518 phba->cfg_hba_queue_depth,
519 mb->un.varRdConfig.max_xri);
520 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
523 phba->lmt = mb->un.varRdConfig.lmt;
525 /* Get the default values for Model Name and Description */
526 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
528 phba->link_state = LPFC_LINK_DOWN;
530 /* Only process IOCBs on ELS ring till hba_state is READY */
531 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
532 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
533 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
536 /* Post receive buffers for desired rings */
537 if (phba->sli_rev != 3)
538 lpfc_post_rcv_buf(phba);
541 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
543 if (phba->intr_type == MSIX) {
544 rc = lpfc_config_msi(phba, pmb);
546 mempool_free(pmb, phba->mbox_mem_pool);
549 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
550 if (rc != MBX_SUCCESS) {
551 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
552 "0352 Config MSI mailbox command "
553 "failed, mbxCmd x%x, mbxStatus x%x\n",
554 pmb->u.mb.mbxCommand,
555 pmb->u.mb.mbxStatus);
556 mempool_free(pmb, phba->mbox_mem_pool);
561 spin_lock_irq(&phba->hbalock);
562 /* Initialize ERATT handling flag */
563 phba->hba_flag &= ~HBA_ERATT_HANDLED;
565 /* Enable appropriate host interrupts */
566 if (lpfc_readl(phba->HCregaddr, &status)) {
567 spin_unlock_irq(&phba->hbalock);
570 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
571 if (psli->num_rings > 0)
572 status |= HC_R0INT_ENA;
573 if (psli->num_rings > 1)
574 status |= HC_R1INT_ENA;
575 if (psli->num_rings > 2)
576 status |= HC_R2INT_ENA;
577 if (psli->num_rings > 3)
578 status |= HC_R3INT_ENA;
580 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
581 (phba->cfg_poll & DISABLE_FCP_RING_INT))
582 status &= ~(HC_R0INT_ENA);
584 writel(status, phba->HCregaddr);
585 readl(phba->HCregaddr); /* flush */
586 spin_unlock_irq(&phba->hbalock);
588 /* Set up ring-0 (ELS) timer */
589 timeout = phba->fc_ratov * 2;
590 mod_timer(&vport->els_tmofunc,
591 jiffies + msecs_to_jiffies(1000 * timeout));
592 /* Set up heart beat (HB) timer */
593 mod_timer(&phba->hb_tmofunc,
594 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
595 phba->hb_outstanding = 0;
596 phba->last_completion_time = jiffies;
597 /* Set up error attention (ERATT) polling timer */
598 mod_timer(&phba->eratt_poll,
599 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
601 if (phba->hba_flag & LINK_DISABLED) {
602 lpfc_printf_log(phba,
604 "2598 Adapter Link is disabled.\n");
605 lpfc_down_link(phba, pmb);
606 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
607 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
608 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
609 lpfc_printf_log(phba,
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,
639 "0456 Adapter failed to issue "
640 "ASYNCEVT_ENABLE mbox status x%x\n",
642 mempool_free(pmb, phba->mbox_mem_pool);
645 /* Get Option rom version */
646 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
648 phba->link_state = LPFC_HBA_ERROR;
652 lpfc_dump_wakeup_param(phba, pmb);
653 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
654 pmb->vport = phba->pport;
655 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
657 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
659 "to get Option ROM version status x%x\n", rc);
660 mempool_free(pmb, phba->mbox_mem_pool);
667 * lpfc_hba_init_link - Initialize the FC link
668 * @phba: pointer to lpfc hba data structure.
669 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
671 * This routine will issue the INIT_LINK mailbox command call.
672 * It is available to other drivers through the lpfc_hba data
673 * structure for use as a delayed link up mechanism with the
674 * module parameter lpfc_suppress_link_up.
678 * Any other value - error
681 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
683 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
687 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
688 * @phba: pointer to lpfc hba data structure.
689 * @fc_topology: desired fc topology.
690 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
692 * This routine will issue the INIT_LINK mailbox command call.
693 * It is available to other drivers through the lpfc_hba data
694 * structure for use as a delayed link up mechanism with the
695 * module parameter lpfc_suppress_link_up.
699 * Any other value - error
702 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
705 struct lpfc_vport *vport = phba->pport;
710 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
712 phba->link_state = LPFC_HBA_ERROR;
718 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
719 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
720 !(phba->lmt & LMT_1Gb)) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
722 !(phba->lmt & LMT_2Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
724 !(phba->lmt & LMT_4Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
726 !(phba->lmt & LMT_8Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
728 !(phba->lmt & LMT_10Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
730 !(phba->lmt & LMT_16Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
732 !(phba->lmt & LMT_32Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
734 !(phba->lmt & LMT_64Gb))) {
735 /* Reset link speed to auto */
736 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
737 "1302 Invalid speed for this board:%d "
738 "Reset link speed to auto.\n",
739 phba->cfg_link_speed);
740 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
742 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
743 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
744 if (phba->sli_rev < LPFC_SLI_REV4)
745 lpfc_set_loopback_flag(phba);
746 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
747 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
749 "0498 Adapter failed to init, mbxCmd x%x "
750 "INIT_LINK, mbxStatus x%x\n",
751 mb->mbxCommand, mb->mbxStatus);
752 if (phba->sli_rev <= LPFC_SLI_REV3) {
753 /* Clear all interrupt enable conditions */
754 writel(0, phba->HCregaddr);
755 readl(phba->HCregaddr); /* flush */
756 /* Clear all pending interrupts */
757 writel(0xffffffff, phba->HAregaddr);
758 readl(phba->HAregaddr); /* flush */
760 phba->link_state = LPFC_HBA_ERROR;
761 if (rc != MBX_BUSY || flag == MBX_POLL)
762 mempool_free(pmb, phba->mbox_mem_pool);
765 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
766 if (flag == MBX_POLL)
767 mempool_free(pmb, phba->mbox_mem_pool);
773 * lpfc_hba_down_link - this routine downs the FC link
774 * @phba: pointer to lpfc hba data structure.
775 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
777 * This routine will issue the DOWN_LINK mailbox command call.
778 * It is available to other drivers through the lpfc_hba data
779 * structure for use to stop the link.
783 * Any other value - error
786 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
791 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
793 phba->link_state = LPFC_HBA_ERROR;
797 lpfc_printf_log(phba,
799 "0491 Adapter Link is disabled.\n");
800 lpfc_down_link(phba, pmb);
801 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
802 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
803 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
804 lpfc_printf_log(phba,
806 "2522 Adapter failed to issue DOWN_LINK"
807 " mbox command rc 0x%x\n", rc);
809 mempool_free(pmb, phba->mbox_mem_pool);
812 if (flag == MBX_POLL)
813 mempool_free(pmb, phba->mbox_mem_pool);
819 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
820 * @phba: pointer to lpfc HBA data structure.
822 * This routine will do LPFC uninitialization before the HBA is reset when
823 * bringing down the SLI Layer.
827 * Any other value - error.
830 lpfc_hba_down_prep(struct lpfc_hba *phba)
832 struct lpfc_vport **vports;
835 if (phba->sli_rev <= LPFC_SLI_REV3) {
836 /* Disable interrupts */
837 writel(0, phba->HCregaddr);
838 readl(phba->HCregaddr); /* flush */
841 if (phba->pport->load_flag & FC_UNLOADING)
842 lpfc_cleanup_discovery_resources(phba->pport);
844 vports = lpfc_create_vport_work_array(phba);
846 for (i = 0; i <= phba->max_vports &&
847 vports[i] != NULL; i++)
848 lpfc_cleanup_discovery_resources(vports[i]);
849 lpfc_destroy_vport_work_array(phba, vports);
855 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
856 * rspiocb which got deferred
858 * @phba: pointer to lpfc HBA data structure.
860 * This routine will cleanup completed slow path events after HBA is reset
861 * when bringing down the SLI Layer.
868 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
870 struct lpfc_iocbq *rspiocbq;
871 struct hbq_dmabuf *dmabuf;
872 struct lpfc_cq_event *cq_event;
874 spin_lock_irq(&phba->hbalock);
875 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
876 spin_unlock_irq(&phba->hbalock);
878 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
879 /* Get the response iocb from the head of work queue */
880 spin_lock_irq(&phba->hbalock);
881 list_remove_head(&phba->sli4_hba.sp_queue_event,
882 cq_event, struct lpfc_cq_event, list);
883 spin_unlock_irq(&phba->hbalock);
885 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
886 case CQE_CODE_COMPL_WQE:
887 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
889 lpfc_sli_release_iocbq(phba, rspiocbq);
891 case CQE_CODE_RECEIVE:
892 case CQE_CODE_RECEIVE_V1:
893 dmabuf = container_of(cq_event, struct hbq_dmabuf,
895 lpfc_in_buf_free(phba, &dmabuf->dbuf);
901 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
902 * @phba: pointer to lpfc HBA data structure.
904 * This routine will cleanup posted ELS buffers after the HBA is reset
905 * when bringing down the SLI Layer.
912 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
914 struct lpfc_sli *psli = &phba->sli;
915 struct lpfc_sli_ring *pring;
916 struct lpfc_dmabuf *mp, *next_mp;
920 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
921 lpfc_sli_hbqbuf_free_all(phba);
923 /* Cleanup preposted buffers on the ELS ring */
924 pring = &psli->sli3_ring[LPFC_ELS_RING];
925 spin_lock_irq(&phba->hbalock);
926 list_splice_init(&pring->postbufq, &buflist);
927 spin_unlock_irq(&phba->hbalock);
930 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
933 lpfc_mbuf_free(phba, mp->virt, mp->phys);
937 spin_lock_irq(&phba->hbalock);
938 pring->postbufq_cnt -= count;
939 spin_unlock_irq(&phba->hbalock);
944 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
945 * @phba: pointer to lpfc HBA data structure.
947 * This routine will cleanup the txcmplq after the HBA is reset when bringing
948 * down the SLI Layer.
954 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
956 struct lpfc_sli *psli = &phba->sli;
957 struct lpfc_queue *qp = NULL;
958 struct lpfc_sli_ring *pring;
959 LIST_HEAD(completions);
961 struct lpfc_iocbq *piocb, *next_iocb;
963 if (phba->sli_rev != LPFC_SLI_REV4) {
964 for (i = 0; i < psli->num_rings; i++) {
965 pring = &psli->sli3_ring[i];
966 spin_lock_irq(&phba->hbalock);
967 /* At this point in time the HBA is either reset or DOA
968 * Nothing should be on txcmplq as it will
971 list_splice_init(&pring->txcmplq, &completions);
972 pring->txcmplq_cnt = 0;
973 spin_unlock_irq(&phba->hbalock);
975 lpfc_sli_abort_iocb_ring(phba, pring);
977 /* Cancel all the IOCBs from the completions list */
978 lpfc_sli_cancel_iocbs(phba, &completions,
979 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
982 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
986 spin_lock_irq(&pring->ring_lock);
987 list_for_each_entry_safe(piocb, next_iocb,
988 &pring->txcmplq, list)
989 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
990 list_splice_init(&pring->txcmplq, &completions);
991 pring->txcmplq_cnt = 0;
992 spin_unlock_irq(&pring->ring_lock);
993 lpfc_sli_abort_iocb_ring(phba, pring);
995 /* Cancel all the IOCBs from the completions list */
996 lpfc_sli_cancel_iocbs(phba, &completions,
997 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1001 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1003 * @phba: pointer to lpfc HBA data structure.
1005 * This routine will do uninitialization after the HBA is reset when bring
1006 * down the SLI Layer.
1010 * Any other value - error.
1013 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1015 lpfc_hba_free_post_buf(phba);
1016 lpfc_hba_clean_txcmplq(phba);
1021 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1022 * @phba: pointer to lpfc HBA data structure.
1024 * This routine will do uninitialization after the HBA is reset when bring
1025 * down the SLI Layer.
1029 * Any other value - error.
1032 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1034 struct lpfc_io_buf *psb, *psb_next;
1035 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
1036 struct lpfc_sli4_hdw_queue *qp;
1038 LIST_HEAD(nvme_aborts);
1039 LIST_HEAD(nvmet_aborts);
1040 struct lpfc_sglq *sglq_entry = NULL;
1044 lpfc_sli_hbqbuf_free_all(phba);
1045 lpfc_hba_clean_txcmplq(phba);
1047 /* At this point in time the HBA is either reset or DOA. Either
1048 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1049 * on the lpfc_els_sgl_list so that it can either be freed if the
1050 * driver is unloading or reposted if the driver is restarting
1053 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
1055 /* sgl_list_lock required because worker thread uses this
1058 spin_lock(&phba->sli4_hba.sgl_list_lock);
1059 list_for_each_entry(sglq_entry,
1060 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1061 sglq_entry->state = SGL_FREED;
1063 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1064 &phba->sli4_hba.lpfc_els_sgl_list);
1067 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1069 /* abts_xxxx_buf_list_lock required because worker thread uses this
1073 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1074 qp = &phba->sli4_hba.hdwq[idx];
1076 spin_lock(&qp->abts_io_buf_list_lock);
1077 list_splice_init(&qp->lpfc_abts_io_buf_list,
1080 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1082 psb->status = IOSTAT_SUCCESS;
1085 spin_lock(&qp->io_buf_list_put_lock);
1086 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1087 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1088 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1089 qp->abts_scsi_io_bufs = 0;
1090 qp->abts_nvme_io_bufs = 0;
1091 spin_unlock(&qp->io_buf_list_put_lock);
1092 spin_unlock(&qp->abts_io_buf_list_lock);
1094 spin_unlock_irq(&phba->hbalock);
1096 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1097 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1098 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1100 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1101 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1102 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
1103 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1107 lpfc_sli4_free_sp_events(phba);
1112 * lpfc_hba_down_post - Wrapper func for hba down post routine
1113 * @phba: pointer to lpfc HBA data structure.
1115 * This routine wraps the actual SLI3 or SLI4 routine for performing
1116 * uninitialization after the HBA is reset when bring down the SLI Layer.
1120 * Any other value - error.
1123 lpfc_hba_down_post(struct lpfc_hba *phba)
1125 return (*phba->lpfc_hba_down_post)(phba);
1129 * lpfc_hb_timeout - The HBA-timer timeout handler
1130 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1132 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1133 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1134 * work-port-events bitmap and the worker thread is notified. This timeout
1135 * event will be used by the worker thread to invoke the actual timeout
1136 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1137 * be performed in the timeout handler and the HBA timeout event bit shall
1138 * be cleared by the worker thread after it has taken the event bitmap out.
1141 lpfc_hb_timeout(struct timer_list *t)
1143 struct lpfc_hba *phba;
1144 uint32_t tmo_posted;
1145 unsigned long iflag;
1147 phba = from_timer(phba, t, hb_tmofunc);
1149 /* Check for heart beat timeout conditions */
1150 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1151 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1153 phba->pport->work_port_events |= WORKER_HB_TMO;
1154 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1156 /* Tell the worker thread there is work to do */
1158 lpfc_worker_wake_up(phba);
1163 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1164 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1166 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1167 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1168 * work-port-events bitmap and the worker thread is notified. This timeout
1169 * event will be used by the worker thread to invoke the actual timeout
1170 * handler routine, lpfc_rrq_handler. Any periodical operations will
1171 * be performed in the timeout handler and the RRQ timeout event bit shall
1172 * be cleared by the worker thread after it has taken the event bitmap out.
1175 lpfc_rrq_timeout(struct timer_list *t)
1177 struct lpfc_hba *phba;
1178 unsigned long iflag;
1180 phba = from_timer(phba, t, rrq_tmr);
1181 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1182 if (!(phba->pport->load_flag & FC_UNLOADING))
1183 phba->hba_flag |= HBA_RRQ_ACTIVE;
1185 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1186 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1188 if (!(phba->pport->load_flag & FC_UNLOADING))
1189 lpfc_worker_wake_up(phba);
1193 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1194 * @phba: pointer to lpfc hba data structure.
1195 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1197 * This is the callback function to the lpfc heart-beat mailbox command.
1198 * If configured, the lpfc driver issues the heart-beat mailbox command to
1199 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1200 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1201 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1202 * heart-beat outstanding state. Once the mailbox command comes back and
1203 * no error conditions detected, the heart-beat mailbox command timer is
1204 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1205 * state is cleared for the next heart-beat. If the timer expired with the
1206 * heart-beat outstanding state set, the driver will put the HBA offline.
1209 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1211 unsigned long drvr_flag;
1213 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1214 phba->hb_outstanding = 0;
1215 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1217 /* Check and reset heart-beat timer is necessary */
1218 mempool_free(pmboxq, phba->mbox_mem_pool);
1219 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1220 !(phba->link_state == LPFC_HBA_ERROR) &&
1221 !(phba->pport->load_flag & FC_UNLOADING))
1222 mod_timer(&phba->hb_tmofunc,
1224 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1229 lpfc_hb_eq_delay_work(struct work_struct *work)
1231 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1232 struct lpfc_hba, eq_delay_work);
1233 struct lpfc_eq_intr_info *eqi, *eqi_new;
1234 struct lpfc_queue *eq, *eq_next;
1235 unsigned char *ena_delay = NULL;
1239 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1242 if (phba->link_state == LPFC_HBA_ERROR ||
1243 phba->pport->fc_flag & FC_OFFLINE_MODE)
1246 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1251 for (i = 0; i < phba->cfg_irq_chann; i++) {
1252 /* Get the EQ corresponding to the IRQ vector */
1253 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1256 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1257 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1258 ena_delay[eq->last_cpu] = 1;
1262 for_each_present_cpu(i) {
1263 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1265 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1266 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1267 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1274 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1275 if (unlikely(eq->last_cpu != i)) {
1276 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1278 list_move_tail(&eq->cpu_list, &eqi_new->list);
1281 if (usdelay != eq->q_mode)
1282 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1290 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1291 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1295 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1296 * @phba: pointer to lpfc hba data structure.
1298 * For each heartbeat, this routine does some heuristic methods to adjust
1299 * XRI distribution. The goal is to fully utilize free XRIs.
1301 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1306 hwq_count = phba->cfg_hdw_queue;
1307 for (i = 0; i < hwq_count; i++) {
1308 /* Adjust XRIs in private pool */
1309 lpfc_adjust_pvt_pool_count(phba, i);
1311 /* Adjust high watermark */
1312 lpfc_adjust_high_watermark(phba, i);
1314 #ifdef LPFC_MXP_STAT
1315 /* Snapshot pbl, pvt and busy count */
1316 lpfc_snapshot_mxp(phba, i);
1322 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1323 * @phba: pointer to lpfc hba data structure.
1325 * This is the actual HBA-timer timeout handler to be invoked by the worker
1326 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1327 * handler performs any periodic operations needed for the device. If such
1328 * periodic event has already been attended to either in the interrupt handler
1329 * or by processing slow-ring or fast-ring events within the HBA-timer
1330 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1331 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1332 * is configured and there is no heart-beat mailbox command outstanding, a
1333 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1334 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1338 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1340 struct lpfc_vport **vports;
1341 LPFC_MBOXQ_t *pmboxq;
1342 struct lpfc_dmabuf *buf_ptr;
1344 struct lpfc_sli *psli = &phba->sli;
1345 LIST_HEAD(completions);
1347 if (phba->cfg_xri_rebalancing) {
1348 /* Multi-XRI pools handler */
1349 lpfc_hb_mxp_handler(phba);
1352 vports = lpfc_create_vport_work_array(phba);
1354 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1355 lpfc_rcv_seq_check_edtov(vports[i]);
1356 lpfc_fdmi_change_check(vports[i]);
1358 lpfc_destroy_vport_work_array(phba, vports);
1360 if ((phba->link_state == LPFC_HBA_ERROR) ||
1361 (phba->pport->load_flag & FC_UNLOADING) ||
1362 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1365 spin_lock_irq(&phba->pport->work_port_lock);
1367 if (time_after(phba->last_completion_time +
1368 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1370 spin_unlock_irq(&phba->pport->work_port_lock);
1371 if (!phba->hb_outstanding)
1372 mod_timer(&phba->hb_tmofunc,
1374 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1376 mod_timer(&phba->hb_tmofunc,
1378 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1381 spin_unlock_irq(&phba->pport->work_port_lock);
1383 if (phba->elsbuf_cnt &&
1384 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1385 spin_lock_irq(&phba->hbalock);
1386 list_splice_init(&phba->elsbuf, &completions);
1387 phba->elsbuf_cnt = 0;
1388 phba->elsbuf_prev_cnt = 0;
1389 spin_unlock_irq(&phba->hbalock);
1391 while (!list_empty(&completions)) {
1392 list_remove_head(&completions, buf_ptr,
1393 struct lpfc_dmabuf, list);
1394 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1398 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1400 /* If there is no heart beat outstanding, issue a heartbeat command */
1401 if (phba->cfg_enable_hba_heartbeat) {
1402 if (!phba->hb_outstanding) {
1403 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1404 (list_empty(&psli->mboxq))) {
1405 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1408 mod_timer(&phba->hb_tmofunc,
1410 msecs_to_jiffies(1000 *
1411 LPFC_HB_MBOX_INTERVAL));
1415 lpfc_heart_beat(phba, pmboxq);
1416 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1417 pmboxq->vport = phba->pport;
1418 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1421 if (retval != MBX_BUSY &&
1422 retval != MBX_SUCCESS) {
1423 mempool_free(pmboxq,
1424 phba->mbox_mem_pool);
1425 mod_timer(&phba->hb_tmofunc,
1427 msecs_to_jiffies(1000 *
1428 LPFC_HB_MBOX_INTERVAL));
1431 phba->skipped_hb = 0;
1432 phba->hb_outstanding = 1;
1433 } else if (time_before_eq(phba->last_completion_time,
1434 phba->skipped_hb)) {
1435 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1436 "2857 Last completion time not "
1437 " updated in %d ms\n",
1438 jiffies_to_msecs(jiffies
1439 - phba->last_completion_time));
1441 phba->skipped_hb = jiffies;
1443 mod_timer(&phba->hb_tmofunc,
1445 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1449 * If heart beat timeout called with hb_outstanding set
1450 * we need to give the hb mailbox cmd a chance to
1453 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1454 "0459 Adapter heartbeat still out"
1455 "standing:last compl time was %d ms.\n",
1456 jiffies_to_msecs(jiffies
1457 - phba->last_completion_time));
1458 mod_timer(&phba->hb_tmofunc,
1460 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1463 mod_timer(&phba->hb_tmofunc,
1465 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1470 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1471 * @phba: pointer to lpfc hba data structure.
1473 * This routine is called to bring the HBA offline when HBA hardware error
1474 * other than Port Error 6 has been detected.
1477 lpfc_offline_eratt(struct lpfc_hba *phba)
1479 struct lpfc_sli *psli = &phba->sli;
1481 spin_lock_irq(&phba->hbalock);
1482 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1483 spin_unlock_irq(&phba->hbalock);
1484 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1487 lpfc_reset_barrier(phba);
1488 spin_lock_irq(&phba->hbalock);
1489 lpfc_sli_brdreset(phba);
1490 spin_unlock_irq(&phba->hbalock);
1491 lpfc_hba_down_post(phba);
1492 lpfc_sli_brdready(phba, HS_MBRDY);
1493 lpfc_unblock_mgmt_io(phba);
1494 phba->link_state = LPFC_HBA_ERROR;
1499 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1500 * @phba: pointer to lpfc hba data structure.
1502 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1503 * other than Port Error 6 has been detected.
1506 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1508 spin_lock_irq(&phba->hbalock);
1509 phba->link_state = LPFC_HBA_ERROR;
1510 spin_unlock_irq(&phba->hbalock);
1512 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1513 lpfc_sli_flush_io_rings(phba);
1515 lpfc_hba_down_post(phba);
1516 lpfc_unblock_mgmt_io(phba);
1520 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1521 * @phba: pointer to lpfc hba data structure.
1523 * This routine is invoked to handle the deferred HBA hardware error
1524 * conditions. This type of error is indicated by HBA by setting ER1
1525 * and another ER bit in the host status register. The driver will
1526 * wait until the ER1 bit clears before handling the error condition.
1529 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1531 uint32_t old_host_status = phba->work_hs;
1532 struct lpfc_sli *psli = &phba->sli;
1534 /* If the pci channel is offline, ignore possible errors,
1535 * since we cannot communicate with the pci card anyway.
1537 if (pci_channel_offline(phba->pcidev)) {
1538 spin_lock_irq(&phba->hbalock);
1539 phba->hba_flag &= ~DEFER_ERATT;
1540 spin_unlock_irq(&phba->hbalock);
1544 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1545 "0479 Deferred Adapter Hardware Error "
1546 "Data: x%x x%x x%x\n",
1548 phba->work_status[0], phba->work_status[1]);
1550 spin_lock_irq(&phba->hbalock);
1551 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1552 spin_unlock_irq(&phba->hbalock);
1556 * Firmware stops when it triggred erratt. That could cause the I/Os
1557 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1558 * SCSI layer retry it after re-establishing link.
1560 lpfc_sli_abort_fcp_rings(phba);
1563 * There was a firmware error. Take the hba offline and then
1564 * attempt to restart it.
1566 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1569 /* Wait for the ER1 bit to clear.*/
1570 while (phba->work_hs & HS_FFER1) {
1572 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1573 phba->work_hs = UNPLUG_ERR ;
1576 /* If driver is unloading let the worker thread continue */
1577 if (phba->pport->load_flag & FC_UNLOADING) {
1584 * This is to ptrotect against a race condition in which
1585 * first write to the host attention register clear the
1586 * host status register.
1588 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1589 phba->work_hs = old_host_status & ~HS_FFER1;
1591 spin_lock_irq(&phba->hbalock);
1592 phba->hba_flag &= ~DEFER_ERATT;
1593 spin_unlock_irq(&phba->hbalock);
1594 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1595 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1599 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1601 struct lpfc_board_event_header board_event;
1602 struct Scsi_Host *shost;
1604 board_event.event_type = FC_REG_BOARD_EVENT;
1605 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1606 shost = lpfc_shost_from_vport(phba->pport);
1607 fc_host_post_vendor_event(shost, fc_get_event_number(),
1608 sizeof(board_event),
1609 (char *) &board_event,
1614 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1615 * @phba: pointer to lpfc hba data structure.
1617 * This routine is invoked to handle the following HBA hardware error
1619 * 1 - HBA error attention interrupt
1620 * 2 - DMA ring index out of range
1621 * 3 - Mailbox command came back as unknown
1624 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1626 struct lpfc_vport *vport = phba->pport;
1627 struct lpfc_sli *psli = &phba->sli;
1628 uint32_t event_data;
1629 unsigned long temperature;
1630 struct temp_event temp_event_data;
1631 struct Scsi_Host *shost;
1633 /* If the pci channel is offline, ignore possible errors,
1634 * since we cannot communicate with the pci card anyway.
1636 if (pci_channel_offline(phba->pcidev)) {
1637 spin_lock_irq(&phba->hbalock);
1638 phba->hba_flag &= ~DEFER_ERATT;
1639 spin_unlock_irq(&phba->hbalock);
1643 /* If resets are disabled then leave the HBA alone and return */
1644 if (!phba->cfg_enable_hba_reset)
1647 /* Send an internal error event to mgmt application */
1648 lpfc_board_errevt_to_mgmt(phba);
1650 if (phba->hba_flag & DEFER_ERATT)
1651 lpfc_handle_deferred_eratt(phba);
1653 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1654 if (phba->work_hs & HS_FFER6)
1655 /* Re-establishing Link */
1656 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1657 "1301 Re-establishing Link "
1658 "Data: x%x x%x x%x\n",
1659 phba->work_hs, phba->work_status[0],
1660 phba->work_status[1]);
1661 if (phba->work_hs & HS_FFER8)
1662 /* Device Zeroization */
1663 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1664 "2861 Host Authentication device "
1665 "zeroization Data:x%x x%x x%x\n",
1666 phba->work_hs, phba->work_status[0],
1667 phba->work_status[1]);
1669 spin_lock_irq(&phba->hbalock);
1670 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1671 spin_unlock_irq(&phba->hbalock);
1674 * Firmware stops when it triggled erratt with HS_FFER6.
1675 * That could cause the I/Os dropped by the firmware.
1676 * Error iocb (I/O) on txcmplq and let the SCSI layer
1677 * retry it after re-establishing link.
1679 lpfc_sli_abort_fcp_rings(phba);
1682 * There was a firmware error. Take the hba offline and then
1683 * attempt to restart it.
1685 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1687 lpfc_sli_brdrestart(phba);
1688 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1689 lpfc_unblock_mgmt_io(phba);
1692 lpfc_unblock_mgmt_io(phba);
1693 } else if (phba->work_hs & HS_CRIT_TEMP) {
1694 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1695 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1696 temp_event_data.event_code = LPFC_CRIT_TEMP;
1697 temp_event_data.data = (uint32_t)temperature;
1699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1700 "0406 Adapter maximum temperature exceeded "
1701 "(%ld), taking this port offline "
1702 "Data: x%x x%x x%x\n",
1703 temperature, phba->work_hs,
1704 phba->work_status[0], phba->work_status[1]);
1706 shost = lpfc_shost_from_vport(phba->pport);
1707 fc_host_post_vendor_event(shost, fc_get_event_number(),
1708 sizeof(temp_event_data),
1709 (char *) &temp_event_data,
1710 SCSI_NL_VID_TYPE_PCI
1711 | PCI_VENDOR_ID_EMULEX);
1713 spin_lock_irq(&phba->hbalock);
1714 phba->over_temp_state = HBA_OVER_TEMP;
1715 spin_unlock_irq(&phba->hbalock);
1716 lpfc_offline_eratt(phba);
1719 /* The if clause above forces this code path when the status
1720 * failure is a value other than FFER6. Do not call the offline
1721 * twice. This is the adapter hardware error path.
1723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1724 "0457 Adapter Hardware Error "
1725 "Data: x%x x%x x%x\n",
1727 phba->work_status[0], phba->work_status[1]);
1729 event_data = FC_REG_DUMP_EVENT;
1730 shost = lpfc_shost_from_vport(vport);
1731 fc_host_post_vendor_event(shost, fc_get_event_number(),
1732 sizeof(event_data), (char *) &event_data,
1733 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1735 lpfc_offline_eratt(phba);
1741 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1742 * @phba: pointer to lpfc hba data structure.
1743 * @mbx_action: flag for mailbox shutdown action.
1745 * This routine is invoked to perform an SLI4 port PCI function reset in
1746 * response to port status register polling attention. It waits for port
1747 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1748 * During this process, interrupt vectors are freed and later requested
1749 * for handling possible port resource change.
1752 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1758 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1759 LPFC_SLI_INTF_IF_TYPE_2) {
1761 * On error status condition, driver need to wait for port
1762 * ready before performing reset.
1764 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1769 /* need reset: attempt for port recovery */
1771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1772 "2887 Reset Needed: Attempting Port "
1774 lpfc_offline_prep(phba, mbx_action);
1775 lpfc_sli_flush_io_rings(phba);
1777 /* release interrupt for possible resource change */
1778 lpfc_sli4_disable_intr(phba);
1779 rc = lpfc_sli_brdrestart(phba);
1781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1782 "6309 Failed to restart board\n");
1785 /* request and enable interrupt */
1786 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1787 if (intr_mode == LPFC_INTR_ERROR) {
1788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1789 "3175 Failed to enable interrupt\n");
1792 phba->intr_mode = intr_mode;
1793 rc = lpfc_online(phba);
1795 lpfc_unblock_mgmt_io(phba);
1801 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1802 * @phba: pointer to lpfc hba data structure.
1804 * This routine is invoked to handle the SLI4 HBA hardware error attention
1808 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1810 struct lpfc_vport *vport = phba->pport;
1811 uint32_t event_data;
1812 struct Scsi_Host *shost;
1814 struct lpfc_register portstat_reg = {0};
1815 uint32_t reg_err1, reg_err2;
1816 uint32_t uerrlo_reg, uemasklo_reg;
1817 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1818 bool en_rn_msg = true;
1819 struct temp_event temp_event_data;
1820 struct lpfc_register portsmphr_reg;
1823 /* If the pci channel is offline, ignore possible errors, since
1824 * we cannot communicate with the pci card anyway.
1826 if (pci_channel_offline(phba->pcidev)) {
1827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1828 "3166 pci channel is offline\n");
1829 lpfc_sli4_offline_eratt(phba);
1833 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1834 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1836 case LPFC_SLI_INTF_IF_TYPE_0:
1837 pci_rd_rc1 = lpfc_readl(
1838 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1840 pci_rd_rc2 = lpfc_readl(
1841 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1843 /* consider PCI bus read error as pci_channel_offline */
1844 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1846 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1847 lpfc_sli4_offline_eratt(phba);
1850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1851 "7623 Checking UE recoverable");
1853 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1854 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1855 &portsmphr_reg.word0))
1858 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1860 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1861 LPFC_PORT_SEM_UE_RECOVERABLE)
1863 /*Sleep for 1Sec, before checking SEMAPHORE */
1867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1868 "4827 smphr_port_status x%x : Waited %dSec",
1869 smphr_port_status, i);
1871 /* Recoverable UE, reset the HBA device */
1872 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1873 LPFC_PORT_SEM_UE_RECOVERABLE) {
1874 for (i = 0; i < 20; i++) {
1876 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1877 &portsmphr_reg.word0) &&
1878 (LPFC_POST_STAGE_PORT_READY ==
1879 bf_get(lpfc_port_smphr_port_status,
1881 rc = lpfc_sli4_port_sta_fn_reset(phba,
1882 LPFC_MBX_NO_WAIT, en_rn_msg);
1885 lpfc_printf_log(phba,
1887 "4215 Failed to recover UE");
1892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1893 "7624 Firmware not ready: Failing UE recovery,"
1894 " waited %dSec", i);
1895 phba->link_state = LPFC_HBA_ERROR;
1898 case LPFC_SLI_INTF_IF_TYPE_2:
1899 case LPFC_SLI_INTF_IF_TYPE_6:
1900 pci_rd_rc1 = lpfc_readl(
1901 phba->sli4_hba.u.if_type2.STATUSregaddr,
1902 &portstat_reg.word0);
1903 /* consider PCI bus read error as pci_channel_offline */
1904 if (pci_rd_rc1 == -EIO) {
1905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1906 "3151 PCI bus read access failure: x%x\n",
1907 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1908 lpfc_sli4_offline_eratt(phba);
1911 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1912 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1913 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1914 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1915 "2889 Port Overtemperature event, "
1916 "taking port offline Data: x%x x%x\n",
1917 reg_err1, reg_err2);
1919 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
1920 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1921 temp_event_data.event_code = LPFC_CRIT_TEMP;
1922 temp_event_data.data = 0xFFFFFFFF;
1924 shost = lpfc_shost_from_vport(phba->pport);
1925 fc_host_post_vendor_event(shost, fc_get_event_number(),
1926 sizeof(temp_event_data),
1927 (char *)&temp_event_data,
1928 SCSI_NL_VID_TYPE_PCI
1929 | PCI_VENDOR_ID_EMULEX);
1931 spin_lock_irq(&phba->hbalock);
1932 phba->over_temp_state = HBA_OVER_TEMP;
1933 spin_unlock_irq(&phba->hbalock);
1934 lpfc_sli4_offline_eratt(phba);
1937 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1938 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1940 "3143 Port Down: Firmware Update "
1943 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1944 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1946 "3144 Port Down: Debug Dump\n");
1947 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1948 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1950 "3145 Port Down: Provisioning\n");
1952 /* If resets are disabled then leave the HBA alone and return */
1953 if (!phba->cfg_enable_hba_reset)
1956 /* Check port status register for function reset */
1957 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1960 /* don't report event on forced debug dump */
1961 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1962 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1967 /* fall through for not able to recover */
1968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1969 "3152 Unrecoverable error\n");
1970 phba->link_state = LPFC_HBA_ERROR;
1972 case LPFC_SLI_INTF_IF_TYPE_1:
1976 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1977 "3123 Report dump event to upper layer\n");
1978 /* Send an internal error event to mgmt application */
1979 lpfc_board_errevt_to_mgmt(phba);
1981 event_data = FC_REG_DUMP_EVENT;
1982 shost = lpfc_shost_from_vport(vport);
1983 fc_host_post_vendor_event(shost, fc_get_event_number(),
1984 sizeof(event_data), (char *) &event_data,
1985 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1989 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1990 * @phba: pointer to lpfc HBA data structure.
1992 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1993 * routine from the API jump table function pointer from the lpfc_hba struct.
1997 * Any other value - error.
2000 lpfc_handle_eratt(struct lpfc_hba *phba)
2002 (*phba->lpfc_handle_eratt)(phba);
2006 * lpfc_handle_latt - The HBA link event handler
2007 * @phba: pointer to lpfc hba data structure.
2009 * This routine is invoked from the worker thread to handle a HBA host
2010 * attention link event. SLI3 only.
2013 lpfc_handle_latt(struct lpfc_hba *phba)
2015 struct lpfc_vport *vport = phba->pport;
2016 struct lpfc_sli *psli = &phba->sli;
2018 volatile uint32_t control;
2019 struct lpfc_dmabuf *mp;
2022 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2025 goto lpfc_handle_latt_err_exit;
2028 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2031 goto lpfc_handle_latt_free_pmb;
2034 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2037 goto lpfc_handle_latt_free_mp;
2040 /* Cleanup any outstanding ELS commands */
2041 lpfc_els_flush_all_cmd(phba);
2043 psli->slistat.link_event++;
2044 lpfc_read_topology(phba, pmb, mp);
2045 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2047 /* Block ELS IOCBs until we have processed this mbox command */
2048 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2049 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2050 if (rc == MBX_NOT_FINISHED) {
2052 goto lpfc_handle_latt_free_mbuf;
2055 /* Clear Link Attention in HA REG */
2056 spin_lock_irq(&phba->hbalock);
2057 writel(HA_LATT, phba->HAregaddr);
2058 readl(phba->HAregaddr); /* flush */
2059 spin_unlock_irq(&phba->hbalock);
2063 lpfc_handle_latt_free_mbuf:
2064 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2065 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2066 lpfc_handle_latt_free_mp:
2068 lpfc_handle_latt_free_pmb:
2069 mempool_free(pmb, phba->mbox_mem_pool);
2070 lpfc_handle_latt_err_exit:
2071 /* Enable Link attention interrupts */
2072 spin_lock_irq(&phba->hbalock);
2073 psli->sli_flag |= LPFC_PROCESS_LA;
2074 control = readl(phba->HCregaddr);
2075 control |= HC_LAINT_ENA;
2076 writel(control, phba->HCregaddr);
2077 readl(phba->HCregaddr); /* flush */
2079 /* Clear Link Attention in HA REG */
2080 writel(HA_LATT, phba->HAregaddr);
2081 readl(phba->HAregaddr); /* flush */
2082 spin_unlock_irq(&phba->hbalock);
2083 lpfc_linkdown(phba);
2084 phba->link_state = LPFC_HBA_ERROR;
2086 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2087 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2093 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2094 * @phba: pointer to lpfc hba data structure.
2095 * @vpd: pointer to the vital product data.
2096 * @len: length of the vital product data in bytes.
2098 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2099 * an array of characters. In this routine, the ModelName, ProgramType, and
2100 * ModelDesc, etc. fields of the phba data structure will be populated.
2103 * 0 - pointer to the VPD passed in is NULL
2107 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2109 uint8_t lenlo, lenhi;
2119 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2120 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2121 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2123 while (!finished && (index < (len - 4))) {
2124 switch (vpd[index]) {
2132 i = ((((unsigned short)lenhi) << 8) + lenlo);
2141 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2142 if (Length > len - index)
2143 Length = len - index;
2144 while (Length > 0) {
2145 /* Look for Serial Number */
2146 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2153 phba->SerialNumber[j++] = vpd[index++];
2157 phba->SerialNumber[j] = 0;
2160 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2161 phba->vpd_flag |= VPD_MODEL_DESC;
2168 phba->ModelDesc[j++] = vpd[index++];
2172 phba->ModelDesc[j] = 0;
2175 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2176 phba->vpd_flag |= VPD_MODEL_NAME;
2183 phba->ModelName[j++] = vpd[index++];
2187 phba->ModelName[j] = 0;
2190 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2191 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2198 phba->ProgramType[j++] = vpd[index++];
2202 phba->ProgramType[j] = 0;
2205 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2206 phba->vpd_flag |= VPD_PORT;
2213 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2214 (phba->sli4_hba.pport_name_sta ==
2215 LPFC_SLI4_PPNAME_GET)) {
2219 phba->Port[j++] = vpd[index++];
2223 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2224 (phba->sli4_hba.pport_name_sta ==
2225 LPFC_SLI4_PPNAME_NON))
2252 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2253 * @phba: pointer to lpfc hba data structure.
2254 * @mdp: pointer to the data structure to hold the derived model name.
2255 * @descp: pointer to the data structure to hold the derived description.
2257 * This routine retrieves HBA's description based on its registered PCI device
2258 * ID. The @descp passed into this function points to an array of 256 chars. It
2259 * shall be returned with the model name, maximum speed, and the host bus type.
2260 * The @mdp passed into this function points to an array of 80 chars. When the
2261 * function returns, the @mdp will be filled with the model name.
2264 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2267 uint16_t dev_id = phba->pcidev->device;
2270 int oneConnect = 0; /* default is not a oneConnect */
2275 } m = {"<Unknown>", "", ""};
2277 if (mdp && mdp[0] != '\0'
2278 && descp && descp[0] != '\0')
2281 if (phba->lmt & LMT_64Gb)
2283 else if (phba->lmt & LMT_32Gb)
2285 else if (phba->lmt & LMT_16Gb)
2287 else if (phba->lmt & LMT_10Gb)
2289 else if (phba->lmt & LMT_8Gb)
2291 else if (phba->lmt & LMT_4Gb)
2293 else if (phba->lmt & LMT_2Gb)
2295 else if (phba->lmt & LMT_1Gb)
2303 case PCI_DEVICE_ID_FIREFLY:
2304 m = (typeof(m)){"LP6000", "PCI",
2305 "Obsolete, Unsupported Fibre Channel Adapter"};
2307 case PCI_DEVICE_ID_SUPERFLY:
2308 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2309 m = (typeof(m)){"LP7000", "PCI", ""};
2311 m = (typeof(m)){"LP7000E", "PCI", ""};
2312 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2314 case PCI_DEVICE_ID_DRAGONFLY:
2315 m = (typeof(m)){"LP8000", "PCI",
2316 "Obsolete, Unsupported Fibre Channel Adapter"};
2318 case PCI_DEVICE_ID_CENTAUR:
2319 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2320 m = (typeof(m)){"LP9002", "PCI", ""};
2322 m = (typeof(m)){"LP9000", "PCI", ""};
2323 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2325 case PCI_DEVICE_ID_RFLY:
2326 m = (typeof(m)){"LP952", "PCI",
2327 "Obsolete, Unsupported Fibre Channel Adapter"};
2329 case PCI_DEVICE_ID_PEGASUS:
2330 m = (typeof(m)){"LP9802", "PCI-X",
2331 "Obsolete, Unsupported Fibre Channel Adapter"};
2333 case PCI_DEVICE_ID_THOR:
2334 m = (typeof(m)){"LP10000", "PCI-X",
2335 "Obsolete, Unsupported Fibre Channel Adapter"};
2337 case PCI_DEVICE_ID_VIPER:
2338 m = (typeof(m)){"LPX1000", "PCI-X",
2339 "Obsolete, Unsupported Fibre Channel Adapter"};
2341 case PCI_DEVICE_ID_PFLY:
2342 m = (typeof(m)){"LP982", "PCI-X",
2343 "Obsolete, Unsupported Fibre Channel Adapter"};
2345 case PCI_DEVICE_ID_TFLY:
2346 m = (typeof(m)){"LP1050", "PCI-X",
2347 "Obsolete, Unsupported Fibre Channel Adapter"};
2349 case PCI_DEVICE_ID_HELIOS:
2350 m = (typeof(m)){"LP11000", "PCI-X2",
2351 "Obsolete, Unsupported Fibre Channel Adapter"};
2353 case PCI_DEVICE_ID_HELIOS_SCSP:
2354 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2355 "Obsolete, Unsupported Fibre Channel Adapter"};
2357 case PCI_DEVICE_ID_HELIOS_DCSP:
2358 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2359 "Obsolete, Unsupported Fibre Channel Adapter"};
2361 case PCI_DEVICE_ID_NEPTUNE:
2362 m = (typeof(m)){"LPe1000", "PCIe",
2363 "Obsolete, Unsupported Fibre Channel Adapter"};
2365 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2366 m = (typeof(m)){"LPe1000-SP", "PCIe",
2367 "Obsolete, Unsupported Fibre Channel Adapter"};
2369 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2370 m = (typeof(m)){"LPe1002-SP", "PCIe",
2371 "Obsolete, Unsupported Fibre Channel Adapter"};
2373 case PCI_DEVICE_ID_BMID:
2374 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2376 case PCI_DEVICE_ID_BSMB:
2377 m = (typeof(m)){"LP111", "PCI-X2",
2378 "Obsolete, Unsupported Fibre Channel Adapter"};
2380 case PCI_DEVICE_ID_ZEPHYR:
2381 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2383 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2384 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2386 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2387 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2390 case PCI_DEVICE_ID_ZMID:
2391 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2393 case PCI_DEVICE_ID_ZSMB:
2394 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2396 case PCI_DEVICE_ID_LP101:
2397 m = (typeof(m)){"LP101", "PCI-X",
2398 "Obsolete, Unsupported Fibre Channel Adapter"};
2400 case PCI_DEVICE_ID_LP10000S:
2401 m = (typeof(m)){"LP10000-S", "PCI",
2402 "Obsolete, Unsupported Fibre Channel Adapter"};
2404 case PCI_DEVICE_ID_LP11000S:
2405 m = (typeof(m)){"LP11000-S", "PCI-X2",
2406 "Obsolete, Unsupported Fibre Channel Adapter"};
2408 case PCI_DEVICE_ID_LPE11000S:
2409 m = (typeof(m)){"LPe11000-S", "PCIe",
2410 "Obsolete, Unsupported Fibre Channel Adapter"};
2412 case PCI_DEVICE_ID_SAT:
2413 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2415 case PCI_DEVICE_ID_SAT_MID:
2416 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2418 case PCI_DEVICE_ID_SAT_SMB:
2419 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2421 case PCI_DEVICE_ID_SAT_DCSP:
2422 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2424 case PCI_DEVICE_ID_SAT_SCSP:
2425 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2427 case PCI_DEVICE_ID_SAT_S:
2428 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2430 case PCI_DEVICE_ID_HORNET:
2431 m = (typeof(m)){"LP21000", "PCIe",
2432 "Obsolete, Unsupported FCoE Adapter"};
2435 case PCI_DEVICE_ID_PROTEUS_VF:
2436 m = (typeof(m)){"LPev12000", "PCIe IOV",
2437 "Obsolete, Unsupported Fibre Channel Adapter"};
2439 case PCI_DEVICE_ID_PROTEUS_PF:
2440 m = (typeof(m)){"LPev12000", "PCIe IOV",
2441 "Obsolete, Unsupported Fibre Channel Adapter"};
2443 case PCI_DEVICE_ID_PROTEUS_S:
2444 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2445 "Obsolete, Unsupported Fibre Channel Adapter"};
2447 case PCI_DEVICE_ID_TIGERSHARK:
2449 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2451 case PCI_DEVICE_ID_TOMCAT:
2453 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2455 case PCI_DEVICE_ID_FALCON:
2456 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2457 "EmulexSecure Fibre"};
2459 case PCI_DEVICE_ID_BALIUS:
2460 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2461 "Obsolete, Unsupported Fibre Channel Adapter"};
2463 case PCI_DEVICE_ID_LANCER_FC:
2464 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2466 case PCI_DEVICE_ID_LANCER_FC_VF:
2467 m = (typeof(m)){"LPe16000", "PCIe",
2468 "Obsolete, Unsupported Fibre Channel Adapter"};
2470 case PCI_DEVICE_ID_LANCER_FCOE:
2472 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2474 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2476 m = (typeof(m)){"OCe15100", "PCIe",
2477 "Obsolete, Unsupported FCoE"};
2479 case PCI_DEVICE_ID_LANCER_G6_FC:
2480 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2482 case PCI_DEVICE_ID_LANCER_G7_FC:
2483 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2485 case PCI_DEVICE_ID_SKYHAWK:
2486 case PCI_DEVICE_ID_SKYHAWK_VF:
2488 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2491 m = (typeof(m)){"Unknown", "", ""};
2495 if (mdp && mdp[0] == '\0')
2496 snprintf(mdp, 79,"%s", m.name);
2498 * oneConnect hba requires special processing, they are all initiators
2499 * and we put the port number on the end
2501 if (descp && descp[0] == '\0') {
2503 snprintf(descp, 255,
2504 "Emulex OneConnect %s, %s Initiator %s",
2507 else if (max_speed == 0)
2508 snprintf(descp, 255,
2510 m.name, m.bus, m.function);
2512 snprintf(descp, 255,
2513 "Emulex %s %d%s %s %s",
2514 m.name, max_speed, (GE) ? "GE" : "Gb",
2520 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2521 * @phba: pointer to lpfc hba data structure.
2522 * @pring: pointer to a IOCB ring.
2523 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2525 * This routine posts a given number of IOCBs with the associated DMA buffer
2526 * descriptors specified by the cnt argument to the given IOCB ring.
2529 * The number of IOCBs NOT able to be posted to the IOCB ring.
2532 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2535 struct lpfc_iocbq *iocb;
2536 struct lpfc_dmabuf *mp1, *mp2;
2538 cnt += pring->missbufcnt;
2540 /* While there are buffers to post */
2542 /* Allocate buffer for command iocb */
2543 iocb = lpfc_sli_get_iocbq(phba);
2545 pring->missbufcnt = cnt;
2550 /* 2 buffers can be posted per command */
2551 /* Allocate buffer to post */
2552 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2554 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2555 if (!mp1 || !mp1->virt) {
2557 lpfc_sli_release_iocbq(phba, iocb);
2558 pring->missbufcnt = cnt;
2562 INIT_LIST_HEAD(&mp1->list);
2563 /* Allocate buffer to post */
2565 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2567 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2569 if (!mp2 || !mp2->virt) {
2571 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2573 lpfc_sli_release_iocbq(phba, iocb);
2574 pring->missbufcnt = cnt;
2578 INIT_LIST_HEAD(&mp2->list);
2583 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2584 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2585 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2586 icmd->ulpBdeCount = 1;
2589 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2590 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2591 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2593 icmd->ulpBdeCount = 2;
2596 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2599 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2601 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2605 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2609 lpfc_sli_release_iocbq(phba, iocb);
2610 pring->missbufcnt = cnt;
2613 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2615 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2617 pring->missbufcnt = 0;
2622 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2623 * @phba: pointer to lpfc hba data structure.
2625 * This routine posts initial receive IOCB buffers to the ELS ring. The
2626 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2627 * set to 64 IOCBs. SLI3 only.
2630 * 0 - success (currently always success)
2633 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2635 struct lpfc_sli *psli = &phba->sli;
2637 /* Ring 0, ELS / CT buffers */
2638 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2639 /* Ring 2 - FCP no buffers needed */
2644 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2647 * lpfc_sha_init - Set up initial array of hash table entries
2648 * @HashResultPointer: pointer to an array as hash table.
2650 * This routine sets up the initial values to the array of hash table entries
2654 lpfc_sha_init(uint32_t * HashResultPointer)
2656 HashResultPointer[0] = 0x67452301;
2657 HashResultPointer[1] = 0xEFCDAB89;
2658 HashResultPointer[2] = 0x98BADCFE;
2659 HashResultPointer[3] = 0x10325476;
2660 HashResultPointer[4] = 0xC3D2E1F0;
2664 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2665 * @HashResultPointer: pointer to an initial/result hash table.
2666 * @HashWorkingPointer: pointer to an working hash table.
2668 * This routine iterates an initial hash table pointed by @HashResultPointer
2669 * with the values from the working hash table pointeed by @HashWorkingPointer.
2670 * The results are putting back to the initial hash table, returned through
2671 * the @HashResultPointer as the result hash table.
2674 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2678 uint32_t A, B, C, D, E;
2681 HashWorkingPointer[t] =
2683 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2685 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2686 } while (++t <= 79);
2688 A = HashResultPointer[0];
2689 B = HashResultPointer[1];
2690 C = HashResultPointer[2];
2691 D = HashResultPointer[3];
2692 E = HashResultPointer[4];
2696 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2697 } else if (t < 40) {
2698 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2699 } else if (t < 60) {
2700 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2702 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2704 TEMP += S(5, A) + E + HashWorkingPointer[t];
2710 } while (++t <= 79);
2712 HashResultPointer[0] += A;
2713 HashResultPointer[1] += B;
2714 HashResultPointer[2] += C;
2715 HashResultPointer[3] += D;
2716 HashResultPointer[4] += E;
2721 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2722 * @RandomChallenge: pointer to the entry of host challenge random number array.
2723 * @HashWorking: pointer to the entry of the working hash array.
2725 * This routine calculates the working hash array referred by @HashWorking
2726 * from the challenge random numbers associated with the host, referred by
2727 * @RandomChallenge. The result is put into the entry of the working hash
2728 * array and returned by reference through @HashWorking.
2731 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2733 *HashWorking = (*RandomChallenge ^ *HashWorking);
2737 * lpfc_hba_init - Perform special handling for LC HBA initialization
2738 * @phba: pointer to lpfc hba data structure.
2739 * @hbainit: pointer to an array of unsigned 32-bit integers.
2741 * This routine performs the special handling for LC HBA initialization.
2744 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2747 uint32_t *HashWorking;
2748 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2750 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2754 HashWorking[0] = HashWorking[78] = *pwwnn++;
2755 HashWorking[1] = HashWorking[79] = *pwwnn;
2757 for (t = 0; t < 7; t++)
2758 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2760 lpfc_sha_init(hbainit);
2761 lpfc_sha_iterate(hbainit, HashWorking);
2766 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2767 * @vport: pointer to a virtual N_Port data structure.
2769 * This routine performs the necessary cleanups before deleting the @vport.
2770 * It invokes the discovery state machine to perform necessary state
2771 * transitions and to release the ndlps associated with the @vport. Note,
2772 * the physical port is treated as @vport 0.
2775 lpfc_cleanup(struct lpfc_vport *vport)
2777 struct lpfc_hba *phba = vport->phba;
2778 struct lpfc_nodelist *ndlp, *next_ndlp;
2781 if (phba->link_state > LPFC_LINK_DOWN)
2782 lpfc_port_link_failure(vport);
2784 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2785 if (!NLP_CHK_NODE_ACT(ndlp)) {
2786 ndlp = lpfc_enable_node(vport, ndlp,
2787 NLP_STE_UNUSED_NODE);
2790 spin_lock_irq(&phba->ndlp_lock);
2791 NLP_SET_FREE_REQ(ndlp);
2792 spin_unlock_irq(&phba->ndlp_lock);
2793 /* Trigger the release of the ndlp memory */
2797 spin_lock_irq(&phba->ndlp_lock);
2798 if (NLP_CHK_FREE_REQ(ndlp)) {
2799 /* The ndlp should not be in memory free mode already */
2800 spin_unlock_irq(&phba->ndlp_lock);
2803 /* Indicate request for freeing ndlp memory */
2804 NLP_SET_FREE_REQ(ndlp);
2805 spin_unlock_irq(&phba->ndlp_lock);
2807 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2808 ndlp->nlp_DID == Fabric_DID) {
2809 /* Just free up ndlp with Fabric_DID for vports */
2814 /* take care of nodes in unused state before the state
2815 * machine taking action.
2817 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2822 if (ndlp->nlp_type & NLP_FABRIC)
2823 lpfc_disc_state_machine(vport, ndlp, NULL,
2824 NLP_EVT_DEVICE_RECOVERY);
2826 lpfc_disc_state_machine(vport, ndlp, NULL,
2830 /* At this point, ALL ndlp's should be gone
2831 * because of the previous NLP_EVT_DEVICE_RM.
2832 * Lets wait for this to happen, if needed.
2834 while (!list_empty(&vport->fc_nodes)) {
2836 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2837 "0233 Nodelist not empty\n");
2838 list_for_each_entry_safe(ndlp, next_ndlp,
2839 &vport->fc_nodes, nlp_listp) {
2840 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2842 "0282 did:x%x ndlp:x%px "
2843 "usgmap:x%x refcnt:%d\n",
2844 ndlp->nlp_DID, (void *)ndlp,
2846 kref_read(&ndlp->kref));
2851 /* Wait for any activity on ndlps to settle */
2854 lpfc_cleanup_vports_rrqs(vport, NULL);
2858 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2859 * @vport: pointer to a virtual N_Port data structure.
2861 * This routine stops all the timers associated with a @vport. This function
2862 * is invoked before disabling or deleting a @vport. Note that the physical
2863 * port is treated as @vport 0.
2866 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2868 del_timer_sync(&vport->els_tmofunc);
2869 del_timer_sync(&vport->delayed_disc_tmo);
2870 lpfc_can_disctmo(vport);
2875 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2876 * @phba: pointer to lpfc hba data structure.
2878 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2879 * caller of this routine should already hold the host lock.
2882 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2884 /* Clear pending FCF rediscovery wait flag */
2885 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2887 /* Now, try to stop the timer */
2888 del_timer(&phba->fcf.redisc_wait);
2892 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2893 * @phba: pointer to lpfc hba data structure.
2895 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2896 * checks whether the FCF rediscovery wait timer is pending with the host
2897 * lock held before proceeding with disabling the timer and clearing the
2898 * wait timer pendig flag.
2901 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2903 spin_lock_irq(&phba->hbalock);
2904 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2905 /* FCF rediscovery timer already fired or stopped */
2906 spin_unlock_irq(&phba->hbalock);
2909 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2910 /* Clear failover in progress flags */
2911 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2912 spin_unlock_irq(&phba->hbalock);
2916 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2917 * @phba: pointer to lpfc hba data structure.
2919 * This routine stops all the timers associated with a HBA. This function is
2920 * invoked before either putting a HBA offline or unloading the driver.
2923 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2926 lpfc_stop_vport_timers(phba->pport);
2927 cancel_delayed_work_sync(&phba->eq_delay_work);
2928 del_timer_sync(&phba->sli.mbox_tmo);
2929 del_timer_sync(&phba->fabric_block_timer);
2930 del_timer_sync(&phba->eratt_poll);
2931 del_timer_sync(&phba->hb_tmofunc);
2932 if (phba->sli_rev == LPFC_SLI_REV4) {
2933 del_timer_sync(&phba->rrq_tmr);
2934 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2936 phba->hb_outstanding = 0;
2938 switch (phba->pci_dev_grp) {
2939 case LPFC_PCI_DEV_LP:
2940 /* Stop any LightPulse device specific driver timers */
2941 del_timer_sync(&phba->fcp_poll_timer);
2943 case LPFC_PCI_DEV_OC:
2944 /* Stop any OneConnect device specific driver timers */
2945 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2949 "0297 Invalid device group (x%x)\n",
2957 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2958 * @phba: pointer to lpfc hba data structure.
2960 * This routine marks a HBA's management interface as blocked. Once the HBA's
2961 * management interface is marked as blocked, all the user space access to
2962 * the HBA, whether they are from sysfs interface or libdfc interface will
2963 * all be blocked. The HBA is set to block the management interface when the
2964 * driver prepares the HBA interface for online or offline.
2967 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2969 unsigned long iflag;
2970 uint8_t actcmd = MBX_HEARTBEAT;
2971 unsigned long timeout;
2973 spin_lock_irqsave(&phba->hbalock, iflag);
2974 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2975 spin_unlock_irqrestore(&phba->hbalock, iflag);
2976 if (mbx_action == LPFC_MBX_NO_WAIT)
2978 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2979 spin_lock_irqsave(&phba->hbalock, iflag);
2980 if (phba->sli.mbox_active) {
2981 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
2982 /* Determine how long we might wait for the active mailbox
2983 * command to be gracefully completed by firmware.
2985 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2986 phba->sli.mbox_active) * 1000) + jiffies;
2988 spin_unlock_irqrestore(&phba->hbalock, iflag);
2990 /* Wait for the outstnading mailbox command to complete */
2991 while (phba->sli.mbox_active) {
2992 /* Check active mailbox complete status every 2ms */
2994 if (time_after(jiffies, timeout)) {
2995 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2996 "2813 Mgmt IO is Blocked %x "
2997 "- mbox cmd %x still active\n",
2998 phba->sli.sli_flag, actcmd);
3005 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3006 * @phba: pointer to lpfc hba data structure.
3008 * Allocate RPIs for all active remote nodes. This is needed whenever
3009 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3010 * is to fixup the temporary rpi assignments.
3013 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3015 struct lpfc_nodelist *ndlp, *next_ndlp;
3016 struct lpfc_vport **vports;
3018 unsigned long flags;
3020 if (phba->sli_rev != LPFC_SLI_REV4)
3023 vports = lpfc_create_vport_work_array(phba);
3027 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3028 if (vports[i]->load_flag & FC_UNLOADING)
3031 list_for_each_entry_safe(ndlp, next_ndlp,
3032 &vports[i]->fc_nodes,
3034 if (!NLP_CHK_NODE_ACT(ndlp))
3036 rpi = lpfc_sli4_alloc_rpi(phba);
3037 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3038 spin_lock_irqsave(&phba->ndlp_lock, flags);
3039 NLP_CLR_NODE_ACT(ndlp);
3040 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3043 ndlp->nlp_rpi = rpi;
3044 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3045 LOG_NODE | LOG_DISCOVERY,
3046 "0009 Assign RPI x%x to ndlp x%px "
3047 "DID:x%06x flg:x%x map:x%x\n",
3048 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3049 ndlp->nlp_flag, ndlp->nlp_usg_map);
3052 lpfc_destroy_vport_work_array(phba, vports);
3056 * lpfc_create_expedite_pool - create expedite pool
3057 * @phba: pointer to lpfc hba data structure.
3059 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3060 * to expedite pool. Mark them as expedite.
3062 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3064 struct lpfc_sli4_hdw_queue *qp;
3065 struct lpfc_io_buf *lpfc_ncmd;
3066 struct lpfc_io_buf *lpfc_ncmd_next;
3067 struct lpfc_epd_pool *epd_pool;
3068 unsigned long iflag;
3070 epd_pool = &phba->epd_pool;
3071 qp = &phba->sli4_hba.hdwq[0];
3073 spin_lock_init(&epd_pool->lock);
3074 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3075 spin_lock(&epd_pool->lock);
3076 INIT_LIST_HEAD(&epd_pool->list);
3077 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3078 &qp->lpfc_io_buf_list_put, list) {
3079 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3080 lpfc_ncmd->expedite = true;
3083 if (epd_pool->count >= XRI_BATCH)
3086 spin_unlock(&epd_pool->lock);
3087 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3091 * lpfc_destroy_expedite_pool - destroy expedite pool
3092 * @phba: pointer to lpfc hba data structure.
3094 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3095 * of HWQ 0. Clear the mark.
3097 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3099 struct lpfc_sli4_hdw_queue *qp;
3100 struct lpfc_io_buf *lpfc_ncmd;
3101 struct lpfc_io_buf *lpfc_ncmd_next;
3102 struct lpfc_epd_pool *epd_pool;
3103 unsigned long iflag;
3105 epd_pool = &phba->epd_pool;
3106 qp = &phba->sli4_hba.hdwq[0];
3108 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3109 spin_lock(&epd_pool->lock);
3110 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3111 &epd_pool->list, list) {
3112 list_move_tail(&lpfc_ncmd->list,
3113 &qp->lpfc_io_buf_list_put);
3114 lpfc_ncmd->flags = false;
3118 spin_unlock(&epd_pool->lock);
3119 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3123 * lpfc_create_multixri_pools - create multi-XRI pools
3124 * @phba: pointer to lpfc hba data structure.
3126 * This routine initialize public, private per HWQ. Then, move XRIs from
3127 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3130 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3135 struct lpfc_io_buf *lpfc_ncmd;
3136 struct lpfc_io_buf *lpfc_ncmd_next;
3137 unsigned long iflag;
3138 struct lpfc_sli4_hdw_queue *qp;
3139 struct lpfc_multixri_pool *multixri_pool;
3140 struct lpfc_pbl_pool *pbl_pool;
3141 struct lpfc_pvt_pool *pvt_pool;
3143 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3144 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3145 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3146 phba->sli4_hba.io_xri_cnt);
3148 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3149 lpfc_create_expedite_pool(phba);
3151 hwq_count = phba->cfg_hdw_queue;
3152 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3154 for (i = 0; i < hwq_count; i++) {
3155 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3157 if (!multixri_pool) {
3158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3159 "1238 Failed to allocate memory for "
3162 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3163 lpfc_destroy_expedite_pool(phba);
3167 qp = &phba->sli4_hba.hdwq[j];
3168 kfree(qp->p_multixri_pool);
3171 phba->cfg_xri_rebalancing = 0;
3175 qp = &phba->sli4_hba.hdwq[i];
3176 qp->p_multixri_pool = multixri_pool;
3178 multixri_pool->xri_limit = count_per_hwq;
3179 multixri_pool->rrb_next_hwqid = i;
3181 /* Deal with public free xri pool */
3182 pbl_pool = &multixri_pool->pbl_pool;
3183 spin_lock_init(&pbl_pool->lock);
3184 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3185 spin_lock(&pbl_pool->lock);
3186 INIT_LIST_HEAD(&pbl_pool->list);
3187 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3188 &qp->lpfc_io_buf_list_put, list) {
3189 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3193 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3194 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3195 pbl_pool->count, i);
3196 spin_unlock(&pbl_pool->lock);
3197 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3199 /* Deal with private free xri pool */
3200 pvt_pool = &multixri_pool->pvt_pool;
3201 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3202 pvt_pool->low_watermark = XRI_BATCH;
3203 spin_lock_init(&pvt_pool->lock);
3204 spin_lock_irqsave(&pvt_pool->lock, iflag);
3205 INIT_LIST_HEAD(&pvt_pool->list);
3206 pvt_pool->count = 0;
3207 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3212 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3213 * @phba: pointer to lpfc hba data structure.
3215 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3217 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3221 struct lpfc_io_buf *lpfc_ncmd;
3222 struct lpfc_io_buf *lpfc_ncmd_next;
3223 unsigned long iflag;
3224 struct lpfc_sli4_hdw_queue *qp;
3225 struct lpfc_multixri_pool *multixri_pool;
3226 struct lpfc_pbl_pool *pbl_pool;
3227 struct lpfc_pvt_pool *pvt_pool;
3229 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3230 lpfc_destroy_expedite_pool(phba);
3232 if (!(phba->pport->load_flag & FC_UNLOADING))
3233 lpfc_sli_flush_io_rings(phba);
3235 hwq_count = phba->cfg_hdw_queue;
3237 for (i = 0; i < hwq_count; i++) {
3238 qp = &phba->sli4_hba.hdwq[i];
3239 multixri_pool = qp->p_multixri_pool;
3243 qp->p_multixri_pool = NULL;
3245 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3247 /* Deal with public free xri pool */
3248 pbl_pool = &multixri_pool->pbl_pool;
3249 spin_lock(&pbl_pool->lock);
3251 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3252 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3253 pbl_pool->count, i);
3255 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3256 &pbl_pool->list, list) {
3257 list_move_tail(&lpfc_ncmd->list,
3258 &qp->lpfc_io_buf_list_put);
3263 INIT_LIST_HEAD(&pbl_pool->list);
3264 pbl_pool->count = 0;
3266 spin_unlock(&pbl_pool->lock);
3268 /* Deal with private free xri pool */
3269 pvt_pool = &multixri_pool->pvt_pool;
3270 spin_lock(&pvt_pool->lock);
3272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3273 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3274 pvt_pool->count, i);
3276 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3277 &pvt_pool->list, list) {
3278 list_move_tail(&lpfc_ncmd->list,
3279 &qp->lpfc_io_buf_list_put);
3284 INIT_LIST_HEAD(&pvt_pool->list);
3285 pvt_pool->count = 0;
3287 spin_unlock(&pvt_pool->lock);
3288 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3290 kfree(multixri_pool);
3295 * lpfc_online - Initialize and bring a HBA online
3296 * @phba: pointer to lpfc hba data structure.
3298 * This routine initializes the HBA and brings a HBA online. During this
3299 * process, the management interface is blocked to prevent user space access
3300 * to the HBA interfering with the driver initialization.
3307 lpfc_online(struct lpfc_hba *phba)
3309 struct lpfc_vport *vport;
3310 struct lpfc_vport **vports;
3312 bool vpis_cleared = false;
3316 vport = phba->pport;
3318 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3321 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3322 "0458 Bring Adapter online\n");
3324 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3326 if (phba->sli_rev == LPFC_SLI_REV4) {
3327 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3328 lpfc_unblock_mgmt_io(phba);
3331 spin_lock_irq(&phba->hbalock);
3332 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3333 vpis_cleared = true;
3334 spin_unlock_irq(&phba->hbalock);
3336 /* Reestablish the local initiator port.
3337 * The offline process destroyed the previous lport.
3339 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3340 !phba->nvmet_support) {
3341 error = lpfc_nvme_create_localport(phba->pport);
3343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3344 "6132 NVME restore reg failed "
3345 "on nvmei error x%x\n", error);
3348 lpfc_sli_queue_init(phba);
3349 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3350 lpfc_unblock_mgmt_io(phba);
3355 vports = lpfc_create_vport_work_array(phba);
3356 if (vports != NULL) {
3357 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3358 struct Scsi_Host *shost;
3359 shost = lpfc_shost_from_vport(vports[i]);
3360 spin_lock_irq(shost->host_lock);
3361 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3362 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3363 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3364 if (phba->sli_rev == LPFC_SLI_REV4) {
3365 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3366 if ((vpis_cleared) &&
3367 (vports[i]->port_type !=
3368 LPFC_PHYSICAL_PORT))
3371 spin_unlock_irq(shost->host_lock);
3374 lpfc_destroy_vport_work_array(phba, vports);
3376 if (phba->cfg_xri_rebalancing)
3377 lpfc_create_multixri_pools(phba);
3379 lpfc_cpuhp_add(phba);
3381 lpfc_unblock_mgmt_io(phba);
3386 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3387 * @phba: pointer to lpfc hba data structure.
3389 * This routine marks a HBA's management interface as not blocked. Once the
3390 * HBA's management interface is marked as not blocked, all the user space
3391 * access to the HBA, whether they are from sysfs interface or libdfc
3392 * interface will be allowed. The HBA is set to block the management interface
3393 * when the driver prepares the HBA interface for online or offline and then
3394 * set to unblock the management interface afterwards.
3397 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3399 unsigned long iflag;
3401 spin_lock_irqsave(&phba->hbalock, iflag);
3402 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3403 spin_unlock_irqrestore(&phba->hbalock, iflag);
3407 * lpfc_offline_prep - Prepare a HBA to be brought offline
3408 * @phba: pointer to lpfc hba data structure.
3410 * This routine is invoked to prepare a HBA to be brought offline. It performs
3411 * unregistration login to all the nodes on all vports and flushes the mailbox
3412 * queue to make it ready to be brought offline.
3415 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3417 struct lpfc_vport *vport = phba->pport;
3418 struct lpfc_nodelist *ndlp, *next_ndlp;
3419 struct lpfc_vport **vports;
3420 struct Scsi_Host *shost;
3423 if (vport->fc_flag & FC_OFFLINE_MODE)
3426 lpfc_block_mgmt_io(phba, mbx_action);
3428 lpfc_linkdown(phba);
3430 /* Issue an unreg_login to all nodes on all vports */
3431 vports = lpfc_create_vport_work_array(phba);
3432 if (vports != NULL) {
3433 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3434 if (vports[i]->load_flag & FC_UNLOADING)
3436 shost = lpfc_shost_from_vport(vports[i]);
3437 spin_lock_irq(shost->host_lock);
3438 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3439 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3440 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3441 spin_unlock_irq(shost->host_lock);
3443 shost = lpfc_shost_from_vport(vports[i]);
3444 list_for_each_entry_safe(ndlp, next_ndlp,
3445 &vports[i]->fc_nodes,
3447 if ((!NLP_CHK_NODE_ACT(ndlp)) ||
3448 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3449 /* Driver must assume RPI is invalid for
3450 * any unused or inactive node.
3452 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3456 if (ndlp->nlp_type & NLP_FABRIC) {
3457 lpfc_disc_state_machine(vports[i], ndlp,
3458 NULL, NLP_EVT_DEVICE_RECOVERY);
3459 lpfc_disc_state_machine(vports[i], ndlp,
3460 NULL, NLP_EVT_DEVICE_RM);
3462 spin_lock_irq(shost->host_lock);
3463 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3464 spin_unlock_irq(shost->host_lock);
3466 * Whenever an SLI4 port goes offline, free the
3467 * RPI. Get a new RPI when the adapter port
3468 * comes back online.
3470 if (phba->sli_rev == LPFC_SLI_REV4) {
3471 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3472 LOG_NODE | LOG_DISCOVERY,
3473 "0011 Free RPI x%x on "
3474 "ndlp:x%px did x%x "
3476 ndlp->nlp_rpi, ndlp,
3479 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3480 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3482 lpfc_unreg_rpi(vports[i], ndlp);
3486 lpfc_destroy_vport_work_array(phba, vports);
3488 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3491 flush_workqueue(phba->wq);
3495 * lpfc_offline - Bring a HBA offline
3496 * @phba: pointer to lpfc hba data structure.
3498 * This routine actually brings a HBA offline. It stops all the timers
3499 * associated with the HBA, brings down the SLI layer, and eventually
3500 * marks the HBA as in offline state for the upper layer protocol.
3503 lpfc_offline(struct lpfc_hba *phba)
3505 struct Scsi_Host *shost;
3506 struct lpfc_vport **vports;
3509 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3512 /* stop port and all timers associated with this hba */
3513 lpfc_stop_port(phba);
3515 /* Tear down the local and target port registrations. The
3516 * nvme transports need to cleanup.
3518 lpfc_nvmet_destroy_targetport(phba);
3519 lpfc_nvme_destroy_localport(phba->pport);
3521 vports = lpfc_create_vport_work_array(phba);
3523 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3524 lpfc_stop_vport_timers(vports[i]);
3525 lpfc_destroy_vport_work_array(phba, vports);
3526 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3527 "0460 Bring Adapter offline\n");
3528 /* Bring down the SLI Layer and cleanup. The HBA is offline
3530 lpfc_sli_hba_down(phba);
3531 spin_lock_irq(&phba->hbalock);
3533 spin_unlock_irq(&phba->hbalock);
3534 vports = lpfc_create_vport_work_array(phba);
3536 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3537 shost = lpfc_shost_from_vport(vports[i]);
3538 spin_lock_irq(shost->host_lock);
3539 vports[i]->work_port_events = 0;
3540 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3541 spin_unlock_irq(shost->host_lock);
3543 lpfc_destroy_vport_work_array(phba, vports);
3544 __lpfc_cpuhp_remove(phba);
3546 if (phba->cfg_xri_rebalancing)
3547 lpfc_destroy_multixri_pools(phba);
3551 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3552 * @phba: pointer to lpfc hba data structure.
3554 * This routine is to free all the SCSI buffers and IOCBs from the driver
3555 * list back to kernel. It is called from lpfc_pci_remove_one to free
3556 * the internal resources before the device is removed from the system.
3559 lpfc_scsi_free(struct lpfc_hba *phba)
3561 struct lpfc_io_buf *sb, *sb_next;
3563 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3566 spin_lock_irq(&phba->hbalock);
3568 /* Release all the lpfc_scsi_bufs maintained by this host. */
3570 spin_lock(&phba->scsi_buf_list_put_lock);
3571 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3573 list_del(&sb->list);
3574 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3577 phba->total_scsi_bufs--;
3579 spin_unlock(&phba->scsi_buf_list_put_lock);
3581 spin_lock(&phba->scsi_buf_list_get_lock);
3582 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3584 list_del(&sb->list);
3585 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3588 phba->total_scsi_bufs--;
3590 spin_unlock(&phba->scsi_buf_list_get_lock);
3591 spin_unlock_irq(&phba->hbalock);
3595 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3596 * @phba: pointer to lpfc hba data structure.
3598 * This routine is to free all the IO buffers and IOCBs from the driver
3599 * list back to kernel. It is called from lpfc_pci_remove_one to free
3600 * the internal resources before the device is removed from the system.
3603 lpfc_io_free(struct lpfc_hba *phba)
3605 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
3606 struct lpfc_sli4_hdw_queue *qp;
3609 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3610 qp = &phba->sli4_hba.hdwq[idx];
3611 /* Release all the lpfc_nvme_bufs maintained by this host. */
3612 spin_lock(&qp->io_buf_list_put_lock);
3613 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3614 &qp->lpfc_io_buf_list_put,
3616 list_del(&lpfc_ncmd->list);
3618 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3619 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3620 if (phba->cfg_xpsgl && !phba->nvmet_support)
3621 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3622 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3624 qp->total_io_bufs--;
3626 spin_unlock(&qp->io_buf_list_put_lock);
3628 spin_lock(&qp->io_buf_list_get_lock);
3629 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3630 &qp->lpfc_io_buf_list_get,
3632 list_del(&lpfc_ncmd->list);
3634 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3635 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3636 if (phba->cfg_xpsgl && !phba->nvmet_support)
3637 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3638 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3640 qp->total_io_bufs--;
3642 spin_unlock(&qp->io_buf_list_get_lock);
3647 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3648 * @phba: pointer to lpfc hba data structure.
3650 * This routine first calculates the sizes of the current els and allocated
3651 * scsi sgl lists, and then goes through all sgls to updates the physical
3652 * XRIs assigned due to port function reset. During port initialization, the
3653 * current els and allocated scsi sgl lists are 0s.
3656 * 0 - successful (for now, it always returns 0)
3659 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3661 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3662 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3663 LIST_HEAD(els_sgl_list);
3667 * update on pci function's els xri-sgl list
3669 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3671 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3672 /* els xri-sgl expanded */
3673 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3674 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3675 "3157 ELS xri-sgl count increased from "
3676 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3678 /* allocate the additional els sgls */
3679 for (i = 0; i < xri_cnt; i++) {
3680 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3682 if (sglq_entry == NULL) {
3683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3684 "2562 Failure to allocate an "
3685 "ELS sgl entry:%d\n", i);
3689 sglq_entry->buff_type = GEN_BUFF_TYPE;
3690 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3692 if (sglq_entry->virt == NULL) {
3694 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3695 "2563 Failure to allocate an "
3696 "ELS mbuf:%d\n", i);
3700 sglq_entry->sgl = sglq_entry->virt;
3701 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3702 sglq_entry->state = SGL_FREED;
3703 list_add_tail(&sglq_entry->list, &els_sgl_list);
3705 spin_lock_irq(&phba->hbalock);
3706 spin_lock(&phba->sli4_hba.sgl_list_lock);
3707 list_splice_init(&els_sgl_list,
3708 &phba->sli4_hba.lpfc_els_sgl_list);
3709 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3710 spin_unlock_irq(&phba->hbalock);
3711 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3712 /* els xri-sgl shrinked */
3713 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3714 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3715 "3158 ELS xri-sgl count decreased from "
3716 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3718 spin_lock_irq(&phba->hbalock);
3719 spin_lock(&phba->sli4_hba.sgl_list_lock);
3720 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3722 /* release extra els sgls from list */
3723 for (i = 0; i < xri_cnt; i++) {
3724 list_remove_head(&els_sgl_list,
3725 sglq_entry, struct lpfc_sglq, list);
3727 __lpfc_mbuf_free(phba, sglq_entry->virt,
3732 list_splice_init(&els_sgl_list,
3733 &phba->sli4_hba.lpfc_els_sgl_list);
3734 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3735 spin_unlock_irq(&phba->hbalock);
3737 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3738 "3163 ELS xri-sgl count unchanged: %d\n",
3740 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3742 /* update xris to els sgls on the list */
3744 sglq_entry_next = NULL;
3745 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3746 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3747 lxri = lpfc_sli4_next_xritag(phba);
3748 if (lxri == NO_XRI) {
3749 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3750 "2400 Failed to allocate xri for "
3755 sglq_entry->sli4_lxritag = lxri;
3756 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3761 lpfc_free_els_sgl_list(phba);
3766 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3767 * @phba: pointer to lpfc hba data structure.
3769 * This routine first calculates the sizes of the current els and allocated
3770 * scsi sgl lists, and then goes through all sgls to updates the physical
3771 * XRIs assigned due to port function reset. During port initialization, the
3772 * current els and allocated scsi sgl lists are 0s.
3775 * 0 - successful (for now, it always returns 0)
3778 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3780 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3781 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3782 uint16_t nvmet_xri_cnt;
3783 LIST_HEAD(nvmet_sgl_list);
3787 * update on pci function's nvmet xri-sgl list
3789 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3791 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3792 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3793 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3794 /* els xri-sgl expanded */
3795 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3796 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3797 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3798 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3799 /* allocate the additional nvmet sgls */
3800 for (i = 0; i < xri_cnt; i++) {
3801 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3803 if (sglq_entry == NULL) {
3804 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3805 "6303 Failure to allocate an "
3806 "NVMET sgl entry:%d\n", i);
3810 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3811 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3813 if (sglq_entry->virt == NULL) {
3815 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3816 "6304 Failure to allocate an "
3817 "NVMET buf:%d\n", i);
3821 sglq_entry->sgl = sglq_entry->virt;
3822 memset(sglq_entry->sgl, 0,
3823 phba->cfg_sg_dma_buf_size);
3824 sglq_entry->state = SGL_FREED;
3825 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3827 spin_lock_irq(&phba->hbalock);
3828 spin_lock(&phba->sli4_hba.sgl_list_lock);
3829 list_splice_init(&nvmet_sgl_list,
3830 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3831 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3832 spin_unlock_irq(&phba->hbalock);
3833 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3834 /* nvmet xri-sgl shrunk */
3835 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3836 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3837 "6305 NVMET xri-sgl count decreased from "
3838 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3840 spin_lock_irq(&phba->hbalock);
3841 spin_lock(&phba->sli4_hba.sgl_list_lock);
3842 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3844 /* release extra nvmet sgls from list */
3845 for (i = 0; i < xri_cnt; i++) {
3846 list_remove_head(&nvmet_sgl_list,
3847 sglq_entry, struct lpfc_sglq, list);
3849 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3854 list_splice_init(&nvmet_sgl_list,
3855 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3856 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3857 spin_unlock_irq(&phba->hbalock);
3859 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3860 "6306 NVMET xri-sgl count unchanged: %d\n",
3862 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3864 /* update xris to nvmet sgls on the list */
3866 sglq_entry_next = NULL;
3867 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3868 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3869 lxri = lpfc_sli4_next_xritag(phba);
3870 if (lxri == NO_XRI) {
3871 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3872 "6307 Failed to allocate xri for "
3877 sglq_entry->sli4_lxritag = lxri;
3878 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3883 lpfc_free_nvmet_sgl_list(phba);
3888 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
3891 struct lpfc_sli4_hdw_queue *qp;
3892 struct lpfc_io_buf *lpfc_cmd;
3893 struct lpfc_io_buf *iobufp, *prev_iobufp;
3894 int idx, cnt, xri, inserted;
3897 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3898 qp = &phba->sli4_hba.hdwq[idx];
3899 spin_lock_irq(&qp->io_buf_list_get_lock);
3900 spin_lock(&qp->io_buf_list_put_lock);
3902 /* Take everything off the get and put lists */
3903 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
3904 list_splice(&qp->lpfc_io_buf_list_put, &blist);
3905 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
3906 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
3907 cnt += qp->get_io_bufs + qp->put_io_bufs;
3908 qp->get_io_bufs = 0;
3909 qp->put_io_bufs = 0;
3910 qp->total_io_bufs = 0;
3911 spin_unlock(&qp->io_buf_list_put_lock);
3912 spin_unlock_irq(&qp->io_buf_list_get_lock);
3916 * Take IO buffers off blist and put on cbuf sorted by XRI.
3917 * This is because POST_SGL takes a sequential range of XRIs
3918 * to post to the firmware.
3920 for (idx = 0; idx < cnt; idx++) {
3921 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
3925 list_add_tail(&lpfc_cmd->list, cbuf);
3928 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
3931 list_for_each_entry(iobufp, cbuf, list) {
3932 if (xri < iobufp->cur_iocbq.sli4_xritag) {
3934 list_add(&lpfc_cmd->list,
3935 &prev_iobufp->list);
3937 list_add(&lpfc_cmd->list, cbuf);
3941 prev_iobufp = iobufp;
3944 list_add_tail(&lpfc_cmd->list, cbuf);
3950 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
3952 struct lpfc_sli4_hdw_queue *qp;
3953 struct lpfc_io_buf *lpfc_cmd;
3956 qp = phba->sli4_hba.hdwq;
3958 while (!list_empty(cbuf)) {
3959 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3960 list_remove_head(cbuf, lpfc_cmd,
3961 struct lpfc_io_buf, list);
3965 qp = &phba->sli4_hba.hdwq[idx];
3966 lpfc_cmd->hdwq_no = idx;
3967 lpfc_cmd->hdwq = qp;
3968 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
3969 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
3970 spin_lock(&qp->io_buf_list_put_lock);
3971 list_add_tail(&lpfc_cmd->list,
3972 &qp->lpfc_io_buf_list_put);
3974 qp->total_io_bufs++;
3975 spin_unlock(&qp->io_buf_list_put_lock);
3982 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
3983 * @phba: pointer to lpfc hba data structure.
3985 * This routine first calculates the sizes of the current els and allocated
3986 * scsi sgl lists, and then goes through all sgls to updates the physical
3987 * XRIs assigned due to port function reset. During port initialization, the
3988 * current els and allocated scsi sgl lists are 0s.
3991 * 0 - successful (for now, it always returns 0)
3994 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
3996 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3997 uint16_t i, lxri, els_xri_cnt;
3998 uint16_t io_xri_cnt, io_xri_max;
3999 LIST_HEAD(io_sgl_list);
4003 * update on pci function's allocated nvme xri-sgl list
4006 /* maximum number of xris available for nvme buffers */
4007 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4008 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4009 phba->sli4_hba.io_xri_max = io_xri_max;
4011 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4012 "6074 Current allocated XRI sgl count:%d, "
4013 "maximum XRI count:%d\n",
4014 phba->sli4_hba.io_xri_cnt,
4015 phba->sli4_hba.io_xri_max);
4017 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4019 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4020 /* max nvme xri shrunk below the allocated nvme buffers */
4021 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4022 phba->sli4_hba.io_xri_max;
4023 /* release the extra allocated nvme buffers */
4024 for (i = 0; i < io_xri_cnt; i++) {
4025 list_remove_head(&io_sgl_list, lpfc_ncmd,
4026 struct lpfc_io_buf, list);
4028 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4030 lpfc_ncmd->dma_handle);
4034 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4037 /* update xris associated to remaining allocated nvme buffers */
4039 lpfc_ncmd_next = NULL;
4040 phba->sli4_hba.io_xri_cnt = cnt;
4041 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4042 &io_sgl_list, list) {
4043 lxri = lpfc_sli4_next_xritag(phba);
4044 if (lxri == NO_XRI) {
4045 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4046 "6075 Failed to allocate xri for "
4051 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4052 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4054 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4063 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4064 * @vport: The virtual port for which this call being executed.
4065 * @num_to_allocate: The requested number of buffers to allocate.
4067 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4068 * the nvme buffer contains all the necessary information needed to initiate
4069 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4070 * them on a list, it post them to the port by using SGL block post.
4073 * int - number of IO buffers that were allocated and posted.
4074 * 0 = failure, less than num_to_alloc is a partial failure.
4077 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4079 struct lpfc_io_buf *lpfc_ncmd;
4080 struct lpfc_iocbq *pwqeq;
4081 uint16_t iotag, lxri = 0;
4082 int bcnt, num_posted;
4083 LIST_HEAD(prep_nblist);
4084 LIST_HEAD(post_nblist);
4085 LIST_HEAD(nvme_nblist);
4087 phba->sli4_hba.io_xri_cnt = 0;
4088 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4089 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4093 * Get memory from the pci pool to map the virt space to
4094 * pci bus space for an I/O. The DMA buffer includes the
4095 * number of SGE's necessary to support the sg_tablesize.
4097 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4099 &lpfc_ncmd->dma_handle);
4100 if (!lpfc_ncmd->data) {
4105 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4106 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4109 * 4K Page alignment is CRITICAL to BlockGuard, double
4112 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4113 (((unsigned long)(lpfc_ncmd->data) &
4114 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4115 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
4116 "3369 Memory alignment err: "
4118 (unsigned long)lpfc_ncmd->data);
4119 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4121 lpfc_ncmd->dma_handle);
4127 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4129 lxri = lpfc_sli4_next_xritag(phba);
4130 if (lxri == NO_XRI) {
4131 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4132 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4136 pwqeq = &lpfc_ncmd->cur_iocbq;
4138 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4139 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4141 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4142 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4144 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
4145 "6121 Failed to allocate IOTAG for"
4146 " XRI:0x%x\n", lxri);
4147 lpfc_sli4_free_xri(phba, lxri);
4150 pwqeq->sli4_lxritag = lxri;
4151 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4152 pwqeq->context1 = lpfc_ncmd;
4154 /* Initialize local short-hand pointers. */
4155 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4156 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4157 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
4158 spin_lock_init(&lpfc_ncmd->buf_lock);
4160 /* add the nvme buffer to a post list */
4161 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4162 phba->sli4_hba.io_xri_cnt++;
4164 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4165 "6114 Allocate %d out of %d requested new NVME "
4166 "buffers\n", bcnt, num_to_alloc);
4168 /* post the list of nvme buffer sgls to port if available */
4169 if (!list_empty(&post_nblist))
4170 num_posted = lpfc_sli4_post_io_sgl_list(
4171 phba, &post_nblist, bcnt);
4179 lpfc_get_wwpn(struct lpfc_hba *phba)
4183 LPFC_MBOXQ_t *mboxq;
4186 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4189 return (uint64_t)-1;
4191 /* First get WWN of HBA instance */
4192 lpfc_read_nv(phba, mboxq);
4193 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4194 if (rc != MBX_SUCCESS) {
4195 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4196 "6019 Mailbox failed , mbxCmd x%x "
4197 "READ_NV, mbxStatus x%x\n",
4198 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4199 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4200 mempool_free(mboxq, phba->mbox_mem_pool);
4201 return (uint64_t) -1;
4204 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4205 /* wwn is WWPN of HBA instance */
4206 mempool_free(mboxq, phba->mbox_mem_pool);
4207 if (phba->sli_rev == LPFC_SLI_REV4)
4208 return be64_to_cpu(wwn);
4210 return rol64(wwn, 32);
4214 * lpfc_create_port - Create an FC port
4215 * @phba: pointer to lpfc hba data structure.
4216 * @instance: a unique integer ID to this FC port.
4217 * @dev: pointer to the device data structure.
4219 * This routine creates a FC port for the upper layer protocol. The FC port
4220 * can be created on top of either a physical port or a virtual port provided
4221 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4222 * and associates the FC port created before adding the shost into the SCSI
4226 * @vport - pointer to the virtual N_Port data structure.
4227 * NULL - port create failed.
4230 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4232 struct lpfc_vport *vport;
4233 struct Scsi_Host *shost = NULL;
4237 bool use_no_reset_hba = false;
4240 if (lpfc_no_hba_reset_cnt) {
4241 if (phba->sli_rev < LPFC_SLI_REV4 &&
4242 dev == &phba->pcidev->dev) {
4243 /* Reset the port first */
4244 lpfc_sli_brdrestart(phba);
4245 rc = lpfc_sli_chipset_init(phba);
4249 wwn = lpfc_get_wwpn(phba);
4252 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4253 if (wwn == lpfc_no_hba_reset[i]) {
4254 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4255 "6020 Setting use_no_reset port=%llx\n",
4257 use_no_reset_hba = true;
4262 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4263 if (dev != &phba->pcidev->dev) {
4264 shost = scsi_host_alloc(&lpfc_vport_template,
4265 sizeof(struct lpfc_vport));
4267 if (!use_no_reset_hba)
4268 shost = scsi_host_alloc(&lpfc_template,
4269 sizeof(struct lpfc_vport));
4271 shost = scsi_host_alloc(&lpfc_template_no_hr,
4272 sizeof(struct lpfc_vport));
4274 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
4275 shost = scsi_host_alloc(&lpfc_template_nvme,
4276 sizeof(struct lpfc_vport));
4281 vport = (struct lpfc_vport *) shost->hostdata;
4283 vport->load_flag |= FC_LOADING;
4284 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4285 vport->fc_rscn_flush = 0;
4286 lpfc_get_vport_cfgparam(vport);
4288 /* Adjust value in vport */
4289 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4291 shost->unique_id = instance;
4292 shost->max_id = LPFC_MAX_TARGET;
4293 shost->max_lun = vport->cfg_max_luns;
4294 shost->this_id = -1;
4295 shost->max_cmd_len = 16;
4297 if (phba->sli_rev == LPFC_SLI_REV4) {
4298 if (!phba->cfg_fcp_mq_threshold ||
4299 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4300 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4302 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4303 phba->cfg_fcp_mq_threshold);
4305 shost->dma_boundary =
4306 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4308 if (phba->cfg_xpsgl && !phba->nvmet_support)
4309 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4311 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
4313 /* SLI-3 has a limited number of hardware queues (3),
4314 * thus there is only one for FCP processing.
4316 shost->nr_hw_queues = 1;
4319 * Set initial can_queue value since 0 is no longer supported and
4320 * scsi_add_host will fail. This will be adjusted later based on the
4321 * max xri value determined in hba setup.
4323 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4324 if (dev != &phba->pcidev->dev) {
4325 shost->transportt = lpfc_vport_transport_template;
4326 vport->port_type = LPFC_NPIV_PORT;
4328 shost->transportt = lpfc_transport_template;
4329 vport->port_type = LPFC_PHYSICAL_PORT;
4332 /* Initialize all internally managed lists. */
4333 INIT_LIST_HEAD(&vport->fc_nodes);
4334 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4335 spin_lock_init(&vport->work_port_lock);
4337 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4339 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4341 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4343 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4344 lpfc_setup_bg(phba, shost);
4346 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4350 spin_lock_irq(&phba->port_list_lock);
4351 list_add_tail(&vport->listentry, &phba->port_list);
4352 spin_unlock_irq(&phba->port_list_lock);
4356 scsi_host_put(shost);
4362 * destroy_port - destroy an FC port
4363 * @vport: pointer to an lpfc virtual N_Port data structure.
4365 * This routine destroys a FC port from the upper layer protocol. All the
4366 * resources associated with the port are released.
4369 destroy_port(struct lpfc_vport *vport)
4371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4372 struct lpfc_hba *phba = vport->phba;
4374 lpfc_debugfs_terminate(vport);
4375 fc_remove_host(shost);
4376 scsi_remove_host(shost);
4378 spin_lock_irq(&phba->port_list_lock);
4379 list_del_init(&vport->listentry);
4380 spin_unlock_irq(&phba->port_list_lock);
4382 lpfc_cleanup(vport);
4387 * lpfc_get_instance - Get a unique integer ID
4389 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4390 * uses the kernel idr facility to perform the task.
4393 * instance - a unique integer ID allocated as the new instance.
4394 * -1 - lpfc get instance failed.
4397 lpfc_get_instance(void)
4401 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4402 return ret < 0 ? -1 : ret;
4406 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4407 * @shost: pointer to SCSI host data structure.
4408 * @time: elapsed time of the scan in jiffies.
4410 * This routine is called by the SCSI layer with a SCSI host to determine
4411 * whether the scan host is finished.
4413 * Note: there is no scan_start function as adapter initialization will have
4414 * asynchronously kicked off the link initialization.
4417 * 0 - SCSI host scan is not over yet.
4418 * 1 - SCSI host scan is over.
4420 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4423 struct lpfc_hba *phba = vport->phba;
4426 spin_lock_irq(shost->host_lock);
4428 if (vport->load_flag & FC_UNLOADING) {
4432 if (time >= msecs_to_jiffies(30 * 1000)) {
4433 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4434 "0461 Scanning longer than 30 "
4435 "seconds. Continuing initialization\n");
4439 if (time >= msecs_to_jiffies(15 * 1000) &&
4440 phba->link_state <= LPFC_LINK_DOWN) {
4441 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4442 "0465 Link down longer than 15 "
4443 "seconds. Continuing initialization\n");
4448 if (vport->port_state != LPFC_VPORT_READY)
4450 if (vport->num_disc_nodes || vport->fc_prli_sent)
4452 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4454 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4460 spin_unlock_irq(shost->host_lock);
4464 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4466 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4467 struct lpfc_hba *phba = vport->phba;
4469 fc_host_supported_speeds(shost) = 0;
4470 if (phba->lmt & LMT_128Gb)
4471 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4472 if (phba->lmt & LMT_64Gb)
4473 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4474 if (phba->lmt & LMT_32Gb)
4475 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4476 if (phba->lmt & LMT_16Gb)
4477 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4478 if (phba->lmt & LMT_10Gb)
4479 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4480 if (phba->lmt & LMT_8Gb)
4481 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4482 if (phba->lmt & LMT_4Gb)
4483 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4484 if (phba->lmt & LMT_2Gb)
4485 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4486 if (phba->lmt & LMT_1Gb)
4487 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4491 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4492 * @shost: pointer to SCSI host data structure.
4494 * This routine initializes a given SCSI host attributes on a FC port. The
4495 * SCSI host can be either on top of a physical port or a virtual port.
4497 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4500 struct lpfc_hba *phba = vport->phba;
4502 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4505 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4506 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4507 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4509 memset(fc_host_supported_fc4s(shost), 0,
4510 sizeof(fc_host_supported_fc4s(shost)));
4511 fc_host_supported_fc4s(shost)[2] = 1;
4512 fc_host_supported_fc4s(shost)[7] = 1;
4514 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4515 sizeof fc_host_symbolic_name(shost));
4517 lpfc_host_supported_speeds_set(shost);
4519 fc_host_maxframe_size(shost) =
4520 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4521 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4523 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4525 /* This value is also unchanging */
4526 memset(fc_host_active_fc4s(shost), 0,
4527 sizeof(fc_host_active_fc4s(shost)));
4528 fc_host_active_fc4s(shost)[2] = 1;
4529 fc_host_active_fc4s(shost)[7] = 1;
4531 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4532 spin_lock_irq(shost->host_lock);
4533 vport->load_flag &= ~FC_LOADING;
4534 spin_unlock_irq(shost->host_lock);
4538 * lpfc_stop_port_s3 - Stop SLI3 device port
4539 * @phba: pointer to lpfc hba data structure.
4541 * This routine is invoked to stop an SLI3 device port, it stops the device
4542 * from generating interrupts and stops the device driver's timers for the
4546 lpfc_stop_port_s3(struct lpfc_hba *phba)
4548 /* Clear all interrupt enable conditions */
4549 writel(0, phba->HCregaddr);
4550 readl(phba->HCregaddr); /* flush */
4551 /* Clear all pending interrupts */
4552 writel(0xffffffff, phba->HAregaddr);
4553 readl(phba->HAregaddr); /* flush */
4555 /* Reset some HBA SLI setup states */
4556 lpfc_stop_hba_timers(phba);
4557 phba->pport->work_port_events = 0;
4561 * lpfc_stop_port_s4 - Stop SLI4 device port
4562 * @phba: pointer to lpfc hba data structure.
4564 * This routine is invoked to stop an SLI4 device port, it stops the device
4565 * from generating interrupts and stops the device driver's timers for the
4569 lpfc_stop_port_s4(struct lpfc_hba *phba)
4571 /* Reset some HBA SLI4 setup states */
4572 lpfc_stop_hba_timers(phba);
4574 phba->pport->work_port_events = 0;
4575 phba->sli4_hba.intr_enable = 0;
4579 * lpfc_stop_port - Wrapper function for stopping hba port
4580 * @phba: Pointer to HBA context object.
4582 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4583 * the API jump table function pointer from the lpfc_hba struct.
4586 lpfc_stop_port(struct lpfc_hba *phba)
4588 phba->lpfc_stop_port(phba);
4591 flush_workqueue(phba->wq);
4595 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4596 * @phba: Pointer to hba for which this call is being executed.
4598 * This routine starts the timer waiting for the FCF rediscovery to complete.
4601 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4603 unsigned long fcf_redisc_wait_tmo =
4604 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4605 /* Start fcf rediscovery wait period timer */
4606 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4607 spin_lock_irq(&phba->hbalock);
4608 /* Allow action to new fcf asynchronous event */
4609 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4610 /* Mark the FCF rediscovery pending state */
4611 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4612 spin_unlock_irq(&phba->hbalock);
4616 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4617 * @ptr: Map to lpfc_hba data structure pointer.
4619 * This routine is invoked when waiting for FCF table rediscover has been
4620 * timed out. If new FCF record(s) has (have) been discovered during the
4621 * wait period, a new FCF event shall be added to the FCOE async event
4622 * list, and then worker thread shall be waked up for processing from the
4623 * worker thread context.
4626 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
4628 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
4630 /* Don't send FCF rediscovery event if timer cancelled */
4631 spin_lock_irq(&phba->hbalock);
4632 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4633 spin_unlock_irq(&phba->hbalock);
4636 /* Clear FCF rediscovery timer pending flag */
4637 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4638 /* FCF rediscovery event to worker thread */
4639 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4640 spin_unlock_irq(&phba->hbalock);
4641 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4642 "2776 FCF rediscover quiescent timer expired\n");
4643 /* wake up worker thread */
4644 lpfc_worker_wake_up(phba);
4648 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4649 * @phba: pointer to lpfc hba data structure.
4650 * @acqe_link: pointer to the async link completion queue entry.
4652 * This routine is to parse the SLI4 link-attention link fault code.
4655 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4656 struct lpfc_acqe_link *acqe_link)
4658 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4659 case LPFC_ASYNC_LINK_FAULT_NONE:
4660 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4661 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4662 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
4665 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4666 "0398 Unknown link fault code: x%x\n",
4667 bf_get(lpfc_acqe_link_fault, acqe_link));
4673 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4674 * @phba: pointer to lpfc hba data structure.
4675 * @acqe_link: pointer to the async link completion queue entry.
4677 * This routine is to parse the SLI4 link attention type and translate it
4678 * into the base driver's link attention type coding.
4680 * Return: Link attention type in terms of base driver's coding.
4683 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4684 struct lpfc_acqe_link *acqe_link)
4688 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4689 case LPFC_ASYNC_LINK_STATUS_DOWN:
4690 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
4691 att_type = LPFC_ATT_LINK_DOWN;
4693 case LPFC_ASYNC_LINK_STATUS_UP:
4694 /* Ignore physical link up events - wait for logical link up */
4695 att_type = LPFC_ATT_RESERVED;
4697 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
4698 att_type = LPFC_ATT_LINK_UP;
4701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4702 "0399 Invalid link attention type: x%x\n",
4703 bf_get(lpfc_acqe_link_status, acqe_link));
4704 att_type = LPFC_ATT_RESERVED;
4711 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4712 * @phba: pointer to lpfc hba data structure.
4714 * This routine is to get an SLI3 FC port's link speed in Mbps.
4716 * Return: link speed in terms of Mbps.
4719 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4721 uint32_t link_speed;
4723 if (!lpfc_is_link_up(phba))
4726 if (phba->sli_rev <= LPFC_SLI_REV3) {
4727 switch (phba->fc_linkspeed) {
4728 case LPFC_LINK_SPEED_1GHZ:
4731 case LPFC_LINK_SPEED_2GHZ:
4734 case LPFC_LINK_SPEED_4GHZ:
4737 case LPFC_LINK_SPEED_8GHZ:
4740 case LPFC_LINK_SPEED_10GHZ:
4743 case LPFC_LINK_SPEED_16GHZ:
4750 if (phba->sli4_hba.link_state.logical_speed)
4752 phba->sli4_hba.link_state.logical_speed;
4754 link_speed = phba->sli4_hba.link_state.speed;
4760 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4761 * @phba: pointer to lpfc hba data structure.
4762 * @evt_code: asynchronous event code.
4763 * @speed_code: asynchronous event link speed code.
4765 * This routine is to parse the giving SLI4 async event link speed code into
4766 * value of Mbps for the link speed.
4768 * Return: link speed in terms of Mbps.
4771 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4774 uint32_t port_speed;
4777 case LPFC_TRAILER_CODE_LINK:
4778 switch (speed_code) {
4779 case LPFC_ASYNC_LINK_SPEED_ZERO:
4782 case LPFC_ASYNC_LINK_SPEED_10MBPS:
4785 case LPFC_ASYNC_LINK_SPEED_100MBPS:
4788 case LPFC_ASYNC_LINK_SPEED_1GBPS:
4791 case LPFC_ASYNC_LINK_SPEED_10GBPS:
4794 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4797 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4800 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4807 case LPFC_TRAILER_CODE_FC:
4808 switch (speed_code) {
4809 case LPFC_FC_LA_SPEED_UNKNOWN:
4812 case LPFC_FC_LA_SPEED_1G:
4815 case LPFC_FC_LA_SPEED_2G:
4818 case LPFC_FC_LA_SPEED_4G:
4821 case LPFC_FC_LA_SPEED_8G:
4824 case LPFC_FC_LA_SPEED_10G:
4827 case LPFC_FC_LA_SPEED_16G:
4830 case LPFC_FC_LA_SPEED_32G:
4833 case LPFC_FC_LA_SPEED_64G:
4836 case LPFC_FC_LA_SPEED_128G:
4837 port_speed = 128000;
4850 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4851 * @phba: pointer to lpfc hba data structure.
4852 * @acqe_link: pointer to the async link completion queue entry.
4854 * This routine is to handle the SLI4 asynchronous FCoE link event.
4857 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4858 struct lpfc_acqe_link *acqe_link)
4860 struct lpfc_dmabuf *mp;
4863 struct lpfc_mbx_read_top *la;
4867 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
4868 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
4870 phba->fcoe_eventtag = acqe_link->event_tag;
4871 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4873 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4874 "0395 The mboxq allocation failed\n");
4877 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4879 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4880 "0396 The lpfc_dmabuf allocation failed\n");
4883 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4885 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4886 "0397 The mbuf allocation failed\n");
4887 goto out_free_dmabuf;
4890 /* Cleanup any outstanding ELS commands */
4891 lpfc_els_flush_all_cmd(phba);
4893 /* Block ELS IOCBs until we have done process link event */
4894 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4896 /* Update link event statistics */
4897 phba->sli.slistat.link_event++;
4899 /* Create lpfc_handle_latt mailbox command from link ACQE */
4900 lpfc_read_topology(phba, pmb, mp);
4901 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4902 pmb->vport = phba->pport;
4904 /* Keep the link status for extra SLI4 state machine reference */
4905 phba->sli4_hba.link_state.speed =
4906 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4907 bf_get(lpfc_acqe_link_speed, acqe_link));
4908 phba->sli4_hba.link_state.duplex =
4909 bf_get(lpfc_acqe_link_duplex, acqe_link);
4910 phba->sli4_hba.link_state.status =
4911 bf_get(lpfc_acqe_link_status, acqe_link);
4912 phba->sli4_hba.link_state.type =
4913 bf_get(lpfc_acqe_link_type, acqe_link);
4914 phba->sli4_hba.link_state.number =
4915 bf_get(lpfc_acqe_link_number, acqe_link);
4916 phba->sli4_hba.link_state.fault =
4917 bf_get(lpfc_acqe_link_fault, acqe_link);
4918 phba->sli4_hba.link_state.logical_speed =
4919 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4921 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4922 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4923 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4924 "Logical speed:%dMbps Fault:%d\n",
4925 phba->sli4_hba.link_state.speed,
4926 phba->sli4_hba.link_state.topology,
4927 phba->sli4_hba.link_state.status,
4928 phba->sli4_hba.link_state.type,
4929 phba->sli4_hba.link_state.number,
4930 phba->sli4_hba.link_state.logical_speed,
4931 phba->sli4_hba.link_state.fault);
4933 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4934 * topology info. Note: Optional for non FC-AL ports.
4936 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4937 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4938 if (rc == MBX_NOT_FINISHED)
4939 goto out_free_dmabuf;
4943 * For FCoE Mode: fill in all the topology information we need and call
4944 * the READ_TOPOLOGY completion routine to continue without actually
4945 * sending the READ_TOPOLOGY mailbox command to the port.
4947 /* Initialize completion status */
4949 mb->mbxStatus = MBX_SUCCESS;
4951 /* Parse port fault information field */
4952 lpfc_sli4_parse_latt_fault(phba, acqe_link);
4954 /* Parse and translate link attention fields */
4955 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4956 la->eventTag = acqe_link->event_tag;
4957 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4958 bf_set(lpfc_mbx_read_top_link_spd, la,
4959 (bf_get(lpfc_acqe_link_speed, acqe_link)));
4961 /* Fake the the following irrelvant fields */
4962 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4963 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4964 bf_set(lpfc_mbx_read_top_il, la, 0);
4965 bf_set(lpfc_mbx_read_top_pb, la, 0);
4966 bf_set(lpfc_mbx_read_top_fa, la, 0);
4967 bf_set(lpfc_mbx_read_top_mm, la, 0);
4969 /* Invoke the lpfc_handle_latt mailbox command callback function */
4970 lpfc_mbx_cmpl_read_topology(phba, pmb);
4977 mempool_free(pmb, phba->mbox_mem_pool);
4981 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
4983 * @phba: pointer to lpfc hba data structure.
4984 * @evt_code: asynchronous event code.
4985 * @speed_code: asynchronous event link speed code.
4987 * This routine is to parse the giving SLI4 async event link speed code into
4988 * value of Read topology link speed.
4990 * Return: link speed in terms of Read topology.
4993 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
4997 switch (speed_code) {
4998 case LPFC_FC_LA_SPEED_1G:
4999 port_speed = LPFC_LINK_SPEED_1GHZ;
5001 case LPFC_FC_LA_SPEED_2G:
5002 port_speed = LPFC_LINK_SPEED_2GHZ;
5004 case LPFC_FC_LA_SPEED_4G:
5005 port_speed = LPFC_LINK_SPEED_4GHZ;
5007 case LPFC_FC_LA_SPEED_8G:
5008 port_speed = LPFC_LINK_SPEED_8GHZ;
5010 case LPFC_FC_LA_SPEED_16G:
5011 port_speed = LPFC_LINK_SPEED_16GHZ;
5013 case LPFC_FC_LA_SPEED_32G:
5014 port_speed = LPFC_LINK_SPEED_32GHZ;
5016 case LPFC_FC_LA_SPEED_64G:
5017 port_speed = LPFC_LINK_SPEED_64GHZ;
5019 case LPFC_FC_LA_SPEED_128G:
5020 port_speed = LPFC_LINK_SPEED_128GHZ;
5022 case LPFC_FC_LA_SPEED_256G:
5023 port_speed = LPFC_LINK_SPEED_256GHZ;
5033 #define trunk_link_status(__idx)\
5034 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5035 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5036 "Link up" : "Link down") : "NA"
5037 /* Did port __idx reported an error */
5038 #define trunk_port_fault(__idx)\
5039 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5040 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5043 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
5044 struct lpfc_acqe_fc_la *acqe_fc)
5046 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
5047 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
5049 phba->sli4_hba.link_state.speed =
5050 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5051 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5053 phba->sli4_hba.link_state.logical_speed =
5054 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
5055 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5056 phba->fc_linkspeed =
5057 lpfc_async_link_speed_to_read_top(
5059 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5061 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
5062 phba->trunk_link.link0.state =
5063 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
5064 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5065 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
5067 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
5068 phba->trunk_link.link1.state =
5069 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
5070 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5071 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
5073 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
5074 phba->trunk_link.link2.state =
5075 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
5076 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5077 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
5079 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
5080 phba->trunk_link.link3.state =
5081 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
5082 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5083 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
5086 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5087 "2910 Async FC Trunking Event - Speed:%d\n"
5088 "\tLogical speed:%d "
5089 "port0: %s port1: %s port2: %s port3: %s\n",
5090 phba->sli4_hba.link_state.speed,
5091 phba->sli4_hba.link_state.logical_speed,
5092 trunk_link_status(0), trunk_link_status(1),
5093 trunk_link_status(2), trunk_link_status(3));
5096 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5097 "3202 trunk error:0x%x (%s) seen on port0:%s "
5099 * SLI-4: We have only 0xA error codes
5100 * defined as of now. print an appropriate
5101 * message in case driver needs to be updated.
5103 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
5104 "UNDEFINED. update driver." : trunk_errmsg[err],
5105 trunk_port_fault(0), trunk_port_fault(1),
5106 trunk_port_fault(2), trunk_port_fault(3));
5111 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5112 * @phba: pointer to lpfc hba data structure.
5113 * @acqe_fc: pointer to the async fc completion queue entry.
5115 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5116 * that the event was received and then issue a read_topology mailbox command so
5117 * that the rest of the driver will treat it the same as SLI3.
5120 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
5122 struct lpfc_dmabuf *mp;
5125 struct lpfc_mbx_read_top *la;
5128 if (bf_get(lpfc_trailer_type, acqe_fc) !=
5129 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
5130 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5131 "2895 Non FC link Event detected.(%d)\n",
5132 bf_get(lpfc_trailer_type, acqe_fc));
5136 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5137 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
5138 lpfc_update_trunk_link_status(phba, acqe_fc);
5142 /* Keep the link status for extra SLI4 state machine reference */
5143 phba->sli4_hba.link_state.speed =
5144 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5145 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5146 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
5147 phba->sli4_hba.link_state.topology =
5148 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
5149 phba->sli4_hba.link_state.status =
5150 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
5151 phba->sli4_hba.link_state.type =
5152 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
5153 phba->sli4_hba.link_state.number =
5154 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
5155 phba->sli4_hba.link_state.fault =
5156 bf_get(lpfc_acqe_link_fault, acqe_fc);
5158 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5159 LPFC_FC_LA_TYPE_LINK_DOWN)
5160 phba->sli4_hba.link_state.logical_speed = 0;
5161 else if (!phba->sli4_hba.conf_trunk)
5162 phba->sli4_hba.link_state.logical_speed =
5163 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
5165 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5166 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5167 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5168 "%dMbps Fault:%d\n",
5169 phba->sli4_hba.link_state.speed,
5170 phba->sli4_hba.link_state.topology,
5171 phba->sli4_hba.link_state.status,
5172 phba->sli4_hba.link_state.type,
5173 phba->sli4_hba.link_state.number,
5174 phba->sli4_hba.link_state.logical_speed,
5175 phba->sli4_hba.link_state.fault);
5176 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5178 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5179 "2897 The mboxq allocation failed\n");
5182 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5184 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5185 "2898 The lpfc_dmabuf allocation failed\n");
5188 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5190 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5191 "2899 The mbuf allocation failed\n");
5192 goto out_free_dmabuf;
5195 /* Cleanup any outstanding ELS commands */
5196 lpfc_els_flush_all_cmd(phba);
5198 /* Block ELS IOCBs until we have done process link event */
5199 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5201 /* Update link event statistics */
5202 phba->sli.slistat.link_event++;
5204 /* Create lpfc_handle_latt mailbox command from link ACQE */
5205 lpfc_read_topology(phba, pmb, mp);
5206 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5207 pmb->vport = phba->pport;
5209 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
5210 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
5212 switch (phba->sli4_hba.link_state.status) {
5213 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
5214 phba->link_flag |= LS_MDS_LINK_DOWN;
5216 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
5217 phba->link_flag |= LS_MDS_LOOPBACK;
5223 /* Initialize completion status */
5225 mb->mbxStatus = MBX_SUCCESS;
5227 /* Parse port fault information field */
5228 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
5230 /* Parse and translate link attention fields */
5231 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
5232 la->eventTag = acqe_fc->event_tag;
5234 if (phba->sli4_hba.link_state.status ==
5235 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
5236 bf_set(lpfc_mbx_read_top_att_type, la,
5237 LPFC_FC_LA_TYPE_UNEXP_WWPN);
5239 bf_set(lpfc_mbx_read_top_att_type, la,
5240 LPFC_FC_LA_TYPE_LINK_DOWN);
5242 /* Invoke the mailbox command callback function */
5243 lpfc_mbx_cmpl_read_topology(phba, pmb);
5248 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5249 if (rc == MBX_NOT_FINISHED)
5250 goto out_free_dmabuf;
5256 mempool_free(pmb, phba->mbox_mem_pool);
5260 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5261 * @phba: pointer to lpfc hba data structure.
5262 * @acqe_fc: pointer to the async SLI completion queue entry.
5264 * This routine is to handle the SLI4 asynchronous SLI events.
5267 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
5273 uint8_t operational = 0;
5274 struct temp_event temp_event_data;
5275 struct lpfc_acqe_misconfigured_event *misconfigured;
5276 struct Scsi_Host *shost;
5277 struct lpfc_vport **vports;
5280 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
5282 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5283 "2901 Async SLI event - Type:%d, Event Data: x%08x "
5284 "x%08x x%08x x%08x\n", evt_type,
5285 acqe_sli->event_data1, acqe_sli->event_data2,
5286 acqe_sli->reserved, acqe_sli->trailer);
5288 port_name = phba->Port[0];
5289 if (port_name == 0x00)
5290 port_name = '?'; /* get port name is empty */
5293 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
5294 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5295 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
5296 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5298 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5299 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5300 acqe_sli->event_data1, port_name);
5302 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
5303 shost = lpfc_shost_from_vport(phba->pport);
5304 fc_host_post_vendor_event(shost, fc_get_event_number(),
5305 sizeof(temp_event_data),
5306 (char *)&temp_event_data,
5307 SCSI_NL_VID_TYPE_PCI
5308 | PCI_VENDOR_ID_EMULEX);
5310 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
5311 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5312 temp_event_data.event_code = LPFC_NORMAL_TEMP;
5313 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5315 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5316 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5317 acqe_sli->event_data1, port_name);
5319 shost = lpfc_shost_from_vport(phba->pport);
5320 fc_host_post_vendor_event(shost, fc_get_event_number(),
5321 sizeof(temp_event_data),
5322 (char *)&temp_event_data,
5323 SCSI_NL_VID_TYPE_PCI
5324 | PCI_VENDOR_ID_EMULEX);
5326 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
5327 misconfigured = (struct lpfc_acqe_misconfigured_event *)
5328 &acqe_sli->event_data1;
5330 /* fetch the status for this port */
5331 switch (phba->sli4_hba.lnk_info.lnk_no) {
5332 case LPFC_LINK_NUMBER_0:
5333 status = bf_get(lpfc_sli_misconfigured_port0_state,
5334 &misconfigured->theEvent);
5335 operational = bf_get(lpfc_sli_misconfigured_port0_op,
5336 &misconfigured->theEvent);
5338 case LPFC_LINK_NUMBER_1:
5339 status = bf_get(lpfc_sli_misconfigured_port1_state,
5340 &misconfigured->theEvent);
5341 operational = bf_get(lpfc_sli_misconfigured_port1_op,
5342 &misconfigured->theEvent);
5344 case LPFC_LINK_NUMBER_2:
5345 status = bf_get(lpfc_sli_misconfigured_port2_state,
5346 &misconfigured->theEvent);
5347 operational = bf_get(lpfc_sli_misconfigured_port2_op,
5348 &misconfigured->theEvent);
5350 case LPFC_LINK_NUMBER_3:
5351 status = bf_get(lpfc_sli_misconfigured_port3_state,
5352 &misconfigured->theEvent);
5353 operational = bf_get(lpfc_sli_misconfigured_port3_op,
5354 &misconfigured->theEvent);
5357 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5359 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5360 "event: Invalid link %d",
5361 phba->sli4_hba.lnk_info.lnk_no);
5365 /* Skip if optic state unchanged */
5366 if (phba->sli4_hba.lnk_info.optic_state == status)
5370 case LPFC_SLI_EVENT_STATUS_VALID:
5371 sprintf(message, "Physical Link is functional");
5373 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5374 sprintf(message, "Optics faulted/incorrectly "
5375 "installed/not installed - Reseat optics, "
5376 "if issue not resolved, replace.");
5378 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5380 "Optics of two types installed - Remove one "
5381 "optic or install matching pair of optics.");
5383 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5384 sprintf(message, "Incompatible optics - Replace with "
5385 "compatible optics for card to function.");
5387 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5388 sprintf(message, "Unqualified optics - Replace with "
5389 "Avago optics for Warranty and Technical "
5390 "Support - Link is%s operational",
5391 (operational) ? " not" : "");
5393 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5394 sprintf(message, "Uncertified optics - Replace with "
5395 "Avago-certified optics to enable link "
5396 "operation - Link is%s operational",
5397 (operational) ? " not" : "");
5400 /* firmware is reporting a status we don't know about */
5401 sprintf(message, "Unknown event status x%02x", status);
5405 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5406 rc = lpfc_sli4_read_config(phba);
5409 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5410 "3194 Unable to retrieve supported "
5411 "speeds, rc = 0x%x\n", rc);
5413 vports = lpfc_create_vport_work_array(phba);
5414 if (vports != NULL) {
5415 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5417 shost = lpfc_shost_from_vport(vports[i]);
5418 lpfc_host_supported_speeds_set(shost);
5421 lpfc_destroy_vport_work_array(phba, vports);
5423 phba->sli4_hba.lnk_info.optic_state = status;
5424 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5425 "3176 Port Name %c %s\n", port_name, message);
5427 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5428 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5429 "3192 Remote DPort Test Initiated - "
5430 "Event Data1:x%08x Event Data2: x%08x\n",
5431 acqe_sli->event_data1, acqe_sli->event_data2);
5433 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
5434 /* Misconfigured WWN. Reports that the SLI Port is configured
5435 * to use FA-WWN, but the attached device doesn’t support it.
5436 * No driver action is required.
5437 * Event Data1 - N.A, Event Data2 - N.A
5439 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI,
5440 "2699 Misconfigured FA-WWN - Attached device does "
5441 "not support FA-WWN\n");
5443 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
5444 /* EEPROM failure. No driver action is required */
5445 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5446 "2518 EEPROM failure - "
5447 "Event Data1: x%08x Event Data2: x%08x\n",
5448 acqe_sli->event_data1, acqe_sli->event_data2);
5451 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5452 "3193 Unrecognized SLI event, type: 0x%x",
5459 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5460 * @vport: pointer to vport data structure.
5462 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5463 * response to a CVL event.
5465 * Return the pointer to the ndlp with the vport if successful, otherwise
5468 static struct lpfc_nodelist *
5469 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
5471 struct lpfc_nodelist *ndlp;
5472 struct Scsi_Host *shost;
5473 struct lpfc_hba *phba;
5480 ndlp = lpfc_findnode_did(vport, Fabric_DID);
5482 /* Cannot find existing Fabric ndlp, so allocate a new one */
5483 ndlp = lpfc_nlp_init(vport, Fabric_DID);
5486 /* Set the node type */
5487 ndlp->nlp_type |= NLP_FABRIC;
5488 /* Put ndlp onto node list */
5489 lpfc_enqueue_node(vport, ndlp);
5490 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5491 /* re-setup ndlp without removing from node list */
5492 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5496 if ((phba->pport->port_state < LPFC_FLOGI) &&
5497 (phba->pport->port_state != LPFC_VPORT_FAILED))
5499 /* If virtual link is not yet instantiated ignore CVL */
5500 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
5501 && (vport->port_state != LPFC_VPORT_FAILED))
5503 shost = lpfc_shost_from_vport(vport);
5506 lpfc_linkdown_port(vport);
5507 lpfc_cleanup_pending_mbox(vport);
5508 spin_lock_irq(shost->host_lock);
5509 vport->fc_flag |= FC_VPORT_CVL_RCVD;
5510 spin_unlock_irq(shost->host_lock);
5516 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
5517 * @vport: pointer to lpfc hba data structure.
5519 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5520 * response to a FCF dead event.
5523 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
5525 struct lpfc_vport **vports;
5528 vports = lpfc_create_vport_work_array(phba);
5530 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
5531 lpfc_sli4_perform_vport_cvl(vports[i]);
5532 lpfc_destroy_vport_work_array(phba, vports);
5536 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
5537 * @phba: pointer to lpfc hba data structure.
5538 * @acqe_link: pointer to the async fcoe completion queue entry.
5540 * This routine is to handle the SLI4 asynchronous fcoe event.
5543 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
5544 struct lpfc_acqe_fip *acqe_fip)
5546 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
5548 struct lpfc_vport *vport;
5549 struct lpfc_nodelist *ndlp;
5550 struct Scsi_Host *shost;
5551 int active_vlink_present;
5552 struct lpfc_vport **vports;
5555 phba->fc_eventTag = acqe_fip->event_tag;
5556 phba->fcoe_eventtag = acqe_fip->event_tag;
5557 switch (event_type) {
5558 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5559 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5560 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
5561 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5563 "2546 New FCF event, evt_tag:x%x, "
5565 acqe_fip->event_tag,
5568 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5570 "2788 FCF param modified event, "
5571 "evt_tag:x%x, index:x%x\n",
5572 acqe_fip->event_tag,
5574 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5576 * During period of FCF discovery, read the FCF
5577 * table record indexed by the event to update
5578 * FCF roundrobin failover eligible FCF bmask.
5580 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5582 "2779 Read FCF (x%x) for updating "
5583 "roundrobin FCF failover bmask\n",
5585 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
5588 /* If the FCF discovery is in progress, do nothing. */
5589 spin_lock_irq(&phba->hbalock);
5590 if (phba->hba_flag & FCF_TS_INPROG) {
5591 spin_unlock_irq(&phba->hbalock);
5594 /* If fast FCF failover rescan event is pending, do nothing */
5595 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
5596 spin_unlock_irq(&phba->hbalock);
5600 /* If the FCF has been in discovered state, do nothing. */
5601 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
5602 spin_unlock_irq(&phba->hbalock);
5605 spin_unlock_irq(&phba->hbalock);
5607 /* Otherwise, scan the entire FCF table and re-discover SAN */
5608 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5609 "2770 Start FCF table scan per async FCF "
5610 "event, evt_tag:x%x, index:x%x\n",
5611 acqe_fip->event_tag, acqe_fip->index);
5612 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5613 LPFC_FCOE_FCF_GET_FIRST);
5615 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5616 "2547 Issue FCF scan read FCF mailbox "
5617 "command failed (x%x)\n", rc);
5620 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
5621 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5622 "2548 FCF Table full count 0x%x tag 0x%x\n",
5623 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5624 acqe_fip->event_tag);
5627 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
5628 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5629 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5630 "2549 FCF (x%x) disconnected from network, "
5631 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
5633 * If we are in the middle of FCF failover process, clear
5634 * the corresponding FCF bit in the roundrobin bitmap.
5636 spin_lock_irq(&phba->hbalock);
5637 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5638 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
5639 spin_unlock_irq(&phba->hbalock);
5640 /* Update FLOGI FCF failover eligible FCF bmask */
5641 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
5644 spin_unlock_irq(&phba->hbalock);
5646 /* If the event is not for currently used fcf do nothing */
5647 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
5651 * Otherwise, request the port to rediscover the entire FCF
5652 * table for a fast recovery from case that the current FCF
5653 * is no longer valid as we are not in the middle of FCF
5654 * failover process already.
5656 spin_lock_irq(&phba->hbalock);
5657 /* Mark the fast failover process in progress */
5658 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5659 spin_unlock_irq(&phba->hbalock);
5661 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5662 "2771 Start FCF fast failover process due to "
5663 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5664 "\n", acqe_fip->event_tag, acqe_fip->index);
5665 rc = lpfc_sli4_redisc_fcf_table(phba);
5667 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5669 "2772 Issue FCF rediscover mailbox "
5670 "command failed, fail through to FCF "
5672 spin_lock_irq(&phba->hbalock);
5673 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5674 spin_unlock_irq(&phba->hbalock);
5676 * Last resort will fail over by treating this
5677 * as a link down to FCF registration.
5679 lpfc_sli4_fcf_dead_failthrough(phba);
5681 /* Reset FCF roundrobin bmask for new discovery */
5682 lpfc_sli4_clear_fcf_rr_bmask(phba);
5684 * Handling fast FCF failover to a DEAD FCF event is
5685 * considered equalivant to receiving CVL to all vports.
5687 lpfc_sli4_perform_all_vport_cvl(phba);
5690 case LPFC_FIP_EVENT_TYPE_CVL:
5691 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5692 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5693 "2718 Clear Virtual Link Received for VPI 0x%x"
5694 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
5696 vport = lpfc_find_vport_by_vpid(phba,
5698 ndlp = lpfc_sli4_perform_vport_cvl(vport);
5701 active_vlink_present = 0;
5703 vports = lpfc_create_vport_work_array(phba);
5705 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5707 if ((!(vports[i]->fc_flag &
5708 FC_VPORT_CVL_RCVD)) &&
5709 (vports[i]->port_state > LPFC_FDISC)) {
5710 active_vlink_present = 1;
5714 lpfc_destroy_vport_work_array(phba, vports);
5718 * Don't re-instantiate if vport is marked for deletion.
5719 * If we are here first then vport_delete is going to wait
5720 * for discovery to complete.
5722 if (!(vport->load_flag & FC_UNLOADING) &&
5723 active_vlink_present) {
5725 * If there are other active VLinks present,
5726 * re-instantiate the Vlink using FDISC.
5728 mod_timer(&ndlp->nlp_delayfunc,
5729 jiffies + msecs_to_jiffies(1000));
5730 shost = lpfc_shost_from_vport(vport);
5731 spin_lock_irq(shost->host_lock);
5732 ndlp->nlp_flag |= NLP_DELAY_TMO;
5733 spin_unlock_irq(shost->host_lock);
5734 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5735 vport->port_state = LPFC_FDISC;
5738 * Otherwise, we request port to rediscover
5739 * the entire FCF table for a fast recovery
5740 * from possible case that the current FCF
5741 * is no longer valid if we are not already
5742 * in the FCF failover process.
5744 spin_lock_irq(&phba->hbalock);
5745 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5746 spin_unlock_irq(&phba->hbalock);
5749 /* Mark the fast failover process in progress */
5750 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
5751 spin_unlock_irq(&phba->hbalock);
5752 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5754 "2773 Start FCF failover per CVL, "
5755 "evt_tag:x%x\n", acqe_fip->event_tag);
5756 rc = lpfc_sli4_redisc_fcf_table(phba);
5758 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5760 "2774 Issue FCF rediscover "
5761 "mailbox command failed, "
5762 "through to CVL event\n");
5763 spin_lock_irq(&phba->hbalock);
5764 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
5765 spin_unlock_irq(&phba->hbalock);
5767 * Last resort will be re-try on the
5768 * the current registered FCF entry.
5770 lpfc_retry_pport_discovery(phba);
5773 * Reset FCF roundrobin bmask for new
5776 lpfc_sli4_clear_fcf_rr_bmask(phba);
5780 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5781 "0288 Unknown FCoE event type 0x%x event tag "
5782 "0x%x\n", event_type, acqe_fip->event_tag);
5788 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5789 * @phba: pointer to lpfc hba data structure.
5790 * @acqe_link: pointer to the async dcbx completion queue entry.
5792 * This routine is to handle the SLI4 asynchronous dcbx event.
5795 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5796 struct lpfc_acqe_dcbx *acqe_dcbx)
5798 phba->fc_eventTag = acqe_dcbx->event_tag;
5799 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5800 "0290 The SLI4 DCBX asynchronous event is not "
5805 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5806 * @phba: pointer to lpfc hba data structure.
5807 * @acqe_link: pointer to the async grp5 completion queue entry.
5809 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5810 * is an asynchronous notified of a logical link speed change. The Port
5811 * reports the logical link speed in units of 10Mbps.
5814 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5815 struct lpfc_acqe_grp5 *acqe_grp5)
5817 uint16_t prev_ll_spd;
5819 phba->fc_eventTag = acqe_grp5->event_tag;
5820 phba->fcoe_eventtag = acqe_grp5->event_tag;
5821 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5822 phba->sli4_hba.link_state.logical_speed =
5823 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
5824 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5825 "2789 GRP5 Async Event: Updating logical link speed "
5826 "from %dMbps to %dMbps\n", prev_ll_spd,
5827 phba->sli4_hba.link_state.logical_speed);
5831 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5832 * @phba: pointer to lpfc hba data structure.
5834 * This routine is invoked by the worker thread to process all the pending
5835 * SLI4 asynchronous events.
5837 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5839 struct lpfc_cq_event *cq_event;
5841 /* First, declare the async event has been handled */
5842 spin_lock_irq(&phba->hbalock);
5843 phba->hba_flag &= ~ASYNC_EVENT;
5844 spin_unlock_irq(&phba->hbalock);
5845 /* Now, handle all the async events */
5846 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5847 /* Get the first event from the head of the event queue */
5848 spin_lock_irq(&phba->hbalock);
5849 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5850 cq_event, struct lpfc_cq_event, list);
5851 spin_unlock_irq(&phba->hbalock);
5852 /* Process the asynchronous event */
5853 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5854 case LPFC_TRAILER_CODE_LINK:
5855 lpfc_sli4_async_link_evt(phba,
5856 &cq_event->cqe.acqe_link);
5858 case LPFC_TRAILER_CODE_FCOE:
5859 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
5861 case LPFC_TRAILER_CODE_DCBX:
5862 lpfc_sli4_async_dcbx_evt(phba,
5863 &cq_event->cqe.acqe_dcbx);
5865 case LPFC_TRAILER_CODE_GRP5:
5866 lpfc_sli4_async_grp5_evt(phba,
5867 &cq_event->cqe.acqe_grp5);
5869 case LPFC_TRAILER_CODE_FC:
5870 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5872 case LPFC_TRAILER_CODE_SLI:
5873 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5876 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5877 "1804 Invalid asynchronous event code: "
5878 "x%x\n", bf_get(lpfc_trailer_code,
5879 &cq_event->cqe.mcqe_cmpl));
5882 /* Free the completion event processed to the free pool */
5883 lpfc_sli4_cq_event_release(phba, cq_event);
5888 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5889 * @phba: pointer to lpfc hba data structure.
5891 * This routine is invoked by the worker thread to process FCF table
5892 * rediscovery pending completion event.
5894 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5898 spin_lock_irq(&phba->hbalock);
5899 /* Clear FCF rediscovery timeout event */
5900 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5901 /* Clear driver fast failover FCF record flag */
5902 phba->fcf.failover_rec.flag = 0;
5903 /* Set state for FCF fast failover */
5904 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5905 spin_unlock_irq(&phba->hbalock);
5907 /* Scan FCF table from the first entry to re-discover SAN */
5908 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5909 "2777 Start post-quiescent FCF table scan\n");
5910 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5912 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5913 "2747 Issue FCF scan read FCF mailbox "
5914 "command failed 0x%x\n", rc);
5918 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5919 * @phba: pointer to lpfc hba data structure.
5920 * @dev_grp: The HBA PCI-Device group number.
5922 * This routine is invoked to set up the per HBA PCI-Device group function
5923 * API jump table entries.
5925 * Return: 0 if success, otherwise -ENODEV
5928 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5932 /* Set up lpfc PCI-device group */
5933 phba->pci_dev_grp = dev_grp;
5935 /* The LPFC_PCI_DEV_OC uses SLI4 */
5936 if (dev_grp == LPFC_PCI_DEV_OC)
5937 phba->sli_rev = LPFC_SLI_REV4;
5939 /* Set up device INIT API function jump table */
5940 rc = lpfc_init_api_table_setup(phba, dev_grp);
5943 /* Set up SCSI API function jump table */
5944 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5947 /* Set up SLI API function jump table */
5948 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5951 /* Set up MBOX API function jump table */
5952 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5960 * lpfc_log_intr_mode - Log the active interrupt mode
5961 * @phba: pointer to lpfc hba data structure.
5962 * @intr_mode: active interrupt mode adopted.
5964 * This routine it invoked to log the currently used active interrupt mode
5967 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
5969 switch (intr_mode) {
5971 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5972 "0470 Enable INTx interrupt mode.\n");
5975 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5976 "0481 Enabled MSI interrupt mode.\n");
5979 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5980 "0480 Enabled MSI-X interrupt mode.\n");
5983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5984 "0482 Illegal interrupt mode.\n");
5991 * lpfc_cpumask_of_node_init - initalizes cpumask of phba's NUMA node
5992 * @phba: Pointer to HBA context object.
5996 lpfc_cpumask_of_node_init(struct lpfc_hba *phba)
5998 unsigned int cpu, numa_node;
5999 struct cpumask *numa_mask = &phba->sli4_hba.numa_mask;
6001 cpumask_clear(numa_mask);
6003 /* Check if we're a NUMA architecture */
6004 numa_node = dev_to_node(&phba->pcidev->dev);
6005 if (numa_node == NUMA_NO_NODE)
6008 for_each_possible_cpu(cpu)
6009 if (cpu_to_node(cpu) == numa_node)
6010 cpumask_set_cpu(cpu, numa_mask);
6014 * lpfc_enable_pci_dev - Enable a generic PCI device.
6015 * @phba: pointer to lpfc hba data structure.
6017 * This routine is invoked to enable the PCI device that is common to all
6022 * other values - error
6025 lpfc_enable_pci_dev(struct lpfc_hba *phba)
6027 struct pci_dev *pdev;
6029 /* Obtain PCI device reference */
6033 pdev = phba->pcidev;
6034 /* Enable PCI device */
6035 if (pci_enable_device_mem(pdev))
6037 /* Request PCI resource for the device */
6038 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
6039 goto out_disable_device;
6040 /* Set up device as PCI master and save state for EEH */
6041 pci_set_master(pdev);
6042 pci_try_set_mwi(pdev);
6043 pci_save_state(pdev);
6045 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
6046 if (pci_is_pcie(pdev))
6047 pdev->needs_freset = 1;
6052 pci_disable_device(pdev);
6054 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6055 "1401 Failed to enable pci device\n");
6060 * lpfc_disable_pci_dev - Disable a generic PCI device.
6061 * @phba: pointer to lpfc hba data structure.
6063 * This routine is invoked to disable the PCI device that is common to all
6067 lpfc_disable_pci_dev(struct lpfc_hba *phba)
6069 struct pci_dev *pdev;
6071 /* Obtain PCI device reference */
6075 pdev = phba->pcidev;
6076 /* Release PCI resource and disable PCI device */
6077 pci_release_mem_regions(pdev);
6078 pci_disable_device(pdev);
6084 * lpfc_reset_hba - Reset a hba
6085 * @phba: pointer to lpfc hba data structure.
6087 * This routine is invoked to reset a hba device. It brings the HBA
6088 * offline, performs a board restart, and then brings the board back
6089 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6090 * on outstanding mailbox commands.
6093 lpfc_reset_hba(struct lpfc_hba *phba)
6095 /* If resets are disabled then set error state and return. */
6096 if (!phba->cfg_enable_hba_reset) {
6097 phba->link_state = LPFC_HBA_ERROR;
6100 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
6101 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6103 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
6105 lpfc_sli_brdrestart(phba);
6107 lpfc_unblock_mgmt_io(phba);
6111 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6112 * @phba: pointer to lpfc hba data structure.
6114 * This function enables the PCI SR-IOV virtual functions to a physical
6115 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6116 * enable the number of virtual functions to the physical function. As
6117 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6118 * API call does not considered as an error condition for most of the device.
6121 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
6123 struct pci_dev *pdev = phba->pcidev;
6127 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6131 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
6136 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6137 * @phba: pointer to lpfc hba data structure.
6138 * @nr_vfn: number of virtual functions to be enabled.
6140 * This function enables the PCI SR-IOV virtual functions to a physical
6141 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6142 * enable the number of virtual functions to the physical function. As
6143 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6144 * API call does not considered as an error condition for most of the device.
6147 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
6149 struct pci_dev *pdev = phba->pcidev;
6150 uint16_t max_nr_vfn;
6153 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
6154 if (nr_vfn > max_nr_vfn) {
6155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6156 "3057 Requested vfs (%d) greater than "
6157 "supported vfs (%d)", nr_vfn, max_nr_vfn);
6161 rc = pci_enable_sriov(pdev, nr_vfn);
6163 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6164 "2806 Failed to enable sriov on this device "
6165 "with vfn number nr_vf:%d, rc:%d\n",
6168 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6169 "2807 Successful enable sriov on this device "
6170 "with vfn number nr_vf:%d\n", nr_vfn);
6175 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
6176 * @phba: pointer to lpfc hba data structure.
6178 * This routine is invoked to set up the driver internal resources before the
6179 * device specific resource setup to support the HBA device it attached to.
6183 * other values - error
6186 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
6188 struct lpfc_sli *psli = &phba->sli;
6191 * Driver resources common to all SLI revisions
6193 atomic_set(&phba->fast_event_count, 0);
6194 spin_lock_init(&phba->hbalock);
6196 /* Initialize ndlp management spinlock */
6197 spin_lock_init(&phba->ndlp_lock);
6199 /* Initialize port_list spinlock */
6200 spin_lock_init(&phba->port_list_lock);
6201 INIT_LIST_HEAD(&phba->port_list);
6203 INIT_LIST_HEAD(&phba->work_list);
6204 init_waitqueue_head(&phba->wait_4_mlo_m_q);
6206 /* Initialize the wait queue head for the kernel thread */
6207 init_waitqueue_head(&phba->work_waitq);
6209 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6210 "1403 Protocols supported %s %s %s\n",
6211 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
6213 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
6215 (phba->nvmet_support ? "NVMET" : " "));
6217 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
6218 spin_lock_init(&phba->scsi_buf_list_get_lock);
6219 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
6220 spin_lock_init(&phba->scsi_buf_list_put_lock);
6221 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
6223 /* Initialize the fabric iocb list */
6224 INIT_LIST_HEAD(&phba->fabric_iocb_list);
6226 /* Initialize list to save ELS buffers */
6227 INIT_LIST_HEAD(&phba->elsbuf);
6229 /* Initialize FCF connection rec list */
6230 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
6232 /* Initialize OAS configuration list */
6233 spin_lock_init(&phba->devicelock);
6234 INIT_LIST_HEAD(&phba->luns);
6236 /* MBOX heartbeat timer */
6237 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
6238 /* Fabric block timer */
6239 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
6240 /* EA polling mode timer */
6241 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
6242 /* Heartbeat timer */
6243 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
6245 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
6251 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
6252 * @phba: pointer to lpfc hba data structure.
6254 * This routine is invoked to set up the driver internal resources specific to
6255 * support the SLI-3 HBA device it attached to.
6259 * other values - error
6262 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
6267 * Initialize timers used by driver
6270 /* FCP polling mode timer */
6271 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
6273 /* Host attention work mask setup */
6274 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
6275 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
6277 /* Get all the module params for configuring this host */
6278 lpfc_get_cfgparam(phba);
6279 /* Set up phase-1 common device driver resources */
6281 rc = lpfc_setup_driver_resource_phase1(phba);
6285 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
6286 phba->menlo_flag |= HBA_MENLO_SUPPORT;
6287 /* check for menlo minimum sg count */
6288 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
6289 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
6292 if (!phba->sli.sli3_ring)
6293 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
6294 sizeof(struct lpfc_sli_ring),
6296 if (!phba->sli.sli3_ring)
6300 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
6301 * used to create the sg_dma_buf_pool must be dynamically calculated.
6304 /* Initialize the host templates the configured values. */
6305 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
6306 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
6307 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
6309 if (phba->sli_rev == LPFC_SLI_REV4)
6310 entry_sz = sizeof(struct sli4_sge);
6312 entry_sz = sizeof(struct ulp_bde64);
6314 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
6315 if (phba->cfg_enable_bg) {
6317 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
6318 * the FCP rsp, and a BDE for each. Sice we have no control
6319 * over how many protection data segments the SCSI Layer
6320 * will hand us (ie: there could be one for every block
6321 * in the IO), we just allocate enough BDEs to accomidate
6322 * our max amount and we need to limit lpfc_sg_seg_cnt to
6323 * minimize the risk of running out.
6325 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6326 sizeof(struct fcp_rsp) +
6327 (LPFC_MAX_SG_SEG_CNT * entry_sz);
6329 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
6330 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
6332 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
6333 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
6336 * The scsi_buf for a regular I/O will hold the FCP cmnd,
6337 * the FCP rsp, a BDE for each, and a BDE for up to
6338 * cfg_sg_seg_cnt data segments.
6340 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6341 sizeof(struct fcp_rsp) +
6342 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
6344 /* Total BDEs in BPL for scsi_sg_list */
6345 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
6348 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
6349 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
6350 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6351 phba->cfg_total_seg_cnt);
6353 phba->max_vpi = LPFC_MAX_VPI;
6354 /* This will be set to correct value after config_port mbox */
6355 phba->max_vports = 0;
6358 * Initialize the SLI Layer to run with lpfc HBAs.
6360 lpfc_sli_setup(phba);
6361 lpfc_sli_queue_init(phba);
6363 /* Allocate device driver memory */
6364 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
6367 phba->lpfc_sg_dma_buf_pool =
6368 dma_pool_create("lpfc_sg_dma_buf_pool",
6369 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
6372 if (!phba->lpfc_sg_dma_buf_pool)
6375 phba->lpfc_cmd_rsp_buf_pool =
6376 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6378 sizeof(struct fcp_cmnd) +
6379 sizeof(struct fcp_rsp),
6382 if (!phba->lpfc_cmd_rsp_buf_pool)
6383 goto fail_free_dma_buf_pool;
6386 * Enable sr-iov virtual functions if supported and configured
6387 * through the module parameter.
6389 if (phba->cfg_sriov_nr_virtfn > 0) {
6390 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6391 phba->cfg_sriov_nr_virtfn);
6393 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6394 "2808 Requested number of SR-IOV "
6395 "virtual functions (%d) is not "
6397 phba->cfg_sriov_nr_virtfn);
6398 phba->cfg_sriov_nr_virtfn = 0;
6404 fail_free_dma_buf_pool:
6405 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
6406 phba->lpfc_sg_dma_buf_pool = NULL;
6408 lpfc_mem_free(phba);
6413 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6414 * @phba: pointer to lpfc hba data structure.
6416 * This routine is invoked to unset the driver internal resources set up
6417 * specific for supporting the SLI-3 HBA device it attached to.
6420 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
6422 /* Free device driver memory allocated */
6423 lpfc_mem_free_all(phba);
6429 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6430 * @phba: pointer to lpfc hba data structure.
6432 * This routine is invoked to set up the driver internal resources specific to
6433 * support the SLI-4 HBA device it attached to.
6437 * other values - error
6440 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
6442 LPFC_MBOXQ_t *mboxq;
6444 int rc, i, max_buf_size;
6445 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
6446 struct lpfc_mqe *mqe;
6453 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
6454 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
6455 phba->sli4_hba.curr_disp_cpu = 0;
6456 lpfc_cpumask_of_node_init(phba);
6458 /* Get all the module params for configuring this host */
6459 lpfc_get_cfgparam(phba);
6461 /* Set up phase-1 common device driver resources */
6462 rc = lpfc_setup_driver_resource_phase1(phba);
6466 /* Before proceed, wait for POST done and device ready */
6467 rc = lpfc_sli4_post_status_check(phba);
6471 /* Allocate all driver workqueues here */
6473 /* The lpfc_wq workqueue for deferred irq use */
6474 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6477 * Initialize timers used by driver
6480 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
6482 /* FCF rediscover timer */
6483 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
6486 * Control structure for handling external multi-buffer mailbox
6487 * command pass-through.
6489 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
6490 sizeof(struct lpfc_mbox_ext_buf_ctx));
6491 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
6493 phba->max_vpi = LPFC_MAX_VPI;
6495 /* This will be set to correct value after the read_config mbox */
6496 phba->max_vports = 0;
6498 /* Program the default value of vlan_id and fc_map */
6499 phba->valid_vlan = 0;
6500 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
6501 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
6502 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
6505 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
6506 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6507 * The WQ create will allocate the ring.
6510 /* Initialize buffer queue management fields */
6511 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
6512 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6513 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6516 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6518 /* Initialize the Abort buffer list used by driver */
6519 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
6520 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
6522 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6523 /* Initialize the Abort nvme buffer list used by driver */
6524 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
6525 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6526 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
6527 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
6528 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
6531 /* This abort list used by worker thread */
6532 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
6533 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
6536 * Initialize driver internal slow-path work queues
6539 /* Driver internel slow-path CQ Event pool */
6540 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6541 /* Response IOCB work queue list */
6542 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
6543 /* Asynchronous event CQ Event work queue list */
6544 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6545 /* Fast-path XRI aborted CQ Event work queue list */
6546 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6547 /* Slow-path XRI aborted CQ Event work queue list */
6548 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6549 /* Receive queue CQ Event work queue list */
6550 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6552 /* Initialize extent block lists. */
6553 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6554 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6555 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6556 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6558 /* Initialize mboxq lists. If the early init routines fail
6559 * these lists need to be correctly initialized.
6561 INIT_LIST_HEAD(&phba->sli.mboxq);
6562 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6564 /* initialize optic_state to 0xFF */
6565 phba->sli4_hba.lnk_info.optic_state = 0xff;
6567 /* Allocate device driver memory */
6568 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6572 /* IF Type 2 ports get initialized now. */
6573 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
6574 LPFC_SLI_INTF_IF_TYPE_2) {
6575 rc = lpfc_pci_function_reset(phba);
6580 phba->temp_sensor_support = 1;
6583 /* Create the bootstrap mailbox command */
6584 rc = lpfc_create_bootstrap_mbox(phba);
6588 /* Set up the host's endian order with the device. */
6589 rc = lpfc_setup_endian_order(phba);
6591 goto out_free_bsmbx;
6593 /* Set up the hba's configuration parameters. */
6594 rc = lpfc_sli4_read_config(phba);
6596 goto out_free_bsmbx;
6597 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6599 goto out_free_bsmbx;
6601 /* IF Type 0 ports get initialized now. */
6602 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6603 LPFC_SLI_INTF_IF_TYPE_0) {
6604 rc = lpfc_pci_function_reset(phba);
6606 goto out_free_bsmbx;
6609 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6613 goto out_free_bsmbx;
6616 /* Check for NVMET being configured */
6617 phba->nvmet_support = 0;
6618 if (lpfc_enable_nvmet_cnt) {
6620 /* First get WWN of HBA instance */
6621 lpfc_read_nv(phba, mboxq);
6622 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6623 if (rc != MBX_SUCCESS) {
6624 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6625 "6016 Mailbox failed , mbxCmd x%x "
6626 "READ_NV, mbxStatus x%x\n",
6627 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6628 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
6629 mempool_free(mboxq, phba->mbox_mem_pool);
6631 goto out_free_bsmbx;
6634 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6636 wwn = cpu_to_be64(wwn);
6637 phba->sli4_hba.wwnn.u.name = wwn;
6638 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6640 /* wwn is WWPN of HBA instance */
6641 wwn = cpu_to_be64(wwn);
6642 phba->sli4_hba.wwpn.u.name = wwn;
6644 /* Check to see if it matches any module parameter */
6645 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6646 if (wwn == lpfc_enable_nvmet[i]) {
6647 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
6648 if (lpfc_nvmet_mem_alloc(phba))
6651 phba->nvmet_support = 1; /* a match */
6653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6654 "6017 NVME Target %016llx\n",
6657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6658 "6021 Can't enable NVME Target."
6659 " NVME_TARGET_FC infrastructure"
6660 " is not in kernel\n");
6662 /* Not supported for NVMET */
6663 phba->cfg_xri_rebalancing = 0;
6669 lpfc_nvme_mod_param_dep(phba);
6671 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
6672 lpfc_supported_pages(mboxq);
6673 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6675 mqe = &mboxq->u.mqe;
6676 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6677 LPFC_MAX_SUPPORTED_PAGES);
6678 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6679 switch (pn_page[i]) {
6680 case LPFC_SLI4_PARAMETERS:
6681 phba->sli4_hba.pc_sli4_params.supported = 1;
6687 /* Read the port's SLI4 Parameters capabilities if supported. */
6688 if (phba->sli4_hba.pc_sli4_params.supported)
6689 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6691 mempool_free(mboxq, phba->mbox_mem_pool);
6693 goto out_free_bsmbx;
6698 * Get sli4 parameters that override parameters from Port capabilities.
6699 * If this call fails, it isn't critical unless the SLI4 parameters come
6702 rc = lpfc_get_sli4_parameters(phba, mboxq);
6704 if_type = bf_get(lpfc_sli_intf_if_type,
6705 &phba->sli4_hba.sli_intf);
6706 if_fam = bf_get(lpfc_sli_intf_sli_family,
6707 &phba->sli4_hba.sli_intf);
6708 if (phba->sli4_hba.extents_in_use &&
6709 phba->sli4_hba.rpi_hdrs_in_use) {
6710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6711 "2999 Unsupported SLI4 Parameters "
6712 "Extents and RPI headers enabled.\n");
6713 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6714 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6715 mempool_free(mboxq, phba->mbox_mem_pool);
6717 goto out_free_bsmbx;
6720 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6721 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6722 mempool_free(mboxq, phba->mbox_mem_pool);
6724 goto out_free_bsmbx;
6729 * 1 for cmd, 1 for rsp, NVME adds an extra one
6730 * for boundary conditions in its max_sgl_segment template.
6733 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
6737 * It doesn't matter what family our adapter is in, we are
6738 * limited to 2 Pages, 512 SGEs, for our SGL.
6739 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6741 max_buf_size = (2 * SLI4_PAGE_SIZE);
6744 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6745 * used to create the sg_dma_buf_pool must be calculated.
6747 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
6748 /* Both cfg_enable_bg and cfg_external_dif code paths */
6751 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6752 * the FCP rsp, and a SGE. Sice we have no control
6753 * over how many protection segments the SCSI Layer
6754 * will hand us (ie: there could be one for every block
6755 * in the IO), just allocate enough SGEs to accomidate
6756 * our max amount and we need to limit lpfc_sg_seg_cnt
6757 * to minimize the risk of running out.
6759 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6760 sizeof(struct fcp_rsp) + max_buf_size;
6762 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6763 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
6766 * If supporting DIF, reduce the seg count for scsi to
6767 * allow room for the DIF sges.
6769 if (phba->cfg_enable_bg &&
6770 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
6771 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
6773 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6777 * The scsi_buf for a regular I/O holds the FCP cmnd,
6778 * the FCP rsp, a SGE for each, and a SGE for up to
6779 * cfg_sg_seg_cnt data segments.
6781 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6782 sizeof(struct fcp_rsp) +
6783 ((phba->cfg_sg_seg_cnt + extra) *
6784 sizeof(struct sli4_sge));
6786 /* Total SGEs for scsi_sg_list */
6787 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
6788 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6791 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
6792 * need to post 1 page for the SGL.
6796 if (phba->cfg_xpsgl && !phba->nvmet_support)
6797 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
6798 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
6799 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6801 phba->cfg_sg_dma_buf_size =
6802 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6804 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
6805 sizeof(struct sli4_sge);
6807 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6808 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6809 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
6810 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
6811 "6300 Reducing NVME sg segment "
6813 LPFC_MAX_NVME_SEG_CNT);
6814 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6816 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
6819 /* Initialize the host templates with the updated values. */
6820 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6821 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6822 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
6824 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
6825 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6826 "total:%d scsi:%d nvme:%d\n",
6827 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6828 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6829 phba->cfg_nvme_seg_cnt);
6831 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
6832 i = phba->cfg_sg_dma_buf_size;
6836 phba->lpfc_sg_dma_buf_pool =
6837 dma_pool_create("lpfc_sg_dma_buf_pool",
6839 phba->cfg_sg_dma_buf_size,
6841 if (!phba->lpfc_sg_dma_buf_pool)
6842 goto out_free_bsmbx;
6844 phba->lpfc_cmd_rsp_buf_pool =
6845 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6847 sizeof(struct fcp_cmnd) +
6848 sizeof(struct fcp_rsp),
6850 if (!phba->lpfc_cmd_rsp_buf_pool)
6851 goto out_free_sg_dma_buf;
6853 mempool_free(mboxq, phba->mbox_mem_pool);
6855 /* Verify OAS is supported */
6856 lpfc_sli4_oas_verify(phba);
6858 /* Verify RAS support on adapter */
6859 lpfc_sli4_ras_init(phba);
6861 /* Verify all the SLI4 queues */
6862 rc = lpfc_sli4_queue_verify(phba);
6864 goto out_free_cmd_rsp_buf;
6866 /* Create driver internal CQE event pool */
6867 rc = lpfc_sli4_cq_event_pool_create(phba);
6869 goto out_free_cmd_rsp_buf;
6871 /* Initialize sgl lists per host */
6872 lpfc_init_sgl_list(phba);
6874 /* Allocate and initialize active sgl array */
6875 rc = lpfc_init_active_sgl_array(phba);
6877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6878 "1430 Failed to initialize sgl list.\n");
6879 goto out_destroy_cq_event_pool;
6881 rc = lpfc_sli4_init_rpi_hdrs(phba);
6883 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6884 "1432 Failed to initialize rpi headers.\n");
6885 goto out_free_active_sgl;
6888 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
6889 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6890 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
6892 if (!phba->fcf.fcf_rr_bmask) {
6893 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6894 "2759 Failed allocate memory for FCF round "
6895 "robin failover bmask\n");
6897 goto out_remove_rpi_hdrs;
6900 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
6901 sizeof(struct lpfc_hba_eq_hdl),
6903 if (!phba->sli4_hba.hba_eq_hdl) {
6904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6905 "2572 Failed allocate memory for "
6906 "fast-path per-EQ handle array\n");
6908 goto out_free_fcf_rr_bmask;
6911 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
6912 sizeof(struct lpfc_vector_map_info),
6914 if (!phba->sli4_hba.cpu_map) {
6915 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6916 "3327 Failed allocate memory for msi-x "
6917 "interrupt vector mapping\n");
6919 goto out_free_hba_eq_hdl;
6922 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
6923 if (!phba->sli4_hba.eq_info) {
6924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6925 "3321 Failed allocation for per_cpu stats\n");
6927 goto out_free_hba_cpu_map;
6930 * Enable sr-iov virtual functions if supported and configured
6931 * through the module parameter.
6933 if (phba->cfg_sriov_nr_virtfn > 0) {
6934 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6935 phba->cfg_sriov_nr_virtfn);
6937 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6938 "3020 Requested number of SR-IOV "
6939 "virtual functions (%d) is not "
6941 phba->cfg_sriov_nr_virtfn);
6942 phba->cfg_sriov_nr_virtfn = 0;
6948 out_free_hba_cpu_map:
6949 kfree(phba->sli4_hba.cpu_map);
6950 out_free_hba_eq_hdl:
6951 kfree(phba->sli4_hba.hba_eq_hdl);
6952 out_free_fcf_rr_bmask:
6953 kfree(phba->fcf.fcf_rr_bmask);
6954 out_remove_rpi_hdrs:
6955 lpfc_sli4_remove_rpi_hdrs(phba);
6956 out_free_active_sgl:
6957 lpfc_free_active_sgl(phba);
6958 out_destroy_cq_event_pool:
6959 lpfc_sli4_cq_event_pool_destroy(phba);
6960 out_free_cmd_rsp_buf:
6961 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
6962 phba->lpfc_cmd_rsp_buf_pool = NULL;
6963 out_free_sg_dma_buf:
6964 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
6965 phba->lpfc_sg_dma_buf_pool = NULL;
6967 lpfc_destroy_bootstrap_mbox(phba);
6969 lpfc_mem_free(phba);
6974 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6975 * @phba: pointer to lpfc hba data structure.
6977 * This routine is invoked to unset the driver internal resources set up
6978 * specific for supporting the SLI-4 HBA device it attached to.
6981 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6983 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6985 free_percpu(phba->sli4_hba.eq_info);
6987 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6988 kfree(phba->sli4_hba.cpu_map);
6989 phba->sli4_hba.num_possible_cpu = 0;
6990 phba->sli4_hba.num_present_cpu = 0;
6991 phba->sli4_hba.curr_disp_cpu = 0;
6992 cpumask_clear(&phba->sli4_hba.numa_mask);
6994 /* Free memory allocated for fast-path work queue handles */
6995 kfree(phba->sli4_hba.hba_eq_hdl);
6997 /* Free the allocated rpi headers. */
6998 lpfc_sli4_remove_rpi_hdrs(phba);
6999 lpfc_sli4_remove_rpis(phba);
7001 /* Free eligible FCF index bmask */
7002 kfree(phba->fcf.fcf_rr_bmask);
7004 /* Free the ELS sgl list */
7005 lpfc_free_active_sgl(phba);
7006 lpfc_free_els_sgl_list(phba);
7007 lpfc_free_nvmet_sgl_list(phba);
7009 /* Free the completion queue EQ event pool */
7010 lpfc_sli4_cq_event_release_all(phba);
7011 lpfc_sli4_cq_event_pool_destroy(phba);
7013 /* Release resource identifiers. */
7014 lpfc_sli4_dealloc_resource_identifiers(phba);
7016 /* Free the bsmbx region. */
7017 lpfc_destroy_bootstrap_mbox(phba);
7019 /* Free the SLI Layer memory with SLI4 HBAs */
7020 lpfc_mem_free_all(phba);
7022 /* Free the current connect table */
7023 list_for_each_entry_safe(conn_entry, next_conn_entry,
7024 &phba->fcf_conn_rec_list, list) {
7025 list_del_init(&conn_entry->list);
7033 * lpfc_init_api_table_setup - Set up init api function jump table
7034 * @phba: The hba struct for which this call is being executed.
7035 * @dev_grp: The HBA PCI-Device group number.
7037 * This routine sets up the device INIT interface API function jump table
7040 * Returns: 0 - success, -ENODEV - failure.
7043 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7045 phba->lpfc_hba_init_link = lpfc_hba_init_link;
7046 phba->lpfc_hba_down_link = lpfc_hba_down_link;
7047 phba->lpfc_selective_reset = lpfc_selective_reset;
7049 case LPFC_PCI_DEV_LP:
7050 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
7051 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
7052 phba->lpfc_stop_port = lpfc_stop_port_s3;
7054 case LPFC_PCI_DEV_OC:
7055 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
7056 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
7057 phba->lpfc_stop_port = lpfc_stop_port_s4;
7060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7061 "1431 Invalid HBA PCI-device group: 0x%x\n",
7070 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
7071 * @phba: pointer to lpfc hba data structure.
7073 * This routine is invoked to set up the driver internal resources after the
7074 * device specific resource setup to support the HBA device it attached to.
7078 * other values - error
7081 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
7085 /* Startup the kernel thread for this host adapter. */
7086 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7087 "lpfc_worker_%d", phba->brd_no);
7088 if (IS_ERR(phba->worker_thread)) {
7089 error = PTR_ERR(phba->worker_thread);
7097 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7098 * @phba: pointer to lpfc hba data structure.
7100 * This routine is invoked to unset the driver internal resources set up after
7101 * the device specific resource setup for supporting the HBA device it
7105 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
7108 flush_workqueue(phba->wq);
7109 destroy_workqueue(phba->wq);
7113 /* Stop kernel worker thread */
7114 if (phba->worker_thread)
7115 kthread_stop(phba->worker_thread);
7119 * lpfc_free_iocb_list - Free iocb list.
7120 * @phba: pointer to lpfc hba data structure.
7122 * This routine is invoked to free the driver's IOCB list and memory.
7125 lpfc_free_iocb_list(struct lpfc_hba *phba)
7127 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
7129 spin_lock_irq(&phba->hbalock);
7130 list_for_each_entry_safe(iocbq_entry, iocbq_next,
7131 &phba->lpfc_iocb_list, list) {
7132 list_del(&iocbq_entry->list);
7134 phba->total_iocbq_bufs--;
7136 spin_unlock_irq(&phba->hbalock);
7142 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7143 * @phba: pointer to lpfc hba data structure.
7145 * This routine is invoked to allocate and initizlize the driver's IOCB
7146 * list and set up the IOCB tag array accordingly.
7150 * other values - error
7153 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
7155 struct lpfc_iocbq *iocbq_entry = NULL;
7159 /* Initialize and populate the iocb list per host. */
7160 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
7161 for (i = 0; i < iocb_count; i++) {
7162 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
7163 if (iocbq_entry == NULL) {
7164 printk(KERN_ERR "%s: only allocated %d iocbs of "
7165 "expected %d count. Unloading driver.\n",
7166 __func__, i, iocb_count);
7167 goto out_free_iocbq;
7170 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
7173 printk(KERN_ERR "%s: failed to allocate IOTAG. "
7174 "Unloading driver.\n", __func__);
7175 goto out_free_iocbq;
7177 iocbq_entry->sli4_lxritag = NO_XRI;
7178 iocbq_entry->sli4_xritag = NO_XRI;
7180 spin_lock_irq(&phba->hbalock);
7181 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
7182 phba->total_iocbq_bufs++;
7183 spin_unlock_irq(&phba->hbalock);
7189 lpfc_free_iocb_list(phba);
7195 * lpfc_free_sgl_list - Free a given sgl list.
7196 * @phba: pointer to lpfc hba data structure.
7197 * @sglq_list: pointer to the head of sgl list.
7199 * This routine is invoked to free a give sgl list and memory.
7202 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
7204 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7206 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
7207 list_del(&sglq_entry->list);
7208 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
7214 * lpfc_free_els_sgl_list - Free els sgl list.
7215 * @phba: pointer to lpfc hba data structure.
7217 * This routine is invoked to free the driver's els sgl list and memory.
7220 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
7222 LIST_HEAD(sglq_list);
7224 /* Retrieve all els sgls from driver list */
7225 spin_lock_irq(&phba->hbalock);
7226 spin_lock(&phba->sli4_hba.sgl_list_lock);
7227 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
7228 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7229 spin_unlock_irq(&phba->hbalock);
7231 /* Now free the sgl list */
7232 lpfc_free_sgl_list(phba, &sglq_list);
7236 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
7237 * @phba: pointer to lpfc hba data structure.
7239 * This routine is invoked to free the driver's nvmet sgl list and memory.
7242 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
7244 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7245 LIST_HEAD(sglq_list);
7247 /* Retrieve all nvmet sgls from driver list */
7248 spin_lock_irq(&phba->hbalock);
7249 spin_lock(&phba->sli4_hba.sgl_list_lock);
7250 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
7251 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7252 spin_unlock_irq(&phba->hbalock);
7254 /* Now free the sgl list */
7255 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
7256 list_del(&sglq_entry->list);
7257 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
7261 /* Update the nvmet_xri_cnt to reflect no current sgls.
7262 * The next initialization cycle sets the count and allocates
7263 * the sgls over again.
7265 phba->sli4_hba.nvmet_xri_cnt = 0;
7269 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
7270 * @phba: pointer to lpfc hba data structure.
7272 * This routine is invoked to allocate the driver's active sgl memory.
7273 * This array will hold the sglq_entry's for active IOs.
7276 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
7279 size = sizeof(struct lpfc_sglq *);
7280 size *= phba->sli4_hba.max_cfg_param.max_xri;
7282 phba->sli4_hba.lpfc_sglq_active_list =
7283 kzalloc(size, GFP_KERNEL);
7284 if (!phba->sli4_hba.lpfc_sglq_active_list)
7290 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
7291 * @phba: pointer to lpfc hba data structure.
7293 * This routine is invoked to walk through the array of active sglq entries
7294 * and free all of the resources.
7295 * This is just a place holder for now.
7298 lpfc_free_active_sgl(struct lpfc_hba *phba)
7300 kfree(phba->sli4_hba.lpfc_sglq_active_list);
7304 * lpfc_init_sgl_list - Allocate and initialize sgl list.
7305 * @phba: pointer to lpfc hba data structure.
7307 * This routine is invoked to allocate and initizlize the driver's sgl
7308 * list and set up the sgl xritag tag array accordingly.
7312 lpfc_init_sgl_list(struct lpfc_hba *phba)
7314 /* Initialize and populate the sglq list per host/VF. */
7315 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
7316 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
7317 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
7318 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
7320 /* els xri-sgl book keeping */
7321 phba->sli4_hba.els_xri_cnt = 0;
7323 /* nvme xri-buffer book keeping */
7324 phba->sli4_hba.io_xri_cnt = 0;
7328 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
7329 * @phba: pointer to lpfc hba data structure.
7331 * This routine is invoked to post rpi header templates to the
7332 * port for those SLI4 ports that do not support extents. This routine
7333 * posts a PAGE_SIZE memory region to the port to hold up to
7334 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
7335 * and should be called only when interrupts are disabled.
7339 * -ERROR - otherwise.
7342 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
7345 struct lpfc_rpi_hdr *rpi_hdr;
7347 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
7348 if (!phba->sli4_hba.rpi_hdrs_in_use)
7350 if (phba->sli4_hba.extents_in_use)
7353 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
7355 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7356 "0391 Error during rpi post operation\n");
7357 lpfc_sli4_remove_rpis(phba);
7365 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
7366 * @phba: pointer to lpfc hba data structure.
7368 * This routine is invoked to allocate a single 4KB memory region to
7369 * support rpis and stores them in the phba. This single region
7370 * provides support for up to 64 rpis. The region is used globally
7374 * A valid rpi hdr on success.
7375 * A NULL pointer on any failure.
7377 struct lpfc_rpi_hdr *
7378 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
7380 uint16_t rpi_limit, curr_rpi_range;
7381 struct lpfc_dmabuf *dmabuf;
7382 struct lpfc_rpi_hdr *rpi_hdr;
7385 * If the SLI4 port supports extents, posting the rpi header isn't
7386 * required. Set the expected maximum count and let the actual value
7387 * get set when extents are fully allocated.
7389 if (!phba->sli4_hba.rpi_hdrs_in_use)
7391 if (phba->sli4_hba.extents_in_use)
7394 /* The limit on the logical index is just the max_rpi count. */
7395 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
7397 spin_lock_irq(&phba->hbalock);
7399 * Establish the starting RPI in this header block. The starting
7400 * rpi is normalized to a zero base because the physical rpi is
7403 curr_rpi_range = phba->sli4_hba.next_rpi;
7404 spin_unlock_irq(&phba->hbalock);
7406 /* Reached full RPI range */
7407 if (curr_rpi_range == rpi_limit)
7411 * First allocate the protocol header region for the port. The
7412 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
7414 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7418 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
7419 LPFC_HDR_TEMPLATE_SIZE,
7420 &dmabuf->phys, GFP_KERNEL);
7421 if (!dmabuf->virt) {
7423 goto err_free_dmabuf;
7426 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
7428 goto err_free_coherent;
7431 /* Save the rpi header data for cleanup later. */
7432 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
7434 goto err_free_coherent;
7436 rpi_hdr->dmabuf = dmabuf;
7437 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
7438 rpi_hdr->page_count = 1;
7439 spin_lock_irq(&phba->hbalock);
7441 /* The rpi_hdr stores the logical index only. */
7442 rpi_hdr->start_rpi = curr_rpi_range;
7443 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
7444 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
7446 spin_unlock_irq(&phba->hbalock);
7450 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
7451 dmabuf->virt, dmabuf->phys);
7458 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7459 * @phba: pointer to lpfc hba data structure.
7461 * This routine is invoked to remove all memory resources allocated
7462 * to support rpis for SLI4 ports not supporting extents. This routine
7463 * presumes the caller has released all rpis consumed by fabric or port
7464 * logins and is prepared to have the header pages removed.
7467 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
7469 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
7471 if (!phba->sli4_hba.rpi_hdrs_in_use)
7474 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
7475 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
7476 list_del(&rpi_hdr->list);
7477 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
7478 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
7479 kfree(rpi_hdr->dmabuf);
7483 /* There are no rpis available to the port now. */
7484 phba->sli4_hba.next_rpi = 0;
7488 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7489 * @pdev: pointer to pci device data structure.
7491 * This routine is invoked to allocate the driver hba data structure for an
7492 * HBA device. If the allocation is successful, the phba reference to the
7493 * PCI device data structure is set.
7496 * pointer to @phba - successful
7499 static struct lpfc_hba *
7500 lpfc_hba_alloc(struct pci_dev *pdev)
7502 struct lpfc_hba *phba;
7504 /* Allocate memory for HBA structure */
7505 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
7507 dev_err(&pdev->dev, "failed to allocate hba struct\n");
7511 /* Set reference to PCI device in HBA structure */
7512 phba->pcidev = pdev;
7514 /* Assign an unused board number */
7515 phba->brd_no = lpfc_get_instance();
7516 if (phba->brd_no < 0) {
7520 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
7522 spin_lock_init(&phba->ct_ev_lock);
7523 INIT_LIST_HEAD(&phba->ct_ev_waiters);
7529 * lpfc_hba_free - Free driver hba data structure with a device.
7530 * @phba: pointer to lpfc hba data structure.
7532 * This routine is invoked to free the driver hba data structure with an
7536 lpfc_hba_free(struct lpfc_hba *phba)
7538 if (phba->sli_rev == LPFC_SLI_REV4)
7539 kfree(phba->sli4_hba.hdwq);
7541 /* Release the driver assigned board number */
7542 idr_remove(&lpfc_hba_index, phba->brd_no);
7544 /* Free memory allocated with sli3 rings */
7545 kfree(phba->sli.sli3_ring);
7546 phba->sli.sli3_ring = NULL;
7553 * lpfc_create_shost - Create hba physical port with associated scsi host.
7554 * @phba: pointer to lpfc hba data structure.
7556 * This routine is invoked to create HBA physical port and associate a SCSI
7561 * other values - error
7564 lpfc_create_shost(struct lpfc_hba *phba)
7566 struct lpfc_vport *vport;
7567 struct Scsi_Host *shost;
7569 /* Initialize HBA FC structure */
7570 phba->fc_edtov = FF_DEF_EDTOV;
7571 phba->fc_ratov = FF_DEF_RATOV;
7572 phba->fc_altov = FF_DEF_ALTOV;
7573 phba->fc_arbtov = FF_DEF_ARBTOV;
7575 atomic_set(&phba->sdev_cnt, 0);
7576 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
7580 shost = lpfc_shost_from_vport(vport);
7581 phba->pport = vport;
7583 if (phba->nvmet_support) {
7584 /* Only 1 vport (pport) will support NVME target */
7585 phba->targetport = NULL;
7586 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
7587 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
7588 "6076 NVME Target Found\n");
7591 lpfc_debugfs_initialize(vport);
7592 /* Put reference to SCSI host to driver's device private data */
7593 pci_set_drvdata(phba->pcidev, shost);
7596 * At this point we are fully registered with PSA. In addition,
7597 * any initial discovery should be completed.
7599 vport->load_flag |= FC_ALLOW_FDMI;
7600 if (phba->cfg_enable_SmartSAN ||
7601 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
7603 /* Setup appropriate attribute masks */
7604 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
7605 if (phba->cfg_enable_SmartSAN)
7606 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
7608 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7614 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7615 * @phba: pointer to lpfc hba data structure.
7617 * This routine is invoked to destroy HBA physical port and the associated
7621 lpfc_destroy_shost(struct lpfc_hba *phba)
7623 struct lpfc_vport *vport = phba->pport;
7625 /* Destroy physical port that associated with the SCSI host */
7626 destroy_port(vport);
7632 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7633 * @phba: pointer to lpfc hba data structure.
7634 * @shost: the shost to be used to detect Block guard settings.
7636 * This routine sets up the local Block guard protocol settings for @shost.
7637 * This routine also allocates memory for debugging bg buffers.
7640 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7645 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7646 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7647 "1478 Registering BlockGuard with the "
7650 old_mask = phba->cfg_prot_mask;
7651 old_guard = phba->cfg_prot_guard;
7653 /* Only allow supported values */
7654 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
7655 SHOST_DIX_TYPE0_PROTECTION |
7656 SHOST_DIX_TYPE1_PROTECTION);
7657 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7658 SHOST_DIX_GUARD_CRC);
7660 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
7661 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7662 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
7664 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7665 if ((old_mask != phba->cfg_prot_mask) ||
7666 (old_guard != phba->cfg_prot_guard))
7667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7668 "1475 Registering BlockGuard with the "
7669 "SCSI layer: mask %d guard %d\n",
7670 phba->cfg_prot_mask,
7671 phba->cfg_prot_guard);
7673 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7674 scsi_host_set_guard(shost, phba->cfg_prot_guard);
7676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7677 "1479 Not Registering BlockGuard with the SCSI "
7678 "layer, Bad protection parameters: %d %d\n",
7679 old_mask, old_guard);
7684 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7685 * @phba: pointer to lpfc hba data structure.
7687 * This routine is invoked to perform all the necessary post initialization
7688 * setup for the device.
7691 lpfc_post_init_setup(struct lpfc_hba *phba)
7693 struct Scsi_Host *shost;
7694 struct lpfc_adapter_event_header adapter_event;
7696 /* Get the default values for Model Name and Description */
7697 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7700 * hba setup may have changed the hba_queue_depth so we need to
7701 * adjust the value of can_queue.
7703 shost = pci_get_drvdata(phba->pcidev);
7704 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7706 lpfc_host_attrib_init(shost);
7708 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7709 spin_lock_irq(shost->host_lock);
7710 lpfc_poll_start_timer(phba);
7711 spin_unlock_irq(shost->host_lock);
7714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7715 "0428 Perform SCSI scan\n");
7716 /* Send board arrival event to upper layer */
7717 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7718 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7719 fc_host_post_vendor_event(shost, fc_get_event_number(),
7720 sizeof(adapter_event),
7721 (char *) &adapter_event,
7727 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7728 * @phba: pointer to lpfc hba data structure.
7730 * This routine is invoked to set up the PCI device memory space for device
7731 * with SLI-3 interface spec.
7735 * other values - error
7738 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7740 struct pci_dev *pdev = phba->pcidev;
7741 unsigned long bar0map_len, bar2map_len;
7749 /* Set the device DMA mask size */
7750 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7752 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7757 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7758 * required by each mapping.
7760 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7761 bar0map_len = pci_resource_len(pdev, 0);
7763 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7764 bar2map_len = pci_resource_len(pdev, 2);
7766 /* Map HBA SLIM to a kernel virtual address. */
7767 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7768 if (!phba->slim_memmap_p) {
7769 dev_printk(KERN_ERR, &pdev->dev,
7770 "ioremap failed for SLIM memory.\n");
7774 /* Map HBA Control Registers to a kernel virtual address. */
7775 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7776 if (!phba->ctrl_regs_memmap_p) {
7777 dev_printk(KERN_ERR, &pdev->dev,
7778 "ioremap failed for HBA control registers.\n");
7779 goto out_iounmap_slim;
7782 /* Allocate memory for SLI-2 structures */
7783 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7784 &phba->slim2p.phys, GFP_KERNEL);
7785 if (!phba->slim2p.virt)
7788 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
7789 phba->mbox_ext = (phba->slim2p.virt +
7790 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
7791 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7792 phba->IOCBs = (phba->slim2p.virt +
7793 offsetof(struct lpfc_sli2_slim, IOCBs));
7795 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7796 lpfc_sli_hbq_size(),
7797 &phba->hbqslimp.phys,
7799 if (!phba->hbqslimp.virt)
7802 hbq_count = lpfc_sli_hbq_count();
7803 ptr = phba->hbqslimp.virt;
7804 for (i = 0; i < hbq_count; ++i) {
7805 phba->hbqs[i].hbq_virt = ptr;
7806 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7807 ptr += (lpfc_hbq_defs[i]->entry_count *
7808 sizeof(struct lpfc_hbq_entry));
7810 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7811 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7813 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7815 phba->MBslimaddr = phba->slim_memmap_p;
7816 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7817 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7818 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7819 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
7824 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7825 phba->slim2p.virt, phba->slim2p.phys);
7827 iounmap(phba->ctrl_regs_memmap_p);
7829 iounmap(phba->slim_memmap_p);
7835 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7836 * @phba: pointer to lpfc hba data structure.
7838 * This routine is invoked to unset the PCI device memory space for device
7839 * with SLI-3 interface spec.
7842 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7844 struct pci_dev *pdev;
7846 /* Obtain PCI device reference */
7850 pdev = phba->pcidev;
7852 /* Free coherent DMA memory allocated */
7853 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7854 phba->hbqslimp.virt, phba->hbqslimp.phys);
7855 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7856 phba->slim2p.virt, phba->slim2p.phys);
7858 /* I/O memory unmap */
7859 iounmap(phba->ctrl_regs_memmap_p);
7860 iounmap(phba->slim_memmap_p);
7866 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7867 * @phba: pointer to lpfc hba data structure.
7869 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7870 * done and check status.
7872 * Return 0 if successful, otherwise -ENODEV.
7875 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7877 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7878 struct lpfc_register reg_data;
7879 int i, port_error = 0;
7882 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7883 memset(®_data, 0, sizeof(reg_data));
7884 if (!phba->sli4_hba.PSMPHRregaddr)
7887 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7888 for (i = 0; i < 3000; i++) {
7889 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7890 &portsmphr_reg.word0) ||
7891 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
7892 /* Port has a fatal POST error, break out */
7893 port_error = -ENODEV;
7896 if (LPFC_POST_STAGE_PORT_READY ==
7897 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
7903 * If there was a port error during POST, then don't proceed with
7904 * other register reads as the data may not be valid. Just exit.
7907 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7908 "1408 Port Failed POST - portsmphr=0x%x, "
7909 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7910 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7911 portsmphr_reg.word0,
7912 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7913 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7914 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7915 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7916 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7917 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7918 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7919 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7921 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7922 "2534 Device Info: SLIFamily=0x%x, "
7923 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7924 "SLIHint_2=0x%x, FT=0x%x\n",
7925 bf_get(lpfc_sli_intf_sli_family,
7926 &phba->sli4_hba.sli_intf),
7927 bf_get(lpfc_sli_intf_slirev,
7928 &phba->sli4_hba.sli_intf),
7929 bf_get(lpfc_sli_intf_if_type,
7930 &phba->sli4_hba.sli_intf),
7931 bf_get(lpfc_sli_intf_sli_hint1,
7932 &phba->sli4_hba.sli_intf),
7933 bf_get(lpfc_sli_intf_sli_hint2,
7934 &phba->sli4_hba.sli_intf),
7935 bf_get(lpfc_sli_intf_func_type,
7936 &phba->sli4_hba.sli_intf));
7938 * Check for other Port errors during the initialization
7939 * process. Fail the load if the port did not come up
7942 if_type = bf_get(lpfc_sli_intf_if_type,
7943 &phba->sli4_hba.sli_intf);
7945 case LPFC_SLI_INTF_IF_TYPE_0:
7946 phba->sli4_hba.ue_mask_lo =
7947 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7948 phba->sli4_hba.ue_mask_hi =
7949 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7951 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7953 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7954 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7955 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7957 "1422 Unrecoverable Error "
7958 "Detected during POST "
7959 "uerr_lo_reg=0x%x, "
7960 "uerr_hi_reg=0x%x, "
7961 "ue_mask_lo_reg=0x%x, "
7962 "ue_mask_hi_reg=0x%x\n",
7965 phba->sli4_hba.ue_mask_lo,
7966 phba->sli4_hba.ue_mask_hi);
7967 port_error = -ENODEV;
7970 case LPFC_SLI_INTF_IF_TYPE_2:
7971 case LPFC_SLI_INTF_IF_TYPE_6:
7972 /* Final checks. The port status should be clean. */
7973 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7975 (bf_get(lpfc_sliport_status_err, ®_data) &&
7976 !bf_get(lpfc_sliport_status_rn, ®_data))) {
7977 phba->work_status[0] =
7978 readl(phba->sli4_hba.u.if_type2.
7980 phba->work_status[1] =
7981 readl(phba->sli4_hba.u.if_type2.
7983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7984 "2888 Unrecoverable port error "
7985 "following POST: port status reg "
7986 "0x%x, port_smphr reg 0x%x, "
7987 "error 1=0x%x, error 2=0x%x\n",
7989 portsmphr_reg.word0,
7990 phba->work_status[0],
7991 phba->work_status[1]);
7992 port_error = -ENODEV;
7995 case LPFC_SLI_INTF_IF_TYPE_1:
8004 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
8005 * @phba: pointer to lpfc hba data structure.
8006 * @if_type: The SLI4 interface type getting configured.
8008 * This routine is invoked to set up SLI4 BAR0 PCI config space register
8012 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
8015 case LPFC_SLI_INTF_IF_TYPE_0:
8016 phba->sli4_hba.u.if_type0.UERRLOregaddr =
8017 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
8018 phba->sli4_hba.u.if_type0.UERRHIregaddr =
8019 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
8020 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
8021 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
8022 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
8023 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
8024 phba->sli4_hba.SLIINTFregaddr =
8025 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8027 case LPFC_SLI_INTF_IF_TYPE_2:
8028 phba->sli4_hba.u.if_type2.EQDregaddr =
8029 phba->sli4_hba.conf_regs_memmap_p +
8030 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8031 phba->sli4_hba.u.if_type2.ERR1regaddr =
8032 phba->sli4_hba.conf_regs_memmap_p +
8033 LPFC_CTL_PORT_ER1_OFFSET;
8034 phba->sli4_hba.u.if_type2.ERR2regaddr =
8035 phba->sli4_hba.conf_regs_memmap_p +
8036 LPFC_CTL_PORT_ER2_OFFSET;
8037 phba->sli4_hba.u.if_type2.CTRLregaddr =
8038 phba->sli4_hba.conf_regs_memmap_p +
8039 LPFC_CTL_PORT_CTL_OFFSET;
8040 phba->sli4_hba.u.if_type2.STATUSregaddr =
8041 phba->sli4_hba.conf_regs_memmap_p +
8042 LPFC_CTL_PORT_STA_OFFSET;
8043 phba->sli4_hba.SLIINTFregaddr =
8044 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8045 phba->sli4_hba.PSMPHRregaddr =
8046 phba->sli4_hba.conf_regs_memmap_p +
8047 LPFC_CTL_PORT_SEM_OFFSET;
8048 phba->sli4_hba.RQDBregaddr =
8049 phba->sli4_hba.conf_regs_memmap_p +
8050 LPFC_ULP0_RQ_DOORBELL;
8051 phba->sli4_hba.WQDBregaddr =
8052 phba->sli4_hba.conf_regs_memmap_p +
8053 LPFC_ULP0_WQ_DOORBELL;
8054 phba->sli4_hba.CQDBregaddr =
8055 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
8056 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
8057 phba->sli4_hba.MQDBregaddr =
8058 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
8059 phba->sli4_hba.BMBXregaddr =
8060 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8062 case LPFC_SLI_INTF_IF_TYPE_6:
8063 phba->sli4_hba.u.if_type2.EQDregaddr =
8064 phba->sli4_hba.conf_regs_memmap_p +
8065 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8066 phba->sli4_hba.u.if_type2.ERR1regaddr =
8067 phba->sli4_hba.conf_regs_memmap_p +
8068 LPFC_CTL_PORT_ER1_OFFSET;
8069 phba->sli4_hba.u.if_type2.ERR2regaddr =
8070 phba->sli4_hba.conf_regs_memmap_p +
8071 LPFC_CTL_PORT_ER2_OFFSET;
8072 phba->sli4_hba.u.if_type2.CTRLregaddr =
8073 phba->sli4_hba.conf_regs_memmap_p +
8074 LPFC_CTL_PORT_CTL_OFFSET;
8075 phba->sli4_hba.u.if_type2.STATUSregaddr =
8076 phba->sli4_hba.conf_regs_memmap_p +
8077 LPFC_CTL_PORT_STA_OFFSET;
8078 phba->sli4_hba.PSMPHRregaddr =
8079 phba->sli4_hba.conf_regs_memmap_p +
8080 LPFC_CTL_PORT_SEM_OFFSET;
8081 phba->sli4_hba.BMBXregaddr =
8082 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8084 case LPFC_SLI_INTF_IF_TYPE_1:
8086 dev_printk(KERN_ERR, &phba->pcidev->dev,
8087 "FATAL - unsupported SLI4 interface type - %d\n",
8094 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8095 * @phba: pointer to lpfc hba data structure.
8097 * This routine is invoked to set up SLI4 BAR1 register memory map.
8100 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
8103 case LPFC_SLI_INTF_IF_TYPE_0:
8104 phba->sli4_hba.PSMPHRregaddr =
8105 phba->sli4_hba.ctrl_regs_memmap_p +
8106 LPFC_SLIPORT_IF0_SMPHR;
8107 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8109 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8111 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8114 case LPFC_SLI_INTF_IF_TYPE_6:
8115 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8116 LPFC_IF6_RQ_DOORBELL;
8117 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8118 LPFC_IF6_WQ_DOORBELL;
8119 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8120 LPFC_IF6_CQ_DOORBELL;
8121 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8122 LPFC_IF6_EQ_DOORBELL;
8123 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8124 LPFC_IF6_MQ_DOORBELL;
8126 case LPFC_SLI_INTF_IF_TYPE_2:
8127 case LPFC_SLI_INTF_IF_TYPE_1:
8129 dev_err(&phba->pcidev->dev,
8130 "FATAL - unsupported SLI4 interface type - %d\n",
8137 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8138 * @phba: pointer to lpfc hba data structure.
8139 * @vf: virtual function number
8141 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8142 * based on the given viftual function number, @vf.
8144 * Return 0 if successful, otherwise -ENODEV.
8147 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
8149 if (vf > LPFC_VIR_FUNC_MAX)
8152 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8153 vf * LPFC_VFR_PAGE_SIZE +
8154 LPFC_ULP0_RQ_DOORBELL);
8155 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8156 vf * LPFC_VFR_PAGE_SIZE +
8157 LPFC_ULP0_WQ_DOORBELL);
8158 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8159 vf * LPFC_VFR_PAGE_SIZE +
8160 LPFC_EQCQ_DOORBELL);
8161 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
8162 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8163 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
8164 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8165 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
8170 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
8171 * @phba: pointer to lpfc hba data structure.
8173 * This routine is invoked to create the bootstrap mailbox
8174 * region consistent with the SLI-4 interface spec. This
8175 * routine allocates all memory necessary to communicate
8176 * mailbox commands to the port and sets up all alignment
8177 * needs. No locks are expected to be held when calling
8182 * -ENOMEM - could not allocated memory.
8185 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
8188 struct lpfc_dmabuf *dmabuf;
8189 struct dma_address *dma_address;
8193 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8198 * The bootstrap mailbox region is comprised of 2 parts
8199 * plus an alignment restriction of 16 bytes.
8201 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
8202 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
8203 &dmabuf->phys, GFP_KERNEL);
8204 if (!dmabuf->virt) {
8210 * Initialize the bootstrap mailbox pointers now so that the register
8211 * operations are simple later. The mailbox dma address is required
8212 * to be 16-byte aligned. Also align the virtual memory as each
8213 * maibox is copied into the bmbx mailbox region before issuing the
8214 * command to the port.
8216 phba->sli4_hba.bmbx.dmabuf = dmabuf;
8217 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
8219 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
8220 LPFC_ALIGN_16_BYTE);
8221 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
8222 LPFC_ALIGN_16_BYTE);
8225 * Set the high and low physical addresses now. The SLI4 alignment
8226 * requirement is 16 bytes and the mailbox is posted to the port
8227 * as two 30-bit addresses. The other data is a bit marking whether
8228 * the 30-bit address is the high or low address.
8229 * Upcast bmbx aphys to 64bits so shift instruction compiles
8230 * clean on 32 bit machines.
8232 dma_address = &phba->sli4_hba.bmbx.dma_address;
8233 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
8234 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
8235 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
8236 LPFC_BMBX_BIT1_ADDR_HI);
8238 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
8239 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
8240 LPFC_BMBX_BIT1_ADDR_LO);
8245 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
8246 * @phba: pointer to lpfc hba data structure.
8248 * This routine is invoked to teardown the bootstrap mailbox
8249 * region and release all host resources. This routine requires
8250 * the caller to ensure all mailbox commands recovered, no
8251 * additional mailbox comands are sent, and interrupts are disabled
8252 * before calling this routine.
8256 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
8258 dma_free_coherent(&phba->pcidev->dev,
8259 phba->sli4_hba.bmbx.bmbx_size,
8260 phba->sli4_hba.bmbx.dmabuf->virt,
8261 phba->sli4_hba.bmbx.dmabuf->phys);
8263 kfree(phba->sli4_hba.bmbx.dmabuf);
8264 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
8267 static const char * const lpfc_topo_to_str[] = {
8278 * lpfc_map_topology - Map the topology read from READ_CONFIG
8279 * @phba: pointer to lpfc hba data structure.
8280 * @rdconf: pointer to read config data
8282 * This routine is invoked to map the topology values as read
8283 * from the read config mailbox command. If the persistent
8284 * topology feature is supported, the firmware will provide the
8285 * saved topology information to be used in INIT_LINK
8288 #define LINK_FLAGS_DEF 0x0
8289 #define LINK_FLAGS_P2P 0x1
8290 #define LINK_FLAGS_LOOP 0x2
8292 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
8296 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
8297 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
8298 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
8300 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8301 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
8304 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8305 "2019 FW does not support persistent topology "
8306 "Using driver parameter defined value [%s]",
8307 lpfc_topo_to_str[phba->cfg_topology]);
8310 /* FW supports persistent topology - override module parameter value */
8311 phba->hba_flag |= HBA_PERSISTENT_TOPO;
8312 switch (phba->pcidev->device) {
8313 case PCI_DEVICE_ID_LANCER_G7_FC:
8314 case PCI_DEVICE_ID_LANCER_G6_FC:
8316 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
8317 ? FLAGS_TOPOLOGY_MODE_LOOP
8318 : FLAGS_TOPOLOGY_MODE_PT_PT);
8320 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
8325 /* If topology failover set - pt is '0' or '1' */
8326 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
8327 FLAGS_TOPOLOGY_MODE_LOOP_PT);
8329 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
8330 ? FLAGS_TOPOLOGY_MODE_PT_PT
8331 : FLAGS_TOPOLOGY_MODE_LOOP);
8335 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
8336 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8337 "2020 Using persistent topology value [%s]",
8338 lpfc_topo_to_str[phba->cfg_topology]);
8340 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8341 "2021 Invalid topology values from FW "
8342 "Using driver parameter defined value [%s]",
8343 lpfc_topo_to_str[phba->cfg_topology]);
8348 * lpfc_sli4_read_config - Get the config parameters.
8349 * @phba: pointer to lpfc hba data structure.
8351 * This routine is invoked to read the configuration parameters from the HBA.
8352 * The configuration parameters are used to set the base and maximum values
8353 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
8354 * allocation for the port.
8358 * -ENOMEM - No available memory
8359 * -EIO - The mailbox failed to complete successfully.
8362 lpfc_sli4_read_config(struct lpfc_hba *phba)
8365 struct lpfc_mbx_read_config *rd_config;
8366 union lpfc_sli4_cfg_shdr *shdr;
8367 uint32_t shdr_status, shdr_add_status;
8368 struct lpfc_mbx_get_func_cfg *get_func_cfg;
8369 struct lpfc_rsrc_desc_fcfcoe *desc;
8371 uint16_t forced_link_speed;
8372 uint32_t if_type, qmin;
8373 int length, i, rc = 0, rc2;
8375 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8377 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8378 "2011 Unable to allocate memory for issuing "
8379 "SLI_CONFIG_SPECIAL mailbox command\n");
8383 lpfc_read_config(phba, pmb);
8385 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8386 if (rc != MBX_SUCCESS) {
8387 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8388 "2012 Mailbox failed , mbxCmd x%x "
8389 "READ_CONFIG, mbxStatus x%x\n",
8390 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8391 bf_get(lpfc_mqe_status, &pmb->u.mqe));
8394 rd_config = &pmb->u.mqe.un.rd_config;
8395 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
8396 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
8397 phba->sli4_hba.lnk_info.lnk_tp =
8398 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
8399 phba->sli4_hba.lnk_info.lnk_no =
8400 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
8401 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8402 "3081 lnk_type:%d, lnk_numb:%d\n",
8403 phba->sli4_hba.lnk_info.lnk_tp,
8404 phba->sli4_hba.lnk_info.lnk_no);
8406 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8407 "3082 Mailbox (x%x) returned ldv:x0\n",
8408 bf_get(lpfc_mqe_command, &pmb->u.mqe));
8409 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
8410 phba->bbcredit_support = 1;
8411 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
8414 phba->sli4_hba.conf_trunk =
8415 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
8416 phba->sli4_hba.extents_in_use =
8417 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
8418 phba->sli4_hba.max_cfg_param.max_xri =
8419 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
8420 /* Reduce resource usage in kdump environment */
8421 if (is_kdump_kernel() &&
8422 phba->sli4_hba.max_cfg_param.max_xri > 512)
8423 phba->sli4_hba.max_cfg_param.max_xri = 512;
8424 phba->sli4_hba.max_cfg_param.xri_base =
8425 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
8426 phba->sli4_hba.max_cfg_param.max_vpi =
8427 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
8428 /* Limit the max we support */
8429 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
8430 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
8431 phba->sli4_hba.max_cfg_param.vpi_base =
8432 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
8433 phba->sli4_hba.max_cfg_param.max_rpi =
8434 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
8435 phba->sli4_hba.max_cfg_param.rpi_base =
8436 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
8437 phba->sli4_hba.max_cfg_param.max_vfi =
8438 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
8439 phba->sli4_hba.max_cfg_param.vfi_base =
8440 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
8441 phba->sli4_hba.max_cfg_param.max_fcfi =
8442 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
8443 phba->sli4_hba.max_cfg_param.max_eq =
8444 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
8445 phba->sli4_hba.max_cfg_param.max_rq =
8446 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
8447 phba->sli4_hba.max_cfg_param.max_wq =
8448 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
8449 phba->sli4_hba.max_cfg_param.max_cq =
8450 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
8451 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
8452 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
8453 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
8454 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
8455 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
8456 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
8457 phba->max_vports = phba->max_vpi;
8458 lpfc_map_topology(phba, rd_config);
8459 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8460 "2003 cfg params Extents? %d "
8465 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
8466 phba->sli4_hba.extents_in_use,
8467 phba->sli4_hba.max_cfg_param.xri_base,
8468 phba->sli4_hba.max_cfg_param.max_xri,
8469 phba->sli4_hba.max_cfg_param.vpi_base,
8470 phba->sli4_hba.max_cfg_param.max_vpi,
8471 phba->sli4_hba.max_cfg_param.vfi_base,
8472 phba->sli4_hba.max_cfg_param.max_vfi,
8473 phba->sli4_hba.max_cfg_param.rpi_base,
8474 phba->sli4_hba.max_cfg_param.max_rpi,
8475 phba->sli4_hba.max_cfg_param.max_fcfi,
8476 phba->sli4_hba.max_cfg_param.max_eq,
8477 phba->sli4_hba.max_cfg_param.max_cq,
8478 phba->sli4_hba.max_cfg_param.max_wq,
8479 phba->sli4_hba.max_cfg_param.max_rq);
8482 * Calculate queue resources based on how
8483 * many WQ/CQ/EQs are available.
8485 qmin = phba->sli4_hba.max_cfg_param.max_wq;
8486 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
8487 qmin = phba->sli4_hba.max_cfg_param.max_cq;
8488 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
8489 qmin = phba->sli4_hba.max_cfg_param.max_eq;
8491 * Whats left after this can go toward NVME / FCP.
8492 * The minus 4 accounts for ELS, NVME LS, MBOX
8493 * plus one extra. When configured for
8494 * NVMET, FCP io channel WQs are not created.
8498 /* Check to see if there is enough for NVME */
8499 if ((phba->cfg_irq_chann > qmin) ||
8500 (phba->cfg_hdw_queue > qmin)) {
8501 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8502 "2005 Reducing Queues: "
8503 "WQ %d CQ %d EQ %d: min %d: "
8505 phba->sli4_hba.max_cfg_param.max_wq,
8506 phba->sli4_hba.max_cfg_param.max_cq,
8507 phba->sli4_hba.max_cfg_param.max_eq,
8508 qmin, phba->cfg_irq_chann,
8509 phba->cfg_hdw_queue);
8511 if (phba->cfg_irq_chann > qmin)
8512 phba->cfg_irq_chann = qmin;
8513 if (phba->cfg_hdw_queue > qmin)
8514 phba->cfg_hdw_queue = qmin;
8521 /* Update link speed if forced link speed is supported */
8522 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8523 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
8525 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8526 if (forced_link_speed) {
8527 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8529 switch (forced_link_speed) {
8531 phba->cfg_link_speed =
8532 LPFC_USER_LINK_SPEED_1G;
8535 phba->cfg_link_speed =
8536 LPFC_USER_LINK_SPEED_2G;
8539 phba->cfg_link_speed =
8540 LPFC_USER_LINK_SPEED_4G;
8543 phba->cfg_link_speed =
8544 LPFC_USER_LINK_SPEED_8G;
8546 case LINK_SPEED_10G:
8547 phba->cfg_link_speed =
8548 LPFC_USER_LINK_SPEED_10G;
8550 case LINK_SPEED_16G:
8551 phba->cfg_link_speed =
8552 LPFC_USER_LINK_SPEED_16G;
8554 case LINK_SPEED_32G:
8555 phba->cfg_link_speed =
8556 LPFC_USER_LINK_SPEED_32G;
8558 case LINK_SPEED_64G:
8559 phba->cfg_link_speed =
8560 LPFC_USER_LINK_SPEED_64G;
8563 phba->cfg_link_speed =
8564 LPFC_USER_LINK_SPEED_AUTO;
8567 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8568 "0047 Unrecognized link "
8571 phba->cfg_link_speed =
8572 LPFC_USER_LINK_SPEED_AUTO;
8577 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
8578 length = phba->sli4_hba.max_cfg_param.max_xri -
8579 lpfc_sli4_get_els_iocb_cnt(phba);
8580 if (phba->cfg_hba_queue_depth > length) {
8581 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8582 "3361 HBA queue depth changed from %d to %d\n",
8583 phba->cfg_hba_queue_depth, length);
8584 phba->cfg_hba_queue_depth = length;
8587 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
8588 LPFC_SLI_INTF_IF_TYPE_2)
8591 /* get the pf# and vf# for SLI4 if_type 2 port */
8592 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8593 sizeof(struct lpfc_sli4_cfg_mhdr));
8594 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8595 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8596 length, LPFC_SLI4_MBX_EMBED);
8598 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8599 shdr = (union lpfc_sli4_cfg_shdr *)
8600 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8601 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8602 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8603 if (rc2 || shdr_status || shdr_add_status) {
8604 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8605 "3026 Mailbox failed , mbxCmd x%x "
8606 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8607 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8608 bf_get(lpfc_mqe_status, &pmb->u.mqe));
8612 /* search for fc_fcoe resrouce descriptor */
8613 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
8615 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8616 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8617 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8618 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8619 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8620 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8623 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
8624 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
8625 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
8626 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
8627 phba->sli4_hba.iov.pf_number =
8628 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8629 phba->sli4_hba.iov.vf_number =
8630 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8635 if (i < LPFC_RSRC_DESC_MAX_NUM)
8636 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8637 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8638 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8639 phba->sli4_hba.iov.vf_number);
8641 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8642 "3028 GET_FUNCTION_CONFIG: failed to find "
8643 "Resource Descriptor:x%x\n",
8644 LPFC_RSRC_DESC_TYPE_FCFCOE);
8647 mempool_free(pmb, phba->mbox_mem_pool);
8652 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
8653 * @phba: pointer to lpfc hba data structure.
8655 * This routine is invoked to setup the port-side endian order when
8656 * the port if_type is 0. This routine has no function for other
8661 * -ENOMEM - No available memory
8662 * -EIO - The mailbox failed to complete successfully.
8665 lpfc_setup_endian_order(struct lpfc_hba *phba)
8667 LPFC_MBOXQ_t *mboxq;
8668 uint32_t if_type, rc = 0;
8669 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8670 HOST_ENDIAN_HIGH_WORD1};
8672 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8674 case LPFC_SLI_INTF_IF_TYPE_0:
8675 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8679 "0492 Unable to allocate memory for "
8680 "issuing SLI_CONFIG_SPECIAL mailbox "
8686 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8687 * two words to contain special data values and no other data.
8689 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8690 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8691 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8692 if (rc != MBX_SUCCESS) {
8693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8694 "0493 SLI_CONFIG_SPECIAL mailbox "
8695 "failed with status x%x\n",
8699 mempool_free(mboxq, phba->mbox_mem_pool);
8701 case LPFC_SLI_INTF_IF_TYPE_6:
8702 case LPFC_SLI_INTF_IF_TYPE_2:
8703 case LPFC_SLI_INTF_IF_TYPE_1:
8711 * lpfc_sli4_queue_verify - Verify and update EQ counts
8712 * @phba: pointer to lpfc hba data structure.
8714 * This routine is invoked to check the user settable queue counts for EQs.
8715 * After this routine is called the counts will be set to valid values that
8716 * adhere to the constraints of the system's interrupt vectors and the port's
8721 * -ENOMEM - No available memory
8724 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
8727 * Sanity check for configured queue parameters against the run-time
8731 if (phba->nvmet_support) {
8732 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
8733 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
8734 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8735 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
8738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8739 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
8740 phba->cfg_hdw_queue, phba->cfg_irq_chann,
8741 phba->cfg_nvmet_mrq);
8743 /* Get EQ depth from module parameter, fake the default for now */
8744 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8745 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8747 /* Get CQ depth from module parameter, fake the default for now */
8748 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8749 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8754 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
8756 struct lpfc_queue *qdesc;
8760 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
8761 /* Create Fast Path IO CQs */
8762 if (phba->enab_exp_wqcq_pages)
8763 /* Increase the CQ size when WQEs contain an embedded cdb */
8764 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8765 phba->sli4_hba.cq_esize,
8766 LPFC_CQE_EXP_COUNT, cpu);
8769 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8770 phba->sli4_hba.cq_esize,
8771 phba->sli4_hba.cq_ecount, cpu);
8773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8774 "0499 Failed allocate fast-path IO CQ (%d)\n", idx);
8777 qdesc->qe_valid = 1;
8780 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
8782 /* Create Fast Path IO WQs */
8783 if (phba->enab_exp_wqcq_pages) {
8784 /* Increase the WQ size when WQEs contain an embedded cdb */
8785 wqesize = (phba->fcp_embed_io) ?
8786 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
8787 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8789 LPFC_WQE_EXP_COUNT, cpu);
8791 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8792 phba->sli4_hba.wq_esize,
8793 phba->sli4_hba.wq_ecount, cpu);
8796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8797 "0503 Failed allocate fast-path IO WQ (%d)\n",
8803 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
8804 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8809 * lpfc_sli4_queue_create - Create all the SLI4 queues
8810 * @phba: pointer to lpfc hba data structure.
8812 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8813 * operation. For each SLI4 queue type, the parameters such as queue entry
8814 * count (queue depth) shall be taken from the module parameter. For now,
8815 * we just use some constant number as place holder.
8819 * -ENOMEM - No availble memory
8820 * -EIO - The mailbox failed to complete successfully.
8823 lpfc_sli4_queue_create(struct lpfc_hba *phba)
8825 struct lpfc_queue *qdesc;
8826 int idx, cpu, eqcpu;
8827 struct lpfc_sli4_hdw_queue *qp;
8828 struct lpfc_vector_map_info *cpup;
8829 struct lpfc_vector_map_info *eqcpup;
8830 struct lpfc_eq_intr_info *eqi;
8833 * Create HBA Record arrays.
8834 * Both NVME and FCP will share that same vectors / EQs
8836 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8837 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8838 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8839 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8840 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8841 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
8842 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8843 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8844 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8845 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8847 if (!phba->sli4_hba.hdwq) {
8848 phba->sli4_hba.hdwq = kcalloc(
8849 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
8851 if (!phba->sli4_hba.hdwq) {
8852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8853 "6427 Failed allocate memory for "
8854 "fast-path Hardware Queue array\n");
8857 /* Prepare hardware queues to take IO buffers */
8858 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
8859 qp = &phba->sli4_hba.hdwq[idx];
8860 spin_lock_init(&qp->io_buf_list_get_lock);
8861 spin_lock_init(&qp->io_buf_list_put_lock);
8862 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
8863 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
8864 qp->get_io_bufs = 0;
8865 qp->put_io_bufs = 0;
8866 qp->total_io_bufs = 0;
8867 spin_lock_init(&qp->abts_io_buf_list_lock);
8868 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
8869 qp->abts_scsi_io_bufs = 0;
8870 qp->abts_nvme_io_bufs = 0;
8871 INIT_LIST_HEAD(&qp->sgl_list);
8872 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
8873 spin_lock_init(&qp->hdwq_lock);
8877 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8878 if (phba->nvmet_support) {
8879 phba->sli4_hba.nvmet_cqset = kcalloc(
8880 phba->cfg_nvmet_mrq,
8881 sizeof(struct lpfc_queue *),
8883 if (!phba->sli4_hba.nvmet_cqset) {
8884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8885 "3121 Fail allocate memory for "
8886 "fast-path CQ set array\n");
8889 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8890 phba->cfg_nvmet_mrq,
8891 sizeof(struct lpfc_queue *),
8893 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8895 "3122 Fail allocate memory for "
8896 "fast-path RQ set hdr array\n");
8899 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8900 phba->cfg_nvmet_mrq,
8901 sizeof(struct lpfc_queue *),
8903 if (!phba->sli4_hba.nvmet_mrq_data) {
8904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8905 "3124 Fail allocate memory for "
8906 "fast-path RQ set data array\n");
8912 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8914 /* Create HBA Event Queues (EQs) */
8915 for_each_present_cpu(cpu) {
8916 /* We only want to create 1 EQ per vector, even though
8917 * multiple CPUs might be using that vector. so only
8918 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
8920 cpup = &phba->sli4_hba.cpu_map[cpu];
8921 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
8924 /* Get a ptr to the Hardware Queue associated with this CPU */
8925 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8927 /* Allocate an EQ */
8928 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8929 phba->sli4_hba.eq_esize,
8930 phba->sli4_hba.eq_ecount, cpu);
8932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8933 "0497 Failed allocate EQ (%d)\n",
8937 qdesc->qe_valid = 1;
8938 qdesc->hdwq = cpup->hdwq;
8939 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
8940 qdesc->last_cpu = qdesc->chann;
8942 /* Save the allocated EQ in the Hardware Queue */
8945 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
8946 list_add(&qdesc->cpu_list, &eqi->list);
8949 /* Now we need to populate the other Hardware Queues, that share
8950 * an IRQ vector, with the associated EQ ptr.
8952 for_each_present_cpu(cpu) {
8953 cpup = &phba->sli4_hba.cpu_map[cpu];
8955 /* Check for EQ already allocated in previous loop */
8956 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
8959 /* Check for multiple CPUs per hdwq */
8960 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8964 /* We need to share an EQ for this hdwq */
8965 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
8966 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
8967 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
8970 /* Allocate IO Path SLI4 CQ/WQs */
8971 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
8972 if (lpfc_alloc_io_wq_cq(phba, idx))
8976 if (phba->nvmet_support) {
8977 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8978 cpu = lpfc_find_cpu_handle(phba, idx,
8980 qdesc = lpfc_sli4_queue_alloc(phba,
8981 LPFC_DEFAULT_PAGE_SIZE,
8982 phba->sli4_hba.cq_esize,
8983 phba->sli4_hba.cq_ecount,
8986 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8987 "3142 Failed allocate NVME "
8988 "CQ Set (%d)\n", idx);
8991 qdesc->qe_valid = 1;
8994 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8999 * Create Slow Path Completion Queues (CQs)
9002 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
9003 /* Create slow-path Mailbox Command Complete Queue */
9004 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9005 phba->sli4_hba.cq_esize,
9006 phba->sli4_hba.cq_ecount, cpu);
9008 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9009 "0500 Failed allocate slow-path mailbox CQ\n");
9012 qdesc->qe_valid = 1;
9013 phba->sli4_hba.mbx_cq = qdesc;
9015 /* Create slow-path ELS Complete Queue */
9016 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9017 phba->sli4_hba.cq_esize,
9018 phba->sli4_hba.cq_ecount, cpu);
9020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9021 "0501 Failed allocate slow-path ELS CQ\n");
9024 qdesc->qe_valid = 1;
9026 phba->sli4_hba.els_cq = qdesc;
9030 * Create Slow Path Work Queues (WQs)
9033 /* Create Mailbox Command Queue */
9035 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9036 phba->sli4_hba.mq_esize,
9037 phba->sli4_hba.mq_ecount, cpu);
9039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9040 "0505 Failed allocate slow-path MQ\n");
9044 phba->sli4_hba.mbx_wq = qdesc;
9047 * Create ELS Work Queues
9050 /* Create slow-path ELS Work Queue */
9051 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9052 phba->sli4_hba.wq_esize,
9053 phba->sli4_hba.wq_ecount, cpu);
9055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9056 "0504 Failed allocate slow-path ELS WQ\n");
9060 phba->sli4_hba.els_wq = qdesc;
9061 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9063 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9064 /* Create NVME LS Complete Queue */
9065 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9066 phba->sli4_hba.cq_esize,
9067 phba->sli4_hba.cq_ecount, cpu);
9069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9070 "6079 Failed allocate NVME LS CQ\n");
9074 qdesc->qe_valid = 1;
9075 phba->sli4_hba.nvmels_cq = qdesc;
9077 /* Create NVME LS Work Queue */
9078 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9079 phba->sli4_hba.wq_esize,
9080 phba->sli4_hba.wq_ecount, cpu);
9082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9083 "6080 Failed allocate NVME LS WQ\n");
9087 phba->sli4_hba.nvmels_wq = qdesc;
9088 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9092 * Create Receive Queue (RQ)
9095 /* Create Receive Queue for header */
9096 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9097 phba->sli4_hba.rq_esize,
9098 phba->sli4_hba.rq_ecount, cpu);
9100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9101 "0506 Failed allocate receive HRQ\n");
9104 phba->sli4_hba.hdr_rq = qdesc;
9106 /* Create Receive Queue for data */
9107 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9108 phba->sli4_hba.rq_esize,
9109 phba->sli4_hba.rq_ecount, cpu);
9111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9112 "0507 Failed allocate receive DRQ\n");
9115 phba->sli4_hba.dat_rq = qdesc;
9117 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
9118 phba->nvmet_support) {
9119 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
9120 cpu = lpfc_find_cpu_handle(phba, idx,
9122 /* Create NVMET Receive Queue for header */
9123 qdesc = lpfc_sli4_queue_alloc(phba,
9124 LPFC_DEFAULT_PAGE_SIZE,
9125 phba->sli4_hba.rq_esize,
9126 LPFC_NVMET_RQE_DEF_COUNT,
9129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9130 "3146 Failed allocate "
9135 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
9137 /* Only needed for header of RQ pair */
9138 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
9141 if (qdesc->rqbp == NULL) {
9142 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9143 "6131 Failed allocate "
9148 /* Put list in known state in case driver load fails. */
9149 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
9151 /* Create NVMET Receive Queue for data */
9152 qdesc = lpfc_sli4_queue_alloc(phba,
9153 LPFC_DEFAULT_PAGE_SIZE,
9154 phba->sli4_hba.rq_esize,
9155 LPFC_NVMET_RQE_DEF_COUNT,
9158 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9159 "3156 Failed allocate "
9164 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
9168 /* Clear NVME stats */
9169 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9170 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9171 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
9172 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
9176 /* Clear SCSI stats */
9177 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
9178 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9179 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
9180 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
9187 lpfc_sli4_queue_destroy(phba);
9192 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
9195 lpfc_sli4_queue_free(*qp);
9201 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
9208 for (idx = 0; idx < max; idx++)
9209 __lpfc_sli4_release_queue(&(*qs)[idx]);
9216 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
9218 struct lpfc_sli4_hdw_queue *hdwq;
9219 struct lpfc_queue *eq;
9222 hdwq = phba->sli4_hba.hdwq;
9224 /* Loop thru all Hardware Queues */
9225 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9226 /* Free the CQ/WQ corresponding to the Hardware Queue */
9227 lpfc_sli4_queue_free(hdwq[idx].io_cq);
9228 lpfc_sli4_queue_free(hdwq[idx].io_wq);
9229 hdwq[idx].hba_eq = NULL;
9230 hdwq[idx].io_cq = NULL;
9231 hdwq[idx].io_wq = NULL;
9232 if (phba->cfg_xpsgl && !phba->nvmet_support)
9233 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
9234 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
9236 /* Loop thru all IRQ vectors */
9237 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
9238 /* Free the EQ corresponding to the IRQ vector */
9239 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
9240 lpfc_sli4_queue_free(eq);
9241 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
9246 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
9247 * @phba: pointer to lpfc hba data structure.
9249 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
9254 * -ENOMEM - No available memory
9255 * -EIO - The mailbox failed to complete successfully.
9258 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
9261 * Set FREE_INIT before beginning to free the queues.
9262 * Wait until the users of queues to acknowledge to
9263 * release queues by clearing FREE_WAIT.
9265 spin_lock_irq(&phba->hbalock);
9266 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
9267 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
9268 spin_unlock_irq(&phba->hbalock);
9270 spin_lock_irq(&phba->hbalock);
9272 spin_unlock_irq(&phba->hbalock);
9274 lpfc_sli4_cleanup_poll_list(phba);
9276 /* Release HBA eqs */
9277 if (phba->sli4_hba.hdwq)
9278 lpfc_sli4_release_hdwq(phba);
9280 if (phba->nvmet_support) {
9281 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
9282 phba->cfg_nvmet_mrq);
9284 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
9285 phba->cfg_nvmet_mrq);
9286 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
9287 phba->cfg_nvmet_mrq);
9290 /* Release mailbox command work queue */
9291 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
9293 /* Release ELS work queue */
9294 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
9296 /* Release ELS work queue */
9297 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
9299 /* Release unsolicited receive queue */
9300 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
9301 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
9303 /* Release ELS complete queue */
9304 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
9306 /* Release NVME LS complete queue */
9307 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
9309 /* Release mailbox command complete queue */
9310 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
9312 /* Everything on this list has been freed */
9313 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
9315 /* Done with freeing the queues */
9316 spin_lock_irq(&phba->hbalock);
9317 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
9318 spin_unlock_irq(&phba->hbalock);
9322 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
9324 struct lpfc_rqb *rqbp;
9325 struct lpfc_dmabuf *h_buf;
9326 struct rqb_dmabuf *rqb_buffer;
9329 while (!list_empty(&rqbp->rqb_buffer_list)) {
9330 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
9331 struct lpfc_dmabuf, list);
9333 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
9334 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
9335 rqbp->buffer_count--;
9341 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
9342 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
9343 int qidx, uint32_t qtype)
9345 struct lpfc_sli_ring *pring;
9348 if (!eq || !cq || !wq) {
9349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9350 "6085 Fast-path %s (%d) not allocated\n",
9351 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
9355 /* create the Cq first */
9356 rc = lpfc_cq_create(phba, cq, eq,
9357 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
9359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9360 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
9361 qidx, (uint32_t)rc);
9365 if (qtype != LPFC_MBOX) {
9366 /* Setup cq_map for fast lookup */
9368 *cq_map = cq->queue_id;
9370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9371 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
9372 qidx, cq->queue_id, qidx, eq->queue_id);
9375 rc = lpfc_wq_create(phba, wq, cq, qtype);
9377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9378 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
9379 qidx, (uint32_t)rc);
9380 /* no need to tear down cq - caller will do so */
9384 /* Bind this CQ/WQ to the NVME ring */
9386 pring->sli.sli4.wqp = (void *)wq;
9389 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9390 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
9391 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
9393 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
9395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9396 "0539 Failed setup of slow-path MQ: "
9398 /* no need to tear down cq - caller will do so */
9402 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9403 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
9404 phba->sli4_hba.mbx_wq->queue_id,
9405 phba->sli4_hba.mbx_cq->queue_id);
9412 * lpfc_setup_cq_lookup - Setup the CQ lookup table
9413 * @phba: pointer to lpfc hba data structure.
9415 * This routine will populate the cq_lookup table by all
9416 * available CQ queue_id's.
9419 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
9421 struct lpfc_queue *eq, *childq;
9424 memset(phba->sli4_hba.cq_lookup, 0,
9425 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
9426 /* Loop thru all IRQ vectors */
9427 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
9428 /* Get the EQ corresponding to the IRQ vector */
9429 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
9432 /* Loop through all CQs associated with that EQ */
9433 list_for_each_entry(childq, &eq->child_list, list) {
9434 if (childq->queue_id > phba->sli4_hba.cq_max)
9436 if (childq->subtype == LPFC_IO)
9437 phba->sli4_hba.cq_lookup[childq->queue_id] =
9444 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
9445 * @phba: pointer to lpfc hba data structure.
9447 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
9452 * -ENOMEM - No available memory
9453 * -EIO - The mailbox failed to complete successfully.
9456 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
9458 uint32_t shdr_status, shdr_add_status;
9459 union lpfc_sli4_cfg_shdr *shdr;
9460 struct lpfc_vector_map_info *cpup;
9461 struct lpfc_sli4_hdw_queue *qp;
9462 LPFC_MBOXQ_t *mboxq;
9464 uint32_t length, usdelay;
9467 /* Check for dual-ULP support */
9468 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9470 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9471 "3249 Unable to allocate memory for "
9472 "QUERY_FW_CFG mailbox command\n");
9475 length = (sizeof(struct lpfc_mbx_query_fw_config) -
9476 sizeof(struct lpfc_sli4_cfg_mhdr));
9477 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9478 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
9479 length, LPFC_SLI4_MBX_EMBED);
9481 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9483 shdr = (union lpfc_sli4_cfg_shdr *)
9484 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9485 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9486 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9487 if (shdr_status || shdr_add_status || rc) {
9488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9489 "3250 QUERY_FW_CFG mailbox failed with status "
9490 "x%x add_status x%x, mbx status x%x\n",
9491 shdr_status, shdr_add_status, rc);
9492 if (rc != MBX_TIMEOUT)
9493 mempool_free(mboxq, phba->mbox_mem_pool);
9498 phba->sli4_hba.fw_func_mode =
9499 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9500 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9501 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
9502 phba->sli4_hba.physical_port =
9503 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
9504 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9505 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9506 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9507 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9509 if (rc != MBX_TIMEOUT)
9510 mempool_free(mboxq, phba->mbox_mem_pool);
9513 * Set up HBA Event Queues (EQs)
9515 qp = phba->sli4_hba.hdwq;
9517 /* Set up HBA event queue */
9519 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9520 "3147 Fast-path EQs not allocated\n");
9525 /* Loop thru all IRQ vectors */
9526 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
9527 /* Create HBA Event Queues (EQs) in order */
9528 for_each_present_cpu(cpu) {
9529 cpup = &phba->sli4_hba.cpu_map[cpu];
9531 /* Look for the CPU thats using that vector with
9532 * LPFC_CPU_FIRST_IRQ set.
9534 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
9536 if (qidx != cpup->eq)
9539 /* Create an EQ for that vector */
9540 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
9541 phba->cfg_fcp_imax);
9543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9544 "0523 Failed setup of fast-path"
9545 " EQ (%d), rc = 0x%x\n",
9546 cpup->eq, (uint32_t)rc);
9550 /* Save the EQ for that vector in the hba_eq_hdl */
9551 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
9552 qp[cpup->hdwq].hba_eq;
9554 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9555 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9557 qp[cpup->hdwq].hba_eq->queue_id);
9561 /* Loop thru all Hardware Queues */
9562 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
9563 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
9564 cpup = &phba->sli4_hba.cpu_map[cpu];
9566 /* Create the CQ/WQ corresponding to the Hardware Queue */
9567 rc = lpfc_create_wq_cq(phba,
9568 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
9571 &phba->sli4_hba.hdwq[qidx].io_cq_map,
9575 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9576 "0535 Failed to setup fastpath "
9577 "IO WQ/CQ (%d), rc = 0x%x\n",
9578 qidx, (uint32_t)rc);
9584 * Set up Slow Path Complete Queues (CQs)
9587 /* Set up slow-path MBOX CQ/MQ */
9589 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
9590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9591 "0528 %s not allocated\n",
9592 phba->sli4_hba.mbx_cq ?
9593 "Mailbox WQ" : "Mailbox CQ");
9598 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9599 phba->sli4_hba.mbx_cq,
9600 phba->sli4_hba.mbx_wq,
9601 NULL, 0, LPFC_MBOX);
9603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9604 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9608 if (phba->nvmet_support) {
9609 if (!phba->sli4_hba.nvmet_cqset) {
9610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9611 "3165 Fast-path NVME CQ Set "
9612 "array not allocated\n");
9616 if (phba->cfg_nvmet_mrq > 1) {
9617 rc = lpfc_cq_create_set(phba,
9618 phba->sli4_hba.nvmet_cqset,
9620 LPFC_WCQ, LPFC_NVMET);
9622 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9623 "3164 Failed setup of NVME CQ "
9629 /* Set up NVMET Receive Complete Queue */
9630 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
9632 LPFC_WCQ, LPFC_NVMET);
9634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9635 "6089 Failed setup NVMET CQ: "
9636 "rc = 0x%x\n", (uint32_t)rc);
9639 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9641 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9642 "6090 NVMET CQ setup: cq-id=%d, "
9643 "parent eq-id=%d\n",
9644 phba->sli4_hba.nvmet_cqset[0]->queue_id,
9645 qp[0].hba_eq->queue_id);
9649 /* Set up slow-path ELS WQ/CQ */
9650 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
9651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9652 "0530 ELS %s not allocated\n",
9653 phba->sli4_hba.els_cq ? "WQ" : "CQ");
9657 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9658 phba->sli4_hba.els_cq,
9659 phba->sli4_hba.els_wq,
9662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9663 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9667 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9668 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9669 phba->sli4_hba.els_wq->queue_id,
9670 phba->sli4_hba.els_cq->queue_id);
9672 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9673 /* Set up NVME LS Complete Queue */
9674 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9676 "6091 LS %s not allocated\n",
9677 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9681 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9682 phba->sli4_hba.nvmels_cq,
9683 phba->sli4_hba.nvmels_wq,
9684 NULL, 0, LPFC_NVME_LS);
9686 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9687 "0526 Failed setup of NVVME LS WQ/CQ: "
9688 "rc = 0x%x\n", (uint32_t)rc);
9692 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9693 "6096 ELS WQ setup: wq-id=%d, "
9694 "parent cq-id=%d\n",
9695 phba->sli4_hba.nvmels_wq->queue_id,
9696 phba->sli4_hba.nvmels_cq->queue_id);
9700 * Create NVMET Receive Queue (RQ)
9702 if (phba->nvmet_support) {
9703 if ((!phba->sli4_hba.nvmet_cqset) ||
9704 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9705 (!phba->sli4_hba.nvmet_mrq_data)) {
9706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9707 "6130 MRQ CQ Queues not "
9712 if (phba->cfg_nvmet_mrq > 1) {
9713 rc = lpfc_mrq_create(phba,
9714 phba->sli4_hba.nvmet_mrq_hdr,
9715 phba->sli4_hba.nvmet_mrq_data,
9716 phba->sli4_hba.nvmet_cqset,
9719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9720 "6098 Failed setup of NVMET "
9727 rc = lpfc_rq_create(phba,
9728 phba->sli4_hba.nvmet_mrq_hdr[0],
9729 phba->sli4_hba.nvmet_mrq_data[0],
9730 phba->sli4_hba.nvmet_cqset[0],
9733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9734 "6057 Failed setup of NVMET "
9735 "Receive Queue: rc = 0x%x\n",
9741 phba, KERN_INFO, LOG_INIT,
9742 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9743 "dat-rq-id=%d parent cq-id=%d\n",
9744 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9745 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9746 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9751 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9753 "0540 Receive Queue not allocated\n");
9758 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
9759 phba->sli4_hba.els_cq, LPFC_USOL);
9761 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9762 "0541 Failed setup of Receive Queue: "
9763 "rc = 0x%x\n", (uint32_t)rc);
9767 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9768 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9769 "parent cq-id=%d\n",
9770 phba->sli4_hba.hdr_rq->queue_id,
9771 phba->sli4_hba.dat_rq->queue_id,
9772 phba->sli4_hba.els_cq->queue_id);
9774 if (phba->cfg_fcp_imax)
9775 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
9779 for (qidx = 0; qidx < phba->cfg_irq_chann;
9780 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
9781 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9784 if (phba->sli4_hba.cq_max) {
9785 kfree(phba->sli4_hba.cq_lookup);
9786 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
9787 sizeof(struct lpfc_queue *), GFP_KERNEL);
9788 if (!phba->sli4_hba.cq_lookup) {
9789 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9790 "0549 Failed setup of CQ Lookup table: "
9791 "size 0x%x\n", phba->sli4_hba.cq_max);
9795 lpfc_setup_cq_lookup(phba);
9800 lpfc_sli4_queue_unset(phba);
9806 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9807 * @phba: pointer to lpfc hba data structure.
9809 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9814 * -ENOMEM - No available memory
9815 * -EIO - The mailbox failed to complete successfully.
9818 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9820 struct lpfc_sli4_hdw_queue *qp;
9821 struct lpfc_queue *eq;
9824 /* Unset mailbox command work queue */
9825 if (phba->sli4_hba.mbx_wq)
9826 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9828 /* Unset NVME LS work queue */
9829 if (phba->sli4_hba.nvmels_wq)
9830 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9832 /* Unset ELS work queue */
9833 if (phba->sli4_hba.els_wq)
9834 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9836 /* Unset unsolicited receive queue */
9837 if (phba->sli4_hba.hdr_rq)
9838 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9839 phba->sli4_hba.dat_rq);
9841 /* Unset mailbox command complete queue */
9842 if (phba->sli4_hba.mbx_cq)
9843 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9845 /* Unset ELS complete queue */
9846 if (phba->sli4_hba.els_cq)
9847 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9849 /* Unset NVME LS complete queue */
9850 if (phba->sli4_hba.nvmels_cq)
9851 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9853 if (phba->nvmet_support) {
9854 /* Unset NVMET MRQ queue */
9855 if (phba->sli4_hba.nvmet_mrq_hdr) {
9856 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9859 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9860 phba->sli4_hba.nvmet_mrq_data[qidx]);
9863 /* Unset NVMET CQ Set complete queue */
9864 if (phba->sli4_hba.nvmet_cqset) {
9865 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9867 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9871 /* Unset fast-path SLI4 queues */
9872 if (phba->sli4_hba.hdwq) {
9873 /* Loop thru all Hardware Queues */
9874 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
9875 /* Destroy the CQ/WQ corresponding to Hardware Queue */
9876 qp = &phba->sli4_hba.hdwq[qidx];
9877 lpfc_wq_destroy(phba, qp->io_wq);
9878 lpfc_cq_destroy(phba, qp->io_cq);
9880 /* Loop thru all IRQ vectors */
9881 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
9882 /* Destroy the EQ corresponding to the IRQ vector */
9883 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
9884 lpfc_eq_destroy(phba, eq);
9888 kfree(phba->sli4_hba.cq_lookup);
9889 phba->sli4_hba.cq_lookup = NULL;
9890 phba->sli4_hba.cq_max = 0;
9894 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9895 * @phba: pointer to lpfc hba data structure.
9897 * This routine is invoked to allocate and set up a pool of completion queue
9898 * events. The body of the completion queue event is a completion queue entry
9899 * CQE. For now, this pool is used for the interrupt service routine to queue
9900 * the following HBA completion queue events for the worker thread to process:
9901 * - Mailbox asynchronous events
9902 * - Receive queue completion unsolicited events
9903 * Later, this can be used for all the slow-path events.
9907 * -ENOMEM - No available memory
9910 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9912 struct lpfc_cq_event *cq_event;
9915 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9916 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9918 goto out_pool_create_fail;
9919 list_add_tail(&cq_event->list,
9920 &phba->sli4_hba.sp_cqe_event_pool);
9924 out_pool_create_fail:
9925 lpfc_sli4_cq_event_pool_destroy(phba);
9930 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9931 * @phba: pointer to lpfc hba data structure.
9933 * This routine is invoked to free the pool of completion queue events at
9934 * driver unload time. Note that, it is the responsibility of the driver
9935 * cleanup routine to free all the outstanding completion-queue events
9936 * allocated from this pool back into the pool before invoking this routine
9937 * to destroy the pool.
9940 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9942 struct lpfc_cq_event *cq_event, *next_cq_event;
9944 list_for_each_entry_safe(cq_event, next_cq_event,
9945 &phba->sli4_hba.sp_cqe_event_pool, list) {
9946 list_del(&cq_event->list);
9952 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9953 * @phba: pointer to lpfc hba data structure.
9955 * This routine is the lock free version of the API invoked to allocate a
9956 * completion-queue event from the free pool.
9958 * Return: Pointer to the newly allocated completion-queue event if successful
9961 struct lpfc_cq_event *
9962 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9964 struct lpfc_cq_event *cq_event = NULL;
9966 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9967 struct lpfc_cq_event, list);
9972 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9973 * @phba: pointer to lpfc hba data structure.
9975 * This routine is the lock version of the API invoked to allocate a
9976 * completion-queue event from the free pool.
9978 * Return: Pointer to the newly allocated completion-queue event if successful
9981 struct lpfc_cq_event *
9982 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9984 struct lpfc_cq_event *cq_event;
9985 unsigned long iflags;
9987 spin_lock_irqsave(&phba->hbalock, iflags);
9988 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9989 spin_unlock_irqrestore(&phba->hbalock, iflags);
9994 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9995 * @phba: pointer to lpfc hba data structure.
9996 * @cq_event: pointer to the completion queue event to be freed.
9998 * This routine is the lock free version of the API invoked to release a
9999 * completion-queue event back into the free pool.
10002 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10003 struct lpfc_cq_event *cq_event)
10005 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
10009 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10010 * @phba: pointer to lpfc hba data structure.
10011 * @cq_event: pointer to the completion queue event to be freed.
10013 * This routine is the lock version of the API invoked to release a
10014 * completion-queue event back into the free pool.
10017 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10018 struct lpfc_cq_event *cq_event)
10020 unsigned long iflags;
10021 spin_lock_irqsave(&phba->hbalock, iflags);
10022 __lpfc_sli4_cq_event_release(phba, cq_event);
10023 spin_unlock_irqrestore(&phba->hbalock, iflags);
10027 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
10028 * @phba: pointer to lpfc hba data structure.
10030 * This routine is to free all the pending completion-queue events to the
10031 * back into the free pool for device reset.
10034 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
10036 LIST_HEAD(cqelist);
10037 struct lpfc_cq_event *cqe;
10038 unsigned long iflags;
10040 /* Retrieve all the pending WCQEs from pending WCQE lists */
10041 spin_lock_irqsave(&phba->hbalock, iflags);
10042 /* Pending FCP XRI abort events */
10043 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
10045 /* Pending ELS XRI abort events */
10046 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10048 /* Pending asynnc events */
10049 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
10051 spin_unlock_irqrestore(&phba->hbalock, iflags);
10053 while (!list_empty(&cqelist)) {
10054 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
10055 lpfc_sli4_cq_event_release(phba, cqe);
10060 * lpfc_pci_function_reset - Reset pci function.
10061 * @phba: pointer to lpfc hba data structure.
10063 * This routine is invoked to request a PCI function reset. It will destroys
10064 * all resources assigned to the PCI function which originates this request.
10068 * -ENOMEM - No available memory
10069 * -EIO - The mailbox failed to complete successfully.
10072 lpfc_pci_function_reset(struct lpfc_hba *phba)
10074 LPFC_MBOXQ_t *mboxq;
10075 uint32_t rc = 0, if_type;
10076 uint32_t shdr_status, shdr_add_status;
10078 uint32_t port_reset = 0;
10079 union lpfc_sli4_cfg_shdr *shdr;
10080 struct lpfc_register reg_data;
10083 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10085 case LPFC_SLI_INTF_IF_TYPE_0:
10086 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10089 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10090 "0494 Unable to allocate memory for "
10091 "issuing SLI_FUNCTION_RESET mailbox "
10096 /* Setup PCI function reset mailbox-ioctl command */
10097 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10098 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
10099 LPFC_SLI4_MBX_EMBED);
10100 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10101 shdr = (union lpfc_sli4_cfg_shdr *)
10102 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10103 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10104 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
10106 if (rc != MBX_TIMEOUT)
10107 mempool_free(mboxq, phba->mbox_mem_pool);
10108 if (shdr_status || shdr_add_status || rc) {
10109 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10110 "0495 SLI_FUNCTION_RESET mailbox "
10111 "failed with status x%x add_status x%x,"
10112 " mbx status x%x\n",
10113 shdr_status, shdr_add_status, rc);
10117 case LPFC_SLI_INTF_IF_TYPE_2:
10118 case LPFC_SLI_INTF_IF_TYPE_6:
10121 * Poll the Port Status Register and wait for RDY for
10122 * up to 30 seconds. If the port doesn't respond, treat
10125 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
10126 if (lpfc_readl(phba->sli4_hba.u.if_type2.
10127 STATUSregaddr, ®_data.word0)) {
10131 if (bf_get(lpfc_sliport_status_rdy, ®_data))
10136 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
10137 phba->work_status[0] = readl(
10138 phba->sli4_hba.u.if_type2.ERR1regaddr);
10139 phba->work_status[1] = readl(
10140 phba->sli4_hba.u.if_type2.ERR2regaddr);
10141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10142 "2890 Port not ready, port status reg "
10143 "0x%x error 1=0x%x, error 2=0x%x\n",
10145 phba->work_status[0],
10146 phba->work_status[1]);
10153 * Reset the port now
10155 reg_data.word0 = 0;
10156 bf_set(lpfc_sliport_ctrl_end, ®_data,
10157 LPFC_SLIPORT_LITTLE_ENDIAN);
10158 bf_set(lpfc_sliport_ctrl_ip, ®_data,
10159 LPFC_SLIPORT_INIT_PORT);
10160 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
10163 pci_read_config_word(phba->pcidev,
10164 PCI_DEVICE_ID, &devid);
10169 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
10175 case LPFC_SLI_INTF_IF_TYPE_1:
10181 /* Catch the not-ready port failure after a port reset. */
10183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10184 "3317 HBA not functional: IP Reset Failed "
10185 "try: echo fw_reset > board_mode\n");
10193 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
10194 * @phba: pointer to lpfc hba data structure.
10196 * This routine is invoked to set up the PCI device memory space for device
10197 * with SLI-4 interface spec.
10201 * other values - error
10204 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10206 struct pci_dev *pdev = phba->pcidev;
10207 unsigned long bar0map_len, bar1map_len, bar2map_len;
10214 /* Set the device DMA mask size */
10215 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
10217 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10222 * The BARs and register set definitions and offset locations are
10223 * dependent on the if_type.
10225 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
10226 &phba->sli4_hba.sli_intf.word0)) {
10230 /* There is no SLI3 failback for SLI4 devices. */
10231 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
10232 LPFC_SLI_INTF_VALID) {
10233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10234 "2894 SLI_INTF reg contents invalid "
10235 "sli_intf reg 0x%x\n",
10236 phba->sli4_hba.sli_intf.word0);
10240 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10242 * Get the bus address of SLI4 device Bar regions and the
10243 * number of bytes required by each mapping. The mapping of the
10244 * particular PCI BARs regions is dependent on the type of
10247 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
10248 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
10249 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
10252 * Map SLI4 PCI Config Space Register base to a kernel virtual
10255 phba->sli4_hba.conf_regs_memmap_p =
10256 ioremap(phba->pci_bar0_map, bar0map_len);
10257 if (!phba->sli4_hba.conf_regs_memmap_p) {
10258 dev_printk(KERN_ERR, &pdev->dev,
10259 "ioremap failed for SLI4 PCI config "
10263 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
10264 /* Set up BAR0 PCI config space register memory map */
10265 lpfc_sli4_bar0_register_memmap(phba, if_type);
10267 phba->pci_bar0_map = pci_resource_start(pdev, 1);
10268 bar0map_len = pci_resource_len(pdev, 1);
10269 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10270 dev_printk(KERN_ERR, &pdev->dev,
10271 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
10274 phba->sli4_hba.conf_regs_memmap_p =
10275 ioremap(phba->pci_bar0_map, bar0map_len);
10276 if (!phba->sli4_hba.conf_regs_memmap_p) {
10277 dev_printk(KERN_ERR, &pdev->dev,
10278 "ioremap failed for SLI4 PCI config "
10282 lpfc_sli4_bar0_register_memmap(phba, if_type);
10285 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10286 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
10288 * Map SLI4 if type 0 HBA Control Register base to a
10289 * kernel virtual address and setup the registers.
10291 phba->pci_bar1_map = pci_resource_start(pdev,
10293 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10294 phba->sli4_hba.ctrl_regs_memmap_p =
10295 ioremap(phba->pci_bar1_map,
10297 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
10298 dev_err(&pdev->dev,
10299 "ioremap failed for SLI4 HBA "
10300 "control registers.\n");
10302 goto out_iounmap_conf;
10304 phba->pci_bar2_memmap_p =
10305 phba->sli4_hba.ctrl_regs_memmap_p;
10306 lpfc_sli4_bar1_register_memmap(phba, if_type);
10309 goto out_iounmap_conf;
10313 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
10314 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
10316 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
10317 * virtual address and setup the registers.
10319 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
10320 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10321 phba->sli4_hba.drbl_regs_memmap_p =
10322 ioremap(phba->pci_bar1_map, bar1map_len);
10323 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10324 dev_err(&pdev->dev,
10325 "ioremap failed for SLI4 HBA doorbell registers.\n");
10327 goto out_iounmap_conf;
10329 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
10330 lpfc_sli4_bar1_register_memmap(phba, if_type);
10333 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10334 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10336 * Map SLI4 if type 0 HBA Doorbell Register base to
10337 * a kernel virtual address and setup the registers.
10339 phba->pci_bar2_map = pci_resource_start(pdev,
10341 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10342 phba->sli4_hba.drbl_regs_memmap_p =
10343 ioremap(phba->pci_bar2_map,
10345 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10346 dev_err(&pdev->dev,
10347 "ioremap failed for SLI4 HBA"
10348 " doorbell registers.\n");
10350 goto out_iounmap_ctrl;
10352 phba->pci_bar4_memmap_p =
10353 phba->sli4_hba.drbl_regs_memmap_p;
10354 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
10356 goto out_iounmap_all;
10359 goto out_iounmap_all;
10363 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
10364 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10366 * Map SLI4 if type 6 HBA DPP Register base to a kernel
10367 * virtual address and setup the registers.
10369 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
10370 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10371 phba->sli4_hba.dpp_regs_memmap_p =
10372 ioremap(phba->pci_bar2_map, bar2map_len);
10373 if (!phba->sli4_hba.dpp_regs_memmap_p) {
10374 dev_err(&pdev->dev,
10375 "ioremap failed for SLI4 HBA dpp registers.\n");
10377 goto out_iounmap_ctrl;
10379 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
10382 /* Set up the EQ/CQ register handeling functions now */
10384 case LPFC_SLI_INTF_IF_TYPE_0:
10385 case LPFC_SLI_INTF_IF_TYPE_2:
10386 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
10387 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
10388 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
10390 case LPFC_SLI_INTF_IF_TYPE_6:
10391 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
10392 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
10393 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
10402 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10404 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10406 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10412 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
10413 * @phba: pointer to lpfc hba data structure.
10415 * This routine is invoked to unset the PCI device memory space for device
10416 * with SLI-4 interface spec.
10419 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
10422 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10425 case LPFC_SLI_INTF_IF_TYPE_0:
10426 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10427 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10428 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10430 case LPFC_SLI_INTF_IF_TYPE_2:
10431 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10433 case LPFC_SLI_INTF_IF_TYPE_6:
10434 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10435 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10436 if (phba->sli4_hba.dpp_regs_memmap_p)
10437 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
10439 case LPFC_SLI_INTF_IF_TYPE_1:
10441 dev_printk(KERN_ERR, &phba->pcidev->dev,
10442 "FATAL - unsupported SLI4 interface type - %d\n",
10449 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
10450 * @phba: pointer to lpfc hba data structure.
10452 * This routine is invoked to enable the MSI-X interrupt vectors to device
10453 * with SLI-3 interface specs.
10457 * other values - error
10460 lpfc_sli_enable_msix(struct lpfc_hba *phba)
10465 /* Set up MSI-X multi-message vectors */
10466 rc = pci_alloc_irq_vectors(phba->pcidev,
10467 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
10469 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10470 "0420 PCI enable MSI-X failed (%d)\n", rc);
10475 * Assign MSI-X vectors to interrupt handlers
10478 /* vector-0 is associated to slow-path handler */
10479 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
10480 &lpfc_sli_sp_intr_handler, 0,
10481 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10483 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10484 "0421 MSI-X slow-path request_irq failed "
10489 /* vector-1 is associated to fast-path handler */
10490 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
10491 &lpfc_sli_fp_intr_handler, 0,
10492 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10495 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10496 "0429 MSI-X fast-path request_irq failed "
10502 * Configure HBA MSI-X attention conditions to messages
10504 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10509 "0474 Unable to allocate memory for issuing "
10510 "MBOX_CONFIG_MSI command\n");
10513 rc = lpfc_config_msi(phba, pmb);
10516 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10517 if (rc != MBX_SUCCESS) {
10518 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10519 "0351 Config MSI mailbox command failed, "
10520 "mbxCmd x%x, mbxStatus x%x\n",
10521 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10525 /* Free memory allocated for mailbox command */
10526 mempool_free(pmb, phba->mbox_mem_pool);
10530 /* Free memory allocated for mailbox command */
10531 mempool_free(pmb, phba->mbox_mem_pool);
10534 /* free the irq already requested */
10535 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
10538 /* free the irq already requested */
10539 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
10542 /* Unconfigure MSI-X capability structure */
10543 pci_free_irq_vectors(phba->pcidev);
10550 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10551 * @phba: pointer to lpfc hba data structure.
10553 * This routine is invoked to enable the MSI interrupt mode to device with
10554 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10555 * enable the MSI vector. The device driver is responsible for calling the
10556 * request_irq() to register MSI vector with a interrupt the handler, which
10557 * is done in this function.
10561 * other values - error
10564 lpfc_sli_enable_msi(struct lpfc_hba *phba)
10568 rc = pci_enable_msi(phba->pcidev);
10570 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10571 "0462 PCI enable MSI mode success.\n");
10573 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10574 "0471 PCI enable MSI mode failed (%d)\n", rc);
10578 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10579 0, LPFC_DRIVER_NAME, phba);
10581 pci_disable_msi(phba->pcidev);
10582 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10583 "0478 MSI request_irq failed (%d)\n", rc);
10589 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10590 * @phba: pointer to lpfc hba data structure.
10592 * This routine is invoked to enable device interrupt and associate driver's
10593 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10594 * spec. Depends on the interrupt mode configured to the driver, the driver
10595 * will try to fallback from the configured interrupt mode to an interrupt
10596 * mode which is supported by the platform, kernel, and device in the order
10598 * MSI-X -> MSI -> IRQ.
10602 * other values - error
10605 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10607 uint32_t intr_mode = LPFC_INTR_ERROR;
10610 if (cfg_mode == 2) {
10611 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10612 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10614 /* Now, try to enable MSI-X interrupt mode */
10615 retval = lpfc_sli_enable_msix(phba);
10617 /* Indicate initialization to MSI-X mode */
10618 phba->intr_type = MSIX;
10624 /* Fallback to MSI if MSI-X initialization failed */
10625 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10626 retval = lpfc_sli_enable_msi(phba);
10628 /* Indicate initialization to MSI mode */
10629 phba->intr_type = MSI;
10634 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10635 if (phba->intr_type == NONE) {
10636 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10637 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10639 /* Indicate initialization to INTx mode */
10640 phba->intr_type = INTx;
10648 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10649 * @phba: pointer to lpfc hba data structure.
10651 * This routine is invoked to disable device interrupt and disassociate the
10652 * driver's interrupt handler(s) from interrupt vector(s) to device with
10653 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10654 * release the interrupt vector(s) for the message signaled interrupt.
10657 lpfc_sli_disable_intr(struct lpfc_hba *phba)
10661 if (phba->intr_type == MSIX)
10662 nr_irqs = LPFC_MSIX_VECTORS;
10666 for (i = 0; i < nr_irqs; i++)
10667 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10668 pci_free_irq_vectors(phba->pcidev);
10670 /* Reset interrupt management states */
10671 phba->intr_type = NONE;
10672 phba->sli.slistat.sli_intr = 0;
10676 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
10677 * @phba: pointer to lpfc hba data structure.
10678 * @id: EQ vector index or Hardware Queue index
10679 * @match: LPFC_FIND_BY_EQ = match by EQ
10680 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
10681 * Return the CPU that matches the selection criteria
10684 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
10686 struct lpfc_vector_map_info *cpup;
10689 /* Loop through all CPUs */
10690 for_each_present_cpu(cpu) {
10691 cpup = &phba->sli4_hba.cpu_map[cpu];
10693 /* If we are matching by EQ, there may be multiple CPUs using
10694 * using the same vector, so select the one with
10695 * LPFC_CPU_FIRST_IRQ set.
10697 if ((match == LPFC_FIND_BY_EQ) &&
10698 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
10702 /* If matching by HDWQ, select the first CPU that matches */
10703 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
10711 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
10712 * @phba: pointer to lpfc hba data structure.
10713 * @cpu: CPU map index
10714 * @phys_id: CPU package physical id
10715 * @core_id: CPU core id
10718 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
10719 uint16_t phys_id, uint16_t core_id)
10721 struct lpfc_vector_map_info *cpup;
10724 for_each_present_cpu(idx) {
10725 cpup = &phba->sli4_hba.cpu_map[idx];
10726 /* Does the cpup match the one we are looking for */
10727 if ((cpup->phys_id == phys_id) &&
10728 (cpup->core_id == core_id) &&
10737 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
10738 * @phba: pointer to lpfc hba data structure.
10739 * @eqidx: index for eq and irq vector
10740 * @flag: flags to set for vector_map structure
10741 * @cpu: cpu used to index vector_map structure
10743 * The routine assigns eq info into vector_map structure
10746 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
10749 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
10750 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
10753 cpup->flag |= flag;
10755 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10756 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
10757 cpu, eqhdl->irq, cpup->eq, cpup->flag);
10761 * lpfc_cpu_map_array_init - Initialize cpu_map structure
10762 * @phba: pointer to lpfc hba data structure.
10764 * The routine initializes the cpu_map array structure
10767 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
10769 struct lpfc_vector_map_info *cpup;
10770 struct lpfc_eq_intr_info *eqi;
10773 for_each_possible_cpu(cpu) {
10774 cpup = &phba->sli4_hba.cpu_map[cpu];
10775 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
10776 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
10777 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
10778 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
10780 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
10781 INIT_LIST_HEAD(&eqi->list);
10787 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
10788 * @phba: pointer to lpfc hba data structure.
10790 * The routine initializes the hba_eq_hdl array structure
10793 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
10795 struct lpfc_hba_eq_hdl *eqhdl;
10798 for (i = 0; i < phba->cfg_irq_chann; i++) {
10799 eqhdl = lpfc_get_eq_hdl(i);
10800 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
10801 eqhdl->phba = phba;
10806 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
10807 * @phba: pointer to lpfc hba data structure.
10808 * @vectors: number of msix vectors allocated.
10810 * The routine will figure out the CPU affinity assignment for every
10811 * MSI-X vector allocated for the HBA.
10812 * In addition, the CPU to IO channel mapping will be calculated
10813 * and the phba->sli4_hba.cpu_map array will reflect this.
10816 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
10818 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
10819 int max_phys_id, min_phys_id;
10820 int max_core_id, min_core_id;
10821 struct lpfc_vector_map_info *cpup;
10822 struct lpfc_vector_map_info *new_cpup;
10824 struct cpuinfo_x86 *cpuinfo;
10828 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
10830 min_core_id = LPFC_VECTOR_MAP_EMPTY;
10832 /* Update CPU map with physical id and core id of each CPU */
10833 for_each_present_cpu(cpu) {
10834 cpup = &phba->sli4_hba.cpu_map[cpu];
10836 cpuinfo = &cpu_data(cpu);
10837 cpup->phys_id = cpuinfo->phys_proc_id;
10838 cpup->core_id = cpuinfo->cpu_core_id;
10839 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
10840 cpup->flag |= LPFC_CPU_MAP_HYPER;
10842 /* No distinction between CPUs for other platforms */
10844 cpup->core_id = cpu;
10847 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10848 "3328 CPU %d physid %d coreid %d flag x%x\n",
10849 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
10851 if (cpup->phys_id > max_phys_id)
10852 max_phys_id = cpup->phys_id;
10853 if (cpup->phys_id < min_phys_id)
10854 min_phys_id = cpup->phys_id;
10856 if (cpup->core_id > max_core_id)
10857 max_core_id = cpup->core_id;
10858 if (cpup->core_id < min_core_id)
10859 min_core_id = cpup->core_id;
10862 /* After looking at each irq vector assigned to this pcidev, its
10863 * possible to see that not ALL CPUs have been accounted for.
10864 * Next we will set any unassigned (unaffinitized) cpu map
10865 * entries to a IRQ on the same phys_id.
10867 first_cpu = cpumask_first(cpu_present_mask);
10868 start_cpu = first_cpu;
10870 for_each_present_cpu(cpu) {
10871 cpup = &phba->sli4_hba.cpu_map[cpu];
10873 /* Is this CPU entry unassigned */
10874 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10875 /* Mark CPU as IRQ not assigned by the kernel */
10876 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10878 /* If so, find a new_cpup thats on the the SAME
10879 * phys_id as cpup. start_cpu will start where we
10880 * left off so all unassigned entries don't get assgined
10881 * the IRQ of the first entry.
10883 new_cpu = start_cpu;
10884 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10885 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10886 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10887 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
10888 (new_cpup->phys_id == cpup->phys_id))
10890 new_cpu = cpumask_next(
10891 new_cpu, cpu_present_mask);
10892 if (new_cpu == nr_cpumask_bits)
10893 new_cpu = first_cpu;
10895 /* At this point, we leave the CPU as unassigned */
10898 /* We found a matching phys_id, so copy the IRQ info */
10899 cpup->eq = new_cpup->eq;
10901 /* Bump start_cpu to the next slot to minmize the
10902 * chance of having multiple unassigned CPU entries
10903 * selecting the same IRQ.
10905 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10906 if (start_cpu == nr_cpumask_bits)
10907 start_cpu = first_cpu;
10909 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10910 "3337 Set Affinity: CPU %d "
10911 "eq %d from peer cpu %d same "
10913 cpu, cpup->eq, new_cpu,
10918 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
10919 start_cpu = first_cpu;
10921 for_each_present_cpu(cpu) {
10922 cpup = &phba->sli4_hba.cpu_map[cpu];
10924 /* Is this entry unassigned */
10925 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10926 /* Mark it as IRQ not assigned by the kernel */
10927 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10929 /* If so, find a new_cpup thats on ANY phys_id
10930 * as the cpup. start_cpu will start where we
10931 * left off so all unassigned entries don't get
10932 * assigned the IRQ of the first entry.
10934 new_cpu = start_cpu;
10935 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10936 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10937 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10938 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
10940 new_cpu = cpumask_next(
10941 new_cpu, cpu_present_mask);
10942 if (new_cpu == nr_cpumask_bits)
10943 new_cpu = first_cpu;
10945 /* We should never leave an entry unassigned */
10946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10947 "3339 Set Affinity: CPU %d "
10948 "eq %d UNASSIGNED\n",
10949 cpup->hdwq, cpup->eq);
10952 /* We found an available entry, copy the IRQ info */
10953 cpup->eq = new_cpup->eq;
10955 /* Bump start_cpu to the next slot to minmize the
10956 * chance of having multiple unassigned CPU entries
10957 * selecting the same IRQ.
10959 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10960 if (start_cpu == nr_cpumask_bits)
10961 start_cpu = first_cpu;
10963 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10964 "3338 Set Affinity: CPU %d "
10965 "eq %d from peer cpu %d (%d/%d)\n",
10966 cpu, cpup->eq, new_cpu,
10967 new_cpup->phys_id, new_cpup->core_id);
10971 /* Assign hdwq indices that are unique across all cpus in the map
10972 * that are also FIRST_CPUs.
10975 for_each_present_cpu(cpu) {
10976 cpup = &phba->sli4_hba.cpu_map[cpu];
10978 /* Only FIRST IRQs get a hdwq index assignment. */
10979 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10982 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
10985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10986 "3333 Set Affinity: CPU %d (phys %d core %d): "
10987 "hdwq %d eq %d flg x%x\n",
10988 cpu, cpup->phys_id, cpup->core_id,
10989 cpup->hdwq, cpup->eq, cpup->flag);
10991 /* Associate a hdwq with each cpu_map entry
10992 * This will be 1 to 1 - hdwq to cpu, unless there are less
10993 * hardware queues then CPUs. For that case we will just round-robin
10994 * the available hardware queues as they get assigned to CPUs.
10995 * The next_idx is the idx from the FIRST_CPU loop above to account
10996 * for irq_chann < hdwq. The idx is used for round-robin assignments
10997 * and needs to start at 0.
11002 for_each_present_cpu(cpu) {
11003 cpup = &phba->sli4_hba.cpu_map[cpu];
11005 /* FIRST cpus are already mapped. */
11006 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
11009 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
11010 * of the unassigned cpus to the next idx so that all
11011 * hdw queues are fully utilized.
11013 if (next_idx < phba->cfg_hdw_queue) {
11014 cpup->hdwq = next_idx;
11019 /* Not a First CPU and all hdw_queues are used. Reuse a
11020 * Hardware Queue for another CPU, so be smart about it
11021 * and pick one that has its IRQ/EQ mapped to the same phys_id
11022 * (CPU package) and core_id.
11024 new_cpu = start_cpu;
11025 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11026 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11027 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11028 new_cpup->phys_id == cpup->phys_id &&
11029 new_cpup->core_id == cpup->core_id) {
11032 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11033 if (new_cpu == nr_cpumask_bits)
11034 new_cpu = first_cpu;
11037 /* If we can't match both phys_id and core_id,
11038 * settle for just a phys_id match.
11040 new_cpu = start_cpu;
11041 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11042 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11043 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11044 new_cpup->phys_id == cpup->phys_id)
11047 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11048 if (new_cpu == nr_cpumask_bits)
11049 new_cpu = first_cpu;
11052 /* Otherwise just round robin on cfg_hdw_queue */
11053 cpup->hdwq = idx % phba->cfg_hdw_queue;
11057 /* We found an available entry, copy the IRQ info */
11058 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11059 if (start_cpu == nr_cpumask_bits)
11060 start_cpu = first_cpu;
11061 cpup->hdwq = new_cpup->hdwq;
11063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11064 "3335 Set Affinity: CPU %d (phys %d core %d): "
11065 "hdwq %d eq %d flg x%x\n",
11066 cpu, cpup->phys_id, cpup->core_id,
11067 cpup->hdwq, cpup->eq, cpup->flag);
11071 * Initialize the cpu_map slots for not-present cpus in case
11072 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
11075 for_each_possible_cpu(cpu) {
11076 cpup = &phba->sli4_hba.cpu_map[cpu];
11077 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
11080 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
11081 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11082 "3340 Set Affinity: not present "
11083 "CPU %d hdwq %d\n",
11087 /* The cpu_map array will be used later during initialization
11088 * when EQ / CQ / WQs are allocated and configured.
11094 * lpfc_cpuhp_get_eq
11096 * @phba: pointer to lpfc hba data structure.
11097 * @cpu: cpu going offline
11101 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
11102 struct list_head *eqlist)
11104 const struct cpumask *maskp;
11105 struct lpfc_queue *eq;
11106 struct cpumask *tmp;
11109 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
11113 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
11114 maskp = pci_irq_get_affinity(phba->pcidev, idx);
11118 * if irq is not affinitized to the cpu going
11119 * then we don't need to poll the eq attached
11122 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
11124 /* get the cpus that are online and are affini-
11125 * tized to this irq vector. If the count is
11126 * more than 1 then cpuhp is not going to shut-
11127 * down this vector. Since this cpu has not
11128 * gone offline yet, we need >1.
11130 cpumask_and(tmp, maskp, cpu_online_mask);
11131 if (cpumask_weight(tmp) > 1)
11134 /* Now that we have an irq to shutdown, get the eq
11135 * mapped to this irq. Note: multiple hdwq's in
11136 * the software can share an eq, but eventually
11137 * only eq will be mapped to this vector
11139 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
11140 list_add(&eq->_poll_list, eqlist);
11146 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
11148 if (phba->sli_rev != LPFC_SLI_REV4)
11151 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
11154 * unregistering the instance doesn't stop the polling
11155 * timer. Wait for the poll timer to retire.
11158 del_timer_sync(&phba->cpuhp_poll_timer);
11161 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
11163 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
11166 __lpfc_cpuhp_remove(phba);
11169 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
11171 if (phba->sli_rev != LPFC_SLI_REV4)
11176 if (!list_empty(&phba->poll_list)) {
11177 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
11178 mod_timer(&phba->cpuhp_poll_timer,
11179 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
11184 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
11188 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
11190 if (phba->pport->load_flag & FC_UNLOADING) {
11195 if (phba->sli_rev != LPFC_SLI_REV4) {
11200 /* proceed with the hotplug */
11205 * lpfc_irq_set_aff - set IRQ affinity
11206 * @eqhdl: EQ handle
11207 * @cpu: cpu to set affinity
11211 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
11213 cpumask_clear(&eqhdl->aff_mask);
11214 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
11215 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
11216 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
11220 * lpfc_irq_clear_aff - clear IRQ affinity
11221 * @eqhdl: EQ handle
11225 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
11227 cpumask_clear(&eqhdl->aff_mask);
11228 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
11229 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
11233 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
11234 * @phba: pointer to HBA context object.
11235 * @cpu: cpu going offline/online
11236 * @offline: true, cpu is going offline. false, cpu is coming online.
11238 * If cpu is going offline, we'll try our best effort to find the next
11239 * online cpu on the phba's NUMA node and migrate all offlining IRQ affinities.
11241 * If cpu is coming online, reaffinitize the IRQ back to the onlineng cpu.
11243 * Note: Call only if cfg_irq_numa is enabled, otherwise rely on
11244 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
11248 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
11250 struct lpfc_vector_map_info *cpup;
11251 struct cpumask *aff_mask;
11252 unsigned int cpu_select, cpu_next, idx;
11253 const struct cpumask *numa_mask;
11255 if (!phba->cfg_irq_numa)
11258 numa_mask = &phba->sli4_hba.numa_mask;
11260 if (!cpumask_test_cpu(cpu, numa_mask))
11263 cpup = &phba->sli4_hba.cpu_map[cpu];
11265 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11269 /* Find next online CPU on NUMA node */
11270 cpu_next = cpumask_next_wrap(cpu, numa_mask, cpu, true);
11271 cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu_next);
11273 /* Found a valid CPU */
11274 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
11275 /* Go through each eqhdl and ensure offlining
11276 * cpu aff_mask is migrated
11278 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
11279 aff_mask = lpfc_get_aff_mask(idx);
11281 /* Migrate affinity */
11282 if (cpumask_test_cpu(cpu, aff_mask))
11283 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
11287 /* Rely on irqbalance if no online CPUs left on NUMA */
11288 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
11289 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
11292 /* Migrate affinity back to this CPU */
11293 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
11297 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
11299 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
11300 struct lpfc_queue *eq, *next;
11305 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
11309 if (__lpfc_cpuhp_checks(phba, &retval))
11312 lpfc_irq_rebalance(phba, cpu, true);
11314 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
11318 /* start polling on these eq's */
11319 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
11320 list_del_init(&eq->_poll_list);
11321 lpfc_sli4_start_polling(eq);
11327 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
11329 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
11330 struct lpfc_queue *eq, *next;
11335 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
11339 if (__lpfc_cpuhp_checks(phba, &retval))
11342 lpfc_irq_rebalance(phba, cpu, false);
11344 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
11345 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
11347 lpfc_sli4_stop_polling(eq);
11354 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
11355 * @phba: pointer to lpfc hba data structure.
11357 * This routine is invoked to enable the MSI-X interrupt vectors to device
11358 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
11359 * to cpus on the system.
11361 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
11362 * the number of cpus on the same numa node as this adapter. The vectors are
11363 * allocated without requesting OS affinity mapping. A vector will be
11364 * allocated and assigned to each online and offline cpu. If the cpu is
11365 * online, then affinity will be set to that cpu. If the cpu is offline, then
11366 * affinity will be set to the nearest peer cpu within the numa node that is
11367 * online. If there are no online cpus within the numa node, affinity is not
11368 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
11369 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
11372 * If numa mode is not enabled and there is more than 1 vector allocated, then
11373 * the driver relies on the managed irq interface where the OS assigns vector to
11374 * cpu affinity. The driver will then use that affinity mapping to setup its
11375 * cpu mapping table.
11379 * other values - error
11382 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
11384 int vectors, rc, index;
11386 const struct cpumask *numa_mask = NULL;
11387 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
11388 struct lpfc_hba_eq_hdl *eqhdl;
11389 const struct cpumask *maskp;
11391 unsigned int flags = PCI_IRQ_MSIX;
11393 /* Set up MSI-X multi-message vectors */
11394 vectors = phba->cfg_irq_chann;
11396 if (phba->cfg_irq_numa) {
11397 numa_mask = &phba->sli4_hba.numa_mask;
11398 cpu_cnt = cpumask_weight(numa_mask);
11399 vectors = min(phba->cfg_irq_chann, cpu_cnt);
11401 /* cpu: iterates over numa_mask including offline or online
11402 * cpu_select: iterates over online numa_mask to set affinity
11404 cpu = cpumask_first(numa_mask);
11405 cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu);
11407 flags |= PCI_IRQ_AFFINITY;
11410 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
11412 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11413 "0484 PCI enable MSI-X failed (%d)\n", rc);
11418 /* Assign MSI-X vectors to interrupt handlers */
11419 for (index = 0; index < vectors; index++) {
11420 eqhdl = lpfc_get_eq_hdl(index);
11421 name = eqhdl->handler_name;
11422 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
11423 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
11424 LPFC_DRIVER_HANDLER_NAME"%d", index);
11426 eqhdl->idx = index;
11427 rc = request_irq(pci_irq_vector(phba->pcidev, index),
11428 &lpfc_sli4_hba_intr_handler, 0,
11431 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11432 "0486 MSI-X fast-path (%d) "
11433 "request_irq failed (%d)\n", index, rc);
11437 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
11439 if (phba->cfg_irq_numa) {
11440 /* If found a neighboring online cpu, set affinity */
11441 if (cpu_select < nr_cpu_ids)
11442 lpfc_irq_set_aff(eqhdl, cpu_select);
11444 /* Assign EQ to cpu_map */
11445 lpfc_assign_eq_map_info(phba, index,
11446 LPFC_CPU_FIRST_IRQ,
11449 /* Iterate to next offline or online cpu in numa_mask */
11450 cpu = cpumask_next(cpu, numa_mask);
11452 /* Find next online cpu in numa_mask to set affinity */
11453 cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu);
11454 } else if (vectors == 1) {
11455 cpu = cpumask_first(cpu_present_mask);
11456 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
11459 maskp = pci_irq_get_affinity(phba->pcidev, index);
11462 /* Loop through all CPUs associated with vector index */
11463 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
11464 /* If this is the first CPU thats assigned to
11465 * this vector, set LPFC_CPU_FIRST_IRQ.
11467 lpfc_assign_eq_map_info(phba, index,
11469 LPFC_CPU_FIRST_IRQ : 0,
11477 if (vectors != phba->cfg_irq_chann) {
11478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11479 "3238 Reducing IO channels to match number of "
11480 "MSI-X vectors, requested %d got %d\n",
11481 phba->cfg_irq_chann, vectors);
11482 if (phba->cfg_irq_chann > vectors)
11483 phba->cfg_irq_chann = vectors;
11489 /* free the irq already requested */
11490 for (--index; index >= 0; index--) {
11491 eqhdl = lpfc_get_eq_hdl(index);
11492 lpfc_irq_clear_aff(eqhdl);
11493 irq_set_affinity_hint(eqhdl->irq, NULL);
11494 free_irq(eqhdl->irq, eqhdl);
11497 /* Unconfigure MSI-X capability structure */
11498 pci_free_irq_vectors(phba->pcidev);
11505 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
11506 * @phba: pointer to lpfc hba data structure.
11508 * This routine is invoked to enable the MSI interrupt mode to device with
11509 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
11510 * called to enable the MSI vector. The device driver is responsible for
11511 * calling the request_irq() to register MSI vector with a interrupt the
11512 * handler, which is done in this function.
11516 * other values - error
11519 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
11523 struct lpfc_hba_eq_hdl *eqhdl;
11525 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
11526 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
11528 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11529 "0487 PCI enable MSI mode success.\n");
11531 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11532 "0488 PCI enable MSI mode failed (%d)\n", rc);
11533 return rc ? rc : -1;
11536 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
11537 0, LPFC_DRIVER_NAME, phba);
11539 pci_free_irq_vectors(phba->pcidev);
11540 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11541 "0490 MSI request_irq failed (%d)\n", rc);
11545 eqhdl = lpfc_get_eq_hdl(0);
11546 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
11548 cpu = cpumask_first(cpu_present_mask);
11549 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
11551 for (index = 0; index < phba->cfg_irq_chann; index++) {
11552 eqhdl = lpfc_get_eq_hdl(index);
11553 eqhdl->idx = index;
11560 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
11561 * @phba: pointer to lpfc hba data structure.
11563 * This routine is invoked to enable device interrupt and associate driver's
11564 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
11565 * interface spec. Depends on the interrupt mode configured to the driver,
11566 * the driver will try to fallback from the configured interrupt mode to an
11567 * interrupt mode which is supported by the platform, kernel, and device in
11569 * MSI-X -> MSI -> IRQ.
11573 * other values - error
11576 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
11578 uint32_t intr_mode = LPFC_INTR_ERROR;
11581 if (cfg_mode == 2) {
11582 /* Preparation before conf_msi mbox cmd */
11585 /* Now, try to enable MSI-X interrupt mode */
11586 retval = lpfc_sli4_enable_msix(phba);
11588 /* Indicate initialization to MSI-X mode */
11589 phba->intr_type = MSIX;
11595 /* Fallback to MSI if MSI-X initialization failed */
11596 if (cfg_mode >= 1 && phba->intr_type == NONE) {
11597 retval = lpfc_sli4_enable_msi(phba);
11599 /* Indicate initialization to MSI mode */
11600 phba->intr_type = MSI;
11605 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11606 if (phba->intr_type == NONE) {
11607 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
11608 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
11610 struct lpfc_hba_eq_hdl *eqhdl;
11613 /* Indicate initialization to INTx mode */
11614 phba->intr_type = INTx;
11617 eqhdl = lpfc_get_eq_hdl(0);
11618 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
11620 cpu = cpumask_first(cpu_present_mask);
11621 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
11623 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
11624 eqhdl = lpfc_get_eq_hdl(idx);
11633 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
11634 * @phba: pointer to lpfc hba data structure.
11636 * This routine is invoked to disable device interrupt and disassociate
11637 * the driver's interrupt handler(s) from interrupt vector(s) to device
11638 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
11639 * will release the interrupt vector(s) for the message signaled interrupt.
11642 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
11644 /* Disable the currently initialized interrupt mode */
11645 if (phba->intr_type == MSIX) {
11647 struct lpfc_hba_eq_hdl *eqhdl;
11649 /* Free up MSI-X multi-message vectors */
11650 for (index = 0; index < phba->cfg_irq_chann; index++) {
11651 eqhdl = lpfc_get_eq_hdl(index);
11652 lpfc_irq_clear_aff(eqhdl);
11653 irq_set_affinity_hint(eqhdl->irq, NULL);
11654 free_irq(eqhdl->irq, eqhdl);
11657 free_irq(phba->pcidev->irq, phba);
11660 pci_free_irq_vectors(phba->pcidev);
11662 /* Reset interrupt management states */
11663 phba->intr_type = NONE;
11664 phba->sli.slistat.sli_intr = 0;
11668 * lpfc_unset_hba - Unset SLI3 hba device initialization
11669 * @phba: pointer to lpfc hba data structure.
11671 * This routine is invoked to unset the HBA device initialization steps to
11672 * a device with SLI-3 interface spec.
11675 lpfc_unset_hba(struct lpfc_hba *phba)
11677 struct lpfc_vport *vport = phba->pport;
11678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11680 spin_lock_irq(shost->host_lock);
11681 vport->load_flag |= FC_UNLOADING;
11682 spin_unlock_irq(shost->host_lock);
11684 kfree(phba->vpi_bmask);
11685 kfree(phba->vpi_ids);
11687 lpfc_stop_hba_timers(phba);
11689 phba->pport->work_port_events = 0;
11691 lpfc_sli_hba_down(phba);
11693 lpfc_sli_brdrestart(phba);
11695 lpfc_sli_disable_intr(phba);
11701 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
11702 * @phba: Pointer to HBA context object.
11704 * This function is called in the SLI4 code path to wait for completion
11705 * of device's XRIs exchange busy. It will check the XRI exchange busy
11706 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
11707 * that, it will check the XRI exchange busy on outstanding FCP and ELS
11708 * I/Os every 30 seconds, log error message, and wait forever. Only when
11709 * all XRI exchange busy complete, the driver unload shall proceed with
11710 * invoking the function reset ioctl mailbox command to the CNA and the
11711 * the rest of the driver unload resource release.
11714 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
11716 struct lpfc_sli4_hdw_queue *qp;
11719 int io_xri_cmpl = 1;
11720 int nvmet_xri_cmpl = 1;
11721 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
11723 /* Driver just aborted IOs during the hba_unset process. Pause
11724 * here to give the HBA time to complete the IO and get entries
11725 * into the abts lists.
11727 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
11729 /* Wait for NVME pending IO to flush back to transport. */
11730 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11731 lpfc_nvme_wait_for_io_drain(phba);
11734 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11735 qp = &phba->sli4_hba.hdwq[idx];
11736 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
11737 if (!io_xri_cmpl) /* if list is NOT empty */
11743 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11745 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11748 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
11749 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
11750 if (!nvmet_xri_cmpl)
11751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11752 "6424 NVMET XRI exchange busy "
11753 "wait time: %d seconds.\n",
11756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11757 "6100 IO XRI exchange busy "
11758 "wait time: %d seconds.\n",
11761 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11762 "2878 ELS XRI exchange busy "
11763 "wait time: %d seconds.\n",
11765 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
11766 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
11768 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
11769 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
11773 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11774 qp = &phba->sli4_hba.hdwq[idx];
11775 io_xri_cmpl = list_empty(
11776 &qp->lpfc_abts_io_buf_list);
11777 if (!io_xri_cmpl) /* if list is NOT empty */
11783 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11784 nvmet_xri_cmpl = list_empty(
11785 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11788 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
11794 * lpfc_sli4_hba_unset - Unset the fcoe hba
11795 * @phba: Pointer to HBA context object.
11797 * This function is called in the SLI4 code path to reset the HBA's FCoE
11798 * function. The caller is not required to hold any lock. This routine
11799 * issues PCI function reset mailbox command to reset the FCoE function.
11800 * At the end of the function, it calls lpfc_hba_down_post function to
11801 * free any pending commands.
11804 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
11807 LPFC_MBOXQ_t *mboxq;
11808 struct pci_dev *pdev = phba->pcidev;
11810 lpfc_stop_hba_timers(phba);
11812 phba->sli4_hba.intr_enable = 0;
11815 * Gracefully wait out the potential current outstanding asynchronous
11819 /* First, block any pending async mailbox command from posted */
11820 spin_lock_irq(&phba->hbalock);
11821 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
11822 spin_unlock_irq(&phba->hbalock);
11823 /* Now, trying to wait it out if we can */
11824 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11826 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
11829 /* Forcefully release the outstanding mailbox command if timed out */
11830 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11831 spin_lock_irq(&phba->hbalock);
11832 mboxq = phba->sli.mbox_active;
11833 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
11834 __lpfc_mbox_cmpl_put(phba, mboxq);
11835 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11836 phba->sli.mbox_active = NULL;
11837 spin_unlock_irq(&phba->hbalock);
11840 /* Abort all iocbs associated with the hba */
11841 lpfc_sli_hba_iocb_abort(phba);
11843 /* Wait for completion of device XRI exchange busy */
11844 lpfc_sli4_xri_exchange_busy_wait(phba);
11846 /* per-phba callback de-registration for hotplug event */
11847 lpfc_cpuhp_remove(phba);
11849 /* Disable PCI subsystem interrupt */
11850 lpfc_sli4_disable_intr(phba);
11852 /* Disable SR-IOV if enabled */
11853 if (phba->cfg_sriov_nr_virtfn)
11854 pci_disable_sriov(pdev);
11856 /* Stop kthread signal shall trigger work_done one more time */
11857 kthread_stop(phba->worker_thread);
11859 /* Disable FW logging to host memory */
11860 lpfc_ras_stop_fwlog(phba);
11862 /* Unset the queues shared with the hardware then release all
11863 * allocated resources.
11865 lpfc_sli4_queue_unset(phba);
11866 lpfc_sli4_queue_destroy(phba);
11868 /* Reset SLI4 HBA FCoE function */
11869 lpfc_pci_function_reset(phba);
11871 /* Free RAS DMA memory */
11872 if (phba->ras_fwlog.ras_enabled)
11873 lpfc_sli4_ras_dma_free(phba);
11875 /* Stop the SLI4 device port */
11877 phba->pport->work_port_events = 0;
11881 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
11882 * @phba: Pointer to HBA context object.
11883 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11885 * This function is called in the SLI4 code path to read the port's
11886 * sli4 capabilities.
11888 * This function may be be called from any context that can block-wait
11889 * for the completion. The expectation is that this routine is called
11890 * typically from probe_one or from the online routine.
11893 lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11896 struct lpfc_mqe *mqe;
11897 struct lpfc_pc_sli4_params *sli4_params;
11901 mqe = &mboxq->u.mqe;
11903 /* Read the port's SLI4 Parameters port capabilities */
11904 lpfc_pc_sli4_params(mboxq);
11905 if (!phba->sli4_hba.intr_enable)
11906 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11908 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
11909 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11915 sli4_params = &phba->sli4_hba.pc_sli4_params;
11916 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
11917 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
11918 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
11919 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
11920 &mqe->un.sli4_params);
11921 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
11922 &mqe->un.sli4_params);
11923 sli4_params->proto_types = mqe->un.sli4_params.word3;
11924 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
11925 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
11926 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
11927 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
11928 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
11929 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
11930 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
11931 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
11932 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
11933 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
11934 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
11935 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
11936 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
11937 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
11938 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
11939 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
11940 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
11941 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
11942 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
11943 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
11945 /* Make sure that sge_supp_len can be handled by the driver */
11946 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
11947 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
11953 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
11954 * @phba: Pointer to HBA context object.
11955 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11957 * This function is called in the SLI4 code path to read the port's
11958 * sli4 capabilities.
11960 * This function may be be called from any context that can block-wait
11961 * for the completion. The expectation is that this routine is called
11962 * typically from probe_one or from the online routine.
11965 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11968 struct lpfc_mqe *mqe = &mboxq->u.mqe;
11969 struct lpfc_pc_sli4_params *sli4_params;
11972 bool exp_wqcq_pages = true;
11973 struct lpfc_sli4_parameters *mbx_sli4_parameters;
11976 * By default, the driver assumes the SLI4 port requires RPI
11977 * header postings. The SLI4_PARAM response will correct this
11980 phba->sli4_hba.rpi_hdrs_in_use = 1;
11982 /* Read the port's SLI4 Config Parameters */
11983 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
11984 sizeof(struct lpfc_sli4_cfg_mhdr));
11985 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11986 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
11987 length, LPFC_SLI4_MBX_EMBED);
11988 if (!phba->sli4_hba.intr_enable)
11989 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11991 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
11992 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11996 sli4_params = &phba->sli4_hba.pc_sli4_params;
11997 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
11998 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
11999 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
12000 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
12001 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
12002 mbx_sli4_parameters);
12003 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
12004 mbx_sli4_parameters);
12005 if (bf_get(cfg_phwq, mbx_sli4_parameters))
12006 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
12008 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
12009 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
12010 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
12011 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
12012 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
12013 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
12014 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
12015 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
12016 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
12017 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
12018 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
12019 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
12020 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
12021 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
12022 mbx_sli4_parameters);
12023 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
12024 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
12025 mbx_sli4_parameters);
12026 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
12027 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
12029 /* Check for Extended Pre-Registered SGL support */
12030 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
12032 /* Check for firmware nvme support */
12033 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
12034 bf_get(cfg_xib, mbx_sli4_parameters));
12037 /* Save this to indicate the Firmware supports NVME */
12038 sli4_params->nvme = 1;
12040 /* Firmware NVME support, check driver FC4 NVME support */
12041 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
12042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
12043 "6133 Disabling NVME support: "
12044 "FC4 type not supported: x%x\n",
12045 phba->cfg_enable_fc4_type);
12049 /* No firmware NVME support, check driver FC4 NVME support */
12050 sli4_params->nvme = 0;
12051 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
12053 "6101 Disabling NVME support: Not "
12054 "supported by firmware (%d %d) x%x\n",
12055 bf_get(cfg_nvme, mbx_sli4_parameters),
12056 bf_get(cfg_xib, mbx_sli4_parameters),
12057 phba->cfg_enable_fc4_type);
12059 phba->nvme_support = 0;
12060 phba->nvmet_support = 0;
12061 phba->cfg_nvmet_mrq = 0;
12062 phba->cfg_nvme_seg_cnt = 0;
12064 /* If no FC4 type support, move to just SCSI support */
12065 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
12067 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
12071 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
12072 * accommodate 512K and 1M IOs in a single nvme buf.
12074 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12075 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
12077 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
12078 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
12079 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
12080 phba->cfg_enable_pbde = 0;
12083 * To support Suppress Response feature we must satisfy 3 conditions.
12084 * lpfc_suppress_rsp module parameter must be set (default).
12085 * In SLI4-Parameters Descriptor:
12086 * Extended Inline Buffers (XIB) must be supported.
12087 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
12088 * (double negative).
12090 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
12091 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
12092 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
12094 phba->cfg_suppress_rsp = 0;
12096 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
12097 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
12099 /* Make sure that sge_supp_len can be handled by the driver */
12100 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
12101 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
12104 * Check whether the adapter supports an embedded copy of the
12105 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
12106 * to use this option, 128-byte WQEs must be used.
12108 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
12109 phba->fcp_embed_io = 1;
12111 phba->fcp_embed_io = 0;
12113 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
12114 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
12115 bf_get(cfg_xib, mbx_sli4_parameters),
12116 phba->cfg_enable_pbde,
12117 phba->fcp_embed_io, phba->nvme_support,
12118 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
12120 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
12121 LPFC_SLI_INTF_IF_TYPE_2) &&
12122 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
12123 LPFC_SLI_INTF_FAMILY_LNCR_A0))
12124 exp_wqcq_pages = false;
12126 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
12127 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
12129 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
12130 phba->enab_exp_wqcq_pages = 1;
12132 phba->enab_exp_wqcq_pages = 0;
12134 * Check if the SLI port supports MDS Diagnostics
12136 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
12137 phba->mds_diags_support = 1;
12139 phba->mds_diags_support = 0;
12142 * Check if the SLI port supports NSLER
12144 if (bf_get(cfg_nsler, mbx_sli4_parameters))
12153 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
12154 * @pdev: pointer to PCI device
12155 * @pid: pointer to PCI device identifier
12157 * This routine is to be called to attach a device with SLI-3 interface spec
12158 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12159 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12160 * information of the device and driver to see if the driver state that it can
12161 * support this kind of device. If the match is successful, the driver core
12162 * invokes this routine. If this routine determines it can claim the HBA, it
12163 * does all the initialization that it needs to do to handle the HBA properly.
12166 * 0 - driver can claim the device
12167 * negative value - driver can not claim the device
12170 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
12172 struct lpfc_hba *phba;
12173 struct lpfc_vport *vport = NULL;
12174 struct Scsi_Host *shost = NULL;
12176 uint32_t cfg_mode, intr_mode;
12178 /* Allocate memory for HBA structure */
12179 phba = lpfc_hba_alloc(pdev);
12183 /* Perform generic PCI device enabling operation */
12184 error = lpfc_enable_pci_dev(phba);
12186 goto out_free_phba;
12188 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
12189 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
12191 goto out_disable_pci_dev;
12193 /* Set up SLI-3 specific device PCI memory space */
12194 error = lpfc_sli_pci_mem_setup(phba);
12196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12197 "1402 Failed to set up pci memory space.\n");
12198 goto out_disable_pci_dev;
12201 /* Set up SLI-3 specific device driver resources */
12202 error = lpfc_sli_driver_resource_setup(phba);
12204 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12205 "1404 Failed to set up driver resource.\n");
12206 goto out_unset_pci_mem_s3;
12209 /* Initialize and populate the iocb list per host */
12211 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
12213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12214 "1405 Failed to initialize iocb list.\n");
12215 goto out_unset_driver_resource_s3;
12218 /* Set up common device driver resources */
12219 error = lpfc_setup_driver_resource_phase2(phba);
12221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12222 "1406 Failed to set up driver resource.\n");
12223 goto out_free_iocb_list;
12226 /* Get the default values for Model Name and Description */
12227 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
12229 /* Create SCSI host to the physical port */
12230 error = lpfc_create_shost(phba);
12232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12233 "1407 Failed to create scsi host.\n");
12234 goto out_unset_driver_resource;
12237 /* Configure sysfs attributes */
12238 vport = phba->pport;
12239 error = lpfc_alloc_sysfs_attr(vport);
12241 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12242 "1476 Failed to allocate sysfs attr\n");
12243 goto out_destroy_shost;
12246 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
12247 /* Now, trying to enable interrupt and bring up the device */
12248 cfg_mode = phba->cfg_use_msi;
12250 /* Put device to a known state before enabling interrupt */
12251 lpfc_stop_port(phba);
12252 /* Configure and enable interrupt */
12253 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
12254 if (intr_mode == LPFC_INTR_ERROR) {
12255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12256 "0431 Failed to enable interrupt.\n");
12258 goto out_free_sysfs_attr;
12260 /* SLI-3 HBA setup */
12261 if (lpfc_sli_hba_setup(phba)) {
12262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12263 "1477 Failed to set up hba\n");
12265 goto out_remove_device;
12268 /* Wait 50ms for the interrupts of previous mailbox commands */
12270 /* Check active interrupts on message signaled interrupts */
12271 if (intr_mode == 0 ||
12272 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
12273 /* Log the current active interrupt mode */
12274 phba->intr_mode = intr_mode;
12275 lpfc_log_intr_mode(phba, intr_mode);
12278 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12279 "0447 Configure interrupt mode (%d) "
12280 "failed active interrupt test.\n",
12282 /* Disable the current interrupt mode */
12283 lpfc_sli_disable_intr(phba);
12284 /* Try next level of interrupt mode */
12285 cfg_mode = --intr_mode;
12289 /* Perform post initialization setup */
12290 lpfc_post_init_setup(phba);
12292 /* Check if there are static vports to be created. */
12293 lpfc_create_static_vport(phba);
12298 lpfc_unset_hba(phba);
12299 out_free_sysfs_attr:
12300 lpfc_free_sysfs_attr(vport);
12302 lpfc_destroy_shost(phba);
12303 out_unset_driver_resource:
12304 lpfc_unset_driver_resource_phase2(phba);
12305 out_free_iocb_list:
12306 lpfc_free_iocb_list(phba);
12307 out_unset_driver_resource_s3:
12308 lpfc_sli_driver_resource_unset(phba);
12309 out_unset_pci_mem_s3:
12310 lpfc_sli_pci_mem_unset(phba);
12311 out_disable_pci_dev:
12312 lpfc_disable_pci_dev(phba);
12314 scsi_host_put(shost);
12316 lpfc_hba_free(phba);
12321 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
12322 * @pdev: pointer to PCI device
12324 * This routine is to be called to disattach a device with SLI-3 interface
12325 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12326 * removed from PCI bus, it performs all the necessary cleanup for the HBA
12327 * device to be removed from the PCI subsystem properly.
12330 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
12332 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
12334 struct lpfc_vport **vports;
12335 struct lpfc_hba *phba = vport->phba;
12338 spin_lock_irq(&phba->hbalock);
12339 vport->load_flag |= FC_UNLOADING;
12340 spin_unlock_irq(&phba->hbalock);
12342 lpfc_free_sysfs_attr(vport);
12344 /* Release all the vports against this physical port */
12345 vports = lpfc_create_vport_work_array(phba);
12346 if (vports != NULL)
12347 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
12348 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
12350 fc_vport_terminate(vports[i]->fc_vport);
12352 lpfc_destroy_vport_work_array(phba, vports);
12354 /* Remove FC host and then SCSI host with the physical port */
12355 fc_remove_host(shost);
12356 scsi_remove_host(shost);
12358 lpfc_cleanup(vport);
12361 * Bring down the SLI Layer. This step disable all interrupts,
12362 * clears the rings, discards all mailbox commands, and resets
12366 /* HBA interrupt will be disabled after this call */
12367 lpfc_sli_hba_down(phba);
12368 /* Stop kthread signal shall trigger work_done one more time */
12369 kthread_stop(phba->worker_thread);
12370 /* Final cleanup of txcmplq and reset the HBA */
12371 lpfc_sli_brdrestart(phba);
12373 kfree(phba->vpi_bmask);
12374 kfree(phba->vpi_ids);
12376 lpfc_stop_hba_timers(phba);
12377 spin_lock_irq(&phba->port_list_lock);
12378 list_del_init(&vport->listentry);
12379 spin_unlock_irq(&phba->port_list_lock);
12381 lpfc_debugfs_terminate(vport);
12383 /* Disable SR-IOV if enabled */
12384 if (phba->cfg_sriov_nr_virtfn)
12385 pci_disable_sriov(pdev);
12387 /* Disable interrupt */
12388 lpfc_sli_disable_intr(phba);
12390 scsi_host_put(shost);
12393 * Call scsi_free before mem_free since scsi bufs are released to their
12394 * corresponding pools here.
12396 lpfc_scsi_free(phba);
12397 lpfc_free_iocb_list(phba);
12399 lpfc_mem_free_all(phba);
12401 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
12402 phba->hbqslimp.virt, phba->hbqslimp.phys);
12404 /* Free resources associated with SLI2 interface */
12405 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
12406 phba->slim2p.virt, phba->slim2p.phys);
12408 /* unmap adapter SLIM and Control Registers */
12409 iounmap(phba->ctrl_regs_memmap_p);
12410 iounmap(phba->slim_memmap_p);
12412 lpfc_hba_free(phba);
12414 pci_release_mem_regions(pdev);
12415 pci_disable_device(pdev);
12419 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
12420 * @pdev: pointer to PCI device
12421 * @msg: power management message
12423 * This routine is to be called from the kernel's PCI subsystem to support
12424 * system Power Management (PM) to device with SLI-3 interface spec. When
12425 * PM invokes this method, it quiesces the device by stopping the driver's
12426 * worker thread for the device, turning off device's interrupt and DMA,
12427 * and bring the device offline. Note that as the driver implements the
12428 * minimum PM requirements to a power-aware driver's PM support for the
12429 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12430 * to the suspend() method call will be treated as SUSPEND and the driver will
12431 * fully reinitialize its device during resume() method call, the driver will
12432 * set device to PCI_D3hot state in PCI config space instead of setting it
12433 * according to the @msg provided by the PM.
12436 * 0 - driver suspended the device
12440 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
12442 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12443 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12445 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12446 "0473 PCI device Power Management suspend.\n");
12448 /* Bring down the device */
12449 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
12450 lpfc_offline(phba);
12451 kthread_stop(phba->worker_thread);
12453 /* Disable interrupt from device */
12454 lpfc_sli_disable_intr(phba);
12456 /* Save device state to PCI config space */
12457 pci_save_state(pdev);
12458 pci_set_power_state(pdev, PCI_D3hot);
12464 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
12465 * @pdev: pointer to PCI device
12467 * This routine is to be called from the kernel's PCI subsystem to support
12468 * system Power Management (PM) to device with SLI-3 interface spec. When PM
12469 * invokes this method, it restores the device's PCI config space state and
12470 * fully reinitializes the device and brings it online. Note that as the
12471 * driver implements the minimum PM requirements to a power-aware driver's
12472 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
12473 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
12474 * driver will fully reinitialize its device during resume() method call,
12475 * the device will be set to PCI_D0 directly in PCI config space before
12476 * restoring the state.
12479 * 0 - driver suspended the device
12483 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
12485 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12486 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12487 uint32_t intr_mode;
12490 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12491 "0452 PCI device Power Management resume.\n");
12493 /* Restore device state from PCI config space */
12494 pci_set_power_state(pdev, PCI_D0);
12495 pci_restore_state(pdev);
12498 * As the new kernel behavior of pci_restore_state() API call clears
12499 * device saved_state flag, need to save the restored state again.
12501 pci_save_state(pdev);
12503 if (pdev->is_busmaster)
12504 pci_set_master(pdev);
12506 /* Startup the kernel thread for this host adapter. */
12507 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12508 "lpfc_worker_%d", phba->brd_no);
12509 if (IS_ERR(phba->worker_thread)) {
12510 error = PTR_ERR(phba->worker_thread);
12511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12512 "0434 PM resume failed to start worker "
12513 "thread: error=x%x.\n", error);
12517 /* Configure and enable interrupt */
12518 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
12519 if (intr_mode == LPFC_INTR_ERROR) {
12520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12521 "0430 PM resume Failed to enable interrupt\n");
12524 phba->intr_mode = intr_mode;
12526 /* Restart HBA and bring it online */
12527 lpfc_sli_brdrestart(phba);
12530 /* Log the current active interrupt mode */
12531 lpfc_log_intr_mode(phba, phba->intr_mode);
12537 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
12538 * @phba: pointer to lpfc hba data structure.
12540 * This routine is called to prepare the SLI3 device for PCI slot recover. It
12541 * aborts all the outstanding SCSI I/Os to the pci device.
12544 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
12546 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12547 "2723 PCI channel I/O abort preparing for recovery\n");
12550 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12551 * and let the SCSI mid-layer to retry them to recover.
12553 lpfc_sli_abort_fcp_rings(phba);
12557 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
12558 * @phba: pointer to lpfc hba data structure.
12560 * This routine is called to prepare the SLI3 device for PCI slot reset. It
12561 * disables the device interrupt and pci device, and aborts the internal FCP
12565 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
12567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12568 "2710 PCI channel disable preparing for reset\n");
12570 /* Block any management I/Os to the device */
12571 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
12573 /* Block all SCSI devices' I/Os on the host */
12574 lpfc_scsi_dev_block(phba);
12576 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12577 lpfc_sli_flush_io_rings(phba);
12579 /* stop all timers */
12580 lpfc_stop_hba_timers(phba);
12582 /* Disable interrupt and pci device */
12583 lpfc_sli_disable_intr(phba);
12584 pci_disable_device(phba->pcidev);
12588 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
12589 * @phba: pointer to lpfc hba data structure.
12591 * This routine is called to prepare the SLI3 device for PCI slot permanently
12592 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12596 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12599 "2711 PCI channel permanent disable for failure\n");
12600 /* Block all SCSI devices' I/Os on the host */
12601 lpfc_scsi_dev_block(phba);
12603 /* stop all timers */
12604 lpfc_stop_hba_timers(phba);
12606 /* Clean up all driver's outstanding SCSI I/Os */
12607 lpfc_sli_flush_io_rings(phba);
12611 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
12612 * @pdev: pointer to PCI device.
12613 * @state: the current PCI connection state.
12615 * This routine is called from the PCI subsystem for I/O error handling to
12616 * device with SLI-3 interface spec. This function is called by the PCI
12617 * subsystem after a PCI bus error affecting this device has been detected.
12618 * When this function is invoked, it will need to stop all the I/Os and
12619 * interrupt(s) to the device. Once that is done, it will return
12620 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
12624 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
12625 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12626 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12628 static pci_ers_result_t
12629 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
12631 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12632 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12635 case pci_channel_io_normal:
12636 /* Non-fatal error, prepare for recovery */
12637 lpfc_sli_prep_dev_for_recover(phba);
12638 return PCI_ERS_RESULT_CAN_RECOVER;
12639 case pci_channel_io_frozen:
12640 /* Fatal error, prepare for slot reset */
12641 lpfc_sli_prep_dev_for_reset(phba);
12642 return PCI_ERS_RESULT_NEED_RESET;
12643 case pci_channel_io_perm_failure:
12644 /* Permanent failure, prepare for device down */
12645 lpfc_sli_prep_dev_for_perm_failure(phba);
12646 return PCI_ERS_RESULT_DISCONNECT;
12648 /* Unknown state, prepare and request slot reset */
12649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12650 "0472 Unknown PCI error state: x%x\n", state);
12651 lpfc_sli_prep_dev_for_reset(phba);
12652 return PCI_ERS_RESULT_NEED_RESET;
12657 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
12658 * @pdev: pointer to PCI device.
12660 * This routine is called from the PCI subsystem for error handling to
12661 * device with SLI-3 interface spec. This is called after PCI bus has been
12662 * reset to restart the PCI card from scratch, as if from a cold-boot.
12663 * During the PCI subsystem error recovery, after driver returns
12664 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12665 * recovery and then call this routine before calling the .resume method
12666 * to recover the device. This function will initialize the HBA device,
12667 * enable the interrupt, but it will just put the HBA to offline state
12668 * without passing any I/O traffic.
12671 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12672 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12674 static pci_ers_result_t
12675 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
12677 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12678 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12679 struct lpfc_sli *psli = &phba->sli;
12680 uint32_t intr_mode;
12682 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12683 if (pci_enable_device_mem(pdev)) {
12684 printk(KERN_ERR "lpfc: Cannot re-enable "
12685 "PCI device after reset.\n");
12686 return PCI_ERS_RESULT_DISCONNECT;
12689 pci_restore_state(pdev);
12692 * As the new kernel behavior of pci_restore_state() API call clears
12693 * device saved_state flag, need to save the restored state again.
12695 pci_save_state(pdev);
12697 if (pdev->is_busmaster)
12698 pci_set_master(pdev);
12700 spin_lock_irq(&phba->hbalock);
12701 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12702 spin_unlock_irq(&phba->hbalock);
12704 /* Configure and enable interrupt */
12705 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
12706 if (intr_mode == LPFC_INTR_ERROR) {
12707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12708 "0427 Cannot re-enable interrupt after "
12710 return PCI_ERS_RESULT_DISCONNECT;
12712 phba->intr_mode = intr_mode;
12714 /* Take device offline, it will perform cleanup */
12715 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
12716 lpfc_offline(phba);
12717 lpfc_sli_brdrestart(phba);
12719 /* Log the current active interrupt mode */
12720 lpfc_log_intr_mode(phba, phba->intr_mode);
12722 return PCI_ERS_RESULT_RECOVERED;
12726 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
12727 * @pdev: pointer to PCI device
12729 * This routine is called from the PCI subsystem for error handling to device
12730 * with SLI-3 interface spec. It is called when kernel error recovery tells
12731 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12732 * error recovery. After this call, traffic can start to flow from this device
12736 lpfc_io_resume_s3(struct pci_dev *pdev)
12738 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12739 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12741 /* Bring device online, it will be no-op for non-fatal error resume */
12746 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
12747 * @phba: pointer to lpfc hba data structure.
12749 * returns the number of ELS/CT IOCBs to reserve
12752 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
12754 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
12756 if (phba->sli_rev == LPFC_SLI_REV4) {
12757 if (max_xri <= 100)
12759 else if (max_xri <= 256)
12761 else if (max_xri <= 512)
12763 else if (max_xri <= 1024)
12765 else if (max_xri <= 1536)
12767 else if (max_xri <= 2048)
12776 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
12777 * @phba: pointer to lpfc hba data structure.
12779 * returns the number of ELS/CT + NVMET IOCBs to reserve
12782 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
12784 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
12786 if (phba->nvmet_support)
12787 max_xri += LPFC_NVMET_BUF_POST;
12793 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
12794 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
12795 const struct firmware *fw)
12799 /* Three cases: (1) FW was not supported on the detected adapter.
12800 * (2) FW update has been locked out administratively.
12801 * (3) Some other error during FW update.
12802 * In each case, an unmaskable message is written to the console
12803 * for admin diagnosis.
12805 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
12806 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
12807 magic_number != MAGIC_NUMBER_G6) ||
12808 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
12809 magic_number != MAGIC_NUMBER_G7)) {
12810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12811 "3030 This firmware version is not supported on"
12812 " this HBA model. Device:%x Magic:%x Type:%x "
12813 "ID:%x Size %d %zd\n",
12814 phba->pcidev->device, magic_number, ftype, fid,
12817 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
12818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12819 "3021 Firmware downloads have been prohibited "
12820 "by a system configuration setting on "
12821 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12823 phba->pcidev->device, magic_number, ftype, fid,
12827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12828 "3022 FW Download failed. Add Status x%x "
12829 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12831 offset, phba->pcidev->device, magic_number,
12832 ftype, fid, fsize, fw->size);
12839 * lpfc_write_firmware - attempt to write a firmware image to the port
12840 * @fw: pointer to firmware image returned from request_firmware.
12841 * @context: pointer to firmware image returned from request_firmware.
12842 * @ret: return value this routine provides to the caller.
12846 lpfc_write_firmware(const struct firmware *fw, void *context)
12848 struct lpfc_hba *phba = (struct lpfc_hba *)context;
12849 char fwrev[FW_REV_STR_SIZE];
12850 struct lpfc_grp_hdr *image;
12851 struct list_head dma_buffer_list;
12853 struct lpfc_dmabuf *dmabuf, *next;
12854 uint32_t offset = 0, temp_offset = 0;
12855 uint32_t magic_number, ftype, fid, fsize;
12857 /* It can be null in no-wait mode, sanity check */
12862 image = (struct lpfc_grp_hdr *)fw->data;
12864 magic_number = be32_to_cpu(image->magic_number);
12865 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
12866 fid = bf_get_be32(lpfc_grp_hdr_id, image);
12867 fsize = be32_to_cpu(image->size);
12869 INIT_LIST_HEAD(&dma_buffer_list);
12870 lpfc_decode_firmware_rev(phba, fwrev, 1);
12871 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
12872 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12873 "3023 Updating Firmware, Current Version:%s "
12874 "New Version:%s\n",
12875 fwrev, image->revision);
12876 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
12877 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
12883 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
12887 if (!dmabuf->virt) {
12892 list_add_tail(&dmabuf->list, &dma_buffer_list);
12894 while (offset < fw->size) {
12895 temp_offset = offset;
12896 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
12897 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
12898 memcpy(dmabuf->virt,
12899 fw->data + temp_offset,
12900 fw->size - temp_offset);
12901 temp_offset = fw->size;
12904 memcpy(dmabuf->virt, fw->data + temp_offset,
12906 temp_offset += SLI4_PAGE_SIZE;
12908 rc = lpfc_wr_object(phba, &dma_buffer_list,
12909 (fw->size - offset), &offset);
12911 rc = lpfc_log_write_firmware_error(phba, offset,
12922 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12923 "3029 Skipped Firmware update, Current "
12924 "Version:%s New Version:%s\n",
12925 fwrev, image->revision);
12928 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
12929 list_del(&dmabuf->list);
12930 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
12931 dmabuf->virt, dmabuf->phys);
12934 release_firmware(fw);
12937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12938 "3062 Firmware update error, status %d.\n", rc);
12940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12941 "3024 Firmware update success: size %d.\n", rc);
12945 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
12946 * @phba: pointer to lpfc hba data structure.
12948 * This routine is called to perform Linux generic firmware upgrade on device
12949 * that supports such feature.
12952 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
12954 uint8_t file_name[ELX_MODEL_NAME_SIZE];
12956 const struct firmware *fw;
12958 /* Only supported on SLI4 interface type 2 for now */
12959 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
12960 LPFC_SLI_INTF_IF_TYPE_2)
12963 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
12965 if (fw_upgrade == INT_FW_UPGRADE) {
12966 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
12967 file_name, &phba->pcidev->dev,
12968 GFP_KERNEL, (void *)phba,
12969 lpfc_write_firmware);
12970 } else if (fw_upgrade == RUN_FW_UPGRADE) {
12971 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
12973 lpfc_write_firmware(fw, (void *)phba);
12982 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
12983 * @pdev: pointer to PCI device
12984 * @pid: pointer to PCI device identifier
12986 * This routine is called from the kernel's PCI subsystem to device with
12987 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
12988 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12989 * information of the device and driver to see if the driver state that it
12990 * can support this kind of device. If the match is successful, the driver
12991 * core invokes this routine. If this routine determines it can claim the HBA,
12992 * it does all the initialization that it needs to do to handle the HBA
12996 * 0 - driver can claim the device
12997 * negative value - driver can not claim the device
13000 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
13002 struct lpfc_hba *phba;
13003 struct lpfc_vport *vport = NULL;
13004 struct Scsi_Host *shost = NULL;
13006 uint32_t cfg_mode, intr_mode;
13008 /* Allocate memory for HBA structure */
13009 phba = lpfc_hba_alloc(pdev);
13013 /* Perform generic PCI device enabling operation */
13014 error = lpfc_enable_pci_dev(phba);
13016 goto out_free_phba;
13018 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
13019 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
13021 goto out_disable_pci_dev;
13023 /* Set up SLI-4 specific device PCI memory space */
13024 error = lpfc_sli4_pci_mem_setup(phba);
13026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13027 "1410 Failed to set up pci memory space.\n");
13028 goto out_disable_pci_dev;
13031 /* Set up SLI-4 Specific device driver resources */
13032 error = lpfc_sli4_driver_resource_setup(phba);
13034 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13035 "1412 Failed to set up driver resource.\n");
13036 goto out_unset_pci_mem_s4;
13039 INIT_LIST_HEAD(&phba->active_rrq_list);
13040 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
13042 /* Set up common device driver resources */
13043 error = lpfc_setup_driver_resource_phase2(phba);
13045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13046 "1414 Failed to set up driver resource.\n");
13047 goto out_unset_driver_resource_s4;
13050 /* Get the default values for Model Name and Description */
13051 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13053 /* Now, trying to enable interrupt and bring up the device */
13054 cfg_mode = phba->cfg_use_msi;
13056 /* Put device to a known state before enabling interrupt */
13057 phba->pport = NULL;
13058 lpfc_stop_port(phba);
13060 /* Init cpu_map array */
13061 lpfc_cpu_map_array_init(phba);
13063 /* Init hba_eq_hdl array */
13064 lpfc_hba_eq_hdl_array_init(phba);
13066 /* Configure and enable interrupt */
13067 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
13068 if (intr_mode == LPFC_INTR_ERROR) {
13069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13070 "0426 Failed to enable interrupt.\n");
13072 goto out_unset_driver_resource;
13074 /* Default to single EQ for non-MSI-X */
13075 if (phba->intr_type != MSIX) {
13076 phba->cfg_irq_chann = 1;
13077 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13078 if (phba->nvmet_support)
13079 phba->cfg_nvmet_mrq = 1;
13082 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
13084 /* Create SCSI host to the physical port */
13085 error = lpfc_create_shost(phba);
13087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13088 "1415 Failed to create scsi host.\n");
13089 goto out_disable_intr;
13091 vport = phba->pport;
13092 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
13094 /* Configure sysfs attributes */
13095 error = lpfc_alloc_sysfs_attr(vport);
13097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13098 "1416 Failed to allocate sysfs attr\n");
13099 goto out_destroy_shost;
13102 /* Set up SLI-4 HBA */
13103 if (lpfc_sli4_hba_setup(phba)) {
13104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13105 "1421 Failed to set up hba\n");
13107 goto out_free_sysfs_attr;
13110 /* Log the current active interrupt mode */
13111 phba->intr_mode = intr_mode;
13112 lpfc_log_intr_mode(phba, intr_mode);
13114 /* Perform post initialization setup */
13115 lpfc_post_init_setup(phba);
13117 /* NVME support in FW earlier in the driver load corrects the
13118 * FC4 type making a check for nvme_support unnecessary.
13120 if (phba->nvmet_support == 0) {
13121 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13122 /* Create NVME binding with nvme_fc_transport. This
13123 * ensures the vport is initialized. If the localport
13124 * create fails, it should not unload the driver to
13125 * support field issues.
13127 error = lpfc_nvme_create_localport(vport);
13129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13130 "6004 NVME registration "
13131 "failed, error x%x\n",
13137 /* check for firmware upgrade or downgrade */
13138 if (phba->cfg_request_firmware_upgrade)
13139 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
13141 /* Check if there are static vports to be created. */
13142 lpfc_create_static_vport(phba);
13144 /* Enable RAS FW log support */
13145 lpfc_sli4_ras_setup(phba);
13147 INIT_LIST_HEAD(&phba->poll_list);
13148 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
13152 out_free_sysfs_attr:
13153 lpfc_free_sysfs_attr(vport);
13155 lpfc_destroy_shost(phba);
13157 lpfc_sli4_disable_intr(phba);
13158 out_unset_driver_resource:
13159 lpfc_unset_driver_resource_phase2(phba);
13160 out_unset_driver_resource_s4:
13161 lpfc_sli4_driver_resource_unset(phba);
13162 out_unset_pci_mem_s4:
13163 lpfc_sli4_pci_mem_unset(phba);
13164 out_disable_pci_dev:
13165 lpfc_disable_pci_dev(phba);
13167 scsi_host_put(shost);
13169 lpfc_hba_free(phba);
13174 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
13175 * @pdev: pointer to PCI device
13177 * This routine is called from the kernel's PCI subsystem to device with
13178 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13179 * removed from PCI bus, it performs all the necessary cleanup for the HBA
13180 * device to be removed from the PCI subsystem properly.
13183 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
13185 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
13187 struct lpfc_vport **vports;
13188 struct lpfc_hba *phba = vport->phba;
13191 /* Mark the device unloading flag */
13192 spin_lock_irq(&phba->hbalock);
13193 vport->load_flag |= FC_UNLOADING;
13194 spin_unlock_irq(&phba->hbalock);
13196 /* Free the HBA sysfs attributes */
13197 lpfc_free_sysfs_attr(vport);
13199 /* Release all the vports against this physical port */
13200 vports = lpfc_create_vport_work_array(phba);
13201 if (vports != NULL)
13202 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
13203 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
13205 fc_vport_terminate(vports[i]->fc_vport);
13207 lpfc_destroy_vport_work_array(phba, vports);
13209 /* Remove FC host and then SCSI host with the physical port */
13210 fc_remove_host(shost);
13211 scsi_remove_host(shost);
13213 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
13214 * localports are destroyed after to cleanup all transport memory.
13216 lpfc_cleanup(vport);
13217 lpfc_nvmet_destroy_targetport(phba);
13218 lpfc_nvme_destroy_localport(vport);
13220 /* De-allocate multi-XRI pools */
13221 if (phba->cfg_xri_rebalancing)
13222 lpfc_destroy_multixri_pools(phba);
13225 * Bring down the SLI Layer. This step disables all interrupts,
13226 * clears the rings, discards all mailbox commands, and resets
13227 * the HBA FCoE function.
13229 lpfc_debugfs_terminate(vport);
13231 lpfc_stop_hba_timers(phba);
13232 spin_lock_irq(&phba->port_list_lock);
13233 list_del_init(&vport->listentry);
13234 spin_unlock_irq(&phba->port_list_lock);
13236 /* Perform scsi free before driver resource_unset since scsi
13237 * buffers are released to their corresponding pools here.
13239 lpfc_io_free(phba);
13240 lpfc_free_iocb_list(phba);
13241 lpfc_sli4_hba_unset(phba);
13243 lpfc_unset_driver_resource_phase2(phba);
13244 lpfc_sli4_driver_resource_unset(phba);
13246 /* Unmap adapter Control and Doorbell registers */
13247 lpfc_sli4_pci_mem_unset(phba);
13249 /* Release PCI resources and disable device's PCI function */
13250 scsi_host_put(shost);
13251 lpfc_disable_pci_dev(phba);
13253 /* Finally, free the driver's device data structure */
13254 lpfc_hba_free(phba);
13260 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
13261 * @pdev: pointer to PCI device
13262 * @msg: power management message
13264 * This routine is called from the kernel's PCI subsystem to support system
13265 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
13266 * this method, it quiesces the device by stopping the driver's worker
13267 * thread for the device, turning off device's interrupt and DMA, and bring
13268 * the device offline. Note that as the driver implements the minimum PM
13269 * requirements to a power-aware driver's PM support for suspend/resume -- all
13270 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
13271 * method call will be treated as SUSPEND and the driver will fully
13272 * reinitialize its device during resume() method call, the driver will set
13273 * device to PCI_D3hot state in PCI config space instead of setting it
13274 * according to the @msg provided by the PM.
13277 * 0 - driver suspended the device
13281 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
13283 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13284 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13286 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13287 "2843 PCI device Power Management suspend.\n");
13289 /* Bring down the device */
13290 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
13291 lpfc_offline(phba);
13292 kthread_stop(phba->worker_thread);
13294 /* Disable interrupt from device */
13295 lpfc_sli4_disable_intr(phba);
13296 lpfc_sli4_queue_destroy(phba);
13298 /* Save device state to PCI config space */
13299 pci_save_state(pdev);
13300 pci_set_power_state(pdev, PCI_D3hot);
13306 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
13307 * @pdev: pointer to PCI device
13309 * This routine is called from the kernel's PCI subsystem to support system
13310 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
13311 * this method, it restores the device's PCI config space state and fully
13312 * reinitializes the device and brings it online. Note that as the driver
13313 * implements the minimum PM requirements to a power-aware driver's PM for
13314 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
13315 * to the suspend() method call will be treated as SUSPEND and the driver
13316 * will fully reinitialize its device during resume() method call, the device
13317 * will be set to PCI_D0 directly in PCI config space before restoring the
13321 * 0 - driver suspended the device
13325 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
13327 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13328 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13329 uint32_t intr_mode;
13332 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13333 "0292 PCI device Power Management resume.\n");
13335 /* Restore device state from PCI config space */
13336 pci_set_power_state(pdev, PCI_D0);
13337 pci_restore_state(pdev);
13340 * As the new kernel behavior of pci_restore_state() API call clears
13341 * device saved_state flag, need to save the restored state again.
13343 pci_save_state(pdev);
13345 if (pdev->is_busmaster)
13346 pci_set_master(pdev);
13348 /* Startup the kernel thread for this host adapter. */
13349 phba->worker_thread = kthread_run(lpfc_do_work, phba,
13350 "lpfc_worker_%d", phba->brd_no);
13351 if (IS_ERR(phba->worker_thread)) {
13352 error = PTR_ERR(phba->worker_thread);
13353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13354 "0293 PM resume failed to start worker "
13355 "thread: error=x%x.\n", error);
13359 /* Configure and enable interrupt */
13360 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13361 if (intr_mode == LPFC_INTR_ERROR) {
13362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13363 "0294 PM resume Failed to enable interrupt\n");
13366 phba->intr_mode = intr_mode;
13368 /* Restart HBA and bring it online */
13369 lpfc_sli_brdrestart(phba);
13372 /* Log the current active interrupt mode */
13373 lpfc_log_intr_mode(phba, phba->intr_mode);
13379 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
13380 * @phba: pointer to lpfc hba data structure.
13382 * This routine is called to prepare the SLI4 device for PCI slot recover. It
13383 * aborts all the outstanding SCSI I/Os to the pci device.
13386 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
13388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13389 "2828 PCI channel I/O abort preparing for recovery\n");
13391 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
13392 * and let the SCSI mid-layer to retry them to recover.
13394 lpfc_sli_abort_fcp_rings(phba);
13398 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
13399 * @phba: pointer to lpfc hba data structure.
13401 * This routine is called to prepare the SLI4 device for PCI slot reset. It
13402 * disables the device interrupt and pci device, and aborts the internal FCP
13406 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
13408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13409 "2826 PCI channel disable preparing for reset\n");
13411 /* Block any management I/Os to the device */
13412 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
13414 /* Block all SCSI devices' I/Os on the host */
13415 lpfc_scsi_dev_block(phba);
13417 /* Flush all driver's outstanding I/Os as we are to reset */
13418 lpfc_sli_flush_io_rings(phba);
13420 /* stop all timers */
13421 lpfc_stop_hba_timers(phba);
13423 /* Disable interrupt and pci device */
13424 lpfc_sli4_disable_intr(phba);
13425 lpfc_sli4_queue_destroy(phba);
13426 pci_disable_device(phba->pcidev);
13430 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
13431 * @phba: pointer to lpfc hba data structure.
13433 * This routine is called to prepare the SLI4 device for PCI slot permanently
13434 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
13438 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
13440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13441 "2827 PCI channel permanent disable for failure\n");
13443 /* Block all SCSI devices' I/Os on the host */
13444 lpfc_scsi_dev_block(phba);
13446 /* stop all timers */
13447 lpfc_stop_hba_timers(phba);
13449 /* Clean up all driver's outstanding I/Os */
13450 lpfc_sli_flush_io_rings(phba);
13454 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
13455 * @pdev: pointer to PCI device.
13456 * @state: the current PCI connection state.
13458 * This routine is called from the PCI subsystem for error handling to device
13459 * with SLI-4 interface spec. This function is called by the PCI subsystem
13460 * after a PCI bus error affecting this device has been detected. When this
13461 * function is invoked, it will need to stop all the I/Os and interrupt(s)
13462 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
13463 * for the PCI subsystem to perform proper recovery as desired.
13466 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13467 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13469 static pci_ers_result_t
13470 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
13472 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13473 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13476 case pci_channel_io_normal:
13477 /* Non-fatal error, prepare for recovery */
13478 lpfc_sli4_prep_dev_for_recover(phba);
13479 return PCI_ERS_RESULT_CAN_RECOVER;
13480 case pci_channel_io_frozen:
13481 /* Fatal error, prepare for slot reset */
13482 lpfc_sli4_prep_dev_for_reset(phba);
13483 return PCI_ERS_RESULT_NEED_RESET;
13484 case pci_channel_io_perm_failure:
13485 /* Permanent failure, prepare for device down */
13486 lpfc_sli4_prep_dev_for_perm_failure(phba);
13487 return PCI_ERS_RESULT_DISCONNECT;
13489 /* Unknown state, prepare and request slot reset */
13490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13491 "2825 Unknown PCI error state: x%x\n", state);
13492 lpfc_sli4_prep_dev_for_reset(phba);
13493 return PCI_ERS_RESULT_NEED_RESET;
13498 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
13499 * @pdev: pointer to PCI device.
13501 * This routine is called from the PCI subsystem for error handling to device
13502 * with SLI-4 interface spec. It is called after PCI bus has been reset to
13503 * restart the PCI card from scratch, as if from a cold-boot. During the
13504 * PCI subsystem error recovery, after the driver returns
13505 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13506 * recovery and then call this routine before calling the .resume method to
13507 * recover the device. This function will initialize the HBA device, enable
13508 * the interrupt, but it will just put the HBA to offline state without
13509 * passing any I/O traffic.
13512 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13513 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13515 static pci_ers_result_t
13516 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
13518 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13519 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13520 struct lpfc_sli *psli = &phba->sli;
13521 uint32_t intr_mode;
13523 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
13524 if (pci_enable_device_mem(pdev)) {
13525 printk(KERN_ERR "lpfc: Cannot re-enable "
13526 "PCI device after reset.\n");
13527 return PCI_ERS_RESULT_DISCONNECT;
13530 pci_restore_state(pdev);
13533 * As the new kernel behavior of pci_restore_state() API call clears
13534 * device saved_state flag, need to save the restored state again.
13536 pci_save_state(pdev);
13538 if (pdev->is_busmaster)
13539 pci_set_master(pdev);
13541 spin_lock_irq(&phba->hbalock);
13542 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
13543 spin_unlock_irq(&phba->hbalock);
13545 /* Configure and enable interrupt */
13546 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13547 if (intr_mode == LPFC_INTR_ERROR) {
13548 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13549 "2824 Cannot re-enable interrupt after "
13551 return PCI_ERS_RESULT_DISCONNECT;
13553 phba->intr_mode = intr_mode;
13555 /* Log the current active interrupt mode */
13556 lpfc_log_intr_mode(phba, phba->intr_mode);
13558 return PCI_ERS_RESULT_RECOVERED;
13562 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
13563 * @pdev: pointer to PCI device
13565 * This routine is called from the PCI subsystem for error handling to device
13566 * with SLI-4 interface spec. It is called when kernel error recovery tells
13567 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13568 * error recovery. After this call, traffic can start to flow from this device
13572 lpfc_io_resume_s4(struct pci_dev *pdev)
13574 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13575 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13578 * In case of slot reset, as function reset is performed through
13579 * mailbox command which needs DMA to be enabled, this operation
13580 * has to be moved to the io resume phase. Taking device offline
13581 * will perform the necessary cleanup.
13583 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
13584 /* Perform device reset */
13585 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
13586 lpfc_offline(phba);
13587 lpfc_sli_brdrestart(phba);
13588 /* Bring the device back online */
13594 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
13595 * @pdev: pointer to PCI device
13596 * @pid: pointer to PCI device identifier
13598 * This routine is to be registered to the kernel's PCI subsystem. When an
13599 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
13600 * at PCI device-specific information of the device and driver to see if the
13601 * driver state that it can support this kind of device. If the match is
13602 * successful, the driver core invokes this routine. This routine dispatches
13603 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
13604 * do all the initialization that it needs to do to handle the HBA device
13608 * 0 - driver can claim the device
13609 * negative value - driver can not claim the device
13612 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
13615 struct lpfc_sli_intf intf;
13617 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
13620 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
13621 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
13622 rc = lpfc_pci_probe_one_s4(pdev, pid);
13624 rc = lpfc_pci_probe_one_s3(pdev, pid);
13630 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
13631 * @pdev: pointer to PCI device
13633 * This routine is to be registered to the kernel's PCI subsystem. When an
13634 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
13635 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
13636 * remove routine, which will perform all the necessary cleanup for the
13637 * device to be removed from the PCI subsystem properly.
13640 lpfc_pci_remove_one(struct pci_dev *pdev)
13642 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13643 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13645 switch (phba->pci_dev_grp) {
13646 case LPFC_PCI_DEV_LP:
13647 lpfc_pci_remove_one_s3(pdev);
13649 case LPFC_PCI_DEV_OC:
13650 lpfc_pci_remove_one_s4(pdev);
13653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13654 "1424 Invalid PCI device group: 0x%x\n",
13655 phba->pci_dev_grp);
13662 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
13663 * @pdev: pointer to PCI device
13664 * @msg: power management message
13666 * This routine is to be registered to the kernel's PCI subsystem to support
13667 * system Power Management (PM). When PM invokes this method, it dispatches
13668 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
13669 * suspend the device.
13672 * 0 - driver suspended the device
13676 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
13678 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13679 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13682 switch (phba->pci_dev_grp) {
13683 case LPFC_PCI_DEV_LP:
13684 rc = lpfc_pci_suspend_one_s3(pdev, msg);
13686 case LPFC_PCI_DEV_OC:
13687 rc = lpfc_pci_suspend_one_s4(pdev, msg);
13690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13691 "1425 Invalid PCI device group: 0x%x\n",
13692 phba->pci_dev_grp);
13699 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
13700 * @pdev: pointer to PCI device
13702 * This routine is to be registered to the kernel's PCI subsystem to support
13703 * system Power Management (PM). When PM invokes this method, it dispatches
13704 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
13705 * resume the device.
13708 * 0 - driver suspended the device
13712 lpfc_pci_resume_one(struct pci_dev *pdev)
13714 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13715 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13718 switch (phba->pci_dev_grp) {
13719 case LPFC_PCI_DEV_LP:
13720 rc = lpfc_pci_resume_one_s3(pdev);
13722 case LPFC_PCI_DEV_OC:
13723 rc = lpfc_pci_resume_one_s4(pdev);
13726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13727 "1426 Invalid PCI device group: 0x%x\n",
13728 phba->pci_dev_grp);
13735 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
13736 * @pdev: pointer to PCI device.
13737 * @state: the current PCI connection state.
13739 * This routine is registered to the PCI subsystem for error handling. This
13740 * function is called by the PCI subsystem after a PCI bus error affecting
13741 * this device has been detected. When this routine is invoked, it dispatches
13742 * the action to the proper SLI-3 or SLI-4 device error detected handling
13743 * routine, which will perform the proper error detected operation.
13746 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13747 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13749 static pci_ers_result_t
13750 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
13752 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13753 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13754 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13756 switch (phba->pci_dev_grp) {
13757 case LPFC_PCI_DEV_LP:
13758 rc = lpfc_io_error_detected_s3(pdev, state);
13760 case LPFC_PCI_DEV_OC:
13761 rc = lpfc_io_error_detected_s4(pdev, state);
13764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13765 "1427 Invalid PCI device group: 0x%x\n",
13766 phba->pci_dev_grp);
13773 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
13774 * @pdev: pointer to PCI device.
13776 * This routine is registered to the PCI subsystem for error handling. This
13777 * function is called after PCI bus has been reset to restart the PCI card
13778 * from scratch, as if from a cold-boot. When this routine is invoked, it
13779 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
13780 * routine, which will perform the proper device reset.
13783 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13784 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13786 static pci_ers_result_t
13787 lpfc_io_slot_reset(struct pci_dev *pdev)
13789 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13790 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13791 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13793 switch (phba->pci_dev_grp) {
13794 case LPFC_PCI_DEV_LP:
13795 rc = lpfc_io_slot_reset_s3(pdev);
13797 case LPFC_PCI_DEV_OC:
13798 rc = lpfc_io_slot_reset_s4(pdev);
13801 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13802 "1428 Invalid PCI device group: 0x%x\n",
13803 phba->pci_dev_grp);
13810 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
13811 * @pdev: pointer to PCI device
13813 * This routine is registered to the PCI subsystem for error handling. It
13814 * is called when kernel error recovery tells the lpfc driver that it is
13815 * OK to resume normal PCI operation after PCI bus error recovery. When
13816 * this routine is invoked, it dispatches the action to the proper SLI-3
13817 * or SLI-4 device io_resume routine, which will resume the device operation.
13820 lpfc_io_resume(struct pci_dev *pdev)
13822 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13823 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13825 switch (phba->pci_dev_grp) {
13826 case LPFC_PCI_DEV_LP:
13827 lpfc_io_resume_s3(pdev);
13829 case LPFC_PCI_DEV_OC:
13830 lpfc_io_resume_s4(pdev);
13833 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13834 "1429 Invalid PCI device group: 0x%x\n",
13835 phba->pci_dev_grp);
13842 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
13843 * @phba: pointer to lpfc hba data structure.
13845 * This routine checks to see if OAS is supported for this adapter. If
13846 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
13847 * the enable oas flag is cleared and the pool created for OAS device data
13852 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
13855 if (!phba->cfg_EnableXLane)
13858 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
13862 mempool_destroy(phba->device_data_mem_pool);
13863 phba->device_data_mem_pool = NULL;
13870 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
13871 * @phba: pointer to lpfc hba data structure.
13873 * This routine checks to see if RAS is supported by the adapter. Check the
13874 * function through which RAS support enablement is to be done.
13877 lpfc_sli4_ras_init(struct lpfc_hba *phba)
13879 switch (phba->pcidev->device) {
13880 case PCI_DEVICE_ID_LANCER_G6_FC:
13881 case PCI_DEVICE_ID_LANCER_G7_FC:
13882 phba->ras_fwlog.ras_hwsupport = true;
13883 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
13884 phba->cfg_ras_fwlog_buffsize)
13885 phba->ras_fwlog.ras_enabled = true;
13887 phba->ras_fwlog.ras_enabled = false;
13890 phba->ras_fwlog.ras_hwsupport = false;
13895 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
13897 static const struct pci_error_handlers lpfc_err_handler = {
13898 .error_detected = lpfc_io_error_detected,
13899 .slot_reset = lpfc_io_slot_reset,
13900 .resume = lpfc_io_resume,
13903 static struct pci_driver lpfc_driver = {
13904 .name = LPFC_DRIVER_NAME,
13905 .id_table = lpfc_id_table,
13906 .probe = lpfc_pci_probe_one,
13907 .remove = lpfc_pci_remove_one,
13908 .shutdown = lpfc_pci_remove_one,
13909 .suspend = lpfc_pci_suspend_one,
13910 .resume = lpfc_pci_resume_one,
13911 .err_handler = &lpfc_err_handler,
13914 static const struct file_operations lpfc_mgmt_fop = {
13915 .owner = THIS_MODULE,
13918 static struct miscdevice lpfc_mgmt_dev = {
13919 .minor = MISC_DYNAMIC_MINOR,
13920 .name = "lpfcmgmt",
13921 .fops = &lpfc_mgmt_fop,
13925 * lpfc_init - lpfc module initialization routine
13927 * This routine is to be invoked when the lpfc module is loaded into the
13928 * kernel. The special kernel macro module_init() is used to indicate the
13929 * role of this routine to the kernel as lpfc module entry point.
13933 * -ENOMEM - FC attach transport failed
13934 * all others - failed
13941 printk(LPFC_MODULE_DESC "\n");
13942 printk(LPFC_COPYRIGHT "\n");
13944 error = misc_register(&lpfc_mgmt_dev);
13946 printk(KERN_ERR "Could not register lpfcmgmt device, "
13947 "misc_register returned with status %d", error);
13949 lpfc_transport_functions.vport_create = lpfc_vport_create;
13950 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
13951 lpfc_transport_template =
13952 fc_attach_transport(&lpfc_transport_functions);
13953 if (lpfc_transport_template == NULL)
13955 lpfc_vport_transport_template =
13956 fc_attach_transport(&lpfc_vport_transport_functions);
13957 if (lpfc_vport_transport_template == NULL) {
13958 fc_release_transport(lpfc_transport_template);
13961 lpfc_nvme_cmd_template();
13962 lpfc_nvmet_cmd_template();
13964 /* Initialize in case vector mapping is needed */
13965 lpfc_present_cpu = num_present_cpus();
13967 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
13968 "lpfc/sli4:online",
13969 lpfc_cpu_online, lpfc_cpu_offline);
13971 goto cpuhp_failure;
13972 lpfc_cpuhp_state = error;
13974 error = pci_register_driver(&lpfc_driver);
13981 cpuhp_remove_multi_state(lpfc_cpuhp_state);
13983 fc_release_transport(lpfc_transport_template);
13984 fc_release_transport(lpfc_vport_transport_template);
13990 * lpfc_exit - lpfc module removal routine
13992 * This routine is invoked when the lpfc module is removed from the kernel.
13993 * The special kernel macro module_exit() is used to indicate the role of
13994 * this routine to the kernel as lpfc module exit point.
13999 misc_deregister(&lpfc_mgmt_dev);
14000 pci_unregister_driver(&lpfc_driver);
14001 cpuhp_remove_multi_state(lpfc_cpuhp_state);
14002 fc_release_transport(lpfc_transport_template);
14003 fc_release_transport(lpfc_vport_transport_template);
14004 idr_destroy(&lpfc_hba_index);
14007 module_init(lpfc_init);
14008 module_exit(lpfc_exit);
14009 MODULE_LICENSE("GPL");
14010 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
14011 MODULE_AUTHOR("Broadcom");
14012 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);