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,
170 phba->sli3_options = 0x0;
172 /* Setup and issue mailbox READ REV command */
173 lpfc_read_rev(phba, pmb);
174 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
175 if (rc != MBX_SUCCESS) {
176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
177 "0439 Adapter failed to init, mbxCmd x%x "
178 "READ_REV, mbxStatus x%x\n",
179 mb->mbxCommand, mb->mbxStatus);
180 mempool_free( pmb, phba->mbox_mem_pool);
186 * The value of rr must be 1 since the driver set the cv field to 1.
187 * This setting requires the FW to set all revision fields.
189 if (mb->un.varRdRev.rr == 0) {
191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
192 "0440 Adapter failed to init, READ_REV has "
193 "missing revision information.\n");
194 mempool_free(pmb, phba->mbox_mem_pool);
198 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
199 mempool_free(pmb, phba->mbox_mem_pool);
203 /* Save information as VPD data */
205 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
206 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
207 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
208 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
209 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
210 vp->rev.biuRev = mb->un.varRdRev.biuRev;
211 vp->rev.smRev = mb->un.varRdRev.smRev;
212 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
213 vp->rev.endecRev = mb->un.varRdRev.endecRev;
214 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
215 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
216 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
217 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
218 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
219 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
221 /* If the sli feature level is less then 9, we must
222 * tear down all RPIs and VPIs on link down if NPIV
225 if (vp->rev.feaLevelHigh < 9)
226 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
228 if (lpfc_is_LC_HBA(phba->pcidev->device))
229 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
230 sizeof (phba->RandomData));
232 /* Get adapter VPD information */
233 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
237 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
238 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
240 if (rc != MBX_SUCCESS) {
241 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
242 "0441 VPD not present on adapter, "
243 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
244 mb->mbxCommand, mb->mbxStatus);
245 mb->un.varDmp.word_cnt = 0;
247 /* dump mem may return a zero when finished or we got a
248 * mailbox error, either way we are done.
250 if (mb->un.varDmp.word_cnt == 0)
252 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
253 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
254 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
255 lpfc_vpd_data + offset,
256 mb->un.varDmp.word_cnt);
257 offset += mb->un.varDmp.word_cnt;
258 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
259 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
261 kfree(lpfc_vpd_data);
263 mempool_free(pmb, phba->mbox_mem_pool);
268 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
272 * This is the completion handler for driver's configuring asynchronous event
273 * mailbox command to the device. If the mailbox command returns successfully,
274 * it will set internal async event support flag to 1; otherwise, it will
275 * set internal async event support flag to 0.
278 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
280 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
281 phba->temp_sensor_support = 1;
283 phba->temp_sensor_support = 0;
284 mempool_free(pmboxq, phba->mbox_mem_pool);
289 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
290 * @phba: pointer to lpfc hba data structure.
291 * @pmboxq: pointer to the driver internal queue element for mailbox command.
293 * This is the completion handler for dump mailbox command for getting
294 * wake up parameters. When this command complete, the response contain
295 * Option rom version of the HBA. This function translate the version number
296 * into a human readable string and store it in OptionROMVersion.
299 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
302 uint32_t prog_id_word;
304 /* character array used for decoding dist type. */
305 char dist_char[] = "nabx";
307 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
308 mempool_free(pmboxq, phba->mbox_mem_pool);
312 prg = (struct prog_id *) &prog_id_word;
314 /* word 7 contain option rom version */
315 prog_id_word = pmboxq->u.mb.un.varWords[7];
317 /* Decode the Option rom version word to a readable string */
319 dist = dist_char[prg->dist];
321 if ((prg->dist == 3) && (prg->num == 0))
322 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
323 prg->ver, prg->rev, prg->lev);
325 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
326 prg->ver, prg->rev, prg->lev,
328 mempool_free(pmboxq, phba->mbox_mem_pool);
333 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
334 * cfg_soft_wwnn, cfg_soft_wwpn
335 * @vport: pointer to lpfc vport data structure.
342 lpfc_update_vport_wwn(struct lpfc_vport *vport)
344 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
345 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
347 /* If the soft name exists then update it using the service params */
348 if (vport->phba->cfg_soft_wwnn)
349 u64_to_wwn(vport->phba->cfg_soft_wwnn,
350 vport->fc_sparam.nodeName.u.wwn);
351 if (vport->phba->cfg_soft_wwpn)
352 u64_to_wwn(vport->phba->cfg_soft_wwpn,
353 vport->fc_sparam.portName.u.wwn);
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
359 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
367 * If the port name has changed, then set the Param changes flag
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name)))
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
375 if (vport->fc_portname.u.wwn[0] == 0 ||
376 vport->phba->cfg_soft_wwpn ||
377 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
378 vport->vport_flag & FAWWPN_SET) {
379 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name));
381 vport->vport_flag &= ~FAWWPN_SET;
382 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
383 vport->vport_flag |= FAWWPN_SET;
386 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
387 sizeof(struct lpfc_name));
391 * lpfc_config_port_post - Perform lpfc initialization after config port
392 * @phba: pointer to lpfc hba data structure.
394 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
395 * command call. It performs all internal resource and state setups on the
396 * port: post IOCB buffers, enable appropriate host interrupt attentions,
397 * ELS ring timers, etc.
401 * Any other value - error.
404 lpfc_config_port_post(struct lpfc_hba *phba)
406 struct lpfc_vport *vport = phba->pport;
407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
410 struct lpfc_dmabuf *mp;
411 struct lpfc_sli *psli = &phba->sli;
412 uint32_t status, timeout;
416 spin_lock_irq(&phba->hbalock);
418 * If the Config port completed correctly the HBA is not
419 * over heated any more.
421 if (phba->over_temp_state == HBA_OVER_TEMP)
422 phba->over_temp_state = HBA_NORMAL_TEMP;
423 spin_unlock_irq(&phba->hbalock);
425 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
427 phba->link_state = LPFC_HBA_ERROR;
432 /* Get login parameters for NID. */
433 rc = lpfc_read_sparam(phba, pmb, 0);
435 mempool_free(pmb, phba->mbox_mem_pool);
440 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
442 "0448 Adapter failed init, mbxCmd x%x "
443 "READ_SPARM mbxStatus x%x\n",
444 mb->mbxCommand, mb->mbxStatus);
445 phba->link_state = LPFC_HBA_ERROR;
446 mp = (struct lpfc_dmabuf *) pmb->context1;
447 mempool_free(pmb, phba->mbox_mem_pool);
448 lpfc_mbuf_free(phba, mp->virt, mp->phys);
453 mp = (struct lpfc_dmabuf *) pmb->context1;
455 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
458 pmb->context1 = NULL;
459 lpfc_update_vport_wwn(vport);
461 /* Update the fc_host data structures with new wwn. */
462 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
463 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
464 fc_host_max_npiv_vports(shost) = phba->max_vpi;
466 /* If no serial number in VPD data, use low 6 bytes of WWNN */
467 /* This should be consolidated into parse_vpd ? - mr */
468 if (phba->SerialNumber[0] == 0) {
471 outptr = &vport->fc_nodename.u.s.IEEE[0];
472 for (i = 0; i < 12; i++) {
474 j = ((status & 0xf0) >> 4);
476 phba->SerialNumber[i] =
477 (char)((uint8_t) 0x30 + (uint8_t) j);
479 phba->SerialNumber[i] =
480 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
492 lpfc_read_config(phba, pmb);
494 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
496 "0453 Adapter failed to init, mbxCmd x%x "
497 "READ_CONFIG, mbxStatus x%x\n",
498 mb->mbxCommand, mb->mbxStatus);
499 phba->link_state = LPFC_HBA_ERROR;
500 mempool_free( pmb, phba->mbox_mem_pool);
504 /* Check if the port is disabled */
505 lpfc_sli_read_link_ste(phba);
507 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
508 i = (mb->un.varRdConfig.max_xri + 1);
509 if (phba->cfg_hba_queue_depth > i) {
510 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
511 "3359 HBA queue depth changed from %d to %d\n",
512 phba->cfg_hba_queue_depth, i);
513 phba->cfg_hba_queue_depth = i;
516 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
517 i = (mb->un.varRdConfig.max_xri >> 3);
518 if (phba->pport->cfg_lun_queue_depth > i) {
519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
520 "3360 LUN queue depth changed from %d to %d\n",
521 phba->pport->cfg_lun_queue_depth, i);
522 phba->pport->cfg_lun_queue_depth = i;
525 phba->lmt = mb->un.varRdConfig.lmt;
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
530 phba->link_state = LPFC_LINK_DOWN;
532 /* Only process IOCBs on ELS ring till hba_state is READY */
533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
538 /* Post receive buffers for desired rings */
539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
548 mempool_free(pmb, phba->mbox_mem_pool);
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
558 mempool_free(pmb, phba->mbox_mem_pool);
563 spin_lock_irq(&phba->hbalock);
564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
567 /* Enable appropriate host interrupts */
568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
584 status &= ~(HC_R0INT_ENA);
586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
588 spin_unlock_irq(&phba->hbalock);
590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
594 /* Set up heart beat (HB) timer */
595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
597 phba->hb_outstanding = 0;
598 phba->last_completion_time = jiffies;
599 /* Set up error attention (ERATT) polling timer */
600 mod_timer(&phba->eratt_poll,
601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba,
606 "2598 Adapter Link is disabled.\n");
607 lpfc_down_link(phba, pmb);
608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
609 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
610 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
611 lpfc_printf_log(phba,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
616 mempool_free(pmb, phba->mbox_mem_pool);
619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
625 /* MBOX buffer will be freed in mbox compl */
626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
628 phba->link_state = LPFC_HBA_ERROR;
632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba,
641 "0456 Adapter failed to issue "
642 "ASYNCEVT_ENABLE mbox status x%x\n",
644 mempool_free(pmb, phba->mbox_mem_pool);
647 /* Get Option rom version */
648 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
650 phba->link_state = LPFC_HBA_ERROR;
654 lpfc_dump_wakeup_param(phba, pmb);
655 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
656 pmb->vport = phba->pport;
657 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
659 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
661 "to get Option ROM version status x%x\n", rc);
662 mempool_free(pmb, phba->mbox_mem_pool);
669 * lpfc_hba_init_link - Initialize the FC link
670 * @phba: pointer to lpfc hba data structure.
671 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
673 * This routine will issue the INIT_LINK mailbox command call.
674 * It is available to other drivers through the lpfc_hba data
675 * structure for use as a delayed link up mechanism with the
676 * module parameter lpfc_suppress_link_up.
680 * Any other value - error
683 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
685 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
689 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
690 * @phba: pointer to lpfc hba data structure.
691 * @fc_topology: desired fc topology.
692 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
694 * This routine will issue the INIT_LINK mailbox command call.
695 * It is available to other drivers through the lpfc_hba data
696 * structure for use as a delayed link up mechanism with the
697 * module parameter lpfc_suppress_link_up.
701 * Any other value - error
704 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
707 struct lpfc_vport *vport = phba->pport;
712 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
714 phba->link_state = LPFC_HBA_ERROR;
720 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
722 !(phba->lmt & LMT_1Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
724 !(phba->lmt & LMT_2Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
726 !(phba->lmt & LMT_4Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
728 !(phba->lmt & LMT_8Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
730 !(phba->lmt & LMT_10Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
732 !(phba->lmt & LMT_16Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
734 !(phba->lmt & LMT_32Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
736 !(phba->lmt & LMT_64Gb))) {
737 /* Reset link speed to auto */
738 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
739 "1302 Invalid speed for this board:%d "
740 "Reset link speed to auto.\n",
741 phba->cfg_link_speed);
742 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
744 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
745 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
746 if (phba->sli_rev < LPFC_SLI_REV4)
747 lpfc_set_loopback_flag(phba);
748 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
749 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
751 "0498 Adapter failed to init, mbxCmd x%x "
752 "INIT_LINK, mbxStatus x%x\n",
753 mb->mbxCommand, mb->mbxStatus);
754 if (phba->sli_rev <= LPFC_SLI_REV3) {
755 /* Clear all interrupt enable conditions */
756 writel(0, phba->HCregaddr);
757 readl(phba->HCregaddr); /* flush */
758 /* Clear all pending interrupts */
759 writel(0xffffffff, phba->HAregaddr);
760 readl(phba->HAregaddr); /* flush */
762 phba->link_state = LPFC_HBA_ERROR;
763 if (rc != MBX_BUSY || flag == MBX_POLL)
764 mempool_free(pmb, phba->mbox_mem_pool);
767 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
768 if (flag == MBX_POLL)
769 mempool_free(pmb, phba->mbox_mem_pool);
775 * lpfc_hba_down_link - this routine downs the FC link
776 * @phba: pointer to lpfc hba data structure.
777 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
779 * This routine will issue the DOWN_LINK mailbox command call.
780 * It is available to other drivers through the lpfc_hba data
781 * structure for use to stop the link.
785 * Any other value - error
788 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
793 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
795 phba->link_state = LPFC_HBA_ERROR;
799 lpfc_printf_log(phba,
801 "0491 Adapter Link is disabled.\n");
802 lpfc_down_link(phba, pmb);
803 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
804 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
805 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
806 lpfc_printf_log(phba,
808 "2522 Adapter failed to issue DOWN_LINK"
809 " mbox command rc 0x%x\n", rc);
811 mempool_free(pmb, phba->mbox_mem_pool);
814 if (flag == MBX_POLL)
815 mempool_free(pmb, phba->mbox_mem_pool);
821 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
822 * @phba: pointer to lpfc HBA data structure.
824 * This routine will do LPFC uninitialization before the HBA is reset when
825 * bringing down the SLI Layer.
829 * Any other value - error.
832 lpfc_hba_down_prep(struct lpfc_hba *phba)
834 struct lpfc_vport **vports;
837 if (phba->sli_rev <= LPFC_SLI_REV3) {
838 /* Disable interrupts */
839 writel(0, phba->HCregaddr);
840 readl(phba->HCregaddr); /* flush */
843 if (phba->pport->load_flag & FC_UNLOADING)
844 lpfc_cleanup_discovery_resources(phba->pport);
846 vports = lpfc_create_vport_work_array(phba);
848 for (i = 0; i <= phba->max_vports &&
849 vports[i] != NULL; i++)
850 lpfc_cleanup_discovery_resources(vports[i]);
851 lpfc_destroy_vport_work_array(phba, vports);
857 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
858 * rspiocb which got deferred
860 * @phba: pointer to lpfc HBA data structure.
862 * This routine will cleanup completed slow path events after HBA is reset
863 * when bringing down the SLI Layer.
870 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
872 struct lpfc_iocbq *rspiocbq;
873 struct hbq_dmabuf *dmabuf;
874 struct lpfc_cq_event *cq_event;
876 spin_lock_irq(&phba->hbalock);
877 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
878 spin_unlock_irq(&phba->hbalock);
880 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
881 /* Get the response iocb from the head of work queue */
882 spin_lock_irq(&phba->hbalock);
883 list_remove_head(&phba->sli4_hba.sp_queue_event,
884 cq_event, struct lpfc_cq_event, list);
885 spin_unlock_irq(&phba->hbalock);
887 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
888 case CQE_CODE_COMPL_WQE:
889 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
891 lpfc_sli_release_iocbq(phba, rspiocbq);
893 case CQE_CODE_RECEIVE:
894 case CQE_CODE_RECEIVE_V1:
895 dmabuf = container_of(cq_event, struct hbq_dmabuf,
897 lpfc_in_buf_free(phba, &dmabuf->dbuf);
903 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
904 * @phba: pointer to lpfc HBA data structure.
906 * This routine will cleanup posted ELS buffers after the HBA is reset
907 * when bringing down the SLI Layer.
914 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
916 struct lpfc_sli *psli = &phba->sli;
917 struct lpfc_sli_ring *pring;
918 struct lpfc_dmabuf *mp, *next_mp;
922 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
923 lpfc_sli_hbqbuf_free_all(phba);
925 /* Cleanup preposted buffers on the ELS ring */
926 pring = &psli->sli3_ring[LPFC_ELS_RING];
927 spin_lock_irq(&phba->hbalock);
928 list_splice_init(&pring->postbufq, &buflist);
929 spin_unlock_irq(&phba->hbalock);
932 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
935 lpfc_mbuf_free(phba, mp->virt, mp->phys);
939 spin_lock_irq(&phba->hbalock);
940 pring->postbufq_cnt -= count;
941 spin_unlock_irq(&phba->hbalock);
946 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
947 * @phba: pointer to lpfc HBA data structure.
949 * This routine will cleanup the txcmplq after the HBA is reset when bringing
950 * down the SLI Layer.
956 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
958 struct lpfc_sli *psli = &phba->sli;
959 struct lpfc_queue *qp = NULL;
960 struct lpfc_sli_ring *pring;
961 LIST_HEAD(completions);
963 struct lpfc_iocbq *piocb, *next_iocb;
965 if (phba->sli_rev != LPFC_SLI_REV4) {
966 for (i = 0; i < psli->num_rings; i++) {
967 pring = &psli->sli3_ring[i];
968 spin_lock_irq(&phba->hbalock);
969 /* At this point in time the HBA is either reset or DOA
970 * Nothing should be on txcmplq as it will
973 list_splice_init(&pring->txcmplq, &completions);
974 pring->txcmplq_cnt = 0;
975 spin_unlock_irq(&phba->hbalock);
977 lpfc_sli_abort_iocb_ring(phba, pring);
979 /* Cancel all the IOCBs from the completions list */
980 lpfc_sli_cancel_iocbs(phba, &completions,
981 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
984 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
988 spin_lock_irq(&pring->ring_lock);
989 list_for_each_entry_safe(piocb, next_iocb,
990 &pring->txcmplq, list)
991 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
992 list_splice_init(&pring->txcmplq, &completions);
993 pring->txcmplq_cnt = 0;
994 spin_unlock_irq(&pring->ring_lock);
995 lpfc_sli_abort_iocb_ring(phba, pring);
997 /* Cancel all the IOCBs from the completions list */
998 lpfc_sli_cancel_iocbs(phba, &completions,
999 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
1003 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
1005 * @phba: pointer to lpfc HBA data structure.
1007 * This routine will do uninitialization after the HBA is reset when bring
1008 * down the SLI Layer.
1012 * Any other value - error.
1015 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1017 lpfc_hba_free_post_buf(phba);
1018 lpfc_hba_clean_txcmplq(phba);
1023 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1024 * @phba: pointer to lpfc HBA data structure.
1026 * This routine will do uninitialization after the HBA is reset when bring
1027 * down the SLI Layer.
1031 * Any other value - error.
1034 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1036 struct lpfc_scsi_buf *psb, *psb_next;
1037 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
1039 LIST_HEAD(nvme_aborts);
1040 LIST_HEAD(nvmet_aborts);
1041 unsigned long iflag = 0;
1042 struct lpfc_sglq *sglq_entry = NULL;
1046 lpfc_sli_hbqbuf_free_all(phba);
1047 lpfc_hba_clean_txcmplq(phba);
1049 /* At this point in time the HBA is either reset or DOA. Either
1050 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1051 * on the lpfc_els_sgl_list so that it can either be freed if the
1052 * driver is unloading or reposted if the driver is restarting
1055 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
1057 /* sgl_list_lock required because worker thread uses this
1060 spin_lock(&phba->sli4_hba.sgl_list_lock);
1061 list_for_each_entry(sglq_entry,
1062 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1063 sglq_entry->state = SGL_FREED;
1065 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1066 &phba->sli4_hba.lpfc_els_sgl_list);
1069 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1070 /* abts_scsi_buf_list_lock required because worker thread uses this
1073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1074 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1075 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1077 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1080 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1081 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1082 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1084 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1086 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1089 spin_unlock_irq(&phba->hbalock);
1091 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1093 psb->status = IOSTAT_SUCCESS;
1095 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1096 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1097 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1099 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1101 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1103 psb->status = IOSTAT_SUCCESS;
1106 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1107 phba->put_nvme_bufs += cnt;
1108 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1109 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1111 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1112 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
1113 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1117 lpfc_sli4_free_sp_events(phba);
1122 * lpfc_hba_down_post - Wrapper func for hba down post routine
1123 * @phba: pointer to lpfc HBA data structure.
1125 * This routine wraps the actual SLI3 or SLI4 routine for performing
1126 * uninitialization after the HBA is reset when bring down the SLI Layer.
1130 * Any other value - error.
1133 lpfc_hba_down_post(struct lpfc_hba *phba)
1135 return (*phba->lpfc_hba_down_post)(phba);
1139 * lpfc_hb_timeout - The HBA-timer timeout handler
1140 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1142 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1143 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1144 * work-port-events bitmap and the worker thread is notified. This timeout
1145 * event will be used by the worker thread to invoke the actual timeout
1146 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1147 * be performed in the timeout handler and the HBA timeout event bit shall
1148 * be cleared by the worker thread after it has taken the event bitmap out.
1151 lpfc_hb_timeout(struct timer_list *t)
1153 struct lpfc_hba *phba;
1154 uint32_t tmo_posted;
1155 unsigned long iflag;
1157 phba = from_timer(phba, t, hb_tmofunc);
1159 /* Check for heart beat timeout conditions */
1160 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1161 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1163 phba->pport->work_port_events |= WORKER_HB_TMO;
1164 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1166 /* Tell the worker thread there is work to do */
1168 lpfc_worker_wake_up(phba);
1173 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1174 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1176 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1177 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1178 * work-port-events bitmap and the worker thread is notified. This timeout
1179 * event will be used by the worker thread to invoke the actual timeout
1180 * handler routine, lpfc_rrq_handler. Any periodical operations will
1181 * be performed in the timeout handler and the RRQ timeout event bit shall
1182 * be cleared by the worker thread after it has taken the event bitmap out.
1185 lpfc_rrq_timeout(struct timer_list *t)
1187 struct lpfc_hba *phba;
1188 unsigned long iflag;
1190 phba = from_timer(phba, t, rrq_tmr);
1191 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1192 if (!(phba->pport->load_flag & FC_UNLOADING))
1193 phba->hba_flag |= HBA_RRQ_ACTIVE;
1195 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1196 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1198 if (!(phba->pport->load_flag & FC_UNLOADING))
1199 lpfc_worker_wake_up(phba);
1203 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1204 * @phba: pointer to lpfc hba data structure.
1205 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1207 * This is the callback function to the lpfc heart-beat mailbox command.
1208 * If configured, the lpfc driver issues the heart-beat mailbox command to
1209 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1210 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1211 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1212 * heart-beat outstanding state. Once the mailbox command comes back and
1213 * no error conditions detected, the heart-beat mailbox command timer is
1214 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1215 * state is cleared for the next heart-beat. If the timer expired with the
1216 * heart-beat outstanding state set, the driver will put the HBA offline.
1219 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1221 unsigned long drvr_flag;
1223 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1224 phba->hb_outstanding = 0;
1225 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1227 /* Check and reset heart-beat timer is necessary */
1228 mempool_free(pmboxq, phba->mbox_mem_pool);
1229 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1230 !(phba->link_state == LPFC_HBA_ERROR) &&
1231 !(phba->pport->load_flag & FC_UNLOADING))
1232 mod_timer(&phba->hb_tmofunc,
1234 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1239 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1240 * @phba: pointer to lpfc hba data structure.
1242 * This is the actual HBA-timer timeout handler to be invoked by the worker
1243 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1244 * handler performs any periodic operations needed for the device. If such
1245 * periodic event has already been attended to either in the interrupt handler
1246 * or by processing slow-ring or fast-ring events within the HBA-timer
1247 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1248 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1249 * is configured and there is no heart-beat mailbox command outstanding, a
1250 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1251 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1255 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1257 struct lpfc_vport **vports;
1258 LPFC_MBOXQ_t *pmboxq;
1259 struct lpfc_dmabuf *buf_ptr;
1261 struct lpfc_sli *psli = &phba->sli;
1262 LIST_HEAD(completions);
1263 struct lpfc_queue *qp;
1264 unsigned long time_elapsed;
1265 uint32_t tick_cqe, max_cqe, val;
1266 uint64_t tot, data1, data2, data3;
1267 struct lpfc_nvmet_tgtport *tgtp;
1268 struct lpfc_register reg_data;
1269 struct nvme_fc_local_port *localport;
1270 struct lpfc_nvme_lport *lport;
1271 struct lpfc_nvme_ctrl_stat *cstat;
1272 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
1274 vports = lpfc_create_vport_work_array(phba);
1276 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1277 lpfc_rcv_seq_check_edtov(vports[i]);
1278 lpfc_fdmi_num_disc_check(vports[i]);
1280 lpfc_destroy_vport_work_array(phba, vports);
1282 if ((phba->link_state == LPFC_HBA_ERROR) ||
1283 (phba->pport->load_flag & FC_UNLOADING) ||
1284 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1287 if (phba->cfg_auto_imax) {
1288 if (!phba->last_eqdelay_time) {
1289 phba->last_eqdelay_time = jiffies;
1292 time_elapsed = jiffies - phba->last_eqdelay_time;
1293 phba->last_eqdelay_time = jiffies;
1296 /* Check outstanding IO count */
1297 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1298 if (phba->nvmet_support) {
1299 tgtp = phba->targetport->private;
1300 /* Calculate outstanding IOs */
1301 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1302 tot += atomic_read(&tgtp->xmt_fcp_release);
1303 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
1305 localport = phba->pport->localport;
1306 if (!localport || !localport->private)
1308 lport = (struct lpfc_nvme_lport *)
1312 i < phba->cfg_nvme_io_channel; i++) {
1313 cstat = &lport->cstat[i];
1314 data1 = atomic_read(
1315 &cstat->fc4NvmeInputRequests);
1316 data2 = atomic_read(
1317 &cstat->fc4NvmeOutputRequests);
1318 data3 = atomic_read(
1319 &cstat->fc4NvmeControlRequests);
1320 tot += (data1 + data2 + data3);
1322 &cstat->fc4NvmeIoCmpls);
1327 /* Interrupts per sec per EQ */
1328 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1329 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1331 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1332 max_cqe = time_elapsed * tick_cqe;
1334 for (i = 0; i < phba->io_channel_irqs; i++) {
1336 qp = phba->sli4_hba.hba_eq[i];
1340 /* Use no EQ delay if we don't have many outstanding
1341 * IOs, or if we are only processing 1 CQE/ISR or less.
1342 * Otherwise, assume we can process up to lpfc_fcp_imax
1343 * interrupts per HBA.
1345 if (tot < LPFC_NODELAY_MAX_IO ||
1346 qp->EQ_cqe_cnt <= max_cqe)
1349 val = phba->cfg_fcp_imax;
1351 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1352 /* Use EQ Delay Register method */
1354 /* Convert for EQ Delay register */
1356 /* First, interrupts per sec per EQ */
1357 val = phba->cfg_fcp_imax /
1358 phba->io_channel_irqs;
1360 /* us delay between each interrupt */
1361 val = LPFC_SEC_TO_USEC / val;
1363 if (val != qp->q_mode) {
1365 bf_set(lpfc_sliport_eqdelay_id,
1366 ®_data, qp->queue_id);
1367 bf_set(lpfc_sliport_eqdelay_delay,
1369 writel(reg_data.word0, eqdreg);
1372 /* Use mbox command method */
1373 if (val != qp->q_mode)
1374 lpfc_modify_hba_eq_delay(phba, i,
1379 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1380 * between interrupts for EQDR.
1388 spin_lock_irq(&phba->pport->work_port_lock);
1390 if (time_after(phba->last_completion_time +
1391 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1393 spin_unlock_irq(&phba->pport->work_port_lock);
1394 if (!phba->hb_outstanding)
1395 mod_timer(&phba->hb_tmofunc,
1397 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1399 mod_timer(&phba->hb_tmofunc,
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1404 spin_unlock_irq(&phba->pport->work_port_lock);
1406 if (phba->elsbuf_cnt &&
1407 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1408 spin_lock_irq(&phba->hbalock);
1409 list_splice_init(&phba->elsbuf, &completions);
1410 phba->elsbuf_cnt = 0;
1411 phba->elsbuf_prev_cnt = 0;
1412 spin_unlock_irq(&phba->hbalock);
1414 while (!list_empty(&completions)) {
1415 list_remove_head(&completions, buf_ptr,
1416 struct lpfc_dmabuf, list);
1417 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1421 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1423 /* If there is no heart beat outstanding, issue a heartbeat command */
1424 if (phba->cfg_enable_hba_heartbeat) {
1425 if (!phba->hb_outstanding) {
1426 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1427 (list_empty(&psli->mboxq))) {
1428 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1431 mod_timer(&phba->hb_tmofunc,
1433 msecs_to_jiffies(1000 *
1434 LPFC_HB_MBOX_INTERVAL));
1438 lpfc_heart_beat(phba, pmboxq);
1439 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1440 pmboxq->vport = phba->pport;
1441 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1444 if (retval != MBX_BUSY &&
1445 retval != MBX_SUCCESS) {
1446 mempool_free(pmboxq,
1447 phba->mbox_mem_pool);
1448 mod_timer(&phba->hb_tmofunc,
1450 msecs_to_jiffies(1000 *
1451 LPFC_HB_MBOX_INTERVAL));
1454 phba->skipped_hb = 0;
1455 phba->hb_outstanding = 1;
1456 } else if (time_before_eq(phba->last_completion_time,
1457 phba->skipped_hb)) {
1458 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1459 "2857 Last completion time not "
1460 " updated in %d ms\n",
1461 jiffies_to_msecs(jiffies
1462 - phba->last_completion_time));
1464 phba->skipped_hb = jiffies;
1466 mod_timer(&phba->hb_tmofunc,
1468 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1472 * If heart beat timeout called with hb_outstanding set
1473 * we need to give the hb mailbox cmd a chance to
1476 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1477 "0459 Adapter heartbeat still out"
1478 "standing:last compl time was %d ms.\n",
1479 jiffies_to_msecs(jiffies
1480 - phba->last_completion_time));
1481 mod_timer(&phba->hb_tmofunc,
1483 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1486 mod_timer(&phba->hb_tmofunc,
1488 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1493 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1494 * @phba: pointer to lpfc hba data structure.
1496 * This routine is called to bring the HBA offline when HBA hardware error
1497 * other than Port Error 6 has been detected.
1500 lpfc_offline_eratt(struct lpfc_hba *phba)
1502 struct lpfc_sli *psli = &phba->sli;
1504 spin_lock_irq(&phba->hbalock);
1505 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1506 spin_unlock_irq(&phba->hbalock);
1507 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1510 lpfc_reset_barrier(phba);
1511 spin_lock_irq(&phba->hbalock);
1512 lpfc_sli_brdreset(phba);
1513 spin_unlock_irq(&phba->hbalock);
1514 lpfc_hba_down_post(phba);
1515 lpfc_sli_brdready(phba, HS_MBRDY);
1516 lpfc_unblock_mgmt_io(phba);
1517 phba->link_state = LPFC_HBA_ERROR;
1522 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1523 * @phba: pointer to lpfc hba data structure.
1525 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1526 * other than Port Error 6 has been detected.
1529 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1531 spin_lock_irq(&phba->hbalock);
1532 phba->link_state = LPFC_HBA_ERROR;
1533 spin_unlock_irq(&phba->hbalock);
1535 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1537 lpfc_hba_down_post(phba);
1538 lpfc_unblock_mgmt_io(phba);
1542 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1543 * @phba: pointer to lpfc hba data structure.
1545 * This routine is invoked to handle the deferred HBA hardware error
1546 * conditions. This type of error is indicated by HBA by setting ER1
1547 * and another ER bit in the host status register. The driver will
1548 * wait until the ER1 bit clears before handling the error condition.
1551 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1553 uint32_t old_host_status = phba->work_hs;
1554 struct lpfc_sli *psli = &phba->sli;
1556 /* If the pci channel is offline, ignore possible errors,
1557 * since we cannot communicate with the pci card anyway.
1559 if (pci_channel_offline(phba->pcidev)) {
1560 spin_lock_irq(&phba->hbalock);
1561 phba->hba_flag &= ~DEFER_ERATT;
1562 spin_unlock_irq(&phba->hbalock);
1566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1567 "0479 Deferred Adapter Hardware Error "
1568 "Data: x%x x%x x%x\n",
1570 phba->work_status[0], phba->work_status[1]);
1572 spin_lock_irq(&phba->hbalock);
1573 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1574 spin_unlock_irq(&phba->hbalock);
1578 * Firmware stops when it triggred erratt. That could cause the I/Os
1579 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1580 * SCSI layer retry it after re-establishing link.
1582 lpfc_sli_abort_fcp_rings(phba);
1585 * There was a firmware error. Take the hba offline and then
1586 * attempt to restart it.
1588 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1591 /* Wait for the ER1 bit to clear.*/
1592 while (phba->work_hs & HS_FFER1) {
1594 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1595 phba->work_hs = UNPLUG_ERR ;
1598 /* If driver is unloading let the worker thread continue */
1599 if (phba->pport->load_flag & FC_UNLOADING) {
1606 * This is to ptrotect against a race condition in which
1607 * first write to the host attention register clear the
1608 * host status register.
1610 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1611 phba->work_hs = old_host_status & ~HS_FFER1;
1613 spin_lock_irq(&phba->hbalock);
1614 phba->hba_flag &= ~DEFER_ERATT;
1615 spin_unlock_irq(&phba->hbalock);
1616 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1617 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1621 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1623 struct lpfc_board_event_header board_event;
1624 struct Scsi_Host *shost;
1626 board_event.event_type = FC_REG_BOARD_EVENT;
1627 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1628 shost = lpfc_shost_from_vport(phba->pport);
1629 fc_host_post_vendor_event(shost, fc_get_event_number(),
1630 sizeof(board_event),
1631 (char *) &board_event,
1636 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1637 * @phba: pointer to lpfc hba data structure.
1639 * This routine is invoked to handle the following HBA hardware error
1641 * 1 - HBA error attention interrupt
1642 * 2 - DMA ring index out of range
1643 * 3 - Mailbox command came back as unknown
1646 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1648 struct lpfc_vport *vport = phba->pport;
1649 struct lpfc_sli *psli = &phba->sli;
1650 uint32_t event_data;
1651 unsigned long temperature;
1652 struct temp_event temp_event_data;
1653 struct Scsi_Host *shost;
1655 /* If the pci channel is offline, ignore possible errors,
1656 * since we cannot communicate with the pci card anyway.
1658 if (pci_channel_offline(phba->pcidev)) {
1659 spin_lock_irq(&phba->hbalock);
1660 phba->hba_flag &= ~DEFER_ERATT;
1661 spin_unlock_irq(&phba->hbalock);
1665 /* If resets are disabled then leave the HBA alone and return */
1666 if (!phba->cfg_enable_hba_reset)
1669 /* Send an internal error event to mgmt application */
1670 lpfc_board_errevt_to_mgmt(phba);
1672 if (phba->hba_flag & DEFER_ERATT)
1673 lpfc_handle_deferred_eratt(phba);
1675 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1676 if (phba->work_hs & HS_FFER6)
1677 /* Re-establishing Link */
1678 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1679 "1301 Re-establishing Link "
1680 "Data: x%x x%x x%x\n",
1681 phba->work_hs, phba->work_status[0],
1682 phba->work_status[1]);
1683 if (phba->work_hs & HS_FFER8)
1684 /* Device Zeroization */
1685 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1686 "2861 Host Authentication device "
1687 "zeroization Data:x%x x%x x%x\n",
1688 phba->work_hs, phba->work_status[0],
1689 phba->work_status[1]);
1691 spin_lock_irq(&phba->hbalock);
1692 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1693 spin_unlock_irq(&phba->hbalock);
1696 * Firmware stops when it triggled erratt with HS_FFER6.
1697 * That could cause the I/Os dropped by the firmware.
1698 * Error iocb (I/O) on txcmplq and let the SCSI layer
1699 * retry it after re-establishing link.
1701 lpfc_sli_abort_fcp_rings(phba);
1704 * There was a firmware error. Take the hba offline and then
1705 * attempt to restart it.
1707 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1709 lpfc_sli_brdrestart(phba);
1710 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1711 lpfc_unblock_mgmt_io(phba);
1714 lpfc_unblock_mgmt_io(phba);
1715 } else if (phba->work_hs & HS_CRIT_TEMP) {
1716 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1717 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1718 temp_event_data.event_code = LPFC_CRIT_TEMP;
1719 temp_event_data.data = (uint32_t)temperature;
1721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1722 "0406 Adapter maximum temperature exceeded "
1723 "(%ld), taking this port offline "
1724 "Data: x%x x%x x%x\n",
1725 temperature, phba->work_hs,
1726 phba->work_status[0], phba->work_status[1]);
1728 shost = lpfc_shost_from_vport(phba->pport);
1729 fc_host_post_vendor_event(shost, fc_get_event_number(),
1730 sizeof(temp_event_data),
1731 (char *) &temp_event_data,
1732 SCSI_NL_VID_TYPE_PCI
1733 | PCI_VENDOR_ID_EMULEX);
1735 spin_lock_irq(&phba->hbalock);
1736 phba->over_temp_state = HBA_OVER_TEMP;
1737 spin_unlock_irq(&phba->hbalock);
1738 lpfc_offline_eratt(phba);
1741 /* The if clause above forces this code path when the status
1742 * failure is a value other than FFER6. Do not call the offline
1743 * twice. This is the adapter hardware error path.
1745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1746 "0457 Adapter Hardware Error "
1747 "Data: x%x x%x x%x\n",
1749 phba->work_status[0], phba->work_status[1]);
1751 event_data = FC_REG_DUMP_EVENT;
1752 shost = lpfc_shost_from_vport(vport);
1753 fc_host_post_vendor_event(shost, fc_get_event_number(),
1754 sizeof(event_data), (char *) &event_data,
1755 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1757 lpfc_offline_eratt(phba);
1763 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1764 * @phba: pointer to lpfc hba data structure.
1765 * @mbx_action: flag for mailbox shutdown action.
1767 * This routine is invoked to perform an SLI4 port PCI function reset in
1768 * response to port status register polling attention. It waits for port
1769 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1770 * During this process, interrupt vectors are freed and later requested
1771 * for handling possible port resource change.
1774 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1780 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
1781 LPFC_SLI_INTF_IF_TYPE_2) {
1783 * On error status condition, driver need to wait for port
1784 * ready before performing reset.
1786 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1791 /* need reset: attempt for port recovery */
1793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1794 "2887 Reset Needed: Attempting Port "
1796 lpfc_offline_prep(phba, mbx_action);
1798 /* release interrupt for possible resource change */
1799 lpfc_sli4_disable_intr(phba);
1800 lpfc_sli_brdrestart(phba);
1801 /* request and enable interrupt */
1802 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1803 if (intr_mode == LPFC_INTR_ERROR) {
1804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1805 "3175 Failed to enable interrupt\n");
1808 phba->intr_mode = intr_mode;
1809 rc = lpfc_online(phba);
1811 lpfc_unblock_mgmt_io(phba);
1817 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1818 * @phba: pointer to lpfc hba data structure.
1820 * This routine is invoked to handle the SLI4 HBA hardware error attention
1824 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1826 struct lpfc_vport *vport = phba->pport;
1827 uint32_t event_data;
1828 struct Scsi_Host *shost;
1830 struct lpfc_register portstat_reg = {0};
1831 uint32_t reg_err1, reg_err2;
1832 uint32_t uerrlo_reg, uemasklo_reg;
1833 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1834 bool en_rn_msg = true;
1835 struct temp_event temp_event_data;
1836 struct lpfc_register portsmphr_reg;
1839 /* If the pci channel is offline, ignore possible errors, since
1840 * we cannot communicate with the pci card anyway.
1842 if (pci_channel_offline(phba->pcidev))
1845 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1846 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1848 case LPFC_SLI_INTF_IF_TYPE_0:
1849 pci_rd_rc1 = lpfc_readl(
1850 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1852 pci_rd_rc2 = lpfc_readl(
1853 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1855 /* consider PCI bus read error as pci_channel_offline */
1856 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1858 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1859 lpfc_sli4_offline_eratt(phba);
1862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1863 "7623 Checking UE recoverable");
1865 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1866 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1867 &portsmphr_reg.word0))
1870 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1872 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1873 LPFC_PORT_SEM_UE_RECOVERABLE)
1875 /*Sleep for 1Sec, before checking SEMAPHORE */
1879 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1880 "4827 smphr_port_status x%x : Waited %dSec",
1881 smphr_port_status, i);
1883 /* Recoverable UE, reset the HBA device */
1884 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1885 LPFC_PORT_SEM_UE_RECOVERABLE) {
1886 for (i = 0; i < 20; i++) {
1888 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1889 &portsmphr_reg.word0) &&
1890 (LPFC_POST_STAGE_PORT_READY ==
1891 bf_get(lpfc_port_smphr_port_status,
1893 rc = lpfc_sli4_port_sta_fn_reset(phba,
1894 LPFC_MBX_NO_WAIT, en_rn_msg);
1897 lpfc_printf_log(phba,
1899 "4215 Failed to recover UE");
1904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1905 "7624 Firmware not ready: Failing UE recovery,"
1906 " waited %dSec", i);
1907 lpfc_sli4_offline_eratt(phba);
1910 case LPFC_SLI_INTF_IF_TYPE_2:
1911 case LPFC_SLI_INTF_IF_TYPE_6:
1912 pci_rd_rc1 = lpfc_readl(
1913 phba->sli4_hba.u.if_type2.STATUSregaddr,
1914 &portstat_reg.word0);
1915 /* consider PCI bus read error as pci_channel_offline */
1916 if (pci_rd_rc1 == -EIO) {
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "3151 PCI bus read access failure: x%x\n",
1919 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1922 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1923 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1924 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1925 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1926 "2889 Port Overtemperature event, "
1927 "taking port offline Data: x%x x%x\n",
1928 reg_err1, reg_err2);
1930 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
1931 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1932 temp_event_data.event_code = LPFC_CRIT_TEMP;
1933 temp_event_data.data = 0xFFFFFFFF;
1935 shost = lpfc_shost_from_vport(phba->pport);
1936 fc_host_post_vendor_event(shost, fc_get_event_number(),
1937 sizeof(temp_event_data),
1938 (char *)&temp_event_data,
1939 SCSI_NL_VID_TYPE_PCI
1940 | PCI_VENDOR_ID_EMULEX);
1942 spin_lock_irq(&phba->hbalock);
1943 phba->over_temp_state = HBA_OVER_TEMP;
1944 spin_unlock_irq(&phba->hbalock);
1945 lpfc_sli4_offline_eratt(phba);
1948 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1949 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1950 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1951 "3143 Port Down: Firmware Update "
1954 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1955 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1957 "3144 Port Down: Debug Dump\n");
1958 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1959 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1961 "3145 Port Down: Provisioning\n");
1963 /* If resets are disabled then leave the HBA alone and return */
1964 if (!phba->cfg_enable_hba_reset)
1967 /* Check port status register for function reset */
1968 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1971 /* don't report event on forced debug dump */
1972 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1973 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1978 /* fall through for not able to recover */
1979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1980 "3152 Unrecoverable error, bring the port "
1982 lpfc_sli4_offline_eratt(phba);
1984 case LPFC_SLI_INTF_IF_TYPE_1:
1988 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1989 "3123 Report dump event to upper layer\n");
1990 /* Send an internal error event to mgmt application */
1991 lpfc_board_errevt_to_mgmt(phba);
1993 event_data = FC_REG_DUMP_EVENT;
1994 shost = lpfc_shost_from_vport(vport);
1995 fc_host_post_vendor_event(shost, fc_get_event_number(),
1996 sizeof(event_data), (char *) &event_data,
1997 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
2001 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2002 * @phba: pointer to lpfc HBA data structure.
2004 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2005 * routine from the API jump table function pointer from the lpfc_hba struct.
2009 * Any other value - error.
2012 lpfc_handle_eratt(struct lpfc_hba *phba)
2014 (*phba->lpfc_handle_eratt)(phba);
2018 * lpfc_handle_latt - The HBA link event handler
2019 * @phba: pointer to lpfc hba data structure.
2021 * This routine is invoked from the worker thread to handle a HBA host
2022 * attention link event. SLI3 only.
2025 lpfc_handle_latt(struct lpfc_hba *phba)
2027 struct lpfc_vport *vport = phba->pport;
2028 struct lpfc_sli *psli = &phba->sli;
2030 volatile uint32_t control;
2031 struct lpfc_dmabuf *mp;
2034 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2037 goto lpfc_handle_latt_err_exit;
2040 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2043 goto lpfc_handle_latt_free_pmb;
2046 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2049 goto lpfc_handle_latt_free_mp;
2052 /* Cleanup any outstanding ELS commands */
2053 lpfc_els_flush_all_cmd(phba);
2055 psli->slistat.link_event++;
2056 lpfc_read_topology(phba, pmb, mp);
2057 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2059 /* Block ELS IOCBs until we have processed this mbox command */
2060 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2061 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2062 if (rc == MBX_NOT_FINISHED) {
2064 goto lpfc_handle_latt_free_mbuf;
2067 /* Clear Link Attention in HA REG */
2068 spin_lock_irq(&phba->hbalock);
2069 writel(HA_LATT, phba->HAregaddr);
2070 readl(phba->HAregaddr); /* flush */
2071 spin_unlock_irq(&phba->hbalock);
2075 lpfc_handle_latt_free_mbuf:
2076 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2077 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2078 lpfc_handle_latt_free_mp:
2080 lpfc_handle_latt_free_pmb:
2081 mempool_free(pmb, phba->mbox_mem_pool);
2082 lpfc_handle_latt_err_exit:
2083 /* Enable Link attention interrupts */
2084 spin_lock_irq(&phba->hbalock);
2085 psli->sli_flag |= LPFC_PROCESS_LA;
2086 control = readl(phba->HCregaddr);
2087 control |= HC_LAINT_ENA;
2088 writel(control, phba->HCregaddr);
2089 readl(phba->HCregaddr); /* flush */
2091 /* Clear Link Attention in HA REG */
2092 writel(HA_LATT, phba->HAregaddr);
2093 readl(phba->HAregaddr); /* flush */
2094 spin_unlock_irq(&phba->hbalock);
2095 lpfc_linkdown(phba);
2096 phba->link_state = LPFC_HBA_ERROR;
2098 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2099 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2105 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2106 * @phba: pointer to lpfc hba data structure.
2107 * @vpd: pointer to the vital product data.
2108 * @len: length of the vital product data in bytes.
2110 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2111 * an array of characters. In this routine, the ModelName, ProgramType, and
2112 * ModelDesc, etc. fields of the phba data structure will be populated.
2115 * 0 - pointer to the VPD passed in is NULL
2119 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2121 uint8_t lenlo, lenhi;
2131 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2132 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2133 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2135 while (!finished && (index < (len - 4))) {
2136 switch (vpd[index]) {
2144 i = ((((unsigned short)lenhi) << 8) + lenlo);
2153 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2154 if (Length > len - index)
2155 Length = len - index;
2156 while (Length > 0) {
2157 /* Look for Serial Number */
2158 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2165 phba->SerialNumber[j++] = vpd[index++];
2169 phba->SerialNumber[j] = 0;
2172 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2173 phba->vpd_flag |= VPD_MODEL_DESC;
2180 phba->ModelDesc[j++] = vpd[index++];
2184 phba->ModelDesc[j] = 0;
2187 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2188 phba->vpd_flag |= VPD_MODEL_NAME;
2195 phba->ModelName[j++] = vpd[index++];
2199 phba->ModelName[j] = 0;
2202 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2203 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2210 phba->ProgramType[j++] = vpd[index++];
2214 phba->ProgramType[j] = 0;
2217 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2218 phba->vpd_flag |= VPD_PORT;
2225 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2226 (phba->sli4_hba.pport_name_sta ==
2227 LPFC_SLI4_PPNAME_GET)) {
2231 phba->Port[j++] = vpd[index++];
2235 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2236 (phba->sli4_hba.pport_name_sta ==
2237 LPFC_SLI4_PPNAME_NON))
2264 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2265 * @phba: pointer to lpfc hba data structure.
2266 * @mdp: pointer to the data structure to hold the derived model name.
2267 * @descp: pointer to the data structure to hold the derived description.
2269 * This routine retrieves HBA's description based on its registered PCI device
2270 * ID. The @descp passed into this function points to an array of 256 chars. It
2271 * shall be returned with the model name, maximum speed, and the host bus type.
2272 * The @mdp passed into this function points to an array of 80 chars. When the
2273 * function returns, the @mdp will be filled with the model name.
2276 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2279 uint16_t dev_id = phba->pcidev->device;
2282 int oneConnect = 0; /* default is not a oneConnect */
2287 } m = {"<Unknown>", "", ""};
2289 if (mdp && mdp[0] != '\0'
2290 && descp && descp[0] != '\0')
2293 if (phba->lmt & LMT_64Gb)
2295 else if (phba->lmt & LMT_32Gb)
2297 else if (phba->lmt & LMT_16Gb)
2299 else if (phba->lmt & LMT_10Gb)
2301 else if (phba->lmt & LMT_8Gb)
2303 else if (phba->lmt & LMT_4Gb)
2305 else if (phba->lmt & LMT_2Gb)
2307 else if (phba->lmt & LMT_1Gb)
2315 case PCI_DEVICE_ID_FIREFLY:
2316 m = (typeof(m)){"LP6000", "PCI",
2317 "Obsolete, Unsupported Fibre Channel Adapter"};
2319 case PCI_DEVICE_ID_SUPERFLY:
2320 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2321 m = (typeof(m)){"LP7000", "PCI", ""};
2323 m = (typeof(m)){"LP7000E", "PCI", ""};
2324 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2326 case PCI_DEVICE_ID_DRAGONFLY:
2327 m = (typeof(m)){"LP8000", "PCI",
2328 "Obsolete, Unsupported Fibre Channel Adapter"};
2330 case PCI_DEVICE_ID_CENTAUR:
2331 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2332 m = (typeof(m)){"LP9002", "PCI", ""};
2334 m = (typeof(m)){"LP9000", "PCI", ""};
2335 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2337 case PCI_DEVICE_ID_RFLY:
2338 m = (typeof(m)){"LP952", "PCI",
2339 "Obsolete, Unsupported Fibre Channel Adapter"};
2341 case PCI_DEVICE_ID_PEGASUS:
2342 m = (typeof(m)){"LP9802", "PCI-X",
2343 "Obsolete, Unsupported Fibre Channel Adapter"};
2345 case PCI_DEVICE_ID_THOR:
2346 m = (typeof(m)){"LP10000", "PCI-X",
2347 "Obsolete, Unsupported Fibre Channel Adapter"};
2349 case PCI_DEVICE_ID_VIPER:
2350 m = (typeof(m)){"LPX1000", "PCI-X",
2351 "Obsolete, Unsupported Fibre Channel Adapter"};
2353 case PCI_DEVICE_ID_PFLY:
2354 m = (typeof(m)){"LP982", "PCI-X",
2355 "Obsolete, Unsupported Fibre Channel Adapter"};
2357 case PCI_DEVICE_ID_TFLY:
2358 m = (typeof(m)){"LP1050", "PCI-X",
2359 "Obsolete, Unsupported Fibre Channel Adapter"};
2361 case PCI_DEVICE_ID_HELIOS:
2362 m = (typeof(m)){"LP11000", "PCI-X2",
2363 "Obsolete, Unsupported Fibre Channel Adapter"};
2365 case PCI_DEVICE_ID_HELIOS_SCSP:
2366 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2367 "Obsolete, Unsupported Fibre Channel Adapter"};
2369 case PCI_DEVICE_ID_HELIOS_DCSP:
2370 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2371 "Obsolete, Unsupported Fibre Channel Adapter"};
2373 case PCI_DEVICE_ID_NEPTUNE:
2374 m = (typeof(m)){"LPe1000", "PCIe",
2375 "Obsolete, Unsupported Fibre Channel Adapter"};
2377 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2378 m = (typeof(m)){"LPe1000-SP", "PCIe",
2379 "Obsolete, Unsupported Fibre Channel Adapter"};
2381 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2382 m = (typeof(m)){"LPe1002-SP", "PCIe",
2383 "Obsolete, Unsupported Fibre Channel Adapter"};
2385 case PCI_DEVICE_ID_BMID:
2386 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2388 case PCI_DEVICE_ID_BSMB:
2389 m = (typeof(m)){"LP111", "PCI-X2",
2390 "Obsolete, Unsupported Fibre Channel Adapter"};
2392 case PCI_DEVICE_ID_ZEPHYR:
2393 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2395 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2396 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2398 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2399 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2402 case PCI_DEVICE_ID_ZMID:
2403 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2405 case PCI_DEVICE_ID_ZSMB:
2406 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2408 case PCI_DEVICE_ID_LP101:
2409 m = (typeof(m)){"LP101", "PCI-X",
2410 "Obsolete, Unsupported Fibre Channel Adapter"};
2412 case PCI_DEVICE_ID_LP10000S:
2413 m = (typeof(m)){"LP10000-S", "PCI",
2414 "Obsolete, Unsupported Fibre Channel Adapter"};
2416 case PCI_DEVICE_ID_LP11000S:
2417 m = (typeof(m)){"LP11000-S", "PCI-X2",
2418 "Obsolete, Unsupported Fibre Channel Adapter"};
2420 case PCI_DEVICE_ID_LPE11000S:
2421 m = (typeof(m)){"LPe11000-S", "PCIe",
2422 "Obsolete, Unsupported Fibre Channel Adapter"};
2424 case PCI_DEVICE_ID_SAT:
2425 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2427 case PCI_DEVICE_ID_SAT_MID:
2428 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2430 case PCI_DEVICE_ID_SAT_SMB:
2431 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2433 case PCI_DEVICE_ID_SAT_DCSP:
2434 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2436 case PCI_DEVICE_ID_SAT_SCSP:
2437 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2439 case PCI_DEVICE_ID_SAT_S:
2440 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2442 case PCI_DEVICE_ID_HORNET:
2443 m = (typeof(m)){"LP21000", "PCIe",
2444 "Obsolete, Unsupported FCoE Adapter"};
2447 case PCI_DEVICE_ID_PROTEUS_VF:
2448 m = (typeof(m)){"LPev12000", "PCIe IOV",
2449 "Obsolete, Unsupported Fibre Channel Adapter"};
2451 case PCI_DEVICE_ID_PROTEUS_PF:
2452 m = (typeof(m)){"LPev12000", "PCIe IOV",
2453 "Obsolete, Unsupported Fibre Channel Adapter"};
2455 case PCI_DEVICE_ID_PROTEUS_S:
2456 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2457 "Obsolete, Unsupported Fibre Channel Adapter"};
2459 case PCI_DEVICE_ID_TIGERSHARK:
2461 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2463 case PCI_DEVICE_ID_TOMCAT:
2465 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2467 case PCI_DEVICE_ID_FALCON:
2468 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2469 "EmulexSecure Fibre"};
2471 case PCI_DEVICE_ID_BALIUS:
2472 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2473 "Obsolete, Unsupported Fibre Channel Adapter"};
2475 case PCI_DEVICE_ID_LANCER_FC:
2476 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2478 case PCI_DEVICE_ID_LANCER_FC_VF:
2479 m = (typeof(m)){"LPe16000", "PCIe",
2480 "Obsolete, Unsupported Fibre Channel Adapter"};
2482 case PCI_DEVICE_ID_LANCER_FCOE:
2484 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2486 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2488 m = (typeof(m)){"OCe15100", "PCIe",
2489 "Obsolete, Unsupported FCoE"};
2491 case PCI_DEVICE_ID_LANCER_G6_FC:
2492 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2494 case PCI_DEVICE_ID_LANCER_G7_FC:
2495 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2497 case PCI_DEVICE_ID_SKYHAWK:
2498 case PCI_DEVICE_ID_SKYHAWK_VF:
2500 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2503 m = (typeof(m)){"Unknown", "", ""};
2507 if (mdp && mdp[0] == '\0')
2508 snprintf(mdp, 79,"%s", m.name);
2510 * oneConnect hba requires special processing, they are all initiators
2511 * and we put the port number on the end
2513 if (descp && descp[0] == '\0') {
2515 snprintf(descp, 255,
2516 "Emulex OneConnect %s, %s Initiator %s",
2519 else if (max_speed == 0)
2520 snprintf(descp, 255,
2522 m.name, m.bus, m.function);
2524 snprintf(descp, 255,
2525 "Emulex %s %d%s %s %s",
2526 m.name, max_speed, (GE) ? "GE" : "Gb",
2532 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2533 * @phba: pointer to lpfc hba data structure.
2534 * @pring: pointer to a IOCB ring.
2535 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2537 * This routine posts a given number of IOCBs with the associated DMA buffer
2538 * descriptors specified by the cnt argument to the given IOCB ring.
2541 * The number of IOCBs NOT able to be posted to the IOCB ring.
2544 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2547 struct lpfc_iocbq *iocb;
2548 struct lpfc_dmabuf *mp1, *mp2;
2550 cnt += pring->missbufcnt;
2552 /* While there are buffers to post */
2554 /* Allocate buffer for command iocb */
2555 iocb = lpfc_sli_get_iocbq(phba);
2557 pring->missbufcnt = cnt;
2562 /* 2 buffers can be posted per command */
2563 /* Allocate buffer to post */
2564 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2566 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2567 if (!mp1 || !mp1->virt) {
2569 lpfc_sli_release_iocbq(phba, iocb);
2570 pring->missbufcnt = cnt;
2574 INIT_LIST_HEAD(&mp1->list);
2575 /* Allocate buffer to post */
2577 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2579 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2581 if (!mp2 || !mp2->virt) {
2583 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2585 lpfc_sli_release_iocbq(phba, iocb);
2586 pring->missbufcnt = cnt;
2590 INIT_LIST_HEAD(&mp2->list);
2595 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2596 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2597 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2598 icmd->ulpBdeCount = 1;
2601 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2602 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2603 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2605 icmd->ulpBdeCount = 2;
2608 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2611 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2613 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2617 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2621 lpfc_sli_release_iocbq(phba, iocb);
2622 pring->missbufcnt = cnt;
2625 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2627 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2629 pring->missbufcnt = 0;
2634 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2635 * @phba: pointer to lpfc hba data structure.
2637 * This routine posts initial receive IOCB buffers to the ELS ring. The
2638 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2639 * set to 64 IOCBs. SLI3 only.
2642 * 0 - success (currently always success)
2645 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2647 struct lpfc_sli *psli = &phba->sli;
2649 /* Ring 0, ELS / CT buffers */
2650 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2651 /* Ring 2 - FCP no buffers needed */
2656 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2659 * lpfc_sha_init - Set up initial array of hash table entries
2660 * @HashResultPointer: pointer to an array as hash table.
2662 * This routine sets up the initial values to the array of hash table entries
2666 lpfc_sha_init(uint32_t * HashResultPointer)
2668 HashResultPointer[0] = 0x67452301;
2669 HashResultPointer[1] = 0xEFCDAB89;
2670 HashResultPointer[2] = 0x98BADCFE;
2671 HashResultPointer[3] = 0x10325476;
2672 HashResultPointer[4] = 0xC3D2E1F0;
2676 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2677 * @HashResultPointer: pointer to an initial/result hash table.
2678 * @HashWorkingPointer: pointer to an working hash table.
2680 * This routine iterates an initial hash table pointed by @HashResultPointer
2681 * with the values from the working hash table pointeed by @HashWorkingPointer.
2682 * The results are putting back to the initial hash table, returned through
2683 * the @HashResultPointer as the result hash table.
2686 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2690 uint32_t A, B, C, D, E;
2693 HashWorkingPointer[t] =
2695 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2697 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2698 } while (++t <= 79);
2700 A = HashResultPointer[0];
2701 B = HashResultPointer[1];
2702 C = HashResultPointer[2];
2703 D = HashResultPointer[3];
2704 E = HashResultPointer[4];
2708 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2709 } else if (t < 40) {
2710 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2711 } else if (t < 60) {
2712 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2714 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2716 TEMP += S(5, A) + E + HashWorkingPointer[t];
2722 } while (++t <= 79);
2724 HashResultPointer[0] += A;
2725 HashResultPointer[1] += B;
2726 HashResultPointer[2] += C;
2727 HashResultPointer[3] += D;
2728 HashResultPointer[4] += E;
2733 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2734 * @RandomChallenge: pointer to the entry of host challenge random number array.
2735 * @HashWorking: pointer to the entry of the working hash array.
2737 * This routine calculates the working hash array referred by @HashWorking
2738 * from the challenge random numbers associated with the host, referred by
2739 * @RandomChallenge. The result is put into the entry of the working hash
2740 * array and returned by reference through @HashWorking.
2743 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2745 *HashWorking = (*RandomChallenge ^ *HashWorking);
2749 * lpfc_hba_init - Perform special handling for LC HBA initialization
2750 * @phba: pointer to lpfc hba data structure.
2751 * @hbainit: pointer to an array of unsigned 32-bit integers.
2753 * This routine performs the special handling for LC HBA initialization.
2756 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2759 uint32_t *HashWorking;
2760 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2762 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2766 HashWorking[0] = HashWorking[78] = *pwwnn++;
2767 HashWorking[1] = HashWorking[79] = *pwwnn;
2769 for (t = 0; t < 7; t++)
2770 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2772 lpfc_sha_init(hbainit);
2773 lpfc_sha_iterate(hbainit, HashWorking);
2778 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2779 * @vport: pointer to a virtual N_Port data structure.
2781 * This routine performs the necessary cleanups before deleting the @vport.
2782 * It invokes the discovery state machine to perform necessary state
2783 * transitions and to release the ndlps associated with the @vport. Note,
2784 * the physical port is treated as @vport 0.
2787 lpfc_cleanup(struct lpfc_vport *vport)
2789 struct lpfc_hba *phba = vport->phba;
2790 struct lpfc_nodelist *ndlp, *next_ndlp;
2793 if (phba->link_state > LPFC_LINK_DOWN)
2794 lpfc_port_link_failure(vport);
2796 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2797 if (!NLP_CHK_NODE_ACT(ndlp)) {
2798 ndlp = lpfc_enable_node(vport, ndlp,
2799 NLP_STE_UNUSED_NODE);
2802 spin_lock_irq(&phba->ndlp_lock);
2803 NLP_SET_FREE_REQ(ndlp);
2804 spin_unlock_irq(&phba->ndlp_lock);
2805 /* Trigger the release of the ndlp memory */
2809 spin_lock_irq(&phba->ndlp_lock);
2810 if (NLP_CHK_FREE_REQ(ndlp)) {
2811 /* The ndlp should not be in memory free mode already */
2812 spin_unlock_irq(&phba->ndlp_lock);
2815 /* Indicate request for freeing ndlp memory */
2816 NLP_SET_FREE_REQ(ndlp);
2817 spin_unlock_irq(&phba->ndlp_lock);
2819 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2820 ndlp->nlp_DID == Fabric_DID) {
2821 /* Just free up ndlp with Fabric_DID for vports */
2826 /* take care of nodes in unused state before the state
2827 * machine taking action.
2829 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2834 if (ndlp->nlp_type & NLP_FABRIC)
2835 lpfc_disc_state_machine(vport, ndlp, NULL,
2836 NLP_EVT_DEVICE_RECOVERY);
2838 lpfc_disc_state_machine(vport, ndlp, NULL,
2842 /* At this point, ALL ndlp's should be gone
2843 * because of the previous NLP_EVT_DEVICE_RM.
2844 * Lets wait for this to happen, if needed.
2846 while (!list_empty(&vport->fc_nodes)) {
2848 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2849 "0233 Nodelist not empty\n");
2850 list_for_each_entry_safe(ndlp, next_ndlp,
2851 &vport->fc_nodes, nlp_listp) {
2852 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2854 "0282 did:x%x ndlp:x%p "
2855 "usgmap:x%x refcnt:%d\n",
2856 ndlp->nlp_DID, (void *)ndlp,
2858 kref_read(&ndlp->kref));
2863 /* Wait for any activity on ndlps to settle */
2866 lpfc_cleanup_vports_rrqs(vport, NULL);
2870 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2871 * @vport: pointer to a virtual N_Port data structure.
2873 * This routine stops all the timers associated with a @vport. This function
2874 * is invoked before disabling or deleting a @vport. Note that the physical
2875 * port is treated as @vport 0.
2878 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2880 del_timer_sync(&vport->els_tmofunc);
2881 del_timer_sync(&vport->delayed_disc_tmo);
2882 lpfc_can_disctmo(vport);
2887 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2888 * @phba: pointer to lpfc hba data structure.
2890 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2891 * caller of this routine should already hold the host lock.
2894 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2896 /* Clear pending FCF rediscovery wait flag */
2897 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2899 /* Now, try to stop the timer */
2900 del_timer(&phba->fcf.redisc_wait);
2904 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2905 * @phba: pointer to lpfc hba data structure.
2907 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2908 * checks whether the FCF rediscovery wait timer is pending with the host
2909 * lock held before proceeding with disabling the timer and clearing the
2910 * wait timer pendig flag.
2913 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2915 spin_lock_irq(&phba->hbalock);
2916 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2917 /* FCF rediscovery timer already fired or stopped */
2918 spin_unlock_irq(&phba->hbalock);
2921 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2922 /* Clear failover in progress flags */
2923 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2924 spin_unlock_irq(&phba->hbalock);
2928 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2929 * @phba: pointer to lpfc hba data structure.
2931 * This routine stops all the timers associated with a HBA. This function is
2932 * invoked before either putting a HBA offline or unloading the driver.
2935 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2937 lpfc_stop_vport_timers(phba->pport);
2938 del_timer_sync(&phba->sli.mbox_tmo);
2939 del_timer_sync(&phba->fabric_block_timer);
2940 del_timer_sync(&phba->eratt_poll);
2941 del_timer_sync(&phba->hb_tmofunc);
2942 if (phba->sli_rev == LPFC_SLI_REV4) {
2943 del_timer_sync(&phba->rrq_tmr);
2944 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2946 phba->hb_outstanding = 0;
2948 switch (phba->pci_dev_grp) {
2949 case LPFC_PCI_DEV_LP:
2950 /* Stop any LightPulse device specific driver timers */
2951 del_timer_sync(&phba->fcp_poll_timer);
2953 case LPFC_PCI_DEV_OC:
2954 /* Stop any OneConnect device sepcific driver timers */
2955 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2959 "0297 Invalid device group (x%x)\n",
2967 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2968 * @phba: pointer to lpfc hba data structure.
2970 * This routine marks a HBA's management interface as blocked. Once the HBA's
2971 * management interface is marked as blocked, all the user space access to
2972 * the HBA, whether they are from sysfs interface or libdfc interface will
2973 * all be blocked. The HBA is set to block the management interface when the
2974 * driver prepares the HBA interface for online or offline.
2977 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2979 unsigned long iflag;
2980 uint8_t actcmd = MBX_HEARTBEAT;
2981 unsigned long timeout;
2983 spin_lock_irqsave(&phba->hbalock, iflag);
2984 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2985 spin_unlock_irqrestore(&phba->hbalock, iflag);
2986 if (mbx_action == LPFC_MBX_NO_WAIT)
2988 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2989 spin_lock_irqsave(&phba->hbalock, iflag);
2990 if (phba->sli.mbox_active) {
2991 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
2992 /* Determine how long we might wait for the active mailbox
2993 * command to be gracefully completed by firmware.
2995 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2996 phba->sli.mbox_active) * 1000) + jiffies;
2998 spin_unlock_irqrestore(&phba->hbalock, iflag);
3000 /* Wait for the outstnading mailbox command to complete */
3001 while (phba->sli.mbox_active) {
3002 /* Check active mailbox complete status every 2ms */
3004 if (time_after(jiffies, timeout)) {
3005 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3006 "2813 Mgmt IO is Blocked %x "
3007 "- mbox cmd %x still active\n",
3008 phba->sli.sli_flag, actcmd);
3015 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3016 * @phba: pointer to lpfc hba data structure.
3018 * Allocate RPIs for all active remote nodes. This is needed whenever
3019 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3020 * is to fixup the temporary rpi assignments.
3023 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3025 struct lpfc_nodelist *ndlp, *next_ndlp;
3026 struct lpfc_vport **vports;
3028 unsigned long flags;
3030 if (phba->sli_rev != LPFC_SLI_REV4)
3033 vports = lpfc_create_vport_work_array(phba);
3037 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3038 if (vports[i]->load_flag & FC_UNLOADING)
3041 list_for_each_entry_safe(ndlp, next_ndlp,
3042 &vports[i]->fc_nodes,
3044 if (!NLP_CHK_NODE_ACT(ndlp))
3046 rpi = lpfc_sli4_alloc_rpi(phba);
3047 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3048 spin_lock_irqsave(&phba->ndlp_lock, flags);
3049 NLP_CLR_NODE_ACT(ndlp);
3050 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3053 ndlp->nlp_rpi = rpi;
3054 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3055 "0009 rpi:%x DID:%x "
3056 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3057 ndlp->nlp_DID, ndlp->nlp_flag,
3058 ndlp->nlp_usg_map, ndlp);
3061 lpfc_destroy_vport_work_array(phba, vports);
3065 * lpfc_online - Initialize and bring a HBA online
3066 * @phba: pointer to lpfc hba data structure.
3068 * This routine initializes the HBA and brings a HBA online. During this
3069 * process, the management interface is blocked to prevent user space access
3070 * to the HBA interfering with the driver initialization.
3077 lpfc_online(struct lpfc_hba *phba)
3079 struct lpfc_vport *vport;
3080 struct lpfc_vport **vports;
3082 bool vpis_cleared = false;
3086 vport = phba->pport;
3088 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3091 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3092 "0458 Bring Adapter online\n");
3094 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3096 if (phba->sli_rev == LPFC_SLI_REV4) {
3097 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3098 lpfc_unblock_mgmt_io(phba);
3101 spin_lock_irq(&phba->hbalock);
3102 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3103 vpis_cleared = true;
3104 spin_unlock_irq(&phba->hbalock);
3106 /* Reestablish the local initiator port.
3107 * The offline process destroyed the previous lport.
3109 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3110 !phba->nvmet_support) {
3111 error = lpfc_nvme_create_localport(phba->pport);
3113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3114 "6132 NVME restore reg failed "
3115 "on nvmei error x%x\n", error);
3118 lpfc_sli_queue_init(phba);
3119 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3120 lpfc_unblock_mgmt_io(phba);
3125 vports = lpfc_create_vport_work_array(phba);
3126 if (vports != NULL) {
3127 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3128 struct Scsi_Host *shost;
3129 shost = lpfc_shost_from_vport(vports[i]);
3130 spin_lock_irq(shost->host_lock);
3131 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3132 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3133 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3134 if (phba->sli_rev == LPFC_SLI_REV4) {
3135 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3136 if ((vpis_cleared) &&
3137 (vports[i]->port_type !=
3138 LPFC_PHYSICAL_PORT))
3141 spin_unlock_irq(shost->host_lock);
3144 lpfc_destroy_vport_work_array(phba, vports);
3146 lpfc_unblock_mgmt_io(phba);
3151 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3152 * @phba: pointer to lpfc hba data structure.
3154 * This routine marks a HBA's management interface as not blocked. Once the
3155 * HBA's management interface is marked as not blocked, all the user space
3156 * access to the HBA, whether they are from sysfs interface or libdfc
3157 * interface will be allowed. The HBA is set to block the management interface
3158 * when the driver prepares the HBA interface for online or offline and then
3159 * set to unblock the management interface afterwards.
3162 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3164 unsigned long iflag;
3166 spin_lock_irqsave(&phba->hbalock, iflag);
3167 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3168 spin_unlock_irqrestore(&phba->hbalock, iflag);
3172 * lpfc_offline_prep - Prepare a HBA to be brought offline
3173 * @phba: pointer to lpfc hba data structure.
3175 * This routine is invoked to prepare a HBA to be brought offline. It performs
3176 * unregistration login to all the nodes on all vports and flushes the mailbox
3177 * queue to make it ready to be brought offline.
3180 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3182 struct lpfc_vport *vport = phba->pport;
3183 struct lpfc_nodelist *ndlp, *next_ndlp;
3184 struct lpfc_vport **vports;
3185 struct Scsi_Host *shost;
3188 if (vport->fc_flag & FC_OFFLINE_MODE)
3191 lpfc_block_mgmt_io(phba, mbx_action);
3193 lpfc_linkdown(phba);
3195 /* Issue an unreg_login to all nodes on all vports */
3196 vports = lpfc_create_vport_work_array(phba);
3197 if (vports != NULL) {
3198 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3199 if (vports[i]->load_flag & FC_UNLOADING)
3201 shost = lpfc_shost_from_vport(vports[i]);
3202 spin_lock_irq(shost->host_lock);
3203 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3204 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3205 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3206 spin_unlock_irq(shost->host_lock);
3208 shost = lpfc_shost_from_vport(vports[i]);
3209 list_for_each_entry_safe(ndlp, next_ndlp,
3210 &vports[i]->fc_nodes,
3212 if (!NLP_CHK_NODE_ACT(ndlp))
3214 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3216 if (ndlp->nlp_type & NLP_FABRIC) {
3217 lpfc_disc_state_machine(vports[i], ndlp,
3218 NULL, NLP_EVT_DEVICE_RECOVERY);
3219 lpfc_disc_state_machine(vports[i], ndlp,
3220 NULL, NLP_EVT_DEVICE_RM);
3222 spin_lock_irq(shost->host_lock);
3223 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3224 spin_unlock_irq(shost->host_lock);
3226 * Whenever an SLI4 port goes offline, free the
3227 * RPI. Get a new RPI when the adapter port
3228 * comes back online.
3230 if (phba->sli_rev == LPFC_SLI_REV4) {
3231 lpfc_printf_vlog(ndlp->vport,
3232 KERN_INFO, LOG_NODE,
3233 "0011 lpfc_offline: "
3235 "usgmap:x%x rpi:%x\n",
3236 ndlp, ndlp->nlp_DID,
3240 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3242 lpfc_unreg_rpi(vports[i], ndlp);
3246 lpfc_destroy_vport_work_array(phba, vports);
3248 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3251 flush_workqueue(phba->wq);
3255 * lpfc_offline - Bring a HBA offline
3256 * @phba: pointer to lpfc hba data structure.
3258 * This routine actually brings a HBA offline. It stops all the timers
3259 * associated with the HBA, brings down the SLI layer, and eventually
3260 * marks the HBA as in offline state for the upper layer protocol.
3263 lpfc_offline(struct lpfc_hba *phba)
3265 struct Scsi_Host *shost;
3266 struct lpfc_vport **vports;
3269 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3272 /* stop port and all timers associated with this hba */
3273 lpfc_stop_port(phba);
3275 /* Tear down the local and target port registrations. The
3276 * nvme transports need to cleanup.
3278 lpfc_nvmet_destroy_targetport(phba);
3279 lpfc_nvme_destroy_localport(phba->pport);
3281 vports = lpfc_create_vport_work_array(phba);
3283 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3284 lpfc_stop_vport_timers(vports[i]);
3285 lpfc_destroy_vport_work_array(phba, vports);
3286 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3287 "0460 Bring Adapter offline\n");
3288 /* Bring down the SLI Layer and cleanup. The HBA is offline
3290 lpfc_sli_hba_down(phba);
3291 spin_lock_irq(&phba->hbalock);
3293 spin_unlock_irq(&phba->hbalock);
3294 vports = lpfc_create_vport_work_array(phba);
3296 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3297 shost = lpfc_shost_from_vport(vports[i]);
3298 spin_lock_irq(shost->host_lock);
3299 vports[i]->work_port_events = 0;
3300 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3301 spin_unlock_irq(shost->host_lock);
3303 lpfc_destroy_vport_work_array(phba, vports);
3307 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3308 * @phba: pointer to lpfc hba data structure.
3310 * This routine is to free all the SCSI buffers and IOCBs from the driver
3311 * list back to kernel. It is called from lpfc_pci_remove_one to free
3312 * the internal resources before the device is removed from the system.
3315 lpfc_scsi_free(struct lpfc_hba *phba)
3317 struct lpfc_scsi_buf *sb, *sb_next;
3319 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3322 spin_lock_irq(&phba->hbalock);
3324 /* Release all the lpfc_scsi_bufs maintained by this host. */
3326 spin_lock(&phba->scsi_buf_list_put_lock);
3327 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3329 list_del(&sb->list);
3330 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3333 phba->total_scsi_bufs--;
3335 spin_unlock(&phba->scsi_buf_list_put_lock);
3337 spin_lock(&phba->scsi_buf_list_get_lock);
3338 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3340 list_del(&sb->list);
3341 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3344 phba->total_scsi_bufs--;
3346 spin_unlock(&phba->scsi_buf_list_get_lock);
3347 spin_unlock_irq(&phba->hbalock);
3350 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3351 * @phba: pointer to lpfc hba data structure.
3353 * This routine is to free all the NVME buffers and IOCBs from the driver
3354 * list back to kernel. It is called from lpfc_pci_remove_one to free
3355 * the internal resources before the device is removed from the system.
3358 lpfc_nvme_free(struct lpfc_hba *phba)
3360 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
3362 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3365 spin_lock_irq(&phba->hbalock);
3367 /* Release all the lpfc_nvme_bufs maintained by this host. */
3368 spin_lock(&phba->nvme_buf_list_put_lock);
3369 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3370 &phba->lpfc_nvme_buf_list_put, list) {
3371 list_del(&lpfc_ncmd->list);
3372 phba->put_nvme_bufs--;
3373 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3374 lpfc_ncmd->dma_handle);
3376 phba->total_nvme_bufs--;
3378 spin_unlock(&phba->nvme_buf_list_put_lock);
3380 spin_lock(&phba->nvme_buf_list_get_lock);
3381 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3382 &phba->lpfc_nvme_buf_list_get, list) {
3383 list_del(&lpfc_ncmd->list);
3384 phba->get_nvme_bufs--;
3385 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3386 lpfc_ncmd->dma_handle);
3388 phba->total_nvme_bufs--;
3390 spin_unlock(&phba->nvme_buf_list_get_lock);
3391 spin_unlock_irq(&phba->hbalock);
3394 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3395 * @phba: pointer to lpfc hba data structure.
3397 * This routine first calculates the sizes of the current els and allocated
3398 * scsi sgl lists, and then goes through all sgls to updates the physical
3399 * XRIs assigned due to port function reset. During port initialization, the
3400 * current els and allocated scsi sgl lists are 0s.
3403 * 0 - successful (for now, it always returns 0)
3406 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3408 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3409 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3410 LIST_HEAD(els_sgl_list);
3414 * update on pci function's els xri-sgl list
3416 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3418 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3419 /* els xri-sgl expanded */
3420 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3421 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3422 "3157 ELS xri-sgl count increased from "
3423 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3425 /* allocate the additional els sgls */
3426 for (i = 0; i < xri_cnt; i++) {
3427 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3429 if (sglq_entry == NULL) {
3430 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3431 "2562 Failure to allocate an "
3432 "ELS sgl entry:%d\n", i);
3436 sglq_entry->buff_type = GEN_BUFF_TYPE;
3437 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3439 if (sglq_entry->virt == NULL) {
3441 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3442 "2563 Failure to allocate an "
3443 "ELS mbuf:%d\n", i);
3447 sglq_entry->sgl = sglq_entry->virt;
3448 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3449 sglq_entry->state = SGL_FREED;
3450 list_add_tail(&sglq_entry->list, &els_sgl_list);
3452 spin_lock_irq(&phba->hbalock);
3453 spin_lock(&phba->sli4_hba.sgl_list_lock);
3454 list_splice_init(&els_sgl_list,
3455 &phba->sli4_hba.lpfc_els_sgl_list);
3456 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3457 spin_unlock_irq(&phba->hbalock);
3458 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3459 /* els xri-sgl shrinked */
3460 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3461 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3462 "3158 ELS xri-sgl count decreased from "
3463 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3465 spin_lock_irq(&phba->hbalock);
3466 spin_lock(&phba->sli4_hba.sgl_list_lock);
3467 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3469 /* release extra els sgls from list */
3470 for (i = 0; i < xri_cnt; i++) {
3471 list_remove_head(&els_sgl_list,
3472 sglq_entry, struct lpfc_sglq, list);
3474 __lpfc_mbuf_free(phba, sglq_entry->virt,
3479 list_splice_init(&els_sgl_list,
3480 &phba->sli4_hba.lpfc_els_sgl_list);
3481 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3482 spin_unlock_irq(&phba->hbalock);
3484 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3485 "3163 ELS xri-sgl count unchanged: %d\n",
3487 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3489 /* update xris to els sgls on the list */
3491 sglq_entry_next = NULL;
3492 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3493 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3494 lxri = lpfc_sli4_next_xritag(phba);
3495 if (lxri == NO_XRI) {
3496 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3497 "2400 Failed to allocate xri for "
3502 sglq_entry->sli4_lxritag = lxri;
3503 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3508 lpfc_free_els_sgl_list(phba);
3513 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3514 * @phba: pointer to lpfc hba data structure.
3516 * This routine first calculates the sizes of the current els and allocated
3517 * scsi sgl lists, and then goes through all sgls to updates the physical
3518 * XRIs assigned due to port function reset. During port initialization, the
3519 * current els and allocated scsi sgl lists are 0s.
3522 * 0 - successful (for now, it always returns 0)
3525 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3527 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3528 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3529 uint16_t nvmet_xri_cnt;
3530 LIST_HEAD(nvmet_sgl_list);
3534 * update on pci function's nvmet xri-sgl list
3536 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3538 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3539 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3540 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3541 /* els xri-sgl expanded */
3542 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3543 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3544 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3545 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3546 /* allocate the additional nvmet sgls */
3547 for (i = 0; i < xri_cnt; i++) {
3548 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3550 if (sglq_entry == NULL) {
3551 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3552 "6303 Failure to allocate an "
3553 "NVMET sgl entry:%d\n", i);
3557 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3558 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3560 if (sglq_entry->virt == NULL) {
3562 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3563 "6304 Failure to allocate an "
3564 "NVMET buf:%d\n", i);
3568 sglq_entry->sgl = sglq_entry->virt;
3569 memset(sglq_entry->sgl, 0,
3570 phba->cfg_sg_dma_buf_size);
3571 sglq_entry->state = SGL_FREED;
3572 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3574 spin_lock_irq(&phba->hbalock);
3575 spin_lock(&phba->sli4_hba.sgl_list_lock);
3576 list_splice_init(&nvmet_sgl_list,
3577 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3578 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3579 spin_unlock_irq(&phba->hbalock);
3580 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3581 /* nvmet xri-sgl shrunk */
3582 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3583 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3584 "6305 NVMET xri-sgl count decreased from "
3585 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3587 spin_lock_irq(&phba->hbalock);
3588 spin_lock(&phba->sli4_hba.sgl_list_lock);
3589 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3591 /* release extra nvmet sgls from list */
3592 for (i = 0; i < xri_cnt; i++) {
3593 list_remove_head(&nvmet_sgl_list,
3594 sglq_entry, struct lpfc_sglq, list);
3596 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3601 list_splice_init(&nvmet_sgl_list,
3602 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3603 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3604 spin_unlock_irq(&phba->hbalock);
3606 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3607 "6306 NVMET xri-sgl count unchanged: %d\n",
3609 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3611 /* update xris to nvmet sgls on the list */
3613 sglq_entry_next = NULL;
3614 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3615 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3616 lxri = lpfc_sli4_next_xritag(phba);
3617 if (lxri == NO_XRI) {
3618 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3619 "6307 Failed to allocate xri for "
3624 sglq_entry->sli4_lxritag = lxri;
3625 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3630 lpfc_free_nvmet_sgl_list(phba);
3635 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3636 * @phba: pointer to lpfc hba data structure.
3638 * This routine first calculates the sizes of the current els and allocated
3639 * scsi sgl lists, and then goes through all sgls to updates the physical
3640 * XRIs assigned due to port function reset. During port initialization, the
3641 * current els and allocated scsi sgl lists are 0s.
3644 * 0 - successful (for now, it always returns 0)
3647 lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3649 struct lpfc_scsi_buf *psb, *psb_next;
3650 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3651 LIST_HEAD(scsi_sgl_list);
3655 * update on pci function's els xri-sgl list
3657 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3658 phba->total_scsi_bufs = 0;
3661 * update on pci function's allocated scsi xri-sgl list
3663 /* maximum number of xris available for scsi buffers */
3664 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3667 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3670 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3671 phba->sli4_hba.scsi_xri_max = /* Split them up */
3672 (phba->sli4_hba.scsi_xri_max *
3673 phba->cfg_xri_split) / 100;
3675 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3676 spin_lock(&phba->scsi_buf_list_put_lock);
3677 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3678 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3679 spin_unlock(&phba->scsi_buf_list_put_lock);
3680 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3682 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3683 "6060 Current allocated SCSI xri-sgl count:%d, "
3684 "maximum SCSI xri count:%d (split:%d)\n",
3685 phba->sli4_hba.scsi_xri_cnt,
3686 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3688 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3689 /* max scsi xri shrinked below the allocated scsi buffers */
3690 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3691 phba->sli4_hba.scsi_xri_max;
3692 /* release the extra allocated scsi buffers */
3693 for (i = 0; i < scsi_xri_cnt; i++) {
3694 list_remove_head(&scsi_sgl_list, psb,
3695 struct lpfc_scsi_buf, list);
3697 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3698 psb->data, psb->dma_handle);
3702 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3703 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3704 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3707 /* update xris associated to remaining allocated scsi buffers */
3710 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3711 lxri = lpfc_sli4_next_xritag(phba);
3712 if (lxri == NO_XRI) {
3713 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3714 "2560 Failed to allocate xri for "
3719 psb->cur_iocbq.sli4_lxritag = lxri;
3720 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3722 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3723 spin_lock(&phba->scsi_buf_list_put_lock);
3724 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3725 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3726 spin_unlock(&phba->scsi_buf_list_put_lock);
3727 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3731 lpfc_scsi_free(phba);
3736 lpfc_get_wwpn(struct lpfc_hba *phba)
3740 LPFC_MBOXQ_t *mboxq;
3743 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3746 return (uint64_t)-1;
3748 /* First get WWN of HBA instance */
3749 lpfc_read_nv(phba, mboxq);
3750 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3751 if (rc != MBX_SUCCESS) {
3752 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3753 "6019 Mailbox failed , mbxCmd x%x "
3754 "READ_NV, mbxStatus x%x\n",
3755 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3756 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3757 mempool_free(mboxq, phba->mbox_mem_pool);
3758 return (uint64_t) -1;
3761 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3762 /* wwn is WWPN of HBA instance */
3763 mempool_free(mboxq, phba->mbox_mem_pool);
3764 if (phba->sli_rev == LPFC_SLI_REV4)
3765 return be64_to_cpu(wwn);
3767 return rol64(wwn, 32);
3771 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3772 * @phba: pointer to lpfc hba data structure.
3774 * This routine first calculates the sizes of the current els and allocated
3775 * scsi sgl lists, and then goes through all sgls to updates the physical
3776 * XRIs assigned due to port function reset. During port initialization, the
3777 * current els and allocated scsi sgl lists are 0s.
3780 * 0 - successful (for now, it always returns 0)
3783 lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3785 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3786 uint16_t i, lxri, els_xri_cnt;
3787 uint16_t nvme_xri_cnt, nvme_xri_max;
3788 LIST_HEAD(nvme_sgl_list);
3791 phba->total_nvme_bufs = 0;
3792 phba->get_nvme_bufs = 0;
3793 phba->put_nvme_bufs = 0;
3795 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3798 * update on pci function's allocated nvme xri-sgl list
3801 /* maximum number of xris available for nvme buffers */
3802 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3803 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3804 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3805 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3807 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3808 "6074 Current allocated NVME xri-sgl count:%d, "
3809 "maximum NVME xri count:%d\n",
3810 phba->sli4_hba.nvme_xri_cnt,
3811 phba->sli4_hba.nvme_xri_max);
3813 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3814 spin_lock(&phba->nvme_buf_list_put_lock);
3815 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3816 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3817 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3818 phba->get_nvme_bufs = 0;
3819 phba->put_nvme_bufs = 0;
3820 spin_unlock(&phba->nvme_buf_list_put_lock);
3821 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3823 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3824 /* max nvme xri shrunk below the allocated nvme buffers */
3825 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3826 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3827 phba->sli4_hba.nvme_xri_max;
3828 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3829 /* release the extra allocated nvme buffers */
3830 for (i = 0; i < nvme_xri_cnt; i++) {
3831 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3832 struct lpfc_nvme_buf, list);
3834 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3836 lpfc_ncmd->dma_handle);
3840 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3841 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3842 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3845 /* update xris associated to remaining allocated nvme buffers */
3847 lpfc_ncmd_next = NULL;
3848 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3849 &nvme_sgl_list, list) {
3850 lxri = lpfc_sli4_next_xritag(phba);
3851 if (lxri == NO_XRI) {
3852 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3853 "6075 Failed to allocate xri for "
3858 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3859 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3861 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3862 spin_lock(&phba->nvme_buf_list_put_lock);
3863 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3864 phba->get_nvme_bufs = cnt;
3865 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3866 spin_unlock(&phba->nvme_buf_list_put_lock);
3867 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3871 lpfc_nvme_free(phba);
3876 * lpfc_create_port - Create an FC port
3877 * @phba: pointer to lpfc hba data structure.
3878 * @instance: a unique integer ID to this FC port.
3879 * @dev: pointer to the device data structure.
3881 * This routine creates a FC port for the upper layer protocol. The FC port
3882 * can be created on top of either a physical port or a virtual port provided
3883 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3884 * and associates the FC port created before adding the shost into the SCSI
3888 * @vport - pointer to the virtual N_Port data structure.
3889 * NULL - port create failed.
3892 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3894 struct lpfc_vport *vport;
3895 struct Scsi_Host *shost = NULL;
3899 bool use_no_reset_hba = false;
3902 if (lpfc_no_hba_reset_cnt) {
3903 if (phba->sli_rev < LPFC_SLI_REV4 &&
3904 dev == &phba->pcidev->dev) {
3905 /* Reset the port first */
3906 lpfc_sli_brdrestart(phba);
3907 rc = lpfc_sli_chipset_init(phba);
3911 wwn = lpfc_get_wwpn(phba);
3914 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3915 if (wwn == lpfc_no_hba_reset[i]) {
3916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3917 "6020 Setting use_no_reset port=%llx\n",
3919 use_no_reset_hba = true;
3924 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3925 if (dev != &phba->pcidev->dev) {
3926 shost = scsi_host_alloc(&lpfc_vport_template,
3927 sizeof(struct lpfc_vport));
3929 if (!use_no_reset_hba)
3930 shost = scsi_host_alloc(&lpfc_template,
3931 sizeof(struct lpfc_vport));
3933 shost = scsi_host_alloc(&lpfc_template_no_hr,
3934 sizeof(struct lpfc_vport));
3936 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3937 shost = scsi_host_alloc(&lpfc_template_nvme,
3938 sizeof(struct lpfc_vport));
3943 vport = (struct lpfc_vport *) shost->hostdata;
3945 vport->load_flag |= FC_LOADING;
3946 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3947 vport->fc_rscn_flush = 0;
3948 lpfc_get_vport_cfgparam(vport);
3950 shost->unique_id = instance;
3951 shost->max_id = LPFC_MAX_TARGET;
3952 shost->max_lun = vport->cfg_max_luns;
3953 shost->this_id = -1;
3954 shost->max_cmd_len = 16;
3955 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
3956 if (phba->sli_rev == LPFC_SLI_REV4) {
3957 shost->dma_boundary =
3958 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
3959 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3963 * Set initial can_queue value since 0 is no longer supported and
3964 * scsi_add_host will fail. This will be adjusted later based on the
3965 * max xri value determined in hba setup.
3967 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3968 if (dev != &phba->pcidev->dev) {
3969 shost->transportt = lpfc_vport_transport_template;
3970 vport->port_type = LPFC_NPIV_PORT;
3972 shost->transportt = lpfc_transport_template;
3973 vport->port_type = LPFC_PHYSICAL_PORT;
3976 /* Initialize all internally managed lists. */
3977 INIT_LIST_HEAD(&vport->fc_nodes);
3978 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3979 spin_lock_init(&vport->work_port_lock);
3981 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
3983 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
3985 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
3987 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
3991 spin_lock_irq(&phba->hbalock);
3992 list_add_tail(&vport->listentry, &phba->port_list);
3993 spin_unlock_irq(&phba->hbalock);
3997 scsi_host_put(shost);
4003 * destroy_port - destroy an FC port
4004 * @vport: pointer to an lpfc virtual N_Port data structure.
4006 * This routine destroys a FC port from the upper layer protocol. All the
4007 * resources associated with the port are released.
4010 destroy_port(struct lpfc_vport *vport)
4012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4013 struct lpfc_hba *phba = vport->phba;
4015 lpfc_debugfs_terminate(vport);
4016 fc_remove_host(shost);
4017 scsi_remove_host(shost);
4019 spin_lock_irq(&phba->hbalock);
4020 list_del_init(&vport->listentry);
4021 spin_unlock_irq(&phba->hbalock);
4023 lpfc_cleanup(vport);
4028 * lpfc_get_instance - Get a unique integer ID
4030 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4031 * uses the kernel idr facility to perform the task.
4034 * instance - a unique integer ID allocated as the new instance.
4035 * -1 - lpfc get instance failed.
4038 lpfc_get_instance(void)
4042 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4043 return ret < 0 ? -1 : ret;
4047 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4048 * @shost: pointer to SCSI host data structure.
4049 * @time: elapsed time of the scan in jiffies.
4051 * This routine is called by the SCSI layer with a SCSI host to determine
4052 * whether the scan host is finished.
4054 * Note: there is no scan_start function as adapter initialization will have
4055 * asynchronously kicked off the link initialization.
4058 * 0 - SCSI host scan is not over yet.
4059 * 1 - SCSI host scan is over.
4061 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4064 struct lpfc_hba *phba = vport->phba;
4067 spin_lock_irq(shost->host_lock);
4069 if (vport->load_flag & FC_UNLOADING) {
4073 if (time >= msecs_to_jiffies(30 * 1000)) {
4074 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4075 "0461 Scanning longer than 30 "
4076 "seconds. Continuing initialization\n");
4080 if (time >= msecs_to_jiffies(15 * 1000) &&
4081 phba->link_state <= LPFC_LINK_DOWN) {
4082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4083 "0465 Link down longer than 15 "
4084 "seconds. Continuing initialization\n");
4089 if (vport->port_state != LPFC_VPORT_READY)
4091 if (vport->num_disc_nodes || vport->fc_prli_sent)
4093 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4095 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4101 spin_unlock_irq(shost->host_lock);
4106 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4107 * @shost: pointer to SCSI host data structure.
4109 * This routine initializes a given SCSI host attributes on a FC port. The
4110 * SCSI host can be either on top of a physical port or a virtual port.
4112 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
4117 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4120 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4121 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4122 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4124 memset(fc_host_supported_fc4s(shost), 0,
4125 sizeof(fc_host_supported_fc4s(shost)));
4126 fc_host_supported_fc4s(shost)[2] = 1;
4127 fc_host_supported_fc4s(shost)[7] = 1;
4129 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4130 sizeof fc_host_symbolic_name(shost));
4132 fc_host_supported_speeds(shost) = 0;
4133 if (phba->lmt & LMT_64Gb)
4134 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4135 if (phba->lmt & LMT_32Gb)
4136 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4137 if (phba->lmt & LMT_16Gb)
4138 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4139 if (phba->lmt & LMT_10Gb)
4140 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4141 if (phba->lmt & LMT_8Gb)
4142 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4143 if (phba->lmt & LMT_4Gb)
4144 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4145 if (phba->lmt & LMT_2Gb)
4146 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4147 if (phba->lmt & LMT_1Gb)
4148 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4150 fc_host_maxframe_size(shost) =
4151 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4152 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4154 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4156 /* This value is also unchanging */
4157 memset(fc_host_active_fc4s(shost), 0,
4158 sizeof(fc_host_active_fc4s(shost)));
4159 fc_host_active_fc4s(shost)[2] = 1;
4160 fc_host_active_fc4s(shost)[7] = 1;
4162 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4163 spin_lock_irq(shost->host_lock);
4164 vport->load_flag &= ~FC_LOADING;
4165 spin_unlock_irq(shost->host_lock);
4169 * lpfc_stop_port_s3 - Stop SLI3 device port
4170 * @phba: pointer to lpfc hba data structure.
4172 * This routine is invoked to stop an SLI3 device port, it stops the device
4173 * from generating interrupts and stops the device driver's timers for the
4177 lpfc_stop_port_s3(struct lpfc_hba *phba)
4179 /* Clear all interrupt enable conditions */
4180 writel(0, phba->HCregaddr);
4181 readl(phba->HCregaddr); /* flush */
4182 /* Clear all pending interrupts */
4183 writel(0xffffffff, phba->HAregaddr);
4184 readl(phba->HAregaddr); /* flush */
4186 /* Reset some HBA SLI setup states */
4187 lpfc_stop_hba_timers(phba);
4188 phba->pport->work_port_events = 0;
4192 * lpfc_stop_port_s4 - Stop SLI4 device port
4193 * @phba: pointer to lpfc hba data structure.
4195 * This routine is invoked to stop an SLI4 device port, it stops the device
4196 * from generating interrupts and stops the device driver's timers for the
4200 lpfc_stop_port_s4(struct lpfc_hba *phba)
4202 /* Reset some HBA SLI4 setup states */
4203 lpfc_stop_hba_timers(phba);
4204 phba->pport->work_port_events = 0;
4205 phba->sli4_hba.intr_enable = 0;
4209 * lpfc_stop_port - Wrapper function for stopping hba port
4210 * @phba: Pointer to HBA context object.
4212 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4213 * the API jump table function pointer from the lpfc_hba struct.
4216 lpfc_stop_port(struct lpfc_hba *phba)
4218 phba->lpfc_stop_port(phba);
4221 flush_workqueue(phba->wq);
4225 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4226 * @phba: Pointer to hba for which this call is being executed.
4228 * This routine starts the timer waiting for the FCF rediscovery to complete.
4231 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4233 unsigned long fcf_redisc_wait_tmo =
4234 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4235 /* Start fcf rediscovery wait period timer */
4236 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4237 spin_lock_irq(&phba->hbalock);
4238 /* Allow action to new fcf asynchronous event */
4239 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4240 /* Mark the FCF rediscovery pending state */
4241 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4242 spin_unlock_irq(&phba->hbalock);
4246 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4247 * @ptr: Map to lpfc_hba data structure pointer.
4249 * This routine is invoked when waiting for FCF table rediscover has been
4250 * timed out. If new FCF record(s) has (have) been discovered during the
4251 * wait period, a new FCF event shall be added to the FCOE async event
4252 * list, and then worker thread shall be waked up for processing from the
4253 * worker thread context.
4256 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
4258 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
4260 /* Don't send FCF rediscovery event if timer cancelled */
4261 spin_lock_irq(&phba->hbalock);
4262 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4263 spin_unlock_irq(&phba->hbalock);
4266 /* Clear FCF rediscovery timer pending flag */
4267 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4268 /* FCF rediscovery event to worker thread */
4269 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4270 spin_unlock_irq(&phba->hbalock);
4271 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4272 "2776 FCF rediscover quiescent timer expired\n");
4273 /* wake up worker thread */
4274 lpfc_worker_wake_up(phba);
4278 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4279 * @phba: pointer to lpfc hba data structure.
4280 * @acqe_link: pointer to the async link completion queue entry.
4282 * This routine is to parse the SLI4 link-attention link fault code.
4285 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4286 struct lpfc_acqe_link *acqe_link)
4288 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4289 case LPFC_ASYNC_LINK_FAULT_NONE:
4290 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4291 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4292 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
4295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4296 "0398 Unknown link fault code: x%x\n",
4297 bf_get(lpfc_acqe_link_fault, acqe_link));
4303 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4304 * @phba: pointer to lpfc hba data structure.
4305 * @acqe_link: pointer to the async link completion queue entry.
4307 * This routine is to parse the SLI4 link attention type and translate it
4308 * into the base driver's link attention type coding.
4310 * Return: Link attention type in terms of base driver's coding.
4313 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4314 struct lpfc_acqe_link *acqe_link)
4318 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4319 case LPFC_ASYNC_LINK_STATUS_DOWN:
4320 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
4321 att_type = LPFC_ATT_LINK_DOWN;
4323 case LPFC_ASYNC_LINK_STATUS_UP:
4324 /* Ignore physical link up events - wait for logical link up */
4325 att_type = LPFC_ATT_RESERVED;
4327 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
4328 att_type = LPFC_ATT_LINK_UP;
4331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4332 "0399 Invalid link attention type: x%x\n",
4333 bf_get(lpfc_acqe_link_status, acqe_link));
4334 att_type = LPFC_ATT_RESERVED;
4341 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4342 * @phba: pointer to lpfc hba data structure.
4344 * This routine is to get an SLI3 FC port's link speed in Mbps.
4346 * Return: link speed in terms of Mbps.
4349 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4351 uint32_t link_speed;
4353 if (!lpfc_is_link_up(phba))
4356 if (phba->sli_rev <= LPFC_SLI_REV3) {
4357 switch (phba->fc_linkspeed) {
4358 case LPFC_LINK_SPEED_1GHZ:
4361 case LPFC_LINK_SPEED_2GHZ:
4364 case LPFC_LINK_SPEED_4GHZ:
4367 case LPFC_LINK_SPEED_8GHZ:
4370 case LPFC_LINK_SPEED_10GHZ:
4373 case LPFC_LINK_SPEED_16GHZ:
4380 if (phba->sli4_hba.link_state.logical_speed)
4382 phba->sli4_hba.link_state.logical_speed;
4384 link_speed = phba->sli4_hba.link_state.speed;
4390 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4391 * @phba: pointer to lpfc hba data structure.
4392 * @evt_code: asynchronous event code.
4393 * @speed_code: asynchronous event link speed code.
4395 * This routine is to parse the giving SLI4 async event link speed code into
4396 * value of Mbps for the link speed.
4398 * Return: link speed in terms of Mbps.
4401 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4404 uint32_t port_speed;
4407 case LPFC_TRAILER_CODE_LINK:
4408 switch (speed_code) {
4409 case LPFC_ASYNC_LINK_SPEED_ZERO:
4412 case LPFC_ASYNC_LINK_SPEED_10MBPS:
4415 case LPFC_ASYNC_LINK_SPEED_100MBPS:
4418 case LPFC_ASYNC_LINK_SPEED_1GBPS:
4421 case LPFC_ASYNC_LINK_SPEED_10GBPS:
4424 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4427 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4430 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4437 case LPFC_TRAILER_CODE_FC:
4438 switch (speed_code) {
4439 case LPFC_FC_LA_SPEED_UNKNOWN:
4442 case LPFC_FC_LA_SPEED_1G:
4445 case LPFC_FC_LA_SPEED_2G:
4448 case LPFC_FC_LA_SPEED_4G:
4451 case LPFC_FC_LA_SPEED_8G:
4454 case LPFC_FC_LA_SPEED_10G:
4457 case LPFC_FC_LA_SPEED_16G:
4460 case LPFC_FC_LA_SPEED_32G:
4463 case LPFC_FC_LA_SPEED_64G:
4477 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4478 * @phba: pointer to lpfc hba data structure.
4479 * @acqe_link: pointer to the async link completion queue entry.
4481 * This routine is to handle the SLI4 asynchronous FCoE link event.
4484 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4485 struct lpfc_acqe_link *acqe_link)
4487 struct lpfc_dmabuf *mp;
4490 struct lpfc_mbx_read_top *la;
4494 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
4495 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
4497 phba->fcoe_eventtag = acqe_link->event_tag;
4498 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4501 "0395 The mboxq allocation failed\n");
4504 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4507 "0396 The lpfc_dmabuf allocation failed\n");
4510 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4512 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4513 "0397 The mbuf allocation failed\n");
4514 goto out_free_dmabuf;
4517 /* Cleanup any outstanding ELS commands */
4518 lpfc_els_flush_all_cmd(phba);
4520 /* Block ELS IOCBs until we have done process link event */
4521 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4523 /* Update link event statistics */
4524 phba->sli.slistat.link_event++;
4526 /* Create lpfc_handle_latt mailbox command from link ACQE */
4527 lpfc_read_topology(phba, pmb, mp);
4528 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4529 pmb->vport = phba->pport;
4531 /* Keep the link status for extra SLI4 state machine reference */
4532 phba->sli4_hba.link_state.speed =
4533 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4534 bf_get(lpfc_acqe_link_speed, acqe_link));
4535 phba->sli4_hba.link_state.duplex =
4536 bf_get(lpfc_acqe_link_duplex, acqe_link);
4537 phba->sli4_hba.link_state.status =
4538 bf_get(lpfc_acqe_link_status, acqe_link);
4539 phba->sli4_hba.link_state.type =
4540 bf_get(lpfc_acqe_link_type, acqe_link);
4541 phba->sli4_hba.link_state.number =
4542 bf_get(lpfc_acqe_link_number, acqe_link);
4543 phba->sli4_hba.link_state.fault =
4544 bf_get(lpfc_acqe_link_fault, acqe_link);
4545 phba->sli4_hba.link_state.logical_speed =
4546 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4548 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4549 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4550 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4551 "Logical speed:%dMbps Fault:%d\n",
4552 phba->sli4_hba.link_state.speed,
4553 phba->sli4_hba.link_state.topology,
4554 phba->sli4_hba.link_state.status,
4555 phba->sli4_hba.link_state.type,
4556 phba->sli4_hba.link_state.number,
4557 phba->sli4_hba.link_state.logical_speed,
4558 phba->sli4_hba.link_state.fault);
4560 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4561 * topology info. Note: Optional for non FC-AL ports.
4563 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4564 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4565 if (rc == MBX_NOT_FINISHED)
4566 goto out_free_dmabuf;
4570 * For FCoE Mode: fill in all the topology information we need and call
4571 * the READ_TOPOLOGY completion routine to continue without actually
4572 * sending the READ_TOPOLOGY mailbox command to the port.
4574 /* Initialize completion status */
4576 mb->mbxStatus = MBX_SUCCESS;
4578 /* Parse port fault information field */
4579 lpfc_sli4_parse_latt_fault(phba, acqe_link);
4581 /* Parse and translate link attention fields */
4582 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4583 la->eventTag = acqe_link->event_tag;
4584 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4585 bf_set(lpfc_mbx_read_top_link_spd, la,
4586 (bf_get(lpfc_acqe_link_speed, acqe_link)));
4588 /* Fake the the following irrelvant fields */
4589 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4590 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4591 bf_set(lpfc_mbx_read_top_il, la, 0);
4592 bf_set(lpfc_mbx_read_top_pb, la, 0);
4593 bf_set(lpfc_mbx_read_top_fa, la, 0);
4594 bf_set(lpfc_mbx_read_top_mm, la, 0);
4596 /* Invoke the lpfc_handle_latt mailbox command callback function */
4597 lpfc_mbx_cmpl_read_topology(phba, pmb);
4604 mempool_free(pmb, phba->mbox_mem_pool);
4608 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4609 * @phba: pointer to lpfc hba data structure.
4610 * @acqe_fc: pointer to the async fc completion queue entry.
4612 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4613 * that the event was received and then issue a read_topology mailbox command so
4614 * that the rest of the driver will treat it the same as SLI3.
4617 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4619 struct lpfc_dmabuf *mp;
4622 struct lpfc_mbx_read_top *la;
4625 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4626 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4627 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4628 "2895 Non FC link Event detected.(%d)\n",
4629 bf_get(lpfc_trailer_type, acqe_fc));
4632 /* Keep the link status for extra SLI4 state machine reference */
4633 phba->sli4_hba.link_state.speed =
4634 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4635 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4636 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4637 phba->sli4_hba.link_state.topology =
4638 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4639 phba->sli4_hba.link_state.status =
4640 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4641 phba->sli4_hba.link_state.type =
4642 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4643 phba->sli4_hba.link_state.number =
4644 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4645 phba->sli4_hba.link_state.fault =
4646 bf_get(lpfc_acqe_link_fault, acqe_fc);
4647 phba->sli4_hba.link_state.logical_speed =
4648 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
4649 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4650 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4651 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4652 "%dMbps Fault:%d\n",
4653 phba->sli4_hba.link_state.speed,
4654 phba->sli4_hba.link_state.topology,
4655 phba->sli4_hba.link_state.status,
4656 phba->sli4_hba.link_state.type,
4657 phba->sli4_hba.link_state.number,
4658 phba->sli4_hba.link_state.logical_speed,
4659 phba->sli4_hba.link_state.fault);
4660 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4662 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4663 "2897 The mboxq allocation failed\n");
4666 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4669 "2898 The lpfc_dmabuf allocation failed\n");
4672 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4674 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4675 "2899 The mbuf allocation failed\n");
4676 goto out_free_dmabuf;
4679 /* Cleanup any outstanding ELS commands */
4680 lpfc_els_flush_all_cmd(phba);
4682 /* Block ELS IOCBs until we have done process link event */
4683 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4685 /* Update link event statistics */
4686 phba->sli.slistat.link_event++;
4688 /* Create lpfc_handle_latt mailbox command from link ACQE */
4689 lpfc_read_topology(phba, pmb, mp);
4690 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4691 pmb->vport = phba->pport;
4693 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4694 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4696 switch (phba->sli4_hba.link_state.status) {
4697 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4698 phba->link_flag |= LS_MDS_LINK_DOWN;
4700 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4701 phba->link_flag |= LS_MDS_LOOPBACK;
4707 /* Initialize completion status */
4709 mb->mbxStatus = MBX_SUCCESS;
4711 /* Parse port fault information field */
4712 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
4714 /* Parse and translate link attention fields */
4715 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4716 la->eventTag = acqe_fc->event_tag;
4718 if (phba->sli4_hba.link_state.status ==
4719 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4720 bf_set(lpfc_mbx_read_top_att_type, la,
4721 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4723 bf_set(lpfc_mbx_read_top_att_type, la,
4724 LPFC_FC_LA_TYPE_LINK_DOWN);
4726 /* Invoke the mailbox command callback function */
4727 lpfc_mbx_cmpl_read_topology(phba, pmb);
4732 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4733 if (rc == MBX_NOT_FINISHED)
4734 goto out_free_dmabuf;
4740 mempool_free(pmb, phba->mbox_mem_pool);
4744 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4745 * @phba: pointer to lpfc hba data structure.
4746 * @acqe_fc: pointer to the async SLI completion queue entry.
4748 * This routine is to handle the SLI4 asynchronous SLI events.
4751 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4757 uint8_t operational = 0;
4758 struct temp_event temp_event_data;
4759 struct lpfc_acqe_misconfigured_event *misconfigured;
4760 struct Scsi_Host *shost;
4762 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4764 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4765 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4766 "x%08x SLI Event Type:%d\n",
4767 acqe_sli->event_data1, acqe_sli->event_data2,
4770 port_name = phba->Port[0];
4771 if (port_name == 0x00)
4772 port_name = '?'; /* get port name is empty */
4775 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4776 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4777 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4778 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4780 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4781 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4782 acqe_sli->event_data1, port_name);
4784 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
4785 shost = lpfc_shost_from_vport(phba->pport);
4786 fc_host_post_vendor_event(shost, fc_get_event_number(),
4787 sizeof(temp_event_data),
4788 (char *)&temp_event_data,
4789 SCSI_NL_VID_TYPE_PCI
4790 | PCI_VENDOR_ID_EMULEX);
4792 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4793 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4794 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4795 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4797 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4798 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4799 acqe_sli->event_data1, port_name);
4801 shost = lpfc_shost_from_vport(phba->pport);
4802 fc_host_post_vendor_event(shost, fc_get_event_number(),
4803 sizeof(temp_event_data),
4804 (char *)&temp_event_data,
4805 SCSI_NL_VID_TYPE_PCI
4806 | PCI_VENDOR_ID_EMULEX);
4808 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4809 misconfigured = (struct lpfc_acqe_misconfigured_event *)
4810 &acqe_sli->event_data1;
4812 /* fetch the status for this port */
4813 switch (phba->sli4_hba.lnk_info.lnk_no) {
4814 case LPFC_LINK_NUMBER_0:
4815 status = bf_get(lpfc_sli_misconfigured_port0_state,
4816 &misconfigured->theEvent);
4817 operational = bf_get(lpfc_sli_misconfigured_port0_op,
4818 &misconfigured->theEvent);
4820 case LPFC_LINK_NUMBER_1:
4821 status = bf_get(lpfc_sli_misconfigured_port1_state,
4822 &misconfigured->theEvent);
4823 operational = bf_get(lpfc_sli_misconfigured_port1_op,
4824 &misconfigured->theEvent);
4826 case LPFC_LINK_NUMBER_2:
4827 status = bf_get(lpfc_sli_misconfigured_port2_state,
4828 &misconfigured->theEvent);
4829 operational = bf_get(lpfc_sli_misconfigured_port2_op,
4830 &misconfigured->theEvent);
4832 case LPFC_LINK_NUMBER_3:
4833 status = bf_get(lpfc_sli_misconfigured_port3_state,
4834 &misconfigured->theEvent);
4835 operational = bf_get(lpfc_sli_misconfigured_port3_op,
4836 &misconfigured->theEvent);
4839 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4841 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4842 "event: Invalid link %d",
4843 phba->sli4_hba.lnk_info.lnk_no);
4847 /* Skip if optic state unchanged */
4848 if (phba->sli4_hba.lnk_info.optic_state == status)
4852 case LPFC_SLI_EVENT_STATUS_VALID:
4853 sprintf(message, "Physical Link is functional");
4855 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4856 sprintf(message, "Optics faulted/incorrectly "
4857 "installed/not installed - Reseat optics, "
4858 "if issue not resolved, replace.");
4860 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4862 "Optics of two types installed - Remove one "
4863 "optic or install matching pair of optics.");
4865 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4866 sprintf(message, "Incompatible optics - Replace with "
4867 "compatible optics for card to function.");
4869 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4870 sprintf(message, "Unqualified optics - Replace with "
4871 "Avago optics for Warranty and Technical "
4872 "Support - Link is%s operational",
4873 (operational) ? " not" : "");
4875 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4876 sprintf(message, "Uncertified optics - Replace with "
4877 "Avago-certified optics to enable link "
4878 "operation - Link is%s operational",
4879 (operational) ? " not" : "");
4882 /* firmware is reporting a status we don't know about */
4883 sprintf(message, "Unknown event status x%02x", status);
4886 phba->sli4_hba.lnk_info.optic_state = status;
4887 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4888 "3176 Port Name %c %s\n", port_name, message);
4890 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4891 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4892 "3192 Remote DPort Test Initiated - "
4893 "Event Data1:x%08x Event Data2: x%08x\n",
4894 acqe_sli->event_data1, acqe_sli->event_data2);
4897 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4898 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4899 "x%08x SLI Event Type:%d\n",
4900 acqe_sli->event_data1, acqe_sli->event_data2,
4907 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4908 * @vport: pointer to vport data structure.
4910 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4911 * response to a CVL event.
4913 * Return the pointer to the ndlp with the vport if successful, otherwise
4916 static struct lpfc_nodelist *
4917 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4919 struct lpfc_nodelist *ndlp;
4920 struct Scsi_Host *shost;
4921 struct lpfc_hba *phba;
4928 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4930 /* Cannot find existing Fabric ndlp, so allocate a new one */
4931 ndlp = lpfc_nlp_init(vport, Fabric_DID);
4934 /* Set the node type */
4935 ndlp->nlp_type |= NLP_FABRIC;
4936 /* Put ndlp onto node list */
4937 lpfc_enqueue_node(vport, ndlp);
4938 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4939 /* re-setup ndlp without removing from node list */
4940 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4944 if ((phba->pport->port_state < LPFC_FLOGI) &&
4945 (phba->pport->port_state != LPFC_VPORT_FAILED))
4947 /* If virtual link is not yet instantiated ignore CVL */
4948 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4949 && (vport->port_state != LPFC_VPORT_FAILED))
4951 shost = lpfc_shost_from_vport(vport);
4954 lpfc_linkdown_port(vport);
4955 lpfc_cleanup_pending_mbox(vport);
4956 spin_lock_irq(shost->host_lock);
4957 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4958 spin_unlock_irq(shost->host_lock);
4964 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4965 * @vport: pointer to lpfc hba data structure.
4967 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4968 * response to a FCF dead event.
4971 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4973 struct lpfc_vport **vports;
4976 vports = lpfc_create_vport_work_array(phba);
4978 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4979 lpfc_sli4_perform_vport_cvl(vports[i]);
4980 lpfc_destroy_vport_work_array(phba, vports);
4984 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4985 * @phba: pointer to lpfc hba data structure.
4986 * @acqe_link: pointer to the async fcoe completion queue entry.
4988 * This routine is to handle the SLI4 asynchronous fcoe event.
4991 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4992 struct lpfc_acqe_fip *acqe_fip)
4994 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
4996 struct lpfc_vport *vport;
4997 struct lpfc_nodelist *ndlp;
4998 struct Scsi_Host *shost;
4999 int active_vlink_present;
5000 struct lpfc_vport **vports;
5003 phba->fc_eventTag = acqe_fip->event_tag;
5004 phba->fcoe_eventtag = acqe_fip->event_tag;
5005 switch (event_type) {
5006 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5007 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5008 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
5009 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5011 "2546 New FCF event, evt_tag:x%x, "
5013 acqe_fip->event_tag,
5016 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5018 "2788 FCF param modified event, "
5019 "evt_tag:x%x, index:x%x\n",
5020 acqe_fip->event_tag,
5022 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5024 * During period of FCF discovery, read the FCF
5025 * table record indexed by the event to update
5026 * FCF roundrobin failover eligible FCF bmask.
5028 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5030 "2779 Read FCF (x%x) for updating "
5031 "roundrobin FCF failover bmask\n",
5033 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
5036 /* If the FCF discovery is in progress, do nothing. */
5037 spin_lock_irq(&phba->hbalock);
5038 if (phba->hba_flag & FCF_TS_INPROG) {
5039 spin_unlock_irq(&phba->hbalock);
5042 /* If fast FCF failover rescan event is pending, do nothing */
5043 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
5044 spin_unlock_irq(&phba->hbalock);
5048 /* If the FCF has been in discovered state, do nothing. */
5049 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
5050 spin_unlock_irq(&phba->hbalock);
5053 spin_unlock_irq(&phba->hbalock);
5055 /* Otherwise, scan the entire FCF table and re-discover SAN */
5056 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5057 "2770 Start FCF table scan per async FCF "
5058 "event, evt_tag:x%x, index:x%x\n",
5059 acqe_fip->event_tag, acqe_fip->index);
5060 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5061 LPFC_FCOE_FCF_GET_FIRST);
5063 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5064 "2547 Issue FCF scan read FCF mailbox "
5065 "command failed (x%x)\n", rc);
5068 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
5069 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5070 "2548 FCF Table full count 0x%x tag 0x%x\n",
5071 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5072 acqe_fip->event_tag);
5075 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
5076 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5077 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5078 "2549 FCF (x%x) disconnected from network, "
5079 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
5081 * If we are in the middle of FCF failover process, clear
5082 * the corresponding FCF bit in the roundrobin bitmap.
5084 spin_lock_irq(&phba->hbalock);
5085 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5086 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
5087 spin_unlock_irq(&phba->hbalock);
5088 /* Update FLOGI FCF failover eligible FCF bmask */
5089 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
5092 spin_unlock_irq(&phba->hbalock);
5094 /* If the event is not for currently used fcf do nothing */
5095 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
5099 * Otherwise, request the port to rediscover the entire FCF
5100 * table for a fast recovery from case that the current FCF
5101 * is no longer valid as we are not in the middle of FCF
5102 * failover process already.
5104 spin_lock_irq(&phba->hbalock);
5105 /* Mark the fast failover process in progress */
5106 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5107 spin_unlock_irq(&phba->hbalock);
5109 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5110 "2771 Start FCF fast failover process due to "
5111 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5112 "\n", acqe_fip->event_tag, acqe_fip->index);
5113 rc = lpfc_sli4_redisc_fcf_table(phba);
5115 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5117 "2772 Issue FCF rediscover mailbox "
5118 "command failed, fail through to FCF "
5120 spin_lock_irq(&phba->hbalock);
5121 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5122 spin_unlock_irq(&phba->hbalock);
5124 * Last resort will fail over by treating this
5125 * as a link down to FCF registration.
5127 lpfc_sli4_fcf_dead_failthrough(phba);
5129 /* Reset FCF roundrobin bmask for new discovery */
5130 lpfc_sli4_clear_fcf_rr_bmask(phba);
5132 * Handling fast FCF failover to a DEAD FCF event is
5133 * considered equalivant to receiving CVL to all vports.
5135 lpfc_sli4_perform_all_vport_cvl(phba);
5138 case LPFC_FIP_EVENT_TYPE_CVL:
5139 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5140 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5141 "2718 Clear Virtual Link Received for VPI 0x%x"
5142 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
5144 vport = lpfc_find_vport_by_vpid(phba,
5146 ndlp = lpfc_sli4_perform_vport_cvl(vport);
5149 active_vlink_present = 0;
5151 vports = lpfc_create_vport_work_array(phba);
5153 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5155 if ((!(vports[i]->fc_flag &
5156 FC_VPORT_CVL_RCVD)) &&
5157 (vports[i]->port_state > LPFC_FDISC)) {
5158 active_vlink_present = 1;
5162 lpfc_destroy_vport_work_array(phba, vports);
5166 * Don't re-instantiate if vport is marked for deletion.
5167 * If we are here first then vport_delete is going to wait
5168 * for discovery to complete.
5170 if (!(vport->load_flag & FC_UNLOADING) &&
5171 active_vlink_present) {
5173 * If there are other active VLinks present,
5174 * re-instantiate the Vlink using FDISC.
5176 mod_timer(&ndlp->nlp_delayfunc,
5177 jiffies + msecs_to_jiffies(1000));
5178 shost = lpfc_shost_from_vport(vport);
5179 spin_lock_irq(shost->host_lock);
5180 ndlp->nlp_flag |= NLP_DELAY_TMO;
5181 spin_unlock_irq(shost->host_lock);
5182 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5183 vport->port_state = LPFC_FDISC;
5186 * Otherwise, we request port to rediscover
5187 * the entire FCF table for a fast recovery
5188 * from possible case that the current FCF
5189 * is no longer valid if we are not already
5190 * in the FCF failover process.
5192 spin_lock_irq(&phba->hbalock);
5193 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5194 spin_unlock_irq(&phba->hbalock);
5197 /* Mark the fast failover process in progress */
5198 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
5199 spin_unlock_irq(&phba->hbalock);
5200 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5202 "2773 Start FCF failover per CVL, "
5203 "evt_tag:x%x\n", acqe_fip->event_tag);
5204 rc = lpfc_sli4_redisc_fcf_table(phba);
5206 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5208 "2774 Issue FCF rediscover "
5209 "mailbox command failed, "
5210 "through to CVL event\n");
5211 spin_lock_irq(&phba->hbalock);
5212 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
5213 spin_unlock_irq(&phba->hbalock);
5215 * Last resort will be re-try on the
5216 * the current registered FCF entry.
5218 lpfc_retry_pport_discovery(phba);
5221 * Reset FCF roundrobin bmask for new
5224 lpfc_sli4_clear_fcf_rr_bmask(phba);
5228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5229 "0288 Unknown FCoE event type 0x%x event tag "
5230 "0x%x\n", event_type, acqe_fip->event_tag);
5236 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5237 * @phba: pointer to lpfc hba data structure.
5238 * @acqe_link: pointer to the async dcbx completion queue entry.
5240 * This routine is to handle the SLI4 asynchronous dcbx event.
5243 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5244 struct lpfc_acqe_dcbx *acqe_dcbx)
5246 phba->fc_eventTag = acqe_dcbx->event_tag;
5247 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5248 "0290 The SLI4 DCBX asynchronous event is not "
5253 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5254 * @phba: pointer to lpfc hba data structure.
5255 * @acqe_link: pointer to the async grp5 completion queue entry.
5257 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5258 * is an asynchronous notified of a logical link speed change. The Port
5259 * reports the logical link speed in units of 10Mbps.
5262 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5263 struct lpfc_acqe_grp5 *acqe_grp5)
5265 uint16_t prev_ll_spd;
5267 phba->fc_eventTag = acqe_grp5->event_tag;
5268 phba->fcoe_eventtag = acqe_grp5->event_tag;
5269 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5270 phba->sli4_hba.link_state.logical_speed =
5271 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
5272 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5273 "2789 GRP5 Async Event: Updating logical link speed "
5274 "from %dMbps to %dMbps\n", prev_ll_spd,
5275 phba->sli4_hba.link_state.logical_speed);
5279 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5280 * @phba: pointer to lpfc hba data structure.
5282 * This routine is invoked by the worker thread to process all the pending
5283 * SLI4 asynchronous events.
5285 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5287 struct lpfc_cq_event *cq_event;
5289 /* First, declare the async event has been handled */
5290 spin_lock_irq(&phba->hbalock);
5291 phba->hba_flag &= ~ASYNC_EVENT;
5292 spin_unlock_irq(&phba->hbalock);
5293 /* Now, handle all the async events */
5294 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5295 /* Get the first event from the head of the event queue */
5296 spin_lock_irq(&phba->hbalock);
5297 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5298 cq_event, struct lpfc_cq_event, list);
5299 spin_unlock_irq(&phba->hbalock);
5300 /* Process the asynchronous event */
5301 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5302 case LPFC_TRAILER_CODE_LINK:
5303 lpfc_sli4_async_link_evt(phba,
5304 &cq_event->cqe.acqe_link);
5306 case LPFC_TRAILER_CODE_FCOE:
5307 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
5309 case LPFC_TRAILER_CODE_DCBX:
5310 lpfc_sli4_async_dcbx_evt(phba,
5311 &cq_event->cqe.acqe_dcbx);
5313 case LPFC_TRAILER_CODE_GRP5:
5314 lpfc_sli4_async_grp5_evt(phba,
5315 &cq_event->cqe.acqe_grp5);
5317 case LPFC_TRAILER_CODE_FC:
5318 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5320 case LPFC_TRAILER_CODE_SLI:
5321 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5324 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5325 "1804 Invalid asynchrous event code: "
5326 "x%x\n", bf_get(lpfc_trailer_code,
5327 &cq_event->cqe.mcqe_cmpl));
5330 /* Free the completion event processed to the free pool */
5331 lpfc_sli4_cq_event_release(phba, cq_event);
5336 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5337 * @phba: pointer to lpfc hba data structure.
5339 * This routine is invoked by the worker thread to process FCF table
5340 * rediscovery pending completion event.
5342 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5346 spin_lock_irq(&phba->hbalock);
5347 /* Clear FCF rediscovery timeout event */
5348 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5349 /* Clear driver fast failover FCF record flag */
5350 phba->fcf.failover_rec.flag = 0;
5351 /* Set state for FCF fast failover */
5352 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5353 spin_unlock_irq(&phba->hbalock);
5355 /* Scan FCF table from the first entry to re-discover SAN */
5356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5357 "2777 Start post-quiescent FCF table scan\n");
5358 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5360 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5361 "2747 Issue FCF scan read FCF mailbox "
5362 "command failed 0x%x\n", rc);
5366 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5367 * @phba: pointer to lpfc hba data structure.
5368 * @dev_grp: The HBA PCI-Device group number.
5370 * This routine is invoked to set up the per HBA PCI-Device group function
5371 * API jump table entries.
5373 * Return: 0 if success, otherwise -ENODEV
5376 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5380 /* Set up lpfc PCI-device group */
5381 phba->pci_dev_grp = dev_grp;
5383 /* The LPFC_PCI_DEV_OC uses SLI4 */
5384 if (dev_grp == LPFC_PCI_DEV_OC)
5385 phba->sli_rev = LPFC_SLI_REV4;
5387 /* Set up device INIT API function jump table */
5388 rc = lpfc_init_api_table_setup(phba, dev_grp);
5391 /* Set up SCSI API function jump table */
5392 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5395 /* Set up SLI API function jump table */
5396 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5399 /* Set up MBOX API function jump table */
5400 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5408 * lpfc_log_intr_mode - Log the active interrupt mode
5409 * @phba: pointer to lpfc hba data structure.
5410 * @intr_mode: active interrupt mode adopted.
5412 * This routine it invoked to log the currently used active interrupt mode
5415 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
5417 switch (intr_mode) {
5419 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5420 "0470 Enable INTx interrupt mode.\n");
5423 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5424 "0481 Enabled MSI interrupt mode.\n");
5427 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5428 "0480 Enabled MSI-X interrupt mode.\n");
5431 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5432 "0482 Illegal interrupt mode.\n");
5439 * lpfc_enable_pci_dev - Enable a generic PCI device.
5440 * @phba: pointer to lpfc hba data structure.
5442 * This routine is invoked to enable the PCI device that is common to all
5447 * other values - error
5450 lpfc_enable_pci_dev(struct lpfc_hba *phba)
5452 struct pci_dev *pdev;
5454 /* Obtain PCI device reference */
5458 pdev = phba->pcidev;
5459 /* Enable PCI device */
5460 if (pci_enable_device_mem(pdev))
5462 /* Request PCI resource for the device */
5463 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
5464 goto out_disable_device;
5465 /* Set up device as PCI master and save state for EEH */
5466 pci_set_master(pdev);
5467 pci_try_set_mwi(pdev);
5468 pci_save_state(pdev);
5470 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5471 if (pci_is_pcie(pdev))
5472 pdev->needs_freset = 1;
5477 pci_disable_device(pdev);
5479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5480 "1401 Failed to enable pci device\n");
5485 * lpfc_disable_pci_dev - Disable a generic PCI device.
5486 * @phba: pointer to lpfc hba data structure.
5488 * This routine is invoked to disable the PCI device that is common to all
5492 lpfc_disable_pci_dev(struct lpfc_hba *phba)
5494 struct pci_dev *pdev;
5496 /* Obtain PCI device reference */
5500 pdev = phba->pcidev;
5501 /* Release PCI resource and disable PCI device */
5502 pci_release_mem_regions(pdev);
5503 pci_disable_device(pdev);
5509 * lpfc_reset_hba - Reset a hba
5510 * @phba: pointer to lpfc hba data structure.
5512 * This routine is invoked to reset a hba device. It brings the HBA
5513 * offline, performs a board restart, and then brings the board back
5514 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5515 * on outstanding mailbox commands.
5518 lpfc_reset_hba(struct lpfc_hba *phba)
5520 /* If resets are disabled then set error state and return. */
5521 if (!phba->cfg_enable_hba_reset) {
5522 phba->link_state = LPFC_HBA_ERROR;
5525 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5526 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5528 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
5530 lpfc_sli_brdrestart(phba);
5532 lpfc_unblock_mgmt_io(phba);
5536 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5537 * @phba: pointer to lpfc hba data structure.
5539 * This function enables the PCI SR-IOV virtual functions to a physical
5540 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5541 * enable the number of virtual functions to the physical function. As
5542 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5543 * API call does not considered as an error condition for most of the device.
5546 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5548 struct pci_dev *pdev = phba->pcidev;
5552 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5556 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5561 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5562 * @phba: pointer to lpfc hba data structure.
5563 * @nr_vfn: number of virtual functions to be enabled.
5565 * This function enables the PCI SR-IOV virtual functions to a physical
5566 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5567 * enable the number of virtual functions to the physical function. As
5568 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5569 * API call does not considered as an error condition for most of the device.
5572 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5574 struct pci_dev *pdev = phba->pcidev;
5575 uint16_t max_nr_vfn;
5578 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5579 if (nr_vfn > max_nr_vfn) {
5580 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5581 "3057 Requested vfs (%d) greater than "
5582 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5586 rc = pci_enable_sriov(pdev, nr_vfn);
5588 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5589 "2806 Failed to enable sriov on this device "
5590 "with vfn number nr_vf:%d, rc:%d\n",
5593 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5594 "2807 Successful enable sriov on this device "
5595 "with vfn number nr_vf:%d\n", nr_vfn);
5600 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5601 * @phba: pointer to lpfc hba data structure.
5603 * This routine is invoked to set up the driver internal resources before the
5604 * device specific resource setup to support the HBA device it attached to.
5608 * other values - error
5611 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5613 struct lpfc_sli *psli = &phba->sli;
5616 * Driver resources common to all SLI revisions
5618 atomic_set(&phba->fast_event_count, 0);
5619 spin_lock_init(&phba->hbalock);
5621 /* Initialize ndlp management spinlock */
5622 spin_lock_init(&phba->ndlp_lock);
5624 INIT_LIST_HEAD(&phba->port_list);
5625 INIT_LIST_HEAD(&phba->work_list);
5626 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5628 /* Initialize the wait queue head for the kernel thread */
5629 init_waitqueue_head(&phba->work_waitq);
5631 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5632 "1403 Protocols supported %s %s %s\n",
5633 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5635 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5637 (phba->nvmet_support ? "NVMET" : " "));
5639 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5640 /* Initialize the scsi buffer list used by driver for scsi IO */
5641 spin_lock_init(&phba->scsi_buf_list_get_lock);
5642 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5643 spin_lock_init(&phba->scsi_buf_list_put_lock);
5644 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5647 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5648 (phba->nvmet_support == 0)) {
5649 /* Initialize the NVME buffer list used by driver for NVME IO */
5650 spin_lock_init(&phba->nvme_buf_list_get_lock);
5651 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5652 phba->get_nvme_bufs = 0;
5653 spin_lock_init(&phba->nvme_buf_list_put_lock);
5654 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5655 phba->put_nvme_bufs = 0;
5658 /* Initialize the fabric iocb list */
5659 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5661 /* Initialize list to save ELS buffers */
5662 INIT_LIST_HEAD(&phba->elsbuf);
5664 /* Initialize FCF connection rec list */
5665 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5667 /* Initialize OAS configuration list */
5668 spin_lock_init(&phba->devicelock);
5669 INIT_LIST_HEAD(&phba->luns);
5671 /* MBOX heartbeat timer */
5672 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
5673 /* Fabric block timer */
5674 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
5675 /* EA polling mode timer */
5676 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
5677 /* Heartbeat timer */
5678 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
5684 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5685 * @phba: pointer to lpfc hba data structure.
5687 * This routine is invoked to set up the driver internal resources specific to
5688 * support the SLI-3 HBA device it attached to.
5692 * other values - error
5695 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5700 * Initialize timers used by driver
5703 /* FCP polling mode timer */
5704 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
5706 /* Host attention work mask setup */
5707 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5708 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5710 /* Get all the module params for configuring this host */
5711 lpfc_get_cfgparam(phba);
5712 /* Set up phase-1 common device driver resources */
5714 rc = lpfc_setup_driver_resource_phase1(phba);
5718 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5719 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5720 /* check for menlo minimum sg count */
5721 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5722 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5725 if (!phba->sli.sli3_ring)
5726 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
5727 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5728 if (!phba->sli.sli3_ring)
5732 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5733 * used to create the sg_dma_buf_pool must be dynamically calculated.
5736 /* Initialize the host templates the configured values. */
5737 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5738 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5739 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5741 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5742 if (phba->cfg_enable_bg) {
5744 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5745 * the FCP rsp, and a BDE for each. Sice we have no control
5746 * over how many protection data segments the SCSI Layer
5747 * will hand us (ie: there could be one for every block
5748 * in the IO), we just allocate enough BDEs to accomidate
5749 * our max amount and we need to limit lpfc_sg_seg_cnt to
5750 * minimize the risk of running out.
5752 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5753 sizeof(struct fcp_rsp) +
5754 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5756 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5757 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5759 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5760 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5763 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5764 * the FCP rsp, a BDE for each, and a BDE for up to
5765 * cfg_sg_seg_cnt data segments.
5767 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5768 sizeof(struct fcp_rsp) +
5769 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5771 /* Total BDEs in BPL for scsi_sg_list */
5772 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5775 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5776 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5777 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5778 phba->cfg_total_seg_cnt);
5780 phba->max_vpi = LPFC_MAX_VPI;
5781 /* This will be set to correct value after config_port mbox */
5782 phba->max_vports = 0;
5785 * Initialize the SLI Layer to run with lpfc HBAs.
5787 lpfc_sli_setup(phba);
5788 lpfc_sli_queue_init(phba);
5790 /* Allocate device driver memory */
5791 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5795 * Enable sr-iov virtual functions if supported and configured
5796 * through the module parameter.
5798 if (phba->cfg_sriov_nr_virtfn > 0) {
5799 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5800 phba->cfg_sriov_nr_virtfn);
5802 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5803 "2808 Requested number of SR-IOV "
5804 "virtual functions (%d) is not "
5806 phba->cfg_sriov_nr_virtfn);
5807 phba->cfg_sriov_nr_virtfn = 0;
5815 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5816 * @phba: pointer to lpfc hba data structure.
5818 * This routine is invoked to unset the driver internal resources set up
5819 * specific for supporting the SLI-3 HBA device it attached to.
5822 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5824 /* Free device driver memory allocated */
5825 lpfc_mem_free_all(phba);
5831 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5832 * @phba: pointer to lpfc hba data structure.
5834 * This routine is invoked to set up the driver internal resources specific to
5835 * support the SLI-4 HBA device it attached to.
5839 * other values - error
5842 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5844 LPFC_MBOXQ_t *mboxq;
5846 int rc, i, max_buf_size;
5847 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5848 struct lpfc_mqe *mqe;
5850 int fof_vectors = 0;
5856 phba->sli4_hba.num_online_cpu = num_online_cpus();
5857 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5858 phba->sli4_hba.curr_disp_cpu = 0;
5860 /* Get all the module params for configuring this host */
5861 lpfc_get_cfgparam(phba);
5863 /* Set up phase-1 common device driver resources */
5864 rc = lpfc_setup_driver_resource_phase1(phba);
5868 /* Before proceed, wait for POST done and device ready */
5869 rc = lpfc_sli4_post_status_check(phba);
5874 * Initialize timers used by driver
5877 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
5879 /* FCF rediscover timer */
5880 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
5883 * Control structure for handling external multi-buffer mailbox
5884 * command pass-through.
5886 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5887 sizeof(struct lpfc_mbox_ext_buf_ctx));
5888 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5890 phba->max_vpi = LPFC_MAX_VPI;
5892 /* This will be set to correct value after the read_config mbox */
5893 phba->max_vports = 0;
5895 /* Program the default value of vlan_id and fc_map */
5896 phba->valid_vlan = 0;
5897 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5898 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5899 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5902 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5903 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5904 * The WQ create will allocate the ring.
5908 * 1 for cmd, 1 for rsp, NVME adds an extra one
5909 * for boundary conditions in its max_sgl_segment template.
5912 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5916 * It doesn't matter what family our adapter is in, we are
5917 * limited to 2 Pages, 512 SGEs, for our SGL.
5918 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5920 max_buf_size = (2 * SLI4_PAGE_SIZE);
5921 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra)
5922 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra;
5925 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5926 * used to create the sg_dma_buf_pool must be calculated.
5928 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5930 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5931 * the FCP rsp, and a SGE. Sice we have no control
5932 * over how many protection segments the SCSI Layer
5933 * will hand us (ie: there could be one for every block
5934 * in the IO), just allocate enough SGEs to accomidate
5935 * our max amount and we need to limit lpfc_sg_seg_cnt
5936 * to minimize the risk of running out.
5938 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5939 sizeof(struct fcp_rsp) + max_buf_size;
5941 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5942 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5944 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5945 phba->cfg_sg_seg_cnt =
5946 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5949 * The scsi_buf for a regular I/O holds the FCP cmnd,
5950 * the FCP rsp, a SGE for each, and a SGE for up to
5951 * cfg_sg_seg_cnt data segments.
5953 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5954 sizeof(struct fcp_rsp) +
5955 ((phba->cfg_sg_seg_cnt + extra) *
5956 sizeof(struct sli4_sge));
5958 /* Total SGEs for scsi_sg_list */
5959 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
5962 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
5963 * need to post 1 page for the SGL.
5967 /* Initialize the host templates with the updated values. */
5968 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5969 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5970 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5972 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5973 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5975 phba->cfg_sg_dma_buf_size =
5976 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5978 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5979 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5980 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5981 phba->cfg_total_seg_cnt);
5983 /* Initialize buffer queue management fields */
5984 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
5985 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5986 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5989 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5991 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5992 /* Initialize the Abort scsi buffer list used by driver */
5993 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5994 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5997 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5998 /* Initialize the Abort nvme buffer list used by driver */
5999 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
6000 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
6001 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6002 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
6005 /* This abort list used by worker thread */
6006 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
6007 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
6010 * Initialize driver internal slow-path work queues
6013 /* Driver internel slow-path CQ Event pool */
6014 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6015 /* Response IOCB work queue list */
6016 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
6017 /* Asynchronous event CQ Event work queue list */
6018 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6019 /* Fast-path XRI aborted CQ Event work queue list */
6020 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6021 /* Slow-path XRI aborted CQ Event work queue list */
6022 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6023 /* Receive queue CQ Event work queue list */
6024 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6026 /* Initialize extent block lists. */
6027 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6028 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6029 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6030 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6032 /* Initialize mboxq lists. If the early init routines fail
6033 * these lists need to be correctly initialized.
6035 INIT_LIST_HEAD(&phba->sli.mboxq);
6036 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6038 /* initialize optic_state to 0xFF */
6039 phba->sli4_hba.lnk_info.optic_state = 0xff;
6041 /* Allocate device driver memory */
6042 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6046 /* IF Type 2 ports get initialized now. */
6047 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
6048 LPFC_SLI_INTF_IF_TYPE_2) {
6049 rc = lpfc_pci_function_reset(phba);
6054 phba->temp_sensor_support = 1;
6057 /* Create the bootstrap mailbox command */
6058 rc = lpfc_create_bootstrap_mbox(phba);
6062 /* Set up the host's endian order with the device. */
6063 rc = lpfc_setup_endian_order(phba);
6065 goto out_free_bsmbx;
6067 /* Set up the hba's configuration parameters. */
6068 rc = lpfc_sli4_read_config(phba);
6070 goto out_free_bsmbx;
6071 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6073 goto out_free_bsmbx;
6075 /* IF Type 0 ports get initialized now. */
6076 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6077 LPFC_SLI_INTF_IF_TYPE_0) {
6078 rc = lpfc_pci_function_reset(phba);
6080 goto out_free_bsmbx;
6083 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6087 goto out_free_bsmbx;
6090 /* Check for NVMET being configured */
6091 phba->nvmet_support = 0;
6092 if (lpfc_enable_nvmet_cnt) {
6094 /* First get WWN of HBA instance */
6095 lpfc_read_nv(phba, mboxq);
6096 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6097 if (rc != MBX_SUCCESS) {
6098 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6099 "6016 Mailbox failed , mbxCmd x%x "
6100 "READ_NV, mbxStatus x%x\n",
6101 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6102 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
6103 mempool_free(mboxq, phba->mbox_mem_pool);
6105 goto out_free_bsmbx;
6108 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6110 wwn = cpu_to_be64(wwn);
6111 phba->sli4_hba.wwnn.u.name = wwn;
6112 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6114 /* wwn is WWPN of HBA instance */
6115 wwn = cpu_to_be64(wwn);
6116 phba->sli4_hba.wwpn.u.name = wwn;
6118 /* Check to see if it matches any module parameter */
6119 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6120 if (wwn == lpfc_enable_nvmet[i]) {
6121 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
6122 if (lpfc_nvmet_mem_alloc(phba))
6125 phba->nvmet_support = 1; /* a match */
6127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6128 "6017 NVME Target %016llx\n",
6131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6132 "6021 Can't enable NVME Target."
6133 " NVME_TARGET_FC infrastructure"
6134 " is not in kernel\n");
6141 lpfc_nvme_mod_param_dep(phba);
6143 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
6144 lpfc_supported_pages(mboxq);
6145 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6147 mqe = &mboxq->u.mqe;
6148 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6149 LPFC_MAX_SUPPORTED_PAGES);
6150 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6151 switch (pn_page[i]) {
6152 case LPFC_SLI4_PARAMETERS:
6153 phba->sli4_hba.pc_sli4_params.supported = 1;
6159 /* Read the port's SLI4 Parameters capabilities if supported. */
6160 if (phba->sli4_hba.pc_sli4_params.supported)
6161 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6163 mempool_free(mboxq, phba->mbox_mem_pool);
6165 goto out_free_bsmbx;
6170 * Get sli4 parameters that override parameters from Port capabilities.
6171 * If this call fails, it isn't critical unless the SLI4 parameters come
6174 rc = lpfc_get_sli4_parameters(phba, mboxq);
6176 if_type = bf_get(lpfc_sli_intf_if_type,
6177 &phba->sli4_hba.sli_intf);
6178 if_fam = bf_get(lpfc_sli_intf_sli_family,
6179 &phba->sli4_hba.sli_intf);
6180 if (phba->sli4_hba.extents_in_use &&
6181 phba->sli4_hba.rpi_hdrs_in_use) {
6182 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6183 "2999 Unsupported SLI4 Parameters "
6184 "Extents and RPI headers enabled.\n");
6185 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6186 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6187 mempool_free(mboxq, phba->mbox_mem_pool);
6189 goto out_free_bsmbx;
6192 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6193 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6194 mempool_free(mboxq, phba->mbox_mem_pool);
6196 goto out_free_bsmbx;
6200 mempool_free(mboxq, phba->mbox_mem_pool);
6202 /* Verify OAS is supported */
6203 lpfc_sli4_oas_verify(phba);
6207 /* Verify all the SLI4 queues */
6208 rc = lpfc_sli4_queue_verify(phba);
6210 goto out_free_bsmbx;
6212 /* Create driver internal CQE event pool */
6213 rc = lpfc_sli4_cq_event_pool_create(phba);
6215 goto out_free_bsmbx;
6217 /* Initialize sgl lists per host */
6218 lpfc_init_sgl_list(phba);
6220 /* Allocate and initialize active sgl array */
6221 rc = lpfc_init_active_sgl_array(phba);
6223 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6224 "1430 Failed to initialize sgl list.\n");
6225 goto out_destroy_cq_event_pool;
6227 rc = lpfc_sli4_init_rpi_hdrs(phba);
6229 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6230 "1432 Failed to initialize rpi headers.\n");
6231 goto out_free_active_sgl;
6234 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
6235 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6236 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
6238 if (!phba->fcf.fcf_rr_bmask) {
6239 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6240 "2759 Failed allocate memory for FCF round "
6241 "robin failover bmask\n");
6243 goto out_remove_rpi_hdrs;
6246 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6247 sizeof(struct lpfc_hba_eq_hdl),
6249 if (!phba->sli4_hba.hba_eq_hdl) {
6250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6251 "2572 Failed allocate memory for "
6252 "fast-path per-EQ handle array\n");
6254 goto out_free_fcf_rr_bmask;
6257 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6258 sizeof(struct lpfc_vector_map_info),
6260 if (!phba->sli4_hba.cpu_map) {
6261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6262 "3327 Failed allocate memory for msi-x "
6263 "interrupt vector mapping\n");
6265 goto out_free_hba_eq_hdl;
6267 if (lpfc_used_cpu == NULL) {
6268 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6270 if (!lpfc_used_cpu) {
6271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6272 "3335 Failed allocate memory for msi-x "
6273 "interrupt vector mapping\n");
6274 kfree(phba->sli4_hba.cpu_map);
6276 goto out_free_hba_eq_hdl;
6278 for (i = 0; i < lpfc_present_cpu; i++)
6279 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6283 * Enable sr-iov virtual functions if supported and configured
6284 * through the module parameter.
6286 if (phba->cfg_sriov_nr_virtfn > 0) {
6287 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6288 phba->cfg_sriov_nr_virtfn);
6290 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6291 "3020 Requested number of SR-IOV "
6292 "virtual functions (%d) is not "
6294 phba->cfg_sriov_nr_virtfn);
6295 phba->cfg_sriov_nr_virtfn = 0;
6301 out_free_hba_eq_hdl:
6302 kfree(phba->sli4_hba.hba_eq_hdl);
6303 out_free_fcf_rr_bmask:
6304 kfree(phba->fcf.fcf_rr_bmask);
6305 out_remove_rpi_hdrs:
6306 lpfc_sli4_remove_rpi_hdrs(phba);
6307 out_free_active_sgl:
6308 lpfc_free_active_sgl(phba);
6309 out_destroy_cq_event_pool:
6310 lpfc_sli4_cq_event_pool_destroy(phba);
6312 lpfc_destroy_bootstrap_mbox(phba);
6314 lpfc_mem_free(phba);
6319 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6320 * @phba: pointer to lpfc hba data structure.
6322 * This routine is invoked to unset the driver internal resources set up
6323 * specific for supporting the SLI-4 HBA device it attached to.
6326 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6328 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6330 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6331 kfree(phba->sli4_hba.cpu_map);
6332 phba->sli4_hba.num_present_cpu = 0;
6333 phba->sli4_hba.num_online_cpu = 0;
6334 phba->sli4_hba.curr_disp_cpu = 0;
6336 /* Free memory allocated for fast-path work queue handles */
6337 kfree(phba->sli4_hba.hba_eq_hdl);
6339 /* Free the allocated rpi headers. */
6340 lpfc_sli4_remove_rpi_hdrs(phba);
6341 lpfc_sli4_remove_rpis(phba);
6343 /* Free eligible FCF index bmask */
6344 kfree(phba->fcf.fcf_rr_bmask);
6346 /* Free the ELS sgl list */
6347 lpfc_free_active_sgl(phba);
6348 lpfc_free_els_sgl_list(phba);
6349 lpfc_free_nvmet_sgl_list(phba);
6351 /* Free the completion queue EQ event pool */
6352 lpfc_sli4_cq_event_release_all(phba);
6353 lpfc_sli4_cq_event_pool_destroy(phba);
6355 /* Release resource identifiers. */
6356 lpfc_sli4_dealloc_resource_identifiers(phba);
6358 /* Free the bsmbx region. */
6359 lpfc_destroy_bootstrap_mbox(phba);
6361 /* Free the SLI Layer memory with SLI4 HBAs */
6362 lpfc_mem_free_all(phba);
6364 /* Free the current connect table */
6365 list_for_each_entry_safe(conn_entry, next_conn_entry,
6366 &phba->fcf_conn_rec_list, list) {
6367 list_del_init(&conn_entry->list);
6375 * lpfc_init_api_table_setup - Set up init api function jump table
6376 * @phba: The hba struct for which this call is being executed.
6377 * @dev_grp: The HBA PCI-Device group number.
6379 * This routine sets up the device INIT interface API function jump table
6382 * Returns: 0 - success, -ENODEV - failure.
6385 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6387 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6388 phba->lpfc_hba_down_link = lpfc_hba_down_link;
6389 phba->lpfc_selective_reset = lpfc_selective_reset;
6391 case LPFC_PCI_DEV_LP:
6392 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6393 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6394 phba->lpfc_stop_port = lpfc_stop_port_s3;
6396 case LPFC_PCI_DEV_OC:
6397 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6398 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6399 phba->lpfc_stop_port = lpfc_stop_port_s4;
6402 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6403 "1431 Invalid HBA PCI-device group: 0x%x\n",
6412 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6413 * @phba: pointer to lpfc hba data structure.
6415 * This routine is invoked to set up the driver internal resources after the
6416 * device specific resource setup to support the HBA device it attached to.
6420 * other values - error
6423 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6427 /* Startup the kernel thread for this host adapter. */
6428 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6429 "lpfc_worker_%d", phba->brd_no);
6430 if (IS_ERR(phba->worker_thread)) {
6431 error = PTR_ERR(phba->worker_thread);
6435 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6436 if (phba->sli_rev == LPFC_SLI_REV4)
6437 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6445 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6446 * @phba: pointer to lpfc hba data structure.
6448 * This routine is invoked to unset the driver internal resources set up after
6449 * the device specific resource setup for supporting the HBA device it
6453 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6456 flush_workqueue(phba->wq);
6457 destroy_workqueue(phba->wq);
6461 /* Stop kernel worker thread */
6462 if (phba->worker_thread)
6463 kthread_stop(phba->worker_thread);
6467 * lpfc_free_iocb_list - Free iocb list.
6468 * @phba: pointer to lpfc hba data structure.
6470 * This routine is invoked to free the driver's IOCB list and memory.
6473 lpfc_free_iocb_list(struct lpfc_hba *phba)
6475 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6477 spin_lock_irq(&phba->hbalock);
6478 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6479 &phba->lpfc_iocb_list, list) {
6480 list_del(&iocbq_entry->list);
6482 phba->total_iocbq_bufs--;
6484 spin_unlock_irq(&phba->hbalock);
6490 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6491 * @phba: pointer to lpfc hba data structure.
6493 * This routine is invoked to allocate and initizlize the driver's IOCB
6494 * list and set up the IOCB tag array accordingly.
6498 * other values - error
6501 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6503 struct lpfc_iocbq *iocbq_entry = NULL;
6507 /* Initialize and populate the iocb list per host. */
6508 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
6509 for (i = 0; i < iocb_count; i++) {
6510 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
6511 if (iocbq_entry == NULL) {
6512 printk(KERN_ERR "%s: only allocated %d iocbs of "
6513 "expected %d count. Unloading driver.\n",
6514 __func__, i, LPFC_IOCB_LIST_CNT);
6515 goto out_free_iocbq;
6518 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6521 printk(KERN_ERR "%s: failed to allocate IOTAG. "
6522 "Unloading driver.\n", __func__);
6523 goto out_free_iocbq;
6525 iocbq_entry->sli4_lxritag = NO_XRI;
6526 iocbq_entry->sli4_xritag = NO_XRI;
6528 spin_lock_irq(&phba->hbalock);
6529 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6530 phba->total_iocbq_bufs++;
6531 spin_unlock_irq(&phba->hbalock);
6537 lpfc_free_iocb_list(phba);
6543 * lpfc_free_sgl_list - Free a given sgl list.
6544 * @phba: pointer to lpfc hba data structure.
6545 * @sglq_list: pointer to the head of sgl list.
6547 * This routine is invoked to free a give sgl list and memory.
6550 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
6552 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6554 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6555 list_del(&sglq_entry->list);
6556 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6562 * lpfc_free_els_sgl_list - Free els sgl list.
6563 * @phba: pointer to lpfc hba data structure.
6565 * This routine is invoked to free the driver's els sgl list and memory.
6568 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6570 LIST_HEAD(sglq_list);
6572 /* Retrieve all els sgls from driver list */
6573 spin_lock_irq(&phba->hbalock);
6574 spin_lock(&phba->sli4_hba.sgl_list_lock);
6575 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6576 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6577 spin_unlock_irq(&phba->hbalock);
6579 /* Now free the sgl list */
6580 lpfc_free_sgl_list(phba, &sglq_list);
6584 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6585 * @phba: pointer to lpfc hba data structure.
6587 * This routine is invoked to free the driver's nvmet sgl list and memory.
6590 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6592 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6593 LIST_HEAD(sglq_list);
6595 /* Retrieve all nvmet sgls from driver list */
6596 spin_lock_irq(&phba->hbalock);
6597 spin_lock(&phba->sli4_hba.sgl_list_lock);
6598 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6599 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6600 spin_unlock_irq(&phba->hbalock);
6602 /* Now free the sgl list */
6603 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6604 list_del(&sglq_entry->list);
6605 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6609 /* Update the nvmet_xri_cnt to reflect no current sgls.
6610 * The next initialization cycle sets the count and allocates
6611 * the sgls over again.
6613 phba->sli4_hba.nvmet_xri_cnt = 0;
6617 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6618 * @phba: pointer to lpfc hba data structure.
6620 * This routine is invoked to allocate the driver's active sgl memory.
6621 * This array will hold the sglq_entry's for active IOs.
6624 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6627 size = sizeof(struct lpfc_sglq *);
6628 size *= phba->sli4_hba.max_cfg_param.max_xri;
6630 phba->sli4_hba.lpfc_sglq_active_list =
6631 kzalloc(size, GFP_KERNEL);
6632 if (!phba->sli4_hba.lpfc_sglq_active_list)
6638 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6639 * @phba: pointer to lpfc hba data structure.
6641 * This routine is invoked to walk through the array of active sglq entries
6642 * and free all of the resources.
6643 * This is just a place holder for now.
6646 lpfc_free_active_sgl(struct lpfc_hba *phba)
6648 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6652 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6653 * @phba: pointer to lpfc hba data structure.
6655 * This routine is invoked to allocate and initizlize the driver's sgl
6656 * list and set up the sgl xritag tag array accordingly.
6660 lpfc_init_sgl_list(struct lpfc_hba *phba)
6662 /* Initialize and populate the sglq list per host/VF. */
6663 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
6664 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6665 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6666 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6668 /* els xri-sgl book keeping */
6669 phba->sli4_hba.els_xri_cnt = 0;
6671 /* scsi xri-buffer book keeping */
6672 phba->sli4_hba.scsi_xri_cnt = 0;
6674 /* nvme xri-buffer book keeping */
6675 phba->sli4_hba.nvme_xri_cnt = 0;
6679 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6680 * @phba: pointer to lpfc hba data structure.
6682 * This routine is invoked to post rpi header templates to the
6683 * port for those SLI4 ports that do not support extents. This routine
6684 * posts a PAGE_SIZE memory region to the port to hold up to
6685 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6686 * and should be called only when interrupts are disabled.
6690 * -ERROR - otherwise.
6693 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6696 struct lpfc_rpi_hdr *rpi_hdr;
6698 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
6699 if (!phba->sli4_hba.rpi_hdrs_in_use)
6701 if (phba->sli4_hba.extents_in_use)
6704 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6706 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6707 "0391 Error during rpi post operation\n");
6708 lpfc_sli4_remove_rpis(phba);
6716 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6717 * @phba: pointer to lpfc hba data structure.
6719 * This routine is invoked to allocate a single 4KB memory region to
6720 * support rpis and stores them in the phba. This single region
6721 * provides support for up to 64 rpis. The region is used globally
6725 * A valid rpi hdr on success.
6726 * A NULL pointer on any failure.
6728 struct lpfc_rpi_hdr *
6729 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6731 uint16_t rpi_limit, curr_rpi_range;
6732 struct lpfc_dmabuf *dmabuf;
6733 struct lpfc_rpi_hdr *rpi_hdr;
6736 * If the SLI4 port supports extents, posting the rpi header isn't
6737 * required. Set the expected maximum count and let the actual value
6738 * get set when extents are fully allocated.
6740 if (!phba->sli4_hba.rpi_hdrs_in_use)
6742 if (phba->sli4_hba.extents_in_use)
6745 /* The limit on the logical index is just the max_rpi count. */
6746 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
6748 spin_lock_irq(&phba->hbalock);
6750 * Establish the starting RPI in this header block. The starting
6751 * rpi is normalized to a zero base because the physical rpi is
6754 curr_rpi_range = phba->sli4_hba.next_rpi;
6755 spin_unlock_irq(&phba->hbalock);
6757 /* Reached full RPI range */
6758 if (curr_rpi_range == rpi_limit)
6762 * First allocate the protocol header region for the port. The
6763 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6765 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6769 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6770 LPFC_HDR_TEMPLATE_SIZE,
6771 &dmabuf->phys, GFP_KERNEL);
6772 if (!dmabuf->virt) {
6774 goto err_free_dmabuf;
6777 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6779 goto err_free_coherent;
6782 /* Save the rpi header data for cleanup later. */
6783 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6785 goto err_free_coherent;
6787 rpi_hdr->dmabuf = dmabuf;
6788 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6789 rpi_hdr->page_count = 1;
6790 spin_lock_irq(&phba->hbalock);
6792 /* The rpi_hdr stores the logical index only. */
6793 rpi_hdr->start_rpi = curr_rpi_range;
6794 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
6795 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6797 spin_unlock_irq(&phba->hbalock);
6801 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6802 dmabuf->virt, dmabuf->phys);
6809 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6810 * @phba: pointer to lpfc hba data structure.
6812 * This routine is invoked to remove all memory resources allocated
6813 * to support rpis for SLI4 ports not supporting extents. This routine
6814 * presumes the caller has released all rpis consumed by fabric or port
6815 * logins and is prepared to have the header pages removed.
6818 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6820 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6822 if (!phba->sli4_hba.rpi_hdrs_in_use)
6825 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6826 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6827 list_del(&rpi_hdr->list);
6828 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6829 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6830 kfree(rpi_hdr->dmabuf);
6834 /* There are no rpis available to the port now. */
6835 phba->sli4_hba.next_rpi = 0;
6839 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6840 * @pdev: pointer to pci device data structure.
6842 * This routine is invoked to allocate the driver hba data structure for an
6843 * HBA device. If the allocation is successful, the phba reference to the
6844 * PCI device data structure is set.
6847 * pointer to @phba - successful
6850 static struct lpfc_hba *
6851 lpfc_hba_alloc(struct pci_dev *pdev)
6853 struct lpfc_hba *phba;
6855 /* Allocate memory for HBA structure */
6856 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6858 dev_err(&pdev->dev, "failed to allocate hba struct\n");
6862 /* Set reference to PCI device in HBA structure */
6863 phba->pcidev = pdev;
6865 /* Assign an unused board number */
6866 phba->brd_no = lpfc_get_instance();
6867 if (phba->brd_no < 0) {
6871 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
6873 spin_lock_init(&phba->ct_ev_lock);
6874 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6880 * lpfc_hba_free - Free driver hba data structure with a device.
6881 * @phba: pointer to lpfc hba data structure.
6883 * This routine is invoked to free the driver hba data structure with an
6887 lpfc_hba_free(struct lpfc_hba *phba)
6889 /* Release the driver assigned board number */
6890 idr_remove(&lpfc_hba_index, phba->brd_no);
6892 /* Free memory allocated with sli3 rings */
6893 kfree(phba->sli.sli3_ring);
6894 phba->sli.sli3_ring = NULL;
6901 * lpfc_create_shost - Create hba physical port with associated scsi host.
6902 * @phba: pointer to lpfc hba data structure.
6904 * This routine is invoked to create HBA physical port and associate a SCSI
6909 * other values - error
6912 lpfc_create_shost(struct lpfc_hba *phba)
6914 struct lpfc_vport *vport;
6915 struct Scsi_Host *shost;
6917 /* Initialize HBA FC structure */
6918 phba->fc_edtov = FF_DEF_EDTOV;
6919 phba->fc_ratov = FF_DEF_RATOV;
6920 phba->fc_altov = FF_DEF_ALTOV;
6921 phba->fc_arbtov = FF_DEF_ARBTOV;
6923 atomic_set(&phba->sdev_cnt, 0);
6924 atomic_set(&phba->fc4ScsiInputRequests, 0);
6925 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6926 atomic_set(&phba->fc4ScsiControlRequests, 0);
6927 atomic_set(&phba->fc4ScsiIoCmpls, 0);
6928 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
6932 shost = lpfc_shost_from_vport(vport);
6933 phba->pport = vport;
6935 if (phba->nvmet_support) {
6936 /* Only 1 vport (pport) will support NVME target */
6937 if (phba->txrdy_payload_pool == NULL) {
6938 phba->txrdy_payload_pool = dma_pool_create(
6939 "txrdy_pool", &phba->pcidev->dev,
6940 TXRDY_PAYLOAD_LEN, 16, 0);
6941 if (phba->txrdy_payload_pool) {
6942 phba->targetport = NULL;
6943 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6944 lpfc_printf_log(phba, KERN_INFO,
6945 LOG_INIT | LOG_NVME_DISC,
6946 "6076 NVME Target Found\n");
6951 lpfc_debugfs_initialize(vport);
6952 /* Put reference to SCSI host to driver's device private data */
6953 pci_set_drvdata(phba->pcidev, shost);
6956 * At this point we are fully registered with PSA. In addition,
6957 * any initial discovery should be completed.
6959 vport->load_flag |= FC_ALLOW_FDMI;
6960 if (phba->cfg_enable_SmartSAN ||
6961 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
6963 /* Setup appropriate attribute masks */
6964 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
6965 if (phba->cfg_enable_SmartSAN)
6966 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6968 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6974 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6975 * @phba: pointer to lpfc hba data structure.
6977 * This routine is invoked to destroy HBA physical port and the associated
6981 lpfc_destroy_shost(struct lpfc_hba *phba)
6983 struct lpfc_vport *vport = phba->pport;
6985 /* Destroy physical port that associated with the SCSI host */
6986 destroy_port(vport);
6992 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6993 * @phba: pointer to lpfc hba data structure.
6994 * @shost: the shost to be used to detect Block guard settings.
6996 * This routine sets up the local Block guard protocol settings for @shost.
6997 * This routine also allocates memory for debugging bg buffers.
7000 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7006 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7007 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7008 "1478 Registering BlockGuard with the "
7011 old_mask = phba->cfg_prot_mask;
7012 old_guard = phba->cfg_prot_guard;
7014 /* Only allow supported values */
7015 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
7016 SHOST_DIX_TYPE0_PROTECTION |
7017 SHOST_DIX_TYPE1_PROTECTION);
7018 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7019 SHOST_DIX_GUARD_CRC);
7021 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
7022 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7023 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
7025 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7026 if ((old_mask != phba->cfg_prot_mask) ||
7027 (old_guard != phba->cfg_prot_guard))
7028 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7029 "1475 Registering BlockGuard with the "
7030 "SCSI layer: mask %d guard %d\n",
7031 phba->cfg_prot_mask,
7032 phba->cfg_prot_guard);
7034 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7035 scsi_host_set_guard(shost, phba->cfg_prot_guard);
7037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7038 "1479 Not Registering BlockGuard with the SCSI "
7039 "layer, Bad protection parameters: %d %d\n",
7040 old_mask, old_guard);
7043 if (!_dump_buf_data) {
7045 spin_lock_init(&_dump_buf_lock);
7047 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7048 if (_dump_buf_data) {
7049 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7050 "9043 BLKGRD: allocated %d pages for "
7051 "_dump_buf_data at 0x%p\n",
7052 (1 << pagecnt), _dump_buf_data);
7053 _dump_buf_data_order = pagecnt;
7054 memset(_dump_buf_data, 0,
7055 ((1 << PAGE_SHIFT) << pagecnt));
7060 if (!_dump_buf_data_order)
7061 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7062 "9044 BLKGRD: ERROR unable to allocate "
7063 "memory for hexdump\n");
7065 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7066 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
7067 "\n", _dump_buf_data);
7068 if (!_dump_buf_dif) {
7071 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7072 if (_dump_buf_dif) {
7073 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7074 "9046 BLKGRD: allocated %d pages for "
7075 "_dump_buf_dif at 0x%p\n",
7076 (1 << pagecnt), _dump_buf_dif);
7077 _dump_buf_dif_order = pagecnt;
7078 memset(_dump_buf_dif, 0,
7079 ((1 << PAGE_SHIFT) << pagecnt));
7084 if (!_dump_buf_dif_order)
7085 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7086 "9047 BLKGRD: ERROR unable to allocate "
7087 "memory for hexdump\n");
7089 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7090 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
7095 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7096 * @phba: pointer to lpfc hba data structure.
7098 * This routine is invoked to perform all the necessary post initialization
7099 * setup for the device.
7102 lpfc_post_init_setup(struct lpfc_hba *phba)
7104 struct Scsi_Host *shost;
7105 struct lpfc_adapter_event_header adapter_event;
7107 /* Get the default values for Model Name and Description */
7108 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7111 * hba setup may have changed the hba_queue_depth so we need to
7112 * adjust the value of can_queue.
7114 shost = pci_get_drvdata(phba->pcidev);
7115 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7116 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7117 lpfc_setup_bg(phba, shost);
7119 lpfc_host_attrib_init(shost);
7121 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7122 spin_lock_irq(shost->host_lock);
7123 lpfc_poll_start_timer(phba);
7124 spin_unlock_irq(shost->host_lock);
7127 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7128 "0428 Perform SCSI scan\n");
7129 /* Send board arrival event to upper layer */
7130 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7131 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7132 fc_host_post_vendor_event(shost, fc_get_event_number(),
7133 sizeof(adapter_event),
7134 (char *) &adapter_event,
7140 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7141 * @phba: pointer to lpfc hba data structure.
7143 * This routine is invoked to set up the PCI device memory space for device
7144 * with SLI-3 interface spec.
7148 * other values - error
7151 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7153 struct pci_dev *pdev;
7154 unsigned long bar0map_len, bar2map_len;
7157 int error = -ENODEV;
7159 /* Obtain PCI device reference */
7163 pdev = phba->pcidev;
7165 /* Set the device DMA mask size */
7166 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7167 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7168 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7169 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
7174 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7175 * required by each mapping.
7177 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7178 bar0map_len = pci_resource_len(pdev, 0);
7180 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7181 bar2map_len = pci_resource_len(pdev, 2);
7183 /* Map HBA SLIM to a kernel virtual address. */
7184 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7185 if (!phba->slim_memmap_p) {
7186 dev_printk(KERN_ERR, &pdev->dev,
7187 "ioremap failed for SLIM memory.\n");
7191 /* Map HBA Control Registers to a kernel virtual address. */
7192 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7193 if (!phba->ctrl_regs_memmap_p) {
7194 dev_printk(KERN_ERR, &pdev->dev,
7195 "ioremap failed for HBA control registers.\n");
7196 goto out_iounmap_slim;
7199 /* Allocate memory for SLI-2 structures */
7200 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7201 &phba->slim2p.phys, GFP_KERNEL);
7202 if (!phba->slim2p.virt)
7205 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
7206 phba->mbox_ext = (phba->slim2p.virt +
7207 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
7208 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7209 phba->IOCBs = (phba->slim2p.virt +
7210 offsetof(struct lpfc_sli2_slim, IOCBs));
7212 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7213 lpfc_sli_hbq_size(),
7214 &phba->hbqslimp.phys,
7216 if (!phba->hbqslimp.virt)
7219 hbq_count = lpfc_sli_hbq_count();
7220 ptr = phba->hbqslimp.virt;
7221 for (i = 0; i < hbq_count; ++i) {
7222 phba->hbqs[i].hbq_virt = ptr;
7223 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7224 ptr += (lpfc_hbq_defs[i]->entry_count *
7225 sizeof(struct lpfc_hbq_entry));
7227 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7228 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7230 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7232 phba->MBslimaddr = phba->slim_memmap_p;
7233 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7234 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7235 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7236 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
7241 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7242 phba->slim2p.virt, phba->slim2p.phys);
7244 iounmap(phba->ctrl_regs_memmap_p);
7246 iounmap(phba->slim_memmap_p);
7252 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7253 * @phba: pointer to lpfc hba data structure.
7255 * This routine is invoked to unset the PCI device memory space for device
7256 * with SLI-3 interface spec.
7259 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7261 struct pci_dev *pdev;
7263 /* Obtain PCI device reference */
7267 pdev = phba->pcidev;
7269 /* Free coherent DMA memory allocated */
7270 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7271 phba->hbqslimp.virt, phba->hbqslimp.phys);
7272 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7273 phba->slim2p.virt, phba->slim2p.phys);
7275 /* I/O memory unmap */
7276 iounmap(phba->ctrl_regs_memmap_p);
7277 iounmap(phba->slim_memmap_p);
7283 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7284 * @phba: pointer to lpfc hba data structure.
7286 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7287 * done and check status.
7289 * Return 0 if successful, otherwise -ENODEV.
7292 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7294 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7295 struct lpfc_register reg_data;
7296 int i, port_error = 0;
7299 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7300 memset(®_data, 0, sizeof(reg_data));
7301 if (!phba->sli4_hba.PSMPHRregaddr)
7304 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7305 for (i = 0; i < 3000; i++) {
7306 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7307 &portsmphr_reg.word0) ||
7308 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
7309 /* Port has a fatal POST error, break out */
7310 port_error = -ENODEV;
7313 if (LPFC_POST_STAGE_PORT_READY ==
7314 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
7320 * If there was a port error during POST, then don't proceed with
7321 * other register reads as the data may not be valid. Just exit.
7324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7325 "1408 Port Failed POST - portsmphr=0x%x, "
7326 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7327 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7328 portsmphr_reg.word0,
7329 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7330 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7331 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7332 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7333 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7334 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7335 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7336 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7338 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7339 "2534 Device Info: SLIFamily=0x%x, "
7340 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7341 "SLIHint_2=0x%x, FT=0x%x\n",
7342 bf_get(lpfc_sli_intf_sli_family,
7343 &phba->sli4_hba.sli_intf),
7344 bf_get(lpfc_sli_intf_slirev,
7345 &phba->sli4_hba.sli_intf),
7346 bf_get(lpfc_sli_intf_if_type,
7347 &phba->sli4_hba.sli_intf),
7348 bf_get(lpfc_sli_intf_sli_hint1,
7349 &phba->sli4_hba.sli_intf),
7350 bf_get(lpfc_sli_intf_sli_hint2,
7351 &phba->sli4_hba.sli_intf),
7352 bf_get(lpfc_sli_intf_func_type,
7353 &phba->sli4_hba.sli_intf));
7355 * Check for other Port errors during the initialization
7356 * process. Fail the load if the port did not come up
7359 if_type = bf_get(lpfc_sli_intf_if_type,
7360 &phba->sli4_hba.sli_intf);
7362 case LPFC_SLI_INTF_IF_TYPE_0:
7363 phba->sli4_hba.ue_mask_lo =
7364 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7365 phba->sli4_hba.ue_mask_hi =
7366 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7368 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7370 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7371 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7372 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7374 "1422 Unrecoverable Error "
7375 "Detected during POST "
7376 "uerr_lo_reg=0x%x, "
7377 "uerr_hi_reg=0x%x, "
7378 "ue_mask_lo_reg=0x%x, "
7379 "ue_mask_hi_reg=0x%x\n",
7382 phba->sli4_hba.ue_mask_lo,
7383 phba->sli4_hba.ue_mask_hi);
7384 port_error = -ENODEV;
7387 case LPFC_SLI_INTF_IF_TYPE_2:
7388 case LPFC_SLI_INTF_IF_TYPE_6:
7389 /* Final checks. The port status should be clean. */
7390 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7392 (bf_get(lpfc_sliport_status_err, ®_data) &&
7393 !bf_get(lpfc_sliport_status_rn, ®_data))) {
7394 phba->work_status[0] =
7395 readl(phba->sli4_hba.u.if_type2.
7397 phba->work_status[1] =
7398 readl(phba->sli4_hba.u.if_type2.
7400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7401 "2888 Unrecoverable port error "
7402 "following POST: port status reg "
7403 "0x%x, port_smphr reg 0x%x, "
7404 "error 1=0x%x, error 2=0x%x\n",
7406 portsmphr_reg.word0,
7407 phba->work_status[0],
7408 phba->work_status[1]);
7409 port_error = -ENODEV;
7412 case LPFC_SLI_INTF_IF_TYPE_1:
7421 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7422 * @phba: pointer to lpfc hba data structure.
7423 * @if_type: The SLI4 interface type getting configured.
7425 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7429 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7432 case LPFC_SLI_INTF_IF_TYPE_0:
7433 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7434 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7435 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7436 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7437 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7438 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7439 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7440 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7441 phba->sli4_hba.SLIINTFregaddr =
7442 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7444 case LPFC_SLI_INTF_IF_TYPE_2:
7445 phba->sli4_hba.u.if_type2.EQDregaddr =
7446 phba->sli4_hba.conf_regs_memmap_p +
7447 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7448 phba->sli4_hba.u.if_type2.ERR1regaddr =
7449 phba->sli4_hba.conf_regs_memmap_p +
7450 LPFC_CTL_PORT_ER1_OFFSET;
7451 phba->sli4_hba.u.if_type2.ERR2regaddr =
7452 phba->sli4_hba.conf_regs_memmap_p +
7453 LPFC_CTL_PORT_ER2_OFFSET;
7454 phba->sli4_hba.u.if_type2.CTRLregaddr =
7455 phba->sli4_hba.conf_regs_memmap_p +
7456 LPFC_CTL_PORT_CTL_OFFSET;
7457 phba->sli4_hba.u.if_type2.STATUSregaddr =
7458 phba->sli4_hba.conf_regs_memmap_p +
7459 LPFC_CTL_PORT_STA_OFFSET;
7460 phba->sli4_hba.SLIINTFregaddr =
7461 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7462 phba->sli4_hba.PSMPHRregaddr =
7463 phba->sli4_hba.conf_regs_memmap_p +
7464 LPFC_CTL_PORT_SEM_OFFSET;
7465 phba->sli4_hba.RQDBregaddr =
7466 phba->sli4_hba.conf_regs_memmap_p +
7467 LPFC_ULP0_RQ_DOORBELL;
7468 phba->sli4_hba.WQDBregaddr =
7469 phba->sli4_hba.conf_regs_memmap_p +
7470 LPFC_ULP0_WQ_DOORBELL;
7471 phba->sli4_hba.CQDBregaddr =
7472 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7473 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
7474 phba->sli4_hba.MQDBregaddr =
7475 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7476 phba->sli4_hba.BMBXregaddr =
7477 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7479 case LPFC_SLI_INTF_IF_TYPE_6:
7480 phba->sli4_hba.u.if_type2.EQDregaddr =
7481 phba->sli4_hba.conf_regs_memmap_p +
7482 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7483 phba->sli4_hba.u.if_type2.ERR1regaddr =
7484 phba->sli4_hba.conf_regs_memmap_p +
7485 LPFC_CTL_PORT_ER1_OFFSET;
7486 phba->sli4_hba.u.if_type2.ERR2regaddr =
7487 phba->sli4_hba.conf_regs_memmap_p +
7488 LPFC_CTL_PORT_ER2_OFFSET;
7489 phba->sli4_hba.u.if_type2.CTRLregaddr =
7490 phba->sli4_hba.conf_regs_memmap_p +
7491 LPFC_CTL_PORT_CTL_OFFSET;
7492 phba->sli4_hba.u.if_type2.STATUSregaddr =
7493 phba->sli4_hba.conf_regs_memmap_p +
7494 LPFC_CTL_PORT_STA_OFFSET;
7495 phba->sli4_hba.PSMPHRregaddr =
7496 phba->sli4_hba.conf_regs_memmap_p +
7497 LPFC_CTL_PORT_SEM_OFFSET;
7498 phba->sli4_hba.BMBXregaddr =
7499 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7501 case LPFC_SLI_INTF_IF_TYPE_1:
7503 dev_printk(KERN_ERR, &phba->pcidev->dev,
7504 "FATAL - unsupported SLI4 interface type - %d\n",
7511 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7512 * @phba: pointer to lpfc hba data structure.
7514 * This routine is invoked to set up SLI4 BAR1 register memory map.
7517 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7520 case LPFC_SLI_INTF_IF_TYPE_0:
7521 phba->sli4_hba.PSMPHRregaddr =
7522 phba->sli4_hba.ctrl_regs_memmap_p +
7523 LPFC_SLIPORT_IF0_SMPHR;
7524 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7526 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7528 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7531 case LPFC_SLI_INTF_IF_TYPE_6:
7532 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7533 LPFC_IF6_RQ_DOORBELL;
7534 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7535 LPFC_IF6_WQ_DOORBELL;
7536 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7537 LPFC_IF6_CQ_DOORBELL;
7538 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7539 LPFC_IF6_EQ_DOORBELL;
7540 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7541 LPFC_IF6_MQ_DOORBELL;
7543 case LPFC_SLI_INTF_IF_TYPE_2:
7544 case LPFC_SLI_INTF_IF_TYPE_1:
7546 dev_err(&phba->pcidev->dev,
7547 "FATAL - unsupported SLI4 interface type - %d\n",
7554 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7555 * @phba: pointer to lpfc hba data structure.
7556 * @vf: virtual function number
7558 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7559 * based on the given viftual function number, @vf.
7561 * Return 0 if successful, otherwise -ENODEV.
7564 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7566 if (vf > LPFC_VIR_FUNC_MAX)
7569 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7570 vf * LPFC_VFR_PAGE_SIZE +
7571 LPFC_ULP0_RQ_DOORBELL);
7572 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7573 vf * LPFC_VFR_PAGE_SIZE +
7574 LPFC_ULP0_WQ_DOORBELL);
7575 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7576 vf * LPFC_VFR_PAGE_SIZE +
7577 LPFC_EQCQ_DOORBELL);
7578 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
7579 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7580 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7581 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7582 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7587 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7588 * @phba: pointer to lpfc hba data structure.
7590 * This routine is invoked to create the bootstrap mailbox
7591 * region consistent with the SLI-4 interface spec. This
7592 * routine allocates all memory necessary to communicate
7593 * mailbox commands to the port and sets up all alignment
7594 * needs. No locks are expected to be held when calling
7599 * -ENOMEM - could not allocated memory.
7602 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7605 struct lpfc_dmabuf *dmabuf;
7606 struct dma_address *dma_address;
7610 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7615 * The bootstrap mailbox region is comprised of 2 parts
7616 * plus an alignment restriction of 16 bytes.
7618 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
7619 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7620 &dmabuf->phys, GFP_KERNEL);
7621 if (!dmabuf->virt) {
7627 * Initialize the bootstrap mailbox pointers now so that the register
7628 * operations are simple later. The mailbox dma address is required
7629 * to be 16-byte aligned. Also align the virtual memory as each
7630 * maibox is copied into the bmbx mailbox region before issuing the
7631 * command to the port.
7633 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7634 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7636 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7637 LPFC_ALIGN_16_BYTE);
7638 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7639 LPFC_ALIGN_16_BYTE);
7642 * Set the high and low physical addresses now. The SLI4 alignment
7643 * requirement is 16 bytes and the mailbox is posted to the port
7644 * as two 30-bit addresses. The other data is a bit marking whether
7645 * the 30-bit address is the high or low address.
7646 * Upcast bmbx aphys to 64bits so shift instruction compiles
7647 * clean on 32 bit machines.
7649 dma_address = &phba->sli4_hba.bmbx.dma_address;
7650 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7651 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7652 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7653 LPFC_BMBX_BIT1_ADDR_HI);
7655 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7656 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7657 LPFC_BMBX_BIT1_ADDR_LO);
7662 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7663 * @phba: pointer to lpfc hba data structure.
7665 * This routine is invoked to teardown the bootstrap mailbox
7666 * region and release all host resources. This routine requires
7667 * the caller to ensure all mailbox commands recovered, no
7668 * additional mailbox comands are sent, and interrupts are disabled
7669 * before calling this routine.
7673 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7675 dma_free_coherent(&phba->pcidev->dev,
7676 phba->sli4_hba.bmbx.bmbx_size,
7677 phba->sli4_hba.bmbx.dmabuf->virt,
7678 phba->sli4_hba.bmbx.dmabuf->phys);
7680 kfree(phba->sli4_hba.bmbx.dmabuf);
7681 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7685 * lpfc_sli4_read_config - Get the config parameters.
7686 * @phba: pointer to lpfc hba data structure.
7688 * This routine is invoked to read the configuration parameters from the HBA.
7689 * The configuration parameters are used to set the base and maximum values
7690 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7691 * allocation for the port.
7695 * -ENOMEM - No available memory
7696 * -EIO - The mailbox failed to complete successfully.
7699 lpfc_sli4_read_config(struct lpfc_hba *phba)
7702 struct lpfc_mbx_read_config *rd_config;
7703 union lpfc_sli4_cfg_shdr *shdr;
7704 uint32_t shdr_status, shdr_add_status;
7705 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7706 struct lpfc_rsrc_desc_fcfcoe *desc;
7708 uint16_t forced_link_speed;
7710 int length, i, rc = 0, rc2;
7712 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7714 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7715 "2011 Unable to allocate memory for issuing "
7716 "SLI_CONFIG_SPECIAL mailbox command\n");
7720 lpfc_read_config(phba, pmb);
7722 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7723 if (rc != MBX_SUCCESS) {
7724 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7725 "2012 Mailbox failed , mbxCmd x%x "
7726 "READ_CONFIG, mbxStatus x%x\n",
7727 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7728 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7731 rd_config = &pmb->u.mqe.un.rd_config;
7732 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7733 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7734 phba->sli4_hba.lnk_info.lnk_tp =
7735 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7736 phba->sli4_hba.lnk_info.lnk_no =
7737 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7738 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7739 "3081 lnk_type:%d, lnk_numb:%d\n",
7740 phba->sli4_hba.lnk_info.lnk_tp,
7741 phba->sli4_hba.lnk_info.lnk_no);
7743 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7744 "3082 Mailbox (x%x) returned ldv:x0\n",
7745 bf_get(lpfc_mqe_command, &pmb->u.mqe));
7746 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7747 phba->bbcredit_support = 1;
7748 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7751 phba->sli4_hba.extents_in_use =
7752 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
7753 phba->sli4_hba.max_cfg_param.max_xri =
7754 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7755 phba->sli4_hba.max_cfg_param.xri_base =
7756 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7757 phba->sli4_hba.max_cfg_param.max_vpi =
7758 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7759 phba->sli4_hba.max_cfg_param.vpi_base =
7760 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7761 phba->sli4_hba.max_cfg_param.max_rpi =
7762 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7763 phba->sli4_hba.max_cfg_param.rpi_base =
7764 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7765 phba->sli4_hba.max_cfg_param.max_vfi =
7766 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7767 phba->sli4_hba.max_cfg_param.vfi_base =
7768 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7769 phba->sli4_hba.max_cfg_param.max_fcfi =
7770 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
7771 phba->sli4_hba.max_cfg_param.max_eq =
7772 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7773 phba->sli4_hba.max_cfg_param.max_rq =
7774 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7775 phba->sli4_hba.max_cfg_param.max_wq =
7776 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7777 phba->sli4_hba.max_cfg_param.max_cq =
7778 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7779 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7780 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7781 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7782 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
7783 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7784 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
7785 phba->max_vports = phba->max_vpi;
7786 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7787 "2003 cfg params Extents? %d "
7792 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7793 phba->sli4_hba.extents_in_use,
7794 phba->sli4_hba.max_cfg_param.xri_base,
7795 phba->sli4_hba.max_cfg_param.max_xri,
7796 phba->sli4_hba.max_cfg_param.vpi_base,
7797 phba->sli4_hba.max_cfg_param.max_vpi,
7798 phba->sli4_hba.max_cfg_param.vfi_base,
7799 phba->sli4_hba.max_cfg_param.max_vfi,
7800 phba->sli4_hba.max_cfg_param.rpi_base,
7801 phba->sli4_hba.max_cfg_param.max_rpi,
7802 phba->sli4_hba.max_cfg_param.max_fcfi,
7803 phba->sli4_hba.max_cfg_param.max_eq,
7804 phba->sli4_hba.max_cfg_param.max_cq,
7805 phba->sli4_hba.max_cfg_param.max_wq,
7806 phba->sli4_hba.max_cfg_param.max_rq);
7809 * Calculate NVME queue resources based on how
7810 * many WQ/CQs are available.
7812 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7813 length = phba->sli4_hba.max_cfg_param.max_wq;
7814 if (phba->sli4_hba.max_cfg_param.max_cq <
7815 phba->sli4_hba.max_cfg_param.max_wq)
7816 length = phba->sli4_hba.max_cfg_param.max_cq;
7819 * Whats left after this can go toward NVME.
7820 * The minus 6 accounts for ELS, NVME LS, MBOX
7821 * fof plus a couple extra. When configured for
7822 * NVMET, FCP io channel WQs are not created.
7825 if (!phba->nvmet_support)
7826 length -= phba->cfg_fcp_io_channel;
7828 if (phba->cfg_nvme_io_channel > length) {
7830 phba, KERN_ERR, LOG_SLI,
7831 "2005 Reducing NVME IO channel to %d: "
7832 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
7834 phba->sli4_hba.max_cfg_param.max_wq,
7835 phba->sli4_hba.max_cfg_param.max_cq,
7836 phba->cfg_nvme_io_channel,
7837 phba->cfg_fcp_io_channel);
7839 phba->cfg_nvme_io_channel = length;
7847 /* Update link speed if forced link speed is supported */
7848 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7849 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
7851 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7852 if (forced_link_speed) {
7853 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7855 switch (forced_link_speed) {
7857 phba->cfg_link_speed =
7858 LPFC_USER_LINK_SPEED_1G;
7861 phba->cfg_link_speed =
7862 LPFC_USER_LINK_SPEED_2G;
7865 phba->cfg_link_speed =
7866 LPFC_USER_LINK_SPEED_4G;
7869 phba->cfg_link_speed =
7870 LPFC_USER_LINK_SPEED_8G;
7872 case LINK_SPEED_10G:
7873 phba->cfg_link_speed =
7874 LPFC_USER_LINK_SPEED_10G;
7876 case LINK_SPEED_16G:
7877 phba->cfg_link_speed =
7878 LPFC_USER_LINK_SPEED_16G;
7880 case LINK_SPEED_32G:
7881 phba->cfg_link_speed =
7882 LPFC_USER_LINK_SPEED_32G;
7884 case LINK_SPEED_64G:
7885 phba->cfg_link_speed =
7886 LPFC_USER_LINK_SPEED_64G;
7889 phba->cfg_link_speed =
7890 LPFC_USER_LINK_SPEED_AUTO;
7893 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7894 "0047 Unrecognized link "
7897 phba->cfg_link_speed =
7898 LPFC_USER_LINK_SPEED_AUTO;
7903 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7904 length = phba->sli4_hba.max_cfg_param.max_xri -
7905 lpfc_sli4_get_els_iocb_cnt(phba);
7906 if (phba->cfg_hba_queue_depth > length) {
7907 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7908 "3361 HBA queue depth changed from %d to %d\n",
7909 phba->cfg_hba_queue_depth, length);
7910 phba->cfg_hba_queue_depth = length;
7913 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7914 LPFC_SLI_INTF_IF_TYPE_2)
7917 /* get the pf# and vf# for SLI4 if_type 2 port */
7918 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7919 sizeof(struct lpfc_sli4_cfg_mhdr));
7920 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7921 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7922 length, LPFC_SLI4_MBX_EMBED);
7924 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7925 shdr = (union lpfc_sli4_cfg_shdr *)
7926 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7927 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7928 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7929 if (rc2 || shdr_status || shdr_add_status) {
7930 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7931 "3026 Mailbox failed , mbxCmd x%x "
7932 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7933 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7934 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7938 /* search for fc_fcoe resrouce descriptor */
7939 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
7941 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7942 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7943 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7944 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7945 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7946 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7949 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
7950 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
7951 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
7952 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
7953 phba->sli4_hba.iov.pf_number =
7954 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7955 phba->sli4_hba.iov.vf_number =
7956 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7961 if (i < LPFC_RSRC_DESC_MAX_NUM)
7962 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7963 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7964 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7965 phba->sli4_hba.iov.vf_number);
7967 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7968 "3028 GET_FUNCTION_CONFIG: failed to find "
7969 "Resrouce Descriptor:x%x\n",
7970 LPFC_RSRC_DESC_TYPE_FCFCOE);
7973 mempool_free(pmb, phba->mbox_mem_pool);
7978 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7979 * @phba: pointer to lpfc hba data structure.
7981 * This routine is invoked to setup the port-side endian order when
7982 * the port if_type is 0. This routine has no function for other
7987 * -ENOMEM - No available memory
7988 * -EIO - The mailbox failed to complete successfully.
7991 lpfc_setup_endian_order(struct lpfc_hba *phba)
7993 LPFC_MBOXQ_t *mboxq;
7994 uint32_t if_type, rc = 0;
7995 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7996 HOST_ENDIAN_HIGH_WORD1};
7998 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8000 case LPFC_SLI_INTF_IF_TYPE_0:
8001 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8005 "0492 Unable to allocate memory for "
8006 "issuing SLI_CONFIG_SPECIAL mailbox "
8012 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8013 * two words to contain special data values and no other data.
8015 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8016 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8017 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8018 if (rc != MBX_SUCCESS) {
8019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8020 "0493 SLI_CONFIG_SPECIAL mailbox "
8021 "failed with status x%x\n",
8025 mempool_free(mboxq, phba->mbox_mem_pool);
8027 case LPFC_SLI_INTF_IF_TYPE_6:
8028 case LPFC_SLI_INTF_IF_TYPE_2:
8029 case LPFC_SLI_INTF_IF_TYPE_1:
8037 * lpfc_sli4_queue_verify - Verify and update EQ counts
8038 * @phba: pointer to lpfc hba data structure.
8040 * This routine is invoked to check the user settable queue counts for EQs.
8041 * After this routine is called the counts will be set to valid values that
8042 * adhere to the constraints of the system's interrupt vectors and the port's
8047 * -ENOMEM - No available memory
8050 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
8053 int fof_vectors = phba->cfg_fof ? 1 : 0;
8056 * Sanity check for configured queue parameters against the run-time
8060 /* Sanity check on HBA EQ parameters */
8061 io_channel = phba->io_channel_irqs;
8063 if (phba->sli4_hba.num_online_cpu < io_channel) {
8064 lpfc_printf_log(phba,
8066 "3188 Reducing IO channels to match number of "
8067 "online CPUs: from %d to %d\n",
8068 io_channel, phba->sli4_hba.num_online_cpu);
8069 io_channel = phba->sli4_hba.num_online_cpu;
8072 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
8073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8074 "2575 Reducing IO channels to match number of "
8075 "available EQs: from %d to %d\n",
8077 phba->sli4_hba.max_cfg_param.max_eq);
8078 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
8081 /* The actual number of FCP / NVME event queues adopted */
8082 if (io_channel != phba->io_channel_irqs)
8083 phba->io_channel_irqs = io_channel;
8084 if (phba->cfg_fcp_io_channel > io_channel)
8085 phba->cfg_fcp_io_channel = io_channel;
8086 if (phba->cfg_nvme_io_channel > io_channel)
8087 phba->cfg_nvme_io_channel = io_channel;
8088 if (phba->nvmet_support) {
8089 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8090 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8092 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8093 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
8095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8096 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
8097 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
8098 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
8100 /* Get EQ depth from module parameter, fake the default for now */
8101 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8102 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8104 /* Get CQ depth from module parameter, fake the default for now */
8105 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8106 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8111 lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8113 struct lpfc_queue *qdesc;
8115 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8116 phba->sli4_hba.cq_esize,
8117 LPFC_CQE_EXP_COUNT);
8119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8120 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8124 qdesc->qe_valid = 1;
8125 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8127 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8128 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
8130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8131 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8135 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8136 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8141 lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8143 struct lpfc_queue *qdesc;
8146 /* Create Fast Path FCP CQs */
8147 if (phba->enab_exp_wqcq_pages)
8148 /* Increase the CQ size when WQEs contain an embedded cdb */
8149 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8150 phba->sli4_hba.cq_esize,
8151 LPFC_CQE_EXP_COUNT);
8154 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8155 phba->sli4_hba.cq_esize,
8156 phba->sli4_hba.cq_ecount);
8158 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8159 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8162 qdesc->qe_valid = 1;
8163 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8165 /* Create Fast Path FCP WQs */
8166 if (phba->enab_exp_wqcq_pages) {
8167 /* Increase the WQ size when WQEs contain an embedded cdb */
8168 wqesize = (phba->fcp_embed_io) ?
8169 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
8170 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8172 LPFC_WQE_EXP_COUNT);
8174 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8175 phba->sli4_hba.wq_esize,
8176 phba->sli4_hba.wq_ecount);
8179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8180 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8184 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8185 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8190 * lpfc_sli4_queue_create - Create all the SLI4 queues
8191 * @phba: pointer to lpfc hba data structure.
8193 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8194 * operation. For each SLI4 queue type, the parameters such as queue entry
8195 * count (queue depth) shall be taken from the module parameter. For now,
8196 * we just use some constant number as place holder.
8200 * -ENOMEM - No availble memory
8201 * -EIO - The mailbox failed to complete successfully.
8204 lpfc_sli4_queue_create(struct lpfc_hba *phba)
8206 struct lpfc_queue *qdesc;
8207 int idx, io_channel;
8210 * Create HBA Record arrays.
8211 * Both NVME and FCP will share that same vectors / EQs
8213 io_channel = phba->io_channel_irqs;
8217 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8218 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8219 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8220 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8221 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8222 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
8223 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8224 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8225 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8226 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8228 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8229 sizeof(struct lpfc_queue *),
8231 if (!phba->sli4_hba.hba_eq) {
8232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8233 "2576 Failed allocate memory for "
8234 "fast-path EQ record array\n");
8238 if (phba->cfg_fcp_io_channel) {
8239 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8240 sizeof(struct lpfc_queue *),
8242 if (!phba->sli4_hba.fcp_cq) {
8243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8244 "2577 Failed allocate memory for "
8245 "fast-path CQ record array\n");
8248 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8249 sizeof(struct lpfc_queue *),
8251 if (!phba->sli4_hba.fcp_wq) {
8252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8253 "2578 Failed allocate memory for "
8254 "fast-path FCP WQ record array\n");
8258 * Since the first EQ can have multiple CQs associated with it,
8259 * this array is used to quickly see if we have a FCP fast-path
8262 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8265 if (!phba->sli4_hba.fcp_cq_map) {
8266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8267 "2545 Failed allocate memory for "
8268 "fast-path CQ map\n");
8273 if (phba->cfg_nvme_io_channel) {
8274 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8275 sizeof(struct lpfc_queue *),
8277 if (!phba->sli4_hba.nvme_cq) {
8278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8279 "6077 Failed allocate memory for "
8280 "fast-path CQ record array\n");
8284 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8285 sizeof(struct lpfc_queue *),
8287 if (!phba->sli4_hba.nvme_wq) {
8288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8289 "2581 Failed allocate memory for "
8290 "fast-path NVME WQ record array\n");
8295 * Since the first EQ can have multiple CQs associated with it,
8296 * this array is used to quickly see if we have a NVME fast-path
8299 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8302 if (!phba->sli4_hba.nvme_cq_map) {
8303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8304 "6078 Failed allocate memory for "
8305 "fast-path CQ map\n");
8309 if (phba->nvmet_support) {
8310 phba->sli4_hba.nvmet_cqset = kcalloc(
8311 phba->cfg_nvmet_mrq,
8312 sizeof(struct lpfc_queue *),
8314 if (!phba->sli4_hba.nvmet_cqset) {
8315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8316 "3121 Fail allocate memory for "
8317 "fast-path CQ set array\n");
8320 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8321 phba->cfg_nvmet_mrq,
8322 sizeof(struct lpfc_queue *),
8324 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8326 "3122 Fail allocate memory for "
8327 "fast-path RQ set hdr array\n");
8330 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8331 phba->cfg_nvmet_mrq,
8332 sizeof(struct lpfc_queue *),
8334 if (!phba->sli4_hba.nvmet_mrq_data) {
8335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8336 "3124 Fail allocate memory for "
8337 "fast-path RQ set data array\n");
8343 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8345 /* Create HBA Event Queues (EQs) */
8346 for (idx = 0; idx < io_channel; idx++) {
8348 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8349 phba->sli4_hba.eq_esize,
8350 phba->sli4_hba.eq_ecount);
8352 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8353 "0497 Failed allocate EQ (%d)\n", idx);
8356 qdesc->qe_valid = 1;
8357 phba->sli4_hba.hba_eq[idx] = qdesc;
8360 /* FCP and NVME io channels are not required to be balanced */
8362 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8363 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8366 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8367 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8370 if (phba->nvmet_support) {
8371 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8372 qdesc = lpfc_sli4_queue_alloc(phba,
8373 LPFC_DEFAULT_PAGE_SIZE,
8374 phba->sli4_hba.cq_esize,
8375 phba->sli4_hba.cq_ecount);
8377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8378 "3142 Failed allocate NVME "
8379 "CQ Set (%d)\n", idx);
8382 qdesc->qe_valid = 1;
8383 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8388 * Create Slow Path Completion Queues (CQs)
8391 /* Create slow-path Mailbox Command Complete Queue */
8392 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8393 phba->sli4_hba.cq_esize,
8394 phba->sli4_hba.cq_ecount);
8396 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8397 "0500 Failed allocate slow-path mailbox CQ\n");
8400 qdesc->qe_valid = 1;
8401 phba->sli4_hba.mbx_cq = qdesc;
8403 /* Create slow-path ELS Complete Queue */
8404 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8405 phba->sli4_hba.cq_esize,
8406 phba->sli4_hba.cq_ecount);
8408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8409 "0501 Failed allocate slow-path ELS CQ\n");
8412 qdesc->qe_valid = 1;
8413 phba->sli4_hba.els_cq = qdesc;
8417 * Create Slow Path Work Queues (WQs)
8420 /* Create Mailbox Command Queue */
8422 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8423 phba->sli4_hba.mq_esize,
8424 phba->sli4_hba.mq_ecount);
8426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8427 "0505 Failed allocate slow-path MQ\n");
8430 phba->sli4_hba.mbx_wq = qdesc;
8433 * Create ELS Work Queues
8436 /* Create slow-path ELS Work Queue */
8437 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8438 phba->sli4_hba.wq_esize,
8439 phba->sli4_hba.wq_ecount);
8441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8442 "0504 Failed allocate slow-path ELS WQ\n");
8445 phba->sli4_hba.els_wq = qdesc;
8446 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8448 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8449 /* Create NVME LS Complete Queue */
8450 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8451 phba->sli4_hba.cq_esize,
8452 phba->sli4_hba.cq_ecount);
8454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8455 "6079 Failed allocate NVME LS CQ\n");
8458 qdesc->qe_valid = 1;
8459 phba->sli4_hba.nvmels_cq = qdesc;
8461 /* Create NVME LS Work Queue */
8462 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8463 phba->sli4_hba.wq_esize,
8464 phba->sli4_hba.wq_ecount);
8466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8467 "6080 Failed allocate NVME LS WQ\n");
8470 phba->sli4_hba.nvmels_wq = qdesc;
8471 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8475 * Create Receive Queue (RQ)
8478 /* Create Receive Queue for header */
8479 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8480 phba->sli4_hba.rq_esize,
8481 phba->sli4_hba.rq_ecount);
8483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8484 "0506 Failed allocate receive HRQ\n");
8487 phba->sli4_hba.hdr_rq = qdesc;
8489 /* Create Receive Queue for data */
8490 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8491 phba->sli4_hba.rq_esize,
8492 phba->sli4_hba.rq_ecount);
8494 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8495 "0507 Failed allocate receive DRQ\n");
8498 phba->sli4_hba.dat_rq = qdesc;
8500 if (phba->nvmet_support) {
8501 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8502 /* Create NVMET Receive Queue for header */
8503 qdesc = lpfc_sli4_queue_alloc(phba,
8504 LPFC_DEFAULT_PAGE_SIZE,
8505 phba->sli4_hba.rq_esize,
8506 LPFC_NVMET_RQE_DEF_COUNT);
8508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8509 "3146 Failed allocate "
8513 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8515 /* Only needed for header of RQ pair */
8516 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8518 if (qdesc->rqbp == NULL) {
8519 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8520 "6131 Failed allocate "
8525 /* Put list in known state in case driver load fails. */
8526 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8528 /* Create NVMET Receive Queue for data */
8529 qdesc = lpfc_sli4_queue_alloc(phba,
8530 LPFC_DEFAULT_PAGE_SIZE,
8531 phba->sli4_hba.rq_esize,
8532 LPFC_NVMET_RQE_DEF_COUNT);
8534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8535 "3156 Failed allocate "
8539 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8543 /* Create the Queues needed for Flash Optimized Fabric operations */
8545 lpfc_fof_queue_create(phba);
8549 lpfc_sli4_queue_destroy(phba);
8554 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
8557 lpfc_sli4_queue_free(*qp);
8563 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8570 for (idx = 0; idx < max; idx++)
8571 __lpfc_sli4_release_queue(&(*qs)[idx]);
8578 lpfc_sli4_release_queue_map(uint16_t **qmap)
8580 if (*qmap != NULL) {
8587 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8588 * @phba: pointer to lpfc hba data structure.
8590 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8595 * -ENOMEM - No available memory
8596 * -EIO - The mailbox failed to complete successfully.
8599 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8602 lpfc_fof_queue_destroy(phba);
8604 /* Release HBA eqs */
8605 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
8607 /* Release FCP cqs */
8608 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
8609 phba->cfg_fcp_io_channel);
8611 /* Release FCP wqs */
8612 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
8613 phba->cfg_fcp_io_channel);
8615 /* Release FCP CQ mapping array */
8616 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8618 /* Release NVME cqs */
8619 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8620 phba->cfg_nvme_io_channel);
8622 /* Release NVME wqs */
8623 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8624 phba->cfg_nvme_io_channel);
8626 /* Release NVME CQ mapping array */
8627 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
8629 if (phba->nvmet_support) {
8630 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8631 phba->cfg_nvmet_mrq);
8633 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8634 phba->cfg_nvmet_mrq);
8635 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8636 phba->cfg_nvmet_mrq);
8639 /* Release mailbox command work queue */
8640 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
8642 /* Release ELS work queue */
8643 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8645 /* Release ELS work queue */
8646 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
8648 /* Release unsolicited receive queue */
8649 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8650 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
8652 /* Release ELS complete queue */
8653 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8655 /* Release NVME LS complete queue */
8656 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
8658 /* Release mailbox command complete queue */
8659 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8661 /* Everything on this list has been freed */
8662 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8666 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8668 struct lpfc_rqb *rqbp;
8669 struct lpfc_dmabuf *h_buf;
8670 struct rqb_dmabuf *rqb_buffer;
8673 while (!list_empty(&rqbp->rqb_buffer_list)) {
8674 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8675 struct lpfc_dmabuf, list);
8677 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8678 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8679 rqbp->buffer_count--;
8685 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8686 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8687 int qidx, uint32_t qtype)
8689 struct lpfc_sli_ring *pring;
8692 if (!eq || !cq || !wq) {
8693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8694 "6085 Fast-path %s (%d) not allocated\n",
8695 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8699 /* create the Cq first */
8700 rc = lpfc_cq_create(phba, cq, eq,
8701 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8704 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8705 qidx, (uint32_t)rc);
8710 if (qtype != LPFC_MBOX) {
8711 /* Setup nvme_cq_map for fast lookup */
8713 *cq_map = cq->queue_id;
8715 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8716 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8717 qidx, cq->queue_id, qidx, eq->queue_id);
8720 rc = lpfc_wq_create(phba, wq, cq, qtype);
8722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8723 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8724 qidx, (uint32_t)rc);
8725 /* no need to tear down cq - caller will do so */
8730 /* Bind this CQ/WQ to the NVME ring */
8732 pring->sli.sli4.wqp = (void *)wq;
8735 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8736 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8737 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8739 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8742 "0539 Failed setup of slow-path MQ: "
8744 /* no need to tear down cq - caller will do so */
8748 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8749 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8750 phba->sli4_hba.mbx_wq->queue_id,
8751 phba->sli4_hba.mbx_cq->queue_id);
8758 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8759 * @phba: pointer to lpfc hba data structure.
8761 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8766 * -ENOMEM - No available memory
8767 * -EIO - The mailbox failed to complete successfully.
8770 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8772 uint32_t shdr_status, shdr_add_status;
8773 union lpfc_sli4_cfg_shdr *shdr;
8774 LPFC_MBOXQ_t *mboxq;
8776 uint32_t length, io_channel;
8779 /* Check for dual-ULP support */
8780 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8782 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8783 "3249 Unable to allocate memory for "
8784 "QUERY_FW_CFG mailbox command\n");
8787 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8788 sizeof(struct lpfc_sli4_cfg_mhdr));
8789 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8790 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8791 length, LPFC_SLI4_MBX_EMBED);
8793 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8795 shdr = (union lpfc_sli4_cfg_shdr *)
8796 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8797 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8798 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8799 if (shdr_status || shdr_add_status || rc) {
8800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8801 "3250 QUERY_FW_CFG mailbox failed with status "
8802 "x%x add_status x%x, mbx status x%x\n",
8803 shdr_status, shdr_add_status, rc);
8804 if (rc != MBX_TIMEOUT)
8805 mempool_free(mboxq, phba->mbox_mem_pool);
8810 phba->sli4_hba.fw_func_mode =
8811 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8812 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8813 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
8814 phba->sli4_hba.physical_port =
8815 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
8816 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8817 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8818 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8819 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8821 if (rc != MBX_TIMEOUT)
8822 mempool_free(mboxq, phba->mbox_mem_pool);
8825 * Set up HBA Event Queues (EQs)
8827 io_channel = phba->io_channel_irqs;
8829 /* Set up HBA event queue */
8830 if (io_channel && !phba->sli4_hba.hba_eq) {
8831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8832 "3147 Fast-path EQs not allocated\n");
8836 for (qidx = 0; qidx < io_channel; qidx++) {
8837 if (!phba->sli4_hba.hba_eq[qidx]) {
8838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8839 "0522 Fast-path EQ (%d) not "
8840 "allocated\n", qidx);
8844 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8845 phba->cfg_fcp_imax);
8847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8848 "0523 Failed setup of fast-path EQ "
8849 "(%d), rc = 0x%x\n", qidx,
8853 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8854 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8855 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
8858 if (phba->cfg_nvme_io_channel) {
8859 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
8860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8861 "6084 Fast-path NVME %s array not allocated\n",
8862 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
8867 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8868 rc = lpfc_create_wq_cq(phba,
8869 phba->sli4_hba.hba_eq[
8871 phba->sli4_hba.nvme_cq[qidx],
8872 phba->sli4_hba.nvme_wq[qidx],
8873 &phba->sli4_hba.nvme_cq_map[qidx],
8876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8877 "6123 Failed to setup fastpath "
8878 "NVME WQ/CQ (%d), rc = 0x%x\n",
8879 qidx, (uint32_t)rc);
8885 if (phba->cfg_fcp_io_channel) {
8886 /* Set up fast-path FCP Response Complete Queue */
8887 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
8888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8889 "3148 Fast-path FCP %s array not allocated\n",
8890 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
8895 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8896 rc = lpfc_create_wq_cq(phba,
8897 phba->sli4_hba.hba_eq[
8899 phba->sli4_hba.fcp_cq[qidx],
8900 phba->sli4_hba.fcp_wq[qidx],
8901 &phba->sli4_hba.fcp_cq_map[qidx],
8904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8905 "0535 Failed to setup fastpath "
8906 "FCP WQ/CQ (%d), rc = 0x%x\n",
8907 qidx, (uint32_t)rc);
8914 * Set up Slow Path Complete Queues (CQs)
8917 /* Set up slow-path MBOX CQ/MQ */
8919 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
8920 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8921 "0528 %s not allocated\n",
8922 phba->sli4_hba.mbx_cq ?
8923 "Mailbox WQ" : "Mailbox CQ");
8928 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8929 phba->sli4_hba.mbx_cq,
8930 phba->sli4_hba.mbx_wq,
8931 NULL, 0, LPFC_MBOX);
8933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8934 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8938 if (phba->nvmet_support) {
8939 if (!phba->sli4_hba.nvmet_cqset) {
8940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8941 "3165 Fast-path NVME CQ Set "
8942 "array not allocated\n");
8946 if (phba->cfg_nvmet_mrq > 1) {
8947 rc = lpfc_cq_create_set(phba,
8948 phba->sli4_hba.nvmet_cqset,
8949 phba->sli4_hba.hba_eq,
8950 LPFC_WCQ, LPFC_NVMET);
8952 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8953 "3164 Failed setup of NVME CQ "
8959 /* Set up NVMET Receive Complete Queue */
8960 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8961 phba->sli4_hba.hba_eq[0],
8962 LPFC_WCQ, LPFC_NVMET);
8964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8965 "6089 Failed setup NVMET CQ: "
8966 "rc = 0x%x\n", (uint32_t)rc);
8969 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
8971 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8972 "6090 NVMET CQ setup: cq-id=%d, "
8973 "parent eq-id=%d\n",
8974 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8975 phba->sli4_hba.hba_eq[0]->queue_id);
8979 /* Set up slow-path ELS WQ/CQ */
8980 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
8981 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8982 "0530 ELS %s not allocated\n",
8983 phba->sli4_hba.els_cq ? "WQ" : "CQ");
8987 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8988 phba->sli4_hba.els_cq,
8989 phba->sli4_hba.els_wq,
8992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8993 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8997 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8998 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8999 phba->sli4_hba.els_wq->queue_id,
9000 phba->sli4_hba.els_cq->queue_id);
9002 if (phba->cfg_nvme_io_channel) {
9003 /* Set up NVME LS Complete Queue */
9004 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9006 "6091 LS %s not allocated\n",
9007 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9011 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9012 phba->sli4_hba.nvmels_cq,
9013 phba->sli4_hba.nvmels_wq,
9014 NULL, 0, LPFC_NVME_LS);
9016 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9017 "0529 Failed setup of NVVME LS WQ/CQ: "
9018 "rc = 0x%x\n", (uint32_t)rc);
9022 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9023 "6096 ELS WQ setup: wq-id=%d, "
9024 "parent cq-id=%d\n",
9025 phba->sli4_hba.nvmels_wq->queue_id,
9026 phba->sli4_hba.nvmels_cq->queue_id);
9030 * Create NVMET Receive Queue (RQ)
9032 if (phba->nvmet_support) {
9033 if ((!phba->sli4_hba.nvmet_cqset) ||
9034 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9035 (!phba->sli4_hba.nvmet_mrq_data)) {
9036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9037 "6130 MRQ CQ Queues not "
9042 if (phba->cfg_nvmet_mrq > 1) {
9043 rc = lpfc_mrq_create(phba,
9044 phba->sli4_hba.nvmet_mrq_hdr,
9045 phba->sli4_hba.nvmet_mrq_data,
9046 phba->sli4_hba.nvmet_cqset,
9049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9050 "6098 Failed setup of NVMET "
9057 rc = lpfc_rq_create(phba,
9058 phba->sli4_hba.nvmet_mrq_hdr[0],
9059 phba->sli4_hba.nvmet_mrq_data[0],
9060 phba->sli4_hba.nvmet_cqset[0],
9063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9064 "6057 Failed setup of NVMET "
9065 "Receive Queue: rc = 0x%x\n",
9071 phba, KERN_INFO, LOG_INIT,
9072 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9073 "dat-rq-id=%d parent cq-id=%d\n",
9074 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9075 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9076 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9081 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9083 "0540 Receive Queue not allocated\n");
9088 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
9089 phba->sli4_hba.els_cq, LPFC_USOL);
9091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9092 "0541 Failed setup of Receive Queue: "
9093 "rc = 0x%x\n", (uint32_t)rc);
9097 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9098 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9099 "parent cq-id=%d\n",
9100 phba->sli4_hba.hdr_rq->queue_id,
9101 phba->sli4_hba.dat_rq->queue_id,
9102 phba->sli4_hba.els_cq->queue_id);
9104 if (phba->cfg_fof) {
9105 rc = lpfc_fof_queue_setup(phba);
9107 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9108 "0549 Failed setup of FOF Queues: "
9114 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
9115 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9116 phba->cfg_fcp_imax);
9121 lpfc_sli4_queue_unset(phba);
9127 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9128 * @phba: pointer to lpfc hba data structure.
9130 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9135 * -ENOMEM - No available memory
9136 * -EIO - The mailbox failed to complete successfully.
9139 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9143 /* Unset the queues created for Flash Optimized Fabric operations */
9145 lpfc_fof_queue_destroy(phba);
9147 /* Unset mailbox command work queue */
9148 if (phba->sli4_hba.mbx_wq)
9149 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9151 /* Unset NVME LS work queue */
9152 if (phba->sli4_hba.nvmels_wq)
9153 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9155 /* Unset ELS work queue */
9156 if (phba->sli4_hba.els_wq)
9157 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9159 /* Unset unsolicited receive queue */
9160 if (phba->sli4_hba.hdr_rq)
9161 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9162 phba->sli4_hba.dat_rq);
9164 /* Unset FCP work queue */
9165 if (phba->sli4_hba.fcp_wq)
9166 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9167 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9169 /* Unset NVME work queue */
9170 if (phba->sli4_hba.nvme_wq) {
9171 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9172 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
9175 /* Unset mailbox command complete queue */
9176 if (phba->sli4_hba.mbx_cq)
9177 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9179 /* Unset ELS complete queue */
9180 if (phba->sli4_hba.els_cq)
9181 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9183 /* Unset NVME LS complete queue */
9184 if (phba->sli4_hba.nvmels_cq)
9185 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9187 /* Unset NVME response complete queue */
9188 if (phba->sli4_hba.nvme_cq)
9189 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9190 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9192 if (phba->nvmet_support) {
9193 /* Unset NVMET MRQ queue */
9194 if (phba->sli4_hba.nvmet_mrq_hdr) {
9195 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9198 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9199 phba->sli4_hba.nvmet_mrq_data[qidx]);
9202 /* Unset NVMET CQ Set complete queue */
9203 if (phba->sli4_hba.nvmet_cqset) {
9204 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9206 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9210 /* Unset FCP response complete queue */
9211 if (phba->sli4_hba.fcp_cq)
9212 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9213 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9215 /* Unset fast-path event queue */
9216 if (phba->sli4_hba.hba_eq)
9217 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9218 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
9222 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9223 * @phba: pointer to lpfc hba data structure.
9225 * This routine is invoked to allocate and set up a pool of completion queue
9226 * events. The body of the completion queue event is a completion queue entry
9227 * CQE. For now, this pool is used for the interrupt service routine to queue
9228 * the following HBA completion queue events for the worker thread to process:
9229 * - Mailbox asynchronous events
9230 * - Receive queue completion unsolicited events
9231 * Later, this can be used for all the slow-path events.
9235 * -ENOMEM - No available memory
9238 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9240 struct lpfc_cq_event *cq_event;
9243 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9244 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9246 goto out_pool_create_fail;
9247 list_add_tail(&cq_event->list,
9248 &phba->sli4_hba.sp_cqe_event_pool);
9252 out_pool_create_fail:
9253 lpfc_sli4_cq_event_pool_destroy(phba);
9258 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9259 * @phba: pointer to lpfc hba data structure.
9261 * This routine is invoked to free the pool of completion queue events at
9262 * driver unload time. Note that, it is the responsibility of the driver
9263 * cleanup routine to free all the outstanding completion-queue events
9264 * allocated from this pool back into the pool before invoking this routine
9265 * to destroy the pool.
9268 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9270 struct lpfc_cq_event *cq_event, *next_cq_event;
9272 list_for_each_entry_safe(cq_event, next_cq_event,
9273 &phba->sli4_hba.sp_cqe_event_pool, list) {
9274 list_del(&cq_event->list);
9280 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9281 * @phba: pointer to lpfc hba data structure.
9283 * This routine is the lock free version of the API invoked to allocate a
9284 * completion-queue event from the free pool.
9286 * Return: Pointer to the newly allocated completion-queue event if successful
9289 struct lpfc_cq_event *
9290 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9292 struct lpfc_cq_event *cq_event = NULL;
9294 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9295 struct lpfc_cq_event, list);
9300 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9301 * @phba: pointer to lpfc hba data structure.
9303 * This routine is the lock version of the API invoked to allocate a
9304 * completion-queue event from the free pool.
9306 * Return: Pointer to the newly allocated completion-queue event if successful
9309 struct lpfc_cq_event *
9310 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9312 struct lpfc_cq_event *cq_event;
9313 unsigned long iflags;
9315 spin_lock_irqsave(&phba->hbalock, iflags);
9316 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9317 spin_unlock_irqrestore(&phba->hbalock, iflags);
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 free 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 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9337 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9338 * @phba: pointer to lpfc hba data structure.
9339 * @cq_event: pointer to the completion queue event to be freed.
9341 * This routine is the lock version of the API invoked to release a
9342 * completion-queue event back into the free pool.
9345 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9346 struct lpfc_cq_event *cq_event)
9348 unsigned long iflags;
9349 spin_lock_irqsave(&phba->hbalock, iflags);
9350 __lpfc_sli4_cq_event_release(phba, cq_event);
9351 spin_unlock_irqrestore(&phba->hbalock, iflags);
9355 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9356 * @phba: pointer to lpfc hba data structure.
9358 * This routine is to free all the pending completion-queue events to the
9359 * back into the free pool for device reset.
9362 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9365 struct lpfc_cq_event *cqe;
9366 unsigned long iflags;
9368 /* Retrieve all the pending WCQEs from pending WCQE lists */
9369 spin_lock_irqsave(&phba->hbalock, iflags);
9370 /* Pending FCP XRI abort events */
9371 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9373 /* Pending ELS XRI abort events */
9374 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9376 /* Pending asynnc events */
9377 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9379 spin_unlock_irqrestore(&phba->hbalock, iflags);
9381 while (!list_empty(&cqelist)) {
9382 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9383 lpfc_sli4_cq_event_release(phba, cqe);
9388 * lpfc_pci_function_reset - Reset pci function.
9389 * @phba: pointer to lpfc hba data structure.
9391 * This routine is invoked to request a PCI function reset. It will destroys
9392 * all resources assigned to the PCI function which originates this request.
9396 * -ENOMEM - No available memory
9397 * -EIO - The mailbox failed to complete successfully.
9400 lpfc_pci_function_reset(struct lpfc_hba *phba)
9402 LPFC_MBOXQ_t *mboxq;
9403 uint32_t rc = 0, if_type;
9404 uint32_t shdr_status, shdr_add_status;
9406 uint32_t port_reset = 0;
9407 union lpfc_sli4_cfg_shdr *shdr;
9408 struct lpfc_register reg_data;
9411 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9413 case LPFC_SLI_INTF_IF_TYPE_0:
9414 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9418 "0494 Unable to allocate memory for "
9419 "issuing SLI_FUNCTION_RESET mailbox "
9424 /* Setup PCI function reset mailbox-ioctl command */
9425 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9426 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9427 LPFC_SLI4_MBX_EMBED);
9428 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9429 shdr = (union lpfc_sli4_cfg_shdr *)
9430 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9431 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9432 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9434 if (rc != MBX_TIMEOUT)
9435 mempool_free(mboxq, phba->mbox_mem_pool);
9436 if (shdr_status || shdr_add_status || rc) {
9437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9438 "0495 SLI_FUNCTION_RESET mailbox "
9439 "failed with status x%x add_status x%x,"
9440 " mbx status x%x\n",
9441 shdr_status, shdr_add_status, rc);
9445 case LPFC_SLI_INTF_IF_TYPE_2:
9446 case LPFC_SLI_INTF_IF_TYPE_6:
9449 * Poll the Port Status Register and wait for RDY for
9450 * up to 30 seconds. If the port doesn't respond, treat
9453 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
9454 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9455 STATUSregaddr, ®_data.word0)) {
9459 if (bf_get(lpfc_sliport_status_rdy, ®_data))
9464 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
9465 phba->work_status[0] = readl(
9466 phba->sli4_hba.u.if_type2.ERR1regaddr);
9467 phba->work_status[1] = readl(
9468 phba->sli4_hba.u.if_type2.ERR2regaddr);
9469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9470 "2890 Port not ready, port status reg "
9471 "0x%x error 1=0x%x, error 2=0x%x\n",
9473 phba->work_status[0],
9474 phba->work_status[1]);
9481 * Reset the port now
9484 bf_set(lpfc_sliport_ctrl_end, ®_data,
9485 LPFC_SLIPORT_LITTLE_ENDIAN);
9486 bf_set(lpfc_sliport_ctrl_ip, ®_data,
9487 LPFC_SLIPORT_INIT_PORT);
9488 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9491 pci_read_config_word(phba->pcidev,
9492 PCI_DEVICE_ID, &devid);
9497 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
9503 case LPFC_SLI_INTF_IF_TYPE_1:
9509 /* Catch the not-ready port failure after a port reset. */
9511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9512 "3317 HBA not functional: IP Reset Failed "
9513 "try: echo fw_reset > board_mode\n");
9521 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9522 * @phba: pointer to lpfc hba data structure.
9524 * This routine is invoked to set up the PCI device memory space for device
9525 * with SLI-4 interface spec.
9529 * other values - error
9532 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9534 struct pci_dev *pdev;
9535 unsigned long bar0map_len, bar1map_len, bar2map_len;
9536 int error = -ENODEV;
9539 /* Obtain PCI device reference */
9543 pdev = phba->pcidev;
9545 /* Set the device DMA mask size */
9546 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9547 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9548 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9549 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
9555 * The BARs and register set definitions and offset locations are
9556 * dependent on the if_type.
9558 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9559 &phba->sli4_hba.sli_intf.word0)) {
9563 /* There is no SLI3 failback for SLI4 devices. */
9564 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9565 LPFC_SLI_INTF_VALID) {
9566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9567 "2894 SLI_INTF reg contents invalid "
9568 "sli_intf reg 0x%x\n",
9569 phba->sli4_hba.sli_intf.word0);
9573 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9575 * Get the bus address of SLI4 device Bar regions and the
9576 * number of bytes required by each mapping. The mapping of the
9577 * particular PCI BARs regions is dependent on the type of
9580 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9581 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9582 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
9585 * Map SLI4 PCI Config Space Register base to a kernel virtual
9588 phba->sli4_hba.conf_regs_memmap_p =
9589 ioremap(phba->pci_bar0_map, bar0map_len);
9590 if (!phba->sli4_hba.conf_regs_memmap_p) {
9591 dev_printk(KERN_ERR, &pdev->dev,
9592 "ioremap failed for SLI4 PCI config "
9596 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
9597 /* Set up BAR0 PCI config space register memory map */
9598 lpfc_sli4_bar0_register_memmap(phba, if_type);
9600 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9601 bar0map_len = pci_resource_len(pdev, 1);
9602 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9603 dev_printk(KERN_ERR, &pdev->dev,
9604 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9607 phba->sli4_hba.conf_regs_memmap_p =
9608 ioremap(phba->pci_bar0_map, bar0map_len);
9609 if (!phba->sli4_hba.conf_regs_memmap_p) {
9610 dev_printk(KERN_ERR, &pdev->dev,
9611 "ioremap failed for SLI4 PCI config "
9615 lpfc_sli4_bar0_register_memmap(phba, if_type);
9618 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9619 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9621 * Map SLI4 if type 0 HBA Control Register base to a
9622 * kernel virtual address and setup the registers.
9624 phba->pci_bar1_map = pci_resource_start(pdev,
9626 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9627 phba->sli4_hba.ctrl_regs_memmap_p =
9628 ioremap(phba->pci_bar1_map,
9630 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9632 "ioremap failed for SLI4 HBA "
9633 "control registers.\n");
9635 goto out_iounmap_conf;
9637 phba->pci_bar2_memmap_p =
9638 phba->sli4_hba.ctrl_regs_memmap_p;
9639 lpfc_sli4_bar1_register_memmap(phba, if_type);
9642 goto out_iounmap_conf;
9646 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9647 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9649 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9650 * virtual address and setup the registers.
9652 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9653 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9654 phba->sli4_hba.drbl_regs_memmap_p =
9655 ioremap(phba->pci_bar1_map, bar1map_len);
9656 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9658 "ioremap failed for SLI4 HBA doorbell registers.\n");
9659 goto out_iounmap_conf;
9661 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9662 lpfc_sli4_bar1_register_memmap(phba, if_type);
9665 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9666 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9668 * Map SLI4 if type 0 HBA Doorbell Register base to
9669 * a kernel virtual address and setup the registers.
9671 phba->pci_bar2_map = pci_resource_start(pdev,
9673 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9674 phba->sli4_hba.drbl_regs_memmap_p =
9675 ioremap(phba->pci_bar2_map,
9677 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9679 "ioremap failed for SLI4 HBA"
9680 " doorbell registers.\n");
9682 goto out_iounmap_ctrl;
9684 phba->pci_bar4_memmap_p =
9685 phba->sli4_hba.drbl_regs_memmap_p;
9686 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9688 goto out_iounmap_all;
9691 goto out_iounmap_all;
9695 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9696 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9698 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9699 * virtual address and setup the registers.
9701 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9702 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9703 phba->sli4_hba.dpp_regs_memmap_p =
9704 ioremap(phba->pci_bar2_map, bar2map_len);
9705 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9707 "ioremap failed for SLI4 HBA dpp registers.\n");
9708 goto out_iounmap_ctrl;
9710 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9713 /* Set up the EQ/CQ register handeling functions now */
9715 case LPFC_SLI_INTF_IF_TYPE_0:
9716 case LPFC_SLI_INTF_IF_TYPE_2:
9717 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9718 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9719 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
9721 case LPFC_SLI_INTF_IF_TYPE_6:
9722 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9723 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9724 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9733 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9735 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9737 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9743 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9744 * @phba: pointer to lpfc hba data structure.
9746 * This routine is invoked to unset the PCI device memory space for device
9747 * with SLI-4 interface spec.
9750 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9753 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9756 case LPFC_SLI_INTF_IF_TYPE_0:
9757 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9758 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9759 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9761 case LPFC_SLI_INTF_IF_TYPE_2:
9762 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9764 case LPFC_SLI_INTF_IF_TYPE_6:
9765 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9766 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9768 case LPFC_SLI_INTF_IF_TYPE_1:
9770 dev_printk(KERN_ERR, &phba->pcidev->dev,
9771 "FATAL - unsupported SLI4 interface type - %d\n",
9778 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9779 * @phba: pointer to lpfc hba data structure.
9781 * This routine is invoked to enable the MSI-X interrupt vectors to device
9782 * with SLI-3 interface specs.
9786 * other values - error
9789 lpfc_sli_enable_msix(struct lpfc_hba *phba)
9794 /* Set up MSI-X multi-message vectors */
9795 rc = pci_alloc_irq_vectors(phba->pcidev,
9796 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9798 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9799 "0420 PCI enable MSI-X failed (%d)\n", rc);
9804 * Assign MSI-X vectors to interrupt handlers
9807 /* vector-0 is associated to slow-path handler */
9808 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
9809 &lpfc_sli_sp_intr_handler, 0,
9810 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9812 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9813 "0421 MSI-X slow-path request_irq failed "
9818 /* vector-1 is associated to fast-path handler */
9819 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
9820 &lpfc_sli_fp_intr_handler, 0,
9821 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9824 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9825 "0429 MSI-X fast-path request_irq failed "
9831 * Configure HBA MSI-X attention conditions to messages
9833 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9837 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9838 "0474 Unable to allocate memory for issuing "
9839 "MBOX_CONFIG_MSI command\n");
9842 rc = lpfc_config_msi(phba, pmb);
9845 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9846 if (rc != MBX_SUCCESS) {
9847 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9848 "0351 Config MSI mailbox command failed, "
9849 "mbxCmd x%x, mbxStatus x%x\n",
9850 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9854 /* Free memory allocated for mailbox command */
9855 mempool_free(pmb, phba->mbox_mem_pool);
9859 /* Free memory allocated for mailbox command */
9860 mempool_free(pmb, phba->mbox_mem_pool);
9863 /* free the irq already requested */
9864 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
9867 /* free the irq already requested */
9868 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
9871 /* Unconfigure MSI-X capability structure */
9872 pci_free_irq_vectors(phba->pcidev);
9879 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9880 * @phba: pointer to lpfc hba data structure.
9882 * This routine is invoked to enable the MSI interrupt mode to device with
9883 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9884 * enable the MSI vector. The device driver is responsible for calling the
9885 * request_irq() to register MSI vector with a interrupt the handler, which
9886 * is done in this function.
9890 * other values - error
9893 lpfc_sli_enable_msi(struct lpfc_hba *phba)
9897 rc = pci_enable_msi(phba->pcidev);
9899 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9900 "0462 PCI enable MSI mode success.\n");
9902 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9903 "0471 PCI enable MSI mode failed (%d)\n", rc);
9907 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9908 0, LPFC_DRIVER_NAME, phba);
9910 pci_disable_msi(phba->pcidev);
9911 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9912 "0478 MSI request_irq failed (%d)\n", rc);
9918 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9919 * @phba: pointer to lpfc hba data structure.
9921 * This routine is invoked to enable device interrupt and associate driver's
9922 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9923 * spec. Depends on the interrupt mode configured to the driver, the driver
9924 * will try to fallback from the configured interrupt mode to an interrupt
9925 * mode which is supported by the platform, kernel, and device in the order
9927 * MSI-X -> MSI -> IRQ.
9931 * other values - error
9934 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9936 uint32_t intr_mode = LPFC_INTR_ERROR;
9939 if (cfg_mode == 2) {
9940 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9941 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9943 /* Now, try to enable MSI-X interrupt mode */
9944 retval = lpfc_sli_enable_msix(phba);
9946 /* Indicate initialization to MSI-X mode */
9947 phba->intr_type = MSIX;
9953 /* Fallback to MSI if MSI-X initialization failed */
9954 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9955 retval = lpfc_sli_enable_msi(phba);
9957 /* Indicate initialization to MSI mode */
9958 phba->intr_type = MSI;
9963 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9964 if (phba->intr_type == NONE) {
9965 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9966 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9968 /* Indicate initialization to INTx mode */
9969 phba->intr_type = INTx;
9977 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9978 * @phba: pointer to lpfc hba data structure.
9980 * This routine is invoked to disable device interrupt and disassociate the
9981 * driver's interrupt handler(s) from interrupt vector(s) to device with
9982 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9983 * release the interrupt vector(s) for the message signaled interrupt.
9986 lpfc_sli_disable_intr(struct lpfc_hba *phba)
9990 if (phba->intr_type == MSIX)
9991 nr_irqs = LPFC_MSIX_VECTORS;
9995 for (i = 0; i < nr_irqs; i++)
9996 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9997 pci_free_irq_vectors(phba->pcidev);
9999 /* Reset interrupt management states */
10000 phba->intr_type = NONE;
10001 phba->sli.slistat.sli_intr = 0;
10005 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
10006 * @phba: pointer to lpfc hba data structure.
10007 * @vectors: number of msix vectors allocated.
10009 * The routine will figure out the CPU affinity assignment for every
10010 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
10011 * with a pointer to the CPU mask that defines ALL the CPUs this vector
10012 * can be associated with. If the vector can be unquely associated with
10013 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
10014 * In addition, the CPU to IO channel mapping will be calculated
10015 * and the phba->sli4_hba.cpu_map array will reflect this.
10018 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
10020 struct lpfc_vector_map_info *cpup;
10025 struct cpuinfo_x86 *cpuinfo;
10028 /* Init cpu_map array */
10029 memset(phba->sli4_hba.cpu_map, 0xff,
10030 (sizeof(struct lpfc_vector_map_info) *
10031 phba->sli4_hba.num_present_cpu));
10033 /* Update CPU map with physical id and core id of each CPU */
10034 cpup = phba->sli4_hba.cpu_map;
10035 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10037 cpuinfo = &cpu_data(cpu);
10038 cpup->phys_id = cpuinfo->phys_proc_id;
10039 cpup->core_id = cpuinfo->cpu_core_id;
10041 /* No distinction between CPUs for other platforms */
10045 cpup->channel_id = index; /* For now round robin */
10046 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10048 if (vec >= vectors)
10051 if (index >= phba->cfg_fcp_io_channel)
10059 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10060 * @phba: pointer to lpfc hba data structure.
10062 * This routine is invoked to enable the MSI-X interrupt vectors to device
10063 * with SLI-4 interface spec.
10067 * other values - error
10070 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10072 int vectors, rc, index;
10075 /* Set up MSI-X multi-message vectors */
10076 vectors = phba->io_channel_irqs;
10080 rc = pci_alloc_irq_vectors(phba->pcidev,
10081 (phba->nvmet_support) ? 1 : 2,
10082 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
10084 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10085 "0484 PCI enable MSI-X failed (%d)\n", rc);
10090 /* Assign MSI-X vectors to interrupt handlers */
10091 for (index = 0; index < vectors; index++) {
10092 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10093 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10094 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
10095 LPFC_DRIVER_HANDLER_NAME"%d", index);
10097 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10098 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10099 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
10100 if (phba->cfg_fof && (index == (vectors - 1)))
10101 rc = request_irq(pci_irq_vector(phba->pcidev, index),
10102 &lpfc_sli4_fof_intr_handler, 0,
10104 &phba->sli4_hba.hba_eq_hdl[index]);
10106 rc = request_irq(pci_irq_vector(phba->pcidev, index),
10107 &lpfc_sli4_hba_intr_handler, 0,
10109 &phba->sli4_hba.hba_eq_hdl[index]);
10111 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10112 "0486 MSI-X fast-path (%d) "
10113 "request_irq failed (%d)\n", index, rc);
10121 if (vectors != phba->io_channel_irqs) {
10122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10123 "3238 Reducing IO channels to match number of "
10124 "MSI-X vectors, requested %d got %d\n",
10125 phba->io_channel_irqs, vectors);
10126 if (phba->cfg_fcp_io_channel > vectors)
10127 phba->cfg_fcp_io_channel = vectors;
10128 if (phba->cfg_nvme_io_channel > vectors)
10129 phba->cfg_nvme_io_channel = vectors;
10130 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10131 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10133 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
10135 lpfc_cpu_affinity_check(phba, vectors);
10140 /* free the irq already requested */
10141 for (--index; index >= 0; index--)
10142 free_irq(pci_irq_vector(phba->pcidev, index),
10143 &phba->sli4_hba.hba_eq_hdl[index]);
10145 /* Unconfigure MSI-X capability structure */
10146 pci_free_irq_vectors(phba->pcidev);
10153 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10154 * @phba: pointer to lpfc hba data structure.
10156 * This routine is invoked to enable the MSI interrupt mode to device with
10157 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10158 * to enable the MSI vector. The device driver is responsible for calling
10159 * the request_irq() to register MSI vector with a interrupt the handler,
10160 * which is done in this function.
10164 * other values - error
10167 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10171 rc = pci_enable_msi(phba->pcidev);
10173 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10174 "0487 PCI enable MSI mode success.\n");
10176 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10177 "0488 PCI enable MSI mode failed (%d)\n", rc);
10181 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10182 0, LPFC_DRIVER_NAME, phba);
10184 pci_disable_msi(phba->pcidev);
10185 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10186 "0490 MSI request_irq failed (%d)\n", rc);
10190 for (index = 0; index < phba->io_channel_irqs; index++) {
10191 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10192 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10195 if (phba->cfg_fof) {
10196 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10197 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10203 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10204 * @phba: pointer to lpfc hba data structure.
10206 * This routine is invoked to enable device interrupt and associate driver's
10207 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10208 * interface spec. Depends on the interrupt mode configured to the driver,
10209 * the driver will try to fallback from the configured interrupt mode to an
10210 * interrupt mode which is supported by the platform, kernel, and device in
10212 * MSI-X -> MSI -> IRQ.
10216 * other values - error
10219 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10221 uint32_t intr_mode = LPFC_INTR_ERROR;
10224 if (cfg_mode == 2) {
10225 /* Preparation before conf_msi mbox cmd */
10228 /* Now, try to enable MSI-X interrupt mode */
10229 retval = lpfc_sli4_enable_msix(phba);
10231 /* Indicate initialization to MSI-X mode */
10232 phba->intr_type = MSIX;
10238 /* Fallback to MSI if MSI-X initialization failed */
10239 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10240 retval = lpfc_sli4_enable_msi(phba);
10242 /* Indicate initialization to MSI mode */
10243 phba->intr_type = MSI;
10248 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10249 if (phba->intr_type == NONE) {
10250 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10251 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10253 struct lpfc_hba_eq_hdl *eqhdl;
10255 /* Indicate initialization to INTx mode */
10256 phba->intr_type = INTx;
10259 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10260 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10262 eqhdl->phba = phba;
10263 atomic_set(&eqhdl->hba_eq_in_use, 1);
10265 if (phba->cfg_fof) {
10266 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10268 eqhdl->phba = phba;
10269 atomic_set(&eqhdl->hba_eq_in_use, 1);
10277 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10278 * @phba: pointer to lpfc hba data structure.
10280 * This routine is invoked to disable device interrupt and disassociate
10281 * the driver's interrupt handler(s) from interrupt vector(s) to device
10282 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10283 * will release the interrupt vector(s) for the message signaled interrupt.
10286 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10288 /* Disable the currently initialized interrupt mode */
10289 if (phba->intr_type == MSIX) {
10292 /* Free up MSI-X multi-message vectors */
10293 for (index = 0; index < phba->io_channel_irqs; index++)
10294 free_irq(pci_irq_vector(phba->pcidev, index),
10295 &phba->sli4_hba.hba_eq_hdl[index]);
10298 free_irq(pci_irq_vector(phba->pcidev, index),
10299 &phba->sli4_hba.hba_eq_hdl[index]);
10301 free_irq(phba->pcidev->irq, phba);
10304 pci_free_irq_vectors(phba->pcidev);
10306 /* Reset interrupt management states */
10307 phba->intr_type = NONE;
10308 phba->sli.slistat.sli_intr = 0;
10312 * lpfc_unset_hba - Unset SLI3 hba device initialization
10313 * @phba: pointer to lpfc hba data structure.
10315 * This routine is invoked to unset the HBA device initialization steps to
10316 * a device with SLI-3 interface spec.
10319 lpfc_unset_hba(struct lpfc_hba *phba)
10321 struct lpfc_vport *vport = phba->pport;
10322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10324 spin_lock_irq(shost->host_lock);
10325 vport->load_flag |= FC_UNLOADING;
10326 spin_unlock_irq(shost->host_lock);
10328 kfree(phba->vpi_bmask);
10329 kfree(phba->vpi_ids);
10331 lpfc_stop_hba_timers(phba);
10333 phba->pport->work_port_events = 0;
10335 lpfc_sli_hba_down(phba);
10337 lpfc_sli_brdrestart(phba);
10339 lpfc_sli_disable_intr(phba);
10345 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10346 * @phba: Pointer to HBA context object.
10348 * This function is called in the SLI4 code path to wait for completion
10349 * of device's XRIs exchange busy. It will check the XRI exchange busy
10350 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10351 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10352 * I/Os every 30 seconds, log error message, and wait forever. Only when
10353 * all XRI exchange busy complete, the driver unload shall proceed with
10354 * invoking the function reset ioctl mailbox command to the CNA and the
10355 * the rest of the driver unload resource release.
10358 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10361 int nvme_xri_cmpl = 1;
10362 int nvmet_xri_cmpl = 1;
10363 int fcp_xri_cmpl = 1;
10364 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10366 /* Driver just aborted IOs during the hba_unset process. Pause
10367 * here to give the HBA time to complete the IO and get entries
10368 * into the abts lists.
10370 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10372 /* Wait for NVME pending IO to flush back to transport. */
10373 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10374 lpfc_nvme_wait_for_io_drain(phba);
10376 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10378 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
10379 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10381 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
10383 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10386 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10388 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
10389 if (!nvme_xri_cmpl)
10390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10391 "6100 NVME XRI exchange busy "
10392 "wait time: %d seconds.\n",
10395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10396 "2877 FCP XRI exchange busy "
10397 "wait time: %d seconds.\n",
10400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10401 "2878 ELS XRI exchange busy "
10402 "wait time: %d seconds.\n",
10404 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10405 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10407 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10408 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10410 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10411 nvme_xri_cmpl = list_empty(
10412 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
10413 nvmet_xri_cmpl = list_empty(
10414 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10417 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10418 fcp_xri_cmpl = list_empty(
10419 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10422 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10428 * lpfc_sli4_hba_unset - Unset the fcoe hba
10429 * @phba: Pointer to HBA context object.
10431 * This function is called in the SLI4 code path to reset the HBA's FCoE
10432 * function. The caller is not required to hold any lock. This routine
10433 * issues PCI function reset mailbox command to reset the FCoE function.
10434 * At the end of the function, it calls lpfc_hba_down_post function to
10435 * free any pending commands.
10438 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10441 LPFC_MBOXQ_t *mboxq;
10442 struct pci_dev *pdev = phba->pcidev;
10444 lpfc_stop_hba_timers(phba);
10445 phba->sli4_hba.intr_enable = 0;
10448 * Gracefully wait out the potential current outstanding asynchronous
10452 /* First, block any pending async mailbox command from posted */
10453 spin_lock_irq(&phba->hbalock);
10454 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10455 spin_unlock_irq(&phba->hbalock);
10456 /* Now, trying to wait it out if we can */
10457 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10459 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10462 /* Forcefully release the outstanding mailbox command if timed out */
10463 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10464 spin_lock_irq(&phba->hbalock);
10465 mboxq = phba->sli.mbox_active;
10466 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10467 __lpfc_mbox_cmpl_put(phba, mboxq);
10468 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10469 phba->sli.mbox_active = NULL;
10470 spin_unlock_irq(&phba->hbalock);
10473 /* Abort all iocbs associated with the hba */
10474 lpfc_sli_hba_iocb_abort(phba);
10476 /* Wait for completion of device XRI exchange busy */
10477 lpfc_sli4_xri_exchange_busy_wait(phba);
10479 /* Disable PCI subsystem interrupt */
10480 lpfc_sli4_disable_intr(phba);
10482 /* Disable SR-IOV if enabled */
10483 if (phba->cfg_sriov_nr_virtfn)
10484 pci_disable_sriov(pdev);
10486 /* Stop kthread signal shall trigger work_done one more time */
10487 kthread_stop(phba->worker_thread);
10489 /* Unset the queues shared with the hardware then release all
10490 * allocated resources.
10492 lpfc_sli4_queue_unset(phba);
10493 lpfc_sli4_queue_destroy(phba);
10495 /* Reset SLI4 HBA FCoE function */
10496 lpfc_pci_function_reset(phba);
10498 /* Stop the SLI4 device port */
10499 phba->pport->work_port_events = 0;
10503 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10504 * @phba: Pointer to HBA context object.
10505 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10507 * This function is called in the SLI4 code path to read the port's
10508 * sli4 capabilities.
10510 * This function may be be called from any context that can block-wait
10511 * for the completion. The expectation is that this routine is called
10512 * typically from probe_one or from the online routine.
10515 lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10518 struct lpfc_mqe *mqe;
10519 struct lpfc_pc_sli4_params *sli4_params;
10523 mqe = &mboxq->u.mqe;
10525 /* Read the port's SLI4 Parameters port capabilities */
10526 lpfc_pc_sli4_params(mboxq);
10527 if (!phba->sli4_hba.intr_enable)
10528 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10530 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10531 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10537 sli4_params = &phba->sli4_hba.pc_sli4_params;
10538 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10539 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10540 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10541 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10542 &mqe->un.sli4_params);
10543 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10544 &mqe->un.sli4_params);
10545 sli4_params->proto_types = mqe->un.sli4_params.word3;
10546 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10547 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10548 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10549 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10550 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10551 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10552 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10553 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10554 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10555 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10556 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10557 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10558 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10559 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10560 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10561 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10562 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10563 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10564 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10565 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
10567 /* Make sure that sge_supp_len can be handled by the driver */
10568 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10569 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10575 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10576 * @phba: Pointer to HBA context object.
10577 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10579 * This function is called in the SLI4 code path to read the port's
10580 * sli4 capabilities.
10582 * This function may be be called from any context that can block-wait
10583 * for the completion. The expectation is that this routine is called
10584 * typically from probe_one or from the online routine.
10587 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10590 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10591 struct lpfc_pc_sli4_params *sli4_params;
10594 bool exp_wqcq_pages = true;
10595 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10598 * By default, the driver assumes the SLI4 port requires RPI
10599 * header postings. The SLI4_PARAM response will correct this
10602 phba->sli4_hba.rpi_hdrs_in_use = 1;
10604 /* Read the port's SLI4 Config Parameters */
10605 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10606 sizeof(struct lpfc_sli4_cfg_mhdr));
10607 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10608 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10609 length, LPFC_SLI4_MBX_EMBED);
10610 if (!phba->sli4_hba.intr_enable)
10611 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10613 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10614 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10618 sli4_params = &phba->sli4_hba.pc_sli4_params;
10619 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10620 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10621 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10622 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10623 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10624 mbx_sli4_parameters);
10625 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10626 mbx_sli4_parameters);
10627 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10628 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10630 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10631 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10632 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
10633 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
10634 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10635 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10636 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10637 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
10638 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10639 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
10640 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
10641 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10642 mbx_sli4_parameters);
10643 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
10644 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10645 mbx_sli4_parameters);
10646 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10647 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
10648 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10649 bf_get(cfg_xib, mbx_sli4_parameters));
10651 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10652 !phba->nvme_support) {
10653 phba->nvme_support = 0;
10654 phba->nvmet_support = 0;
10655 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
10656 phba->cfg_nvme_io_channel = 0;
10657 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10659 "6101 Disabling NVME support: "
10660 "Not supported by firmware: %d %d\n",
10661 bf_get(cfg_nvme, mbx_sli4_parameters),
10662 bf_get(cfg_xib, mbx_sli4_parameters));
10664 /* If firmware doesn't support NVME, just use SCSI support */
10665 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10667 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10670 /* Only embed PBDE for if_type 6 */
10671 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10672 LPFC_SLI_INTF_IF_TYPE_6) {
10673 phba->fcp_embed_pbde = 1;
10674 phba->nvme_embed_pbde = 1;
10677 /* PBDE support requires xib be set */
10678 if (!bf_get(cfg_xib, mbx_sli4_parameters)) {
10679 phba->fcp_embed_pbde = 0;
10680 phba->nvme_embed_pbde = 0;
10684 * To support Suppress Response feature we must satisfy 3 conditions.
10685 * lpfc_suppress_rsp module parameter must be set (default).
10686 * In SLI4-Parameters Descriptor:
10687 * Extended Inline Buffers (XIB) must be supported.
10688 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10689 * (double negative).
10691 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10692 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
10693 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10695 phba->cfg_suppress_rsp = 0;
10697 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10698 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10700 /* Make sure that sge_supp_len can be handled by the driver */
10701 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10702 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10705 * Check whether the adapter supports an embedded copy of the
10706 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10707 * to use this option, 128-byte WQEs must be used.
10709 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10710 phba->fcp_embed_io = 1;
10712 phba->fcp_embed_io = 0;
10714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
10715 "6422 XIB %d: FCP %d %d NVME %d %d %d %d\n",
10716 bf_get(cfg_xib, mbx_sli4_parameters),
10717 phba->fcp_embed_pbde, phba->fcp_embed_io,
10718 phba->nvme_support, phba->nvme_embed_pbde,
10719 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
10721 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10722 LPFC_SLI_INTF_IF_TYPE_2) &&
10723 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
10724 LPFC_SLI_INTF_FAMILY_LNCR_A0))
10725 exp_wqcq_pages = false;
10727 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10728 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
10730 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10731 phba->enab_exp_wqcq_pages = 1;
10733 phba->enab_exp_wqcq_pages = 0;
10735 * Check if the SLI port supports MDS Diagnostics
10737 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10738 phba->mds_diags_support = 1;
10740 phba->mds_diags_support = 0;
10745 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10746 * @pdev: pointer to PCI device
10747 * @pid: pointer to PCI device identifier
10749 * This routine is to be called to attach a device with SLI-3 interface spec
10750 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10751 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10752 * information of the device and driver to see if the driver state that it can
10753 * support this kind of device. If the match is successful, the driver core
10754 * invokes this routine. If this routine determines it can claim the HBA, it
10755 * does all the initialization that it needs to do to handle the HBA properly.
10758 * 0 - driver can claim the device
10759 * negative value - driver can not claim the device
10762 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10764 struct lpfc_hba *phba;
10765 struct lpfc_vport *vport = NULL;
10766 struct Scsi_Host *shost = NULL;
10768 uint32_t cfg_mode, intr_mode;
10770 /* Allocate memory for HBA structure */
10771 phba = lpfc_hba_alloc(pdev);
10775 /* Perform generic PCI device enabling operation */
10776 error = lpfc_enable_pci_dev(phba);
10778 goto out_free_phba;
10780 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10781 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10783 goto out_disable_pci_dev;
10785 /* Set up SLI-3 specific device PCI memory space */
10786 error = lpfc_sli_pci_mem_setup(phba);
10788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10789 "1402 Failed to set up pci memory space.\n");
10790 goto out_disable_pci_dev;
10793 /* Set up SLI-3 specific device driver resources */
10794 error = lpfc_sli_driver_resource_setup(phba);
10796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10797 "1404 Failed to set up driver resource.\n");
10798 goto out_unset_pci_mem_s3;
10801 /* Initialize and populate the iocb list per host */
10803 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10806 "1405 Failed to initialize iocb list.\n");
10807 goto out_unset_driver_resource_s3;
10810 /* Set up common device driver resources */
10811 error = lpfc_setup_driver_resource_phase2(phba);
10813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10814 "1406 Failed to set up driver resource.\n");
10815 goto out_free_iocb_list;
10818 /* Get the default values for Model Name and Description */
10819 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10821 /* Create SCSI host to the physical port */
10822 error = lpfc_create_shost(phba);
10824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10825 "1407 Failed to create scsi host.\n");
10826 goto out_unset_driver_resource;
10829 /* Configure sysfs attributes */
10830 vport = phba->pport;
10831 error = lpfc_alloc_sysfs_attr(vport);
10833 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10834 "1476 Failed to allocate sysfs attr\n");
10835 goto out_destroy_shost;
10838 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
10839 /* Now, trying to enable interrupt and bring up the device */
10840 cfg_mode = phba->cfg_use_msi;
10842 /* Put device to a known state before enabling interrupt */
10843 lpfc_stop_port(phba);
10844 /* Configure and enable interrupt */
10845 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10846 if (intr_mode == LPFC_INTR_ERROR) {
10847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10848 "0431 Failed to enable interrupt.\n");
10850 goto out_free_sysfs_attr;
10852 /* SLI-3 HBA setup */
10853 if (lpfc_sli_hba_setup(phba)) {
10854 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10855 "1477 Failed to set up hba\n");
10857 goto out_remove_device;
10860 /* Wait 50ms for the interrupts of previous mailbox commands */
10862 /* Check active interrupts on message signaled interrupts */
10863 if (intr_mode == 0 ||
10864 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10865 /* Log the current active interrupt mode */
10866 phba->intr_mode = intr_mode;
10867 lpfc_log_intr_mode(phba, intr_mode);
10870 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10871 "0447 Configure interrupt mode (%d) "
10872 "failed active interrupt test.\n",
10874 /* Disable the current interrupt mode */
10875 lpfc_sli_disable_intr(phba);
10876 /* Try next level of interrupt mode */
10877 cfg_mode = --intr_mode;
10881 /* Perform post initialization setup */
10882 lpfc_post_init_setup(phba);
10884 /* Check if there are static vports to be created. */
10885 lpfc_create_static_vport(phba);
10890 lpfc_unset_hba(phba);
10891 out_free_sysfs_attr:
10892 lpfc_free_sysfs_attr(vport);
10894 lpfc_destroy_shost(phba);
10895 out_unset_driver_resource:
10896 lpfc_unset_driver_resource_phase2(phba);
10897 out_free_iocb_list:
10898 lpfc_free_iocb_list(phba);
10899 out_unset_driver_resource_s3:
10900 lpfc_sli_driver_resource_unset(phba);
10901 out_unset_pci_mem_s3:
10902 lpfc_sli_pci_mem_unset(phba);
10903 out_disable_pci_dev:
10904 lpfc_disable_pci_dev(phba);
10906 scsi_host_put(shost);
10908 lpfc_hba_free(phba);
10913 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10914 * @pdev: pointer to PCI device
10916 * This routine is to be called to disattach a device with SLI-3 interface
10917 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10918 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10919 * device to be removed from the PCI subsystem properly.
10922 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
10924 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10926 struct lpfc_vport **vports;
10927 struct lpfc_hba *phba = vport->phba;
10930 spin_lock_irq(&phba->hbalock);
10931 vport->load_flag |= FC_UNLOADING;
10932 spin_unlock_irq(&phba->hbalock);
10934 lpfc_free_sysfs_attr(vport);
10936 /* Release all the vports against this physical port */
10937 vports = lpfc_create_vport_work_array(phba);
10938 if (vports != NULL)
10939 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10940 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10942 fc_vport_terminate(vports[i]->fc_vport);
10944 lpfc_destroy_vport_work_array(phba, vports);
10946 /* Remove FC host and then SCSI host with the physical port */
10947 fc_remove_host(shost);
10948 scsi_remove_host(shost);
10950 lpfc_cleanup(vport);
10953 * Bring down the SLI Layer. This step disable all interrupts,
10954 * clears the rings, discards all mailbox commands, and resets
10958 /* HBA interrupt will be disabled after this call */
10959 lpfc_sli_hba_down(phba);
10960 /* Stop kthread signal shall trigger work_done one more time */
10961 kthread_stop(phba->worker_thread);
10962 /* Final cleanup of txcmplq and reset the HBA */
10963 lpfc_sli_brdrestart(phba);
10965 kfree(phba->vpi_bmask);
10966 kfree(phba->vpi_ids);
10968 lpfc_stop_hba_timers(phba);
10969 spin_lock_irq(&phba->hbalock);
10970 list_del_init(&vport->listentry);
10971 spin_unlock_irq(&phba->hbalock);
10973 lpfc_debugfs_terminate(vport);
10975 /* Disable SR-IOV if enabled */
10976 if (phba->cfg_sriov_nr_virtfn)
10977 pci_disable_sriov(pdev);
10979 /* Disable interrupt */
10980 lpfc_sli_disable_intr(phba);
10982 scsi_host_put(shost);
10985 * Call scsi_free before mem_free since scsi bufs are released to their
10986 * corresponding pools here.
10988 lpfc_scsi_free(phba);
10989 lpfc_mem_free_all(phba);
10991 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10992 phba->hbqslimp.virt, phba->hbqslimp.phys);
10994 /* Free resources associated with SLI2 interface */
10995 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
10996 phba->slim2p.virt, phba->slim2p.phys);
10998 /* unmap adapter SLIM and Control Registers */
10999 iounmap(phba->ctrl_regs_memmap_p);
11000 iounmap(phba->slim_memmap_p);
11002 lpfc_hba_free(phba);
11004 pci_release_mem_regions(pdev);
11005 pci_disable_device(pdev);
11009 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
11010 * @pdev: pointer to PCI device
11011 * @msg: power management message
11013 * This routine is to be called from the kernel's PCI subsystem to support
11014 * system Power Management (PM) to device with SLI-3 interface spec. When
11015 * PM invokes this method, it quiesces the device by stopping the driver's
11016 * worker thread for the device, turning off device's interrupt and DMA,
11017 * and bring the device offline. Note that as the driver implements the
11018 * minimum PM requirements to a power-aware driver's PM support for the
11019 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11020 * to the suspend() method call will be treated as SUSPEND and the driver will
11021 * fully reinitialize its device during resume() method call, the driver will
11022 * set device to PCI_D3hot state in PCI config space instead of setting it
11023 * according to the @msg provided by the PM.
11026 * 0 - driver suspended the device
11030 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
11032 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11033 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11035 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11036 "0473 PCI device Power Management suspend.\n");
11038 /* Bring down the device */
11039 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11040 lpfc_offline(phba);
11041 kthread_stop(phba->worker_thread);
11043 /* Disable interrupt from device */
11044 lpfc_sli_disable_intr(phba);
11046 /* Save device state to PCI config space */
11047 pci_save_state(pdev);
11048 pci_set_power_state(pdev, PCI_D3hot);
11054 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
11055 * @pdev: pointer to PCI device
11057 * This routine is to be called from the kernel's PCI subsystem to support
11058 * system Power Management (PM) to device with SLI-3 interface spec. When PM
11059 * invokes this method, it restores the device's PCI config space state and
11060 * fully reinitializes the device and brings it online. Note that as the
11061 * driver implements the minimum PM requirements to a power-aware driver's
11062 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
11063 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
11064 * driver will fully reinitialize its device during resume() method call,
11065 * the device will be set to PCI_D0 directly in PCI config space before
11066 * restoring the state.
11069 * 0 - driver suspended the device
11073 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
11075 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11076 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11077 uint32_t intr_mode;
11080 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11081 "0452 PCI device Power Management resume.\n");
11083 /* Restore device state from PCI config space */
11084 pci_set_power_state(pdev, PCI_D0);
11085 pci_restore_state(pdev);
11088 * As the new kernel behavior of pci_restore_state() API call clears
11089 * device saved_state flag, need to save the restored state again.
11091 pci_save_state(pdev);
11093 if (pdev->is_busmaster)
11094 pci_set_master(pdev);
11096 /* Startup the kernel thread for this host adapter. */
11097 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11098 "lpfc_worker_%d", phba->brd_no);
11099 if (IS_ERR(phba->worker_thread)) {
11100 error = PTR_ERR(phba->worker_thread);
11101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11102 "0434 PM resume failed to start worker "
11103 "thread: error=x%x.\n", error);
11107 /* Configure and enable interrupt */
11108 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
11109 if (intr_mode == LPFC_INTR_ERROR) {
11110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11111 "0430 PM resume Failed to enable interrupt\n");
11114 phba->intr_mode = intr_mode;
11116 /* Restart HBA and bring it online */
11117 lpfc_sli_brdrestart(phba);
11120 /* Log the current active interrupt mode */
11121 lpfc_log_intr_mode(phba, phba->intr_mode);
11127 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11128 * @phba: pointer to lpfc hba data structure.
11130 * This routine is called to prepare the SLI3 device for PCI slot recover. It
11131 * aborts all the outstanding SCSI I/Os to the pci device.
11134 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11137 "2723 PCI channel I/O abort preparing for recovery\n");
11140 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11141 * and let the SCSI mid-layer to retry them to recover.
11143 lpfc_sli_abort_fcp_rings(phba);
11147 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11148 * @phba: pointer to lpfc hba data structure.
11150 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11151 * disables the device interrupt and pci device, and aborts the internal FCP
11155 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11158 "2710 PCI channel disable preparing for reset\n");
11160 /* Block any management I/Os to the device */
11161 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
11163 /* Block all SCSI devices' I/Os on the host */
11164 lpfc_scsi_dev_block(phba);
11166 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11167 lpfc_sli_flush_fcp_rings(phba);
11169 /* stop all timers */
11170 lpfc_stop_hba_timers(phba);
11172 /* Disable interrupt and pci device */
11173 lpfc_sli_disable_intr(phba);
11174 pci_disable_device(phba->pcidev);
11178 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11179 * @phba: pointer to lpfc hba data structure.
11181 * This routine is called to prepare the SLI3 device for PCI slot permanently
11182 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11186 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11188 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11189 "2711 PCI channel permanent disable for failure\n");
11190 /* Block all SCSI devices' I/Os on the host */
11191 lpfc_scsi_dev_block(phba);
11193 /* stop all timers */
11194 lpfc_stop_hba_timers(phba);
11196 /* Clean up all driver's outstanding SCSI I/Os */
11197 lpfc_sli_flush_fcp_rings(phba);
11201 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
11202 * @pdev: pointer to PCI device.
11203 * @state: the current PCI connection state.
11205 * This routine is called from the PCI subsystem for I/O error handling to
11206 * device with SLI-3 interface spec. This function is called by the PCI
11207 * subsystem after a PCI bus error affecting this device has been detected.
11208 * When this function is invoked, it will need to stop all the I/Os and
11209 * interrupt(s) to the device. Once that is done, it will return
11210 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11214 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
11215 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11216 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11218 static pci_ers_result_t
11219 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
11221 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11222 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11225 case pci_channel_io_normal:
11226 /* Non-fatal error, prepare for recovery */
11227 lpfc_sli_prep_dev_for_recover(phba);
11228 return PCI_ERS_RESULT_CAN_RECOVER;
11229 case pci_channel_io_frozen:
11230 /* Fatal error, prepare for slot reset */
11231 lpfc_sli_prep_dev_for_reset(phba);
11232 return PCI_ERS_RESULT_NEED_RESET;
11233 case pci_channel_io_perm_failure:
11234 /* Permanent failure, prepare for device down */
11235 lpfc_sli_prep_dev_for_perm_failure(phba);
11236 return PCI_ERS_RESULT_DISCONNECT;
11238 /* Unknown state, prepare and request slot reset */
11239 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11240 "0472 Unknown PCI error state: x%x\n", state);
11241 lpfc_sli_prep_dev_for_reset(phba);
11242 return PCI_ERS_RESULT_NEED_RESET;
11247 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
11248 * @pdev: pointer to PCI device.
11250 * This routine is called from the PCI subsystem for error handling to
11251 * device with SLI-3 interface spec. This is called after PCI bus has been
11252 * reset to restart the PCI card from scratch, as if from a cold-boot.
11253 * During the PCI subsystem error recovery, after driver returns
11254 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11255 * recovery and then call this routine before calling the .resume method
11256 * to recover the device. This function will initialize the HBA device,
11257 * enable the interrupt, but it will just put the HBA to offline state
11258 * without passing any I/O traffic.
11261 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11262 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11264 static pci_ers_result_t
11265 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
11267 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11268 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11269 struct lpfc_sli *psli = &phba->sli;
11270 uint32_t intr_mode;
11272 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11273 if (pci_enable_device_mem(pdev)) {
11274 printk(KERN_ERR "lpfc: Cannot re-enable "
11275 "PCI device after reset.\n");
11276 return PCI_ERS_RESULT_DISCONNECT;
11279 pci_restore_state(pdev);
11282 * As the new kernel behavior of pci_restore_state() API call clears
11283 * device saved_state flag, need to save the restored state again.
11285 pci_save_state(pdev);
11287 if (pdev->is_busmaster)
11288 pci_set_master(pdev);
11290 spin_lock_irq(&phba->hbalock);
11291 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11292 spin_unlock_irq(&phba->hbalock);
11294 /* Configure and enable interrupt */
11295 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
11296 if (intr_mode == LPFC_INTR_ERROR) {
11297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11298 "0427 Cannot re-enable interrupt after "
11300 return PCI_ERS_RESULT_DISCONNECT;
11302 phba->intr_mode = intr_mode;
11304 /* Take device offline, it will perform cleanup */
11305 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11306 lpfc_offline(phba);
11307 lpfc_sli_brdrestart(phba);
11309 /* Log the current active interrupt mode */
11310 lpfc_log_intr_mode(phba, phba->intr_mode);
11312 return PCI_ERS_RESULT_RECOVERED;
11316 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
11317 * @pdev: pointer to PCI device
11319 * This routine is called from the PCI subsystem for error handling to device
11320 * with SLI-3 interface spec. It is called when kernel error recovery tells
11321 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11322 * error recovery. After this call, traffic can start to flow from this device
11326 lpfc_io_resume_s3(struct pci_dev *pdev)
11328 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11329 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11331 /* Bring device online, it will be no-op for non-fatal error resume */
11334 /* Clean up Advanced Error Reporting (AER) if needed */
11335 if (phba->hba_flag & HBA_AER_ENABLED)
11336 pci_cleanup_aer_uncorrect_error_status(pdev);
11340 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11341 * @phba: pointer to lpfc hba data structure.
11343 * returns the number of ELS/CT IOCBs to reserve
11346 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11348 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11350 if (phba->sli_rev == LPFC_SLI_REV4) {
11351 if (max_xri <= 100)
11353 else if (max_xri <= 256)
11355 else if (max_xri <= 512)
11357 else if (max_xri <= 1024)
11359 else if (max_xri <= 1536)
11361 else if (max_xri <= 2048)
11370 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11371 * @phba: pointer to lpfc hba data structure.
11373 * returns the number of ELS/CT + NVMET IOCBs to reserve
11376 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11378 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11380 if (phba->nvmet_support)
11381 max_xri += LPFC_NVMET_BUF_POST;
11387 lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11388 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11389 const struct firmware *fw)
11391 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11392 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11393 magic_number != MAGIC_NUMER_G6) ||
11394 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11395 magic_number != MAGIC_NUMER_G7))
11396 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11397 "3030 This firmware version is not supported on "
11398 "this HBA model. Device:%x Magic:%x Type:%x "
11399 "ID:%x Size %d %zd\n",
11400 phba->pcidev->device, magic_number, ftype, fid,
11403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11404 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11405 "ID:%x Size %d %zd\n",
11406 phba->pcidev->device, magic_number, ftype, fid,
11412 * lpfc_write_firmware - attempt to write a firmware image to the port
11413 * @fw: pointer to firmware image returned from request_firmware.
11414 * @phba: pointer to lpfc hba data structure.
11418 lpfc_write_firmware(const struct firmware *fw, void *context)
11420 struct lpfc_hba *phba = (struct lpfc_hba *)context;
11421 char fwrev[FW_REV_STR_SIZE];
11422 struct lpfc_grp_hdr *image;
11423 struct list_head dma_buffer_list;
11425 struct lpfc_dmabuf *dmabuf, *next;
11426 uint32_t offset = 0, temp_offset = 0;
11427 uint32_t magic_number, ftype, fid, fsize;
11429 /* It can be null in no-wait mode, sanity check */
11434 image = (struct lpfc_grp_hdr *)fw->data;
11436 magic_number = be32_to_cpu(image->magic_number);
11437 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
11438 fid = bf_get_be32(lpfc_grp_hdr_id, image);
11439 fsize = be32_to_cpu(image->size);
11441 INIT_LIST_HEAD(&dma_buffer_list);
11442 lpfc_decode_firmware_rev(phba, fwrev, 1);
11443 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
11444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11445 "3023 Updating Firmware, Current Version:%s "
11446 "New Version:%s\n",
11447 fwrev, image->revision);
11448 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11449 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11455 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11459 if (!dmabuf->virt) {
11464 list_add_tail(&dmabuf->list, &dma_buffer_list);
11466 while (offset < fw->size) {
11467 temp_offset = offset;
11468 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
11469 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
11470 memcpy(dmabuf->virt,
11471 fw->data + temp_offset,
11472 fw->size - temp_offset);
11473 temp_offset = fw->size;
11476 memcpy(dmabuf->virt, fw->data + temp_offset,
11478 temp_offset += SLI4_PAGE_SIZE;
11480 rc = lpfc_wr_object(phba, &dma_buffer_list,
11481 (fw->size - offset), &offset);
11483 lpfc_log_write_firmware_error(phba, offset,
11484 magic_number, ftype, fid, fsize, fw);
11490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11491 "3029 Skipped Firmware update, Current "
11492 "Version:%s New Version:%s\n",
11493 fwrev, image->revision);
11496 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11497 list_del(&dmabuf->list);
11498 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11499 dmabuf->virt, dmabuf->phys);
11502 release_firmware(fw);
11504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11505 "3024 Firmware update done: %d.\n", rc);
11510 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11511 * @phba: pointer to lpfc hba data structure.
11513 * This routine is called to perform Linux generic firmware upgrade on device
11514 * that supports such feature.
11517 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11519 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11521 const struct firmware *fw;
11523 /* Only supported on SLI4 interface type 2 for now */
11524 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
11525 LPFC_SLI_INTF_IF_TYPE_2)
11528 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11530 if (fw_upgrade == INT_FW_UPGRADE) {
11531 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11532 file_name, &phba->pcidev->dev,
11533 GFP_KERNEL, (void *)phba,
11534 lpfc_write_firmware);
11535 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11536 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11538 lpfc_write_firmware(fw, (void *)phba);
11547 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11548 * @pdev: pointer to PCI device
11549 * @pid: pointer to PCI device identifier
11551 * This routine is called from the kernel's PCI subsystem to device with
11552 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11553 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11554 * information of the device and driver to see if the driver state that it
11555 * can support this kind of device. If the match is successful, the driver
11556 * core invokes this routine. If this routine determines it can claim the HBA,
11557 * it does all the initialization that it needs to do to handle the HBA
11561 * 0 - driver can claim the device
11562 * negative value - driver can not claim the device
11565 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11567 struct lpfc_hba *phba;
11568 struct lpfc_vport *vport = NULL;
11569 struct Scsi_Host *shost = NULL;
11571 uint32_t cfg_mode, intr_mode;
11573 /* Allocate memory for HBA structure */
11574 phba = lpfc_hba_alloc(pdev);
11578 /* Perform generic PCI device enabling operation */
11579 error = lpfc_enable_pci_dev(phba);
11581 goto out_free_phba;
11583 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11584 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11586 goto out_disable_pci_dev;
11588 /* Set up SLI-4 specific device PCI memory space */
11589 error = lpfc_sli4_pci_mem_setup(phba);
11591 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11592 "1410 Failed to set up pci memory space.\n");
11593 goto out_disable_pci_dev;
11596 /* Set up SLI-4 Specific device driver resources */
11597 error = lpfc_sli4_driver_resource_setup(phba);
11599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11600 "1412 Failed to set up driver resource.\n");
11601 goto out_unset_pci_mem_s4;
11604 INIT_LIST_HEAD(&phba->active_rrq_list);
11605 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
11607 /* Set up common device driver resources */
11608 error = lpfc_setup_driver_resource_phase2(phba);
11610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11611 "1414 Failed to set up driver resource.\n");
11612 goto out_unset_driver_resource_s4;
11615 /* Get the default values for Model Name and Description */
11616 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11618 /* Create SCSI host to the physical port */
11619 error = lpfc_create_shost(phba);
11621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11622 "1415 Failed to create scsi host.\n");
11623 goto out_unset_driver_resource;
11626 /* Configure sysfs attributes */
11627 vport = phba->pport;
11628 error = lpfc_alloc_sysfs_attr(vport);
11630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11631 "1416 Failed to allocate sysfs attr\n");
11632 goto out_destroy_shost;
11635 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
11636 /* Now, trying to enable interrupt and bring up the device */
11637 cfg_mode = phba->cfg_use_msi;
11639 /* Put device to a known state before enabling interrupt */
11640 lpfc_stop_port(phba);
11642 /* Configure and enable interrupt */
11643 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11644 if (intr_mode == LPFC_INTR_ERROR) {
11645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11646 "0426 Failed to enable interrupt.\n");
11648 goto out_free_sysfs_attr;
11650 /* Default to single EQ for non-MSI-X */
11651 if (phba->intr_type != MSIX) {
11652 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11653 phba->cfg_fcp_io_channel = 1;
11654 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11655 phba->cfg_nvme_io_channel = 1;
11656 if (phba->nvmet_support)
11657 phba->cfg_nvmet_mrq = 1;
11659 phba->io_channel_irqs = 1;
11662 /* Set up SLI-4 HBA */
11663 if (lpfc_sli4_hba_setup(phba)) {
11664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11665 "1421 Failed to set up hba\n");
11667 goto out_disable_intr;
11670 /* Log the current active interrupt mode */
11671 phba->intr_mode = intr_mode;
11672 lpfc_log_intr_mode(phba, intr_mode);
11674 /* Perform post initialization setup */
11675 lpfc_post_init_setup(phba);
11677 /* NVME support in FW earlier in the driver load corrects the
11678 * FC4 type making a check for nvme_support unnecessary.
11680 if ((phba->nvmet_support == 0) &&
11681 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11682 /* Create NVME binding with nvme_fc_transport. This
11683 * ensures the vport is initialized. If the localport
11684 * create fails, it should not unload the driver to
11685 * support field issues.
11687 error = lpfc_nvme_create_localport(vport);
11689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11690 "6004 NVME registration failed, "
11696 /* check for firmware upgrade or downgrade */
11697 if (phba->cfg_request_firmware_upgrade)
11698 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
11700 /* Check if there are static vports to be created. */
11701 lpfc_create_static_vport(phba);
11705 lpfc_sli4_disable_intr(phba);
11706 out_free_sysfs_attr:
11707 lpfc_free_sysfs_attr(vport);
11709 lpfc_destroy_shost(phba);
11710 out_unset_driver_resource:
11711 lpfc_unset_driver_resource_phase2(phba);
11712 out_unset_driver_resource_s4:
11713 lpfc_sli4_driver_resource_unset(phba);
11714 out_unset_pci_mem_s4:
11715 lpfc_sli4_pci_mem_unset(phba);
11716 out_disable_pci_dev:
11717 lpfc_disable_pci_dev(phba);
11719 scsi_host_put(shost);
11721 lpfc_hba_free(phba);
11726 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11727 * @pdev: pointer to PCI device
11729 * This routine is called from the kernel's PCI subsystem to device with
11730 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11731 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11732 * device to be removed from the PCI subsystem properly.
11735 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11737 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11738 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11739 struct lpfc_vport **vports;
11740 struct lpfc_hba *phba = vport->phba;
11743 /* Mark the device unloading flag */
11744 spin_lock_irq(&phba->hbalock);
11745 vport->load_flag |= FC_UNLOADING;
11746 spin_unlock_irq(&phba->hbalock);
11748 /* Free the HBA sysfs attributes */
11749 lpfc_free_sysfs_attr(vport);
11751 /* Release all the vports against this physical port */
11752 vports = lpfc_create_vport_work_array(phba);
11753 if (vports != NULL)
11754 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11755 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11757 fc_vport_terminate(vports[i]->fc_vport);
11759 lpfc_destroy_vport_work_array(phba, vports);
11761 /* Remove FC host and then SCSI host with the physical port */
11762 fc_remove_host(shost);
11763 scsi_remove_host(shost);
11765 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11766 * localports are destroyed after to cleanup all transport memory.
11768 lpfc_cleanup(vport);
11769 lpfc_nvmet_destroy_targetport(phba);
11770 lpfc_nvme_destroy_localport(vport);
11773 * Bring down the SLI Layer. This step disables all interrupts,
11774 * clears the rings, discards all mailbox commands, and resets
11775 * the HBA FCoE function.
11777 lpfc_debugfs_terminate(vport);
11778 lpfc_sli4_hba_unset(phba);
11780 lpfc_stop_hba_timers(phba);
11781 spin_lock_irq(&phba->hbalock);
11782 list_del_init(&vport->listentry);
11783 spin_unlock_irq(&phba->hbalock);
11785 /* Perform scsi free before driver resource_unset since scsi
11786 * buffers are released to their corresponding pools here.
11788 lpfc_scsi_free(phba);
11789 lpfc_nvme_free(phba);
11790 lpfc_free_iocb_list(phba);
11792 lpfc_unset_driver_resource_phase2(phba);
11793 lpfc_sli4_driver_resource_unset(phba);
11795 /* Unmap adapter Control and Doorbell registers */
11796 lpfc_sli4_pci_mem_unset(phba);
11798 /* Release PCI resources and disable device's PCI function */
11799 scsi_host_put(shost);
11800 lpfc_disable_pci_dev(phba);
11802 /* Finally, free the driver's device data structure */
11803 lpfc_hba_free(phba);
11809 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11810 * @pdev: pointer to PCI device
11811 * @msg: power management message
11813 * This routine is called from the kernel's PCI subsystem to support system
11814 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11815 * this method, it quiesces the device by stopping the driver's worker
11816 * thread for the device, turning off device's interrupt and DMA, and bring
11817 * the device offline. Note that as the driver implements the minimum PM
11818 * requirements to a power-aware driver's PM support for suspend/resume -- all
11819 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11820 * method call will be treated as SUSPEND and the driver will fully
11821 * reinitialize its device during resume() method call, the driver will set
11822 * device to PCI_D3hot state in PCI config space instead of setting it
11823 * according to the @msg provided by the PM.
11826 * 0 - driver suspended the device
11830 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11832 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11833 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11835 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11836 "2843 PCI device Power Management suspend.\n");
11838 /* Bring down the device */
11839 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11840 lpfc_offline(phba);
11841 kthread_stop(phba->worker_thread);
11843 /* Disable interrupt from device */
11844 lpfc_sli4_disable_intr(phba);
11845 lpfc_sli4_queue_destroy(phba);
11847 /* Save device state to PCI config space */
11848 pci_save_state(pdev);
11849 pci_set_power_state(pdev, PCI_D3hot);
11855 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11856 * @pdev: pointer to PCI device
11858 * This routine is called from the kernel's PCI subsystem to support system
11859 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11860 * this method, it restores the device's PCI config space state and fully
11861 * reinitializes the device and brings it online. Note that as the driver
11862 * implements the minimum PM requirements to a power-aware driver's PM for
11863 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11864 * to the suspend() method call will be treated as SUSPEND and the driver
11865 * will fully reinitialize its device during resume() method call, the device
11866 * will be set to PCI_D0 directly in PCI config space before restoring the
11870 * 0 - driver suspended the device
11874 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11876 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11877 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11878 uint32_t intr_mode;
11881 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11882 "0292 PCI device Power Management resume.\n");
11884 /* Restore device state from PCI config space */
11885 pci_set_power_state(pdev, PCI_D0);
11886 pci_restore_state(pdev);
11889 * As the new kernel behavior of pci_restore_state() API call clears
11890 * device saved_state flag, need to save the restored state again.
11892 pci_save_state(pdev);
11894 if (pdev->is_busmaster)
11895 pci_set_master(pdev);
11897 /* Startup the kernel thread for this host adapter. */
11898 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11899 "lpfc_worker_%d", phba->brd_no);
11900 if (IS_ERR(phba->worker_thread)) {
11901 error = PTR_ERR(phba->worker_thread);
11902 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11903 "0293 PM resume failed to start worker "
11904 "thread: error=x%x.\n", error);
11908 /* Configure and enable interrupt */
11909 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11910 if (intr_mode == LPFC_INTR_ERROR) {
11911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11912 "0294 PM resume Failed to enable interrupt\n");
11915 phba->intr_mode = intr_mode;
11917 /* Restart HBA and bring it online */
11918 lpfc_sli_brdrestart(phba);
11921 /* Log the current active interrupt mode */
11922 lpfc_log_intr_mode(phba, phba->intr_mode);
11928 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11929 * @phba: pointer to lpfc hba data structure.
11931 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11932 * aborts all the outstanding SCSI I/Os to the pci device.
11935 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11938 "2828 PCI channel I/O abort preparing for recovery\n");
11940 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11941 * and let the SCSI mid-layer to retry them to recover.
11943 lpfc_sli_abort_fcp_rings(phba);
11947 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11948 * @phba: pointer to lpfc hba data structure.
11950 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11951 * disables the device interrupt and pci device, and aborts the internal FCP
11955 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11957 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11958 "2826 PCI channel disable preparing for reset\n");
11960 /* Block any management I/Os to the device */
11961 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
11963 /* Block all SCSI devices' I/Os on the host */
11964 lpfc_scsi_dev_block(phba);
11966 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11967 lpfc_sli_flush_fcp_rings(phba);
11969 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11970 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11971 lpfc_sli_flush_nvme_rings(phba);
11973 /* stop all timers */
11974 lpfc_stop_hba_timers(phba);
11976 /* Disable interrupt and pci device */
11977 lpfc_sli4_disable_intr(phba);
11978 lpfc_sli4_queue_destroy(phba);
11979 pci_disable_device(phba->pcidev);
11983 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11984 * @phba: pointer to lpfc hba data structure.
11986 * This routine is called to prepare the SLI4 device for PCI slot permanently
11987 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11991 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11994 "2827 PCI channel permanent disable for failure\n");
11996 /* Block all SCSI devices' I/Os on the host */
11997 lpfc_scsi_dev_block(phba);
11999 /* stop all timers */
12000 lpfc_stop_hba_timers(phba);
12002 /* Clean up all driver's outstanding SCSI I/Os */
12003 lpfc_sli_flush_fcp_rings(phba);
12005 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12006 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12007 lpfc_sli_flush_nvme_rings(phba);
12011 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12012 * @pdev: pointer to PCI device.
12013 * @state: the current PCI connection state.
12015 * This routine is called from the PCI subsystem for error handling to device
12016 * with SLI-4 interface spec. This function is called by the PCI subsystem
12017 * after a PCI bus error affecting this device has been detected. When this
12018 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12019 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12020 * for the PCI subsystem to perform proper recovery as desired.
12023 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12024 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12026 static pci_ers_result_t
12027 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
12029 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12030 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12033 case pci_channel_io_normal:
12034 /* Non-fatal error, prepare for recovery */
12035 lpfc_sli4_prep_dev_for_recover(phba);
12036 return PCI_ERS_RESULT_CAN_RECOVER;
12037 case pci_channel_io_frozen:
12038 /* Fatal error, prepare for slot reset */
12039 lpfc_sli4_prep_dev_for_reset(phba);
12040 return PCI_ERS_RESULT_NEED_RESET;
12041 case pci_channel_io_perm_failure:
12042 /* Permanent failure, prepare for device down */
12043 lpfc_sli4_prep_dev_for_perm_failure(phba);
12044 return PCI_ERS_RESULT_DISCONNECT;
12046 /* Unknown state, prepare and request slot reset */
12047 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12048 "2825 Unknown PCI error state: x%x\n", state);
12049 lpfc_sli4_prep_dev_for_reset(phba);
12050 return PCI_ERS_RESULT_NEED_RESET;
12055 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
12056 * @pdev: pointer to PCI device.
12058 * This routine is called from the PCI subsystem for error handling to device
12059 * with SLI-4 interface spec. It is called after PCI bus has been reset to
12060 * restart the PCI card from scratch, as if from a cold-boot. During the
12061 * PCI subsystem error recovery, after the driver returns
12062 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12063 * recovery and then call this routine before calling the .resume method to
12064 * recover the device. This function will initialize the HBA device, enable
12065 * the interrupt, but it will just put the HBA to offline state without
12066 * passing any I/O traffic.
12069 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12070 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12072 static pci_ers_result_t
12073 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
12075 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12076 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12077 struct lpfc_sli *psli = &phba->sli;
12078 uint32_t intr_mode;
12080 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12081 if (pci_enable_device_mem(pdev)) {
12082 printk(KERN_ERR "lpfc: Cannot re-enable "
12083 "PCI device after reset.\n");
12084 return PCI_ERS_RESULT_DISCONNECT;
12087 pci_restore_state(pdev);
12090 * As the new kernel behavior of pci_restore_state() API call clears
12091 * device saved_state flag, need to save the restored state again.
12093 pci_save_state(pdev);
12095 if (pdev->is_busmaster)
12096 pci_set_master(pdev);
12098 spin_lock_irq(&phba->hbalock);
12099 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12100 spin_unlock_irq(&phba->hbalock);
12102 /* Configure and enable interrupt */
12103 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12104 if (intr_mode == LPFC_INTR_ERROR) {
12105 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12106 "2824 Cannot re-enable interrupt after "
12108 return PCI_ERS_RESULT_DISCONNECT;
12110 phba->intr_mode = intr_mode;
12112 /* Log the current active interrupt mode */
12113 lpfc_log_intr_mode(phba, phba->intr_mode);
12115 return PCI_ERS_RESULT_RECOVERED;
12119 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12120 * @pdev: pointer to PCI device
12122 * This routine is called from the PCI subsystem for error handling to device
12123 * with SLI-4 interface spec. It is called when kernel error recovery tells
12124 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12125 * error recovery. After this call, traffic can start to flow from this device
12129 lpfc_io_resume_s4(struct pci_dev *pdev)
12131 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12132 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12135 * In case of slot reset, as function reset is performed through
12136 * mailbox command which needs DMA to be enabled, this operation
12137 * has to be moved to the io resume phase. Taking device offline
12138 * will perform the necessary cleanup.
12140 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12141 /* Perform device reset */
12142 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
12143 lpfc_offline(phba);
12144 lpfc_sli_brdrestart(phba);
12145 /* Bring the device back online */
12149 /* Clean up Advanced Error Reporting (AER) if needed */
12150 if (phba->hba_flag & HBA_AER_ENABLED)
12151 pci_cleanup_aer_uncorrect_error_status(pdev);
12155 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12156 * @pdev: pointer to PCI device
12157 * @pid: pointer to PCI device identifier
12159 * This routine is to be registered to the kernel's PCI subsystem. When an
12160 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12161 * at PCI device-specific information of the device and driver to see if the
12162 * driver state that it can support this kind of device. If the match is
12163 * successful, the driver core invokes this routine. This routine dispatches
12164 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12165 * do all the initialization that it needs to do to handle the HBA device
12169 * 0 - driver can claim the device
12170 * negative value - driver can not claim the device
12173 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12176 struct lpfc_sli_intf intf;
12178 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
12181 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
12182 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
12183 rc = lpfc_pci_probe_one_s4(pdev, pid);
12185 rc = lpfc_pci_probe_one_s3(pdev, pid);
12191 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12192 * @pdev: pointer to PCI device
12194 * This routine is to be registered to the kernel's PCI subsystem. When an
12195 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12196 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12197 * remove routine, which will perform all the necessary cleanup for the
12198 * device to be removed from the PCI subsystem properly.
12201 lpfc_pci_remove_one(struct pci_dev *pdev)
12203 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12204 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12206 switch (phba->pci_dev_grp) {
12207 case LPFC_PCI_DEV_LP:
12208 lpfc_pci_remove_one_s3(pdev);
12210 case LPFC_PCI_DEV_OC:
12211 lpfc_pci_remove_one_s4(pdev);
12214 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12215 "1424 Invalid PCI device group: 0x%x\n",
12216 phba->pci_dev_grp);
12223 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12224 * @pdev: pointer to PCI device
12225 * @msg: power management message
12227 * This routine is to be registered to the kernel's PCI subsystem to support
12228 * system Power Management (PM). When PM invokes this method, it dispatches
12229 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12230 * suspend the device.
12233 * 0 - driver suspended the device
12237 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12239 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12240 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12243 switch (phba->pci_dev_grp) {
12244 case LPFC_PCI_DEV_LP:
12245 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12247 case LPFC_PCI_DEV_OC:
12248 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12251 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12252 "1425 Invalid PCI device group: 0x%x\n",
12253 phba->pci_dev_grp);
12260 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12261 * @pdev: pointer to PCI device
12263 * This routine is to be registered to the kernel's PCI subsystem to support
12264 * system Power Management (PM). When PM invokes this method, it dispatches
12265 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12266 * resume the device.
12269 * 0 - driver suspended the device
12273 lpfc_pci_resume_one(struct pci_dev *pdev)
12275 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12276 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12279 switch (phba->pci_dev_grp) {
12280 case LPFC_PCI_DEV_LP:
12281 rc = lpfc_pci_resume_one_s3(pdev);
12283 case LPFC_PCI_DEV_OC:
12284 rc = lpfc_pci_resume_one_s4(pdev);
12287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12288 "1426 Invalid PCI device group: 0x%x\n",
12289 phba->pci_dev_grp);
12296 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12297 * @pdev: pointer to PCI device.
12298 * @state: the current PCI connection state.
12300 * This routine is registered to the PCI subsystem for error handling. This
12301 * function is called by the PCI subsystem after a PCI bus error affecting
12302 * this device has been detected. When this routine is invoked, it dispatches
12303 * the action to the proper SLI-3 or SLI-4 device error detected handling
12304 * routine, which will perform the proper error detected operation.
12307 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12308 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12310 static pci_ers_result_t
12311 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12313 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12314 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12315 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12317 switch (phba->pci_dev_grp) {
12318 case LPFC_PCI_DEV_LP:
12319 rc = lpfc_io_error_detected_s3(pdev, state);
12321 case LPFC_PCI_DEV_OC:
12322 rc = lpfc_io_error_detected_s4(pdev, state);
12325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12326 "1427 Invalid PCI device group: 0x%x\n",
12327 phba->pci_dev_grp);
12334 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12335 * @pdev: pointer to PCI device.
12337 * This routine is registered to the PCI subsystem for error handling. This
12338 * function is called after PCI bus has been reset to restart the PCI card
12339 * from scratch, as if from a cold-boot. When this routine is invoked, it
12340 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12341 * routine, which will perform the proper device reset.
12344 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12345 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12347 static pci_ers_result_t
12348 lpfc_io_slot_reset(struct pci_dev *pdev)
12350 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12351 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12352 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12354 switch (phba->pci_dev_grp) {
12355 case LPFC_PCI_DEV_LP:
12356 rc = lpfc_io_slot_reset_s3(pdev);
12358 case LPFC_PCI_DEV_OC:
12359 rc = lpfc_io_slot_reset_s4(pdev);
12362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12363 "1428 Invalid PCI device group: 0x%x\n",
12364 phba->pci_dev_grp);
12371 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12372 * @pdev: pointer to PCI device
12374 * This routine is registered to the PCI subsystem for error handling. It
12375 * is called when kernel error recovery tells the lpfc driver that it is
12376 * OK to resume normal PCI operation after PCI bus error recovery. When
12377 * this routine is invoked, it dispatches the action to the proper SLI-3
12378 * or SLI-4 device io_resume routine, which will resume the device operation.
12381 lpfc_io_resume(struct pci_dev *pdev)
12383 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12384 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12386 switch (phba->pci_dev_grp) {
12387 case LPFC_PCI_DEV_LP:
12388 lpfc_io_resume_s3(pdev);
12390 case LPFC_PCI_DEV_OC:
12391 lpfc_io_resume_s4(pdev);
12394 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12395 "1429 Invalid PCI device group: 0x%x\n",
12396 phba->pci_dev_grp);
12403 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12404 * @phba: pointer to lpfc hba data structure.
12406 * This routine checks to see if OAS is supported for this adapter. If
12407 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12408 * the enable oas flag is cleared and the pool created for OAS device data
12413 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12416 if (!phba->cfg_EnableXLane)
12419 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12423 if (phba->device_data_mem_pool)
12424 mempool_destroy(phba->device_data_mem_pool);
12425 phba->device_data_mem_pool = NULL;
12432 * lpfc_fof_queue_setup - Set up all the fof queues
12433 * @phba: pointer to lpfc hba data structure.
12435 * This routine is invoked to set up all the fof queues for the FC HBA
12440 * -ENOMEM - No available memory
12443 lpfc_fof_queue_setup(struct lpfc_hba *phba)
12445 struct lpfc_sli_ring *pring;
12448 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12452 if (phba->cfg_fof) {
12454 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12455 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12459 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12460 phba->sli4_hba.oas_cq, LPFC_FCP);
12464 /* Bind this CQ/WQ to the NVME ring */
12465 pring = phba->sli4_hba.oas_wq->pring;
12466 pring->sli.sli4.wqp =
12467 (void *)phba->sli4_hba.oas_wq;
12468 phba->sli4_hba.oas_cq->pring = pring;
12474 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
12476 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12482 * lpfc_fof_queue_create - Create all the fof queues
12483 * @phba: pointer to lpfc hba data structure.
12485 * This routine is invoked to allocate all the fof queues for the FC HBA
12486 * operation. For each SLI4 queue type, the parameters such as queue entry
12487 * count (queue depth) shall be taken from the module parameter. For now,
12488 * we just use some constant number as place holder.
12492 * -ENOMEM - No availble memory
12493 * -EIO - The mailbox failed to complete successfully.
12496 lpfc_fof_queue_create(struct lpfc_hba *phba)
12498 struct lpfc_queue *qdesc;
12501 /* Create FOF EQ */
12502 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12503 phba->sli4_hba.eq_esize,
12504 phba->sli4_hba.eq_ecount);
12508 qdesc->qe_valid = 1;
12509 phba->sli4_hba.fof_eq = qdesc;
12511 if (phba->cfg_fof) {
12513 /* Create OAS CQ */
12514 if (phba->enab_exp_wqcq_pages)
12515 qdesc = lpfc_sli4_queue_alloc(phba,
12516 LPFC_EXPANDED_PAGE_SIZE,
12517 phba->sli4_hba.cq_esize,
12518 LPFC_CQE_EXP_COUNT);
12520 qdesc = lpfc_sli4_queue_alloc(phba,
12521 LPFC_DEFAULT_PAGE_SIZE,
12522 phba->sli4_hba.cq_esize,
12523 phba->sli4_hba.cq_ecount);
12527 qdesc->qe_valid = 1;
12528 phba->sli4_hba.oas_cq = qdesc;
12530 /* Create OAS WQ */
12531 if (phba->enab_exp_wqcq_pages) {
12532 wqesize = (phba->fcp_embed_io) ?
12533 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
12534 qdesc = lpfc_sli4_queue_alloc(phba,
12535 LPFC_EXPANDED_PAGE_SIZE,
12537 LPFC_WQE_EXP_COUNT);
12539 qdesc = lpfc_sli4_queue_alloc(phba,
12540 LPFC_DEFAULT_PAGE_SIZE,
12541 phba->sli4_hba.wq_esize,
12542 phba->sli4_hba.wq_ecount);
12547 phba->sli4_hba.oas_wq = qdesc;
12548 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
12554 lpfc_fof_queue_destroy(phba);
12559 * lpfc_fof_queue_destroy - Destroy all the fof queues
12560 * @phba: pointer to lpfc hba data structure.
12562 * This routine is invoked to release all the SLI4 queues with the FC HBA
12569 lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12571 /* Release FOF Event queue */
12572 if (phba->sli4_hba.fof_eq != NULL) {
12573 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12574 phba->sli4_hba.fof_eq = NULL;
12577 /* Release OAS Completion queue */
12578 if (phba->sli4_hba.oas_cq != NULL) {
12579 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12580 phba->sli4_hba.oas_cq = NULL;
12583 /* Release OAS Work queue */
12584 if (phba->sli4_hba.oas_wq != NULL) {
12585 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12586 phba->sli4_hba.oas_wq = NULL;
12591 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12593 static const struct pci_error_handlers lpfc_err_handler = {
12594 .error_detected = lpfc_io_error_detected,
12595 .slot_reset = lpfc_io_slot_reset,
12596 .resume = lpfc_io_resume,
12599 static struct pci_driver lpfc_driver = {
12600 .name = LPFC_DRIVER_NAME,
12601 .id_table = lpfc_id_table,
12602 .probe = lpfc_pci_probe_one,
12603 .remove = lpfc_pci_remove_one,
12604 .shutdown = lpfc_pci_remove_one,
12605 .suspend = lpfc_pci_suspend_one,
12606 .resume = lpfc_pci_resume_one,
12607 .err_handler = &lpfc_err_handler,
12610 static const struct file_operations lpfc_mgmt_fop = {
12611 .owner = THIS_MODULE,
12614 static struct miscdevice lpfc_mgmt_dev = {
12615 .minor = MISC_DYNAMIC_MINOR,
12616 .name = "lpfcmgmt",
12617 .fops = &lpfc_mgmt_fop,
12621 * lpfc_init - lpfc module initialization routine
12623 * This routine is to be invoked when the lpfc module is loaded into the
12624 * kernel. The special kernel macro module_init() is used to indicate the
12625 * role of this routine to the kernel as lpfc module entry point.
12629 * -ENOMEM - FC attach transport failed
12630 * all others - failed
12637 printk(LPFC_MODULE_DESC "\n");
12638 printk(LPFC_COPYRIGHT "\n");
12640 error = misc_register(&lpfc_mgmt_dev);
12642 printk(KERN_ERR "Could not register lpfcmgmt device, "
12643 "misc_register returned with status %d", error);
12645 lpfc_transport_functions.vport_create = lpfc_vport_create;
12646 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
12647 lpfc_transport_template =
12648 fc_attach_transport(&lpfc_transport_functions);
12649 if (lpfc_transport_template == NULL)
12651 lpfc_vport_transport_template =
12652 fc_attach_transport(&lpfc_vport_transport_functions);
12653 if (lpfc_vport_transport_template == NULL) {
12654 fc_release_transport(lpfc_transport_template);
12657 lpfc_nvme_cmd_template();
12658 lpfc_nvmet_cmd_template();
12660 /* Initialize in case vector mapping is needed */
12661 lpfc_used_cpu = NULL;
12662 lpfc_present_cpu = num_present_cpus();
12664 error = pci_register_driver(&lpfc_driver);
12666 fc_release_transport(lpfc_transport_template);
12667 fc_release_transport(lpfc_vport_transport_template);
12674 * lpfc_exit - lpfc module removal routine
12676 * This routine is invoked when the lpfc module is removed from the kernel.
12677 * The special kernel macro module_exit() is used to indicate the role of
12678 * this routine to the kernel as lpfc module exit point.
12683 misc_deregister(&lpfc_mgmt_dev);
12684 pci_unregister_driver(&lpfc_driver);
12685 fc_release_transport(lpfc_transport_template);
12686 fc_release_transport(lpfc_vport_transport_template);
12687 if (_dump_buf_data) {
12688 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12689 "_dump_buf_data at 0x%p\n",
12690 (1L << _dump_buf_data_order), _dump_buf_data);
12691 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12694 if (_dump_buf_dif) {
12695 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12696 "_dump_buf_dif at 0x%p\n",
12697 (1L << _dump_buf_dif_order), _dump_buf_dif);
12698 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12700 kfree(lpfc_used_cpu);
12701 idr_destroy(&lpfc_hba_index);
12704 module_init(lpfc_init);
12705 module_exit(lpfc_exit);
12706 MODULE_LICENSE("GPL");
12707 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
12708 MODULE_AUTHOR("Broadcom");
12709 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);