1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/kthread.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/ctype.h>
34 #include <linux/aer.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/msi.h>
40 #include <linux/irq.h>
41 #include <linux/bitops.h>
42 #include <linux/crash_dump.h>
43 #include <linux/cpu.h>
44 #include <linux/cpuhotplug.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_transport_fc.h>
50 #include <scsi/scsi_tcq.h>
51 #include <scsi/fc/fc_fs.h>
56 #include "lpfc_sli4.h"
58 #include "lpfc_disc.h"
60 #include "lpfc_scsi.h"
61 #include "lpfc_nvme.h"
62 #include "lpfc_logmsg.h"
63 #include "lpfc_crtn.h"
64 #include "lpfc_vport.h"
65 #include "lpfc_version.h"
68 static enum cpuhp_state lpfc_cpuhp_state;
69 /* Used when mapping IRQ vectors in a driver centric manner */
70 static uint32_t lpfc_present_cpu;
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 *);
98 static struct scsi_transport_template *lpfc_transport_template = NULL;
99 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
100 static DEFINE_IDR(lpfc_hba_index);
101 #define LPFC_NVMET_BUF_POST 254
102 static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
105 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
106 * @phba: pointer to lpfc hba data structure.
108 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
109 * mailbox command. It retrieves the revision information from the HBA and
110 * collects the Vital Product Data (VPD) about the HBA for preparing the
111 * configuration of the HBA.
115 * -ERESTART - requests the SLI layer to reset the HBA and try again.
116 * Any other value - indicates an error.
119 lpfc_config_port_prep(struct lpfc_hba *phba)
121 lpfc_vpd_t *vp = &phba->vpd;
125 char *lpfc_vpd_data = NULL;
127 static char licensed[56] =
128 "key unlock for use with gnu public licensed code only\0";
129 static int init_key = 1;
131 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
133 phba->link_state = LPFC_HBA_ERROR;
138 phba->link_state = LPFC_INIT_MBX_CMDS;
140 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
142 uint32_t *ptext = (uint32_t *) licensed;
144 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
145 *ptext = cpu_to_be32(*ptext);
149 lpfc_read_nv(phba, pmb);
150 memset((char*)mb->un.varRDnvp.rsvd3, 0,
151 sizeof (mb->un.varRDnvp.rsvd3));
152 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
155 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
157 if (rc != MBX_SUCCESS) {
158 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
159 "0324 Config Port initialization "
160 "error, mbxCmd x%x READ_NVPARM, "
162 mb->mbxCommand, mb->mbxStatus);
163 mempool_free(pmb, phba->mbox_mem_pool);
166 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
168 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
173 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
174 * which was already set in lpfc_get_cfgparam()
176 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
178 /* Setup and issue mailbox READ REV command */
179 lpfc_read_rev(phba, pmb);
180 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
181 if (rc != MBX_SUCCESS) {
182 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
183 "0439 Adapter failed to init, mbxCmd x%x "
184 "READ_REV, mbxStatus x%x\n",
185 mb->mbxCommand, mb->mbxStatus);
186 mempool_free( pmb, phba->mbox_mem_pool);
192 * The value of rr must be 1 since the driver set the cv field to 1.
193 * This setting requires the FW to set all revision fields.
195 if (mb->un.varRdRev.rr == 0) {
197 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
198 "0440 Adapter failed to init, READ_REV has "
199 "missing revision information.\n");
200 mempool_free(pmb, phba->mbox_mem_pool);
204 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
205 mempool_free(pmb, phba->mbox_mem_pool);
209 /* Save information as VPD data */
211 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
212 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
213 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
214 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
215 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
216 vp->rev.biuRev = mb->un.varRdRev.biuRev;
217 vp->rev.smRev = mb->un.varRdRev.smRev;
218 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
219 vp->rev.endecRev = mb->un.varRdRev.endecRev;
220 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
221 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
222 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
223 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
224 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
225 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
227 /* If the sli feature level is less then 9, we must
228 * tear down all RPIs and VPIs on link down if NPIV
231 if (vp->rev.feaLevelHigh < 9)
232 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
234 if (lpfc_is_LC_HBA(phba->pcidev->device))
235 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
236 sizeof (phba->RandomData));
238 /* Get adapter VPD information */
239 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
243 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
244 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
246 if (rc != MBX_SUCCESS) {
247 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
248 "0441 VPD not present on adapter, "
249 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
250 mb->mbxCommand, mb->mbxStatus);
251 mb->un.varDmp.word_cnt = 0;
253 /* dump mem may return a zero when finished or we got a
254 * mailbox error, either way we are done.
256 if (mb->un.varDmp.word_cnt == 0)
259 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
260 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
261 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
262 lpfc_vpd_data + offset,
263 mb->un.varDmp.word_cnt);
264 offset += mb->un.varDmp.word_cnt;
265 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
267 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
269 kfree(lpfc_vpd_data);
271 mempool_free(pmb, phba->mbox_mem_pool);
276 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
277 * @phba: pointer to lpfc hba data structure.
278 * @pmboxq: pointer to the driver internal queue element for mailbox command.
280 * This is the completion handler for driver's configuring asynchronous event
281 * mailbox command to the device. If the mailbox command returns successfully,
282 * it will set internal async event support flag to 1; otherwise, it will
283 * set internal async event support flag to 0.
286 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
288 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
289 phba->temp_sensor_support = 1;
291 phba->temp_sensor_support = 0;
292 mempool_free(pmboxq, phba->mbox_mem_pool);
297 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
298 * @phba: pointer to lpfc hba data structure.
299 * @pmboxq: pointer to the driver internal queue element for mailbox command.
301 * This is the completion handler for dump mailbox command for getting
302 * wake up parameters. When this command complete, the response contain
303 * Option rom version of the HBA. This function translate the version number
304 * into a human readable string and store it in OptionROMVersion.
307 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
310 uint32_t prog_id_word;
312 /* character array used for decoding dist type. */
313 char dist_char[] = "nabx";
315 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
316 mempool_free(pmboxq, phba->mbox_mem_pool);
320 prg = (struct prog_id *) &prog_id_word;
322 /* word 7 contain option rom version */
323 prog_id_word = pmboxq->u.mb.un.varWords[7];
325 /* 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 * cfg_soft_wwnn, cfg_soft_wwpn
343 * @vport: pointer to lpfc vport data structure.
350 lpfc_update_vport_wwn(struct lpfc_vport *vport)
352 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
353 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
355 /* If the soft name exists then update it using the service params */
356 if (vport->phba->cfg_soft_wwnn)
357 u64_to_wwn(vport->phba->cfg_soft_wwnn,
358 vport->fc_sparam.nodeName.u.wwn);
359 if (vport->phba->cfg_soft_wwpn)
360 u64_to_wwn(vport->phba->cfg_soft_wwpn,
361 vport->fc_sparam.portName.u.wwn);
364 * If the name is empty or there exists a soft name
365 * then copy the service params name, otherwise use the fc name
367 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
368 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
369 sizeof(struct lpfc_name));
371 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
372 sizeof(struct lpfc_name));
375 * If the port name has changed, then set the Param changes flag
378 if (vport->fc_portname.u.wwn[0] != 0 &&
379 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name)))
381 vport->vport_flag |= FAWWPN_PARAM_CHG;
383 if (vport->fc_portname.u.wwn[0] == 0 ||
384 vport->phba->cfg_soft_wwpn ||
385 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
386 vport->vport_flag & FAWWPN_SET) {
387 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
388 sizeof(struct lpfc_name));
389 vport->vport_flag &= ~FAWWPN_SET;
390 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
391 vport->vport_flag |= FAWWPN_SET;
394 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
395 sizeof(struct lpfc_name));
399 * lpfc_config_port_post - Perform lpfc initialization after config port
400 * @phba: pointer to lpfc hba data structure.
402 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
403 * command call. It performs all internal resource and state setups on the
404 * port: post IOCB buffers, enable appropriate host interrupt attentions,
405 * ELS ring timers, etc.
409 * Any other value - error.
412 lpfc_config_port_post(struct lpfc_hba *phba)
414 struct lpfc_vport *vport = phba->pport;
415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
418 struct lpfc_dmabuf *mp;
419 struct lpfc_sli *psli = &phba->sli;
420 uint32_t status, timeout;
424 spin_lock_irq(&phba->hbalock);
426 * If the Config port completed correctly the HBA is not
427 * over heated any more.
429 if (phba->over_temp_state == HBA_OVER_TEMP)
430 phba->over_temp_state = HBA_NORMAL_TEMP;
431 spin_unlock_irq(&phba->hbalock);
433 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
435 phba->link_state = LPFC_HBA_ERROR;
440 /* Get login parameters for NID. */
441 rc = lpfc_read_sparam(phba, pmb, 0);
443 mempool_free(pmb, phba->mbox_mem_pool);
448 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
449 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
450 "0448 Adapter failed init, mbxCmd x%x "
451 "READ_SPARM mbxStatus x%x\n",
452 mb->mbxCommand, mb->mbxStatus);
453 phba->link_state = LPFC_HBA_ERROR;
454 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
455 mempool_free(pmb, phba->mbox_mem_pool);
456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
461 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
463 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
464 lpfc_mbuf_free(phba, mp->virt, mp->phys);
467 lpfc_update_vport_wwn(vport);
469 /* Update the fc_host data structures with new wwn. */
470 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
471 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
472 fc_host_max_npiv_vports(shost) = phba->max_vpi;
474 /* If no serial number in VPD data, use low 6 bytes of WWNN */
475 /* This should be consolidated into parse_vpd ? - mr */
476 if (phba->SerialNumber[0] == 0) {
479 outptr = &vport->fc_nodename.u.s.IEEE[0];
480 for (i = 0; i < 12; i++) {
482 j = ((status & 0xf0) >> 4);
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
492 phba->SerialNumber[i] =
493 (char)((uint8_t) 0x30 + (uint8_t) j);
495 phba->SerialNumber[i] =
496 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
500 lpfc_read_config(phba, pmb);
502 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
503 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
504 "0453 Adapter failed to init, mbxCmd x%x "
505 "READ_CONFIG, mbxStatus x%x\n",
506 mb->mbxCommand, mb->mbxStatus);
507 phba->link_state = LPFC_HBA_ERROR;
508 mempool_free( pmb, phba->mbox_mem_pool);
512 /* Check if the port is disabled */
513 lpfc_sli_read_link_ste(phba);
515 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
516 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
517 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
518 "3359 HBA queue depth changed from %d to %d\n",
519 phba->cfg_hba_queue_depth,
520 mb->un.varRdConfig.max_xri);
521 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
524 phba->lmt = mb->un.varRdConfig.lmt;
526 /* Get the default values for Model Name and Description */
527 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
529 phba->link_state = LPFC_LINK_DOWN;
531 /* Only process IOCBs on ELS ring till hba_state is READY */
532 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
533 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
534 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
535 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
537 /* Post receive buffers for desired rings */
538 if (phba->sli_rev != 3)
539 lpfc_post_rcv_buf(phba);
542 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
544 if (phba->intr_type == MSIX) {
545 rc = lpfc_config_msi(phba, pmb);
547 mempool_free(pmb, phba->mbox_mem_pool);
550 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
551 if (rc != MBX_SUCCESS) {
552 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
553 "0352 Config MSI mailbox command "
554 "failed, mbxCmd x%x, mbxStatus x%x\n",
555 pmb->u.mb.mbxCommand,
556 pmb->u.mb.mbxStatus);
557 mempool_free(pmb, phba->mbox_mem_pool);
562 spin_lock_irq(&phba->hbalock);
563 /* Initialize ERATT handling flag */
564 phba->hba_flag &= ~HBA_ERATT_HANDLED;
566 /* Enable appropriate host interrupts */
567 if (lpfc_readl(phba->HCregaddr, &status)) {
568 spin_unlock_irq(&phba->hbalock);
571 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
572 if (psli->num_rings > 0)
573 status |= HC_R0INT_ENA;
574 if (psli->num_rings > 1)
575 status |= HC_R1INT_ENA;
576 if (psli->num_rings > 2)
577 status |= HC_R2INT_ENA;
578 if (psli->num_rings > 3)
579 status |= HC_R3INT_ENA;
581 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
582 (phba->cfg_poll & DISABLE_FCP_RING_INT))
583 status &= ~(HC_R0INT_ENA);
585 writel(status, phba->HCregaddr);
586 readl(phba->HCregaddr); /* flush */
587 spin_unlock_irq(&phba->hbalock);
589 /* Set up ring-0 (ELS) timer */
590 timeout = phba->fc_ratov * 2;
591 mod_timer(&vport->els_tmofunc,
592 jiffies + msecs_to_jiffies(1000 * timeout));
593 /* Set up heart beat (HB) timer */
594 mod_timer(&phba->hb_tmofunc,
595 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
596 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
597 phba->last_completion_time = jiffies;
598 /* Set up error attention (ERATT) polling timer */
599 mod_timer(&phba->eratt_poll,
600 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
602 if (phba->hba_flag & LINK_DISABLED) {
603 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
604 "2598 Adapter Link is disabled.\n");
605 lpfc_down_link(phba, pmb);
606 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
607 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
608 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
609 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
610 "2599 Adapter failed to issue DOWN_LINK"
611 " mbox command rc 0x%x\n", rc);
613 mempool_free(pmb, phba->mbox_mem_pool);
616 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
617 mempool_free(pmb, phba->mbox_mem_pool);
618 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
622 /* MBOX buffer will be freed in mbox compl */
623 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
625 phba->link_state = LPFC_HBA_ERROR;
629 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
630 pmb->mbox_cmpl = lpfc_config_async_cmpl;
631 pmb->vport = phba->pport;
632 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
634 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
635 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
636 "0456 Adapter failed to issue "
637 "ASYNCEVT_ENABLE mbox status x%x\n",
639 mempool_free(pmb, phba->mbox_mem_pool);
642 /* Get Option rom version */
643 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
645 phba->link_state = LPFC_HBA_ERROR;
649 lpfc_dump_wakeup_param(phba, pmb);
650 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
651 pmb->vport = phba->pport;
652 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
654 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
655 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
656 "0435 Adapter failed "
657 "to get Option ROM version status x%x\n", rc);
658 mempool_free(pmb, phba->mbox_mem_pool);
665 * lpfc_hba_init_link - Initialize the FC link
666 * @phba: pointer to lpfc hba data structure.
667 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
669 * This routine will issue the INIT_LINK mailbox command call.
670 * It is available to other drivers through the lpfc_hba data
671 * structure for use as a delayed link up mechanism with the
672 * module parameter lpfc_suppress_link_up.
676 * Any other value - error
679 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
681 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
685 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
686 * @phba: pointer to lpfc hba data structure.
687 * @fc_topology: desired fc topology.
688 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
690 * This routine will issue the INIT_LINK mailbox command call.
691 * It is available to other drivers through the lpfc_hba data
692 * structure for use as a delayed link up mechanism with the
693 * module parameter lpfc_suppress_link_up.
697 * Any other value - error
700 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
703 struct lpfc_vport *vport = phba->pport;
708 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
710 phba->link_state = LPFC_HBA_ERROR;
716 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
717 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
718 !(phba->lmt & LMT_1Gb)) ||
719 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
720 !(phba->lmt & LMT_2Gb)) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
722 !(phba->lmt & LMT_4Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
724 !(phba->lmt & LMT_8Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
726 !(phba->lmt & LMT_10Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
728 !(phba->lmt & LMT_16Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
730 !(phba->lmt & LMT_32Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
732 !(phba->lmt & LMT_64Gb))) {
733 /* Reset link speed to auto */
734 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
735 "1302 Invalid speed for this board:%d "
736 "Reset link speed to auto.\n",
737 phba->cfg_link_speed);
738 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
740 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
741 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
742 if (phba->sli_rev < LPFC_SLI_REV4)
743 lpfc_set_loopback_flag(phba);
744 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
745 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
746 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
747 "0498 Adapter failed to init, mbxCmd x%x "
748 "INIT_LINK, mbxStatus x%x\n",
749 mb->mbxCommand, mb->mbxStatus);
750 if (phba->sli_rev <= LPFC_SLI_REV3) {
751 /* Clear all interrupt enable conditions */
752 writel(0, phba->HCregaddr);
753 readl(phba->HCregaddr); /* flush */
754 /* Clear all pending interrupts */
755 writel(0xffffffff, phba->HAregaddr);
756 readl(phba->HAregaddr); /* flush */
758 phba->link_state = LPFC_HBA_ERROR;
759 if (rc != MBX_BUSY || flag == MBX_POLL)
760 mempool_free(pmb, phba->mbox_mem_pool);
763 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
764 if (flag == MBX_POLL)
765 mempool_free(pmb, phba->mbox_mem_pool);
771 * lpfc_hba_down_link - this routine downs the FC link
772 * @phba: pointer to lpfc hba data structure.
773 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
775 * This routine will issue the DOWN_LINK mailbox command call.
776 * It is available to other drivers through the lpfc_hba data
777 * structure for use to stop the link.
781 * Any other value - error
784 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
789 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
791 phba->link_state = LPFC_HBA_ERROR;
795 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
796 "0491 Adapter Link is disabled.\n");
797 lpfc_down_link(phba, pmb);
798 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
799 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
800 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
801 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
802 "2522 Adapter failed to issue DOWN_LINK"
803 " mbox command rc 0x%x\n", rc);
805 mempool_free(pmb, phba->mbox_mem_pool);
808 if (flag == MBX_POLL)
809 mempool_free(pmb, phba->mbox_mem_pool);
815 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
816 * @phba: pointer to lpfc HBA data structure.
818 * This routine will do LPFC uninitialization before the HBA is reset when
819 * bringing down the SLI Layer.
823 * Any other value - error.
826 lpfc_hba_down_prep(struct lpfc_hba *phba)
828 struct lpfc_vport **vports;
831 if (phba->sli_rev <= LPFC_SLI_REV3) {
832 /* Disable interrupts */
833 writel(0, phba->HCregaddr);
834 readl(phba->HCregaddr); /* flush */
837 if (phba->pport->load_flag & FC_UNLOADING)
838 lpfc_cleanup_discovery_resources(phba->pport);
840 vports = lpfc_create_vport_work_array(phba);
842 for (i = 0; i <= phba->max_vports &&
843 vports[i] != NULL; i++)
844 lpfc_cleanup_discovery_resources(vports[i]);
845 lpfc_destroy_vport_work_array(phba, vports);
851 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
852 * rspiocb which got deferred
854 * @phba: pointer to lpfc HBA data structure.
856 * This routine will cleanup completed slow path events after HBA is reset
857 * when bringing down the SLI Layer.
864 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
866 struct lpfc_iocbq *rspiocbq;
867 struct hbq_dmabuf *dmabuf;
868 struct lpfc_cq_event *cq_event;
870 spin_lock_irq(&phba->hbalock);
871 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
872 spin_unlock_irq(&phba->hbalock);
874 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
875 /* Get the response iocb from the head of work queue */
876 spin_lock_irq(&phba->hbalock);
877 list_remove_head(&phba->sli4_hba.sp_queue_event,
878 cq_event, struct lpfc_cq_event, list);
879 spin_unlock_irq(&phba->hbalock);
881 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
882 case CQE_CODE_COMPL_WQE:
883 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
885 lpfc_sli_release_iocbq(phba, rspiocbq);
887 case CQE_CODE_RECEIVE:
888 case CQE_CODE_RECEIVE_V1:
889 dmabuf = container_of(cq_event, struct hbq_dmabuf,
891 lpfc_in_buf_free(phba, &dmabuf->dbuf);
897 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
898 * @phba: pointer to lpfc HBA data structure.
900 * This routine will cleanup posted ELS buffers after the HBA is reset
901 * when bringing down the SLI Layer.
908 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
910 struct lpfc_sli *psli = &phba->sli;
911 struct lpfc_sli_ring *pring;
912 struct lpfc_dmabuf *mp, *next_mp;
916 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
917 lpfc_sli_hbqbuf_free_all(phba);
919 /* Cleanup preposted buffers on the ELS ring */
920 pring = &psli->sli3_ring[LPFC_ELS_RING];
921 spin_lock_irq(&phba->hbalock);
922 list_splice_init(&pring->postbufq, &buflist);
923 spin_unlock_irq(&phba->hbalock);
926 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
929 lpfc_mbuf_free(phba, mp->virt, mp->phys);
933 spin_lock_irq(&phba->hbalock);
934 pring->postbufq_cnt -= count;
935 spin_unlock_irq(&phba->hbalock);
940 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
941 * @phba: pointer to lpfc HBA data structure.
943 * This routine will cleanup the txcmplq after the HBA is reset when bringing
944 * down the SLI Layer.
950 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
952 struct lpfc_sli *psli = &phba->sli;
953 struct lpfc_queue *qp = NULL;
954 struct lpfc_sli_ring *pring;
955 LIST_HEAD(completions);
957 struct lpfc_iocbq *piocb, *next_iocb;
959 if (phba->sli_rev != LPFC_SLI_REV4) {
960 for (i = 0; i < psli->num_rings; i++) {
961 pring = &psli->sli3_ring[i];
962 spin_lock_irq(&phba->hbalock);
963 /* At this point in time the HBA is either reset or DOA
964 * Nothing should be on txcmplq as it will
967 list_splice_init(&pring->txcmplq, &completions);
968 pring->txcmplq_cnt = 0;
969 spin_unlock_irq(&phba->hbalock);
971 lpfc_sli_abort_iocb_ring(phba, pring);
973 /* Cancel all the IOCBs from the completions list */
974 lpfc_sli_cancel_iocbs(phba, &completions,
975 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
978 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
982 spin_lock_irq(&pring->ring_lock);
983 list_for_each_entry_safe(piocb, next_iocb,
984 &pring->txcmplq, list)
985 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
986 list_splice_init(&pring->txcmplq, &completions);
987 pring->txcmplq_cnt = 0;
988 spin_unlock_irq(&pring->ring_lock);
989 lpfc_sli_abort_iocb_ring(phba, pring);
991 /* Cancel all the IOCBs from the completions list */
992 lpfc_sli_cancel_iocbs(phba, &completions,
993 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
997 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
998 * @phba: pointer to lpfc HBA data structure.
1000 * This routine will do uninitialization after the HBA is reset when bring
1001 * down the SLI Layer.
1005 * Any other value - error.
1008 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1010 lpfc_hba_free_post_buf(phba);
1011 lpfc_hba_clean_txcmplq(phba);
1016 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1017 * @phba: pointer to lpfc HBA data structure.
1019 * This routine will do uninitialization after the HBA is reset when bring
1020 * down the SLI Layer.
1024 * Any other value - error.
1027 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1029 struct lpfc_io_buf *psb, *psb_next;
1030 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
1031 struct lpfc_sli4_hdw_queue *qp;
1033 LIST_HEAD(nvme_aborts);
1034 LIST_HEAD(nvmet_aborts);
1035 struct lpfc_sglq *sglq_entry = NULL;
1039 lpfc_sli_hbqbuf_free_all(phba);
1040 lpfc_hba_clean_txcmplq(phba);
1042 /* At this point in time the HBA is either reset or DOA. Either
1043 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1044 * on the lpfc_els_sgl_list so that it can either be freed if the
1045 * driver is unloading or reposted if the driver is restarting
1049 /* sgl_list_lock required because worker thread uses this
1052 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
1053 list_for_each_entry(sglq_entry,
1054 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1055 sglq_entry->state = SGL_FREED;
1057 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1058 &phba->sli4_hba.lpfc_els_sgl_list);
1061 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
1063 /* abts_xxxx_buf_list_lock required because worker thread uses this
1066 spin_lock_irq(&phba->hbalock);
1068 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1069 qp = &phba->sli4_hba.hdwq[idx];
1071 spin_lock(&qp->abts_io_buf_list_lock);
1072 list_splice_init(&qp->lpfc_abts_io_buf_list,
1075 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1077 psb->status = IOSTAT_SUCCESS;
1080 spin_lock(&qp->io_buf_list_put_lock);
1081 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1082 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1083 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1084 qp->abts_scsi_io_bufs = 0;
1085 qp->abts_nvme_io_bufs = 0;
1086 spin_unlock(&qp->io_buf_list_put_lock);
1087 spin_unlock(&qp->abts_io_buf_list_lock);
1089 spin_unlock_irq(&phba->hbalock);
1091 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1092 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1093 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1095 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
1096 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1097 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
1098 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1102 lpfc_sli4_free_sp_events(phba);
1107 * lpfc_hba_down_post - Wrapper func for hba down post routine
1108 * @phba: pointer to lpfc HBA data structure.
1110 * This routine wraps the actual SLI3 or SLI4 routine for performing
1111 * uninitialization after the HBA is reset when bring down the SLI Layer.
1115 * Any other value - error.
1118 lpfc_hba_down_post(struct lpfc_hba *phba)
1120 return (*phba->lpfc_hba_down_post)(phba);
1124 * lpfc_hb_timeout - The HBA-timer timeout handler
1125 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1127 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1128 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1129 * work-port-events bitmap and the worker thread is notified. This timeout
1130 * event will be used by the worker thread to invoke the actual timeout
1131 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1132 * be performed in the timeout handler and the HBA timeout event bit shall
1133 * be cleared by the worker thread after it has taken the event bitmap out.
1136 lpfc_hb_timeout(struct timer_list *t)
1138 struct lpfc_hba *phba;
1139 uint32_t tmo_posted;
1140 unsigned long iflag;
1142 phba = from_timer(phba, t, hb_tmofunc);
1144 /* Check for heart beat timeout conditions */
1145 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1146 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1148 phba->pport->work_port_events |= WORKER_HB_TMO;
1149 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1151 /* Tell the worker thread there is work to do */
1153 lpfc_worker_wake_up(phba);
1158 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1159 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1161 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1162 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1163 * work-port-events bitmap and the worker thread is notified. This timeout
1164 * event will be used by the worker thread to invoke the actual timeout
1165 * handler routine, lpfc_rrq_handler. Any periodical operations will
1166 * be performed in the timeout handler and the RRQ timeout event bit shall
1167 * be cleared by the worker thread after it has taken the event bitmap out.
1170 lpfc_rrq_timeout(struct timer_list *t)
1172 struct lpfc_hba *phba;
1173 unsigned long iflag;
1175 phba = from_timer(phba, t, rrq_tmr);
1176 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1177 if (!(phba->pport->load_flag & FC_UNLOADING))
1178 phba->hba_flag |= HBA_RRQ_ACTIVE;
1180 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1181 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1183 if (!(phba->pport->load_flag & FC_UNLOADING))
1184 lpfc_worker_wake_up(phba);
1188 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1189 * @phba: pointer to lpfc hba data structure.
1190 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1192 * This is the callback function to the lpfc heart-beat mailbox command.
1193 * If configured, the lpfc driver issues the heart-beat mailbox command to
1194 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1195 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1196 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1197 * heart-beat outstanding state. Once the mailbox command comes back and
1198 * no error conditions detected, the heart-beat mailbox command timer is
1199 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1200 * state is cleared for the next heart-beat. If the timer expired with the
1201 * heart-beat outstanding state set, the driver will put the HBA offline.
1204 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1206 unsigned long drvr_flag;
1208 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1209 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
1210 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1212 /* Check and reset heart-beat timer if necessary */
1213 mempool_free(pmboxq, phba->mbox_mem_pool);
1214 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1215 !(phba->link_state == LPFC_HBA_ERROR) &&
1216 !(phba->pport->load_flag & FC_UNLOADING))
1217 mod_timer(&phba->hb_tmofunc,
1219 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1224 * lpfc_idle_stat_delay_work - idle_stat tracking
1226 * This routine tracks per-cq idle_stat and determines polling decisions.
1232 lpfc_idle_stat_delay_work(struct work_struct *work)
1234 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1236 idle_stat_delay_work);
1237 struct lpfc_queue *cq;
1238 struct lpfc_sli4_hdw_queue *hdwq;
1239 struct lpfc_idle_stat *idle_stat;
1240 u32 i, idle_percent;
1241 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1243 if (phba->pport->load_flag & FC_UNLOADING)
1246 if (phba->link_state == LPFC_HBA_ERROR ||
1247 phba->pport->fc_flag & FC_OFFLINE_MODE ||
1248 phba->cmf_active_mode != LPFC_CFG_OFF)
1251 for_each_present_cpu(i) {
1252 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1255 /* Skip if we've already handled this cq's primary CPU */
1259 idle_stat = &phba->sli4_hba.idle_stat[i];
1261 /* get_cpu_idle_time returns values as running counters. Thus,
1262 * to know the amount for this period, the prior counter values
1263 * need to be subtracted from the current counter values.
1264 * From there, the idle time stat can be calculated as a
1265 * percentage of 100 - the sum of the other consumption times.
1267 wall_idle = get_cpu_idle_time(i, &wall, 1);
1268 diff_idle = wall_idle - idle_stat->prev_idle;
1269 diff_wall = wall - idle_stat->prev_wall;
1271 if (diff_wall <= diff_idle)
1274 busy_time = diff_wall - diff_idle;
1276 idle_percent = div64_u64(100 * busy_time, diff_wall);
1277 idle_percent = 100 - idle_percent;
1279 if (idle_percent < 15)
1280 cq->poll_mode = LPFC_QUEUE_WORK;
1282 cq->poll_mode = LPFC_IRQ_POLL;
1284 idle_stat->prev_idle = wall_idle;
1285 idle_stat->prev_wall = wall;
1289 schedule_delayed_work(&phba->idle_stat_delay_work,
1290 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1294 lpfc_hb_eq_delay_work(struct work_struct *work)
1296 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1297 struct lpfc_hba, eq_delay_work);
1298 struct lpfc_eq_intr_info *eqi, *eqi_new;
1299 struct lpfc_queue *eq, *eq_next;
1300 unsigned char *ena_delay = NULL;
1304 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1307 if (phba->link_state == LPFC_HBA_ERROR ||
1308 phba->pport->fc_flag & FC_OFFLINE_MODE)
1311 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1316 for (i = 0; i < phba->cfg_irq_chann; i++) {
1317 /* Get the EQ corresponding to the IRQ vector */
1318 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1321 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1322 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1323 ena_delay[eq->last_cpu] = 1;
1327 for_each_present_cpu(i) {
1328 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1330 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1331 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1332 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1339 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1340 if (unlikely(eq->last_cpu != i)) {
1341 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1343 list_move_tail(&eq->cpu_list, &eqi_new->list);
1346 if (usdelay != eq->q_mode)
1347 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1355 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1356 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1360 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1361 * @phba: pointer to lpfc hba data structure.
1363 * For each heartbeat, this routine does some heuristic methods to adjust
1364 * XRI distribution. The goal is to fully utilize free XRIs.
1366 static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1371 hwq_count = phba->cfg_hdw_queue;
1372 for (i = 0; i < hwq_count; i++) {
1373 /* Adjust XRIs in private pool */
1374 lpfc_adjust_pvt_pool_count(phba, i);
1376 /* Adjust high watermark */
1377 lpfc_adjust_high_watermark(phba, i);
1379 #ifdef LPFC_MXP_STAT
1380 /* Snapshot pbl, pvt and busy count */
1381 lpfc_snapshot_mxp(phba, i);
1387 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1388 * @phba: pointer to lpfc hba data structure.
1390 * If a HB mbox is not already in progrees, this routine will allocate
1391 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1392 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1395 lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1397 LPFC_MBOXQ_t *pmboxq;
1400 /* Is a Heartbeat mbox already in progress */
1401 if (phba->hba_flag & HBA_HBEAT_INP)
1404 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1408 lpfc_heart_beat(phba, pmboxq);
1409 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1410 pmboxq->vport = phba->pport;
1411 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1413 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1414 mempool_free(pmboxq, phba->mbox_mem_pool);
1417 phba->hba_flag |= HBA_HBEAT_INP;
1423 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1424 * @phba: pointer to lpfc hba data structure.
1426 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1427 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1428 * of the value of lpfc_enable_hba_heartbeat.
1429 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1430 * try to issue a MBX_HEARTBEAT mbox command.
1433 lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1435 if (phba->cfg_enable_hba_heartbeat)
1437 phba->hba_flag |= HBA_HBEAT_TMO;
1441 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1442 * @phba: pointer to lpfc hba data structure.
1444 * This is the actual HBA-timer timeout handler to be invoked by the worker
1445 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1446 * handler performs any periodic operations needed for the device. If such
1447 * periodic event has already been attended to either in the interrupt handler
1448 * or by processing slow-ring or fast-ring events within the HBA-timer
1449 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1450 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1451 * is configured and there is no heart-beat mailbox command outstanding, a
1452 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1453 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1457 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1459 struct lpfc_vport **vports;
1460 struct lpfc_dmabuf *buf_ptr;
1463 struct lpfc_sli *psli = &phba->sli;
1464 LIST_HEAD(completions);
1466 if (phba->cfg_xri_rebalancing) {
1467 /* Multi-XRI pools handler */
1468 lpfc_hb_mxp_handler(phba);
1471 vports = lpfc_create_vport_work_array(phba);
1473 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1474 lpfc_rcv_seq_check_edtov(vports[i]);
1475 lpfc_fdmi_change_check(vports[i]);
1477 lpfc_destroy_vport_work_array(phba, vports);
1479 if ((phba->link_state == LPFC_HBA_ERROR) ||
1480 (phba->pport->load_flag & FC_UNLOADING) ||
1481 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1484 if (phba->elsbuf_cnt &&
1485 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1486 spin_lock_irq(&phba->hbalock);
1487 list_splice_init(&phba->elsbuf, &completions);
1488 phba->elsbuf_cnt = 0;
1489 phba->elsbuf_prev_cnt = 0;
1490 spin_unlock_irq(&phba->hbalock);
1492 while (!list_empty(&completions)) {
1493 list_remove_head(&completions, buf_ptr,
1494 struct lpfc_dmabuf, list);
1495 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1499 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1501 /* If there is no heart beat outstanding, issue a heartbeat command */
1502 if (phba->cfg_enable_hba_heartbeat) {
1503 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1504 spin_lock_irq(&phba->pport->work_port_lock);
1505 if (time_after(phba->last_completion_time +
1506 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1508 spin_unlock_irq(&phba->pport->work_port_lock);
1509 if (phba->hba_flag & HBA_HBEAT_INP)
1510 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1512 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1515 spin_unlock_irq(&phba->pport->work_port_lock);
1517 /* Check if a MBX_HEARTBEAT is already in progress */
1518 if (phba->hba_flag & HBA_HBEAT_INP) {
1520 * If heart beat timeout called with HBA_HBEAT_INP set
1521 * we need to give the hb mailbox cmd a chance to
1524 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1525 "0459 Adapter heartbeat still outstanding: "
1526 "last compl time was %d ms.\n",
1527 jiffies_to_msecs(jiffies
1528 - phba->last_completion_time));
1529 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1531 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1532 (list_empty(&psli->mboxq))) {
1534 retval = lpfc_issue_hb_mbox(phba);
1536 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1539 phba->skipped_hb = 0;
1540 } else if (time_before_eq(phba->last_completion_time,
1541 phba->skipped_hb)) {
1542 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1543 "2857 Last completion time not "
1544 " updated in %d ms\n",
1545 jiffies_to_msecs(jiffies
1546 - phba->last_completion_time));
1548 phba->skipped_hb = jiffies;
1550 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1554 /* Check to see if we want to force a MBX_HEARTBEAT */
1555 if (phba->hba_flag & HBA_HBEAT_TMO) {
1556 retval = lpfc_issue_hb_mbox(phba);
1558 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1560 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1563 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1566 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
1570 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1571 * @phba: pointer to lpfc hba data structure.
1573 * This routine is called to bring the HBA offline when HBA hardware error
1574 * other than Port Error 6 has been detected.
1577 lpfc_offline_eratt(struct lpfc_hba *phba)
1579 struct lpfc_sli *psli = &phba->sli;
1581 spin_lock_irq(&phba->hbalock);
1582 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1583 spin_unlock_irq(&phba->hbalock);
1584 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1587 lpfc_reset_barrier(phba);
1588 spin_lock_irq(&phba->hbalock);
1589 lpfc_sli_brdreset(phba);
1590 spin_unlock_irq(&phba->hbalock);
1591 lpfc_hba_down_post(phba);
1592 lpfc_sli_brdready(phba, HS_MBRDY);
1593 lpfc_unblock_mgmt_io(phba);
1594 phba->link_state = LPFC_HBA_ERROR;
1599 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1600 * @phba: pointer to lpfc hba data structure.
1602 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1603 * other than Port Error 6 has been detected.
1606 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1608 spin_lock_irq(&phba->hbalock);
1609 phba->link_state = LPFC_HBA_ERROR;
1610 spin_unlock_irq(&phba->hbalock);
1612 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1613 lpfc_sli_flush_io_rings(phba);
1615 lpfc_hba_down_post(phba);
1616 lpfc_unblock_mgmt_io(phba);
1620 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1621 * @phba: pointer to lpfc hba data structure.
1623 * This routine is invoked to handle the deferred HBA hardware error
1624 * conditions. This type of error is indicated by HBA by setting ER1
1625 * and another ER bit in the host status register. The driver will
1626 * wait until the ER1 bit clears before handling the error condition.
1629 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1631 uint32_t old_host_status = phba->work_hs;
1632 struct lpfc_sli *psli = &phba->sli;
1634 /* If the pci channel is offline, ignore possible errors,
1635 * since we cannot communicate with the pci card anyway.
1637 if (pci_channel_offline(phba->pcidev)) {
1638 spin_lock_irq(&phba->hbalock);
1639 phba->hba_flag &= ~DEFER_ERATT;
1640 spin_unlock_irq(&phba->hbalock);
1644 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1645 "0479 Deferred Adapter Hardware Error "
1646 "Data: x%x x%x x%x\n",
1647 phba->work_hs, phba->work_status[0],
1648 phba->work_status[1]);
1650 spin_lock_irq(&phba->hbalock);
1651 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1652 spin_unlock_irq(&phba->hbalock);
1656 * Firmware stops when it triggred erratt. That could cause the I/Os
1657 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1658 * SCSI layer retry it after re-establishing link.
1660 lpfc_sli_abort_fcp_rings(phba);
1663 * There was a firmware error. Take the hba offline and then
1664 * attempt to restart it.
1666 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1669 /* Wait for the ER1 bit to clear.*/
1670 while (phba->work_hs & HS_FFER1) {
1672 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1673 phba->work_hs = UNPLUG_ERR ;
1676 /* If driver is unloading let the worker thread continue */
1677 if (phba->pport->load_flag & FC_UNLOADING) {
1684 * This is to ptrotect against a race condition in which
1685 * first write to the host attention register clear the
1686 * host status register.
1688 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1689 phba->work_hs = old_host_status & ~HS_FFER1;
1691 spin_lock_irq(&phba->hbalock);
1692 phba->hba_flag &= ~DEFER_ERATT;
1693 spin_unlock_irq(&phba->hbalock);
1694 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1695 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1699 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1701 struct lpfc_board_event_header board_event;
1702 struct Scsi_Host *shost;
1704 board_event.event_type = FC_REG_BOARD_EVENT;
1705 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1706 shost = lpfc_shost_from_vport(phba->pport);
1707 fc_host_post_vendor_event(shost, fc_get_event_number(),
1708 sizeof(board_event),
1709 (char *) &board_event,
1714 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1715 * @phba: pointer to lpfc hba data structure.
1717 * This routine is invoked to handle the following HBA hardware error
1719 * 1 - HBA error attention interrupt
1720 * 2 - DMA ring index out of range
1721 * 3 - Mailbox command came back as unknown
1724 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1726 struct lpfc_vport *vport = phba->pport;
1727 struct lpfc_sli *psli = &phba->sli;
1728 uint32_t event_data;
1729 unsigned long temperature;
1730 struct temp_event temp_event_data;
1731 struct Scsi_Host *shost;
1733 /* If the pci channel is offline, ignore possible errors,
1734 * since we cannot communicate with the pci card anyway.
1736 if (pci_channel_offline(phba->pcidev)) {
1737 spin_lock_irq(&phba->hbalock);
1738 phba->hba_flag &= ~DEFER_ERATT;
1739 spin_unlock_irq(&phba->hbalock);
1743 /* If resets are disabled then leave the HBA alone and return */
1744 if (!phba->cfg_enable_hba_reset)
1747 /* Send an internal error event to mgmt application */
1748 lpfc_board_errevt_to_mgmt(phba);
1750 if (phba->hba_flag & DEFER_ERATT)
1751 lpfc_handle_deferred_eratt(phba);
1753 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1754 if (phba->work_hs & HS_FFER6)
1755 /* Re-establishing Link */
1756 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1757 "1301 Re-establishing Link "
1758 "Data: x%x x%x x%x\n",
1759 phba->work_hs, phba->work_status[0],
1760 phba->work_status[1]);
1761 if (phba->work_hs & HS_FFER8)
1762 /* Device Zeroization */
1763 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1764 "2861 Host Authentication device "
1765 "zeroization Data:x%x x%x x%x\n",
1766 phba->work_hs, phba->work_status[0],
1767 phba->work_status[1]);
1769 spin_lock_irq(&phba->hbalock);
1770 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1771 spin_unlock_irq(&phba->hbalock);
1774 * Firmware stops when it triggled erratt with HS_FFER6.
1775 * That could cause the I/Os dropped by the firmware.
1776 * Error iocb (I/O) on txcmplq and let the SCSI layer
1777 * retry it after re-establishing link.
1779 lpfc_sli_abort_fcp_rings(phba);
1782 * There was a firmware error. Take the hba offline and then
1783 * attempt to restart it.
1785 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1787 lpfc_sli_brdrestart(phba);
1788 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1789 lpfc_unblock_mgmt_io(phba);
1792 lpfc_unblock_mgmt_io(phba);
1793 } else if (phba->work_hs & HS_CRIT_TEMP) {
1794 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1795 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1796 temp_event_data.event_code = LPFC_CRIT_TEMP;
1797 temp_event_data.data = (uint32_t)temperature;
1799 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1800 "0406 Adapter maximum temperature exceeded "
1801 "(%ld), taking this port offline "
1802 "Data: x%x x%x x%x\n",
1803 temperature, phba->work_hs,
1804 phba->work_status[0], phba->work_status[1]);
1806 shost = lpfc_shost_from_vport(phba->pport);
1807 fc_host_post_vendor_event(shost, fc_get_event_number(),
1808 sizeof(temp_event_data),
1809 (char *) &temp_event_data,
1810 SCSI_NL_VID_TYPE_PCI
1811 | PCI_VENDOR_ID_EMULEX);
1813 spin_lock_irq(&phba->hbalock);
1814 phba->over_temp_state = HBA_OVER_TEMP;
1815 spin_unlock_irq(&phba->hbalock);
1816 lpfc_offline_eratt(phba);
1819 /* The if clause above forces this code path when the status
1820 * failure is a value other than FFER6. Do not call the offline
1821 * twice. This is the adapter hardware error path.
1823 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1824 "0457 Adapter Hardware Error "
1825 "Data: x%x x%x x%x\n",
1827 phba->work_status[0], phba->work_status[1]);
1829 event_data = FC_REG_DUMP_EVENT;
1830 shost = lpfc_shost_from_vport(vport);
1831 fc_host_post_vendor_event(shost, fc_get_event_number(),
1832 sizeof(event_data), (char *) &event_data,
1833 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1835 lpfc_offline_eratt(phba);
1841 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1842 * @phba: pointer to lpfc hba data structure.
1843 * @mbx_action: flag for mailbox shutdown action.
1844 * @en_rn_msg: send reset/port recovery message.
1845 * This routine is invoked to perform an SLI4 port PCI function reset in
1846 * response to port status register polling attention. It waits for port
1847 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1848 * During this process, interrupt vectors are freed and later requested
1849 * for handling possible port resource change.
1852 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1857 LPFC_MBOXQ_t *mboxq;
1859 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1860 LPFC_SLI_INTF_IF_TYPE_2) {
1862 * On error status condition, driver need to wait for port
1863 * ready before performing reset.
1865 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1870 /* need reset: attempt for port recovery */
1872 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1873 "2887 Reset Needed: Attempting Port "
1876 /* If we are no wait, the HBA has been reset and is not
1877 * functional, thus we should clear
1878 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
1880 if (mbx_action == LPFC_MBX_NO_WAIT) {
1881 spin_lock_irq(&phba->hbalock);
1882 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
1883 if (phba->sli.mbox_active) {
1884 mboxq = phba->sli.mbox_active;
1885 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1886 __lpfc_mbox_cmpl_put(phba, mboxq);
1887 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1888 phba->sli.mbox_active = NULL;
1890 spin_unlock_irq(&phba->hbalock);
1893 lpfc_offline_prep(phba, mbx_action);
1894 lpfc_sli_flush_io_rings(phba);
1896 /* release interrupt for possible resource change */
1897 lpfc_sli4_disable_intr(phba);
1898 rc = lpfc_sli_brdrestart(phba);
1900 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1901 "6309 Failed to restart board\n");
1904 /* request and enable interrupt */
1905 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1906 if (intr_mode == LPFC_INTR_ERROR) {
1907 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1908 "3175 Failed to enable interrupt\n");
1911 phba->intr_mode = intr_mode;
1912 rc = lpfc_online(phba);
1914 lpfc_unblock_mgmt_io(phba);
1920 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1921 * @phba: pointer to lpfc hba data structure.
1923 * This routine is invoked to handle the SLI4 HBA hardware error attention
1927 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1929 struct lpfc_vport *vport = phba->pport;
1930 uint32_t event_data;
1931 struct Scsi_Host *shost;
1933 struct lpfc_register portstat_reg = {0};
1934 uint32_t reg_err1, reg_err2;
1935 uint32_t uerrlo_reg, uemasklo_reg;
1936 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1937 bool en_rn_msg = true;
1938 struct temp_event temp_event_data;
1939 struct lpfc_register portsmphr_reg;
1942 /* If the pci channel is offline, ignore possible errors, since
1943 * we cannot communicate with the pci card anyway.
1945 if (pci_channel_offline(phba->pcidev)) {
1946 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1947 "3166 pci channel is offline\n");
1948 lpfc_sli4_offline_eratt(phba);
1952 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1953 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1955 case LPFC_SLI_INTF_IF_TYPE_0:
1956 pci_rd_rc1 = lpfc_readl(
1957 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1959 pci_rd_rc2 = lpfc_readl(
1960 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1962 /* consider PCI bus read error as pci_channel_offline */
1963 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1965 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1966 lpfc_sli4_offline_eratt(phba);
1969 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1970 "7623 Checking UE recoverable");
1972 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1973 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1974 &portsmphr_reg.word0))
1977 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1979 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1980 LPFC_PORT_SEM_UE_RECOVERABLE)
1982 /*Sleep for 1Sec, before checking SEMAPHORE */
1986 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1987 "4827 smphr_port_status x%x : Waited %dSec",
1988 smphr_port_status, i);
1990 /* Recoverable UE, reset the HBA device */
1991 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1992 LPFC_PORT_SEM_UE_RECOVERABLE) {
1993 for (i = 0; i < 20; i++) {
1995 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1996 &portsmphr_reg.word0) &&
1997 (LPFC_POST_STAGE_PORT_READY ==
1998 bf_get(lpfc_port_smphr_port_status,
2000 rc = lpfc_sli4_port_sta_fn_reset(phba,
2001 LPFC_MBX_NO_WAIT, en_rn_msg);
2004 lpfc_printf_log(phba, KERN_ERR,
2006 "4215 Failed to recover UE");
2011 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2012 "7624 Firmware not ready: Failing UE recovery,"
2013 " waited %dSec", i);
2014 phba->link_state = LPFC_HBA_ERROR;
2017 case LPFC_SLI_INTF_IF_TYPE_2:
2018 case LPFC_SLI_INTF_IF_TYPE_6:
2019 pci_rd_rc1 = lpfc_readl(
2020 phba->sli4_hba.u.if_type2.STATUSregaddr,
2021 &portstat_reg.word0);
2022 /* consider PCI bus read error as pci_channel_offline */
2023 if (pci_rd_rc1 == -EIO) {
2024 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2025 "3151 PCI bus read access failure: x%x\n",
2026 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
2027 lpfc_sli4_offline_eratt(phba);
2030 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2031 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
2032 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
2033 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2034 "2889 Port Overtemperature event, "
2035 "taking port offline Data: x%x x%x\n",
2036 reg_err1, reg_err2);
2038 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
2039 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2040 temp_event_data.event_code = LPFC_CRIT_TEMP;
2041 temp_event_data.data = 0xFFFFFFFF;
2043 shost = lpfc_shost_from_vport(phba->pport);
2044 fc_host_post_vendor_event(shost, fc_get_event_number(),
2045 sizeof(temp_event_data),
2046 (char *)&temp_event_data,
2047 SCSI_NL_VID_TYPE_PCI
2048 | PCI_VENDOR_ID_EMULEX);
2050 spin_lock_irq(&phba->hbalock);
2051 phba->over_temp_state = HBA_OVER_TEMP;
2052 spin_unlock_irq(&phba->hbalock);
2053 lpfc_sli4_offline_eratt(phba);
2056 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2057 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
2058 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2059 "3143 Port Down: Firmware Update "
2062 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2063 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2064 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2065 "3144 Port Down: Debug Dump\n");
2066 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2067 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
2068 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2069 "3145 Port Down: Provisioning\n");
2071 /* If resets are disabled then leave the HBA alone and return */
2072 if (!phba->cfg_enable_hba_reset)
2075 /* Check port status register for function reset */
2076 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2079 /* don't report event on forced debug dump */
2080 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2081 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2086 /* fall through for not able to recover */
2087 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2088 "3152 Unrecoverable error\n");
2089 phba->link_state = LPFC_HBA_ERROR;
2091 case LPFC_SLI_INTF_IF_TYPE_1:
2095 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2096 "3123 Report dump event to upper layer\n");
2097 /* Send an internal error event to mgmt application */
2098 lpfc_board_errevt_to_mgmt(phba);
2100 event_data = FC_REG_DUMP_EVENT;
2101 shost = lpfc_shost_from_vport(vport);
2102 fc_host_post_vendor_event(shost, fc_get_event_number(),
2103 sizeof(event_data), (char *) &event_data,
2104 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2108 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2109 * @phba: pointer to lpfc HBA data structure.
2111 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2112 * routine from the API jump table function pointer from the lpfc_hba struct.
2116 * Any other value - error.
2119 lpfc_handle_eratt(struct lpfc_hba *phba)
2121 (*phba->lpfc_handle_eratt)(phba);
2125 * lpfc_handle_latt - The HBA link event handler
2126 * @phba: pointer to lpfc hba data structure.
2128 * This routine is invoked from the worker thread to handle a HBA host
2129 * attention link event. SLI3 only.
2132 lpfc_handle_latt(struct lpfc_hba *phba)
2134 struct lpfc_vport *vport = phba->pport;
2135 struct lpfc_sli *psli = &phba->sli;
2137 volatile uint32_t control;
2138 struct lpfc_dmabuf *mp;
2141 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2144 goto lpfc_handle_latt_err_exit;
2147 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2150 goto lpfc_handle_latt_free_pmb;
2153 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2156 goto lpfc_handle_latt_free_mp;
2159 /* Cleanup any outstanding ELS commands */
2160 lpfc_els_flush_all_cmd(phba);
2162 psli->slistat.link_event++;
2163 lpfc_read_topology(phba, pmb, mp);
2164 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2166 /* Block ELS IOCBs until we have processed this mbox command */
2167 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2168 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2169 if (rc == MBX_NOT_FINISHED) {
2171 goto lpfc_handle_latt_free_mbuf;
2174 /* Clear Link Attention in HA REG */
2175 spin_lock_irq(&phba->hbalock);
2176 writel(HA_LATT, phba->HAregaddr);
2177 readl(phba->HAregaddr); /* flush */
2178 spin_unlock_irq(&phba->hbalock);
2182 lpfc_handle_latt_free_mbuf:
2183 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2184 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2185 lpfc_handle_latt_free_mp:
2187 lpfc_handle_latt_free_pmb:
2188 mempool_free(pmb, phba->mbox_mem_pool);
2189 lpfc_handle_latt_err_exit:
2190 /* Enable Link attention interrupts */
2191 spin_lock_irq(&phba->hbalock);
2192 psli->sli_flag |= LPFC_PROCESS_LA;
2193 control = readl(phba->HCregaddr);
2194 control |= HC_LAINT_ENA;
2195 writel(control, phba->HCregaddr);
2196 readl(phba->HCregaddr); /* flush */
2198 /* Clear Link Attention in HA REG */
2199 writel(HA_LATT, phba->HAregaddr);
2200 readl(phba->HAregaddr); /* flush */
2201 spin_unlock_irq(&phba->hbalock);
2202 lpfc_linkdown(phba);
2203 phba->link_state = LPFC_HBA_ERROR;
2205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2206 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2212 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2213 * @phba: pointer to lpfc hba data structure.
2214 * @vpd: pointer to the vital product data.
2215 * @len: length of the vital product data in bytes.
2217 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2218 * an array of characters. In this routine, the ModelName, ProgramType, and
2219 * ModelDesc, etc. fields of the phba data structure will be populated.
2222 * 0 - pointer to the VPD passed in is NULL
2226 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2228 uint8_t lenlo, lenhi;
2238 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2239 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2240 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2242 while (!finished && (index < (len - 4))) {
2243 switch (vpd[index]) {
2251 i = ((((unsigned short)lenhi) << 8) + lenlo);
2260 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2261 if (Length > len - index)
2262 Length = len - index;
2263 while (Length > 0) {
2264 /* Look for Serial Number */
2265 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2272 phba->SerialNumber[j++] = vpd[index++];
2276 phba->SerialNumber[j] = 0;
2279 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2280 phba->vpd_flag |= VPD_MODEL_DESC;
2287 phba->ModelDesc[j++] = vpd[index++];
2291 phba->ModelDesc[j] = 0;
2294 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2295 phba->vpd_flag |= VPD_MODEL_NAME;
2302 phba->ModelName[j++] = vpd[index++];
2306 phba->ModelName[j] = 0;
2309 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2310 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2317 phba->ProgramType[j++] = vpd[index++];
2321 phba->ProgramType[j] = 0;
2324 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2325 phba->vpd_flag |= VPD_PORT;
2332 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2333 (phba->sli4_hba.pport_name_sta ==
2334 LPFC_SLI4_PPNAME_GET)) {
2338 phba->Port[j++] = vpd[index++];
2342 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2343 (phba->sli4_hba.pport_name_sta ==
2344 LPFC_SLI4_PPNAME_NON))
2371 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2372 * @phba: pointer to lpfc hba data structure.
2373 * @mdp: pointer to the data structure to hold the derived model name.
2374 * @descp: pointer to the data structure to hold the derived description.
2376 * This routine retrieves HBA's description based on its registered PCI device
2377 * ID. The @descp passed into this function points to an array of 256 chars. It
2378 * shall be returned with the model name, maximum speed, and the host bus type.
2379 * The @mdp passed into this function points to an array of 80 chars. When the
2380 * function returns, the @mdp will be filled with the model name.
2383 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2386 uint16_t dev_id = phba->pcidev->device;
2389 int oneConnect = 0; /* default is not a oneConnect */
2394 } m = {"<Unknown>", "", ""};
2396 if (mdp && mdp[0] != '\0'
2397 && descp && descp[0] != '\0')
2400 if (phba->lmt & LMT_64Gb)
2402 else if (phba->lmt & LMT_32Gb)
2404 else if (phba->lmt & LMT_16Gb)
2406 else if (phba->lmt & LMT_10Gb)
2408 else if (phba->lmt & LMT_8Gb)
2410 else if (phba->lmt & LMT_4Gb)
2412 else if (phba->lmt & LMT_2Gb)
2414 else if (phba->lmt & LMT_1Gb)
2422 case PCI_DEVICE_ID_FIREFLY:
2423 m = (typeof(m)){"LP6000", "PCI",
2424 "Obsolete, Unsupported Fibre Channel Adapter"};
2426 case PCI_DEVICE_ID_SUPERFLY:
2427 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2428 m = (typeof(m)){"LP7000", "PCI", ""};
2430 m = (typeof(m)){"LP7000E", "PCI", ""};
2431 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2433 case PCI_DEVICE_ID_DRAGONFLY:
2434 m = (typeof(m)){"LP8000", "PCI",
2435 "Obsolete, Unsupported Fibre Channel Adapter"};
2437 case PCI_DEVICE_ID_CENTAUR:
2438 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2439 m = (typeof(m)){"LP9002", "PCI", ""};
2441 m = (typeof(m)){"LP9000", "PCI", ""};
2442 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2444 case PCI_DEVICE_ID_RFLY:
2445 m = (typeof(m)){"LP952", "PCI",
2446 "Obsolete, Unsupported Fibre Channel Adapter"};
2448 case PCI_DEVICE_ID_PEGASUS:
2449 m = (typeof(m)){"LP9802", "PCI-X",
2450 "Obsolete, Unsupported Fibre Channel Adapter"};
2452 case PCI_DEVICE_ID_THOR:
2453 m = (typeof(m)){"LP10000", "PCI-X",
2454 "Obsolete, Unsupported Fibre Channel Adapter"};
2456 case PCI_DEVICE_ID_VIPER:
2457 m = (typeof(m)){"LPX1000", "PCI-X",
2458 "Obsolete, Unsupported Fibre Channel Adapter"};
2460 case PCI_DEVICE_ID_PFLY:
2461 m = (typeof(m)){"LP982", "PCI-X",
2462 "Obsolete, Unsupported Fibre Channel Adapter"};
2464 case PCI_DEVICE_ID_TFLY:
2465 m = (typeof(m)){"LP1050", "PCI-X",
2466 "Obsolete, Unsupported Fibre Channel Adapter"};
2468 case PCI_DEVICE_ID_HELIOS:
2469 m = (typeof(m)){"LP11000", "PCI-X2",
2470 "Obsolete, Unsupported Fibre Channel Adapter"};
2472 case PCI_DEVICE_ID_HELIOS_SCSP:
2473 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2474 "Obsolete, Unsupported Fibre Channel Adapter"};
2476 case PCI_DEVICE_ID_HELIOS_DCSP:
2477 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2478 "Obsolete, Unsupported Fibre Channel Adapter"};
2480 case PCI_DEVICE_ID_NEPTUNE:
2481 m = (typeof(m)){"LPe1000", "PCIe",
2482 "Obsolete, Unsupported Fibre Channel Adapter"};
2484 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2485 m = (typeof(m)){"LPe1000-SP", "PCIe",
2486 "Obsolete, Unsupported Fibre Channel Adapter"};
2488 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2489 m = (typeof(m)){"LPe1002-SP", "PCIe",
2490 "Obsolete, Unsupported Fibre Channel Adapter"};
2492 case PCI_DEVICE_ID_BMID:
2493 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2495 case PCI_DEVICE_ID_BSMB:
2496 m = (typeof(m)){"LP111", "PCI-X2",
2497 "Obsolete, Unsupported Fibre Channel Adapter"};
2499 case PCI_DEVICE_ID_ZEPHYR:
2500 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2502 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2503 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2505 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2506 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2509 case PCI_DEVICE_ID_ZMID:
2510 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2512 case PCI_DEVICE_ID_ZSMB:
2513 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2515 case PCI_DEVICE_ID_LP101:
2516 m = (typeof(m)){"LP101", "PCI-X",
2517 "Obsolete, Unsupported Fibre Channel Adapter"};
2519 case PCI_DEVICE_ID_LP10000S:
2520 m = (typeof(m)){"LP10000-S", "PCI",
2521 "Obsolete, Unsupported Fibre Channel Adapter"};
2523 case PCI_DEVICE_ID_LP11000S:
2524 m = (typeof(m)){"LP11000-S", "PCI-X2",
2525 "Obsolete, Unsupported Fibre Channel Adapter"};
2527 case PCI_DEVICE_ID_LPE11000S:
2528 m = (typeof(m)){"LPe11000-S", "PCIe",
2529 "Obsolete, Unsupported Fibre Channel Adapter"};
2531 case PCI_DEVICE_ID_SAT:
2532 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2534 case PCI_DEVICE_ID_SAT_MID:
2535 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2537 case PCI_DEVICE_ID_SAT_SMB:
2538 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2540 case PCI_DEVICE_ID_SAT_DCSP:
2541 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2543 case PCI_DEVICE_ID_SAT_SCSP:
2544 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2546 case PCI_DEVICE_ID_SAT_S:
2547 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2549 case PCI_DEVICE_ID_HORNET:
2550 m = (typeof(m)){"LP21000", "PCIe",
2551 "Obsolete, Unsupported FCoE Adapter"};
2554 case PCI_DEVICE_ID_PROTEUS_VF:
2555 m = (typeof(m)){"LPev12000", "PCIe IOV",
2556 "Obsolete, Unsupported Fibre Channel Adapter"};
2558 case PCI_DEVICE_ID_PROTEUS_PF:
2559 m = (typeof(m)){"LPev12000", "PCIe IOV",
2560 "Obsolete, Unsupported Fibre Channel Adapter"};
2562 case PCI_DEVICE_ID_PROTEUS_S:
2563 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2564 "Obsolete, Unsupported Fibre Channel Adapter"};
2566 case PCI_DEVICE_ID_TIGERSHARK:
2568 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2570 case PCI_DEVICE_ID_TOMCAT:
2572 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2574 case PCI_DEVICE_ID_FALCON:
2575 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2576 "EmulexSecure Fibre"};
2578 case PCI_DEVICE_ID_BALIUS:
2579 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2580 "Obsolete, Unsupported Fibre Channel Adapter"};
2582 case PCI_DEVICE_ID_LANCER_FC:
2583 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2585 case PCI_DEVICE_ID_LANCER_FC_VF:
2586 m = (typeof(m)){"LPe16000", "PCIe",
2587 "Obsolete, Unsupported Fibre Channel Adapter"};
2589 case PCI_DEVICE_ID_LANCER_FCOE:
2591 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2593 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2595 m = (typeof(m)){"OCe15100", "PCIe",
2596 "Obsolete, Unsupported FCoE"};
2598 case PCI_DEVICE_ID_LANCER_G6_FC:
2599 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2601 case PCI_DEVICE_ID_LANCER_G7_FC:
2602 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2604 case PCI_DEVICE_ID_LANCER_G7P_FC:
2605 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2607 case PCI_DEVICE_ID_SKYHAWK:
2608 case PCI_DEVICE_ID_SKYHAWK_VF:
2610 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2613 m = (typeof(m)){"Unknown", "", ""};
2617 if (mdp && mdp[0] == '\0')
2618 snprintf(mdp, 79,"%s", m.name);
2620 * oneConnect hba requires special processing, they are all initiators
2621 * and we put the port number on the end
2623 if (descp && descp[0] == '\0') {
2625 snprintf(descp, 255,
2626 "Emulex OneConnect %s, %s Initiator %s",
2629 else if (max_speed == 0)
2630 snprintf(descp, 255,
2632 m.name, m.bus, m.function);
2634 snprintf(descp, 255,
2635 "Emulex %s %d%s %s %s",
2636 m.name, max_speed, (GE) ? "GE" : "Gb",
2642 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2643 * @phba: pointer to lpfc hba data structure.
2644 * @pring: pointer to a IOCB ring.
2645 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2647 * This routine posts a given number of IOCBs with the associated DMA buffer
2648 * descriptors specified by the cnt argument to the given IOCB ring.
2651 * The number of IOCBs NOT able to be posted to the IOCB ring.
2654 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2657 struct lpfc_iocbq *iocb;
2658 struct lpfc_dmabuf *mp1, *mp2;
2660 cnt += pring->missbufcnt;
2662 /* While there are buffers to post */
2664 /* Allocate buffer for command iocb */
2665 iocb = lpfc_sli_get_iocbq(phba);
2667 pring->missbufcnt = cnt;
2672 /* 2 buffers can be posted per command */
2673 /* Allocate buffer to post */
2674 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2676 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2677 if (!mp1 || !mp1->virt) {
2679 lpfc_sli_release_iocbq(phba, iocb);
2680 pring->missbufcnt = cnt;
2684 INIT_LIST_HEAD(&mp1->list);
2685 /* Allocate buffer to post */
2687 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2689 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2691 if (!mp2 || !mp2->virt) {
2693 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2695 lpfc_sli_release_iocbq(phba, iocb);
2696 pring->missbufcnt = cnt;
2700 INIT_LIST_HEAD(&mp2->list);
2705 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2706 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2707 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2708 icmd->ulpBdeCount = 1;
2711 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2712 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2713 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2715 icmd->ulpBdeCount = 2;
2718 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2721 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2723 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2727 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2731 lpfc_sli_release_iocbq(phba, iocb);
2732 pring->missbufcnt = cnt;
2735 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2737 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2739 pring->missbufcnt = 0;
2744 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2745 * @phba: pointer to lpfc hba data structure.
2747 * This routine posts initial receive IOCB buffers to the ELS ring. The
2748 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2749 * set to 64 IOCBs. SLI3 only.
2752 * 0 - success (currently always success)
2755 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2757 struct lpfc_sli *psli = &phba->sli;
2759 /* Ring 0, ELS / CT buffers */
2760 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2761 /* Ring 2 - FCP no buffers needed */
2766 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2769 * lpfc_sha_init - Set up initial array of hash table entries
2770 * @HashResultPointer: pointer to an array as hash table.
2772 * This routine sets up the initial values to the array of hash table entries
2776 lpfc_sha_init(uint32_t * HashResultPointer)
2778 HashResultPointer[0] = 0x67452301;
2779 HashResultPointer[1] = 0xEFCDAB89;
2780 HashResultPointer[2] = 0x98BADCFE;
2781 HashResultPointer[3] = 0x10325476;
2782 HashResultPointer[4] = 0xC3D2E1F0;
2786 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2787 * @HashResultPointer: pointer to an initial/result hash table.
2788 * @HashWorkingPointer: pointer to an working hash table.
2790 * This routine iterates an initial hash table pointed by @HashResultPointer
2791 * with the values from the working hash table pointeed by @HashWorkingPointer.
2792 * The results are putting back to the initial hash table, returned through
2793 * the @HashResultPointer as the result hash table.
2796 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2800 uint32_t A, B, C, D, E;
2803 HashWorkingPointer[t] =
2805 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2807 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2808 } while (++t <= 79);
2810 A = HashResultPointer[0];
2811 B = HashResultPointer[1];
2812 C = HashResultPointer[2];
2813 D = HashResultPointer[3];
2814 E = HashResultPointer[4];
2818 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2819 } else if (t < 40) {
2820 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2821 } else if (t < 60) {
2822 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2824 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2826 TEMP += S(5, A) + E + HashWorkingPointer[t];
2832 } while (++t <= 79);
2834 HashResultPointer[0] += A;
2835 HashResultPointer[1] += B;
2836 HashResultPointer[2] += C;
2837 HashResultPointer[3] += D;
2838 HashResultPointer[4] += E;
2843 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2844 * @RandomChallenge: pointer to the entry of host challenge random number array.
2845 * @HashWorking: pointer to the entry of the working hash array.
2847 * This routine calculates the working hash array referred by @HashWorking
2848 * from the challenge random numbers associated with the host, referred by
2849 * @RandomChallenge. The result is put into the entry of the working hash
2850 * array and returned by reference through @HashWorking.
2853 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2855 *HashWorking = (*RandomChallenge ^ *HashWorking);
2859 * lpfc_hba_init - Perform special handling for LC HBA initialization
2860 * @phba: pointer to lpfc hba data structure.
2861 * @hbainit: pointer to an array of unsigned 32-bit integers.
2863 * This routine performs the special handling for LC HBA initialization.
2866 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2869 uint32_t *HashWorking;
2870 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2872 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2876 HashWorking[0] = HashWorking[78] = *pwwnn++;
2877 HashWorking[1] = HashWorking[79] = *pwwnn;
2879 for (t = 0; t < 7; t++)
2880 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2882 lpfc_sha_init(hbainit);
2883 lpfc_sha_iterate(hbainit, HashWorking);
2888 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2889 * @vport: pointer to a virtual N_Port data structure.
2891 * This routine performs the necessary cleanups before deleting the @vport.
2892 * It invokes the discovery state machine to perform necessary state
2893 * transitions and to release the ndlps associated with the @vport. Note,
2894 * the physical port is treated as @vport 0.
2897 lpfc_cleanup(struct lpfc_vport *vport)
2899 struct lpfc_hba *phba = vport->phba;
2900 struct lpfc_nodelist *ndlp, *next_ndlp;
2903 if (phba->link_state > LPFC_LINK_DOWN)
2904 lpfc_port_link_failure(vport);
2906 /* Clean up VMID resources */
2907 if (lpfc_is_vmid_enabled(phba))
2908 lpfc_vmid_vport_cleanup(vport);
2910 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2911 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2912 ndlp->nlp_DID == Fabric_DID) {
2913 /* Just free up ndlp with Fabric_DID for vports */
2918 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
2919 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2924 /* Fabric Ports not in UNMAPPED state are cleaned up in the
2927 if (ndlp->nlp_type & NLP_FABRIC &&
2928 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
2929 lpfc_disc_state_machine(vport, ndlp, NULL,
2930 NLP_EVT_DEVICE_RECOVERY);
2932 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
2933 lpfc_disc_state_machine(vport, ndlp, NULL,
2937 /* At this point, ALL ndlp's should be gone
2938 * because of the previous NLP_EVT_DEVICE_RM.
2939 * Lets wait for this to happen, if needed.
2941 while (!list_empty(&vport->fc_nodes)) {
2943 lpfc_printf_vlog(vport, KERN_ERR,
2945 "0233 Nodelist not empty\n");
2946 list_for_each_entry_safe(ndlp, next_ndlp,
2947 &vport->fc_nodes, nlp_listp) {
2948 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2950 "0282 did:x%x ndlp:x%px "
2951 "refcnt:%d xflags x%x nflag x%x\n",
2952 ndlp->nlp_DID, (void *)ndlp,
2953 kref_read(&ndlp->kref),
2954 ndlp->fc4_xpt_flags,
2960 /* Wait for any activity on ndlps to settle */
2963 lpfc_cleanup_vports_rrqs(vport, NULL);
2967 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2968 * @vport: pointer to a virtual N_Port data structure.
2970 * This routine stops all the timers associated with a @vport. This function
2971 * is invoked before disabling or deleting a @vport. Note that the physical
2972 * port is treated as @vport 0.
2975 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2977 del_timer_sync(&vport->els_tmofunc);
2978 del_timer_sync(&vport->delayed_disc_tmo);
2979 lpfc_can_disctmo(vport);
2984 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2985 * @phba: pointer to lpfc hba data structure.
2987 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2988 * caller of this routine should already hold the host lock.
2991 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2993 /* Clear pending FCF rediscovery wait flag */
2994 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2996 /* Now, try to stop the timer */
2997 del_timer(&phba->fcf.redisc_wait);
3001 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3002 * @phba: pointer to lpfc hba data structure.
3004 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3005 * checks whether the FCF rediscovery wait timer is pending with the host
3006 * lock held before proceeding with disabling the timer and clearing the
3007 * wait timer pendig flag.
3010 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3012 spin_lock_irq(&phba->hbalock);
3013 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3014 /* FCF rediscovery timer already fired or stopped */
3015 spin_unlock_irq(&phba->hbalock);
3018 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3019 /* Clear failover in progress flags */
3020 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
3021 spin_unlock_irq(&phba->hbalock);
3025 * lpfc_cmf_stop - Stop CMF processing
3026 * @phba: pointer to lpfc hba data structure.
3028 * This is called when the link goes down or if CMF mode is turned OFF.
3029 * It is also called when going offline or unloaded just before the
3030 * congestion info buffer is unregistered.
3033 lpfc_cmf_stop(struct lpfc_hba *phba)
3036 struct lpfc_cgn_stat *cgs;
3038 /* We only do something if CMF is enabled */
3039 if (!phba->sli4_hba.pc_sli4_params.cmf)
3042 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3043 "6221 Stop CMF / Cancel Timer\n");
3045 /* Cancel the CMF timer */
3046 hrtimer_cancel(&phba->cmf_timer);
3048 /* Zero CMF counters */
3049 atomic_set(&phba->cmf_busy, 0);
3050 for_each_present_cpu(cpu) {
3051 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3052 atomic64_set(&cgs->total_bytes, 0);
3053 atomic64_set(&cgs->rcv_bytes, 0);
3054 atomic_set(&cgs->rx_io_cnt, 0);
3055 atomic64_set(&cgs->rx_latency, 0);
3057 atomic_set(&phba->cmf_bw_wait, 0);
3059 /* Resume any blocked IO - Queue unblock on workqueue */
3060 queue_work(phba->wq, &phba->unblock_request_work);
3063 static inline uint64_t
3064 lpfc_get_max_line_rate(struct lpfc_hba *phba)
3066 uint64_t rate = lpfc_sli_port_speed_get(phba);
3068 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3072 lpfc_cmf_signal_init(struct lpfc_hba *phba)
3074 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3075 "6223 Signal CMF init\n");
3077 /* Use the new fc_linkspeed to recalculate */
3078 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3079 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3080 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3081 phba->cmf_interval_rate, 1000);
3082 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3084 /* This is a signal to firmware to sync up CMF BW with link speed */
3085 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3089 * lpfc_cmf_start - Start CMF processing
3090 * @phba: pointer to lpfc hba data structure.
3092 * This is called when the link comes up or if CMF mode is turned OFF
3093 * to Monitor or Managed.
3096 lpfc_cmf_start(struct lpfc_hba *phba)
3098 struct lpfc_cgn_stat *cgs;
3101 /* We only do something if CMF is enabled */
3102 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3103 phba->cmf_active_mode == LPFC_CFG_OFF)
3106 /* Reinitialize congestion buffer info */
3107 lpfc_init_congestion_buf(phba);
3109 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3110 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3111 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3112 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3114 atomic_set(&phba->cmf_busy, 0);
3115 for_each_present_cpu(cpu) {
3116 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3117 atomic64_set(&cgs->total_bytes, 0);
3118 atomic64_set(&cgs->rcv_bytes, 0);
3119 atomic_set(&cgs->rx_io_cnt, 0);
3120 atomic64_set(&cgs->rx_latency, 0);
3122 phba->cmf_latency.tv_sec = 0;
3123 phba->cmf_latency.tv_nsec = 0;
3125 lpfc_cmf_signal_init(phba);
3127 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3128 "6222 Start CMF / Timer\n");
3130 phba->cmf_timer_cnt = 0;
3131 hrtimer_start(&phba->cmf_timer,
3132 ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
3134 /* Setup for latency check in IO cmpl routines */
3135 ktime_get_real_ts64(&phba->cmf_latency);
3137 atomic_set(&phba->cmf_bw_wait, 0);
3138 atomic_set(&phba->cmf_stop_io, 0);
3142 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
3143 * @phba: pointer to lpfc hba data structure.
3145 * This routine stops all the timers associated with a HBA. This function is
3146 * invoked before either putting a HBA offline or unloading the driver.
3149 lpfc_stop_hba_timers(struct lpfc_hba *phba)
3152 lpfc_stop_vport_timers(phba->pport);
3153 cancel_delayed_work_sync(&phba->eq_delay_work);
3154 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
3155 del_timer_sync(&phba->sli.mbox_tmo);
3156 del_timer_sync(&phba->fabric_block_timer);
3157 del_timer_sync(&phba->eratt_poll);
3158 del_timer_sync(&phba->hb_tmofunc);
3159 if (phba->sli_rev == LPFC_SLI_REV4) {
3160 del_timer_sync(&phba->rrq_tmr);
3161 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
3163 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
3165 switch (phba->pci_dev_grp) {
3166 case LPFC_PCI_DEV_LP:
3167 /* Stop any LightPulse device specific driver timers */
3168 del_timer_sync(&phba->fcp_poll_timer);
3170 case LPFC_PCI_DEV_OC:
3171 /* Stop any OneConnect device specific driver timers */
3172 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
3175 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3176 "0297 Invalid device group (x%x)\n",
3184 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3185 * @phba: pointer to lpfc hba data structure.
3186 * @mbx_action: flag for mailbox no wait action.
3188 * This routine marks a HBA's management interface as blocked. Once the HBA's
3189 * management interface is marked as blocked, all the user space access to
3190 * the HBA, whether they are from sysfs interface or libdfc interface will
3191 * all be blocked. The HBA is set to block the management interface when the
3192 * driver prepares the HBA interface for online or offline.
3195 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
3197 unsigned long iflag;
3198 uint8_t actcmd = MBX_HEARTBEAT;
3199 unsigned long timeout;
3201 spin_lock_irqsave(&phba->hbalock, iflag);
3202 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
3203 spin_unlock_irqrestore(&phba->hbalock, iflag);
3204 if (mbx_action == LPFC_MBX_NO_WAIT)
3206 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3207 spin_lock_irqsave(&phba->hbalock, iflag);
3208 if (phba->sli.mbox_active) {
3209 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3210 /* Determine how long we might wait for the active mailbox
3211 * command to be gracefully completed by firmware.
3213 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3214 phba->sli.mbox_active) * 1000) + jiffies;
3216 spin_unlock_irqrestore(&phba->hbalock, iflag);
3218 /* Wait for the outstnading mailbox command to complete */
3219 while (phba->sli.mbox_active) {
3220 /* Check active mailbox complete status every 2ms */
3222 if (time_after(jiffies, timeout)) {
3223 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3224 "2813 Mgmt IO is Blocked %x "
3225 "- mbox cmd %x still active\n",
3226 phba->sli.sli_flag, actcmd);
3233 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3234 * @phba: pointer to lpfc hba data structure.
3236 * Allocate RPIs for all active remote nodes. This is needed whenever
3237 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3238 * is to fixup the temporary rpi assignments.
3241 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3243 struct lpfc_nodelist *ndlp, *next_ndlp;
3244 struct lpfc_vport **vports;
3247 if (phba->sli_rev != LPFC_SLI_REV4)
3250 vports = lpfc_create_vport_work_array(phba);
3254 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3255 if (vports[i]->load_flag & FC_UNLOADING)
3258 list_for_each_entry_safe(ndlp, next_ndlp,
3259 &vports[i]->fc_nodes,
3261 rpi = lpfc_sli4_alloc_rpi(phba);
3262 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3263 /* TODO print log? */
3266 ndlp->nlp_rpi = rpi;
3267 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3268 LOG_NODE | LOG_DISCOVERY,
3269 "0009 Assign RPI x%x to ndlp x%px "
3270 "DID:x%06x flg:x%x\n",
3271 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
3275 lpfc_destroy_vport_work_array(phba, vports);
3279 * lpfc_create_expedite_pool - create expedite pool
3280 * @phba: pointer to lpfc hba data structure.
3282 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3283 * to expedite pool. Mark them as expedite.
3285 static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
3287 struct lpfc_sli4_hdw_queue *qp;
3288 struct lpfc_io_buf *lpfc_ncmd;
3289 struct lpfc_io_buf *lpfc_ncmd_next;
3290 struct lpfc_epd_pool *epd_pool;
3291 unsigned long iflag;
3293 epd_pool = &phba->epd_pool;
3294 qp = &phba->sli4_hba.hdwq[0];
3296 spin_lock_init(&epd_pool->lock);
3297 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3298 spin_lock(&epd_pool->lock);
3299 INIT_LIST_HEAD(&epd_pool->list);
3300 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3301 &qp->lpfc_io_buf_list_put, list) {
3302 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3303 lpfc_ncmd->expedite = true;
3306 if (epd_pool->count >= XRI_BATCH)
3309 spin_unlock(&epd_pool->lock);
3310 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3314 * lpfc_destroy_expedite_pool - destroy expedite pool
3315 * @phba: pointer to lpfc hba data structure.
3317 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3318 * of HWQ 0. Clear the mark.
3320 static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
3322 struct lpfc_sli4_hdw_queue *qp;
3323 struct lpfc_io_buf *lpfc_ncmd;
3324 struct lpfc_io_buf *lpfc_ncmd_next;
3325 struct lpfc_epd_pool *epd_pool;
3326 unsigned long iflag;
3328 epd_pool = &phba->epd_pool;
3329 qp = &phba->sli4_hba.hdwq[0];
3331 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3332 spin_lock(&epd_pool->lock);
3333 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3334 &epd_pool->list, list) {
3335 list_move_tail(&lpfc_ncmd->list,
3336 &qp->lpfc_io_buf_list_put);
3337 lpfc_ncmd->flags = false;
3341 spin_unlock(&epd_pool->lock);
3342 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3346 * lpfc_create_multixri_pools - create multi-XRI pools
3347 * @phba: pointer to lpfc hba data structure.
3349 * This routine initialize public, private per HWQ. Then, move XRIs from
3350 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3353 void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3358 struct lpfc_io_buf *lpfc_ncmd;
3359 struct lpfc_io_buf *lpfc_ncmd_next;
3360 unsigned long iflag;
3361 struct lpfc_sli4_hdw_queue *qp;
3362 struct lpfc_multixri_pool *multixri_pool;
3363 struct lpfc_pbl_pool *pbl_pool;
3364 struct lpfc_pvt_pool *pvt_pool;
3366 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3367 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3368 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3369 phba->sli4_hba.io_xri_cnt);
3371 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3372 lpfc_create_expedite_pool(phba);
3374 hwq_count = phba->cfg_hdw_queue;
3375 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3377 for (i = 0; i < hwq_count; i++) {
3378 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3380 if (!multixri_pool) {
3381 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3382 "1238 Failed to allocate memory for "
3385 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3386 lpfc_destroy_expedite_pool(phba);
3390 qp = &phba->sli4_hba.hdwq[j];
3391 kfree(qp->p_multixri_pool);
3394 phba->cfg_xri_rebalancing = 0;
3398 qp = &phba->sli4_hba.hdwq[i];
3399 qp->p_multixri_pool = multixri_pool;
3401 multixri_pool->xri_limit = count_per_hwq;
3402 multixri_pool->rrb_next_hwqid = i;
3404 /* Deal with public free xri pool */
3405 pbl_pool = &multixri_pool->pbl_pool;
3406 spin_lock_init(&pbl_pool->lock);
3407 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3408 spin_lock(&pbl_pool->lock);
3409 INIT_LIST_HEAD(&pbl_pool->list);
3410 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3411 &qp->lpfc_io_buf_list_put, list) {
3412 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3416 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3417 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3418 pbl_pool->count, i);
3419 spin_unlock(&pbl_pool->lock);
3420 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3422 /* Deal with private free xri pool */
3423 pvt_pool = &multixri_pool->pvt_pool;
3424 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3425 pvt_pool->low_watermark = XRI_BATCH;
3426 spin_lock_init(&pvt_pool->lock);
3427 spin_lock_irqsave(&pvt_pool->lock, iflag);
3428 INIT_LIST_HEAD(&pvt_pool->list);
3429 pvt_pool->count = 0;
3430 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3435 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3436 * @phba: pointer to lpfc hba data structure.
3438 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3440 static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
3444 struct lpfc_io_buf *lpfc_ncmd;
3445 struct lpfc_io_buf *lpfc_ncmd_next;
3446 unsigned long iflag;
3447 struct lpfc_sli4_hdw_queue *qp;
3448 struct lpfc_multixri_pool *multixri_pool;
3449 struct lpfc_pbl_pool *pbl_pool;
3450 struct lpfc_pvt_pool *pvt_pool;
3452 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3453 lpfc_destroy_expedite_pool(phba);
3455 if (!(phba->pport->load_flag & FC_UNLOADING))
3456 lpfc_sli_flush_io_rings(phba);
3458 hwq_count = phba->cfg_hdw_queue;
3460 for (i = 0; i < hwq_count; i++) {
3461 qp = &phba->sli4_hba.hdwq[i];
3462 multixri_pool = qp->p_multixri_pool;
3466 qp->p_multixri_pool = NULL;
3468 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3470 /* Deal with public free xri pool */
3471 pbl_pool = &multixri_pool->pbl_pool;
3472 spin_lock(&pbl_pool->lock);
3474 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3475 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3476 pbl_pool->count, i);
3478 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3479 &pbl_pool->list, list) {
3480 list_move_tail(&lpfc_ncmd->list,
3481 &qp->lpfc_io_buf_list_put);
3486 INIT_LIST_HEAD(&pbl_pool->list);
3487 pbl_pool->count = 0;
3489 spin_unlock(&pbl_pool->lock);
3491 /* Deal with private free xri pool */
3492 pvt_pool = &multixri_pool->pvt_pool;
3493 spin_lock(&pvt_pool->lock);
3495 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3496 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3497 pvt_pool->count, i);
3499 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3500 &pvt_pool->list, list) {
3501 list_move_tail(&lpfc_ncmd->list,
3502 &qp->lpfc_io_buf_list_put);
3507 INIT_LIST_HEAD(&pvt_pool->list);
3508 pvt_pool->count = 0;
3510 spin_unlock(&pvt_pool->lock);
3511 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3513 kfree(multixri_pool);
3518 * lpfc_online - Initialize and bring a HBA online
3519 * @phba: pointer to lpfc hba data structure.
3521 * This routine initializes the HBA and brings a HBA online. During this
3522 * process, the management interface is blocked to prevent user space access
3523 * to the HBA interfering with the driver initialization.
3530 lpfc_online(struct lpfc_hba *phba)
3532 struct lpfc_vport *vport;
3533 struct lpfc_vport **vports;
3535 bool vpis_cleared = false;
3539 vport = phba->pport;
3541 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3544 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3545 "0458 Bring Adapter online\n");
3547 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3549 if (phba->sli_rev == LPFC_SLI_REV4) {
3550 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3551 lpfc_unblock_mgmt_io(phba);
3554 spin_lock_irq(&phba->hbalock);
3555 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3556 vpis_cleared = true;
3557 spin_unlock_irq(&phba->hbalock);
3559 /* Reestablish the local initiator port.
3560 * The offline process destroyed the previous lport.
3562 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3563 !phba->nvmet_support) {
3564 error = lpfc_nvme_create_localport(phba->pport);
3566 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3567 "6132 NVME restore reg failed "
3568 "on nvmei error x%x\n", error);
3571 lpfc_sli_queue_init(phba);
3572 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3573 lpfc_unblock_mgmt_io(phba);
3578 vports = lpfc_create_vport_work_array(phba);
3579 if (vports != NULL) {
3580 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3581 struct Scsi_Host *shost;
3582 shost = lpfc_shost_from_vport(vports[i]);
3583 spin_lock_irq(shost->host_lock);
3584 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3585 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3586 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3587 if (phba->sli_rev == LPFC_SLI_REV4) {
3588 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3589 if ((vpis_cleared) &&
3590 (vports[i]->port_type !=
3591 LPFC_PHYSICAL_PORT))
3594 spin_unlock_irq(shost->host_lock);
3597 lpfc_destroy_vport_work_array(phba, vports);
3599 if (phba->cfg_xri_rebalancing)
3600 lpfc_create_multixri_pools(phba);
3602 lpfc_cpuhp_add(phba);
3604 lpfc_unblock_mgmt_io(phba);
3609 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3610 * @phba: pointer to lpfc hba data structure.
3612 * This routine marks a HBA's management interface as not blocked. Once the
3613 * HBA's management interface is marked as not blocked, all the user space
3614 * access to the HBA, whether they are from sysfs interface or libdfc
3615 * interface will be allowed. The HBA is set to block the management interface
3616 * when the driver prepares the HBA interface for online or offline and then
3617 * set to unblock the management interface afterwards.
3620 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3622 unsigned long iflag;
3624 spin_lock_irqsave(&phba->hbalock, iflag);
3625 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3626 spin_unlock_irqrestore(&phba->hbalock, iflag);
3630 * lpfc_offline_prep - Prepare a HBA to be brought offline
3631 * @phba: pointer to lpfc hba data structure.
3632 * @mbx_action: flag for mailbox shutdown action.
3634 * This routine is invoked to prepare a HBA to be brought offline. It performs
3635 * unregistration login to all the nodes on all vports and flushes the mailbox
3636 * queue to make it ready to be brought offline.
3639 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3641 struct lpfc_vport *vport = phba->pport;
3642 struct lpfc_nodelist *ndlp, *next_ndlp;
3643 struct lpfc_vport **vports;
3644 struct Scsi_Host *shost;
3647 if (vport->fc_flag & FC_OFFLINE_MODE)
3650 lpfc_block_mgmt_io(phba, mbx_action);
3652 lpfc_linkdown(phba);
3654 /* Issue an unreg_login to all nodes on all vports */
3655 vports = lpfc_create_vport_work_array(phba);
3656 if (vports != NULL) {
3657 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3658 if (vports[i]->load_flag & FC_UNLOADING)
3660 shost = lpfc_shost_from_vport(vports[i]);
3661 spin_lock_irq(shost->host_lock);
3662 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3663 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3664 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3665 spin_unlock_irq(shost->host_lock);
3667 shost = lpfc_shost_from_vport(vports[i]);
3668 list_for_each_entry_safe(ndlp, next_ndlp,
3669 &vports[i]->fc_nodes,
3672 spin_lock_irq(&ndlp->lock);
3673 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3674 spin_unlock_irq(&ndlp->lock);
3676 lpfc_unreg_rpi(vports[i], ndlp);
3678 * Whenever an SLI4 port goes offline, free the
3679 * RPI. Get a new RPI when the adapter port
3680 * comes back online.
3682 if (phba->sli_rev == LPFC_SLI_REV4) {
3683 lpfc_printf_vlog(vports[i], KERN_INFO,
3684 LOG_NODE | LOG_DISCOVERY,
3685 "0011 Free RPI x%x on "
3686 "ndlp: x%px did x%x\n",
3687 ndlp->nlp_rpi, ndlp,
3689 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3690 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
3693 if (ndlp->nlp_type & NLP_FABRIC) {
3694 lpfc_disc_state_machine(vports[i], ndlp,
3695 NULL, NLP_EVT_DEVICE_RECOVERY);
3697 /* Don't remove the node unless the
3698 * has been unregistered with the
3699 * transport. If so, let dev_loss
3700 * take care of the node.
3702 if (!(ndlp->fc4_xpt_flags &
3703 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3704 lpfc_disc_state_machine
3712 lpfc_destroy_vport_work_array(phba, vports);
3714 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3717 flush_workqueue(phba->wq);
3721 * lpfc_offline - Bring a HBA offline
3722 * @phba: pointer to lpfc hba data structure.
3724 * This routine actually brings a HBA offline. It stops all the timers
3725 * associated with the HBA, brings down the SLI layer, and eventually
3726 * marks the HBA as in offline state for the upper layer protocol.
3729 lpfc_offline(struct lpfc_hba *phba)
3731 struct Scsi_Host *shost;
3732 struct lpfc_vport **vports;
3735 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3738 /* stop port and all timers associated with this hba */
3739 lpfc_stop_port(phba);
3741 /* Tear down the local and target port registrations. The
3742 * nvme transports need to cleanup.
3744 lpfc_nvmet_destroy_targetport(phba);
3745 lpfc_nvme_destroy_localport(phba->pport);
3747 vports = lpfc_create_vport_work_array(phba);
3749 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3750 lpfc_stop_vport_timers(vports[i]);
3751 lpfc_destroy_vport_work_array(phba, vports);
3752 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3753 "0460 Bring Adapter offline\n");
3754 /* Bring down the SLI Layer and cleanup. The HBA is offline
3756 lpfc_sli_hba_down(phba);
3757 spin_lock_irq(&phba->hbalock);
3759 spin_unlock_irq(&phba->hbalock);
3760 vports = lpfc_create_vport_work_array(phba);
3762 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3763 shost = lpfc_shost_from_vport(vports[i]);
3764 spin_lock_irq(shost->host_lock);
3765 vports[i]->work_port_events = 0;
3766 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3767 spin_unlock_irq(shost->host_lock);
3769 lpfc_destroy_vport_work_array(phba, vports);
3770 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3773 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3774 __lpfc_cpuhp_remove(phba);
3776 if (phba->cfg_xri_rebalancing)
3777 lpfc_destroy_multixri_pools(phba);
3781 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3782 * @phba: pointer to lpfc hba data structure.
3784 * This routine is to free all the SCSI buffers and IOCBs from the driver
3785 * list back to kernel. It is called from lpfc_pci_remove_one to free
3786 * the internal resources before the device is removed from the system.
3789 lpfc_scsi_free(struct lpfc_hba *phba)
3791 struct lpfc_io_buf *sb, *sb_next;
3793 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3796 spin_lock_irq(&phba->hbalock);
3798 /* Release all the lpfc_scsi_bufs maintained by this host. */
3800 spin_lock(&phba->scsi_buf_list_put_lock);
3801 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3803 list_del(&sb->list);
3804 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3807 phba->total_scsi_bufs--;
3809 spin_unlock(&phba->scsi_buf_list_put_lock);
3811 spin_lock(&phba->scsi_buf_list_get_lock);
3812 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3814 list_del(&sb->list);
3815 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3818 phba->total_scsi_bufs--;
3820 spin_unlock(&phba->scsi_buf_list_get_lock);
3821 spin_unlock_irq(&phba->hbalock);
3825 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3826 * @phba: pointer to lpfc hba data structure.
3828 * This routine is to free all the IO buffers and IOCBs from the driver
3829 * list back to kernel. It is called from lpfc_pci_remove_one to free
3830 * the internal resources before the device is removed from the system.
3833 lpfc_io_free(struct lpfc_hba *phba)
3835 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
3836 struct lpfc_sli4_hdw_queue *qp;
3839 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3840 qp = &phba->sli4_hba.hdwq[idx];
3841 /* Release all the lpfc_nvme_bufs maintained by this host. */
3842 spin_lock(&qp->io_buf_list_put_lock);
3843 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3844 &qp->lpfc_io_buf_list_put,
3846 list_del(&lpfc_ncmd->list);
3848 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3849 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3850 if (phba->cfg_xpsgl && !phba->nvmet_support)
3851 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3852 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3854 qp->total_io_bufs--;
3856 spin_unlock(&qp->io_buf_list_put_lock);
3858 spin_lock(&qp->io_buf_list_get_lock);
3859 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3860 &qp->lpfc_io_buf_list_get,
3862 list_del(&lpfc_ncmd->list);
3864 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3865 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3866 if (phba->cfg_xpsgl && !phba->nvmet_support)
3867 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3868 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
3870 qp->total_io_bufs--;
3872 spin_unlock(&qp->io_buf_list_get_lock);
3877 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3878 * @phba: pointer to lpfc hba data structure.
3880 * This routine first calculates the sizes of the current els and allocated
3881 * scsi sgl lists, and then goes through all sgls to updates the physical
3882 * XRIs assigned due to port function reset. During port initialization, the
3883 * current els and allocated scsi sgl lists are 0s.
3886 * 0 - successful (for now, it always returns 0)
3889 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3891 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3892 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3893 LIST_HEAD(els_sgl_list);
3897 * update on pci function's els xri-sgl list
3899 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3901 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3902 /* els xri-sgl expanded */
3903 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3904 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3905 "3157 ELS xri-sgl count increased from "
3906 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3908 /* allocate the additional els sgls */
3909 for (i = 0; i < xri_cnt; i++) {
3910 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3912 if (sglq_entry == NULL) {
3913 lpfc_printf_log(phba, KERN_ERR,
3915 "2562 Failure to allocate an "
3916 "ELS sgl entry:%d\n", i);
3920 sglq_entry->buff_type = GEN_BUFF_TYPE;
3921 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3923 if (sglq_entry->virt == NULL) {
3925 lpfc_printf_log(phba, KERN_ERR,
3927 "2563 Failure to allocate an "
3928 "ELS mbuf:%d\n", i);
3932 sglq_entry->sgl = sglq_entry->virt;
3933 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3934 sglq_entry->state = SGL_FREED;
3935 list_add_tail(&sglq_entry->list, &els_sgl_list);
3937 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
3938 list_splice_init(&els_sgl_list,
3939 &phba->sli4_hba.lpfc_els_sgl_list);
3940 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
3941 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3942 /* els xri-sgl shrinked */
3943 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3944 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3945 "3158 ELS xri-sgl count decreased from "
3946 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3948 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
3949 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3951 /* release extra els sgls from list */
3952 for (i = 0; i < xri_cnt; i++) {
3953 list_remove_head(&els_sgl_list,
3954 sglq_entry, struct lpfc_sglq, list);
3956 __lpfc_mbuf_free(phba, sglq_entry->virt,
3961 list_splice_init(&els_sgl_list,
3962 &phba->sli4_hba.lpfc_els_sgl_list);
3963 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
3965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3966 "3163 ELS xri-sgl count unchanged: %d\n",
3968 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3970 /* update xris to els sgls on the list */
3972 sglq_entry_next = NULL;
3973 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3974 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3975 lxri = lpfc_sli4_next_xritag(phba);
3976 if (lxri == NO_XRI) {
3977 lpfc_printf_log(phba, KERN_ERR,
3979 "2400 Failed to allocate xri for "
3984 sglq_entry->sli4_lxritag = lxri;
3985 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3990 lpfc_free_els_sgl_list(phba);
3995 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3996 * @phba: pointer to lpfc hba data structure.
3998 * This routine first calculates the sizes of the current els and allocated
3999 * scsi sgl lists, and then goes through all sgls to updates the physical
4000 * XRIs assigned due to port function reset. During port initialization, the
4001 * current els and allocated scsi sgl lists are 0s.
4004 * 0 - successful (for now, it always returns 0)
4007 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4009 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4010 uint16_t i, lxri, xri_cnt, els_xri_cnt;
4011 uint16_t nvmet_xri_cnt;
4012 LIST_HEAD(nvmet_sgl_list);
4016 * update on pci function's nvmet xri-sgl list
4018 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4020 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4021 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4022 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4023 /* els xri-sgl expanded */
4024 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4025 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4026 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4027 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4028 /* allocate the additional nvmet sgls */
4029 for (i = 0; i < xri_cnt; i++) {
4030 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4032 if (sglq_entry == NULL) {
4033 lpfc_printf_log(phba, KERN_ERR,
4035 "6303 Failure to allocate an "
4036 "NVMET sgl entry:%d\n", i);
4040 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4041 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4043 if (sglq_entry->virt == NULL) {
4045 lpfc_printf_log(phba, KERN_ERR,
4047 "6304 Failure to allocate an "
4048 "NVMET buf:%d\n", i);
4052 sglq_entry->sgl = sglq_entry->virt;
4053 memset(sglq_entry->sgl, 0,
4054 phba->cfg_sg_dma_buf_size);
4055 sglq_entry->state = SGL_FREED;
4056 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4058 spin_lock_irq(&phba->hbalock);
4059 spin_lock(&phba->sli4_hba.sgl_list_lock);
4060 list_splice_init(&nvmet_sgl_list,
4061 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4062 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4063 spin_unlock_irq(&phba->hbalock);
4064 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4065 /* nvmet xri-sgl shrunk */
4066 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4067 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4068 "6305 NVMET xri-sgl count decreased from "
4069 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4071 spin_lock_irq(&phba->hbalock);
4072 spin_lock(&phba->sli4_hba.sgl_list_lock);
4073 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4075 /* release extra nvmet sgls from list */
4076 for (i = 0; i < xri_cnt; i++) {
4077 list_remove_head(&nvmet_sgl_list,
4078 sglq_entry, struct lpfc_sglq, list);
4080 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4085 list_splice_init(&nvmet_sgl_list,
4086 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4087 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4088 spin_unlock_irq(&phba->hbalock);
4090 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4091 "6306 NVMET xri-sgl count unchanged: %d\n",
4093 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4095 /* update xris to nvmet sgls on the list */
4097 sglq_entry_next = NULL;
4098 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4099 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4100 lxri = lpfc_sli4_next_xritag(phba);
4101 if (lxri == NO_XRI) {
4102 lpfc_printf_log(phba, KERN_ERR,
4104 "6307 Failed to allocate xri for "
4109 sglq_entry->sli4_lxritag = lxri;
4110 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4115 lpfc_free_nvmet_sgl_list(phba);
4120 lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4123 struct lpfc_sli4_hdw_queue *qp;
4124 struct lpfc_io_buf *lpfc_cmd;
4125 struct lpfc_io_buf *iobufp, *prev_iobufp;
4126 int idx, cnt, xri, inserted;
4129 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4130 qp = &phba->sli4_hba.hdwq[idx];
4131 spin_lock_irq(&qp->io_buf_list_get_lock);
4132 spin_lock(&qp->io_buf_list_put_lock);
4134 /* Take everything off the get and put lists */
4135 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4136 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4137 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4138 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4139 cnt += qp->get_io_bufs + qp->put_io_bufs;
4140 qp->get_io_bufs = 0;
4141 qp->put_io_bufs = 0;
4142 qp->total_io_bufs = 0;
4143 spin_unlock(&qp->io_buf_list_put_lock);
4144 spin_unlock_irq(&qp->io_buf_list_get_lock);
4148 * Take IO buffers off blist and put on cbuf sorted by XRI.
4149 * This is because POST_SGL takes a sequential range of XRIs
4150 * to post to the firmware.
4152 for (idx = 0; idx < cnt; idx++) {
4153 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
4157 list_add_tail(&lpfc_cmd->list, cbuf);
4160 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4163 list_for_each_entry(iobufp, cbuf, list) {
4164 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4166 list_add(&lpfc_cmd->list,
4167 &prev_iobufp->list);
4169 list_add(&lpfc_cmd->list, cbuf);
4173 prev_iobufp = iobufp;
4176 list_add_tail(&lpfc_cmd->list, cbuf);
4182 lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4184 struct lpfc_sli4_hdw_queue *qp;
4185 struct lpfc_io_buf *lpfc_cmd;
4188 qp = phba->sli4_hba.hdwq;
4190 while (!list_empty(cbuf)) {
4191 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4192 list_remove_head(cbuf, lpfc_cmd,
4193 struct lpfc_io_buf, list);
4197 qp = &phba->sli4_hba.hdwq[idx];
4198 lpfc_cmd->hdwq_no = idx;
4199 lpfc_cmd->hdwq = qp;
4200 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
4201 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
4202 spin_lock(&qp->io_buf_list_put_lock);
4203 list_add_tail(&lpfc_cmd->list,
4204 &qp->lpfc_io_buf_list_put);
4206 qp->total_io_bufs++;
4207 spin_unlock(&qp->io_buf_list_put_lock);
4214 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4215 * @phba: pointer to lpfc hba data structure.
4217 * This routine first calculates the sizes of the current els and allocated
4218 * scsi sgl lists, and then goes through all sgls to updates the physical
4219 * XRIs assigned due to port function reset. During port initialization, the
4220 * current els and allocated scsi sgl lists are 0s.
4223 * 0 - successful (for now, it always returns 0)
4226 lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
4228 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
4229 uint16_t i, lxri, els_xri_cnt;
4230 uint16_t io_xri_cnt, io_xri_max;
4231 LIST_HEAD(io_sgl_list);
4235 * update on pci function's allocated nvme xri-sgl list
4238 /* maximum number of xris available for nvme buffers */
4239 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4240 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4241 phba->sli4_hba.io_xri_max = io_xri_max;
4243 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4244 "6074 Current allocated XRI sgl count:%d, "
4245 "maximum XRI count:%d\n",
4246 phba->sli4_hba.io_xri_cnt,
4247 phba->sli4_hba.io_xri_max);
4249 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
4251 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
4252 /* max nvme xri shrunk below the allocated nvme buffers */
4253 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4254 phba->sli4_hba.io_xri_max;
4255 /* release the extra allocated nvme buffers */
4256 for (i = 0; i < io_xri_cnt; i++) {
4257 list_remove_head(&io_sgl_list, lpfc_ncmd,
4258 struct lpfc_io_buf, list);
4260 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4262 lpfc_ncmd->dma_handle);
4266 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
4269 /* update xris associated to remaining allocated nvme buffers */
4271 lpfc_ncmd_next = NULL;
4272 phba->sli4_hba.io_xri_cnt = cnt;
4273 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
4274 &io_sgl_list, list) {
4275 lxri = lpfc_sli4_next_xritag(phba);
4276 if (lxri == NO_XRI) {
4277 lpfc_printf_log(phba, KERN_ERR,
4279 "6075 Failed to allocate xri for "
4284 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4285 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4287 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
4296 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4297 * @phba: Pointer to lpfc hba data structure.
4298 * @num_to_alloc: The requested number of buffers to allocate.
4300 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4301 * the nvme buffer contains all the necessary information needed to initiate
4302 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4303 * them on a list, it post them to the port by using SGL block post.
4306 * int - number of IO buffers that were allocated and posted.
4307 * 0 = failure, less than num_to_alloc is a partial failure.
4310 lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4312 struct lpfc_io_buf *lpfc_ncmd;
4313 struct lpfc_iocbq *pwqeq;
4314 uint16_t iotag, lxri = 0;
4315 int bcnt, num_posted;
4316 LIST_HEAD(prep_nblist);
4317 LIST_HEAD(post_nblist);
4318 LIST_HEAD(nvme_nblist);
4320 phba->sli4_hba.io_xri_cnt = 0;
4321 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4322 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
4326 * Get memory from the pci pool to map the virt space to
4327 * pci bus space for an I/O. The DMA buffer includes the
4328 * number of SGE's necessary to support the sg_tablesize.
4330 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4332 &lpfc_ncmd->dma_handle);
4333 if (!lpfc_ncmd->data) {
4338 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4339 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4342 * 4K Page alignment is CRITICAL to BlockGuard, double
4345 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4346 (((unsigned long)(lpfc_ncmd->data) &
4347 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4348 lpfc_printf_log(phba, KERN_ERR,
4350 "3369 Memory alignment err: "
4352 (unsigned long)lpfc_ncmd->data);
4353 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4355 lpfc_ncmd->dma_handle);
4361 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4363 lxri = lpfc_sli4_next_xritag(phba);
4364 if (lxri == NO_XRI) {
4365 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4366 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4370 pwqeq = &lpfc_ncmd->cur_iocbq;
4372 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4373 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4375 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4376 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4378 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4379 "6121 Failed to allocate IOTAG for"
4380 " XRI:0x%x\n", lxri);
4381 lpfc_sli4_free_xri(phba, lxri);
4384 pwqeq->sli4_lxritag = lxri;
4385 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4386 pwqeq->context1 = lpfc_ncmd;
4388 /* Initialize local short-hand pointers. */
4389 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4390 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4391 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
4392 spin_lock_init(&lpfc_ncmd->buf_lock);
4394 /* add the nvme buffer to a post list */
4395 list_add_tail(&lpfc_ncmd->list, &post_nblist);
4396 phba->sli4_hba.io_xri_cnt++;
4398 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4399 "6114 Allocate %d out of %d requested new NVME "
4400 "buffers\n", bcnt, num_to_alloc);
4402 /* post the list of nvme buffer sgls to port if available */
4403 if (!list_empty(&post_nblist))
4404 num_posted = lpfc_sli4_post_io_sgl_list(
4405 phba, &post_nblist, bcnt);
4413 lpfc_get_wwpn(struct lpfc_hba *phba)
4417 LPFC_MBOXQ_t *mboxq;
4420 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4423 return (uint64_t)-1;
4425 /* First get WWN of HBA instance */
4426 lpfc_read_nv(phba, mboxq);
4427 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4428 if (rc != MBX_SUCCESS) {
4429 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4430 "6019 Mailbox failed , mbxCmd x%x "
4431 "READ_NV, mbxStatus x%x\n",
4432 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4433 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4434 mempool_free(mboxq, phba->mbox_mem_pool);
4435 return (uint64_t) -1;
4438 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4439 /* wwn is WWPN of HBA instance */
4440 mempool_free(mboxq, phba->mbox_mem_pool);
4441 if (phba->sli_rev == LPFC_SLI_REV4)
4442 return be64_to_cpu(wwn);
4444 return rol64(wwn, 32);
4448 * lpfc_vmid_res_alloc - Allocates resources for VMID
4449 * @phba: pointer to lpfc hba data structure.
4450 * @vport: pointer to vport data structure
4452 * This routine allocated the resources needed for the VMID.
4459 lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4461 /* VMID feature is supported only on SLI4 */
4462 if (phba->sli_rev == LPFC_SLI_REV3) {
4463 phba->cfg_vmid_app_header = 0;
4464 phba->cfg_vmid_priority_tagging = 0;
4467 if (lpfc_is_vmid_enabled(phba)) {
4469 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4474 rwlock_init(&vport->vmid_lock);
4476 /* Set the VMID parameters for the vport */
4477 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4478 vport->vmid_inactivity_timeout =
4479 phba->cfg_vmid_inactivity_timeout;
4480 vport->max_vmid = phba->cfg_max_vmid;
4481 vport->cur_vmid_cnt = 0;
4483 vport->vmid_priority_range = bitmap_zalloc
4484 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4486 if (!vport->vmid_priority_range) {
4491 hash_init(vport->hash_table);
4497 * lpfc_create_port - Create an FC port
4498 * @phba: pointer to lpfc hba data structure.
4499 * @instance: a unique integer ID to this FC port.
4500 * @dev: pointer to the device data structure.
4502 * This routine creates a FC port for the upper layer protocol. The FC port
4503 * can be created on top of either a physical port or a virtual port provided
4504 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4505 * and associates the FC port created before adding the shost into the SCSI
4509 * @vport - pointer to the virtual N_Port data structure.
4510 * NULL - port create failed.
4513 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
4515 struct lpfc_vport *vport;
4516 struct Scsi_Host *shost = NULL;
4517 struct scsi_host_template *template;
4521 bool use_no_reset_hba = false;
4524 if (lpfc_no_hba_reset_cnt) {
4525 if (phba->sli_rev < LPFC_SLI_REV4 &&
4526 dev == &phba->pcidev->dev) {
4527 /* Reset the port first */
4528 lpfc_sli_brdrestart(phba);
4529 rc = lpfc_sli_chipset_init(phba);
4533 wwn = lpfc_get_wwpn(phba);
4536 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4537 if (wwn == lpfc_no_hba_reset[i]) {
4538 lpfc_printf_log(phba, KERN_ERR,
4540 "6020 Setting use_no_reset port=%llx\n",
4542 use_no_reset_hba = true;
4547 /* Seed template for SCSI host registration */
4548 if (dev == &phba->pcidev->dev) {
4549 template = &phba->port_template;
4551 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4552 /* Seed physical port template */
4553 memcpy(template, &lpfc_template, sizeof(*template));
4555 if (use_no_reset_hba)
4556 /* template is for a no reset SCSI Host */
4557 template->eh_host_reset_handler = NULL;
4559 /* Template for all vports this physical port creates */
4560 memcpy(&phba->vport_template, &lpfc_template,
4562 phba->vport_template.shost_attrs = lpfc_vport_attrs;
4563 phba->vport_template.eh_bus_reset_handler = NULL;
4564 phba->vport_template.eh_host_reset_handler = NULL;
4565 phba->vport_template.vendor_id = 0;
4567 /* Initialize the host templates with updated value */
4568 if (phba->sli_rev == LPFC_SLI_REV4) {
4569 template->sg_tablesize = phba->cfg_scsi_seg_cnt;
4570 phba->vport_template.sg_tablesize =
4571 phba->cfg_scsi_seg_cnt;
4573 template->sg_tablesize = phba->cfg_sg_seg_cnt;
4574 phba->vport_template.sg_tablesize =
4575 phba->cfg_sg_seg_cnt;
4579 /* NVMET is for physical port only */
4580 memcpy(template, &lpfc_template_nvme,
4584 template = &phba->vport_template;
4587 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
4591 vport = (struct lpfc_vport *) shost->hostdata;
4593 vport->load_flag |= FC_LOADING;
4594 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4595 vport->fc_rscn_flush = 0;
4596 lpfc_get_vport_cfgparam(vport);
4598 /* Adjust value in vport */
4599 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4601 shost->unique_id = instance;
4602 shost->max_id = LPFC_MAX_TARGET;
4603 shost->max_lun = vport->cfg_max_luns;
4604 shost->this_id = -1;
4605 shost->max_cmd_len = 16;
4607 if (phba->sli_rev == LPFC_SLI_REV4) {
4608 if (!phba->cfg_fcp_mq_threshold ||
4609 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4610 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4612 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4613 phba->cfg_fcp_mq_threshold);
4615 shost->dma_boundary =
4616 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
4618 if (phba->cfg_xpsgl && !phba->nvmet_support)
4619 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4621 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
4623 /* SLI-3 has a limited number of hardware queues (3),
4624 * thus there is only one for FCP processing.
4626 shost->nr_hw_queues = 1;
4629 * Set initial can_queue value since 0 is no longer supported and
4630 * scsi_add_host will fail. This will be adjusted later based on the
4631 * max xri value determined in hba setup.
4633 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4634 if (dev != &phba->pcidev->dev) {
4635 shost->transportt = lpfc_vport_transport_template;
4636 vport->port_type = LPFC_NPIV_PORT;
4638 shost->transportt = lpfc_transport_template;
4639 vport->port_type = LPFC_PHYSICAL_PORT;
4642 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4643 "9081 CreatePort TMPLATE type %x TBLsize %d "
4645 vport->port_type, shost->sg_tablesize,
4646 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4648 /* Allocate the resources for VMID */
4649 rc = lpfc_vmid_res_alloc(phba, vport);
4654 /* Initialize all internally managed lists. */
4655 INIT_LIST_HEAD(&vport->fc_nodes);
4656 INIT_LIST_HEAD(&vport->rcv_buffer_list);
4657 spin_lock_init(&vport->work_port_lock);
4659 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
4661 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
4663 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
4665 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4666 lpfc_setup_bg(phba, shost);
4668 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4672 spin_lock_irq(&phba->port_list_lock);
4673 list_add_tail(&vport->listentry, &phba->port_list);
4674 spin_unlock_irq(&phba->port_list_lock);
4679 bitmap_free(vport->vmid_priority_range);
4680 scsi_host_put(shost);
4686 * destroy_port - destroy an FC port
4687 * @vport: pointer to an lpfc virtual N_Port data structure.
4689 * This routine destroys a FC port from the upper layer protocol. All the
4690 * resources associated with the port are released.
4693 destroy_port(struct lpfc_vport *vport)
4695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4696 struct lpfc_hba *phba = vport->phba;
4698 lpfc_debugfs_terminate(vport);
4699 fc_remove_host(shost);
4700 scsi_remove_host(shost);
4702 spin_lock_irq(&phba->port_list_lock);
4703 list_del_init(&vport->listentry);
4704 spin_unlock_irq(&phba->port_list_lock);
4706 lpfc_cleanup(vport);
4711 * lpfc_get_instance - Get a unique integer ID
4713 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4714 * uses the kernel idr facility to perform the task.
4717 * instance - a unique integer ID allocated as the new instance.
4718 * -1 - lpfc get instance failed.
4721 lpfc_get_instance(void)
4725 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4726 return ret < 0 ? -1 : ret;
4730 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4731 * @shost: pointer to SCSI host data structure.
4732 * @time: elapsed time of the scan in jiffies.
4734 * This routine is called by the SCSI layer with a SCSI host to determine
4735 * whether the scan host is finished.
4737 * Note: there is no scan_start function as adapter initialization will have
4738 * asynchronously kicked off the link initialization.
4741 * 0 - SCSI host scan is not over yet.
4742 * 1 - SCSI host scan is over.
4744 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4747 struct lpfc_hba *phba = vport->phba;
4750 spin_lock_irq(shost->host_lock);
4752 if (vport->load_flag & FC_UNLOADING) {
4756 if (time >= msecs_to_jiffies(30 * 1000)) {
4757 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4758 "0461 Scanning longer than 30 "
4759 "seconds. Continuing initialization\n");
4763 if (time >= msecs_to_jiffies(15 * 1000) &&
4764 phba->link_state <= LPFC_LINK_DOWN) {
4765 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4766 "0465 Link down longer than 15 "
4767 "seconds. Continuing initialization\n");
4772 if (vport->port_state != LPFC_VPORT_READY)
4774 if (vport->num_disc_nodes || vport->fc_prli_sent)
4776 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4778 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4784 spin_unlock_irq(shost->host_lock);
4788 static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4790 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4791 struct lpfc_hba *phba = vport->phba;
4793 fc_host_supported_speeds(shost) = 0;
4795 * Avoid reporting supported link speed for FCoE as it can't be
4796 * controlled via FCoE.
4798 if (phba->hba_flag & HBA_FCOE_MODE)
4801 if (phba->lmt & LMT_256Gb)
4802 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
4803 if (phba->lmt & LMT_128Gb)
4804 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
4805 if (phba->lmt & LMT_64Gb)
4806 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4807 if (phba->lmt & LMT_32Gb)
4808 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4809 if (phba->lmt & LMT_16Gb)
4810 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4811 if (phba->lmt & LMT_10Gb)
4812 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4813 if (phba->lmt & LMT_8Gb)
4814 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4815 if (phba->lmt & LMT_4Gb)
4816 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4817 if (phba->lmt & LMT_2Gb)
4818 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4819 if (phba->lmt & LMT_1Gb)
4820 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4824 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4825 * @shost: pointer to SCSI host data structure.
4827 * This routine initializes a given SCSI host attributes on a FC port. The
4828 * SCSI host can be either on top of a physical port or a virtual port.
4830 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4832 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4833 struct lpfc_hba *phba = vport->phba;
4835 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4838 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4839 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4840 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4842 memset(fc_host_supported_fc4s(shost), 0,
4843 sizeof(fc_host_supported_fc4s(shost)));
4844 fc_host_supported_fc4s(shost)[2] = 1;
4845 fc_host_supported_fc4s(shost)[7] = 1;
4847 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4848 sizeof fc_host_symbolic_name(shost));
4850 lpfc_host_supported_speeds_set(shost);
4852 fc_host_maxframe_size(shost) =
4853 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4854 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4856 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4858 /* This value is also unchanging */
4859 memset(fc_host_active_fc4s(shost), 0,
4860 sizeof(fc_host_active_fc4s(shost)));
4861 fc_host_active_fc4s(shost)[2] = 1;
4862 fc_host_active_fc4s(shost)[7] = 1;
4864 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4865 spin_lock_irq(shost->host_lock);
4866 vport->load_flag &= ~FC_LOADING;
4867 spin_unlock_irq(shost->host_lock);
4871 * lpfc_stop_port_s3 - Stop SLI3 device port
4872 * @phba: pointer to lpfc hba data structure.
4874 * This routine is invoked to stop an SLI3 device port, it stops the device
4875 * from generating interrupts and stops the device driver's timers for the
4879 lpfc_stop_port_s3(struct lpfc_hba *phba)
4881 /* Clear all interrupt enable conditions */
4882 writel(0, phba->HCregaddr);
4883 readl(phba->HCregaddr); /* flush */
4884 /* Clear all pending interrupts */
4885 writel(0xffffffff, phba->HAregaddr);
4886 readl(phba->HAregaddr); /* flush */
4888 /* Reset some HBA SLI setup states */
4889 lpfc_stop_hba_timers(phba);
4890 phba->pport->work_port_events = 0;
4894 * lpfc_stop_port_s4 - Stop SLI4 device port
4895 * @phba: pointer to lpfc hba data structure.
4897 * This routine is invoked to stop an SLI4 device port, it stops the device
4898 * from generating interrupts and stops the device driver's timers for the
4902 lpfc_stop_port_s4(struct lpfc_hba *phba)
4904 /* Reset some HBA SLI4 setup states */
4905 lpfc_stop_hba_timers(phba);
4907 phba->pport->work_port_events = 0;
4908 phba->sli4_hba.intr_enable = 0;
4912 * lpfc_stop_port - Wrapper function for stopping hba port
4913 * @phba: Pointer to HBA context object.
4915 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4916 * the API jump table function pointer from the lpfc_hba struct.
4919 lpfc_stop_port(struct lpfc_hba *phba)
4921 phba->lpfc_stop_port(phba);
4924 flush_workqueue(phba->wq);
4928 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4929 * @phba: Pointer to hba for which this call is being executed.
4931 * This routine starts the timer waiting for the FCF rediscovery to complete.
4934 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4936 unsigned long fcf_redisc_wait_tmo =
4937 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4938 /* Start fcf rediscovery wait period timer */
4939 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4940 spin_lock_irq(&phba->hbalock);
4941 /* Allow action to new fcf asynchronous event */
4942 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4943 /* Mark the FCF rediscovery pending state */
4944 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4945 spin_unlock_irq(&phba->hbalock);
4949 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4950 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
4952 * This routine is invoked when waiting for FCF table rediscover has been
4953 * timed out. If new FCF record(s) has (have) been discovered during the
4954 * wait period, a new FCF event shall be added to the FCOE async event
4955 * list, and then worker thread shall be waked up for processing from the
4956 * worker thread context.
4959 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
4961 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
4963 /* Don't send FCF rediscovery event if timer cancelled */
4964 spin_lock_irq(&phba->hbalock);
4965 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4966 spin_unlock_irq(&phba->hbalock);
4969 /* Clear FCF rediscovery timer pending flag */
4970 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4971 /* FCF rediscovery event to worker thread */
4972 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4973 spin_unlock_irq(&phba->hbalock);
4974 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4975 "2776 FCF rediscover quiescent timer expired\n");
4976 /* wake up worker thread */
4977 lpfc_worker_wake_up(phba);
4981 * lpfc_vmid_poll - VMID timeout detection
4982 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
4984 * This routine is invoked when there is no I/O on by a VM for the specified
4985 * amount of time. When this situation is detected, the VMID has to be
4986 * deregistered from the switch and all the local resources freed. The VMID
4987 * will be reassigned to the VM once the I/O begins.
4990 lpfc_vmid_poll(struct timer_list *t)
4992 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
4995 /* check if there is a need to issue QFPA */
4996 if (phba->pport->vmid_priority_tagging) {
4998 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5001 /* Is the vmid inactivity timer enabled */
5002 if (phba->pport->vmid_inactivity_timeout ||
5003 phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
5005 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5009 lpfc_worker_wake_up(phba);
5011 /* restart the timer for the next iteration */
5012 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5017 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5018 * @phba: pointer to lpfc hba data structure.
5019 * @acqe_link: pointer to the async link completion queue entry.
5021 * This routine is to parse the SLI4 link-attention link fault code.
5024 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5025 struct lpfc_acqe_link *acqe_link)
5027 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5028 case LPFC_ASYNC_LINK_FAULT_NONE:
5029 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5030 case LPFC_ASYNC_LINK_FAULT_REMOTE:
5031 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
5034 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5035 "0398 Unknown link fault code: x%x\n",
5036 bf_get(lpfc_acqe_link_fault, acqe_link));
5042 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5043 * @phba: pointer to lpfc hba data structure.
5044 * @acqe_link: pointer to the async link completion queue entry.
5046 * This routine is to parse the SLI4 link attention type and translate it
5047 * into the base driver's link attention type coding.
5049 * Return: Link attention type in terms of base driver's coding.
5052 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5053 struct lpfc_acqe_link *acqe_link)
5057 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5058 case LPFC_ASYNC_LINK_STATUS_DOWN:
5059 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
5060 att_type = LPFC_ATT_LINK_DOWN;
5062 case LPFC_ASYNC_LINK_STATUS_UP:
5063 /* Ignore physical link up events - wait for logical link up */
5064 att_type = LPFC_ATT_RESERVED;
5066 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
5067 att_type = LPFC_ATT_LINK_UP;
5070 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5071 "0399 Invalid link attention type: x%x\n",
5072 bf_get(lpfc_acqe_link_status, acqe_link));
5073 att_type = LPFC_ATT_RESERVED;
5080 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5081 * @phba: pointer to lpfc hba data structure.
5083 * This routine is to get an SLI3 FC port's link speed in Mbps.
5085 * Return: link speed in terms of Mbps.
5088 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5090 uint32_t link_speed;
5092 if (!lpfc_is_link_up(phba))
5095 if (phba->sli_rev <= LPFC_SLI_REV3) {
5096 switch (phba->fc_linkspeed) {
5097 case LPFC_LINK_SPEED_1GHZ:
5100 case LPFC_LINK_SPEED_2GHZ:
5103 case LPFC_LINK_SPEED_4GHZ:
5106 case LPFC_LINK_SPEED_8GHZ:
5109 case LPFC_LINK_SPEED_10GHZ:
5112 case LPFC_LINK_SPEED_16GHZ:
5119 if (phba->sli4_hba.link_state.logical_speed)
5121 phba->sli4_hba.link_state.logical_speed;
5123 link_speed = phba->sli4_hba.link_state.speed;
5129 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5130 * @phba: pointer to lpfc hba data structure.
5131 * @evt_code: asynchronous event code.
5132 * @speed_code: asynchronous event link speed code.
5134 * This routine is to parse the giving SLI4 async event link speed code into
5135 * value of Mbps for the link speed.
5137 * Return: link speed in terms of Mbps.
5140 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5143 uint32_t port_speed;
5146 case LPFC_TRAILER_CODE_LINK:
5147 switch (speed_code) {
5148 case LPFC_ASYNC_LINK_SPEED_ZERO:
5151 case LPFC_ASYNC_LINK_SPEED_10MBPS:
5154 case LPFC_ASYNC_LINK_SPEED_100MBPS:
5157 case LPFC_ASYNC_LINK_SPEED_1GBPS:
5160 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5163 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5166 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5169 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5172 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5173 port_speed = 100000;
5179 case LPFC_TRAILER_CODE_FC:
5180 switch (speed_code) {
5181 case LPFC_FC_LA_SPEED_UNKNOWN:
5184 case LPFC_FC_LA_SPEED_1G:
5187 case LPFC_FC_LA_SPEED_2G:
5190 case LPFC_FC_LA_SPEED_4G:
5193 case LPFC_FC_LA_SPEED_8G:
5196 case LPFC_FC_LA_SPEED_10G:
5199 case LPFC_FC_LA_SPEED_16G:
5202 case LPFC_FC_LA_SPEED_32G:
5205 case LPFC_FC_LA_SPEED_64G:
5208 case LPFC_FC_LA_SPEED_128G:
5209 port_speed = 128000;
5211 case LPFC_FC_LA_SPEED_256G:
5212 port_speed = 256000;
5225 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
5226 * @phba: pointer to lpfc hba data structure.
5227 * @acqe_link: pointer to the async link completion queue entry.
5229 * This routine is to handle the SLI4 asynchronous FCoE link event.
5232 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5233 struct lpfc_acqe_link *acqe_link)
5235 struct lpfc_dmabuf *mp;
5238 struct lpfc_mbx_read_top *la;
5242 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
5243 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
5245 phba->fcoe_eventtag = acqe_link->event_tag;
5246 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5248 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5249 "0395 The mboxq allocation failed\n");
5252 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5254 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5255 "0396 The lpfc_dmabuf allocation failed\n");
5258 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5260 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5261 "0397 The mbuf allocation failed\n");
5262 goto out_free_dmabuf;
5265 /* Cleanup any outstanding ELS commands */
5266 lpfc_els_flush_all_cmd(phba);
5268 /* Block ELS IOCBs until we have done process link event */
5269 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5271 /* Update link event statistics */
5272 phba->sli.slistat.link_event++;
5274 /* Create lpfc_handle_latt mailbox command from link ACQE */
5275 lpfc_read_topology(phba, pmb, mp);
5276 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5277 pmb->vport = phba->pport;
5279 /* Keep the link status for extra SLI4 state machine reference */
5280 phba->sli4_hba.link_state.speed =
5281 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5282 bf_get(lpfc_acqe_link_speed, acqe_link));
5283 phba->sli4_hba.link_state.duplex =
5284 bf_get(lpfc_acqe_link_duplex, acqe_link);
5285 phba->sli4_hba.link_state.status =
5286 bf_get(lpfc_acqe_link_status, acqe_link);
5287 phba->sli4_hba.link_state.type =
5288 bf_get(lpfc_acqe_link_type, acqe_link);
5289 phba->sli4_hba.link_state.number =
5290 bf_get(lpfc_acqe_link_number, acqe_link);
5291 phba->sli4_hba.link_state.fault =
5292 bf_get(lpfc_acqe_link_fault, acqe_link);
5293 phba->sli4_hba.link_state.logical_speed =
5294 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5296 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5297 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5298 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5299 "Logical speed:%dMbps Fault:%d\n",
5300 phba->sli4_hba.link_state.speed,
5301 phba->sli4_hba.link_state.topology,
5302 phba->sli4_hba.link_state.status,
5303 phba->sli4_hba.link_state.type,
5304 phba->sli4_hba.link_state.number,
5305 phba->sli4_hba.link_state.logical_speed,
5306 phba->sli4_hba.link_state.fault);
5308 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5309 * topology info. Note: Optional for non FC-AL ports.
5311 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5312 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5313 if (rc == MBX_NOT_FINISHED)
5314 goto out_free_dmabuf;
5318 * For FCoE Mode: fill in all the topology information we need and call
5319 * the READ_TOPOLOGY completion routine to continue without actually
5320 * sending the READ_TOPOLOGY mailbox command to the port.
5322 /* Initialize completion status */
5324 mb->mbxStatus = MBX_SUCCESS;
5326 /* Parse port fault information field */
5327 lpfc_sli4_parse_latt_fault(phba, acqe_link);
5329 /* Parse and translate link attention fields */
5330 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5331 la->eventTag = acqe_link->event_tag;
5332 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5333 bf_set(lpfc_mbx_read_top_link_spd, la,
5334 (bf_get(lpfc_acqe_link_speed, acqe_link)));
5336 /* Fake the the following irrelvant fields */
5337 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5338 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5339 bf_set(lpfc_mbx_read_top_il, la, 0);
5340 bf_set(lpfc_mbx_read_top_pb, la, 0);
5341 bf_set(lpfc_mbx_read_top_fa, la, 0);
5342 bf_set(lpfc_mbx_read_top_mm, la, 0);
5344 /* Invoke the lpfc_handle_latt mailbox command callback function */
5345 lpfc_mbx_cmpl_read_topology(phba, pmb);
5352 mempool_free(pmb, phba->mbox_mem_pool);
5356 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5358 * @phba: pointer to lpfc hba data structure.
5359 * @speed_code: asynchronous event link speed code.
5361 * This routine is to parse the giving SLI4 async event link speed code into
5362 * value of Read topology link speed.
5364 * Return: link speed in terms of Read topology.
5367 lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5371 switch (speed_code) {
5372 case LPFC_FC_LA_SPEED_1G:
5373 port_speed = LPFC_LINK_SPEED_1GHZ;
5375 case LPFC_FC_LA_SPEED_2G:
5376 port_speed = LPFC_LINK_SPEED_2GHZ;
5378 case LPFC_FC_LA_SPEED_4G:
5379 port_speed = LPFC_LINK_SPEED_4GHZ;
5381 case LPFC_FC_LA_SPEED_8G:
5382 port_speed = LPFC_LINK_SPEED_8GHZ;
5384 case LPFC_FC_LA_SPEED_16G:
5385 port_speed = LPFC_LINK_SPEED_16GHZ;
5387 case LPFC_FC_LA_SPEED_32G:
5388 port_speed = LPFC_LINK_SPEED_32GHZ;
5390 case LPFC_FC_LA_SPEED_64G:
5391 port_speed = LPFC_LINK_SPEED_64GHZ;
5393 case LPFC_FC_LA_SPEED_128G:
5394 port_speed = LPFC_LINK_SPEED_128GHZ;
5396 case LPFC_FC_LA_SPEED_256G:
5397 port_speed = LPFC_LINK_SPEED_256GHZ;
5408 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5409 * @phba: The Hba for which this call is being executed.
5411 * The routine calculates the latency from the beginning of the CMF timer
5412 * interval to the current point in time. It is called from IO completion
5413 * when we exceed our Bandwidth limitation for the time interval.
5416 lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5418 struct timespec64 cmpl_time;
5421 ktime_get_real_ts64(&cmpl_time);
5423 /* This routine works on a ms granularity so sec and usec are
5424 * converted accordingly.
5426 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5427 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5430 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5431 msec = (cmpl_time.tv_sec -
5432 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5433 msec += ((cmpl_time.tv_nsec -
5434 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5436 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5438 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5439 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5446 * lpfc_cmf_timer - This is the timer function for one congestion
5448 * @timer: Pointer to the high resolution timer that expired
5450 static enum hrtimer_restart
5451 lpfc_cmf_timer(struct hrtimer *timer)
5453 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5456 uint64_t total, rcv, lat, mbpi;
5457 int timer_interval = LPFC_CMF_INTERVAL;
5458 struct lpfc_cgn_stat *cgs;
5461 /* Only restart the timer if congestion mgmt is on */
5462 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5463 !phba->cmf_latency.tv_sec) {
5464 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5465 "6224 CMF timer exit: %d %lld\n",
5466 phba->cmf_active_mode,
5467 (uint64_t)phba->cmf_latency.tv_sec);
5468 return HRTIMER_NORESTART;
5471 /* If pport is not ready yet, just exit and wait for
5472 * the next timer cycle to hit.
5477 /* Do not block SCSI IO while in the timer routine since
5478 * total_bytes will be cleared
5480 atomic_set(&phba->cmf_stop_io, 1);
5482 /* Immediately after we calculate the time since the last
5483 * timer interrupt, set the start time for the next
5486 ktime_get_real_ts64(&phba->cmf_latency);
5488 phba->cmf_link_byte_count =
5489 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
5491 /* Collect all the stats from the prior timer interval */
5496 for_each_present_cpu(cpu) {
5497 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
5498 total += atomic64_xchg(&cgs->total_bytes, 0);
5499 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
5500 lat += atomic64_xchg(&cgs->rx_latency, 0);
5501 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
5504 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
5505 * returned from the last CMF_SYNC_WQE issued, from
5506 * cmf_last_sync_bw. This will be the target BW for
5507 * this next timer interval.
5509 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
5510 phba->link_state != LPFC_LINK_DOWN &&
5511 phba->hba_flag & HBA_SETUP) {
5512 mbpi = phba->cmf_last_sync_bw;
5513 phba->cmf_last_sync_bw = 0;
5514 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total);
5516 /* For Monitor mode or link down we want mbpi
5517 * to be the full link speed
5519 mbpi = phba->cmf_link_byte_count;
5521 phba->cmf_timer_cnt++;
5524 /* Update congestion info buffer latency in us */
5525 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
5526 atomic64_add(lat, &phba->cgn_latency_evt);
5529 /* Calculate MBPI for the next timer interval */
5531 if (mbpi > phba->cmf_link_byte_count ||
5532 phba->cmf_active_mode == LPFC_CFG_MONITOR)
5533 mbpi = phba->cmf_link_byte_count;
5535 /* Change max_bytes_per_interval to what the prior
5536 * CMF_SYNC_WQE cmpl indicated.
5538 if (mbpi != phba->cmf_max_bytes_per_interval)
5539 phba->cmf_max_bytes_per_interval = mbpi;
5542 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
5543 /* If Monitor mode, check if we are oversubscribed
5544 * against the full line rate.
5546 if (mbpi && total > mbpi)
5547 atomic_inc(&phba->cgn_driver_evt_cnt);
5549 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
5551 /* Since total_bytes has already been zero'ed, its okay to unblock
5552 * after max_bytes_per_interval is setup.
5554 if (atomic_xchg(&phba->cmf_bw_wait, 0))
5555 queue_work(phba->wq, &phba->unblock_request_work);
5557 /* SCSI IO is now unblocked */
5558 atomic_set(&phba->cmf_stop_io, 0);
5561 hrtimer_forward_now(timer,
5562 ktime_set(0, timer_interval * NSEC_PER_MSEC));
5563 return HRTIMER_RESTART;
5566 #define trunk_link_status(__idx)\
5567 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5568 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5569 "Link up" : "Link down") : "NA"
5570 /* Did port __idx reported an error */
5571 #define trunk_port_fault(__idx)\
5572 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5573 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5576 lpfc_update_trunk_link_status(struct lpfc_hba *phba,
5577 struct lpfc_acqe_fc_la *acqe_fc)
5579 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
5580 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
5582 phba->sli4_hba.link_state.speed =
5583 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5584 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5586 phba->sli4_hba.link_state.logical_speed =
5587 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
5588 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5589 phba->fc_linkspeed =
5590 lpfc_async_link_speed_to_read_top(
5592 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5594 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
5595 phba->trunk_link.link0.state =
5596 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
5597 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5598 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
5600 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
5601 phba->trunk_link.link1.state =
5602 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
5603 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5604 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
5606 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
5607 phba->trunk_link.link2.state =
5608 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
5609 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5610 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
5612 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
5613 phba->trunk_link.link3.state =
5614 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
5615 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
5616 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
5619 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5620 "2910 Async FC Trunking Event - Speed:%d\n"
5621 "\tLogical speed:%d "
5622 "port0: %s port1: %s port2: %s port3: %s\n",
5623 phba->sli4_hba.link_state.speed,
5624 phba->sli4_hba.link_state.logical_speed,
5625 trunk_link_status(0), trunk_link_status(1),
5626 trunk_link_status(2), trunk_link_status(3));
5628 if (phba->cmf_active_mode != LPFC_CFG_OFF)
5629 lpfc_cmf_signal_init(phba);
5632 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5633 "3202 trunk error:0x%x (%s) seen on port0:%s "
5635 * SLI-4: We have only 0xA error codes
5636 * defined as of now. print an appropriate
5637 * message in case driver needs to be updated.
5639 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
5640 "UNDEFINED. update driver." : trunk_errmsg[err],
5641 trunk_port_fault(0), trunk_port_fault(1),
5642 trunk_port_fault(2), trunk_port_fault(3));
5647 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5648 * @phba: pointer to lpfc hba data structure.
5649 * @acqe_fc: pointer to the async fc completion queue entry.
5651 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5652 * that the event was received and then issue a read_topology mailbox command so
5653 * that the rest of the driver will treat it the same as SLI3.
5656 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
5658 struct lpfc_dmabuf *mp;
5661 struct lpfc_mbx_read_top *la;
5664 if (bf_get(lpfc_trailer_type, acqe_fc) !=
5665 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
5666 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5667 "2895 Non FC link Event detected.(%d)\n",
5668 bf_get(lpfc_trailer_type, acqe_fc));
5672 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5673 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
5674 lpfc_update_trunk_link_status(phba, acqe_fc);
5678 /* Keep the link status for extra SLI4 state machine reference */
5679 phba->sli4_hba.link_state.speed =
5680 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5681 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5682 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
5683 phba->sli4_hba.link_state.topology =
5684 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
5685 phba->sli4_hba.link_state.status =
5686 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
5687 phba->sli4_hba.link_state.type =
5688 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
5689 phba->sli4_hba.link_state.number =
5690 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
5691 phba->sli4_hba.link_state.fault =
5692 bf_get(lpfc_acqe_link_fault, acqe_fc);
5694 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5695 LPFC_FC_LA_TYPE_LINK_DOWN)
5696 phba->sli4_hba.link_state.logical_speed = 0;
5697 else if (!phba->sli4_hba.conf_trunk)
5698 phba->sli4_hba.link_state.logical_speed =
5699 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
5701 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5702 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5703 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5704 "%dMbps Fault:%d\n",
5705 phba->sli4_hba.link_state.speed,
5706 phba->sli4_hba.link_state.topology,
5707 phba->sli4_hba.link_state.status,
5708 phba->sli4_hba.link_state.type,
5709 phba->sli4_hba.link_state.number,
5710 phba->sli4_hba.link_state.logical_speed,
5711 phba->sli4_hba.link_state.fault);
5712 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5714 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5715 "2897 The mboxq allocation failed\n");
5718 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5720 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5721 "2898 The lpfc_dmabuf allocation failed\n");
5724 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5726 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5727 "2899 The mbuf allocation failed\n");
5728 goto out_free_dmabuf;
5731 /* Cleanup any outstanding ELS commands */
5732 lpfc_els_flush_all_cmd(phba);
5734 /* Block ELS IOCBs until we have done process link event */
5735 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
5737 /* Update link event statistics */
5738 phba->sli.slistat.link_event++;
5740 /* Create lpfc_handle_latt mailbox command from link ACQE */
5741 lpfc_read_topology(phba, pmb, mp);
5742 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5743 pmb->vport = phba->pport;
5745 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
5746 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
5748 switch (phba->sli4_hba.link_state.status) {
5749 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
5750 phba->link_flag |= LS_MDS_LINK_DOWN;
5752 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
5753 phba->link_flag |= LS_MDS_LOOPBACK;
5759 /* Initialize completion status */
5761 mb->mbxStatus = MBX_SUCCESS;
5763 /* Parse port fault information field */
5764 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
5766 /* Parse and translate link attention fields */
5767 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
5768 la->eventTag = acqe_fc->event_tag;
5770 if (phba->sli4_hba.link_state.status ==
5771 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
5772 bf_set(lpfc_mbx_read_top_att_type, la,
5773 LPFC_FC_LA_TYPE_UNEXP_WWPN);
5775 bf_set(lpfc_mbx_read_top_att_type, la,
5776 LPFC_FC_LA_TYPE_LINK_DOWN);
5778 /* Invoke the mailbox command callback function */
5779 lpfc_mbx_cmpl_read_topology(phba, pmb);
5784 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5785 if (rc == MBX_NOT_FINISHED)
5786 goto out_free_dmabuf;
5792 mempool_free(pmb, phba->mbox_mem_pool);
5796 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5797 * @phba: pointer to lpfc hba data structure.
5798 * @acqe_sli: pointer to the async SLI completion queue entry.
5800 * This routine is to handle the SLI4 asynchronous SLI events.
5803 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
5809 uint8_t operational = 0;
5810 struct temp_event temp_event_data;
5811 struct lpfc_acqe_misconfigured_event *misconfigured;
5812 struct lpfc_acqe_cgn_signal *cgn_signal;
5813 struct Scsi_Host *shost;
5814 struct lpfc_vport **vports;
5817 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
5819 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5820 "2901 Async SLI event - Type:%d, Event Data: x%08x "
5821 "x%08x x%08x x%08x\n", evt_type,
5822 acqe_sli->event_data1, acqe_sli->event_data2,
5823 acqe_sli->reserved, acqe_sli->trailer);
5825 port_name = phba->Port[0];
5826 if (port_name == 0x00)
5827 port_name = '?'; /* get port name is empty */
5830 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
5831 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5832 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
5833 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5835 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5836 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5837 acqe_sli->event_data1, port_name);
5839 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
5840 shost = lpfc_shost_from_vport(phba->pport);
5841 fc_host_post_vendor_event(shost, fc_get_event_number(),
5842 sizeof(temp_event_data),
5843 (char *)&temp_event_data,
5844 SCSI_NL_VID_TYPE_PCI
5845 | PCI_VENDOR_ID_EMULEX);
5847 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
5848 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5849 temp_event_data.event_code = LPFC_NORMAL_TEMP;
5850 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5852 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5853 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5854 acqe_sli->event_data1, port_name);
5856 shost = lpfc_shost_from_vport(phba->pport);
5857 fc_host_post_vendor_event(shost, fc_get_event_number(),
5858 sizeof(temp_event_data),
5859 (char *)&temp_event_data,
5860 SCSI_NL_VID_TYPE_PCI
5861 | PCI_VENDOR_ID_EMULEX);
5863 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
5864 misconfigured = (struct lpfc_acqe_misconfigured_event *)
5865 &acqe_sli->event_data1;
5867 /* fetch the status for this port */
5868 switch (phba->sli4_hba.lnk_info.lnk_no) {
5869 case LPFC_LINK_NUMBER_0:
5870 status = bf_get(lpfc_sli_misconfigured_port0_state,
5871 &misconfigured->theEvent);
5872 operational = bf_get(lpfc_sli_misconfigured_port0_op,
5873 &misconfigured->theEvent);
5875 case LPFC_LINK_NUMBER_1:
5876 status = bf_get(lpfc_sli_misconfigured_port1_state,
5877 &misconfigured->theEvent);
5878 operational = bf_get(lpfc_sli_misconfigured_port1_op,
5879 &misconfigured->theEvent);
5881 case LPFC_LINK_NUMBER_2:
5882 status = bf_get(lpfc_sli_misconfigured_port2_state,
5883 &misconfigured->theEvent);
5884 operational = bf_get(lpfc_sli_misconfigured_port2_op,
5885 &misconfigured->theEvent);
5887 case LPFC_LINK_NUMBER_3:
5888 status = bf_get(lpfc_sli_misconfigured_port3_state,
5889 &misconfigured->theEvent);
5890 operational = bf_get(lpfc_sli_misconfigured_port3_op,
5891 &misconfigured->theEvent);
5894 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5896 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5897 "event: Invalid link %d",
5898 phba->sli4_hba.lnk_info.lnk_no);
5902 /* Skip if optic state unchanged */
5903 if (phba->sli4_hba.lnk_info.optic_state == status)
5907 case LPFC_SLI_EVENT_STATUS_VALID:
5908 sprintf(message, "Physical Link is functional");
5910 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5911 sprintf(message, "Optics faulted/incorrectly "
5912 "installed/not installed - Reseat optics, "
5913 "if issue not resolved, replace.");
5915 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5917 "Optics of two types installed - Remove one "
5918 "optic or install matching pair of optics.");
5920 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5921 sprintf(message, "Incompatible optics - Replace with "
5922 "compatible optics for card to function.");
5924 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5925 sprintf(message, "Unqualified optics - Replace with "
5926 "Avago optics for Warranty and Technical "
5927 "Support - Link is%s operational",
5928 (operational) ? " not" : "");
5930 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5931 sprintf(message, "Uncertified optics - Replace with "
5932 "Avago-certified optics to enable link "
5933 "operation - Link is%s operational",
5934 (operational) ? " not" : "");
5937 /* firmware is reporting a status we don't know about */
5938 sprintf(message, "Unknown event status x%02x", status);
5942 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5943 rc = lpfc_sli4_read_config(phba);
5946 lpfc_printf_log(phba, KERN_ERR,
5948 "3194 Unable to retrieve supported "
5949 "speeds, rc = 0x%x\n", rc);
5951 vports = lpfc_create_vport_work_array(phba);
5952 if (vports != NULL) {
5953 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5955 shost = lpfc_shost_from_vport(vports[i]);
5956 lpfc_host_supported_speeds_set(shost);
5959 lpfc_destroy_vport_work_array(phba, vports);
5961 phba->sli4_hba.lnk_info.optic_state = status;
5962 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5963 "3176 Port Name %c %s\n", port_name, message);
5965 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5966 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5967 "3192 Remote DPort Test Initiated - "
5968 "Event Data1:x%08x Event Data2: x%08x\n",
5969 acqe_sli->event_data1, acqe_sli->event_data2);
5971 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
5972 /* Call FW to obtain active parms */
5973 lpfc_sli4_cgn_parm_chg_evt(phba);
5975 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
5976 /* Misconfigured WWN. Reports that the SLI Port is configured
5977 * to use FA-WWN, but the attached device doesn’t support it.
5978 * No driver action is required.
5979 * Event Data1 - N.A, Event Data2 - N.A
5981 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI,
5982 "2699 Misconfigured FA-WWN - Attached device does "
5983 "not support FA-WWN\n");
5985 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
5986 /* EEPROM failure. No driver action is required */
5987 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5988 "2518 EEPROM failure - "
5989 "Event Data1: x%08x Event Data2: x%08x\n",
5990 acqe_sli->event_data1, acqe_sli->event_data2);
5992 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
5993 if (phba->cmf_active_mode == LPFC_CFG_OFF)
5995 cgn_signal = (struct lpfc_acqe_cgn_signal *)
5996 &acqe_sli->event_data1;
5997 phba->cgn_acqe_cnt++;
5999 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6000 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6001 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6003 /* no threshold for CMF, even 1 signal will trigger an event */
6005 /* Alarm overrides warning, so check that first */
6006 if (cgn_signal->alarm_cnt) {
6007 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6008 /* Keep track of alarm cnt for cgn_info */
6009 atomic_add(cgn_signal->alarm_cnt,
6010 &phba->cgn_fabric_alarm_cnt);
6011 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6012 atomic_add(cgn_signal->alarm_cnt,
6013 &phba->cgn_sync_alarm_cnt);
6016 /* signal action needs to be taken */
6017 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6018 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6019 /* Keep track of warning cnt for cgn_info */
6020 atomic_add(cnt, &phba->cgn_fabric_warn_cnt);
6021 /* Keep track of warning cnt for CMF_SYNC_WQE */
6022 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6027 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6028 "3193 Unrecognized SLI event, type: 0x%x",
6035 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6036 * @vport: pointer to vport data structure.
6038 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6039 * response to a CVL event.
6041 * Return the pointer to the ndlp with the vport if successful, otherwise
6044 static struct lpfc_nodelist *
6045 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6047 struct lpfc_nodelist *ndlp;
6048 struct Scsi_Host *shost;
6049 struct lpfc_hba *phba;
6056 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6058 /* Cannot find existing Fabric ndlp, so allocate a new one */
6059 ndlp = lpfc_nlp_init(vport, Fabric_DID);
6062 /* Set the node type */
6063 ndlp->nlp_type |= NLP_FABRIC;
6064 /* Put ndlp onto node list */
6065 lpfc_enqueue_node(vport, ndlp);
6067 if ((phba->pport->port_state < LPFC_FLOGI) &&
6068 (phba->pport->port_state != LPFC_VPORT_FAILED))
6070 /* If virtual link is not yet instantiated ignore CVL */
6071 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6072 && (vport->port_state != LPFC_VPORT_FAILED))
6074 shost = lpfc_shost_from_vport(vport);
6077 lpfc_linkdown_port(vport);
6078 lpfc_cleanup_pending_mbox(vport);
6079 spin_lock_irq(shost->host_lock);
6080 vport->fc_flag |= FC_VPORT_CVL_RCVD;
6081 spin_unlock_irq(shost->host_lock);
6087 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
6088 * @phba: pointer to lpfc hba data structure.
6090 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6091 * response to a FCF dead event.
6094 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6096 struct lpfc_vport **vports;
6099 vports = lpfc_create_vport_work_array(phba);
6101 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6102 lpfc_sli4_perform_vport_cvl(vports[i]);
6103 lpfc_destroy_vport_work_array(phba, vports);
6107 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
6108 * @phba: pointer to lpfc hba data structure.
6109 * @acqe_fip: pointer to the async fcoe completion queue entry.
6111 * This routine is to handle the SLI4 asynchronous fcoe event.
6114 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
6115 struct lpfc_acqe_fip *acqe_fip)
6117 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
6119 struct lpfc_vport *vport;
6120 struct lpfc_nodelist *ndlp;
6121 int active_vlink_present;
6122 struct lpfc_vport **vports;
6125 phba->fc_eventTag = acqe_fip->event_tag;
6126 phba->fcoe_eventtag = acqe_fip->event_tag;
6127 switch (event_type) {
6128 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6129 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6130 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
6131 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6132 "2546 New FCF event, evt_tag:x%x, "
6134 acqe_fip->event_tag,
6137 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6139 "2788 FCF param modified event, "
6140 "evt_tag:x%x, index:x%x\n",
6141 acqe_fip->event_tag,
6143 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6145 * During period of FCF discovery, read the FCF
6146 * table record indexed by the event to update
6147 * FCF roundrobin failover eligible FCF bmask.
6149 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6151 "2779 Read FCF (x%x) for updating "
6152 "roundrobin FCF failover bmask\n",
6154 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
6157 /* If the FCF discovery is in progress, do nothing. */
6158 spin_lock_irq(&phba->hbalock);
6159 if (phba->hba_flag & FCF_TS_INPROG) {
6160 spin_unlock_irq(&phba->hbalock);
6163 /* If fast FCF failover rescan event is pending, do nothing */
6164 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
6165 spin_unlock_irq(&phba->hbalock);
6169 /* If the FCF has been in discovered state, do nothing. */
6170 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
6171 spin_unlock_irq(&phba->hbalock);
6174 spin_unlock_irq(&phba->hbalock);
6176 /* Otherwise, scan the entire FCF table and re-discover SAN */
6177 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6178 "2770 Start FCF table scan per async FCF "
6179 "event, evt_tag:x%x, index:x%x\n",
6180 acqe_fip->event_tag, acqe_fip->index);
6181 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6182 LPFC_FCOE_FCF_GET_FIRST);
6184 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6185 "2547 Issue FCF scan read FCF mailbox "
6186 "command failed (x%x)\n", rc);
6189 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
6190 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6191 "2548 FCF Table full count 0x%x tag 0x%x\n",
6192 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6193 acqe_fip->event_tag);
6196 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
6197 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6198 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6199 "2549 FCF (x%x) disconnected from network, "
6200 "tag:x%x\n", acqe_fip->index,
6201 acqe_fip->event_tag);
6203 * If we are in the middle of FCF failover process, clear
6204 * the corresponding FCF bit in the roundrobin bitmap.
6206 spin_lock_irq(&phba->hbalock);
6207 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6208 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
6209 spin_unlock_irq(&phba->hbalock);
6210 /* Update FLOGI FCF failover eligible FCF bmask */
6211 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
6214 spin_unlock_irq(&phba->hbalock);
6216 /* If the event is not for currently used fcf do nothing */
6217 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
6221 * Otherwise, request the port to rediscover the entire FCF
6222 * table for a fast recovery from case that the current FCF
6223 * is no longer valid as we are not in the middle of FCF
6224 * failover process already.
6226 spin_lock_irq(&phba->hbalock);
6227 /* Mark the fast failover process in progress */
6228 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6229 spin_unlock_irq(&phba->hbalock);
6231 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6232 "2771 Start FCF fast failover process due to "
6233 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6234 "\n", acqe_fip->event_tag, acqe_fip->index);
6235 rc = lpfc_sli4_redisc_fcf_table(phba);
6237 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6239 "2772 Issue FCF rediscover mailbox "
6240 "command failed, fail through to FCF "
6242 spin_lock_irq(&phba->hbalock);
6243 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6244 spin_unlock_irq(&phba->hbalock);
6246 * Last resort will fail over by treating this
6247 * as a link down to FCF registration.
6249 lpfc_sli4_fcf_dead_failthrough(phba);
6251 /* Reset FCF roundrobin bmask for new discovery */
6252 lpfc_sli4_clear_fcf_rr_bmask(phba);
6254 * Handling fast FCF failover to a DEAD FCF event is
6255 * considered equalivant to receiving CVL to all vports.
6257 lpfc_sli4_perform_all_vport_cvl(phba);
6260 case LPFC_FIP_EVENT_TYPE_CVL:
6261 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
6262 lpfc_printf_log(phba, KERN_ERR,
6264 "2718 Clear Virtual Link Received for VPI 0x%x"
6265 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
6267 vport = lpfc_find_vport_by_vpid(phba,
6269 ndlp = lpfc_sli4_perform_vport_cvl(vport);
6272 active_vlink_present = 0;
6274 vports = lpfc_create_vport_work_array(phba);
6276 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6278 if ((!(vports[i]->fc_flag &
6279 FC_VPORT_CVL_RCVD)) &&
6280 (vports[i]->port_state > LPFC_FDISC)) {
6281 active_vlink_present = 1;
6285 lpfc_destroy_vport_work_array(phba, vports);
6289 * Don't re-instantiate if vport is marked for deletion.
6290 * If we are here first then vport_delete is going to wait
6291 * for discovery to complete.
6293 if (!(vport->load_flag & FC_UNLOADING) &&
6294 active_vlink_present) {
6296 * If there are other active VLinks present,
6297 * re-instantiate the Vlink using FDISC.
6299 mod_timer(&ndlp->nlp_delayfunc,
6300 jiffies + msecs_to_jiffies(1000));
6301 spin_lock_irq(&ndlp->lock);
6302 ndlp->nlp_flag |= NLP_DELAY_TMO;
6303 spin_unlock_irq(&ndlp->lock);
6304 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6305 vport->port_state = LPFC_FDISC;
6308 * Otherwise, we request port to rediscover
6309 * the entire FCF table for a fast recovery
6310 * from possible case that the current FCF
6311 * is no longer valid if we are not already
6312 * in the FCF failover process.
6314 spin_lock_irq(&phba->hbalock);
6315 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
6316 spin_unlock_irq(&phba->hbalock);
6319 /* Mark the fast failover process in progress */
6320 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
6321 spin_unlock_irq(&phba->hbalock);
6322 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6324 "2773 Start FCF failover per CVL, "
6325 "evt_tag:x%x\n", acqe_fip->event_tag);
6326 rc = lpfc_sli4_redisc_fcf_table(phba);
6328 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
6330 "2774 Issue FCF rediscover "
6331 "mailbox command failed, "
6332 "through to CVL event\n");
6333 spin_lock_irq(&phba->hbalock);
6334 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
6335 spin_unlock_irq(&phba->hbalock);
6337 * Last resort will be re-try on the
6338 * the current registered FCF entry.
6340 lpfc_retry_pport_discovery(phba);
6343 * Reset FCF roundrobin bmask for new
6346 lpfc_sli4_clear_fcf_rr_bmask(phba);
6350 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6351 "0288 Unknown FCoE event type 0x%x event tag "
6352 "0x%x\n", event_type, acqe_fip->event_tag);
6358 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
6359 * @phba: pointer to lpfc hba data structure.
6360 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
6362 * This routine is to handle the SLI4 asynchronous dcbx event.
6365 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
6366 struct lpfc_acqe_dcbx *acqe_dcbx)
6368 phba->fc_eventTag = acqe_dcbx->event_tag;
6369 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6370 "0290 The SLI4 DCBX asynchronous event is not "
6375 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
6376 * @phba: pointer to lpfc hba data structure.
6377 * @acqe_grp5: pointer to the async grp5 completion queue entry.
6379 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
6380 * is an asynchronous notified of a logical link speed change. The Port
6381 * reports the logical link speed in units of 10Mbps.
6384 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
6385 struct lpfc_acqe_grp5 *acqe_grp5)
6387 uint16_t prev_ll_spd;
6389 phba->fc_eventTag = acqe_grp5->event_tag;
6390 phba->fcoe_eventtag = acqe_grp5->event_tag;
6391 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
6392 phba->sli4_hba.link_state.logical_speed =
6393 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
6394 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6395 "2789 GRP5 Async Event: Updating logical link speed "
6396 "from %dMbps to %dMbps\n", prev_ll_spd,
6397 phba->sli4_hba.link_state.logical_speed);
6401 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
6402 * @phba: pointer to lpfc hba data structure.
6404 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
6405 * is an asynchronous notification of a request to reset CM stats.
6408 lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
6412 lpfc_init_congestion_stat(phba);
6416 * lpfc_cgn_params_val - Validate FW congestion parameters.
6417 * @phba: pointer to lpfc hba data structure.
6418 * @p_cfg_param: pointer to FW provided congestion parameters.
6420 * This routine validates the congestion parameters passed
6421 * by the FW to the driver via an ACQE event.
6424 lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
6426 spin_lock_irq(&phba->hbalock);
6428 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
6429 LPFC_CFG_MONITOR)) {
6430 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
6431 "6225 CMF mode param out of range: %d\n",
6432 p_cfg_param->cgn_param_mode);
6433 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
6436 spin_unlock_irq(&phba->hbalock);
6440 * lpfc_cgn_params_parse - Process a FW cong parm change event
6441 * @phba: pointer to lpfc hba data structure.
6442 * @p_cgn_param: pointer to a data buffer with the FW cong params.
6443 * @len: the size of pdata in bytes.
6445 * This routine validates the congestion management buffer signature
6446 * from the FW, validates the contents and makes corrections for
6447 * valid, in-range values. If the signature magic is correct and
6448 * after parameter validation, the contents are copied to the driver's
6449 * @phba structure. If the magic is incorrect, an error message is
6453 lpfc_cgn_params_parse(struct lpfc_hba *phba,
6454 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
6458 /* Make sure the FW has encoded the correct magic number to
6459 * validate the congestion parameter in FW memory.
6461 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
6462 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
6463 "4668 FW cgn parm buffer data: "
6464 "magic 0x%x version %d mode %d "
6465 "level0 %d level1 %d "
6466 "level2 %d byte13 %d "
6467 "byte14 %d byte15 %d "
6468 "byte11 %d byte12 %d activeMode %d\n",
6469 p_cgn_param->cgn_param_magic,
6470 p_cgn_param->cgn_param_version,
6471 p_cgn_param->cgn_param_mode,
6472 p_cgn_param->cgn_param_level0,
6473 p_cgn_param->cgn_param_level1,
6474 p_cgn_param->cgn_param_level2,
6475 p_cgn_param->byte13,
6476 p_cgn_param->byte14,
6477 p_cgn_param->byte15,
6478 p_cgn_param->byte11,
6479 p_cgn_param->byte12,
6480 phba->cmf_active_mode);
6482 oldmode = phba->cmf_active_mode;
6484 /* Any parameters out of range are corrected to defaults
6485 * by this routine. No need to fail.
6487 lpfc_cgn_params_val(phba, p_cgn_param);
6489 /* Parameters are verified, move them into driver storage */
6490 spin_lock_irq(&phba->hbalock);
6491 memcpy(&phba->cgn_p, p_cgn_param,
6492 sizeof(struct lpfc_cgn_param));
6494 spin_unlock_irq(&phba->hbalock);
6496 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
6500 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
6501 /* Turning CMF on */
6502 lpfc_cmf_start(phba);
6504 if (phba->link_state >= LPFC_LINK_UP) {
6505 phba->cgn_reg_fpin =
6506 phba->cgn_init_reg_fpin;
6507 phba->cgn_reg_signal =
6508 phba->cgn_init_reg_signal;
6509 lpfc_issue_els_edc(phba->pport, 0);
6513 case LPFC_CFG_MANAGED:
6514 switch (phba->cgn_p.cgn_param_mode) {
6516 /* Turning CMF off */
6517 lpfc_cmf_stop(phba);
6518 if (phba->link_state >= LPFC_LINK_UP)
6519 lpfc_issue_els_edc(phba->pport, 0);
6521 case LPFC_CFG_MONITOR:
6522 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
6523 "4661 Switch from MANAGED to "
6525 phba->cmf_max_bytes_per_interval =
6526 phba->cmf_link_byte_count;
6528 /* Resume blocked IO - unblock on workqueue */
6529 queue_work(phba->wq,
6530 &phba->unblock_request_work);
6534 case LPFC_CFG_MONITOR:
6535 switch (phba->cgn_p.cgn_param_mode) {
6537 /* Turning CMF off */
6538 lpfc_cmf_stop(phba);
6539 if (phba->link_state >= LPFC_LINK_UP)
6540 lpfc_issue_els_edc(phba->pport, 0);
6542 case LPFC_CFG_MANAGED:
6543 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
6544 "4662 Switch from MONITOR to "
6546 lpfc_cmf_signal_init(phba);
6552 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
6553 "4669 FW cgn parm buf wrong magic 0x%x "
6554 "version %d\n", p_cgn_param->cgn_param_magic,
6555 p_cgn_param->cgn_param_version);
6560 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
6561 * @phba: pointer to lpfc hba data structure.
6563 * This routine issues a read_object mailbox command to
6564 * get the congestion management parameters from the FW
6565 * parses it and updates the driver maintained values.
6568 * 0 if the object was empty
6569 * -Eval if an error was encountered
6570 * Count if bytes were read from object
6573 lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
6576 struct lpfc_cgn_param *p_cgn_param = NULL;
6580 /* Find out if the FW has a new set of congestion parameters. */
6581 len = sizeof(struct lpfc_cgn_param);
6582 pdata = kzalloc(len, GFP_KERNEL);
6583 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
6586 /* 0 means no data. A negative means error. A positive means
6587 * bytes were copied.
6590 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
6591 "4670 CGN RD OBJ returns no data\n");
6593 } else if (ret < 0) {
6594 /* Some error. Just exit and return it to the caller.*/
6598 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
6599 "6234 READ CGN PARAMS Successful %d\n", len);
6601 /* Parse data pointer over len and update the phba congestion
6602 * parameters with values passed back. The receive rate values
6603 * may have been altered in FW, but take no action here.
6605 p_cgn_param = (struct lpfc_cgn_param *)pdata;
6606 lpfc_cgn_params_parse(phba, p_cgn_param, len);
6614 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
6615 * @phba: pointer to lpfc hba data structure.
6617 * The FW generated Async ACQE SLI event calls this routine when
6618 * the event type is an SLI Internal Port Event and the Event Code
6619 * indicates a change to the FW maintained congestion parameters.
6621 * This routine executes a Read_Object mailbox call to obtain the
6622 * current congestion parameters maintained in FW and corrects
6623 * the driver's active congestion parameters.
6625 * The acqe event is not passed because there is no further data
6628 * Returns nonzero error if event processing encountered an error.
6629 * Zero otherwise for success.
6632 lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
6636 if (!phba->sli4_hba.pc_sli4_params.cmf) {
6637 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
6638 "4664 Cgn Evt when E2E off. Drop event\n");
6642 /* If the event is claiming an empty object, it's ok. A write
6643 * could have cleared it. Only error is a negative return
6646 ret = lpfc_sli4_cgn_params_read(phba);
6648 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
6649 "4667 Error reading Cgn Params (%d)\n",
6652 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
6653 "4673 CGN Event empty object.\n");
6659 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
6660 * @phba: pointer to lpfc hba data structure.
6662 * This routine is invoked by the worker thread to process all the pending
6663 * SLI4 asynchronous events.
6665 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
6667 struct lpfc_cq_event *cq_event;
6668 unsigned long iflags;
6670 /* First, declare the async event has been handled */
6671 spin_lock_irqsave(&phba->hbalock, iflags);
6672 phba->hba_flag &= ~ASYNC_EVENT;
6673 spin_unlock_irqrestore(&phba->hbalock, iflags);
6675 /* Now, handle all the async events */
6676 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
6677 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
6678 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
6679 cq_event, struct lpfc_cq_event, list);
6680 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
6683 /* Process the asynchronous event */
6684 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
6685 case LPFC_TRAILER_CODE_LINK:
6686 lpfc_sli4_async_link_evt(phba,
6687 &cq_event->cqe.acqe_link);
6689 case LPFC_TRAILER_CODE_FCOE:
6690 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
6692 case LPFC_TRAILER_CODE_DCBX:
6693 lpfc_sli4_async_dcbx_evt(phba,
6694 &cq_event->cqe.acqe_dcbx);
6696 case LPFC_TRAILER_CODE_GRP5:
6697 lpfc_sli4_async_grp5_evt(phba,
6698 &cq_event->cqe.acqe_grp5);
6700 case LPFC_TRAILER_CODE_FC:
6701 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
6703 case LPFC_TRAILER_CODE_SLI:
6704 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
6706 case LPFC_TRAILER_CODE_CMSTAT:
6707 lpfc_sli4_async_cmstat_evt(phba);
6710 lpfc_printf_log(phba, KERN_ERR,
6712 "1804 Invalid asynchronous event code: "
6713 "x%x\n", bf_get(lpfc_trailer_code,
6714 &cq_event->cqe.mcqe_cmpl));
6718 /* Free the completion event processed to the free pool */
6719 lpfc_sli4_cq_event_release(phba, cq_event);
6720 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
6722 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
6726 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
6727 * @phba: pointer to lpfc hba data structure.
6729 * This routine is invoked by the worker thread to process FCF table
6730 * rediscovery pending completion event.
6732 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
6736 spin_lock_irq(&phba->hbalock);
6737 /* Clear FCF rediscovery timeout event */
6738 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
6739 /* Clear driver fast failover FCF record flag */
6740 phba->fcf.failover_rec.flag = 0;
6741 /* Set state for FCF fast failover */
6742 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
6743 spin_unlock_irq(&phba->hbalock);
6745 /* Scan FCF table from the first entry to re-discover SAN */
6746 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6747 "2777 Start post-quiescent FCF table scan\n");
6748 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6750 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6751 "2747 Issue FCF scan read FCF mailbox "
6752 "command failed 0x%x\n", rc);
6756 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
6757 * @phba: pointer to lpfc hba data structure.
6758 * @dev_grp: The HBA PCI-Device group number.
6760 * This routine is invoked to set up the per HBA PCI-Device group function
6761 * API jump table entries.
6763 * Return: 0 if success, otherwise -ENODEV
6766 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6770 /* Set up lpfc PCI-device group */
6771 phba->pci_dev_grp = dev_grp;
6773 /* The LPFC_PCI_DEV_OC uses SLI4 */
6774 if (dev_grp == LPFC_PCI_DEV_OC)
6775 phba->sli_rev = LPFC_SLI_REV4;
6777 /* Set up device INIT API function jump table */
6778 rc = lpfc_init_api_table_setup(phba, dev_grp);
6781 /* Set up SCSI API function jump table */
6782 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
6785 /* Set up SLI API function jump table */
6786 rc = lpfc_sli_api_table_setup(phba, dev_grp);
6789 /* Set up MBOX API function jump table */
6790 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
6798 * lpfc_log_intr_mode - Log the active interrupt mode
6799 * @phba: pointer to lpfc hba data structure.
6800 * @intr_mode: active interrupt mode adopted.
6802 * This routine it invoked to log the currently used active interrupt mode
6805 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
6807 switch (intr_mode) {
6809 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6810 "0470 Enable INTx interrupt mode.\n");
6813 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6814 "0481 Enabled MSI interrupt mode.\n");
6817 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6818 "0480 Enabled MSI-X interrupt mode.\n");
6821 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6822 "0482 Illegal interrupt mode.\n");
6829 * lpfc_enable_pci_dev - Enable a generic PCI device.
6830 * @phba: pointer to lpfc hba data structure.
6832 * This routine is invoked to enable the PCI device that is common to all
6837 * other values - error
6840 lpfc_enable_pci_dev(struct lpfc_hba *phba)
6842 struct pci_dev *pdev;
6844 /* Obtain PCI device reference */
6848 pdev = phba->pcidev;
6849 /* Enable PCI device */
6850 if (pci_enable_device_mem(pdev))
6852 /* Request PCI resource for the device */
6853 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
6854 goto out_disable_device;
6855 /* Set up device as PCI master and save state for EEH */
6856 pci_set_master(pdev);
6857 pci_try_set_mwi(pdev);
6858 pci_save_state(pdev);
6860 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
6861 if (pci_is_pcie(pdev))
6862 pdev->needs_freset = 1;
6867 pci_disable_device(pdev);
6869 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6870 "1401 Failed to enable pci device\n");
6875 * lpfc_disable_pci_dev - Disable a generic PCI device.
6876 * @phba: pointer to lpfc hba data structure.
6878 * This routine is invoked to disable the PCI device that is common to all
6882 lpfc_disable_pci_dev(struct lpfc_hba *phba)
6884 struct pci_dev *pdev;
6886 /* Obtain PCI device reference */
6890 pdev = phba->pcidev;
6891 /* Release PCI resource and disable PCI device */
6892 pci_release_mem_regions(pdev);
6893 pci_disable_device(pdev);
6899 * lpfc_reset_hba - Reset a hba
6900 * @phba: pointer to lpfc hba data structure.
6902 * This routine is invoked to reset a hba device. It brings the HBA
6903 * offline, performs a board restart, and then brings the board back
6904 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6905 * on outstanding mailbox commands.
6908 lpfc_reset_hba(struct lpfc_hba *phba)
6910 /* If resets are disabled then set error state and return. */
6911 if (!phba->cfg_enable_hba_reset) {
6912 phba->link_state = LPFC_HBA_ERROR;
6916 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
6917 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
6918 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6920 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
6921 lpfc_sli_flush_io_rings(phba);
6924 lpfc_sli_brdrestart(phba);
6926 lpfc_unblock_mgmt_io(phba);
6930 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6931 * @phba: pointer to lpfc hba data structure.
6933 * This function enables the PCI SR-IOV virtual functions to a physical
6934 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6935 * enable the number of virtual functions to the physical function. As
6936 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6937 * API call does not considered as an error condition for most of the device.
6940 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
6942 struct pci_dev *pdev = phba->pcidev;
6946 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6950 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
6955 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6956 * @phba: pointer to lpfc hba data structure.
6957 * @nr_vfn: number of virtual functions to be enabled.
6959 * This function enables the PCI SR-IOV virtual functions to a physical
6960 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6961 * enable the number of virtual functions to the physical function. As
6962 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6963 * API call does not considered as an error condition for most of the device.
6966 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
6968 struct pci_dev *pdev = phba->pcidev;
6969 uint16_t max_nr_vfn;
6972 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
6973 if (nr_vfn > max_nr_vfn) {
6974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6975 "3057 Requested vfs (%d) greater than "
6976 "supported vfs (%d)", nr_vfn, max_nr_vfn);
6980 rc = pci_enable_sriov(pdev, nr_vfn);
6982 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6983 "2806 Failed to enable sriov on this device "
6984 "with vfn number nr_vf:%d, rc:%d\n",
6987 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6988 "2807 Successful enable sriov on this device "
6989 "with vfn number nr_vf:%d\n", nr_vfn);
6994 lpfc_unblock_requests_work(struct work_struct *work)
6996 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
6997 unblock_request_work);
6999 lpfc_unblock_requests(phba);
7003 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
7004 * @phba: pointer to lpfc hba data structure.
7006 * This routine is invoked to set up the driver internal resources before the
7007 * device specific resource setup to support the HBA device it attached to.
7011 * other values - error
7014 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
7016 struct lpfc_sli *psli = &phba->sli;
7019 * Driver resources common to all SLI revisions
7021 atomic_set(&phba->fast_event_count, 0);
7022 atomic_set(&phba->dbg_log_idx, 0);
7023 atomic_set(&phba->dbg_log_cnt, 0);
7024 atomic_set(&phba->dbg_log_dmping, 0);
7025 spin_lock_init(&phba->hbalock);
7027 /* Initialize port_list spinlock */
7028 spin_lock_init(&phba->port_list_lock);
7029 INIT_LIST_HEAD(&phba->port_list);
7031 INIT_LIST_HEAD(&phba->work_list);
7032 init_waitqueue_head(&phba->wait_4_mlo_m_q);
7034 /* Initialize the wait queue head for the kernel thread */
7035 init_waitqueue_head(&phba->work_waitq);
7037 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7038 "1403 Protocols supported %s %s %s\n",
7039 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7041 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
7043 (phba->nvmet_support ? "NVMET" : " "));
7045 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7046 spin_lock_init(&phba->scsi_buf_list_get_lock);
7047 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7048 spin_lock_init(&phba->scsi_buf_list_put_lock);
7049 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
7051 /* Initialize the fabric iocb list */
7052 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7054 /* Initialize list to save ELS buffers */
7055 INIT_LIST_HEAD(&phba->elsbuf);
7057 /* Initialize FCF connection rec list */
7058 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7060 /* Initialize OAS configuration list */
7061 spin_lock_init(&phba->devicelock);
7062 INIT_LIST_HEAD(&phba->luns);
7064 /* MBOX heartbeat timer */
7065 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
7066 /* Fabric block timer */
7067 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
7068 /* EA polling mode timer */
7069 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
7070 /* Heartbeat timer */
7071 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
7073 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7075 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7076 lpfc_idle_stat_delay_work);
7077 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
7082 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7083 * @phba: pointer to lpfc hba data structure.
7085 * This routine is invoked to set up the driver internal resources specific to
7086 * support the SLI-3 HBA device it attached to.
7090 * other values - error
7093 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7098 * Initialize timers used by driver
7101 /* FCP polling mode timer */
7102 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
7104 /* Host attention work mask setup */
7105 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7106 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7108 /* Get all the module params for configuring this host */
7109 lpfc_get_cfgparam(phba);
7110 /* Set up phase-1 common device driver resources */
7112 rc = lpfc_setup_driver_resource_phase1(phba);
7116 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
7117 phba->menlo_flag |= HBA_MENLO_SUPPORT;
7118 /* check for menlo minimum sg count */
7119 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
7120 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
7123 if (!phba->sli.sli3_ring)
7124 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7125 sizeof(struct lpfc_sli_ring),
7127 if (!phba->sli.sli3_ring)
7131 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
7132 * used to create the sg_dma_buf_pool must be dynamically calculated.
7135 if (phba->sli_rev == LPFC_SLI_REV4)
7136 entry_sz = sizeof(struct sli4_sge);
7138 entry_sz = sizeof(struct ulp_bde64);
7140 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7141 if (phba->cfg_enable_bg) {
7143 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7144 * the FCP rsp, and a BDE for each. Sice we have no control
7145 * over how many protection data segments the SCSI Layer
7146 * will hand us (ie: there could be one for every block
7147 * in the IO), we just allocate enough BDEs to accomidate
7148 * our max amount and we need to limit lpfc_sg_seg_cnt to
7149 * minimize the risk of running out.
7151 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7152 sizeof(struct fcp_rsp) +
7153 (LPFC_MAX_SG_SEG_CNT * entry_sz);
7155 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7156 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7158 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7159 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7162 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7163 * the FCP rsp, a BDE for each, and a BDE for up to
7164 * cfg_sg_seg_cnt data segments.
7166 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7167 sizeof(struct fcp_rsp) +
7168 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
7170 /* Total BDEs in BPL for scsi_sg_list */
7171 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7174 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7175 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
7176 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7177 phba->cfg_total_seg_cnt);
7179 phba->max_vpi = LPFC_MAX_VPI;
7180 /* This will be set to correct value after config_port mbox */
7181 phba->max_vports = 0;
7184 * Initialize the SLI Layer to run with lpfc HBAs.
7186 lpfc_sli_setup(phba);
7187 lpfc_sli_queue_init(phba);
7189 /* Allocate device driver memory */
7190 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7193 phba->lpfc_sg_dma_buf_pool =
7194 dma_pool_create("lpfc_sg_dma_buf_pool",
7195 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7198 if (!phba->lpfc_sg_dma_buf_pool)
7201 phba->lpfc_cmd_rsp_buf_pool =
7202 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7204 sizeof(struct fcp_cmnd) +
7205 sizeof(struct fcp_rsp),
7208 if (!phba->lpfc_cmd_rsp_buf_pool)
7209 goto fail_free_dma_buf_pool;
7212 * Enable sr-iov virtual functions if supported and configured
7213 * through the module parameter.
7215 if (phba->cfg_sriov_nr_virtfn > 0) {
7216 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7217 phba->cfg_sriov_nr_virtfn);
7219 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7220 "2808 Requested number of SR-IOV "
7221 "virtual functions (%d) is not "
7223 phba->cfg_sriov_nr_virtfn);
7224 phba->cfg_sriov_nr_virtfn = 0;
7230 fail_free_dma_buf_pool:
7231 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7232 phba->lpfc_sg_dma_buf_pool = NULL;
7234 lpfc_mem_free(phba);
7239 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7240 * @phba: pointer to lpfc hba data structure.
7242 * This routine is invoked to unset the driver internal resources set up
7243 * specific for supporting the SLI-3 HBA device it attached to.
7246 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7248 /* Free device driver memory allocated */
7249 lpfc_mem_free_all(phba);
7255 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7256 * @phba: pointer to lpfc hba data structure.
7258 * This routine is invoked to set up the driver internal resources specific to
7259 * support the SLI-4 HBA device it attached to.
7263 * other values - error
7266 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7268 LPFC_MBOXQ_t *mboxq;
7270 int rc, i, max_buf_size;
7277 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7278 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
7279 phba->sli4_hba.curr_disp_cpu = 0;
7281 /* Get all the module params for configuring this host */
7282 lpfc_get_cfgparam(phba);
7284 /* Set up phase-1 common device driver resources */
7285 rc = lpfc_setup_driver_resource_phase1(phba);
7289 /* Before proceed, wait for POST done and device ready */
7290 rc = lpfc_sli4_post_status_check(phba);
7294 /* Allocate all driver workqueues here */
7296 /* The lpfc_wq workqueue for deferred irq use */
7297 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7300 * Initialize timers used by driver
7303 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
7305 /* FCF rediscover timer */
7306 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
7308 /* CMF congestion timer */
7309 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7310 phba->cmf_timer.function = lpfc_cmf_timer;
7313 * Control structure for handling external multi-buffer mailbox
7314 * command pass-through.
7316 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
7317 sizeof(struct lpfc_mbox_ext_buf_ctx));
7318 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
7320 phba->max_vpi = LPFC_MAX_VPI;
7322 /* This will be set to correct value after the read_config mbox */
7323 phba->max_vports = 0;
7325 /* Program the default value of vlan_id and fc_map */
7326 phba->valid_vlan = 0;
7327 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
7328 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
7329 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
7332 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
7333 * we will associate a new ring, for each EQ/CQ/WQ tuple.
7334 * The WQ create will allocate the ring.
7337 /* Initialize buffer queue management fields */
7338 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
7339 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
7340 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
7342 /* for VMID idle timeout if VMID is enabled */
7343 if (lpfc_is_vmid_enabled(phba))
7344 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
7347 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
7349 /* Initialize the Abort buffer list used by driver */
7350 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
7351 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
7353 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7354 /* Initialize the Abort nvme buffer list used by driver */
7355 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
7356 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
7357 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
7358 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
7359 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
7362 /* This abort list used by worker thread */
7363 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
7364 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
7365 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
7366 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
7369 * Initialize driver internal slow-path work queues
7372 /* Driver internel slow-path CQ Event pool */
7373 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
7374 /* Response IOCB work queue list */
7375 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
7376 /* Asynchronous event CQ Event work queue list */
7377 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
7378 /* Slow-path XRI aborted CQ Event work queue list */
7379 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
7380 /* Receive queue CQ Event work queue list */
7381 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
7383 /* Initialize extent block lists. */
7384 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
7385 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
7386 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
7387 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
7389 /* Initialize mboxq lists. If the early init routines fail
7390 * these lists need to be correctly initialized.
7392 INIT_LIST_HEAD(&phba->sli.mboxq);
7393 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
7395 /* initialize optic_state to 0xFF */
7396 phba->sli4_hba.lnk_info.optic_state = 0xff;
7398 /* Allocate device driver memory */
7399 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
7403 /* IF Type 2 ports get initialized now. */
7404 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
7405 LPFC_SLI_INTF_IF_TYPE_2) {
7406 rc = lpfc_pci_function_reset(phba);
7411 phba->temp_sensor_support = 1;
7414 /* Create the bootstrap mailbox command */
7415 rc = lpfc_create_bootstrap_mbox(phba);
7419 /* Set up the host's endian order with the device. */
7420 rc = lpfc_setup_endian_order(phba);
7422 goto out_free_bsmbx;
7424 /* Set up the hba's configuration parameters. */
7425 rc = lpfc_sli4_read_config(phba);
7427 goto out_free_bsmbx;
7428 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
7430 goto out_free_bsmbx;
7432 /* IF Type 0 ports get initialized now. */
7433 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7434 LPFC_SLI_INTF_IF_TYPE_0) {
7435 rc = lpfc_pci_function_reset(phba);
7437 goto out_free_bsmbx;
7440 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7444 goto out_free_bsmbx;
7447 /* Check for NVMET being configured */
7448 phba->nvmet_support = 0;
7449 if (lpfc_enable_nvmet_cnt) {
7451 /* First get WWN of HBA instance */
7452 lpfc_read_nv(phba, mboxq);
7453 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7454 if (rc != MBX_SUCCESS) {
7455 lpfc_printf_log(phba, KERN_ERR,
7457 "6016 Mailbox failed , mbxCmd x%x "
7458 "READ_NV, mbxStatus x%x\n",
7459 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7460 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
7461 mempool_free(mboxq, phba->mbox_mem_pool);
7463 goto out_free_bsmbx;
7466 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
7468 wwn = cpu_to_be64(wwn);
7469 phba->sli4_hba.wwnn.u.name = wwn;
7470 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
7472 /* wwn is WWPN of HBA instance */
7473 wwn = cpu_to_be64(wwn);
7474 phba->sli4_hba.wwpn.u.name = wwn;
7476 /* Check to see if it matches any module parameter */
7477 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
7478 if (wwn == lpfc_enable_nvmet[i]) {
7479 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
7480 if (lpfc_nvmet_mem_alloc(phba))
7483 phba->nvmet_support = 1; /* a match */
7485 lpfc_printf_log(phba, KERN_ERR,
7487 "6017 NVME Target %016llx\n",
7490 lpfc_printf_log(phba, KERN_ERR,
7492 "6021 Can't enable NVME Target."
7493 " NVME_TARGET_FC infrastructure"
7494 " is not in kernel\n");
7496 /* Not supported for NVMET */
7497 phba->cfg_xri_rebalancing = 0;
7498 if (phba->irq_chann_mode == NHT_MODE) {
7499 phba->cfg_irq_chann =
7500 phba->sli4_hba.num_present_cpu;
7501 phba->cfg_hdw_queue =
7502 phba->sli4_hba.num_present_cpu;
7503 phba->irq_chann_mode = NORMAL_MODE;
7510 lpfc_nvme_mod_param_dep(phba);
7513 * Get sli4 parameters that override parameters from Port capabilities.
7514 * If this call fails, it isn't critical unless the SLI4 parameters come
7517 rc = lpfc_get_sli4_parameters(phba, mboxq);
7519 if_type = bf_get(lpfc_sli_intf_if_type,
7520 &phba->sli4_hba.sli_intf);
7521 if_fam = bf_get(lpfc_sli_intf_sli_family,
7522 &phba->sli4_hba.sli_intf);
7523 if (phba->sli4_hba.extents_in_use &&
7524 phba->sli4_hba.rpi_hdrs_in_use) {
7525 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7526 "2999 Unsupported SLI4 Parameters "
7527 "Extents and RPI headers enabled.\n");
7528 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
7529 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
7530 mempool_free(mboxq, phba->mbox_mem_pool);
7532 goto out_free_bsmbx;
7535 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
7536 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
7537 mempool_free(mboxq, phba->mbox_mem_pool);
7539 goto out_free_bsmbx;
7544 * 1 for cmd, 1 for rsp, NVME adds an extra one
7545 * for boundary conditions in its max_sgl_segment template.
7548 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
7552 * It doesn't matter what family our adapter is in, we are
7553 * limited to 2 Pages, 512 SGEs, for our SGL.
7554 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
7556 max_buf_size = (2 * SLI4_PAGE_SIZE);
7559 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
7560 * used to create the sg_dma_buf_pool must be calculated.
7562 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
7563 /* Both cfg_enable_bg and cfg_external_dif code paths */
7566 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
7567 * the FCP rsp, and a SGE. Sice we have no control
7568 * over how many protection segments the SCSI Layer
7569 * will hand us (ie: there could be one for every block
7570 * in the IO), just allocate enough SGEs to accomidate
7571 * our max amount and we need to limit lpfc_sg_seg_cnt
7572 * to minimize the risk of running out.
7574 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7575 sizeof(struct fcp_rsp) + max_buf_size;
7577 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
7578 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
7581 * If supporting DIF, reduce the seg count for scsi to
7582 * allow room for the DIF sges.
7584 if (phba->cfg_enable_bg &&
7585 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
7586 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
7588 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
7592 * The scsi_buf for a regular I/O holds the FCP cmnd,
7593 * the FCP rsp, a SGE for each, and a SGE for up to
7594 * cfg_sg_seg_cnt data segments.
7596 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7597 sizeof(struct fcp_rsp) +
7598 ((phba->cfg_sg_seg_cnt + extra) *
7599 sizeof(struct sli4_sge));
7601 /* Total SGEs for scsi_sg_list */
7602 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
7603 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
7606 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
7607 * need to post 1 page for the SGL.
7611 if (phba->cfg_xpsgl && !phba->nvmet_support)
7612 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
7613 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
7614 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
7616 phba->cfg_sg_dma_buf_size =
7617 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
7619 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
7620 sizeof(struct sli4_sge);
7622 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
7623 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7624 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
7625 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
7626 "6300 Reducing NVME sg segment "
7628 LPFC_MAX_NVME_SEG_CNT);
7629 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
7631 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
7634 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
7635 "9087 sg_seg_cnt:%d dmabuf_size:%d "
7636 "total:%d scsi:%d nvme:%d\n",
7637 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7638 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
7639 phba->cfg_nvme_seg_cnt);
7641 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
7642 i = phba->cfg_sg_dma_buf_size;
7646 phba->lpfc_sg_dma_buf_pool =
7647 dma_pool_create("lpfc_sg_dma_buf_pool",
7649 phba->cfg_sg_dma_buf_size,
7651 if (!phba->lpfc_sg_dma_buf_pool)
7652 goto out_free_bsmbx;
7654 phba->lpfc_cmd_rsp_buf_pool =
7655 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7657 sizeof(struct fcp_cmnd) +
7658 sizeof(struct fcp_rsp),
7660 if (!phba->lpfc_cmd_rsp_buf_pool)
7661 goto out_free_sg_dma_buf;
7663 mempool_free(mboxq, phba->mbox_mem_pool);
7665 /* Verify OAS is supported */
7666 lpfc_sli4_oas_verify(phba);
7668 /* Verify RAS support on adapter */
7669 lpfc_sli4_ras_init(phba);
7671 /* Verify all the SLI4 queues */
7672 rc = lpfc_sli4_queue_verify(phba);
7674 goto out_free_cmd_rsp_buf;
7676 /* Create driver internal CQE event pool */
7677 rc = lpfc_sli4_cq_event_pool_create(phba);
7679 goto out_free_cmd_rsp_buf;
7681 /* Initialize sgl lists per host */
7682 lpfc_init_sgl_list(phba);
7684 /* Allocate and initialize active sgl array */
7685 rc = lpfc_init_active_sgl_array(phba);
7687 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7688 "1430 Failed to initialize sgl list.\n");
7689 goto out_destroy_cq_event_pool;
7691 rc = lpfc_sli4_init_rpi_hdrs(phba);
7693 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7694 "1432 Failed to initialize rpi headers.\n");
7695 goto out_free_active_sgl;
7698 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
7699 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
7700 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
7702 if (!phba->fcf.fcf_rr_bmask) {
7703 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7704 "2759 Failed allocate memory for FCF round "
7705 "robin failover bmask\n");
7707 goto out_remove_rpi_hdrs;
7710 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
7711 sizeof(struct lpfc_hba_eq_hdl),
7713 if (!phba->sli4_hba.hba_eq_hdl) {
7714 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7715 "2572 Failed allocate memory for "
7716 "fast-path per-EQ handle array\n");
7718 goto out_free_fcf_rr_bmask;
7721 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
7722 sizeof(struct lpfc_vector_map_info),
7724 if (!phba->sli4_hba.cpu_map) {
7725 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7726 "3327 Failed allocate memory for msi-x "
7727 "interrupt vector mapping\n");
7729 goto out_free_hba_eq_hdl;
7732 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
7733 if (!phba->sli4_hba.eq_info) {
7734 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7735 "3321 Failed allocation for per_cpu stats\n");
7737 goto out_free_hba_cpu_map;
7740 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
7741 sizeof(*phba->sli4_hba.idle_stat),
7743 if (!phba->sli4_hba.idle_stat) {
7744 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7745 "3390 Failed allocation for idle_stat\n");
7747 goto out_free_hba_eq_info;
7750 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7751 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
7752 if (!phba->sli4_hba.c_stat) {
7753 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7754 "3332 Failed allocating per cpu hdwq stats\n");
7756 goto out_free_hba_idle_stat;
7760 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
7761 if (!phba->cmf_stat) {
7762 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7763 "3331 Failed allocating per cpu cgn stats\n");
7765 goto out_free_hba_hdwq_info;
7769 * Enable sr-iov virtual functions if supported and configured
7770 * through the module parameter.
7772 if (phba->cfg_sriov_nr_virtfn > 0) {
7773 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7774 phba->cfg_sriov_nr_virtfn);
7776 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7777 "3020 Requested number of SR-IOV "
7778 "virtual functions (%d) is not "
7780 phba->cfg_sriov_nr_virtfn);
7781 phba->cfg_sriov_nr_virtfn = 0;
7787 out_free_hba_hdwq_info:
7788 free_percpu(phba->sli4_hba.c_stat);
7789 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7790 out_free_hba_idle_stat:
7791 kfree(phba->sli4_hba.idle_stat);
7793 out_free_hba_eq_info:
7794 free_percpu(phba->sli4_hba.eq_info);
7795 out_free_hba_cpu_map:
7796 kfree(phba->sli4_hba.cpu_map);
7797 out_free_hba_eq_hdl:
7798 kfree(phba->sli4_hba.hba_eq_hdl);
7799 out_free_fcf_rr_bmask:
7800 kfree(phba->fcf.fcf_rr_bmask);
7801 out_remove_rpi_hdrs:
7802 lpfc_sli4_remove_rpi_hdrs(phba);
7803 out_free_active_sgl:
7804 lpfc_free_active_sgl(phba);
7805 out_destroy_cq_event_pool:
7806 lpfc_sli4_cq_event_pool_destroy(phba);
7807 out_free_cmd_rsp_buf:
7808 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
7809 phba->lpfc_cmd_rsp_buf_pool = NULL;
7810 out_free_sg_dma_buf:
7811 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7812 phba->lpfc_sg_dma_buf_pool = NULL;
7814 lpfc_destroy_bootstrap_mbox(phba);
7816 lpfc_mem_free(phba);
7821 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
7822 * @phba: pointer to lpfc hba data structure.
7824 * This routine is invoked to unset the driver internal resources set up
7825 * specific for supporting the SLI-4 HBA device it attached to.
7828 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
7830 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7832 free_percpu(phba->sli4_hba.eq_info);
7833 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7834 free_percpu(phba->sli4_hba.c_stat);
7836 free_percpu(phba->cmf_stat);
7837 kfree(phba->sli4_hba.idle_stat);
7839 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
7840 kfree(phba->sli4_hba.cpu_map);
7841 phba->sli4_hba.num_possible_cpu = 0;
7842 phba->sli4_hba.num_present_cpu = 0;
7843 phba->sli4_hba.curr_disp_cpu = 0;
7844 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
7846 /* Free memory allocated for fast-path work queue handles */
7847 kfree(phba->sli4_hba.hba_eq_hdl);
7849 /* Free the allocated rpi headers. */
7850 lpfc_sli4_remove_rpi_hdrs(phba);
7851 lpfc_sli4_remove_rpis(phba);
7853 /* Free eligible FCF index bmask */
7854 kfree(phba->fcf.fcf_rr_bmask);
7856 /* Free the ELS sgl list */
7857 lpfc_free_active_sgl(phba);
7858 lpfc_free_els_sgl_list(phba);
7859 lpfc_free_nvmet_sgl_list(phba);
7861 /* Free the completion queue EQ event pool */
7862 lpfc_sli4_cq_event_release_all(phba);
7863 lpfc_sli4_cq_event_pool_destroy(phba);
7865 /* Release resource identifiers. */
7866 lpfc_sli4_dealloc_resource_identifiers(phba);
7868 /* Free the bsmbx region. */
7869 lpfc_destroy_bootstrap_mbox(phba);
7871 /* Free the SLI Layer memory with SLI4 HBAs */
7872 lpfc_mem_free_all(phba);
7874 /* Free the current connect table */
7875 list_for_each_entry_safe(conn_entry, next_conn_entry,
7876 &phba->fcf_conn_rec_list, list) {
7877 list_del_init(&conn_entry->list);
7885 * lpfc_init_api_table_setup - Set up init api function jump table
7886 * @phba: The hba struct for which this call is being executed.
7887 * @dev_grp: The HBA PCI-Device group number.
7889 * This routine sets up the device INIT interface API function jump table
7892 * Returns: 0 - success, -ENODEV - failure.
7895 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7897 phba->lpfc_hba_init_link = lpfc_hba_init_link;
7898 phba->lpfc_hba_down_link = lpfc_hba_down_link;
7899 phba->lpfc_selective_reset = lpfc_selective_reset;
7901 case LPFC_PCI_DEV_LP:
7902 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
7903 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
7904 phba->lpfc_stop_port = lpfc_stop_port_s3;
7906 case LPFC_PCI_DEV_OC:
7907 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
7908 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
7909 phba->lpfc_stop_port = lpfc_stop_port_s4;
7912 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7913 "1431 Invalid HBA PCI-device group: 0x%x\n",
7921 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
7922 * @phba: pointer to lpfc hba data structure.
7924 * This routine is invoked to set up the driver internal resources after the
7925 * device specific resource setup to support the HBA device it attached to.
7929 * other values - error
7932 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
7936 /* Startup the kernel thread for this host adapter. */
7937 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7938 "lpfc_worker_%d", phba->brd_no);
7939 if (IS_ERR(phba->worker_thread)) {
7940 error = PTR_ERR(phba->worker_thread);
7948 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7949 * @phba: pointer to lpfc hba data structure.
7951 * This routine is invoked to unset the driver internal resources set up after
7952 * the device specific resource setup for supporting the HBA device it
7956 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
7959 flush_workqueue(phba->wq);
7960 destroy_workqueue(phba->wq);
7964 /* Stop kernel worker thread */
7965 if (phba->worker_thread)
7966 kthread_stop(phba->worker_thread);
7970 * lpfc_free_iocb_list - Free iocb list.
7971 * @phba: pointer to lpfc hba data structure.
7973 * This routine is invoked to free the driver's IOCB list and memory.
7976 lpfc_free_iocb_list(struct lpfc_hba *phba)
7978 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
7980 spin_lock_irq(&phba->hbalock);
7981 list_for_each_entry_safe(iocbq_entry, iocbq_next,
7982 &phba->lpfc_iocb_list, list) {
7983 list_del(&iocbq_entry->list);
7985 phba->total_iocbq_bufs--;
7987 spin_unlock_irq(&phba->hbalock);
7993 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7994 * @phba: pointer to lpfc hba data structure.
7995 * @iocb_count: number of requested iocbs
7997 * This routine is invoked to allocate and initizlize the driver's IOCB
7998 * list and set up the IOCB tag array accordingly.
8002 * other values - error
8005 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8007 struct lpfc_iocbq *iocbq_entry = NULL;
8011 /* Initialize and populate the iocb list per host. */
8012 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
8013 for (i = 0; i < iocb_count; i++) {
8014 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
8015 if (iocbq_entry == NULL) {
8016 printk(KERN_ERR "%s: only allocated %d iocbs of "
8017 "expected %d count. Unloading driver.\n",
8018 __func__, i, iocb_count);
8019 goto out_free_iocbq;
8022 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8025 printk(KERN_ERR "%s: failed to allocate IOTAG. "
8026 "Unloading driver.\n", __func__);
8027 goto out_free_iocbq;
8029 iocbq_entry->sli4_lxritag = NO_XRI;
8030 iocbq_entry->sli4_xritag = NO_XRI;
8032 spin_lock_irq(&phba->hbalock);
8033 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8034 phba->total_iocbq_bufs++;
8035 spin_unlock_irq(&phba->hbalock);
8041 lpfc_free_iocb_list(phba);
8047 * lpfc_free_sgl_list - Free a given sgl list.
8048 * @phba: pointer to lpfc hba data structure.
8049 * @sglq_list: pointer to the head of sgl list.
8051 * This routine is invoked to free a give sgl list and memory.
8054 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
8056 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8058 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8059 list_del(&sglq_entry->list);
8060 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8066 * lpfc_free_els_sgl_list - Free els sgl list.
8067 * @phba: pointer to lpfc hba data structure.
8069 * This routine is invoked to free the driver's els sgl list and memory.
8072 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8074 LIST_HEAD(sglq_list);
8076 /* Retrieve all els sgls from driver list */
8077 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
8078 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
8079 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
8081 /* Now free the sgl list */
8082 lpfc_free_sgl_list(phba, &sglq_list);
8086 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8087 * @phba: pointer to lpfc hba data structure.
8089 * This routine is invoked to free the driver's nvmet sgl list and memory.
8092 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8094 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8095 LIST_HEAD(sglq_list);
8097 /* Retrieve all nvmet sgls from driver list */
8098 spin_lock_irq(&phba->hbalock);
8099 spin_lock(&phba->sli4_hba.sgl_list_lock);
8100 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8101 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8102 spin_unlock_irq(&phba->hbalock);
8104 /* Now free the sgl list */
8105 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8106 list_del(&sglq_entry->list);
8107 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8111 /* Update the nvmet_xri_cnt to reflect no current sgls.
8112 * The next initialization cycle sets the count and allocates
8113 * the sgls over again.
8115 phba->sli4_hba.nvmet_xri_cnt = 0;
8119 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8120 * @phba: pointer to lpfc hba data structure.
8122 * This routine is invoked to allocate the driver's active sgl memory.
8123 * This array will hold the sglq_entry's for active IOs.
8126 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8129 size = sizeof(struct lpfc_sglq *);
8130 size *= phba->sli4_hba.max_cfg_param.max_xri;
8132 phba->sli4_hba.lpfc_sglq_active_list =
8133 kzalloc(size, GFP_KERNEL);
8134 if (!phba->sli4_hba.lpfc_sglq_active_list)
8140 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8141 * @phba: pointer to lpfc hba data structure.
8143 * This routine is invoked to walk through the array of active sglq entries
8144 * and free all of the resources.
8145 * This is just a place holder for now.
8148 lpfc_free_active_sgl(struct lpfc_hba *phba)
8150 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8154 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8155 * @phba: pointer to lpfc hba data structure.
8157 * This routine is invoked to allocate and initizlize the driver's sgl
8158 * list and set up the sgl xritag tag array accordingly.
8162 lpfc_init_sgl_list(struct lpfc_hba *phba)
8164 /* Initialize and populate the sglq list per host/VF. */
8165 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
8166 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8167 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
8168 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
8170 /* els xri-sgl book keeping */
8171 phba->sli4_hba.els_xri_cnt = 0;
8173 /* nvme xri-buffer book keeping */
8174 phba->sli4_hba.io_xri_cnt = 0;
8178 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8179 * @phba: pointer to lpfc hba data structure.
8181 * This routine is invoked to post rpi header templates to the
8182 * port for those SLI4 ports that do not support extents. This routine
8183 * posts a PAGE_SIZE memory region to the port to hold up to
8184 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8185 * and should be called only when interrupts are disabled.
8189 * -ERROR - otherwise.
8192 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8195 struct lpfc_rpi_hdr *rpi_hdr;
8197 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
8198 if (!phba->sli4_hba.rpi_hdrs_in_use)
8200 if (phba->sli4_hba.extents_in_use)
8203 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8206 "0391 Error during rpi post operation\n");
8207 lpfc_sli4_remove_rpis(phba);
8215 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8216 * @phba: pointer to lpfc hba data structure.
8218 * This routine is invoked to allocate a single 4KB memory region to
8219 * support rpis and stores them in the phba. This single region
8220 * provides support for up to 64 rpis. The region is used globally
8224 * A valid rpi hdr on success.
8225 * A NULL pointer on any failure.
8227 struct lpfc_rpi_hdr *
8228 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8230 uint16_t rpi_limit, curr_rpi_range;
8231 struct lpfc_dmabuf *dmabuf;
8232 struct lpfc_rpi_hdr *rpi_hdr;
8235 * If the SLI4 port supports extents, posting the rpi header isn't
8236 * required. Set the expected maximum count and let the actual value
8237 * get set when extents are fully allocated.
8239 if (!phba->sli4_hba.rpi_hdrs_in_use)
8241 if (phba->sli4_hba.extents_in_use)
8244 /* The limit on the logical index is just the max_rpi count. */
8245 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
8247 spin_lock_irq(&phba->hbalock);
8249 * Establish the starting RPI in this header block. The starting
8250 * rpi is normalized to a zero base because the physical rpi is
8253 curr_rpi_range = phba->sli4_hba.next_rpi;
8254 spin_unlock_irq(&phba->hbalock);
8256 /* Reached full RPI range */
8257 if (curr_rpi_range == rpi_limit)
8261 * First allocate the protocol header region for the port. The
8262 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8264 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8268 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8269 LPFC_HDR_TEMPLATE_SIZE,
8270 &dmabuf->phys, GFP_KERNEL);
8271 if (!dmabuf->virt) {
8273 goto err_free_dmabuf;
8276 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
8278 goto err_free_coherent;
8281 /* Save the rpi header data for cleanup later. */
8282 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
8284 goto err_free_coherent;
8286 rpi_hdr->dmabuf = dmabuf;
8287 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
8288 rpi_hdr->page_count = 1;
8289 spin_lock_irq(&phba->hbalock);
8291 /* The rpi_hdr stores the logical index only. */
8292 rpi_hdr->start_rpi = curr_rpi_range;
8293 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
8294 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
8296 spin_unlock_irq(&phba->hbalock);
8300 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
8301 dmabuf->virt, dmabuf->phys);
8308 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
8309 * @phba: pointer to lpfc hba data structure.
8311 * This routine is invoked to remove all memory resources allocated
8312 * to support rpis for SLI4 ports not supporting extents. This routine
8313 * presumes the caller has released all rpis consumed by fabric or port
8314 * logins and is prepared to have the header pages removed.
8317 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
8319 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
8321 if (!phba->sli4_hba.rpi_hdrs_in_use)
8324 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
8325 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
8326 list_del(&rpi_hdr->list);
8327 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
8328 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
8329 kfree(rpi_hdr->dmabuf);
8333 /* There are no rpis available to the port now. */
8334 phba->sli4_hba.next_rpi = 0;
8338 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
8339 * @pdev: pointer to pci device data structure.
8341 * This routine is invoked to allocate the driver hba data structure for an
8342 * HBA device. If the allocation is successful, the phba reference to the
8343 * PCI device data structure is set.
8346 * pointer to @phba - successful
8349 static struct lpfc_hba *
8350 lpfc_hba_alloc(struct pci_dev *pdev)
8352 struct lpfc_hba *phba;
8354 /* Allocate memory for HBA structure */
8355 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
8357 dev_err(&pdev->dev, "failed to allocate hba struct\n");
8361 /* Set reference to PCI device in HBA structure */
8362 phba->pcidev = pdev;
8364 /* Assign an unused board number */
8365 phba->brd_no = lpfc_get_instance();
8366 if (phba->brd_no < 0) {
8370 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
8372 spin_lock_init(&phba->ct_ev_lock);
8373 INIT_LIST_HEAD(&phba->ct_ev_waiters);
8379 * lpfc_hba_free - Free driver hba data structure with a device.
8380 * @phba: pointer to lpfc hba data structure.
8382 * This routine is invoked to free the driver hba data structure with an
8386 lpfc_hba_free(struct lpfc_hba *phba)
8388 if (phba->sli_rev == LPFC_SLI_REV4)
8389 kfree(phba->sli4_hba.hdwq);
8391 /* Release the driver assigned board number */
8392 idr_remove(&lpfc_hba_index, phba->brd_no);
8394 /* Free memory allocated with sli3 rings */
8395 kfree(phba->sli.sli3_ring);
8396 phba->sli.sli3_ring = NULL;
8403 * lpfc_create_shost - Create hba physical port with associated scsi host.
8404 * @phba: pointer to lpfc hba data structure.
8406 * This routine is invoked to create HBA physical port and associate a SCSI
8411 * other values - error
8414 lpfc_create_shost(struct lpfc_hba *phba)
8416 struct lpfc_vport *vport;
8417 struct Scsi_Host *shost;
8419 /* Initialize HBA FC structure */
8420 phba->fc_edtov = FF_DEF_EDTOV;
8421 phba->fc_ratov = FF_DEF_RATOV;
8422 phba->fc_altov = FF_DEF_ALTOV;
8423 phba->fc_arbtov = FF_DEF_ARBTOV;
8425 atomic_set(&phba->sdev_cnt, 0);
8426 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
8430 shost = lpfc_shost_from_vport(vport);
8431 phba->pport = vport;
8433 if (phba->nvmet_support) {
8434 /* Only 1 vport (pport) will support NVME target */
8435 phba->targetport = NULL;
8436 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
8437 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
8438 "6076 NVME Target Found\n");
8441 lpfc_debugfs_initialize(vport);
8442 /* Put reference to SCSI host to driver's device private data */
8443 pci_set_drvdata(phba->pcidev, shost);
8446 * At this point we are fully registered with PSA. In addition,
8447 * any initial discovery should be completed.
8449 vport->load_flag |= FC_ALLOW_FDMI;
8450 if (phba->cfg_enable_SmartSAN ||
8451 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
8453 /* Setup appropriate attribute masks */
8454 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
8455 if (phba->cfg_enable_SmartSAN)
8456 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
8458 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
8464 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
8465 * @phba: pointer to lpfc hba data structure.
8467 * This routine is invoked to destroy HBA physical port and the associated
8471 lpfc_destroy_shost(struct lpfc_hba *phba)
8473 struct lpfc_vport *vport = phba->pport;
8475 /* Destroy physical port that associated with the SCSI host */
8476 destroy_port(vport);
8482 * lpfc_setup_bg - Setup Block guard structures and debug areas.
8483 * @phba: pointer to lpfc hba data structure.
8484 * @shost: the shost to be used to detect Block guard settings.
8486 * This routine sets up the local Block guard protocol settings for @shost.
8487 * This routine also allocates memory for debugging bg buffers.
8490 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
8495 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
8496 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8497 "1478 Registering BlockGuard with the "
8500 old_mask = phba->cfg_prot_mask;
8501 old_guard = phba->cfg_prot_guard;
8503 /* Only allow supported values */
8504 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
8505 SHOST_DIX_TYPE0_PROTECTION |
8506 SHOST_DIX_TYPE1_PROTECTION);
8507 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
8508 SHOST_DIX_GUARD_CRC);
8510 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
8511 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
8512 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
8514 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
8515 if ((old_mask != phba->cfg_prot_mask) ||
8516 (old_guard != phba->cfg_prot_guard))
8517 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8518 "1475 Registering BlockGuard with the "
8519 "SCSI layer: mask %d guard %d\n",
8520 phba->cfg_prot_mask,
8521 phba->cfg_prot_guard);
8523 scsi_host_set_prot(shost, phba->cfg_prot_mask);
8524 scsi_host_set_guard(shost, phba->cfg_prot_guard);
8526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8527 "1479 Not Registering BlockGuard with the SCSI "
8528 "layer, Bad protection parameters: %d %d\n",
8529 old_mask, old_guard);
8534 * lpfc_post_init_setup - Perform necessary device post initialization setup.
8535 * @phba: pointer to lpfc hba data structure.
8537 * This routine is invoked to perform all the necessary post initialization
8538 * setup for the device.
8541 lpfc_post_init_setup(struct lpfc_hba *phba)
8543 struct Scsi_Host *shost;
8544 struct lpfc_adapter_event_header adapter_event;
8546 /* Get the default values for Model Name and Description */
8547 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8550 * hba setup may have changed the hba_queue_depth so we need to
8551 * adjust the value of can_queue.
8553 shost = pci_get_drvdata(phba->pcidev);
8554 shost->can_queue = phba->cfg_hba_queue_depth - 10;
8556 lpfc_host_attrib_init(shost);
8558 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
8559 spin_lock_irq(shost->host_lock);
8560 lpfc_poll_start_timer(phba);
8561 spin_unlock_irq(shost->host_lock);
8564 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8565 "0428 Perform SCSI scan\n");
8566 /* Send board arrival event to upper layer */
8567 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
8568 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
8569 fc_host_post_vendor_event(shost, fc_get_event_number(),
8570 sizeof(adapter_event),
8571 (char *) &adapter_event,
8577 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
8578 * @phba: pointer to lpfc hba data structure.
8580 * This routine is invoked to set up the PCI device memory space for device
8581 * with SLI-3 interface spec.
8585 * other values - error
8588 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
8590 struct pci_dev *pdev = phba->pcidev;
8591 unsigned long bar0map_len, bar2map_len;
8599 /* Set the device DMA mask size */
8600 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
8602 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
8607 /* Get the bus address of Bar0 and Bar2 and the number of bytes
8608 * required by each mapping.
8610 phba->pci_bar0_map = pci_resource_start(pdev, 0);
8611 bar0map_len = pci_resource_len(pdev, 0);
8613 phba->pci_bar2_map = pci_resource_start(pdev, 2);
8614 bar2map_len = pci_resource_len(pdev, 2);
8616 /* Map HBA SLIM to a kernel virtual address. */
8617 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
8618 if (!phba->slim_memmap_p) {
8619 dev_printk(KERN_ERR, &pdev->dev,
8620 "ioremap failed for SLIM memory.\n");
8624 /* Map HBA Control Registers to a kernel virtual address. */
8625 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
8626 if (!phba->ctrl_regs_memmap_p) {
8627 dev_printk(KERN_ERR, &pdev->dev,
8628 "ioremap failed for HBA control registers.\n");
8629 goto out_iounmap_slim;
8632 /* Allocate memory for SLI-2 structures */
8633 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
8634 &phba->slim2p.phys, GFP_KERNEL);
8635 if (!phba->slim2p.virt)
8638 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
8639 phba->mbox_ext = (phba->slim2p.virt +
8640 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
8641 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
8642 phba->IOCBs = (phba->slim2p.virt +
8643 offsetof(struct lpfc_sli2_slim, IOCBs));
8645 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
8646 lpfc_sli_hbq_size(),
8647 &phba->hbqslimp.phys,
8649 if (!phba->hbqslimp.virt)
8652 hbq_count = lpfc_sli_hbq_count();
8653 ptr = phba->hbqslimp.virt;
8654 for (i = 0; i < hbq_count; ++i) {
8655 phba->hbqs[i].hbq_virt = ptr;
8656 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
8657 ptr += (lpfc_hbq_defs[i]->entry_count *
8658 sizeof(struct lpfc_hbq_entry));
8660 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
8661 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
8663 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
8665 phba->MBslimaddr = phba->slim_memmap_p;
8666 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
8667 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
8668 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
8669 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
8674 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
8675 phba->slim2p.virt, phba->slim2p.phys);
8677 iounmap(phba->ctrl_regs_memmap_p);
8679 iounmap(phba->slim_memmap_p);
8685 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
8686 * @phba: pointer to lpfc hba data structure.
8688 * This routine is invoked to unset the PCI device memory space for device
8689 * with SLI-3 interface spec.
8692 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
8694 struct pci_dev *pdev;
8696 /* Obtain PCI device reference */
8700 pdev = phba->pcidev;
8702 /* Free coherent DMA memory allocated */
8703 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
8704 phba->hbqslimp.virt, phba->hbqslimp.phys);
8705 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
8706 phba->slim2p.virt, phba->slim2p.phys);
8708 /* I/O memory unmap */
8709 iounmap(phba->ctrl_regs_memmap_p);
8710 iounmap(phba->slim_memmap_p);
8716 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
8717 * @phba: pointer to lpfc hba data structure.
8719 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
8720 * done and check status.
8722 * Return 0 if successful, otherwise -ENODEV.
8725 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
8727 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
8728 struct lpfc_register reg_data;
8729 int i, port_error = 0;
8732 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
8733 memset(®_data, 0, sizeof(reg_data));
8734 if (!phba->sli4_hba.PSMPHRregaddr)
8737 /* Wait up to 30 seconds for the SLI Port POST done and ready */
8738 for (i = 0; i < 3000; i++) {
8739 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
8740 &portsmphr_reg.word0) ||
8741 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
8742 /* Port has a fatal POST error, break out */
8743 port_error = -ENODEV;
8746 if (LPFC_POST_STAGE_PORT_READY ==
8747 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
8753 * If there was a port error during POST, then don't proceed with
8754 * other register reads as the data may not be valid. Just exit.
8757 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8758 "1408 Port Failed POST - portsmphr=0x%x, "
8759 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
8760 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
8761 portsmphr_reg.word0,
8762 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
8763 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
8764 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
8765 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
8766 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
8767 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
8768 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
8769 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
8771 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8772 "2534 Device Info: SLIFamily=0x%x, "
8773 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
8774 "SLIHint_2=0x%x, FT=0x%x\n",
8775 bf_get(lpfc_sli_intf_sli_family,
8776 &phba->sli4_hba.sli_intf),
8777 bf_get(lpfc_sli_intf_slirev,
8778 &phba->sli4_hba.sli_intf),
8779 bf_get(lpfc_sli_intf_if_type,
8780 &phba->sli4_hba.sli_intf),
8781 bf_get(lpfc_sli_intf_sli_hint1,
8782 &phba->sli4_hba.sli_intf),
8783 bf_get(lpfc_sli_intf_sli_hint2,
8784 &phba->sli4_hba.sli_intf),
8785 bf_get(lpfc_sli_intf_func_type,
8786 &phba->sli4_hba.sli_intf));
8788 * Check for other Port errors during the initialization
8789 * process. Fail the load if the port did not come up
8792 if_type = bf_get(lpfc_sli_intf_if_type,
8793 &phba->sli4_hba.sli_intf);
8795 case LPFC_SLI_INTF_IF_TYPE_0:
8796 phba->sli4_hba.ue_mask_lo =
8797 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
8798 phba->sli4_hba.ue_mask_hi =
8799 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
8801 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
8803 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
8804 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
8805 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
8806 lpfc_printf_log(phba, KERN_ERR,
8808 "1422 Unrecoverable Error "
8809 "Detected during POST "
8810 "uerr_lo_reg=0x%x, "
8811 "uerr_hi_reg=0x%x, "
8812 "ue_mask_lo_reg=0x%x, "
8813 "ue_mask_hi_reg=0x%x\n",
8816 phba->sli4_hba.ue_mask_lo,
8817 phba->sli4_hba.ue_mask_hi);
8818 port_error = -ENODEV;
8821 case LPFC_SLI_INTF_IF_TYPE_2:
8822 case LPFC_SLI_INTF_IF_TYPE_6:
8823 /* Final checks. The port status should be clean. */
8824 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
8826 (bf_get(lpfc_sliport_status_err, ®_data) &&
8827 !bf_get(lpfc_sliport_status_rn, ®_data))) {
8828 phba->work_status[0] =
8829 readl(phba->sli4_hba.u.if_type2.
8831 phba->work_status[1] =
8832 readl(phba->sli4_hba.u.if_type2.
8834 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8835 "2888 Unrecoverable port error "
8836 "following POST: port status reg "
8837 "0x%x, port_smphr reg 0x%x, "
8838 "error 1=0x%x, error 2=0x%x\n",
8840 portsmphr_reg.word0,
8841 phba->work_status[0],
8842 phba->work_status[1]);
8843 port_error = -ENODEV;
8846 case LPFC_SLI_INTF_IF_TYPE_1:
8855 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
8856 * @phba: pointer to lpfc hba data structure.
8857 * @if_type: The SLI4 interface type getting configured.
8859 * This routine is invoked to set up SLI4 BAR0 PCI config space register
8863 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
8866 case LPFC_SLI_INTF_IF_TYPE_0:
8867 phba->sli4_hba.u.if_type0.UERRLOregaddr =
8868 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
8869 phba->sli4_hba.u.if_type0.UERRHIregaddr =
8870 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
8871 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
8872 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
8873 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
8874 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
8875 phba->sli4_hba.SLIINTFregaddr =
8876 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8878 case LPFC_SLI_INTF_IF_TYPE_2:
8879 phba->sli4_hba.u.if_type2.EQDregaddr =
8880 phba->sli4_hba.conf_regs_memmap_p +
8881 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8882 phba->sli4_hba.u.if_type2.ERR1regaddr =
8883 phba->sli4_hba.conf_regs_memmap_p +
8884 LPFC_CTL_PORT_ER1_OFFSET;
8885 phba->sli4_hba.u.if_type2.ERR2regaddr =
8886 phba->sli4_hba.conf_regs_memmap_p +
8887 LPFC_CTL_PORT_ER2_OFFSET;
8888 phba->sli4_hba.u.if_type2.CTRLregaddr =
8889 phba->sli4_hba.conf_regs_memmap_p +
8890 LPFC_CTL_PORT_CTL_OFFSET;
8891 phba->sli4_hba.u.if_type2.STATUSregaddr =
8892 phba->sli4_hba.conf_regs_memmap_p +
8893 LPFC_CTL_PORT_STA_OFFSET;
8894 phba->sli4_hba.SLIINTFregaddr =
8895 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8896 phba->sli4_hba.PSMPHRregaddr =
8897 phba->sli4_hba.conf_regs_memmap_p +
8898 LPFC_CTL_PORT_SEM_OFFSET;
8899 phba->sli4_hba.RQDBregaddr =
8900 phba->sli4_hba.conf_regs_memmap_p +
8901 LPFC_ULP0_RQ_DOORBELL;
8902 phba->sli4_hba.WQDBregaddr =
8903 phba->sli4_hba.conf_regs_memmap_p +
8904 LPFC_ULP0_WQ_DOORBELL;
8905 phba->sli4_hba.CQDBregaddr =
8906 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
8907 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
8908 phba->sli4_hba.MQDBregaddr =
8909 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
8910 phba->sli4_hba.BMBXregaddr =
8911 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8913 case LPFC_SLI_INTF_IF_TYPE_6:
8914 phba->sli4_hba.u.if_type2.EQDregaddr =
8915 phba->sli4_hba.conf_regs_memmap_p +
8916 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8917 phba->sli4_hba.u.if_type2.ERR1regaddr =
8918 phba->sli4_hba.conf_regs_memmap_p +
8919 LPFC_CTL_PORT_ER1_OFFSET;
8920 phba->sli4_hba.u.if_type2.ERR2regaddr =
8921 phba->sli4_hba.conf_regs_memmap_p +
8922 LPFC_CTL_PORT_ER2_OFFSET;
8923 phba->sli4_hba.u.if_type2.CTRLregaddr =
8924 phba->sli4_hba.conf_regs_memmap_p +
8925 LPFC_CTL_PORT_CTL_OFFSET;
8926 phba->sli4_hba.u.if_type2.STATUSregaddr =
8927 phba->sli4_hba.conf_regs_memmap_p +
8928 LPFC_CTL_PORT_STA_OFFSET;
8929 phba->sli4_hba.PSMPHRregaddr =
8930 phba->sli4_hba.conf_regs_memmap_p +
8931 LPFC_CTL_PORT_SEM_OFFSET;
8932 phba->sli4_hba.BMBXregaddr =
8933 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8935 case LPFC_SLI_INTF_IF_TYPE_1:
8937 dev_printk(KERN_ERR, &phba->pcidev->dev,
8938 "FATAL - unsupported SLI4 interface type - %d\n",
8945 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8946 * @phba: pointer to lpfc hba data structure.
8947 * @if_type: sli if type to operate on.
8949 * This routine is invoked to set up SLI4 BAR1 register memory map.
8952 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
8955 case LPFC_SLI_INTF_IF_TYPE_0:
8956 phba->sli4_hba.PSMPHRregaddr =
8957 phba->sli4_hba.ctrl_regs_memmap_p +
8958 LPFC_SLIPORT_IF0_SMPHR;
8959 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8961 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8963 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8966 case LPFC_SLI_INTF_IF_TYPE_6:
8967 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8968 LPFC_IF6_RQ_DOORBELL;
8969 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8970 LPFC_IF6_WQ_DOORBELL;
8971 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8972 LPFC_IF6_CQ_DOORBELL;
8973 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8974 LPFC_IF6_EQ_DOORBELL;
8975 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8976 LPFC_IF6_MQ_DOORBELL;
8978 case LPFC_SLI_INTF_IF_TYPE_2:
8979 case LPFC_SLI_INTF_IF_TYPE_1:
8981 dev_err(&phba->pcidev->dev,
8982 "FATAL - unsupported SLI4 interface type - %d\n",
8989 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8990 * @phba: pointer to lpfc hba data structure.
8991 * @vf: virtual function number
8993 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8994 * based on the given viftual function number, @vf.
8996 * Return 0 if successful, otherwise -ENODEV.
8999 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9001 if (vf > LPFC_VIR_FUNC_MAX)
9004 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9005 vf * LPFC_VFR_PAGE_SIZE +
9006 LPFC_ULP0_RQ_DOORBELL);
9007 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9008 vf * LPFC_VFR_PAGE_SIZE +
9009 LPFC_ULP0_WQ_DOORBELL);
9010 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9011 vf * LPFC_VFR_PAGE_SIZE +
9012 LPFC_EQCQ_DOORBELL);
9013 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
9014 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9015 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9016 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9017 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9022 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9023 * @phba: pointer to lpfc hba data structure.
9025 * This routine is invoked to create the bootstrap mailbox
9026 * region consistent with the SLI-4 interface spec. This
9027 * routine allocates all memory necessary to communicate
9028 * mailbox commands to the port and sets up all alignment
9029 * needs. No locks are expected to be held when calling
9034 * -ENOMEM - could not allocated memory.
9037 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9040 struct lpfc_dmabuf *dmabuf;
9041 struct dma_address *dma_address;
9045 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9050 * The bootstrap mailbox region is comprised of 2 parts
9051 * plus an alignment restriction of 16 bytes.
9053 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
9054 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9055 &dmabuf->phys, GFP_KERNEL);
9056 if (!dmabuf->virt) {
9062 * Initialize the bootstrap mailbox pointers now so that the register
9063 * operations are simple later. The mailbox dma address is required
9064 * to be 16-byte aligned. Also align the virtual memory as each
9065 * maibox is copied into the bmbx mailbox region before issuing the
9066 * command to the port.
9068 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9069 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9071 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9072 LPFC_ALIGN_16_BYTE);
9073 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9074 LPFC_ALIGN_16_BYTE);
9077 * Set the high and low physical addresses now. The SLI4 alignment
9078 * requirement is 16 bytes and the mailbox is posted to the port
9079 * as two 30-bit addresses. The other data is a bit marking whether
9080 * the 30-bit address is the high or low address.
9081 * Upcast bmbx aphys to 64bits so shift instruction compiles
9082 * clean on 32 bit machines.
9084 dma_address = &phba->sli4_hba.bmbx.dma_address;
9085 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9086 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9087 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9088 LPFC_BMBX_BIT1_ADDR_HI);
9090 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9091 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9092 LPFC_BMBX_BIT1_ADDR_LO);
9097 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9098 * @phba: pointer to lpfc hba data structure.
9100 * This routine is invoked to teardown the bootstrap mailbox
9101 * region and release all host resources. This routine requires
9102 * the caller to ensure all mailbox commands recovered, no
9103 * additional mailbox comands are sent, and interrupts are disabled
9104 * before calling this routine.
9108 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9110 dma_free_coherent(&phba->pcidev->dev,
9111 phba->sli4_hba.bmbx.bmbx_size,
9112 phba->sli4_hba.bmbx.dmabuf->virt,
9113 phba->sli4_hba.bmbx.dmabuf->phys);
9115 kfree(phba->sli4_hba.bmbx.dmabuf);
9116 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9119 static const char * const lpfc_topo_to_str[] = {
9129 #define LINK_FLAGS_DEF 0x0
9130 #define LINK_FLAGS_P2P 0x1
9131 #define LINK_FLAGS_LOOP 0x2
9133 * lpfc_map_topology - Map the topology read from READ_CONFIG
9134 * @phba: pointer to lpfc hba data structure.
9135 * @rd_config: pointer to read config data
9137 * This routine is invoked to map the topology values as read
9138 * from the read config mailbox command. If the persistent
9139 * topology feature is supported, the firmware will provide the
9140 * saved topology information to be used in INIT_LINK
9143 lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9147 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9148 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9149 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9151 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9152 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9155 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9156 "2019 FW does not support persistent topology "
9157 "Using driver parameter defined value [%s]",
9158 lpfc_topo_to_str[phba->cfg_topology]);
9161 /* FW supports persistent topology - override module parameter value */
9162 phba->hba_flag |= HBA_PERSISTENT_TOPO;
9164 /* if ASIC_GEN_NUM >= 0xC) */
9165 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9166 LPFC_SLI_INTF_IF_TYPE_6) ||
9167 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9168 LPFC_SLI_INTF_FAMILY_G6)) {
9170 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9171 ? FLAGS_TOPOLOGY_MODE_LOOP
9172 : FLAGS_TOPOLOGY_MODE_PT_PT);
9174 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
9178 /* If topology failover set - pt is '0' or '1' */
9179 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9180 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9182 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9183 ? FLAGS_TOPOLOGY_MODE_PT_PT
9184 : FLAGS_TOPOLOGY_MODE_LOOP);
9187 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
9188 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9189 "2020 Using persistent topology value [%s]",
9190 lpfc_topo_to_str[phba->cfg_topology]);
9192 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9193 "2021 Invalid topology values from FW "
9194 "Using driver parameter defined value [%s]",
9195 lpfc_topo_to_str[phba->cfg_topology]);
9200 * lpfc_sli4_read_config - Get the config parameters.
9201 * @phba: pointer to lpfc hba data structure.
9203 * This routine is invoked to read the configuration parameters from the HBA.
9204 * The configuration parameters are used to set the base and maximum values
9205 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9206 * allocation for the port.
9210 * -ENOMEM - No available memory
9211 * -EIO - The mailbox failed to complete successfully.
9214 lpfc_sli4_read_config(struct lpfc_hba *phba)
9217 struct lpfc_mbx_read_config *rd_config;
9218 union lpfc_sli4_cfg_shdr *shdr;
9219 uint32_t shdr_status, shdr_add_status;
9220 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9221 struct lpfc_rsrc_desc_fcfcoe *desc;
9223 uint16_t forced_link_speed;
9224 uint32_t if_type, qmin;
9225 int length, i, rc = 0, rc2;
9227 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9229 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9230 "2011 Unable to allocate memory for issuing "
9231 "SLI_CONFIG_SPECIAL mailbox command\n");
9235 lpfc_read_config(phba, pmb);
9237 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9238 if (rc != MBX_SUCCESS) {
9239 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9240 "2012 Mailbox failed , mbxCmd x%x "
9241 "READ_CONFIG, mbxStatus x%x\n",
9242 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9243 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9246 rd_config = &pmb->u.mqe.un.rd_config;
9247 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9248 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
9249 phba->sli4_hba.lnk_info.lnk_tp =
9250 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
9251 phba->sli4_hba.lnk_info.lnk_no =
9252 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
9253 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9254 "3081 lnk_type:%d, lnk_numb:%d\n",
9255 phba->sli4_hba.lnk_info.lnk_tp,
9256 phba->sli4_hba.lnk_info.lnk_no);
9258 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9259 "3082 Mailbox (x%x) returned ldv:x0\n",
9260 bf_get(lpfc_mqe_command, &pmb->u.mqe));
9261 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
9262 phba->bbcredit_support = 1;
9263 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
9266 phba->sli4_hba.conf_trunk =
9267 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
9268 phba->sli4_hba.extents_in_use =
9269 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
9270 phba->sli4_hba.max_cfg_param.max_xri =
9271 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
9272 /* Reduce resource usage in kdump environment */
9273 if (is_kdump_kernel() &&
9274 phba->sli4_hba.max_cfg_param.max_xri > 512)
9275 phba->sli4_hba.max_cfg_param.max_xri = 512;
9276 phba->sli4_hba.max_cfg_param.xri_base =
9277 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
9278 phba->sli4_hba.max_cfg_param.max_vpi =
9279 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
9280 /* Limit the max we support */
9281 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
9282 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
9283 phba->sli4_hba.max_cfg_param.vpi_base =
9284 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
9285 phba->sli4_hba.max_cfg_param.max_rpi =
9286 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
9287 phba->sli4_hba.max_cfg_param.rpi_base =
9288 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
9289 phba->sli4_hba.max_cfg_param.max_vfi =
9290 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
9291 phba->sli4_hba.max_cfg_param.vfi_base =
9292 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
9293 phba->sli4_hba.max_cfg_param.max_fcfi =
9294 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
9295 phba->sli4_hba.max_cfg_param.max_eq =
9296 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
9297 phba->sli4_hba.max_cfg_param.max_rq =
9298 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
9299 phba->sli4_hba.max_cfg_param.max_wq =
9300 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
9301 phba->sli4_hba.max_cfg_param.max_cq =
9302 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
9303 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
9304 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
9305 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
9306 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
9307 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
9308 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
9309 phba->max_vports = phba->max_vpi;
9311 /* Next decide on FPIN or Signal E2E CGN support
9312 * For congestion alarms and warnings valid combination are:
9313 * 1. FPIN alarms / FPIN warnings
9314 * 2. Signal alarms / Signal warnings
9315 * 3. FPIN alarms / Signal warnings
9316 * 4. Signal alarms / FPIN warnings
9318 * Initialize the adapter frequency to 100 mSecs
9320 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9321 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9322 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9324 if (lpfc_use_cgn_signal) {
9325 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
9326 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
9327 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
9329 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
9330 /* MUST support both alarm and warning
9331 * because EDC does not support alarm alone.
9333 if (phba->cgn_reg_signal !=
9334 EDC_CG_SIG_WARN_ONLY) {
9335 /* Must support both or none */
9336 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9337 phba->cgn_reg_signal =
9338 EDC_CG_SIG_NOTSUPPORTED;
9340 phba->cgn_reg_signal =
9341 EDC_CG_SIG_WARN_ALARM;
9342 phba->cgn_reg_fpin =
9348 /* Set the congestion initial signal and fpin values. */
9349 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
9350 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
9352 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
9353 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
9354 phba->cgn_reg_signal, phba->cgn_reg_fpin);
9356 lpfc_map_topology(phba, rd_config);
9357 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9358 "2003 cfg params Extents? %d "
9363 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
9364 phba->sli4_hba.extents_in_use,
9365 phba->sli4_hba.max_cfg_param.xri_base,
9366 phba->sli4_hba.max_cfg_param.max_xri,
9367 phba->sli4_hba.max_cfg_param.vpi_base,
9368 phba->sli4_hba.max_cfg_param.max_vpi,
9369 phba->sli4_hba.max_cfg_param.vfi_base,
9370 phba->sli4_hba.max_cfg_param.max_vfi,
9371 phba->sli4_hba.max_cfg_param.rpi_base,
9372 phba->sli4_hba.max_cfg_param.max_rpi,
9373 phba->sli4_hba.max_cfg_param.max_fcfi,
9374 phba->sli4_hba.max_cfg_param.max_eq,
9375 phba->sli4_hba.max_cfg_param.max_cq,
9376 phba->sli4_hba.max_cfg_param.max_wq,
9377 phba->sli4_hba.max_cfg_param.max_rq,
9381 * Calculate queue resources based on how
9382 * many WQ/CQ/EQs are available.
9384 qmin = phba->sli4_hba.max_cfg_param.max_wq;
9385 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
9386 qmin = phba->sli4_hba.max_cfg_param.max_cq;
9387 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
9388 qmin = phba->sli4_hba.max_cfg_param.max_eq;
9390 * Whats left after this can go toward NVME / FCP.
9391 * The minus 4 accounts for ELS, NVME LS, MBOX
9392 * plus one extra. When configured for
9393 * NVMET, FCP io channel WQs are not created.
9397 /* Check to see if there is enough for NVME */
9398 if ((phba->cfg_irq_chann > qmin) ||
9399 (phba->cfg_hdw_queue > qmin)) {
9400 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9401 "2005 Reducing Queues - "
9402 "FW resource limitation: "
9403 "WQ %d CQ %d EQ %d: min %d: "
9405 phba->sli4_hba.max_cfg_param.max_wq,
9406 phba->sli4_hba.max_cfg_param.max_cq,
9407 phba->sli4_hba.max_cfg_param.max_eq,
9408 qmin, phba->cfg_irq_chann,
9409 phba->cfg_hdw_queue);
9411 if (phba->cfg_irq_chann > qmin)
9412 phba->cfg_irq_chann = qmin;
9413 if (phba->cfg_hdw_queue > qmin)
9414 phba->cfg_hdw_queue = qmin;
9421 /* Update link speed if forced link speed is supported */
9422 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9423 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9425 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
9426 if (forced_link_speed) {
9427 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
9429 switch (forced_link_speed) {
9431 phba->cfg_link_speed =
9432 LPFC_USER_LINK_SPEED_1G;
9435 phba->cfg_link_speed =
9436 LPFC_USER_LINK_SPEED_2G;
9439 phba->cfg_link_speed =
9440 LPFC_USER_LINK_SPEED_4G;
9443 phba->cfg_link_speed =
9444 LPFC_USER_LINK_SPEED_8G;
9446 case LINK_SPEED_10G:
9447 phba->cfg_link_speed =
9448 LPFC_USER_LINK_SPEED_10G;
9450 case LINK_SPEED_16G:
9451 phba->cfg_link_speed =
9452 LPFC_USER_LINK_SPEED_16G;
9454 case LINK_SPEED_32G:
9455 phba->cfg_link_speed =
9456 LPFC_USER_LINK_SPEED_32G;
9458 case LINK_SPEED_64G:
9459 phba->cfg_link_speed =
9460 LPFC_USER_LINK_SPEED_64G;
9463 phba->cfg_link_speed =
9464 LPFC_USER_LINK_SPEED_AUTO;
9467 lpfc_printf_log(phba, KERN_ERR,
9469 "0047 Unrecognized link "
9472 phba->cfg_link_speed =
9473 LPFC_USER_LINK_SPEED_AUTO;
9478 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
9479 length = phba->sli4_hba.max_cfg_param.max_xri -
9480 lpfc_sli4_get_els_iocb_cnt(phba);
9481 if (phba->cfg_hba_queue_depth > length) {
9482 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9483 "3361 HBA queue depth changed from %d to %d\n",
9484 phba->cfg_hba_queue_depth, length);
9485 phba->cfg_hba_queue_depth = length;
9488 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
9489 LPFC_SLI_INTF_IF_TYPE_2)
9492 /* get the pf# and vf# for SLI4 if_type 2 port */
9493 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
9494 sizeof(struct lpfc_sli4_cfg_mhdr));
9495 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
9496 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
9497 length, LPFC_SLI4_MBX_EMBED);
9499 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9500 shdr = (union lpfc_sli4_cfg_shdr *)
9501 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
9502 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9503 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9504 if (rc2 || shdr_status || shdr_add_status) {
9505 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9506 "3026 Mailbox failed , mbxCmd x%x "
9507 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
9508 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9509 bf_get(lpfc_mqe_status, &pmb->u.mqe));
9513 /* search for fc_fcoe resrouce descriptor */
9514 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
9516 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
9517 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
9518 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
9519 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
9520 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
9521 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
9524 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
9525 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
9526 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
9527 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
9528 phba->sli4_hba.iov.pf_number =
9529 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
9530 phba->sli4_hba.iov.vf_number =
9531 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
9536 if (i < LPFC_RSRC_DESC_MAX_NUM)
9537 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9538 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
9539 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
9540 phba->sli4_hba.iov.vf_number);
9542 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9543 "3028 GET_FUNCTION_CONFIG: failed to find "
9544 "Resource Descriptor:x%x\n",
9545 LPFC_RSRC_DESC_TYPE_FCFCOE);
9548 mempool_free(pmb, phba->mbox_mem_pool);
9553 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
9554 * @phba: pointer to lpfc hba data structure.
9556 * This routine is invoked to setup the port-side endian order when
9557 * the port if_type is 0. This routine has no function for other
9562 * -ENOMEM - No available memory
9563 * -EIO - The mailbox failed to complete successfully.
9566 lpfc_setup_endian_order(struct lpfc_hba *phba)
9568 LPFC_MBOXQ_t *mboxq;
9569 uint32_t if_type, rc = 0;
9570 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
9571 HOST_ENDIAN_HIGH_WORD1};
9573 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9575 case LPFC_SLI_INTF_IF_TYPE_0:
9576 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9579 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9580 "0492 Unable to allocate memory for "
9581 "issuing SLI_CONFIG_SPECIAL mailbox "
9587 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
9588 * two words to contain special data values and no other data.
9590 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
9591 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
9592 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9593 if (rc != MBX_SUCCESS) {
9594 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9595 "0493 SLI_CONFIG_SPECIAL mailbox "
9596 "failed with status x%x\n",
9600 mempool_free(mboxq, phba->mbox_mem_pool);
9602 case LPFC_SLI_INTF_IF_TYPE_6:
9603 case LPFC_SLI_INTF_IF_TYPE_2:
9604 case LPFC_SLI_INTF_IF_TYPE_1:
9612 * lpfc_sli4_queue_verify - Verify and update EQ counts
9613 * @phba: pointer to lpfc hba data structure.
9615 * This routine is invoked to check the user settable queue counts for EQs.
9616 * After this routine is called the counts will be set to valid values that
9617 * adhere to the constraints of the system's interrupt vectors and the port's
9622 * -ENOMEM - No available memory
9625 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
9628 * Sanity check for configured queue parameters against the run-time
9632 if (phba->nvmet_support) {
9633 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
9634 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
9635 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
9636 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
9639 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9640 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
9641 phba->cfg_hdw_queue, phba->cfg_irq_chann,
9642 phba->cfg_nvmet_mrq);
9644 /* Get EQ depth from module parameter, fake the default for now */
9645 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
9646 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
9648 /* Get CQ depth from module parameter, fake the default for now */
9649 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
9650 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
9655 lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
9657 struct lpfc_queue *qdesc;
9661 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
9662 /* Create Fast Path IO CQs */
9663 if (phba->enab_exp_wqcq_pages)
9664 /* Increase the CQ size when WQEs contain an embedded cdb */
9665 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
9666 phba->sli4_hba.cq_esize,
9667 LPFC_CQE_EXP_COUNT, cpu);
9670 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9671 phba->sli4_hba.cq_esize,
9672 phba->sli4_hba.cq_ecount, cpu);
9674 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9675 "0499 Failed allocate fast-path IO CQ (%d)\n",
9679 qdesc->qe_valid = 1;
9682 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
9684 /* Create Fast Path IO WQs */
9685 if (phba->enab_exp_wqcq_pages) {
9686 /* Increase the WQ size when WQEs contain an embedded cdb */
9687 wqesize = (phba->fcp_embed_io) ?
9688 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
9689 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
9691 LPFC_WQE_EXP_COUNT, cpu);
9693 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9694 phba->sli4_hba.wq_esize,
9695 phba->sli4_hba.wq_ecount, cpu);
9698 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9699 "0503 Failed allocate fast-path IO WQ (%d)\n",
9705 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
9706 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9711 * lpfc_sli4_queue_create - Create all the SLI4 queues
9712 * @phba: pointer to lpfc hba data structure.
9714 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
9715 * operation. For each SLI4 queue type, the parameters such as queue entry
9716 * count (queue depth) shall be taken from the module parameter. For now,
9717 * we just use some constant number as place holder.
9721 * -ENOMEM - No availble memory
9722 * -EIO - The mailbox failed to complete successfully.
9725 lpfc_sli4_queue_create(struct lpfc_hba *phba)
9727 struct lpfc_queue *qdesc;
9728 int idx, cpu, eqcpu;
9729 struct lpfc_sli4_hdw_queue *qp;
9730 struct lpfc_vector_map_info *cpup;
9731 struct lpfc_vector_map_info *eqcpup;
9732 struct lpfc_eq_intr_info *eqi;
9735 * Create HBA Record arrays.
9736 * Both NVME and FCP will share that same vectors / EQs
9738 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
9739 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
9740 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
9741 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
9742 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
9743 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
9744 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
9745 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
9746 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
9747 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
9749 if (!phba->sli4_hba.hdwq) {
9750 phba->sli4_hba.hdwq = kcalloc(
9751 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
9753 if (!phba->sli4_hba.hdwq) {
9754 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9755 "6427 Failed allocate memory for "
9756 "fast-path Hardware Queue array\n");
9759 /* Prepare hardware queues to take IO buffers */
9760 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9761 qp = &phba->sli4_hba.hdwq[idx];
9762 spin_lock_init(&qp->io_buf_list_get_lock);
9763 spin_lock_init(&qp->io_buf_list_put_lock);
9764 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
9765 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
9766 qp->get_io_bufs = 0;
9767 qp->put_io_bufs = 0;
9768 qp->total_io_bufs = 0;
9769 spin_lock_init(&qp->abts_io_buf_list_lock);
9770 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
9771 qp->abts_scsi_io_bufs = 0;
9772 qp->abts_nvme_io_bufs = 0;
9773 INIT_LIST_HEAD(&qp->sgl_list);
9774 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
9775 spin_lock_init(&qp->hdwq_lock);
9779 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9780 if (phba->nvmet_support) {
9781 phba->sli4_hba.nvmet_cqset = kcalloc(
9782 phba->cfg_nvmet_mrq,
9783 sizeof(struct lpfc_queue *),
9785 if (!phba->sli4_hba.nvmet_cqset) {
9786 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9787 "3121 Fail allocate memory for "
9788 "fast-path CQ set array\n");
9791 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
9792 phba->cfg_nvmet_mrq,
9793 sizeof(struct lpfc_queue *),
9795 if (!phba->sli4_hba.nvmet_mrq_hdr) {
9796 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9797 "3122 Fail allocate memory for "
9798 "fast-path RQ set hdr array\n");
9801 phba->sli4_hba.nvmet_mrq_data = kcalloc(
9802 phba->cfg_nvmet_mrq,
9803 sizeof(struct lpfc_queue *),
9805 if (!phba->sli4_hba.nvmet_mrq_data) {
9806 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9807 "3124 Fail allocate memory for "
9808 "fast-path RQ set data array\n");
9814 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
9816 /* Create HBA Event Queues (EQs) */
9817 for_each_present_cpu(cpu) {
9818 /* We only want to create 1 EQ per vector, even though
9819 * multiple CPUs might be using that vector. so only
9820 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
9822 cpup = &phba->sli4_hba.cpu_map[cpu];
9823 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
9826 /* Get a ptr to the Hardware Queue associated with this CPU */
9827 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
9829 /* Allocate an EQ */
9830 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9831 phba->sli4_hba.eq_esize,
9832 phba->sli4_hba.eq_ecount, cpu);
9834 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9835 "0497 Failed allocate EQ (%d)\n",
9839 qdesc->qe_valid = 1;
9840 qdesc->hdwq = cpup->hdwq;
9841 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
9842 qdesc->last_cpu = qdesc->chann;
9844 /* Save the allocated EQ in the Hardware Queue */
9847 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
9848 list_add(&qdesc->cpu_list, &eqi->list);
9851 /* Now we need to populate the other Hardware Queues, that share
9852 * an IRQ vector, with the associated EQ ptr.
9854 for_each_present_cpu(cpu) {
9855 cpup = &phba->sli4_hba.cpu_map[cpu];
9857 /* Check for EQ already allocated in previous loop */
9858 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
9861 /* Check for multiple CPUs per hdwq */
9862 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
9866 /* We need to share an EQ for this hdwq */
9867 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
9868 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
9869 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
9872 /* Allocate IO Path SLI4 CQ/WQs */
9873 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9874 if (lpfc_alloc_io_wq_cq(phba, idx))
9878 if (phba->nvmet_support) {
9879 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
9880 cpu = lpfc_find_cpu_handle(phba, idx,
9882 qdesc = lpfc_sli4_queue_alloc(phba,
9883 LPFC_DEFAULT_PAGE_SIZE,
9884 phba->sli4_hba.cq_esize,
9885 phba->sli4_hba.cq_ecount,
9888 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9889 "3142 Failed allocate NVME "
9890 "CQ Set (%d)\n", idx);
9893 qdesc->qe_valid = 1;
9896 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
9901 * Create Slow Path Completion Queues (CQs)
9904 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
9905 /* Create slow-path Mailbox Command Complete Queue */
9906 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9907 phba->sli4_hba.cq_esize,
9908 phba->sli4_hba.cq_ecount, cpu);
9910 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9911 "0500 Failed allocate slow-path mailbox CQ\n");
9914 qdesc->qe_valid = 1;
9915 phba->sli4_hba.mbx_cq = qdesc;
9917 /* Create slow-path ELS Complete Queue */
9918 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9919 phba->sli4_hba.cq_esize,
9920 phba->sli4_hba.cq_ecount, cpu);
9922 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9923 "0501 Failed allocate slow-path ELS CQ\n");
9926 qdesc->qe_valid = 1;
9928 phba->sli4_hba.els_cq = qdesc;
9932 * Create Slow Path Work Queues (WQs)
9935 /* Create Mailbox Command Queue */
9937 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9938 phba->sli4_hba.mq_esize,
9939 phba->sli4_hba.mq_ecount, cpu);
9941 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9942 "0505 Failed allocate slow-path MQ\n");
9946 phba->sli4_hba.mbx_wq = qdesc;
9949 * Create ELS Work Queues
9952 /* Create slow-path ELS Work Queue */
9953 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9954 phba->sli4_hba.wq_esize,
9955 phba->sli4_hba.wq_ecount, cpu);
9957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9958 "0504 Failed allocate slow-path ELS WQ\n");
9962 phba->sli4_hba.els_wq = qdesc;
9963 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9965 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9966 /* Create NVME LS Complete Queue */
9967 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9968 phba->sli4_hba.cq_esize,
9969 phba->sli4_hba.cq_ecount, cpu);
9971 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9972 "6079 Failed allocate NVME LS CQ\n");
9976 qdesc->qe_valid = 1;
9977 phba->sli4_hba.nvmels_cq = qdesc;
9979 /* Create NVME LS Work Queue */
9980 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9981 phba->sli4_hba.wq_esize,
9982 phba->sli4_hba.wq_ecount, cpu);
9984 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9985 "6080 Failed allocate NVME LS WQ\n");
9989 phba->sli4_hba.nvmels_wq = qdesc;
9990 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9994 * Create Receive Queue (RQ)
9997 /* Create Receive Queue for header */
9998 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9999 phba->sli4_hba.rq_esize,
10000 phba->sli4_hba.rq_ecount, cpu);
10002 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10003 "0506 Failed allocate receive HRQ\n");
10006 phba->sli4_hba.hdr_rq = qdesc;
10008 /* Create Receive Queue for data */
10009 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10010 phba->sli4_hba.rq_esize,
10011 phba->sli4_hba.rq_ecount, cpu);
10013 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10014 "0507 Failed allocate receive DRQ\n");
10017 phba->sli4_hba.dat_rq = qdesc;
10019 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10020 phba->nvmet_support) {
10021 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10022 cpu = lpfc_find_cpu_handle(phba, idx,
10023 LPFC_FIND_BY_HDWQ);
10024 /* Create NVMET Receive Queue for header */
10025 qdesc = lpfc_sli4_queue_alloc(phba,
10026 LPFC_DEFAULT_PAGE_SIZE,
10027 phba->sli4_hba.rq_esize,
10028 LPFC_NVMET_RQE_DEF_COUNT,
10031 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10032 "3146 Failed allocate "
10037 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10039 /* Only needed for header of RQ pair */
10040 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10043 if (qdesc->rqbp == NULL) {
10044 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10045 "6131 Failed allocate "
10050 /* Put list in known state in case driver load fails. */
10051 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10053 /* Create NVMET Receive Queue for data */
10054 qdesc = lpfc_sli4_queue_alloc(phba,
10055 LPFC_DEFAULT_PAGE_SIZE,
10056 phba->sli4_hba.rq_esize,
10057 LPFC_NVMET_RQE_DEF_COUNT,
10060 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10061 "3156 Failed allocate "
10066 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10070 /* Clear NVME stats */
10071 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10072 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10073 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10074 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10078 /* Clear SCSI stats */
10079 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10080 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10081 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10082 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10089 lpfc_sli4_queue_destroy(phba);
10094 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
10097 lpfc_sli4_queue_free(*qp);
10103 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10110 for (idx = 0; idx < max; idx++)
10111 __lpfc_sli4_release_queue(&(*qs)[idx]);
10118 lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
10120 struct lpfc_sli4_hdw_queue *hdwq;
10121 struct lpfc_queue *eq;
10124 hdwq = phba->sli4_hba.hdwq;
10126 /* Loop thru all Hardware Queues */
10127 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10128 /* Free the CQ/WQ corresponding to the Hardware Queue */
10129 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10130 lpfc_sli4_queue_free(hdwq[idx].io_wq);
10131 hdwq[idx].hba_eq = NULL;
10132 hdwq[idx].io_cq = NULL;
10133 hdwq[idx].io_wq = NULL;
10134 if (phba->cfg_xpsgl && !phba->nvmet_support)
10135 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10136 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
10138 /* Loop thru all IRQ vectors */
10139 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10140 /* Free the EQ corresponding to the IRQ vector */
10141 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10142 lpfc_sli4_queue_free(eq);
10143 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10148 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10149 * @phba: pointer to lpfc hba data structure.
10151 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10156 * -ENOMEM - No available memory
10157 * -EIO - The mailbox failed to complete successfully.
10160 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10163 * Set FREE_INIT before beginning to free the queues.
10164 * Wait until the users of queues to acknowledge to
10165 * release queues by clearing FREE_WAIT.
10167 spin_lock_irq(&phba->hbalock);
10168 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10169 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10170 spin_unlock_irq(&phba->hbalock);
10172 spin_lock_irq(&phba->hbalock);
10174 spin_unlock_irq(&phba->hbalock);
10176 lpfc_sli4_cleanup_poll_list(phba);
10178 /* Release HBA eqs */
10179 if (phba->sli4_hba.hdwq)
10180 lpfc_sli4_release_hdwq(phba);
10182 if (phba->nvmet_support) {
10183 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10184 phba->cfg_nvmet_mrq);
10186 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10187 phba->cfg_nvmet_mrq);
10188 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10189 phba->cfg_nvmet_mrq);
10192 /* Release mailbox command work queue */
10193 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
10195 /* Release ELS work queue */
10196 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10198 /* Release ELS work queue */
10199 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
10201 /* Release unsolicited receive queue */
10202 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10203 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
10205 /* Release ELS complete queue */
10206 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10208 /* Release NVME LS complete queue */
10209 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
10211 /* Release mailbox command complete queue */
10212 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10214 /* Everything on this list has been freed */
10215 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
10217 /* Done with freeing the queues */
10218 spin_lock_irq(&phba->hbalock);
10219 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10220 spin_unlock_irq(&phba->hbalock);
10224 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10226 struct lpfc_rqb *rqbp;
10227 struct lpfc_dmabuf *h_buf;
10228 struct rqb_dmabuf *rqb_buffer;
10231 while (!list_empty(&rqbp->rqb_buffer_list)) {
10232 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10233 struct lpfc_dmabuf, list);
10235 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10236 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
10237 rqbp->buffer_count--;
10243 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
10244 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
10245 int qidx, uint32_t qtype)
10247 struct lpfc_sli_ring *pring;
10250 if (!eq || !cq || !wq) {
10251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10252 "6085 Fast-path %s (%d) not allocated\n",
10253 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
10257 /* create the Cq first */
10258 rc = lpfc_cq_create(phba, cq, eq,
10259 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
10261 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10262 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
10263 qidx, (uint32_t)rc);
10267 if (qtype != LPFC_MBOX) {
10268 /* Setup cq_map for fast lookup */
10270 *cq_map = cq->queue_id;
10272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10273 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
10274 qidx, cq->queue_id, qidx, eq->queue_id);
10276 /* create the wq */
10277 rc = lpfc_wq_create(phba, wq, cq, qtype);
10279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10280 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
10281 qidx, (uint32_t)rc);
10282 /* no need to tear down cq - caller will do so */
10286 /* Bind this CQ/WQ to the NVME ring */
10288 pring->sli.sli4.wqp = (void *)wq;
10291 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10292 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
10293 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
10295 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
10297 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10298 "0539 Failed setup of slow-path MQ: "
10299 "rc = 0x%x\n", rc);
10300 /* no need to tear down cq - caller will do so */
10304 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10305 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
10306 phba->sli4_hba.mbx_wq->queue_id,
10307 phba->sli4_hba.mbx_cq->queue_id);
10314 * lpfc_setup_cq_lookup - Setup the CQ lookup table
10315 * @phba: pointer to lpfc hba data structure.
10317 * This routine will populate the cq_lookup table by all
10318 * available CQ queue_id's.
10321 lpfc_setup_cq_lookup(struct lpfc_hba *phba)
10323 struct lpfc_queue *eq, *childq;
10326 memset(phba->sli4_hba.cq_lookup, 0,
10327 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
10328 /* Loop thru all IRQ vectors */
10329 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10330 /* Get the EQ corresponding to the IRQ vector */
10331 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
10334 /* Loop through all CQs associated with that EQ */
10335 list_for_each_entry(childq, &eq->child_list, list) {
10336 if (childq->queue_id > phba->sli4_hba.cq_max)
10338 if (childq->subtype == LPFC_IO)
10339 phba->sli4_hba.cq_lookup[childq->queue_id] =
10346 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
10347 * @phba: pointer to lpfc hba data structure.
10349 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
10354 * -ENOMEM - No available memory
10355 * -EIO - The mailbox failed to complete successfully.
10358 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
10360 uint32_t shdr_status, shdr_add_status;
10361 union lpfc_sli4_cfg_shdr *shdr;
10362 struct lpfc_vector_map_info *cpup;
10363 struct lpfc_sli4_hdw_queue *qp;
10364 LPFC_MBOXQ_t *mboxq;
10366 uint32_t length, usdelay;
10369 /* Check for dual-ULP support */
10370 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10372 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10373 "3249 Unable to allocate memory for "
10374 "QUERY_FW_CFG mailbox command\n");
10377 length = (sizeof(struct lpfc_mbx_query_fw_config) -
10378 sizeof(struct lpfc_sli4_cfg_mhdr));
10379 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10380 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
10381 length, LPFC_SLI4_MBX_EMBED);
10383 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10385 shdr = (union lpfc_sli4_cfg_shdr *)
10386 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10387 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10388 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10389 if (shdr_status || shdr_add_status || rc) {
10390 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10391 "3250 QUERY_FW_CFG mailbox failed with status "
10392 "x%x add_status x%x, mbx status x%x\n",
10393 shdr_status, shdr_add_status, rc);
10394 mempool_free(mboxq, phba->mbox_mem_pool);
10399 phba->sli4_hba.fw_func_mode =
10400 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
10401 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
10402 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
10403 phba->sli4_hba.physical_port =
10404 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
10405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10406 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
10407 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
10408 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
10410 mempool_free(mboxq, phba->mbox_mem_pool);
10413 * Set up HBA Event Queues (EQs)
10415 qp = phba->sli4_hba.hdwq;
10417 /* Set up HBA event queue */
10419 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10420 "3147 Fast-path EQs not allocated\n");
10425 /* Loop thru all IRQ vectors */
10426 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10427 /* Create HBA Event Queues (EQs) in order */
10428 for_each_present_cpu(cpu) {
10429 cpup = &phba->sli4_hba.cpu_map[cpu];
10431 /* Look for the CPU thats using that vector with
10432 * LPFC_CPU_FIRST_IRQ set.
10434 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10436 if (qidx != cpup->eq)
10439 /* Create an EQ for that vector */
10440 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
10441 phba->cfg_fcp_imax);
10443 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10444 "0523 Failed setup of fast-path"
10445 " EQ (%d), rc = 0x%x\n",
10446 cpup->eq, (uint32_t)rc);
10450 /* Save the EQ for that vector in the hba_eq_hdl */
10451 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
10452 qp[cpup->hdwq].hba_eq;
10454 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10455 "2584 HBA EQ setup: queue[%d]-id=%d\n",
10457 qp[cpup->hdwq].hba_eq->queue_id);
10461 /* Loop thru all Hardware Queues */
10462 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
10463 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
10464 cpup = &phba->sli4_hba.cpu_map[cpu];
10466 /* Create the CQ/WQ corresponding to the Hardware Queue */
10467 rc = lpfc_create_wq_cq(phba,
10468 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
10471 &phba->sli4_hba.hdwq[qidx].io_cq_map,
10475 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10476 "0535 Failed to setup fastpath "
10477 "IO WQ/CQ (%d), rc = 0x%x\n",
10478 qidx, (uint32_t)rc);
10484 * Set up Slow Path Complete Queues (CQs)
10487 /* Set up slow-path MBOX CQ/MQ */
10489 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
10490 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10491 "0528 %s not allocated\n",
10492 phba->sli4_hba.mbx_cq ?
10493 "Mailbox WQ" : "Mailbox CQ");
10498 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
10499 phba->sli4_hba.mbx_cq,
10500 phba->sli4_hba.mbx_wq,
10501 NULL, 0, LPFC_MBOX);
10503 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10504 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
10508 if (phba->nvmet_support) {
10509 if (!phba->sli4_hba.nvmet_cqset) {
10510 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10511 "3165 Fast-path NVME CQ Set "
10512 "array not allocated\n");
10516 if (phba->cfg_nvmet_mrq > 1) {
10517 rc = lpfc_cq_create_set(phba,
10518 phba->sli4_hba.nvmet_cqset,
10520 LPFC_WCQ, LPFC_NVMET);
10522 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10523 "3164 Failed setup of NVME CQ "
10524 "Set, rc = 0x%x\n",
10529 /* Set up NVMET Receive Complete Queue */
10530 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
10532 LPFC_WCQ, LPFC_NVMET);
10534 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10535 "6089 Failed setup NVMET CQ: "
10536 "rc = 0x%x\n", (uint32_t)rc);
10539 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
10541 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10542 "6090 NVMET CQ setup: cq-id=%d, "
10543 "parent eq-id=%d\n",
10544 phba->sli4_hba.nvmet_cqset[0]->queue_id,
10545 qp[0].hba_eq->queue_id);
10549 /* Set up slow-path ELS WQ/CQ */
10550 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
10551 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10552 "0530 ELS %s not allocated\n",
10553 phba->sli4_hba.els_cq ? "WQ" : "CQ");
10557 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
10558 phba->sli4_hba.els_cq,
10559 phba->sli4_hba.els_wq,
10560 NULL, 0, LPFC_ELS);
10562 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10563 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
10567 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10568 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
10569 phba->sli4_hba.els_wq->queue_id,
10570 phba->sli4_hba.els_cq->queue_id);
10572 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10573 /* Set up NVME LS Complete Queue */
10574 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
10575 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10576 "6091 LS %s not allocated\n",
10577 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
10581 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
10582 phba->sli4_hba.nvmels_cq,
10583 phba->sli4_hba.nvmels_wq,
10584 NULL, 0, LPFC_NVME_LS);
10586 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10587 "0526 Failed setup of NVVME LS WQ/CQ: "
10588 "rc = 0x%x\n", (uint32_t)rc);
10592 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10593 "6096 ELS WQ setup: wq-id=%d, "
10594 "parent cq-id=%d\n",
10595 phba->sli4_hba.nvmels_wq->queue_id,
10596 phba->sli4_hba.nvmels_cq->queue_id);
10600 * Create NVMET Receive Queue (RQ)
10602 if (phba->nvmet_support) {
10603 if ((!phba->sli4_hba.nvmet_cqset) ||
10604 (!phba->sli4_hba.nvmet_mrq_hdr) ||
10605 (!phba->sli4_hba.nvmet_mrq_data)) {
10606 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10607 "6130 MRQ CQ Queues not "
10612 if (phba->cfg_nvmet_mrq > 1) {
10613 rc = lpfc_mrq_create(phba,
10614 phba->sli4_hba.nvmet_mrq_hdr,
10615 phba->sli4_hba.nvmet_mrq_data,
10616 phba->sli4_hba.nvmet_cqset,
10619 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10620 "6098 Failed setup of NVMET "
10621 "MRQ: rc = 0x%x\n",
10627 rc = lpfc_rq_create(phba,
10628 phba->sli4_hba.nvmet_mrq_hdr[0],
10629 phba->sli4_hba.nvmet_mrq_data[0],
10630 phba->sli4_hba.nvmet_cqset[0],
10633 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10634 "6057 Failed setup of NVMET "
10635 "Receive Queue: rc = 0x%x\n",
10641 phba, KERN_INFO, LOG_INIT,
10642 "6099 NVMET RQ setup: hdr-rq-id=%d, "
10643 "dat-rq-id=%d parent cq-id=%d\n",
10644 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
10645 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
10646 phba->sli4_hba.nvmet_cqset[0]->queue_id);
10651 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
10652 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10653 "0540 Receive Queue not allocated\n");
10658 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
10659 phba->sli4_hba.els_cq, LPFC_USOL);
10661 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10662 "0541 Failed setup of Receive Queue: "
10663 "rc = 0x%x\n", (uint32_t)rc);
10667 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10668 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
10669 "parent cq-id=%d\n",
10670 phba->sli4_hba.hdr_rq->queue_id,
10671 phba->sli4_hba.dat_rq->queue_id,
10672 phba->sli4_hba.els_cq->queue_id);
10674 if (phba->cfg_fcp_imax)
10675 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
10679 for (qidx = 0; qidx < phba->cfg_irq_chann;
10680 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
10681 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
10684 if (phba->sli4_hba.cq_max) {
10685 kfree(phba->sli4_hba.cq_lookup);
10686 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
10687 sizeof(struct lpfc_queue *), GFP_KERNEL);
10688 if (!phba->sli4_hba.cq_lookup) {
10689 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10690 "0549 Failed setup of CQ Lookup table: "
10691 "size 0x%x\n", phba->sli4_hba.cq_max);
10695 lpfc_setup_cq_lookup(phba);
10700 lpfc_sli4_queue_unset(phba);
10706 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
10707 * @phba: pointer to lpfc hba data structure.
10709 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
10714 * -ENOMEM - No available memory
10715 * -EIO - The mailbox failed to complete successfully.
10718 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
10720 struct lpfc_sli4_hdw_queue *qp;
10721 struct lpfc_queue *eq;
10724 /* Unset mailbox command work queue */
10725 if (phba->sli4_hba.mbx_wq)
10726 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
10728 /* Unset NVME LS work queue */
10729 if (phba->sli4_hba.nvmels_wq)
10730 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
10732 /* Unset ELS work queue */
10733 if (phba->sli4_hba.els_wq)
10734 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
10736 /* Unset unsolicited receive queue */
10737 if (phba->sli4_hba.hdr_rq)
10738 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
10739 phba->sli4_hba.dat_rq);
10741 /* Unset mailbox command complete queue */
10742 if (phba->sli4_hba.mbx_cq)
10743 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
10745 /* Unset ELS complete queue */
10746 if (phba->sli4_hba.els_cq)
10747 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
10749 /* Unset NVME LS complete queue */
10750 if (phba->sli4_hba.nvmels_cq)
10751 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
10753 if (phba->nvmet_support) {
10754 /* Unset NVMET MRQ queue */
10755 if (phba->sli4_hba.nvmet_mrq_hdr) {
10756 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
10759 phba->sli4_hba.nvmet_mrq_hdr[qidx],
10760 phba->sli4_hba.nvmet_mrq_data[qidx]);
10763 /* Unset NVMET CQ Set complete queue */
10764 if (phba->sli4_hba.nvmet_cqset) {
10765 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
10767 phba, phba->sli4_hba.nvmet_cqset[qidx]);
10771 /* Unset fast-path SLI4 queues */
10772 if (phba->sli4_hba.hdwq) {
10773 /* Loop thru all Hardware Queues */
10774 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
10775 /* Destroy the CQ/WQ corresponding to Hardware Queue */
10776 qp = &phba->sli4_hba.hdwq[qidx];
10777 lpfc_wq_destroy(phba, qp->io_wq);
10778 lpfc_cq_destroy(phba, qp->io_cq);
10780 /* Loop thru all IRQ vectors */
10781 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10782 /* Destroy the EQ corresponding to the IRQ vector */
10783 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
10784 lpfc_eq_destroy(phba, eq);
10788 kfree(phba->sli4_hba.cq_lookup);
10789 phba->sli4_hba.cq_lookup = NULL;
10790 phba->sli4_hba.cq_max = 0;
10794 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
10795 * @phba: pointer to lpfc hba data structure.
10797 * This routine is invoked to allocate and set up a pool of completion queue
10798 * events. The body of the completion queue event is a completion queue entry
10799 * CQE. For now, this pool is used for the interrupt service routine to queue
10800 * the following HBA completion queue events for the worker thread to process:
10801 * - Mailbox asynchronous events
10802 * - Receive queue completion unsolicited events
10803 * Later, this can be used for all the slow-path events.
10807 * -ENOMEM - No available memory
10810 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
10812 struct lpfc_cq_event *cq_event;
10815 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
10816 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
10818 goto out_pool_create_fail;
10819 list_add_tail(&cq_event->list,
10820 &phba->sli4_hba.sp_cqe_event_pool);
10824 out_pool_create_fail:
10825 lpfc_sli4_cq_event_pool_destroy(phba);
10830 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
10831 * @phba: pointer to lpfc hba data structure.
10833 * This routine is invoked to free the pool of completion queue events at
10834 * driver unload time. Note that, it is the responsibility of the driver
10835 * cleanup routine to free all the outstanding completion-queue events
10836 * allocated from this pool back into the pool before invoking this routine
10837 * to destroy the pool.
10840 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
10842 struct lpfc_cq_event *cq_event, *next_cq_event;
10844 list_for_each_entry_safe(cq_event, next_cq_event,
10845 &phba->sli4_hba.sp_cqe_event_pool, list) {
10846 list_del(&cq_event->list);
10852 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10853 * @phba: pointer to lpfc hba data structure.
10855 * This routine is the lock free version of the API invoked to allocate a
10856 * completion-queue event from the free pool.
10858 * Return: Pointer to the newly allocated completion-queue event if successful
10861 struct lpfc_cq_event *
10862 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
10864 struct lpfc_cq_event *cq_event = NULL;
10866 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
10867 struct lpfc_cq_event, list);
10872 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10873 * @phba: pointer to lpfc hba data structure.
10875 * This routine is the lock version of the API invoked to allocate a
10876 * completion-queue event from the free pool.
10878 * Return: Pointer to the newly allocated completion-queue event if successful
10881 struct lpfc_cq_event *
10882 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
10884 struct lpfc_cq_event *cq_event;
10885 unsigned long iflags;
10887 spin_lock_irqsave(&phba->hbalock, iflags);
10888 cq_event = __lpfc_sli4_cq_event_alloc(phba);
10889 spin_unlock_irqrestore(&phba->hbalock, iflags);
10894 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10895 * @phba: pointer to lpfc hba data structure.
10896 * @cq_event: pointer to the completion queue event to be freed.
10898 * This routine is the lock free version of the API invoked to release a
10899 * completion-queue event back into the free pool.
10902 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10903 struct lpfc_cq_event *cq_event)
10905 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
10909 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10910 * @phba: pointer to lpfc hba data structure.
10911 * @cq_event: pointer to the completion queue event to be freed.
10913 * This routine is the lock version of the API invoked to release a
10914 * completion-queue event back into the free pool.
10917 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10918 struct lpfc_cq_event *cq_event)
10920 unsigned long iflags;
10921 spin_lock_irqsave(&phba->hbalock, iflags);
10922 __lpfc_sli4_cq_event_release(phba, cq_event);
10923 spin_unlock_irqrestore(&phba->hbalock, iflags);
10927 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
10928 * @phba: pointer to lpfc hba data structure.
10930 * This routine is to free all the pending completion-queue events to the
10931 * back into the free pool for device reset.
10934 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
10936 LIST_HEAD(cq_event_list);
10937 struct lpfc_cq_event *cq_event;
10938 unsigned long iflags;
10940 /* Retrieve all the pending WCQEs from pending WCQE lists */
10942 /* Pending ELS XRI abort events */
10943 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
10944 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10946 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
10948 /* Pending asynnc events */
10949 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
10950 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
10952 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
10954 while (!list_empty(&cq_event_list)) {
10955 list_remove_head(&cq_event_list, cq_event,
10956 struct lpfc_cq_event, list);
10957 lpfc_sli4_cq_event_release(phba, cq_event);
10962 * lpfc_pci_function_reset - Reset pci function.
10963 * @phba: pointer to lpfc hba data structure.
10965 * This routine is invoked to request a PCI function reset. It will destroys
10966 * all resources assigned to the PCI function which originates this request.
10970 * -ENOMEM - No available memory
10971 * -EIO - The mailbox failed to complete successfully.
10974 lpfc_pci_function_reset(struct lpfc_hba *phba)
10976 LPFC_MBOXQ_t *mboxq;
10977 uint32_t rc = 0, if_type;
10978 uint32_t shdr_status, shdr_add_status;
10980 uint32_t port_reset = 0;
10981 union lpfc_sli4_cfg_shdr *shdr;
10982 struct lpfc_register reg_data;
10985 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10987 case LPFC_SLI_INTF_IF_TYPE_0:
10988 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10991 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10992 "0494 Unable to allocate memory for "
10993 "issuing SLI_FUNCTION_RESET mailbox "
10998 /* Setup PCI function reset mailbox-ioctl command */
10999 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11000 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11001 LPFC_SLI4_MBX_EMBED);
11002 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11003 shdr = (union lpfc_sli4_cfg_shdr *)
11004 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11005 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11006 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11008 mempool_free(mboxq, phba->mbox_mem_pool);
11009 if (shdr_status || shdr_add_status || rc) {
11010 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11011 "0495 SLI_FUNCTION_RESET mailbox "
11012 "failed with status x%x add_status x%x,"
11013 " mbx status x%x\n",
11014 shdr_status, shdr_add_status, rc);
11018 case LPFC_SLI_INTF_IF_TYPE_2:
11019 case LPFC_SLI_INTF_IF_TYPE_6:
11022 * Poll the Port Status Register and wait for RDY for
11023 * up to 30 seconds. If the port doesn't respond, treat
11026 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
11027 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11028 STATUSregaddr, ®_data.word0)) {
11032 if (bf_get(lpfc_sliport_status_rdy, ®_data))
11037 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
11038 phba->work_status[0] = readl(
11039 phba->sli4_hba.u.if_type2.ERR1regaddr);
11040 phba->work_status[1] = readl(
11041 phba->sli4_hba.u.if_type2.ERR2regaddr);
11042 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11043 "2890 Port not ready, port status reg "
11044 "0x%x error 1=0x%x, error 2=0x%x\n",
11046 phba->work_status[0],
11047 phba->work_status[1]);
11054 * Reset the port now
11056 reg_data.word0 = 0;
11057 bf_set(lpfc_sliport_ctrl_end, ®_data,
11058 LPFC_SLIPORT_LITTLE_ENDIAN);
11059 bf_set(lpfc_sliport_ctrl_ip, ®_data,
11060 LPFC_SLIPORT_INIT_PORT);
11061 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11064 pci_read_config_word(phba->pcidev,
11065 PCI_DEVICE_ID, &devid);
11070 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
11076 case LPFC_SLI_INTF_IF_TYPE_1:
11082 /* Catch the not-ready port failure after a port reset. */
11084 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11085 "3317 HBA not functional: IP Reset Failed "
11086 "try: echo fw_reset > board_mode\n");
11094 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11095 * @phba: pointer to lpfc hba data structure.
11097 * This routine is invoked to set up the PCI device memory space for device
11098 * with SLI-4 interface spec.
11102 * other values - error
11105 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11107 struct pci_dev *pdev = phba->pcidev;
11108 unsigned long bar0map_len, bar1map_len, bar2map_len;
11115 /* Set the device DMA mask size */
11116 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11118 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11123 * The BARs and register set definitions and offset locations are
11124 * dependent on the if_type.
11126 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11127 &phba->sli4_hba.sli_intf.word0)) {
11131 /* There is no SLI3 failback for SLI4 devices. */
11132 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11133 LPFC_SLI_INTF_VALID) {
11134 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11135 "2894 SLI_INTF reg contents invalid "
11136 "sli_intf reg 0x%x\n",
11137 phba->sli4_hba.sli_intf.word0);
11141 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11143 * Get the bus address of SLI4 device Bar regions and the
11144 * number of bytes required by each mapping. The mapping of the
11145 * particular PCI BARs regions is dependent on the type of
11148 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11149 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11150 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
11153 * Map SLI4 PCI Config Space Register base to a kernel virtual
11156 phba->sli4_hba.conf_regs_memmap_p =
11157 ioremap(phba->pci_bar0_map, bar0map_len);
11158 if (!phba->sli4_hba.conf_regs_memmap_p) {
11159 dev_printk(KERN_ERR, &pdev->dev,
11160 "ioremap failed for SLI4 PCI config "
11164 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
11165 /* Set up BAR0 PCI config space register memory map */
11166 lpfc_sli4_bar0_register_memmap(phba, if_type);
11168 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11169 bar0map_len = pci_resource_len(pdev, 1);
11170 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
11171 dev_printk(KERN_ERR, &pdev->dev,
11172 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
11175 phba->sli4_hba.conf_regs_memmap_p =
11176 ioremap(phba->pci_bar0_map, bar0map_len);
11177 if (!phba->sli4_hba.conf_regs_memmap_p) {
11178 dev_printk(KERN_ERR, &pdev->dev,
11179 "ioremap failed for SLI4 PCI config "
11183 lpfc_sli4_bar0_register_memmap(phba, if_type);
11186 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11187 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11189 * Map SLI4 if type 0 HBA Control Register base to a
11190 * kernel virtual address and setup the registers.
11192 phba->pci_bar1_map = pci_resource_start(pdev,
11194 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11195 phba->sli4_hba.ctrl_regs_memmap_p =
11196 ioremap(phba->pci_bar1_map,
11198 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11199 dev_err(&pdev->dev,
11200 "ioremap failed for SLI4 HBA "
11201 "control registers.\n");
11203 goto out_iounmap_conf;
11205 phba->pci_bar2_memmap_p =
11206 phba->sli4_hba.ctrl_regs_memmap_p;
11207 lpfc_sli4_bar1_register_memmap(phba, if_type);
11210 goto out_iounmap_conf;
11214 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11215 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11217 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11218 * virtual address and setup the registers.
11220 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11221 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11222 phba->sli4_hba.drbl_regs_memmap_p =
11223 ioremap(phba->pci_bar1_map, bar1map_len);
11224 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11225 dev_err(&pdev->dev,
11226 "ioremap failed for SLI4 HBA doorbell registers.\n");
11228 goto out_iounmap_conf;
11230 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11231 lpfc_sli4_bar1_register_memmap(phba, if_type);
11234 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11235 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11237 * Map SLI4 if type 0 HBA Doorbell Register base to
11238 * a kernel virtual address and setup the registers.
11240 phba->pci_bar2_map = pci_resource_start(pdev,
11242 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11243 phba->sli4_hba.drbl_regs_memmap_p =
11244 ioremap(phba->pci_bar2_map,
11246 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11247 dev_err(&pdev->dev,
11248 "ioremap failed for SLI4 HBA"
11249 " doorbell registers.\n");
11251 goto out_iounmap_ctrl;
11253 phba->pci_bar4_memmap_p =
11254 phba->sli4_hba.drbl_regs_memmap_p;
11255 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
11257 goto out_iounmap_all;
11260 goto out_iounmap_all;
11264 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
11265 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11267 * Map SLI4 if type 6 HBA DPP Register base to a kernel
11268 * virtual address and setup the registers.
11270 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
11271 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11272 phba->sli4_hba.dpp_regs_memmap_p =
11273 ioremap(phba->pci_bar2_map, bar2map_len);
11274 if (!phba->sli4_hba.dpp_regs_memmap_p) {
11275 dev_err(&pdev->dev,
11276 "ioremap failed for SLI4 HBA dpp registers.\n");
11278 goto out_iounmap_ctrl;
11280 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
11283 /* Set up the EQ/CQ register handeling functions now */
11285 case LPFC_SLI_INTF_IF_TYPE_0:
11286 case LPFC_SLI_INTF_IF_TYPE_2:
11287 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
11288 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
11289 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
11291 case LPFC_SLI_INTF_IF_TYPE_6:
11292 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
11293 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
11294 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
11303 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11305 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11307 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11313 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
11314 * @phba: pointer to lpfc hba data structure.
11316 * This routine is invoked to unset the PCI device memory space for device
11317 * with SLI-4 interface spec.
11320 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
11323 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11326 case LPFC_SLI_INTF_IF_TYPE_0:
11327 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11328 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11329 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11331 case LPFC_SLI_INTF_IF_TYPE_2:
11332 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11334 case LPFC_SLI_INTF_IF_TYPE_6:
11335 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11336 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11337 if (phba->sli4_hba.dpp_regs_memmap_p)
11338 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
11340 case LPFC_SLI_INTF_IF_TYPE_1:
11342 dev_printk(KERN_ERR, &phba->pcidev->dev,
11343 "FATAL - unsupported SLI4 interface type - %d\n",
11350 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
11351 * @phba: pointer to lpfc hba data structure.
11353 * This routine is invoked to enable the MSI-X interrupt vectors to device
11354 * with SLI-3 interface specs.
11358 * other values - error
11361 lpfc_sli_enable_msix(struct lpfc_hba *phba)
11366 /* Set up MSI-X multi-message vectors */
11367 rc = pci_alloc_irq_vectors(phba->pcidev,
11368 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
11370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11371 "0420 PCI enable MSI-X failed (%d)\n", rc);
11376 * Assign MSI-X vectors to interrupt handlers
11379 /* vector-0 is associated to slow-path handler */
11380 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
11381 &lpfc_sli_sp_intr_handler, 0,
11382 LPFC_SP_DRIVER_HANDLER_NAME, phba);
11384 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11385 "0421 MSI-X slow-path request_irq failed "
11390 /* vector-1 is associated to fast-path handler */
11391 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
11392 &lpfc_sli_fp_intr_handler, 0,
11393 LPFC_FP_DRIVER_HANDLER_NAME, phba);
11396 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11397 "0429 MSI-X fast-path request_irq failed "
11403 * Configure HBA MSI-X attention conditions to messages
11405 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11409 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11410 "0474 Unable to allocate memory for issuing "
11411 "MBOX_CONFIG_MSI command\n");
11414 rc = lpfc_config_msi(phba, pmb);
11417 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
11418 if (rc != MBX_SUCCESS) {
11419 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
11420 "0351 Config MSI mailbox command failed, "
11421 "mbxCmd x%x, mbxStatus x%x\n",
11422 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
11426 /* Free memory allocated for mailbox command */
11427 mempool_free(pmb, phba->mbox_mem_pool);
11431 /* Free memory allocated for mailbox command */
11432 mempool_free(pmb, phba->mbox_mem_pool);
11435 /* free the irq already requested */
11436 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
11439 /* free the irq already requested */
11440 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
11443 /* Unconfigure MSI-X capability structure */
11444 pci_free_irq_vectors(phba->pcidev);
11451 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
11452 * @phba: pointer to lpfc hba data structure.
11454 * This routine is invoked to enable the MSI interrupt mode to device with
11455 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
11456 * enable the MSI vector. The device driver is responsible for calling the
11457 * request_irq() to register MSI vector with a interrupt the handler, which
11458 * is done in this function.
11462 * other values - error
11465 lpfc_sli_enable_msi(struct lpfc_hba *phba)
11469 rc = pci_enable_msi(phba->pcidev);
11471 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11472 "0462 PCI enable MSI mode success.\n");
11474 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11475 "0471 PCI enable MSI mode failed (%d)\n", rc);
11479 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
11480 0, LPFC_DRIVER_NAME, phba);
11482 pci_disable_msi(phba->pcidev);
11483 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11484 "0478 MSI request_irq failed (%d)\n", rc);
11490 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
11491 * @phba: pointer to lpfc hba data structure.
11492 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
11494 * This routine is invoked to enable device interrupt and associate driver's
11495 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
11496 * spec. Depends on the interrupt mode configured to the driver, the driver
11497 * will try to fallback from the configured interrupt mode to an interrupt
11498 * mode which is supported by the platform, kernel, and device in the order
11500 * MSI-X -> MSI -> IRQ.
11504 * other values - error
11507 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
11509 uint32_t intr_mode = LPFC_INTR_ERROR;
11512 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
11513 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
11516 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
11518 if (cfg_mode == 2) {
11519 /* Now, try to enable MSI-X interrupt mode */
11520 retval = lpfc_sli_enable_msix(phba);
11522 /* Indicate initialization to MSI-X mode */
11523 phba->intr_type = MSIX;
11528 /* Fallback to MSI if MSI-X initialization failed */
11529 if (cfg_mode >= 1 && phba->intr_type == NONE) {
11530 retval = lpfc_sli_enable_msi(phba);
11532 /* Indicate initialization to MSI mode */
11533 phba->intr_type = MSI;
11538 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11539 if (phba->intr_type == NONE) {
11540 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
11541 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
11543 /* Indicate initialization to INTx mode */
11544 phba->intr_type = INTx;
11552 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
11553 * @phba: pointer to lpfc hba data structure.
11555 * This routine is invoked to disable device interrupt and disassociate the
11556 * driver's interrupt handler(s) from interrupt vector(s) to device with
11557 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
11558 * release the interrupt vector(s) for the message signaled interrupt.
11561 lpfc_sli_disable_intr(struct lpfc_hba *phba)
11565 if (phba->intr_type == MSIX)
11566 nr_irqs = LPFC_MSIX_VECTORS;
11570 for (i = 0; i < nr_irqs; i++)
11571 free_irq(pci_irq_vector(phba->pcidev, i), phba);
11572 pci_free_irq_vectors(phba->pcidev);
11574 /* Reset interrupt management states */
11575 phba->intr_type = NONE;
11576 phba->sli.slistat.sli_intr = 0;
11580 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
11581 * @phba: pointer to lpfc hba data structure.
11582 * @id: EQ vector index or Hardware Queue index
11583 * @match: LPFC_FIND_BY_EQ = match by EQ
11584 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
11585 * Return the CPU that matches the selection criteria
11588 lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
11590 struct lpfc_vector_map_info *cpup;
11593 /* Loop through all CPUs */
11594 for_each_present_cpu(cpu) {
11595 cpup = &phba->sli4_hba.cpu_map[cpu];
11597 /* If we are matching by EQ, there may be multiple CPUs using
11598 * using the same vector, so select the one with
11599 * LPFC_CPU_FIRST_IRQ set.
11601 if ((match == LPFC_FIND_BY_EQ) &&
11602 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
11606 /* If matching by HDWQ, select the first CPU that matches */
11607 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
11615 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
11616 * @phba: pointer to lpfc hba data structure.
11617 * @cpu: CPU map index
11618 * @phys_id: CPU package physical id
11619 * @core_id: CPU core id
11622 lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
11623 uint16_t phys_id, uint16_t core_id)
11625 struct lpfc_vector_map_info *cpup;
11628 for_each_present_cpu(idx) {
11629 cpup = &phba->sli4_hba.cpu_map[idx];
11630 /* Does the cpup match the one we are looking for */
11631 if ((cpup->phys_id == phys_id) &&
11632 (cpup->core_id == core_id) &&
11641 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
11642 * @phba: pointer to lpfc hba data structure.
11643 * @eqidx: index for eq and irq vector
11644 * @flag: flags to set for vector_map structure
11645 * @cpu: cpu used to index vector_map structure
11647 * The routine assigns eq info into vector_map structure
11650 lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
11653 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
11654 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
11657 cpup->flag |= flag;
11659 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11660 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
11661 cpu, eqhdl->irq, cpup->eq, cpup->flag);
11665 * lpfc_cpu_map_array_init - Initialize cpu_map structure
11666 * @phba: pointer to lpfc hba data structure.
11668 * The routine initializes the cpu_map array structure
11671 lpfc_cpu_map_array_init(struct lpfc_hba *phba)
11673 struct lpfc_vector_map_info *cpup;
11674 struct lpfc_eq_intr_info *eqi;
11677 for_each_possible_cpu(cpu) {
11678 cpup = &phba->sli4_hba.cpu_map[cpu];
11679 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
11680 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
11681 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
11682 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
11684 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
11685 INIT_LIST_HEAD(&eqi->list);
11691 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
11692 * @phba: pointer to lpfc hba data structure.
11694 * The routine initializes the hba_eq_hdl array structure
11697 lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
11699 struct lpfc_hba_eq_hdl *eqhdl;
11702 for (i = 0; i < phba->cfg_irq_chann; i++) {
11703 eqhdl = lpfc_get_eq_hdl(i);
11704 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
11705 eqhdl->phba = phba;
11710 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
11711 * @phba: pointer to lpfc hba data structure.
11712 * @vectors: number of msix vectors allocated.
11714 * The routine will figure out the CPU affinity assignment for every
11715 * MSI-X vector allocated for the HBA.
11716 * In addition, the CPU to IO channel mapping will be calculated
11717 * and the phba->sli4_hba.cpu_map array will reflect this.
11720 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
11722 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
11723 int max_phys_id, min_phys_id;
11724 int max_core_id, min_core_id;
11725 struct lpfc_vector_map_info *cpup;
11726 struct lpfc_vector_map_info *new_cpup;
11728 struct cpuinfo_x86 *cpuinfo;
11730 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11731 struct lpfc_hdwq_stat *c_stat;
11735 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
11737 min_core_id = LPFC_VECTOR_MAP_EMPTY;
11739 /* Update CPU map with physical id and core id of each CPU */
11740 for_each_present_cpu(cpu) {
11741 cpup = &phba->sli4_hba.cpu_map[cpu];
11743 cpuinfo = &cpu_data(cpu);
11744 cpup->phys_id = cpuinfo->phys_proc_id;
11745 cpup->core_id = cpuinfo->cpu_core_id;
11746 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
11747 cpup->flag |= LPFC_CPU_MAP_HYPER;
11749 /* No distinction between CPUs for other platforms */
11751 cpup->core_id = cpu;
11754 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11755 "3328 CPU %d physid %d coreid %d flag x%x\n",
11756 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
11758 if (cpup->phys_id > max_phys_id)
11759 max_phys_id = cpup->phys_id;
11760 if (cpup->phys_id < min_phys_id)
11761 min_phys_id = cpup->phys_id;
11763 if (cpup->core_id > max_core_id)
11764 max_core_id = cpup->core_id;
11765 if (cpup->core_id < min_core_id)
11766 min_core_id = cpup->core_id;
11769 /* After looking at each irq vector assigned to this pcidev, its
11770 * possible to see that not ALL CPUs have been accounted for.
11771 * Next we will set any unassigned (unaffinitized) cpu map
11772 * entries to a IRQ on the same phys_id.
11774 first_cpu = cpumask_first(cpu_present_mask);
11775 start_cpu = first_cpu;
11777 for_each_present_cpu(cpu) {
11778 cpup = &phba->sli4_hba.cpu_map[cpu];
11780 /* Is this CPU entry unassigned */
11781 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
11782 /* Mark CPU as IRQ not assigned by the kernel */
11783 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
11785 /* If so, find a new_cpup thats on the the SAME
11786 * phys_id as cpup. start_cpu will start where we
11787 * left off so all unassigned entries don't get assgined
11788 * the IRQ of the first entry.
11790 new_cpu = start_cpu;
11791 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11792 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11793 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
11794 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
11795 (new_cpup->phys_id == cpup->phys_id))
11797 new_cpu = cpumask_next(
11798 new_cpu, cpu_present_mask);
11799 if (new_cpu == nr_cpumask_bits)
11800 new_cpu = first_cpu;
11802 /* At this point, we leave the CPU as unassigned */
11805 /* We found a matching phys_id, so copy the IRQ info */
11806 cpup->eq = new_cpup->eq;
11808 /* Bump start_cpu to the next slot to minmize the
11809 * chance of having multiple unassigned CPU entries
11810 * selecting the same IRQ.
11812 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11813 if (start_cpu == nr_cpumask_bits)
11814 start_cpu = first_cpu;
11816 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11817 "3337 Set Affinity: CPU %d "
11818 "eq %d from peer cpu %d same "
11820 cpu, cpup->eq, new_cpu,
11825 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
11826 start_cpu = first_cpu;
11828 for_each_present_cpu(cpu) {
11829 cpup = &phba->sli4_hba.cpu_map[cpu];
11831 /* Is this entry unassigned */
11832 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
11833 /* Mark it as IRQ not assigned by the kernel */
11834 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
11836 /* If so, find a new_cpup thats on ANY phys_id
11837 * as the cpup. start_cpu will start where we
11838 * left off so all unassigned entries don't get
11839 * assigned the IRQ of the first entry.
11841 new_cpu = start_cpu;
11842 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11843 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11844 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
11845 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
11847 new_cpu = cpumask_next(
11848 new_cpu, cpu_present_mask);
11849 if (new_cpu == nr_cpumask_bits)
11850 new_cpu = first_cpu;
11852 /* We should never leave an entry unassigned */
11853 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11854 "3339 Set Affinity: CPU %d "
11855 "eq %d UNASSIGNED\n",
11856 cpup->hdwq, cpup->eq);
11859 /* We found an available entry, copy the IRQ info */
11860 cpup->eq = new_cpup->eq;
11862 /* Bump start_cpu to the next slot to minmize the
11863 * chance of having multiple unassigned CPU entries
11864 * selecting the same IRQ.
11866 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11867 if (start_cpu == nr_cpumask_bits)
11868 start_cpu = first_cpu;
11870 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11871 "3338 Set Affinity: CPU %d "
11872 "eq %d from peer cpu %d (%d/%d)\n",
11873 cpu, cpup->eq, new_cpu,
11874 new_cpup->phys_id, new_cpup->core_id);
11878 /* Assign hdwq indices that are unique across all cpus in the map
11879 * that are also FIRST_CPUs.
11882 for_each_present_cpu(cpu) {
11883 cpup = &phba->sli4_hba.cpu_map[cpu];
11885 /* Only FIRST IRQs get a hdwq index assignment. */
11886 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11889 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
11892 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11893 "3333 Set Affinity: CPU %d (phys %d core %d): "
11894 "hdwq %d eq %d flg x%x\n",
11895 cpu, cpup->phys_id, cpup->core_id,
11896 cpup->hdwq, cpup->eq, cpup->flag);
11898 /* Associate a hdwq with each cpu_map entry
11899 * This will be 1 to 1 - hdwq to cpu, unless there are less
11900 * hardware queues then CPUs. For that case we will just round-robin
11901 * the available hardware queues as they get assigned to CPUs.
11902 * The next_idx is the idx from the FIRST_CPU loop above to account
11903 * for irq_chann < hdwq. The idx is used for round-robin assignments
11904 * and needs to start at 0.
11909 for_each_present_cpu(cpu) {
11910 cpup = &phba->sli4_hba.cpu_map[cpu];
11912 /* FIRST cpus are already mapped. */
11913 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
11916 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
11917 * of the unassigned cpus to the next idx so that all
11918 * hdw queues are fully utilized.
11920 if (next_idx < phba->cfg_hdw_queue) {
11921 cpup->hdwq = next_idx;
11926 /* Not a First CPU and all hdw_queues are used. Reuse a
11927 * Hardware Queue for another CPU, so be smart about it
11928 * and pick one that has its IRQ/EQ mapped to the same phys_id
11929 * (CPU package) and core_id.
11931 new_cpu = start_cpu;
11932 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11933 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11934 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11935 new_cpup->phys_id == cpup->phys_id &&
11936 new_cpup->core_id == cpup->core_id) {
11939 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11940 if (new_cpu == nr_cpumask_bits)
11941 new_cpu = first_cpu;
11944 /* If we can't match both phys_id and core_id,
11945 * settle for just a phys_id match.
11947 new_cpu = start_cpu;
11948 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11949 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11950 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11951 new_cpup->phys_id == cpup->phys_id)
11954 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11955 if (new_cpu == nr_cpumask_bits)
11956 new_cpu = first_cpu;
11959 /* Otherwise just round robin on cfg_hdw_queue */
11960 cpup->hdwq = idx % phba->cfg_hdw_queue;
11964 /* We found an available entry, copy the IRQ info */
11965 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11966 if (start_cpu == nr_cpumask_bits)
11967 start_cpu = first_cpu;
11968 cpup->hdwq = new_cpup->hdwq;
11970 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11971 "3335 Set Affinity: CPU %d (phys %d core %d): "
11972 "hdwq %d eq %d flg x%x\n",
11973 cpu, cpup->phys_id, cpup->core_id,
11974 cpup->hdwq, cpup->eq, cpup->flag);
11978 * Initialize the cpu_map slots for not-present cpus in case
11979 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
11982 for_each_possible_cpu(cpu) {
11983 cpup = &phba->sli4_hba.cpu_map[cpu];
11984 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11985 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
11986 c_stat->hdwq_no = cpup->hdwq;
11988 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
11991 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
11992 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11993 c_stat->hdwq_no = cpup->hdwq;
11995 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11996 "3340 Set Affinity: not present "
11997 "CPU %d hdwq %d\n",
12001 /* The cpu_map array will be used later during initialization
12002 * when EQ / CQ / WQs are allocated and configured.
12008 * lpfc_cpuhp_get_eq
12010 * @phba: pointer to lpfc hba data structure.
12011 * @cpu: cpu going offline
12012 * @eqlist: eq list to append to
12015 lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12016 struct list_head *eqlist)
12018 const struct cpumask *maskp;
12019 struct lpfc_queue *eq;
12020 struct cpumask *tmp;
12023 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12027 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12028 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12032 * if irq is not affinitized to the cpu going
12033 * then we don't need to poll the eq attached
12036 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
12038 /* get the cpus that are online and are affini-
12039 * tized to this irq vector. If the count is
12040 * more than 1 then cpuhp is not going to shut-
12041 * down this vector. Since this cpu has not
12042 * gone offline yet, we need >1.
12044 cpumask_and(tmp, maskp, cpu_online_mask);
12045 if (cpumask_weight(tmp) > 1)
12048 /* Now that we have an irq to shutdown, get the eq
12049 * mapped to this irq. Note: multiple hdwq's in
12050 * the software can share an eq, but eventually
12051 * only eq will be mapped to this vector
12053 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12054 list_add(&eq->_poll_list, eqlist);
12060 static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12062 if (phba->sli_rev != LPFC_SLI_REV4)
12065 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12068 * unregistering the instance doesn't stop the polling
12069 * timer. Wait for the poll timer to retire.
12072 del_timer_sync(&phba->cpuhp_poll_timer);
12075 static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12077 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
12080 __lpfc_cpuhp_remove(phba);
12083 static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12085 if (phba->sli_rev != LPFC_SLI_REV4)
12090 if (!list_empty(&phba->poll_list))
12091 mod_timer(&phba->cpuhp_poll_timer,
12092 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
12096 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12100 static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12102 if (phba->pport->load_flag & FC_UNLOADING) {
12107 if (phba->sli_rev != LPFC_SLI_REV4) {
12112 /* proceed with the hotplug */
12117 * lpfc_irq_set_aff - set IRQ affinity
12118 * @eqhdl: EQ handle
12119 * @cpu: cpu to set affinity
12123 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12125 cpumask_clear(&eqhdl->aff_mask);
12126 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12127 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12128 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
12132 * lpfc_irq_clear_aff - clear IRQ affinity
12133 * @eqhdl: EQ handle
12137 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12139 cpumask_clear(&eqhdl->aff_mask);
12140 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12144 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12145 * @phba: pointer to HBA context object.
12146 * @cpu: cpu going offline/online
12147 * @offline: true, cpu is going offline. false, cpu is coming online.
12149 * If cpu is going offline, we'll try our best effort to find the next
12150 * online cpu on the phba's original_mask and migrate all offlining IRQ
12153 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
12155 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
12156 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12160 lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12162 struct lpfc_vector_map_info *cpup;
12163 struct cpumask *aff_mask;
12164 unsigned int cpu_select, cpu_next, idx;
12165 const struct cpumask *orig_mask;
12167 if (phba->irq_chann_mode == NORMAL_MODE)
12170 orig_mask = &phba->sli4_hba.irq_aff_mask;
12172 if (!cpumask_test_cpu(cpu, orig_mask))
12175 cpup = &phba->sli4_hba.cpu_map[cpu];
12177 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12181 /* Find next online CPU on original mask */
12182 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12183 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
12185 /* Found a valid CPU */
12186 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12187 /* Go through each eqhdl and ensure offlining
12188 * cpu aff_mask is migrated
12190 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12191 aff_mask = lpfc_get_aff_mask(idx);
12193 /* Migrate affinity */
12194 if (cpumask_test_cpu(cpu, aff_mask))
12195 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12199 /* Rely on irqbalance if no online CPUs left on NUMA */
12200 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12201 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12204 /* Migrate affinity back to this CPU */
12205 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12209 static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12211 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12212 struct lpfc_queue *eq, *next;
12217 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12221 if (__lpfc_cpuhp_checks(phba, &retval))
12224 lpfc_irq_rebalance(phba, cpu, true);
12226 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12230 /* start polling on these eq's */
12231 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12232 list_del_init(&eq->_poll_list);
12233 lpfc_sli4_start_polling(eq);
12239 static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
12241 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12242 struct lpfc_queue *eq, *next;
12247 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12251 if (__lpfc_cpuhp_checks(phba, &retval))
12254 lpfc_irq_rebalance(phba, cpu, false);
12256 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
12257 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
12259 lpfc_sli4_stop_polling(eq);
12266 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
12267 * @phba: pointer to lpfc hba data structure.
12269 * This routine is invoked to enable the MSI-X interrupt vectors to device
12270 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
12271 * to cpus on the system.
12273 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
12274 * the number of cpus on the same numa node as this adapter. The vectors are
12275 * allocated without requesting OS affinity mapping. A vector will be
12276 * allocated and assigned to each online and offline cpu. If the cpu is
12277 * online, then affinity will be set to that cpu. If the cpu is offline, then
12278 * affinity will be set to the nearest peer cpu within the numa node that is
12279 * online. If there are no online cpus within the numa node, affinity is not
12280 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
12281 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
12284 * If numa mode is not enabled and there is more than 1 vector allocated, then
12285 * the driver relies on the managed irq interface where the OS assigns vector to
12286 * cpu affinity. The driver will then use that affinity mapping to setup its
12287 * cpu mapping table.
12291 * other values - error
12294 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
12296 int vectors, rc, index;
12298 const struct cpumask *aff_mask = NULL;
12299 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
12300 struct lpfc_vector_map_info *cpup;
12301 struct lpfc_hba_eq_hdl *eqhdl;
12302 const struct cpumask *maskp;
12303 unsigned int flags = PCI_IRQ_MSIX;
12305 /* Set up MSI-X multi-message vectors */
12306 vectors = phba->cfg_irq_chann;
12308 if (phba->irq_chann_mode != NORMAL_MODE)
12309 aff_mask = &phba->sli4_hba.irq_aff_mask;
12312 cpu_cnt = cpumask_weight(aff_mask);
12313 vectors = min(phba->cfg_irq_chann, cpu_cnt);
12315 /* cpu: iterates over aff_mask including offline or online
12316 * cpu_select: iterates over online aff_mask to set affinity
12318 cpu = cpumask_first(aff_mask);
12319 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12321 flags |= PCI_IRQ_AFFINITY;
12324 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
12326 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12327 "0484 PCI enable MSI-X failed (%d)\n", rc);
12332 /* Assign MSI-X vectors to interrupt handlers */
12333 for (index = 0; index < vectors; index++) {
12334 eqhdl = lpfc_get_eq_hdl(index);
12335 name = eqhdl->handler_name;
12336 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
12337 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
12338 LPFC_DRIVER_HANDLER_NAME"%d", index);
12340 eqhdl->idx = index;
12341 rc = request_irq(pci_irq_vector(phba->pcidev, index),
12342 &lpfc_sli4_hba_intr_handler, 0,
12345 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12346 "0486 MSI-X fast-path (%d) "
12347 "request_irq failed (%d)\n", index, rc);
12351 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
12354 /* If found a neighboring online cpu, set affinity */
12355 if (cpu_select < nr_cpu_ids)
12356 lpfc_irq_set_aff(eqhdl, cpu_select);
12358 /* Assign EQ to cpu_map */
12359 lpfc_assign_eq_map_info(phba, index,
12360 LPFC_CPU_FIRST_IRQ,
12363 /* Iterate to next offline or online cpu in aff_mask */
12364 cpu = cpumask_next(cpu, aff_mask);
12366 /* Find next online cpu in aff_mask to set affinity */
12367 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
12368 } else if (vectors == 1) {
12369 cpu = cpumask_first(cpu_present_mask);
12370 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
12373 maskp = pci_irq_get_affinity(phba->pcidev, index);
12375 /* Loop through all CPUs associated with vector index */
12376 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
12377 cpup = &phba->sli4_hba.cpu_map[cpu];
12379 /* If this is the first CPU thats assigned to
12380 * this vector, set LPFC_CPU_FIRST_IRQ.
12382 * With certain platforms its possible that irq
12383 * vectors are affinitized to all the cpu's.
12384 * This can result in each cpu_map.eq to be set
12385 * to the last vector, resulting in overwrite
12386 * of all the previous cpu_map.eq. Ensure that
12387 * each vector receives a place in cpu_map.
12388 * Later call to lpfc_cpu_affinity_check will
12389 * ensure we are nicely balanced out.
12391 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
12393 lpfc_assign_eq_map_info(phba, index,
12394 LPFC_CPU_FIRST_IRQ,
12401 if (vectors != phba->cfg_irq_chann) {
12402 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12403 "3238 Reducing IO channels to match number of "
12404 "MSI-X vectors, requested %d got %d\n",
12405 phba->cfg_irq_chann, vectors);
12406 if (phba->cfg_irq_chann > vectors)
12407 phba->cfg_irq_chann = vectors;
12413 /* free the irq already requested */
12414 for (--index; index >= 0; index--) {
12415 eqhdl = lpfc_get_eq_hdl(index);
12416 lpfc_irq_clear_aff(eqhdl);
12417 irq_set_affinity_hint(eqhdl->irq, NULL);
12418 free_irq(eqhdl->irq, eqhdl);
12421 /* Unconfigure MSI-X capability structure */
12422 pci_free_irq_vectors(phba->pcidev);
12429 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
12430 * @phba: pointer to lpfc hba data structure.
12432 * This routine is invoked to enable the MSI interrupt mode to device with
12433 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
12434 * called to enable the MSI vector. The device driver is responsible for
12435 * calling the request_irq() to register MSI vector with a interrupt the
12436 * handler, which is done in this function.
12440 * other values - error
12443 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
12447 struct lpfc_hba_eq_hdl *eqhdl;
12449 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
12450 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
12452 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12453 "0487 PCI enable MSI mode success.\n");
12455 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12456 "0488 PCI enable MSI mode failed (%d)\n", rc);
12457 return rc ? rc : -1;
12460 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
12461 0, LPFC_DRIVER_NAME, phba);
12463 pci_free_irq_vectors(phba->pcidev);
12464 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12465 "0490 MSI request_irq failed (%d)\n", rc);
12469 eqhdl = lpfc_get_eq_hdl(0);
12470 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
12472 cpu = cpumask_first(cpu_present_mask);
12473 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
12475 for (index = 0; index < phba->cfg_irq_chann; index++) {
12476 eqhdl = lpfc_get_eq_hdl(index);
12477 eqhdl->idx = index;
12484 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
12485 * @phba: pointer to lpfc hba data structure.
12486 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
12488 * This routine is invoked to enable device interrupt and associate driver's
12489 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
12490 * interface spec. Depends on the interrupt mode configured to the driver,
12491 * the driver will try to fallback from the configured interrupt mode to an
12492 * interrupt mode which is supported by the platform, kernel, and device in
12494 * MSI-X -> MSI -> IRQ.
12498 * other values - error
12501 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12503 uint32_t intr_mode = LPFC_INTR_ERROR;
12506 if (cfg_mode == 2) {
12507 /* Preparation before conf_msi mbox cmd */
12510 /* Now, try to enable MSI-X interrupt mode */
12511 retval = lpfc_sli4_enable_msix(phba);
12513 /* Indicate initialization to MSI-X mode */
12514 phba->intr_type = MSIX;
12520 /* Fallback to MSI if MSI-X initialization failed */
12521 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12522 retval = lpfc_sli4_enable_msi(phba);
12524 /* Indicate initialization to MSI mode */
12525 phba->intr_type = MSI;
12530 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12531 if (phba->intr_type == NONE) {
12532 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
12533 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12535 struct lpfc_hba_eq_hdl *eqhdl;
12538 /* Indicate initialization to INTx mode */
12539 phba->intr_type = INTx;
12542 eqhdl = lpfc_get_eq_hdl(0);
12543 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
12545 cpu = cpumask_first(cpu_present_mask);
12546 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
12548 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12549 eqhdl = lpfc_get_eq_hdl(idx);
12558 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
12559 * @phba: pointer to lpfc hba data structure.
12561 * This routine is invoked to disable device interrupt and disassociate
12562 * the driver's interrupt handler(s) from interrupt vector(s) to device
12563 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
12564 * will release the interrupt vector(s) for the message signaled interrupt.
12567 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
12569 /* Disable the currently initialized interrupt mode */
12570 if (phba->intr_type == MSIX) {
12572 struct lpfc_hba_eq_hdl *eqhdl;
12574 /* Free up MSI-X multi-message vectors */
12575 for (index = 0; index < phba->cfg_irq_chann; index++) {
12576 eqhdl = lpfc_get_eq_hdl(index);
12577 lpfc_irq_clear_aff(eqhdl);
12578 irq_set_affinity_hint(eqhdl->irq, NULL);
12579 free_irq(eqhdl->irq, eqhdl);
12582 free_irq(phba->pcidev->irq, phba);
12585 pci_free_irq_vectors(phba->pcidev);
12587 /* Reset interrupt management states */
12588 phba->intr_type = NONE;
12589 phba->sli.slistat.sli_intr = 0;
12593 * lpfc_unset_hba - Unset SLI3 hba device initialization
12594 * @phba: pointer to lpfc hba data structure.
12596 * This routine is invoked to unset the HBA device initialization steps to
12597 * a device with SLI-3 interface spec.
12600 lpfc_unset_hba(struct lpfc_hba *phba)
12602 struct lpfc_vport *vport = phba->pport;
12603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
12605 spin_lock_irq(shost->host_lock);
12606 vport->load_flag |= FC_UNLOADING;
12607 spin_unlock_irq(shost->host_lock);
12609 kfree(phba->vpi_bmask);
12610 kfree(phba->vpi_ids);
12612 lpfc_stop_hba_timers(phba);
12614 phba->pport->work_port_events = 0;
12616 lpfc_sli_hba_down(phba);
12618 lpfc_sli_brdrestart(phba);
12620 lpfc_sli_disable_intr(phba);
12626 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
12627 * @phba: Pointer to HBA context object.
12629 * This function is called in the SLI4 code path to wait for completion
12630 * of device's XRIs exchange busy. It will check the XRI exchange busy
12631 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
12632 * that, it will check the XRI exchange busy on outstanding FCP and ELS
12633 * I/Os every 30 seconds, log error message, and wait forever. Only when
12634 * all XRI exchange busy complete, the driver unload shall proceed with
12635 * invoking the function reset ioctl mailbox command to the CNA and the
12636 * the rest of the driver unload resource release.
12639 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
12641 struct lpfc_sli4_hdw_queue *qp;
12644 int io_xri_cmpl = 1;
12645 int nvmet_xri_cmpl = 1;
12646 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
12648 /* Driver just aborted IOs during the hba_unset process. Pause
12649 * here to give the HBA time to complete the IO and get entries
12650 * into the abts lists.
12652 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
12654 /* Wait for NVME pending IO to flush back to transport. */
12655 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12656 lpfc_nvme_wait_for_io_drain(phba);
12659 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
12660 qp = &phba->sli4_hba.hdwq[idx];
12661 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
12662 if (!io_xri_cmpl) /* if list is NOT empty */
12668 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12670 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
12673 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
12674 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
12675 if (!nvmet_xri_cmpl)
12676 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12677 "6424 NVMET XRI exchange busy "
12678 "wait time: %d seconds.\n",
12681 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12682 "6100 IO XRI exchange busy "
12683 "wait time: %d seconds.\n",
12686 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12687 "2878 ELS XRI exchange busy "
12688 "wait time: %d seconds.\n",
12690 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
12691 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
12693 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
12694 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
12698 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
12699 qp = &phba->sli4_hba.hdwq[idx];
12700 io_xri_cmpl = list_empty(
12701 &qp->lpfc_abts_io_buf_list);
12702 if (!io_xri_cmpl) /* if list is NOT empty */
12708 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12709 nvmet_xri_cmpl = list_empty(
12710 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
12713 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
12719 * lpfc_sli4_hba_unset - Unset the fcoe hba
12720 * @phba: Pointer to HBA context object.
12722 * This function is called in the SLI4 code path to reset the HBA's FCoE
12723 * function. The caller is not required to hold any lock. This routine
12724 * issues PCI function reset mailbox command to reset the FCoE function.
12725 * At the end of the function, it calls lpfc_hba_down_post function to
12726 * free any pending commands.
12729 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
12732 LPFC_MBOXQ_t *mboxq;
12733 struct pci_dev *pdev = phba->pcidev;
12735 lpfc_stop_hba_timers(phba);
12736 hrtimer_cancel(&phba->cmf_timer);
12739 phba->sli4_hba.intr_enable = 0;
12742 * Gracefully wait out the potential current outstanding asynchronous
12746 /* First, block any pending async mailbox command from posted */
12747 spin_lock_irq(&phba->hbalock);
12748 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
12749 spin_unlock_irq(&phba->hbalock);
12750 /* Now, trying to wait it out if we can */
12751 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
12753 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
12756 /* Forcefully release the outstanding mailbox command if timed out */
12757 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
12758 spin_lock_irq(&phba->hbalock);
12759 mboxq = phba->sli.mbox_active;
12760 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
12761 __lpfc_mbox_cmpl_put(phba, mboxq);
12762 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
12763 phba->sli.mbox_active = NULL;
12764 spin_unlock_irq(&phba->hbalock);
12767 /* Abort all iocbs associated with the hba */
12768 lpfc_sli_hba_iocb_abort(phba);
12770 /* Wait for completion of device XRI exchange busy */
12771 lpfc_sli4_xri_exchange_busy_wait(phba);
12773 /* per-phba callback de-registration for hotplug event */
12775 lpfc_cpuhp_remove(phba);
12777 /* Disable PCI subsystem interrupt */
12778 lpfc_sli4_disable_intr(phba);
12780 /* Disable SR-IOV if enabled */
12781 if (phba->cfg_sriov_nr_virtfn)
12782 pci_disable_sriov(pdev);
12784 /* Stop kthread signal shall trigger work_done one more time */
12785 kthread_stop(phba->worker_thread);
12787 /* Disable FW logging to host memory */
12788 lpfc_ras_stop_fwlog(phba);
12790 /* Unset the queues shared with the hardware then release all
12791 * allocated resources.
12793 lpfc_sli4_queue_unset(phba);
12794 lpfc_sli4_queue_destroy(phba);
12796 /* Reset SLI4 HBA FCoE function */
12797 lpfc_pci_function_reset(phba);
12799 /* Free RAS DMA memory */
12800 if (phba->ras_fwlog.ras_enabled)
12801 lpfc_sli4_ras_dma_free(phba);
12803 /* Stop the SLI4 device port */
12805 phba->pport->work_port_events = 0;
12809 lpfc_init_congestion_buf(struct lpfc_hba *phba)
12811 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
12812 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
12817 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
12818 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
12819 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
12820 atomic_set(&phba->cgn_sync_warn_cnt, 0);
12822 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
12823 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
12824 atomic_set(&phba->cgn_driver_evt_cnt, 0);
12825 atomic_set(&phba->cgn_latency_evt_cnt, 0);
12826 atomic64_set(&phba->cgn_latency_evt, 0);
12827 phba->cgn_evt_minute = 0;
12829 phba->cgn_evt_timestamp = jiffies +
12830 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
12834 lpfc_init_congestion_stat(struct lpfc_hba *phba)
12836 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
12837 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
12844 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
12845 * @phba: Pointer to hba context object.
12846 * @reg: flag to determine register or unregister.
12849 __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
12851 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
12852 union lpfc_sli4_cfg_shdr *shdr;
12853 uint32_t shdr_status, shdr_add_status;
12854 LPFC_MBOXQ_t *mboxq;
12860 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12862 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
12863 "2641 REG_CONGESTION_BUF mbox allocation fail: "
12864 "HBA state x%x reg %d\n",
12865 phba->pport->port_state, reg);
12869 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
12870 sizeof(struct lpfc_sli4_cfg_mhdr));
12871 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
12872 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
12873 LPFC_SLI4_MBX_EMBED);
12874 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
12875 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
12877 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
12879 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
12880 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
12881 reg_congestion_buf->addr_lo =
12882 putPaddrLow(phba->cgn_i->phys);
12883 reg_congestion_buf->addr_hi =
12884 putPaddrHigh(phba->cgn_i->phys);
12886 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
12887 shdr = (union lpfc_sli4_cfg_shdr *)
12888 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
12889 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
12890 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
12892 mempool_free(mboxq, phba->mbox_mem_pool);
12893 if (shdr_status || shdr_add_status || rc) {
12894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12895 "2642 REG_CONGESTION_BUF mailbox "
12896 "failed with status x%x add_status x%x,"
12897 " mbx status x%x reg %d\n",
12898 shdr_status, shdr_add_status, rc, reg);
12905 lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
12907 lpfc_cmf_stop(phba);
12908 return __lpfc_reg_congestion_buf(phba, 0);
12912 lpfc_reg_congestion_buf(struct lpfc_hba *phba)
12914 return __lpfc_reg_congestion_buf(phba, 1);
12918 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
12919 * @phba: Pointer to HBA context object.
12920 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
12922 * This function is called in the SLI4 code path to read the port's
12923 * sli4 capabilities.
12925 * This function may be be called from any context that can block-wait
12926 * for the completion. The expectation is that this routine is called
12927 * typically from probe_one or from the online routine.
12930 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
12933 struct lpfc_mqe *mqe = &mboxq->u.mqe;
12934 struct lpfc_pc_sli4_params *sli4_params;
12937 bool exp_wqcq_pages = true;
12938 struct lpfc_sli4_parameters *mbx_sli4_parameters;
12941 * By default, the driver assumes the SLI4 port requires RPI
12942 * header postings. The SLI4_PARAM response will correct this
12945 phba->sli4_hba.rpi_hdrs_in_use = 1;
12947 /* Read the port's SLI4 Config Parameters */
12948 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
12949 sizeof(struct lpfc_sli4_cfg_mhdr));
12950 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
12951 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
12952 length, LPFC_SLI4_MBX_EMBED);
12953 if (!phba->sli4_hba.intr_enable)
12954 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
12956 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
12957 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
12961 sli4_params = &phba->sli4_hba.pc_sli4_params;
12962 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
12963 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
12964 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
12965 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
12966 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
12967 mbx_sli4_parameters);
12968 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
12969 mbx_sli4_parameters);
12970 if (bf_get(cfg_phwq, mbx_sli4_parameters))
12971 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
12973 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
12974 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
12975 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
12976 mbx_sli4_parameters);
12977 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
12978 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
12979 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
12980 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
12981 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
12982 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
12983 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
12984 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
12985 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
12986 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
12987 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
12988 mbx_sli4_parameters);
12989 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
12990 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
12991 mbx_sli4_parameters);
12992 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
12993 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
12995 /* Check for Extended Pre-Registered SGL support */
12996 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
12998 /* Check for firmware nvme support */
12999 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13000 bf_get(cfg_xib, mbx_sli4_parameters));
13003 /* Save this to indicate the Firmware supports NVME */
13004 sli4_params->nvme = 1;
13006 /* Firmware NVME support, check driver FC4 NVME support */
13007 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13008 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13009 "6133 Disabling NVME support: "
13010 "FC4 type not supported: x%x\n",
13011 phba->cfg_enable_fc4_type);
13015 /* No firmware NVME support, check driver FC4 NVME support */
13016 sli4_params->nvme = 0;
13017 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13019 "6101 Disabling NVME support: Not "
13020 "supported by firmware (%d %d) x%x\n",
13021 bf_get(cfg_nvme, mbx_sli4_parameters),
13022 bf_get(cfg_xib, mbx_sli4_parameters),
13023 phba->cfg_enable_fc4_type);
13025 phba->nvmet_support = 0;
13026 phba->cfg_nvmet_mrq = 0;
13027 phba->cfg_nvme_seg_cnt = 0;
13029 /* If no FC4 type support, move to just SCSI support */
13030 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13032 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13036 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
13037 * accommodate 512K and 1M IOs in a single nvme buf.
13039 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13040 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
13042 /* Enable embedded Payload BDE if support is indicated */
13043 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13044 phba->cfg_enable_pbde = 1;
13046 phba->cfg_enable_pbde = 0;
13049 * To support Suppress Response feature we must satisfy 3 conditions.
13050 * lpfc_suppress_rsp module parameter must be set (default).
13051 * In SLI4-Parameters Descriptor:
13052 * Extended Inline Buffers (XIB) must be supported.
13053 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13054 * (double negative).
13056 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13057 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
13058 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
13060 phba->cfg_suppress_rsp = 0;
13062 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13063 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13065 /* Make sure that sge_supp_len can be handled by the driver */
13066 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13067 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13070 * Check whether the adapter supports an embedded copy of the
13071 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13072 * to use this option, 128-byte WQEs must be used.
13074 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13075 phba->fcp_embed_io = 1;
13077 phba->fcp_embed_io = 0;
13079 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13080 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
13081 bf_get(cfg_xib, mbx_sli4_parameters),
13082 phba->cfg_enable_pbde,
13083 phba->fcp_embed_io, sli4_params->nvme,
13084 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
13086 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
13087 LPFC_SLI_INTF_IF_TYPE_2) &&
13088 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
13089 LPFC_SLI_INTF_FAMILY_LNCR_A0))
13090 exp_wqcq_pages = false;
13092 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
13093 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
13095 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
13096 phba->enab_exp_wqcq_pages = 1;
13098 phba->enab_exp_wqcq_pages = 0;
13100 * Check if the SLI port supports MDS Diagnostics
13102 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
13103 phba->mds_diags_support = 1;
13105 phba->mds_diags_support = 0;
13108 * Check if the SLI port supports NSLER
13110 if (bf_get(cfg_nsler, mbx_sli4_parameters))
13119 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
13120 * @pdev: pointer to PCI device
13121 * @pid: pointer to PCI device identifier
13123 * This routine is to be called to attach a device with SLI-3 interface spec
13124 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13125 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13126 * information of the device and driver to see if the driver state that it can
13127 * support this kind of device. If the match is successful, the driver core
13128 * invokes this routine. If this routine determines it can claim the HBA, it
13129 * does all the initialization that it needs to do to handle the HBA properly.
13132 * 0 - driver can claim the device
13133 * negative value - driver can not claim the device
13136 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
13138 struct lpfc_hba *phba;
13139 struct lpfc_vport *vport = NULL;
13140 struct Scsi_Host *shost = NULL;
13142 uint32_t cfg_mode, intr_mode;
13144 /* Allocate memory for HBA structure */
13145 phba = lpfc_hba_alloc(pdev);
13149 /* Perform generic PCI device enabling operation */
13150 error = lpfc_enable_pci_dev(phba);
13152 goto out_free_phba;
13154 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
13155 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
13157 goto out_disable_pci_dev;
13159 /* Set up SLI-3 specific device PCI memory space */
13160 error = lpfc_sli_pci_mem_setup(phba);
13162 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13163 "1402 Failed to set up pci memory space.\n");
13164 goto out_disable_pci_dev;
13167 /* Set up SLI-3 specific device driver resources */
13168 error = lpfc_sli_driver_resource_setup(phba);
13170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13171 "1404 Failed to set up driver resource.\n");
13172 goto out_unset_pci_mem_s3;
13175 /* Initialize and populate the iocb list per host */
13177 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
13179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13180 "1405 Failed to initialize iocb list.\n");
13181 goto out_unset_driver_resource_s3;
13184 /* Set up common device driver resources */
13185 error = lpfc_setup_driver_resource_phase2(phba);
13187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13188 "1406 Failed to set up driver resource.\n");
13189 goto out_free_iocb_list;
13192 /* Get the default values for Model Name and Description */
13193 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13195 /* Create SCSI host to the physical port */
13196 error = lpfc_create_shost(phba);
13198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13199 "1407 Failed to create scsi host.\n");
13200 goto out_unset_driver_resource;
13203 /* Configure sysfs attributes */
13204 vport = phba->pport;
13205 error = lpfc_alloc_sysfs_attr(vport);
13207 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13208 "1476 Failed to allocate sysfs attr\n");
13209 goto out_destroy_shost;
13212 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
13213 /* Now, trying to enable interrupt and bring up the device */
13214 cfg_mode = phba->cfg_use_msi;
13216 /* Put device to a known state before enabling interrupt */
13217 lpfc_stop_port(phba);
13218 /* Configure and enable interrupt */
13219 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
13220 if (intr_mode == LPFC_INTR_ERROR) {
13221 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13222 "0431 Failed to enable interrupt.\n");
13224 goto out_free_sysfs_attr;
13226 /* SLI-3 HBA setup */
13227 if (lpfc_sli_hba_setup(phba)) {
13228 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13229 "1477 Failed to set up hba\n");
13231 goto out_remove_device;
13234 /* Wait 50ms for the interrupts of previous mailbox commands */
13236 /* Check active interrupts on message signaled interrupts */
13237 if (intr_mode == 0 ||
13238 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
13239 /* Log the current active interrupt mode */
13240 phba->intr_mode = intr_mode;
13241 lpfc_log_intr_mode(phba, intr_mode);
13244 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13245 "0447 Configure interrupt mode (%d) "
13246 "failed active interrupt test.\n",
13248 /* Disable the current interrupt mode */
13249 lpfc_sli_disable_intr(phba);
13250 /* Try next level of interrupt mode */
13251 cfg_mode = --intr_mode;
13255 /* Perform post initialization setup */
13256 lpfc_post_init_setup(phba);
13258 /* Check if there are static vports to be created. */
13259 lpfc_create_static_vport(phba);
13264 lpfc_unset_hba(phba);
13265 out_free_sysfs_attr:
13266 lpfc_free_sysfs_attr(vport);
13268 lpfc_destroy_shost(phba);
13269 out_unset_driver_resource:
13270 lpfc_unset_driver_resource_phase2(phba);
13271 out_free_iocb_list:
13272 lpfc_free_iocb_list(phba);
13273 out_unset_driver_resource_s3:
13274 lpfc_sli_driver_resource_unset(phba);
13275 out_unset_pci_mem_s3:
13276 lpfc_sli_pci_mem_unset(phba);
13277 out_disable_pci_dev:
13278 lpfc_disable_pci_dev(phba);
13280 scsi_host_put(shost);
13282 lpfc_hba_free(phba);
13287 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
13288 * @pdev: pointer to PCI device
13290 * This routine is to be called to disattach a device with SLI-3 interface
13291 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13292 * removed from PCI bus, it performs all the necessary cleanup for the HBA
13293 * device to be removed from the PCI subsystem properly.
13296 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
13298 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13299 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
13300 struct lpfc_vport **vports;
13301 struct lpfc_hba *phba = vport->phba;
13304 spin_lock_irq(&phba->hbalock);
13305 vport->load_flag |= FC_UNLOADING;
13306 spin_unlock_irq(&phba->hbalock);
13308 lpfc_free_sysfs_attr(vport);
13310 /* Release all the vports against this physical port */
13311 vports = lpfc_create_vport_work_array(phba);
13312 if (vports != NULL)
13313 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
13314 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
13316 fc_vport_terminate(vports[i]->fc_vport);
13318 lpfc_destroy_vport_work_array(phba, vports);
13320 /* Remove FC host with the physical port */
13321 fc_remove_host(shost);
13322 scsi_remove_host(shost);
13324 /* Clean up all nodes, mailboxes and IOs. */
13325 lpfc_cleanup(vport);
13328 * Bring down the SLI Layer. This step disable all interrupts,
13329 * clears the rings, discards all mailbox commands, and resets
13333 /* HBA interrupt will be disabled after this call */
13334 lpfc_sli_hba_down(phba);
13335 /* Stop kthread signal shall trigger work_done one more time */
13336 kthread_stop(phba->worker_thread);
13337 /* Final cleanup of txcmplq and reset the HBA */
13338 lpfc_sli_brdrestart(phba);
13340 kfree(phba->vpi_bmask);
13341 kfree(phba->vpi_ids);
13343 lpfc_stop_hba_timers(phba);
13344 spin_lock_irq(&phba->port_list_lock);
13345 list_del_init(&vport->listentry);
13346 spin_unlock_irq(&phba->port_list_lock);
13348 lpfc_debugfs_terminate(vport);
13350 /* Disable SR-IOV if enabled */
13351 if (phba->cfg_sriov_nr_virtfn)
13352 pci_disable_sriov(pdev);
13354 /* Disable interrupt */
13355 lpfc_sli_disable_intr(phba);
13357 scsi_host_put(shost);
13360 * Call scsi_free before mem_free since scsi bufs are released to their
13361 * corresponding pools here.
13363 lpfc_scsi_free(phba);
13364 lpfc_free_iocb_list(phba);
13366 lpfc_mem_free_all(phba);
13368 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
13369 phba->hbqslimp.virt, phba->hbqslimp.phys);
13371 /* Free resources associated with SLI2 interface */
13372 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
13373 phba->slim2p.virt, phba->slim2p.phys);
13375 /* unmap adapter SLIM and Control Registers */
13376 iounmap(phba->ctrl_regs_memmap_p);
13377 iounmap(phba->slim_memmap_p);
13379 lpfc_hba_free(phba);
13381 pci_release_mem_regions(pdev);
13382 pci_disable_device(pdev);
13386 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
13387 * @dev_d: pointer to device
13389 * This routine is to be called from the kernel's PCI subsystem to support
13390 * system Power Management (PM) to device with SLI-3 interface spec. When
13391 * PM invokes this method, it quiesces the device by stopping the driver's
13392 * worker thread for the device, turning off device's interrupt and DMA,
13393 * and bring the device offline. Note that as the driver implements the
13394 * minimum PM requirements to a power-aware driver's PM support for the
13395 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
13396 * to the suspend() method call will be treated as SUSPEND and the driver will
13397 * fully reinitialize its device during resume() method call, the driver will
13398 * set device to PCI_D3hot state in PCI config space instead of setting it
13399 * according to the @msg provided by the PM.
13402 * 0 - driver suspended the device
13405 static int __maybe_unused
13406 lpfc_pci_suspend_one_s3(struct device *dev_d)
13408 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
13409 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13411 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13412 "0473 PCI device Power Management suspend.\n");
13414 /* Bring down the device */
13415 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
13416 lpfc_offline(phba);
13417 kthread_stop(phba->worker_thread);
13419 /* Disable interrupt from device */
13420 lpfc_sli_disable_intr(phba);
13426 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
13427 * @dev_d: pointer to device
13429 * This routine is to be called from the kernel's PCI subsystem to support
13430 * system Power Management (PM) to device with SLI-3 interface spec. When PM
13431 * invokes this method, it restores the device's PCI config space state and
13432 * fully reinitializes the device and brings it online. Note that as the
13433 * driver implements the minimum PM requirements to a power-aware driver's
13434 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
13435 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
13436 * driver will fully reinitialize its device during resume() method call,
13437 * the device will be set to PCI_D0 directly in PCI config space before
13438 * restoring the state.
13441 * 0 - driver suspended the device
13444 static int __maybe_unused
13445 lpfc_pci_resume_one_s3(struct device *dev_d)
13447 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
13448 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13449 uint32_t intr_mode;
13452 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13453 "0452 PCI device Power Management resume.\n");
13455 /* Startup the kernel thread for this host adapter. */
13456 phba->worker_thread = kthread_run(lpfc_do_work, phba,
13457 "lpfc_worker_%d", phba->brd_no);
13458 if (IS_ERR(phba->worker_thread)) {
13459 error = PTR_ERR(phba->worker_thread);
13460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13461 "0434 PM resume failed to start worker "
13462 "thread: error=x%x.\n", error);
13466 /* Configure and enable interrupt */
13467 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
13468 if (intr_mode == LPFC_INTR_ERROR) {
13469 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13470 "0430 PM resume Failed to enable interrupt\n");
13473 phba->intr_mode = intr_mode;
13475 /* Restart HBA and bring it online */
13476 lpfc_sli_brdrestart(phba);
13479 /* Log the current active interrupt mode */
13480 lpfc_log_intr_mode(phba, phba->intr_mode);
13486 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
13487 * @phba: pointer to lpfc hba data structure.
13489 * This routine is called to prepare the SLI3 device for PCI slot recover. It
13490 * aborts all the outstanding SCSI I/Os to the pci device.
13493 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
13495 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13496 "2723 PCI channel I/O abort preparing for recovery\n");
13499 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
13500 * and let the SCSI mid-layer to retry them to recover.
13502 lpfc_sli_abort_fcp_rings(phba);
13506 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
13507 * @phba: pointer to lpfc hba data structure.
13509 * This routine is called to prepare the SLI3 device for PCI slot reset. It
13510 * disables the device interrupt and pci device, and aborts the internal FCP
13514 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
13516 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13517 "2710 PCI channel disable preparing for reset\n");
13519 /* Block any management I/Os to the device */
13520 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
13522 /* Block all SCSI devices' I/Os on the host */
13523 lpfc_scsi_dev_block(phba);
13525 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
13526 lpfc_sli_flush_io_rings(phba);
13528 /* stop all timers */
13529 lpfc_stop_hba_timers(phba);
13531 /* Disable interrupt and pci device */
13532 lpfc_sli_disable_intr(phba);
13533 pci_disable_device(phba->pcidev);
13537 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
13538 * @phba: pointer to lpfc hba data structure.
13540 * This routine is called to prepare the SLI3 device for PCI slot permanently
13541 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
13545 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
13547 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13548 "2711 PCI channel permanent disable for failure\n");
13549 /* Block all SCSI devices' I/Os on the host */
13550 lpfc_scsi_dev_block(phba);
13552 /* stop all timers */
13553 lpfc_stop_hba_timers(phba);
13555 /* Clean up all driver's outstanding SCSI I/Os */
13556 lpfc_sli_flush_io_rings(phba);
13560 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
13561 * @pdev: pointer to PCI device.
13562 * @state: the current PCI connection state.
13564 * This routine is called from the PCI subsystem for I/O error handling to
13565 * device with SLI-3 interface spec. This function is called by the PCI
13566 * subsystem after a PCI bus error affecting this device has been detected.
13567 * When this function is invoked, it will need to stop all the I/Os and
13568 * interrupt(s) to the device. Once that is done, it will return
13569 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
13573 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
13574 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13575 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13577 static pci_ers_result_t
13578 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
13580 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13581 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13584 case pci_channel_io_normal:
13585 /* Non-fatal error, prepare for recovery */
13586 lpfc_sli_prep_dev_for_recover(phba);
13587 return PCI_ERS_RESULT_CAN_RECOVER;
13588 case pci_channel_io_frozen:
13589 /* Fatal error, prepare for slot reset */
13590 lpfc_sli_prep_dev_for_reset(phba);
13591 return PCI_ERS_RESULT_NEED_RESET;
13592 case pci_channel_io_perm_failure:
13593 /* Permanent failure, prepare for device down */
13594 lpfc_sli_prep_dev_for_perm_failure(phba);
13595 return PCI_ERS_RESULT_DISCONNECT;
13597 /* Unknown state, prepare and request slot reset */
13598 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13599 "0472 Unknown PCI error state: x%x\n", state);
13600 lpfc_sli_prep_dev_for_reset(phba);
13601 return PCI_ERS_RESULT_NEED_RESET;
13606 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
13607 * @pdev: pointer to PCI device.
13609 * This routine is called from the PCI subsystem for error handling to
13610 * device with SLI-3 interface spec. This is called after PCI bus has been
13611 * reset to restart the PCI card from scratch, as if from a cold-boot.
13612 * During the PCI subsystem error recovery, after driver returns
13613 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13614 * recovery and then call this routine before calling the .resume method
13615 * to recover the device. This function will initialize the HBA device,
13616 * enable the interrupt, but it will just put the HBA to offline state
13617 * without passing any I/O traffic.
13620 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13621 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13623 static pci_ers_result_t
13624 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
13626 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13627 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13628 struct lpfc_sli *psli = &phba->sli;
13629 uint32_t intr_mode;
13631 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
13632 if (pci_enable_device_mem(pdev)) {
13633 printk(KERN_ERR "lpfc: Cannot re-enable "
13634 "PCI device after reset.\n");
13635 return PCI_ERS_RESULT_DISCONNECT;
13638 pci_restore_state(pdev);
13641 * As the new kernel behavior of pci_restore_state() API call clears
13642 * device saved_state flag, need to save the restored state again.
13644 pci_save_state(pdev);
13646 if (pdev->is_busmaster)
13647 pci_set_master(pdev);
13649 spin_lock_irq(&phba->hbalock);
13650 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
13651 spin_unlock_irq(&phba->hbalock);
13653 /* Configure and enable interrupt */
13654 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
13655 if (intr_mode == LPFC_INTR_ERROR) {
13656 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13657 "0427 Cannot re-enable interrupt after "
13659 return PCI_ERS_RESULT_DISCONNECT;
13661 phba->intr_mode = intr_mode;
13663 /* Take device offline, it will perform cleanup */
13664 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
13665 lpfc_offline(phba);
13666 lpfc_sli_brdrestart(phba);
13668 /* Log the current active interrupt mode */
13669 lpfc_log_intr_mode(phba, phba->intr_mode);
13671 return PCI_ERS_RESULT_RECOVERED;
13675 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
13676 * @pdev: pointer to PCI device
13678 * This routine is called from the PCI subsystem for error handling to device
13679 * with SLI-3 interface spec. It is called when kernel error recovery tells
13680 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13681 * error recovery. After this call, traffic can start to flow from this device
13685 lpfc_io_resume_s3(struct pci_dev *pdev)
13687 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13688 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13690 /* Bring device online, it will be no-op for non-fatal error resume */
13695 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
13696 * @phba: pointer to lpfc hba data structure.
13698 * returns the number of ELS/CT IOCBs to reserve
13701 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
13703 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
13705 if (phba->sli_rev == LPFC_SLI_REV4) {
13706 if (max_xri <= 100)
13708 else if (max_xri <= 256)
13710 else if (max_xri <= 512)
13712 else if (max_xri <= 1024)
13714 else if (max_xri <= 1536)
13716 else if (max_xri <= 2048)
13725 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
13726 * @phba: pointer to lpfc hba data structure.
13728 * returns the number of ELS/CT + NVMET IOCBs to reserve
13731 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
13733 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
13735 if (phba->nvmet_support)
13736 max_xri += LPFC_NVMET_BUF_POST;
13742 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
13743 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
13744 const struct firmware *fw)
13749 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
13750 /* Three cases: (1) FW was not supported on the detected adapter.
13751 * (2) FW update has been locked out administratively.
13752 * (3) Some other error during FW update.
13753 * In each case, an unmaskable message is written to the console
13754 * for admin diagnosis.
13756 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
13757 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
13758 magic_number != MAGIC_NUMBER_G6) ||
13759 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
13760 magic_number != MAGIC_NUMBER_G7) ||
13761 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
13762 magic_number != MAGIC_NUMBER_G7P)) {
13763 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13764 "3030 This firmware version is not supported on"
13765 " this HBA model. Device:%x Magic:%x Type:%x "
13766 "ID:%x Size %d %zd\n",
13767 phba->pcidev->device, magic_number, ftype, fid,
13770 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
13771 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13772 "3021 Firmware downloads have been prohibited "
13773 "by a system configuration setting on "
13774 "Device:%x Magic:%x Type:%x ID:%x Size %d "
13776 phba->pcidev->device, magic_number, ftype, fid,
13780 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13781 "3022 FW Download failed. Add Status x%x "
13782 "Device:%x Magic:%x Type:%x ID:%x Size %d "
13784 offset, phba->pcidev->device, magic_number,
13785 ftype, fid, fsize, fw->size);
13792 * lpfc_write_firmware - attempt to write a firmware image to the port
13793 * @fw: pointer to firmware image returned from request_firmware.
13794 * @context: pointer to firmware image returned from request_firmware.
13798 lpfc_write_firmware(const struct firmware *fw, void *context)
13800 struct lpfc_hba *phba = (struct lpfc_hba *)context;
13801 char fwrev[FW_REV_STR_SIZE];
13802 struct lpfc_grp_hdr *image;
13803 struct list_head dma_buffer_list;
13805 struct lpfc_dmabuf *dmabuf, *next;
13806 uint32_t offset = 0, temp_offset = 0;
13807 uint32_t magic_number, ftype, fid, fsize;
13809 /* It can be null in no-wait mode, sanity check */
13814 image = (struct lpfc_grp_hdr *)fw->data;
13816 magic_number = be32_to_cpu(image->magic_number);
13817 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
13818 fid = bf_get_be32(lpfc_grp_hdr_id, image);
13819 fsize = be32_to_cpu(image->size);
13821 INIT_LIST_HEAD(&dma_buffer_list);
13822 lpfc_decode_firmware_rev(phba, fwrev, 1);
13823 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
13824 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13825 "3023 Updating Firmware, Current Version:%s "
13826 "New Version:%s\n",
13827 fwrev, image->revision);
13828 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
13829 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
13835 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
13839 if (!dmabuf->virt) {
13844 list_add_tail(&dmabuf->list, &dma_buffer_list);
13846 while (offset < fw->size) {
13847 temp_offset = offset;
13848 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
13849 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
13850 memcpy(dmabuf->virt,
13851 fw->data + temp_offset,
13852 fw->size - temp_offset);
13853 temp_offset = fw->size;
13856 memcpy(dmabuf->virt, fw->data + temp_offset,
13858 temp_offset += SLI4_PAGE_SIZE;
13860 rc = lpfc_wr_object(phba, &dma_buffer_list,
13861 (fw->size - offset), &offset);
13863 rc = lpfc_log_write_firmware_error(phba, offset,
13874 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13875 "3029 Skipped Firmware update, Current "
13876 "Version:%s New Version:%s\n",
13877 fwrev, image->revision);
13880 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
13881 list_del(&dmabuf->list);
13882 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
13883 dmabuf->virt, dmabuf->phys);
13886 release_firmware(fw);
13889 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13890 "3062 Firmware update error, status %d.\n", rc);
13892 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13893 "3024 Firmware update success: size %d.\n", rc);
13897 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
13898 * @phba: pointer to lpfc hba data structure.
13899 * @fw_upgrade: which firmware to update.
13901 * This routine is called to perform Linux generic firmware upgrade on device
13902 * that supports such feature.
13905 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
13907 uint8_t file_name[ELX_MODEL_NAME_SIZE];
13909 const struct firmware *fw;
13911 /* Only supported on SLI4 interface type 2 for now */
13912 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
13913 LPFC_SLI_INTF_IF_TYPE_2)
13916 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
13918 if (fw_upgrade == INT_FW_UPGRADE) {
13919 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
13920 file_name, &phba->pcidev->dev,
13921 GFP_KERNEL, (void *)phba,
13922 lpfc_write_firmware);
13923 } else if (fw_upgrade == RUN_FW_UPGRADE) {
13924 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
13926 lpfc_write_firmware(fw, (void *)phba);
13935 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
13936 * @pdev: pointer to PCI device
13937 * @pid: pointer to PCI device identifier
13939 * This routine is called from the kernel's PCI subsystem to device with
13940 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13941 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13942 * information of the device and driver to see if the driver state that it
13943 * can support this kind of device. If the match is successful, the driver
13944 * core invokes this routine. If this routine determines it can claim the HBA,
13945 * it does all the initialization that it needs to do to handle the HBA
13949 * 0 - driver can claim the device
13950 * negative value - driver can not claim the device
13953 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
13955 struct lpfc_hba *phba;
13956 struct lpfc_vport *vport = NULL;
13957 struct Scsi_Host *shost = NULL;
13959 uint32_t cfg_mode, intr_mode;
13961 /* Allocate memory for HBA structure */
13962 phba = lpfc_hba_alloc(pdev);
13966 /* Perform generic PCI device enabling operation */
13967 error = lpfc_enable_pci_dev(phba);
13969 goto out_free_phba;
13971 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
13972 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
13974 goto out_disable_pci_dev;
13976 /* Set up SLI-4 specific device PCI memory space */
13977 error = lpfc_sli4_pci_mem_setup(phba);
13979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13980 "1410 Failed to set up pci memory space.\n");
13981 goto out_disable_pci_dev;
13984 /* Set up SLI-4 Specific device driver resources */
13985 error = lpfc_sli4_driver_resource_setup(phba);
13987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13988 "1412 Failed to set up driver resource.\n");
13989 goto out_unset_pci_mem_s4;
13992 INIT_LIST_HEAD(&phba->active_rrq_list);
13993 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
13995 /* Set up common device driver resources */
13996 error = lpfc_setup_driver_resource_phase2(phba);
13998 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13999 "1414 Failed to set up driver resource.\n");
14000 goto out_unset_driver_resource_s4;
14003 /* Get the default values for Model Name and Description */
14004 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14006 /* Now, trying to enable interrupt and bring up the device */
14007 cfg_mode = phba->cfg_use_msi;
14009 /* Put device to a known state before enabling interrupt */
14010 phba->pport = NULL;
14011 lpfc_stop_port(phba);
14013 /* Init cpu_map array */
14014 lpfc_cpu_map_array_init(phba);
14016 /* Init hba_eq_hdl array */
14017 lpfc_hba_eq_hdl_array_init(phba);
14019 /* Configure and enable interrupt */
14020 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14021 if (intr_mode == LPFC_INTR_ERROR) {
14022 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14023 "0426 Failed to enable interrupt.\n");
14025 goto out_unset_driver_resource;
14027 /* Default to single EQ for non-MSI-X */
14028 if (phba->intr_type != MSIX) {
14029 phba->cfg_irq_chann = 1;
14030 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14031 if (phba->nvmet_support)
14032 phba->cfg_nvmet_mrq = 1;
14035 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
14037 /* Create SCSI host to the physical port */
14038 error = lpfc_create_shost(phba);
14040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14041 "1415 Failed to create scsi host.\n");
14042 goto out_disable_intr;
14044 vport = phba->pport;
14045 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14047 /* Configure sysfs attributes */
14048 error = lpfc_alloc_sysfs_attr(vport);
14050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14051 "1416 Failed to allocate sysfs attr\n");
14052 goto out_destroy_shost;
14055 /* Set up SLI-4 HBA */
14056 if (lpfc_sli4_hba_setup(phba)) {
14057 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14058 "1421 Failed to set up hba\n");
14060 goto out_free_sysfs_attr;
14063 /* Log the current active interrupt mode */
14064 phba->intr_mode = intr_mode;
14065 lpfc_log_intr_mode(phba, intr_mode);
14067 /* Perform post initialization setup */
14068 lpfc_post_init_setup(phba);
14070 /* NVME support in FW earlier in the driver load corrects the
14071 * FC4 type making a check for nvme_support unnecessary.
14073 if (phba->nvmet_support == 0) {
14074 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14075 /* Create NVME binding with nvme_fc_transport. This
14076 * ensures the vport is initialized. If the localport
14077 * create fails, it should not unload the driver to
14078 * support field issues.
14080 error = lpfc_nvme_create_localport(vport);
14082 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14083 "6004 NVME registration "
14084 "failed, error x%x\n",
14090 /* check for firmware upgrade or downgrade */
14091 if (phba->cfg_request_firmware_upgrade)
14092 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
14094 /* Check if there are static vports to be created. */
14095 lpfc_create_static_vport(phba);
14097 /* Enable RAS FW log support */
14098 lpfc_sli4_ras_setup(phba);
14100 INIT_LIST_HEAD(&phba->poll_list);
14101 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
14102 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
14106 out_free_sysfs_attr:
14107 lpfc_free_sysfs_attr(vport);
14109 lpfc_destroy_shost(phba);
14111 lpfc_sli4_disable_intr(phba);
14112 out_unset_driver_resource:
14113 lpfc_unset_driver_resource_phase2(phba);
14114 out_unset_driver_resource_s4:
14115 lpfc_sli4_driver_resource_unset(phba);
14116 out_unset_pci_mem_s4:
14117 lpfc_sli4_pci_mem_unset(phba);
14118 out_disable_pci_dev:
14119 lpfc_disable_pci_dev(phba);
14121 scsi_host_put(shost);
14123 lpfc_hba_free(phba);
14128 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
14129 * @pdev: pointer to PCI device
14131 * This routine is called from the kernel's PCI subsystem to device with
14132 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14133 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14134 * device to be removed from the PCI subsystem properly.
14137 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
14139 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14141 struct lpfc_vport **vports;
14142 struct lpfc_hba *phba = vport->phba;
14145 /* Mark the device unloading flag */
14146 spin_lock_irq(&phba->hbalock);
14147 vport->load_flag |= FC_UNLOADING;
14148 spin_unlock_irq(&phba->hbalock);
14150 lpfc_unreg_congestion_buf(phba);
14152 lpfc_free_sysfs_attr(vport);
14154 /* Release all the vports against this physical port */
14155 vports = lpfc_create_vport_work_array(phba);
14156 if (vports != NULL)
14157 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14158 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14160 fc_vport_terminate(vports[i]->fc_vport);
14162 lpfc_destroy_vport_work_array(phba, vports);
14164 /* Remove FC host with the physical port */
14165 fc_remove_host(shost);
14166 scsi_remove_host(shost);
14168 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
14169 * localports are destroyed after to cleanup all transport memory.
14171 lpfc_cleanup(vport);
14172 lpfc_nvmet_destroy_targetport(phba);
14173 lpfc_nvme_destroy_localport(vport);
14175 /* De-allocate multi-XRI pools */
14176 if (phba->cfg_xri_rebalancing)
14177 lpfc_destroy_multixri_pools(phba);
14180 * Bring down the SLI Layer. This step disables all interrupts,
14181 * clears the rings, discards all mailbox commands, and resets
14182 * the HBA FCoE function.
14184 lpfc_debugfs_terminate(vport);
14186 lpfc_stop_hba_timers(phba);
14187 spin_lock_irq(&phba->port_list_lock);
14188 list_del_init(&vport->listentry);
14189 spin_unlock_irq(&phba->port_list_lock);
14191 /* Perform scsi free before driver resource_unset since scsi
14192 * buffers are released to their corresponding pools here.
14194 lpfc_io_free(phba);
14195 lpfc_free_iocb_list(phba);
14196 lpfc_sli4_hba_unset(phba);
14198 lpfc_unset_driver_resource_phase2(phba);
14199 lpfc_sli4_driver_resource_unset(phba);
14201 /* Unmap adapter Control and Doorbell registers */
14202 lpfc_sli4_pci_mem_unset(phba);
14204 /* Release PCI resources and disable device's PCI function */
14205 scsi_host_put(shost);
14206 lpfc_disable_pci_dev(phba);
14208 /* Finally, free the driver's device data structure */
14209 lpfc_hba_free(phba);
14215 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
14216 * @dev_d: pointer to device
14218 * This routine is called from the kernel's PCI subsystem to support system
14219 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
14220 * this method, it quiesces the device by stopping the driver's worker
14221 * thread for the device, turning off device's interrupt and DMA, and bring
14222 * the device offline. Note that as the driver implements the minimum PM
14223 * requirements to a power-aware driver's PM support for suspend/resume -- all
14224 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
14225 * method call will be treated as SUSPEND and the driver will fully
14226 * reinitialize its device during resume() method call, the driver will set
14227 * device to PCI_D3hot state in PCI config space instead of setting it
14228 * according to the @msg provided by the PM.
14231 * 0 - driver suspended the device
14234 static int __maybe_unused
14235 lpfc_pci_suspend_one_s4(struct device *dev_d)
14237 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14238 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14240 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14241 "2843 PCI device Power Management suspend.\n");
14243 /* Bring down the device */
14244 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14245 lpfc_offline(phba);
14246 kthread_stop(phba->worker_thread);
14248 /* Disable interrupt from device */
14249 lpfc_sli4_disable_intr(phba);
14250 lpfc_sli4_queue_destroy(phba);
14256 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
14257 * @dev_d: pointer to device
14259 * This routine is called from the kernel's PCI subsystem to support system
14260 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
14261 * this method, it restores the device's PCI config space state and fully
14262 * reinitializes the device and brings it online. Note that as the driver
14263 * implements the minimum PM requirements to a power-aware driver's PM for
14264 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14265 * to the suspend() method call will be treated as SUSPEND and the driver
14266 * will fully reinitialize its device during resume() method call, the device
14267 * will be set to PCI_D0 directly in PCI config space before restoring the
14271 * 0 - driver suspended the device
14274 static int __maybe_unused
14275 lpfc_pci_resume_one_s4(struct device *dev_d)
14277 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
14278 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14279 uint32_t intr_mode;
14282 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14283 "0292 PCI device Power Management resume.\n");
14285 /* Startup the kernel thread for this host adapter. */
14286 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14287 "lpfc_worker_%d", phba->brd_no);
14288 if (IS_ERR(phba->worker_thread)) {
14289 error = PTR_ERR(phba->worker_thread);
14290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14291 "0293 PM resume failed to start worker "
14292 "thread: error=x%x.\n", error);
14296 /* Configure and enable interrupt */
14297 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
14298 if (intr_mode == LPFC_INTR_ERROR) {
14299 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14300 "0294 PM resume Failed to enable interrupt\n");
14303 phba->intr_mode = intr_mode;
14305 /* Restart HBA and bring it online */
14306 lpfc_sli_brdrestart(phba);
14309 /* Log the current active interrupt mode */
14310 lpfc_log_intr_mode(phba, phba->intr_mode);
14316 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
14317 * @phba: pointer to lpfc hba data structure.
14319 * This routine is called to prepare the SLI4 device for PCI slot recover. It
14320 * aborts all the outstanding SCSI I/Os to the pci device.
14323 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
14325 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14326 "2828 PCI channel I/O abort preparing for recovery\n");
14328 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14329 * and let the SCSI mid-layer to retry them to recover.
14331 lpfc_sli_abort_fcp_rings(phba);
14335 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
14336 * @phba: pointer to lpfc hba data structure.
14338 * This routine is called to prepare the SLI4 device for PCI slot reset. It
14339 * disables the device interrupt and pci device, and aborts the internal FCP
14343 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
14345 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14346 "2826 PCI channel disable preparing for reset\n");
14348 /* Block any management I/Os to the device */
14349 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
14351 /* Block all SCSI devices' I/Os on the host */
14352 lpfc_scsi_dev_block(phba);
14354 /* Flush all driver's outstanding I/Os as we are to reset */
14355 lpfc_sli_flush_io_rings(phba);
14357 /* stop all timers */
14358 lpfc_stop_hba_timers(phba);
14360 /* Disable interrupt and pci device */
14361 lpfc_sli4_disable_intr(phba);
14362 lpfc_sli4_queue_destroy(phba);
14363 pci_disable_device(phba->pcidev);
14367 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
14368 * @phba: pointer to lpfc hba data structure.
14370 * This routine is called to prepare the SLI4 device for PCI slot permanently
14371 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14375 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
14377 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14378 "2827 PCI channel permanent disable for failure\n");
14380 /* Block all SCSI devices' I/Os on the host */
14381 lpfc_scsi_dev_block(phba);
14383 /* stop all timers */
14384 lpfc_stop_hba_timers(phba);
14386 /* Clean up all driver's outstanding I/Os */
14387 lpfc_sli_flush_io_rings(phba);
14391 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
14392 * @pdev: pointer to PCI device.
14393 * @state: the current PCI connection state.
14395 * This routine is called from the PCI subsystem for error handling to device
14396 * with SLI-4 interface spec. This function is called by the PCI subsystem
14397 * after a PCI bus error affecting this device has been detected. When this
14398 * function is invoked, it will need to stop all the I/Os and interrupt(s)
14399 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
14400 * for the PCI subsystem to perform proper recovery as desired.
14403 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14404 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14406 static pci_ers_result_t
14407 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
14409 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14410 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14413 case pci_channel_io_normal:
14414 /* Non-fatal error, prepare for recovery */
14415 lpfc_sli4_prep_dev_for_recover(phba);
14416 return PCI_ERS_RESULT_CAN_RECOVER;
14417 case pci_channel_io_frozen:
14418 /* Fatal error, prepare for slot reset */
14419 lpfc_sli4_prep_dev_for_reset(phba);
14420 return PCI_ERS_RESULT_NEED_RESET;
14421 case pci_channel_io_perm_failure:
14422 /* Permanent failure, prepare for device down */
14423 lpfc_sli4_prep_dev_for_perm_failure(phba);
14424 return PCI_ERS_RESULT_DISCONNECT;
14426 /* Unknown state, prepare and request slot reset */
14427 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14428 "2825 Unknown PCI error state: x%x\n", state);
14429 lpfc_sli4_prep_dev_for_reset(phba);
14430 return PCI_ERS_RESULT_NEED_RESET;
14435 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
14436 * @pdev: pointer to PCI device.
14438 * This routine is called from the PCI subsystem for error handling to device
14439 * with SLI-4 interface spec. It is called after PCI bus has been reset to
14440 * restart the PCI card from scratch, as if from a cold-boot. During the
14441 * PCI subsystem error recovery, after the driver returns
14442 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14443 * recovery and then call this routine before calling the .resume method to
14444 * recover the device. This function will initialize the HBA device, enable
14445 * the interrupt, but it will just put the HBA to offline state without
14446 * passing any I/O traffic.
14449 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14450 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14452 static pci_ers_result_t
14453 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
14455 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14456 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14457 struct lpfc_sli *psli = &phba->sli;
14458 uint32_t intr_mode;
14460 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
14461 if (pci_enable_device_mem(pdev)) {
14462 printk(KERN_ERR "lpfc: Cannot re-enable "
14463 "PCI device after reset.\n");
14464 return PCI_ERS_RESULT_DISCONNECT;
14467 pci_restore_state(pdev);
14470 * As the new kernel behavior of pci_restore_state() API call clears
14471 * device saved_state flag, need to save the restored state again.
14473 pci_save_state(pdev);
14475 if (pdev->is_busmaster)
14476 pci_set_master(pdev);
14478 spin_lock_irq(&phba->hbalock);
14479 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
14480 spin_unlock_irq(&phba->hbalock);
14482 /* Configure and enable interrupt */
14483 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
14484 if (intr_mode == LPFC_INTR_ERROR) {
14485 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14486 "2824 Cannot re-enable interrupt after "
14488 return PCI_ERS_RESULT_DISCONNECT;
14490 phba->intr_mode = intr_mode;
14492 /* Log the current active interrupt mode */
14493 lpfc_log_intr_mode(phba, phba->intr_mode);
14495 return PCI_ERS_RESULT_RECOVERED;
14499 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
14500 * @pdev: pointer to PCI device
14502 * This routine is called from the PCI subsystem for error handling to device
14503 * with SLI-4 interface spec. It is called when kernel error recovery tells
14504 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14505 * error recovery. After this call, traffic can start to flow from this device
14509 lpfc_io_resume_s4(struct pci_dev *pdev)
14511 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14512 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14515 * In case of slot reset, as function reset is performed through
14516 * mailbox command which needs DMA to be enabled, this operation
14517 * has to be moved to the io resume phase. Taking device offline
14518 * will perform the necessary cleanup.
14520 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
14521 /* Perform device reset */
14522 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
14523 lpfc_offline(phba);
14524 lpfc_sli_brdrestart(phba);
14525 /* Bring the device back online */
14531 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
14532 * @pdev: pointer to PCI device
14533 * @pid: pointer to PCI device identifier
14535 * This routine is to be registered to the kernel's PCI subsystem. When an
14536 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
14537 * at PCI device-specific information of the device and driver to see if the
14538 * driver state that it can support this kind of device. If the match is
14539 * successful, the driver core invokes this routine. This routine dispatches
14540 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
14541 * do all the initialization that it needs to do to handle the HBA device
14545 * 0 - driver can claim the device
14546 * negative value - driver can not claim the device
14549 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
14552 struct lpfc_sli_intf intf;
14554 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
14557 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
14558 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
14559 rc = lpfc_pci_probe_one_s4(pdev, pid);
14561 rc = lpfc_pci_probe_one_s3(pdev, pid);
14567 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
14568 * @pdev: pointer to PCI device
14570 * This routine is to be registered to the kernel's PCI subsystem. When an
14571 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
14572 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
14573 * remove routine, which will perform all the necessary cleanup for the
14574 * device to be removed from the PCI subsystem properly.
14577 lpfc_pci_remove_one(struct pci_dev *pdev)
14579 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14580 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14582 switch (phba->pci_dev_grp) {
14583 case LPFC_PCI_DEV_LP:
14584 lpfc_pci_remove_one_s3(pdev);
14586 case LPFC_PCI_DEV_OC:
14587 lpfc_pci_remove_one_s4(pdev);
14590 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14591 "1424 Invalid PCI device group: 0x%x\n",
14592 phba->pci_dev_grp);
14599 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
14600 * @dev: pointer to device
14602 * This routine is to be registered to the kernel's PCI subsystem to support
14603 * system Power Management (PM). When PM invokes this method, it dispatches
14604 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
14605 * suspend the device.
14608 * 0 - driver suspended the device
14611 static int __maybe_unused
14612 lpfc_pci_suspend_one(struct device *dev)
14614 struct Scsi_Host *shost = dev_get_drvdata(dev);
14615 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14618 switch (phba->pci_dev_grp) {
14619 case LPFC_PCI_DEV_LP:
14620 rc = lpfc_pci_suspend_one_s3(dev);
14622 case LPFC_PCI_DEV_OC:
14623 rc = lpfc_pci_suspend_one_s4(dev);
14626 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14627 "1425 Invalid PCI device group: 0x%x\n",
14628 phba->pci_dev_grp);
14635 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
14636 * @dev: pointer to device
14638 * This routine is to be registered to the kernel's PCI subsystem to support
14639 * system Power Management (PM). When PM invokes this method, it dispatches
14640 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
14641 * resume the device.
14644 * 0 - driver suspended the device
14647 static int __maybe_unused
14648 lpfc_pci_resume_one(struct device *dev)
14650 struct Scsi_Host *shost = dev_get_drvdata(dev);
14651 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14654 switch (phba->pci_dev_grp) {
14655 case LPFC_PCI_DEV_LP:
14656 rc = lpfc_pci_resume_one_s3(dev);
14658 case LPFC_PCI_DEV_OC:
14659 rc = lpfc_pci_resume_one_s4(dev);
14662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14663 "1426 Invalid PCI device group: 0x%x\n",
14664 phba->pci_dev_grp);
14671 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
14672 * @pdev: pointer to PCI device.
14673 * @state: the current PCI connection state.
14675 * This routine is registered to the PCI subsystem for error handling. This
14676 * function is called by the PCI subsystem after a PCI bus error affecting
14677 * this device has been detected. When this routine is invoked, it dispatches
14678 * the action to the proper SLI-3 or SLI-4 device error detected handling
14679 * routine, which will perform the proper error detected operation.
14682 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14683 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14685 static pci_ers_result_t
14686 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
14688 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14689 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14690 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
14692 switch (phba->pci_dev_grp) {
14693 case LPFC_PCI_DEV_LP:
14694 rc = lpfc_io_error_detected_s3(pdev, state);
14696 case LPFC_PCI_DEV_OC:
14697 rc = lpfc_io_error_detected_s4(pdev, state);
14700 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14701 "1427 Invalid PCI device group: 0x%x\n",
14702 phba->pci_dev_grp);
14709 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
14710 * @pdev: pointer to PCI device.
14712 * This routine is registered to the PCI subsystem for error handling. This
14713 * function is called after PCI bus has been reset to restart the PCI card
14714 * from scratch, as if from a cold-boot. When this routine is invoked, it
14715 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
14716 * routine, which will perform the proper device reset.
14719 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14720 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
14722 static pci_ers_result_t
14723 lpfc_io_slot_reset(struct pci_dev *pdev)
14725 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14726 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14727 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
14729 switch (phba->pci_dev_grp) {
14730 case LPFC_PCI_DEV_LP:
14731 rc = lpfc_io_slot_reset_s3(pdev);
14733 case LPFC_PCI_DEV_OC:
14734 rc = lpfc_io_slot_reset_s4(pdev);
14737 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14738 "1428 Invalid PCI device group: 0x%x\n",
14739 phba->pci_dev_grp);
14746 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
14747 * @pdev: pointer to PCI device
14749 * This routine is registered to the PCI subsystem for error handling. It
14750 * is called when kernel error recovery tells the lpfc driver that it is
14751 * OK to resume normal PCI operation after PCI bus error recovery. When
14752 * this routine is invoked, it dispatches the action to the proper SLI-3
14753 * or SLI-4 device io_resume routine, which will resume the device operation.
14756 lpfc_io_resume(struct pci_dev *pdev)
14758 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14759 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14761 switch (phba->pci_dev_grp) {
14762 case LPFC_PCI_DEV_LP:
14763 lpfc_io_resume_s3(pdev);
14765 case LPFC_PCI_DEV_OC:
14766 lpfc_io_resume_s4(pdev);
14769 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14770 "1429 Invalid PCI device group: 0x%x\n",
14771 phba->pci_dev_grp);
14778 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
14779 * @phba: pointer to lpfc hba data structure.
14781 * This routine checks to see if OAS is supported for this adapter. If
14782 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
14783 * the enable oas flag is cleared and the pool created for OAS device data
14788 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
14791 if (!phba->cfg_EnableXLane)
14794 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
14798 mempool_destroy(phba->device_data_mem_pool);
14799 phba->device_data_mem_pool = NULL;
14806 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
14807 * @phba: pointer to lpfc hba data structure.
14809 * This routine checks to see if RAS is supported by the adapter. Check the
14810 * function through which RAS support enablement is to be done.
14813 lpfc_sli4_ras_init(struct lpfc_hba *phba)
14815 /* if ASIC_GEN_NUM >= 0xC) */
14816 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
14817 LPFC_SLI_INTF_IF_TYPE_6) ||
14818 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
14819 LPFC_SLI_INTF_FAMILY_G6)) {
14820 phba->ras_fwlog.ras_hwsupport = true;
14821 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
14822 phba->cfg_ras_fwlog_buffsize)
14823 phba->ras_fwlog.ras_enabled = true;
14825 phba->ras_fwlog.ras_enabled = false;
14827 phba->ras_fwlog.ras_hwsupport = false;
14832 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
14834 static const struct pci_error_handlers lpfc_err_handler = {
14835 .error_detected = lpfc_io_error_detected,
14836 .slot_reset = lpfc_io_slot_reset,
14837 .resume = lpfc_io_resume,
14840 static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
14841 lpfc_pci_suspend_one,
14842 lpfc_pci_resume_one);
14844 static struct pci_driver lpfc_driver = {
14845 .name = LPFC_DRIVER_NAME,
14846 .id_table = lpfc_id_table,
14847 .probe = lpfc_pci_probe_one,
14848 .remove = lpfc_pci_remove_one,
14849 .shutdown = lpfc_pci_remove_one,
14850 .driver.pm = &lpfc_pci_pm_ops_one,
14851 .err_handler = &lpfc_err_handler,
14854 static const struct file_operations lpfc_mgmt_fop = {
14855 .owner = THIS_MODULE,
14858 static struct miscdevice lpfc_mgmt_dev = {
14859 .minor = MISC_DYNAMIC_MINOR,
14860 .name = "lpfcmgmt",
14861 .fops = &lpfc_mgmt_fop,
14865 * lpfc_init - lpfc module initialization routine
14867 * This routine is to be invoked when the lpfc module is loaded into the
14868 * kernel. The special kernel macro module_init() is used to indicate the
14869 * role of this routine to the kernel as lpfc module entry point.
14873 * -ENOMEM - FC attach transport failed
14874 * all others - failed
14881 pr_info(LPFC_MODULE_DESC "\n");
14882 pr_info(LPFC_COPYRIGHT "\n");
14884 error = misc_register(&lpfc_mgmt_dev);
14886 printk(KERN_ERR "Could not register lpfcmgmt device, "
14887 "misc_register returned with status %d", error);
14890 lpfc_transport_functions.vport_create = lpfc_vport_create;
14891 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
14892 lpfc_transport_template =
14893 fc_attach_transport(&lpfc_transport_functions);
14894 if (lpfc_transport_template == NULL)
14896 lpfc_vport_transport_template =
14897 fc_attach_transport(&lpfc_vport_transport_functions);
14898 if (lpfc_vport_transport_template == NULL) {
14899 fc_release_transport(lpfc_transport_template);
14902 lpfc_wqe_cmd_template();
14903 lpfc_nvmet_cmd_template();
14905 /* Initialize in case vector mapping is needed */
14906 lpfc_present_cpu = num_present_cpus();
14908 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
14909 "lpfc/sli4:online",
14910 lpfc_cpu_online, lpfc_cpu_offline);
14912 goto cpuhp_failure;
14913 lpfc_cpuhp_state = error;
14915 error = pci_register_driver(&lpfc_driver);
14922 cpuhp_remove_multi_state(lpfc_cpuhp_state);
14924 fc_release_transport(lpfc_transport_template);
14925 fc_release_transport(lpfc_vport_transport_template);
14927 misc_deregister(&lpfc_mgmt_dev);
14932 void lpfc_dmp_dbg(struct lpfc_hba *phba)
14934 unsigned int start_idx;
14935 unsigned int dbg_cnt;
14936 unsigned int temp_idx;
14939 unsigned long rem_nsec, iflags;
14940 bool log_verbose = false;
14941 struct lpfc_vport *port_iterator;
14943 /* Don't dump messages if we explicitly set log_verbose for the
14944 * physical port or any vport.
14946 if (phba->cfg_log_verbose)
14949 spin_lock_irqsave(&phba->port_list_lock, iflags);
14950 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
14951 if (port_iterator->load_flag & FC_UNLOADING)
14953 if (scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
14954 if (port_iterator->cfg_log_verbose)
14955 log_verbose = true;
14957 scsi_host_put(lpfc_shost_from_vport(port_iterator));
14960 spin_unlock_irqrestore(&phba->port_list_lock,
14966 spin_unlock_irqrestore(&phba->port_list_lock, iflags);
14968 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
14971 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
14972 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
14975 temp_idx = start_idx;
14976 if (dbg_cnt >= DBG_LOG_SZ) {
14977 dbg_cnt = DBG_LOG_SZ;
14980 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
14981 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
14983 if (start_idx < dbg_cnt)
14984 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
14986 start_idx -= dbg_cnt;
14989 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
14990 start_idx, temp_idx, dbg_cnt);
14992 for (i = 0; i < dbg_cnt; i++) {
14993 if ((start_idx + i) < DBG_LOG_SZ)
14994 temp_idx = (start_idx + i) % DBG_LOG_SZ;
14997 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
14998 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15000 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15002 phba->dbg_log[temp_idx].log);
15005 atomic_set(&phba->dbg_log_cnt, 0);
15006 atomic_set(&phba->dbg_log_dmping, 0);
15010 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15014 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15015 struct va_format vaf;
15018 va_start(args, fmt);
15019 if (unlikely(dbg_dmping)) {
15022 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15026 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15029 atomic_inc(&phba->dbg_log_cnt);
15031 vscnprintf(phba->dbg_log[idx].log,
15032 sizeof(phba->dbg_log[idx].log), fmt, args);
15035 phba->dbg_log[idx].t_ns = local_clock();
15039 * lpfc_exit - lpfc module removal routine
15041 * This routine is invoked when the lpfc module is removed from the kernel.
15042 * The special kernel macro module_exit() is used to indicate the role of
15043 * this routine to the kernel as lpfc module exit point.
15048 misc_deregister(&lpfc_mgmt_dev);
15049 pci_unregister_driver(&lpfc_driver);
15050 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15051 fc_release_transport(lpfc_transport_template);
15052 fc_release_transport(lpfc_vport_transport_template);
15053 idr_destroy(&lpfc_hba_index);
15056 module_init(lpfc_init);
15057 module_exit(lpfc_exit);
15058 MODULE_LICENSE("GPL");
15059 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
15060 MODULE_AUTHOR("Broadcom");
15061 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);