1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/kthread.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/ctype.h>
34 #include <linux/aer.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/msi.h>
40 #include <linux/irq.h>
41 #include <linux/bitops.h>
42 #include <linux/crash_dump.h>
43 #include <linux/cpu.h>
44 #include <linux/cpuhotplug.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_transport_fc.h>
50 #include <scsi/scsi_tcq.h>
51 #include <scsi/fc/fc_fs.h>
56 #include "lpfc_sli4.h"
58 #include "lpfc_disc.h"
60 #include "lpfc_scsi.h"
61 #include "lpfc_nvme.h"
62 #include "lpfc_logmsg.h"
63 #include "lpfc_crtn.h"
64 #include "lpfc_vport.h"
65 #include "lpfc_version.h"
68 static enum cpuhp_state lpfc_cpuhp_state;
69 /* Used when mapping IRQ vectors in a driver centric manner */
70 static uint32_t lpfc_present_cpu;
71 static bool lpfc_pldv_detect;
73 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
74 static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
75 static void lpfc_cpuhp_add(struct lpfc_hba *phba);
76 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
77 static int lpfc_post_rcv_buf(struct lpfc_hba *);
78 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
79 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
80 static int lpfc_setup_endian_order(struct lpfc_hba *);
81 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
82 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
83 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
84 static void lpfc_init_sgl_list(struct lpfc_hba *);
85 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
86 static void lpfc_free_active_sgl(struct lpfc_hba *);
87 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
88 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
89 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
90 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
91 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
92 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
93 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
94 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
95 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
96 static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
97 static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
98 static void lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba);
100 static struct scsi_transport_template *lpfc_transport_template = NULL;
101 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
102 static DEFINE_IDR(lpfc_hba_index);
103 #define LPFC_NVMET_BUF_POST 254
104 static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
107 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
108 * @phba: pointer to lpfc hba data structure.
110 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
111 * mailbox command. It retrieves the revision information from the HBA and
112 * collects the Vital Product Data (VPD) about the HBA for preparing the
113 * configuration of the HBA.
117 * -ERESTART - requests the SLI layer to reset the HBA and try again.
118 * Any other value - indicates an error.
121 lpfc_config_port_prep(struct lpfc_hba *phba)
123 lpfc_vpd_t *vp = &phba->vpd;
127 char *lpfc_vpd_data = NULL;
129 static char licensed[56] =
130 "key unlock for use with gnu public licensed code only\0";
131 static int init_key = 1;
133 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
135 phba->link_state = LPFC_HBA_ERROR;
140 phba->link_state = LPFC_INIT_MBX_CMDS;
142 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
144 uint32_t *ptext = (uint32_t *) licensed;
146 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
147 *ptext = cpu_to_be32(*ptext);
151 lpfc_read_nv(phba, pmb);
152 memset((char*)mb->un.varRDnvp.rsvd3, 0,
153 sizeof (mb->un.varRDnvp.rsvd3));
154 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
157 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
159 if (rc != MBX_SUCCESS) {
160 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
161 "0324 Config Port initialization "
162 "error, mbxCmd x%x READ_NVPARM, "
164 mb->mbxCommand, mb->mbxStatus);
165 mempool_free(pmb, phba->mbox_mem_pool);
168 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
170 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
175 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
176 * which was already set in lpfc_get_cfgparam()
178 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
180 /* Setup and issue mailbox READ REV command */
181 lpfc_read_rev(phba, pmb);
182 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
183 if (rc != MBX_SUCCESS) {
184 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
185 "0439 Adapter failed to init, mbxCmd x%x "
186 "READ_REV, mbxStatus x%x\n",
187 mb->mbxCommand, mb->mbxStatus);
188 mempool_free( pmb, phba->mbox_mem_pool);
194 * The value of rr must be 1 since the driver set the cv field to 1.
195 * This setting requires the FW to set all revision fields.
197 if (mb->un.varRdRev.rr == 0) {
199 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
200 "0440 Adapter failed to init, READ_REV has "
201 "missing revision information.\n");
202 mempool_free(pmb, phba->mbox_mem_pool);
206 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
207 mempool_free(pmb, phba->mbox_mem_pool);
211 /* Save information as VPD data */
213 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
214 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
215 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
216 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
217 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
218 vp->rev.biuRev = mb->un.varRdRev.biuRev;
219 vp->rev.smRev = mb->un.varRdRev.smRev;
220 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
221 vp->rev.endecRev = mb->un.varRdRev.endecRev;
222 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
223 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
224 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
225 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
226 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
227 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
229 /* If the sli feature level is less then 9, we must
230 * tear down all RPIs and VPIs on link down if NPIV
233 if (vp->rev.feaLevelHigh < 9)
234 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
236 if (lpfc_is_LC_HBA(phba->pcidev->device))
237 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
238 sizeof (phba->RandomData));
240 /* Get adapter VPD information */
241 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
245 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
246 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
248 if (rc != MBX_SUCCESS) {
249 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
250 "0441 VPD not present on adapter, "
251 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
252 mb->mbxCommand, mb->mbxStatus);
253 mb->un.varDmp.word_cnt = 0;
255 /* dump mem may return a zero when finished or we got a
256 * mailbox error, either way we are done.
258 if (mb->un.varDmp.word_cnt == 0)
261 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
262 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
263 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
264 lpfc_vpd_data + offset,
265 mb->un.varDmp.word_cnt);
266 offset += mb->un.varDmp.word_cnt;
267 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
269 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
271 kfree(lpfc_vpd_data);
273 mempool_free(pmb, phba->mbox_mem_pool);
278 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
279 * @phba: pointer to lpfc hba data structure.
280 * @pmboxq: pointer to the driver internal queue element for mailbox command.
282 * This is the completion handler for driver's configuring asynchronous event
283 * mailbox command to the device. If the mailbox command returns successfully,
284 * it will set internal async event support flag to 1; otherwise, it will
285 * set internal async event support flag to 0.
288 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
290 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
291 phba->temp_sensor_support = 1;
293 phba->temp_sensor_support = 0;
294 mempool_free(pmboxq, phba->mbox_mem_pool);
299 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
300 * @phba: pointer to lpfc hba data structure.
301 * @pmboxq: pointer to the driver internal queue element for mailbox command.
303 * This is the completion handler for dump mailbox command for getting
304 * wake up parameters. When this command complete, the response contain
305 * Option rom version of the HBA. This function translate the version number
306 * into a human readable string and store it in OptionROMVersion.
309 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
312 uint32_t prog_id_word;
314 /* character array used for decoding dist type. */
315 char dist_char[] = "nabx";
317 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
318 mempool_free(pmboxq, phba->mbox_mem_pool);
322 prg = (struct prog_id *) &prog_id_word;
324 /* word 7 contain option rom version */
325 prog_id_word = pmboxq->u.mb.un.varWords[7];
327 /* Decode the Option rom version word to a readable string */
329 dist = dist_char[prg->dist];
331 if ((prg->dist == 3) && (prg->num == 0))
332 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
333 prg->ver, prg->rev, prg->lev);
335 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
336 prg->ver, prg->rev, prg->lev,
338 mempool_free(pmboxq, phba->mbox_mem_pool);
343 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
344 * @vport: pointer to lpfc vport data structure.
351 lpfc_update_vport_wwn(struct lpfc_vport *vport)
353 struct lpfc_hba *phba = vport->phba;
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
359 if (vport->fc_nodename.u.wwn[0] == 0)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
367 * If the port name has changed, then set the Param changes flag
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name))) {
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
375 if (phba->sli_rev == LPFC_SLI_REV4 &&
376 vport->port_type == LPFC_PHYSICAL_PORT &&
377 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_FABRIC) {
378 lpfc_printf_log(phba, KERN_INFO,
379 LOG_SLI | LOG_DISCOVERY | LOG_ELS,
380 "2701 FA-PWWN change WWPN from %llx to "
381 "%llx: vflag x%x fawwpn_flag x%x\n",
382 wwn_to_u64(vport->fc_portname.u.wwn),
384 (vport->fc_sparam.portName.u.wwn),
386 phba->sli4_hba.fawwpn_flag);
387 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
388 sizeof(struct lpfc_name));
392 if (vport->fc_portname.u.wwn[0] == 0)
393 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
394 sizeof(struct lpfc_name));
396 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
397 sizeof(struct lpfc_name));
401 * lpfc_config_port_post - Perform lpfc initialization after config port
402 * @phba: pointer to lpfc hba data structure.
404 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
405 * command call. It performs all internal resource and state setups on the
406 * port: post IOCB buffers, enable appropriate host interrupt attentions,
407 * ELS ring timers, etc.
411 * Any other value - error.
414 lpfc_config_port_post(struct lpfc_hba *phba)
416 struct lpfc_vport *vport = phba->pport;
417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
420 struct lpfc_dmabuf *mp;
421 struct lpfc_sli *psli = &phba->sli;
422 uint32_t status, timeout;
426 spin_lock_irq(&phba->hbalock);
428 * If the Config port completed correctly the HBA is not
429 * over heated any more.
431 if (phba->over_temp_state == HBA_OVER_TEMP)
432 phba->over_temp_state = HBA_NORMAL_TEMP;
433 spin_unlock_irq(&phba->hbalock);
435 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
437 phba->link_state = LPFC_HBA_ERROR;
442 /* Get login parameters for NID. */
443 rc = lpfc_read_sparam(phba, pmb, 0);
445 mempool_free(pmb, phba->mbox_mem_pool);
450 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
451 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
452 "0448 Adapter failed init, mbxCmd x%x "
453 "READ_SPARM mbxStatus x%x\n",
454 mb->mbxCommand, mb->mbxStatus);
455 phba->link_state = LPFC_HBA_ERROR;
456 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
460 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
462 /* This dmabuf was allocated by lpfc_read_sparam. The dmabuf is no
463 * longer needed. Prevent unintended ctx_buf access as the mbox is
466 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
467 lpfc_mbuf_free(phba, mp->virt, mp->phys);
470 lpfc_update_vport_wwn(vport);
472 /* Update the fc_host data structures with new wwn. */
473 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
474 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
475 fc_host_max_npiv_vports(shost) = phba->max_vpi;
477 /* If no serial number in VPD data, use low 6 bytes of WWNN */
478 /* This should be consolidated into parse_vpd ? - mr */
479 if (phba->SerialNumber[0] == 0) {
482 outptr = &vport->fc_nodename.u.s.IEEE[0];
483 for (i = 0; i < 12; i++) {
485 j = ((status & 0xf0) >> 4);
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x30 + (uint8_t) j);
490 phba->SerialNumber[i] =
491 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
495 phba->SerialNumber[i] =
496 (char)((uint8_t) 0x30 + (uint8_t) j);
498 phba->SerialNumber[i] =
499 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
503 lpfc_read_config(phba, pmb);
505 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
506 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
507 "0453 Adapter failed to init, mbxCmd x%x "
508 "READ_CONFIG, mbxStatus x%x\n",
509 mb->mbxCommand, mb->mbxStatus);
510 phba->link_state = LPFC_HBA_ERROR;
511 mempool_free( pmb, phba->mbox_mem_pool);
515 /* Check if the port is disabled */
516 lpfc_sli_read_link_ste(phba);
518 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
519 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
520 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
521 "3359 HBA queue depth changed from %d to %d\n",
522 phba->cfg_hba_queue_depth,
523 mb->un.varRdConfig.max_xri);
524 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
527 phba->lmt = mb->un.varRdConfig.lmt;
529 /* Get the default values for Model Name and Description */
530 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
532 phba->link_state = LPFC_LINK_DOWN;
534 /* Only process IOCBs on ELS ring till hba_state is READY */
535 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
537 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
538 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
540 /* Post receive buffers for desired rings */
541 if (phba->sli_rev != 3)
542 lpfc_post_rcv_buf(phba);
545 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
547 if (phba->intr_type == MSIX) {
548 rc = lpfc_config_msi(phba, pmb);
550 mempool_free(pmb, phba->mbox_mem_pool);
553 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
554 if (rc != MBX_SUCCESS) {
555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
556 "0352 Config MSI mailbox command "
557 "failed, mbxCmd x%x, mbxStatus x%x\n",
558 pmb->u.mb.mbxCommand,
559 pmb->u.mb.mbxStatus);
560 mempool_free(pmb, phba->mbox_mem_pool);
565 spin_lock_irq(&phba->hbalock);
566 /* Initialize ERATT handling flag */
567 phba->hba_flag &= ~HBA_ERATT_HANDLED;
569 /* Enable appropriate host interrupts */
570 if (lpfc_readl(phba->HCregaddr, &status)) {
571 spin_unlock_irq(&phba->hbalock);
574 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
575 if (psli->num_rings > 0)
576 status |= HC_R0INT_ENA;
577 if (psli->num_rings > 1)
578 status |= HC_R1INT_ENA;
579 if (psli->num_rings > 2)
580 status |= HC_R2INT_ENA;
581 if (psli->num_rings > 3)
582 status |= HC_R3INT_ENA;
584 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
585 (phba->cfg_poll & DISABLE_FCP_RING_INT))
586 status &= ~(HC_R0INT_ENA);
588 writel(status, phba->HCregaddr);
589 readl(phba->HCregaddr); /* flush */
590 spin_unlock_irq(&phba->hbalock);
592 /* Set up ring-0 (ELS) timer */
593 timeout = phba->fc_ratov * 2;
594 mod_timer(&vport->els_tmofunc,
595 jiffies + msecs_to_jiffies(1000 * timeout));
596 /* Set up heart beat (HB) timer */
597 mod_timer(&phba->hb_tmofunc,
598 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
599 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
600 phba->last_completion_time = jiffies;
601 /* Set up error attention (ERATT) polling timer */
602 mod_timer(&phba->eratt_poll,
603 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
605 if (phba->hba_flag & LINK_DISABLED) {
606 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
607 "2598 Adapter Link is disabled.\n");
608 lpfc_down_link(phba, pmb);
609 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
610 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
611 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
612 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
616 mempool_free(pmb, phba->mbox_mem_pool);
619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
625 /* MBOX buffer will be freed in mbox compl */
626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
628 phba->link_state = LPFC_HBA_ERROR;
632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
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_TRACE_EVENT,
659 "0435 Adapter failed "
660 "to get Option ROM version status x%x\n", rc);
661 mempool_free(pmb, phba->mbox_mem_pool);
668 * lpfc_sli4_refresh_params - update driver copy of params.
669 * @phba: Pointer to HBA context object.
671 * This is called to refresh driver copy of dynamic fields from the
672 * common_get_sli4_parameters descriptor.
675 lpfc_sli4_refresh_params(struct lpfc_hba *phba)
678 struct lpfc_mqe *mqe;
679 struct lpfc_sli4_parameters *mbx_sli4_parameters;
682 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
687 /* Read the port's SLI4 Config Parameters */
688 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
689 sizeof(struct lpfc_sli4_cfg_mhdr));
690 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
691 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
692 length, LPFC_SLI4_MBX_EMBED);
694 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
696 mempool_free(mboxq, phba->mbox_mem_pool);
699 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
701 /* Are we forcing MI off via module parameter? */
702 if (phba->cfg_enable_mi)
703 phba->sli4_hba.pc_sli4_params.mi_ver =
704 bf_get(cfg_mi_ver, mbx_sli4_parameters);
706 phba->sli4_hba.pc_sli4_params.mi_ver = 0;
708 phba->sli4_hba.pc_sli4_params.cmf =
709 bf_get(cfg_cmf, mbx_sli4_parameters);
710 phba->sli4_hba.pc_sli4_params.pls =
711 bf_get(cfg_pvl, mbx_sli4_parameters);
713 mempool_free(mboxq, phba->mbox_mem_pool);
718 * lpfc_hba_init_link - Initialize the FC link
719 * @phba: pointer to lpfc hba data structure.
720 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
722 * This routine will issue the INIT_LINK mailbox command call.
723 * It is available to other drivers through the lpfc_hba data
724 * structure for use as a delayed link up mechanism with the
725 * module parameter lpfc_suppress_link_up.
729 * Any other value - error
732 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
734 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
738 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
739 * @phba: pointer to lpfc hba data structure.
740 * @fc_topology: desired fc topology.
741 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
743 * This routine will issue the INIT_LINK mailbox command call.
744 * It is available to other drivers through the lpfc_hba data
745 * structure for use as a delayed link up mechanism with the
746 * module parameter lpfc_suppress_link_up.
750 * Any other value - error
753 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
756 struct lpfc_vport *vport = phba->pport;
761 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
763 phba->link_state = LPFC_HBA_ERROR;
769 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
770 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
771 !(phba->lmt & LMT_1Gb)) ||
772 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
773 !(phba->lmt & LMT_2Gb)) ||
774 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
775 !(phba->lmt & LMT_4Gb)) ||
776 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
777 !(phba->lmt & LMT_8Gb)) ||
778 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
779 !(phba->lmt & LMT_10Gb)) ||
780 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
781 !(phba->lmt & LMT_16Gb)) ||
782 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
783 !(phba->lmt & LMT_32Gb)) ||
784 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
785 !(phba->lmt & LMT_64Gb))) {
786 /* Reset link speed to auto */
787 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
788 "1302 Invalid speed for this board:%d "
789 "Reset link speed to auto.\n",
790 phba->cfg_link_speed);
791 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
793 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
794 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
795 if (phba->sli_rev < LPFC_SLI_REV4)
796 lpfc_set_loopback_flag(phba);
797 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
798 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
799 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
800 "0498 Adapter failed to init, mbxCmd x%x "
801 "INIT_LINK, mbxStatus x%x\n",
802 mb->mbxCommand, mb->mbxStatus);
803 if (phba->sli_rev <= LPFC_SLI_REV3) {
804 /* Clear all interrupt enable conditions */
805 writel(0, phba->HCregaddr);
806 readl(phba->HCregaddr); /* flush */
807 /* Clear all pending interrupts */
808 writel(0xffffffff, phba->HAregaddr);
809 readl(phba->HAregaddr); /* flush */
811 phba->link_state = LPFC_HBA_ERROR;
812 if (rc != MBX_BUSY || flag == MBX_POLL)
813 mempool_free(pmb, phba->mbox_mem_pool);
816 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
817 if (flag == MBX_POLL)
818 mempool_free(pmb, phba->mbox_mem_pool);
824 * lpfc_hba_down_link - this routine downs the FC link
825 * @phba: pointer to lpfc hba data structure.
826 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
828 * This routine will issue the DOWN_LINK mailbox command call.
829 * It is available to other drivers through the lpfc_hba data
830 * structure for use to stop the link.
834 * Any other value - error
837 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
842 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
844 phba->link_state = LPFC_HBA_ERROR;
848 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
849 "0491 Adapter Link is disabled.\n");
850 lpfc_down_link(phba, pmb);
851 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
852 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
853 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
854 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
855 "2522 Adapter failed to issue DOWN_LINK"
856 " mbox command rc 0x%x\n", rc);
858 mempool_free(pmb, phba->mbox_mem_pool);
861 if (flag == MBX_POLL)
862 mempool_free(pmb, phba->mbox_mem_pool);
868 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
869 * @phba: pointer to lpfc HBA data structure.
871 * This routine will do LPFC uninitialization before the HBA is reset when
872 * bringing down the SLI Layer.
876 * Any other value - error.
879 lpfc_hba_down_prep(struct lpfc_hba *phba)
881 struct lpfc_vport **vports;
884 if (phba->sli_rev <= LPFC_SLI_REV3) {
885 /* Disable interrupts */
886 writel(0, phba->HCregaddr);
887 readl(phba->HCregaddr); /* flush */
890 if (phba->pport->load_flag & FC_UNLOADING)
891 lpfc_cleanup_discovery_resources(phba->pport);
893 vports = lpfc_create_vport_work_array(phba);
895 for (i = 0; i <= phba->max_vports &&
896 vports[i] != NULL; i++)
897 lpfc_cleanup_discovery_resources(vports[i]);
898 lpfc_destroy_vport_work_array(phba, vports);
904 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
905 * rspiocb which got deferred
907 * @phba: pointer to lpfc HBA data structure.
909 * This routine will cleanup completed slow path events after HBA is reset
910 * when bringing down the SLI Layer.
917 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
919 struct lpfc_iocbq *rspiocbq;
920 struct hbq_dmabuf *dmabuf;
921 struct lpfc_cq_event *cq_event;
923 spin_lock_irq(&phba->hbalock);
924 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
925 spin_unlock_irq(&phba->hbalock);
927 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
928 /* Get the response iocb from the head of work queue */
929 spin_lock_irq(&phba->hbalock);
930 list_remove_head(&phba->sli4_hba.sp_queue_event,
931 cq_event, struct lpfc_cq_event, list);
932 spin_unlock_irq(&phba->hbalock);
934 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
935 case CQE_CODE_COMPL_WQE:
936 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
938 lpfc_sli_release_iocbq(phba, rspiocbq);
940 case CQE_CODE_RECEIVE:
941 case CQE_CODE_RECEIVE_V1:
942 dmabuf = container_of(cq_event, struct hbq_dmabuf,
944 lpfc_in_buf_free(phba, &dmabuf->dbuf);
950 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
951 * @phba: pointer to lpfc HBA data structure.
953 * This routine will cleanup posted ELS buffers after the HBA is reset
954 * when bringing down the SLI Layer.
961 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
963 struct lpfc_sli *psli = &phba->sli;
964 struct lpfc_sli_ring *pring;
965 struct lpfc_dmabuf *mp, *next_mp;
969 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
970 lpfc_sli_hbqbuf_free_all(phba);
972 /* Cleanup preposted buffers on the ELS ring */
973 pring = &psli->sli3_ring[LPFC_ELS_RING];
974 spin_lock_irq(&phba->hbalock);
975 list_splice_init(&pring->postbufq, &buflist);
976 spin_unlock_irq(&phba->hbalock);
979 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
982 lpfc_mbuf_free(phba, mp->virt, mp->phys);
986 spin_lock_irq(&phba->hbalock);
987 pring->postbufq_cnt -= count;
988 spin_unlock_irq(&phba->hbalock);
993 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
994 * @phba: pointer to lpfc HBA data structure.
996 * This routine will cleanup the txcmplq after the HBA is reset when bringing
997 * down the SLI Layer.
1003 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
1005 struct lpfc_sli *psli = &phba->sli;
1006 struct lpfc_queue *qp = NULL;
1007 struct lpfc_sli_ring *pring;
1008 LIST_HEAD(completions);
1010 struct lpfc_iocbq *piocb, *next_iocb;
1012 if (phba->sli_rev != LPFC_SLI_REV4) {
1013 for (i = 0; i < psli->num_rings; i++) {
1014 pring = &psli->sli3_ring[i];
1015 spin_lock_irq(&phba->hbalock);
1016 /* At this point in time the HBA is either reset or DOA
1017 * Nothing should be on txcmplq as it will
1020 list_splice_init(&pring->txcmplq, &completions);
1021 pring->txcmplq_cnt = 0;
1022 spin_unlock_irq(&phba->hbalock);
1024 lpfc_sli_abort_iocb_ring(phba, pring);
1026 /* Cancel all the IOCBs from the completions list */
1027 lpfc_sli_cancel_iocbs(phba, &completions,
1028 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1031 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1035 spin_lock_irq(&pring->ring_lock);
1036 list_for_each_entry_safe(piocb, next_iocb,
1037 &pring->txcmplq, list)
1038 piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
1039 list_splice_init(&pring->txcmplq, &completions);
1040 pring->txcmplq_cnt = 0;
1041 spin_unlock_irq(&pring->ring_lock);
1042 lpfc_sli_abort_iocb_ring(phba, pring);
1044 /* Cancel all the IOCBs from the completions list */
1045 lpfc_sli_cancel_iocbs(phba, &completions,
1046 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1050 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1051 * @phba: pointer to lpfc HBA data structure.
1053 * This routine will do uninitialization after the HBA is reset when bring
1054 * down the SLI Layer.
1058 * Any other value - error.
1061 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1063 lpfc_hba_free_post_buf(phba);
1064 lpfc_hba_clean_txcmplq(phba);
1069 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1070 * @phba: pointer to lpfc HBA data structure.
1072 * This routine will do uninitialization after the HBA is reset when bring
1073 * down the SLI Layer.
1077 * Any other value - error.
1080 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1082 struct lpfc_io_buf *psb, *psb_next;
1083 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
1084 struct lpfc_sli4_hdw_queue *qp;
1086 LIST_HEAD(nvme_aborts);
1087 LIST_HEAD(nvmet_aborts);
1088 struct lpfc_sglq *sglq_entry = NULL;
1092 lpfc_sli_hbqbuf_free_all(phba);
1093 lpfc_hba_clean_txcmplq(phba);
1095 /* At this point in time the HBA is either reset or DOA. Either
1096 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1097 * on the lpfc_els_sgl_list so that it can either be freed if the
1098 * driver is unloading or reposted if the driver is restarting
1102 /* sgl_list_lock required because worker thread uses this
1105 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
1106 list_for_each_entry(sglq_entry,
1107 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1108 sglq_entry->state = SGL_FREED;
1110 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1111 &phba->sli4_hba.lpfc_els_sgl_list);
1114 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
1116 /* abts_xxxx_buf_list_lock required because worker thread uses this
1119 spin_lock_irq(&phba->hbalock);
1121 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1122 qp = &phba->sli4_hba.hdwq[idx];
1124 spin_lock(&qp->abts_io_buf_list_lock);
1125 list_splice_init(&qp->lpfc_abts_io_buf_list,
1128 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1130 psb->status = IOSTAT_SUCCESS;
1133 spin_lock(&qp->io_buf_list_put_lock);
1134 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1135 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1136 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1137 qp->abts_scsi_io_bufs = 0;
1138 qp->abts_nvme_io_bufs = 0;
1139 spin_unlock(&qp->io_buf_list_put_lock);
1140 spin_unlock(&qp->abts_io_buf_list_lock);
1142 spin_unlock_irq(&phba->hbalock);
1144 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1145 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1146 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1148 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1149 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1150 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
1151 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1155 lpfc_sli4_free_sp_events(phba);
1160 * lpfc_hba_down_post - Wrapper func for hba down post routine
1161 * @phba: pointer to lpfc HBA data structure.
1163 * This routine wraps the actual SLI3 or SLI4 routine for performing
1164 * uninitialization after the HBA is reset when bring down the SLI Layer.
1168 * Any other value - error.
1171 lpfc_hba_down_post(struct lpfc_hba *phba)
1173 return (*phba->lpfc_hba_down_post)(phba);
1177 * lpfc_hb_timeout - The HBA-timer timeout handler
1178 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1180 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1181 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1182 * work-port-events bitmap and the worker thread is notified. This timeout
1183 * event will be used by the worker thread to invoke the actual timeout
1184 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1185 * be performed in the timeout handler and the HBA timeout event bit shall
1186 * be cleared by the worker thread after it has taken the event bitmap out.
1189 lpfc_hb_timeout(struct timer_list *t)
1191 struct lpfc_hba *phba;
1192 uint32_t tmo_posted;
1193 unsigned long iflag;
1195 phba = from_timer(phba, t, hb_tmofunc);
1197 /* Check for heart beat timeout conditions */
1198 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1199 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1201 phba->pport->work_port_events |= WORKER_HB_TMO;
1202 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1204 /* Tell the worker thread there is work to do */
1206 lpfc_worker_wake_up(phba);
1211 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1212 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1214 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1215 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1216 * work-port-events bitmap and the worker thread is notified. This timeout
1217 * event will be used by the worker thread to invoke the actual timeout
1218 * handler routine, lpfc_rrq_handler. Any periodical operations will
1219 * be performed in the timeout handler and the RRQ timeout event bit shall
1220 * be cleared by the worker thread after it has taken the event bitmap out.
1223 lpfc_rrq_timeout(struct timer_list *t)
1225 struct lpfc_hba *phba;
1226 unsigned long iflag;
1228 phba = from_timer(phba, t, rrq_tmr);
1229 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1230 if (!(phba->pport->load_flag & FC_UNLOADING))
1231 phba->hba_flag |= HBA_RRQ_ACTIVE;
1233 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1234 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1236 if (!(phba->pport->load_flag & FC_UNLOADING))
1237 lpfc_worker_wake_up(phba);
1241 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1242 * @phba: pointer to lpfc hba data structure.
1243 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1245 * This is the callback function to the lpfc heart-beat mailbox command.
1246 * If configured, the lpfc driver issues the heart-beat mailbox command to
1247 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1248 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1249 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1250 * heart-beat outstanding state. Once the mailbox command comes back and
1251 * no error conditions detected, the heart-beat mailbox command timer is
1252 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1253 * state is cleared for the next heart-beat. If the timer expired with the
1254 * heart-beat outstanding state set, the driver will put the HBA offline.
1257 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1259 unsigned long drvr_flag;
1261 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1262 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
1263 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1265 /* Check and reset heart-beat timer if necessary */
1266 mempool_free(pmboxq, phba->mbox_mem_pool);
1267 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1268 !(phba->link_state == LPFC_HBA_ERROR) &&
1269 !(phba->pport->load_flag & FC_UNLOADING))
1270 mod_timer(&phba->hb_tmofunc,
1272 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1277 * lpfc_idle_stat_delay_work - idle_stat tracking
1279 * This routine tracks per-cq idle_stat and determines polling decisions.
1285 lpfc_idle_stat_delay_work(struct work_struct *work)
1287 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1289 idle_stat_delay_work);
1290 struct lpfc_queue *cq;
1291 struct lpfc_sli4_hdw_queue *hdwq;
1292 struct lpfc_idle_stat *idle_stat;
1293 u32 i, idle_percent;
1294 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1296 if (phba->pport->load_flag & FC_UNLOADING)
1299 if (phba->link_state == LPFC_HBA_ERROR ||
1300 phba->pport->fc_flag & FC_OFFLINE_MODE ||
1301 phba->cmf_active_mode != LPFC_CFG_OFF)
1304 for_each_present_cpu(i) {
1305 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1308 /* Skip if we've already handled this cq's primary CPU */
1312 idle_stat = &phba->sli4_hba.idle_stat[i];
1314 /* get_cpu_idle_time returns values as running counters. Thus,
1315 * to know the amount for this period, the prior counter values
1316 * need to be subtracted from the current counter values.
1317 * From there, the idle time stat can be calculated as a
1318 * percentage of 100 - the sum of the other consumption times.
1320 wall_idle = get_cpu_idle_time(i, &wall, 1);
1321 diff_idle = wall_idle - idle_stat->prev_idle;
1322 diff_wall = wall - idle_stat->prev_wall;
1324 if (diff_wall <= diff_idle)
1327 busy_time = diff_wall - diff_idle;
1329 idle_percent = div64_u64(100 * busy_time, diff_wall);
1330 idle_percent = 100 - idle_percent;
1332 if (idle_percent < 15)
1333 cq->poll_mode = LPFC_QUEUE_WORK;
1335 cq->poll_mode = LPFC_IRQ_POLL;
1337 idle_stat->prev_idle = wall_idle;
1338 idle_stat->prev_wall = wall;
1342 schedule_delayed_work(&phba->idle_stat_delay_work,
1343 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1347 lpfc_hb_eq_delay_work(struct work_struct *work)
1349 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1350 struct lpfc_hba, eq_delay_work);
1351 struct lpfc_eq_intr_info *eqi, *eqi_new;
1352 struct lpfc_queue *eq, *eq_next;
1353 unsigned char *ena_delay = NULL;
1357 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1360 if (phba->link_state == LPFC_HBA_ERROR ||
1361 phba->pport->fc_flag & FC_OFFLINE_MODE)
1364 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1369 for (i = 0; i < phba->cfg_irq_chann; i++) {
1370 /* Get the EQ corresponding to the IRQ vector */
1371 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1374 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1375 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1376 ena_delay[eq->last_cpu] = 1;
1380 for_each_present_cpu(i) {
1381 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1383 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1384 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1385 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1392 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1393 if (unlikely(eq->last_cpu != i)) {
1394 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1396 list_move_tail(&eq->cpu_list, &eqi_new->list);
1399 if (usdelay != eq->q_mode)
1400 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1408 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1409 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1413 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1414 * @phba: pointer to lpfc hba data structure.
1416 * For each heartbeat, this routine does some heuristic methods to adjust
1417 * XRI distribution. The goal is to fully utilize free XRIs.
1419 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1424 hwq_count = phba->cfg_hdw_queue;
1425 for (i = 0; i < hwq_count; i++) {
1426 /* Adjust XRIs in private pool */
1427 lpfc_adjust_pvt_pool_count(phba, i);
1429 /* Adjust high watermark */
1430 lpfc_adjust_high_watermark(phba, i);
1432 #ifdef LPFC_MXP_STAT
1433 /* Snapshot pbl, pvt and busy count */
1434 lpfc_snapshot_mxp(phba, i);
1440 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1441 * @phba: pointer to lpfc hba data structure.
1443 * If a HB mbox is not already in progrees, this routine will allocate
1444 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1445 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1448 lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1450 LPFC_MBOXQ_t *pmboxq;
1453 /* Is a Heartbeat mbox already in progress */
1454 if (phba->hba_flag & HBA_HBEAT_INP)
1457 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1461 lpfc_heart_beat(phba, pmboxq);
1462 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1463 pmboxq->vport = phba->pport;
1464 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1466 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1467 mempool_free(pmboxq, phba->mbox_mem_pool);
1470 phba->hba_flag |= HBA_HBEAT_INP;
1476 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1477 * @phba: pointer to lpfc hba data structure.
1479 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1480 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1481 * of the value of lpfc_enable_hba_heartbeat.
1482 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1483 * try to issue a MBX_HEARTBEAT mbox command.
1486 lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1488 if (phba->cfg_enable_hba_heartbeat)
1490 phba->hba_flag |= HBA_HBEAT_TMO;
1494 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1495 * @phba: pointer to lpfc hba data structure.
1497 * This is the actual HBA-timer timeout handler to be invoked by the worker
1498 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1499 * handler performs any periodic operations needed for the device. If such
1500 * periodic event has already been attended to either in the interrupt handler
1501 * or by processing slow-ring or fast-ring events within the HBA-timer
1502 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1503 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1504 * is configured and there is no heart-beat mailbox command outstanding, a
1505 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1506 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1510 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1512 struct lpfc_vport **vports;
1513 struct lpfc_dmabuf *buf_ptr;
1516 struct lpfc_sli *psli = &phba->sli;
1517 LIST_HEAD(completions);
1519 if (phba->cfg_xri_rebalancing) {
1520 /* Multi-XRI pools handler */
1521 lpfc_hb_mxp_handler(phba);
1524 vports = lpfc_create_vport_work_array(phba);
1526 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1527 lpfc_rcv_seq_check_edtov(vports[i]);
1528 lpfc_fdmi_change_check(vports[i]);
1530 lpfc_destroy_vport_work_array(phba, vports);
1532 if ((phba->link_state == LPFC_HBA_ERROR) ||
1533 (phba->pport->load_flag & FC_UNLOADING) ||
1534 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1537 if (phba->elsbuf_cnt &&
1538 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1539 spin_lock_irq(&phba->hbalock);
1540 list_splice_init(&phba->elsbuf, &completions);
1541 phba->elsbuf_cnt = 0;
1542 phba->elsbuf_prev_cnt = 0;
1543 spin_unlock_irq(&phba->hbalock);
1545 while (!list_empty(&completions)) {
1546 list_remove_head(&completions, buf_ptr,
1547 struct lpfc_dmabuf, list);
1548 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1552 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1554 /* If there is no heart beat outstanding, issue a heartbeat command */
1555 if (phba->cfg_enable_hba_heartbeat) {
1556 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1557 spin_lock_irq(&phba->pport->work_port_lock);
1558 if (time_after(phba->last_completion_time +
1559 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1561 spin_unlock_irq(&phba->pport->work_port_lock);
1562 if (phba->hba_flag & HBA_HBEAT_INP)
1563 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1565 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1568 spin_unlock_irq(&phba->pport->work_port_lock);
1570 /* Check if a MBX_HEARTBEAT is already in progress */
1571 if (phba->hba_flag & HBA_HBEAT_INP) {
1573 * If heart beat timeout called with HBA_HBEAT_INP set
1574 * we need to give the hb mailbox cmd a chance to
1577 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1578 "0459 Adapter heartbeat still outstanding: "
1579 "last compl time was %d ms.\n",
1580 jiffies_to_msecs(jiffies
1581 - phba->last_completion_time));
1582 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1584 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1585 (list_empty(&psli->mboxq))) {
1587 retval = lpfc_issue_hb_mbox(phba);
1589 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1592 phba->skipped_hb = 0;
1593 } else if (time_before_eq(phba->last_completion_time,
1594 phba->skipped_hb)) {
1595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1596 "2857 Last completion time not "
1597 " updated in %d ms\n",
1598 jiffies_to_msecs(jiffies
1599 - phba->last_completion_time));
1601 phba->skipped_hb = jiffies;
1603 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1607 /* Check to see if we want to force a MBX_HEARTBEAT */
1608 if (phba->hba_flag & HBA_HBEAT_TMO) {
1609 retval = lpfc_issue_hb_mbox(phba);
1611 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1613 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1616 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1619 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
1623 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1624 * @phba: pointer to lpfc hba data structure.
1626 * This routine is called to bring the HBA offline when HBA hardware error
1627 * other than Port Error 6 has been detected.
1630 lpfc_offline_eratt(struct lpfc_hba *phba)
1632 struct lpfc_sli *psli = &phba->sli;
1634 spin_lock_irq(&phba->hbalock);
1635 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1636 spin_unlock_irq(&phba->hbalock);
1637 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1640 lpfc_reset_barrier(phba);
1641 spin_lock_irq(&phba->hbalock);
1642 lpfc_sli_brdreset(phba);
1643 spin_unlock_irq(&phba->hbalock);
1644 lpfc_hba_down_post(phba);
1645 lpfc_sli_brdready(phba, HS_MBRDY);
1646 lpfc_unblock_mgmt_io(phba);
1647 phba->link_state = LPFC_HBA_ERROR;
1652 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1653 * @phba: pointer to lpfc hba data structure.
1655 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1656 * other than Port Error 6 has been detected.
1659 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1661 spin_lock_irq(&phba->hbalock);
1662 if (phba->link_state == LPFC_HBA_ERROR &&
1663 test_bit(HBA_PCI_ERR, &phba->bit_flags)) {
1664 spin_unlock_irq(&phba->hbalock);
1667 phba->link_state = LPFC_HBA_ERROR;
1668 spin_unlock_irq(&phba->hbalock);
1670 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1671 lpfc_sli_flush_io_rings(phba);
1673 lpfc_hba_down_post(phba);
1674 lpfc_unblock_mgmt_io(phba);
1678 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1679 * @phba: pointer to lpfc hba data structure.
1681 * This routine is invoked to handle the deferred HBA hardware error
1682 * conditions. This type of error is indicated by HBA by setting ER1
1683 * and another ER bit in the host status register. The driver will
1684 * wait until the ER1 bit clears before handling the error condition.
1687 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1689 uint32_t old_host_status = phba->work_hs;
1690 struct lpfc_sli *psli = &phba->sli;
1692 /* If the pci channel is offline, ignore possible errors,
1693 * since we cannot communicate with the pci card anyway.
1695 if (pci_channel_offline(phba->pcidev)) {
1696 spin_lock_irq(&phba->hbalock);
1697 phba->hba_flag &= ~DEFER_ERATT;
1698 spin_unlock_irq(&phba->hbalock);
1702 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1703 "0479 Deferred Adapter Hardware Error "
1704 "Data: x%x x%x x%x\n",
1705 phba->work_hs, phba->work_status[0],
1706 phba->work_status[1]);
1708 spin_lock_irq(&phba->hbalock);
1709 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1710 spin_unlock_irq(&phba->hbalock);
1714 * Firmware stops when it triggred erratt. That could cause the I/Os
1715 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1716 * SCSI layer retry it after re-establishing link.
1718 lpfc_sli_abort_fcp_rings(phba);
1721 * There was a firmware error. Take the hba offline and then
1722 * attempt to restart it.
1724 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1727 /* Wait for the ER1 bit to clear.*/
1728 while (phba->work_hs & HS_FFER1) {
1730 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1731 phba->work_hs = UNPLUG_ERR ;
1734 /* If driver is unloading let the worker thread continue */
1735 if (phba->pport->load_flag & FC_UNLOADING) {
1742 * This is to ptrotect against a race condition in which
1743 * first write to the host attention register clear the
1744 * host status register.
1746 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1747 phba->work_hs = old_host_status & ~HS_FFER1;
1749 spin_lock_irq(&phba->hbalock);
1750 phba->hba_flag &= ~DEFER_ERATT;
1751 spin_unlock_irq(&phba->hbalock);
1752 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1753 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1757 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1759 struct lpfc_board_event_header board_event;
1760 struct Scsi_Host *shost;
1762 board_event.event_type = FC_REG_BOARD_EVENT;
1763 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1764 shost = lpfc_shost_from_vport(phba->pport);
1765 fc_host_post_vendor_event(shost, fc_get_event_number(),
1766 sizeof(board_event),
1767 (char *) &board_event,
1772 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1773 * @phba: pointer to lpfc hba data structure.
1775 * This routine is invoked to handle the following HBA hardware error
1777 * 1 - HBA error attention interrupt
1778 * 2 - DMA ring index out of range
1779 * 3 - Mailbox command came back as unknown
1782 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1784 struct lpfc_vport *vport = phba->pport;
1785 struct lpfc_sli *psli = &phba->sli;
1786 uint32_t event_data;
1787 unsigned long temperature;
1788 struct temp_event temp_event_data;
1789 struct Scsi_Host *shost;
1791 /* If the pci channel is offline, ignore possible errors,
1792 * since we cannot communicate with the pci card anyway.
1794 if (pci_channel_offline(phba->pcidev)) {
1795 spin_lock_irq(&phba->hbalock);
1796 phba->hba_flag &= ~DEFER_ERATT;
1797 spin_unlock_irq(&phba->hbalock);
1801 /* If resets are disabled then leave the HBA alone and return */
1802 if (!phba->cfg_enable_hba_reset)
1805 /* Send an internal error event to mgmt application */
1806 lpfc_board_errevt_to_mgmt(phba);
1808 if (phba->hba_flag & DEFER_ERATT)
1809 lpfc_handle_deferred_eratt(phba);
1811 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1812 if (phba->work_hs & HS_FFER6)
1813 /* Re-establishing Link */
1814 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1815 "1301 Re-establishing Link "
1816 "Data: x%x x%x x%x\n",
1817 phba->work_hs, phba->work_status[0],
1818 phba->work_status[1]);
1819 if (phba->work_hs & HS_FFER8)
1820 /* Device Zeroization */
1821 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1822 "2861 Host Authentication device "
1823 "zeroization Data:x%x x%x x%x\n",
1824 phba->work_hs, phba->work_status[0],
1825 phba->work_status[1]);
1827 spin_lock_irq(&phba->hbalock);
1828 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1829 spin_unlock_irq(&phba->hbalock);
1832 * Firmware stops when it triggled erratt with HS_FFER6.
1833 * That could cause the I/Os dropped by the firmware.
1834 * Error iocb (I/O) on txcmplq and let the SCSI layer
1835 * retry it after re-establishing link.
1837 lpfc_sli_abort_fcp_rings(phba);
1840 * There was a firmware error. Take the hba offline and then
1841 * attempt to restart it.
1843 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1845 lpfc_sli_brdrestart(phba);
1846 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1847 lpfc_unblock_mgmt_io(phba);
1850 lpfc_unblock_mgmt_io(phba);
1851 } else if (phba->work_hs & HS_CRIT_TEMP) {
1852 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1853 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1854 temp_event_data.event_code = LPFC_CRIT_TEMP;
1855 temp_event_data.data = (uint32_t)temperature;
1857 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1858 "0406 Adapter maximum temperature exceeded "
1859 "(%ld), taking this port offline "
1860 "Data: x%x x%x x%x\n",
1861 temperature, phba->work_hs,
1862 phba->work_status[0], phba->work_status[1]);
1864 shost = lpfc_shost_from_vport(phba->pport);
1865 fc_host_post_vendor_event(shost, fc_get_event_number(),
1866 sizeof(temp_event_data),
1867 (char *) &temp_event_data,
1868 SCSI_NL_VID_TYPE_PCI
1869 | PCI_VENDOR_ID_EMULEX);
1871 spin_lock_irq(&phba->hbalock);
1872 phba->over_temp_state = HBA_OVER_TEMP;
1873 spin_unlock_irq(&phba->hbalock);
1874 lpfc_offline_eratt(phba);
1877 /* The if clause above forces this code path when the status
1878 * failure is a value other than FFER6. Do not call the offline
1879 * twice. This is the adapter hardware error path.
1881 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1882 "0457 Adapter Hardware Error "
1883 "Data: x%x x%x x%x\n",
1885 phba->work_status[0], phba->work_status[1]);
1887 event_data = FC_REG_DUMP_EVENT;
1888 shost = lpfc_shost_from_vport(vport);
1889 fc_host_post_vendor_event(shost, fc_get_event_number(),
1890 sizeof(event_data), (char *) &event_data,
1891 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1893 lpfc_offline_eratt(phba);
1899 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1900 * @phba: pointer to lpfc hba data structure.
1901 * @mbx_action: flag for mailbox shutdown action.
1902 * @en_rn_msg: send reset/port recovery message.
1903 * This routine is invoked to perform an SLI4 port PCI function reset in
1904 * response to port status register polling attention. It waits for port
1905 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1906 * During this process, interrupt vectors are freed and later requested
1907 * for handling possible port resource change.
1910 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1915 LPFC_MBOXQ_t *mboxq;
1917 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1918 LPFC_SLI_INTF_IF_TYPE_2) {
1920 * On error status condition, driver need to wait for port
1921 * ready before performing reset.
1923 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1928 /* need reset: attempt for port recovery */
1930 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1931 "2887 Reset Needed: Attempting Port "
1934 /* If we are no wait, the HBA has been reset and is not
1935 * functional, thus we should clear
1936 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
1938 if (mbx_action == LPFC_MBX_NO_WAIT) {
1939 spin_lock_irq(&phba->hbalock);
1940 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
1941 if (phba->sli.mbox_active) {
1942 mboxq = phba->sli.mbox_active;
1943 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1944 __lpfc_mbox_cmpl_put(phba, mboxq);
1945 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1946 phba->sli.mbox_active = NULL;
1948 spin_unlock_irq(&phba->hbalock);
1951 lpfc_offline_prep(phba, mbx_action);
1952 lpfc_sli_flush_io_rings(phba);
1954 /* release interrupt for possible resource change */
1955 lpfc_sli4_disable_intr(phba);
1956 rc = lpfc_sli_brdrestart(phba);
1958 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1959 "6309 Failed to restart board\n");
1962 /* request and enable interrupt */
1963 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1964 if (intr_mode == LPFC_INTR_ERROR) {
1965 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1966 "3175 Failed to enable interrupt\n");
1969 phba->intr_mode = intr_mode;
1970 rc = lpfc_online(phba);
1972 lpfc_unblock_mgmt_io(phba);
1978 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1979 * @phba: pointer to lpfc hba data structure.
1981 * This routine is invoked to handle the SLI4 HBA hardware error attention
1985 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1987 struct lpfc_vport *vport = phba->pport;
1988 uint32_t event_data;
1989 struct Scsi_Host *shost;
1991 struct lpfc_register portstat_reg = {0};
1992 uint32_t reg_err1, reg_err2;
1993 uint32_t uerrlo_reg, uemasklo_reg;
1994 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1995 bool en_rn_msg = true;
1996 struct temp_event temp_event_data;
1997 struct lpfc_register portsmphr_reg;
2000 /* If the pci channel is offline, ignore possible errors, since
2001 * we cannot communicate with the pci card anyway.
2003 if (pci_channel_offline(phba->pcidev)) {
2004 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2005 "3166 pci channel is offline\n");
2006 lpfc_sli_flush_io_rings(phba);
2010 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
2011 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2013 case LPFC_SLI_INTF_IF_TYPE_0:
2014 pci_rd_rc1 = lpfc_readl(
2015 phba->sli4_hba.u.if_type0.UERRLOregaddr,
2017 pci_rd_rc2 = lpfc_readl(
2018 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
2020 /* consider PCI bus read error as pci_channel_offline */
2021 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
2023 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
2024 lpfc_sli4_offline_eratt(phba);
2027 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2028 "7623 Checking UE recoverable");
2030 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
2031 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2032 &portsmphr_reg.word0))
2035 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
2037 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2038 LPFC_PORT_SEM_UE_RECOVERABLE)
2040 /*Sleep for 1Sec, before checking SEMAPHORE */
2044 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2045 "4827 smphr_port_status x%x : Waited %dSec",
2046 smphr_port_status, i);
2048 /* Recoverable UE, reset the HBA device */
2049 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2050 LPFC_PORT_SEM_UE_RECOVERABLE) {
2051 for (i = 0; i < 20; i++) {
2053 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2054 &portsmphr_reg.word0) &&
2055 (LPFC_POST_STAGE_PORT_READY ==
2056 bf_get(lpfc_port_smphr_port_status,
2058 rc = lpfc_sli4_port_sta_fn_reset(phba,
2059 LPFC_MBX_NO_WAIT, en_rn_msg);
2062 lpfc_printf_log(phba, KERN_ERR,
2064 "4215 Failed to recover UE");
2069 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2070 "7624 Firmware not ready: Failing UE recovery,"
2071 " waited %dSec", i);
2072 phba->link_state = LPFC_HBA_ERROR;
2075 case LPFC_SLI_INTF_IF_TYPE_2:
2076 case LPFC_SLI_INTF_IF_TYPE_6:
2077 pci_rd_rc1 = lpfc_readl(
2078 phba->sli4_hba.u.if_type2.STATUSregaddr,
2079 &portstat_reg.word0);
2080 /* consider PCI bus read error as pci_channel_offline */
2081 if (pci_rd_rc1 == -EIO) {
2082 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2083 "3151 PCI bus read access failure: x%x\n",
2084 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
2085 lpfc_sli4_offline_eratt(phba);
2088 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2089 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
2090 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
2091 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2092 "2889 Port Overtemperature event, "
2093 "taking port offline Data: x%x x%x\n",
2094 reg_err1, reg_err2);
2096 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
2097 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2098 temp_event_data.event_code = LPFC_CRIT_TEMP;
2099 temp_event_data.data = 0xFFFFFFFF;
2101 shost = lpfc_shost_from_vport(phba->pport);
2102 fc_host_post_vendor_event(shost, fc_get_event_number(),
2103 sizeof(temp_event_data),
2104 (char *)&temp_event_data,
2105 SCSI_NL_VID_TYPE_PCI
2106 | PCI_VENDOR_ID_EMULEX);
2108 spin_lock_irq(&phba->hbalock);
2109 phba->over_temp_state = HBA_OVER_TEMP;
2110 spin_unlock_irq(&phba->hbalock);
2111 lpfc_sli4_offline_eratt(phba);
2114 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2115 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
2116 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2117 "3143 Port Down: Firmware Update "
2120 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2121 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2122 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2123 "3144 Port Down: Debug Dump\n");
2124 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2125 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
2126 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2127 "3145 Port Down: Provisioning\n");
2129 /* If resets are disabled then leave the HBA alone and return */
2130 if (!phba->cfg_enable_hba_reset)
2133 /* Check port status register for function reset */
2134 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2137 /* don't report event on forced debug dump */
2138 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2139 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2144 /* fall through for not able to recover */
2145 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2146 "3152 Unrecoverable error\n");
2147 phba->link_state = LPFC_HBA_ERROR;
2149 case LPFC_SLI_INTF_IF_TYPE_1:
2153 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2154 "3123 Report dump event to upper layer\n");
2155 /* Send an internal error event to mgmt application */
2156 lpfc_board_errevt_to_mgmt(phba);
2158 event_data = FC_REG_DUMP_EVENT;
2159 shost = lpfc_shost_from_vport(vport);
2160 fc_host_post_vendor_event(shost, fc_get_event_number(),
2161 sizeof(event_data), (char *) &event_data,
2162 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2166 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2167 * @phba: pointer to lpfc HBA data structure.
2169 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2170 * routine from the API jump table function pointer from the lpfc_hba struct.
2174 * Any other value - error.
2177 lpfc_handle_eratt(struct lpfc_hba *phba)
2179 (*phba->lpfc_handle_eratt)(phba);
2183 * lpfc_handle_latt - The HBA link event handler
2184 * @phba: pointer to lpfc hba data structure.
2186 * This routine is invoked from the worker thread to handle a HBA host
2187 * attention link event. SLI3 only.
2190 lpfc_handle_latt(struct lpfc_hba *phba)
2192 struct lpfc_vport *vport = phba->pport;
2193 struct lpfc_sli *psli = &phba->sli;
2195 volatile uint32_t control;
2198 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2201 goto lpfc_handle_latt_err_exit;
2204 rc = lpfc_mbox_rsrc_prep(phba, pmb);
2207 mempool_free(pmb, phba->mbox_mem_pool);
2208 goto lpfc_handle_latt_err_exit;
2211 /* Cleanup any outstanding ELS commands */
2212 lpfc_els_flush_all_cmd(phba);
2213 psli->slistat.link_event++;
2214 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
2215 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2217 /* Block ELS IOCBs until we have processed this mbox command */
2218 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2219 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2220 if (rc == MBX_NOT_FINISHED) {
2222 goto lpfc_handle_latt_free_mbuf;
2225 /* Clear Link Attention in HA REG */
2226 spin_lock_irq(&phba->hbalock);
2227 writel(HA_LATT, phba->HAregaddr);
2228 readl(phba->HAregaddr); /* flush */
2229 spin_unlock_irq(&phba->hbalock);
2233 lpfc_handle_latt_free_mbuf:
2234 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2235 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
2236 lpfc_handle_latt_err_exit:
2237 /* Enable Link attention interrupts */
2238 spin_lock_irq(&phba->hbalock);
2239 psli->sli_flag |= LPFC_PROCESS_LA;
2240 control = readl(phba->HCregaddr);
2241 control |= HC_LAINT_ENA;
2242 writel(control, phba->HCregaddr);
2243 readl(phba->HCregaddr); /* flush */
2245 /* Clear Link Attention in HA REG */
2246 writel(HA_LATT, phba->HAregaddr);
2247 readl(phba->HAregaddr); /* flush */
2248 spin_unlock_irq(&phba->hbalock);
2249 lpfc_linkdown(phba);
2250 phba->link_state = LPFC_HBA_ERROR;
2252 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2253 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2259 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2260 * @phba: pointer to lpfc hba data structure.
2261 * @vpd: pointer to the vital product data.
2262 * @len: length of the vital product data in bytes.
2264 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2265 * an array of characters. In this routine, the ModelName, ProgramType, and
2266 * ModelDesc, etc. fields of the phba data structure will be populated.
2269 * 0 - pointer to the VPD passed in is NULL
2273 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2275 uint8_t lenlo, lenhi;
2285 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2286 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2287 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2289 while (!finished && (index < (len - 4))) {
2290 switch (vpd[index]) {
2298 i = ((((unsigned short)lenhi) << 8) + lenlo);
2307 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2308 if (Length > len - index)
2309 Length = len - index;
2310 while (Length > 0) {
2311 /* Look for Serial Number */
2312 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2319 phba->SerialNumber[j++] = vpd[index++];
2323 phba->SerialNumber[j] = 0;
2326 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2327 phba->vpd_flag |= VPD_MODEL_DESC;
2334 phba->ModelDesc[j++] = vpd[index++];
2338 phba->ModelDesc[j] = 0;
2341 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2342 phba->vpd_flag |= VPD_MODEL_NAME;
2349 phba->ModelName[j++] = vpd[index++];
2353 phba->ModelName[j] = 0;
2356 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2357 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2364 phba->ProgramType[j++] = vpd[index++];
2368 phba->ProgramType[j] = 0;
2371 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2372 phba->vpd_flag |= VPD_PORT;
2379 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2380 (phba->sli4_hba.pport_name_sta ==
2381 LPFC_SLI4_PPNAME_GET)) {
2385 phba->Port[j++] = vpd[index++];
2389 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2390 (phba->sli4_hba.pport_name_sta ==
2391 LPFC_SLI4_PPNAME_NON))
2418 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2419 * @phba: pointer to lpfc hba data structure.
2420 * @mdp: pointer to the data structure to hold the derived model name.
2421 * @descp: pointer to the data structure to hold the derived description.
2423 * This routine retrieves HBA's description based on its registered PCI device
2424 * ID. The @descp passed into this function points to an array of 256 chars. It
2425 * shall be returned with the model name, maximum speed, and the host bus type.
2426 * The @mdp passed into this function points to an array of 80 chars. When the
2427 * function returns, the @mdp will be filled with the model name.
2430 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2433 uint16_t dev_id = phba->pcidev->device;
2436 int oneConnect = 0; /* default is not a oneConnect */
2441 } m = {"<Unknown>", "", ""};
2443 if (mdp && mdp[0] != '\0'
2444 && descp && descp[0] != '\0')
2447 if (phba->lmt & LMT_64Gb)
2449 else if (phba->lmt & LMT_32Gb)
2451 else if (phba->lmt & LMT_16Gb)
2453 else if (phba->lmt & LMT_10Gb)
2455 else if (phba->lmt & LMT_8Gb)
2457 else if (phba->lmt & LMT_4Gb)
2459 else if (phba->lmt & LMT_2Gb)
2461 else if (phba->lmt & LMT_1Gb)
2469 case PCI_DEVICE_ID_FIREFLY:
2470 m = (typeof(m)){"LP6000", "PCI",
2471 "Obsolete, Unsupported Fibre Channel Adapter"};
2473 case PCI_DEVICE_ID_SUPERFLY:
2474 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2475 m = (typeof(m)){"LP7000", "PCI", ""};
2477 m = (typeof(m)){"LP7000E", "PCI", ""};
2478 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2480 case PCI_DEVICE_ID_DRAGONFLY:
2481 m = (typeof(m)){"LP8000", "PCI",
2482 "Obsolete, Unsupported Fibre Channel Adapter"};
2484 case PCI_DEVICE_ID_CENTAUR:
2485 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2486 m = (typeof(m)){"LP9002", "PCI", ""};
2488 m = (typeof(m)){"LP9000", "PCI", ""};
2489 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2491 case PCI_DEVICE_ID_RFLY:
2492 m = (typeof(m)){"LP952", "PCI",
2493 "Obsolete, Unsupported Fibre Channel Adapter"};
2495 case PCI_DEVICE_ID_PEGASUS:
2496 m = (typeof(m)){"LP9802", "PCI-X",
2497 "Obsolete, Unsupported Fibre Channel Adapter"};
2499 case PCI_DEVICE_ID_THOR:
2500 m = (typeof(m)){"LP10000", "PCI-X",
2501 "Obsolete, Unsupported Fibre Channel Adapter"};
2503 case PCI_DEVICE_ID_VIPER:
2504 m = (typeof(m)){"LPX1000", "PCI-X",
2505 "Obsolete, Unsupported Fibre Channel Adapter"};
2507 case PCI_DEVICE_ID_PFLY:
2508 m = (typeof(m)){"LP982", "PCI-X",
2509 "Obsolete, Unsupported Fibre Channel Adapter"};
2511 case PCI_DEVICE_ID_TFLY:
2512 m = (typeof(m)){"LP1050", "PCI-X",
2513 "Obsolete, Unsupported Fibre Channel Adapter"};
2515 case PCI_DEVICE_ID_HELIOS:
2516 m = (typeof(m)){"LP11000", "PCI-X2",
2517 "Obsolete, Unsupported Fibre Channel Adapter"};
2519 case PCI_DEVICE_ID_HELIOS_SCSP:
2520 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2521 "Obsolete, Unsupported Fibre Channel Adapter"};
2523 case PCI_DEVICE_ID_HELIOS_DCSP:
2524 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2525 "Obsolete, Unsupported Fibre Channel Adapter"};
2527 case PCI_DEVICE_ID_NEPTUNE:
2528 m = (typeof(m)){"LPe1000", "PCIe",
2529 "Obsolete, Unsupported Fibre Channel Adapter"};
2531 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2532 m = (typeof(m)){"LPe1000-SP", "PCIe",
2533 "Obsolete, Unsupported Fibre Channel Adapter"};
2535 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2536 m = (typeof(m)){"LPe1002-SP", "PCIe",
2537 "Obsolete, Unsupported Fibre Channel Adapter"};
2539 case PCI_DEVICE_ID_BMID:
2540 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2542 case PCI_DEVICE_ID_BSMB:
2543 m = (typeof(m)){"LP111", "PCI-X2",
2544 "Obsolete, Unsupported Fibre Channel Adapter"};
2546 case PCI_DEVICE_ID_ZEPHYR:
2547 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2549 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2550 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2552 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2553 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2556 case PCI_DEVICE_ID_ZMID:
2557 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2559 case PCI_DEVICE_ID_ZSMB:
2560 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2562 case PCI_DEVICE_ID_LP101:
2563 m = (typeof(m)){"LP101", "PCI-X",
2564 "Obsolete, Unsupported Fibre Channel Adapter"};
2566 case PCI_DEVICE_ID_LP10000S:
2567 m = (typeof(m)){"LP10000-S", "PCI",
2568 "Obsolete, Unsupported Fibre Channel Adapter"};
2570 case PCI_DEVICE_ID_LP11000S:
2571 m = (typeof(m)){"LP11000-S", "PCI-X2",
2572 "Obsolete, Unsupported Fibre Channel Adapter"};
2574 case PCI_DEVICE_ID_LPE11000S:
2575 m = (typeof(m)){"LPe11000-S", "PCIe",
2576 "Obsolete, Unsupported Fibre Channel Adapter"};
2578 case PCI_DEVICE_ID_SAT:
2579 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2581 case PCI_DEVICE_ID_SAT_MID:
2582 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2584 case PCI_DEVICE_ID_SAT_SMB:
2585 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2587 case PCI_DEVICE_ID_SAT_DCSP:
2588 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2590 case PCI_DEVICE_ID_SAT_SCSP:
2591 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2593 case PCI_DEVICE_ID_SAT_S:
2594 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2596 case PCI_DEVICE_ID_HORNET:
2597 m = (typeof(m)){"LP21000", "PCIe",
2598 "Obsolete, Unsupported FCoE Adapter"};
2601 case PCI_DEVICE_ID_PROTEUS_VF:
2602 m = (typeof(m)){"LPev12000", "PCIe IOV",
2603 "Obsolete, Unsupported Fibre Channel Adapter"};
2605 case PCI_DEVICE_ID_PROTEUS_PF:
2606 m = (typeof(m)){"LPev12000", "PCIe IOV",
2607 "Obsolete, Unsupported Fibre Channel Adapter"};
2609 case PCI_DEVICE_ID_PROTEUS_S:
2610 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2611 "Obsolete, Unsupported Fibre Channel Adapter"};
2613 case PCI_DEVICE_ID_TIGERSHARK:
2615 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2617 case PCI_DEVICE_ID_TOMCAT:
2619 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2621 case PCI_DEVICE_ID_FALCON:
2622 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2623 "EmulexSecure Fibre"};
2625 case PCI_DEVICE_ID_BALIUS:
2626 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2627 "Obsolete, Unsupported Fibre Channel Adapter"};
2629 case PCI_DEVICE_ID_LANCER_FC:
2630 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2632 case PCI_DEVICE_ID_LANCER_FC_VF:
2633 m = (typeof(m)){"LPe16000", "PCIe",
2634 "Obsolete, Unsupported Fibre Channel Adapter"};
2636 case PCI_DEVICE_ID_LANCER_FCOE:
2638 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2640 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2642 m = (typeof(m)){"OCe15100", "PCIe",
2643 "Obsolete, Unsupported FCoE"};
2645 case PCI_DEVICE_ID_LANCER_G6_FC:
2646 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2648 case PCI_DEVICE_ID_LANCER_G7_FC:
2649 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2651 case PCI_DEVICE_ID_LANCER_G7P_FC:
2652 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2654 case PCI_DEVICE_ID_SKYHAWK:
2655 case PCI_DEVICE_ID_SKYHAWK_VF:
2657 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2660 m = (typeof(m)){"Unknown", "", ""};
2664 if (mdp && mdp[0] == '\0')
2665 snprintf(mdp, 79,"%s", m.name);
2667 * oneConnect hba requires special processing, they are all initiators
2668 * and we put the port number on the end
2670 if (descp && descp[0] == '\0') {
2672 snprintf(descp, 255,
2673 "Emulex OneConnect %s, %s Initiator %s",
2676 else if (max_speed == 0)
2677 snprintf(descp, 255,
2679 m.name, m.bus, m.function);
2681 snprintf(descp, 255,
2682 "Emulex %s %d%s %s %s",
2683 m.name, max_speed, (GE) ? "GE" : "Gb",
2689 * lpfc_sli3_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2690 * @phba: pointer to lpfc hba data structure.
2691 * @pring: pointer to a IOCB ring.
2692 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2694 * This routine posts a given number of IOCBs with the associated DMA buffer
2695 * descriptors specified by the cnt argument to the given IOCB ring.
2698 * The number of IOCBs NOT able to be posted to the IOCB ring.
2701 lpfc_sli3_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2704 struct lpfc_iocbq *iocb;
2705 struct lpfc_dmabuf *mp1, *mp2;
2707 cnt += pring->missbufcnt;
2709 /* While there are buffers to post */
2711 /* Allocate buffer for command iocb */
2712 iocb = lpfc_sli_get_iocbq(phba);
2714 pring->missbufcnt = cnt;
2719 /* 2 buffers can be posted per command */
2720 /* Allocate buffer to post */
2721 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2723 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2724 if (!mp1 || !mp1->virt) {
2726 lpfc_sli_release_iocbq(phba, iocb);
2727 pring->missbufcnt = cnt;
2731 INIT_LIST_HEAD(&mp1->list);
2732 /* Allocate buffer to post */
2734 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2736 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2738 if (!mp2 || !mp2->virt) {
2740 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2742 lpfc_sli_release_iocbq(phba, iocb);
2743 pring->missbufcnt = cnt;
2747 INIT_LIST_HEAD(&mp2->list);
2752 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2753 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2754 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2755 icmd->ulpBdeCount = 1;
2758 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2759 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2760 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2762 icmd->ulpBdeCount = 2;
2765 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2768 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2770 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2774 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2778 lpfc_sli_release_iocbq(phba, iocb);
2779 pring->missbufcnt = cnt;
2782 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2784 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2786 pring->missbufcnt = 0;
2791 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2792 * @phba: pointer to lpfc hba data structure.
2794 * This routine posts initial receive IOCB buffers to the ELS ring. The
2795 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2796 * set to 64 IOCBs. SLI3 only.
2799 * 0 - success (currently always success)
2802 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2804 struct lpfc_sli *psli = &phba->sli;
2806 /* Ring 0, ELS / CT buffers */
2807 lpfc_sli3_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2808 /* Ring 2 - FCP no buffers needed */
2813 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2816 * lpfc_sha_init - Set up initial array of hash table entries
2817 * @HashResultPointer: pointer to an array as hash table.
2819 * This routine sets up the initial values to the array of hash table entries
2823 lpfc_sha_init(uint32_t * HashResultPointer)
2825 HashResultPointer[0] = 0x67452301;
2826 HashResultPointer[1] = 0xEFCDAB89;
2827 HashResultPointer[2] = 0x98BADCFE;
2828 HashResultPointer[3] = 0x10325476;
2829 HashResultPointer[4] = 0xC3D2E1F0;
2833 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2834 * @HashResultPointer: pointer to an initial/result hash table.
2835 * @HashWorkingPointer: pointer to an working hash table.
2837 * This routine iterates an initial hash table pointed by @HashResultPointer
2838 * with the values from the working hash table pointeed by @HashWorkingPointer.
2839 * The results are putting back to the initial hash table, returned through
2840 * the @HashResultPointer as the result hash table.
2843 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2847 uint32_t A, B, C, D, E;
2850 HashWorkingPointer[t] =
2852 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2854 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2855 } while (++t <= 79);
2857 A = HashResultPointer[0];
2858 B = HashResultPointer[1];
2859 C = HashResultPointer[2];
2860 D = HashResultPointer[3];
2861 E = HashResultPointer[4];
2865 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2866 } else if (t < 40) {
2867 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2868 } else if (t < 60) {
2869 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2871 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2873 TEMP += S(5, A) + E + HashWorkingPointer[t];
2879 } while (++t <= 79);
2881 HashResultPointer[0] += A;
2882 HashResultPointer[1] += B;
2883 HashResultPointer[2] += C;
2884 HashResultPointer[3] += D;
2885 HashResultPointer[4] += E;
2890 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2891 * @RandomChallenge: pointer to the entry of host challenge random number array.
2892 * @HashWorking: pointer to the entry of the working hash array.
2894 * This routine calculates the working hash array referred by @HashWorking
2895 * from the challenge random numbers associated with the host, referred by
2896 * @RandomChallenge. The result is put into the entry of the working hash
2897 * array and returned by reference through @HashWorking.
2900 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2902 *HashWorking = (*RandomChallenge ^ *HashWorking);
2906 * lpfc_hba_init - Perform special handling for LC HBA initialization
2907 * @phba: pointer to lpfc hba data structure.
2908 * @hbainit: pointer to an array of unsigned 32-bit integers.
2910 * This routine performs the special handling for LC HBA initialization.
2913 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2916 uint32_t *HashWorking;
2917 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2919 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2923 HashWorking[0] = HashWorking[78] = *pwwnn++;
2924 HashWorking[1] = HashWorking[79] = *pwwnn;
2926 for (t = 0; t < 7; t++)
2927 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2929 lpfc_sha_init(hbainit);
2930 lpfc_sha_iterate(hbainit, HashWorking);
2935 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2936 * @vport: pointer to a virtual N_Port data structure.
2938 * This routine performs the necessary cleanups before deleting the @vport.
2939 * It invokes the discovery state machine to perform necessary state
2940 * transitions and to release the ndlps associated with the @vport. Note,
2941 * the physical port is treated as @vport 0.
2944 lpfc_cleanup(struct lpfc_vport *vport)
2946 struct lpfc_hba *phba = vport->phba;
2947 struct lpfc_nodelist *ndlp, *next_ndlp;
2950 if (phba->link_state > LPFC_LINK_DOWN)
2951 lpfc_port_link_failure(vport);
2953 /* Clean up VMID resources */
2954 if (lpfc_is_vmid_enabled(phba))
2955 lpfc_vmid_vport_cleanup(vport);
2957 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2958 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2959 ndlp->nlp_DID == Fabric_DID) {
2960 /* Just free up ndlp with Fabric_DID for vports */
2965 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
2966 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2971 /* Fabric Ports not in UNMAPPED state are cleaned up in the
2974 if (ndlp->nlp_type & NLP_FABRIC &&
2975 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
2976 lpfc_disc_state_machine(vport, ndlp, NULL,
2977 NLP_EVT_DEVICE_RECOVERY);
2979 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
2980 lpfc_disc_state_machine(vport, ndlp, NULL,
2984 /* This is a special case flush to return all
2985 * IOs before entering this loop. There are
2986 * two points in the code where a flush is
2987 * avoided if the FC_UNLOADING flag is set.
2988 * one is in the multipool destroy,
2989 * (this prevents a crash) and the other is
2990 * in the nvme abort handler, ( also prevents
2991 * a crash). Both of these exceptions are
2992 * cases where the slot is still accessible.
2993 * The flush here is only when the pci slot
2996 if (vport->load_flag & FC_UNLOADING &&
2997 pci_channel_offline(phba->pcidev))
2998 lpfc_sli_flush_io_rings(vport->phba);
3000 /* At this point, ALL ndlp's should be gone
3001 * because of the previous NLP_EVT_DEVICE_RM.
3002 * Lets wait for this to happen, if needed.
3004 while (!list_empty(&vport->fc_nodes)) {
3006 lpfc_printf_vlog(vport, KERN_ERR,
3008 "0233 Nodelist not empty\n");
3009 list_for_each_entry_safe(ndlp, next_ndlp,
3010 &vport->fc_nodes, nlp_listp) {
3011 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
3013 "0282 did:x%x ndlp:x%px "
3014 "refcnt:%d xflags x%x nflag x%x\n",
3015 ndlp->nlp_DID, (void *)ndlp,
3016 kref_read(&ndlp->kref),
3017 ndlp->fc4_xpt_flags,
3023 /* Wait for any activity on ndlps to settle */
3026 lpfc_cleanup_vports_rrqs(vport, NULL);
3030 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
3031 * @vport: pointer to a virtual N_Port data structure.
3033 * This routine stops all the timers associated with a @vport. This function
3034 * is invoked before disabling or deleting a @vport. Note that the physical
3035 * port is treated as @vport 0.
3038 lpfc_stop_vport_timers(struct lpfc_vport *vport)
3040 del_timer_sync(&vport->els_tmofunc);
3041 del_timer_sync(&vport->delayed_disc_tmo);
3042 lpfc_can_disctmo(vport);
3047 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3048 * @phba: pointer to lpfc hba data structure.
3050 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
3051 * caller of this routine should already hold the host lock.
3054 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3056 /* Clear pending FCF rediscovery wait flag */
3057 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3059 /* Now, try to stop the timer */
3060 del_timer(&phba->fcf.redisc_wait);
3064 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3065 * @phba: pointer to lpfc hba data structure.
3067 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3068 * checks whether the FCF rediscovery wait timer is pending with the host
3069 * lock held before proceeding with disabling the timer and clearing the
3070 * wait timer pendig flag.
3073 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3075 spin_lock_irq(&phba->hbalock);
3076 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3077 /* FCF rediscovery timer already fired or stopped */
3078 spin_unlock_irq(&phba->hbalock);
3081 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3082 /* Clear failover in progress flags */
3083 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
3084 spin_unlock_irq(&phba->hbalock);
3088 * lpfc_cmf_stop - Stop CMF processing
3089 * @phba: pointer to lpfc hba data structure.
3091 * This is called when the link goes down or if CMF mode is turned OFF.
3092 * It is also called when going offline or unloaded just before the
3093 * congestion info buffer is unregistered.
3096 lpfc_cmf_stop(struct lpfc_hba *phba)
3099 struct lpfc_cgn_stat *cgs;
3101 /* We only do something if CMF is enabled */
3102 if (!phba->sli4_hba.pc_sli4_params.cmf)
3105 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3106 "6221 Stop CMF / Cancel Timer\n");
3108 /* Cancel the CMF timer */
3109 hrtimer_cancel(&phba->cmf_timer);
3111 /* Zero CMF counters */
3112 atomic_set(&phba->cmf_busy, 0);
3113 for_each_present_cpu(cpu) {
3114 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3115 atomic64_set(&cgs->total_bytes, 0);
3116 atomic64_set(&cgs->rcv_bytes, 0);
3117 atomic_set(&cgs->rx_io_cnt, 0);
3118 atomic64_set(&cgs->rx_latency, 0);
3120 atomic_set(&phba->cmf_bw_wait, 0);
3122 /* Resume any blocked IO - Queue unblock on workqueue */
3123 queue_work(phba->wq, &phba->unblock_request_work);
3126 static inline uint64_t
3127 lpfc_get_max_line_rate(struct lpfc_hba *phba)
3129 uint64_t rate = lpfc_sli_port_speed_get(phba);
3131 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3135 lpfc_cmf_signal_init(struct lpfc_hba *phba)
3137 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3138 "6223 Signal CMF init\n");
3140 /* Use the new fc_linkspeed to recalculate */
3141 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3142 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3143 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3144 phba->cmf_interval_rate, 1000);
3145 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3147 /* This is a signal to firmware to sync up CMF BW with link speed */
3148 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3152 * lpfc_cmf_start - Start CMF processing
3153 * @phba: pointer to lpfc hba data structure.
3155 * This is called when the link comes up or if CMF mode is turned OFF
3156 * to Monitor or Managed.
3159 lpfc_cmf_start(struct lpfc_hba *phba)
3161 struct lpfc_cgn_stat *cgs;
3164 /* We only do something if CMF is enabled */
3165 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3166 phba->cmf_active_mode == LPFC_CFG_OFF)
3169 /* Reinitialize congestion buffer info */
3170 lpfc_init_congestion_buf(phba);
3172 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3173 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3174 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3175 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3177 atomic_set(&phba->cmf_busy, 0);
3178 for_each_present_cpu(cpu) {
3179 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3180 atomic64_set(&cgs->total_bytes, 0);
3181 atomic64_set(&cgs->rcv_bytes, 0);
3182 atomic_set(&cgs->rx_io_cnt, 0);
3183 atomic64_set(&cgs->rx_latency, 0);
3185 phba->cmf_latency.tv_sec = 0;
3186 phba->cmf_latency.tv_nsec = 0;
3188 lpfc_cmf_signal_init(phba);
3190 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3191 "6222 Start CMF / Timer\n");
3193 phba->cmf_timer_cnt = 0;
3194 hrtimer_start(&phba->cmf_timer,
3195 ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
3197 /* Setup for latency check in IO cmpl routines */
3198 ktime_get_real_ts64(&phba->cmf_latency);
3200 atomic_set(&phba->cmf_bw_wait, 0);
3201 atomic_set(&phba->cmf_stop_io, 0);
3205 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
3206 * @phba: pointer to lpfc hba data structure.
3208 * This routine stops all the timers associated with a HBA. This function is
3209 * invoked before either putting a HBA offline or unloading the driver.
3212 lpfc_stop_hba_timers(struct lpfc_hba *phba)
3215 lpfc_stop_vport_timers(phba->pport);
3216 cancel_delayed_work_sync(&phba->eq_delay_work);
3217 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
3218 del_timer_sync(&phba->sli.mbox_tmo);
3219 del_timer_sync(&phba->fabric_block_timer);
3220 del_timer_sync(&phba->eratt_poll);
3221 del_timer_sync(&phba->hb_tmofunc);
3222 if (phba->sli_rev == LPFC_SLI_REV4) {
3223 del_timer_sync(&phba->rrq_tmr);
3224 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
3226 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
3228 switch (phba->pci_dev_grp) {
3229 case LPFC_PCI_DEV_LP:
3230 /* Stop any LightPulse device specific driver timers */
3231 del_timer_sync(&phba->fcp_poll_timer);
3233 case LPFC_PCI_DEV_OC:
3234 /* Stop any OneConnect device specific driver timers */
3235 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3238 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3239 "0297 Invalid device group (x%x)\n",
3247 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3248 * @phba: pointer to lpfc hba data structure.
3249 * @mbx_action: flag for mailbox no wait action.
3251 * This routine marks a HBA's management interface as blocked. Once the HBA's
3252 * management interface is marked as blocked, all the user space access to
3253 * the HBA, whether they are from sysfs interface or libdfc interface will
3254 * all be blocked. The HBA is set to block the management interface when the
3255 * driver prepares the HBA interface for online or offline.
3258 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
3260 unsigned long iflag;
3261 uint8_t actcmd = MBX_HEARTBEAT;
3262 unsigned long timeout;
3264 spin_lock_irqsave(&phba->hbalock, iflag);
3265 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
3266 spin_unlock_irqrestore(&phba->hbalock, iflag);
3267 if (mbx_action == LPFC_MBX_NO_WAIT)
3269 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3270 spin_lock_irqsave(&phba->hbalock, iflag);
3271 if (phba->sli.mbox_active) {
3272 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3273 /* Determine how long we might wait for the active mailbox
3274 * command to be gracefully completed by firmware.
3276 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3277 phba->sli.mbox_active) * 1000) + jiffies;
3279 spin_unlock_irqrestore(&phba->hbalock, iflag);
3281 /* Wait for the outstnading mailbox command to complete */
3282 while (phba->sli.mbox_active) {
3283 /* Check active mailbox complete status every 2ms */
3285 if (time_after(jiffies, timeout)) {
3286 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3287 "2813 Mgmt IO is Blocked %x "
3288 "- mbox cmd %x still active\n",
3289 phba->sli.sli_flag, actcmd);
3296 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3297 * @phba: pointer to lpfc hba data structure.
3299 * Allocate RPIs for all active remote nodes. This is needed whenever
3300 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3301 * is to fixup the temporary rpi assignments.
3304 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3306 struct lpfc_nodelist *ndlp, *next_ndlp;
3307 struct lpfc_vport **vports;
3310 if (phba->sli_rev != LPFC_SLI_REV4)
3313 vports = lpfc_create_vport_work_array(phba);
3317 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3318 if (vports[i]->load_flag & FC_UNLOADING)
3321 list_for_each_entry_safe(ndlp, next_ndlp,
3322 &vports[i]->fc_nodes,
3324 rpi = lpfc_sli4_alloc_rpi(phba);
3325 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3326 /* TODO print log? */
3329 ndlp->nlp_rpi = rpi;
3330 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3331 LOG_NODE | LOG_DISCOVERY,
3332 "0009 Assign RPI x%x to ndlp x%px "
3333 "DID:x%06x flg:x%x\n",
3334 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3338 lpfc_destroy_vport_work_array(phba, vports);
3342 * lpfc_create_expedite_pool - create expedite pool
3343 * @phba: pointer to lpfc hba data structure.
3345 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3346 * to expedite pool. Mark them as expedite.
3348 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3350 struct lpfc_sli4_hdw_queue *qp;
3351 struct lpfc_io_buf *lpfc_ncmd;
3352 struct lpfc_io_buf *lpfc_ncmd_next;
3353 struct lpfc_epd_pool *epd_pool;
3354 unsigned long iflag;
3356 epd_pool = &phba->epd_pool;
3357 qp = &phba->sli4_hba.hdwq[0];
3359 spin_lock_init(&epd_pool->lock);
3360 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3361 spin_lock(&epd_pool->lock);
3362 INIT_LIST_HEAD(&epd_pool->list);
3363 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3364 &qp->lpfc_io_buf_list_put, list) {
3365 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3366 lpfc_ncmd->expedite = true;
3369 if (epd_pool->count >= XRI_BATCH)
3372 spin_unlock(&epd_pool->lock);
3373 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3377 * lpfc_destroy_expedite_pool - destroy expedite pool
3378 * @phba: pointer to lpfc hba data structure.
3380 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3381 * of HWQ 0. Clear the mark.
3383 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3385 struct lpfc_sli4_hdw_queue *qp;
3386 struct lpfc_io_buf *lpfc_ncmd;
3387 struct lpfc_io_buf *lpfc_ncmd_next;
3388 struct lpfc_epd_pool *epd_pool;
3389 unsigned long iflag;
3391 epd_pool = &phba->epd_pool;
3392 qp = &phba->sli4_hba.hdwq[0];
3394 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3395 spin_lock(&epd_pool->lock);
3396 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3397 &epd_pool->list, list) {
3398 list_move_tail(&lpfc_ncmd->list,
3399 &qp->lpfc_io_buf_list_put);
3400 lpfc_ncmd->flags = false;
3404 spin_unlock(&epd_pool->lock);
3405 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3409 * lpfc_create_multixri_pools - create multi-XRI pools
3410 * @phba: pointer to lpfc hba data structure.
3412 * This routine initialize public, private per HWQ. Then, move XRIs from
3413 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3416 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3421 struct lpfc_io_buf *lpfc_ncmd;
3422 struct lpfc_io_buf *lpfc_ncmd_next;
3423 unsigned long iflag;
3424 struct lpfc_sli4_hdw_queue *qp;
3425 struct lpfc_multixri_pool *multixri_pool;
3426 struct lpfc_pbl_pool *pbl_pool;
3427 struct lpfc_pvt_pool *pvt_pool;
3429 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3430 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3431 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3432 phba->sli4_hba.io_xri_cnt);
3434 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3435 lpfc_create_expedite_pool(phba);
3437 hwq_count = phba->cfg_hdw_queue;
3438 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3440 for (i = 0; i < hwq_count; i++) {
3441 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3443 if (!multixri_pool) {
3444 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3445 "1238 Failed to allocate memory for "
3448 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3449 lpfc_destroy_expedite_pool(phba);
3453 qp = &phba->sli4_hba.hdwq[j];
3454 kfree(qp->p_multixri_pool);
3457 phba->cfg_xri_rebalancing = 0;
3461 qp = &phba->sli4_hba.hdwq[i];
3462 qp->p_multixri_pool = multixri_pool;
3464 multixri_pool->xri_limit = count_per_hwq;
3465 multixri_pool->rrb_next_hwqid = i;
3467 /* Deal with public free xri pool */
3468 pbl_pool = &multixri_pool->pbl_pool;
3469 spin_lock_init(&pbl_pool->lock);
3470 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3471 spin_lock(&pbl_pool->lock);
3472 INIT_LIST_HEAD(&pbl_pool->list);
3473 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3474 &qp->lpfc_io_buf_list_put, list) {
3475 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3479 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3480 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3481 pbl_pool->count, i);
3482 spin_unlock(&pbl_pool->lock);
3483 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3485 /* Deal with private free xri pool */
3486 pvt_pool = &multixri_pool->pvt_pool;
3487 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3488 pvt_pool->low_watermark = XRI_BATCH;
3489 spin_lock_init(&pvt_pool->lock);
3490 spin_lock_irqsave(&pvt_pool->lock, iflag);
3491 INIT_LIST_HEAD(&pvt_pool->list);
3492 pvt_pool->count = 0;
3493 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3498 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3499 * @phba: pointer to lpfc hba data structure.
3501 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3503 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3507 struct lpfc_io_buf *lpfc_ncmd;
3508 struct lpfc_io_buf *lpfc_ncmd_next;
3509 unsigned long iflag;
3510 struct lpfc_sli4_hdw_queue *qp;
3511 struct lpfc_multixri_pool *multixri_pool;
3512 struct lpfc_pbl_pool *pbl_pool;
3513 struct lpfc_pvt_pool *pvt_pool;
3515 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3516 lpfc_destroy_expedite_pool(phba);
3518 if (!(phba->pport->load_flag & FC_UNLOADING))
3519 lpfc_sli_flush_io_rings(phba);
3521 hwq_count = phba->cfg_hdw_queue;
3523 for (i = 0; i < hwq_count; i++) {
3524 qp = &phba->sli4_hba.hdwq[i];
3525 multixri_pool = qp->p_multixri_pool;
3529 qp->p_multixri_pool = NULL;
3531 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3533 /* Deal with public free xri pool */
3534 pbl_pool = &multixri_pool->pbl_pool;
3535 spin_lock(&pbl_pool->lock);
3537 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3538 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3539 pbl_pool->count, i);
3541 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3542 &pbl_pool->list, list) {
3543 list_move_tail(&lpfc_ncmd->list,
3544 &qp->lpfc_io_buf_list_put);
3549 INIT_LIST_HEAD(&pbl_pool->list);
3550 pbl_pool->count = 0;
3552 spin_unlock(&pbl_pool->lock);
3554 /* Deal with private free xri pool */
3555 pvt_pool = &multixri_pool->pvt_pool;
3556 spin_lock(&pvt_pool->lock);
3558 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3559 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3560 pvt_pool->count, i);
3562 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3563 &pvt_pool->list, list) {
3564 list_move_tail(&lpfc_ncmd->list,
3565 &qp->lpfc_io_buf_list_put);
3570 INIT_LIST_HEAD(&pvt_pool->list);
3571 pvt_pool->count = 0;
3573 spin_unlock(&pvt_pool->lock);
3574 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3576 kfree(multixri_pool);
3581 * lpfc_online - Initialize and bring a HBA online
3582 * @phba: pointer to lpfc hba data structure.
3584 * This routine initializes the HBA and brings a HBA online. During this
3585 * process, the management interface is blocked to prevent user space access
3586 * to the HBA interfering with the driver initialization.
3593 lpfc_online(struct lpfc_hba *phba)
3595 struct lpfc_vport *vport;
3596 struct lpfc_vport **vports;
3598 bool vpis_cleared = false;
3602 vport = phba->pport;
3604 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3607 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3608 "0458 Bring Adapter online\n");
3610 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3612 if (phba->sli_rev == LPFC_SLI_REV4) {
3613 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3614 lpfc_unblock_mgmt_io(phba);
3617 spin_lock_irq(&phba->hbalock);
3618 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3619 vpis_cleared = true;
3620 spin_unlock_irq(&phba->hbalock);
3622 /* Reestablish the local initiator port.
3623 * The offline process destroyed the previous lport.
3625 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3626 !phba->nvmet_support) {
3627 error = lpfc_nvme_create_localport(phba->pport);
3629 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3630 "6132 NVME restore reg failed "
3631 "on nvmei error x%x\n", error);
3634 lpfc_sli_queue_init(phba);
3635 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3636 lpfc_unblock_mgmt_io(phba);
3641 vports = lpfc_create_vport_work_array(phba);
3642 if (vports != NULL) {
3643 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3644 struct Scsi_Host *shost;
3645 shost = lpfc_shost_from_vport(vports[i]);
3646 spin_lock_irq(shost->host_lock);
3647 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3648 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3649 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3650 if (phba->sli_rev == LPFC_SLI_REV4) {
3651 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3652 if ((vpis_cleared) &&
3653 (vports[i]->port_type !=
3654 LPFC_PHYSICAL_PORT))
3657 spin_unlock_irq(shost->host_lock);
3660 lpfc_destroy_vport_work_array(phba, vports);
3662 if (phba->cfg_xri_rebalancing)
3663 lpfc_create_multixri_pools(phba);
3665 lpfc_cpuhp_add(phba);
3667 lpfc_unblock_mgmt_io(phba);
3672 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3673 * @phba: pointer to lpfc hba data structure.
3675 * This routine marks a HBA's management interface as not blocked. Once the
3676 * HBA's management interface is marked as not blocked, all the user space
3677 * access to the HBA, whether they are from sysfs interface or libdfc
3678 * interface will be allowed. The HBA is set to block the management interface
3679 * when the driver prepares the HBA interface for online or offline and then
3680 * set to unblock the management interface afterwards.
3683 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3685 unsigned long iflag;
3687 spin_lock_irqsave(&phba->hbalock, iflag);
3688 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3689 spin_unlock_irqrestore(&phba->hbalock, iflag);
3693 * lpfc_offline_prep - Prepare a HBA to be brought offline
3694 * @phba: pointer to lpfc hba data structure.
3695 * @mbx_action: flag for mailbox shutdown action.
3697 * This routine is invoked to prepare a HBA to be brought offline. It performs
3698 * unregistration login to all the nodes on all vports and flushes the mailbox
3699 * queue to make it ready to be brought offline.
3702 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3704 struct lpfc_vport *vport = phba->pport;
3705 struct lpfc_nodelist *ndlp, *next_ndlp;
3706 struct lpfc_vport **vports;
3707 struct Scsi_Host *shost;
3712 if (vport->fc_flag & FC_OFFLINE_MODE)
3715 lpfc_block_mgmt_io(phba, mbx_action);
3717 lpfc_linkdown(phba);
3719 offline = pci_channel_offline(phba->pcidev);
3720 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
3722 /* Issue an unreg_login to all nodes on all vports */
3723 vports = lpfc_create_vport_work_array(phba);
3724 if (vports != NULL) {
3725 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3726 if (vports[i]->load_flag & FC_UNLOADING)
3728 shost = lpfc_shost_from_vport(vports[i]);
3729 spin_lock_irq(shost->host_lock);
3730 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3731 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3732 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3733 spin_unlock_irq(shost->host_lock);
3735 shost = lpfc_shost_from_vport(vports[i]);
3736 list_for_each_entry_safe(ndlp, next_ndlp,
3737 &vports[i]->fc_nodes,
3740 spin_lock_irq(&ndlp->lock);
3741 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3742 spin_unlock_irq(&ndlp->lock);
3744 if (offline || hba_pci_err) {
3745 spin_lock_irq(&ndlp->lock);
3746 ndlp->nlp_flag &= ~(NLP_UNREG_INP |
3747 NLP_RPI_REGISTERED);
3748 spin_unlock_irq(&ndlp->lock);
3749 if (phba->sli_rev == LPFC_SLI_REV4)
3750 lpfc_sli_rpi_release(vports[i],
3753 lpfc_unreg_rpi(vports[i], ndlp);
3756 * Whenever an SLI4 port goes offline, free the
3757 * RPI. Get a new RPI when the adapter port
3758 * comes back online.
3760 if (phba->sli_rev == LPFC_SLI_REV4) {
3761 lpfc_printf_vlog(vports[i], KERN_INFO,
3762 LOG_NODE | LOG_DISCOVERY,
3763 "0011 Free RPI x%x on "
3764 "ndlp: x%px did x%x\n",
3765 ndlp->nlp_rpi, ndlp,
3767 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3768 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3771 if (ndlp->nlp_type & NLP_FABRIC) {
3772 lpfc_disc_state_machine(vports[i], ndlp,
3773 NULL, NLP_EVT_DEVICE_RECOVERY);
3775 /* Don't remove the node unless the node
3776 * has been unregistered with the
3777 * transport, and we're not in recovery
3778 * before dev_loss_tmo triggered.
3779 * Otherwise, let dev_loss take care of
3782 if (!(ndlp->save_flags &
3783 NLP_IN_RECOV_POST_DEV_LOSS) &&
3784 !(ndlp->fc4_xpt_flags &
3785 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3786 lpfc_disc_state_machine
3794 lpfc_destroy_vport_work_array(phba, vports);
3796 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3799 flush_workqueue(phba->wq);
3803 * lpfc_offline - Bring a HBA offline
3804 * @phba: pointer to lpfc hba data structure.
3806 * This routine actually brings a HBA offline. It stops all the timers
3807 * associated with the HBA, brings down the SLI layer, and eventually
3808 * marks the HBA as in offline state for the upper layer protocol.
3811 lpfc_offline(struct lpfc_hba *phba)
3813 struct Scsi_Host *shost;
3814 struct lpfc_vport **vports;
3817 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3820 /* stop port and all timers associated with this hba */
3821 lpfc_stop_port(phba);
3823 /* Tear down the local and target port registrations. The
3824 * nvme transports need to cleanup.
3826 lpfc_nvmet_destroy_targetport(phba);
3827 lpfc_nvme_destroy_localport(phba->pport);
3829 vports = lpfc_create_vport_work_array(phba);
3831 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3832 lpfc_stop_vport_timers(vports[i]);
3833 lpfc_destroy_vport_work_array(phba, vports);
3834 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3835 "0460 Bring Adapter offline\n");
3836 /* Bring down the SLI Layer and cleanup. The HBA is offline
3838 lpfc_sli_hba_down(phba);
3839 spin_lock_irq(&phba->hbalock);
3841 spin_unlock_irq(&phba->hbalock);
3842 vports = lpfc_create_vport_work_array(phba);
3844 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3845 shost = lpfc_shost_from_vport(vports[i]);
3846 spin_lock_irq(shost->host_lock);
3847 vports[i]->work_port_events = 0;
3848 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3849 spin_unlock_irq(shost->host_lock);
3851 lpfc_destroy_vport_work_array(phba, vports);
3852 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3855 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3856 __lpfc_cpuhp_remove(phba);
3858 if (phba->cfg_xri_rebalancing)
3859 lpfc_destroy_multixri_pools(phba);
3863 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3864 * @phba: pointer to lpfc hba data structure.
3866 * This routine is to free all the SCSI buffers and IOCBs from the driver
3867 * list back to kernel. It is called from lpfc_pci_remove_one to free
3868 * the internal resources before the device is removed from the system.
3871 lpfc_scsi_free(struct lpfc_hba *phba)
3873 struct lpfc_io_buf *sb, *sb_next;
3875 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3878 spin_lock_irq(&phba->hbalock);
3880 /* Release all the lpfc_scsi_bufs maintained by this host. */
3882 spin_lock(&phba->scsi_buf_list_put_lock);
3883 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3885 list_del(&sb->list);
3886 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3889 phba->total_scsi_bufs--;
3891 spin_unlock(&phba->scsi_buf_list_put_lock);
3893 spin_lock(&phba->scsi_buf_list_get_lock);
3894 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3896 list_del(&sb->list);
3897 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3900 phba->total_scsi_bufs--;
3902 spin_unlock(&phba->scsi_buf_list_get_lock);
3903 spin_unlock_irq(&phba->hbalock);
3907 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3908 * @phba: pointer to lpfc hba data structure.
3910 * This routine is to free all the IO buffers and IOCBs from the driver
3911 * list back to kernel. It is called from lpfc_pci_remove_one to free
3912 * the internal resources before the device is removed from the system.
3915 lpfc_io_free(struct lpfc_hba *phba)
3917 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
3918 struct lpfc_sli4_hdw_queue *qp;
3921 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3922 qp = &phba->sli4_hba.hdwq[idx];
3923 /* Release all the lpfc_nvme_bufs maintained by this host. */
3924 spin_lock(&qp->io_buf_list_put_lock);
3925 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3926 &qp->lpfc_io_buf_list_put,
3928 list_del(&lpfc_ncmd->list);
3930 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3931 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3932 if (phba->cfg_xpsgl && !phba->nvmet_support)
3933 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3934 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3936 qp->total_io_bufs--;
3938 spin_unlock(&qp->io_buf_list_put_lock);
3940 spin_lock(&qp->io_buf_list_get_lock);
3941 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3942 &qp->lpfc_io_buf_list_get,
3944 list_del(&lpfc_ncmd->list);
3946 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3947 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3948 if (phba->cfg_xpsgl && !phba->nvmet_support)
3949 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3950 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3952 qp->total_io_bufs--;
3954 spin_unlock(&qp->io_buf_list_get_lock);
3959 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3960 * @phba: pointer to lpfc hba data structure.
3962 * This routine first calculates the sizes of the current els and allocated
3963 * scsi sgl lists, and then goes through all sgls to updates the physical
3964 * XRIs assigned due to port function reset. During port initialization, the
3965 * current els and allocated scsi sgl lists are 0s.
3968 * 0 - successful (for now, it always returns 0)
3971 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3973 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3974 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3975 LIST_HEAD(els_sgl_list);
3979 * update on pci function's els xri-sgl list
3981 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3983 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3984 /* els xri-sgl expanded */
3985 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3986 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3987 "3157 ELS xri-sgl count increased from "
3988 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3990 /* allocate the additional els sgls */
3991 for (i = 0; i < xri_cnt; i++) {
3992 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3994 if (sglq_entry == NULL) {
3995 lpfc_printf_log(phba, KERN_ERR,
3997 "2562 Failure to allocate an "
3998 "ELS sgl entry:%d\n", i);
4002 sglq_entry->buff_type = GEN_BUFF_TYPE;
4003 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
4005 if (sglq_entry->virt == NULL) {
4007 lpfc_printf_log(phba, KERN_ERR,
4009 "2563 Failure to allocate an "
4010 "ELS mbuf:%d\n", i);
4014 sglq_entry->sgl = sglq_entry->virt;
4015 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
4016 sglq_entry->state = SGL_FREED;
4017 list_add_tail(&sglq_entry->list, &els_sgl_list);
4019 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4020 list_splice_init(&els_sgl_list,
4021 &phba->sli4_hba.lpfc_els_sgl_list);
4022 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4023 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
4024 /* els xri-sgl shrinked */
4025 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
4026 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4027 "3158 ELS xri-sgl count decreased from "
4028 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4030 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4031 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
4033 /* release extra els sgls from list */
4034 for (i = 0; i < xri_cnt; i++) {
4035 list_remove_head(&els_sgl_list,
4036 sglq_entry, struct lpfc_sglq, list);
4038 __lpfc_mbuf_free(phba, sglq_entry->virt,
4043 list_splice_init(&els_sgl_list,
4044 &phba->sli4_hba.lpfc_els_sgl_list);
4045 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4047 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4048 "3163 ELS xri-sgl count unchanged: %d\n",
4050 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
4052 /* update xris to els sgls on the list */
4054 sglq_entry_next = NULL;
4055 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4056 &phba->sli4_hba.lpfc_els_sgl_list, list) {
4057 lxri = lpfc_sli4_next_xritag(phba);
4058 if (lxri == NO_XRI) {
4059 lpfc_printf_log(phba, KERN_ERR,
4061 "2400 Failed to allocate xri for "
4066 sglq_entry->sli4_lxritag = lxri;
4067 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4072 lpfc_free_els_sgl_list(phba);
4077 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
4078 * @phba: pointer to lpfc hba data structure.
4080 * This routine first calculates the sizes of the current els and allocated
4081 * scsi sgl lists, and then goes through all sgls to updates the physical
4082 * XRIs assigned due to port function reset. During port initialization, the
4083 * current els and allocated scsi sgl lists are 0s.
4086 * 0 - successful (for now, it always returns 0)
4089 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4091 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4092 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4093 uint16_t nvmet_xri_cnt;
4094 LIST_HEAD(nvmet_sgl_list);
4098 * update on pci function's nvmet xri-sgl list
4100 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4102 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4103 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4104 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4105 /* els xri-sgl expanded */
4106 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4107 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4108 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4109 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4110 /* allocate the additional nvmet sgls */
4111 for (i = 0; i < xri_cnt; i++) {
4112 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4114 if (sglq_entry == NULL) {
4115 lpfc_printf_log(phba, KERN_ERR,
4117 "6303 Failure to allocate an "
4118 "NVMET sgl entry:%d\n", i);
4122 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4123 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4125 if (sglq_entry->virt == NULL) {
4127 lpfc_printf_log(phba, KERN_ERR,
4129 "6304 Failure to allocate an "
4130 "NVMET buf:%d\n", i);
4134 sglq_entry->sgl = sglq_entry->virt;
4135 memset(sglq_entry->sgl, 0,
4136 phba->cfg_sg_dma_buf_size);
4137 sglq_entry->state = SGL_FREED;
4138 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4140 spin_lock_irq(&phba->hbalock);
4141 spin_lock(&phba->sli4_hba.sgl_list_lock);
4142 list_splice_init(&nvmet_sgl_list,
4143 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4144 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4145 spin_unlock_irq(&phba->hbalock);
4146 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4147 /* nvmet xri-sgl shrunk */
4148 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4149 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4150 "6305 NVMET xri-sgl count decreased from "
4151 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4153 spin_lock_irq(&phba->hbalock);
4154 spin_lock(&phba->sli4_hba.sgl_list_lock);
4155 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4157 /* release extra nvmet sgls from list */
4158 for (i = 0; i < xri_cnt; i++) {
4159 list_remove_head(&nvmet_sgl_list,
4160 sglq_entry, struct lpfc_sglq, list);
4162 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4167 list_splice_init(&nvmet_sgl_list,
4168 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4169 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4170 spin_unlock_irq(&phba->hbalock);
4172 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4173 "6306 NVMET xri-sgl count unchanged: %d\n",
4175 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4177 /* update xris to nvmet sgls on the list */
4179 sglq_entry_next = NULL;
4180 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4181 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4182 lxri = lpfc_sli4_next_xritag(phba);
4183 if (lxri == NO_XRI) {
4184 lpfc_printf_log(phba, KERN_ERR,
4186 "6307 Failed to allocate xri for "
4191 sglq_entry->sli4_lxritag = lxri;
4192 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4197 lpfc_free_nvmet_sgl_list(phba);
4202 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4205 struct lpfc_sli4_hdw_queue *qp;
4206 struct lpfc_io_buf *lpfc_cmd;
4207 struct lpfc_io_buf *iobufp, *prev_iobufp;
4208 int idx, cnt, xri, inserted;
4211 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4212 qp = &phba->sli4_hba.hdwq[idx];
4213 spin_lock_irq(&qp->io_buf_list_get_lock);
4214 spin_lock(&qp->io_buf_list_put_lock);
4216 /* Take everything off the get and put lists */
4217 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4218 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4219 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4220 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4221 cnt += qp->get_io_bufs + qp->put_io_bufs;
4222 qp->get_io_bufs = 0;
4223 qp->put_io_bufs = 0;
4224 qp->total_io_bufs = 0;
4225 spin_unlock(&qp->io_buf_list_put_lock);
4226 spin_unlock_irq(&qp->io_buf_list_get_lock);
4230 * Take IO buffers off blist and put on cbuf sorted by XRI.
4231 * This is because POST_SGL takes a sequential range of XRIs
4232 * to post to the firmware.
4234 for (idx = 0; idx < cnt; idx++) {
4235 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
4239 list_add_tail(&lpfc_cmd->list, cbuf);
4242 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4245 list_for_each_entry(iobufp, cbuf, list) {
4246 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4248 list_add(&lpfc_cmd->list,
4249 &prev_iobufp->list);
4251 list_add(&lpfc_cmd->list, cbuf);
4255 prev_iobufp = iobufp;
4258 list_add_tail(&lpfc_cmd->list, cbuf);
4264 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4266 struct lpfc_sli4_hdw_queue *qp;
4267 struct lpfc_io_buf *lpfc_cmd;
4270 qp = phba->sli4_hba.hdwq;
4272 while (!list_empty(cbuf)) {
4273 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4274 list_remove_head(cbuf, lpfc_cmd,
4275 struct lpfc_io_buf, list);
4279 qp = &phba->sli4_hba.hdwq[idx];
4280 lpfc_cmd->hdwq_no = idx;
4281 lpfc_cmd->hdwq = qp;
4282 lpfc_cmd->cur_iocbq.cmd_cmpl = NULL;
4283 spin_lock(&qp->io_buf_list_put_lock);
4284 list_add_tail(&lpfc_cmd->list,
4285 &qp->lpfc_io_buf_list_put);
4287 qp->total_io_bufs++;
4288 spin_unlock(&qp->io_buf_list_put_lock);
4295 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4296 * @phba: pointer to lpfc hba data structure.
4298 * This routine first calculates the sizes of the current els and allocated
4299 * scsi sgl lists, and then goes through all sgls to updates the physical
4300 * XRIs assigned due to port function reset. During port initialization, the
4301 * current els and allocated scsi sgl lists are 0s.
4304 * 0 - successful (for now, it always returns 0)
4307 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
4309 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
4310 uint16_t i, lxri, els_xri_cnt;
4311 uint16_t io_xri_cnt, io_xri_max;
4312 LIST_HEAD(io_sgl_list);
4316 * update on pci function's allocated nvme xri-sgl list
4319 /* maximum number of xris available for nvme buffers */
4320 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4321 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4322 phba->sli4_hba.io_xri_max = io_xri_max;
4324 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4325 "6074 Current allocated XRI sgl count:%d, "
4326 "maximum XRI count:%d els_xri_cnt:%d\n\n",
4327 phba->sli4_hba.io_xri_cnt,
4328 phba->sli4_hba.io_xri_max,
4331 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4333 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4334 /* max nvme xri shrunk below the allocated nvme buffers */
4335 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4336 phba->sli4_hba.io_xri_max;
4337 /* release the extra allocated nvme buffers */
4338 for (i = 0; i < io_xri_cnt; i++) {
4339 list_remove_head(&io_sgl_list, lpfc_ncmd,
4340 struct lpfc_io_buf, list);
4342 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4344 lpfc_ncmd->dma_handle);
4348 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4351 /* update xris associated to remaining allocated nvme buffers */
4353 lpfc_ncmd_next = NULL;
4354 phba->sli4_hba.io_xri_cnt = cnt;
4355 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4356 &io_sgl_list, list) {
4357 lxri = lpfc_sli4_next_xritag(phba);
4358 if (lxri == NO_XRI) {
4359 lpfc_printf_log(phba, KERN_ERR,
4361 "6075 Failed to allocate xri for "
4366 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4367 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4369 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4378 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4379 * @phba: Pointer to lpfc hba data structure.
4380 * @num_to_alloc: The requested number of buffers to allocate.
4382 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4383 * the nvme buffer contains all the necessary information needed to initiate
4384 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4385 * them on a list, it post them to the port by using SGL block post.
4388 * int - number of IO buffers that were allocated and posted.
4389 * 0 = failure, less than num_to_alloc is a partial failure.
4392 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4394 struct lpfc_io_buf *lpfc_ncmd;
4395 struct lpfc_iocbq *pwqeq;
4396 uint16_t iotag, lxri = 0;
4397 int bcnt, num_posted;
4398 LIST_HEAD(prep_nblist);
4399 LIST_HEAD(post_nblist);
4400 LIST_HEAD(nvme_nblist);
4402 phba->sli4_hba.io_xri_cnt = 0;
4403 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4404 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4408 * Get memory from the pci pool to map the virt space to
4409 * pci bus space for an I/O. The DMA buffer includes the
4410 * number of SGE's necessary to support the sg_tablesize.
4412 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4414 &lpfc_ncmd->dma_handle);
4415 if (!lpfc_ncmd->data) {
4420 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4421 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4424 * 4K Page alignment is CRITICAL to BlockGuard, double
4427 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4428 (((unsigned long)(lpfc_ncmd->data) &
4429 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4430 lpfc_printf_log(phba, KERN_ERR,
4432 "3369 Memory alignment err: "
4434 (unsigned long)lpfc_ncmd->data);
4435 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4437 lpfc_ncmd->dma_handle);
4443 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4445 lxri = lpfc_sli4_next_xritag(phba);
4446 if (lxri == NO_XRI) {
4447 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4448 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4452 pwqeq = &lpfc_ncmd->cur_iocbq;
4454 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4455 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4457 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4458 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4460 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4461 "6121 Failed to allocate IOTAG for"
4462 " XRI:0x%x\n", lxri);
4463 lpfc_sli4_free_xri(phba, lxri);
4466 pwqeq->sli4_lxritag = lxri;
4467 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4469 /* Initialize local short-hand pointers. */
4470 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4471 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4472 lpfc_ncmd->cur_iocbq.io_buf = lpfc_ncmd;
4473 spin_lock_init(&lpfc_ncmd->buf_lock);
4475 /* add the nvme buffer to a post list */
4476 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4477 phba->sli4_hba.io_xri_cnt++;
4479 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4480 "6114 Allocate %d out of %d requested new NVME "
4481 "buffers of size x%zu bytes\n", bcnt, num_to_alloc,
4482 sizeof(*lpfc_ncmd));
4485 /* post the list of nvme buffer sgls to port if available */
4486 if (!list_empty(&post_nblist))
4487 num_posted = lpfc_sli4_post_io_sgl_list(
4488 phba, &post_nblist, bcnt);
4496 lpfc_get_wwpn(struct lpfc_hba *phba)
4500 LPFC_MBOXQ_t *mboxq;
4503 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4506 return (uint64_t)-1;
4508 /* First get WWN of HBA instance */
4509 lpfc_read_nv(phba, mboxq);
4510 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4511 if (rc != MBX_SUCCESS) {
4512 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4513 "6019 Mailbox failed , mbxCmd x%x "
4514 "READ_NV, mbxStatus x%x\n",
4515 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4516 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4517 mempool_free(mboxq, phba->mbox_mem_pool);
4518 return (uint64_t) -1;
4521 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4522 /* wwn is WWPN of HBA instance */
4523 mempool_free(mboxq, phba->mbox_mem_pool);
4524 if (phba->sli_rev == LPFC_SLI_REV4)
4525 return be64_to_cpu(wwn);
4527 return rol64(wwn, 32);
4531 * lpfc_vmid_res_alloc - Allocates resources for VMID
4532 * @phba: pointer to lpfc hba data structure.
4533 * @vport: pointer to vport data structure
4535 * This routine allocated the resources needed for the VMID.
4542 lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4544 /* VMID feature is supported only on SLI4 */
4545 if (phba->sli_rev == LPFC_SLI_REV3) {
4546 phba->cfg_vmid_app_header = 0;
4547 phba->cfg_vmid_priority_tagging = 0;
4550 if (lpfc_is_vmid_enabled(phba)) {
4552 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4557 rwlock_init(&vport->vmid_lock);
4559 /* Set the VMID parameters for the vport */
4560 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4561 vport->vmid_inactivity_timeout =
4562 phba->cfg_vmid_inactivity_timeout;
4563 vport->max_vmid = phba->cfg_max_vmid;
4564 vport->cur_vmid_cnt = 0;
4566 vport->vmid_priority_range = bitmap_zalloc
4567 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4569 if (!vport->vmid_priority_range) {
4574 hash_init(vport->hash_table);
4580 * lpfc_create_port - Create an FC port
4581 * @phba: pointer to lpfc hba data structure.
4582 * @instance: a unique integer ID to this FC port.
4583 * @dev: pointer to the device data structure.
4585 * This routine creates a FC port for the upper layer protocol. The FC port
4586 * can be created on top of either a physical port or a virtual port provided
4587 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4588 * and associates the FC port created before adding the shost into the SCSI
4592 * @vport - pointer to the virtual N_Port data structure.
4593 * NULL - port create failed.
4596 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4598 struct lpfc_vport *vport;
4599 struct Scsi_Host *shost = NULL;
4600 struct scsi_host_template *template;
4604 bool use_no_reset_hba = false;
4607 if (lpfc_no_hba_reset_cnt) {
4608 if (phba->sli_rev < LPFC_SLI_REV4 &&
4609 dev == &phba->pcidev->dev) {
4610 /* Reset the port first */
4611 lpfc_sli_brdrestart(phba);
4612 rc = lpfc_sli_chipset_init(phba);
4616 wwn = lpfc_get_wwpn(phba);
4619 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4620 if (wwn == lpfc_no_hba_reset[i]) {
4621 lpfc_printf_log(phba, KERN_ERR,
4623 "6020 Setting use_no_reset port=%llx\n",
4625 use_no_reset_hba = true;
4630 /* Seed template for SCSI host registration */
4631 if (dev == &phba->pcidev->dev) {
4632 template = &phba->port_template;
4634 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4635 /* Seed physical port template */
4636 memcpy(template, &lpfc_template, sizeof(*template));
4638 if (use_no_reset_hba)
4639 /* template is for a no reset SCSI Host */
4640 template->eh_host_reset_handler = NULL;
4642 /* Template for all vports this physical port creates */
4643 memcpy(&phba->vport_template, &lpfc_template,
4645 phba->vport_template.shost_groups = lpfc_vport_groups;
4646 phba->vport_template.eh_bus_reset_handler = NULL;
4647 phba->vport_template.eh_host_reset_handler = NULL;
4648 phba->vport_template.vendor_id = 0;
4650 /* Initialize the host templates with updated value */
4651 if (phba->sli_rev == LPFC_SLI_REV4) {
4652 template->sg_tablesize = phba->cfg_scsi_seg_cnt;
4653 phba->vport_template.sg_tablesize =
4654 phba->cfg_scsi_seg_cnt;
4656 template->sg_tablesize = phba->cfg_sg_seg_cnt;
4657 phba->vport_template.sg_tablesize =
4658 phba->cfg_sg_seg_cnt;
4662 /* NVMET is for physical port only */
4663 memcpy(template, &lpfc_template_nvme,
4667 template = &phba->vport_template;
4670 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
4674 vport = (struct lpfc_vport *) shost->hostdata;
4676 vport->load_flag |= FC_LOADING;
4677 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4678 vport->fc_rscn_flush = 0;
4679 lpfc_get_vport_cfgparam(vport);
4681 /* Adjust value in vport */
4682 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4684 shost->unique_id = instance;
4685 shost->max_id = LPFC_MAX_TARGET;
4686 shost->max_lun = vport->cfg_max_luns;
4687 shost->this_id = -1;
4688 shost->max_cmd_len = 16;
4690 if (phba->sli_rev == LPFC_SLI_REV4) {
4691 if (!phba->cfg_fcp_mq_threshold ||
4692 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4693 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4695 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4696 phba->cfg_fcp_mq_threshold);
4698 shost->dma_boundary =
4699 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4701 if (phba->cfg_xpsgl && !phba->nvmet_support)
4702 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4704 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
4706 /* SLI-3 has a limited number of hardware queues (3),
4707 * thus there is only one for FCP processing.
4709 shost->nr_hw_queues = 1;
4712 * Set initial can_queue value since 0 is no longer supported and
4713 * scsi_add_host will fail. This will be adjusted later based on the
4714 * max xri value determined in hba setup.
4716 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4717 if (dev != &phba->pcidev->dev) {
4718 shost->transportt = lpfc_vport_transport_template;
4719 vport->port_type = LPFC_NPIV_PORT;
4721 shost->transportt = lpfc_transport_template;
4722 vport->port_type = LPFC_PHYSICAL_PORT;
4725 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4726 "9081 CreatePort TMPLATE type %x TBLsize %d "
4728 vport->port_type, shost->sg_tablesize,
4729 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4731 /* Allocate the resources for VMID */
4732 rc = lpfc_vmid_res_alloc(phba, vport);
4737 /* Initialize all internally managed lists. */
4738 INIT_LIST_HEAD(&vport->fc_nodes);
4739 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4740 spin_lock_init(&vport->work_port_lock);
4742 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4744 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4746 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4748 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4749 lpfc_setup_bg(phba, shost);
4751 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4755 spin_lock_irq(&phba->port_list_lock);
4756 list_add_tail(&vport->listentry, &phba->port_list);
4757 spin_unlock_irq(&phba->port_list_lock);
4762 bitmap_free(vport->vmid_priority_range);
4763 scsi_host_put(shost);
4769 * destroy_port - destroy an FC port
4770 * @vport: pointer to an lpfc virtual N_Port data structure.
4772 * This routine destroys a FC port from the upper layer protocol. All the
4773 * resources associated with the port are released.
4776 destroy_port(struct lpfc_vport *vport)
4778 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4779 struct lpfc_hba *phba = vport->phba;
4781 lpfc_debugfs_terminate(vport);
4782 fc_remove_host(shost);
4783 scsi_remove_host(shost);
4785 spin_lock_irq(&phba->port_list_lock);
4786 list_del_init(&vport->listentry);
4787 spin_unlock_irq(&phba->port_list_lock);
4789 lpfc_cleanup(vport);
4794 * lpfc_get_instance - Get a unique integer ID
4796 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4797 * uses the kernel idr facility to perform the task.
4800 * instance - a unique integer ID allocated as the new instance.
4801 * -1 - lpfc get instance failed.
4804 lpfc_get_instance(void)
4808 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4809 return ret < 0 ? -1 : ret;
4813 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4814 * @shost: pointer to SCSI host data structure.
4815 * @time: elapsed time of the scan in jiffies.
4817 * This routine is called by the SCSI layer with a SCSI host to determine
4818 * whether the scan host is finished.
4820 * Note: there is no scan_start function as adapter initialization will have
4821 * asynchronously kicked off the link initialization.
4824 * 0 - SCSI host scan is not over yet.
4825 * 1 - SCSI host scan is over.
4827 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4829 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4830 struct lpfc_hba *phba = vport->phba;
4833 spin_lock_irq(shost->host_lock);
4835 if (vport->load_flag & FC_UNLOADING) {
4839 if (time >= msecs_to_jiffies(30 * 1000)) {
4840 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4841 "0461 Scanning longer than 30 "
4842 "seconds. Continuing initialization\n");
4846 if (time >= msecs_to_jiffies(15 * 1000) &&
4847 phba->link_state <= LPFC_LINK_DOWN) {
4848 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4849 "0465 Link down longer than 15 "
4850 "seconds. Continuing initialization\n");
4855 if (vport->port_state != LPFC_VPORT_READY)
4857 if (vport->num_disc_nodes || vport->fc_prli_sent)
4859 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4861 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4867 spin_unlock_irq(shost->host_lock);
4871 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4873 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4874 struct lpfc_hba *phba = vport->phba;
4876 fc_host_supported_speeds(shost) = 0;
4878 * Avoid reporting supported link speed for FCoE as it can't be
4879 * controlled via FCoE.
4881 if (phba->hba_flag & HBA_FCOE_MODE)
4884 if (phba->lmt & LMT_256Gb)
4885 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
4886 if (phba->lmt & LMT_128Gb)
4887 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4888 if (phba->lmt & LMT_64Gb)
4889 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4890 if (phba->lmt & LMT_32Gb)
4891 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4892 if (phba->lmt & LMT_16Gb)
4893 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4894 if (phba->lmt & LMT_10Gb)
4895 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4896 if (phba->lmt & LMT_8Gb)
4897 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4898 if (phba->lmt & LMT_4Gb)
4899 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4900 if (phba->lmt & LMT_2Gb)
4901 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4902 if (phba->lmt & LMT_1Gb)
4903 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4907 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4908 * @shost: pointer to SCSI host data structure.
4910 * This routine initializes a given SCSI host attributes on a FC port. The
4911 * SCSI host can be either on top of a physical port or a virtual port.
4913 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4916 struct lpfc_hba *phba = vport->phba;
4918 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4921 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4922 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4923 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4925 memset(fc_host_supported_fc4s(shost), 0,
4926 sizeof(fc_host_supported_fc4s(shost)));
4927 fc_host_supported_fc4s(shost)[2] = 1;
4928 fc_host_supported_fc4s(shost)[7] = 1;
4930 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4931 sizeof fc_host_symbolic_name(shost));
4933 lpfc_host_supported_speeds_set(shost);
4935 fc_host_maxframe_size(shost) =
4936 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4937 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4939 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4941 /* This value is also unchanging */
4942 memset(fc_host_active_fc4s(shost), 0,
4943 sizeof(fc_host_active_fc4s(shost)));
4944 fc_host_active_fc4s(shost)[2] = 1;
4945 fc_host_active_fc4s(shost)[7] = 1;
4947 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4948 spin_lock_irq(shost->host_lock);
4949 vport->load_flag &= ~FC_LOADING;
4950 spin_unlock_irq(shost->host_lock);
4954 * lpfc_stop_port_s3 - Stop SLI3 device port
4955 * @phba: pointer to lpfc hba data structure.
4957 * This routine is invoked to stop an SLI3 device port, it stops the device
4958 * from generating interrupts and stops the device driver's timers for the
4962 lpfc_stop_port_s3(struct lpfc_hba *phba)
4964 /* Clear all interrupt enable conditions */
4965 writel(0, phba->HCregaddr);
4966 readl(phba->HCregaddr); /* flush */
4967 /* Clear all pending interrupts */
4968 writel(0xffffffff, phba->HAregaddr);
4969 readl(phba->HAregaddr); /* flush */
4971 /* Reset some HBA SLI setup states */
4972 lpfc_stop_hba_timers(phba);
4973 phba->pport->work_port_events = 0;
4977 * lpfc_stop_port_s4 - Stop SLI4 device port
4978 * @phba: pointer to lpfc hba data structure.
4980 * This routine is invoked to stop an SLI4 device port, it stops the device
4981 * from generating interrupts and stops the device driver's timers for the
4985 lpfc_stop_port_s4(struct lpfc_hba *phba)
4987 /* Reset some HBA SLI4 setup states */
4988 lpfc_stop_hba_timers(phba);
4990 phba->pport->work_port_events = 0;
4991 phba->sli4_hba.intr_enable = 0;
4995 * lpfc_stop_port - Wrapper function for stopping hba port
4996 * @phba: Pointer to HBA context object.
4998 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4999 * the API jump table function pointer from the lpfc_hba struct.
5002 lpfc_stop_port(struct lpfc_hba *phba)
5004 phba->lpfc_stop_port(phba);
5007 flush_workqueue(phba->wq);
5011 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
5012 * @phba: Pointer to hba for which this call is being executed.
5014 * This routine starts the timer waiting for the FCF rediscovery to complete.
5017 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
5019 unsigned long fcf_redisc_wait_tmo =
5020 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
5021 /* Start fcf rediscovery wait period timer */
5022 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
5023 spin_lock_irq(&phba->hbalock);
5024 /* Allow action to new fcf asynchronous event */
5025 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
5026 /* Mark the FCF rediscovery pending state */
5027 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
5028 spin_unlock_irq(&phba->hbalock);
5032 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
5033 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5035 * This routine is invoked when waiting for FCF table rediscover has been
5036 * timed out. If new FCF record(s) has (have) been discovered during the
5037 * wait period, a new FCF event shall be added to the FCOE async event
5038 * list, and then worker thread shall be waked up for processing from the
5039 * worker thread context.
5042 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
5044 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
5046 /* Don't send FCF rediscovery event if timer cancelled */
5047 spin_lock_irq(&phba->hbalock);
5048 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
5049 spin_unlock_irq(&phba->hbalock);
5052 /* Clear FCF rediscovery timer pending flag */
5053 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
5054 /* FCF rediscovery event to worker thread */
5055 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
5056 spin_unlock_irq(&phba->hbalock);
5057 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
5058 "2776 FCF rediscover quiescent timer expired\n");
5059 /* wake up worker thread */
5060 lpfc_worker_wake_up(phba);
5064 * lpfc_vmid_poll - VMID timeout detection
5065 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5067 * This routine is invoked when there is no I/O on by a VM for the specified
5068 * amount of time. When this situation is detected, the VMID has to be
5069 * deregistered from the switch and all the local resources freed. The VMID
5070 * will be reassigned to the VM once the I/O begins.
5073 lpfc_vmid_poll(struct timer_list *t)
5075 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
5078 /* check if there is a need to issue QFPA */
5079 if (phba->pport->vmid_priority_tagging) {
5081 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5084 /* Is the vmid inactivity timer enabled */
5085 if (phba->pport->vmid_inactivity_timeout ||
5086 phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
5088 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5092 lpfc_worker_wake_up(phba);
5094 /* restart the timer for the next iteration */
5095 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5100 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5101 * @phba: pointer to lpfc hba data structure.
5102 * @acqe_link: pointer to the async link completion queue entry.
5104 * This routine is to parse the SLI4 link-attention link fault code.
5107 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5108 struct lpfc_acqe_link *acqe_link)
5110 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5111 case LPFC_ASYNC_LINK_FAULT_NONE:
5112 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5113 case LPFC_ASYNC_LINK_FAULT_REMOTE:
5114 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
5117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5118 "0398 Unknown link fault code: x%x\n",
5119 bf_get(lpfc_acqe_link_fault, acqe_link));
5125 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5126 * @phba: pointer to lpfc hba data structure.
5127 * @acqe_link: pointer to the async link completion queue entry.
5129 * This routine is to parse the SLI4 link attention type and translate it
5130 * into the base driver's link attention type coding.
5132 * Return: Link attention type in terms of base driver's coding.
5135 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5136 struct lpfc_acqe_link *acqe_link)
5140 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5141 case LPFC_ASYNC_LINK_STATUS_DOWN:
5142 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
5143 att_type = LPFC_ATT_LINK_DOWN;
5145 case LPFC_ASYNC_LINK_STATUS_UP:
5146 /* Ignore physical link up events - wait for logical link up */
5147 att_type = LPFC_ATT_RESERVED;
5149 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
5150 att_type = LPFC_ATT_LINK_UP;
5153 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5154 "0399 Invalid link attention type: x%x\n",
5155 bf_get(lpfc_acqe_link_status, acqe_link));
5156 att_type = LPFC_ATT_RESERVED;
5163 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5164 * @phba: pointer to lpfc hba data structure.
5166 * This routine is to get an SLI3 FC port's link speed in Mbps.
5168 * Return: link speed in terms of Mbps.
5171 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5173 uint32_t link_speed;
5175 if (!lpfc_is_link_up(phba))
5178 if (phba->sli_rev <= LPFC_SLI_REV3) {
5179 switch (phba->fc_linkspeed) {
5180 case LPFC_LINK_SPEED_1GHZ:
5183 case LPFC_LINK_SPEED_2GHZ:
5186 case LPFC_LINK_SPEED_4GHZ:
5189 case LPFC_LINK_SPEED_8GHZ:
5192 case LPFC_LINK_SPEED_10GHZ:
5195 case LPFC_LINK_SPEED_16GHZ:
5202 if (phba->sli4_hba.link_state.logical_speed)
5204 phba->sli4_hba.link_state.logical_speed;
5206 link_speed = phba->sli4_hba.link_state.speed;
5212 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5213 * @phba: pointer to lpfc hba data structure.
5214 * @evt_code: asynchronous event code.
5215 * @speed_code: asynchronous event link speed code.
5217 * This routine is to parse the giving SLI4 async event link speed code into
5218 * value of Mbps for the link speed.
5220 * Return: link speed in terms of Mbps.
5223 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5226 uint32_t port_speed;
5229 case LPFC_TRAILER_CODE_LINK:
5230 switch (speed_code) {
5231 case LPFC_ASYNC_LINK_SPEED_ZERO:
5234 case LPFC_ASYNC_LINK_SPEED_10MBPS:
5237 case LPFC_ASYNC_LINK_SPEED_100MBPS:
5240 case LPFC_ASYNC_LINK_SPEED_1GBPS:
5243 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5246 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5249 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5252 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5255 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5256 port_speed = 100000;
5262 case LPFC_TRAILER_CODE_FC:
5263 switch (speed_code) {
5264 case LPFC_FC_LA_SPEED_UNKNOWN:
5267 case LPFC_FC_LA_SPEED_1G:
5270 case LPFC_FC_LA_SPEED_2G:
5273 case LPFC_FC_LA_SPEED_4G:
5276 case LPFC_FC_LA_SPEED_8G:
5279 case LPFC_FC_LA_SPEED_10G:
5282 case LPFC_FC_LA_SPEED_16G:
5285 case LPFC_FC_LA_SPEED_32G:
5288 case LPFC_FC_LA_SPEED_64G:
5291 case LPFC_FC_LA_SPEED_128G:
5292 port_speed = 128000;
5294 case LPFC_FC_LA_SPEED_256G:
5295 port_speed = 256000;
5308 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
5309 * @phba: pointer to lpfc hba data structure.
5310 * @acqe_link: pointer to the async link completion queue entry.
5312 * This routine is to handle the SLI4 asynchronous FCoE link event.
5315 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5316 struct lpfc_acqe_link *acqe_link)
5320 struct lpfc_mbx_read_top *la;
5324 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
5325 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
5327 phba->fcoe_eventtag = acqe_link->event_tag;
5328 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5330 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5331 "0395 The mboxq allocation failed\n");
5335 rc = lpfc_mbox_rsrc_prep(phba, pmb);
5337 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5338 "0396 mailbox allocation failed\n");
5342 /* Cleanup any outstanding ELS commands */
5343 lpfc_els_flush_all_cmd(phba);
5345 /* Block ELS IOCBs until we have done process link event */
5346 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5348 /* Update link event statistics */
5349 phba->sli.slistat.link_event++;
5351 /* Create lpfc_handle_latt mailbox command from link ACQE */
5352 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
5353 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5354 pmb->vport = phba->pport;
5356 /* Keep the link status for extra SLI4 state machine reference */
5357 phba->sli4_hba.link_state.speed =
5358 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5359 bf_get(lpfc_acqe_link_speed, acqe_link));
5360 phba->sli4_hba.link_state.duplex =
5361 bf_get(lpfc_acqe_link_duplex, acqe_link);
5362 phba->sli4_hba.link_state.status =
5363 bf_get(lpfc_acqe_link_status, acqe_link);
5364 phba->sli4_hba.link_state.type =
5365 bf_get(lpfc_acqe_link_type, acqe_link);
5366 phba->sli4_hba.link_state.number =
5367 bf_get(lpfc_acqe_link_number, acqe_link);
5368 phba->sli4_hba.link_state.fault =
5369 bf_get(lpfc_acqe_link_fault, acqe_link);
5370 phba->sli4_hba.link_state.logical_speed =
5371 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5373 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5374 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5375 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5376 "Logical speed:%dMbps Fault:%d\n",
5377 phba->sli4_hba.link_state.speed,
5378 phba->sli4_hba.link_state.topology,
5379 phba->sli4_hba.link_state.status,
5380 phba->sli4_hba.link_state.type,
5381 phba->sli4_hba.link_state.number,
5382 phba->sli4_hba.link_state.logical_speed,
5383 phba->sli4_hba.link_state.fault);
5385 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5386 * topology info. Note: Optional for non FC-AL ports.
5388 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5389 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5390 if (rc == MBX_NOT_FINISHED)
5395 * For FCoE Mode: fill in all the topology information we need and call
5396 * the READ_TOPOLOGY completion routine to continue without actually
5397 * sending the READ_TOPOLOGY mailbox command to the port.
5399 /* Initialize completion status */
5401 mb->mbxStatus = MBX_SUCCESS;
5403 /* Parse port fault information field */
5404 lpfc_sli4_parse_latt_fault(phba, acqe_link);
5406 /* Parse and translate link attention fields */
5407 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5408 la->eventTag = acqe_link->event_tag;
5409 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5410 bf_set(lpfc_mbx_read_top_link_spd, la,
5411 (bf_get(lpfc_acqe_link_speed, acqe_link)));
5413 /* Fake the the following irrelvant fields */
5414 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5415 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5416 bf_set(lpfc_mbx_read_top_il, la, 0);
5417 bf_set(lpfc_mbx_read_top_pb, la, 0);
5418 bf_set(lpfc_mbx_read_top_fa, la, 0);
5419 bf_set(lpfc_mbx_read_top_mm, la, 0);
5421 /* Invoke the lpfc_handle_latt mailbox command callback function */
5422 lpfc_mbx_cmpl_read_topology(phba, pmb);
5427 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5431 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5433 * @phba: pointer to lpfc hba data structure.
5434 * @speed_code: asynchronous event link speed code.
5436 * This routine is to parse the giving SLI4 async event link speed code into
5437 * value of Read topology link speed.
5439 * Return: link speed in terms of Read topology.
5442 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5446 switch (speed_code) {
5447 case LPFC_FC_LA_SPEED_1G:
5448 port_speed = LPFC_LINK_SPEED_1GHZ;
5450 case LPFC_FC_LA_SPEED_2G:
5451 port_speed = LPFC_LINK_SPEED_2GHZ;
5453 case LPFC_FC_LA_SPEED_4G:
5454 port_speed = LPFC_LINK_SPEED_4GHZ;
5456 case LPFC_FC_LA_SPEED_8G:
5457 port_speed = LPFC_LINK_SPEED_8GHZ;
5459 case LPFC_FC_LA_SPEED_16G:
5460 port_speed = LPFC_LINK_SPEED_16GHZ;
5462 case LPFC_FC_LA_SPEED_32G:
5463 port_speed = LPFC_LINK_SPEED_32GHZ;
5465 case LPFC_FC_LA_SPEED_64G:
5466 port_speed = LPFC_LINK_SPEED_64GHZ;
5468 case LPFC_FC_LA_SPEED_128G:
5469 port_speed = LPFC_LINK_SPEED_128GHZ;
5471 case LPFC_FC_LA_SPEED_256G:
5472 port_speed = LPFC_LINK_SPEED_256GHZ;
5483 lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
5485 struct rxtable_entry *entry;
5486 int cnt = 0, head, tail, last, start;
5488 head = atomic_read(&phba->rxtable_idx_head);
5489 tail = atomic_read(&phba->rxtable_idx_tail);
5490 if (!phba->rxtable || head == tail) {
5491 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
5492 "4411 Rxtable is empty\n");
5498 /* Display the last LPFC_MAX_RXMONITOR_DUMP entries from the rxtable */
5499 while (start != last) {
5503 start = LPFC_MAX_RXMONITOR_ENTRY - 1;
5504 entry = &phba->rxtable[start];
5505 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5506 "4410 %02d: MBPI %lld Xmit %lld Cmpl %lld "
5507 "Lat %lld ASz %lld Info %02d BWUtil %d "
5509 cnt, entry->max_bytes_per_interval,
5510 entry->total_bytes, entry->rcv_bytes,
5511 entry->avg_io_latency, entry->avg_io_size,
5512 entry->cmf_info, entry->timer_utilization,
5513 entry->timer_interval, start);
5515 if (cnt >= LPFC_MAX_RXMONITOR_DUMP)
5521 * lpfc_cgn_update_stat - Save data into congestion stats buffer
5522 * @phba: pointer to lpfc hba data structure.
5523 * @dtag: FPIN descriptor received
5525 * Increment the FPIN received counter/time when it happens.
5528 lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
5530 struct lpfc_cgn_info *cp;
5532 struct timespec64 cur_time;
5536 /* Make sure we have a congestion info buffer */
5539 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5540 ktime_get_real_ts64(&cur_time);
5541 time64_to_tm(cur_time.tv_sec, 0, &broken);
5543 /* Update congestion statistics */
5545 case ELS_DTAG_LNK_INTEGRITY:
5546 cnt = le32_to_cpu(cp->link_integ_notification);
5548 cp->link_integ_notification = cpu_to_le32(cnt);
5550 cp->cgn_stat_lnk_month = broken.tm_mon + 1;
5551 cp->cgn_stat_lnk_day = broken.tm_mday;
5552 cp->cgn_stat_lnk_year = broken.tm_year - 100;
5553 cp->cgn_stat_lnk_hour = broken.tm_hour;
5554 cp->cgn_stat_lnk_min = broken.tm_min;
5555 cp->cgn_stat_lnk_sec = broken.tm_sec;
5557 case ELS_DTAG_DELIVERY:
5558 cnt = le32_to_cpu(cp->delivery_notification);
5560 cp->delivery_notification = cpu_to_le32(cnt);
5562 cp->cgn_stat_del_month = broken.tm_mon + 1;
5563 cp->cgn_stat_del_day = broken.tm_mday;
5564 cp->cgn_stat_del_year = broken.tm_year - 100;
5565 cp->cgn_stat_del_hour = broken.tm_hour;
5566 cp->cgn_stat_del_min = broken.tm_min;
5567 cp->cgn_stat_del_sec = broken.tm_sec;
5569 case ELS_DTAG_PEER_CONGEST:
5570 cnt = le32_to_cpu(cp->cgn_peer_notification);
5572 cp->cgn_peer_notification = cpu_to_le32(cnt);
5574 cp->cgn_stat_peer_month = broken.tm_mon + 1;
5575 cp->cgn_stat_peer_day = broken.tm_mday;
5576 cp->cgn_stat_peer_year = broken.tm_year - 100;
5577 cp->cgn_stat_peer_hour = broken.tm_hour;
5578 cp->cgn_stat_peer_min = broken.tm_min;
5579 cp->cgn_stat_peer_sec = broken.tm_sec;
5581 case ELS_DTAG_CONGESTION:
5582 cnt = le32_to_cpu(cp->cgn_notification);
5584 cp->cgn_notification = cpu_to_le32(cnt);
5586 cp->cgn_stat_cgn_month = broken.tm_mon + 1;
5587 cp->cgn_stat_cgn_day = broken.tm_mday;
5588 cp->cgn_stat_cgn_year = broken.tm_year - 100;
5589 cp->cgn_stat_cgn_hour = broken.tm_hour;
5590 cp->cgn_stat_cgn_min = broken.tm_min;
5591 cp->cgn_stat_cgn_sec = broken.tm_sec;
5593 if (phba->cgn_fpin_frequency &&
5594 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5595 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5596 cp->cgn_stat_npm = value;
5598 value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5599 LPFC_CGN_CRC32_SEED);
5600 cp->cgn_info_crc = cpu_to_le32(value);
5604 * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer
5605 * @phba: pointer to lpfc hba data structure.
5607 * Save the congestion event data every minute.
5608 * On the hour collapse all the minute data into hour data. Every day
5609 * collapse all the hour data into daily data. Separate driver
5610 * and fabrc congestion event counters that will be saved out
5611 * to the registered congestion buffer every minute.
5614 lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba)
5616 struct lpfc_cgn_info *cp;
5618 struct timespec64 cur_time;
5620 uint16_t value, mvalue;
5623 uint32_t dvalue, wvalue, lvalue, avalue;
5629 /* Make sure we have a congestion info buffer */
5632 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5634 if (time_before(jiffies, phba->cgn_evt_timestamp))
5636 phba->cgn_evt_timestamp = jiffies +
5637 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
5638 phba->cgn_evt_minute++;
5640 /* We should get to this point in the routine on 1 minute intervals */
5642 ktime_get_real_ts64(&cur_time);
5643 time64_to_tm(cur_time.tv_sec, 0, &broken);
5645 if (phba->cgn_fpin_frequency &&
5646 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5647 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5648 cp->cgn_stat_npm = value;
5651 /* Read and clear the latency counters for this minute */
5652 lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
5653 latsum = atomic64_read(&phba->cgn_latency_evt);
5654 atomic_set(&phba->cgn_latency_evt_cnt, 0);
5655 atomic64_set(&phba->cgn_latency_evt, 0);
5657 /* We need to store MB/sec bandwidth in the congestion information.
5658 * block_cnt is count of 512 byte blocks for the entire minute,
5659 * bps will get bytes per sec before finally converting to MB/sec.
5661 bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
5662 phba->rx_block_cnt = 0;
5663 mvalue = bps / (1024 * 1024); /* convert to MB/sec */
5666 /* cgn parameters */
5667 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
5668 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
5669 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
5670 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
5672 /* Fill in default LUN qdepth */
5673 value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
5674 cp->cgn_lunq = cpu_to_le16(value);
5676 /* Record congestion buffer info - every minute
5677 * cgn_driver_evt_cnt (Driver events)
5678 * cgn_fabric_warn_cnt (Congestion Warnings)
5679 * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
5680 * cgn_fabric_alarm_cnt (Congestion Alarms)
5682 index = ++cp->cgn_index_minute;
5683 if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
5684 cp->cgn_index_minute = 0;
5688 /* Get the number of driver events in this sample and reset counter */
5689 dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
5690 atomic_set(&phba->cgn_driver_evt_cnt, 0);
5692 /* Get the number of warning events - FPIN and Signal for this minute */
5694 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
5695 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5696 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5697 wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
5698 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
5700 /* Get the number of alarm events - FPIN and Signal for this minute */
5702 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
5703 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5704 avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
5705 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
5707 /* Collect the driver, warning, alarm and latency counts for this
5708 * minute into the driver congestion buffer.
5710 ptr = &cp->cgn_drvr_min[index];
5711 value = (uint16_t)dvalue;
5712 *ptr = cpu_to_le16(value);
5714 ptr = &cp->cgn_warn_min[index];
5715 value = (uint16_t)wvalue;
5716 *ptr = cpu_to_le16(value);
5718 ptr = &cp->cgn_alarm_min[index];
5719 value = (uint16_t)avalue;
5720 *ptr = cpu_to_le16(value);
5722 lptr = &cp->cgn_latency_min[index];
5724 lvalue = (uint32_t)div_u64(latsum, lvalue);
5725 *lptr = cpu_to_le32(lvalue);
5730 /* Collect the bandwidth value into the driver's congesion buffer. */
5731 mptr = &cp->cgn_bw_min[index];
5732 *mptr = cpu_to_le16(mvalue);
5734 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5735 "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
5736 index, dvalue, wvalue, *lptr, mvalue, avalue);
5739 if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
5740 /* Record congestion buffer info - every hour
5741 * Collapse all minutes into an hour
5743 index = ++cp->cgn_index_hour;
5744 if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
5745 cp->cgn_index_hour = 0;
5755 for (i = 0; i < LPFC_MIN_HOUR; i++) {
5756 dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
5757 wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
5758 lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
5759 mbps += le16_to_cpu(cp->cgn_bw_min[i]);
5760 avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
5762 if (lvalue) /* Avg of latency averages */
5763 lvalue /= LPFC_MIN_HOUR;
5764 if (mbps) /* Avg of Bandwidth averages */
5765 mvalue = mbps / LPFC_MIN_HOUR;
5767 lptr = &cp->cgn_drvr_hr[index];
5768 *lptr = cpu_to_le32(dvalue);
5769 lptr = &cp->cgn_warn_hr[index];
5770 *lptr = cpu_to_le32(wvalue);
5771 lptr = &cp->cgn_latency_hr[index];
5772 *lptr = cpu_to_le32(lvalue);
5773 mptr = &cp->cgn_bw_hr[index];
5774 *mptr = cpu_to_le16(mvalue);
5775 lptr = &cp->cgn_alarm_hr[index];
5776 *lptr = cpu_to_le32(avalue);
5778 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5779 "2419 Congestion Info - hour "
5780 "(%d): %d %d %d %d %d\n",
5781 index, dvalue, wvalue, lvalue, mvalue, avalue);
5785 if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
5786 /* Record congestion buffer info - every hour
5787 * Collapse all hours into a day. Rotate days
5788 * after LPFC_MAX_CGN_DAYS.
5790 index = ++cp->cgn_index_day;
5791 if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
5792 cp->cgn_index_day = 0;
5796 /* Anytime we overwrite daily index 0, after we wrap,
5797 * we will be overwriting the oldest day, so we must
5798 * update the congestion data start time for that day.
5799 * That start time should have previously been saved after
5800 * we wrote the last days worth of data.
5802 if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) {
5803 time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken);
5805 cp->cgn_info_month = broken.tm_mon + 1;
5806 cp->cgn_info_day = broken.tm_mday;
5807 cp->cgn_info_year = broken.tm_year - 100;
5808 cp->cgn_info_hour = broken.tm_hour;
5809 cp->cgn_info_minute = broken.tm_min;
5810 cp->cgn_info_second = broken.tm_sec;
5813 (phba, KERN_INFO, LOG_CGN_MGMT,
5814 "2646 CGNInfo idx0 Start Time: "
5815 "%d/%d/%d %d:%d:%d\n",
5816 cp->cgn_info_day, cp->cgn_info_month,
5817 cp->cgn_info_year, cp->cgn_info_hour,
5818 cp->cgn_info_minute, cp->cgn_info_second);
5827 for (i = 0; i < LPFC_HOUR_DAY; i++) {
5828 dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
5829 wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
5830 lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
5831 mbps += le16_to_cpu(cp->cgn_bw_hr[i]);
5832 avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
5834 if (lvalue) /* Avg of latency averages */
5835 lvalue /= LPFC_HOUR_DAY;
5836 if (mbps) /* Avg of Bandwidth averages */
5837 mvalue = mbps / LPFC_HOUR_DAY;
5839 lptr = &cp->cgn_drvr_day[index];
5840 *lptr = cpu_to_le32(dvalue);
5841 lptr = &cp->cgn_warn_day[index];
5842 *lptr = cpu_to_le32(wvalue);
5843 lptr = &cp->cgn_latency_day[index];
5844 *lptr = cpu_to_le32(lvalue);
5845 mptr = &cp->cgn_bw_day[index];
5846 *mptr = cpu_to_le16(mvalue);
5847 lptr = &cp->cgn_alarm_day[index];
5848 *lptr = cpu_to_le32(avalue);
5850 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5851 "2420 Congestion Info - daily (%d): "
5853 index, dvalue, wvalue, lvalue, mvalue, avalue);
5855 /* We just wrote LPFC_MAX_CGN_DAYS of data,
5856 * so we are wrapped on any data after this.
5857 * Save this as the start time for the next day.
5859 if (index == (LPFC_MAX_CGN_DAYS - 1)) {
5860 phba->hba_flag |= HBA_CGN_DAY_WRAP;
5861 ktime_get_real_ts64(&phba->cgn_daily_ts);
5865 /* Use the frequency found in the last rcv'ed FPIN */
5866 value = phba->cgn_fpin_frequency;
5867 cp->cgn_warn_freq = cpu_to_le16(value);
5868 cp->cgn_alarm_freq = cpu_to_le16(value);
5870 lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5871 LPFC_CGN_CRC32_SEED);
5872 cp->cgn_info_crc = cpu_to_le32(lvalue);
5876 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5877 * @phba: The Hba for which this call is being executed.
5879 * The routine calculates the latency from the beginning of the CMF timer
5880 * interval to the current point in time. It is called from IO completion
5881 * when we exceed our Bandwidth limitation for the time interval.
5884 lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5886 struct timespec64 cmpl_time;
5889 ktime_get_real_ts64(&cmpl_time);
5891 /* This routine works on a ms granularity so sec and usec are
5892 * converted accordingly.
5894 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5895 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5898 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5899 msec = (cmpl_time.tv_sec -
5900 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5901 msec += ((cmpl_time.tv_nsec -
5902 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5904 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5906 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5907 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5914 * lpfc_cmf_timer - This is the timer function for one congestion
5916 * @timer: Pointer to the high resolution timer that expired
5918 static enum hrtimer_restart
5919 lpfc_cmf_timer(struct hrtimer *timer)
5921 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5923 struct rxtable_entry *entry;
5925 uint32_t head, tail;
5926 uint32_t busy, max_read;
5927 uint64_t total, rcv, lat, mbpi, extra, cnt;
5928 int timer_interval = LPFC_CMF_INTERVAL;
5930 struct lpfc_cgn_stat *cgs;
5933 /* Only restart the timer if congestion mgmt is on */
5934 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5935 !phba->cmf_latency.tv_sec) {
5936 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5937 "6224 CMF timer exit: %d %lld\n",
5938 phba->cmf_active_mode,
5939 (uint64_t)phba->cmf_latency.tv_sec);
5940 return HRTIMER_NORESTART;
5943 /* If pport is not ready yet, just exit and wait for
5944 * the next timer cycle to hit.
5949 /* Do not block SCSI IO while in the timer routine since
5950 * total_bytes will be cleared
5952 atomic_set(&phba->cmf_stop_io, 1);
5954 /* First we need to calculate the actual ms between
5955 * the last timer interrupt and this one. We ask for
5956 * LPFC_CMF_INTERVAL, however the actual time may
5957 * vary depending on system overhead.
5959 ms = lpfc_calc_cmf_latency(phba);
5962 /* Immediately after we calculate the time since the last
5963 * timer interrupt, set the start time for the next
5966 ktime_get_real_ts64(&phba->cmf_latency);
5968 phba->cmf_link_byte_count =
5969 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
5971 /* Collect all the stats from the prior timer interval */
5976 for_each_present_cpu(cpu) {
5977 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
5978 total += atomic64_xchg(&cgs->total_bytes, 0);
5979 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
5980 lat += atomic64_xchg(&cgs->rx_latency, 0);
5981 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
5984 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
5985 * returned from the last CMF_SYNC_WQE issued, from
5986 * cmf_last_sync_bw. This will be the target BW for
5987 * this next timer interval.
5989 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
5990 phba->link_state != LPFC_LINK_DOWN &&
5991 phba->hba_flag & HBA_SETUP) {
5992 mbpi = phba->cmf_last_sync_bw;
5993 phba->cmf_last_sync_bw = 0;
5996 /* Calculate any extra bytes needed to account for the
5997 * timer accuracy. If we are less than LPFC_CMF_INTERVAL
5998 * calculate the adjustment needed for total to reflect
5999 * a full LPFC_CMF_INTERVAL.
6001 if (ms && ms < LPFC_CMF_INTERVAL) {
6002 cnt = div_u64(total, ms); /* bytes per ms */
6003 cnt *= LPFC_CMF_INTERVAL; /* what total should be */
6005 /* If the timeout is scheduled to be shorter,
6006 * this value may skew the data, so cap it at mbpi.
6008 if ((phba->hba_flag & HBA_SHORT_CMF) && cnt > mbpi)
6011 extra = cnt - total;
6013 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
6015 /* For Monitor mode or link down we want mbpi
6016 * to be the full link speed
6018 mbpi = phba->cmf_link_byte_count;
6021 phba->cmf_timer_cnt++;
6024 /* Update congestion info buffer latency in us */
6025 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
6026 atomic64_add(lat, &phba->cgn_latency_evt);
6028 busy = atomic_xchg(&phba->cmf_busy, 0);
6029 max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
6031 /* Calculate MBPI for the next timer interval */
6033 if (mbpi > phba->cmf_link_byte_count ||
6034 phba->cmf_active_mode == LPFC_CFG_MONITOR)
6035 mbpi = phba->cmf_link_byte_count;
6037 /* Change max_bytes_per_interval to what the prior
6038 * CMF_SYNC_WQE cmpl indicated.
6040 if (mbpi != phba->cmf_max_bytes_per_interval)
6041 phba->cmf_max_bytes_per_interval = mbpi;
6044 /* Save rxmonitor information for debug */
6045 if (phba->rxtable) {
6046 head = atomic_xchg(&phba->rxtable_idx_head,
6047 LPFC_RXMONITOR_TABLE_IN_USE);
6048 entry = &phba->rxtable[head];
6049 entry->total_bytes = total;
6050 entry->cmf_bytes = total + extra;
6051 entry->rcv_bytes = rcv;
6052 entry->cmf_busy = busy;
6053 entry->cmf_info = phba->cmf_active_info;
6055 entry->avg_io_latency = div_u64(lat, io_cnt);
6056 entry->avg_io_size = div_u64(rcv, io_cnt);
6058 entry->avg_io_latency = 0;
6059 entry->avg_io_size = 0;
6061 entry->max_read_cnt = max_read;
6062 entry->io_cnt = io_cnt;
6063 entry->max_bytes_per_interval = mbpi;
6064 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
6065 entry->timer_utilization = phba->cmf_last_ts;
6067 entry->timer_utilization = ms;
6068 entry->timer_interval = ms;
6069 phba->cmf_last_ts = 0;
6071 /* Increment rxtable index */
6072 head = (head + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6073 tail = atomic_read(&phba->rxtable_idx_tail);
6075 tail = (tail + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6076 atomic_set(&phba->rxtable_idx_tail, tail);
6078 atomic_set(&phba->rxtable_idx_head, head);
6081 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
6082 /* If Monitor mode, check if we are oversubscribed
6083 * against the full line rate.
6085 if (mbpi && total > mbpi)
6086 atomic_inc(&phba->cgn_driver_evt_cnt);
6088 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
6090 /* Each minute save Fabric and Driver congestion information */
6091 lpfc_cgn_save_evt_cnt(phba);
6093 phba->hba_flag &= ~HBA_SHORT_CMF;
6095 /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the
6096 * minute, adjust our next timer interval, if needed, to ensure a
6097 * 1 minute granularity when we get the next timer interrupt.
6099 if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL),
6100 phba->cgn_evt_timestamp)) {
6101 timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp -
6103 if (timer_interval <= 0)
6104 timer_interval = LPFC_CMF_INTERVAL;
6106 phba->hba_flag |= HBA_SHORT_CMF;
6108 /* If we adjust timer_interval, max_bytes_per_interval
6109 * needs to be adjusted as well.
6111 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
6112 timer_interval, 1000);
6113 if (phba->cmf_active_mode == LPFC_CFG_MONITOR)
6114 phba->cmf_max_bytes_per_interval =
6115 phba->cmf_link_byte_count;
6118 /* Since total_bytes has already been zero'ed, its okay to unblock
6119 * after max_bytes_per_interval is setup.
6121 if (atomic_xchg(&phba->cmf_bw_wait, 0))
6122 queue_work(phba->wq, &phba->unblock_request_work);
6124 /* SCSI IO is now unblocked */
6125 atomic_set(&phba->cmf_stop_io, 0);
6128 hrtimer_forward_now(timer,
6129 ktime_set(0, timer_interval * NSEC_PER_MSEC));
6130 return HRTIMER_RESTART;
6133 #define trunk_link_status(__idx)\
6134 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6135 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
6136 "Link up" : "Link down") : "NA"
6137 /* Did port __idx reported an error */
6138 #define trunk_port_fault(__idx)\
6139 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6140 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
6143 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
6144 struct lpfc_acqe_fc_la *acqe_fc)
6146 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
6147 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
6149 phba->sli4_hba.link_state.speed =
6150 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6151 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6153 phba->sli4_hba.link_state.logical_speed =
6154 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6155 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
6156 phba->fc_linkspeed =
6157 lpfc_async_link_speed_to_read_top(
6159 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6161 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
6162 phba->trunk_link.link0.state =
6163 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
6164 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6165 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
6167 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
6168 phba->trunk_link.link1.state =
6169 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
6170 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6171 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
6173 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
6174 phba->trunk_link.link2.state =
6175 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
6176 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6177 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
6179 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
6180 phba->trunk_link.link3.state =
6181 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
6182 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6183 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
6186 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6187 "2910 Async FC Trunking Event - Speed:%d\n"
6188 "\tLogical speed:%d "
6189 "port0: %s port1: %s port2: %s port3: %s\n",
6190 phba->sli4_hba.link_state.speed,
6191 phba->sli4_hba.link_state.logical_speed,
6192 trunk_link_status(0), trunk_link_status(1),
6193 trunk_link_status(2), trunk_link_status(3));
6195 if (phba->cmf_active_mode != LPFC_CFG_OFF)
6196 lpfc_cmf_signal_init(phba);
6199 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6200 "3202 trunk error:0x%x (%s) seen on port0:%s "
6202 * SLI-4: We have only 0xA error codes
6203 * defined as of now. print an appropriate
6204 * message in case driver needs to be updated.
6206 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
6207 "UNDEFINED. update driver." : trunk_errmsg[err],
6208 trunk_port_fault(0), trunk_port_fault(1),
6209 trunk_port_fault(2), trunk_port_fault(3));
6214 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
6215 * @phba: pointer to lpfc hba data structure.
6216 * @acqe_fc: pointer to the async fc completion queue entry.
6218 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
6219 * that the event was received and then issue a read_topology mailbox command so
6220 * that the rest of the driver will treat it the same as SLI3.
6223 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
6227 struct lpfc_mbx_read_top *la;
6230 if (bf_get(lpfc_trailer_type, acqe_fc) !=
6231 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
6232 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6233 "2895 Non FC link Event detected.(%d)\n",
6234 bf_get(lpfc_trailer_type, acqe_fc));
6238 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6239 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
6240 lpfc_update_trunk_link_status(phba, acqe_fc);
6244 /* Keep the link status for extra SLI4 state machine reference */
6245 phba->sli4_hba.link_state.speed =
6246 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6247 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6248 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
6249 phba->sli4_hba.link_state.topology =
6250 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
6251 phba->sli4_hba.link_state.status =
6252 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
6253 phba->sli4_hba.link_state.type =
6254 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
6255 phba->sli4_hba.link_state.number =
6256 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
6257 phba->sli4_hba.link_state.fault =
6258 bf_get(lpfc_acqe_link_fault, acqe_fc);
6260 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6261 LPFC_FC_LA_TYPE_LINK_DOWN)
6262 phba->sli4_hba.link_state.logical_speed = 0;
6263 else if (!phba->sli4_hba.conf_trunk)
6264 phba->sli4_hba.link_state.logical_speed =
6265 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6267 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6268 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
6269 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
6270 "%dMbps Fault:%d\n",
6271 phba->sli4_hba.link_state.speed,
6272 phba->sli4_hba.link_state.topology,
6273 phba->sli4_hba.link_state.status,
6274 phba->sli4_hba.link_state.type,
6275 phba->sli4_hba.link_state.number,
6276 phba->sli4_hba.link_state.logical_speed,
6277 phba->sli4_hba.link_state.fault);
6278 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6280 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6281 "2897 The mboxq allocation failed\n");
6284 rc = lpfc_mbox_rsrc_prep(phba, pmb);
6286 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6287 "2898 The mboxq prep failed\n");
6291 /* Cleanup any outstanding ELS commands */
6292 lpfc_els_flush_all_cmd(phba);
6294 /* Block ELS IOCBs until we have done process link event */
6295 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
6297 /* Update link event statistics */
6298 phba->sli.slistat.link_event++;
6300 /* Create lpfc_handle_latt mailbox command from link ACQE */
6301 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
6302 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
6303 pmb->vport = phba->pport;
6305 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
6306 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
6308 switch (phba->sli4_hba.link_state.status) {
6309 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
6310 phba->link_flag |= LS_MDS_LINK_DOWN;
6312 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
6313 phba->link_flag |= LS_MDS_LOOPBACK;
6319 /* Initialize completion status */
6321 mb->mbxStatus = MBX_SUCCESS;
6323 /* Parse port fault information field */
6324 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
6326 /* Parse and translate link attention fields */
6327 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
6328 la->eventTag = acqe_fc->event_tag;
6330 if (phba->sli4_hba.link_state.status ==
6331 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
6332 bf_set(lpfc_mbx_read_top_att_type, la,
6333 LPFC_FC_LA_TYPE_UNEXP_WWPN);
6335 bf_set(lpfc_mbx_read_top_att_type, la,
6336 LPFC_FC_LA_TYPE_LINK_DOWN);
6338 /* Invoke the mailbox command callback function */
6339 lpfc_mbx_cmpl_read_topology(phba, pmb);
6344 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
6345 if (rc == MBX_NOT_FINISHED)
6350 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6354 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
6355 * @phba: pointer to lpfc hba data structure.
6356 * @acqe_sli: pointer to the async SLI completion queue entry.
6358 * This routine is to handle the SLI4 asynchronous SLI events.
6361 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
6367 uint8_t operational = 0;
6368 struct temp_event temp_event_data;
6369 struct lpfc_acqe_misconfigured_event *misconfigured;
6370 struct lpfc_acqe_cgn_signal *cgn_signal;
6371 struct Scsi_Host *shost;
6372 struct lpfc_vport **vports;
6375 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
6377 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6378 "2901 Async SLI event - Type:%d, Event Data: x%08x "
6379 "x%08x x%08x x%08x\n", evt_type,
6380 acqe_sli->event_data1, acqe_sli->event_data2,
6381 acqe_sli->reserved, acqe_sli->trailer);
6383 port_name = phba->Port[0];
6384 if (port_name == 0x00)
6385 port_name = '?'; /* get port name is empty */
6388 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
6389 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6390 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6391 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6393 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6394 "3190 Over Temperature:%d Celsius- Port Name %c\n",
6395 acqe_sli->event_data1, port_name);
6397 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
6398 shost = lpfc_shost_from_vport(phba->pport);
6399 fc_host_post_vendor_event(shost, fc_get_event_number(),
6400 sizeof(temp_event_data),
6401 (char *)&temp_event_data,
6402 SCSI_NL_VID_TYPE_PCI
6403 | PCI_VENDOR_ID_EMULEX);
6405 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
6406 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6407 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6408 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6410 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6411 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
6412 acqe_sli->event_data1, port_name);
6414 shost = lpfc_shost_from_vport(phba->pport);
6415 fc_host_post_vendor_event(shost, fc_get_event_number(),
6416 sizeof(temp_event_data),
6417 (char *)&temp_event_data,
6418 SCSI_NL_VID_TYPE_PCI
6419 | PCI_VENDOR_ID_EMULEX);
6421 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
6422 misconfigured = (struct lpfc_acqe_misconfigured_event *)
6423 &acqe_sli->event_data1;
6425 /* fetch the status for this port */
6426 switch (phba->sli4_hba.lnk_info.lnk_no) {
6427 case LPFC_LINK_NUMBER_0:
6428 status = bf_get(lpfc_sli_misconfigured_port0_state,
6429 &misconfigured->theEvent);
6430 operational = bf_get(lpfc_sli_misconfigured_port0_op,
6431 &misconfigured->theEvent);
6433 case LPFC_LINK_NUMBER_1:
6434 status = bf_get(lpfc_sli_misconfigured_port1_state,
6435 &misconfigured->theEvent);
6436 operational = bf_get(lpfc_sli_misconfigured_port1_op,
6437 &misconfigured->theEvent);
6439 case LPFC_LINK_NUMBER_2:
6440 status = bf_get(lpfc_sli_misconfigured_port2_state,
6441 &misconfigured->theEvent);
6442 operational = bf_get(lpfc_sli_misconfigured_port2_op,
6443 &misconfigured->theEvent);
6445 case LPFC_LINK_NUMBER_3:
6446 status = bf_get(lpfc_sli_misconfigured_port3_state,
6447 &misconfigured->theEvent);
6448 operational = bf_get(lpfc_sli_misconfigured_port3_op,
6449 &misconfigured->theEvent);
6452 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6454 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
6455 "event: Invalid link %d",
6456 phba->sli4_hba.lnk_info.lnk_no);
6460 /* Skip if optic state unchanged */
6461 if (phba->sli4_hba.lnk_info.optic_state == status)
6465 case LPFC_SLI_EVENT_STATUS_VALID:
6466 sprintf(message, "Physical Link is functional");
6468 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
6469 sprintf(message, "Optics faulted/incorrectly "
6470 "installed/not installed - Reseat optics, "
6471 "if issue not resolved, replace.");
6473 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
6475 "Optics of two types installed - Remove one "
6476 "optic or install matching pair of optics.");
6478 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
6479 sprintf(message, "Incompatible optics - Replace with "
6480 "compatible optics for card to function.");
6482 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
6483 sprintf(message, "Unqualified optics - Replace with "
6484 "Avago optics for Warranty and Technical "
6485 "Support - Link is%s operational",
6486 (operational) ? " not" : "");
6488 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
6489 sprintf(message, "Uncertified optics - Replace with "
6490 "Avago-certified optics to enable link "
6491 "operation - Link is%s operational",
6492 (operational) ? " not" : "");
6495 /* firmware is reporting a status we don't know about */
6496 sprintf(message, "Unknown event status x%02x", status);
6500 /* Issue READ_CONFIG mbox command to refresh supported speeds */
6501 rc = lpfc_sli4_read_config(phba);
6504 lpfc_printf_log(phba, KERN_ERR,
6506 "3194 Unable to retrieve supported "
6507 "speeds, rc = 0x%x\n", rc);
6509 rc = lpfc_sli4_refresh_params(phba);
6511 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6512 "3174 Unable to update pls support, "
6515 vports = lpfc_create_vport_work_array(phba);
6516 if (vports != NULL) {
6517 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6519 shost = lpfc_shost_from_vport(vports[i]);
6520 lpfc_host_supported_speeds_set(shost);
6523 lpfc_destroy_vport_work_array(phba, vports);
6525 phba->sli4_hba.lnk_info.optic_state = status;
6526 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6527 "3176 Port Name %c %s\n", port_name, message);
6529 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
6530 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6531 "3192 Remote DPort Test Initiated - "
6532 "Event Data1:x%08x Event Data2: x%08x\n",
6533 acqe_sli->event_data1, acqe_sli->event_data2);
6535 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
6536 /* Call FW to obtain active parms */
6537 lpfc_sli4_cgn_parm_chg_evt(phba);
6539 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
6540 /* Misconfigured WWN. Reports that the SLI Port is configured
6541 * to use FA-WWN, but the attached device doesn’t support it.
6542 * Event Data1 - N.A, Event Data2 - N.A
6543 * This event only happens on the physical port.
6545 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI | LOG_DISCOVERY,
6546 "2699 Misconfigured FA-PWWN - Attached device "
6547 "does not support FA-PWWN\n");
6548 phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_FABRIC;
6549 memset(phba->pport->fc_portname.u.wwn, 0,
6550 sizeof(struct lpfc_name));
6552 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
6553 /* EEPROM failure. No driver action is required */
6554 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6555 "2518 EEPROM failure - "
6556 "Event Data1: x%08x Event Data2: x%08x\n",
6557 acqe_sli->event_data1, acqe_sli->event_data2);
6559 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
6560 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6562 cgn_signal = (struct lpfc_acqe_cgn_signal *)
6563 &acqe_sli->event_data1;
6564 phba->cgn_acqe_cnt++;
6566 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6567 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6568 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6570 /* no threshold for CMF, even 1 signal will trigger an event */
6572 /* Alarm overrides warning, so check that first */
6573 if (cgn_signal->alarm_cnt) {
6574 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6575 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6576 atomic_add(cgn_signal->alarm_cnt,
6577 &phba->cgn_sync_alarm_cnt);
6580 /* signal action needs to be taken */
6581 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6582 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6583 /* Keep track of warning cnt for CMF_SYNC_WQE */
6584 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6589 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6590 "3193 Unrecognized SLI event, type: 0x%x",
6597 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6598 * @vport: pointer to vport data structure.
6600 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6601 * response to a CVL event.
6603 * Return the pointer to the ndlp with the vport if successful, otherwise
6606 static struct lpfc_nodelist *
6607 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6609 struct lpfc_nodelist *ndlp;
6610 struct Scsi_Host *shost;
6611 struct lpfc_hba *phba;
6618 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6620 /* Cannot find existing Fabric ndlp, so allocate a new one */
6621 ndlp = lpfc_nlp_init(vport, Fabric_DID);
6624 /* Set the node type */
6625 ndlp->nlp_type |= NLP_FABRIC;
6626 /* Put ndlp onto node list */
6627 lpfc_enqueue_node(vport, ndlp);
6629 if ((phba->pport->port_state < LPFC_FLOGI) &&
6630 (phba->pport->port_state != LPFC_VPORT_FAILED))
6632 /* If virtual link is not yet instantiated ignore CVL */
6633 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6634 && (vport->port_state != LPFC_VPORT_FAILED))
6636 shost = lpfc_shost_from_vport(vport);
6639 lpfc_linkdown_port(vport);
6640 lpfc_cleanup_pending_mbox(vport);
6641 spin_lock_irq(shost->host_lock);
6642 vport->fc_flag |= FC_VPORT_CVL_RCVD;
6643 spin_unlock_irq(shost->host_lock);
6649 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
6650 * @phba: pointer to lpfc hba data structure.
6652 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6653 * response to a FCF dead event.
6656 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6658 struct lpfc_vport **vports;
6661 vports = lpfc_create_vport_work_array(phba);
6663 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6664 lpfc_sli4_perform_vport_cvl(vports[i]);
6665 lpfc_destroy_vport_work_array(phba, vports);
6669 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
6670 * @phba: pointer to lpfc hba data structure.
6671 * @acqe_fip: pointer to the async fcoe completion queue entry.
6673 * This routine is to handle the SLI4 asynchronous fcoe event.
6676 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
6677 struct lpfc_acqe_fip *acqe_fip)
6679 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
6681 struct lpfc_vport *vport;
6682 struct lpfc_nodelist *ndlp;
6683 int active_vlink_present;
6684 struct lpfc_vport **vports;
6687 phba->fc_eventTag = acqe_fip->event_tag;
6688 phba->fcoe_eventtag = acqe_fip->event_tag;
6689 switch (event_type) {
6690 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6691 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6692 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
6693 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6694 "2546 New FCF event, evt_tag:x%x, "
6696 acqe_fip->event_tag,
6699 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6701 "2788 FCF param modified event, "
6702 "evt_tag:x%x, index:x%x\n",
6703 acqe_fip->event_tag,
6705 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6707 * During period of FCF discovery, read the FCF
6708 * table record indexed by the event to update
6709 * FCF roundrobin failover eligible FCF bmask.
6711 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6713 "2779 Read FCF (x%x) for updating "
6714 "roundrobin FCF failover bmask\n",
6716 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
6719 /* If the FCF discovery is in progress, do nothing. */
6720 spin_lock_irq(&phba->hbalock);
6721 if (phba->hba_flag & FCF_TS_INPROG) {
6722 spin_unlock_irq(&phba->hbalock);
6725 /* If fast FCF failover rescan event is pending, do nothing */
6726 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
6727 spin_unlock_irq(&phba->hbalock);
6731 /* If the FCF has been in discovered state, do nothing. */
6732 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
6733 spin_unlock_irq(&phba->hbalock);
6736 spin_unlock_irq(&phba->hbalock);
6738 /* Otherwise, scan the entire FCF table and re-discover SAN */
6739 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6740 "2770 Start FCF table scan per async FCF "
6741 "event, evt_tag:x%x, index:x%x\n",
6742 acqe_fip->event_tag, acqe_fip->index);
6743 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6744 LPFC_FCOE_FCF_GET_FIRST);
6746 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6747 "2547 Issue FCF scan read FCF mailbox "
6748 "command failed (x%x)\n", rc);
6751 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
6752 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6753 "2548 FCF Table full count 0x%x tag 0x%x\n",
6754 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6755 acqe_fip->event_tag);
6758 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
6759 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6760 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6761 "2549 FCF (x%x) disconnected from network, "
6762 "tag:x%x\n", acqe_fip->index,
6763 acqe_fip->event_tag);
6765 * If we are in the middle of FCF failover process, clear
6766 * the corresponding FCF bit in the roundrobin bitmap.
6768 spin_lock_irq(&phba->hbalock);
6769 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6770 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
6771 spin_unlock_irq(&phba->hbalock);
6772 /* Update FLOGI FCF failover eligible FCF bmask */
6773 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
6776 spin_unlock_irq(&phba->hbalock);
6778 /* If the event is not for currently used fcf do nothing */
6779 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
6783 * Otherwise, request the port to rediscover the entire FCF
6784 * table for a fast recovery from case that the current FCF
6785 * is no longer valid as we are not in the middle of FCF
6786 * failover process already.
6788 spin_lock_irq(&phba->hbalock);
6789 /* Mark the fast failover process in progress */
6790 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6791 spin_unlock_irq(&phba->hbalock);
6793 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6794 "2771 Start FCF fast failover process due to "
6795 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6796 "\n", acqe_fip->event_tag, acqe_fip->index);
6797 rc = lpfc_sli4_redisc_fcf_table(phba);
6799 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6801 "2772 Issue FCF rediscover mailbox "
6802 "command failed, fail through to FCF "
6804 spin_lock_irq(&phba->hbalock);
6805 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6806 spin_unlock_irq(&phba->hbalock);
6808 * Last resort will fail over by treating this
6809 * as a link down to FCF registration.
6811 lpfc_sli4_fcf_dead_failthrough(phba);
6813 /* Reset FCF roundrobin bmask for new discovery */
6814 lpfc_sli4_clear_fcf_rr_bmask(phba);
6816 * Handling fast FCF failover to a DEAD FCF event is
6817 * considered equalivant to receiving CVL to all vports.
6819 lpfc_sli4_perform_all_vport_cvl(phba);
6822 case LPFC_FIP_EVENT_TYPE_CVL:
6823 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6824 lpfc_printf_log(phba, KERN_ERR,
6826 "2718 Clear Virtual Link Received for VPI 0x%x"
6827 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
6829 vport = lpfc_find_vport_by_vpid(phba,
6831 ndlp = lpfc_sli4_perform_vport_cvl(vport);
6834 active_vlink_present = 0;
6836 vports = lpfc_create_vport_work_array(phba);
6838 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6840 if ((!(vports[i]->fc_flag &
6841 FC_VPORT_CVL_RCVD)) &&
6842 (vports[i]->port_state > LPFC_FDISC)) {
6843 active_vlink_present = 1;
6847 lpfc_destroy_vport_work_array(phba, vports);
6851 * Don't re-instantiate if vport is marked for deletion.
6852 * If we are here first then vport_delete is going to wait
6853 * for discovery to complete.
6855 if (!(vport->load_flag & FC_UNLOADING) &&
6856 active_vlink_present) {
6858 * If there are other active VLinks present,
6859 * re-instantiate the Vlink using FDISC.
6861 mod_timer(&ndlp->nlp_delayfunc,
6862 jiffies + msecs_to_jiffies(1000));
6863 spin_lock_irq(&ndlp->lock);
6864 ndlp->nlp_flag |= NLP_DELAY_TMO;
6865 spin_unlock_irq(&ndlp->lock);
6866 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6867 vport->port_state = LPFC_FDISC;
6870 * Otherwise, we request port to rediscover
6871 * the entire FCF table for a fast recovery
6872 * from possible case that the current FCF
6873 * is no longer valid if we are not already
6874 * in the FCF failover process.
6876 spin_lock_irq(&phba->hbalock);
6877 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6878 spin_unlock_irq(&phba->hbalock);
6881 /* Mark the fast failover process in progress */
6882 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
6883 spin_unlock_irq(&phba->hbalock);
6884 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6886 "2773 Start FCF failover per CVL, "
6887 "evt_tag:x%x\n", acqe_fip->event_tag);
6888 rc = lpfc_sli4_redisc_fcf_table(phba);
6890 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6892 "2774 Issue FCF rediscover "
6893 "mailbox command failed, "
6894 "through to CVL event\n");
6895 spin_lock_irq(&phba->hbalock);
6896 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
6897 spin_unlock_irq(&phba->hbalock);
6899 * Last resort will be re-try on the
6900 * the current registered FCF entry.
6902 lpfc_retry_pport_discovery(phba);
6905 * Reset FCF roundrobin bmask for new
6908 lpfc_sli4_clear_fcf_rr_bmask(phba);
6912 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6913 "0288 Unknown FCoE event type 0x%x event tag "
6914 "0x%x\n", event_type, acqe_fip->event_tag);
6920 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
6921 * @phba: pointer to lpfc hba data structure.
6922 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
6924 * This routine is to handle the SLI4 asynchronous dcbx event.
6927 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
6928 struct lpfc_acqe_dcbx *acqe_dcbx)
6930 phba->fc_eventTag = acqe_dcbx->event_tag;
6931 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6932 "0290 The SLI4 DCBX asynchronous event is not "
6937 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
6938 * @phba: pointer to lpfc hba data structure.
6939 * @acqe_grp5: pointer to the async grp5 completion queue entry.
6941 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
6942 * is an asynchronous notified of a logical link speed change. The Port
6943 * reports the logical link speed in units of 10Mbps.
6946 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
6947 struct lpfc_acqe_grp5 *acqe_grp5)
6949 uint16_t prev_ll_spd;
6951 phba->fc_eventTag = acqe_grp5->event_tag;
6952 phba->fcoe_eventtag = acqe_grp5->event_tag;
6953 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
6954 phba->sli4_hba.link_state.logical_speed =
6955 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
6956 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6957 "2789 GRP5 Async Event: Updating logical link speed "
6958 "from %dMbps to %dMbps\n", prev_ll_spd,
6959 phba->sli4_hba.link_state.logical_speed);
6963 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
6964 * @phba: pointer to lpfc hba data structure.
6966 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
6967 * is an asynchronous notification of a request to reset CM stats.
6970 lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
6974 lpfc_init_congestion_stat(phba);
6978 * lpfc_cgn_params_val - Validate FW congestion parameters.
6979 * @phba: pointer to lpfc hba data structure.
6980 * @p_cfg_param: pointer to FW provided congestion parameters.
6982 * This routine validates the congestion parameters passed
6983 * by the FW to the driver via an ACQE event.
6986 lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
6988 spin_lock_irq(&phba->hbalock);
6990 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
6991 LPFC_CFG_MONITOR)) {
6992 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
6993 "6225 CMF mode param out of range: %d\n",
6994 p_cfg_param->cgn_param_mode);
6995 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
6998 spin_unlock_irq(&phba->hbalock);
7002 * lpfc_cgn_params_parse - Process a FW cong parm change event
7003 * @phba: pointer to lpfc hba data structure.
7004 * @p_cgn_param: pointer to a data buffer with the FW cong params.
7005 * @len: the size of pdata in bytes.
7007 * This routine validates the congestion management buffer signature
7008 * from the FW, validates the contents and makes corrections for
7009 * valid, in-range values. If the signature magic is correct and
7010 * after parameter validation, the contents are copied to the driver's
7011 * @phba structure. If the magic is incorrect, an error message is
7015 lpfc_cgn_params_parse(struct lpfc_hba *phba,
7016 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
7018 struct lpfc_cgn_info *cp;
7019 uint32_t crc, oldmode;
7021 /* Make sure the FW has encoded the correct magic number to
7022 * validate the congestion parameter in FW memory.
7024 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
7025 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7026 "4668 FW cgn parm buffer data: "
7027 "magic 0x%x version %d mode %d "
7028 "level0 %d level1 %d "
7029 "level2 %d byte13 %d "
7030 "byte14 %d byte15 %d "
7031 "byte11 %d byte12 %d activeMode %d\n",
7032 p_cgn_param->cgn_param_magic,
7033 p_cgn_param->cgn_param_version,
7034 p_cgn_param->cgn_param_mode,
7035 p_cgn_param->cgn_param_level0,
7036 p_cgn_param->cgn_param_level1,
7037 p_cgn_param->cgn_param_level2,
7038 p_cgn_param->byte13,
7039 p_cgn_param->byte14,
7040 p_cgn_param->byte15,
7041 p_cgn_param->byte11,
7042 p_cgn_param->byte12,
7043 phba->cmf_active_mode);
7045 oldmode = phba->cmf_active_mode;
7047 /* Any parameters out of range are corrected to defaults
7048 * by this routine. No need to fail.
7050 lpfc_cgn_params_val(phba, p_cgn_param);
7052 /* Parameters are verified, move them into driver storage */
7053 spin_lock_irq(&phba->hbalock);
7054 memcpy(&phba->cgn_p, p_cgn_param,
7055 sizeof(struct lpfc_cgn_param));
7057 /* Update parameters in congestion info buffer now */
7059 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
7060 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
7061 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
7062 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
7063 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
7064 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
7065 LPFC_CGN_CRC32_SEED);
7066 cp->cgn_info_crc = cpu_to_le32(crc);
7068 spin_unlock_irq(&phba->hbalock);
7070 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
7074 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
7075 /* Turning CMF on */
7076 lpfc_cmf_start(phba);
7078 if (phba->link_state >= LPFC_LINK_UP) {
7079 phba->cgn_reg_fpin =
7080 phba->cgn_init_reg_fpin;
7081 phba->cgn_reg_signal =
7082 phba->cgn_init_reg_signal;
7083 lpfc_issue_els_edc(phba->pport, 0);
7087 case LPFC_CFG_MANAGED:
7088 switch (phba->cgn_p.cgn_param_mode) {
7090 /* Turning CMF off */
7091 lpfc_cmf_stop(phba);
7092 if (phba->link_state >= LPFC_LINK_UP)
7093 lpfc_issue_els_edc(phba->pport, 0);
7095 case LPFC_CFG_MONITOR:
7096 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7097 "4661 Switch from MANAGED to "
7099 phba->cmf_max_bytes_per_interval =
7100 phba->cmf_link_byte_count;
7102 /* Resume blocked IO - unblock on workqueue */
7103 queue_work(phba->wq,
7104 &phba->unblock_request_work);
7108 case LPFC_CFG_MONITOR:
7109 switch (phba->cgn_p.cgn_param_mode) {
7111 /* Turning CMF off */
7112 lpfc_cmf_stop(phba);
7113 if (phba->link_state >= LPFC_LINK_UP)
7114 lpfc_issue_els_edc(phba->pport, 0);
7116 case LPFC_CFG_MANAGED:
7117 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7118 "4662 Switch from MONITOR to "
7120 lpfc_cmf_signal_init(phba);
7126 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7127 "4669 FW cgn parm buf wrong magic 0x%x "
7128 "version %d\n", p_cgn_param->cgn_param_magic,
7129 p_cgn_param->cgn_param_version);
7134 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
7135 * @phba: pointer to lpfc hba data structure.
7137 * This routine issues a read_object mailbox command to
7138 * get the congestion management parameters from the FW
7139 * parses it and updates the driver maintained values.
7142 * 0 if the object was empty
7143 * -Eval if an error was encountered
7144 * Count if bytes were read from object
7147 lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
7150 struct lpfc_cgn_param *p_cgn_param = NULL;
7154 /* Find out if the FW has a new set of congestion parameters. */
7155 len = sizeof(struct lpfc_cgn_param);
7156 pdata = kzalloc(len, GFP_KERNEL);
7157 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
7160 /* 0 means no data. A negative means error. A positive means
7161 * bytes were copied.
7164 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7165 "4670 CGN RD OBJ returns no data\n");
7167 } else if (ret < 0) {
7168 /* Some error. Just exit and return it to the caller.*/
7172 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7173 "6234 READ CGN PARAMS Successful %d\n", len);
7175 /* Parse data pointer over len and update the phba congestion
7176 * parameters with values passed back. The receive rate values
7177 * may have been altered in FW, but take no action here.
7179 p_cgn_param = (struct lpfc_cgn_param *)pdata;
7180 lpfc_cgn_params_parse(phba, p_cgn_param, len);
7188 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
7189 * @phba: pointer to lpfc hba data structure.
7191 * The FW generated Async ACQE SLI event calls this routine when
7192 * the event type is an SLI Internal Port Event and the Event Code
7193 * indicates a change to the FW maintained congestion parameters.
7195 * This routine executes a Read_Object mailbox call to obtain the
7196 * current congestion parameters maintained in FW and corrects
7197 * the driver's active congestion parameters.
7199 * The acqe event is not passed because there is no further data
7202 * Returns nonzero error if event processing encountered an error.
7203 * Zero otherwise for success.
7206 lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
7210 if (!phba->sli4_hba.pc_sli4_params.cmf) {
7211 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7212 "4664 Cgn Evt when E2E off. Drop event\n");
7216 /* If the event is claiming an empty object, it's ok. A write
7217 * could have cleared it. Only error is a negative return
7220 ret = lpfc_sli4_cgn_params_read(phba);
7222 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7223 "4667 Error reading Cgn Params (%d)\n",
7226 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7227 "4673 CGN Event empty object.\n");
7233 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
7234 * @phba: pointer to lpfc hba data structure.
7236 * This routine is invoked by the worker thread to process all the pending
7237 * SLI4 asynchronous events.
7239 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
7241 struct lpfc_cq_event *cq_event;
7242 unsigned long iflags;
7244 /* First, declare the async event has been handled */
7245 spin_lock_irqsave(&phba->hbalock, iflags);
7246 phba->hba_flag &= ~ASYNC_EVENT;
7247 spin_unlock_irqrestore(&phba->hbalock, iflags);
7249 /* Now, handle all the async events */
7250 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7251 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
7252 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
7253 cq_event, struct lpfc_cq_event, list);
7254 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
7257 /* Process the asynchronous event */
7258 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
7259 case LPFC_TRAILER_CODE_LINK:
7260 lpfc_sli4_async_link_evt(phba,
7261 &cq_event->cqe.acqe_link);
7263 case LPFC_TRAILER_CODE_FCOE:
7264 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
7266 case LPFC_TRAILER_CODE_DCBX:
7267 lpfc_sli4_async_dcbx_evt(phba,
7268 &cq_event->cqe.acqe_dcbx);
7270 case LPFC_TRAILER_CODE_GRP5:
7271 lpfc_sli4_async_grp5_evt(phba,
7272 &cq_event->cqe.acqe_grp5);
7274 case LPFC_TRAILER_CODE_FC:
7275 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
7277 case LPFC_TRAILER_CODE_SLI:
7278 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
7280 case LPFC_TRAILER_CODE_CMSTAT:
7281 lpfc_sli4_async_cmstat_evt(phba);
7284 lpfc_printf_log(phba, KERN_ERR,
7286 "1804 Invalid asynchronous event code: "
7287 "x%x\n", bf_get(lpfc_trailer_code,
7288 &cq_event->cqe.mcqe_cmpl));
7292 /* Free the completion event processed to the free pool */
7293 lpfc_sli4_cq_event_release(phba, cq_event);
7294 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7296 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
7300 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
7301 * @phba: pointer to lpfc hba data structure.
7303 * This routine is invoked by the worker thread to process FCF table
7304 * rediscovery pending completion event.
7306 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
7310 spin_lock_irq(&phba->hbalock);
7311 /* Clear FCF rediscovery timeout event */
7312 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
7313 /* Clear driver fast failover FCF record flag */
7314 phba->fcf.failover_rec.flag = 0;
7315 /* Set state for FCF fast failover */
7316 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
7317 spin_unlock_irq(&phba->hbalock);
7319 /* Scan FCF table from the first entry to re-discover SAN */
7320 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
7321 "2777 Start post-quiescent FCF table scan\n");
7322 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
7324 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7325 "2747 Issue FCF scan read FCF mailbox "
7326 "command failed 0x%x\n", rc);
7330 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
7331 * @phba: pointer to lpfc hba data structure.
7332 * @dev_grp: The HBA PCI-Device group number.
7334 * This routine is invoked to set up the per HBA PCI-Device group function
7335 * API jump table entries.
7337 * Return: 0 if success, otherwise -ENODEV
7340 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7344 /* Set up lpfc PCI-device group */
7345 phba->pci_dev_grp = dev_grp;
7347 /* The LPFC_PCI_DEV_OC uses SLI4 */
7348 if (dev_grp == LPFC_PCI_DEV_OC)
7349 phba->sli_rev = LPFC_SLI_REV4;
7351 /* Set up device INIT API function jump table */
7352 rc = lpfc_init_api_table_setup(phba, dev_grp);
7355 /* Set up SCSI API function jump table */
7356 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
7359 /* Set up SLI API function jump table */
7360 rc = lpfc_sli_api_table_setup(phba, dev_grp);
7363 /* Set up MBOX API function jump table */
7364 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
7372 * lpfc_log_intr_mode - Log the active interrupt mode
7373 * @phba: pointer to lpfc hba data structure.
7374 * @intr_mode: active interrupt mode adopted.
7376 * This routine it invoked to log the currently used active interrupt mode
7379 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
7381 switch (intr_mode) {
7383 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7384 "0470 Enable INTx interrupt mode.\n");
7387 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7388 "0481 Enabled MSI interrupt mode.\n");
7391 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7392 "0480 Enabled MSI-X interrupt mode.\n");
7395 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7396 "0482 Illegal interrupt mode.\n");
7403 * lpfc_enable_pci_dev - Enable a generic PCI device.
7404 * @phba: pointer to lpfc hba data structure.
7406 * This routine is invoked to enable the PCI device that is common to all
7411 * other values - error
7414 lpfc_enable_pci_dev(struct lpfc_hba *phba)
7416 struct pci_dev *pdev;
7418 /* Obtain PCI device reference */
7422 pdev = phba->pcidev;
7423 /* Enable PCI device */
7424 if (pci_enable_device_mem(pdev))
7426 /* Request PCI resource for the device */
7427 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
7428 goto out_disable_device;
7429 /* Set up device as PCI master and save state for EEH */
7430 pci_set_master(pdev);
7431 pci_try_set_mwi(pdev);
7432 pci_save_state(pdev);
7434 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
7435 if (pci_is_pcie(pdev))
7436 pdev->needs_freset = 1;
7441 pci_disable_device(pdev);
7443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7444 "1401 Failed to enable pci device\n");
7449 * lpfc_disable_pci_dev - Disable a generic PCI device.
7450 * @phba: pointer to lpfc hba data structure.
7452 * This routine is invoked to disable the PCI device that is common to all
7456 lpfc_disable_pci_dev(struct lpfc_hba *phba)
7458 struct pci_dev *pdev;
7460 /* Obtain PCI device reference */
7464 pdev = phba->pcidev;
7465 /* Release PCI resource and disable PCI device */
7466 pci_release_mem_regions(pdev);
7467 pci_disable_device(pdev);
7473 * lpfc_reset_hba - Reset a hba
7474 * @phba: pointer to lpfc hba data structure.
7476 * This routine is invoked to reset a hba device. It brings the HBA
7477 * offline, performs a board restart, and then brings the board back
7478 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
7479 * on outstanding mailbox commands.
7482 lpfc_reset_hba(struct lpfc_hba *phba)
7484 /* If resets are disabled then set error state and return. */
7485 if (!phba->cfg_enable_hba_reset) {
7486 phba->link_state = LPFC_HBA_ERROR;
7490 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
7491 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
7492 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
7494 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
7495 lpfc_sli_flush_io_rings(phba);
7498 lpfc_sli_brdrestart(phba);
7500 lpfc_unblock_mgmt_io(phba);
7504 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
7505 * @phba: pointer to lpfc hba data structure.
7507 * This function enables the PCI SR-IOV virtual functions to a physical
7508 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7509 * enable the number of virtual functions to the physical function. As
7510 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7511 * API call does not considered as an error condition for most of the device.
7514 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
7516 struct pci_dev *pdev = phba->pcidev;
7520 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
7524 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
7529 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
7530 * @phba: pointer to lpfc hba data structure.
7531 * @nr_vfn: number of virtual functions to be enabled.
7533 * This function enables the PCI SR-IOV virtual functions to a physical
7534 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7535 * enable the number of virtual functions to the physical function. As
7536 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7537 * API call does not considered as an error condition for most of the device.
7540 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
7542 struct pci_dev *pdev = phba->pcidev;
7543 uint16_t max_nr_vfn;
7546 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
7547 if (nr_vfn > max_nr_vfn) {
7548 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7549 "3057 Requested vfs (%d) greater than "
7550 "supported vfs (%d)", nr_vfn, max_nr_vfn);
7554 rc = pci_enable_sriov(pdev, nr_vfn);
7556 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7557 "2806 Failed to enable sriov on this device "
7558 "with vfn number nr_vf:%d, rc:%d\n",
7561 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7562 "2807 Successful enable sriov on this device "
7563 "with vfn number nr_vf:%d\n", nr_vfn);
7568 lpfc_unblock_requests_work(struct work_struct *work)
7570 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
7571 unblock_request_work);
7573 lpfc_unblock_requests(phba);
7577 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
7578 * @phba: pointer to lpfc hba data structure.
7580 * This routine is invoked to set up the driver internal resources before the
7581 * device specific resource setup to support the HBA device it attached to.
7585 * other values - error
7588 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
7590 struct lpfc_sli *psli = &phba->sli;
7593 * Driver resources common to all SLI revisions
7595 atomic_set(&phba->fast_event_count, 0);
7596 atomic_set(&phba->dbg_log_idx, 0);
7597 atomic_set(&phba->dbg_log_cnt, 0);
7598 atomic_set(&phba->dbg_log_dmping, 0);
7599 spin_lock_init(&phba->hbalock);
7601 /* Initialize port_list spinlock */
7602 spin_lock_init(&phba->port_list_lock);
7603 INIT_LIST_HEAD(&phba->port_list);
7605 INIT_LIST_HEAD(&phba->work_list);
7606 init_waitqueue_head(&phba->wait_4_mlo_m_q);
7608 /* Initialize the wait queue head for the kernel thread */
7609 init_waitqueue_head(&phba->work_waitq);
7611 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7612 "1403 Protocols supported %s %s %s\n",
7613 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7615 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
7617 (phba->nvmet_support ? "NVMET" : " "));
7619 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7620 spin_lock_init(&phba->scsi_buf_list_get_lock);
7621 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7622 spin_lock_init(&phba->scsi_buf_list_put_lock);
7623 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
7625 /* Initialize the fabric iocb list */
7626 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7628 /* Initialize list to save ELS buffers */
7629 INIT_LIST_HEAD(&phba->elsbuf);
7631 /* Initialize FCF connection rec list */
7632 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7634 /* Initialize OAS configuration list */
7635 spin_lock_init(&phba->devicelock);
7636 INIT_LIST_HEAD(&phba->luns);
7638 /* MBOX heartbeat timer */
7639 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
7640 /* Fabric block timer */
7641 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
7642 /* EA polling mode timer */
7643 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
7644 /* Heartbeat timer */
7645 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
7647 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7649 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7650 lpfc_idle_stat_delay_work);
7651 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
7656 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7657 * @phba: pointer to lpfc hba data structure.
7659 * This routine is invoked to set up the driver internal resources specific to
7660 * support the SLI-3 HBA device it attached to.
7664 * other values - error
7667 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7672 * Initialize timers used by driver
7675 /* FCP polling mode timer */
7676 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
7678 /* Host attention work mask setup */
7679 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7680 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7682 /* Get all the module params for configuring this host */
7683 lpfc_get_cfgparam(phba);
7684 /* Set up phase-1 common device driver resources */
7686 rc = lpfc_setup_driver_resource_phase1(phba);
7690 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
7691 phba->menlo_flag |= HBA_MENLO_SUPPORT;
7692 /* check for menlo minimum sg count */
7693 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
7694 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
7697 if (!phba->sli.sli3_ring)
7698 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7699 sizeof(struct lpfc_sli_ring),
7701 if (!phba->sli.sli3_ring)
7705 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
7706 * used to create the sg_dma_buf_pool must be dynamically calculated.
7709 if (phba->sli_rev == LPFC_SLI_REV4)
7710 entry_sz = sizeof(struct sli4_sge);
7712 entry_sz = sizeof(struct ulp_bde64);
7714 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7715 if (phba->cfg_enable_bg) {
7717 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7718 * the FCP rsp, and a BDE for each. Sice we have no control
7719 * over how many protection data segments the SCSI Layer
7720 * will hand us (ie: there could be one for every block
7721 * in the IO), we just allocate enough BDEs to accomidate
7722 * our max amount and we need to limit lpfc_sg_seg_cnt to
7723 * minimize the risk of running out.
7725 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7726 sizeof(struct fcp_rsp) +
7727 (LPFC_MAX_SG_SEG_CNT * entry_sz);
7729 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7730 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7732 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7733 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7736 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7737 * the FCP rsp, a BDE for each, and a BDE for up to
7738 * cfg_sg_seg_cnt data segments.
7740 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7741 sizeof(struct fcp_rsp) +
7742 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
7744 /* Total BDEs in BPL for scsi_sg_list */
7745 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7748 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7749 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
7750 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7751 phba->cfg_total_seg_cnt);
7753 phba->max_vpi = LPFC_MAX_VPI;
7754 /* This will be set to correct value after config_port mbox */
7755 phba->max_vports = 0;
7758 * Initialize the SLI Layer to run with lpfc HBAs.
7760 lpfc_sli_setup(phba);
7761 lpfc_sli_queue_init(phba);
7763 /* Allocate device driver memory */
7764 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7767 phba->lpfc_sg_dma_buf_pool =
7768 dma_pool_create("lpfc_sg_dma_buf_pool",
7769 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7772 if (!phba->lpfc_sg_dma_buf_pool)
7775 phba->lpfc_cmd_rsp_buf_pool =
7776 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7778 sizeof(struct fcp_cmnd) +
7779 sizeof(struct fcp_rsp),
7782 if (!phba->lpfc_cmd_rsp_buf_pool)
7783 goto fail_free_dma_buf_pool;
7786 * Enable sr-iov virtual functions if supported and configured
7787 * through the module parameter.
7789 if (phba->cfg_sriov_nr_virtfn > 0) {
7790 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7791 phba->cfg_sriov_nr_virtfn);
7793 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7794 "2808 Requested number of SR-IOV "
7795 "virtual functions (%d) is not "
7797 phba->cfg_sriov_nr_virtfn);
7798 phba->cfg_sriov_nr_virtfn = 0;
7804 fail_free_dma_buf_pool:
7805 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7806 phba->lpfc_sg_dma_buf_pool = NULL;
7808 lpfc_mem_free(phba);
7813 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7814 * @phba: pointer to lpfc hba data structure.
7816 * This routine is invoked to unset the driver internal resources set up
7817 * specific for supporting the SLI-3 HBA device it attached to.
7820 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7822 /* Free device driver memory allocated */
7823 lpfc_mem_free_all(phba);
7829 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7830 * @phba: pointer to lpfc hba data structure.
7832 * This routine is invoked to set up the driver internal resources specific to
7833 * support the SLI-4 HBA device it attached to.
7837 * other values - error
7840 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7842 LPFC_MBOXQ_t *mboxq;
7844 int rc, i, max_buf_size;
7851 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7852 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
7853 phba->sli4_hba.curr_disp_cpu = 0;
7855 /* Get all the module params for configuring this host */
7856 lpfc_get_cfgparam(phba);
7858 /* Set up phase-1 common device driver resources */
7859 rc = lpfc_setup_driver_resource_phase1(phba);
7863 /* Before proceed, wait for POST done and device ready */
7864 rc = lpfc_sli4_post_status_check(phba);
7868 /* Allocate all driver workqueues here */
7870 /* The lpfc_wq workqueue for deferred irq use */
7871 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7874 * Initialize timers used by driver
7877 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
7879 /* FCF rediscover timer */
7880 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
7882 /* CMF congestion timer */
7883 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7884 phba->cmf_timer.function = lpfc_cmf_timer;
7887 * Control structure for handling external multi-buffer mailbox
7888 * command pass-through.
7890 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
7891 sizeof(struct lpfc_mbox_ext_buf_ctx));
7892 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
7894 phba->max_vpi = LPFC_MAX_VPI;
7896 /* This will be set to correct value after the read_config mbox */
7897 phba->max_vports = 0;
7899 /* Program the default value of vlan_id and fc_map */
7900 phba->valid_vlan = 0;
7901 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
7902 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
7903 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
7906 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
7907 * we will associate a new ring, for each EQ/CQ/WQ tuple.
7908 * The WQ create will allocate the ring.
7911 /* Initialize buffer queue management fields */
7912 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
7913 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
7914 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
7916 /* for VMID idle timeout if VMID is enabled */
7917 if (lpfc_is_vmid_enabled(phba))
7918 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
7921 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
7923 /* Initialize the Abort buffer list used by driver */
7924 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
7925 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
7927 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7928 /* Initialize the Abort nvme buffer list used by driver */
7929 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
7930 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
7931 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
7932 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
7933 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
7936 /* This abort list used by worker thread */
7937 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
7938 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
7939 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
7940 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
7943 * Initialize driver internal slow-path work queues
7946 /* Driver internel slow-path CQ Event pool */
7947 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
7948 /* Response IOCB work queue list */
7949 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
7950 /* Asynchronous event CQ Event work queue list */
7951 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
7952 /* Slow-path XRI aborted CQ Event work queue list */
7953 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
7954 /* Receive queue CQ Event work queue list */
7955 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
7957 /* Initialize extent block lists. */
7958 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
7959 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
7960 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
7961 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
7963 /* Initialize mboxq lists. If the early init routines fail
7964 * these lists need to be correctly initialized.
7966 INIT_LIST_HEAD(&phba->sli.mboxq);
7967 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
7969 /* initialize optic_state to 0xFF */
7970 phba->sli4_hba.lnk_info.optic_state = 0xff;
7972 /* Allocate device driver memory */
7973 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
7977 /* IF Type 2 ports get initialized now. */
7978 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
7979 LPFC_SLI_INTF_IF_TYPE_2) {
7980 rc = lpfc_pci_function_reset(phba);
7985 phba->temp_sensor_support = 1;
7988 /* Create the bootstrap mailbox command */
7989 rc = lpfc_create_bootstrap_mbox(phba);
7993 /* Set up the host's endian order with the device. */
7994 rc = lpfc_setup_endian_order(phba);
7996 goto out_free_bsmbx;
7998 /* Set up the hba's configuration parameters. */
7999 rc = lpfc_sli4_read_config(phba);
8001 goto out_free_bsmbx;
8003 if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
8004 /* Right now the link is down, if FA-PWWN is configured the
8005 * firmware will try FLOGI before the driver gets a link up.
8006 * If it fails, the driver should get a MISCONFIGURED async
8007 * event which will clear this flag. The only notification
8008 * the driver gets is if it fails, if it succeeds there is no
8009 * notification given. Assume success.
8011 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
8014 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
8016 goto out_free_bsmbx;
8018 /* IF Type 0 ports get initialized now. */
8019 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8020 LPFC_SLI_INTF_IF_TYPE_0) {
8021 rc = lpfc_pci_function_reset(phba);
8023 goto out_free_bsmbx;
8026 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8030 goto out_free_bsmbx;
8033 /* Check for NVMET being configured */
8034 phba->nvmet_support = 0;
8035 if (lpfc_enable_nvmet_cnt) {
8037 /* First get WWN of HBA instance */
8038 lpfc_read_nv(phba, mboxq);
8039 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8040 if (rc != MBX_SUCCESS) {
8041 lpfc_printf_log(phba, KERN_ERR,
8043 "6016 Mailbox failed , mbxCmd x%x "
8044 "READ_NV, mbxStatus x%x\n",
8045 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8046 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
8047 mempool_free(mboxq, phba->mbox_mem_pool);
8049 goto out_free_bsmbx;
8052 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
8054 wwn = cpu_to_be64(wwn);
8055 phba->sli4_hba.wwnn.u.name = wwn;
8056 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
8058 /* wwn is WWPN of HBA instance */
8059 wwn = cpu_to_be64(wwn);
8060 phba->sli4_hba.wwpn.u.name = wwn;
8062 /* Check to see if it matches any module parameter */
8063 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
8064 if (wwn == lpfc_enable_nvmet[i]) {
8065 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
8066 if (lpfc_nvmet_mem_alloc(phba))
8069 phba->nvmet_support = 1; /* a match */
8071 lpfc_printf_log(phba, KERN_ERR,
8073 "6017 NVME Target %016llx\n",
8076 lpfc_printf_log(phba, KERN_ERR,
8078 "6021 Can't enable NVME Target."
8079 " NVME_TARGET_FC infrastructure"
8080 " is not in kernel\n");
8082 /* Not supported for NVMET */
8083 phba->cfg_xri_rebalancing = 0;
8084 if (phba->irq_chann_mode == NHT_MODE) {
8085 phba->cfg_irq_chann =
8086 phba->sli4_hba.num_present_cpu;
8087 phba->cfg_hdw_queue =
8088 phba->sli4_hba.num_present_cpu;
8089 phba->irq_chann_mode = NORMAL_MODE;
8096 lpfc_nvme_mod_param_dep(phba);
8099 * Get sli4 parameters that override parameters from Port capabilities.
8100 * If this call fails, it isn't critical unless the SLI4 parameters come
8103 rc = lpfc_get_sli4_parameters(phba, mboxq);
8105 if_type = bf_get(lpfc_sli_intf_if_type,
8106 &phba->sli4_hba.sli_intf);
8107 if_fam = bf_get(lpfc_sli_intf_sli_family,
8108 &phba->sli4_hba.sli_intf);
8109 if (phba->sli4_hba.extents_in_use &&
8110 phba->sli4_hba.rpi_hdrs_in_use) {
8111 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8112 "2999 Unsupported SLI4 Parameters "
8113 "Extents and RPI headers enabled.\n");
8114 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8115 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
8116 mempool_free(mboxq, phba->mbox_mem_pool);
8118 goto out_free_bsmbx;
8121 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8122 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
8123 mempool_free(mboxq, phba->mbox_mem_pool);
8125 goto out_free_bsmbx;
8130 * 1 for cmd, 1 for rsp, NVME adds an extra one
8131 * for boundary conditions in its max_sgl_segment template.
8134 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
8138 * It doesn't matter what family our adapter is in, we are
8139 * limited to 2 Pages, 512 SGEs, for our SGL.
8140 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
8142 max_buf_size = (2 * SLI4_PAGE_SIZE);
8145 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
8146 * used to create the sg_dma_buf_pool must be calculated.
8148 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8149 /* Both cfg_enable_bg and cfg_external_dif code paths */
8152 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
8153 * the FCP rsp, and a SGE. Sice we have no control
8154 * over how many protection segments the SCSI Layer
8155 * will hand us (ie: there could be one for every block
8156 * in the IO), just allocate enough SGEs to accomidate
8157 * our max amount and we need to limit lpfc_sg_seg_cnt
8158 * to minimize the risk of running out.
8160 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8161 sizeof(struct fcp_rsp) + max_buf_size;
8163 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
8164 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
8167 * If supporting DIF, reduce the seg count for scsi to
8168 * allow room for the DIF sges.
8170 if (phba->cfg_enable_bg &&
8171 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
8172 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
8174 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8178 * The scsi_buf for a regular I/O holds the FCP cmnd,
8179 * the FCP rsp, a SGE for each, and a SGE for up to
8180 * cfg_sg_seg_cnt data segments.
8182 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8183 sizeof(struct fcp_rsp) +
8184 ((phba->cfg_sg_seg_cnt + extra) *
8185 sizeof(struct sli4_sge));
8187 /* Total SGEs for scsi_sg_list */
8188 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
8189 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8192 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
8193 * need to post 1 page for the SGL.
8197 if (phba->cfg_xpsgl && !phba->nvmet_support)
8198 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
8199 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
8200 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
8202 phba->cfg_sg_dma_buf_size =
8203 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
8205 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
8206 sizeof(struct sli4_sge);
8208 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
8209 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8210 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
8211 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
8212 "6300 Reducing NVME sg segment "
8214 LPFC_MAX_NVME_SEG_CNT);
8215 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
8217 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
8220 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
8221 "9087 sg_seg_cnt:%d dmabuf_size:%d "
8222 "total:%d scsi:%d nvme:%d\n",
8223 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
8224 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
8225 phba->cfg_nvme_seg_cnt);
8227 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
8228 i = phba->cfg_sg_dma_buf_size;
8232 phba->lpfc_sg_dma_buf_pool =
8233 dma_pool_create("lpfc_sg_dma_buf_pool",
8235 phba->cfg_sg_dma_buf_size,
8237 if (!phba->lpfc_sg_dma_buf_pool)
8238 goto out_free_bsmbx;
8240 phba->lpfc_cmd_rsp_buf_pool =
8241 dma_pool_create("lpfc_cmd_rsp_buf_pool",
8243 sizeof(struct fcp_cmnd) +
8244 sizeof(struct fcp_rsp),
8246 if (!phba->lpfc_cmd_rsp_buf_pool)
8247 goto out_free_sg_dma_buf;
8249 mempool_free(mboxq, phba->mbox_mem_pool);
8251 /* Verify OAS is supported */
8252 lpfc_sli4_oas_verify(phba);
8254 /* Verify RAS support on adapter */
8255 lpfc_sli4_ras_init(phba);
8257 /* Verify all the SLI4 queues */
8258 rc = lpfc_sli4_queue_verify(phba);
8260 goto out_free_cmd_rsp_buf;
8262 /* Create driver internal CQE event pool */
8263 rc = lpfc_sli4_cq_event_pool_create(phba);
8265 goto out_free_cmd_rsp_buf;
8267 /* Initialize sgl lists per host */
8268 lpfc_init_sgl_list(phba);
8270 /* Allocate and initialize active sgl array */
8271 rc = lpfc_init_active_sgl_array(phba);
8273 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8274 "1430 Failed to initialize sgl list.\n");
8275 goto out_destroy_cq_event_pool;
8277 rc = lpfc_sli4_init_rpi_hdrs(phba);
8279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8280 "1432 Failed to initialize rpi headers.\n");
8281 goto out_free_active_sgl;
8284 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
8285 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
8286 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
8288 if (!phba->fcf.fcf_rr_bmask) {
8289 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8290 "2759 Failed allocate memory for FCF round "
8291 "robin failover bmask\n");
8293 goto out_remove_rpi_hdrs;
8296 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
8297 sizeof(struct lpfc_hba_eq_hdl),
8299 if (!phba->sli4_hba.hba_eq_hdl) {
8300 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8301 "2572 Failed allocate memory for "
8302 "fast-path per-EQ handle array\n");
8304 goto out_free_fcf_rr_bmask;
8307 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
8308 sizeof(struct lpfc_vector_map_info),
8310 if (!phba->sli4_hba.cpu_map) {
8311 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8312 "3327 Failed allocate memory for msi-x "
8313 "interrupt vector mapping\n");
8315 goto out_free_hba_eq_hdl;
8318 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
8319 if (!phba->sli4_hba.eq_info) {
8320 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8321 "3321 Failed allocation for per_cpu stats\n");
8323 goto out_free_hba_cpu_map;
8326 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
8327 sizeof(*phba->sli4_hba.idle_stat),
8329 if (!phba->sli4_hba.idle_stat) {
8330 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8331 "3390 Failed allocation for idle_stat\n");
8333 goto out_free_hba_eq_info;
8336 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8337 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
8338 if (!phba->sli4_hba.c_stat) {
8339 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8340 "3332 Failed allocating per cpu hdwq stats\n");
8342 goto out_free_hba_idle_stat;
8346 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
8347 if (!phba->cmf_stat) {
8348 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8349 "3331 Failed allocating per cpu cgn stats\n");
8351 goto out_free_hba_hdwq_info;
8355 * Enable sr-iov virtual functions if supported and configured
8356 * through the module parameter.
8358 if (phba->cfg_sriov_nr_virtfn > 0) {
8359 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
8360 phba->cfg_sriov_nr_virtfn);
8362 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8363 "3020 Requested number of SR-IOV "
8364 "virtual functions (%d) is not "
8366 phba->cfg_sriov_nr_virtfn);
8367 phba->cfg_sriov_nr_virtfn = 0;
8373 out_free_hba_hdwq_info:
8374 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8375 free_percpu(phba->sli4_hba.c_stat);
8376 out_free_hba_idle_stat:
8378 kfree(phba->sli4_hba.idle_stat);
8379 out_free_hba_eq_info:
8380 free_percpu(phba->sli4_hba.eq_info);
8381 out_free_hba_cpu_map:
8382 kfree(phba->sli4_hba.cpu_map);
8383 out_free_hba_eq_hdl:
8384 kfree(phba->sli4_hba.hba_eq_hdl);
8385 out_free_fcf_rr_bmask:
8386 kfree(phba->fcf.fcf_rr_bmask);
8387 out_remove_rpi_hdrs:
8388 lpfc_sli4_remove_rpi_hdrs(phba);
8389 out_free_active_sgl:
8390 lpfc_free_active_sgl(phba);
8391 out_destroy_cq_event_pool:
8392 lpfc_sli4_cq_event_pool_destroy(phba);
8393 out_free_cmd_rsp_buf:
8394 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
8395 phba->lpfc_cmd_rsp_buf_pool = NULL;
8396 out_free_sg_dma_buf:
8397 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
8398 phba->lpfc_sg_dma_buf_pool = NULL;
8400 lpfc_destroy_bootstrap_mbox(phba);
8402 lpfc_mem_free(phba);
8407 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
8408 * @phba: pointer to lpfc hba data structure.
8410 * This routine is invoked to unset the driver internal resources set up
8411 * specific for supporting the SLI-4 HBA device it attached to.
8414 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
8416 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
8418 free_percpu(phba->sli4_hba.eq_info);
8419 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8420 free_percpu(phba->sli4_hba.c_stat);
8422 free_percpu(phba->cmf_stat);
8423 kfree(phba->sli4_hba.idle_stat);
8425 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
8426 kfree(phba->sli4_hba.cpu_map);
8427 phba->sli4_hba.num_possible_cpu = 0;
8428 phba->sli4_hba.num_present_cpu = 0;
8429 phba->sli4_hba.curr_disp_cpu = 0;
8430 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
8432 /* Free memory allocated for fast-path work queue handles */
8433 kfree(phba->sli4_hba.hba_eq_hdl);
8435 /* Free the allocated rpi headers. */
8436 lpfc_sli4_remove_rpi_hdrs(phba);
8437 lpfc_sli4_remove_rpis(phba);
8439 /* Free eligible FCF index bmask */
8440 kfree(phba->fcf.fcf_rr_bmask);
8442 /* Free the ELS sgl list */
8443 lpfc_free_active_sgl(phba);
8444 lpfc_free_els_sgl_list(phba);
8445 lpfc_free_nvmet_sgl_list(phba);
8447 /* Free the completion queue EQ event pool */
8448 lpfc_sli4_cq_event_release_all(phba);
8449 lpfc_sli4_cq_event_pool_destroy(phba);
8451 /* Release resource identifiers. */
8452 lpfc_sli4_dealloc_resource_identifiers(phba);
8454 /* Free the bsmbx region. */
8455 lpfc_destroy_bootstrap_mbox(phba);
8457 /* Free the SLI Layer memory with SLI4 HBAs */
8458 lpfc_mem_free_all(phba);
8460 /* Free the current connect table */
8461 list_for_each_entry_safe(conn_entry, next_conn_entry,
8462 &phba->fcf_conn_rec_list, list) {
8463 list_del_init(&conn_entry->list);
8471 * lpfc_init_api_table_setup - Set up init api function jump table
8472 * @phba: The hba struct for which this call is being executed.
8473 * @dev_grp: The HBA PCI-Device group number.
8475 * This routine sets up the device INIT interface API function jump table
8478 * Returns: 0 - success, -ENODEV - failure.
8481 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8483 phba->lpfc_hba_init_link = lpfc_hba_init_link;
8484 phba->lpfc_hba_down_link = lpfc_hba_down_link;
8485 phba->lpfc_selective_reset = lpfc_selective_reset;
8487 case LPFC_PCI_DEV_LP:
8488 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
8489 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
8490 phba->lpfc_stop_port = lpfc_stop_port_s3;
8492 case LPFC_PCI_DEV_OC:
8493 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
8494 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
8495 phba->lpfc_stop_port = lpfc_stop_port_s4;
8498 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8499 "1431 Invalid HBA PCI-device group: 0x%x\n",
8507 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
8508 * @phba: pointer to lpfc hba data structure.
8510 * This routine is invoked to set up the driver internal resources after the
8511 * device specific resource setup to support the HBA device it attached to.
8515 * other values - error
8518 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
8522 /* Startup the kernel thread for this host adapter. */
8523 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8524 "lpfc_worker_%d", phba->brd_no);
8525 if (IS_ERR(phba->worker_thread)) {
8526 error = PTR_ERR(phba->worker_thread);
8534 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
8535 * @phba: pointer to lpfc hba data structure.
8537 * This routine is invoked to unset the driver internal resources set up after
8538 * the device specific resource setup for supporting the HBA device it
8542 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
8545 destroy_workqueue(phba->wq);
8549 /* Stop kernel worker thread */
8550 if (phba->worker_thread)
8551 kthread_stop(phba->worker_thread);
8555 * lpfc_free_iocb_list - Free iocb list.
8556 * @phba: pointer to lpfc hba data structure.
8558 * This routine is invoked to free the driver's IOCB list and memory.
8561 lpfc_free_iocb_list(struct lpfc_hba *phba)
8563 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
8565 spin_lock_irq(&phba->hbalock);
8566 list_for_each_entry_safe(iocbq_entry, iocbq_next,
8567 &phba->lpfc_iocb_list, list) {
8568 list_del(&iocbq_entry->list);
8570 phba->total_iocbq_bufs--;
8572 spin_unlock_irq(&phba->hbalock);
8578 * lpfc_init_iocb_list - Allocate and initialize iocb list.
8579 * @phba: pointer to lpfc hba data structure.
8580 * @iocb_count: number of requested iocbs
8582 * This routine is invoked to allocate and initizlize the driver's IOCB
8583 * list and set up the IOCB tag array accordingly.
8587 * other values - error
8590 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8592 struct lpfc_iocbq *iocbq_entry = NULL;
8596 /* Initialize and populate the iocb list per host. */
8597 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
8598 for (i = 0; i < iocb_count; i++) {
8599 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
8600 if (iocbq_entry == NULL) {
8601 printk(KERN_ERR "%s: only allocated %d iocbs of "
8602 "expected %d count. Unloading driver.\n",
8603 __func__, i, iocb_count);
8604 goto out_free_iocbq;
8607 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8610 printk(KERN_ERR "%s: failed to allocate IOTAG. "
8611 "Unloading driver.\n", __func__);
8612 goto out_free_iocbq;
8614 iocbq_entry->sli4_lxritag = NO_XRI;
8615 iocbq_entry->sli4_xritag = NO_XRI;
8617 spin_lock_irq(&phba->hbalock);
8618 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8619 phba->total_iocbq_bufs++;
8620 spin_unlock_irq(&phba->hbalock);
8626 lpfc_free_iocb_list(phba);
8632 * lpfc_free_sgl_list - Free a given sgl list.
8633 * @phba: pointer to lpfc hba data structure.
8634 * @sglq_list: pointer to the head of sgl list.
8636 * This routine is invoked to free a give sgl list and memory.
8639 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
8641 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8643 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8644 list_del(&sglq_entry->list);
8645 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8651 * lpfc_free_els_sgl_list - Free els sgl list.
8652 * @phba: pointer to lpfc hba data structure.
8654 * This routine is invoked to free the driver's els sgl list and memory.
8657 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8659 LIST_HEAD(sglq_list);
8661 /* Retrieve all els sgls from driver list */
8662 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
8663 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
8664 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
8666 /* Now free the sgl list */
8667 lpfc_free_sgl_list(phba, &sglq_list);
8671 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8672 * @phba: pointer to lpfc hba data structure.
8674 * This routine is invoked to free the driver's nvmet sgl list and memory.
8677 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8679 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8680 LIST_HEAD(sglq_list);
8682 /* Retrieve all nvmet sgls from driver list */
8683 spin_lock_irq(&phba->hbalock);
8684 spin_lock(&phba->sli4_hba.sgl_list_lock);
8685 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8686 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8687 spin_unlock_irq(&phba->hbalock);
8689 /* Now free the sgl list */
8690 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8691 list_del(&sglq_entry->list);
8692 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8696 /* Update the nvmet_xri_cnt to reflect no current sgls.
8697 * The next initialization cycle sets the count and allocates
8698 * the sgls over again.
8700 phba->sli4_hba.nvmet_xri_cnt = 0;
8704 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8705 * @phba: pointer to lpfc hba data structure.
8707 * This routine is invoked to allocate the driver's active sgl memory.
8708 * This array will hold the sglq_entry's for active IOs.
8711 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8714 size = sizeof(struct lpfc_sglq *);
8715 size *= phba->sli4_hba.max_cfg_param.max_xri;
8717 phba->sli4_hba.lpfc_sglq_active_list =
8718 kzalloc(size, GFP_KERNEL);
8719 if (!phba->sli4_hba.lpfc_sglq_active_list)
8725 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8726 * @phba: pointer to lpfc hba data structure.
8728 * This routine is invoked to walk through the array of active sglq entries
8729 * and free all of the resources.
8730 * This is just a place holder for now.
8733 lpfc_free_active_sgl(struct lpfc_hba *phba)
8735 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8739 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8740 * @phba: pointer to lpfc hba data structure.
8742 * This routine is invoked to allocate and initizlize the driver's sgl
8743 * list and set up the sgl xritag tag array accordingly.
8747 lpfc_init_sgl_list(struct lpfc_hba *phba)
8749 /* Initialize and populate the sglq list per host/VF. */
8750 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
8751 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8752 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
8753 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8755 /* els xri-sgl book keeping */
8756 phba->sli4_hba.els_xri_cnt = 0;
8758 /* nvme xri-buffer book keeping */
8759 phba->sli4_hba.io_xri_cnt = 0;
8763 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8764 * @phba: pointer to lpfc hba data structure.
8766 * This routine is invoked to post rpi header templates to the
8767 * port for those SLI4 ports that do not support extents. This routine
8768 * posts a PAGE_SIZE memory region to the port to hold up to
8769 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8770 * and should be called only when interrupts are disabled.
8774 * -ERROR - otherwise.
8777 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8780 struct lpfc_rpi_hdr *rpi_hdr;
8782 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
8783 if (!phba->sli4_hba.rpi_hdrs_in_use)
8785 if (phba->sli4_hba.extents_in_use)
8788 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8790 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8791 "0391 Error during rpi post operation\n");
8792 lpfc_sli4_remove_rpis(phba);
8800 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8801 * @phba: pointer to lpfc hba data structure.
8803 * This routine is invoked to allocate a single 4KB memory region to
8804 * support rpis and stores them in the phba. This single region
8805 * provides support for up to 64 rpis. The region is used globally
8809 * A valid rpi hdr on success.
8810 * A NULL pointer on any failure.
8812 struct lpfc_rpi_hdr *
8813 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8815 uint16_t rpi_limit, curr_rpi_range;
8816 struct lpfc_dmabuf *dmabuf;
8817 struct lpfc_rpi_hdr *rpi_hdr;
8820 * If the SLI4 port supports extents, posting the rpi header isn't
8821 * required. Set the expected maximum count and let the actual value
8822 * get set when extents are fully allocated.
8824 if (!phba->sli4_hba.rpi_hdrs_in_use)
8826 if (phba->sli4_hba.extents_in_use)
8829 /* The limit on the logical index is just the max_rpi count. */
8830 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
8832 spin_lock_irq(&phba->hbalock);
8834 * Establish the starting RPI in this header block. The starting
8835 * rpi is normalized to a zero base because the physical rpi is
8838 curr_rpi_range = phba->sli4_hba.next_rpi;
8839 spin_unlock_irq(&phba->hbalock);
8841 /* Reached full RPI range */
8842 if (curr_rpi_range == rpi_limit)
8846 * First allocate the protocol header region for the port. The
8847 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8849 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8853 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8854 LPFC_HDR_TEMPLATE_SIZE,
8855 &dmabuf->phys, GFP_KERNEL);
8856 if (!dmabuf->virt) {
8858 goto err_free_dmabuf;
8861 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
8863 goto err_free_coherent;
8866 /* Save the rpi header data for cleanup later. */
8867 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
8869 goto err_free_coherent;
8871 rpi_hdr->dmabuf = dmabuf;
8872 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
8873 rpi_hdr->page_count = 1;
8874 spin_lock_irq(&phba->hbalock);
8876 /* The rpi_hdr stores the logical index only. */
8877 rpi_hdr->start_rpi = curr_rpi_range;
8878 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
8879 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
8881 spin_unlock_irq(&phba->hbalock);
8885 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
8886 dmabuf->virt, dmabuf->phys);
8893 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
8894 * @phba: pointer to lpfc hba data structure.
8896 * This routine is invoked to remove all memory resources allocated
8897 * to support rpis for SLI4 ports not supporting extents. This routine
8898 * presumes the caller has released all rpis consumed by fabric or port
8899 * logins and is prepared to have the header pages removed.
8902 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
8904 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
8906 if (!phba->sli4_hba.rpi_hdrs_in_use)
8909 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
8910 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
8911 list_del(&rpi_hdr->list);
8912 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
8913 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
8914 kfree(rpi_hdr->dmabuf);
8918 /* There are no rpis available to the port now. */
8919 phba->sli4_hba.next_rpi = 0;
8923 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
8924 * @pdev: pointer to pci device data structure.
8926 * This routine is invoked to allocate the driver hba data structure for an
8927 * HBA device. If the allocation is successful, the phba reference to the
8928 * PCI device data structure is set.
8931 * pointer to @phba - successful
8934 static struct lpfc_hba *
8935 lpfc_hba_alloc(struct pci_dev *pdev)
8937 struct lpfc_hba *phba;
8939 /* Allocate memory for HBA structure */
8940 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
8942 dev_err(&pdev->dev, "failed to allocate hba struct\n");
8946 /* Set reference to PCI device in HBA structure */
8947 phba->pcidev = pdev;
8949 /* Assign an unused board number */
8950 phba->brd_no = lpfc_get_instance();
8951 if (phba->brd_no < 0) {
8955 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
8957 spin_lock_init(&phba->ct_ev_lock);
8958 INIT_LIST_HEAD(&phba->ct_ev_waiters);
8964 * lpfc_hba_free - Free driver hba data structure with a device.
8965 * @phba: pointer to lpfc hba data structure.
8967 * This routine is invoked to free the driver hba data structure with an
8971 lpfc_hba_free(struct lpfc_hba *phba)
8973 if (phba->sli_rev == LPFC_SLI_REV4)
8974 kfree(phba->sli4_hba.hdwq);
8976 /* Release the driver assigned board number */
8977 idr_remove(&lpfc_hba_index, phba->brd_no);
8979 /* Free memory allocated with sli3 rings */
8980 kfree(phba->sli.sli3_ring);
8981 phba->sli.sli3_ring = NULL;
8988 * lpfc_setup_fdmi_mask - Setup initial FDMI mask for HBA and Port attributes
8989 * @vport: pointer to lpfc vport data structure.
8991 * This routine is will setup initial FDMI attribute masks for
8992 * FDMI2 or SmartSAN depending on module parameters. The driver will attempt
8993 * to get these attributes first before falling back, the attribute
8994 * fallback hierarchy is SmartSAN -> FDMI2 -> FMDI1
8997 lpfc_setup_fdmi_mask(struct lpfc_vport *vport)
8999 struct lpfc_hba *phba = vport->phba;
9001 vport->load_flag |= FC_ALLOW_FDMI;
9002 if (phba->cfg_enable_SmartSAN ||
9003 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) {
9004 /* Setup appropriate attribute masks */
9005 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
9006 if (phba->cfg_enable_SmartSAN)
9007 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
9009 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
9012 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
9013 "6077 Setup FDMI mask: hba x%x port x%x\n",
9014 vport->fdmi_hba_mask, vport->fdmi_port_mask);
9018 * lpfc_create_shost - Create hba physical port with associated scsi host.
9019 * @phba: pointer to lpfc hba data structure.
9021 * This routine is invoked to create HBA physical port and associate a SCSI
9026 * other values - error
9029 lpfc_create_shost(struct lpfc_hba *phba)
9031 struct lpfc_vport *vport;
9032 struct Scsi_Host *shost;
9034 /* Initialize HBA FC structure */
9035 phba->fc_edtov = FF_DEF_EDTOV;
9036 phba->fc_ratov = FF_DEF_RATOV;
9037 phba->fc_altov = FF_DEF_ALTOV;
9038 phba->fc_arbtov = FF_DEF_ARBTOV;
9040 atomic_set(&phba->sdev_cnt, 0);
9041 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
9045 shost = lpfc_shost_from_vport(vport);
9046 phba->pport = vport;
9048 if (phba->nvmet_support) {
9049 /* Only 1 vport (pport) will support NVME target */
9050 phba->targetport = NULL;
9051 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
9052 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
9053 "6076 NVME Target Found\n");
9056 lpfc_debugfs_initialize(vport);
9057 /* Put reference to SCSI host to driver's device private data */
9058 pci_set_drvdata(phba->pcidev, shost);
9060 lpfc_setup_fdmi_mask(vport);
9063 * At this point we are fully registered with PSA. In addition,
9064 * any initial discovery should be completed.
9070 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
9071 * @phba: pointer to lpfc hba data structure.
9073 * This routine is invoked to destroy HBA physical port and the associated
9077 lpfc_destroy_shost(struct lpfc_hba *phba)
9079 struct lpfc_vport *vport = phba->pport;
9081 /* Destroy physical port that associated with the SCSI host */
9082 destroy_port(vport);
9088 * lpfc_setup_bg - Setup Block guard structures and debug areas.
9089 * @phba: pointer to lpfc hba data structure.
9090 * @shost: the shost to be used to detect Block guard settings.
9092 * This routine sets up the local Block guard protocol settings for @shost.
9093 * This routine also allocates memory for debugging bg buffers.
9096 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
9101 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9102 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9103 "1478 Registering BlockGuard with the "
9106 old_mask = phba->cfg_prot_mask;
9107 old_guard = phba->cfg_prot_guard;
9109 /* Only allow supported values */
9110 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
9111 SHOST_DIX_TYPE0_PROTECTION |
9112 SHOST_DIX_TYPE1_PROTECTION);
9113 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
9114 SHOST_DIX_GUARD_CRC);
9116 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
9117 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
9118 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
9120 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9121 if ((old_mask != phba->cfg_prot_mask) ||
9122 (old_guard != phba->cfg_prot_guard))
9123 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9124 "1475 Registering BlockGuard with the "
9125 "SCSI layer: mask %d guard %d\n",
9126 phba->cfg_prot_mask,
9127 phba->cfg_prot_guard);
9129 scsi_host_set_prot(shost, phba->cfg_prot_mask);
9130 scsi_host_set_guard(shost, phba->cfg_prot_guard);
9132 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9133 "1479 Not Registering BlockGuard with the SCSI "
9134 "layer, Bad protection parameters: %d %d\n",
9135 old_mask, old_guard);
9140 * lpfc_post_init_setup - Perform necessary device post initialization setup.
9141 * @phba: pointer to lpfc hba data structure.
9143 * This routine is invoked to perform all the necessary post initialization
9144 * setup for the device.
9147 lpfc_post_init_setup(struct lpfc_hba *phba)
9149 struct Scsi_Host *shost;
9150 struct lpfc_adapter_event_header adapter_event;
9152 /* Get the default values for Model Name and Description */
9153 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9156 * hba setup may have changed the hba_queue_depth so we need to
9157 * adjust the value of can_queue.
9159 shost = pci_get_drvdata(phba->pcidev);
9160 shost->can_queue = phba->cfg_hba_queue_depth - 10;
9162 lpfc_host_attrib_init(shost);
9164 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9165 spin_lock_irq(shost->host_lock);
9166 lpfc_poll_start_timer(phba);
9167 spin_unlock_irq(shost->host_lock);
9170 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9171 "0428 Perform SCSI scan\n");
9172 /* Send board arrival event to upper layer */
9173 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
9174 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
9175 fc_host_post_vendor_event(shost, fc_get_event_number(),
9176 sizeof(adapter_event),
9177 (char *) &adapter_event,
9183 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
9184 * @phba: pointer to lpfc hba data structure.
9186 * This routine is invoked to set up the PCI device memory space for device
9187 * with SLI-3 interface spec.
9191 * other values - error
9194 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
9196 struct pci_dev *pdev = phba->pcidev;
9197 unsigned long bar0map_len, bar2map_len;
9205 /* Set the device DMA mask size */
9206 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9208 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9213 /* Get the bus address of Bar0 and Bar2 and the number of bytes
9214 * required by each mapping.
9216 phba->pci_bar0_map = pci_resource_start(pdev, 0);
9217 bar0map_len = pci_resource_len(pdev, 0);
9219 phba->pci_bar2_map = pci_resource_start(pdev, 2);
9220 bar2map_len = pci_resource_len(pdev, 2);
9222 /* Map HBA SLIM to a kernel virtual address. */
9223 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
9224 if (!phba->slim_memmap_p) {
9225 dev_printk(KERN_ERR, &pdev->dev,
9226 "ioremap failed for SLIM memory.\n");
9230 /* Map HBA Control Registers to a kernel virtual address. */
9231 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
9232 if (!phba->ctrl_regs_memmap_p) {
9233 dev_printk(KERN_ERR, &pdev->dev,
9234 "ioremap failed for HBA control registers.\n");
9235 goto out_iounmap_slim;
9238 /* Allocate memory for SLI-2 structures */
9239 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9240 &phba->slim2p.phys, GFP_KERNEL);
9241 if (!phba->slim2p.virt)
9244 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
9245 phba->mbox_ext = (phba->slim2p.virt +
9246 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
9247 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
9248 phba->IOCBs = (phba->slim2p.virt +
9249 offsetof(struct lpfc_sli2_slim, IOCBs));
9251 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
9252 lpfc_sli_hbq_size(),
9253 &phba->hbqslimp.phys,
9255 if (!phba->hbqslimp.virt)
9258 hbq_count = lpfc_sli_hbq_count();
9259 ptr = phba->hbqslimp.virt;
9260 for (i = 0; i < hbq_count; ++i) {
9261 phba->hbqs[i].hbq_virt = ptr;
9262 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
9263 ptr += (lpfc_hbq_defs[i]->entry_count *
9264 sizeof(struct lpfc_hbq_entry));
9266 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
9267 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
9269 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
9271 phba->MBslimaddr = phba->slim_memmap_p;
9272 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
9273 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
9274 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
9275 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
9280 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9281 phba->slim2p.virt, phba->slim2p.phys);
9283 iounmap(phba->ctrl_regs_memmap_p);
9285 iounmap(phba->slim_memmap_p);
9291 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
9292 * @phba: pointer to lpfc hba data structure.
9294 * This routine is invoked to unset the PCI device memory space for device
9295 * with SLI-3 interface spec.
9298 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
9300 struct pci_dev *pdev;
9302 /* Obtain PCI device reference */
9306 pdev = phba->pcidev;
9308 /* Free coherent DMA memory allocated */
9309 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9310 phba->hbqslimp.virt, phba->hbqslimp.phys);
9311 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9312 phba->slim2p.virt, phba->slim2p.phys);
9314 /* I/O memory unmap */
9315 iounmap(phba->ctrl_regs_memmap_p);
9316 iounmap(phba->slim_memmap_p);
9322 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
9323 * @phba: pointer to lpfc hba data structure.
9325 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
9326 * done and check status.
9328 * Return 0 if successful, otherwise -ENODEV.
9331 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
9333 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
9334 struct lpfc_register reg_data;
9335 int i, port_error = 0;
9338 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
9339 memset(®_data, 0, sizeof(reg_data));
9340 if (!phba->sli4_hba.PSMPHRregaddr)
9343 /* Wait up to 30 seconds for the SLI Port POST done and ready */
9344 for (i = 0; i < 3000; i++) {
9345 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9346 &portsmphr_reg.word0) ||
9347 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
9348 /* Port has a fatal POST error, break out */
9349 port_error = -ENODEV;
9352 if (LPFC_POST_STAGE_PORT_READY ==
9353 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
9359 * If there was a port error during POST, then don't proceed with
9360 * other register reads as the data may not be valid. Just exit.
9363 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9364 "1408 Port Failed POST - portsmphr=0x%x, "
9365 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
9366 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
9367 portsmphr_reg.word0,
9368 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
9369 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
9370 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
9371 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
9372 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
9373 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
9374 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
9375 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
9377 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9378 "2534 Device Info: SLIFamily=0x%x, "
9379 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
9380 "SLIHint_2=0x%x, FT=0x%x\n",
9381 bf_get(lpfc_sli_intf_sli_family,
9382 &phba->sli4_hba.sli_intf),
9383 bf_get(lpfc_sli_intf_slirev,
9384 &phba->sli4_hba.sli_intf),
9385 bf_get(lpfc_sli_intf_if_type,
9386 &phba->sli4_hba.sli_intf),
9387 bf_get(lpfc_sli_intf_sli_hint1,
9388 &phba->sli4_hba.sli_intf),
9389 bf_get(lpfc_sli_intf_sli_hint2,
9390 &phba->sli4_hba.sli_intf),
9391 bf_get(lpfc_sli_intf_func_type,
9392 &phba->sli4_hba.sli_intf));
9394 * Check for other Port errors during the initialization
9395 * process. Fail the load if the port did not come up
9398 if_type = bf_get(lpfc_sli_intf_if_type,
9399 &phba->sli4_hba.sli_intf);
9401 case LPFC_SLI_INTF_IF_TYPE_0:
9402 phba->sli4_hba.ue_mask_lo =
9403 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
9404 phba->sli4_hba.ue_mask_hi =
9405 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
9407 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
9409 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
9410 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
9411 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
9412 lpfc_printf_log(phba, KERN_ERR,
9414 "1422 Unrecoverable Error "
9415 "Detected during POST "
9416 "uerr_lo_reg=0x%x, "
9417 "uerr_hi_reg=0x%x, "
9418 "ue_mask_lo_reg=0x%x, "
9419 "ue_mask_hi_reg=0x%x\n",
9422 phba->sli4_hba.ue_mask_lo,
9423 phba->sli4_hba.ue_mask_hi);
9424 port_error = -ENODEV;
9427 case LPFC_SLI_INTF_IF_TYPE_2:
9428 case LPFC_SLI_INTF_IF_TYPE_6:
9429 /* Final checks. The port status should be clean. */
9430 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9432 (bf_get(lpfc_sliport_status_err, ®_data) &&
9433 !bf_get(lpfc_sliport_status_rn, ®_data))) {
9434 phba->work_status[0] =
9435 readl(phba->sli4_hba.u.if_type2.
9437 phba->work_status[1] =
9438 readl(phba->sli4_hba.u.if_type2.
9440 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9441 "2888 Unrecoverable port error "
9442 "following POST: port status reg "
9443 "0x%x, port_smphr reg 0x%x, "
9444 "error 1=0x%x, error 2=0x%x\n",
9446 portsmphr_reg.word0,
9447 phba->work_status[0],
9448 phba->work_status[1]);
9449 port_error = -ENODEV;
9453 if (lpfc_pldv_detect &&
9454 bf_get(lpfc_sli_intf_sli_family,
9455 &phba->sli4_hba.sli_intf) ==
9456 LPFC_SLI_INTF_FAMILY_G6)
9457 pci_write_config_byte(phba->pcidev,
9458 LPFC_SLI_INTF, CFG_PLD);
9460 case LPFC_SLI_INTF_IF_TYPE_1:
9469 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
9470 * @phba: pointer to lpfc hba data structure.
9471 * @if_type: The SLI4 interface type getting configured.
9473 * This routine is invoked to set up SLI4 BAR0 PCI config space register
9477 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9480 case LPFC_SLI_INTF_IF_TYPE_0:
9481 phba->sli4_hba.u.if_type0.UERRLOregaddr =
9482 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
9483 phba->sli4_hba.u.if_type0.UERRHIregaddr =
9484 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
9485 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
9486 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
9487 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
9488 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
9489 phba->sli4_hba.SLIINTFregaddr =
9490 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9492 case LPFC_SLI_INTF_IF_TYPE_2:
9493 phba->sli4_hba.u.if_type2.EQDregaddr =
9494 phba->sli4_hba.conf_regs_memmap_p +
9495 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9496 phba->sli4_hba.u.if_type2.ERR1regaddr =
9497 phba->sli4_hba.conf_regs_memmap_p +
9498 LPFC_CTL_PORT_ER1_OFFSET;
9499 phba->sli4_hba.u.if_type2.ERR2regaddr =
9500 phba->sli4_hba.conf_regs_memmap_p +
9501 LPFC_CTL_PORT_ER2_OFFSET;
9502 phba->sli4_hba.u.if_type2.CTRLregaddr =
9503 phba->sli4_hba.conf_regs_memmap_p +
9504 LPFC_CTL_PORT_CTL_OFFSET;
9505 phba->sli4_hba.u.if_type2.STATUSregaddr =
9506 phba->sli4_hba.conf_regs_memmap_p +
9507 LPFC_CTL_PORT_STA_OFFSET;
9508 phba->sli4_hba.SLIINTFregaddr =
9509 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9510 phba->sli4_hba.PSMPHRregaddr =
9511 phba->sli4_hba.conf_regs_memmap_p +
9512 LPFC_CTL_PORT_SEM_OFFSET;
9513 phba->sli4_hba.RQDBregaddr =
9514 phba->sli4_hba.conf_regs_memmap_p +
9515 LPFC_ULP0_RQ_DOORBELL;
9516 phba->sli4_hba.WQDBregaddr =
9517 phba->sli4_hba.conf_regs_memmap_p +
9518 LPFC_ULP0_WQ_DOORBELL;
9519 phba->sli4_hba.CQDBregaddr =
9520 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
9521 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9522 phba->sli4_hba.MQDBregaddr =
9523 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
9524 phba->sli4_hba.BMBXregaddr =
9525 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9527 case LPFC_SLI_INTF_IF_TYPE_6:
9528 phba->sli4_hba.u.if_type2.EQDregaddr =
9529 phba->sli4_hba.conf_regs_memmap_p +
9530 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9531 phba->sli4_hba.u.if_type2.ERR1regaddr =
9532 phba->sli4_hba.conf_regs_memmap_p +
9533 LPFC_CTL_PORT_ER1_OFFSET;
9534 phba->sli4_hba.u.if_type2.ERR2regaddr =
9535 phba->sli4_hba.conf_regs_memmap_p +
9536 LPFC_CTL_PORT_ER2_OFFSET;
9537 phba->sli4_hba.u.if_type2.CTRLregaddr =
9538 phba->sli4_hba.conf_regs_memmap_p +
9539 LPFC_CTL_PORT_CTL_OFFSET;
9540 phba->sli4_hba.u.if_type2.STATUSregaddr =
9541 phba->sli4_hba.conf_regs_memmap_p +
9542 LPFC_CTL_PORT_STA_OFFSET;
9543 phba->sli4_hba.PSMPHRregaddr =
9544 phba->sli4_hba.conf_regs_memmap_p +
9545 LPFC_CTL_PORT_SEM_OFFSET;
9546 phba->sli4_hba.BMBXregaddr =
9547 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9549 case LPFC_SLI_INTF_IF_TYPE_1:
9551 dev_printk(KERN_ERR, &phba->pcidev->dev,
9552 "FATAL - unsupported SLI4 interface type - %d\n",
9559 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
9560 * @phba: pointer to lpfc hba data structure.
9561 * @if_type: sli if type to operate on.
9563 * This routine is invoked to set up SLI4 BAR1 register memory map.
9566 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9569 case LPFC_SLI_INTF_IF_TYPE_0:
9570 phba->sli4_hba.PSMPHRregaddr =
9571 phba->sli4_hba.ctrl_regs_memmap_p +
9572 LPFC_SLIPORT_IF0_SMPHR;
9573 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9575 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9577 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9580 case LPFC_SLI_INTF_IF_TYPE_6:
9581 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9582 LPFC_IF6_RQ_DOORBELL;
9583 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9584 LPFC_IF6_WQ_DOORBELL;
9585 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9586 LPFC_IF6_CQ_DOORBELL;
9587 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9588 LPFC_IF6_EQ_DOORBELL;
9589 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9590 LPFC_IF6_MQ_DOORBELL;
9592 case LPFC_SLI_INTF_IF_TYPE_2:
9593 case LPFC_SLI_INTF_IF_TYPE_1:
9595 dev_err(&phba->pcidev->dev,
9596 "FATAL - unsupported SLI4 interface type - %d\n",
9603 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
9604 * @phba: pointer to lpfc hba data structure.
9605 * @vf: virtual function number
9607 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
9608 * based on the given viftual function number, @vf.
9610 * Return 0 if successful, otherwise -ENODEV.
9613 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9615 if (vf > LPFC_VIR_FUNC_MAX)
9618 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9619 vf * LPFC_VFR_PAGE_SIZE +
9620 LPFC_ULP0_RQ_DOORBELL);
9621 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9622 vf * LPFC_VFR_PAGE_SIZE +
9623 LPFC_ULP0_WQ_DOORBELL);
9624 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9625 vf * LPFC_VFR_PAGE_SIZE +
9626 LPFC_EQCQ_DOORBELL);
9627 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9628 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9629 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9630 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9631 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9636 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9637 * @phba: pointer to lpfc hba data structure.
9639 * This routine is invoked to create the bootstrap mailbox
9640 * region consistent with the SLI-4 interface spec. This
9641 * routine allocates all memory necessary to communicate
9642 * mailbox commands to the port and sets up all alignment
9643 * needs. No locks are expected to be held when calling
9648 * -ENOMEM - could not allocated memory.
9651 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9654 struct lpfc_dmabuf *dmabuf;
9655 struct dma_address *dma_address;
9659 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9664 * The bootstrap mailbox region is comprised of 2 parts
9665 * plus an alignment restriction of 16 bytes.
9667 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
9668 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9669 &dmabuf->phys, GFP_KERNEL);
9670 if (!dmabuf->virt) {
9676 * Initialize the bootstrap mailbox pointers now so that the register
9677 * operations are simple later. The mailbox dma address is required
9678 * to be 16-byte aligned. Also align the virtual memory as each
9679 * maibox is copied into the bmbx mailbox region before issuing the
9680 * command to the port.
9682 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9683 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9685 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9686 LPFC_ALIGN_16_BYTE);
9687 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9688 LPFC_ALIGN_16_BYTE);
9691 * Set the high and low physical addresses now. The SLI4 alignment
9692 * requirement is 16 bytes and the mailbox is posted to the port
9693 * as two 30-bit addresses. The other data is a bit marking whether
9694 * the 30-bit address is the high or low address.
9695 * Upcast bmbx aphys to 64bits so shift instruction compiles
9696 * clean on 32 bit machines.
9698 dma_address = &phba->sli4_hba.bmbx.dma_address;
9699 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9700 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9701 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9702 LPFC_BMBX_BIT1_ADDR_HI);
9704 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9705 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9706 LPFC_BMBX_BIT1_ADDR_LO);
9711 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9712 * @phba: pointer to lpfc hba data structure.
9714 * This routine is invoked to teardown the bootstrap mailbox
9715 * region and release all host resources. This routine requires
9716 * the caller to ensure all mailbox commands recovered, no
9717 * additional mailbox comands are sent, and interrupts are disabled
9718 * before calling this routine.
9722 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9724 dma_free_coherent(&phba->pcidev->dev,
9725 phba->sli4_hba.bmbx.bmbx_size,
9726 phba->sli4_hba.bmbx.dmabuf->virt,
9727 phba->sli4_hba.bmbx.dmabuf->phys);
9729 kfree(phba->sli4_hba.bmbx.dmabuf);
9730 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9733 static const char * const lpfc_topo_to_str[] = {
9743 #define LINK_FLAGS_DEF 0x0
9744 #define LINK_FLAGS_P2P 0x1
9745 #define LINK_FLAGS_LOOP 0x2
9747 * lpfc_map_topology - Map the topology read from READ_CONFIG
9748 * @phba: pointer to lpfc hba data structure.
9749 * @rd_config: pointer to read config data
9751 * This routine is invoked to map the topology values as read
9752 * from the read config mailbox command. If the persistent
9753 * topology feature is supported, the firmware will provide the
9754 * saved topology information to be used in INIT_LINK
9757 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9761 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9762 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9763 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9765 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9766 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9769 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9770 "2019 FW does not support persistent topology "
9771 "Using driver parameter defined value [%s]",
9772 lpfc_topo_to_str[phba->cfg_topology]);
9775 /* FW supports persistent topology - override module parameter value */
9776 phba->hba_flag |= HBA_PERSISTENT_TOPO;
9778 /* if ASIC_GEN_NUM >= 0xC) */
9779 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9780 LPFC_SLI_INTF_IF_TYPE_6) ||
9781 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9782 LPFC_SLI_INTF_FAMILY_G6)) {
9784 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9785 ? FLAGS_TOPOLOGY_MODE_LOOP
9786 : FLAGS_TOPOLOGY_MODE_PT_PT);
9788 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
9792 /* If topology failover set - pt is '0' or '1' */
9793 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9794 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9796 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9797 ? FLAGS_TOPOLOGY_MODE_PT_PT
9798 : FLAGS_TOPOLOGY_MODE_LOOP);
9801 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
9802 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9803 "2020 Using persistent topology value [%s]",
9804 lpfc_topo_to_str[phba->cfg_topology]);
9806 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9807 "2021 Invalid topology values from FW "
9808 "Using driver parameter defined value [%s]",
9809 lpfc_topo_to_str[phba->cfg_topology]);
9814 * lpfc_sli4_read_config - Get the config parameters.
9815 * @phba: pointer to lpfc hba data structure.
9817 * This routine is invoked to read the configuration parameters from the HBA.
9818 * The configuration parameters are used to set the base and maximum values
9819 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9820 * allocation for the port.
9824 * -ENOMEM - No available memory
9825 * -EIO - The mailbox failed to complete successfully.
9828 lpfc_sli4_read_config(struct lpfc_hba *phba)
9831 struct lpfc_mbx_read_config *rd_config;
9832 union lpfc_sli4_cfg_shdr *shdr;
9833 uint32_t shdr_status, shdr_add_status;
9834 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9835 struct lpfc_rsrc_desc_fcfcoe *desc;
9837 uint16_t forced_link_speed;
9838 uint32_t if_type, qmin, fawwpn;
9839 int length, i, rc = 0, rc2;
9841 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9843 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9844 "2011 Unable to allocate memory for issuing "
9845 "SLI_CONFIG_SPECIAL mailbox command\n");
9849 lpfc_read_config(phba, pmb);
9851 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9852 if (rc != MBX_SUCCESS) {
9853 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9854 "2012 Mailbox failed , mbxCmd x%x "
9855 "READ_CONFIG, mbxStatus x%x\n",
9856 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9857 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9860 rd_config = &pmb->u.mqe.un.rd_config;
9861 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9862 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
9863 phba->sli4_hba.lnk_info.lnk_tp =
9864 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
9865 phba->sli4_hba.lnk_info.lnk_no =
9866 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
9867 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9868 "3081 lnk_type:%d, lnk_numb:%d\n",
9869 phba->sli4_hba.lnk_info.lnk_tp,
9870 phba->sli4_hba.lnk_info.lnk_no);
9872 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9873 "3082 Mailbox (x%x) returned ldv:x0\n",
9874 bf_get(lpfc_mqe_command, &pmb->u.mqe));
9875 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
9876 phba->bbcredit_support = 1;
9877 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
9880 fawwpn = bf_get(lpfc_mbx_rd_conf_fawwpn, rd_config);
9883 lpfc_printf_log(phba, KERN_INFO,
9884 LOG_INIT | LOG_DISCOVERY,
9885 "2702 READ_CONFIG: FA-PWWN is "
9887 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_CONFIG;
9889 phba->sli4_hba.fawwpn_flag = 0;
9892 phba->sli4_hba.conf_trunk =
9893 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
9894 phba->sli4_hba.extents_in_use =
9895 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
9897 phba->sli4_hba.max_cfg_param.max_xri =
9898 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
9899 /* Reduce resource usage in kdump environment */
9900 if (is_kdump_kernel() &&
9901 phba->sli4_hba.max_cfg_param.max_xri > 512)
9902 phba->sli4_hba.max_cfg_param.max_xri = 512;
9903 phba->sli4_hba.max_cfg_param.xri_base =
9904 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
9905 phba->sli4_hba.max_cfg_param.max_vpi =
9906 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
9907 /* Limit the max we support */
9908 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
9909 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
9910 phba->sli4_hba.max_cfg_param.vpi_base =
9911 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
9912 phba->sli4_hba.max_cfg_param.max_rpi =
9913 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
9914 phba->sli4_hba.max_cfg_param.rpi_base =
9915 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
9916 phba->sli4_hba.max_cfg_param.max_vfi =
9917 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
9918 phba->sli4_hba.max_cfg_param.vfi_base =
9919 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
9920 phba->sli4_hba.max_cfg_param.max_fcfi =
9921 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
9922 phba->sli4_hba.max_cfg_param.max_eq =
9923 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
9924 phba->sli4_hba.max_cfg_param.max_rq =
9925 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
9926 phba->sli4_hba.max_cfg_param.max_wq =
9927 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
9928 phba->sli4_hba.max_cfg_param.max_cq =
9929 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
9930 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
9931 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
9932 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
9933 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
9934 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
9935 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
9936 phba->max_vports = phba->max_vpi;
9938 /* Next decide on FPIN or Signal E2E CGN support
9939 * For congestion alarms and warnings valid combination are:
9940 * 1. FPIN alarms / FPIN warnings
9941 * 2. Signal alarms / Signal warnings
9942 * 3. FPIN alarms / Signal warnings
9943 * 4. Signal alarms / FPIN warnings
9945 * Initialize the adapter frequency to 100 mSecs
9947 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9948 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9949 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9951 if (lpfc_use_cgn_signal) {
9952 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
9953 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
9954 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
9956 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
9957 /* MUST support both alarm and warning
9958 * because EDC does not support alarm alone.
9960 if (phba->cgn_reg_signal !=
9961 EDC_CG_SIG_WARN_ONLY) {
9962 /* Must support both or none */
9963 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9964 phba->cgn_reg_signal =
9965 EDC_CG_SIG_NOTSUPPORTED;
9967 phba->cgn_reg_signal =
9968 EDC_CG_SIG_WARN_ALARM;
9969 phba->cgn_reg_fpin =
9975 /* Set the congestion initial signal and fpin values. */
9976 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
9977 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
9979 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
9980 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
9981 phba->cgn_reg_signal, phba->cgn_reg_fpin);
9983 lpfc_map_topology(phba, rd_config);
9984 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9985 "2003 cfg params Extents? %d "
9990 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
9991 phba->sli4_hba.extents_in_use,
9992 phba->sli4_hba.max_cfg_param.xri_base,
9993 phba->sli4_hba.max_cfg_param.max_xri,
9994 phba->sli4_hba.max_cfg_param.vpi_base,
9995 phba->sli4_hba.max_cfg_param.max_vpi,
9996 phba->sli4_hba.max_cfg_param.vfi_base,
9997 phba->sli4_hba.max_cfg_param.max_vfi,
9998 phba->sli4_hba.max_cfg_param.rpi_base,
9999 phba->sli4_hba.max_cfg_param.max_rpi,
10000 phba->sli4_hba.max_cfg_param.max_fcfi,
10001 phba->sli4_hba.max_cfg_param.max_eq,
10002 phba->sli4_hba.max_cfg_param.max_cq,
10003 phba->sli4_hba.max_cfg_param.max_wq,
10004 phba->sli4_hba.max_cfg_param.max_rq,
10008 * Calculate queue resources based on how
10009 * many WQ/CQ/EQs are available.
10011 qmin = phba->sli4_hba.max_cfg_param.max_wq;
10012 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
10013 qmin = phba->sli4_hba.max_cfg_param.max_cq;
10014 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
10015 qmin = phba->sli4_hba.max_cfg_param.max_eq;
10017 * Whats left after this can go toward NVME / FCP.
10018 * The minus 4 accounts for ELS, NVME LS, MBOX
10019 * plus one extra. When configured for
10020 * NVMET, FCP io channel WQs are not created.
10024 /* Check to see if there is enough for NVME */
10025 if ((phba->cfg_irq_chann > qmin) ||
10026 (phba->cfg_hdw_queue > qmin)) {
10027 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10028 "2005 Reducing Queues - "
10029 "FW resource limitation: "
10030 "WQ %d CQ %d EQ %d: min %d: "
10031 "IRQ %d HDWQ %d\n",
10032 phba->sli4_hba.max_cfg_param.max_wq,
10033 phba->sli4_hba.max_cfg_param.max_cq,
10034 phba->sli4_hba.max_cfg_param.max_eq,
10035 qmin, phba->cfg_irq_chann,
10036 phba->cfg_hdw_queue);
10038 if (phba->cfg_irq_chann > qmin)
10039 phba->cfg_irq_chann = qmin;
10040 if (phba->cfg_hdw_queue > qmin)
10041 phba->cfg_hdw_queue = qmin;
10048 /* Update link speed if forced link speed is supported */
10049 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10050 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10051 forced_link_speed =
10052 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
10053 if (forced_link_speed) {
10054 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
10056 switch (forced_link_speed) {
10057 case LINK_SPEED_1G:
10058 phba->cfg_link_speed =
10059 LPFC_USER_LINK_SPEED_1G;
10061 case LINK_SPEED_2G:
10062 phba->cfg_link_speed =
10063 LPFC_USER_LINK_SPEED_2G;
10065 case LINK_SPEED_4G:
10066 phba->cfg_link_speed =
10067 LPFC_USER_LINK_SPEED_4G;
10069 case LINK_SPEED_8G:
10070 phba->cfg_link_speed =
10071 LPFC_USER_LINK_SPEED_8G;
10073 case LINK_SPEED_10G:
10074 phba->cfg_link_speed =
10075 LPFC_USER_LINK_SPEED_10G;
10077 case LINK_SPEED_16G:
10078 phba->cfg_link_speed =
10079 LPFC_USER_LINK_SPEED_16G;
10081 case LINK_SPEED_32G:
10082 phba->cfg_link_speed =
10083 LPFC_USER_LINK_SPEED_32G;
10085 case LINK_SPEED_64G:
10086 phba->cfg_link_speed =
10087 LPFC_USER_LINK_SPEED_64G;
10090 phba->cfg_link_speed =
10091 LPFC_USER_LINK_SPEED_AUTO;
10094 lpfc_printf_log(phba, KERN_ERR,
10096 "0047 Unrecognized link "
10098 forced_link_speed);
10099 phba->cfg_link_speed =
10100 LPFC_USER_LINK_SPEED_AUTO;
10105 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
10106 length = phba->sli4_hba.max_cfg_param.max_xri -
10107 lpfc_sli4_get_els_iocb_cnt(phba);
10108 if (phba->cfg_hba_queue_depth > length) {
10109 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10110 "3361 HBA queue depth changed from %d to %d\n",
10111 phba->cfg_hba_queue_depth, length);
10112 phba->cfg_hba_queue_depth = length;
10115 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
10116 LPFC_SLI_INTF_IF_TYPE_2)
10119 /* get the pf# and vf# for SLI4 if_type 2 port */
10120 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
10121 sizeof(struct lpfc_sli4_cfg_mhdr));
10122 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
10123 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
10124 length, LPFC_SLI4_MBX_EMBED);
10126 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10127 shdr = (union lpfc_sli4_cfg_shdr *)
10128 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
10129 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10130 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10131 if (rc2 || shdr_status || shdr_add_status) {
10132 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10133 "3026 Mailbox failed , mbxCmd x%x "
10134 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
10135 bf_get(lpfc_mqe_command, &pmb->u.mqe),
10136 bf_get(lpfc_mqe_status, &pmb->u.mqe));
10140 /* search for fc_fcoe resrouce descriptor */
10141 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
10143 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
10144 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
10145 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
10146 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
10147 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
10148 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
10151 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
10152 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
10153 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
10154 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
10155 phba->sli4_hba.iov.pf_number =
10156 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
10157 phba->sli4_hba.iov.vf_number =
10158 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
10163 if (i < LPFC_RSRC_DESC_MAX_NUM)
10164 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10165 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
10166 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
10167 phba->sli4_hba.iov.vf_number);
10169 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10170 "3028 GET_FUNCTION_CONFIG: failed to find "
10171 "Resource Descriptor:x%x\n",
10172 LPFC_RSRC_DESC_TYPE_FCFCOE);
10175 mempool_free(pmb, phba->mbox_mem_pool);
10180 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
10181 * @phba: pointer to lpfc hba data structure.
10183 * This routine is invoked to setup the port-side endian order when
10184 * the port if_type is 0. This routine has no function for other
10189 * -ENOMEM - No available memory
10190 * -EIO - The mailbox failed to complete successfully.
10193 lpfc_setup_endian_order(struct lpfc_hba *phba)
10195 LPFC_MBOXQ_t *mboxq;
10196 uint32_t if_type, rc = 0;
10197 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
10198 HOST_ENDIAN_HIGH_WORD1};
10200 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10202 case LPFC_SLI_INTF_IF_TYPE_0:
10203 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10206 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10207 "0492 Unable to allocate memory for "
10208 "issuing SLI_CONFIG_SPECIAL mailbox "
10214 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
10215 * two words to contain special data values and no other data.
10217 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
10218 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
10219 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10220 if (rc != MBX_SUCCESS) {
10221 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10222 "0493 SLI_CONFIG_SPECIAL mailbox "
10223 "failed with status x%x\n",
10227 mempool_free(mboxq, phba->mbox_mem_pool);
10229 case LPFC_SLI_INTF_IF_TYPE_6:
10230 case LPFC_SLI_INTF_IF_TYPE_2:
10231 case LPFC_SLI_INTF_IF_TYPE_1:
10239 * lpfc_sli4_queue_verify - Verify and update EQ counts
10240 * @phba: pointer to lpfc hba data structure.
10242 * This routine is invoked to check the user settable queue counts for EQs.
10243 * After this routine is called the counts will be set to valid values that
10244 * adhere to the constraints of the system's interrupt vectors and the port's
10249 * -ENOMEM - No available memory
10252 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
10255 * Sanity check for configured queue parameters against the run-time
10256 * device parameters
10259 if (phba->nvmet_support) {
10260 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
10261 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
10262 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
10263 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
10266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10267 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
10268 phba->cfg_hdw_queue, phba->cfg_irq_chann,
10269 phba->cfg_nvmet_mrq);
10271 /* Get EQ depth from module parameter, fake the default for now */
10272 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10273 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10275 /* Get CQ depth from module parameter, fake the default for now */
10276 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10277 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10282 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
10284 struct lpfc_queue *qdesc;
10288 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
10289 /* Create Fast Path IO CQs */
10290 if (phba->enab_exp_wqcq_pages)
10291 /* Increase the CQ size when WQEs contain an embedded cdb */
10292 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10293 phba->sli4_hba.cq_esize,
10294 LPFC_CQE_EXP_COUNT, cpu);
10297 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10298 phba->sli4_hba.cq_esize,
10299 phba->sli4_hba.cq_ecount, cpu);
10301 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10302 "0499 Failed allocate fast-path IO CQ (%d)\n",
10306 qdesc->qe_valid = 1;
10308 qdesc->chann = cpu;
10309 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
10311 /* Create Fast Path IO WQs */
10312 if (phba->enab_exp_wqcq_pages) {
10313 /* Increase the WQ size when WQEs contain an embedded cdb */
10314 wqesize = (phba->fcp_embed_io) ?
10315 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
10316 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10318 LPFC_WQE_EXP_COUNT, cpu);
10320 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10321 phba->sli4_hba.wq_esize,
10322 phba->sli4_hba.wq_ecount, cpu);
10325 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10326 "0503 Failed allocate fast-path IO WQ (%d)\n",
10331 qdesc->chann = cpu;
10332 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
10333 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10338 * lpfc_sli4_queue_create - Create all the SLI4 queues
10339 * @phba: pointer to lpfc hba data structure.
10341 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
10342 * operation. For each SLI4 queue type, the parameters such as queue entry
10343 * count (queue depth) shall be taken from the module parameter. For now,
10344 * we just use some constant number as place holder.
10348 * -ENOMEM - No availble memory
10349 * -EIO - The mailbox failed to complete successfully.
10352 lpfc_sli4_queue_create(struct lpfc_hba *phba)
10354 struct lpfc_queue *qdesc;
10355 int idx, cpu, eqcpu;
10356 struct lpfc_sli4_hdw_queue *qp;
10357 struct lpfc_vector_map_info *cpup;
10358 struct lpfc_vector_map_info *eqcpup;
10359 struct lpfc_eq_intr_info *eqi;
10362 * Create HBA Record arrays.
10363 * Both NVME and FCP will share that same vectors / EQs
10365 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
10366 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
10367 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
10368 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
10369 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
10370 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
10371 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10372 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10373 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10374 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10376 if (!phba->sli4_hba.hdwq) {
10377 phba->sli4_hba.hdwq = kcalloc(
10378 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
10380 if (!phba->sli4_hba.hdwq) {
10381 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10382 "6427 Failed allocate memory for "
10383 "fast-path Hardware Queue array\n");
10386 /* Prepare hardware queues to take IO buffers */
10387 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10388 qp = &phba->sli4_hba.hdwq[idx];
10389 spin_lock_init(&qp->io_buf_list_get_lock);
10390 spin_lock_init(&qp->io_buf_list_put_lock);
10391 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
10392 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
10393 qp->get_io_bufs = 0;
10394 qp->put_io_bufs = 0;
10395 qp->total_io_bufs = 0;
10396 spin_lock_init(&qp->abts_io_buf_list_lock);
10397 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
10398 qp->abts_scsi_io_bufs = 0;
10399 qp->abts_nvme_io_bufs = 0;
10400 INIT_LIST_HEAD(&qp->sgl_list);
10401 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
10402 spin_lock_init(&qp->hdwq_lock);
10406 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10407 if (phba->nvmet_support) {
10408 phba->sli4_hba.nvmet_cqset = kcalloc(
10409 phba->cfg_nvmet_mrq,
10410 sizeof(struct lpfc_queue *),
10412 if (!phba->sli4_hba.nvmet_cqset) {
10413 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10414 "3121 Fail allocate memory for "
10415 "fast-path CQ set array\n");
10418 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
10419 phba->cfg_nvmet_mrq,
10420 sizeof(struct lpfc_queue *),
10422 if (!phba->sli4_hba.nvmet_mrq_hdr) {
10423 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10424 "3122 Fail allocate memory for "
10425 "fast-path RQ set hdr array\n");
10428 phba->sli4_hba.nvmet_mrq_data = kcalloc(
10429 phba->cfg_nvmet_mrq,
10430 sizeof(struct lpfc_queue *),
10432 if (!phba->sli4_hba.nvmet_mrq_data) {
10433 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10434 "3124 Fail allocate memory for "
10435 "fast-path RQ set data array\n");
10441 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10443 /* Create HBA Event Queues (EQs) */
10444 for_each_present_cpu(cpu) {
10445 /* We only want to create 1 EQ per vector, even though
10446 * multiple CPUs might be using that vector. so only
10447 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
10449 cpup = &phba->sli4_hba.cpu_map[cpu];
10450 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10453 /* Get a ptr to the Hardware Queue associated with this CPU */
10454 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10456 /* Allocate an EQ */
10457 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10458 phba->sli4_hba.eq_esize,
10459 phba->sli4_hba.eq_ecount, cpu);
10461 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10462 "0497 Failed allocate EQ (%d)\n",
10466 qdesc->qe_valid = 1;
10467 qdesc->hdwq = cpup->hdwq;
10468 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
10469 qdesc->last_cpu = qdesc->chann;
10471 /* Save the allocated EQ in the Hardware Queue */
10472 qp->hba_eq = qdesc;
10474 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
10475 list_add(&qdesc->cpu_list, &eqi->list);
10478 /* Now we need to populate the other Hardware Queues, that share
10479 * an IRQ vector, with the associated EQ ptr.
10481 for_each_present_cpu(cpu) {
10482 cpup = &phba->sli4_hba.cpu_map[cpu];
10484 /* Check for EQ already allocated in previous loop */
10485 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
10488 /* Check for multiple CPUs per hdwq */
10489 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10493 /* We need to share an EQ for this hdwq */
10494 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
10495 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
10496 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
10499 /* Allocate IO Path SLI4 CQ/WQs */
10500 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10501 if (lpfc_alloc_io_wq_cq(phba, idx))
10505 if (phba->nvmet_support) {
10506 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10507 cpu = lpfc_find_cpu_handle(phba, idx,
10508 LPFC_FIND_BY_HDWQ);
10509 qdesc = lpfc_sli4_queue_alloc(phba,
10510 LPFC_DEFAULT_PAGE_SIZE,
10511 phba->sli4_hba.cq_esize,
10512 phba->sli4_hba.cq_ecount,
10515 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10516 "3142 Failed allocate NVME "
10517 "CQ Set (%d)\n", idx);
10520 qdesc->qe_valid = 1;
10522 qdesc->chann = cpu;
10523 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
10528 * Create Slow Path Completion Queues (CQs)
10531 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
10532 /* Create slow-path Mailbox Command Complete Queue */
10533 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10534 phba->sli4_hba.cq_esize,
10535 phba->sli4_hba.cq_ecount, cpu);
10537 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10538 "0500 Failed allocate slow-path mailbox CQ\n");
10541 qdesc->qe_valid = 1;
10542 phba->sli4_hba.mbx_cq = qdesc;
10544 /* Create slow-path ELS Complete Queue */
10545 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10546 phba->sli4_hba.cq_esize,
10547 phba->sli4_hba.cq_ecount, cpu);
10549 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10550 "0501 Failed allocate slow-path ELS CQ\n");
10553 qdesc->qe_valid = 1;
10554 qdesc->chann = cpu;
10555 phba->sli4_hba.els_cq = qdesc;
10559 * Create Slow Path Work Queues (WQs)
10562 /* Create Mailbox Command Queue */
10564 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10565 phba->sli4_hba.mq_esize,
10566 phba->sli4_hba.mq_ecount, cpu);
10568 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10569 "0505 Failed allocate slow-path MQ\n");
10572 qdesc->chann = cpu;
10573 phba->sli4_hba.mbx_wq = qdesc;
10576 * Create ELS Work Queues
10579 /* Create slow-path ELS Work Queue */
10580 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10581 phba->sli4_hba.wq_esize,
10582 phba->sli4_hba.wq_ecount, cpu);
10584 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10585 "0504 Failed allocate slow-path ELS WQ\n");
10588 qdesc->chann = cpu;
10589 phba->sli4_hba.els_wq = qdesc;
10590 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10592 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10593 /* Create NVME LS Complete Queue */
10594 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10595 phba->sli4_hba.cq_esize,
10596 phba->sli4_hba.cq_ecount, cpu);
10598 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10599 "6079 Failed allocate NVME LS CQ\n");
10602 qdesc->chann = cpu;
10603 qdesc->qe_valid = 1;
10604 phba->sli4_hba.nvmels_cq = qdesc;
10606 /* Create NVME LS Work Queue */
10607 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10608 phba->sli4_hba.wq_esize,
10609 phba->sli4_hba.wq_ecount, cpu);
10611 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10612 "6080 Failed allocate NVME LS WQ\n");
10615 qdesc->chann = cpu;
10616 phba->sli4_hba.nvmels_wq = qdesc;
10617 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10621 * Create Receive Queue (RQ)
10624 /* Create Receive Queue for header */
10625 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10626 phba->sli4_hba.rq_esize,
10627 phba->sli4_hba.rq_ecount, cpu);
10629 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10630 "0506 Failed allocate receive HRQ\n");
10633 phba->sli4_hba.hdr_rq = qdesc;
10635 /* Create Receive Queue for data */
10636 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10637 phba->sli4_hba.rq_esize,
10638 phba->sli4_hba.rq_ecount, cpu);
10640 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10641 "0507 Failed allocate receive DRQ\n");
10644 phba->sli4_hba.dat_rq = qdesc;
10646 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10647 phba->nvmet_support) {
10648 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10649 cpu = lpfc_find_cpu_handle(phba, idx,
10650 LPFC_FIND_BY_HDWQ);
10651 /* Create NVMET Receive Queue for header */
10652 qdesc = lpfc_sli4_queue_alloc(phba,
10653 LPFC_DEFAULT_PAGE_SIZE,
10654 phba->sli4_hba.rq_esize,
10655 LPFC_NVMET_RQE_DEF_COUNT,
10658 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10659 "3146 Failed allocate "
10664 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10666 /* Only needed for header of RQ pair */
10667 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10670 if (qdesc->rqbp == NULL) {
10671 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10672 "6131 Failed allocate "
10677 /* Put list in known state in case driver load fails. */
10678 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10680 /* Create NVMET Receive Queue for data */
10681 qdesc = lpfc_sli4_queue_alloc(phba,
10682 LPFC_DEFAULT_PAGE_SIZE,
10683 phba->sli4_hba.rq_esize,
10684 LPFC_NVMET_RQE_DEF_COUNT,
10687 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10688 "3156 Failed allocate "
10693 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10697 /* Clear NVME stats */
10698 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10699 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10700 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10701 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10705 /* Clear SCSI stats */
10706 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10707 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10708 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10709 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10716 lpfc_sli4_queue_destroy(phba);
10721 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
10724 lpfc_sli4_queue_free(*qp);
10730 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10737 for (idx = 0; idx < max; idx++)
10738 __lpfc_sli4_release_queue(&(*qs)[idx]);
10745 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
10747 struct lpfc_sli4_hdw_queue *hdwq;
10748 struct lpfc_queue *eq;
10751 hdwq = phba->sli4_hba.hdwq;
10753 /* Loop thru all Hardware Queues */
10754 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10755 /* Free the CQ/WQ corresponding to the Hardware Queue */
10756 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10757 lpfc_sli4_queue_free(hdwq[idx].io_wq);
10758 hdwq[idx].hba_eq = NULL;
10759 hdwq[idx].io_cq = NULL;
10760 hdwq[idx].io_wq = NULL;
10761 if (phba->cfg_xpsgl && !phba->nvmet_support)
10762 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10763 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
10765 /* Loop thru all IRQ vectors */
10766 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10767 /* Free the EQ corresponding to the IRQ vector */
10768 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10769 lpfc_sli4_queue_free(eq);
10770 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10775 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10776 * @phba: pointer to lpfc hba data structure.
10778 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10783 * -ENOMEM - No available memory
10784 * -EIO - The mailbox failed to complete successfully.
10787 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10790 * Set FREE_INIT before beginning to free the queues.
10791 * Wait until the users of queues to acknowledge to
10792 * release queues by clearing FREE_WAIT.
10794 spin_lock_irq(&phba->hbalock);
10795 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10796 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10797 spin_unlock_irq(&phba->hbalock);
10799 spin_lock_irq(&phba->hbalock);
10801 spin_unlock_irq(&phba->hbalock);
10803 lpfc_sli4_cleanup_poll_list(phba);
10805 /* Release HBA eqs */
10806 if (phba->sli4_hba.hdwq)
10807 lpfc_sli4_release_hdwq(phba);
10809 if (phba->nvmet_support) {
10810 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10811 phba->cfg_nvmet_mrq);
10813 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10814 phba->cfg_nvmet_mrq);
10815 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10816 phba->cfg_nvmet_mrq);
10819 /* Release mailbox command work queue */
10820 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
10822 /* Release ELS work queue */
10823 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10825 /* Release ELS work queue */
10826 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
10828 /* Release unsolicited receive queue */
10829 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10830 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
10832 /* Release ELS complete queue */
10833 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10835 /* Release NVME LS complete queue */
10836 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
10838 /* Release mailbox command complete queue */
10839 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10841 /* Everything on this list has been freed */
10842 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10844 /* Done with freeing the queues */
10845 spin_lock_irq(&phba->hbalock);
10846 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10847 spin_unlock_irq(&phba->hbalock);
10851 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10853 struct lpfc_rqb *rqbp;
10854 struct lpfc_dmabuf *h_buf;
10855 struct rqb_dmabuf *rqb_buffer;
10858 while (!list_empty(&rqbp->rqb_buffer_list)) {
10859 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10860 struct lpfc_dmabuf, list);
10862 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10863 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
10864 rqbp->buffer_count--;
10870 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
10871 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
10872 int qidx, uint32_t qtype)
10874 struct lpfc_sli_ring *pring;
10877 if (!eq || !cq || !wq) {
10878 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10879 "6085 Fast-path %s (%d) not allocated\n",
10880 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
10884 /* create the Cq first */
10885 rc = lpfc_cq_create(phba, cq, eq,
10886 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
10888 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10889 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
10890 qidx, (uint32_t)rc);
10894 if (qtype != LPFC_MBOX) {
10895 /* Setup cq_map for fast lookup */
10897 *cq_map = cq->queue_id;
10899 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10900 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
10901 qidx, cq->queue_id, qidx, eq->queue_id);
10903 /* create the wq */
10904 rc = lpfc_wq_create(phba, wq, cq, qtype);
10906 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10907 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
10908 qidx, (uint32_t)rc);
10909 /* no need to tear down cq - caller will do so */
10913 /* Bind this CQ/WQ to the NVME ring */
10915 pring->sli.sli4.wqp = (void *)wq;
10918 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10919 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
10920 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
10922 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
10924 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10925 "0539 Failed setup of slow-path MQ: "
10926 "rc = 0x%x\n", rc);
10927 /* no need to tear down cq - caller will do so */
10931 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10932 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
10933 phba->sli4_hba.mbx_wq->queue_id,
10934 phba->sli4_hba.mbx_cq->queue_id);
10941 * lpfc_setup_cq_lookup - Setup the CQ lookup table
10942 * @phba: pointer to lpfc hba data structure.
10944 * This routine will populate the cq_lookup table by all
10945 * available CQ queue_id's.
10948 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
10950 struct lpfc_queue *eq, *childq;
10953 memset(phba->sli4_hba.cq_lookup, 0,
10954 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
10955 /* Loop thru all IRQ vectors */
10956 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10957 /* Get the EQ corresponding to the IRQ vector */
10958 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
10961 /* Loop through all CQs associated with that EQ */
10962 list_for_each_entry(childq, &eq->child_list, list) {
10963 if (childq->queue_id > phba->sli4_hba.cq_max)
10965 if (childq->subtype == LPFC_IO)
10966 phba->sli4_hba.cq_lookup[childq->queue_id] =
10973 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
10974 * @phba: pointer to lpfc hba data structure.
10976 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
10981 * -ENOMEM - No available memory
10982 * -EIO - The mailbox failed to complete successfully.
10985 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
10987 uint32_t shdr_status, shdr_add_status;
10988 union lpfc_sli4_cfg_shdr *shdr;
10989 struct lpfc_vector_map_info *cpup;
10990 struct lpfc_sli4_hdw_queue *qp;
10991 LPFC_MBOXQ_t *mboxq;
10993 uint32_t length, usdelay;
10996 /* Check for dual-ULP support */
10997 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10999 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11000 "3249 Unable to allocate memory for "
11001 "QUERY_FW_CFG mailbox command\n");
11004 length = (sizeof(struct lpfc_mbx_query_fw_config) -
11005 sizeof(struct lpfc_sli4_cfg_mhdr));
11006 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11007 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
11008 length, LPFC_SLI4_MBX_EMBED);
11010 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11012 shdr = (union lpfc_sli4_cfg_shdr *)
11013 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11014 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11015 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11016 if (shdr_status || shdr_add_status || rc) {
11017 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11018 "3250 QUERY_FW_CFG mailbox failed with status "
11019 "x%x add_status x%x, mbx status x%x\n",
11020 shdr_status, shdr_add_status, rc);
11021 mempool_free(mboxq, phba->mbox_mem_pool);
11026 phba->sli4_hba.fw_func_mode =
11027 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
11028 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
11029 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
11030 phba->sli4_hba.physical_port =
11031 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
11032 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11033 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
11034 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
11035 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
11037 mempool_free(mboxq, phba->mbox_mem_pool);
11040 * Set up HBA Event Queues (EQs)
11042 qp = phba->sli4_hba.hdwq;
11044 /* Set up HBA event queue */
11046 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11047 "3147 Fast-path EQs not allocated\n");
11052 /* Loop thru all IRQ vectors */
11053 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11054 /* Create HBA Event Queues (EQs) in order */
11055 for_each_present_cpu(cpu) {
11056 cpup = &phba->sli4_hba.cpu_map[cpu];
11058 /* Look for the CPU thats using that vector with
11059 * LPFC_CPU_FIRST_IRQ set.
11061 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11063 if (qidx != cpup->eq)
11066 /* Create an EQ for that vector */
11067 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
11068 phba->cfg_fcp_imax);
11070 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11071 "0523 Failed setup of fast-path"
11072 " EQ (%d), rc = 0x%x\n",
11073 cpup->eq, (uint32_t)rc);
11077 /* Save the EQ for that vector in the hba_eq_hdl */
11078 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
11079 qp[cpup->hdwq].hba_eq;
11081 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11082 "2584 HBA EQ setup: queue[%d]-id=%d\n",
11084 qp[cpup->hdwq].hba_eq->queue_id);
11088 /* Loop thru all Hardware Queues */
11089 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11090 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
11091 cpup = &phba->sli4_hba.cpu_map[cpu];
11093 /* Create the CQ/WQ corresponding to the Hardware Queue */
11094 rc = lpfc_create_wq_cq(phba,
11095 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
11098 &phba->sli4_hba.hdwq[qidx].io_cq_map,
11102 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11103 "0535 Failed to setup fastpath "
11104 "IO WQ/CQ (%d), rc = 0x%x\n",
11105 qidx, (uint32_t)rc);
11111 * Set up Slow Path Complete Queues (CQs)
11114 /* Set up slow-path MBOX CQ/MQ */
11116 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
11117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11118 "0528 %s not allocated\n",
11119 phba->sli4_hba.mbx_cq ?
11120 "Mailbox WQ" : "Mailbox CQ");
11125 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11126 phba->sli4_hba.mbx_cq,
11127 phba->sli4_hba.mbx_wq,
11128 NULL, 0, LPFC_MBOX);
11130 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11131 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
11135 if (phba->nvmet_support) {
11136 if (!phba->sli4_hba.nvmet_cqset) {
11137 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11138 "3165 Fast-path NVME CQ Set "
11139 "array not allocated\n");
11143 if (phba->cfg_nvmet_mrq > 1) {
11144 rc = lpfc_cq_create_set(phba,
11145 phba->sli4_hba.nvmet_cqset,
11147 LPFC_WCQ, LPFC_NVMET);
11149 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11150 "3164 Failed setup of NVME CQ "
11151 "Set, rc = 0x%x\n",
11156 /* Set up NVMET Receive Complete Queue */
11157 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
11159 LPFC_WCQ, LPFC_NVMET);
11161 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11162 "6089 Failed setup NVMET CQ: "
11163 "rc = 0x%x\n", (uint32_t)rc);
11166 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
11168 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11169 "6090 NVMET CQ setup: cq-id=%d, "
11170 "parent eq-id=%d\n",
11171 phba->sli4_hba.nvmet_cqset[0]->queue_id,
11172 qp[0].hba_eq->queue_id);
11176 /* Set up slow-path ELS WQ/CQ */
11177 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
11178 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11179 "0530 ELS %s not allocated\n",
11180 phba->sli4_hba.els_cq ? "WQ" : "CQ");
11184 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11185 phba->sli4_hba.els_cq,
11186 phba->sli4_hba.els_wq,
11187 NULL, 0, LPFC_ELS);
11189 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11190 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
11194 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11195 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
11196 phba->sli4_hba.els_wq->queue_id,
11197 phba->sli4_hba.els_cq->queue_id);
11199 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11200 /* Set up NVME LS Complete Queue */
11201 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
11202 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11203 "6091 LS %s not allocated\n",
11204 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
11208 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11209 phba->sli4_hba.nvmels_cq,
11210 phba->sli4_hba.nvmels_wq,
11211 NULL, 0, LPFC_NVME_LS);
11213 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11214 "0526 Failed setup of NVVME LS WQ/CQ: "
11215 "rc = 0x%x\n", (uint32_t)rc);
11219 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11220 "6096 ELS WQ setup: wq-id=%d, "
11221 "parent cq-id=%d\n",
11222 phba->sli4_hba.nvmels_wq->queue_id,
11223 phba->sli4_hba.nvmels_cq->queue_id);
11227 * Create NVMET Receive Queue (RQ)
11229 if (phba->nvmet_support) {
11230 if ((!phba->sli4_hba.nvmet_cqset) ||
11231 (!phba->sli4_hba.nvmet_mrq_hdr) ||
11232 (!phba->sli4_hba.nvmet_mrq_data)) {
11233 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11234 "6130 MRQ CQ Queues not "
11239 if (phba->cfg_nvmet_mrq > 1) {
11240 rc = lpfc_mrq_create(phba,
11241 phba->sli4_hba.nvmet_mrq_hdr,
11242 phba->sli4_hba.nvmet_mrq_data,
11243 phba->sli4_hba.nvmet_cqset,
11246 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11247 "6098 Failed setup of NVMET "
11248 "MRQ: rc = 0x%x\n",
11254 rc = lpfc_rq_create(phba,
11255 phba->sli4_hba.nvmet_mrq_hdr[0],
11256 phba->sli4_hba.nvmet_mrq_data[0],
11257 phba->sli4_hba.nvmet_cqset[0],
11260 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11261 "6057 Failed setup of NVMET "
11262 "Receive Queue: rc = 0x%x\n",
11268 phba, KERN_INFO, LOG_INIT,
11269 "6099 NVMET RQ setup: hdr-rq-id=%d, "
11270 "dat-rq-id=%d parent cq-id=%d\n",
11271 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
11272 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
11273 phba->sli4_hba.nvmet_cqset[0]->queue_id);
11278 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
11279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11280 "0540 Receive Queue not allocated\n");
11285 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
11286 phba->sli4_hba.els_cq, LPFC_USOL);
11288 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11289 "0541 Failed setup of Receive Queue: "
11290 "rc = 0x%x\n", (uint32_t)rc);
11294 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11295 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
11296 "parent cq-id=%d\n",
11297 phba->sli4_hba.hdr_rq->queue_id,
11298 phba->sli4_hba.dat_rq->queue_id,
11299 phba->sli4_hba.els_cq->queue_id);
11301 if (phba->cfg_fcp_imax)
11302 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
11306 for (qidx = 0; qidx < phba->cfg_irq_chann;
11307 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
11308 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
11311 if (phba->sli4_hba.cq_max) {
11312 kfree(phba->sli4_hba.cq_lookup);
11313 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
11314 sizeof(struct lpfc_queue *), GFP_KERNEL);
11315 if (!phba->sli4_hba.cq_lookup) {
11316 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11317 "0549 Failed setup of CQ Lookup table: "
11318 "size 0x%x\n", phba->sli4_hba.cq_max);
11322 lpfc_setup_cq_lookup(phba);
11327 lpfc_sli4_queue_unset(phba);
11333 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
11334 * @phba: pointer to lpfc hba data structure.
11336 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
11341 * -ENOMEM - No available memory
11342 * -EIO - The mailbox failed to complete successfully.
11345 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
11347 struct lpfc_sli4_hdw_queue *qp;
11348 struct lpfc_queue *eq;
11351 /* Unset mailbox command work queue */
11352 if (phba->sli4_hba.mbx_wq)
11353 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
11355 /* Unset NVME LS work queue */
11356 if (phba->sli4_hba.nvmels_wq)
11357 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
11359 /* Unset ELS work queue */
11360 if (phba->sli4_hba.els_wq)
11361 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
11363 /* Unset unsolicited receive queue */
11364 if (phba->sli4_hba.hdr_rq)
11365 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
11366 phba->sli4_hba.dat_rq);
11368 /* Unset mailbox command complete queue */
11369 if (phba->sli4_hba.mbx_cq)
11370 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
11372 /* Unset ELS complete queue */
11373 if (phba->sli4_hba.els_cq)
11374 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
11376 /* Unset NVME LS complete queue */
11377 if (phba->sli4_hba.nvmels_cq)
11378 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
11380 if (phba->nvmet_support) {
11381 /* Unset NVMET MRQ queue */
11382 if (phba->sli4_hba.nvmet_mrq_hdr) {
11383 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11386 phba->sli4_hba.nvmet_mrq_hdr[qidx],
11387 phba->sli4_hba.nvmet_mrq_data[qidx]);
11390 /* Unset NVMET CQ Set complete queue */
11391 if (phba->sli4_hba.nvmet_cqset) {
11392 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11394 phba, phba->sli4_hba.nvmet_cqset[qidx]);
11398 /* Unset fast-path SLI4 queues */
11399 if (phba->sli4_hba.hdwq) {
11400 /* Loop thru all Hardware Queues */
11401 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11402 /* Destroy the CQ/WQ corresponding to Hardware Queue */
11403 qp = &phba->sli4_hba.hdwq[qidx];
11404 lpfc_wq_destroy(phba, qp->io_wq);
11405 lpfc_cq_destroy(phba, qp->io_cq);
11407 /* Loop thru all IRQ vectors */
11408 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11409 /* Destroy the EQ corresponding to the IRQ vector */
11410 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11411 lpfc_eq_destroy(phba, eq);
11415 kfree(phba->sli4_hba.cq_lookup);
11416 phba->sli4_hba.cq_lookup = NULL;
11417 phba->sli4_hba.cq_max = 0;
11421 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
11422 * @phba: pointer to lpfc hba data structure.
11424 * This routine is invoked to allocate and set up a pool of completion queue
11425 * events. The body of the completion queue event is a completion queue entry
11426 * CQE. For now, this pool is used for the interrupt service routine to queue
11427 * the following HBA completion queue events for the worker thread to process:
11428 * - Mailbox asynchronous events
11429 * - Receive queue completion unsolicited events
11430 * Later, this can be used for all the slow-path events.
11434 * -ENOMEM - No available memory
11437 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
11439 struct lpfc_cq_event *cq_event;
11442 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
11443 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
11445 goto out_pool_create_fail;
11446 list_add_tail(&cq_event->list,
11447 &phba->sli4_hba.sp_cqe_event_pool);
11451 out_pool_create_fail:
11452 lpfc_sli4_cq_event_pool_destroy(phba);
11457 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
11458 * @phba: pointer to lpfc hba data structure.
11460 * This routine is invoked to free the pool of completion queue events at
11461 * driver unload time. Note that, it is the responsibility of the driver
11462 * cleanup routine to free all the outstanding completion-queue events
11463 * allocated from this pool back into the pool before invoking this routine
11464 * to destroy the pool.
11467 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
11469 struct lpfc_cq_event *cq_event, *next_cq_event;
11471 list_for_each_entry_safe(cq_event, next_cq_event,
11472 &phba->sli4_hba.sp_cqe_event_pool, list) {
11473 list_del(&cq_event->list);
11479 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11480 * @phba: pointer to lpfc hba data structure.
11482 * This routine is the lock free version of the API invoked to allocate a
11483 * completion-queue event from the free pool.
11485 * Return: Pointer to the newly allocated completion-queue event if successful
11488 struct lpfc_cq_event *
11489 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11491 struct lpfc_cq_event *cq_event = NULL;
11493 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
11494 struct lpfc_cq_event, list);
11499 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11500 * @phba: pointer to lpfc hba data structure.
11502 * This routine is the lock version of the API invoked to allocate a
11503 * completion-queue event from the free pool.
11505 * Return: Pointer to the newly allocated completion-queue event if successful
11508 struct lpfc_cq_event *
11509 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11511 struct lpfc_cq_event *cq_event;
11512 unsigned long iflags;
11514 spin_lock_irqsave(&phba->hbalock, iflags);
11515 cq_event = __lpfc_sli4_cq_event_alloc(phba);
11516 spin_unlock_irqrestore(&phba->hbalock, iflags);
11521 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11522 * @phba: pointer to lpfc hba data structure.
11523 * @cq_event: pointer to the completion queue event to be freed.
11525 * This routine is the lock free version of the API invoked to release a
11526 * completion-queue event back into the free pool.
11529 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11530 struct lpfc_cq_event *cq_event)
11532 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
11536 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11537 * @phba: pointer to lpfc hba data structure.
11538 * @cq_event: pointer to the completion queue event to be freed.
11540 * This routine is the lock version of the API invoked to release a
11541 * completion-queue event back into the free pool.
11544 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11545 struct lpfc_cq_event *cq_event)
11547 unsigned long iflags;
11548 spin_lock_irqsave(&phba->hbalock, iflags);
11549 __lpfc_sli4_cq_event_release(phba, cq_event);
11550 spin_unlock_irqrestore(&phba->hbalock, iflags);
11554 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
11555 * @phba: pointer to lpfc hba data structure.
11557 * This routine is to free all the pending completion-queue events to the
11558 * back into the free pool for device reset.
11561 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
11563 LIST_HEAD(cq_event_list);
11564 struct lpfc_cq_event *cq_event;
11565 unsigned long iflags;
11567 /* Retrieve all the pending WCQEs from pending WCQE lists */
11569 /* Pending ELS XRI abort events */
11570 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11571 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11573 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11575 /* Pending asynnc events */
11576 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
11577 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
11579 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
11581 while (!list_empty(&cq_event_list)) {
11582 list_remove_head(&cq_event_list, cq_event,
11583 struct lpfc_cq_event, list);
11584 lpfc_sli4_cq_event_release(phba, cq_event);
11589 * lpfc_pci_function_reset - Reset pci function.
11590 * @phba: pointer to lpfc hba data structure.
11592 * This routine is invoked to request a PCI function reset. It will destroys
11593 * all resources assigned to the PCI function which originates this request.
11597 * -ENOMEM - No available memory
11598 * -EIO - The mailbox failed to complete successfully.
11601 lpfc_pci_function_reset(struct lpfc_hba *phba)
11603 LPFC_MBOXQ_t *mboxq;
11604 uint32_t rc = 0, if_type;
11605 uint32_t shdr_status, shdr_add_status;
11607 uint32_t port_reset = 0;
11608 union lpfc_sli4_cfg_shdr *shdr;
11609 struct lpfc_register reg_data;
11612 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11614 case LPFC_SLI_INTF_IF_TYPE_0:
11615 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
11618 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11619 "0494 Unable to allocate memory for "
11620 "issuing SLI_FUNCTION_RESET mailbox "
11625 /* Setup PCI function reset mailbox-ioctl command */
11626 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11627 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11628 LPFC_SLI4_MBX_EMBED);
11629 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11630 shdr = (union lpfc_sli4_cfg_shdr *)
11631 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11632 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11633 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11635 mempool_free(mboxq, phba->mbox_mem_pool);
11636 if (shdr_status || shdr_add_status || rc) {
11637 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11638 "0495 SLI_FUNCTION_RESET mailbox "
11639 "failed with status x%x add_status x%x,"
11640 " mbx status x%x\n",
11641 shdr_status, shdr_add_status, rc);
11645 case LPFC_SLI_INTF_IF_TYPE_2:
11646 case LPFC_SLI_INTF_IF_TYPE_6:
11649 * Poll the Port Status Register and wait for RDY for
11650 * up to 30 seconds. If the port doesn't respond, treat
11653 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
11654 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11655 STATUSregaddr, ®_data.word0)) {
11659 if (bf_get(lpfc_sliport_status_rdy, ®_data))
11664 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
11665 phba->work_status[0] = readl(
11666 phba->sli4_hba.u.if_type2.ERR1regaddr);
11667 phba->work_status[1] = readl(
11668 phba->sli4_hba.u.if_type2.ERR2regaddr);
11669 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11670 "2890 Port not ready, port status reg "
11671 "0x%x error 1=0x%x, error 2=0x%x\n",
11673 phba->work_status[0],
11674 phba->work_status[1]);
11679 if (bf_get(lpfc_sliport_status_pldv, ®_data))
11680 lpfc_pldv_detect = true;
11684 * Reset the port now
11686 reg_data.word0 = 0;
11687 bf_set(lpfc_sliport_ctrl_end, ®_data,
11688 LPFC_SLIPORT_LITTLE_ENDIAN);
11689 bf_set(lpfc_sliport_ctrl_ip, ®_data,
11690 LPFC_SLIPORT_INIT_PORT);
11691 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11694 pci_read_config_word(phba->pcidev,
11695 PCI_DEVICE_ID, &devid);
11700 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
11706 case LPFC_SLI_INTF_IF_TYPE_1:
11712 /* Catch the not-ready port failure after a port reset. */
11714 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11715 "3317 HBA not functional: IP Reset Failed "
11716 "try: echo fw_reset > board_mode\n");
11724 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11725 * @phba: pointer to lpfc hba data structure.
11727 * This routine is invoked to set up the PCI device memory space for device
11728 * with SLI-4 interface spec.
11732 * other values - error
11735 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11737 struct pci_dev *pdev = phba->pcidev;
11738 unsigned long bar0map_len, bar1map_len, bar2map_len;
11745 /* Set the device DMA mask size */
11746 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11748 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11753 * The BARs and register set definitions and offset locations are
11754 * dependent on the if_type.
11756 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11757 &phba->sli4_hba.sli_intf.word0)) {
11761 /* There is no SLI3 failback for SLI4 devices. */
11762 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11763 LPFC_SLI_INTF_VALID) {
11764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11765 "2894 SLI_INTF reg contents invalid "
11766 "sli_intf reg 0x%x\n",
11767 phba->sli4_hba.sli_intf.word0);
11771 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11773 * Get the bus address of SLI4 device Bar regions and the
11774 * number of bytes required by each mapping. The mapping of the
11775 * particular PCI BARs regions is dependent on the type of
11778 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11779 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11780 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
11783 * Map SLI4 PCI Config Space Register base to a kernel virtual
11786 phba->sli4_hba.conf_regs_memmap_p =
11787 ioremap(phba->pci_bar0_map, bar0map_len);
11788 if (!phba->sli4_hba.conf_regs_memmap_p) {
11789 dev_printk(KERN_ERR, &pdev->dev,
11790 "ioremap failed for SLI4 PCI config "
11794 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
11795 /* Set up BAR0 PCI config space register memory map */
11796 lpfc_sli4_bar0_register_memmap(phba, if_type);
11798 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11799 bar0map_len = pci_resource_len(pdev, 1);
11800 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
11801 dev_printk(KERN_ERR, &pdev->dev,
11802 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
11805 phba->sli4_hba.conf_regs_memmap_p =
11806 ioremap(phba->pci_bar0_map, bar0map_len);
11807 if (!phba->sli4_hba.conf_regs_memmap_p) {
11808 dev_printk(KERN_ERR, &pdev->dev,
11809 "ioremap failed for SLI4 PCI config "
11813 lpfc_sli4_bar0_register_memmap(phba, if_type);
11816 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11817 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11819 * Map SLI4 if type 0 HBA Control Register base to a
11820 * kernel virtual address and setup the registers.
11822 phba->pci_bar1_map = pci_resource_start(pdev,
11824 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11825 phba->sli4_hba.ctrl_regs_memmap_p =
11826 ioremap(phba->pci_bar1_map,
11828 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11829 dev_err(&pdev->dev,
11830 "ioremap failed for SLI4 HBA "
11831 "control registers.\n");
11833 goto out_iounmap_conf;
11835 phba->pci_bar2_memmap_p =
11836 phba->sli4_hba.ctrl_regs_memmap_p;
11837 lpfc_sli4_bar1_register_memmap(phba, if_type);
11840 goto out_iounmap_conf;
11844 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11845 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11847 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11848 * virtual address and setup the registers.
11850 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11851 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11852 phba->sli4_hba.drbl_regs_memmap_p =
11853 ioremap(phba->pci_bar1_map, bar1map_len);
11854 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11855 dev_err(&pdev->dev,
11856 "ioremap failed for SLI4 HBA doorbell registers.\n");
11858 goto out_iounmap_conf;
11860 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11861 lpfc_sli4_bar1_register_memmap(phba, if_type);
11864 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11865 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11867 * Map SLI4 if type 0 HBA Doorbell Register base to
11868 * a kernel virtual address and setup the registers.
11870 phba->pci_bar2_map = pci_resource_start(pdev,
11872 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11873 phba->sli4_hba.drbl_regs_memmap_p =
11874 ioremap(phba->pci_bar2_map,
11876 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11877 dev_err(&pdev->dev,
11878 "ioremap failed for SLI4 HBA"
11879 " doorbell registers.\n");
11881 goto out_iounmap_ctrl;
11883 phba->pci_bar4_memmap_p =
11884 phba->sli4_hba.drbl_regs_memmap_p;
11885 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
11887 goto out_iounmap_all;
11890 goto out_iounmap_all;
11894 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
11895 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11897 * Map SLI4 if type 6 HBA DPP Register base to a kernel
11898 * virtual address and setup the registers.
11900 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
11901 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11902 phba->sli4_hba.dpp_regs_memmap_p =
11903 ioremap(phba->pci_bar2_map, bar2map_len);
11904 if (!phba->sli4_hba.dpp_regs_memmap_p) {
11905 dev_err(&pdev->dev,
11906 "ioremap failed for SLI4 HBA dpp registers.\n");
11908 goto out_iounmap_ctrl;
11910 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
11913 /* Set up the EQ/CQ register handeling functions now */
11915 case LPFC_SLI_INTF_IF_TYPE_0:
11916 case LPFC_SLI_INTF_IF_TYPE_2:
11917 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
11918 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
11919 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
11921 case LPFC_SLI_INTF_IF_TYPE_6:
11922 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
11923 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
11924 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
11933 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11935 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11937 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11943 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
11944 * @phba: pointer to lpfc hba data structure.
11946 * This routine is invoked to unset the PCI device memory space for device
11947 * with SLI-4 interface spec.
11950 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
11953 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11956 case LPFC_SLI_INTF_IF_TYPE_0:
11957 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11958 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11959 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11961 case LPFC_SLI_INTF_IF_TYPE_2:
11962 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11964 case LPFC_SLI_INTF_IF_TYPE_6:
11965 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11966 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11967 if (phba->sli4_hba.dpp_regs_memmap_p)
11968 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
11970 case LPFC_SLI_INTF_IF_TYPE_1:
11972 dev_printk(KERN_ERR, &phba->pcidev->dev,
11973 "FATAL - unsupported SLI4 interface type - %d\n",
11980 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
11981 * @phba: pointer to lpfc hba data structure.
11983 * This routine is invoked to enable the MSI-X interrupt vectors to device
11984 * with SLI-3 interface specs.
11988 * other values - error
11991 lpfc_sli_enable_msix(struct lpfc_hba *phba)
11996 /* Set up MSI-X multi-message vectors */
11997 rc = pci_alloc_irq_vectors(phba->pcidev,
11998 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
12000 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12001 "0420 PCI enable MSI-X failed (%d)\n", rc);
12006 * Assign MSI-X vectors to interrupt handlers
12009 /* vector-0 is associated to slow-path handler */
12010 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
12011 &lpfc_sli_sp_intr_handler, 0,
12012 LPFC_SP_DRIVER_HANDLER_NAME, phba);
12014 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12015 "0421 MSI-X slow-path request_irq failed "
12020 /* vector-1 is associated to fast-path handler */
12021 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
12022 &lpfc_sli_fp_intr_handler, 0,
12023 LPFC_FP_DRIVER_HANDLER_NAME, phba);
12026 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12027 "0429 MSI-X fast-path request_irq failed "
12033 * Configure HBA MSI-X attention conditions to messages
12035 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12039 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12040 "0474 Unable to allocate memory for issuing "
12041 "MBOX_CONFIG_MSI command\n");
12044 rc = lpfc_config_msi(phba, pmb);
12047 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
12048 if (rc != MBX_SUCCESS) {
12049 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
12050 "0351 Config MSI mailbox command failed, "
12051 "mbxCmd x%x, mbxStatus x%x\n",
12052 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
12056 /* Free memory allocated for mailbox command */
12057 mempool_free(pmb, phba->mbox_mem_pool);
12061 /* Free memory allocated for mailbox command */
12062 mempool_free(pmb, phba->mbox_mem_pool);
12065 /* free the irq already requested */
12066 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
12069 /* free the irq already requested */
12070 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
12073 /* Unconfigure MSI-X capability structure */
12074 pci_free_irq_vectors(phba->pcidev);
12081 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
12082 * @phba: pointer to lpfc hba data structure.
12084 * This routine is invoked to enable the MSI interrupt mode to device with
12085 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
12086 * enable the MSI vector. The device driver is responsible for calling the
12087 * request_irq() to register MSI vector with a interrupt the handler, which
12088 * is done in this function.
12092 * other values - error
12095 lpfc_sli_enable_msi(struct lpfc_hba *phba)
12099 rc = pci_enable_msi(phba->pcidev);
12101 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12102 "0462 PCI enable MSI mode success.\n");
12104 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12105 "0471 PCI enable MSI mode failed (%d)\n", rc);
12109 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12110 0, LPFC_DRIVER_NAME, phba);
12112 pci_disable_msi(phba->pcidev);
12113 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12114 "0478 MSI request_irq failed (%d)\n", rc);
12120 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
12121 * @phba: pointer to lpfc hba data structure.
12122 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
12124 * This routine is invoked to enable device interrupt and associate driver's
12125 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
12126 * spec. Depends on the interrupt mode configured to the driver, the driver
12127 * will try to fallback from the configured interrupt mode to an interrupt
12128 * mode which is supported by the platform, kernel, and device in the order
12130 * MSI-X -> MSI -> IRQ.
12134 * other values - error
12137 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12139 uint32_t intr_mode = LPFC_INTR_ERROR;
12142 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
12143 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
12146 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
12148 if (cfg_mode == 2) {
12149 /* Now, try to enable MSI-X interrupt mode */
12150 retval = lpfc_sli_enable_msix(phba);
12152 /* Indicate initialization to MSI-X mode */
12153 phba->intr_type = MSIX;
12158 /* Fallback to MSI if MSI-X initialization failed */
12159 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12160 retval = lpfc_sli_enable_msi(phba);
12162 /* Indicate initialization to MSI mode */
12163 phba->intr_type = MSI;
12168 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12169 if (phba->intr_type == NONE) {
12170 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12171 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12173 /* Indicate initialization to INTx mode */
12174 phba->intr_type = INTx;
12182 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
12183 * @phba: pointer to lpfc hba data structure.
12185 * This routine is invoked to disable device interrupt and disassociate the
12186 * driver's interrupt handler(s) from interrupt vector(s) to device with
12187 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
12188 * release the interrupt vector(s) for the message signaled interrupt.
12191 lpfc_sli_disable_intr(struct lpfc_hba *phba)
12195 if (phba->intr_type == MSIX)
12196 nr_irqs = LPFC_MSIX_VECTORS;
12200 for (i = 0; i < nr_irqs; i++)
12201 free_irq(pci_irq_vector(phba->pcidev, i), phba);
12202 pci_free_irq_vectors(phba->pcidev);
12204 /* Reset interrupt management states */
12205 phba->intr_type = NONE;
12206 phba->sli.slistat.sli_intr = 0;
12210 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
12211 * @phba: pointer to lpfc hba data structure.
12212 * @id: EQ vector index or Hardware Queue index
12213 * @match: LPFC_FIND_BY_EQ = match by EQ
12214 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
12215 * Return the CPU that matches the selection criteria
12218 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
12220 struct lpfc_vector_map_info *cpup;
12223 /* Loop through all CPUs */
12224 for_each_present_cpu(cpu) {
12225 cpup = &phba->sli4_hba.cpu_map[cpu];
12227 /* If we are matching by EQ, there may be multiple CPUs using
12228 * using the same vector, so select the one with
12229 * LPFC_CPU_FIRST_IRQ set.
12231 if ((match == LPFC_FIND_BY_EQ) &&
12232 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
12236 /* If matching by HDWQ, select the first CPU that matches */
12237 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
12245 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
12246 * @phba: pointer to lpfc hba data structure.
12247 * @cpu: CPU map index
12248 * @phys_id: CPU package physical id
12249 * @core_id: CPU core id
12252 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
12253 uint16_t phys_id, uint16_t core_id)
12255 struct lpfc_vector_map_info *cpup;
12258 for_each_present_cpu(idx) {
12259 cpup = &phba->sli4_hba.cpu_map[idx];
12260 /* Does the cpup match the one we are looking for */
12261 if ((cpup->phys_id == phys_id) &&
12262 (cpup->core_id == core_id) &&
12271 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
12272 * @phba: pointer to lpfc hba data structure.
12273 * @eqidx: index for eq and irq vector
12274 * @flag: flags to set for vector_map structure
12275 * @cpu: cpu used to index vector_map structure
12277 * The routine assigns eq info into vector_map structure
12280 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
12283 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
12284 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
12287 cpup->flag |= flag;
12289 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12290 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
12291 cpu, eqhdl->irq, cpup->eq, cpup->flag);
12295 * lpfc_cpu_map_array_init - Initialize cpu_map structure
12296 * @phba: pointer to lpfc hba data structure.
12298 * The routine initializes the cpu_map array structure
12301 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
12303 struct lpfc_vector_map_info *cpup;
12304 struct lpfc_eq_intr_info *eqi;
12307 for_each_possible_cpu(cpu) {
12308 cpup = &phba->sli4_hba.cpu_map[cpu];
12309 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
12310 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
12311 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
12312 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
12314 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
12315 INIT_LIST_HEAD(&eqi->list);
12321 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
12322 * @phba: pointer to lpfc hba data structure.
12324 * The routine initializes the hba_eq_hdl array structure
12327 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
12329 struct lpfc_hba_eq_hdl *eqhdl;
12332 for (i = 0; i < phba->cfg_irq_chann; i++) {
12333 eqhdl = lpfc_get_eq_hdl(i);
12334 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
12335 eqhdl->phba = phba;
12340 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
12341 * @phba: pointer to lpfc hba data structure.
12342 * @vectors: number of msix vectors allocated.
12344 * The routine will figure out the CPU affinity assignment for every
12345 * MSI-X vector allocated for the HBA.
12346 * In addition, the CPU to IO channel mapping will be calculated
12347 * and the phba->sli4_hba.cpu_map array will reflect this.
12350 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
12352 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
12353 int max_phys_id, min_phys_id;
12354 int max_core_id, min_core_id;
12355 struct lpfc_vector_map_info *cpup;
12356 struct lpfc_vector_map_info *new_cpup;
12358 struct cpuinfo_x86 *cpuinfo;
12360 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12361 struct lpfc_hdwq_stat *c_stat;
12365 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
12367 min_core_id = LPFC_VECTOR_MAP_EMPTY;
12369 /* Update CPU map with physical id and core id of each CPU */
12370 for_each_present_cpu(cpu) {
12371 cpup = &phba->sli4_hba.cpu_map[cpu];
12373 cpuinfo = &cpu_data(cpu);
12374 cpup->phys_id = cpuinfo->phys_proc_id;
12375 cpup->core_id = cpuinfo->cpu_core_id;
12376 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
12377 cpup->flag |= LPFC_CPU_MAP_HYPER;
12379 /* No distinction between CPUs for other platforms */
12381 cpup->core_id = cpu;
12384 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12385 "3328 CPU %d physid %d coreid %d flag x%x\n",
12386 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
12388 if (cpup->phys_id > max_phys_id)
12389 max_phys_id = cpup->phys_id;
12390 if (cpup->phys_id < min_phys_id)
12391 min_phys_id = cpup->phys_id;
12393 if (cpup->core_id > max_core_id)
12394 max_core_id = cpup->core_id;
12395 if (cpup->core_id < min_core_id)
12396 min_core_id = cpup->core_id;
12399 /* After looking at each irq vector assigned to this pcidev, its
12400 * possible to see that not ALL CPUs have been accounted for.
12401 * Next we will set any unassigned (unaffinitized) cpu map
12402 * entries to a IRQ on the same phys_id.
12404 first_cpu = cpumask_first(cpu_present_mask);
12405 start_cpu = first_cpu;
12407 for_each_present_cpu(cpu) {
12408 cpup = &phba->sli4_hba.cpu_map[cpu];
12410 /* Is this CPU entry unassigned */
12411 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12412 /* Mark CPU as IRQ not assigned by the kernel */
12413 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12415 /* If so, find a new_cpup thats on the the SAME
12416 * phys_id as cpup. start_cpu will start where we
12417 * left off so all unassigned entries don't get assgined
12418 * the IRQ of the first entry.
12420 new_cpu = start_cpu;
12421 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12422 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12423 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12424 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
12425 (new_cpup->phys_id == cpup->phys_id))
12427 new_cpu = cpumask_next(
12428 new_cpu, cpu_present_mask);
12429 if (new_cpu == nr_cpumask_bits)
12430 new_cpu = first_cpu;
12432 /* At this point, we leave the CPU as unassigned */
12435 /* We found a matching phys_id, so copy the IRQ info */
12436 cpup->eq = new_cpup->eq;
12438 /* Bump start_cpu to the next slot to minmize the
12439 * chance of having multiple unassigned CPU entries
12440 * selecting the same IRQ.
12442 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12443 if (start_cpu == nr_cpumask_bits)
12444 start_cpu = first_cpu;
12446 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12447 "3337 Set Affinity: CPU %d "
12448 "eq %d from peer cpu %d same "
12450 cpu, cpup->eq, new_cpu,
12455 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
12456 start_cpu = first_cpu;
12458 for_each_present_cpu(cpu) {
12459 cpup = &phba->sli4_hba.cpu_map[cpu];
12461 /* Is this entry unassigned */
12462 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12463 /* Mark it as IRQ not assigned by the kernel */
12464 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12466 /* If so, find a new_cpup thats on ANY phys_id
12467 * as the cpup. start_cpu will start where we
12468 * left off so all unassigned entries don't get
12469 * assigned the IRQ of the first entry.
12471 new_cpu = start_cpu;
12472 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12473 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12474 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12475 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
12477 new_cpu = cpumask_next(
12478 new_cpu, cpu_present_mask);
12479 if (new_cpu == nr_cpumask_bits)
12480 new_cpu = first_cpu;
12482 /* We should never leave an entry unassigned */
12483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12484 "3339 Set Affinity: CPU %d "
12485 "eq %d UNASSIGNED\n",
12486 cpup->hdwq, cpup->eq);
12489 /* We found an available entry, copy the IRQ info */
12490 cpup->eq = new_cpup->eq;
12492 /* Bump start_cpu to the next slot to minmize the
12493 * chance of having multiple unassigned CPU entries
12494 * selecting the same IRQ.
12496 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12497 if (start_cpu == nr_cpumask_bits)
12498 start_cpu = first_cpu;
12500 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12501 "3338 Set Affinity: CPU %d "
12502 "eq %d from peer cpu %d (%d/%d)\n",
12503 cpu, cpup->eq, new_cpu,
12504 new_cpup->phys_id, new_cpup->core_id);
12508 /* Assign hdwq indices that are unique across all cpus in the map
12509 * that are also FIRST_CPUs.
12512 for_each_present_cpu(cpu) {
12513 cpup = &phba->sli4_hba.cpu_map[cpu];
12515 /* Only FIRST IRQs get a hdwq index assignment. */
12516 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12519 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
12522 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12523 "3333 Set Affinity: CPU %d (phys %d core %d): "
12524 "hdwq %d eq %d flg x%x\n",
12525 cpu, cpup->phys_id, cpup->core_id,
12526 cpup->hdwq, cpup->eq, cpup->flag);
12528 /* Associate a hdwq with each cpu_map entry
12529 * This will be 1 to 1 - hdwq to cpu, unless there are less
12530 * hardware queues then CPUs. For that case we will just round-robin
12531 * the available hardware queues as they get assigned to CPUs.
12532 * The next_idx is the idx from the FIRST_CPU loop above to account
12533 * for irq_chann < hdwq. The idx is used for round-robin assignments
12534 * and needs to start at 0.
12539 for_each_present_cpu(cpu) {
12540 cpup = &phba->sli4_hba.cpu_map[cpu];
12542 /* FIRST cpus are already mapped. */
12543 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
12546 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
12547 * of the unassigned cpus to the next idx so that all
12548 * hdw queues are fully utilized.
12550 if (next_idx < phba->cfg_hdw_queue) {
12551 cpup->hdwq = next_idx;
12556 /* Not a First CPU and all hdw_queues are used. Reuse a
12557 * Hardware Queue for another CPU, so be smart about it
12558 * and pick one that has its IRQ/EQ mapped to the same phys_id
12559 * (CPU package) and core_id.
12561 new_cpu = start_cpu;
12562 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12563 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12564 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12565 new_cpup->phys_id == cpup->phys_id &&
12566 new_cpup->core_id == cpup->core_id) {
12569 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12570 if (new_cpu == nr_cpumask_bits)
12571 new_cpu = first_cpu;
12574 /* If we can't match both phys_id and core_id,
12575 * settle for just a phys_id match.
12577 new_cpu = start_cpu;
12578 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12579 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12580 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12581 new_cpup->phys_id == cpup->phys_id)
12584 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12585 if (new_cpu == nr_cpumask_bits)
12586 new_cpu = first_cpu;
12589 /* Otherwise just round robin on cfg_hdw_queue */
12590 cpup->hdwq = idx % phba->cfg_hdw_queue;
12594 /* We found an available entry, copy the IRQ info */
12595 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12596 if (start_cpu == nr_cpumask_bits)
12597 start_cpu = first_cpu;
12598 cpup->hdwq = new_cpup->hdwq;
12600 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12601 "3335 Set Affinity: CPU %d (phys %d core %d): "
12602 "hdwq %d eq %d flg x%x\n",
12603 cpu, cpup->phys_id, cpup->core_id,
12604 cpup->hdwq, cpup->eq, cpup->flag);
12608 * Initialize the cpu_map slots for not-present cpus in case
12609 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
12612 for_each_possible_cpu(cpu) {
12613 cpup = &phba->sli4_hba.cpu_map[cpu];
12614 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12615 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
12616 c_stat->hdwq_no = cpup->hdwq;
12618 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
12621 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
12622 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12623 c_stat->hdwq_no = cpup->hdwq;
12625 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12626 "3340 Set Affinity: not present "
12627 "CPU %d hdwq %d\n",
12631 /* The cpu_map array will be used later during initialization
12632 * when EQ / CQ / WQs are allocated and configured.
12638 * lpfc_cpuhp_get_eq
12640 * @phba: pointer to lpfc hba data structure.
12641 * @cpu: cpu going offline
12642 * @eqlist: eq list to append to
12645 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12646 struct list_head *eqlist)
12648 const struct cpumask *maskp;
12649 struct lpfc_queue *eq;
12650 struct cpumask *tmp;
12653 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12657 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12658 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12662 * if irq is not affinitized to the cpu going
12663 * then we don't need to poll the eq attached
12666 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
12668 /* get the cpus that are online and are affini-
12669 * tized to this irq vector. If the count is
12670 * more than 1 then cpuhp is not going to shut-
12671 * down this vector. Since this cpu has not
12672 * gone offline yet, we need >1.
12674 cpumask_and(tmp, maskp, cpu_online_mask);
12675 if (cpumask_weight(tmp) > 1)
12678 /* Now that we have an irq to shutdown, get the eq
12679 * mapped to this irq. Note: multiple hdwq's in
12680 * the software can share an eq, but eventually
12681 * only eq will be mapped to this vector
12683 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12684 list_add(&eq->_poll_list, eqlist);
12690 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12692 if (phba->sli_rev != LPFC_SLI_REV4)
12695 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12698 * unregistering the instance doesn't stop the polling
12699 * timer. Wait for the poll timer to retire.
12702 del_timer_sync(&phba->cpuhp_poll_timer);
12705 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12707 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
12710 __lpfc_cpuhp_remove(phba);
12713 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12715 if (phba->sli_rev != LPFC_SLI_REV4)
12720 if (!list_empty(&phba->poll_list))
12721 mod_timer(&phba->cpuhp_poll_timer,
12722 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
12726 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12730 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12732 if (phba->pport->load_flag & FC_UNLOADING) {
12737 if (phba->sli_rev != LPFC_SLI_REV4) {
12742 /* proceed with the hotplug */
12747 * lpfc_irq_set_aff - set IRQ affinity
12748 * @eqhdl: EQ handle
12749 * @cpu: cpu to set affinity
12753 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12755 cpumask_clear(&eqhdl->aff_mask);
12756 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12757 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12758 irq_set_affinity(eqhdl->irq, &eqhdl->aff_mask);
12762 * lpfc_irq_clear_aff - clear IRQ affinity
12763 * @eqhdl: EQ handle
12767 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12769 cpumask_clear(&eqhdl->aff_mask);
12770 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12774 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12775 * @phba: pointer to HBA context object.
12776 * @cpu: cpu going offline/online
12777 * @offline: true, cpu is going offline. false, cpu is coming online.
12779 * If cpu is going offline, we'll try our best effort to find the next
12780 * online cpu on the phba's original_mask and migrate all offlining IRQ
12783 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
12785 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
12786 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12790 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12792 struct lpfc_vector_map_info *cpup;
12793 struct cpumask *aff_mask;
12794 unsigned int cpu_select, cpu_next, idx;
12795 const struct cpumask *orig_mask;
12797 if (phba->irq_chann_mode == NORMAL_MODE)
12800 orig_mask = &phba->sli4_hba.irq_aff_mask;
12802 if (!cpumask_test_cpu(cpu, orig_mask))
12805 cpup = &phba->sli4_hba.cpu_map[cpu];
12807 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12811 /* Find next online CPU on original mask */
12812 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12813 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
12815 /* Found a valid CPU */
12816 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12817 /* Go through each eqhdl and ensure offlining
12818 * cpu aff_mask is migrated
12820 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12821 aff_mask = lpfc_get_aff_mask(idx);
12823 /* Migrate affinity */
12824 if (cpumask_test_cpu(cpu, aff_mask))
12825 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12829 /* Rely on irqbalance if no online CPUs left on NUMA */
12830 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12831 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12834 /* Migrate affinity back to this CPU */
12835 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12839 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12841 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12842 struct lpfc_queue *eq, *next;
12847 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12851 if (__lpfc_cpuhp_checks(phba, &retval))
12854 lpfc_irq_rebalance(phba, cpu, true);
12856 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12860 /* start polling on these eq's */
12861 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12862 list_del_init(&eq->_poll_list);
12863 lpfc_sli4_start_polling(eq);
12869 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
12871 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12872 struct lpfc_queue *eq, *next;
12877 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12881 if (__lpfc_cpuhp_checks(phba, &retval))
12884 lpfc_irq_rebalance(phba, cpu, false);
12886 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
12887 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
12889 lpfc_sli4_stop_polling(eq);
12896 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
12897 * @phba: pointer to lpfc hba data structure.
12899 * This routine is invoked to enable the MSI-X interrupt vectors to device
12900 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
12901 * to cpus on the system.
12903 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
12904 * the number of cpus on the same numa node as this adapter. The vectors are
12905 * allocated without requesting OS affinity mapping. A vector will be
12906 * allocated and assigned to each online and offline cpu. If the cpu is
12907 * online, then affinity will be set to that cpu. If the cpu is offline, then
12908 * affinity will be set to the nearest peer cpu within the numa node that is
12909 * online. If there are no online cpus within the numa node, affinity is not
12910 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
12911 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
12914 * If numa mode is not enabled and there is more than 1 vector allocated, then
12915 * the driver relies on the managed irq interface where the OS assigns vector to
12916 * cpu affinity. The driver will then use that affinity mapping to setup its
12917 * cpu mapping table.
12921 * other values - error
12924 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
12926 int vectors, rc, index;
12928 const struct cpumask *aff_mask = NULL;
12929 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
12930 struct lpfc_vector_map_info *cpup;
12931 struct lpfc_hba_eq_hdl *eqhdl;
12932 const struct cpumask *maskp;
12933 unsigned int flags = PCI_IRQ_MSIX;
12935 /* Set up MSI-X multi-message vectors */
12936 vectors = phba->cfg_irq_chann;
12938 if (phba->irq_chann_mode != NORMAL_MODE)
12939 aff_mask = &phba->sli4_hba.irq_aff_mask;
12942 cpu_cnt = cpumask_weight(aff_mask);
12943 vectors = min(phba->cfg_irq_chann, cpu_cnt);
12945 /* cpu: iterates over aff_mask including offline or online
12946 * cpu_select: iterates over online aff_mask to set affinity
12948 cpu = cpumask_first(aff_mask);
12949 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12951 flags |= PCI_IRQ_AFFINITY;
12954 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
12956 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12957 "0484 PCI enable MSI-X failed (%d)\n", rc);
12962 /* Assign MSI-X vectors to interrupt handlers */
12963 for (index = 0; index < vectors; index++) {
12964 eqhdl = lpfc_get_eq_hdl(index);
12965 name = eqhdl->handler_name;
12966 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
12967 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
12968 LPFC_DRIVER_HANDLER_NAME"%d", index);
12970 eqhdl->idx = index;
12971 rc = request_irq(pci_irq_vector(phba->pcidev, index),
12972 &lpfc_sli4_hba_intr_handler, 0,
12975 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12976 "0486 MSI-X fast-path (%d) "
12977 "request_irq failed (%d)\n", index, rc);
12981 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
12984 /* If found a neighboring online cpu, set affinity */
12985 if (cpu_select < nr_cpu_ids)
12986 lpfc_irq_set_aff(eqhdl, cpu_select);
12988 /* Assign EQ to cpu_map */
12989 lpfc_assign_eq_map_info(phba, index,
12990 LPFC_CPU_FIRST_IRQ,
12993 /* Iterate to next offline or online cpu in aff_mask */
12994 cpu = cpumask_next(cpu, aff_mask);
12996 /* Find next online cpu in aff_mask to set affinity */
12997 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12998 } else if (vectors == 1) {
12999 cpu = cpumask_first(cpu_present_mask);
13000 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
13003 maskp = pci_irq_get_affinity(phba->pcidev, index);
13005 /* Loop through all CPUs associated with vector index */
13006 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
13007 cpup = &phba->sli4_hba.cpu_map[cpu];
13009 /* If this is the first CPU thats assigned to
13010 * this vector, set LPFC_CPU_FIRST_IRQ.
13012 * With certain platforms its possible that irq
13013 * vectors are affinitized to all the cpu's.
13014 * This can result in each cpu_map.eq to be set
13015 * to the last vector, resulting in overwrite
13016 * of all the previous cpu_map.eq. Ensure that
13017 * each vector receives a place in cpu_map.
13018 * Later call to lpfc_cpu_affinity_check will
13019 * ensure we are nicely balanced out.
13021 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
13023 lpfc_assign_eq_map_info(phba, index,
13024 LPFC_CPU_FIRST_IRQ,
13031 if (vectors != phba->cfg_irq_chann) {
13032 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13033 "3238 Reducing IO channels to match number of "
13034 "MSI-X vectors, requested %d got %d\n",
13035 phba->cfg_irq_chann, vectors);
13036 if (phba->cfg_irq_chann > vectors)
13037 phba->cfg_irq_chann = vectors;
13043 /* free the irq already requested */
13044 for (--index; index >= 0; index--) {
13045 eqhdl = lpfc_get_eq_hdl(index);
13046 lpfc_irq_clear_aff(eqhdl);
13047 free_irq(eqhdl->irq, eqhdl);
13050 /* Unconfigure MSI-X capability structure */
13051 pci_free_irq_vectors(phba->pcidev);
13058 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
13059 * @phba: pointer to lpfc hba data structure.
13061 * This routine is invoked to enable the MSI interrupt mode to device with
13062 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
13063 * called to enable the MSI vector. The device driver is responsible for
13064 * calling the request_irq() to register MSI vector with a interrupt the
13065 * handler, which is done in this function.
13069 * other values - error
13072 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
13076 struct lpfc_hba_eq_hdl *eqhdl;
13078 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
13079 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
13081 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13082 "0487 PCI enable MSI mode success.\n");
13084 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13085 "0488 PCI enable MSI mode failed (%d)\n", rc);
13086 return rc ? rc : -1;
13089 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13090 0, LPFC_DRIVER_NAME, phba);
13092 pci_free_irq_vectors(phba->pcidev);
13093 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13094 "0490 MSI request_irq failed (%d)\n", rc);
13098 eqhdl = lpfc_get_eq_hdl(0);
13099 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
13101 cpu = cpumask_first(cpu_present_mask);
13102 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
13104 for (index = 0; index < phba->cfg_irq_chann; index++) {
13105 eqhdl = lpfc_get_eq_hdl(index);
13106 eqhdl->idx = index;
13113 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
13114 * @phba: pointer to lpfc hba data structure.
13115 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
13117 * This routine is invoked to enable device interrupt and associate driver's
13118 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
13119 * interface spec. Depends on the interrupt mode configured to the driver,
13120 * the driver will try to fallback from the configured interrupt mode to an
13121 * interrupt mode which is supported by the platform, kernel, and device in
13123 * MSI-X -> MSI -> IRQ.
13127 * other values - error
13130 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
13132 uint32_t intr_mode = LPFC_INTR_ERROR;
13135 if (cfg_mode == 2) {
13136 /* Preparation before conf_msi mbox cmd */
13139 /* Now, try to enable MSI-X interrupt mode */
13140 retval = lpfc_sli4_enable_msix(phba);
13142 /* Indicate initialization to MSI-X mode */
13143 phba->intr_type = MSIX;
13149 /* Fallback to MSI if MSI-X initialization failed */
13150 if (cfg_mode >= 1 && phba->intr_type == NONE) {
13151 retval = lpfc_sli4_enable_msi(phba);
13153 /* Indicate initialization to MSI mode */
13154 phba->intr_type = MSI;
13159 /* Fallback to INTx if both MSI-X/MSI initalization failed */
13160 if (phba->intr_type == NONE) {
13161 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13162 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
13164 struct lpfc_hba_eq_hdl *eqhdl;
13167 /* Indicate initialization to INTx mode */
13168 phba->intr_type = INTx;
13171 eqhdl = lpfc_get_eq_hdl(0);
13172 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
13174 cpu = cpumask_first(cpu_present_mask);
13175 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
13177 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
13178 eqhdl = lpfc_get_eq_hdl(idx);
13187 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
13188 * @phba: pointer to lpfc hba data structure.
13190 * This routine is invoked to disable device interrupt and disassociate
13191 * the driver's interrupt handler(s) from interrupt vector(s) to device
13192 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
13193 * will release the interrupt vector(s) for the message signaled interrupt.
13196 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
13198 /* Disable the currently initialized interrupt mode */
13199 if (phba->intr_type == MSIX) {
13201 struct lpfc_hba_eq_hdl *eqhdl;
13203 /* Free up MSI-X multi-message vectors */
13204 for (index = 0; index < phba->cfg_irq_chann; index++) {
13205 eqhdl = lpfc_get_eq_hdl(index);
13206 lpfc_irq_clear_aff(eqhdl);
13207 free_irq(eqhdl->irq, eqhdl);
13210 free_irq(phba->pcidev->irq, phba);
13213 pci_free_irq_vectors(phba->pcidev);
13215 /* Reset interrupt management states */
13216 phba->intr_type = NONE;
13217 phba->sli.slistat.sli_intr = 0;
13221 * lpfc_unset_hba - Unset SLI3 hba device initialization
13222 * @phba: pointer to lpfc hba data structure.
13224 * This routine is invoked to unset the HBA device initialization steps to
13225 * a device with SLI-3 interface spec.
13228 lpfc_unset_hba(struct lpfc_hba *phba)
13230 struct lpfc_vport *vport = phba->pport;
13231 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
13233 spin_lock_irq(shost->host_lock);
13234 vport->load_flag |= FC_UNLOADING;
13235 spin_unlock_irq(shost->host_lock);
13237 kfree(phba->vpi_bmask);
13238 kfree(phba->vpi_ids);
13240 lpfc_stop_hba_timers(phba);
13242 phba->pport->work_port_events = 0;
13244 lpfc_sli_hba_down(phba);
13246 lpfc_sli_brdrestart(phba);
13248 lpfc_sli_disable_intr(phba);
13254 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
13255 * @phba: Pointer to HBA context object.
13257 * This function is called in the SLI4 code path to wait for completion
13258 * of device's XRIs exchange busy. It will check the XRI exchange busy
13259 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
13260 * that, it will check the XRI exchange busy on outstanding FCP and ELS
13261 * I/Os every 30 seconds, log error message, and wait forever. Only when
13262 * all XRI exchange busy complete, the driver unload shall proceed with
13263 * invoking the function reset ioctl mailbox command to the CNA and the
13264 * the rest of the driver unload resource release.
13267 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
13269 struct lpfc_sli4_hdw_queue *qp;
13272 int io_xri_cmpl = 1;
13273 int nvmet_xri_cmpl = 1;
13274 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13276 /* Driver just aborted IOs during the hba_unset process. Pause
13277 * here to give the HBA time to complete the IO and get entries
13278 * into the abts lists.
13280 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
13282 /* Wait for NVME pending IO to flush back to transport. */
13283 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13284 lpfc_nvme_wait_for_io_drain(phba);
13287 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13288 qp = &phba->sli4_hba.hdwq[idx];
13289 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
13290 if (!io_xri_cmpl) /* if list is NOT empty */
13296 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13298 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13301 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
13302 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
13303 if (!nvmet_xri_cmpl)
13304 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13305 "6424 NVMET XRI exchange busy "
13306 "wait time: %d seconds.\n",
13309 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13310 "6100 IO XRI exchange busy "
13311 "wait time: %d seconds.\n",
13314 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13315 "2878 ELS XRI exchange busy "
13316 "wait time: %d seconds.\n",
13318 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
13319 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
13321 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
13322 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
13326 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13327 qp = &phba->sli4_hba.hdwq[idx];
13328 io_xri_cmpl = list_empty(
13329 &qp->lpfc_abts_io_buf_list);
13330 if (!io_xri_cmpl) /* if list is NOT empty */
13336 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13337 nvmet_xri_cmpl = list_empty(
13338 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13341 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13347 * lpfc_sli4_hba_unset - Unset the fcoe hba
13348 * @phba: Pointer to HBA context object.
13350 * This function is called in the SLI4 code path to reset the HBA's FCoE
13351 * function. The caller is not required to hold any lock. This routine
13352 * issues PCI function reset mailbox command to reset the FCoE function.
13353 * At the end of the function, it calls lpfc_hba_down_post function to
13354 * free any pending commands.
13357 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
13360 LPFC_MBOXQ_t *mboxq;
13361 struct pci_dev *pdev = phba->pcidev;
13363 lpfc_stop_hba_timers(phba);
13364 hrtimer_cancel(&phba->cmf_timer);
13367 phba->sli4_hba.intr_enable = 0;
13370 * Gracefully wait out the potential current outstanding asynchronous
13374 /* First, block any pending async mailbox command from posted */
13375 spin_lock_irq(&phba->hbalock);
13376 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13377 spin_unlock_irq(&phba->hbalock);
13378 /* Now, trying to wait it out if we can */
13379 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13381 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
13384 /* Forcefully release the outstanding mailbox command if timed out */
13385 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13386 spin_lock_irq(&phba->hbalock);
13387 mboxq = phba->sli.mbox_active;
13388 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
13389 __lpfc_mbox_cmpl_put(phba, mboxq);
13390 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13391 phba->sli.mbox_active = NULL;
13392 spin_unlock_irq(&phba->hbalock);
13395 /* Abort all iocbs associated with the hba */
13396 lpfc_sli_hba_iocb_abort(phba);
13398 if (!pci_channel_offline(phba->pcidev))
13399 /* Wait for completion of device XRI exchange busy */
13400 lpfc_sli4_xri_exchange_busy_wait(phba);
13402 /* per-phba callback de-registration for hotplug event */
13404 lpfc_cpuhp_remove(phba);
13406 /* Disable PCI subsystem interrupt */
13407 lpfc_sli4_disable_intr(phba);
13409 /* Disable SR-IOV if enabled */
13410 if (phba->cfg_sriov_nr_virtfn)
13411 pci_disable_sriov(pdev);
13413 /* Stop kthread signal shall trigger work_done one more time */
13414 kthread_stop(phba->worker_thread);
13416 /* Disable FW logging to host memory */
13417 lpfc_ras_stop_fwlog(phba);
13419 /* Reset SLI4 HBA FCoE function */
13420 lpfc_pci_function_reset(phba);
13422 /* release all queue allocated resources. */
13423 lpfc_sli4_queue_destroy(phba);
13425 /* Free RAS DMA memory */
13426 if (phba->ras_fwlog.ras_enabled)
13427 lpfc_sli4_ras_dma_free(phba);
13429 /* Stop the SLI4 device port */
13431 phba->pport->work_port_events = 0;
13435 lpfc_cgn_crc32(uint32_t crc, u8 byte)
13440 for (bit = 0; bit < 8; bit++) {
13441 msb = (crc >> 31) & 1;
13444 if (msb ^ (byte & 1)) {
13445 crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
13454 lpfc_cgn_reverse_bits(uint32_t wd)
13456 uint32_t result = 0;
13459 for (i = 0; i < 32; i++) {
13461 result |= (1 & (wd >> i));
13467 * The routine corresponds with the algorithm the HBA firmware
13468 * uses to validate the data integrity.
13471 lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
13475 uint8_t *data = (uint8_t *)ptr;
13477 for (i = 0; i < byteLen; ++i)
13478 crc = lpfc_cgn_crc32(crc, data[i]);
13480 result = ~lpfc_cgn_reverse_bits(crc);
13485 lpfc_init_congestion_buf(struct lpfc_hba *phba)
13487 struct lpfc_cgn_info *cp;
13488 struct timespec64 cmpl_time;
13493 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13494 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
13498 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13500 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
13501 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
13502 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
13503 atomic_set(&phba->cgn_sync_warn_cnt, 0);
13505 atomic_set(&phba->cgn_driver_evt_cnt, 0);
13506 atomic_set(&phba->cgn_latency_evt_cnt, 0);
13507 atomic64_set(&phba->cgn_latency_evt, 0);
13508 phba->cgn_evt_minute = 0;
13509 phba->hba_flag &= ~HBA_CGN_DAY_WRAP;
13511 memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat));
13512 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
13513 cp->cgn_info_version = LPFC_CGN_INFO_V3;
13515 /* cgn parameters */
13516 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
13517 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
13518 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
13519 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
13521 ktime_get_real_ts64(&cmpl_time);
13522 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13524 cp->cgn_info_month = broken.tm_mon + 1;
13525 cp->cgn_info_day = broken.tm_mday;
13526 cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */
13527 cp->cgn_info_hour = broken.tm_hour;
13528 cp->cgn_info_minute = broken.tm_min;
13529 cp->cgn_info_second = broken.tm_sec;
13531 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13532 "2643 CGNInfo Init: Start Time "
13533 "%d/%d/%d %d:%d:%d\n",
13534 cp->cgn_info_day, cp->cgn_info_month,
13535 cp->cgn_info_year, cp->cgn_info_hour,
13536 cp->cgn_info_minute, cp->cgn_info_second);
13538 /* Fill in default LUN qdepth */
13540 size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
13541 cp->cgn_lunq = cpu_to_le16(size);
13544 /* last used Index initialized to 0xff already */
13546 cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13547 cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13548 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13549 cp->cgn_info_crc = cpu_to_le32(crc);
13551 phba->cgn_evt_timestamp = jiffies +
13552 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
13556 lpfc_init_congestion_stat(struct lpfc_hba *phba)
13558 struct lpfc_cgn_info *cp;
13559 struct timespec64 cmpl_time;
13563 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13564 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
13569 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13570 memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));
13572 ktime_get_real_ts64(&cmpl_time);
13573 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13575 cp->cgn_stat_month = broken.tm_mon + 1;
13576 cp->cgn_stat_day = broken.tm_mday;
13577 cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */
13578 cp->cgn_stat_hour = broken.tm_hour;
13579 cp->cgn_stat_minute = broken.tm_min;
13581 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13582 "2647 CGNstat Init: Start Time "
13583 "%d/%d/%d %d:%d\n",
13584 cp->cgn_stat_day, cp->cgn_stat_month,
13585 cp->cgn_stat_year, cp->cgn_stat_hour,
13586 cp->cgn_stat_minute);
13588 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13589 cp->cgn_info_crc = cpu_to_le32(crc);
13593 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
13594 * @phba: Pointer to hba context object.
13595 * @reg: flag to determine register or unregister.
13598 __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
13600 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
13601 union lpfc_sli4_cfg_shdr *shdr;
13602 uint32_t shdr_status, shdr_add_status;
13603 LPFC_MBOXQ_t *mboxq;
13609 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13611 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13612 "2641 REG_CONGESTION_BUF mbox allocation fail: "
13613 "HBA state x%x reg %d\n",
13614 phba->pport->port_state, reg);
13618 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
13619 sizeof(struct lpfc_sli4_cfg_mhdr));
13620 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13621 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
13622 LPFC_SLI4_MBX_EMBED);
13623 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
13624 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
13626 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
13628 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
13629 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
13630 reg_congestion_buf->addr_lo =
13631 putPaddrLow(phba->cgn_i->phys);
13632 reg_congestion_buf->addr_hi =
13633 putPaddrHigh(phba->cgn_i->phys);
13635 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13636 shdr = (union lpfc_sli4_cfg_shdr *)
13637 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
13638 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13639 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13641 mempool_free(mboxq, phba->mbox_mem_pool);
13642 if (shdr_status || shdr_add_status || rc) {
13643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13644 "2642 REG_CONGESTION_BUF mailbox "
13645 "failed with status x%x add_status x%x,"
13646 " mbx status x%x reg %d\n",
13647 shdr_status, shdr_add_status, rc, reg);
13654 lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
13656 lpfc_cmf_stop(phba);
13657 return __lpfc_reg_congestion_buf(phba, 0);
13661 lpfc_reg_congestion_buf(struct lpfc_hba *phba)
13663 return __lpfc_reg_congestion_buf(phba, 1);
13667 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
13668 * @phba: Pointer to HBA context object.
13669 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
13671 * This function is called in the SLI4 code path to read the port's
13672 * sli4 capabilities.
13674 * This function may be be called from any context that can block-wait
13675 * for the completion. The expectation is that this routine is called
13676 * typically from probe_one or from the online routine.
13679 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
13682 struct lpfc_mqe *mqe = &mboxq->u.mqe;
13683 struct lpfc_pc_sli4_params *sli4_params;
13686 bool exp_wqcq_pages = true;
13687 struct lpfc_sli4_parameters *mbx_sli4_parameters;
13690 * By default, the driver assumes the SLI4 port requires RPI
13691 * header postings. The SLI4_PARAM response will correct this
13694 phba->sli4_hba.rpi_hdrs_in_use = 1;
13696 /* Read the port's SLI4 Config Parameters */
13697 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
13698 sizeof(struct lpfc_sli4_cfg_mhdr));
13699 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13700 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
13701 length, LPFC_SLI4_MBX_EMBED);
13702 if (!phba->sli4_hba.intr_enable)
13703 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13705 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
13706 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
13710 sli4_params = &phba->sli4_hba.pc_sli4_params;
13711 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
13712 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
13713 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
13714 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
13715 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
13716 mbx_sli4_parameters);
13717 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
13718 mbx_sli4_parameters);
13719 if (bf_get(cfg_phwq, mbx_sli4_parameters))
13720 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
13722 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
13723 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
13724 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
13725 mbx_sli4_parameters);
13726 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
13727 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
13728 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
13729 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
13730 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
13731 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
13732 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
13733 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
13734 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
13735 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
13736 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
13737 mbx_sli4_parameters);
13738 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
13739 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
13740 mbx_sli4_parameters);
13741 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
13742 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
13744 /* Check for Extended Pre-Registered SGL support */
13745 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
13747 /* Check for firmware nvme support */
13748 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13749 bf_get(cfg_xib, mbx_sli4_parameters));
13752 /* Save this to indicate the Firmware supports NVME */
13753 sli4_params->nvme = 1;
13755 /* Firmware NVME support, check driver FC4 NVME support */
13756 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13757 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13758 "6133 Disabling NVME support: "
13759 "FC4 type not supported: x%x\n",
13760 phba->cfg_enable_fc4_type);
13764 /* No firmware NVME support, check driver FC4 NVME support */
13765 sli4_params->nvme = 0;
13766 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13767 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13768 "6101 Disabling NVME support: Not "
13769 "supported by firmware (%d %d) x%x\n",
13770 bf_get(cfg_nvme, mbx_sli4_parameters),
13771 bf_get(cfg_xib, mbx_sli4_parameters),
13772 phba->cfg_enable_fc4_type);
13774 phba->nvmet_support = 0;
13775 phba->cfg_nvmet_mrq = 0;
13776 phba->cfg_nvme_seg_cnt = 0;
13778 /* If no FC4 type support, move to just SCSI support */
13779 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13781 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13785 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
13786 * accommodate 512K and 1M IOs in a single nvme buf.
13788 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13789 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
13791 /* Enable embedded Payload BDE if support is indicated */
13792 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13793 phba->cfg_enable_pbde = 1;
13795 phba->cfg_enable_pbde = 0;
13798 * To support Suppress Response feature we must satisfy 3 conditions.
13799 * lpfc_suppress_rsp module parameter must be set (default).
13800 * In SLI4-Parameters Descriptor:
13801 * Extended Inline Buffers (XIB) must be supported.
13802 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13803 * (double negative).
13805 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13806 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
13807 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
13809 phba->cfg_suppress_rsp = 0;
13811 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13812 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13814 /* Make sure that sge_supp_len can be handled by the driver */
13815 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13816 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13819 * Check whether the adapter supports an embedded copy of the
13820 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13821 * to use this option, 128-byte WQEs must be used.
13823 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13824 phba->fcp_embed_io = 1;
13826 phba->fcp_embed_io = 0;
13828 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13829 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
13830 bf_get(cfg_xib, mbx_sli4_parameters),
13831 phba->cfg_enable_pbde,
13832 phba->fcp_embed_io, sli4_params->nvme,
13833 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
13835 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
13836 LPFC_SLI_INTF_IF_TYPE_2) &&
13837 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
13838 LPFC_SLI_INTF_FAMILY_LNCR_A0))
13839 exp_wqcq_pages = false;
13841 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
13842 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
13844 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
13845 phba->enab_exp_wqcq_pages = 1;
13847 phba->enab_exp_wqcq_pages = 0;
13849 * Check if the SLI port supports MDS Diagnostics
13851 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
13852 phba->mds_diags_support = 1;
13854 phba->mds_diags_support = 0;
13857 * Check if the SLI port supports NSLER
13859 if (bf_get(cfg_nsler, mbx_sli4_parameters))
13868 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
13869 * @pdev: pointer to PCI device
13870 * @pid: pointer to PCI device identifier
13872 * This routine is to be called to attach a device with SLI-3 interface spec
13873 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13874 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13875 * information of the device and driver to see if the driver state that it can
13876 * support this kind of device. If the match is successful, the driver core
13877 * invokes this routine. If this routine determines it can claim the HBA, it
13878 * does all the initialization that it needs to do to handle the HBA properly.
13881 * 0 - driver can claim the device
13882 * negative value - driver can not claim the device
13885 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
13887 struct lpfc_hba *phba;
13888 struct lpfc_vport *vport = NULL;
13889 struct Scsi_Host *shost = NULL;
13891 uint32_t cfg_mode, intr_mode;
13893 /* Allocate memory for HBA structure */
13894 phba = lpfc_hba_alloc(pdev);
13898 /* Perform generic PCI device enabling operation */
13899 error = lpfc_enable_pci_dev(phba);
13901 goto out_free_phba;
13903 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
13904 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
13906 goto out_disable_pci_dev;
13908 /* Set up SLI-3 specific device PCI memory space */
13909 error = lpfc_sli_pci_mem_setup(phba);
13911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13912 "1402 Failed to set up pci memory space.\n");
13913 goto out_disable_pci_dev;
13916 /* Set up SLI-3 specific device driver resources */
13917 error = lpfc_sli_driver_resource_setup(phba);
13919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13920 "1404 Failed to set up driver resource.\n");
13921 goto out_unset_pci_mem_s3;
13924 /* Initialize and populate the iocb list per host */
13926 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
13928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13929 "1405 Failed to initialize iocb list.\n");
13930 goto out_unset_driver_resource_s3;
13933 /* Set up common device driver resources */
13934 error = lpfc_setup_driver_resource_phase2(phba);
13936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13937 "1406 Failed to set up driver resource.\n");
13938 goto out_free_iocb_list;
13941 /* Get the default values for Model Name and Description */
13942 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13944 /* Create SCSI host to the physical port */
13945 error = lpfc_create_shost(phba);
13947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13948 "1407 Failed to create scsi host.\n");
13949 goto out_unset_driver_resource;
13952 /* Configure sysfs attributes */
13953 vport = phba->pport;
13954 error = lpfc_alloc_sysfs_attr(vport);
13956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13957 "1476 Failed to allocate sysfs attr\n");
13958 goto out_destroy_shost;
13961 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
13962 /* Now, trying to enable interrupt and bring up the device */
13963 cfg_mode = phba->cfg_use_msi;
13965 /* Put device to a known state before enabling interrupt */
13966 lpfc_stop_port(phba);
13967 /* Configure and enable interrupt */
13968 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
13969 if (intr_mode == LPFC_INTR_ERROR) {
13970 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13971 "0431 Failed to enable interrupt.\n");
13973 goto out_free_sysfs_attr;
13975 /* SLI-3 HBA setup */
13976 if (lpfc_sli_hba_setup(phba)) {
13977 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13978 "1477 Failed to set up hba\n");
13980 goto out_remove_device;
13983 /* Wait 50ms for the interrupts of previous mailbox commands */
13985 /* Check active interrupts on message signaled interrupts */
13986 if (intr_mode == 0 ||
13987 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
13988 /* Log the current active interrupt mode */
13989 phba->intr_mode = intr_mode;
13990 lpfc_log_intr_mode(phba, intr_mode);
13993 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13994 "0447 Configure interrupt mode (%d) "
13995 "failed active interrupt test.\n",
13997 /* Disable the current interrupt mode */
13998 lpfc_sli_disable_intr(phba);
13999 /* Try next level of interrupt mode */
14000 cfg_mode = --intr_mode;
14004 /* Perform post initialization setup */
14005 lpfc_post_init_setup(phba);
14007 /* Check if there are static vports to be created. */
14008 lpfc_create_static_vport(phba);
14013 lpfc_unset_hba(phba);
14014 out_free_sysfs_attr:
14015 lpfc_free_sysfs_attr(vport);
14017 lpfc_destroy_shost(phba);
14018 out_unset_driver_resource:
14019 lpfc_unset_driver_resource_phase2(phba);
14020 out_free_iocb_list:
14021 lpfc_free_iocb_list(phba);
14022 out_unset_driver_resource_s3:
14023 lpfc_sli_driver_resource_unset(phba);
14024 out_unset_pci_mem_s3:
14025 lpfc_sli_pci_mem_unset(phba);
14026 out_disable_pci_dev:
14027 lpfc_disable_pci_dev(phba);
14029 scsi_host_put(shost);
14031 lpfc_hba_free(phba);
14036 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
14037 * @pdev: pointer to PCI device
14039 * This routine is to be called to disattach a device with SLI-3 interface
14040 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
14041 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14042 * device to be removed from the PCI subsystem properly.
14045 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
14047 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14049 struct lpfc_vport **vports;
14050 struct lpfc_hba *phba = vport->phba;
14053 spin_lock_irq(&phba->hbalock);
14054 vport->load_flag |= FC_UNLOADING;
14055 spin_unlock_irq(&phba->hbalock);
14057 lpfc_free_sysfs_attr(vport);
14059 /* Release all the vports against this physical port */
14060 vports = lpfc_create_vport_work_array(phba);
14061 if (vports != NULL)
14062 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14063 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14065 fc_vport_terminate(vports[i]->fc_vport);
14067 lpfc_destroy_vport_work_array(phba, vports);
14069 /* Remove FC host with the physical port */
14070 fc_remove_host(shost);
14071 scsi_remove_host(shost);
14073 /* Clean up all nodes, mailboxes and IOs. */
14074 lpfc_cleanup(vport);
14077 * Bring down the SLI Layer. This step disable all interrupts,
14078 * clears the rings, discards all mailbox commands, and resets
14082 /* HBA interrupt will be disabled after this call */
14083 lpfc_sli_hba_down(phba);
14084 /* Stop kthread signal shall trigger work_done one more time */
14085 kthread_stop(phba->worker_thread);
14086 /* Final cleanup of txcmplq and reset the HBA */
14087 lpfc_sli_brdrestart(phba);
14089 kfree(phba->vpi_bmask);
14090 kfree(phba->vpi_ids);
14092 lpfc_stop_hba_timers(phba);
14093 spin_lock_irq(&phba->port_list_lock);
14094 list_del_init(&vport->listentry);
14095 spin_unlock_irq(&phba->port_list_lock);
14097 lpfc_debugfs_terminate(vport);
14099 /* Disable SR-IOV if enabled */
14100 if (phba->cfg_sriov_nr_virtfn)
14101 pci_disable_sriov(pdev);
14103 /* Disable interrupt */
14104 lpfc_sli_disable_intr(phba);
14106 scsi_host_put(shost);
14109 * Call scsi_free before mem_free since scsi bufs are released to their
14110 * corresponding pools here.
14112 lpfc_scsi_free(phba);
14113 lpfc_free_iocb_list(phba);
14115 lpfc_mem_free_all(phba);
14117 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
14118 phba->hbqslimp.virt, phba->hbqslimp.phys);
14120 /* Free resources associated with SLI2 interface */
14121 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
14122 phba->slim2p.virt, phba->slim2p.phys);
14124 /* unmap adapter SLIM and Control Registers */
14125 iounmap(phba->ctrl_regs_memmap_p);
14126 iounmap(phba->slim_memmap_p);
14128 lpfc_hba_free(phba);
14130 pci_release_mem_regions(pdev);
14131 pci_disable_device(pdev);
14135 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
14136 * @dev_d: pointer to device
14138 * This routine is to be called from the kernel's PCI subsystem to support
14139 * system Power Management (PM) to device with SLI-3 interface spec. When
14140 * PM invokes this method, it quiesces the device by stopping the driver's
14141 * worker thread for the device, turning off device's interrupt and DMA,
14142 * and bring the device offline. Note that as the driver implements the
14143 * minimum PM requirements to a power-aware driver's PM support for the
14144 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14145 * to the suspend() method call will be treated as SUSPEND and the driver will
14146 * fully reinitialize its device during resume() method call, the driver will
14147 * set device to PCI_D3hot state in PCI config space instead of setting it
14148 * according to the @msg provided by the PM.
14151 * 0 - driver suspended the device
14154 static int __maybe_unused
14155 lpfc_pci_suspend_one_s3(struct device *dev_d)
14157 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14158 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14160 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14161 "0473 PCI device Power Management suspend.\n");
14163 /* Bring down the device */
14164 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14165 lpfc_offline(phba);
14166 kthread_stop(phba->worker_thread);
14168 /* Disable interrupt from device */
14169 lpfc_sli_disable_intr(phba);
14175 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
14176 * @dev_d: pointer to device
14178 * This routine is to be called from the kernel's PCI subsystem to support
14179 * system Power Management (PM) to device with SLI-3 interface spec. When PM
14180 * invokes this method, it restores the device's PCI config space state and
14181 * fully reinitializes the device and brings it online. Note that as the
14182 * driver implements the minimum PM requirements to a power-aware driver's
14183 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
14184 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
14185 * driver will fully reinitialize its device during resume() method call,
14186 * the device will be set to PCI_D0 directly in PCI config space before
14187 * restoring the state.
14190 * 0 - driver suspended the device
14193 static int __maybe_unused
14194 lpfc_pci_resume_one_s3(struct device *dev_d)
14196 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14197 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14198 uint32_t intr_mode;
14201 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14202 "0452 PCI device Power Management resume.\n");
14204 /* Startup the kernel thread for this host adapter. */
14205 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14206 "lpfc_worker_%d", phba->brd_no);
14207 if (IS_ERR(phba->worker_thread)) {
14208 error = PTR_ERR(phba->worker_thread);
14209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14210 "0434 PM resume failed to start worker "
14211 "thread: error=x%x.\n", error);
14215 /* Init cpu_map array */
14216 lpfc_cpu_map_array_init(phba);
14217 /* Init hba_eq_hdl array */
14218 lpfc_hba_eq_hdl_array_init(phba);
14219 /* Configure and enable interrupt */
14220 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14221 if (intr_mode == LPFC_INTR_ERROR) {
14222 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14223 "0430 PM resume Failed to enable interrupt\n");
14226 phba->intr_mode = intr_mode;
14228 /* Restart HBA and bring it online */
14229 lpfc_sli_brdrestart(phba);
14232 /* Log the current active interrupt mode */
14233 lpfc_log_intr_mode(phba, phba->intr_mode);
14239 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
14240 * @phba: pointer to lpfc hba data structure.
14242 * This routine is called to prepare the SLI3 device for PCI slot recover. It
14243 * aborts all the outstanding SCSI I/Os to the pci device.
14246 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
14248 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14249 "2723 PCI channel I/O abort preparing for recovery\n");
14252 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14253 * and let the SCSI mid-layer to retry them to recover.
14255 lpfc_sli_abort_fcp_rings(phba);
14259 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
14260 * @phba: pointer to lpfc hba data structure.
14262 * This routine is called to prepare the SLI3 device for PCI slot reset. It
14263 * disables the device interrupt and pci device, and aborts the internal FCP
14267 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
14269 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14270 "2710 PCI channel disable preparing for reset\n");
14272 /* Block any management I/Os to the device */
14273 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
14275 /* Block all SCSI devices' I/Os on the host */
14276 lpfc_scsi_dev_block(phba);
14278 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
14279 lpfc_sli_flush_io_rings(phba);
14281 /* stop all timers */
14282 lpfc_stop_hba_timers(phba);
14284 /* Disable interrupt and pci device */
14285 lpfc_sli_disable_intr(phba);
14286 pci_disable_device(phba->pcidev);
14290 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
14291 * @phba: pointer to lpfc hba data structure.
14293 * This routine is called to prepare the SLI3 device for PCI slot permanently
14294 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14298 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
14300 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14301 "2711 PCI channel permanent disable for failure\n");
14302 /* Block all SCSI devices' I/Os on the host */
14303 lpfc_scsi_dev_block(phba);
14304 lpfc_sli4_prep_dev_for_reset(phba);
14306 /* stop all timers */
14307 lpfc_stop_hba_timers(phba);
14309 /* Clean up all driver's outstanding SCSI I/Os */
14310 lpfc_sli_flush_io_rings(phba);
14314 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
14315 * @pdev: pointer to PCI device.
14316 * @state: the current PCI connection state.
14318 * This routine is called from the PCI subsystem for I/O error handling to
14319 * device with SLI-3 interface spec. This function is called by the PCI
14320 * subsystem after a PCI bus error affecting this device has been detected.
14321 * When this function is invoked, it will need to stop all the I/Os and
14322 * interrupt(s) to the device. Once that is done, it will return
14323 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
14327 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
14328 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14329 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14331 static pci_ers_result_t
14332 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
14334 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14335 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14338 case pci_channel_io_normal:
14339 /* Non-fatal error, prepare for recovery */
14340 lpfc_sli_prep_dev_for_recover(phba);
14341 return PCI_ERS_RESULT_CAN_RECOVER;
14342 case pci_channel_io_frozen:
14343 /* Fatal error, prepare for slot reset */
14344 lpfc_sli_prep_dev_for_reset(phba);
14345 return PCI_ERS_RESULT_NEED_RESET;
14346 case pci_channel_io_perm_failure:
14347 /* Permanent failure, prepare for device down */
14348 lpfc_sli_prep_dev_for_perm_failure(phba);
14349 return PCI_ERS_RESULT_DISCONNECT;
14351 /* Unknown state, prepare and request slot reset */
14352 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14353 "0472 Unknown PCI error state: x%x\n", state);
14354 lpfc_sli_prep_dev_for_reset(phba);
14355 return PCI_ERS_RESULT_NEED_RESET;
14360 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
14361 * @pdev: pointer to PCI device.
14363 * This routine is called from the PCI subsystem for error handling to
14364 * device with SLI-3 interface spec. This is called after PCI bus has been
14365 * reset to restart the PCI card from scratch, as if from a cold-boot.
14366 * During the PCI subsystem error recovery, after driver returns
14367 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14368 * recovery and then call this routine before calling the .resume method
14369 * to recover the device. This function will initialize the HBA device,
14370 * enable the interrupt, but it will just put the HBA to offline state
14371 * without passing any I/O traffic.
14374 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14375 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14377 static pci_ers_result_t
14378 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
14380 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14381 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14382 struct lpfc_sli *psli = &phba->sli;
14383 uint32_t intr_mode;
14385 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
14386 if (pci_enable_device_mem(pdev)) {
14387 printk(KERN_ERR "lpfc: Cannot re-enable "
14388 "PCI device after reset.\n");
14389 return PCI_ERS_RESULT_DISCONNECT;
14392 pci_restore_state(pdev);
14395 * As the new kernel behavior of pci_restore_state() API call clears
14396 * device saved_state flag, need to save the restored state again.
14398 pci_save_state(pdev);
14400 if (pdev->is_busmaster)
14401 pci_set_master(pdev);
14403 spin_lock_irq(&phba->hbalock);
14404 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
14405 spin_unlock_irq(&phba->hbalock);
14407 /* Configure and enable interrupt */
14408 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14409 if (intr_mode == LPFC_INTR_ERROR) {
14410 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14411 "0427 Cannot re-enable interrupt after "
14413 return PCI_ERS_RESULT_DISCONNECT;
14415 phba->intr_mode = intr_mode;
14417 /* Take device offline, it will perform cleanup */
14418 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14419 lpfc_offline(phba);
14420 lpfc_sli_brdrestart(phba);
14422 /* Log the current active interrupt mode */
14423 lpfc_log_intr_mode(phba, phba->intr_mode);
14425 return PCI_ERS_RESULT_RECOVERED;
14429 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
14430 * @pdev: pointer to PCI device
14432 * This routine is called from the PCI subsystem for error handling to device
14433 * with SLI-3 interface spec. It is called when kernel error recovery tells
14434 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14435 * error recovery. After this call, traffic can start to flow from this device
14439 lpfc_io_resume_s3(struct pci_dev *pdev)
14441 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14442 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14444 /* Bring device online, it will be no-op for non-fatal error resume */
14449 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
14450 * @phba: pointer to lpfc hba data structure.
14452 * returns the number of ELS/CT IOCBs to reserve
14455 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
14457 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
14459 if (phba->sli_rev == LPFC_SLI_REV4) {
14460 if (max_xri <= 100)
14462 else if (max_xri <= 256)
14464 else if (max_xri <= 512)
14466 else if (max_xri <= 1024)
14468 else if (max_xri <= 1536)
14470 else if (max_xri <= 2048)
14479 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
14480 * @phba: pointer to lpfc hba data structure.
14482 * returns the number of ELS/CT + NVMET IOCBs to reserve
14485 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
14487 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
14489 if (phba->nvmet_support)
14490 max_xri += LPFC_NVMET_BUF_POST;
14496 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
14497 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
14498 const struct firmware *fw)
14503 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
14504 /* Three cases: (1) FW was not supported on the detected adapter.
14505 * (2) FW update has been locked out administratively.
14506 * (3) Some other error during FW update.
14507 * In each case, an unmaskable message is written to the console
14508 * for admin diagnosis.
14510 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
14511 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
14512 magic_number != MAGIC_NUMBER_G6) ||
14513 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
14514 magic_number != MAGIC_NUMBER_G7) ||
14515 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
14516 magic_number != MAGIC_NUMBER_G7P)) {
14517 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14518 "3030 This firmware version is not supported on"
14519 " this HBA model. Device:%x Magic:%x Type:%x "
14520 "ID:%x Size %d %zd\n",
14521 phba->pcidev->device, magic_number, ftype, fid,
14524 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
14525 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14526 "3021 Firmware downloads have been prohibited "
14527 "by a system configuration setting on "
14528 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14530 phba->pcidev->device, magic_number, ftype, fid,
14534 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14535 "3022 FW Download failed. Add Status x%x "
14536 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14538 offset, phba->pcidev->device, magic_number,
14539 ftype, fid, fsize, fw->size);
14546 * lpfc_write_firmware - attempt to write a firmware image to the port
14547 * @fw: pointer to firmware image returned from request_firmware.
14548 * @context: pointer to firmware image returned from request_firmware.
14552 lpfc_write_firmware(const struct firmware *fw, void *context)
14554 struct lpfc_hba *phba = (struct lpfc_hba *)context;
14555 char fwrev[FW_REV_STR_SIZE];
14556 struct lpfc_grp_hdr *image;
14557 struct list_head dma_buffer_list;
14559 struct lpfc_dmabuf *dmabuf, *next;
14560 uint32_t offset = 0, temp_offset = 0;
14561 uint32_t magic_number, ftype, fid, fsize;
14563 /* It can be null in no-wait mode, sanity check */
14568 image = (struct lpfc_grp_hdr *)fw->data;
14570 magic_number = be32_to_cpu(image->magic_number);
14571 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
14572 fid = bf_get_be32(lpfc_grp_hdr_id, image);
14573 fsize = be32_to_cpu(image->size);
14575 INIT_LIST_HEAD(&dma_buffer_list);
14576 lpfc_decode_firmware_rev(phba, fwrev, 1);
14577 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
14578 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14579 "3023 Updating Firmware, Current Version:%s "
14580 "New Version:%s\n",
14581 fwrev, image->revision);
14582 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
14583 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
14589 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14593 if (!dmabuf->virt) {
14598 list_add_tail(&dmabuf->list, &dma_buffer_list);
14600 while (offset < fw->size) {
14601 temp_offset = offset;
14602 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
14603 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
14604 memcpy(dmabuf->virt,
14605 fw->data + temp_offset,
14606 fw->size - temp_offset);
14607 temp_offset = fw->size;
14610 memcpy(dmabuf->virt, fw->data + temp_offset,
14612 temp_offset += SLI4_PAGE_SIZE;
14614 rc = lpfc_wr_object(phba, &dma_buffer_list,
14615 (fw->size - offset), &offset);
14617 rc = lpfc_log_write_firmware_error(phba, offset,
14628 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14629 "3029 Skipped Firmware update, Current "
14630 "Version:%s New Version:%s\n",
14631 fwrev, image->revision);
14634 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
14635 list_del(&dmabuf->list);
14636 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
14637 dmabuf->virt, dmabuf->phys);
14640 release_firmware(fw);
14643 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14644 "3062 Firmware update error, status %d.\n", rc);
14646 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14647 "3024 Firmware update success: size %d.\n", rc);
14651 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
14652 * @phba: pointer to lpfc hba data structure.
14653 * @fw_upgrade: which firmware to update.
14655 * This routine is called to perform Linux generic firmware upgrade on device
14656 * that supports such feature.
14659 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
14661 uint8_t file_name[ELX_MODEL_NAME_SIZE];
14663 const struct firmware *fw;
14665 /* Only supported on SLI4 interface type 2 for now */
14666 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
14667 LPFC_SLI_INTF_IF_TYPE_2)
14670 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
14672 if (fw_upgrade == INT_FW_UPGRADE) {
14673 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
14674 file_name, &phba->pcidev->dev,
14675 GFP_KERNEL, (void *)phba,
14676 lpfc_write_firmware);
14677 } else if (fw_upgrade == RUN_FW_UPGRADE) {
14678 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
14680 lpfc_write_firmware(fw, (void *)phba);
14689 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
14690 * @pdev: pointer to PCI device
14691 * @pid: pointer to PCI device identifier
14693 * This routine is called from the kernel's PCI subsystem to device with
14694 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14695 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14696 * information of the device and driver to see if the driver state that it
14697 * can support this kind of device. If the match is successful, the driver
14698 * core invokes this routine. If this routine determines it can claim the HBA,
14699 * it does all the initialization that it needs to do to handle the HBA
14703 * 0 - driver can claim the device
14704 * negative value - driver can not claim the device
14707 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
14709 struct lpfc_hba *phba;
14710 struct lpfc_vport *vport = NULL;
14711 struct Scsi_Host *shost = NULL;
14713 uint32_t cfg_mode, intr_mode;
14715 /* Allocate memory for HBA structure */
14716 phba = lpfc_hba_alloc(pdev);
14720 INIT_LIST_HEAD(&phba->poll_list);
14722 /* Perform generic PCI device enabling operation */
14723 error = lpfc_enable_pci_dev(phba);
14725 goto out_free_phba;
14727 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
14728 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
14730 goto out_disable_pci_dev;
14732 /* Set up SLI-4 specific device PCI memory space */
14733 error = lpfc_sli4_pci_mem_setup(phba);
14735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14736 "1410 Failed to set up pci memory space.\n");
14737 goto out_disable_pci_dev;
14740 /* Set up SLI-4 Specific device driver resources */
14741 error = lpfc_sli4_driver_resource_setup(phba);
14743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14744 "1412 Failed to set up driver resource.\n");
14745 goto out_unset_pci_mem_s4;
14748 INIT_LIST_HEAD(&phba->active_rrq_list);
14749 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
14751 /* Set up common device driver resources */
14752 error = lpfc_setup_driver_resource_phase2(phba);
14754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14755 "1414 Failed to set up driver resource.\n");
14756 goto out_unset_driver_resource_s4;
14759 /* Get the default values for Model Name and Description */
14760 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14762 /* Now, trying to enable interrupt and bring up the device */
14763 cfg_mode = phba->cfg_use_msi;
14765 /* Put device to a known state before enabling interrupt */
14766 phba->pport = NULL;
14767 lpfc_stop_port(phba);
14769 /* Init cpu_map array */
14770 lpfc_cpu_map_array_init(phba);
14772 /* Init hba_eq_hdl array */
14773 lpfc_hba_eq_hdl_array_init(phba);
14775 /* Configure and enable interrupt */
14776 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14777 if (intr_mode == LPFC_INTR_ERROR) {
14778 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14779 "0426 Failed to enable interrupt.\n");
14781 goto out_unset_driver_resource;
14783 /* Default to single EQ for non-MSI-X */
14784 if (phba->intr_type != MSIX) {
14785 phba->cfg_irq_chann = 1;
14786 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14787 if (phba->nvmet_support)
14788 phba->cfg_nvmet_mrq = 1;
14791 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
14793 /* Create SCSI host to the physical port */
14794 error = lpfc_create_shost(phba);
14796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14797 "1415 Failed to create scsi host.\n");
14798 goto out_disable_intr;
14800 vport = phba->pport;
14801 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14803 /* Configure sysfs attributes */
14804 error = lpfc_alloc_sysfs_attr(vport);
14806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14807 "1416 Failed to allocate sysfs attr\n");
14808 goto out_destroy_shost;
14811 /* Set up SLI-4 HBA */
14812 if (lpfc_sli4_hba_setup(phba)) {
14813 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14814 "1421 Failed to set up hba\n");
14816 goto out_free_sysfs_attr;
14819 /* Log the current active interrupt mode */
14820 phba->intr_mode = intr_mode;
14821 lpfc_log_intr_mode(phba, intr_mode);
14823 /* Perform post initialization setup */
14824 lpfc_post_init_setup(phba);
14826 /* NVME support in FW earlier in the driver load corrects the
14827 * FC4 type making a check for nvme_support unnecessary.
14829 if (phba->nvmet_support == 0) {
14830 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14831 /* Create NVME binding with nvme_fc_transport. This
14832 * ensures the vport is initialized. If the localport
14833 * create fails, it should not unload the driver to
14834 * support field issues.
14836 error = lpfc_nvme_create_localport(vport);
14838 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14839 "6004 NVME registration "
14840 "failed, error x%x\n",
14846 /* check for firmware upgrade or downgrade */
14847 if (phba->cfg_request_firmware_upgrade)
14848 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
14850 /* Check if there are static vports to be created. */
14851 lpfc_create_static_vport(phba);
14853 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
14854 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
14858 out_free_sysfs_attr:
14859 lpfc_free_sysfs_attr(vport);
14861 lpfc_destroy_shost(phba);
14863 lpfc_sli4_disable_intr(phba);
14864 out_unset_driver_resource:
14865 lpfc_unset_driver_resource_phase2(phba);
14866 out_unset_driver_resource_s4:
14867 lpfc_sli4_driver_resource_unset(phba);
14868 out_unset_pci_mem_s4:
14869 lpfc_sli4_pci_mem_unset(phba);
14870 out_disable_pci_dev:
14871 lpfc_disable_pci_dev(phba);
14873 scsi_host_put(shost);
14875 lpfc_hba_free(phba);
14880 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
14881 * @pdev: pointer to PCI device
14883 * This routine is called from the kernel's PCI subsystem to device with
14884 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14885 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14886 * device to be removed from the PCI subsystem properly.
14889 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
14891 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14892 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14893 struct lpfc_vport **vports;
14894 struct lpfc_hba *phba = vport->phba;
14897 /* Mark the device unloading flag */
14898 spin_lock_irq(&phba->hbalock);
14899 vport->load_flag |= FC_UNLOADING;
14900 spin_unlock_irq(&phba->hbalock);
14902 lpfc_unreg_congestion_buf(phba);
14904 lpfc_free_sysfs_attr(vport);
14906 /* Release all the vports against this physical port */
14907 vports = lpfc_create_vport_work_array(phba);
14908 if (vports != NULL)
14909 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14910 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14912 fc_vport_terminate(vports[i]->fc_vport);
14914 lpfc_destroy_vport_work_array(phba, vports);
14916 /* Remove FC host with the physical port */
14917 fc_remove_host(shost);
14918 scsi_remove_host(shost);
14920 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
14921 * localports are destroyed after to cleanup all transport memory.
14923 lpfc_cleanup(vport);
14924 lpfc_nvmet_destroy_targetport(phba);
14925 lpfc_nvme_destroy_localport(vport);
14927 /* De-allocate multi-XRI pools */
14928 if (phba->cfg_xri_rebalancing)
14929 lpfc_destroy_multixri_pools(phba);
14932 * Bring down the SLI Layer. This step disables all interrupts,
14933 * clears the rings, discards all mailbox commands, and resets
14934 * the HBA FCoE function.
14936 lpfc_debugfs_terminate(vport);
14938 lpfc_stop_hba_timers(phba);
14939 spin_lock_irq(&phba->port_list_lock);
14940 list_del_init(&vport->listentry);
14941 spin_unlock_irq(&phba->port_list_lock);
14943 /* Perform scsi free before driver resource_unset since scsi
14944 * buffers are released to their corresponding pools here.
14946 lpfc_io_free(phba);
14947 lpfc_free_iocb_list(phba);
14948 lpfc_sli4_hba_unset(phba);
14950 lpfc_unset_driver_resource_phase2(phba);
14951 lpfc_sli4_driver_resource_unset(phba);
14953 /* Unmap adapter Control and Doorbell registers */
14954 lpfc_sli4_pci_mem_unset(phba);
14956 /* Release PCI resources and disable device's PCI function */
14957 scsi_host_put(shost);
14958 lpfc_disable_pci_dev(phba);
14960 /* Finally, free the driver's device data structure */
14961 lpfc_hba_free(phba);
14967 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
14968 * @dev_d: pointer to device
14970 * This routine is called from the kernel's PCI subsystem to support system
14971 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
14972 * this method, it quiesces the device by stopping the driver's worker
14973 * thread for the device, turning off device's interrupt and DMA, and bring
14974 * the device offline. Note that as the driver implements the minimum PM
14975 * requirements to a power-aware driver's PM support for suspend/resume -- all
14976 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
14977 * method call will be treated as SUSPEND and the driver will fully
14978 * reinitialize its device during resume() method call, the driver will set
14979 * device to PCI_D3hot state in PCI config space instead of setting it
14980 * according to the @msg provided by the PM.
14983 * 0 - driver suspended the device
14986 static int __maybe_unused
14987 lpfc_pci_suspend_one_s4(struct device *dev_d)
14989 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14990 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14993 "2843 PCI device Power Management suspend.\n");
14995 /* Bring down the device */
14996 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14997 lpfc_offline(phba);
14998 kthread_stop(phba->worker_thread);
15000 /* Disable interrupt from device */
15001 lpfc_sli4_disable_intr(phba);
15002 lpfc_sli4_queue_destroy(phba);
15008 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
15009 * @dev_d: pointer to device
15011 * This routine is called from the kernel's PCI subsystem to support system
15012 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
15013 * this method, it restores the device's PCI config space state and fully
15014 * reinitializes the device and brings it online. Note that as the driver
15015 * implements the minimum PM requirements to a power-aware driver's PM for
15016 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
15017 * to the suspend() method call will be treated as SUSPEND and the driver
15018 * will fully reinitialize its device during resume() method call, the device
15019 * will be set to PCI_D0 directly in PCI config space before restoring the
15023 * 0 - driver suspended the device
15026 static int __maybe_unused
15027 lpfc_pci_resume_one_s4(struct device *dev_d)
15029 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
15030 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15031 uint32_t intr_mode;
15034 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15035 "0292 PCI device Power Management resume.\n");
15037 /* Startup the kernel thread for this host adapter. */
15038 phba->worker_thread = kthread_run(lpfc_do_work, phba,
15039 "lpfc_worker_%d", phba->brd_no);
15040 if (IS_ERR(phba->worker_thread)) {
15041 error = PTR_ERR(phba->worker_thread);
15042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15043 "0293 PM resume failed to start worker "
15044 "thread: error=x%x.\n", error);
15048 /* Configure and enable interrupt */
15049 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15050 if (intr_mode == LPFC_INTR_ERROR) {
15051 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15052 "0294 PM resume Failed to enable interrupt\n");
15055 phba->intr_mode = intr_mode;
15057 /* Restart HBA and bring it online */
15058 lpfc_sli_brdrestart(phba);
15061 /* Log the current active interrupt mode */
15062 lpfc_log_intr_mode(phba, phba->intr_mode);
15068 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
15069 * @phba: pointer to lpfc hba data structure.
15071 * This routine is called to prepare the SLI4 device for PCI slot recover. It
15072 * aborts all the outstanding SCSI I/Os to the pci device.
15075 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
15077 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15078 "2828 PCI channel I/O abort preparing for recovery\n");
15080 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
15081 * and let the SCSI mid-layer to retry them to recover.
15083 lpfc_sli_abort_fcp_rings(phba);
15087 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
15088 * @phba: pointer to lpfc hba data structure.
15090 * This routine is called to prepare the SLI4 device for PCI slot reset. It
15091 * disables the device interrupt and pci device, and aborts the internal FCP
15095 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
15097 int offline = pci_channel_offline(phba->pcidev);
15099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15100 "2826 PCI channel disable preparing for reset offline"
15103 /* Block any management I/Os to the device */
15104 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
15107 /* HBA_PCI_ERR was set in io_error_detect */
15108 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
15109 /* Flush all driver's outstanding I/Os as we are to reset */
15110 lpfc_sli_flush_io_rings(phba);
15111 lpfc_offline(phba);
15113 /* stop all timers */
15114 lpfc_stop_hba_timers(phba);
15116 lpfc_sli4_queue_destroy(phba);
15117 /* Disable interrupt and pci device */
15118 lpfc_sli4_disable_intr(phba);
15119 pci_disable_device(phba->pcidev);
15123 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
15124 * @phba: pointer to lpfc hba data structure.
15126 * This routine is called to prepare the SLI4 device for PCI slot permanently
15127 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
15131 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
15133 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15134 "2827 PCI channel permanent disable for failure\n");
15136 /* Block all SCSI devices' I/Os on the host */
15137 lpfc_scsi_dev_block(phba);
15139 /* stop all timers */
15140 lpfc_stop_hba_timers(phba);
15142 /* Clean up all driver's outstanding I/Os */
15143 lpfc_sli_flush_io_rings(phba);
15147 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
15148 * @pdev: pointer to PCI device.
15149 * @state: the current PCI connection state.
15151 * This routine is called from the PCI subsystem for error handling to device
15152 * with SLI-4 interface spec. This function is called by the PCI subsystem
15153 * after a PCI bus error affecting this device has been detected. When this
15154 * function is invoked, it will need to stop all the I/Os and interrupt(s)
15155 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
15156 * for the PCI subsystem to perform proper recovery as desired.
15159 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15160 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15162 static pci_ers_result_t
15163 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
15165 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15166 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15170 case pci_channel_io_normal:
15171 /* Non-fatal error, prepare for recovery */
15172 lpfc_sli4_prep_dev_for_recover(phba);
15173 return PCI_ERS_RESULT_CAN_RECOVER;
15174 case pci_channel_io_frozen:
15175 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15176 /* Fatal error, prepare for slot reset */
15178 lpfc_sli4_prep_dev_for_reset(phba);
15180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15181 "2832 Already handling PCI error "
15182 "state: x%x\n", state);
15183 return PCI_ERS_RESULT_NEED_RESET;
15184 case pci_channel_io_perm_failure:
15185 set_bit(HBA_PCI_ERR, &phba->bit_flags);
15186 /* Permanent failure, prepare for device down */
15187 lpfc_sli4_prep_dev_for_perm_failure(phba);
15188 return PCI_ERS_RESULT_DISCONNECT;
15190 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15192 lpfc_sli4_prep_dev_for_reset(phba);
15193 /* Unknown state, prepare and request slot reset */
15194 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15195 "2825 Unknown PCI error state: x%x\n", state);
15196 lpfc_sli4_prep_dev_for_reset(phba);
15197 return PCI_ERS_RESULT_NEED_RESET;
15202 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
15203 * @pdev: pointer to PCI device.
15205 * This routine is called from the PCI subsystem for error handling to device
15206 * with SLI-4 interface spec. It is called after PCI bus has been reset to
15207 * restart the PCI card from scratch, as if from a cold-boot. During the
15208 * PCI subsystem error recovery, after the driver returns
15209 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
15210 * recovery and then call this routine before calling the .resume method to
15211 * recover the device. This function will initialize the HBA device, enable
15212 * the interrupt, but it will just put the HBA to offline state without
15213 * passing any I/O traffic.
15216 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15217 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15219 static pci_ers_result_t
15220 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
15222 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15223 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15224 struct lpfc_sli *psli = &phba->sli;
15225 uint32_t intr_mode;
15228 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
15229 if (pci_enable_device_mem(pdev)) {
15230 printk(KERN_ERR "lpfc: Cannot re-enable "
15231 "PCI device after reset.\n");
15232 return PCI_ERS_RESULT_DISCONNECT;
15235 pci_restore_state(pdev);
15237 hba_pci_err = test_and_clear_bit(HBA_PCI_ERR, &phba->bit_flags);
15239 dev_info(&pdev->dev,
15240 "hba_pci_err was not set, recovering slot reset.\n");
15242 * As the new kernel behavior of pci_restore_state() API call clears
15243 * device saved_state flag, need to save the restored state again.
15245 pci_save_state(pdev);
15247 if (pdev->is_busmaster)
15248 pci_set_master(pdev);
15250 spin_lock_irq(&phba->hbalock);
15251 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
15252 spin_unlock_irq(&phba->hbalock);
15254 /* Init cpu_map array */
15255 lpfc_cpu_map_array_init(phba);
15256 /* Configure and enable interrupt */
15257 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15258 if (intr_mode == LPFC_INTR_ERROR) {
15259 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15260 "2824 Cannot re-enable interrupt after "
15262 return PCI_ERS_RESULT_DISCONNECT;
15264 phba->intr_mode = intr_mode;
15265 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
15267 /* Log the current active interrupt mode */
15268 lpfc_log_intr_mode(phba, phba->intr_mode);
15270 return PCI_ERS_RESULT_RECOVERED;
15274 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
15275 * @pdev: pointer to PCI device
15277 * This routine is called from the PCI subsystem for error handling to device
15278 * with SLI-4 interface spec. It is called when kernel error recovery tells
15279 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
15280 * error recovery. After this call, traffic can start to flow from this device
15284 lpfc_io_resume_s4(struct pci_dev *pdev)
15286 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15287 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15290 * In case of slot reset, as function reset is performed through
15291 * mailbox command which needs DMA to be enabled, this operation
15292 * has to be moved to the io resume phase. Taking device offline
15293 * will perform the necessary cleanup.
15295 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
15296 /* Perform device reset */
15297 lpfc_sli_brdrestart(phba);
15298 /* Bring the device back online */
15304 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
15305 * @pdev: pointer to PCI device
15306 * @pid: pointer to PCI device identifier
15308 * This routine is to be registered to the kernel's PCI subsystem. When an
15309 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
15310 * at PCI device-specific information of the device and driver to see if the
15311 * driver state that it can support this kind of device. If the match is
15312 * successful, the driver core invokes this routine. This routine dispatches
15313 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
15314 * do all the initialization that it needs to do to handle the HBA device
15318 * 0 - driver can claim the device
15319 * negative value - driver can not claim the device
15322 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
15325 struct lpfc_sli_intf intf;
15327 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
15330 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
15331 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
15332 rc = lpfc_pci_probe_one_s4(pdev, pid);
15334 rc = lpfc_pci_probe_one_s3(pdev, pid);
15340 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
15341 * @pdev: pointer to PCI device
15343 * This routine is to be registered to the kernel's PCI subsystem. When an
15344 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
15345 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
15346 * remove routine, which will perform all the necessary cleanup for the
15347 * device to be removed from the PCI subsystem properly.
15350 lpfc_pci_remove_one(struct pci_dev *pdev)
15352 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15353 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15355 switch (phba->pci_dev_grp) {
15356 case LPFC_PCI_DEV_LP:
15357 lpfc_pci_remove_one_s3(pdev);
15359 case LPFC_PCI_DEV_OC:
15360 lpfc_pci_remove_one_s4(pdev);
15363 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15364 "1424 Invalid PCI device group: 0x%x\n",
15365 phba->pci_dev_grp);
15372 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
15373 * @dev: pointer to device
15375 * This routine is to be registered to the kernel's PCI subsystem to support
15376 * system Power Management (PM). When PM invokes this method, it dispatches
15377 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
15378 * suspend the device.
15381 * 0 - driver suspended the device
15384 static int __maybe_unused
15385 lpfc_pci_suspend_one(struct device *dev)
15387 struct Scsi_Host *shost = dev_get_drvdata(dev);
15388 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15391 switch (phba->pci_dev_grp) {
15392 case LPFC_PCI_DEV_LP:
15393 rc = lpfc_pci_suspend_one_s3(dev);
15395 case LPFC_PCI_DEV_OC:
15396 rc = lpfc_pci_suspend_one_s4(dev);
15399 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15400 "1425 Invalid PCI device group: 0x%x\n",
15401 phba->pci_dev_grp);
15408 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
15409 * @dev: pointer to device
15411 * This routine is to be registered to the kernel's PCI subsystem to support
15412 * system Power Management (PM). When PM invokes this method, it dispatches
15413 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
15414 * resume the device.
15417 * 0 - driver suspended the device
15420 static int __maybe_unused
15421 lpfc_pci_resume_one(struct device *dev)
15423 struct Scsi_Host *shost = dev_get_drvdata(dev);
15424 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15427 switch (phba->pci_dev_grp) {
15428 case LPFC_PCI_DEV_LP:
15429 rc = lpfc_pci_resume_one_s3(dev);
15431 case LPFC_PCI_DEV_OC:
15432 rc = lpfc_pci_resume_one_s4(dev);
15435 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15436 "1426 Invalid PCI device group: 0x%x\n",
15437 phba->pci_dev_grp);
15444 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
15445 * @pdev: pointer to PCI device.
15446 * @state: the current PCI connection state.
15448 * This routine is registered to the PCI subsystem for error handling. This
15449 * function is called by the PCI subsystem after a PCI bus error affecting
15450 * this device has been detected. When this routine is invoked, it dispatches
15451 * the action to the proper SLI-3 or SLI-4 device error detected handling
15452 * routine, which will perform the proper error detected operation.
15455 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15456 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15458 static pci_ers_result_t
15459 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
15461 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15462 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15463 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15465 if (phba->link_state == LPFC_HBA_ERROR &&
15466 phba->hba_flag & HBA_IOQ_FLUSH)
15467 return PCI_ERS_RESULT_NEED_RESET;
15469 switch (phba->pci_dev_grp) {
15470 case LPFC_PCI_DEV_LP:
15471 rc = lpfc_io_error_detected_s3(pdev, state);
15473 case LPFC_PCI_DEV_OC:
15474 rc = lpfc_io_error_detected_s4(pdev, state);
15477 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15478 "1427 Invalid PCI device group: 0x%x\n",
15479 phba->pci_dev_grp);
15486 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
15487 * @pdev: pointer to PCI device.
15489 * This routine is registered to the PCI subsystem for error handling. This
15490 * function is called after PCI bus has been reset to restart the PCI card
15491 * from scratch, as if from a cold-boot. When this routine is invoked, it
15492 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
15493 * routine, which will perform the proper device reset.
15496 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15497 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15499 static pci_ers_result_t
15500 lpfc_io_slot_reset(struct pci_dev *pdev)
15502 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15503 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15504 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15506 switch (phba->pci_dev_grp) {
15507 case LPFC_PCI_DEV_LP:
15508 rc = lpfc_io_slot_reset_s3(pdev);
15510 case LPFC_PCI_DEV_OC:
15511 rc = lpfc_io_slot_reset_s4(pdev);
15514 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15515 "1428 Invalid PCI device group: 0x%x\n",
15516 phba->pci_dev_grp);
15523 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
15524 * @pdev: pointer to PCI device
15526 * This routine is registered to the PCI subsystem for error handling. It
15527 * is called when kernel error recovery tells the lpfc driver that it is
15528 * OK to resume normal PCI operation after PCI bus error recovery. When
15529 * this routine is invoked, it dispatches the action to the proper SLI-3
15530 * or SLI-4 device io_resume routine, which will resume the device operation.
15533 lpfc_io_resume(struct pci_dev *pdev)
15535 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15536 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15538 switch (phba->pci_dev_grp) {
15539 case LPFC_PCI_DEV_LP:
15540 lpfc_io_resume_s3(pdev);
15542 case LPFC_PCI_DEV_OC:
15543 lpfc_io_resume_s4(pdev);
15546 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15547 "1429 Invalid PCI device group: 0x%x\n",
15548 phba->pci_dev_grp);
15555 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
15556 * @phba: pointer to lpfc hba data structure.
15558 * This routine checks to see if OAS is supported for this adapter. If
15559 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
15560 * the enable oas flag is cleared and the pool created for OAS device data
15565 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
15568 if (!phba->cfg_EnableXLane)
15571 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
15575 mempool_destroy(phba->device_data_mem_pool);
15576 phba->device_data_mem_pool = NULL;
15583 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
15584 * @phba: pointer to lpfc hba data structure.
15586 * This routine checks to see if RAS is supported by the adapter. Check the
15587 * function through which RAS support enablement is to be done.
15590 lpfc_sli4_ras_init(struct lpfc_hba *phba)
15592 /* if ASIC_GEN_NUM >= 0xC) */
15593 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
15594 LPFC_SLI_INTF_IF_TYPE_6) ||
15595 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
15596 LPFC_SLI_INTF_FAMILY_G6)) {
15597 phba->ras_fwlog.ras_hwsupport = true;
15598 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
15599 phba->cfg_ras_fwlog_buffsize)
15600 phba->ras_fwlog.ras_enabled = true;
15602 phba->ras_fwlog.ras_enabled = false;
15604 phba->ras_fwlog.ras_hwsupport = false;
15609 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
15611 static const struct pci_error_handlers lpfc_err_handler = {
15612 .error_detected = lpfc_io_error_detected,
15613 .slot_reset = lpfc_io_slot_reset,
15614 .resume = lpfc_io_resume,
15617 static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
15618 lpfc_pci_suspend_one,
15619 lpfc_pci_resume_one);
15621 static struct pci_driver lpfc_driver = {
15622 .name = LPFC_DRIVER_NAME,
15623 .id_table = lpfc_id_table,
15624 .probe = lpfc_pci_probe_one,
15625 .remove = lpfc_pci_remove_one,
15626 .shutdown = lpfc_pci_remove_one,
15627 .driver.pm = &lpfc_pci_pm_ops_one,
15628 .err_handler = &lpfc_err_handler,
15631 static const struct file_operations lpfc_mgmt_fop = {
15632 .owner = THIS_MODULE,
15635 static struct miscdevice lpfc_mgmt_dev = {
15636 .minor = MISC_DYNAMIC_MINOR,
15637 .name = "lpfcmgmt",
15638 .fops = &lpfc_mgmt_fop,
15642 * lpfc_init - lpfc module initialization routine
15644 * This routine is to be invoked when the lpfc module is loaded into the
15645 * kernel. The special kernel macro module_init() is used to indicate the
15646 * role of this routine to the kernel as lpfc module entry point.
15650 * -ENOMEM - FC attach transport failed
15651 * all others - failed
15658 pr_info(LPFC_MODULE_DESC "\n");
15659 pr_info(LPFC_COPYRIGHT "\n");
15661 error = misc_register(&lpfc_mgmt_dev);
15663 printk(KERN_ERR "Could not register lpfcmgmt device, "
15664 "misc_register returned with status %d", error);
15667 lpfc_transport_functions.vport_create = lpfc_vport_create;
15668 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
15669 lpfc_transport_template =
15670 fc_attach_transport(&lpfc_transport_functions);
15671 if (lpfc_transport_template == NULL)
15673 lpfc_vport_transport_template =
15674 fc_attach_transport(&lpfc_vport_transport_functions);
15675 if (lpfc_vport_transport_template == NULL) {
15676 fc_release_transport(lpfc_transport_template);
15679 lpfc_wqe_cmd_template();
15680 lpfc_nvmet_cmd_template();
15682 /* Initialize in case vector mapping is needed */
15683 lpfc_present_cpu = num_present_cpus();
15685 lpfc_pldv_detect = false;
15687 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
15688 "lpfc/sli4:online",
15689 lpfc_cpu_online, lpfc_cpu_offline);
15691 goto cpuhp_failure;
15692 lpfc_cpuhp_state = error;
15694 error = pci_register_driver(&lpfc_driver);
15701 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15703 fc_release_transport(lpfc_transport_template);
15704 fc_release_transport(lpfc_vport_transport_template);
15706 misc_deregister(&lpfc_mgmt_dev);
15711 void lpfc_dmp_dbg(struct lpfc_hba *phba)
15713 unsigned int start_idx;
15714 unsigned int dbg_cnt;
15715 unsigned int temp_idx;
15718 unsigned long rem_nsec;
15720 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
15723 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
15724 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
15727 temp_idx = start_idx;
15728 if (dbg_cnt >= DBG_LOG_SZ) {
15729 dbg_cnt = DBG_LOG_SZ;
15732 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
15733 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
15735 if (start_idx < dbg_cnt)
15736 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
15738 start_idx -= dbg_cnt;
15741 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
15742 start_idx, temp_idx, dbg_cnt);
15744 for (i = 0; i < dbg_cnt; i++) {
15745 if ((start_idx + i) < DBG_LOG_SZ)
15746 temp_idx = (start_idx + i) % DBG_LOG_SZ;
15749 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
15750 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15752 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15754 phba->dbg_log[temp_idx].log);
15757 atomic_set(&phba->dbg_log_cnt, 0);
15758 atomic_set(&phba->dbg_log_dmping, 0);
15762 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15766 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15767 struct va_format vaf;
15770 va_start(args, fmt);
15771 if (unlikely(dbg_dmping)) {
15774 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15778 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15781 atomic_inc(&phba->dbg_log_cnt);
15783 vscnprintf(phba->dbg_log[idx].log,
15784 sizeof(phba->dbg_log[idx].log), fmt, args);
15787 phba->dbg_log[idx].t_ns = local_clock();
15791 * lpfc_exit - lpfc module removal routine
15793 * This routine is invoked when the lpfc module is removed from the kernel.
15794 * The special kernel macro module_exit() is used to indicate the role of
15795 * this routine to the kernel as lpfc module exit point.
15800 misc_deregister(&lpfc_mgmt_dev);
15801 pci_unregister_driver(&lpfc_driver);
15802 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15803 fc_release_transport(lpfc_transport_template);
15804 fc_release_transport(lpfc_vport_transport_template);
15805 idr_destroy(&lpfc_hba_index);
15808 module_init(lpfc_init);
15809 module_exit(lpfc_exit);
15810 MODULE_LICENSE("GPL");
15811 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
15812 MODULE_AUTHOR("Broadcom");
15813 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);