1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 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/irq.h>
40 #include <linux/bitops.h>
41 #include <linux/crash_dump.h>
42 #include <linux/cpu.h>
43 #include <linux/cpuhotplug.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_device.h>
47 #include <scsi/scsi_host.h>
48 #include <scsi/scsi_transport_fc.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/fc/fc_fs.h>
55 #include "lpfc_sli4.h"
57 #include "lpfc_disc.h"
59 #include "lpfc_scsi.h"
60 #include "lpfc_nvme.h"
61 #include "lpfc_logmsg.h"
62 #include "lpfc_crtn.h"
63 #include "lpfc_vport.h"
64 #include "lpfc_version.h"
67 static enum cpuhp_state lpfc_cpuhp_state;
68 /* Used when mapping IRQ vectors in a driver centric manner */
69 static uint32_t lpfc_present_cpu;
70 static bool lpfc_pldv_detect;
72 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
73 static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
74 static void lpfc_cpuhp_add(struct lpfc_hba *phba);
75 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
76 static int lpfc_post_rcv_buf(struct lpfc_hba *);
77 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
78 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
79 static int lpfc_setup_endian_order(struct lpfc_hba *);
80 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
81 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
82 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
83 static void lpfc_init_sgl_list(struct lpfc_hba *);
84 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
85 static void lpfc_free_active_sgl(struct lpfc_hba *);
86 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
87 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
88 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
89 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
90 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
91 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
92 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
93 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
94 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
95 static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
96 static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
97 static void lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba);
99 static struct scsi_transport_template *lpfc_transport_template = NULL;
100 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
101 static DEFINE_IDR(lpfc_hba_index);
102 #define LPFC_NVMET_BUF_POST 254
103 static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
106 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
107 * @phba: pointer to lpfc hba data structure.
109 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
110 * mailbox command. It retrieves the revision information from the HBA and
111 * collects the Vital Product Data (VPD) about the HBA for preparing the
112 * configuration of the HBA.
116 * -ERESTART - requests the SLI layer to reset the HBA and try again.
117 * Any other value - indicates an error.
120 lpfc_config_port_prep(struct lpfc_hba *phba)
122 lpfc_vpd_t *vp = &phba->vpd;
126 char *lpfc_vpd_data = NULL;
128 static char licensed[56] =
129 "key unlock for use with gnu public licensed code only\0";
130 static int init_key = 1;
132 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
134 phba->link_state = LPFC_HBA_ERROR;
139 phba->link_state = LPFC_INIT_MBX_CMDS;
141 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
143 uint32_t *ptext = (uint32_t *) licensed;
145 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
146 *ptext = cpu_to_be32(*ptext);
150 lpfc_read_nv(phba, pmb);
151 memset((char*)mb->un.varRDnvp.rsvd3, 0,
152 sizeof (mb->un.varRDnvp.rsvd3));
153 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
156 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
158 if (rc != MBX_SUCCESS) {
159 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
160 "0324 Config Port initialization "
161 "error, mbxCmd x%x READ_NVPARM, "
163 mb->mbxCommand, mb->mbxStatus);
164 mempool_free(pmb, phba->mbox_mem_pool);
167 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
169 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
174 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
175 * which was already set in lpfc_get_cfgparam()
177 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
179 /* Setup and issue mailbox READ REV command */
180 lpfc_read_rev(phba, pmb);
181 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
182 if (rc != MBX_SUCCESS) {
183 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
184 "0439 Adapter failed to init, mbxCmd x%x "
185 "READ_REV, mbxStatus x%x\n",
186 mb->mbxCommand, mb->mbxStatus);
187 mempool_free( pmb, phba->mbox_mem_pool);
193 * The value of rr must be 1 since the driver set the cv field to 1.
194 * This setting requires the FW to set all revision fields.
196 if (mb->un.varRdRev.rr == 0) {
198 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
199 "0440 Adapter failed to init, READ_REV has "
200 "missing revision information.\n");
201 mempool_free(pmb, phba->mbox_mem_pool);
205 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
206 mempool_free(pmb, phba->mbox_mem_pool);
210 /* Save information as VPD data */
212 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
213 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
214 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
215 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
216 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
217 vp->rev.biuRev = mb->un.varRdRev.biuRev;
218 vp->rev.smRev = mb->un.varRdRev.smRev;
219 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
220 vp->rev.endecRev = mb->un.varRdRev.endecRev;
221 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
222 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
223 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
224 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
225 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
226 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
228 /* If the sli feature level is less then 9, we must
229 * tear down all RPIs and VPIs on link down if NPIV
232 if (vp->rev.feaLevelHigh < 9)
233 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
235 if (lpfc_is_LC_HBA(phba->pcidev->device))
236 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
237 sizeof (phba->RandomData));
239 /* Get adapter VPD information */
240 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
244 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
245 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
247 if (rc != MBX_SUCCESS) {
248 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
249 "0441 VPD not present on adapter, "
250 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
251 mb->mbxCommand, mb->mbxStatus);
252 mb->un.varDmp.word_cnt = 0;
254 /* dump mem may return a zero when finished or we got a
255 * mailbox error, either way we are done.
257 if (mb->un.varDmp.word_cnt == 0)
260 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
261 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
262 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
263 lpfc_vpd_data + offset,
264 mb->un.varDmp.word_cnt);
265 offset += mb->un.varDmp.word_cnt;
266 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
268 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
270 kfree(lpfc_vpd_data);
272 mempool_free(pmb, phba->mbox_mem_pool);
277 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
278 * @phba: pointer to lpfc hba data structure.
279 * @pmboxq: pointer to the driver internal queue element for mailbox command.
281 * This is the completion handler for driver's configuring asynchronous event
282 * mailbox command to the device. If the mailbox command returns successfully,
283 * it will set internal async event support flag to 1; otherwise, it will
284 * set internal async event support flag to 0.
287 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
289 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
290 phba->temp_sensor_support = 1;
292 phba->temp_sensor_support = 0;
293 mempool_free(pmboxq, phba->mbox_mem_pool);
298 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
299 * @phba: pointer to lpfc hba data structure.
300 * @pmboxq: pointer to the driver internal queue element for mailbox command.
302 * This is the completion handler for dump mailbox command for getting
303 * wake up parameters. When this command complete, the response contain
304 * Option rom version of the HBA. This function translate the version number
305 * into a human readable string and store it in OptionROMVersion.
308 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
311 uint32_t prog_id_word;
313 /* character array used for decoding dist type. */
314 char dist_char[] = "nabx";
316 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
317 mempool_free(pmboxq, phba->mbox_mem_pool);
321 prg = (struct prog_id *) &prog_id_word;
323 /* word 7 contain option rom version */
324 prog_id_word = pmboxq->u.mb.un.varWords[7];
326 /* Decode the Option rom version word to a readable string */
327 dist = dist_char[prg->dist];
329 if ((prg->dist == 3) && (prg->num == 0))
330 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
331 prg->ver, prg->rev, prg->lev);
333 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
334 prg->ver, prg->rev, prg->lev,
336 mempool_free(pmboxq, phba->mbox_mem_pool);
341 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
342 * @vport: pointer to lpfc vport data structure.
349 lpfc_update_vport_wwn(struct lpfc_vport *vport)
351 struct lpfc_hba *phba = vport->phba;
354 * If the name is empty or there exists a soft name
355 * then copy the service params name, otherwise use the fc name
357 if (vport->fc_nodename.u.wwn[0] == 0)
358 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
359 sizeof(struct lpfc_name));
361 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
362 sizeof(struct lpfc_name));
365 * If the port name has changed, then set the Param changes flag
368 if (vport->fc_portname.u.wwn[0] != 0 &&
369 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
370 sizeof(struct lpfc_name))) {
371 vport->vport_flag |= FAWWPN_PARAM_CHG;
373 if (phba->sli_rev == LPFC_SLI_REV4 &&
374 vport->port_type == LPFC_PHYSICAL_PORT &&
375 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_FABRIC) {
376 if (!(phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG))
377 phba->sli4_hba.fawwpn_flag &=
379 lpfc_printf_log(phba, KERN_INFO,
380 LOG_SLI | LOG_DISCOVERY | LOG_ELS,
381 "2701 FA-PWWN change WWPN from %llx to "
382 "%llx: vflag x%x fawwpn_flag x%x\n",
383 wwn_to_u64(vport->fc_portname.u.wwn),
385 (vport->fc_sparam.portName.u.wwn),
387 phba->sli4_hba.fawwpn_flag);
388 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
389 sizeof(struct lpfc_name));
393 if (vport->fc_portname.u.wwn[0] == 0)
394 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
395 sizeof(struct lpfc_name));
397 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
398 sizeof(struct lpfc_name));
402 * lpfc_config_port_post - Perform lpfc initialization after config port
403 * @phba: pointer to lpfc hba data structure.
405 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
406 * command call. It performs all internal resource and state setups on the
407 * port: post IOCB buffers, enable appropriate host interrupt attentions,
408 * ELS ring timers, etc.
412 * Any other value - error.
415 lpfc_config_port_post(struct lpfc_hba *phba)
417 struct lpfc_vport *vport = phba->pport;
418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
421 struct lpfc_dmabuf *mp;
422 struct lpfc_sli *psli = &phba->sli;
423 uint32_t status, timeout;
427 spin_lock_irq(&phba->hbalock);
429 * If the Config port completed correctly the HBA is not
430 * over heated any more.
432 if (phba->over_temp_state == HBA_OVER_TEMP)
433 phba->over_temp_state = HBA_NORMAL_TEMP;
434 spin_unlock_irq(&phba->hbalock);
436 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
438 phba->link_state = LPFC_HBA_ERROR;
443 /* Get login parameters for NID. */
444 rc = lpfc_read_sparam(phba, pmb, 0);
446 mempool_free(pmb, phba->mbox_mem_pool);
451 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
452 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
453 "0448 Adapter failed init, mbxCmd x%x "
454 "READ_SPARM mbxStatus x%x\n",
455 mb->mbxCommand, mb->mbxStatus);
456 phba->link_state = LPFC_HBA_ERROR;
457 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
461 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
463 /* This dmabuf was allocated by lpfc_read_sparam. The dmabuf is no
464 * longer needed. Prevent unintended ctx_buf access as the mbox is
467 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
468 lpfc_mbuf_free(phba, mp->virt, mp->phys);
471 lpfc_update_vport_wwn(vport);
473 /* Update the fc_host data structures with new wwn. */
474 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
475 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
476 fc_host_max_npiv_vports(shost) = phba->max_vpi;
478 /* If no serial number in VPD data, use low 6 bytes of WWNN */
479 /* This should be consolidated into parse_vpd ? - mr */
480 if (phba->SerialNumber[0] == 0) {
483 outptr = &vport->fc_nodename.u.s.IEEE[0];
484 for (i = 0; i < 12; i++) {
486 j = ((status & 0xf0) >> 4);
488 phba->SerialNumber[i] =
489 (char)((uint8_t) 0x30 + (uint8_t) j);
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
496 phba->SerialNumber[i] =
497 (char)((uint8_t) 0x30 + (uint8_t) j);
499 phba->SerialNumber[i] =
500 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
504 lpfc_read_config(phba, pmb);
506 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
507 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
508 "0453 Adapter failed to init, mbxCmd x%x "
509 "READ_CONFIG, mbxStatus x%x\n",
510 mb->mbxCommand, mb->mbxStatus);
511 phba->link_state = LPFC_HBA_ERROR;
512 mempool_free( pmb, phba->mbox_mem_pool);
516 /* Check if the port is disabled */
517 lpfc_sli_read_link_ste(phba);
519 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
520 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
521 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
522 "3359 HBA queue depth changed from %d to %d\n",
523 phba->cfg_hba_queue_depth,
524 mb->un.varRdConfig.max_xri);
525 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
528 phba->lmt = mb->un.varRdConfig.lmt;
530 /* Get the default values for Model Name and Description */
531 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
533 phba->link_state = LPFC_LINK_DOWN;
535 /* Only process IOCBs on ELS ring till hba_state is READY */
536 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
537 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
538 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
539 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
541 /* Post receive buffers for desired rings */
542 if (phba->sli_rev != 3)
543 lpfc_post_rcv_buf(phba);
546 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
548 if (phba->intr_type == MSIX) {
549 rc = lpfc_config_msi(phba, pmb);
551 mempool_free(pmb, phba->mbox_mem_pool);
554 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
555 if (rc != MBX_SUCCESS) {
556 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
557 "0352 Config MSI mailbox command "
558 "failed, mbxCmd x%x, mbxStatus x%x\n",
559 pmb->u.mb.mbxCommand,
560 pmb->u.mb.mbxStatus);
561 mempool_free(pmb, phba->mbox_mem_pool);
566 spin_lock_irq(&phba->hbalock);
567 /* Initialize ERATT handling flag */
568 phba->hba_flag &= ~HBA_ERATT_HANDLED;
570 /* Enable appropriate host interrupts */
571 if (lpfc_readl(phba->HCregaddr, &status)) {
572 spin_unlock_irq(&phba->hbalock);
575 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
576 if (psli->num_rings > 0)
577 status |= HC_R0INT_ENA;
578 if (psli->num_rings > 1)
579 status |= HC_R1INT_ENA;
580 if (psli->num_rings > 2)
581 status |= HC_R2INT_ENA;
582 if (psli->num_rings > 3)
583 status |= HC_R3INT_ENA;
585 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
586 (phba->cfg_poll & DISABLE_FCP_RING_INT))
587 status &= ~(HC_R0INT_ENA);
589 writel(status, phba->HCregaddr);
590 readl(phba->HCregaddr); /* flush */
591 spin_unlock_irq(&phba->hbalock);
593 /* Set up ring-0 (ELS) timer */
594 timeout = phba->fc_ratov * 2;
595 mod_timer(&vport->els_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * timeout));
597 /* Set up heart beat (HB) timer */
598 mod_timer(&phba->hb_tmofunc,
599 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
600 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
601 phba->last_completion_time = jiffies;
602 /* Set up error attention (ERATT) polling timer */
603 mod_timer(&phba->eratt_poll,
604 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
606 if (phba->hba_flag & LINK_DISABLED) {
607 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
608 "2598 Adapter Link is disabled.\n");
609 lpfc_down_link(phba, pmb);
610 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
611 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
612 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
613 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
614 "2599 Adapter failed to issue DOWN_LINK"
615 " mbox command rc 0x%x\n", rc);
617 mempool_free(pmb, phba->mbox_mem_pool);
620 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
621 mempool_free(pmb, phba->mbox_mem_pool);
622 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
626 /* MBOX buffer will be freed in mbox compl */
627 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
629 phba->link_state = LPFC_HBA_ERROR;
633 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
634 pmb->mbox_cmpl = lpfc_config_async_cmpl;
635 pmb->vport = phba->pport;
636 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
638 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
639 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
640 "0456 Adapter failed to issue "
641 "ASYNCEVT_ENABLE mbox status x%x\n",
643 mempool_free(pmb, phba->mbox_mem_pool);
646 /* Get Option rom version */
647 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
649 phba->link_state = LPFC_HBA_ERROR;
653 lpfc_dump_wakeup_param(phba, pmb);
654 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
655 pmb->vport = phba->pport;
656 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
658 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
659 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
660 "0435 Adapter failed "
661 "to get Option ROM version status x%x\n", rc);
662 mempool_free(pmb, phba->mbox_mem_pool);
669 * lpfc_sli4_refresh_params - update driver copy of params.
670 * @phba: Pointer to HBA context object.
672 * This is called to refresh driver copy of dynamic fields from the
673 * common_get_sli4_parameters descriptor.
676 lpfc_sli4_refresh_params(struct lpfc_hba *phba)
679 struct lpfc_mqe *mqe;
680 struct lpfc_sli4_parameters *mbx_sli4_parameters;
683 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
688 /* Read the port's SLI4 Config Parameters */
689 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
690 sizeof(struct lpfc_sli4_cfg_mhdr));
691 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
692 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
693 length, LPFC_SLI4_MBX_EMBED);
695 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
697 mempool_free(mboxq, phba->mbox_mem_pool);
700 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
701 phba->sli4_hba.pc_sli4_params.mi_cap =
702 bf_get(cfg_mi_ver, mbx_sli4_parameters);
704 /* Are we forcing MI off via module parameter? */
705 if (phba->cfg_enable_mi)
706 phba->sli4_hba.pc_sli4_params.mi_ver =
707 bf_get(cfg_mi_ver, mbx_sli4_parameters);
709 phba->sli4_hba.pc_sli4_params.mi_ver = 0;
711 phba->sli4_hba.pc_sli4_params.cmf =
712 bf_get(cfg_cmf, mbx_sli4_parameters);
713 phba->sli4_hba.pc_sli4_params.pls =
714 bf_get(cfg_pvl, mbx_sli4_parameters);
716 mempool_free(mboxq, phba->mbox_mem_pool);
721 * lpfc_hba_init_link - Initialize the FC link
722 * @phba: pointer to lpfc hba data structure.
723 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
725 * This routine will issue the INIT_LINK mailbox command call.
726 * It is available to other drivers through the lpfc_hba data
727 * structure for use as a delayed link up mechanism with the
728 * module parameter lpfc_suppress_link_up.
732 * Any other value - error
735 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
737 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
741 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
742 * @phba: pointer to lpfc hba data structure.
743 * @fc_topology: desired fc topology.
744 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
746 * This routine will issue the INIT_LINK mailbox command call.
747 * It is available to other drivers through the lpfc_hba data
748 * structure for use as a delayed link up mechanism with the
749 * module parameter lpfc_suppress_link_up.
753 * Any other value - error
756 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
759 struct lpfc_vport *vport = phba->pport;
764 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
766 phba->link_state = LPFC_HBA_ERROR;
772 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
773 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
774 !(phba->lmt & LMT_1Gb)) ||
775 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
776 !(phba->lmt & LMT_2Gb)) ||
777 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
778 !(phba->lmt & LMT_4Gb)) ||
779 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
780 !(phba->lmt & LMT_8Gb)) ||
781 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
782 !(phba->lmt & LMT_10Gb)) ||
783 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
784 !(phba->lmt & LMT_16Gb)) ||
785 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
786 !(phba->lmt & LMT_32Gb)) ||
787 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
788 !(phba->lmt & LMT_64Gb))) {
789 /* Reset link speed to auto */
790 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
791 "1302 Invalid speed for this board:%d "
792 "Reset link speed to auto.\n",
793 phba->cfg_link_speed);
794 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
796 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
797 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
798 if (phba->sli_rev < LPFC_SLI_REV4)
799 lpfc_set_loopback_flag(phba);
800 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
801 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
802 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
803 "0498 Adapter failed to init, mbxCmd x%x "
804 "INIT_LINK, mbxStatus x%x\n",
805 mb->mbxCommand, mb->mbxStatus);
806 if (phba->sli_rev <= LPFC_SLI_REV3) {
807 /* Clear all interrupt enable conditions */
808 writel(0, phba->HCregaddr);
809 readl(phba->HCregaddr); /* flush */
810 /* Clear all pending interrupts */
811 writel(0xffffffff, phba->HAregaddr);
812 readl(phba->HAregaddr); /* flush */
814 phba->link_state = LPFC_HBA_ERROR;
815 if (rc != MBX_BUSY || flag == MBX_POLL)
816 mempool_free(pmb, phba->mbox_mem_pool);
819 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
820 if (flag == MBX_POLL)
821 mempool_free(pmb, phba->mbox_mem_pool);
827 * lpfc_hba_down_link - this routine downs the FC link
828 * @phba: pointer to lpfc hba data structure.
829 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
831 * This routine will issue the DOWN_LINK mailbox command call.
832 * It is available to other drivers through the lpfc_hba data
833 * structure for use to stop the link.
837 * Any other value - error
840 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
845 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
847 phba->link_state = LPFC_HBA_ERROR;
851 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
852 "0491 Adapter Link is disabled.\n");
853 lpfc_down_link(phba, pmb);
854 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
855 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
856 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
857 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
858 "2522 Adapter failed to issue DOWN_LINK"
859 " mbox command rc 0x%x\n", rc);
861 mempool_free(pmb, phba->mbox_mem_pool);
864 if (flag == MBX_POLL)
865 mempool_free(pmb, phba->mbox_mem_pool);
871 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
872 * @phba: pointer to lpfc HBA data structure.
874 * This routine will do LPFC uninitialization before the HBA is reset when
875 * bringing down the SLI Layer.
879 * Any other value - error.
882 lpfc_hba_down_prep(struct lpfc_hba *phba)
884 struct lpfc_vport **vports;
887 if (phba->sli_rev <= LPFC_SLI_REV3) {
888 /* Disable interrupts */
889 writel(0, phba->HCregaddr);
890 readl(phba->HCregaddr); /* flush */
893 if (phba->pport->load_flag & FC_UNLOADING)
894 lpfc_cleanup_discovery_resources(phba->pport);
896 vports = lpfc_create_vport_work_array(phba);
898 for (i = 0; i <= phba->max_vports &&
899 vports[i] != NULL; i++)
900 lpfc_cleanup_discovery_resources(vports[i]);
901 lpfc_destroy_vport_work_array(phba, vports);
907 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
908 * rspiocb which got deferred
910 * @phba: pointer to lpfc HBA data structure.
912 * This routine will cleanup completed slow path events after HBA is reset
913 * when bringing down the SLI Layer.
920 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
922 struct lpfc_iocbq *rspiocbq;
923 struct hbq_dmabuf *dmabuf;
924 struct lpfc_cq_event *cq_event;
926 spin_lock_irq(&phba->hbalock);
927 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
928 spin_unlock_irq(&phba->hbalock);
930 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
931 /* Get the response iocb from the head of work queue */
932 spin_lock_irq(&phba->hbalock);
933 list_remove_head(&phba->sli4_hba.sp_queue_event,
934 cq_event, struct lpfc_cq_event, list);
935 spin_unlock_irq(&phba->hbalock);
937 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
938 case CQE_CODE_COMPL_WQE:
939 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
941 lpfc_sli_release_iocbq(phba, rspiocbq);
943 case CQE_CODE_RECEIVE:
944 case CQE_CODE_RECEIVE_V1:
945 dmabuf = container_of(cq_event, struct hbq_dmabuf,
947 lpfc_in_buf_free(phba, &dmabuf->dbuf);
953 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
954 * @phba: pointer to lpfc HBA data structure.
956 * This routine will cleanup posted ELS buffers after the HBA is reset
957 * when bringing down the SLI Layer.
964 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
966 struct lpfc_sli *psli = &phba->sli;
967 struct lpfc_sli_ring *pring;
968 struct lpfc_dmabuf *mp, *next_mp;
972 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
973 lpfc_sli_hbqbuf_free_all(phba);
975 /* Cleanup preposted buffers on the ELS ring */
976 pring = &psli->sli3_ring[LPFC_ELS_RING];
977 spin_lock_irq(&phba->hbalock);
978 list_splice_init(&pring->postbufq, &buflist);
979 spin_unlock_irq(&phba->hbalock);
982 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
985 lpfc_mbuf_free(phba, mp->virt, mp->phys);
989 spin_lock_irq(&phba->hbalock);
990 pring->postbufq_cnt -= count;
991 spin_unlock_irq(&phba->hbalock);
996 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
997 * @phba: pointer to lpfc HBA data structure.
999 * This routine will cleanup the txcmplq after the HBA is reset when bringing
1000 * down the SLI Layer.
1006 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
1008 struct lpfc_sli *psli = &phba->sli;
1009 struct lpfc_queue *qp = NULL;
1010 struct lpfc_sli_ring *pring;
1011 LIST_HEAD(completions);
1013 struct lpfc_iocbq *piocb, *next_iocb;
1015 if (phba->sli_rev != LPFC_SLI_REV4) {
1016 for (i = 0; i < psli->num_rings; i++) {
1017 pring = &psli->sli3_ring[i];
1018 spin_lock_irq(&phba->hbalock);
1019 /* At this point in time the HBA is either reset or DOA
1020 * Nothing should be on txcmplq as it will
1023 list_splice_init(&pring->txcmplq, &completions);
1024 pring->txcmplq_cnt = 0;
1025 spin_unlock_irq(&phba->hbalock);
1027 lpfc_sli_abort_iocb_ring(phba, pring);
1029 /* Cancel all the IOCBs from the completions list */
1030 lpfc_sli_cancel_iocbs(phba, &completions,
1031 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1034 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1038 spin_lock_irq(&pring->ring_lock);
1039 list_for_each_entry_safe(piocb, next_iocb,
1040 &pring->txcmplq, list)
1041 piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
1042 list_splice_init(&pring->txcmplq, &completions);
1043 pring->txcmplq_cnt = 0;
1044 spin_unlock_irq(&pring->ring_lock);
1045 lpfc_sli_abort_iocb_ring(phba, pring);
1047 /* Cancel all the IOCBs from the completions list */
1048 lpfc_sli_cancel_iocbs(phba, &completions,
1049 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1053 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1054 * @phba: pointer to lpfc HBA data structure.
1056 * This routine will do uninitialization after the HBA is reset when bring
1057 * down the SLI Layer.
1061 * Any other value - error.
1064 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1066 lpfc_hba_free_post_buf(phba);
1067 lpfc_hba_clean_txcmplq(phba);
1072 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1073 * @phba: pointer to lpfc HBA data structure.
1075 * This routine will do uninitialization after the HBA is reset when bring
1076 * down the SLI Layer.
1080 * Any other value - error.
1083 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1085 struct lpfc_io_buf *psb, *psb_next;
1086 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
1087 struct lpfc_sli4_hdw_queue *qp;
1089 LIST_HEAD(nvme_aborts);
1090 LIST_HEAD(nvmet_aborts);
1091 struct lpfc_sglq *sglq_entry = NULL;
1095 lpfc_sli_hbqbuf_free_all(phba);
1096 lpfc_hba_clean_txcmplq(phba);
1098 /* At this point in time the HBA is either reset or DOA. Either
1099 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1100 * on the lpfc_els_sgl_list so that it can either be freed if the
1101 * driver is unloading or reposted if the driver is restarting
1105 /* sgl_list_lock required because worker thread uses this
1108 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
1109 list_for_each_entry(sglq_entry,
1110 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1111 sglq_entry->state = SGL_FREED;
1113 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1114 &phba->sli4_hba.lpfc_els_sgl_list);
1117 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
1119 /* abts_xxxx_buf_list_lock required because worker thread uses this
1122 spin_lock_irq(&phba->hbalock);
1124 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1125 qp = &phba->sli4_hba.hdwq[idx];
1127 spin_lock(&qp->abts_io_buf_list_lock);
1128 list_splice_init(&qp->lpfc_abts_io_buf_list,
1131 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1133 psb->status = IOSTAT_SUCCESS;
1136 spin_lock(&qp->io_buf_list_put_lock);
1137 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1138 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1139 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1140 qp->abts_scsi_io_bufs = 0;
1141 qp->abts_nvme_io_bufs = 0;
1142 spin_unlock(&qp->io_buf_list_put_lock);
1143 spin_unlock(&qp->abts_io_buf_list_lock);
1145 spin_unlock_irq(&phba->hbalock);
1147 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1148 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1149 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1151 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1152 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1153 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
1154 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1158 lpfc_sli4_free_sp_events(phba);
1163 * lpfc_hba_down_post - Wrapper func for hba down post routine
1164 * @phba: pointer to lpfc HBA data structure.
1166 * This routine wraps the actual SLI3 or SLI4 routine for performing
1167 * uninitialization after the HBA is reset when bring down the SLI Layer.
1171 * Any other value - error.
1174 lpfc_hba_down_post(struct lpfc_hba *phba)
1176 return (*phba->lpfc_hba_down_post)(phba);
1180 * lpfc_hb_timeout - The HBA-timer timeout handler
1181 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1183 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1184 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1185 * work-port-events bitmap and the worker thread is notified. This timeout
1186 * event will be used by the worker thread to invoke the actual timeout
1187 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1188 * be performed in the timeout handler and the HBA timeout event bit shall
1189 * be cleared by the worker thread after it has taken the event bitmap out.
1192 lpfc_hb_timeout(struct timer_list *t)
1194 struct lpfc_hba *phba;
1195 uint32_t tmo_posted;
1196 unsigned long iflag;
1198 phba = from_timer(phba, t, hb_tmofunc);
1200 /* Check for heart beat timeout conditions */
1201 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1202 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1204 phba->pport->work_port_events |= WORKER_HB_TMO;
1205 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1207 /* Tell the worker thread there is work to do */
1209 lpfc_worker_wake_up(phba);
1214 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1215 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1217 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1218 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1219 * work-port-events bitmap and the worker thread is notified. This timeout
1220 * event will be used by the worker thread to invoke the actual timeout
1221 * handler routine, lpfc_rrq_handler. Any periodical operations will
1222 * be performed in the timeout handler and the RRQ timeout event bit shall
1223 * be cleared by the worker thread after it has taken the event bitmap out.
1226 lpfc_rrq_timeout(struct timer_list *t)
1228 struct lpfc_hba *phba;
1229 unsigned long iflag;
1231 phba = from_timer(phba, t, rrq_tmr);
1232 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1233 if (!(phba->pport->load_flag & FC_UNLOADING))
1234 phba->hba_flag |= HBA_RRQ_ACTIVE;
1236 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1237 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1239 if (!(phba->pport->load_flag & FC_UNLOADING))
1240 lpfc_worker_wake_up(phba);
1244 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1245 * @phba: pointer to lpfc hba data structure.
1246 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1248 * This is the callback function to the lpfc heart-beat mailbox command.
1249 * If configured, the lpfc driver issues the heart-beat mailbox command to
1250 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1251 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1252 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1253 * heart-beat outstanding state. Once the mailbox command comes back and
1254 * no error conditions detected, the heart-beat mailbox command timer is
1255 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1256 * state is cleared for the next heart-beat. If the timer expired with the
1257 * heart-beat outstanding state set, the driver will put the HBA offline.
1260 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1262 unsigned long drvr_flag;
1264 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1265 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
1266 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1268 /* Check and reset heart-beat timer if necessary */
1269 mempool_free(pmboxq, phba->mbox_mem_pool);
1270 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1271 !(phba->link_state == LPFC_HBA_ERROR) &&
1272 !(phba->pport->load_flag & FC_UNLOADING))
1273 mod_timer(&phba->hb_tmofunc,
1275 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1280 * lpfc_idle_stat_delay_work - idle_stat tracking
1282 * This routine tracks per-cq idle_stat and determines polling decisions.
1288 lpfc_idle_stat_delay_work(struct work_struct *work)
1290 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1292 idle_stat_delay_work);
1293 struct lpfc_queue *cq;
1294 struct lpfc_sli4_hdw_queue *hdwq;
1295 struct lpfc_idle_stat *idle_stat;
1296 u32 i, idle_percent;
1297 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1299 if (phba->pport->load_flag & FC_UNLOADING)
1302 if (phba->link_state == LPFC_HBA_ERROR ||
1303 phba->pport->fc_flag & FC_OFFLINE_MODE ||
1304 phba->cmf_active_mode != LPFC_CFG_OFF)
1307 for_each_present_cpu(i) {
1308 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1311 /* Skip if we've already handled this cq's primary CPU */
1315 idle_stat = &phba->sli4_hba.idle_stat[i];
1317 /* get_cpu_idle_time returns values as running counters. Thus,
1318 * to know the amount for this period, the prior counter values
1319 * need to be subtracted from the current counter values.
1320 * From there, the idle time stat can be calculated as a
1321 * percentage of 100 - the sum of the other consumption times.
1323 wall_idle = get_cpu_idle_time(i, &wall, 1);
1324 diff_idle = wall_idle - idle_stat->prev_idle;
1325 diff_wall = wall - idle_stat->prev_wall;
1327 if (diff_wall <= diff_idle)
1330 busy_time = diff_wall - diff_idle;
1332 idle_percent = div64_u64(100 * busy_time, diff_wall);
1333 idle_percent = 100 - idle_percent;
1335 if (idle_percent < 15)
1336 cq->poll_mode = LPFC_QUEUE_WORK;
1338 cq->poll_mode = LPFC_IRQ_POLL;
1340 idle_stat->prev_idle = wall_idle;
1341 idle_stat->prev_wall = wall;
1345 schedule_delayed_work(&phba->idle_stat_delay_work,
1346 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1350 lpfc_hb_eq_delay_work(struct work_struct *work)
1352 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1353 struct lpfc_hba, eq_delay_work);
1354 struct lpfc_eq_intr_info *eqi, *eqi_new;
1355 struct lpfc_queue *eq, *eq_next;
1356 unsigned char *ena_delay = NULL;
1360 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1363 if (phba->link_state == LPFC_HBA_ERROR ||
1364 phba->pport->fc_flag & FC_OFFLINE_MODE)
1367 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1372 for (i = 0; i < phba->cfg_irq_chann; i++) {
1373 /* Get the EQ corresponding to the IRQ vector */
1374 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1377 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1378 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1379 ena_delay[eq->last_cpu] = 1;
1383 for_each_present_cpu(i) {
1384 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1386 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1387 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1388 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1395 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1396 if (unlikely(eq->last_cpu != i)) {
1397 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1399 list_move_tail(&eq->cpu_list, &eqi_new->list);
1402 if (usdelay != eq->q_mode)
1403 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1411 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1412 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1416 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1417 * @phba: pointer to lpfc hba data structure.
1419 * For each heartbeat, this routine does some heuristic methods to adjust
1420 * XRI distribution. The goal is to fully utilize free XRIs.
1422 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1427 hwq_count = phba->cfg_hdw_queue;
1428 for (i = 0; i < hwq_count; i++) {
1429 /* Adjust XRIs in private pool */
1430 lpfc_adjust_pvt_pool_count(phba, i);
1432 /* Adjust high watermark */
1433 lpfc_adjust_high_watermark(phba, i);
1435 #ifdef LPFC_MXP_STAT
1436 /* Snapshot pbl, pvt and busy count */
1437 lpfc_snapshot_mxp(phba, i);
1443 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1444 * @phba: pointer to lpfc hba data structure.
1446 * If a HB mbox is not already in progrees, this routine will allocate
1447 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1448 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1451 lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1453 LPFC_MBOXQ_t *pmboxq;
1456 /* Is a Heartbeat mbox already in progress */
1457 if (phba->hba_flag & HBA_HBEAT_INP)
1460 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1464 lpfc_heart_beat(phba, pmboxq);
1465 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1466 pmboxq->vport = phba->pport;
1467 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1469 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1470 mempool_free(pmboxq, phba->mbox_mem_pool);
1473 phba->hba_flag |= HBA_HBEAT_INP;
1479 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1480 * @phba: pointer to lpfc hba data structure.
1482 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1483 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1484 * of the value of lpfc_enable_hba_heartbeat.
1485 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1486 * try to issue a MBX_HEARTBEAT mbox command.
1489 lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1491 if (phba->cfg_enable_hba_heartbeat)
1493 phba->hba_flag |= HBA_HBEAT_TMO;
1497 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1498 * @phba: pointer to lpfc hba data structure.
1500 * This is the actual HBA-timer timeout handler to be invoked by the worker
1501 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1502 * handler performs any periodic operations needed for the device. If such
1503 * periodic event has already been attended to either in the interrupt handler
1504 * or by processing slow-ring or fast-ring events within the HBA-timer
1505 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1506 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1507 * is configured and there is no heart-beat mailbox command outstanding, a
1508 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1509 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1513 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1515 struct lpfc_vport **vports;
1516 struct lpfc_dmabuf *buf_ptr;
1519 struct lpfc_sli *psli = &phba->sli;
1520 LIST_HEAD(completions);
1522 if (phba->cfg_xri_rebalancing) {
1523 /* Multi-XRI pools handler */
1524 lpfc_hb_mxp_handler(phba);
1527 vports = lpfc_create_vport_work_array(phba);
1529 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1530 lpfc_rcv_seq_check_edtov(vports[i]);
1531 lpfc_fdmi_change_check(vports[i]);
1533 lpfc_destroy_vport_work_array(phba, vports);
1535 if ((phba->link_state == LPFC_HBA_ERROR) ||
1536 (phba->pport->load_flag & FC_UNLOADING) ||
1537 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1540 if (phba->elsbuf_cnt &&
1541 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1542 spin_lock_irq(&phba->hbalock);
1543 list_splice_init(&phba->elsbuf, &completions);
1544 phba->elsbuf_cnt = 0;
1545 phba->elsbuf_prev_cnt = 0;
1546 spin_unlock_irq(&phba->hbalock);
1548 while (!list_empty(&completions)) {
1549 list_remove_head(&completions, buf_ptr,
1550 struct lpfc_dmabuf, list);
1551 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1555 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1557 /* If there is no heart beat outstanding, issue a heartbeat command */
1558 if (phba->cfg_enable_hba_heartbeat) {
1559 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1560 spin_lock_irq(&phba->pport->work_port_lock);
1561 if (time_after(phba->last_completion_time +
1562 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1564 spin_unlock_irq(&phba->pport->work_port_lock);
1565 if (phba->hba_flag & HBA_HBEAT_INP)
1566 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1568 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1571 spin_unlock_irq(&phba->pport->work_port_lock);
1573 /* Check if a MBX_HEARTBEAT is already in progress */
1574 if (phba->hba_flag & HBA_HBEAT_INP) {
1576 * If heart beat timeout called with HBA_HBEAT_INP set
1577 * we need to give the hb mailbox cmd a chance to
1580 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1581 "0459 Adapter heartbeat still outstanding: "
1582 "last compl time was %d ms.\n",
1583 jiffies_to_msecs(jiffies
1584 - phba->last_completion_time));
1585 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1587 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1588 (list_empty(&psli->mboxq))) {
1590 retval = lpfc_issue_hb_mbox(phba);
1592 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1595 phba->skipped_hb = 0;
1596 } else if (time_before_eq(phba->last_completion_time,
1597 phba->skipped_hb)) {
1598 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1599 "2857 Last completion time not "
1600 " updated in %d ms\n",
1601 jiffies_to_msecs(jiffies
1602 - phba->last_completion_time));
1604 phba->skipped_hb = jiffies;
1606 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1610 /* Check to see if we want to force a MBX_HEARTBEAT */
1611 if (phba->hba_flag & HBA_HBEAT_TMO) {
1612 retval = lpfc_issue_hb_mbox(phba);
1614 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1616 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1619 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1622 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
1626 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1627 * @phba: pointer to lpfc hba data structure.
1629 * This routine is called to bring the HBA offline when HBA hardware error
1630 * other than Port Error 6 has been detected.
1633 lpfc_offline_eratt(struct lpfc_hba *phba)
1635 struct lpfc_sli *psli = &phba->sli;
1637 spin_lock_irq(&phba->hbalock);
1638 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1639 spin_unlock_irq(&phba->hbalock);
1640 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1643 lpfc_reset_barrier(phba);
1644 spin_lock_irq(&phba->hbalock);
1645 lpfc_sli_brdreset(phba);
1646 spin_unlock_irq(&phba->hbalock);
1647 lpfc_hba_down_post(phba);
1648 lpfc_sli_brdready(phba, HS_MBRDY);
1649 lpfc_unblock_mgmt_io(phba);
1650 phba->link_state = LPFC_HBA_ERROR;
1655 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1656 * @phba: pointer to lpfc hba data structure.
1658 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1659 * other than Port Error 6 has been detected.
1662 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1664 spin_lock_irq(&phba->hbalock);
1665 if (phba->link_state == LPFC_HBA_ERROR &&
1666 test_bit(HBA_PCI_ERR, &phba->bit_flags)) {
1667 spin_unlock_irq(&phba->hbalock);
1670 phba->link_state = LPFC_HBA_ERROR;
1671 spin_unlock_irq(&phba->hbalock);
1673 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1674 lpfc_sli_flush_io_rings(phba);
1676 lpfc_hba_down_post(phba);
1677 lpfc_unblock_mgmt_io(phba);
1681 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1682 * @phba: pointer to lpfc hba data structure.
1684 * This routine is invoked to handle the deferred HBA hardware error
1685 * conditions. This type of error is indicated by HBA by setting ER1
1686 * and another ER bit in the host status register. The driver will
1687 * wait until the ER1 bit clears before handling the error condition.
1690 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1692 uint32_t old_host_status = phba->work_hs;
1693 struct lpfc_sli *psli = &phba->sli;
1695 /* If the pci channel is offline, ignore possible errors,
1696 * since we cannot communicate with the pci card anyway.
1698 if (pci_channel_offline(phba->pcidev)) {
1699 spin_lock_irq(&phba->hbalock);
1700 phba->hba_flag &= ~DEFER_ERATT;
1701 spin_unlock_irq(&phba->hbalock);
1705 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1706 "0479 Deferred Adapter Hardware Error "
1707 "Data: x%x x%x x%x\n",
1708 phba->work_hs, phba->work_status[0],
1709 phba->work_status[1]);
1711 spin_lock_irq(&phba->hbalock);
1712 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1713 spin_unlock_irq(&phba->hbalock);
1717 * Firmware stops when it triggred erratt. That could cause the I/Os
1718 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1719 * SCSI layer retry it after re-establishing link.
1721 lpfc_sli_abort_fcp_rings(phba);
1724 * There was a firmware error. Take the hba offline and then
1725 * attempt to restart it.
1727 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1730 /* Wait for the ER1 bit to clear.*/
1731 while (phba->work_hs & HS_FFER1) {
1733 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1734 phba->work_hs = UNPLUG_ERR ;
1737 /* If driver is unloading let the worker thread continue */
1738 if (phba->pport->load_flag & FC_UNLOADING) {
1745 * This is to ptrotect against a race condition in which
1746 * first write to the host attention register clear the
1747 * host status register.
1749 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1750 phba->work_hs = old_host_status & ~HS_FFER1;
1752 spin_lock_irq(&phba->hbalock);
1753 phba->hba_flag &= ~DEFER_ERATT;
1754 spin_unlock_irq(&phba->hbalock);
1755 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1756 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1760 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1762 struct lpfc_board_event_header board_event;
1763 struct Scsi_Host *shost;
1765 board_event.event_type = FC_REG_BOARD_EVENT;
1766 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1767 shost = lpfc_shost_from_vport(phba->pport);
1768 fc_host_post_vendor_event(shost, fc_get_event_number(),
1769 sizeof(board_event),
1770 (char *) &board_event,
1775 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1776 * @phba: pointer to lpfc hba data structure.
1778 * This routine is invoked to handle the following HBA hardware error
1780 * 1 - HBA error attention interrupt
1781 * 2 - DMA ring index out of range
1782 * 3 - Mailbox command came back as unknown
1785 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1787 struct lpfc_vport *vport = phba->pport;
1788 struct lpfc_sli *psli = &phba->sli;
1789 uint32_t event_data;
1790 unsigned long temperature;
1791 struct temp_event temp_event_data;
1792 struct Scsi_Host *shost;
1794 /* If the pci channel is offline, ignore possible errors,
1795 * since we cannot communicate with the pci card anyway.
1797 if (pci_channel_offline(phba->pcidev)) {
1798 spin_lock_irq(&phba->hbalock);
1799 phba->hba_flag &= ~DEFER_ERATT;
1800 spin_unlock_irq(&phba->hbalock);
1804 /* If resets are disabled then leave the HBA alone and return */
1805 if (!phba->cfg_enable_hba_reset)
1808 /* Send an internal error event to mgmt application */
1809 lpfc_board_errevt_to_mgmt(phba);
1811 if (phba->hba_flag & DEFER_ERATT)
1812 lpfc_handle_deferred_eratt(phba);
1814 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1815 if (phba->work_hs & HS_FFER6)
1816 /* Re-establishing Link */
1817 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1818 "1301 Re-establishing Link "
1819 "Data: x%x x%x x%x\n",
1820 phba->work_hs, phba->work_status[0],
1821 phba->work_status[1]);
1822 if (phba->work_hs & HS_FFER8)
1823 /* Device Zeroization */
1824 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1825 "2861 Host Authentication device "
1826 "zeroization Data:x%x x%x x%x\n",
1827 phba->work_hs, phba->work_status[0],
1828 phba->work_status[1]);
1830 spin_lock_irq(&phba->hbalock);
1831 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1832 spin_unlock_irq(&phba->hbalock);
1835 * Firmware stops when it triggled erratt with HS_FFER6.
1836 * That could cause the I/Os dropped by the firmware.
1837 * Error iocb (I/O) on txcmplq and let the SCSI layer
1838 * retry it after re-establishing link.
1840 lpfc_sli_abort_fcp_rings(phba);
1843 * There was a firmware error. Take the hba offline and then
1844 * attempt to restart it.
1846 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1848 lpfc_sli_brdrestart(phba);
1849 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1850 lpfc_unblock_mgmt_io(phba);
1853 lpfc_unblock_mgmt_io(phba);
1854 } else if (phba->work_hs & HS_CRIT_TEMP) {
1855 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1856 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1857 temp_event_data.event_code = LPFC_CRIT_TEMP;
1858 temp_event_data.data = (uint32_t)temperature;
1860 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1861 "0406 Adapter maximum temperature exceeded "
1862 "(%ld), taking this port offline "
1863 "Data: x%x x%x x%x\n",
1864 temperature, phba->work_hs,
1865 phba->work_status[0], phba->work_status[1]);
1867 shost = lpfc_shost_from_vport(phba->pport);
1868 fc_host_post_vendor_event(shost, fc_get_event_number(),
1869 sizeof(temp_event_data),
1870 (char *) &temp_event_data,
1871 SCSI_NL_VID_TYPE_PCI
1872 | PCI_VENDOR_ID_EMULEX);
1874 spin_lock_irq(&phba->hbalock);
1875 phba->over_temp_state = HBA_OVER_TEMP;
1876 spin_unlock_irq(&phba->hbalock);
1877 lpfc_offline_eratt(phba);
1880 /* The if clause above forces this code path when the status
1881 * failure is a value other than FFER6. Do not call the offline
1882 * twice. This is the adapter hardware error path.
1884 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1885 "0457 Adapter Hardware Error "
1886 "Data: x%x x%x x%x\n",
1888 phba->work_status[0], phba->work_status[1]);
1890 event_data = FC_REG_DUMP_EVENT;
1891 shost = lpfc_shost_from_vport(vport);
1892 fc_host_post_vendor_event(shost, fc_get_event_number(),
1893 sizeof(event_data), (char *) &event_data,
1894 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1896 lpfc_offline_eratt(phba);
1902 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1903 * @phba: pointer to lpfc hba data structure.
1904 * @mbx_action: flag for mailbox shutdown action.
1905 * @en_rn_msg: send reset/port recovery message.
1906 * This routine is invoked to perform an SLI4 port PCI function reset in
1907 * response to port status register polling attention. It waits for port
1908 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1909 * During this process, interrupt vectors are freed and later requested
1910 * for handling possible port resource change.
1913 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1918 LPFC_MBOXQ_t *mboxq;
1920 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1921 LPFC_SLI_INTF_IF_TYPE_2) {
1923 * On error status condition, driver need to wait for port
1924 * ready before performing reset.
1926 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1931 /* need reset: attempt for port recovery */
1933 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1934 "2887 Reset Needed: Attempting Port "
1937 /* If we are no wait, the HBA has been reset and is not
1938 * functional, thus we should clear
1939 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
1941 if (mbx_action == LPFC_MBX_NO_WAIT) {
1942 spin_lock_irq(&phba->hbalock);
1943 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
1944 if (phba->sli.mbox_active) {
1945 mboxq = phba->sli.mbox_active;
1946 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1947 __lpfc_mbox_cmpl_put(phba, mboxq);
1948 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1949 phba->sli.mbox_active = NULL;
1951 spin_unlock_irq(&phba->hbalock);
1954 lpfc_offline_prep(phba, mbx_action);
1955 lpfc_sli_flush_io_rings(phba);
1957 /* release interrupt for possible resource change */
1958 lpfc_sli4_disable_intr(phba);
1959 rc = lpfc_sli_brdrestart(phba);
1961 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1962 "6309 Failed to restart board\n");
1965 /* request and enable interrupt */
1966 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1967 if (intr_mode == LPFC_INTR_ERROR) {
1968 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1969 "3175 Failed to enable interrupt\n");
1972 phba->intr_mode = intr_mode;
1973 rc = lpfc_online(phba);
1975 lpfc_unblock_mgmt_io(phba);
1981 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1982 * @phba: pointer to lpfc hba data structure.
1984 * This routine is invoked to handle the SLI4 HBA hardware error attention
1988 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1990 struct lpfc_vport *vport = phba->pport;
1991 uint32_t event_data;
1992 struct Scsi_Host *shost;
1994 struct lpfc_register portstat_reg = {0};
1995 uint32_t reg_err1, reg_err2;
1996 uint32_t uerrlo_reg, uemasklo_reg;
1997 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1998 bool en_rn_msg = true;
1999 struct temp_event temp_event_data;
2000 struct lpfc_register portsmphr_reg;
2003 /* If the pci channel is offline, ignore possible errors, since
2004 * we cannot communicate with the pci card anyway.
2006 if (pci_channel_offline(phba->pcidev)) {
2007 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2008 "3166 pci channel is offline\n");
2009 lpfc_sli_flush_io_rings(phba);
2013 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
2014 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2016 case LPFC_SLI_INTF_IF_TYPE_0:
2017 pci_rd_rc1 = lpfc_readl(
2018 phba->sli4_hba.u.if_type0.UERRLOregaddr,
2020 pci_rd_rc2 = lpfc_readl(
2021 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
2023 /* consider PCI bus read error as pci_channel_offline */
2024 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
2026 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
2027 lpfc_sli4_offline_eratt(phba);
2030 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2031 "7623 Checking UE recoverable");
2033 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
2034 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2035 &portsmphr_reg.word0))
2038 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
2040 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2041 LPFC_PORT_SEM_UE_RECOVERABLE)
2043 /*Sleep for 1Sec, before checking SEMAPHORE */
2047 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2048 "4827 smphr_port_status x%x : Waited %dSec",
2049 smphr_port_status, i);
2051 /* Recoverable UE, reset the HBA device */
2052 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
2053 LPFC_PORT_SEM_UE_RECOVERABLE) {
2054 for (i = 0; i < 20; i++) {
2056 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2057 &portsmphr_reg.word0) &&
2058 (LPFC_POST_STAGE_PORT_READY ==
2059 bf_get(lpfc_port_smphr_port_status,
2061 rc = lpfc_sli4_port_sta_fn_reset(phba,
2062 LPFC_MBX_NO_WAIT, en_rn_msg);
2065 lpfc_printf_log(phba, KERN_ERR,
2067 "4215 Failed to recover UE");
2072 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2073 "7624 Firmware not ready: Failing UE recovery,"
2074 " waited %dSec", i);
2075 phba->link_state = LPFC_HBA_ERROR;
2078 case LPFC_SLI_INTF_IF_TYPE_2:
2079 case LPFC_SLI_INTF_IF_TYPE_6:
2080 pci_rd_rc1 = lpfc_readl(
2081 phba->sli4_hba.u.if_type2.STATUSregaddr,
2082 &portstat_reg.word0);
2083 /* consider PCI bus read error as pci_channel_offline */
2084 if (pci_rd_rc1 == -EIO) {
2085 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2086 "3151 PCI bus read access failure: x%x\n",
2087 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
2088 lpfc_sli4_offline_eratt(phba);
2091 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2092 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
2093 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
2094 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2095 "2889 Port Overtemperature event, "
2096 "taking port offline Data: x%x x%x\n",
2097 reg_err1, reg_err2);
2099 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
2100 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2101 temp_event_data.event_code = LPFC_CRIT_TEMP;
2102 temp_event_data.data = 0xFFFFFFFF;
2104 shost = lpfc_shost_from_vport(phba->pport);
2105 fc_host_post_vendor_event(shost, fc_get_event_number(),
2106 sizeof(temp_event_data),
2107 (char *)&temp_event_data,
2108 SCSI_NL_VID_TYPE_PCI
2109 | PCI_VENDOR_ID_EMULEX);
2111 spin_lock_irq(&phba->hbalock);
2112 phba->over_temp_state = HBA_OVER_TEMP;
2113 spin_unlock_irq(&phba->hbalock);
2114 lpfc_sli4_offline_eratt(phba);
2117 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2118 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
2119 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2120 "3143 Port Down: Firmware Update "
2123 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2124 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2125 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2126 "3144 Port Down: Debug Dump\n");
2127 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2128 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
2129 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2130 "3145 Port Down: Provisioning\n");
2132 /* If resets are disabled then leave the HBA alone and return */
2133 if (!phba->cfg_enable_hba_reset)
2136 /* Check port status register for function reset */
2137 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2140 /* don't report event on forced debug dump */
2141 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2142 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2147 /* fall through for not able to recover */
2148 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2149 "3152 Unrecoverable error\n");
2150 phba->link_state = LPFC_HBA_ERROR;
2152 case LPFC_SLI_INTF_IF_TYPE_1:
2156 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2157 "3123 Report dump event to upper layer\n");
2158 /* Send an internal error event to mgmt application */
2159 lpfc_board_errevt_to_mgmt(phba);
2161 event_data = FC_REG_DUMP_EVENT;
2162 shost = lpfc_shost_from_vport(vport);
2163 fc_host_post_vendor_event(shost, fc_get_event_number(),
2164 sizeof(event_data), (char *) &event_data,
2165 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2169 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2170 * @phba: pointer to lpfc HBA data structure.
2172 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2173 * routine from the API jump table function pointer from the lpfc_hba struct.
2177 * Any other value - error.
2180 lpfc_handle_eratt(struct lpfc_hba *phba)
2182 (*phba->lpfc_handle_eratt)(phba);
2186 * lpfc_handle_latt - The HBA link event handler
2187 * @phba: pointer to lpfc hba data structure.
2189 * This routine is invoked from the worker thread to handle a HBA host
2190 * attention link event. SLI3 only.
2193 lpfc_handle_latt(struct lpfc_hba *phba)
2195 struct lpfc_vport *vport = phba->pport;
2196 struct lpfc_sli *psli = &phba->sli;
2198 volatile uint32_t control;
2201 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2204 goto lpfc_handle_latt_err_exit;
2207 rc = lpfc_mbox_rsrc_prep(phba, pmb);
2210 mempool_free(pmb, phba->mbox_mem_pool);
2211 goto lpfc_handle_latt_err_exit;
2214 /* Cleanup any outstanding ELS commands */
2215 lpfc_els_flush_all_cmd(phba);
2216 psli->slistat.link_event++;
2217 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
2218 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2220 /* Block ELS IOCBs until we have processed this mbox command */
2221 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2222 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2223 if (rc == MBX_NOT_FINISHED) {
2225 goto lpfc_handle_latt_free_mbuf;
2228 /* Clear Link Attention in HA REG */
2229 spin_lock_irq(&phba->hbalock);
2230 writel(HA_LATT, phba->HAregaddr);
2231 readl(phba->HAregaddr); /* flush */
2232 spin_unlock_irq(&phba->hbalock);
2236 lpfc_handle_latt_free_mbuf:
2237 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2238 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
2239 lpfc_handle_latt_err_exit:
2240 /* Enable Link attention interrupts */
2241 spin_lock_irq(&phba->hbalock);
2242 psli->sli_flag |= LPFC_PROCESS_LA;
2243 control = readl(phba->HCregaddr);
2244 control |= HC_LAINT_ENA;
2245 writel(control, phba->HCregaddr);
2246 readl(phba->HCregaddr); /* flush */
2248 /* Clear Link Attention in HA REG */
2249 writel(HA_LATT, phba->HAregaddr);
2250 readl(phba->HAregaddr); /* flush */
2251 spin_unlock_irq(&phba->hbalock);
2252 lpfc_linkdown(phba);
2253 phba->link_state = LPFC_HBA_ERROR;
2255 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2256 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2262 lpfc_fill_vpd(struct lpfc_hba *phba, uint8_t *vpd, int length, int *pindex)
2266 while (length > 0) {
2267 /* Look for Serial Number */
2268 if ((vpd[*pindex] == 'S') && (vpd[*pindex + 1] == 'N')) {
2275 phba->SerialNumber[j++] = vpd[(*pindex)++];
2279 phba->SerialNumber[j] = 0;
2281 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '1')) {
2282 phba->vpd_flag |= VPD_MODEL_DESC;
2289 phba->ModelDesc[j++] = vpd[(*pindex)++];
2293 phba->ModelDesc[j] = 0;
2295 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '2')) {
2296 phba->vpd_flag |= VPD_MODEL_NAME;
2303 phba->ModelName[j++] = vpd[(*pindex)++];
2307 phba->ModelName[j] = 0;
2309 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '3')) {
2310 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2317 phba->ProgramType[j++] = vpd[(*pindex)++];
2321 phba->ProgramType[j] = 0;
2323 } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '4')) {
2324 phba->vpd_flag |= VPD_PORT;
2331 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2332 (phba->sli4_hba.pport_name_sta ==
2333 LPFC_SLI4_PPNAME_GET)) {
2337 phba->Port[j++] = vpd[(*pindex)++];
2341 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2342 (phba->sli4_hba.pport_name_sta ==
2343 LPFC_SLI4_PPNAME_NON))
2357 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2358 * @phba: pointer to lpfc hba data structure.
2359 * @vpd: pointer to the vital product data.
2360 * @len: length of the vital product data in bytes.
2362 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2363 * an array of characters. In this routine, the ModelName, ProgramType, and
2364 * ModelDesc, etc. fields of the phba data structure will be populated.
2367 * 0 - pointer to the VPD passed in is NULL
2371 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2373 uint8_t lenlo, lenhi;
2383 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2384 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2385 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2387 while (!finished && (index < (len - 4))) {
2388 switch (vpd[index]) {
2396 i = ((((unsigned short)lenhi) << 8) + lenlo);
2405 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2406 if (Length > len - index)
2407 Length = len - index;
2409 lpfc_fill_vpd(phba, vpd, Length, &index);
2425 * lpfc_get_atto_model_desc - Retrieve ATTO HBA device model name and description
2426 * @phba: pointer to lpfc hba data structure.
2427 * @mdp: pointer to the data structure to hold the derived model name.
2428 * @descp: pointer to the data structure to hold the derived description.
2430 * This routine retrieves HBA's description based on its registered PCI device
2431 * ID. The @descp passed into this function points to an array of 256 chars. It
2432 * shall be returned with the model name, maximum speed, and the host bus type.
2433 * The @mdp passed into this function points to an array of 80 chars. When the
2434 * function returns, the @mdp will be filled with the model name.
2437 lpfc_get_atto_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2439 uint16_t sub_dev_id = phba->pcidev->subsystem_device;
2440 char *model = "<Unknown>";
2443 switch (sub_dev_id) {
2444 case PCI_DEVICE_ID_CLRY_161E:
2447 case PCI_DEVICE_ID_CLRY_162E:
2450 case PCI_DEVICE_ID_CLRY_164E:
2453 case PCI_DEVICE_ID_CLRY_161P:
2456 case PCI_DEVICE_ID_CLRY_162P:
2459 case PCI_DEVICE_ID_CLRY_164P:
2462 case PCI_DEVICE_ID_CLRY_321E:
2465 case PCI_DEVICE_ID_CLRY_322E:
2468 case PCI_DEVICE_ID_CLRY_324E:
2471 case PCI_DEVICE_ID_CLRY_321P:
2474 case PCI_DEVICE_ID_CLRY_322P:
2477 case PCI_DEVICE_ID_CLRY_324P:
2480 case PCI_DEVICE_ID_TLFC_2XX2:
2484 case PCI_DEVICE_ID_TLFC_3162:
2488 case PCI_DEVICE_ID_TLFC_3322:
2497 if (mdp && mdp[0] == '\0')
2498 snprintf(mdp, 79, "%s", model);
2500 if (descp && descp[0] == '\0')
2501 snprintf(descp, 255,
2502 "ATTO %s%s, Fibre Channel Adapter Initiator, Port %s",
2503 (tbolt) ? "ThunderLink FC " : "Celerity FC-",
2509 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2510 * @phba: pointer to lpfc hba data structure.
2511 * @mdp: pointer to the data structure to hold the derived model name.
2512 * @descp: pointer to the data structure to hold the derived description.
2514 * This routine retrieves HBA's description based on its registered PCI device
2515 * ID. The @descp passed into this function points to an array of 256 chars. It
2516 * shall be returned with the model name, maximum speed, and the host bus type.
2517 * The @mdp passed into this function points to an array of 80 chars. When the
2518 * function returns, the @mdp will be filled with the model name.
2521 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2524 uint16_t dev_id = phba->pcidev->device;
2527 int oneConnect = 0; /* default is not a oneConnect */
2532 } m = {"<Unknown>", "", ""};
2534 if (mdp && mdp[0] != '\0'
2535 && descp && descp[0] != '\0')
2538 if (phba->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
2539 lpfc_get_atto_model_desc(phba, mdp, descp);
2543 if (phba->lmt & LMT_64Gb)
2545 else if (phba->lmt & LMT_32Gb)
2547 else if (phba->lmt & LMT_16Gb)
2549 else if (phba->lmt & LMT_10Gb)
2551 else if (phba->lmt & LMT_8Gb)
2553 else if (phba->lmt & LMT_4Gb)
2555 else if (phba->lmt & LMT_2Gb)
2557 else if (phba->lmt & LMT_1Gb)
2565 case PCI_DEVICE_ID_FIREFLY:
2566 m = (typeof(m)){"LP6000", "PCI",
2567 "Obsolete, Unsupported Fibre Channel Adapter"};
2569 case PCI_DEVICE_ID_SUPERFLY:
2570 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2571 m = (typeof(m)){"LP7000", "PCI", ""};
2573 m = (typeof(m)){"LP7000E", "PCI", ""};
2574 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2576 case PCI_DEVICE_ID_DRAGONFLY:
2577 m = (typeof(m)){"LP8000", "PCI",
2578 "Obsolete, Unsupported Fibre Channel Adapter"};
2580 case PCI_DEVICE_ID_CENTAUR:
2581 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2582 m = (typeof(m)){"LP9002", "PCI", ""};
2584 m = (typeof(m)){"LP9000", "PCI", ""};
2585 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2587 case PCI_DEVICE_ID_RFLY:
2588 m = (typeof(m)){"LP952", "PCI",
2589 "Obsolete, Unsupported Fibre Channel Adapter"};
2591 case PCI_DEVICE_ID_PEGASUS:
2592 m = (typeof(m)){"LP9802", "PCI-X",
2593 "Obsolete, Unsupported Fibre Channel Adapter"};
2595 case PCI_DEVICE_ID_THOR:
2596 m = (typeof(m)){"LP10000", "PCI-X",
2597 "Obsolete, Unsupported Fibre Channel Adapter"};
2599 case PCI_DEVICE_ID_VIPER:
2600 m = (typeof(m)){"LPX1000", "PCI-X",
2601 "Obsolete, Unsupported Fibre Channel Adapter"};
2603 case PCI_DEVICE_ID_PFLY:
2604 m = (typeof(m)){"LP982", "PCI-X",
2605 "Obsolete, Unsupported Fibre Channel Adapter"};
2607 case PCI_DEVICE_ID_TFLY:
2608 m = (typeof(m)){"LP1050", "PCI-X",
2609 "Obsolete, Unsupported Fibre Channel Adapter"};
2611 case PCI_DEVICE_ID_HELIOS:
2612 m = (typeof(m)){"LP11000", "PCI-X2",
2613 "Obsolete, Unsupported Fibre Channel Adapter"};
2615 case PCI_DEVICE_ID_HELIOS_SCSP:
2616 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2617 "Obsolete, Unsupported Fibre Channel Adapter"};
2619 case PCI_DEVICE_ID_HELIOS_DCSP:
2620 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2621 "Obsolete, Unsupported Fibre Channel Adapter"};
2623 case PCI_DEVICE_ID_NEPTUNE:
2624 m = (typeof(m)){"LPe1000", "PCIe",
2625 "Obsolete, Unsupported Fibre Channel Adapter"};
2627 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2628 m = (typeof(m)){"LPe1000-SP", "PCIe",
2629 "Obsolete, Unsupported Fibre Channel Adapter"};
2631 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2632 m = (typeof(m)){"LPe1002-SP", "PCIe",
2633 "Obsolete, Unsupported Fibre Channel Adapter"};
2635 case PCI_DEVICE_ID_BMID:
2636 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2638 case PCI_DEVICE_ID_BSMB:
2639 m = (typeof(m)){"LP111", "PCI-X2",
2640 "Obsolete, Unsupported Fibre Channel Adapter"};
2642 case PCI_DEVICE_ID_ZEPHYR:
2643 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2645 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2646 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2648 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2649 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2652 case PCI_DEVICE_ID_ZMID:
2653 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2655 case PCI_DEVICE_ID_ZSMB:
2656 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2658 case PCI_DEVICE_ID_LP101:
2659 m = (typeof(m)){"LP101", "PCI-X",
2660 "Obsolete, Unsupported Fibre Channel Adapter"};
2662 case PCI_DEVICE_ID_LP10000S:
2663 m = (typeof(m)){"LP10000-S", "PCI",
2664 "Obsolete, Unsupported Fibre Channel Adapter"};
2666 case PCI_DEVICE_ID_LP11000S:
2667 m = (typeof(m)){"LP11000-S", "PCI-X2",
2668 "Obsolete, Unsupported Fibre Channel Adapter"};
2670 case PCI_DEVICE_ID_LPE11000S:
2671 m = (typeof(m)){"LPe11000-S", "PCIe",
2672 "Obsolete, Unsupported Fibre Channel Adapter"};
2674 case PCI_DEVICE_ID_SAT:
2675 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2677 case PCI_DEVICE_ID_SAT_MID:
2678 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2680 case PCI_DEVICE_ID_SAT_SMB:
2681 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2683 case PCI_DEVICE_ID_SAT_DCSP:
2684 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2686 case PCI_DEVICE_ID_SAT_SCSP:
2687 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2689 case PCI_DEVICE_ID_SAT_S:
2690 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2692 case PCI_DEVICE_ID_PROTEUS_VF:
2693 m = (typeof(m)){"LPev12000", "PCIe IOV",
2694 "Obsolete, Unsupported Fibre Channel Adapter"};
2696 case PCI_DEVICE_ID_PROTEUS_PF:
2697 m = (typeof(m)){"LPev12000", "PCIe IOV",
2698 "Obsolete, Unsupported Fibre Channel Adapter"};
2700 case PCI_DEVICE_ID_PROTEUS_S:
2701 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2702 "Obsolete, Unsupported Fibre Channel Adapter"};
2704 case PCI_DEVICE_ID_TIGERSHARK:
2706 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2708 case PCI_DEVICE_ID_TOMCAT:
2710 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2712 case PCI_DEVICE_ID_FALCON:
2713 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2714 "EmulexSecure Fibre"};
2716 case PCI_DEVICE_ID_BALIUS:
2717 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2718 "Obsolete, Unsupported Fibre Channel Adapter"};
2720 case PCI_DEVICE_ID_LANCER_FC:
2721 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2723 case PCI_DEVICE_ID_LANCER_FC_VF:
2724 m = (typeof(m)){"LPe16000", "PCIe",
2725 "Obsolete, Unsupported Fibre Channel Adapter"};
2727 case PCI_DEVICE_ID_LANCER_FCOE:
2729 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2731 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2733 m = (typeof(m)){"OCe15100", "PCIe",
2734 "Obsolete, Unsupported FCoE"};
2736 case PCI_DEVICE_ID_LANCER_G6_FC:
2737 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2739 case PCI_DEVICE_ID_LANCER_G7_FC:
2740 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2742 case PCI_DEVICE_ID_LANCER_G7P_FC:
2743 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2745 case PCI_DEVICE_ID_SKYHAWK:
2746 case PCI_DEVICE_ID_SKYHAWK_VF:
2748 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2751 m = (typeof(m)){"Unknown", "", ""};
2755 if (mdp && mdp[0] == '\0')
2756 snprintf(mdp, 79,"%s", m.name);
2758 * oneConnect hba requires special processing, they are all initiators
2759 * and we put the port number on the end
2761 if (descp && descp[0] == '\0') {
2763 snprintf(descp, 255,
2764 "Emulex OneConnect %s, %s Initiator %s",
2767 else if (max_speed == 0)
2768 snprintf(descp, 255,
2770 m.name, m.bus, m.function);
2772 snprintf(descp, 255,
2773 "Emulex %s %d%s %s %s",
2774 m.name, max_speed, (GE) ? "GE" : "Gb",
2780 * lpfc_sli3_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2781 * @phba: pointer to lpfc hba data structure.
2782 * @pring: pointer to a IOCB ring.
2783 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2785 * This routine posts a given number of IOCBs with the associated DMA buffer
2786 * descriptors specified by the cnt argument to the given IOCB ring.
2789 * The number of IOCBs NOT able to be posted to the IOCB ring.
2792 lpfc_sli3_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2795 struct lpfc_iocbq *iocb;
2796 struct lpfc_dmabuf *mp1, *mp2;
2798 cnt += pring->missbufcnt;
2800 /* While there are buffers to post */
2802 /* Allocate buffer for command iocb */
2803 iocb = lpfc_sli_get_iocbq(phba);
2805 pring->missbufcnt = cnt;
2810 /* 2 buffers can be posted per command */
2811 /* Allocate buffer to post */
2812 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2814 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2815 if (!mp1 || !mp1->virt) {
2817 lpfc_sli_release_iocbq(phba, iocb);
2818 pring->missbufcnt = cnt;
2822 INIT_LIST_HEAD(&mp1->list);
2823 /* Allocate buffer to post */
2825 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2827 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2829 if (!mp2 || !mp2->virt) {
2831 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2833 lpfc_sli_release_iocbq(phba, iocb);
2834 pring->missbufcnt = cnt;
2838 INIT_LIST_HEAD(&mp2->list);
2843 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2844 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2845 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2846 icmd->ulpBdeCount = 1;
2849 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2850 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2851 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2853 icmd->ulpBdeCount = 2;
2856 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2859 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2861 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2865 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2869 lpfc_sli_release_iocbq(phba, iocb);
2870 pring->missbufcnt = cnt;
2873 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2875 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2877 pring->missbufcnt = 0;
2882 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2883 * @phba: pointer to lpfc hba data structure.
2885 * This routine posts initial receive IOCB buffers to the ELS ring. The
2886 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2887 * set to 64 IOCBs. SLI3 only.
2890 * 0 - success (currently always success)
2893 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2895 struct lpfc_sli *psli = &phba->sli;
2897 /* Ring 0, ELS / CT buffers */
2898 lpfc_sli3_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2899 /* Ring 2 - FCP no buffers needed */
2904 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2907 * lpfc_sha_init - Set up initial array of hash table entries
2908 * @HashResultPointer: pointer to an array as hash table.
2910 * This routine sets up the initial values to the array of hash table entries
2914 lpfc_sha_init(uint32_t * HashResultPointer)
2916 HashResultPointer[0] = 0x67452301;
2917 HashResultPointer[1] = 0xEFCDAB89;
2918 HashResultPointer[2] = 0x98BADCFE;
2919 HashResultPointer[3] = 0x10325476;
2920 HashResultPointer[4] = 0xC3D2E1F0;
2924 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2925 * @HashResultPointer: pointer to an initial/result hash table.
2926 * @HashWorkingPointer: pointer to an working hash table.
2928 * This routine iterates an initial hash table pointed by @HashResultPointer
2929 * with the values from the working hash table pointeed by @HashWorkingPointer.
2930 * The results are putting back to the initial hash table, returned through
2931 * the @HashResultPointer as the result hash table.
2934 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2938 uint32_t A, B, C, D, E;
2941 HashWorkingPointer[t] =
2943 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2945 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2946 } while (++t <= 79);
2948 A = HashResultPointer[0];
2949 B = HashResultPointer[1];
2950 C = HashResultPointer[2];
2951 D = HashResultPointer[3];
2952 E = HashResultPointer[4];
2956 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2957 } else if (t < 40) {
2958 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2959 } else if (t < 60) {
2960 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2962 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2964 TEMP += S(5, A) + E + HashWorkingPointer[t];
2970 } while (++t <= 79);
2972 HashResultPointer[0] += A;
2973 HashResultPointer[1] += B;
2974 HashResultPointer[2] += C;
2975 HashResultPointer[3] += D;
2976 HashResultPointer[4] += E;
2981 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2982 * @RandomChallenge: pointer to the entry of host challenge random number array.
2983 * @HashWorking: pointer to the entry of the working hash array.
2985 * This routine calculates the working hash array referred by @HashWorking
2986 * from the challenge random numbers associated with the host, referred by
2987 * @RandomChallenge. The result is put into the entry of the working hash
2988 * array and returned by reference through @HashWorking.
2991 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2993 *HashWorking = (*RandomChallenge ^ *HashWorking);
2997 * lpfc_hba_init - Perform special handling for LC HBA initialization
2998 * @phba: pointer to lpfc hba data structure.
2999 * @hbainit: pointer to an array of unsigned 32-bit integers.
3001 * This routine performs the special handling for LC HBA initialization.
3004 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
3007 uint32_t *HashWorking;
3008 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
3010 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
3014 HashWorking[0] = HashWorking[78] = *pwwnn++;
3015 HashWorking[1] = HashWorking[79] = *pwwnn;
3017 for (t = 0; t < 7; t++)
3018 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
3020 lpfc_sha_init(hbainit);
3021 lpfc_sha_iterate(hbainit, HashWorking);
3026 * lpfc_cleanup - Performs vport cleanups before deleting a vport
3027 * @vport: pointer to a virtual N_Port data structure.
3029 * This routine performs the necessary cleanups before deleting the @vport.
3030 * It invokes the discovery state machine to perform necessary state
3031 * transitions and to release the ndlps associated with the @vport. Note,
3032 * the physical port is treated as @vport 0.
3035 lpfc_cleanup(struct lpfc_vport *vport)
3037 struct lpfc_hba *phba = vport->phba;
3038 struct lpfc_nodelist *ndlp, *next_ndlp;
3041 if (phba->link_state > LPFC_LINK_DOWN)
3042 lpfc_port_link_failure(vport);
3044 /* Clean up VMID resources */
3045 if (lpfc_is_vmid_enabled(phba))
3046 lpfc_vmid_vport_cleanup(vport);
3048 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3049 if (vport->port_type != LPFC_PHYSICAL_PORT &&
3050 ndlp->nlp_DID == Fabric_DID) {
3051 /* Just free up ndlp with Fabric_DID for vports */
3056 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
3057 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3062 /* Fabric Ports not in UNMAPPED state are cleaned up in the
3065 if (ndlp->nlp_type & NLP_FABRIC &&
3066 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
3067 lpfc_disc_state_machine(vport, ndlp, NULL,
3068 NLP_EVT_DEVICE_RECOVERY);
3070 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
3071 lpfc_disc_state_machine(vport, ndlp, NULL,
3075 /* This is a special case flush to return all
3076 * IOs before entering this loop. There are
3077 * two points in the code where a flush is
3078 * avoided if the FC_UNLOADING flag is set.
3079 * one is in the multipool destroy,
3080 * (this prevents a crash) and the other is
3081 * in the nvme abort handler, ( also prevents
3082 * a crash). Both of these exceptions are
3083 * cases where the slot is still accessible.
3084 * The flush here is only when the pci slot
3087 if (vport->load_flag & FC_UNLOADING &&
3088 pci_channel_offline(phba->pcidev))
3089 lpfc_sli_flush_io_rings(vport->phba);
3091 /* At this point, ALL ndlp's should be gone
3092 * because of the previous NLP_EVT_DEVICE_RM.
3093 * Lets wait for this to happen, if needed.
3095 while (!list_empty(&vport->fc_nodes)) {
3097 lpfc_printf_vlog(vport, KERN_ERR,
3099 "0233 Nodelist not empty\n");
3100 list_for_each_entry_safe(ndlp, next_ndlp,
3101 &vport->fc_nodes, nlp_listp) {
3102 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
3104 "0282 did:x%x ndlp:x%px "
3105 "refcnt:%d xflags x%x nflag x%x\n",
3106 ndlp->nlp_DID, (void *)ndlp,
3107 kref_read(&ndlp->kref),
3108 ndlp->fc4_xpt_flags,
3114 /* Wait for any activity on ndlps to settle */
3117 lpfc_cleanup_vports_rrqs(vport, NULL);
3121 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
3122 * @vport: pointer to a virtual N_Port data structure.
3124 * This routine stops all the timers associated with a @vport. This function
3125 * is invoked before disabling or deleting a @vport. Note that the physical
3126 * port is treated as @vport 0.
3129 lpfc_stop_vport_timers(struct lpfc_vport *vport)
3131 del_timer_sync(&vport->els_tmofunc);
3132 del_timer_sync(&vport->delayed_disc_tmo);
3133 lpfc_can_disctmo(vport);
3138 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3139 * @phba: pointer to lpfc hba data structure.
3141 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
3142 * caller of this routine should already hold the host lock.
3145 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3147 /* Clear pending FCF rediscovery wait flag */
3148 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3150 /* Now, try to stop the timer */
3151 del_timer(&phba->fcf.redisc_wait);
3155 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3156 * @phba: pointer to lpfc hba data structure.
3158 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3159 * checks whether the FCF rediscovery wait timer is pending with the host
3160 * lock held before proceeding with disabling the timer and clearing the
3161 * wait timer pendig flag.
3164 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3166 spin_lock_irq(&phba->hbalock);
3167 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3168 /* FCF rediscovery timer already fired or stopped */
3169 spin_unlock_irq(&phba->hbalock);
3172 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3173 /* Clear failover in progress flags */
3174 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
3175 spin_unlock_irq(&phba->hbalock);
3179 * lpfc_cmf_stop - Stop CMF processing
3180 * @phba: pointer to lpfc hba data structure.
3182 * This is called when the link goes down or if CMF mode is turned OFF.
3183 * It is also called when going offline or unloaded just before the
3184 * congestion info buffer is unregistered.
3187 lpfc_cmf_stop(struct lpfc_hba *phba)
3190 struct lpfc_cgn_stat *cgs;
3192 /* We only do something if CMF is enabled */
3193 if (!phba->sli4_hba.pc_sli4_params.cmf)
3196 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3197 "6221 Stop CMF / Cancel Timer\n");
3199 /* Cancel the CMF timer */
3200 hrtimer_cancel(&phba->cmf_timer);
3202 /* Zero CMF counters */
3203 atomic_set(&phba->cmf_busy, 0);
3204 for_each_present_cpu(cpu) {
3205 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3206 atomic64_set(&cgs->total_bytes, 0);
3207 atomic64_set(&cgs->rcv_bytes, 0);
3208 atomic_set(&cgs->rx_io_cnt, 0);
3209 atomic64_set(&cgs->rx_latency, 0);
3211 atomic_set(&phba->cmf_bw_wait, 0);
3213 /* Resume any blocked IO - Queue unblock on workqueue */
3214 queue_work(phba->wq, &phba->unblock_request_work);
3217 static inline uint64_t
3218 lpfc_get_max_line_rate(struct lpfc_hba *phba)
3220 uint64_t rate = lpfc_sli_port_speed_get(phba);
3222 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3226 lpfc_cmf_signal_init(struct lpfc_hba *phba)
3228 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3229 "6223 Signal CMF init\n");
3231 /* Use the new fc_linkspeed to recalculate */
3232 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3233 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3234 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3235 phba->cmf_interval_rate, 1000);
3236 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3238 /* This is a signal to firmware to sync up CMF BW with link speed */
3239 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3243 * lpfc_cmf_start - Start CMF processing
3244 * @phba: pointer to lpfc hba data structure.
3246 * This is called when the link comes up or if CMF mode is turned OFF
3247 * to Monitor or Managed.
3250 lpfc_cmf_start(struct lpfc_hba *phba)
3252 struct lpfc_cgn_stat *cgs;
3255 /* We only do something if CMF is enabled */
3256 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3257 phba->cmf_active_mode == LPFC_CFG_OFF)
3260 /* Reinitialize congestion buffer info */
3261 lpfc_init_congestion_buf(phba);
3263 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3264 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3265 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3266 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3268 atomic_set(&phba->cmf_busy, 0);
3269 for_each_present_cpu(cpu) {
3270 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3271 atomic64_set(&cgs->total_bytes, 0);
3272 atomic64_set(&cgs->rcv_bytes, 0);
3273 atomic_set(&cgs->rx_io_cnt, 0);
3274 atomic64_set(&cgs->rx_latency, 0);
3276 phba->cmf_latency.tv_sec = 0;
3277 phba->cmf_latency.tv_nsec = 0;
3279 lpfc_cmf_signal_init(phba);
3281 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3282 "6222 Start CMF / Timer\n");
3284 phba->cmf_timer_cnt = 0;
3285 hrtimer_start(&phba->cmf_timer,
3286 ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
3288 /* Setup for latency check in IO cmpl routines */
3289 ktime_get_real_ts64(&phba->cmf_latency);
3291 atomic_set(&phba->cmf_bw_wait, 0);
3292 atomic_set(&phba->cmf_stop_io, 0);
3296 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
3297 * @phba: pointer to lpfc hba data structure.
3299 * This routine stops all the timers associated with a HBA. This function is
3300 * invoked before either putting a HBA offline or unloading the driver.
3303 lpfc_stop_hba_timers(struct lpfc_hba *phba)
3306 lpfc_stop_vport_timers(phba->pport);
3307 cancel_delayed_work_sync(&phba->eq_delay_work);
3308 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
3309 del_timer_sync(&phba->sli.mbox_tmo);
3310 del_timer_sync(&phba->fabric_block_timer);
3311 del_timer_sync(&phba->eratt_poll);
3312 del_timer_sync(&phba->hb_tmofunc);
3313 if (phba->sli_rev == LPFC_SLI_REV4) {
3314 del_timer_sync(&phba->rrq_tmr);
3315 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
3317 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
3319 switch (phba->pci_dev_grp) {
3320 case LPFC_PCI_DEV_LP:
3321 /* Stop any LightPulse device specific driver timers */
3322 del_timer_sync(&phba->fcp_poll_timer);
3324 case LPFC_PCI_DEV_OC:
3325 /* Stop any OneConnect device specific driver timers */
3326 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3329 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3330 "0297 Invalid device group (x%x)\n",
3338 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3339 * @phba: pointer to lpfc hba data structure.
3340 * @mbx_action: flag for mailbox no wait action.
3342 * This routine marks a HBA's management interface as blocked. Once the HBA's
3343 * management interface is marked as blocked, all the user space access to
3344 * the HBA, whether they are from sysfs interface or libdfc interface will
3345 * all be blocked. The HBA is set to block the management interface when the
3346 * driver prepares the HBA interface for online or offline.
3349 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
3351 unsigned long iflag;
3352 uint8_t actcmd = MBX_HEARTBEAT;
3353 unsigned long timeout;
3355 spin_lock_irqsave(&phba->hbalock, iflag);
3356 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
3357 spin_unlock_irqrestore(&phba->hbalock, iflag);
3358 if (mbx_action == LPFC_MBX_NO_WAIT)
3360 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3361 spin_lock_irqsave(&phba->hbalock, iflag);
3362 if (phba->sli.mbox_active) {
3363 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3364 /* Determine how long we might wait for the active mailbox
3365 * command to be gracefully completed by firmware.
3367 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3368 phba->sli.mbox_active) * 1000) + jiffies;
3370 spin_unlock_irqrestore(&phba->hbalock, iflag);
3372 /* Wait for the outstnading mailbox command to complete */
3373 while (phba->sli.mbox_active) {
3374 /* Check active mailbox complete status every 2ms */
3376 if (time_after(jiffies, timeout)) {
3377 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3378 "2813 Mgmt IO is Blocked %x "
3379 "- mbox cmd %x still active\n",
3380 phba->sli.sli_flag, actcmd);
3387 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3388 * @phba: pointer to lpfc hba data structure.
3390 * Allocate RPIs for all active remote nodes. This is needed whenever
3391 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3392 * is to fixup the temporary rpi assignments.
3395 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3397 struct lpfc_nodelist *ndlp, *next_ndlp;
3398 struct lpfc_vport **vports;
3401 if (phba->sli_rev != LPFC_SLI_REV4)
3404 vports = lpfc_create_vport_work_array(phba);
3408 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3409 if (vports[i]->load_flag & FC_UNLOADING)
3412 list_for_each_entry_safe(ndlp, next_ndlp,
3413 &vports[i]->fc_nodes,
3415 rpi = lpfc_sli4_alloc_rpi(phba);
3416 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3417 /* TODO print log? */
3420 ndlp->nlp_rpi = rpi;
3421 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3422 LOG_NODE | LOG_DISCOVERY,
3423 "0009 Assign RPI x%x to ndlp x%px "
3424 "DID:x%06x flg:x%x\n",
3425 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3429 lpfc_destroy_vport_work_array(phba, vports);
3433 * lpfc_create_expedite_pool - create expedite pool
3434 * @phba: pointer to lpfc hba data structure.
3436 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3437 * to expedite pool. Mark them as expedite.
3439 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3441 struct lpfc_sli4_hdw_queue *qp;
3442 struct lpfc_io_buf *lpfc_ncmd;
3443 struct lpfc_io_buf *lpfc_ncmd_next;
3444 struct lpfc_epd_pool *epd_pool;
3445 unsigned long iflag;
3447 epd_pool = &phba->epd_pool;
3448 qp = &phba->sli4_hba.hdwq[0];
3450 spin_lock_init(&epd_pool->lock);
3451 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3452 spin_lock(&epd_pool->lock);
3453 INIT_LIST_HEAD(&epd_pool->list);
3454 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3455 &qp->lpfc_io_buf_list_put, list) {
3456 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3457 lpfc_ncmd->expedite = true;
3460 if (epd_pool->count >= XRI_BATCH)
3463 spin_unlock(&epd_pool->lock);
3464 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3468 * lpfc_destroy_expedite_pool - destroy expedite pool
3469 * @phba: pointer to lpfc hba data structure.
3471 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3472 * of HWQ 0. Clear the mark.
3474 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3476 struct lpfc_sli4_hdw_queue *qp;
3477 struct lpfc_io_buf *lpfc_ncmd;
3478 struct lpfc_io_buf *lpfc_ncmd_next;
3479 struct lpfc_epd_pool *epd_pool;
3480 unsigned long iflag;
3482 epd_pool = &phba->epd_pool;
3483 qp = &phba->sli4_hba.hdwq[0];
3485 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3486 spin_lock(&epd_pool->lock);
3487 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3488 &epd_pool->list, list) {
3489 list_move_tail(&lpfc_ncmd->list,
3490 &qp->lpfc_io_buf_list_put);
3491 lpfc_ncmd->flags = false;
3495 spin_unlock(&epd_pool->lock);
3496 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3500 * lpfc_create_multixri_pools - create multi-XRI pools
3501 * @phba: pointer to lpfc hba data structure.
3503 * This routine initialize public, private per HWQ. Then, move XRIs from
3504 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3507 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3512 struct lpfc_io_buf *lpfc_ncmd;
3513 struct lpfc_io_buf *lpfc_ncmd_next;
3514 unsigned long iflag;
3515 struct lpfc_sli4_hdw_queue *qp;
3516 struct lpfc_multixri_pool *multixri_pool;
3517 struct lpfc_pbl_pool *pbl_pool;
3518 struct lpfc_pvt_pool *pvt_pool;
3520 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3521 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3522 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3523 phba->sli4_hba.io_xri_cnt);
3525 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3526 lpfc_create_expedite_pool(phba);
3528 hwq_count = phba->cfg_hdw_queue;
3529 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3531 for (i = 0; i < hwq_count; i++) {
3532 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3534 if (!multixri_pool) {
3535 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3536 "1238 Failed to allocate memory for "
3539 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3540 lpfc_destroy_expedite_pool(phba);
3544 qp = &phba->sli4_hba.hdwq[j];
3545 kfree(qp->p_multixri_pool);
3548 phba->cfg_xri_rebalancing = 0;
3552 qp = &phba->sli4_hba.hdwq[i];
3553 qp->p_multixri_pool = multixri_pool;
3555 multixri_pool->xri_limit = count_per_hwq;
3556 multixri_pool->rrb_next_hwqid = i;
3558 /* Deal with public free xri pool */
3559 pbl_pool = &multixri_pool->pbl_pool;
3560 spin_lock_init(&pbl_pool->lock);
3561 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3562 spin_lock(&pbl_pool->lock);
3563 INIT_LIST_HEAD(&pbl_pool->list);
3564 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3565 &qp->lpfc_io_buf_list_put, list) {
3566 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3570 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3571 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3572 pbl_pool->count, i);
3573 spin_unlock(&pbl_pool->lock);
3574 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3576 /* Deal with private free xri pool */
3577 pvt_pool = &multixri_pool->pvt_pool;
3578 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3579 pvt_pool->low_watermark = XRI_BATCH;
3580 spin_lock_init(&pvt_pool->lock);
3581 spin_lock_irqsave(&pvt_pool->lock, iflag);
3582 INIT_LIST_HEAD(&pvt_pool->list);
3583 pvt_pool->count = 0;
3584 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3589 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3590 * @phba: pointer to lpfc hba data structure.
3592 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3594 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3598 struct lpfc_io_buf *lpfc_ncmd;
3599 struct lpfc_io_buf *lpfc_ncmd_next;
3600 unsigned long iflag;
3601 struct lpfc_sli4_hdw_queue *qp;
3602 struct lpfc_multixri_pool *multixri_pool;
3603 struct lpfc_pbl_pool *pbl_pool;
3604 struct lpfc_pvt_pool *pvt_pool;
3606 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3607 lpfc_destroy_expedite_pool(phba);
3609 if (!(phba->pport->load_flag & FC_UNLOADING))
3610 lpfc_sli_flush_io_rings(phba);
3612 hwq_count = phba->cfg_hdw_queue;
3614 for (i = 0; i < hwq_count; i++) {
3615 qp = &phba->sli4_hba.hdwq[i];
3616 multixri_pool = qp->p_multixri_pool;
3620 qp->p_multixri_pool = NULL;
3622 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3624 /* Deal with public free xri pool */
3625 pbl_pool = &multixri_pool->pbl_pool;
3626 spin_lock(&pbl_pool->lock);
3628 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3629 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3630 pbl_pool->count, i);
3632 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3633 &pbl_pool->list, list) {
3634 list_move_tail(&lpfc_ncmd->list,
3635 &qp->lpfc_io_buf_list_put);
3640 INIT_LIST_HEAD(&pbl_pool->list);
3641 pbl_pool->count = 0;
3643 spin_unlock(&pbl_pool->lock);
3645 /* Deal with private free xri pool */
3646 pvt_pool = &multixri_pool->pvt_pool;
3647 spin_lock(&pvt_pool->lock);
3649 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3650 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3651 pvt_pool->count, i);
3653 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3654 &pvt_pool->list, list) {
3655 list_move_tail(&lpfc_ncmd->list,
3656 &qp->lpfc_io_buf_list_put);
3661 INIT_LIST_HEAD(&pvt_pool->list);
3662 pvt_pool->count = 0;
3664 spin_unlock(&pvt_pool->lock);
3665 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3667 kfree(multixri_pool);
3672 * lpfc_online - Initialize and bring a HBA online
3673 * @phba: pointer to lpfc hba data structure.
3675 * This routine initializes the HBA and brings a HBA online. During this
3676 * process, the management interface is blocked to prevent user space access
3677 * to the HBA interfering with the driver initialization.
3684 lpfc_online(struct lpfc_hba *phba)
3686 struct lpfc_vport *vport;
3687 struct lpfc_vport **vports;
3689 bool vpis_cleared = false;
3693 vport = phba->pport;
3695 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3698 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3699 "0458 Bring Adapter online\n");
3701 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3703 if (phba->sli_rev == LPFC_SLI_REV4) {
3704 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3705 lpfc_unblock_mgmt_io(phba);
3708 spin_lock_irq(&phba->hbalock);
3709 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3710 vpis_cleared = true;
3711 spin_unlock_irq(&phba->hbalock);
3713 /* Reestablish the local initiator port.
3714 * The offline process destroyed the previous lport.
3716 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3717 !phba->nvmet_support) {
3718 error = lpfc_nvme_create_localport(phba->pport);
3720 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3721 "6132 NVME restore reg failed "
3722 "on nvmei error x%x\n", error);
3725 lpfc_sli_queue_init(phba);
3726 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3727 lpfc_unblock_mgmt_io(phba);
3732 vports = lpfc_create_vport_work_array(phba);
3733 if (vports != NULL) {
3734 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3735 struct Scsi_Host *shost;
3736 shost = lpfc_shost_from_vport(vports[i]);
3737 spin_lock_irq(shost->host_lock);
3738 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3739 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3740 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3741 if (phba->sli_rev == LPFC_SLI_REV4) {
3742 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3743 if ((vpis_cleared) &&
3744 (vports[i]->port_type !=
3745 LPFC_PHYSICAL_PORT))
3748 spin_unlock_irq(shost->host_lock);
3751 lpfc_destroy_vport_work_array(phba, vports);
3753 if (phba->cfg_xri_rebalancing)
3754 lpfc_create_multixri_pools(phba);
3756 lpfc_cpuhp_add(phba);
3758 lpfc_unblock_mgmt_io(phba);
3763 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3764 * @phba: pointer to lpfc hba data structure.
3766 * This routine marks a HBA's management interface as not blocked. Once the
3767 * HBA's management interface is marked as not blocked, all the user space
3768 * access to the HBA, whether they are from sysfs interface or libdfc
3769 * interface will be allowed. The HBA is set to block the management interface
3770 * when the driver prepares the HBA interface for online or offline and then
3771 * set to unblock the management interface afterwards.
3774 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3776 unsigned long iflag;
3778 spin_lock_irqsave(&phba->hbalock, iflag);
3779 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3780 spin_unlock_irqrestore(&phba->hbalock, iflag);
3784 * lpfc_offline_prep - Prepare a HBA to be brought offline
3785 * @phba: pointer to lpfc hba data structure.
3786 * @mbx_action: flag for mailbox shutdown action.
3788 * This routine is invoked to prepare a HBA to be brought offline. It performs
3789 * unregistration login to all the nodes on all vports and flushes the mailbox
3790 * queue to make it ready to be brought offline.
3793 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3795 struct lpfc_vport *vport = phba->pport;
3796 struct lpfc_nodelist *ndlp, *next_ndlp;
3797 struct lpfc_vport **vports;
3798 struct Scsi_Host *shost;
3803 if (vport->fc_flag & FC_OFFLINE_MODE)
3806 lpfc_block_mgmt_io(phba, mbx_action);
3808 lpfc_linkdown(phba);
3810 offline = pci_channel_offline(phba->pcidev);
3811 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
3813 /* Issue an unreg_login to all nodes on all vports */
3814 vports = lpfc_create_vport_work_array(phba);
3815 if (vports != NULL) {
3816 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3817 if (vports[i]->load_flag & FC_UNLOADING)
3819 shost = lpfc_shost_from_vport(vports[i]);
3820 spin_lock_irq(shost->host_lock);
3821 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3822 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3823 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3824 spin_unlock_irq(shost->host_lock);
3826 shost = lpfc_shost_from_vport(vports[i]);
3827 list_for_each_entry_safe(ndlp, next_ndlp,
3828 &vports[i]->fc_nodes,
3831 spin_lock_irq(&ndlp->lock);
3832 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3833 spin_unlock_irq(&ndlp->lock);
3835 if (offline || hba_pci_err) {
3836 spin_lock_irq(&ndlp->lock);
3837 ndlp->nlp_flag &= ~(NLP_UNREG_INP |
3838 NLP_RPI_REGISTERED);
3839 spin_unlock_irq(&ndlp->lock);
3840 if (phba->sli_rev == LPFC_SLI_REV4)
3841 lpfc_sli_rpi_release(vports[i],
3844 lpfc_unreg_rpi(vports[i], ndlp);
3847 * Whenever an SLI4 port goes offline, free the
3848 * RPI. Get a new RPI when the adapter port
3849 * comes back online.
3851 if (phba->sli_rev == LPFC_SLI_REV4) {
3852 lpfc_printf_vlog(vports[i], KERN_INFO,
3853 LOG_NODE | LOG_DISCOVERY,
3854 "0011 Free RPI x%x on "
3855 "ndlp: x%px did x%x\n",
3856 ndlp->nlp_rpi, ndlp,
3858 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3859 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3862 if (ndlp->nlp_type & NLP_FABRIC) {
3863 lpfc_disc_state_machine(vports[i], ndlp,
3864 NULL, NLP_EVT_DEVICE_RECOVERY);
3866 /* Don't remove the node unless the node
3867 * has been unregistered with the
3868 * transport, and we're not in recovery
3869 * before dev_loss_tmo triggered.
3870 * Otherwise, let dev_loss take care of
3873 if (!(ndlp->save_flags &
3874 NLP_IN_RECOV_POST_DEV_LOSS) &&
3875 !(ndlp->fc4_xpt_flags &
3876 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3877 lpfc_disc_state_machine
3885 lpfc_destroy_vport_work_array(phba, vports);
3887 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3890 flush_workqueue(phba->wq);
3894 * lpfc_offline - Bring a HBA offline
3895 * @phba: pointer to lpfc hba data structure.
3897 * This routine actually brings a HBA offline. It stops all the timers
3898 * associated with the HBA, brings down the SLI layer, and eventually
3899 * marks the HBA as in offline state for the upper layer protocol.
3902 lpfc_offline(struct lpfc_hba *phba)
3904 struct Scsi_Host *shost;
3905 struct lpfc_vport **vports;
3908 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3911 /* stop port and all timers associated with this hba */
3912 lpfc_stop_port(phba);
3914 /* Tear down the local and target port registrations. The
3915 * nvme transports need to cleanup.
3917 lpfc_nvmet_destroy_targetport(phba);
3918 lpfc_nvme_destroy_localport(phba->pport);
3920 vports = lpfc_create_vport_work_array(phba);
3922 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3923 lpfc_stop_vport_timers(vports[i]);
3924 lpfc_destroy_vport_work_array(phba, vports);
3925 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3926 "0460 Bring Adapter offline\n");
3927 /* Bring down the SLI Layer and cleanup. The HBA is offline
3929 lpfc_sli_hba_down(phba);
3930 spin_lock_irq(&phba->hbalock);
3932 spin_unlock_irq(&phba->hbalock);
3933 vports = lpfc_create_vport_work_array(phba);
3935 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3936 shost = lpfc_shost_from_vport(vports[i]);
3937 spin_lock_irq(shost->host_lock);
3938 vports[i]->work_port_events = 0;
3939 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3940 spin_unlock_irq(shost->host_lock);
3942 lpfc_destroy_vport_work_array(phba, vports);
3943 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3946 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3947 __lpfc_cpuhp_remove(phba);
3949 if (phba->cfg_xri_rebalancing)
3950 lpfc_destroy_multixri_pools(phba);
3954 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3955 * @phba: pointer to lpfc hba data structure.
3957 * This routine is to free all the SCSI buffers and IOCBs from the driver
3958 * list back to kernel. It is called from lpfc_pci_remove_one to free
3959 * the internal resources before the device is removed from the system.
3962 lpfc_scsi_free(struct lpfc_hba *phba)
3964 struct lpfc_io_buf *sb, *sb_next;
3966 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3969 spin_lock_irq(&phba->hbalock);
3971 /* Release all the lpfc_scsi_bufs maintained by this host. */
3973 spin_lock(&phba->scsi_buf_list_put_lock);
3974 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3976 list_del(&sb->list);
3977 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3980 phba->total_scsi_bufs--;
3982 spin_unlock(&phba->scsi_buf_list_put_lock);
3984 spin_lock(&phba->scsi_buf_list_get_lock);
3985 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3987 list_del(&sb->list);
3988 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3991 phba->total_scsi_bufs--;
3993 spin_unlock(&phba->scsi_buf_list_get_lock);
3994 spin_unlock_irq(&phba->hbalock);
3998 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3999 * @phba: pointer to lpfc hba data structure.
4001 * This routine is to free all the IO buffers and IOCBs from the driver
4002 * list back to kernel. It is called from lpfc_pci_remove_one to free
4003 * the internal resources before the device is removed from the system.
4006 lpfc_io_free(struct lpfc_hba *phba)
4008 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
4009 struct lpfc_sli4_hdw_queue *qp;
4012 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4013 qp = &phba->sli4_hba.hdwq[idx];
4014 /* Release all the lpfc_nvme_bufs maintained by this host. */
4015 spin_lock(&qp->io_buf_list_put_lock);
4016 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4017 &qp->lpfc_io_buf_list_put,
4019 list_del(&lpfc_ncmd->list);
4021 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4022 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4023 if (phba->cfg_xpsgl && !phba->nvmet_support)
4024 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
4025 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
4027 qp->total_io_bufs--;
4029 spin_unlock(&qp->io_buf_list_put_lock);
4031 spin_lock(&qp->io_buf_list_get_lock);
4032 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4033 &qp->lpfc_io_buf_list_get,
4035 list_del(&lpfc_ncmd->list);
4037 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4038 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4039 if (phba->cfg_xpsgl && !phba->nvmet_support)
4040 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
4041 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
4043 qp->total_io_bufs--;
4045 spin_unlock(&qp->io_buf_list_get_lock);
4050 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
4051 * @phba: pointer to lpfc hba data structure.
4053 * This routine first calculates the sizes of the current els and allocated
4054 * scsi sgl lists, and then goes through all sgls to updates the physical
4055 * XRIs assigned due to port function reset. During port initialization, the
4056 * current els and allocated scsi sgl lists are 0s.
4059 * 0 - successful (for now, it always returns 0)
4062 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
4064 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4065 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4066 LIST_HEAD(els_sgl_list);
4070 * update on pci function's els xri-sgl list
4072 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4074 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
4075 /* els xri-sgl expanded */
4076 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
4077 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4078 "3157 ELS xri-sgl count increased from "
4079 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4081 /* allocate the additional els sgls */
4082 for (i = 0; i < xri_cnt; i++) {
4083 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4085 if (sglq_entry == NULL) {
4086 lpfc_printf_log(phba, KERN_ERR,
4088 "2562 Failure to allocate an "
4089 "ELS sgl entry:%d\n", i);
4093 sglq_entry->buff_type = GEN_BUFF_TYPE;
4094 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
4096 if (sglq_entry->virt == NULL) {
4098 lpfc_printf_log(phba, KERN_ERR,
4100 "2563 Failure to allocate an "
4101 "ELS mbuf:%d\n", i);
4105 sglq_entry->sgl = sglq_entry->virt;
4106 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
4107 sglq_entry->state = SGL_FREED;
4108 list_add_tail(&sglq_entry->list, &els_sgl_list);
4110 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4111 list_splice_init(&els_sgl_list,
4112 &phba->sli4_hba.lpfc_els_sgl_list);
4113 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4114 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
4115 /* els xri-sgl shrinked */
4116 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
4117 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4118 "3158 ELS xri-sgl count decreased from "
4119 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
4121 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
4122 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
4124 /* release extra els sgls from list */
4125 for (i = 0; i < xri_cnt; i++) {
4126 list_remove_head(&els_sgl_list,
4127 sglq_entry, struct lpfc_sglq, list);
4129 __lpfc_mbuf_free(phba, sglq_entry->virt,
4134 list_splice_init(&els_sgl_list,
4135 &phba->sli4_hba.lpfc_els_sgl_list);
4136 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
4138 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4139 "3163 ELS xri-sgl count unchanged: %d\n",
4141 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
4143 /* update xris to els sgls on the list */
4145 sglq_entry_next = NULL;
4146 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4147 &phba->sli4_hba.lpfc_els_sgl_list, list) {
4148 lxri = lpfc_sli4_next_xritag(phba);
4149 if (lxri == NO_XRI) {
4150 lpfc_printf_log(phba, KERN_ERR,
4152 "2400 Failed to allocate xri for "
4157 sglq_entry->sli4_lxritag = lxri;
4158 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4163 lpfc_free_els_sgl_list(phba);
4168 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
4169 * @phba: pointer to lpfc hba data structure.
4171 * This routine first calculates the sizes of the current els and allocated
4172 * scsi sgl lists, and then goes through all sgls to updates the physical
4173 * XRIs assigned due to port function reset. During port initialization, the
4174 * current els and allocated scsi sgl lists are 0s.
4177 * 0 - successful (for now, it always returns 0)
4180 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4182 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4183 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4184 uint16_t nvmet_xri_cnt;
4185 LIST_HEAD(nvmet_sgl_list);
4189 * update on pci function's nvmet xri-sgl list
4191 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4193 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4194 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4195 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4196 /* els xri-sgl expanded */
4197 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4198 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4199 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4200 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4201 /* allocate the additional nvmet sgls */
4202 for (i = 0; i < xri_cnt; i++) {
4203 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4205 if (sglq_entry == NULL) {
4206 lpfc_printf_log(phba, KERN_ERR,
4208 "6303 Failure to allocate an "
4209 "NVMET sgl entry:%d\n", i);
4213 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4214 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4216 if (sglq_entry->virt == NULL) {
4218 lpfc_printf_log(phba, KERN_ERR,
4220 "6304 Failure to allocate an "
4221 "NVMET buf:%d\n", i);
4225 sglq_entry->sgl = sglq_entry->virt;
4226 memset(sglq_entry->sgl, 0,
4227 phba->cfg_sg_dma_buf_size);
4228 sglq_entry->state = SGL_FREED;
4229 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4231 spin_lock_irq(&phba->hbalock);
4232 spin_lock(&phba->sli4_hba.sgl_list_lock);
4233 list_splice_init(&nvmet_sgl_list,
4234 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4235 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4236 spin_unlock_irq(&phba->hbalock);
4237 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4238 /* nvmet xri-sgl shrunk */
4239 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4240 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4241 "6305 NVMET xri-sgl count decreased from "
4242 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4244 spin_lock_irq(&phba->hbalock);
4245 spin_lock(&phba->sli4_hba.sgl_list_lock);
4246 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4248 /* release extra nvmet sgls from list */
4249 for (i = 0; i < xri_cnt; i++) {
4250 list_remove_head(&nvmet_sgl_list,
4251 sglq_entry, struct lpfc_sglq, list);
4253 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4258 list_splice_init(&nvmet_sgl_list,
4259 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4260 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4261 spin_unlock_irq(&phba->hbalock);
4263 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4264 "6306 NVMET xri-sgl count unchanged: %d\n",
4266 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4268 /* update xris to nvmet sgls on the list */
4270 sglq_entry_next = NULL;
4271 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4272 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4273 lxri = lpfc_sli4_next_xritag(phba);
4274 if (lxri == NO_XRI) {
4275 lpfc_printf_log(phba, KERN_ERR,
4277 "6307 Failed to allocate xri for "
4282 sglq_entry->sli4_lxritag = lxri;
4283 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4288 lpfc_free_nvmet_sgl_list(phba);
4293 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4296 struct lpfc_sli4_hdw_queue *qp;
4297 struct lpfc_io_buf *lpfc_cmd;
4298 struct lpfc_io_buf *iobufp, *prev_iobufp;
4299 int idx, cnt, xri, inserted;
4302 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4303 qp = &phba->sli4_hba.hdwq[idx];
4304 spin_lock_irq(&qp->io_buf_list_get_lock);
4305 spin_lock(&qp->io_buf_list_put_lock);
4307 /* Take everything off the get and put lists */
4308 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4309 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4310 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4311 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4312 cnt += qp->get_io_bufs + qp->put_io_bufs;
4313 qp->get_io_bufs = 0;
4314 qp->put_io_bufs = 0;
4315 qp->total_io_bufs = 0;
4316 spin_unlock(&qp->io_buf_list_put_lock);
4317 spin_unlock_irq(&qp->io_buf_list_get_lock);
4321 * Take IO buffers off blist and put on cbuf sorted by XRI.
4322 * This is because POST_SGL takes a sequential range of XRIs
4323 * to post to the firmware.
4325 for (idx = 0; idx < cnt; idx++) {
4326 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
4330 list_add_tail(&lpfc_cmd->list, cbuf);
4333 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4336 list_for_each_entry(iobufp, cbuf, list) {
4337 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4339 list_add(&lpfc_cmd->list,
4340 &prev_iobufp->list);
4342 list_add(&lpfc_cmd->list, cbuf);
4346 prev_iobufp = iobufp;
4349 list_add_tail(&lpfc_cmd->list, cbuf);
4355 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4357 struct lpfc_sli4_hdw_queue *qp;
4358 struct lpfc_io_buf *lpfc_cmd;
4361 qp = phba->sli4_hba.hdwq;
4363 while (!list_empty(cbuf)) {
4364 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4365 list_remove_head(cbuf, lpfc_cmd,
4366 struct lpfc_io_buf, list);
4370 qp = &phba->sli4_hba.hdwq[idx];
4371 lpfc_cmd->hdwq_no = idx;
4372 lpfc_cmd->hdwq = qp;
4373 lpfc_cmd->cur_iocbq.cmd_cmpl = NULL;
4374 spin_lock(&qp->io_buf_list_put_lock);
4375 list_add_tail(&lpfc_cmd->list,
4376 &qp->lpfc_io_buf_list_put);
4378 qp->total_io_bufs++;
4379 spin_unlock(&qp->io_buf_list_put_lock);
4386 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4387 * @phba: pointer to lpfc hba data structure.
4389 * This routine first calculates the sizes of the current els and allocated
4390 * scsi sgl lists, and then goes through all sgls to updates the physical
4391 * XRIs assigned due to port function reset. During port initialization, the
4392 * current els and allocated scsi sgl lists are 0s.
4395 * 0 - successful (for now, it always returns 0)
4398 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
4400 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
4401 uint16_t i, lxri, els_xri_cnt;
4402 uint16_t io_xri_cnt, io_xri_max;
4403 LIST_HEAD(io_sgl_list);
4407 * update on pci function's allocated nvme xri-sgl list
4410 /* maximum number of xris available for nvme buffers */
4411 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4412 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4413 phba->sli4_hba.io_xri_max = io_xri_max;
4415 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4416 "6074 Current allocated XRI sgl count:%d, "
4417 "maximum XRI count:%d els_xri_cnt:%d\n\n",
4418 phba->sli4_hba.io_xri_cnt,
4419 phba->sli4_hba.io_xri_max,
4422 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4424 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4425 /* max nvme xri shrunk below the allocated nvme buffers */
4426 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4427 phba->sli4_hba.io_xri_max;
4428 /* release the extra allocated nvme buffers */
4429 for (i = 0; i < io_xri_cnt; i++) {
4430 list_remove_head(&io_sgl_list, lpfc_ncmd,
4431 struct lpfc_io_buf, list);
4433 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4435 lpfc_ncmd->dma_handle);
4439 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4442 /* update xris associated to remaining allocated nvme buffers */
4444 lpfc_ncmd_next = NULL;
4445 phba->sli4_hba.io_xri_cnt = cnt;
4446 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4447 &io_sgl_list, list) {
4448 lxri = lpfc_sli4_next_xritag(phba);
4449 if (lxri == NO_XRI) {
4450 lpfc_printf_log(phba, KERN_ERR,
4452 "6075 Failed to allocate xri for "
4457 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4458 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4460 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4469 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4470 * @phba: Pointer to lpfc hba data structure.
4471 * @num_to_alloc: The requested number of buffers to allocate.
4473 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4474 * the nvme buffer contains all the necessary information needed to initiate
4475 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4476 * them on a list, it post them to the port by using SGL block post.
4479 * int - number of IO buffers that were allocated and posted.
4480 * 0 = failure, less than num_to_alloc is a partial failure.
4483 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4485 struct lpfc_io_buf *lpfc_ncmd;
4486 struct lpfc_iocbq *pwqeq;
4487 uint16_t iotag, lxri = 0;
4488 int bcnt, num_posted;
4489 LIST_HEAD(prep_nblist);
4490 LIST_HEAD(post_nblist);
4491 LIST_HEAD(nvme_nblist);
4493 phba->sli4_hba.io_xri_cnt = 0;
4494 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4495 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4499 * Get memory from the pci pool to map the virt space to
4500 * pci bus space for an I/O. The DMA buffer includes the
4501 * number of SGE's necessary to support the sg_tablesize.
4503 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4505 &lpfc_ncmd->dma_handle);
4506 if (!lpfc_ncmd->data) {
4511 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4512 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4515 * 4K Page alignment is CRITICAL to BlockGuard, double
4518 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4519 (((unsigned long)(lpfc_ncmd->data) &
4520 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4521 lpfc_printf_log(phba, KERN_ERR,
4523 "3369 Memory alignment err: "
4525 (unsigned long)lpfc_ncmd->data);
4526 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4528 lpfc_ncmd->dma_handle);
4534 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4536 lxri = lpfc_sli4_next_xritag(phba);
4537 if (lxri == NO_XRI) {
4538 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4539 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4543 pwqeq = &lpfc_ncmd->cur_iocbq;
4545 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4546 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4548 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4549 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4551 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4552 "6121 Failed to allocate IOTAG for"
4553 " XRI:0x%x\n", lxri);
4554 lpfc_sli4_free_xri(phba, lxri);
4557 pwqeq->sli4_lxritag = lxri;
4558 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4560 /* Initialize local short-hand pointers. */
4561 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4562 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4563 lpfc_ncmd->cur_iocbq.io_buf = lpfc_ncmd;
4564 spin_lock_init(&lpfc_ncmd->buf_lock);
4566 /* add the nvme buffer to a post list */
4567 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4568 phba->sli4_hba.io_xri_cnt++;
4570 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4571 "6114 Allocate %d out of %d requested new NVME "
4572 "buffers of size x%zu bytes\n", bcnt, num_to_alloc,
4573 sizeof(*lpfc_ncmd));
4576 /* post the list of nvme buffer sgls to port if available */
4577 if (!list_empty(&post_nblist))
4578 num_posted = lpfc_sli4_post_io_sgl_list(
4579 phba, &post_nblist, bcnt);
4587 lpfc_get_wwpn(struct lpfc_hba *phba)
4591 LPFC_MBOXQ_t *mboxq;
4594 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4597 return (uint64_t)-1;
4599 /* First get WWN of HBA instance */
4600 lpfc_read_nv(phba, mboxq);
4601 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4602 if (rc != MBX_SUCCESS) {
4603 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4604 "6019 Mailbox failed , mbxCmd x%x "
4605 "READ_NV, mbxStatus x%x\n",
4606 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4607 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4608 mempool_free(mboxq, phba->mbox_mem_pool);
4609 return (uint64_t) -1;
4612 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4613 /* wwn is WWPN of HBA instance */
4614 mempool_free(mboxq, phba->mbox_mem_pool);
4615 if (phba->sli_rev == LPFC_SLI_REV4)
4616 return be64_to_cpu(wwn);
4618 return rol64(wwn, 32);
4621 static unsigned short lpfc_get_sg_tablesize(struct lpfc_hba *phba)
4623 if (phba->sli_rev == LPFC_SLI_REV4)
4624 if (phba->cfg_xpsgl && !phba->nvmet_support)
4625 return LPFC_MAX_SG_TABLESIZE;
4627 return phba->cfg_scsi_seg_cnt;
4629 return phba->cfg_sg_seg_cnt;
4633 * lpfc_vmid_res_alloc - Allocates resources for VMID
4634 * @phba: pointer to lpfc hba data structure.
4635 * @vport: pointer to vport data structure
4637 * This routine allocated the resources needed for the VMID.
4644 lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4646 /* VMID feature is supported only on SLI4 */
4647 if (phba->sli_rev == LPFC_SLI_REV3) {
4648 phba->cfg_vmid_app_header = 0;
4649 phba->cfg_vmid_priority_tagging = 0;
4652 if (lpfc_is_vmid_enabled(phba)) {
4654 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4659 rwlock_init(&vport->vmid_lock);
4661 /* Set the VMID parameters for the vport */
4662 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4663 vport->vmid_inactivity_timeout =
4664 phba->cfg_vmid_inactivity_timeout;
4665 vport->max_vmid = phba->cfg_max_vmid;
4666 vport->cur_vmid_cnt = 0;
4668 vport->vmid_priority_range = bitmap_zalloc
4669 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4671 if (!vport->vmid_priority_range) {
4676 hash_init(vport->hash_table);
4682 * lpfc_create_port - Create an FC port
4683 * @phba: pointer to lpfc hba data structure.
4684 * @instance: a unique integer ID to this FC port.
4685 * @dev: pointer to the device data structure.
4687 * This routine creates a FC port for the upper layer protocol. The FC port
4688 * can be created on top of either a physical port or a virtual port provided
4689 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4690 * and associates the FC port created before adding the shost into the SCSI
4694 * @vport - pointer to the virtual N_Port data structure.
4695 * NULL - port create failed.
4698 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4700 struct lpfc_vport *vport;
4701 struct Scsi_Host *shost = NULL;
4702 struct scsi_host_template *template;
4706 bool use_no_reset_hba = false;
4709 if (lpfc_no_hba_reset_cnt) {
4710 if (phba->sli_rev < LPFC_SLI_REV4 &&
4711 dev == &phba->pcidev->dev) {
4712 /* Reset the port first */
4713 lpfc_sli_brdrestart(phba);
4714 rc = lpfc_sli_chipset_init(phba);
4718 wwn = lpfc_get_wwpn(phba);
4721 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4722 if (wwn == lpfc_no_hba_reset[i]) {
4723 lpfc_printf_log(phba, KERN_ERR,
4725 "6020 Setting use_no_reset port=%llx\n",
4727 use_no_reset_hba = true;
4732 /* Seed template for SCSI host registration */
4733 if (dev == &phba->pcidev->dev) {
4734 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4735 /* Seed physical port template */
4736 template = &lpfc_template;
4738 if (use_no_reset_hba)
4739 /* template is for a no reset SCSI Host */
4740 template->eh_host_reset_handler = NULL;
4742 /* Seed updated value of sg_tablesize */
4743 template->sg_tablesize = lpfc_get_sg_tablesize(phba);
4745 /* NVMET is for physical port only */
4746 template = &lpfc_template_nvme;
4749 /* Seed vport template */
4750 template = &lpfc_vport_template;
4752 /* Seed updated value of sg_tablesize */
4753 template->sg_tablesize = lpfc_get_sg_tablesize(phba);
4756 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
4760 vport = (struct lpfc_vport *) shost->hostdata;
4762 vport->load_flag |= FC_LOADING;
4763 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4764 vport->fc_rscn_flush = 0;
4765 lpfc_get_vport_cfgparam(vport);
4767 /* Adjust value in vport */
4768 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4770 shost->unique_id = instance;
4771 shost->max_id = LPFC_MAX_TARGET;
4772 shost->max_lun = vport->cfg_max_luns;
4773 shost->this_id = -1;
4774 shost->max_cmd_len = 16;
4776 if (phba->sli_rev == LPFC_SLI_REV4) {
4777 if (!phba->cfg_fcp_mq_threshold ||
4778 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4779 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4781 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4782 phba->cfg_fcp_mq_threshold);
4784 shost->dma_boundary =
4785 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4787 /* SLI-3 has a limited number of hardware queues (3),
4788 * thus there is only one for FCP processing.
4790 shost->nr_hw_queues = 1;
4793 * Set initial can_queue value since 0 is no longer supported and
4794 * scsi_add_host will fail. This will be adjusted later based on the
4795 * max xri value determined in hba setup.
4797 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4798 if (dev != &phba->pcidev->dev) {
4799 shost->transportt = lpfc_vport_transport_template;
4800 vport->port_type = LPFC_NPIV_PORT;
4802 shost->transportt = lpfc_transport_template;
4803 vport->port_type = LPFC_PHYSICAL_PORT;
4806 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4807 "9081 CreatePort TMPLATE type %x TBLsize %d "
4809 vport->port_type, shost->sg_tablesize,
4810 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4812 /* Allocate the resources for VMID */
4813 rc = lpfc_vmid_res_alloc(phba, vport);
4818 /* Initialize all internally managed lists. */
4819 INIT_LIST_HEAD(&vport->fc_nodes);
4820 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4821 spin_lock_init(&vport->work_port_lock);
4823 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4825 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4827 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4829 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4830 lpfc_setup_bg(phba, shost);
4832 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4836 spin_lock_irq(&phba->port_list_lock);
4837 list_add_tail(&vport->listentry, &phba->port_list);
4838 spin_unlock_irq(&phba->port_list_lock);
4843 bitmap_free(vport->vmid_priority_range);
4845 scsi_host_put(shost);
4851 * destroy_port - destroy an FC port
4852 * @vport: pointer to an lpfc virtual N_Port data structure.
4854 * This routine destroys a FC port from the upper layer protocol. All the
4855 * resources associated with the port are released.
4858 destroy_port(struct lpfc_vport *vport)
4860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4861 struct lpfc_hba *phba = vport->phba;
4863 lpfc_debugfs_terminate(vport);
4864 fc_remove_host(shost);
4865 scsi_remove_host(shost);
4867 spin_lock_irq(&phba->port_list_lock);
4868 list_del_init(&vport->listentry);
4869 spin_unlock_irq(&phba->port_list_lock);
4871 lpfc_cleanup(vport);
4876 * lpfc_get_instance - Get a unique integer ID
4878 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4879 * uses the kernel idr facility to perform the task.
4882 * instance - a unique integer ID allocated as the new instance.
4883 * -1 - lpfc get instance failed.
4886 lpfc_get_instance(void)
4890 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4891 return ret < 0 ? -1 : ret;
4895 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4896 * @shost: pointer to SCSI host data structure.
4897 * @time: elapsed time of the scan in jiffies.
4899 * This routine is called by the SCSI layer with a SCSI host to determine
4900 * whether the scan host is finished.
4902 * Note: there is no scan_start function as adapter initialization will have
4903 * asynchronously kicked off the link initialization.
4906 * 0 - SCSI host scan is not over yet.
4907 * 1 - SCSI host scan is over.
4909 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4912 struct lpfc_hba *phba = vport->phba;
4915 spin_lock_irq(shost->host_lock);
4917 if (vport->load_flag & FC_UNLOADING) {
4921 if (time >= msecs_to_jiffies(30 * 1000)) {
4922 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4923 "0461 Scanning longer than 30 "
4924 "seconds. Continuing initialization\n");
4928 if (time >= msecs_to_jiffies(15 * 1000) &&
4929 phba->link_state <= LPFC_LINK_DOWN) {
4930 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4931 "0465 Link down longer than 15 "
4932 "seconds. Continuing initialization\n");
4937 if (vport->port_state != LPFC_VPORT_READY)
4939 if (vport->num_disc_nodes || vport->fc_prli_sent)
4941 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4943 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4949 spin_unlock_irq(shost->host_lock);
4953 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4955 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4956 struct lpfc_hba *phba = vport->phba;
4958 fc_host_supported_speeds(shost) = 0;
4960 * Avoid reporting supported link speed for FCoE as it can't be
4961 * controlled via FCoE.
4963 if (phba->hba_flag & HBA_FCOE_MODE)
4966 if (phba->lmt & LMT_256Gb)
4967 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
4968 if (phba->lmt & LMT_128Gb)
4969 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4970 if (phba->lmt & LMT_64Gb)
4971 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4972 if (phba->lmt & LMT_32Gb)
4973 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4974 if (phba->lmt & LMT_16Gb)
4975 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4976 if (phba->lmt & LMT_10Gb)
4977 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4978 if (phba->lmt & LMT_8Gb)
4979 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4980 if (phba->lmt & LMT_4Gb)
4981 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4982 if (phba->lmt & LMT_2Gb)
4983 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4984 if (phba->lmt & LMT_1Gb)
4985 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4989 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4990 * @shost: pointer to SCSI host data structure.
4992 * This routine initializes a given SCSI host attributes on a FC port. The
4993 * SCSI host can be either on top of a physical port or a virtual port.
4995 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4998 struct lpfc_hba *phba = vport->phba;
5000 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
5003 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
5004 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
5005 fc_host_supported_classes(shost) = FC_COS_CLASS3;
5007 memset(fc_host_supported_fc4s(shost), 0,
5008 sizeof(fc_host_supported_fc4s(shost)));
5009 fc_host_supported_fc4s(shost)[2] = 1;
5010 fc_host_supported_fc4s(shost)[7] = 1;
5012 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5013 sizeof fc_host_symbolic_name(shost));
5015 lpfc_host_supported_speeds_set(shost);
5017 fc_host_maxframe_size(shost) =
5018 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
5019 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
5021 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
5023 /* This value is also unchanging */
5024 memset(fc_host_active_fc4s(shost), 0,
5025 sizeof(fc_host_active_fc4s(shost)));
5026 fc_host_active_fc4s(shost)[2] = 1;
5027 fc_host_active_fc4s(shost)[7] = 1;
5029 fc_host_max_npiv_vports(shost) = phba->max_vpi;
5030 spin_lock_irq(shost->host_lock);
5031 vport->load_flag &= ~FC_LOADING;
5032 spin_unlock_irq(shost->host_lock);
5036 * lpfc_stop_port_s3 - Stop SLI3 device port
5037 * @phba: pointer to lpfc hba data structure.
5039 * This routine is invoked to stop an SLI3 device port, it stops the device
5040 * from generating interrupts and stops the device driver's timers for the
5044 lpfc_stop_port_s3(struct lpfc_hba *phba)
5046 /* Clear all interrupt enable conditions */
5047 writel(0, phba->HCregaddr);
5048 readl(phba->HCregaddr); /* flush */
5049 /* Clear all pending interrupts */
5050 writel(0xffffffff, phba->HAregaddr);
5051 readl(phba->HAregaddr); /* flush */
5053 /* Reset some HBA SLI setup states */
5054 lpfc_stop_hba_timers(phba);
5055 phba->pport->work_port_events = 0;
5059 * lpfc_stop_port_s4 - Stop SLI4 device port
5060 * @phba: pointer to lpfc hba data structure.
5062 * This routine is invoked to stop an SLI4 device port, it stops the device
5063 * from generating interrupts and stops the device driver's timers for the
5067 lpfc_stop_port_s4(struct lpfc_hba *phba)
5069 /* Reset some HBA SLI4 setup states */
5070 lpfc_stop_hba_timers(phba);
5072 phba->pport->work_port_events = 0;
5073 phba->sli4_hba.intr_enable = 0;
5077 * lpfc_stop_port - Wrapper function for stopping hba port
5078 * @phba: Pointer to HBA context object.
5080 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
5081 * the API jump table function pointer from the lpfc_hba struct.
5084 lpfc_stop_port(struct lpfc_hba *phba)
5086 phba->lpfc_stop_port(phba);
5089 flush_workqueue(phba->wq);
5093 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
5094 * @phba: Pointer to hba for which this call is being executed.
5096 * This routine starts the timer waiting for the FCF rediscovery to complete.
5099 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
5101 unsigned long fcf_redisc_wait_tmo =
5102 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
5103 /* Start fcf rediscovery wait period timer */
5104 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
5105 spin_lock_irq(&phba->hbalock);
5106 /* Allow action to new fcf asynchronous event */
5107 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
5108 /* Mark the FCF rediscovery pending state */
5109 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
5110 spin_unlock_irq(&phba->hbalock);
5114 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
5115 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5117 * This routine is invoked when waiting for FCF table rediscover has been
5118 * timed out. If new FCF record(s) has (have) been discovered during the
5119 * wait period, a new FCF event shall be added to the FCOE async event
5120 * list, and then worker thread shall be waked up for processing from the
5121 * worker thread context.
5124 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
5126 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
5128 /* Don't send FCF rediscovery event if timer cancelled */
5129 spin_lock_irq(&phba->hbalock);
5130 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
5131 spin_unlock_irq(&phba->hbalock);
5134 /* Clear FCF rediscovery timer pending flag */
5135 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
5136 /* FCF rediscovery event to worker thread */
5137 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
5138 spin_unlock_irq(&phba->hbalock);
5139 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
5140 "2776 FCF rediscover quiescent timer expired\n");
5141 /* wake up worker thread */
5142 lpfc_worker_wake_up(phba);
5146 * lpfc_vmid_poll - VMID timeout detection
5147 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
5149 * This routine is invoked when there is no I/O on by a VM for the specified
5150 * amount of time. When this situation is detected, the VMID has to be
5151 * deregistered from the switch and all the local resources freed. The VMID
5152 * will be reassigned to the VM once the I/O begins.
5155 lpfc_vmid_poll(struct timer_list *t)
5157 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
5160 /* check if there is a need to issue QFPA */
5161 if (phba->pport->vmid_priority_tagging) {
5163 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5166 /* Is the vmid inactivity timer enabled */
5167 if (phba->pport->vmid_inactivity_timeout ||
5168 phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
5170 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5174 lpfc_worker_wake_up(phba);
5176 /* restart the timer for the next iteration */
5177 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5182 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5183 * @phba: pointer to lpfc hba data structure.
5184 * @acqe_link: pointer to the async link completion queue entry.
5186 * This routine is to parse the SLI4 link-attention link fault code.
5189 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5190 struct lpfc_acqe_link *acqe_link)
5192 switch (bf_get(lpfc_acqe_fc_la_att_type, acqe_link)) {
5193 case LPFC_FC_LA_TYPE_LINK_DOWN:
5194 case LPFC_FC_LA_TYPE_TRUNKING_EVENT:
5195 case LPFC_FC_LA_TYPE_ACTIVATE_FAIL:
5196 case LPFC_FC_LA_TYPE_LINK_RESET_PRTCL_EVT:
5199 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5200 case LPFC_ASYNC_LINK_FAULT_NONE:
5201 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5202 case LPFC_ASYNC_LINK_FAULT_REMOTE:
5203 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
5206 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5207 "0398 Unknown link fault code: x%x\n",
5208 bf_get(lpfc_acqe_link_fault, acqe_link));
5216 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5217 * @phba: pointer to lpfc hba data structure.
5218 * @acqe_link: pointer to the async link completion queue entry.
5220 * This routine is to parse the SLI4 link attention type and translate it
5221 * into the base driver's link attention type coding.
5223 * Return: Link attention type in terms of base driver's coding.
5226 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5227 struct lpfc_acqe_link *acqe_link)
5231 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5232 case LPFC_ASYNC_LINK_STATUS_DOWN:
5233 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
5234 att_type = LPFC_ATT_LINK_DOWN;
5236 case LPFC_ASYNC_LINK_STATUS_UP:
5237 /* Ignore physical link up events - wait for logical link up */
5238 att_type = LPFC_ATT_RESERVED;
5240 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
5241 att_type = LPFC_ATT_LINK_UP;
5244 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5245 "0399 Invalid link attention type: x%x\n",
5246 bf_get(lpfc_acqe_link_status, acqe_link));
5247 att_type = LPFC_ATT_RESERVED;
5254 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5255 * @phba: pointer to lpfc hba data structure.
5257 * This routine is to get an SLI3 FC port's link speed in Mbps.
5259 * Return: link speed in terms of Mbps.
5262 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5264 uint32_t link_speed;
5266 if (!lpfc_is_link_up(phba))
5269 if (phba->sli_rev <= LPFC_SLI_REV3) {
5270 switch (phba->fc_linkspeed) {
5271 case LPFC_LINK_SPEED_1GHZ:
5274 case LPFC_LINK_SPEED_2GHZ:
5277 case LPFC_LINK_SPEED_4GHZ:
5280 case LPFC_LINK_SPEED_8GHZ:
5283 case LPFC_LINK_SPEED_10GHZ:
5286 case LPFC_LINK_SPEED_16GHZ:
5293 if (phba->sli4_hba.link_state.logical_speed)
5295 phba->sli4_hba.link_state.logical_speed;
5297 link_speed = phba->sli4_hba.link_state.speed;
5303 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5304 * @phba: pointer to lpfc hba data structure.
5305 * @evt_code: asynchronous event code.
5306 * @speed_code: asynchronous event link speed code.
5308 * This routine is to parse the giving SLI4 async event link speed code into
5309 * value of Mbps for the link speed.
5311 * Return: link speed in terms of Mbps.
5314 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5317 uint32_t port_speed;
5320 case LPFC_TRAILER_CODE_LINK:
5321 switch (speed_code) {
5322 case LPFC_ASYNC_LINK_SPEED_ZERO:
5325 case LPFC_ASYNC_LINK_SPEED_10MBPS:
5328 case LPFC_ASYNC_LINK_SPEED_100MBPS:
5331 case LPFC_ASYNC_LINK_SPEED_1GBPS:
5334 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5337 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5340 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5343 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5346 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5347 port_speed = 100000;
5353 case LPFC_TRAILER_CODE_FC:
5354 switch (speed_code) {
5355 case LPFC_FC_LA_SPEED_UNKNOWN:
5358 case LPFC_FC_LA_SPEED_1G:
5361 case LPFC_FC_LA_SPEED_2G:
5364 case LPFC_FC_LA_SPEED_4G:
5367 case LPFC_FC_LA_SPEED_8G:
5370 case LPFC_FC_LA_SPEED_10G:
5373 case LPFC_FC_LA_SPEED_16G:
5376 case LPFC_FC_LA_SPEED_32G:
5379 case LPFC_FC_LA_SPEED_64G:
5382 case LPFC_FC_LA_SPEED_128G:
5383 port_speed = 128000;
5385 case LPFC_FC_LA_SPEED_256G:
5386 port_speed = 256000;
5399 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
5400 * @phba: pointer to lpfc hba data structure.
5401 * @acqe_link: pointer to the async link completion queue entry.
5403 * This routine is to handle the SLI4 asynchronous FCoE link event.
5406 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5407 struct lpfc_acqe_link *acqe_link)
5411 struct lpfc_mbx_read_top *la;
5415 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
5416 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
5418 phba->fcoe_eventtag = acqe_link->event_tag;
5419 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5421 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5422 "0395 The mboxq allocation failed\n");
5426 rc = lpfc_mbox_rsrc_prep(phba, pmb);
5428 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5429 "0396 mailbox allocation failed\n");
5433 /* Cleanup any outstanding ELS commands */
5434 lpfc_els_flush_all_cmd(phba);
5436 /* Block ELS IOCBs until we have done process link event */
5437 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5439 /* Update link event statistics */
5440 phba->sli.slistat.link_event++;
5442 /* Create lpfc_handle_latt mailbox command from link ACQE */
5443 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
5444 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5445 pmb->vport = phba->pport;
5447 /* Keep the link status for extra SLI4 state machine reference */
5448 phba->sli4_hba.link_state.speed =
5449 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5450 bf_get(lpfc_acqe_link_speed, acqe_link));
5451 phba->sli4_hba.link_state.duplex =
5452 bf_get(lpfc_acqe_link_duplex, acqe_link);
5453 phba->sli4_hba.link_state.status =
5454 bf_get(lpfc_acqe_link_status, acqe_link);
5455 phba->sli4_hba.link_state.type =
5456 bf_get(lpfc_acqe_link_type, acqe_link);
5457 phba->sli4_hba.link_state.number =
5458 bf_get(lpfc_acqe_link_number, acqe_link);
5459 phba->sli4_hba.link_state.fault =
5460 bf_get(lpfc_acqe_link_fault, acqe_link);
5461 phba->sli4_hba.link_state.logical_speed =
5462 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5464 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5465 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5466 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5467 "Logical speed:%dMbps Fault:%d\n",
5468 phba->sli4_hba.link_state.speed,
5469 phba->sli4_hba.link_state.topology,
5470 phba->sli4_hba.link_state.status,
5471 phba->sli4_hba.link_state.type,
5472 phba->sli4_hba.link_state.number,
5473 phba->sli4_hba.link_state.logical_speed,
5474 phba->sli4_hba.link_state.fault);
5476 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5477 * topology info. Note: Optional for non FC-AL ports.
5479 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5480 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5481 if (rc == MBX_NOT_FINISHED)
5486 * For FCoE Mode: fill in all the topology information we need and call
5487 * the READ_TOPOLOGY completion routine to continue without actually
5488 * sending the READ_TOPOLOGY mailbox command to the port.
5490 /* Initialize completion status */
5492 mb->mbxStatus = MBX_SUCCESS;
5494 /* Parse port fault information field */
5495 lpfc_sli4_parse_latt_fault(phba, acqe_link);
5497 /* Parse and translate link attention fields */
5498 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5499 la->eventTag = acqe_link->event_tag;
5500 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5501 bf_set(lpfc_mbx_read_top_link_spd, la,
5502 (bf_get(lpfc_acqe_link_speed, acqe_link)));
5504 /* Fake the following irrelevant fields */
5505 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5506 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5507 bf_set(lpfc_mbx_read_top_il, la, 0);
5508 bf_set(lpfc_mbx_read_top_pb, la, 0);
5509 bf_set(lpfc_mbx_read_top_fa, la, 0);
5510 bf_set(lpfc_mbx_read_top_mm, la, 0);
5512 /* Invoke the lpfc_handle_latt mailbox command callback function */
5513 lpfc_mbx_cmpl_read_topology(phba, pmb);
5518 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5522 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5524 * @phba: pointer to lpfc hba data structure.
5525 * @speed_code: asynchronous event link speed code.
5527 * This routine is to parse the giving SLI4 async event link speed code into
5528 * value of Read topology link speed.
5530 * Return: link speed in terms of Read topology.
5533 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5537 switch (speed_code) {
5538 case LPFC_FC_LA_SPEED_1G:
5539 port_speed = LPFC_LINK_SPEED_1GHZ;
5541 case LPFC_FC_LA_SPEED_2G:
5542 port_speed = LPFC_LINK_SPEED_2GHZ;
5544 case LPFC_FC_LA_SPEED_4G:
5545 port_speed = LPFC_LINK_SPEED_4GHZ;
5547 case LPFC_FC_LA_SPEED_8G:
5548 port_speed = LPFC_LINK_SPEED_8GHZ;
5550 case LPFC_FC_LA_SPEED_16G:
5551 port_speed = LPFC_LINK_SPEED_16GHZ;
5553 case LPFC_FC_LA_SPEED_32G:
5554 port_speed = LPFC_LINK_SPEED_32GHZ;
5556 case LPFC_FC_LA_SPEED_64G:
5557 port_speed = LPFC_LINK_SPEED_64GHZ;
5559 case LPFC_FC_LA_SPEED_128G:
5560 port_speed = LPFC_LINK_SPEED_128GHZ;
5562 case LPFC_FC_LA_SPEED_256G:
5563 port_speed = LPFC_LINK_SPEED_256GHZ;
5574 lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
5576 if (!phba->rx_monitor) {
5577 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5578 "4411 Rx Monitor Info is empty.\n");
5580 lpfc_rx_monitor_report(phba, phba->rx_monitor, NULL, 0,
5581 LPFC_MAX_RXMONITOR_DUMP);
5586 * lpfc_cgn_update_stat - Save data into congestion stats buffer
5587 * @phba: pointer to lpfc hba data structure.
5588 * @dtag: FPIN descriptor received
5590 * Increment the FPIN received counter/time when it happens.
5593 lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
5595 struct lpfc_cgn_info *cp;
5597 struct timespec64 cur_time;
5601 /* Make sure we have a congestion info buffer */
5604 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5605 ktime_get_real_ts64(&cur_time);
5606 time64_to_tm(cur_time.tv_sec, 0, &broken);
5608 /* Update congestion statistics */
5610 case ELS_DTAG_LNK_INTEGRITY:
5611 cnt = le32_to_cpu(cp->link_integ_notification);
5613 cp->link_integ_notification = cpu_to_le32(cnt);
5615 cp->cgn_stat_lnk_month = broken.tm_mon + 1;
5616 cp->cgn_stat_lnk_day = broken.tm_mday;
5617 cp->cgn_stat_lnk_year = broken.tm_year - 100;
5618 cp->cgn_stat_lnk_hour = broken.tm_hour;
5619 cp->cgn_stat_lnk_min = broken.tm_min;
5620 cp->cgn_stat_lnk_sec = broken.tm_sec;
5622 case ELS_DTAG_DELIVERY:
5623 cnt = le32_to_cpu(cp->delivery_notification);
5625 cp->delivery_notification = cpu_to_le32(cnt);
5627 cp->cgn_stat_del_month = broken.tm_mon + 1;
5628 cp->cgn_stat_del_day = broken.tm_mday;
5629 cp->cgn_stat_del_year = broken.tm_year - 100;
5630 cp->cgn_stat_del_hour = broken.tm_hour;
5631 cp->cgn_stat_del_min = broken.tm_min;
5632 cp->cgn_stat_del_sec = broken.tm_sec;
5634 case ELS_DTAG_PEER_CONGEST:
5635 cnt = le32_to_cpu(cp->cgn_peer_notification);
5637 cp->cgn_peer_notification = cpu_to_le32(cnt);
5639 cp->cgn_stat_peer_month = broken.tm_mon + 1;
5640 cp->cgn_stat_peer_day = broken.tm_mday;
5641 cp->cgn_stat_peer_year = broken.tm_year - 100;
5642 cp->cgn_stat_peer_hour = broken.tm_hour;
5643 cp->cgn_stat_peer_min = broken.tm_min;
5644 cp->cgn_stat_peer_sec = broken.tm_sec;
5646 case ELS_DTAG_CONGESTION:
5647 cnt = le32_to_cpu(cp->cgn_notification);
5649 cp->cgn_notification = cpu_to_le32(cnt);
5651 cp->cgn_stat_cgn_month = broken.tm_mon + 1;
5652 cp->cgn_stat_cgn_day = broken.tm_mday;
5653 cp->cgn_stat_cgn_year = broken.tm_year - 100;
5654 cp->cgn_stat_cgn_hour = broken.tm_hour;
5655 cp->cgn_stat_cgn_min = broken.tm_min;
5656 cp->cgn_stat_cgn_sec = broken.tm_sec;
5658 if (phba->cgn_fpin_frequency &&
5659 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5660 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5661 cp->cgn_stat_npm = value;
5663 value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5664 LPFC_CGN_CRC32_SEED);
5665 cp->cgn_info_crc = cpu_to_le32(value);
5669 * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer
5670 * @phba: pointer to lpfc hba data structure.
5672 * Save the congestion event data every minute.
5673 * On the hour collapse all the minute data into hour data. Every day
5674 * collapse all the hour data into daily data. Separate driver
5675 * and fabrc congestion event counters that will be saved out
5676 * to the registered congestion buffer every minute.
5679 lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba)
5681 struct lpfc_cgn_info *cp;
5683 struct timespec64 cur_time;
5685 uint16_t value, mvalue;
5688 uint32_t dvalue, wvalue, lvalue, avalue;
5694 /* Make sure we have a congestion info buffer */
5697 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5699 if (time_before(jiffies, phba->cgn_evt_timestamp))
5701 phba->cgn_evt_timestamp = jiffies +
5702 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
5703 phba->cgn_evt_minute++;
5705 /* We should get to this point in the routine on 1 minute intervals */
5707 ktime_get_real_ts64(&cur_time);
5708 time64_to_tm(cur_time.tv_sec, 0, &broken);
5710 if (phba->cgn_fpin_frequency &&
5711 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5712 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5713 cp->cgn_stat_npm = value;
5716 /* Read and clear the latency counters for this minute */
5717 lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
5718 latsum = atomic64_read(&phba->cgn_latency_evt);
5719 atomic_set(&phba->cgn_latency_evt_cnt, 0);
5720 atomic64_set(&phba->cgn_latency_evt, 0);
5722 /* We need to store MB/sec bandwidth in the congestion information.
5723 * block_cnt is count of 512 byte blocks for the entire minute,
5724 * bps will get bytes per sec before finally converting to MB/sec.
5726 bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
5727 phba->rx_block_cnt = 0;
5728 mvalue = bps / (1024 * 1024); /* convert to MB/sec */
5731 /* cgn parameters */
5732 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
5733 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
5734 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
5735 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
5737 /* Fill in default LUN qdepth */
5738 value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
5739 cp->cgn_lunq = cpu_to_le16(value);
5741 /* Record congestion buffer info - every minute
5742 * cgn_driver_evt_cnt (Driver events)
5743 * cgn_fabric_warn_cnt (Congestion Warnings)
5744 * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
5745 * cgn_fabric_alarm_cnt (Congestion Alarms)
5747 index = ++cp->cgn_index_minute;
5748 if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
5749 cp->cgn_index_minute = 0;
5753 /* Get the number of driver events in this sample and reset counter */
5754 dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
5755 atomic_set(&phba->cgn_driver_evt_cnt, 0);
5757 /* Get the number of warning events - FPIN and Signal for this minute */
5759 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
5760 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5761 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5762 wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
5763 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
5765 /* Get the number of alarm events - FPIN and Signal for this minute */
5767 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
5768 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5769 avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
5770 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
5772 /* Collect the driver, warning, alarm and latency counts for this
5773 * minute into the driver congestion buffer.
5775 ptr = &cp->cgn_drvr_min[index];
5776 value = (uint16_t)dvalue;
5777 *ptr = cpu_to_le16(value);
5779 ptr = &cp->cgn_warn_min[index];
5780 value = (uint16_t)wvalue;
5781 *ptr = cpu_to_le16(value);
5783 ptr = &cp->cgn_alarm_min[index];
5784 value = (uint16_t)avalue;
5785 *ptr = cpu_to_le16(value);
5787 lptr = &cp->cgn_latency_min[index];
5789 lvalue = (uint32_t)div_u64(latsum, lvalue);
5790 *lptr = cpu_to_le32(lvalue);
5795 /* Collect the bandwidth value into the driver's congesion buffer. */
5796 mptr = &cp->cgn_bw_min[index];
5797 *mptr = cpu_to_le16(mvalue);
5799 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5800 "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
5801 index, dvalue, wvalue, *lptr, mvalue, avalue);
5804 if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
5805 /* Record congestion buffer info - every hour
5806 * Collapse all minutes into an hour
5808 index = ++cp->cgn_index_hour;
5809 if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
5810 cp->cgn_index_hour = 0;
5820 for (i = 0; i < LPFC_MIN_HOUR; i++) {
5821 dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
5822 wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
5823 lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
5824 mbps += le16_to_cpu(cp->cgn_bw_min[i]);
5825 avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
5827 if (lvalue) /* Avg of latency averages */
5828 lvalue /= LPFC_MIN_HOUR;
5829 if (mbps) /* Avg of Bandwidth averages */
5830 mvalue = mbps / LPFC_MIN_HOUR;
5832 lptr = &cp->cgn_drvr_hr[index];
5833 *lptr = cpu_to_le32(dvalue);
5834 lptr = &cp->cgn_warn_hr[index];
5835 *lptr = cpu_to_le32(wvalue);
5836 lptr = &cp->cgn_latency_hr[index];
5837 *lptr = cpu_to_le32(lvalue);
5838 mptr = &cp->cgn_bw_hr[index];
5839 *mptr = cpu_to_le16(mvalue);
5840 lptr = &cp->cgn_alarm_hr[index];
5841 *lptr = cpu_to_le32(avalue);
5843 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5844 "2419 Congestion Info - hour "
5845 "(%d): %d %d %d %d %d\n",
5846 index, dvalue, wvalue, lvalue, mvalue, avalue);
5850 if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
5851 /* Record congestion buffer info - every hour
5852 * Collapse all hours into a day. Rotate days
5853 * after LPFC_MAX_CGN_DAYS.
5855 index = ++cp->cgn_index_day;
5856 if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
5857 cp->cgn_index_day = 0;
5861 /* Anytime we overwrite daily index 0, after we wrap,
5862 * we will be overwriting the oldest day, so we must
5863 * update the congestion data start time for that day.
5864 * That start time should have previously been saved after
5865 * we wrote the last days worth of data.
5867 if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) {
5868 time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken);
5870 cp->cgn_info_month = broken.tm_mon + 1;
5871 cp->cgn_info_day = broken.tm_mday;
5872 cp->cgn_info_year = broken.tm_year - 100;
5873 cp->cgn_info_hour = broken.tm_hour;
5874 cp->cgn_info_minute = broken.tm_min;
5875 cp->cgn_info_second = broken.tm_sec;
5878 (phba, KERN_INFO, LOG_CGN_MGMT,
5879 "2646 CGNInfo idx0 Start Time: "
5880 "%d/%d/%d %d:%d:%d\n",
5881 cp->cgn_info_day, cp->cgn_info_month,
5882 cp->cgn_info_year, cp->cgn_info_hour,
5883 cp->cgn_info_minute, cp->cgn_info_second);
5892 for (i = 0; i < LPFC_HOUR_DAY; i++) {
5893 dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
5894 wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
5895 lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
5896 mbps += le16_to_cpu(cp->cgn_bw_hr[i]);
5897 avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
5899 if (lvalue) /* Avg of latency averages */
5900 lvalue /= LPFC_HOUR_DAY;
5901 if (mbps) /* Avg of Bandwidth averages */
5902 mvalue = mbps / LPFC_HOUR_DAY;
5904 lptr = &cp->cgn_drvr_day[index];
5905 *lptr = cpu_to_le32(dvalue);
5906 lptr = &cp->cgn_warn_day[index];
5907 *lptr = cpu_to_le32(wvalue);
5908 lptr = &cp->cgn_latency_day[index];
5909 *lptr = cpu_to_le32(lvalue);
5910 mptr = &cp->cgn_bw_day[index];
5911 *mptr = cpu_to_le16(mvalue);
5912 lptr = &cp->cgn_alarm_day[index];
5913 *lptr = cpu_to_le32(avalue);
5915 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5916 "2420 Congestion Info - daily (%d): "
5918 index, dvalue, wvalue, lvalue, mvalue, avalue);
5920 /* We just wrote LPFC_MAX_CGN_DAYS of data,
5921 * so we are wrapped on any data after this.
5922 * Save this as the start time for the next day.
5924 if (index == (LPFC_MAX_CGN_DAYS - 1)) {
5925 phba->hba_flag |= HBA_CGN_DAY_WRAP;
5926 ktime_get_real_ts64(&phba->cgn_daily_ts);
5930 /* Use the frequency found in the last rcv'ed FPIN */
5931 value = phba->cgn_fpin_frequency;
5932 cp->cgn_warn_freq = cpu_to_le16(value);
5933 cp->cgn_alarm_freq = cpu_to_le16(value);
5935 lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5936 LPFC_CGN_CRC32_SEED);
5937 cp->cgn_info_crc = cpu_to_le32(lvalue);
5941 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5942 * @phba: The Hba for which this call is being executed.
5944 * The routine calculates the latency from the beginning of the CMF timer
5945 * interval to the current point in time. It is called from IO completion
5946 * when we exceed our Bandwidth limitation for the time interval.
5949 lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5951 struct timespec64 cmpl_time;
5954 ktime_get_real_ts64(&cmpl_time);
5956 /* This routine works on a ms granularity so sec and usec are
5957 * converted accordingly.
5959 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5960 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5963 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5964 msec = (cmpl_time.tv_sec -
5965 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5966 msec += ((cmpl_time.tv_nsec -
5967 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5969 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5971 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5972 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5979 * lpfc_cmf_timer - This is the timer function for one congestion
5981 * @timer: Pointer to the high resolution timer that expired
5983 static enum hrtimer_restart
5984 lpfc_cmf_timer(struct hrtimer *timer)
5986 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5988 struct rx_info_entry entry;
5990 uint32_t busy, max_read;
5991 uint64_t total, rcv, lat, mbpi, extra, cnt;
5992 int timer_interval = LPFC_CMF_INTERVAL;
5994 struct lpfc_cgn_stat *cgs;
5997 /* Only restart the timer if congestion mgmt is on */
5998 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5999 !phba->cmf_latency.tv_sec) {
6000 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
6001 "6224 CMF timer exit: %d %lld\n",
6002 phba->cmf_active_mode,
6003 (uint64_t)phba->cmf_latency.tv_sec);
6004 return HRTIMER_NORESTART;
6007 /* If pport is not ready yet, just exit and wait for
6008 * the next timer cycle to hit.
6013 /* Do not block SCSI IO while in the timer routine since
6014 * total_bytes will be cleared
6016 atomic_set(&phba->cmf_stop_io, 1);
6018 /* First we need to calculate the actual ms between
6019 * the last timer interrupt and this one. We ask for
6020 * LPFC_CMF_INTERVAL, however the actual time may
6021 * vary depending on system overhead.
6023 ms = lpfc_calc_cmf_latency(phba);
6026 /* Immediately after we calculate the time since the last
6027 * timer interrupt, set the start time for the next
6030 ktime_get_real_ts64(&phba->cmf_latency);
6032 phba->cmf_link_byte_count =
6033 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
6035 /* Collect all the stats from the prior timer interval */
6040 for_each_present_cpu(cpu) {
6041 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
6042 total += atomic64_xchg(&cgs->total_bytes, 0);
6043 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
6044 lat += atomic64_xchg(&cgs->rx_latency, 0);
6045 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
6048 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
6049 * returned from the last CMF_SYNC_WQE issued, from
6050 * cmf_last_sync_bw. This will be the target BW for
6051 * this next timer interval.
6053 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
6054 phba->link_state != LPFC_LINK_DOWN &&
6055 phba->hba_flag & HBA_SETUP) {
6056 mbpi = phba->cmf_last_sync_bw;
6057 phba->cmf_last_sync_bw = 0;
6060 /* Calculate any extra bytes needed to account for the
6061 * timer accuracy. If we are less than LPFC_CMF_INTERVAL
6062 * calculate the adjustment needed for total to reflect
6063 * a full LPFC_CMF_INTERVAL.
6065 if (ms && ms < LPFC_CMF_INTERVAL) {
6066 cnt = div_u64(total, ms); /* bytes per ms */
6067 cnt *= LPFC_CMF_INTERVAL; /* what total should be */
6069 /* If the timeout is scheduled to be shorter,
6070 * this value may skew the data, so cap it at mbpi.
6072 if ((phba->hba_flag & HBA_SHORT_CMF) && cnt > mbpi)
6075 extra = cnt - total;
6077 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
6079 /* For Monitor mode or link down we want mbpi
6080 * to be the full link speed
6082 mbpi = phba->cmf_link_byte_count;
6085 phba->cmf_timer_cnt++;
6088 /* Update congestion info buffer latency in us */
6089 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
6090 atomic64_add(lat, &phba->cgn_latency_evt);
6092 busy = atomic_xchg(&phba->cmf_busy, 0);
6093 max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
6095 /* Calculate MBPI for the next timer interval */
6097 if (mbpi > phba->cmf_link_byte_count ||
6098 phba->cmf_active_mode == LPFC_CFG_MONITOR)
6099 mbpi = phba->cmf_link_byte_count;
6101 /* Change max_bytes_per_interval to what the prior
6102 * CMF_SYNC_WQE cmpl indicated.
6104 if (mbpi != phba->cmf_max_bytes_per_interval)
6105 phba->cmf_max_bytes_per_interval = mbpi;
6108 /* Save rxmonitor information for debug */
6109 if (phba->rx_monitor) {
6110 entry.total_bytes = total;
6111 entry.cmf_bytes = total + extra;
6112 entry.rcv_bytes = rcv;
6113 entry.cmf_busy = busy;
6114 entry.cmf_info = phba->cmf_active_info;
6116 entry.avg_io_latency = div_u64(lat, io_cnt);
6117 entry.avg_io_size = div_u64(rcv, io_cnt);
6119 entry.avg_io_latency = 0;
6120 entry.avg_io_size = 0;
6122 entry.max_read_cnt = max_read;
6123 entry.io_cnt = io_cnt;
6124 entry.max_bytes_per_interval = mbpi;
6125 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
6126 entry.timer_utilization = phba->cmf_last_ts;
6128 entry.timer_utilization = ms;
6129 entry.timer_interval = ms;
6130 phba->cmf_last_ts = 0;
6132 lpfc_rx_monitor_record(phba->rx_monitor, &entry);
6135 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
6136 /* If Monitor mode, check if we are oversubscribed
6137 * against the full line rate.
6139 if (mbpi && total > mbpi)
6140 atomic_inc(&phba->cgn_driver_evt_cnt);
6142 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
6144 /* Each minute save Fabric and Driver congestion information */
6145 lpfc_cgn_save_evt_cnt(phba);
6147 phba->hba_flag &= ~HBA_SHORT_CMF;
6149 /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the
6150 * minute, adjust our next timer interval, if needed, to ensure a
6151 * 1 minute granularity when we get the next timer interrupt.
6153 if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL),
6154 phba->cgn_evt_timestamp)) {
6155 timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp -
6157 if (timer_interval <= 0)
6158 timer_interval = LPFC_CMF_INTERVAL;
6160 phba->hba_flag |= HBA_SHORT_CMF;
6162 /* If we adjust timer_interval, max_bytes_per_interval
6163 * needs to be adjusted as well.
6165 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
6166 timer_interval, 1000);
6167 if (phba->cmf_active_mode == LPFC_CFG_MONITOR)
6168 phba->cmf_max_bytes_per_interval =
6169 phba->cmf_link_byte_count;
6172 /* Since total_bytes has already been zero'ed, its okay to unblock
6173 * after max_bytes_per_interval is setup.
6175 if (atomic_xchg(&phba->cmf_bw_wait, 0))
6176 queue_work(phba->wq, &phba->unblock_request_work);
6178 /* SCSI IO is now unblocked */
6179 atomic_set(&phba->cmf_stop_io, 0);
6182 hrtimer_forward_now(timer,
6183 ktime_set(0, timer_interval * NSEC_PER_MSEC));
6184 return HRTIMER_RESTART;
6187 #define trunk_link_status(__idx)\
6188 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6189 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
6190 "Link up" : "Link down") : "NA"
6191 /* Did port __idx reported an error */
6192 #define trunk_port_fault(__idx)\
6193 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6194 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
6197 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
6198 struct lpfc_acqe_fc_la *acqe_fc)
6200 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
6201 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
6204 phba->sli4_hba.link_state.speed =
6205 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6206 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6208 phba->sli4_hba.link_state.logical_speed =
6209 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6210 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
6211 phba->fc_linkspeed =
6212 lpfc_async_link_speed_to_read_top(
6214 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6216 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
6217 phba->trunk_link.link0.state =
6218 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
6219 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6220 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
6223 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
6224 phba->trunk_link.link1.state =
6225 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
6226 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6227 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
6230 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
6231 phba->trunk_link.link2.state =
6232 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
6233 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6234 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
6237 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
6238 phba->trunk_link.link3.state =
6239 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
6240 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
6241 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
6246 phba->trunk_link.phy_lnk_speed =
6247 phba->sli4_hba.link_state.logical_speed / (cnt * 1000);
6249 phba->trunk_link.phy_lnk_speed = LPFC_LINK_SPEED_UNKNOWN;
6251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6252 "2910 Async FC Trunking Event - Speed:%d\n"
6253 "\tLogical speed:%d "
6254 "port0: %s port1: %s port2: %s port3: %s\n",
6255 phba->sli4_hba.link_state.speed,
6256 phba->sli4_hba.link_state.logical_speed,
6257 trunk_link_status(0), trunk_link_status(1),
6258 trunk_link_status(2), trunk_link_status(3));
6260 if (phba->cmf_active_mode != LPFC_CFG_OFF)
6261 lpfc_cmf_signal_init(phba);
6264 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6265 "3202 trunk error:0x%x (%s) seen on port0:%s "
6267 * SLI-4: We have only 0xA error codes
6268 * defined as of now. print an appropriate
6269 * message in case driver needs to be updated.
6271 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
6272 "UNDEFINED. update driver." : trunk_errmsg[err],
6273 trunk_port_fault(0), trunk_port_fault(1),
6274 trunk_port_fault(2), trunk_port_fault(3));
6279 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
6280 * @phba: pointer to lpfc hba data structure.
6281 * @acqe_fc: pointer to the async fc completion queue entry.
6283 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
6284 * that the event was received and then issue a read_topology mailbox command so
6285 * that the rest of the driver will treat it the same as SLI3.
6288 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
6292 struct lpfc_mbx_read_top *la;
6296 if (bf_get(lpfc_trailer_type, acqe_fc) !=
6297 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
6298 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6299 "2895 Non FC link Event detected.(%d)\n",
6300 bf_get(lpfc_trailer_type, acqe_fc));
6304 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6305 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
6306 lpfc_update_trunk_link_status(phba, acqe_fc);
6310 /* Keep the link status for extra SLI4 state machine reference */
6311 phba->sli4_hba.link_state.speed =
6312 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6313 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6314 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
6315 phba->sli4_hba.link_state.topology =
6316 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
6317 phba->sli4_hba.link_state.status =
6318 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
6319 phba->sli4_hba.link_state.type =
6320 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
6321 phba->sli4_hba.link_state.number =
6322 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
6323 phba->sli4_hba.link_state.fault =
6324 bf_get(lpfc_acqe_link_fault, acqe_fc);
6325 phba->sli4_hba.link_state.link_status =
6326 bf_get(lpfc_acqe_fc_la_link_status, acqe_fc);
6329 * Only select attention types need logical speed modification to what
6330 * was previously set.
6332 if (phba->sli4_hba.link_state.status >= LPFC_FC_LA_TYPE_LINK_UP &&
6333 phba->sli4_hba.link_state.status < LPFC_FC_LA_TYPE_ACTIVATE_FAIL) {
6334 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6335 LPFC_FC_LA_TYPE_LINK_DOWN)
6336 phba->sli4_hba.link_state.logical_speed = 0;
6337 else if (!phba->sli4_hba.conf_trunk)
6338 phba->sli4_hba.link_state.logical_speed =
6339 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
6342 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6343 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
6344 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
6345 "%dMbps Fault:x%x Link Status:x%x\n",
6346 phba->sli4_hba.link_state.speed,
6347 phba->sli4_hba.link_state.topology,
6348 phba->sli4_hba.link_state.status,
6349 phba->sli4_hba.link_state.type,
6350 phba->sli4_hba.link_state.number,
6351 phba->sli4_hba.link_state.logical_speed,
6352 phba->sli4_hba.link_state.fault,
6353 phba->sli4_hba.link_state.link_status);
6356 * The following attention types are informational only, providing
6357 * further details about link status. Overwrite the value of
6358 * link_state.status appropriately. No further action is required.
6360 if (phba->sli4_hba.link_state.status >= LPFC_FC_LA_TYPE_ACTIVATE_FAIL) {
6361 switch (phba->sli4_hba.link_state.status) {
6362 case LPFC_FC_LA_TYPE_ACTIVATE_FAIL:
6363 log_level = KERN_WARNING;
6364 phba->sli4_hba.link_state.status =
6365 LPFC_FC_LA_TYPE_LINK_DOWN;
6367 case LPFC_FC_LA_TYPE_LINK_RESET_PRTCL_EVT:
6369 * During bb credit recovery establishment, receiving
6370 * this attention type is normal. Link Up attention
6371 * type is expected to occur before this informational
6372 * attention type so keep the Link Up status.
6374 log_level = KERN_INFO;
6375 phba->sli4_hba.link_state.status =
6376 LPFC_FC_LA_TYPE_LINK_UP;
6379 log_level = KERN_INFO;
6382 lpfc_log_msg(phba, log_level, LOG_SLI,
6383 "2992 Async FC event - Informational Link "
6384 "Attention Type x%x\n",
6385 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc));
6389 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6391 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6392 "2897 The mboxq allocation failed\n");
6395 rc = lpfc_mbox_rsrc_prep(phba, pmb);
6397 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6398 "2898 The mboxq prep failed\n");
6402 /* Cleanup any outstanding ELS commands */
6403 lpfc_els_flush_all_cmd(phba);
6405 /* Block ELS IOCBs until we have done process link event */
6406 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
6408 /* Update link event statistics */
6409 phba->sli.slistat.link_event++;
6411 /* Create lpfc_handle_latt mailbox command from link ACQE */
6412 lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
6413 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
6414 pmb->vport = phba->pport;
6416 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
6417 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
6419 switch (phba->sli4_hba.link_state.status) {
6420 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
6421 phba->link_flag |= LS_MDS_LINK_DOWN;
6423 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
6424 phba->link_flag |= LS_MDS_LOOPBACK;
6430 /* Initialize completion status */
6432 mb->mbxStatus = MBX_SUCCESS;
6434 /* Parse port fault information field */
6435 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
6437 /* Parse and translate link attention fields */
6438 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
6439 la->eventTag = acqe_fc->event_tag;
6441 if (phba->sli4_hba.link_state.status ==
6442 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
6443 bf_set(lpfc_mbx_read_top_att_type, la,
6444 LPFC_FC_LA_TYPE_UNEXP_WWPN);
6446 bf_set(lpfc_mbx_read_top_att_type, la,
6447 LPFC_FC_LA_TYPE_LINK_DOWN);
6449 /* Invoke the mailbox command callback function */
6450 lpfc_mbx_cmpl_read_topology(phba, pmb);
6455 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
6456 if (rc == MBX_NOT_FINISHED)
6461 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6465 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
6466 * @phba: pointer to lpfc hba data structure.
6467 * @acqe_sli: pointer to the async SLI completion queue entry.
6469 * This routine is to handle the SLI4 asynchronous SLI events.
6472 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
6478 uint8_t operational = 0;
6479 struct temp_event temp_event_data;
6480 struct lpfc_acqe_misconfigured_event *misconfigured;
6481 struct lpfc_acqe_cgn_signal *cgn_signal;
6482 struct Scsi_Host *shost;
6483 struct lpfc_vport **vports;
6486 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
6488 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6489 "2901 Async SLI event - Type:%d, Event Data: x%08x "
6490 "x%08x x%08x x%08x\n", evt_type,
6491 acqe_sli->event_data1, acqe_sli->event_data2,
6492 acqe_sli->event_data3, acqe_sli->trailer);
6494 port_name = phba->Port[0];
6495 if (port_name == 0x00)
6496 port_name = '?'; /* get port name is empty */
6499 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
6500 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6501 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6502 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6504 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6505 "3190 Over Temperature:%d Celsius- Port Name %c\n",
6506 acqe_sli->event_data1, port_name);
6508 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
6509 shost = lpfc_shost_from_vport(phba->pport);
6510 fc_host_post_vendor_event(shost, fc_get_event_number(),
6511 sizeof(temp_event_data),
6512 (char *)&temp_event_data,
6513 SCSI_NL_VID_TYPE_PCI
6514 | PCI_VENDOR_ID_EMULEX);
6516 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
6517 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6518 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6519 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6521 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_LDS_EVENT,
6522 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
6523 acqe_sli->event_data1, port_name);
6525 shost = lpfc_shost_from_vport(phba->pport);
6526 fc_host_post_vendor_event(shost, fc_get_event_number(),
6527 sizeof(temp_event_data),
6528 (char *)&temp_event_data,
6529 SCSI_NL_VID_TYPE_PCI
6530 | PCI_VENDOR_ID_EMULEX);
6532 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
6533 misconfigured = (struct lpfc_acqe_misconfigured_event *)
6534 &acqe_sli->event_data1;
6536 /* fetch the status for this port */
6537 switch (phba->sli4_hba.lnk_info.lnk_no) {
6538 case LPFC_LINK_NUMBER_0:
6539 status = bf_get(lpfc_sli_misconfigured_port0_state,
6540 &misconfigured->theEvent);
6541 operational = bf_get(lpfc_sli_misconfigured_port0_op,
6542 &misconfigured->theEvent);
6544 case LPFC_LINK_NUMBER_1:
6545 status = bf_get(lpfc_sli_misconfigured_port1_state,
6546 &misconfigured->theEvent);
6547 operational = bf_get(lpfc_sli_misconfigured_port1_op,
6548 &misconfigured->theEvent);
6550 case LPFC_LINK_NUMBER_2:
6551 status = bf_get(lpfc_sli_misconfigured_port2_state,
6552 &misconfigured->theEvent);
6553 operational = bf_get(lpfc_sli_misconfigured_port2_op,
6554 &misconfigured->theEvent);
6556 case LPFC_LINK_NUMBER_3:
6557 status = bf_get(lpfc_sli_misconfigured_port3_state,
6558 &misconfigured->theEvent);
6559 operational = bf_get(lpfc_sli_misconfigured_port3_op,
6560 &misconfigured->theEvent);
6563 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6565 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
6566 "event: Invalid link %d",
6567 phba->sli4_hba.lnk_info.lnk_no);
6571 /* Skip if optic state unchanged */
6572 if (phba->sli4_hba.lnk_info.optic_state == status)
6576 case LPFC_SLI_EVENT_STATUS_VALID:
6577 sprintf(message, "Physical Link is functional");
6579 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
6580 sprintf(message, "Optics faulted/incorrectly "
6581 "installed/not installed - Reseat optics, "
6582 "if issue not resolved, replace.");
6584 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
6586 "Optics of two types installed - Remove one "
6587 "optic or install matching pair of optics.");
6589 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
6590 sprintf(message, "Incompatible optics - Replace with "
6591 "compatible optics for card to function.");
6593 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
6594 sprintf(message, "Unqualified optics - Replace with "
6595 "Avago optics for Warranty and Technical "
6596 "Support - Link is%s operational",
6597 (operational) ? " not" : "");
6599 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
6600 sprintf(message, "Uncertified optics - Replace with "
6601 "Avago-certified optics to enable link "
6602 "operation - Link is%s operational",
6603 (operational) ? " not" : "");
6606 /* firmware is reporting a status we don't know about */
6607 sprintf(message, "Unknown event status x%02x", status);
6611 /* Issue READ_CONFIG mbox command to refresh supported speeds */
6612 rc = lpfc_sli4_read_config(phba);
6615 lpfc_printf_log(phba, KERN_ERR,
6617 "3194 Unable to retrieve supported "
6618 "speeds, rc = 0x%x\n", rc);
6620 rc = lpfc_sli4_refresh_params(phba);
6622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6623 "3174 Unable to update pls support, "
6626 vports = lpfc_create_vport_work_array(phba);
6627 if (vports != NULL) {
6628 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6630 shost = lpfc_shost_from_vport(vports[i]);
6631 lpfc_host_supported_speeds_set(shost);
6634 lpfc_destroy_vport_work_array(phba, vports);
6636 phba->sli4_hba.lnk_info.optic_state = status;
6637 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6638 "3176 Port Name %c %s\n", port_name, message);
6640 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
6641 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6642 "3192 Remote DPort Test Initiated - "
6643 "Event Data1:x%08x Event Data2: x%08x\n",
6644 acqe_sli->event_data1, acqe_sli->event_data2);
6646 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
6647 /* Call FW to obtain active parms */
6648 lpfc_sli4_cgn_parm_chg_evt(phba);
6650 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
6651 /* Misconfigured WWN. Reports that the SLI Port is configured
6652 * to use FA-WWN, but the attached device doesn’t support it.
6653 * Event Data1 - N.A, Event Data2 - N.A
6654 * This event only happens on the physical port.
6656 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI | LOG_DISCOVERY,
6657 "2699 Misconfigured FA-PWWN - Attached device "
6658 "does not support FA-PWWN\n");
6659 phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_FABRIC;
6660 memset(phba->pport->fc_portname.u.wwn, 0,
6661 sizeof(struct lpfc_name));
6663 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
6664 /* EEPROM failure. No driver action is required */
6665 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6666 "2518 EEPROM failure - "
6667 "Event Data1: x%08x Event Data2: x%08x\n",
6668 acqe_sli->event_data1, acqe_sli->event_data2);
6670 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
6671 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6673 cgn_signal = (struct lpfc_acqe_cgn_signal *)
6674 &acqe_sli->event_data1;
6675 phba->cgn_acqe_cnt++;
6677 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6678 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6679 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6681 /* no threshold for CMF, even 1 signal will trigger an event */
6683 /* Alarm overrides warning, so check that first */
6684 if (cgn_signal->alarm_cnt) {
6685 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6686 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6687 atomic_add(cgn_signal->alarm_cnt,
6688 &phba->cgn_sync_alarm_cnt);
6691 /* signal action needs to be taken */
6692 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6693 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6694 /* Keep track of warning cnt for CMF_SYNC_WQE */
6695 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6699 case LPFC_SLI_EVENT_TYPE_RD_SIGNAL:
6700 /* May be accompanied by a temperature event */
6701 lpfc_printf_log(phba, KERN_INFO,
6702 LOG_SLI | LOG_LINK_EVENT | LOG_LDS_EVENT,
6703 "2902 Remote Degrade Signaling: x%08x x%08x "
6705 acqe_sli->event_data1, acqe_sli->event_data2,
6706 acqe_sli->event_data3);
6709 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6710 "3193 Unrecognized SLI event, type: 0x%x",
6717 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6718 * @vport: pointer to vport data structure.
6720 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6721 * response to a CVL event.
6723 * Return the pointer to the ndlp with the vport if successful, otherwise
6726 static struct lpfc_nodelist *
6727 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6729 struct lpfc_nodelist *ndlp;
6730 struct Scsi_Host *shost;
6731 struct lpfc_hba *phba;
6738 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6740 /* Cannot find existing Fabric ndlp, so allocate a new one */
6741 ndlp = lpfc_nlp_init(vport, Fabric_DID);
6744 /* Set the node type */
6745 ndlp->nlp_type |= NLP_FABRIC;
6746 /* Put ndlp onto node list */
6747 lpfc_enqueue_node(vport, ndlp);
6749 if ((phba->pport->port_state < LPFC_FLOGI) &&
6750 (phba->pport->port_state != LPFC_VPORT_FAILED))
6752 /* If virtual link is not yet instantiated ignore CVL */
6753 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6754 && (vport->port_state != LPFC_VPORT_FAILED))
6756 shost = lpfc_shost_from_vport(vport);
6759 lpfc_linkdown_port(vport);
6760 lpfc_cleanup_pending_mbox(vport);
6761 spin_lock_irq(shost->host_lock);
6762 vport->fc_flag |= FC_VPORT_CVL_RCVD;
6763 spin_unlock_irq(shost->host_lock);
6769 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
6770 * @phba: pointer to lpfc hba data structure.
6772 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6773 * response to a FCF dead event.
6776 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6778 struct lpfc_vport **vports;
6781 vports = lpfc_create_vport_work_array(phba);
6783 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6784 lpfc_sli4_perform_vport_cvl(vports[i]);
6785 lpfc_destroy_vport_work_array(phba, vports);
6789 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
6790 * @phba: pointer to lpfc hba data structure.
6791 * @acqe_fip: pointer to the async fcoe completion queue entry.
6793 * This routine is to handle the SLI4 asynchronous fcoe event.
6796 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
6797 struct lpfc_acqe_fip *acqe_fip)
6799 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
6801 struct lpfc_vport *vport;
6802 struct lpfc_nodelist *ndlp;
6803 int active_vlink_present;
6804 struct lpfc_vport **vports;
6807 phba->fc_eventTag = acqe_fip->event_tag;
6808 phba->fcoe_eventtag = acqe_fip->event_tag;
6809 switch (event_type) {
6810 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6811 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6812 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
6813 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6814 "2546 New FCF event, evt_tag:x%x, "
6816 acqe_fip->event_tag,
6819 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6821 "2788 FCF param modified event, "
6822 "evt_tag:x%x, index:x%x\n",
6823 acqe_fip->event_tag,
6825 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6827 * During period of FCF discovery, read the FCF
6828 * table record indexed by the event to update
6829 * FCF roundrobin failover eligible FCF bmask.
6831 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6833 "2779 Read FCF (x%x) for updating "
6834 "roundrobin FCF failover bmask\n",
6836 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
6839 /* If the FCF discovery is in progress, do nothing. */
6840 spin_lock_irq(&phba->hbalock);
6841 if (phba->hba_flag & FCF_TS_INPROG) {
6842 spin_unlock_irq(&phba->hbalock);
6845 /* If fast FCF failover rescan event is pending, do nothing */
6846 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
6847 spin_unlock_irq(&phba->hbalock);
6851 /* If the FCF has been in discovered state, do nothing. */
6852 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
6853 spin_unlock_irq(&phba->hbalock);
6856 spin_unlock_irq(&phba->hbalock);
6858 /* Otherwise, scan the entire FCF table and re-discover SAN */
6859 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6860 "2770 Start FCF table scan per async FCF "
6861 "event, evt_tag:x%x, index:x%x\n",
6862 acqe_fip->event_tag, acqe_fip->index);
6863 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6864 LPFC_FCOE_FCF_GET_FIRST);
6866 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6867 "2547 Issue FCF scan read FCF mailbox "
6868 "command failed (x%x)\n", rc);
6871 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
6872 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6873 "2548 FCF Table full count 0x%x tag 0x%x\n",
6874 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6875 acqe_fip->event_tag);
6878 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
6879 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6880 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6881 "2549 FCF (x%x) disconnected from network, "
6882 "tag:x%x\n", acqe_fip->index,
6883 acqe_fip->event_tag);
6885 * If we are in the middle of FCF failover process, clear
6886 * the corresponding FCF bit in the roundrobin bitmap.
6888 spin_lock_irq(&phba->hbalock);
6889 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6890 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
6891 spin_unlock_irq(&phba->hbalock);
6892 /* Update FLOGI FCF failover eligible FCF bmask */
6893 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
6896 spin_unlock_irq(&phba->hbalock);
6898 /* If the event is not for currently used fcf do nothing */
6899 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
6903 * Otherwise, request the port to rediscover the entire FCF
6904 * table for a fast recovery from case that the current FCF
6905 * is no longer valid as we are not in the middle of FCF
6906 * failover process already.
6908 spin_lock_irq(&phba->hbalock);
6909 /* Mark the fast failover process in progress */
6910 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6911 spin_unlock_irq(&phba->hbalock);
6913 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6914 "2771 Start FCF fast failover process due to "
6915 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6916 "\n", acqe_fip->event_tag, acqe_fip->index);
6917 rc = lpfc_sli4_redisc_fcf_table(phba);
6919 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6921 "2772 Issue FCF rediscover mailbox "
6922 "command failed, fail through to FCF "
6924 spin_lock_irq(&phba->hbalock);
6925 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6926 spin_unlock_irq(&phba->hbalock);
6928 * Last resort will fail over by treating this
6929 * as a link down to FCF registration.
6931 lpfc_sli4_fcf_dead_failthrough(phba);
6933 /* Reset FCF roundrobin bmask for new discovery */
6934 lpfc_sli4_clear_fcf_rr_bmask(phba);
6936 * Handling fast FCF failover to a DEAD FCF event is
6937 * considered equalivant to receiving CVL to all vports.
6939 lpfc_sli4_perform_all_vport_cvl(phba);
6942 case LPFC_FIP_EVENT_TYPE_CVL:
6943 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6944 lpfc_printf_log(phba, KERN_ERR,
6946 "2718 Clear Virtual Link Received for VPI 0x%x"
6947 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
6949 vport = lpfc_find_vport_by_vpid(phba,
6951 ndlp = lpfc_sli4_perform_vport_cvl(vport);
6954 active_vlink_present = 0;
6956 vports = lpfc_create_vport_work_array(phba);
6958 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6960 if ((!(vports[i]->fc_flag &
6961 FC_VPORT_CVL_RCVD)) &&
6962 (vports[i]->port_state > LPFC_FDISC)) {
6963 active_vlink_present = 1;
6967 lpfc_destroy_vport_work_array(phba, vports);
6971 * Don't re-instantiate if vport is marked for deletion.
6972 * If we are here first then vport_delete is going to wait
6973 * for discovery to complete.
6975 if (!(vport->load_flag & FC_UNLOADING) &&
6976 active_vlink_present) {
6978 * If there are other active VLinks present,
6979 * re-instantiate the Vlink using FDISC.
6981 mod_timer(&ndlp->nlp_delayfunc,
6982 jiffies + msecs_to_jiffies(1000));
6983 spin_lock_irq(&ndlp->lock);
6984 ndlp->nlp_flag |= NLP_DELAY_TMO;
6985 spin_unlock_irq(&ndlp->lock);
6986 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6987 vport->port_state = LPFC_FDISC;
6990 * Otherwise, we request port to rediscover
6991 * the entire FCF table for a fast recovery
6992 * from possible case that the current FCF
6993 * is no longer valid if we are not already
6994 * in the FCF failover process.
6996 spin_lock_irq(&phba->hbalock);
6997 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6998 spin_unlock_irq(&phba->hbalock);
7001 /* Mark the fast failover process in progress */
7002 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
7003 spin_unlock_irq(&phba->hbalock);
7004 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
7006 "2773 Start FCF failover per CVL, "
7007 "evt_tag:x%x\n", acqe_fip->event_tag);
7008 rc = lpfc_sli4_redisc_fcf_table(phba);
7010 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
7012 "2774 Issue FCF rediscover "
7013 "mailbox command failed, "
7014 "through to CVL event\n");
7015 spin_lock_irq(&phba->hbalock);
7016 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
7017 spin_unlock_irq(&phba->hbalock);
7019 * Last resort will be re-try on the
7020 * the current registered FCF entry.
7022 lpfc_retry_pport_discovery(phba);
7025 * Reset FCF roundrobin bmask for new
7028 lpfc_sli4_clear_fcf_rr_bmask(phba);
7032 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7033 "0288 Unknown FCoE event type 0x%x event tag "
7034 "0x%x\n", event_type, acqe_fip->event_tag);
7040 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
7041 * @phba: pointer to lpfc hba data structure.
7042 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
7044 * This routine is to handle the SLI4 asynchronous dcbx event.
7047 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
7048 struct lpfc_acqe_dcbx *acqe_dcbx)
7050 phba->fc_eventTag = acqe_dcbx->event_tag;
7051 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7052 "0290 The SLI4 DCBX asynchronous event is not "
7057 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
7058 * @phba: pointer to lpfc hba data structure.
7059 * @acqe_grp5: pointer to the async grp5 completion queue entry.
7061 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
7062 * is an asynchronous notified of a logical link speed change. The Port
7063 * reports the logical link speed in units of 10Mbps.
7066 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
7067 struct lpfc_acqe_grp5 *acqe_grp5)
7069 uint16_t prev_ll_spd;
7071 phba->fc_eventTag = acqe_grp5->event_tag;
7072 phba->fcoe_eventtag = acqe_grp5->event_tag;
7073 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
7074 phba->sli4_hba.link_state.logical_speed =
7075 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
7076 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7077 "2789 GRP5 Async Event: Updating logical link speed "
7078 "from %dMbps to %dMbps\n", prev_ll_spd,
7079 phba->sli4_hba.link_state.logical_speed);
7083 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
7084 * @phba: pointer to lpfc hba data structure.
7086 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
7087 * is an asynchronous notification of a request to reset CM stats.
7090 lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
7094 lpfc_init_congestion_stat(phba);
7098 * lpfc_cgn_params_val - Validate FW congestion parameters.
7099 * @phba: pointer to lpfc hba data structure.
7100 * @p_cfg_param: pointer to FW provided congestion parameters.
7102 * This routine validates the congestion parameters passed
7103 * by the FW to the driver via an ACQE event.
7106 lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
7108 spin_lock_irq(&phba->hbalock);
7110 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
7111 LPFC_CFG_MONITOR)) {
7112 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
7113 "6225 CMF mode param out of range: %d\n",
7114 p_cfg_param->cgn_param_mode);
7115 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
7118 spin_unlock_irq(&phba->hbalock);
7121 static const char * const lpfc_cmf_mode_to_str[] = {
7128 * lpfc_cgn_params_parse - Process a FW cong parm change event
7129 * @phba: pointer to lpfc hba data structure.
7130 * @p_cgn_param: pointer to a data buffer with the FW cong params.
7131 * @len: the size of pdata in bytes.
7133 * This routine validates the congestion management buffer signature
7134 * from the FW, validates the contents and makes corrections for
7135 * valid, in-range values. If the signature magic is correct and
7136 * after parameter validation, the contents are copied to the driver's
7137 * @phba structure. If the magic is incorrect, an error message is
7141 lpfc_cgn_params_parse(struct lpfc_hba *phba,
7142 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
7144 struct lpfc_cgn_info *cp;
7145 uint32_t crc, oldmode;
7146 char acr_string[4] = {0};
7148 /* Make sure the FW has encoded the correct magic number to
7149 * validate the congestion parameter in FW memory.
7151 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
7152 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7153 "4668 FW cgn parm buffer data: "
7154 "magic 0x%x version %d mode %d "
7155 "level0 %d level1 %d "
7156 "level2 %d byte13 %d "
7157 "byte14 %d byte15 %d "
7158 "byte11 %d byte12 %d activeMode %d\n",
7159 p_cgn_param->cgn_param_magic,
7160 p_cgn_param->cgn_param_version,
7161 p_cgn_param->cgn_param_mode,
7162 p_cgn_param->cgn_param_level0,
7163 p_cgn_param->cgn_param_level1,
7164 p_cgn_param->cgn_param_level2,
7165 p_cgn_param->byte13,
7166 p_cgn_param->byte14,
7167 p_cgn_param->byte15,
7168 p_cgn_param->byte11,
7169 p_cgn_param->byte12,
7170 phba->cmf_active_mode);
7172 oldmode = phba->cmf_active_mode;
7174 /* Any parameters out of range are corrected to defaults
7175 * by this routine. No need to fail.
7177 lpfc_cgn_params_val(phba, p_cgn_param);
7179 /* Parameters are verified, move them into driver storage */
7180 spin_lock_irq(&phba->hbalock);
7181 memcpy(&phba->cgn_p, p_cgn_param,
7182 sizeof(struct lpfc_cgn_param));
7184 /* Update parameters in congestion info buffer now */
7186 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
7187 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
7188 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
7189 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
7190 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
7191 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
7192 LPFC_CGN_CRC32_SEED);
7193 cp->cgn_info_crc = cpu_to_le32(crc);
7195 spin_unlock_irq(&phba->hbalock);
7197 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
7201 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
7202 /* Turning CMF on */
7203 lpfc_cmf_start(phba);
7205 if (phba->link_state >= LPFC_LINK_UP) {
7206 phba->cgn_reg_fpin =
7207 phba->cgn_init_reg_fpin;
7208 phba->cgn_reg_signal =
7209 phba->cgn_init_reg_signal;
7210 lpfc_issue_els_edc(phba->pport, 0);
7214 case LPFC_CFG_MANAGED:
7215 switch (phba->cgn_p.cgn_param_mode) {
7217 /* Turning CMF off */
7218 lpfc_cmf_stop(phba);
7219 if (phba->link_state >= LPFC_LINK_UP)
7220 lpfc_issue_els_edc(phba->pport, 0);
7222 case LPFC_CFG_MONITOR:
7223 phba->cmf_max_bytes_per_interval =
7224 phba->cmf_link_byte_count;
7226 /* Resume blocked IO - unblock on workqueue */
7227 queue_work(phba->wq,
7228 &phba->unblock_request_work);
7232 case LPFC_CFG_MONITOR:
7233 switch (phba->cgn_p.cgn_param_mode) {
7235 /* Turning CMF off */
7236 lpfc_cmf_stop(phba);
7237 if (phba->link_state >= LPFC_LINK_UP)
7238 lpfc_issue_els_edc(phba->pport, 0);
7240 case LPFC_CFG_MANAGED:
7241 lpfc_cmf_signal_init(phba);
7246 if (oldmode != LPFC_CFG_OFF ||
7247 oldmode != phba->cgn_p.cgn_param_mode) {
7248 if (phba->cgn_p.cgn_param_mode == LPFC_CFG_MANAGED)
7249 scnprintf(acr_string, sizeof(acr_string), "%u",
7250 phba->cgn_p.cgn_param_level0);
7252 scnprintf(acr_string, sizeof(acr_string), "NA");
7254 dev_info(&phba->pcidev->dev, "%d: "
7255 "4663 CMF: Mode %s acr %s\n",
7257 lpfc_cmf_mode_to_str
7258 [phba->cgn_p.cgn_param_mode],
7262 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7263 "4669 FW cgn parm buf wrong magic 0x%x "
7264 "version %d\n", p_cgn_param->cgn_param_magic,
7265 p_cgn_param->cgn_param_version);
7270 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
7271 * @phba: pointer to lpfc hba data structure.
7273 * This routine issues a read_object mailbox command to
7274 * get the congestion management parameters from the FW
7275 * parses it and updates the driver maintained values.
7278 * 0 if the object was empty
7279 * -Eval if an error was encountered
7280 * Count if bytes were read from object
7283 lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
7286 struct lpfc_cgn_param *p_cgn_param = NULL;
7290 /* Find out if the FW has a new set of congestion parameters. */
7291 len = sizeof(struct lpfc_cgn_param);
7292 pdata = kzalloc(len, GFP_KERNEL);
7293 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
7296 /* 0 means no data. A negative means error. A positive means
7297 * bytes were copied.
7300 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7301 "4670 CGN RD OBJ returns no data\n");
7303 } else if (ret < 0) {
7304 /* Some error. Just exit and return it to the caller.*/
7308 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7309 "6234 READ CGN PARAMS Successful %d\n", len);
7311 /* Parse data pointer over len and update the phba congestion
7312 * parameters with values passed back. The receive rate values
7313 * may have been altered in FW, but take no action here.
7315 p_cgn_param = (struct lpfc_cgn_param *)pdata;
7316 lpfc_cgn_params_parse(phba, p_cgn_param, len);
7324 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
7325 * @phba: pointer to lpfc hba data structure.
7327 * The FW generated Async ACQE SLI event calls this routine when
7328 * the event type is an SLI Internal Port Event and the Event Code
7329 * indicates a change to the FW maintained congestion parameters.
7331 * This routine executes a Read_Object mailbox call to obtain the
7332 * current congestion parameters maintained in FW and corrects
7333 * the driver's active congestion parameters.
7335 * The acqe event is not passed because there is no further data
7338 * Returns nonzero error if event processing encountered an error.
7339 * Zero otherwise for success.
7342 lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
7346 if (!phba->sli4_hba.pc_sli4_params.cmf) {
7347 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7348 "4664 Cgn Evt when E2E off. Drop event\n");
7352 /* If the event is claiming an empty object, it's ok. A write
7353 * could have cleared it. Only error is a negative return
7356 ret = lpfc_sli4_cgn_params_read(phba);
7358 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7359 "4667 Error reading Cgn Params (%d)\n",
7362 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7363 "4673 CGN Event empty object.\n");
7369 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
7370 * @phba: pointer to lpfc hba data structure.
7372 * This routine is invoked by the worker thread to process all the pending
7373 * SLI4 asynchronous events.
7375 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
7377 struct lpfc_cq_event *cq_event;
7378 unsigned long iflags;
7380 /* First, declare the async event has been handled */
7381 spin_lock_irqsave(&phba->hbalock, iflags);
7382 phba->hba_flag &= ~ASYNC_EVENT;
7383 spin_unlock_irqrestore(&phba->hbalock, iflags);
7385 /* Now, handle all the async events */
7386 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7387 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
7388 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
7389 cq_event, struct lpfc_cq_event, list);
7390 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
7393 /* Process the asynchronous event */
7394 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
7395 case LPFC_TRAILER_CODE_LINK:
7396 lpfc_sli4_async_link_evt(phba,
7397 &cq_event->cqe.acqe_link);
7399 case LPFC_TRAILER_CODE_FCOE:
7400 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
7402 case LPFC_TRAILER_CODE_DCBX:
7403 lpfc_sli4_async_dcbx_evt(phba,
7404 &cq_event->cqe.acqe_dcbx);
7406 case LPFC_TRAILER_CODE_GRP5:
7407 lpfc_sli4_async_grp5_evt(phba,
7408 &cq_event->cqe.acqe_grp5);
7410 case LPFC_TRAILER_CODE_FC:
7411 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
7413 case LPFC_TRAILER_CODE_SLI:
7414 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
7416 case LPFC_TRAILER_CODE_CMSTAT:
7417 lpfc_sli4_async_cmstat_evt(phba);
7420 lpfc_printf_log(phba, KERN_ERR,
7422 "1804 Invalid asynchronous event code: "
7423 "x%x\n", bf_get(lpfc_trailer_code,
7424 &cq_event->cqe.mcqe_cmpl));
7428 /* Free the completion event processed to the free pool */
7429 lpfc_sli4_cq_event_release(phba, cq_event);
7430 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
7432 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
7436 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
7437 * @phba: pointer to lpfc hba data structure.
7439 * This routine is invoked by the worker thread to process FCF table
7440 * rediscovery pending completion event.
7442 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
7446 spin_lock_irq(&phba->hbalock);
7447 /* Clear FCF rediscovery timeout event */
7448 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
7449 /* Clear driver fast failover FCF record flag */
7450 phba->fcf.failover_rec.flag = 0;
7451 /* Set state for FCF fast failover */
7452 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
7453 spin_unlock_irq(&phba->hbalock);
7455 /* Scan FCF table from the first entry to re-discover SAN */
7456 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
7457 "2777 Start post-quiescent FCF table scan\n");
7458 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
7460 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7461 "2747 Issue FCF scan read FCF mailbox "
7462 "command failed 0x%x\n", rc);
7466 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
7467 * @phba: pointer to lpfc hba data structure.
7468 * @dev_grp: The HBA PCI-Device group number.
7470 * This routine is invoked to set up the per HBA PCI-Device group function
7471 * API jump table entries.
7473 * Return: 0 if success, otherwise -ENODEV
7476 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7480 /* Set up lpfc PCI-device group */
7481 phba->pci_dev_grp = dev_grp;
7483 /* The LPFC_PCI_DEV_OC uses SLI4 */
7484 if (dev_grp == LPFC_PCI_DEV_OC)
7485 phba->sli_rev = LPFC_SLI_REV4;
7487 /* Set up device INIT API function jump table */
7488 rc = lpfc_init_api_table_setup(phba, dev_grp);
7491 /* Set up SCSI API function jump table */
7492 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
7495 /* Set up SLI API function jump table */
7496 rc = lpfc_sli_api_table_setup(phba, dev_grp);
7499 /* Set up MBOX API function jump table */
7500 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
7508 * lpfc_log_intr_mode - Log the active interrupt mode
7509 * @phba: pointer to lpfc hba data structure.
7510 * @intr_mode: active interrupt mode adopted.
7512 * This routine it invoked to log the currently used active interrupt mode
7515 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
7517 switch (intr_mode) {
7519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7520 "0470 Enable INTx interrupt mode.\n");
7523 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7524 "0481 Enabled MSI interrupt mode.\n");
7527 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7528 "0480 Enabled MSI-X interrupt mode.\n");
7531 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7532 "0482 Illegal interrupt mode.\n");
7539 * lpfc_enable_pci_dev - Enable a generic PCI device.
7540 * @phba: pointer to lpfc hba data structure.
7542 * This routine is invoked to enable the PCI device that is common to all
7547 * other values - error
7550 lpfc_enable_pci_dev(struct lpfc_hba *phba)
7552 struct pci_dev *pdev;
7554 /* Obtain PCI device reference */
7558 pdev = phba->pcidev;
7559 /* Enable PCI device */
7560 if (pci_enable_device_mem(pdev))
7562 /* Request PCI resource for the device */
7563 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
7564 goto out_disable_device;
7565 /* Set up device as PCI master and save state for EEH */
7566 pci_set_master(pdev);
7567 pci_try_set_mwi(pdev);
7568 pci_save_state(pdev);
7570 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
7571 if (pci_is_pcie(pdev))
7572 pdev->needs_freset = 1;
7577 pci_disable_device(pdev);
7579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7580 "1401 Failed to enable pci device\n");
7585 * lpfc_disable_pci_dev - Disable a generic PCI device.
7586 * @phba: pointer to lpfc hba data structure.
7588 * This routine is invoked to disable the PCI device that is common to all
7592 lpfc_disable_pci_dev(struct lpfc_hba *phba)
7594 struct pci_dev *pdev;
7596 /* Obtain PCI device reference */
7600 pdev = phba->pcidev;
7601 /* Release PCI resource and disable PCI device */
7602 pci_release_mem_regions(pdev);
7603 pci_disable_device(pdev);
7609 * lpfc_reset_hba - Reset a hba
7610 * @phba: pointer to lpfc hba data structure.
7612 * This routine is invoked to reset a hba device. It brings the HBA
7613 * offline, performs a board restart, and then brings the board back
7614 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
7615 * on outstanding mailbox commands.
7618 lpfc_reset_hba(struct lpfc_hba *phba)
7620 /* If resets are disabled then set error state and return. */
7621 if (!phba->cfg_enable_hba_reset) {
7622 phba->link_state = LPFC_HBA_ERROR;
7626 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
7627 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
7628 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
7630 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
7631 lpfc_sli_flush_io_rings(phba);
7634 lpfc_sli_brdrestart(phba);
7636 lpfc_unblock_mgmt_io(phba);
7640 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
7641 * @phba: pointer to lpfc hba data structure.
7643 * This function enables the PCI SR-IOV virtual functions to a physical
7644 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7645 * enable the number of virtual functions to the physical function. As
7646 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7647 * API call does not considered as an error condition for most of the device.
7650 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
7652 struct pci_dev *pdev = phba->pcidev;
7656 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
7660 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
7665 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
7666 * @phba: pointer to lpfc hba data structure.
7667 * @nr_vfn: number of virtual functions to be enabled.
7669 * This function enables the PCI SR-IOV virtual functions to a physical
7670 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7671 * enable the number of virtual functions to the physical function. As
7672 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7673 * API call does not considered as an error condition for most of the device.
7676 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
7678 struct pci_dev *pdev = phba->pcidev;
7679 uint16_t max_nr_vfn;
7682 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
7683 if (nr_vfn > max_nr_vfn) {
7684 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7685 "3057 Requested vfs (%d) greater than "
7686 "supported vfs (%d)", nr_vfn, max_nr_vfn);
7690 rc = pci_enable_sriov(pdev, nr_vfn);
7692 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7693 "2806 Failed to enable sriov on this device "
7694 "with vfn number nr_vf:%d, rc:%d\n",
7697 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7698 "2807 Successful enable sriov on this device "
7699 "with vfn number nr_vf:%d\n", nr_vfn);
7704 lpfc_unblock_requests_work(struct work_struct *work)
7706 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
7707 unblock_request_work);
7709 lpfc_unblock_requests(phba);
7713 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
7714 * @phba: pointer to lpfc hba data structure.
7716 * This routine is invoked to set up the driver internal resources before the
7717 * device specific resource setup to support the HBA device it attached to.
7721 * other values - error
7724 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
7726 struct lpfc_sli *psli = &phba->sli;
7729 * Driver resources common to all SLI revisions
7731 atomic_set(&phba->fast_event_count, 0);
7732 atomic_set(&phba->dbg_log_idx, 0);
7733 atomic_set(&phba->dbg_log_cnt, 0);
7734 atomic_set(&phba->dbg_log_dmping, 0);
7735 spin_lock_init(&phba->hbalock);
7737 /* Initialize port_list spinlock */
7738 spin_lock_init(&phba->port_list_lock);
7739 INIT_LIST_HEAD(&phba->port_list);
7741 INIT_LIST_HEAD(&phba->work_list);
7743 /* Initialize the wait queue head for the kernel thread */
7744 init_waitqueue_head(&phba->work_waitq);
7746 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7747 "1403 Protocols supported %s %s %s\n",
7748 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7750 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
7752 (phba->nvmet_support ? "NVMET" : " "));
7754 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7755 spin_lock_init(&phba->scsi_buf_list_get_lock);
7756 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7757 spin_lock_init(&phba->scsi_buf_list_put_lock);
7758 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
7760 /* Initialize the fabric iocb list */
7761 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7763 /* Initialize list to save ELS buffers */
7764 INIT_LIST_HEAD(&phba->elsbuf);
7766 /* Initialize FCF connection rec list */
7767 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7769 /* Initialize OAS configuration list */
7770 spin_lock_init(&phba->devicelock);
7771 INIT_LIST_HEAD(&phba->luns);
7773 /* MBOX heartbeat timer */
7774 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
7775 /* Fabric block timer */
7776 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
7777 /* EA polling mode timer */
7778 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
7779 /* Heartbeat timer */
7780 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
7782 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7784 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7785 lpfc_idle_stat_delay_work);
7786 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
7791 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7792 * @phba: pointer to lpfc hba data structure.
7794 * This routine is invoked to set up the driver internal resources specific to
7795 * support the SLI-3 HBA device it attached to.
7799 * other values - error
7802 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7807 * Initialize timers used by driver
7810 /* FCP polling mode timer */
7811 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
7813 /* Host attention work mask setup */
7814 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7815 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7817 /* Get all the module params for configuring this host */
7818 lpfc_get_cfgparam(phba);
7819 /* Set up phase-1 common device driver resources */
7821 rc = lpfc_setup_driver_resource_phase1(phba);
7825 if (!phba->sli.sli3_ring)
7826 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7827 sizeof(struct lpfc_sli_ring),
7829 if (!phba->sli.sli3_ring)
7833 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
7834 * used to create the sg_dma_buf_pool must be dynamically calculated.
7837 if (phba->sli_rev == LPFC_SLI_REV4)
7838 entry_sz = sizeof(struct sli4_sge);
7840 entry_sz = sizeof(struct ulp_bde64);
7842 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7843 if (phba->cfg_enable_bg) {
7845 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7846 * the FCP rsp, and a BDE for each. Sice we have no control
7847 * over how many protection data segments the SCSI Layer
7848 * will hand us (ie: there could be one for every block
7849 * in the IO), we just allocate enough BDEs to accomidate
7850 * our max amount and we need to limit lpfc_sg_seg_cnt to
7851 * minimize the risk of running out.
7853 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7854 sizeof(struct fcp_rsp) +
7855 (LPFC_MAX_SG_SEG_CNT * entry_sz);
7857 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7858 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7860 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7861 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7864 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7865 * the FCP rsp, a BDE for each, and a BDE for up to
7866 * cfg_sg_seg_cnt data segments.
7868 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7869 sizeof(struct fcp_rsp) +
7870 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
7872 /* Total BDEs in BPL for scsi_sg_list */
7873 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7877 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
7878 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7879 phba->cfg_total_seg_cnt);
7881 phba->max_vpi = LPFC_MAX_VPI;
7882 /* This will be set to correct value after config_port mbox */
7883 phba->max_vports = 0;
7886 * Initialize the SLI Layer to run with lpfc HBAs.
7888 lpfc_sli_setup(phba);
7889 lpfc_sli_queue_init(phba);
7891 /* Allocate device driver memory */
7892 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7895 phba->lpfc_sg_dma_buf_pool =
7896 dma_pool_create("lpfc_sg_dma_buf_pool",
7897 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7900 if (!phba->lpfc_sg_dma_buf_pool)
7903 phba->lpfc_cmd_rsp_buf_pool =
7904 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7906 sizeof(struct fcp_cmnd) +
7907 sizeof(struct fcp_rsp),
7910 if (!phba->lpfc_cmd_rsp_buf_pool)
7911 goto fail_free_dma_buf_pool;
7914 * Enable sr-iov virtual functions if supported and configured
7915 * through the module parameter.
7917 if (phba->cfg_sriov_nr_virtfn > 0) {
7918 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7919 phba->cfg_sriov_nr_virtfn);
7921 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7922 "2808 Requested number of SR-IOV "
7923 "virtual functions (%d) is not "
7925 phba->cfg_sriov_nr_virtfn);
7926 phba->cfg_sriov_nr_virtfn = 0;
7932 fail_free_dma_buf_pool:
7933 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7934 phba->lpfc_sg_dma_buf_pool = NULL;
7936 lpfc_mem_free(phba);
7941 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7942 * @phba: pointer to lpfc hba data structure.
7944 * This routine is invoked to unset the driver internal resources set up
7945 * specific for supporting the SLI-3 HBA device it attached to.
7948 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7950 /* Free device driver memory allocated */
7951 lpfc_mem_free_all(phba);
7957 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7958 * @phba: pointer to lpfc hba data structure.
7960 * This routine is invoked to set up the driver internal resources specific to
7961 * support the SLI-4 HBA device it attached to.
7965 * other values - error
7968 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7970 LPFC_MBOXQ_t *mboxq;
7972 int rc, i, max_buf_size;
7979 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7980 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
7981 phba->sli4_hba.curr_disp_cpu = 0;
7983 /* Get all the module params for configuring this host */
7984 lpfc_get_cfgparam(phba);
7986 /* Set up phase-1 common device driver resources */
7987 rc = lpfc_setup_driver_resource_phase1(phba);
7991 /* Before proceed, wait for POST done and device ready */
7992 rc = lpfc_sli4_post_status_check(phba);
7996 /* Allocate all driver workqueues here */
7998 /* The lpfc_wq workqueue for deferred irq use */
7999 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
8004 * Initialize timers used by driver
8007 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
8009 /* FCF rediscover timer */
8010 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
8012 /* CMF congestion timer */
8013 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
8014 phba->cmf_timer.function = lpfc_cmf_timer;
8017 * Control structure for handling external multi-buffer mailbox
8018 * command pass-through.
8020 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
8021 sizeof(struct lpfc_mbox_ext_buf_ctx));
8022 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
8024 phba->max_vpi = LPFC_MAX_VPI;
8026 /* This will be set to correct value after the read_config mbox */
8027 phba->max_vports = 0;
8029 /* Program the default value of vlan_id and fc_map */
8030 phba->valid_vlan = 0;
8031 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
8032 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
8033 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
8036 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
8037 * we will associate a new ring, for each EQ/CQ/WQ tuple.
8038 * The WQ create will allocate the ring.
8041 /* Initialize buffer queue management fields */
8042 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
8043 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
8044 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
8046 /* for VMID idle timeout if VMID is enabled */
8047 if (lpfc_is_vmid_enabled(phba))
8048 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
8051 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
8053 /* Initialize the Abort buffer list used by driver */
8054 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
8055 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
8057 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8058 /* Initialize the Abort nvme buffer list used by driver */
8059 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
8060 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8061 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
8062 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
8063 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
8066 /* This abort list used by worker thread */
8067 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
8068 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
8069 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
8070 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
8073 * Initialize driver internal slow-path work queues
8076 /* Driver internel slow-path CQ Event pool */
8077 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
8078 /* Response IOCB work queue list */
8079 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
8080 /* Asynchronous event CQ Event work queue list */
8081 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
8082 /* Slow-path XRI aborted CQ Event work queue list */
8083 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
8084 /* Receive queue CQ Event work queue list */
8085 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
8087 /* Initialize extent block lists. */
8088 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
8089 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
8090 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
8091 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
8093 /* Initialize mboxq lists. If the early init routines fail
8094 * these lists need to be correctly initialized.
8096 INIT_LIST_HEAD(&phba->sli.mboxq);
8097 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
8099 /* initialize optic_state to 0xFF */
8100 phba->sli4_hba.lnk_info.optic_state = 0xff;
8102 /* Allocate device driver memory */
8103 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
8105 goto out_destroy_workqueue;
8107 /* IF Type 2 ports get initialized now. */
8108 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
8109 LPFC_SLI_INTF_IF_TYPE_2) {
8110 rc = lpfc_pci_function_reset(phba);
8115 phba->temp_sensor_support = 1;
8118 /* Create the bootstrap mailbox command */
8119 rc = lpfc_create_bootstrap_mbox(phba);
8123 /* Set up the host's endian order with the device. */
8124 rc = lpfc_setup_endian_order(phba);
8126 goto out_free_bsmbx;
8128 /* Set up the hba's configuration parameters. */
8129 rc = lpfc_sli4_read_config(phba);
8131 goto out_free_bsmbx;
8133 if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
8134 /* Right now the link is down, if FA-PWWN is configured the
8135 * firmware will try FLOGI before the driver gets a link up.
8136 * If it fails, the driver should get a MISCONFIGURED async
8137 * event which will clear this flag. The only notification
8138 * the driver gets is if it fails, if it succeeds there is no
8139 * notification given. Assume success.
8141 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
8144 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
8146 goto out_free_bsmbx;
8148 /* IF Type 0 ports get initialized now. */
8149 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8150 LPFC_SLI_INTF_IF_TYPE_0) {
8151 rc = lpfc_pci_function_reset(phba);
8153 goto out_free_bsmbx;
8156 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8160 goto out_free_bsmbx;
8163 /* Check for NVMET being configured */
8164 phba->nvmet_support = 0;
8165 if (lpfc_enable_nvmet_cnt) {
8167 /* First get WWN of HBA instance */
8168 lpfc_read_nv(phba, mboxq);
8169 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8170 if (rc != MBX_SUCCESS) {
8171 lpfc_printf_log(phba, KERN_ERR,
8173 "6016 Mailbox failed , mbxCmd x%x "
8174 "READ_NV, mbxStatus x%x\n",
8175 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8176 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
8177 mempool_free(mboxq, phba->mbox_mem_pool);
8179 goto out_free_bsmbx;
8182 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
8184 wwn = cpu_to_be64(wwn);
8185 phba->sli4_hba.wwnn.u.name = wwn;
8186 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
8188 /* wwn is WWPN of HBA instance */
8189 wwn = cpu_to_be64(wwn);
8190 phba->sli4_hba.wwpn.u.name = wwn;
8192 /* Check to see if it matches any module parameter */
8193 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
8194 if (wwn == lpfc_enable_nvmet[i]) {
8195 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
8196 if (lpfc_nvmet_mem_alloc(phba))
8199 phba->nvmet_support = 1; /* a match */
8201 lpfc_printf_log(phba, KERN_ERR,
8203 "6017 NVME Target %016llx\n",
8206 lpfc_printf_log(phba, KERN_ERR,
8208 "6021 Can't enable NVME Target."
8209 " NVME_TARGET_FC infrastructure"
8210 " is not in kernel\n");
8212 /* Not supported for NVMET */
8213 phba->cfg_xri_rebalancing = 0;
8214 if (phba->irq_chann_mode == NHT_MODE) {
8215 phba->cfg_irq_chann =
8216 phba->sli4_hba.num_present_cpu;
8217 phba->cfg_hdw_queue =
8218 phba->sli4_hba.num_present_cpu;
8219 phba->irq_chann_mode = NORMAL_MODE;
8226 lpfc_nvme_mod_param_dep(phba);
8229 * Get sli4 parameters that override parameters from Port capabilities.
8230 * If this call fails, it isn't critical unless the SLI4 parameters come
8233 rc = lpfc_get_sli4_parameters(phba, mboxq);
8235 if_type = bf_get(lpfc_sli_intf_if_type,
8236 &phba->sli4_hba.sli_intf);
8237 if_fam = bf_get(lpfc_sli_intf_sli_family,
8238 &phba->sli4_hba.sli_intf);
8239 if (phba->sli4_hba.extents_in_use &&
8240 phba->sli4_hba.rpi_hdrs_in_use) {
8241 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8242 "2999 Unsupported SLI4 Parameters "
8243 "Extents and RPI headers enabled.\n");
8244 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8245 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
8246 mempool_free(mboxq, phba->mbox_mem_pool);
8248 goto out_free_bsmbx;
8251 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8252 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
8253 mempool_free(mboxq, phba->mbox_mem_pool);
8255 goto out_free_bsmbx;
8260 * 1 for cmd, 1 for rsp, NVME adds an extra one
8261 * for boundary conditions in its max_sgl_segment template.
8264 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
8268 * It doesn't matter what family our adapter is in, we are
8269 * limited to 2 Pages, 512 SGEs, for our SGL.
8270 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
8272 max_buf_size = (2 * SLI4_PAGE_SIZE);
8275 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
8276 * used to create the sg_dma_buf_pool must be calculated.
8278 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8279 /* Both cfg_enable_bg and cfg_external_dif code paths */
8282 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
8283 * the FCP rsp, and a SGE. Sice we have no control
8284 * over how many protection segments the SCSI Layer
8285 * will hand us (ie: there could be one for every block
8286 * in the IO), just allocate enough SGEs to accomidate
8287 * our max amount and we need to limit lpfc_sg_seg_cnt
8288 * to minimize the risk of running out.
8290 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8291 sizeof(struct fcp_rsp) + max_buf_size;
8293 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
8294 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
8297 * If supporting DIF, reduce the seg count for scsi to
8298 * allow room for the DIF sges.
8300 if (phba->cfg_enable_bg &&
8301 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
8302 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
8304 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8308 * The scsi_buf for a regular I/O holds the FCP cmnd,
8309 * the FCP rsp, a SGE for each, and a SGE for up to
8310 * cfg_sg_seg_cnt data segments.
8312 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8313 sizeof(struct fcp_rsp) +
8314 ((phba->cfg_sg_seg_cnt + extra) *
8315 sizeof(struct sli4_sge));
8317 /* Total SGEs for scsi_sg_list */
8318 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
8319 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8322 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
8323 * need to post 1 page for the SGL.
8327 if (phba->cfg_xpsgl && !phba->nvmet_support)
8328 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
8329 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
8330 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
8332 phba->cfg_sg_dma_buf_size =
8333 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
8335 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
8336 sizeof(struct sli4_sge);
8338 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
8339 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8340 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
8341 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
8342 "6300 Reducing NVME sg segment "
8344 LPFC_MAX_NVME_SEG_CNT);
8345 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
8347 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
8350 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
8351 "9087 sg_seg_cnt:%d dmabuf_size:%d "
8352 "total:%d scsi:%d nvme:%d\n",
8353 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
8354 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
8355 phba->cfg_nvme_seg_cnt);
8357 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
8358 i = phba->cfg_sg_dma_buf_size;
8362 phba->lpfc_sg_dma_buf_pool =
8363 dma_pool_create("lpfc_sg_dma_buf_pool",
8365 phba->cfg_sg_dma_buf_size,
8367 if (!phba->lpfc_sg_dma_buf_pool) {
8369 goto out_free_bsmbx;
8372 phba->lpfc_cmd_rsp_buf_pool =
8373 dma_pool_create("lpfc_cmd_rsp_buf_pool",
8375 sizeof(struct fcp_cmnd) +
8376 sizeof(struct fcp_rsp),
8378 if (!phba->lpfc_cmd_rsp_buf_pool) {
8380 goto out_free_sg_dma_buf;
8383 mempool_free(mboxq, phba->mbox_mem_pool);
8385 /* Verify OAS is supported */
8386 lpfc_sli4_oas_verify(phba);
8388 /* Verify RAS support on adapter */
8389 lpfc_sli4_ras_init(phba);
8391 /* Verify all the SLI4 queues */
8392 rc = lpfc_sli4_queue_verify(phba);
8394 goto out_free_cmd_rsp_buf;
8396 /* Create driver internal CQE event pool */
8397 rc = lpfc_sli4_cq_event_pool_create(phba);
8399 goto out_free_cmd_rsp_buf;
8401 /* Initialize sgl lists per host */
8402 lpfc_init_sgl_list(phba);
8404 /* Allocate and initialize active sgl array */
8405 rc = lpfc_init_active_sgl_array(phba);
8407 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8408 "1430 Failed to initialize sgl list.\n");
8409 goto out_destroy_cq_event_pool;
8411 rc = lpfc_sli4_init_rpi_hdrs(phba);
8413 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8414 "1432 Failed to initialize rpi headers.\n");
8415 goto out_free_active_sgl;
8418 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
8419 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
8420 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
8422 if (!phba->fcf.fcf_rr_bmask) {
8423 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8424 "2759 Failed allocate memory for FCF round "
8425 "robin failover bmask\n");
8427 goto out_remove_rpi_hdrs;
8430 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
8431 sizeof(struct lpfc_hba_eq_hdl),
8433 if (!phba->sli4_hba.hba_eq_hdl) {
8434 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8435 "2572 Failed allocate memory for "
8436 "fast-path per-EQ handle array\n");
8438 goto out_free_fcf_rr_bmask;
8441 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
8442 sizeof(struct lpfc_vector_map_info),
8444 if (!phba->sli4_hba.cpu_map) {
8445 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8446 "3327 Failed allocate memory for msi-x "
8447 "interrupt vector mapping\n");
8449 goto out_free_hba_eq_hdl;
8452 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
8453 if (!phba->sli4_hba.eq_info) {
8454 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8455 "3321 Failed allocation for per_cpu stats\n");
8457 goto out_free_hba_cpu_map;
8460 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
8461 sizeof(*phba->sli4_hba.idle_stat),
8463 if (!phba->sli4_hba.idle_stat) {
8464 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8465 "3390 Failed allocation for idle_stat\n");
8467 goto out_free_hba_eq_info;
8470 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8471 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
8472 if (!phba->sli4_hba.c_stat) {
8473 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8474 "3332 Failed allocating per cpu hdwq stats\n");
8476 goto out_free_hba_idle_stat;
8480 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
8481 if (!phba->cmf_stat) {
8482 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8483 "3331 Failed allocating per cpu cgn stats\n");
8485 goto out_free_hba_hdwq_info;
8489 * Enable sr-iov virtual functions if supported and configured
8490 * through the module parameter.
8492 if (phba->cfg_sriov_nr_virtfn > 0) {
8493 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
8494 phba->cfg_sriov_nr_virtfn);
8496 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8497 "3020 Requested number of SR-IOV "
8498 "virtual functions (%d) is not "
8500 phba->cfg_sriov_nr_virtfn);
8501 phba->cfg_sriov_nr_virtfn = 0;
8507 out_free_hba_hdwq_info:
8508 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8509 free_percpu(phba->sli4_hba.c_stat);
8510 out_free_hba_idle_stat:
8512 kfree(phba->sli4_hba.idle_stat);
8513 out_free_hba_eq_info:
8514 free_percpu(phba->sli4_hba.eq_info);
8515 out_free_hba_cpu_map:
8516 kfree(phba->sli4_hba.cpu_map);
8517 out_free_hba_eq_hdl:
8518 kfree(phba->sli4_hba.hba_eq_hdl);
8519 out_free_fcf_rr_bmask:
8520 kfree(phba->fcf.fcf_rr_bmask);
8521 out_remove_rpi_hdrs:
8522 lpfc_sli4_remove_rpi_hdrs(phba);
8523 out_free_active_sgl:
8524 lpfc_free_active_sgl(phba);
8525 out_destroy_cq_event_pool:
8526 lpfc_sli4_cq_event_pool_destroy(phba);
8527 out_free_cmd_rsp_buf:
8528 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
8529 phba->lpfc_cmd_rsp_buf_pool = NULL;
8530 out_free_sg_dma_buf:
8531 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
8532 phba->lpfc_sg_dma_buf_pool = NULL;
8534 lpfc_destroy_bootstrap_mbox(phba);
8536 lpfc_mem_free(phba);
8537 out_destroy_workqueue:
8538 destroy_workqueue(phba->wq);
8544 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
8545 * @phba: pointer to lpfc hba data structure.
8547 * This routine is invoked to unset the driver internal resources set up
8548 * specific for supporting the SLI-4 HBA device it attached to.
8551 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
8553 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
8555 free_percpu(phba->sli4_hba.eq_info);
8556 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8557 free_percpu(phba->sli4_hba.c_stat);
8559 free_percpu(phba->cmf_stat);
8560 kfree(phba->sli4_hba.idle_stat);
8562 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
8563 kfree(phba->sli4_hba.cpu_map);
8564 phba->sli4_hba.num_possible_cpu = 0;
8565 phba->sli4_hba.num_present_cpu = 0;
8566 phba->sli4_hba.curr_disp_cpu = 0;
8567 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
8569 /* Free memory allocated for fast-path work queue handles */
8570 kfree(phba->sli4_hba.hba_eq_hdl);
8572 /* Free the allocated rpi headers. */
8573 lpfc_sli4_remove_rpi_hdrs(phba);
8574 lpfc_sli4_remove_rpis(phba);
8576 /* Free eligible FCF index bmask */
8577 kfree(phba->fcf.fcf_rr_bmask);
8579 /* Free the ELS sgl list */
8580 lpfc_free_active_sgl(phba);
8581 lpfc_free_els_sgl_list(phba);
8582 lpfc_free_nvmet_sgl_list(phba);
8584 /* Free the completion queue EQ event pool */
8585 lpfc_sli4_cq_event_release_all(phba);
8586 lpfc_sli4_cq_event_pool_destroy(phba);
8588 /* Release resource identifiers. */
8589 lpfc_sli4_dealloc_resource_identifiers(phba);
8591 /* Free the bsmbx region. */
8592 lpfc_destroy_bootstrap_mbox(phba);
8594 /* Free the SLI Layer memory with SLI4 HBAs */
8595 lpfc_mem_free_all(phba);
8597 /* Free the current connect table */
8598 list_for_each_entry_safe(conn_entry, next_conn_entry,
8599 &phba->fcf_conn_rec_list, list) {
8600 list_del_init(&conn_entry->list);
8608 * lpfc_init_api_table_setup - Set up init api function jump table
8609 * @phba: The hba struct for which this call is being executed.
8610 * @dev_grp: The HBA PCI-Device group number.
8612 * This routine sets up the device INIT interface API function jump table
8615 * Returns: 0 - success, -ENODEV - failure.
8618 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8620 phba->lpfc_hba_init_link = lpfc_hba_init_link;
8621 phba->lpfc_hba_down_link = lpfc_hba_down_link;
8622 phba->lpfc_selective_reset = lpfc_selective_reset;
8624 case LPFC_PCI_DEV_LP:
8625 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
8626 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
8627 phba->lpfc_stop_port = lpfc_stop_port_s3;
8629 case LPFC_PCI_DEV_OC:
8630 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
8631 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
8632 phba->lpfc_stop_port = lpfc_stop_port_s4;
8635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8636 "1431 Invalid HBA PCI-device group: 0x%x\n",
8644 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
8645 * @phba: pointer to lpfc hba data structure.
8647 * This routine is invoked to set up the driver internal resources after the
8648 * device specific resource setup to support the HBA device it attached to.
8652 * other values - error
8655 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
8659 /* Startup the kernel thread for this host adapter. */
8660 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8661 "lpfc_worker_%d", phba->brd_no);
8662 if (IS_ERR(phba->worker_thread)) {
8663 error = PTR_ERR(phba->worker_thread);
8671 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
8672 * @phba: pointer to lpfc hba data structure.
8674 * This routine is invoked to unset the driver internal resources set up after
8675 * the device specific resource setup for supporting the HBA device it
8679 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
8682 destroy_workqueue(phba->wq);
8686 /* Stop kernel worker thread */
8687 if (phba->worker_thread)
8688 kthread_stop(phba->worker_thread);
8692 * lpfc_free_iocb_list - Free iocb list.
8693 * @phba: pointer to lpfc hba data structure.
8695 * This routine is invoked to free the driver's IOCB list and memory.
8698 lpfc_free_iocb_list(struct lpfc_hba *phba)
8700 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
8702 spin_lock_irq(&phba->hbalock);
8703 list_for_each_entry_safe(iocbq_entry, iocbq_next,
8704 &phba->lpfc_iocb_list, list) {
8705 list_del(&iocbq_entry->list);
8707 phba->total_iocbq_bufs--;
8709 spin_unlock_irq(&phba->hbalock);
8715 * lpfc_init_iocb_list - Allocate and initialize iocb list.
8716 * @phba: pointer to lpfc hba data structure.
8717 * @iocb_count: number of requested iocbs
8719 * This routine is invoked to allocate and initizlize the driver's IOCB
8720 * list and set up the IOCB tag array accordingly.
8724 * other values - error
8727 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8729 struct lpfc_iocbq *iocbq_entry = NULL;
8733 /* Initialize and populate the iocb list per host. */
8734 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
8735 for (i = 0; i < iocb_count; i++) {
8736 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
8737 if (iocbq_entry == NULL) {
8738 printk(KERN_ERR "%s: only allocated %d iocbs of "
8739 "expected %d count. Unloading driver.\n",
8740 __func__, i, iocb_count);
8741 goto out_free_iocbq;
8744 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8747 printk(KERN_ERR "%s: failed to allocate IOTAG. "
8748 "Unloading driver.\n", __func__);
8749 goto out_free_iocbq;
8751 iocbq_entry->sli4_lxritag = NO_XRI;
8752 iocbq_entry->sli4_xritag = NO_XRI;
8754 spin_lock_irq(&phba->hbalock);
8755 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8756 phba->total_iocbq_bufs++;
8757 spin_unlock_irq(&phba->hbalock);
8763 lpfc_free_iocb_list(phba);
8769 * lpfc_free_sgl_list - Free a given sgl list.
8770 * @phba: pointer to lpfc hba data structure.
8771 * @sglq_list: pointer to the head of sgl list.
8773 * This routine is invoked to free a give sgl list and memory.
8776 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
8778 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8780 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8781 list_del(&sglq_entry->list);
8782 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8788 * lpfc_free_els_sgl_list - Free els sgl list.
8789 * @phba: pointer to lpfc hba data structure.
8791 * This routine is invoked to free the driver's els sgl list and memory.
8794 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8796 LIST_HEAD(sglq_list);
8798 /* Retrieve all els sgls from driver list */
8799 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
8800 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
8801 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
8803 /* Now free the sgl list */
8804 lpfc_free_sgl_list(phba, &sglq_list);
8808 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8809 * @phba: pointer to lpfc hba data structure.
8811 * This routine is invoked to free the driver's nvmet sgl list and memory.
8814 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8816 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8817 LIST_HEAD(sglq_list);
8819 /* Retrieve all nvmet sgls from driver list */
8820 spin_lock_irq(&phba->hbalock);
8821 spin_lock(&phba->sli4_hba.sgl_list_lock);
8822 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8823 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8824 spin_unlock_irq(&phba->hbalock);
8826 /* Now free the sgl list */
8827 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8828 list_del(&sglq_entry->list);
8829 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8833 /* Update the nvmet_xri_cnt to reflect no current sgls.
8834 * The next initialization cycle sets the count and allocates
8835 * the sgls over again.
8837 phba->sli4_hba.nvmet_xri_cnt = 0;
8841 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8842 * @phba: pointer to lpfc hba data structure.
8844 * This routine is invoked to allocate the driver's active sgl memory.
8845 * This array will hold the sglq_entry's for active IOs.
8848 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8851 size = sizeof(struct lpfc_sglq *);
8852 size *= phba->sli4_hba.max_cfg_param.max_xri;
8854 phba->sli4_hba.lpfc_sglq_active_list =
8855 kzalloc(size, GFP_KERNEL);
8856 if (!phba->sli4_hba.lpfc_sglq_active_list)
8862 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8863 * @phba: pointer to lpfc hba data structure.
8865 * This routine is invoked to walk through the array of active sglq entries
8866 * and free all of the resources.
8867 * This is just a place holder for now.
8870 lpfc_free_active_sgl(struct lpfc_hba *phba)
8872 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8876 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8877 * @phba: pointer to lpfc hba data structure.
8879 * This routine is invoked to allocate and initizlize the driver's sgl
8880 * list and set up the sgl xritag tag array accordingly.
8884 lpfc_init_sgl_list(struct lpfc_hba *phba)
8886 /* Initialize and populate the sglq list per host/VF. */
8887 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
8888 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8889 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
8890 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8892 /* els xri-sgl book keeping */
8893 phba->sli4_hba.els_xri_cnt = 0;
8895 /* nvme xri-buffer book keeping */
8896 phba->sli4_hba.io_xri_cnt = 0;
8900 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8901 * @phba: pointer to lpfc hba data structure.
8903 * This routine is invoked to post rpi header templates to the
8904 * port for those SLI4 ports that do not support extents. This routine
8905 * posts a PAGE_SIZE memory region to the port to hold up to
8906 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8907 * and should be called only when interrupts are disabled.
8911 * -ERROR - otherwise.
8914 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8917 struct lpfc_rpi_hdr *rpi_hdr;
8919 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
8920 if (!phba->sli4_hba.rpi_hdrs_in_use)
8922 if (phba->sli4_hba.extents_in_use)
8925 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8927 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8928 "0391 Error during rpi post operation\n");
8929 lpfc_sli4_remove_rpis(phba);
8937 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8938 * @phba: pointer to lpfc hba data structure.
8940 * This routine is invoked to allocate a single 4KB memory region to
8941 * support rpis and stores them in the phba. This single region
8942 * provides support for up to 64 rpis. The region is used globally
8946 * A valid rpi hdr on success.
8947 * A NULL pointer on any failure.
8949 struct lpfc_rpi_hdr *
8950 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8952 uint16_t rpi_limit, curr_rpi_range;
8953 struct lpfc_dmabuf *dmabuf;
8954 struct lpfc_rpi_hdr *rpi_hdr;
8957 * If the SLI4 port supports extents, posting the rpi header isn't
8958 * required. Set the expected maximum count and let the actual value
8959 * get set when extents are fully allocated.
8961 if (!phba->sli4_hba.rpi_hdrs_in_use)
8963 if (phba->sli4_hba.extents_in_use)
8966 /* The limit on the logical index is just the max_rpi count. */
8967 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
8969 spin_lock_irq(&phba->hbalock);
8971 * Establish the starting RPI in this header block. The starting
8972 * rpi is normalized to a zero base because the physical rpi is
8975 curr_rpi_range = phba->sli4_hba.next_rpi;
8976 spin_unlock_irq(&phba->hbalock);
8978 /* Reached full RPI range */
8979 if (curr_rpi_range == rpi_limit)
8983 * First allocate the protocol header region for the port. The
8984 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8986 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8990 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8991 LPFC_HDR_TEMPLATE_SIZE,
8992 &dmabuf->phys, GFP_KERNEL);
8993 if (!dmabuf->virt) {
8995 goto err_free_dmabuf;
8998 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
9000 goto err_free_coherent;
9003 /* Save the rpi header data for cleanup later. */
9004 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
9006 goto err_free_coherent;
9008 rpi_hdr->dmabuf = dmabuf;
9009 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
9010 rpi_hdr->page_count = 1;
9011 spin_lock_irq(&phba->hbalock);
9013 /* The rpi_hdr stores the logical index only. */
9014 rpi_hdr->start_rpi = curr_rpi_range;
9015 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
9016 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
9018 spin_unlock_irq(&phba->hbalock);
9022 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
9023 dmabuf->virt, dmabuf->phys);
9030 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
9031 * @phba: pointer to lpfc hba data structure.
9033 * This routine is invoked to remove all memory resources allocated
9034 * to support rpis for SLI4 ports not supporting extents. This routine
9035 * presumes the caller has released all rpis consumed by fabric or port
9036 * logins and is prepared to have the header pages removed.
9039 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
9041 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
9043 if (!phba->sli4_hba.rpi_hdrs_in_use)
9046 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
9047 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
9048 list_del(&rpi_hdr->list);
9049 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
9050 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
9051 kfree(rpi_hdr->dmabuf);
9055 /* There are no rpis available to the port now. */
9056 phba->sli4_hba.next_rpi = 0;
9060 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
9061 * @pdev: pointer to pci device data structure.
9063 * This routine is invoked to allocate the driver hba data structure for an
9064 * HBA device. If the allocation is successful, the phba reference to the
9065 * PCI device data structure is set.
9068 * pointer to @phba - successful
9071 static struct lpfc_hba *
9072 lpfc_hba_alloc(struct pci_dev *pdev)
9074 struct lpfc_hba *phba;
9076 /* Allocate memory for HBA structure */
9077 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
9079 dev_err(&pdev->dev, "failed to allocate hba struct\n");
9083 /* Set reference to PCI device in HBA structure */
9084 phba->pcidev = pdev;
9086 /* Assign an unused board number */
9087 phba->brd_no = lpfc_get_instance();
9088 if (phba->brd_no < 0) {
9092 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
9094 spin_lock_init(&phba->ct_ev_lock);
9095 INIT_LIST_HEAD(&phba->ct_ev_waiters);
9101 * lpfc_hba_free - Free driver hba data structure with a device.
9102 * @phba: pointer to lpfc hba data structure.
9104 * This routine is invoked to free the driver hba data structure with an
9108 lpfc_hba_free(struct lpfc_hba *phba)
9110 if (phba->sli_rev == LPFC_SLI_REV4)
9111 kfree(phba->sli4_hba.hdwq);
9113 /* Release the driver assigned board number */
9114 idr_remove(&lpfc_hba_index, phba->brd_no);
9116 /* Free memory allocated with sli3 rings */
9117 kfree(phba->sli.sli3_ring);
9118 phba->sli.sli3_ring = NULL;
9125 * lpfc_setup_fdmi_mask - Setup initial FDMI mask for HBA and Port attributes
9126 * @vport: pointer to lpfc vport data structure.
9128 * This routine is will setup initial FDMI attribute masks for
9129 * FDMI2 or SmartSAN depending on module parameters. The driver will attempt
9130 * to get these attributes first before falling back, the attribute
9131 * fallback hierarchy is SmartSAN -> FDMI2 -> FMDI1
9134 lpfc_setup_fdmi_mask(struct lpfc_vport *vport)
9136 struct lpfc_hba *phba = vport->phba;
9138 vport->load_flag |= FC_ALLOW_FDMI;
9139 if (phba->cfg_enable_SmartSAN ||
9140 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) {
9141 /* Setup appropriate attribute masks */
9142 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
9143 if (phba->cfg_enable_SmartSAN)
9144 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
9146 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
9149 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
9150 "6077 Setup FDMI mask: hba x%x port x%x\n",
9151 vport->fdmi_hba_mask, vport->fdmi_port_mask);
9155 * lpfc_create_shost - Create hba physical port with associated scsi host.
9156 * @phba: pointer to lpfc hba data structure.
9158 * This routine is invoked to create HBA physical port and associate a SCSI
9163 * other values - error
9166 lpfc_create_shost(struct lpfc_hba *phba)
9168 struct lpfc_vport *vport;
9169 struct Scsi_Host *shost;
9171 /* Initialize HBA FC structure */
9172 phba->fc_edtov = FF_DEF_EDTOV;
9173 phba->fc_ratov = FF_DEF_RATOV;
9174 phba->fc_altov = FF_DEF_ALTOV;
9175 phba->fc_arbtov = FF_DEF_ARBTOV;
9177 atomic_set(&phba->sdev_cnt, 0);
9178 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
9182 shost = lpfc_shost_from_vport(vport);
9183 phba->pport = vport;
9185 if (phba->nvmet_support) {
9186 /* Only 1 vport (pport) will support NVME target */
9187 phba->targetport = NULL;
9188 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
9189 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
9190 "6076 NVME Target Found\n");
9193 lpfc_debugfs_initialize(vport);
9194 /* Put reference to SCSI host to driver's device private data */
9195 pci_set_drvdata(phba->pcidev, shost);
9197 lpfc_setup_fdmi_mask(vport);
9200 * At this point we are fully registered with PSA. In addition,
9201 * any initial discovery should be completed.
9207 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
9208 * @phba: pointer to lpfc hba data structure.
9210 * This routine is invoked to destroy HBA physical port and the associated
9214 lpfc_destroy_shost(struct lpfc_hba *phba)
9216 struct lpfc_vport *vport = phba->pport;
9218 /* Destroy physical port that associated with the SCSI host */
9219 destroy_port(vport);
9225 * lpfc_setup_bg - Setup Block guard structures and debug areas.
9226 * @phba: pointer to lpfc hba data structure.
9227 * @shost: the shost to be used to detect Block guard settings.
9229 * This routine sets up the local Block guard protocol settings for @shost.
9230 * This routine also allocates memory for debugging bg buffers.
9233 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
9238 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9239 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9240 "1478 Registering BlockGuard with the "
9243 old_mask = phba->cfg_prot_mask;
9244 old_guard = phba->cfg_prot_guard;
9246 /* Only allow supported values */
9247 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
9248 SHOST_DIX_TYPE0_PROTECTION |
9249 SHOST_DIX_TYPE1_PROTECTION);
9250 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
9251 SHOST_DIX_GUARD_CRC);
9253 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
9254 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
9255 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
9257 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9258 if ((old_mask != phba->cfg_prot_mask) ||
9259 (old_guard != phba->cfg_prot_guard))
9260 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9261 "1475 Registering BlockGuard with the "
9262 "SCSI layer: mask %d guard %d\n",
9263 phba->cfg_prot_mask,
9264 phba->cfg_prot_guard);
9266 scsi_host_set_prot(shost, phba->cfg_prot_mask);
9267 scsi_host_set_guard(shost, phba->cfg_prot_guard);
9269 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9270 "1479 Not Registering BlockGuard with the SCSI "
9271 "layer, Bad protection parameters: %d %d\n",
9272 old_mask, old_guard);
9277 * lpfc_post_init_setup - Perform necessary device post initialization setup.
9278 * @phba: pointer to lpfc hba data structure.
9280 * This routine is invoked to perform all the necessary post initialization
9281 * setup for the device.
9284 lpfc_post_init_setup(struct lpfc_hba *phba)
9286 struct Scsi_Host *shost;
9287 struct lpfc_adapter_event_header adapter_event;
9289 /* Get the default values for Model Name and Description */
9290 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9293 * hba setup may have changed the hba_queue_depth so we need to
9294 * adjust the value of can_queue.
9296 shost = pci_get_drvdata(phba->pcidev);
9297 shost->can_queue = phba->cfg_hba_queue_depth - 10;
9299 lpfc_host_attrib_init(shost);
9301 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9302 spin_lock_irq(shost->host_lock);
9303 lpfc_poll_start_timer(phba);
9304 spin_unlock_irq(shost->host_lock);
9307 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9308 "0428 Perform SCSI scan\n");
9309 /* Send board arrival event to upper layer */
9310 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
9311 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
9312 fc_host_post_vendor_event(shost, fc_get_event_number(),
9313 sizeof(adapter_event),
9314 (char *) &adapter_event,
9320 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
9321 * @phba: pointer to lpfc hba data structure.
9323 * This routine is invoked to set up the PCI device memory space for device
9324 * with SLI-3 interface spec.
9328 * other values - error
9331 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
9333 struct pci_dev *pdev = phba->pcidev;
9334 unsigned long bar0map_len, bar2map_len;
9342 /* Set the device DMA mask size */
9343 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9345 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9350 /* Get the bus address of Bar0 and Bar2 and the number of bytes
9351 * required by each mapping.
9353 phba->pci_bar0_map = pci_resource_start(pdev, 0);
9354 bar0map_len = pci_resource_len(pdev, 0);
9356 phba->pci_bar2_map = pci_resource_start(pdev, 2);
9357 bar2map_len = pci_resource_len(pdev, 2);
9359 /* Map HBA SLIM to a kernel virtual address. */
9360 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
9361 if (!phba->slim_memmap_p) {
9362 dev_printk(KERN_ERR, &pdev->dev,
9363 "ioremap failed for SLIM memory.\n");
9367 /* Map HBA Control Registers to a kernel virtual address. */
9368 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
9369 if (!phba->ctrl_regs_memmap_p) {
9370 dev_printk(KERN_ERR, &pdev->dev,
9371 "ioremap failed for HBA control registers.\n");
9372 goto out_iounmap_slim;
9375 /* Allocate memory for SLI-2 structures */
9376 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9377 &phba->slim2p.phys, GFP_KERNEL);
9378 if (!phba->slim2p.virt)
9381 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
9382 phba->mbox_ext = (phba->slim2p.virt +
9383 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
9384 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
9385 phba->IOCBs = (phba->slim2p.virt +
9386 offsetof(struct lpfc_sli2_slim, IOCBs));
9388 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
9389 lpfc_sli_hbq_size(),
9390 &phba->hbqslimp.phys,
9392 if (!phba->hbqslimp.virt)
9395 hbq_count = lpfc_sli_hbq_count();
9396 ptr = phba->hbqslimp.virt;
9397 for (i = 0; i < hbq_count; ++i) {
9398 phba->hbqs[i].hbq_virt = ptr;
9399 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
9400 ptr += (lpfc_hbq_defs[i]->entry_count *
9401 sizeof(struct lpfc_hbq_entry));
9403 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
9404 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
9406 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
9408 phba->MBslimaddr = phba->slim_memmap_p;
9409 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
9410 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
9411 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
9412 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
9417 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9418 phba->slim2p.virt, phba->slim2p.phys);
9420 iounmap(phba->ctrl_regs_memmap_p);
9422 iounmap(phba->slim_memmap_p);
9428 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
9429 * @phba: pointer to lpfc hba data structure.
9431 * This routine is invoked to unset the PCI device memory space for device
9432 * with SLI-3 interface spec.
9435 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
9437 struct pci_dev *pdev;
9439 /* Obtain PCI device reference */
9443 pdev = phba->pcidev;
9445 /* Free coherent DMA memory allocated */
9446 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9447 phba->hbqslimp.virt, phba->hbqslimp.phys);
9448 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9449 phba->slim2p.virt, phba->slim2p.phys);
9451 /* I/O memory unmap */
9452 iounmap(phba->ctrl_regs_memmap_p);
9453 iounmap(phba->slim_memmap_p);
9459 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
9460 * @phba: pointer to lpfc hba data structure.
9462 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
9463 * done and check status.
9465 * Return 0 if successful, otherwise -ENODEV.
9468 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
9470 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
9471 struct lpfc_register reg_data;
9472 int i, port_error = 0;
9475 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
9476 memset(®_data, 0, sizeof(reg_data));
9477 if (!phba->sli4_hba.PSMPHRregaddr)
9480 /* Wait up to 30 seconds for the SLI Port POST done and ready */
9481 for (i = 0; i < 3000; i++) {
9482 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9483 &portsmphr_reg.word0) ||
9484 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
9485 /* Port has a fatal POST error, break out */
9486 port_error = -ENODEV;
9489 if (LPFC_POST_STAGE_PORT_READY ==
9490 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
9496 * If there was a port error during POST, then don't proceed with
9497 * other register reads as the data may not be valid. Just exit.
9500 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9501 "1408 Port Failed POST - portsmphr=0x%x, "
9502 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
9503 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
9504 portsmphr_reg.word0,
9505 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
9506 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
9507 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
9508 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
9509 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
9510 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
9511 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
9512 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
9514 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9515 "2534 Device Info: SLIFamily=0x%x, "
9516 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
9517 "SLIHint_2=0x%x, FT=0x%x\n",
9518 bf_get(lpfc_sli_intf_sli_family,
9519 &phba->sli4_hba.sli_intf),
9520 bf_get(lpfc_sli_intf_slirev,
9521 &phba->sli4_hba.sli_intf),
9522 bf_get(lpfc_sli_intf_if_type,
9523 &phba->sli4_hba.sli_intf),
9524 bf_get(lpfc_sli_intf_sli_hint1,
9525 &phba->sli4_hba.sli_intf),
9526 bf_get(lpfc_sli_intf_sli_hint2,
9527 &phba->sli4_hba.sli_intf),
9528 bf_get(lpfc_sli_intf_func_type,
9529 &phba->sli4_hba.sli_intf));
9531 * Check for other Port errors during the initialization
9532 * process. Fail the load if the port did not come up
9535 if_type = bf_get(lpfc_sli_intf_if_type,
9536 &phba->sli4_hba.sli_intf);
9538 case LPFC_SLI_INTF_IF_TYPE_0:
9539 phba->sli4_hba.ue_mask_lo =
9540 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
9541 phba->sli4_hba.ue_mask_hi =
9542 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
9544 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
9546 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
9547 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
9548 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
9549 lpfc_printf_log(phba, KERN_ERR,
9551 "1422 Unrecoverable Error "
9552 "Detected during POST "
9553 "uerr_lo_reg=0x%x, "
9554 "uerr_hi_reg=0x%x, "
9555 "ue_mask_lo_reg=0x%x, "
9556 "ue_mask_hi_reg=0x%x\n",
9559 phba->sli4_hba.ue_mask_lo,
9560 phba->sli4_hba.ue_mask_hi);
9561 port_error = -ENODEV;
9564 case LPFC_SLI_INTF_IF_TYPE_2:
9565 case LPFC_SLI_INTF_IF_TYPE_6:
9566 /* Final checks. The port status should be clean. */
9567 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9569 (bf_get(lpfc_sliport_status_err, ®_data) &&
9570 !bf_get(lpfc_sliport_status_rn, ®_data))) {
9571 phba->work_status[0] =
9572 readl(phba->sli4_hba.u.if_type2.
9574 phba->work_status[1] =
9575 readl(phba->sli4_hba.u.if_type2.
9577 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9578 "2888 Unrecoverable port error "
9579 "following POST: port status reg "
9580 "0x%x, port_smphr reg 0x%x, "
9581 "error 1=0x%x, error 2=0x%x\n",
9583 portsmphr_reg.word0,
9584 phba->work_status[0],
9585 phba->work_status[1]);
9586 port_error = -ENODEV;
9590 if (lpfc_pldv_detect &&
9591 bf_get(lpfc_sli_intf_sli_family,
9592 &phba->sli4_hba.sli_intf) ==
9593 LPFC_SLI_INTF_FAMILY_G6)
9594 pci_write_config_byte(phba->pcidev,
9595 LPFC_SLI_INTF, CFG_PLD);
9597 case LPFC_SLI_INTF_IF_TYPE_1:
9606 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
9607 * @phba: pointer to lpfc hba data structure.
9608 * @if_type: The SLI4 interface type getting configured.
9610 * This routine is invoked to set up SLI4 BAR0 PCI config space register
9614 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9617 case LPFC_SLI_INTF_IF_TYPE_0:
9618 phba->sli4_hba.u.if_type0.UERRLOregaddr =
9619 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
9620 phba->sli4_hba.u.if_type0.UERRHIregaddr =
9621 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
9622 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
9623 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
9624 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
9625 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
9626 phba->sli4_hba.SLIINTFregaddr =
9627 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9629 case LPFC_SLI_INTF_IF_TYPE_2:
9630 phba->sli4_hba.u.if_type2.EQDregaddr =
9631 phba->sli4_hba.conf_regs_memmap_p +
9632 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9633 phba->sli4_hba.u.if_type2.ERR1regaddr =
9634 phba->sli4_hba.conf_regs_memmap_p +
9635 LPFC_CTL_PORT_ER1_OFFSET;
9636 phba->sli4_hba.u.if_type2.ERR2regaddr =
9637 phba->sli4_hba.conf_regs_memmap_p +
9638 LPFC_CTL_PORT_ER2_OFFSET;
9639 phba->sli4_hba.u.if_type2.CTRLregaddr =
9640 phba->sli4_hba.conf_regs_memmap_p +
9641 LPFC_CTL_PORT_CTL_OFFSET;
9642 phba->sli4_hba.u.if_type2.STATUSregaddr =
9643 phba->sli4_hba.conf_regs_memmap_p +
9644 LPFC_CTL_PORT_STA_OFFSET;
9645 phba->sli4_hba.SLIINTFregaddr =
9646 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9647 phba->sli4_hba.PSMPHRregaddr =
9648 phba->sli4_hba.conf_regs_memmap_p +
9649 LPFC_CTL_PORT_SEM_OFFSET;
9650 phba->sli4_hba.RQDBregaddr =
9651 phba->sli4_hba.conf_regs_memmap_p +
9652 LPFC_ULP0_RQ_DOORBELL;
9653 phba->sli4_hba.WQDBregaddr =
9654 phba->sli4_hba.conf_regs_memmap_p +
9655 LPFC_ULP0_WQ_DOORBELL;
9656 phba->sli4_hba.CQDBregaddr =
9657 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
9658 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9659 phba->sli4_hba.MQDBregaddr =
9660 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
9661 phba->sli4_hba.BMBXregaddr =
9662 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9664 case LPFC_SLI_INTF_IF_TYPE_6:
9665 phba->sli4_hba.u.if_type2.EQDregaddr =
9666 phba->sli4_hba.conf_regs_memmap_p +
9667 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9668 phba->sli4_hba.u.if_type2.ERR1regaddr =
9669 phba->sli4_hba.conf_regs_memmap_p +
9670 LPFC_CTL_PORT_ER1_OFFSET;
9671 phba->sli4_hba.u.if_type2.ERR2regaddr =
9672 phba->sli4_hba.conf_regs_memmap_p +
9673 LPFC_CTL_PORT_ER2_OFFSET;
9674 phba->sli4_hba.u.if_type2.CTRLregaddr =
9675 phba->sli4_hba.conf_regs_memmap_p +
9676 LPFC_CTL_PORT_CTL_OFFSET;
9677 phba->sli4_hba.u.if_type2.STATUSregaddr =
9678 phba->sli4_hba.conf_regs_memmap_p +
9679 LPFC_CTL_PORT_STA_OFFSET;
9680 phba->sli4_hba.PSMPHRregaddr =
9681 phba->sli4_hba.conf_regs_memmap_p +
9682 LPFC_CTL_PORT_SEM_OFFSET;
9683 phba->sli4_hba.BMBXregaddr =
9684 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9686 case LPFC_SLI_INTF_IF_TYPE_1:
9688 dev_printk(KERN_ERR, &phba->pcidev->dev,
9689 "FATAL - unsupported SLI4 interface type - %d\n",
9696 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
9697 * @phba: pointer to lpfc hba data structure.
9698 * @if_type: sli if type to operate on.
9700 * This routine is invoked to set up SLI4 BAR1 register memory map.
9703 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
9706 case LPFC_SLI_INTF_IF_TYPE_0:
9707 phba->sli4_hba.PSMPHRregaddr =
9708 phba->sli4_hba.ctrl_regs_memmap_p +
9709 LPFC_SLIPORT_IF0_SMPHR;
9710 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9712 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9714 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9717 case LPFC_SLI_INTF_IF_TYPE_6:
9718 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9719 LPFC_IF6_RQ_DOORBELL;
9720 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9721 LPFC_IF6_WQ_DOORBELL;
9722 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9723 LPFC_IF6_CQ_DOORBELL;
9724 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9725 LPFC_IF6_EQ_DOORBELL;
9726 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9727 LPFC_IF6_MQ_DOORBELL;
9729 case LPFC_SLI_INTF_IF_TYPE_2:
9730 case LPFC_SLI_INTF_IF_TYPE_1:
9732 dev_err(&phba->pcidev->dev,
9733 "FATAL - unsupported SLI4 interface type - %d\n",
9740 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
9741 * @phba: pointer to lpfc hba data structure.
9742 * @vf: virtual function number
9744 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
9745 * based on the given viftual function number, @vf.
9747 * Return 0 if successful, otherwise -ENODEV.
9750 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9752 if (vf > LPFC_VIR_FUNC_MAX)
9755 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9756 vf * LPFC_VFR_PAGE_SIZE +
9757 LPFC_ULP0_RQ_DOORBELL);
9758 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9759 vf * LPFC_VFR_PAGE_SIZE +
9760 LPFC_ULP0_WQ_DOORBELL);
9761 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9762 vf * LPFC_VFR_PAGE_SIZE +
9763 LPFC_EQCQ_DOORBELL);
9764 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9765 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9766 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9767 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9768 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9773 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9774 * @phba: pointer to lpfc hba data structure.
9776 * This routine is invoked to create the bootstrap mailbox
9777 * region consistent with the SLI-4 interface spec. This
9778 * routine allocates all memory necessary to communicate
9779 * mailbox commands to the port and sets up all alignment
9780 * needs. No locks are expected to be held when calling
9785 * -ENOMEM - could not allocated memory.
9788 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9791 struct lpfc_dmabuf *dmabuf;
9792 struct dma_address *dma_address;
9796 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9801 * The bootstrap mailbox region is comprised of 2 parts
9802 * plus an alignment restriction of 16 bytes.
9804 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
9805 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9806 &dmabuf->phys, GFP_KERNEL);
9807 if (!dmabuf->virt) {
9813 * Initialize the bootstrap mailbox pointers now so that the register
9814 * operations are simple later. The mailbox dma address is required
9815 * to be 16-byte aligned. Also align the virtual memory as each
9816 * maibox is copied into the bmbx mailbox region before issuing the
9817 * command to the port.
9819 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9820 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9822 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9823 LPFC_ALIGN_16_BYTE);
9824 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9825 LPFC_ALIGN_16_BYTE);
9828 * Set the high and low physical addresses now. The SLI4 alignment
9829 * requirement is 16 bytes and the mailbox is posted to the port
9830 * as two 30-bit addresses. The other data is a bit marking whether
9831 * the 30-bit address is the high or low address.
9832 * Upcast bmbx aphys to 64bits so shift instruction compiles
9833 * clean on 32 bit machines.
9835 dma_address = &phba->sli4_hba.bmbx.dma_address;
9836 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9837 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9838 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9839 LPFC_BMBX_BIT1_ADDR_HI);
9841 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9842 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9843 LPFC_BMBX_BIT1_ADDR_LO);
9848 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9849 * @phba: pointer to lpfc hba data structure.
9851 * This routine is invoked to teardown the bootstrap mailbox
9852 * region and release all host resources. This routine requires
9853 * the caller to ensure all mailbox commands recovered, no
9854 * additional mailbox comands are sent, and interrupts are disabled
9855 * before calling this routine.
9859 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9861 dma_free_coherent(&phba->pcidev->dev,
9862 phba->sli4_hba.bmbx.bmbx_size,
9863 phba->sli4_hba.bmbx.dmabuf->virt,
9864 phba->sli4_hba.bmbx.dmabuf->phys);
9866 kfree(phba->sli4_hba.bmbx.dmabuf);
9867 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9870 static const char * const lpfc_topo_to_str[] = {
9880 #define LINK_FLAGS_DEF 0x0
9881 #define LINK_FLAGS_P2P 0x1
9882 #define LINK_FLAGS_LOOP 0x2
9884 * lpfc_map_topology - Map the topology read from READ_CONFIG
9885 * @phba: pointer to lpfc hba data structure.
9886 * @rd_config: pointer to read config data
9888 * This routine is invoked to map the topology values as read
9889 * from the read config mailbox command. If the persistent
9890 * topology feature is supported, the firmware will provide the
9891 * saved topology information to be used in INIT_LINK
9894 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9898 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9899 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9900 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9902 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9903 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9906 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9907 "2019 FW does not support persistent topology "
9908 "Using driver parameter defined value [%s]",
9909 lpfc_topo_to_str[phba->cfg_topology]);
9912 /* FW supports persistent topology - override module parameter value */
9913 phba->hba_flag |= HBA_PERSISTENT_TOPO;
9915 /* if ASIC_GEN_NUM >= 0xC) */
9916 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9917 LPFC_SLI_INTF_IF_TYPE_6) ||
9918 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9919 LPFC_SLI_INTF_FAMILY_G6)) {
9921 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9922 ? FLAGS_TOPOLOGY_MODE_LOOP
9923 : FLAGS_TOPOLOGY_MODE_PT_PT);
9925 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
9929 /* If topology failover set - pt is '0' or '1' */
9930 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9931 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9933 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9934 ? FLAGS_TOPOLOGY_MODE_PT_PT
9935 : FLAGS_TOPOLOGY_MODE_LOOP);
9938 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
9939 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9940 "2020 Using persistent topology value [%s]",
9941 lpfc_topo_to_str[phba->cfg_topology]);
9943 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9944 "2021 Invalid topology values from FW "
9945 "Using driver parameter defined value [%s]",
9946 lpfc_topo_to_str[phba->cfg_topology]);
9951 * lpfc_sli4_read_config - Get the config parameters.
9952 * @phba: pointer to lpfc hba data structure.
9954 * This routine is invoked to read the configuration parameters from the HBA.
9955 * The configuration parameters are used to set the base and maximum values
9956 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9957 * allocation for the port.
9961 * -ENOMEM - No available memory
9962 * -EIO - The mailbox failed to complete successfully.
9965 lpfc_sli4_read_config(struct lpfc_hba *phba)
9968 struct lpfc_mbx_read_config *rd_config;
9969 union lpfc_sli4_cfg_shdr *shdr;
9970 uint32_t shdr_status, shdr_add_status;
9971 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9972 struct lpfc_rsrc_desc_fcfcoe *desc;
9974 uint16_t forced_link_speed;
9975 uint32_t if_type, qmin, fawwpn;
9976 int length, i, rc = 0, rc2;
9978 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9980 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9981 "2011 Unable to allocate memory for issuing "
9982 "SLI_CONFIG_SPECIAL mailbox command\n");
9986 lpfc_read_config(phba, pmb);
9988 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9989 if (rc != MBX_SUCCESS) {
9990 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9991 "2012 Mailbox failed , mbxCmd x%x "
9992 "READ_CONFIG, mbxStatus x%x\n",
9993 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9994 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9997 rd_config = &pmb->u.mqe.un.rd_config;
9998 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9999 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
10000 phba->sli4_hba.lnk_info.lnk_tp =
10001 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
10002 phba->sli4_hba.lnk_info.lnk_no =
10003 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
10004 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10005 "3081 lnk_type:%d, lnk_numb:%d\n",
10006 phba->sli4_hba.lnk_info.lnk_tp,
10007 phba->sli4_hba.lnk_info.lnk_no);
10009 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10010 "3082 Mailbox (x%x) returned ldv:x0\n",
10011 bf_get(lpfc_mqe_command, &pmb->u.mqe));
10012 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
10013 phba->bbcredit_support = 1;
10014 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
10017 fawwpn = bf_get(lpfc_mbx_rd_conf_fawwpn, rd_config);
10020 lpfc_printf_log(phba, KERN_INFO,
10021 LOG_INIT | LOG_DISCOVERY,
10022 "2702 READ_CONFIG: FA-PWWN is "
10023 "configured on\n");
10024 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_CONFIG;
10026 /* Clear FW configured flag, preserve driver flag */
10027 phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_CONFIG;
10030 phba->sli4_hba.conf_trunk =
10031 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
10032 phba->sli4_hba.extents_in_use =
10033 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
10035 phba->sli4_hba.max_cfg_param.max_xri =
10036 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
10037 /* Reduce resource usage in kdump environment */
10038 if (is_kdump_kernel() &&
10039 phba->sli4_hba.max_cfg_param.max_xri > 512)
10040 phba->sli4_hba.max_cfg_param.max_xri = 512;
10041 phba->sli4_hba.max_cfg_param.xri_base =
10042 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
10043 phba->sli4_hba.max_cfg_param.max_vpi =
10044 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
10045 /* Limit the max we support */
10046 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
10047 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
10048 phba->sli4_hba.max_cfg_param.vpi_base =
10049 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
10050 phba->sli4_hba.max_cfg_param.max_rpi =
10051 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
10052 phba->sli4_hba.max_cfg_param.rpi_base =
10053 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
10054 phba->sli4_hba.max_cfg_param.max_vfi =
10055 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
10056 phba->sli4_hba.max_cfg_param.vfi_base =
10057 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
10058 phba->sli4_hba.max_cfg_param.max_fcfi =
10059 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
10060 phba->sli4_hba.max_cfg_param.max_eq =
10061 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
10062 phba->sli4_hba.max_cfg_param.max_rq =
10063 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
10064 phba->sli4_hba.max_cfg_param.max_wq =
10065 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
10066 phba->sli4_hba.max_cfg_param.max_cq =
10067 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
10068 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
10069 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
10070 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
10071 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
10072 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
10073 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
10074 phba->max_vports = phba->max_vpi;
10076 /* Next decide on FPIN or Signal E2E CGN support
10077 * For congestion alarms and warnings valid combination are:
10078 * 1. FPIN alarms / FPIN warnings
10079 * 2. Signal alarms / Signal warnings
10080 * 3. FPIN alarms / Signal warnings
10081 * 4. Signal alarms / FPIN warnings
10083 * Initialize the adapter frequency to 100 mSecs
10085 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
10086 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
10087 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
10089 if (lpfc_use_cgn_signal) {
10090 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
10091 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
10092 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
10094 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
10095 /* MUST support both alarm and warning
10096 * because EDC does not support alarm alone.
10098 if (phba->cgn_reg_signal !=
10099 EDC_CG_SIG_WARN_ONLY) {
10100 /* Must support both or none */
10101 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
10102 phba->cgn_reg_signal =
10103 EDC_CG_SIG_NOTSUPPORTED;
10105 phba->cgn_reg_signal =
10106 EDC_CG_SIG_WARN_ALARM;
10107 phba->cgn_reg_fpin =
10108 LPFC_CGN_FPIN_NONE;
10113 /* Set the congestion initial signal and fpin values. */
10114 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
10115 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
10117 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
10118 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
10119 phba->cgn_reg_signal, phba->cgn_reg_fpin);
10121 lpfc_map_topology(phba, rd_config);
10122 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10123 "2003 cfg params Extents? %d "
10128 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
10129 phba->sli4_hba.extents_in_use,
10130 phba->sli4_hba.max_cfg_param.xri_base,
10131 phba->sli4_hba.max_cfg_param.max_xri,
10132 phba->sli4_hba.max_cfg_param.vpi_base,
10133 phba->sli4_hba.max_cfg_param.max_vpi,
10134 phba->sli4_hba.max_cfg_param.vfi_base,
10135 phba->sli4_hba.max_cfg_param.max_vfi,
10136 phba->sli4_hba.max_cfg_param.rpi_base,
10137 phba->sli4_hba.max_cfg_param.max_rpi,
10138 phba->sli4_hba.max_cfg_param.max_fcfi,
10139 phba->sli4_hba.max_cfg_param.max_eq,
10140 phba->sli4_hba.max_cfg_param.max_cq,
10141 phba->sli4_hba.max_cfg_param.max_wq,
10142 phba->sli4_hba.max_cfg_param.max_rq,
10146 * Calculate queue resources based on how
10147 * many WQ/CQ/EQs are available.
10149 qmin = phba->sli4_hba.max_cfg_param.max_wq;
10150 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
10151 qmin = phba->sli4_hba.max_cfg_param.max_cq;
10153 * Reserve 4 (ELS, NVME LS, MBOX, plus one extra) and
10154 * the remainder can be used for NVME / FCP.
10157 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
10158 qmin = phba->sli4_hba.max_cfg_param.max_eq;
10160 /* Check to see if there is enough for default cfg */
10161 if ((phba->cfg_irq_chann > qmin) ||
10162 (phba->cfg_hdw_queue > qmin)) {
10163 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10164 "2005 Reducing Queues - "
10165 "FW resource limitation: "
10166 "WQ %d CQ %d EQ %d: min %d: "
10167 "IRQ %d HDWQ %d\n",
10168 phba->sli4_hba.max_cfg_param.max_wq,
10169 phba->sli4_hba.max_cfg_param.max_cq,
10170 phba->sli4_hba.max_cfg_param.max_eq,
10171 qmin, phba->cfg_irq_chann,
10172 phba->cfg_hdw_queue);
10174 if (phba->cfg_irq_chann > qmin)
10175 phba->cfg_irq_chann = qmin;
10176 if (phba->cfg_hdw_queue > qmin)
10177 phba->cfg_hdw_queue = qmin;
10184 /* Update link speed if forced link speed is supported */
10185 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10186 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10187 forced_link_speed =
10188 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
10189 if (forced_link_speed) {
10190 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
10192 switch (forced_link_speed) {
10193 case LINK_SPEED_1G:
10194 phba->cfg_link_speed =
10195 LPFC_USER_LINK_SPEED_1G;
10197 case LINK_SPEED_2G:
10198 phba->cfg_link_speed =
10199 LPFC_USER_LINK_SPEED_2G;
10201 case LINK_SPEED_4G:
10202 phba->cfg_link_speed =
10203 LPFC_USER_LINK_SPEED_4G;
10205 case LINK_SPEED_8G:
10206 phba->cfg_link_speed =
10207 LPFC_USER_LINK_SPEED_8G;
10209 case LINK_SPEED_10G:
10210 phba->cfg_link_speed =
10211 LPFC_USER_LINK_SPEED_10G;
10213 case LINK_SPEED_16G:
10214 phba->cfg_link_speed =
10215 LPFC_USER_LINK_SPEED_16G;
10217 case LINK_SPEED_32G:
10218 phba->cfg_link_speed =
10219 LPFC_USER_LINK_SPEED_32G;
10221 case LINK_SPEED_64G:
10222 phba->cfg_link_speed =
10223 LPFC_USER_LINK_SPEED_64G;
10226 phba->cfg_link_speed =
10227 LPFC_USER_LINK_SPEED_AUTO;
10230 lpfc_printf_log(phba, KERN_ERR,
10232 "0047 Unrecognized link "
10234 forced_link_speed);
10235 phba->cfg_link_speed =
10236 LPFC_USER_LINK_SPEED_AUTO;
10241 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
10242 length = phba->sli4_hba.max_cfg_param.max_xri -
10243 lpfc_sli4_get_els_iocb_cnt(phba);
10244 if (phba->cfg_hba_queue_depth > length) {
10245 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10246 "3361 HBA queue depth changed from %d to %d\n",
10247 phba->cfg_hba_queue_depth, length);
10248 phba->cfg_hba_queue_depth = length;
10251 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
10252 LPFC_SLI_INTF_IF_TYPE_2)
10255 /* get the pf# and vf# for SLI4 if_type 2 port */
10256 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
10257 sizeof(struct lpfc_sli4_cfg_mhdr));
10258 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
10259 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
10260 length, LPFC_SLI4_MBX_EMBED);
10262 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10263 shdr = (union lpfc_sli4_cfg_shdr *)
10264 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
10265 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10266 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10267 if (rc2 || shdr_status || shdr_add_status) {
10268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10269 "3026 Mailbox failed , mbxCmd x%x "
10270 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
10271 bf_get(lpfc_mqe_command, &pmb->u.mqe),
10272 bf_get(lpfc_mqe_status, &pmb->u.mqe));
10276 /* search for fc_fcoe resrouce descriptor */
10277 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
10279 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
10280 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
10281 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
10282 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
10283 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
10284 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
10287 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
10288 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
10289 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
10290 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
10291 phba->sli4_hba.iov.pf_number =
10292 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
10293 phba->sli4_hba.iov.vf_number =
10294 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
10299 if (i < LPFC_RSRC_DESC_MAX_NUM)
10300 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10301 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
10302 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
10303 phba->sli4_hba.iov.vf_number);
10305 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10306 "3028 GET_FUNCTION_CONFIG: failed to find "
10307 "Resource Descriptor:x%x\n",
10308 LPFC_RSRC_DESC_TYPE_FCFCOE);
10311 mempool_free(pmb, phba->mbox_mem_pool);
10316 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
10317 * @phba: pointer to lpfc hba data structure.
10319 * This routine is invoked to setup the port-side endian order when
10320 * the port if_type is 0. This routine has no function for other
10325 * -ENOMEM - No available memory
10326 * -EIO - The mailbox failed to complete successfully.
10329 lpfc_setup_endian_order(struct lpfc_hba *phba)
10331 LPFC_MBOXQ_t *mboxq;
10332 uint32_t if_type, rc = 0;
10333 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
10334 HOST_ENDIAN_HIGH_WORD1};
10336 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10338 case LPFC_SLI_INTF_IF_TYPE_0:
10339 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10342 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10343 "0492 Unable to allocate memory for "
10344 "issuing SLI_CONFIG_SPECIAL mailbox "
10350 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
10351 * two words to contain special data values and no other data.
10353 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
10354 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
10355 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10356 if (rc != MBX_SUCCESS) {
10357 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10358 "0493 SLI_CONFIG_SPECIAL mailbox "
10359 "failed with status x%x\n",
10363 mempool_free(mboxq, phba->mbox_mem_pool);
10365 case LPFC_SLI_INTF_IF_TYPE_6:
10366 case LPFC_SLI_INTF_IF_TYPE_2:
10367 case LPFC_SLI_INTF_IF_TYPE_1:
10375 * lpfc_sli4_queue_verify - Verify and update EQ counts
10376 * @phba: pointer to lpfc hba data structure.
10378 * This routine is invoked to check the user settable queue counts for EQs.
10379 * After this routine is called the counts will be set to valid values that
10380 * adhere to the constraints of the system's interrupt vectors and the port's
10385 * -ENOMEM - No available memory
10388 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
10391 * Sanity check for configured queue parameters against the run-time
10392 * device parameters
10395 if (phba->nvmet_support) {
10396 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
10397 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
10398 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
10399 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
10402 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10403 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
10404 phba->cfg_hdw_queue, phba->cfg_irq_chann,
10405 phba->cfg_nvmet_mrq);
10407 /* Get EQ depth from module parameter, fake the default for now */
10408 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10409 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10411 /* Get CQ depth from module parameter, fake the default for now */
10412 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10413 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10418 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
10420 struct lpfc_queue *qdesc;
10424 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
10425 /* Create Fast Path IO CQs */
10426 if (phba->enab_exp_wqcq_pages)
10427 /* Increase the CQ size when WQEs contain an embedded cdb */
10428 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10429 phba->sli4_hba.cq_esize,
10430 LPFC_CQE_EXP_COUNT, cpu);
10433 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10434 phba->sli4_hba.cq_esize,
10435 phba->sli4_hba.cq_ecount, cpu);
10437 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10438 "0499 Failed allocate fast-path IO CQ (%d)\n",
10442 qdesc->qe_valid = 1;
10444 qdesc->chann = cpu;
10445 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
10447 /* Create Fast Path IO WQs */
10448 if (phba->enab_exp_wqcq_pages) {
10449 /* Increase the WQ size when WQEs contain an embedded cdb */
10450 wqesize = (phba->fcp_embed_io) ?
10451 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
10452 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10454 LPFC_WQE_EXP_COUNT, cpu);
10456 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10457 phba->sli4_hba.wq_esize,
10458 phba->sli4_hba.wq_ecount, cpu);
10461 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10462 "0503 Failed allocate fast-path IO WQ (%d)\n",
10467 qdesc->chann = cpu;
10468 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
10469 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10474 * lpfc_sli4_queue_create - Create all the SLI4 queues
10475 * @phba: pointer to lpfc hba data structure.
10477 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
10478 * operation. For each SLI4 queue type, the parameters such as queue entry
10479 * count (queue depth) shall be taken from the module parameter. For now,
10480 * we just use some constant number as place holder.
10484 * -ENOMEM - No availble memory
10485 * -EIO - The mailbox failed to complete successfully.
10488 lpfc_sli4_queue_create(struct lpfc_hba *phba)
10490 struct lpfc_queue *qdesc;
10491 int idx, cpu, eqcpu;
10492 struct lpfc_sli4_hdw_queue *qp;
10493 struct lpfc_vector_map_info *cpup;
10494 struct lpfc_vector_map_info *eqcpup;
10495 struct lpfc_eq_intr_info *eqi;
10498 * Create HBA Record arrays.
10499 * Both NVME and FCP will share that same vectors / EQs
10501 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
10502 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
10503 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
10504 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
10505 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
10506 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
10507 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10508 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10509 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10510 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
10512 if (!phba->sli4_hba.hdwq) {
10513 phba->sli4_hba.hdwq = kcalloc(
10514 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
10516 if (!phba->sli4_hba.hdwq) {
10517 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10518 "6427 Failed allocate memory for "
10519 "fast-path Hardware Queue array\n");
10522 /* Prepare hardware queues to take IO buffers */
10523 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10524 qp = &phba->sli4_hba.hdwq[idx];
10525 spin_lock_init(&qp->io_buf_list_get_lock);
10526 spin_lock_init(&qp->io_buf_list_put_lock);
10527 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
10528 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
10529 qp->get_io_bufs = 0;
10530 qp->put_io_bufs = 0;
10531 qp->total_io_bufs = 0;
10532 spin_lock_init(&qp->abts_io_buf_list_lock);
10533 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
10534 qp->abts_scsi_io_bufs = 0;
10535 qp->abts_nvme_io_bufs = 0;
10536 INIT_LIST_HEAD(&qp->sgl_list);
10537 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
10538 spin_lock_init(&qp->hdwq_lock);
10542 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10543 if (phba->nvmet_support) {
10544 phba->sli4_hba.nvmet_cqset = kcalloc(
10545 phba->cfg_nvmet_mrq,
10546 sizeof(struct lpfc_queue *),
10548 if (!phba->sli4_hba.nvmet_cqset) {
10549 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10550 "3121 Fail allocate memory for "
10551 "fast-path CQ set array\n");
10554 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
10555 phba->cfg_nvmet_mrq,
10556 sizeof(struct lpfc_queue *),
10558 if (!phba->sli4_hba.nvmet_mrq_hdr) {
10559 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10560 "3122 Fail allocate memory for "
10561 "fast-path RQ set hdr array\n");
10564 phba->sli4_hba.nvmet_mrq_data = kcalloc(
10565 phba->cfg_nvmet_mrq,
10566 sizeof(struct lpfc_queue *),
10568 if (!phba->sli4_hba.nvmet_mrq_data) {
10569 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10570 "3124 Fail allocate memory for "
10571 "fast-path RQ set data array\n");
10577 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10579 /* Create HBA Event Queues (EQs) */
10580 for_each_present_cpu(cpu) {
10581 /* We only want to create 1 EQ per vector, even though
10582 * multiple CPUs might be using that vector. so only
10583 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
10585 cpup = &phba->sli4_hba.cpu_map[cpu];
10586 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10589 /* Get a ptr to the Hardware Queue associated with this CPU */
10590 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10592 /* Allocate an EQ */
10593 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10594 phba->sli4_hba.eq_esize,
10595 phba->sli4_hba.eq_ecount, cpu);
10597 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10598 "0497 Failed allocate EQ (%d)\n",
10602 qdesc->qe_valid = 1;
10603 qdesc->hdwq = cpup->hdwq;
10604 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
10605 qdesc->last_cpu = qdesc->chann;
10607 /* Save the allocated EQ in the Hardware Queue */
10608 qp->hba_eq = qdesc;
10610 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
10611 list_add(&qdesc->cpu_list, &eqi->list);
10614 /* Now we need to populate the other Hardware Queues, that share
10615 * an IRQ vector, with the associated EQ ptr.
10617 for_each_present_cpu(cpu) {
10618 cpup = &phba->sli4_hba.cpu_map[cpu];
10620 /* Check for EQ already allocated in previous loop */
10621 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
10624 /* Check for multiple CPUs per hdwq */
10625 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10629 /* We need to share an EQ for this hdwq */
10630 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
10631 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
10632 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
10635 /* Allocate IO Path SLI4 CQ/WQs */
10636 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10637 if (lpfc_alloc_io_wq_cq(phba, idx))
10641 if (phba->nvmet_support) {
10642 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10643 cpu = lpfc_find_cpu_handle(phba, idx,
10644 LPFC_FIND_BY_HDWQ);
10645 qdesc = lpfc_sli4_queue_alloc(phba,
10646 LPFC_DEFAULT_PAGE_SIZE,
10647 phba->sli4_hba.cq_esize,
10648 phba->sli4_hba.cq_ecount,
10651 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10652 "3142 Failed allocate NVME "
10653 "CQ Set (%d)\n", idx);
10656 qdesc->qe_valid = 1;
10658 qdesc->chann = cpu;
10659 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
10664 * Create Slow Path Completion Queues (CQs)
10667 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
10668 /* Create slow-path Mailbox Command Complete Queue */
10669 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10670 phba->sli4_hba.cq_esize,
10671 phba->sli4_hba.cq_ecount, cpu);
10673 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10674 "0500 Failed allocate slow-path mailbox CQ\n");
10677 qdesc->qe_valid = 1;
10678 phba->sli4_hba.mbx_cq = qdesc;
10680 /* Create slow-path ELS Complete Queue */
10681 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10682 phba->sli4_hba.cq_esize,
10683 phba->sli4_hba.cq_ecount, cpu);
10685 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10686 "0501 Failed allocate slow-path ELS CQ\n");
10689 qdesc->qe_valid = 1;
10690 qdesc->chann = cpu;
10691 phba->sli4_hba.els_cq = qdesc;
10695 * Create Slow Path Work Queues (WQs)
10698 /* Create Mailbox Command Queue */
10700 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10701 phba->sli4_hba.mq_esize,
10702 phba->sli4_hba.mq_ecount, cpu);
10704 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10705 "0505 Failed allocate slow-path MQ\n");
10708 qdesc->chann = cpu;
10709 phba->sli4_hba.mbx_wq = qdesc;
10712 * Create ELS Work Queues
10715 /* Create slow-path ELS Work Queue */
10716 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10717 phba->sli4_hba.wq_esize,
10718 phba->sli4_hba.wq_ecount, cpu);
10720 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10721 "0504 Failed allocate slow-path ELS WQ\n");
10724 qdesc->chann = cpu;
10725 phba->sli4_hba.els_wq = qdesc;
10726 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10728 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10729 /* Create NVME LS Complete Queue */
10730 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10731 phba->sli4_hba.cq_esize,
10732 phba->sli4_hba.cq_ecount, cpu);
10734 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10735 "6079 Failed allocate NVME LS CQ\n");
10738 qdesc->chann = cpu;
10739 qdesc->qe_valid = 1;
10740 phba->sli4_hba.nvmels_cq = qdesc;
10742 /* Create NVME LS Work Queue */
10743 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10744 phba->sli4_hba.wq_esize,
10745 phba->sli4_hba.wq_ecount, cpu);
10747 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10748 "6080 Failed allocate NVME LS WQ\n");
10751 qdesc->chann = cpu;
10752 phba->sli4_hba.nvmels_wq = qdesc;
10753 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10757 * Create Receive Queue (RQ)
10760 /* Create Receive Queue for header */
10761 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10762 phba->sli4_hba.rq_esize,
10763 phba->sli4_hba.rq_ecount, cpu);
10765 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10766 "0506 Failed allocate receive HRQ\n");
10769 phba->sli4_hba.hdr_rq = qdesc;
10771 /* Create Receive Queue for data */
10772 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10773 phba->sli4_hba.rq_esize,
10774 phba->sli4_hba.rq_ecount, cpu);
10776 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10777 "0507 Failed allocate receive DRQ\n");
10780 phba->sli4_hba.dat_rq = qdesc;
10782 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10783 phba->nvmet_support) {
10784 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10785 cpu = lpfc_find_cpu_handle(phba, idx,
10786 LPFC_FIND_BY_HDWQ);
10787 /* Create NVMET Receive Queue for header */
10788 qdesc = lpfc_sli4_queue_alloc(phba,
10789 LPFC_DEFAULT_PAGE_SIZE,
10790 phba->sli4_hba.rq_esize,
10791 LPFC_NVMET_RQE_DEF_COUNT,
10794 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10795 "3146 Failed allocate "
10800 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10802 /* Only needed for header of RQ pair */
10803 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10806 if (qdesc->rqbp == NULL) {
10807 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10808 "6131 Failed allocate "
10813 /* Put list in known state in case driver load fails. */
10814 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10816 /* Create NVMET Receive Queue for data */
10817 qdesc = lpfc_sli4_queue_alloc(phba,
10818 LPFC_DEFAULT_PAGE_SIZE,
10819 phba->sli4_hba.rq_esize,
10820 LPFC_NVMET_RQE_DEF_COUNT,
10823 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10824 "3156 Failed allocate "
10829 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10833 /* Clear NVME stats */
10834 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10835 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10836 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10837 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10841 /* Clear SCSI stats */
10842 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10843 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10844 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10845 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10852 lpfc_sli4_queue_destroy(phba);
10857 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
10860 lpfc_sli4_queue_free(*qp);
10866 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10873 for (idx = 0; idx < max; idx++)
10874 __lpfc_sli4_release_queue(&(*qs)[idx]);
10881 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
10883 struct lpfc_sli4_hdw_queue *hdwq;
10884 struct lpfc_queue *eq;
10887 hdwq = phba->sli4_hba.hdwq;
10889 /* Loop thru all Hardware Queues */
10890 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10891 /* Free the CQ/WQ corresponding to the Hardware Queue */
10892 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10893 lpfc_sli4_queue_free(hdwq[idx].io_wq);
10894 hdwq[idx].hba_eq = NULL;
10895 hdwq[idx].io_cq = NULL;
10896 hdwq[idx].io_wq = NULL;
10897 if (phba->cfg_xpsgl && !phba->nvmet_support)
10898 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10899 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
10901 /* Loop thru all IRQ vectors */
10902 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10903 /* Free the EQ corresponding to the IRQ vector */
10904 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10905 lpfc_sli4_queue_free(eq);
10906 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10911 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10912 * @phba: pointer to lpfc hba data structure.
10914 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10919 * -ENOMEM - No available memory
10920 * -EIO - The mailbox failed to complete successfully.
10923 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10926 * Set FREE_INIT before beginning to free the queues.
10927 * Wait until the users of queues to acknowledge to
10928 * release queues by clearing FREE_WAIT.
10930 spin_lock_irq(&phba->hbalock);
10931 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10932 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10933 spin_unlock_irq(&phba->hbalock);
10935 spin_lock_irq(&phba->hbalock);
10937 spin_unlock_irq(&phba->hbalock);
10939 lpfc_sli4_cleanup_poll_list(phba);
10941 /* Release HBA eqs */
10942 if (phba->sli4_hba.hdwq)
10943 lpfc_sli4_release_hdwq(phba);
10945 if (phba->nvmet_support) {
10946 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10947 phba->cfg_nvmet_mrq);
10949 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10950 phba->cfg_nvmet_mrq);
10951 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10952 phba->cfg_nvmet_mrq);
10955 /* Release mailbox command work queue */
10956 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
10958 /* Release ELS work queue */
10959 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10961 /* Release ELS work queue */
10962 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
10964 /* Release unsolicited receive queue */
10965 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10966 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
10968 /* Release ELS complete queue */
10969 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10971 /* Release NVME LS complete queue */
10972 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
10974 /* Release mailbox command complete queue */
10975 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10977 /* Everything on this list has been freed */
10978 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10980 /* Done with freeing the queues */
10981 spin_lock_irq(&phba->hbalock);
10982 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10983 spin_unlock_irq(&phba->hbalock);
10987 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10989 struct lpfc_rqb *rqbp;
10990 struct lpfc_dmabuf *h_buf;
10991 struct rqb_dmabuf *rqb_buffer;
10994 while (!list_empty(&rqbp->rqb_buffer_list)) {
10995 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10996 struct lpfc_dmabuf, list);
10998 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10999 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
11000 rqbp->buffer_count--;
11006 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
11007 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
11008 int qidx, uint32_t qtype)
11010 struct lpfc_sli_ring *pring;
11013 if (!eq || !cq || !wq) {
11014 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11015 "6085 Fast-path %s (%d) not allocated\n",
11016 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
11020 /* create the Cq first */
11021 rc = lpfc_cq_create(phba, cq, eq,
11022 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
11024 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11025 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
11026 qidx, (uint32_t)rc);
11030 if (qtype != LPFC_MBOX) {
11031 /* Setup cq_map for fast lookup */
11033 *cq_map = cq->queue_id;
11035 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11036 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
11037 qidx, cq->queue_id, qidx, eq->queue_id);
11039 /* create the wq */
11040 rc = lpfc_wq_create(phba, wq, cq, qtype);
11042 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11043 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
11044 qidx, (uint32_t)rc);
11045 /* no need to tear down cq - caller will do so */
11049 /* Bind this CQ/WQ to the NVME ring */
11051 pring->sli.sli4.wqp = (void *)wq;
11054 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11055 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
11056 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
11058 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
11060 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11061 "0539 Failed setup of slow-path MQ: "
11062 "rc = 0x%x\n", rc);
11063 /* no need to tear down cq - caller will do so */
11067 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11068 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
11069 phba->sli4_hba.mbx_wq->queue_id,
11070 phba->sli4_hba.mbx_cq->queue_id);
11077 * lpfc_setup_cq_lookup - Setup the CQ lookup table
11078 * @phba: pointer to lpfc hba data structure.
11080 * This routine will populate the cq_lookup table by all
11081 * available CQ queue_id's.
11084 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
11086 struct lpfc_queue *eq, *childq;
11089 memset(phba->sli4_hba.cq_lookup, 0,
11090 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
11091 /* Loop thru all IRQ vectors */
11092 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11093 /* Get the EQ corresponding to the IRQ vector */
11094 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11097 /* Loop through all CQs associated with that EQ */
11098 list_for_each_entry(childq, &eq->child_list, list) {
11099 if (childq->queue_id > phba->sli4_hba.cq_max)
11101 if (childq->subtype == LPFC_IO)
11102 phba->sli4_hba.cq_lookup[childq->queue_id] =
11109 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
11110 * @phba: pointer to lpfc hba data structure.
11112 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
11117 * -ENOMEM - No available memory
11118 * -EIO - The mailbox failed to complete successfully.
11121 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
11123 uint32_t shdr_status, shdr_add_status;
11124 union lpfc_sli4_cfg_shdr *shdr;
11125 struct lpfc_vector_map_info *cpup;
11126 struct lpfc_sli4_hdw_queue *qp;
11127 LPFC_MBOXQ_t *mboxq;
11129 uint32_t length, usdelay;
11132 /* Check for dual-ULP support */
11133 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11135 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11136 "3249 Unable to allocate memory for "
11137 "QUERY_FW_CFG mailbox command\n");
11140 length = (sizeof(struct lpfc_mbx_query_fw_config) -
11141 sizeof(struct lpfc_sli4_cfg_mhdr));
11142 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11143 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
11144 length, LPFC_SLI4_MBX_EMBED);
11146 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11148 shdr = (union lpfc_sli4_cfg_shdr *)
11149 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11150 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11151 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
11152 if (shdr_status || shdr_add_status || rc) {
11153 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11154 "3250 QUERY_FW_CFG mailbox failed with status "
11155 "x%x add_status x%x, mbx status x%x\n",
11156 shdr_status, shdr_add_status, rc);
11157 mempool_free(mboxq, phba->mbox_mem_pool);
11162 phba->sli4_hba.fw_func_mode =
11163 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
11164 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
11165 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
11166 phba->sli4_hba.physical_port =
11167 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
11168 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11169 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
11170 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
11171 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
11173 mempool_free(mboxq, phba->mbox_mem_pool);
11176 * Set up HBA Event Queues (EQs)
11178 qp = phba->sli4_hba.hdwq;
11180 /* Set up HBA event queue */
11182 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11183 "3147 Fast-path EQs not allocated\n");
11188 /* Loop thru all IRQ vectors */
11189 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11190 /* Create HBA Event Queues (EQs) in order */
11191 for_each_present_cpu(cpu) {
11192 cpup = &phba->sli4_hba.cpu_map[cpu];
11194 /* Look for the CPU thats using that vector with
11195 * LPFC_CPU_FIRST_IRQ set.
11197 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11199 if (qidx != cpup->eq)
11202 /* Create an EQ for that vector */
11203 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
11204 phba->cfg_fcp_imax);
11206 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11207 "0523 Failed setup of fast-path"
11208 " EQ (%d), rc = 0x%x\n",
11209 cpup->eq, (uint32_t)rc);
11213 /* Save the EQ for that vector in the hba_eq_hdl */
11214 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
11215 qp[cpup->hdwq].hba_eq;
11217 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11218 "2584 HBA EQ setup: queue[%d]-id=%d\n",
11220 qp[cpup->hdwq].hba_eq->queue_id);
11224 /* Loop thru all Hardware Queues */
11225 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11226 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
11227 cpup = &phba->sli4_hba.cpu_map[cpu];
11229 /* Create the CQ/WQ corresponding to the Hardware Queue */
11230 rc = lpfc_create_wq_cq(phba,
11231 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
11234 &phba->sli4_hba.hdwq[qidx].io_cq_map,
11238 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11239 "0535 Failed to setup fastpath "
11240 "IO WQ/CQ (%d), rc = 0x%x\n",
11241 qidx, (uint32_t)rc);
11247 * Set up Slow Path Complete Queues (CQs)
11250 /* Set up slow-path MBOX CQ/MQ */
11252 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
11253 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11254 "0528 %s not allocated\n",
11255 phba->sli4_hba.mbx_cq ?
11256 "Mailbox WQ" : "Mailbox CQ");
11261 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11262 phba->sli4_hba.mbx_cq,
11263 phba->sli4_hba.mbx_wq,
11264 NULL, 0, LPFC_MBOX);
11266 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11267 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
11271 if (phba->nvmet_support) {
11272 if (!phba->sli4_hba.nvmet_cqset) {
11273 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11274 "3165 Fast-path NVME CQ Set "
11275 "array not allocated\n");
11279 if (phba->cfg_nvmet_mrq > 1) {
11280 rc = lpfc_cq_create_set(phba,
11281 phba->sli4_hba.nvmet_cqset,
11283 LPFC_WCQ, LPFC_NVMET);
11285 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11286 "3164 Failed setup of NVME CQ "
11287 "Set, rc = 0x%x\n",
11292 /* Set up NVMET Receive Complete Queue */
11293 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
11295 LPFC_WCQ, LPFC_NVMET);
11297 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11298 "6089 Failed setup NVMET CQ: "
11299 "rc = 0x%x\n", (uint32_t)rc);
11302 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
11304 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11305 "6090 NVMET CQ setup: cq-id=%d, "
11306 "parent eq-id=%d\n",
11307 phba->sli4_hba.nvmet_cqset[0]->queue_id,
11308 qp[0].hba_eq->queue_id);
11312 /* Set up slow-path ELS WQ/CQ */
11313 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
11314 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11315 "0530 ELS %s not allocated\n",
11316 phba->sli4_hba.els_cq ? "WQ" : "CQ");
11320 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11321 phba->sli4_hba.els_cq,
11322 phba->sli4_hba.els_wq,
11323 NULL, 0, LPFC_ELS);
11325 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11326 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
11330 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11331 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
11332 phba->sli4_hba.els_wq->queue_id,
11333 phba->sli4_hba.els_cq->queue_id);
11335 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11336 /* Set up NVME LS Complete Queue */
11337 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
11338 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11339 "6091 LS %s not allocated\n",
11340 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
11344 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11345 phba->sli4_hba.nvmels_cq,
11346 phba->sli4_hba.nvmels_wq,
11347 NULL, 0, LPFC_NVME_LS);
11349 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11350 "0526 Failed setup of NVVME LS WQ/CQ: "
11351 "rc = 0x%x\n", (uint32_t)rc);
11355 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11356 "6096 ELS WQ setup: wq-id=%d, "
11357 "parent cq-id=%d\n",
11358 phba->sli4_hba.nvmels_wq->queue_id,
11359 phba->sli4_hba.nvmels_cq->queue_id);
11363 * Create NVMET Receive Queue (RQ)
11365 if (phba->nvmet_support) {
11366 if ((!phba->sli4_hba.nvmet_cqset) ||
11367 (!phba->sli4_hba.nvmet_mrq_hdr) ||
11368 (!phba->sli4_hba.nvmet_mrq_data)) {
11369 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11370 "6130 MRQ CQ Queues not "
11375 if (phba->cfg_nvmet_mrq > 1) {
11376 rc = lpfc_mrq_create(phba,
11377 phba->sli4_hba.nvmet_mrq_hdr,
11378 phba->sli4_hba.nvmet_mrq_data,
11379 phba->sli4_hba.nvmet_cqset,
11382 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11383 "6098 Failed setup of NVMET "
11384 "MRQ: rc = 0x%x\n",
11390 rc = lpfc_rq_create(phba,
11391 phba->sli4_hba.nvmet_mrq_hdr[0],
11392 phba->sli4_hba.nvmet_mrq_data[0],
11393 phba->sli4_hba.nvmet_cqset[0],
11396 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11397 "6057 Failed setup of NVMET "
11398 "Receive Queue: rc = 0x%x\n",
11404 phba, KERN_INFO, LOG_INIT,
11405 "6099 NVMET RQ setup: hdr-rq-id=%d, "
11406 "dat-rq-id=%d parent cq-id=%d\n",
11407 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
11408 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
11409 phba->sli4_hba.nvmet_cqset[0]->queue_id);
11414 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
11415 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11416 "0540 Receive Queue not allocated\n");
11421 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
11422 phba->sli4_hba.els_cq, LPFC_USOL);
11424 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11425 "0541 Failed setup of Receive Queue: "
11426 "rc = 0x%x\n", (uint32_t)rc);
11430 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11431 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
11432 "parent cq-id=%d\n",
11433 phba->sli4_hba.hdr_rq->queue_id,
11434 phba->sli4_hba.dat_rq->queue_id,
11435 phba->sli4_hba.els_cq->queue_id);
11437 if (phba->cfg_fcp_imax)
11438 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
11442 for (qidx = 0; qidx < phba->cfg_irq_chann;
11443 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
11444 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
11447 if (phba->sli4_hba.cq_max) {
11448 kfree(phba->sli4_hba.cq_lookup);
11449 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
11450 sizeof(struct lpfc_queue *), GFP_KERNEL);
11451 if (!phba->sli4_hba.cq_lookup) {
11452 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11453 "0549 Failed setup of CQ Lookup table: "
11454 "size 0x%x\n", phba->sli4_hba.cq_max);
11458 lpfc_setup_cq_lookup(phba);
11463 lpfc_sli4_queue_unset(phba);
11469 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
11470 * @phba: pointer to lpfc hba data structure.
11472 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
11477 * -ENOMEM - No available memory
11478 * -EIO - The mailbox failed to complete successfully.
11481 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
11483 struct lpfc_sli4_hdw_queue *qp;
11484 struct lpfc_queue *eq;
11487 /* Unset mailbox command work queue */
11488 if (phba->sli4_hba.mbx_wq)
11489 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
11491 /* Unset NVME LS work queue */
11492 if (phba->sli4_hba.nvmels_wq)
11493 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
11495 /* Unset ELS work queue */
11496 if (phba->sli4_hba.els_wq)
11497 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
11499 /* Unset unsolicited receive queue */
11500 if (phba->sli4_hba.hdr_rq)
11501 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
11502 phba->sli4_hba.dat_rq);
11504 /* Unset mailbox command complete queue */
11505 if (phba->sli4_hba.mbx_cq)
11506 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
11508 /* Unset ELS complete queue */
11509 if (phba->sli4_hba.els_cq)
11510 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
11512 /* Unset NVME LS complete queue */
11513 if (phba->sli4_hba.nvmels_cq)
11514 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
11516 if (phba->nvmet_support) {
11517 /* Unset NVMET MRQ queue */
11518 if (phba->sli4_hba.nvmet_mrq_hdr) {
11519 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11522 phba->sli4_hba.nvmet_mrq_hdr[qidx],
11523 phba->sli4_hba.nvmet_mrq_data[qidx]);
11526 /* Unset NVMET CQ Set complete queue */
11527 if (phba->sli4_hba.nvmet_cqset) {
11528 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11530 phba, phba->sli4_hba.nvmet_cqset[qidx]);
11534 /* Unset fast-path SLI4 queues */
11535 if (phba->sli4_hba.hdwq) {
11536 /* Loop thru all Hardware Queues */
11537 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
11538 /* Destroy the CQ/WQ corresponding to Hardware Queue */
11539 qp = &phba->sli4_hba.hdwq[qidx];
11540 lpfc_wq_destroy(phba, qp->io_wq);
11541 lpfc_cq_destroy(phba, qp->io_cq);
11543 /* Loop thru all IRQ vectors */
11544 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11545 /* Destroy the EQ corresponding to the IRQ vector */
11546 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11547 lpfc_eq_destroy(phba, eq);
11551 kfree(phba->sli4_hba.cq_lookup);
11552 phba->sli4_hba.cq_lookup = NULL;
11553 phba->sli4_hba.cq_max = 0;
11557 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
11558 * @phba: pointer to lpfc hba data structure.
11560 * This routine is invoked to allocate and set up a pool of completion queue
11561 * events. The body of the completion queue event is a completion queue entry
11562 * CQE. For now, this pool is used for the interrupt service routine to queue
11563 * the following HBA completion queue events for the worker thread to process:
11564 * - Mailbox asynchronous events
11565 * - Receive queue completion unsolicited events
11566 * Later, this can be used for all the slow-path events.
11570 * -ENOMEM - No available memory
11573 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
11575 struct lpfc_cq_event *cq_event;
11578 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
11579 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
11581 goto out_pool_create_fail;
11582 list_add_tail(&cq_event->list,
11583 &phba->sli4_hba.sp_cqe_event_pool);
11587 out_pool_create_fail:
11588 lpfc_sli4_cq_event_pool_destroy(phba);
11593 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
11594 * @phba: pointer to lpfc hba data structure.
11596 * This routine is invoked to free the pool of completion queue events at
11597 * driver unload time. Note that, it is the responsibility of the driver
11598 * cleanup routine to free all the outstanding completion-queue events
11599 * allocated from this pool back into the pool before invoking this routine
11600 * to destroy the pool.
11603 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
11605 struct lpfc_cq_event *cq_event, *next_cq_event;
11607 list_for_each_entry_safe(cq_event, next_cq_event,
11608 &phba->sli4_hba.sp_cqe_event_pool, list) {
11609 list_del(&cq_event->list);
11615 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11616 * @phba: pointer to lpfc hba data structure.
11618 * This routine is the lock free version of the API invoked to allocate a
11619 * completion-queue event from the free pool.
11621 * Return: Pointer to the newly allocated completion-queue event if successful
11624 struct lpfc_cq_event *
11625 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11627 struct lpfc_cq_event *cq_event = NULL;
11629 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
11630 struct lpfc_cq_event, list);
11635 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11636 * @phba: pointer to lpfc hba data structure.
11638 * This routine is the lock version of the API invoked to allocate a
11639 * completion-queue event from the free pool.
11641 * Return: Pointer to the newly allocated completion-queue event if successful
11644 struct lpfc_cq_event *
11645 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11647 struct lpfc_cq_event *cq_event;
11648 unsigned long iflags;
11650 spin_lock_irqsave(&phba->hbalock, iflags);
11651 cq_event = __lpfc_sli4_cq_event_alloc(phba);
11652 spin_unlock_irqrestore(&phba->hbalock, iflags);
11657 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11658 * @phba: pointer to lpfc hba data structure.
11659 * @cq_event: pointer to the completion queue event to be freed.
11661 * This routine is the lock free version of the API invoked to release a
11662 * completion-queue event back into the free pool.
11665 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11666 struct lpfc_cq_event *cq_event)
11668 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
11672 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11673 * @phba: pointer to lpfc hba data structure.
11674 * @cq_event: pointer to the completion queue event to be freed.
11676 * This routine is the lock version of the API invoked to release a
11677 * completion-queue event back into the free pool.
11680 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11681 struct lpfc_cq_event *cq_event)
11683 unsigned long iflags;
11684 spin_lock_irqsave(&phba->hbalock, iflags);
11685 __lpfc_sli4_cq_event_release(phba, cq_event);
11686 spin_unlock_irqrestore(&phba->hbalock, iflags);
11690 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
11691 * @phba: pointer to lpfc hba data structure.
11693 * This routine is to free all the pending completion-queue events to the
11694 * back into the free pool for device reset.
11697 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
11699 LIST_HEAD(cq_event_list);
11700 struct lpfc_cq_event *cq_event;
11701 unsigned long iflags;
11703 /* Retrieve all the pending WCQEs from pending WCQE lists */
11705 /* Pending ELS XRI abort events */
11706 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11707 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11709 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11711 /* Pending asynnc events */
11712 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
11713 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
11715 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
11717 while (!list_empty(&cq_event_list)) {
11718 list_remove_head(&cq_event_list, cq_event,
11719 struct lpfc_cq_event, list);
11720 lpfc_sli4_cq_event_release(phba, cq_event);
11725 * lpfc_pci_function_reset - Reset pci function.
11726 * @phba: pointer to lpfc hba data structure.
11728 * This routine is invoked to request a PCI function reset. It will destroys
11729 * all resources assigned to the PCI function which originates this request.
11733 * -ENOMEM - No available memory
11734 * -EIO - The mailbox failed to complete successfully.
11737 lpfc_pci_function_reset(struct lpfc_hba *phba)
11739 LPFC_MBOXQ_t *mboxq;
11740 uint32_t rc = 0, if_type;
11741 uint32_t shdr_status, shdr_add_status;
11743 uint32_t port_reset = 0;
11744 union lpfc_sli4_cfg_shdr *shdr;
11745 struct lpfc_register reg_data;
11748 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11750 case LPFC_SLI_INTF_IF_TYPE_0:
11751 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
11754 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11755 "0494 Unable to allocate memory for "
11756 "issuing SLI_FUNCTION_RESET mailbox "
11761 /* Setup PCI function reset mailbox-ioctl command */
11762 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11763 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11764 LPFC_SLI4_MBX_EMBED);
11765 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11766 shdr = (union lpfc_sli4_cfg_shdr *)
11767 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11768 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11769 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11771 mempool_free(mboxq, phba->mbox_mem_pool);
11772 if (shdr_status || shdr_add_status || rc) {
11773 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11774 "0495 SLI_FUNCTION_RESET mailbox "
11775 "failed with status x%x add_status x%x,"
11776 " mbx status x%x\n",
11777 shdr_status, shdr_add_status, rc);
11781 case LPFC_SLI_INTF_IF_TYPE_2:
11782 case LPFC_SLI_INTF_IF_TYPE_6:
11785 * Poll the Port Status Register and wait for RDY for
11786 * up to 30 seconds. If the port doesn't respond, treat
11789 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
11790 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11791 STATUSregaddr, ®_data.word0)) {
11795 if (bf_get(lpfc_sliport_status_rdy, ®_data))
11800 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
11801 phba->work_status[0] = readl(
11802 phba->sli4_hba.u.if_type2.ERR1regaddr);
11803 phba->work_status[1] = readl(
11804 phba->sli4_hba.u.if_type2.ERR2regaddr);
11805 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11806 "2890 Port not ready, port status reg "
11807 "0x%x error 1=0x%x, error 2=0x%x\n",
11809 phba->work_status[0],
11810 phba->work_status[1]);
11815 if (bf_get(lpfc_sliport_status_pldv, ®_data))
11816 lpfc_pldv_detect = true;
11820 * Reset the port now
11822 reg_data.word0 = 0;
11823 bf_set(lpfc_sliport_ctrl_end, ®_data,
11824 LPFC_SLIPORT_LITTLE_ENDIAN);
11825 bf_set(lpfc_sliport_ctrl_ip, ®_data,
11826 LPFC_SLIPORT_INIT_PORT);
11827 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11830 pci_read_config_word(phba->pcidev,
11831 PCI_DEVICE_ID, &devid);
11836 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
11842 case LPFC_SLI_INTF_IF_TYPE_1:
11848 /* Catch the not-ready port failure after a port reset. */
11850 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11851 "3317 HBA not functional: IP Reset Failed "
11852 "try: echo fw_reset > board_mode\n");
11860 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11861 * @phba: pointer to lpfc hba data structure.
11863 * This routine is invoked to set up the PCI device memory space for device
11864 * with SLI-4 interface spec.
11868 * other values - error
11871 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11873 struct pci_dev *pdev = phba->pcidev;
11874 unsigned long bar0map_len, bar1map_len, bar2map_len;
11881 /* Set the device DMA mask size */
11882 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11884 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11889 * The BARs and register set definitions and offset locations are
11890 * dependent on the if_type.
11892 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11893 &phba->sli4_hba.sli_intf.word0)) {
11897 /* There is no SLI3 failback for SLI4 devices. */
11898 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11899 LPFC_SLI_INTF_VALID) {
11900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11901 "2894 SLI_INTF reg contents invalid "
11902 "sli_intf reg 0x%x\n",
11903 phba->sli4_hba.sli_intf.word0);
11907 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11909 * Get the bus address of SLI4 device Bar regions and the
11910 * number of bytes required by each mapping. The mapping of the
11911 * particular PCI BARs regions is dependent on the type of
11914 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11915 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11916 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
11919 * Map SLI4 PCI Config Space Register base to a kernel virtual
11922 phba->sli4_hba.conf_regs_memmap_p =
11923 ioremap(phba->pci_bar0_map, bar0map_len);
11924 if (!phba->sli4_hba.conf_regs_memmap_p) {
11925 dev_printk(KERN_ERR, &pdev->dev,
11926 "ioremap failed for SLI4 PCI config "
11930 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
11931 /* Set up BAR0 PCI config space register memory map */
11932 lpfc_sli4_bar0_register_memmap(phba, if_type);
11934 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11935 bar0map_len = pci_resource_len(pdev, 1);
11936 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
11937 dev_printk(KERN_ERR, &pdev->dev,
11938 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
11941 phba->sli4_hba.conf_regs_memmap_p =
11942 ioremap(phba->pci_bar0_map, bar0map_len);
11943 if (!phba->sli4_hba.conf_regs_memmap_p) {
11944 dev_printk(KERN_ERR, &pdev->dev,
11945 "ioremap failed for SLI4 PCI config "
11949 lpfc_sli4_bar0_register_memmap(phba, if_type);
11952 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11953 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11955 * Map SLI4 if type 0 HBA Control Register base to a
11956 * kernel virtual address and setup the registers.
11958 phba->pci_bar1_map = pci_resource_start(pdev,
11960 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11961 phba->sli4_hba.ctrl_regs_memmap_p =
11962 ioremap(phba->pci_bar1_map,
11964 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11965 dev_err(&pdev->dev,
11966 "ioremap failed for SLI4 HBA "
11967 "control registers.\n");
11969 goto out_iounmap_conf;
11971 phba->pci_bar2_memmap_p =
11972 phba->sli4_hba.ctrl_regs_memmap_p;
11973 lpfc_sli4_bar1_register_memmap(phba, if_type);
11976 goto out_iounmap_conf;
11980 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11981 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11983 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11984 * virtual address and setup the registers.
11986 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11987 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11988 phba->sli4_hba.drbl_regs_memmap_p =
11989 ioremap(phba->pci_bar1_map, bar1map_len);
11990 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11991 dev_err(&pdev->dev,
11992 "ioremap failed for SLI4 HBA doorbell registers.\n");
11994 goto out_iounmap_conf;
11996 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11997 lpfc_sli4_bar1_register_memmap(phba, if_type);
12000 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
12001 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
12003 * Map SLI4 if type 0 HBA Doorbell Register base to
12004 * a kernel virtual address and setup the registers.
12006 phba->pci_bar2_map = pci_resource_start(pdev,
12008 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
12009 phba->sli4_hba.drbl_regs_memmap_p =
12010 ioremap(phba->pci_bar2_map,
12012 if (!phba->sli4_hba.drbl_regs_memmap_p) {
12013 dev_err(&pdev->dev,
12014 "ioremap failed for SLI4 HBA"
12015 " doorbell registers.\n");
12017 goto out_iounmap_ctrl;
12019 phba->pci_bar4_memmap_p =
12020 phba->sli4_hba.drbl_regs_memmap_p;
12021 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
12023 goto out_iounmap_all;
12026 goto out_iounmap_all;
12030 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
12031 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
12033 * Map SLI4 if type 6 HBA DPP Register base to a kernel
12034 * virtual address and setup the registers.
12036 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
12037 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
12038 phba->sli4_hba.dpp_regs_memmap_p =
12039 ioremap(phba->pci_bar2_map, bar2map_len);
12040 if (!phba->sli4_hba.dpp_regs_memmap_p) {
12041 dev_err(&pdev->dev,
12042 "ioremap failed for SLI4 HBA dpp registers.\n");
12044 goto out_iounmap_ctrl;
12046 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
12049 /* Set up the EQ/CQ register handeling functions now */
12051 case LPFC_SLI_INTF_IF_TYPE_0:
12052 case LPFC_SLI_INTF_IF_TYPE_2:
12053 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
12054 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
12055 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
12057 case LPFC_SLI_INTF_IF_TYPE_6:
12058 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
12059 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
12060 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
12069 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12071 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
12073 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12079 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
12080 * @phba: pointer to lpfc hba data structure.
12082 * This routine is invoked to unset the PCI device memory space for device
12083 * with SLI-4 interface spec.
12086 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
12089 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
12092 case LPFC_SLI_INTF_IF_TYPE_0:
12093 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12094 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
12095 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12097 case LPFC_SLI_INTF_IF_TYPE_2:
12098 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12100 case LPFC_SLI_INTF_IF_TYPE_6:
12101 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12102 iounmap(phba->sli4_hba.conf_regs_memmap_p);
12103 if (phba->sli4_hba.dpp_regs_memmap_p)
12104 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
12106 case LPFC_SLI_INTF_IF_TYPE_1:
12108 dev_printk(KERN_ERR, &phba->pcidev->dev,
12109 "FATAL - unsupported SLI4 interface type - %d\n",
12116 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
12117 * @phba: pointer to lpfc hba data structure.
12119 * This routine is invoked to enable the MSI-X interrupt vectors to device
12120 * with SLI-3 interface specs.
12124 * other values - error
12127 lpfc_sli_enable_msix(struct lpfc_hba *phba)
12132 /* Set up MSI-X multi-message vectors */
12133 rc = pci_alloc_irq_vectors(phba->pcidev,
12134 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
12136 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12137 "0420 PCI enable MSI-X failed (%d)\n", rc);
12142 * Assign MSI-X vectors to interrupt handlers
12145 /* vector-0 is associated to slow-path handler */
12146 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
12147 &lpfc_sli_sp_intr_handler, 0,
12148 LPFC_SP_DRIVER_HANDLER_NAME, phba);
12150 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12151 "0421 MSI-X slow-path request_irq failed "
12156 /* vector-1 is associated to fast-path handler */
12157 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
12158 &lpfc_sli_fp_intr_handler, 0,
12159 LPFC_FP_DRIVER_HANDLER_NAME, phba);
12162 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12163 "0429 MSI-X fast-path request_irq failed "
12169 * Configure HBA MSI-X attention conditions to messages
12171 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12175 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12176 "0474 Unable to allocate memory for issuing "
12177 "MBOX_CONFIG_MSI command\n");
12180 rc = lpfc_config_msi(phba, pmb);
12183 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
12184 if (rc != MBX_SUCCESS) {
12185 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
12186 "0351 Config MSI mailbox command failed, "
12187 "mbxCmd x%x, mbxStatus x%x\n",
12188 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
12192 /* Free memory allocated for mailbox command */
12193 mempool_free(pmb, phba->mbox_mem_pool);
12197 /* Free memory allocated for mailbox command */
12198 mempool_free(pmb, phba->mbox_mem_pool);
12201 /* free the irq already requested */
12202 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
12205 /* free the irq already requested */
12206 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
12209 /* Unconfigure MSI-X capability structure */
12210 pci_free_irq_vectors(phba->pcidev);
12217 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
12218 * @phba: pointer to lpfc hba data structure.
12220 * This routine is invoked to enable the MSI interrupt mode to device with
12221 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
12222 * enable the MSI vector. The device driver is responsible for calling the
12223 * request_irq() to register MSI vector with a interrupt the handler, which
12224 * is done in this function.
12228 * other values - error
12231 lpfc_sli_enable_msi(struct lpfc_hba *phba)
12235 rc = pci_enable_msi(phba->pcidev);
12237 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12238 "0012 PCI enable MSI mode success.\n");
12240 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12241 "0471 PCI enable MSI mode failed (%d)\n", rc);
12245 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12246 0, LPFC_DRIVER_NAME, phba);
12248 pci_disable_msi(phba->pcidev);
12249 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12250 "0478 MSI request_irq failed (%d)\n", rc);
12256 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
12257 * @phba: pointer to lpfc hba data structure.
12258 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
12260 * This routine is invoked to enable device interrupt and associate driver's
12261 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
12262 * spec. Depends on the interrupt mode configured to the driver, the driver
12263 * will try to fallback from the configured interrupt mode to an interrupt
12264 * mode which is supported by the platform, kernel, and device in the order
12266 * MSI-X -> MSI -> IRQ.
12270 * other values - error
12273 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12275 uint32_t intr_mode = LPFC_INTR_ERROR;
12278 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
12279 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
12282 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
12284 if (cfg_mode == 2) {
12285 /* Now, try to enable MSI-X interrupt mode */
12286 retval = lpfc_sli_enable_msix(phba);
12288 /* Indicate initialization to MSI-X mode */
12289 phba->intr_type = MSIX;
12294 /* Fallback to MSI if MSI-X initialization failed */
12295 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12296 retval = lpfc_sli_enable_msi(phba);
12298 /* Indicate initialization to MSI mode */
12299 phba->intr_type = MSI;
12304 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12305 if (phba->intr_type == NONE) {
12306 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12307 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12309 /* Indicate initialization to INTx mode */
12310 phba->intr_type = INTx;
12318 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
12319 * @phba: pointer to lpfc hba data structure.
12321 * This routine is invoked to disable device interrupt and disassociate the
12322 * driver's interrupt handler(s) from interrupt vector(s) to device with
12323 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
12324 * release the interrupt vector(s) for the message signaled interrupt.
12327 lpfc_sli_disable_intr(struct lpfc_hba *phba)
12331 if (phba->intr_type == MSIX)
12332 nr_irqs = LPFC_MSIX_VECTORS;
12336 for (i = 0; i < nr_irqs; i++)
12337 free_irq(pci_irq_vector(phba->pcidev, i), phba);
12338 pci_free_irq_vectors(phba->pcidev);
12340 /* Reset interrupt management states */
12341 phba->intr_type = NONE;
12342 phba->sli.slistat.sli_intr = 0;
12346 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
12347 * @phba: pointer to lpfc hba data structure.
12348 * @id: EQ vector index or Hardware Queue index
12349 * @match: LPFC_FIND_BY_EQ = match by EQ
12350 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
12351 * Return the CPU that matches the selection criteria
12354 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
12356 struct lpfc_vector_map_info *cpup;
12359 /* Loop through all CPUs */
12360 for_each_present_cpu(cpu) {
12361 cpup = &phba->sli4_hba.cpu_map[cpu];
12363 /* If we are matching by EQ, there may be multiple CPUs using
12364 * using the same vector, so select the one with
12365 * LPFC_CPU_FIRST_IRQ set.
12367 if ((match == LPFC_FIND_BY_EQ) &&
12368 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
12372 /* If matching by HDWQ, select the first CPU that matches */
12373 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
12381 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
12382 * @phba: pointer to lpfc hba data structure.
12383 * @cpu: CPU map index
12384 * @phys_id: CPU package physical id
12385 * @core_id: CPU core id
12388 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
12389 uint16_t phys_id, uint16_t core_id)
12391 struct lpfc_vector_map_info *cpup;
12394 for_each_present_cpu(idx) {
12395 cpup = &phba->sli4_hba.cpu_map[idx];
12396 /* Does the cpup match the one we are looking for */
12397 if ((cpup->phys_id == phys_id) &&
12398 (cpup->core_id == core_id) &&
12407 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
12408 * @phba: pointer to lpfc hba data structure.
12409 * @eqidx: index for eq and irq vector
12410 * @flag: flags to set for vector_map structure
12411 * @cpu: cpu used to index vector_map structure
12413 * The routine assigns eq info into vector_map structure
12416 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
12419 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
12420 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
12423 cpup->flag |= flag;
12425 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12426 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
12427 cpu, eqhdl->irq, cpup->eq, cpup->flag);
12431 * lpfc_cpu_map_array_init - Initialize cpu_map structure
12432 * @phba: pointer to lpfc hba data structure.
12434 * The routine initializes the cpu_map array structure
12437 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
12439 struct lpfc_vector_map_info *cpup;
12440 struct lpfc_eq_intr_info *eqi;
12443 for_each_possible_cpu(cpu) {
12444 cpup = &phba->sli4_hba.cpu_map[cpu];
12445 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
12446 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
12447 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
12448 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
12450 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
12451 INIT_LIST_HEAD(&eqi->list);
12457 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
12458 * @phba: pointer to lpfc hba data structure.
12460 * The routine initializes the hba_eq_hdl array structure
12463 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
12465 struct lpfc_hba_eq_hdl *eqhdl;
12468 for (i = 0; i < phba->cfg_irq_chann; i++) {
12469 eqhdl = lpfc_get_eq_hdl(i);
12470 eqhdl->irq = LPFC_IRQ_EMPTY;
12471 eqhdl->phba = phba;
12476 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
12477 * @phba: pointer to lpfc hba data structure.
12478 * @vectors: number of msix vectors allocated.
12480 * The routine will figure out the CPU affinity assignment for every
12481 * MSI-X vector allocated for the HBA.
12482 * In addition, the CPU to IO channel mapping will be calculated
12483 * and the phba->sli4_hba.cpu_map array will reflect this.
12486 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
12488 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
12489 int max_phys_id, min_phys_id;
12490 int max_core_id, min_core_id;
12491 struct lpfc_vector_map_info *cpup;
12492 struct lpfc_vector_map_info *new_cpup;
12494 struct cpuinfo_x86 *cpuinfo;
12496 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12497 struct lpfc_hdwq_stat *c_stat;
12501 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
12503 min_core_id = LPFC_VECTOR_MAP_EMPTY;
12505 /* Update CPU map with physical id and core id of each CPU */
12506 for_each_present_cpu(cpu) {
12507 cpup = &phba->sli4_hba.cpu_map[cpu];
12509 cpuinfo = &cpu_data(cpu);
12510 cpup->phys_id = cpuinfo->phys_proc_id;
12511 cpup->core_id = cpuinfo->cpu_core_id;
12512 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
12513 cpup->flag |= LPFC_CPU_MAP_HYPER;
12515 /* No distinction between CPUs for other platforms */
12517 cpup->core_id = cpu;
12520 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12521 "3328 CPU %d physid %d coreid %d flag x%x\n",
12522 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
12524 if (cpup->phys_id > max_phys_id)
12525 max_phys_id = cpup->phys_id;
12526 if (cpup->phys_id < min_phys_id)
12527 min_phys_id = cpup->phys_id;
12529 if (cpup->core_id > max_core_id)
12530 max_core_id = cpup->core_id;
12531 if (cpup->core_id < min_core_id)
12532 min_core_id = cpup->core_id;
12535 /* After looking at each irq vector assigned to this pcidev, its
12536 * possible to see that not ALL CPUs have been accounted for.
12537 * Next we will set any unassigned (unaffinitized) cpu map
12538 * entries to a IRQ on the same phys_id.
12540 first_cpu = cpumask_first(cpu_present_mask);
12541 start_cpu = first_cpu;
12543 for_each_present_cpu(cpu) {
12544 cpup = &phba->sli4_hba.cpu_map[cpu];
12546 /* Is this CPU entry unassigned */
12547 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12548 /* Mark CPU as IRQ not assigned by the kernel */
12549 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12551 /* If so, find a new_cpup that is on the SAME
12552 * phys_id as cpup. start_cpu will start where we
12553 * left off so all unassigned entries don't get assgined
12554 * the IRQ of the first entry.
12556 new_cpu = start_cpu;
12557 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12558 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12559 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12560 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
12561 (new_cpup->phys_id == cpup->phys_id))
12563 new_cpu = cpumask_next(
12564 new_cpu, cpu_present_mask);
12565 if (new_cpu == nr_cpumask_bits)
12566 new_cpu = first_cpu;
12568 /* At this point, we leave the CPU as unassigned */
12571 /* We found a matching phys_id, so copy the IRQ info */
12572 cpup->eq = new_cpup->eq;
12574 /* Bump start_cpu to the next slot to minmize the
12575 * chance of having multiple unassigned CPU entries
12576 * selecting the same IRQ.
12578 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12579 if (start_cpu == nr_cpumask_bits)
12580 start_cpu = first_cpu;
12582 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12583 "3337 Set Affinity: CPU %d "
12584 "eq %d from peer cpu %d same "
12586 cpu, cpup->eq, new_cpu,
12591 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
12592 start_cpu = first_cpu;
12594 for_each_present_cpu(cpu) {
12595 cpup = &phba->sli4_hba.cpu_map[cpu];
12597 /* Is this entry unassigned */
12598 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12599 /* Mark it as IRQ not assigned by the kernel */
12600 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12602 /* If so, find a new_cpup thats on ANY phys_id
12603 * as the cpup. start_cpu will start where we
12604 * left off so all unassigned entries don't get
12605 * assigned the IRQ of the first entry.
12607 new_cpu = start_cpu;
12608 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12609 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12610 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
12611 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
12613 new_cpu = cpumask_next(
12614 new_cpu, cpu_present_mask);
12615 if (new_cpu == nr_cpumask_bits)
12616 new_cpu = first_cpu;
12618 /* We should never leave an entry unassigned */
12619 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12620 "3339 Set Affinity: CPU %d "
12621 "eq %d UNASSIGNED\n",
12622 cpup->hdwq, cpup->eq);
12625 /* We found an available entry, copy the IRQ info */
12626 cpup->eq = new_cpup->eq;
12628 /* Bump start_cpu to the next slot to minmize the
12629 * chance of having multiple unassigned CPU entries
12630 * selecting the same IRQ.
12632 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12633 if (start_cpu == nr_cpumask_bits)
12634 start_cpu = first_cpu;
12636 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12637 "3338 Set Affinity: CPU %d "
12638 "eq %d from peer cpu %d (%d/%d)\n",
12639 cpu, cpup->eq, new_cpu,
12640 new_cpup->phys_id, new_cpup->core_id);
12644 /* Assign hdwq indices that are unique across all cpus in the map
12645 * that are also FIRST_CPUs.
12648 for_each_present_cpu(cpu) {
12649 cpup = &phba->sli4_hba.cpu_map[cpu];
12651 /* Only FIRST IRQs get a hdwq index assignment. */
12652 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12655 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
12658 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12659 "3333 Set Affinity: CPU %d (phys %d core %d): "
12660 "hdwq %d eq %d flg x%x\n",
12661 cpu, cpup->phys_id, cpup->core_id,
12662 cpup->hdwq, cpup->eq, cpup->flag);
12664 /* Associate a hdwq with each cpu_map entry
12665 * This will be 1 to 1 - hdwq to cpu, unless there are less
12666 * hardware queues then CPUs. For that case we will just round-robin
12667 * the available hardware queues as they get assigned to CPUs.
12668 * The next_idx is the idx from the FIRST_CPU loop above to account
12669 * for irq_chann < hdwq. The idx is used for round-robin assignments
12670 * and needs to start at 0.
12675 for_each_present_cpu(cpu) {
12676 cpup = &phba->sli4_hba.cpu_map[cpu];
12678 /* FIRST cpus are already mapped. */
12679 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
12682 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
12683 * of the unassigned cpus to the next idx so that all
12684 * hdw queues are fully utilized.
12686 if (next_idx < phba->cfg_hdw_queue) {
12687 cpup->hdwq = next_idx;
12692 /* Not a First CPU and all hdw_queues are used. Reuse a
12693 * Hardware Queue for another CPU, so be smart about it
12694 * and pick one that has its IRQ/EQ mapped to the same phys_id
12695 * (CPU package) and core_id.
12697 new_cpu = start_cpu;
12698 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12699 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12700 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12701 new_cpup->phys_id == cpup->phys_id &&
12702 new_cpup->core_id == cpup->core_id) {
12705 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12706 if (new_cpu == nr_cpumask_bits)
12707 new_cpu = first_cpu;
12710 /* If we can't match both phys_id and core_id,
12711 * settle for just a phys_id match.
12713 new_cpu = start_cpu;
12714 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12715 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12716 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12717 new_cpup->phys_id == cpup->phys_id)
12720 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12721 if (new_cpu == nr_cpumask_bits)
12722 new_cpu = first_cpu;
12725 /* Otherwise just round robin on cfg_hdw_queue */
12726 cpup->hdwq = idx % phba->cfg_hdw_queue;
12730 /* We found an available entry, copy the IRQ info */
12731 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12732 if (start_cpu == nr_cpumask_bits)
12733 start_cpu = first_cpu;
12734 cpup->hdwq = new_cpup->hdwq;
12736 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12737 "3335 Set Affinity: CPU %d (phys %d core %d): "
12738 "hdwq %d eq %d flg x%x\n",
12739 cpu, cpup->phys_id, cpup->core_id,
12740 cpup->hdwq, cpup->eq, cpup->flag);
12744 * Initialize the cpu_map slots for not-present cpus in case
12745 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
12748 for_each_possible_cpu(cpu) {
12749 cpup = &phba->sli4_hba.cpu_map[cpu];
12750 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12751 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
12752 c_stat->hdwq_no = cpup->hdwq;
12754 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
12757 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
12758 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12759 c_stat->hdwq_no = cpup->hdwq;
12761 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12762 "3340 Set Affinity: not present "
12763 "CPU %d hdwq %d\n",
12767 /* The cpu_map array will be used later during initialization
12768 * when EQ / CQ / WQs are allocated and configured.
12774 * lpfc_cpuhp_get_eq
12776 * @phba: pointer to lpfc hba data structure.
12777 * @cpu: cpu going offline
12778 * @eqlist: eq list to append to
12781 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12782 struct list_head *eqlist)
12784 const struct cpumask *maskp;
12785 struct lpfc_queue *eq;
12786 struct cpumask *tmp;
12789 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12793 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12794 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12798 * if irq is not affinitized to the cpu going
12799 * then we don't need to poll the eq attached
12802 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
12804 /* get the cpus that are online and are affini-
12805 * tized to this irq vector. If the count is
12806 * more than 1 then cpuhp is not going to shut-
12807 * down this vector. Since this cpu has not
12808 * gone offline yet, we need >1.
12810 cpumask_and(tmp, maskp, cpu_online_mask);
12811 if (cpumask_weight(tmp) > 1)
12814 /* Now that we have an irq to shutdown, get the eq
12815 * mapped to this irq. Note: multiple hdwq's in
12816 * the software can share an eq, but eventually
12817 * only eq will be mapped to this vector
12819 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12820 list_add(&eq->_poll_list, eqlist);
12826 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12828 if (phba->sli_rev != LPFC_SLI_REV4)
12831 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12834 * unregistering the instance doesn't stop the polling
12835 * timer. Wait for the poll timer to retire.
12838 del_timer_sync(&phba->cpuhp_poll_timer);
12841 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12843 if (phba->pport && (phba->pport->fc_flag & FC_OFFLINE_MODE))
12846 __lpfc_cpuhp_remove(phba);
12849 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12851 if (phba->sli_rev != LPFC_SLI_REV4)
12856 if (!list_empty(&phba->poll_list))
12857 mod_timer(&phba->cpuhp_poll_timer,
12858 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
12862 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12866 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12868 if (phba->pport->load_flag & FC_UNLOADING) {
12873 if (phba->sli_rev != LPFC_SLI_REV4) {
12878 /* proceed with the hotplug */
12883 * lpfc_irq_set_aff - set IRQ affinity
12884 * @eqhdl: EQ handle
12885 * @cpu: cpu to set affinity
12889 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12891 cpumask_clear(&eqhdl->aff_mask);
12892 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12893 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12894 irq_set_affinity(eqhdl->irq, &eqhdl->aff_mask);
12898 * lpfc_irq_clear_aff - clear IRQ affinity
12899 * @eqhdl: EQ handle
12903 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12905 cpumask_clear(&eqhdl->aff_mask);
12906 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12910 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12911 * @phba: pointer to HBA context object.
12912 * @cpu: cpu going offline/online
12913 * @offline: true, cpu is going offline. false, cpu is coming online.
12915 * If cpu is going offline, we'll try our best effort to find the next
12916 * online cpu on the phba's original_mask and migrate all offlining IRQ
12919 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
12921 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
12922 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12926 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12928 struct lpfc_vector_map_info *cpup;
12929 struct cpumask *aff_mask;
12930 unsigned int cpu_select, cpu_next, idx;
12931 const struct cpumask *orig_mask;
12933 if (phba->irq_chann_mode == NORMAL_MODE)
12936 orig_mask = &phba->sli4_hba.irq_aff_mask;
12938 if (!cpumask_test_cpu(cpu, orig_mask))
12941 cpup = &phba->sli4_hba.cpu_map[cpu];
12943 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12947 /* Find next online CPU on original mask */
12948 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12949 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
12951 /* Found a valid CPU */
12952 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12953 /* Go through each eqhdl and ensure offlining
12954 * cpu aff_mask is migrated
12956 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12957 aff_mask = lpfc_get_aff_mask(idx);
12959 /* Migrate affinity */
12960 if (cpumask_test_cpu(cpu, aff_mask))
12961 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12965 /* Rely on irqbalance if no online CPUs left on NUMA */
12966 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12967 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12970 /* Migrate affinity back to this CPU */
12971 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12975 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12977 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12978 struct lpfc_queue *eq, *next;
12983 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12987 if (__lpfc_cpuhp_checks(phba, &retval))
12990 lpfc_irq_rebalance(phba, cpu, true);
12992 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12996 /* start polling on these eq's */
12997 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12998 list_del_init(&eq->_poll_list);
12999 lpfc_sli4_start_polling(eq);
13005 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
13007 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
13008 struct lpfc_queue *eq, *next;
13013 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
13017 if (__lpfc_cpuhp_checks(phba, &retval))
13020 lpfc_irq_rebalance(phba, cpu, false);
13022 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
13023 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
13025 lpfc_sli4_stop_polling(eq);
13032 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
13033 * @phba: pointer to lpfc hba data structure.
13035 * This routine is invoked to enable the MSI-X interrupt vectors to device
13036 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
13037 * to cpus on the system.
13039 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
13040 * the number of cpus on the same numa node as this adapter. The vectors are
13041 * allocated without requesting OS affinity mapping. A vector will be
13042 * allocated and assigned to each online and offline cpu. If the cpu is
13043 * online, then affinity will be set to that cpu. If the cpu is offline, then
13044 * affinity will be set to the nearest peer cpu within the numa node that is
13045 * online. If there are no online cpus within the numa node, affinity is not
13046 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
13047 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
13050 * If numa mode is not enabled and there is more than 1 vector allocated, then
13051 * the driver relies on the managed irq interface where the OS assigns vector to
13052 * cpu affinity. The driver will then use that affinity mapping to setup its
13053 * cpu mapping table.
13057 * other values - error
13060 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
13062 int vectors, rc, index;
13064 const struct cpumask *aff_mask = NULL;
13065 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
13066 struct lpfc_vector_map_info *cpup;
13067 struct lpfc_hba_eq_hdl *eqhdl;
13068 const struct cpumask *maskp;
13069 unsigned int flags = PCI_IRQ_MSIX;
13071 /* Set up MSI-X multi-message vectors */
13072 vectors = phba->cfg_irq_chann;
13074 if (phba->irq_chann_mode != NORMAL_MODE)
13075 aff_mask = &phba->sli4_hba.irq_aff_mask;
13078 cpu_cnt = cpumask_weight(aff_mask);
13079 vectors = min(phba->cfg_irq_chann, cpu_cnt);
13081 /* cpu: iterates over aff_mask including offline or online
13082 * cpu_select: iterates over online aff_mask to set affinity
13084 cpu = cpumask_first(aff_mask);
13085 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
13087 flags |= PCI_IRQ_AFFINITY;
13090 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
13092 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13093 "0484 PCI enable MSI-X failed (%d)\n", rc);
13098 /* Assign MSI-X vectors to interrupt handlers */
13099 for (index = 0; index < vectors; index++) {
13100 eqhdl = lpfc_get_eq_hdl(index);
13101 name = eqhdl->handler_name;
13102 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
13103 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
13104 LPFC_DRIVER_HANDLER_NAME"%d", index);
13106 eqhdl->idx = index;
13107 rc = pci_irq_vector(phba->pcidev, index);
13109 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13110 "0489 MSI-X fast-path (%d) "
13111 "pci_irq_vec failed (%d)\n", index, rc);
13116 rc = request_irq(eqhdl->irq, &lpfc_sli4_hba_intr_handler, 0,
13119 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13120 "0486 MSI-X fast-path (%d) "
13121 "request_irq failed (%d)\n", index, rc);
13126 /* If found a neighboring online cpu, set affinity */
13127 if (cpu_select < nr_cpu_ids)
13128 lpfc_irq_set_aff(eqhdl, cpu_select);
13130 /* Assign EQ to cpu_map */
13131 lpfc_assign_eq_map_info(phba, index,
13132 LPFC_CPU_FIRST_IRQ,
13135 /* Iterate to next offline or online cpu in aff_mask */
13136 cpu = cpumask_next(cpu, aff_mask);
13138 /* Find next online cpu in aff_mask to set affinity */
13139 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
13140 } else if (vectors == 1) {
13141 cpu = cpumask_first(cpu_present_mask);
13142 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
13145 maskp = pci_irq_get_affinity(phba->pcidev, index);
13147 /* Loop through all CPUs associated with vector index */
13148 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
13149 cpup = &phba->sli4_hba.cpu_map[cpu];
13151 /* If this is the first CPU thats assigned to
13152 * this vector, set LPFC_CPU_FIRST_IRQ.
13154 * With certain platforms its possible that irq
13155 * vectors are affinitized to all the cpu's.
13156 * This can result in each cpu_map.eq to be set
13157 * to the last vector, resulting in overwrite
13158 * of all the previous cpu_map.eq. Ensure that
13159 * each vector receives a place in cpu_map.
13160 * Later call to lpfc_cpu_affinity_check will
13161 * ensure we are nicely balanced out.
13163 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
13165 lpfc_assign_eq_map_info(phba, index,
13166 LPFC_CPU_FIRST_IRQ,
13173 if (vectors != phba->cfg_irq_chann) {
13174 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13175 "3238 Reducing IO channels to match number of "
13176 "MSI-X vectors, requested %d got %d\n",
13177 phba->cfg_irq_chann, vectors);
13178 if (phba->cfg_irq_chann > vectors)
13179 phba->cfg_irq_chann = vectors;
13185 /* free the irq already requested */
13186 for (--index; index >= 0; index--) {
13187 eqhdl = lpfc_get_eq_hdl(index);
13188 lpfc_irq_clear_aff(eqhdl);
13189 free_irq(eqhdl->irq, eqhdl);
13192 /* Unconfigure MSI-X capability structure */
13193 pci_free_irq_vectors(phba->pcidev);
13200 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
13201 * @phba: pointer to lpfc hba data structure.
13203 * This routine is invoked to enable the MSI interrupt mode to device with
13204 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
13205 * called to enable the MSI vector. The device driver is responsible for
13206 * calling the request_irq() to register MSI vector with a interrupt the
13207 * handler, which is done in this function.
13211 * other values - error
13214 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
13218 struct lpfc_hba_eq_hdl *eqhdl;
13220 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
13221 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
13223 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13224 "0487 PCI enable MSI mode success.\n");
13226 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13227 "0488 PCI enable MSI mode failed (%d)\n", rc);
13228 return rc ? rc : -1;
13231 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13232 0, LPFC_DRIVER_NAME, phba);
13234 pci_free_irq_vectors(phba->pcidev);
13235 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13236 "0490 MSI request_irq failed (%d)\n", rc);
13240 eqhdl = lpfc_get_eq_hdl(0);
13241 rc = pci_irq_vector(phba->pcidev, 0);
13243 pci_free_irq_vectors(phba->pcidev);
13244 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13245 "0496 MSI pci_irq_vec failed (%d)\n", rc);
13250 cpu = cpumask_first(cpu_present_mask);
13251 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
13253 for (index = 0; index < phba->cfg_irq_chann; index++) {
13254 eqhdl = lpfc_get_eq_hdl(index);
13255 eqhdl->idx = index;
13262 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
13263 * @phba: pointer to lpfc hba data structure.
13264 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
13266 * This routine is invoked to enable device interrupt and associate driver's
13267 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
13268 * interface spec. Depends on the interrupt mode configured to the driver,
13269 * the driver will try to fallback from the configured interrupt mode to an
13270 * interrupt mode which is supported by the platform, kernel, and device in
13272 * MSI-X -> MSI -> IRQ.
13275 * Interrupt mode (2, 1, 0) - successful
13276 * LPFC_INTR_ERROR - error
13279 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
13281 uint32_t intr_mode = LPFC_INTR_ERROR;
13284 if (cfg_mode == 2) {
13285 /* Preparation before conf_msi mbox cmd */
13288 /* Now, try to enable MSI-X interrupt mode */
13289 retval = lpfc_sli4_enable_msix(phba);
13291 /* Indicate initialization to MSI-X mode */
13292 phba->intr_type = MSIX;
13298 /* Fallback to MSI if MSI-X initialization failed */
13299 if (cfg_mode >= 1 && phba->intr_type == NONE) {
13300 retval = lpfc_sli4_enable_msi(phba);
13302 /* Indicate initialization to MSI mode */
13303 phba->intr_type = MSI;
13308 /* Fallback to INTx if both MSI-X/MSI initalization failed */
13309 if (phba->intr_type == NONE) {
13310 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13311 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
13313 struct lpfc_hba_eq_hdl *eqhdl;
13316 /* Indicate initialization to INTx mode */
13317 phba->intr_type = INTx;
13320 eqhdl = lpfc_get_eq_hdl(0);
13321 retval = pci_irq_vector(phba->pcidev, 0);
13323 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
13324 "0502 INTR pci_irq_vec failed (%d)\n",
13326 return LPFC_INTR_ERROR;
13328 eqhdl->irq = retval;
13330 cpu = cpumask_first(cpu_present_mask);
13331 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
13333 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
13334 eqhdl = lpfc_get_eq_hdl(idx);
13343 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
13344 * @phba: pointer to lpfc hba data structure.
13346 * This routine is invoked to disable device interrupt and disassociate
13347 * the driver's interrupt handler(s) from interrupt vector(s) to device
13348 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
13349 * will release the interrupt vector(s) for the message signaled interrupt.
13352 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
13354 /* Disable the currently initialized interrupt mode */
13355 if (phba->intr_type == MSIX) {
13357 struct lpfc_hba_eq_hdl *eqhdl;
13359 /* Free up MSI-X multi-message vectors */
13360 for (index = 0; index < phba->cfg_irq_chann; index++) {
13361 eqhdl = lpfc_get_eq_hdl(index);
13362 lpfc_irq_clear_aff(eqhdl);
13363 free_irq(eqhdl->irq, eqhdl);
13366 free_irq(phba->pcidev->irq, phba);
13369 pci_free_irq_vectors(phba->pcidev);
13371 /* Reset interrupt management states */
13372 phba->intr_type = NONE;
13373 phba->sli.slistat.sli_intr = 0;
13377 * lpfc_unset_hba - Unset SLI3 hba device initialization
13378 * @phba: pointer to lpfc hba data structure.
13380 * This routine is invoked to unset the HBA device initialization steps to
13381 * a device with SLI-3 interface spec.
13384 lpfc_unset_hba(struct lpfc_hba *phba)
13386 struct lpfc_vport *vport = phba->pport;
13387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
13389 spin_lock_irq(shost->host_lock);
13390 vport->load_flag |= FC_UNLOADING;
13391 spin_unlock_irq(shost->host_lock);
13393 kfree(phba->vpi_bmask);
13394 kfree(phba->vpi_ids);
13396 lpfc_stop_hba_timers(phba);
13398 phba->pport->work_port_events = 0;
13400 lpfc_sli_hba_down(phba);
13402 lpfc_sli_brdrestart(phba);
13404 lpfc_sli_disable_intr(phba);
13410 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
13411 * @phba: Pointer to HBA context object.
13413 * This function is called in the SLI4 code path to wait for completion
13414 * of device's XRIs exchange busy. It will check the XRI exchange busy
13415 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
13416 * that, it will check the XRI exchange busy on outstanding FCP and ELS
13417 * I/Os every 30 seconds, log error message, and wait forever. Only when
13418 * all XRI exchange busy complete, the driver unload shall proceed with
13419 * invoking the function reset ioctl mailbox command to the CNA and the
13420 * the rest of the driver unload resource release.
13423 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
13425 struct lpfc_sli4_hdw_queue *qp;
13428 int io_xri_cmpl = 1;
13429 int nvmet_xri_cmpl = 1;
13430 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13432 /* Driver just aborted IOs during the hba_unset process. Pause
13433 * here to give the HBA time to complete the IO and get entries
13434 * into the abts lists.
13436 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
13438 /* Wait for NVME pending IO to flush back to transport. */
13439 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13440 lpfc_nvme_wait_for_io_drain(phba);
13443 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13444 qp = &phba->sli4_hba.hdwq[idx];
13445 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
13446 if (!io_xri_cmpl) /* if list is NOT empty */
13452 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13454 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13457 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
13458 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
13459 if (!nvmet_xri_cmpl)
13460 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13461 "6424 NVMET XRI exchange busy "
13462 "wait time: %d seconds.\n",
13465 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13466 "6100 IO XRI exchange busy "
13467 "wait time: %d seconds.\n",
13470 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13471 "2878 ELS XRI exchange busy "
13472 "wait time: %d seconds.\n",
13474 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
13475 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
13477 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
13478 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
13482 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13483 qp = &phba->sli4_hba.hdwq[idx];
13484 io_xri_cmpl = list_empty(
13485 &qp->lpfc_abts_io_buf_list);
13486 if (!io_xri_cmpl) /* if list is NOT empty */
13492 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13493 nvmet_xri_cmpl = list_empty(
13494 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13497 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13503 * lpfc_sli4_hba_unset - Unset the fcoe hba
13504 * @phba: Pointer to HBA context object.
13506 * This function is called in the SLI4 code path to reset the HBA's FCoE
13507 * function. The caller is not required to hold any lock. This routine
13508 * issues PCI function reset mailbox command to reset the FCoE function.
13509 * At the end of the function, it calls lpfc_hba_down_post function to
13510 * free any pending commands.
13513 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
13516 LPFC_MBOXQ_t *mboxq;
13517 struct pci_dev *pdev = phba->pcidev;
13519 lpfc_stop_hba_timers(phba);
13520 hrtimer_cancel(&phba->cmf_timer);
13523 phba->sli4_hba.intr_enable = 0;
13526 * Gracefully wait out the potential current outstanding asynchronous
13530 /* First, block any pending async mailbox command from posted */
13531 spin_lock_irq(&phba->hbalock);
13532 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13533 spin_unlock_irq(&phba->hbalock);
13534 /* Now, trying to wait it out if we can */
13535 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13537 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
13540 /* Forcefully release the outstanding mailbox command if timed out */
13541 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13542 spin_lock_irq(&phba->hbalock);
13543 mboxq = phba->sli.mbox_active;
13544 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
13545 __lpfc_mbox_cmpl_put(phba, mboxq);
13546 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13547 phba->sli.mbox_active = NULL;
13548 spin_unlock_irq(&phba->hbalock);
13551 /* Abort all iocbs associated with the hba */
13552 lpfc_sli_hba_iocb_abort(phba);
13554 if (!pci_channel_offline(phba->pcidev))
13555 /* Wait for completion of device XRI exchange busy */
13556 lpfc_sli4_xri_exchange_busy_wait(phba);
13558 /* per-phba callback de-registration for hotplug event */
13560 lpfc_cpuhp_remove(phba);
13562 /* Disable PCI subsystem interrupt */
13563 lpfc_sli4_disable_intr(phba);
13565 /* Disable SR-IOV if enabled */
13566 if (phba->cfg_sriov_nr_virtfn)
13567 pci_disable_sriov(pdev);
13569 /* Stop kthread signal shall trigger work_done one more time */
13570 kthread_stop(phba->worker_thread);
13572 /* Disable FW logging to host memory */
13573 lpfc_ras_stop_fwlog(phba);
13575 /* Reset SLI4 HBA FCoE function */
13576 lpfc_pci_function_reset(phba);
13578 /* release all queue allocated resources. */
13579 lpfc_sli4_queue_destroy(phba);
13581 /* Free RAS DMA memory */
13582 if (phba->ras_fwlog.ras_enabled)
13583 lpfc_sli4_ras_dma_free(phba);
13585 /* Stop the SLI4 device port */
13587 phba->pport->work_port_events = 0;
13591 lpfc_cgn_crc32(uint32_t crc, u8 byte)
13596 for (bit = 0; bit < 8; bit++) {
13597 msb = (crc >> 31) & 1;
13600 if (msb ^ (byte & 1)) {
13601 crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
13610 lpfc_cgn_reverse_bits(uint32_t wd)
13612 uint32_t result = 0;
13615 for (i = 0; i < 32; i++) {
13617 result |= (1 & (wd >> i));
13623 * The routine corresponds with the algorithm the HBA firmware
13624 * uses to validate the data integrity.
13627 lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
13631 uint8_t *data = (uint8_t *)ptr;
13633 for (i = 0; i < byteLen; ++i)
13634 crc = lpfc_cgn_crc32(crc, data[i]);
13636 result = ~lpfc_cgn_reverse_bits(crc);
13641 lpfc_init_congestion_buf(struct lpfc_hba *phba)
13643 struct lpfc_cgn_info *cp;
13644 struct timespec64 cmpl_time;
13649 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13650 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
13654 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13656 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
13657 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
13658 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
13659 atomic_set(&phba->cgn_sync_warn_cnt, 0);
13661 atomic_set(&phba->cgn_driver_evt_cnt, 0);
13662 atomic_set(&phba->cgn_latency_evt_cnt, 0);
13663 atomic64_set(&phba->cgn_latency_evt, 0);
13664 phba->cgn_evt_minute = 0;
13665 phba->hba_flag &= ~HBA_CGN_DAY_WRAP;
13667 memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat));
13668 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
13669 cp->cgn_info_version = LPFC_CGN_INFO_V3;
13671 /* cgn parameters */
13672 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
13673 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
13674 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
13675 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
13677 ktime_get_real_ts64(&cmpl_time);
13678 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13680 cp->cgn_info_month = broken.tm_mon + 1;
13681 cp->cgn_info_day = broken.tm_mday;
13682 cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */
13683 cp->cgn_info_hour = broken.tm_hour;
13684 cp->cgn_info_minute = broken.tm_min;
13685 cp->cgn_info_second = broken.tm_sec;
13687 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13688 "2643 CGNInfo Init: Start Time "
13689 "%d/%d/%d %d:%d:%d\n",
13690 cp->cgn_info_day, cp->cgn_info_month,
13691 cp->cgn_info_year, cp->cgn_info_hour,
13692 cp->cgn_info_minute, cp->cgn_info_second);
13694 /* Fill in default LUN qdepth */
13696 size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
13697 cp->cgn_lunq = cpu_to_le16(size);
13700 /* last used Index initialized to 0xff already */
13702 cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13703 cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
13704 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13705 cp->cgn_info_crc = cpu_to_le32(crc);
13707 phba->cgn_evt_timestamp = jiffies +
13708 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
13712 lpfc_init_congestion_stat(struct lpfc_hba *phba)
13714 struct lpfc_cgn_info *cp;
13715 struct timespec64 cmpl_time;
13719 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13720 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
13725 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13726 memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));
13728 ktime_get_real_ts64(&cmpl_time);
13729 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13731 cp->cgn_stat_month = broken.tm_mon + 1;
13732 cp->cgn_stat_day = broken.tm_mday;
13733 cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */
13734 cp->cgn_stat_hour = broken.tm_hour;
13735 cp->cgn_stat_minute = broken.tm_min;
13737 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13738 "2647 CGNstat Init: Start Time "
13739 "%d/%d/%d %d:%d\n",
13740 cp->cgn_stat_day, cp->cgn_stat_month,
13741 cp->cgn_stat_year, cp->cgn_stat_hour,
13742 cp->cgn_stat_minute);
13744 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13745 cp->cgn_info_crc = cpu_to_le32(crc);
13749 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
13750 * @phba: Pointer to hba context object.
13751 * @reg: flag to determine register or unregister.
13754 __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
13756 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
13757 union lpfc_sli4_cfg_shdr *shdr;
13758 uint32_t shdr_status, shdr_add_status;
13759 LPFC_MBOXQ_t *mboxq;
13765 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13767 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13768 "2641 REG_CONGESTION_BUF mbox allocation fail: "
13769 "HBA state x%x reg %d\n",
13770 phba->pport->port_state, reg);
13774 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
13775 sizeof(struct lpfc_sli4_cfg_mhdr));
13776 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13777 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
13778 LPFC_SLI4_MBX_EMBED);
13779 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
13780 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
13782 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
13784 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
13785 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
13786 reg_congestion_buf->addr_lo =
13787 putPaddrLow(phba->cgn_i->phys);
13788 reg_congestion_buf->addr_hi =
13789 putPaddrHigh(phba->cgn_i->phys);
13791 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13792 shdr = (union lpfc_sli4_cfg_shdr *)
13793 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
13794 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13795 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13797 mempool_free(mboxq, phba->mbox_mem_pool);
13798 if (shdr_status || shdr_add_status || rc) {
13799 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13800 "2642 REG_CONGESTION_BUF mailbox "
13801 "failed with status x%x add_status x%x,"
13802 " mbx status x%x reg %d\n",
13803 shdr_status, shdr_add_status, rc, reg);
13810 lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
13812 lpfc_cmf_stop(phba);
13813 return __lpfc_reg_congestion_buf(phba, 0);
13817 lpfc_reg_congestion_buf(struct lpfc_hba *phba)
13819 return __lpfc_reg_congestion_buf(phba, 1);
13823 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
13824 * @phba: Pointer to HBA context object.
13825 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
13827 * This function is called in the SLI4 code path to read the port's
13828 * sli4 capabilities.
13830 * This function may be be called from any context that can block-wait
13831 * for the completion. The expectation is that this routine is called
13832 * typically from probe_one or from the online routine.
13835 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
13838 struct lpfc_mqe *mqe = &mboxq->u.mqe;
13839 struct lpfc_pc_sli4_params *sli4_params;
13842 bool exp_wqcq_pages = true;
13843 struct lpfc_sli4_parameters *mbx_sli4_parameters;
13846 * By default, the driver assumes the SLI4 port requires RPI
13847 * header postings. The SLI4_PARAM response will correct this
13850 phba->sli4_hba.rpi_hdrs_in_use = 1;
13852 /* Read the port's SLI4 Config Parameters */
13853 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
13854 sizeof(struct lpfc_sli4_cfg_mhdr));
13855 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13856 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
13857 length, LPFC_SLI4_MBX_EMBED);
13858 if (!phba->sli4_hba.intr_enable)
13859 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13861 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
13862 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
13866 sli4_params = &phba->sli4_hba.pc_sli4_params;
13867 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
13868 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
13869 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
13870 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
13871 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
13872 mbx_sli4_parameters);
13873 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
13874 mbx_sli4_parameters);
13875 if (bf_get(cfg_phwq, mbx_sli4_parameters))
13876 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
13878 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
13879 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
13880 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
13881 mbx_sli4_parameters);
13882 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
13883 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
13884 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
13885 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
13886 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
13887 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
13888 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
13889 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
13890 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
13891 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
13892 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
13893 mbx_sli4_parameters);
13894 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
13895 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
13896 mbx_sli4_parameters);
13897 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
13898 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
13899 sli4_params->mi_cap = bf_get(cfg_mi_ver, mbx_sli4_parameters);
13901 /* Check for Extended Pre-Registered SGL support */
13902 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
13904 /* Check for firmware nvme support */
13905 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13906 bf_get(cfg_xib, mbx_sli4_parameters));
13909 /* Save this to indicate the Firmware supports NVME */
13910 sli4_params->nvme = 1;
13912 /* Firmware NVME support, check driver FC4 NVME support */
13913 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13914 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13915 "6133 Disabling NVME support: "
13916 "FC4 type not supported: x%x\n",
13917 phba->cfg_enable_fc4_type);
13921 /* No firmware NVME support, check driver FC4 NVME support */
13922 sli4_params->nvme = 0;
13923 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13925 "6101 Disabling NVME support: Not "
13926 "supported by firmware (%d %d) x%x\n",
13927 bf_get(cfg_nvme, mbx_sli4_parameters),
13928 bf_get(cfg_xib, mbx_sli4_parameters),
13929 phba->cfg_enable_fc4_type);
13931 phba->nvmet_support = 0;
13932 phba->cfg_nvmet_mrq = 0;
13933 phba->cfg_nvme_seg_cnt = 0;
13935 /* If no FC4 type support, move to just SCSI support */
13936 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13938 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13942 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
13943 * accommodate 512K and 1M IOs in a single nvme buf.
13945 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13946 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
13948 /* Enable embedded Payload BDE if support is indicated */
13949 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13950 phba->cfg_enable_pbde = 1;
13952 phba->cfg_enable_pbde = 0;
13955 * To support Suppress Response feature we must satisfy 3 conditions.
13956 * lpfc_suppress_rsp module parameter must be set (default).
13957 * In SLI4-Parameters Descriptor:
13958 * Extended Inline Buffers (XIB) must be supported.
13959 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13960 * (double negative).
13962 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13963 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
13964 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
13966 phba->cfg_suppress_rsp = 0;
13968 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13969 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13971 /* Make sure that sge_supp_len can be handled by the driver */
13972 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13973 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13975 rc = dma_set_max_seg_size(&phba->pcidev->dev, sli4_params->sge_supp_len);
13976 if (unlikely(rc)) {
13977 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13978 "6400 Can't set dma maximum segment size\n");
13983 * Check whether the adapter supports an embedded copy of the
13984 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13985 * to use this option, 128-byte WQEs must be used.
13987 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13988 phba->fcp_embed_io = 1;
13990 phba->fcp_embed_io = 0;
13992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13993 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
13994 bf_get(cfg_xib, mbx_sli4_parameters),
13995 phba->cfg_enable_pbde,
13996 phba->fcp_embed_io, sli4_params->nvme,
13997 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
13999 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
14000 LPFC_SLI_INTF_IF_TYPE_2) &&
14001 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
14002 LPFC_SLI_INTF_FAMILY_LNCR_A0))
14003 exp_wqcq_pages = false;
14005 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
14006 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
14008 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
14009 phba->enab_exp_wqcq_pages = 1;
14011 phba->enab_exp_wqcq_pages = 0;
14013 * Check if the SLI port supports MDS Diagnostics
14015 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
14016 phba->mds_diags_support = 1;
14018 phba->mds_diags_support = 0;
14021 * Check if the SLI port supports NSLER
14023 if (bf_get(cfg_nsler, mbx_sli4_parameters))
14032 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
14033 * @pdev: pointer to PCI device
14034 * @pid: pointer to PCI device identifier
14036 * This routine is to be called to attach a device with SLI-3 interface spec
14037 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
14038 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14039 * information of the device and driver to see if the driver state that it can
14040 * support this kind of device. If the match is successful, the driver core
14041 * invokes this routine. If this routine determines it can claim the HBA, it
14042 * does all the initialization that it needs to do to handle the HBA properly.
14045 * 0 - driver can claim the device
14046 * negative value - driver can not claim the device
14049 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
14051 struct lpfc_hba *phba;
14052 struct lpfc_vport *vport = NULL;
14053 struct Scsi_Host *shost = NULL;
14055 uint32_t cfg_mode, intr_mode;
14057 /* Allocate memory for HBA structure */
14058 phba = lpfc_hba_alloc(pdev);
14062 /* Perform generic PCI device enabling operation */
14063 error = lpfc_enable_pci_dev(phba);
14065 goto out_free_phba;
14067 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
14068 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
14070 goto out_disable_pci_dev;
14072 /* Set up SLI-3 specific device PCI memory space */
14073 error = lpfc_sli_pci_mem_setup(phba);
14075 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14076 "1402 Failed to set up pci memory space.\n");
14077 goto out_disable_pci_dev;
14080 /* Set up SLI-3 specific device driver resources */
14081 error = lpfc_sli_driver_resource_setup(phba);
14083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14084 "1404 Failed to set up driver resource.\n");
14085 goto out_unset_pci_mem_s3;
14088 /* Initialize and populate the iocb list per host */
14090 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
14092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14093 "1405 Failed to initialize iocb list.\n");
14094 goto out_unset_driver_resource_s3;
14097 /* Set up common device driver resources */
14098 error = lpfc_setup_driver_resource_phase2(phba);
14100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14101 "1406 Failed to set up driver resource.\n");
14102 goto out_free_iocb_list;
14105 /* Get the default values for Model Name and Description */
14106 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14108 /* Create SCSI host to the physical port */
14109 error = lpfc_create_shost(phba);
14111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14112 "1407 Failed to create scsi host.\n");
14113 goto out_unset_driver_resource;
14116 /* Configure sysfs attributes */
14117 vport = phba->pport;
14118 error = lpfc_alloc_sysfs_attr(vport);
14120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14121 "1476 Failed to allocate sysfs attr\n");
14122 goto out_destroy_shost;
14125 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14126 /* Now, trying to enable interrupt and bring up the device */
14127 cfg_mode = phba->cfg_use_msi;
14129 /* Put device to a known state before enabling interrupt */
14130 lpfc_stop_port(phba);
14131 /* Configure and enable interrupt */
14132 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
14133 if (intr_mode == LPFC_INTR_ERROR) {
14134 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14135 "0431 Failed to enable interrupt.\n");
14137 goto out_free_sysfs_attr;
14139 /* SLI-3 HBA setup */
14140 if (lpfc_sli_hba_setup(phba)) {
14141 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14142 "1477 Failed to set up hba\n");
14144 goto out_remove_device;
14147 /* Wait 50ms for the interrupts of previous mailbox commands */
14149 /* Check active interrupts on message signaled interrupts */
14150 if (intr_mode == 0 ||
14151 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
14152 /* Log the current active interrupt mode */
14153 phba->intr_mode = intr_mode;
14154 lpfc_log_intr_mode(phba, intr_mode);
14157 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14158 "0447 Configure interrupt mode (%d) "
14159 "failed active interrupt test.\n",
14161 /* Disable the current interrupt mode */
14162 lpfc_sli_disable_intr(phba);
14163 /* Try next level of interrupt mode */
14164 cfg_mode = --intr_mode;
14168 /* Perform post initialization setup */
14169 lpfc_post_init_setup(phba);
14171 /* Check if there are static vports to be created. */
14172 lpfc_create_static_vport(phba);
14177 lpfc_unset_hba(phba);
14178 out_free_sysfs_attr:
14179 lpfc_free_sysfs_attr(vport);
14181 lpfc_destroy_shost(phba);
14182 out_unset_driver_resource:
14183 lpfc_unset_driver_resource_phase2(phba);
14184 out_free_iocb_list:
14185 lpfc_free_iocb_list(phba);
14186 out_unset_driver_resource_s3:
14187 lpfc_sli_driver_resource_unset(phba);
14188 out_unset_pci_mem_s3:
14189 lpfc_sli_pci_mem_unset(phba);
14190 out_disable_pci_dev:
14191 lpfc_disable_pci_dev(phba);
14193 scsi_host_put(shost);
14195 lpfc_hba_free(phba);
14200 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
14201 * @pdev: pointer to PCI device
14203 * This routine is to be called to disattach a device with SLI-3 interface
14204 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
14205 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14206 * device to be removed from the PCI subsystem properly.
14209 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
14211 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14213 struct lpfc_vport **vports;
14214 struct lpfc_hba *phba = vport->phba;
14217 spin_lock_irq(&phba->hbalock);
14218 vport->load_flag |= FC_UNLOADING;
14219 spin_unlock_irq(&phba->hbalock);
14221 lpfc_free_sysfs_attr(vport);
14223 /* Release all the vports against this physical port */
14224 vports = lpfc_create_vport_work_array(phba);
14225 if (vports != NULL)
14226 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14227 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14229 fc_vport_terminate(vports[i]->fc_vport);
14231 lpfc_destroy_vport_work_array(phba, vports);
14233 /* Remove FC host with the physical port */
14234 fc_remove_host(shost);
14235 scsi_remove_host(shost);
14237 /* Clean up all nodes, mailboxes and IOs. */
14238 lpfc_cleanup(vport);
14241 * Bring down the SLI Layer. This step disable all interrupts,
14242 * clears the rings, discards all mailbox commands, and resets
14246 /* HBA interrupt will be disabled after this call */
14247 lpfc_sli_hba_down(phba);
14248 /* Stop kthread signal shall trigger work_done one more time */
14249 kthread_stop(phba->worker_thread);
14250 /* Final cleanup of txcmplq and reset the HBA */
14251 lpfc_sli_brdrestart(phba);
14253 kfree(phba->vpi_bmask);
14254 kfree(phba->vpi_ids);
14256 lpfc_stop_hba_timers(phba);
14257 spin_lock_irq(&phba->port_list_lock);
14258 list_del_init(&vport->listentry);
14259 spin_unlock_irq(&phba->port_list_lock);
14261 lpfc_debugfs_terminate(vport);
14263 /* Disable SR-IOV if enabled */
14264 if (phba->cfg_sriov_nr_virtfn)
14265 pci_disable_sriov(pdev);
14267 /* Disable interrupt */
14268 lpfc_sli_disable_intr(phba);
14270 scsi_host_put(shost);
14273 * Call scsi_free before mem_free since scsi bufs are released to their
14274 * corresponding pools here.
14276 lpfc_scsi_free(phba);
14277 lpfc_free_iocb_list(phba);
14279 lpfc_mem_free_all(phba);
14281 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
14282 phba->hbqslimp.virt, phba->hbqslimp.phys);
14284 /* Free resources associated with SLI2 interface */
14285 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
14286 phba->slim2p.virt, phba->slim2p.phys);
14288 /* unmap adapter SLIM and Control Registers */
14289 iounmap(phba->ctrl_regs_memmap_p);
14290 iounmap(phba->slim_memmap_p);
14292 lpfc_hba_free(phba);
14294 pci_release_mem_regions(pdev);
14295 pci_disable_device(pdev);
14299 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
14300 * @dev_d: pointer to device
14302 * This routine is to be called from the kernel's PCI subsystem to support
14303 * system Power Management (PM) to device with SLI-3 interface spec. When
14304 * PM invokes this method, it quiesces the device by stopping the driver's
14305 * worker thread for the device, turning off device's interrupt and DMA,
14306 * and bring the device offline. Note that as the driver implements the
14307 * minimum PM requirements to a power-aware driver's PM support for the
14308 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14309 * to the suspend() method call will be treated as SUSPEND and the driver will
14310 * fully reinitialize its device during resume() method call, the driver will
14311 * set device to PCI_D3hot state in PCI config space instead of setting it
14312 * according to the @msg provided by the PM.
14315 * 0 - driver suspended the device
14318 static int __maybe_unused
14319 lpfc_pci_suspend_one_s3(struct device *dev_d)
14321 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14322 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14324 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14325 "0473 PCI device Power Management suspend.\n");
14327 /* Bring down the device */
14328 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14329 lpfc_offline(phba);
14330 kthread_stop(phba->worker_thread);
14332 /* Disable interrupt from device */
14333 lpfc_sli_disable_intr(phba);
14339 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
14340 * @dev_d: pointer to device
14342 * This routine is to be called from the kernel's PCI subsystem to support
14343 * system Power Management (PM) to device with SLI-3 interface spec. When PM
14344 * invokes this method, it restores the device's PCI config space state and
14345 * fully reinitializes the device and brings it online. Note that as the
14346 * driver implements the minimum PM requirements to a power-aware driver's
14347 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
14348 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
14349 * driver will fully reinitialize its device during resume() method call,
14350 * the device will be set to PCI_D0 directly in PCI config space before
14351 * restoring the state.
14354 * 0 - driver suspended the device
14357 static int __maybe_unused
14358 lpfc_pci_resume_one_s3(struct device *dev_d)
14360 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14361 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14362 uint32_t intr_mode;
14365 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14366 "0452 PCI device Power Management resume.\n");
14368 /* Startup the kernel thread for this host adapter. */
14369 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14370 "lpfc_worker_%d", phba->brd_no);
14371 if (IS_ERR(phba->worker_thread)) {
14372 error = PTR_ERR(phba->worker_thread);
14373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14374 "0434 PM resume failed to start worker "
14375 "thread: error=x%x.\n", error);
14379 /* Init cpu_map array */
14380 lpfc_cpu_map_array_init(phba);
14381 /* Init hba_eq_hdl array */
14382 lpfc_hba_eq_hdl_array_init(phba);
14383 /* Configure and enable interrupt */
14384 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14385 if (intr_mode == LPFC_INTR_ERROR) {
14386 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14387 "0430 PM resume Failed to enable interrupt\n");
14390 phba->intr_mode = intr_mode;
14392 /* Restart HBA and bring it online */
14393 lpfc_sli_brdrestart(phba);
14396 /* Log the current active interrupt mode */
14397 lpfc_log_intr_mode(phba, phba->intr_mode);
14403 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
14404 * @phba: pointer to lpfc hba data structure.
14406 * This routine is called to prepare the SLI3 device for PCI slot recover. It
14407 * aborts all the outstanding SCSI I/Os to the pci device.
14410 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
14412 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14413 "2723 PCI channel I/O abort preparing for recovery\n");
14416 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14417 * and let the SCSI mid-layer to retry them to recover.
14419 lpfc_sli_abort_fcp_rings(phba);
14423 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
14424 * @phba: pointer to lpfc hba data structure.
14426 * This routine is called to prepare the SLI3 device for PCI slot reset. It
14427 * disables the device interrupt and pci device, and aborts the internal FCP
14431 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
14433 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14434 "2710 PCI channel disable preparing for reset\n");
14436 /* Block any management I/Os to the device */
14437 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
14439 /* Block all SCSI devices' I/Os on the host */
14440 lpfc_scsi_dev_block(phba);
14442 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
14443 lpfc_sli_flush_io_rings(phba);
14445 /* stop all timers */
14446 lpfc_stop_hba_timers(phba);
14448 /* Disable interrupt and pci device */
14449 lpfc_sli_disable_intr(phba);
14450 pci_disable_device(phba->pcidev);
14454 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
14455 * @phba: pointer to lpfc hba data structure.
14457 * This routine is called to prepare the SLI3 device for PCI slot permanently
14458 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14462 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
14464 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14465 "2711 PCI channel permanent disable for failure\n");
14466 /* Block all SCSI devices' I/Os on the host */
14467 lpfc_scsi_dev_block(phba);
14468 lpfc_sli4_prep_dev_for_reset(phba);
14470 /* stop all timers */
14471 lpfc_stop_hba_timers(phba);
14473 /* Clean up all driver's outstanding SCSI I/Os */
14474 lpfc_sli_flush_io_rings(phba);
14478 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
14479 * @pdev: pointer to PCI device.
14480 * @state: the current PCI connection state.
14482 * This routine is called from the PCI subsystem for I/O error handling to
14483 * device with SLI-3 interface spec. This function is called by the PCI
14484 * subsystem after a PCI bus error affecting this device has been detected.
14485 * When this function is invoked, it will need to stop all the I/Os and
14486 * interrupt(s) to the device. Once that is done, it will return
14487 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
14491 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
14492 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14493 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14495 static pci_ers_result_t
14496 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
14498 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14499 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14502 case pci_channel_io_normal:
14503 /* Non-fatal error, prepare for recovery */
14504 lpfc_sli_prep_dev_for_recover(phba);
14505 return PCI_ERS_RESULT_CAN_RECOVER;
14506 case pci_channel_io_frozen:
14507 /* Fatal error, prepare for slot reset */
14508 lpfc_sli_prep_dev_for_reset(phba);
14509 return PCI_ERS_RESULT_NEED_RESET;
14510 case pci_channel_io_perm_failure:
14511 /* Permanent failure, prepare for device down */
14512 lpfc_sli_prep_dev_for_perm_failure(phba);
14513 return PCI_ERS_RESULT_DISCONNECT;
14515 /* Unknown state, prepare and request slot reset */
14516 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14517 "0472 Unknown PCI error state: x%x\n", state);
14518 lpfc_sli_prep_dev_for_reset(phba);
14519 return PCI_ERS_RESULT_NEED_RESET;
14524 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
14525 * @pdev: pointer to PCI device.
14527 * This routine is called from the PCI subsystem for error handling to
14528 * device with SLI-3 interface spec. This is called after PCI bus has been
14529 * reset to restart the PCI card from scratch, as if from a cold-boot.
14530 * During the PCI subsystem error recovery, after driver returns
14531 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14532 * recovery and then call this routine before calling the .resume method
14533 * to recover the device. This function will initialize the HBA device,
14534 * enable the interrupt, but it will just put the HBA to offline state
14535 * without passing any I/O traffic.
14538 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14539 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14541 static pci_ers_result_t
14542 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
14544 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14545 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14546 struct lpfc_sli *psli = &phba->sli;
14547 uint32_t intr_mode;
14549 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
14550 if (pci_enable_device_mem(pdev)) {
14551 printk(KERN_ERR "lpfc: Cannot re-enable "
14552 "PCI device after reset.\n");
14553 return PCI_ERS_RESULT_DISCONNECT;
14556 pci_restore_state(pdev);
14559 * As the new kernel behavior of pci_restore_state() API call clears
14560 * device saved_state flag, need to save the restored state again.
14562 pci_save_state(pdev);
14564 if (pdev->is_busmaster)
14565 pci_set_master(pdev);
14567 spin_lock_irq(&phba->hbalock);
14568 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
14569 spin_unlock_irq(&phba->hbalock);
14571 /* Configure and enable interrupt */
14572 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
14573 if (intr_mode == LPFC_INTR_ERROR) {
14574 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14575 "0427 Cannot re-enable interrupt after "
14577 return PCI_ERS_RESULT_DISCONNECT;
14579 phba->intr_mode = intr_mode;
14581 /* Take device offline, it will perform cleanup */
14582 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14583 lpfc_offline(phba);
14584 lpfc_sli_brdrestart(phba);
14586 /* Log the current active interrupt mode */
14587 lpfc_log_intr_mode(phba, phba->intr_mode);
14589 return PCI_ERS_RESULT_RECOVERED;
14593 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
14594 * @pdev: pointer to PCI device
14596 * This routine is called from the PCI subsystem for error handling to device
14597 * with SLI-3 interface spec. It is called when kernel error recovery tells
14598 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14599 * error recovery. After this call, traffic can start to flow from this device
14603 lpfc_io_resume_s3(struct pci_dev *pdev)
14605 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14606 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14608 /* Bring device online, it will be no-op for non-fatal error resume */
14613 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
14614 * @phba: pointer to lpfc hba data structure.
14616 * returns the number of ELS/CT IOCBs to reserve
14619 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
14621 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
14623 if (phba->sli_rev == LPFC_SLI_REV4) {
14624 if (max_xri <= 100)
14626 else if (max_xri <= 256)
14628 else if (max_xri <= 512)
14630 else if (max_xri <= 1024)
14632 else if (max_xri <= 1536)
14634 else if (max_xri <= 2048)
14643 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
14644 * @phba: pointer to lpfc hba data structure.
14646 * returns the number of ELS/CT + NVMET IOCBs to reserve
14649 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
14651 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
14653 if (phba->nvmet_support)
14654 max_xri += LPFC_NVMET_BUF_POST;
14660 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
14661 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
14662 const struct firmware *fw)
14667 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
14668 /* Three cases: (1) FW was not supported on the detected adapter.
14669 * (2) FW update has been locked out administratively.
14670 * (3) Some other error during FW update.
14671 * In each case, an unmaskable message is written to the console
14672 * for admin diagnosis.
14674 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
14675 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
14676 magic_number != MAGIC_NUMBER_G6) ||
14677 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
14678 magic_number != MAGIC_NUMBER_G7) ||
14679 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
14680 magic_number != MAGIC_NUMBER_G7P)) {
14681 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14682 "3030 This firmware version is not supported on"
14683 " this HBA model. Device:%x Magic:%x Type:%x "
14684 "ID:%x Size %d %zd\n",
14685 phba->pcidev->device, magic_number, ftype, fid,
14688 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
14689 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14690 "3021 Firmware downloads have been prohibited "
14691 "by a system configuration setting on "
14692 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14694 phba->pcidev->device, magic_number, ftype, fid,
14698 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14699 "3022 FW Download failed. Add Status x%x "
14700 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14702 offset, phba->pcidev->device, magic_number,
14703 ftype, fid, fsize, fw->size);
14710 * lpfc_write_firmware - attempt to write a firmware image to the port
14711 * @fw: pointer to firmware image returned from request_firmware.
14712 * @context: pointer to firmware image returned from request_firmware.
14716 lpfc_write_firmware(const struct firmware *fw, void *context)
14718 struct lpfc_hba *phba = (struct lpfc_hba *)context;
14719 char fwrev[FW_REV_STR_SIZE];
14720 struct lpfc_grp_hdr *image;
14721 struct list_head dma_buffer_list;
14723 struct lpfc_dmabuf *dmabuf, *next;
14724 uint32_t offset = 0, temp_offset = 0;
14725 uint32_t magic_number, ftype, fid, fsize;
14727 /* It can be null in no-wait mode, sanity check */
14732 image = (struct lpfc_grp_hdr *)fw->data;
14734 magic_number = be32_to_cpu(image->magic_number);
14735 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
14736 fid = bf_get_be32(lpfc_grp_hdr_id, image);
14737 fsize = be32_to_cpu(image->size);
14739 INIT_LIST_HEAD(&dma_buffer_list);
14740 lpfc_decode_firmware_rev(phba, fwrev, 1);
14741 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
14742 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14743 "3023 Updating Firmware, Current Version:%s "
14744 "New Version:%s\n",
14745 fwrev, image->revision);
14746 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
14747 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
14753 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14757 if (!dmabuf->virt) {
14762 list_add_tail(&dmabuf->list, &dma_buffer_list);
14764 while (offset < fw->size) {
14765 temp_offset = offset;
14766 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
14767 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
14768 memcpy(dmabuf->virt,
14769 fw->data + temp_offset,
14770 fw->size - temp_offset);
14771 temp_offset = fw->size;
14774 memcpy(dmabuf->virt, fw->data + temp_offset,
14776 temp_offset += SLI4_PAGE_SIZE;
14778 rc = lpfc_wr_object(phba, &dma_buffer_list,
14779 (fw->size - offset), &offset);
14781 rc = lpfc_log_write_firmware_error(phba, offset,
14792 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14793 "3029 Skipped Firmware update, Current "
14794 "Version:%s New Version:%s\n",
14795 fwrev, image->revision);
14798 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
14799 list_del(&dmabuf->list);
14800 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
14801 dmabuf->virt, dmabuf->phys);
14804 release_firmware(fw);
14807 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14808 "3062 Firmware update error, status %d.\n", rc);
14810 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14811 "3024 Firmware update success: size %d.\n", rc);
14815 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
14816 * @phba: pointer to lpfc hba data structure.
14817 * @fw_upgrade: which firmware to update.
14819 * This routine is called to perform Linux generic firmware upgrade on device
14820 * that supports such feature.
14823 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
14825 uint8_t file_name[ELX_MODEL_NAME_SIZE];
14827 const struct firmware *fw;
14829 /* Only supported on SLI4 interface type 2 for now */
14830 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
14831 LPFC_SLI_INTF_IF_TYPE_2)
14834 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
14836 if (fw_upgrade == INT_FW_UPGRADE) {
14837 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
14838 file_name, &phba->pcidev->dev,
14839 GFP_KERNEL, (void *)phba,
14840 lpfc_write_firmware);
14841 } else if (fw_upgrade == RUN_FW_UPGRADE) {
14842 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
14844 lpfc_write_firmware(fw, (void *)phba);
14853 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
14854 * @pdev: pointer to PCI device
14855 * @pid: pointer to PCI device identifier
14857 * This routine is called from the kernel's PCI subsystem to device with
14858 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14859 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14860 * information of the device and driver to see if the driver state that it
14861 * can support this kind of device. If the match is successful, the driver
14862 * core invokes this routine. If this routine determines it can claim the HBA,
14863 * it does all the initialization that it needs to do to handle the HBA
14867 * 0 - driver can claim the device
14868 * negative value - driver can not claim the device
14871 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
14873 struct lpfc_hba *phba;
14874 struct lpfc_vport *vport = NULL;
14875 struct Scsi_Host *shost = NULL;
14877 uint32_t cfg_mode, intr_mode;
14879 /* Allocate memory for HBA structure */
14880 phba = lpfc_hba_alloc(pdev);
14884 INIT_LIST_HEAD(&phba->poll_list);
14886 /* Perform generic PCI device enabling operation */
14887 error = lpfc_enable_pci_dev(phba);
14889 goto out_free_phba;
14891 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
14892 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
14894 goto out_disable_pci_dev;
14896 /* Set up SLI-4 specific device PCI memory space */
14897 error = lpfc_sli4_pci_mem_setup(phba);
14899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14900 "1410 Failed to set up pci memory space.\n");
14901 goto out_disable_pci_dev;
14904 /* Set up SLI-4 Specific device driver resources */
14905 error = lpfc_sli4_driver_resource_setup(phba);
14907 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14908 "1412 Failed to set up driver resource.\n");
14909 goto out_unset_pci_mem_s4;
14912 INIT_LIST_HEAD(&phba->active_rrq_list);
14913 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
14915 /* Set up common device driver resources */
14916 error = lpfc_setup_driver_resource_phase2(phba);
14918 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14919 "1414 Failed to set up driver resource.\n");
14920 goto out_unset_driver_resource_s4;
14923 /* Get the default values for Model Name and Description */
14924 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14926 /* Now, trying to enable interrupt and bring up the device */
14927 cfg_mode = phba->cfg_use_msi;
14929 /* Put device to a known state before enabling interrupt */
14930 phba->pport = NULL;
14931 lpfc_stop_port(phba);
14933 /* Init cpu_map array */
14934 lpfc_cpu_map_array_init(phba);
14936 /* Init hba_eq_hdl array */
14937 lpfc_hba_eq_hdl_array_init(phba);
14939 /* Configure and enable interrupt */
14940 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14941 if (intr_mode == LPFC_INTR_ERROR) {
14942 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14943 "0426 Failed to enable interrupt.\n");
14945 goto out_unset_driver_resource;
14947 /* Default to single EQ for non-MSI-X */
14948 if (phba->intr_type != MSIX) {
14949 phba->cfg_irq_chann = 1;
14950 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14951 if (phba->nvmet_support)
14952 phba->cfg_nvmet_mrq = 1;
14955 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
14957 /* Create SCSI host to the physical port */
14958 error = lpfc_create_shost(phba);
14960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14961 "1415 Failed to create scsi host.\n");
14962 goto out_disable_intr;
14964 vport = phba->pport;
14965 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14967 /* Configure sysfs attributes */
14968 error = lpfc_alloc_sysfs_attr(vport);
14970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14971 "1416 Failed to allocate sysfs attr\n");
14972 goto out_destroy_shost;
14975 /* Set up SLI-4 HBA */
14976 if (lpfc_sli4_hba_setup(phba)) {
14977 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14978 "1421 Failed to set up hba\n");
14980 goto out_free_sysfs_attr;
14983 /* Log the current active interrupt mode */
14984 phba->intr_mode = intr_mode;
14985 lpfc_log_intr_mode(phba, intr_mode);
14987 /* Perform post initialization setup */
14988 lpfc_post_init_setup(phba);
14990 /* NVME support in FW earlier in the driver load corrects the
14991 * FC4 type making a check for nvme_support unnecessary.
14993 if (phba->nvmet_support == 0) {
14994 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14995 /* Create NVME binding with nvme_fc_transport. This
14996 * ensures the vport is initialized. If the localport
14997 * create fails, it should not unload the driver to
14998 * support field issues.
15000 error = lpfc_nvme_create_localport(vport);
15002 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15003 "6004 NVME registration "
15004 "failed, error x%x\n",
15010 /* check for firmware upgrade or downgrade */
15011 if (phba->cfg_request_firmware_upgrade)
15012 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
15014 /* Check if there are static vports to be created. */
15015 lpfc_create_static_vport(phba);
15017 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
15018 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
15022 out_free_sysfs_attr:
15023 lpfc_free_sysfs_attr(vport);
15025 lpfc_destroy_shost(phba);
15027 lpfc_sli4_disable_intr(phba);
15028 out_unset_driver_resource:
15029 lpfc_unset_driver_resource_phase2(phba);
15030 out_unset_driver_resource_s4:
15031 lpfc_sli4_driver_resource_unset(phba);
15032 out_unset_pci_mem_s4:
15033 lpfc_sli4_pci_mem_unset(phba);
15034 out_disable_pci_dev:
15035 lpfc_disable_pci_dev(phba);
15037 scsi_host_put(shost);
15039 lpfc_hba_free(phba);
15044 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
15045 * @pdev: pointer to PCI device
15047 * This routine is called from the kernel's PCI subsystem to device with
15048 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
15049 * removed from PCI bus, it performs all the necessary cleanup for the HBA
15050 * device to be removed from the PCI subsystem properly.
15053 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
15055 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15056 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
15057 struct lpfc_vport **vports;
15058 struct lpfc_hba *phba = vport->phba;
15061 /* Mark the device unloading flag */
15062 spin_lock_irq(&phba->hbalock);
15063 vport->load_flag |= FC_UNLOADING;
15064 spin_unlock_irq(&phba->hbalock);
15066 lpfc_unreg_congestion_buf(phba);
15068 lpfc_free_sysfs_attr(vport);
15070 /* Release all the vports against this physical port */
15071 vports = lpfc_create_vport_work_array(phba);
15072 if (vports != NULL)
15073 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
15074 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
15076 fc_vport_terminate(vports[i]->fc_vport);
15078 lpfc_destroy_vport_work_array(phba, vports);
15080 /* Remove FC host with the physical port */
15081 fc_remove_host(shost);
15082 scsi_remove_host(shost);
15084 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
15085 * localports are destroyed after to cleanup all transport memory.
15087 lpfc_cleanup(vport);
15088 lpfc_nvmet_destroy_targetport(phba);
15089 lpfc_nvme_destroy_localport(vport);
15091 /* De-allocate multi-XRI pools */
15092 if (phba->cfg_xri_rebalancing)
15093 lpfc_destroy_multixri_pools(phba);
15096 * Bring down the SLI Layer. This step disables all interrupts,
15097 * clears the rings, discards all mailbox commands, and resets
15098 * the HBA FCoE function.
15100 lpfc_debugfs_terminate(vport);
15102 lpfc_stop_hba_timers(phba);
15103 spin_lock_irq(&phba->port_list_lock);
15104 list_del_init(&vport->listentry);
15105 spin_unlock_irq(&phba->port_list_lock);
15107 /* Perform scsi free before driver resource_unset since scsi
15108 * buffers are released to their corresponding pools here.
15110 lpfc_io_free(phba);
15111 lpfc_free_iocb_list(phba);
15112 lpfc_sli4_hba_unset(phba);
15114 lpfc_unset_driver_resource_phase2(phba);
15115 lpfc_sli4_driver_resource_unset(phba);
15117 /* Unmap adapter Control and Doorbell registers */
15118 lpfc_sli4_pci_mem_unset(phba);
15120 /* Release PCI resources and disable device's PCI function */
15121 scsi_host_put(shost);
15122 lpfc_disable_pci_dev(phba);
15124 /* Finally, free the driver's device data structure */
15125 lpfc_hba_free(phba);
15131 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
15132 * @dev_d: pointer to device
15134 * This routine is called from the kernel's PCI subsystem to support system
15135 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
15136 * this method, it quiesces the device by stopping the driver's worker
15137 * thread for the device, turning off device's interrupt and DMA, and bring
15138 * the device offline. Note that as the driver implements the minimum PM
15139 * requirements to a power-aware driver's PM support for suspend/resume -- all
15140 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
15141 * method call will be treated as SUSPEND and the driver will fully
15142 * reinitialize its device during resume() method call, the driver will set
15143 * device to PCI_D3hot state in PCI config space instead of setting it
15144 * according to the @msg provided by the PM.
15147 * 0 - driver suspended the device
15150 static int __maybe_unused
15151 lpfc_pci_suspend_one_s4(struct device *dev_d)
15153 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
15154 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15156 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15157 "2843 PCI device Power Management suspend.\n");
15159 /* Bring down the device */
15160 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
15161 lpfc_offline(phba);
15162 kthread_stop(phba->worker_thread);
15164 /* Disable interrupt from device */
15165 lpfc_sli4_disable_intr(phba);
15166 lpfc_sli4_queue_destroy(phba);
15172 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
15173 * @dev_d: pointer to device
15175 * This routine is called from the kernel's PCI subsystem to support system
15176 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
15177 * this method, it restores the device's PCI config space state and fully
15178 * reinitializes the device and brings it online. Note that as the driver
15179 * implements the minimum PM requirements to a power-aware driver's PM for
15180 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
15181 * to the suspend() method call will be treated as SUSPEND and the driver
15182 * will fully reinitialize its device during resume() method call, the device
15183 * will be set to PCI_D0 directly in PCI config space before restoring the
15187 * 0 - driver suspended the device
15190 static int __maybe_unused
15191 lpfc_pci_resume_one_s4(struct device *dev_d)
15193 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
15194 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15195 uint32_t intr_mode;
15198 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15199 "0292 PCI device Power Management resume.\n");
15201 /* Startup the kernel thread for this host adapter. */
15202 phba->worker_thread = kthread_run(lpfc_do_work, phba,
15203 "lpfc_worker_%d", phba->brd_no);
15204 if (IS_ERR(phba->worker_thread)) {
15205 error = PTR_ERR(phba->worker_thread);
15206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15207 "0293 PM resume failed to start worker "
15208 "thread: error=x%x.\n", error);
15212 /* Configure and enable interrupt */
15213 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15214 if (intr_mode == LPFC_INTR_ERROR) {
15215 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15216 "0294 PM resume Failed to enable interrupt\n");
15219 phba->intr_mode = intr_mode;
15221 /* Restart HBA and bring it online */
15222 lpfc_sli_brdrestart(phba);
15225 /* Log the current active interrupt mode */
15226 lpfc_log_intr_mode(phba, phba->intr_mode);
15232 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
15233 * @phba: pointer to lpfc hba data structure.
15235 * This routine is called to prepare the SLI4 device for PCI slot recover. It
15236 * aborts all the outstanding SCSI I/Os to the pci device.
15239 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
15241 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15242 "2828 PCI channel I/O abort preparing for recovery\n");
15244 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
15245 * and let the SCSI mid-layer to retry them to recover.
15247 lpfc_sli_abort_fcp_rings(phba);
15251 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
15252 * @phba: pointer to lpfc hba data structure.
15254 * This routine is called to prepare the SLI4 device for PCI slot reset. It
15255 * disables the device interrupt and pci device, and aborts the internal FCP
15259 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
15261 int offline = pci_channel_offline(phba->pcidev);
15263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15264 "2826 PCI channel disable preparing for reset offline"
15267 /* Block any management I/Os to the device */
15268 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
15271 /* HBA_PCI_ERR was set in io_error_detect */
15272 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
15273 /* Flush all driver's outstanding I/Os as we are to reset */
15274 lpfc_sli_flush_io_rings(phba);
15275 lpfc_offline(phba);
15277 /* stop all timers */
15278 lpfc_stop_hba_timers(phba);
15280 lpfc_sli4_queue_destroy(phba);
15281 /* Disable interrupt and pci device */
15282 lpfc_sli4_disable_intr(phba);
15283 pci_disable_device(phba->pcidev);
15287 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
15288 * @phba: pointer to lpfc hba data structure.
15290 * This routine is called to prepare the SLI4 device for PCI slot permanently
15291 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
15295 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
15297 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15298 "2827 PCI channel permanent disable for failure\n");
15300 /* Block all SCSI devices' I/Os on the host */
15301 lpfc_scsi_dev_block(phba);
15303 /* stop all timers */
15304 lpfc_stop_hba_timers(phba);
15306 /* Clean up all driver's outstanding I/Os */
15307 lpfc_sli_flush_io_rings(phba);
15311 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
15312 * @pdev: pointer to PCI device.
15313 * @state: the current PCI connection state.
15315 * This routine is called from the PCI subsystem for error handling to device
15316 * with SLI-4 interface spec. This function is called by the PCI subsystem
15317 * after a PCI bus error affecting this device has been detected. When this
15318 * function is invoked, it will need to stop all the I/Os and interrupt(s)
15319 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
15320 * for the PCI subsystem to perform proper recovery as desired.
15323 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15324 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15326 static pci_ers_result_t
15327 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
15329 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15330 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15334 case pci_channel_io_normal:
15335 /* Non-fatal error, prepare for recovery */
15336 lpfc_sli4_prep_dev_for_recover(phba);
15337 return PCI_ERS_RESULT_CAN_RECOVER;
15338 case pci_channel_io_frozen:
15339 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15340 /* Fatal error, prepare for slot reset */
15342 lpfc_sli4_prep_dev_for_reset(phba);
15344 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15345 "2832 Already handling PCI error "
15346 "state: x%x\n", state);
15347 return PCI_ERS_RESULT_NEED_RESET;
15348 case pci_channel_io_perm_failure:
15349 set_bit(HBA_PCI_ERR, &phba->bit_flags);
15350 /* Permanent failure, prepare for device down */
15351 lpfc_sli4_prep_dev_for_perm_failure(phba);
15352 return PCI_ERS_RESULT_DISCONNECT;
15354 hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
15356 lpfc_sli4_prep_dev_for_reset(phba);
15357 /* Unknown state, prepare and request slot reset */
15358 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15359 "2825 Unknown PCI error state: x%x\n", state);
15360 lpfc_sli4_prep_dev_for_reset(phba);
15361 return PCI_ERS_RESULT_NEED_RESET;
15366 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
15367 * @pdev: pointer to PCI device.
15369 * This routine is called from the PCI subsystem for error handling to device
15370 * with SLI-4 interface spec. It is called after PCI bus has been reset to
15371 * restart the PCI card from scratch, as if from a cold-boot. During the
15372 * PCI subsystem error recovery, after the driver returns
15373 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
15374 * recovery and then call this routine before calling the .resume method to
15375 * recover the device. This function will initialize the HBA device, enable
15376 * the interrupt, but it will just put the HBA to offline state without
15377 * passing any I/O traffic.
15380 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15381 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15383 static pci_ers_result_t
15384 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
15386 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15387 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15388 struct lpfc_sli *psli = &phba->sli;
15389 uint32_t intr_mode;
15392 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
15393 if (pci_enable_device_mem(pdev)) {
15394 printk(KERN_ERR "lpfc: Cannot re-enable "
15395 "PCI device after reset.\n");
15396 return PCI_ERS_RESULT_DISCONNECT;
15399 pci_restore_state(pdev);
15401 hba_pci_err = test_and_clear_bit(HBA_PCI_ERR, &phba->bit_flags);
15403 dev_info(&pdev->dev,
15404 "hba_pci_err was not set, recovering slot reset.\n");
15406 * As the new kernel behavior of pci_restore_state() API call clears
15407 * device saved_state flag, need to save the restored state again.
15409 pci_save_state(pdev);
15411 if (pdev->is_busmaster)
15412 pci_set_master(pdev);
15414 spin_lock_irq(&phba->hbalock);
15415 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
15416 spin_unlock_irq(&phba->hbalock);
15418 /* Init cpu_map array */
15419 lpfc_cpu_map_array_init(phba);
15420 /* Configure and enable interrupt */
15421 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15422 if (intr_mode == LPFC_INTR_ERROR) {
15423 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15424 "2824 Cannot re-enable interrupt after "
15426 return PCI_ERS_RESULT_DISCONNECT;
15428 phba->intr_mode = intr_mode;
15429 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
15431 /* Log the current active interrupt mode */
15432 lpfc_log_intr_mode(phba, phba->intr_mode);
15434 return PCI_ERS_RESULT_RECOVERED;
15438 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
15439 * @pdev: pointer to PCI device
15441 * This routine is called from the PCI subsystem for error handling to device
15442 * with SLI-4 interface spec. It is called when kernel error recovery tells
15443 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
15444 * error recovery. After this call, traffic can start to flow from this device
15448 lpfc_io_resume_s4(struct pci_dev *pdev)
15450 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15451 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15454 * In case of slot reset, as function reset is performed through
15455 * mailbox command which needs DMA to be enabled, this operation
15456 * has to be moved to the io resume phase. Taking device offline
15457 * will perform the necessary cleanup.
15459 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
15460 /* Perform device reset */
15461 lpfc_sli_brdrestart(phba);
15462 /* Bring the device back online */
15468 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
15469 * @pdev: pointer to PCI device
15470 * @pid: pointer to PCI device identifier
15472 * This routine is to be registered to the kernel's PCI subsystem. When an
15473 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
15474 * at PCI device-specific information of the device and driver to see if the
15475 * driver state that it can support this kind of device. If the match is
15476 * successful, the driver core invokes this routine. This routine dispatches
15477 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
15478 * do all the initialization that it needs to do to handle the HBA device
15482 * 0 - driver can claim the device
15483 * negative value - driver can not claim the device
15486 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
15489 struct lpfc_sli_intf intf;
15491 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
15494 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
15495 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
15496 rc = lpfc_pci_probe_one_s4(pdev, pid);
15498 rc = lpfc_pci_probe_one_s3(pdev, pid);
15504 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
15505 * @pdev: pointer to PCI device
15507 * This routine is to be registered to the kernel's PCI subsystem. When an
15508 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
15509 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
15510 * remove routine, which will perform all the necessary cleanup for the
15511 * device to be removed from the PCI subsystem properly.
15514 lpfc_pci_remove_one(struct pci_dev *pdev)
15516 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15517 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15519 switch (phba->pci_dev_grp) {
15520 case LPFC_PCI_DEV_LP:
15521 lpfc_pci_remove_one_s3(pdev);
15523 case LPFC_PCI_DEV_OC:
15524 lpfc_pci_remove_one_s4(pdev);
15527 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15528 "1424 Invalid PCI device group: 0x%x\n",
15529 phba->pci_dev_grp);
15536 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
15537 * @dev: pointer to device
15539 * This routine is to be registered to the kernel's PCI subsystem to support
15540 * system Power Management (PM). When PM invokes this method, it dispatches
15541 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
15542 * suspend the device.
15545 * 0 - driver suspended the device
15548 static int __maybe_unused
15549 lpfc_pci_suspend_one(struct device *dev)
15551 struct Scsi_Host *shost = dev_get_drvdata(dev);
15552 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15555 switch (phba->pci_dev_grp) {
15556 case LPFC_PCI_DEV_LP:
15557 rc = lpfc_pci_suspend_one_s3(dev);
15559 case LPFC_PCI_DEV_OC:
15560 rc = lpfc_pci_suspend_one_s4(dev);
15563 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15564 "1425 Invalid PCI device group: 0x%x\n",
15565 phba->pci_dev_grp);
15572 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
15573 * @dev: pointer to device
15575 * This routine is to be registered to the kernel's PCI subsystem to support
15576 * system Power Management (PM). When PM invokes this method, it dispatches
15577 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
15578 * resume the device.
15581 * 0 - driver suspended the device
15584 static int __maybe_unused
15585 lpfc_pci_resume_one(struct device *dev)
15587 struct Scsi_Host *shost = dev_get_drvdata(dev);
15588 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15591 switch (phba->pci_dev_grp) {
15592 case LPFC_PCI_DEV_LP:
15593 rc = lpfc_pci_resume_one_s3(dev);
15595 case LPFC_PCI_DEV_OC:
15596 rc = lpfc_pci_resume_one_s4(dev);
15599 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15600 "1426 Invalid PCI device group: 0x%x\n",
15601 phba->pci_dev_grp);
15608 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
15609 * @pdev: pointer to PCI device.
15610 * @state: the current PCI connection state.
15612 * This routine is registered to the PCI subsystem for error handling. This
15613 * function is called by the PCI subsystem after a PCI bus error affecting
15614 * this device has been detected. When this routine is invoked, it dispatches
15615 * the action to the proper SLI-3 or SLI-4 device error detected handling
15616 * routine, which will perform the proper error detected operation.
15619 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15620 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15622 static pci_ers_result_t
15623 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
15625 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15626 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15627 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15629 if (phba->link_state == LPFC_HBA_ERROR &&
15630 phba->hba_flag & HBA_IOQ_FLUSH)
15631 return PCI_ERS_RESULT_NEED_RESET;
15633 switch (phba->pci_dev_grp) {
15634 case LPFC_PCI_DEV_LP:
15635 rc = lpfc_io_error_detected_s3(pdev, state);
15637 case LPFC_PCI_DEV_OC:
15638 rc = lpfc_io_error_detected_s4(pdev, state);
15641 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15642 "1427 Invalid PCI device group: 0x%x\n",
15643 phba->pci_dev_grp);
15650 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
15651 * @pdev: pointer to PCI device.
15653 * This routine is registered to the PCI subsystem for error handling. This
15654 * function is called after PCI bus has been reset to restart the PCI card
15655 * from scratch, as if from a cold-boot. When this routine is invoked, it
15656 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
15657 * routine, which will perform the proper device reset.
15660 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15661 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15663 static pci_ers_result_t
15664 lpfc_io_slot_reset(struct pci_dev *pdev)
15666 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15667 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15668 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15670 switch (phba->pci_dev_grp) {
15671 case LPFC_PCI_DEV_LP:
15672 rc = lpfc_io_slot_reset_s3(pdev);
15674 case LPFC_PCI_DEV_OC:
15675 rc = lpfc_io_slot_reset_s4(pdev);
15678 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15679 "1428 Invalid PCI device group: 0x%x\n",
15680 phba->pci_dev_grp);
15687 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
15688 * @pdev: pointer to PCI device
15690 * This routine is registered to the PCI subsystem for error handling. It
15691 * is called when kernel error recovery tells the lpfc driver that it is
15692 * OK to resume normal PCI operation after PCI bus error recovery. When
15693 * this routine is invoked, it dispatches the action to the proper SLI-3
15694 * or SLI-4 device io_resume routine, which will resume the device operation.
15697 lpfc_io_resume(struct pci_dev *pdev)
15699 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15700 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15702 switch (phba->pci_dev_grp) {
15703 case LPFC_PCI_DEV_LP:
15704 lpfc_io_resume_s3(pdev);
15706 case LPFC_PCI_DEV_OC:
15707 lpfc_io_resume_s4(pdev);
15710 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15711 "1429 Invalid PCI device group: 0x%x\n",
15712 phba->pci_dev_grp);
15719 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
15720 * @phba: pointer to lpfc hba data structure.
15722 * This routine checks to see if OAS is supported for this adapter. If
15723 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
15724 * the enable oas flag is cleared and the pool created for OAS device data
15729 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
15732 if (!phba->cfg_EnableXLane)
15735 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
15739 mempool_destroy(phba->device_data_mem_pool);
15740 phba->device_data_mem_pool = NULL;
15747 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
15748 * @phba: pointer to lpfc hba data structure.
15750 * This routine checks to see if RAS is supported by the adapter. Check the
15751 * function through which RAS support enablement is to be done.
15754 lpfc_sli4_ras_init(struct lpfc_hba *phba)
15756 /* if ASIC_GEN_NUM >= 0xC) */
15757 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
15758 LPFC_SLI_INTF_IF_TYPE_6) ||
15759 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
15760 LPFC_SLI_INTF_FAMILY_G6)) {
15761 phba->ras_fwlog.ras_hwsupport = true;
15762 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
15763 phba->cfg_ras_fwlog_buffsize)
15764 phba->ras_fwlog.ras_enabled = true;
15766 phba->ras_fwlog.ras_enabled = false;
15768 phba->ras_fwlog.ras_hwsupport = false;
15773 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
15775 static const struct pci_error_handlers lpfc_err_handler = {
15776 .error_detected = lpfc_io_error_detected,
15777 .slot_reset = lpfc_io_slot_reset,
15778 .resume = lpfc_io_resume,
15781 static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
15782 lpfc_pci_suspend_one,
15783 lpfc_pci_resume_one);
15785 static struct pci_driver lpfc_driver = {
15786 .name = LPFC_DRIVER_NAME,
15787 .id_table = lpfc_id_table,
15788 .probe = lpfc_pci_probe_one,
15789 .remove = lpfc_pci_remove_one,
15790 .shutdown = lpfc_pci_remove_one,
15791 .driver.pm = &lpfc_pci_pm_ops_one,
15792 .err_handler = &lpfc_err_handler,
15795 static const struct file_operations lpfc_mgmt_fop = {
15796 .owner = THIS_MODULE,
15799 static struct miscdevice lpfc_mgmt_dev = {
15800 .minor = MISC_DYNAMIC_MINOR,
15801 .name = "lpfcmgmt",
15802 .fops = &lpfc_mgmt_fop,
15806 * lpfc_init - lpfc module initialization routine
15808 * This routine is to be invoked when the lpfc module is loaded into the
15809 * kernel. The special kernel macro module_init() is used to indicate the
15810 * role of this routine to the kernel as lpfc module entry point.
15814 * -ENOMEM - FC attach transport failed
15815 * all others - failed
15822 pr_info(LPFC_MODULE_DESC "\n");
15823 pr_info(LPFC_COPYRIGHT "\n");
15825 error = misc_register(&lpfc_mgmt_dev);
15827 printk(KERN_ERR "Could not register lpfcmgmt device, "
15828 "misc_register returned with status %d", error);
15831 lpfc_transport_functions.vport_create = lpfc_vport_create;
15832 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
15833 lpfc_transport_template =
15834 fc_attach_transport(&lpfc_transport_functions);
15835 if (lpfc_transport_template == NULL)
15837 lpfc_vport_transport_template =
15838 fc_attach_transport(&lpfc_vport_transport_functions);
15839 if (lpfc_vport_transport_template == NULL) {
15840 fc_release_transport(lpfc_transport_template);
15843 lpfc_wqe_cmd_template();
15844 lpfc_nvmet_cmd_template();
15846 /* Initialize in case vector mapping is needed */
15847 lpfc_present_cpu = num_present_cpus();
15849 lpfc_pldv_detect = false;
15851 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
15852 "lpfc/sli4:online",
15853 lpfc_cpu_online, lpfc_cpu_offline);
15855 goto cpuhp_failure;
15856 lpfc_cpuhp_state = error;
15858 error = pci_register_driver(&lpfc_driver);
15865 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15867 fc_release_transport(lpfc_transport_template);
15868 fc_release_transport(lpfc_vport_transport_template);
15870 misc_deregister(&lpfc_mgmt_dev);
15875 void lpfc_dmp_dbg(struct lpfc_hba *phba)
15877 unsigned int start_idx;
15878 unsigned int dbg_cnt;
15879 unsigned int temp_idx;
15882 unsigned long rem_nsec;
15884 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
15887 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
15888 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
15891 temp_idx = start_idx;
15892 if (dbg_cnt >= DBG_LOG_SZ) {
15893 dbg_cnt = DBG_LOG_SZ;
15896 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
15897 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
15899 if (start_idx < dbg_cnt)
15900 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
15902 start_idx -= dbg_cnt;
15905 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
15906 start_idx, temp_idx, dbg_cnt);
15908 for (i = 0; i < dbg_cnt; i++) {
15909 if ((start_idx + i) < DBG_LOG_SZ)
15910 temp_idx = (start_idx + i) % DBG_LOG_SZ;
15913 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
15914 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15916 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15918 phba->dbg_log[temp_idx].log);
15921 atomic_set(&phba->dbg_log_cnt, 0);
15922 atomic_set(&phba->dbg_log_dmping, 0);
15926 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15930 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15931 struct va_format vaf;
15934 va_start(args, fmt);
15935 if (unlikely(dbg_dmping)) {
15938 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15942 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15945 atomic_inc(&phba->dbg_log_cnt);
15947 vscnprintf(phba->dbg_log[idx].log,
15948 sizeof(phba->dbg_log[idx].log), fmt, args);
15951 phba->dbg_log[idx].t_ns = local_clock();
15955 * lpfc_exit - lpfc module removal routine
15957 * This routine is invoked when the lpfc module is removed from the kernel.
15958 * The special kernel macro module_exit() is used to indicate the role of
15959 * this routine to the kernel as lpfc module exit point.
15964 misc_deregister(&lpfc_mgmt_dev);
15965 pci_unregister_driver(&lpfc_driver);
15966 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15967 fc_release_transport(lpfc_transport_template);
15968 fc_release_transport(lpfc_vport_transport_template);
15969 idr_destroy(&lpfc_hba_index);
15972 module_init(lpfc_init);
15973 module_exit(lpfc_exit);
15974 MODULE_LICENSE("GPL");
15975 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
15976 MODULE_AUTHOR("Broadcom");
15977 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);