1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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 /* Reset link speed to auto */
736 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
737 "1302 Invalid speed for this board:%d "
738 "Reset link speed to auto.\n",
739 phba->cfg_link_speed);
740 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
742 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
743 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
744 if (phba->sli_rev < LPFC_SLI_REV4)
745 lpfc_set_loopback_flag(phba);
746 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
747 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
749 "0498 Adapter failed to init, mbxCmd x%x "
750 "INIT_LINK, mbxStatus x%x\n",
751 mb->mbxCommand, mb->mbxStatus);
752 if (phba->sli_rev <= LPFC_SLI_REV3) {
753 /* Clear all interrupt enable conditions */
754 writel(0, phba->HCregaddr);
755 readl(phba->HCregaddr); /* flush */
756 /* Clear all pending interrupts */
757 writel(0xffffffff, phba->HAregaddr);
758 readl(phba->HAregaddr); /* flush */
760 phba->link_state = LPFC_HBA_ERROR;
761 if (rc != MBX_BUSY || flag == MBX_POLL)
762 mempool_free(pmb, phba->mbox_mem_pool);
765 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
766 if (flag == MBX_POLL)
767 mempool_free(pmb, phba->mbox_mem_pool);
773 * lpfc_hba_down_link - this routine downs the FC link
774 * @phba: pointer to lpfc hba data structure.
775 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
777 * This routine will issue the DOWN_LINK mailbox command call.
778 * It is available to other drivers through the lpfc_hba data
779 * structure for use to stop the link.
783 * Any other value - error
786 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
791 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
793 phba->link_state = LPFC_HBA_ERROR;
797 lpfc_printf_log(phba,
799 "0491 Adapter Link is disabled.\n");
800 lpfc_down_link(phba, pmb);
801 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
802 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
803 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
804 lpfc_printf_log(phba,
806 "2522 Adapter failed to issue DOWN_LINK"
807 " mbox command rc 0x%x\n", rc);
809 mempool_free(pmb, phba->mbox_mem_pool);
812 if (flag == MBX_POLL)
813 mempool_free(pmb, phba->mbox_mem_pool);
819 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
820 * @phba: pointer to lpfc HBA data structure.
822 * This routine will do LPFC uninitialization before the HBA is reset when
823 * bringing down the SLI Layer.
827 * Any other value - error.
830 lpfc_hba_down_prep(struct lpfc_hba *phba)
832 struct lpfc_vport **vports;
835 if (phba->sli_rev <= LPFC_SLI_REV3) {
836 /* Disable interrupts */
837 writel(0, phba->HCregaddr);
838 readl(phba->HCregaddr); /* flush */
841 if (phba->pport->load_flag & FC_UNLOADING)
842 lpfc_cleanup_discovery_resources(phba->pport);
844 vports = lpfc_create_vport_work_array(phba);
846 for (i = 0; i <= phba->max_vports &&
847 vports[i] != NULL; i++)
848 lpfc_cleanup_discovery_resources(vports[i]);
849 lpfc_destroy_vport_work_array(phba, vports);
855 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
856 * rspiocb which got deferred
858 * @phba: pointer to lpfc HBA data structure.
860 * This routine will cleanup completed slow path events after HBA is reset
861 * when bringing down the SLI Layer.
868 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
870 struct lpfc_iocbq *rspiocbq;
871 struct hbq_dmabuf *dmabuf;
872 struct lpfc_cq_event *cq_event;
874 spin_lock_irq(&phba->hbalock);
875 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
876 spin_unlock_irq(&phba->hbalock);
878 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
879 /* Get the response iocb from the head of work queue */
880 spin_lock_irq(&phba->hbalock);
881 list_remove_head(&phba->sli4_hba.sp_queue_event,
882 cq_event, struct lpfc_cq_event, list);
883 spin_unlock_irq(&phba->hbalock);
885 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
886 case CQE_CODE_COMPL_WQE:
887 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
889 lpfc_sli_release_iocbq(phba, rspiocbq);
891 case CQE_CODE_RECEIVE:
892 case CQE_CODE_RECEIVE_V1:
893 dmabuf = container_of(cq_event, struct hbq_dmabuf,
895 lpfc_in_buf_free(phba, &dmabuf->dbuf);
901 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
902 * @phba: pointer to lpfc HBA data structure.
904 * This routine will cleanup posted ELS buffers after the HBA is reset
905 * when bringing down the SLI Layer.
912 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
914 struct lpfc_sli *psli = &phba->sli;
915 struct lpfc_sli_ring *pring;
916 struct lpfc_dmabuf *mp, *next_mp;
920 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
921 lpfc_sli_hbqbuf_free_all(phba);
923 /* Cleanup preposted buffers on the ELS ring */
924 pring = &psli->sli3_ring[LPFC_ELS_RING];
925 spin_lock_irq(&phba->hbalock);
926 list_splice_init(&pring->postbufq, &buflist);
927 spin_unlock_irq(&phba->hbalock);
930 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
933 lpfc_mbuf_free(phba, mp->virt, mp->phys);
937 spin_lock_irq(&phba->hbalock);
938 pring->postbufq_cnt -= count;
939 spin_unlock_irq(&phba->hbalock);
944 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
945 * @phba: pointer to lpfc HBA data structure.
947 * This routine will cleanup the txcmplq after the HBA is reset when bringing
948 * down the SLI Layer.
954 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
956 struct lpfc_sli *psli = &phba->sli;
957 struct lpfc_queue *qp = NULL;
958 struct lpfc_sli_ring *pring;
959 LIST_HEAD(completions);
962 if (phba->sli_rev != LPFC_SLI_REV4) {
963 for (i = 0; i < psli->num_rings; i++) {
964 pring = &psli->sli3_ring[i];
965 spin_lock_irq(&phba->hbalock);
966 /* At this point in time the HBA is either reset or DOA
967 * Nothing should be on txcmplq as it will
970 list_splice_init(&pring->txcmplq, &completions);
971 pring->txcmplq_cnt = 0;
972 spin_unlock_irq(&phba->hbalock);
974 lpfc_sli_abort_iocb_ring(phba, pring);
976 /* Cancel all the IOCBs from the completions list */
977 lpfc_sli_cancel_iocbs(phba, &completions,
978 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
981 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
985 spin_lock_irq(&pring->ring_lock);
986 list_splice_init(&pring->txcmplq, &completions);
987 pring->txcmplq_cnt = 0;
988 spin_unlock_irq(&pring->ring_lock);
989 lpfc_sli_abort_iocb_ring(phba, pring);
991 /* Cancel all the IOCBs from the completions list */
992 lpfc_sli_cancel_iocbs(phba, &completions,
993 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
997 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
999 * @phba: pointer to lpfc HBA data structure.
1001 * This routine will do uninitialization after the HBA is reset when bring
1002 * down the SLI Layer.
1006 * Any other value - error.
1009 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
1011 lpfc_hba_free_post_buf(phba);
1012 lpfc_hba_clean_txcmplq(phba);
1017 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1018 * @phba: pointer to lpfc HBA data structure.
1020 * This routine will do uninitialization after the HBA is reset when bring
1021 * down the SLI Layer.
1025 * Any other value - error.
1028 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1030 struct lpfc_scsi_buf *psb, *psb_next;
1031 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
1033 LIST_HEAD(nvme_aborts);
1034 LIST_HEAD(nvmet_aborts);
1035 unsigned long iflag = 0;
1036 struct lpfc_sglq *sglq_entry = NULL;
1039 lpfc_sli_hbqbuf_free_all(phba);
1040 lpfc_hba_clean_txcmplq(phba);
1042 /* At this point in time the HBA is either reset or DOA. Either
1043 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1044 * on the lpfc_els_sgl_list so that it can either be freed if the
1045 * driver is unloading or reposted if the driver is restarting
1048 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
1050 /* sgl_list_lock required because worker thread uses this
1053 spin_lock(&phba->sli4_hba.sgl_list_lock);
1054 list_for_each_entry(sglq_entry,
1055 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1056 sglq_entry->state = SGL_FREED;
1058 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1059 &phba->sli4_hba.lpfc_els_sgl_list);
1062 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1063 /* abts_scsi_buf_list_lock required because worker thread uses this
1066 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1067 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1068 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1070 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1074 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1075 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1077 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1079 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1082 spin_unlock_irq(&phba->hbalock);
1084 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1086 psb->status = IOSTAT_SUCCESS;
1088 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1089 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1090 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1092 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1093 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1095 psb->status = IOSTAT_SUCCESS;
1097 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1098 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1099 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1101 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1102 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
1103 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
1107 lpfc_sli4_free_sp_events(phba);
1112 * lpfc_hba_down_post - Wrapper func for hba down post routine
1113 * @phba: pointer to lpfc HBA data structure.
1115 * This routine wraps the actual SLI3 or SLI4 routine for performing
1116 * uninitialization after the HBA is reset when bring down the SLI Layer.
1120 * Any other value - error.
1123 lpfc_hba_down_post(struct lpfc_hba *phba)
1125 return (*phba->lpfc_hba_down_post)(phba);
1129 * lpfc_hb_timeout - The HBA-timer timeout handler
1130 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1132 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1133 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1134 * work-port-events bitmap and the worker thread is notified. This timeout
1135 * event will be used by the worker thread to invoke the actual timeout
1136 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1137 * be performed in the timeout handler and the HBA timeout event bit shall
1138 * be cleared by the worker thread after it has taken the event bitmap out.
1141 lpfc_hb_timeout(unsigned long ptr)
1143 struct lpfc_hba *phba;
1144 uint32_t tmo_posted;
1145 unsigned long iflag;
1147 phba = (struct lpfc_hba *)ptr;
1149 /* Check for heart beat timeout conditions */
1150 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1151 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1153 phba->pport->work_port_events |= WORKER_HB_TMO;
1154 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1156 /* Tell the worker thread there is work to do */
1158 lpfc_worker_wake_up(phba);
1163 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1164 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1166 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1167 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1168 * work-port-events bitmap and the worker thread is notified. This timeout
1169 * event will be used by the worker thread to invoke the actual timeout
1170 * handler routine, lpfc_rrq_handler. Any periodical operations will
1171 * be performed in the timeout handler and the RRQ timeout event bit shall
1172 * be cleared by the worker thread after it has taken the event bitmap out.
1175 lpfc_rrq_timeout(unsigned long ptr)
1177 struct lpfc_hba *phba;
1178 unsigned long iflag;
1180 phba = (struct lpfc_hba *)ptr;
1181 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1182 if (!(phba->pport->load_flag & FC_UNLOADING))
1183 phba->hba_flag |= HBA_RRQ_ACTIVE;
1185 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1186 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1188 if (!(phba->pport->load_flag & FC_UNLOADING))
1189 lpfc_worker_wake_up(phba);
1193 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1194 * @phba: pointer to lpfc hba data structure.
1195 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1197 * This is the callback function to the lpfc heart-beat mailbox command.
1198 * If configured, the lpfc driver issues the heart-beat mailbox command to
1199 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1200 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1201 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1202 * heart-beat outstanding state. Once the mailbox command comes back and
1203 * no error conditions detected, the heart-beat mailbox command timer is
1204 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1205 * state is cleared for the next heart-beat. If the timer expired with the
1206 * heart-beat outstanding state set, the driver will put the HBA offline.
1209 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1211 unsigned long drvr_flag;
1213 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1214 phba->hb_outstanding = 0;
1215 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1217 /* Check and reset heart-beat timer is necessary */
1218 mempool_free(pmboxq, phba->mbox_mem_pool);
1219 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1220 !(phba->link_state == LPFC_HBA_ERROR) &&
1221 !(phba->pport->load_flag & FC_UNLOADING))
1222 mod_timer(&phba->hb_tmofunc,
1224 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1229 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1230 * @phba: pointer to lpfc hba data structure.
1232 * This is the actual HBA-timer timeout handler to be invoked by the worker
1233 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1234 * handler performs any periodic operations needed for the device. If such
1235 * periodic event has already been attended to either in the interrupt handler
1236 * or by processing slow-ring or fast-ring events within the HBA-timer
1237 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1238 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1239 * is configured and there is no heart-beat mailbox command outstanding, a
1240 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1241 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1245 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1247 struct lpfc_vport **vports;
1248 LPFC_MBOXQ_t *pmboxq;
1249 struct lpfc_dmabuf *buf_ptr;
1251 struct lpfc_sli *psli = &phba->sli;
1252 LIST_HEAD(completions);
1253 struct lpfc_queue *qp;
1254 unsigned long time_elapsed;
1255 uint32_t tick_cqe, max_cqe, val;
1256 uint64_t tot, data1, data2, data3;
1257 struct lpfc_nvmet_tgtport *tgtp;
1258 struct lpfc_register reg_data;
1259 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
1261 vports = lpfc_create_vport_work_array(phba);
1263 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1264 lpfc_rcv_seq_check_edtov(vports[i]);
1265 lpfc_fdmi_num_disc_check(vports[i]);
1267 lpfc_destroy_vport_work_array(phba, vports);
1269 if ((phba->link_state == LPFC_HBA_ERROR) ||
1270 (phba->pport->load_flag & FC_UNLOADING) ||
1271 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1274 if (phba->cfg_auto_imax) {
1275 if (!phba->last_eqdelay_time) {
1276 phba->last_eqdelay_time = jiffies;
1279 time_elapsed = jiffies - phba->last_eqdelay_time;
1280 phba->last_eqdelay_time = jiffies;
1283 /* Check outstanding IO count */
1284 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1285 if (phba->nvmet_support) {
1286 tgtp = phba->targetport->private;
1287 /* Calculate outstanding IOs */
1288 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1289 tot += atomic_read(&tgtp->xmt_fcp_release);
1290 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
1292 tot = atomic_read(&phba->fc4NvmeIoCmpls);
1293 data1 = atomic_read(
1294 &phba->fc4NvmeInputRequests);
1295 data2 = atomic_read(
1296 &phba->fc4NvmeOutputRequests);
1297 data3 = atomic_read(
1298 &phba->fc4NvmeControlRequests);
1299 tot = (data1 + data2 + data3) - tot;
1303 /* Interrupts per sec per EQ */
1304 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1305 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1307 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1308 max_cqe = time_elapsed * tick_cqe;
1310 for (i = 0; i < phba->io_channel_irqs; i++) {
1312 qp = phba->sli4_hba.hba_eq[i];
1316 /* Use no EQ delay if we don't have many outstanding
1317 * IOs, or if we are only processing 1 CQE/ISR or less.
1318 * Otherwise, assume we can process up to lpfc_fcp_imax
1319 * interrupts per HBA.
1321 if (tot < LPFC_NODELAY_MAX_IO ||
1322 qp->EQ_cqe_cnt <= max_cqe)
1325 val = phba->cfg_fcp_imax;
1327 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1328 /* Use EQ Delay Register method */
1330 /* Convert for EQ Delay register */
1332 /* First, interrupts per sec per EQ */
1333 val = phba->cfg_fcp_imax /
1334 phba->io_channel_irqs;
1336 /* us delay between each interrupt */
1337 val = LPFC_SEC_TO_USEC / val;
1339 if (val != qp->q_mode) {
1341 bf_set(lpfc_sliport_eqdelay_id,
1342 ®_data, qp->queue_id);
1343 bf_set(lpfc_sliport_eqdelay_delay,
1345 writel(reg_data.word0, eqdreg);
1348 /* Use mbox command method */
1349 if (val != qp->q_mode)
1350 lpfc_modify_hba_eq_delay(phba, i,
1355 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1356 * between interrupts for EQDR.
1364 spin_lock_irq(&phba->pport->work_port_lock);
1366 if (time_after(phba->last_completion_time +
1367 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1369 spin_unlock_irq(&phba->pport->work_port_lock);
1370 if (!phba->hb_outstanding)
1371 mod_timer(&phba->hb_tmofunc,
1373 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1375 mod_timer(&phba->hb_tmofunc,
1377 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1380 spin_unlock_irq(&phba->pport->work_port_lock);
1382 if (phba->elsbuf_cnt &&
1383 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1384 spin_lock_irq(&phba->hbalock);
1385 list_splice_init(&phba->elsbuf, &completions);
1386 phba->elsbuf_cnt = 0;
1387 phba->elsbuf_prev_cnt = 0;
1388 spin_unlock_irq(&phba->hbalock);
1390 while (!list_empty(&completions)) {
1391 list_remove_head(&completions, buf_ptr,
1392 struct lpfc_dmabuf, list);
1393 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1397 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1399 /* If there is no heart beat outstanding, issue a heartbeat command */
1400 if (phba->cfg_enable_hba_heartbeat) {
1401 if (!phba->hb_outstanding) {
1402 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1403 (list_empty(&psli->mboxq))) {
1404 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1407 mod_timer(&phba->hb_tmofunc,
1409 msecs_to_jiffies(1000 *
1410 LPFC_HB_MBOX_INTERVAL));
1414 lpfc_heart_beat(phba, pmboxq);
1415 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1416 pmboxq->vport = phba->pport;
1417 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1420 if (retval != MBX_BUSY &&
1421 retval != MBX_SUCCESS) {
1422 mempool_free(pmboxq,
1423 phba->mbox_mem_pool);
1424 mod_timer(&phba->hb_tmofunc,
1426 msecs_to_jiffies(1000 *
1427 LPFC_HB_MBOX_INTERVAL));
1430 phba->skipped_hb = 0;
1431 phba->hb_outstanding = 1;
1432 } else if (time_before_eq(phba->last_completion_time,
1433 phba->skipped_hb)) {
1434 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1435 "2857 Last completion time not "
1436 " updated in %d ms\n",
1437 jiffies_to_msecs(jiffies
1438 - phba->last_completion_time));
1440 phba->skipped_hb = jiffies;
1442 mod_timer(&phba->hb_tmofunc,
1444 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1448 * If heart beat timeout called with hb_outstanding set
1449 * we need to give the hb mailbox cmd a chance to
1452 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1453 "0459 Adapter heartbeat still out"
1454 "standing:last compl time was %d ms.\n",
1455 jiffies_to_msecs(jiffies
1456 - phba->last_completion_time));
1457 mod_timer(&phba->hb_tmofunc,
1459 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1462 mod_timer(&phba->hb_tmofunc,
1464 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1469 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1470 * @phba: pointer to lpfc hba data structure.
1472 * This routine is called to bring the HBA offline when HBA hardware error
1473 * other than Port Error 6 has been detected.
1476 lpfc_offline_eratt(struct lpfc_hba *phba)
1478 struct lpfc_sli *psli = &phba->sli;
1480 spin_lock_irq(&phba->hbalock);
1481 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1482 spin_unlock_irq(&phba->hbalock);
1483 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1486 lpfc_reset_barrier(phba);
1487 spin_lock_irq(&phba->hbalock);
1488 lpfc_sli_brdreset(phba);
1489 spin_unlock_irq(&phba->hbalock);
1490 lpfc_hba_down_post(phba);
1491 lpfc_sli_brdready(phba, HS_MBRDY);
1492 lpfc_unblock_mgmt_io(phba);
1493 phba->link_state = LPFC_HBA_ERROR;
1498 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1499 * @phba: pointer to lpfc hba data structure.
1501 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1502 * other than Port Error 6 has been detected.
1505 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1507 spin_lock_irq(&phba->hbalock);
1508 phba->link_state = LPFC_HBA_ERROR;
1509 spin_unlock_irq(&phba->hbalock);
1511 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1513 lpfc_hba_down_post(phba);
1514 lpfc_unblock_mgmt_io(phba);
1518 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1519 * @phba: pointer to lpfc hba data structure.
1521 * This routine is invoked to handle the deferred HBA hardware error
1522 * conditions. This type of error is indicated by HBA by setting ER1
1523 * and another ER bit in the host status register. The driver will
1524 * wait until the ER1 bit clears before handling the error condition.
1527 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1529 uint32_t old_host_status = phba->work_hs;
1530 struct lpfc_sli *psli = &phba->sli;
1532 /* If the pci channel is offline, ignore possible errors,
1533 * since we cannot communicate with the pci card anyway.
1535 if (pci_channel_offline(phba->pcidev)) {
1536 spin_lock_irq(&phba->hbalock);
1537 phba->hba_flag &= ~DEFER_ERATT;
1538 spin_unlock_irq(&phba->hbalock);
1542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1543 "0479 Deferred Adapter Hardware Error "
1544 "Data: x%x x%x x%x\n",
1546 phba->work_status[0], phba->work_status[1]);
1548 spin_lock_irq(&phba->hbalock);
1549 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1550 spin_unlock_irq(&phba->hbalock);
1554 * Firmware stops when it triggred erratt. That could cause the I/Os
1555 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1556 * SCSI layer retry it after re-establishing link.
1558 lpfc_sli_abort_fcp_rings(phba);
1561 * There was a firmware error. Take the hba offline and then
1562 * attempt to restart it.
1564 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1567 /* Wait for the ER1 bit to clear.*/
1568 while (phba->work_hs & HS_FFER1) {
1570 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1571 phba->work_hs = UNPLUG_ERR ;
1574 /* If driver is unloading let the worker thread continue */
1575 if (phba->pport->load_flag & FC_UNLOADING) {
1582 * This is to ptrotect against a race condition in which
1583 * first write to the host attention register clear the
1584 * host status register.
1586 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1587 phba->work_hs = old_host_status & ~HS_FFER1;
1589 spin_lock_irq(&phba->hbalock);
1590 phba->hba_flag &= ~DEFER_ERATT;
1591 spin_unlock_irq(&phba->hbalock);
1592 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1593 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1597 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1599 struct lpfc_board_event_header board_event;
1600 struct Scsi_Host *shost;
1602 board_event.event_type = FC_REG_BOARD_EVENT;
1603 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1604 shost = lpfc_shost_from_vport(phba->pport);
1605 fc_host_post_vendor_event(shost, fc_get_event_number(),
1606 sizeof(board_event),
1607 (char *) &board_event,
1612 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1613 * @phba: pointer to lpfc hba data structure.
1615 * This routine is invoked to handle the following HBA hardware error
1617 * 1 - HBA error attention interrupt
1618 * 2 - DMA ring index out of range
1619 * 3 - Mailbox command came back as unknown
1622 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1624 struct lpfc_vport *vport = phba->pport;
1625 struct lpfc_sli *psli = &phba->sli;
1626 uint32_t event_data;
1627 unsigned long temperature;
1628 struct temp_event temp_event_data;
1629 struct Scsi_Host *shost;
1631 /* If the pci channel is offline, ignore possible errors,
1632 * since we cannot communicate with the pci card anyway.
1634 if (pci_channel_offline(phba->pcidev)) {
1635 spin_lock_irq(&phba->hbalock);
1636 phba->hba_flag &= ~DEFER_ERATT;
1637 spin_unlock_irq(&phba->hbalock);
1641 /* If resets are disabled then leave the HBA alone and return */
1642 if (!phba->cfg_enable_hba_reset)
1645 /* Send an internal error event to mgmt application */
1646 lpfc_board_errevt_to_mgmt(phba);
1648 if (phba->hba_flag & DEFER_ERATT)
1649 lpfc_handle_deferred_eratt(phba);
1651 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1652 if (phba->work_hs & HS_FFER6)
1653 /* Re-establishing Link */
1654 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1655 "1301 Re-establishing Link "
1656 "Data: x%x x%x x%x\n",
1657 phba->work_hs, phba->work_status[0],
1658 phba->work_status[1]);
1659 if (phba->work_hs & HS_FFER8)
1660 /* Device Zeroization */
1661 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1662 "2861 Host Authentication device "
1663 "zeroization Data:x%x x%x x%x\n",
1664 phba->work_hs, phba->work_status[0],
1665 phba->work_status[1]);
1667 spin_lock_irq(&phba->hbalock);
1668 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1669 spin_unlock_irq(&phba->hbalock);
1672 * Firmware stops when it triggled erratt with HS_FFER6.
1673 * That could cause the I/Os dropped by the firmware.
1674 * Error iocb (I/O) on txcmplq and let the SCSI layer
1675 * retry it after re-establishing link.
1677 lpfc_sli_abort_fcp_rings(phba);
1680 * There was a firmware error. Take the hba offline and then
1681 * attempt to restart it.
1683 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1685 lpfc_sli_brdrestart(phba);
1686 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1687 lpfc_unblock_mgmt_io(phba);
1690 lpfc_unblock_mgmt_io(phba);
1691 } else if (phba->work_hs & HS_CRIT_TEMP) {
1692 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1693 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1694 temp_event_data.event_code = LPFC_CRIT_TEMP;
1695 temp_event_data.data = (uint32_t)temperature;
1697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1698 "0406 Adapter maximum temperature exceeded "
1699 "(%ld), taking this port offline "
1700 "Data: x%x x%x x%x\n",
1701 temperature, phba->work_hs,
1702 phba->work_status[0], phba->work_status[1]);
1704 shost = lpfc_shost_from_vport(phba->pport);
1705 fc_host_post_vendor_event(shost, fc_get_event_number(),
1706 sizeof(temp_event_data),
1707 (char *) &temp_event_data,
1708 SCSI_NL_VID_TYPE_PCI
1709 | PCI_VENDOR_ID_EMULEX);
1711 spin_lock_irq(&phba->hbalock);
1712 phba->over_temp_state = HBA_OVER_TEMP;
1713 spin_unlock_irq(&phba->hbalock);
1714 lpfc_offline_eratt(phba);
1717 /* The if clause above forces this code path when the status
1718 * failure is a value other than FFER6. Do not call the offline
1719 * twice. This is the adapter hardware error path.
1721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1722 "0457 Adapter Hardware Error "
1723 "Data: x%x x%x x%x\n",
1725 phba->work_status[0], phba->work_status[1]);
1727 event_data = FC_REG_DUMP_EVENT;
1728 shost = lpfc_shost_from_vport(vport);
1729 fc_host_post_vendor_event(shost, fc_get_event_number(),
1730 sizeof(event_data), (char *) &event_data,
1731 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1733 lpfc_offline_eratt(phba);
1739 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1740 * @phba: pointer to lpfc hba data structure.
1741 * @mbx_action: flag for mailbox shutdown action.
1743 * This routine is invoked to perform an SLI4 port PCI function reset in
1744 * response to port status register polling attention. It waits for port
1745 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1746 * During this process, interrupt vectors are freed and later requested
1747 * for handling possible port resource change.
1750 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1756 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1757 LPFC_SLI_INTF_IF_TYPE_2) {
1759 * On error status condition, driver need to wait for port
1760 * ready before performing reset.
1762 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1767 /* need reset: attempt for port recovery */
1769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1770 "2887 Reset Needed: Attempting Port "
1772 lpfc_offline_prep(phba, mbx_action);
1774 /* release interrupt for possible resource change */
1775 lpfc_sli4_disable_intr(phba);
1776 rc = lpfc_sli_brdrestart(phba);
1778 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1779 "6309 Failed to restart board\n");
1782 /* request and enable interrupt */
1783 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1784 if (intr_mode == LPFC_INTR_ERROR) {
1785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1786 "3175 Failed to enable interrupt\n");
1789 phba->intr_mode = intr_mode;
1790 rc = lpfc_online(phba);
1792 lpfc_unblock_mgmt_io(phba);
1798 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1799 * @phba: pointer to lpfc hba data structure.
1801 * This routine is invoked to handle the SLI4 HBA hardware error attention
1805 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1807 struct lpfc_vport *vport = phba->pport;
1808 uint32_t event_data;
1809 struct Scsi_Host *shost;
1811 struct lpfc_register portstat_reg = {0};
1812 uint32_t reg_err1, reg_err2;
1813 uint32_t uerrlo_reg, uemasklo_reg;
1814 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1815 bool en_rn_msg = true;
1816 struct temp_event temp_event_data;
1817 struct lpfc_register portsmphr_reg;
1820 /* If the pci channel is offline, ignore possible errors, since
1821 * we cannot communicate with the pci card anyway.
1823 if (pci_channel_offline(phba->pcidev))
1826 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1827 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1829 case LPFC_SLI_INTF_IF_TYPE_0:
1830 pci_rd_rc1 = lpfc_readl(
1831 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1833 pci_rd_rc2 = lpfc_readl(
1834 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1836 /* consider PCI bus read error as pci_channel_offline */
1837 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1839 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1840 lpfc_sli4_offline_eratt(phba);
1843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1844 "7623 Checking UE recoverable");
1846 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1847 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1848 &portsmphr_reg.word0))
1851 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1853 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1854 LPFC_PORT_SEM_UE_RECOVERABLE)
1856 /*Sleep for 1Sec, before checking SEMAPHORE */
1860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1861 "4827 smphr_port_status x%x : Waited %dSec",
1862 smphr_port_status, i);
1864 /* Recoverable UE, reset the HBA device */
1865 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1866 LPFC_PORT_SEM_UE_RECOVERABLE) {
1867 for (i = 0; i < 20; i++) {
1869 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1870 &portsmphr_reg.word0) &&
1871 (LPFC_POST_STAGE_PORT_READY ==
1872 bf_get(lpfc_port_smphr_port_status,
1874 rc = lpfc_sli4_port_sta_fn_reset(phba,
1875 LPFC_MBX_NO_WAIT, en_rn_msg);
1878 lpfc_printf_log(phba,
1880 "4215 Failed to recover UE");
1885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1886 "7624 Firmware not ready: Failing UE recovery,"
1887 " waited %dSec", i);
1888 lpfc_sli4_offline_eratt(phba);
1891 case LPFC_SLI_INTF_IF_TYPE_2:
1892 pci_rd_rc1 = lpfc_readl(
1893 phba->sli4_hba.u.if_type2.STATUSregaddr,
1894 &portstat_reg.word0);
1895 /* consider PCI bus read error as pci_channel_offline */
1896 if (pci_rd_rc1 == -EIO) {
1897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1898 "3151 PCI bus read access failure: x%x\n",
1899 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1902 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1903 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1904 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1906 "2889 Port Overtemperature event, "
1907 "taking port offline Data: x%x x%x\n",
1908 reg_err1, reg_err2);
1910 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
1911 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1912 temp_event_data.event_code = LPFC_CRIT_TEMP;
1913 temp_event_data.data = 0xFFFFFFFF;
1915 shost = lpfc_shost_from_vport(phba->pport);
1916 fc_host_post_vendor_event(shost, fc_get_event_number(),
1917 sizeof(temp_event_data),
1918 (char *)&temp_event_data,
1919 SCSI_NL_VID_TYPE_PCI
1920 | PCI_VENDOR_ID_EMULEX);
1922 spin_lock_irq(&phba->hbalock);
1923 phba->over_temp_state = HBA_OVER_TEMP;
1924 spin_unlock_irq(&phba->hbalock);
1925 lpfc_sli4_offline_eratt(phba);
1928 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1929 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1931 "3143 Port Down: Firmware Update "
1934 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1935 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1937 "3144 Port Down: Debug Dump\n");
1938 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1939 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1941 "3145 Port Down: Provisioning\n");
1943 /* If resets are disabled then leave the HBA alone and return */
1944 if (!phba->cfg_enable_hba_reset)
1947 /* Check port status register for function reset */
1948 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1951 /* don't report event on forced debug dump */
1952 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1953 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1958 /* fall through for not able to recover */
1959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1960 "3152 Unrecoverable error, bring the port "
1962 lpfc_sli4_offline_eratt(phba);
1964 case LPFC_SLI_INTF_IF_TYPE_1:
1968 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1969 "3123 Report dump event to upper layer\n");
1970 /* Send an internal error event to mgmt application */
1971 lpfc_board_errevt_to_mgmt(phba);
1973 event_data = FC_REG_DUMP_EVENT;
1974 shost = lpfc_shost_from_vport(vport);
1975 fc_host_post_vendor_event(shost, fc_get_event_number(),
1976 sizeof(event_data), (char *) &event_data,
1977 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1981 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1982 * @phba: pointer to lpfc HBA data structure.
1984 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1985 * routine from the API jump table function pointer from the lpfc_hba struct.
1989 * Any other value - error.
1992 lpfc_handle_eratt(struct lpfc_hba *phba)
1994 (*phba->lpfc_handle_eratt)(phba);
1998 * lpfc_handle_latt - The HBA link event handler
1999 * @phba: pointer to lpfc hba data structure.
2001 * This routine is invoked from the worker thread to handle a HBA host
2002 * attention link event. SLI3 only.
2005 lpfc_handle_latt(struct lpfc_hba *phba)
2007 struct lpfc_vport *vport = phba->pport;
2008 struct lpfc_sli *psli = &phba->sli;
2010 volatile uint32_t control;
2011 struct lpfc_dmabuf *mp;
2014 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2017 goto lpfc_handle_latt_err_exit;
2020 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2023 goto lpfc_handle_latt_free_pmb;
2026 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2029 goto lpfc_handle_latt_free_mp;
2032 /* Cleanup any outstanding ELS commands */
2033 lpfc_els_flush_all_cmd(phba);
2035 psli->slistat.link_event++;
2036 lpfc_read_topology(phba, pmb, mp);
2037 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
2039 /* Block ELS IOCBs until we have processed this mbox command */
2040 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2041 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
2042 if (rc == MBX_NOT_FINISHED) {
2044 goto lpfc_handle_latt_free_mbuf;
2047 /* Clear Link Attention in HA REG */
2048 spin_lock_irq(&phba->hbalock);
2049 writel(HA_LATT, phba->HAregaddr);
2050 readl(phba->HAregaddr); /* flush */
2051 spin_unlock_irq(&phba->hbalock);
2055 lpfc_handle_latt_free_mbuf:
2056 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2057 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2058 lpfc_handle_latt_free_mp:
2060 lpfc_handle_latt_free_pmb:
2061 mempool_free(pmb, phba->mbox_mem_pool);
2062 lpfc_handle_latt_err_exit:
2063 /* Enable Link attention interrupts */
2064 spin_lock_irq(&phba->hbalock);
2065 psli->sli_flag |= LPFC_PROCESS_LA;
2066 control = readl(phba->HCregaddr);
2067 control |= HC_LAINT_ENA;
2068 writel(control, phba->HCregaddr);
2069 readl(phba->HCregaddr); /* flush */
2071 /* Clear Link Attention in HA REG */
2072 writel(HA_LATT, phba->HAregaddr);
2073 readl(phba->HAregaddr); /* flush */
2074 spin_unlock_irq(&phba->hbalock);
2075 lpfc_linkdown(phba);
2076 phba->link_state = LPFC_HBA_ERROR;
2078 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2079 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
2085 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2086 * @phba: pointer to lpfc hba data structure.
2087 * @vpd: pointer to the vital product data.
2088 * @len: length of the vital product data in bytes.
2090 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2091 * an array of characters. In this routine, the ModelName, ProgramType, and
2092 * ModelDesc, etc. fields of the phba data structure will be populated.
2095 * 0 - pointer to the VPD passed in is NULL
2099 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
2101 uint8_t lenlo, lenhi;
2111 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2112 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2113 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2115 while (!finished && (index < (len - 4))) {
2116 switch (vpd[index]) {
2124 i = ((((unsigned short)lenhi) << 8) + lenlo);
2133 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2134 if (Length > len - index)
2135 Length = len - index;
2136 while (Length > 0) {
2137 /* Look for Serial Number */
2138 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2145 phba->SerialNumber[j++] = vpd[index++];
2149 phba->SerialNumber[j] = 0;
2152 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2153 phba->vpd_flag |= VPD_MODEL_DESC;
2160 phba->ModelDesc[j++] = vpd[index++];
2164 phba->ModelDesc[j] = 0;
2167 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2168 phba->vpd_flag |= VPD_MODEL_NAME;
2175 phba->ModelName[j++] = vpd[index++];
2179 phba->ModelName[j] = 0;
2182 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2183 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2190 phba->ProgramType[j++] = vpd[index++];
2194 phba->ProgramType[j] = 0;
2197 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2198 phba->vpd_flag |= VPD_PORT;
2205 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2206 (phba->sli4_hba.pport_name_sta ==
2207 LPFC_SLI4_PPNAME_GET)) {
2211 phba->Port[j++] = vpd[index++];
2215 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2216 (phba->sli4_hba.pport_name_sta ==
2217 LPFC_SLI4_PPNAME_NON))
2244 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2245 * @phba: pointer to lpfc hba data structure.
2246 * @mdp: pointer to the data structure to hold the derived model name.
2247 * @descp: pointer to the data structure to hold the derived description.
2249 * This routine retrieves HBA's description based on its registered PCI device
2250 * ID. The @descp passed into this function points to an array of 256 chars. It
2251 * shall be returned with the model name, maximum speed, and the host bus type.
2252 * The @mdp passed into this function points to an array of 80 chars. When the
2253 * function returns, the @mdp will be filled with the model name.
2256 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2259 uint16_t dev_id = phba->pcidev->device;
2262 int oneConnect = 0; /* default is not a oneConnect */
2267 } m = {"<Unknown>", "", ""};
2269 if (mdp && mdp[0] != '\0'
2270 && descp && descp[0] != '\0')
2273 if (phba->lmt & LMT_32Gb)
2275 else if (phba->lmt & LMT_16Gb)
2277 else if (phba->lmt & LMT_10Gb)
2279 else if (phba->lmt & LMT_8Gb)
2281 else if (phba->lmt & LMT_4Gb)
2283 else if (phba->lmt & LMT_2Gb)
2285 else if (phba->lmt & LMT_1Gb)
2293 case PCI_DEVICE_ID_FIREFLY:
2294 m = (typeof(m)){"LP6000", "PCI",
2295 "Obsolete, Unsupported Fibre Channel Adapter"};
2297 case PCI_DEVICE_ID_SUPERFLY:
2298 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2299 m = (typeof(m)){"LP7000", "PCI", ""};
2301 m = (typeof(m)){"LP7000E", "PCI", ""};
2302 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2304 case PCI_DEVICE_ID_DRAGONFLY:
2305 m = (typeof(m)){"LP8000", "PCI",
2306 "Obsolete, Unsupported Fibre Channel Adapter"};
2308 case PCI_DEVICE_ID_CENTAUR:
2309 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2310 m = (typeof(m)){"LP9002", "PCI", ""};
2312 m = (typeof(m)){"LP9000", "PCI", ""};
2313 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2315 case PCI_DEVICE_ID_RFLY:
2316 m = (typeof(m)){"LP952", "PCI",
2317 "Obsolete, Unsupported Fibre Channel Adapter"};
2319 case PCI_DEVICE_ID_PEGASUS:
2320 m = (typeof(m)){"LP9802", "PCI-X",
2321 "Obsolete, Unsupported Fibre Channel Adapter"};
2323 case PCI_DEVICE_ID_THOR:
2324 m = (typeof(m)){"LP10000", "PCI-X",
2325 "Obsolete, Unsupported Fibre Channel Adapter"};
2327 case PCI_DEVICE_ID_VIPER:
2328 m = (typeof(m)){"LPX1000", "PCI-X",
2329 "Obsolete, Unsupported Fibre Channel Adapter"};
2331 case PCI_DEVICE_ID_PFLY:
2332 m = (typeof(m)){"LP982", "PCI-X",
2333 "Obsolete, Unsupported Fibre Channel Adapter"};
2335 case PCI_DEVICE_ID_TFLY:
2336 m = (typeof(m)){"LP1050", "PCI-X",
2337 "Obsolete, Unsupported Fibre Channel Adapter"};
2339 case PCI_DEVICE_ID_HELIOS:
2340 m = (typeof(m)){"LP11000", "PCI-X2",
2341 "Obsolete, Unsupported Fibre Channel Adapter"};
2343 case PCI_DEVICE_ID_HELIOS_SCSP:
2344 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2345 "Obsolete, Unsupported Fibre Channel Adapter"};
2347 case PCI_DEVICE_ID_HELIOS_DCSP:
2348 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2349 "Obsolete, Unsupported Fibre Channel Adapter"};
2351 case PCI_DEVICE_ID_NEPTUNE:
2352 m = (typeof(m)){"LPe1000", "PCIe",
2353 "Obsolete, Unsupported Fibre Channel Adapter"};
2355 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2356 m = (typeof(m)){"LPe1000-SP", "PCIe",
2357 "Obsolete, Unsupported Fibre Channel Adapter"};
2359 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2360 m = (typeof(m)){"LPe1002-SP", "PCIe",
2361 "Obsolete, Unsupported Fibre Channel Adapter"};
2363 case PCI_DEVICE_ID_BMID:
2364 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2366 case PCI_DEVICE_ID_BSMB:
2367 m = (typeof(m)){"LP111", "PCI-X2",
2368 "Obsolete, Unsupported Fibre Channel Adapter"};
2370 case PCI_DEVICE_ID_ZEPHYR:
2371 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2373 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2374 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2376 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2377 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2380 case PCI_DEVICE_ID_ZMID:
2381 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2383 case PCI_DEVICE_ID_ZSMB:
2384 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2386 case PCI_DEVICE_ID_LP101:
2387 m = (typeof(m)){"LP101", "PCI-X",
2388 "Obsolete, Unsupported Fibre Channel Adapter"};
2390 case PCI_DEVICE_ID_LP10000S:
2391 m = (typeof(m)){"LP10000-S", "PCI",
2392 "Obsolete, Unsupported Fibre Channel Adapter"};
2394 case PCI_DEVICE_ID_LP11000S:
2395 m = (typeof(m)){"LP11000-S", "PCI-X2",
2396 "Obsolete, Unsupported Fibre Channel Adapter"};
2398 case PCI_DEVICE_ID_LPE11000S:
2399 m = (typeof(m)){"LPe11000-S", "PCIe",
2400 "Obsolete, Unsupported Fibre Channel Adapter"};
2402 case PCI_DEVICE_ID_SAT:
2403 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2405 case PCI_DEVICE_ID_SAT_MID:
2406 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2408 case PCI_DEVICE_ID_SAT_SMB:
2409 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2411 case PCI_DEVICE_ID_SAT_DCSP:
2412 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2414 case PCI_DEVICE_ID_SAT_SCSP:
2415 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2417 case PCI_DEVICE_ID_SAT_S:
2418 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2420 case PCI_DEVICE_ID_HORNET:
2421 m = (typeof(m)){"LP21000", "PCIe",
2422 "Obsolete, Unsupported FCoE Adapter"};
2425 case PCI_DEVICE_ID_PROTEUS_VF:
2426 m = (typeof(m)){"LPev12000", "PCIe IOV",
2427 "Obsolete, Unsupported Fibre Channel Adapter"};
2429 case PCI_DEVICE_ID_PROTEUS_PF:
2430 m = (typeof(m)){"LPev12000", "PCIe IOV",
2431 "Obsolete, Unsupported Fibre Channel Adapter"};
2433 case PCI_DEVICE_ID_PROTEUS_S:
2434 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2435 "Obsolete, Unsupported Fibre Channel Adapter"};
2437 case PCI_DEVICE_ID_TIGERSHARK:
2439 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2441 case PCI_DEVICE_ID_TOMCAT:
2443 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2445 case PCI_DEVICE_ID_FALCON:
2446 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2447 "EmulexSecure Fibre"};
2449 case PCI_DEVICE_ID_BALIUS:
2450 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2451 "Obsolete, Unsupported Fibre Channel Adapter"};
2453 case PCI_DEVICE_ID_LANCER_FC:
2454 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2456 case PCI_DEVICE_ID_LANCER_FC_VF:
2457 m = (typeof(m)){"LPe16000", "PCIe",
2458 "Obsolete, Unsupported Fibre Channel Adapter"};
2460 case PCI_DEVICE_ID_LANCER_FCOE:
2462 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2464 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2466 m = (typeof(m)){"OCe15100", "PCIe",
2467 "Obsolete, Unsupported FCoE"};
2469 case PCI_DEVICE_ID_LANCER_G6_FC:
2470 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2472 case PCI_DEVICE_ID_SKYHAWK:
2473 case PCI_DEVICE_ID_SKYHAWK_VF:
2475 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2478 m = (typeof(m)){"Unknown", "", ""};
2482 if (mdp && mdp[0] == '\0')
2483 snprintf(mdp, 79,"%s", m.name);
2485 * oneConnect hba requires special processing, they are all initiators
2486 * and we put the port number on the end
2488 if (descp && descp[0] == '\0') {
2490 snprintf(descp, 255,
2491 "Emulex OneConnect %s, %s Initiator %s",
2494 else if (max_speed == 0)
2495 snprintf(descp, 255,
2497 m.name, m.bus, m.function);
2499 snprintf(descp, 255,
2500 "Emulex %s %d%s %s %s",
2501 m.name, max_speed, (GE) ? "GE" : "Gb",
2507 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2508 * @phba: pointer to lpfc hba data structure.
2509 * @pring: pointer to a IOCB ring.
2510 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2512 * This routine posts a given number of IOCBs with the associated DMA buffer
2513 * descriptors specified by the cnt argument to the given IOCB ring.
2516 * The number of IOCBs NOT able to be posted to the IOCB ring.
2519 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2522 struct lpfc_iocbq *iocb;
2523 struct lpfc_dmabuf *mp1, *mp2;
2525 cnt += pring->missbufcnt;
2527 /* While there are buffers to post */
2529 /* Allocate buffer for command iocb */
2530 iocb = lpfc_sli_get_iocbq(phba);
2532 pring->missbufcnt = cnt;
2537 /* 2 buffers can be posted per command */
2538 /* Allocate buffer to post */
2539 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2541 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2542 if (!mp1 || !mp1->virt) {
2544 lpfc_sli_release_iocbq(phba, iocb);
2545 pring->missbufcnt = cnt;
2549 INIT_LIST_HEAD(&mp1->list);
2550 /* Allocate buffer to post */
2552 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2554 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2556 if (!mp2 || !mp2->virt) {
2558 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2560 lpfc_sli_release_iocbq(phba, iocb);
2561 pring->missbufcnt = cnt;
2565 INIT_LIST_HEAD(&mp2->list);
2570 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2571 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2572 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2573 icmd->ulpBdeCount = 1;
2576 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2577 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2578 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2580 icmd->ulpBdeCount = 2;
2583 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2586 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2588 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2592 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2596 lpfc_sli_release_iocbq(phba, iocb);
2597 pring->missbufcnt = cnt;
2600 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2602 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2604 pring->missbufcnt = 0;
2609 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2610 * @phba: pointer to lpfc hba data structure.
2612 * This routine posts initial receive IOCB buffers to the ELS ring. The
2613 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2614 * set to 64 IOCBs. SLI3 only.
2617 * 0 - success (currently always success)
2620 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2622 struct lpfc_sli *psli = &phba->sli;
2624 /* Ring 0, ELS / CT buffers */
2625 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2626 /* Ring 2 - FCP no buffers needed */
2631 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2634 * lpfc_sha_init - Set up initial array of hash table entries
2635 * @HashResultPointer: pointer to an array as hash table.
2637 * This routine sets up the initial values to the array of hash table entries
2641 lpfc_sha_init(uint32_t * HashResultPointer)
2643 HashResultPointer[0] = 0x67452301;
2644 HashResultPointer[1] = 0xEFCDAB89;
2645 HashResultPointer[2] = 0x98BADCFE;
2646 HashResultPointer[3] = 0x10325476;
2647 HashResultPointer[4] = 0xC3D2E1F0;
2651 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2652 * @HashResultPointer: pointer to an initial/result hash table.
2653 * @HashWorkingPointer: pointer to an working hash table.
2655 * This routine iterates an initial hash table pointed by @HashResultPointer
2656 * with the values from the working hash table pointeed by @HashWorkingPointer.
2657 * The results are putting back to the initial hash table, returned through
2658 * the @HashResultPointer as the result hash table.
2661 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2665 uint32_t A, B, C, D, E;
2668 HashWorkingPointer[t] =
2670 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2672 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2673 } while (++t <= 79);
2675 A = HashResultPointer[0];
2676 B = HashResultPointer[1];
2677 C = HashResultPointer[2];
2678 D = HashResultPointer[3];
2679 E = HashResultPointer[4];
2683 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2684 } else if (t < 40) {
2685 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2686 } else if (t < 60) {
2687 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2689 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2691 TEMP += S(5, A) + E + HashWorkingPointer[t];
2697 } while (++t <= 79);
2699 HashResultPointer[0] += A;
2700 HashResultPointer[1] += B;
2701 HashResultPointer[2] += C;
2702 HashResultPointer[3] += D;
2703 HashResultPointer[4] += E;
2708 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2709 * @RandomChallenge: pointer to the entry of host challenge random number array.
2710 * @HashWorking: pointer to the entry of the working hash array.
2712 * This routine calculates the working hash array referred by @HashWorking
2713 * from the challenge random numbers associated with the host, referred by
2714 * @RandomChallenge. The result is put into the entry of the working hash
2715 * array and returned by reference through @HashWorking.
2718 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2720 *HashWorking = (*RandomChallenge ^ *HashWorking);
2724 * lpfc_hba_init - Perform special handling for LC HBA initialization
2725 * @phba: pointer to lpfc hba data structure.
2726 * @hbainit: pointer to an array of unsigned 32-bit integers.
2728 * This routine performs the special handling for LC HBA initialization.
2731 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2734 uint32_t *HashWorking;
2735 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2737 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2741 HashWorking[0] = HashWorking[78] = *pwwnn++;
2742 HashWorking[1] = HashWorking[79] = *pwwnn;
2744 for (t = 0; t < 7; t++)
2745 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2747 lpfc_sha_init(hbainit);
2748 lpfc_sha_iterate(hbainit, HashWorking);
2753 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2754 * @vport: pointer to a virtual N_Port data structure.
2756 * This routine performs the necessary cleanups before deleting the @vport.
2757 * It invokes the discovery state machine to perform necessary state
2758 * transitions and to release the ndlps associated with the @vport. Note,
2759 * the physical port is treated as @vport 0.
2762 lpfc_cleanup(struct lpfc_vport *vport)
2764 struct lpfc_hba *phba = vport->phba;
2765 struct lpfc_nodelist *ndlp, *next_ndlp;
2768 if (phba->link_state > LPFC_LINK_DOWN)
2769 lpfc_port_link_failure(vport);
2771 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2772 if (!NLP_CHK_NODE_ACT(ndlp)) {
2773 ndlp = lpfc_enable_node(vport, ndlp,
2774 NLP_STE_UNUSED_NODE);
2777 spin_lock_irq(&phba->ndlp_lock);
2778 NLP_SET_FREE_REQ(ndlp);
2779 spin_unlock_irq(&phba->ndlp_lock);
2780 /* Trigger the release of the ndlp memory */
2784 spin_lock_irq(&phba->ndlp_lock);
2785 if (NLP_CHK_FREE_REQ(ndlp)) {
2786 /* The ndlp should not be in memory free mode already */
2787 spin_unlock_irq(&phba->ndlp_lock);
2790 /* Indicate request for freeing ndlp memory */
2791 NLP_SET_FREE_REQ(ndlp);
2792 spin_unlock_irq(&phba->ndlp_lock);
2794 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2795 ndlp->nlp_DID == Fabric_DID) {
2796 /* Just free up ndlp with Fabric_DID for vports */
2801 /* take care of nodes in unused state before the state
2802 * machine taking action.
2804 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2809 if (ndlp->nlp_type & NLP_FABRIC)
2810 lpfc_disc_state_machine(vport, ndlp, NULL,
2811 NLP_EVT_DEVICE_RECOVERY);
2813 lpfc_disc_state_machine(vport, ndlp, NULL,
2817 /* At this point, ALL ndlp's should be gone
2818 * because of the previous NLP_EVT_DEVICE_RM.
2819 * Lets wait for this to happen, if needed.
2821 while (!list_empty(&vport->fc_nodes)) {
2823 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2824 "0233 Nodelist not empty\n");
2825 list_for_each_entry_safe(ndlp, next_ndlp,
2826 &vport->fc_nodes, nlp_listp) {
2827 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2829 "0282 did:x%x ndlp:x%p "
2830 "usgmap:x%x refcnt:%d\n",
2831 ndlp->nlp_DID, (void *)ndlp,
2833 kref_read(&ndlp->kref));
2838 /* Wait for any activity on ndlps to settle */
2841 lpfc_cleanup_vports_rrqs(vport, NULL);
2845 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2846 * @vport: pointer to a virtual N_Port data structure.
2848 * This routine stops all the timers associated with a @vport. This function
2849 * is invoked before disabling or deleting a @vport. Note that the physical
2850 * port is treated as @vport 0.
2853 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2855 del_timer_sync(&vport->els_tmofunc);
2856 del_timer_sync(&vport->delayed_disc_tmo);
2857 lpfc_can_disctmo(vport);
2862 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2863 * @phba: pointer to lpfc hba data structure.
2865 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2866 * caller of this routine should already hold the host lock.
2869 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2871 /* Clear pending FCF rediscovery wait flag */
2872 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2874 /* Now, try to stop the timer */
2875 del_timer(&phba->fcf.redisc_wait);
2879 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2880 * @phba: pointer to lpfc hba data structure.
2882 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2883 * checks whether the FCF rediscovery wait timer is pending with the host
2884 * lock held before proceeding with disabling the timer and clearing the
2885 * wait timer pendig flag.
2888 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2890 spin_lock_irq(&phba->hbalock);
2891 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2892 /* FCF rediscovery timer already fired or stopped */
2893 spin_unlock_irq(&phba->hbalock);
2896 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2897 /* Clear failover in progress flags */
2898 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2899 spin_unlock_irq(&phba->hbalock);
2903 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2904 * @phba: pointer to lpfc hba data structure.
2906 * This routine stops all the timers associated with a HBA. This function is
2907 * invoked before either putting a HBA offline or unloading the driver.
2910 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2912 lpfc_stop_vport_timers(phba->pport);
2913 del_timer_sync(&phba->sli.mbox_tmo);
2914 del_timer_sync(&phba->fabric_block_timer);
2915 del_timer_sync(&phba->eratt_poll);
2916 del_timer_sync(&phba->hb_tmofunc);
2917 if (phba->sli_rev == LPFC_SLI_REV4) {
2918 del_timer_sync(&phba->rrq_tmr);
2919 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2921 phba->hb_outstanding = 0;
2923 switch (phba->pci_dev_grp) {
2924 case LPFC_PCI_DEV_LP:
2925 /* Stop any LightPulse device specific driver timers */
2926 del_timer_sync(&phba->fcp_poll_timer);
2928 case LPFC_PCI_DEV_OC:
2929 /* Stop any OneConnect device sepcific driver timers */
2930 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2934 "0297 Invalid device group (x%x)\n",
2942 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2943 * @phba: pointer to lpfc hba data structure.
2945 * This routine marks a HBA's management interface as blocked. Once the HBA's
2946 * management interface is marked as blocked, all the user space access to
2947 * the HBA, whether they are from sysfs interface or libdfc interface will
2948 * all be blocked. The HBA is set to block the management interface when the
2949 * driver prepares the HBA interface for online or offline.
2952 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2954 unsigned long iflag;
2955 uint8_t actcmd = MBX_HEARTBEAT;
2956 unsigned long timeout;
2958 spin_lock_irqsave(&phba->hbalock, iflag);
2959 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2960 spin_unlock_irqrestore(&phba->hbalock, iflag);
2961 if (mbx_action == LPFC_MBX_NO_WAIT)
2963 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2964 spin_lock_irqsave(&phba->hbalock, iflag);
2965 if (phba->sli.mbox_active) {
2966 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
2967 /* Determine how long we might wait for the active mailbox
2968 * command to be gracefully completed by firmware.
2970 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2971 phba->sli.mbox_active) * 1000) + jiffies;
2973 spin_unlock_irqrestore(&phba->hbalock, iflag);
2975 /* Wait for the outstnading mailbox command to complete */
2976 while (phba->sli.mbox_active) {
2977 /* Check active mailbox complete status every 2ms */
2979 if (time_after(jiffies, timeout)) {
2980 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2981 "2813 Mgmt IO is Blocked %x "
2982 "- mbox cmd %x still active\n",
2983 phba->sli.sli_flag, actcmd);
2990 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2991 * @phba: pointer to lpfc hba data structure.
2993 * Allocate RPIs for all active remote nodes. This is needed whenever
2994 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2995 * is to fixup the temporary rpi assignments.
2998 lpfc_sli4_node_prep(struct lpfc_hba *phba)
3000 struct lpfc_nodelist *ndlp, *next_ndlp;
3001 struct lpfc_vport **vports;
3003 unsigned long flags;
3005 if (phba->sli_rev != LPFC_SLI_REV4)
3008 vports = lpfc_create_vport_work_array(phba);
3012 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3013 if (vports[i]->load_flag & FC_UNLOADING)
3016 list_for_each_entry_safe(ndlp, next_ndlp,
3017 &vports[i]->fc_nodes,
3019 if (!NLP_CHK_NODE_ACT(ndlp))
3021 rpi = lpfc_sli4_alloc_rpi(phba);
3022 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3023 spin_lock_irqsave(&phba->ndlp_lock, flags);
3024 NLP_CLR_NODE_ACT(ndlp);
3025 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3028 ndlp->nlp_rpi = rpi;
3029 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3030 "0009 rpi:%x DID:%x "
3031 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3032 ndlp->nlp_DID, ndlp->nlp_flag,
3033 ndlp->nlp_usg_map, ndlp);
3036 lpfc_destroy_vport_work_array(phba, vports);
3040 * lpfc_online - Initialize and bring a HBA online
3041 * @phba: pointer to lpfc hba data structure.
3043 * This routine initializes the HBA and brings a HBA online. During this
3044 * process, the management interface is blocked to prevent user space access
3045 * to the HBA interfering with the driver initialization.
3052 lpfc_online(struct lpfc_hba *phba)
3054 struct lpfc_vport *vport;
3055 struct lpfc_vport **vports;
3057 bool vpis_cleared = false;
3061 vport = phba->pport;
3063 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3066 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3067 "0458 Bring Adapter online\n");
3069 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
3071 if (phba->sli_rev == LPFC_SLI_REV4) {
3072 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3073 lpfc_unblock_mgmt_io(phba);
3076 spin_lock_irq(&phba->hbalock);
3077 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3078 vpis_cleared = true;
3079 spin_unlock_irq(&phba->hbalock);
3081 /* Reestablish the local initiator port.
3082 * The offline process destroyed the previous lport.
3084 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3085 !phba->nvmet_support) {
3086 error = lpfc_nvme_create_localport(phba->pport);
3088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3089 "6132 NVME restore reg failed "
3090 "on nvmei error x%x\n", error);
3093 lpfc_sli_queue_init(phba);
3094 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3095 lpfc_unblock_mgmt_io(phba);
3100 vports = lpfc_create_vport_work_array(phba);
3101 if (vports != NULL) {
3102 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3103 struct Scsi_Host *shost;
3104 shost = lpfc_shost_from_vport(vports[i]);
3105 spin_lock_irq(shost->host_lock);
3106 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3107 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3108 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3109 if (phba->sli_rev == LPFC_SLI_REV4) {
3110 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
3111 if ((vpis_cleared) &&
3112 (vports[i]->port_type !=
3113 LPFC_PHYSICAL_PORT))
3116 spin_unlock_irq(shost->host_lock);
3119 lpfc_destroy_vport_work_array(phba, vports);
3121 lpfc_unblock_mgmt_io(phba);
3126 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3127 * @phba: pointer to lpfc hba data structure.
3129 * This routine marks a HBA's management interface as not blocked. Once the
3130 * HBA's management interface is marked as not blocked, all the user space
3131 * access to the HBA, whether they are from sysfs interface or libdfc
3132 * interface will be allowed. The HBA is set to block the management interface
3133 * when the driver prepares the HBA interface for online or offline and then
3134 * set to unblock the management interface afterwards.
3137 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3139 unsigned long iflag;
3141 spin_lock_irqsave(&phba->hbalock, iflag);
3142 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3143 spin_unlock_irqrestore(&phba->hbalock, iflag);
3147 * lpfc_offline_prep - Prepare a HBA to be brought offline
3148 * @phba: pointer to lpfc hba data structure.
3150 * This routine is invoked to prepare a HBA to be brought offline. It performs
3151 * unregistration login to all the nodes on all vports and flushes the mailbox
3152 * queue to make it ready to be brought offline.
3155 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3157 struct lpfc_vport *vport = phba->pport;
3158 struct lpfc_nodelist *ndlp, *next_ndlp;
3159 struct lpfc_vport **vports;
3160 struct Scsi_Host *shost;
3163 if (vport->fc_flag & FC_OFFLINE_MODE)
3166 lpfc_block_mgmt_io(phba, mbx_action);
3168 lpfc_linkdown(phba);
3170 /* Issue an unreg_login to all nodes on all vports */
3171 vports = lpfc_create_vport_work_array(phba);
3172 if (vports != NULL) {
3173 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3174 if (vports[i]->load_flag & FC_UNLOADING)
3176 shost = lpfc_shost_from_vport(vports[i]);
3177 spin_lock_irq(shost->host_lock);
3178 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3179 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3180 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3181 spin_unlock_irq(shost->host_lock);
3183 shost = lpfc_shost_from_vport(vports[i]);
3184 list_for_each_entry_safe(ndlp, next_ndlp,
3185 &vports[i]->fc_nodes,
3187 if (!NLP_CHK_NODE_ACT(ndlp))
3189 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3191 if (ndlp->nlp_type & NLP_FABRIC) {
3192 lpfc_disc_state_machine(vports[i], ndlp,
3193 NULL, NLP_EVT_DEVICE_RECOVERY);
3194 lpfc_disc_state_machine(vports[i], ndlp,
3195 NULL, NLP_EVT_DEVICE_RM);
3197 spin_lock_irq(shost->host_lock);
3198 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3199 spin_unlock_irq(shost->host_lock);
3201 * Whenever an SLI4 port goes offline, free the
3202 * RPI. Get a new RPI when the adapter port
3203 * comes back online.
3205 if (phba->sli_rev == LPFC_SLI_REV4) {
3206 lpfc_printf_vlog(ndlp->vport,
3207 KERN_INFO, LOG_NODE,
3208 "0011 lpfc_offline: "
3210 "usgmap:x%x rpi:%x\n",
3211 ndlp, ndlp->nlp_DID,
3215 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3217 lpfc_unreg_rpi(vports[i], ndlp);
3221 lpfc_destroy_vport_work_array(phba, vports);
3223 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3227 * lpfc_offline - Bring a HBA offline
3228 * @phba: pointer to lpfc hba data structure.
3230 * This routine actually brings a HBA offline. It stops all the timers
3231 * associated with the HBA, brings down the SLI layer, and eventually
3232 * marks the HBA as in offline state for the upper layer protocol.
3235 lpfc_offline(struct lpfc_hba *phba)
3237 struct Scsi_Host *shost;
3238 struct lpfc_vport **vports;
3241 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3244 /* stop port and all timers associated with this hba */
3245 lpfc_stop_port(phba);
3247 /* Tear down the local and target port registrations. The
3248 * nvme transports need to cleanup.
3250 lpfc_nvmet_destroy_targetport(phba);
3251 lpfc_nvme_destroy_localport(phba->pport);
3253 vports = lpfc_create_vport_work_array(phba);
3255 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3256 lpfc_stop_vport_timers(vports[i]);
3257 lpfc_destroy_vport_work_array(phba, vports);
3258 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3259 "0460 Bring Adapter offline\n");
3260 /* Bring down the SLI Layer and cleanup. The HBA is offline
3262 lpfc_sli_hba_down(phba);
3263 spin_lock_irq(&phba->hbalock);
3265 spin_unlock_irq(&phba->hbalock);
3266 vports = lpfc_create_vport_work_array(phba);
3268 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3269 shost = lpfc_shost_from_vport(vports[i]);
3270 spin_lock_irq(shost->host_lock);
3271 vports[i]->work_port_events = 0;
3272 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3273 spin_unlock_irq(shost->host_lock);
3275 lpfc_destroy_vport_work_array(phba, vports);
3279 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3280 * @phba: pointer to lpfc hba data structure.
3282 * This routine is to free all the SCSI buffers and IOCBs from the driver
3283 * list back to kernel. It is called from lpfc_pci_remove_one to free
3284 * the internal resources before the device is removed from the system.
3287 lpfc_scsi_free(struct lpfc_hba *phba)
3289 struct lpfc_scsi_buf *sb, *sb_next;
3291 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3294 spin_lock_irq(&phba->hbalock);
3296 /* Release all the lpfc_scsi_bufs maintained by this host. */
3298 spin_lock(&phba->scsi_buf_list_put_lock);
3299 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3301 list_del(&sb->list);
3302 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3305 phba->total_scsi_bufs--;
3307 spin_unlock(&phba->scsi_buf_list_put_lock);
3309 spin_lock(&phba->scsi_buf_list_get_lock);
3310 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3312 list_del(&sb->list);
3313 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3316 phba->total_scsi_bufs--;
3318 spin_unlock(&phba->scsi_buf_list_get_lock);
3319 spin_unlock_irq(&phba->hbalock);
3322 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3323 * @phba: pointer to lpfc hba data structure.
3325 * This routine is to free all the NVME buffers and IOCBs from the driver
3326 * list back to kernel. It is called from lpfc_pci_remove_one to free
3327 * the internal resources before the device is removed from the system.
3330 lpfc_nvme_free(struct lpfc_hba *phba)
3332 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
3334 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3337 spin_lock_irq(&phba->hbalock);
3339 /* Release all the lpfc_nvme_bufs maintained by this host. */
3340 spin_lock(&phba->nvme_buf_list_put_lock);
3341 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3342 &phba->lpfc_nvme_buf_list_put, list) {
3343 list_del(&lpfc_ncmd->list);
3344 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3345 lpfc_ncmd->dma_handle);
3347 phba->total_nvme_bufs--;
3349 spin_unlock(&phba->nvme_buf_list_put_lock);
3351 spin_lock(&phba->nvme_buf_list_get_lock);
3352 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3353 &phba->lpfc_nvme_buf_list_get, list) {
3354 list_del(&lpfc_ncmd->list);
3355 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3356 lpfc_ncmd->dma_handle);
3358 phba->total_nvme_bufs--;
3360 spin_unlock(&phba->nvme_buf_list_get_lock);
3361 spin_unlock_irq(&phba->hbalock);
3364 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3365 * @phba: pointer to lpfc hba data structure.
3367 * This routine first calculates the sizes of the current els and allocated
3368 * scsi sgl lists, and then goes through all sgls to updates the physical
3369 * XRIs assigned due to port function reset. During port initialization, the
3370 * current els and allocated scsi sgl lists are 0s.
3373 * 0 - successful (for now, it always returns 0)
3376 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3378 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3379 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3380 LIST_HEAD(els_sgl_list);
3384 * update on pci function's els xri-sgl list
3386 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3388 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3389 /* els xri-sgl expanded */
3390 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3391 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3392 "3157 ELS xri-sgl count increased from "
3393 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3395 /* allocate the additional els sgls */
3396 for (i = 0; i < xri_cnt; i++) {
3397 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3399 if (sglq_entry == NULL) {
3400 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3401 "2562 Failure to allocate an "
3402 "ELS sgl entry:%d\n", i);
3406 sglq_entry->buff_type = GEN_BUFF_TYPE;
3407 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3409 if (sglq_entry->virt == NULL) {
3411 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3412 "2563 Failure to allocate an "
3413 "ELS mbuf:%d\n", i);
3417 sglq_entry->sgl = sglq_entry->virt;
3418 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3419 sglq_entry->state = SGL_FREED;
3420 list_add_tail(&sglq_entry->list, &els_sgl_list);
3422 spin_lock_irq(&phba->hbalock);
3423 spin_lock(&phba->sli4_hba.sgl_list_lock);
3424 list_splice_init(&els_sgl_list,
3425 &phba->sli4_hba.lpfc_els_sgl_list);
3426 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3427 spin_unlock_irq(&phba->hbalock);
3428 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3429 /* els xri-sgl shrinked */
3430 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3431 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3432 "3158 ELS xri-sgl count decreased from "
3433 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3435 spin_lock_irq(&phba->hbalock);
3436 spin_lock(&phba->sli4_hba.sgl_list_lock);
3437 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3439 /* release extra els sgls from list */
3440 for (i = 0; i < xri_cnt; i++) {
3441 list_remove_head(&els_sgl_list,
3442 sglq_entry, struct lpfc_sglq, list);
3444 __lpfc_mbuf_free(phba, sglq_entry->virt,
3449 list_splice_init(&els_sgl_list,
3450 &phba->sli4_hba.lpfc_els_sgl_list);
3451 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3452 spin_unlock_irq(&phba->hbalock);
3454 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3455 "3163 ELS xri-sgl count unchanged: %d\n",
3457 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3459 /* update xris to els sgls on the list */
3461 sglq_entry_next = NULL;
3462 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3463 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3464 lxri = lpfc_sli4_next_xritag(phba);
3465 if (lxri == NO_XRI) {
3466 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3467 "2400 Failed to allocate xri for "
3472 sglq_entry->sli4_lxritag = lxri;
3473 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3478 lpfc_free_els_sgl_list(phba);
3483 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3484 * @phba: pointer to lpfc hba data structure.
3486 * This routine first calculates the sizes of the current els and allocated
3487 * scsi sgl lists, and then goes through all sgls to updates the physical
3488 * XRIs assigned due to port function reset. During port initialization, the
3489 * current els and allocated scsi sgl lists are 0s.
3492 * 0 - successful (for now, it always returns 0)
3495 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3497 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3498 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3499 uint16_t nvmet_xri_cnt;
3500 LIST_HEAD(nvmet_sgl_list);
3504 * update on pci function's nvmet xri-sgl list
3506 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3508 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3509 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3510 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3511 /* els xri-sgl expanded */
3512 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3513 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3514 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3515 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3516 /* allocate the additional nvmet sgls */
3517 for (i = 0; i < xri_cnt; i++) {
3518 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3520 if (sglq_entry == NULL) {
3521 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3522 "6303 Failure to allocate an "
3523 "NVMET sgl entry:%d\n", i);
3527 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3528 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3530 if (sglq_entry->virt == NULL) {
3532 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3533 "6304 Failure to allocate an "
3534 "NVMET buf:%d\n", i);
3538 sglq_entry->sgl = sglq_entry->virt;
3539 memset(sglq_entry->sgl, 0,
3540 phba->cfg_sg_dma_buf_size);
3541 sglq_entry->state = SGL_FREED;
3542 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3544 spin_lock_irq(&phba->hbalock);
3545 spin_lock(&phba->sli4_hba.sgl_list_lock);
3546 list_splice_init(&nvmet_sgl_list,
3547 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3548 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3549 spin_unlock_irq(&phba->hbalock);
3550 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3551 /* nvmet xri-sgl shrunk */
3552 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3553 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3554 "6305 NVMET xri-sgl count decreased from "
3555 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3557 spin_lock_irq(&phba->hbalock);
3558 spin_lock(&phba->sli4_hba.sgl_list_lock);
3559 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3561 /* release extra nvmet sgls from list */
3562 for (i = 0; i < xri_cnt; i++) {
3563 list_remove_head(&nvmet_sgl_list,
3564 sglq_entry, struct lpfc_sglq, list);
3566 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3571 list_splice_init(&nvmet_sgl_list,
3572 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3573 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3574 spin_unlock_irq(&phba->hbalock);
3576 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3577 "6306 NVMET xri-sgl count unchanged: %d\n",
3579 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3581 /* update xris to nvmet sgls on the list */
3583 sglq_entry_next = NULL;
3584 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3585 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3586 lxri = lpfc_sli4_next_xritag(phba);
3587 if (lxri == NO_XRI) {
3588 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3589 "6307 Failed to allocate xri for "
3594 sglq_entry->sli4_lxritag = lxri;
3595 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3600 lpfc_free_nvmet_sgl_list(phba);
3605 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3606 * @phba: pointer to lpfc hba data structure.
3608 * This routine first calculates the sizes of the current els and allocated
3609 * scsi sgl lists, and then goes through all sgls to updates the physical
3610 * XRIs assigned due to port function reset. During port initialization, the
3611 * current els and allocated scsi sgl lists are 0s.
3614 * 0 - successful (for now, it always returns 0)
3617 lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3619 struct lpfc_scsi_buf *psb, *psb_next;
3620 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3621 LIST_HEAD(scsi_sgl_list);
3625 * update on pci function's els xri-sgl list
3627 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3628 phba->total_scsi_bufs = 0;
3631 * update on pci function's allocated scsi xri-sgl list
3633 /* maximum number of xris available for scsi buffers */
3634 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3637 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3640 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3641 phba->sli4_hba.scsi_xri_max = /* Split them up */
3642 (phba->sli4_hba.scsi_xri_max *
3643 phba->cfg_xri_split) / 100;
3645 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3646 spin_lock(&phba->scsi_buf_list_put_lock);
3647 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3648 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3649 spin_unlock(&phba->scsi_buf_list_put_lock);
3650 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3652 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3653 "6060 Current allocated SCSI xri-sgl count:%d, "
3654 "maximum SCSI xri count:%d (split:%d)\n",
3655 phba->sli4_hba.scsi_xri_cnt,
3656 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3658 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3659 /* max scsi xri shrinked below the allocated scsi buffers */
3660 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3661 phba->sli4_hba.scsi_xri_max;
3662 /* release the extra allocated scsi buffers */
3663 for (i = 0; i < scsi_xri_cnt; i++) {
3664 list_remove_head(&scsi_sgl_list, psb,
3665 struct lpfc_scsi_buf, list);
3667 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3668 psb->data, psb->dma_handle);
3672 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3673 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3674 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3677 /* update xris associated to remaining allocated scsi buffers */
3680 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3681 lxri = lpfc_sli4_next_xritag(phba);
3682 if (lxri == NO_XRI) {
3683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3684 "2560 Failed to allocate xri for "
3689 psb->cur_iocbq.sli4_lxritag = lxri;
3690 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3692 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3693 spin_lock(&phba->scsi_buf_list_put_lock);
3694 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3695 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3696 spin_unlock(&phba->scsi_buf_list_put_lock);
3697 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3701 lpfc_scsi_free(phba);
3706 lpfc_get_wwpn(struct lpfc_hba *phba)
3710 LPFC_MBOXQ_t *mboxq;
3713 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3716 return (uint64_t)-1;
3718 /* First get WWN of HBA instance */
3719 lpfc_read_nv(phba, mboxq);
3720 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3721 if (rc != MBX_SUCCESS) {
3722 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3723 "6019 Mailbox failed , mbxCmd x%x "
3724 "READ_NV, mbxStatus x%x\n",
3725 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3726 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3727 mempool_free(mboxq, phba->mbox_mem_pool);
3728 return (uint64_t) -1;
3731 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3732 /* wwn is WWPN of HBA instance */
3733 mempool_free(mboxq, phba->mbox_mem_pool);
3734 if (phba->sli_rev == LPFC_SLI_REV4)
3735 return be64_to_cpu(wwn);
3737 return rol64(wwn, 32);
3741 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3742 * @phba: pointer to lpfc hba data structure.
3744 * This routine first calculates the sizes of the current els and allocated
3745 * scsi sgl lists, and then goes through all sgls to updates the physical
3746 * XRIs assigned due to port function reset. During port initialization, the
3747 * current els and allocated scsi sgl lists are 0s.
3750 * 0 - successful (for now, it always returns 0)
3753 lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3755 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3756 uint16_t i, lxri, els_xri_cnt;
3757 uint16_t nvme_xri_cnt, nvme_xri_max;
3758 LIST_HEAD(nvme_sgl_list);
3761 phba->total_nvme_bufs = 0;
3763 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3766 * update on pci function's allocated nvme xri-sgl list
3769 /* maximum number of xris available for nvme buffers */
3770 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3771 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3772 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3773 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3775 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3776 "6074 Current allocated NVME xri-sgl count:%d, "
3777 "maximum NVME xri count:%d\n",
3778 phba->sli4_hba.nvme_xri_cnt,
3779 phba->sli4_hba.nvme_xri_max);
3781 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3782 spin_lock(&phba->nvme_buf_list_put_lock);
3783 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3784 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3785 spin_unlock(&phba->nvme_buf_list_put_lock);
3786 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3788 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3789 /* max nvme xri shrunk below the allocated nvme buffers */
3790 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3791 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3792 phba->sli4_hba.nvme_xri_max;
3793 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3794 /* release the extra allocated nvme buffers */
3795 for (i = 0; i < nvme_xri_cnt; i++) {
3796 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3797 struct lpfc_nvme_buf, list);
3799 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3801 lpfc_ncmd->dma_handle);
3805 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3806 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3807 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3810 /* update xris associated to remaining allocated nvme buffers */
3812 lpfc_ncmd_next = NULL;
3813 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3814 &nvme_sgl_list, list) {
3815 lxri = lpfc_sli4_next_xritag(phba);
3816 if (lxri == NO_XRI) {
3817 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3818 "6075 Failed to allocate xri for "
3823 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3824 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3826 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3827 spin_lock(&phba->nvme_buf_list_put_lock);
3828 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3829 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3830 spin_unlock(&phba->nvme_buf_list_put_lock);
3831 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3835 lpfc_nvme_free(phba);
3840 * lpfc_create_port - Create an FC port
3841 * @phba: pointer to lpfc hba data structure.
3842 * @instance: a unique integer ID to this FC port.
3843 * @dev: pointer to the device data structure.
3845 * This routine creates a FC port for the upper layer protocol. The FC port
3846 * can be created on top of either a physical port or a virtual port provided
3847 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3848 * and associates the FC port created before adding the shost into the SCSI
3852 * @vport - pointer to the virtual N_Port data structure.
3853 * NULL - port create failed.
3856 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3858 struct lpfc_vport *vport;
3859 struct Scsi_Host *shost = NULL;
3863 bool use_no_reset_hba = false;
3866 if (lpfc_no_hba_reset_cnt) {
3867 if (phba->sli_rev < LPFC_SLI_REV4 &&
3868 dev == &phba->pcidev->dev) {
3869 /* Reset the port first */
3870 lpfc_sli_brdrestart(phba);
3871 rc = lpfc_sli_chipset_init(phba);
3875 wwn = lpfc_get_wwpn(phba);
3878 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3879 if (wwn == lpfc_no_hba_reset[i]) {
3880 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3881 "6020 Setting use_no_reset port=%llx\n",
3883 use_no_reset_hba = true;
3888 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3889 if (dev != &phba->pcidev->dev) {
3890 shost = scsi_host_alloc(&lpfc_vport_template,
3891 sizeof(struct lpfc_vport));
3893 if (!use_no_reset_hba)
3894 shost = scsi_host_alloc(&lpfc_template,
3895 sizeof(struct lpfc_vport));
3897 shost = scsi_host_alloc(&lpfc_template_no_hr,
3898 sizeof(struct lpfc_vport));
3900 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3901 shost = scsi_host_alloc(&lpfc_template_nvme,
3902 sizeof(struct lpfc_vport));
3907 vport = (struct lpfc_vport *) shost->hostdata;
3909 vport->load_flag |= FC_LOADING;
3910 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3911 vport->fc_rscn_flush = 0;
3912 lpfc_get_vport_cfgparam(vport);
3914 shost->unique_id = instance;
3915 shost->max_id = LPFC_MAX_TARGET;
3916 shost->max_lun = vport->cfg_max_luns;
3917 shost->this_id = -1;
3918 shost->max_cmd_len = 16;
3919 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
3920 if (phba->sli_rev == LPFC_SLI_REV4) {
3921 shost->dma_boundary =
3922 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
3923 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3927 * Set initial can_queue value since 0 is no longer supported and
3928 * scsi_add_host will fail. This will be adjusted later based on the
3929 * max xri value determined in hba setup.
3931 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3932 if (dev != &phba->pcidev->dev) {
3933 shost->transportt = lpfc_vport_transport_template;
3934 vport->port_type = LPFC_NPIV_PORT;
3936 shost->transportt = lpfc_transport_template;
3937 vport->port_type = LPFC_PHYSICAL_PORT;
3940 /* Initialize all internally managed lists. */
3941 INIT_LIST_HEAD(&vport->fc_nodes);
3942 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3943 spin_lock_init(&vport->work_port_lock);
3945 setup_timer(&vport->fc_disctmo, lpfc_disc_timeout,
3946 (unsigned long)vport);
3948 setup_timer(&vport->els_tmofunc, lpfc_els_timeout,
3949 (unsigned long)vport);
3951 setup_timer(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo,
3952 (unsigned long)vport);
3954 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
3958 spin_lock_irq(&phba->hbalock);
3959 list_add_tail(&vport->listentry, &phba->port_list);
3960 spin_unlock_irq(&phba->hbalock);
3964 scsi_host_put(shost);
3970 * destroy_port - destroy an FC port
3971 * @vport: pointer to an lpfc virtual N_Port data structure.
3973 * This routine destroys a FC port from the upper layer protocol. All the
3974 * resources associated with the port are released.
3977 destroy_port(struct lpfc_vport *vport)
3979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3980 struct lpfc_hba *phba = vport->phba;
3982 lpfc_debugfs_terminate(vport);
3983 fc_remove_host(shost);
3984 scsi_remove_host(shost);
3986 spin_lock_irq(&phba->hbalock);
3987 list_del_init(&vport->listentry);
3988 spin_unlock_irq(&phba->hbalock);
3990 lpfc_cleanup(vport);
3995 * lpfc_get_instance - Get a unique integer ID
3997 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3998 * uses the kernel idr facility to perform the task.
4001 * instance - a unique integer ID allocated as the new instance.
4002 * -1 - lpfc get instance failed.
4005 lpfc_get_instance(void)
4009 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4010 return ret < 0 ? -1 : ret;
4014 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4015 * @shost: pointer to SCSI host data structure.
4016 * @time: elapsed time of the scan in jiffies.
4018 * This routine is called by the SCSI layer with a SCSI host to determine
4019 * whether the scan host is finished.
4021 * Note: there is no scan_start function as adapter initialization will have
4022 * asynchronously kicked off the link initialization.
4025 * 0 - SCSI host scan is not over yet.
4026 * 1 - SCSI host scan is over.
4028 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4031 struct lpfc_hba *phba = vport->phba;
4034 spin_lock_irq(shost->host_lock);
4036 if (vport->load_flag & FC_UNLOADING) {
4040 if (time >= msecs_to_jiffies(30 * 1000)) {
4041 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4042 "0461 Scanning longer than 30 "
4043 "seconds. Continuing initialization\n");
4047 if (time >= msecs_to_jiffies(15 * 1000) &&
4048 phba->link_state <= LPFC_LINK_DOWN) {
4049 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4050 "0465 Link down longer than 15 "
4051 "seconds. Continuing initialization\n");
4056 if (vport->port_state != LPFC_VPORT_READY)
4058 if (vport->num_disc_nodes || vport->fc_prli_sent)
4060 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4062 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
4068 spin_unlock_irq(shost->host_lock);
4073 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4074 * @shost: pointer to SCSI host data structure.
4076 * This routine initializes a given SCSI host attributes on a FC port. The
4077 * SCSI host can be either on top of a physical port or a virtual port.
4079 void lpfc_host_attrib_init(struct Scsi_Host *shost)
4081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4082 struct lpfc_hba *phba = vport->phba;
4084 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4087 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4088 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
4089 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4091 memset(fc_host_supported_fc4s(shost), 0,
4092 sizeof(fc_host_supported_fc4s(shost)));
4093 fc_host_supported_fc4s(shost)[2] = 1;
4094 fc_host_supported_fc4s(shost)[7] = 1;
4096 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4097 sizeof fc_host_symbolic_name(shost));
4099 fc_host_supported_speeds(shost) = 0;
4100 if (phba->lmt & LMT_32Gb)
4101 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4102 if (phba->lmt & LMT_16Gb)
4103 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4104 if (phba->lmt & LMT_10Gb)
4105 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4106 if (phba->lmt & LMT_8Gb)
4107 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4108 if (phba->lmt & LMT_4Gb)
4109 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4110 if (phba->lmt & LMT_2Gb)
4111 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4112 if (phba->lmt & LMT_1Gb)
4113 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4115 fc_host_maxframe_size(shost) =
4116 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4117 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
4119 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4121 /* This value is also unchanging */
4122 memset(fc_host_active_fc4s(shost), 0,
4123 sizeof(fc_host_active_fc4s(shost)));
4124 fc_host_active_fc4s(shost)[2] = 1;
4125 fc_host_active_fc4s(shost)[7] = 1;
4127 fc_host_max_npiv_vports(shost) = phba->max_vpi;
4128 spin_lock_irq(shost->host_lock);
4129 vport->load_flag &= ~FC_LOADING;
4130 spin_unlock_irq(shost->host_lock);
4134 * lpfc_stop_port_s3 - Stop SLI3 device port
4135 * @phba: pointer to lpfc hba data structure.
4137 * This routine is invoked to stop an SLI3 device port, it stops the device
4138 * from generating interrupts and stops the device driver's timers for the
4142 lpfc_stop_port_s3(struct lpfc_hba *phba)
4144 /* Clear all interrupt enable conditions */
4145 writel(0, phba->HCregaddr);
4146 readl(phba->HCregaddr); /* flush */
4147 /* Clear all pending interrupts */
4148 writel(0xffffffff, phba->HAregaddr);
4149 readl(phba->HAregaddr); /* flush */
4151 /* Reset some HBA SLI setup states */
4152 lpfc_stop_hba_timers(phba);
4153 phba->pport->work_port_events = 0;
4157 * lpfc_stop_port_s4 - Stop SLI4 device port
4158 * @phba: pointer to lpfc hba data structure.
4160 * This routine is invoked to stop an SLI4 device port, it stops the device
4161 * from generating interrupts and stops the device driver's timers for the
4165 lpfc_stop_port_s4(struct lpfc_hba *phba)
4167 /* Reset some HBA SLI4 setup states */
4168 lpfc_stop_hba_timers(phba);
4169 phba->pport->work_port_events = 0;
4170 phba->sli4_hba.intr_enable = 0;
4174 * lpfc_stop_port - Wrapper function for stopping hba port
4175 * @phba: Pointer to HBA context object.
4177 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4178 * the API jump table function pointer from the lpfc_hba struct.
4181 lpfc_stop_port(struct lpfc_hba *phba)
4183 phba->lpfc_stop_port(phba);
4187 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4188 * @phba: Pointer to hba for which this call is being executed.
4190 * This routine starts the timer waiting for the FCF rediscovery to complete.
4193 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4195 unsigned long fcf_redisc_wait_tmo =
4196 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4197 /* Start fcf rediscovery wait period timer */
4198 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4199 spin_lock_irq(&phba->hbalock);
4200 /* Allow action to new fcf asynchronous event */
4201 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4202 /* Mark the FCF rediscovery pending state */
4203 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4204 spin_unlock_irq(&phba->hbalock);
4208 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4209 * @ptr: Map to lpfc_hba data structure pointer.
4211 * This routine is invoked when waiting for FCF table rediscover has been
4212 * timed out. If new FCF record(s) has (have) been discovered during the
4213 * wait period, a new FCF event shall be added to the FCOE async event
4214 * list, and then worker thread shall be waked up for processing from the
4215 * worker thread context.
4218 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
4220 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
4222 /* Don't send FCF rediscovery event if timer cancelled */
4223 spin_lock_irq(&phba->hbalock);
4224 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4225 spin_unlock_irq(&phba->hbalock);
4228 /* Clear FCF rediscovery timer pending flag */
4229 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4230 /* FCF rediscovery event to worker thread */
4231 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4232 spin_unlock_irq(&phba->hbalock);
4233 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4234 "2776 FCF rediscover quiescent timer expired\n");
4235 /* wake up worker thread */
4236 lpfc_worker_wake_up(phba);
4240 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4241 * @phba: pointer to lpfc hba data structure.
4242 * @acqe_link: pointer to the async link completion queue entry.
4244 * This routine is to parse the SLI4 link-attention link fault code and
4245 * translate it into the base driver's read link attention mailbox command
4248 * Return: Link-attention status in terms of base driver's coding.
4251 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4252 struct lpfc_acqe_link *acqe_link)
4254 uint16_t latt_fault;
4256 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4257 case LPFC_ASYNC_LINK_FAULT_NONE:
4258 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4259 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4264 "0398 Invalid link fault code: x%x\n",
4265 bf_get(lpfc_acqe_link_fault, acqe_link));
4266 latt_fault = MBXERR_ERROR;
4273 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4274 * @phba: pointer to lpfc hba data structure.
4275 * @acqe_link: pointer to the async link completion queue entry.
4277 * This routine is to parse the SLI4 link attention type and translate it
4278 * into the base driver's link attention type coding.
4280 * Return: Link attention type in terms of base driver's coding.
4283 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4284 struct lpfc_acqe_link *acqe_link)
4288 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4289 case LPFC_ASYNC_LINK_STATUS_DOWN:
4290 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
4291 att_type = LPFC_ATT_LINK_DOWN;
4293 case LPFC_ASYNC_LINK_STATUS_UP:
4294 /* Ignore physical link up events - wait for logical link up */
4295 att_type = LPFC_ATT_RESERVED;
4297 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
4298 att_type = LPFC_ATT_LINK_UP;
4301 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4302 "0399 Invalid link attention type: x%x\n",
4303 bf_get(lpfc_acqe_link_status, acqe_link));
4304 att_type = LPFC_ATT_RESERVED;
4311 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4312 * @phba: pointer to lpfc hba data structure.
4314 * This routine is to get an SLI3 FC port's link speed in Mbps.
4316 * Return: link speed in terms of Mbps.
4319 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4321 uint32_t link_speed;
4323 if (!lpfc_is_link_up(phba))
4326 if (phba->sli_rev <= LPFC_SLI_REV3) {
4327 switch (phba->fc_linkspeed) {
4328 case LPFC_LINK_SPEED_1GHZ:
4331 case LPFC_LINK_SPEED_2GHZ:
4334 case LPFC_LINK_SPEED_4GHZ:
4337 case LPFC_LINK_SPEED_8GHZ:
4340 case LPFC_LINK_SPEED_10GHZ:
4343 case LPFC_LINK_SPEED_16GHZ:
4350 if (phba->sli4_hba.link_state.logical_speed)
4352 phba->sli4_hba.link_state.logical_speed;
4354 link_speed = phba->sli4_hba.link_state.speed;
4360 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4361 * @phba: pointer to lpfc hba data structure.
4362 * @evt_code: asynchronous event code.
4363 * @speed_code: asynchronous event link speed code.
4365 * This routine is to parse the giving SLI4 async event link speed code into
4366 * value of Mbps for the link speed.
4368 * Return: link speed in terms of Mbps.
4371 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4374 uint32_t port_speed;
4377 case LPFC_TRAILER_CODE_LINK:
4378 switch (speed_code) {
4379 case LPFC_ASYNC_LINK_SPEED_ZERO:
4382 case LPFC_ASYNC_LINK_SPEED_10MBPS:
4385 case LPFC_ASYNC_LINK_SPEED_100MBPS:
4388 case LPFC_ASYNC_LINK_SPEED_1GBPS:
4391 case LPFC_ASYNC_LINK_SPEED_10GBPS:
4394 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4397 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4400 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4407 case LPFC_TRAILER_CODE_FC:
4408 switch (speed_code) {
4409 case LPFC_FC_LA_SPEED_UNKNOWN:
4412 case LPFC_FC_LA_SPEED_1G:
4415 case LPFC_FC_LA_SPEED_2G:
4418 case LPFC_FC_LA_SPEED_4G:
4421 case LPFC_FC_LA_SPEED_8G:
4424 case LPFC_FC_LA_SPEED_10G:
4427 case LPFC_FC_LA_SPEED_16G:
4430 case LPFC_FC_LA_SPEED_32G:
4444 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4445 * @phba: pointer to lpfc hba data structure.
4446 * @acqe_link: pointer to the async link completion queue entry.
4448 * This routine is to handle the SLI4 asynchronous FCoE link event.
4451 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4452 struct lpfc_acqe_link *acqe_link)
4454 struct lpfc_dmabuf *mp;
4457 struct lpfc_mbx_read_top *la;
4461 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
4462 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
4464 phba->fcoe_eventtag = acqe_link->event_tag;
4465 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4467 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4468 "0395 The mboxq allocation failed\n");
4471 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4473 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4474 "0396 The lpfc_dmabuf allocation failed\n");
4477 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4479 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4480 "0397 The mbuf allocation failed\n");
4481 goto out_free_dmabuf;
4484 /* Cleanup any outstanding ELS commands */
4485 lpfc_els_flush_all_cmd(phba);
4487 /* Block ELS IOCBs until we have done process link event */
4488 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4490 /* Update link event statistics */
4491 phba->sli.slistat.link_event++;
4493 /* Create lpfc_handle_latt mailbox command from link ACQE */
4494 lpfc_read_topology(phba, pmb, mp);
4495 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4496 pmb->vport = phba->pport;
4498 /* Keep the link status for extra SLI4 state machine reference */
4499 phba->sli4_hba.link_state.speed =
4500 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4501 bf_get(lpfc_acqe_link_speed, acqe_link));
4502 phba->sli4_hba.link_state.duplex =
4503 bf_get(lpfc_acqe_link_duplex, acqe_link);
4504 phba->sli4_hba.link_state.status =
4505 bf_get(lpfc_acqe_link_status, acqe_link);
4506 phba->sli4_hba.link_state.type =
4507 bf_get(lpfc_acqe_link_type, acqe_link);
4508 phba->sli4_hba.link_state.number =
4509 bf_get(lpfc_acqe_link_number, acqe_link);
4510 phba->sli4_hba.link_state.fault =
4511 bf_get(lpfc_acqe_link_fault, acqe_link);
4512 phba->sli4_hba.link_state.logical_speed =
4513 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4515 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4516 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4517 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4518 "Logical speed:%dMbps Fault:%d\n",
4519 phba->sli4_hba.link_state.speed,
4520 phba->sli4_hba.link_state.topology,
4521 phba->sli4_hba.link_state.status,
4522 phba->sli4_hba.link_state.type,
4523 phba->sli4_hba.link_state.number,
4524 phba->sli4_hba.link_state.logical_speed,
4525 phba->sli4_hba.link_state.fault);
4527 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4528 * topology info. Note: Optional for non FC-AL ports.
4530 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4531 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4532 if (rc == MBX_NOT_FINISHED)
4533 goto out_free_dmabuf;
4537 * For FCoE Mode: fill in all the topology information we need and call
4538 * the READ_TOPOLOGY completion routine to continue without actually
4539 * sending the READ_TOPOLOGY mailbox command to the port.
4541 /* Parse and translate status field */
4543 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4545 /* Parse and translate link attention fields */
4546 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4547 la->eventTag = acqe_link->event_tag;
4548 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4549 bf_set(lpfc_mbx_read_top_link_spd, la,
4550 (bf_get(lpfc_acqe_link_speed, acqe_link)));
4552 /* Fake the the following irrelvant fields */
4553 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4554 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4555 bf_set(lpfc_mbx_read_top_il, la, 0);
4556 bf_set(lpfc_mbx_read_top_pb, la, 0);
4557 bf_set(lpfc_mbx_read_top_fa, la, 0);
4558 bf_set(lpfc_mbx_read_top_mm, la, 0);
4560 /* Invoke the lpfc_handle_latt mailbox command callback function */
4561 lpfc_mbx_cmpl_read_topology(phba, pmb);
4568 mempool_free(pmb, phba->mbox_mem_pool);
4572 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4573 * @phba: pointer to lpfc hba data structure.
4574 * @acqe_fc: pointer to the async fc completion queue entry.
4576 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4577 * that the event was received and then issue a read_topology mailbox command so
4578 * that the rest of the driver will treat it the same as SLI3.
4581 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4583 struct lpfc_dmabuf *mp;
4586 struct lpfc_mbx_read_top *la;
4589 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4590 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4591 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4592 "2895 Non FC link Event detected.(%d)\n",
4593 bf_get(lpfc_trailer_type, acqe_fc));
4596 /* Keep the link status for extra SLI4 state machine reference */
4597 phba->sli4_hba.link_state.speed =
4598 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4599 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4600 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4601 phba->sli4_hba.link_state.topology =
4602 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4603 phba->sli4_hba.link_state.status =
4604 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4605 phba->sli4_hba.link_state.type =
4606 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4607 phba->sli4_hba.link_state.number =
4608 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4609 phba->sli4_hba.link_state.fault =
4610 bf_get(lpfc_acqe_link_fault, acqe_fc);
4611 phba->sli4_hba.link_state.logical_speed =
4612 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
4613 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4614 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4615 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4616 "%dMbps Fault:%d\n",
4617 phba->sli4_hba.link_state.speed,
4618 phba->sli4_hba.link_state.topology,
4619 phba->sli4_hba.link_state.status,
4620 phba->sli4_hba.link_state.type,
4621 phba->sli4_hba.link_state.number,
4622 phba->sli4_hba.link_state.logical_speed,
4623 phba->sli4_hba.link_state.fault);
4624 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4626 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4627 "2897 The mboxq allocation failed\n");
4630 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4632 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4633 "2898 The lpfc_dmabuf allocation failed\n");
4636 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4638 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4639 "2899 The mbuf allocation failed\n");
4640 goto out_free_dmabuf;
4643 /* Cleanup any outstanding ELS commands */
4644 lpfc_els_flush_all_cmd(phba);
4646 /* Block ELS IOCBs until we have done process link event */
4647 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4649 /* Update link event statistics */
4650 phba->sli.slistat.link_event++;
4652 /* Create lpfc_handle_latt mailbox command from link ACQE */
4653 lpfc_read_topology(phba, pmb, mp);
4654 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4655 pmb->vport = phba->pport;
4657 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4658 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4660 switch (phba->sli4_hba.link_state.status) {
4661 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4662 phba->link_flag |= LS_MDS_LINK_DOWN;
4664 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4665 phba->link_flag |= LS_MDS_LOOPBACK;
4671 /* Parse and translate status field */
4673 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4676 /* Parse and translate link attention fields */
4677 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4678 la->eventTag = acqe_fc->event_tag;
4680 if (phba->sli4_hba.link_state.status ==
4681 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4682 bf_set(lpfc_mbx_read_top_att_type, la,
4683 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4685 bf_set(lpfc_mbx_read_top_att_type, la,
4686 LPFC_FC_LA_TYPE_LINK_DOWN);
4688 /* Invoke the mailbox command callback function */
4689 lpfc_mbx_cmpl_read_topology(phba, pmb);
4694 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4695 if (rc == MBX_NOT_FINISHED)
4696 goto out_free_dmabuf;
4702 mempool_free(pmb, phba->mbox_mem_pool);
4706 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4707 * @phba: pointer to lpfc hba data structure.
4708 * @acqe_fc: pointer to the async SLI completion queue entry.
4710 * This routine is to handle the SLI4 asynchronous SLI events.
4713 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4719 uint8_t operational = 0;
4720 struct temp_event temp_event_data;
4721 struct lpfc_acqe_misconfigured_event *misconfigured;
4722 struct Scsi_Host *shost;
4724 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4726 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4727 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4728 "x%08x SLI Event Type:%d\n",
4729 acqe_sli->event_data1, acqe_sli->event_data2,
4732 port_name = phba->Port[0];
4733 if (port_name == 0x00)
4734 port_name = '?'; /* get port name is empty */
4737 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4738 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4739 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4740 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4742 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4743 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4744 acqe_sli->event_data1, port_name);
4746 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
4747 shost = lpfc_shost_from_vport(phba->pport);
4748 fc_host_post_vendor_event(shost, fc_get_event_number(),
4749 sizeof(temp_event_data),
4750 (char *)&temp_event_data,
4751 SCSI_NL_VID_TYPE_PCI
4752 | PCI_VENDOR_ID_EMULEX);
4754 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4755 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4756 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4757 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4759 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4760 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4761 acqe_sli->event_data1, port_name);
4763 shost = lpfc_shost_from_vport(phba->pport);
4764 fc_host_post_vendor_event(shost, fc_get_event_number(),
4765 sizeof(temp_event_data),
4766 (char *)&temp_event_data,
4767 SCSI_NL_VID_TYPE_PCI
4768 | PCI_VENDOR_ID_EMULEX);
4770 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4771 misconfigured = (struct lpfc_acqe_misconfigured_event *)
4772 &acqe_sli->event_data1;
4774 /* fetch the status for this port */
4775 switch (phba->sli4_hba.lnk_info.lnk_no) {
4776 case LPFC_LINK_NUMBER_0:
4777 status = bf_get(lpfc_sli_misconfigured_port0_state,
4778 &misconfigured->theEvent);
4779 operational = bf_get(lpfc_sli_misconfigured_port0_op,
4780 &misconfigured->theEvent);
4782 case LPFC_LINK_NUMBER_1:
4783 status = bf_get(lpfc_sli_misconfigured_port1_state,
4784 &misconfigured->theEvent);
4785 operational = bf_get(lpfc_sli_misconfigured_port1_op,
4786 &misconfigured->theEvent);
4788 case LPFC_LINK_NUMBER_2:
4789 status = bf_get(lpfc_sli_misconfigured_port2_state,
4790 &misconfigured->theEvent);
4791 operational = bf_get(lpfc_sli_misconfigured_port2_op,
4792 &misconfigured->theEvent);
4794 case LPFC_LINK_NUMBER_3:
4795 status = bf_get(lpfc_sli_misconfigured_port3_state,
4796 &misconfigured->theEvent);
4797 operational = bf_get(lpfc_sli_misconfigured_port3_op,
4798 &misconfigured->theEvent);
4801 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4803 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4804 "event: Invalid link %d",
4805 phba->sli4_hba.lnk_info.lnk_no);
4809 /* Skip if optic state unchanged */
4810 if (phba->sli4_hba.lnk_info.optic_state == status)
4814 case LPFC_SLI_EVENT_STATUS_VALID:
4815 sprintf(message, "Physical Link is functional");
4817 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4818 sprintf(message, "Optics faulted/incorrectly "
4819 "installed/not installed - Reseat optics, "
4820 "if issue not resolved, replace.");
4822 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4824 "Optics of two types installed - Remove one "
4825 "optic or install matching pair of optics.");
4827 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4828 sprintf(message, "Incompatible optics - Replace with "
4829 "compatible optics for card to function.");
4831 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4832 sprintf(message, "Unqualified optics - Replace with "
4833 "Avago optics for Warranty and Technical "
4834 "Support - Link is%s operational",
4835 (operational) ? " not" : "");
4837 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4838 sprintf(message, "Uncertified optics - Replace with "
4839 "Avago-certified optics to enable link "
4840 "operation - Link is%s operational",
4841 (operational) ? " not" : "");
4844 /* firmware is reporting a status we don't know about */
4845 sprintf(message, "Unknown event status x%02x", status);
4848 phba->sli4_hba.lnk_info.optic_state = status;
4849 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4850 "3176 Port Name %c %s\n", port_name, message);
4852 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4853 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4854 "3192 Remote DPort Test Initiated - "
4855 "Event Data1:x%08x Event Data2: x%08x\n",
4856 acqe_sli->event_data1, acqe_sli->event_data2);
4859 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4860 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4861 "x%08x SLI Event Type:%d\n",
4862 acqe_sli->event_data1, acqe_sli->event_data2,
4869 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4870 * @vport: pointer to vport data structure.
4872 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4873 * response to a CVL event.
4875 * Return the pointer to the ndlp with the vport if successful, otherwise
4878 static struct lpfc_nodelist *
4879 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4881 struct lpfc_nodelist *ndlp;
4882 struct Scsi_Host *shost;
4883 struct lpfc_hba *phba;
4890 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4892 /* Cannot find existing Fabric ndlp, so allocate a new one */
4893 ndlp = lpfc_nlp_init(vport, Fabric_DID);
4896 /* Set the node type */
4897 ndlp->nlp_type |= NLP_FABRIC;
4898 /* Put ndlp onto node list */
4899 lpfc_enqueue_node(vport, ndlp);
4900 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4901 /* re-setup ndlp without removing from node list */
4902 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4906 if ((phba->pport->port_state < LPFC_FLOGI) &&
4907 (phba->pport->port_state != LPFC_VPORT_FAILED))
4909 /* If virtual link is not yet instantiated ignore CVL */
4910 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4911 && (vport->port_state != LPFC_VPORT_FAILED))
4913 shost = lpfc_shost_from_vport(vport);
4916 lpfc_linkdown_port(vport);
4917 lpfc_cleanup_pending_mbox(vport);
4918 spin_lock_irq(shost->host_lock);
4919 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4920 spin_unlock_irq(shost->host_lock);
4926 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4927 * @vport: pointer to lpfc hba data structure.
4929 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4930 * response to a FCF dead event.
4933 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4935 struct lpfc_vport **vports;
4938 vports = lpfc_create_vport_work_array(phba);
4940 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4941 lpfc_sli4_perform_vport_cvl(vports[i]);
4942 lpfc_destroy_vport_work_array(phba, vports);
4946 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4947 * @phba: pointer to lpfc hba data structure.
4948 * @acqe_link: pointer to the async fcoe completion queue entry.
4950 * This routine is to handle the SLI4 asynchronous fcoe event.
4953 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4954 struct lpfc_acqe_fip *acqe_fip)
4956 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
4958 struct lpfc_vport *vport;
4959 struct lpfc_nodelist *ndlp;
4960 struct Scsi_Host *shost;
4961 int active_vlink_present;
4962 struct lpfc_vport **vports;
4965 phba->fc_eventTag = acqe_fip->event_tag;
4966 phba->fcoe_eventtag = acqe_fip->event_tag;
4967 switch (event_type) {
4968 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4969 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4970 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
4971 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4973 "2546 New FCF event, evt_tag:x%x, "
4975 acqe_fip->event_tag,
4978 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4980 "2788 FCF param modified event, "
4981 "evt_tag:x%x, index:x%x\n",
4982 acqe_fip->event_tag,
4984 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4986 * During period of FCF discovery, read the FCF
4987 * table record indexed by the event to update
4988 * FCF roundrobin failover eligible FCF bmask.
4990 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4992 "2779 Read FCF (x%x) for updating "
4993 "roundrobin FCF failover bmask\n",
4995 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
4998 /* If the FCF discovery is in progress, do nothing. */
4999 spin_lock_irq(&phba->hbalock);
5000 if (phba->hba_flag & FCF_TS_INPROG) {
5001 spin_unlock_irq(&phba->hbalock);
5004 /* If fast FCF failover rescan event is pending, do nothing */
5005 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
5006 spin_unlock_irq(&phba->hbalock);
5010 /* If the FCF has been in discovered state, do nothing. */
5011 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
5012 spin_unlock_irq(&phba->hbalock);
5015 spin_unlock_irq(&phba->hbalock);
5017 /* Otherwise, scan the entire FCF table and re-discover SAN */
5018 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5019 "2770 Start FCF table scan per async FCF "
5020 "event, evt_tag:x%x, index:x%x\n",
5021 acqe_fip->event_tag, acqe_fip->index);
5022 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5023 LPFC_FCOE_FCF_GET_FIRST);
5025 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5026 "2547 Issue FCF scan read FCF mailbox "
5027 "command failed (x%x)\n", rc);
5030 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
5031 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5032 "2548 FCF Table full count 0x%x tag 0x%x\n",
5033 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5034 acqe_fip->event_tag);
5037 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
5038 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5039 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5040 "2549 FCF (x%x) disconnected from network, "
5041 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
5043 * If we are in the middle of FCF failover process, clear
5044 * the corresponding FCF bit in the roundrobin bitmap.
5046 spin_lock_irq(&phba->hbalock);
5047 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5048 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
5049 spin_unlock_irq(&phba->hbalock);
5050 /* Update FLOGI FCF failover eligible FCF bmask */
5051 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
5054 spin_unlock_irq(&phba->hbalock);
5056 /* If the event is not for currently used fcf do nothing */
5057 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
5061 * Otherwise, request the port to rediscover the entire FCF
5062 * table for a fast recovery from case that the current FCF
5063 * is no longer valid as we are not in the middle of FCF
5064 * failover process already.
5066 spin_lock_irq(&phba->hbalock);
5067 /* Mark the fast failover process in progress */
5068 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5069 spin_unlock_irq(&phba->hbalock);
5071 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5072 "2771 Start FCF fast failover process due to "
5073 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5074 "\n", acqe_fip->event_tag, acqe_fip->index);
5075 rc = lpfc_sli4_redisc_fcf_table(phba);
5077 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5079 "2772 Issue FCF rediscover mabilbox "
5080 "command failed, fail through to FCF "
5082 spin_lock_irq(&phba->hbalock);
5083 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5084 spin_unlock_irq(&phba->hbalock);
5086 * Last resort will fail over by treating this
5087 * as a link down to FCF registration.
5089 lpfc_sli4_fcf_dead_failthrough(phba);
5091 /* Reset FCF roundrobin bmask for new discovery */
5092 lpfc_sli4_clear_fcf_rr_bmask(phba);
5094 * Handling fast FCF failover to a DEAD FCF event is
5095 * considered equalivant to receiving CVL to all vports.
5097 lpfc_sli4_perform_all_vport_cvl(phba);
5100 case LPFC_FIP_EVENT_TYPE_CVL:
5101 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
5102 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5103 "2718 Clear Virtual Link Received for VPI 0x%x"
5104 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
5106 vport = lpfc_find_vport_by_vpid(phba,
5108 ndlp = lpfc_sli4_perform_vport_cvl(vport);
5111 active_vlink_present = 0;
5113 vports = lpfc_create_vport_work_array(phba);
5115 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5117 if ((!(vports[i]->fc_flag &
5118 FC_VPORT_CVL_RCVD)) &&
5119 (vports[i]->port_state > LPFC_FDISC)) {
5120 active_vlink_present = 1;
5124 lpfc_destroy_vport_work_array(phba, vports);
5128 * Don't re-instantiate if vport is marked for deletion.
5129 * If we are here first then vport_delete is going to wait
5130 * for discovery to complete.
5132 if (!(vport->load_flag & FC_UNLOADING) &&
5133 active_vlink_present) {
5135 * If there are other active VLinks present,
5136 * re-instantiate the Vlink using FDISC.
5138 mod_timer(&ndlp->nlp_delayfunc,
5139 jiffies + msecs_to_jiffies(1000));
5140 shost = lpfc_shost_from_vport(vport);
5141 spin_lock_irq(shost->host_lock);
5142 ndlp->nlp_flag |= NLP_DELAY_TMO;
5143 spin_unlock_irq(shost->host_lock);
5144 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5145 vport->port_state = LPFC_FDISC;
5148 * Otherwise, we request port to rediscover
5149 * the entire FCF table for a fast recovery
5150 * from possible case that the current FCF
5151 * is no longer valid if we are not already
5152 * in the FCF failover process.
5154 spin_lock_irq(&phba->hbalock);
5155 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
5156 spin_unlock_irq(&phba->hbalock);
5159 /* Mark the fast failover process in progress */
5160 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
5161 spin_unlock_irq(&phba->hbalock);
5162 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5164 "2773 Start FCF failover per CVL, "
5165 "evt_tag:x%x\n", acqe_fip->event_tag);
5166 rc = lpfc_sli4_redisc_fcf_table(phba);
5168 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5170 "2774 Issue FCF rediscover "
5171 "mabilbox command failed, "
5172 "through to CVL event\n");
5173 spin_lock_irq(&phba->hbalock);
5174 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
5175 spin_unlock_irq(&phba->hbalock);
5177 * Last resort will be re-try on the
5178 * the current registered FCF entry.
5180 lpfc_retry_pport_discovery(phba);
5183 * Reset FCF roundrobin bmask for new
5186 lpfc_sli4_clear_fcf_rr_bmask(phba);
5190 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5191 "0288 Unknown FCoE event type 0x%x event tag "
5192 "0x%x\n", event_type, acqe_fip->event_tag);
5198 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5199 * @phba: pointer to lpfc hba data structure.
5200 * @acqe_link: pointer to the async dcbx completion queue entry.
5202 * This routine is to handle the SLI4 asynchronous dcbx event.
5205 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5206 struct lpfc_acqe_dcbx *acqe_dcbx)
5208 phba->fc_eventTag = acqe_dcbx->event_tag;
5209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5210 "0290 The SLI4 DCBX asynchronous event is not "
5215 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5216 * @phba: pointer to lpfc hba data structure.
5217 * @acqe_link: pointer to the async grp5 completion queue entry.
5219 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5220 * is an asynchronous notified of a logical link speed change. The Port
5221 * reports the logical link speed in units of 10Mbps.
5224 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5225 struct lpfc_acqe_grp5 *acqe_grp5)
5227 uint16_t prev_ll_spd;
5229 phba->fc_eventTag = acqe_grp5->event_tag;
5230 phba->fcoe_eventtag = acqe_grp5->event_tag;
5231 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5232 phba->sli4_hba.link_state.logical_speed =
5233 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
5234 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5235 "2789 GRP5 Async Event: Updating logical link speed "
5236 "from %dMbps to %dMbps\n", prev_ll_spd,
5237 phba->sli4_hba.link_state.logical_speed);
5241 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5242 * @phba: pointer to lpfc hba data structure.
5244 * This routine is invoked by the worker thread to process all the pending
5245 * SLI4 asynchronous events.
5247 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5249 struct lpfc_cq_event *cq_event;
5251 /* First, declare the async event has been handled */
5252 spin_lock_irq(&phba->hbalock);
5253 phba->hba_flag &= ~ASYNC_EVENT;
5254 spin_unlock_irq(&phba->hbalock);
5255 /* Now, handle all the async events */
5256 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5257 /* Get the first event from the head of the event queue */
5258 spin_lock_irq(&phba->hbalock);
5259 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5260 cq_event, struct lpfc_cq_event, list);
5261 spin_unlock_irq(&phba->hbalock);
5262 /* Process the asynchronous event */
5263 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5264 case LPFC_TRAILER_CODE_LINK:
5265 lpfc_sli4_async_link_evt(phba,
5266 &cq_event->cqe.acqe_link);
5268 case LPFC_TRAILER_CODE_FCOE:
5269 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
5271 case LPFC_TRAILER_CODE_DCBX:
5272 lpfc_sli4_async_dcbx_evt(phba,
5273 &cq_event->cqe.acqe_dcbx);
5275 case LPFC_TRAILER_CODE_GRP5:
5276 lpfc_sli4_async_grp5_evt(phba,
5277 &cq_event->cqe.acqe_grp5);
5279 case LPFC_TRAILER_CODE_FC:
5280 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5282 case LPFC_TRAILER_CODE_SLI:
5283 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5286 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5287 "1804 Invalid asynchrous event code: "
5288 "x%x\n", bf_get(lpfc_trailer_code,
5289 &cq_event->cqe.mcqe_cmpl));
5292 /* Free the completion event processed to the free pool */
5293 lpfc_sli4_cq_event_release(phba, cq_event);
5298 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5299 * @phba: pointer to lpfc hba data structure.
5301 * This routine is invoked by the worker thread to process FCF table
5302 * rediscovery pending completion event.
5304 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5308 spin_lock_irq(&phba->hbalock);
5309 /* Clear FCF rediscovery timeout event */
5310 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5311 /* Clear driver fast failover FCF record flag */
5312 phba->fcf.failover_rec.flag = 0;
5313 /* Set state for FCF fast failover */
5314 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5315 spin_unlock_irq(&phba->hbalock);
5317 /* Scan FCF table from the first entry to re-discover SAN */
5318 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5319 "2777 Start post-quiescent FCF table scan\n");
5320 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5322 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5323 "2747 Issue FCF scan read FCF mailbox "
5324 "command failed 0x%x\n", rc);
5328 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5329 * @phba: pointer to lpfc hba data structure.
5330 * @dev_grp: The HBA PCI-Device group number.
5332 * This routine is invoked to set up the per HBA PCI-Device group function
5333 * API jump table entries.
5335 * Return: 0 if success, otherwise -ENODEV
5338 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5342 /* Set up lpfc PCI-device group */
5343 phba->pci_dev_grp = dev_grp;
5345 /* The LPFC_PCI_DEV_OC uses SLI4 */
5346 if (dev_grp == LPFC_PCI_DEV_OC)
5347 phba->sli_rev = LPFC_SLI_REV4;
5349 /* Set up device INIT API function jump table */
5350 rc = lpfc_init_api_table_setup(phba, dev_grp);
5353 /* Set up SCSI API function jump table */
5354 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5357 /* Set up SLI API function jump table */
5358 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5361 /* Set up MBOX API function jump table */
5362 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5370 * lpfc_log_intr_mode - Log the active interrupt mode
5371 * @phba: pointer to lpfc hba data structure.
5372 * @intr_mode: active interrupt mode adopted.
5374 * This routine it invoked to log the currently used active interrupt mode
5377 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
5379 switch (intr_mode) {
5381 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5382 "0470 Enable INTx interrupt mode.\n");
5385 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5386 "0481 Enabled MSI interrupt mode.\n");
5389 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5390 "0480 Enabled MSI-X interrupt mode.\n");
5393 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5394 "0482 Illegal interrupt mode.\n");
5401 * lpfc_enable_pci_dev - Enable a generic PCI device.
5402 * @phba: pointer to lpfc hba data structure.
5404 * This routine is invoked to enable the PCI device that is common to all
5409 * other values - error
5412 lpfc_enable_pci_dev(struct lpfc_hba *phba)
5414 struct pci_dev *pdev;
5416 /* Obtain PCI device reference */
5420 pdev = phba->pcidev;
5421 /* Enable PCI device */
5422 if (pci_enable_device_mem(pdev))
5424 /* Request PCI resource for the device */
5425 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
5426 goto out_disable_device;
5427 /* Set up device as PCI master and save state for EEH */
5428 pci_set_master(pdev);
5429 pci_try_set_mwi(pdev);
5430 pci_save_state(pdev);
5432 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5433 if (pci_is_pcie(pdev))
5434 pdev->needs_freset = 1;
5439 pci_disable_device(pdev);
5441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5442 "1401 Failed to enable pci device\n");
5447 * lpfc_disable_pci_dev - Disable a generic PCI device.
5448 * @phba: pointer to lpfc hba data structure.
5450 * This routine is invoked to disable the PCI device that is common to all
5454 lpfc_disable_pci_dev(struct lpfc_hba *phba)
5456 struct pci_dev *pdev;
5458 /* Obtain PCI device reference */
5462 pdev = phba->pcidev;
5463 /* Release PCI resource and disable PCI device */
5464 pci_release_mem_regions(pdev);
5465 pci_disable_device(pdev);
5471 * lpfc_reset_hba - Reset a hba
5472 * @phba: pointer to lpfc hba data structure.
5474 * This routine is invoked to reset a hba device. It brings the HBA
5475 * offline, performs a board restart, and then brings the board back
5476 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5477 * on outstanding mailbox commands.
5480 lpfc_reset_hba(struct lpfc_hba *phba)
5482 /* If resets are disabled then set error state and return. */
5483 if (!phba->cfg_enable_hba_reset) {
5484 phba->link_state = LPFC_HBA_ERROR;
5487 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5488 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5490 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
5492 lpfc_sli_brdrestart(phba);
5494 lpfc_unblock_mgmt_io(phba);
5498 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5499 * @phba: pointer to lpfc hba data structure.
5501 * This function enables the PCI SR-IOV virtual functions to a physical
5502 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5503 * enable the number of virtual functions to the physical function. As
5504 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5505 * API call does not considered as an error condition for most of the device.
5508 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5510 struct pci_dev *pdev = phba->pcidev;
5514 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5518 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5523 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5524 * @phba: pointer to lpfc hba data structure.
5525 * @nr_vfn: number of virtual functions to be enabled.
5527 * This function enables the PCI SR-IOV virtual functions to a physical
5528 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5529 * enable the number of virtual functions to the physical function. As
5530 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5531 * API call does not considered as an error condition for most of the device.
5534 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5536 struct pci_dev *pdev = phba->pcidev;
5537 uint16_t max_nr_vfn;
5540 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5541 if (nr_vfn > max_nr_vfn) {
5542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5543 "3057 Requested vfs (%d) greater than "
5544 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5548 rc = pci_enable_sriov(pdev, nr_vfn);
5550 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5551 "2806 Failed to enable sriov on this device "
5552 "with vfn number nr_vf:%d, rc:%d\n",
5555 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5556 "2807 Successful enable sriov on this device "
5557 "with vfn number nr_vf:%d\n", nr_vfn);
5562 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5563 * @phba: pointer to lpfc hba data structure.
5565 * This routine is invoked to set up the driver internal resources before the
5566 * device specific resource setup to support the HBA device it attached to.
5570 * other values - error
5573 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5575 struct lpfc_sli *psli = &phba->sli;
5578 * Driver resources common to all SLI revisions
5580 atomic_set(&phba->fast_event_count, 0);
5581 spin_lock_init(&phba->hbalock);
5583 /* Initialize ndlp management spinlock */
5584 spin_lock_init(&phba->ndlp_lock);
5586 INIT_LIST_HEAD(&phba->port_list);
5587 INIT_LIST_HEAD(&phba->work_list);
5588 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5590 /* Initialize the wait queue head for the kernel thread */
5591 init_waitqueue_head(&phba->work_waitq);
5593 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5594 "1403 Protocols supported %s %s %s\n",
5595 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5597 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5599 (phba->nvmet_support ? "NVMET" : " "));
5601 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5602 /* Initialize the scsi buffer list used by driver for scsi IO */
5603 spin_lock_init(&phba->scsi_buf_list_get_lock);
5604 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5605 spin_lock_init(&phba->scsi_buf_list_put_lock);
5606 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5609 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5610 (phba->nvmet_support == 0)) {
5611 /* Initialize the NVME buffer list used by driver for NVME IO */
5612 spin_lock_init(&phba->nvme_buf_list_get_lock);
5613 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5614 spin_lock_init(&phba->nvme_buf_list_put_lock);
5615 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5618 /* Initialize the fabric iocb list */
5619 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5621 /* Initialize list to save ELS buffers */
5622 INIT_LIST_HEAD(&phba->elsbuf);
5624 /* Initialize FCF connection rec list */
5625 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5627 /* Initialize OAS configuration list */
5628 spin_lock_init(&phba->devicelock);
5629 INIT_LIST_HEAD(&phba->luns);
5631 /* MBOX heartbeat timer */
5632 setup_timer(&psli->mbox_tmo, lpfc_mbox_timeout, (unsigned long)phba);
5633 /* Fabric block timer */
5634 setup_timer(&phba->fabric_block_timer, lpfc_fabric_block_timeout,
5635 (unsigned long)phba);
5636 /* EA polling mode timer */
5637 setup_timer(&phba->eratt_poll, lpfc_poll_eratt,
5638 (unsigned long)phba);
5639 /* Heartbeat timer */
5640 setup_timer(&phba->hb_tmofunc, lpfc_hb_timeout, (unsigned long)phba);
5646 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5647 * @phba: pointer to lpfc hba data structure.
5649 * This routine is invoked to set up the driver internal resources specific to
5650 * support the SLI-3 HBA device it attached to.
5654 * other values - error
5657 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5662 * Initialize timers used by driver
5665 /* FCP polling mode timer */
5666 setup_timer(&phba->fcp_poll_timer, lpfc_poll_timeout,
5667 (unsigned long)phba);
5669 /* Host attention work mask setup */
5670 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5671 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5673 /* Get all the module params for configuring this host */
5674 lpfc_get_cfgparam(phba);
5675 /* Set up phase-1 common device driver resources */
5677 rc = lpfc_setup_driver_resource_phase1(phba);
5681 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5682 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5683 /* check for menlo minimum sg count */
5684 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5685 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5688 if (!phba->sli.sli3_ring)
5689 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
5690 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5691 if (!phba->sli.sli3_ring)
5695 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5696 * used to create the sg_dma_buf_pool must be dynamically calculated.
5699 /* Initialize the host templates the configured values. */
5700 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5701 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5702 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5704 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5705 if (phba->cfg_enable_bg) {
5707 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5708 * the FCP rsp, and a BDE for each. Sice we have no control
5709 * over how many protection data segments the SCSI Layer
5710 * will hand us (ie: there could be one for every block
5711 * in the IO), we just allocate enough BDEs to accomidate
5712 * our max amount and we need to limit lpfc_sg_seg_cnt to
5713 * minimize the risk of running out.
5715 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5716 sizeof(struct fcp_rsp) +
5717 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5719 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5720 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5722 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5723 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5726 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5727 * the FCP rsp, a BDE for each, and a BDE for up to
5728 * cfg_sg_seg_cnt data segments.
5730 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5731 sizeof(struct fcp_rsp) +
5732 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5734 /* Total BDEs in BPL for scsi_sg_list */
5735 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5738 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5739 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5740 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5741 phba->cfg_total_seg_cnt);
5743 phba->max_vpi = LPFC_MAX_VPI;
5744 /* This will be set to correct value after config_port mbox */
5745 phba->max_vports = 0;
5748 * Initialize the SLI Layer to run with lpfc HBAs.
5750 lpfc_sli_setup(phba);
5751 lpfc_sli_queue_init(phba);
5753 /* Allocate device driver memory */
5754 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5758 * Enable sr-iov virtual functions if supported and configured
5759 * through the module parameter.
5761 if (phba->cfg_sriov_nr_virtfn > 0) {
5762 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5763 phba->cfg_sriov_nr_virtfn);
5765 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5766 "2808 Requested number of SR-IOV "
5767 "virtual functions (%d) is not "
5769 phba->cfg_sriov_nr_virtfn);
5770 phba->cfg_sriov_nr_virtfn = 0;
5778 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5779 * @phba: pointer to lpfc hba data structure.
5781 * This routine is invoked to unset the driver internal resources set up
5782 * specific for supporting the SLI-3 HBA device it attached to.
5785 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5787 /* Free device driver memory allocated */
5788 lpfc_mem_free_all(phba);
5794 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5795 * @phba: pointer to lpfc hba data structure.
5797 * This routine is invoked to set up the driver internal resources specific to
5798 * support the SLI-4 HBA device it attached to.
5802 * other values - error
5805 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5807 LPFC_MBOXQ_t *mboxq;
5809 int rc, i, max_buf_size;
5811 int fof_vectors = 0;
5814 phba->sli4_hba.num_online_cpu = num_online_cpus();
5815 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5816 phba->sli4_hba.curr_disp_cpu = 0;
5818 /* Get all the module params for configuring this host */
5819 lpfc_get_cfgparam(phba);
5821 /* Set up phase-1 common device driver resources */
5822 rc = lpfc_setup_driver_resource_phase1(phba);
5826 /* Before proceed, wait for POST done and device ready */
5827 rc = lpfc_sli4_post_status_check(phba);
5832 * Initialize timers used by driver
5835 setup_timer(&phba->rrq_tmr, lpfc_rrq_timeout, (unsigned long)phba);
5837 /* FCF rediscover timer */
5838 setup_timer(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo,
5839 (unsigned long)phba);
5842 * Control structure for handling external multi-buffer mailbox
5843 * command pass-through.
5845 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5846 sizeof(struct lpfc_mbox_ext_buf_ctx));
5847 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5849 phba->max_vpi = LPFC_MAX_VPI;
5851 /* This will be set to correct value after the read_config mbox */
5852 phba->max_vports = 0;
5854 /* Program the default value of vlan_id and fc_map */
5855 phba->valid_vlan = 0;
5856 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5857 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5858 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5861 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5862 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5863 * The WQ create will allocate the ring.
5867 * It doesn't matter what family our adapter is in, we are
5868 * limited to 2 Pages, 512 SGEs, for our SGL.
5869 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5871 max_buf_size = (2 * SLI4_PAGE_SIZE);
5872 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5873 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
5876 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5877 * used to create the sg_dma_buf_pool must be calculated.
5879 if (phba->cfg_enable_bg) {
5881 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5882 * the FCP rsp, and a SGE. Sice we have no control
5883 * over how many protection segments the SCSI Layer
5884 * will hand us (ie: there could be one for every block
5885 * in the IO), just allocate enough SGEs to accomidate
5886 * our max amount and we need to limit lpfc_sg_seg_cnt
5887 * to minimize the risk of running out.
5889 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5890 sizeof(struct fcp_rsp) + max_buf_size;
5892 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5893 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5895 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5896 phba->cfg_sg_seg_cnt =
5897 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5900 * The scsi_buf for a regular I/O holds the FCP cmnd,
5901 * the FCP rsp, a SGE for each, and a SGE for up to
5902 * cfg_sg_seg_cnt data segments.
5904 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5905 sizeof(struct fcp_rsp) +
5906 ((phba->cfg_sg_seg_cnt + 2) *
5907 sizeof(struct sli4_sge));
5909 /* Total SGEs for scsi_sg_list */
5910 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5913 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5914 * need to post 1 page for the SGL.
5918 /* Initialize the host templates with the updated values. */
5919 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5920 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5921 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5923 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5924 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5926 phba->cfg_sg_dma_buf_size =
5927 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5929 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5930 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5931 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5932 phba->cfg_total_seg_cnt);
5934 /* Initialize buffer queue management fields */
5935 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
5936 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5937 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5940 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5942 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5943 /* Initialize the Abort scsi buffer list used by driver */
5944 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5945 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5948 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5949 /* Initialize the Abort nvme buffer list used by driver */
5950 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5951 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5952 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
5953 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
5955 /* Fast-path XRI aborted CQ Event work queue list */
5956 INIT_LIST_HEAD(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue);
5959 /* This abort list used by worker thread */
5960 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
5961 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
5964 * Initialize driver internal slow-path work queues
5967 /* Driver internel slow-path CQ Event pool */
5968 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5969 /* Response IOCB work queue list */
5970 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
5971 /* Asynchronous event CQ Event work queue list */
5972 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5973 /* Fast-path XRI aborted CQ Event work queue list */
5974 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5975 /* Slow-path XRI aborted CQ Event work queue list */
5976 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5977 /* Receive queue CQ Event work queue list */
5978 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5980 /* Initialize extent block lists. */
5981 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5982 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5983 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5984 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5986 /* Initialize mboxq lists. If the early init routines fail
5987 * these lists need to be correctly initialized.
5989 INIT_LIST_HEAD(&phba->sli.mboxq);
5990 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
5992 /* initialize optic_state to 0xFF */
5993 phba->sli4_hba.lnk_info.optic_state = 0xff;
5995 /* Allocate device driver memory */
5996 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6000 /* IF Type 2 ports get initialized now. */
6001 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6002 LPFC_SLI_INTF_IF_TYPE_2) {
6003 rc = lpfc_pci_function_reset(phba);
6008 phba->temp_sensor_support = 1;
6011 /* Create the bootstrap mailbox command */
6012 rc = lpfc_create_bootstrap_mbox(phba);
6016 /* Set up the host's endian order with the device. */
6017 rc = lpfc_setup_endian_order(phba);
6019 goto out_free_bsmbx;
6021 /* Set up the hba's configuration parameters. */
6022 rc = lpfc_sli4_read_config(phba);
6024 goto out_free_bsmbx;
6025 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6027 goto out_free_bsmbx;
6029 /* IF Type 0 ports get initialized now. */
6030 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6031 LPFC_SLI_INTF_IF_TYPE_0) {
6032 rc = lpfc_pci_function_reset(phba);
6034 goto out_free_bsmbx;
6037 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6041 goto out_free_bsmbx;
6044 /* Check for NVMET being configured */
6045 phba->nvmet_support = 0;
6046 if (lpfc_enable_nvmet_cnt) {
6048 /* First get WWN of HBA instance */
6049 lpfc_read_nv(phba, mboxq);
6050 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6051 if (rc != MBX_SUCCESS) {
6052 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6053 "6016 Mailbox failed , mbxCmd x%x "
6054 "READ_NV, mbxStatus x%x\n",
6055 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6056 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
6057 mempool_free(mboxq, phba->mbox_mem_pool);
6059 goto out_free_bsmbx;
6062 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6064 wwn = cpu_to_be64(wwn);
6065 phba->sli4_hba.wwnn.u.name = wwn;
6066 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6068 /* wwn is WWPN of HBA instance */
6069 wwn = cpu_to_be64(wwn);
6070 phba->sli4_hba.wwpn.u.name = wwn;
6072 /* Check to see if it matches any module parameter */
6073 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6074 if (wwn == lpfc_enable_nvmet[i]) {
6075 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
6076 if (lpfc_nvmet_mem_alloc(phba))
6079 phba->nvmet_support = 1; /* a match */
6081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6082 "6017 NVME Target %016llx\n",
6085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6086 "6021 Can't enable NVME Target."
6087 " NVME_TARGET_FC infrastructure"
6088 " is not in kernel\n");
6095 lpfc_nvme_mod_param_dep(phba);
6098 * Get sli4 parameters that override parameters from Port capabilities.
6099 * If this call fails, it isn't critical unless the SLI4 parameters come
6102 rc = lpfc_get_sli4_parameters(phba, mboxq);
6104 if (phba->sli4_hba.extents_in_use &&
6105 phba->sli4_hba.rpi_hdrs_in_use) {
6106 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6107 "2999 Unsupported SLI4 Parameters "
6108 "Extents and RPI headers enabled.\n");
6110 mempool_free(mboxq, phba->mbox_mem_pool);
6112 goto out_free_bsmbx;
6115 mempool_free(mboxq, phba->mbox_mem_pool);
6117 /* Verify OAS is supported */
6118 lpfc_sli4_oas_verify(phba);
6122 /* Verify all the SLI4 queues */
6123 rc = lpfc_sli4_queue_verify(phba);
6125 goto out_free_bsmbx;
6127 /* Create driver internal CQE event pool */
6128 rc = lpfc_sli4_cq_event_pool_create(phba);
6130 goto out_free_bsmbx;
6132 /* Initialize sgl lists per host */
6133 lpfc_init_sgl_list(phba);
6135 /* Allocate and initialize active sgl array */
6136 rc = lpfc_init_active_sgl_array(phba);
6138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6139 "1430 Failed to initialize sgl list.\n");
6140 goto out_destroy_cq_event_pool;
6142 rc = lpfc_sli4_init_rpi_hdrs(phba);
6144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6145 "1432 Failed to initialize rpi headers.\n");
6146 goto out_free_active_sgl;
6149 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
6150 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6151 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
6153 if (!phba->fcf.fcf_rr_bmask) {
6154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6155 "2759 Failed allocate memory for FCF round "
6156 "robin failover bmask\n");
6158 goto out_remove_rpi_hdrs;
6161 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6162 sizeof(struct lpfc_hba_eq_hdl),
6164 if (!phba->sli4_hba.hba_eq_hdl) {
6165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6166 "2572 Failed allocate memory for "
6167 "fast-path per-EQ handle array\n");
6169 goto out_free_fcf_rr_bmask;
6172 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6173 sizeof(struct lpfc_vector_map_info),
6175 if (!phba->sli4_hba.cpu_map) {
6176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6177 "3327 Failed allocate memory for msi-x "
6178 "interrupt vector mapping\n");
6180 goto out_free_hba_eq_hdl;
6182 if (lpfc_used_cpu == NULL) {
6183 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6185 if (!lpfc_used_cpu) {
6186 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6187 "3335 Failed allocate memory for msi-x "
6188 "interrupt vector mapping\n");
6189 kfree(phba->sli4_hba.cpu_map);
6191 goto out_free_hba_eq_hdl;
6193 for (i = 0; i < lpfc_present_cpu; i++)
6194 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6198 * Enable sr-iov virtual functions if supported and configured
6199 * through the module parameter.
6201 if (phba->cfg_sriov_nr_virtfn > 0) {
6202 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6203 phba->cfg_sriov_nr_virtfn);
6205 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6206 "3020 Requested number of SR-IOV "
6207 "virtual functions (%d) is not "
6209 phba->cfg_sriov_nr_virtfn);
6210 phba->cfg_sriov_nr_virtfn = 0;
6216 out_free_hba_eq_hdl:
6217 kfree(phba->sli4_hba.hba_eq_hdl);
6218 out_free_fcf_rr_bmask:
6219 kfree(phba->fcf.fcf_rr_bmask);
6220 out_remove_rpi_hdrs:
6221 lpfc_sli4_remove_rpi_hdrs(phba);
6222 out_free_active_sgl:
6223 lpfc_free_active_sgl(phba);
6224 out_destroy_cq_event_pool:
6225 lpfc_sli4_cq_event_pool_destroy(phba);
6227 lpfc_destroy_bootstrap_mbox(phba);
6229 lpfc_mem_free(phba);
6234 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6235 * @phba: pointer to lpfc hba data structure.
6237 * This routine is invoked to unset the driver internal resources set up
6238 * specific for supporting the SLI-4 HBA device it attached to.
6241 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6243 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6245 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6246 kfree(phba->sli4_hba.cpu_map);
6247 phba->sli4_hba.num_present_cpu = 0;
6248 phba->sli4_hba.num_online_cpu = 0;
6249 phba->sli4_hba.curr_disp_cpu = 0;
6251 /* Free memory allocated for fast-path work queue handles */
6252 kfree(phba->sli4_hba.hba_eq_hdl);
6254 /* Free the allocated rpi headers. */
6255 lpfc_sli4_remove_rpi_hdrs(phba);
6256 lpfc_sli4_remove_rpis(phba);
6258 /* Free eligible FCF index bmask */
6259 kfree(phba->fcf.fcf_rr_bmask);
6261 /* Free the ELS sgl list */
6262 lpfc_free_active_sgl(phba);
6263 lpfc_free_els_sgl_list(phba);
6264 lpfc_free_nvmet_sgl_list(phba);
6266 /* Free the completion queue EQ event pool */
6267 lpfc_sli4_cq_event_release_all(phba);
6268 lpfc_sli4_cq_event_pool_destroy(phba);
6270 /* Release resource identifiers. */
6271 lpfc_sli4_dealloc_resource_identifiers(phba);
6273 /* Free the bsmbx region. */
6274 lpfc_destroy_bootstrap_mbox(phba);
6276 /* Free the SLI Layer memory with SLI4 HBAs */
6277 lpfc_mem_free_all(phba);
6279 /* Free the current connect table */
6280 list_for_each_entry_safe(conn_entry, next_conn_entry,
6281 &phba->fcf_conn_rec_list, list) {
6282 list_del_init(&conn_entry->list);
6290 * lpfc_init_api_table_setup - Set up init api function jump table
6291 * @phba: The hba struct for which this call is being executed.
6292 * @dev_grp: The HBA PCI-Device group number.
6294 * This routine sets up the device INIT interface API function jump table
6297 * Returns: 0 - success, -ENODEV - failure.
6300 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6302 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6303 phba->lpfc_hba_down_link = lpfc_hba_down_link;
6304 phba->lpfc_selective_reset = lpfc_selective_reset;
6306 case LPFC_PCI_DEV_LP:
6307 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6308 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6309 phba->lpfc_stop_port = lpfc_stop_port_s3;
6311 case LPFC_PCI_DEV_OC:
6312 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6313 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6314 phba->lpfc_stop_port = lpfc_stop_port_s4;
6317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6318 "1431 Invalid HBA PCI-device group: 0x%x\n",
6327 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6328 * @phba: pointer to lpfc hba data structure.
6330 * This routine is invoked to set up the driver internal resources after the
6331 * device specific resource setup to support the HBA device it attached to.
6335 * other values - error
6338 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6342 /* Startup the kernel thread for this host adapter. */
6343 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6344 "lpfc_worker_%d", phba->brd_no);
6345 if (IS_ERR(phba->worker_thread)) {
6346 error = PTR_ERR(phba->worker_thread);
6354 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6355 * @phba: pointer to lpfc hba data structure.
6357 * This routine is invoked to unset the driver internal resources set up after
6358 * the device specific resource setup for supporting the HBA device it
6362 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6364 /* Stop kernel worker thread */
6365 kthread_stop(phba->worker_thread);
6369 * lpfc_free_iocb_list - Free iocb list.
6370 * @phba: pointer to lpfc hba data structure.
6372 * This routine is invoked to free the driver's IOCB list and memory.
6375 lpfc_free_iocb_list(struct lpfc_hba *phba)
6377 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6379 spin_lock_irq(&phba->hbalock);
6380 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6381 &phba->lpfc_iocb_list, list) {
6382 list_del(&iocbq_entry->list);
6384 phba->total_iocbq_bufs--;
6386 spin_unlock_irq(&phba->hbalock);
6392 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6393 * @phba: pointer to lpfc hba data structure.
6395 * This routine is invoked to allocate and initizlize the driver's IOCB
6396 * list and set up the IOCB tag array accordingly.
6400 * other values - error
6403 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6405 struct lpfc_iocbq *iocbq_entry = NULL;
6409 /* Initialize and populate the iocb list per host. */
6410 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
6411 for (i = 0; i < iocb_count; i++) {
6412 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
6413 if (iocbq_entry == NULL) {
6414 printk(KERN_ERR "%s: only allocated %d iocbs of "
6415 "expected %d count. Unloading driver.\n",
6416 __func__, i, LPFC_IOCB_LIST_CNT);
6417 goto out_free_iocbq;
6420 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6423 printk(KERN_ERR "%s: failed to allocate IOTAG. "
6424 "Unloading driver.\n", __func__);
6425 goto out_free_iocbq;
6427 iocbq_entry->sli4_lxritag = NO_XRI;
6428 iocbq_entry->sli4_xritag = NO_XRI;
6430 spin_lock_irq(&phba->hbalock);
6431 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6432 phba->total_iocbq_bufs++;
6433 spin_unlock_irq(&phba->hbalock);
6439 lpfc_free_iocb_list(phba);
6445 * lpfc_free_sgl_list - Free a given sgl list.
6446 * @phba: pointer to lpfc hba data structure.
6447 * @sglq_list: pointer to the head of sgl list.
6449 * This routine is invoked to free a give sgl list and memory.
6452 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
6454 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6456 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6457 list_del(&sglq_entry->list);
6458 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6464 * lpfc_free_els_sgl_list - Free els sgl list.
6465 * @phba: pointer to lpfc hba data structure.
6467 * This routine is invoked to free the driver's els sgl list and memory.
6470 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6472 LIST_HEAD(sglq_list);
6474 /* Retrieve all els sgls from driver list */
6475 spin_lock_irq(&phba->hbalock);
6476 spin_lock(&phba->sli4_hba.sgl_list_lock);
6477 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6478 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6479 spin_unlock_irq(&phba->hbalock);
6481 /* Now free the sgl list */
6482 lpfc_free_sgl_list(phba, &sglq_list);
6486 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6487 * @phba: pointer to lpfc hba data structure.
6489 * This routine is invoked to free the driver's nvmet sgl list and memory.
6492 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6494 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6495 LIST_HEAD(sglq_list);
6497 /* Retrieve all nvmet sgls from driver list */
6498 spin_lock_irq(&phba->hbalock);
6499 spin_lock(&phba->sli4_hba.sgl_list_lock);
6500 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6501 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6502 spin_unlock_irq(&phba->hbalock);
6504 /* Now free the sgl list */
6505 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6506 list_del(&sglq_entry->list);
6507 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6511 /* Update the nvmet_xri_cnt to reflect no current sgls.
6512 * The next initialization cycle sets the count and allocates
6513 * the sgls over again.
6515 phba->sli4_hba.nvmet_xri_cnt = 0;
6519 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6520 * @phba: pointer to lpfc hba data structure.
6522 * This routine is invoked to allocate the driver's active sgl memory.
6523 * This array will hold the sglq_entry's for active IOs.
6526 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6529 size = sizeof(struct lpfc_sglq *);
6530 size *= phba->sli4_hba.max_cfg_param.max_xri;
6532 phba->sli4_hba.lpfc_sglq_active_list =
6533 kzalloc(size, GFP_KERNEL);
6534 if (!phba->sli4_hba.lpfc_sglq_active_list)
6540 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6541 * @phba: pointer to lpfc hba data structure.
6543 * This routine is invoked to walk through the array of active sglq entries
6544 * and free all of the resources.
6545 * This is just a place holder for now.
6548 lpfc_free_active_sgl(struct lpfc_hba *phba)
6550 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6554 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6555 * @phba: pointer to lpfc hba data structure.
6557 * This routine is invoked to allocate and initizlize the driver's sgl
6558 * list and set up the sgl xritag tag array accordingly.
6562 lpfc_init_sgl_list(struct lpfc_hba *phba)
6564 /* Initialize and populate the sglq list per host/VF. */
6565 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
6566 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6567 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6568 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
6570 /* els xri-sgl book keeping */
6571 phba->sli4_hba.els_xri_cnt = 0;
6573 /* scsi xri-buffer book keeping */
6574 phba->sli4_hba.scsi_xri_cnt = 0;
6576 /* nvme xri-buffer book keeping */
6577 phba->sli4_hba.nvme_xri_cnt = 0;
6581 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6582 * @phba: pointer to lpfc hba data structure.
6584 * This routine is invoked to post rpi header templates to the
6585 * port for those SLI4 ports that do not support extents. This routine
6586 * posts a PAGE_SIZE memory region to the port to hold up to
6587 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6588 * and should be called only when interrupts are disabled.
6592 * -ERROR - otherwise.
6595 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6598 struct lpfc_rpi_hdr *rpi_hdr;
6600 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
6601 if (!phba->sli4_hba.rpi_hdrs_in_use)
6603 if (phba->sli4_hba.extents_in_use)
6606 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6608 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6609 "0391 Error during rpi post operation\n");
6610 lpfc_sli4_remove_rpis(phba);
6618 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6619 * @phba: pointer to lpfc hba data structure.
6621 * This routine is invoked to allocate a single 4KB memory region to
6622 * support rpis and stores them in the phba. This single region
6623 * provides support for up to 64 rpis. The region is used globally
6627 * A valid rpi hdr on success.
6628 * A NULL pointer on any failure.
6630 struct lpfc_rpi_hdr *
6631 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6633 uint16_t rpi_limit, curr_rpi_range;
6634 struct lpfc_dmabuf *dmabuf;
6635 struct lpfc_rpi_hdr *rpi_hdr;
6638 * If the SLI4 port supports extents, posting the rpi header isn't
6639 * required. Set the expected maximum count and let the actual value
6640 * get set when extents are fully allocated.
6642 if (!phba->sli4_hba.rpi_hdrs_in_use)
6644 if (phba->sli4_hba.extents_in_use)
6647 /* The limit on the logical index is just the max_rpi count. */
6648 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
6650 spin_lock_irq(&phba->hbalock);
6652 * Establish the starting RPI in this header block. The starting
6653 * rpi is normalized to a zero base because the physical rpi is
6656 curr_rpi_range = phba->sli4_hba.next_rpi;
6657 spin_unlock_irq(&phba->hbalock);
6659 /* Reached full RPI range */
6660 if (curr_rpi_range == rpi_limit)
6664 * First allocate the protocol header region for the port. The
6665 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6667 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6671 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6672 LPFC_HDR_TEMPLATE_SIZE,
6673 &dmabuf->phys, GFP_KERNEL);
6674 if (!dmabuf->virt) {
6676 goto err_free_dmabuf;
6679 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6681 goto err_free_coherent;
6684 /* Save the rpi header data for cleanup later. */
6685 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6687 goto err_free_coherent;
6689 rpi_hdr->dmabuf = dmabuf;
6690 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6691 rpi_hdr->page_count = 1;
6692 spin_lock_irq(&phba->hbalock);
6694 /* The rpi_hdr stores the logical index only. */
6695 rpi_hdr->start_rpi = curr_rpi_range;
6696 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
6697 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6699 spin_unlock_irq(&phba->hbalock);
6703 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6704 dmabuf->virt, dmabuf->phys);
6711 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6712 * @phba: pointer to lpfc hba data structure.
6714 * This routine is invoked to remove all memory resources allocated
6715 * to support rpis for SLI4 ports not supporting extents. This routine
6716 * presumes the caller has released all rpis consumed by fabric or port
6717 * logins and is prepared to have the header pages removed.
6720 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6722 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6724 if (!phba->sli4_hba.rpi_hdrs_in_use)
6727 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6728 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6729 list_del(&rpi_hdr->list);
6730 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6731 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6732 kfree(rpi_hdr->dmabuf);
6736 /* There are no rpis available to the port now. */
6737 phba->sli4_hba.next_rpi = 0;
6741 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6742 * @pdev: pointer to pci device data structure.
6744 * This routine is invoked to allocate the driver hba data structure for an
6745 * HBA device. If the allocation is successful, the phba reference to the
6746 * PCI device data structure is set.
6749 * pointer to @phba - successful
6752 static struct lpfc_hba *
6753 lpfc_hba_alloc(struct pci_dev *pdev)
6755 struct lpfc_hba *phba;
6757 /* Allocate memory for HBA structure */
6758 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6760 dev_err(&pdev->dev, "failed to allocate hba struct\n");
6764 /* Set reference to PCI device in HBA structure */
6765 phba->pcidev = pdev;
6767 /* Assign an unused board number */
6768 phba->brd_no = lpfc_get_instance();
6769 if (phba->brd_no < 0) {
6773 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
6775 spin_lock_init(&phba->ct_ev_lock);
6776 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6782 * lpfc_hba_free - Free driver hba data structure with a device.
6783 * @phba: pointer to lpfc hba data structure.
6785 * This routine is invoked to free the driver hba data structure with an
6789 lpfc_hba_free(struct lpfc_hba *phba)
6791 /* Release the driver assigned board number */
6792 idr_remove(&lpfc_hba_index, phba->brd_no);
6794 /* Free memory allocated with sli3 rings */
6795 kfree(phba->sli.sli3_ring);
6796 phba->sli.sli3_ring = NULL;
6803 * lpfc_create_shost - Create hba physical port with associated scsi host.
6804 * @phba: pointer to lpfc hba data structure.
6806 * This routine is invoked to create HBA physical port and associate a SCSI
6811 * other values - error
6814 lpfc_create_shost(struct lpfc_hba *phba)
6816 struct lpfc_vport *vport;
6817 struct Scsi_Host *shost;
6819 /* Initialize HBA FC structure */
6820 phba->fc_edtov = FF_DEF_EDTOV;
6821 phba->fc_ratov = FF_DEF_RATOV;
6822 phba->fc_altov = FF_DEF_ALTOV;
6823 phba->fc_arbtov = FF_DEF_ARBTOV;
6825 atomic_set(&phba->sdev_cnt, 0);
6826 atomic_set(&phba->fc4ScsiInputRequests, 0);
6827 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6828 atomic_set(&phba->fc4ScsiControlRequests, 0);
6829 atomic_set(&phba->fc4ScsiIoCmpls, 0);
6830 atomic_set(&phba->fc4NvmeInputRequests, 0);
6831 atomic_set(&phba->fc4NvmeOutputRequests, 0);
6832 atomic_set(&phba->fc4NvmeControlRequests, 0);
6833 atomic_set(&phba->fc4NvmeIoCmpls, 0);
6834 atomic_set(&phba->fc4NvmeLsRequests, 0);
6835 atomic_set(&phba->fc4NvmeLsCmpls, 0);
6836 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
6840 shost = lpfc_shost_from_vport(vport);
6841 phba->pport = vport;
6843 if (phba->nvmet_support) {
6844 /* Only 1 vport (pport) will support NVME target */
6845 if (phba->txrdy_payload_pool == NULL) {
6846 phba->txrdy_payload_pool = dma_pool_create(
6847 "txrdy_pool", &phba->pcidev->dev,
6848 TXRDY_PAYLOAD_LEN, 16, 0);
6849 if (phba->txrdy_payload_pool) {
6850 phba->targetport = NULL;
6851 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6852 lpfc_printf_log(phba, KERN_INFO,
6853 LOG_INIT | LOG_NVME_DISC,
6854 "6076 NVME Target Found\n");
6859 lpfc_debugfs_initialize(vport);
6860 /* Put reference to SCSI host to driver's device private data */
6861 pci_set_drvdata(phba->pcidev, shost);
6864 * At this point we are fully registered with PSA. In addition,
6865 * any initial discovery should be completed.
6867 vport->load_flag |= FC_ALLOW_FDMI;
6868 if (phba->cfg_enable_SmartSAN ||
6869 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
6871 /* Setup appropriate attribute masks */
6872 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
6873 if (phba->cfg_enable_SmartSAN)
6874 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6876 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6882 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6883 * @phba: pointer to lpfc hba data structure.
6885 * This routine is invoked to destroy HBA physical port and the associated
6889 lpfc_destroy_shost(struct lpfc_hba *phba)
6891 struct lpfc_vport *vport = phba->pport;
6893 /* Destroy physical port that associated with the SCSI host */
6894 destroy_port(vport);
6900 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6901 * @phba: pointer to lpfc hba data structure.
6902 * @shost: the shost to be used to detect Block guard settings.
6904 * This routine sets up the local Block guard protocol settings for @shost.
6905 * This routine also allocates memory for debugging bg buffers.
6908 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6914 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6915 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6916 "1478 Registering BlockGuard with the "
6919 old_mask = phba->cfg_prot_mask;
6920 old_guard = phba->cfg_prot_guard;
6922 /* Only allow supported values */
6923 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6924 SHOST_DIX_TYPE0_PROTECTION |
6925 SHOST_DIX_TYPE1_PROTECTION);
6926 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6927 SHOST_DIX_GUARD_CRC);
6929 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6930 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6931 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6933 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6934 if ((old_mask != phba->cfg_prot_mask) ||
6935 (old_guard != phba->cfg_prot_guard))
6936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6937 "1475 Registering BlockGuard with the "
6938 "SCSI layer: mask %d guard %d\n",
6939 phba->cfg_prot_mask,
6940 phba->cfg_prot_guard);
6942 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6943 scsi_host_set_guard(shost, phba->cfg_prot_guard);
6945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6946 "1479 Not Registering BlockGuard with the SCSI "
6947 "layer, Bad protection parameters: %d %d\n",
6948 old_mask, old_guard);
6951 if (!_dump_buf_data) {
6953 spin_lock_init(&_dump_buf_lock);
6955 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6956 if (_dump_buf_data) {
6957 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6958 "9043 BLKGRD: allocated %d pages for "
6959 "_dump_buf_data at 0x%p\n",
6960 (1 << pagecnt), _dump_buf_data);
6961 _dump_buf_data_order = pagecnt;
6962 memset(_dump_buf_data, 0,
6963 ((1 << PAGE_SHIFT) << pagecnt));
6968 if (!_dump_buf_data_order)
6969 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6970 "9044 BLKGRD: ERROR unable to allocate "
6971 "memory for hexdump\n");
6973 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6974 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6975 "\n", _dump_buf_data);
6976 if (!_dump_buf_dif) {
6979 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6980 if (_dump_buf_dif) {
6981 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6982 "9046 BLKGRD: allocated %d pages for "
6983 "_dump_buf_dif at 0x%p\n",
6984 (1 << pagecnt), _dump_buf_dif);
6985 _dump_buf_dif_order = pagecnt;
6986 memset(_dump_buf_dif, 0,
6987 ((1 << PAGE_SHIFT) << pagecnt));
6992 if (!_dump_buf_dif_order)
6993 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6994 "9047 BLKGRD: ERROR unable to allocate "
6995 "memory for hexdump\n");
6997 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6998 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
7003 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7004 * @phba: pointer to lpfc hba data structure.
7006 * This routine is invoked to perform all the necessary post initialization
7007 * setup for the device.
7010 lpfc_post_init_setup(struct lpfc_hba *phba)
7012 struct Scsi_Host *shost;
7013 struct lpfc_adapter_event_header adapter_event;
7015 /* Get the default values for Model Name and Description */
7016 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7019 * hba setup may have changed the hba_queue_depth so we need to
7020 * adjust the value of can_queue.
7022 shost = pci_get_drvdata(phba->pcidev);
7023 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7024 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7025 lpfc_setup_bg(phba, shost);
7027 lpfc_host_attrib_init(shost);
7029 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7030 spin_lock_irq(shost->host_lock);
7031 lpfc_poll_start_timer(phba);
7032 spin_unlock_irq(shost->host_lock);
7035 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7036 "0428 Perform SCSI scan\n");
7037 /* Send board arrival event to upper layer */
7038 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7039 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7040 fc_host_post_vendor_event(shost, fc_get_event_number(),
7041 sizeof(adapter_event),
7042 (char *) &adapter_event,
7048 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7049 * @phba: pointer to lpfc hba data structure.
7051 * This routine is invoked to set up the PCI device memory space for device
7052 * with SLI-3 interface spec.
7056 * other values - error
7059 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7061 struct pci_dev *pdev;
7062 unsigned long bar0map_len, bar2map_len;
7065 int error = -ENODEV;
7067 /* Obtain PCI device reference */
7071 pdev = phba->pcidev;
7073 /* Set the device DMA mask size */
7074 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7075 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7076 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7077 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
7082 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7083 * required by each mapping.
7085 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7086 bar0map_len = pci_resource_len(pdev, 0);
7088 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7089 bar2map_len = pci_resource_len(pdev, 2);
7091 /* Map HBA SLIM to a kernel virtual address. */
7092 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7093 if (!phba->slim_memmap_p) {
7094 dev_printk(KERN_ERR, &pdev->dev,
7095 "ioremap failed for SLIM memory.\n");
7099 /* Map HBA Control Registers to a kernel virtual address. */
7100 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7101 if (!phba->ctrl_regs_memmap_p) {
7102 dev_printk(KERN_ERR, &pdev->dev,
7103 "ioremap failed for HBA control registers.\n");
7104 goto out_iounmap_slim;
7107 /* Allocate memory for SLI-2 structures */
7108 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7109 &phba->slim2p.phys, GFP_KERNEL);
7110 if (!phba->slim2p.virt)
7113 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
7114 phba->mbox_ext = (phba->slim2p.virt +
7115 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
7116 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7117 phba->IOCBs = (phba->slim2p.virt +
7118 offsetof(struct lpfc_sli2_slim, IOCBs));
7120 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7121 lpfc_sli_hbq_size(),
7122 &phba->hbqslimp.phys,
7124 if (!phba->hbqslimp.virt)
7127 hbq_count = lpfc_sli_hbq_count();
7128 ptr = phba->hbqslimp.virt;
7129 for (i = 0; i < hbq_count; ++i) {
7130 phba->hbqs[i].hbq_virt = ptr;
7131 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7132 ptr += (lpfc_hbq_defs[i]->entry_count *
7133 sizeof(struct lpfc_hbq_entry));
7135 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7136 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7138 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7140 phba->MBslimaddr = phba->slim_memmap_p;
7141 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7142 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7143 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7144 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
7149 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7150 phba->slim2p.virt, phba->slim2p.phys);
7152 iounmap(phba->ctrl_regs_memmap_p);
7154 iounmap(phba->slim_memmap_p);
7160 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7161 * @phba: pointer to lpfc hba data structure.
7163 * This routine is invoked to unset the PCI device memory space for device
7164 * with SLI-3 interface spec.
7167 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7169 struct pci_dev *pdev;
7171 /* Obtain PCI device reference */
7175 pdev = phba->pcidev;
7177 /* Free coherent DMA memory allocated */
7178 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7179 phba->hbqslimp.virt, phba->hbqslimp.phys);
7180 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7181 phba->slim2p.virt, phba->slim2p.phys);
7183 /* I/O memory unmap */
7184 iounmap(phba->ctrl_regs_memmap_p);
7185 iounmap(phba->slim_memmap_p);
7191 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7192 * @phba: pointer to lpfc hba data structure.
7194 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7195 * done and check status.
7197 * Return 0 if successful, otherwise -ENODEV.
7200 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7202 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7203 struct lpfc_register reg_data;
7204 int i, port_error = 0;
7207 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7208 memset(®_data, 0, sizeof(reg_data));
7209 if (!phba->sli4_hba.PSMPHRregaddr)
7212 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7213 for (i = 0; i < 3000; i++) {
7214 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7215 &portsmphr_reg.word0) ||
7216 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
7217 /* Port has a fatal POST error, break out */
7218 port_error = -ENODEV;
7221 if (LPFC_POST_STAGE_PORT_READY ==
7222 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
7228 * If there was a port error during POST, then don't proceed with
7229 * other register reads as the data may not be valid. Just exit.
7232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7233 "1408 Port Failed POST - portsmphr=0x%x, "
7234 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7235 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7236 portsmphr_reg.word0,
7237 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7238 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7239 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7240 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7241 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7242 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7243 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7244 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7246 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7247 "2534 Device Info: SLIFamily=0x%x, "
7248 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7249 "SLIHint_2=0x%x, FT=0x%x\n",
7250 bf_get(lpfc_sli_intf_sli_family,
7251 &phba->sli4_hba.sli_intf),
7252 bf_get(lpfc_sli_intf_slirev,
7253 &phba->sli4_hba.sli_intf),
7254 bf_get(lpfc_sli_intf_if_type,
7255 &phba->sli4_hba.sli_intf),
7256 bf_get(lpfc_sli_intf_sli_hint1,
7257 &phba->sli4_hba.sli_intf),
7258 bf_get(lpfc_sli_intf_sli_hint2,
7259 &phba->sli4_hba.sli_intf),
7260 bf_get(lpfc_sli_intf_func_type,
7261 &phba->sli4_hba.sli_intf));
7263 * Check for other Port errors during the initialization
7264 * process. Fail the load if the port did not come up
7267 if_type = bf_get(lpfc_sli_intf_if_type,
7268 &phba->sli4_hba.sli_intf);
7270 case LPFC_SLI_INTF_IF_TYPE_0:
7271 phba->sli4_hba.ue_mask_lo =
7272 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7273 phba->sli4_hba.ue_mask_hi =
7274 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7276 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7278 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7279 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7280 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7282 "1422 Unrecoverable Error "
7283 "Detected during POST "
7284 "uerr_lo_reg=0x%x, "
7285 "uerr_hi_reg=0x%x, "
7286 "ue_mask_lo_reg=0x%x, "
7287 "ue_mask_hi_reg=0x%x\n",
7290 phba->sli4_hba.ue_mask_lo,
7291 phba->sli4_hba.ue_mask_hi);
7292 port_error = -ENODEV;
7295 case LPFC_SLI_INTF_IF_TYPE_2:
7296 /* Final checks. The port status should be clean. */
7297 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7299 (bf_get(lpfc_sliport_status_err, ®_data) &&
7300 !bf_get(lpfc_sliport_status_rn, ®_data))) {
7301 phba->work_status[0] =
7302 readl(phba->sli4_hba.u.if_type2.
7304 phba->work_status[1] =
7305 readl(phba->sli4_hba.u.if_type2.
7307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7308 "2888 Unrecoverable port error "
7309 "following POST: port status reg "
7310 "0x%x, port_smphr reg 0x%x, "
7311 "error 1=0x%x, error 2=0x%x\n",
7313 portsmphr_reg.word0,
7314 phba->work_status[0],
7315 phba->work_status[1]);
7316 port_error = -ENODEV;
7319 case LPFC_SLI_INTF_IF_TYPE_1:
7328 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7329 * @phba: pointer to lpfc hba data structure.
7330 * @if_type: The SLI4 interface type getting configured.
7332 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7336 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7339 case LPFC_SLI_INTF_IF_TYPE_0:
7340 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7341 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7342 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7343 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7344 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7345 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7346 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7347 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7348 phba->sli4_hba.SLIINTFregaddr =
7349 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7351 case LPFC_SLI_INTF_IF_TYPE_2:
7352 phba->sli4_hba.u.if_type2.EQDregaddr =
7353 phba->sli4_hba.conf_regs_memmap_p +
7354 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7355 phba->sli4_hba.u.if_type2.ERR1regaddr =
7356 phba->sli4_hba.conf_regs_memmap_p +
7357 LPFC_CTL_PORT_ER1_OFFSET;
7358 phba->sli4_hba.u.if_type2.ERR2regaddr =
7359 phba->sli4_hba.conf_regs_memmap_p +
7360 LPFC_CTL_PORT_ER2_OFFSET;
7361 phba->sli4_hba.u.if_type2.CTRLregaddr =
7362 phba->sli4_hba.conf_regs_memmap_p +
7363 LPFC_CTL_PORT_CTL_OFFSET;
7364 phba->sli4_hba.u.if_type2.STATUSregaddr =
7365 phba->sli4_hba.conf_regs_memmap_p +
7366 LPFC_CTL_PORT_STA_OFFSET;
7367 phba->sli4_hba.SLIINTFregaddr =
7368 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7369 phba->sli4_hba.PSMPHRregaddr =
7370 phba->sli4_hba.conf_regs_memmap_p +
7371 LPFC_CTL_PORT_SEM_OFFSET;
7372 phba->sli4_hba.RQDBregaddr =
7373 phba->sli4_hba.conf_regs_memmap_p +
7374 LPFC_ULP0_RQ_DOORBELL;
7375 phba->sli4_hba.WQDBregaddr =
7376 phba->sli4_hba.conf_regs_memmap_p +
7377 LPFC_ULP0_WQ_DOORBELL;
7378 phba->sli4_hba.EQCQDBregaddr =
7379 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7380 phba->sli4_hba.MQDBregaddr =
7381 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7382 phba->sli4_hba.BMBXregaddr =
7383 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7385 case LPFC_SLI_INTF_IF_TYPE_1:
7387 dev_printk(KERN_ERR, &phba->pcidev->dev,
7388 "FATAL - unsupported SLI4 interface type - %d\n",
7395 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7396 * @phba: pointer to lpfc hba data structure.
7398 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7402 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
7404 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7405 LPFC_SLIPORT_IF0_SMPHR;
7406 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7408 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7410 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7415 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7416 * @phba: pointer to lpfc hba data structure.
7417 * @vf: virtual function number
7419 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7420 * based on the given viftual function number, @vf.
7422 * Return 0 if successful, otherwise -ENODEV.
7425 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7427 if (vf > LPFC_VIR_FUNC_MAX)
7430 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7431 vf * LPFC_VFR_PAGE_SIZE +
7432 LPFC_ULP0_RQ_DOORBELL);
7433 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7434 vf * LPFC_VFR_PAGE_SIZE +
7435 LPFC_ULP0_WQ_DOORBELL);
7436 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7437 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7438 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7439 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7440 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7441 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7446 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7447 * @phba: pointer to lpfc hba data structure.
7449 * This routine is invoked to create the bootstrap mailbox
7450 * region consistent with the SLI-4 interface spec. This
7451 * routine allocates all memory necessary to communicate
7452 * mailbox commands to the port and sets up all alignment
7453 * needs. No locks are expected to be held when calling
7458 * -ENOMEM - could not allocated memory.
7461 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7464 struct lpfc_dmabuf *dmabuf;
7465 struct dma_address *dma_address;
7469 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7474 * The bootstrap mailbox region is comprised of 2 parts
7475 * plus an alignment restriction of 16 bytes.
7477 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
7478 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7479 &dmabuf->phys, GFP_KERNEL);
7480 if (!dmabuf->virt) {
7486 * Initialize the bootstrap mailbox pointers now so that the register
7487 * operations are simple later. The mailbox dma address is required
7488 * to be 16-byte aligned. Also align the virtual memory as each
7489 * maibox is copied into the bmbx mailbox region before issuing the
7490 * command to the port.
7492 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7493 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7495 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7496 LPFC_ALIGN_16_BYTE);
7497 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7498 LPFC_ALIGN_16_BYTE);
7501 * Set the high and low physical addresses now. The SLI4 alignment
7502 * requirement is 16 bytes and the mailbox is posted to the port
7503 * as two 30-bit addresses. The other data is a bit marking whether
7504 * the 30-bit address is the high or low address.
7505 * Upcast bmbx aphys to 64bits so shift instruction compiles
7506 * clean on 32 bit machines.
7508 dma_address = &phba->sli4_hba.bmbx.dma_address;
7509 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7510 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7511 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7512 LPFC_BMBX_BIT1_ADDR_HI);
7514 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7515 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7516 LPFC_BMBX_BIT1_ADDR_LO);
7521 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7522 * @phba: pointer to lpfc hba data structure.
7524 * This routine is invoked to teardown the bootstrap mailbox
7525 * region and release all host resources. This routine requires
7526 * the caller to ensure all mailbox commands recovered, no
7527 * additional mailbox comands are sent, and interrupts are disabled
7528 * before calling this routine.
7532 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7534 dma_free_coherent(&phba->pcidev->dev,
7535 phba->sli4_hba.bmbx.bmbx_size,
7536 phba->sli4_hba.bmbx.dmabuf->virt,
7537 phba->sli4_hba.bmbx.dmabuf->phys);
7539 kfree(phba->sli4_hba.bmbx.dmabuf);
7540 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7544 * lpfc_sli4_read_config - Get the config parameters.
7545 * @phba: pointer to lpfc hba data structure.
7547 * This routine is invoked to read the configuration parameters from the HBA.
7548 * The configuration parameters are used to set the base and maximum values
7549 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7550 * allocation for the port.
7554 * -ENOMEM - No available memory
7555 * -EIO - The mailbox failed to complete successfully.
7558 lpfc_sli4_read_config(struct lpfc_hba *phba)
7561 struct lpfc_mbx_read_config *rd_config;
7562 union lpfc_sli4_cfg_shdr *shdr;
7563 uint32_t shdr_status, shdr_add_status;
7564 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7565 struct lpfc_rsrc_desc_fcfcoe *desc;
7567 uint16_t forced_link_speed;
7569 int length, i, rc = 0, rc2;
7571 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7573 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7574 "2011 Unable to allocate memory for issuing "
7575 "SLI_CONFIG_SPECIAL mailbox command\n");
7579 lpfc_read_config(phba, pmb);
7581 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7582 if (rc != MBX_SUCCESS) {
7583 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7584 "2012 Mailbox failed , mbxCmd x%x "
7585 "READ_CONFIG, mbxStatus x%x\n",
7586 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7587 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7590 rd_config = &pmb->u.mqe.un.rd_config;
7591 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7592 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7593 phba->sli4_hba.lnk_info.lnk_tp =
7594 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7595 phba->sli4_hba.lnk_info.lnk_no =
7596 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7597 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7598 "3081 lnk_type:%d, lnk_numb:%d\n",
7599 phba->sli4_hba.lnk_info.lnk_tp,
7600 phba->sli4_hba.lnk_info.lnk_no);
7602 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7603 "3082 Mailbox (x%x) returned ldv:x0\n",
7604 bf_get(lpfc_mqe_command, &pmb->u.mqe));
7605 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7606 phba->bbcredit_support = 1;
7607 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7610 phba->sli4_hba.extents_in_use =
7611 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
7612 phba->sli4_hba.max_cfg_param.max_xri =
7613 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7614 phba->sli4_hba.max_cfg_param.xri_base =
7615 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7616 phba->sli4_hba.max_cfg_param.max_vpi =
7617 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7618 /* Limit the max we support */
7619 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
7620 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
7621 phba->sli4_hba.max_cfg_param.vpi_base =
7622 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7623 phba->sli4_hba.max_cfg_param.max_rpi =
7624 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7625 phba->sli4_hba.max_cfg_param.rpi_base =
7626 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7627 phba->sli4_hba.max_cfg_param.max_vfi =
7628 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7629 phba->sli4_hba.max_cfg_param.vfi_base =
7630 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7631 phba->sli4_hba.max_cfg_param.max_fcfi =
7632 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
7633 phba->sli4_hba.max_cfg_param.max_eq =
7634 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7635 phba->sli4_hba.max_cfg_param.max_rq =
7636 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7637 phba->sli4_hba.max_cfg_param.max_wq =
7638 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7639 phba->sli4_hba.max_cfg_param.max_cq =
7640 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7641 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7642 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7643 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7644 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
7645 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7646 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
7647 phba->max_vports = phba->max_vpi;
7648 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7649 "2003 cfg params Extents? %d "
7654 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7655 phba->sli4_hba.extents_in_use,
7656 phba->sli4_hba.max_cfg_param.xri_base,
7657 phba->sli4_hba.max_cfg_param.max_xri,
7658 phba->sli4_hba.max_cfg_param.vpi_base,
7659 phba->sli4_hba.max_cfg_param.max_vpi,
7660 phba->sli4_hba.max_cfg_param.vfi_base,
7661 phba->sli4_hba.max_cfg_param.max_vfi,
7662 phba->sli4_hba.max_cfg_param.rpi_base,
7663 phba->sli4_hba.max_cfg_param.max_rpi,
7664 phba->sli4_hba.max_cfg_param.max_fcfi,
7665 phba->sli4_hba.max_cfg_param.max_eq,
7666 phba->sli4_hba.max_cfg_param.max_cq,
7667 phba->sli4_hba.max_cfg_param.max_wq,
7668 phba->sli4_hba.max_cfg_param.max_rq);
7675 /* Update link speed if forced link speed is supported */
7676 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7677 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7679 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7680 if (forced_link_speed) {
7681 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7683 switch (forced_link_speed) {
7685 phba->cfg_link_speed =
7686 LPFC_USER_LINK_SPEED_1G;
7689 phba->cfg_link_speed =
7690 LPFC_USER_LINK_SPEED_2G;
7693 phba->cfg_link_speed =
7694 LPFC_USER_LINK_SPEED_4G;
7697 phba->cfg_link_speed =
7698 LPFC_USER_LINK_SPEED_8G;
7700 case LINK_SPEED_10G:
7701 phba->cfg_link_speed =
7702 LPFC_USER_LINK_SPEED_10G;
7704 case LINK_SPEED_16G:
7705 phba->cfg_link_speed =
7706 LPFC_USER_LINK_SPEED_16G;
7708 case LINK_SPEED_32G:
7709 phba->cfg_link_speed =
7710 LPFC_USER_LINK_SPEED_32G;
7713 phba->cfg_link_speed =
7714 LPFC_USER_LINK_SPEED_AUTO;
7717 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7718 "0047 Unrecognized link "
7721 phba->cfg_link_speed =
7722 LPFC_USER_LINK_SPEED_AUTO;
7727 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7728 length = phba->sli4_hba.max_cfg_param.max_xri -
7729 lpfc_sli4_get_els_iocb_cnt(phba);
7730 if (phba->cfg_hba_queue_depth > length) {
7731 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7732 "3361 HBA queue depth changed from %d to %d\n",
7733 phba->cfg_hba_queue_depth, length);
7734 phba->cfg_hba_queue_depth = length;
7737 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7738 LPFC_SLI_INTF_IF_TYPE_2)
7741 /* get the pf# and vf# for SLI4 if_type 2 port */
7742 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7743 sizeof(struct lpfc_sli4_cfg_mhdr));
7744 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7745 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7746 length, LPFC_SLI4_MBX_EMBED);
7748 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7749 shdr = (union lpfc_sli4_cfg_shdr *)
7750 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7751 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7752 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7753 if (rc2 || shdr_status || shdr_add_status) {
7754 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7755 "3026 Mailbox failed , mbxCmd x%x "
7756 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7757 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7758 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7762 /* search for fc_fcoe resrouce descriptor */
7763 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
7765 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7766 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7767 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7768 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7769 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7770 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7773 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
7774 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
7775 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
7776 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
7777 phba->sli4_hba.iov.pf_number =
7778 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7779 phba->sli4_hba.iov.vf_number =
7780 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7785 if (i < LPFC_RSRC_DESC_MAX_NUM)
7786 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7787 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7788 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7789 phba->sli4_hba.iov.vf_number);
7791 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7792 "3028 GET_FUNCTION_CONFIG: failed to find "
7793 "Resrouce Descriptor:x%x\n",
7794 LPFC_RSRC_DESC_TYPE_FCFCOE);
7797 mempool_free(pmb, phba->mbox_mem_pool);
7802 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7803 * @phba: pointer to lpfc hba data structure.
7805 * This routine is invoked to setup the port-side endian order when
7806 * the port if_type is 0. This routine has no function for other
7811 * -ENOMEM - No available memory
7812 * -EIO - The mailbox failed to complete successfully.
7815 lpfc_setup_endian_order(struct lpfc_hba *phba)
7817 LPFC_MBOXQ_t *mboxq;
7818 uint32_t if_type, rc = 0;
7819 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7820 HOST_ENDIAN_HIGH_WORD1};
7822 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7824 case LPFC_SLI_INTF_IF_TYPE_0:
7825 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7829 "0492 Unable to allocate memory for "
7830 "issuing SLI_CONFIG_SPECIAL mailbox "
7836 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7837 * two words to contain special data values and no other data.
7839 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7840 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7841 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7842 if (rc != MBX_SUCCESS) {
7843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7844 "0493 SLI_CONFIG_SPECIAL mailbox "
7845 "failed with status x%x\n",
7849 mempool_free(mboxq, phba->mbox_mem_pool);
7851 case LPFC_SLI_INTF_IF_TYPE_2:
7852 case LPFC_SLI_INTF_IF_TYPE_1:
7860 * lpfc_sli4_queue_verify - Verify and update EQ counts
7861 * @phba: pointer to lpfc hba data structure.
7863 * This routine is invoked to check the user settable queue counts for EQs.
7864 * After this routine is called the counts will be set to valid values that
7865 * adhere to the constraints of the system's interrupt vectors and the port's
7870 * -ENOMEM - No available memory
7873 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
7876 int fof_vectors = phba->cfg_fof ? 1 : 0;
7879 * Sanity check for configured queue parameters against the run-time
7883 /* Sanity check on HBA EQ parameters */
7884 io_channel = phba->io_channel_irqs;
7886 if (phba->sli4_hba.num_online_cpu < io_channel) {
7887 lpfc_printf_log(phba,
7889 "3188 Reducing IO channels to match number of "
7890 "online CPUs: from %d to %d\n",
7891 io_channel, phba->sli4_hba.num_online_cpu);
7892 io_channel = phba->sli4_hba.num_online_cpu;
7895 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
7896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7897 "2575 Reducing IO channels to match number of "
7898 "available EQs: from %d to %d\n",
7900 phba->sli4_hba.max_cfg_param.max_eq);
7901 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
7904 /* The actual number of FCP / NVME event queues adopted */
7905 if (io_channel != phba->io_channel_irqs)
7906 phba->io_channel_irqs = io_channel;
7907 if (phba->cfg_fcp_io_channel > io_channel)
7908 phba->cfg_fcp_io_channel = io_channel;
7909 if (phba->cfg_nvme_io_channel > io_channel)
7910 phba->cfg_nvme_io_channel = io_channel;
7911 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
7912 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
7914 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7915 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
7916 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
7917 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
7919 /* Get EQ depth from module parameter, fake the default for now */
7920 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7921 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7923 /* Get CQ depth from module parameter, fake the default for now */
7924 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7925 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7930 lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7932 struct lpfc_queue *qdesc;
7935 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7936 phba->sli4_hba.cq_ecount);
7938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7939 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7943 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7945 cnt = LPFC_NVME_WQSIZE;
7946 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7949 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7953 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7954 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7959 lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7961 struct lpfc_queue *qdesc;
7964 /* Create Fast Path FCP CQs */
7965 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7966 phba->sli4_hba.cq_ecount);
7968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7969 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7972 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7974 /* Create Fast Path FCP WQs */
7975 wqesize = (phba->fcp_embed_io) ?
7976 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
7977 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7980 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7984 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7985 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7990 * lpfc_sli4_queue_create - Create all the SLI4 queues
7991 * @phba: pointer to lpfc hba data structure.
7993 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7994 * operation. For each SLI4 queue type, the parameters such as queue entry
7995 * count (queue depth) shall be taken from the module parameter. For now,
7996 * we just use some constant number as place holder.
8000 * -ENOMEM - No availble memory
8001 * -EIO - The mailbox failed to complete successfully.
8004 lpfc_sli4_queue_create(struct lpfc_hba *phba)
8006 struct lpfc_queue *qdesc;
8007 int idx, io_channel;
8010 * Create HBA Record arrays.
8011 * Both NVME and FCP will share that same vectors / EQs
8013 io_channel = phba->io_channel_irqs;
8017 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8018 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8019 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8020 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8021 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8022 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
8023 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8024 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8025 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8026 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
8028 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8029 sizeof(struct lpfc_queue *),
8031 if (!phba->sli4_hba.hba_eq) {
8032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8033 "2576 Failed allocate memory for "
8034 "fast-path EQ record array\n");
8038 if (phba->cfg_fcp_io_channel) {
8039 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8040 sizeof(struct lpfc_queue *),
8042 if (!phba->sli4_hba.fcp_cq) {
8043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8044 "2577 Failed allocate memory for "
8045 "fast-path CQ record array\n");
8048 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8049 sizeof(struct lpfc_queue *),
8051 if (!phba->sli4_hba.fcp_wq) {
8052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8053 "2578 Failed allocate memory for "
8054 "fast-path FCP WQ record array\n");
8058 * Since the first EQ can have multiple CQs associated with it,
8059 * this array is used to quickly see if we have a FCP fast-path
8062 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8065 if (!phba->sli4_hba.fcp_cq_map) {
8066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8067 "2545 Failed allocate memory for "
8068 "fast-path CQ map\n");
8073 if (phba->cfg_nvme_io_channel) {
8074 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8075 sizeof(struct lpfc_queue *),
8077 if (!phba->sli4_hba.nvme_cq) {
8078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8079 "6077 Failed allocate memory for "
8080 "fast-path CQ record array\n");
8084 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8085 sizeof(struct lpfc_queue *),
8087 if (!phba->sli4_hba.nvme_wq) {
8088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8089 "2581 Failed allocate memory for "
8090 "fast-path NVME WQ record array\n");
8095 * Since the first EQ can have multiple CQs associated with it,
8096 * this array is used to quickly see if we have a NVME fast-path
8099 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8102 if (!phba->sli4_hba.nvme_cq_map) {
8103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8104 "6078 Failed allocate memory for "
8105 "fast-path CQ map\n");
8109 if (phba->nvmet_support) {
8110 phba->sli4_hba.nvmet_cqset = kcalloc(
8111 phba->cfg_nvmet_mrq,
8112 sizeof(struct lpfc_queue *),
8114 if (!phba->sli4_hba.nvmet_cqset) {
8115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8116 "3121 Fail allocate memory for "
8117 "fast-path CQ set array\n");
8120 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8121 phba->cfg_nvmet_mrq,
8122 sizeof(struct lpfc_queue *),
8124 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8126 "3122 Fail allocate memory for "
8127 "fast-path RQ set hdr array\n");
8130 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8131 phba->cfg_nvmet_mrq,
8132 sizeof(struct lpfc_queue *),
8134 if (!phba->sli4_hba.nvmet_mrq_data) {
8135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8136 "3124 Fail allocate memory for "
8137 "fast-path RQ set data array\n");
8143 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8145 /* Create HBA Event Queues (EQs) */
8146 for (idx = 0; idx < io_channel; idx++) {
8148 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
8149 phba->sli4_hba.eq_ecount);
8151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8152 "0497 Failed allocate EQ (%d)\n", idx);
8155 phba->sli4_hba.hba_eq[idx] = qdesc;
8158 /* FCP and NVME io channels are not required to be balanced */
8160 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8161 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8164 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8165 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8168 if (phba->nvmet_support) {
8169 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8170 qdesc = lpfc_sli4_queue_alloc(phba,
8171 phba->sli4_hba.cq_esize,
8172 phba->sli4_hba.cq_ecount);
8174 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8175 "3142 Failed allocate NVME "
8176 "CQ Set (%d)\n", idx);
8179 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8184 * Create Slow Path Completion Queues (CQs)
8187 /* Create slow-path Mailbox Command Complete Queue */
8188 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8189 phba->sli4_hba.cq_ecount);
8191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8192 "0500 Failed allocate slow-path mailbox CQ\n");
8195 phba->sli4_hba.mbx_cq = qdesc;
8197 /* Create slow-path ELS Complete Queue */
8198 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8199 phba->sli4_hba.cq_ecount);
8201 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8202 "0501 Failed allocate slow-path ELS CQ\n");
8205 phba->sli4_hba.els_cq = qdesc;
8209 * Create Slow Path Work Queues (WQs)
8212 /* Create Mailbox Command Queue */
8214 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
8215 phba->sli4_hba.mq_ecount);
8217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8218 "0505 Failed allocate slow-path MQ\n");
8221 phba->sli4_hba.mbx_wq = qdesc;
8224 * Create ELS Work Queues
8227 /* Create slow-path ELS Work Queue */
8228 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8229 phba->sli4_hba.wq_ecount);
8231 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8232 "0504 Failed allocate slow-path ELS WQ\n");
8235 phba->sli4_hba.els_wq = qdesc;
8236 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8238 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8239 /* Create NVME LS Complete Queue */
8240 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8241 phba->sli4_hba.cq_ecount);
8243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8244 "6079 Failed allocate NVME LS CQ\n");
8247 phba->sli4_hba.nvmels_cq = qdesc;
8249 /* Create NVME LS Work Queue */
8250 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8251 phba->sli4_hba.wq_ecount);
8253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8254 "6080 Failed allocate NVME LS WQ\n");
8257 phba->sli4_hba.nvmels_wq = qdesc;
8258 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8262 * Create Receive Queue (RQ)
8265 /* Create Receive Queue for header */
8266 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8267 phba->sli4_hba.rq_ecount);
8269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8270 "0506 Failed allocate receive HRQ\n");
8273 phba->sli4_hba.hdr_rq = qdesc;
8275 /* Create Receive Queue for data */
8276 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8277 phba->sli4_hba.rq_ecount);
8279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8280 "0507 Failed allocate receive DRQ\n");
8283 phba->sli4_hba.dat_rq = qdesc;
8285 if (phba->nvmet_support) {
8286 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8287 /* Create NVMET Receive Queue for header */
8288 qdesc = lpfc_sli4_queue_alloc(phba,
8289 phba->sli4_hba.rq_esize,
8290 LPFC_NVMET_RQE_DEF_COUNT);
8292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8293 "3146 Failed allocate "
8297 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8299 /* Only needed for header of RQ pair */
8300 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8302 if (qdesc->rqbp == NULL) {
8303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8304 "6131 Failed allocate "
8309 /* Put list in known state in case driver load fails. */
8310 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8312 /* Create NVMET Receive Queue for data */
8313 qdesc = lpfc_sli4_queue_alloc(phba,
8314 phba->sli4_hba.rq_esize,
8315 LPFC_NVMET_RQE_DEF_COUNT);
8317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8318 "3156 Failed allocate "
8322 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8326 /* Create the Queues needed for Flash Optimized Fabric operations */
8328 lpfc_fof_queue_create(phba);
8332 lpfc_sli4_queue_destroy(phba);
8337 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
8340 lpfc_sli4_queue_free(*qp);
8346 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8353 for (idx = 0; idx < max; idx++)
8354 __lpfc_sli4_release_queue(&(*qs)[idx]);
8361 lpfc_sli4_release_queue_map(uint16_t **qmap)
8363 if (*qmap != NULL) {
8370 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8371 * @phba: pointer to lpfc hba data structure.
8373 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8378 * -ENOMEM - No available memory
8379 * -EIO - The mailbox failed to complete successfully.
8382 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8385 lpfc_fof_queue_destroy(phba);
8387 /* Release HBA eqs */
8388 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
8390 /* Release FCP cqs */
8391 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
8392 phba->cfg_fcp_io_channel);
8394 /* Release FCP wqs */
8395 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
8396 phba->cfg_fcp_io_channel);
8398 /* Release FCP CQ mapping array */
8399 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8401 /* Release NVME cqs */
8402 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8403 phba->cfg_nvme_io_channel);
8405 /* Release NVME wqs */
8406 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8407 phba->cfg_nvme_io_channel);
8409 /* Release NVME CQ mapping array */
8410 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
8412 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8413 phba->cfg_nvmet_mrq);
8415 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8416 phba->cfg_nvmet_mrq);
8417 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8418 phba->cfg_nvmet_mrq);
8420 /* Release mailbox command work queue */
8421 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
8423 /* Release ELS work queue */
8424 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8426 /* Release ELS work queue */
8427 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
8429 /* Release unsolicited receive queue */
8430 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8431 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
8433 /* Release ELS complete queue */
8434 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8436 /* Release NVME LS complete queue */
8437 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
8439 /* Release mailbox command complete queue */
8440 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8442 /* Everything on this list has been freed */
8443 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8447 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8449 struct lpfc_rqb *rqbp;
8450 struct lpfc_dmabuf *h_buf;
8451 struct rqb_dmabuf *rqb_buffer;
8454 while (!list_empty(&rqbp->rqb_buffer_list)) {
8455 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8456 struct lpfc_dmabuf, list);
8458 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8459 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8460 rqbp->buffer_count--;
8466 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8467 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8468 int qidx, uint32_t qtype)
8470 struct lpfc_sli_ring *pring;
8473 if (!eq || !cq || !wq) {
8474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8475 "6085 Fast-path %s (%d) not allocated\n",
8476 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8480 /* create the Cq first */
8481 rc = lpfc_cq_create(phba, cq, eq,
8482 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8485 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8486 qidx, (uint32_t)rc);
8490 if (qtype != LPFC_MBOX) {
8491 /* Setup nvme_cq_map for fast lookup */
8493 *cq_map = cq->queue_id;
8495 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8496 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8497 qidx, cq->queue_id, qidx, eq->queue_id);
8500 rc = lpfc_wq_create(phba, wq, cq, qtype);
8502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8503 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8504 qidx, (uint32_t)rc);
8505 /* no need to tear down cq - caller will do so */
8509 /* Bind this CQ/WQ to the NVME ring */
8511 pring->sli.sli4.wqp = (void *)wq;
8514 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8515 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8516 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8518 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8521 "0539 Failed setup of slow-path MQ: "
8523 /* no need to tear down cq - caller will do so */
8527 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8528 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8529 phba->sli4_hba.mbx_wq->queue_id,
8530 phba->sli4_hba.mbx_cq->queue_id);
8537 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8538 * @phba: pointer to lpfc hba data structure.
8540 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8545 * -ENOMEM - No available memory
8546 * -EIO - The mailbox failed to complete successfully.
8549 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8551 uint32_t shdr_status, shdr_add_status;
8552 union lpfc_sli4_cfg_shdr *shdr;
8553 LPFC_MBOXQ_t *mboxq;
8555 uint32_t length, io_channel;
8558 /* Check for dual-ULP support */
8559 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8561 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8562 "3249 Unable to allocate memory for "
8563 "QUERY_FW_CFG mailbox command\n");
8566 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8567 sizeof(struct lpfc_sli4_cfg_mhdr));
8568 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8569 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8570 length, LPFC_SLI4_MBX_EMBED);
8572 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8574 shdr = (union lpfc_sli4_cfg_shdr *)
8575 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8576 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8577 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8578 if (shdr_status || shdr_add_status || rc) {
8579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8580 "3250 QUERY_FW_CFG mailbox failed with status "
8581 "x%x add_status x%x, mbx status x%x\n",
8582 shdr_status, shdr_add_status, rc);
8583 if (rc != MBX_TIMEOUT)
8584 mempool_free(mboxq, phba->mbox_mem_pool);
8589 phba->sli4_hba.fw_func_mode =
8590 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8591 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8592 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
8593 phba->sli4_hba.physical_port =
8594 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
8595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8596 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8597 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8598 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8600 if (rc != MBX_TIMEOUT)
8601 mempool_free(mboxq, phba->mbox_mem_pool);
8604 * Set up HBA Event Queues (EQs)
8606 io_channel = phba->io_channel_irqs;
8608 /* Set up HBA event queue */
8609 if (io_channel && !phba->sli4_hba.hba_eq) {
8610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8611 "3147 Fast-path EQs not allocated\n");
8615 for (qidx = 0; qidx < io_channel; qidx++) {
8616 if (!phba->sli4_hba.hba_eq[qidx]) {
8617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8618 "0522 Fast-path EQ (%d) not "
8619 "allocated\n", qidx);
8623 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8624 phba->cfg_fcp_imax);
8626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8627 "0523 Failed setup of fast-path EQ "
8628 "(%d), rc = 0x%x\n", qidx,
8632 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8633 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8634 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
8637 if (phba->cfg_nvme_io_channel) {
8638 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
8639 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8640 "6084 Fast-path NVME %s array not allocated\n",
8641 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
8646 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8647 rc = lpfc_create_wq_cq(phba,
8648 phba->sli4_hba.hba_eq[
8650 phba->sli4_hba.nvme_cq[qidx],
8651 phba->sli4_hba.nvme_wq[qidx],
8652 &phba->sli4_hba.nvme_cq_map[qidx],
8655 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8656 "6123 Failed to setup fastpath "
8657 "NVME WQ/CQ (%d), rc = 0x%x\n",
8658 qidx, (uint32_t)rc);
8664 if (phba->cfg_fcp_io_channel) {
8665 /* Set up fast-path FCP Response Complete Queue */
8666 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
8667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8668 "3148 Fast-path FCP %s array not allocated\n",
8669 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
8674 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8675 rc = lpfc_create_wq_cq(phba,
8676 phba->sli4_hba.hba_eq[
8678 phba->sli4_hba.fcp_cq[qidx],
8679 phba->sli4_hba.fcp_wq[qidx],
8680 &phba->sli4_hba.fcp_cq_map[qidx],
8683 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8684 "0535 Failed to setup fastpath "
8685 "FCP WQ/CQ (%d), rc = 0x%x\n",
8686 qidx, (uint32_t)rc);
8693 * Set up Slow Path Complete Queues (CQs)
8696 /* Set up slow-path MBOX CQ/MQ */
8698 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
8699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8700 "0528 %s not allocated\n",
8701 phba->sli4_hba.mbx_cq ?
8702 "Mailbox WQ" : "Mailbox CQ");
8707 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8708 phba->sli4_hba.mbx_cq,
8709 phba->sli4_hba.mbx_wq,
8710 NULL, 0, LPFC_MBOX);
8712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8713 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8717 if (phba->nvmet_support) {
8718 if (!phba->sli4_hba.nvmet_cqset) {
8719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8720 "3165 Fast-path NVME CQ Set "
8721 "array not allocated\n");
8725 if (phba->cfg_nvmet_mrq > 1) {
8726 rc = lpfc_cq_create_set(phba,
8727 phba->sli4_hba.nvmet_cqset,
8728 phba->sli4_hba.hba_eq,
8729 LPFC_WCQ, LPFC_NVMET);
8731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8732 "3164 Failed setup of NVME CQ "
8738 /* Set up NVMET Receive Complete Queue */
8739 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8740 phba->sli4_hba.hba_eq[0],
8741 LPFC_WCQ, LPFC_NVMET);
8743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8744 "6089 Failed setup NVMET CQ: "
8745 "rc = 0x%x\n", (uint32_t)rc);
8748 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8749 "6090 NVMET CQ setup: cq-id=%d, "
8750 "parent eq-id=%d\n",
8751 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8752 phba->sli4_hba.hba_eq[0]->queue_id);
8756 /* Set up slow-path ELS WQ/CQ */
8757 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
8758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8759 "0530 ELS %s not allocated\n",
8760 phba->sli4_hba.els_cq ? "WQ" : "CQ");
8764 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8765 phba->sli4_hba.els_cq,
8766 phba->sli4_hba.els_wq,
8769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8770 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8774 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8775 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8776 phba->sli4_hba.els_wq->queue_id,
8777 phba->sli4_hba.els_cq->queue_id);
8779 if (phba->cfg_nvme_io_channel) {
8780 /* Set up NVME LS Complete Queue */
8781 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8782 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8783 "6091 LS %s not allocated\n",
8784 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8788 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8789 phba->sli4_hba.nvmels_cq,
8790 phba->sli4_hba.nvmels_wq,
8791 NULL, 0, LPFC_NVME_LS);
8793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8794 "0529 Failed setup of NVVME LS WQ/CQ: "
8795 "rc = 0x%x\n", (uint32_t)rc);
8799 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8800 "6096 ELS WQ setup: wq-id=%d, "
8801 "parent cq-id=%d\n",
8802 phba->sli4_hba.nvmels_wq->queue_id,
8803 phba->sli4_hba.nvmels_cq->queue_id);
8807 * Create NVMET Receive Queue (RQ)
8809 if (phba->nvmet_support) {
8810 if ((!phba->sli4_hba.nvmet_cqset) ||
8811 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8812 (!phba->sli4_hba.nvmet_mrq_data)) {
8813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8814 "6130 MRQ CQ Queues not "
8819 if (phba->cfg_nvmet_mrq > 1) {
8820 rc = lpfc_mrq_create(phba,
8821 phba->sli4_hba.nvmet_mrq_hdr,
8822 phba->sli4_hba.nvmet_mrq_data,
8823 phba->sli4_hba.nvmet_cqset,
8826 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8827 "6098 Failed setup of NVMET "
8834 rc = lpfc_rq_create(phba,
8835 phba->sli4_hba.nvmet_mrq_hdr[0],
8836 phba->sli4_hba.nvmet_mrq_data[0],
8837 phba->sli4_hba.nvmet_cqset[0],
8840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8841 "6057 Failed setup of NVMET "
8842 "Receive Queue: rc = 0x%x\n",
8848 phba, KERN_INFO, LOG_INIT,
8849 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8850 "dat-rq-id=%d parent cq-id=%d\n",
8851 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
8852 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
8853 phba->sli4_hba.nvmet_cqset[0]->queue_id);
8858 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8859 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8860 "0540 Receive Queue not allocated\n");
8865 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
8866 phba->sli4_hba.els_cq, LPFC_USOL);
8868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8869 "0541 Failed setup of Receive Queue: "
8870 "rc = 0x%x\n", (uint32_t)rc);
8874 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8875 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8876 "parent cq-id=%d\n",
8877 phba->sli4_hba.hdr_rq->queue_id,
8878 phba->sli4_hba.dat_rq->queue_id,
8879 phba->sli4_hba.els_cq->queue_id);
8881 if (phba->cfg_fof) {
8882 rc = lpfc_fof_queue_setup(phba);
8884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8885 "0549 Failed setup of FOF Queues: "
8891 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
8892 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
8893 phba->cfg_fcp_imax);
8898 lpfc_sli4_queue_unset(phba);
8904 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8905 * @phba: pointer to lpfc hba data structure.
8907 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8912 * -ENOMEM - No available memory
8913 * -EIO - The mailbox failed to complete successfully.
8916 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8920 /* Unset the queues created for Flash Optimized Fabric operations */
8922 lpfc_fof_queue_destroy(phba);
8924 /* Unset mailbox command work queue */
8925 if (phba->sli4_hba.mbx_wq)
8926 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8928 /* Unset NVME LS work queue */
8929 if (phba->sli4_hba.nvmels_wq)
8930 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8932 /* Unset ELS work queue */
8933 if (phba->sli4_hba.els_wq)
8934 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8936 /* Unset unsolicited receive queue */
8937 if (phba->sli4_hba.hdr_rq)
8938 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8939 phba->sli4_hba.dat_rq);
8941 /* Unset FCP work queue */
8942 if (phba->sli4_hba.fcp_wq)
8943 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8944 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8946 /* Unset NVME work queue */
8947 if (phba->sli4_hba.nvme_wq) {
8948 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8949 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
8952 /* Unset mailbox command complete queue */
8953 if (phba->sli4_hba.mbx_cq)
8954 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8956 /* Unset ELS complete queue */
8957 if (phba->sli4_hba.els_cq)
8958 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8960 /* Unset NVME LS complete queue */
8961 if (phba->sli4_hba.nvmels_cq)
8962 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8964 /* Unset NVME response complete queue */
8965 if (phba->sli4_hba.nvme_cq)
8966 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8967 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8969 /* Unset NVMET MRQ queue */
8970 if (phba->sli4_hba.nvmet_mrq_hdr) {
8971 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8972 lpfc_rq_destroy(phba,
8973 phba->sli4_hba.nvmet_mrq_hdr[qidx],
8974 phba->sli4_hba.nvmet_mrq_data[qidx]);
8977 /* Unset NVMET CQ Set complete queue */
8978 if (phba->sli4_hba.nvmet_cqset) {
8979 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8980 lpfc_cq_destroy(phba,
8981 phba->sli4_hba.nvmet_cqset[qidx]);
8984 /* Unset FCP response complete queue */
8985 if (phba->sli4_hba.fcp_cq)
8986 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8987 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8989 /* Unset fast-path event queue */
8990 if (phba->sli4_hba.hba_eq)
8991 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8992 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
8996 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8997 * @phba: pointer to lpfc hba data structure.
8999 * This routine is invoked to allocate and set up a pool of completion queue
9000 * events. The body of the completion queue event is a completion queue entry
9001 * CQE. For now, this pool is used for the interrupt service routine to queue
9002 * the following HBA completion queue events for the worker thread to process:
9003 * - Mailbox asynchronous events
9004 * - Receive queue completion unsolicited events
9005 * Later, this can be used for all the slow-path events.
9009 * -ENOMEM - No available memory
9012 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9014 struct lpfc_cq_event *cq_event;
9017 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9018 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9020 goto out_pool_create_fail;
9021 list_add_tail(&cq_event->list,
9022 &phba->sli4_hba.sp_cqe_event_pool);
9026 out_pool_create_fail:
9027 lpfc_sli4_cq_event_pool_destroy(phba);
9032 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9033 * @phba: pointer to lpfc hba data structure.
9035 * This routine is invoked to free the pool of completion queue events at
9036 * driver unload time. Note that, it is the responsibility of the driver
9037 * cleanup routine to free all the outstanding completion-queue events
9038 * allocated from this pool back into the pool before invoking this routine
9039 * to destroy the pool.
9042 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9044 struct lpfc_cq_event *cq_event, *next_cq_event;
9046 list_for_each_entry_safe(cq_event, next_cq_event,
9047 &phba->sli4_hba.sp_cqe_event_pool, list) {
9048 list_del(&cq_event->list);
9054 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9055 * @phba: pointer to lpfc hba data structure.
9057 * This routine is the lock free version of the API invoked to allocate a
9058 * completion-queue event from the free pool.
9060 * Return: Pointer to the newly allocated completion-queue event if successful
9063 struct lpfc_cq_event *
9064 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9066 struct lpfc_cq_event *cq_event = NULL;
9068 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9069 struct lpfc_cq_event, list);
9074 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9075 * @phba: pointer to lpfc hba data structure.
9077 * This routine is the lock version of the API invoked to allocate a
9078 * completion-queue event from the free pool.
9080 * Return: Pointer to the newly allocated completion-queue event if successful
9083 struct lpfc_cq_event *
9084 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9086 struct lpfc_cq_event *cq_event;
9087 unsigned long iflags;
9089 spin_lock_irqsave(&phba->hbalock, iflags);
9090 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9091 spin_unlock_irqrestore(&phba->hbalock, iflags);
9096 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9097 * @phba: pointer to lpfc hba data structure.
9098 * @cq_event: pointer to the completion queue event to be freed.
9100 * This routine is the lock free version of the API invoked to release a
9101 * completion-queue event back into the free pool.
9104 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9105 struct lpfc_cq_event *cq_event)
9107 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9111 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9112 * @phba: pointer to lpfc hba data structure.
9113 * @cq_event: pointer to the completion queue event to be freed.
9115 * This routine is the lock version of the API invoked to release a
9116 * completion-queue event back into the free pool.
9119 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9120 struct lpfc_cq_event *cq_event)
9122 unsigned long iflags;
9123 spin_lock_irqsave(&phba->hbalock, iflags);
9124 __lpfc_sli4_cq_event_release(phba, cq_event);
9125 spin_unlock_irqrestore(&phba->hbalock, iflags);
9129 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9130 * @phba: pointer to lpfc hba data structure.
9132 * This routine is to free all the pending completion-queue events to the
9133 * back into the free pool for device reset.
9136 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9139 struct lpfc_cq_event *cqe;
9140 unsigned long iflags;
9142 /* Retrieve all the pending WCQEs from pending WCQE lists */
9143 spin_lock_irqsave(&phba->hbalock, iflags);
9144 /* Pending FCP XRI abort events */
9145 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9147 /* Pending ELS XRI abort events */
9148 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9150 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9151 /* Pending NVME XRI abort events */
9152 list_splice_init(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue,
9155 /* Pending asynnc events */
9156 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9158 spin_unlock_irqrestore(&phba->hbalock, iflags);
9160 while (!list_empty(&cqelist)) {
9161 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9162 lpfc_sli4_cq_event_release(phba, cqe);
9167 * lpfc_pci_function_reset - Reset pci function.
9168 * @phba: pointer to lpfc hba data structure.
9170 * This routine is invoked to request a PCI function reset. It will destroys
9171 * all resources assigned to the PCI function which originates this request.
9175 * -ENOMEM - No available memory
9176 * -EIO - The mailbox failed to complete successfully.
9179 lpfc_pci_function_reset(struct lpfc_hba *phba)
9181 LPFC_MBOXQ_t *mboxq;
9182 uint32_t rc = 0, if_type;
9183 uint32_t shdr_status, shdr_add_status;
9185 uint32_t port_reset = 0;
9186 union lpfc_sli4_cfg_shdr *shdr;
9187 struct lpfc_register reg_data;
9190 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9192 case LPFC_SLI_INTF_IF_TYPE_0:
9193 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9197 "0494 Unable to allocate memory for "
9198 "issuing SLI_FUNCTION_RESET mailbox "
9203 /* Setup PCI function reset mailbox-ioctl command */
9204 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9205 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9206 LPFC_SLI4_MBX_EMBED);
9207 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9208 shdr = (union lpfc_sli4_cfg_shdr *)
9209 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9210 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9211 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9213 if (rc != MBX_TIMEOUT)
9214 mempool_free(mboxq, phba->mbox_mem_pool);
9215 if (shdr_status || shdr_add_status || rc) {
9216 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9217 "0495 SLI_FUNCTION_RESET mailbox "
9218 "failed with status x%x add_status x%x,"
9219 " mbx status x%x\n",
9220 shdr_status, shdr_add_status, rc);
9224 case LPFC_SLI_INTF_IF_TYPE_2:
9227 * Poll the Port Status Register and wait for RDY for
9228 * up to 30 seconds. If the port doesn't respond, treat
9231 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
9232 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9233 STATUSregaddr, ®_data.word0)) {
9237 if (bf_get(lpfc_sliport_status_rdy, ®_data))
9242 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
9243 phba->work_status[0] = readl(
9244 phba->sli4_hba.u.if_type2.ERR1regaddr);
9245 phba->work_status[1] = readl(
9246 phba->sli4_hba.u.if_type2.ERR2regaddr);
9247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9248 "2890 Port not ready, port status reg "
9249 "0x%x error 1=0x%x, error 2=0x%x\n",
9251 phba->work_status[0],
9252 phba->work_status[1]);
9259 * Reset the port now
9262 bf_set(lpfc_sliport_ctrl_end, ®_data,
9263 LPFC_SLIPORT_LITTLE_ENDIAN);
9264 bf_set(lpfc_sliport_ctrl_ip, ®_data,
9265 LPFC_SLIPORT_INIT_PORT);
9266 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9269 pci_read_config_word(phba->pcidev,
9270 PCI_DEVICE_ID, &devid);
9275 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
9281 case LPFC_SLI_INTF_IF_TYPE_1:
9287 /* Catch the not-ready port failure after a port reset. */
9289 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9290 "3317 HBA not functional: IP Reset Failed "
9291 "try: echo fw_reset > board_mode\n");
9299 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9300 * @phba: pointer to lpfc hba data structure.
9302 * This routine is invoked to set up the PCI device memory space for device
9303 * with SLI-4 interface spec.
9307 * other values - error
9310 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9312 struct pci_dev *pdev;
9313 unsigned long bar0map_len, bar1map_len, bar2map_len;
9314 int error = -ENODEV;
9317 /* Obtain PCI device reference */
9321 pdev = phba->pcidev;
9323 /* Set the device DMA mask size */
9324 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9325 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9326 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9327 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
9333 * The BARs and register set definitions and offset locations are
9334 * dependent on the if_type.
9336 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9337 &phba->sli4_hba.sli_intf.word0)) {
9341 /* There is no SLI3 failback for SLI4 devices. */
9342 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9343 LPFC_SLI_INTF_VALID) {
9344 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9345 "2894 SLI_INTF reg contents invalid "
9346 "sli_intf reg 0x%x\n",
9347 phba->sli4_hba.sli_intf.word0);
9351 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9353 * Get the bus address of SLI4 device Bar regions and the
9354 * number of bytes required by each mapping. The mapping of the
9355 * particular PCI BARs regions is dependent on the type of
9358 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9359 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9360 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
9363 * Map SLI4 PCI Config Space Register base to a kernel virtual
9366 phba->sli4_hba.conf_regs_memmap_p =
9367 ioremap(phba->pci_bar0_map, bar0map_len);
9368 if (!phba->sli4_hba.conf_regs_memmap_p) {
9369 dev_printk(KERN_ERR, &pdev->dev,
9370 "ioremap failed for SLI4 PCI config "
9374 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
9375 /* Set up BAR0 PCI config space register memory map */
9376 lpfc_sli4_bar0_register_memmap(phba, if_type);
9378 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9379 bar0map_len = pci_resource_len(pdev, 1);
9380 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
9381 dev_printk(KERN_ERR, &pdev->dev,
9382 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9385 phba->sli4_hba.conf_regs_memmap_p =
9386 ioremap(phba->pci_bar0_map, bar0map_len);
9387 if (!phba->sli4_hba.conf_regs_memmap_p) {
9388 dev_printk(KERN_ERR, &pdev->dev,
9389 "ioremap failed for SLI4 PCI config "
9393 lpfc_sli4_bar0_register_memmap(phba, if_type);
9396 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9397 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9399 * Map SLI4 if type 0 HBA Control Register base to a
9400 * kernel virtual address and setup the registers.
9402 phba->pci_bar1_map = pci_resource_start(pdev,
9404 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9405 phba->sli4_hba.ctrl_regs_memmap_p =
9406 ioremap(phba->pci_bar1_map,
9408 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9410 "ioremap failed for SLI4 HBA "
9411 "control registers.\n");
9413 goto out_iounmap_conf;
9415 phba->pci_bar2_memmap_p =
9416 phba->sli4_hba.ctrl_regs_memmap_p;
9417 lpfc_sli4_bar1_register_memmap(phba);
9420 goto out_iounmap_conf;
9424 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9425 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9427 * Map SLI4 if type 0 HBA Doorbell Register base to
9428 * a kernel virtual address and setup the registers.
9430 phba->pci_bar2_map = pci_resource_start(pdev,
9432 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9433 phba->sli4_hba.drbl_regs_memmap_p =
9434 ioremap(phba->pci_bar2_map,
9436 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9438 "ioremap failed for SLI4 HBA"
9439 " doorbell registers.\n");
9441 goto out_iounmap_ctrl;
9443 phba->pci_bar4_memmap_p =
9444 phba->sli4_hba.drbl_regs_memmap_p;
9445 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9447 goto out_iounmap_all;
9450 goto out_iounmap_all;
9457 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9459 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9461 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9467 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9468 * @phba: pointer to lpfc hba data structure.
9470 * This routine is invoked to unset the PCI device memory space for device
9471 * with SLI-4 interface spec.
9474 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9477 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9480 case LPFC_SLI_INTF_IF_TYPE_0:
9481 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9482 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9483 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9485 case LPFC_SLI_INTF_IF_TYPE_2:
9486 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9488 case LPFC_SLI_INTF_IF_TYPE_1:
9490 dev_printk(KERN_ERR, &phba->pcidev->dev,
9491 "FATAL - unsupported SLI4 interface type - %d\n",
9498 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9499 * @phba: pointer to lpfc hba data structure.
9501 * This routine is invoked to enable the MSI-X interrupt vectors to device
9502 * with SLI-3 interface specs.
9506 * other values - error
9509 lpfc_sli_enable_msix(struct lpfc_hba *phba)
9514 /* Set up MSI-X multi-message vectors */
9515 rc = pci_alloc_irq_vectors(phba->pcidev,
9516 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9518 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9519 "0420 PCI enable MSI-X failed (%d)\n", rc);
9524 * Assign MSI-X vectors to interrupt handlers
9527 /* vector-0 is associated to slow-path handler */
9528 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
9529 &lpfc_sli_sp_intr_handler, 0,
9530 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9532 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9533 "0421 MSI-X slow-path request_irq failed "
9538 /* vector-1 is associated to fast-path handler */
9539 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
9540 &lpfc_sli_fp_intr_handler, 0,
9541 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9544 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9545 "0429 MSI-X fast-path request_irq failed "
9551 * Configure HBA MSI-X attention conditions to messages
9553 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9558 "0474 Unable to allocate memory for issuing "
9559 "MBOX_CONFIG_MSI command\n");
9562 rc = lpfc_config_msi(phba, pmb);
9565 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9566 if (rc != MBX_SUCCESS) {
9567 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9568 "0351 Config MSI mailbox command failed, "
9569 "mbxCmd x%x, mbxStatus x%x\n",
9570 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9574 /* Free memory allocated for mailbox command */
9575 mempool_free(pmb, phba->mbox_mem_pool);
9579 /* Free memory allocated for mailbox command */
9580 mempool_free(pmb, phba->mbox_mem_pool);
9583 /* free the irq already requested */
9584 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
9587 /* free the irq already requested */
9588 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
9591 /* Unconfigure MSI-X capability structure */
9592 pci_free_irq_vectors(phba->pcidev);
9599 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9600 * @phba: pointer to lpfc hba data structure.
9602 * This routine is invoked to enable the MSI interrupt mode to device with
9603 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9604 * enable the MSI vector. The device driver is responsible for calling the
9605 * request_irq() to register MSI vector with a interrupt the handler, which
9606 * is done in this function.
9610 * other values - error
9613 lpfc_sli_enable_msi(struct lpfc_hba *phba)
9617 rc = pci_enable_msi(phba->pcidev);
9619 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9620 "0462 PCI enable MSI mode success.\n");
9622 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9623 "0471 PCI enable MSI mode failed (%d)\n", rc);
9627 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9628 0, LPFC_DRIVER_NAME, phba);
9630 pci_disable_msi(phba->pcidev);
9631 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9632 "0478 MSI request_irq failed (%d)\n", rc);
9638 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9639 * @phba: pointer to lpfc hba data structure.
9641 * This routine is invoked to enable device interrupt and associate driver's
9642 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9643 * spec. Depends on the interrupt mode configured to the driver, the driver
9644 * will try to fallback from the configured interrupt mode to an interrupt
9645 * mode which is supported by the platform, kernel, and device in the order
9647 * MSI-X -> MSI -> IRQ.
9651 * other values - error
9654 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9656 uint32_t intr_mode = LPFC_INTR_ERROR;
9659 if (cfg_mode == 2) {
9660 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9661 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9663 /* Now, try to enable MSI-X interrupt mode */
9664 retval = lpfc_sli_enable_msix(phba);
9666 /* Indicate initialization to MSI-X mode */
9667 phba->intr_type = MSIX;
9673 /* Fallback to MSI if MSI-X initialization failed */
9674 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9675 retval = lpfc_sli_enable_msi(phba);
9677 /* Indicate initialization to MSI mode */
9678 phba->intr_type = MSI;
9683 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9684 if (phba->intr_type == NONE) {
9685 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9686 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9688 /* Indicate initialization to INTx mode */
9689 phba->intr_type = INTx;
9697 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9698 * @phba: pointer to lpfc hba data structure.
9700 * This routine is invoked to disable device interrupt and disassociate the
9701 * driver's interrupt handler(s) from interrupt vector(s) to device with
9702 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9703 * release the interrupt vector(s) for the message signaled interrupt.
9706 lpfc_sli_disable_intr(struct lpfc_hba *phba)
9710 if (phba->intr_type == MSIX)
9711 nr_irqs = LPFC_MSIX_VECTORS;
9715 for (i = 0; i < nr_irqs; i++)
9716 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9717 pci_free_irq_vectors(phba->pcidev);
9719 /* Reset interrupt management states */
9720 phba->intr_type = NONE;
9721 phba->sli.slistat.sli_intr = 0;
9725 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
9726 * @phba: pointer to lpfc hba data structure.
9727 * @vectors: number of msix vectors allocated.
9729 * The routine will figure out the CPU affinity assignment for every
9730 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9731 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9732 * can be associated with. If the vector can be unquely associated with
9733 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9734 * In addition, the CPU to IO channel mapping will be calculated
9735 * and the phba->sli4_hba.cpu_map array will reflect this.
9738 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
9740 struct lpfc_vector_map_info *cpup;
9745 struct cpuinfo_x86 *cpuinfo;
9748 /* Init cpu_map array */
9749 memset(phba->sli4_hba.cpu_map, 0xff,
9750 (sizeof(struct lpfc_vector_map_info) *
9751 phba->sli4_hba.num_present_cpu));
9753 /* Update CPU map with physical id and core id of each CPU */
9754 cpup = phba->sli4_hba.cpu_map;
9755 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9757 cpuinfo = &cpu_data(cpu);
9758 cpup->phys_id = cpuinfo->phys_proc_id;
9759 cpup->core_id = cpuinfo->cpu_core_id;
9761 /* No distinction between CPUs for other platforms */
9765 cpup->channel_id = index; /* For now round robin */
9766 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9771 if (index >= phba->cfg_fcp_io_channel)
9779 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9780 * @phba: pointer to lpfc hba data structure.
9782 * This routine is invoked to enable the MSI-X interrupt vectors to device
9783 * with SLI-4 interface spec.
9787 * other values - error
9790 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9792 int vectors, rc, index;
9795 /* Set up MSI-X multi-message vectors */
9796 vectors = phba->io_channel_irqs;
9800 rc = pci_alloc_irq_vectors(phba->pcidev,
9801 (phba->nvmet_support) ? 1 : 2,
9802 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
9804 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9805 "0484 PCI enable MSI-X failed (%d)\n", rc);
9810 /* Assign MSI-X vectors to interrupt handlers */
9811 for (index = 0; index < vectors; index++) {
9812 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
9813 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
9814 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
9815 LPFC_DRIVER_HANDLER_NAME"%d", index);
9817 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9818 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9819 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
9820 if (phba->cfg_fof && (index == (vectors - 1)))
9821 rc = request_irq(pci_irq_vector(phba->pcidev, index),
9822 &lpfc_sli4_fof_intr_handler, 0,
9824 &phba->sli4_hba.hba_eq_hdl[index]);
9826 rc = request_irq(pci_irq_vector(phba->pcidev, index),
9827 &lpfc_sli4_hba_intr_handler, 0,
9829 &phba->sli4_hba.hba_eq_hdl[index]);
9831 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9832 "0486 MSI-X fast-path (%d) "
9833 "request_irq failed (%d)\n", index, rc);
9841 if (vectors != phba->io_channel_irqs) {
9842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9843 "3238 Reducing IO channels to match number of "
9844 "MSI-X vectors, requested %d got %d\n",
9845 phba->io_channel_irqs, vectors);
9846 if (phba->cfg_fcp_io_channel > vectors)
9847 phba->cfg_fcp_io_channel = vectors;
9848 if (phba->cfg_nvme_io_channel > vectors)
9849 phba->cfg_nvme_io_channel = vectors;
9850 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9851 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9853 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
9855 lpfc_cpu_affinity_check(phba, vectors);
9860 /* free the irq already requested */
9861 for (--index; index >= 0; index--)
9862 free_irq(pci_irq_vector(phba->pcidev, index),
9863 &phba->sli4_hba.hba_eq_hdl[index]);
9865 /* Unconfigure MSI-X capability structure */
9866 pci_free_irq_vectors(phba->pcidev);
9873 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9874 * @phba: pointer to lpfc hba data structure.
9876 * This routine is invoked to enable the MSI interrupt mode to device with
9877 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9878 * to enable the MSI vector. The device driver is responsible for calling
9879 * the request_irq() to register MSI vector with a interrupt the handler,
9880 * which is done in this function.
9884 * other values - error
9887 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9891 rc = pci_enable_msi(phba->pcidev);
9893 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9894 "0487 PCI enable MSI mode success.\n");
9896 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9897 "0488 PCI enable MSI mode failed (%d)\n", rc);
9901 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9902 0, LPFC_DRIVER_NAME, phba);
9904 pci_disable_msi(phba->pcidev);
9905 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9906 "0490 MSI request_irq failed (%d)\n", rc);
9910 for (index = 0; index < phba->io_channel_irqs; index++) {
9911 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9912 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9915 if (phba->cfg_fof) {
9916 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9917 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9923 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9924 * @phba: pointer to lpfc hba data structure.
9926 * This routine is invoked to enable device interrupt and associate driver's
9927 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9928 * interface spec. Depends on the interrupt mode configured to the driver,
9929 * the driver will try to fallback from the configured interrupt mode to an
9930 * interrupt mode which is supported by the platform, kernel, and device in
9932 * MSI-X -> MSI -> IRQ.
9936 * other values - error
9939 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9941 uint32_t intr_mode = LPFC_INTR_ERROR;
9944 if (cfg_mode == 2) {
9945 /* Preparation before conf_msi mbox cmd */
9948 /* Now, try to enable MSI-X interrupt mode */
9949 retval = lpfc_sli4_enable_msix(phba);
9951 /* Indicate initialization to MSI-X mode */
9952 phba->intr_type = MSIX;
9958 /* Fallback to MSI if MSI-X initialization failed */
9959 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9960 retval = lpfc_sli4_enable_msi(phba);
9962 /* Indicate initialization to MSI mode */
9963 phba->intr_type = MSI;
9968 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9969 if (phba->intr_type == NONE) {
9970 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9971 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9973 struct lpfc_hba_eq_hdl *eqhdl;
9975 /* Indicate initialization to INTx mode */
9976 phba->intr_type = INTx;
9979 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9980 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9983 atomic_set(&eqhdl->hba_eq_in_use, 1);
9985 if (phba->cfg_fof) {
9986 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9989 atomic_set(&eqhdl->hba_eq_in_use, 1);
9997 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9998 * @phba: pointer to lpfc hba data structure.
10000 * This routine is invoked to disable device interrupt and disassociate
10001 * the driver's interrupt handler(s) from interrupt vector(s) to device
10002 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10003 * will release the interrupt vector(s) for the message signaled interrupt.
10006 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10008 /* Disable the currently initialized interrupt mode */
10009 if (phba->intr_type == MSIX) {
10012 /* Free up MSI-X multi-message vectors */
10013 for (index = 0; index < phba->io_channel_irqs; index++)
10014 free_irq(pci_irq_vector(phba->pcidev, index),
10015 &phba->sli4_hba.hba_eq_hdl[index]);
10018 free_irq(pci_irq_vector(phba->pcidev, index),
10019 &phba->sli4_hba.hba_eq_hdl[index]);
10021 free_irq(phba->pcidev->irq, phba);
10024 pci_free_irq_vectors(phba->pcidev);
10026 /* Reset interrupt management states */
10027 phba->intr_type = NONE;
10028 phba->sli.slistat.sli_intr = 0;
10032 * lpfc_unset_hba - Unset SLI3 hba device initialization
10033 * @phba: pointer to lpfc hba data structure.
10035 * This routine is invoked to unset the HBA device initialization steps to
10036 * a device with SLI-3 interface spec.
10039 lpfc_unset_hba(struct lpfc_hba *phba)
10041 struct lpfc_vport *vport = phba->pport;
10042 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10044 spin_lock_irq(shost->host_lock);
10045 vport->load_flag |= FC_UNLOADING;
10046 spin_unlock_irq(shost->host_lock);
10048 kfree(phba->vpi_bmask);
10049 kfree(phba->vpi_ids);
10051 lpfc_stop_hba_timers(phba);
10053 phba->pport->work_port_events = 0;
10055 lpfc_sli_hba_down(phba);
10057 lpfc_sli_brdrestart(phba);
10059 lpfc_sli_disable_intr(phba);
10065 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10066 * @phba: Pointer to HBA context object.
10068 * This function is called in the SLI4 code path to wait for completion
10069 * of device's XRIs exchange busy. It will check the XRI exchange busy
10070 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10071 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10072 * I/Os every 30 seconds, log error message, and wait forever. Only when
10073 * all XRI exchange busy complete, the driver unload shall proceed with
10074 * invoking the function reset ioctl mailbox command to the CNA and the
10075 * the rest of the driver unload resource release.
10078 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10081 int nvme_xri_cmpl = 1;
10082 int nvmet_xri_cmpl = 1;
10083 int fcp_xri_cmpl = 1;
10084 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10086 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10088 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
10089 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10091 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
10093 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10096 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10098 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
10099 if (!nvme_xri_cmpl)
10100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10101 "6100 NVME XRI exchange busy "
10102 "wait time: %d seconds.\n",
10105 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10106 "2877 FCP XRI exchange busy "
10107 "wait time: %d seconds.\n",
10110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10111 "2878 ELS XRI exchange busy "
10112 "wait time: %d seconds.\n",
10114 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10115 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10117 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10118 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10120 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10121 nvme_xri_cmpl = list_empty(
10122 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
10123 nvmet_xri_cmpl = list_empty(
10124 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10127 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10128 fcp_xri_cmpl = list_empty(
10129 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10132 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10138 * lpfc_sli4_hba_unset - Unset the fcoe hba
10139 * @phba: Pointer to HBA context object.
10141 * This function is called in the SLI4 code path to reset the HBA's FCoE
10142 * function. The caller is not required to hold any lock. This routine
10143 * issues PCI function reset mailbox command to reset the FCoE function.
10144 * At the end of the function, it calls lpfc_hba_down_post function to
10145 * free any pending commands.
10148 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10151 LPFC_MBOXQ_t *mboxq;
10152 struct pci_dev *pdev = phba->pcidev;
10154 lpfc_stop_hba_timers(phba);
10155 phba->sli4_hba.intr_enable = 0;
10158 * Gracefully wait out the potential current outstanding asynchronous
10162 /* First, block any pending async mailbox command from posted */
10163 spin_lock_irq(&phba->hbalock);
10164 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10165 spin_unlock_irq(&phba->hbalock);
10166 /* Now, trying to wait it out if we can */
10167 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10169 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10172 /* Forcefully release the outstanding mailbox command if timed out */
10173 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10174 spin_lock_irq(&phba->hbalock);
10175 mboxq = phba->sli.mbox_active;
10176 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10177 __lpfc_mbox_cmpl_put(phba, mboxq);
10178 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10179 phba->sli.mbox_active = NULL;
10180 spin_unlock_irq(&phba->hbalock);
10183 /* Abort all iocbs associated with the hba */
10184 lpfc_sli_hba_iocb_abort(phba);
10186 /* Wait for completion of device XRI exchange busy */
10187 lpfc_sli4_xri_exchange_busy_wait(phba);
10189 /* Disable PCI subsystem interrupt */
10190 lpfc_sli4_disable_intr(phba);
10192 /* Disable SR-IOV if enabled */
10193 if (phba->cfg_sriov_nr_virtfn)
10194 pci_disable_sriov(pdev);
10196 /* Stop kthread signal shall trigger work_done one more time */
10197 kthread_stop(phba->worker_thread);
10199 /* Unset the queues shared with the hardware then release all
10200 * allocated resources.
10202 lpfc_sli4_queue_unset(phba);
10203 lpfc_sli4_queue_destroy(phba);
10205 /* Reset SLI4 HBA FCoE function */
10206 lpfc_pci_function_reset(phba);
10208 /* Stop the SLI4 device port */
10209 phba->pport->work_port_events = 0;
10213 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10214 * @phba: Pointer to HBA context object.
10215 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10217 * This function is called in the SLI4 code path to read the port's
10218 * sli4 capabilities.
10220 * This function may be be called from any context that can block-wait
10221 * for the completion. The expectation is that this routine is called
10222 * typically from probe_one or from the online routine.
10225 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10228 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10229 struct lpfc_pc_sli4_params *sli4_params;
10232 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10235 * By default, the driver assumes the SLI4 port requires RPI
10236 * header postings. The SLI4_PARAM response will correct this
10239 phba->sli4_hba.rpi_hdrs_in_use = 1;
10241 /* Read the port's SLI4 Config Parameters */
10242 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10243 sizeof(struct lpfc_sli4_cfg_mhdr));
10244 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10245 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10246 length, LPFC_SLI4_MBX_EMBED);
10247 if (!phba->sli4_hba.intr_enable)
10248 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10250 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10251 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10255 sli4_params = &phba->sli4_hba.pc_sli4_params;
10256 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10257 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10258 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10259 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10260 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10261 mbx_sli4_parameters);
10262 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10263 mbx_sli4_parameters);
10264 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10265 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10267 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10268 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10269 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
10270 mbx_sli4_parameters);
10271 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
10272 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10273 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10274 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10275 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
10276 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
10277 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10278 mbx_sli4_parameters);
10279 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
10280 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10281 mbx_sli4_parameters);
10282 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10283 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
10284 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10285 bf_get(cfg_xib, mbx_sli4_parameters));
10287 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10288 !phba->nvme_support) {
10289 phba->nvme_support = 0;
10290 phba->nvmet_support = 0;
10291 phba->cfg_nvmet_mrq = 0;
10292 phba->cfg_nvme_io_channel = 0;
10293 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10294 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10295 "6101 Disabling NVME support: "
10296 "Not supported by firmware: %d %d\n",
10297 bf_get(cfg_nvme, mbx_sli4_parameters),
10298 bf_get(cfg_xib, mbx_sli4_parameters));
10300 /* If firmware doesn't support NVME, just use SCSI support */
10301 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10303 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10306 if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp)
10307 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10309 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10310 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10312 /* Make sure that sge_supp_len can be handled by the driver */
10313 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10314 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10317 * Issue IOs with CDB embedded in WQE to minimized the number
10318 * of DMAs the firmware has to do. Setting this to 1 also forces
10319 * the driver to use 128 bytes WQEs for FCP IOs.
10321 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10322 phba->fcp_embed_io = 1;
10324 phba->fcp_embed_io = 0;
10327 * Check if the SLI port supports MDS Diagnostics
10329 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10330 phba->mds_diags_support = 1;
10332 phba->mds_diags_support = 0;
10337 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10338 * @pdev: pointer to PCI device
10339 * @pid: pointer to PCI device identifier
10341 * This routine is to be called to attach a device with SLI-3 interface spec
10342 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10343 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10344 * information of the device and driver to see if the driver state that it can
10345 * support this kind of device. If the match is successful, the driver core
10346 * invokes this routine. If this routine determines it can claim the HBA, it
10347 * does all the initialization that it needs to do to handle the HBA properly.
10350 * 0 - driver can claim the device
10351 * negative value - driver can not claim the device
10354 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10356 struct lpfc_hba *phba;
10357 struct lpfc_vport *vport = NULL;
10358 struct Scsi_Host *shost = NULL;
10360 uint32_t cfg_mode, intr_mode;
10362 /* Allocate memory for HBA structure */
10363 phba = lpfc_hba_alloc(pdev);
10367 /* Perform generic PCI device enabling operation */
10368 error = lpfc_enable_pci_dev(phba);
10370 goto out_free_phba;
10372 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10373 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10375 goto out_disable_pci_dev;
10377 /* Set up SLI-3 specific device PCI memory space */
10378 error = lpfc_sli_pci_mem_setup(phba);
10380 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10381 "1402 Failed to set up pci memory space.\n");
10382 goto out_disable_pci_dev;
10385 /* Set up SLI-3 specific device driver resources */
10386 error = lpfc_sli_driver_resource_setup(phba);
10388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10389 "1404 Failed to set up driver resource.\n");
10390 goto out_unset_pci_mem_s3;
10393 /* Initialize and populate the iocb list per host */
10395 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10398 "1405 Failed to initialize iocb list.\n");
10399 goto out_unset_driver_resource_s3;
10402 /* Set up common device driver resources */
10403 error = lpfc_setup_driver_resource_phase2(phba);
10405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10406 "1406 Failed to set up driver resource.\n");
10407 goto out_free_iocb_list;
10410 /* Get the default values for Model Name and Description */
10411 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10413 /* Create SCSI host to the physical port */
10414 error = lpfc_create_shost(phba);
10416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10417 "1407 Failed to create scsi host.\n");
10418 goto out_unset_driver_resource;
10421 /* Configure sysfs attributes */
10422 vport = phba->pport;
10423 error = lpfc_alloc_sysfs_attr(vport);
10425 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10426 "1476 Failed to allocate sysfs attr\n");
10427 goto out_destroy_shost;
10430 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
10431 /* Now, trying to enable interrupt and bring up the device */
10432 cfg_mode = phba->cfg_use_msi;
10434 /* Put device to a known state before enabling interrupt */
10435 lpfc_stop_port(phba);
10436 /* Configure and enable interrupt */
10437 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10438 if (intr_mode == LPFC_INTR_ERROR) {
10439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10440 "0431 Failed to enable interrupt.\n");
10442 goto out_free_sysfs_attr;
10444 /* SLI-3 HBA setup */
10445 if (lpfc_sli_hba_setup(phba)) {
10446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10447 "1477 Failed to set up hba\n");
10449 goto out_remove_device;
10452 /* Wait 50ms for the interrupts of previous mailbox commands */
10454 /* Check active interrupts on message signaled interrupts */
10455 if (intr_mode == 0 ||
10456 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10457 /* Log the current active interrupt mode */
10458 phba->intr_mode = intr_mode;
10459 lpfc_log_intr_mode(phba, intr_mode);
10462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10463 "0447 Configure interrupt mode (%d) "
10464 "failed active interrupt test.\n",
10466 /* Disable the current interrupt mode */
10467 lpfc_sli_disable_intr(phba);
10468 /* Try next level of interrupt mode */
10469 cfg_mode = --intr_mode;
10473 /* Perform post initialization setup */
10474 lpfc_post_init_setup(phba);
10476 /* Check if there are static vports to be created. */
10477 lpfc_create_static_vport(phba);
10482 lpfc_unset_hba(phba);
10483 out_free_sysfs_attr:
10484 lpfc_free_sysfs_attr(vport);
10486 lpfc_destroy_shost(phba);
10487 out_unset_driver_resource:
10488 lpfc_unset_driver_resource_phase2(phba);
10489 out_free_iocb_list:
10490 lpfc_free_iocb_list(phba);
10491 out_unset_driver_resource_s3:
10492 lpfc_sli_driver_resource_unset(phba);
10493 out_unset_pci_mem_s3:
10494 lpfc_sli_pci_mem_unset(phba);
10495 out_disable_pci_dev:
10496 lpfc_disable_pci_dev(phba);
10498 scsi_host_put(shost);
10500 lpfc_hba_free(phba);
10505 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10506 * @pdev: pointer to PCI device
10508 * This routine is to be called to disattach a device with SLI-3 interface
10509 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10510 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10511 * device to be removed from the PCI subsystem properly.
10514 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
10516 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10518 struct lpfc_vport **vports;
10519 struct lpfc_hba *phba = vport->phba;
10522 spin_lock_irq(&phba->hbalock);
10523 vport->load_flag |= FC_UNLOADING;
10524 spin_unlock_irq(&phba->hbalock);
10526 lpfc_free_sysfs_attr(vport);
10528 /* Release all the vports against this physical port */
10529 vports = lpfc_create_vport_work_array(phba);
10530 if (vports != NULL)
10531 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10532 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10534 fc_vport_terminate(vports[i]->fc_vport);
10536 lpfc_destroy_vport_work_array(phba, vports);
10538 /* Remove FC host and then SCSI host with the physical port */
10539 fc_remove_host(shost);
10540 scsi_remove_host(shost);
10542 lpfc_cleanup(vport);
10545 * Bring down the SLI Layer. This step disable all interrupts,
10546 * clears the rings, discards all mailbox commands, and resets
10550 /* HBA interrupt will be disabled after this call */
10551 lpfc_sli_hba_down(phba);
10552 /* Stop kthread signal shall trigger work_done one more time */
10553 kthread_stop(phba->worker_thread);
10554 /* Final cleanup of txcmplq and reset the HBA */
10555 lpfc_sli_brdrestart(phba);
10557 kfree(phba->vpi_bmask);
10558 kfree(phba->vpi_ids);
10560 lpfc_stop_hba_timers(phba);
10561 spin_lock_irq(&phba->hbalock);
10562 list_del_init(&vport->listentry);
10563 spin_unlock_irq(&phba->hbalock);
10565 lpfc_debugfs_terminate(vport);
10567 /* Disable SR-IOV if enabled */
10568 if (phba->cfg_sriov_nr_virtfn)
10569 pci_disable_sriov(pdev);
10571 /* Disable interrupt */
10572 lpfc_sli_disable_intr(phba);
10574 scsi_host_put(shost);
10577 * Call scsi_free before mem_free since scsi bufs are released to their
10578 * corresponding pools here.
10580 lpfc_scsi_free(phba);
10581 lpfc_mem_free_all(phba);
10583 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10584 phba->hbqslimp.virt, phba->hbqslimp.phys);
10586 /* Free resources associated with SLI2 interface */
10587 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
10588 phba->slim2p.virt, phba->slim2p.phys);
10590 /* unmap adapter SLIM and Control Registers */
10591 iounmap(phba->ctrl_regs_memmap_p);
10592 iounmap(phba->slim_memmap_p);
10594 lpfc_hba_free(phba);
10596 pci_release_mem_regions(pdev);
10597 pci_disable_device(pdev);
10601 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
10602 * @pdev: pointer to PCI device
10603 * @msg: power management message
10605 * This routine is to be called from the kernel's PCI subsystem to support
10606 * system Power Management (PM) to device with SLI-3 interface spec. When
10607 * PM invokes this method, it quiesces the device by stopping the driver's
10608 * worker thread for the device, turning off device's interrupt and DMA,
10609 * and bring the device offline. Note that as the driver implements the
10610 * minimum PM requirements to a power-aware driver's PM support for the
10611 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10612 * to the suspend() method call will be treated as SUSPEND and the driver will
10613 * fully reinitialize its device during resume() method call, the driver will
10614 * set device to PCI_D3hot state in PCI config space instead of setting it
10615 * according to the @msg provided by the PM.
10618 * 0 - driver suspended the device
10622 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
10624 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10625 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10627 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10628 "0473 PCI device Power Management suspend.\n");
10630 /* Bring down the device */
10631 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10632 lpfc_offline(phba);
10633 kthread_stop(phba->worker_thread);
10635 /* Disable interrupt from device */
10636 lpfc_sli_disable_intr(phba);
10638 /* Save device state to PCI config space */
10639 pci_save_state(pdev);
10640 pci_set_power_state(pdev, PCI_D3hot);
10646 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
10647 * @pdev: pointer to PCI device
10649 * This routine is to be called from the kernel's PCI subsystem to support
10650 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10651 * invokes this method, it restores the device's PCI config space state and
10652 * fully reinitializes the device and brings it online. Note that as the
10653 * driver implements the minimum PM requirements to a power-aware driver's
10654 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10655 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10656 * driver will fully reinitialize its device during resume() method call,
10657 * the device will be set to PCI_D0 directly in PCI config space before
10658 * restoring the state.
10661 * 0 - driver suspended the device
10665 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
10667 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10668 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10669 uint32_t intr_mode;
10672 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10673 "0452 PCI device Power Management resume.\n");
10675 /* Restore device state from PCI config space */
10676 pci_set_power_state(pdev, PCI_D0);
10677 pci_restore_state(pdev);
10680 * As the new kernel behavior of pci_restore_state() API call clears
10681 * device saved_state flag, need to save the restored state again.
10683 pci_save_state(pdev);
10685 if (pdev->is_busmaster)
10686 pci_set_master(pdev);
10688 /* Startup the kernel thread for this host adapter. */
10689 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10690 "lpfc_worker_%d", phba->brd_no);
10691 if (IS_ERR(phba->worker_thread)) {
10692 error = PTR_ERR(phba->worker_thread);
10693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10694 "0434 PM resume failed to start worker "
10695 "thread: error=x%x.\n", error);
10699 /* Configure and enable interrupt */
10700 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
10701 if (intr_mode == LPFC_INTR_ERROR) {
10702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10703 "0430 PM resume Failed to enable interrupt\n");
10706 phba->intr_mode = intr_mode;
10708 /* Restart HBA and bring it online */
10709 lpfc_sli_brdrestart(phba);
10712 /* Log the current active interrupt mode */
10713 lpfc_log_intr_mode(phba, phba->intr_mode);
10719 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10720 * @phba: pointer to lpfc hba data structure.
10722 * This routine is called to prepare the SLI3 device for PCI slot recover. It
10723 * aborts all the outstanding SCSI I/Os to the pci device.
10726 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10729 "2723 PCI channel I/O abort preparing for recovery\n");
10732 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10733 * and let the SCSI mid-layer to retry them to recover.
10735 lpfc_sli_abort_fcp_rings(phba);
10739 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10740 * @phba: pointer to lpfc hba data structure.
10742 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10743 * disables the device interrupt and pci device, and aborts the internal FCP
10747 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10750 "2710 PCI channel disable preparing for reset\n");
10752 /* Block any management I/Os to the device */
10753 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
10755 /* Block all SCSI devices' I/Os on the host */
10756 lpfc_scsi_dev_block(phba);
10758 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10759 lpfc_sli_flush_fcp_rings(phba);
10761 /* stop all timers */
10762 lpfc_stop_hba_timers(phba);
10764 /* Disable interrupt and pci device */
10765 lpfc_sli_disable_intr(phba);
10766 pci_disable_device(phba->pcidev);
10770 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10771 * @phba: pointer to lpfc hba data structure.
10773 * This routine is called to prepare the SLI3 device for PCI slot permanently
10774 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10778 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10781 "2711 PCI channel permanent disable for failure\n");
10782 /* Block all SCSI devices' I/Os on the host */
10783 lpfc_scsi_dev_block(phba);
10785 /* stop all timers */
10786 lpfc_stop_hba_timers(phba);
10788 /* Clean up all driver's outstanding SCSI I/Os */
10789 lpfc_sli_flush_fcp_rings(phba);
10793 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
10794 * @pdev: pointer to PCI device.
10795 * @state: the current PCI connection state.
10797 * This routine is called from the PCI subsystem for I/O error handling to
10798 * device with SLI-3 interface spec. This function is called by the PCI
10799 * subsystem after a PCI bus error affecting this device has been detected.
10800 * When this function is invoked, it will need to stop all the I/Os and
10801 * interrupt(s) to the device. Once that is done, it will return
10802 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10806 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
10807 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10808 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10810 static pci_ers_result_t
10811 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
10813 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10814 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10817 case pci_channel_io_normal:
10818 /* Non-fatal error, prepare for recovery */
10819 lpfc_sli_prep_dev_for_recover(phba);
10820 return PCI_ERS_RESULT_CAN_RECOVER;
10821 case pci_channel_io_frozen:
10822 /* Fatal error, prepare for slot reset */
10823 lpfc_sli_prep_dev_for_reset(phba);
10824 return PCI_ERS_RESULT_NEED_RESET;
10825 case pci_channel_io_perm_failure:
10826 /* Permanent failure, prepare for device down */
10827 lpfc_sli_prep_dev_for_perm_failure(phba);
10828 return PCI_ERS_RESULT_DISCONNECT;
10830 /* Unknown state, prepare and request slot reset */
10831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10832 "0472 Unknown PCI error state: x%x\n", state);
10833 lpfc_sli_prep_dev_for_reset(phba);
10834 return PCI_ERS_RESULT_NEED_RESET;
10839 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
10840 * @pdev: pointer to PCI device.
10842 * This routine is called from the PCI subsystem for error handling to
10843 * device with SLI-3 interface spec. This is called after PCI bus has been
10844 * reset to restart the PCI card from scratch, as if from a cold-boot.
10845 * During the PCI subsystem error recovery, after driver returns
10846 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10847 * recovery and then call this routine before calling the .resume method
10848 * to recover the device. This function will initialize the HBA device,
10849 * enable the interrupt, but it will just put the HBA to offline state
10850 * without passing any I/O traffic.
10853 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10854 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10856 static pci_ers_result_t
10857 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
10859 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10860 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10861 struct lpfc_sli *psli = &phba->sli;
10862 uint32_t intr_mode;
10864 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10865 if (pci_enable_device_mem(pdev)) {
10866 printk(KERN_ERR "lpfc: Cannot re-enable "
10867 "PCI device after reset.\n");
10868 return PCI_ERS_RESULT_DISCONNECT;
10871 pci_restore_state(pdev);
10874 * As the new kernel behavior of pci_restore_state() API call clears
10875 * device saved_state flag, need to save the restored state again.
10877 pci_save_state(pdev);
10879 if (pdev->is_busmaster)
10880 pci_set_master(pdev);
10882 spin_lock_irq(&phba->hbalock);
10883 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10884 spin_unlock_irq(&phba->hbalock);
10886 /* Configure and enable interrupt */
10887 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
10888 if (intr_mode == LPFC_INTR_ERROR) {
10889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10890 "0427 Cannot re-enable interrupt after "
10892 return PCI_ERS_RESULT_DISCONNECT;
10894 phba->intr_mode = intr_mode;
10896 /* Take device offline, it will perform cleanup */
10897 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10898 lpfc_offline(phba);
10899 lpfc_sli_brdrestart(phba);
10901 /* Log the current active interrupt mode */
10902 lpfc_log_intr_mode(phba, phba->intr_mode);
10904 return PCI_ERS_RESULT_RECOVERED;
10908 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
10909 * @pdev: pointer to PCI device
10911 * This routine is called from the PCI subsystem for error handling to device
10912 * with SLI-3 interface spec. It is called when kernel error recovery tells
10913 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10914 * error recovery. After this call, traffic can start to flow from this device
10918 lpfc_io_resume_s3(struct pci_dev *pdev)
10920 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10921 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10923 /* Bring device online, it will be no-op for non-fatal error resume */
10926 /* Clean up Advanced Error Reporting (AER) if needed */
10927 if (phba->hba_flag & HBA_AER_ENABLED)
10928 pci_cleanup_aer_uncorrect_error_status(pdev);
10932 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10933 * @phba: pointer to lpfc hba data structure.
10935 * returns the number of ELS/CT IOCBs to reserve
10938 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10940 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10942 if (phba->sli_rev == LPFC_SLI_REV4) {
10943 if (max_xri <= 100)
10945 else if (max_xri <= 256)
10947 else if (max_xri <= 512)
10949 else if (max_xri <= 1024)
10951 else if (max_xri <= 1536)
10953 else if (max_xri <= 2048)
10962 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10963 * @phba: pointer to lpfc hba data structure.
10965 * returns the number of ELS/CT + NVMET IOCBs to reserve
10968 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10970 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10972 if (phba->nvmet_support)
10973 max_xri += LPFC_NVMET_BUF_POST;
10979 * lpfc_write_firmware - attempt to write a firmware image to the port
10980 * @fw: pointer to firmware image returned from request_firmware.
10981 * @phba: pointer to lpfc hba data structure.
10985 lpfc_write_firmware(const struct firmware *fw, void *context)
10987 struct lpfc_hba *phba = (struct lpfc_hba *)context;
10988 char fwrev[FW_REV_STR_SIZE];
10989 struct lpfc_grp_hdr *image;
10990 struct list_head dma_buffer_list;
10992 struct lpfc_dmabuf *dmabuf, *next;
10993 uint32_t offset = 0, temp_offset = 0;
10994 uint32_t magic_number, ftype, fid, fsize;
10996 /* It can be null in no-wait mode, sanity check */
11001 image = (struct lpfc_grp_hdr *)fw->data;
11003 magic_number = be32_to_cpu(image->magic_number);
11004 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
11005 fid = bf_get_be32(lpfc_grp_hdr_id, image),
11006 fsize = be32_to_cpu(image->size);
11008 INIT_LIST_HEAD(&dma_buffer_list);
11009 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
11010 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
11011 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
11012 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11013 "3022 Invalid FW image found. "
11014 "Magic:%x Type:%x ID:%x Size %d %zd\n",
11015 magic_number, ftype, fid, fsize, fw->size);
11019 lpfc_decode_firmware_rev(phba, fwrev, 1);
11020 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
11021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11022 "3023 Updating Firmware, Current Version:%s "
11023 "New Version:%s\n",
11024 fwrev, image->revision);
11025 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11026 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11032 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11036 if (!dmabuf->virt) {
11041 list_add_tail(&dmabuf->list, &dma_buffer_list);
11043 while (offset < fw->size) {
11044 temp_offset = offset;
11045 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
11046 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
11047 memcpy(dmabuf->virt,
11048 fw->data + temp_offset,
11049 fw->size - temp_offset);
11050 temp_offset = fw->size;
11053 memcpy(dmabuf->virt, fw->data + temp_offset,
11055 temp_offset += SLI4_PAGE_SIZE;
11057 rc = lpfc_wr_object(phba, &dma_buffer_list,
11058 (fw->size - offset), &offset);
11066 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11067 list_del(&dmabuf->list);
11068 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11069 dmabuf->virt, dmabuf->phys);
11072 release_firmware(fw);
11074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11075 "3024 Firmware update done: %d.\n", rc);
11080 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11081 * @phba: pointer to lpfc hba data structure.
11083 * This routine is called to perform Linux generic firmware upgrade on device
11084 * that supports such feature.
11087 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11089 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11091 const struct firmware *fw;
11093 /* Only supported on SLI4 interface type 2 for now */
11094 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
11095 LPFC_SLI_INTF_IF_TYPE_2)
11098 snprintf(file_name, ELX_MODEL_NAME_SIZE, "/*(DEBLOBBED)*/", phba->ModelName);
11100 if (fw_upgrade == INT_FW_UPGRADE) {
11101 ret = reject_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11102 file_name, &phba->pcidev->dev,
11103 GFP_KERNEL, (void *)phba,
11104 lpfc_write_firmware);
11105 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11106 ret = reject_firmware(&fw, file_name, &phba->pcidev->dev);
11108 lpfc_write_firmware(fw, (void *)phba);
11117 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11118 * @pdev: pointer to PCI device
11119 * @pid: pointer to PCI device identifier
11121 * This routine is called from the kernel's PCI subsystem to device with
11122 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11123 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11124 * information of the device and driver to see if the driver state that it
11125 * can support this kind of device. If the match is successful, the driver
11126 * core invokes this routine. If this routine determines it can claim the HBA,
11127 * it does all the initialization that it needs to do to handle the HBA
11131 * 0 - driver can claim the device
11132 * negative value - driver can not claim the device
11135 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11137 struct lpfc_hba *phba;
11138 struct lpfc_vport *vport = NULL;
11139 struct Scsi_Host *shost = NULL;
11141 uint32_t cfg_mode, intr_mode;
11143 /* Allocate memory for HBA structure */
11144 phba = lpfc_hba_alloc(pdev);
11148 /* Perform generic PCI device enabling operation */
11149 error = lpfc_enable_pci_dev(phba);
11151 goto out_free_phba;
11153 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11154 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11156 goto out_disable_pci_dev;
11158 /* Set up SLI-4 specific device PCI memory space */
11159 error = lpfc_sli4_pci_mem_setup(phba);
11161 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11162 "1410 Failed to set up pci memory space.\n");
11163 goto out_disable_pci_dev;
11166 /* Set up SLI-4 Specific device driver resources */
11167 error = lpfc_sli4_driver_resource_setup(phba);
11169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11170 "1412 Failed to set up driver resource.\n");
11171 goto out_unset_pci_mem_s4;
11174 INIT_LIST_HEAD(&phba->active_rrq_list);
11175 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
11177 /* Set up common device driver resources */
11178 error = lpfc_setup_driver_resource_phase2(phba);
11180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11181 "1414 Failed to set up driver resource.\n");
11182 goto out_unset_driver_resource_s4;
11185 /* Get the default values for Model Name and Description */
11186 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11188 /* Create SCSI host to the physical port */
11189 error = lpfc_create_shost(phba);
11191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11192 "1415 Failed to create scsi host.\n");
11193 goto out_unset_driver_resource;
11196 /* Configure sysfs attributes */
11197 vport = phba->pport;
11198 error = lpfc_alloc_sysfs_attr(vport);
11200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11201 "1416 Failed to allocate sysfs attr\n");
11202 goto out_destroy_shost;
11205 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
11206 /* Now, trying to enable interrupt and bring up the device */
11207 cfg_mode = phba->cfg_use_msi;
11209 /* Put device to a known state before enabling interrupt */
11210 lpfc_stop_port(phba);
11212 /* Configure and enable interrupt */
11213 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11214 if (intr_mode == LPFC_INTR_ERROR) {
11215 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11216 "0426 Failed to enable interrupt.\n");
11218 goto out_free_sysfs_attr;
11220 /* Default to single EQ for non-MSI-X */
11221 if (phba->intr_type != MSIX) {
11222 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11223 phba->cfg_fcp_io_channel = 1;
11224 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11225 phba->cfg_nvme_io_channel = 1;
11226 if (phba->nvmet_support)
11227 phba->cfg_nvmet_mrq = 1;
11229 phba->io_channel_irqs = 1;
11232 /* Set up SLI-4 HBA */
11233 if (lpfc_sli4_hba_setup(phba)) {
11234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11235 "1421 Failed to set up hba\n");
11237 goto out_disable_intr;
11240 /* Log the current active interrupt mode */
11241 phba->intr_mode = intr_mode;
11242 lpfc_log_intr_mode(phba, intr_mode);
11244 /* Perform post initialization setup */
11245 lpfc_post_init_setup(phba);
11247 /* NVME support in FW earlier in the driver load corrects the
11248 * FC4 type making a check for nvme_support unnecessary.
11250 if ((phba->nvmet_support == 0) &&
11251 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11252 /* Create NVME binding with nvme_fc_transport. This
11253 * ensures the vport is initialized. If the localport
11254 * create fails, it should not unload the driver to
11255 * support field issues.
11257 error = lpfc_nvme_create_localport(vport);
11259 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11260 "6004 NVME registration failed, "
11266 /* check for firmware upgrade or downgrade */
11267 if (phba->cfg_request_firmware_upgrade)
11268 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
11270 /* Check if there are static vports to be created. */
11271 lpfc_create_static_vport(phba);
11275 lpfc_sli4_disable_intr(phba);
11276 out_free_sysfs_attr:
11277 lpfc_free_sysfs_attr(vport);
11279 lpfc_destroy_shost(phba);
11280 out_unset_driver_resource:
11281 lpfc_unset_driver_resource_phase2(phba);
11282 out_unset_driver_resource_s4:
11283 lpfc_sli4_driver_resource_unset(phba);
11284 out_unset_pci_mem_s4:
11285 lpfc_sli4_pci_mem_unset(phba);
11286 out_disable_pci_dev:
11287 lpfc_disable_pci_dev(phba);
11289 scsi_host_put(shost);
11291 lpfc_hba_free(phba);
11296 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11297 * @pdev: pointer to PCI device
11299 * This routine is called from the kernel's PCI subsystem to device with
11300 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11301 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11302 * device to be removed from the PCI subsystem properly.
11305 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11307 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11309 struct lpfc_vport **vports;
11310 struct lpfc_hba *phba = vport->phba;
11313 /* Mark the device unloading flag */
11314 spin_lock_irq(&phba->hbalock);
11315 vport->load_flag |= FC_UNLOADING;
11316 spin_unlock_irq(&phba->hbalock);
11318 /* Free the HBA sysfs attributes */
11319 lpfc_free_sysfs_attr(vport);
11321 /* Release all the vports against this physical port */
11322 vports = lpfc_create_vport_work_array(phba);
11323 if (vports != NULL)
11324 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11325 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11327 fc_vport_terminate(vports[i]->fc_vport);
11329 lpfc_destroy_vport_work_array(phba, vports);
11331 /* Remove FC host and then SCSI host with the physical port */
11332 fc_remove_host(shost);
11333 scsi_remove_host(shost);
11335 * Bring down the SLI Layer. This step disables all interrupts,
11336 * clears the rings, discards all mailbox commands, and resets
11337 * the HBA FCoE function.
11339 lpfc_debugfs_terminate(vport);
11340 lpfc_sli4_hba_unset(phba);
11342 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11343 * localports are destroyed after to cleanup all transport memory.
11345 lpfc_cleanup(vport);
11346 lpfc_nvmet_destroy_targetport(phba);
11347 lpfc_nvme_destroy_localport(vport);
11350 lpfc_stop_hba_timers(phba);
11351 spin_lock_irq(&phba->hbalock);
11352 list_del_init(&vport->listentry);
11353 spin_unlock_irq(&phba->hbalock);
11355 /* Perform scsi free before driver resource_unset since scsi
11356 * buffers are released to their corresponding pools here.
11358 lpfc_scsi_free(phba);
11359 lpfc_nvme_free(phba);
11360 lpfc_free_iocb_list(phba);
11362 lpfc_sli4_driver_resource_unset(phba);
11364 /* Unmap adapter Control and Doorbell registers */
11365 lpfc_sli4_pci_mem_unset(phba);
11367 /* Release PCI resources and disable device's PCI function */
11368 scsi_host_put(shost);
11369 lpfc_disable_pci_dev(phba);
11371 /* Finally, free the driver's device data structure */
11372 lpfc_hba_free(phba);
11378 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11379 * @pdev: pointer to PCI device
11380 * @msg: power management message
11382 * This routine is called from the kernel's PCI subsystem to support system
11383 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11384 * this method, it quiesces the device by stopping the driver's worker
11385 * thread for the device, turning off device's interrupt and DMA, and bring
11386 * the device offline. Note that as the driver implements the minimum PM
11387 * requirements to a power-aware driver's PM support for suspend/resume -- all
11388 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11389 * method call will be treated as SUSPEND and the driver will fully
11390 * reinitialize its device during resume() method call, the driver will set
11391 * device to PCI_D3hot state in PCI config space instead of setting it
11392 * according to the @msg provided by the PM.
11395 * 0 - driver suspended the device
11399 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11401 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11402 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11404 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11405 "2843 PCI device Power Management suspend.\n");
11407 /* Bring down the device */
11408 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11409 lpfc_offline(phba);
11410 kthread_stop(phba->worker_thread);
11412 /* Disable interrupt from device */
11413 lpfc_sli4_disable_intr(phba);
11414 lpfc_sli4_queue_destroy(phba);
11416 /* Save device state to PCI config space */
11417 pci_save_state(pdev);
11418 pci_set_power_state(pdev, PCI_D3hot);
11424 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11425 * @pdev: pointer to PCI device
11427 * This routine is called from the kernel's PCI subsystem to support system
11428 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11429 * this method, it restores the device's PCI config space state and fully
11430 * reinitializes the device and brings it online. Note that as the driver
11431 * implements the minimum PM requirements to a power-aware driver's PM for
11432 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11433 * to the suspend() method call will be treated as SUSPEND and the driver
11434 * will fully reinitialize its device during resume() method call, the device
11435 * will be set to PCI_D0 directly in PCI config space before restoring the
11439 * 0 - driver suspended the device
11443 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11445 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11446 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11447 uint32_t intr_mode;
11450 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11451 "0292 PCI device Power Management resume.\n");
11453 /* Restore device state from PCI config space */
11454 pci_set_power_state(pdev, PCI_D0);
11455 pci_restore_state(pdev);
11458 * As the new kernel behavior of pci_restore_state() API call clears
11459 * device saved_state flag, need to save the restored state again.
11461 pci_save_state(pdev);
11463 if (pdev->is_busmaster)
11464 pci_set_master(pdev);
11466 /* Startup the kernel thread for this host adapter. */
11467 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11468 "lpfc_worker_%d", phba->brd_no);
11469 if (IS_ERR(phba->worker_thread)) {
11470 error = PTR_ERR(phba->worker_thread);
11471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11472 "0293 PM resume failed to start worker "
11473 "thread: error=x%x.\n", error);
11477 /* Configure and enable interrupt */
11478 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11479 if (intr_mode == LPFC_INTR_ERROR) {
11480 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11481 "0294 PM resume Failed to enable interrupt\n");
11484 phba->intr_mode = intr_mode;
11486 /* Restart HBA and bring it online */
11487 lpfc_sli_brdrestart(phba);
11490 /* Log the current active interrupt mode */
11491 lpfc_log_intr_mode(phba, phba->intr_mode);
11497 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11498 * @phba: pointer to lpfc hba data structure.
11500 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11501 * aborts all the outstanding SCSI I/Os to the pci device.
11504 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11507 "2828 PCI channel I/O abort preparing for recovery\n");
11509 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11510 * and let the SCSI mid-layer to retry them to recover.
11512 lpfc_sli_abort_fcp_rings(phba);
11516 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11517 * @phba: pointer to lpfc hba data structure.
11519 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11520 * disables the device interrupt and pci device, and aborts the internal FCP
11524 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11527 "2826 PCI channel disable preparing for reset\n");
11529 /* Block any management I/Os to the device */
11530 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
11532 /* Block all SCSI devices' I/Os on the host */
11533 lpfc_scsi_dev_block(phba);
11535 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11536 lpfc_sli_flush_fcp_rings(phba);
11538 /* stop all timers */
11539 lpfc_stop_hba_timers(phba);
11541 /* Disable interrupt and pci device */
11542 lpfc_sli4_disable_intr(phba);
11543 lpfc_sli4_queue_destroy(phba);
11544 pci_disable_device(phba->pcidev);
11548 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11549 * @phba: pointer to lpfc hba data structure.
11551 * This routine is called to prepare the SLI4 device for PCI slot permanently
11552 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11556 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11558 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11559 "2827 PCI channel permanent disable for failure\n");
11561 /* Block all SCSI devices' I/Os on the host */
11562 lpfc_scsi_dev_block(phba);
11564 /* stop all timers */
11565 lpfc_stop_hba_timers(phba);
11567 /* Clean up all driver's outstanding SCSI I/Os */
11568 lpfc_sli_flush_fcp_rings(phba);
11572 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11573 * @pdev: pointer to PCI device.
11574 * @state: the current PCI connection state.
11576 * This routine is called from the PCI subsystem for error handling to device
11577 * with SLI-4 interface spec. This function is called by the PCI subsystem
11578 * after a PCI bus error affecting this device has been detected. When this
11579 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11580 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11581 * for the PCI subsystem to perform proper recovery as desired.
11584 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11585 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11587 static pci_ers_result_t
11588 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11590 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11591 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11594 case pci_channel_io_normal:
11595 /* Non-fatal error, prepare for recovery */
11596 lpfc_sli4_prep_dev_for_recover(phba);
11597 return PCI_ERS_RESULT_CAN_RECOVER;
11598 case pci_channel_io_frozen:
11599 /* Fatal error, prepare for slot reset */
11600 lpfc_sli4_prep_dev_for_reset(phba);
11601 return PCI_ERS_RESULT_NEED_RESET;
11602 case pci_channel_io_perm_failure:
11603 /* Permanent failure, prepare for device down */
11604 lpfc_sli4_prep_dev_for_perm_failure(phba);
11605 return PCI_ERS_RESULT_DISCONNECT;
11607 /* Unknown state, prepare and request slot reset */
11608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11609 "2825 Unknown PCI error state: x%x\n", state);
11610 lpfc_sli4_prep_dev_for_reset(phba);
11611 return PCI_ERS_RESULT_NEED_RESET;
11616 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11617 * @pdev: pointer to PCI device.
11619 * This routine is called from the PCI subsystem for error handling to device
11620 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11621 * restart the PCI card from scratch, as if from a cold-boot. During the
11622 * PCI subsystem error recovery, after the driver returns
11623 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11624 * recovery and then call this routine before calling the .resume method to
11625 * recover the device. This function will initialize the HBA device, enable
11626 * the interrupt, but it will just put the HBA to offline state without
11627 * passing any I/O traffic.
11630 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11631 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11633 static pci_ers_result_t
11634 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11636 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11637 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11638 struct lpfc_sli *psli = &phba->sli;
11639 uint32_t intr_mode;
11641 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11642 if (pci_enable_device_mem(pdev)) {
11643 printk(KERN_ERR "lpfc: Cannot re-enable "
11644 "PCI device after reset.\n");
11645 return PCI_ERS_RESULT_DISCONNECT;
11648 pci_restore_state(pdev);
11651 * As the new kernel behavior of pci_restore_state() API call clears
11652 * device saved_state flag, need to save the restored state again.
11654 pci_save_state(pdev);
11656 if (pdev->is_busmaster)
11657 pci_set_master(pdev);
11659 spin_lock_irq(&phba->hbalock);
11660 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11661 spin_unlock_irq(&phba->hbalock);
11663 /* Configure and enable interrupt */
11664 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11665 if (intr_mode == LPFC_INTR_ERROR) {
11666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11667 "2824 Cannot re-enable interrupt after "
11669 return PCI_ERS_RESULT_DISCONNECT;
11671 phba->intr_mode = intr_mode;
11673 /* Log the current active interrupt mode */
11674 lpfc_log_intr_mode(phba, phba->intr_mode);
11676 return PCI_ERS_RESULT_RECOVERED;
11680 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11681 * @pdev: pointer to PCI device
11683 * This routine is called from the PCI subsystem for error handling to device
11684 * with SLI-4 interface spec. It is called when kernel error recovery tells
11685 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11686 * error recovery. After this call, traffic can start to flow from this device
11690 lpfc_io_resume_s4(struct pci_dev *pdev)
11692 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11693 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11696 * In case of slot reset, as function reset is performed through
11697 * mailbox command which needs DMA to be enabled, this operation
11698 * has to be moved to the io resume phase. Taking device offline
11699 * will perform the necessary cleanup.
11701 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11702 /* Perform device reset */
11703 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11704 lpfc_offline(phba);
11705 lpfc_sli_brdrestart(phba);
11706 /* Bring the device back online */
11710 /* Clean up Advanced Error Reporting (AER) if needed */
11711 if (phba->hba_flag & HBA_AER_ENABLED)
11712 pci_cleanup_aer_uncorrect_error_status(pdev);
11716 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11717 * @pdev: pointer to PCI device
11718 * @pid: pointer to PCI device identifier
11720 * This routine is to be registered to the kernel's PCI subsystem. When an
11721 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11722 * at PCI device-specific information of the device and driver to see if the
11723 * driver state that it can support this kind of device. If the match is
11724 * successful, the driver core invokes this routine. This routine dispatches
11725 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11726 * do all the initialization that it needs to do to handle the HBA device
11730 * 0 - driver can claim the device
11731 * negative value - driver can not claim the device
11734 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11737 struct lpfc_sli_intf intf;
11739 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
11742 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
11743 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
11744 rc = lpfc_pci_probe_one_s4(pdev, pid);
11746 rc = lpfc_pci_probe_one_s3(pdev, pid);
11752 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11753 * @pdev: pointer to PCI device
11755 * This routine is to be registered to the kernel's PCI subsystem. When an
11756 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11757 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11758 * remove routine, which will perform all the necessary cleanup for the
11759 * device to be removed from the PCI subsystem properly.
11762 lpfc_pci_remove_one(struct pci_dev *pdev)
11764 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11765 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11767 switch (phba->pci_dev_grp) {
11768 case LPFC_PCI_DEV_LP:
11769 lpfc_pci_remove_one_s3(pdev);
11771 case LPFC_PCI_DEV_OC:
11772 lpfc_pci_remove_one_s4(pdev);
11775 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11776 "1424 Invalid PCI device group: 0x%x\n",
11777 phba->pci_dev_grp);
11784 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11785 * @pdev: pointer to PCI device
11786 * @msg: power management message
11788 * This routine is to be registered to the kernel's PCI subsystem to support
11789 * system Power Management (PM). When PM invokes this method, it dispatches
11790 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11791 * suspend the device.
11794 * 0 - driver suspended the device
11798 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11800 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11801 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11804 switch (phba->pci_dev_grp) {
11805 case LPFC_PCI_DEV_LP:
11806 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11808 case LPFC_PCI_DEV_OC:
11809 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11813 "1425 Invalid PCI device group: 0x%x\n",
11814 phba->pci_dev_grp);
11821 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11822 * @pdev: pointer to PCI device
11824 * This routine is to be registered to the kernel's PCI subsystem to support
11825 * system Power Management (PM). When PM invokes this method, it dispatches
11826 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11827 * resume the device.
11830 * 0 - driver suspended the device
11834 lpfc_pci_resume_one(struct pci_dev *pdev)
11836 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11837 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11840 switch (phba->pci_dev_grp) {
11841 case LPFC_PCI_DEV_LP:
11842 rc = lpfc_pci_resume_one_s3(pdev);
11844 case LPFC_PCI_DEV_OC:
11845 rc = lpfc_pci_resume_one_s4(pdev);
11848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11849 "1426 Invalid PCI device group: 0x%x\n",
11850 phba->pci_dev_grp);
11857 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11858 * @pdev: pointer to PCI device.
11859 * @state: the current PCI connection state.
11861 * This routine is registered to the PCI subsystem for error handling. This
11862 * function is called by the PCI subsystem after a PCI bus error affecting
11863 * this device has been detected. When this routine is invoked, it dispatches
11864 * the action to the proper SLI-3 or SLI-4 device error detected handling
11865 * routine, which will perform the proper error detected operation.
11868 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11869 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11871 static pci_ers_result_t
11872 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11874 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11875 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11876 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11878 switch (phba->pci_dev_grp) {
11879 case LPFC_PCI_DEV_LP:
11880 rc = lpfc_io_error_detected_s3(pdev, state);
11882 case LPFC_PCI_DEV_OC:
11883 rc = lpfc_io_error_detected_s4(pdev, state);
11886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11887 "1427 Invalid PCI device group: 0x%x\n",
11888 phba->pci_dev_grp);
11895 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11896 * @pdev: pointer to PCI device.
11898 * This routine is registered to the PCI subsystem for error handling. This
11899 * function is called after PCI bus has been reset to restart the PCI card
11900 * from scratch, as if from a cold-boot. When this routine is invoked, it
11901 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11902 * routine, which will perform the proper device reset.
11905 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11906 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11908 static pci_ers_result_t
11909 lpfc_io_slot_reset(struct pci_dev *pdev)
11911 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11912 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11913 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11915 switch (phba->pci_dev_grp) {
11916 case LPFC_PCI_DEV_LP:
11917 rc = lpfc_io_slot_reset_s3(pdev);
11919 case LPFC_PCI_DEV_OC:
11920 rc = lpfc_io_slot_reset_s4(pdev);
11923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11924 "1428 Invalid PCI device group: 0x%x\n",
11925 phba->pci_dev_grp);
11932 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11933 * @pdev: pointer to PCI device
11935 * This routine is registered to the PCI subsystem for error handling. It
11936 * is called when kernel error recovery tells the lpfc driver that it is
11937 * OK to resume normal PCI operation after PCI bus error recovery. When
11938 * this routine is invoked, it dispatches the action to the proper SLI-3
11939 * or SLI-4 device io_resume routine, which will resume the device operation.
11942 lpfc_io_resume(struct pci_dev *pdev)
11944 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11945 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11947 switch (phba->pci_dev_grp) {
11948 case LPFC_PCI_DEV_LP:
11949 lpfc_io_resume_s3(pdev);
11951 case LPFC_PCI_DEV_OC:
11952 lpfc_io_resume_s4(pdev);
11955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11956 "1429 Invalid PCI device group: 0x%x\n",
11957 phba->pci_dev_grp);
11964 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11965 * @phba: pointer to lpfc hba data structure.
11967 * This routine checks to see if OAS is supported for this adapter. If
11968 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11969 * the enable oas flag is cleared and the pool created for OAS device data
11974 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11977 if (!phba->cfg_EnableXLane)
11980 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11984 if (phba->device_data_mem_pool)
11985 mempool_destroy(phba->device_data_mem_pool);
11986 phba->device_data_mem_pool = NULL;
11993 * lpfc_fof_queue_setup - Set up all the fof queues
11994 * @phba: pointer to lpfc hba data structure.
11996 * This routine is invoked to set up all the fof queues for the FC HBA
12001 * -ENOMEM - No available memory
12004 lpfc_fof_queue_setup(struct lpfc_hba *phba)
12006 struct lpfc_sli_ring *pring;
12009 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12013 if (phba->cfg_fof) {
12015 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12016 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12020 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12021 phba->sli4_hba.oas_cq, LPFC_FCP);
12025 /* Bind this CQ/WQ to the NVME ring */
12026 pring = phba->sli4_hba.oas_wq->pring;
12027 pring->sli.sli4.wqp =
12028 (void *)phba->sli4_hba.oas_wq;
12029 phba->sli4_hba.oas_cq->pring = pring;
12035 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
12037 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12043 * lpfc_fof_queue_create - Create all the fof queues
12044 * @phba: pointer to lpfc hba data structure.
12046 * This routine is invoked to allocate all the fof queues for the FC HBA
12047 * operation. For each SLI4 queue type, the parameters such as queue entry
12048 * count (queue depth) shall be taken from the module parameter. For now,
12049 * we just use some constant number as place holder.
12053 * -ENOMEM - No availble memory
12054 * -EIO - The mailbox failed to complete successfully.
12057 lpfc_fof_queue_create(struct lpfc_hba *phba)
12059 struct lpfc_queue *qdesc;
12062 /* Create FOF EQ */
12063 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
12064 phba->sli4_hba.eq_ecount);
12068 phba->sli4_hba.fof_eq = qdesc;
12070 if (phba->cfg_fof) {
12072 /* Create OAS CQ */
12073 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
12074 phba->sli4_hba.cq_ecount);
12078 phba->sli4_hba.oas_cq = qdesc;
12080 /* Create OAS WQ */
12081 wqesize = (phba->fcp_embed_io) ?
12082 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
12083 qdesc = lpfc_sli4_queue_alloc(phba, wqesize,
12084 phba->sli4_hba.wq_ecount);
12089 phba->sli4_hba.oas_wq = qdesc;
12090 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
12096 lpfc_fof_queue_destroy(phba);
12101 * lpfc_fof_queue_destroy - Destroy all the fof queues
12102 * @phba: pointer to lpfc hba data structure.
12104 * This routine is invoked to release all the SLI4 queues with the FC HBA
12111 lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12113 /* Release FOF Event queue */
12114 if (phba->sli4_hba.fof_eq != NULL) {
12115 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12116 phba->sli4_hba.fof_eq = NULL;
12119 /* Release OAS Completion queue */
12120 if (phba->sli4_hba.oas_cq != NULL) {
12121 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12122 phba->sli4_hba.oas_cq = NULL;
12125 /* Release OAS Work queue */
12126 if (phba->sli4_hba.oas_wq != NULL) {
12127 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12128 phba->sli4_hba.oas_wq = NULL;
12133 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12135 static const struct pci_error_handlers lpfc_err_handler = {
12136 .error_detected = lpfc_io_error_detected,
12137 .slot_reset = lpfc_io_slot_reset,
12138 .resume = lpfc_io_resume,
12141 static struct pci_driver lpfc_driver = {
12142 .name = LPFC_DRIVER_NAME,
12143 .id_table = lpfc_id_table,
12144 .probe = lpfc_pci_probe_one,
12145 .remove = lpfc_pci_remove_one,
12146 .shutdown = lpfc_pci_remove_one,
12147 .suspend = lpfc_pci_suspend_one,
12148 .resume = lpfc_pci_resume_one,
12149 .err_handler = &lpfc_err_handler,
12152 static const struct file_operations lpfc_mgmt_fop = {
12153 .owner = THIS_MODULE,
12156 static struct miscdevice lpfc_mgmt_dev = {
12157 .minor = MISC_DYNAMIC_MINOR,
12158 .name = "lpfcmgmt",
12159 .fops = &lpfc_mgmt_fop,
12163 * lpfc_init - lpfc module initialization routine
12165 * This routine is to be invoked when the lpfc module is loaded into the
12166 * kernel. The special kernel macro module_init() is used to indicate the
12167 * role of this routine to the kernel as lpfc module entry point.
12171 * -ENOMEM - FC attach transport failed
12172 * all others - failed
12179 printk(LPFC_MODULE_DESC "\n");
12180 printk(LPFC_COPYRIGHT "\n");
12182 error = misc_register(&lpfc_mgmt_dev);
12184 printk(KERN_ERR "Could not register lpfcmgmt device, "
12185 "misc_register returned with status %d", error);
12187 lpfc_transport_functions.vport_create = lpfc_vport_create;
12188 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
12189 lpfc_transport_template =
12190 fc_attach_transport(&lpfc_transport_functions);
12191 if (lpfc_transport_template == NULL)
12193 lpfc_vport_transport_template =
12194 fc_attach_transport(&lpfc_vport_transport_functions);
12195 if (lpfc_vport_transport_template == NULL) {
12196 fc_release_transport(lpfc_transport_template);
12200 /* Initialize in case vector mapping is needed */
12201 lpfc_used_cpu = NULL;
12202 lpfc_present_cpu = num_present_cpus();
12204 error = pci_register_driver(&lpfc_driver);
12206 fc_release_transport(lpfc_transport_template);
12207 fc_release_transport(lpfc_vport_transport_template);
12214 * lpfc_exit - lpfc module removal routine
12216 * This routine is invoked when the lpfc module is removed from the kernel.
12217 * The special kernel macro module_exit() is used to indicate the role of
12218 * this routine to the kernel as lpfc module exit point.
12223 misc_deregister(&lpfc_mgmt_dev);
12224 pci_unregister_driver(&lpfc_driver);
12225 fc_release_transport(lpfc_transport_template);
12226 fc_release_transport(lpfc_vport_transport_template);
12227 if (_dump_buf_data) {
12228 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12229 "_dump_buf_data at 0x%p\n",
12230 (1L << _dump_buf_data_order), _dump_buf_data);
12231 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12234 if (_dump_buf_dif) {
12235 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12236 "_dump_buf_dif at 0x%p\n",
12237 (1L << _dump_buf_dif_order), _dump_buf_dif);
12238 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12240 kfree(lpfc_used_cpu);
12241 idr_destroy(&lpfc_hba_index);
12244 module_init(lpfc_init);
12245 module_exit(lpfc_exit);
12246 MODULE_LICENSE("GPL");
12247 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
12248 MODULE_AUTHOR("Broadcom");
12249 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);