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>
41 #include <scsi/scsi.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
44 #include <scsi/scsi_transport_fc.h>
49 #include "lpfc_sli4.h"
51 #include "lpfc_disc.h"
53 #include "lpfc_scsi.h"
54 #include "lpfc_nvme.h"
55 #include "lpfc_logmsg.h"
56 #include "lpfc_crtn.h"
57 #include "lpfc_vport.h"
58 #include "lpfc_version.h"
62 unsigned long _dump_buf_data_order;
64 unsigned long _dump_buf_dif_order;
65 spinlock_t _dump_buf_lock;
67 /* Used when mapping IRQ vectors in a driver centric manner */
68 uint16_t *lpfc_used_cpu;
69 uint32_t lpfc_present_cpu;
71 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
72 static int lpfc_post_rcv_buf(struct lpfc_hba *);
73 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
74 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
75 static int lpfc_setup_endian_order(struct lpfc_hba *);
76 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
77 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
78 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
79 static void lpfc_init_sgl_list(struct lpfc_hba *);
80 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
81 static void lpfc_free_active_sgl(struct lpfc_hba *);
82 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
83 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
84 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
85 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
86 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
87 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
88 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
89 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
91 static struct scsi_transport_template *lpfc_transport_template = NULL;
92 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
93 static DEFINE_IDR(lpfc_hba_index);
94 #define LPFC_NVMET_BUF_POST 254
97 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
98 * @phba: pointer to lpfc hba data structure.
100 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
101 * mailbox command. It retrieves the revision information from the HBA and
102 * collects the Vital Product Data (VPD) about the HBA for preparing the
103 * configuration of the HBA.
107 * -ERESTART - requests the SLI layer to reset the HBA and try again.
108 * Any other value - indicates an error.
111 lpfc_config_port_prep(struct lpfc_hba *phba)
113 lpfc_vpd_t *vp = &phba->vpd;
117 char *lpfc_vpd_data = NULL;
119 static char licensed[56] =
120 "key unlock for use with gnu public licensed code only\0";
121 static int init_key = 1;
123 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
125 phba->link_state = LPFC_HBA_ERROR;
130 phba->link_state = LPFC_INIT_MBX_CMDS;
132 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
134 uint32_t *ptext = (uint32_t *) licensed;
136 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
137 *ptext = cpu_to_be32(*ptext);
141 lpfc_read_nv(phba, pmb);
142 memset((char*)mb->un.varRDnvp.rsvd3, 0,
143 sizeof (mb->un.varRDnvp.rsvd3));
144 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
147 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
149 if (rc != MBX_SUCCESS) {
150 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
151 "0324 Config Port initialization "
152 "error, mbxCmd x%x READ_NVPARM, "
154 mb->mbxCommand, mb->mbxStatus);
155 mempool_free(pmb, phba->mbox_mem_pool);
158 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
160 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
164 phba->sli3_options = 0x0;
166 /* Setup and issue mailbox READ REV command */
167 lpfc_read_rev(phba, pmb);
168 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
169 if (rc != MBX_SUCCESS) {
170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
171 "0439 Adapter failed to init, mbxCmd x%x "
172 "READ_REV, mbxStatus x%x\n",
173 mb->mbxCommand, mb->mbxStatus);
174 mempool_free( pmb, phba->mbox_mem_pool);
180 * The value of rr must be 1 since the driver set the cv field to 1.
181 * This setting requires the FW to set all revision fields.
183 if (mb->un.varRdRev.rr == 0) {
185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
186 "0440 Adapter failed to init, READ_REV has "
187 "missing revision information.\n");
188 mempool_free(pmb, phba->mbox_mem_pool);
192 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
193 mempool_free(pmb, phba->mbox_mem_pool);
197 /* Save information as VPD data */
199 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
200 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
201 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
202 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
203 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
204 vp->rev.biuRev = mb->un.varRdRev.biuRev;
205 vp->rev.smRev = mb->un.varRdRev.smRev;
206 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
207 vp->rev.endecRev = mb->un.varRdRev.endecRev;
208 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
209 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
210 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
211 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
212 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
213 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
215 /* If the sli feature level is less then 9, we must
216 * tear down all RPIs and VPIs on link down if NPIV
219 if (vp->rev.feaLevelHigh < 9)
220 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
222 if (lpfc_is_LC_HBA(phba->pcidev->device))
223 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
224 sizeof (phba->RandomData));
226 /* Get adapter VPD information */
227 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
231 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
232 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
234 if (rc != MBX_SUCCESS) {
235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
236 "0441 VPD not present on adapter, "
237 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
238 mb->mbxCommand, mb->mbxStatus);
239 mb->un.varDmp.word_cnt = 0;
241 /* dump mem may return a zero when finished or we got a
242 * mailbox error, either way we are done.
244 if (mb->un.varDmp.word_cnt == 0)
246 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
247 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
248 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
249 lpfc_vpd_data + offset,
250 mb->un.varDmp.word_cnt);
251 offset += mb->un.varDmp.word_cnt;
252 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
253 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
255 kfree(lpfc_vpd_data);
257 mempool_free(pmb, phba->mbox_mem_pool);
262 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
263 * @phba: pointer to lpfc hba data structure.
264 * @pmboxq: pointer to the driver internal queue element for mailbox command.
266 * This is the completion handler for driver's configuring asynchronous event
267 * mailbox command to the device. If the mailbox command returns successfully,
268 * it will set internal async event support flag to 1; otherwise, it will
269 * set internal async event support flag to 0.
272 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
274 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
275 phba->temp_sensor_support = 1;
277 phba->temp_sensor_support = 0;
278 mempool_free(pmboxq, phba->mbox_mem_pool);
283 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
284 * @phba: pointer to lpfc hba data structure.
285 * @pmboxq: pointer to the driver internal queue element for mailbox command.
287 * This is the completion handler for dump mailbox command for getting
288 * wake up parameters. When this command complete, the response contain
289 * Option rom version of the HBA. This function translate the version number
290 * into a human readable string and store it in OptionROMVersion.
293 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
296 uint32_t prog_id_word;
298 /* character array used for decoding dist type. */
299 char dist_char[] = "nabx";
301 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
302 mempool_free(pmboxq, phba->mbox_mem_pool);
306 prg = (struct prog_id *) &prog_id_word;
308 /* word 7 contain option rom version */
309 prog_id_word = pmboxq->u.mb.un.varWords[7];
311 /* Decode the Option rom version word to a readable string */
313 dist = dist_char[prg->dist];
315 if ((prg->dist == 3) && (prg->num == 0))
316 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
317 prg->ver, prg->rev, prg->lev);
319 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
320 prg->ver, prg->rev, prg->lev,
322 mempool_free(pmboxq, phba->mbox_mem_pool);
327 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
328 * cfg_soft_wwnn, cfg_soft_wwpn
329 * @vport: pointer to lpfc vport data structure.
336 lpfc_update_vport_wwn(struct lpfc_vport *vport)
338 /* If the soft name exists then update it using the service params */
339 if (vport->phba->cfg_soft_wwnn)
340 u64_to_wwn(vport->phba->cfg_soft_wwnn,
341 vport->fc_sparam.nodeName.u.wwn);
342 if (vport->phba->cfg_soft_wwpn)
343 u64_to_wwn(vport->phba->cfg_soft_wwpn,
344 vport->fc_sparam.portName.u.wwn);
347 * If the name is empty or there exists a soft name
348 * then copy the service params name, otherwise use the fc name
350 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
351 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
352 sizeof(struct lpfc_name));
354 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
355 sizeof(struct lpfc_name));
357 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
358 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
359 sizeof(struct lpfc_name));
361 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
362 sizeof(struct lpfc_name));
366 * lpfc_config_port_post - Perform lpfc initialization after config port
367 * @phba: pointer to lpfc hba data structure.
369 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
370 * command call. It performs all internal resource and state setups on the
371 * port: post IOCB buffers, enable appropriate host interrupt attentions,
372 * ELS ring timers, etc.
376 * Any other value - error.
379 lpfc_config_port_post(struct lpfc_hba *phba)
381 struct lpfc_vport *vport = phba->pport;
382 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
385 struct lpfc_dmabuf *mp;
386 struct lpfc_sli *psli = &phba->sli;
387 uint32_t status, timeout;
391 spin_lock_irq(&phba->hbalock);
393 * If the Config port completed correctly the HBA is not
394 * over heated any more.
396 if (phba->over_temp_state == HBA_OVER_TEMP)
397 phba->over_temp_state = HBA_NORMAL_TEMP;
398 spin_unlock_irq(&phba->hbalock);
400 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
402 phba->link_state = LPFC_HBA_ERROR;
407 /* Get login parameters for NID. */
408 rc = lpfc_read_sparam(phba, pmb, 0);
410 mempool_free(pmb, phba->mbox_mem_pool);
415 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
417 "0448 Adapter failed init, mbxCmd x%x "
418 "READ_SPARM mbxStatus x%x\n",
419 mb->mbxCommand, mb->mbxStatus);
420 phba->link_state = LPFC_HBA_ERROR;
421 mp = (struct lpfc_dmabuf *) pmb->context1;
422 mempool_free(pmb, phba->mbox_mem_pool);
423 lpfc_mbuf_free(phba, mp->virt, mp->phys);
428 mp = (struct lpfc_dmabuf *) pmb->context1;
430 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
433 pmb->context1 = NULL;
434 lpfc_update_vport_wwn(vport);
436 /* Update the fc_host data structures with new wwn. */
437 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
438 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
439 fc_host_max_npiv_vports(shost) = phba->max_vpi;
441 /* If no serial number in VPD data, use low 6 bytes of WWNN */
442 /* This should be consolidated into parse_vpd ? - mr */
443 if (phba->SerialNumber[0] == 0) {
446 outptr = &vport->fc_nodename.u.s.IEEE[0];
447 for (i = 0; i < 12; i++) {
449 j = ((status & 0xf0) >> 4);
451 phba->SerialNumber[i] =
452 (char)((uint8_t) 0x30 + (uint8_t) j);
454 phba->SerialNumber[i] =
455 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
459 phba->SerialNumber[i] =
460 (char)((uint8_t) 0x30 + (uint8_t) j);
462 phba->SerialNumber[i] =
463 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
467 lpfc_read_config(phba, pmb);
469 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
470 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
471 "0453 Adapter failed to init, mbxCmd x%x "
472 "READ_CONFIG, mbxStatus x%x\n",
473 mb->mbxCommand, mb->mbxStatus);
474 phba->link_state = LPFC_HBA_ERROR;
475 mempool_free( pmb, phba->mbox_mem_pool);
479 /* Check if the port is disabled */
480 lpfc_sli_read_link_ste(phba);
482 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
483 i = (mb->un.varRdConfig.max_xri + 1);
484 if (phba->cfg_hba_queue_depth > i) {
485 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
486 "3359 HBA queue depth changed from %d to %d\n",
487 phba->cfg_hba_queue_depth, i);
488 phba->cfg_hba_queue_depth = i;
491 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
492 i = (mb->un.varRdConfig.max_xri >> 3);
493 if (phba->pport->cfg_lun_queue_depth > i) {
494 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
495 "3360 LUN queue depth changed from %d to %d\n",
496 phba->pport->cfg_lun_queue_depth, i);
497 phba->pport->cfg_lun_queue_depth = i;
500 phba->lmt = mb->un.varRdConfig.lmt;
502 /* Get the default values for Model Name and Description */
503 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
505 phba->link_state = LPFC_LINK_DOWN;
507 /* Only process IOCBs on ELS ring till hba_state is READY */
508 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
509 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
510 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
511 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
513 /* Post receive buffers for desired rings */
514 if (phba->sli_rev != 3)
515 lpfc_post_rcv_buf(phba);
518 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
520 if (phba->intr_type == MSIX) {
521 rc = lpfc_config_msi(phba, pmb);
523 mempool_free(pmb, phba->mbox_mem_pool);
526 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
527 if (rc != MBX_SUCCESS) {
528 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
529 "0352 Config MSI mailbox command "
530 "failed, mbxCmd x%x, mbxStatus x%x\n",
531 pmb->u.mb.mbxCommand,
532 pmb->u.mb.mbxStatus);
533 mempool_free(pmb, phba->mbox_mem_pool);
538 spin_lock_irq(&phba->hbalock);
539 /* Initialize ERATT handling flag */
540 phba->hba_flag &= ~HBA_ERATT_HANDLED;
542 /* Enable appropriate host interrupts */
543 if (lpfc_readl(phba->HCregaddr, &status)) {
544 spin_unlock_irq(&phba->hbalock);
547 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
548 if (psli->num_rings > 0)
549 status |= HC_R0INT_ENA;
550 if (psli->num_rings > 1)
551 status |= HC_R1INT_ENA;
552 if (psli->num_rings > 2)
553 status |= HC_R2INT_ENA;
554 if (psli->num_rings > 3)
555 status |= HC_R3INT_ENA;
557 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
558 (phba->cfg_poll & DISABLE_FCP_RING_INT))
559 status &= ~(HC_R0INT_ENA);
561 writel(status, phba->HCregaddr);
562 readl(phba->HCregaddr); /* flush */
563 spin_unlock_irq(&phba->hbalock);
565 /* Set up ring-0 (ELS) timer */
566 timeout = phba->fc_ratov * 2;
567 mod_timer(&vport->els_tmofunc,
568 jiffies + msecs_to_jiffies(1000 * timeout));
569 /* Set up heart beat (HB) timer */
570 mod_timer(&phba->hb_tmofunc,
571 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
572 phba->hb_outstanding = 0;
573 phba->last_completion_time = jiffies;
574 /* Set up error attention (ERATT) polling timer */
575 mod_timer(&phba->eratt_poll,
576 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
578 if (phba->hba_flag & LINK_DISABLED) {
579 lpfc_printf_log(phba,
581 "2598 Adapter Link is disabled.\n");
582 lpfc_down_link(phba, pmb);
583 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
584 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
585 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
586 lpfc_printf_log(phba,
588 "2599 Adapter failed to issue DOWN_LINK"
589 " mbox command rc 0x%x\n", rc);
591 mempool_free(pmb, phba->mbox_mem_pool);
594 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
595 mempool_free(pmb, phba->mbox_mem_pool);
596 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
600 /* MBOX buffer will be freed in mbox compl */
601 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
603 phba->link_state = LPFC_HBA_ERROR;
607 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
608 pmb->mbox_cmpl = lpfc_config_async_cmpl;
609 pmb->vport = phba->pport;
610 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
612 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
613 lpfc_printf_log(phba,
616 "0456 Adapter failed to issue "
617 "ASYNCEVT_ENABLE mbox status x%x\n",
619 mempool_free(pmb, phba->mbox_mem_pool);
622 /* Get Option rom version */
623 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
625 phba->link_state = LPFC_HBA_ERROR;
629 lpfc_dump_wakeup_param(phba, pmb);
630 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
631 pmb->vport = phba->pport;
632 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
634 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
636 "to get Option ROM version status x%x\n", rc);
637 mempool_free(pmb, phba->mbox_mem_pool);
644 * lpfc_hba_init_link - Initialize the FC link
645 * @phba: pointer to lpfc hba data structure.
646 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
648 * This routine will issue the INIT_LINK mailbox command call.
649 * It is available to other drivers through the lpfc_hba data
650 * structure for use as a delayed link up mechanism with the
651 * module parameter lpfc_suppress_link_up.
655 * Any other value - error
658 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
660 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
664 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
665 * @phba: pointer to lpfc hba data structure.
666 * @fc_topology: desired fc topology.
667 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
669 * This routine will issue the INIT_LINK mailbox command call.
670 * It is available to other drivers through the lpfc_hba data
671 * structure for use as a delayed link up mechanism with the
672 * module parameter lpfc_suppress_link_up.
676 * Any other value - error
679 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
682 struct lpfc_vport *vport = phba->pport;
687 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
689 phba->link_state = LPFC_HBA_ERROR;
695 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
696 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
697 !(phba->lmt & LMT_1Gb)) ||
698 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
699 !(phba->lmt & LMT_2Gb)) ||
700 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
701 !(phba->lmt & LMT_4Gb)) ||
702 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
703 !(phba->lmt & LMT_8Gb)) ||
704 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
705 !(phba->lmt & LMT_10Gb)) ||
706 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
707 !(phba->lmt & LMT_16Gb)) ||
708 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
709 !(phba->lmt & LMT_32Gb))) {
710 /* Reset link speed to auto */
711 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
712 "1302 Invalid speed for this board:%d "
713 "Reset link speed to auto.\n",
714 phba->cfg_link_speed);
715 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
717 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
718 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
719 if (phba->sli_rev < LPFC_SLI_REV4)
720 lpfc_set_loopback_flag(phba);
721 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
722 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
724 "0498 Adapter failed to init, mbxCmd x%x "
725 "INIT_LINK, mbxStatus x%x\n",
726 mb->mbxCommand, mb->mbxStatus);
727 if (phba->sli_rev <= LPFC_SLI_REV3) {
728 /* Clear all interrupt enable conditions */
729 writel(0, phba->HCregaddr);
730 readl(phba->HCregaddr); /* flush */
731 /* Clear all pending interrupts */
732 writel(0xffffffff, phba->HAregaddr);
733 readl(phba->HAregaddr); /* flush */
735 phba->link_state = LPFC_HBA_ERROR;
736 if (rc != MBX_BUSY || flag == MBX_POLL)
737 mempool_free(pmb, phba->mbox_mem_pool);
740 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
741 if (flag == MBX_POLL)
742 mempool_free(pmb, phba->mbox_mem_pool);
748 * lpfc_hba_down_link - this routine downs the FC link
749 * @phba: pointer to lpfc hba data structure.
750 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
752 * This routine will issue the DOWN_LINK mailbox command call.
753 * It is available to other drivers through the lpfc_hba data
754 * structure for use to stop the link.
758 * Any other value - error
761 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
766 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
768 phba->link_state = LPFC_HBA_ERROR;
772 lpfc_printf_log(phba,
774 "0491 Adapter Link is disabled.\n");
775 lpfc_down_link(phba, pmb);
776 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
777 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
778 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
779 lpfc_printf_log(phba,
781 "2522 Adapter failed to issue DOWN_LINK"
782 " mbox command rc 0x%x\n", rc);
784 mempool_free(pmb, phba->mbox_mem_pool);
787 if (flag == MBX_POLL)
788 mempool_free(pmb, phba->mbox_mem_pool);
794 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
795 * @phba: pointer to lpfc HBA data structure.
797 * This routine will do LPFC uninitialization before the HBA is reset when
798 * bringing down the SLI Layer.
802 * Any other value - error.
805 lpfc_hba_down_prep(struct lpfc_hba *phba)
807 struct lpfc_vport **vports;
810 if (phba->sli_rev <= LPFC_SLI_REV3) {
811 /* Disable interrupts */
812 writel(0, phba->HCregaddr);
813 readl(phba->HCregaddr); /* flush */
816 if (phba->pport->load_flag & FC_UNLOADING)
817 lpfc_cleanup_discovery_resources(phba->pport);
819 vports = lpfc_create_vport_work_array(phba);
821 for (i = 0; i <= phba->max_vports &&
822 vports[i] != NULL; i++)
823 lpfc_cleanup_discovery_resources(vports[i]);
824 lpfc_destroy_vport_work_array(phba, vports);
830 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
831 * rspiocb which got deferred
833 * @phba: pointer to lpfc HBA data structure.
835 * This routine will cleanup completed slow path events after HBA is reset
836 * when bringing down the SLI Layer.
843 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
845 struct lpfc_iocbq *rspiocbq;
846 struct hbq_dmabuf *dmabuf;
847 struct lpfc_cq_event *cq_event;
849 spin_lock_irq(&phba->hbalock);
850 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
851 spin_unlock_irq(&phba->hbalock);
853 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
854 /* Get the response iocb from the head of work queue */
855 spin_lock_irq(&phba->hbalock);
856 list_remove_head(&phba->sli4_hba.sp_queue_event,
857 cq_event, struct lpfc_cq_event, list);
858 spin_unlock_irq(&phba->hbalock);
860 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
861 case CQE_CODE_COMPL_WQE:
862 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
864 lpfc_sli_release_iocbq(phba, rspiocbq);
866 case CQE_CODE_RECEIVE:
867 case CQE_CODE_RECEIVE_V1:
868 dmabuf = container_of(cq_event, struct hbq_dmabuf,
870 lpfc_in_buf_free(phba, &dmabuf->dbuf);
876 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
877 * @phba: pointer to lpfc HBA data structure.
879 * This routine will cleanup posted ELS buffers after the HBA is reset
880 * when bringing down the SLI Layer.
887 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
889 struct lpfc_sli *psli = &phba->sli;
890 struct lpfc_sli_ring *pring;
891 struct lpfc_dmabuf *mp, *next_mp;
895 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
896 lpfc_sli_hbqbuf_free_all(phba);
898 /* Cleanup preposted buffers on the ELS ring */
899 pring = &psli->sli3_ring[LPFC_ELS_RING];
900 spin_lock_irq(&phba->hbalock);
901 list_splice_init(&pring->postbufq, &buflist);
902 spin_unlock_irq(&phba->hbalock);
905 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
908 lpfc_mbuf_free(phba, mp->virt, mp->phys);
912 spin_lock_irq(&phba->hbalock);
913 pring->postbufq_cnt -= count;
914 spin_unlock_irq(&phba->hbalock);
919 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
920 * @phba: pointer to lpfc HBA data structure.
922 * This routine will cleanup the txcmplq after the HBA is reset when bringing
923 * down the SLI Layer.
929 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
931 struct lpfc_sli *psli = &phba->sli;
932 struct lpfc_queue *qp = NULL;
933 struct lpfc_sli_ring *pring;
934 LIST_HEAD(completions);
937 if (phba->sli_rev != LPFC_SLI_REV4) {
938 for (i = 0; i < psli->num_rings; i++) {
939 pring = &psli->sli3_ring[i];
940 spin_lock_irq(&phba->hbalock);
941 /* At this point in time the HBA is either reset or DOA
942 * Nothing should be on txcmplq as it will
945 list_splice_init(&pring->txcmplq, &completions);
946 pring->txcmplq_cnt = 0;
947 spin_unlock_irq(&phba->hbalock);
949 lpfc_sli_abort_iocb_ring(phba, pring);
951 /* Cancel all the IOCBs from the completions list */
952 lpfc_sli_cancel_iocbs(phba, &completions,
953 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
956 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
960 spin_lock_irq(&pring->ring_lock);
961 list_splice_init(&pring->txcmplq, &completions);
962 pring->txcmplq_cnt = 0;
963 spin_unlock_irq(&pring->ring_lock);
964 lpfc_sli_abort_iocb_ring(phba, pring);
966 /* Cancel all the IOCBs from the completions list */
967 lpfc_sli_cancel_iocbs(phba, &completions,
968 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
972 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
974 * @phba: pointer to lpfc HBA data structure.
976 * This routine will do uninitialization after the HBA is reset when bring
977 * down the SLI Layer.
981 * Any other value - error.
984 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
986 lpfc_hba_free_post_buf(phba);
987 lpfc_hba_clean_txcmplq(phba);
992 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
993 * @phba: pointer to lpfc HBA data structure.
995 * This routine will do uninitialization after the HBA is reset when bring
996 * down the SLI Layer.
1000 * Any other value - error.
1003 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1005 struct lpfc_scsi_buf *psb, *psb_next;
1007 LIST_HEAD(nvme_aborts);
1008 unsigned long iflag = 0;
1009 struct lpfc_sglq *sglq_entry = NULL;
1012 lpfc_sli_hbqbuf_free_all(phba);
1013 lpfc_hba_clean_txcmplq(phba);
1015 /* At this point in time the HBA is either reset or DOA. Either
1016 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1017 * on the lpfc_els_sgl_list so that it can either be freed if the
1018 * driver is unloading or reposted if the driver is restarting
1021 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
1023 /* sgl_list_lock required because worker thread uses this
1026 spin_lock(&phba->sli4_hba.sgl_list_lock);
1027 list_for_each_entry(sglq_entry,
1028 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1029 sglq_entry->state = SGL_FREED;
1030 list_for_each_entry(sglq_entry,
1031 &phba->sli4_hba.lpfc_abts_nvmet_sgl_list, list)
1032 sglq_entry->state = SGL_FREED;
1034 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1035 &phba->sli4_hba.lpfc_els_sgl_list);
1037 if (phba->sli4_hba.nvme_wq)
1038 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list,
1039 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1041 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1042 /* abts_scsi_buf_list_lock required because worker thread uses this
1045 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1046 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1047 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1049 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1052 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1053 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1054 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1056 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1059 spin_unlock_irq(&phba->hbalock);
1061 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1063 psb->status = IOSTAT_SUCCESS;
1065 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1066 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1067 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1069 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1071 psb->status = IOSTAT_SUCCESS;
1073 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1074 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1075 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1077 lpfc_sli4_free_sp_events(phba);
1082 * lpfc_hba_down_post - Wrapper func for hba down post routine
1083 * @phba: pointer to lpfc HBA data structure.
1085 * This routine wraps the actual SLI3 or SLI4 routine for performing
1086 * uninitialization after the HBA is reset when bring down the SLI Layer.
1090 * Any other value - error.
1093 lpfc_hba_down_post(struct lpfc_hba *phba)
1095 return (*phba->lpfc_hba_down_post)(phba);
1099 * lpfc_hb_timeout - The HBA-timer timeout handler
1100 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1102 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1103 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1104 * work-port-events bitmap and the worker thread is notified. This timeout
1105 * event will be used by the worker thread to invoke the actual timeout
1106 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1107 * be performed in the timeout handler and the HBA timeout event bit shall
1108 * be cleared by the worker thread after it has taken the event bitmap out.
1111 lpfc_hb_timeout(unsigned long ptr)
1113 struct lpfc_hba *phba;
1114 uint32_t tmo_posted;
1115 unsigned long iflag;
1117 phba = (struct lpfc_hba *)ptr;
1119 /* Check for heart beat timeout conditions */
1120 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1121 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1123 phba->pport->work_port_events |= WORKER_HB_TMO;
1124 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1126 /* Tell the worker thread there is work to do */
1128 lpfc_worker_wake_up(phba);
1133 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1134 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1136 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1137 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1138 * work-port-events bitmap and the worker thread is notified. This timeout
1139 * event will be used by the worker thread to invoke the actual timeout
1140 * handler routine, lpfc_rrq_handler. Any periodical operations will
1141 * be performed in the timeout handler and the RRQ timeout event bit shall
1142 * be cleared by the worker thread after it has taken the event bitmap out.
1145 lpfc_rrq_timeout(unsigned long ptr)
1147 struct lpfc_hba *phba;
1148 unsigned long iflag;
1150 phba = (struct lpfc_hba *)ptr;
1151 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1152 if (!(phba->pport->load_flag & FC_UNLOADING))
1153 phba->hba_flag |= HBA_RRQ_ACTIVE;
1155 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1156 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1158 if (!(phba->pport->load_flag & FC_UNLOADING))
1159 lpfc_worker_wake_up(phba);
1163 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1164 * @phba: pointer to lpfc hba data structure.
1165 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1167 * This is the callback function to the lpfc heart-beat mailbox command.
1168 * If configured, the lpfc driver issues the heart-beat mailbox command to
1169 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1170 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1171 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1172 * heart-beat outstanding state. Once the mailbox command comes back and
1173 * no error conditions detected, the heart-beat mailbox command timer is
1174 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1175 * state is cleared for the next heart-beat. If the timer expired with the
1176 * heart-beat outstanding state set, the driver will put the HBA offline.
1179 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1181 unsigned long drvr_flag;
1183 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1184 phba->hb_outstanding = 0;
1185 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1187 /* Check and reset heart-beat timer is necessary */
1188 mempool_free(pmboxq, phba->mbox_mem_pool);
1189 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1190 !(phba->link_state == LPFC_HBA_ERROR) &&
1191 !(phba->pport->load_flag & FC_UNLOADING))
1192 mod_timer(&phba->hb_tmofunc,
1194 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1199 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1200 * @phba: pointer to lpfc hba data structure.
1202 * This is the actual HBA-timer timeout handler to be invoked by the worker
1203 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1204 * handler performs any periodic operations needed for the device. If such
1205 * periodic event has already been attended to either in the interrupt handler
1206 * or by processing slow-ring or fast-ring events within the HBA-timer
1207 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1208 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1209 * is configured and there is no heart-beat mailbox command outstanding, a
1210 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1211 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1215 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1217 struct lpfc_vport **vports;
1218 LPFC_MBOXQ_t *pmboxq;
1219 struct lpfc_dmabuf *buf_ptr;
1221 struct lpfc_sli *psli = &phba->sli;
1222 LIST_HEAD(completions);
1224 vports = lpfc_create_vport_work_array(phba);
1226 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1227 lpfc_rcv_seq_check_edtov(vports[i]);
1228 lpfc_fdmi_num_disc_check(vports[i]);
1230 lpfc_destroy_vport_work_array(phba, vports);
1232 if ((phba->link_state == LPFC_HBA_ERROR) ||
1233 (phba->pport->load_flag & FC_UNLOADING) ||
1234 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1237 spin_lock_irq(&phba->pport->work_port_lock);
1239 if (time_after(phba->last_completion_time +
1240 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1242 spin_unlock_irq(&phba->pport->work_port_lock);
1243 if (!phba->hb_outstanding)
1244 mod_timer(&phba->hb_tmofunc,
1246 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1248 mod_timer(&phba->hb_tmofunc,
1250 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1253 spin_unlock_irq(&phba->pport->work_port_lock);
1255 if (phba->elsbuf_cnt &&
1256 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1257 spin_lock_irq(&phba->hbalock);
1258 list_splice_init(&phba->elsbuf, &completions);
1259 phba->elsbuf_cnt = 0;
1260 phba->elsbuf_prev_cnt = 0;
1261 spin_unlock_irq(&phba->hbalock);
1263 while (!list_empty(&completions)) {
1264 list_remove_head(&completions, buf_ptr,
1265 struct lpfc_dmabuf, list);
1266 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1270 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1272 /* If there is no heart beat outstanding, issue a heartbeat command */
1273 if (phba->cfg_enable_hba_heartbeat) {
1274 if (!phba->hb_outstanding) {
1275 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1276 (list_empty(&psli->mboxq))) {
1277 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1280 mod_timer(&phba->hb_tmofunc,
1282 msecs_to_jiffies(1000 *
1283 LPFC_HB_MBOX_INTERVAL));
1287 lpfc_heart_beat(phba, pmboxq);
1288 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1289 pmboxq->vport = phba->pport;
1290 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1293 if (retval != MBX_BUSY &&
1294 retval != MBX_SUCCESS) {
1295 mempool_free(pmboxq,
1296 phba->mbox_mem_pool);
1297 mod_timer(&phba->hb_tmofunc,
1299 msecs_to_jiffies(1000 *
1300 LPFC_HB_MBOX_INTERVAL));
1303 phba->skipped_hb = 0;
1304 phba->hb_outstanding = 1;
1305 } else if (time_before_eq(phba->last_completion_time,
1306 phba->skipped_hb)) {
1307 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1308 "2857 Last completion time not "
1309 " updated in %d ms\n",
1310 jiffies_to_msecs(jiffies
1311 - phba->last_completion_time));
1313 phba->skipped_hb = jiffies;
1315 mod_timer(&phba->hb_tmofunc,
1317 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1321 * If heart beat timeout called with hb_outstanding set
1322 * we need to give the hb mailbox cmd a chance to
1325 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1326 "0459 Adapter heartbeat still out"
1327 "standing:last compl time was %d ms.\n",
1328 jiffies_to_msecs(jiffies
1329 - phba->last_completion_time));
1330 mod_timer(&phba->hb_tmofunc,
1332 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1335 mod_timer(&phba->hb_tmofunc,
1337 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1342 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1343 * @phba: pointer to lpfc hba data structure.
1345 * This routine is called to bring the HBA offline when HBA hardware error
1346 * other than Port Error 6 has been detected.
1349 lpfc_offline_eratt(struct lpfc_hba *phba)
1351 struct lpfc_sli *psli = &phba->sli;
1353 spin_lock_irq(&phba->hbalock);
1354 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1355 spin_unlock_irq(&phba->hbalock);
1356 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1359 lpfc_reset_barrier(phba);
1360 spin_lock_irq(&phba->hbalock);
1361 lpfc_sli_brdreset(phba);
1362 spin_unlock_irq(&phba->hbalock);
1363 lpfc_hba_down_post(phba);
1364 lpfc_sli_brdready(phba, HS_MBRDY);
1365 lpfc_unblock_mgmt_io(phba);
1366 phba->link_state = LPFC_HBA_ERROR;
1371 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1372 * @phba: pointer to lpfc hba data structure.
1374 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1375 * other than Port Error 6 has been detected.
1378 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1380 spin_lock_irq(&phba->hbalock);
1381 phba->link_state = LPFC_HBA_ERROR;
1382 spin_unlock_irq(&phba->hbalock);
1384 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1386 lpfc_hba_down_post(phba);
1387 lpfc_unblock_mgmt_io(phba);
1391 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1392 * @phba: pointer to lpfc hba data structure.
1394 * This routine is invoked to handle the deferred HBA hardware error
1395 * conditions. This type of error is indicated by HBA by setting ER1
1396 * and another ER bit in the host status register. The driver will
1397 * wait until the ER1 bit clears before handling the error condition.
1400 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1402 uint32_t old_host_status = phba->work_hs;
1403 struct lpfc_sli *psli = &phba->sli;
1405 /* If the pci channel is offline, ignore possible errors,
1406 * since we cannot communicate with the pci card anyway.
1408 if (pci_channel_offline(phba->pcidev)) {
1409 spin_lock_irq(&phba->hbalock);
1410 phba->hba_flag &= ~DEFER_ERATT;
1411 spin_unlock_irq(&phba->hbalock);
1415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1416 "0479 Deferred Adapter Hardware Error "
1417 "Data: x%x x%x x%x\n",
1419 phba->work_status[0], phba->work_status[1]);
1421 spin_lock_irq(&phba->hbalock);
1422 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1423 spin_unlock_irq(&phba->hbalock);
1427 * Firmware stops when it triggred erratt. That could cause the I/Os
1428 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1429 * SCSI layer retry it after re-establishing link.
1431 lpfc_sli_abort_fcp_rings(phba);
1434 * There was a firmware error. Take the hba offline and then
1435 * attempt to restart it.
1437 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1440 /* Wait for the ER1 bit to clear.*/
1441 while (phba->work_hs & HS_FFER1) {
1443 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1444 phba->work_hs = UNPLUG_ERR ;
1447 /* If driver is unloading let the worker thread continue */
1448 if (phba->pport->load_flag & FC_UNLOADING) {
1455 * This is to ptrotect against a race condition in which
1456 * first write to the host attention register clear the
1457 * host status register.
1459 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1460 phba->work_hs = old_host_status & ~HS_FFER1;
1462 spin_lock_irq(&phba->hbalock);
1463 phba->hba_flag &= ~DEFER_ERATT;
1464 spin_unlock_irq(&phba->hbalock);
1465 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1466 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1470 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1472 struct lpfc_board_event_header board_event;
1473 struct Scsi_Host *shost;
1475 board_event.event_type = FC_REG_BOARD_EVENT;
1476 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1477 shost = lpfc_shost_from_vport(phba->pport);
1478 fc_host_post_vendor_event(shost, fc_get_event_number(),
1479 sizeof(board_event),
1480 (char *) &board_event,
1485 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1486 * @phba: pointer to lpfc hba data structure.
1488 * This routine is invoked to handle the following HBA hardware error
1490 * 1 - HBA error attention interrupt
1491 * 2 - DMA ring index out of range
1492 * 3 - Mailbox command came back as unknown
1495 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1497 struct lpfc_vport *vport = phba->pport;
1498 struct lpfc_sli *psli = &phba->sli;
1499 uint32_t event_data;
1500 unsigned long temperature;
1501 struct temp_event temp_event_data;
1502 struct Scsi_Host *shost;
1504 /* If the pci channel is offline, ignore possible errors,
1505 * since we cannot communicate with the pci card anyway.
1507 if (pci_channel_offline(phba->pcidev)) {
1508 spin_lock_irq(&phba->hbalock);
1509 phba->hba_flag &= ~DEFER_ERATT;
1510 spin_unlock_irq(&phba->hbalock);
1514 /* If resets are disabled then leave the HBA alone and return */
1515 if (!phba->cfg_enable_hba_reset)
1518 /* Send an internal error event to mgmt application */
1519 lpfc_board_errevt_to_mgmt(phba);
1521 if (phba->hba_flag & DEFER_ERATT)
1522 lpfc_handle_deferred_eratt(phba);
1524 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1525 if (phba->work_hs & HS_FFER6)
1526 /* Re-establishing Link */
1527 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1528 "1301 Re-establishing Link "
1529 "Data: x%x x%x x%x\n",
1530 phba->work_hs, phba->work_status[0],
1531 phba->work_status[1]);
1532 if (phba->work_hs & HS_FFER8)
1533 /* Device Zeroization */
1534 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1535 "2861 Host Authentication device "
1536 "zeroization Data:x%x x%x x%x\n",
1537 phba->work_hs, phba->work_status[0],
1538 phba->work_status[1]);
1540 spin_lock_irq(&phba->hbalock);
1541 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1542 spin_unlock_irq(&phba->hbalock);
1545 * Firmware stops when it triggled erratt with HS_FFER6.
1546 * That could cause the I/Os dropped by the firmware.
1547 * Error iocb (I/O) on txcmplq and let the SCSI layer
1548 * retry it after re-establishing link.
1550 lpfc_sli_abort_fcp_rings(phba);
1553 * There was a firmware error. Take the hba offline and then
1554 * attempt to restart it.
1556 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1558 lpfc_sli_brdrestart(phba);
1559 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1560 lpfc_unblock_mgmt_io(phba);
1563 lpfc_unblock_mgmt_io(phba);
1564 } else if (phba->work_hs & HS_CRIT_TEMP) {
1565 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1566 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1567 temp_event_data.event_code = LPFC_CRIT_TEMP;
1568 temp_event_data.data = (uint32_t)temperature;
1570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1571 "0406 Adapter maximum temperature exceeded "
1572 "(%ld), taking this port offline "
1573 "Data: x%x x%x x%x\n",
1574 temperature, phba->work_hs,
1575 phba->work_status[0], phba->work_status[1]);
1577 shost = lpfc_shost_from_vport(phba->pport);
1578 fc_host_post_vendor_event(shost, fc_get_event_number(),
1579 sizeof(temp_event_data),
1580 (char *) &temp_event_data,
1581 SCSI_NL_VID_TYPE_PCI
1582 | PCI_VENDOR_ID_EMULEX);
1584 spin_lock_irq(&phba->hbalock);
1585 phba->over_temp_state = HBA_OVER_TEMP;
1586 spin_unlock_irq(&phba->hbalock);
1587 lpfc_offline_eratt(phba);
1590 /* The if clause above forces this code path when the status
1591 * failure is a value other than FFER6. Do not call the offline
1592 * twice. This is the adapter hardware error path.
1594 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1595 "0457 Adapter Hardware Error "
1596 "Data: x%x x%x x%x\n",
1598 phba->work_status[0], phba->work_status[1]);
1600 event_data = FC_REG_DUMP_EVENT;
1601 shost = lpfc_shost_from_vport(vport);
1602 fc_host_post_vendor_event(shost, fc_get_event_number(),
1603 sizeof(event_data), (char *) &event_data,
1604 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1606 lpfc_offline_eratt(phba);
1612 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1613 * @phba: pointer to lpfc hba data structure.
1614 * @mbx_action: flag for mailbox shutdown action.
1616 * This routine is invoked to perform an SLI4 port PCI function reset in
1617 * response to port status register polling attention. It waits for port
1618 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1619 * During this process, interrupt vectors are freed and later requested
1620 * for handling possible port resource change.
1623 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1629 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1630 LPFC_SLI_INTF_IF_TYPE_2) {
1632 * On error status condition, driver need to wait for port
1633 * ready before performing reset.
1635 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1640 /* need reset: attempt for port recovery */
1642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1643 "2887 Reset Needed: Attempting Port "
1645 lpfc_offline_prep(phba, mbx_action);
1647 /* release interrupt for possible resource change */
1648 lpfc_sli4_disable_intr(phba);
1649 lpfc_sli_brdrestart(phba);
1650 /* request and enable interrupt */
1651 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1652 if (intr_mode == LPFC_INTR_ERROR) {
1653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1654 "3175 Failed to enable interrupt\n");
1657 phba->intr_mode = intr_mode;
1658 rc = lpfc_online(phba);
1660 lpfc_unblock_mgmt_io(phba);
1666 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1667 * @phba: pointer to lpfc hba data structure.
1669 * This routine is invoked to handle the SLI4 HBA hardware error attention
1673 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1675 struct lpfc_vport *vport = phba->pport;
1676 uint32_t event_data;
1677 struct Scsi_Host *shost;
1679 struct lpfc_register portstat_reg = {0};
1680 uint32_t reg_err1, reg_err2;
1681 uint32_t uerrlo_reg, uemasklo_reg;
1682 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
1683 bool en_rn_msg = true;
1684 struct temp_event temp_event_data;
1685 struct lpfc_register portsmphr_reg;
1688 /* If the pci channel is offline, ignore possible errors, since
1689 * we cannot communicate with the pci card anyway.
1691 if (pci_channel_offline(phba->pcidev))
1694 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
1695 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1697 case LPFC_SLI_INTF_IF_TYPE_0:
1698 pci_rd_rc1 = lpfc_readl(
1699 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1701 pci_rd_rc2 = lpfc_readl(
1702 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1704 /* consider PCI bus read error as pci_channel_offline */
1705 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1707 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1708 lpfc_sli4_offline_eratt(phba);
1711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1712 "7623 Checking UE recoverable");
1714 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1715 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1716 &portsmphr_reg.word0))
1719 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1721 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1722 LPFC_PORT_SEM_UE_RECOVERABLE)
1724 /*Sleep for 1Sec, before checking SEMAPHORE */
1728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1729 "4827 smphr_port_status x%x : Waited %dSec",
1730 smphr_port_status, i);
1732 /* Recoverable UE, reset the HBA device */
1733 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1734 LPFC_PORT_SEM_UE_RECOVERABLE) {
1735 for (i = 0; i < 20; i++) {
1737 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1738 &portsmphr_reg.word0) &&
1739 (LPFC_POST_STAGE_PORT_READY ==
1740 bf_get(lpfc_port_smphr_port_status,
1742 rc = lpfc_sli4_port_sta_fn_reset(phba,
1743 LPFC_MBX_NO_WAIT, en_rn_msg);
1746 lpfc_printf_log(phba,
1748 "4215 Failed to recover UE");
1753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1754 "7624 Firmware not ready: Failing UE recovery,"
1755 " waited %dSec", i);
1756 lpfc_sli4_offline_eratt(phba);
1759 case LPFC_SLI_INTF_IF_TYPE_2:
1760 pci_rd_rc1 = lpfc_readl(
1761 phba->sli4_hba.u.if_type2.STATUSregaddr,
1762 &portstat_reg.word0);
1763 /* consider PCI bus read error as pci_channel_offline */
1764 if (pci_rd_rc1 == -EIO) {
1765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1766 "3151 PCI bus read access failure: x%x\n",
1767 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1770 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1771 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1772 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1774 "2889 Port Overtemperature event, "
1775 "taking port offline Data: x%x x%x\n",
1776 reg_err1, reg_err2);
1778 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
1779 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1780 temp_event_data.event_code = LPFC_CRIT_TEMP;
1781 temp_event_data.data = 0xFFFFFFFF;
1783 shost = lpfc_shost_from_vport(phba->pport);
1784 fc_host_post_vendor_event(shost, fc_get_event_number(),
1785 sizeof(temp_event_data),
1786 (char *)&temp_event_data,
1787 SCSI_NL_VID_TYPE_PCI
1788 | PCI_VENDOR_ID_EMULEX);
1790 spin_lock_irq(&phba->hbalock);
1791 phba->over_temp_state = HBA_OVER_TEMP;
1792 spin_unlock_irq(&phba->hbalock);
1793 lpfc_sli4_offline_eratt(phba);
1796 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1797 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1798 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1799 "3143 Port Down: Firmware Update "
1802 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1803 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1805 "3144 Port Down: Debug Dump\n");
1806 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1807 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1809 "3145 Port Down: Provisioning\n");
1811 /* If resets are disabled then leave the HBA alone and return */
1812 if (!phba->cfg_enable_hba_reset)
1815 /* Check port status register for function reset */
1816 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1819 /* don't report event on forced debug dump */
1820 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1821 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1826 /* fall through for not able to recover */
1827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1828 "3152 Unrecoverable error, bring the port "
1830 lpfc_sli4_offline_eratt(phba);
1832 case LPFC_SLI_INTF_IF_TYPE_1:
1836 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1837 "3123 Report dump event to upper layer\n");
1838 /* Send an internal error event to mgmt application */
1839 lpfc_board_errevt_to_mgmt(phba);
1841 event_data = FC_REG_DUMP_EVENT;
1842 shost = lpfc_shost_from_vport(vport);
1843 fc_host_post_vendor_event(shost, fc_get_event_number(),
1844 sizeof(event_data), (char *) &event_data,
1845 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1849 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1850 * @phba: pointer to lpfc HBA data structure.
1852 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1853 * routine from the API jump table function pointer from the lpfc_hba struct.
1857 * Any other value - error.
1860 lpfc_handle_eratt(struct lpfc_hba *phba)
1862 (*phba->lpfc_handle_eratt)(phba);
1866 * lpfc_handle_latt - The HBA link event handler
1867 * @phba: pointer to lpfc hba data structure.
1869 * This routine is invoked from the worker thread to handle a HBA host
1870 * attention link event. SLI3 only.
1873 lpfc_handle_latt(struct lpfc_hba *phba)
1875 struct lpfc_vport *vport = phba->pport;
1876 struct lpfc_sli *psli = &phba->sli;
1878 volatile uint32_t control;
1879 struct lpfc_dmabuf *mp;
1882 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1885 goto lpfc_handle_latt_err_exit;
1888 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1891 goto lpfc_handle_latt_free_pmb;
1894 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1897 goto lpfc_handle_latt_free_mp;
1900 /* Cleanup any outstanding ELS commands */
1901 lpfc_els_flush_all_cmd(phba);
1903 psli->slistat.link_event++;
1904 lpfc_read_topology(phba, pmb, mp);
1905 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
1907 /* Block ELS IOCBs until we have processed this mbox command */
1908 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
1909 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
1910 if (rc == MBX_NOT_FINISHED) {
1912 goto lpfc_handle_latt_free_mbuf;
1915 /* Clear Link Attention in HA REG */
1916 spin_lock_irq(&phba->hbalock);
1917 writel(HA_LATT, phba->HAregaddr);
1918 readl(phba->HAregaddr); /* flush */
1919 spin_unlock_irq(&phba->hbalock);
1923 lpfc_handle_latt_free_mbuf:
1924 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1925 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1926 lpfc_handle_latt_free_mp:
1928 lpfc_handle_latt_free_pmb:
1929 mempool_free(pmb, phba->mbox_mem_pool);
1930 lpfc_handle_latt_err_exit:
1931 /* Enable Link attention interrupts */
1932 spin_lock_irq(&phba->hbalock);
1933 psli->sli_flag |= LPFC_PROCESS_LA;
1934 control = readl(phba->HCregaddr);
1935 control |= HC_LAINT_ENA;
1936 writel(control, phba->HCregaddr);
1937 readl(phba->HCregaddr); /* flush */
1939 /* Clear Link Attention in HA REG */
1940 writel(HA_LATT, phba->HAregaddr);
1941 readl(phba->HAregaddr); /* flush */
1942 spin_unlock_irq(&phba->hbalock);
1943 lpfc_linkdown(phba);
1944 phba->link_state = LPFC_HBA_ERROR;
1946 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1947 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
1953 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1954 * @phba: pointer to lpfc hba data structure.
1955 * @vpd: pointer to the vital product data.
1956 * @len: length of the vital product data in bytes.
1958 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1959 * an array of characters. In this routine, the ModelName, ProgramType, and
1960 * ModelDesc, etc. fields of the phba data structure will be populated.
1963 * 0 - pointer to the VPD passed in is NULL
1967 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
1969 uint8_t lenlo, lenhi;
1979 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1980 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1981 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1983 while (!finished && (index < (len - 4))) {
1984 switch (vpd[index]) {
1992 i = ((((unsigned short)lenhi) << 8) + lenlo);
2001 Length = ((((unsigned short)lenhi) << 8) + lenlo);
2002 if (Length > len - index)
2003 Length = len - index;
2004 while (Length > 0) {
2005 /* Look for Serial Number */
2006 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2013 phba->SerialNumber[j++] = vpd[index++];
2017 phba->SerialNumber[j] = 0;
2020 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2021 phba->vpd_flag |= VPD_MODEL_DESC;
2028 phba->ModelDesc[j++] = vpd[index++];
2032 phba->ModelDesc[j] = 0;
2035 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2036 phba->vpd_flag |= VPD_MODEL_NAME;
2043 phba->ModelName[j++] = vpd[index++];
2047 phba->ModelName[j] = 0;
2050 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2051 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2058 phba->ProgramType[j++] = vpd[index++];
2062 phba->ProgramType[j] = 0;
2065 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2066 phba->vpd_flag |= VPD_PORT;
2073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2074 (phba->sli4_hba.pport_name_sta ==
2075 LPFC_SLI4_PPNAME_GET)) {
2079 phba->Port[j++] = vpd[index++];
2083 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2084 (phba->sli4_hba.pport_name_sta ==
2085 LPFC_SLI4_PPNAME_NON))
2112 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2113 * @phba: pointer to lpfc hba data structure.
2114 * @mdp: pointer to the data structure to hold the derived model name.
2115 * @descp: pointer to the data structure to hold the derived description.
2117 * This routine retrieves HBA's description based on its registered PCI device
2118 * ID. The @descp passed into this function points to an array of 256 chars. It
2119 * shall be returned with the model name, maximum speed, and the host bus type.
2120 * The @mdp passed into this function points to an array of 80 chars. When the
2121 * function returns, the @mdp will be filled with the model name.
2124 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2127 uint16_t dev_id = phba->pcidev->device;
2130 int oneConnect = 0; /* default is not a oneConnect */
2135 } m = {"<Unknown>", "", ""};
2137 if (mdp && mdp[0] != '\0'
2138 && descp && descp[0] != '\0')
2141 if (phba->lmt & LMT_32Gb)
2143 else if (phba->lmt & LMT_16Gb)
2145 else if (phba->lmt & LMT_10Gb)
2147 else if (phba->lmt & LMT_8Gb)
2149 else if (phba->lmt & LMT_4Gb)
2151 else if (phba->lmt & LMT_2Gb)
2153 else if (phba->lmt & LMT_1Gb)
2161 case PCI_DEVICE_ID_FIREFLY:
2162 m = (typeof(m)){"LP6000", "PCI",
2163 "Obsolete, Unsupported Fibre Channel Adapter"};
2165 case PCI_DEVICE_ID_SUPERFLY:
2166 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2167 m = (typeof(m)){"LP7000", "PCI", ""};
2169 m = (typeof(m)){"LP7000E", "PCI", ""};
2170 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2172 case PCI_DEVICE_ID_DRAGONFLY:
2173 m = (typeof(m)){"LP8000", "PCI",
2174 "Obsolete, Unsupported Fibre Channel Adapter"};
2176 case PCI_DEVICE_ID_CENTAUR:
2177 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2178 m = (typeof(m)){"LP9002", "PCI", ""};
2180 m = (typeof(m)){"LP9000", "PCI", ""};
2181 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2183 case PCI_DEVICE_ID_RFLY:
2184 m = (typeof(m)){"LP952", "PCI",
2185 "Obsolete, Unsupported Fibre Channel Adapter"};
2187 case PCI_DEVICE_ID_PEGASUS:
2188 m = (typeof(m)){"LP9802", "PCI-X",
2189 "Obsolete, Unsupported Fibre Channel Adapter"};
2191 case PCI_DEVICE_ID_THOR:
2192 m = (typeof(m)){"LP10000", "PCI-X",
2193 "Obsolete, Unsupported Fibre Channel Adapter"};
2195 case PCI_DEVICE_ID_VIPER:
2196 m = (typeof(m)){"LPX1000", "PCI-X",
2197 "Obsolete, Unsupported Fibre Channel Adapter"};
2199 case PCI_DEVICE_ID_PFLY:
2200 m = (typeof(m)){"LP982", "PCI-X",
2201 "Obsolete, Unsupported Fibre Channel Adapter"};
2203 case PCI_DEVICE_ID_TFLY:
2204 m = (typeof(m)){"LP1050", "PCI-X",
2205 "Obsolete, Unsupported Fibre Channel Adapter"};
2207 case PCI_DEVICE_ID_HELIOS:
2208 m = (typeof(m)){"LP11000", "PCI-X2",
2209 "Obsolete, Unsupported Fibre Channel Adapter"};
2211 case PCI_DEVICE_ID_HELIOS_SCSP:
2212 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2213 "Obsolete, Unsupported Fibre Channel Adapter"};
2215 case PCI_DEVICE_ID_HELIOS_DCSP:
2216 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2217 "Obsolete, Unsupported Fibre Channel Adapter"};
2219 case PCI_DEVICE_ID_NEPTUNE:
2220 m = (typeof(m)){"LPe1000", "PCIe",
2221 "Obsolete, Unsupported Fibre Channel Adapter"};
2223 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2224 m = (typeof(m)){"LPe1000-SP", "PCIe",
2225 "Obsolete, Unsupported Fibre Channel Adapter"};
2227 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2228 m = (typeof(m)){"LPe1002-SP", "PCIe",
2229 "Obsolete, Unsupported Fibre Channel Adapter"};
2231 case PCI_DEVICE_ID_BMID:
2232 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2234 case PCI_DEVICE_ID_BSMB:
2235 m = (typeof(m)){"LP111", "PCI-X2",
2236 "Obsolete, Unsupported Fibre Channel Adapter"};
2238 case PCI_DEVICE_ID_ZEPHYR:
2239 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2241 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2242 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2244 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2245 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2248 case PCI_DEVICE_ID_ZMID:
2249 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2251 case PCI_DEVICE_ID_ZSMB:
2252 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2254 case PCI_DEVICE_ID_LP101:
2255 m = (typeof(m)){"LP101", "PCI-X",
2256 "Obsolete, Unsupported Fibre Channel Adapter"};
2258 case PCI_DEVICE_ID_LP10000S:
2259 m = (typeof(m)){"LP10000-S", "PCI",
2260 "Obsolete, Unsupported Fibre Channel Adapter"};
2262 case PCI_DEVICE_ID_LP11000S:
2263 m = (typeof(m)){"LP11000-S", "PCI-X2",
2264 "Obsolete, Unsupported Fibre Channel Adapter"};
2266 case PCI_DEVICE_ID_LPE11000S:
2267 m = (typeof(m)){"LPe11000-S", "PCIe",
2268 "Obsolete, Unsupported Fibre Channel Adapter"};
2270 case PCI_DEVICE_ID_SAT:
2271 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2273 case PCI_DEVICE_ID_SAT_MID:
2274 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2276 case PCI_DEVICE_ID_SAT_SMB:
2277 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2279 case PCI_DEVICE_ID_SAT_DCSP:
2280 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2282 case PCI_DEVICE_ID_SAT_SCSP:
2283 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2285 case PCI_DEVICE_ID_SAT_S:
2286 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2288 case PCI_DEVICE_ID_HORNET:
2289 m = (typeof(m)){"LP21000", "PCIe",
2290 "Obsolete, Unsupported FCoE Adapter"};
2293 case PCI_DEVICE_ID_PROTEUS_VF:
2294 m = (typeof(m)){"LPev12000", "PCIe IOV",
2295 "Obsolete, Unsupported Fibre Channel Adapter"};
2297 case PCI_DEVICE_ID_PROTEUS_PF:
2298 m = (typeof(m)){"LPev12000", "PCIe IOV",
2299 "Obsolete, Unsupported Fibre Channel Adapter"};
2301 case PCI_DEVICE_ID_PROTEUS_S:
2302 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2303 "Obsolete, Unsupported Fibre Channel Adapter"};
2305 case PCI_DEVICE_ID_TIGERSHARK:
2307 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2309 case PCI_DEVICE_ID_TOMCAT:
2311 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2313 case PCI_DEVICE_ID_FALCON:
2314 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2315 "EmulexSecure Fibre"};
2317 case PCI_DEVICE_ID_BALIUS:
2318 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2319 "Obsolete, Unsupported Fibre Channel Adapter"};
2321 case PCI_DEVICE_ID_LANCER_FC:
2322 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2324 case PCI_DEVICE_ID_LANCER_FC_VF:
2325 m = (typeof(m)){"LPe16000", "PCIe",
2326 "Obsolete, Unsupported Fibre Channel Adapter"};
2328 case PCI_DEVICE_ID_LANCER_FCOE:
2330 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2332 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2334 m = (typeof(m)){"OCe15100", "PCIe",
2335 "Obsolete, Unsupported FCoE"};
2337 case PCI_DEVICE_ID_LANCER_G6_FC:
2338 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2340 case PCI_DEVICE_ID_SKYHAWK:
2341 case PCI_DEVICE_ID_SKYHAWK_VF:
2343 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2346 m = (typeof(m)){"Unknown", "", ""};
2350 if (mdp && mdp[0] == '\0')
2351 snprintf(mdp, 79,"%s", m.name);
2353 * oneConnect hba requires special processing, they are all initiators
2354 * and we put the port number on the end
2356 if (descp && descp[0] == '\0') {
2358 snprintf(descp, 255,
2359 "Emulex OneConnect %s, %s Initiator %s",
2362 else if (max_speed == 0)
2363 snprintf(descp, 255,
2365 m.name, m.bus, m.function);
2367 snprintf(descp, 255,
2368 "Emulex %s %d%s %s %s",
2369 m.name, max_speed, (GE) ? "GE" : "Gb",
2375 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2376 * @phba: pointer to lpfc hba data structure.
2377 * @pring: pointer to a IOCB ring.
2378 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2380 * This routine posts a given number of IOCBs with the associated DMA buffer
2381 * descriptors specified by the cnt argument to the given IOCB ring.
2384 * The number of IOCBs NOT able to be posted to the IOCB ring.
2387 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2390 struct lpfc_iocbq *iocb;
2391 struct lpfc_dmabuf *mp1, *mp2;
2393 cnt += pring->missbufcnt;
2395 /* While there are buffers to post */
2397 /* Allocate buffer for command iocb */
2398 iocb = lpfc_sli_get_iocbq(phba);
2400 pring->missbufcnt = cnt;
2405 /* 2 buffers can be posted per command */
2406 /* Allocate buffer to post */
2407 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2409 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2410 if (!mp1 || !mp1->virt) {
2412 lpfc_sli_release_iocbq(phba, iocb);
2413 pring->missbufcnt = cnt;
2417 INIT_LIST_HEAD(&mp1->list);
2418 /* Allocate buffer to post */
2420 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2422 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2424 if (!mp2 || !mp2->virt) {
2426 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2428 lpfc_sli_release_iocbq(phba, iocb);
2429 pring->missbufcnt = cnt;
2433 INIT_LIST_HEAD(&mp2->list);
2438 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2439 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2440 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2441 icmd->ulpBdeCount = 1;
2444 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2445 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2446 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2448 icmd->ulpBdeCount = 2;
2451 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2454 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2456 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2460 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2464 lpfc_sli_release_iocbq(phba, iocb);
2465 pring->missbufcnt = cnt;
2468 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2470 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2472 pring->missbufcnt = 0;
2477 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2478 * @phba: pointer to lpfc hba data structure.
2480 * This routine posts initial receive IOCB buffers to the ELS ring. The
2481 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2482 * set to 64 IOCBs. SLI3 only.
2485 * 0 - success (currently always success)
2488 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2490 struct lpfc_sli *psli = &phba->sli;
2492 /* Ring 0, ELS / CT buffers */
2493 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2494 /* Ring 2 - FCP no buffers needed */
2499 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2502 * lpfc_sha_init - Set up initial array of hash table entries
2503 * @HashResultPointer: pointer to an array as hash table.
2505 * This routine sets up the initial values to the array of hash table entries
2509 lpfc_sha_init(uint32_t * HashResultPointer)
2511 HashResultPointer[0] = 0x67452301;
2512 HashResultPointer[1] = 0xEFCDAB89;
2513 HashResultPointer[2] = 0x98BADCFE;
2514 HashResultPointer[3] = 0x10325476;
2515 HashResultPointer[4] = 0xC3D2E1F0;
2519 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2520 * @HashResultPointer: pointer to an initial/result hash table.
2521 * @HashWorkingPointer: pointer to an working hash table.
2523 * This routine iterates an initial hash table pointed by @HashResultPointer
2524 * with the values from the working hash table pointeed by @HashWorkingPointer.
2525 * The results are putting back to the initial hash table, returned through
2526 * the @HashResultPointer as the result hash table.
2529 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2533 uint32_t A, B, C, D, E;
2536 HashWorkingPointer[t] =
2538 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2540 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2541 } while (++t <= 79);
2543 A = HashResultPointer[0];
2544 B = HashResultPointer[1];
2545 C = HashResultPointer[2];
2546 D = HashResultPointer[3];
2547 E = HashResultPointer[4];
2551 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2552 } else if (t < 40) {
2553 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2554 } else if (t < 60) {
2555 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2557 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2559 TEMP += S(5, A) + E + HashWorkingPointer[t];
2565 } while (++t <= 79);
2567 HashResultPointer[0] += A;
2568 HashResultPointer[1] += B;
2569 HashResultPointer[2] += C;
2570 HashResultPointer[3] += D;
2571 HashResultPointer[4] += E;
2576 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2577 * @RandomChallenge: pointer to the entry of host challenge random number array.
2578 * @HashWorking: pointer to the entry of the working hash array.
2580 * This routine calculates the working hash array referred by @HashWorking
2581 * from the challenge random numbers associated with the host, referred by
2582 * @RandomChallenge. The result is put into the entry of the working hash
2583 * array and returned by reference through @HashWorking.
2586 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2588 *HashWorking = (*RandomChallenge ^ *HashWorking);
2592 * lpfc_hba_init - Perform special handling for LC HBA initialization
2593 * @phba: pointer to lpfc hba data structure.
2594 * @hbainit: pointer to an array of unsigned 32-bit integers.
2596 * This routine performs the special handling for LC HBA initialization.
2599 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2602 uint32_t *HashWorking;
2603 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2605 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2609 HashWorking[0] = HashWorking[78] = *pwwnn++;
2610 HashWorking[1] = HashWorking[79] = *pwwnn;
2612 for (t = 0; t < 7; t++)
2613 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2615 lpfc_sha_init(hbainit);
2616 lpfc_sha_iterate(hbainit, HashWorking);
2621 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2622 * @vport: pointer to a virtual N_Port data structure.
2624 * This routine performs the necessary cleanups before deleting the @vport.
2625 * It invokes the discovery state machine to perform necessary state
2626 * transitions and to release the ndlps associated with the @vport. Note,
2627 * the physical port is treated as @vport 0.
2630 lpfc_cleanup(struct lpfc_vport *vport)
2632 struct lpfc_hba *phba = vport->phba;
2633 struct lpfc_nodelist *ndlp, *next_ndlp;
2636 if (phba->link_state > LPFC_LINK_DOWN)
2637 lpfc_port_link_failure(vport);
2639 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2640 if (!NLP_CHK_NODE_ACT(ndlp)) {
2641 ndlp = lpfc_enable_node(vport, ndlp,
2642 NLP_STE_UNUSED_NODE);
2645 spin_lock_irq(&phba->ndlp_lock);
2646 NLP_SET_FREE_REQ(ndlp);
2647 spin_unlock_irq(&phba->ndlp_lock);
2648 /* Trigger the release of the ndlp memory */
2652 spin_lock_irq(&phba->ndlp_lock);
2653 if (NLP_CHK_FREE_REQ(ndlp)) {
2654 /* The ndlp should not be in memory free mode already */
2655 spin_unlock_irq(&phba->ndlp_lock);
2658 /* Indicate request for freeing ndlp memory */
2659 NLP_SET_FREE_REQ(ndlp);
2660 spin_unlock_irq(&phba->ndlp_lock);
2662 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2663 ndlp->nlp_DID == Fabric_DID) {
2664 /* Just free up ndlp with Fabric_DID for vports */
2669 /* take care of nodes in unused state before the state
2670 * machine taking action.
2672 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2677 if (ndlp->nlp_type & NLP_FABRIC)
2678 lpfc_disc_state_machine(vport, ndlp, NULL,
2679 NLP_EVT_DEVICE_RECOVERY);
2681 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
2682 /* Remove the NVME transport reference now and
2683 * continue to remove the node.
2688 lpfc_disc_state_machine(vport, ndlp, NULL,
2692 /* At this point, ALL ndlp's should be gone
2693 * because of the previous NLP_EVT_DEVICE_RM.
2694 * Lets wait for this to happen, if needed.
2696 while (!list_empty(&vport->fc_nodes)) {
2698 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2699 "0233 Nodelist not empty\n");
2700 list_for_each_entry_safe(ndlp, next_ndlp,
2701 &vport->fc_nodes, nlp_listp) {
2702 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2704 "0282 did:x%x ndlp:x%p "
2705 "usgmap:x%x refcnt:%d\n",
2706 ndlp->nlp_DID, (void *)ndlp,
2708 kref_read(&ndlp->kref));
2713 /* Wait for any activity on ndlps to settle */
2716 lpfc_cleanup_vports_rrqs(vport, NULL);
2720 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2721 * @vport: pointer to a virtual N_Port data structure.
2723 * This routine stops all the timers associated with a @vport. This function
2724 * is invoked before disabling or deleting a @vport. Note that the physical
2725 * port is treated as @vport 0.
2728 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2730 del_timer_sync(&vport->els_tmofunc);
2731 del_timer_sync(&vport->delayed_disc_tmo);
2732 lpfc_can_disctmo(vport);
2737 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2738 * @phba: pointer to lpfc hba data structure.
2740 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2741 * caller of this routine should already hold the host lock.
2744 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2746 /* Clear pending FCF rediscovery wait flag */
2747 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2749 /* Now, try to stop the timer */
2750 del_timer(&phba->fcf.redisc_wait);
2754 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2755 * @phba: pointer to lpfc hba data structure.
2757 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2758 * checks whether the FCF rediscovery wait timer is pending with the host
2759 * lock held before proceeding with disabling the timer and clearing the
2760 * wait timer pendig flag.
2763 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2765 spin_lock_irq(&phba->hbalock);
2766 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2767 /* FCF rediscovery timer already fired or stopped */
2768 spin_unlock_irq(&phba->hbalock);
2771 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2772 /* Clear failover in progress flags */
2773 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2774 spin_unlock_irq(&phba->hbalock);
2778 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2779 * @phba: pointer to lpfc hba data structure.
2781 * This routine stops all the timers associated with a HBA. This function is
2782 * invoked before either putting a HBA offline or unloading the driver.
2785 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2787 lpfc_stop_vport_timers(phba->pport);
2788 del_timer_sync(&phba->sli.mbox_tmo);
2789 del_timer_sync(&phba->fabric_block_timer);
2790 del_timer_sync(&phba->eratt_poll);
2791 del_timer_sync(&phba->hb_tmofunc);
2792 if (phba->sli_rev == LPFC_SLI_REV4) {
2793 del_timer_sync(&phba->rrq_tmr);
2794 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2796 phba->hb_outstanding = 0;
2798 switch (phba->pci_dev_grp) {
2799 case LPFC_PCI_DEV_LP:
2800 /* Stop any LightPulse device specific driver timers */
2801 del_timer_sync(&phba->fcp_poll_timer);
2803 case LPFC_PCI_DEV_OC:
2804 /* Stop any OneConnect device sepcific driver timers */
2805 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2809 "0297 Invalid device group (x%x)\n",
2817 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2818 * @phba: pointer to lpfc hba data structure.
2820 * This routine marks a HBA's management interface as blocked. Once the HBA's
2821 * management interface is marked as blocked, all the user space access to
2822 * the HBA, whether they are from sysfs interface or libdfc interface will
2823 * all be blocked. The HBA is set to block the management interface when the
2824 * driver prepares the HBA interface for online or offline.
2827 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2829 unsigned long iflag;
2830 uint8_t actcmd = MBX_HEARTBEAT;
2831 unsigned long timeout;
2833 spin_lock_irqsave(&phba->hbalock, iflag);
2834 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2835 spin_unlock_irqrestore(&phba->hbalock, iflag);
2836 if (mbx_action == LPFC_MBX_NO_WAIT)
2838 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2839 spin_lock_irqsave(&phba->hbalock, iflag);
2840 if (phba->sli.mbox_active) {
2841 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
2842 /* Determine how long we might wait for the active mailbox
2843 * command to be gracefully completed by firmware.
2845 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2846 phba->sli.mbox_active) * 1000) + jiffies;
2848 spin_unlock_irqrestore(&phba->hbalock, iflag);
2850 /* Wait for the outstnading mailbox command to complete */
2851 while (phba->sli.mbox_active) {
2852 /* Check active mailbox complete status every 2ms */
2854 if (time_after(jiffies, timeout)) {
2855 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2856 "2813 Mgmt IO is Blocked %x "
2857 "- mbox cmd %x still active\n",
2858 phba->sli.sli_flag, actcmd);
2865 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2866 * @phba: pointer to lpfc hba data structure.
2868 * Allocate RPIs for all active remote nodes. This is needed whenever
2869 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2870 * is to fixup the temporary rpi assignments.
2873 lpfc_sli4_node_prep(struct lpfc_hba *phba)
2875 struct lpfc_nodelist *ndlp, *next_ndlp;
2876 struct lpfc_vport **vports;
2879 if (phba->sli_rev != LPFC_SLI_REV4)
2882 vports = lpfc_create_vport_work_array(phba);
2883 if (vports != NULL) {
2884 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2885 if (vports[i]->load_flag & FC_UNLOADING)
2888 list_for_each_entry_safe(ndlp, next_ndlp,
2889 &vports[i]->fc_nodes,
2891 if (NLP_CHK_NODE_ACT(ndlp)) {
2893 lpfc_sli4_alloc_rpi(phba);
2894 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2896 "0009 rpi:%x DID:%x "
2897 "flg:%x map:%x %p\n",
2907 lpfc_destroy_vport_work_array(phba, vports);
2911 * lpfc_online - Initialize and bring a HBA online
2912 * @phba: pointer to lpfc hba data structure.
2914 * This routine initializes the HBA and brings a HBA online. During this
2915 * process, the management interface is blocked to prevent user space access
2916 * to the HBA interfering with the driver initialization.
2923 lpfc_online(struct lpfc_hba *phba)
2925 struct lpfc_vport *vport;
2926 struct lpfc_vport **vports;
2928 bool vpis_cleared = false;
2932 vport = phba->pport;
2934 if (!(vport->fc_flag & FC_OFFLINE_MODE))
2937 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2938 "0458 Bring Adapter online\n");
2940 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
2942 if (phba->sli_rev == LPFC_SLI_REV4) {
2943 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2944 lpfc_unblock_mgmt_io(phba);
2947 spin_lock_irq(&phba->hbalock);
2948 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2949 vpis_cleared = true;
2950 spin_unlock_irq(&phba->hbalock);
2952 lpfc_sli_queue_init(phba);
2953 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2954 lpfc_unblock_mgmt_io(phba);
2959 vports = lpfc_create_vport_work_array(phba);
2960 if (vports != NULL) {
2961 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2962 struct Scsi_Host *shost;
2963 shost = lpfc_shost_from_vport(vports[i]);
2964 spin_lock_irq(shost->host_lock);
2965 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2966 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2967 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2968 if (phba->sli_rev == LPFC_SLI_REV4) {
2969 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
2970 if ((vpis_cleared) &&
2971 (vports[i]->port_type !=
2972 LPFC_PHYSICAL_PORT))
2975 spin_unlock_irq(shost->host_lock);
2978 lpfc_destroy_vport_work_array(phba, vports);
2980 lpfc_unblock_mgmt_io(phba);
2985 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2986 * @phba: pointer to lpfc hba data structure.
2988 * This routine marks a HBA's management interface as not blocked. Once the
2989 * HBA's management interface is marked as not blocked, all the user space
2990 * access to the HBA, whether they are from sysfs interface or libdfc
2991 * interface will be allowed. The HBA is set to block the management interface
2992 * when the driver prepares the HBA interface for online or offline and then
2993 * set to unblock the management interface afterwards.
2996 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2998 unsigned long iflag;
3000 spin_lock_irqsave(&phba->hbalock, iflag);
3001 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3002 spin_unlock_irqrestore(&phba->hbalock, iflag);
3006 * lpfc_offline_prep - Prepare a HBA to be brought offline
3007 * @phba: pointer to lpfc hba data structure.
3009 * This routine is invoked to prepare a HBA to be brought offline. It performs
3010 * unregistration login to all the nodes on all vports and flushes the mailbox
3011 * queue to make it ready to be brought offline.
3014 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
3016 struct lpfc_vport *vport = phba->pport;
3017 struct lpfc_nodelist *ndlp, *next_ndlp;
3018 struct lpfc_vport **vports;
3019 struct Scsi_Host *shost;
3022 if (vport->fc_flag & FC_OFFLINE_MODE)
3025 lpfc_block_mgmt_io(phba, mbx_action);
3027 lpfc_linkdown(phba);
3029 /* Issue an unreg_login to all nodes on all vports */
3030 vports = lpfc_create_vport_work_array(phba);
3031 if (vports != NULL) {
3032 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3033 if (vports[i]->load_flag & FC_UNLOADING)
3035 shost = lpfc_shost_from_vport(vports[i]);
3036 spin_lock_irq(shost->host_lock);
3037 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
3038 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3039 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
3040 spin_unlock_irq(shost->host_lock);
3042 shost = lpfc_shost_from_vport(vports[i]);
3043 list_for_each_entry_safe(ndlp, next_ndlp,
3044 &vports[i]->fc_nodes,
3046 if (!NLP_CHK_NODE_ACT(ndlp))
3048 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3050 if (ndlp->nlp_type & NLP_FABRIC) {
3051 lpfc_disc_state_machine(vports[i], ndlp,
3052 NULL, NLP_EVT_DEVICE_RECOVERY);
3053 lpfc_disc_state_machine(vports[i], ndlp,
3054 NULL, NLP_EVT_DEVICE_RM);
3056 spin_lock_irq(shost->host_lock);
3057 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3058 spin_unlock_irq(shost->host_lock);
3060 * Whenever an SLI4 port goes offline, free the
3061 * RPI. Get a new RPI when the adapter port
3062 * comes back online.
3064 if (phba->sli_rev == LPFC_SLI_REV4) {
3065 lpfc_printf_vlog(ndlp->vport,
3066 KERN_INFO, LOG_NODE,
3067 "0011 lpfc_offline: "
3069 "usgmap:x%x rpi:%x\n",
3070 ndlp, ndlp->nlp_DID,
3074 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
3076 lpfc_unreg_rpi(vports[i], ndlp);
3080 lpfc_destroy_vport_work_array(phba, vports);
3082 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
3086 * lpfc_offline - Bring a HBA offline
3087 * @phba: pointer to lpfc hba data structure.
3089 * This routine actually brings a HBA offline. It stops all the timers
3090 * associated with the HBA, brings down the SLI layer, and eventually
3091 * marks the HBA as in offline state for the upper layer protocol.
3094 lpfc_offline(struct lpfc_hba *phba)
3096 struct Scsi_Host *shost;
3097 struct lpfc_vport **vports;
3100 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3103 /* stop port and all timers associated with this hba */
3104 lpfc_stop_port(phba);
3105 vports = lpfc_create_vport_work_array(phba);
3107 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3108 lpfc_stop_vport_timers(vports[i]);
3109 lpfc_destroy_vport_work_array(phba, vports);
3110 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3111 "0460 Bring Adapter offline\n");
3112 /* Bring down the SLI Layer and cleanup. The HBA is offline
3114 lpfc_sli_hba_down(phba);
3115 spin_lock_irq(&phba->hbalock);
3117 spin_unlock_irq(&phba->hbalock);
3118 vports = lpfc_create_vport_work_array(phba);
3120 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3121 shost = lpfc_shost_from_vport(vports[i]);
3122 spin_lock_irq(shost->host_lock);
3123 vports[i]->work_port_events = 0;
3124 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3125 spin_unlock_irq(shost->host_lock);
3127 lpfc_destroy_vport_work_array(phba, vports);
3131 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3132 * @phba: pointer to lpfc hba data structure.
3134 * This routine is to free all the SCSI buffers and IOCBs from the driver
3135 * list back to kernel. It is called from lpfc_pci_remove_one to free
3136 * the internal resources before the device is removed from the system.
3139 lpfc_scsi_free(struct lpfc_hba *phba)
3141 struct lpfc_scsi_buf *sb, *sb_next;
3143 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3146 spin_lock_irq(&phba->hbalock);
3148 /* Release all the lpfc_scsi_bufs maintained by this host. */
3150 spin_lock(&phba->scsi_buf_list_put_lock);
3151 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3153 list_del(&sb->list);
3154 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3157 phba->total_scsi_bufs--;
3159 spin_unlock(&phba->scsi_buf_list_put_lock);
3161 spin_lock(&phba->scsi_buf_list_get_lock);
3162 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3164 list_del(&sb->list);
3165 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
3168 phba->total_scsi_bufs--;
3170 spin_unlock(&phba->scsi_buf_list_get_lock);
3171 spin_unlock_irq(&phba->hbalock);
3174 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3175 * @phba: pointer to lpfc hba data structure.
3177 * This routine is to free all the NVME buffers and IOCBs from the driver
3178 * list back to kernel. It is called from lpfc_pci_remove_one to free
3179 * the internal resources before the device is removed from the system.
3182 lpfc_nvme_free(struct lpfc_hba *phba)
3184 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
3186 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3189 spin_lock_irq(&phba->hbalock);
3191 /* Release all the lpfc_nvme_bufs maintained by this host. */
3192 spin_lock(&phba->nvme_buf_list_put_lock);
3193 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3194 &phba->lpfc_nvme_buf_list_put, list) {
3195 list_del(&lpfc_ncmd->list);
3196 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3197 lpfc_ncmd->dma_handle);
3199 phba->total_nvme_bufs--;
3201 spin_unlock(&phba->nvme_buf_list_put_lock);
3203 spin_lock(&phba->nvme_buf_list_get_lock);
3204 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3205 &phba->lpfc_nvme_buf_list_get, list) {
3206 list_del(&lpfc_ncmd->list);
3207 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3208 lpfc_ncmd->dma_handle);
3210 phba->total_nvme_bufs--;
3212 spin_unlock(&phba->nvme_buf_list_get_lock);
3213 spin_unlock_irq(&phba->hbalock);
3216 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3217 * @phba: pointer to lpfc hba data structure.
3219 * This routine first calculates the sizes of the current els and allocated
3220 * scsi sgl lists, and then goes through all sgls to updates the physical
3221 * XRIs assigned due to port function reset. During port initialization, the
3222 * current els and allocated scsi sgl lists are 0s.
3225 * 0 - successful (for now, it always returns 0)
3228 lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
3230 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3231 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3232 LIST_HEAD(els_sgl_list);
3236 * update on pci function's els xri-sgl list
3238 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3240 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3241 /* els xri-sgl expanded */
3242 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3243 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3244 "3157 ELS xri-sgl count increased from "
3245 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3247 /* allocate the additional els sgls */
3248 for (i = 0; i < xri_cnt; i++) {
3249 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3251 if (sglq_entry == NULL) {
3252 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3253 "2562 Failure to allocate an "
3254 "ELS sgl entry:%d\n", i);
3258 sglq_entry->buff_type = GEN_BUFF_TYPE;
3259 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3261 if (sglq_entry->virt == NULL) {
3263 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3264 "2563 Failure to allocate an "
3265 "ELS mbuf:%d\n", i);
3269 sglq_entry->sgl = sglq_entry->virt;
3270 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3271 sglq_entry->state = SGL_FREED;
3272 list_add_tail(&sglq_entry->list, &els_sgl_list);
3274 spin_lock_irq(&phba->hbalock);
3275 spin_lock(&phba->sli4_hba.sgl_list_lock);
3276 list_splice_init(&els_sgl_list,
3277 &phba->sli4_hba.lpfc_els_sgl_list);
3278 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3279 spin_unlock_irq(&phba->hbalock);
3280 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3281 /* els xri-sgl shrinked */
3282 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3283 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3284 "3158 ELS xri-sgl count decreased from "
3285 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3287 spin_lock_irq(&phba->hbalock);
3288 spin_lock(&phba->sli4_hba.sgl_list_lock);
3289 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3291 /* release extra els sgls from list */
3292 for (i = 0; i < xri_cnt; i++) {
3293 list_remove_head(&els_sgl_list,
3294 sglq_entry, struct lpfc_sglq, list);
3296 __lpfc_mbuf_free(phba, sglq_entry->virt,
3301 list_splice_init(&els_sgl_list,
3302 &phba->sli4_hba.lpfc_els_sgl_list);
3303 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3304 spin_unlock_irq(&phba->hbalock);
3306 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3307 "3163 ELS xri-sgl count unchanged: %d\n",
3309 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3311 /* update xris to els sgls on the list */
3313 sglq_entry_next = NULL;
3314 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3315 &phba->sli4_hba.lpfc_els_sgl_list, list) {
3316 lxri = lpfc_sli4_next_xritag(phba);
3317 if (lxri == NO_XRI) {
3318 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3319 "2400 Failed to allocate xri for "
3324 sglq_entry->sli4_lxritag = lxri;
3325 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3330 lpfc_free_els_sgl_list(phba);
3335 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3336 * @phba: pointer to lpfc hba data structure.
3338 * This routine first calculates the sizes of the current els and allocated
3339 * scsi sgl lists, and then goes through all sgls to updates the physical
3340 * XRIs assigned due to port function reset. During port initialization, the
3341 * current els and allocated scsi sgl lists are 0s.
3344 * 0 - successful (for now, it always returns 0)
3347 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3349 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3350 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3351 uint16_t nvmet_xri_cnt, tot_cnt;
3352 LIST_HEAD(nvmet_sgl_list);
3356 * update on pci function's nvmet xri-sgl list
3358 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3359 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
3360 tot_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3361 if (nvmet_xri_cnt > tot_cnt) {
3362 phba->cfg_nvmet_mrq_post = tot_cnt / phba->cfg_nvmet_mrq;
3363 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
3364 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3365 "6301 NVMET post-sgl count changed to %d\n",
3366 phba->cfg_nvmet_mrq_post);
3369 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3370 /* els xri-sgl expanded */
3371 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3372 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3373 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3374 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3375 /* allocate the additional nvmet sgls */
3376 for (i = 0; i < xri_cnt; i++) {
3377 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3379 if (sglq_entry == NULL) {
3380 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3381 "6303 Failure to allocate an "
3382 "NVMET sgl entry:%d\n", i);
3386 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3387 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3389 if (sglq_entry->virt == NULL) {
3391 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3392 "6304 Failure to allocate an "
3393 "NVMET buf:%d\n", i);
3397 sglq_entry->sgl = sglq_entry->virt;
3398 memset(sglq_entry->sgl, 0,
3399 phba->cfg_sg_dma_buf_size);
3400 sglq_entry->state = SGL_FREED;
3401 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3403 spin_lock_irq(&phba->hbalock);
3404 spin_lock(&phba->sli4_hba.sgl_list_lock);
3405 list_splice_init(&nvmet_sgl_list,
3406 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3407 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3408 spin_unlock_irq(&phba->hbalock);
3409 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3410 /* nvmet xri-sgl shrunk */
3411 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3412 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3413 "6305 NVMET xri-sgl count decreased from "
3414 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3416 spin_lock_irq(&phba->hbalock);
3417 spin_lock(&phba->sli4_hba.sgl_list_lock);
3418 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3420 /* release extra nvmet sgls from list */
3421 for (i = 0; i < xri_cnt; i++) {
3422 list_remove_head(&nvmet_sgl_list,
3423 sglq_entry, struct lpfc_sglq, list);
3425 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3430 list_splice_init(&nvmet_sgl_list,
3431 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3432 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3433 spin_unlock_irq(&phba->hbalock);
3435 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3436 "6306 NVMET xri-sgl count unchanged: %d\n",
3438 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3440 /* update xris to nvmet sgls on the list */
3442 sglq_entry_next = NULL;
3443 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3444 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3445 lxri = lpfc_sli4_next_xritag(phba);
3446 if (lxri == NO_XRI) {
3447 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3448 "6307 Failed to allocate xri for "
3453 sglq_entry->sli4_lxritag = lxri;
3454 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3459 lpfc_free_nvmet_sgl_list(phba);
3464 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3465 * @phba: pointer to lpfc hba data structure.
3467 * This routine first calculates the sizes of the current els and allocated
3468 * scsi sgl lists, and then goes through all sgls to updates the physical
3469 * XRIs assigned due to port function reset. During port initialization, the
3470 * current els and allocated scsi sgl lists are 0s.
3473 * 0 - successful (for now, it always returns 0)
3476 lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3478 struct lpfc_scsi_buf *psb, *psb_next;
3479 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3480 LIST_HEAD(scsi_sgl_list);
3484 * update on pci function's els xri-sgl list
3486 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3487 phba->total_scsi_bufs = 0;
3490 * update on pci function's allocated scsi xri-sgl list
3492 /* maximum number of xris available for scsi buffers */
3493 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3496 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3499 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3500 phba->sli4_hba.scsi_xri_max = /* Split them up */
3501 (phba->sli4_hba.scsi_xri_max *
3502 phba->cfg_xri_split) / 100;
3504 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3505 spin_lock(&phba->scsi_buf_list_put_lock);
3506 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3507 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3508 spin_unlock(&phba->scsi_buf_list_put_lock);
3509 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3511 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3512 /* max scsi xri shrinked below the allocated scsi buffers */
3513 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3514 phba->sli4_hba.scsi_xri_max;
3515 /* release the extra allocated scsi buffers */
3516 for (i = 0; i < scsi_xri_cnt; i++) {
3517 list_remove_head(&scsi_sgl_list, psb,
3518 struct lpfc_scsi_buf, list);
3520 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3521 psb->data, psb->dma_handle);
3525 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3526 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3527 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3530 /* update xris associated to remaining allocated scsi buffers */
3533 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3534 lxri = lpfc_sli4_next_xritag(phba);
3535 if (lxri == NO_XRI) {
3536 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3537 "2560 Failed to allocate xri for "
3542 psb->cur_iocbq.sli4_lxritag = lxri;
3543 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3545 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3546 spin_lock(&phba->scsi_buf_list_put_lock);
3547 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3548 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3549 spin_unlock(&phba->scsi_buf_list_put_lock);
3550 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3554 lpfc_scsi_free(phba);
3559 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3560 * @phba: pointer to lpfc hba data structure.
3562 * This routine first calculates the sizes of the current els and allocated
3563 * scsi sgl lists, and then goes through all sgls to updates the physical
3564 * XRIs assigned due to port function reset. During port initialization, the
3565 * current els and allocated scsi sgl lists are 0s.
3568 * 0 - successful (for now, it always returns 0)
3571 lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3573 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3574 uint16_t i, lxri, els_xri_cnt;
3575 uint16_t nvme_xri_cnt, nvme_xri_max;
3576 LIST_HEAD(nvme_sgl_list);
3579 phba->total_nvme_bufs = 0;
3581 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3584 * update on pci function's allocated nvme xri-sgl list
3587 /* maximum number of xris available for nvme buffers */
3588 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3589 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3590 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3591 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3593 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3594 "6074 Current allocated NVME xri-sgl count:%d, "
3595 "maximum NVME xri count:%d\n",
3596 phba->sli4_hba.nvme_xri_cnt,
3597 phba->sli4_hba.nvme_xri_max);
3599 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3600 spin_lock(&phba->nvme_buf_list_put_lock);
3601 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3602 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3603 spin_unlock(&phba->nvme_buf_list_put_lock);
3604 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3606 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3607 /* max nvme xri shrunk below the allocated nvme buffers */
3608 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3609 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3610 phba->sli4_hba.nvme_xri_max;
3611 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3612 /* release the extra allocated nvme buffers */
3613 for (i = 0; i < nvme_xri_cnt; i++) {
3614 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3615 struct lpfc_nvme_buf, list);
3617 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3619 lpfc_ncmd->dma_handle);
3623 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3624 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3625 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3628 /* update xris associated to remaining allocated nvme buffers */
3630 lpfc_ncmd_next = NULL;
3631 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3632 &nvme_sgl_list, list) {
3633 lxri = lpfc_sli4_next_xritag(phba);
3634 if (lxri == NO_XRI) {
3635 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3636 "6075 Failed to allocate xri for "
3641 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3642 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3644 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3645 spin_lock(&phba->nvme_buf_list_put_lock);
3646 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3647 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3648 spin_unlock(&phba->nvme_buf_list_put_lock);
3649 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3653 lpfc_nvme_free(phba);
3658 * lpfc_create_port - Create an FC port
3659 * @phba: pointer to lpfc hba data structure.
3660 * @instance: a unique integer ID to this FC port.
3661 * @dev: pointer to the device data structure.
3663 * This routine creates a FC port for the upper layer protocol. The FC port
3664 * can be created on top of either a physical port or a virtual port provided
3665 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3666 * and associates the FC port created before adding the shost into the SCSI
3670 * @vport - pointer to the virtual N_Port data structure.
3671 * NULL - port create failed.
3674 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3676 struct lpfc_vport *vport;
3677 struct Scsi_Host *shost = NULL;
3680 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3681 if (dev != &phba->pcidev->dev) {
3682 shost = scsi_host_alloc(&lpfc_vport_template,
3683 sizeof(struct lpfc_vport));
3685 if (phba->sli_rev == LPFC_SLI_REV4)
3686 shost = scsi_host_alloc(&lpfc_template,
3687 sizeof(struct lpfc_vport));
3689 shost = scsi_host_alloc(&lpfc_template_s3,
3690 sizeof(struct lpfc_vport));
3692 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3693 shost = scsi_host_alloc(&lpfc_template_nvme,
3694 sizeof(struct lpfc_vport));
3699 vport = (struct lpfc_vport *) shost->hostdata;
3701 vport->load_flag |= FC_LOADING;
3702 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3703 vport->fc_rscn_flush = 0;
3704 lpfc_get_vport_cfgparam(vport);
3706 shost->unique_id = instance;
3707 shost->max_id = LPFC_MAX_TARGET;
3708 shost->max_lun = vport->cfg_max_luns;
3709 shost->this_id = -1;
3710 shost->max_cmd_len = 16;
3711 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
3712 if (phba->sli_rev == LPFC_SLI_REV4) {
3713 shost->dma_boundary =
3714 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
3715 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3719 * Set initial can_queue value since 0 is no longer supported and
3720 * scsi_add_host will fail. This will be adjusted later based on the
3721 * max xri value determined in hba setup.
3723 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3724 if (dev != &phba->pcidev->dev) {
3725 shost->transportt = lpfc_vport_transport_template;
3726 vport->port_type = LPFC_NPIV_PORT;
3728 shost->transportt = lpfc_transport_template;
3729 vport->port_type = LPFC_PHYSICAL_PORT;
3732 /* Initialize all internally managed lists. */
3733 INIT_LIST_HEAD(&vport->fc_nodes);
3734 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3735 spin_lock_init(&vport->work_port_lock);
3737 init_timer(&vport->fc_disctmo);
3738 vport->fc_disctmo.function = lpfc_disc_timeout;
3739 vport->fc_disctmo.data = (unsigned long)vport;
3741 init_timer(&vport->els_tmofunc);
3742 vport->els_tmofunc.function = lpfc_els_timeout;
3743 vport->els_tmofunc.data = (unsigned long)vport;
3745 init_timer(&vport->delayed_disc_tmo);
3746 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3747 vport->delayed_disc_tmo.data = (unsigned long)vport;
3749 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
3753 spin_lock_irq(&phba->hbalock);
3754 list_add_tail(&vport->listentry, &phba->port_list);
3755 spin_unlock_irq(&phba->hbalock);
3759 scsi_host_put(shost);
3765 * destroy_port - destroy an FC port
3766 * @vport: pointer to an lpfc virtual N_Port data structure.
3768 * This routine destroys a FC port from the upper layer protocol. All the
3769 * resources associated with the port are released.
3772 destroy_port(struct lpfc_vport *vport)
3774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3775 struct lpfc_hba *phba = vport->phba;
3777 lpfc_debugfs_terminate(vport);
3778 fc_remove_host(shost);
3779 scsi_remove_host(shost);
3781 spin_lock_irq(&phba->hbalock);
3782 list_del_init(&vport->listentry);
3783 spin_unlock_irq(&phba->hbalock);
3785 lpfc_cleanup(vport);
3790 * lpfc_get_instance - Get a unique integer ID
3792 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3793 * uses the kernel idr facility to perform the task.
3796 * instance - a unique integer ID allocated as the new instance.
3797 * -1 - lpfc get instance failed.
3800 lpfc_get_instance(void)
3804 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3805 return ret < 0 ? -1 : ret;
3809 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3810 * @shost: pointer to SCSI host data structure.
3811 * @time: elapsed time of the scan in jiffies.
3813 * This routine is called by the SCSI layer with a SCSI host to determine
3814 * whether the scan host is finished.
3816 * Note: there is no scan_start function as adapter initialization will have
3817 * asynchronously kicked off the link initialization.
3820 * 0 - SCSI host scan is not over yet.
3821 * 1 - SCSI host scan is over.
3823 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3826 struct lpfc_hba *phba = vport->phba;
3829 spin_lock_irq(shost->host_lock);
3831 if (vport->load_flag & FC_UNLOADING) {
3835 if (time >= msecs_to_jiffies(30 * 1000)) {
3836 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3837 "0461 Scanning longer than 30 "
3838 "seconds. Continuing initialization\n");
3842 if (time >= msecs_to_jiffies(15 * 1000) &&
3843 phba->link_state <= LPFC_LINK_DOWN) {
3844 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3845 "0465 Link down longer than 15 "
3846 "seconds. Continuing initialization\n");
3851 if (vport->port_state != LPFC_VPORT_READY)
3853 if (vport->num_disc_nodes || vport->fc_prli_sent)
3855 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
3857 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
3863 spin_unlock_irq(shost->host_lock);
3868 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3869 * @shost: pointer to SCSI host data structure.
3871 * This routine initializes a given SCSI host attributes on a FC port. The
3872 * SCSI host can be either on top of a physical port or a virtual port.
3874 void lpfc_host_attrib_init(struct Scsi_Host *shost)
3876 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3877 struct lpfc_hba *phba = vport->phba;
3879 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3882 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3883 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3884 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3886 memset(fc_host_supported_fc4s(shost), 0,
3887 sizeof(fc_host_supported_fc4s(shost)));
3888 fc_host_supported_fc4s(shost)[2] = 1;
3889 fc_host_supported_fc4s(shost)[7] = 1;
3891 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3892 sizeof fc_host_symbolic_name(shost));
3894 fc_host_supported_speeds(shost) = 0;
3895 if (phba->lmt & LMT_32Gb)
3896 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
3897 if (phba->lmt & LMT_16Gb)
3898 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
3899 if (phba->lmt & LMT_10Gb)
3900 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
3901 if (phba->lmt & LMT_8Gb)
3902 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
3903 if (phba->lmt & LMT_4Gb)
3904 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3905 if (phba->lmt & LMT_2Gb)
3906 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3907 if (phba->lmt & LMT_1Gb)
3908 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3910 fc_host_maxframe_size(shost) =
3911 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3912 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
3914 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3916 /* This value is also unchanging */
3917 memset(fc_host_active_fc4s(shost), 0,
3918 sizeof(fc_host_active_fc4s(shost)));
3919 fc_host_active_fc4s(shost)[2] = 1;
3920 fc_host_active_fc4s(shost)[7] = 1;
3922 fc_host_max_npiv_vports(shost) = phba->max_vpi;
3923 spin_lock_irq(shost->host_lock);
3924 vport->load_flag &= ~FC_LOADING;
3925 spin_unlock_irq(shost->host_lock);
3929 * lpfc_stop_port_s3 - Stop SLI3 device port
3930 * @phba: pointer to lpfc hba data structure.
3932 * This routine is invoked to stop an SLI3 device port, it stops the device
3933 * from generating interrupts and stops the device driver's timers for the
3937 lpfc_stop_port_s3(struct lpfc_hba *phba)
3939 /* Clear all interrupt enable conditions */
3940 writel(0, phba->HCregaddr);
3941 readl(phba->HCregaddr); /* flush */
3942 /* Clear all pending interrupts */
3943 writel(0xffffffff, phba->HAregaddr);
3944 readl(phba->HAregaddr); /* flush */
3946 /* Reset some HBA SLI setup states */
3947 lpfc_stop_hba_timers(phba);
3948 phba->pport->work_port_events = 0;
3952 * lpfc_stop_port_s4 - Stop SLI4 device port
3953 * @phba: pointer to lpfc hba data structure.
3955 * This routine is invoked to stop an SLI4 device port, it stops the device
3956 * from generating interrupts and stops the device driver's timers for the
3960 lpfc_stop_port_s4(struct lpfc_hba *phba)
3962 /* Reset some HBA SLI4 setup states */
3963 lpfc_stop_hba_timers(phba);
3964 phba->pport->work_port_events = 0;
3965 phba->sli4_hba.intr_enable = 0;
3969 * lpfc_stop_port - Wrapper function for stopping hba port
3970 * @phba: Pointer to HBA context object.
3972 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3973 * the API jump table function pointer from the lpfc_hba struct.
3976 lpfc_stop_port(struct lpfc_hba *phba)
3978 phba->lpfc_stop_port(phba);
3982 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3983 * @phba: Pointer to hba for which this call is being executed.
3985 * This routine starts the timer waiting for the FCF rediscovery to complete.
3988 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3990 unsigned long fcf_redisc_wait_tmo =
3991 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3992 /* Start fcf rediscovery wait period timer */
3993 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3994 spin_lock_irq(&phba->hbalock);
3995 /* Allow action to new fcf asynchronous event */
3996 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3997 /* Mark the FCF rediscovery pending state */
3998 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3999 spin_unlock_irq(&phba->hbalock);
4003 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4004 * @ptr: Map to lpfc_hba data structure pointer.
4006 * This routine is invoked when waiting for FCF table rediscover has been
4007 * timed out. If new FCF record(s) has (have) been discovered during the
4008 * wait period, a new FCF event shall be added to the FCOE async event
4009 * list, and then worker thread shall be waked up for processing from the
4010 * worker thread context.
4013 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
4015 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
4017 /* Don't send FCF rediscovery event if timer cancelled */
4018 spin_lock_irq(&phba->hbalock);
4019 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4020 spin_unlock_irq(&phba->hbalock);
4023 /* Clear FCF rediscovery timer pending flag */
4024 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4025 /* FCF rediscovery event to worker thread */
4026 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4027 spin_unlock_irq(&phba->hbalock);
4028 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4029 "2776 FCF rediscover quiescent timer expired\n");
4030 /* wake up worker thread */
4031 lpfc_worker_wake_up(phba);
4035 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4036 * @phba: pointer to lpfc hba data structure.
4037 * @acqe_link: pointer to the async link completion queue entry.
4039 * This routine is to parse the SLI4 link-attention link fault code and
4040 * translate it into the base driver's read link attention mailbox command
4043 * Return: Link-attention status in terms of base driver's coding.
4046 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4047 struct lpfc_acqe_link *acqe_link)
4049 uint16_t latt_fault;
4051 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4052 case LPFC_ASYNC_LINK_FAULT_NONE:
4053 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4054 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4059 "0398 Invalid link fault code: x%x\n",
4060 bf_get(lpfc_acqe_link_fault, acqe_link));
4061 latt_fault = MBXERR_ERROR;
4068 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4069 * @phba: pointer to lpfc hba data structure.
4070 * @acqe_link: pointer to the async link completion queue entry.
4072 * This routine is to parse the SLI4 link attention type and translate it
4073 * into the base driver's link attention type coding.
4075 * Return: Link attention type in terms of base driver's coding.
4078 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4079 struct lpfc_acqe_link *acqe_link)
4083 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4084 case LPFC_ASYNC_LINK_STATUS_DOWN:
4085 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
4086 att_type = LPFC_ATT_LINK_DOWN;
4088 case LPFC_ASYNC_LINK_STATUS_UP:
4089 /* Ignore physical link up events - wait for logical link up */
4090 att_type = LPFC_ATT_RESERVED;
4092 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
4093 att_type = LPFC_ATT_LINK_UP;
4096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4097 "0399 Invalid link attention type: x%x\n",
4098 bf_get(lpfc_acqe_link_status, acqe_link));
4099 att_type = LPFC_ATT_RESERVED;
4106 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4107 * @phba: pointer to lpfc hba data structure.
4109 * This routine is to get an SLI3 FC port's link speed in Mbps.
4111 * Return: link speed in terms of Mbps.
4114 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4116 uint32_t link_speed;
4118 if (!lpfc_is_link_up(phba))
4121 if (phba->sli_rev <= LPFC_SLI_REV3) {
4122 switch (phba->fc_linkspeed) {
4123 case LPFC_LINK_SPEED_1GHZ:
4126 case LPFC_LINK_SPEED_2GHZ:
4129 case LPFC_LINK_SPEED_4GHZ:
4132 case LPFC_LINK_SPEED_8GHZ:
4135 case LPFC_LINK_SPEED_10GHZ:
4138 case LPFC_LINK_SPEED_16GHZ:
4145 if (phba->sli4_hba.link_state.logical_speed)
4147 phba->sli4_hba.link_state.logical_speed;
4149 link_speed = phba->sli4_hba.link_state.speed;
4155 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4156 * @phba: pointer to lpfc hba data structure.
4157 * @evt_code: asynchronous event code.
4158 * @speed_code: asynchronous event link speed code.
4160 * This routine is to parse the giving SLI4 async event link speed code into
4161 * value of Mbps for the link speed.
4163 * Return: link speed in terms of Mbps.
4166 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4169 uint32_t port_speed;
4172 case LPFC_TRAILER_CODE_LINK:
4173 switch (speed_code) {
4174 case LPFC_ASYNC_LINK_SPEED_ZERO:
4177 case LPFC_ASYNC_LINK_SPEED_10MBPS:
4180 case LPFC_ASYNC_LINK_SPEED_100MBPS:
4183 case LPFC_ASYNC_LINK_SPEED_1GBPS:
4186 case LPFC_ASYNC_LINK_SPEED_10GBPS:
4189 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4192 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4195 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4202 case LPFC_TRAILER_CODE_FC:
4203 switch (speed_code) {
4204 case LPFC_FC_LA_SPEED_UNKNOWN:
4207 case LPFC_FC_LA_SPEED_1G:
4210 case LPFC_FC_LA_SPEED_2G:
4213 case LPFC_FC_LA_SPEED_4G:
4216 case LPFC_FC_LA_SPEED_8G:
4219 case LPFC_FC_LA_SPEED_10G:
4222 case LPFC_FC_LA_SPEED_16G:
4225 case LPFC_FC_LA_SPEED_32G:
4239 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4240 * @phba: pointer to lpfc hba data structure.
4241 * @acqe_link: pointer to the async link completion queue entry.
4243 * This routine is to handle the SLI4 asynchronous FCoE link event.
4246 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4247 struct lpfc_acqe_link *acqe_link)
4249 struct lpfc_dmabuf *mp;
4252 struct lpfc_mbx_read_top *la;
4256 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
4257 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
4259 phba->fcoe_eventtag = acqe_link->event_tag;
4260 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4262 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4263 "0395 The mboxq allocation failed\n");
4266 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4269 "0396 The lpfc_dmabuf allocation failed\n");
4272 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4274 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4275 "0397 The mbuf allocation failed\n");
4276 goto out_free_dmabuf;
4279 /* Cleanup any outstanding ELS commands */
4280 lpfc_els_flush_all_cmd(phba);
4282 /* Block ELS IOCBs until we have done process link event */
4283 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4285 /* Update link event statistics */
4286 phba->sli.slistat.link_event++;
4288 /* Create lpfc_handle_latt mailbox command from link ACQE */
4289 lpfc_read_topology(phba, pmb, mp);
4290 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4291 pmb->vport = phba->pport;
4293 /* Keep the link status for extra SLI4 state machine reference */
4294 phba->sli4_hba.link_state.speed =
4295 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4296 bf_get(lpfc_acqe_link_speed, acqe_link));
4297 phba->sli4_hba.link_state.duplex =
4298 bf_get(lpfc_acqe_link_duplex, acqe_link);
4299 phba->sli4_hba.link_state.status =
4300 bf_get(lpfc_acqe_link_status, acqe_link);
4301 phba->sli4_hba.link_state.type =
4302 bf_get(lpfc_acqe_link_type, acqe_link);
4303 phba->sli4_hba.link_state.number =
4304 bf_get(lpfc_acqe_link_number, acqe_link);
4305 phba->sli4_hba.link_state.fault =
4306 bf_get(lpfc_acqe_link_fault, acqe_link);
4307 phba->sli4_hba.link_state.logical_speed =
4308 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4310 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4311 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4312 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4313 "Logical speed:%dMbps Fault:%d\n",
4314 phba->sli4_hba.link_state.speed,
4315 phba->sli4_hba.link_state.topology,
4316 phba->sli4_hba.link_state.status,
4317 phba->sli4_hba.link_state.type,
4318 phba->sli4_hba.link_state.number,
4319 phba->sli4_hba.link_state.logical_speed,
4320 phba->sli4_hba.link_state.fault);
4322 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4323 * topology info. Note: Optional for non FC-AL ports.
4325 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4326 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4327 if (rc == MBX_NOT_FINISHED)
4328 goto out_free_dmabuf;
4332 * For FCoE Mode: fill in all the topology information we need and call
4333 * the READ_TOPOLOGY completion routine to continue without actually
4334 * sending the READ_TOPOLOGY mailbox command to the port.
4336 /* Parse and translate status field */
4338 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4340 /* Parse and translate link attention fields */
4341 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4342 la->eventTag = acqe_link->event_tag;
4343 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4344 bf_set(lpfc_mbx_read_top_link_spd, la,
4345 (bf_get(lpfc_acqe_link_speed, acqe_link)));
4347 /* Fake the the following irrelvant fields */
4348 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4349 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4350 bf_set(lpfc_mbx_read_top_il, la, 0);
4351 bf_set(lpfc_mbx_read_top_pb, la, 0);
4352 bf_set(lpfc_mbx_read_top_fa, la, 0);
4353 bf_set(lpfc_mbx_read_top_mm, la, 0);
4355 /* Invoke the lpfc_handle_latt mailbox command callback function */
4356 lpfc_mbx_cmpl_read_topology(phba, pmb);
4363 mempool_free(pmb, phba->mbox_mem_pool);
4367 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4368 * @phba: pointer to lpfc hba data structure.
4369 * @acqe_fc: pointer to the async fc completion queue entry.
4371 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4372 * that the event was received and then issue a read_topology mailbox command so
4373 * that the rest of the driver will treat it the same as SLI3.
4376 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4378 struct lpfc_dmabuf *mp;
4381 struct lpfc_mbx_read_top *la;
4384 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4385 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4386 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4387 "2895 Non FC link Event detected.(%d)\n",
4388 bf_get(lpfc_trailer_type, acqe_fc));
4391 /* Keep the link status for extra SLI4 state machine reference */
4392 phba->sli4_hba.link_state.speed =
4393 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4394 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4395 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4396 phba->sli4_hba.link_state.topology =
4397 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4398 phba->sli4_hba.link_state.status =
4399 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4400 phba->sli4_hba.link_state.type =
4401 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4402 phba->sli4_hba.link_state.number =
4403 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4404 phba->sli4_hba.link_state.fault =
4405 bf_get(lpfc_acqe_link_fault, acqe_fc);
4406 phba->sli4_hba.link_state.logical_speed =
4407 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
4408 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4409 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4410 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4411 "%dMbps Fault:%d\n",
4412 phba->sli4_hba.link_state.speed,
4413 phba->sli4_hba.link_state.topology,
4414 phba->sli4_hba.link_state.status,
4415 phba->sli4_hba.link_state.type,
4416 phba->sli4_hba.link_state.number,
4417 phba->sli4_hba.link_state.logical_speed,
4418 phba->sli4_hba.link_state.fault);
4419 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4421 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4422 "2897 The mboxq allocation failed\n");
4425 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4427 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4428 "2898 The lpfc_dmabuf allocation failed\n");
4431 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4433 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4434 "2899 The mbuf allocation failed\n");
4435 goto out_free_dmabuf;
4438 /* Cleanup any outstanding ELS commands */
4439 lpfc_els_flush_all_cmd(phba);
4441 /* Block ELS IOCBs until we have done process link event */
4442 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
4444 /* Update link event statistics */
4445 phba->sli.slistat.link_event++;
4447 /* Create lpfc_handle_latt mailbox command from link ACQE */
4448 lpfc_read_topology(phba, pmb, mp);
4449 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4450 pmb->vport = phba->pport;
4452 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4453 /* Parse and translate status field */
4455 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4458 /* Parse and translate link attention fields */
4459 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4460 la->eventTag = acqe_fc->event_tag;
4461 bf_set(lpfc_mbx_read_top_att_type, la,
4462 LPFC_FC_LA_TYPE_LINK_DOWN);
4464 /* Invoke the mailbox command callback function */
4465 lpfc_mbx_cmpl_read_topology(phba, pmb);
4470 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4471 if (rc == MBX_NOT_FINISHED)
4472 goto out_free_dmabuf;
4478 mempool_free(pmb, phba->mbox_mem_pool);
4482 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4483 * @phba: pointer to lpfc hba data structure.
4484 * @acqe_fc: pointer to the async SLI completion queue entry.
4486 * This routine is to handle the SLI4 asynchronous SLI events.
4489 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4495 uint8_t operational = 0;
4496 struct temp_event temp_event_data;
4497 struct lpfc_acqe_misconfigured_event *misconfigured;
4498 struct Scsi_Host *shost;
4500 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4502 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4503 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4504 "x%08x SLI Event Type:%d\n",
4505 acqe_sli->event_data1, acqe_sli->event_data2,
4508 port_name = phba->Port[0];
4509 if (port_name == 0x00)
4510 port_name = '?'; /* get port name is empty */
4513 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4514 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4515 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4516 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4518 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4519 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4520 acqe_sli->event_data1, port_name);
4522 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
4523 shost = lpfc_shost_from_vport(phba->pport);
4524 fc_host_post_vendor_event(shost, fc_get_event_number(),
4525 sizeof(temp_event_data),
4526 (char *)&temp_event_data,
4527 SCSI_NL_VID_TYPE_PCI
4528 | PCI_VENDOR_ID_EMULEX);
4530 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4531 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4532 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4533 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4535 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4536 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4537 acqe_sli->event_data1, port_name);
4539 shost = lpfc_shost_from_vport(phba->pport);
4540 fc_host_post_vendor_event(shost, fc_get_event_number(),
4541 sizeof(temp_event_data),
4542 (char *)&temp_event_data,
4543 SCSI_NL_VID_TYPE_PCI
4544 | PCI_VENDOR_ID_EMULEX);
4546 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4547 misconfigured = (struct lpfc_acqe_misconfigured_event *)
4548 &acqe_sli->event_data1;
4550 /* fetch the status for this port */
4551 switch (phba->sli4_hba.lnk_info.lnk_no) {
4552 case LPFC_LINK_NUMBER_0:
4553 status = bf_get(lpfc_sli_misconfigured_port0_state,
4554 &misconfigured->theEvent);
4555 operational = bf_get(lpfc_sli_misconfigured_port0_op,
4556 &misconfigured->theEvent);
4558 case LPFC_LINK_NUMBER_1:
4559 status = bf_get(lpfc_sli_misconfigured_port1_state,
4560 &misconfigured->theEvent);
4561 operational = bf_get(lpfc_sli_misconfigured_port1_op,
4562 &misconfigured->theEvent);
4564 case LPFC_LINK_NUMBER_2:
4565 status = bf_get(lpfc_sli_misconfigured_port2_state,
4566 &misconfigured->theEvent);
4567 operational = bf_get(lpfc_sli_misconfigured_port2_op,
4568 &misconfigured->theEvent);
4570 case LPFC_LINK_NUMBER_3:
4571 status = bf_get(lpfc_sli_misconfigured_port3_state,
4572 &misconfigured->theEvent);
4573 operational = bf_get(lpfc_sli_misconfigured_port3_op,
4574 &misconfigured->theEvent);
4577 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4579 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4580 "event: Invalid link %d",
4581 phba->sli4_hba.lnk_info.lnk_no);
4585 /* Skip if optic state unchanged */
4586 if (phba->sli4_hba.lnk_info.optic_state == status)
4590 case LPFC_SLI_EVENT_STATUS_VALID:
4591 sprintf(message, "Physical Link is functional");
4593 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4594 sprintf(message, "Optics faulted/incorrectly "
4595 "installed/not installed - Reseat optics, "
4596 "if issue not resolved, replace.");
4598 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4600 "Optics of two types installed - Remove one "
4601 "optic or install matching pair of optics.");
4603 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4604 sprintf(message, "Incompatible optics - Replace with "
4605 "compatible optics for card to function.");
4607 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4608 sprintf(message, "Unqualified optics - Replace with "
4609 "Avago optics for Warranty and Technical "
4610 "Support - Link is%s operational",
4611 (operational) ? " not" : "");
4613 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4614 sprintf(message, "Uncertified optics - Replace with "
4615 "Avago-certified optics to enable link "
4616 "operation - Link is%s operational",
4617 (operational) ? " not" : "");
4620 /* firmware is reporting a status we don't know about */
4621 sprintf(message, "Unknown event status x%02x", status);
4624 phba->sli4_hba.lnk_info.optic_state = status;
4625 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4626 "3176 Port Name %c %s\n", port_name, message);
4628 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4629 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4630 "3192 Remote DPort Test Initiated - "
4631 "Event Data1:x%08x Event Data2: x%08x\n",
4632 acqe_sli->event_data1, acqe_sli->event_data2);
4635 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4636 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4637 "x%08x SLI Event Type:%d\n",
4638 acqe_sli->event_data1, acqe_sli->event_data2,
4645 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4646 * @vport: pointer to vport data structure.
4648 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4649 * response to a CVL event.
4651 * Return the pointer to the ndlp with the vport if successful, otherwise
4654 static struct lpfc_nodelist *
4655 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4657 struct lpfc_nodelist *ndlp;
4658 struct Scsi_Host *shost;
4659 struct lpfc_hba *phba;
4666 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4668 /* Cannot find existing Fabric ndlp, so allocate a new one */
4669 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4672 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4673 /* Set the node type */
4674 ndlp->nlp_type |= NLP_FABRIC;
4675 /* Put ndlp onto node list */
4676 lpfc_enqueue_node(vport, ndlp);
4677 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4678 /* re-setup ndlp without removing from node list */
4679 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4683 if ((phba->pport->port_state < LPFC_FLOGI) &&
4684 (phba->pport->port_state != LPFC_VPORT_FAILED))
4686 /* If virtual link is not yet instantiated ignore CVL */
4687 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4688 && (vport->port_state != LPFC_VPORT_FAILED))
4690 shost = lpfc_shost_from_vport(vport);
4693 lpfc_linkdown_port(vport);
4694 lpfc_cleanup_pending_mbox(vport);
4695 spin_lock_irq(shost->host_lock);
4696 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4697 spin_unlock_irq(shost->host_lock);
4703 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4704 * @vport: pointer to lpfc hba data structure.
4706 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4707 * response to a FCF dead event.
4710 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4712 struct lpfc_vport **vports;
4715 vports = lpfc_create_vport_work_array(phba);
4717 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4718 lpfc_sli4_perform_vport_cvl(vports[i]);
4719 lpfc_destroy_vport_work_array(phba, vports);
4723 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4724 * @phba: pointer to lpfc hba data structure.
4725 * @acqe_link: pointer to the async fcoe completion queue entry.
4727 * This routine is to handle the SLI4 asynchronous fcoe event.
4730 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4731 struct lpfc_acqe_fip *acqe_fip)
4733 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
4735 struct lpfc_vport *vport;
4736 struct lpfc_nodelist *ndlp;
4737 struct Scsi_Host *shost;
4738 int active_vlink_present;
4739 struct lpfc_vport **vports;
4742 phba->fc_eventTag = acqe_fip->event_tag;
4743 phba->fcoe_eventtag = acqe_fip->event_tag;
4744 switch (event_type) {
4745 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4746 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4747 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
4748 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4750 "2546 New FCF event, evt_tag:x%x, "
4752 acqe_fip->event_tag,
4755 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4757 "2788 FCF param modified event, "
4758 "evt_tag:x%x, index:x%x\n",
4759 acqe_fip->event_tag,
4761 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4763 * During period of FCF discovery, read the FCF
4764 * table record indexed by the event to update
4765 * FCF roundrobin failover eligible FCF bmask.
4767 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4769 "2779 Read FCF (x%x) for updating "
4770 "roundrobin FCF failover bmask\n",
4772 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
4775 /* If the FCF discovery is in progress, do nothing. */
4776 spin_lock_irq(&phba->hbalock);
4777 if (phba->hba_flag & FCF_TS_INPROG) {
4778 spin_unlock_irq(&phba->hbalock);
4781 /* If fast FCF failover rescan event is pending, do nothing */
4782 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4783 spin_unlock_irq(&phba->hbalock);
4787 /* If the FCF has been in discovered state, do nothing. */
4788 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
4789 spin_unlock_irq(&phba->hbalock);
4792 spin_unlock_irq(&phba->hbalock);
4794 /* Otherwise, scan the entire FCF table and re-discover SAN */
4795 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4796 "2770 Start FCF table scan per async FCF "
4797 "event, evt_tag:x%x, index:x%x\n",
4798 acqe_fip->event_tag, acqe_fip->index);
4799 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4800 LPFC_FCOE_FCF_GET_FIRST);
4802 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4803 "2547 Issue FCF scan read FCF mailbox "
4804 "command failed (x%x)\n", rc);
4807 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
4808 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4809 "2548 FCF Table full count 0x%x tag 0x%x\n",
4810 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4811 acqe_fip->event_tag);
4814 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
4815 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
4816 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4817 "2549 FCF (x%x) disconnected from network, "
4818 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
4820 * If we are in the middle of FCF failover process, clear
4821 * the corresponding FCF bit in the roundrobin bitmap.
4823 spin_lock_irq(&phba->hbalock);
4824 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4825 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
4826 spin_unlock_irq(&phba->hbalock);
4827 /* Update FLOGI FCF failover eligible FCF bmask */
4828 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
4831 spin_unlock_irq(&phba->hbalock);
4833 /* If the event is not for currently used fcf do nothing */
4834 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
4838 * Otherwise, request the port to rediscover the entire FCF
4839 * table for a fast recovery from case that the current FCF
4840 * is no longer valid as we are not in the middle of FCF
4841 * failover process already.
4843 spin_lock_irq(&phba->hbalock);
4844 /* Mark the fast failover process in progress */
4845 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4846 spin_unlock_irq(&phba->hbalock);
4848 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4849 "2771 Start FCF fast failover process due to "
4850 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4851 "\n", acqe_fip->event_tag, acqe_fip->index);
4852 rc = lpfc_sli4_redisc_fcf_table(phba);
4854 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4856 "2772 Issue FCF rediscover mabilbox "
4857 "command failed, fail through to FCF "
4859 spin_lock_irq(&phba->hbalock);
4860 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4861 spin_unlock_irq(&phba->hbalock);
4863 * Last resort will fail over by treating this
4864 * as a link down to FCF registration.
4866 lpfc_sli4_fcf_dead_failthrough(phba);
4868 /* Reset FCF roundrobin bmask for new discovery */
4869 lpfc_sli4_clear_fcf_rr_bmask(phba);
4871 * Handling fast FCF failover to a DEAD FCF event is
4872 * considered equalivant to receiving CVL to all vports.
4874 lpfc_sli4_perform_all_vport_cvl(phba);
4877 case LPFC_FIP_EVENT_TYPE_CVL:
4878 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
4879 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4880 "2718 Clear Virtual Link Received for VPI 0x%x"
4881 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
4883 vport = lpfc_find_vport_by_vpid(phba,
4885 ndlp = lpfc_sli4_perform_vport_cvl(vport);
4888 active_vlink_present = 0;
4890 vports = lpfc_create_vport_work_array(phba);
4892 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4894 if ((!(vports[i]->fc_flag &
4895 FC_VPORT_CVL_RCVD)) &&
4896 (vports[i]->port_state > LPFC_FDISC)) {
4897 active_vlink_present = 1;
4901 lpfc_destroy_vport_work_array(phba, vports);
4905 * Don't re-instantiate if vport is marked for deletion.
4906 * If we are here first then vport_delete is going to wait
4907 * for discovery to complete.
4909 if (!(vport->load_flag & FC_UNLOADING) &&
4910 active_vlink_present) {
4912 * If there are other active VLinks present,
4913 * re-instantiate the Vlink using FDISC.
4915 mod_timer(&ndlp->nlp_delayfunc,
4916 jiffies + msecs_to_jiffies(1000));
4917 shost = lpfc_shost_from_vport(vport);
4918 spin_lock_irq(shost->host_lock);
4919 ndlp->nlp_flag |= NLP_DELAY_TMO;
4920 spin_unlock_irq(shost->host_lock);
4921 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4922 vport->port_state = LPFC_FDISC;
4925 * Otherwise, we request port to rediscover
4926 * the entire FCF table for a fast recovery
4927 * from possible case that the current FCF
4928 * is no longer valid if we are not already
4929 * in the FCF failover process.
4931 spin_lock_irq(&phba->hbalock);
4932 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4933 spin_unlock_irq(&phba->hbalock);
4936 /* Mark the fast failover process in progress */
4937 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
4938 spin_unlock_irq(&phba->hbalock);
4939 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4941 "2773 Start FCF failover per CVL, "
4942 "evt_tag:x%x\n", acqe_fip->event_tag);
4943 rc = lpfc_sli4_redisc_fcf_table(phba);
4945 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4947 "2774 Issue FCF rediscover "
4948 "mabilbox command failed, "
4949 "through to CVL event\n");
4950 spin_lock_irq(&phba->hbalock);
4951 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
4952 spin_unlock_irq(&phba->hbalock);
4954 * Last resort will be re-try on the
4955 * the current registered FCF entry.
4957 lpfc_retry_pport_discovery(phba);
4960 * Reset FCF roundrobin bmask for new
4963 lpfc_sli4_clear_fcf_rr_bmask(phba);
4967 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4968 "0288 Unknown FCoE event type 0x%x event tag "
4969 "0x%x\n", event_type, acqe_fip->event_tag);
4975 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4976 * @phba: pointer to lpfc hba data structure.
4977 * @acqe_link: pointer to the async dcbx completion queue entry.
4979 * This routine is to handle the SLI4 asynchronous dcbx event.
4982 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4983 struct lpfc_acqe_dcbx *acqe_dcbx)
4985 phba->fc_eventTag = acqe_dcbx->event_tag;
4986 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4987 "0290 The SLI4 DCBX asynchronous event is not "
4992 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4993 * @phba: pointer to lpfc hba data structure.
4994 * @acqe_link: pointer to the async grp5 completion queue entry.
4996 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4997 * is an asynchronous notified of a logical link speed change. The Port
4998 * reports the logical link speed in units of 10Mbps.
5001 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5002 struct lpfc_acqe_grp5 *acqe_grp5)
5004 uint16_t prev_ll_spd;
5006 phba->fc_eventTag = acqe_grp5->event_tag;
5007 phba->fcoe_eventtag = acqe_grp5->event_tag;
5008 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5009 phba->sli4_hba.link_state.logical_speed =
5010 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
5011 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5012 "2789 GRP5 Async Event: Updating logical link speed "
5013 "from %dMbps to %dMbps\n", prev_ll_spd,
5014 phba->sli4_hba.link_state.logical_speed);
5018 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5019 * @phba: pointer to lpfc hba data structure.
5021 * This routine is invoked by the worker thread to process all the pending
5022 * SLI4 asynchronous events.
5024 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5026 struct lpfc_cq_event *cq_event;
5028 /* First, declare the async event has been handled */
5029 spin_lock_irq(&phba->hbalock);
5030 phba->hba_flag &= ~ASYNC_EVENT;
5031 spin_unlock_irq(&phba->hbalock);
5032 /* Now, handle all the async events */
5033 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5034 /* Get the first event from the head of the event queue */
5035 spin_lock_irq(&phba->hbalock);
5036 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5037 cq_event, struct lpfc_cq_event, list);
5038 spin_unlock_irq(&phba->hbalock);
5039 /* Process the asynchronous event */
5040 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5041 case LPFC_TRAILER_CODE_LINK:
5042 lpfc_sli4_async_link_evt(phba,
5043 &cq_event->cqe.acqe_link);
5045 case LPFC_TRAILER_CODE_FCOE:
5046 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
5048 case LPFC_TRAILER_CODE_DCBX:
5049 lpfc_sli4_async_dcbx_evt(phba,
5050 &cq_event->cqe.acqe_dcbx);
5052 case LPFC_TRAILER_CODE_GRP5:
5053 lpfc_sli4_async_grp5_evt(phba,
5054 &cq_event->cqe.acqe_grp5);
5056 case LPFC_TRAILER_CODE_FC:
5057 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5059 case LPFC_TRAILER_CODE_SLI:
5060 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5063 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5064 "1804 Invalid asynchrous event code: "
5065 "x%x\n", bf_get(lpfc_trailer_code,
5066 &cq_event->cqe.mcqe_cmpl));
5069 /* Free the completion event processed to the free pool */
5070 lpfc_sli4_cq_event_release(phba, cq_event);
5075 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5076 * @phba: pointer to lpfc hba data structure.
5078 * This routine is invoked by the worker thread to process FCF table
5079 * rediscovery pending completion event.
5081 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5085 spin_lock_irq(&phba->hbalock);
5086 /* Clear FCF rediscovery timeout event */
5087 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5088 /* Clear driver fast failover FCF record flag */
5089 phba->fcf.failover_rec.flag = 0;
5090 /* Set state for FCF fast failover */
5091 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5092 spin_unlock_irq(&phba->hbalock);
5094 /* Scan FCF table from the first entry to re-discover SAN */
5095 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5096 "2777 Start post-quiescent FCF table scan\n");
5097 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5099 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5100 "2747 Issue FCF scan read FCF mailbox "
5101 "command failed 0x%x\n", rc);
5105 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5106 * @phba: pointer to lpfc hba data structure.
5107 * @dev_grp: The HBA PCI-Device group number.
5109 * This routine is invoked to set up the per HBA PCI-Device group function
5110 * API jump table entries.
5112 * Return: 0 if success, otherwise -ENODEV
5115 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5119 /* Set up lpfc PCI-device group */
5120 phba->pci_dev_grp = dev_grp;
5122 /* The LPFC_PCI_DEV_OC uses SLI4 */
5123 if (dev_grp == LPFC_PCI_DEV_OC)
5124 phba->sli_rev = LPFC_SLI_REV4;
5126 /* Set up device INIT API function jump table */
5127 rc = lpfc_init_api_table_setup(phba, dev_grp);
5130 /* Set up SCSI API function jump table */
5131 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5134 /* Set up SLI API function jump table */
5135 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5138 /* Set up MBOX API function jump table */
5139 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5147 * lpfc_log_intr_mode - Log the active interrupt mode
5148 * @phba: pointer to lpfc hba data structure.
5149 * @intr_mode: active interrupt mode adopted.
5151 * This routine it invoked to log the currently used active interrupt mode
5154 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
5156 switch (intr_mode) {
5158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5159 "0470 Enable INTx interrupt mode.\n");
5162 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5163 "0481 Enabled MSI interrupt mode.\n");
5166 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5167 "0480 Enabled MSI-X interrupt mode.\n");
5170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5171 "0482 Illegal interrupt mode.\n");
5178 * lpfc_enable_pci_dev - Enable a generic PCI device.
5179 * @phba: pointer to lpfc hba data structure.
5181 * This routine is invoked to enable the PCI device that is common to all
5186 * other values - error
5189 lpfc_enable_pci_dev(struct lpfc_hba *phba)
5191 struct pci_dev *pdev;
5193 /* Obtain PCI device reference */
5197 pdev = phba->pcidev;
5198 /* Enable PCI device */
5199 if (pci_enable_device_mem(pdev))
5201 /* Request PCI resource for the device */
5202 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
5203 goto out_disable_device;
5204 /* Set up device as PCI master and save state for EEH */
5205 pci_set_master(pdev);
5206 pci_try_set_mwi(pdev);
5207 pci_save_state(pdev);
5209 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5210 if (pci_is_pcie(pdev))
5211 pdev->needs_freset = 1;
5216 pci_disable_device(pdev);
5218 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5219 "1401 Failed to enable pci device\n");
5224 * lpfc_disable_pci_dev - Disable a generic PCI device.
5225 * @phba: pointer to lpfc hba data structure.
5227 * This routine is invoked to disable the PCI device that is common to all
5231 lpfc_disable_pci_dev(struct lpfc_hba *phba)
5233 struct pci_dev *pdev;
5235 /* Obtain PCI device reference */
5239 pdev = phba->pcidev;
5240 /* Release PCI resource and disable PCI device */
5241 pci_release_mem_regions(pdev);
5242 pci_disable_device(pdev);
5248 * lpfc_reset_hba - Reset a hba
5249 * @phba: pointer to lpfc hba data structure.
5251 * This routine is invoked to reset a hba device. It brings the HBA
5252 * offline, performs a board restart, and then brings the board back
5253 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5254 * on outstanding mailbox commands.
5257 lpfc_reset_hba(struct lpfc_hba *phba)
5259 /* If resets are disabled then set error state and return. */
5260 if (!phba->cfg_enable_hba_reset) {
5261 phba->link_state = LPFC_HBA_ERROR;
5264 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5265 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5267 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
5269 lpfc_sli_brdrestart(phba);
5271 lpfc_unblock_mgmt_io(phba);
5275 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5276 * @phba: pointer to lpfc hba data structure.
5278 * This function enables the PCI SR-IOV virtual functions to a physical
5279 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5280 * enable the number of virtual functions to the physical function. As
5281 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5282 * API call does not considered as an error condition for most of the device.
5285 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5287 struct pci_dev *pdev = phba->pcidev;
5291 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5295 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5300 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5301 * @phba: pointer to lpfc hba data structure.
5302 * @nr_vfn: number of virtual functions to be enabled.
5304 * This function enables the PCI SR-IOV virtual functions to a physical
5305 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5306 * enable the number of virtual functions to the physical function. As
5307 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5308 * API call does not considered as an error condition for most of the device.
5311 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5313 struct pci_dev *pdev = phba->pcidev;
5314 uint16_t max_nr_vfn;
5317 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5318 if (nr_vfn > max_nr_vfn) {
5319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5320 "3057 Requested vfs (%d) greater than "
5321 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5325 rc = pci_enable_sriov(pdev, nr_vfn);
5327 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5328 "2806 Failed to enable sriov on this device "
5329 "with vfn number nr_vf:%d, rc:%d\n",
5332 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5333 "2807 Successful enable sriov on this device "
5334 "with vfn number nr_vf:%d\n", nr_vfn);
5339 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5340 * @phba: pointer to lpfc hba data structure.
5342 * This routine is invoked to set up the driver internal resources before the
5343 * device specific resource setup to support the HBA device it attached to.
5347 * other values - error
5350 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5352 struct lpfc_sli *psli = &phba->sli;
5355 * Driver resources common to all SLI revisions
5357 atomic_set(&phba->fast_event_count, 0);
5358 spin_lock_init(&phba->hbalock);
5360 /* Initialize ndlp management spinlock */
5361 spin_lock_init(&phba->ndlp_lock);
5363 INIT_LIST_HEAD(&phba->port_list);
5364 INIT_LIST_HEAD(&phba->work_list);
5365 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5367 /* Initialize the wait queue head for the kernel thread */
5368 init_waitqueue_head(&phba->work_waitq);
5370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5371 "1403 Protocols supported %s %s %s\n",
5372 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5374 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5376 (phba->nvmet_support ? "NVMET" : " "));
5378 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5379 /* Initialize the scsi buffer list used by driver for scsi IO */
5380 spin_lock_init(&phba->scsi_buf_list_get_lock);
5381 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5382 spin_lock_init(&phba->scsi_buf_list_put_lock);
5383 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5386 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5387 (phba->nvmet_support == 0)) {
5388 /* Initialize the NVME buffer list used by driver for NVME IO */
5389 spin_lock_init(&phba->nvme_buf_list_get_lock);
5390 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5391 spin_lock_init(&phba->nvme_buf_list_put_lock);
5392 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5395 /* Initialize the fabric iocb list */
5396 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5398 /* Initialize list to save ELS buffers */
5399 INIT_LIST_HEAD(&phba->elsbuf);
5401 /* Initialize FCF connection rec list */
5402 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5404 /* Initialize OAS configuration list */
5405 spin_lock_init(&phba->devicelock);
5406 INIT_LIST_HEAD(&phba->luns);
5408 /* MBOX heartbeat timer */
5409 init_timer(&psli->mbox_tmo);
5410 psli->mbox_tmo.function = lpfc_mbox_timeout;
5411 psli->mbox_tmo.data = (unsigned long) phba;
5412 /* Fabric block timer */
5413 init_timer(&phba->fabric_block_timer);
5414 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5415 phba->fabric_block_timer.data = (unsigned long) phba;
5416 /* EA polling mode timer */
5417 init_timer(&phba->eratt_poll);
5418 phba->eratt_poll.function = lpfc_poll_eratt;
5419 phba->eratt_poll.data = (unsigned long) phba;
5420 /* Heartbeat timer */
5421 init_timer(&phba->hb_tmofunc);
5422 phba->hb_tmofunc.function = lpfc_hb_timeout;
5423 phba->hb_tmofunc.data = (unsigned long)phba;
5429 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5430 * @phba: pointer to lpfc hba data structure.
5432 * This routine is invoked to set up the driver internal resources specific to
5433 * support the SLI-3 HBA device it attached to.
5437 * other values - error
5440 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5445 * Initialize timers used by driver
5448 /* FCP polling mode timer */
5449 init_timer(&phba->fcp_poll_timer);
5450 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5451 phba->fcp_poll_timer.data = (unsigned long) phba;
5453 /* Host attention work mask setup */
5454 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5455 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5457 /* Get all the module params for configuring this host */
5458 lpfc_get_cfgparam(phba);
5459 /* Set up phase-1 common device driver resources */
5461 rc = lpfc_setup_driver_resource_phase1(phba);
5465 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5466 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5467 /* check for menlo minimum sg count */
5468 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5469 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5472 if (!phba->sli.sli3_ring)
5473 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
5474 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5475 if (!phba->sli.sli3_ring)
5479 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5480 * used to create the sg_dma_buf_pool must be dynamically calculated.
5483 /* Initialize the host templates the configured values. */
5484 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5485 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
5487 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5488 if (phba->cfg_enable_bg) {
5490 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5491 * the FCP rsp, and a BDE for each. Sice we have no control
5492 * over how many protection data segments the SCSI Layer
5493 * will hand us (ie: there could be one for every block
5494 * in the IO), we just allocate enough BDEs to accomidate
5495 * our max amount and we need to limit lpfc_sg_seg_cnt to
5496 * minimize the risk of running out.
5498 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5499 sizeof(struct fcp_rsp) +
5500 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5502 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5503 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5505 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5506 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5509 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5510 * the FCP rsp, a BDE for each, and a BDE for up to
5511 * cfg_sg_seg_cnt data segments.
5513 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5514 sizeof(struct fcp_rsp) +
5515 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5517 /* Total BDEs in BPL for scsi_sg_list */
5518 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5521 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5522 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5523 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5524 phba->cfg_total_seg_cnt);
5526 phba->max_vpi = LPFC_MAX_VPI;
5527 /* This will be set to correct value after config_port mbox */
5528 phba->max_vports = 0;
5531 * Initialize the SLI Layer to run with lpfc HBAs.
5533 lpfc_sli_setup(phba);
5534 lpfc_sli_queue_init(phba);
5536 /* Allocate device driver memory */
5537 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5541 * Enable sr-iov virtual functions if supported and configured
5542 * through the module parameter.
5544 if (phba->cfg_sriov_nr_virtfn > 0) {
5545 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5546 phba->cfg_sriov_nr_virtfn);
5548 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5549 "2808 Requested number of SR-IOV "
5550 "virtual functions (%d) is not "
5552 phba->cfg_sriov_nr_virtfn);
5553 phba->cfg_sriov_nr_virtfn = 0;
5561 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5562 * @phba: pointer to lpfc hba data structure.
5564 * This routine is invoked to unset the driver internal resources set up
5565 * specific for supporting the SLI-3 HBA device it attached to.
5568 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5570 /* Free device driver memory allocated */
5571 lpfc_mem_free_all(phba);
5577 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5578 * @phba: pointer to lpfc hba data structure.
5580 * This routine is invoked to set up the driver internal resources specific to
5581 * support the SLI-4 HBA device it attached to.
5585 * other values - error
5588 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5590 LPFC_MBOXQ_t *mboxq;
5592 int rc, i, max_buf_size;
5593 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5594 struct lpfc_mqe *mqe;
5596 int fof_vectors = 0;
5599 phba->sli4_hba.num_online_cpu = num_online_cpus();
5600 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5601 phba->sli4_hba.curr_disp_cpu = 0;
5603 /* Get all the module params for configuring this host */
5604 lpfc_get_cfgparam(phba);
5606 /* Set up phase-1 common device driver resources */
5607 rc = lpfc_setup_driver_resource_phase1(phba);
5611 /* Before proceed, wait for POST done and device ready */
5612 rc = lpfc_sli4_post_status_check(phba);
5617 * Initialize timers used by driver
5620 init_timer(&phba->rrq_tmr);
5621 phba->rrq_tmr.function = lpfc_rrq_timeout;
5622 phba->rrq_tmr.data = (unsigned long)phba;
5624 /* FCF rediscover timer */
5625 init_timer(&phba->fcf.redisc_wait);
5626 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5627 phba->fcf.redisc_wait.data = (unsigned long)phba;
5630 * Control structure for handling external multi-buffer mailbox
5631 * command pass-through.
5633 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5634 sizeof(struct lpfc_mbox_ext_buf_ctx));
5635 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5637 phba->max_vpi = LPFC_MAX_VPI;
5639 /* This will be set to correct value after the read_config mbox */
5640 phba->max_vports = 0;
5642 /* Program the default value of vlan_id and fc_map */
5643 phba->valid_vlan = 0;
5644 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5645 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5646 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5649 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5650 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5651 * The WQ create will allocate the ring.
5655 * It doesn't matter what family our adapter is in, we are
5656 * limited to 2 Pages, 512 SGEs, for our SGL.
5657 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5659 max_buf_size = (2 * SLI4_PAGE_SIZE);
5660 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5661 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
5664 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5665 * used to create the sg_dma_buf_pool must be calculated.
5667 if (phba->cfg_enable_bg) {
5669 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5670 * the FCP rsp, and a SGE. Sice we have no control
5671 * over how many protection segments the SCSI Layer
5672 * will hand us (ie: there could be one for every block
5673 * in the IO), just allocate enough SGEs to accomidate
5674 * our max amount and we need to limit lpfc_sg_seg_cnt
5675 * to minimize the risk of running out.
5677 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5678 sizeof(struct fcp_rsp) + max_buf_size;
5680 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5681 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5683 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5684 phba->cfg_sg_seg_cnt =
5685 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5688 * The scsi_buf for a regular I/O holds the FCP cmnd,
5689 * the FCP rsp, a SGE for each, and a SGE for up to
5690 * cfg_sg_seg_cnt data segments.
5692 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5693 sizeof(struct fcp_rsp) +
5694 ((phba->cfg_sg_seg_cnt + 2) *
5695 sizeof(struct sli4_sge));
5697 /* Total SGEs for scsi_sg_list */
5698 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5701 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5702 * need to post 1 page for the SGL.
5706 /* Initialize the host templates with the updated values. */
5707 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5708 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5710 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5711 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5713 phba->cfg_sg_dma_buf_size =
5714 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5716 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5717 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5718 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5719 phba->cfg_total_seg_cnt);
5721 /* Initialize buffer queue management fields */
5722 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
5723 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5724 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5727 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5729 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5730 /* Initialize the Abort scsi buffer list used by driver */
5731 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5732 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5735 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5736 /* Initialize the Abort nvme buffer list used by driver */
5737 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5738 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5741 /* This abort list used by worker thread */
5742 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
5743 spin_lock_init(&phba->sli4_hba.nvmet_io_lock);
5746 * Initialize driver internal slow-path work queues
5749 /* Driver internel slow-path CQ Event pool */
5750 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5751 /* Response IOCB work queue list */
5752 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
5753 /* Asynchronous event CQ Event work queue list */
5754 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5755 /* Fast-path XRI aborted CQ Event work queue list */
5756 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5757 /* Slow-path XRI aborted CQ Event work queue list */
5758 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5759 /* Receive queue CQ Event work queue list */
5760 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5762 /* Initialize extent block lists. */
5763 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5764 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5765 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5766 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5768 /* initialize optic_state to 0xFF */
5769 phba->sli4_hba.lnk_info.optic_state = 0xff;
5771 /* Allocate device driver memory */
5772 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5776 /* IF Type 2 ports get initialized now. */
5777 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5778 LPFC_SLI_INTF_IF_TYPE_2) {
5779 rc = lpfc_pci_function_reset(phba);
5784 phba->temp_sensor_support = 1;
5787 /* Create the bootstrap mailbox command */
5788 rc = lpfc_create_bootstrap_mbox(phba);
5792 /* Set up the host's endian order with the device. */
5793 rc = lpfc_setup_endian_order(phba);
5795 goto out_free_bsmbx;
5797 /* Set up the hba's configuration parameters. */
5798 rc = lpfc_sli4_read_config(phba);
5800 goto out_free_bsmbx;
5801 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5803 goto out_free_bsmbx;
5805 /* IF Type 0 ports get initialized now. */
5806 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5807 LPFC_SLI_INTF_IF_TYPE_0) {
5808 rc = lpfc_pci_function_reset(phba);
5810 goto out_free_bsmbx;
5813 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5817 goto out_free_bsmbx;
5820 /* Check for NVMET being configured */
5821 phba->nvmet_support = 0;
5822 if (lpfc_enable_nvmet_cnt) {
5824 /* First get WWN of HBA instance */
5825 lpfc_read_nv(phba, mboxq);
5826 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5827 if (rc != MBX_SUCCESS) {
5828 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5829 "6016 Mailbox failed , mbxCmd x%x "
5830 "READ_NV, mbxStatus x%x\n",
5831 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5832 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
5834 goto out_free_bsmbx;
5837 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
5839 wwn = cpu_to_be64(wwn);
5840 phba->sli4_hba.wwnn.u.name = wwn;
5841 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
5843 /* wwn is WWPN of HBA instance */
5844 wwn = cpu_to_be64(wwn);
5845 phba->sli4_hba.wwpn.u.name = wwn;
5847 /* Check to see if it matches any module parameter */
5848 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
5849 if (wwn == lpfc_enable_nvmet[i]) {
5850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5851 "6017 NVME Target %016llx\n",
5853 phba->nvmet_support = 1; /* a match */
5858 lpfc_nvme_mod_param_dep(phba);
5860 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
5861 lpfc_supported_pages(mboxq);
5862 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5864 mqe = &mboxq->u.mqe;
5865 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5866 LPFC_MAX_SUPPORTED_PAGES);
5867 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5868 switch (pn_page[i]) {
5869 case LPFC_SLI4_PARAMETERS:
5870 phba->sli4_hba.pc_sli4_params.supported = 1;
5876 /* Read the port's SLI4 Parameters capabilities if supported. */
5877 if (phba->sli4_hba.pc_sli4_params.supported)
5878 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5880 mempool_free(mboxq, phba->mbox_mem_pool);
5882 goto out_free_bsmbx;
5887 * Get sli4 parameters that override parameters from Port capabilities.
5888 * If this call fails, it isn't critical unless the SLI4 parameters come
5891 rc = lpfc_get_sli4_parameters(phba, mboxq);
5893 if (phba->sli4_hba.extents_in_use &&
5894 phba->sli4_hba.rpi_hdrs_in_use) {
5895 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5896 "2999 Unsupported SLI4 Parameters "
5897 "Extents and RPI headers enabled.\n");
5899 mempool_free(mboxq, phba->mbox_mem_pool);
5900 goto out_free_bsmbx;
5903 mempool_free(mboxq, phba->mbox_mem_pool);
5905 /* Verify OAS is supported */
5906 lpfc_sli4_oas_verify(phba);
5910 /* Verify all the SLI4 queues */
5911 rc = lpfc_sli4_queue_verify(phba);
5913 goto out_free_bsmbx;
5915 /* Create driver internal CQE event pool */
5916 rc = lpfc_sli4_cq_event_pool_create(phba);
5918 goto out_free_bsmbx;
5920 /* Initialize sgl lists per host */
5921 lpfc_init_sgl_list(phba);
5923 /* Allocate and initialize active sgl array */
5924 rc = lpfc_init_active_sgl_array(phba);
5926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5927 "1430 Failed to initialize sgl list.\n");
5928 goto out_destroy_cq_event_pool;
5930 rc = lpfc_sli4_init_rpi_hdrs(phba);
5932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5933 "1432 Failed to initialize rpi headers.\n");
5934 goto out_free_active_sgl;
5937 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5938 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5939 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5941 if (!phba->fcf.fcf_rr_bmask) {
5942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5943 "2759 Failed allocate memory for FCF round "
5944 "robin failover bmask\n");
5946 goto out_remove_rpi_hdrs;
5949 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
5950 sizeof(struct lpfc_hba_eq_hdl),
5952 if (!phba->sli4_hba.hba_eq_hdl) {
5953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5954 "2572 Failed allocate memory for "
5955 "fast-path per-EQ handle array\n");
5957 goto out_free_fcf_rr_bmask;
5960 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
5961 sizeof(struct lpfc_vector_map_info),
5963 if (!phba->sli4_hba.cpu_map) {
5964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5965 "3327 Failed allocate memory for msi-x "
5966 "interrupt vector mapping\n");
5968 goto out_free_hba_eq_hdl;
5970 if (lpfc_used_cpu == NULL) {
5971 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
5973 if (!lpfc_used_cpu) {
5974 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5975 "3335 Failed allocate memory for msi-x "
5976 "interrupt vector mapping\n");
5977 kfree(phba->sli4_hba.cpu_map);
5979 goto out_free_hba_eq_hdl;
5981 for (i = 0; i < lpfc_present_cpu; i++)
5982 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5986 * Enable sr-iov virtual functions if supported and configured
5987 * through the module parameter.
5989 if (phba->cfg_sriov_nr_virtfn > 0) {
5990 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5991 phba->cfg_sriov_nr_virtfn);
5993 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5994 "3020 Requested number of SR-IOV "
5995 "virtual functions (%d) is not "
5997 phba->cfg_sriov_nr_virtfn);
5998 phba->cfg_sriov_nr_virtfn = 0;
6004 out_free_hba_eq_hdl:
6005 kfree(phba->sli4_hba.hba_eq_hdl);
6006 out_free_fcf_rr_bmask:
6007 kfree(phba->fcf.fcf_rr_bmask);
6008 out_remove_rpi_hdrs:
6009 lpfc_sli4_remove_rpi_hdrs(phba);
6010 out_free_active_sgl:
6011 lpfc_free_active_sgl(phba);
6012 out_destroy_cq_event_pool:
6013 lpfc_sli4_cq_event_pool_destroy(phba);
6015 lpfc_destroy_bootstrap_mbox(phba);
6017 lpfc_mem_free(phba);
6022 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6023 * @phba: pointer to lpfc hba data structure.
6025 * This routine is invoked to unset the driver internal resources set up
6026 * specific for supporting the SLI-4 HBA device it attached to.
6029 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6031 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6033 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6034 kfree(phba->sli4_hba.cpu_map);
6035 phba->sli4_hba.num_present_cpu = 0;
6036 phba->sli4_hba.num_online_cpu = 0;
6037 phba->sli4_hba.curr_disp_cpu = 0;
6039 /* Free memory allocated for fast-path work queue handles */
6040 kfree(phba->sli4_hba.hba_eq_hdl);
6042 /* Free the allocated rpi headers. */
6043 lpfc_sli4_remove_rpi_hdrs(phba);
6044 lpfc_sli4_remove_rpis(phba);
6046 /* Free eligible FCF index bmask */
6047 kfree(phba->fcf.fcf_rr_bmask);
6049 /* Free the ELS sgl list */
6050 lpfc_free_active_sgl(phba);
6051 lpfc_free_els_sgl_list(phba);
6052 lpfc_free_nvmet_sgl_list(phba);
6054 /* Free the completion queue EQ event pool */
6055 lpfc_sli4_cq_event_release_all(phba);
6056 lpfc_sli4_cq_event_pool_destroy(phba);
6058 /* Release resource identifiers. */
6059 lpfc_sli4_dealloc_resource_identifiers(phba);
6061 /* Free the bsmbx region. */
6062 lpfc_destroy_bootstrap_mbox(phba);
6064 /* Free the SLI Layer memory with SLI4 HBAs */
6065 lpfc_mem_free_all(phba);
6067 /* Free the current connect table */
6068 list_for_each_entry_safe(conn_entry, next_conn_entry,
6069 &phba->fcf_conn_rec_list, list) {
6070 list_del_init(&conn_entry->list);
6078 * lpfc_init_api_table_setup - Set up init api function jump table
6079 * @phba: The hba struct for which this call is being executed.
6080 * @dev_grp: The HBA PCI-Device group number.
6082 * This routine sets up the device INIT interface API function jump table
6085 * Returns: 0 - success, -ENODEV - failure.
6088 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6090 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6091 phba->lpfc_hba_down_link = lpfc_hba_down_link;
6092 phba->lpfc_selective_reset = lpfc_selective_reset;
6094 case LPFC_PCI_DEV_LP:
6095 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6096 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6097 phba->lpfc_stop_port = lpfc_stop_port_s3;
6099 case LPFC_PCI_DEV_OC:
6100 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6101 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6102 phba->lpfc_stop_port = lpfc_stop_port_s4;
6105 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6106 "1431 Invalid HBA PCI-device group: 0x%x\n",
6115 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6116 * @phba: pointer to lpfc hba data structure.
6118 * This routine is invoked to set up the driver internal resources after the
6119 * device specific resource setup to support the HBA device it attached to.
6123 * other values - error
6126 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6130 /* Startup the kernel thread for this host adapter. */
6131 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6132 "lpfc_worker_%d", phba->brd_no);
6133 if (IS_ERR(phba->worker_thread)) {
6134 error = PTR_ERR(phba->worker_thread);
6142 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6143 * @phba: pointer to lpfc hba data structure.
6145 * This routine is invoked to unset the driver internal resources set up after
6146 * the device specific resource setup for supporting the HBA device it
6150 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6152 /* Stop kernel worker thread */
6153 kthread_stop(phba->worker_thread);
6157 * lpfc_free_iocb_list - Free iocb list.
6158 * @phba: pointer to lpfc hba data structure.
6160 * This routine is invoked to free the driver's IOCB list and memory.
6163 lpfc_free_iocb_list(struct lpfc_hba *phba)
6165 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6167 spin_lock_irq(&phba->hbalock);
6168 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6169 &phba->lpfc_iocb_list, list) {
6170 list_del(&iocbq_entry->list);
6172 phba->total_iocbq_bufs--;
6174 spin_unlock_irq(&phba->hbalock);
6180 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6181 * @phba: pointer to lpfc hba data structure.
6183 * This routine is invoked to allocate and initizlize the driver's IOCB
6184 * list and set up the IOCB tag array accordingly.
6188 * other values - error
6191 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6193 struct lpfc_iocbq *iocbq_entry = NULL;
6197 /* Initialize and populate the iocb list per host. */
6198 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
6199 for (i = 0; i < iocb_count; i++) {
6200 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
6201 if (iocbq_entry == NULL) {
6202 printk(KERN_ERR "%s: only allocated %d iocbs of "
6203 "expected %d count. Unloading driver.\n",
6204 __func__, i, LPFC_IOCB_LIST_CNT);
6205 goto out_free_iocbq;
6208 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6211 printk(KERN_ERR "%s: failed to allocate IOTAG. "
6212 "Unloading driver.\n", __func__);
6213 goto out_free_iocbq;
6215 iocbq_entry->sli4_lxritag = NO_XRI;
6216 iocbq_entry->sli4_xritag = NO_XRI;
6218 spin_lock_irq(&phba->hbalock);
6219 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6220 phba->total_iocbq_bufs++;
6221 spin_unlock_irq(&phba->hbalock);
6227 lpfc_free_iocb_list(phba);
6233 * lpfc_free_sgl_list - Free a given sgl list.
6234 * @phba: pointer to lpfc hba data structure.
6235 * @sglq_list: pointer to the head of sgl list.
6237 * This routine is invoked to free a give sgl list and memory.
6240 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
6242 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6244 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6245 list_del(&sglq_entry->list);
6246 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6252 * lpfc_free_els_sgl_list - Free els sgl list.
6253 * @phba: pointer to lpfc hba data structure.
6255 * This routine is invoked to free the driver's els sgl list and memory.
6258 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6260 LIST_HEAD(sglq_list);
6262 /* Retrieve all els sgls from driver list */
6263 spin_lock_irq(&phba->hbalock);
6264 spin_lock(&phba->sli4_hba.sgl_list_lock);
6265 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6266 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6267 spin_unlock_irq(&phba->hbalock);
6269 /* Now free the sgl list */
6270 lpfc_free_sgl_list(phba, &sglq_list);
6274 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6275 * @phba: pointer to lpfc hba data structure.
6277 * This routine is invoked to free the driver's nvmet sgl list and memory.
6280 lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6282 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6283 LIST_HEAD(sglq_list);
6285 /* Retrieve all nvmet sgls from driver list */
6286 spin_lock_irq(&phba->hbalock);
6287 spin_lock(&phba->sli4_hba.sgl_list_lock);
6288 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6289 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6290 spin_unlock_irq(&phba->hbalock);
6292 /* Now free the sgl list */
6293 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6294 list_del(&sglq_entry->list);
6295 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6301 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6302 * @phba: pointer to lpfc hba data structure.
6304 * This routine is invoked to allocate the driver's active sgl memory.
6305 * This array will hold the sglq_entry's for active IOs.
6308 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6311 size = sizeof(struct lpfc_sglq *);
6312 size *= phba->sli4_hba.max_cfg_param.max_xri;
6314 phba->sli4_hba.lpfc_sglq_active_list =
6315 kzalloc(size, GFP_KERNEL);
6316 if (!phba->sli4_hba.lpfc_sglq_active_list)
6322 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6323 * @phba: pointer to lpfc hba data structure.
6325 * This routine is invoked to walk through the array of active sglq entries
6326 * and free all of the resources.
6327 * This is just a place holder for now.
6330 lpfc_free_active_sgl(struct lpfc_hba *phba)
6332 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6336 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6337 * @phba: pointer to lpfc hba data structure.
6339 * This routine is invoked to allocate and initizlize the driver's sgl
6340 * list and set up the sgl xritag tag array accordingly.
6344 lpfc_init_sgl_list(struct lpfc_hba *phba)
6346 /* Initialize and populate the sglq list per host/VF. */
6347 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
6348 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6349 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6350 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
6352 /* els xri-sgl book keeping */
6353 phba->sli4_hba.els_xri_cnt = 0;
6355 /* scsi xri-buffer book keeping */
6356 phba->sli4_hba.scsi_xri_cnt = 0;
6358 /* nvme xri-buffer book keeping */
6359 phba->sli4_hba.nvme_xri_cnt = 0;
6363 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6364 * @phba: pointer to lpfc hba data structure.
6366 * This routine is invoked to post rpi header templates to the
6367 * port for those SLI4 ports that do not support extents. This routine
6368 * posts a PAGE_SIZE memory region to the port to hold up to
6369 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6370 * and should be called only when interrupts are disabled.
6374 * -ERROR - otherwise.
6377 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6380 struct lpfc_rpi_hdr *rpi_hdr;
6382 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
6383 if (!phba->sli4_hba.rpi_hdrs_in_use)
6385 if (phba->sli4_hba.extents_in_use)
6388 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6390 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6391 "0391 Error during rpi post operation\n");
6392 lpfc_sli4_remove_rpis(phba);
6400 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6401 * @phba: pointer to lpfc hba data structure.
6403 * This routine is invoked to allocate a single 4KB memory region to
6404 * support rpis and stores them in the phba. This single region
6405 * provides support for up to 64 rpis. The region is used globally
6409 * A valid rpi hdr on success.
6410 * A NULL pointer on any failure.
6412 struct lpfc_rpi_hdr *
6413 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6415 uint16_t rpi_limit, curr_rpi_range;
6416 struct lpfc_dmabuf *dmabuf;
6417 struct lpfc_rpi_hdr *rpi_hdr;
6421 * If the SLI4 port supports extents, posting the rpi header isn't
6422 * required. Set the expected maximum count and let the actual value
6423 * get set when extents are fully allocated.
6425 if (!phba->sli4_hba.rpi_hdrs_in_use)
6427 if (phba->sli4_hba.extents_in_use)
6430 /* The limit on the logical index is just the max_rpi count. */
6431 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
6432 phba->sli4_hba.max_cfg_param.max_rpi - 1;
6434 spin_lock_irq(&phba->hbalock);
6436 * Establish the starting RPI in this header block. The starting
6437 * rpi is normalized to a zero base because the physical rpi is
6440 curr_rpi_range = phba->sli4_hba.next_rpi;
6441 spin_unlock_irq(&phba->hbalock);
6444 * The port has a limited number of rpis. The increment here
6445 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6446 * and to allow the full max_rpi range per port.
6448 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
6449 rpi_count = rpi_limit - curr_rpi_range;
6451 rpi_count = LPFC_RPI_HDR_COUNT;
6456 * First allocate the protocol header region for the port. The
6457 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6459 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6463 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6464 LPFC_HDR_TEMPLATE_SIZE,
6465 &dmabuf->phys, GFP_KERNEL);
6466 if (!dmabuf->virt) {
6468 goto err_free_dmabuf;
6471 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6473 goto err_free_coherent;
6476 /* Save the rpi header data for cleanup later. */
6477 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6479 goto err_free_coherent;
6481 rpi_hdr->dmabuf = dmabuf;
6482 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6483 rpi_hdr->page_count = 1;
6484 spin_lock_irq(&phba->hbalock);
6486 /* The rpi_hdr stores the logical index only. */
6487 rpi_hdr->start_rpi = curr_rpi_range;
6488 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6491 * The next_rpi stores the next logical module-64 rpi value used
6492 * to post physical rpis in subsequent rpi postings.
6494 phba->sli4_hba.next_rpi += rpi_count;
6495 spin_unlock_irq(&phba->hbalock);
6499 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6500 dmabuf->virt, dmabuf->phys);
6507 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6508 * @phba: pointer to lpfc hba data structure.
6510 * This routine is invoked to remove all memory resources allocated
6511 * to support rpis for SLI4 ports not supporting extents. This routine
6512 * presumes the caller has released all rpis consumed by fabric or port
6513 * logins and is prepared to have the header pages removed.
6516 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6518 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6520 if (!phba->sli4_hba.rpi_hdrs_in_use)
6523 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6524 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6525 list_del(&rpi_hdr->list);
6526 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6527 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6528 kfree(rpi_hdr->dmabuf);
6532 /* There are no rpis available to the port now. */
6533 phba->sli4_hba.next_rpi = 0;
6537 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6538 * @pdev: pointer to pci device data structure.
6540 * This routine is invoked to allocate the driver hba data structure for an
6541 * HBA device. If the allocation is successful, the phba reference to the
6542 * PCI device data structure is set.
6545 * pointer to @phba - successful
6548 static struct lpfc_hba *
6549 lpfc_hba_alloc(struct pci_dev *pdev)
6551 struct lpfc_hba *phba;
6553 /* Allocate memory for HBA structure */
6554 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6556 dev_err(&pdev->dev, "failed to allocate hba struct\n");
6560 /* Set reference to PCI device in HBA structure */
6561 phba->pcidev = pdev;
6563 /* Assign an unused board number */
6564 phba->brd_no = lpfc_get_instance();
6565 if (phba->brd_no < 0) {
6569 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
6571 spin_lock_init(&phba->ct_ev_lock);
6572 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6578 * lpfc_hba_free - Free driver hba data structure with a device.
6579 * @phba: pointer to lpfc hba data structure.
6581 * This routine is invoked to free the driver hba data structure with an
6585 lpfc_hba_free(struct lpfc_hba *phba)
6587 /* Release the driver assigned board number */
6588 idr_remove(&lpfc_hba_index, phba->brd_no);
6590 /* Free memory allocated with sli3 rings */
6591 kfree(phba->sli.sli3_ring);
6592 phba->sli.sli3_ring = NULL;
6599 * lpfc_create_shost - Create hba physical port with associated scsi host.
6600 * @phba: pointer to lpfc hba data structure.
6602 * This routine is invoked to create HBA physical port and associate a SCSI
6607 * other values - error
6610 lpfc_create_shost(struct lpfc_hba *phba)
6612 struct lpfc_vport *vport;
6613 struct Scsi_Host *shost;
6615 /* Initialize HBA FC structure */
6616 phba->fc_edtov = FF_DEF_EDTOV;
6617 phba->fc_ratov = FF_DEF_RATOV;
6618 phba->fc_altov = FF_DEF_ALTOV;
6619 phba->fc_arbtov = FF_DEF_ARBTOV;
6621 atomic_set(&phba->sdev_cnt, 0);
6622 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
6626 shost = lpfc_shost_from_vport(vport);
6627 phba->pport = vport;
6629 if (phba->nvmet_support) {
6630 /* Only 1 vport (pport) will support NVME target */
6631 if (phba->txrdy_payload_pool == NULL) {
6632 phba->txrdy_payload_pool = pci_pool_create(
6633 "txrdy_pool", phba->pcidev,
6634 TXRDY_PAYLOAD_LEN, 16, 0);
6635 if (phba->txrdy_payload_pool) {
6636 phba->targetport = NULL;
6637 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6638 lpfc_printf_log(phba, KERN_INFO,
6639 LOG_INIT | LOG_NVME_DISC,
6640 "6076 NVME Target Found\n");
6645 lpfc_debugfs_initialize(vport);
6646 /* Put reference to SCSI host to driver's device private data */
6647 pci_set_drvdata(phba->pcidev, shost);
6650 * At this point we are fully registered with PSA. In addition,
6651 * any initial discovery should be completed.
6653 vport->load_flag |= FC_ALLOW_FDMI;
6654 if (phba->cfg_enable_SmartSAN ||
6655 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
6657 /* Setup appropriate attribute masks */
6658 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
6659 if (phba->cfg_enable_SmartSAN)
6660 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6662 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6668 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6669 * @phba: pointer to lpfc hba data structure.
6671 * This routine is invoked to destroy HBA physical port and the associated
6675 lpfc_destroy_shost(struct lpfc_hba *phba)
6677 struct lpfc_vport *vport = phba->pport;
6679 /* Destroy physical port that associated with the SCSI host */
6680 destroy_port(vport);
6686 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6687 * @phba: pointer to lpfc hba data structure.
6688 * @shost: the shost to be used to detect Block guard settings.
6690 * This routine sets up the local Block guard protocol settings for @shost.
6691 * This routine also allocates memory for debugging bg buffers.
6694 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6700 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6701 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6702 "1478 Registering BlockGuard with the "
6705 old_mask = phba->cfg_prot_mask;
6706 old_guard = phba->cfg_prot_guard;
6708 /* Only allow supported values */
6709 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6710 SHOST_DIX_TYPE0_PROTECTION |
6711 SHOST_DIX_TYPE1_PROTECTION);
6712 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6713 SHOST_DIX_GUARD_CRC);
6715 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6716 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6717 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6719 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6720 if ((old_mask != phba->cfg_prot_mask) ||
6721 (old_guard != phba->cfg_prot_guard))
6722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6723 "1475 Registering BlockGuard with the "
6724 "SCSI layer: mask %d guard %d\n",
6725 phba->cfg_prot_mask,
6726 phba->cfg_prot_guard);
6728 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6729 scsi_host_set_guard(shost, phba->cfg_prot_guard);
6731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6732 "1479 Not Registering BlockGuard with the SCSI "
6733 "layer, Bad protection parameters: %d %d\n",
6734 old_mask, old_guard);
6737 if (!_dump_buf_data) {
6739 spin_lock_init(&_dump_buf_lock);
6741 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6742 if (_dump_buf_data) {
6743 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6744 "9043 BLKGRD: allocated %d pages for "
6745 "_dump_buf_data at 0x%p\n",
6746 (1 << pagecnt), _dump_buf_data);
6747 _dump_buf_data_order = pagecnt;
6748 memset(_dump_buf_data, 0,
6749 ((1 << PAGE_SHIFT) << pagecnt));
6754 if (!_dump_buf_data_order)
6755 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6756 "9044 BLKGRD: ERROR unable to allocate "
6757 "memory for hexdump\n");
6759 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6760 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6761 "\n", _dump_buf_data);
6762 if (!_dump_buf_dif) {
6765 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6766 if (_dump_buf_dif) {
6767 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6768 "9046 BLKGRD: allocated %d pages for "
6769 "_dump_buf_dif at 0x%p\n",
6770 (1 << pagecnt), _dump_buf_dif);
6771 _dump_buf_dif_order = pagecnt;
6772 memset(_dump_buf_dif, 0,
6773 ((1 << PAGE_SHIFT) << pagecnt));
6778 if (!_dump_buf_dif_order)
6779 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6780 "9047 BLKGRD: ERROR unable to allocate "
6781 "memory for hexdump\n");
6783 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6784 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
6789 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6790 * @phba: pointer to lpfc hba data structure.
6792 * This routine is invoked to perform all the necessary post initialization
6793 * setup for the device.
6796 lpfc_post_init_setup(struct lpfc_hba *phba)
6798 struct Scsi_Host *shost;
6799 struct lpfc_adapter_event_header adapter_event;
6801 /* Get the default values for Model Name and Description */
6802 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6805 * hba setup may have changed the hba_queue_depth so we need to
6806 * adjust the value of can_queue.
6808 shost = pci_get_drvdata(phba->pcidev);
6809 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6810 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6811 lpfc_setup_bg(phba, shost);
6813 lpfc_host_attrib_init(shost);
6815 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6816 spin_lock_irq(shost->host_lock);
6817 lpfc_poll_start_timer(phba);
6818 spin_unlock_irq(shost->host_lock);
6821 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6822 "0428 Perform SCSI scan\n");
6823 /* Send board arrival event to upper layer */
6824 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6825 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6826 fc_host_post_vendor_event(shost, fc_get_event_number(),
6827 sizeof(adapter_event),
6828 (char *) &adapter_event,
6834 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6835 * @phba: pointer to lpfc hba data structure.
6837 * This routine is invoked to set up the PCI device memory space for device
6838 * with SLI-3 interface spec.
6842 * other values - error
6845 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6847 struct pci_dev *pdev;
6848 unsigned long bar0map_len, bar2map_len;
6851 int error = -ENODEV;
6853 /* Obtain PCI device reference */
6857 pdev = phba->pcidev;
6859 /* Set the device DMA mask size */
6860 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6861 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6862 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6863 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
6868 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6869 * required by each mapping.
6871 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6872 bar0map_len = pci_resource_len(pdev, 0);
6874 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6875 bar2map_len = pci_resource_len(pdev, 2);
6877 /* Map HBA SLIM to a kernel virtual address. */
6878 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6879 if (!phba->slim_memmap_p) {
6880 dev_printk(KERN_ERR, &pdev->dev,
6881 "ioremap failed for SLIM memory.\n");
6885 /* Map HBA Control Registers to a kernel virtual address. */
6886 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6887 if (!phba->ctrl_regs_memmap_p) {
6888 dev_printk(KERN_ERR, &pdev->dev,
6889 "ioremap failed for HBA control registers.\n");
6890 goto out_iounmap_slim;
6893 /* Allocate memory for SLI-2 structures */
6894 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6895 &phba->slim2p.phys, GFP_KERNEL);
6896 if (!phba->slim2p.virt)
6899 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
6900 phba->mbox_ext = (phba->slim2p.virt +
6901 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
6902 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6903 phba->IOCBs = (phba->slim2p.virt +
6904 offsetof(struct lpfc_sli2_slim, IOCBs));
6906 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6907 lpfc_sli_hbq_size(),
6908 &phba->hbqslimp.phys,
6910 if (!phba->hbqslimp.virt)
6913 hbq_count = lpfc_sli_hbq_count();
6914 ptr = phba->hbqslimp.virt;
6915 for (i = 0; i < hbq_count; ++i) {
6916 phba->hbqs[i].hbq_virt = ptr;
6917 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6918 ptr += (lpfc_hbq_defs[i]->entry_count *
6919 sizeof(struct lpfc_hbq_entry));
6921 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6922 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6924 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6926 phba->MBslimaddr = phba->slim_memmap_p;
6927 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6928 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6929 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6930 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
6935 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6936 phba->slim2p.virt, phba->slim2p.phys);
6938 iounmap(phba->ctrl_regs_memmap_p);
6940 iounmap(phba->slim_memmap_p);
6946 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6947 * @phba: pointer to lpfc hba data structure.
6949 * This routine is invoked to unset the PCI device memory space for device
6950 * with SLI-3 interface spec.
6953 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6955 struct pci_dev *pdev;
6957 /* Obtain PCI device reference */
6961 pdev = phba->pcidev;
6963 /* Free coherent DMA memory allocated */
6964 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6965 phba->hbqslimp.virt, phba->hbqslimp.phys);
6966 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6967 phba->slim2p.virt, phba->slim2p.phys);
6969 /* I/O memory unmap */
6970 iounmap(phba->ctrl_regs_memmap_p);
6971 iounmap(phba->slim_memmap_p);
6977 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6978 * @phba: pointer to lpfc hba data structure.
6980 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6981 * done and check status.
6983 * Return 0 if successful, otherwise -ENODEV.
6986 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6988 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6989 struct lpfc_register reg_data;
6990 int i, port_error = 0;
6993 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6994 memset(®_data, 0, sizeof(reg_data));
6995 if (!phba->sli4_hba.PSMPHRregaddr)
6998 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6999 for (i = 0; i < 3000; i++) {
7000 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7001 &portsmphr_reg.word0) ||
7002 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
7003 /* Port has a fatal POST error, break out */
7004 port_error = -ENODEV;
7007 if (LPFC_POST_STAGE_PORT_READY ==
7008 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
7014 * If there was a port error during POST, then don't proceed with
7015 * other register reads as the data may not be valid. Just exit.
7018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7019 "1408 Port Failed POST - portsmphr=0x%x, "
7020 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7021 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7022 portsmphr_reg.word0,
7023 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7024 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7025 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7026 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7027 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7028 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7029 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7030 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7032 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7033 "2534 Device Info: SLIFamily=0x%x, "
7034 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7035 "SLIHint_2=0x%x, FT=0x%x\n",
7036 bf_get(lpfc_sli_intf_sli_family,
7037 &phba->sli4_hba.sli_intf),
7038 bf_get(lpfc_sli_intf_slirev,
7039 &phba->sli4_hba.sli_intf),
7040 bf_get(lpfc_sli_intf_if_type,
7041 &phba->sli4_hba.sli_intf),
7042 bf_get(lpfc_sli_intf_sli_hint1,
7043 &phba->sli4_hba.sli_intf),
7044 bf_get(lpfc_sli_intf_sli_hint2,
7045 &phba->sli4_hba.sli_intf),
7046 bf_get(lpfc_sli_intf_func_type,
7047 &phba->sli4_hba.sli_intf));
7049 * Check for other Port errors during the initialization
7050 * process. Fail the load if the port did not come up
7053 if_type = bf_get(lpfc_sli_intf_if_type,
7054 &phba->sli4_hba.sli_intf);
7056 case LPFC_SLI_INTF_IF_TYPE_0:
7057 phba->sli4_hba.ue_mask_lo =
7058 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7059 phba->sli4_hba.ue_mask_hi =
7060 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7062 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7064 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7065 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7066 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7068 "1422 Unrecoverable Error "
7069 "Detected during POST "
7070 "uerr_lo_reg=0x%x, "
7071 "uerr_hi_reg=0x%x, "
7072 "ue_mask_lo_reg=0x%x, "
7073 "ue_mask_hi_reg=0x%x\n",
7076 phba->sli4_hba.ue_mask_lo,
7077 phba->sli4_hba.ue_mask_hi);
7078 port_error = -ENODEV;
7081 case LPFC_SLI_INTF_IF_TYPE_2:
7082 /* Final checks. The port status should be clean. */
7083 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7085 (bf_get(lpfc_sliport_status_err, ®_data) &&
7086 !bf_get(lpfc_sliport_status_rn, ®_data))) {
7087 phba->work_status[0] =
7088 readl(phba->sli4_hba.u.if_type2.
7090 phba->work_status[1] =
7091 readl(phba->sli4_hba.u.if_type2.
7093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7094 "2888 Unrecoverable port error "
7095 "following POST: port status reg "
7096 "0x%x, port_smphr reg 0x%x, "
7097 "error 1=0x%x, error 2=0x%x\n",
7099 portsmphr_reg.word0,
7100 phba->work_status[0],
7101 phba->work_status[1]);
7102 port_error = -ENODEV;
7105 case LPFC_SLI_INTF_IF_TYPE_1:
7114 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7115 * @phba: pointer to lpfc hba data structure.
7116 * @if_type: The SLI4 interface type getting configured.
7118 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7122 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
7125 case LPFC_SLI_INTF_IF_TYPE_0:
7126 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7127 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7128 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7129 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7130 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7131 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7132 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7133 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7134 phba->sli4_hba.SLIINTFregaddr =
7135 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7137 case LPFC_SLI_INTF_IF_TYPE_2:
7138 phba->sli4_hba.u.if_type2.ERR1regaddr =
7139 phba->sli4_hba.conf_regs_memmap_p +
7140 LPFC_CTL_PORT_ER1_OFFSET;
7141 phba->sli4_hba.u.if_type2.ERR2regaddr =
7142 phba->sli4_hba.conf_regs_memmap_p +
7143 LPFC_CTL_PORT_ER2_OFFSET;
7144 phba->sli4_hba.u.if_type2.CTRLregaddr =
7145 phba->sli4_hba.conf_regs_memmap_p +
7146 LPFC_CTL_PORT_CTL_OFFSET;
7147 phba->sli4_hba.u.if_type2.STATUSregaddr =
7148 phba->sli4_hba.conf_regs_memmap_p +
7149 LPFC_CTL_PORT_STA_OFFSET;
7150 phba->sli4_hba.SLIINTFregaddr =
7151 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7152 phba->sli4_hba.PSMPHRregaddr =
7153 phba->sli4_hba.conf_regs_memmap_p +
7154 LPFC_CTL_PORT_SEM_OFFSET;
7155 phba->sli4_hba.RQDBregaddr =
7156 phba->sli4_hba.conf_regs_memmap_p +
7157 LPFC_ULP0_RQ_DOORBELL;
7158 phba->sli4_hba.WQDBregaddr =
7159 phba->sli4_hba.conf_regs_memmap_p +
7160 LPFC_ULP0_WQ_DOORBELL;
7161 phba->sli4_hba.EQCQDBregaddr =
7162 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7163 phba->sli4_hba.MQDBregaddr =
7164 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7165 phba->sli4_hba.BMBXregaddr =
7166 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7168 case LPFC_SLI_INTF_IF_TYPE_1:
7170 dev_printk(KERN_ERR, &phba->pcidev->dev,
7171 "FATAL - unsupported SLI4 interface type - %d\n",
7178 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7179 * @phba: pointer to lpfc hba data structure.
7181 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7185 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
7187 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7188 LPFC_SLIPORT_IF0_SMPHR;
7189 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7191 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7193 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7198 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7199 * @phba: pointer to lpfc hba data structure.
7200 * @vf: virtual function number
7202 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7203 * based on the given viftual function number, @vf.
7205 * Return 0 if successful, otherwise -ENODEV.
7208 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7210 if (vf > LPFC_VIR_FUNC_MAX)
7213 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7214 vf * LPFC_VFR_PAGE_SIZE +
7215 LPFC_ULP0_RQ_DOORBELL);
7216 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7217 vf * LPFC_VFR_PAGE_SIZE +
7218 LPFC_ULP0_WQ_DOORBELL);
7219 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7220 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7221 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7222 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7223 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7224 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7229 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7230 * @phba: pointer to lpfc hba data structure.
7232 * This routine is invoked to create the bootstrap mailbox
7233 * region consistent with the SLI-4 interface spec. This
7234 * routine allocates all memory necessary to communicate
7235 * mailbox commands to the port and sets up all alignment
7236 * needs. No locks are expected to be held when calling
7241 * -ENOMEM - could not allocated memory.
7244 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7247 struct lpfc_dmabuf *dmabuf;
7248 struct dma_address *dma_address;
7252 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7257 * The bootstrap mailbox region is comprised of 2 parts
7258 * plus an alignment restriction of 16 bytes.
7260 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
7261 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7262 &dmabuf->phys, GFP_KERNEL);
7263 if (!dmabuf->virt) {
7269 * Initialize the bootstrap mailbox pointers now so that the register
7270 * operations are simple later. The mailbox dma address is required
7271 * to be 16-byte aligned. Also align the virtual memory as each
7272 * maibox is copied into the bmbx mailbox region before issuing the
7273 * command to the port.
7275 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7276 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7278 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7279 LPFC_ALIGN_16_BYTE);
7280 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7281 LPFC_ALIGN_16_BYTE);
7284 * Set the high and low physical addresses now. The SLI4 alignment
7285 * requirement is 16 bytes and the mailbox is posted to the port
7286 * as two 30-bit addresses. The other data is a bit marking whether
7287 * the 30-bit address is the high or low address.
7288 * Upcast bmbx aphys to 64bits so shift instruction compiles
7289 * clean on 32 bit machines.
7291 dma_address = &phba->sli4_hba.bmbx.dma_address;
7292 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7293 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7294 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7295 LPFC_BMBX_BIT1_ADDR_HI);
7297 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7298 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7299 LPFC_BMBX_BIT1_ADDR_LO);
7304 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7305 * @phba: pointer to lpfc hba data structure.
7307 * This routine is invoked to teardown the bootstrap mailbox
7308 * region and release all host resources. This routine requires
7309 * the caller to ensure all mailbox commands recovered, no
7310 * additional mailbox comands are sent, and interrupts are disabled
7311 * before calling this routine.
7315 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7317 dma_free_coherent(&phba->pcidev->dev,
7318 phba->sli4_hba.bmbx.bmbx_size,
7319 phba->sli4_hba.bmbx.dmabuf->virt,
7320 phba->sli4_hba.bmbx.dmabuf->phys);
7322 kfree(phba->sli4_hba.bmbx.dmabuf);
7323 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7327 * lpfc_sli4_read_config - Get the config parameters.
7328 * @phba: pointer to lpfc hba data structure.
7330 * This routine is invoked to read the configuration parameters from the HBA.
7331 * The configuration parameters are used to set the base and maximum values
7332 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7333 * allocation for the port.
7337 * -ENOMEM - No available memory
7338 * -EIO - The mailbox failed to complete successfully.
7341 lpfc_sli4_read_config(struct lpfc_hba *phba)
7344 struct lpfc_mbx_read_config *rd_config;
7345 union lpfc_sli4_cfg_shdr *shdr;
7346 uint32_t shdr_status, shdr_add_status;
7347 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7348 struct lpfc_rsrc_desc_fcfcoe *desc;
7350 uint16_t forced_link_speed;
7352 int length, i, rc = 0, rc2;
7354 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7356 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7357 "2011 Unable to allocate memory for issuing "
7358 "SLI_CONFIG_SPECIAL mailbox command\n");
7362 lpfc_read_config(phba, pmb);
7364 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7365 if (rc != MBX_SUCCESS) {
7366 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7367 "2012 Mailbox failed , mbxCmd x%x "
7368 "READ_CONFIG, mbxStatus x%x\n",
7369 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7370 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7373 rd_config = &pmb->u.mqe.un.rd_config;
7374 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7375 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7376 phba->sli4_hba.lnk_info.lnk_tp =
7377 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7378 phba->sli4_hba.lnk_info.lnk_no =
7379 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7380 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7381 "3081 lnk_type:%d, lnk_numb:%d\n",
7382 phba->sli4_hba.lnk_info.lnk_tp,
7383 phba->sli4_hba.lnk_info.lnk_no);
7385 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7386 "3082 Mailbox (x%x) returned ldv:x0\n",
7387 bf_get(lpfc_mqe_command, &pmb->u.mqe));
7388 phba->sli4_hba.extents_in_use =
7389 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
7390 phba->sli4_hba.max_cfg_param.max_xri =
7391 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7392 phba->sli4_hba.max_cfg_param.xri_base =
7393 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7394 phba->sli4_hba.max_cfg_param.max_vpi =
7395 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7396 phba->sli4_hba.max_cfg_param.vpi_base =
7397 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7398 phba->sli4_hba.max_cfg_param.max_rpi =
7399 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7400 phba->sli4_hba.max_cfg_param.rpi_base =
7401 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7402 phba->sli4_hba.max_cfg_param.max_vfi =
7403 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7404 phba->sli4_hba.max_cfg_param.vfi_base =
7405 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7406 phba->sli4_hba.max_cfg_param.max_fcfi =
7407 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
7408 phba->sli4_hba.max_cfg_param.max_eq =
7409 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7410 phba->sli4_hba.max_cfg_param.max_rq =
7411 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7412 phba->sli4_hba.max_cfg_param.max_wq =
7413 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7414 phba->sli4_hba.max_cfg_param.max_cq =
7415 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7416 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7417 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7418 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7419 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
7420 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7421 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
7422 phba->max_vports = phba->max_vpi;
7423 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7424 "2003 cfg params Extents? %d "
7429 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7430 phba->sli4_hba.extents_in_use,
7431 phba->sli4_hba.max_cfg_param.xri_base,
7432 phba->sli4_hba.max_cfg_param.max_xri,
7433 phba->sli4_hba.max_cfg_param.vpi_base,
7434 phba->sli4_hba.max_cfg_param.max_vpi,
7435 phba->sli4_hba.max_cfg_param.vfi_base,
7436 phba->sli4_hba.max_cfg_param.max_vfi,
7437 phba->sli4_hba.max_cfg_param.rpi_base,
7438 phba->sli4_hba.max_cfg_param.max_rpi,
7439 phba->sli4_hba.max_cfg_param.max_fcfi,
7440 phba->sli4_hba.max_cfg_param.max_eq,
7441 phba->sli4_hba.max_cfg_param.max_cq,
7442 phba->sli4_hba.max_cfg_param.max_wq,
7443 phba->sli4_hba.max_cfg_param.max_rq);
7450 /* Update link speed if forced link speed is supported */
7451 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7452 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7454 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7455 if (forced_link_speed) {
7456 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7458 switch (forced_link_speed) {
7460 phba->cfg_link_speed =
7461 LPFC_USER_LINK_SPEED_1G;
7464 phba->cfg_link_speed =
7465 LPFC_USER_LINK_SPEED_2G;
7468 phba->cfg_link_speed =
7469 LPFC_USER_LINK_SPEED_4G;
7472 phba->cfg_link_speed =
7473 LPFC_USER_LINK_SPEED_8G;
7475 case LINK_SPEED_10G:
7476 phba->cfg_link_speed =
7477 LPFC_USER_LINK_SPEED_10G;
7479 case LINK_SPEED_16G:
7480 phba->cfg_link_speed =
7481 LPFC_USER_LINK_SPEED_16G;
7483 case LINK_SPEED_32G:
7484 phba->cfg_link_speed =
7485 LPFC_USER_LINK_SPEED_32G;
7488 phba->cfg_link_speed =
7489 LPFC_USER_LINK_SPEED_AUTO;
7492 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7493 "0047 Unrecognized link "
7496 phba->cfg_link_speed =
7497 LPFC_USER_LINK_SPEED_AUTO;
7502 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7503 length = phba->sli4_hba.max_cfg_param.max_xri -
7504 lpfc_sli4_get_els_iocb_cnt(phba);
7505 if (phba->cfg_hba_queue_depth > length) {
7506 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7507 "3361 HBA queue depth changed from %d to %d\n",
7508 phba->cfg_hba_queue_depth, length);
7509 phba->cfg_hba_queue_depth = length;
7512 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7513 LPFC_SLI_INTF_IF_TYPE_2)
7516 /* get the pf# and vf# for SLI4 if_type 2 port */
7517 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7518 sizeof(struct lpfc_sli4_cfg_mhdr));
7519 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7520 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7521 length, LPFC_SLI4_MBX_EMBED);
7523 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7524 shdr = (union lpfc_sli4_cfg_shdr *)
7525 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7526 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7527 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7528 if (rc2 || shdr_status || shdr_add_status) {
7529 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7530 "3026 Mailbox failed , mbxCmd x%x "
7531 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7532 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7533 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7537 /* search for fc_fcoe resrouce descriptor */
7538 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
7540 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7541 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7542 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7543 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7544 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7545 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7548 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
7549 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
7550 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
7551 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
7552 phba->sli4_hba.iov.pf_number =
7553 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7554 phba->sli4_hba.iov.vf_number =
7555 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7560 if (i < LPFC_RSRC_DESC_MAX_NUM)
7561 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7562 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7563 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7564 phba->sli4_hba.iov.vf_number);
7566 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7567 "3028 GET_FUNCTION_CONFIG: failed to find "
7568 "Resrouce Descriptor:x%x\n",
7569 LPFC_RSRC_DESC_TYPE_FCFCOE);
7572 mempool_free(pmb, phba->mbox_mem_pool);
7577 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7578 * @phba: pointer to lpfc hba data structure.
7580 * This routine is invoked to setup the port-side endian order when
7581 * the port if_type is 0. This routine has no function for other
7586 * -ENOMEM - No available memory
7587 * -EIO - The mailbox failed to complete successfully.
7590 lpfc_setup_endian_order(struct lpfc_hba *phba)
7592 LPFC_MBOXQ_t *mboxq;
7593 uint32_t if_type, rc = 0;
7594 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7595 HOST_ENDIAN_HIGH_WORD1};
7597 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7599 case LPFC_SLI_INTF_IF_TYPE_0:
7600 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7604 "0492 Unable to allocate memory for "
7605 "issuing SLI_CONFIG_SPECIAL mailbox "
7611 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7612 * two words to contain special data values and no other data.
7614 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7615 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7616 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7617 if (rc != MBX_SUCCESS) {
7618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7619 "0493 SLI_CONFIG_SPECIAL mailbox "
7620 "failed with status x%x\n",
7624 mempool_free(mboxq, phba->mbox_mem_pool);
7626 case LPFC_SLI_INTF_IF_TYPE_2:
7627 case LPFC_SLI_INTF_IF_TYPE_1:
7635 * lpfc_sli4_queue_verify - Verify and update EQ counts
7636 * @phba: pointer to lpfc hba data structure.
7638 * This routine is invoked to check the user settable queue counts for EQs.
7639 * After this routine is called the counts will be set to valid values that
7640 * adhere to the constraints of the system's interrupt vectors and the port's
7645 * -ENOMEM - No available memory
7648 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
7651 int fof_vectors = phba->cfg_fof ? 1 : 0;
7654 * Sanity check for configured queue parameters against the run-time
7658 /* Sanity check on HBA EQ parameters */
7659 io_channel = phba->io_channel_irqs;
7661 if (phba->sli4_hba.num_online_cpu < io_channel) {
7662 lpfc_printf_log(phba,
7664 "3188 Reducing IO channels to match number of "
7665 "online CPUs: from %d to %d\n",
7666 io_channel, phba->sli4_hba.num_online_cpu);
7667 io_channel = phba->sli4_hba.num_online_cpu;
7670 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
7671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7672 "2575 Reducing IO channels to match number of "
7673 "available EQs: from %d to %d\n",
7675 phba->sli4_hba.max_cfg_param.max_eq);
7676 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
7679 /* The actual number of FCP / NVME event queues adopted */
7680 if (io_channel != phba->io_channel_irqs)
7681 phba->io_channel_irqs = io_channel;
7682 if (phba->cfg_fcp_io_channel > io_channel)
7683 phba->cfg_fcp_io_channel = io_channel;
7684 if (phba->cfg_nvme_io_channel > io_channel)
7685 phba->cfg_nvme_io_channel = io_channel;
7686 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
7687 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
7689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7690 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
7691 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
7692 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
7694 /* Get EQ depth from module parameter, fake the default for now */
7695 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7696 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7698 /* Get CQ depth from module parameter, fake the default for now */
7699 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7700 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7705 lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7707 struct lpfc_queue *qdesc;
7710 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7711 phba->sli4_hba.cq_ecount);
7713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7714 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7718 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7720 cnt = LPFC_NVME_WQSIZE;
7721 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7724 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7728 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7729 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7734 lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7736 struct lpfc_queue *qdesc;
7739 /* Create Fast Path FCP CQs */
7740 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7741 phba->sli4_hba.cq_ecount);
7743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7744 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7747 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7749 /* Create Fast Path FCP WQs */
7750 wqesize = (phba->fcp_embed_io) ?
7751 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
7752 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7755 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7759 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7760 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7765 * lpfc_sli4_queue_create - Create all the SLI4 queues
7766 * @phba: pointer to lpfc hba data structure.
7768 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7769 * operation. For each SLI4 queue type, the parameters such as queue entry
7770 * count (queue depth) shall be taken from the module parameter. For now,
7771 * we just use some constant number as place holder.
7775 * -ENOMEM - No availble memory
7776 * -EIO - The mailbox failed to complete successfully.
7779 lpfc_sli4_queue_create(struct lpfc_hba *phba)
7781 struct lpfc_queue *qdesc;
7782 int idx, io_channel, max;
7785 * Create HBA Record arrays.
7786 * Both NVME and FCP will share that same vectors / EQs
7788 io_channel = phba->io_channel_irqs;
7792 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7793 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7794 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7795 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7796 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7797 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7798 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7799 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7800 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7801 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7803 phba->sli4_hba.hba_eq = kcalloc(io_channel,
7804 sizeof(struct lpfc_queue *),
7806 if (!phba->sli4_hba.hba_eq) {
7807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7808 "2576 Failed allocate memory for "
7809 "fast-path EQ record array\n");
7813 if (phba->cfg_fcp_io_channel) {
7814 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
7815 sizeof(struct lpfc_queue *),
7817 if (!phba->sli4_hba.fcp_cq) {
7818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7819 "2577 Failed allocate memory for "
7820 "fast-path CQ record array\n");
7823 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
7824 sizeof(struct lpfc_queue *),
7826 if (!phba->sli4_hba.fcp_wq) {
7827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7828 "2578 Failed allocate memory for "
7829 "fast-path FCP WQ record array\n");
7833 * Since the first EQ can have multiple CQs associated with it,
7834 * this array is used to quickly see if we have a FCP fast-path
7837 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
7840 if (!phba->sli4_hba.fcp_cq_map) {
7841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7842 "2545 Failed allocate memory for "
7843 "fast-path CQ map\n");
7848 if (phba->cfg_nvme_io_channel) {
7849 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
7850 sizeof(struct lpfc_queue *),
7852 if (!phba->sli4_hba.nvme_cq) {
7853 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7854 "6077 Failed allocate memory for "
7855 "fast-path CQ record array\n");
7859 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
7860 sizeof(struct lpfc_queue *),
7862 if (!phba->sli4_hba.nvme_wq) {
7863 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7864 "2581 Failed allocate memory for "
7865 "fast-path NVME WQ record array\n");
7870 * Since the first EQ can have multiple CQs associated with it,
7871 * this array is used to quickly see if we have a NVME fast-path
7874 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
7877 if (!phba->sli4_hba.nvme_cq_map) {
7878 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7879 "6078 Failed allocate memory for "
7880 "fast-path CQ map\n");
7884 if (phba->nvmet_support) {
7885 phba->sli4_hba.nvmet_cqset = kcalloc(
7886 phba->cfg_nvmet_mrq,
7887 sizeof(struct lpfc_queue *),
7889 if (!phba->sli4_hba.nvmet_cqset) {
7890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7891 "3121 Fail allocate memory for "
7892 "fast-path CQ set array\n");
7895 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
7896 phba->cfg_nvmet_mrq,
7897 sizeof(struct lpfc_queue *),
7899 if (!phba->sli4_hba.nvmet_mrq_hdr) {
7900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7901 "3122 Fail allocate memory for "
7902 "fast-path RQ set hdr array\n");
7905 phba->sli4_hba.nvmet_mrq_data = kcalloc(
7906 phba->cfg_nvmet_mrq,
7907 sizeof(struct lpfc_queue *),
7909 if (!phba->sli4_hba.nvmet_mrq_data) {
7910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7911 "3124 Fail allocate memory for "
7912 "fast-path RQ set data array\n");
7918 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
7920 /* Create HBA Event Queues (EQs) */
7921 for (idx = 0; idx < io_channel; idx++) {
7923 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7924 phba->sli4_hba.eq_ecount);
7926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7927 "0497 Failed allocate EQ (%d)\n", idx);
7930 phba->sli4_hba.hba_eq[idx] = qdesc;
7933 /* FCP and NVME io channels are not required to be balanced */
7935 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
7936 if (lpfc_alloc_fcp_wq_cq(phba, idx))
7939 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
7940 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7943 /* allocate MRQ CQs */
7944 max = phba->cfg_nvme_io_channel;
7945 if (max < phba->cfg_nvmet_mrq)
7946 max = phba->cfg_nvmet_mrq;
7948 for (idx = 0; idx < max; idx++)
7949 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7952 if (phba->nvmet_support) {
7953 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
7954 qdesc = lpfc_sli4_queue_alloc(phba,
7955 phba->sli4_hba.cq_esize,
7956 phba->sli4_hba.cq_ecount);
7958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7959 "3142 Failed allocate NVME "
7960 "CQ Set (%d)\n", idx);
7963 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
7968 * Create Slow Path Completion Queues (CQs)
7971 /* Create slow-path Mailbox Command Complete Queue */
7972 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7973 phba->sli4_hba.cq_ecount);
7975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7976 "0500 Failed allocate slow-path mailbox CQ\n");
7979 phba->sli4_hba.mbx_cq = qdesc;
7981 /* Create slow-path ELS Complete Queue */
7982 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7983 phba->sli4_hba.cq_ecount);
7985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7986 "0501 Failed allocate slow-path ELS CQ\n");
7989 phba->sli4_hba.els_cq = qdesc;
7993 * Create Slow Path Work Queues (WQs)
7996 /* Create Mailbox Command Queue */
7998 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7999 phba->sli4_hba.mq_ecount);
8001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8002 "0505 Failed allocate slow-path MQ\n");
8005 phba->sli4_hba.mbx_wq = qdesc;
8008 * Create ELS Work Queues
8011 /* Create slow-path ELS Work Queue */
8012 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8013 phba->sli4_hba.wq_ecount);
8015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8016 "0504 Failed allocate slow-path ELS WQ\n");
8019 phba->sli4_hba.els_wq = qdesc;
8020 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8022 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8023 /* Create NVME LS Complete Queue */
8024 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8025 phba->sli4_hba.cq_ecount);
8027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8028 "6079 Failed allocate NVME LS CQ\n");
8031 phba->sli4_hba.nvmels_cq = qdesc;
8033 /* Create NVME LS Work Queue */
8034 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8035 phba->sli4_hba.wq_ecount);
8037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8038 "6080 Failed allocate NVME LS WQ\n");
8041 phba->sli4_hba.nvmels_wq = qdesc;
8042 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8046 * Create Receive Queue (RQ)
8049 /* Create Receive Queue for header */
8050 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8051 phba->sli4_hba.rq_ecount);
8053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8054 "0506 Failed allocate receive HRQ\n");
8057 phba->sli4_hba.hdr_rq = qdesc;
8059 /* Create Receive Queue for data */
8060 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8061 phba->sli4_hba.rq_ecount);
8063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8064 "0507 Failed allocate receive DRQ\n");
8067 phba->sli4_hba.dat_rq = qdesc;
8069 if (phba->nvmet_support) {
8070 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8071 /* Create NVMET Receive Queue for header */
8072 qdesc = lpfc_sli4_queue_alloc(phba,
8073 phba->sli4_hba.rq_esize,
8074 phba->sli4_hba.rq_ecount);
8076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8077 "3146 Failed allocate "
8081 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8083 /* Only needed for header of RQ pair */
8084 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8086 if (qdesc->rqbp == NULL) {
8087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8088 "6131 Failed allocate "
8093 /* Create NVMET Receive Queue for data */
8094 qdesc = lpfc_sli4_queue_alloc(phba,
8095 phba->sli4_hba.rq_esize,
8096 phba->sli4_hba.rq_ecount);
8098 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8099 "3156 Failed allocate "
8103 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8107 /* Create the Queues needed for Flash Optimized Fabric operations */
8109 lpfc_fof_queue_create(phba);
8113 lpfc_sli4_queue_destroy(phba);
8118 __lpfc_sli4_release_queue(struct lpfc_queue **qp)
8121 lpfc_sli4_queue_free(*qp);
8127 lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8134 for (idx = 0; idx < max; idx++)
8135 __lpfc_sli4_release_queue(&(*qs)[idx]);
8142 lpfc_sli4_release_queue_map(uint16_t **qmap)
8144 if (*qmap != NULL) {
8151 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8152 * @phba: pointer to lpfc hba data structure.
8154 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8159 * -ENOMEM - No available memory
8160 * -EIO - The mailbox failed to complete successfully.
8163 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8166 lpfc_fof_queue_destroy(phba);
8168 /* Release HBA eqs */
8169 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
8171 /* Release FCP cqs */
8172 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
8173 phba->cfg_fcp_io_channel);
8175 /* Release FCP wqs */
8176 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
8177 phba->cfg_fcp_io_channel);
8179 /* Release FCP CQ mapping array */
8180 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8182 /* Release NVME cqs */
8183 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8184 phba->cfg_nvme_io_channel);
8186 /* Release NVME wqs */
8187 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8188 phba->cfg_nvme_io_channel);
8190 /* Release NVME CQ mapping array */
8191 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
8193 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8194 phba->cfg_nvmet_mrq);
8196 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8197 phba->cfg_nvmet_mrq);
8198 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8199 phba->cfg_nvmet_mrq);
8201 /* Release mailbox command work queue */
8202 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
8204 /* Release ELS work queue */
8205 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8207 /* Release ELS work queue */
8208 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
8210 /* Release unsolicited receive queue */
8211 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8212 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
8214 /* Release ELS complete queue */
8215 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8217 /* Release NVME LS complete queue */
8218 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
8220 /* Release mailbox command complete queue */
8221 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8223 /* Everything on this list has been freed */
8224 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8228 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
8229 struct lpfc_queue *drq, int count)
8232 struct lpfc_rqe hrqe;
8233 struct lpfc_rqe drqe;
8234 struct lpfc_rqb *rqbp;
8235 struct rqb_dmabuf *rqb_buffer;
8236 LIST_HEAD(rqb_buf_list);
8239 for (i = 0; i < count; i++) {
8240 rqb_buffer = (rqbp->rqb_alloc_buffer)(phba);
8243 rqb_buffer->hrq = hrq;
8244 rqb_buffer->drq = drq;
8245 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
8247 while (!list_empty(&rqb_buf_list)) {
8248 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
8251 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
8252 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
8253 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
8254 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
8255 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
8257 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8259 list_add_tail(&rqb_buffer->hbuf.list,
8260 &rqbp->rqb_buffer_list);
8261 rqbp->buffer_count++;
8268 lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8270 struct lpfc_rqb *rqbp;
8271 struct lpfc_dmabuf *h_buf;
8272 struct rqb_dmabuf *rqb_buffer;
8275 while (!list_empty(&rqbp->rqb_buffer_list)) {
8276 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8277 struct lpfc_dmabuf, list);
8279 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8280 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8281 rqbp->buffer_count--;
8287 lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8288 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8289 int qidx, uint32_t qtype)
8291 struct lpfc_sli_ring *pring;
8294 if (!eq || !cq || !wq) {
8295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8296 "6085 Fast-path %s (%d) not allocated\n",
8297 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8301 /* create the Cq first */
8302 rc = lpfc_cq_create(phba, cq, eq,
8303 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8306 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8307 qidx, (uint32_t)rc);
8311 if (qtype != LPFC_MBOX) {
8312 /* Setup nvme_cq_map for fast lookup */
8314 *cq_map = cq->queue_id;
8316 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8317 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8318 qidx, cq->queue_id, qidx, eq->queue_id);
8321 rc = lpfc_wq_create(phba, wq, cq, qtype);
8323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8324 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8325 qidx, (uint32_t)rc);
8326 /* no need to tear down cq - caller will do so */
8330 /* Bind this CQ/WQ to the NVME ring */
8332 pring->sli.sli4.wqp = (void *)wq;
8335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8336 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8337 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8339 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8341 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8342 "0539 Failed setup of slow-path MQ: "
8344 /* no need to tear down cq - caller will do so */
8348 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8349 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8350 phba->sli4_hba.mbx_wq->queue_id,
8351 phba->sli4_hba.mbx_cq->queue_id);
8358 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8359 * @phba: pointer to lpfc hba data structure.
8361 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8366 * -ENOMEM - No available memory
8367 * -EIO - The mailbox failed to complete successfully.
8370 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8372 uint32_t shdr_status, shdr_add_status;
8373 union lpfc_sli4_cfg_shdr *shdr;
8374 LPFC_MBOXQ_t *mboxq;
8376 uint32_t length, io_channel;
8379 /* Check for dual-ULP support */
8380 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8383 "3249 Unable to allocate memory for "
8384 "QUERY_FW_CFG mailbox command\n");
8387 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8388 sizeof(struct lpfc_sli4_cfg_mhdr));
8389 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8390 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8391 length, LPFC_SLI4_MBX_EMBED);
8393 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8395 shdr = (union lpfc_sli4_cfg_shdr *)
8396 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8397 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8398 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8399 if (shdr_status || shdr_add_status || rc) {
8400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8401 "3250 QUERY_FW_CFG mailbox failed with status "
8402 "x%x add_status x%x, mbx status x%x\n",
8403 shdr_status, shdr_add_status, rc);
8404 if (rc != MBX_TIMEOUT)
8405 mempool_free(mboxq, phba->mbox_mem_pool);
8410 phba->sli4_hba.fw_func_mode =
8411 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8412 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8413 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
8414 phba->sli4_hba.physical_port =
8415 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
8416 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8417 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8418 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8419 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8421 if (rc != MBX_TIMEOUT)
8422 mempool_free(mboxq, phba->mbox_mem_pool);
8425 * Set up HBA Event Queues (EQs)
8427 io_channel = phba->io_channel_irqs;
8429 /* Set up HBA event queue */
8430 if (io_channel && !phba->sli4_hba.hba_eq) {
8431 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8432 "3147 Fast-path EQs not allocated\n");
8436 for (qidx = 0; qidx < io_channel; qidx++) {
8437 if (!phba->sli4_hba.hba_eq[qidx]) {
8438 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8439 "0522 Fast-path EQ (%d) not "
8440 "allocated\n", qidx);
8444 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8445 phba->cfg_fcp_imax);
8447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8448 "0523 Failed setup of fast-path EQ "
8449 "(%d), rc = 0x%x\n", qidx,
8453 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8454 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8455 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
8458 if (phba->cfg_nvme_io_channel) {
8459 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
8460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8461 "6084 Fast-path NVME %s array not allocated\n",
8462 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
8467 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8468 rc = lpfc_create_wq_cq(phba,
8469 phba->sli4_hba.hba_eq[
8471 phba->sli4_hba.nvme_cq[qidx],
8472 phba->sli4_hba.nvme_wq[qidx],
8473 &phba->sli4_hba.nvme_cq_map[qidx],
8476 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8477 "6123 Failed to setup fastpath "
8478 "NVME WQ/CQ (%d), rc = 0x%x\n",
8479 qidx, (uint32_t)rc);
8485 if (phba->cfg_fcp_io_channel) {
8486 /* Set up fast-path FCP Response Complete Queue */
8487 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
8488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8489 "3148 Fast-path FCP %s array not allocated\n",
8490 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
8495 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8496 rc = lpfc_create_wq_cq(phba,
8497 phba->sli4_hba.hba_eq[
8499 phba->sli4_hba.fcp_cq[qidx],
8500 phba->sli4_hba.fcp_wq[qidx],
8501 &phba->sli4_hba.fcp_cq_map[qidx],
8504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8505 "0535 Failed to setup fastpath "
8506 "FCP WQ/CQ (%d), rc = 0x%x\n",
8507 qidx, (uint32_t)rc);
8514 * Set up Slow Path Complete Queues (CQs)
8517 /* Set up slow-path MBOX CQ/MQ */
8519 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
8520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8521 "0528 %s not allocated\n",
8522 phba->sli4_hba.mbx_cq ?
8523 "Mailbox WQ" : "Mailbox CQ");
8528 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8529 phba->sli4_hba.mbx_cq,
8530 phba->sli4_hba.mbx_wq,
8531 NULL, 0, LPFC_MBOX);
8533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8534 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8538 if (phba->nvmet_support) {
8539 if (!phba->sli4_hba.nvmet_cqset) {
8540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8541 "3165 Fast-path NVME CQ Set "
8542 "array not allocated\n");
8546 if (phba->cfg_nvmet_mrq > 1) {
8547 rc = lpfc_cq_create_set(phba,
8548 phba->sli4_hba.nvmet_cqset,
8549 phba->sli4_hba.hba_eq,
8550 LPFC_WCQ, LPFC_NVMET);
8552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8553 "3164 Failed setup of NVME CQ "
8559 /* Set up NVMET Receive Complete Queue */
8560 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8561 phba->sli4_hba.hba_eq[0],
8562 LPFC_WCQ, LPFC_NVMET);
8564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8565 "6089 Failed setup NVMET CQ: "
8566 "rc = 0x%x\n", (uint32_t)rc);
8569 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8570 "6090 NVMET CQ setup: cq-id=%d, "
8571 "parent eq-id=%d\n",
8572 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8573 phba->sli4_hba.hba_eq[0]->queue_id);
8577 /* Set up slow-path ELS WQ/CQ */
8578 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
8579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8580 "0530 ELS %s not allocated\n",
8581 phba->sli4_hba.els_cq ? "WQ" : "CQ");
8585 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8586 phba->sli4_hba.els_cq,
8587 phba->sli4_hba.els_wq,
8590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8591 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8596 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8597 phba->sli4_hba.els_wq->queue_id,
8598 phba->sli4_hba.els_cq->queue_id);
8600 if (phba->cfg_nvme_io_channel) {
8601 /* Set up NVME LS Complete Queue */
8602 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8604 "6091 LS %s not allocated\n",
8605 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8609 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8610 phba->sli4_hba.nvmels_cq,
8611 phba->sli4_hba.nvmels_wq,
8612 NULL, 0, LPFC_NVME_LS);
8614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8615 "0529 Failed setup of NVVME LS WQ/CQ: "
8616 "rc = 0x%x\n", (uint32_t)rc);
8620 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8621 "6096 ELS WQ setup: wq-id=%d, "
8622 "parent cq-id=%d\n",
8623 phba->sli4_hba.nvmels_wq->queue_id,
8624 phba->sli4_hba.nvmels_cq->queue_id);
8628 * Create NVMET Receive Queue (RQ)
8630 if (phba->nvmet_support) {
8631 if ((!phba->sli4_hba.nvmet_cqset) ||
8632 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8633 (!phba->sli4_hba.nvmet_mrq_data)) {
8634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8635 "6130 MRQ CQ Queues not "
8640 if (phba->cfg_nvmet_mrq > 1) {
8641 rc = lpfc_mrq_create(phba,
8642 phba->sli4_hba.nvmet_mrq_hdr,
8643 phba->sli4_hba.nvmet_mrq_data,
8644 phba->sli4_hba.nvmet_cqset,
8647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8648 "6098 Failed setup of NVMET "
8655 rc = lpfc_rq_create(phba,
8656 phba->sli4_hba.nvmet_mrq_hdr[0],
8657 phba->sli4_hba.nvmet_mrq_data[0],
8658 phba->sli4_hba.nvmet_cqset[0],
8661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8662 "6057 Failed setup of NVMET "
8663 "Receive Queue: rc = 0x%x\n",
8669 phba, KERN_INFO, LOG_INIT,
8670 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8671 "dat-rq-id=%d parent cq-id=%d\n",
8672 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
8673 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
8674 phba->sli4_hba.nvmet_cqset[0]->queue_id);
8679 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8681 "0540 Receive Queue not allocated\n");
8686 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
8687 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
8689 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
8690 phba->sli4_hba.els_cq, LPFC_USOL);
8692 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8693 "0541 Failed setup of Receive Queue: "
8694 "rc = 0x%x\n", (uint32_t)rc);
8698 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8699 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8700 "parent cq-id=%d\n",
8701 phba->sli4_hba.hdr_rq->queue_id,
8702 phba->sli4_hba.dat_rq->queue_id,
8703 phba->sli4_hba.els_cq->queue_id);
8705 if (phba->cfg_fof) {
8706 rc = lpfc_fof_queue_setup(phba);
8708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8709 "0549 Failed setup of FOF Queues: "
8716 * Configure EQ delay multipier for interrupt coalescing using
8717 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8719 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY)
8720 lpfc_modify_hba_eq_delay(phba, qidx);
8724 lpfc_sli4_queue_unset(phba);
8730 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8731 * @phba: pointer to lpfc hba data structure.
8733 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8738 * -ENOMEM - No available memory
8739 * -EIO - The mailbox failed to complete successfully.
8742 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8746 /* Unset the queues created for Flash Optimized Fabric operations */
8748 lpfc_fof_queue_destroy(phba);
8750 /* Unset mailbox command work queue */
8751 if (phba->sli4_hba.mbx_wq)
8752 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8754 /* Unset NVME LS work queue */
8755 if (phba->sli4_hba.nvmels_wq)
8756 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8758 /* Unset ELS work queue */
8759 if (phba->sli4_hba.els_cq)
8760 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8762 /* Unset unsolicited receive queue */
8763 if (phba->sli4_hba.hdr_rq)
8764 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8765 phba->sli4_hba.dat_rq);
8767 /* Unset FCP work queue */
8768 if (phba->sli4_hba.fcp_wq)
8769 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8770 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8772 /* Unset NVME work queue */
8773 if (phba->sli4_hba.nvme_wq) {
8774 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8775 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
8778 /* Unset mailbox command complete queue */
8779 if (phba->sli4_hba.mbx_cq)
8780 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8782 /* Unset ELS complete queue */
8783 if (phba->sli4_hba.els_cq)
8784 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8786 /* Unset NVME LS complete queue */
8787 if (phba->sli4_hba.nvmels_cq)
8788 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8790 /* Unset NVME response complete queue */
8791 if (phba->sli4_hba.nvme_cq)
8792 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8793 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8795 /* Unset NVMET MRQ queue */
8796 if (phba->sli4_hba.nvmet_mrq_hdr) {
8797 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8798 lpfc_rq_destroy(phba,
8799 phba->sli4_hba.nvmet_mrq_hdr[qidx],
8800 phba->sli4_hba.nvmet_mrq_data[qidx]);
8803 /* Unset NVMET CQ Set complete queue */
8804 if (phba->sli4_hba.nvmet_cqset) {
8805 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8806 lpfc_cq_destroy(phba,
8807 phba->sli4_hba.nvmet_cqset[qidx]);
8810 /* Unset FCP response complete queue */
8811 if (phba->sli4_hba.fcp_cq)
8812 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8813 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8815 /* Unset fast-path event queue */
8816 if (phba->sli4_hba.hba_eq)
8817 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8818 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
8822 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8823 * @phba: pointer to lpfc hba data structure.
8825 * This routine is invoked to allocate and set up a pool of completion queue
8826 * events. The body of the completion queue event is a completion queue entry
8827 * CQE. For now, this pool is used for the interrupt service routine to queue
8828 * the following HBA completion queue events for the worker thread to process:
8829 * - Mailbox asynchronous events
8830 * - Receive queue completion unsolicited events
8831 * Later, this can be used for all the slow-path events.
8835 * -ENOMEM - No available memory
8838 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
8840 struct lpfc_cq_event *cq_event;
8843 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
8844 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
8846 goto out_pool_create_fail;
8847 list_add_tail(&cq_event->list,
8848 &phba->sli4_hba.sp_cqe_event_pool);
8852 out_pool_create_fail:
8853 lpfc_sli4_cq_event_pool_destroy(phba);
8858 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8859 * @phba: pointer to lpfc hba data structure.
8861 * This routine is invoked to free the pool of completion queue events at
8862 * driver unload time. Note that, it is the responsibility of the driver
8863 * cleanup routine to free all the outstanding completion-queue events
8864 * allocated from this pool back into the pool before invoking this routine
8865 * to destroy the pool.
8868 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8870 struct lpfc_cq_event *cq_event, *next_cq_event;
8872 list_for_each_entry_safe(cq_event, next_cq_event,
8873 &phba->sli4_hba.sp_cqe_event_pool, list) {
8874 list_del(&cq_event->list);
8880 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8881 * @phba: pointer to lpfc hba data structure.
8883 * This routine is the lock free version of the API invoked to allocate a
8884 * completion-queue event from the free pool.
8886 * Return: Pointer to the newly allocated completion-queue event if successful
8889 struct lpfc_cq_event *
8890 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8892 struct lpfc_cq_event *cq_event = NULL;
8894 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8895 struct lpfc_cq_event, list);
8900 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8901 * @phba: pointer to lpfc hba data structure.
8903 * This routine is the lock version of the API invoked to allocate a
8904 * completion-queue event from the free pool.
8906 * Return: Pointer to the newly allocated completion-queue event if successful
8909 struct lpfc_cq_event *
8910 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8912 struct lpfc_cq_event *cq_event;
8913 unsigned long iflags;
8915 spin_lock_irqsave(&phba->hbalock, iflags);
8916 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8917 spin_unlock_irqrestore(&phba->hbalock, iflags);
8922 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8923 * @phba: pointer to lpfc hba data structure.
8924 * @cq_event: pointer to the completion queue event to be freed.
8926 * This routine is the lock free version of the API invoked to release a
8927 * completion-queue event back into the free pool.
8930 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8931 struct lpfc_cq_event *cq_event)
8933 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8937 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8938 * @phba: pointer to lpfc hba data structure.
8939 * @cq_event: pointer to the completion queue event to be freed.
8941 * This routine is the lock version of the API invoked to release a
8942 * completion-queue event back into the free pool.
8945 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8946 struct lpfc_cq_event *cq_event)
8948 unsigned long iflags;
8949 spin_lock_irqsave(&phba->hbalock, iflags);
8950 __lpfc_sli4_cq_event_release(phba, cq_event);
8951 spin_unlock_irqrestore(&phba->hbalock, iflags);
8955 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8956 * @phba: pointer to lpfc hba data structure.
8958 * This routine is to free all the pending completion-queue events to the
8959 * back into the free pool for device reset.
8962 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8965 struct lpfc_cq_event *cqe;
8966 unsigned long iflags;
8968 /* Retrieve all the pending WCQEs from pending WCQE lists */
8969 spin_lock_irqsave(&phba->hbalock, iflags);
8970 /* Pending FCP XRI abort events */
8971 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8973 /* Pending ELS XRI abort events */
8974 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8976 /* Pending asynnc events */
8977 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8979 spin_unlock_irqrestore(&phba->hbalock, iflags);
8981 while (!list_empty(&cqelist)) {
8982 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8983 lpfc_sli4_cq_event_release(phba, cqe);
8988 * lpfc_pci_function_reset - Reset pci function.
8989 * @phba: pointer to lpfc hba data structure.
8991 * This routine is invoked to request a PCI function reset. It will destroys
8992 * all resources assigned to the PCI function which originates this request.
8996 * -ENOMEM - No available memory
8997 * -EIO - The mailbox failed to complete successfully.
9000 lpfc_pci_function_reset(struct lpfc_hba *phba)
9002 LPFC_MBOXQ_t *mboxq;
9003 uint32_t rc = 0, if_type;
9004 uint32_t shdr_status, shdr_add_status;
9006 uint32_t port_reset = 0;
9007 union lpfc_sli4_cfg_shdr *shdr;
9008 struct lpfc_register reg_data;
9011 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9013 case LPFC_SLI_INTF_IF_TYPE_0:
9014 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9018 "0494 Unable to allocate memory for "
9019 "issuing SLI_FUNCTION_RESET mailbox "
9024 /* Setup PCI function reset mailbox-ioctl command */
9025 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9026 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9027 LPFC_SLI4_MBX_EMBED);
9028 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9029 shdr = (union lpfc_sli4_cfg_shdr *)
9030 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9031 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9032 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9034 if (rc != MBX_TIMEOUT)
9035 mempool_free(mboxq, phba->mbox_mem_pool);
9036 if (shdr_status || shdr_add_status || rc) {
9037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9038 "0495 SLI_FUNCTION_RESET mailbox "
9039 "failed with status x%x add_status x%x,"
9040 " mbx status x%x\n",
9041 shdr_status, shdr_add_status, rc);
9045 case LPFC_SLI_INTF_IF_TYPE_2:
9048 * Poll the Port Status Register and wait for RDY for
9049 * up to 30 seconds. If the port doesn't respond, treat
9052 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
9053 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9054 STATUSregaddr, ®_data.word0)) {
9058 if (bf_get(lpfc_sliport_status_rdy, ®_data))
9063 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
9064 phba->work_status[0] = readl(
9065 phba->sli4_hba.u.if_type2.ERR1regaddr);
9066 phba->work_status[1] = readl(
9067 phba->sli4_hba.u.if_type2.ERR2regaddr);
9068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9069 "2890 Port not ready, port status reg "
9070 "0x%x error 1=0x%x, error 2=0x%x\n",
9072 phba->work_status[0],
9073 phba->work_status[1]);
9080 * Reset the port now
9083 bf_set(lpfc_sliport_ctrl_end, ®_data,
9084 LPFC_SLIPORT_LITTLE_ENDIAN);
9085 bf_set(lpfc_sliport_ctrl_ip, ®_data,
9086 LPFC_SLIPORT_INIT_PORT);
9087 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9090 pci_read_config_word(phba->pcidev,
9091 PCI_DEVICE_ID, &devid);
9096 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
9102 case LPFC_SLI_INTF_IF_TYPE_1:
9108 /* Catch the not-ready port failure after a port reset. */
9110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9111 "3317 HBA not functional: IP Reset Failed "
9112 "try: echo fw_reset > board_mode\n");
9120 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9121 * @phba: pointer to lpfc hba data structure.
9123 * This routine is invoked to set up the PCI device memory space for device
9124 * with SLI-4 interface spec.
9128 * other values - error
9131 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9133 struct pci_dev *pdev;
9134 unsigned long bar0map_len, bar1map_len, bar2map_len;
9135 int error = -ENODEV;
9138 /* Obtain PCI device reference */
9142 pdev = phba->pcidev;
9144 /* Set the device DMA mask size */
9145 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9146 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9147 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9148 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
9154 * The BARs and register set definitions and offset locations are
9155 * dependent on the if_type.
9157 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9158 &phba->sli4_hba.sli_intf.word0)) {
9162 /* There is no SLI3 failback for SLI4 devices. */
9163 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9164 LPFC_SLI_INTF_VALID) {
9165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9166 "2894 SLI_INTF reg contents invalid "
9167 "sli_intf reg 0x%x\n",
9168 phba->sli4_hba.sli_intf.word0);
9172 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9174 * Get the bus address of SLI4 device Bar regions and the
9175 * number of bytes required by each mapping. The mapping of the
9176 * particular PCI BARs regions is dependent on the type of
9179 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9180 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9181 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
9184 * Map SLI4 PCI Config Space Register base to a kernel virtual
9187 phba->sli4_hba.conf_regs_memmap_p =
9188 ioremap(phba->pci_bar0_map, bar0map_len);
9189 if (!phba->sli4_hba.conf_regs_memmap_p) {
9190 dev_printk(KERN_ERR, &pdev->dev,
9191 "ioremap failed for SLI4 PCI config "
9195 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
9196 /* Set up BAR0 PCI config space register memory map */
9197 lpfc_sli4_bar0_register_memmap(phba, if_type);
9199 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9200 bar0map_len = pci_resource_len(pdev, 1);
9201 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
9202 dev_printk(KERN_ERR, &pdev->dev,
9203 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9206 phba->sli4_hba.conf_regs_memmap_p =
9207 ioremap(phba->pci_bar0_map, bar0map_len);
9208 if (!phba->sli4_hba.conf_regs_memmap_p) {
9209 dev_printk(KERN_ERR, &pdev->dev,
9210 "ioremap failed for SLI4 PCI config "
9214 lpfc_sli4_bar0_register_memmap(phba, if_type);
9217 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
9218 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9220 * Map SLI4 if type 0 HBA Control Register base to a kernel
9221 * virtual address and setup the registers.
9223 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9224 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9225 phba->sli4_hba.ctrl_regs_memmap_p =
9226 ioremap(phba->pci_bar1_map, bar1map_len);
9227 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9228 dev_printk(KERN_ERR, &pdev->dev,
9229 "ioremap failed for SLI4 HBA control registers.\n");
9230 goto out_iounmap_conf;
9232 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
9233 lpfc_sli4_bar1_register_memmap(phba);
9236 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
9237 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
9239 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
9240 * virtual address and setup the registers.
9242 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9243 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9244 phba->sli4_hba.drbl_regs_memmap_p =
9245 ioremap(phba->pci_bar2_map, bar2map_len);
9246 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9247 dev_printk(KERN_ERR, &pdev->dev,
9248 "ioremap failed for SLI4 HBA doorbell registers.\n");
9249 goto out_iounmap_ctrl;
9251 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9252 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9254 goto out_iounmap_all;
9260 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9262 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9264 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9270 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9271 * @phba: pointer to lpfc hba data structure.
9273 * This routine is invoked to unset the PCI device memory space for device
9274 * with SLI-4 interface spec.
9277 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9280 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9283 case LPFC_SLI_INTF_IF_TYPE_0:
9284 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9285 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9286 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9288 case LPFC_SLI_INTF_IF_TYPE_2:
9289 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9291 case LPFC_SLI_INTF_IF_TYPE_1:
9293 dev_printk(KERN_ERR, &phba->pcidev->dev,
9294 "FATAL - unsupported SLI4 interface type - %d\n",
9301 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9302 * @phba: pointer to lpfc hba data structure.
9304 * This routine is invoked to enable the MSI-X interrupt vectors to device
9305 * with SLI-3 interface specs.
9309 * other values - error
9312 lpfc_sli_enable_msix(struct lpfc_hba *phba)
9317 /* Set up MSI-X multi-message vectors */
9318 rc = pci_alloc_irq_vectors(phba->pcidev,
9319 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9321 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9322 "0420 PCI enable MSI-X failed (%d)\n", rc);
9327 * Assign MSI-X vectors to interrupt handlers
9330 /* vector-0 is associated to slow-path handler */
9331 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
9332 &lpfc_sli_sp_intr_handler, 0,
9333 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9335 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9336 "0421 MSI-X slow-path request_irq failed "
9341 /* vector-1 is associated to fast-path handler */
9342 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
9343 &lpfc_sli_fp_intr_handler, 0,
9344 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9347 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9348 "0429 MSI-X fast-path request_irq failed "
9354 * Configure HBA MSI-X attention conditions to messages
9356 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9361 "0474 Unable to allocate memory for issuing "
9362 "MBOX_CONFIG_MSI command\n");
9365 rc = lpfc_config_msi(phba, pmb);
9368 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9369 if (rc != MBX_SUCCESS) {
9370 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9371 "0351 Config MSI mailbox command failed, "
9372 "mbxCmd x%x, mbxStatus x%x\n",
9373 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9377 /* Free memory allocated for mailbox command */
9378 mempool_free(pmb, phba->mbox_mem_pool);
9382 /* Free memory allocated for mailbox command */
9383 mempool_free(pmb, phba->mbox_mem_pool);
9386 /* free the irq already requested */
9387 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
9390 /* free the irq already requested */
9391 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
9394 /* Unconfigure MSI-X capability structure */
9395 pci_free_irq_vectors(phba->pcidev);
9402 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9403 * @phba: pointer to lpfc hba data structure.
9405 * This routine is invoked to enable the MSI interrupt mode to device with
9406 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9407 * enable the MSI vector. The device driver is responsible for calling the
9408 * request_irq() to register MSI vector with a interrupt the handler, which
9409 * is done in this function.
9413 * other values - error
9416 lpfc_sli_enable_msi(struct lpfc_hba *phba)
9420 rc = pci_enable_msi(phba->pcidev);
9422 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9423 "0462 PCI enable MSI mode success.\n");
9425 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9426 "0471 PCI enable MSI mode failed (%d)\n", rc);
9430 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9431 0, LPFC_DRIVER_NAME, phba);
9433 pci_disable_msi(phba->pcidev);
9434 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9435 "0478 MSI request_irq failed (%d)\n", rc);
9441 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9442 * @phba: pointer to lpfc hba data structure.
9444 * This routine is invoked to enable device interrupt and associate driver's
9445 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9446 * spec. Depends on the interrupt mode configured to the driver, the driver
9447 * will try to fallback from the configured interrupt mode to an interrupt
9448 * mode which is supported by the platform, kernel, and device in the order
9450 * MSI-X -> MSI -> IRQ.
9454 * other values - error
9457 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9459 uint32_t intr_mode = LPFC_INTR_ERROR;
9462 if (cfg_mode == 2) {
9463 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9464 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9466 /* Now, try to enable MSI-X interrupt mode */
9467 retval = lpfc_sli_enable_msix(phba);
9469 /* Indicate initialization to MSI-X mode */
9470 phba->intr_type = MSIX;
9476 /* Fallback to MSI if MSI-X initialization failed */
9477 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9478 retval = lpfc_sli_enable_msi(phba);
9480 /* Indicate initialization to MSI mode */
9481 phba->intr_type = MSI;
9486 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9487 if (phba->intr_type == NONE) {
9488 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9489 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9491 /* Indicate initialization to INTx mode */
9492 phba->intr_type = INTx;
9500 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9501 * @phba: pointer to lpfc hba data structure.
9503 * This routine is invoked to disable device interrupt and disassociate the
9504 * driver's interrupt handler(s) from interrupt vector(s) to device with
9505 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9506 * release the interrupt vector(s) for the message signaled interrupt.
9509 lpfc_sli_disable_intr(struct lpfc_hba *phba)
9513 if (phba->intr_type == MSIX)
9514 nr_irqs = LPFC_MSIX_VECTORS;
9518 for (i = 0; i < nr_irqs; i++)
9519 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9520 pci_free_irq_vectors(phba->pcidev);
9522 /* Reset interrupt management states */
9523 phba->intr_type = NONE;
9524 phba->sli.slistat.sli_intr = 0;
9528 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
9529 * @phba: pointer to lpfc hba data structure.
9530 * @vectors: number of msix vectors allocated.
9532 * The routine will figure out the CPU affinity assignment for every
9533 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9534 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9535 * can be associated with. If the vector can be unquely associated with
9536 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9537 * In addition, the CPU to IO channel mapping will be calculated
9538 * and the phba->sli4_hba.cpu_map array will reflect this.
9541 lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
9543 struct lpfc_vector_map_info *cpup;
9548 struct cpuinfo_x86 *cpuinfo;
9551 /* Init cpu_map array */
9552 memset(phba->sli4_hba.cpu_map, 0xff,
9553 (sizeof(struct lpfc_vector_map_info) *
9554 phba->sli4_hba.num_present_cpu));
9556 /* Update CPU map with physical id and core id of each CPU */
9557 cpup = phba->sli4_hba.cpu_map;
9558 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9560 cpuinfo = &cpu_data(cpu);
9561 cpup->phys_id = cpuinfo->phys_proc_id;
9562 cpup->core_id = cpuinfo->cpu_core_id;
9564 /* No distinction between CPUs for other platforms */
9568 cpup->channel_id = index; /* For now round robin */
9569 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9574 if (index >= phba->cfg_fcp_io_channel)
9582 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9583 * @phba: pointer to lpfc hba data structure.
9585 * This routine is invoked to enable the MSI-X interrupt vectors to device
9586 * with SLI-4 interface spec.
9590 * other values - error
9593 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9595 int vectors, rc, index;
9597 /* Set up MSI-X multi-message vectors */
9598 vectors = phba->io_channel_irqs;
9602 rc = pci_alloc_irq_vectors(phba->pcidev,
9603 (phba->nvmet_support) ? 1 : 2,
9604 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
9606 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9607 "0484 PCI enable MSI-X failed (%d)\n", rc);
9612 /* Assign MSI-X vectors to interrupt handlers */
9613 for (index = 0; index < vectors; index++) {
9614 memset(&phba->sli4_hba.handler_name[index], 0, 16);
9615 snprintf((char *)&phba->sli4_hba.handler_name[index],
9616 LPFC_SLI4_HANDLER_NAME_SZ,
9617 LPFC_DRIVER_HANDLER_NAME"%d", index);
9619 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9620 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9621 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
9622 if (phba->cfg_fof && (index == (vectors - 1)))
9623 rc = request_irq(pci_irq_vector(phba->pcidev, index),
9624 &lpfc_sli4_fof_intr_handler, 0,
9625 (char *)&phba->sli4_hba.handler_name[index],
9626 &phba->sli4_hba.hba_eq_hdl[index]);
9628 rc = request_irq(pci_irq_vector(phba->pcidev, index),
9629 &lpfc_sli4_hba_intr_handler, 0,
9630 (char *)&phba->sli4_hba.handler_name[index],
9631 &phba->sli4_hba.hba_eq_hdl[index]);
9633 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9634 "0486 MSI-X fast-path (%d) "
9635 "request_irq failed (%d)\n", index, rc);
9643 if (vectors != phba->io_channel_irqs) {
9644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9645 "3238 Reducing IO channels to match number of "
9646 "MSI-X vectors, requested %d got %d\n",
9647 phba->io_channel_irqs, vectors);
9648 if (phba->cfg_fcp_io_channel > vectors)
9649 phba->cfg_fcp_io_channel = vectors;
9650 if (phba->cfg_nvme_io_channel > vectors)
9651 phba->cfg_nvme_io_channel = vectors;
9652 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9653 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9655 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
9657 lpfc_cpu_affinity_check(phba, vectors);
9662 /* free the irq already requested */
9663 for (--index; index >= 0; index--)
9664 free_irq(pci_irq_vector(phba->pcidev, index),
9665 &phba->sli4_hba.hba_eq_hdl[index]);
9667 /* Unconfigure MSI-X capability structure */
9668 pci_free_irq_vectors(phba->pcidev);
9675 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9676 * @phba: pointer to lpfc hba data structure.
9678 * This routine is invoked to enable the MSI interrupt mode to device with
9679 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9680 * to enable the MSI vector. The device driver is responsible for calling
9681 * the request_irq() to register MSI vector with a interrupt the handler,
9682 * which is done in this function.
9686 * other values - error
9689 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9693 rc = pci_enable_msi(phba->pcidev);
9695 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9696 "0487 PCI enable MSI mode success.\n");
9698 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9699 "0488 PCI enable MSI mode failed (%d)\n", rc);
9703 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9704 0, LPFC_DRIVER_NAME, phba);
9706 pci_disable_msi(phba->pcidev);
9707 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9708 "0490 MSI request_irq failed (%d)\n", rc);
9712 for (index = 0; index < phba->io_channel_irqs; index++) {
9713 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9714 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9717 if (phba->cfg_fof) {
9718 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9719 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9725 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9726 * @phba: pointer to lpfc hba data structure.
9728 * This routine is invoked to enable device interrupt and associate driver's
9729 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9730 * interface spec. Depends on the interrupt mode configured to the driver,
9731 * the driver will try to fallback from the configured interrupt mode to an
9732 * interrupt mode which is supported by the platform, kernel, and device in
9734 * MSI-X -> MSI -> IRQ.
9738 * other values - error
9741 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9743 uint32_t intr_mode = LPFC_INTR_ERROR;
9746 if (cfg_mode == 2) {
9747 /* Preparation before conf_msi mbox cmd */
9750 /* Now, try to enable MSI-X interrupt mode */
9751 retval = lpfc_sli4_enable_msix(phba);
9753 /* Indicate initialization to MSI-X mode */
9754 phba->intr_type = MSIX;
9760 /* Fallback to MSI if MSI-X initialization failed */
9761 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9762 retval = lpfc_sli4_enable_msi(phba);
9764 /* Indicate initialization to MSI mode */
9765 phba->intr_type = MSI;
9770 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9771 if (phba->intr_type == NONE) {
9772 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9773 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9775 struct lpfc_hba_eq_hdl *eqhdl;
9777 /* Indicate initialization to INTx mode */
9778 phba->intr_type = INTx;
9781 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9782 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9785 atomic_set(&eqhdl->hba_eq_in_use, 1);
9787 if (phba->cfg_fof) {
9788 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9791 atomic_set(&eqhdl->hba_eq_in_use, 1);
9799 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9800 * @phba: pointer to lpfc hba data structure.
9802 * This routine is invoked to disable device interrupt and disassociate
9803 * the driver's interrupt handler(s) from interrupt vector(s) to device
9804 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9805 * will release the interrupt vector(s) for the message signaled interrupt.
9808 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9810 /* Disable the currently initialized interrupt mode */
9811 if (phba->intr_type == MSIX) {
9814 /* Free up MSI-X multi-message vectors */
9815 for (index = 0; index < phba->io_channel_irqs; index++)
9816 free_irq(pci_irq_vector(phba->pcidev, index),
9817 &phba->sli4_hba.hba_eq_hdl[index]);
9820 free_irq(pci_irq_vector(phba->pcidev, index),
9821 &phba->sli4_hba.hba_eq_hdl[index]);
9823 free_irq(phba->pcidev->irq, phba);
9826 pci_free_irq_vectors(phba->pcidev);
9828 /* Reset interrupt management states */
9829 phba->intr_type = NONE;
9830 phba->sli.slistat.sli_intr = 0;
9834 * lpfc_unset_hba - Unset SLI3 hba device initialization
9835 * @phba: pointer to lpfc hba data structure.
9837 * This routine is invoked to unset the HBA device initialization steps to
9838 * a device with SLI-3 interface spec.
9841 lpfc_unset_hba(struct lpfc_hba *phba)
9843 struct lpfc_vport *vport = phba->pport;
9844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9846 spin_lock_irq(shost->host_lock);
9847 vport->load_flag |= FC_UNLOADING;
9848 spin_unlock_irq(shost->host_lock);
9850 kfree(phba->vpi_bmask);
9851 kfree(phba->vpi_ids);
9853 lpfc_stop_hba_timers(phba);
9855 phba->pport->work_port_events = 0;
9857 lpfc_sli_hba_down(phba);
9859 lpfc_sli_brdrestart(phba);
9861 lpfc_sli_disable_intr(phba);
9867 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9868 * @phba: Pointer to HBA context object.
9870 * This function is called in the SLI4 code path to wait for completion
9871 * of device's XRIs exchange busy. It will check the XRI exchange busy
9872 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9873 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9874 * I/Os every 30 seconds, log error message, and wait forever. Only when
9875 * all XRI exchange busy complete, the driver unload shall proceed with
9876 * invoking the function reset ioctl mailbox command to the CNA and the
9877 * the rest of the driver unload resource release.
9880 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9883 int nvme_xri_cmpl = 1;
9884 int fcp_xri_cmpl = 1;
9885 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9886 int nvmet_xri_cmpl =
9887 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
9889 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9891 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9892 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9894 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
9896 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
9898 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9901 "6100 NVME XRI exchange busy "
9902 "wait time: %d seconds.\n",
9905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9906 "2877 FCP XRI exchange busy "
9907 "wait time: %d seconds.\n",
9910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9911 "2878 ELS XRI exchange busy "
9912 "wait time: %d seconds.\n",
9914 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9915 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9917 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9918 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9920 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9921 nvme_xri_cmpl = list_empty(
9922 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
9924 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9925 fcp_xri_cmpl = list_empty(
9926 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
9929 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9932 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
9937 * lpfc_sli4_hba_unset - Unset the fcoe hba
9938 * @phba: Pointer to HBA context object.
9940 * This function is called in the SLI4 code path to reset the HBA's FCoE
9941 * function. The caller is not required to hold any lock. This routine
9942 * issues PCI function reset mailbox command to reset the FCoE function.
9943 * At the end of the function, it calls lpfc_hba_down_post function to
9944 * free any pending commands.
9947 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9950 LPFC_MBOXQ_t *mboxq;
9951 struct pci_dev *pdev = phba->pcidev;
9953 lpfc_stop_hba_timers(phba);
9954 phba->sli4_hba.intr_enable = 0;
9957 * Gracefully wait out the potential current outstanding asynchronous
9961 /* First, block any pending async mailbox command from posted */
9962 spin_lock_irq(&phba->hbalock);
9963 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9964 spin_unlock_irq(&phba->hbalock);
9965 /* Now, trying to wait it out if we can */
9966 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9968 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9971 /* Forcefully release the outstanding mailbox command if timed out */
9972 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9973 spin_lock_irq(&phba->hbalock);
9974 mboxq = phba->sli.mbox_active;
9975 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9976 __lpfc_mbox_cmpl_put(phba, mboxq);
9977 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9978 phba->sli.mbox_active = NULL;
9979 spin_unlock_irq(&phba->hbalock);
9982 /* Abort all iocbs associated with the hba */
9983 lpfc_sli_hba_iocb_abort(phba);
9985 /* Wait for completion of device XRI exchange busy */
9986 lpfc_sli4_xri_exchange_busy_wait(phba);
9988 /* Disable PCI subsystem interrupt */
9989 lpfc_sli4_disable_intr(phba);
9991 /* Disable SR-IOV if enabled */
9992 if (phba->cfg_sriov_nr_virtfn)
9993 pci_disable_sriov(pdev);
9995 /* Stop kthread signal shall trigger work_done one more time */
9996 kthread_stop(phba->worker_thread);
9998 /* Reset SLI4 HBA FCoE function */
9999 lpfc_pci_function_reset(phba);
10000 lpfc_sli4_queue_destroy(phba);
10002 /* Stop the SLI4 device port */
10003 phba->pport->work_port_events = 0;
10007 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10008 * @phba: Pointer to HBA context object.
10009 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10011 * This function is called in the SLI4 code path to read the port's
10012 * sli4 capabilities.
10014 * This function may be be called from any context that can block-wait
10015 * for the completion. The expectation is that this routine is called
10016 * typically from probe_one or from the online routine.
10019 lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10022 struct lpfc_mqe *mqe;
10023 struct lpfc_pc_sli4_params *sli4_params;
10027 mqe = &mboxq->u.mqe;
10029 /* Read the port's SLI4 Parameters port capabilities */
10030 lpfc_pc_sli4_params(mboxq);
10031 if (!phba->sli4_hba.intr_enable)
10032 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10034 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10035 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10041 sli4_params = &phba->sli4_hba.pc_sli4_params;
10042 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10043 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10044 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10045 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10046 &mqe->un.sli4_params);
10047 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10048 &mqe->un.sli4_params);
10049 sli4_params->proto_types = mqe->un.sli4_params.word3;
10050 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10051 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10052 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10053 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10054 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10055 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10056 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10057 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10058 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10059 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10060 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10061 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10062 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10063 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10064 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10065 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10066 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10067 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10068 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10069 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
10071 /* Make sure that sge_supp_len can be handled by the driver */
10072 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10073 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10079 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10080 * @phba: Pointer to HBA context object.
10081 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10083 * This function is called in the SLI4 code path to read the port's
10084 * sli4 capabilities.
10086 * This function may be be called from any context that can block-wait
10087 * for the completion. The expectation is that this routine is called
10088 * typically from probe_one or from the online routine.
10091 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10094 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10095 struct lpfc_pc_sli4_params *sli4_params;
10098 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10101 * By default, the driver assumes the SLI4 port requires RPI
10102 * header postings. The SLI4_PARAM response will correct this
10105 phba->sli4_hba.rpi_hdrs_in_use = 1;
10107 /* Read the port's SLI4 Config Parameters */
10108 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10109 sizeof(struct lpfc_sli4_cfg_mhdr));
10110 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10111 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10112 length, LPFC_SLI4_MBX_EMBED);
10113 if (!phba->sli4_hba.intr_enable)
10114 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10116 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10117 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10121 sli4_params = &phba->sli4_hba.pc_sli4_params;
10122 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10123 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10124 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10125 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10126 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10127 mbx_sli4_parameters);
10128 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10129 mbx_sli4_parameters);
10130 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10131 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10133 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10134 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10135 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
10136 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
10137 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10138 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10139 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10140 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
10141 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
10142 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10143 mbx_sli4_parameters);
10144 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
10145 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10146 mbx_sli4_parameters);
10147 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10148 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
10149 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10150 bf_get(cfg_xib, mbx_sli4_parameters));
10152 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10153 !phba->nvme_support) {
10154 phba->nvme_support = 0;
10155 phba->nvmet_support = 0;
10156 phba->cfg_nvmet_mrq = 0;
10157 phba->cfg_nvme_io_channel = 0;
10158 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10160 "6101 Disabling NVME support: "
10161 "Not supported by firmware: %d %d\n",
10162 bf_get(cfg_nvme, mbx_sli4_parameters),
10163 bf_get(cfg_xib, mbx_sli4_parameters));
10165 /* If firmware doesn't support NVME, just use SCSI support */
10166 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10168 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10171 if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp)
10172 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10174 /* Make sure that sge_supp_len can be handled by the driver */
10175 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10176 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10179 * Issue IOs with CDB embedded in WQE to minimized the number
10180 * of DMAs the firmware has to do. Setting this to 1 also forces
10181 * the driver to use 128 bytes WQEs for FCP IOs.
10183 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10184 phba->fcp_embed_io = 1;
10186 phba->fcp_embed_io = 0;
10189 * Check if the SLI port supports MDS Diagnostics
10191 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10192 phba->mds_diags_support = 1;
10194 phba->mds_diags_support = 0;
10199 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10200 * @pdev: pointer to PCI device
10201 * @pid: pointer to PCI device identifier
10203 * This routine is to be called to attach a device with SLI-3 interface spec
10204 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10205 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10206 * information of the device and driver to see if the driver state that it can
10207 * support this kind of device. If the match is successful, the driver core
10208 * invokes this routine. If this routine determines it can claim the HBA, it
10209 * does all the initialization that it needs to do to handle the HBA properly.
10212 * 0 - driver can claim the device
10213 * negative value - driver can not claim the device
10216 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10218 struct lpfc_hba *phba;
10219 struct lpfc_vport *vport = NULL;
10220 struct Scsi_Host *shost = NULL;
10222 uint32_t cfg_mode, intr_mode;
10224 /* Allocate memory for HBA structure */
10225 phba = lpfc_hba_alloc(pdev);
10229 /* Perform generic PCI device enabling operation */
10230 error = lpfc_enable_pci_dev(phba);
10232 goto out_free_phba;
10234 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10235 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10237 goto out_disable_pci_dev;
10239 /* Set up SLI-3 specific device PCI memory space */
10240 error = lpfc_sli_pci_mem_setup(phba);
10242 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10243 "1402 Failed to set up pci memory space.\n");
10244 goto out_disable_pci_dev;
10247 /* Set up SLI-3 specific device driver resources */
10248 error = lpfc_sli_driver_resource_setup(phba);
10250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10251 "1404 Failed to set up driver resource.\n");
10252 goto out_unset_pci_mem_s3;
10255 /* Initialize and populate the iocb list per host */
10256 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10259 "1405 Failed to initialize iocb list.\n");
10260 goto out_unset_driver_resource_s3;
10263 /* Set up common device driver resources */
10264 error = lpfc_setup_driver_resource_phase2(phba);
10266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10267 "1406 Failed to set up driver resource.\n");
10268 goto out_free_iocb_list;
10271 /* Get the default values for Model Name and Description */
10272 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10274 /* Create SCSI host to the physical port */
10275 error = lpfc_create_shost(phba);
10277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10278 "1407 Failed to create scsi host.\n");
10279 goto out_unset_driver_resource;
10282 /* Configure sysfs attributes */
10283 vport = phba->pport;
10284 error = lpfc_alloc_sysfs_attr(vport);
10286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10287 "1476 Failed to allocate sysfs attr\n");
10288 goto out_destroy_shost;
10291 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
10292 /* Now, trying to enable interrupt and bring up the device */
10293 cfg_mode = phba->cfg_use_msi;
10295 /* Put device to a known state before enabling interrupt */
10296 lpfc_stop_port(phba);
10297 /* Configure and enable interrupt */
10298 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10299 if (intr_mode == LPFC_INTR_ERROR) {
10300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10301 "0431 Failed to enable interrupt.\n");
10303 goto out_free_sysfs_attr;
10305 /* SLI-3 HBA setup */
10306 if (lpfc_sli_hba_setup(phba)) {
10307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10308 "1477 Failed to set up hba\n");
10310 goto out_remove_device;
10313 /* Wait 50ms for the interrupts of previous mailbox commands */
10315 /* Check active interrupts on message signaled interrupts */
10316 if (intr_mode == 0 ||
10317 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10318 /* Log the current active interrupt mode */
10319 phba->intr_mode = intr_mode;
10320 lpfc_log_intr_mode(phba, intr_mode);
10323 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10324 "0447 Configure interrupt mode (%d) "
10325 "failed active interrupt test.\n",
10327 /* Disable the current interrupt mode */
10328 lpfc_sli_disable_intr(phba);
10329 /* Try next level of interrupt mode */
10330 cfg_mode = --intr_mode;
10334 /* Perform post initialization setup */
10335 lpfc_post_init_setup(phba);
10337 /* Check if there are static vports to be created. */
10338 lpfc_create_static_vport(phba);
10343 lpfc_unset_hba(phba);
10344 out_free_sysfs_attr:
10345 lpfc_free_sysfs_attr(vport);
10347 lpfc_destroy_shost(phba);
10348 out_unset_driver_resource:
10349 lpfc_unset_driver_resource_phase2(phba);
10350 out_free_iocb_list:
10351 lpfc_free_iocb_list(phba);
10352 out_unset_driver_resource_s3:
10353 lpfc_sli_driver_resource_unset(phba);
10354 out_unset_pci_mem_s3:
10355 lpfc_sli_pci_mem_unset(phba);
10356 out_disable_pci_dev:
10357 lpfc_disable_pci_dev(phba);
10359 scsi_host_put(shost);
10361 lpfc_hba_free(phba);
10366 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10367 * @pdev: pointer to PCI device
10369 * This routine is to be called to disattach a device with SLI-3 interface
10370 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10371 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10372 * device to be removed from the PCI subsystem properly.
10375 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
10377 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10379 struct lpfc_vport **vports;
10380 struct lpfc_hba *phba = vport->phba;
10383 spin_lock_irq(&phba->hbalock);
10384 vport->load_flag |= FC_UNLOADING;
10385 spin_unlock_irq(&phba->hbalock);
10387 lpfc_free_sysfs_attr(vport);
10389 /* Release all the vports against this physical port */
10390 vports = lpfc_create_vport_work_array(phba);
10391 if (vports != NULL)
10392 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10393 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10395 fc_vport_terminate(vports[i]->fc_vport);
10397 lpfc_destroy_vport_work_array(phba, vports);
10399 /* Remove FC host and then SCSI host with the physical port */
10400 fc_remove_host(shost);
10401 scsi_remove_host(shost);
10403 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
10404 * localports are destroyed after to cleanup all transport memory.
10406 lpfc_cleanup(vport);
10407 lpfc_nvmet_destroy_targetport(phba);
10408 lpfc_nvme_destroy_localport(vport);
10411 * Bring down the SLI Layer. This step disable all interrupts,
10412 * clears the rings, discards all mailbox commands, and resets
10416 /* HBA interrupt will be disabled after this call */
10417 lpfc_sli_hba_down(phba);
10418 /* Stop kthread signal shall trigger work_done one more time */
10419 kthread_stop(phba->worker_thread);
10420 /* Final cleanup of txcmplq and reset the HBA */
10421 lpfc_sli_brdrestart(phba);
10423 kfree(phba->vpi_bmask);
10424 kfree(phba->vpi_ids);
10426 lpfc_stop_hba_timers(phba);
10427 spin_lock_irq(&phba->hbalock);
10428 list_del_init(&vport->listentry);
10429 spin_unlock_irq(&phba->hbalock);
10431 lpfc_debugfs_terminate(vport);
10433 /* Disable SR-IOV if enabled */
10434 if (phba->cfg_sriov_nr_virtfn)
10435 pci_disable_sriov(pdev);
10437 /* Disable interrupt */
10438 lpfc_sli_disable_intr(phba);
10440 scsi_host_put(shost);
10443 * Call scsi_free before mem_free since scsi bufs are released to their
10444 * corresponding pools here.
10446 lpfc_scsi_free(phba);
10447 lpfc_mem_free_all(phba);
10449 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10450 phba->hbqslimp.virt, phba->hbqslimp.phys);
10452 /* Free resources associated with SLI2 interface */
10453 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
10454 phba->slim2p.virt, phba->slim2p.phys);
10456 /* unmap adapter SLIM and Control Registers */
10457 iounmap(phba->ctrl_regs_memmap_p);
10458 iounmap(phba->slim_memmap_p);
10460 lpfc_hba_free(phba);
10462 pci_release_mem_regions(pdev);
10463 pci_disable_device(pdev);
10467 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
10468 * @pdev: pointer to PCI device
10469 * @msg: power management message
10471 * This routine is to be called from the kernel's PCI subsystem to support
10472 * system Power Management (PM) to device with SLI-3 interface spec. When
10473 * PM invokes this method, it quiesces the device by stopping the driver's
10474 * worker thread for the device, turning off device's interrupt and DMA,
10475 * and bring the device offline. Note that as the driver implements the
10476 * minimum PM requirements to a power-aware driver's PM support for the
10477 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10478 * to the suspend() method call will be treated as SUSPEND and the driver will
10479 * fully reinitialize its device during resume() method call, the driver will
10480 * set device to PCI_D3hot state in PCI config space instead of setting it
10481 * according to the @msg provided by the PM.
10484 * 0 - driver suspended the device
10488 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
10490 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10491 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10493 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10494 "0473 PCI device Power Management suspend.\n");
10496 /* Bring down the device */
10497 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10498 lpfc_offline(phba);
10499 kthread_stop(phba->worker_thread);
10501 /* Disable interrupt from device */
10502 lpfc_sli_disable_intr(phba);
10504 /* Save device state to PCI config space */
10505 pci_save_state(pdev);
10506 pci_set_power_state(pdev, PCI_D3hot);
10512 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
10513 * @pdev: pointer to PCI device
10515 * This routine is to be called from the kernel's PCI subsystem to support
10516 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10517 * invokes this method, it restores the device's PCI config space state and
10518 * fully reinitializes the device and brings it online. Note that as the
10519 * driver implements the minimum PM requirements to a power-aware driver's
10520 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10521 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10522 * driver will fully reinitialize its device during resume() method call,
10523 * the device will be set to PCI_D0 directly in PCI config space before
10524 * restoring the state.
10527 * 0 - driver suspended the device
10531 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
10533 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10534 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10535 uint32_t intr_mode;
10538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10539 "0452 PCI device Power Management resume.\n");
10541 /* Restore device state from PCI config space */
10542 pci_set_power_state(pdev, PCI_D0);
10543 pci_restore_state(pdev);
10546 * As the new kernel behavior of pci_restore_state() API call clears
10547 * device saved_state flag, need to save the restored state again.
10549 pci_save_state(pdev);
10551 if (pdev->is_busmaster)
10552 pci_set_master(pdev);
10554 /* Startup the kernel thread for this host adapter. */
10555 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10556 "lpfc_worker_%d", phba->brd_no);
10557 if (IS_ERR(phba->worker_thread)) {
10558 error = PTR_ERR(phba->worker_thread);
10559 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10560 "0434 PM resume failed to start worker "
10561 "thread: error=x%x.\n", error);
10565 /* Configure and enable interrupt */
10566 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
10567 if (intr_mode == LPFC_INTR_ERROR) {
10568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10569 "0430 PM resume Failed to enable interrupt\n");
10572 phba->intr_mode = intr_mode;
10574 /* Restart HBA and bring it online */
10575 lpfc_sli_brdrestart(phba);
10578 /* Log the current active interrupt mode */
10579 lpfc_log_intr_mode(phba, phba->intr_mode);
10585 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10586 * @phba: pointer to lpfc hba data structure.
10588 * This routine is called to prepare the SLI3 device for PCI slot recover. It
10589 * aborts all the outstanding SCSI I/Os to the pci device.
10592 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10594 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10595 "2723 PCI channel I/O abort preparing for recovery\n");
10598 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10599 * and let the SCSI mid-layer to retry them to recover.
10601 lpfc_sli_abort_fcp_rings(phba);
10605 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10606 * @phba: pointer to lpfc hba data structure.
10608 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10609 * disables the device interrupt and pci device, and aborts the internal FCP
10613 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10615 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10616 "2710 PCI channel disable preparing for reset\n");
10618 /* Block any management I/Os to the device */
10619 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
10621 /* Block all SCSI devices' I/Os on the host */
10622 lpfc_scsi_dev_block(phba);
10624 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10625 lpfc_sli_flush_fcp_rings(phba);
10627 /* stop all timers */
10628 lpfc_stop_hba_timers(phba);
10630 /* Disable interrupt and pci device */
10631 lpfc_sli_disable_intr(phba);
10632 pci_disable_device(phba->pcidev);
10636 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10637 * @phba: pointer to lpfc hba data structure.
10639 * This routine is called to prepare the SLI3 device for PCI slot permanently
10640 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10644 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10646 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10647 "2711 PCI channel permanent disable for failure\n");
10648 /* Block all SCSI devices' I/Os on the host */
10649 lpfc_scsi_dev_block(phba);
10651 /* stop all timers */
10652 lpfc_stop_hba_timers(phba);
10654 /* Clean up all driver's outstanding SCSI I/Os */
10655 lpfc_sli_flush_fcp_rings(phba);
10659 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
10660 * @pdev: pointer to PCI device.
10661 * @state: the current PCI connection state.
10663 * This routine is called from the PCI subsystem for I/O error handling to
10664 * device with SLI-3 interface spec. This function is called by the PCI
10665 * subsystem after a PCI bus error affecting this device has been detected.
10666 * When this function is invoked, it will need to stop all the I/Os and
10667 * interrupt(s) to the device. Once that is done, it will return
10668 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10672 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
10673 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10674 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10676 static pci_ers_result_t
10677 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
10679 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10680 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10683 case pci_channel_io_normal:
10684 /* Non-fatal error, prepare for recovery */
10685 lpfc_sli_prep_dev_for_recover(phba);
10686 return PCI_ERS_RESULT_CAN_RECOVER;
10687 case pci_channel_io_frozen:
10688 /* Fatal error, prepare for slot reset */
10689 lpfc_sli_prep_dev_for_reset(phba);
10690 return PCI_ERS_RESULT_NEED_RESET;
10691 case pci_channel_io_perm_failure:
10692 /* Permanent failure, prepare for device down */
10693 lpfc_sli_prep_dev_for_perm_failure(phba);
10694 return PCI_ERS_RESULT_DISCONNECT;
10696 /* Unknown state, prepare and request slot reset */
10697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10698 "0472 Unknown PCI error state: x%x\n", state);
10699 lpfc_sli_prep_dev_for_reset(phba);
10700 return PCI_ERS_RESULT_NEED_RESET;
10705 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
10706 * @pdev: pointer to PCI device.
10708 * This routine is called from the PCI subsystem for error handling to
10709 * device with SLI-3 interface spec. This is called after PCI bus has been
10710 * reset to restart the PCI card from scratch, as if from a cold-boot.
10711 * During the PCI subsystem error recovery, after driver returns
10712 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10713 * recovery and then call this routine before calling the .resume method
10714 * to recover the device. This function will initialize the HBA device,
10715 * enable the interrupt, but it will just put the HBA to offline state
10716 * without passing any I/O traffic.
10719 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10720 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10722 static pci_ers_result_t
10723 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
10725 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10726 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10727 struct lpfc_sli *psli = &phba->sli;
10728 uint32_t intr_mode;
10730 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10731 if (pci_enable_device_mem(pdev)) {
10732 printk(KERN_ERR "lpfc: Cannot re-enable "
10733 "PCI device after reset.\n");
10734 return PCI_ERS_RESULT_DISCONNECT;
10737 pci_restore_state(pdev);
10740 * As the new kernel behavior of pci_restore_state() API call clears
10741 * device saved_state flag, need to save the restored state again.
10743 pci_save_state(pdev);
10745 if (pdev->is_busmaster)
10746 pci_set_master(pdev);
10748 spin_lock_irq(&phba->hbalock);
10749 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10750 spin_unlock_irq(&phba->hbalock);
10752 /* Configure and enable interrupt */
10753 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
10754 if (intr_mode == LPFC_INTR_ERROR) {
10755 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10756 "0427 Cannot re-enable interrupt after "
10758 return PCI_ERS_RESULT_DISCONNECT;
10760 phba->intr_mode = intr_mode;
10762 /* Take device offline, it will perform cleanup */
10763 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10764 lpfc_offline(phba);
10765 lpfc_sli_brdrestart(phba);
10767 /* Log the current active interrupt mode */
10768 lpfc_log_intr_mode(phba, phba->intr_mode);
10770 return PCI_ERS_RESULT_RECOVERED;
10774 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
10775 * @pdev: pointer to PCI device
10777 * This routine is called from the PCI subsystem for error handling to device
10778 * with SLI-3 interface spec. It is called when kernel error recovery tells
10779 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10780 * error recovery. After this call, traffic can start to flow from this device
10784 lpfc_io_resume_s3(struct pci_dev *pdev)
10786 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10787 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10789 /* Bring device online, it will be no-op for non-fatal error resume */
10792 /* Clean up Advanced Error Reporting (AER) if needed */
10793 if (phba->hba_flag & HBA_AER_ENABLED)
10794 pci_cleanup_aer_uncorrect_error_status(pdev);
10798 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10799 * @phba: pointer to lpfc hba data structure.
10801 * returns the number of ELS/CT IOCBs to reserve
10804 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10806 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10808 if (phba->sli_rev == LPFC_SLI_REV4) {
10809 if (max_xri <= 100)
10811 else if (max_xri <= 256)
10813 else if (max_xri <= 512)
10815 else if (max_xri <= 1024)
10817 else if (max_xri <= 1536)
10819 else if (max_xri <= 2048)
10828 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10829 * @phba: pointer to lpfc hba data structure.
10831 * returns the number of ELS/CT + NVMET IOCBs to reserve
10834 lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10836 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10838 if (phba->nvmet_support)
10839 max_xri += LPFC_NVMET_BUF_POST;
10845 * lpfc_write_firmware - attempt to write a firmware image to the port
10846 * @fw: pointer to firmware image returned from request_firmware.
10847 * @phba: pointer to lpfc hba data structure.
10851 lpfc_write_firmware(const struct firmware *fw, void *context)
10853 struct lpfc_hba *phba = (struct lpfc_hba *)context;
10854 char fwrev[FW_REV_STR_SIZE];
10855 struct lpfc_grp_hdr *image;
10856 struct list_head dma_buffer_list;
10858 struct lpfc_dmabuf *dmabuf, *next;
10859 uint32_t offset = 0, temp_offset = 0;
10860 uint32_t magic_number, ftype, fid, fsize;
10862 /* It can be null in no-wait mode, sanity check */
10867 image = (struct lpfc_grp_hdr *)fw->data;
10869 magic_number = be32_to_cpu(image->magic_number);
10870 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
10871 fid = bf_get_be32(lpfc_grp_hdr_id, image),
10872 fsize = be32_to_cpu(image->size);
10874 INIT_LIST_HEAD(&dma_buffer_list);
10875 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
10876 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
10877 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
10878 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10879 "3022 Invalid FW image found. "
10880 "Magic:%x Type:%x ID:%x Size %d %zd\n",
10881 magic_number, ftype, fid, fsize, fw->size);
10885 lpfc_decode_firmware_rev(phba, fwrev, 1);
10886 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
10887 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10888 "3023 Updating Firmware, Current Version:%s "
10889 "New Version:%s\n",
10890 fwrev, image->revision);
10891 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10892 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10898 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10902 if (!dmabuf->virt) {
10907 list_add_tail(&dmabuf->list, &dma_buffer_list);
10909 while (offset < fw->size) {
10910 temp_offset = offset;
10911 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
10912 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
10913 memcpy(dmabuf->virt,
10914 fw->data + temp_offset,
10915 fw->size - temp_offset);
10916 temp_offset = fw->size;
10919 memcpy(dmabuf->virt, fw->data + temp_offset,
10921 temp_offset += SLI4_PAGE_SIZE;
10923 rc = lpfc_wr_object(phba, &dma_buffer_list,
10924 (fw->size - offset), &offset);
10932 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10933 list_del(&dmabuf->list);
10934 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10935 dmabuf->virt, dmabuf->phys);
10938 release_firmware(fw);
10940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10941 "3024 Firmware update done: %d.\n", rc);
10946 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10947 * @phba: pointer to lpfc hba data structure.
10949 * This routine is called to perform Linux generic firmware upgrade on device
10950 * that supports such feature.
10953 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10955 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10957 const struct firmware *fw;
10959 /* Only supported on SLI4 interface type 2 for now */
10960 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10961 LPFC_SLI_INTF_IF_TYPE_2)
10964 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10966 if (fw_upgrade == INT_FW_UPGRADE) {
10967 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10968 file_name, &phba->pcidev->dev,
10969 GFP_KERNEL, (void *)phba,
10970 lpfc_write_firmware);
10971 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10972 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10974 lpfc_write_firmware(fw, (void *)phba);
10983 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10984 * @pdev: pointer to PCI device
10985 * @pid: pointer to PCI device identifier
10987 * This routine is called from the kernel's PCI subsystem to device with
10988 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10989 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10990 * information of the device and driver to see if the driver state that it
10991 * can support this kind of device. If the match is successful, the driver
10992 * core invokes this routine. If this routine determines it can claim the HBA,
10993 * it does all the initialization that it needs to do to handle the HBA
10997 * 0 - driver can claim the device
10998 * negative value - driver can not claim the device
11001 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11003 struct lpfc_hba *phba;
11004 struct lpfc_vport *vport = NULL;
11005 struct Scsi_Host *shost = NULL;
11007 uint32_t cfg_mode, intr_mode;
11009 /* Allocate memory for HBA structure */
11010 phba = lpfc_hba_alloc(pdev);
11014 /* Perform generic PCI device enabling operation */
11015 error = lpfc_enable_pci_dev(phba);
11017 goto out_free_phba;
11019 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11020 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11022 goto out_disable_pci_dev;
11024 /* Set up SLI-4 specific device PCI memory space */
11025 error = lpfc_sli4_pci_mem_setup(phba);
11027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11028 "1410 Failed to set up pci memory space.\n");
11029 goto out_disable_pci_dev;
11032 /* Set up SLI-4 Specific device driver resources */
11033 error = lpfc_sli4_driver_resource_setup(phba);
11035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11036 "1412 Failed to set up driver resource.\n");
11037 goto out_unset_pci_mem_s4;
11040 /* Initialize and populate the iocb list per host */
11042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11043 "2821 initialize iocb list %d.\n",
11044 phba->cfg_iocb_cnt*1024);
11045 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
11048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11049 "1413 Failed to initialize iocb list.\n");
11050 goto out_unset_driver_resource_s4;
11053 INIT_LIST_HEAD(&phba->active_rrq_list);
11054 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
11056 /* Set up common device driver resources */
11057 error = lpfc_setup_driver_resource_phase2(phba);
11059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11060 "1414 Failed to set up driver resource.\n");
11061 goto out_free_iocb_list;
11064 /* Get the default values for Model Name and Description */
11065 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11067 /* Create SCSI host to the physical port */
11068 error = lpfc_create_shost(phba);
11070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11071 "1415 Failed to create scsi host.\n");
11072 goto out_unset_driver_resource;
11075 /* Configure sysfs attributes */
11076 vport = phba->pport;
11077 error = lpfc_alloc_sysfs_attr(vport);
11079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11080 "1416 Failed to allocate sysfs attr\n");
11081 goto out_destroy_shost;
11084 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
11085 /* Now, trying to enable interrupt and bring up the device */
11086 cfg_mode = phba->cfg_use_msi;
11088 /* Put device to a known state before enabling interrupt */
11089 lpfc_stop_port(phba);
11091 /* Configure and enable interrupt */
11092 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11093 if (intr_mode == LPFC_INTR_ERROR) {
11094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11095 "0426 Failed to enable interrupt.\n");
11097 goto out_free_sysfs_attr;
11099 /* Default to single EQ for non-MSI-X */
11100 if (phba->intr_type != MSIX) {
11101 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11102 phba->cfg_fcp_io_channel = 1;
11103 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11104 phba->cfg_nvme_io_channel = 1;
11105 if (phba->nvmet_support)
11106 phba->cfg_nvmet_mrq = 1;
11108 phba->io_channel_irqs = 1;
11111 /* Set up SLI-4 HBA */
11112 if (lpfc_sli4_hba_setup(phba)) {
11113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11114 "1421 Failed to set up hba\n");
11116 goto out_disable_intr;
11119 /* Log the current active interrupt mode */
11120 phba->intr_mode = intr_mode;
11121 lpfc_log_intr_mode(phba, intr_mode);
11123 /* Perform post initialization setup */
11124 lpfc_post_init_setup(phba);
11126 /* NVME support in FW earlier in the driver load corrects the
11127 * FC4 type making a check for nvme_support unnecessary.
11129 if ((phba->nvmet_support == 0) &&
11130 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11131 /* Create NVME binding with nvme_fc_transport. This
11132 * ensures the vport is initialized.
11134 error = lpfc_nvme_create_localport(vport);
11136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11137 "6004 NVME registration failed, "
11140 goto out_disable_intr;
11144 /* check for firmware upgrade or downgrade */
11145 if (phba->cfg_request_firmware_upgrade)
11146 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
11148 /* Check if there are static vports to be created. */
11149 lpfc_create_static_vport(phba);
11153 lpfc_sli4_disable_intr(phba);
11154 out_free_sysfs_attr:
11155 lpfc_free_sysfs_attr(vport);
11157 lpfc_destroy_shost(phba);
11158 out_unset_driver_resource:
11159 lpfc_unset_driver_resource_phase2(phba);
11160 out_free_iocb_list:
11161 lpfc_free_iocb_list(phba);
11162 out_unset_driver_resource_s4:
11163 lpfc_sli4_driver_resource_unset(phba);
11164 out_unset_pci_mem_s4:
11165 lpfc_sli4_pci_mem_unset(phba);
11166 out_disable_pci_dev:
11167 lpfc_disable_pci_dev(phba);
11169 scsi_host_put(shost);
11171 lpfc_hba_free(phba);
11176 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11177 * @pdev: pointer to PCI device
11179 * This routine is called from the kernel's PCI subsystem to device with
11180 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11181 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11182 * device to be removed from the PCI subsystem properly.
11185 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11187 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11188 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11189 struct lpfc_vport **vports;
11190 struct lpfc_hba *phba = vport->phba;
11193 /* Mark the device unloading flag */
11194 spin_lock_irq(&phba->hbalock);
11195 vport->load_flag |= FC_UNLOADING;
11196 spin_unlock_irq(&phba->hbalock);
11198 /* Free the HBA sysfs attributes */
11199 lpfc_free_sysfs_attr(vport);
11201 /* Release all the vports against this physical port */
11202 vports = lpfc_create_vport_work_array(phba);
11203 if (vports != NULL)
11204 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11205 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11207 fc_vport_terminate(vports[i]->fc_vport);
11209 lpfc_destroy_vport_work_array(phba, vports);
11211 /* Remove FC host and then SCSI host with the physical port */
11212 fc_remove_host(shost);
11213 scsi_remove_host(shost);
11215 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11216 * localports are destroyed after to cleanup all transport memory.
11218 lpfc_cleanup(vport);
11219 lpfc_nvmet_destroy_targetport(phba);
11220 lpfc_nvme_destroy_localport(vport);
11223 * Bring down the SLI Layer. This step disables all interrupts,
11224 * clears the rings, discards all mailbox commands, and resets
11225 * the HBA FCoE function.
11227 lpfc_debugfs_terminate(vport);
11228 lpfc_sli4_hba_unset(phba);
11230 spin_lock_irq(&phba->hbalock);
11231 list_del_init(&vport->listentry);
11232 spin_unlock_irq(&phba->hbalock);
11234 /* Perform scsi free before driver resource_unset since scsi
11235 * buffers are released to their corresponding pools here.
11237 lpfc_scsi_free(phba);
11238 lpfc_nvme_free(phba);
11239 lpfc_free_iocb_list(phba);
11241 lpfc_sli4_driver_resource_unset(phba);
11243 /* Unmap adapter Control and Doorbell registers */
11244 lpfc_sli4_pci_mem_unset(phba);
11246 /* Release PCI resources and disable device's PCI function */
11247 scsi_host_put(shost);
11248 lpfc_disable_pci_dev(phba);
11250 /* Finally, free the driver's device data structure */
11251 lpfc_hba_free(phba);
11257 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11258 * @pdev: pointer to PCI device
11259 * @msg: power management message
11261 * This routine is called from the kernel's PCI subsystem to support system
11262 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11263 * this method, it quiesces the device by stopping the driver's worker
11264 * thread for the device, turning off device's interrupt and DMA, and bring
11265 * the device offline. Note that as the driver implements the minimum PM
11266 * requirements to a power-aware driver's PM support for suspend/resume -- all
11267 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11268 * method call will be treated as SUSPEND and the driver will fully
11269 * reinitialize its device during resume() method call, the driver will set
11270 * device to PCI_D3hot state in PCI config space instead of setting it
11271 * according to the @msg provided by the PM.
11274 * 0 - driver suspended the device
11278 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11280 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11281 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11283 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11284 "2843 PCI device Power Management suspend.\n");
11286 /* Bring down the device */
11287 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11288 lpfc_offline(phba);
11289 kthread_stop(phba->worker_thread);
11291 /* Disable interrupt from device */
11292 lpfc_sli4_disable_intr(phba);
11293 lpfc_sli4_queue_destroy(phba);
11295 /* Save device state to PCI config space */
11296 pci_save_state(pdev);
11297 pci_set_power_state(pdev, PCI_D3hot);
11303 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11304 * @pdev: pointer to PCI device
11306 * This routine is called from the kernel's PCI subsystem to support system
11307 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11308 * this method, it restores the device's PCI config space state and fully
11309 * reinitializes the device and brings it online. Note that as the driver
11310 * implements the minimum PM requirements to a power-aware driver's PM for
11311 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11312 * to the suspend() method call will be treated as SUSPEND and the driver
11313 * will fully reinitialize its device during resume() method call, the device
11314 * will be set to PCI_D0 directly in PCI config space before restoring the
11318 * 0 - driver suspended the device
11322 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11324 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11325 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11326 uint32_t intr_mode;
11329 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11330 "0292 PCI device Power Management resume.\n");
11332 /* Restore device state from PCI config space */
11333 pci_set_power_state(pdev, PCI_D0);
11334 pci_restore_state(pdev);
11337 * As the new kernel behavior of pci_restore_state() API call clears
11338 * device saved_state flag, need to save the restored state again.
11340 pci_save_state(pdev);
11342 if (pdev->is_busmaster)
11343 pci_set_master(pdev);
11345 /* Startup the kernel thread for this host adapter. */
11346 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11347 "lpfc_worker_%d", phba->brd_no);
11348 if (IS_ERR(phba->worker_thread)) {
11349 error = PTR_ERR(phba->worker_thread);
11350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11351 "0293 PM resume failed to start worker "
11352 "thread: error=x%x.\n", error);
11356 /* Configure and enable interrupt */
11357 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11358 if (intr_mode == LPFC_INTR_ERROR) {
11359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11360 "0294 PM resume Failed to enable interrupt\n");
11363 phba->intr_mode = intr_mode;
11365 /* Restart HBA and bring it online */
11366 lpfc_sli_brdrestart(phba);
11369 /* Log the current active interrupt mode */
11370 lpfc_log_intr_mode(phba, phba->intr_mode);
11376 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11377 * @phba: pointer to lpfc hba data structure.
11379 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11380 * aborts all the outstanding SCSI I/Os to the pci device.
11383 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11386 "2828 PCI channel I/O abort preparing for recovery\n");
11388 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11389 * and let the SCSI mid-layer to retry them to recover.
11391 lpfc_sli_abort_fcp_rings(phba);
11395 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11396 * @phba: pointer to lpfc hba data structure.
11398 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11399 * disables the device interrupt and pci device, and aborts the internal FCP
11403 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11406 "2826 PCI channel disable preparing for reset\n");
11408 /* Block any management I/Os to the device */
11409 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
11411 /* Block all SCSI devices' I/Os on the host */
11412 lpfc_scsi_dev_block(phba);
11414 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11415 lpfc_sli_flush_fcp_rings(phba);
11417 /* stop all timers */
11418 lpfc_stop_hba_timers(phba);
11420 /* Disable interrupt and pci device */
11421 lpfc_sli4_disable_intr(phba);
11422 lpfc_sli4_queue_destroy(phba);
11423 pci_disable_device(phba->pcidev);
11427 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11428 * @phba: pointer to lpfc hba data structure.
11430 * This routine is called to prepare the SLI4 device for PCI slot permanently
11431 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11435 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11438 "2827 PCI channel permanent disable for failure\n");
11440 /* Block all SCSI devices' I/Os on the host */
11441 lpfc_scsi_dev_block(phba);
11443 /* stop all timers */
11444 lpfc_stop_hba_timers(phba);
11446 /* Clean up all driver's outstanding SCSI I/Os */
11447 lpfc_sli_flush_fcp_rings(phba);
11451 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11452 * @pdev: pointer to PCI device.
11453 * @state: the current PCI connection state.
11455 * This routine is called from the PCI subsystem for error handling to device
11456 * with SLI-4 interface spec. This function is called by the PCI subsystem
11457 * after a PCI bus error affecting this device has been detected. When this
11458 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11459 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11460 * for the PCI subsystem to perform proper recovery as desired.
11463 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11464 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11466 static pci_ers_result_t
11467 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11469 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11470 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11473 case pci_channel_io_normal:
11474 /* Non-fatal error, prepare for recovery */
11475 lpfc_sli4_prep_dev_for_recover(phba);
11476 return PCI_ERS_RESULT_CAN_RECOVER;
11477 case pci_channel_io_frozen:
11478 /* Fatal error, prepare for slot reset */
11479 lpfc_sli4_prep_dev_for_reset(phba);
11480 return PCI_ERS_RESULT_NEED_RESET;
11481 case pci_channel_io_perm_failure:
11482 /* Permanent failure, prepare for device down */
11483 lpfc_sli4_prep_dev_for_perm_failure(phba);
11484 return PCI_ERS_RESULT_DISCONNECT;
11486 /* Unknown state, prepare and request slot reset */
11487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11488 "2825 Unknown PCI error state: x%x\n", state);
11489 lpfc_sli4_prep_dev_for_reset(phba);
11490 return PCI_ERS_RESULT_NEED_RESET;
11495 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11496 * @pdev: pointer to PCI device.
11498 * This routine is called from the PCI subsystem for error handling to device
11499 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11500 * restart the PCI card from scratch, as if from a cold-boot. During the
11501 * PCI subsystem error recovery, after the driver returns
11502 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11503 * recovery and then call this routine before calling the .resume method to
11504 * recover the device. This function will initialize the HBA device, enable
11505 * the interrupt, but it will just put the HBA to offline state without
11506 * passing any I/O traffic.
11509 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11510 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11512 static pci_ers_result_t
11513 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11515 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11516 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11517 struct lpfc_sli *psli = &phba->sli;
11518 uint32_t intr_mode;
11520 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11521 if (pci_enable_device_mem(pdev)) {
11522 printk(KERN_ERR "lpfc: Cannot re-enable "
11523 "PCI device after reset.\n");
11524 return PCI_ERS_RESULT_DISCONNECT;
11527 pci_restore_state(pdev);
11530 * As the new kernel behavior of pci_restore_state() API call clears
11531 * device saved_state flag, need to save the restored state again.
11533 pci_save_state(pdev);
11535 if (pdev->is_busmaster)
11536 pci_set_master(pdev);
11538 spin_lock_irq(&phba->hbalock);
11539 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11540 spin_unlock_irq(&phba->hbalock);
11542 /* Configure and enable interrupt */
11543 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11544 if (intr_mode == LPFC_INTR_ERROR) {
11545 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11546 "2824 Cannot re-enable interrupt after "
11548 return PCI_ERS_RESULT_DISCONNECT;
11550 phba->intr_mode = intr_mode;
11552 /* Log the current active interrupt mode */
11553 lpfc_log_intr_mode(phba, phba->intr_mode);
11555 return PCI_ERS_RESULT_RECOVERED;
11559 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11560 * @pdev: pointer to PCI device
11562 * This routine is called from the PCI subsystem for error handling to device
11563 * with SLI-4 interface spec. It is called when kernel error recovery tells
11564 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11565 * error recovery. After this call, traffic can start to flow from this device
11569 lpfc_io_resume_s4(struct pci_dev *pdev)
11571 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11572 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11575 * In case of slot reset, as function reset is performed through
11576 * mailbox command which needs DMA to be enabled, this operation
11577 * has to be moved to the io resume phase. Taking device offline
11578 * will perform the necessary cleanup.
11580 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11581 /* Perform device reset */
11582 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
11583 lpfc_offline(phba);
11584 lpfc_sli_brdrestart(phba);
11585 /* Bring the device back online */
11589 /* Clean up Advanced Error Reporting (AER) if needed */
11590 if (phba->hba_flag & HBA_AER_ENABLED)
11591 pci_cleanup_aer_uncorrect_error_status(pdev);
11595 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11596 * @pdev: pointer to PCI device
11597 * @pid: pointer to PCI device identifier
11599 * This routine is to be registered to the kernel's PCI subsystem. When an
11600 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11601 * at PCI device-specific information of the device and driver to see if the
11602 * driver state that it can support this kind of device. If the match is
11603 * successful, the driver core invokes this routine. This routine dispatches
11604 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11605 * do all the initialization that it needs to do to handle the HBA device
11609 * 0 - driver can claim the device
11610 * negative value - driver can not claim the device
11613 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11616 struct lpfc_sli_intf intf;
11618 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
11621 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
11622 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
11623 rc = lpfc_pci_probe_one_s4(pdev, pid);
11625 rc = lpfc_pci_probe_one_s3(pdev, pid);
11631 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11632 * @pdev: pointer to PCI device
11634 * This routine is to be registered to the kernel's PCI subsystem. When an
11635 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11636 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11637 * remove routine, which will perform all the necessary cleanup for the
11638 * device to be removed from the PCI subsystem properly.
11641 lpfc_pci_remove_one(struct pci_dev *pdev)
11643 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11644 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11646 switch (phba->pci_dev_grp) {
11647 case LPFC_PCI_DEV_LP:
11648 lpfc_pci_remove_one_s3(pdev);
11650 case LPFC_PCI_DEV_OC:
11651 lpfc_pci_remove_one_s4(pdev);
11654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11655 "1424 Invalid PCI device group: 0x%x\n",
11656 phba->pci_dev_grp);
11663 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11664 * @pdev: pointer to PCI device
11665 * @msg: power management message
11667 * This routine is to be registered to the kernel's PCI subsystem to support
11668 * system Power Management (PM). When PM invokes this method, it dispatches
11669 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11670 * suspend the device.
11673 * 0 - driver suspended the device
11677 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11679 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11680 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11683 switch (phba->pci_dev_grp) {
11684 case LPFC_PCI_DEV_LP:
11685 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11687 case LPFC_PCI_DEV_OC:
11688 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11692 "1425 Invalid PCI device group: 0x%x\n",
11693 phba->pci_dev_grp);
11700 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11701 * @pdev: pointer to PCI device
11703 * This routine is to be registered to the kernel's PCI subsystem to support
11704 * system Power Management (PM). When PM invokes this method, it dispatches
11705 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11706 * resume the device.
11709 * 0 - driver suspended the device
11713 lpfc_pci_resume_one(struct pci_dev *pdev)
11715 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11716 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11719 switch (phba->pci_dev_grp) {
11720 case LPFC_PCI_DEV_LP:
11721 rc = lpfc_pci_resume_one_s3(pdev);
11723 case LPFC_PCI_DEV_OC:
11724 rc = lpfc_pci_resume_one_s4(pdev);
11727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11728 "1426 Invalid PCI device group: 0x%x\n",
11729 phba->pci_dev_grp);
11736 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11737 * @pdev: pointer to PCI device.
11738 * @state: the current PCI connection state.
11740 * This routine is registered to the PCI subsystem for error handling. This
11741 * function is called by the PCI subsystem after a PCI bus error affecting
11742 * this device has been detected. When this routine is invoked, it dispatches
11743 * the action to the proper SLI-3 or SLI-4 device error detected handling
11744 * routine, which will perform the proper error detected operation.
11747 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11748 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11750 static pci_ers_result_t
11751 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11753 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11754 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11755 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11757 switch (phba->pci_dev_grp) {
11758 case LPFC_PCI_DEV_LP:
11759 rc = lpfc_io_error_detected_s3(pdev, state);
11761 case LPFC_PCI_DEV_OC:
11762 rc = lpfc_io_error_detected_s4(pdev, state);
11765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11766 "1427 Invalid PCI device group: 0x%x\n",
11767 phba->pci_dev_grp);
11774 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11775 * @pdev: pointer to PCI device.
11777 * This routine is registered to the PCI subsystem for error handling. This
11778 * function is called after PCI bus has been reset to restart the PCI card
11779 * from scratch, as if from a cold-boot. When this routine is invoked, it
11780 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11781 * routine, which will perform the proper device reset.
11784 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11785 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11787 static pci_ers_result_t
11788 lpfc_io_slot_reset(struct pci_dev *pdev)
11790 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11791 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11792 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11794 switch (phba->pci_dev_grp) {
11795 case LPFC_PCI_DEV_LP:
11796 rc = lpfc_io_slot_reset_s3(pdev);
11798 case LPFC_PCI_DEV_OC:
11799 rc = lpfc_io_slot_reset_s4(pdev);
11802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11803 "1428 Invalid PCI device group: 0x%x\n",
11804 phba->pci_dev_grp);
11811 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11812 * @pdev: pointer to PCI device
11814 * This routine is registered to the PCI subsystem for error handling. It
11815 * is called when kernel error recovery tells the lpfc driver that it is
11816 * OK to resume normal PCI operation after PCI bus error recovery. When
11817 * this routine is invoked, it dispatches the action to the proper SLI-3
11818 * or SLI-4 device io_resume routine, which will resume the device operation.
11821 lpfc_io_resume(struct pci_dev *pdev)
11823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11824 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11826 switch (phba->pci_dev_grp) {
11827 case LPFC_PCI_DEV_LP:
11828 lpfc_io_resume_s3(pdev);
11830 case LPFC_PCI_DEV_OC:
11831 lpfc_io_resume_s4(pdev);
11834 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11835 "1429 Invalid PCI device group: 0x%x\n",
11836 phba->pci_dev_grp);
11843 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11844 * @phba: pointer to lpfc hba data structure.
11846 * This routine checks to see if OAS is supported for this adapter. If
11847 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11848 * the enable oas flag is cleared and the pool created for OAS device data
11853 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11856 if (!phba->cfg_EnableXLane)
11859 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11863 if (phba->device_data_mem_pool)
11864 mempool_destroy(phba->device_data_mem_pool);
11865 phba->device_data_mem_pool = NULL;
11872 * lpfc_fof_queue_setup - Set up all the fof queues
11873 * @phba: pointer to lpfc hba data structure.
11875 * This routine is invoked to set up all the fof queues for the FC HBA
11880 * -ENOMEM - No available memory
11883 lpfc_fof_queue_setup(struct lpfc_hba *phba)
11885 struct lpfc_sli_ring *pring;
11888 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11892 if (phba->cfg_fof) {
11894 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11895 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11899 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11900 phba->sli4_hba.oas_cq, LPFC_FCP);
11904 /* Bind this CQ/WQ to the NVME ring */
11905 pring = phba->sli4_hba.oas_wq->pring;
11906 pring->sli.sli4.wqp =
11907 (void *)phba->sli4_hba.oas_wq;
11908 phba->sli4_hba.oas_cq->pring = pring;
11914 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
11916 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11922 * lpfc_fof_queue_create - Create all the fof queues
11923 * @phba: pointer to lpfc hba data structure.
11925 * This routine is invoked to allocate all the fof queues for the FC HBA
11926 * operation. For each SLI4 queue type, the parameters such as queue entry
11927 * count (queue depth) shall be taken from the module parameter. For now,
11928 * we just use some constant number as place holder.
11932 * -ENOMEM - No availble memory
11933 * -EIO - The mailbox failed to complete successfully.
11936 lpfc_fof_queue_create(struct lpfc_hba *phba)
11938 struct lpfc_queue *qdesc;
11940 /* Create FOF EQ */
11941 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11942 phba->sli4_hba.eq_ecount);
11946 phba->sli4_hba.fof_eq = qdesc;
11948 if (phba->cfg_fof) {
11950 /* Create OAS CQ */
11951 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11952 phba->sli4_hba.cq_ecount);
11956 phba->sli4_hba.oas_cq = qdesc;
11958 /* Create OAS WQ */
11959 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11960 phba->sli4_hba.wq_ecount);
11964 phba->sli4_hba.oas_wq = qdesc;
11965 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
11971 lpfc_fof_queue_destroy(phba);
11976 * lpfc_fof_queue_destroy - Destroy all the fof queues
11977 * @phba: pointer to lpfc hba data structure.
11979 * This routine is invoked to release all the SLI4 queues with the FC HBA
11986 lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11988 /* Release FOF Event queue */
11989 if (phba->sli4_hba.fof_eq != NULL) {
11990 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11991 phba->sli4_hba.fof_eq = NULL;
11994 /* Release OAS Completion queue */
11995 if (phba->sli4_hba.oas_cq != NULL) {
11996 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11997 phba->sli4_hba.oas_cq = NULL;
12000 /* Release OAS Work queue */
12001 if (phba->sli4_hba.oas_wq != NULL) {
12002 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12003 phba->sli4_hba.oas_wq = NULL;
12008 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12010 static const struct pci_error_handlers lpfc_err_handler = {
12011 .error_detected = lpfc_io_error_detected,
12012 .slot_reset = lpfc_io_slot_reset,
12013 .resume = lpfc_io_resume,
12016 static struct pci_driver lpfc_driver = {
12017 .name = LPFC_DRIVER_NAME,
12018 .id_table = lpfc_id_table,
12019 .probe = lpfc_pci_probe_one,
12020 .remove = lpfc_pci_remove_one,
12021 .suspend = lpfc_pci_suspend_one,
12022 .resume = lpfc_pci_resume_one,
12023 .err_handler = &lpfc_err_handler,
12026 static const struct file_operations lpfc_mgmt_fop = {
12027 .owner = THIS_MODULE,
12030 static struct miscdevice lpfc_mgmt_dev = {
12031 .minor = MISC_DYNAMIC_MINOR,
12032 .name = "lpfcmgmt",
12033 .fops = &lpfc_mgmt_fop,
12037 * lpfc_init - lpfc module initialization routine
12039 * This routine is to be invoked when the lpfc module is loaded into the
12040 * kernel. The special kernel macro module_init() is used to indicate the
12041 * role of this routine to the kernel as lpfc module entry point.
12045 * -ENOMEM - FC attach transport failed
12046 * all others - failed
12053 printk(LPFC_MODULE_DESC "\n");
12054 printk(LPFC_COPYRIGHT "\n");
12056 error = misc_register(&lpfc_mgmt_dev);
12058 printk(KERN_ERR "Could not register lpfcmgmt device, "
12059 "misc_register returned with status %d", error);
12061 lpfc_transport_functions.vport_create = lpfc_vport_create;
12062 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
12063 lpfc_transport_template =
12064 fc_attach_transport(&lpfc_transport_functions);
12065 if (lpfc_transport_template == NULL)
12067 lpfc_vport_transport_template =
12068 fc_attach_transport(&lpfc_vport_transport_functions);
12069 if (lpfc_vport_transport_template == NULL) {
12070 fc_release_transport(lpfc_transport_template);
12074 /* Initialize in case vector mapping is needed */
12075 lpfc_used_cpu = NULL;
12076 lpfc_present_cpu = num_present_cpus();
12078 error = pci_register_driver(&lpfc_driver);
12080 fc_release_transport(lpfc_transport_template);
12081 fc_release_transport(lpfc_vport_transport_template);
12088 * lpfc_exit - lpfc module removal routine
12090 * This routine is invoked when the lpfc module is removed from the kernel.
12091 * The special kernel macro module_exit() is used to indicate the role of
12092 * this routine to the kernel as lpfc module exit point.
12097 misc_deregister(&lpfc_mgmt_dev);
12098 pci_unregister_driver(&lpfc_driver);
12099 fc_release_transport(lpfc_transport_template);
12100 fc_release_transport(lpfc_vport_transport_template);
12101 if (_dump_buf_data) {
12102 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12103 "_dump_buf_data at 0x%p\n",
12104 (1L << _dump_buf_data_order), _dump_buf_data);
12105 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12108 if (_dump_buf_dif) {
12109 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12110 "_dump_buf_dif at 0x%p\n",
12111 (1L << _dump_buf_dif_order), _dump_buf_dif);
12112 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12114 kfree(lpfc_used_cpu);
12115 idr_destroy(&lpfc_hba_index);
12118 module_init(lpfc_init);
12119 module_exit(lpfc_exit);
12120 MODULE_LICENSE("GPL");
12121 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
12122 MODULE_AUTHOR("Broadcom");
12123 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);