1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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/bitops.h>
42 #include <scsi/scsi.h>
43 #include <scsi/scsi_device.h>
44 #include <scsi/scsi_host.h>
45 #include <scsi/scsi_transport_fc.h>
46 #include <scsi/scsi_tcq.h>
47 #include <scsi/fc/fc_fs.h>
49 #include <linux/nvme-fc-driver.h>
54 #include "lpfc_sli4.h"
56 #include "lpfc_disc.h"
58 #include "lpfc_scsi.h"
59 #include "lpfc_nvme.h"
60 #include "lpfc_nvmet.h"
61 #include "lpfc_logmsg.h"
62 #include "lpfc_crtn.h"
63 #include "lpfc_vport.h"
64 #include "lpfc_version.h"
68 unsigned long _dump_buf_data_order;
70 unsigned long _dump_buf_dif_order;
71 spinlock_t _dump_buf_lock;
73 /* Used when mapping IRQ vectors in a driver centric manner */
74 uint16_t *lpfc_used_cpu;
75 uint32_t lpfc_present_cpu;
77 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78 static int lpfc_post_rcv_buf(struct lpfc_hba *);
79 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
80 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81 static int lpfc_setup_endian_order(struct lpfc_hba *);
82 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
83 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
84 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
85 static void lpfc_init_sgl_list(struct lpfc_hba *);
86 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87 static void lpfc_free_active_sgl(struct lpfc_hba *);
88 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
93 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
95 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
97 static struct scsi_transport_template *lpfc_transport_template = NULL;
98 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
99 static DEFINE_IDR(lpfc_hba_index);
100 #define LPFC_NVMET_BUF_POST 254
103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
104 * @phba: pointer to lpfc hba data structure.
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
117 lpfc_config_port_prep(struct lpfc_hba *phba)
119 lpfc_vpd_t *vp = &phba->vpd;
123 char *lpfc_vpd_data = NULL;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
127 static int init_key = 1;
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
131 phba->link_state = LPFC_HBA_ERROR;
136 phba->link_state = LPFC_INIT_MBX_CMDS;
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
140 uint32_t *ptext = (uint32_t *) licensed;
142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
155 if (rc != MBX_SUCCESS) {
156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
157 "0324 Config Port initialization "
158 "error, mbxCmd x%x READ_NVPARM, "
160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
171 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
172 * which was already set in lpfc_get_cfgparam()
174 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
176 /* Setup and issue mailbox READ REV command */
177 lpfc_read_rev(phba, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
181 "0439 Adapter failed to init, mbxCmd x%x "
182 "READ_REV, mbxStatus x%x\n",
183 mb->mbxCommand, mb->mbxStatus);
184 mempool_free( pmb, phba->mbox_mem_pool);
190 * The value of rr must be 1 since the driver set the cv field to 1.
191 * This setting requires the FW to set all revision fields.
193 if (mb->un.varRdRev.rr == 0) {
195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
196 "0440 Adapter failed to init, READ_REV has "
197 "missing revision information.\n");
198 mempool_free(pmb, phba->mbox_mem_pool);
202 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
203 mempool_free(pmb, phba->mbox_mem_pool);
207 /* Save information as VPD data */
209 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
210 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
211 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
212 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
213 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
214 vp->rev.biuRev = mb->un.varRdRev.biuRev;
215 vp->rev.smRev = mb->un.varRdRev.smRev;
216 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
217 vp->rev.endecRev = mb->un.varRdRev.endecRev;
218 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
219 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
220 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
221 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
222 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
223 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
225 /* If the sli feature level is less then 9, we must
226 * tear down all RPIs and VPIs on link down if NPIV
229 if (vp->rev.feaLevelHigh < 9)
230 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
232 if (lpfc_is_LC_HBA(phba->pcidev->device))
233 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
234 sizeof (phba->RandomData));
236 /* Get adapter VPD information */
237 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
241 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
242 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
244 if (rc != MBX_SUCCESS) {
245 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
246 "0441 VPD not present on adapter, "
247 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
248 mb->mbxCommand, mb->mbxStatus);
249 mb->un.varDmp.word_cnt = 0;
251 /* dump mem may return a zero when finished or we got a
252 * mailbox error, either way we are done.
254 if (mb->un.varDmp.word_cnt == 0)
256 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
257 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
258 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
259 lpfc_vpd_data + offset,
260 mb->un.varDmp.word_cnt);
261 offset += mb->un.varDmp.word_cnt;
262 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
263 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
265 kfree(lpfc_vpd_data);
267 mempool_free(pmb, phba->mbox_mem_pool);
272 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
273 * @phba: pointer to lpfc hba data structure.
274 * @pmboxq: pointer to the driver internal queue element for mailbox command.
276 * This is the completion handler for driver's configuring asynchronous event
277 * mailbox command to the device. If the mailbox command returns successfully,
278 * it will set internal async event support flag to 1; otherwise, it will
279 * set internal async event support flag to 0.
282 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
284 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
285 phba->temp_sensor_support = 1;
287 phba->temp_sensor_support = 0;
288 mempool_free(pmboxq, phba->mbox_mem_pool);
293 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
294 * @phba: pointer to lpfc hba data structure.
295 * @pmboxq: pointer to the driver internal queue element for mailbox command.
297 * This is the completion handler for dump mailbox command for getting
298 * wake up parameters. When this command complete, the response contain
299 * Option rom version of the HBA. This function translate the version number
300 * into a human readable string and store it in OptionROMVersion.
303 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
306 uint32_t prog_id_word;
308 /* character array used for decoding dist type. */
309 char dist_char[] = "nabx";
311 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
312 mempool_free(pmboxq, phba->mbox_mem_pool);
316 prg = (struct prog_id *) &prog_id_word;
318 /* word 7 contain option rom version */
319 prog_id_word = pmboxq->u.mb.un.varWords[7];
321 /* Decode the Option rom version word to a readable string */
323 dist = dist_char[prg->dist];
325 if ((prg->dist == 3) && (prg->num == 0))
326 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
327 prg->ver, prg->rev, prg->lev);
329 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
330 prg->ver, prg->rev, prg->lev,
332 mempool_free(pmboxq, phba->mbox_mem_pool);
337 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
338 * cfg_soft_wwnn, cfg_soft_wwpn
339 * @vport: pointer to lpfc vport data structure.
346 lpfc_update_vport_wwn(struct lpfc_vport *vport)
348 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
349 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
351 /* If the soft name exists then update it using the service params */
352 if (vport->phba->cfg_soft_wwnn)
353 u64_to_wwn(vport->phba->cfg_soft_wwnn,
354 vport->fc_sparam.nodeName.u.wwn);
355 if (vport->phba->cfg_soft_wwpn)
356 u64_to_wwn(vport->phba->cfg_soft_wwpn,
357 vport->fc_sparam.portName.u.wwn);
360 * If the name is empty or there exists a soft name
361 * then copy the service params name, otherwise use the fc name
363 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
364 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
365 sizeof(struct lpfc_name));
367 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
368 sizeof(struct lpfc_name));
371 * If the port name has changed, then set the Param changes flag
374 if (vport->fc_portname.u.wwn[0] != 0 &&
375 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
376 sizeof(struct lpfc_name)))
377 vport->vport_flag |= FAWWPN_PARAM_CHG;
379 if (vport->fc_portname.u.wwn[0] == 0 ||
380 vport->phba->cfg_soft_wwpn ||
381 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
382 vport->vport_flag & FAWWPN_SET) {
383 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
384 sizeof(struct lpfc_name));
385 vport->vport_flag &= ~FAWWPN_SET;
386 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
387 vport->vport_flag |= FAWWPN_SET;
390 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
391 sizeof(struct lpfc_name));
395 * lpfc_config_port_post - Perform lpfc initialization after config port
396 * @phba: pointer to lpfc hba data structure.
398 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
399 * command call. It performs all internal resource and state setups on the
400 * port: post IOCB buffers, enable appropriate host interrupt attentions,
401 * ELS ring timers, etc.
405 * Any other value - error.
408 lpfc_config_port_post(struct lpfc_hba *phba)
410 struct lpfc_vport *vport = phba->pport;
411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
414 struct lpfc_dmabuf *mp;
415 struct lpfc_sli *psli = &phba->sli;
416 uint32_t status, timeout;
420 spin_lock_irq(&phba->hbalock);
422 * If the Config port completed correctly the HBA is not
423 * over heated any more.
425 if (phba->over_temp_state == HBA_OVER_TEMP)
426 phba->over_temp_state = HBA_NORMAL_TEMP;
427 spin_unlock_irq(&phba->hbalock);
429 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
431 phba->link_state = LPFC_HBA_ERROR;
436 /* Get login parameters for NID. */
437 rc = lpfc_read_sparam(phba, pmb, 0);
439 mempool_free(pmb, phba->mbox_mem_pool);
444 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
446 "0448 Adapter failed init, mbxCmd x%x "
447 "READ_SPARM mbxStatus x%x\n",
448 mb->mbxCommand, mb->mbxStatus);
449 phba->link_state = LPFC_HBA_ERROR;
450 mp = (struct lpfc_dmabuf *) pmb->context1;
451 mempool_free(pmb, phba->mbox_mem_pool);
452 lpfc_mbuf_free(phba, mp->virt, mp->phys);
457 mp = (struct lpfc_dmabuf *) pmb->context1;
459 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
460 lpfc_mbuf_free(phba, mp->virt, mp->phys);
462 pmb->context1 = NULL;
463 lpfc_update_vport_wwn(vport);
465 /* Update the fc_host data structures with new wwn. */
466 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
467 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
468 fc_host_max_npiv_vports(shost) = phba->max_vpi;
470 /* If no serial number in VPD data, use low 6 bytes of WWNN */
471 /* This should be consolidated into parse_vpd ? - mr */
472 if (phba->SerialNumber[0] == 0) {
475 outptr = &vport->fc_nodename.u.s.IEEE[0];
476 for (i = 0; i < 12; i++) {
478 j = ((status & 0xf0) >> 4);
480 phba->SerialNumber[i] =
481 (char)((uint8_t) 0x30 + (uint8_t) j);
483 phba->SerialNumber[i] =
484 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
488 phba->SerialNumber[i] =
489 (char)((uint8_t) 0x30 + (uint8_t) j);
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
496 lpfc_read_config(phba, pmb);
498 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
500 "0453 Adapter failed to init, mbxCmd x%x "
501 "READ_CONFIG, mbxStatus x%x\n",
502 mb->mbxCommand, mb->mbxStatus);
503 phba->link_state = LPFC_HBA_ERROR;
504 mempool_free( pmb, phba->mbox_mem_pool);
508 /* Check if the port is disabled */
509 lpfc_sli_read_link_ste(phba);
511 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
512 i = (mb->un.varRdConfig.max_xri + 1);
513 if (phba->cfg_hba_queue_depth > i) {
514 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
515 "3359 HBA queue depth changed from %d to %d\n",
516 phba->cfg_hba_queue_depth, i);
517 phba->cfg_hba_queue_depth = i;
520 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
521 i = (mb->un.varRdConfig.max_xri >> 3);
522 if (phba->pport->cfg_lun_queue_depth > i) {
523 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
524 "3360 LUN queue depth changed from %d to %d\n",
525 phba->pport->cfg_lun_queue_depth, i);
526 phba->pport->cfg_lun_queue_depth = i;
529 phba->lmt = mb->un.varRdConfig.lmt;
531 /* Get the default values for Model Name and Description */
532 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
534 phba->link_state = LPFC_LINK_DOWN;
536 /* Only process IOCBs on ELS ring till hba_state is READY */
537 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
538 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
539 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
540 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
542 /* Post receive buffers for desired rings */
543 if (phba->sli_rev != 3)
544 lpfc_post_rcv_buf(phba);
547 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
549 if (phba->intr_type == MSIX) {
550 rc = lpfc_config_msi(phba, pmb);
552 mempool_free(pmb, phba->mbox_mem_pool);
555 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
556 if (rc != MBX_SUCCESS) {
557 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
558 "0352 Config MSI mailbox command "
559 "failed, mbxCmd x%x, mbxStatus x%x\n",
560 pmb->u.mb.mbxCommand,
561 pmb->u.mb.mbxStatus);
562 mempool_free(pmb, phba->mbox_mem_pool);
567 spin_lock_irq(&phba->hbalock);
568 /* Initialize ERATT handling flag */
569 phba->hba_flag &= ~HBA_ERATT_HANDLED;
571 /* Enable appropriate host interrupts */
572 if (lpfc_readl(phba->HCregaddr, &status)) {
573 spin_unlock_irq(&phba->hbalock);
576 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
577 if (psli->num_rings > 0)
578 status |= HC_R0INT_ENA;
579 if (psli->num_rings > 1)
580 status |= HC_R1INT_ENA;
581 if (psli->num_rings > 2)
582 status |= HC_R2INT_ENA;
583 if (psli->num_rings > 3)
584 status |= HC_R3INT_ENA;
586 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
587 (phba->cfg_poll & DISABLE_FCP_RING_INT))
588 status &= ~(HC_R0INT_ENA);
590 writel(status, phba->HCregaddr);
591 readl(phba->HCregaddr); /* flush */
592 spin_unlock_irq(&phba->hbalock);
594 /* Set up ring-0 (ELS) timer */
595 timeout = phba->fc_ratov * 2;
596 mod_timer(&vport->els_tmofunc,
597 jiffies + msecs_to_jiffies(1000 * timeout));
598 /* Set up heart beat (HB) timer */
599 mod_timer(&phba->hb_tmofunc,
600 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
601 phba->hb_outstanding = 0;
602 phba->last_completion_time = jiffies;
603 /* Set up error attention (ERATT) polling timer */
604 mod_timer(&phba->eratt_poll,
605 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
607 if (phba->hba_flag & LINK_DISABLED) {
608 lpfc_printf_log(phba,
610 "2598 Adapter Link is disabled.\n");
611 lpfc_down_link(phba, pmb);
612 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
613 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
614 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
615 lpfc_printf_log(phba,
617 "2599 Adapter failed to issue DOWN_LINK"
618 " mbox command rc 0x%x\n", rc);
620 mempool_free(pmb, phba->mbox_mem_pool);
623 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
624 mempool_free(pmb, phba->mbox_mem_pool);
625 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
629 /* MBOX buffer will be freed in mbox compl */
630 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
632 phba->link_state = LPFC_HBA_ERROR;
636 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
637 pmb->mbox_cmpl = lpfc_config_async_cmpl;
638 pmb->vport = phba->pport;
639 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
641 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
642 lpfc_printf_log(phba,
645 "0456 Adapter failed to issue "
646 "ASYNCEVT_ENABLE mbox status x%x\n",
648 mempool_free(pmb, phba->mbox_mem_pool);
651 /* Get Option rom version */
652 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
654 phba->link_state = LPFC_HBA_ERROR;
658 lpfc_dump_wakeup_param(phba, pmb);
659 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
660 pmb->vport = phba->pport;
661 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
663 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
665 "to get Option ROM version status x%x\n", rc);
666 mempool_free(pmb, phba->mbox_mem_pool);
673 * lpfc_hba_init_link - Initialize the FC link
674 * @phba: pointer to lpfc hba data structure.
675 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
677 * This routine will issue the INIT_LINK mailbox command call.
678 * It is available to other drivers through the lpfc_hba data
679 * structure for use as a delayed link up mechanism with the
680 * module parameter lpfc_suppress_link_up.
684 * Any other value - error
687 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
689 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
693 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
694 * @phba: pointer to lpfc hba data structure.
695 * @fc_topology: desired fc topology.
696 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
698 * This routine will issue the INIT_LINK mailbox command call.
699 * It is available to other drivers through the lpfc_hba data
700 * structure for use as a delayed link up mechanism with the
701 * module parameter lpfc_suppress_link_up.
705 * Any other value - error
708 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
711 struct lpfc_vport *vport = phba->pport;
716 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
718 phba->link_state = LPFC_HBA_ERROR;
724 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
726 !(phba->lmt & LMT_1Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
728 !(phba->lmt & LMT_2Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
730 !(phba->lmt & LMT_4Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
732 !(phba->lmt & LMT_8Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
734 !(phba->lmt & LMT_10Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
736 !(phba->lmt & LMT_16Gb)) ||
737 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
738 !(phba->lmt & LMT_32Gb)) ||
739 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
740 !(phba->lmt & LMT_64Gb))) {
741 /* Reset link speed to auto */
742 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
743 "1302 Invalid speed for this board:%d "
744 "Reset link speed to auto.\n",
745 phba->cfg_link_speed);
746 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
748 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
749 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
750 if (phba->sli_rev < LPFC_SLI_REV4)
751 lpfc_set_loopback_flag(phba);
752 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
753 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
755 "0498 Adapter failed to init, mbxCmd x%x "
756 "INIT_LINK, mbxStatus x%x\n",
757 mb->mbxCommand, mb->mbxStatus);
758 if (phba->sli_rev <= LPFC_SLI_REV3) {
759 /* Clear all interrupt enable conditions */
760 writel(0, phba->HCregaddr);
761 readl(phba->HCregaddr); /* flush */
762 /* Clear all pending interrupts */
763 writel(0xffffffff, phba->HAregaddr);
764 readl(phba->HAregaddr); /* flush */
766 phba->link_state = LPFC_HBA_ERROR;
767 if (rc != MBX_BUSY || flag == MBX_POLL)
768 mempool_free(pmb, phba->mbox_mem_pool);
771 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
772 if (flag == MBX_POLL)
773 mempool_free(pmb, phba->mbox_mem_pool);
779 * lpfc_hba_down_link - this routine downs the FC link
780 * @phba: pointer to lpfc hba data structure.
781 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
783 * This routine will issue the DOWN_LINK mailbox command call.
784 * It is available to other drivers through the lpfc_hba data
785 * structure for use to stop the link.
789 * Any other value - error
792 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
797 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
799 phba->link_state = LPFC_HBA_ERROR;
803 lpfc_printf_log(phba,
805 "0491 Adapter Link is disabled.\n");
806 lpfc_down_link(phba, pmb);
807 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
808 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
809 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
810 lpfc_printf_log(phba,
812 "2522 Adapter failed to issue DOWN_LINK"
813 " mbox command rc 0x%x\n", rc);
815 mempool_free(pmb, phba->mbox_mem_pool);
818 if (flag == MBX_POLL)
819 mempool_free(pmb, phba->mbox_mem_pool);
825 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
826 * @phba: pointer to lpfc HBA data structure.
828 * This routine will do LPFC uninitialization before the HBA is reset when
829 * bringing down the SLI Layer.
833 * Any other value - error.
836 lpfc_hba_down_prep(struct lpfc_hba *phba)
838 struct lpfc_vport **vports;
841 if (phba->sli_rev <= LPFC_SLI_REV3) {
842 /* Disable interrupts */
843 writel(0, phba->HCregaddr);
844 readl(phba->HCregaddr); /* flush */
847 if (phba->pport->load_flag & FC_UNLOADING)
848 lpfc_cleanup_discovery_resources(phba->pport);
850 vports = lpfc_create_vport_work_array(phba);
852 for (i = 0; i <= phba->max_vports &&
853 vports[i] != NULL; i++)
854 lpfc_cleanup_discovery_resources(vports[i]);
855 lpfc_destroy_vport_work_array(phba, vports);
861 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
862 * rspiocb which got deferred
864 * @phba: pointer to lpfc HBA data structure.
866 * This routine will cleanup completed slow path events after HBA is reset
867 * when bringing down the SLI Layer.
874 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
876 struct lpfc_iocbq *rspiocbq;
877 struct hbq_dmabuf *dmabuf;
878 struct lpfc_cq_event *cq_event;
880 spin_lock_irq(&phba->hbalock);
881 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
882 spin_unlock_irq(&phba->hbalock);
884 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
885 /* Get the response iocb from the head of work queue */
886 spin_lock_irq(&phba->hbalock);
887 list_remove_head(&phba->sli4_hba.sp_queue_event,
888 cq_event, struct lpfc_cq_event, list);
889 spin_unlock_irq(&phba->hbalock);
891 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
892 case CQE_CODE_COMPL_WQE:
893 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
895 lpfc_sli_release_iocbq(phba, rspiocbq);
897 case CQE_CODE_RECEIVE:
898 case CQE_CODE_RECEIVE_V1:
899 dmabuf = container_of(cq_event, struct hbq_dmabuf,
901 lpfc_in_buf_free(phba, &dmabuf->dbuf);
907 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
908 * @phba: pointer to lpfc HBA data structure.
910 * This routine will cleanup posted ELS buffers after the HBA is reset
911 * when bringing down the SLI Layer.
918 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
920 struct lpfc_sli *psli = &phba->sli;
921 struct lpfc_sli_ring *pring;
922 struct lpfc_dmabuf *mp, *next_mp;
926 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
927 lpfc_sli_hbqbuf_free_all(phba);
929 /* Cleanup preposted buffers on the ELS ring */
930 pring = &psli->sli3_ring[LPFC_ELS_RING];
931 spin_lock_irq(&phba->hbalock);
932 list_splice_init(&pring->postbufq, &buflist);
933 spin_unlock_irq(&phba->hbalock);
936 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
939 lpfc_mbuf_free(phba, mp->virt, mp->phys);
943 spin_lock_irq(&phba->hbalock);
944 pring->postbufq_cnt -= count;
945 spin_unlock_irq(&phba->hbalock);
950 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
951 * @phba: pointer to lpfc HBA data structure.
953 * This routine will cleanup the txcmplq after the HBA is reset when bringing
954 * down the SLI Layer.
960 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
962 struct lpfc_sli *psli = &phba->sli;
963 struct lpfc_queue *qp = NULL;
964 struct lpfc_sli_ring *pring;
965 LIST_HEAD(completions);
967 struct lpfc_iocbq *piocb, *next_iocb;
969 if (phba->sli_rev != LPFC_SLI_REV4) {
970 for (i = 0; i < psli->num_rings; i++) {
971 pring = &psli->sli3_ring[i];
972 spin_lock_irq(&phba->hbalock);
973 /* At this point in time the HBA is either reset or DOA
974 * Nothing should be on txcmplq as it will
977 list_splice_init(&pring->txcmplq, &completions);
978 pring->txcmplq_cnt = 0;
979 spin_unlock_irq(&phba->hbalock);
981 lpfc_sli_abort_iocb_ring(phba, pring);
983 /* Cancel all the IOCBs from the completions list */
984 lpfc_sli_cancel_iocbs(phba, &completions,
985 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
988 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
992 spin_lock_irq(&pring->ring_lock);
993 list_for_each_entry_safe(piocb, next_iocb,
994 &pring->txcmplq, list)
995 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
996 list_splice_init(&pring->txcmplq, &completions);
997 pring->txcmplq_cnt = 0;
998 spin_unlock_irq(&pring->ring_lock);
999 lpfc_sli_abort_iocb_ring(phba, pring);
1001 /* Cancel all the IOCBs from the completions list */
1002 lpfc_sli_cancel_iocbs(phba, &completions,
1003 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1007 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1009 * @phba: pointer to lpfc HBA data structure.
1011 * This routine will do uninitialization after the HBA is reset when bring
1012 * down the SLI Layer.
1016 * Any other value - error.
1019 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1021 lpfc_hba_free_post_buf(phba);
1022 lpfc_hba_clean_txcmplq(phba);
1027 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1028 * @phba: pointer to lpfc HBA data structure.
1030 * This routine will do uninitialization after the HBA is reset when bring
1031 * down the SLI Layer.
1035 * Any other value - error.
1038 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1040 struct lpfc_scsi_buf *psb, *psb_next;
1041 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
1043 LIST_HEAD(nvme_aborts);
1044 LIST_HEAD(nvmet_aborts);
1045 unsigned long iflag = 0;
1046 struct lpfc_sglq *sglq_entry = NULL;
1050 lpfc_sli_hbqbuf_free_all(phba);
1051 lpfc_hba_clean_txcmplq(phba);
1053 /* At this point in time the HBA is either reset or DOA. Either
1054 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1055 * on the lpfc_els_sgl_list so that it can either be freed if the
1056 * driver is unloading or reposted if the driver is restarting
1059 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
1061 /* sgl_list_lock required because worker thread uses this
1064 spin_lock(&phba->sli4_hba.sgl_list_lock);
1065 list_for_each_entry(sglq_entry,
1066 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1067 sglq_entry->state = SGL_FREED;
1069 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1070 &phba->sli4_hba.lpfc_els_sgl_list);
1073 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1074 /* abts_scsi_buf_list_lock required because worker thread uses this
1077 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1078 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1079 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1081 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1084 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1085 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1086 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1088 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1090 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1093 spin_unlock_irq(&phba->hbalock);
1095 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1097 psb->status = IOSTAT_SUCCESS;
1099 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1100 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1101 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1103 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1105 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1107 psb->status = IOSTAT_SUCCESS;
1110 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1111 phba->put_nvme_bufs += cnt;
1112 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1113 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1115 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1116 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
1117 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1121 lpfc_sli4_free_sp_events(phba);
1126 * lpfc_hba_down_post - Wrapper func for hba down post routine
1127 * @phba: pointer to lpfc HBA data structure.
1129 * This routine wraps the actual SLI3 or SLI4 routine for performing
1130 * uninitialization after the HBA is reset when bring down the SLI Layer.
1134 * Any other value - error.
1137 lpfc_hba_down_post(struct lpfc_hba *phba)
1139 return (*phba->lpfc_hba_down_post)(phba);
1143 * lpfc_hb_timeout - The HBA-timer timeout handler
1144 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1146 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1147 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1148 * work-port-events bitmap and the worker thread is notified. This timeout
1149 * event will be used by the worker thread to invoke the actual timeout
1150 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1151 * be performed in the timeout handler and the HBA timeout event bit shall
1152 * be cleared by the worker thread after it has taken the event bitmap out.
1155 lpfc_hb_timeout(struct timer_list *t)
1157 struct lpfc_hba *phba;
1158 uint32_t tmo_posted;
1159 unsigned long iflag;
1161 phba = from_timer(phba, t, hb_tmofunc);
1163 /* Check for heart beat timeout conditions */
1164 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1165 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1167 phba->pport->work_port_events |= WORKER_HB_TMO;
1168 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1170 /* Tell the worker thread there is work to do */
1172 lpfc_worker_wake_up(phba);
1177 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1178 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1180 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1181 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1182 * work-port-events bitmap and the worker thread is notified. This timeout
1183 * event will be used by the worker thread to invoke the actual timeout
1184 * handler routine, lpfc_rrq_handler. Any periodical operations will
1185 * be performed in the timeout handler and the RRQ timeout event bit shall
1186 * be cleared by the worker thread after it has taken the event bitmap out.
1189 lpfc_rrq_timeout(struct timer_list *t)
1191 struct lpfc_hba *phba;
1192 unsigned long iflag;
1194 phba = from_timer(phba, t, rrq_tmr);
1195 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1196 if (!(phba->pport->load_flag & FC_UNLOADING))
1197 phba->hba_flag |= HBA_RRQ_ACTIVE;
1199 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1200 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1202 if (!(phba->pport->load_flag & FC_UNLOADING))
1203 lpfc_worker_wake_up(phba);
1207 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1208 * @phba: pointer to lpfc hba data structure.
1209 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1211 * This is the callback function to the lpfc heart-beat mailbox command.
1212 * If configured, the lpfc driver issues the heart-beat mailbox command to
1213 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1214 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1215 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1216 * heart-beat outstanding state. Once the mailbox command comes back and
1217 * no error conditions detected, the heart-beat mailbox command timer is
1218 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1219 * state is cleared for the next heart-beat. If the timer expired with the
1220 * heart-beat outstanding state set, the driver will put the HBA offline.
1223 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1225 unsigned long drvr_flag;
1227 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1228 phba->hb_outstanding = 0;
1229 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1231 /* Check and reset heart-beat timer is necessary */
1232 mempool_free(pmboxq, phba->mbox_mem_pool);
1233 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1234 !(phba->link_state == LPFC_HBA_ERROR) &&
1235 !(phba->pport->load_flag & FC_UNLOADING))
1236 mod_timer(&phba->hb_tmofunc,
1238 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1243 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1244 * @phba: pointer to lpfc hba data structure.
1246 * This is the actual HBA-timer timeout handler to be invoked by the worker
1247 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1248 * handler performs any periodic operations needed for the device. If such
1249 * periodic event has already been attended to either in the interrupt handler
1250 * or by processing slow-ring or fast-ring events within the HBA-timer
1251 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1252 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1253 * is configured and there is no heart-beat mailbox command outstanding, a
1254 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1255 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1259 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1261 struct lpfc_vport **vports;
1262 LPFC_MBOXQ_t *pmboxq;
1263 struct lpfc_dmabuf *buf_ptr;
1265 struct lpfc_sli *psli = &phba->sli;
1266 LIST_HEAD(completions);
1267 struct lpfc_queue *qp;
1268 unsigned long time_elapsed;
1269 uint32_t tick_cqe, max_cqe, val;
1270 uint64_t tot, data1, data2, data3;
1271 struct lpfc_nvmet_tgtport *tgtp;
1272 struct lpfc_register reg_data;
1273 struct nvme_fc_local_port *localport;
1274 struct lpfc_nvme_lport *lport;
1275 struct lpfc_nvme_ctrl_stat *cstat;
1276 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
1278 vports = lpfc_create_vport_work_array(phba);
1280 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1281 lpfc_rcv_seq_check_edtov(vports[i]);
1282 lpfc_fdmi_num_disc_check(vports[i]);
1284 lpfc_destroy_vport_work_array(phba, vports);
1286 if ((phba->link_state == LPFC_HBA_ERROR) ||
1287 (phba->pport->load_flag & FC_UNLOADING) ||
1288 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1291 if (phba->cfg_auto_imax) {
1292 if (!phba->last_eqdelay_time) {
1293 phba->last_eqdelay_time = jiffies;
1296 time_elapsed = jiffies - phba->last_eqdelay_time;
1297 phba->last_eqdelay_time = jiffies;
1300 /* Check outstanding IO count */
1301 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1302 if (phba->nvmet_support) {
1303 tgtp = phba->targetport->private;
1304 /* Calculate outstanding IOs */
1305 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1306 tot += atomic_read(&tgtp->xmt_fcp_release);
1307 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
1309 localport = phba->pport->localport;
1310 if (!localport || !localport->private)
1312 lport = (struct lpfc_nvme_lport *)
1316 i < phba->cfg_nvme_io_channel; i++) {
1317 cstat = &lport->cstat[i];
1318 data1 = atomic_read(
1319 &cstat->fc4NvmeInputRequests);
1320 data2 = atomic_read(
1321 &cstat->fc4NvmeOutputRequests);
1322 data3 = atomic_read(
1323 &cstat->fc4NvmeControlRequests);
1324 tot += (data1 + data2 + data3);
1326 &cstat->fc4NvmeIoCmpls);
1331 /* Interrupts per sec per EQ */
1332 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1333 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1335 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1336 max_cqe = time_elapsed * tick_cqe;
1338 for (i = 0; i < phba->io_channel_irqs; i++) {
1340 qp = phba->sli4_hba.hba_eq[i];
1344 /* Use no EQ delay if we don't have many outstanding
1345 * IOs, or if we are only processing 1 CQE/ISR or less.
1346 * Otherwise, assume we can process up to lpfc_fcp_imax
1347 * interrupts per HBA.
1349 if (tot < LPFC_NODELAY_MAX_IO ||
1350 qp->EQ_cqe_cnt <= max_cqe)
1353 val = phba->cfg_fcp_imax;
1355 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1356 /* Use EQ Delay Register method */
1358 /* Convert for EQ Delay register */
1360 /* First, interrupts per sec per EQ */
1361 val = phba->cfg_fcp_imax /
1362 phba->io_channel_irqs;
1364 /* us delay between each interrupt */
1365 val = LPFC_SEC_TO_USEC / val;
1367 if (val != qp->q_mode) {
1369 bf_set(lpfc_sliport_eqdelay_id,
1370 ®_data, qp->queue_id);
1371 bf_set(lpfc_sliport_eqdelay_delay,
1373 writel(reg_data.word0, eqdreg);
1376 /* Use mbox command method */
1377 if (val != qp->q_mode)
1378 lpfc_modify_hba_eq_delay(phba, i,
1383 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1384 * between interrupts for EQDR.
1392 spin_lock_irq(&phba->pport->work_port_lock);
1394 if (time_after(phba->last_completion_time +
1395 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1397 spin_unlock_irq(&phba->pport->work_port_lock);
1398 if (!phba->hb_outstanding)
1399 mod_timer(&phba->hb_tmofunc,
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1403 mod_timer(&phba->hb_tmofunc,
1405 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1408 spin_unlock_irq(&phba->pport->work_port_lock);
1410 if (phba->elsbuf_cnt &&
1411 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1412 spin_lock_irq(&phba->hbalock);
1413 list_splice_init(&phba->elsbuf, &completions);
1414 phba->elsbuf_cnt = 0;
1415 phba->elsbuf_prev_cnt = 0;
1416 spin_unlock_irq(&phba->hbalock);
1418 while (!list_empty(&completions)) {
1419 list_remove_head(&completions, buf_ptr,
1420 struct lpfc_dmabuf, list);
1421 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1425 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1427 /* If there is no heart beat outstanding, issue a heartbeat command */
1428 if (phba->cfg_enable_hba_heartbeat) {
1429 if (!phba->hb_outstanding) {
1430 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1431 (list_empty(&psli->mboxq))) {
1432 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1435 mod_timer(&phba->hb_tmofunc,
1437 msecs_to_jiffies(1000 *
1438 LPFC_HB_MBOX_INTERVAL));
1442 lpfc_heart_beat(phba, pmboxq);
1443 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1444 pmboxq->vport = phba->pport;
1445 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1448 if (retval != MBX_BUSY &&
1449 retval != MBX_SUCCESS) {
1450 mempool_free(pmboxq,
1451 phba->mbox_mem_pool);
1452 mod_timer(&phba->hb_tmofunc,
1454 msecs_to_jiffies(1000 *
1455 LPFC_HB_MBOX_INTERVAL));
1458 phba->skipped_hb = 0;
1459 phba->hb_outstanding = 1;
1460 } else if (time_before_eq(phba->last_completion_time,
1461 phba->skipped_hb)) {
1462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1463 "2857 Last completion time not "
1464 " updated in %d ms\n",
1465 jiffies_to_msecs(jiffies
1466 - phba->last_completion_time));
1468 phba->skipped_hb = jiffies;
1470 mod_timer(&phba->hb_tmofunc,
1472 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1476 * If heart beat timeout called with hb_outstanding set
1477 * we need to give the hb mailbox cmd a chance to
1480 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1481 "0459 Adapter heartbeat still out"
1482 "standing:last compl time was %d ms.\n",
1483 jiffies_to_msecs(jiffies
1484 - phba->last_completion_time));
1485 mod_timer(&phba->hb_tmofunc,
1487 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1490 mod_timer(&phba->hb_tmofunc,
1492 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1497 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1498 * @phba: pointer to lpfc hba data structure.
1500 * This routine is called to bring the HBA offline when HBA hardware error
1501 * other than Port Error 6 has been detected.
1504 lpfc_offline_eratt(struct lpfc_hba *phba)
1506 struct lpfc_sli *psli = &phba->sli;
1508 spin_lock_irq(&phba->hbalock);
1509 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1510 spin_unlock_irq(&phba->hbalock);
1511 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1514 lpfc_reset_barrier(phba);
1515 spin_lock_irq(&phba->hbalock);
1516 lpfc_sli_brdreset(phba);
1517 spin_unlock_irq(&phba->hbalock);
1518 lpfc_hba_down_post(phba);
1519 lpfc_sli_brdready(phba, HS_MBRDY);
1520 lpfc_unblock_mgmt_io(phba);
1521 phba->link_state = LPFC_HBA_ERROR;
1526 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1527 * @phba: pointer to lpfc hba data structure.
1529 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1530 * other than Port Error 6 has been detected.
1533 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1535 spin_lock_irq(&phba->hbalock);
1536 phba->link_state = LPFC_HBA_ERROR;
1537 spin_unlock_irq(&phba->hbalock);
1539 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1541 lpfc_hba_down_post(phba);
1542 lpfc_unblock_mgmt_io(phba);
1546 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1547 * @phba: pointer to lpfc hba data structure.
1549 * This routine is invoked to handle the deferred HBA hardware error
1550 * conditions. This type of error is indicated by HBA by setting ER1
1551 * and another ER bit in the host status register. The driver will
1552 * wait until the ER1 bit clears before handling the error condition.
1555 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1557 uint32_t old_host_status = phba->work_hs;
1558 struct lpfc_sli *psli = &phba->sli;
1560 /* If the pci channel is offline, ignore possible errors,
1561 * since we cannot communicate with the pci card anyway.
1563 if (pci_channel_offline(phba->pcidev)) {
1564 spin_lock_irq(&phba->hbalock);
1565 phba->hba_flag &= ~DEFER_ERATT;
1566 spin_unlock_irq(&phba->hbalock);
1570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1571 "0479 Deferred Adapter Hardware Error "
1572 "Data: x%x x%x x%x\n",
1574 phba->work_status[0], phba->work_status[1]);
1576 spin_lock_irq(&phba->hbalock);
1577 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1578 spin_unlock_irq(&phba->hbalock);
1582 * Firmware stops when it triggred erratt. That could cause the I/Os
1583 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1584 * SCSI layer retry it after re-establishing link.
1586 lpfc_sli_abort_fcp_rings(phba);
1589 * There was a firmware error. Take the hba offline and then
1590 * attempt to restart it.
1592 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1595 /* Wait for the ER1 bit to clear.*/
1596 while (phba->work_hs & HS_FFER1) {
1598 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1599 phba->work_hs = UNPLUG_ERR ;
1602 /* If driver is unloading let the worker thread continue */
1603 if (phba->pport->load_flag & FC_UNLOADING) {
1610 * This is to ptrotect against a race condition in which
1611 * first write to the host attention register clear the
1612 * host status register.
1614 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1615 phba->work_hs = old_host_status & ~HS_FFER1;
1617 spin_lock_irq(&phba->hbalock);
1618 phba->hba_flag &= ~DEFER_ERATT;
1619 spin_unlock_irq(&phba->hbalock);
1620 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1621 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1625 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1627 struct lpfc_board_event_header board_event;
1628 struct Scsi_Host *shost;
1630 board_event.event_type = FC_REG_BOARD_EVENT;
1631 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1632 shost = lpfc_shost_from_vport(phba->pport);
1633 fc_host_post_vendor_event(shost, fc_get_event_number(),
1634 sizeof(board_event),
1635 (char *) &board_event,
1640 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1641 * @phba: pointer to lpfc hba data structure.
1643 * This routine is invoked to handle the following HBA hardware error
1645 * 1 - HBA error attention interrupt
1646 * 2 - DMA ring index out of range
1647 * 3 - Mailbox command came back as unknown
1650 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1652 struct lpfc_vport *vport = phba->pport;
1653 struct lpfc_sli *psli = &phba->sli;
1654 uint32_t event_data;
1655 unsigned long temperature;
1656 struct temp_event temp_event_data;
1657 struct Scsi_Host *shost;
1659 /* If the pci channel is offline, ignore possible errors,
1660 * since we cannot communicate with the pci card anyway.
1662 if (pci_channel_offline(phba->pcidev)) {
1663 spin_lock_irq(&phba->hbalock);
1664 phba->hba_flag &= ~DEFER_ERATT;
1665 spin_unlock_irq(&phba->hbalock);
1669 /* If resets are disabled then leave the HBA alone and return */
1670 if (!phba->cfg_enable_hba_reset)
1673 /* Send an internal error event to mgmt application */
1674 lpfc_board_errevt_to_mgmt(phba);
1676 if (phba->hba_flag & DEFER_ERATT)
1677 lpfc_handle_deferred_eratt(phba);
1679 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1680 if (phba->work_hs & HS_FFER6)
1681 /* Re-establishing Link */
1682 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1683 "1301 Re-establishing Link "
1684 "Data: x%x x%x x%x\n",
1685 phba->work_hs, phba->work_status[0],
1686 phba->work_status[1]);
1687 if (phba->work_hs & HS_FFER8)
1688 /* Device Zeroization */
1689 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1690 "2861 Host Authentication device "
1691 "zeroization Data:x%x x%x x%x\n",
1692 phba->work_hs, phba->work_status[0],
1693 phba->work_status[1]);
1695 spin_lock_irq(&phba->hbalock);
1696 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1697 spin_unlock_irq(&phba->hbalock);
1700 * Firmware stops when it triggled erratt with HS_FFER6.
1701 * That could cause the I/Os dropped by the firmware.
1702 * Error iocb (I/O) on txcmplq and let the SCSI layer
1703 * retry it after re-establishing link.
1705 lpfc_sli_abort_fcp_rings(phba);
1708 * There was a firmware error. Take the hba offline and then
1709 * attempt to restart it.
1711 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1713 lpfc_sli_brdrestart(phba);
1714 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1715 lpfc_unblock_mgmt_io(phba);
1718 lpfc_unblock_mgmt_io(phba);
1719 } else if (phba->work_hs & HS_CRIT_TEMP) {
1720 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1721 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1722 temp_event_data.event_code = LPFC_CRIT_TEMP;
1723 temp_event_data.data = (uint32_t)temperature;
1725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1726 "0406 Adapter maximum temperature exceeded "
1727 "(%ld), taking this port offline "
1728 "Data: x%x x%x x%x\n",
1729 temperature, phba->work_hs,
1730 phba->work_status[0], phba->work_status[1]);
1732 shost = lpfc_shost_from_vport(phba->pport);
1733 fc_host_post_vendor_event(shost, fc_get_event_number(),
1734 sizeof(temp_event_data),
1735 (char *) &temp_event_data,
1736 SCSI_NL_VID_TYPE_PCI
1737 | PCI_VENDOR_ID_EMULEX);
1739 spin_lock_irq(&phba->hbalock);
1740 phba->over_temp_state = HBA_OVER_TEMP;
1741 spin_unlock_irq(&phba->hbalock);
1742 lpfc_offline_eratt(phba);
1745 /* The if clause above forces this code path when the status
1746 * failure is a value other than FFER6. Do not call the offline
1747 * twice. This is the adapter hardware error path.
1749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1750 "0457 Adapter Hardware Error "
1751 "Data: x%x x%x x%x\n",
1753 phba->work_status[0], phba->work_status[1]);
1755 event_data = FC_REG_DUMP_EVENT;
1756 shost = lpfc_shost_from_vport(vport);
1757 fc_host_post_vendor_event(shost, fc_get_event_number(),
1758 sizeof(event_data), (char *) &event_data,
1759 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1761 lpfc_offline_eratt(phba);
1767 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1768 * @phba: pointer to lpfc hba data structure.
1769 * @mbx_action: flag for mailbox shutdown action.
1771 * This routine is invoked to perform an SLI4 port PCI function reset in
1772 * response to port status register polling attention. It waits for port
1773 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1774 * During this process, interrupt vectors are freed and later requested
1775 * for handling possible port resource change.
1778 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1784 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1785 LPFC_SLI_INTF_IF_TYPE_2) {
1787 * On error status condition, driver need to wait for port
1788 * ready before performing reset.
1790 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1795 /* need reset: attempt for port recovery */
1797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1798 "2887 Reset Needed: Attempting Port "
1800 lpfc_offline_prep(phba, mbx_action);
1802 /* release interrupt for possible resource change */
1803 lpfc_sli4_disable_intr(phba);
1804 rc = lpfc_sli_brdrestart(phba);
1806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1807 "6309 Failed to restart board\n");
1810 /* request and enable interrupt */
1811 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1812 if (intr_mode == LPFC_INTR_ERROR) {
1813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1814 "3175 Failed to enable interrupt\n");
1817 phba->intr_mode = intr_mode;
1818 rc = lpfc_online(phba);
1820 lpfc_unblock_mgmt_io(phba);
1826 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1827 * @phba: pointer to lpfc hba data structure.
1829 * This routine is invoked to handle the SLI4 HBA hardware error attention
1833 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1835 struct lpfc_vport *vport = phba->pport;
1836 uint32_t event_data;
1837 struct Scsi_Host *shost;
1839 struct lpfc_register portstat_reg = {0};
1840 uint32_t reg_err1, reg_err2;
1841 uint32_t uerrlo_reg, uemasklo_reg;
1842 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1843 bool en_rn_msg = true;
1844 struct temp_event temp_event_data;
1845 struct lpfc_register portsmphr_reg;
1848 /* If the pci channel is offline, ignore possible errors, since
1849 * we cannot communicate with the pci card anyway.
1851 if (pci_channel_offline(phba->pcidev))
1854 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1855 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1857 case LPFC_SLI_INTF_IF_TYPE_0:
1858 pci_rd_rc1 = lpfc_readl(
1859 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1861 pci_rd_rc2 = lpfc_readl(
1862 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1864 /* consider PCI bus read error as pci_channel_offline */
1865 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1867 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1868 lpfc_sli4_offline_eratt(phba);
1871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1872 "7623 Checking UE recoverable");
1874 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1875 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1876 &portsmphr_reg.word0))
1879 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1881 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1882 LPFC_PORT_SEM_UE_RECOVERABLE)
1884 /*Sleep for 1Sec, before checking SEMAPHORE */
1888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1889 "4827 smphr_port_status x%x : Waited %dSec",
1890 smphr_port_status, i);
1892 /* Recoverable UE, reset the HBA device */
1893 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1894 LPFC_PORT_SEM_UE_RECOVERABLE) {
1895 for (i = 0; i < 20; i++) {
1897 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1898 &portsmphr_reg.word0) &&
1899 (LPFC_POST_STAGE_PORT_READY ==
1900 bf_get(lpfc_port_smphr_port_status,
1902 rc = lpfc_sli4_port_sta_fn_reset(phba,
1903 LPFC_MBX_NO_WAIT, en_rn_msg);
1906 lpfc_printf_log(phba,
1908 "4215 Failed to recover UE");
1913 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1914 "7624 Firmware not ready: Failing UE recovery,"
1915 " waited %dSec", i);
1916 lpfc_sli4_offline_eratt(phba);
1919 case LPFC_SLI_INTF_IF_TYPE_2:
1920 case LPFC_SLI_INTF_IF_TYPE_6:
1921 pci_rd_rc1 = lpfc_readl(
1922 phba->sli4_hba.u.if_type2.STATUSregaddr,
1923 &portstat_reg.word0);
1924 /* consider PCI bus read error as pci_channel_offline */
1925 if (pci_rd_rc1 == -EIO) {
1926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1927 "3151 PCI bus read access failure: x%x\n",
1928 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1931 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1932 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1933 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1935 "2889 Port Overtemperature event, "
1936 "taking port offline Data: x%x x%x\n",
1937 reg_err1, reg_err2);
1939 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
1940 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1941 temp_event_data.event_code = LPFC_CRIT_TEMP;
1942 temp_event_data.data = 0xFFFFFFFF;
1944 shost = lpfc_shost_from_vport(phba->pport);
1945 fc_host_post_vendor_event(shost, fc_get_event_number(),
1946 sizeof(temp_event_data),
1947 (char *)&temp_event_data,
1948 SCSI_NL_VID_TYPE_PCI
1949 | PCI_VENDOR_ID_EMULEX);
1951 spin_lock_irq(&phba->hbalock);
1952 phba->over_temp_state = HBA_OVER_TEMP;
1953 spin_unlock_irq(&phba->hbalock);
1954 lpfc_sli4_offline_eratt(phba);
1957 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1958 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1960 "3143 Port Down: Firmware Update "
1963 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1964 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1966 "3144 Port Down: Debug Dump\n");
1967 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1968 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1969 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1970 "3145 Port Down: Provisioning\n");
1972 /* If resets are disabled then leave the HBA alone and return */
1973 if (!phba->cfg_enable_hba_reset)
1976 /* Check port status register for function reset */
1977 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1980 /* don't report event on forced debug dump */
1981 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1982 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1987 /* fall through for not able to recover */
1988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1989 "3152 Unrecoverable error, bring the port "
1991 lpfc_sli4_offline_eratt(phba);
1993 case LPFC_SLI_INTF_IF_TYPE_1:
1997 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1998 "3123 Report dump event to upper layer\n");
1999 /* Send an internal error event to mgmt application */
2000 lpfc_board_errevt_to_mgmt(phba);
2002 event_data = FC_REG_DUMP_EVENT;
2003 shost = lpfc_shost_from_vport(vport);
2004 fc_host_post_vendor_event(shost, fc_get_event_number(),
2005 sizeof(event_data), (char *) &event_data,
2006 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2010 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2011 * @phba: pointer to lpfc HBA data structure.
2013 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2014 * routine from the API jump table function pointer from the lpfc_hba struct.
2018 * Any other value - error.
2021 lpfc_handle_eratt(struct lpfc_hba *phba)
2023 (*phba->lpfc_handle_eratt)(phba);
2027 * lpfc_handle_latt - The HBA link event handler
2028 * @phba: pointer to lpfc hba data structure.
2030 * This routine is invoked from the worker thread to handle a HBA host
2031 * attention link event. SLI3 only.
2034 lpfc_handle_latt(struct lpfc_hba *phba)
2036 struct lpfc_vport *vport = phba->pport;
2037 struct lpfc_sli *psli = &phba->sli;
2039 volatile uint32_t control;
2040 struct lpfc_dmabuf *mp;
2043 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2046 goto lpfc_handle_latt_err_exit;
2049 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2052 goto lpfc_handle_latt_free_pmb;
2055 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2058 goto lpfc_handle_latt_free_mp;
2061 /* Cleanup any outstanding ELS commands */
2062 lpfc_els_flush_all_cmd(phba);
2064 psli->slistat.link_event++;
2065 lpfc_read_topology(phba, pmb, mp);
2066 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2068 /* Block ELS IOCBs until we have processed this mbox command */
2069 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2070 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2071 if (rc == MBX_NOT_FINISHED) {
2073 goto lpfc_handle_latt_free_mbuf;
2076 /* Clear Link Attention in HA REG */
2077 spin_lock_irq(&phba->hbalock);
2078 writel(HA_LATT, phba->HAregaddr);
2079 readl(phba->HAregaddr); /* flush */
2080 spin_unlock_irq(&phba->hbalock);
2084 lpfc_handle_latt_free_mbuf:
2085 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2086 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2087 lpfc_handle_latt_free_mp:
2089 lpfc_handle_latt_free_pmb:
2090 mempool_free(pmb, phba->mbox_mem_pool);
2091 lpfc_handle_latt_err_exit:
2092 /* Enable Link attention interrupts */
2093 spin_lock_irq(&phba->hbalock);
2094 psli->sli_flag |= LPFC_PROCESS_LA;
2095 control = readl(phba->HCregaddr);
2096 control |= HC_LAINT_ENA;
2097 writel(control, phba->HCregaddr);
2098 readl(phba->HCregaddr); /* flush */
2100 /* Clear Link Attention in HA REG */
2101 writel(HA_LATT, phba->HAregaddr);
2102 readl(phba->HAregaddr); /* flush */
2103 spin_unlock_irq(&phba->hbalock);
2104 lpfc_linkdown(phba);
2105 phba->link_state = LPFC_HBA_ERROR;
2107 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2108 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2114 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2115 * @phba: pointer to lpfc hba data structure.
2116 * @vpd: pointer to the vital product data.
2117 * @len: length of the vital product data in bytes.
2119 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2120 * an array of characters. In this routine, the ModelName, ProgramType, and
2121 * ModelDesc, etc. fields of the phba data structure will be populated.
2124 * 0 - pointer to the VPD passed in is NULL
2128 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2130 uint8_t lenlo, lenhi;
2140 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2141 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2142 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2144 while (!finished && (index < (len - 4))) {
2145 switch (vpd[index]) {
2153 i = ((((unsigned short)lenhi) << 8) + lenlo);
2162 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2163 if (Length > len - index)
2164 Length = len - index;
2165 while (Length > 0) {
2166 /* Look for Serial Number */
2167 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2174 phba->SerialNumber[j++] = vpd[index++];
2178 phba->SerialNumber[j] = 0;
2181 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2182 phba->vpd_flag |= VPD_MODEL_DESC;
2189 phba->ModelDesc[j++] = vpd[index++];
2193 phba->ModelDesc[j] = 0;
2196 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2197 phba->vpd_flag |= VPD_MODEL_NAME;
2204 phba->ModelName[j++] = vpd[index++];
2208 phba->ModelName[j] = 0;
2211 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2212 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2219 phba->ProgramType[j++] = vpd[index++];
2223 phba->ProgramType[j] = 0;
2226 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2227 phba->vpd_flag |= VPD_PORT;
2234 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2235 (phba->sli4_hba.pport_name_sta ==
2236 LPFC_SLI4_PPNAME_GET)) {
2240 phba->Port[j++] = vpd[index++];
2244 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2245 (phba->sli4_hba.pport_name_sta ==
2246 LPFC_SLI4_PPNAME_NON))
2273 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2274 * @phba: pointer to lpfc hba data structure.
2275 * @mdp: pointer to the data structure to hold the derived model name.
2276 * @descp: pointer to the data structure to hold the derived description.
2278 * This routine retrieves HBA's description based on its registered PCI device
2279 * ID. The @descp passed into this function points to an array of 256 chars. It
2280 * shall be returned with the model name, maximum speed, and the host bus type.
2281 * The @mdp passed into this function points to an array of 80 chars. When the
2282 * function returns, the @mdp will be filled with the model name.
2285 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2288 uint16_t dev_id = phba->pcidev->device;
2291 int oneConnect = 0; /* default is not a oneConnect */
2296 } m = {"<Unknown>", "", ""};
2298 if (mdp && mdp[0] != '\0'
2299 && descp && descp[0] != '\0')
2302 if (phba->lmt & LMT_64Gb)
2304 else if (phba->lmt & LMT_32Gb)
2306 else if (phba->lmt & LMT_16Gb)
2308 else if (phba->lmt & LMT_10Gb)
2310 else if (phba->lmt & LMT_8Gb)
2312 else if (phba->lmt & LMT_4Gb)
2314 else if (phba->lmt & LMT_2Gb)
2316 else if (phba->lmt & LMT_1Gb)
2324 case PCI_DEVICE_ID_FIREFLY:
2325 m = (typeof(m)){"LP6000", "PCI",
2326 "Obsolete, Unsupported Fibre Channel Adapter"};
2328 case PCI_DEVICE_ID_SUPERFLY:
2329 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2330 m = (typeof(m)){"LP7000", "PCI", ""};
2332 m = (typeof(m)){"LP7000E", "PCI", ""};
2333 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2335 case PCI_DEVICE_ID_DRAGONFLY:
2336 m = (typeof(m)){"LP8000", "PCI",
2337 "Obsolete, Unsupported Fibre Channel Adapter"};
2339 case PCI_DEVICE_ID_CENTAUR:
2340 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2341 m = (typeof(m)){"LP9002", "PCI", ""};
2343 m = (typeof(m)){"LP9000", "PCI", ""};
2344 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2346 case PCI_DEVICE_ID_RFLY:
2347 m = (typeof(m)){"LP952", "PCI",
2348 "Obsolete, Unsupported Fibre Channel Adapter"};
2350 case PCI_DEVICE_ID_PEGASUS:
2351 m = (typeof(m)){"LP9802", "PCI-X",
2352 "Obsolete, Unsupported Fibre Channel Adapter"};
2354 case PCI_DEVICE_ID_THOR:
2355 m = (typeof(m)){"LP10000", "PCI-X",
2356 "Obsolete, Unsupported Fibre Channel Adapter"};
2358 case PCI_DEVICE_ID_VIPER:
2359 m = (typeof(m)){"LPX1000", "PCI-X",
2360 "Obsolete, Unsupported Fibre Channel Adapter"};
2362 case PCI_DEVICE_ID_PFLY:
2363 m = (typeof(m)){"LP982", "PCI-X",
2364 "Obsolete, Unsupported Fibre Channel Adapter"};
2366 case PCI_DEVICE_ID_TFLY:
2367 m = (typeof(m)){"LP1050", "PCI-X",
2368 "Obsolete, Unsupported Fibre Channel Adapter"};
2370 case PCI_DEVICE_ID_HELIOS:
2371 m = (typeof(m)){"LP11000", "PCI-X2",
2372 "Obsolete, Unsupported Fibre Channel Adapter"};
2374 case PCI_DEVICE_ID_HELIOS_SCSP:
2375 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2376 "Obsolete, Unsupported Fibre Channel Adapter"};
2378 case PCI_DEVICE_ID_HELIOS_DCSP:
2379 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2380 "Obsolete, Unsupported Fibre Channel Adapter"};
2382 case PCI_DEVICE_ID_NEPTUNE:
2383 m = (typeof(m)){"LPe1000", "PCIe",
2384 "Obsolete, Unsupported Fibre Channel Adapter"};
2386 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2387 m = (typeof(m)){"LPe1000-SP", "PCIe",
2388 "Obsolete, Unsupported Fibre Channel Adapter"};
2390 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2391 m = (typeof(m)){"LPe1002-SP", "PCIe",
2392 "Obsolete, Unsupported Fibre Channel Adapter"};
2394 case PCI_DEVICE_ID_BMID:
2395 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2397 case PCI_DEVICE_ID_BSMB:
2398 m = (typeof(m)){"LP111", "PCI-X2",
2399 "Obsolete, Unsupported Fibre Channel Adapter"};
2401 case PCI_DEVICE_ID_ZEPHYR:
2402 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2404 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2405 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2407 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2408 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2411 case PCI_DEVICE_ID_ZMID:
2412 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2414 case PCI_DEVICE_ID_ZSMB:
2415 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2417 case PCI_DEVICE_ID_LP101:
2418 m = (typeof(m)){"LP101", "PCI-X",
2419 "Obsolete, Unsupported Fibre Channel Adapter"};
2421 case PCI_DEVICE_ID_LP10000S:
2422 m = (typeof(m)){"LP10000-S", "PCI",
2423 "Obsolete, Unsupported Fibre Channel Adapter"};
2425 case PCI_DEVICE_ID_LP11000S:
2426 m = (typeof(m)){"LP11000-S", "PCI-X2",
2427 "Obsolete, Unsupported Fibre Channel Adapter"};
2429 case PCI_DEVICE_ID_LPE11000S:
2430 m = (typeof(m)){"LPe11000-S", "PCIe",
2431 "Obsolete, Unsupported Fibre Channel Adapter"};
2433 case PCI_DEVICE_ID_SAT:
2434 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2436 case PCI_DEVICE_ID_SAT_MID:
2437 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2439 case PCI_DEVICE_ID_SAT_SMB:
2440 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2442 case PCI_DEVICE_ID_SAT_DCSP:
2443 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2445 case PCI_DEVICE_ID_SAT_SCSP:
2446 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2448 case PCI_DEVICE_ID_SAT_S:
2449 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2451 case PCI_DEVICE_ID_HORNET:
2452 m = (typeof(m)){"LP21000", "PCIe",
2453 "Obsolete, Unsupported FCoE Adapter"};
2456 case PCI_DEVICE_ID_PROTEUS_VF:
2457 m = (typeof(m)){"LPev12000", "PCIe IOV",
2458 "Obsolete, Unsupported Fibre Channel Adapter"};
2460 case PCI_DEVICE_ID_PROTEUS_PF:
2461 m = (typeof(m)){"LPev12000", "PCIe IOV",
2462 "Obsolete, Unsupported Fibre Channel Adapter"};
2464 case PCI_DEVICE_ID_PROTEUS_S:
2465 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2466 "Obsolete, Unsupported Fibre Channel Adapter"};
2468 case PCI_DEVICE_ID_TIGERSHARK:
2470 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2472 case PCI_DEVICE_ID_TOMCAT:
2474 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2476 case PCI_DEVICE_ID_FALCON:
2477 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2478 "EmulexSecure Fibre"};
2480 case PCI_DEVICE_ID_BALIUS:
2481 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2482 "Obsolete, Unsupported Fibre Channel Adapter"};
2484 case PCI_DEVICE_ID_LANCER_FC:
2485 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2487 case PCI_DEVICE_ID_LANCER_FC_VF:
2488 m = (typeof(m)){"LPe16000", "PCIe",
2489 "Obsolete, Unsupported Fibre Channel Adapter"};
2491 case PCI_DEVICE_ID_LANCER_FCOE:
2493 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2495 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2497 m = (typeof(m)){"OCe15100", "PCIe",
2498 "Obsolete, Unsupported FCoE"};
2500 case PCI_DEVICE_ID_LANCER_G6_FC:
2501 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2503 case PCI_DEVICE_ID_LANCER_G7_FC:
2504 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2506 case PCI_DEVICE_ID_SKYHAWK:
2507 case PCI_DEVICE_ID_SKYHAWK_VF:
2509 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2512 m = (typeof(m)){"Unknown", "", ""};
2516 if (mdp && mdp[0] == '\0')
2517 snprintf(mdp, 79,"%s", m.name);
2519 * oneConnect hba requires special processing, they are all initiators
2520 * and we put the port number on the end
2522 if (descp && descp[0] == '\0') {
2524 snprintf(descp, 255,
2525 "Emulex OneConnect %s, %s Initiator %s",
2528 else if (max_speed == 0)
2529 snprintf(descp, 255,
2531 m.name, m.bus, m.function);
2533 snprintf(descp, 255,
2534 "Emulex %s %d%s %s %s",
2535 m.name, max_speed, (GE) ? "GE" : "Gb",
2541 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2542 * @phba: pointer to lpfc hba data structure.
2543 * @pring: pointer to a IOCB ring.
2544 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2546 * This routine posts a given number of IOCBs with the associated DMA buffer
2547 * descriptors specified by the cnt argument to the given IOCB ring.
2550 * The number of IOCBs NOT able to be posted to the IOCB ring.
2553 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2556 struct lpfc_iocbq *iocb;
2557 struct lpfc_dmabuf *mp1, *mp2;
2559 cnt += pring->missbufcnt;
2561 /* While there are buffers to post */
2563 /* Allocate buffer for command iocb */
2564 iocb = lpfc_sli_get_iocbq(phba);
2566 pring->missbufcnt = cnt;
2571 /* 2 buffers can be posted per command */
2572 /* Allocate buffer to post */
2573 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2575 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2576 if (!mp1 || !mp1->virt) {
2578 lpfc_sli_release_iocbq(phba, iocb);
2579 pring->missbufcnt = cnt;
2583 INIT_LIST_HEAD(&mp1->list);
2584 /* Allocate buffer to post */
2586 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2588 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2590 if (!mp2 || !mp2->virt) {
2592 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2594 lpfc_sli_release_iocbq(phba, iocb);
2595 pring->missbufcnt = cnt;
2599 INIT_LIST_HEAD(&mp2->list);
2604 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2605 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2606 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2607 icmd->ulpBdeCount = 1;
2610 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2611 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2612 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2614 icmd->ulpBdeCount = 2;
2617 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2620 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2622 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2626 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2630 lpfc_sli_release_iocbq(phba, iocb);
2631 pring->missbufcnt = cnt;
2634 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2636 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2638 pring->missbufcnt = 0;
2643 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2644 * @phba: pointer to lpfc hba data structure.
2646 * This routine posts initial receive IOCB buffers to the ELS ring. The
2647 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2648 * set to 64 IOCBs. SLI3 only.
2651 * 0 - success (currently always success)
2654 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2656 struct lpfc_sli *psli = &phba->sli;
2658 /* Ring 0, ELS / CT buffers */
2659 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2660 /* Ring 2 - FCP no buffers needed */
2665 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2668 * lpfc_sha_init - Set up initial array of hash table entries
2669 * @HashResultPointer: pointer to an array as hash table.
2671 * This routine sets up the initial values to the array of hash table entries
2675 lpfc_sha_init(uint32_t * HashResultPointer)
2677 HashResultPointer[0] = 0x67452301;
2678 HashResultPointer[1] = 0xEFCDAB89;
2679 HashResultPointer[2] = 0x98BADCFE;
2680 HashResultPointer[3] = 0x10325476;
2681 HashResultPointer[4] = 0xC3D2E1F0;
2685 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2686 * @HashResultPointer: pointer to an initial/result hash table.
2687 * @HashWorkingPointer: pointer to an working hash table.
2689 * This routine iterates an initial hash table pointed by @HashResultPointer
2690 * with the values from the working hash table pointeed by @HashWorkingPointer.
2691 * The results are putting back to the initial hash table, returned through
2692 * the @HashResultPointer as the result hash table.
2695 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2699 uint32_t A, B, C, D, E;
2702 HashWorkingPointer[t] =
2704 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2706 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2707 } while (++t <= 79);
2709 A = HashResultPointer[0];
2710 B = HashResultPointer[1];
2711 C = HashResultPointer[2];
2712 D = HashResultPointer[3];
2713 E = HashResultPointer[4];
2717 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2718 } else if (t < 40) {
2719 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2720 } else if (t < 60) {
2721 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2723 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2725 TEMP += S(5, A) + E + HashWorkingPointer[t];
2731 } while (++t <= 79);
2733 HashResultPointer[0] += A;
2734 HashResultPointer[1] += B;
2735 HashResultPointer[2] += C;
2736 HashResultPointer[3] += D;
2737 HashResultPointer[4] += E;
2742 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2743 * @RandomChallenge: pointer to the entry of host challenge random number array.
2744 * @HashWorking: pointer to the entry of the working hash array.
2746 * This routine calculates the working hash array referred by @HashWorking
2747 * from the challenge random numbers associated with the host, referred by
2748 * @RandomChallenge. The result is put into the entry of the working hash
2749 * array and returned by reference through @HashWorking.
2752 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2754 *HashWorking = (*RandomChallenge ^ *HashWorking);
2758 * lpfc_hba_init - Perform special handling for LC HBA initialization
2759 * @phba: pointer to lpfc hba data structure.
2760 * @hbainit: pointer to an array of unsigned 32-bit integers.
2762 * This routine performs the special handling for LC HBA initialization.
2765 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2768 uint32_t *HashWorking;
2769 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2771 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2775 HashWorking[0] = HashWorking[78] = *pwwnn++;
2776 HashWorking[1] = HashWorking[79] = *pwwnn;
2778 for (t = 0; t < 7; t++)
2779 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2781 lpfc_sha_init(hbainit);
2782 lpfc_sha_iterate(hbainit, HashWorking);
2787 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2788 * @vport: pointer to a virtual N_Port data structure.
2790 * This routine performs the necessary cleanups before deleting the @vport.
2791 * It invokes the discovery state machine to perform necessary state
2792 * transitions and to release the ndlps associated with the @vport. Note,
2793 * the physical port is treated as @vport 0.
2796 lpfc_cleanup(struct lpfc_vport *vport)
2798 struct lpfc_hba *phba = vport->phba;
2799 struct lpfc_nodelist *ndlp, *next_ndlp;
2802 if (phba->link_state > LPFC_LINK_DOWN)
2803 lpfc_port_link_failure(vport);
2805 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2806 if (!NLP_CHK_NODE_ACT(ndlp)) {
2807 ndlp = lpfc_enable_node(vport, ndlp,
2808 NLP_STE_UNUSED_NODE);
2811 spin_lock_irq(&phba->ndlp_lock);
2812 NLP_SET_FREE_REQ(ndlp);
2813 spin_unlock_irq(&phba->ndlp_lock);
2814 /* Trigger the release of the ndlp memory */
2818 spin_lock_irq(&phba->ndlp_lock);
2819 if (NLP_CHK_FREE_REQ(ndlp)) {
2820 /* The ndlp should not be in memory free mode already */
2821 spin_unlock_irq(&phba->ndlp_lock);
2824 /* Indicate request for freeing ndlp memory */
2825 NLP_SET_FREE_REQ(ndlp);
2826 spin_unlock_irq(&phba->ndlp_lock);
2828 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2829 ndlp->nlp_DID == Fabric_DID) {
2830 /* Just free up ndlp with Fabric_DID for vports */
2835 /* take care of nodes in unused state before the state
2836 * machine taking action.
2838 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2843 if (ndlp->nlp_type & NLP_FABRIC)
2844 lpfc_disc_state_machine(vport, ndlp, NULL,
2845 NLP_EVT_DEVICE_RECOVERY);
2847 lpfc_disc_state_machine(vport, ndlp, NULL,
2851 /* At this point, ALL ndlp's should be gone
2852 * because of the previous NLP_EVT_DEVICE_RM.
2853 * Lets wait for this to happen, if needed.
2855 while (!list_empty(&vport->fc_nodes)) {
2857 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2858 "0233 Nodelist not empty\n");
2859 list_for_each_entry_safe(ndlp, next_ndlp,
2860 &vport->fc_nodes, nlp_listp) {
2861 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2863 "0282 did:x%x ndlp:x%p "
2864 "usgmap:x%x refcnt:%d\n",
2865 ndlp->nlp_DID, (void *)ndlp,
2867 kref_read(&ndlp->kref));
2872 /* Wait for any activity on ndlps to settle */
2875 lpfc_cleanup_vports_rrqs(vport, NULL);
2879 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2880 * @vport: pointer to a virtual N_Port data structure.
2882 * This routine stops all the timers associated with a @vport. This function
2883 * is invoked before disabling or deleting a @vport. Note that the physical
2884 * port is treated as @vport 0.
2887 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2889 del_timer_sync(&vport->els_tmofunc);
2890 del_timer_sync(&vport->delayed_disc_tmo);
2891 lpfc_can_disctmo(vport);
2896 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2897 * @phba: pointer to lpfc hba data structure.
2899 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2900 * caller of this routine should already hold the host lock.
2903 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2905 /* Clear pending FCF rediscovery wait flag */
2906 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2908 /* Now, try to stop the timer */
2909 del_timer(&phba->fcf.redisc_wait);
2913 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2914 * @phba: pointer to lpfc hba data structure.
2916 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2917 * checks whether the FCF rediscovery wait timer is pending with the host
2918 * lock held before proceeding with disabling the timer and clearing the
2919 * wait timer pendig flag.
2922 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2924 spin_lock_irq(&phba->hbalock);
2925 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2926 /* FCF rediscovery timer already fired or stopped */
2927 spin_unlock_irq(&phba->hbalock);
2930 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2931 /* Clear failover in progress flags */
2932 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2933 spin_unlock_irq(&phba->hbalock);
2937 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2938 * @phba: pointer to lpfc hba data structure.
2940 * This routine stops all the timers associated with a HBA. This function is
2941 * invoked before either putting a HBA offline or unloading the driver.
2944 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2946 lpfc_stop_vport_timers(phba->pport);
2947 del_timer_sync(&phba->sli.mbox_tmo);
2948 del_timer_sync(&phba->fabric_block_timer);
2949 del_timer_sync(&phba->eratt_poll);
2950 del_timer_sync(&phba->hb_tmofunc);
2951 if (phba->sli_rev == LPFC_SLI_REV4) {
2952 del_timer_sync(&phba->rrq_tmr);
2953 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2955 phba->hb_outstanding = 0;
2957 switch (phba->pci_dev_grp) {
2958 case LPFC_PCI_DEV_LP:
2959 /* Stop any LightPulse device specific driver timers */
2960 del_timer_sync(&phba->fcp_poll_timer);
2962 case LPFC_PCI_DEV_OC:
2963 /* Stop any OneConnect device sepcific driver timers */
2964 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2967 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2968 "0297 Invalid device group (x%x)\n",
2976 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2977 * @phba: pointer to lpfc hba data structure.
2979 * This routine marks a HBA's management interface as blocked. Once the HBA's
2980 * management interface is marked as blocked, all the user space access to
2981 * the HBA, whether they are from sysfs interface or libdfc interface will
2982 * all be blocked. The HBA is set to block the management interface when the
2983 * driver prepares the HBA interface for online or offline.
2986 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2988 unsigned long iflag;
2989 uint8_t actcmd = MBX_HEARTBEAT;
2990 unsigned long timeout;
2992 spin_lock_irqsave(&phba->hbalock, iflag);
2993 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2994 spin_unlock_irqrestore(&phba->hbalock, iflag);
2995 if (mbx_action == LPFC_MBX_NO_WAIT)
2997 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2998 spin_lock_irqsave(&phba->hbalock, iflag);
2999 if (phba->sli.mbox_active) {
3000 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
3001 /* Determine how long we might wait for the active mailbox
3002 * command to be gracefully completed by firmware.
3004 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3005 phba->sli.mbox_active) * 1000) + jiffies;
3007 spin_unlock_irqrestore(&phba->hbalock, iflag);
3009 /* Wait for the outstnading mailbox command to complete */
3010 while (phba->sli.mbox_active) {
3011 /* Check active mailbox complete status every 2ms */
3013 if (time_after(jiffies, timeout)) {
3014 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3015 "2813 Mgmt IO is Blocked %x "
3016 "- mbox cmd %x still active\n",
3017 phba->sli.sli_flag, actcmd);
3024 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3025 * @phba: pointer to lpfc hba data structure.
3027 * Allocate RPIs for all active remote nodes. This is needed whenever
3028 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3029 * is to fixup the temporary rpi assignments.
3032 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3034 struct lpfc_nodelist *ndlp, *next_ndlp;
3035 struct lpfc_vport **vports;
3037 unsigned long flags;
3039 if (phba->sli_rev != LPFC_SLI_REV4)
3042 vports = lpfc_create_vport_work_array(phba);
3046 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3047 if (vports[i]->load_flag & FC_UNLOADING)
3050 list_for_each_entry_safe(ndlp, next_ndlp,
3051 &vports[i]->fc_nodes,
3053 if (!NLP_CHK_NODE_ACT(ndlp))
3055 rpi = lpfc_sli4_alloc_rpi(phba);
3056 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3057 spin_lock_irqsave(&phba->ndlp_lock, flags);
3058 NLP_CLR_NODE_ACT(ndlp);
3059 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3062 ndlp->nlp_rpi = rpi;
3063 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3064 "0009 rpi:%x DID:%x "
3065 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3066 ndlp->nlp_DID, ndlp->nlp_flag,
3067 ndlp->nlp_usg_map, ndlp);
3070 lpfc_destroy_vport_work_array(phba, vports);
3074 * lpfc_online - Initialize and bring a HBA online
3075 * @phba: pointer to lpfc hba data structure.
3077 * This routine initializes the HBA and brings a HBA online. During this
3078 * process, the management interface is blocked to prevent user space access
3079 * to the HBA interfering with the driver initialization.
3086 lpfc_online(struct lpfc_hba *phba)
3088 struct lpfc_vport *vport;
3089 struct lpfc_vport **vports;
3091 bool vpis_cleared = false;
3095 vport = phba->pport;
3097 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3100 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3101 "0458 Bring Adapter online\n");
3103 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3105 if (phba->sli_rev == LPFC_SLI_REV4) {
3106 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3107 lpfc_unblock_mgmt_io(phba);
3110 spin_lock_irq(&phba->hbalock);
3111 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3112 vpis_cleared = true;
3113 spin_unlock_irq(&phba->hbalock);
3115 /* Reestablish the local initiator port.
3116 * The offline process destroyed the previous lport.
3118 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3119 !phba->nvmet_support) {
3120 error = lpfc_nvme_create_localport(phba->pport);
3122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3123 "6132 NVME restore reg failed "
3124 "on nvmei error x%x\n", error);
3127 lpfc_sli_queue_init(phba);
3128 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3129 lpfc_unblock_mgmt_io(phba);
3134 vports = lpfc_create_vport_work_array(phba);
3135 if (vports != NULL) {
3136 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3137 struct Scsi_Host *shost;
3138 shost = lpfc_shost_from_vport(vports[i]);
3139 spin_lock_irq(shost->host_lock);
3140 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3141 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3142 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3143 if (phba->sli_rev == LPFC_SLI_REV4) {
3144 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3145 if ((vpis_cleared) &&
3146 (vports[i]->port_type !=
3147 LPFC_PHYSICAL_PORT))
3150 spin_unlock_irq(shost->host_lock);
3153 lpfc_destroy_vport_work_array(phba, vports);
3155 lpfc_unblock_mgmt_io(phba);
3160 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3161 * @phba: pointer to lpfc hba data structure.
3163 * This routine marks a HBA's management interface as not blocked. Once the
3164 * HBA's management interface is marked as not blocked, all the user space
3165 * access to the HBA, whether they are from sysfs interface or libdfc
3166 * interface will be allowed. The HBA is set to block the management interface
3167 * when the driver prepares the HBA interface for online or offline and then
3168 * set to unblock the management interface afterwards.
3171 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3173 unsigned long iflag;
3175 spin_lock_irqsave(&phba->hbalock, iflag);
3176 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3177 spin_unlock_irqrestore(&phba->hbalock, iflag);
3181 * lpfc_offline_prep - Prepare a HBA to be brought offline
3182 * @phba: pointer to lpfc hba data structure.
3184 * This routine is invoked to prepare a HBA to be brought offline. It performs
3185 * unregistration login to all the nodes on all vports and flushes the mailbox
3186 * queue to make it ready to be brought offline.
3189 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3191 struct lpfc_vport *vport = phba->pport;
3192 struct lpfc_nodelist *ndlp, *next_ndlp;
3193 struct lpfc_vport **vports;
3194 struct Scsi_Host *shost;
3197 if (vport->fc_flag & FC_OFFLINE_MODE)
3200 lpfc_block_mgmt_io(phba, mbx_action);
3202 lpfc_linkdown(phba);
3204 /* Issue an unreg_login to all nodes on all vports */
3205 vports = lpfc_create_vport_work_array(phba);
3206 if (vports != NULL) {
3207 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3208 if (vports[i]->load_flag & FC_UNLOADING)
3210 shost = lpfc_shost_from_vport(vports[i]);
3211 spin_lock_irq(shost->host_lock);
3212 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3213 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3214 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3215 spin_unlock_irq(shost->host_lock);
3217 shost = lpfc_shost_from_vport(vports[i]);
3218 list_for_each_entry_safe(ndlp, next_ndlp,
3219 &vports[i]->fc_nodes,
3221 if (!NLP_CHK_NODE_ACT(ndlp))
3223 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3225 if (ndlp->nlp_type & NLP_FABRIC) {
3226 lpfc_disc_state_machine(vports[i], ndlp,
3227 NULL, NLP_EVT_DEVICE_RECOVERY);
3228 lpfc_disc_state_machine(vports[i], ndlp,
3229 NULL, NLP_EVT_DEVICE_RM);
3231 spin_lock_irq(shost->host_lock);
3232 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3233 spin_unlock_irq(shost->host_lock);
3235 * Whenever an SLI4 port goes offline, free the
3236 * RPI. Get a new RPI when the adapter port
3237 * comes back online.
3239 if (phba->sli_rev == LPFC_SLI_REV4) {
3240 lpfc_printf_vlog(ndlp->vport,
3241 KERN_INFO, LOG_NODE,
3242 "0011 lpfc_offline: "
3244 "usgmap:x%x rpi:%x\n",
3245 ndlp, ndlp->nlp_DID,
3249 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3251 lpfc_unreg_rpi(vports[i], ndlp);
3255 lpfc_destroy_vport_work_array(phba, vports);
3257 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3260 flush_workqueue(phba->wq);
3264 * lpfc_offline - Bring a HBA offline
3265 * @phba: pointer to lpfc hba data structure.
3267 * This routine actually brings a HBA offline. It stops all the timers
3268 * associated with the HBA, brings down the SLI layer, and eventually
3269 * marks the HBA as in offline state for the upper layer protocol.
3272 lpfc_offline(struct lpfc_hba *phba)
3274 struct Scsi_Host *shost;
3275 struct lpfc_vport **vports;
3278 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3281 /* stop port and all timers associated with this hba */
3282 lpfc_stop_port(phba);
3284 /* Tear down the local and target port registrations. The
3285 * nvme transports need to cleanup.
3287 lpfc_nvmet_destroy_targetport(phba);
3288 lpfc_nvme_destroy_localport(phba->pport);
3290 vports = lpfc_create_vport_work_array(phba);
3292 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3293 lpfc_stop_vport_timers(vports[i]);
3294 lpfc_destroy_vport_work_array(phba, vports);
3295 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3296 "0460 Bring Adapter offline\n");
3297 /* Bring down the SLI Layer and cleanup. The HBA is offline
3299 lpfc_sli_hba_down(phba);
3300 spin_lock_irq(&phba->hbalock);
3302 spin_unlock_irq(&phba->hbalock);
3303 vports = lpfc_create_vport_work_array(phba);
3305 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3306 shost = lpfc_shost_from_vport(vports[i]);
3307 spin_lock_irq(shost->host_lock);
3308 vports[i]->work_port_events = 0;
3309 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3310 spin_unlock_irq(shost->host_lock);
3312 lpfc_destroy_vport_work_array(phba, vports);
3316 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3317 * @phba: pointer to lpfc hba data structure.
3319 * This routine is to free all the SCSI buffers and IOCBs from the driver
3320 * list back to kernel. It is called from lpfc_pci_remove_one to free
3321 * the internal resources before the device is removed from the system.
3324 lpfc_scsi_free(struct lpfc_hba *phba)
3326 struct lpfc_scsi_buf *sb, *sb_next;
3328 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3331 spin_lock_irq(&phba->hbalock);
3333 /* Release all the lpfc_scsi_bufs maintained by this host. */
3335 spin_lock(&phba->scsi_buf_list_put_lock);
3336 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3338 list_del(&sb->list);
3339 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3342 phba->total_scsi_bufs--;
3344 spin_unlock(&phba->scsi_buf_list_put_lock);
3346 spin_lock(&phba->scsi_buf_list_get_lock);
3347 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3349 list_del(&sb->list);
3350 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3353 phba->total_scsi_bufs--;
3355 spin_unlock(&phba->scsi_buf_list_get_lock);
3356 spin_unlock_irq(&phba->hbalock);
3359 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3360 * @phba: pointer to lpfc hba data structure.
3362 * This routine is to free all the NVME buffers and IOCBs from the driver
3363 * list back to kernel. It is called from lpfc_pci_remove_one to free
3364 * the internal resources before the device is removed from the system.
3367 lpfc_nvme_free(struct lpfc_hba *phba)
3369 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
3371 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3374 spin_lock_irq(&phba->hbalock);
3376 /* Release all the lpfc_nvme_bufs maintained by this host. */
3377 spin_lock(&phba->nvme_buf_list_put_lock);
3378 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3379 &phba->lpfc_nvme_buf_list_put, list) {
3380 list_del(&lpfc_ncmd->list);
3381 phba->put_nvme_bufs--;
3382 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3383 lpfc_ncmd->dma_handle);
3385 phba->total_nvme_bufs--;
3387 spin_unlock(&phba->nvme_buf_list_put_lock);
3389 spin_lock(&phba->nvme_buf_list_get_lock);
3390 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3391 &phba->lpfc_nvme_buf_list_get, list) {
3392 list_del(&lpfc_ncmd->list);
3393 phba->get_nvme_bufs--;
3394 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3395 lpfc_ncmd->dma_handle);
3397 phba->total_nvme_bufs--;
3399 spin_unlock(&phba->nvme_buf_list_get_lock);
3400 spin_unlock_irq(&phba->hbalock);
3403 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3404 * @phba: pointer to lpfc hba data structure.
3406 * This routine first calculates the sizes of the current els and allocated
3407 * scsi sgl lists, and then goes through all sgls to updates the physical
3408 * XRIs assigned due to port function reset. During port initialization, the
3409 * current els and allocated scsi sgl lists are 0s.
3412 * 0 - successful (for now, it always returns 0)
3415 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3417 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3418 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3419 LIST_HEAD(els_sgl_list);
3423 * update on pci function's els xri-sgl list
3425 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3427 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3428 /* els xri-sgl expanded */
3429 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3430 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3431 "3157 ELS xri-sgl count increased from "
3432 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3434 /* allocate the additional els sgls */
3435 for (i = 0; i < xri_cnt; i++) {
3436 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3438 if (sglq_entry == NULL) {
3439 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3440 "2562 Failure to allocate an "
3441 "ELS sgl entry:%d\n", i);
3445 sglq_entry->buff_type = GEN_BUFF_TYPE;
3446 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3448 if (sglq_entry->virt == NULL) {
3450 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3451 "2563 Failure to allocate an "
3452 "ELS mbuf:%d\n", i);
3456 sglq_entry->sgl = sglq_entry->virt;
3457 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3458 sglq_entry->state = SGL_FREED;
3459 list_add_tail(&sglq_entry->list, &els_sgl_list);
3461 spin_lock_irq(&phba->hbalock);
3462 spin_lock(&phba->sli4_hba.sgl_list_lock);
3463 list_splice_init(&els_sgl_list,
3464 &phba->sli4_hba.lpfc_els_sgl_list);
3465 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3466 spin_unlock_irq(&phba->hbalock);
3467 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3468 /* els xri-sgl shrinked */
3469 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3470 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3471 "3158 ELS xri-sgl count decreased from "
3472 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3474 spin_lock_irq(&phba->hbalock);
3475 spin_lock(&phba->sli4_hba.sgl_list_lock);
3476 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3478 /* release extra els sgls from list */
3479 for (i = 0; i < xri_cnt; i++) {
3480 list_remove_head(&els_sgl_list,
3481 sglq_entry, struct lpfc_sglq, list);
3483 __lpfc_mbuf_free(phba, sglq_entry->virt,
3488 list_splice_init(&els_sgl_list,
3489 &phba->sli4_hba.lpfc_els_sgl_list);
3490 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3491 spin_unlock_irq(&phba->hbalock);
3493 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3494 "3163 ELS xri-sgl count unchanged: %d\n",
3496 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3498 /* update xris to els sgls on the list */
3500 sglq_entry_next = NULL;
3501 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3502 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3503 lxri = lpfc_sli4_next_xritag(phba);
3504 if (lxri == NO_XRI) {
3505 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3506 "2400 Failed to allocate xri for "
3511 sglq_entry->sli4_lxritag = lxri;
3512 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3517 lpfc_free_els_sgl_list(phba);
3522 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3523 * @phba: pointer to lpfc hba data structure.
3525 * This routine first calculates the sizes of the current els and allocated
3526 * scsi sgl lists, and then goes through all sgls to updates the physical
3527 * XRIs assigned due to port function reset. During port initialization, the
3528 * current els and allocated scsi sgl lists are 0s.
3531 * 0 - successful (for now, it always returns 0)
3534 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3536 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3537 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3538 uint16_t nvmet_xri_cnt;
3539 LIST_HEAD(nvmet_sgl_list);
3543 * update on pci function's nvmet xri-sgl list
3545 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3547 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3548 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3549 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3550 /* els xri-sgl expanded */
3551 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3552 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3553 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3554 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3555 /* allocate the additional nvmet sgls */
3556 for (i = 0; i < xri_cnt; i++) {
3557 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3559 if (sglq_entry == NULL) {
3560 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3561 "6303 Failure to allocate an "
3562 "NVMET sgl entry:%d\n", i);
3566 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3567 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3569 if (sglq_entry->virt == NULL) {
3571 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3572 "6304 Failure to allocate an "
3573 "NVMET buf:%d\n", i);
3577 sglq_entry->sgl = sglq_entry->virt;
3578 memset(sglq_entry->sgl, 0,
3579 phba->cfg_sg_dma_buf_size);
3580 sglq_entry->state = SGL_FREED;
3581 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3583 spin_lock_irq(&phba->hbalock);
3584 spin_lock(&phba->sli4_hba.sgl_list_lock);
3585 list_splice_init(&nvmet_sgl_list,
3586 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3587 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3588 spin_unlock_irq(&phba->hbalock);
3589 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3590 /* nvmet xri-sgl shrunk */
3591 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3592 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3593 "6305 NVMET xri-sgl count decreased from "
3594 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3596 spin_lock_irq(&phba->hbalock);
3597 spin_lock(&phba->sli4_hba.sgl_list_lock);
3598 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3600 /* release extra nvmet sgls from list */
3601 for (i = 0; i < xri_cnt; i++) {
3602 list_remove_head(&nvmet_sgl_list,
3603 sglq_entry, struct lpfc_sglq, list);
3605 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3610 list_splice_init(&nvmet_sgl_list,
3611 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3612 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3613 spin_unlock_irq(&phba->hbalock);
3615 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3616 "6306 NVMET xri-sgl count unchanged: %d\n",
3618 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3620 /* update xris to nvmet sgls on the list */
3622 sglq_entry_next = NULL;
3623 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3624 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3625 lxri = lpfc_sli4_next_xritag(phba);
3626 if (lxri == NO_XRI) {
3627 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3628 "6307 Failed to allocate xri for "
3633 sglq_entry->sli4_lxritag = lxri;
3634 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3639 lpfc_free_nvmet_sgl_list(phba);
3644 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3645 * @phba: pointer to lpfc hba data structure.
3647 * This routine first calculates the sizes of the current els and allocated
3648 * scsi sgl lists, and then goes through all sgls to updates the physical
3649 * XRIs assigned due to port function reset. During port initialization, the
3650 * current els and allocated scsi sgl lists are 0s.
3653 * 0 - successful (for now, it always returns 0)
3656 lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3658 struct lpfc_scsi_buf *psb, *psb_next;
3659 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3660 LIST_HEAD(scsi_sgl_list);
3664 * update on pci function's els xri-sgl list
3666 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3667 phba->total_scsi_bufs = 0;
3670 * update on pci function's allocated scsi xri-sgl list
3672 /* maximum number of xris available for scsi buffers */
3673 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3676 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3679 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3680 phba->sli4_hba.scsi_xri_max = /* Split them up */
3681 (phba->sli4_hba.scsi_xri_max *
3682 phba->cfg_xri_split) / 100;
3684 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3685 spin_lock(&phba->scsi_buf_list_put_lock);
3686 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3687 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3688 spin_unlock(&phba->scsi_buf_list_put_lock);
3689 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3691 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3692 "6060 Current allocated SCSI xri-sgl count:%d, "
3693 "maximum SCSI xri count:%d (split:%d)\n",
3694 phba->sli4_hba.scsi_xri_cnt,
3695 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3697 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3698 /* max scsi xri shrinked below the allocated scsi buffers */
3699 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3700 phba->sli4_hba.scsi_xri_max;
3701 /* release the extra allocated scsi buffers */
3702 for (i = 0; i < scsi_xri_cnt; i++) {
3703 list_remove_head(&scsi_sgl_list, psb,
3704 struct lpfc_scsi_buf, list);
3706 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3707 psb->data, psb->dma_handle);
3711 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3712 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3713 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3716 /* update xris associated to remaining allocated scsi buffers */
3719 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3720 lxri = lpfc_sli4_next_xritag(phba);
3721 if (lxri == NO_XRI) {
3722 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3723 "2560 Failed to allocate xri for "
3728 psb->cur_iocbq.sli4_lxritag = lxri;
3729 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3731 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3732 spin_lock(&phba->scsi_buf_list_put_lock);
3733 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3734 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3735 spin_unlock(&phba->scsi_buf_list_put_lock);
3736 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3740 lpfc_scsi_free(phba);
3745 lpfc_get_wwpn(struct lpfc_hba *phba)
3749 LPFC_MBOXQ_t *mboxq;
3752 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3755 return (uint64_t)-1;
3757 /* First get WWN of HBA instance */
3758 lpfc_read_nv(phba, mboxq);
3759 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3760 if (rc != MBX_SUCCESS) {
3761 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3762 "6019 Mailbox failed , mbxCmd x%x "
3763 "READ_NV, mbxStatus x%x\n",
3764 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3765 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3766 mempool_free(mboxq, phba->mbox_mem_pool);
3767 return (uint64_t) -1;
3770 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3771 /* wwn is WWPN of HBA instance */
3772 mempool_free(mboxq, phba->mbox_mem_pool);
3773 if (phba->sli_rev == LPFC_SLI_REV4)
3774 return be64_to_cpu(wwn);
3776 return rol64(wwn, 32);
3780 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3781 * @phba: pointer to lpfc hba data structure.
3783 * This routine first calculates the sizes of the current els and allocated
3784 * scsi sgl lists, and then goes through all sgls to updates the physical
3785 * XRIs assigned due to port function reset. During port initialization, the
3786 * current els and allocated scsi sgl lists are 0s.
3789 * 0 - successful (for now, it always returns 0)
3792 lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3794 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3795 uint16_t i, lxri, els_xri_cnt;
3796 uint16_t nvme_xri_cnt, nvme_xri_max;
3797 LIST_HEAD(nvme_sgl_list);
3800 phba->total_nvme_bufs = 0;
3801 phba->get_nvme_bufs = 0;
3802 phba->put_nvme_bufs = 0;
3804 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3807 * update on pci function's allocated nvme xri-sgl list
3810 /* maximum number of xris available for nvme buffers */
3811 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3812 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3813 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3814 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3816 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3817 "6074 Current allocated NVME xri-sgl count:%d, "
3818 "maximum NVME xri count:%d\n",
3819 phba->sli4_hba.nvme_xri_cnt,
3820 phba->sli4_hba.nvme_xri_max);
3822 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3823 spin_lock(&phba->nvme_buf_list_put_lock);
3824 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3825 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3826 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3827 phba->get_nvme_bufs = 0;
3828 phba->put_nvme_bufs = 0;
3829 spin_unlock(&phba->nvme_buf_list_put_lock);
3830 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3832 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3833 /* max nvme xri shrunk below the allocated nvme buffers */
3834 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3835 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3836 phba->sli4_hba.nvme_xri_max;
3837 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3838 /* release the extra allocated nvme buffers */
3839 for (i = 0; i < nvme_xri_cnt; i++) {
3840 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3841 struct lpfc_nvme_buf, list);
3843 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3845 lpfc_ncmd->dma_handle);
3849 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3850 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3851 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3854 /* update xris associated to remaining allocated nvme buffers */
3856 lpfc_ncmd_next = NULL;
3857 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3858 &nvme_sgl_list, list) {
3859 lxri = lpfc_sli4_next_xritag(phba);
3860 if (lxri == NO_XRI) {
3861 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3862 "6075 Failed to allocate xri for "
3867 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3868 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3870 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3871 spin_lock(&phba->nvme_buf_list_put_lock);
3872 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3873 phba->get_nvme_bufs = cnt;
3874 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3875 spin_unlock(&phba->nvme_buf_list_put_lock);
3876 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3880 lpfc_nvme_free(phba);
3885 * lpfc_create_port - Create an FC port
3886 * @phba: pointer to lpfc hba data structure.
3887 * @instance: a unique integer ID to this FC port.
3888 * @dev: pointer to the device data structure.
3890 * This routine creates a FC port for the upper layer protocol. The FC port
3891 * can be created on top of either a physical port or a virtual port provided
3892 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3893 * and associates the FC port created before adding the shost into the SCSI
3897 * @vport - pointer to the virtual N_Port data structure.
3898 * NULL - port create failed.
3901 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3903 struct lpfc_vport *vport;
3904 struct Scsi_Host *shost = NULL;
3908 bool use_no_reset_hba = false;
3911 if (lpfc_no_hba_reset_cnt) {
3912 if (phba->sli_rev < LPFC_SLI_REV4 &&
3913 dev == &phba->pcidev->dev) {
3914 /* Reset the port first */
3915 lpfc_sli_brdrestart(phba);
3916 rc = lpfc_sli_chipset_init(phba);
3920 wwn = lpfc_get_wwpn(phba);
3923 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3924 if (wwn == lpfc_no_hba_reset[i]) {
3925 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3926 "6020 Setting use_no_reset port=%llx\n",
3928 use_no_reset_hba = true;
3933 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3934 if (dev != &phba->pcidev->dev) {
3935 shost = scsi_host_alloc(&lpfc_vport_template,
3936 sizeof(struct lpfc_vport));
3938 if (!use_no_reset_hba)
3939 shost = scsi_host_alloc(&lpfc_template,
3940 sizeof(struct lpfc_vport));
3942 shost = scsi_host_alloc(&lpfc_template_no_hr,
3943 sizeof(struct lpfc_vport));
3945 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3946 shost = scsi_host_alloc(&lpfc_template_nvme,
3947 sizeof(struct lpfc_vport));
3952 vport = (struct lpfc_vport *) shost->hostdata;
3954 vport->load_flag |= FC_LOADING;
3955 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3956 vport->fc_rscn_flush = 0;
3957 lpfc_get_vport_cfgparam(vport);
3959 shost->unique_id = instance;
3960 shost->max_id = LPFC_MAX_TARGET;
3961 shost->max_lun = vport->cfg_max_luns;
3962 shost->this_id = -1;
3963 shost->max_cmd_len = 16;
3964 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
3965 if (phba->sli_rev == LPFC_SLI_REV4) {
3966 shost->dma_boundary =
3967 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
3968 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3972 * Set initial can_queue value since 0 is no longer supported and
3973 * scsi_add_host will fail. This will be adjusted later based on the
3974 * max xri value determined in hba setup.
3976 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3977 if (dev != &phba->pcidev->dev) {
3978 shost->transportt = lpfc_vport_transport_template;
3979 vport->port_type = LPFC_NPIV_PORT;
3981 shost->transportt = lpfc_transport_template;
3982 vport->port_type = LPFC_PHYSICAL_PORT;
3985 /* Initialize all internally managed lists. */
3986 INIT_LIST_HEAD(&vport->fc_nodes);
3987 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3988 spin_lock_init(&vport->work_port_lock);
3990 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
3992 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
3994 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
3996 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
4000 spin_lock_irq(&phba->hbalock);
4001 list_add_tail(&vport->listentry, &phba->port_list);
4002 spin_unlock_irq(&phba->hbalock);
4006 scsi_host_put(shost);
4012 * destroy_port - destroy an FC port
4013 * @vport: pointer to an lpfc virtual N_Port data structure.
4015 * This routine destroys a FC port from the upper layer protocol. All the
4016 * resources associated with the port are released.
4019 destroy_port(struct lpfc_vport *vport)
4021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4022 struct lpfc_hba *phba = vport->phba;
4024 lpfc_debugfs_terminate(vport);
4025 fc_remove_host(shost);
4026 scsi_remove_host(shost);
4028 spin_lock_irq(&phba->hbalock);
4029 list_del_init(&vport->listentry);
4030 spin_unlock_irq(&phba->hbalock);
4032 lpfc_cleanup(vport);
4037 * lpfc_get_instance - Get a unique integer ID
4039 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4040 * uses the kernel idr facility to perform the task.
4043 * instance - a unique integer ID allocated as the new instance.
4044 * -1 - lpfc get instance failed.
4047 lpfc_get_instance(void)
4051 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4052 return ret < 0 ? -1 : ret;
4056 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4057 * @shost: pointer to SCSI host data structure.
4058 * @time: elapsed time of the scan in jiffies.
4060 * This routine is called by the SCSI layer with a SCSI host to determine
4061 * whether the scan host is finished.
4063 * Note: there is no scan_start function as adapter initialization will have
4064 * asynchronously kicked off the link initialization.
4067 * 0 - SCSI host scan is not over yet.
4068 * 1 - SCSI host scan is over.
4070 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4072 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4073 struct lpfc_hba *phba = vport->phba;
4076 spin_lock_irq(shost->host_lock);
4078 if (vport->load_flag & FC_UNLOADING) {
4082 if (time >= msecs_to_jiffies(30 * 1000)) {
4083 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4084 "0461 Scanning longer than 30 "
4085 "seconds. Continuing initialization\n");
4089 if (time >= msecs_to_jiffies(15 * 1000) &&
4090 phba->link_state <= LPFC_LINK_DOWN) {
4091 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4092 "0465 Link down longer than 15 "
4093 "seconds. Continuing initialization\n");
4098 if (vport->port_state != LPFC_VPORT_READY)
4100 if (vport->num_disc_nodes || vport->fc_prli_sent)
4102 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4104 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4110 spin_unlock_irq(shost->host_lock);
4115 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4116 * @shost: pointer to SCSI host data structure.
4118 * This routine initializes a given SCSI host attributes on a FC port. The
4119 * SCSI host can be either on top of a physical port or a virtual port.
4121 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4124 struct lpfc_hba *phba = vport->phba;
4126 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4129 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4130 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4131 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4133 memset(fc_host_supported_fc4s(shost), 0,
4134 sizeof(fc_host_supported_fc4s(shost)));
4135 fc_host_supported_fc4s(shost)[2] = 1;
4136 fc_host_supported_fc4s(shost)[7] = 1;
4138 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4139 sizeof fc_host_symbolic_name(shost));
4141 fc_host_supported_speeds(shost) = 0;
4142 if (phba->lmt & LMT_64Gb)
4143 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4144 if (phba->lmt & LMT_32Gb)
4145 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4146 if (phba->lmt & LMT_16Gb)
4147 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4148 if (phba->lmt & LMT_10Gb)
4149 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4150 if (phba->lmt & LMT_8Gb)
4151 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4152 if (phba->lmt & LMT_4Gb)
4153 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4154 if (phba->lmt & LMT_2Gb)
4155 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4156 if (phba->lmt & LMT_1Gb)
4157 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4159 fc_host_maxframe_size(shost) =
4160 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4161 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4163 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4165 /* This value is also unchanging */
4166 memset(fc_host_active_fc4s(shost), 0,
4167 sizeof(fc_host_active_fc4s(shost)));
4168 fc_host_active_fc4s(shost)[2] = 1;
4169 fc_host_active_fc4s(shost)[7] = 1;
4171 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4172 spin_lock_irq(shost->host_lock);
4173 vport->load_flag &= ~FC_LOADING;
4174 spin_unlock_irq(shost->host_lock);
4178 * lpfc_stop_port_s3 - Stop SLI3 device port
4179 * @phba: pointer to lpfc hba data structure.
4181 * This routine is invoked to stop an SLI3 device port, it stops the device
4182 * from generating interrupts and stops the device driver's timers for the
4186 lpfc_stop_port_s3(struct lpfc_hba *phba)
4188 /* Clear all interrupt enable conditions */
4189 writel(0, phba->HCregaddr);
4190 readl(phba->HCregaddr); /* flush */
4191 /* Clear all pending interrupts */
4192 writel(0xffffffff, phba->HAregaddr);
4193 readl(phba->HAregaddr); /* flush */
4195 /* Reset some HBA SLI setup states */
4196 lpfc_stop_hba_timers(phba);
4197 phba->pport->work_port_events = 0;
4201 * lpfc_stop_port_s4 - Stop SLI4 device port
4202 * @phba: pointer to lpfc hba data structure.
4204 * This routine is invoked to stop an SLI4 device port, it stops the device
4205 * from generating interrupts and stops the device driver's timers for the
4209 lpfc_stop_port_s4(struct lpfc_hba *phba)
4211 /* Reset some HBA SLI4 setup states */
4212 lpfc_stop_hba_timers(phba);
4213 phba->pport->work_port_events = 0;
4214 phba->sli4_hba.intr_enable = 0;
4218 * lpfc_stop_port - Wrapper function for stopping hba port
4219 * @phba: Pointer to HBA context object.
4221 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4222 * the API jump table function pointer from the lpfc_hba struct.
4225 lpfc_stop_port(struct lpfc_hba *phba)
4227 phba->lpfc_stop_port(phba);
4230 flush_workqueue(phba->wq);
4234 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4235 * @phba: Pointer to hba for which this call is being executed.
4237 * This routine starts the timer waiting for the FCF rediscovery to complete.
4240 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4242 unsigned long fcf_redisc_wait_tmo =
4243 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4244 /* Start fcf rediscovery wait period timer */
4245 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4246 spin_lock_irq(&phba->hbalock);
4247 /* Allow action to new fcf asynchronous event */
4248 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4249 /* Mark the FCF rediscovery pending state */
4250 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4251 spin_unlock_irq(&phba->hbalock);
4255 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4256 * @ptr: Map to lpfc_hba data structure pointer.
4258 * This routine is invoked when waiting for FCF table rediscover has been
4259 * timed out. If new FCF record(s) has (have) been discovered during the
4260 * wait period, a new FCF event shall be added to the FCOE async event
4261 * list, and then worker thread shall be waked up for processing from the
4262 * worker thread context.
4265 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
4267 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
4269 /* Don't send FCF rediscovery event if timer cancelled */
4270 spin_lock_irq(&phba->hbalock);
4271 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4272 spin_unlock_irq(&phba->hbalock);
4275 /* Clear FCF rediscovery timer pending flag */
4276 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4277 /* FCF rediscovery event to worker thread */
4278 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4279 spin_unlock_irq(&phba->hbalock);
4280 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4281 "2776 FCF rediscover quiescent timer expired\n");
4282 /* wake up worker thread */
4283 lpfc_worker_wake_up(phba);
4287 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4288 * @phba: pointer to lpfc hba data structure.
4289 * @acqe_link: pointer to the async link completion queue entry.
4291 * This routine is to parse the SLI4 link-attention link fault code.
4294 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4295 struct lpfc_acqe_link *acqe_link)
4297 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4298 case LPFC_ASYNC_LINK_FAULT_NONE:
4299 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4300 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4301 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
4304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4305 "0398 Unknown link fault code: x%x\n",
4306 bf_get(lpfc_acqe_link_fault, acqe_link));
4312 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4313 * @phba: pointer to lpfc hba data structure.
4314 * @acqe_link: pointer to the async link completion queue entry.
4316 * This routine is to parse the SLI4 link attention type and translate it
4317 * into the base driver's link attention type coding.
4319 * Return: Link attention type in terms of base driver's coding.
4322 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4323 struct lpfc_acqe_link *acqe_link)
4327 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4328 case LPFC_ASYNC_LINK_STATUS_DOWN:
4329 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
4330 att_type = LPFC_ATT_LINK_DOWN;
4332 case LPFC_ASYNC_LINK_STATUS_UP:
4333 /* Ignore physical link up events - wait for logical link up */
4334 att_type = LPFC_ATT_RESERVED;
4336 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
4337 att_type = LPFC_ATT_LINK_UP;
4340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4341 "0399 Invalid link attention type: x%x\n",
4342 bf_get(lpfc_acqe_link_status, acqe_link));
4343 att_type = LPFC_ATT_RESERVED;
4350 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4351 * @phba: pointer to lpfc hba data structure.
4353 * This routine is to get an SLI3 FC port's link speed in Mbps.
4355 * Return: link speed in terms of Mbps.
4358 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4360 uint32_t link_speed;
4362 if (!lpfc_is_link_up(phba))
4365 if (phba->sli_rev <= LPFC_SLI_REV3) {
4366 switch (phba->fc_linkspeed) {
4367 case LPFC_LINK_SPEED_1GHZ:
4370 case LPFC_LINK_SPEED_2GHZ:
4373 case LPFC_LINK_SPEED_4GHZ:
4376 case LPFC_LINK_SPEED_8GHZ:
4379 case LPFC_LINK_SPEED_10GHZ:
4382 case LPFC_LINK_SPEED_16GHZ:
4389 if (phba->sli4_hba.link_state.logical_speed)
4391 phba->sli4_hba.link_state.logical_speed;
4393 link_speed = phba->sli4_hba.link_state.speed;
4399 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4400 * @phba: pointer to lpfc hba data structure.
4401 * @evt_code: asynchronous event code.
4402 * @speed_code: asynchronous event link speed code.
4404 * This routine is to parse the giving SLI4 async event link speed code into
4405 * value of Mbps for the link speed.
4407 * Return: link speed in terms of Mbps.
4410 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4413 uint32_t port_speed;
4416 case LPFC_TRAILER_CODE_LINK:
4417 switch (speed_code) {
4418 case LPFC_ASYNC_LINK_SPEED_ZERO:
4421 case LPFC_ASYNC_LINK_SPEED_10MBPS:
4424 case LPFC_ASYNC_LINK_SPEED_100MBPS:
4427 case LPFC_ASYNC_LINK_SPEED_1GBPS:
4430 case LPFC_ASYNC_LINK_SPEED_10GBPS:
4433 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4436 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4439 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4446 case LPFC_TRAILER_CODE_FC:
4447 switch (speed_code) {
4448 case LPFC_FC_LA_SPEED_UNKNOWN:
4451 case LPFC_FC_LA_SPEED_1G:
4454 case LPFC_FC_LA_SPEED_2G:
4457 case LPFC_FC_LA_SPEED_4G:
4460 case LPFC_FC_LA_SPEED_8G:
4463 case LPFC_FC_LA_SPEED_10G:
4466 case LPFC_FC_LA_SPEED_16G:
4469 case LPFC_FC_LA_SPEED_32G:
4472 case LPFC_FC_LA_SPEED_64G:
4486 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4487 * @phba: pointer to lpfc hba data structure.
4488 * @acqe_link: pointer to the async link completion queue entry.
4490 * This routine is to handle the SLI4 asynchronous FCoE link event.
4493 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4494 struct lpfc_acqe_link *acqe_link)
4496 struct lpfc_dmabuf *mp;
4499 struct lpfc_mbx_read_top *la;
4503 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
4504 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
4506 phba->fcoe_eventtag = acqe_link->event_tag;
4507 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4509 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4510 "0395 The mboxq allocation failed\n");
4513 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4515 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4516 "0396 The lpfc_dmabuf allocation failed\n");
4519 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4521 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4522 "0397 The mbuf allocation failed\n");
4523 goto out_free_dmabuf;
4526 /* Cleanup any outstanding ELS commands */
4527 lpfc_els_flush_all_cmd(phba);
4529 /* Block ELS IOCBs until we have done process link event */
4530 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4532 /* Update link event statistics */
4533 phba->sli.slistat.link_event++;
4535 /* Create lpfc_handle_latt mailbox command from link ACQE */
4536 lpfc_read_topology(phba, pmb, mp);
4537 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4538 pmb->vport = phba->pport;
4540 /* Keep the link status for extra SLI4 state machine reference */
4541 phba->sli4_hba.link_state.speed =
4542 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4543 bf_get(lpfc_acqe_link_speed, acqe_link));
4544 phba->sli4_hba.link_state.duplex =
4545 bf_get(lpfc_acqe_link_duplex, acqe_link);
4546 phba->sli4_hba.link_state.status =
4547 bf_get(lpfc_acqe_link_status, acqe_link);
4548 phba->sli4_hba.link_state.type =
4549 bf_get(lpfc_acqe_link_type, acqe_link);
4550 phba->sli4_hba.link_state.number =
4551 bf_get(lpfc_acqe_link_number, acqe_link);
4552 phba->sli4_hba.link_state.fault =
4553 bf_get(lpfc_acqe_link_fault, acqe_link);
4554 phba->sli4_hba.link_state.logical_speed =
4555 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4557 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4558 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4559 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4560 "Logical speed:%dMbps Fault:%d\n",
4561 phba->sli4_hba.link_state.speed,
4562 phba->sli4_hba.link_state.topology,
4563 phba->sli4_hba.link_state.status,
4564 phba->sli4_hba.link_state.type,
4565 phba->sli4_hba.link_state.number,
4566 phba->sli4_hba.link_state.logical_speed,
4567 phba->sli4_hba.link_state.fault);
4569 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4570 * topology info. Note: Optional for non FC-AL ports.
4572 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4573 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4574 if (rc == MBX_NOT_FINISHED)
4575 goto out_free_dmabuf;
4579 * For FCoE Mode: fill in all the topology information we need and call
4580 * the READ_TOPOLOGY completion routine to continue without actually
4581 * sending the READ_TOPOLOGY mailbox command to the port.
4583 /* Initialize completion status */
4585 mb->mbxStatus = MBX_SUCCESS;
4587 /* Parse port fault information field */
4588 lpfc_sli4_parse_latt_fault(phba, acqe_link);
4590 /* Parse and translate link attention fields */
4591 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4592 la->eventTag = acqe_link->event_tag;
4593 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4594 bf_set(lpfc_mbx_read_top_link_spd, la,
4595 (bf_get(lpfc_acqe_link_speed, acqe_link)));
4597 /* Fake the the following irrelvant fields */
4598 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4599 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4600 bf_set(lpfc_mbx_read_top_il, la, 0);
4601 bf_set(lpfc_mbx_read_top_pb, la, 0);
4602 bf_set(lpfc_mbx_read_top_fa, la, 0);
4603 bf_set(lpfc_mbx_read_top_mm, la, 0);
4605 /* Invoke the lpfc_handle_latt mailbox command callback function */
4606 lpfc_mbx_cmpl_read_topology(phba, pmb);
4613 mempool_free(pmb, phba->mbox_mem_pool);
4617 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4618 * @phba: pointer to lpfc hba data structure.
4619 * @acqe_fc: pointer to the async fc completion queue entry.
4621 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4622 * that the event was received and then issue a read_topology mailbox command so
4623 * that the rest of the driver will treat it the same as SLI3.
4626 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4628 struct lpfc_dmabuf *mp;
4631 struct lpfc_mbx_read_top *la;
4634 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4635 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4636 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4637 "2895 Non FC link Event detected.(%d)\n",
4638 bf_get(lpfc_trailer_type, acqe_fc));
4641 /* Keep the link status for extra SLI4 state machine reference */
4642 phba->sli4_hba.link_state.speed =
4643 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4644 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4645 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4646 phba->sli4_hba.link_state.topology =
4647 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4648 phba->sli4_hba.link_state.status =
4649 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4650 phba->sli4_hba.link_state.type =
4651 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4652 phba->sli4_hba.link_state.number =
4653 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4654 phba->sli4_hba.link_state.fault =
4655 bf_get(lpfc_acqe_link_fault, acqe_fc);
4656 phba->sli4_hba.link_state.logical_speed =
4657 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
4658 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4659 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4660 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4661 "%dMbps Fault:%d\n",
4662 phba->sli4_hba.link_state.speed,
4663 phba->sli4_hba.link_state.topology,
4664 phba->sli4_hba.link_state.status,
4665 phba->sli4_hba.link_state.type,
4666 phba->sli4_hba.link_state.number,
4667 phba->sli4_hba.link_state.logical_speed,
4668 phba->sli4_hba.link_state.fault);
4669 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4671 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4672 "2897 The mboxq allocation failed\n");
4675 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4677 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4678 "2898 The lpfc_dmabuf allocation failed\n");
4681 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4684 "2899 The mbuf allocation failed\n");
4685 goto out_free_dmabuf;
4688 /* Cleanup any outstanding ELS commands */
4689 lpfc_els_flush_all_cmd(phba);
4691 /* Block ELS IOCBs until we have done process link event */
4692 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4694 /* Update link event statistics */
4695 phba->sli.slistat.link_event++;
4697 /* Create lpfc_handle_latt mailbox command from link ACQE */
4698 lpfc_read_topology(phba, pmb, mp);
4699 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4700 pmb->vport = phba->pport;
4702 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4703 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4705 switch (phba->sli4_hba.link_state.status) {
4706 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4707 phba->link_flag |= LS_MDS_LINK_DOWN;
4709 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4710 phba->link_flag |= LS_MDS_LOOPBACK;
4716 /* Initialize completion status */
4718 mb->mbxStatus = MBX_SUCCESS;
4720 /* Parse port fault information field */
4721 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
4723 /* Parse and translate link attention fields */
4724 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4725 la->eventTag = acqe_fc->event_tag;
4727 if (phba->sli4_hba.link_state.status ==
4728 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4729 bf_set(lpfc_mbx_read_top_att_type, la,
4730 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4732 bf_set(lpfc_mbx_read_top_att_type, la,
4733 LPFC_FC_LA_TYPE_LINK_DOWN);
4735 /* Invoke the mailbox command callback function */
4736 lpfc_mbx_cmpl_read_topology(phba, pmb);
4741 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4742 if (rc == MBX_NOT_FINISHED)
4743 goto out_free_dmabuf;
4749 mempool_free(pmb, phba->mbox_mem_pool);
4753 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4754 * @phba: pointer to lpfc hba data structure.
4755 * @acqe_fc: pointer to the async SLI completion queue entry.
4757 * This routine is to handle the SLI4 asynchronous SLI events.
4760 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4766 uint8_t operational = 0;
4767 struct temp_event temp_event_data;
4768 struct lpfc_acqe_misconfigured_event *misconfigured;
4769 struct Scsi_Host *shost;
4771 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4773 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4774 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4775 "x%08x SLI Event Type:%d\n",
4776 acqe_sli->event_data1, acqe_sli->event_data2,
4779 port_name = phba->Port[0];
4780 if (port_name == 0x00)
4781 port_name = '?'; /* get port name is empty */
4784 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4785 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4786 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4787 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4789 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4790 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4791 acqe_sli->event_data1, port_name);
4793 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
4794 shost = lpfc_shost_from_vport(phba->pport);
4795 fc_host_post_vendor_event(shost, fc_get_event_number(),
4796 sizeof(temp_event_data),
4797 (char *)&temp_event_data,
4798 SCSI_NL_VID_TYPE_PCI
4799 | PCI_VENDOR_ID_EMULEX);
4801 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4802 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4803 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4804 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4806 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4807 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4808 acqe_sli->event_data1, port_name);
4810 shost = lpfc_shost_from_vport(phba->pport);
4811 fc_host_post_vendor_event(shost, fc_get_event_number(),
4812 sizeof(temp_event_data),
4813 (char *)&temp_event_data,
4814 SCSI_NL_VID_TYPE_PCI
4815 | PCI_VENDOR_ID_EMULEX);
4817 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4818 misconfigured = (struct lpfc_acqe_misconfigured_event *)
4819 &acqe_sli->event_data1;
4821 /* fetch the status for this port */
4822 switch (phba->sli4_hba.lnk_info.lnk_no) {
4823 case LPFC_LINK_NUMBER_0:
4824 status = bf_get(lpfc_sli_misconfigured_port0_state,
4825 &misconfigured->theEvent);
4826 operational = bf_get(lpfc_sli_misconfigured_port0_op,
4827 &misconfigured->theEvent);
4829 case LPFC_LINK_NUMBER_1:
4830 status = bf_get(lpfc_sli_misconfigured_port1_state,
4831 &misconfigured->theEvent);
4832 operational = bf_get(lpfc_sli_misconfigured_port1_op,
4833 &misconfigured->theEvent);
4835 case LPFC_LINK_NUMBER_2:
4836 status = bf_get(lpfc_sli_misconfigured_port2_state,
4837 &misconfigured->theEvent);
4838 operational = bf_get(lpfc_sli_misconfigured_port2_op,
4839 &misconfigured->theEvent);
4841 case LPFC_LINK_NUMBER_3:
4842 status = bf_get(lpfc_sli_misconfigured_port3_state,
4843 &misconfigured->theEvent);
4844 operational = bf_get(lpfc_sli_misconfigured_port3_op,
4845 &misconfigured->theEvent);
4848 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4850 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4851 "event: Invalid link %d",
4852 phba->sli4_hba.lnk_info.lnk_no);
4856 /* Skip if optic state unchanged */
4857 if (phba->sli4_hba.lnk_info.optic_state == status)
4861 case LPFC_SLI_EVENT_STATUS_VALID:
4862 sprintf(message, "Physical Link is functional");
4864 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4865 sprintf(message, "Optics faulted/incorrectly "
4866 "installed/not installed - Reseat optics, "
4867 "if issue not resolved, replace.");
4869 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4871 "Optics of two types installed - Remove one "
4872 "optic or install matching pair of optics.");
4874 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4875 sprintf(message, "Incompatible optics - Replace with "
4876 "compatible optics for card to function.");
4878 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4879 sprintf(message, "Unqualified optics - Replace with "
4880 "Avago optics for Warranty and Technical "
4881 "Support - Link is%s operational",
4882 (operational) ? " not" : "");
4884 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4885 sprintf(message, "Uncertified optics - Replace with "
4886 "Avago-certified optics to enable link "
4887 "operation - Link is%s operational",
4888 (operational) ? " not" : "");
4891 /* firmware is reporting a status we don't know about */
4892 sprintf(message, "Unknown event status x%02x", status);
4895 phba->sli4_hba.lnk_info.optic_state = status;
4896 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4897 "3176 Port Name %c %s\n", port_name, message);
4899 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4900 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4901 "3192 Remote DPort Test Initiated - "
4902 "Event Data1:x%08x Event Data2: x%08x\n",
4903 acqe_sli->event_data1, acqe_sli->event_data2);
4906 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4907 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4908 "x%08x SLI Event Type:%d\n",
4909 acqe_sli->event_data1, acqe_sli->event_data2,
4916 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4917 * @vport: pointer to vport data structure.
4919 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4920 * response to a CVL event.
4922 * Return the pointer to the ndlp with the vport if successful, otherwise
4925 static struct lpfc_nodelist *
4926 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4928 struct lpfc_nodelist *ndlp;
4929 struct Scsi_Host *shost;
4930 struct lpfc_hba *phba;
4937 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4939 /* Cannot find existing Fabric ndlp, so allocate a new one */
4940 ndlp = lpfc_nlp_init(vport, Fabric_DID);
4943 /* Set the node type */
4944 ndlp->nlp_type |= NLP_FABRIC;
4945 /* Put ndlp onto node list */
4946 lpfc_enqueue_node(vport, ndlp);
4947 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4948 /* re-setup ndlp without removing from node list */
4949 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4953 if ((phba->pport->port_state < LPFC_FLOGI) &&
4954 (phba->pport->port_state != LPFC_VPORT_FAILED))
4956 /* If virtual link is not yet instantiated ignore CVL */
4957 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4958 && (vport->port_state != LPFC_VPORT_FAILED))
4960 shost = lpfc_shost_from_vport(vport);
4963 lpfc_linkdown_port(vport);
4964 lpfc_cleanup_pending_mbox(vport);
4965 spin_lock_irq(shost->host_lock);
4966 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4967 spin_unlock_irq(shost->host_lock);
4973 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4974 * @vport: pointer to lpfc hba data structure.
4976 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4977 * response to a FCF dead event.
4980 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4982 struct lpfc_vport **vports;
4985 vports = lpfc_create_vport_work_array(phba);
4987 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4988 lpfc_sli4_perform_vport_cvl(vports[i]);
4989 lpfc_destroy_vport_work_array(phba, vports);
4993 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4994 * @phba: pointer to lpfc hba data structure.
4995 * @acqe_link: pointer to the async fcoe completion queue entry.
4997 * This routine is to handle the SLI4 asynchronous fcoe event.
5000 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
5001 struct lpfc_acqe_fip *acqe_fip)
5003 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
5005 struct lpfc_vport *vport;
5006 struct lpfc_nodelist *ndlp;
5007 struct Scsi_Host *shost;
5008 int active_vlink_present;
5009 struct lpfc_vport **vports;
5012 phba->fc_eventTag = acqe_fip->event_tag;
5013 phba->fcoe_eventtag = acqe_fip->event_tag;
5014 switch (event_type) {
5015 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5016 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5017 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
5018 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5020 "2546 New FCF event, evt_tag:x%x, "
5022 acqe_fip->event_tag,
5025 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5027 "2788 FCF param modified event, "
5028 "evt_tag:x%x, index:x%x\n",
5029 acqe_fip->event_tag,
5031 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5033 * During period of FCF discovery, read the FCF
5034 * table record indexed by the event to update
5035 * FCF roundrobin failover eligible FCF bmask.
5037 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5039 "2779 Read FCF (x%x) for updating "
5040 "roundrobin FCF failover bmask\n",
5042 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
5045 /* If the FCF discovery is in progress, do nothing. */
5046 spin_lock_irq(&phba->hbalock);
5047 if (phba->hba_flag & FCF_TS_INPROG) {
5048 spin_unlock_irq(&phba->hbalock);
5051 /* If fast FCF failover rescan event is pending, do nothing */
5052 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
5053 spin_unlock_irq(&phba->hbalock);
5057 /* If the FCF has been in discovered state, do nothing. */
5058 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
5059 spin_unlock_irq(&phba->hbalock);
5062 spin_unlock_irq(&phba->hbalock);
5064 /* Otherwise, scan the entire FCF table and re-discover SAN */
5065 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5066 "2770 Start FCF table scan per async FCF "
5067 "event, evt_tag:x%x, index:x%x\n",
5068 acqe_fip->event_tag, acqe_fip->index);
5069 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5070 LPFC_FCOE_FCF_GET_FIRST);
5072 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5073 "2547 Issue FCF scan read FCF mailbox "
5074 "command failed (x%x)\n", rc);
5077 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
5078 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5079 "2548 FCF Table full count 0x%x tag 0x%x\n",
5080 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5081 acqe_fip->event_tag);
5084 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
5085 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5086 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5087 "2549 FCF (x%x) disconnected from network, "
5088 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
5090 * If we are in the middle of FCF failover process, clear
5091 * the corresponding FCF bit in the roundrobin bitmap.
5093 spin_lock_irq(&phba->hbalock);
5094 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5095 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
5096 spin_unlock_irq(&phba->hbalock);
5097 /* Update FLOGI FCF failover eligible FCF bmask */
5098 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
5101 spin_unlock_irq(&phba->hbalock);
5103 /* If the event is not for currently used fcf do nothing */
5104 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
5108 * Otherwise, request the port to rediscover the entire FCF
5109 * table for a fast recovery from case that the current FCF
5110 * is no longer valid as we are not in the middle of FCF
5111 * failover process already.
5113 spin_lock_irq(&phba->hbalock);
5114 /* Mark the fast failover process in progress */
5115 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5116 spin_unlock_irq(&phba->hbalock);
5118 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5119 "2771 Start FCF fast failover process due to "
5120 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5121 "\n", acqe_fip->event_tag, acqe_fip->index);
5122 rc = lpfc_sli4_redisc_fcf_table(phba);
5124 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5126 "2772 Issue FCF rediscover mailbox "
5127 "command failed, fail through to FCF "
5129 spin_lock_irq(&phba->hbalock);
5130 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5131 spin_unlock_irq(&phba->hbalock);
5133 * Last resort will fail over by treating this
5134 * as a link down to FCF registration.
5136 lpfc_sli4_fcf_dead_failthrough(phba);
5138 /* Reset FCF roundrobin bmask for new discovery */
5139 lpfc_sli4_clear_fcf_rr_bmask(phba);
5141 * Handling fast FCF failover to a DEAD FCF event is
5142 * considered equalivant to receiving CVL to all vports.
5144 lpfc_sli4_perform_all_vport_cvl(phba);
5147 case LPFC_FIP_EVENT_TYPE_CVL:
5148 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5149 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5150 "2718 Clear Virtual Link Received for VPI 0x%x"
5151 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
5153 vport = lpfc_find_vport_by_vpid(phba,
5155 ndlp = lpfc_sli4_perform_vport_cvl(vport);
5158 active_vlink_present = 0;
5160 vports = lpfc_create_vport_work_array(phba);
5162 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5164 if ((!(vports[i]->fc_flag &
5165 FC_VPORT_CVL_RCVD)) &&
5166 (vports[i]->port_state > LPFC_FDISC)) {
5167 active_vlink_present = 1;
5171 lpfc_destroy_vport_work_array(phba, vports);
5175 * Don't re-instantiate if vport is marked for deletion.
5176 * If we are here first then vport_delete is going to wait
5177 * for discovery to complete.
5179 if (!(vport->load_flag & FC_UNLOADING) &&
5180 active_vlink_present) {
5182 * If there are other active VLinks present,
5183 * re-instantiate the Vlink using FDISC.
5185 mod_timer(&ndlp->nlp_delayfunc,
5186 jiffies + msecs_to_jiffies(1000));
5187 shost = lpfc_shost_from_vport(vport);
5188 spin_lock_irq(shost->host_lock);
5189 ndlp->nlp_flag |= NLP_DELAY_TMO;
5190 spin_unlock_irq(shost->host_lock);
5191 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5192 vport->port_state = LPFC_FDISC;
5195 * Otherwise, we request port to rediscover
5196 * the entire FCF table for a fast recovery
5197 * from possible case that the current FCF
5198 * is no longer valid if we are not already
5199 * in the FCF failover process.
5201 spin_lock_irq(&phba->hbalock);
5202 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5203 spin_unlock_irq(&phba->hbalock);
5206 /* Mark the fast failover process in progress */
5207 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
5208 spin_unlock_irq(&phba->hbalock);
5209 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5211 "2773 Start FCF failover per CVL, "
5212 "evt_tag:x%x\n", acqe_fip->event_tag);
5213 rc = lpfc_sli4_redisc_fcf_table(phba);
5215 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5217 "2774 Issue FCF rediscover "
5218 "mailbox command failed, "
5219 "through to CVL event\n");
5220 spin_lock_irq(&phba->hbalock);
5221 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
5222 spin_unlock_irq(&phba->hbalock);
5224 * Last resort will be re-try on the
5225 * the current registered FCF entry.
5227 lpfc_retry_pport_discovery(phba);
5230 * Reset FCF roundrobin bmask for new
5233 lpfc_sli4_clear_fcf_rr_bmask(phba);
5237 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5238 "0288 Unknown FCoE event type 0x%x event tag "
5239 "0x%x\n", event_type, acqe_fip->event_tag);
5245 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5246 * @phba: pointer to lpfc hba data structure.
5247 * @acqe_link: pointer to the async dcbx completion queue entry.
5249 * This routine is to handle the SLI4 asynchronous dcbx event.
5252 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5253 struct lpfc_acqe_dcbx *acqe_dcbx)
5255 phba->fc_eventTag = acqe_dcbx->event_tag;
5256 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5257 "0290 The SLI4 DCBX asynchronous event is not "
5262 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5263 * @phba: pointer to lpfc hba data structure.
5264 * @acqe_link: pointer to the async grp5 completion queue entry.
5266 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5267 * is an asynchronous notified of a logical link speed change. The Port
5268 * reports the logical link speed in units of 10Mbps.
5271 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5272 struct lpfc_acqe_grp5 *acqe_grp5)
5274 uint16_t prev_ll_spd;
5276 phba->fc_eventTag = acqe_grp5->event_tag;
5277 phba->fcoe_eventtag = acqe_grp5->event_tag;
5278 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5279 phba->sli4_hba.link_state.logical_speed =
5280 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
5281 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5282 "2789 GRP5 Async Event: Updating logical link speed "
5283 "from %dMbps to %dMbps\n", prev_ll_spd,
5284 phba->sli4_hba.link_state.logical_speed);
5288 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5289 * @phba: pointer to lpfc hba data structure.
5291 * This routine is invoked by the worker thread to process all the pending
5292 * SLI4 asynchronous events.
5294 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5296 struct lpfc_cq_event *cq_event;
5298 /* First, declare the async event has been handled */
5299 spin_lock_irq(&phba->hbalock);
5300 phba->hba_flag &= ~ASYNC_EVENT;
5301 spin_unlock_irq(&phba->hbalock);
5302 /* Now, handle all the async events */
5303 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5304 /* Get the first event from the head of the event queue */
5305 spin_lock_irq(&phba->hbalock);
5306 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5307 cq_event, struct lpfc_cq_event, list);
5308 spin_unlock_irq(&phba->hbalock);
5309 /* Process the asynchronous event */
5310 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5311 case LPFC_TRAILER_CODE_LINK:
5312 lpfc_sli4_async_link_evt(phba,
5313 &cq_event->cqe.acqe_link);
5315 case LPFC_TRAILER_CODE_FCOE:
5316 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
5318 case LPFC_TRAILER_CODE_DCBX:
5319 lpfc_sli4_async_dcbx_evt(phba,
5320 &cq_event->cqe.acqe_dcbx);
5322 case LPFC_TRAILER_CODE_GRP5:
5323 lpfc_sli4_async_grp5_evt(phba,
5324 &cq_event->cqe.acqe_grp5);
5326 case LPFC_TRAILER_CODE_FC:
5327 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5329 case LPFC_TRAILER_CODE_SLI:
5330 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5333 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5334 "1804 Invalid asynchrous event code: "
5335 "x%x\n", bf_get(lpfc_trailer_code,
5336 &cq_event->cqe.mcqe_cmpl));
5339 /* Free the completion event processed to the free pool */
5340 lpfc_sli4_cq_event_release(phba, cq_event);
5345 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5346 * @phba: pointer to lpfc hba data structure.
5348 * This routine is invoked by the worker thread to process FCF table
5349 * rediscovery pending completion event.
5351 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5355 spin_lock_irq(&phba->hbalock);
5356 /* Clear FCF rediscovery timeout event */
5357 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5358 /* Clear driver fast failover FCF record flag */
5359 phba->fcf.failover_rec.flag = 0;
5360 /* Set state for FCF fast failover */
5361 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5362 spin_unlock_irq(&phba->hbalock);
5364 /* Scan FCF table from the first entry to re-discover SAN */
5365 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5366 "2777 Start post-quiescent FCF table scan\n");
5367 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5369 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5370 "2747 Issue FCF scan read FCF mailbox "
5371 "command failed 0x%x\n", rc);
5375 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5376 * @phba: pointer to lpfc hba data structure.
5377 * @dev_grp: The HBA PCI-Device group number.
5379 * This routine is invoked to set up the per HBA PCI-Device group function
5380 * API jump table entries.
5382 * Return: 0 if success, otherwise -ENODEV
5385 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5389 /* Set up lpfc PCI-device group */
5390 phba->pci_dev_grp = dev_grp;
5392 /* The LPFC_PCI_DEV_OC uses SLI4 */
5393 if (dev_grp == LPFC_PCI_DEV_OC)
5394 phba->sli_rev = LPFC_SLI_REV4;
5396 /* Set up device INIT API function jump table */
5397 rc = lpfc_init_api_table_setup(phba, dev_grp);
5400 /* Set up SCSI API function jump table */
5401 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5404 /* Set up SLI API function jump table */
5405 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5408 /* Set up MBOX API function jump table */
5409 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5417 * lpfc_log_intr_mode - Log the active interrupt mode
5418 * @phba: pointer to lpfc hba data structure.
5419 * @intr_mode: active interrupt mode adopted.
5421 * This routine it invoked to log the currently used active interrupt mode
5424 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
5426 switch (intr_mode) {
5428 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5429 "0470 Enable INTx interrupt mode.\n");
5432 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5433 "0481 Enabled MSI interrupt mode.\n");
5436 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5437 "0480 Enabled MSI-X interrupt mode.\n");
5440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5441 "0482 Illegal interrupt mode.\n");
5448 * lpfc_enable_pci_dev - Enable a generic PCI device.
5449 * @phba: pointer to lpfc hba data structure.
5451 * This routine is invoked to enable the PCI device that is common to all
5456 * other values - error
5459 lpfc_enable_pci_dev(struct lpfc_hba *phba)
5461 struct pci_dev *pdev;
5463 /* Obtain PCI device reference */
5467 pdev = phba->pcidev;
5468 /* Enable PCI device */
5469 if (pci_enable_device_mem(pdev))
5471 /* Request PCI resource for the device */
5472 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
5473 goto out_disable_device;
5474 /* Set up device as PCI master and save state for EEH */
5475 pci_set_master(pdev);
5476 pci_try_set_mwi(pdev);
5477 pci_save_state(pdev);
5479 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5480 if (pci_is_pcie(pdev))
5481 pdev->needs_freset = 1;
5486 pci_disable_device(pdev);
5488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5489 "1401 Failed to enable pci device\n");
5494 * lpfc_disable_pci_dev - Disable a generic PCI device.
5495 * @phba: pointer to lpfc hba data structure.
5497 * This routine is invoked to disable the PCI device that is common to all
5501 lpfc_disable_pci_dev(struct lpfc_hba *phba)
5503 struct pci_dev *pdev;
5505 /* Obtain PCI device reference */
5509 pdev = phba->pcidev;
5510 /* Release PCI resource and disable PCI device */
5511 pci_release_mem_regions(pdev);
5512 pci_disable_device(pdev);
5518 * lpfc_reset_hba - Reset a hba
5519 * @phba: pointer to lpfc hba data structure.
5521 * This routine is invoked to reset a hba device. It brings the HBA
5522 * offline, performs a board restart, and then brings the board back
5523 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5524 * on outstanding mailbox commands.
5527 lpfc_reset_hba(struct lpfc_hba *phba)
5529 /* If resets are disabled then set error state and return. */
5530 if (!phba->cfg_enable_hba_reset) {
5531 phba->link_state = LPFC_HBA_ERROR;
5534 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5535 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5537 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
5539 lpfc_sli_brdrestart(phba);
5541 lpfc_unblock_mgmt_io(phba);
5545 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5546 * @phba: pointer to lpfc hba data structure.
5548 * This function enables the PCI SR-IOV virtual functions to a physical
5549 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5550 * enable the number of virtual functions to the physical function. As
5551 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5552 * API call does not considered as an error condition for most of the device.
5555 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5557 struct pci_dev *pdev = phba->pcidev;
5561 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5565 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5570 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5571 * @phba: pointer to lpfc hba data structure.
5572 * @nr_vfn: number of virtual functions to be enabled.
5574 * This function enables the PCI SR-IOV virtual functions to a physical
5575 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5576 * enable the number of virtual functions to the physical function. As
5577 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5578 * API call does not considered as an error condition for most of the device.
5581 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5583 struct pci_dev *pdev = phba->pcidev;
5584 uint16_t max_nr_vfn;
5587 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5588 if (nr_vfn > max_nr_vfn) {
5589 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5590 "3057 Requested vfs (%d) greater than "
5591 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5595 rc = pci_enable_sriov(pdev, nr_vfn);
5597 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5598 "2806 Failed to enable sriov on this device "
5599 "with vfn number nr_vf:%d, rc:%d\n",
5602 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5603 "2807 Successful enable sriov on this device "
5604 "with vfn number nr_vf:%d\n", nr_vfn);
5609 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5610 * @phba: pointer to lpfc hba data structure.
5612 * This routine is invoked to set up the driver internal resources before the
5613 * device specific resource setup to support the HBA device it attached to.
5617 * other values - error
5620 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5622 struct lpfc_sli *psli = &phba->sli;
5625 * Driver resources common to all SLI revisions
5627 atomic_set(&phba->fast_event_count, 0);
5628 spin_lock_init(&phba->hbalock);
5630 /* Initialize ndlp management spinlock */
5631 spin_lock_init(&phba->ndlp_lock);
5633 INIT_LIST_HEAD(&phba->port_list);
5634 INIT_LIST_HEAD(&phba->work_list);
5635 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5637 /* Initialize the wait queue head for the kernel thread */
5638 init_waitqueue_head(&phba->work_waitq);
5640 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5641 "1403 Protocols supported %s %s %s\n",
5642 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5644 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5646 (phba->nvmet_support ? "NVMET" : " "));
5648 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5649 /* Initialize the scsi buffer list used by driver for scsi IO */
5650 spin_lock_init(&phba->scsi_buf_list_get_lock);
5651 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5652 spin_lock_init(&phba->scsi_buf_list_put_lock);
5653 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5656 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5657 (phba->nvmet_support == 0)) {
5658 /* Initialize the NVME buffer list used by driver for NVME IO */
5659 spin_lock_init(&phba->nvme_buf_list_get_lock);
5660 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5661 phba->get_nvme_bufs = 0;
5662 spin_lock_init(&phba->nvme_buf_list_put_lock);
5663 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5664 phba->put_nvme_bufs = 0;
5667 /* Initialize the fabric iocb list */
5668 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5670 /* Initialize list to save ELS buffers */
5671 INIT_LIST_HEAD(&phba->elsbuf);
5673 /* Initialize FCF connection rec list */
5674 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5676 /* Initialize OAS configuration list */
5677 spin_lock_init(&phba->devicelock);
5678 INIT_LIST_HEAD(&phba->luns);
5680 /* MBOX heartbeat timer */
5681 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
5682 /* Fabric block timer */
5683 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
5684 /* EA polling mode timer */
5685 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
5686 /* Heartbeat timer */
5687 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
5693 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5694 * @phba: pointer to lpfc hba data structure.
5696 * This routine is invoked to set up the driver internal resources specific to
5697 * support the SLI-3 HBA device it attached to.
5701 * other values - error
5704 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5709 * Initialize timers used by driver
5712 /* FCP polling mode timer */
5713 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
5715 /* Host attention work mask setup */
5716 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5717 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5719 /* Get all the module params for configuring this host */
5720 lpfc_get_cfgparam(phba);
5721 /* Set up phase-1 common device driver resources */
5723 rc = lpfc_setup_driver_resource_phase1(phba);
5727 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5728 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5729 /* check for menlo minimum sg count */
5730 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5731 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5734 if (!phba->sli.sli3_ring)
5735 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
5736 sizeof(struct lpfc_sli_ring),
5738 if (!phba->sli.sli3_ring)
5742 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5743 * used to create the sg_dma_buf_pool must be dynamically calculated.
5746 /* Initialize the host templates the configured values. */
5747 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5748 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5749 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5751 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5752 if (phba->cfg_enable_bg) {
5754 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5755 * the FCP rsp, and a BDE for each. Sice we have no control
5756 * over how many protection data segments the SCSI Layer
5757 * will hand us (ie: there could be one for every block
5758 * in the IO), we just allocate enough BDEs to accomidate
5759 * our max amount and we need to limit lpfc_sg_seg_cnt to
5760 * minimize the risk of running out.
5762 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5763 sizeof(struct fcp_rsp) +
5764 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5766 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5767 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5769 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5770 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5773 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5774 * the FCP rsp, a BDE for each, and a BDE for up to
5775 * cfg_sg_seg_cnt data segments.
5777 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5778 sizeof(struct fcp_rsp) +
5779 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5781 /* Total BDEs in BPL for scsi_sg_list */
5782 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5785 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5786 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5787 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5788 phba->cfg_total_seg_cnt);
5790 phba->max_vpi = LPFC_MAX_VPI;
5791 /* This will be set to correct value after config_port mbox */
5792 phba->max_vports = 0;
5795 * Initialize the SLI Layer to run with lpfc HBAs.
5797 lpfc_sli_setup(phba);
5798 lpfc_sli_queue_init(phba);
5800 /* Allocate device driver memory */
5801 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5805 * Enable sr-iov virtual functions if supported and configured
5806 * through the module parameter.
5808 if (phba->cfg_sriov_nr_virtfn > 0) {
5809 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5810 phba->cfg_sriov_nr_virtfn);
5812 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5813 "2808 Requested number of SR-IOV "
5814 "virtual functions (%d) is not "
5816 phba->cfg_sriov_nr_virtfn);
5817 phba->cfg_sriov_nr_virtfn = 0;
5825 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5826 * @phba: pointer to lpfc hba data structure.
5828 * This routine is invoked to unset the driver internal resources set up
5829 * specific for supporting the SLI-3 HBA device it attached to.
5832 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5834 /* Free device driver memory allocated */
5835 lpfc_mem_free_all(phba);
5841 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5842 * @phba: pointer to lpfc hba data structure.
5844 * This routine is invoked to set up the driver internal resources specific to
5845 * support the SLI-4 HBA device it attached to.
5849 * other values - error
5852 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5854 LPFC_MBOXQ_t *mboxq;
5856 int rc, i, max_buf_size;
5858 int fof_vectors = 0;
5864 phba->sli4_hba.num_online_cpu = num_online_cpus();
5865 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5866 phba->sli4_hba.curr_disp_cpu = 0;
5868 /* Get all the module params for configuring this host */
5869 lpfc_get_cfgparam(phba);
5871 /* Set up phase-1 common device driver resources */
5872 rc = lpfc_setup_driver_resource_phase1(phba);
5876 /* Before proceed, wait for POST done and device ready */
5877 rc = lpfc_sli4_post_status_check(phba);
5882 * Initialize timers used by driver
5885 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
5887 /* FCF rediscover timer */
5888 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
5891 * Control structure for handling external multi-buffer mailbox
5892 * command pass-through.
5894 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5895 sizeof(struct lpfc_mbox_ext_buf_ctx));
5896 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5898 phba->max_vpi = LPFC_MAX_VPI;
5900 /* This will be set to correct value after the read_config mbox */
5901 phba->max_vports = 0;
5903 /* Program the default value of vlan_id and fc_map */
5904 phba->valid_vlan = 0;
5905 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5906 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5907 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5910 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5911 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5912 * The WQ create will allocate the ring.
5916 * 1 for cmd, 1 for rsp, NVME adds an extra one
5917 * for boundary conditions in its max_sgl_segment template.
5920 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5924 * It doesn't matter what family our adapter is in, we are
5925 * limited to 2 Pages, 512 SGEs, for our SGL.
5926 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5928 max_buf_size = (2 * SLI4_PAGE_SIZE);
5929 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra)
5930 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra;
5933 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5934 * used to create the sg_dma_buf_pool must be calculated.
5936 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5938 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5939 * the FCP rsp, and a SGE. Sice we have no control
5940 * over how many protection segments the SCSI Layer
5941 * will hand us (ie: there could be one for every block
5942 * in the IO), just allocate enough SGEs to accomidate
5943 * our max amount and we need to limit lpfc_sg_seg_cnt
5944 * to minimize the risk of running out.
5946 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5947 sizeof(struct fcp_rsp) + max_buf_size;
5949 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5950 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5952 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5953 phba->cfg_sg_seg_cnt =
5954 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5957 * The scsi_buf for a regular I/O holds the FCP cmnd,
5958 * the FCP rsp, a SGE for each, and a SGE for up to
5959 * cfg_sg_seg_cnt data segments.
5961 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5962 sizeof(struct fcp_rsp) +
5963 ((phba->cfg_sg_seg_cnt + extra) *
5964 sizeof(struct sli4_sge));
5966 /* Total SGEs for scsi_sg_list */
5967 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
5970 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
5971 * need to post 1 page for the SGL.
5975 /* Initialize the host templates with the updated values. */
5976 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5977 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5978 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5980 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5981 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5983 phba->cfg_sg_dma_buf_size =
5984 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5986 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5987 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5988 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5989 phba->cfg_total_seg_cnt);
5991 /* Initialize buffer queue management fields */
5992 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
5993 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5994 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5997 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5999 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6000 /* Initialize the Abort scsi buffer list used by driver */
6001 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6002 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6005 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6006 /* Initialize the Abort nvme buffer list used by driver */
6007 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
6008 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
6009 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6010 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
6013 /* This abort list used by worker thread */
6014 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
6015 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
6018 * Initialize driver internal slow-path work queues
6021 /* Driver internel slow-path CQ Event pool */
6022 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6023 /* Response IOCB work queue list */
6024 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
6025 /* Asynchronous event CQ Event work queue list */
6026 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6027 /* Fast-path XRI aborted CQ Event work queue list */
6028 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6029 /* Slow-path XRI aborted CQ Event work queue list */
6030 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6031 /* Receive queue CQ Event work queue list */
6032 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6034 /* Initialize extent block lists. */
6035 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6036 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6037 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6038 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6040 /* Initialize mboxq lists. If the early init routines fail
6041 * these lists need to be correctly initialized.
6043 INIT_LIST_HEAD(&phba->sli.mboxq);
6044 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6046 /* initialize optic_state to 0xFF */
6047 phba->sli4_hba.lnk_info.optic_state = 0xff;
6049 /* Allocate device driver memory */
6050 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6054 /* IF Type 2 ports get initialized now. */
6055 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
6056 LPFC_SLI_INTF_IF_TYPE_2) {
6057 rc = lpfc_pci_function_reset(phba);
6062 phba->temp_sensor_support = 1;
6065 /* Create the bootstrap mailbox command */
6066 rc = lpfc_create_bootstrap_mbox(phba);
6070 /* Set up the host's endian order with the device. */
6071 rc = lpfc_setup_endian_order(phba);
6073 goto out_free_bsmbx;
6075 /* Set up the hba's configuration parameters. */
6076 rc = lpfc_sli4_read_config(phba);
6078 goto out_free_bsmbx;
6079 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6081 goto out_free_bsmbx;
6083 /* IF Type 0 ports get initialized now. */
6084 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6085 LPFC_SLI_INTF_IF_TYPE_0) {
6086 rc = lpfc_pci_function_reset(phba);
6088 goto out_free_bsmbx;
6091 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6095 goto out_free_bsmbx;
6098 /* Check for NVMET being configured */
6099 phba->nvmet_support = 0;
6100 if (lpfc_enable_nvmet_cnt) {
6102 /* First get WWN of HBA instance */
6103 lpfc_read_nv(phba, mboxq);
6104 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6105 if (rc != MBX_SUCCESS) {
6106 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6107 "6016 Mailbox failed , mbxCmd x%x "
6108 "READ_NV, mbxStatus x%x\n",
6109 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6110 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
6111 mempool_free(mboxq, phba->mbox_mem_pool);
6113 goto out_free_bsmbx;
6116 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6118 wwn = cpu_to_be64(wwn);
6119 phba->sli4_hba.wwnn.u.name = wwn;
6120 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6122 /* wwn is WWPN of HBA instance */
6123 wwn = cpu_to_be64(wwn);
6124 phba->sli4_hba.wwpn.u.name = wwn;
6126 /* Check to see if it matches any module parameter */
6127 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6128 if (wwn == lpfc_enable_nvmet[i]) {
6129 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
6130 if (lpfc_nvmet_mem_alloc(phba))
6133 phba->nvmet_support = 1; /* a match */
6135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6136 "6017 NVME Target %016llx\n",
6139 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6140 "6021 Can't enable NVME Target."
6141 " NVME_TARGET_FC infrastructure"
6142 " is not in kernel\n");
6149 lpfc_nvme_mod_param_dep(phba);
6152 * Get sli4 parameters that override parameters from Port capabilities.
6153 * If this call fails, it isn't critical unless the SLI4 parameters come
6156 rc = lpfc_get_sli4_parameters(phba, mboxq);
6158 if_type = bf_get(lpfc_sli_intf_if_type,
6159 &phba->sli4_hba.sli_intf);
6160 if_fam = bf_get(lpfc_sli_intf_sli_family,
6161 &phba->sli4_hba.sli_intf);
6162 if (phba->sli4_hba.extents_in_use &&
6163 phba->sli4_hba.rpi_hdrs_in_use) {
6164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6165 "2999 Unsupported SLI4 Parameters "
6166 "Extents and RPI headers enabled.\n");
6167 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6168 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6169 mempool_free(mboxq, phba->mbox_mem_pool);
6171 goto out_free_bsmbx;
6174 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6175 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6176 mempool_free(mboxq, phba->mbox_mem_pool);
6178 goto out_free_bsmbx;
6182 mempool_free(mboxq, phba->mbox_mem_pool);
6184 /* Verify OAS is supported */
6185 lpfc_sli4_oas_verify(phba);
6189 /* Verify all the SLI4 queues */
6190 rc = lpfc_sli4_queue_verify(phba);
6192 goto out_free_bsmbx;
6194 /* Create driver internal CQE event pool */
6195 rc = lpfc_sli4_cq_event_pool_create(phba);
6197 goto out_free_bsmbx;
6199 /* Initialize sgl lists per host */
6200 lpfc_init_sgl_list(phba);
6202 /* Allocate and initialize active sgl array */
6203 rc = lpfc_init_active_sgl_array(phba);
6205 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6206 "1430 Failed to initialize sgl list.\n");
6207 goto out_destroy_cq_event_pool;
6209 rc = lpfc_sli4_init_rpi_hdrs(phba);
6211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6212 "1432 Failed to initialize rpi headers.\n");
6213 goto out_free_active_sgl;
6216 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
6217 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6218 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
6220 if (!phba->fcf.fcf_rr_bmask) {
6221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6222 "2759 Failed allocate memory for FCF round "
6223 "robin failover bmask\n");
6225 goto out_remove_rpi_hdrs;
6228 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6229 sizeof(struct lpfc_hba_eq_hdl),
6231 if (!phba->sli4_hba.hba_eq_hdl) {
6232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6233 "2572 Failed allocate memory for "
6234 "fast-path per-EQ handle array\n");
6236 goto out_free_fcf_rr_bmask;
6239 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6240 sizeof(struct lpfc_vector_map_info),
6242 if (!phba->sli4_hba.cpu_map) {
6243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6244 "3327 Failed allocate memory for msi-x "
6245 "interrupt vector mapping\n");
6247 goto out_free_hba_eq_hdl;
6249 if (lpfc_used_cpu == NULL) {
6250 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6252 if (!lpfc_used_cpu) {
6253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6254 "3335 Failed allocate memory for msi-x "
6255 "interrupt vector mapping\n");
6256 kfree(phba->sli4_hba.cpu_map);
6258 goto out_free_hba_eq_hdl;
6260 for (i = 0; i < lpfc_present_cpu; i++)
6261 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6265 * Enable sr-iov virtual functions if supported and configured
6266 * through the module parameter.
6268 if (phba->cfg_sriov_nr_virtfn > 0) {
6269 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6270 phba->cfg_sriov_nr_virtfn);
6272 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6273 "3020 Requested number of SR-IOV "
6274 "virtual functions (%d) is not "
6276 phba->cfg_sriov_nr_virtfn);
6277 phba->cfg_sriov_nr_virtfn = 0;
6283 out_free_hba_eq_hdl:
6284 kfree(phba->sli4_hba.hba_eq_hdl);
6285 out_free_fcf_rr_bmask:
6286 kfree(phba->fcf.fcf_rr_bmask);
6287 out_remove_rpi_hdrs:
6288 lpfc_sli4_remove_rpi_hdrs(phba);
6289 out_free_active_sgl:
6290 lpfc_free_active_sgl(phba);
6291 out_destroy_cq_event_pool:
6292 lpfc_sli4_cq_event_pool_destroy(phba);
6294 lpfc_destroy_bootstrap_mbox(phba);
6296 lpfc_mem_free(phba);
6301 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6302 * @phba: pointer to lpfc hba data structure.
6304 * This routine is invoked to unset the driver internal resources set up
6305 * specific for supporting the SLI-4 HBA device it attached to.
6308 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6310 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6312 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6313 kfree(phba->sli4_hba.cpu_map);
6314 phba->sli4_hba.num_present_cpu = 0;
6315 phba->sli4_hba.num_online_cpu = 0;
6316 phba->sli4_hba.curr_disp_cpu = 0;
6318 /* Free memory allocated for fast-path work queue handles */
6319 kfree(phba->sli4_hba.hba_eq_hdl);
6321 /* Free the allocated rpi headers. */
6322 lpfc_sli4_remove_rpi_hdrs(phba);
6323 lpfc_sli4_remove_rpis(phba);
6325 /* Free eligible FCF index bmask */
6326 kfree(phba->fcf.fcf_rr_bmask);
6328 /* Free the ELS sgl list */
6329 lpfc_free_active_sgl(phba);
6330 lpfc_free_els_sgl_list(phba);
6331 lpfc_free_nvmet_sgl_list(phba);
6333 /* Free the completion queue EQ event pool */
6334 lpfc_sli4_cq_event_release_all(phba);
6335 lpfc_sli4_cq_event_pool_destroy(phba);
6337 /* Release resource identifiers. */
6338 lpfc_sli4_dealloc_resource_identifiers(phba);
6340 /* Free the bsmbx region. */
6341 lpfc_destroy_bootstrap_mbox(phba);
6343 /* Free the SLI Layer memory with SLI4 HBAs */
6344 lpfc_mem_free_all(phba);
6346 /* Free the current connect table */
6347 list_for_each_entry_safe(conn_entry, next_conn_entry,
6348 &phba->fcf_conn_rec_list, list) {
6349 list_del_init(&conn_entry->list);
6357 * lpfc_init_api_table_setup - Set up init api function jump table
6358 * @phba: The hba struct for which this call is being executed.
6359 * @dev_grp: The HBA PCI-Device group number.
6361 * This routine sets up the device INIT interface API function jump table
6364 * Returns: 0 - success, -ENODEV - failure.
6367 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6369 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6370 phba->lpfc_hba_down_link = lpfc_hba_down_link;
6371 phba->lpfc_selective_reset = lpfc_selective_reset;
6373 case LPFC_PCI_DEV_LP:
6374 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6375 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6376 phba->lpfc_stop_port = lpfc_stop_port_s3;
6378 case LPFC_PCI_DEV_OC:
6379 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6380 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6381 phba->lpfc_stop_port = lpfc_stop_port_s4;
6384 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6385 "1431 Invalid HBA PCI-device group: 0x%x\n",
6394 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6395 * @phba: pointer to lpfc hba data structure.
6397 * This routine is invoked to set up the driver internal resources after the
6398 * device specific resource setup to support the HBA device it attached to.
6402 * other values - error
6405 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6409 /* Startup the kernel thread for this host adapter. */
6410 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6411 "lpfc_worker_%d", phba->brd_no);
6412 if (IS_ERR(phba->worker_thread)) {
6413 error = PTR_ERR(phba->worker_thread);
6417 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6418 if (phba->sli_rev == LPFC_SLI_REV4)
6419 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6427 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6428 * @phba: pointer to lpfc hba data structure.
6430 * This routine is invoked to unset the driver internal resources set up after
6431 * the device specific resource setup for supporting the HBA device it
6435 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6438 flush_workqueue(phba->wq);
6439 destroy_workqueue(phba->wq);
6443 /* Stop kernel worker thread */
6444 if (phba->worker_thread)
6445 kthread_stop(phba->worker_thread);
6449 * lpfc_free_iocb_list - Free iocb list.
6450 * @phba: pointer to lpfc hba data structure.
6452 * This routine is invoked to free the driver's IOCB list and memory.
6455 lpfc_free_iocb_list(struct lpfc_hba *phba)
6457 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6459 spin_lock_irq(&phba->hbalock);
6460 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6461 &phba->lpfc_iocb_list, list) {
6462 list_del(&iocbq_entry->list);
6464 phba->total_iocbq_bufs--;
6466 spin_unlock_irq(&phba->hbalock);
6472 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6473 * @phba: pointer to lpfc hba data structure.
6475 * This routine is invoked to allocate and initizlize the driver's IOCB
6476 * list and set up the IOCB tag array accordingly.
6480 * other values - error
6483 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6485 struct lpfc_iocbq *iocbq_entry = NULL;
6489 /* Initialize and populate the iocb list per host. */
6490 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
6491 for (i = 0; i < iocb_count; i++) {
6492 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
6493 if (iocbq_entry == NULL) {
6494 printk(KERN_ERR "%s: only allocated %d iocbs of "
6495 "expected %d count. Unloading driver.\n",
6496 __func__, i, LPFC_IOCB_LIST_CNT);
6497 goto out_free_iocbq;
6500 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6503 printk(KERN_ERR "%s: failed to allocate IOTAG. "
6504 "Unloading driver.\n", __func__);
6505 goto out_free_iocbq;
6507 iocbq_entry->sli4_lxritag = NO_XRI;
6508 iocbq_entry->sli4_xritag = NO_XRI;
6510 spin_lock_irq(&phba->hbalock);
6511 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6512 phba->total_iocbq_bufs++;
6513 spin_unlock_irq(&phba->hbalock);
6519 lpfc_free_iocb_list(phba);
6525 * lpfc_free_sgl_list - Free a given sgl list.
6526 * @phba: pointer to lpfc hba data structure.
6527 * @sglq_list: pointer to the head of sgl list.
6529 * This routine is invoked to free a give sgl list and memory.
6532 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
6534 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6536 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6537 list_del(&sglq_entry->list);
6538 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6544 * lpfc_free_els_sgl_list - Free els sgl list.
6545 * @phba: pointer to lpfc hba data structure.
6547 * This routine is invoked to free the driver's els sgl list and memory.
6550 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6552 LIST_HEAD(sglq_list);
6554 /* Retrieve all els sgls from driver list */
6555 spin_lock_irq(&phba->hbalock);
6556 spin_lock(&phba->sli4_hba.sgl_list_lock);
6557 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6558 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6559 spin_unlock_irq(&phba->hbalock);
6561 /* Now free the sgl list */
6562 lpfc_free_sgl_list(phba, &sglq_list);
6566 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6567 * @phba: pointer to lpfc hba data structure.
6569 * This routine is invoked to free the driver's nvmet sgl list and memory.
6572 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6574 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6575 LIST_HEAD(sglq_list);
6577 /* Retrieve all nvmet sgls from driver list */
6578 spin_lock_irq(&phba->hbalock);
6579 spin_lock(&phba->sli4_hba.sgl_list_lock);
6580 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6581 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6582 spin_unlock_irq(&phba->hbalock);
6584 /* Now free the sgl list */
6585 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6586 list_del(&sglq_entry->list);
6587 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6591 /* Update the nvmet_xri_cnt to reflect no current sgls.
6592 * The next initialization cycle sets the count and allocates
6593 * the sgls over again.
6595 phba->sli4_hba.nvmet_xri_cnt = 0;
6599 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6600 * @phba: pointer to lpfc hba data structure.
6602 * This routine is invoked to allocate the driver's active sgl memory.
6603 * This array will hold the sglq_entry's for active IOs.
6606 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6609 size = sizeof(struct lpfc_sglq *);
6610 size *= phba->sli4_hba.max_cfg_param.max_xri;
6612 phba->sli4_hba.lpfc_sglq_active_list =
6613 kzalloc(size, GFP_KERNEL);
6614 if (!phba->sli4_hba.lpfc_sglq_active_list)
6620 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6621 * @phba: pointer to lpfc hba data structure.
6623 * This routine is invoked to walk through the array of active sglq entries
6624 * and free all of the resources.
6625 * This is just a place holder for now.
6628 lpfc_free_active_sgl(struct lpfc_hba *phba)
6630 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6634 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6635 * @phba: pointer to lpfc hba data structure.
6637 * This routine is invoked to allocate and initizlize the driver's sgl
6638 * list and set up the sgl xritag tag array accordingly.
6642 lpfc_init_sgl_list(struct lpfc_hba *phba)
6644 /* Initialize and populate the sglq list per host/VF. */
6645 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
6646 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6647 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6648 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6650 /* els xri-sgl book keeping */
6651 phba->sli4_hba.els_xri_cnt = 0;
6653 /* scsi xri-buffer book keeping */
6654 phba->sli4_hba.scsi_xri_cnt = 0;
6656 /* nvme xri-buffer book keeping */
6657 phba->sli4_hba.nvme_xri_cnt = 0;
6661 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6662 * @phba: pointer to lpfc hba data structure.
6664 * This routine is invoked to post rpi header templates to the
6665 * port for those SLI4 ports that do not support extents. This routine
6666 * posts a PAGE_SIZE memory region to the port to hold up to
6667 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6668 * and should be called only when interrupts are disabled.
6672 * -ERROR - otherwise.
6675 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6678 struct lpfc_rpi_hdr *rpi_hdr;
6680 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
6681 if (!phba->sli4_hba.rpi_hdrs_in_use)
6683 if (phba->sli4_hba.extents_in_use)
6686 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6688 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6689 "0391 Error during rpi post operation\n");
6690 lpfc_sli4_remove_rpis(phba);
6698 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6699 * @phba: pointer to lpfc hba data structure.
6701 * This routine is invoked to allocate a single 4KB memory region to
6702 * support rpis and stores them in the phba. This single region
6703 * provides support for up to 64 rpis. The region is used globally
6707 * A valid rpi hdr on success.
6708 * A NULL pointer on any failure.
6710 struct lpfc_rpi_hdr *
6711 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6713 uint16_t rpi_limit, curr_rpi_range;
6714 struct lpfc_dmabuf *dmabuf;
6715 struct lpfc_rpi_hdr *rpi_hdr;
6718 * If the SLI4 port supports extents, posting the rpi header isn't
6719 * required. Set the expected maximum count and let the actual value
6720 * get set when extents are fully allocated.
6722 if (!phba->sli4_hba.rpi_hdrs_in_use)
6724 if (phba->sli4_hba.extents_in_use)
6727 /* The limit on the logical index is just the max_rpi count. */
6728 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
6730 spin_lock_irq(&phba->hbalock);
6732 * Establish the starting RPI in this header block. The starting
6733 * rpi is normalized to a zero base because the physical rpi is
6736 curr_rpi_range = phba->sli4_hba.next_rpi;
6737 spin_unlock_irq(&phba->hbalock);
6739 /* Reached full RPI range */
6740 if (curr_rpi_range == rpi_limit)
6744 * First allocate the protocol header region for the port. The
6745 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6747 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6751 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6752 LPFC_HDR_TEMPLATE_SIZE,
6753 &dmabuf->phys, GFP_KERNEL);
6754 if (!dmabuf->virt) {
6756 goto err_free_dmabuf;
6759 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6761 goto err_free_coherent;
6764 /* Save the rpi header data for cleanup later. */
6765 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6767 goto err_free_coherent;
6769 rpi_hdr->dmabuf = dmabuf;
6770 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6771 rpi_hdr->page_count = 1;
6772 spin_lock_irq(&phba->hbalock);
6774 /* The rpi_hdr stores the logical index only. */
6775 rpi_hdr->start_rpi = curr_rpi_range;
6776 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
6777 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6779 spin_unlock_irq(&phba->hbalock);
6783 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6784 dmabuf->virt, dmabuf->phys);
6791 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6792 * @phba: pointer to lpfc hba data structure.
6794 * This routine is invoked to remove all memory resources allocated
6795 * to support rpis for SLI4 ports not supporting extents. This routine
6796 * presumes the caller has released all rpis consumed by fabric or port
6797 * logins and is prepared to have the header pages removed.
6800 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6802 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6804 if (!phba->sli4_hba.rpi_hdrs_in_use)
6807 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6808 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6809 list_del(&rpi_hdr->list);
6810 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6811 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6812 kfree(rpi_hdr->dmabuf);
6816 /* There are no rpis available to the port now. */
6817 phba->sli4_hba.next_rpi = 0;
6821 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6822 * @pdev: pointer to pci device data structure.
6824 * This routine is invoked to allocate the driver hba data structure for an
6825 * HBA device. If the allocation is successful, the phba reference to the
6826 * PCI device data structure is set.
6829 * pointer to @phba - successful
6832 static struct lpfc_hba *
6833 lpfc_hba_alloc(struct pci_dev *pdev)
6835 struct lpfc_hba *phba;
6837 /* Allocate memory for HBA structure */
6838 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6840 dev_err(&pdev->dev, "failed to allocate hba struct\n");
6844 /* Set reference to PCI device in HBA structure */
6845 phba->pcidev = pdev;
6847 /* Assign an unused board number */
6848 phba->brd_no = lpfc_get_instance();
6849 if (phba->brd_no < 0) {
6853 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
6855 spin_lock_init(&phba->ct_ev_lock);
6856 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6862 * lpfc_hba_free - Free driver hba data structure with a device.
6863 * @phba: pointer to lpfc hba data structure.
6865 * This routine is invoked to free the driver hba data structure with an
6869 lpfc_hba_free(struct lpfc_hba *phba)
6871 /* Release the driver assigned board number */
6872 idr_remove(&lpfc_hba_index, phba->brd_no);
6874 /* Free memory allocated with sli3 rings */
6875 kfree(phba->sli.sli3_ring);
6876 phba->sli.sli3_ring = NULL;
6883 * lpfc_create_shost - Create hba physical port with associated scsi host.
6884 * @phba: pointer to lpfc hba data structure.
6886 * This routine is invoked to create HBA physical port and associate a SCSI
6891 * other values - error
6894 lpfc_create_shost(struct lpfc_hba *phba)
6896 struct lpfc_vport *vport;
6897 struct Scsi_Host *shost;
6899 /* Initialize HBA FC structure */
6900 phba->fc_edtov = FF_DEF_EDTOV;
6901 phba->fc_ratov = FF_DEF_RATOV;
6902 phba->fc_altov = FF_DEF_ALTOV;
6903 phba->fc_arbtov = FF_DEF_ARBTOV;
6905 atomic_set(&phba->sdev_cnt, 0);
6906 atomic_set(&phba->fc4ScsiInputRequests, 0);
6907 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6908 atomic_set(&phba->fc4ScsiControlRequests, 0);
6909 atomic_set(&phba->fc4ScsiIoCmpls, 0);
6910 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
6914 shost = lpfc_shost_from_vport(vport);
6915 phba->pport = vport;
6917 if (phba->nvmet_support) {
6918 /* Only 1 vport (pport) will support NVME target */
6919 if (phba->txrdy_payload_pool == NULL) {
6920 phba->txrdy_payload_pool = dma_pool_create(
6921 "txrdy_pool", &phba->pcidev->dev,
6922 TXRDY_PAYLOAD_LEN, 16, 0);
6923 if (phba->txrdy_payload_pool) {
6924 phba->targetport = NULL;
6925 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6926 lpfc_printf_log(phba, KERN_INFO,
6927 LOG_INIT | LOG_NVME_DISC,
6928 "6076 NVME Target Found\n");
6933 lpfc_debugfs_initialize(vport);
6934 /* Put reference to SCSI host to driver's device private data */
6935 pci_set_drvdata(phba->pcidev, shost);
6938 * At this point we are fully registered with PSA. In addition,
6939 * any initial discovery should be completed.
6941 vport->load_flag |= FC_ALLOW_FDMI;
6942 if (phba->cfg_enable_SmartSAN ||
6943 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
6945 /* Setup appropriate attribute masks */
6946 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
6947 if (phba->cfg_enable_SmartSAN)
6948 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6950 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6956 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6957 * @phba: pointer to lpfc hba data structure.
6959 * This routine is invoked to destroy HBA physical port and the associated
6963 lpfc_destroy_shost(struct lpfc_hba *phba)
6965 struct lpfc_vport *vport = phba->pport;
6967 /* Destroy physical port that associated with the SCSI host */
6968 destroy_port(vport);
6974 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6975 * @phba: pointer to lpfc hba data structure.
6976 * @shost: the shost to be used to detect Block guard settings.
6978 * This routine sets up the local Block guard protocol settings for @shost.
6979 * This routine also allocates memory for debugging bg buffers.
6982 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6988 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6989 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6990 "1478 Registering BlockGuard with the "
6993 old_mask = phba->cfg_prot_mask;
6994 old_guard = phba->cfg_prot_guard;
6996 /* Only allow supported values */
6997 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6998 SHOST_DIX_TYPE0_PROTECTION |
6999 SHOST_DIX_TYPE1_PROTECTION);
7000 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7001 SHOST_DIX_GUARD_CRC);
7003 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
7004 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7005 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
7007 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7008 if ((old_mask != phba->cfg_prot_mask) ||
7009 (old_guard != phba->cfg_prot_guard))
7010 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7011 "1475 Registering BlockGuard with the "
7012 "SCSI layer: mask %d guard %d\n",
7013 phba->cfg_prot_mask,
7014 phba->cfg_prot_guard);
7016 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7017 scsi_host_set_guard(shost, phba->cfg_prot_guard);
7019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7020 "1479 Not Registering BlockGuard with the SCSI "
7021 "layer, Bad protection parameters: %d %d\n",
7022 old_mask, old_guard);
7025 if (!_dump_buf_data) {
7027 spin_lock_init(&_dump_buf_lock);
7029 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7030 if (_dump_buf_data) {
7031 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7032 "9043 BLKGRD: allocated %d pages for "
7033 "_dump_buf_data at 0x%p\n",
7034 (1 << pagecnt), _dump_buf_data);
7035 _dump_buf_data_order = pagecnt;
7036 memset(_dump_buf_data, 0,
7037 ((1 << PAGE_SHIFT) << pagecnt));
7042 if (!_dump_buf_data_order)
7043 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7044 "9044 BLKGRD: ERROR unable to allocate "
7045 "memory for hexdump\n");
7047 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7048 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
7049 "\n", _dump_buf_data);
7050 if (!_dump_buf_dif) {
7053 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7054 if (_dump_buf_dif) {
7055 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7056 "9046 BLKGRD: allocated %d pages for "
7057 "_dump_buf_dif at 0x%p\n",
7058 (1 << pagecnt), _dump_buf_dif);
7059 _dump_buf_dif_order = pagecnt;
7060 memset(_dump_buf_dif, 0,
7061 ((1 << PAGE_SHIFT) << pagecnt));
7066 if (!_dump_buf_dif_order)
7067 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7068 "9047 BLKGRD: ERROR unable to allocate "
7069 "memory for hexdump\n");
7071 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7072 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
7077 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7078 * @phba: pointer to lpfc hba data structure.
7080 * This routine is invoked to perform all the necessary post initialization
7081 * setup for the device.
7084 lpfc_post_init_setup(struct lpfc_hba *phba)
7086 struct Scsi_Host *shost;
7087 struct lpfc_adapter_event_header adapter_event;
7089 /* Get the default values for Model Name and Description */
7090 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7093 * hba setup may have changed the hba_queue_depth so we need to
7094 * adjust the value of can_queue.
7096 shost = pci_get_drvdata(phba->pcidev);
7097 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7098 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7099 lpfc_setup_bg(phba, shost);
7101 lpfc_host_attrib_init(shost);
7103 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7104 spin_lock_irq(shost->host_lock);
7105 lpfc_poll_start_timer(phba);
7106 spin_unlock_irq(shost->host_lock);
7109 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7110 "0428 Perform SCSI scan\n");
7111 /* Send board arrival event to upper layer */
7112 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7113 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7114 fc_host_post_vendor_event(shost, fc_get_event_number(),
7115 sizeof(adapter_event),
7116 (char *) &adapter_event,
7122 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7123 * @phba: pointer to lpfc hba data structure.
7125 * This routine is invoked to set up the PCI device memory space for device
7126 * with SLI-3 interface spec.
7130 * other values - error
7133 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7135 struct pci_dev *pdev;
7136 unsigned long bar0map_len, bar2map_len;
7139 int error = -ENODEV;
7141 /* Obtain PCI device reference */
7145 pdev = phba->pcidev;
7147 /* Set the device DMA mask size */
7148 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7149 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7150 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7151 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
7156 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7157 * required by each mapping.
7159 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7160 bar0map_len = pci_resource_len(pdev, 0);
7162 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7163 bar2map_len = pci_resource_len(pdev, 2);
7165 /* Map HBA SLIM to a kernel virtual address. */
7166 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7167 if (!phba->slim_memmap_p) {
7168 dev_printk(KERN_ERR, &pdev->dev,
7169 "ioremap failed for SLIM memory.\n");
7173 /* Map HBA Control Registers to a kernel virtual address. */
7174 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7175 if (!phba->ctrl_regs_memmap_p) {
7176 dev_printk(KERN_ERR, &pdev->dev,
7177 "ioremap failed for HBA control registers.\n");
7178 goto out_iounmap_slim;
7181 /* Allocate memory for SLI-2 structures */
7182 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7183 &phba->slim2p.phys, GFP_KERNEL);
7184 if (!phba->slim2p.virt)
7187 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
7188 phba->mbox_ext = (phba->slim2p.virt +
7189 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
7190 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7191 phba->IOCBs = (phba->slim2p.virt +
7192 offsetof(struct lpfc_sli2_slim, IOCBs));
7194 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7195 lpfc_sli_hbq_size(),
7196 &phba->hbqslimp.phys,
7198 if (!phba->hbqslimp.virt)
7201 hbq_count = lpfc_sli_hbq_count();
7202 ptr = phba->hbqslimp.virt;
7203 for (i = 0; i < hbq_count; ++i) {
7204 phba->hbqs[i].hbq_virt = ptr;
7205 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7206 ptr += (lpfc_hbq_defs[i]->entry_count *
7207 sizeof(struct lpfc_hbq_entry));
7209 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7210 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7212 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7214 phba->MBslimaddr = phba->slim_memmap_p;
7215 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7216 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7217 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7218 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
7223 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7224 phba->slim2p.virt, phba->slim2p.phys);
7226 iounmap(phba->ctrl_regs_memmap_p);
7228 iounmap(phba->slim_memmap_p);
7234 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7235 * @phba: pointer to lpfc hba data structure.
7237 * This routine is invoked to unset the PCI device memory space for device
7238 * with SLI-3 interface spec.
7241 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7243 struct pci_dev *pdev;
7245 /* Obtain PCI device reference */
7249 pdev = phba->pcidev;
7251 /* Free coherent DMA memory allocated */
7252 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7253 phba->hbqslimp.virt, phba->hbqslimp.phys);
7254 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7255 phba->slim2p.virt, phba->slim2p.phys);
7257 /* I/O memory unmap */
7258 iounmap(phba->ctrl_regs_memmap_p);
7259 iounmap(phba->slim_memmap_p);
7265 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7266 * @phba: pointer to lpfc hba data structure.
7268 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7269 * done and check status.
7271 * Return 0 if successful, otherwise -ENODEV.
7274 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7276 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7277 struct lpfc_register reg_data;
7278 int i, port_error = 0;
7281 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7282 memset(®_data, 0, sizeof(reg_data));
7283 if (!phba->sli4_hba.PSMPHRregaddr)
7286 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7287 for (i = 0; i < 3000; i++) {
7288 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7289 &portsmphr_reg.word0) ||
7290 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
7291 /* Port has a fatal POST error, break out */
7292 port_error = -ENODEV;
7295 if (LPFC_POST_STAGE_PORT_READY ==
7296 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
7302 * If there was a port error during POST, then don't proceed with
7303 * other register reads as the data may not be valid. Just exit.
7306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7307 "1408 Port Failed POST - portsmphr=0x%x, "
7308 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7309 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7310 portsmphr_reg.word0,
7311 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7312 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7313 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7314 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7315 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7316 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7317 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7318 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7320 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7321 "2534 Device Info: SLIFamily=0x%x, "
7322 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7323 "SLIHint_2=0x%x, FT=0x%x\n",
7324 bf_get(lpfc_sli_intf_sli_family,
7325 &phba->sli4_hba.sli_intf),
7326 bf_get(lpfc_sli_intf_slirev,
7327 &phba->sli4_hba.sli_intf),
7328 bf_get(lpfc_sli_intf_if_type,
7329 &phba->sli4_hba.sli_intf),
7330 bf_get(lpfc_sli_intf_sli_hint1,
7331 &phba->sli4_hba.sli_intf),
7332 bf_get(lpfc_sli_intf_sli_hint2,
7333 &phba->sli4_hba.sli_intf),
7334 bf_get(lpfc_sli_intf_func_type,
7335 &phba->sli4_hba.sli_intf));
7337 * Check for other Port errors during the initialization
7338 * process. Fail the load if the port did not come up
7341 if_type = bf_get(lpfc_sli_intf_if_type,
7342 &phba->sli4_hba.sli_intf);
7344 case LPFC_SLI_INTF_IF_TYPE_0:
7345 phba->sli4_hba.ue_mask_lo =
7346 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7347 phba->sli4_hba.ue_mask_hi =
7348 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7350 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7352 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7353 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7354 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7356 "1422 Unrecoverable Error "
7357 "Detected during POST "
7358 "uerr_lo_reg=0x%x, "
7359 "uerr_hi_reg=0x%x, "
7360 "ue_mask_lo_reg=0x%x, "
7361 "ue_mask_hi_reg=0x%x\n",
7364 phba->sli4_hba.ue_mask_lo,
7365 phba->sli4_hba.ue_mask_hi);
7366 port_error = -ENODEV;
7369 case LPFC_SLI_INTF_IF_TYPE_2:
7370 case LPFC_SLI_INTF_IF_TYPE_6:
7371 /* Final checks. The port status should be clean. */
7372 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7374 (bf_get(lpfc_sliport_status_err, ®_data) &&
7375 !bf_get(lpfc_sliport_status_rn, ®_data))) {
7376 phba->work_status[0] =
7377 readl(phba->sli4_hba.u.if_type2.
7379 phba->work_status[1] =
7380 readl(phba->sli4_hba.u.if_type2.
7382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7383 "2888 Unrecoverable port error "
7384 "following POST: port status reg "
7385 "0x%x, port_smphr reg 0x%x, "
7386 "error 1=0x%x, error 2=0x%x\n",
7388 portsmphr_reg.word0,
7389 phba->work_status[0],
7390 phba->work_status[1]);
7391 port_error = -ENODEV;
7394 case LPFC_SLI_INTF_IF_TYPE_1:
7403 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7404 * @phba: pointer to lpfc hba data structure.
7405 * @if_type: The SLI4 interface type getting configured.
7407 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7411 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7414 case LPFC_SLI_INTF_IF_TYPE_0:
7415 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7416 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7417 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7418 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7419 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7420 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7421 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7422 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7423 phba->sli4_hba.SLIINTFregaddr =
7424 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7426 case LPFC_SLI_INTF_IF_TYPE_2:
7427 phba->sli4_hba.u.if_type2.EQDregaddr =
7428 phba->sli4_hba.conf_regs_memmap_p +
7429 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7430 phba->sli4_hba.u.if_type2.ERR1regaddr =
7431 phba->sli4_hba.conf_regs_memmap_p +
7432 LPFC_CTL_PORT_ER1_OFFSET;
7433 phba->sli4_hba.u.if_type2.ERR2regaddr =
7434 phba->sli4_hba.conf_regs_memmap_p +
7435 LPFC_CTL_PORT_ER2_OFFSET;
7436 phba->sli4_hba.u.if_type2.CTRLregaddr =
7437 phba->sli4_hba.conf_regs_memmap_p +
7438 LPFC_CTL_PORT_CTL_OFFSET;
7439 phba->sli4_hba.u.if_type2.STATUSregaddr =
7440 phba->sli4_hba.conf_regs_memmap_p +
7441 LPFC_CTL_PORT_STA_OFFSET;
7442 phba->sli4_hba.SLIINTFregaddr =
7443 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7444 phba->sli4_hba.PSMPHRregaddr =
7445 phba->sli4_hba.conf_regs_memmap_p +
7446 LPFC_CTL_PORT_SEM_OFFSET;
7447 phba->sli4_hba.RQDBregaddr =
7448 phba->sli4_hba.conf_regs_memmap_p +
7449 LPFC_ULP0_RQ_DOORBELL;
7450 phba->sli4_hba.WQDBregaddr =
7451 phba->sli4_hba.conf_regs_memmap_p +
7452 LPFC_ULP0_WQ_DOORBELL;
7453 phba->sli4_hba.CQDBregaddr =
7454 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7455 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
7456 phba->sli4_hba.MQDBregaddr =
7457 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7458 phba->sli4_hba.BMBXregaddr =
7459 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7461 case LPFC_SLI_INTF_IF_TYPE_6:
7462 phba->sli4_hba.u.if_type2.EQDregaddr =
7463 phba->sli4_hba.conf_regs_memmap_p +
7464 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7465 phba->sli4_hba.u.if_type2.ERR1regaddr =
7466 phba->sli4_hba.conf_regs_memmap_p +
7467 LPFC_CTL_PORT_ER1_OFFSET;
7468 phba->sli4_hba.u.if_type2.ERR2regaddr =
7469 phba->sli4_hba.conf_regs_memmap_p +
7470 LPFC_CTL_PORT_ER2_OFFSET;
7471 phba->sli4_hba.u.if_type2.CTRLregaddr =
7472 phba->sli4_hba.conf_regs_memmap_p +
7473 LPFC_CTL_PORT_CTL_OFFSET;
7474 phba->sli4_hba.u.if_type2.STATUSregaddr =
7475 phba->sli4_hba.conf_regs_memmap_p +
7476 LPFC_CTL_PORT_STA_OFFSET;
7477 phba->sli4_hba.PSMPHRregaddr =
7478 phba->sli4_hba.conf_regs_memmap_p +
7479 LPFC_CTL_PORT_SEM_OFFSET;
7480 phba->sli4_hba.BMBXregaddr =
7481 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7483 case LPFC_SLI_INTF_IF_TYPE_1:
7485 dev_printk(KERN_ERR, &phba->pcidev->dev,
7486 "FATAL - unsupported SLI4 interface type - %d\n",
7493 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7494 * @phba: pointer to lpfc hba data structure.
7496 * This routine is invoked to set up SLI4 BAR1 register memory map.
7499 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7502 case LPFC_SLI_INTF_IF_TYPE_0:
7503 phba->sli4_hba.PSMPHRregaddr =
7504 phba->sli4_hba.ctrl_regs_memmap_p +
7505 LPFC_SLIPORT_IF0_SMPHR;
7506 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7508 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7510 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7513 case LPFC_SLI_INTF_IF_TYPE_6:
7514 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7515 LPFC_IF6_RQ_DOORBELL;
7516 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7517 LPFC_IF6_WQ_DOORBELL;
7518 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7519 LPFC_IF6_CQ_DOORBELL;
7520 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7521 LPFC_IF6_EQ_DOORBELL;
7522 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7523 LPFC_IF6_MQ_DOORBELL;
7525 case LPFC_SLI_INTF_IF_TYPE_2:
7526 case LPFC_SLI_INTF_IF_TYPE_1:
7528 dev_err(&phba->pcidev->dev,
7529 "FATAL - unsupported SLI4 interface type - %d\n",
7536 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7537 * @phba: pointer to lpfc hba data structure.
7538 * @vf: virtual function number
7540 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7541 * based on the given viftual function number, @vf.
7543 * Return 0 if successful, otherwise -ENODEV.
7546 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7548 if (vf > LPFC_VIR_FUNC_MAX)
7551 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7552 vf * LPFC_VFR_PAGE_SIZE +
7553 LPFC_ULP0_RQ_DOORBELL);
7554 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7555 vf * LPFC_VFR_PAGE_SIZE +
7556 LPFC_ULP0_WQ_DOORBELL);
7557 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7558 vf * LPFC_VFR_PAGE_SIZE +
7559 LPFC_EQCQ_DOORBELL);
7560 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
7561 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7562 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7563 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7564 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7569 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7570 * @phba: pointer to lpfc hba data structure.
7572 * This routine is invoked to create the bootstrap mailbox
7573 * region consistent with the SLI-4 interface spec. This
7574 * routine allocates all memory necessary to communicate
7575 * mailbox commands to the port and sets up all alignment
7576 * needs. No locks are expected to be held when calling
7581 * -ENOMEM - could not allocated memory.
7584 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7587 struct lpfc_dmabuf *dmabuf;
7588 struct dma_address *dma_address;
7592 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7597 * The bootstrap mailbox region is comprised of 2 parts
7598 * plus an alignment restriction of 16 bytes.
7600 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
7601 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7602 &dmabuf->phys, GFP_KERNEL);
7603 if (!dmabuf->virt) {
7609 * Initialize the bootstrap mailbox pointers now so that the register
7610 * operations are simple later. The mailbox dma address is required
7611 * to be 16-byte aligned. Also align the virtual memory as each
7612 * maibox is copied into the bmbx mailbox region before issuing the
7613 * command to the port.
7615 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7616 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7618 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7619 LPFC_ALIGN_16_BYTE);
7620 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7621 LPFC_ALIGN_16_BYTE);
7624 * Set the high and low physical addresses now. The SLI4 alignment
7625 * requirement is 16 bytes and the mailbox is posted to the port
7626 * as two 30-bit addresses. The other data is a bit marking whether
7627 * the 30-bit address is the high or low address.
7628 * Upcast bmbx aphys to 64bits so shift instruction compiles
7629 * clean on 32 bit machines.
7631 dma_address = &phba->sli4_hba.bmbx.dma_address;
7632 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7633 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7634 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7635 LPFC_BMBX_BIT1_ADDR_HI);
7637 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7638 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7639 LPFC_BMBX_BIT1_ADDR_LO);
7644 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7645 * @phba: pointer to lpfc hba data structure.
7647 * This routine is invoked to teardown the bootstrap mailbox
7648 * region and release all host resources. This routine requires
7649 * the caller to ensure all mailbox commands recovered, no
7650 * additional mailbox comands are sent, and interrupts are disabled
7651 * before calling this routine.
7655 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7657 dma_free_coherent(&phba->pcidev->dev,
7658 phba->sli4_hba.bmbx.bmbx_size,
7659 phba->sli4_hba.bmbx.dmabuf->virt,
7660 phba->sli4_hba.bmbx.dmabuf->phys);
7662 kfree(phba->sli4_hba.bmbx.dmabuf);
7663 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7667 * lpfc_sli4_read_config - Get the config parameters.
7668 * @phba: pointer to lpfc hba data structure.
7670 * This routine is invoked to read the configuration parameters from the HBA.
7671 * The configuration parameters are used to set the base and maximum values
7672 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7673 * allocation for the port.
7677 * -ENOMEM - No available memory
7678 * -EIO - The mailbox failed to complete successfully.
7681 lpfc_sli4_read_config(struct lpfc_hba *phba)
7684 struct lpfc_mbx_read_config *rd_config;
7685 union lpfc_sli4_cfg_shdr *shdr;
7686 uint32_t shdr_status, shdr_add_status;
7687 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7688 struct lpfc_rsrc_desc_fcfcoe *desc;
7690 uint16_t forced_link_speed;
7692 int length, i, rc = 0, rc2;
7694 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7696 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7697 "2011 Unable to allocate memory for issuing "
7698 "SLI_CONFIG_SPECIAL mailbox command\n");
7702 lpfc_read_config(phba, pmb);
7704 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7705 if (rc != MBX_SUCCESS) {
7706 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7707 "2012 Mailbox failed , mbxCmd x%x "
7708 "READ_CONFIG, mbxStatus x%x\n",
7709 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7710 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7713 rd_config = &pmb->u.mqe.un.rd_config;
7714 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7715 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7716 phba->sli4_hba.lnk_info.lnk_tp =
7717 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7718 phba->sli4_hba.lnk_info.lnk_no =
7719 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7720 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7721 "3081 lnk_type:%d, lnk_numb:%d\n",
7722 phba->sli4_hba.lnk_info.lnk_tp,
7723 phba->sli4_hba.lnk_info.lnk_no);
7725 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7726 "3082 Mailbox (x%x) returned ldv:x0\n",
7727 bf_get(lpfc_mqe_command, &pmb->u.mqe));
7728 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7729 phba->bbcredit_support = 1;
7730 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7733 phba->sli4_hba.extents_in_use =
7734 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
7735 phba->sli4_hba.max_cfg_param.max_xri =
7736 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7737 phba->sli4_hba.max_cfg_param.xri_base =
7738 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7739 phba->sli4_hba.max_cfg_param.max_vpi =
7740 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7741 /* Limit the max we support */
7742 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
7743 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
7744 phba->sli4_hba.max_cfg_param.vpi_base =
7745 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7746 phba->sli4_hba.max_cfg_param.max_rpi =
7747 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7748 phba->sli4_hba.max_cfg_param.rpi_base =
7749 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7750 phba->sli4_hba.max_cfg_param.max_vfi =
7751 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7752 phba->sli4_hba.max_cfg_param.vfi_base =
7753 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7754 phba->sli4_hba.max_cfg_param.max_fcfi =
7755 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
7756 phba->sli4_hba.max_cfg_param.max_eq =
7757 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7758 phba->sli4_hba.max_cfg_param.max_rq =
7759 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7760 phba->sli4_hba.max_cfg_param.max_wq =
7761 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7762 phba->sli4_hba.max_cfg_param.max_cq =
7763 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7764 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7765 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7766 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7767 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
7768 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7769 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
7770 phba->max_vports = phba->max_vpi;
7771 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7772 "2003 cfg params Extents? %d "
7777 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7778 phba->sli4_hba.extents_in_use,
7779 phba->sli4_hba.max_cfg_param.xri_base,
7780 phba->sli4_hba.max_cfg_param.max_xri,
7781 phba->sli4_hba.max_cfg_param.vpi_base,
7782 phba->sli4_hba.max_cfg_param.max_vpi,
7783 phba->sli4_hba.max_cfg_param.vfi_base,
7784 phba->sli4_hba.max_cfg_param.max_vfi,
7785 phba->sli4_hba.max_cfg_param.rpi_base,
7786 phba->sli4_hba.max_cfg_param.max_rpi,
7787 phba->sli4_hba.max_cfg_param.max_fcfi,
7788 phba->sli4_hba.max_cfg_param.max_eq,
7789 phba->sli4_hba.max_cfg_param.max_cq,
7790 phba->sli4_hba.max_cfg_param.max_wq,
7791 phba->sli4_hba.max_cfg_param.max_rq);
7794 * Calculate NVME queue resources based on how
7795 * many WQ/CQs are available.
7797 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7798 length = phba->sli4_hba.max_cfg_param.max_wq;
7799 if (phba->sli4_hba.max_cfg_param.max_cq <
7800 phba->sli4_hba.max_cfg_param.max_wq)
7801 length = phba->sli4_hba.max_cfg_param.max_cq;
7804 * Whats left after this can go toward NVME.
7805 * The minus 6 accounts for ELS, NVME LS, MBOX
7806 * fof plus a couple extra. When configured for
7807 * NVMET, FCP io channel WQs are not created.
7810 if (!phba->nvmet_support)
7811 length -= phba->cfg_fcp_io_channel;
7813 if (phba->cfg_nvme_io_channel > length) {
7815 phba, KERN_ERR, LOG_SLI,
7816 "2005 Reducing NVME IO channel to %d: "
7817 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
7819 phba->sli4_hba.max_cfg_param.max_wq,
7820 phba->sli4_hba.max_cfg_param.max_cq,
7821 phba->cfg_nvme_io_channel,
7822 phba->cfg_fcp_io_channel);
7824 phba->cfg_nvme_io_channel = length;
7832 /* Update link speed if forced link speed is supported */
7833 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7834 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
7836 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7837 if (forced_link_speed) {
7838 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7840 switch (forced_link_speed) {
7842 phba->cfg_link_speed =
7843 LPFC_USER_LINK_SPEED_1G;
7846 phba->cfg_link_speed =
7847 LPFC_USER_LINK_SPEED_2G;
7850 phba->cfg_link_speed =
7851 LPFC_USER_LINK_SPEED_4G;
7854 phba->cfg_link_speed =
7855 LPFC_USER_LINK_SPEED_8G;
7857 case LINK_SPEED_10G:
7858 phba->cfg_link_speed =
7859 LPFC_USER_LINK_SPEED_10G;
7861 case LINK_SPEED_16G:
7862 phba->cfg_link_speed =
7863 LPFC_USER_LINK_SPEED_16G;
7865 case LINK_SPEED_32G:
7866 phba->cfg_link_speed =
7867 LPFC_USER_LINK_SPEED_32G;
7869 case LINK_SPEED_64G:
7870 phba->cfg_link_speed =
7871 LPFC_USER_LINK_SPEED_64G;
7874 phba->cfg_link_speed =
7875 LPFC_USER_LINK_SPEED_AUTO;
7878 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7879 "0047 Unrecognized link "
7882 phba->cfg_link_speed =
7883 LPFC_USER_LINK_SPEED_AUTO;
7888 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7889 length = phba->sli4_hba.max_cfg_param.max_xri -
7890 lpfc_sli4_get_els_iocb_cnt(phba);
7891 if (phba->cfg_hba_queue_depth > length) {
7892 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7893 "3361 HBA queue depth changed from %d to %d\n",
7894 phba->cfg_hba_queue_depth, length);
7895 phba->cfg_hba_queue_depth = length;
7898 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7899 LPFC_SLI_INTF_IF_TYPE_2)
7902 /* get the pf# and vf# for SLI4 if_type 2 port */
7903 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7904 sizeof(struct lpfc_sli4_cfg_mhdr));
7905 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7906 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7907 length, LPFC_SLI4_MBX_EMBED);
7909 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7910 shdr = (union lpfc_sli4_cfg_shdr *)
7911 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7912 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7913 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7914 if (rc2 || shdr_status || shdr_add_status) {
7915 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7916 "3026 Mailbox failed , mbxCmd x%x "
7917 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7918 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7919 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7923 /* search for fc_fcoe resrouce descriptor */
7924 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
7926 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7927 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7928 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7929 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7930 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7931 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7934 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
7935 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
7936 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
7937 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
7938 phba->sli4_hba.iov.pf_number =
7939 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7940 phba->sli4_hba.iov.vf_number =
7941 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7946 if (i < LPFC_RSRC_DESC_MAX_NUM)
7947 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7948 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7949 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7950 phba->sli4_hba.iov.vf_number);
7952 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7953 "3028 GET_FUNCTION_CONFIG: failed to find "
7954 "Resrouce Descriptor:x%x\n",
7955 LPFC_RSRC_DESC_TYPE_FCFCOE);
7958 mempool_free(pmb, phba->mbox_mem_pool);
7963 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7964 * @phba: pointer to lpfc hba data structure.
7966 * This routine is invoked to setup the port-side endian order when
7967 * the port if_type is 0. This routine has no function for other
7972 * -ENOMEM - No available memory
7973 * -EIO - The mailbox failed to complete successfully.
7976 lpfc_setup_endian_order(struct lpfc_hba *phba)
7978 LPFC_MBOXQ_t *mboxq;
7979 uint32_t if_type, rc = 0;
7980 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7981 HOST_ENDIAN_HIGH_WORD1};
7983 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7985 case LPFC_SLI_INTF_IF_TYPE_0:
7986 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7990 "0492 Unable to allocate memory for "
7991 "issuing SLI_CONFIG_SPECIAL mailbox "
7997 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7998 * two words to contain special data values and no other data.
8000 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8001 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8002 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8003 if (rc != MBX_SUCCESS) {
8004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8005 "0493 SLI_CONFIG_SPECIAL mailbox "
8006 "failed with status x%x\n",
8010 mempool_free(mboxq, phba->mbox_mem_pool);
8012 case LPFC_SLI_INTF_IF_TYPE_6:
8013 case LPFC_SLI_INTF_IF_TYPE_2:
8014 case LPFC_SLI_INTF_IF_TYPE_1:
8022 * lpfc_sli4_queue_verify - Verify and update EQ counts
8023 * @phba: pointer to lpfc hba data structure.
8025 * This routine is invoked to check the user settable queue counts for EQs.
8026 * After this routine is called the counts will be set to valid values that
8027 * adhere to the constraints of the system's interrupt vectors and the port's
8032 * -ENOMEM - No available memory
8035 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
8038 int fof_vectors = phba->cfg_fof ? 1 : 0;
8041 * Sanity check for configured queue parameters against the run-time
8045 /* Sanity check on HBA EQ parameters */
8046 io_channel = phba->io_channel_irqs;
8048 if (phba->sli4_hba.num_online_cpu < io_channel) {
8049 lpfc_printf_log(phba,
8051 "3188 Reducing IO channels to match number of "
8052 "online CPUs: from %d to %d\n",
8053 io_channel, phba->sli4_hba.num_online_cpu);
8054 io_channel = phba->sli4_hba.num_online_cpu;
8057 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
8058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8059 "2575 Reducing IO channels to match number of "
8060 "available EQs: from %d to %d\n",
8062 phba->sli4_hba.max_cfg_param.max_eq);
8063 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
8066 /* The actual number of FCP / NVME event queues adopted */
8067 if (io_channel != phba->io_channel_irqs)
8068 phba->io_channel_irqs = io_channel;
8069 if (phba->cfg_fcp_io_channel > io_channel)
8070 phba->cfg_fcp_io_channel = io_channel;
8071 if (phba->cfg_nvme_io_channel > io_channel)
8072 phba->cfg_nvme_io_channel = io_channel;
8073 if (phba->nvmet_support) {
8074 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8075 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8077 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8078 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
8080 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8081 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
8082 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
8083 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
8085 /* Get EQ depth from module parameter, fake the default for now */
8086 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8087 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8089 /* Get CQ depth from module parameter, fake the default for now */
8090 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8091 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8096 lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8098 struct lpfc_queue *qdesc;
8100 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8101 phba->sli4_hba.cq_esize,
8102 LPFC_CQE_EXP_COUNT);
8104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8105 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8109 qdesc->qe_valid = 1;
8110 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8112 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8113 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
8115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8116 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8120 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8121 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8126 lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8128 struct lpfc_queue *qdesc;
8131 /* Create Fast Path FCP CQs */
8132 if (phba->enab_exp_wqcq_pages)
8133 /* Increase the CQ size when WQEs contain an embedded cdb */
8134 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8135 phba->sli4_hba.cq_esize,
8136 LPFC_CQE_EXP_COUNT);
8139 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8140 phba->sli4_hba.cq_esize,
8141 phba->sli4_hba.cq_ecount);
8143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8144 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8147 qdesc->qe_valid = 1;
8148 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8150 /* Create Fast Path FCP WQs */
8151 if (phba->enab_exp_wqcq_pages) {
8152 /* Increase the WQ size when WQEs contain an embedded cdb */
8153 wqesize = (phba->fcp_embed_io) ?
8154 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
8155 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8157 LPFC_WQE_EXP_COUNT);
8159 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8160 phba->sli4_hba.wq_esize,
8161 phba->sli4_hba.wq_ecount);
8164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8165 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8169 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8170 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8175 * lpfc_sli4_queue_create - Create all the SLI4 queues
8176 * @phba: pointer to lpfc hba data structure.
8178 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8179 * operation. For each SLI4 queue type, the parameters such as queue entry
8180 * count (queue depth) shall be taken from the module parameter. For now,
8181 * we just use some constant number as place holder.
8185 * -ENOMEM - No availble memory
8186 * -EIO - The mailbox failed to complete successfully.
8189 lpfc_sli4_queue_create(struct lpfc_hba *phba)
8191 struct lpfc_queue *qdesc;
8192 int idx, io_channel;
8195 * Create HBA Record arrays.
8196 * Both NVME and FCP will share that same vectors / EQs
8198 io_channel = phba->io_channel_irqs;
8202 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8203 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8204 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8205 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8206 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8207 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
8208 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8209 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8210 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8211 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8213 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8214 sizeof(struct lpfc_queue *),
8216 if (!phba->sli4_hba.hba_eq) {
8217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8218 "2576 Failed allocate memory for "
8219 "fast-path EQ record array\n");
8223 if (phba->cfg_fcp_io_channel) {
8224 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8225 sizeof(struct lpfc_queue *),
8227 if (!phba->sli4_hba.fcp_cq) {
8228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8229 "2577 Failed allocate memory for "
8230 "fast-path CQ record array\n");
8233 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8234 sizeof(struct lpfc_queue *),
8236 if (!phba->sli4_hba.fcp_wq) {
8237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8238 "2578 Failed allocate memory for "
8239 "fast-path FCP WQ record array\n");
8243 * Since the first EQ can have multiple CQs associated with it,
8244 * this array is used to quickly see if we have a FCP fast-path
8247 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8250 if (!phba->sli4_hba.fcp_cq_map) {
8251 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8252 "2545 Failed allocate memory for "
8253 "fast-path CQ map\n");
8258 if (phba->cfg_nvme_io_channel) {
8259 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8260 sizeof(struct lpfc_queue *),
8262 if (!phba->sli4_hba.nvme_cq) {
8263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8264 "6077 Failed allocate memory for "
8265 "fast-path CQ record array\n");
8269 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8270 sizeof(struct lpfc_queue *),
8272 if (!phba->sli4_hba.nvme_wq) {
8273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8274 "2581 Failed allocate memory for "
8275 "fast-path NVME WQ record array\n");
8280 * Since the first EQ can have multiple CQs associated with it,
8281 * this array is used to quickly see if we have a NVME fast-path
8284 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8287 if (!phba->sli4_hba.nvme_cq_map) {
8288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8289 "6078 Failed allocate memory for "
8290 "fast-path CQ map\n");
8294 if (phba->nvmet_support) {
8295 phba->sli4_hba.nvmet_cqset = kcalloc(
8296 phba->cfg_nvmet_mrq,
8297 sizeof(struct lpfc_queue *),
8299 if (!phba->sli4_hba.nvmet_cqset) {
8300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8301 "3121 Fail allocate memory for "
8302 "fast-path CQ set array\n");
8305 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8306 phba->cfg_nvmet_mrq,
8307 sizeof(struct lpfc_queue *),
8309 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8311 "3122 Fail allocate memory for "
8312 "fast-path RQ set hdr array\n");
8315 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8316 phba->cfg_nvmet_mrq,
8317 sizeof(struct lpfc_queue *),
8319 if (!phba->sli4_hba.nvmet_mrq_data) {
8320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8321 "3124 Fail allocate memory for "
8322 "fast-path RQ set data array\n");
8328 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8330 /* Create HBA Event Queues (EQs) */
8331 for (idx = 0; idx < io_channel; idx++) {
8333 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8334 phba->sli4_hba.eq_esize,
8335 phba->sli4_hba.eq_ecount);
8337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8338 "0497 Failed allocate EQ (%d)\n", idx);
8341 qdesc->qe_valid = 1;
8342 phba->sli4_hba.hba_eq[idx] = qdesc;
8345 /* FCP and NVME io channels are not required to be balanced */
8347 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8348 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8351 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8352 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8355 if (phba->nvmet_support) {
8356 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8357 qdesc = lpfc_sli4_queue_alloc(phba,
8358 LPFC_DEFAULT_PAGE_SIZE,
8359 phba->sli4_hba.cq_esize,
8360 phba->sli4_hba.cq_ecount);
8362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8363 "3142 Failed allocate NVME "
8364 "CQ Set (%d)\n", idx);
8367 qdesc->qe_valid = 1;
8368 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8373 * Create Slow Path Completion Queues (CQs)
8376 /* Create slow-path Mailbox Command Complete Queue */
8377 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8378 phba->sli4_hba.cq_esize,
8379 phba->sli4_hba.cq_ecount);
8381 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8382 "0500 Failed allocate slow-path mailbox CQ\n");
8385 qdesc->qe_valid = 1;
8386 phba->sli4_hba.mbx_cq = qdesc;
8388 /* Create slow-path ELS Complete Queue */
8389 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8390 phba->sli4_hba.cq_esize,
8391 phba->sli4_hba.cq_ecount);
8393 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8394 "0501 Failed allocate slow-path ELS CQ\n");
8397 qdesc->qe_valid = 1;
8398 phba->sli4_hba.els_cq = qdesc;
8402 * Create Slow Path Work Queues (WQs)
8405 /* Create Mailbox Command Queue */
8407 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8408 phba->sli4_hba.mq_esize,
8409 phba->sli4_hba.mq_ecount);
8411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8412 "0505 Failed allocate slow-path MQ\n");
8415 phba->sli4_hba.mbx_wq = qdesc;
8418 * Create ELS Work Queues
8421 /* Create slow-path ELS Work Queue */
8422 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8423 phba->sli4_hba.wq_esize,
8424 phba->sli4_hba.wq_ecount);
8426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8427 "0504 Failed allocate slow-path ELS WQ\n");
8430 phba->sli4_hba.els_wq = qdesc;
8431 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8433 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8434 /* Create NVME LS Complete Queue */
8435 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8436 phba->sli4_hba.cq_esize,
8437 phba->sli4_hba.cq_ecount);
8439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8440 "6079 Failed allocate NVME LS CQ\n");
8443 qdesc->qe_valid = 1;
8444 phba->sli4_hba.nvmels_cq = qdesc;
8446 /* Create NVME LS Work Queue */
8447 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8448 phba->sli4_hba.wq_esize,
8449 phba->sli4_hba.wq_ecount);
8451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8452 "6080 Failed allocate NVME LS WQ\n");
8455 phba->sli4_hba.nvmels_wq = qdesc;
8456 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8460 * Create Receive Queue (RQ)
8463 /* Create Receive Queue for header */
8464 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8465 phba->sli4_hba.rq_esize,
8466 phba->sli4_hba.rq_ecount);
8468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8469 "0506 Failed allocate receive HRQ\n");
8472 phba->sli4_hba.hdr_rq = qdesc;
8474 /* Create Receive Queue for data */
8475 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8476 phba->sli4_hba.rq_esize,
8477 phba->sli4_hba.rq_ecount);
8479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8480 "0507 Failed allocate receive DRQ\n");
8483 phba->sli4_hba.dat_rq = qdesc;
8485 if (phba->nvmet_support) {
8486 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8487 /* Create NVMET Receive Queue for header */
8488 qdesc = lpfc_sli4_queue_alloc(phba,
8489 LPFC_DEFAULT_PAGE_SIZE,
8490 phba->sli4_hba.rq_esize,
8491 LPFC_NVMET_RQE_DEF_COUNT);
8493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8494 "3146 Failed allocate "
8498 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8500 /* Only needed for header of RQ pair */
8501 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8503 if (qdesc->rqbp == NULL) {
8504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8505 "6131 Failed allocate "
8510 /* Put list in known state in case driver load fails. */
8511 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8513 /* Create NVMET Receive Queue for data */
8514 qdesc = lpfc_sli4_queue_alloc(phba,
8515 LPFC_DEFAULT_PAGE_SIZE,
8516 phba->sli4_hba.rq_esize,
8517 LPFC_NVMET_RQE_DEF_COUNT);
8519 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8520 "3156 Failed allocate "
8524 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8528 /* Create the Queues needed for Flash Optimized Fabric operations */
8530 lpfc_fof_queue_create(phba);
8534 lpfc_sli4_queue_destroy(phba);
8539 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
8542 lpfc_sli4_queue_free(*qp);
8548 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8555 for (idx = 0; idx < max; idx++)
8556 __lpfc_sli4_release_queue(&(*qs)[idx]);
8563 lpfc_sli4_release_queue_map(uint16_t **qmap)
8565 if (*qmap != NULL) {
8572 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8573 * @phba: pointer to lpfc hba data structure.
8575 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8580 * -ENOMEM - No available memory
8581 * -EIO - The mailbox failed to complete successfully.
8584 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8587 lpfc_fof_queue_destroy(phba);
8589 /* Release HBA eqs */
8590 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
8592 /* Release FCP cqs */
8593 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
8594 phba->cfg_fcp_io_channel);
8596 /* Release FCP wqs */
8597 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
8598 phba->cfg_fcp_io_channel);
8600 /* Release FCP CQ mapping array */
8601 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8603 /* Release NVME cqs */
8604 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8605 phba->cfg_nvme_io_channel);
8607 /* Release NVME wqs */
8608 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8609 phba->cfg_nvme_io_channel);
8611 /* Release NVME CQ mapping array */
8612 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
8614 if (phba->nvmet_support) {
8615 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8616 phba->cfg_nvmet_mrq);
8618 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8619 phba->cfg_nvmet_mrq);
8620 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8621 phba->cfg_nvmet_mrq);
8624 /* Release mailbox command work queue */
8625 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
8627 /* Release ELS work queue */
8628 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8630 /* Release ELS work queue */
8631 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
8633 /* Release unsolicited receive queue */
8634 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8635 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
8637 /* Release ELS complete queue */
8638 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8640 /* Release NVME LS complete queue */
8641 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
8643 /* Release mailbox command complete queue */
8644 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8646 /* Everything on this list has been freed */
8647 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8651 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8653 struct lpfc_rqb *rqbp;
8654 struct lpfc_dmabuf *h_buf;
8655 struct rqb_dmabuf *rqb_buffer;
8658 while (!list_empty(&rqbp->rqb_buffer_list)) {
8659 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8660 struct lpfc_dmabuf, list);
8662 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8663 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8664 rqbp->buffer_count--;
8670 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8671 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8672 int qidx, uint32_t qtype)
8674 struct lpfc_sli_ring *pring;
8677 if (!eq || !cq || !wq) {
8678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8679 "6085 Fast-path %s (%d) not allocated\n",
8680 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8684 /* create the Cq first */
8685 rc = lpfc_cq_create(phba, cq, eq,
8686 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8689 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8690 qidx, (uint32_t)rc);
8695 if (qtype != LPFC_MBOX) {
8696 /* Setup nvme_cq_map for fast lookup */
8698 *cq_map = cq->queue_id;
8700 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8701 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8702 qidx, cq->queue_id, qidx, eq->queue_id);
8705 rc = lpfc_wq_create(phba, wq, cq, qtype);
8707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8708 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8709 qidx, (uint32_t)rc);
8710 /* no need to tear down cq - caller will do so */
8715 /* Bind this CQ/WQ to the NVME ring */
8717 pring->sli.sli4.wqp = (void *)wq;
8720 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8721 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8722 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8724 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8727 "0539 Failed setup of slow-path MQ: "
8729 /* no need to tear down cq - caller will do so */
8733 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8734 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8735 phba->sli4_hba.mbx_wq->queue_id,
8736 phba->sli4_hba.mbx_cq->queue_id);
8743 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8744 * @phba: pointer to lpfc hba data structure.
8746 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8751 * -ENOMEM - No available memory
8752 * -EIO - The mailbox failed to complete successfully.
8755 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8757 uint32_t shdr_status, shdr_add_status;
8758 union lpfc_sli4_cfg_shdr *shdr;
8759 LPFC_MBOXQ_t *mboxq;
8761 uint32_t length, io_channel;
8764 /* Check for dual-ULP support */
8765 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8767 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8768 "3249 Unable to allocate memory for "
8769 "QUERY_FW_CFG mailbox command\n");
8772 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8773 sizeof(struct lpfc_sli4_cfg_mhdr));
8774 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8775 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8776 length, LPFC_SLI4_MBX_EMBED);
8778 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8780 shdr = (union lpfc_sli4_cfg_shdr *)
8781 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8782 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8783 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8784 if (shdr_status || shdr_add_status || rc) {
8785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8786 "3250 QUERY_FW_CFG mailbox failed with status "
8787 "x%x add_status x%x, mbx status x%x\n",
8788 shdr_status, shdr_add_status, rc);
8789 if (rc != MBX_TIMEOUT)
8790 mempool_free(mboxq, phba->mbox_mem_pool);
8795 phba->sli4_hba.fw_func_mode =
8796 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8797 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8798 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
8799 phba->sli4_hba.physical_port =
8800 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
8801 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8802 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8803 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8804 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8806 if (rc != MBX_TIMEOUT)
8807 mempool_free(mboxq, phba->mbox_mem_pool);
8810 * Set up HBA Event Queues (EQs)
8812 io_channel = phba->io_channel_irqs;
8814 /* Set up HBA event queue */
8815 if (io_channel && !phba->sli4_hba.hba_eq) {
8816 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8817 "3147 Fast-path EQs not allocated\n");
8821 for (qidx = 0; qidx < io_channel; qidx++) {
8822 if (!phba->sli4_hba.hba_eq[qidx]) {
8823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8824 "0522 Fast-path EQ (%d) not "
8825 "allocated\n", qidx);
8829 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8830 phba->cfg_fcp_imax);
8832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8833 "0523 Failed setup of fast-path EQ "
8834 "(%d), rc = 0x%x\n", qidx,
8838 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8839 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8840 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
8843 if (phba->cfg_nvme_io_channel) {
8844 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
8845 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8846 "6084 Fast-path NVME %s array not allocated\n",
8847 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
8852 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8853 rc = lpfc_create_wq_cq(phba,
8854 phba->sli4_hba.hba_eq[
8856 phba->sli4_hba.nvme_cq[qidx],
8857 phba->sli4_hba.nvme_wq[qidx],
8858 &phba->sli4_hba.nvme_cq_map[qidx],
8861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8862 "6123 Failed to setup fastpath "
8863 "NVME WQ/CQ (%d), rc = 0x%x\n",
8864 qidx, (uint32_t)rc);
8870 if (phba->cfg_fcp_io_channel) {
8871 /* Set up fast-path FCP Response Complete Queue */
8872 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
8873 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8874 "3148 Fast-path FCP %s array not allocated\n",
8875 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
8880 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8881 rc = lpfc_create_wq_cq(phba,
8882 phba->sli4_hba.hba_eq[
8884 phba->sli4_hba.fcp_cq[qidx],
8885 phba->sli4_hba.fcp_wq[qidx],
8886 &phba->sli4_hba.fcp_cq_map[qidx],
8889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8890 "0535 Failed to setup fastpath "
8891 "FCP WQ/CQ (%d), rc = 0x%x\n",
8892 qidx, (uint32_t)rc);
8899 * Set up Slow Path Complete Queues (CQs)
8902 /* Set up slow-path MBOX CQ/MQ */
8904 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
8905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8906 "0528 %s not allocated\n",
8907 phba->sli4_hba.mbx_cq ?
8908 "Mailbox WQ" : "Mailbox CQ");
8913 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8914 phba->sli4_hba.mbx_cq,
8915 phba->sli4_hba.mbx_wq,
8916 NULL, 0, LPFC_MBOX);
8918 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8919 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8923 if (phba->nvmet_support) {
8924 if (!phba->sli4_hba.nvmet_cqset) {
8925 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8926 "3165 Fast-path NVME CQ Set "
8927 "array not allocated\n");
8931 if (phba->cfg_nvmet_mrq > 1) {
8932 rc = lpfc_cq_create_set(phba,
8933 phba->sli4_hba.nvmet_cqset,
8934 phba->sli4_hba.hba_eq,
8935 LPFC_WCQ, LPFC_NVMET);
8937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8938 "3164 Failed setup of NVME CQ "
8944 /* Set up NVMET Receive Complete Queue */
8945 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8946 phba->sli4_hba.hba_eq[0],
8947 LPFC_WCQ, LPFC_NVMET);
8949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8950 "6089 Failed setup NVMET CQ: "
8951 "rc = 0x%x\n", (uint32_t)rc);
8954 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
8956 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8957 "6090 NVMET CQ setup: cq-id=%d, "
8958 "parent eq-id=%d\n",
8959 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8960 phba->sli4_hba.hba_eq[0]->queue_id);
8964 /* Set up slow-path ELS WQ/CQ */
8965 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
8966 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8967 "0530 ELS %s not allocated\n",
8968 phba->sli4_hba.els_cq ? "WQ" : "CQ");
8972 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8973 phba->sli4_hba.els_cq,
8974 phba->sli4_hba.els_wq,
8977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8978 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8982 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8983 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8984 phba->sli4_hba.els_wq->queue_id,
8985 phba->sli4_hba.els_cq->queue_id);
8987 if (phba->cfg_nvme_io_channel) {
8988 /* Set up NVME LS Complete Queue */
8989 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8991 "6091 LS %s not allocated\n",
8992 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8996 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8997 phba->sli4_hba.nvmels_cq,
8998 phba->sli4_hba.nvmels_wq,
8999 NULL, 0, LPFC_NVME_LS);
9001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9002 "0529 Failed setup of NVVME LS WQ/CQ: "
9003 "rc = 0x%x\n", (uint32_t)rc);
9007 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9008 "6096 ELS WQ setup: wq-id=%d, "
9009 "parent cq-id=%d\n",
9010 phba->sli4_hba.nvmels_wq->queue_id,
9011 phba->sli4_hba.nvmels_cq->queue_id);
9015 * Create NVMET Receive Queue (RQ)
9017 if (phba->nvmet_support) {
9018 if ((!phba->sli4_hba.nvmet_cqset) ||
9019 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9020 (!phba->sli4_hba.nvmet_mrq_data)) {
9021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9022 "6130 MRQ CQ Queues not "
9027 if (phba->cfg_nvmet_mrq > 1) {
9028 rc = lpfc_mrq_create(phba,
9029 phba->sli4_hba.nvmet_mrq_hdr,
9030 phba->sli4_hba.nvmet_mrq_data,
9031 phba->sli4_hba.nvmet_cqset,
9034 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9035 "6098 Failed setup of NVMET "
9042 rc = lpfc_rq_create(phba,
9043 phba->sli4_hba.nvmet_mrq_hdr[0],
9044 phba->sli4_hba.nvmet_mrq_data[0],
9045 phba->sli4_hba.nvmet_cqset[0],
9048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9049 "6057 Failed setup of NVMET "
9050 "Receive Queue: rc = 0x%x\n",
9056 phba, KERN_INFO, LOG_INIT,
9057 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9058 "dat-rq-id=%d parent cq-id=%d\n",
9059 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9060 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9061 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9066 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9068 "0540 Receive Queue not allocated\n");
9073 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
9074 phba->sli4_hba.els_cq, LPFC_USOL);
9076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9077 "0541 Failed setup of Receive Queue: "
9078 "rc = 0x%x\n", (uint32_t)rc);
9082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9083 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9084 "parent cq-id=%d\n",
9085 phba->sli4_hba.hdr_rq->queue_id,
9086 phba->sli4_hba.dat_rq->queue_id,
9087 phba->sli4_hba.els_cq->queue_id);
9089 if (phba->cfg_fof) {
9090 rc = lpfc_fof_queue_setup(phba);
9092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9093 "0549 Failed setup of FOF Queues: "
9099 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
9100 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9101 phba->cfg_fcp_imax);
9106 lpfc_sli4_queue_unset(phba);
9112 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9113 * @phba: pointer to lpfc hba data structure.
9115 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9120 * -ENOMEM - No available memory
9121 * -EIO - The mailbox failed to complete successfully.
9124 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9128 /* Unset the queues created for Flash Optimized Fabric operations */
9130 lpfc_fof_queue_destroy(phba);
9132 /* Unset mailbox command work queue */
9133 if (phba->sli4_hba.mbx_wq)
9134 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9136 /* Unset NVME LS work queue */
9137 if (phba->sli4_hba.nvmels_wq)
9138 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9140 /* Unset ELS work queue */
9141 if (phba->sli4_hba.els_wq)
9142 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9144 /* Unset unsolicited receive queue */
9145 if (phba->sli4_hba.hdr_rq)
9146 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9147 phba->sli4_hba.dat_rq);
9149 /* Unset FCP work queue */
9150 if (phba->sli4_hba.fcp_wq)
9151 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9152 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9154 /* Unset NVME work queue */
9155 if (phba->sli4_hba.nvme_wq) {
9156 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9157 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
9160 /* Unset mailbox command complete queue */
9161 if (phba->sli4_hba.mbx_cq)
9162 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9164 /* Unset ELS complete queue */
9165 if (phba->sli4_hba.els_cq)
9166 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9168 /* Unset NVME LS complete queue */
9169 if (phba->sli4_hba.nvmels_cq)
9170 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9172 /* Unset NVME response complete queue */
9173 if (phba->sli4_hba.nvme_cq)
9174 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9175 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9177 if (phba->nvmet_support) {
9178 /* Unset NVMET MRQ queue */
9179 if (phba->sli4_hba.nvmet_mrq_hdr) {
9180 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9183 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9184 phba->sli4_hba.nvmet_mrq_data[qidx]);
9187 /* Unset NVMET CQ Set complete queue */
9188 if (phba->sli4_hba.nvmet_cqset) {
9189 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9191 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9195 /* Unset FCP response complete queue */
9196 if (phba->sli4_hba.fcp_cq)
9197 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9198 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9200 /* Unset fast-path event queue */
9201 if (phba->sli4_hba.hba_eq)
9202 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9203 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
9207 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9208 * @phba: pointer to lpfc hba data structure.
9210 * This routine is invoked to allocate and set up a pool of completion queue
9211 * events. The body of the completion queue event is a completion queue entry
9212 * CQE. For now, this pool is used for the interrupt service routine to queue
9213 * the following HBA completion queue events for the worker thread to process:
9214 * - Mailbox asynchronous events
9215 * - Receive queue completion unsolicited events
9216 * Later, this can be used for all the slow-path events.
9220 * -ENOMEM - No available memory
9223 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9225 struct lpfc_cq_event *cq_event;
9228 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9229 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9231 goto out_pool_create_fail;
9232 list_add_tail(&cq_event->list,
9233 &phba->sli4_hba.sp_cqe_event_pool);
9237 out_pool_create_fail:
9238 lpfc_sli4_cq_event_pool_destroy(phba);
9243 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9244 * @phba: pointer to lpfc hba data structure.
9246 * This routine is invoked to free the pool of completion queue events at
9247 * driver unload time. Note that, it is the responsibility of the driver
9248 * cleanup routine to free all the outstanding completion-queue events
9249 * allocated from this pool back into the pool before invoking this routine
9250 * to destroy the pool.
9253 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9255 struct lpfc_cq_event *cq_event, *next_cq_event;
9257 list_for_each_entry_safe(cq_event, next_cq_event,
9258 &phba->sli4_hba.sp_cqe_event_pool, list) {
9259 list_del(&cq_event->list);
9265 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9266 * @phba: pointer to lpfc hba data structure.
9268 * This routine is the lock free version of the API invoked to allocate a
9269 * completion-queue event from the free pool.
9271 * Return: Pointer to the newly allocated completion-queue event if successful
9274 struct lpfc_cq_event *
9275 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9277 struct lpfc_cq_event *cq_event = NULL;
9279 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9280 struct lpfc_cq_event, list);
9285 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9286 * @phba: pointer to lpfc hba data structure.
9288 * This routine is the lock version of the API invoked to allocate a
9289 * completion-queue event from the free pool.
9291 * Return: Pointer to the newly allocated completion-queue event if successful
9294 struct lpfc_cq_event *
9295 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9297 struct lpfc_cq_event *cq_event;
9298 unsigned long iflags;
9300 spin_lock_irqsave(&phba->hbalock, iflags);
9301 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9302 spin_unlock_irqrestore(&phba->hbalock, iflags);
9307 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9308 * @phba: pointer to lpfc hba data structure.
9309 * @cq_event: pointer to the completion queue event to be freed.
9311 * This routine is the lock free version of the API invoked to release a
9312 * completion-queue event back into the free pool.
9315 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9316 struct lpfc_cq_event *cq_event)
9318 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9322 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9323 * @phba: pointer to lpfc hba data structure.
9324 * @cq_event: pointer to the completion queue event to be freed.
9326 * This routine is the lock version of the API invoked to release a
9327 * completion-queue event back into the free pool.
9330 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9331 struct lpfc_cq_event *cq_event)
9333 unsigned long iflags;
9334 spin_lock_irqsave(&phba->hbalock, iflags);
9335 __lpfc_sli4_cq_event_release(phba, cq_event);
9336 spin_unlock_irqrestore(&phba->hbalock, iflags);
9340 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9341 * @phba: pointer to lpfc hba data structure.
9343 * This routine is to free all the pending completion-queue events to the
9344 * back into the free pool for device reset.
9347 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9350 struct lpfc_cq_event *cqe;
9351 unsigned long iflags;
9353 /* Retrieve all the pending WCQEs from pending WCQE lists */
9354 spin_lock_irqsave(&phba->hbalock, iflags);
9355 /* Pending FCP XRI abort events */
9356 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9358 /* Pending ELS XRI abort events */
9359 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9361 /* Pending asynnc events */
9362 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9364 spin_unlock_irqrestore(&phba->hbalock, iflags);
9366 while (!list_empty(&cqelist)) {
9367 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9368 lpfc_sli4_cq_event_release(phba, cqe);
9373 * lpfc_pci_function_reset - Reset pci function.
9374 * @phba: pointer to lpfc hba data structure.
9376 * This routine is invoked to request a PCI function reset. It will destroys
9377 * all resources assigned to the PCI function which originates this request.
9381 * -ENOMEM - No available memory
9382 * -EIO - The mailbox failed to complete successfully.
9385 lpfc_pci_function_reset(struct lpfc_hba *phba)
9387 LPFC_MBOXQ_t *mboxq;
9388 uint32_t rc = 0, if_type;
9389 uint32_t shdr_status, shdr_add_status;
9391 uint32_t port_reset = 0;
9392 union lpfc_sli4_cfg_shdr *shdr;
9393 struct lpfc_register reg_data;
9396 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9398 case LPFC_SLI_INTF_IF_TYPE_0:
9399 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9402 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9403 "0494 Unable to allocate memory for "
9404 "issuing SLI_FUNCTION_RESET mailbox "
9409 /* Setup PCI function reset mailbox-ioctl command */
9410 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9411 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9412 LPFC_SLI4_MBX_EMBED);
9413 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9414 shdr = (union lpfc_sli4_cfg_shdr *)
9415 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9416 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9417 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9419 if (rc != MBX_TIMEOUT)
9420 mempool_free(mboxq, phba->mbox_mem_pool);
9421 if (shdr_status || shdr_add_status || rc) {
9422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9423 "0495 SLI_FUNCTION_RESET mailbox "
9424 "failed with status x%x add_status x%x,"
9425 " mbx status x%x\n",
9426 shdr_status, shdr_add_status, rc);
9430 case LPFC_SLI_INTF_IF_TYPE_2:
9431 case LPFC_SLI_INTF_IF_TYPE_6:
9434 * Poll the Port Status Register and wait for RDY for
9435 * up to 30 seconds. If the port doesn't respond, treat
9438 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
9439 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9440 STATUSregaddr, ®_data.word0)) {
9444 if (bf_get(lpfc_sliport_status_rdy, ®_data))
9449 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
9450 phba->work_status[0] = readl(
9451 phba->sli4_hba.u.if_type2.ERR1regaddr);
9452 phba->work_status[1] = readl(
9453 phba->sli4_hba.u.if_type2.ERR2regaddr);
9454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9455 "2890 Port not ready, port status reg "
9456 "0x%x error 1=0x%x, error 2=0x%x\n",
9458 phba->work_status[0],
9459 phba->work_status[1]);
9466 * Reset the port now
9469 bf_set(lpfc_sliport_ctrl_end, ®_data,
9470 LPFC_SLIPORT_LITTLE_ENDIAN);
9471 bf_set(lpfc_sliport_ctrl_ip, ®_data,
9472 LPFC_SLIPORT_INIT_PORT);
9473 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9476 pci_read_config_word(phba->pcidev,
9477 PCI_DEVICE_ID, &devid);
9482 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
9488 case LPFC_SLI_INTF_IF_TYPE_1:
9494 /* Catch the not-ready port failure after a port reset. */
9496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9497 "3317 HBA not functional: IP Reset Failed "
9498 "try: echo fw_reset > board_mode\n");
9506 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9507 * @phba: pointer to lpfc hba data structure.
9509 * This routine is invoked to set up the PCI device memory space for device
9510 * with SLI-4 interface spec.
9514 * other values - error
9517 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9519 struct pci_dev *pdev;
9520 unsigned long bar0map_len, bar1map_len, bar2map_len;
9521 int error = -ENODEV;
9524 /* Obtain PCI device reference */
9528 pdev = phba->pcidev;
9530 /* Set the device DMA mask size */
9531 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9532 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9533 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9534 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
9540 * The BARs and register set definitions and offset locations are
9541 * dependent on the if_type.
9543 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9544 &phba->sli4_hba.sli_intf.word0)) {
9548 /* There is no SLI3 failback for SLI4 devices. */
9549 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9550 LPFC_SLI_INTF_VALID) {
9551 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9552 "2894 SLI_INTF reg contents invalid "
9553 "sli_intf reg 0x%x\n",
9554 phba->sli4_hba.sli_intf.word0);
9558 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9560 * Get the bus address of SLI4 device Bar regions and the
9561 * number of bytes required by each mapping. The mapping of the
9562 * particular PCI BARs regions is dependent on the type of
9565 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9566 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9567 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
9570 * Map SLI4 PCI Config Space Register base to a kernel virtual
9573 phba->sli4_hba.conf_regs_memmap_p =
9574 ioremap(phba->pci_bar0_map, bar0map_len);
9575 if (!phba->sli4_hba.conf_regs_memmap_p) {
9576 dev_printk(KERN_ERR, &pdev->dev,
9577 "ioremap failed for SLI4 PCI config "
9581 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
9582 /* Set up BAR0 PCI config space register memory map */
9583 lpfc_sli4_bar0_register_memmap(phba, if_type);
9585 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9586 bar0map_len = pci_resource_len(pdev, 1);
9587 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9588 dev_printk(KERN_ERR, &pdev->dev,
9589 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9592 phba->sli4_hba.conf_regs_memmap_p =
9593 ioremap(phba->pci_bar0_map, bar0map_len);
9594 if (!phba->sli4_hba.conf_regs_memmap_p) {
9595 dev_printk(KERN_ERR, &pdev->dev,
9596 "ioremap failed for SLI4 PCI config "
9600 lpfc_sli4_bar0_register_memmap(phba, if_type);
9603 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9604 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9606 * Map SLI4 if type 0 HBA Control Register base to a
9607 * kernel virtual address and setup the registers.
9609 phba->pci_bar1_map = pci_resource_start(pdev,
9611 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9612 phba->sli4_hba.ctrl_regs_memmap_p =
9613 ioremap(phba->pci_bar1_map,
9615 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9617 "ioremap failed for SLI4 HBA "
9618 "control registers.\n");
9620 goto out_iounmap_conf;
9622 phba->pci_bar2_memmap_p =
9623 phba->sli4_hba.ctrl_regs_memmap_p;
9624 lpfc_sli4_bar1_register_memmap(phba, if_type);
9627 goto out_iounmap_conf;
9631 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9632 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9634 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9635 * virtual address and setup the registers.
9637 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9638 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9639 phba->sli4_hba.drbl_regs_memmap_p =
9640 ioremap(phba->pci_bar1_map, bar1map_len);
9641 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9643 "ioremap failed for SLI4 HBA doorbell registers.\n");
9644 goto out_iounmap_conf;
9646 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9647 lpfc_sli4_bar1_register_memmap(phba, if_type);
9650 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9651 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9653 * Map SLI4 if type 0 HBA Doorbell Register base to
9654 * a kernel virtual address and setup the registers.
9656 phba->pci_bar2_map = pci_resource_start(pdev,
9658 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9659 phba->sli4_hba.drbl_regs_memmap_p =
9660 ioremap(phba->pci_bar2_map,
9662 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9664 "ioremap failed for SLI4 HBA"
9665 " doorbell registers.\n");
9667 goto out_iounmap_ctrl;
9669 phba->pci_bar4_memmap_p =
9670 phba->sli4_hba.drbl_regs_memmap_p;
9671 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9673 goto out_iounmap_all;
9676 goto out_iounmap_all;
9680 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9681 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9683 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9684 * virtual address and setup the registers.
9686 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9687 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9688 phba->sli4_hba.dpp_regs_memmap_p =
9689 ioremap(phba->pci_bar2_map, bar2map_len);
9690 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9692 "ioremap failed for SLI4 HBA dpp registers.\n");
9693 goto out_iounmap_ctrl;
9695 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9698 /* Set up the EQ/CQ register handeling functions now */
9700 case LPFC_SLI_INTF_IF_TYPE_0:
9701 case LPFC_SLI_INTF_IF_TYPE_2:
9702 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9703 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9704 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
9706 case LPFC_SLI_INTF_IF_TYPE_6:
9707 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9708 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9709 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9718 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9720 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9722 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9728 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9729 * @phba: pointer to lpfc hba data structure.
9731 * This routine is invoked to unset the PCI device memory space for device
9732 * with SLI-4 interface spec.
9735 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9738 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9741 case LPFC_SLI_INTF_IF_TYPE_0:
9742 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9743 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9744 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9746 case LPFC_SLI_INTF_IF_TYPE_2:
9747 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9749 case LPFC_SLI_INTF_IF_TYPE_6:
9750 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9751 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9753 case LPFC_SLI_INTF_IF_TYPE_1:
9755 dev_printk(KERN_ERR, &phba->pcidev->dev,
9756 "FATAL - unsupported SLI4 interface type - %d\n",
9763 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9764 * @phba: pointer to lpfc hba data structure.
9766 * This routine is invoked to enable the MSI-X interrupt vectors to device
9767 * with SLI-3 interface specs.
9771 * other values - error
9774 lpfc_sli_enable_msix(struct lpfc_hba *phba)
9779 /* Set up MSI-X multi-message vectors */
9780 rc = pci_alloc_irq_vectors(phba->pcidev,
9781 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9783 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9784 "0420 PCI enable MSI-X failed (%d)\n", rc);
9789 * Assign MSI-X vectors to interrupt handlers
9792 /* vector-0 is associated to slow-path handler */
9793 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
9794 &lpfc_sli_sp_intr_handler, 0,
9795 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9797 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9798 "0421 MSI-X slow-path request_irq failed "
9803 /* vector-1 is associated to fast-path handler */
9804 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
9805 &lpfc_sli_fp_intr_handler, 0,
9806 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9809 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9810 "0429 MSI-X fast-path request_irq failed "
9816 * Configure HBA MSI-X attention conditions to messages
9818 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9823 "0474 Unable to allocate memory for issuing "
9824 "MBOX_CONFIG_MSI command\n");
9827 rc = lpfc_config_msi(phba, pmb);
9830 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9831 if (rc != MBX_SUCCESS) {
9832 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9833 "0351 Config MSI mailbox command failed, "
9834 "mbxCmd x%x, mbxStatus x%x\n",
9835 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9839 /* Free memory allocated for mailbox command */
9840 mempool_free(pmb, phba->mbox_mem_pool);
9844 /* Free memory allocated for mailbox command */
9845 mempool_free(pmb, phba->mbox_mem_pool);
9848 /* free the irq already requested */
9849 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
9852 /* free the irq already requested */
9853 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
9856 /* Unconfigure MSI-X capability structure */
9857 pci_free_irq_vectors(phba->pcidev);
9864 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9865 * @phba: pointer to lpfc hba data structure.
9867 * This routine is invoked to enable the MSI interrupt mode to device with
9868 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9869 * enable the MSI vector. The device driver is responsible for calling the
9870 * request_irq() to register MSI vector with a interrupt the handler, which
9871 * is done in this function.
9875 * other values - error
9878 lpfc_sli_enable_msi(struct lpfc_hba *phba)
9882 rc = pci_enable_msi(phba->pcidev);
9884 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9885 "0462 PCI enable MSI mode success.\n");
9887 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9888 "0471 PCI enable MSI mode failed (%d)\n", rc);
9892 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9893 0, LPFC_DRIVER_NAME, phba);
9895 pci_disable_msi(phba->pcidev);
9896 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9897 "0478 MSI request_irq failed (%d)\n", rc);
9903 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9904 * @phba: pointer to lpfc hba data structure.
9906 * This routine is invoked to enable device interrupt and associate driver's
9907 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9908 * spec. Depends on the interrupt mode configured to the driver, the driver
9909 * will try to fallback from the configured interrupt mode to an interrupt
9910 * mode which is supported by the platform, kernel, and device in the order
9912 * MSI-X -> MSI -> IRQ.
9916 * other values - error
9919 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9921 uint32_t intr_mode = LPFC_INTR_ERROR;
9924 if (cfg_mode == 2) {
9925 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9926 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9928 /* Now, try to enable MSI-X interrupt mode */
9929 retval = lpfc_sli_enable_msix(phba);
9931 /* Indicate initialization to MSI-X mode */
9932 phba->intr_type = MSIX;
9938 /* Fallback to MSI if MSI-X initialization failed */
9939 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9940 retval = lpfc_sli_enable_msi(phba);
9942 /* Indicate initialization to MSI mode */
9943 phba->intr_type = MSI;
9948 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9949 if (phba->intr_type == NONE) {
9950 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9951 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9953 /* Indicate initialization to INTx mode */
9954 phba->intr_type = INTx;
9962 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9963 * @phba: pointer to lpfc hba data structure.
9965 * This routine is invoked to disable device interrupt and disassociate the
9966 * driver's interrupt handler(s) from interrupt vector(s) to device with
9967 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9968 * release the interrupt vector(s) for the message signaled interrupt.
9971 lpfc_sli_disable_intr(struct lpfc_hba *phba)
9975 if (phba->intr_type == MSIX)
9976 nr_irqs = LPFC_MSIX_VECTORS;
9980 for (i = 0; i < nr_irqs; i++)
9981 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9982 pci_free_irq_vectors(phba->pcidev);
9984 /* Reset interrupt management states */
9985 phba->intr_type = NONE;
9986 phba->sli.slistat.sli_intr = 0;
9990 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
9991 * @phba: pointer to lpfc hba data structure.
9992 * @vectors: number of msix vectors allocated.
9994 * The routine will figure out the CPU affinity assignment for every
9995 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9996 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9997 * can be associated with. If the vector can be unquely associated with
9998 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9999 * In addition, the CPU to IO channel mapping will be calculated
10000 * and the phba->sli4_hba.cpu_map array will reflect this.
10003 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
10005 struct lpfc_vector_map_info *cpup;
10010 struct cpuinfo_x86 *cpuinfo;
10013 /* Init cpu_map array */
10014 memset(phba->sli4_hba.cpu_map, 0xff,
10015 (sizeof(struct lpfc_vector_map_info) *
10016 phba->sli4_hba.num_present_cpu));
10018 /* Update CPU map with physical id and core id of each CPU */
10019 cpup = phba->sli4_hba.cpu_map;
10020 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10022 cpuinfo = &cpu_data(cpu);
10023 cpup->phys_id = cpuinfo->phys_proc_id;
10024 cpup->core_id = cpuinfo->cpu_core_id;
10026 /* No distinction between CPUs for other platforms */
10030 cpup->channel_id = index; /* For now round robin */
10031 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10033 if (vec >= vectors)
10036 if (index >= phba->cfg_fcp_io_channel)
10044 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10045 * @phba: pointer to lpfc hba data structure.
10047 * This routine is invoked to enable the MSI-X interrupt vectors to device
10048 * with SLI-4 interface spec.
10052 * other values - error
10055 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10057 int vectors, rc, index;
10060 /* Set up MSI-X multi-message vectors */
10061 vectors = phba->io_channel_irqs;
10065 rc = pci_alloc_irq_vectors(phba->pcidev,
10066 (phba->nvmet_support) ? 1 : 2,
10067 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
10069 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10070 "0484 PCI enable MSI-X failed (%d)\n", rc);
10075 /* Assign MSI-X vectors to interrupt handlers */
10076 for (index = 0; index < vectors; index++) {
10077 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10078 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10079 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
10080 LPFC_DRIVER_HANDLER_NAME"%d", index);
10082 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10083 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10084 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
10085 if (phba->cfg_fof && (index == (vectors - 1)))
10086 rc = request_irq(pci_irq_vector(phba->pcidev, index),
10087 &lpfc_sli4_fof_intr_handler, 0,
10089 &phba->sli4_hba.hba_eq_hdl[index]);
10091 rc = request_irq(pci_irq_vector(phba->pcidev, index),
10092 &lpfc_sli4_hba_intr_handler, 0,
10094 &phba->sli4_hba.hba_eq_hdl[index]);
10096 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10097 "0486 MSI-X fast-path (%d) "
10098 "request_irq failed (%d)\n", index, rc);
10106 if (vectors != phba->io_channel_irqs) {
10107 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10108 "3238 Reducing IO channels to match number of "
10109 "MSI-X vectors, requested %d got %d\n",
10110 phba->io_channel_irqs, vectors);
10111 if (phba->cfg_fcp_io_channel > vectors)
10112 phba->cfg_fcp_io_channel = vectors;
10113 if (phba->cfg_nvme_io_channel > vectors)
10114 phba->cfg_nvme_io_channel = vectors;
10115 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10116 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10118 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
10120 lpfc_cpu_affinity_check(phba, vectors);
10125 /* free the irq already requested */
10126 for (--index; index >= 0; index--)
10127 free_irq(pci_irq_vector(phba->pcidev, index),
10128 &phba->sli4_hba.hba_eq_hdl[index]);
10130 /* Unconfigure MSI-X capability structure */
10131 pci_free_irq_vectors(phba->pcidev);
10138 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10139 * @phba: pointer to lpfc hba data structure.
10141 * This routine is invoked to enable the MSI interrupt mode to device with
10142 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10143 * to enable the MSI vector. The device driver is responsible for calling
10144 * the request_irq() to register MSI vector with a interrupt the handler,
10145 * which is done in this function.
10149 * other values - error
10152 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10156 rc = pci_enable_msi(phba->pcidev);
10158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10159 "0487 PCI enable MSI mode success.\n");
10161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10162 "0488 PCI enable MSI mode failed (%d)\n", rc);
10166 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10167 0, LPFC_DRIVER_NAME, phba);
10169 pci_disable_msi(phba->pcidev);
10170 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10171 "0490 MSI request_irq failed (%d)\n", rc);
10175 for (index = 0; index < phba->io_channel_irqs; index++) {
10176 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10177 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10180 if (phba->cfg_fof) {
10181 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10182 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10188 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10189 * @phba: pointer to lpfc hba data structure.
10191 * This routine is invoked to enable device interrupt and associate driver's
10192 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10193 * interface spec. Depends on the interrupt mode configured to the driver,
10194 * the driver will try to fallback from the configured interrupt mode to an
10195 * interrupt mode which is supported by the platform, kernel, and device in
10197 * MSI-X -> MSI -> IRQ.
10201 * other values - error
10204 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10206 uint32_t intr_mode = LPFC_INTR_ERROR;
10209 if (cfg_mode == 2) {
10210 /* Preparation before conf_msi mbox cmd */
10213 /* Now, try to enable MSI-X interrupt mode */
10214 retval = lpfc_sli4_enable_msix(phba);
10216 /* Indicate initialization to MSI-X mode */
10217 phba->intr_type = MSIX;
10223 /* Fallback to MSI if MSI-X initialization failed */
10224 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10225 retval = lpfc_sli4_enable_msi(phba);
10227 /* Indicate initialization to MSI mode */
10228 phba->intr_type = MSI;
10233 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10234 if (phba->intr_type == NONE) {
10235 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10236 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10238 struct lpfc_hba_eq_hdl *eqhdl;
10240 /* Indicate initialization to INTx mode */
10241 phba->intr_type = INTx;
10244 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10245 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10247 eqhdl->phba = phba;
10248 atomic_set(&eqhdl->hba_eq_in_use, 1);
10250 if (phba->cfg_fof) {
10251 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10253 eqhdl->phba = phba;
10254 atomic_set(&eqhdl->hba_eq_in_use, 1);
10262 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10263 * @phba: pointer to lpfc hba data structure.
10265 * This routine is invoked to disable device interrupt and disassociate
10266 * the driver's interrupt handler(s) from interrupt vector(s) to device
10267 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10268 * will release the interrupt vector(s) for the message signaled interrupt.
10271 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10273 /* Disable the currently initialized interrupt mode */
10274 if (phba->intr_type == MSIX) {
10277 /* Free up MSI-X multi-message vectors */
10278 for (index = 0; index < phba->io_channel_irqs; index++)
10279 free_irq(pci_irq_vector(phba->pcidev, index),
10280 &phba->sli4_hba.hba_eq_hdl[index]);
10283 free_irq(pci_irq_vector(phba->pcidev, index),
10284 &phba->sli4_hba.hba_eq_hdl[index]);
10286 free_irq(phba->pcidev->irq, phba);
10289 pci_free_irq_vectors(phba->pcidev);
10291 /* Reset interrupt management states */
10292 phba->intr_type = NONE;
10293 phba->sli.slistat.sli_intr = 0;
10297 * lpfc_unset_hba - Unset SLI3 hba device initialization
10298 * @phba: pointer to lpfc hba data structure.
10300 * This routine is invoked to unset the HBA device initialization steps to
10301 * a device with SLI-3 interface spec.
10304 lpfc_unset_hba(struct lpfc_hba *phba)
10306 struct lpfc_vport *vport = phba->pport;
10307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10309 spin_lock_irq(shost->host_lock);
10310 vport->load_flag |= FC_UNLOADING;
10311 spin_unlock_irq(shost->host_lock);
10313 kfree(phba->vpi_bmask);
10314 kfree(phba->vpi_ids);
10316 lpfc_stop_hba_timers(phba);
10318 phba->pport->work_port_events = 0;
10320 lpfc_sli_hba_down(phba);
10322 lpfc_sli_brdrestart(phba);
10324 lpfc_sli_disable_intr(phba);
10330 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10331 * @phba: Pointer to HBA context object.
10333 * This function is called in the SLI4 code path to wait for completion
10334 * of device's XRIs exchange busy. It will check the XRI exchange busy
10335 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10336 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10337 * I/Os every 30 seconds, log error message, and wait forever. Only when
10338 * all XRI exchange busy complete, the driver unload shall proceed with
10339 * invoking the function reset ioctl mailbox command to the CNA and the
10340 * the rest of the driver unload resource release.
10343 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10346 int nvme_xri_cmpl = 1;
10347 int nvmet_xri_cmpl = 1;
10348 int fcp_xri_cmpl = 1;
10349 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10351 /* Driver just aborted IOs during the hba_unset process. Pause
10352 * here to give the HBA time to complete the IO and get entries
10353 * into the abts lists.
10355 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10357 /* Wait for NVME pending IO to flush back to transport. */
10358 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10359 lpfc_nvme_wait_for_io_drain(phba);
10361 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10363 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
10364 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10366 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
10368 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10371 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10373 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
10374 if (!nvmet_xri_cmpl)
10375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10376 "6424 NVMET XRI exchange busy "
10377 "wait time: %d seconds.\n",
10379 if (!nvme_xri_cmpl)
10380 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10381 "6100 NVME XRI exchange busy "
10382 "wait time: %d seconds.\n",
10385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10386 "2877 FCP XRI exchange busy "
10387 "wait time: %d seconds.\n",
10390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10391 "2878 ELS XRI exchange busy "
10392 "wait time: %d seconds.\n",
10394 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10395 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10397 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10398 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10400 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10401 nvme_xri_cmpl = list_empty(
10402 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
10403 nvmet_xri_cmpl = list_empty(
10404 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10407 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10408 fcp_xri_cmpl = list_empty(
10409 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10412 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10418 * lpfc_sli4_hba_unset - Unset the fcoe hba
10419 * @phba: Pointer to HBA context object.
10421 * This function is called in the SLI4 code path to reset the HBA's FCoE
10422 * function. The caller is not required to hold any lock. This routine
10423 * issues PCI function reset mailbox command to reset the FCoE function.
10424 * At the end of the function, it calls lpfc_hba_down_post function to
10425 * free any pending commands.
10428 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10431 LPFC_MBOXQ_t *mboxq;
10432 struct pci_dev *pdev = phba->pcidev;
10434 lpfc_stop_hba_timers(phba);
10435 phba->sli4_hba.intr_enable = 0;
10438 * Gracefully wait out the potential current outstanding asynchronous
10442 /* First, block any pending async mailbox command from posted */
10443 spin_lock_irq(&phba->hbalock);
10444 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10445 spin_unlock_irq(&phba->hbalock);
10446 /* Now, trying to wait it out if we can */
10447 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10449 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10452 /* Forcefully release the outstanding mailbox command if timed out */
10453 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10454 spin_lock_irq(&phba->hbalock);
10455 mboxq = phba->sli.mbox_active;
10456 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10457 __lpfc_mbox_cmpl_put(phba, mboxq);
10458 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10459 phba->sli.mbox_active = NULL;
10460 spin_unlock_irq(&phba->hbalock);
10463 /* Abort all iocbs associated with the hba */
10464 lpfc_sli_hba_iocb_abort(phba);
10466 /* Wait for completion of device XRI exchange busy */
10467 lpfc_sli4_xri_exchange_busy_wait(phba);
10469 /* Disable PCI subsystem interrupt */
10470 lpfc_sli4_disable_intr(phba);
10472 /* Disable SR-IOV if enabled */
10473 if (phba->cfg_sriov_nr_virtfn)
10474 pci_disable_sriov(pdev);
10476 /* Stop kthread signal shall trigger work_done one more time */
10477 kthread_stop(phba->worker_thread);
10479 /* Unset the queues shared with the hardware then release all
10480 * allocated resources.
10482 lpfc_sli4_queue_unset(phba);
10483 lpfc_sli4_queue_destroy(phba);
10485 /* Reset SLI4 HBA FCoE function */
10486 lpfc_pci_function_reset(phba);
10488 /* Stop the SLI4 device port */
10489 phba->pport->work_port_events = 0;
10493 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10494 * @phba: Pointer to HBA context object.
10495 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10497 * This function is called in the SLI4 code path to read the port's
10498 * sli4 capabilities.
10500 * This function may be be called from any context that can block-wait
10501 * for the completion. The expectation is that this routine is called
10502 * typically from probe_one or from the online routine.
10505 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10508 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10509 struct lpfc_pc_sli4_params *sli4_params;
10512 bool exp_wqcq_pages = true;
10513 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10516 * By default, the driver assumes the SLI4 port requires RPI
10517 * header postings. The SLI4_PARAM response will correct this
10520 phba->sli4_hba.rpi_hdrs_in_use = 1;
10522 /* Read the port's SLI4 Config Parameters */
10523 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10524 sizeof(struct lpfc_sli4_cfg_mhdr));
10525 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10526 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10527 length, LPFC_SLI4_MBX_EMBED);
10528 if (!phba->sli4_hba.intr_enable)
10529 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10531 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10532 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10536 sli4_params = &phba->sli4_hba.pc_sli4_params;
10537 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10538 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10539 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10540 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10541 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10542 mbx_sli4_parameters);
10543 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10544 mbx_sli4_parameters);
10545 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10546 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10548 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10549 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10550 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
10551 mbx_sli4_parameters);
10552 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
10553 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10554 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10555 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10556 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
10557 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10558 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
10559 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
10560 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
10561 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10562 mbx_sli4_parameters);
10563 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
10564 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10565 mbx_sli4_parameters);
10566 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10567 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
10568 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10569 bf_get(cfg_xib, mbx_sli4_parameters));
10571 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10572 !phba->nvme_support) {
10573 phba->nvme_support = 0;
10574 phba->nvmet_support = 0;
10575 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
10576 phba->cfg_nvme_io_channel = 0;
10577 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10579 "6101 Disabling NVME support: "
10580 "Not supported by firmware: %d %d\n",
10581 bf_get(cfg_nvme, mbx_sli4_parameters),
10582 bf_get(cfg_xib, mbx_sli4_parameters));
10584 /* If firmware doesn't support NVME, just use SCSI support */
10585 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10587 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10590 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
10591 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10592 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
10593 phba->cfg_enable_pbde = 0;
10596 * To support Suppress Response feature we must satisfy 3 conditions.
10597 * lpfc_suppress_rsp module parameter must be set (default).
10598 * In SLI4-Parameters Descriptor:
10599 * Extended Inline Buffers (XIB) must be supported.
10600 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10601 * (double negative).
10603 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10604 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
10605 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10607 phba->cfg_suppress_rsp = 0;
10609 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10610 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10612 /* Make sure that sge_supp_len can be handled by the driver */
10613 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10614 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10617 * Check whether the adapter supports an embedded copy of the
10618 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10619 * to use this option, 128-byte WQEs must be used.
10621 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10622 phba->fcp_embed_io = 1;
10624 phba->fcp_embed_io = 0;
10626 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
10627 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
10628 bf_get(cfg_xib, mbx_sli4_parameters),
10629 phba->cfg_enable_pbde,
10630 phba->fcp_embed_io, phba->nvme_support,
10631 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
10633 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10634 LPFC_SLI_INTF_IF_TYPE_2) &&
10635 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
10636 LPFC_SLI_INTF_FAMILY_LNCR_A0))
10637 exp_wqcq_pages = false;
10639 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10640 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
10642 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10643 phba->enab_exp_wqcq_pages = 1;
10645 phba->enab_exp_wqcq_pages = 0;
10647 * Check if the SLI port supports MDS Diagnostics
10649 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10650 phba->mds_diags_support = 1;
10652 phba->mds_diags_support = 0;
10657 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10658 * @pdev: pointer to PCI device
10659 * @pid: pointer to PCI device identifier
10661 * This routine is to be called to attach a device with SLI-3 interface spec
10662 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10663 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10664 * information of the device and driver to see if the driver state that it can
10665 * support this kind of device. If the match is successful, the driver core
10666 * invokes this routine. If this routine determines it can claim the HBA, it
10667 * does all the initialization that it needs to do to handle the HBA properly.
10670 * 0 - driver can claim the device
10671 * negative value - driver can not claim the device
10674 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10676 struct lpfc_hba *phba;
10677 struct lpfc_vport *vport = NULL;
10678 struct Scsi_Host *shost = NULL;
10680 uint32_t cfg_mode, intr_mode;
10682 /* Allocate memory for HBA structure */
10683 phba = lpfc_hba_alloc(pdev);
10687 /* Perform generic PCI device enabling operation */
10688 error = lpfc_enable_pci_dev(phba);
10690 goto out_free_phba;
10692 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10693 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10695 goto out_disable_pci_dev;
10697 /* Set up SLI-3 specific device PCI memory space */
10698 error = lpfc_sli_pci_mem_setup(phba);
10700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10701 "1402 Failed to set up pci memory space.\n");
10702 goto out_disable_pci_dev;
10705 /* Set up SLI-3 specific device driver resources */
10706 error = lpfc_sli_driver_resource_setup(phba);
10708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10709 "1404 Failed to set up driver resource.\n");
10710 goto out_unset_pci_mem_s3;
10713 /* Initialize and populate the iocb list per host */
10715 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10718 "1405 Failed to initialize iocb list.\n");
10719 goto out_unset_driver_resource_s3;
10722 /* Set up common device driver resources */
10723 error = lpfc_setup_driver_resource_phase2(phba);
10725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10726 "1406 Failed to set up driver resource.\n");
10727 goto out_free_iocb_list;
10730 /* Get the default values for Model Name and Description */
10731 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10733 /* Create SCSI host to the physical port */
10734 error = lpfc_create_shost(phba);
10736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10737 "1407 Failed to create scsi host.\n");
10738 goto out_unset_driver_resource;
10741 /* Configure sysfs attributes */
10742 vport = phba->pport;
10743 error = lpfc_alloc_sysfs_attr(vport);
10745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10746 "1476 Failed to allocate sysfs attr\n");
10747 goto out_destroy_shost;
10750 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
10751 /* Now, trying to enable interrupt and bring up the device */
10752 cfg_mode = phba->cfg_use_msi;
10754 /* Put device to a known state before enabling interrupt */
10755 lpfc_stop_port(phba);
10756 /* Configure and enable interrupt */
10757 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10758 if (intr_mode == LPFC_INTR_ERROR) {
10759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10760 "0431 Failed to enable interrupt.\n");
10762 goto out_free_sysfs_attr;
10764 /* SLI-3 HBA setup */
10765 if (lpfc_sli_hba_setup(phba)) {
10766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10767 "1477 Failed to set up hba\n");
10769 goto out_remove_device;
10772 /* Wait 50ms for the interrupts of previous mailbox commands */
10774 /* Check active interrupts on message signaled interrupts */
10775 if (intr_mode == 0 ||
10776 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10777 /* Log the current active interrupt mode */
10778 phba->intr_mode = intr_mode;
10779 lpfc_log_intr_mode(phba, intr_mode);
10782 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10783 "0447 Configure interrupt mode (%d) "
10784 "failed active interrupt test.\n",
10786 /* Disable the current interrupt mode */
10787 lpfc_sli_disable_intr(phba);
10788 /* Try next level of interrupt mode */
10789 cfg_mode = --intr_mode;
10793 /* Perform post initialization setup */
10794 lpfc_post_init_setup(phba);
10796 /* Check if there are static vports to be created. */
10797 lpfc_create_static_vport(phba);
10802 lpfc_unset_hba(phba);
10803 out_free_sysfs_attr:
10804 lpfc_free_sysfs_attr(vport);
10806 lpfc_destroy_shost(phba);
10807 out_unset_driver_resource:
10808 lpfc_unset_driver_resource_phase2(phba);
10809 out_free_iocb_list:
10810 lpfc_free_iocb_list(phba);
10811 out_unset_driver_resource_s3:
10812 lpfc_sli_driver_resource_unset(phba);
10813 out_unset_pci_mem_s3:
10814 lpfc_sli_pci_mem_unset(phba);
10815 out_disable_pci_dev:
10816 lpfc_disable_pci_dev(phba);
10818 scsi_host_put(shost);
10820 lpfc_hba_free(phba);
10825 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10826 * @pdev: pointer to PCI device
10828 * This routine is to be called to disattach a device with SLI-3 interface
10829 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10830 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10831 * device to be removed from the PCI subsystem properly.
10834 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
10836 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10838 struct lpfc_vport **vports;
10839 struct lpfc_hba *phba = vport->phba;
10842 spin_lock_irq(&phba->hbalock);
10843 vport->load_flag |= FC_UNLOADING;
10844 spin_unlock_irq(&phba->hbalock);
10846 lpfc_free_sysfs_attr(vport);
10848 /* Release all the vports against this physical port */
10849 vports = lpfc_create_vport_work_array(phba);
10850 if (vports != NULL)
10851 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10852 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10854 fc_vport_terminate(vports[i]->fc_vport);
10856 lpfc_destroy_vport_work_array(phba, vports);
10858 /* Remove FC host and then SCSI host with the physical port */
10859 fc_remove_host(shost);
10860 scsi_remove_host(shost);
10862 lpfc_cleanup(vport);
10865 * Bring down the SLI Layer. This step disable all interrupts,
10866 * clears the rings, discards all mailbox commands, and resets
10870 /* HBA interrupt will be disabled after this call */
10871 lpfc_sli_hba_down(phba);
10872 /* Stop kthread signal shall trigger work_done one more time */
10873 kthread_stop(phba->worker_thread);
10874 /* Final cleanup of txcmplq and reset the HBA */
10875 lpfc_sli_brdrestart(phba);
10877 kfree(phba->vpi_bmask);
10878 kfree(phba->vpi_ids);
10880 lpfc_stop_hba_timers(phba);
10881 spin_lock_irq(&phba->hbalock);
10882 list_del_init(&vport->listentry);
10883 spin_unlock_irq(&phba->hbalock);
10885 lpfc_debugfs_terminate(vport);
10887 /* Disable SR-IOV if enabled */
10888 if (phba->cfg_sriov_nr_virtfn)
10889 pci_disable_sriov(pdev);
10891 /* Disable interrupt */
10892 lpfc_sli_disable_intr(phba);
10894 scsi_host_put(shost);
10897 * Call scsi_free before mem_free since scsi bufs are released to their
10898 * corresponding pools here.
10900 lpfc_scsi_free(phba);
10901 lpfc_mem_free_all(phba);
10903 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10904 phba->hbqslimp.virt, phba->hbqslimp.phys);
10906 /* Free resources associated with SLI2 interface */
10907 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
10908 phba->slim2p.virt, phba->slim2p.phys);
10910 /* unmap adapter SLIM and Control Registers */
10911 iounmap(phba->ctrl_regs_memmap_p);
10912 iounmap(phba->slim_memmap_p);
10914 lpfc_hba_free(phba);
10916 pci_release_mem_regions(pdev);
10917 pci_disable_device(pdev);
10921 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
10922 * @pdev: pointer to PCI device
10923 * @msg: power management message
10925 * This routine is to be called from the kernel's PCI subsystem to support
10926 * system Power Management (PM) to device with SLI-3 interface spec. When
10927 * PM invokes this method, it quiesces the device by stopping the driver's
10928 * worker thread for the device, turning off device's interrupt and DMA,
10929 * and bring the device offline. Note that as the driver implements the
10930 * minimum PM requirements to a power-aware driver's PM support for the
10931 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10932 * to the suspend() method call will be treated as SUSPEND and the driver will
10933 * fully reinitialize its device during resume() method call, the driver will
10934 * set device to PCI_D3hot state in PCI config space instead of setting it
10935 * according to the @msg provided by the PM.
10938 * 0 - driver suspended the device
10942 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
10944 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10945 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10947 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10948 "0473 PCI device Power Management suspend.\n");
10950 /* Bring down the device */
10951 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10952 lpfc_offline(phba);
10953 kthread_stop(phba->worker_thread);
10955 /* Disable interrupt from device */
10956 lpfc_sli_disable_intr(phba);
10958 /* Save device state to PCI config space */
10959 pci_save_state(pdev);
10960 pci_set_power_state(pdev, PCI_D3hot);
10966 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
10967 * @pdev: pointer to PCI device
10969 * This routine is to be called from the kernel's PCI subsystem to support
10970 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10971 * invokes this method, it restores the device's PCI config space state and
10972 * fully reinitializes the device and brings it online. Note that as the
10973 * driver implements the minimum PM requirements to a power-aware driver's
10974 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10975 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10976 * driver will fully reinitialize its device during resume() method call,
10977 * the device will be set to PCI_D0 directly in PCI config space before
10978 * restoring the state.
10981 * 0 - driver suspended the device
10985 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
10987 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10988 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10989 uint32_t intr_mode;
10992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10993 "0452 PCI device Power Management resume.\n");
10995 /* Restore device state from PCI config space */
10996 pci_set_power_state(pdev, PCI_D0);
10997 pci_restore_state(pdev);
11000 * As the new kernel behavior of pci_restore_state() API call clears
11001 * device saved_state flag, need to save the restored state again.
11003 pci_save_state(pdev);
11005 if (pdev->is_busmaster)
11006 pci_set_master(pdev);
11008 /* Startup the kernel thread for this host adapter. */
11009 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11010 "lpfc_worker_%d", phba->brd_no);
11011 if (IS_ERR(phba->worker_thread)) {
11012 error = PTR_ERR(phba->worker_thread);
11013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11014 "0434 PM resume failed to start worker "
11015 "thread: error=x%x.\n", error);
11019 /* Configure and enable interrupt */
11020 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
11021 if (intr_mode == LPFC_INTR_ERROR) {
11022 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11023 "0430 PM resume Failed to enable interrupt\n");
11026 phba->intr_mode = intr_mode;
11028 /* Restart HBA and bring it online */
11029 lpfc_sli_brdrestart(phba);
11032 /* Log the current active interrupt mode */
11033 lpfc_log_intr_mode(phba, phba->intr_mode);
11039 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11040 * @phba: pointer to lpfc hba data structure.
11042 * This routine is called to prepare the SLI3 device for PCI slot recover. It
11043 * aborts all the outstanding SCSI I/Os to the pci device.
11046 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11049 "2723 PCI channel I/O abort preparing for recovery\n");
11052 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11053 * and let the SCSI mid-layer to retry them to recover.
11055 lpfc_sli_abort_fcp_rings(phba);
11059 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11060 * @phba: pointer to lpfc hba data structure.
11062 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11063 * disables the device interrupt and pci device, and aborts the internal FCP
11067 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11070 "2710 PCI channel disable preparing for reset\n");
11072 /* Block any management I/Os to the device */
11073 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
11075 /* Block all SCSI devices' I/Os on the host */
11076 lpfc_scsi_dev_block(phba);
11078 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11079 lpfc_sli_flush_fcp_rings(phba);
11081 /* stop all timers */
11082 lpfc_stop_hba_timers(phba);
11084 /* Disable interrupt and pci device */
11085 lpfc_sli_disable_intr(phba);
11086 pci_disable_device(phba->pcidev);
11090 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11091 * @phba: pointer to lpfc hba data structure.
11093 * This routine is called to prepare the SLI3 device for PCI slot permanently
11094 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11098 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11101 "2711 PCI channel permanent disable for failure\n");
11102 /* Block all SCSI devices' I/Os on the host */
11103 lpfc_scsi_dev_block(phba);
11105 /* stop all timers */
11106 lpfc_stop_hba_timers(phba);
11108 /* Clean up all driver's outstanding SCSI I/Os */
11109 lpfc_sli_flush_fcp_rings(phba);
11113 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
11114 * @pdev: pointer to PCI device.
11115 * @state: the current PCI connection state.
11117 * This routine is called from the PCI subsystem for I/O error handling to
11118 * device with SLI-3 interface spec. This function is called by the PCI
11119 * subsystem after a PCI bus error affecting this device has been detected.
11120 * When this function is invoked, it will need to stop all the I/Os and
11121 * interrupt(s) to the device. Once that is done, it will return
11122 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11126 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
11127 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11128 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11130 static pci_ers_result_t
11131 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
11133 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11134 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11137 case pci_channel_io_normal:
11138 /* Non-fatal error, prepare for recovery */
11139 lpfc_sli_prep_dev_for_recover(phba);
11140 return PCI_ERS_RESULT_CAN_RECOVER;
11141 case pci_channel_io_frozen:
11142 /* Fatal error, prepare for slot reset */
11143 lpfc_sli_prep_dev_for_reset(phba);
11144 return PCI_ERS_RESULT_NEED_RESET;
11145 case pci_channel_io_perm_failure:
11146 /* Permanent failure, prepare for device down */
11147 lpfc_sli_prep_dev_for_perm_failure(phba);
11148 return PCI_ERS_RESULT_DISCONNECT;
11150 /* Unknown state, prepare and request slot reset */
11151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11152 "0472 Unknown PCI error state: x%x\n", state);
11153 lpfc_sli_prep_dev_for_reset(phba);
11154 return PCI_ERS_RESULT_NEED_RESET;
11159 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
11160 * @pdev: pointer to PCI device.
11162 * This routine is called from the PCI subsystem for error handling to
11163 * device with SLI-3 interface spec. This is called after PCI bus has been
11164 * reset to restart the PCI card from scratch, as if from a cold-boot.
11165 * During the PCI subsystem error recovery, after driver returns
11166 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11167 * recovery and then call this routine before calling the .resume method
11168 * to recover the device. This function will initialize the HBA device,
11169 * enable the interrupt, but it will just put the HBA to offline state
11170 * without passing any I/O traffic.
11173 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11174 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11176 static pci_ers_result_t
11177 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
11179 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11180 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11181 struct lpfc_sli *psli = &phba->sli;
11182 uint32_t intr_mode;
11184 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11185 if (pci_enable_device_mem(pdev)) {
11186 printk(KERN_ERR "lpfc: Cannot re-enable "
11187 "PCI device after reset.\n");
11188 return PCI_ERS_RESULT_DISCONNECT;
11191 pci_restore_state(pdev);
11194 * As the new kernel behavior of pci_restore_state() API call clears
11195 * device saved_state flag, need to save the restored state again.
11197 pci_save_state(pdev);
11199 if (pdev->is_busmaster)
11200 pci_set_master(pdev);
11202 spin_lock_irq(&phba->hbalock);
11203 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11204 spin_unlock_irq(&phba->hbalock);
11206 /* Configure and enable interrupt */
11207 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
11208 if (intr_mode == LPFC_INTR_ERROR) {
11209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11210 "0427 Cannot re-enable interrupt after "
11212 return PCI_ERS_RESULT_DISCONNECT;
11214 phba->intr_mode = intr_mode;
11216 /* Take device offline, it will perform cleanup */
11217 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11218 lpfc_offline(phba);
11219 lpfc_sli_brdrestart(phba);
11221 /* Log the current active interrupt mode */
11222 lpfc_log_intr_mode(phba, phba->intr_mode);
11224 return PCI_ERS_RESULT_RECOVERED;
11228 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
11229 * @pdev: pointer to PCI device
11231 * This routine is called from the PCI subsystem for error handling to device
11232 * with SLI-3 interface spec. It is called when kernel error recovery tells
11233 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11234 * error recovery. After this call, traffic can start to flow from this device
11238 lpfc_io_resume_s3(struct pci_dev *pdev)
11240 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11241 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11243 /* Bring device online, it will be no-op for non-fatal error resume */
11246 /* Clean up Advanced Error Reporting (AER) if needed */
11247 if (phba->hba_flag & HBA_AER_ENABLED)
11248 pci_cleanup_aer_uncorrect_error_status(pdev);
11252 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11253 * @phba: pointer to lpfc hba data structure.
11255 * returns the number of ELS/CT IOCBs to reserve
11258 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11260 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11262 if (phba->sli_rev == LPFC_SLI_REV4) {
11263 if (max_xri <= 100)
11265 else if (max_xri <= 256)
11267 else if (max_xri <= 512)
11269 else if (max_xri <= 1024)
11271 else if (max_xri <= 1536)
11273 else if (max_xri <= 2048)
11282 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11283 * @phba: pointer to lpfc hba data structure.
11285 * returns the number of ELS/CT + NVMET IOCBs to reserve
11288 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11290 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11292 if (phba->nvmet_support)
11293 max_xri += LPFC_NVMET_BUF_POST;
11299 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11300 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11301 const struct firmware *fw)
11303 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11304 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11305 magic_number != MAGIC_NUMER_G6) ||
11306 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11307 magic_number != MAGIC_NUMER_G7))
11308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11309 "3030 This firmware version is not supported on "
11310 "this HBA model. Device:%x Magic:%x Type:%x "
11311 "ID:%x Size %d %zd\n",
11312 phba->pcidev->device, magic_number, ftype, fid,
11315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11316 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11317 "ID:%x Size %d %zd\n",
11318 phba->pcidev->device, magic_number, ftype, fid,
11324 * lpfc_write_firmware - attempt to write a firmware image to the port
11325 * @fw: pointer to firmware image returned from request_firmware.
11326 * @phba: pointer to lpfc hba data structure.
11330 lpfc_write_firmware(const struct firmware *fw, void *context)
11332 struct lpfc_hba *phba = (struct lpfc_hba *)context;
11333 char fwrev[FW_REV_STR_SIZE];
11334 struct lpfc_grp_hdr *image;
11335 struct list_head dma_buffer_list;
11337 struct lpfc_dmabuf *dmabuf, *next;
11338 uint32_t offset = 0, temp_offset = 0;
11339 uint32_t magic_number, ftype, fid, fsize;
11341 /* It can be null in no-wait mode, sanity check */
11346 image = (struct lpfc_grp_hdr *)fw->data;
11348 magic_number = be32_to_cpu(image->magic_number);
11349 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
11350 fid = bf_get_be32(lpfc_grp_hdr_id, image);
11351 fsize = be32_to_cpu(image->size);
11353 INIT_LIST_HEAD(&dma_buffer_list);
11354 lpfc_decode_firmware_rev(phba, fwrev, 1);
11355 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
11356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11357 "3023 Updating Firmware, Current Version:%s "
11358 "New Version:%s\n",
11359 fwrev, image->revision);
11360 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11361 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11367 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11371 if (!dmabuf->virt) {
11376 list_add_tail(&dmabuf->list, &dma_buffer_list);
11378 while (offset < fw->size) {
11379 temp_offset = offset;
11380 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
11381 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
11382 memcpy(dmabuf->virt,
11383 fw->data + temp_offset,
11384 fw->size - temp_offset);
11385 temp_offset = fw->size;
11388 memcpy(dmabuf->virt, fw->data + temp_offset,
11390 temp_offset += SLI4_PAGE_SIZE;
11392 rc = lpfc_wr_object(phba, &dma_buffer_list,
11393 (fw->size - offset), &offset);
11395 lpfc_log_write_firmware_error(phba, offset,
11396 magic_number, ftype, fid, fsize, fw);
11402 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11403 "3029 Skipped Firmware update, Current "
11404 "Version:%s New Version:%s\n",
11405 fwrev, image->revision);
11408 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11409 list_del(&dmabuf->list);
11410 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11411 dmabuf->virt, dmabuf->phys);
11414 release_firmware(fw);
11416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11417 "3024 Firmware update done: %d.\n", rc);
11422 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11423 * @phba: pointer to lpfc hba data structure.
11425 * This routine is called to perform Linux generic firmware upgrade on device
11426 * that supports such feature.
11429 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11431 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11433 const struct firmware *fw;
11435 /* Only supported on SLI4 interface type 2 for now */
11436 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
11437 LPFC_SLI_INTF_IF_TYPE_2)
11440 snprintf(file_name, ELX_MODEL_NAME_SIZE, "/*(DEBLOBBED)*/", phba->ModelName);
11442 if (fw_upgrade == INT_FW_UPGRADE) {
11443 ret = reject_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11444 file_name, &phba->pcidev->dev,
11445 GFP_KERNEL, (void *)phba,
11446 lpfc_write_firmware);
11447 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11448 ret = reject_firmware(&fw, file_name, &phba->pcidev->dev);
11450 lpfc_write_firmware(fw, (void *)phba);
11459 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11460 * @pdev: pointer to PCI device
11461 * @pid: pointer to PCI device identifier
11463 * This routine is called from the kernel's PCI subsystem to device with
11464 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11465 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11466 * information of the device and driver to see if the driver state that it
11467 * can support this kind of device. If the match is successful, the driver
11468 * core invokes this routine. If this routine determines it can claim the HBA,
11469 * it does all the initialization that it needs to do to handle the HBA
11473 * 0 - driver can claim the device
11474 * negative value - driver can not claim the device
11477 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11479 struct lpfc_hba *phba;
11480 struct lpfc_vport *vport = NULL;
11481 struct Scsi_Host *shost = NULL;
11483 uint32_t cfg_mode, intr_mode;
11485 /* Allocate memory for HBA structure */
11486 phba = lpfc_hba_alloc(pdev);
11490 /* Perform generic PCI device enabling operation */
11491 error = lpfc_enable_pci_dev(phba);
11493 goto out_free_phba;
11495 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11496 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11498 goto out_disable_pci_dev;
11500 /* Set up SLI-4 specific device PCI memory space */
11501 error = lpfc_sli4_pci_mem_setup(phba);
11503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11504 "1410 Failed to set up pci memory space.\n");
11505 goto out_disable_pci_dev;
11508 /* Set up SLI-4 Specific device driver resources */
11509 error = lpfc_sli4_driver_resource_setup(phba);
11511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11512 "1412 Failed to set up driver resource.\n");
11513 goto out_unset_pci_mem_s4;
11516 INIT_LIST_HEAD(&phba->active_rrq_list);
11517 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
11519 /* Set up common device driver resources */
11520 error = lpfc_setup_driver_resource_phase2(phba);
11522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11523 "1414 Failed to set up driver resource.\n");
11524 goto out_unset_driver_resource_s4;
11527 /* Get the default values for Model Name and Description */
11528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11530 /* Create SCSI host to the physical port */
11531 error = lpfc_create_shost(phba);
11533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11534 "1415 Failed to create scsi host.\n");
11535 goto out_unset_driver_resource;
11538 /* Configure sysfs attributes */
11539 vport = phba->pport;
11540 error = lpfc_alloc_sysfs_attr(vport);
11542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11543 "1416 Failed to allocate sysfs attr\n");
11544 goto out_destroy_shost;
11547 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
11548 /* Now, trying to enable interrupt and bring up the device */
11549 cfg_mode = phba->cfg_use_msi;
11551 /* Put device to a known state before enabling interrupt */
11552 lpfc_stop_port(phba);
11554 /* Configure and enable interrupt */
11555 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11556 if (intr_mode == LPFC_INTR_ERROR) {
11557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11558 "0426 Failed to enable interrupt.\n");
11560 goto out_free_sysfs_attr;
11562 /* Default to single EQ for non-MSI-X */
11563 if (phba->intr_type != MSIX) {
11564 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11565 phba->cfg_fcp_io_channel = 1;
11566 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11567 phba->cfg_nvme_io_channel = 1;
11568 if (phba->nvmet_support)
11569 phba->cfg_nvmet_mrq = 1;
11571 phba->io_channel_irqs = 1;
11574 /* Set up SLI-4 HBA */
11575 if (lpfc_sli4_hba_setup(phba)) {
11576 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11577 "1421 Failed to set up hba\n");
11579 goto out_disable_intr;
11582 /* Log the current active interrupt mode */
11583 phba->intr_mode = intr_mode;
11584 lpfc_log_intr_mode(phba, intr_mode);
11586 /* Perform post initialization setup */
11587 lpfc_post_init_setup(phba);
11589 /* NVME support in FW earlier in the driver load corrects the
11590 * FC4 type making a check for nvme_support unnecessary.
11592 if ((phba->nvmet_support == 0) &&
11593 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11594 /* Create NVME binding with nvme_fc_transport. This
11595 * ensures the vport is initialized. If the localport
11596 * create fails, it should not unload the driver to
11597 * support field issues.
11599 error = lpfc_nvme_create_localport(vport);
11601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11602 "6004 NVME registration failed, "
11608 /* check for firmware upgrade or downgrade */
11609 if (phba->cfg_request_firmware_upgrade)
11610 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
11612 /* Check if there are static vports to be created. */
11613 lpfc_create_static_vport(phba);
11617 lpfc_sli4_disable_intr(phba);
11618 out_free_sysfs_attr:
11619 lpfc_free_sysfs_attr(vport);
11621 lpfc_destroy_shost(phba);
11622 out_unset_driver_resource:
11623 lpfc_unset_driver_resource_phase2(phba);
11624 out_unset_driver_resource_s4:
11625 lpfc_sli4_driver_resource_unset(phba);
11626 out_unset_pci_mem_s4:
11627 lpfc_sli4_pci_mem_unset(phba);
11628 out_disable_pci_dev:
11629 lpfc_disable_pci_dev(phba);
11631 scsi_host_put(shost);
11633 lpfc_hba_free(phba);
11638 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11639 * @pdev: pointer to PCI device
11641 * This routine is called from the kernel's PCI subsystem to device with
11642 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11643 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11644 * device to be removed from the PCI subsystem properly.
11647 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11649 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11651 struct lpfc_vport **vports;
11652 struct lpfc_hba *phba = vport->phba;
11655 /* Mark the device unloading flag */
11656 spin_lock_irq(&phba->hbalock);
11657 vport->load_flag |= FC_UNLOADING;
11658 spin_unlock_irq(&phba->hbalock);
11660 /* Free the HBA sysfs attributes */
11661 lpfc_free_sysfs_attr(vport);
11663 /* Release all the vports against this physical port */
11664 vports = lpfc_create_vport_work_array(phba);
11665 if (vports != NULL)
11666 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11667 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11669 fc_vport_terminate(vports[i]->fc_vport);
11671 lpfc_destroy_vport_work_array(phba, vports);
11673 /* Remove FC host and then SCSI host with the physical port */
11674 fc_remove_host(shost);
11675 scsi_remove_host(shost);
11677 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11678 * localports are destroyed after to cleanup all transport memory.
11680 lpfc_cleanup(vport);
11681 lpfc_nvmet_destroy_targetport(phba);
11682 lpfc_nvme_destroy_localport(vport);
11685 * Bring down the SLI Layer. This step disables all interrupts,
11686 * clears the rings, discards all mailbox commands, and resets
11687 * the HBA FCoE function.
11689 lpfc_debugfs_terminate(vport);
11690 lpfc_sli4_hba_unset(phba);
11692 lpfc_stop_hba_timers(phba);
11693 spin_lock_irq(&phba->hbalock);
11694 list_del_init(&vport->listentry);
11695 spin_unlock_irq(&phba->hbalock);
11697 /* Perform scsi free before driver resource_unset since scsi
11698 * buffers are released to their corresponding pools here.
11700 lpfc_scsi_free(phba);
11701 lpfc_nvme_free(phba);
11702 lpfc_free_iocb_list(phba);
11704 lpfc_unset_driver_resource_phase2(phba);
11705 lpfc_sli4_driver_resource_unset(phba);
11707 /* Unmap adapter Control and Doorbell registers */
11708 lpfc_sli4_pci_mem_unset(phba);
11710 /* Release PCI resources and disable device's PCI function */
11711 scsi_host_put(shost);
11712 lpfc_disable_pci_dev(phba);
11714 /* Finally, free the driver's device data structure */
11715 lpfc_hba_free(phba);
11721 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11722 * @pdev: pointer to PCI device
11723 * @msg: power management message
11725 * This routine is called from the kernel's PCI subsystem to support system
11726 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11727 * this method, it quiesces the device by stopping the driver's worker
11728 * thread for the device, turning off device's interrupt and DMA, and bring
11729 * the device offline. Note that as the driver implements the minimum PM
11730 * requirements to a power-aware driver's PM support for suspend/resume -- all
11731 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11732 * method call will be treated as SUSPEND and the driver will fully
11733 * reinitialize its device during resume() method call, the driver will set
11734 * device to PCI_D3hot state in PCI config space instead of setting it
11735 * according to the @msg provided by the PM.
11738 * 0 - driver suspended the device
11742 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11744 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11745 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11747 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11748 "2843 PCI device Power Management suspend.\n");
11750 /* Bring down the device */
11751 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11752 lpfc_offline(phba);
11753 kthread_stop(phba->worker_thread);
11755 /* Disable interrupt from device */
11756 lpfc_sli4_disable_intr(phba);
11757 lpfc_sli4_queue_destroy(phba);
11759 /* Save device state to PCI config space */
11760 pci_save_state(pdev);
11761 pci_set_power_state(pdev, PCI_D3hot);
11767 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11768 * @pdev: pointer to PCI device
11770 * This routine is called from the kernel's PCI subsystem to support system
11771 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11772 * this method, it restores the device's PCI config space state and fully
11773 * reinitializes the device and brings it online. Note that as the driver
11774 * implements the minimum PM requirements to a power-aware driver's PM for
11775 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11776 * to the suspend() method call will be treated as SUSPEND and the driver
11777 * will fully reinitialize its device during resume() method call, the device
11778 * will be set to PCI_D0 directly in PCI config space before restoring the
11782 * 0 - driver suspended the device
11786 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11788 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11789 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11790 uint32_t intr_mode;
11793 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11794 "0292 PCI device Power Management resume.\n");
11796 /* Restore device state from PCI config space */
11797 pci_set_power_state(pdev, PCI_D0);
11798 pci_restore_state(pdev);
11801 * As the new kernel behavior of pci_restore_state() API call clears
11802 * device saved_state flag, need to save the restored state again.
11804 pci_save_state(pdev);
11806 if (pdev->is_busmaster)
11807 pci_set_master(pdev);
11809 /* Startup the kernel thread for this host adapter. */
11810 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11811 "lpfc_worker_%d", phba->brd_no);
11812 if (IS_ERR(phba->worker_thread)) {
11813 error = PTR_ERR(phba->worker_thread);
11814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11815 "0293 PM resume failed to start worker "
11816 "thread: error=x%x.\n", error);
11820 /* Configure and enable interrupt */
11821 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11822 if (intr_mode == LPFC_INTR_ERROR) {
11823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11824 "0294 PM resume Failed to enable interrupt\n");
11827 phba->intr_mode = intr_mode;
11829 /* Restart HBA and bring it online */
11830 lpfc_sli_brdrestart(phba);
11833 /* Log the current active interrupt mode */
11834 lpfc_log_intr_mode(phba, phba->intr_mode);
11840 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11841 * @phba: pointer to lpfc hba data structure.
11843 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11844 * aborts all the outstanding SCSI I/Os to the pci device.
11847 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11849 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11850 "2828 PCI channel I/O abort preparing for recovery\n");
11852 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11853 * and let the SCSI mid-layer to retry them to recover.
11855 lpfc_sli_abort_fcp_rings(phba);
11859 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11860 * @phba: pointer to lpfc hba data structure.
11862 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11863 * disables the device interrupt and pci device, and aborts the internal FCP
11867 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11870 "2826 PCI channel disable preparing for reset\n");
11872 /* Block any management I/Os to the device */
11873 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
11875 /* Block all SCSI devices' I/Os on the host */
11876 lpfc_scsi_dev_block(phba);
11878 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11879 lpfc_sli_flush_fcp_rings(phba);
11881 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11882 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11883 lpfc_sli_flush_nvme_rings(phba);
11885 /* stop all timers */
11886 lpfc_stop_hba_timers(phba);
11888 /* Disable interrupt and pci device */
11889 lpfc_sli4_disable_intr(phba);
11890 lpfc_sli4_queue_destroy(phba);
11891 pci_disable_device(phba->pcidev);
11895 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11896 * @phba: pointer to lpfc hba data structure.
11898 * This routine is called to prepare the SLI4 device for PCI slot permanently
11899 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11903 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11906 "2827 PCI channel permanent disable for failure\n");
11908 /* Block all SCSI devices' I/Os on the host */
11909 lpfc_scsi_dev_block(phba);
11911 /* stop all timers */
11912 lpfc_stop_hba_timers(phba);
11914 /* Clean up all driver's outstanding SCSI I/Os */
11915 lpfc_sli_flush_fcp_rings(phba);
11917 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11918 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11919 lpfc_sli_flush_nvme_rings(phba);
11923 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11924 * @pdev: pointer to PCI device.
11925 * @state: the current PCI connection state.
11927 * This routine is called from the PCI subsystem for error handling to device
11928 * with SLI-4 interface spec. This function is called by the PCI subsystem
11929 * after a PCI bus error affecting this device has been detected. When this
11930 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11931 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11932 * for the PCI subsystem to perform proper recovery as desired.
11935 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11936 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11938 static pci_ers_result_t
11939 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11941 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11942 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11945 case pci_channel_io_normal:
11946 /* Non-fatal error, prepare for recovery */
11947 lpfc_sli4_prep_dev_for_recover(phba);
11948 return PCI_ERS_RESULT_CAN_RECOVER;
11949 case pci_channel_io_frozen:
11950 /* Fatal error, prepare for slot reset */
11951 lpfc_sli4_prep_dev_for_reset(phba);
11952 return PCI_ERS_RESULT_NEED_RESET;
11953 case pci_channel_io_perm_failure:
11954 /* Permanent failure, prepare for device down */
11955 lpfc_sli4_prep_dev_for_perm_failure(phba);
11956 return PCI_ERS_RESULT_DISCONNECT;
11958 /* Unknown state, prepare and request slot reset */
11959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11960 "2825 Unknown PCI error state: x%x\n", state);
11961 lpfc_sli4_prep_dev_for_reset(phba);
11962 return PCI_ERS_RESULT_NEED_RESET;
11967 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11968 * @pdev: pointer to PCI device.
11970 * This routine is called from the PCI subsystem for error handling to device
11971 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11972 * restart the PCI card from scratch, as if from a cold-boot. During the
11973 * PCI subsystem error recovery, after the driver returns
11974 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11975 * recovery and then call this routine before calling the .resume method to
11976 * recover the device. This function will initialize the HBA device, enable
11977 * the interrupt, but it will just put the HBA to offline state without
11978 * passing any I/O traffic.
11981 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11982 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11984 static pci_ers_result_t
11985 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11987 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11988 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11989 struct lpfc_sli *psli = &phba->sli;
11990 uint32_t intr_mode;
11992 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11993 if (pci_enable_device_mem(pdev)) {
11994 printk(KERN_ERR "lpfc: Cannot re-enable "
11995 "PCI device after reset.\n");
11996 return PCI_ERS_RESULT_DISCONNECT;
11999 pci_restore_state(pdev);
12002 * As the new kernel behavior of pci_restore_state() API call clears
12003 * device saved_state flag, need to save the restored state again.
12005 pci_save_state(pdev);
12007 if (pdev->is_busmaster)
12008 pci_set_master(pdev);
12010 spin_lock_irq(&phba->hbalock);
12011 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12012 spin_unlock_irq(&phba->hbalock);
12014 /* Configure and enable interrupt */
12015 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12016 if (intr_mode == LPFC_INTR_ERROR) {
12017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12018 "2824 Cannot re-enable interrupt after "
12020 return PCI_ERS_RESULT_DISCONNECT;
12022 phba->intr_mode = intr_mode;
12024 /* Log the current active interrupt mode */
12025 lpfc_log_intr_mode(phba, phba->intr_mode);
12027 return PCI_ERS_RESULT_RECOVERED;
12031 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12032 * @pdev: pointer to PCI device
12034 * This routine is called from the PCI subsystem for error handling to device
12035 * with SLI-4 interface spec. It is called when kernel error recovery tells
12036 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12037 * error recovery. After this call, traffic can start to flow from this device
12041 lpfc_io_resume_s4(struct pci_dev *pdev)
12043 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12044 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12047 * In case of slot reset, as function reset is performed through
12048 * mailbox command which needs DMA to be enabled, this operation
12049 * has to be moved to the io resume phase. Taking device offline
12050 * will perform the necessary cleanup.
12052 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12053 /* Perform device reset */
12054 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
12055 lpfc_offline(phba);
12056 lpfc_sli_brdrestart(phba);
12057 /* Bring the device back online */
12061 /* Clean up Advanced Error Reporting (AER) if needed */
12062 if (phba->hba_flag & HBA_AER_ENABLED)
12063 pci_cleanup_aer_uncorrect_error_status(pdev);
12067 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12068 * @pdev: pointer to PCI device
12069 * @pid: pointer to PCI device identifier
12071 * This routine is to be registered to the kernel's PCI subsystem. When an
12072 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12073 * at PCI device-specific information of the device and driver to see if the
12074 * driver state that it can support this kind of device. If the match is
12075 * successful, the driver core invokes this routine. This routine dispatches
12076 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12077 * do all the initialization that it needs to do to handle the HBA device
12081 * 0 - driver can claim the device
12082 * negative value - driver can not claim the device
12085 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12088 struct lpfc_sli_intf intf;
12090 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
12093 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
12094 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
12095 rc = lpfc_pci_probe_one_s4(pdev, pid);
12097 rc = lpfc_pci_probe_one_s3(pdev, pid);
12103 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12104 * @pdev: pointer to PCI device
12106 * This routine is to be registered to the kernel's PCI subsystem. When an
12107 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12108 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12109 * remove routine, which will perform all the necessary cleanup for the
12110 * device to be removed from the PCI subsystem properly.
12113 lpfc_pci_remove_one(struct pci_dev *pdev)
12115 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12116 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12118 switch (phba->pci_dev_grp) {
12119 case LPFC_PCI_DEV_LP:
12120 lpfc_pci_remove_one_s3(pdev);
12122 case LPFC_PCI_DEV_OC:
12123 lpfc_pci_remove_one_s4(pdev);
12126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12127 "1424 Invalid PCI device group: 0x%x\n",
12128 phba->pci_dev_grp);
12135 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12136 * @pdev: pointer to PCI device
12137 * @msg: power management message
12139 * This routine is to be registered to the kernel's PCI subsystem to support
12140 * system Power Management (PM). When PM invokes this method, it dispatches
12141 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12142 * suspend the device.
12145 * 0 - driver suspended the device
12149 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12151 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12152 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12155 switch (phba->pci_dev_grp) {
12156 case LPFC_PCI_DEV_LP:
12157 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12159 case LPFC_PCI_DEV_OC:
12160 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12164 "1425 Invalid PCI device group: 0x%x\n",
12165 phba->pci_dev_grp);
12172 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12173 * @pdev: pointer to PCI device
12175 * This routine is to be registered to the kernel's PCI subsystem to support
12176 * system Power Management (PM). When PM invokes this method, it dispatches
12177 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12178 * resume the device.
12181 * 0 - driver suspended the device
12185 lpfc_pci_resume_one(struct pci_dev *pdev)
12187 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12188 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12191 switch (phba->pci_dev_grp) {
12192 case LPFC_PCI_DEV_LP:
12193 rc = lpfc_pci_resume_one_s3(pdev);
12195 case LPFC_PCI_DEV_OC:
12196 rc = lpfc_pci_resume_one_s4(pdev);
12199 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12200 "1426 Invalid PCI device group: 0x%x\n",
12201 phba->pci_dev_grp);
12208 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12209 * @pdev: pointer to PCI device.
12210 * @state: the current PCI connection state.
12212 * This routine is registered to the PCI subsystem for error handling. This
12213 * function is called by the PCI subsystem after a PCI bus error affecting
12214 * this device has been detected. When this routine is invoked, it dispatches
12215 * the action to the proper SLI-3 or SLI-4 device error detected handling
12216 * routine, which will perform the proper error detected operation.
12219 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12220 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12222 static pci_ers_result_t
12223 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12225 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12226 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12227 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12229 switch (phba->pci_dev_grp) {
12230 case LPFC_PCI_DEV_LP:
12231 rc = lpfc_io_error_detected_s3(pdev, state);
12233 case LPFC_PCI_DEV_OC:
12234 rc = lpfc_io_error_detected_s4(pdev, state);
12237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12238 "1427 Invalid PCI device group: 0x%x\n",
12239 phba->pci_dev_grp);
12246 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12247 * @pdev: pointer to PCI device.
12249 * This routine is registered to the PCI subsystem for error handling. This
12250 * function is called after PCI bus has been reset to restart the PCI card
12251 * from scratch, as if from a cold-boot. When this routine is invoked, it
12252 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12253 * routine, which will perform the proper device reset.
12256 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12257 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12259 static pci_ers_result_t
12260 lpfc_io_slot_reset(struct pci_dev *pdev)
12262 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12263 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12264 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12266 switch (phba->pci_dev_grp) {
12267 case LPFC_PCI_DEV_LP:
12268 rc = lpfc_io_slot_reset_s3(pdev);
12270 case LPFC_PCI_DEV_OC:
12271 rc = lpfc_io_slot_reset_s4(pdev);
12274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12275 "1428 Invalid PCI device group: 0x%x\n",
12276 phba->pci_dev_grp);
12283 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12284 * @pdev: pointer to PCI device
12286 * This routine is registered to the PCI subsystem for error handling. It
12287 * is called when kernel error recovery tells the lpfc driver that it is
12288 * OK to resume normal PCI operation after PCI bus error recovery. When
12289 * this routine is invoked, it dispatches the action to the proper SLI-3
12290 * or SLI-4 device io_resume routine, which will resume the device operation.
12293 lpfc_io_resume(struct pci_dev *pdev)
12295 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12296 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12298 switch (phba->pci_dev_grp) {
12299 case LPFC_PCI_DEV_LP:
12300 lpfc_io_resume_s3(pdev);
12302 case LPFC_PCI_DEV_OC:
12303 lpfc_io_resume_s4(pdev);
12306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12307 "1429 Invalid PCI device group: 0x%x\n",
12308 phba->pci_dev_grp);
12315 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12316 * @phba: pointer to lpfc hba data structure.
12318 * This routine checks to see if OAS is supported for this adapter. If
12319 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12320 * the enable oas flag is cleared and the pool created for OAS device data
12325 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12328 if (!phba->cfg_EnableXLane)
12331 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12335 if (phba->device_data_mem_pool)
12336 mempool_destroy(phba->device_data_mem_pool);
12337 phba->device_data_mem_pool = NULL;
12344 * lpfc_fof_queue_setup - Set up all the fof queues
12345 * @phba: pointer to lpfc hba data structure.
12347 * This routine is invoked to set up all the fof queues for the FC HBA
12352 * -ENOMEM - No available memory
12355 lpfc_fof_queue_setup(struct lpfc_hba *phba)
12357 struct lpfc_sli_ring *pring;
12360 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12364 if (phba->cfg_fof) {
12366 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12367 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12371 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12372 phba->sli4_hba.oas_cq, LPFC_FCP);
12376 /* Bind this CQ/WQ to the NVME ring */
12377 pring = phba->sli4_hba.oas_wq->pring;
12378 pring->sli.sli4.wqp =
12379 (void *)phba->sli4_hba.oas_wq;
12380 phba->sli4_hba.oas_cq->pring = pring;
12386 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
12388 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12394 * lpfc_fof_queue_create - Create all the fof queues
12395 * @phba: pointer to lpfc hba data structure.
12397 * This routine is invoked to allocate all the fof queues for the FC HBA
12398 * operation. For each SLI4 queue type, the parameters such as queue entry
12399 * count (queue depth) shall be taken from the module parameter. For now,
12400 * we just use some constant number as place holder.
12404 * -ENOMEM - No availble memory
12405 * -EIO - The mailbox failed to complete successfully.
12408 lpfc_fof_queue_create(struct lpfc_hba *phba)
12410 struct lpfc_queue *qdesc;
12413 /* Create FOF EQ */
12414 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12415 phba->sli4_hba.eq_esize,
12416 phba->sli4_hba.eq_ecount);
12420 qdesc->qe_valid = 1;
12421 phba->sli4_hba.fof_eq = qdesc;
12423 if (phba->cfg_fof) {
12425 /* Create OAS CQ */
12426 if (phba->enab_exp_wqcq_pages)
12427 qdesc = lpfc_sli4_queue_alloc(phba,
12428 LPFC_EXPANDED_PAGE_SIZE,
12429 phba->sli4_hba.cq_esize,
12430 LPFC_CQE_EXP_COUNT);
12432 qdesc = lpfc_sli4_queue_alloc(phba,
12433 LPFC_DEFAULT_PAGE_SIZE,
12434 phba->sli4_hba.cq_esize,
12435 phba->sli4_hba.cq_ecount);
12439 qdesc->qe_valid = 1;
12440 phba->sli4_hba.oas_cq = qdesc;
12442 /* Create OAS WQ */
12443 if (phba->enab_exp_wqcq_pages) {
12444 wqesize = (phba->fcp_embed_io) ?
12445 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
12446 qdesc = lpfc_sli4_queue_alloc(phba,
12447 LPFC_EXPANDED_PAGE_SIZE,
12449 LPFC_WQE_EXP_COUNT);
12451 qdesc = lpfc_sli4_queue_alloc(phba,
12452 LPFC_DEFAULT_PAGE_SIZE,
12453 phba->sli4_hba.wq_esize,
12454 phba->sli4_hba.wq_ecount);
12459 phba->sli4_hba.oas_wq = qdesc;
12460 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
12466 lpfc_fof_queue_destroy(phba);
12471 * lpfc_fof_queue_destroy - Destroy all the fof queues
12472 * @phba: pointer to lpfc hba data structure.
12474 * This routine is invoked to release all the SLI4 queues with the FC HBA
12481 lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12483 /* Release FOF Event queue */
12484 if (phba->sli4_hba.fof_eq != NULL) {
12485 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12486 phba->sli4_hba.fof_eq = NULL;
12489 /* Release OAS Completion queue */
12490 if (phba->sli4_hba.oas_cq != NULL) {
12491 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12492 phba->sli4_hba.oas_cq = NULL;
12495 /* Release OAS Work queue */
12496 if (phba->sli4_hba.oas_wq != NULL) {
12497 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12498 phba->sli4_hba.oas_wq = NULL;
12503 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12505 static const struct pci_error_handlers lpfc_err_handler = {
12506 .error_detected = lpfc_io_error_detected,
12507 .slot_reset = lpfc_io_slot_reset,
12508 .resume = lpfc_io_resume,
12511 static struct pci_driver lpfc_driver = {
12512 .name = LPFC_DRIVER_NAME,
12513 .id_table = lpfc_id_table,
12514 .probe = lpfc_pci_probe_one,
12515 .remove = lpfc_pci_remove_one,
12516 .shutdown = lpfc_pci_remove_one,
12517 .suspend = lpfc_pci_suspend_one,
12518 .resume = lpfc_pci_resume_one,
12519 .err_handler = &lpfc_err_handler,
12522 static const struct file_operations lpfc_mgmt_fop = {
12523 .owner = THIS_MODULE,
12526 static struct miscdevice lpfc_mgmt_dev = {
12527 .minor = MISC_DYNAMIC_MINOR,
12528 .name = "lpfcmgmt",
12529 .fops = &lpfc_mgmt_fop,
12533 * lpfc_init - lpfc module initialization routine
12535 * This routine is to be invoked when the lpfc module is loaded into the
12536 * kernel. The special kernel macro module_init() is used to indicate the
12537 * role of this routine to the kernel as lpfc module entry point.
12541 * -ENOMEM - FC attach transport failed
12542 * all others - failed
12549 printk(LPFC_MODULE_DESC "\n");
12550 printk(LPFC_COPYRIGHT "\n");
12552 error = misc_register(&lpfc_mgmt_dev);
12554 printk(KERN_ERR "Could not register lpfcmgmt device, "
12555 "misc_register returned with status %d", error);
12557 lpfc_transport_functions.vport_create = lpfc_vport_create;
12558 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
12559 lpfc_transport_template =
12560 fc_attach_transport(&lpfc_transport_functions);
12561 if (lpfc_transport_template == NULL)
12563 lpfc_vport_transport_template =
12564 fc_attach_transport(&lpfc_vport_transport_functions);
12565 if (lpfc_vport_transport_template == NULL) {
12566 fc_release_transport(lpfc_transport_template);
12569 lpfc_nvme_cmd_template();
12570 lpfc_nvmet_cmd_template();
12572 /* Initialize in case vector mapping is needed */
12573 lpfc_used_cpu = NULL;
12574 lpfc_present_cpu = num_present_cpus();
12576 error = pci_register_driver(&lpfc_driver);
12578 fc_release_transport(lpfc_transport_template);
12579 fc_release_transport(lpfc_vport_transport_template);
12586 * lpfc_exit - lpfc module removal routine
12588 * This routine is invoked when the lpfc module is removed from the kernel.
12589 * The special kernel macro module_exit() is used to indicate the role of
12590 * this routine to the kernel as lpfc module exit point.
12595 misc_deregister(&lpfc_mgmt_dev);
12596 pci_unregister_driver(&lpfc_driver);
12597 fc_release_transport(lpfc_transport_template);
12598 fc_release_transport(lpfc_vport_transport_template);
12599 if (_dump_buf_data) {
12600 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12601 "_dump_buf_data at 0x%p\n",
12602 (1L << _dump_buf_data_order), _dump_buf_data);
12603 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12606 if (_dump_buf_dif) {
12607 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12608 "_dump_buf_dif at 0x%p\n",
12609 (1L << _dump_buf_dif_order), _dump_buf_dif);
12610 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12612 kfree(lpfc_used_cpu);
12613 idr_destroy(&lpfc_hba_index);
12616 module_init(lpfc_init);
12617 module_exit(lpfc_exit);
12618 MODULE_LICENSE("GPL");
12619 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
12620 MODULE_AUTHOR("Broadcom");
12621 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);