1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2014 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
28 #include <linux/kthread.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
32 #include <linux/aer.h>
33 #include <linux/slab.h>
34 #include <linux/firmware.h>
35 #include <linux/miscdevice.h>
36 #include <linux/percpu.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi_transport_fc.h>
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
51 #include "lpfc_logmsg.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_version.h"
57 unsigned long _dump_buf_data_order;
59 unsigned long _dump_buf_dif_order;
60 spinlock_t _dump_buf_lock;
62 /* Used when mapping IRQ vectors in a driver centric manner */
63 uint16_t *lpfc_used_cpu;
64 uint32_t lpfc_present_cpu;
66 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
67 static int lpfc_post_rcv_buf(struct lpfc_hba *);
68 static int lpfc_sli4_queue_verify(struct lpfc_hba *);
69 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
70 static int lpfc_setup_endian_order(struct lpfc_hba *);
71 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
72 static void lpfc_free_els_sgl_list(struct lpfc_hba *);
73 static void lpfc_init_sgl_list(struct lpfc_hba *);
74 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
75 static void lpfc_free_active_sgl(struct lpfc_hba *);
76 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
77 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
78 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
79 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
80 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
81 static void lpfc_sli4_disable_intr(struct lpfc_hba *);
82 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
83 static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
85 static struct scsi_transport_template *lpfc_transport_template = NULL;
86 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
87 static DEFINE_IDR(lpfc_hba_index);
90 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
91 * @phba: pointer to lpfc hba data structure.
93 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
94 * mailbox command. It retrieves the revision information from the HBA and
95 * collects the Vital Product Data (VPD) about the HBA for preparing the
96 * configuration of the HBA.
100 * -ERESTART - requests the SLI layer to reset the HBA and try again.
101 * Any other value - indicates an error.
104 lpfc_config_port_prep(struct lpfc_hba *phba)
106 lpfc_vpd_t *vp = &phba->vpd;
110 char *lpfc_vpd_data = NULL;
112 static char licensed[56] =
113 "key unlock for use with gnu public licensed code only\0";
114 static int init_key = 1;
116 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
118 phba->link_state = LPFC_HBA_ERROR;
123 phba->link_state = LPFC_INIT_MBX_CMDS;
125 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
127 uint32_t *ptext = (uint32_t *) licensed;
129 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
130 *ptext = cpu_to_be32(*ptext);
134 lpfc_read_nv(phba, pmb);
135 memset((char*)mb->un.varRDnvp.rsvd3, 0,
136 sizeof (mb->un.varRDnvp.rsvd3));
137 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
140 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
142 if (rc != MBX_SUCCESS) {
143 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
144 "0324 Config Port initialization "
145 "error, mbxCmd x%x READ_NVPARM, "
147 mb->mbxCommand, mb->mbxStatus);
148 mempool_free(pmb, phba->mbox_mem_pool);
151 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
153 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
157 phba->sli3_options = 0x0;
159 /* Setup and issue mailbox READ REV command */
160 lpfc_read_rev(phba, pmb);
161 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
162 if (rc != MBX_SUCCESS) {
163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
164 "0439 Adapter failed to init, mbxCmd x%x "
165 "READ_REV, mbxStatus x%x\n",
166 mb->mbxCommand, mb->mbxStatus);
167 mempool_free( pmb, phba->mbox_mem_pool);
173 * The value of rr must be 1 since the driver set the cv field to 1.
174 * This setting requires the FW to set all revision fields.
176 if (mb->un.varRdRev.rr == 0) {
178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
179 "0440 Adapter failed to init, READ_REV has "
180 "missing revision information.\n");
181 mempool_free(pmb, phba->mbox_mem_pool);
185 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
186 mempool_free(pmb, phba->mbox_mem_pool);
190 /* Save information as VPD data */
192 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
193 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
194 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
195 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
196 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
197 vp->rev.biuRev = mb->un.varRdRev.biuRev;
198 vp->rev.smRev = mb->un.varRdRev.smRev;
199 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
200 vp->rev.endecRev = mb->un.varRdRev.endecRev;
201 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
202 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
203 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
204 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
205 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
206 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
208 /* If the sli feature level is less then 9, we must
209 * tear down all RPIs and VPIs on link down if NPIV
212 if (vp->rev.feaLevelHigh < 9)
213 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
215 if (lpfc_is_LC_HBA(phba->pcidev->device))
216 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
217 sizeof (phba->RandomData));
219 /* Get adapter VPD information */
220 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
224 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
225 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
227 if (rc != MBX_SUCCESS) {
228 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
229 "0441 VPD not present on adapter, "
230 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
231 mb->mbxCommand, mb->mbxStatus);
232 mb->un.varDmp.word_cnt = 0;
234 /* dump mem may return a zero when finished or we got a
235 * mailbox error, either way we are done.
237 if (mb->un.varDmp.word_cnt == 0)
239 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
240 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
241 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
242 lpfc_vpd_data + offset,
243 mb->un.varDmp.word_cnt);
244 offset += mb->un.varDmp.word_cnt;
245 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
246 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
248 kfree(lpfc_vpd_data);
250 mempool_free(pmb, phba->mbox_mem_pool);
255 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
256 * @phba: pointer to lpfc hba data structure.
257 * @pmboxq: pointer to the driver internal queue element for mailbox command.
259 * This is the completion handler for driver's configuring asynchronous event
260 * mailbox command to the device. If the mailbox command returns successfully,
261 * it will set internal async event support flag to 1; otherwise, it will
262 * set internal async event support flag to 0.
265 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
267 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
268 phba->temp_sensor_support = 1;
270 phba->temp_sensor_support = 0;
271 mempool_free(pmboxq, phba->mbox_mem_pool);
276 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
277 * @phba: pointer to lpfc hba data structure.
278 * @pmboxq: pointer to the driver internal queue element for mailbox command.
280 * This is the completion handler for dump mailbox command for getting
281 * wake up parameters. When this command complete, the response contain
282 * Option rom version of the HBA. This function translate the version number
283 * into a human readable string and store it in OptionROMVersion.
286 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
289 uint32_t prog_id_word;
291 /* character array used for decoding dist type. */
292 char dist_char[] = "nabx";
294 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
295 mempool_free(pmboxq, phba->mbox_mem_pool);
299 prg = (struct prog_id *) &prog_id_word;
301 /* word 7 contain option rom version */
302 prog_id_word = pmboxq->u.mb.un.varWords[7];
304 /* Decode the Option rom version word to a readable string */
306 dist = dist_char[prg->dist];
308 if ((prg->dist == 3) && (prg->num == 0))
309 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
310 prg->ver, prg->rev, prg->lev);
312 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
313 prg->ver, prg->rev, prg->lev,
315 mempool_free(pmboxq, phba->mbox_mem_pool);
320 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
321 * cfg_soft_wwnn, cfg_soft_wwpn
322 * @vport: pointer to lpfc vport data structure.
329 lpfc_update_vport_wwn(struct lpfc_vport *vport)
331 /* If the soft name exists then update it using the service params */
332 if (vport->phba->cfg_soft_wwnn)
333 u64_to_wwn(vport->phba->cfg_soft_wwnn,
334 vport->fc_sparam.nodeName.u.wwn);
335 if (vport->phba->cfg_soft_wwpn)
336 u64_to_wwn(vport->phba->cfg_soft_wwpn,
337 vport->fc_sparam.portName.u.wwn);
340 * If the name is empty or there exists a soft name
341 * then copy the service params name, otherwise use the fc name
343 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
344 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
345 sizeof(struct lpfc_name));
347 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
348 sizeof(struct lpfc_name));
350 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
351 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
352 sizeof(struct lpfc_name));
354 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
355 sizeof(struct lpfc_name));
359 * lpfc_config_port_post - Perform lpfc initialization after config port
360 * @phba: pointer to lpfc hba data structure.
362 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
363 * command call. It performs all internal resource and state setups on the
364 * port: post IOCB buffers, enable appropriate host interrupt attentions,
365 * ELS ring timers, etc.
369 * Any other value - error.
372 lpfc_config_port_post(struct lpfc_hba *phba)
374 struct lpfc_vport *vport = phba->pport;
375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
378 struct lpfc_dmabuf *mp;
379 struct lpfc_sli *psli = &phba->sli;
380 uint32_t status, timeout;
384 spin_lock_irq(&phba->hbalock);
386 * If the Config port completed correctly the HBA is not
387 * over heated any more.
389 if (phba->over_temp_state == HBA_OVER_TEMP)
390 phba->over_temp_state = HBA_NORMAL_TEMP;
391 spin_unlock_irq(&phba->hbalock);
393 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
395 phba->link_state = LPFC_HBA_ERROR;
400 /* Get login parameters for NID. */
401 rc = lpfc_read_sparam(phba, pmb, 0);
403 mempool_free(pmb, phba->mbox_mem_pool);
408 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
410 "0448 Adapter failed init, mbxCmd x%x "
411 "READ_SPARM mbxStatus x%x\n",
412 mb->mbxCommand, mb->mbxStatus);
413 phba->link_state = LPFC_HBA_ERROR;
414 mp = (struct lpfc_dmabuf *) pmb->context1;
415 mempool_free(pmb, phba->mbox_mem_pool);
416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
421 mp = (struct lpfc_dmabuf *) pmb->context1;
423 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
424 lpfc_mbuf_free(phba, mp->virt, mp->phys);
426 pmb->context1 = NULL;
427 lpfc_update_vport_wwn(vport);
429 /* Update the fc_host data structures with new wwn. */
430 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
431 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
432 fc_host_max_npiv_vports(shost) = phba->max_vpi;
434 /* If no serial number in VPD data, use low 6 bytes of WWNN */
435 /* This should be consolidated into parse_vpd ? - mr */
436 if (phba->SerialNumber[0] == 0) {
439 outptr = &vport->fc_nodename.u.s.IEEE[0];
440 for (i = 0; i < 12; i++) {
442 j = ((status & 0xf0) >> 4);
444 phba->SerialNumber[i] =
445 (char)((uint8_t) 0x30 + (uint8_t) j);
447 phba->SerialNumber[i] =
448 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
452 phba->SerialNumber[i] =
453 (char)((uint8_t) 0x30 + (uint8_t) j);
455 phba->SerialNumber[i] =
456 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
460 lpfc_read_config(phba, pmb);
462 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
464 "0453 Adapter failed to init, mbxCmd x%x "
465 "READ_CONFIG, mbxStatus x%x\n",
466 mb->mbxCommand, mb->mbxStatus);
467 phba->link_state = LPFC_HBA_ERROR;
468 mempool_free( pmb, phba->mbox_mem_pool);
472 /* Check if the port is disabled */
473 lpfc_sli_read_link_ste(phba);
475 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
476 i = (mb->un.varRdConfig.max_xri + 1);
477 if (phba->cfg_hba_queue_depth > i) {
478 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
479 "3359 HBA queue depth changed from %d to %d\n",
480 phba->cfg_hba_queue_depth, i);
481 phba->cfg_hba_queue_depth = i;
484 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
485 i = (mb->un.varRdConfig.max_xri >> 3);
486 if (phba->pport->cfg_lun_queue_depth > i) {
487 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
488 "3360 LUN queue depth changed from %d to %d\n",
489 phba->pport->cfg_lun_queue_depth, i);
490 phba->pport->cfg_lun_queue_depth = i;
493 phba->lmt = mb->un.varRdConfig.lmt;
495 /* Get the default values for Model Name and Description */
496 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
498 phba->link_state = LPFC_LINK_DOWN;
500 /* Only process IOCBs on ELS ring till hba_state is READY */
501 if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
502 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
503 if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
504 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
505 if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
506 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
508 /* Post receive buffers for desired rings */
509 if (phba->sli_rev != 3)
510 lpfc_post_rcv_buf(phba);
513 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
515 if (phba->intr_type == MSIX) {
516 rc = lpfc_config_msi(phba, pmb);
518 mempool_free(pmb, phba->mbox_mem_pool);
521 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
522 if (rc != MBX_SUCCESS) {
523 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
524 "0352 Config MSI mailbox command "
525 "failed, mbxCmd x%x, mbxStatus x%x\n",
526 pmb->u.mb.mbxCommand,
527 pmb->u.mb.mbxStatus);
528 mempool_free(pmb, phba->mbox_mem_pool);
533 spin_lock_irq(&phba->hbalock);
534 /* Initialize ERATT handling flag */
535 phba->hba_flag &= ~HBA_ERATT_HANDLED;
537 /* Enable appropriate host interrupts */
538 if (lpfc_readl(phba->HCregaddr, &status)) {
539 spin_unlock_irq(&phba->hbalock);
542 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
543 if (psli->num_rings > 0)
544 status |= HC_R0INT_ENA;
545 if (psli->num_rings > 1)
546 status |= HC_R1INT_ENA;
547 if (psli->num_rings > 2)
548 status |= HC_R2INT_ENA;
549 if (psli->num_rings > 3)
550 status |= HC_R3INT_ENA;
552 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
553 (phba->cfg_poll & DISABLE_FCP_RING_INT))
554 status &= ~(HC_R0INT_ENA);
556 writel(status, phba->HCregaddr);
557 readl(phba->HCregaddr); /* flush */
558 spin_unlock_irq(&phba->hbalock);
560 /* Set up ring-0 (ELS) timer */
561 timeout = phba->fc_ratov * 2;
562 mod_timer(&vport->els_tmofunc,
563 jiffies + msecs_to_jiffies(1000 * timeout));
564 /* Set up heart beat (HB) timer */
565 mod_timer(&phba->hb_tmofunc,
566 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
567 phba->hb_outstanding = 0;
568 phba->last_completion_time = jiffies;
569 /* Set up error attention (ERATT) polling timer */
570 mod_timer(&phba->eratt_poll,
571 jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
573 if (phba->hba_flag & LINK_DISABLED) {
574 lpfc_printf_log(phba,
576 "2598 Adapter Link is disabled.\n");
577 lpfc_down_link(phba, pmb);
578 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
579 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
580 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
581 lpfc_printf_log(phba,
583 "2599 Adapter failed to issue DOWN_LINK"
584 " mbox command rc 0x%x\n", rc);
586 mempool_free(pmb, phba->mbox_mem_pool);
589 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
590 mempool_free(pmb, phba->mbox_mem_pool);
591 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
595 /* MBOX buffer will be freed in mbox compl */
596 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
598 phba->link_state = LPFC_HBA_ERROR;
602 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
603 pmb->mbox_cmpl = lpfc_config_async_cmpl;
604 pmb->vport = phba->pport;
605 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
607 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
608 lpfc_printf_log(phba,
611 "0456 Adapter failed to issue "
612 "ASYNCEVT_ENABLE mbox status x%x\n",
614 mempool_free(pmb, phba->mbox_mem_pool);
617 /* Get Option rom version */
618 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
620 phba->link_state = LPFC_HBA_ERROR;
624 lpfc_dump_wakeup_param(phba, pmb);
625 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
626 pmb->vport = phba->pport;
627 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
629 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
631 "to get Option ROM version status x%x\n", rc);
632 mempool_free(pmb, phba->mbox_mem_pool);
639 * lpfc_hba_init_link - Initialize the FC link
640 * @phba: pointer to lpfc hba data structure.
641 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
643 * This routine will issue the INIT_LINK mailbox command call.
644 * It is available to other drivers through the lpfc_hba data
645 * structure for use as a delayed link up mechanism with the
646 * module parameter lpfc_suppress_link_up.
650 * Any other value - error
653 lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
655 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
659 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
660 * @phba: pointer to lpfc hba data structure.
661 * @fc_topology: desired fc topology.
662 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
664 * This routine will issue the INIT_LINK mailbox command call.
665 * It is available to other drivers through the lpfc_hba data
666 * structure for use as a delayed link up mechanism with the
667 * module parameter lpfc_suppress_link_up.
671 * Any other value - error
674 lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
677 struct lpfc_vport *vport = phba->pport;
682 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
684 phba->link_state = LPFC_HBA_ERROR;
690 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
691 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
692 !(phba->lmt & LMT_1Gb)) ||
693 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
694 !(phba->lmt & LMT_2Gb)) ||
695 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
696 !(phba->lmt & LMT_4Gb)) ||
697 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
698 !(phba->lmt & LMT_8Gb)) ||
699 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
700 !(phba->lmt & LMT_10Gb)) ||
701 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
702 !(phba->lmt & LMT_16Gb))) {
703 /* Reset link speed to auto */
704 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
705 "1302 Invalid speed for this board:%d "
706 "Reset link speed to auto.\n",
707 phba->cfg_link_speed);
708 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
710 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
711 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
712 if (phba->sli_rev < LPFC_SLI_REV4)
713 lpfc_set_loopback_flag(phba);
714 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
715 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
717 "0498 Adapter failed to init, mbxCmd x%x "
718 "INIT_LINK, mbxStatus x%x\n",
719 mb->mbxCommand, mb->mbxStatus);
720 if (phba->sli_rev <= LPFC_SLI_REV3) {
721 /* Clear all interrupt enable conditions */
722 writel(0, phba->HCregaddr);
723 readl(phba->HCregaddr); /* flush */
724 /* Clear all pending interrupts */
725 writel(0xffffffff, phba->HAregaddr);
726 readl(phba->HAregaddr); /* flush */
728 phba->link_state = LPFC_HBA_ERROR;
729 if (rc != MBX_BUSY || flag == MBX_POLL)
730 mempool_free(pmb, phba->mbox_mem_pool);
733 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
734 if (flag == MBX_POLL)
735 mempool_free(pmb, phba->mbox_mem_pool);
741 * lpfc_hba_down_link - this routine downs the FC link
742 * @phba: pointer to lpfc hba data structure.
743 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
745 * This routine will issue the DOWN_LINK mailbox command call.
746 * It is available to other drivers through the lpfc_hba data
747 * structure for use to stop the link.
751 * Any other value - error
754 lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
759 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
761 phba->link_state = LPFC_HBA_ERROR;
765 lpfc_printf_log(phba,
767 "0491 Adapter Link is disabled.\n");
768 lpfc_down_link(phba, pmb);
769 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
770 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
771 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
772 lpfc_printf_log(phba,
774 "2522 Adapter failed to issue DOWN_LINK"
775 " mbox command rc 0x%x\n", rc);
777 mempool_free(pmb, phba->mbox_mem_pool);
780 if (flag == MBX_POLL)
781 mempool_free(pmb, phba->mbox_mem_pool);
787 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
788 * @phba: pointer to lpfc HBA data structure.
790 * This routine will do LPFC uninitialization before the HBA is reset when
791 * bringing down the SLI Layer.
795 * Any other value - error.
798 lpfc_hba_down_prep(struct lpfc_hba *phba)
800 struct lpfc_vport **vports;
803 if (phba->sli_rev <= LPFC_SLI_REV3) {
804 /* Disable interrupts */
805 writel(0, phba->HCregaddr);
806 readl(phba->HCregaddr); /* flush */
809 if (phba->pport->load_flag & FC_UNLOADING)
810 lpfc_cleanup_discovery_resources(phba->pport);
812 vports = lpfc_create_vport_work_array(phba);
814 for (i = 0; i <= phba->max_vports &&
815 vports[i] != NULL; i++)
816 lpfc_cleanup_discovery_resources(vports[i]);
817 lpfc_destroy_vport_work_array(phba, vports);
823 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
824 * rspiocb which got deferred
826 * @phba: pointer to lpfc HBA data structure.
828 * This routine will cleanup completed slow path events after HBA is reset
829 * when bringing down the SLI Layer.
836 lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
838 struct lpfc_iocbq *rspiocbq;
839 struct hbq_dmabuf *dmabuf;
840 struct lpfc_cq_event *cq_event;
842 spin_lock_irq(&phba->hbalock);
843 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
844 spin_unlock_irq(&phba->hbalock);
846 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
847 /* Get the response iocb from the head of work queue */
848 spin_lock_irq(&phba->hbalock);
849 list_remove_head(&phba->sli4_hba.sp_queue_event,
850 cq_event, struct lpfc_cq_event, list);
851 spin_unlock_irq(&phba->hbalock);
853 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
854 case CQE_CODE_COMPL_WQE:
855 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
857 lpfc_sli_release_iocbq(phba, rspiocbq);
859 case CQE_CODE_RECEIVE:
860 case CQE_CODE_RECEIVE_V1:
861 dmabuf = container_of(cq_event, struct hbq_dmabuf,
863 lpfc_in_buf_free(phba, &dmabuf->dbuf);
869 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
870 * @phba: pointer to lpfc HBA data structure.
872 * This routine will cleanup posted ELS buffers after the HBA is reset
873 * when bringing down the SLI Layer.
880 lpfc_hba_free_post_buf(struct lpfc_hba *phba)
882 struct lpfc_sli *psli = &phba->sli;
883 struct lpfc_sli_ring *pring;
884 struct lpfc_dmabuf *mp, *next_mp;
888 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
889 lpfc_sli_hbqbuf_free_all(phba);
891 /* Cleanup preposted buffers on the ELS ring */
892 pring = &psli->ring[LPFC_ELS_RING];
893 spin_lock_irq(&phba->hbalock);
894 list_splice_init(&pring->postbufq, &buflist);
895 spin_unlock_irq(&phba->hbalock);
898 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
901 lpfc_mbuf_free(phba, mp->virt, mp->phys);
905 spin_lock_irq(&phba->hbalock);
906 pring->postbufq_cnt -= count;
907 spin_unlock_irq(&phba->hbalock);
912 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
913 * @phba: pointer to lpfc HBA data structure.
915 * This routine will cleanup the txcmplq after the HBA is reset when bringing
916 * down the SLI Layer.
922 lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
924 struct lpfc_sli *psli = &phba->sli;
925 struct lpfc_sli_ring *pring;
926 LIST_HEAD(completions);
929 for (i = 0; i < psli->num_rings; i++) {
930 pring = &psli->ring[i];
931 if (phba->sli_rev >= LPFC_SLI_REV4)
932 spin_lock_irq(&pring->ring_lock);
934 spin_lock_irq(&phba->hbalock);
935 /* At this point in time the HBA is either reset or DOA. Either
936 * way, nothing should be on txcmplq as it will NEVER complete.
938 list_splice_init(&pring->txcmplq, &completions);
939 pring->txcmplq_cnt = 0;
941 if (phba->sli_rev >= LPFC_SLI_REV4)
942 spin_unlock_irq(&pring->ring_lock);
944 spin_unlock_irq(&phba->hbalock);
946 /* Cancel all the IOCBs from the completions list */
947 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
949 lpfc_sli_abort_iocb_ring(phba, pring);
954 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
956 * @phba: pointer to lpfc HBA data structure.
958 * This routine will do uninitialization after the HBA is reset when bring
959 * down the SLI Layer.
963 * Any other value - error.
966 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
968 lpfc_hba_free_post_buf(phba);
969 lpfc_hba_clean_txcmplq(phba);
974 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
975 * @phba: pointer to lpfc HBA data structure.
977 * This routine will do uninitialization after the HBA is reset when bring
978 * down the SLI Layer.
982 * Any other value - error.
985 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
987 struct lpfc_scsi_buf *psb, *psb_next;
989 unsigned long iflag = 0;
990 struct lpfc_sglq *sglq_entry = NULL;
991 struct lpfc_sli *psli = &phba->sli;
992 struct lpfc_sli_ring *pring;
994 lpfc_hba_free_post_buf(phba);
995 lpfc_hba_clean_txcmplq(phba);
996 pring = &psli->ring[LPFC_ELS_RING];
998 /* At this point in time the HBA is either reset or DOA. Either
999 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1000 * on the lpfc_sgl_list so that it can either be freed if the
1001 * driver is unloading or reposted if the driver is restarting
1004 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
1006 /* abts_sgl_list_lock required because worker thread uses this
1009 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
1010 list_for_each_entry(sglq_entry,
1011 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1012 sglq_entry->state = SGL_FREED;
1014 spin_lock(&pring->ring_lock);
1015 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1016 &phba->sli4_hba.lpfc_sgl_list);
1017 spin_unlock(&pring->ring_lock);
1018 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
1019 /* abts_scsi_buf_list_lock required because worker thread uses this
1022 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1023 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1025 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1026 spin_unlock_irq(&phba->hbalock);
1028 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1030 psb->status = IOSTAT_SUCCESS;
1032 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1033 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1034 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
1036 lpfc_sli4_free_sp_events(phba);
1041 * lpfc_hba_down_post - Wrapper func for hba down post routine
1042 * @phba: pointer to lpfc HBA data structure.
1044 * This routine wraps the actual SLI3 or SLI4 routine for performing
1045 * uninitialization after the HBA is reset when bring down the SLI Layer.
1049 * Any other value - error.
1052 lpfc_hba_down_post(struct lpfc_hba *phba)
1054 return (*phba->lpfc_hba_down_post)(phba);
1058 * lpfc_hb_timeout - The HBA-timer timeout handler
1059 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1061 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1062 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1063 * work-port-events bitmap and the worker thread is notified. This timeout
1064 * event will be used by the worker thread to invoke the actual timeout
1065 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1066 * be performed in the timeout handler and the HBA timeout event bit shall
1067 * be cleared by the worker thread after it has taken the event bitmap out.
1070 lpfc_hb_timeout(unsigned long ptr)
1072 struct lpfc_hba *phba;
1073 uint32_t tmo_posted;
1074 unsigned long iflag;
1076 phba = (struct lpfc_hba *)ptr;
1078 /* Check for heart beat timeout conditions */
1079 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1080 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1082 phba->pport->work_port_events |= WORKER_HB_TMO;
1083 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1085 /* Tell the worker thread there is work to do */
1087 lpfc_worker_wake_up(phba);
1092 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1093 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1095 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1096 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1097 * work-port-events bitmap and the worker thread is notified. This timeout
1098 * event will be used by the worker thread to invoke the actual timeout
1099 * handler routine, lpfc_rrq_handler. Any periodical operations will
1100 * be performed in the timeout handler and the RRQ timeout event bit shall
1101 * be cleared by the worker thread after it has taken the event bitmap out.
1104 lpfc_rrq_timeout(unsigned long ptr)
1106 struct lpfc_hba *phba;
1107 unsigned long iflag;
1109 phba = (struct lpfc_hba *)ptr;
1110 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
1111 if (!(phba->pport->load_flag & FC_UNLOADING))
1112 phba->hba_flag |= HBA_RRQ_ACTIVE;
1114 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1115 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1117 if (!(phba->pport->load_flag & FC_UNLOADING))
1118 lpfc_worker_wake_up(phba);
1122 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1123 * @phba: pointer to lpfc hba data structure.
1124 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1126 * This is the callback function to the lpfc heart-beat mailbox command.
1127 * If configured, the lpfc driver issues the heart-beat mailbox command to
1128 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1129 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1130 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1131 * heart-beat outstanding state. Once the mailbox command comes back and
1132 * no error conditions detected, the heart-beat mailbox command timer is
1133 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1134 * state is cleared for the next heart-beat. If the timer expired with the
1135 * heart-beat outstanding state set, the driver will put the HBA offline.
1138 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1140 unsigned long drvr_flag;
1142 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1143 phba->hb_outstanding = 0;
1144 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1146 /* Check and reset heart-beat timer is necessary */
1147 mempool_free(pmboxq, phba->mbox_mem_pool);
1148 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1149 !(phba->link_state == LPFC_HBA_ERROR) &&
1150 !(phba->pport->load_flag & FC_UNLOADING))
1151 mod_timer(&phba->hb_tmofunc,
1153 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1158 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1159 * @phba: pointer to lpfc hba data structure.
1161 * This is the actual HBA-timer timeout handler to be invoked by the worker
1162 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1163 * handler performs any periodic operations needed for the device. If such
1164 * periodic event has already been attended to either in the interrupt handler
1165 * or by processing slow-ring or fast-ring events within the HBA-timer
1166 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1167 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1168 * is configured and there is no heart-beat mailbox command outstanding, a
1169 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1170 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1174 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1176 struct lpfc_vport **vports;
1177 LPFC_MBOXQ_t *pmboxq;
1178 struct lpfc_dmabuf *buf_ptr;
1180 struct lpfc_sli *psli = &phba->sli;
1181 LIST_HEAD(completions);
1183 vports = lpfc_create_vport_work_array(phba);
1185 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1186 lpfc_rcv_seq_check_edtov(vports[i]);
1187 lpfc_destroy_vport_work_array(phba, vports);
1189 if ((phba->link_state == LPFC_HBA_ERROR) ||
1190 (phba->pport->load_flag & FC_UNLOADING) ||
1191 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1194 spin_lock_irq(&phba->pport->work_port_lock);
1196 if (time_after(phba->last_completion_time +
1197 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1199 spin_unlock_irq(&phba->pport->work_port_lock);
1200 if (!phba->hb_outstanding)
1201 mod_timer(&phba->hb_tmofunc,
1203 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1205 mod_timer(&phba->hb_tmofunc,
1207 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1210 spin_unlock_irq(&phba->pport->work_port_lock);
1212 if (phba->elsbuf_cnt &&
1213 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1214 spin_lock_irq(&phba->hbalock);
1215 list_splice_init(&phba->elsbuf, &completions);
1216 phba->elsbuf_cnt = 0;
1217 phba->elsbuf_prev_cnt = 0;
1218 spin_unlock_irq(&phba->hbalock);
1220 while (!list_empty(&completions)) {
1221 list_remove_head(&completions, buf_ptr,
1222 struct lpfc_dmabuf, list);
1223 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1227 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1229 /* If there is no heart beat outstanding, issue a heartbeat command */
1230 if (phba->cfg_enable_hba_heartbeat) {
1231 if (!phba->hb_outstanding) {
1232 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1233 (list_empty(&psli->mboxq))) {
1234 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1237 mod_timer(&phba->hb_tmofunc,
1239 msecs_to_jiffies(1000 *
1240 LPFC_HB_MBOX_INTERVAL));
1244 lpfc_heart_beat(phba, pmboxq);
1245 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1246 pmboxq->vport = phba->pport;
1247 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1250 if (retval != MBX_BUSY &&
1251 retval != MBX_SUCCESS) {
1252 mempool_free(pmboxq,
1253 phba->mbox_mem_pool);
1254 mod_timer(&phba->hb_tmofunc,
1256 msecs_to_jiffies(1000 *
1257 LPFC_HB_MBOX_INTERVAL));
1260 phba->skipped_hb = 0;
1261 phba->hb_outstanding = 1;
1262 } else if (time_before_eq(phba->last_completion_time,
1263 phba->skipped_hb)) {
1264 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1265 "2857 Last completion time not "
1266 " updated in %d ms\n",
1267 jiffies_to_msecs(jiffies
1268 - phba->last_completion_time));
1270 phba->skipped_hb = jiffies;
1272 mod_timer(&phba->hb_tmofunc,
1274 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1278 * If heart beat timeout called with hb_outstanding set
1279 * we need to give the hb mailbox cmd a chance to
1282 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1283 "0459 Adapter heartbeat still out"
1284 "standing:last compl time was %d ms.\n",
1285 jiffies_to_msecs(jiffies
1286 - phba->last_completion_time));
1287 mod_timer(&phba->hb_tmofunc,
1289 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1295 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1296 * @phba: pointer to lpfc hba data structure.
1298 * This routine is called to bring the HBA offline when HBA hardware error
1299 * other than Port Error 6 has been detected.
1302 lpfc_offline_eratt(struct lpfc_hba *phba)
1304 struct lpfc_sli *psli = &phba->sli;
1306 spin_lock_irq(&phba->hbalock);
1307 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1308 spin_unlock_irq(&phba->hbalock);
1309 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1312 lpfc_reset_barrier(phba);
1313 spin_lock_irq(&phba->hbalock);
1314 lpfc_sli_brdreset(phba);
1315 spin_unlock_irq(&phba->hbalock);
1316 lpfc_hba_down_post(phba);
1317 lpfc_sli_brdready(phba, HS_MBRDY);
1318 lpfc_unblock_mgmt_io(phba);
1319 phba->link_state = LPFC_HBA_ERROR;
1324 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1325 * @phba: pointer to lpfc hba data structure.
1327 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1328 * other than Port Error 6 has been detected.
1331 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1333 spin_lock_irq(&phba->hbalock);
1334 phba->link_state = LPFC_HBA_ERROR;
1335 spin_unlock_irq(&phba->hbalock);
1337 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1339 lpfc_hba_down_post(phba);
1340 lpfc_unblock_mgmt_io(phba);
1344 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1345 * @phba: pointer to lpfc hba data structure.
1347 * This routine is invoked to handle the deferred HBA hardware error
1348 * conditions. This type of error is indicated by HBA by setting ER1
1349 * and another ER bit in the host status register. The driver will
1350 * wait until the ER1 bit clears before handling the error condition.
1353 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1355 uint32_t old_host_status = phba->work_hs;
1356 struct lpfc_sli *psli = &phba->sli;
1358 /* If the pci channel is offline, ignore possible errors,
1359 * since we cannot communicate with the pci card anyway.
1361 if (pci_channel_offline(phba->pcidev)) {
1362 spin_lock_irq(&phba->hbalock);
1363 phba->hba_flag &= ~DEFER_ERATT;
1364 spin_unlock_irq(&phba->hbalock);
1368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1369 "0479 Deferred Adapter Hardware Error "
1370 "Data: x%x x%x x%x\n",
1372 phba->work_status[0], phba->work_status[1]);
1374 spin_lock_irq(&phba->hbalock);
1375 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1376 spin_unlock_irq(&phba->hbalock);
1380 * Firmware stops when it triggred erratt. That could cause the I/Os
1381 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1382 * SCSI layer retry it after re-establishing link.
1384 lpfc_sli_abort_fcp_rings(phba);
1387 * There was a firmware error. Take the hba offline and then
1388 * attempt to restart it.
1390 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
1393 /* Wait for the ER1 bit to clear.*/
1394 while (phba->work_hs & HS_FFER1) {
1396 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1397 phba->work_hs = UNPLUG_ERR ;
1400 /* If driver is unloading let the worker thread continue */
1401 if (phba->pport->load_flag & FC_UNLOADING) {
1408 * This is to ptrotect against a race condition in which
1409 * first write to the host attention register clear the
1410 * host status register.
1412 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1413 phba->work_hs = old_host_status & ~HS_FFER1;
1415 spin_lock_irq(&phba->hbalock);
1416 phba->hba_flag &= ~DEFER_ERATT;
1417 spin_unlock_irq(&phba->hbalock);
1418 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1419 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1423 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1425 struct lpfc_board_event_header board_event;
1426 struct Scsi_Host *shost;
1428 board_event.event_type = FC_REG_BOARD_EVENT;
1429 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1430 shost = lpfc_shost_from_vport(phba->pport);
1431 fc_host_post_vendor_event(shost, fc_get_event_number(),
1432 sizeof(board_event),
1433 (char *) &board_event,
1438 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1439 * @phba: pointer to lpfc hba data structure.
1441 * This routine is invoked to handle the following HBA hardware error
1443 * 1 - HBA error attention interrupt
1444 * 2 - DMA ring index out of range
1445 * 3 - Mailbox command came back as unknown
1448 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1450 struct lpfc_vport *vport = phba->pport;
1451 struct lpfc_sli *psli = &phba->sli;
1452 uint32_t event_data;
1453 unsigned long temperature;
1454 struct temp_event temp_event_data;
1455 struct Scsi_Host *shost;
1457 /* If the pci channel is offline, ignore possible errors,
1458 * since we cannot communicate with the pci card anyway.
1460 if (pci_channel_offline(phba->pcidev)) {
1461 spin_lock_irq(&phba->hbalock);
1462 phba->hba_flag &= ~DEFER_ERATT;
1463 spin_unlock_irq(&phba->hbalock);
1467 /* If resets are disabled then leave the HBA alone and return */
1468 if (!phba->cfg_enable_hba_reset)
1471 /* Send an internal error event to mgmt application */
1472 lpfc_board_errevt_to_mgmt(phba);
1474 if (phba->hba_flag & DEFER_ERATT)
1475 lpfc_handle_deferred_eratt(phba);
1477 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1478 if (phba->work_hs & HS_FFER6)
1479 /* Re-establishing Link */
1480 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1481 "1301 Re-establishing Link "
1482 "Data: x%x x%x x%x\n",
1483 phba->work_hs, phba->work_status[0],
1484 phba->work_status[1]);
1485 if (phba->work_hs & HS_FFER8)
1486 /* Device Zeroization */
1487 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1488 "2861 Host Authentication device "
1489 "zeroization Data:x%x x%x x%x\n",
1490 phba->work_hs, phba->work_status[0],
1491 phba->work_status[1]);
1493 spin_lock_irq(&phba->hbalock);
1494 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
1495 spin_unlock_irq(&phba->hbalock);
1498 * Firmware stops when it triggled erratt with HS_FFER6.
1499 * That could cause the I/Os dropped by the firmware.
1500 * Error iocb (I/O) on txcmplq and let the SCSI layer
1501 * retry it after re-establishing link.
1503 lpfc_sli_abort_fcp_rings(phba);
1506 * There was a firmware error. Take the hba offline and then
1507 * attempt to restart it.
1509 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
1511 lpfc_sli_brdrestart(phba);
1512 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1513 lpfc_unblock_mgmt_io(phba);
1516 lpfc_unblock_mgmt_io(phba);
1517 } else if (phba->work_hs & HS_CRIT_TEMP) {
1518 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1519 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1520 temp_event_data.event_code = LPFC_CRIT_TEMP;
1521 temp_event_data.data = (uint32_t)temperature;
1523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1524 "0406 Adapter maximum temperature exceeded "
1525 "(%ld), taking this port offline "
1526 "Data: x%x x%x x%x\n",
1527 temperature, phba->work_hs,
1528 phba->work_status[0], phba->work_status[1]);
1530 shost = lpfc_shost_from_vport(phba->pport);
1531 fc_host_post_vendor_event(shost, fc_get_event_number(),
1532 sizeof(temp_event_data),
1533 (char *) &temp_event_data,
1534 SCSI_NL_VID_TYPE_PCI
1535 | PCI_VENDOR_ID_EMULEX);
1537 spin_lock_irq(&phba->hbalock);
1538 phba->over_temp_state = HBA_OVER_TEMP;
1539 spin_unlock_irq(&phba->hbalock);
1540 lpfc_offline_eratt(phba);
1543 /* The if clause above forces this code path when the status
1544 * failure is a value other than FFER6. Do not call the offline
1545 * twice. This is the adapter hardware error path.
1547 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1548 "0457 Adapter Hardware Error "
1549 "Data: x%x x%x x%x\n",
1551 phba->work_status[0], phba->work_status[1]);
1553 event_data = FC_REG_DUMP_EVENT;
1554 shost = lpfc_shost_from_vport(vport);
1555 fc_host_post_vendor_event(shost, fc_get_event_number(),
1556 sizeof(event_data), (char *) &event_data,
1557 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1559 lpfc_offline_eratt(phba);
1565 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1566 * @phba: pointer to lpfc hba data structure.
1567 * @mbx_action: flag for mailbox shutdown action.
1569 * This routine is invoked to perform an SLI4 port PCI function reset in
1570 * response to port status register polling attention. It waits for port
1571 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1572 * During this process, interrupt vectors are freed and later requested
1573 * for handling possible port resource change.
1576 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1583 * On error status condition, driver need to wait for port
1584 * ready before performing reset.
1586 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1588 /* need reset: attempt for port recovery */
1590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1591 "2887 Reset Needed: Attempting Port "
1593 lpfc_offline_prep(phba, mbx_action);
1595 /* release interrupt for possible resource change */
1596 lpfc_sli4_disable_intr(phba);
1597 lpfc_sli_brdrestart(phba);
1598 /* request and enable interrupt */
1599 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1600 if (intr_mode == LPFC_INTR_ERROR) {
1601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1602 "3175 Failed to enable interrupt\n");
1605 phba->intr_mode = intr_mode;
1607 rc = lpfc_online(phba);
1609 lpfc_unblock_mgmt_io(phba);
1615 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1616 * @phba: pointer to lpfc hba data structure.
1618 * This routine is invoked to handle the SLI4 HBA hardware error attention
1622 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1624 struct lpfc_vport *vport = phba->pport;
1625 uint32_t event_data;
1626 struct Scsi_Host *shost;
1628 struct lpfc_register portstat_reg = {0};
1629 uint32_t reg_err1, reg_err2;
1630 uint32_t uerrlo_reg, uemasklo_reg;
1631 uint32_t pci_rd_rc1, pci_rd_rc2;
1632 bool en_rn_msg = true;
1633 struct temp_event temp_event_data;
1636 /* If the pci channel is offline, ignore possible errors, since
1637 * we cannot communicate with the pci card anyway.
1639 if (pci_channel_offline(phba->pcidev))
1642 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1644 case LPFC_SLI_INTF_IF_TYPE_0:
1645 pci_rd_rc1 = lpfc_readl(
1646 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1648 pci_rd_rc2 = lpfc_readl(
1649 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1651 /* consider PCI bus read error as pci_channel_offline */
1652 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1654 lpfc_sli4_offline_eratt(phba);
1657 case LPFC_SLI_INTF_IF_TYPE_2:
1658 pci_rd_rc1 = lpfc_readl(
1659 phba->sli4_hba.u.if_type2.STATUSregaddr,
1660 &portstat_reg.word0);
1661 /* consider PCI bus read error as pci_channel_offline */
1662 if (pci_rd_rc1 == -EIO) {
1663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1664 "3151 PCI bus read access failure: x%x\n",
1665 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
1668 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1669 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
1670 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1672 "2889 Port Overtemperature event, "
1673 "taking port offline Data: x%x x%x\n",
1674 reg_err1, reg_err2);
1676 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1677 temp_event_data.event_code = LPFC_CRIT_TEMP;
1678 temp_event_data.data = 0xFFFFFFFF;
1680 shost = lpfc_shost_from_vport(phba->pport);
1681 fc_host_post_vendor_event(shost, fc_get_event_number(),
1682 sizeof(temp_event_data),
1683 (char *)&temp_event_data,
1684 SCSI_NL_VID_TYPE_PCI
1685 | PCI_VENDOR_ID_EMULEX);
1687 spin_lock_irq(&phba->hbalock);
1688 phba->over_temp_state = HBA_OVER_TEMP;
1689 spin_unlock_irq(&phba->hbalock);
1690 lpfc_sli4_offline_eratt(phba);
1693 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1694 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
1695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1696 "3143 Port Down: Firmware Update "
1699 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1700 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1702 "3144 Port Down: Debug Dump\n");
1703 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1704 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1706 "3145 Port Down: Provisioning\n");
1708 /* If resets are disabled then leave the HBA alone and return */
1709 if (!phba->cfg_enable_hba_reset)
1712 /* Check port status register for function reset */
1713 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1716 /* don't report event on forced debug dump */
1717 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1718 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1723 /* fall through for not able to recover */
1724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1725 "3152 Unrecoverable error, bring the port "
1727 lpfc_sli4_offline_eratt(phba);
1729 case LPFC_SLI_INTF_IF_TYPE_1:
1733 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1734 "3123 Report dump event to upper layer\n");
1735 /* Send an internal error event to mgmt application */
1736 lpfc_board_errevt_to_mgmt(phba);
1738 event_data = FC_REG_DUMP_EVENT;
1739 shost = lpfc_shost_from_vport(vport);
1740 fc_host_post_vendor_event(shost, fc_get_event_number(),
1741 sizeof(event_data), (char *) &event_data,
1742 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1746 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1747 * @phba: pointer to lpfc HBA data structure.
1749 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1750 * routine from the API jump table function pointer from the lpfc_hba struct.
1754 * Any other value - error.
1757 lpfc_handle_eratt(struct lpfc_hba *phba)
1759 (*phba->lpfc_handle_eratt)(phba);
1763 * lpfc_handle_latt - The HBA link event handler
1764 * @phba: pointer to lpfc hba data structure.
1766 * This routine is invoked from the worker thread to handle a HBA host
1767 * attention link event.
1770 lpfc_handle_latt(struct lpfc_hba *phba)
1772 struct lpfc_vport *vport = phba->pport;
1773 struct lpfc_sli *psli = &phba->sli;
1775 volatile uint32_t control;
1776 struct lpfc_dmabuf *mp;
1779 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1782 goto lpfc_handle_latt_err_exit;
1785 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1788 goto lpfc_handle_latt_free_pmb;
1791 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1794 goto lpfc_handle_latt_free_mp;
1797 /* Cleanup any outstanding ELS commands */
1798 lpfc_els_flush_all_cmd(phba);
1800 psli->slistat.link_event++;
1801 lpfc_read_topology(phba, pmb, mp);
1802 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
1804 /* Block ELS IOCBs until we have processed this mbox command */
1805 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
1806 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
1807 if (rc == MBX_NOT_FINISHED) {
1809 goto lpfc_handle_latt_free_mbuf;
1812 /* Clear Link Attention in HA REG */
1813 spin_lock_irq(&phba->hbalock);
1814 writel(HA_LATT, phba->HAregaddr);
1815 readl(phba->HAregaddr); /* flush */
1816 spin_unlock_irq(&phba->hbalock);
1820 lpfc_handle_latt_free_mbuf:
1821 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1822 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1823 lpfc_handle_latt_free_mp:
1825 lpfc_handle_latt_free_pmb:
1826 mempool_free(pmb, phba->mbox_mem_pool);
1827 lpfc_handle_latt_err_exit:
1828 /* Enable Link attention interrupts */
1829 spin_lock_irq(&phba->hbalock);
1830 psli->sli_flag |= LPFC_PROCESS_LA;
1831 control = readl(phba->HCregaddr);
1832 control |= HC_LAINT_ENA;
1833 writel(control, phba->HCregaddr);
1834 readl(phba->HCregaddr); /* flush */
1836 /* Clear Link Attention in HA REG */
1837 writel(HA_LATT, phba->HAregaddr);
1838 readl(phba->HAregaddr); /* flush */
1839 spin_unlock_irq(&phba->hbalock);
1840 lpfc_linkdown(phba);
1841 phba->link_state = LPFC_HBA_ERROR;
1843 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1844 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
1850 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1851 * @phba: pointer to lpfc hba data structure.
1852 * @vpd: pointer to the vital product data.
1853 * @len: length of the vital product data in bytes.
1855 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1856 * an array of characters. In this routine, the ModelName, ProgramType, and
1857 * ModelDesc, etc. fields of the phba data structure will be populated.
1860 * 0 - pointer to the VPD passed in is NULL
1864 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
1866 uint8_t lenlo, lenhi;
1876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1877 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1878 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1880 while (!finished && (index < (len - 4))) {
1881 switch (vpd[index]) {
1889 i = ((((unsigned short)lenhi) << 8) + lenlo);
1898 Length = ((((unsigned short)lenhi) << 8) + lenlo);
1899 if (Length > len - index)
1900 Length = len - index;
1901 while (Length > 0) {
1902 /* Look for Serial Number */
1903 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1910 phba->SerialNumber[j++] = vpd[index++];
1914 phba->SerialNumber[j] = 0;
1917 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1918 phba->vpd_flag |= VPD_MODEL_DESC;
1925 phba->ModelDesc[j++] = vpd[index++];
1929 phba->ModelDesc[j] = 0;
1932 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1933 phba->vpd_flag |= VPD_MODEL_NAME;
1940 phba->ModelName[j++] = vpd[index++];
1944 phba->ModelName[j] = 0;
1947 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1948 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1955 phba->ProgramType[j++] = vpd[index++];
1959 phba->ProgramType[j] = 0;
1962 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1963 phba->vpd_flag |= VPD_PORT;
1970 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1971 (phba->sli4_hba.pport_name_sta ==
1972 LPFC_SLI4_PPNAME_GET)) {
1976 phba->Port[j++] = vpd[index++];
1980 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1981 (phba->sli4_hba.pport_name_sta ==
1982 LPFC_SLI4_PPNAME_NON))
2009 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2010 * @phba: pointer to lpfc hba data structure.
2011 * @mdp: pointer to the data structure to hold the derived model name.
2012 * @descp: pointer to the data structure to hold the derived description.
2014 * This routine retrieves HBA's description based on its registered PCI device
2015 * ID. The @descp passed into this function points to an array of 256 chars. It
2016 * shall be returned with the model name, maximum speed, and the host bus type.
2017 * The @mdp passed into this function points to an array of 80 chars. When the
2018 * function returns, the @mdp will be filled with the model name.
2021 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
2024 uint16_t dev_id = phba->pcidev->device;
2027 int oneConnect = 0; /* default is not a oneConnect */
2032 } m = {"<Unknown>", "", ""};
2034 if (mdp && mdp[0] != '\0'
2035 && descp && descp[0] != '\0')
2038 if (phba->lmt & LMT_16Gb)
2040 else if (phba->lmt & LMT_10Gb)
2042 else if (phba->lmt & LMT_8Gb)
2044 else if (phba->lmt & LMT_4Gb)
2046 else if (phba->lmt & LMT_2Gb)
2048 else if (phba->lmt & LMT_1Gb)
2056 case PCI_DEVICE_ID_FIREFLY:
2057 m = (typeof(m)){"LP6000", "PCI",
2058 "Obsolete, Unsupported Fibre Channel Adapter"};
2060 case PCI_DEVICE_ID_SUPERFLY:
2061 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
2062 m = (typeof(m)){"LP7000", "PCI", ""};
2064 m = (typeof(m)){"LP7000E", "PCI", ""};
2065 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2067 case PCI_DEVICE_ID_DRAGONFLY:
2068 m = (typeof(m)){"LP8000", "PCI",
2069 "Obsolete, Unsupported Fibre Channel Adapter"};
2071 case PCI_DEVICE_ID_CENTAUR:
2072 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
2073 m = (typeof(m)){"LP9002", "PCI", ""};
2075 m = (typeof(m)){"LP9000", "PCI", ""};
2076 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
2078 case PCI_DEVICE_ID_RFLY:
2079 m = (typeof(m)){"LP952", "PCI",
2080 "Obsolete, Unsupported Fibre Channel Adapter"};
2082 case PCI_DEVICE_ID_PEGASUS:
2083 m = (typeof(m)){"LP9802", "PCI-X",
2084 "Obsolete, Unsupported Fibre Channel Adapter"};
2086 case PCI_DEVICE_ID_THOR:
2087 m = (typeof(m)){"LP10000", "PCI-X",
2088 "Obsolete, Unsupported Fibre Channel Adapter"};
2090 case PCI_DEVICE_ID_VIPER:
2091 m = (typeof(m)){"LPX1000", "PCI-X",
2092 "Obsolete, Unsupported Fibre Channel Adapter"};
2094 case PCI_DEVICE_ID_PFLY:
2095 m = (typeof(m)){"LP982", "PCI-X",
2096 "Obsolete, Unsupported Fibre Channel Adapter"};
2098 case PCI_DEVICE_ID_TFLY:
2099 m = (typeof(m)){"LP1050", "PCI-X",
2100 "Obsolete, Unsupported Fibre Channel Adapter"};
2102 case PCI_DEVICE_ID_HELIOS:
2103 m = (typeof(m)){"LP11000", "PCI-X2",
2104 "Obsolete, Unsupported Fibre Channel Adapter"};
2106 case PCI_DEVICE_ID_HELIOS_SCSP:
2107 m = (typeof(m)){"LP11000-SP", "PCI-X2",
2108 "Obsolete, Unsupported Fibre Channel Adapter"};
2110 case PCI_DEVICE_ID_HELIOS_DCSP:
2111 m = (typeof(m)){"LP11002-SP", "PCI-X2",
2112 "Obsolete, Unsupported Fibre Channel Adapter"};
2114 case PCI_DEVICE_ID_NEPTUNE:
2115 m = (typeof(m)){"LPe1000", "PCIe",
2116 "Obsolete, Unsupported Fibre Channel Adapter"};
2118 case PCI_DEVICE_ID_NEPTUNE_SCSP:
2119 m = (typeof(m)){"LPe1000-SP", "PCIe",
2120 "Obsolete, Unsupported Fibre Channel Adapter"};
2122 case PCI_DEVICE_ID_NEPTUNE_DCSP:
2123 m = (typeof(m)){"LPe1002-SP", "PCIe",
2124 "Obsolete, Unsupported Fibre Channel Adapter"};
2126 case PCI_DEVICE_ID_BMID:
2127 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2129 case PCI_DEVICE_ID_BSMB:
2130 m = (typeof(m)){"LP111", "PCI-X2",
2131 "Obsolete, Unsupported Fibre Channel Adapter"};
2133 case PCI_DEVICE_ID_ZEPHYR:
2134 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2136 case PCI_DEVICE_ID_ZEPHYR_SCSP:
2137 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2139 case PCI_DEVICE_ID_ZEPHYR_DCSP:
2140 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
2143 case PCI_DEVICE_ID_ZMID:
2144 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2146 case PCI_DEVICE_ID_ZSMB:
2147 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2149 case PCI_DEVICE_ID_LP101:
2150 m = (typeof(m)){"LP101", "PCI-X",
2151 "Obsolete, Unsupported Fibre Channel Adapter"};
2153 case PCI_DEVICE_ID_LP10000S:
2154 m = (typeof(m)){"LP10000-S", "PCI",
2155 "Obsolete, Unsupported Fibre Channel Adapter"};
2157 case PCI_DEVICE_ID_LP11000S:
2158 m = (typeof(m)){"LP11000-S", "PCI-X2",
2159 "Obsolete, Unsupported Fibre Channel Adapter"};
2161 case PCI_DEVICE_ID_LPE11000S:
2162 m = (typeof(m)){"LPe11000-S", "PCIe",
2163 "Obsolete, Unsupported Fibre Channel Adapter"};
2165 case PCI_DEVICE_ID_SAT:
2166 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2168 case PCI_DEVICE_ID_SAT_MID:
2169 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2171 case PCI_DEVICE_ID_SAT_SMB:
2172 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2174 case PCI_DEVICE_ID_SAT_DCSP:
2175 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2177 case PCI_DEVICE_ID_SAT_SCSP:
2178 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2180 case PCI_DEVICE_ID_SAT_S:
2181 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2183 case PCI_DEVICE_ID_HORNET:
2184 m = (typeof(m)){"LP21000", "PCIe",
2185 "Obsolete, Unsupported FCoE Adapter"};
2188 case PCI_DEVICE_ID_PROTEUS_VF:
2189 m = (typeof(m)){"LPev12000", "PCIe IOV",
2190 "Obsolete, Unsupported Fibre Channel Adapter"};
2192 case PCI_DEVICE_ID_PROTEUS_PF:
2193 m = (typeof(m)){"LPev12000", "PCIe IOV",
2194 "Obsolete, Unsupported Fibre Channel Adapter"};
2196 case PCI_DEVICE_ID_PROTEUS_S:
2197 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2198 "Obsolete, Unsupported Fibre Channel Adapter"};
2200 case PCI_DEVICE_ID_TIGERSHARK:
2202 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
2204 case PCI_DEVICE_ID_TOMCAT:
2206 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2208 case PCI_DEVICE_ID_FALCON:
2209 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2210 "EmulexSecure Fibre"};
2212 case PCI_DEVICE_ID_BALIUS:
2213 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2214 "Obsolete, Unsupported Fibre Channel Adapter"};
2216 case PCI_DEVICE_ID_LANCER_FC:
2217 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2219 case PCI_DEVICE_ID_LANCER_FC_VF:
2220 m = (typeof(m)){"LPe16000", "PCIe",
2221 "Obsolete, Unsupported Fibre Channel Adapter"};
2223 case PCI_DEVICE_ID_LANCER_FCOE:
2225 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
2227 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2229 m = (typeof(m)){"OCe15100", "PCIe",
2230 "Obsolete, Unsupported FCoE"};
2232 case PCI_DEVICE_ID_SKYHAWK:
2233 case PCI_DEVICE_ID_SKYHAWK_VF:
2235 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2238 m = (typeof(m)){"Unknown", "", ""};
2242 if (mdp && mdp[0] == '\0')
2243 snprintf(mdp, 79,"%s", m.name);
2245 * oneConnect hba requires special processing, they are all initiators
2246 * and we put the port number on the end
2248 if (descp && descp[0] == '\0') {
2250 snprintf(descp, 255,
2251 "Emulex OneConnect %s, %s Initiator %s",
2254 else if (max_speed == 0)
2255 snprintf(descp, 255,
2257 m.name, m.bus, m.function);
2259 snprintf(descp, 255,
2260 "Emulex %s %d%s %s %s",
2261 m.name, max_speed, (GE) ? "GE" : "Gb",
2267 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2268 * @phba: pointer to lpfc hba data structure.
2269 * @pring: pointer to a IOCB ring.
2270 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2272 * This routine posts a given number of IOCBs with the associated DMA buffer
2273 * descriptors specified by the cnt argument to the given IOCB ring.
2276 * The number of IOCBs NOT able to be posted to the IOCB ring.
2279 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
2282 struct lpfc_iocbq *iocb;
2283 struct lpfc_dmabuf *mp1, *mp2;
2285 cnt += pring->missbufcnt;
2287 /* While there are buffers to post */
2289 /* Allocate buffer for command iocb */
2290 iocb = lpfc_sli_get_iocbq(phba);
2292 pring->missbufcnt = cnt;
2297 /* 2 buffers can be posted per command */
2298 /* Allocate buffer to post */
2299 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2301 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2302 if (!mp1 || !mp1->virt) {
2304 lpfc_sli_release_iocbq(phba, iocb);
2305 pring->missbufcnt = cnt;
2309 INIT_LIST_HEAD(&mp1->list);
2310 /* Allocate buffer to post */
2312 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2314 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2316 if (!mp2 || !mp2->virt) {
2318 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2320 lpfc_sli_release_iocbq(phba, iocb);
2321 pring->missbufcnt = cnt;
2325 INIT_LIST_HEAD(&mp2->list);
2330 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2331 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2332 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2333 icmd->ulpBdeCount = 1;
2336 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2337 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2338 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2340 icmd->ulpBdeCount = 2;
2343 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2346 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2348 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2352 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2356 lpfc_sli_release_iocbq(phba, iocb);
2357 pring->missbufcnt = cnt;
2360 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
2362 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
2364 pring->missbufcnt = 0;
2369 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2370 * @phba: pointer to lpfc hba data structure.
2372 * This routine posts initial receive IOCB buffers to the ELS ring. The
2373 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2377 * 0 - success (currently always success)
2380 lpfc_post_rcv_buf(struct lpfc_hba *phba)
2382 struct lpfc_sli *psli = &phba->sli;
2384 /* Ring 0, ELS / CT buffers */
2385 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
2386 /* Ring 2 - FCP no buffers needed */
2391 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2394 * lpfc_sha_init - Set up initial array of hash table entries
2395 * @HashResultPointer: pointer to an array as hash table.
2397 * This routine sets up the initial values to the array of hash table entries
2401 lpfc_sha_init(uint32_t * HashResultPointer)
2403 HashResultPointer[0] = 0x67452301;
2404 HashResultPointer[1] = 0xEFCDAB89;
2405 HashResultPointer[2] = 0x98BADCFE;
2406 HashResultPointer[3] = 0x10325476;
2407 HashResultPointer[4] = 0xC3D2E1F0;
2411 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2412 * @HashResultPointer: pointer to an initial/result hash table.
2413 * @HashWorkingPointer: pointer to an working hash table.
2415 * This routine iterates an initial hash table pointed by @HashResultPointer
2416 * with the values from the working hash table pointeed by @HashWorkingPointer.
2417 * The results are putting back to the initial hash table, returned through
2418 * the @HashResultPointer as the result hash table.
2421 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2425 uint32_t A, B, C, D, E;
2428 HashWorkingPointer[t] =
2430 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2432 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2433 } while (++t <= 79);
2435 A = HashResultPointer[0];
2436 B = HashResultPointer[1];
2437 C = HashResultPointer[2];
2438 D = HashResultPointer[3];
2439 E = HashResultPointer[4];
2443 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2444 } else if (t < 40) {
2445 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2446 } else if (t < 60) {
2447 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2449 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2451 TEMP += S(5, A) + E + HashWorkingPointer[t];
2457 } while (++t <= 79);
2459 HashResultPointer[0] += A;
2460 HashResultPointer[1] += B;
2461 HashResultPointer[2] += C;
2462 HashResultPointer[3] += D;
2463 HashResultPointer[4] += E;
2468 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2469 * @RandomChallenge: pointer to the entry of host challenge random number array.
2470 * @HashWorking: pointer to the entry of the working hash array.
2472 * This routine calculates the working hash array referred by @HashWorking
2473 * from the challenge random numbers associated with the host, referred by
2474 * @RandomChallenge. The result is put into the entry of the working hash
2475 * array and returned by reference through @HashWorking.
2478 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2480 *HashWorking = (*RandomChallenge ^ *HashWorking);
2484 * lpfc_hba_init - Perform special handling for LC HBA initialization
2485 * @phba: pointer to lpfc hba data structure.
2486 * @hbainit: pointer to an array of unsigned 32-bit integers.
2488 * This routine performs the special handling for LC HBA initialization.
2491 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2494 uint32_t *HashWorking;
2495 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
2497 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
2501 HashWorking[0] = HashWorking[78] = *pwwnn++;
2502 HashWorking[1] = HashWorking[79] = *pwwnn;
2504 for (t = 0; t < 7; t++)
2505 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2507 lpfc_sha_init(hbainit);
2508 lpfc_sha_iterate(hbainit, HashWorking);
2513 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2514 * @vport: pointer to a virtual N_Port data structure.
2516 * This routine performs the necessary cleanups before deleting the @vport.
2517 * It invokes the discovery state machine to perform necessary state
2518 * transitions and to release the ndlps associated with the @vport. Note,
2519 * the physical port is treated as @vport 0.
2522 lpfc_cleanup(struct lpfc_vport *vport)
2524 struct lpfc_hba *phba = vport->phba;
2525 struct lpfc_nodelist *ndlp, *next_ndlp;
2528 if (phba->link_state > LPFC_LINK_DOWN)
2529 lpfc_port_link_failure(vport);
2531 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2532 if (!NLP_CHK_NODE_ACT(ndlp)) {
2533 ndlp = lpfc_enable_node(vport, ndlp,
2534 NLP_STE_UNUSED_NODE);
2537 spin_lock_irq(&phba->ndlp_lock);
2538 NLP_SET_FREE_REQ(ndlp);
2539 spin_unlock_irq(&phba->ndlp_lock);
2540 /* Trigger the release of the ndlp memory */
2544 spin_lock_irq(&phba->ndlp_lock);
2545 if (NLP_CHK_FREE_REQ(ndlp)) {
2546 /* The ndlp should not be in memory free mode already */
2547 spin_unlock_irq(&phba->ndlp_lock);
2550 /* Indicate request for freeing ndlp memory */
2551 NLP_SET_FREE_REQ(ndlp);
2552 spin_unlock_irq(&phba->ndlp_lock);
2554 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2555 ndlp->nlp_DID == Fabric_DID) {
2556 /* Just free up ndlp with Fabric_DID for vports */
2561 /* take care of nodes in unused state before the state
2562 * machine taking action.
2564 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2569 if (ndlp->nlp_type & NLP_FABRIC)
2570 lpfc_disc_state_machine(vport, ndlp, NULL,
2571 NLP_EVT_DEVICE_RECOVERY);
2573 lpfc_disc_state_machine(vport, ndlp, NULL,
2577 /* At this point, ALL ndlp's should be gone
2578 * because of the previous NLP_EVT_DEVICE_RM.
2579 * Lets wait for this to happen, if needed.
2581 while (!list_empty(&vport->fc_nodes)) {
2583 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2584 "0233 Nodelist not empty\n");
2585 list_for_each_entry_safe(ndlp, next_ndlp,
2586 &vport->fc_nodes, nlp_listp) {
2587 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2589 "0282 did:x%x ndlp:x%p "
2590 "usgmap:x%x refcnt:%d\n",
2591 ndlp->nlp_DID, (void *)ndlp,
2594 &ndlp->kref.refcount));
2599 /* Wait for any activity on ndlps to settle */
2602 lpfc_cleanup_vports_rrqs(vport, NULL);
2606 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2607 * @vport: pointer to a virtual N_Port data structure.
2609 * This routine stops all the timers associated with a @vport. This function
2610 * is invoked before disabling or deleting a @vport. Note that the physical
2611 * port is treated as @vport 0.
2614 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2616 del_timer_sync(&vport->els_tmofunc);
2617 del_timer_sync(&vport->fc_fdmitmo);
2618 del_timer_sync(&vport->delayed_disc_tmo);
2619 lpfc_can_disctmo(vport);
2624 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2625 * @phba: pointer to lpfc hba data structure.
2627 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2628 * caller of this routine should already hold the host lock.
2631 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2633 /* Clear pending FCF rediscovery wait flag */
2634 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2636 /* Now, try to stop the timer */
2637 del_timer(&phba->fcf.redisc_wait);
2641 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2642 * @phba: pointer to lpfc hba data structure.
2644 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2645 * checks whether the FCF rediscovery wait timer is pending with the host
2646 * lock held before proceeding with disabling the timer and clearing the
2647 * wait timer pendig flag.
2650 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2652 spin_lock_irq(&phba->hbalock);
2653 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2654 /* FCF rediscovery timer already fired or stopped */
2655 spin_unlock_irq(&phba->hbalock);
2658 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2659 /* Clear failover in progress flags */
2660 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2661 spin_unlock_irq(&phba->hbalock);
2665 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2666 * @phba: pointer to lpfc hba data structure.
2668 * This routine stops all the timers associated with a HBA. This function is
2669 * invoked before either putting a HBA offline or unloading the driver.
2672 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2674 lpfc_stop_vport_timers(phba->pport);
2675 del_timer_sync(&phba->sli.mbox_tmo);
2676 del_timer_sync(&phba->fabric_block_timer);
2677 del_timer_sync(&phba->eratt_poll);
2678 del_timer_sync(&phba->hb_tmofunc);
2679 if (phba->sli_rev == LPFC_SLI_REV4) {
2680 del_timer_sync(&phba->rrq_tmr);
2681 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2683 phba->hb_outstanding = 0;
2685 switch (phba->pci_dev_grp) {
2686 case LPFC_PCI_DEV_LP:
2687 /* Stop any LightPulse device specific driver timers */
2688 del_timer_sync(&phba->fcp_poll_timer);
2690 case LPFC_PCI_DEV_OC:
2691 /* Stop any OneConnect device sepcific driver timers */
2692 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2696 "0297 Invalid device group (x%x)\n",
2704 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2705 * @phba: pointer to lpfc hba data structure.
2707 * This routine marks a HBA's management interface as blocked. Once the HBA's
2708 * management interface is marked as blocked, all the user space access to
2709 * the HBA, whether they are from sysfs interface or libdfc interface will
2710 * all be blocked. The HBA is set to block the management interface when the
2711 * driver prepares the HBA interface for online or offline.
2714 lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
2716 unsigned long iflag;
2717 uint8_t actcmd = MBX_HEARTBEAT;
2718 unsigned long timeout;
2720 spin_lock_irqsave(&phba->hbalock, iflag);
2721 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2722 spin_unlock_irqrestore(&phba->hbalock, iflag);
2723 if (mbx_action == LPFC_MBX_NO_WAIT)
2725 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2726 spin_lock_irqsave(&phba->hbalock, iflag);
2727 if (phba->sli.mbox_active) {
2728 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
2729 /* Determine how long we might wait for the active mailbox
2730 * command to be gracefully completed by firmware.
2732 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2733 phba->sli.mbox_active) * 1000) + jiffies;
2735 spin_unlock_irqrestore(&phba->hbalock, iflag);
2737 /* Wait for the outstnading mailbox command to complete */
2738 while (phba->sli.mbox_active) {
2739 /* Check active mailbox complete status every 2ms */
2741 if (time_after(jiffies, timeout)) {
2742 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2743 "2813 Mgmt IO is Blocked %x "
2744 "- mbox cmd %x still active\n",
2745 phba->sli.sli_flag, actcmd);
2752 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2753 * @phba: pointer to lpfc hba data structure.
2755 * Allocate RPIs for all active remote nodes. This is needed whenever
2756 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2757 * is to fixup the temporary rpi assignments.
2760 lpfc_sli4_node_prep(struct lpfc_hba *phba)
2762 struct lpfc_nodelist *ndlp, *next_ndlp;
2763 struct lpfc_vport **vports;
2766 if (phba->sli_rev != LPFC_SLI_REV4)
2769 vports = lpfc_create_vport_work_array(phba);
2770 if (vports != NULL) {
2771 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2772 if (vports[i]->load_flag & FC_UNLOADING)
2775 list_for_each_entry_safe(ndlp, next_ndlp,
2776 &vports[i]->fc_nodes,
2778 if (NLP_CHK_NODE_ACT(ndlp))
2780 lpfc_sli4_alloc_rpi(phba);
2784 lpfc_destroy_vport_work_array(phba, vports);
2788 * lpfc_online - Initialize and bring a HBA online
2789 * @phba: pointer to lpfc hba data structure.
2791 * This routine initializes the HBA and brings a HBA online. During this
2792 * process, the management interface is blocked to prevent user space access
2793 * to the HBA interfering with the driver initialization.
2800 lpfc_online(struct lpfc_hba *phba)
2802 struct lpfc_vport *vport;
2803 struct lpfc_vport **vports;
2805 bool vpis_cleared = false;
2809 vport = phba->pport;
2811 if (!(vport->fc_flag & FC_OFFLINE_MODE))
2814 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2815 "0458 Bring Adapter online\n");
2817 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
2819 if (!lpfc_sli_queue_setup(phba)) {
2820 lpfc_unblock_mgmt_io(phba);
2824 if (phba->sli_rev == LPFC_SLI_REV4) {
2825 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2826 lpfc_unblock_mgmt_io(phba);
2829 spin_lock_irq(&phba->hbalock);
2830 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2831 vpis_cleared = true;
2832 spin_unlock_irq(&phba->hbalock);
2834 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2835 lpfc_unblock_mgmt_io(phba);
2840 vports = lpfc_create_vport_work_array(phba);
2842 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2843 struct Scsi_Host *shost;
2844 shost = lpfc_shost_from_vport(vports[i]);
2845 spin_lock_irq(shost->host_lock);
2846 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2847 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2848 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2849 if (phba->sli_rev == LPFC_SLI_REV4) {
2850 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
2851 if ((vpis_cleared) &&
2852 (vports[i]->port_type !=
2853 LPFC_PHYSICAL_PORT))
2856 spin_unlock_irq(shost->host_lock);
2858 lpfc_destroy_vport_work_array(phba, vports);
2860 lpfc_unblock_mgmt_io(phba);
2865 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2866 * @phba: pointer to lpfc hba data structure.
2868 * This routine marks a HBA's management interface as not blocked. Once the
2869 * HBA's management interface is marked as not blocked, all the user space
2870 * access to the HBA, whether they are from sysfs interface or libdfc
2871 * interface will be allowed. The HBA is set to block the management interface
2872 * when the driver prepares the HBA interface for online or offline and then
2873 * set to unblock the management interface afterwards.
2876 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2878 unsigned long iflag;
2880 spin_lock_irqsave(&phba->hbalock, iflag);
2881 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2882 spin_unlock_irqrestore(&phba->hbalock, iflag);
2886 * lpfc_offline_prep - Prepare a HBA to be brought offline
2887 * @phba: pointer to lpfc hba data structure.
2889 * This routine is invoked to prepare a HBA to be brought offline. It performs
2890 * unregistration login to all the nodes on all vports and flushes the mailbox
2891 * queue to make it ready to be brought offline.
2894 lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
2896 struct lpfc_vport *vport = phba->pport;
2897 struct lpfc_nodelist *ndlp, *next_ndlp;
2898 struct lpfc_vport **vports;
2899 struct Scsi_Host *shost;
2902 if (vport->fc_flag & FC_OFFLINE_MODE)
2905 lpfc_block_mgmt_io(phba, mbx_action);
2907 lpfc_linkdown(phba);
2909 /* Issue an unreg_login to all nodes on all vports */
2910 vports = lpfc_create_vport_work_array(phba);
2911 if (vports != NULL) {
2912 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2913 if (vports[i]->load_flag & FC_UNLOADING)
2915 shost = lpfc_shost_from_vport(vports[i]);
2916 spin_lock_irq(shost->host_lock);
2917 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
2918 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2919 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
2920 spin_unlock_irq(shost->host_lock);
2922 shost = lpfc_shost_from_vport(vports[i]);
2923 list_for_each_entry_safe(ndlp, next_ndlp,
2924 &vports[i]->fc_nodes,
2926 if (!NLP_CHK_NODE_ACT(ndlp))
2928 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2930 if (ndlp->nlp_type & NLP_FABRIC) {
2931 lpfc_disc_state_machine(vports[i], ndlp,
2932 NULL, NLP_EVT_DEVICE_RECOVERY);
2933 lpfc_disc_state_machine(vports[i], ndlp,
2934 NULL, NLP_EVT_DEVICE_RM);
2936 spin_lock_irq(shost->host_lock);
2937 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2938 spin_unlock_irq(shost->host_lock);
2940 * Whenever an SLI4 port goes offline, free the
2941 * RPI. Get a new RPI when the adapter port
2942 * comes back online.
2944 if (phba->sli_rev == LPFC_SLI_REV4)
2945 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
2946 lpfc_unreg_rpi(vports[i], ndlp);
2950 lpfc_destroy_vport_work_array(phba, vports);
2952 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
2956 * lpfc_offline - Bring a HBA offline
2957 * @phba: pointer to lpfc hba data structure.
2959 * This routine actually brings a HBA offline. It stops all the timers
2960 * associated with the HBA, brings down the SLI layer, and eventually
2961 * marks the HBA as in offline state for the upper layer protocol.
2964 lpfc_offline(struct lpfc_hba *phba)
2966 struct Scsi_Host *shost;
2967 struct lpfc_vport **vports;
2970 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2973 /* stop port and all timers associated with this hba */
2974 lpfc_stop_port(phba);
2975 vports = lpfc_create_vport_work_array(phba);
2977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
2978 lpfc_stop_vport_timers(vports[i]);
2979 lpfc_destroy_vport_work_array(phba, vports);
2980 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2981 "0460 Bring Adapter offline\n");
2982 /* Bring down the SLI Layer and cleanup. The HBA is offline
2984 lpfc_sli_hba_down(phba);
2985 spin_lock_irq(&phba->hbalock);
2987 spin_unlock_irq(&phba->hbalock);
2988 vports = lpfc_create_vport_work_array(phba);
2990 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2991 shost = lpfc_shost_from_vport(vports[i]);
2992 spin_lock_irq(shost->host_lock);
2993 vports[i]->work_port_events = 0;
2994 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2995 spin_unlock_irq(shost->host_lock);
2997 lpfc_destroy_vport_work_array(phba, vports);
3001 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3002 * @phba: pointer to lpfc hba data structure.
3004 * This routine is to free all the SCSI buffers and IOCBs from the driver
3005 * list back to kernel. It is called from lpfc_pci_remove_one to free
3006 * the internal resources before the device is removed from the system.
3009 lpfc_scsi_free(struct lpfc_hba *phba)
3011 struct lpfc_scsi_buf *sb, *sb_next;
3012 struct lpfc_iocbq *io, *io_next;
3014 spin_lock_irq(&phba->hbalock);
3016 /* Release all the lpfc_scsi_bufs maintained by this host. */
3018 spin_lock(&phba->scsi_buf_list_put_lock);
3019 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3021 list_del(&sb->list);
3022 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3025 phba->total_scsi_bufs--;
3027 spin_unlock(&phba->scsi_buf_list_put_lock);
3029 spin_lock(&phba->scsi_buf_list_get_lock);
3030 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3032 list_del(&sb->list);
3033 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3036 phba->total_scsi_bufs--;
3038 spin_unlock(&phba->scsi_buf_list_get_lock);
3040 /* Release all the lpfc_iocbq entries maintained by this host. */
3041 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3042 list_del(&io->list);
3044 phba->total_iocbq_bufs--;
3047 spin_unlock_irq(&phba->hbalock);
3051 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3052 * @phba: pointer to lpfc hba data structure.
3054 * This routine first calculates the sizes of the current els and allocated
3055 * scsi sgl lists, and then goes through all sgls to updates the physical
3056 * XRIs assigned due to port function reset. During port initialization, the
3057 * current els and allocated scsi sgl lists are 0s.
3060 * 0 - successful (for now, it always returns 0)
3063 lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3065 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3066 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3067 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3068 LIST_HEAD(els_sgl_list);
3069 LIST_HEAD(scsi_sgl_list);
3071 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3074 * update on pci function's els xri-sgl list
3076 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3077 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3078 /* els xri-sgl expanded */
3079 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3080 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3081 "3157 ELS xri-sgl count increased from "
3082 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3084 /* allocate the additional els sgls */
3085 for (i = 0; i < xri_cnt; i++) {
3086 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3088 if (sglq_entry == NULL) {
3089 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3090 "2562 Failure to allocate an "
3091 "ELS sgl entry:%d\n", i);
3095 sglq_entry->buff_type = GEN_BUFF_TYPE;
3096 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3098 if (sglq_entry->virt == NULL) {
3100 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3101 "2563 Failure to allocate an "
3102 "ELS mbuf:%d\n", i);
3106 sglq_entry->sgl = sglq_entry->virt;
3107 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3108 sglq_entry->state = SGL_FREED;
3109 list_add_tail(&sglq_entry->list, &els_sgl_list);
3111 spin_lock_irq(&phba->hbalock);
3112 spin_lock(&pring->ring_lock);
3113 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
3114 spin_unlock(&pring->ring_lock);
3115 spin_unlock_irq(&phba->hbalock);
3116 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3117 /* els xri-sgl shrinked */
3118 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3119 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3120 "3158 ELS xri-sgl count decreased from "
3121 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3123 spin_lock_irq(&phba->hbalock);
3124 spin_lock(&pring->ring_lock);
3125 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
3126 spin_unlock(&pring->ring_lock);
3127 spin_unlock_irq(&phba->hbalock);
3128 /* release extra els sgls from list */
3129 for (i = 0; i < xri_cnt; i++) {
3130 list_remove_head(&els_sgl_list,
3131 sglq_entry, struct lpfc_sglq, list);
3133 lpfc_mbuf_free(phba, sglq_entry->virt,
3138 spin_lock_irq(&phba->hbalock);
3139 spin_lock(&pring->ring_lock);
3140 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
3141 spin_unlock(&pring->ring_lock);
3142 spin_unlock_irq(&phba->hbalock);
3144 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3145 "3163 ELS xri-sgl count unchanged: %d\n",
3147 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3149 /* update xris to els sgls on the list */
3151 sglq_entry_next = NULL;
3152 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3153 &phba->sli4_hba.lpfc_sgl_list, list) {
3154 lxri = lpfc_sli4_next_xritag(phba);
3155 if (lxri == NO_XRI) {
3156 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3157 "2400 Failed to allocate xri for "
3162 sglq_entry->sli4_lxritag = lxri;
3163 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3167 * update on pci function's allocated scsi xri-sgl list
3169 phba->total_scsi_bufs = 0;
3171 /* maximum number of xris available for scsi buffers */
3172 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3175 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3176 "2401 Current allocated SCSI xri-sgl count:%d, "
3177 "maximum SCSI xri count:%d\n",
3178 phba->sli4_hba.scsi_xri_cnt,
3179 phba->sli4_hba.scsi_xri_max);
3181 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3182 spin_lock(&phba->scsi_buf_list_put_lock);
3183 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3184 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3185 spin_unlock(&phba->scsi_buf_list_put_lock);
3186 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3188 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3189 /* max scsi xri shrinked below the allocated scsi buffers */
3190 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3191 phba->sli4_hba.scsi_xri_max;
3192 /* release the extra allocated scsi buffers */
3193 for (i = 0; i < scsi_xri_cnt; i++) {
3194 list_remove_head(&scsi_sgl_list, psb,
3195 struct lpfc_scsi_buf, list);
3197 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3198 psb->data, psb->dma_handle);
3202 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3203 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3204 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3207 /* update xris associated to remaining allocated scsi buffers */
3210 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3211 lxri = lpfc_sli4_next_xritag(phba);
3212 if (lxri == NO_XRI) {
3213 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3214 "2560 Failed to allocate xri for "
3219 psb->cur_iocbq.sli4_lxritag = lxri;
3220 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3222 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3223 spin_lock(&phba->scsi_buf_list_put_lock);
3224 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3225 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3226 spin_unlock(&phba->scsi_buf_list_put_lock);
3227 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3232 lpfc_free_els_sgl_list(phba);
3233 lpfc_scsi_free(phba);
3238 * lpfc_create_port - Create an FC port
3239 * @phba: pointer to lpfc hba data structure.
3240 * @instance: a unique integer ID to this FC port.
3241 * @dev: pointer to the device data structure.
3243 * This routine creates a FC port for the upper layer protocol. The FC port
3244 * can be created on top of either a physical port or a virtual port provided
3245 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3246 * and associates the FC port created before adding the shost into the SCSI
3250 * @vport - pointer to the virtual N_Port data structure.
3251 * NULL - port create failed.
3254 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3256 struct lpfc_vport *vport;
3257 struct Scsi_Host *shost;
3260 if (dev != &phba->pcidev->dev) {
3261 shost = scsi_host_alloc(&lpfc_vport_template,
3262 sizeof(struct lpfc_vport));
3264 if (phba->sli_rev == LPFC_SLI_REV4)
3265 shost = scsi_host_alloc(&lpfc_template,
3266 sizeof(struct lpfc_vport));
3268 shost = scsi_host_alloc(&lpfc_template_s3,
3269 sizeof(struct lpfc_vport));
3274 vport = (struct lpfc_vport *) shost->hostdata;
3276 vport->load_flag |= FC_LOADING;
3277 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3278 vport->fc_rscn_flush = 0;
3280 lpfc_get_vport_cfgparam(vport);
3281 shost->unique_id = instance;
3282 shost->max_id = LPFC_MAX_TARGET;
3283 shost->max_lun = vport->cfg_max_luns;
3284 shost->this_id = -1;
3285 shost->max_cmd_len = 16;
3286 if (phba->sli_rev == LPFC_SLI_REV4) {
3287 shost->dma_boundary =
3288 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
3289 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3293 * Set initial can_queue value since 0 is no longer supported and
3294 * scsi_add_host will fail. This will be adjusted later based on the
3295 * max xri value determined in hba setup.
3297 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3298 if (dev != &phba->pcidev->dev) {
3299 shost->transportt = lpfc_vport_transport_template;
3300 vport->port_type = LPFC_NPIV_PORT;
3302 shost->transportt = lpfc_transport_template;
3303 vport->port_type = LPFC_PHYSICAL_PORT;
3306 /* Initialize all internally managed lists. */
3307 INIT_LIST_HEAD(&vport->fc_nodes);
3308 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3309 spin_lock_init(&vport->work_port_lock);
3311 init_timer(&vport->fc_disctmo);
3312 vport->fc_disctmo.function = lpfc_disc_timeout;
3313 vport->fc_disctmo.data = (unsigned long)vport;
3315 init_timer(&vport->fc_fdmitmo);
3316 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
3317 vport->fc_fdmitmo.data = (unsigned long)vport;
3319 init_timer(&vport->els_tmofunc);
3320 vport->els_tmofunc.function = lpfc_els_timeout;
3321 vport->els_tmofunc.data = (unsigned long)vport;
3323 init_timer(&vport->delayed_disc_tmo);
3324 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3325 vport->delayed_disc_tmo.data = (unsigned long)vport;
3327 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
3331 spin_lock_irq(&phba->hbalock);
3332 list_add_tail(&vport->listentry, &phba->port_list);
3333 spin_unlock_irq(&phba->hbalock);
3337 scsi_host_put(shost);
3343 * destroy_port - destroy an FC port
3344 * @vport: pointer to an lpfc virtual N_Port data structure.
3346 * This routine destroys a FC port from the upper layer protocol. All the
3347 * resources associated with the port are released.
3350 destroy_port(struct lpfc_vport *vport)
3352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3353 struct lpfc_hba *phba = vport->phba;
3355 lpfc_debugfs_terminate(vport);
3356 fc_remove_host(shost);
3357 scsi_remove_host(shost);
3359 spin_lock_irq(&phba->hbalock);
3360 list_del_init(&vport->listentry);
3361 spin_unlock_irq(&phba->hbalock);
3363 lpfc_cleanup(vport);
3368 * lpfc_get_instance - Get a unique integer ID
3370 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3371 * uses the kernel idr facility to perform the task.
3374 * instance - a unique integer ID allocated as the new instance.
3375 * -1 - lpfc get instance failed.
3378 lpfc_get_instance(void)
3382 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3383 return ret < 0 ? -1 : ret;
3387 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3388 * @shost: pointer to SCSI host data structure.
3389 * @time: elapsed time of the scan in jiffies.
3391 * This routine is called by the SCSI layer with a SCSI host to determine
3392 * whether the scan host is finished.
3394 * Note: there is no scan_start function as adapter initialization will have
3395 * asynchronously kicked off the link initialization.
3398 * 0 - SCSI host scan is not over yet.
3399 * 1 - SCSI host scan is over.
3401 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3403 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3404 struct lpfc_hba *phba = vport->phba;
3407 spin_lock_irq(shost->host_lock);
3409 if (vport->load_flag & FC_UNLOADING) {
3413 if (time >= msecs_to_jiffies(30 * 1000)) {
3414 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3415 "0461 Scanning longer than 30 "
3416 "seconds. Continuing initialization\n");
3420 if (time >= msecs_to_jiffies(15 * 1000) &&
3421 phba->link_state <= LPFC_LINK_DOWN) {
3422 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3423 "0465 Link down longer than 15 "
3424 "seconds. Continuing initialization\n");
3429 if (vport->port_state != LPFC_VPORT_READY)
3431 if (vport->num_disc_nodes || vport->fc_prli_sent)
3433 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
3435 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
3441 spin_unlock_irq(shost->host_lock);
3446 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3447 * @shost: pointer to SCSI host data structure.
3449 * This routine initializes a given SCSI host attributes on a FC port. The
3450 * SCSI host can be either on top of a physical port or a virtual port.
3452 void lpfc_host_attrib_init(struct Scsi_Host *shost)
3454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3455 struct lpfc_hba *phba = vport->phba;
3457 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3460 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3461 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3462 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3464 memset(fc_host_supported_fc4s(shost), 0,
3465 sizeof(fc_host_supported_fc4s(shost)));
3466 fc_host_supported_fc4s(shost)[2] = 1;
3467 fc_host_supported_fc4s(shost)[7] = 1;
3469 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3470 sizeof fc_host_symbolic_name(shost));
3472 fc_host_supported_speeds(shost) = 0;
3473 if (phba->lmt & LMT_16Gb)
3474 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
3475 if (phba->lmt & LMT_10Gb)
3476 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
3477 if (phba->lmt & LMT_8Gb)
3478 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
3479 if (phba->lmt & LMT_4Gb)
3480 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3481 if (phba->lmt & LMT_2Gb)
3482 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3483 if (phba->lmt & LMT_1Gb)
3484 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3486 fc_host_maxframe_size(shost) =
3487 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3488 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
3490 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3492 /* This value is also unchanging */
3493 memset(fc_host_active_fc4s(shost), 0,
3494 sizeof(fc_host_active_fc4s(shost)));
3495 fc_host_active_fc4s(shost)[2] = 1;
3496 fc_host_active_fc4s(shost)[7] = 1;
3498 fc_host_max_npiv_vports(shost) = phba->max_vpi;
3499 spin_lock_irq(shost->host_lock);
3500 vport->load_flag &= ~FC_LOADING;
3501 spin_unlock_irq(shost->host_lock);
3505 * lpfc_stop_port_s3 - Stop SLI3 device port
3506 * @phba: pointer to lpfc hba data structure.
3508 * This routine is invoked to stop an SLI3 device port, it stops the device
3509 * from generating interrupts and stops the device driver's timers for the
3513 lpfc_stop_port_s3(struct lpfc_hba *phba)
3515 /* Clear all interrupt enable conditions */
3516 writel(0, phba->HCregaddr);
3517 readl(phba->HCregaddr); /* flush */
3518 /* Clear all pending interrupts */
3519 writel(0xffffffff, phba->HAregaddr);
3520 readl(phba->HAregaddr); /* flush */
3522 /* Reset some HBA SLI setup states */
3523 lpfc_stop_hba_timers(phba);
3524 phba->pport->work_port_events = 0;
3528 * lpfc_stop_port_s4 - Stop SLI4 device port
3529 * @phba: pointer to lpfc hba data structure.
3531 * This routine is invoked to stop an SLI4 device port, it stops the device
3532 * from generating interrupts and stops the device driver's timers for the
3536 lpfc_stop_port_s4(struct lpfc_hba *phba)
3538 /* Reset some HBA SLI4 setup states */
3539 lpfc_stop_hba_timers(phba);
3540 phba->pport->work_port_events = 0;
3541 phba->sli4_hba.intr_enable = 0;
3545 * lpfc_stop_port - Wrapper function for stopping hba port
3546 * @phba: Pointer to HBA context object.
3548 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3549 * the API jump table function pointer from the lpfc_hba struct.
3552 lpfc_stop_port(struct lpfc_hba *phba)
3554 phba->lpfc_stop_port(phba);
3558 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3559 * @phba: Pointer to hba for which this call is being executed.
3561 * This routine starts the timer waiting for the FCF rediscovery to complete.
3564 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3566 unsigned long fcf_redisc_wait_tmo =
3567 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3568 /* Start fcf rediscovery wait period timer */
3569 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3570 spin_lock_irq(&phba->hbalock);
3571 /* Allow action to new fcf asynchronous event */
3572 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3573 /* Mark the FCF rediscovery pending state */
3574 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3575 spin_unlock_irq(&phba->hbalock);
3579 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3580 * @ptr: Map to lpfc_hba data structure pointer.
3582 * This routine is invoked when waiting for FCF table rediscover has been
3583 * timed out. If new FCF record(s) has (have) been discovered during the
3584 * wait period, a new FCF event shall be added to the FCOE async event
3585 * list, and then worker thread shall be waked up for processing from the
3586 * worker thread context.
3589 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3591 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3593 /* Don't send FCF rediscovery event if timer cancelled */
3594 spin_lock_irq(&phba->hbalock);
3595 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3596 spin_unlock_irq(&phba->hbalock);
3599 /* Clear FCF rediscovery timer pending flag */
3600 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3601 /* FCF rediscovery event to worker thread */
3602 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3603 spin_unlock_irq(&phba->hbalock);
3604 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3605 "2776 FCF rediscover quiescent timer expired\n");
3606 /* wake up worker thread */
3607 lpfc_worker_wake_up(phba);
3611 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3612 * @phba: pointer to lpfc hba data structure.
3613 * @acqe_link: pointer to the async link completion queue entry.
3615 * This routine is to parse the SLI4 link-attention link fault code and
3616 * translate it into the base driver's read link attention mailbox command
3619 * Return: Link-attention status in terms of base driver's coding.
3622 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3623 struct lpfc_acqe_link *acqe_link)
3625 uint16_t latt_fault;
3627 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3628 case LPFC_ASYNC_LINK_FAULT_NONE:
3629 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3630 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3635 "0398 Invalid link fault code: x%x\n",
3636 bf_get(lpfc_acqe_link_fault, acqe_link));
3637 latt_fault = MBXERR_ERROR;
3644 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3645 * @phba: pointer to lpfc hba data structure.
3646 * @acqe_link: pointer to the async link completion queue entry.
3648 * This routine is to parse the SLI4 link attention type and translate it
3649 * into the base driver's link attention type coding.
3651 * Return: Link attention type in terms of base driver's coding.
3654 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3655 struct lpfc_acqe_link *acqe_link)
3659 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3660 case LPFC_ASYNC_LINK_STATUS_DOWN:
3661 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
3662 att_type = LPFC_ATT_LINK_DOWN;
3664 case LPFC_ASYNC_LINK_STATUS_UP:
3665 /* Ignore physical link up events - wait for logical link up */
3666 att_type = LPFC_ATT_RESERVED;
3668 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
3669 att_type = LPFC_ATT_LINK_UP;
3672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3673 "0399 Invalid link attention type: x%x\n",
3674 bf_get(lpfc_acqe_link_status, acqe_link));
3675 att_type = LPFC_ATT_RESERVED;
3682 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3683 * @phba: pointer to lpfc hba data structure.
3684 * @acqe_link: pointer to the async link completion queue entry.
3686 * This routine is to parse the SLI4 link-attention link speed and translate
3687 * it into the base driver's link-attention link speed coding.
3689 * Return: Link-attention link speed in terms of base driver's coding.
3692 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3693 struct lpfc_acqe_link *acqe_link)
3697 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3698 case LPFC_ASYNC_LINK_SPEED_ZERO:
3699 case LPFC_ASYNC_LINK_SPEED_10MBPS:
3700 case LPFC_ASYNC_LINK_SPEED_100MBPS:
3701 link_speed = LPFC_LINK_SPEED_UNKNOWN;
3703 case LPFC_ASYNC_LINK_SPEED_1GBPS:
3704 link_speed = LPFC_LINK_SPEED_1GHZ;
3706 case LPFC_ASYNC_LINK_SPEED_10GBPS:
3707 link_speed = LPFC_LINK_SPEED_10GHZ;
3709 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3710 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3711 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3712 link_speed = LPFC_LINK_SPEED_UNKNOWN;
3715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3716 "0483 Invalid link-attention link speed: x%x\n",
3717 bf_get(lpfc_acqe_link_speed, acqe_link));
3718 link_speed = LPFC_LINK_SPEED_UNKNOWN;
3725 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3726 * @phba: pointer to lpfc hba data structure.
3728 * This routine is to get an SLI3 FC port's link speed in Mbps.
3730 * Return: link speed in terms of Mbps.
3733 lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3735 uint32_t link_speed;
3737 if (!lpfc_is_link_up(phba))
3740 switch (phba->fc_linkspeed) {
3741 case LPFC_LINK_SPEED_1GHZ:
3744 case LPFC_LINK_SPEED_2GHZ:
3747 case LPFC_LINK_SPEED_4GHZ:
3750 case LPFC_LINK_SPEED_8GHZ:
3753 case LPFC_LINK_SPEED_10GHZ:
3756 case LPFC_LINK_SPEED_16GHZ:
3766 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3767 * @phba: pointer to lpfc hba data structure.
3768 * @evt_code: asynchronous event code.
3769 * @speed_code: asynchronous event link speed code.
3771 * This routine is to parse the giving SLI4 async event link speed code into
3772 * value of Mbps for the link speed.
3774 * Return: link speed in terms of Mbps.
3777 lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3780 uint32_t port_speed;
3783 case LPFC_TRAILER_CODE_LINK:
3784 switch (speed_code) {
3785 case LPFC_ASYNC_LINK_SPEED_ZERO:
3788 case LPFC_ASYNC_LINK_SPEED_10MBPS:
3791 case LPFC_ASYNC_LINK_SPEED_100MBPS:
3794 case LPFC_ASYNC_LINK_SPEED_1GBPS:
3797 case LPFC_ASYNC_LINK_SPEED_10GBPS:
3800 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3803 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3806 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3813 case LPFC_TRAILER_CODE_FC:
3814 switch (speed_code) {
3815 case LPFC_FC_LA_SPEED_UNKNOWN:
3818 case LPFC_FC_LA_SPEED_1G:
3821 case LPFC_FC_LA_SPEED_2G:
3824 case LPFC_FC_LA_SPEED_4G:
3827 case LPFC_FC_LA_SPEED_8G:
3830 case LPFC_FC_LA_SPEED_10G:
3833 case LPFC_FC_LA_SPEED_16G:
3847 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
3848 * @phba: pointer to lpfc hba data structure.
3849 * @acqe_link: pointer to the async link completion queue entry.
3851 * This routine is to handle the SLI4 asynchronous FCoE link event.
3854 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3855 struct lpfc_acqe_link *acqe_link)
3857 struct lpfc_dmabuf *mp;
3860 struct lpfc_mbx_read_top *la;
3864 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
3865 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
3867 phba->fcoe_eventtag = acqe_link->event_tag;
3868 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3870 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3871 "0395 The mboxq allocation failed\n");
3874 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3876 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3877 "0396 The lpfc_dmabuf allocation failed\n");
3880 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3883 "0397 The mbuf allocation failed\n");
3884 goto out_free_dmabuf;
3887 /* Cleanup any outstanding ELS commands */
3888 lpfc_els_flush_all_cmd(phba);
3890 /* Block ELS IOCBs until we have done process link event */
3891 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3893 /* Update link event statistics */
3894 phba->sli.slistat.link_event++;
3896 /* Create lpfc_handle_latt mailbox command from link ACQE */
3897 lpfc_read_topology(phba, pmb, mp);
3898 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3899 pmb->vport = phba->pport;
3901 /* Keep the link status for extra SLI4 state machine reference */
3902 phba->sli4_hba.link_state.speed =
3903 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3904 bf_get(lpfc_acqe_link_speed, acqe_link));
3905 phba->sli4_hba.link_state.duplex =
3906 bf_get(lpfc_acqe_link_duplex, acqe_link);
3907 phba->sli4_hba.link_state.status =
3908 bf_get(lpfc_acqe_link_status, acqe_link);
3909 phba->sli4_hba.link_state.type =
3910 bf_get(lpfc_acqe_link_type, acqe_link);
3911 phba->sli4_hba.link_state.number =
3912 bf_get(lpfc_acqe_link_number, acqe_link);
3913 phba->sli4_hba.link_state.fault =
3914 bf_get(lpfc_acqe_link_fault, acqe_link);
3915 phba->sli4_hba.link_state.logical_speed =
3916 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3918 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3919 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3920 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3921 "Logical speed:%dMbps Fault:%d\n",
3922 phba->sli4_hba.link_state.speed,
3923 phba->sli4_hba.link_state.topology,
3924 phba->sli4_hba.link_state.status,
3925 phba->sli4_hba.link_state.type,
3926 phba->sli4_hba.link_state.number,
3927 phba->sli4_hba.link_state.logical_speed,
3928 phba->sli4_hba.link_state.fault);
3930 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3931 * topology info. Note: Optional for non FC-AL ports.
3933 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3934 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3935 if (rc == MBX_NOT_FINISHED)
3936 goto out_free_dmabuf;
3940 * For FCoE Mode: fill in all the topology information we need and call
3941 * the READ_TOPOLOGY completion routine to continue without actually
3942 * sending the READ_TOPOLOGY mailbox command to the port.
3944 /* Parse and translate status field */
3946 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3948 /* Parse and translate link attention fields */
3949 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3950 la->eventTag = acqe_link->event_tag;
3951 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3952 bf_set(lpfc_mbx_read_top_link_spd, la,
3953 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3955 /* Fake the the following irrelvant fields */
3956 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3957 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3958 bf_set(lpfc_mbx_read_top_il, la, 0);
3959 bf_set(lpfc_mbx_read_top_pb, la, 0);
3960 bf_set(lpfc_mbx_read_top_fa, la, 0);
3961 bf_set(lpfc_mbx_read_top_mm, la, 0);
3963 /* Invoke the lpfc_handle_latt mailbox command callback function */
3964 lpfc_mbx_cmpl_read_topology(phba, pmb);
3971 mempool_free(pmb, phba->mbox_mem_pool);
3975 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3976 * @phba: pointer to lpfc hba data structure.
3977 * @acqe_fc: pointer to the async fc completion queue entry.
3979 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3980 * that the event was received and then issue a read_topology mailbox command so
3981 * that the rest of the driver will treat it the same as SLI3.
3984 lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3986 struct lpfc_dmabuf *mp;
3990 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3991 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3992 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3993 "2895 Non FC link Event detected.(%d)\n",
3994 bf_get(lpfc_trailer_type, acqe_fc));
3997 /* Keep the link status for extra SLI4 state machine reference */
3998 phba->sli4_hba.link_state.speed =
3999 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4000 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4001 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4002 phba->sli4_hba.link_state.topology =
4003 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4004 phba->sli4_hba.link_state.status =
4005 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4006 phba->sli4_hba.link_state.type =
4007 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4008 phba->sli4_hba.link_state.number =
4009 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4010 phba->sli4_hba.link_state.fault =
4011 bf_get(lpfc_acqe_link_fault, acqe_fc);
4012 phba->sli4_hba.link_state.logical_speed =
4013 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
4014 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4015 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4016 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4017 "%dMbps Fault:%d\n",
4018 phba->sli4_hba.link_state.speed,
4019 phba->sli4_hba.link_state.topology,
4020 phba->sli4_hba.link_state.status,
4021 phba->sli4_hba.link_state.type,
4022 phba->sli4_hba.link_state.number,
4023 phba->sli4_hba.link_state.logical_speed,
4024 phba->sli4_hba.link_state.fault);
4025 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4027 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4028 "2897 The mboxq allocation failed\n");
4031 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4033 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4034 "2898 The lpfc_dmabuf allocation failed\n");
4037 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4039 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4040 "2899 The mbuf allocation failed\n");
4041 goto out_free_dmabuf;
4044 /* Cleanup any outstanding ELS commands */
4045 lpfc_els_flush_all_cmd(phba);
4047 /* Block ELS IOCBs until we have done process link event */
4048 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4050 /* Update link event statistics */
4051 phba->sli.slistat.link_event++;
4053 /* Create lpfc_handle_latt mailbox command from link ACQE */
4054 lpfc_read_topology(phba, pmb, mp);
4055 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4056 pmb->vport = phba->pport;
4058 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4059 if (rc == MBX_NOT_FINISHED)
4060 goto out_free_dmabuf;
4066 mempool_free(pmb, phba->mbox_mem_pool);
4070 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4071 * @phba: pointer to lpfc hba data structure.
4072 * @acqe_fc: pointer to the async SLI completion queue entry.
4074 * This routine is to handle the SLI4 asynchronous SLI events.
4077 lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4083 struct temp_event temp_event_data;
4084 struct lpfc_acqe_misconfigured_event *misconfigured;
4085 struct Scsi_Host *shost;
4087 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4089 /* Special case Lancer */
4090 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
4091 LPFC_SLI_INTF_IF_TYPE_2) {
4092 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4093 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4094 "x%08x SLI Event Type:%d\n",
4095 acqe_sli->event_data1, acqe_sli->event_data2,
4100 port_name = phba->Port[0];
4101 if (port_name == 0x00)
4102 port_name = '?'; /* get port name is empty */
4105 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4106 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4107 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4108 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4110 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4111 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4112 acqe_sli->event_data1, port_name);
4114 shost = lpfc_shost_from_vport(phba->pport);
4115 fc_host_post_vendor_event(shost, fc_get_event_number(),
4116 sizeof(temp_event_data),
4117 (char *)&temp_event_data,
4118 SCSI_NL_VID_TYPE_PCI
4119 | PCI_VENDOR_ID_EMULEX);
4121 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4122 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4123 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4124 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4126 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4127 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4128 acqe_sli->event_data1, port_name);
4130 shost = lpfc_shost_from_vport(phba->pport);
4131 fc_host_post_vendor_event(shost, fc_get_event_number(),
4132 sizeof(temp_event_data),
4133 (char *)&temp_event_data,
4134 SCSI_NL_VID_TYPE_PCI
4135 | PCI_VENDOR_ID_EMULEX);
4137 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4138 misconfigured = (struct lpfc_acqe_misconfigured_event *)
4139 &acqe_sli->event_data1;
4141 /* fetch the status for this port */
4142 switch (phba->sli4_hba.lnk_info.lnk_no) {
4143 case LPFC_LINK_NUMBER_0:
4144 status = bf_get(lpfc_sli_misconfigured_port0,
4145 &misconfigured->theEvent);
4147 case LPFC_LINK_NUMBER_1:
4148 status = bf_get(lpfc_sli_misconfigured_port1,
4149 &misconfigured->theEvent);
4151 case LPFC_LINK_NUMBER_2:
4152 status = bf_get(lpfc_sli_misconfigured_port2,
4153 &misconfigured->theEvent);
4155 case LPFC_LINK_NUMBER_3:
4156 status = bf_get(lpfc_sli_misconfigured_port3,
4157 &misconfigured->theEvent);
4160 status = ~LPFC_SLI_EVENT_STATUS_VALID;
4165 case LPFC_SLI_EVENT_STATUS_VALID:
4166 return; /* no message if the sfp is okay */
4167 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4168 sprintf(message, "Optics faulted/incorrectly "
4169 "installed/not installed - Reseat optics, "
4170 "if issue not resolved, replace.");
4172 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4174 "Optics of two types installed - Remove one "
4175 "optic or install matching pair of optics.");
4177 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4178 sprintf(message, "Incompatible optics - Replace with "
4179 "compatible optics for card to function.");
4182 /* firmware is reporting a status we don't know about */
4183 sprintf(message, "Unknown event status x%02x", status);
4187 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4188 "3176 Misconfigured Physical Port - "
4189 "Port Name %c %s\n", port_name, message);
4191 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4192 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4193 "3192 Remote DPort Test Initiated - "
4194 "Event Data1:x%08x Event Data2: x%08x\n",
4195 acqe_sli->event_data1, acqe_sli->event_data2);
4198 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4199 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4200 "x%08x SLI Event Type:%d\n",
4201 acqe_sli->event_data1, acqe_sli->event_data2,
4208 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4209 * @vport: pointer to vport data structure.
4211 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4212 * response to a CVL event.
4214 * Return the pointer to the ndlp with the vport if successful, otherwise
4217 static struct lpfc_nodelist *
4218 lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4220 struct lpfc_nodelist *ndlp;
4221 struct Scsi_Host *shost;
4222 struct lpfc_hba *phba;
4229 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4231 /* Cannot find existing Fabric ndlp, so allocate a new one */
4232 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4235 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4236 /* Set the node type */
4237 ndlp->nlp_type |= NLP_FABRIC;
4238 /* Put ndlp onto node list */
4239 lpfc_enqueue_node(vport, ndlp);
4240 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4241 /* re-setup ndlp without removing from node list */
4242 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4246 if ((phba->pport->port_state < LPFC_FLOGI) &&
4247 (phba->pport->port_state != LPFC_VPORT_FAILED))
4249 /* If virtual link is not yet instantiated ignore CVL */
4250 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4251 && (vport->port_state != LPFC_VPORT_FAILED))
4253 shost = lpfc_shost_from_vport(vport);
4256 lpfc_linkdown_port(vport);
4257 lpfc_cleanup_pending_mbox(vport);
4258 spin_lock_irq(shost->host_lock);
4259 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4260 spin_unlock_irq(shost->host_lock);
4266 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4267 * @vport: pointer to lpfc hba data structure.
4269 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4270 * response to a FCF dead event.
4273 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4275 struct lpfc_vport **vports;
4278 vports = lpfc_create_vport_work_array(phba);
4280 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4281 lpfc_sli4_perform_vport_cvl(vports[i]);
4282 lpfc_destroy_vport_work_array(phba, vports);
4286 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4287 * @phba: pointer to lpfc hba data structure.
4288 * @acqe_link: pointer to the async fcoe completion queue entry.
4290 * This routine is to handle the SLI4 asynchronous fcoe event.
4293 lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4294 struct lpfc_acqe_fip *acqe_fip)
4296 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
4298 struct lpfc_vport *vport;
4299 struct lpfc_nodelist *ndlp;
4300 struct Scsi_Host *shost;
4301 int active_vlink_present;
4302 struct lpfc_vport **vports;
4305 phba->fc_eventTag = acqe_fip->event_tag;
4306 phba->fcoe_eventtag = acqe_fip->event_tag;
4307 switch (event_type) {
4308 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4309 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4310 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
4311 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4313 "2546 New FCF event, evt_tag:x%x, "
4315 acqe_fip->event_tag,
4318 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4320 "2788 FCF param modified event, "
4321 "evt_tag:x%x, index:x%x\n",
4322 acqe_fip->event_tag,
4324 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4326 * During period of FCF discovery, read the FCF
4327 * table record indexed by the event to update
4328 * FCF roundrobin failover eligible FCF bmask.
4330 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4332 "2779 Read FCF (x%x) for updating "
4333 "roundrobin FCF failover bmask\n",
4335 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
4338 /* If the FCF discovery is in progress, do nothing. */
4339 spin_lock_irq(&phba->hbalock);
4340 if (phba->hba_flag & FCF_TS_INPROG) {
4341 spin_unlock_irq(&phba->hbalock);
4344 /* If fast FCF failover rescan event is pending, do nothing */
4345 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4346 spin_unlock_irq(&phba->hbalock);
4350 /* If the FCF has been in discovered state, do nothing. */
4351 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
4352 spin_unlock_irq(&phba->hbalock);
4355 spin_unlock_irq(&phba->hbalock);
4357 /* Otherwise, scan the entire FCF table and re-discover SAN */
4358 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4359 "2770 Start FCF table scan per async FCF "
4360 "event, evt_tag:x%x, index:x%x\n",
4361 acqe_fip->event_tag, acqe_fip->index);
4362 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4363 LPFC_FCOE_FCF_GET_FIRST);
4365 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4366 "2547 Issue FCF scan read FCF mailbox "
4367 "command failed (x%x)\n", rc);
4370 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
4371 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4372 "2548 FCF Table full count 0x%x tag 0x%x\n",
4373 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4374 acqe_fip->event_tag);
4377 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
4378 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
4379 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4380 "2549 FCF (x%x) disconnected from network, "
4381 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
4383 * If we are in the middle of FCF failover process, clear
4384 * the corresponding FCF bit in the roundrobin bitmap.
4386 spin_lock_irq(&phba->hbalock);
4387 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4388 spin_unlock_irq(&phba->hbalock);
4389 /* Update FLOGI FCF failover eligible FCF bmask */
4390 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
4393 spin_unlock_irq(&phba->hbalock);
4395 /* If the event is not for currently used fcf do nothing */
4396 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
4400 * Otherwise, request the port to rediscover the entire FCF
4401 * table for a fast recovery from case that the current FCF
4402 * is no longer valid as we are not in the middle of FCF
4403 * failover process already.
4405 spin_lock_irq(&phba->hbalock);
4406 /* Mark the fast failover process in progress */
4407 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4408 spin_unlock_irq(&phba->hbalock);
4410 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4411 "2771 Start FCF fast failover process due to "
4412 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4413 "\n", acqe_fip->event_tag, acqe_fip->index);
4414 rc = lpfc_sli4_redisc_fcf_table(phba);
4416 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4418 "2772 Issue FCF rediscover mabilbox "
4419 "command failed, fail through to FCF "
4421 spin_lock_irq(&phba->hbalock);
4422 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4423 spin_unlock_irq(&phba->hbalock);
4425 * Last resort will fail over by treating this
4426 * as a link down to FCF registration.
4428 lpfc_sli4_fcf_dead_failthrough(phba);
4430 /* Reset FCF roundrobin bmask for new discovery */
4431 lpfc_sli4_clear_fcf_rr_bmask(phba);
4433 * Handling fast FCF failover to a DEAD FCF event is
4434 * considered equalivant to receiving CVL to all vports.
4436 lpfc_sli4_perform_all_vport_cvl(phba);
4439 case LPFC_FIP_EVENT_TYPE_CVL:
4440 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
4441 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4442 "2718 Clear Virtual Link Received for VPI 0x%x"
4443 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
4445 vport = lpfc_find_vport_by_vpid(phba,
4447 ndlp = lpfc_sli4_perform_vport_cvl(vport);
4450 active_vlink_present = 0;
4452 vports = lpfc_create_vport_work_array(phba);
4454 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4456 if ((!(vports[i]->fc_flag &
4457 FC_VPORT_CVL_RCVD)) &&
4458 (vports[i]->port_state > LPFC_FDISC)) {
4459 active_vlink_present = 1;
4463 lpfc_destroy_vport_work_array(phba, vports);
4466 if (active_vlink_present) {
4468 * If there are other active VLinks present,
4469 * re-instantiate the Vlink using FDISC.
4471 mod_timer(&ndlp->nlp_delayfunc,
4472 jiffies + msecs_to_jiffies(1000));
4473 shost = lpfc_shost_from_vport(vport);
4474 spin_lock_irq(shost->host_lock);
4475 ndlp->nlp_flag |= NLP_DELAY_TMO;
4476 spin_unlock_irq(shost->host_lock);
4477 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4478 vport->port_state = LPFC_FDISC;
4481 * Otherwise, we request port to rediscover
4482 * the entire FCF table for a fast recovery
4483 * from possible case that the current FCF
4484 * is no longer valid if we are not already
4485 * in the FCF failover process.
4487 spin_lock_irq(&phba->hbalock);
4488 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4489 spin_unlock_irq(&phba->hbalock);
4492 /* Mark the fast failover process in progress */
4493 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
4494 spin_unlock_irq(&phba->hbalock);
4495 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4497 "2773 Start FCF failover per CVL, "
4498 "evt_tag:x%x\n", acqe_fip->event_tag);
4499 rc = lpfc_sli4_redisc_fcf_table(phba);
4501 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4503 "2774 Issue FCF rediscover "
4504 "mabilbox command failed, "
4505 "through to CVL event\n");
4506 spin_lock_irq(&phba->hbalock);
4507 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
4508 spin_unlock_irq(&phba->hbalock);
4510 * Last resort will be re-try on the
4511 * the current registered FCF entry.
4513 lpfc_retry_pport_discovery(phba);
4516 * Reset FCF roundrobin bmask for new
4519 lpfc_sli4_clear_fcf_rr_bmask(phba);
4523 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4524 "0288 Unknown FCoE event type 0x%x event tag "
4525 "0x%x\n", event_type, acqe_fip->event_tag);
4531 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4532 * @phba: pointer to lpfc hba data structure.
4533 * @acqe_link: pointer to the async dcbx completion queue entry.
4535 * This routine is to handle the SLI4 asynchronous dcbx event.
4538 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4539 struct lpfc_acqe_dcbx *acqe_dcbx)
4541 phba->fc_eventTag = acqe_dcbx->event_tag;
4542 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4543 "0290 The SLI4 DCBX asynchronous event is not "
4548 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4549 * @phba: pointer to lpfc hba data structure.
4550 * @acqe_link: pointer to the async grp5 completion queue entry.
4552 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4553 * is an asynchronous notified of a logical link speed change. The Port
4554 * reports the logical link speed in units of 10Mbps.
4557 lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4558 struct lpfc_acqe_grp5 *acqe_grp5)
4560 uint16_t prev_ll_spd;
4562 phba->fc_eventTag = acqe_grp5->event_tag;
4563 phba->fcoe_eventtag = acqe_grp5->event_tag;
4564 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4565 phba->sli4_hba.link_state.logical_speed =
4566 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
4567 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4568 "2789 GRP5 Async Event: Updating logical link speed "
4569 "from %dMbps to %dMbps\n", prev_ll_spd,
4570 phba->sli4_hba.link_state.logical_speed);
4574 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4575 * @phba: pointer to lpfc hba data structure.
4577 * This routine is invoked by the worker thread to process all the pending
4578 * SLI4 asynchronous events.
4580 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4582 struct lpfc_cq_event *cq_event;
4584 /* First, declare the async event has been handled */
4585 spin_lock_irq(&phba->hbalock);
4586 phba->hba_flag &= ~ASYNC_EVENT;
4587 spin_unlock_irq(&phba->hbalock);
4588 /* Now, handle all the async events */
4589 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4590 /* Get the first event from the head of the event queue */
4591 spin_lock_irq(&phba->hbalock);
4592 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4593 cq_event, struct lpfc_cq_event, list);
4594 spin_unlock_irq(&phba->hbalock);
4595 /* Process the asynchronous event */
4596 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4597 case LPFC_TRAILER_CODE_LINK:
4598 lpfc_sli4_async_link_evt(phba,
4599 &cq_event->cqe.acqe_link);
4601 case LPFC_TRAILER_CODE_FCOE:
4602 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
4604 case LPFC_TRAILER_CODE_DCBX:
4605 lpfc_sli4_async_dcbx_evt(phba,
4606 &cq_event->cqe.acqe_dcbx);
4608 case LPFC_TRAILER_CODE_GRP5:
4609 lpfc_sli4_async_grp5_evt(phba,
4610 &cq_event->cqe.acqe_grp5);
4612 case LPFC_TRAILER_CODE_FC:
4613 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4615 case LPFC_TRAILER_CODE_SLI:
4616 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4619 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4620 "1804 Invalid asynchrous event code: "
4621 "x%x\n", bf_get(lpfc_trailer_code,
4622 &cq_event->cqe.mcqe_cmpl));
4625 /* Free the completion event processed to the free pool */
4626 lpfc_sli4_cq_event_release(phba, cq_event);
4631 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4632 * @phba: pointer to lpfc hba data structure.
4634 * This routine is invoked by the worker thread to process FCF table
4635 * rediscovery pending completion event.
4637 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4641 spin_lock_irq(&phba->hbalock);
4642 /* Clear FCF rediscovery timeout event */
4643 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4644 /* Clear driver fast failover FCF record flag */
4645 phba->fcf.failover_rec.flag = 0;
4646 /* Set state for FCF fast failover */
4647 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4648 spin_unlock_irq(&phba->hbalock);
4650 /* Scan FCF table from the first entry to re-discover SAN */
4651 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4652 "2777 Start post-quiescent FCF table scan\n");
4653 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
4655 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4656 "2747 Issue FCF scan read FCF mailbox "
4657 "command failed 0x%x\n", rc);
4661 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4662 * @phba: pointer to lpfc hba data structure.
4663 * @dev_grp: The HBA PCI-Device group number.
4665 * This routine is invoked to set up the per HBA PCI-Device group function
4666 * API jump table entries.
4668 * Return: 0 if success, otherwise -ENODEV
4671 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4675 /* Set up lpfc PCI-device group */
4676 phba->pci_dev_grp = dev_grp;
4678 /* The LPFC_PCI_DEV_OC uses SLI4 */
4679 if (dev_grp == LPFC_PCI_DEV_OC)
4680 phba->sli_rev = LPFC_SLI_REV4;
4682 /* Set up device INIT API function jump table */
4683 rc = lpfc_init_api_table_setup(phba, dev_grp);
4686 /* Set up SCSI API function jump table */
4687 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4690 /* Set up SLI API function jump table */
4691 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4694 /* Set up MBOX API function jump table */
4695 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4703 * lpfc_log_intr_mode - Log the active interrupt mode
4704 * @phba: pointer to lpfc hba data structure.
4705 * @intr_mode: active interrupt mode adopted.
4707 * This routine it invoked to log the currently used active interrupt mode
4710 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
4712 switch (intr_mode) {
4714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4715 "0470 Enable INTx interrupt mode.\n");
4718 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4719 "0481 Enabled MSI interrupt mode.\n");
4722 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4723 "0480 Enabled MSI-X interrupt mode.\n");
4726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4727 "0482 Illegal interrupt mode.\n");
4734 * lpfc_enable_pci_dev - Enable a generic PCI device.
4735 * @phba: pointer to lpfc hba data structure.
4737 * This routine is invoked to enable the PCI device that is common to all
4742 * other values - error
4745 lpfc_enable_pci_dev(struct lpfc_hba *phba)
4747 struct pci_dev *pdev;
4750 /* Obtain PCI device reference */
4754 pdev = phba->pcidev;
4755 /* Select PCI BARs */
4756 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4757 /* Enable PCI device */
4758 if (pci_enable_device_mem(pdev))
4760 /* Request PCI resource for the device */
4761 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4762 goto out_disable_device;
4763 /* Set up device as PCI master and save state for EEH */
4764 pci_set_master(pdev);
4765 pci_try_set_mwi(pdev);
4766 pci_save_state(pdev);
4768 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4769 if (pci_is_pcie(pdev))
4770 pdev->needs_freset = 1;
4775 pci_disable_device(pdev);
4777 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4778 "1401 Failed to enable pci device, bars:x%x\n", bars);
4783 * lpfc_disable_pci_dev - Disable a generic PCI device.
4784 * @phba: pointer to lpfc hba data structure.
4786 * This routine is invoked to disable the PCI device that is common to all
4790 lpfc_disable_pci_dev(struct lpfc_hba *phba)
4792 struct pci_dev *pdev;
4795 /* Obtain PCI device reference */
4799 pdev = phba->pcidev;
4800 /* Select PCI BARs */
4801 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4802 /* Release PCI resource and disable PCI device */
4803 pci_release_selected_regions(pdev, bars);
4804 pci_disable_device(pdev);
4810 * lpfc_reset_hba - Reset a hba
4811 * @phba: pointer to lpfc hba data structure.
4813 * This routine is invoked to reset a hba device. It brings the HBA
4814 * offline, performs a board restart, and then brings the board back
4815 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4816 * on outstanding mailbox commands.
4819 lpfc_reset_hba(struct lpfc_hba *phba)
4821 /* If resets are disabled then set error state and return. */
4822 if (!phba->cfg_enable_hba_reset) {
4823 phba->link_state = LPFC_HBA_ERROR;
4826 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4827 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4829 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
4831 lpfc_sli_brdrestart(phba);
4833 lpfc_unblock_mgmt_io(phba);
4837 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4838 * @phba: pointer to lpfc hba data structure.
4840 * This function enables the PCI SR-IOV virtual functions to a physical
4841 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4842 * enable the number of virtual functions to the physical function. As
4843 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4844 * API call does not considered as an error condition for most of the device.
4847 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4849 struct pci_dev *pdev = phba->pcidev;
4853 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4857 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4862 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4863 * @phba: pointer to lpfc hba data structure.
4864 * @nr_vfn: number of virtual functions to be enabled.
4866 * This function enables the PCI SR-IOV virtual functions to a physical
4867 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4868 * enable the number of virtual functions to the physical function. As
4869 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4870 * API call does not considered as an error condition for most of the device.
4873 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4875 struct pci_dev *pdev = phba->pcidev;
4876 uint16_t max_nr_vfn;
4879 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4880 if (nr_vfn > max_nr_vfn) {
4881 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4882 "3057 Requested vfs (%d) greater than "
4883 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4887 rc = pci_enable_sriov(pdev, nr_vfn);
4889 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4890 "2806 Failed to enable sriov on this device "
4891 "with vfn number nr_vf:%d, rc:%d\n",
4894 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4895 "2807 Successful enable sriov on this device "
4896 "with vfn number nr_vf:%d\n", nr_vfn);
4901 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4902 * @phba: pointer to lpfc hba data structure.
4904 * This routine is invoked to set up the driver internal resources specific to
4905 * support the SLI-3 HBA device it attached to.
4909 * other values - error
4912 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4914 struct lpfc_sli *psli;
4918 * Initialize timers used by driver
4921 /* Heartbeat timer */
4922 init_timer(&phba->hb_tmofunc);
4923 phba->hb_tmofunc.function = lpfc_hb_timeout;
4924 phba->hb_tmofunc.data = (unsigned long)phba;
4927 /* MBOX heartbeat timer */
4928 init_timer(&psli->mbox_tmo);
4929 psli->mbox_tmo.function = lpfc_mbox_timeout;
4930 psli->mbox_tmo.data = (unsigned long) phba;
4931 /* FCP polling mode timer */
4932 init_timer(&phba->fcp_poll_timer);
4933 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4934 phba->fcp_poll_timer.data = (unsigned long) phba;
4935 /* Fabric block timer */
4936 init_timer(&phba->fabric_block_timer);
4937 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4938 phba->fabric_block_timer.data = (unsigned long) phba;
4939 /* EA polling mode timer */
4940 init_timer(&phba->eratt_poll);
4941 phba->eratt_poll.function = lpfc_poll_eratt;
4942 phba->eratt_poll.data = (unsigned long) phba;
4944 /* Host attention work mask setup */
4945 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4946 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4948 /* Get all the module params for configuring this host */
4949 lpfc_get_cfgparam(phba);
4950 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4951 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4952 /* check for menlo minimum sg count */
4953 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4954 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4957 if (!phba->sli.ring)
4958 phba->sli.ring = (struct lpfc_sli_ring *)
4959 kzalloc(LPFC_SLI3_MAX_RING *
4960 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4961 if (!phba->sli.ring)
4965 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
4966 * used to create the sg_dma_buf_pool must be dynamically calculated.
4969 /* Initialize the host templates the configured values. */
4970 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4971 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4973 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
4974 if (phba->cfg_enable_bg) {
4976 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4977 * the FCP rsp, and a BDE for each. Sice we have no control
4978 * over how many protection data segments the SCSI Layer
4979 * will hand us (ie: there could be one for every block
4980 * in the IO), we just allocate enough BDEs to accomidate
4981 * our max amount and we need to limit lpfc_sg_seg_cnt to
4982 * minimize the risk of running out.
4984 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4985 sizeof(struct fcp_rsp) +
4986 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
4988 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
4989 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
4991 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
4992 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4995 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4996 * the FCP rsp, a BDE for each, and a BDE for up to
4997 * cfg_sg_seg_cnt data segments.
4999 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5000 sizeof(struct fcp_rsp) +
5001 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5003 /* Total BDEs in BPL for scsi_sg_list */
5004 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5007 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5008 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5009 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5010 phba->cfg_total_seg_cnt);
5012 phba->max_vpi = LPFC_MAX_VPI;
5013 /* This will be set to correct value after config_port mbox */
5014 phba->max_vports = 0;
5017 * Initialize the SLI Layer to run with lpfc HBAs.
5019 lpfc_sli_setup(phba);
5020 lpfc_sli_queue_setup(phba);
5022 /* Allocate device driver memory */
5023 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5027 * Enable sr-iov virtual functions if supported and configured
5028 * through the module parameter.
5030 if (phba->cfg_sriov_nr_virtfn > 0) {
5031 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5032 phba->cfg_sriov_nr_virtfn);
5034 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5035 "2808 Requested number of SR-IOV "
5036 "virtual functions (%d) is not "
5038 phba->cfg_sriov_nr_virtfn);
5039 phba->cfg_sriov_nr_virtfn = 0;
5047 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5048 * @phba: pointer to lpfc hba data structure.
5050 * This routine is invoked to unset the driver internal resources set up
5051 * specific for supporting the SLI-3 HBA device it attached to.
5054 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5056 /* Free device driver memory allocated */
5057 lpfc_mem_free_all(phba);
5063 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5064 * @phba: pointer to lpfc hba data structure.
5066 * This routine is invoked to set up the driver internal resources specific to
5067 * support the SLI-4 HBA device it attached to.
5071 * other values - error
5074 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5076 struct lpfc_vector_map_info *cpup;
5077 struct lpfc_sli *psli;
5078 LPFC_MBOXQ_t *mboxq;
5079 int rc, i, hbq_count, max_buf_size;
5080 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5081 struct lpfc_mqe *mqe;
5083 int fof_vectors = 0;
5085 /* Get all the module params for configuring this host */
5086 lpfc_get_cfgparam(phba);
5088 /* Before proceed, wait for POST done and device ready */
5089 rc = lpfc_sli4_post_status_check(phba);
5094 * Initialize timers used by driver
5097 /* Heartbeat timer */
5098 init_timer(&phba->hb_tmofunc);
5099 phba->hb_tmofunc.function = lpfc_hb_timeout;
5100 phba->hb_tmofunc.data = (unsigned long)phba;
5101 init_timer(&phba->rrq_tmr);
5102 phba->rrq_tmr.function = lpfc_rrq_timeout;
5103 phba->rrq_tmr.data = (unsigned long)phba;
5106 /* MBOX heartbeat timer */
5107 init_timer(&psli->mbox_tmo);
5108 psli->mbox_tmo.function = lpfc_mbox_timeout;
5109 psli->mbox_tmo.data = (unsigned long) phba;
5110 /* Fabric block timer */
5111 init_timer(&phba->fabric_block_timer);
5112 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5113 phba->fabric_block_timer.data = (unsigned long) phba;
5114 /* EA polling mode timer */
5115 init_timer(&phba->eratt_poll);
5116 phba->eratt_poll.function = lpfc_poll_eratt;
5117 phba->eratt_poll.data = (unsigned long) phba;
5118 /* FCF rediscover timer */
5119 init_timer(&phba->fcf.redisc_wait);
5120 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5121 phba->fcf.redisc_wait.data = (unsigned long)phba;
5124 * Control structure for handling external multi-buffer mailbox
5125 * command pass-through.
5127 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5128 sizeof(struct lpfc_mbox_ext_buf_ctx));
5129 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5131 phba->max_vpi = LPFC_MAX_VPI;
5133 /* This will be set to correct value after the read_config mbox */
5134 phba->max_vports = 0;
5136 /* Program the default value of vlan_id and fc_map */
5137 phba->valid_vlan = 0;
5138 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5139 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5140 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5143 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5144 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5146 if (!phba->sli.ring)
5147 phba->sli.ring = kzalloc(
5148 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
5149 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5150 if (!phba->sli.ring)
5154 * It doesn't matter what family our adapter is in, we are
5155 * limited to 2 Pages, 512 SGEs, for our SGL.
5156 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5158 max_buf_size = (2 * SLI4_PAGE_SIZE);
5159 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5160 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
5163 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5164 * used to create the sg_dma_buf_pool must be dynamically calculated.
5167 if (phba->cfg_enable_bg) {
5169 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5170 * the FCP rsp, and a SGE for each. Sice we have no control
5171 * over how many protection data segments the SCSI Layer
5172 * will hand us (ie: there could be one for every block
5173 * in the IO), we just allocate enough SGEs to accomidate
5174 * our max amount and we need to limit lpfc_sg_seg_cnt to
5175 * minimize the risk of running out.
5177 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5178 sizeof(struct fcp_rsp) + max_buf_size;
5180 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5181 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5183 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5184 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5187 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5188 * the FCP rsp, a SGE for each, and a SGE for up to
5189 * cfg_sg_seg_cnt data segments.
5191 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5192 sizeof(struct fcp_rsp) +
5193 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5195 /* Total SGEs for scsi_sg_list */
5196 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5198 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5199 * to post 1 page for the SGL.
5203 /* Initialize the host templates with the updated values. */
5204 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5205 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5207 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5208 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5210 phba->cfg_sg_dma_buf_size =
5211 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5213 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5214 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5215 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5216 phba->cfg_total_seg_cnt);
5218 /* Initialize buffer queue management fields */
5219 hbq_count = lpfc_sli_hbq_count();
5220 for (i = 0; i < hbq_count; ++i)
5221 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5222 INIT_LIST_HEAD(&phba->rb_pend_list);
5223 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5224 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5227 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5229 /* Initialize the Abort scsi buffer list used by driver */
5230 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5231 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5232 /* This abort list used by worker thread */
5233 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5236 * Initialize driver internal slow-path work queues
5239 /* Driver internel slow-path CQ Event pool */
5240 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5241 /* Response IOCB work queue list */
5242 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
5243 /* Asynchronous event CQ Event work queue list */
5244 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5245 /* Fast-path XRI aborted CQ Event work queue list */
5246 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5247 /* Slow-path XRI aborted CQ Event work queue list */
5248 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5249 /* Receive queue CQ Event work queue list */
5250 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5252 /* Initialize extent block lists. */
5253 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5254 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5255 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5256 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5258 /* Initialize the driver internal SLI layer lists. */
5259 lpfc_sli_setup(phba);
5260 lpfc_sli_queue_setup(phba);
5262 /* Allocate device driver memory */
5263 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5267 /* IF Type 2 ports get initialized now. */
5268 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5269 LPFC_SLI_INTF_IF_TYPE_2) {
5270 rc = lpfc_pci_function_reset(phba);
5273 phba->temp_sensor_support = 1;
5276 /* Create the bootstrap mailbox command */
5277 rc = lpfc_create_bootstrap_mbox(phba);
5281 /* Set up the host's endian order with the device. */
5282 rc = lpfc_setup_endian_order(phba);
5284 goto out_free_bsmbx;
5286 /* Set up the hba's configuration parameters. */
5287 rc = lpfc_sli4_read_config(phba);
5289 goto out_free_bsmbx;
5290 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5292 goto out_free_bsmbx;
5294 /* IF Type 0 ports get initialized now. */
5295 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5296 LPFC_SLI_INTF_IF_TYPE_0) {
5297 rc = lpfc_pci_function_reset(phba);
5299 goto out_free_bsmbx;
5302 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5306 goto out_free_bsmbx;
5309 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
5310 lpfc_supported_pages(mboxq);
5311 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5313 mqe = &mboxq->u.mqe;
5314 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5315 LPFC_MAX_SUPPORTED_PAGES);
5316 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5317 switch (pn_page[i]) {
5318 case LPFC_SLI4_PARAMETERS:
5319 phba->sli4_hba.pc_sli4_params.supported = 1;
5325 /* Read the port's SLI4 Parameters capabilities if supported. */
5326 if (phba->sli4_hba.pc_sli4_params.supported)
5327 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5329 mempool_free(mboxq, phba->mbox_mem_pool);
5331 goto out_free_bsmbx;
5335 * Get sli4 parameters that override parameters from Port capabilities.
5336 * If this call fails, it isn't critical unless the SLI4 parameters come
5339 rc = lpfc_get_sli4_parameters(phba, mboxq);
5341 if (phba->sli4_hba.extents_in_use &&
5342 phba->sli4_hba.rpi_hdrs_in_use) {
5343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5344 "2999 Unsupported SLI4 Parameters "
5345 "Extents and RPI headers enabled.\n");
5346 goto out_free_bsmbx;
5349 mempool_free(mboxq, phba->mbox_mem_pool);
5351 /* Verify OAS is supported */
5352 lpfc_sli4_oas_verify(phba);
5356 /* Verify all the SLI4 queues */
5357 rc = lpfc_sli4_queue_verify(phba);
5359 goto out_free_bsmbx;
5361 /* Create driver internal CQE event pool */
5362 rc = lpfc_sli4_cq_event_pool_create(phba);
5364 goto out_free_bsmbx;
5366 /* Initialize sgl lists per host */
5367 lpfc_init_sgl_list(phba);
5369 /* Allocate and initialize active sgl array */
5370 rc = lpfc_init_active_sgl_array(phba);
5372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5373 "1430 Failed to initialize sgl list.\n");
5374 goto out_destroy_cq_event_pool;
5376 rc = lpfc_sli4_init_rpi_hdrs(phba);
5378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5379 "1432 Failed to initialize rpi headers.\n");
5380 goto out_free_active_sgl;
5383 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5384 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5385 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5387 if (!phba->fcf.fcf_rr_bmask) {
5388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5389 "2759 Failed allocate memory for FCF round "
5390 "robin failover bmask\n");
5392 goto out_remove_rpi_hdrs;
5395 phba->sli4_hba.fcp_eq_hdl =
5396 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
5397 (fof_vectors + phba->cfg_fcp_io_channel)),
5399 if (!phba->sli4_hba.fcp_eq_hdl) {
5400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5401 "2572 Failed allocate memory for "
5402 "fast-path per-EQ handle array\n");
5404 goto out_free_fcf_rr_bmask;
5407 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
5409 phba->cfg_fcp_io_channel)), GFP_KERNEL);
5410 if (!phba->sli4_hba.msix_entries) {
5411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5412 "2573 Failed allocate memory for msi-x "
5413 "interrupt vector entries\n");
5415 goto out_free_fcp_eq_hdl;
5418 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5419 phba->sli4_hba.num_present_cpu),
5421 if (!phba->sli4_hba.cpu_map) {
5422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5423 "3327 Failed allocate memory for msi-x "
5424 "interrupt vector mapping\n");
5428 if (lpfc_used_cpu == NULL) {
5429 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5431 if (!lpfc_used_cpu) {
5432 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5433 "3335 Failed allocate memory for msi-x "
5434 "interrupt vector mapping\n");
5435 kfree(phba->sli4_hba.cpu_map);
5439 for (i = 0; i < lpfc_present_cpu; i++)
5440 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5443 /* Initialize io channels for round robin */
5444 cpup = phba->sli4_hba.cpu_map;
5446 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5447 cpup->channel_id = rc;
5449 if (rc >= phba->cfg_fcp_io_channel)
5454 * Enable sr-iov virtual functions if supported and configured
5455 * through the module parameter.
5457 if (phba->cfg_sriov_nr_virtfn > 0) {
5458 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5459 phba->cfg_sriov_nr_virtfn);
5461 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5462 "3020 Requested number of SR-IOV "
5463 "virtual functions (%d) is not "
5465 phba->cfg_sriov_nr_virtfn);
5466 phba->cfg_sriov_nr_virtfn = 0;
5473 kfree(phba->sli4_hba.msix_entries);
5474 out_free_fcp_eq_hdl:
5475 kfree(phba->sli4_hba.fcp_eq_hdl);
5476 out_free_fcf_rr_bmask:
5477 kfree(phba->fcf.fcf_rr_bmask);
5478 out_remove_rpi_hdrs:
5479 lpfc_sli4_remove_rpi_hdrs(phba);
5480 out_free_active_sgl:
5481 lpfc_free_active_sgl(phba);
5482 out_destroy_cq_event_pool:
5483 lpfc_sli4_cq_event_pool_destroy(phba);
5485 lpfc_destroy_bootstrap_mbox(phba);
5487 lpfc_mem_free(phba);
5492 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5493 * @phba: pointer to lpfc hba data structure.
5495 * This routine is invoked to unset the driver internal resources set up
5496 * specific for supporting the SLI-4 HBA device it attached to.
5499 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5501 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5503 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5504 kfree(phba->sli4_hba.cpu_map);
5505 phba->sli4_hba.num_present_cpu = 0;
5506 phba->sli4_hba.num_online_cpu = 0;
5507 phba->sli4_hba.curr_disp_cpu = 0;
5509 /* Free memory allocated for msi-x interrupt vector entries */
5510 kfree(phba->sli4_hba.msix_entries);
5512 /* Free memory allocated for fast-path work queue handles */
5513 kfree(phba->sli4_hba.fcp_eq_hdl);
5515 /* Free the allocated rpi headers. */
5516 lpfc_sli4_remove_rpi_hdrs(phba);
5517 lpfc_sli4_remove_rpis(phba);
5519 /* Free eligible FCF index bmask */
5520 kfree(phba->fcf.fcf_rr_bmask);
5522 /* Free the ELS sgl list */
5523 lpfc_free_active_sgl(phba);
5524 lpfc_free_els_sgl_list(phba);
5526 /* Free the completion queue EQ event pool */
5527 lpfc_sli4_cq_event_release_all(phba);
5528 lpfc_sli4_cq_event_pool_destroy(phba);
5530 /* Release resource identifiers. */
5531 lpfc_sli4_dealloc_resource_identifiers(phba);
5533 /* Free the bsmbx region. */
5534 lpfc_destroy_bootstrap_mbox(phba);
5536 /* Free the SLI Layer memory with SLI4 HBAs */
5537 lpfc_mem_free_all(phba);
5539 /* Free the current connect table */
5540 list_for_each_entry_safe(conn_entry, next_conn_entry,
5541 &phba->fcf_conn_rec_list, list) {
5542 list_del_init(&conn_entry->list);
5550 * lpfc_init_api_table_setup - Set up init api function jump table
5551 * @phba: The hba struct for which this call is being executed.
5552 * @dev_grp: The HBA PCI-Device group number.
5554 * This routine sets up the device INIT interface API function jump table
5557 * Returns: 0 - success, -ENODEV - failure.
5560 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5562 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5563 phba->lpfc_hba_down_link = lpfc_hba_down_link;
5564 phba->lpfc_selective_reset = lpfc_selective_reset;
5566 case LPFC_PCI_DEV_LP:
5567 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5568 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5569 phba->lpfc_stop_port = lpfc_stop_port_s3;
5571 case LPFC_PCI_DEV_OC:
5572 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5573 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5574 phba->lpfc_stop_port = lpfc_stop_port_s4;
5577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5578 "1431 Invalid HBA PCI-device group: 0x%x\n",
5587 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5588 * @phba: pointer to lpfc hba data structure.
5590 * This routine is invoked to set up the driver internal resources before the
5591 * device specific resource setup to support the HBA device it attached to.
5595 * other values - error
5598 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5601 * Driver resources common to all SLI revisions
5603 atomic_set(&phba->fast_event_count, 0);
5604 spin_lock_init(&phba->hbalock);
5606 /* Initialize ndlp management spinlock */
5607 spin_lock_init(&phba->ndlp_lock);
5609 INIT_LIST_HEAD(&phba->port_list);
5610 INIT_LIST_HEAD(&phba->work_list);
5611 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5613 /* Initialize the wait queue head for the kernel thread */
5614 init_waitqueue_head(&phba->work_waitq);
5616 /* Initialize the scsi buffer list used by driver for scsi IO */
5617 spin_lock_init(&phba->scsi_buf_list_get_lock);
5618 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5619 spin_lock_init(&phba->scsi_buf_list_put_lock);
5620 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5622 /* Initialize the fabric iocb list */
5623 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5625 /* Initialize list to save ELS buffers */
5626 INIT_LIST_HEAD(&phba->elsbuf);
5628 /* Initialize FCF connection rec list */
5629 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5631 /* Initialize OAS configuration list */
5632 spin_lock_init(&phba->devicelock);
5633 INIT_LIST_HEAD(&phba->luns);
5639 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5640 * @phba: pointer to lpfc hba data structure.
5642 * This routine is invoked to set up the driver internal resources after the
5643 * device specific resource setup to support the HBA device it attached to.
5647 * other values - error
5650 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5654 /* Startup the kernel thread for this host adapter. */
5655 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5656 "lpfc_worker_%d", phba->brd_no);
5657 if (IS_ERR(phba->worker_thread)) {
5658 error = PTR_ERR(phba->worker_thread);
5666 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5667 * @phba: pointer to lpfc hba data structure.
5669 * This routine is invoked to unset the driver internal resources set up after
5670 * the device specific resource setup for supporting the HBA device it
5674 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5676 /* Stop kernel worker thread */
5677 kthread_stop(phba->worker_thread);
5681 * lpfc_free_iocb_list - Free iocb list.
5682 * @phba: pointer to lpfc hba data structure.
5684 * This routine is invoked to free the driver's IOCB list and memory.
5687 lpfc_free_iocb_list(struct lpfc_hba *phba)
5689 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5691 spin_lock_irq(&phba->hbalock);
5692 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5693 &phba->lpfc_iocb_list, list) {
5694 list_del(&iocbq_entry->list);
5696 phba->total_iocbq_bufs--;
5698 spin_unlock_irq(&phba->hbalock);
5704 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5705 * @phba: pointer to lpfc hba data structure.
5707 * This routine is invoked to allocate and initizlize the driver's IOCB
5708 * list and set up the IOCB tag array accordingly.
5712 * other values - error
5715 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5717 struct lpfc_iocbq *iocbq_entry = NULL;
5721 /* Initialize and populate the iocb list per host. */
5722 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
5723 for (i = 0; i < iocb_count; i++) {
5724 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
5725 if (iocbq_entry == NULL) {
5726 printk(KERN_ERR "%s: only allocated %d iocbs of "
5727 "expected %d count. Unloading driver.\n",
5728 __func__, i, LPFC_IOCB_LIST_CNT);
5729 goto out_free_iocbq;
5732 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5735 printk(KERN_ERR "%s: failed to allocate IOTAG. "
5736 "Unloading driver.\n", __func__);
5737 goto out_free_iocbq;
5739 iocbq_entry->sli4_lxritag = NO_XRI;
5740 iocbq_entry->sli4_xritag = NO_XRI;
5742 spin_lock_irq(&phba->hbalock);
5743 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5744 phba->total_iocbq_bufs++;
5745 spin_unlock_irq(&phba->hbalock);
5751 lpfc_free_iocb_list(phba);
5757 * lpfc_free_sgl_list - Free a given sgl list.
5758 * @phba: pointer to lpfc hba data structure.
5759 * @sglq_list: pointer to the head of sgl list.
5761 * This routine is invoked to free a give sgl list and memory.
5764 lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
5766 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
5768 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5769 list_del(&sglq_entry->list);
5770 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5776 * lpfc_free_els_sgl_list - Free els sgl list.
5777 * @phba: pointer to lpfc hba data structure.
5779 * This routine is invoked to free the driver's els sgl list and memory.
5782 lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5784 LIST_HEAD(sglq_list);
5785 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5787 /* Retrieve all els sgls from driver list */
5788 spin_lock_irq(&phba->hbalock);
5789 spin_lock(&pring->ring_lock);
5790 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
5791 spin_unlock(&pring->ring_lock);
5792 spin_unlock_irq(&phba->hbalock);
5794 /* Now free the sgl list */
5795 lpfc_free_sgl_list(phba, &sglq_list);
5799 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5800 * @phba: pointer to lpfc hba data structure.
5802 * This routine is invoked to allocate the driver's active sgl memory.
5803 * This array will hold the sglq_entry's for active IOs.
5806 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5809 size = sizeof(struct lpfc_sglq *);
5810 size *= phba->sli4_hba.max_cfg_param.max_xri;
5812 phba->sli4_hba.lpfc_sglq_active_list =
5813 kzalloc(size, GFP_KERNEL);
5814 if (!phba->sli4_hba.lpfc_sglq_active_list)
5820 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5821 * @phba: pointer to lpfc hba data structure.
5823 * This routine is invoked to walk through the array of active sglq entries
5824 * and free all of the resources.
5825 * This is just a place holder for now.
5828 lpfc_free_active_sgl(struct lpfc_hba *phba)
5830 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5834 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5835 * @phba: pointer to lpfc hba data structure.
5837 * This routine is invoked to allocate and initizlize the driver's sgl
5838 * list and set up the sgl xritag tag array accordingly.
5842 lpfc_init_sgl_list(struct lpfc_hba *phba)
5844 /* Initialize and populate the sglq list per host/VF. */
5845 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5846 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5848 /* els xri-sgl book keeping */
5849 phba->sli4_hba.els_xri_cnt = 0;
5851 /* scsi xri-buffer book keeping */
5852 phba->sli4_hba.scsi_xri_cnt = 0;
5856 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5857 * @phba: pointer to lpfc hba data structure.
5859 * This routine is invoked to post rpi header templates to the
5860 * port for those SLI4 ports that do not support extents. This routine
5861 * posts a PAGE_SIZE memory region to the port to hold up to
5862 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5863 * and should be called only when interrupts are disabled.
5867 * -ERROR - otherwise.
5870 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5873 struct lpfc_rpi_hdr *rpi_hdr;
5875 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
5876 if (!phba->sli4_hba.rpi_hdrs_in_use)
5878 if (phba->sli4_hba.extents_in_use)
5881 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5883 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5884 "0391 Error during rpi post operation\n");
5885 lpfc_sli4_remove_rpis(phba);
5893 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5894 * @phba: pointer to lpfc hba data structure.
5896 * This routine is invoked to allocate a single 4KB memory region to
5897 * support rpis and stores them in the phba. This single region
5898 * provides support for up to 64 rpis. The region is used globally
5902 * A valid rpi hdr on success.
5903 * A NULL pointer on any failure.
5905 struct lpfc_rpi_hdr *
5906 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5908 uint16_t rpi_limit, curr_rpi_range;
5909 struct lpfc_dmabuf *dmabuf;
5910 struct lpfc_rpi_hdr *rpi_hdr;
5914 * If the SLI4 port supports extents, posting the rpi header isn't
5915 * required. Set the expected maximum count and let the actual value
5916 * get set when extents are fully allocated.
5918 if (!phba->sli4_hba.rpi_hdrs_in_use)
5920 if (phba->sli4_hba.extents_in_use)
5923 /* The limit on the logical index is just the max_rpi count. */
5924 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
5925 phba->sli4_hba.max_cfg_param.max_rpi - 1;
5927 spin_lock_irq(&phba->hbalock);
5929 * Establish the starting RPI in this header block. The starting
5930 * rpi is normalized to a zero base because the physical rpi is
5933 curr_rpi_range = phba->sli4_hba.next_rpi;
5934 spin_unlock_irq(&phba->hbalock);
5937 * The port has a limited number of rpis. The increment here
5938 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5939 * and to allow the full max_rpi range per port.
5941 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
5942 rpi_count = rpi_limit - curr_rpi_range;
5944 rpi_count = LPFC_RPI_HDR_COUNT;
5949 * First allocate the protocol header region for the port. The
5950 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5952 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5956 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
5957 LPFC_HDR_TEMPLATE_SIZE,
5958 &dmabuf->phys, GFP_KERNEL);
5959 if (!dmabuf->virt) {
5961 goto err_free_dmabuf;
5964 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5966 goto err_free_coherent;
5969 /* Save the rpi header data for cleanup later. */
5970 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5972 goto err_free_coherent;
5974 rpi_hdr->dmabuf = dmabuf;
5975 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5976 rpi_hdr->page_count = 1;
5977 spin_lock_irq(&phba->hbalock);
5979 /* The rpi_hdr stores the logical index only. */
5980 rpi_hdr->start_rpi = curr_rpi_range;
5981 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5984 * The next_rpi stores the next logical module-64 rpi value used
5985 * to post physical rpis in subsequent rpi postings.
5987 phba->sli4_hba.next_rpi += rpi_count;
5988 spin_unlock_irq(&phba->hbalock);
5992 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5993 dmabuf->virt, dmabuf->phys);
6000 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6001 * @phba: pointer to lpfc hba data structure.
6003 * This routine is invoked to remove all memory resources allocated
6004 * to support rpis for SLI4 ports not supporting extents. This routine
6005 * presumes the caller has released all rpis consumed by fabric or port
6006 * logins and is prepared to have the header pages removed.
6009 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6011 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6013 if (!phba->sli4_hba.rpi_hdrs_in_use)
6016 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6017 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6018 list_del(&rpi_hdr->list);
6019 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6020 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6021 kfree(rpi_hdr->dmabuf);
6025 /* There are no rpis available to the port now. */
6026 phba->sli4_hba.next_rpi = 0;
6030 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6031 * @pdev: pointer to pci device data structure.
6033 * This routine is invoked to allocate the driver hba data structure for an
6034 * HBA device. If the allocation is successful, the phba reference to the
6035 * PCI device data structure is set.
6038 * pointer to @phba - successful
6041 static struct lpfc_hba *
6042 lpfc_hba_alloc(struct pci_dev *pdev)
6044 struct lpfc_hba *phba;
6046 /* Allocate memory for HBA structure */
6047 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6049 dev_err(&pdev->dev, "failed to allocate hba struct\n");
6053 /* Set reference to PCI device in HBA structure */
6054 phba->pcidev = pdev;
6056 /* Assign an unused board number */
6057 phba->brd_no = lpfc_get_instance();
6058 if (phba->brd_no < 0) {
6063 spin_lock_init(&phba->ct_ev_lock);
6064 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6070 * lpfc_hba_free - Free driver hba data structure with a device.
6071 * @phba: pointer to lpfc hba data structure.
6073 * This routine is invoked to free the driver hba data structure with an
6077 lpfc_hba_free(struct lpfc_hba *phba)
6079 /* Release the driver assigned board number */
6080 idr_remove(&lpfc_hba_index, phba->brd_no);
6082 /* Free memory allocated with sli rings */
6083 kfree(phba->sli.ring);
6084 phba->sli.ring = NULL;
6091 * lpfc_create_shost - Create hba physical port with associated scsi host.
6092 * @phba: pointer to lpfc hba data structure.
6094 * This routine is invoked to create HBA physical port and associate a SCSI
6099 * other values - error
6102 lpfc_create_shost(struct lpfc_hba *phba)
6104 struct lpfc_vport *vport;
6105 struct Scsi_Host *shost;
6107 /* Initialize HBA FC structure */
6108 phba->fc_edtov = FF_DEF_EDTOV;
6109 phba->fc_ratov = FF_DEF_RATOV;
6110 phba->fc_altov = FF_DEF_ALTOV;
6111 phba->fc_arbtov = FF_DEF_ARBTOV;
6113 atomic_set(&phba->sdev_cnt, 0);
6114 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
6118 shost = lpfc_shost_from_vport(vport);
6119 phba->pport = vport;
6120 lpfc_debugfs_initialize(vport);
6121 /* Put reference to SCSI host to driver's device private data */
6122 pci_set_drvdata(phba->pcidev, shost);
6128 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6129 * @phba: pointer to lpfc hba data structure.
6131 * This routine is invoked to destroy HBA physical port and the associated
6135 lpfc_destroy_shost(struct lpfc_hba *phba)
6137 struct lpfc_vport *vport = phba->pport;
6139 /* Destroy physical port that associated with the SCSI host */
6140 destroy_port(vport);
6146 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6147 * @phba: pointer to lpfc hba data structure.
6148 * @shost: the shost to be used to detect Block guard settings.
6150 * This routine sets up the local Block guard protocol settings for @shost.
6151 * This routine also allocates memory for debugging bg buffers.
6154 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6160 if (lpfc_prot_mask && lpfc_prot_guard) {
6161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6162 "1478 Registering BlockGuard with the "
6165 old_mask = lpfc_prot_mask;
6166 old_guard = lpfc_prot_guard;
6168 /* Only allow supported values */
6169 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6170 SHOST_DIX_TYPE0_PROTECTION |
6171 SHOST_DIX_TYPE1_PROTECTION);
6172 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6174 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6175 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6176 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6178 if (lpfc_prot_mask && lpfc_prot_guard) {
6179 if ((old_mask != lpfc_prot_mask) ||
6180 (old_guard != lpfc_prot_guard))
6181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6182 "1475 Registering BlockGuard with the "
6183 "SCSI layer: mask %d guard %d\n",
6184 lpfc_prot_mask, lpfc_prot_guard);
6186 scsi_host_set_prot(shost, lpfc_prot_mask);
6187 scsi_host_set_guard(shost, lpfc_prot_guard);
6189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6190 "1479 Not Registering BlockGuard with the SCSI "
6191 "layer, Bad protection parameters: %d %d\n",
6192 old_mask, old_guard);
6195 if (!_dump_buf_data) {
6197 spin_lock_init(&_dump_buf_lock);
6199 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6200 if (_dump_buf_data) {
6201 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6202 "9043 BLKGRD: allocated %d pages for "
6203 "_dump_buf_data at 0x%p\n",
6204 (1 << pagecnt), _dump_buf_data);
6205 _dump_buf_data_order = pagecnt;
6206 memset(_dump_buf_data, 0,
6207 ((1 << PAGE_SHIFT) << pagecnt));
6212 if (!_dump_buf_data_order)
6213 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6214 "9044 BLKGRD: ERROR unable to allocate "
6215 "memory for hexdump\n");
6217 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6218 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6219 "\n", _dump_buf_data);
6220 if (!_dump_buf_dif) {
6223 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6224 if (_dump_buf_dif) {
6225 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6226 "9046 BLKGRD: allocated %d pages for "
6227 "_dump_buf_dif at 0x%p\n",
6228 (1 << pagecnt), _dump_buf_dif);
6229 _dump_buf_dif_order = pagecnt;
6230 memset(_dump_buf_dif, 0,
6231 ((1 << PAGE_SHIFT) << pagecnt));
6236 if (!_dump_buf_dif_order)
6237 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6238 "9047 BLKGRD: ERROR unable to allocate "
6239 "memory for hexdump\n");
6241 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6242 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
6247 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6248 * @phba: pointer to lpfc hba data structure.
6250 * This routine is invoked to perform all the necessary post initialization
6251 * setup for the device.
6254 lpfc_post_init_setup(struct lpfc_hba *phba)
6256 struct Scsi_Host *shost;
6257 struct lpfc_adapter_event_header adapter_event;
6259 /* Get the default values for Model Name and Description */
6260 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6263 * hba setup may have changed the hba_queue_depth so we need to
6264 * adjust the value of can_queue.
6266 shost = pci_get_drvdata(phba->pcidev);
6267 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6268 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6269 lpfc_setup_bg(phba, shost);
6271 lpfc_host_attrib_init(shost);
6273 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6274 spin_lock_irq(shost->host_lock);
6275 lpfc_poll_start_timer(phba);
6276 spin_unlock_irq(shost->host_lock);
6279 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6280 "0428 Perform SCSI scan\n");
6281 /* Send board arrival event to upper layer */
6282 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6283 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6284 fc_host_post_vendor_event(shost, fc_get_event_number(),
6285 sizeof(adapter_event),
6286 (char *) &adapter_event,
6292 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6293 * @phba: pointer to lpfc hba data structure.
6295 * This routine is invoked to set up the PCI device memory space for device
6296 * with SLI-3 interface spec.
6300 * other values - error
6303 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6305 struct pci_dev *pdev;
6306 unsigned long bar0map_len, bar2map_len;
6309 int error = -ENODEV;
6311 /* Obtain PCI device reference */
6315 pdev = phba->pcidev;
6317 /* Set the device DMA mask size */
6318 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6319 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6320 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6321 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
6326 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6327 * required by each mapping.
6329 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6330 bar0map_len = pci_resource_len(pdev, 0);
6332 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6333 bar2map_len = pci_resource_len(pdev, 2);
6335 /* Map HBA SLIM to a kernel virtual address. */
6336 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6337 if (!phba->slim_memmap_p) {
6338 dev_printk(KERN_ERR, &pdev->dev,
6339 "ioremap failed for SLIM memory.\n");
6343 /* Map HBA Control Registers to a kernel virtual address. */
6344 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6345 if (!phba->ctrl_regs_memmap_p) {
6346 dev_printk(KERN_ERR, &pdev->dev,
6347 "ioremap failed for HBA control registers.\n");
6348 goto out_iounmap_slim;
6351 /* Allocate memory for SLI-2 structures */
6352 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6353 &phba->slim2p.phys, GFP_KERNEL);
6354 if (!phba->slim2p.virt)
6357 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
6358 phba->mbox_ext = (phba->slim2p.virt +
6359 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
6360 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6361 phba->IOCBs = (phba->slim2p.virt +
6362 offsetof(struct lpfc_sli2_slim, IOCBs));
6364 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6365 lpfc_sli_hbq_size(),
6366 &phba->hbqslimp.phys,
6368 if (!phba->hbqslimp.virt)
6371 hbq_count = lpfc_sli_hbq_count();
6372 ptr = phba->hbqslimp.virt;
6373 for (i = 0; i < hbq_count; ++i) {
6374 phba->hbqs[i].hbq_virt = ptr;
6375 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6376 ptr += (lpfc_hbq_defs[i]->entry_count *
6377 sizeof(struct lpfc_hbq_entry));
6379 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6380 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6382 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6384 INIT_LIST_HEAD(&phba->rb_pend_list);
6386 phba->MBslimaddr = phba->slim_memmap_p;
6387 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6388 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6389 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6390 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
6395 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6396 phba->slim2p.virt, phba->slim2p.phys);
6398 iounmap(phba->ctrl_regs_memmap_p);
6400 iounmap(phba->slim_memmap_p);
6406 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6407 * @phba: pointer to lpfc hba data structure.
6409 * This routine is invoked to unset the PCI device memory space for device
6410 * with SLI-3 interface spec.
6413 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6415 struct pci_dev *pdev;
6417 /* Obtain PCI device reference */
6421 pdev = phba->pcidev;
6423 /* Free coherent DMA memory allocated */
6424 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6425 phba->hbqslimp.virt, phba->hbqslimp.phys);
6426 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6427 phba->slim2p.virt, phba->slim2p.phys);
6429 /* I/O memory unmap */
6430 iounmap(phba->ctrl_regs_memmap_p);
6431 iounmap(phba->slim_memmap_p);
6437 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6438 * @phba: pointer to lpfc hba data structure.
6440 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6441 * done and check status.
6443 * Return 0 if successful, otherwise -ENODEV.
6446 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6448 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6449 struct lpfc_register reg_data;
6450 int i, port_error = 0;
6453 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6454 memset(®_data, 0, sizeof(reg_data));
6455 if (!phba->sli4_hba.PSMPHRregaddr)
6458 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6459 for (i = 0; i < 3000; i++) {
6460 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6461 &portsmphr_reg.word0) ||
6462 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
6463 /* Port has a fatal POST error, break out */
6464 port_error = -ENODEV;
6467 if (LPFC_POST_STAGE_PORT_READY ==
6468 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
6474 * If there was a port error during POST, then don't proceed with
6475 * other register reads as the data may not be valid. Just exit.
6478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6479 "1408 Port Failed POST - portsmphr=0x%x, "
6480 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6481 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6482 portsmphr_reg.word0,
6483 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6484 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6485 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6486 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6487 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6488 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6489 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6490 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6492 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6493 "2534 Device Info: SLIFamily=0x%x, "
6494 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6495 "SLIHint_2=0x%x, FT=0x%x\n",
6496 bf_get(lpfc_sli_intf_sli_family,
6497 &phba->sli4_hba.sli_intf),
6498 bf_get(lpfc_sli_intf_slirev,
6499 &phba->sli4_hba.sli_intf),
6500 bf_get(lpfc_sli_intf_if_type,
6501 &phba->sli4_hba.sli_intf),
6502 bf_get(lpfc_sli_intf_sli_hint1,
6503 &phba->sli4_hba.sli_intf),
6504 bf_get(lpfc_sli_intf_sli_hint2,
6505 &phba->sli4_hba.sli_intf),
6506 bf_get(lpfc_sli_intf_func_type,
6507 &phba->sli4_hba.sli_intf));
6509 * Check for other Port errors during the initialization
6510 * process. Fail the load if the port did not come up
6513 if_type = bf_get(lpfc_sli_intf_if_type,
6514 &phba->sli4_hba.sli_intf);
6516 case LPFC_SLI_INTF_IF_TYPE_0:
6517 phba->sli4_hba.ue_mask_lo =
6518 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6519 phba->sli4_hba.ue_mask_hi =
6520 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6522 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6524 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6525 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6526 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6528 "1422 Unrecoverable Error "
6529 "Detected during POST "
6530 "uerr_lo_reg=0x%x, "
6531 "uerr_hi_reg=0x%x, "
6532 "ue_mask_lo_reg=0x%x, "
6533 "ue_mask_hi_reg=0x%x\n",
6536 phba->sli4_hba.ue_mask_lo,
6537 phba->sli4_hba.ue_mask_hi);
6538 port_error = -ENODEV;
6541 case LPFC_SLI_INTF_IF_TYPE_2:
6542 /* Final checks. The port status should be clean. */
6543 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6545 (bf_get(lpfc_sliport_status_err, ®_data) &&
6546 !bf_get(lpfc_sliport_status_rn, ®_data))) {
6547 phba->work_status[0] =
6548 readl(phba->sli4_hba.u.if_type2.
6550 phba->work_status[1] =
6551 readl(phba->sli4_hba.u.if_type2.
6553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6554 "2888 Unrecoverable port error "
6555 "following POST: port status reg "
6556 "0x%x, port_smphr reg 0x%x, "
6557 "error 1=0x%x, error 2=0x%x\n",
6559 portsmphr_reg.word0,
6560 phba->work_status[0],
6561 phba->work_status[1]);
6562 port_error = -ENODEV;
6565 case LPFC_SLI_INTF_IF_TYPE_1:
6574 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6575 * @phba: pointer to lpfc hba data structure.
6576 * @if_type: The SLI4 interface type getting configured.
6578 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6582 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
6585 case LPFC_SLI_INTF_IF_TYPE_0:
6586 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6587 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6588 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6589 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6590 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6591 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6592 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6593 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6594 phba->sli4_hba.SLIINTFregaddr =
6595 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6597 case LPFC_SLI_INTF_IF_TYPE_2:
6598 phba->sli4_hba.u.if_type2.ERR1regaddr =
6599 phba->sli4_hba.conf_regs_memmap_p +
6600 LPFC_CTL_PORT_ER1_OFFSET;
6601 phba->sli4_hba.u.if_type2.ERR2regaddr =
6602 phba->sli4_hba.conf_regs_memmap_p +
6603 LPFC_CTL_PORT_ER2_OFFSET;
6604 phba->sli4_hba.u.if_type2.CTRLregaddr =
6605 phba->sli4_hba.conf_regs_memmap_p +
6606 LPFC_CTL_PORT_CTL_OFFSET;
6607 phba->sli4_hba.u.if_type2.STATUSregaddr =
6608 phba->sli4_hba.conf_regs_memmap_p +
6609 LPFC_CTL_PORT_STA_OFFSET;
6610 phba->sli4_hba.SLIINTFregaddr =
6611 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6612 phba->sli4_hba.PSMPHRregaddr =
6613 phba->sli4_hba.conf_regs_memmap_p +
6614 LPFC_CTL_PORT_SEM_OFFSET;
6615 phba->sli4_hba.RQDBregaddr =
6616 phba->sli4_hba.conf_regs_memmap_p +
6617 LPFC_ULP0_RQ_DOORBELL;
6618 phba->sli4_hba.WQDBregaddr =
6619 phba->sli4_hba.conf_regs_memmap_p +
6620 LPFC_ULP0_WQ_DOORBELL;
6621 phba->sli4_hba.EQCQDBregaddr =
6622 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6623 phba->sli4_hba.MQDBregaddr =
6624 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6625 phba->sli4_hba.BMBXregaddr =
6626 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6628 case LPFC_SLI_INTF_IF_TYPE_1:
6630 dev_printk(KERN_ERR, &phba->pcidev->dev,
6631 "FATAL - unsupported SLI4 interface type - %d\n",
6638 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6639 * @phba: pointer to lpfc hba data structure.
6641 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6645 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6647 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6648 LPFC_SLIPORT_IF0_SMPHR;
6649 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6651 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6653 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6658 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6659 * @phba: pointer to lpfc hba data structure.
6660 * @vf: virtual function number
6662 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6663 * based on the given viftual function number, @vf.
6665 * Return 0 if successful, otherwise -ENODEV.
6668 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6670 if (vf > LPFC_VIR_FUNC_MAX)
6673 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6674 vf * LPFC_VFR_PAGE_SIZE +
6675 LPFC_ULP0_RQ_DOORBELL);
6676 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6677 vf * LPFC_VFR_PAGE_SIZE +
6678 LPFC_ULP0_WQ_DOORBELL);
6679 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6680 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6681 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6682 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6683 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6684 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6689 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6690 * @phba: pointer to lpfc hba data structure.
6692 * This routine is invoked to create the bootstrap mailbox
6693 * region consistent with the SLI-4 interface spec. This
6694 * routine allocates all memory necessary to communicate
6695 * mailbox commands to the port and sets up all alignment
6696 * needs. No locks are expected to be held when calling
6701 * -ENOMEM - could not allocated memory.
6704 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6707 struct lpfc_dmabuf *dmabuf;
6708 struct dma_address *dma_address;
6712 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6717 * The bootstrap mailbox region is comprised of 2 parts
6718 * plus an alignment restriction of 16 bytes.
6720 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
6721 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6722 &dmabuf->phys, GFP_KERNEL);
6723 if (!dmabuf->virt) {
6729 * Initialize the bootstrap mailbox pointers now so that the register
6730 * operations are simple later. The mailbox dma address is required
6731 * to be 16-byte aligned. Also align the virtual memory as each
6732 * maibox is copied into the bmbx mailbox region before issuing the
6733 * command to the port.
6735 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6736 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6738 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6739 LPFC_ALIGN_16_BYTE);
6740 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6741 LPFC_ALIGN_16_BYTE);
6744 * Set the high and low physical addresses now. The SLI4 alignment
6745 * requirement is 16 bytes and the mailbox is posted to the port
6746 * as two 30-bit addresses. The other data is a bit marking whether
6747 * the 30-bit address is the high or low address.
6748 * Upcast bmbx aphys to 64bits so shift instruction compiles
6749 * clean on 32 bit machines.
6751 dma_address = &phba->sli4_hba.bmbx.dma_address;
6752 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6753 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6754 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6755 LPFC_BMBX_BIT1_ADDR_HI);
6757 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6758 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6759 LPFC_BMBX_BIT1_ADDR_LO);
6764 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6765 * @phba: pointer to lpfc hba data structure.
6767 * This routine is invoked to teardown the bootstrap mailbox
6768 * region and release all host resources. This routine requires
6769 * the caller to ensure all mailbox commands recovered, no
6770 * additional mailbox comands are sent, and interrupts are disabled
6771 * before calling this routine.
6775 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6777 dma_free_coherent(&phba->pcidev->dev,
6778 phba->sli4_hba.bmbx.bmbx_size,
6779 phba->sli4_hba.bmbx.dmabuf->virt,
6780 phba->sli4_hba.bmbx.dmabuf->phys);
6782 kfree(phba->sli4_hba.bmbx.dmabuf);
6783 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6787 * lpfc_sli4_read_config - Get the config parameters.
6788 * @phba: pointer to lpfc hba data structure.
6790 * This routine is invoked to read the configuration parameters from the HBA.
6791 * The configuration parameters are used to set the base and maximum values
6792 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6793 * allocation for the port.
6797 * -ENOMEM - No available memory
6798 * -EIO - The mailbox failed to complete successfully.
6801 lpfc_sli4_read_config(struct lpfc_hba *phba)
6804 struct lpfc_mbx_read_config *rd_config;
6805 union lpfc_sli4_cfg_shdr *shdr;
6806 uint32_t shdr_status, shdr_add_status;
6807 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6808 struct lpfc_rsrc_desc_fcfcoe *desc;
6810 int length, i, rc = 0, rc2;
6812 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6814 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6815 "2011 Unable to allocate memory for issuing "
6816 "SLI_CONFIG_SPECIAL mailbox command\n");
6820 lpfc_read_config(phba, pmb);
6822 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6823 if (rc != MBX_SUCCESS) {
6824 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6825 "2012 Mailbox failed , mbxCmd x%x "
6826 "READ_CONFIG, mbxStatus x%x\n",
6827 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6828 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6831 rd_config = &pmb->u.mqe.un.rd_config;
6832 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6833 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6834 phba->sli4_hba.lnk_info.lnk_tp =
6835 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6836 phba->sli4_hba.lnk_info.lnk_no =
6837 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6838 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6839 "3081 lnk_type:%d, lnk_numb:%d\n",
6840 phba->sli4_hba.lnk_info.lnk_tp,
6841 phba->sli4_hba.lnk_info.lnk_no);
6843 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6844 "3082 Mailbox (x%x) returned ldv:x0\n",
6845 bf_get(lpfc_mqe_command, &pmb->u.mqe));
6846 phba->sli4_hba.extents_in_use =
6847 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
6848 phba->sli4_hba.max_cfg_param.max_xri =
6849 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6850 phba->sli4_hba.max_cfg_param.xri_base =
6851 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6852 phba->sli4_hba.max_cfg_param.max_vpi =
6853 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6854 phba->sli4_hba.max_cfg_param.vpi_base =
6855 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6856 phba->sli4_hba.max_cfg_param.max_rpi =
6857 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6858 phba->sli4_hba.max_cfg_param.rpi_base =
6859 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6860 phba->sli4_hba.max_cfg_param.max_vfi =
6861 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6862 phba->sli4_hba.max_cfg_param.vfi_base =
6863 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6864 phba->sli4_hba.max_cfg_param.max_fcfi =
6865 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
6866 phba->sli4_hba.max_cfg_param.max_eq =
6867 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6868 phba->sli4_hba.max_cfg_param.max_rq =
6869 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6870 phba->sli4_hba.max_cfg_param.max_wq =
6871 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6872 phba->sli4_hba.max_cfg_param.max_cq =
6873 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6874 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6875 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6876 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6877 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
6878 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6879 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
6880 phba->max_vports = phba->max_vpi;
6881 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6882 "2003 cfg params Extents? %d "
6888 phba->sli4_hba.extents_in_use,
6889 phba->sli4_hba.max_cfg_param.xri_base,
6890 phba->sli4_hba.max_cfg_param.max_xri,
6891 phba->sli4_hba.max_cfg_param.vpi_base,
6892 phba->sli4_hba.max_cfg_param.max_vpi,
6893 phba->sli4_hba.max_cfg_param.vfi_base,
6894 phba->sli4_hba.max_cfg_param.max_vfi,
6895 phba->sli4_hba.max_cfg_param.rpi_base,
6896 phba->sli4_hba.max_cfg_param.max_rpi,
6897 phba->sli4_hba.max_cfg_param.max_fcfi);
6903 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
6904 length = phba->sli4_hba.max_cfg_param.max_xri -
6905 lpfc_sli4_get_els_iocb_cnt(phba);
6906 if (phba->cfg_hba_queue_depth > length) {
6907 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6908 "3361 HBA queue depth changed from %d to %d\n",
6909 phba->cfg_hba_queue_depth, length);
6910 phba->cfg_hba_queue_depth = length;
6913 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6914 LPFC_SLI_INTF_IF_TYPE_2)
6917 /* get the pf# and vf# for SLI4 if_type 2 port */
6918 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6919 sizeof(struct lpfc_sli4_cfg_mhdr));
6920 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6921 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6922 length, LPFC_SLI4_MBX_EMBED);
6924 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6925 shdr = (union lpfc_sli4_cfg_shdr *)
6926 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6927 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6928 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6929 if (rc2 || shdr_status || shdr_add_status) {
6930 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6931 "3026 Mailbox failed , mbxCmd x%x "
6932 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6933 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6934 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6938 /* search for fc_fcoe resrouce descriptor */
6939 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6941 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6942 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6943 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6944 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6945 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6946 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6949 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
6950 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
6951 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
6952 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
6953 phba->sli4_hba.iov.pf_number =
6954 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6955 phba->sli4_hba.iov.vf_number =
6956 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6961 if (i < LPFC_RSRC_DESC_MAX_NUM)
6962 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6963 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6964 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6965 phba->sli4_hba.iov.vf_number);
6967 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6968 "3028 GET_FUNCTION_CONFIG: failed to find "
6969 "Resrouce Descriptor:x%x\n",
6970 LPFC_RSRC_DESC_TYPE_FCFCOE);
6973 mempool_free(pmb, phba->mbox_mem_pool);
6978 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
6979 * @phba: pointer to lpfc hba data structure.
6981 * This routine is invoked to setup the port-side endian order when
6982 * the port if_type is 0. This routine has no function for other
6987 * -ENOMEM - No available memory
6988 * -EIO - The mailbox failed to complete successfully.
6991 lpfc_setup_endian_order(struct lpfc_hba *phba)
6993 LPFC_MBOXQ_t *mboxq;
6994 uint32_t if_type, rc = 0;
6995 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6996 HOST_ENDIAN_HIGH_WORD1};
6998 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7000 case LPFC_SLI_INTF_IF_TYPE_0:
7001 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7005 "0492 Unable to allocate memory for "
7006 "issuing SLI_CONFIG_SPECIAL mailbox "
7012 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7013 * two words to contain special data values and no other data.
7015 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7016 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7017 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7018 if (rc != MBX_SUCCESS) {
7019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7020 "0493 SLI_CONFIG_SPECIAL mailbox "
7021 "failed with status x%x\n",
7025 mempool_free(mboxq, phba->mbox_mem_pool);
7027 case LPFC_SLI_INTF_IF_TYPE_2:
7028 case LPFC_SLI_INTF_IF_TYPE_1:
7036 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
7037 * @phba: pointer to lpfc hba data structure.
7039 * This routine is invoked to check the user settable queue counts for EQs and
7040 * CQs. after this routine is called the counts will be set to valid values that
7041 * adhere to the constraints of the system's interrupt vectors and the port's
7046 * -ENOMEM - No available memory
7049 lpfc_sli4_queue_verify(struct lpfc_hba *phba)
7051 int cfg_fcp_io_channel;
7054 int fof_vectors = phba->cfg_fof ? 1 : 0;
7057 * Sanity check for configured queue parameters against the run-time
7061 /* Sanity check on HBA EQ parameters */
7062 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
7064 /* It doesn't make sense to have more io channels then online CPUs */
7065 for_each_present_cpu(cpu) {
7066 if (cpu_online(cpu))
7069 phba->sli4_hba.num_online_cpu = i;
7070 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
7071 phba->sli4_hba.curr_disp_cpu = 0;
7073 if (i < cfg_fcp_io_channel) {
7074 lpfc_printf_log(phba,
7076 "3188 Reducing IO channels to match number of "
7077 "online CPUs: from %d to %d\n",
7078 cfg_fcp_io_channel, i);
7079 cfg_fcp_io_channel = i;
7082 if (cfg_fcp_io_channel + fof_vectors >
7083 phba->sli4_hba.max_cfg_param.max_eq) {
7084 if (phba->sli4_hba.max_cfg_param.max_eq <
7085 LPFC_FCP_IO_CHAN_MIN) {
7086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7087 "2574 Not enough EQs (%d) from the "
7088 "pci function for supporting FCP "
7090 phba->sli4_hba.max_cfg_param.max_eq,
7091 phba->cfg_fcp_io_channel);
7094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7095 "2575 Reducing IO channels to match number of "
7096 "available EQs: from %d to %d\n",
7098 phba->sli4_hba.max_cfg_param.max_eq);
7099 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7103 /* The actual number of FCP event queues adopted */
7104 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
7106 /* Get EQ depth from module parameter, fake the default for now */
7107 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7108 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7110 /* Get CQ depth from module parameter, fake the default for now */
7111 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7112 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7120 * lpfc_sli4_queue_create - Create all the SLI4 queues
7121 * @phba: pointer to lpfc hba data structure.
7123 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7124 * operation. For each SLI4 queue type, the parameters such as queue entry
7125 * count (queue depth) shall be taken from the module parameter. For now,
7126 * we just use some constant number as place holder.
7130 * -ENOMEM - No availble memory
7131 * -EIO - The mailbox failed to complete successfully.
7134 lpfc_sli4_queue_create(struct lpfc_hba *phba)
7136 struct lpfc_queue *qdesc;
7140 * Create HBA Record arrays.
7142 if (!phba->cfg_fcp_io_channel)
7145 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7146 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7147 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7148 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7149 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7150 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7152 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7153 phba->cfg_fcp_io_channel), GFP_KERNEL);
7154 if (!phba->sli4_hba.hba_eq) {
7155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7156 "2576 Failed allocate memory for "
7157 "fast-path EQ record array\n");
7161 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7162 phba->cfg_fcp_io_channel), GFP_KERNEL);
7163 if (!phba->sli4_hba.fcp_cq) {
7164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7165 "2577 Failed allocate memory for fast-path "
7166 "CQ record array\n");
7170 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7171 phba->cfg_fcp_io_channel), GFP_KERNEL);
7172 if (!phba->sli4_hba.fcp_wq) {
7173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7174 "2578 Failed allocate memory for fast-path "
7175 "WQ record array\n");
7180 * Since the first EQ can have multiple CQs associated with it,
7181 * this array is used to quickly see if we have a FCP fast-path
7184 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7185 phba->cfg_fcp_io_channel), GFP_KERNEL);
7186 if (!phba->sli4_hba.fcp_cq_map) {
7187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7188 "2545 Failed allocate memory for fast-path "
7194 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7195 * how many EQs to create.
7197 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7200 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7201 phba->sli4_hba.eq_ecount);
7203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7204 "0497 Failed allocate EQ (%d)\n", idx);
7207 phba->sli4_hba.hba_eq[idx] = qdesc;
7209 /* Create Fast Path FCP CQs */
7210 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7211 phba->sli4_hba.cq_ecount);
7213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7214 "0499 Failed allocate fast-path FCP "
7218 phba->sli4_hba.fcp_cq[idx] = qdesc;
7220 /* Create Fast Path FCP WQs */
7221 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7222 phba->sli4_hba.wq_ecount);
7224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7225 "0503 Failed allocate fast-path FCP "
7229 phba->sli4_hba.fcp_wq[idx] = qdesc;
7234 * Create Slow Path Completion Queues (CQs)
7237 /* Create slow-path Mailbox Command Complete Queue */
7238 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7239 phba->sli4_hba.cq_ecount);
7241 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7242 "0500 Failed allocate slow-path mailbox CQ\n");
7245 phba->sli4_hba.mbx_cq = qdesc;
7247 /* Create slow-path ELS Complete Queue */
7248 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7249 phba->sli4_hba.cq_ecount);
7251 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7252 "0501 Failed allocate slow-path ELS CQ\n");
7255 phba->sli4_hba.els_cq = qdesc;
7259 * Create Slow Path Work Queues (WQs)
7262 /* Create Mailbox Command Queue */
7264 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7265 phba->sli4_hba.mq_ecount);
7267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7268 "0505 Failed allocate slow-path MQ\n");
7271 phba->sli4_hba.mbx_wq = qdesc;
7274 * Create ELS Work Queues
7277 /* Create slow-path ELS Work Queue */
7278 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7279 phba->sli4_hba.wq_ecount);
7281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7282 "0504 Failed allocate slow-path ELS WQ\n");
7285 phba->sli4_hba.els_wq = qdesc;
7288 * Create Receive Queue (RQ)
7291 /* Create Receive Queue for header */
7292 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7293 phba->sli4_hba.rq_ecount);
7295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7296 "0506 Failed allocate receive HRQ\n");
7299 phba->sli4_hba.hdr_rq = qdesc;
7301 /* Create Receive Queue for data */
7302 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7303 phba->sli4_hba.rq_ecount);
7305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7306 "0507 Failed allocate receive DRQ\n");
7309 phba->sli4_hba.dat_rq = qdesc;
7311 /* Create the Queues needed for Flash Optimized Fabric operations */
7313 lpfc_fof_queue_create(phba);
7317 lpfc_sli4_queue_destroy(phba);
7322 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7323 * @phba: pointer to lpfc hba data structure.
7325 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7330 * -ENOMEM - No available memory
7331 * -EIO - The mailbox failed to complete successfully.
7334 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7339 lpfc_fof_queue_destroy(phba);
7341 if (phba->sli4_hba.hba_eq != NULL) {
7342 /* Release HBA event queue */
7343 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7344 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7345 lpfc_sli4_queue_free(
7346 phba->sli4_hba.hba_eq[idx]);
7347 phba->sli4_hba.hba_eq[idx] = NULL;
7350 kfree(phba->sli4_hba.hba_eq);
7351 phba->sli4_hba.hba_eq = NULL;
7354 if (phba->sli4_hba.fcp_cq != NULL) {
7355 /* Release FCP completion queue */
7356 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7357 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7358 lpfc_sli4_queue_free(
7359 phba->sli4_hba.fcp_cq[idx]);
7360 phba->sli4_hba.fcp_cq[idx] = NULL;
7363 kfree(phba->sli4_hba.fcp_cq);
7364 phba->sli4_hba.fcp_cq = NULL;
7367 if (phba->sli4_hba.fcp_wq != NULL) {
7368 /* Release FCP work queue */
7369 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7370 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7371 lpfc_sli4_queue_free(
7372 phba->sli4_hba.fcp_wq[idx]);
7373 phba->sli4_hba.fcp_wq[idx] = NULL;
7376 kfree(phba->sli4_hba.fcp_wq);
7377 phba->sli4_hba.fcp_wq = NULL;
7380 /* Release FCP CQ mapping array */
7381 if (phba->sli4_hba.fcp_cq_map != NULL) {
7382 kfree(phba->sli4_hba.fcp_cq_map);
7383 phba->sli4_hba.fcp_cq_map = NULL;
7386 /* Release mailbox command work queue */
7387 if (phba->sli4_hba.mbx_wq != NULL) {
7388 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7389 phba->sli4_hba.mbx_wq = NULL;
7392 /* Release ELS work queue */
7393 if (phba->sli4_hba.els_wq != NULL) {
7394 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7395 phba->sli4_hba.els_wq = NULL;
7398 /* Release unsolicited receive queue */
7399 if (phba->sli4_hba.hdr_rq != NULL) {
7400 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7401 phba->sli4_hba.hdr_rq = NULL;
7403 if (phba->sli4_hba.dat_rq != NULL) {
7404 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7405 phba->sli4_hba.dat_rq = NULL;
7408 /* Release ELS complete queue */
7409 if (phba->sli4_hba.els_cq != NULL) {
7410 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7411 phba->sli4_hba.els_cq = NULL;
7414 /* Release mailbox command complete queue */
7415 if (phba->sli4_hba.mbx_cq != NULL) {
7416 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7417 phba->sli4_hba.mbx_cq = NULL;
7424 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7425 * @phba: pointer to lpfc hba data structure.
7427 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7432 * -ENOMEM - No available memory
7433 * -EIO - The mailbox failed to complete successfully.
7436 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7438 struct lpfc_sli *psli = &phba->sli;
7439 struct lpfc_sli_ring *pring;
7441 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7442 int fcp_cq_index = 0;
7443 uint32_t shdr_status, shdr_add_status;
7444 union lpfc_sli4_cfg_shdr *shdr;
7445 LPFC_MBOXQ_t *mboxq;
7448 /* Check for dual-ULP support */
7449 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7452 "3249 Unable to allocate memory for "
7453 "QUERY_FW_CFG mailbox command\n");
7456 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7457 sizeof(struct lpfc_sli4_cfg_mhdr));
7458 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7459 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7460 length, LPFC_SLI4_MBX_EMBED);
7462 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7464 shdr = (union lpfc_sli4_cfg_shdr *)
7465 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7466 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7467 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7468 if (shdr_status || shdr_add_status || rc) {
7469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7470 "3250 QUERY_FW_CFG mailbox failed with status "
7471 "x%x add_status x%x, mbx status x%x\n",
7472 shdr_status, shdr_add_status, rc);
7473 if (rc != MBX_TIMEOUT)
7474 mempool_free(mboxq, phba->mbox_mem_pool);
7479 phba->sli4_hba.fw_func_mode =
7480 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7481 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7482 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
7483 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7484 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7485 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7486 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7488 if (rc != MBX_TIMEOUT)
7489 mempool_free(mboxq, phba->mbox_mem_pool);
7492 * Set up HBA Event Queues (EQs)
7495 /* Set up HBA event queue */
7496 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
7497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7498 "3147 Fast-path EQs not allocated\n");
7502 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7503 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
7504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7505 "0522 Fast-path EQ (%d) not "
7506 "allocated\n", fcp_eqidx);
7508 goto out_destroy_hba_eq;
7510 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
7511 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
7513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7514 "0523 Failed setup of fast-path EQ "
7515 "(%d), rc = 0x%x\n", fcp_eqidx,
7517 goto out_destroy_hba_eq;
7519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7520 "2584 HBA EQ setup: "
7521 "queue[%d]-id=%d\n", fcp_eqidx,
7522 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
7525 /* Set up fast-path FCP Response Complete Queue */
7526 if (!phba->sli4_hba.fcp_cq) {
7527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7528 "3148 Fast-path FCP CQ array not "
7531 goto out_destroy_hba_eq;
7534 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7535 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7536 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7537 "0526 Fast-path FCP CQ (%d) not "
7538 "allocated\n", fcp_cqidx);
7540 goto out_destroy_fcp_cq;
7542 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7543 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7545 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7546 "0527 Failed setup of fast-path FCP "
7547 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7549 goto out_destroy_fcp_cq;
7552 /* Setup fcp_cq_map for fast lookup */
7553 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7554 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7556 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7557 "2588 FCP CQ setup: cq[%d]-id=%d, "
7558 "parent seq[%d]-id=%d\n",
7560 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7562 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7565 /* Set up fast-path FCP Work Queue */
7566 if (!phba->sli4_hba.fcp_wq) {
7567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7568 "3149 Fast-path FCP WQ array not "
7571 goto out_destroy_fcp_cq;
7574 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7575 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7576 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7577 "0534 Fast-path FCP WQ (%d) not "
7578 "allocated\n", fcp_wqidx);
7580 goto out_destroy_fcp_wq;
7582 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7583 phba->sli4_hba.fcp_cq[fcp_wqidx],
7586 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7587 "0535 Failed setup of fast-path FCP "
7588 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7590 goto out_destroy_fcp_wq;
7593 /* Bind this WQ to the next FCP ring */
7594 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7595 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7596 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7598 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7599 "2591 FCP WQ setup: wq[%d]-id=%d, "
7600 "parent cq[%d]-id=%d\n",
7602 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7604 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7607 * Set up Complete Queues (CQs)
7610 /* Set up slow-path MBOX Complete Queue as the first CQ */
7611 if (!phba->sli4_hba.mbx_cq) {
7612 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7613 "0528 Mailbox CQ not allocated\n");
7615 goto out_destroy_fcp_wq;
7617 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7618 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
7620 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7621 "0529 Failed setup of slow-path mailbox CQ: "
7622 "rc = 0x%x\n", (uint32_t)rc);
7623 goto out_destroy_fcp_wq;
7625 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7626 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7627 phba->sli4_hba.mbx_cq->queue_id,
7628 phba->sli4_hba.hba_eq[0]->queue_id);
7630 /* Set up slow-path ELS Complete Queue */
7631 if (!phba->sli4_hba.els_cq) {
7632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7633 "0530 ELS CQ not allocated\n");
7635 goto out_destroy_mbx_cq;
7637 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7638 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
7640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7641 "0531 Failed setup of slow-path ELS CQ: "
7642 "rc = 0x%x\n", (uint32_t)rc);
7643 goto out_destroy_mbx_cq;
7645 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7646 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7647 phba->sli4_hba.els_cq->queue_id,
7648 phba->sli4_hba.hba_eq[0]->queue_id);
7651 * Set up all the Work Queues (WQs)
7654 /* Set up Mailbox Command Queue */
7655 if (!phba->sli4_hba.mbx_wq) {
7656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7657 "0538 Slow-path MQ not allocated\n");
7659 goto out_destroy_els_cq;
7661 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7662 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7665 "0539 Failed setup of slow-path MQ: "
7667 goto out_destroy_els_cq;
7669 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7670 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7671 phba->sli4_hba.mbx_wq->queue_id,
7672 phba->sli4_hba.mbx_cq->queue_id);
7674 /* Set up slow-path ELS Work Queue */
7675 if (!phba->sli4_hba.els_wq) {
7676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7677 "0536 Slow-path ELS WQ not allocated\n");
7679 goto out_destroy_mbx_wq;
7681 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7682 phba->sli4_hba.els_cq, LPFC_ELS);
7684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7685 "0537 Failed setup of slow-path ELS WQ: "
7686 "rc = 0x%x\n", (uint32_t)rc);
7687 goto out_destroy_mbx_wq;
7690 /* Bind this WQ to the ELS ring */
7691 pring = &psli->ring[LPFC_ELS_RING];
7692 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7693 phba->sli4_hba.els_cq->pring = pring;
7695 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7696 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7697 phba->sli4_hba.els_wq->queue_id,
7698 phba->sli4_hba.els_cq->queue_id);
7701 * Create Receive Queue (RQ)
7703 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7705 "0540 Receive Queue not allocated\n");
7707 goto out_destroy_els_wq;
7710 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7711 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7713 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
7714 phba->sli4_hba.els_cq, LPFC_USOL);
7716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7717 "0541 Failed setup of Receive Queue: "
7718 "rc = 0x%x\n", (uint32_t)rc);
7719 goto out_destroy_fcp_wq;
7722 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7723 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7724 "parent cq-id=%d\n",
7725 phba->sli4_hba.hdr_rq->queue_id,
7726 phba->sli4_hba.dat_rq->queue_id,
7727 phba->sli4_hba.els_cq->queue_id);
7729 if (phba->cfg_fof) {
7730 rc = lpfc_fof_queue_setup(phba);
7732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7733 "0549 Failed setup of FOF Queues: "
7735 goto out_destroy_els_rq;
7740 * Configure EQ delay multipier for interrupt coalescing using
7741 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7743 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7744 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7745 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
7749 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7751 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7753 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7755 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7757 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7759 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7760 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7762 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7763 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7765 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
7766 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
7772 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7773 * @phba: pointer to lpfc hba data structure.
7775 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7780 * -ENOMEM - No available memory
7781 * -EIO - The mailbox failed to complete successfully.
7784 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7788 /* Unset the queues created for Flash Optimized Fabric operations */
7790 lpfc_fof_queue_destroy(phba);
7791 /* Unset mailbox command work queue */
7792 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7793 /* Unset ELS work queue */
7794 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7795 /* Unset unsolicited receive queue */
7796 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7797 /* Unset FCP work queue */
7798 if (phba->sli4_hba.fcp_wq) {
7799 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7801 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7803 /* Unset mailbox command complete queue */
7804 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7805 /* Unset ELS complete queue */
7806 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7807 /* Unset FCP response complete queue */
7808 if (phba->sli4_hba.fcp_cq) {
7809 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7811 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
7813 /* Unset fast-path event queue */
7814 if (phba->sli4_hba.hba_eq) {
7815 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7817 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
7822 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7823 * @phba: pointer to lpfc hba data structure.
7825 * This routine is invoked to allocate and set up a pool of completion queue
7826 * events. The body of the completion queue event is a completion queue entry
7827 * CQE. For now, this pool is used for the interrupt service routine to queue
7828 * the following HBA completion queue events for the worker thread to process:
7829 * - Mailbox asynchronous events
7830 * - Receive queue completion unsolicited events
7831 * Later, this can be used for all the slow-path events.
7835 * -ENOMEM - No available memory
7838 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7840 struct lpfc_cq_event *cq_event;
7843 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7844 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7846 goto out_pool_create_fail;
7847 list_add_tail(&cq_event->list,
7848 &phba->sli4_hba.sp_cqe_event_pool);
7852 out_pool_create_fail:
7853 lpfc_sli4_cq_event_pool_destroy(phba);
7858 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7859 * @phba: pointer to lpfc hba data structure.
7861 * This routine is invoked to free the pool of completion queue events at
7862 * driver unload time. Note that, it is the responsibility of the driver
7863 * cleanup routine to free all the outstanding completion-queue events
7864 * allocated from this pool back into the pool before invoking this routine
7865 * to destroy the pool.
7868 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7870 struct lpfc_cq_event *cq_event, *next_cq_event;
7872 list_for_each_entry_safe(cq_event, next_cq_event,
7873 &phba->sli4_hba.sp_cqe_event_pool, list) {
7874 list_del(&cq_event->list);
7880 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7881 * @phba: pointer to lpfc hba data structure.
7883 * This routine is the lock free version of the API invoked to allocate a
7884 * completion-queue event from the free pool.
7886 * Return: Pointer to the newly allocated completion-queue event if successful
7889 struct lpfc_cq_event *
7890 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7892 struct lpfc_cq_event *cq_event = NULL;
7894 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7895 struct lpfc_cq_event, list);
7900 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7901 * @phba: pointer to lpfc hba data structure.
7903 * This routine is the lock version of the API invoked to allocate a
7904 * completion-queue event from the free pool.
7906 * Return: Pointer to the newly allocated completion-queue event if successful
7909 struct lpfc_cq_event *
7910 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7912 struct lpfc_cq_event *cq_event;
7913 unsigned long iflags;
7915 spin_lock_irqsave(&phba->hbalock, iflags);
7916 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7917 spin_unlock_irqrestore(&phba->hbalock, iflags);
7922 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7923 * @phba: pointer to lpfc hba data structure.
7924 * @cq_event: pointer to the completion queue event to be freed.
7926 * This routine is the lock free version of the API invoked to release a
7927 * completion-queue event back into the free pool.
7930 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7931 struct lpfc_cq_event *cq_event)
7933 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7937 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7938 * @phba: pointer to lpfc hba data structure.
7939 * @cq_event: pointer to the completion queue event to be freed.
7941 * This routine is the lock version of the API invoked to release a
7942 * completion-queue event back into the free pool.
7945 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7946 struct lpfc_cq_event *cq_event)
7948 unsigned long iflags;
7949 spin_lock_irqsave(&phba->hbalock, iflags);
7950 __lpfc_sli4_cq_event_release(phba, cq_event);
7951 spin_unlock_irqrestore(&phba->hbalock, iflags);
7955 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7956 * @phba: pointer to lpfc hba data structure.
7958 * This routine is to free all the pending completion-queue events to the
7959 * back into the free pool for device reset.
7962 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7965 struct lpfc_cq_event *cqe;
7966 unsigned long iflags;
7968 /* Retrieve all the pending WCQEs from pending WCQE lists */
7969 spin_lock_irqsave(&phba->hbalock, iflags);
7970 /* Pending FCP XRI abort events */
7971 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7973 /* Pending ELS XRI abort events */
7974 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7976 /* Pending asynnc events */
7977 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7979 spin_unlock_irqrestore(&phba->hbalock, iflags);
7981 while (!list_empty(&cqelist)) {
7982 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7983 lpfc_sli4_cq_event_release(phba, cqe);
7988 * lpfc_pci_function_reset - Reset pci function.
7989 * @phba: pointer to lpfc hba data structure.
7991 * This routine is invoked to request a PCI function reset. It will destroys
7992 * all resources assigned to the PCI function which originates this request.
7996 * -ENOMEM - No available memory
7997 * -EIO - The mailbox failed to complete successfully.
8000 lpfc_pci_function_reset(struct lpfc_hba *phba)
8002 LPFC_MBOXQ_t *mboxq;
8003 uint32_t rc = 0, if_type;
8004 uint32_t shdr_status, shdr_add_status;
8006 uint32_t port_reset = 0;
8007 union lpfc_sli4_cfg_shdr *shdr;
8008 struct lpfc_register reg_data;
8011 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8013 case LPFC_SLI_INTF_IF_TYPE_0:
8014 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8018 "0494 Unable to allocate memory for "
8019 "issuing SLI_FUNCTION_RESET mailbox "
8024 /* Setup PCI function reset mailbox-ioctl command */
8025 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8026 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8027 LPFC_SLI4_MBX_EMBED);
8028 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8029 shdr = (union lpfc_sli4_cfg_shdr *)
8030 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8031 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8032 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8034 if (rc != MBX_TIMEOUT)
8035 mempool_free(mboxq, phba->mbox_mem_pool);
8036 if (shdr_status || shdr_add_status || rc) {
8037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8038 "0495 SLI_FUNCTION_RESET mailbox "
8039 "failed with status x%x add_status x%x,"
8040 " mbx status x%x\n",
8041 shdr_status, shdr_add_status, rc);
8045 case LPFC_SLI_INTF_IF_TYPE_2:
8048 * Poll the Port Status Register and wait for RDY for
8049 * up to 30 seconds. If the port doesn't respond, treat
8052 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
8053 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8054 STATUSregaddr, ®_data.word0)) {
8058 if (bf_get(lpfc_sliport_status_rdy, ®_data))
8063 if (!bf_get(lpfc_sliport_status_rdy, ®_data)) {
8064 phba->work_status[0] = readl(
8065 phba->sli4_hba.u.if_type2.ERR1regaddr);
8066 phba->work_status[1] = readl(
8067 phba->sli4_hba.u.if_type2.ERR2regaddr);
8068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8069 "2890 Port not ready, port status reg "
8070 "0x%x error 1=0x%x, error 2=0x%x\n",
8072 phba->work_status[0],
8073 phba->work_status[1]);
8080 * Reset the port now
8083 bf_set(lpfc_sliport_ctrl_end, ®_data,
8084 LPFC_SLIPORT_LITTLE_ENDIAN);
8085 bf_set(lpfc_sliport_ctrl_ip, ®_data,
8086 LPFC_SLIPORT_INIT_PORT);
8087 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8090 pci_read_config_word(phba->pcidev,
8091 PCI_DEVICE_ID, &devid);
8096 } else if (bf_get(lpfc_sliport_status_rn, ®_data)) {
8102 case LPFC_SLI_INTF_IF_TYPE_1:
8108 /* Catch the not-ready port failure after a port reset. */
8110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8111 "3317 HBA not functional: IP Reset Failed "
8112 "try: echo fw_reset > board_mode\n");
8120 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8121 * @phba: pointer to lpfc hba data structure.
8123 * This routine is invoked to set up the PCI device memory space for device
8124 * with SLI-4 interface spec.
8128 * other values - error
8131 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8133 struct pci_dev *pdev;
8134 unsigned long bar0map_len, bar1map_len, bar2map_len;
8135 int error = -ENODEV;
8138 /* Obtain PCI device reference */
8142 pdev = phba->pcidev;
8144 /* Set the device DMA mask size */
8145 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8146 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8147 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8148 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
8154 * The BARs and register set definitions and offset locations are
8155 * dependent on the if_type.
8157 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8158 &phba->sli4_hba.sli_intf.word0)) {
8162 /* There is no SLI3 failback for SLI4 devices. */
8163 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8164 LPFC_SLI_INTF_VALID) {
8165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8166 "2894 SLI_INTF reg contents invalid "
8167 "sli_intf reg 0x%x\n",
8168 phba->sli4_hba.sli_intf.word0);
8172 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8174 * Get the bus address of SLI4 device Bar regions and the
8175 * number of bytes required by each mapping. The mapping of the
8176 * particular PCI BARs regions is dependent on the type of
8179 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8180 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8181 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
8184 * Map SLI4 PCI Config Space Register base to a kernel virtual
8187 phba->sli4_hba.conf_regs_memmap_p =
8188 ioremap(phba->pci_bar0_map, bar0map_len);
8189 if (!phba->sli4_hba.conf_regs_memmap_p) {
8190 dev_printk(KERN_ERR, &pdev->dev,
8191 "ioremap failed for SLI4 PCI config "
8195 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
8196 /* Set up BAR0 PCI config space register memory map */
8197 lpfc_sli4_bar0_register_memmap(phba, if_type);
8199 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8200 bar0map_len = pci_resource_len(pdev, 1);
8201 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8202 dev_printk(KERN_ERR, &pdev->dev,
8203 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8206 phba->sli4_hba.conf_regs_memmap_p =
8207 ioremap(phba->pci_bar0_map, bar0map_len);
8208 if (!phba->sli4_hba.conf_regs_memmap_p) {
8209 dev_printk(KERN_ERR, &pdev->dev,
8210 "ioremap failed for SLI4 PCI config "
8214 lpfc_sli4_bar0_register_memmap(phba, if_type);
8217 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
8218 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
8220 * Map SLI4 if type 0 HBA Control Register base to a kernel
8221 * virtual address and setup the registers.
8223 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8224 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
8225 phba->sli4_hba.ctrl_regs_memmap_p =
8226 ioremap(phba->pci_bar1_map, bar1map_len);
8227 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8228 dev_printk(KERN_ERR, &pdev->dev,
8229 "ioremap failed for SLI4 HBA control registers.\n");
8230 goto out_iounmap_conf;
8232 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
8233 lpfc_sli4_bar1_register_memmap(phba);
8236 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
8237 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
8239 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8240 * virtual address and setup the registers.
8242 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8243 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
8244 phba->sli4_hba.drbl_regs_memmap_p =
8245 ioremap(phba->pci_bar2_map, bar2map_len);
8246 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8247 dev_printk(KERN_ERR, &pdev->dev,
8248 "ioremap failed for SLI4 HBA doorbell registers.\n");
8249 goto out_iounmap_ctrl;
8251 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
8252 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8254 goto out_iounmap_all;
8260 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8262 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8264 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8270 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8271 * @phba: pointer to lpfc hba data structure.
8273 * This routine is invoked to unset the PCI device memory space for device
8274 * with SLI-4 interface spec.
8277 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8280 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8283 case LPFC_SLI_INTF_IF_TYPE_0:
8284 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8285 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8286 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8288 case LPFC_SLI_INTF_IF_TYPE_2:
8289 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8291 case LPFC_SLI_INTF_IF_TYPE_1:
8293 dev_printk(KERN_ERR, &phba->pcidev->dev,
8294 "FATAL - unsupported SLI4 interface type - %d\n",
8301 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8302 * @phba: pointer to lpfc hba data structure.
8304 * This routine is invoked to enable the MSI-X interrupt vectors to device
8305 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8306 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8307 * once invoked, enables either all or nothing, depending on the current
8308 * availability of PCI vector resources. The device driver is responsible
8309 * for calling the individual request_irq() to register each MSI-X vector
8310 * with a interrupt handler, which is done in this function. Note that
8311 * later when device is unloading, the driver should always call free_irq()
8312 * on all MSI-X vectors it has done request_irq() on before calling
8313 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8314 * will be left with MSI-X enabled and leaks its vectors.
8318 * other values - error
8321 lpfc_sli_enable_msix(struct lpfc_hba *phba)
8326 /* Set up MSI-X multi-message vectors */
8327 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8328 phba->msix_entries[i].entry = i;
8330 /* Configure MSI-X capability structure */
8331 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8334 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8335 "0420 PCI enable MSI-X failed (%d)\n", rc);
8338 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8339 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8340 "0477 MSI-X entry[%d]: vector=x%x "
8342 phba->msix_entries[i].vector,
8343 phba->msix_entries[i].entry);
8345 * Assign MSI-X vectors to interrupt handlers
8348 /* vector-0 is associated to slow-path handler */
8349 rc = request_irq(phba->msix_entries[0].vector,
8350 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
8351 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8353 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8354 "0421 MSI-X slow-path request_irq failed "
8359 /* vector-1 is associated to fast-path handler */
8360 rc = request_irq(phba->msix_entries[1].vector,
8361 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
8362 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8365 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8366 "0429 MSI-X fast-path request_irq failed "
8372 * Configure HBA MSI-X attention conditions to messages
8374 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8379 "0474 Unable to allocate memory for issuing "
8380 "MBOX_CONFIG_MSI command\n");
8383 rc = lpfc_config_msi(phba, pmb);
8386 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8387 if (rc != MBX_SUCCESS) {
8388 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8389 "0351 Config MSI mailbox command failed, "
8390 "mbxCmd x%x, mbxStatus x%x\n",
8391 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8395 /* Free memory allocated for mailbox command */
8396 mempool_free(pmb, phba->mbox_mem_pool);
8400 /* Free memory allocated for mailbox command */
8401 mempool_free(pmb, phba->mbox_mem_pool);
8404 /* free the irq already requested */
8405 free_irq(phba->msix_entries[1].vector, phba);
8408 /* free the irq already requested */
8409 free_irq(phba->msix_entries[0].vector, phba);
8412 /* Unconfigure MSI-X capability structure */
8413 pci_disable_msix(phba->pcidev);
8420 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8421 * @phba: pointer to lpfc hba data structure.
8423 * This routine is invoked to release the MSI-X vectors and then disable the
8424 * MSI-X interrupt mode to device with SLI-3 interface spec.
8427 lpfc_sli_disable_msix(struct lpfc_hba *phba)
8431 /* Free up MSI-X multi-message vectors */
8432 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8433 free_irq(phba->msix_entries[i].vector, phba);
8435 pci_disable_msix(phba->pcidev);
8441 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8442 * @phba: pointer to lpfc hba data structure.
8444 * This routine is invoked to enable the MSI interrupt mode to device with
8445 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8446 * enable the MSI vector. The device driver is responsible for calling the
8447 * request_irq() to register MSI vector with a interrupt the handler, which
8448 * is done in this function.
8452 * other values - error
8455 lpfc_sli_enable_msi(struct lpfc_hba *phba)
8459 rc = pci_enable_msi(phba->pcidev);
8461 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8462 "0462 PCI enable MSI mode success.\n");
8464 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8465 "0471 PCI enable MSI mode failed (%d)\n", rc);
8469 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8470 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8472 pci_disable_msi(phba->pcidev);
8473 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8474 "0478 MSI request_irq failed (%d)\n", rc);
8480 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8481 * @phba: pointer to lpfc hba data structure.
8483 * This routine is invoked to disable the MSI interrupt mode to device with
8484 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8485 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8486 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8490 lpfc_sli_disable_msi(struct lpfc_hba *phba)
8492 free_irq(phba->pcidev->irq, phba);
8493 pci_disable_msi(phba->pcidev);
8498 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8499 * @phba: pointer to lpfc hba data structure.
8501 * This routine is invoked to enable device interrupt and associate driver's
8502 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8503 * spec. Depends on the interrupt mode configured to the driver, the driver
8504 * will try to fallback from the configured interrupt mode to an interrupt
8505 * mode which is supported by the platform, kernel, and device in the order
8507 * MSI-X -> MSI -> IRQ.
8511 * other values - error
8514 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8516 uint32_t intr_mode = LPFC_INTR_ERROR;
8519 if (cfg_mode == 2) {
8520 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8521 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8523 /* Now, try to enable MSI-X interrupt mode */
8524 retval = lpfc_sli_enable_msix(phba);
8526 /* Indicate initialization to MSI-X mode */
8527 phba->intr_type = MSIX;
8533 /* Fallback to MSI if MSI-X initialization failed */
8534 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8535 retval = lpfc_sli_enable_msi(phba);
8537 /* Indicate initialization to MSI mode */
8538 phba->intr_type = MSI;
8543 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8544 if (phba->intr_type == NONE) {
8545 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8546 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8548 /* Indicate initialization to INTx mode */
8549 phba->intr_type = INTx;
8557 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8558 * @phba: pointer to lpfc hba data structure.
8560 * This routine is invoked to disable device interrupt and disassociate the
8561 * driver's interrupt handler(s) from interrupt vector(s) to device with
8562 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8563 * release the interrupt vector(s) for the message signaled interrupt.
8566 lpfc_sli_disable_intr(struct lpfc_hba *phba)
8568 /* Disable the currently initialized interrupt mode */
8569 if (phba->intr_type == MSIX)
8570 lpfc_sli_disable_msix(phba);
8571 else if (phba->intr_type == MSI)
8572 lpfc_sli_disable_msi(phba);
8573 else if (phba->intr_type == INTx)
8574 free_irq(phba->pcidev->irq, phba);
8576 /* Reset interrupt management states */
8577 phba->intr_type = NONE;
8578 phba->sli.slistat.sli_intr = 0;
8584 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8585 * @phba: pointer to lpfc hba data structure.
8587 * Find next available CPU to use for IRQ to CPU affinity.
8590 lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8592 struct lpfc_vector_map_info *cpup;
8595 cpup = phba->sli4_hba.cpu_map;
8596 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8597 /* CPU must be online */
8598 if (cpu_online(cpu)) {
8599 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8600 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8601 (cpup->phys_id == phys_id)) {
8609 * If we get here, we have used ALL CPUs for the specific
8610 * phys_id. Now we need to clear out lpfc_used_cpu and start
8614 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8615 if (lpfc_used_cpu[cpu] == phys_id)
8616 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8619 cpup = phba->sli4_hba.cpu_map;
8620 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8621 /* CPU must be online */
8622 if (cpu_online(cpu)) {
8623 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8624 (cpup->phys_id == phys_id)) {
8630 return LPFC_VECTOR_MAP_EMPTY;
8634 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8635 * @phba: pointer to lpfc hba data structure.
8636 * @vectors: number of HBA vectors
8638 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8639 * affinization across multple physical CPUs (numa nodes).
8640 * In addition, this routine will assign an IO channel for each CPU
8641 * to use when issuing I/Os.
8644 lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8646 int i, idx, saved_chann, used_chann, cpu, phys_id;
8647 int max_phys_id, min_phys_id;
8648 int num_io_channel, first_cpu, chan;
8649 struct lpfc_vector_map_info *cpup;
8651 struct cpuinfo_x86 *cpuinfo;
8653 struct cpumask *mask;
8654 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8656 /* If there is no mapping, just return */
8657 if (!phba->cfg_fcp_cpu_map)
8660 /* Init cpu_map array */
8661 memset(phba->sli4_hba.cpu_map, 0xff,
8662 (sizeof(struct lpfc_vector_map_info) *
8663 phba->sli4_hba.num_present_cpu));
8669 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8671 /* Update CPU map with physical id and core id of each CPU */
8672 cpup = phba->sli4_hba.cpu_map;
8673 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8675 cpuinfo = &cpu_data(cpu);
8676 cpup->phys_id = cpuinfo->phys_proc_id;
8677 cpup->core_id = cpuinfo->cpu_core_id;
8679 /* No distinction between CPUs for other platforms */
8684 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8685 "3328 CPU physid %d coreid %d\n",
8686 cpup->phys_id, cpup->core_id);
8688 if (cpup->phys_id > max_phys_id)
8689 max_phys_id = cpup->phys_id;
8690 if (cpup->phys_id < min_phys_id)
8691 min_phys_id = cpup->phys_id;
8695 phys_id = min_phys_id;
8696 /* Now associate the HBA vectors with specific CPUs */
8697 for (idx = 0; idx < vectors; idx++) {
8698 cpup = phba->sli4_hba.cpu_map;
8699 cpu = lpfc_find_next_cpu(phba, phys_id);
8700 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8702 /* Try for all phys_id's */
8703 for (i = 1; i < max_phys_id; i++) {
8705 if (phys_id > max_phys_id)
8706 phys_id = min_phys_id;
8707 cpu = lpfc_find_next_cpu(phba, phys_id);
8708 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8713 /* Use round robin for scheduling */
8714 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8716 cpup = phba->sli4_hba.cpu_map;
8717 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8718 cpup->channel_id = chan;
8721 if (chan >= phba->cfg_fcp_io_channel)
8725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8726 "3329 Cannot set affinity:"
8727 "Error mapping vector %d (%d)\n",
8733 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8734 lpfc_used_cpu[cpu] = phys_id;
8736 /* Associate vector with selected CPU */
8737 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8739 /* Associate IO channel with selected CPU */
8740 cpup->channel_id = idx;
8743 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8746 /* Now affinitize to the selected CPU */
8747 mask = &cpup->maskbits;
8748 cpumask_clear(mask);
8749 cpumask_set_cpu(cpu, mask);
8750 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
8753 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8754 "3330 Set Affinity: CPU %d channel %d "
8756 cpu, cpup->channel_id,
8757 phba->sli4_hba.msix_entries[idx].vector, i);
8759 /* Spread vector mapping across multple physical CPU nodes */
8761 if (phys_id > max_phys_id)
8762 phys_id = min_phys_id;
8766 * Finally fill in the IO channel for any remaining CPUs.
8767 * At this point, all IO channels have been assigned to a specific
8768 * MSIx vector, mapped to a specific CPU.
8769 * Base the remaining IO channel assigned, to IO channels already
8770 * assigned to other CPUs on the same phys_id.
8772 for (i = min_phys_id; i <= max_phys_id; i++) {
8774 * If there are no io channels already mapped to
8775 * this phys_id, just round robin thru the io_channels.
8776 * Setup chann[] for round robin.
8778 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8785 * First build a list of IO channels already assigned
8786 * to this phys_id before reassigning the same IO
8787 * channels to the remaining CPUs.
8789 cpup = phba->sli4_hba.cpu_map;
8792 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8794 if (cpup->phys_id == i) {
8796 * Save any IO channels that are
8797 * already mapped to this phys_id.
8799 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
8800 chann[saved_chann] =
8806 /* See if we are using round-robin */
8807 if (saved_chann == 0)
8809 phba->cfg_fcp_io_channel;
8811 /* Associate next IO channel with CPU */
8812 cpup->channel_id = chann[used_chann];
8815 if (used_chann == saved_chann)
8818 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8819 "3331 Set IO_CHANN "
8820 "CPU %d channel %d\n",
8821 idx, cpup->channel_id);
8825 if (cpu >= phba->sli4_hba.num_present_cpu) {
8826 cpup = phba->sli4_hba.cpu_map;
8834 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8835 cpup = phba->sli4_hba.cpu_map;
8836 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8837 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8838 cpup->channel_id = 0;
8841 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8842 "3332 Assign IO_CHANN "
8843 "CPU %d channel %d\n",
8844 idx, cpup->channel_id);
8851 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8853 "3333 Set affinity mismatch:"
8854 "%d chann != %d cpus: %d vectors\n",
8855 num_io_channel, phba->sli4_hba.num_present_cpu,
8858 /* Enable using cpu affinity for scheduling */
8859 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8865 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8866 * @phba: pointer to lpfc hba data structure.
8868 * This routine is invoked to enable the MSI-X interrupt vectors to device
8869 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
8870 * is called to enable the MSI-X vectors. The device driver is responsible
8871 * for calling the individual request_irq() to register each MSI-X vector
8872 * with a interrupt handler, which is done in this function. Note that
8873 * later when device is unloading, the driver should always call free_irq()
8874 * on all MSI-X vectors it has done request_irq() on before calling
8875 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8876 * will be left with MSI-X enabled and leaks its vectors.
8880 * other values - error
8883 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8885 int vectors, rc, index;
8887 /* Set up MSI-X multi-message vectors */
8888 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
8889 phba->sli4_hba.msix_entries[index].entry = index;
8891 /* Configure MSI-X capability structure */
8892 vectors = phba->cfg_fcp_io_channel;
8893 if (phba->cfg_fof) {
8894 phba->sli4_hba.msix_entries[index].entry = index;
8897 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
8900 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8901 "0484 PCI enable MSI-X failed (%d)\n", rc);
8906 /* Log MSI-X vector assignment */
8907 for (index = 0; index < vectors; index++)
8908 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8909 "0489 MSI-X entry[%d]: vector=x%x "
8910 "message=%d\n", index,
8911 phba->sli4_hba.msix_entries[index].vector,
8912 phba->sli4_hba.msix_entries[index].entry);
8914 /* Assign MSI-X vectors to interrupt handlers */
8915 for (index = 0; index < vectors; index++) {
8916 memset(&phba->sli4_hba.handler_name[index], 0, 16);
8917 snprintf((char *)&phba->sli4_hba.handler_name[index],
8918 LPFC_SLI4_HANDLER_NAME_SZ,
8919 LPFC_DRIVER_HANDLER_NAME"%d", index);
8921 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8922 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8923 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
8924 if (phba->cfg_fof && (index == (vectors - 1)))
8926 phba->sli4_hba.msix_entries[index].vector,
8927 &lpfc_sli4_fof_intr_handler, IRQF_SHARED,
8928 (char *)&phba->sli4_hba.handler_name[index],
8929 &phba->sli4_hba.fcp_eq_hdl[index]);
8932 phba->sli4_hba.msix_entries[index].vector,
8933 &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
8934 (char *)&phba->sli4_hba.handler_name[index],
8935 &phba->sli4_hba.fcp_eq_hdl[index]);
8937 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8938 "0486 MSI-X fast-path (%d) "
8939 "request_irq failed (%d)\n", index, rc);
8947 if (vectors != phba->cfg_fcp_io_channel) {
8948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8949 "3238 Reducing IO channels to match number of "
8950 "MSI-X vectors, requested %d got %d\n",
8951 phba->cfg_fcp_io_channel, vectors);
8952 phba->cfg_fcp_io_channel = vectors;
8955 lpfc_sli4_set_affinity(phba, vectors);
8959 /* free the irq already requested */
8960 for (--index; index >= 0; index--) {
8961 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8963 free_irq(phba->sli4_hba.msix_entries[index].vector,
8964 &phba->sli4_hba.fcp_eq_hdl[index]);
8967 /* Unconfigure MSI-X capability structure */
8968 pci_disable_msix(phba->pcidev);
8975 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8976 * @phba: pointer to lpfc hba data structure.
8978 * This routine is invoked to release the MSI-X vectors and then disable the
8979 * MSI-X interrupt mode to device with SLI-4 interface spec.
8982 lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8986 /* Free up MSI-X multi-message vectors */
8987 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
8988 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8990 free_irq(phba->sli4_hba.msix_entries[index].vector,
8991 &phba->sli4_hba.fcp_eq_hdl[index]);
8993 if (phba->cfg_fof) {
8994 free_irq(phba->sli4_hba.msix_entries[index].vector,
8995 &phba->sli4_hba.fcp_eq_hdl[index]);
8998 pci_disable_msix(phba->pcidev);
9004 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9005 * @phba: pointer to lpfc hba data structure.
9007 * This routine is invoked to enable the MSI interrupt mode to device with
9008 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9009 * to enable the MSI vector. The device driver is responsible for calling
9010 * the request_irq() to register MSI vector with a interrupt the handler,
9011 * which is done in this function.
9015 * other values - error
9018 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9022 rc = pci_enable_msi(phba->pcidev);
9024 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9025 "0487 PCI enable MSI mode success.\n");
9027 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9028 "0488 PCI enable MSI mode failed (%d)\n", rc);
9032 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9033 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9035 pci_disable_msi(phba->pcidev);
9036 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9037 "0490 MSI request_irq failed (%d)\n", rc);
9041 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9042 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9043 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9046 if (phba->cfg_fof) {
9047 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9048 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9054 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9055 * @phba: pointer to lpfc hba data structure.
9057 * This routine is invoked to disable the MSI interrupt mode to device with
9058 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9059 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9060 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9064 lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9066 free_irq(phba->pcidev->irq, phba);
9067 pci_disable_msi(phba->pcidev);
9072 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9073 * @phba: pointer to lpfc hba data structure.
9075 * This routine is invoked to enable device interrupt and associate driver's
9076 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9077 * interface spec. Depends on the interrupt mode configured to the driver,
9078 * the driver will try to fallback from the configured interrupt mode to an
9079 * interrupt mode which is supported by the platform, kernel, and device in
9081 * MSI-X -> MSI -> IRQ.
9085 * other values - error
9088 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9090 uint32_t intr_mode = LPFC_INTR_ERROR;
9093 if (cfg_mode == 2) {
9094 /* Preparation before conf_msi mbox cmd */
9097 /* Now, try to enable MSI-X interrupt mode */
9098 retval = lpfc_sli4_enable_msix(phba);
9100 /* Indicate initialization to MSI-X mode */
9101 phba->intr_type = MSIX;
9107 /* Fallback to MSI if MSI-X initialization failed */
9108 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9109 retval = lpfc_sli4_enable_msi(phba);
9111 /* Indicate initialization to MSI mode */
9112 phba->intr_type = MSI;
9117 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9118 if (phba->intr_type == NONE) {
9119 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9120 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9122 /* Indicate initialization to INTx mode */
9123 phba->intr_type = INTx;
9125 for (index = 0; index < phba->cfg_fcp_io_channel;
9127 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9128 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9129 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9132 if (phba->cfg_fof) {
9133 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9134 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9135 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9144 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9145 * @phba: pointer to lpfc hba data structure.
9147 * This routine is invoked to disable device interrupt and disassociate
9148 * the driver's interrupt handler(s) from interrupt vector(s) to device
9149 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9150 * will release the interrupt vector(s) for the message signaled interrupt.
9153 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9155 /* Disable the currently initialized interrupt mode */
9156 if (phba->intr_type == MSIX)
9157 lpfc_sli4_disable_msix(phba);
9158 else if (phba->intr_type == MSI)
9159 lpfc_sli4_disable_msi(phba);
9160 else if (phba->intr_type == INTx)
9161 free_irq(phba->pcidev->irq, phba);
9163 /* Reset interrupt management states */
9164 phba->intr_type = NONE;
9165 phba->sli.slistat.sli_intr = 0;
9171 * lpfc_unset_hba - Unset SLI3 hba device initialization
9172 * @phba: pointer to lpfc hba data structure.
9174 * This routine is invoked to unset the HBA device initialization steps to
9175 * a device with SLI-3 interface spec.
9178 lpfc_unset_hba(struct lpfc_hba *phba)
9180 struct lpfc_vport *vport = phba->pport;
9181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9183 spin_lock_irq(shost->host_lock);
9184 vport->load_flag |= FC_UNLOADING;
9185 spin_unlock_irq(shost->host_lock);
9187 kfree(phba->vpi_bmask);
9188 kfree(phba->vpi_ids);
9190 lpfc_stop_hba_timers(phba);
9192 phba->pport->work_port_events = 0;
9194 lpfc_sli_hba_down(phba);
9196 lpfc_sli_brdrestart(phba);
9198 lpfc_sli_disable_intr(phba);
9204 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9205 * @phba: Pointer to HBA context object.
9207 * This function is called in the SLI4 code path to wait for completion
9208 * of device's XRIs exchange busy. It will check the XRI exchange busy
9209 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9210 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9211 * I/Os every 30 seconds, log error message, and wait forever. Only when
9212 * all XRI exchange busy complete, the driver unload shall proceed with
9213 * invoking the function reset ioctl mailbox command to the CNA and the
9214 * the rest of the driver unload resource release.
9217 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9220 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9221 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9223 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9224 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9227 "2877 FCP XRI exchange busy "
9228 "wait time: %d seconds.\n",
9231 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9232 "2878 ELS XRI exchange busy "
9233 "wait time: %d seconds.\n",
9235 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9236 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9238 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9239 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9242 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9244 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9249 * lpfc_sli4_hba_unset - Unset the fcoe hba
9250 * @phba: Pointer to HBA context object.
9252 * This function is called in the SLI4 code path to reset the HBA's FCoE
9253 * function. The caller is not required to hold any lock. This routine
9254 * issues PCI function reset mailbox command to reset the FCoE function.
9255 * At the end of the function, it calls lpfc_hba_down_post function to
9256 * free any pending commands.
9259 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9262 LPFC_MBOXQ_t *mboxq;
9263 struct pci_dev *pdev = phba->pcidev;
9265 lpfc_stop_hba_timers(phba);
9266 phba->sli4_hba.intr_enable = 0;
9269 * Gracefully wait out the potential current outstanding asynchronous
9273 /* First, block any pending async mailbox command from posted */
9274 spin_lock_irq(&phba->hbalock);
9275 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9276 spin_unlock_irq(&phba->hbalock);
9277 /* Now, trying to wait it out if we can */
9278 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9280 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9283 /* Forcefully release the outstanding mailbox command if timed out */
9284 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9285 spin_lock_irq(&phba->hbalock);
9286 mboxq = phba->sli.mbox_active;
9287 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9288 __lpfc_mbox_cmpl_put(phba, mboxq);
9289 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9290 phba->sli.mbox_active = NULL;
9291 spin_unlock_irq(&phba->hbalock);
9294 /* Abort all iocbs associated with the hba */
9295 lpfc_sli_hba_iocb_abort(phba);
9297 /* Wait for completion of device XRI exchange busy */
9298 lpfc_sli4_xri_exchange_busy_wait(phba);
9300 /* Disable PCI subsystem interrupt */
9301 lpfc_sli4_disable_intr(phba);
9303 /* Disable SR-IOV if enabled */
9304 if (phba->cfg_sriov_nr_virtfn)
9305 pci_disable_sriov(pdev);
9307 /* Stop kthread signal shall trigger work_done one more time */
9308 kthread_stop(phba->worker_thread);
9310 /* Reset SLI4 HBA FCoE function */
9311 lpfc_pci_function_reset(phba);
9312 lpfc_sli4_queue_destroy(phba);
9314 /* Stop the SLI4 device port */
9315 phba->pport->work_port_events = 0;
9319 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9320 * @phba: Pointer to HBA context object.
9321 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9323 * This function is called in the SLI4 code path to read the port's
9324 * sli4 capabilities.
9326 * This function may be be called from any context that can block-wait
9327 * for the completion. The expectation is that this routine is called
9328 * typically from probe_one or from the online routine.
9331 lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9334 struct lpfc_mqe *mqe;
9335 struct lpfc_pc_sli4_params *sli4_params;
9339 mqe = &mboxq->u.mqe;
9341 /* Read the port's SLI4 Parameters port capabilities */
9342 lpfc_pc_sli4_params(mboxq);
9343 if (!phba->sli4_hba.intr_enable)
9344 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9346 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9347 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9353 sli4_params = &phba->sli4_hba.pc_sli4_params;
9354 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9355 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9356 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9357 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9358 &mqe->un.sli4_params);
9359 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9360 &mqe->un.sli4_params);
9361 sli4_params->proto_types = mqe->un.sli4_params.word3;
9362 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9363 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9364 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9365 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9366 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9367 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9368 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9369 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9370 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9371 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9372 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9373 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9374 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9375 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9376 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9377 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9378 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9379 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9380 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9381 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
9383 /* Make sure that sge_supp_len can be handled by the driver */
9384 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9385 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9391 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9392 * @phba: Pointer to HBA context object.
9393 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9395 * This function is called in the SLI4 code path to read the port's
9396 * sli4 capabilities.
9398 * This function may be be called from any context that can block-wait
9399 * for the completion. The expectation is that this routine is called
9400 * typically from probe_one or from the online routine.
9403 lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9406 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9407 struct lpfc_pc_sli4_params *sli4_params;
9410 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9413 * By default, the driver assumes the SLI4 port requires RPI
9414 * header postings. The SLI4_PARAM response will correct this
9417 phba->sli4_hba.rpi_hdrs_in_use = 1;
9419 /* Read the port's SLI4 Config Parameters */
9420 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9421 sizeof(struct lpfc_sli4_cfg_mhdr));
9422 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9423 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9424 length, LPFC_SLI4_MBX_EMBED);
9425 if (!phba->sli4_hba.intr_enable)
9426 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9428 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9429 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9433 sli4_params = &phba->sli4_hba.pc_sli4_params;
9434 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9435 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9436 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9437 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9438 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9439 mbx_sli4_parameters);
9440 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9441 mbx_sli4_parameters);
9442 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9443 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9445 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9446 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9447 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
9448 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
9449 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9450 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9451 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9452 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
9453 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
9454 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9455 mbx_sli4_parameters);
9456 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9457 mbx_sli4_parameters);
9458 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9459 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
9461 /* Make sure that sge_supp_len can be handled by the driver */
9462 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9463 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9469 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9470 * @pdev: pointer to PCI device
9471 * @pid: pointer to PCI device identifier
9473 * This routine is to be called to attach a device with SLI-3 interface spec
9474 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9475 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9476 * information of the device and driver to see if the driver state that it can
9477 * support this kind of device. If the match is successful, the driver core
9478 * invokes this routine. If this routine determines it can claim the HBA, it
9479 * does all the initialization that it needs to do to handle the HBA properly.
9482 * 0 - driver can claim the device
9483 * negative value - driver can not claim the device
9486 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9488 struct lpfc_hba *phba;
9489 struct lpfc_vport *vport = NULL;
9490 struct Scsi_Host *shost = NULL;
9492 uint32_t cfg_mode, intr_mode;
9494 /* Allocate memory for HBA structure */
9495 phba = lpfc_hba_alloc(pdev);
9499 /* Perform generic PCI device enabling operation */
9500 error = lpfc_enable_pci_dev(phba);
9504 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9505 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9507 goto out_disable_pci_dev;
9509 /* Set up SLI-3 specific device PCI memory space */
9510 error = lpfc_sli_pci_mem_setup(phba);
9512 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9513 "1402 Failed to set up pci memory space.\n");
9514 goto out_disable_pci_dev;
9517 /* Set up phase-1 common device driver resources */
9518 error = lpfc_setup_driver_resource_phase1(phba);
9520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9521 "1403 Failed to set up driver resource.\n");
9522 goto out_unset_pci_mem_s3;
9525 /* Set up SLI-3 specific device driver resources */
9526 error = lpfc_sli_driver_resource_setup(phba);
9528 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9529 "1404 Failed to set up driver resource.\n");
9530 goto out_unset_pci_mem_s3;
9533 /* Initialize and populate the iocb list per host */
9534 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9536 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9537 "1405 Failed to initialize iocb list.\n");
9538 goto out_unset_driver_resource_s3;
9541 /* Set up common device driver resources */
9542 error = lpfc_setup_driver_resource_phase2(phba);
9544 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9545 "1406 Failed to set up driver resource.\n");
9546 goto out_free_iocb_list;
9549 /* Get the default values for Model Name and Description */
9550 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9552 /* Create SCSI host to the physical port */
9553 error = lpfc_create_shost(phba);
9555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9556 "1407 Failed to create scsi host.\n");
9557 goto out_unset_driver_resource;
9560 /* Configure sysfs attributes */
9561 vport = phba->pport;
9562 error = lpfc_alloc_sysfs_attr(vport);
9564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9565 "1476 Failed to allocate sysfs attr\n");
9566 goto out_destroy_shost;
9569 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
9570 /* Now, trying to enable interrupt and bring up the device */
9571 cfg_mode = phba->cfg_use_msi;
9573 /* Put device to a known state before enabling interrupt */
9574 lpfc_stop_port(phba);
9575 /* Configure and enable interrupt */
9576 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9577 if (intr_mode == LPFC_INTR_ERROR) {
9578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9579 "0431 Failed to enable interrupt.\n");
9581 goto out_free_sysfs_attr;
9583 /* SLI-3 HBA setup */
9584 if (lpfc_sli_hba_setup(phba)) {
9585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9586 "1477 Failed to set up hba\n");
9588 goto out_remove_device;
9591 /* Wait 50ms for the interrupts of previous mailbox commands */
9593 /* Check active interrupts on message signaled interrupts */
9594 if (intr_mode == 0 ||
9595 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9596 /* Log the current active interrupt mode */
9597 phba->intr_mode = intr_mode;
9598 lpfc_log_intr_mode(phba, intr_mode);
9601 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9602 "0447 Configure interrupt mode (%d) "
9603 "failed active interrupt test.\n",
9605 /* Disable the current interrupt mode */
9606 lpfc_sli_disable_intr(phba);
9607 /* Try next level of interrupt mode */
9608 cfg_mode = --intr_mode;
9612 /* Perform post initialization setup */
9613 lpfc_post_init_setup(phba);
9615 /* Check if there are static vports to be created. */
9616 lpfc_create_static_vport(phba);
9621 lpfc_unset_hba(phba);
9622 out_free_sysfs_attr:
9623 lpfc_free_sysfs_attr(vport);
9625 lpfc_destroy_shost(phba);
9626 out_unset_driver_resource:
9627 lpfc_unset_driver_resource_phase2(phba);
9629 lpfc_free_iocb_list(phba);
9630 out_unset_driver_resource_s3:
9631 lpfc_sli_driver_resource_unset(phba);
9632 out_unset_pci_mem_s3:
9633 lpfc_sli_pci_mem_unset(phba);
9634 out_disable_pci_dev:
9635 lpfc_disable_pci_dev(phba);
9637 scsi_host_put(shost);
9639 lpfc_hba_free(phba);
9644 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
9645 * @pdev: pointer to PCI device
9647 * This routine is to be called to disattach a device with SLI-3 interface
9648 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9649 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9650 * device to be removed from the PCI subsystem properly.
9653 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
9655 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9657 struct lpfc_vport **vports;
9658 struct lpfc_hba *phba = vport->phba;
9660 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9662 spin_lock_irq(&phba->hbalock);
9663 vport->load_flag |= FC_UNLOADING;
9664 spin_unlock_irq(&phba->hbalock);
9666 lpfc_free_sysfs_attr(vport);
9668 /* Release all the vports against this physical port */
9669 vports = lpfc_create_vport_work_array(phba);
9671 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9672 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9674 fc_vport_terminate(vports[i]->fc_vport);
9676 lpfc_destroy_vport_work_array(phba, vports);
9678 /* Remove FC host and then SCSI host with the physical port */
9679 fc_remove_host(shost);
9680 scsi_remove_host(shost);
9681 lpfc_cleanup(vport);
9684 * Bring down the SLI Layer. This step disable all interrupts,
9685 * clears the rings, discards all mailbox commands, and resets
9689 /* HBA interrupt will be disabled after this call */
9690 lpfc_sli_hba_down(phba);
9691 /* Stop kthread signal shall trigger work_done one more time */
9692 kthread_stop(phba->worker_thread);
9693 /* Final cleanup of txcmplq and reset the HBA */
9694 lpfc_sli_brdrestart(phba);
9696 kfree(phba->vpi_bmask);
9697 kfree(phba->vpi_ids);
9699 lpfc_stop_hba_timers(phba);
9700 spin_lock_irq(&phba->hbalock);
9701 list_del_init(&vport->listentry);
9702 spin_unlock_irq(&phba->hbalock);
9704 lpfc_debugfs_terminate(vport);
9706 /* Disable SR-IOV if enabled */
9707 if (phba->cfg_sriov_nr_virtfn)
9708 pci_disable_sriov(pdev);
9710 /* Disable interrupt */
9711 lpfc_sli_disable_intr(phba);
9713 scsi_host_put(shost);
9716 * Call scsi_free before mem_free since scsi bufs are released to their
9717 * corresponding pools here.
9719 lpfc_scsi_free(phba);
9720 lpfc_mem_free_all(phba);
9722 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9723 phba->hbqslimp.virt, phba->hbqslimp.phys);
9725 /* Free resources associated with SLI2 interface */
9726 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9727 phba->slim2p.virt, phba->slim2p.phys);
9729 /* unmap adapter SLIM and Control Registers */
9730 iounmap(phba->ctrl_regs_memmap_p);
9731 iounmap(phba->slim_memmap_p);
9733 lpfc_hba_free(phba);
9735 pci_release_selected_regions(pdev, bars);
9736 pci_disable_device(pdev);
9740 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
9741 * @pdev: pointer to PCI device
9742 * @msg: power management message
9744 * This routine is to be called from the kernel's PCI subsystem to support
9745 * system Power Management (PM) to device with SLI-3 interface spec. When
9746 * PM invokes this method, it quiesces the device by stopping the driver's
9747 * worker thread for the device, turning off device's interrupt and DMA,
9748 * and bring the device offline. Note that as the driver implements the
9749 * minimum PM requirements to a power-aware driver's PM support for the
9750 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9751 * to the suspend() method call will be treated as SUSPEND and the driver will
9752 * fully reinitialize its device during resume() method call, the driver will
9753 * set device to PCI_D3hot state in PCI config space instead of setting it
9754 * according to the @msg provided by the PM.
9757 * 0 - driver suspended the device
9761 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
9763 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9764 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9766 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9767 "0473 PCI device Power Management suspend.\n");
9769 /* Bring down the device */
9770 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
9772 kthread_stop(phba->worker_thread);
9774 /* Disable interrupt from device */
9775 lpfc_sli_disable_intr(phba);
9777 /* Save device state to PCI config space */
9778 pci_save_state(pdev);
9779 pci_set_power_state(pdev, PCI_D3hot);
9785 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
9786 * @pdev: pointer to PCI device
9788 * This routine is to be called from the kernel's PCI subsystem to support
9789 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9790 * invokes this method, it restores the device's PCI config space state and
9791 * fully reinitializes the device and brings it online. Note that as the
9792 * driver implements the minimum PM requirements to a power-aware driver's
9793 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9794 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9795 * driver will fully reinitialize its device during resume() method call,
9796 * the device will be set to PCI_D0 directly in PCI config space before
9797 * restoring the state.
9800 * 0 - driver suspended the device
9804 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
9806 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9807 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9811 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9812 "0452 PCI device Power Management resume.\n");
9814 /* Restore device state from PCI config space */
9815 pci_set_power_state(pdev, PCI_D0);
9816 pci_restore_state(pdev);
9819 * As the new kernel behavior of pci_restore_state() API call clears
9820 * device saved_state flag, need to save the restored state again.
9822 pci_save_state(pdev);
9824 if (pdev->is_busmaster)
9825 pci_set_master(pdev);
9827 /* Startup the kernel thread for this host adapter. */
9828 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9829 "lpfc_worker_%d", phba->brd_no);
9830 if (IS_ERR(phba->worker_thread)) {
9831 error = PTR_ERR(phba->worker_thread);
9832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9833 "0434 PM resume failed to start worker "
9834 "thread: error=x%x.\n", error);
9838 /* Configure and enable interrupt */
9839 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
9840 if (intr_mode == LPFC_INTR_ERROR) {
9841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9842 "0430 PM resume Failed to enable interrupt\n");
9845 phba->intr_mode = intr_mode;
9847 /* Restart HBA and bring it online */
9848 lpfc_sli_brdrestart(phba);
9851 /* Log the current active interrupt mode */
9852 lpfc_log_intr_mode(phba, phba->intr_mode);
9858 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9859 * @phba: pointer to lpfc hba data structure.
9861 * This routine is called to prepare the SLI3 device for PCI slot recover. It
9862 * aborts all the outstanding SCSI I/Os to the pci device.
9865 lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9868 "2723 PCI channel I/O abort preparing for recovery\n");
9871 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9872 * and let the SCSI mid-layer to retry them to recover.
9874 lpfc_sli_abort_fcp_rings(phba);
9878 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9879 * @phba: pointer to lpfc hba data structure.
9881 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9882 * disables the device interrupt and pci device, and aborts the internal FCP
9886 lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9889 "2710 PCI channel disable preparing for reset\n");
9891 /* Block any management I/Os to the device */
9892 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
9894 /* Block all SCSI devices' I/Os on the host */
9895 lpfc_scsi_dev_block(phba);
9897 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9898 lpfc_sli_flush_fcp_rings(phba);
9900 /* stop all timers */
9901 lpfc_stop_hba_timers(phba);
9903 /* Disable interrupt and pci device */
9904 lpfc_sli_disable_intr(phba);
9905 pci_disable_device(phba->pcidev);
9909 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9910 * @phba: pointer to lpfc hba data structure.
9912 * This routine is called to prepare the SLI3 device for PCI slot permanently
9913 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9917 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
9919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9920 "2711 PCI channel permanent disable for failure\n");
9921 /* Block all SCSI devices' I/Os on the host */
9922 lpfc_scsi_dev_block(phba);
9924 /* stop all timers */
9925 lpfc_stop_hba_timers(phba);
9927 /* Clean up all driver's outstanding SCSI I/Os */
9928 lpfc_sli_flush_fcp_rings(phba);
9932 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
9933 * @pdev: pointer to PCI device.
9934 * @state: the current PCI connection state.
9936 * This routine is called from the PCI subsystem for I/O error handling to
9937 * device with SLI-3 interface spec. This function is called by the PCI
9938 * subsystem after a PCI bus error affecting this device has been detected.
9939 * When this function is invoked, it will need to stop all the I/Os and
9940 * interrupt(s) to the device. Once that is done, it will return
9941 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9945 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
9946 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9947 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9949 static pci_ers_result_t
9950 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
9952 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9953 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9956 case pci_channel_io_normal:
9957 /* Non-fatal error, prepare for recovery */
9958 lpfc_sli_prep_dev_for_recover(phba);
9959 return PCI_ERS_RESULT_CAN_RECOVER;
9960 case pci_channel_io_frozen:
9961 /* Fatal error, prepare for slot reset */
9962 lpfc_sli_prep_dev_for_reset(phba);
9963 return PCI_ERS_RESULT_NEED_RESET;
9964 case pci_channel_io_perm_failure:
9965 /* Permanent failure, prepare for device down */
9966 lpfc_sli_prep_dev_for_perm_failure(phba);
9967 return PCI_ERS_RESULT_DISCONNECT;
9969 /* Unknown state, prepare and request slot reset */
9970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9971 "0472 Unknown PCI error state: x%x\n", state);
9972 lpfc_sli_prep_dev_for_reset(phba);
9973 return PCI_ERS_RESULT_NEED_RESET;
9978 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
9979 * @pdev: pointer to PCI device.
9981 * This routine is called from the PCI subsystem for error handling to
9982 * device with SLI-3 interface spec. This is called after PCI bus has been
9983 * reset to restart the PCI card from scratch, as if from a cold-boot.
9984 * During the PCI subsystem error recovery, after driver returns
9985 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9986 * recovery and then call this routine before calling the .resume method
9987 * to recover the device. This function will initialize the HBA device,
9988 * enable the interrupt, but it will just put the HBA to offline state
9989 * without passing any I/O traffic.
9992 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9993 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9995 static pci_ers_result_t
9996 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
9998 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9999 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10000 struct lpfc_sli *psli = &phba->sli;
10001 uint32_t intr_mode;
10003 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10004 if (pci_enable_device_mem(pdev)) {
10005 printk(KERN_ERR "lpfc: Cannot re-enable "
10006 "PCI device after reset.\n");
10007 return PCI_ERS_RESULT_DISCONNECT;
10010 pci_restore_state(pdev);
10013 * As the new kernel behavior of pci_restore_state() API call clears
10014 * device saved_state flag, need to save the restored state again.
10016 pci_save_state(pdev);
10018 if (pdev->is_busmaster)
10019 pci_set_master(pdev);
10021 spin_lock_irq(&phba->hbalock);
10022 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10023 spin_unlock_irq(&phba->hbalock);
10025 /* Configure and enable interrupt */
10026 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
10027 if (intr_mode == LPFC_INTR_ERROR) {
10028 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10029 "0427 Cannot re-enable interrupt after "
10031 return PCI_ERS_RESULT_DISCONNECT;
10033 phba->intr_mode = intr_mode;
10035 /* Take device offline, it will perform cleanup */
10036 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10037 lpfc_offline(phba);
10038 lpfc_sli_brdrestart(phba);
10040 /* Log the current active interrupt mode */
10041 lpfc_log_intr_mode(phba, phba->intr_mode);
10043 return PCI_ERS_RESULT_RECOVERED;
10047 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
10048 * @pdev: pointer to PCI device
10050 * This routine is called from the PCI subsystem for error handling to device
10051 * with SLI-3 interface spec. It is called when kernel error recovery tells
10052 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10053 * error recovery. After this call, traffic can start to flow from this device
10057 lpfc_io_resume_s3(struct pci_dev *pdev)
10059 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10060 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10062 /* Bring device online, it will be no-op for non-fatal error resume */
10065 /* Clean up Advanced Error Reporting (AER) if needed */
10066 if (phba->hba_flag & HBA_AER_ENABLED)
10067 pci_cleanup_aer_uncorrect_error_status(pdev);
10071 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10072 * @phba: pointer to lpfc hba data structure.
10074 * returns the number of ELS/CT IOCBs to reserve
10077 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10079 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10081 if (phba->sli_rev == LPFC_SLI_REV4) {
10082 if (max_xri <= 100)
10084 else if (max_xri <= 256)
10086 else if (max_xri <= 512)
10088 else if (max_xri <= 1024)
10090 else if (max_xri <= 1536)
10092 else if (max_xri <= 2048)
10101 * lpfc_write_firmware - attempt to write a firmware image to the port
10102 * @fw: pointer to firmware image returned from request_firmware.
10103 * @phba: pointer to lpfc hba data structure.
10107 lpfc_write_firmware(const struct firmware *fw, void *context)
10109 struct lpfc_hba *phba = (struct lpfc_hba *)context;
10110 char fwrev[FW_REV_STR_SIZE];
10111 struct lpfc_grp_hdr *image;
10112 struct list_head dma_buffer_list;
10114 struct lpfc_dmabuf *dmabuf, *next;
10115 uint32_t offset = 0, temp_offset = 0;
10117 /* It can be null in no-wait mode, sanity check */
10122 image = (struct lpfc_grp_hdr *)fw->data;
10124 INIT_LIST_HEAD(&dma_buffer_list);
10125 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10126 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10127 LPFC_FILE_TYPE_GROUP) ||
10128 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10129 (be32_to_cpu(image->size) != fw->size)) {
10130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10131 "3022 Invalid FW image found. "
10132 "Magic:%x Type:%x ID:%x\n",
10133 be32_to_cpu(image->magic_number),
10134 bf_get_be32(lpfc_grp_hdr_file_type, image),
10135 bf_get_be32(lpfc_grp_hdr_id, image));
10139 lpfc_decode_firmware_rev(phba, fwrev, 1);
10140 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
10141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10142 "3023 Updating Firmware, Current Version:%s "
10143 "New Version:%s\n",
10144 fwrev, image->revision);
10145 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10146 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10152 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10156 if (!dmabuf->virt) {
10161 list_add_tail(&dmabuf->list, &dma_buffer_list);
10163 while (offset < fw->size) {
10164 temp_offset = offset;
10165 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
10166 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
10167 memcpy(dmabuf->virt,
10168 fw->data + temp_offset,
10169 fw->size - temp_offset);
10170 temp_offset = fw->size;
10173 memcpy(dmabuf->virt, fw->data + temp_offset,
10175 temp_offset += SLI4_PAGE_SIZE;
10177 rc = lpfc_wr_object(phba, &dma_buffer_list,
10178 (fw->size - offset), &offset);
10186 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10187 list_del(&dmabuf->list);
10188 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10189 dmabuf->virt, dmabuf->phys);
10192 release_firmware(fw);
10194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10195 "3024 Firmware update done: %d.\n", rc);
10200 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10201 * @phba: pointer to lpfc hba data structure.
10203 * This routine is called to perform Linux generic firmware upgrade on device
10204 * that supports such feature.
10207 lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10209 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10211 const struct firmware *fw;
10213 /* Only supported on SLI4 interface type 2 for now */
10214 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10215 LPFC_SLI_INTF_IF_TYPE_2)
10218 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10220 if (fw_upgrade == INT_FW_UPGRADE) {
10221 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10222 file_name, &phba->pcidev->dev,
10223 GFP_KERNEL, (void *)phba,
10224 lpfc_write_firmware);
10225 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10226 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10228 lpfc_write_firmware(fw, (void *)phba);
10237 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10238 * @pdev: pointer to PCI device
10239 * @pid: pointer to PCI device identifier
10241 * This routine is called from the kernel's PCI subsystem to device with
10242 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10243 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10244 * information of the device and driver to see if the driver state that it
10245 * can support this kind of device. If the match is successful, the driver
10246 * core invokes this routine. If this routine determines it can claim the HBA,
10247 * it does all the initialization that it needs to do to handle the HBA
10251 * 0 - driver can claim the device
10252 * negative value - driver can not claim the device
10255 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10257 struct lpfc_hba *phba;
10258 struct lpfc_vport *vport = NULL;
10259 struct Scsi_Host *shost = NULL;
10261 uint32_t cfg_mode, intr_mode;
10262 int adjusted_fcp_io_channel;
10264 /* Allocate memory for HBA structure */
10265 phba = lpfc_hba_alloc(pdev);
10269 /* Perform generic PCI device enabling operation */
10270 error = lpfc_enable_pci_dev(phba);
10272 goto out_free_phba;
10274 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10275 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10277 goto out_disable_pci_dev;
10279 /* Set up SLI-4 specific device PCI memory space */
10280 error = lpfc_sli4_pci_mem_setup(phba);
10282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10283 "1410 Failed to set up pci memory space.\n");
10284 goto out_disable_pci_dev;
10287 /* Set up phase-1 common device driver resources */
10288 error = lpfc_setup_driver_resource_phase1(phba);
10290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10291 "1411 Failed to set up driver resource.\n");
10292 goto out_unset_pci_mem_s4;
10295 /* Set up SLI-4 Specific device driver resources */
10296 error = lpfc_sli4_driver_resource_setup(phba);
10298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10299 "1412 Failed to set up driver resource.\n");
10300 goto out_unset_pci_mem_s4;
10303 /* Initialize and populate the iocb list per host */
10305 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10306 "2821 initialize iocb list %d.\n",
10307 phba->cfg_iocb_cnt*1024);
10308 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10312 "1413 Failed to initialize iocb list.\n");
10313 goto out_unset_driver_resource_s4;
10316 INIT_LIST_HEAD(&phba->active_rrq_list);
10317 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
10319 /* Set up common device driver resources */
10320 error = lpfc_setup_driver_resource_phase2(phba);
10322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10323 "1414 Failed to set up driver resource.\n");
10324 goto out_free_iocb_list;
10327 /* Get the default values for Model Name and Description */
10328 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10330 /* Create SCSI host to the physical port */
10331 error = lpfc_create_shost(phba);
10333 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10334 "1415 Failed to create scsi host.\n");
10335 goto out_unset_driver_resource;
10338 /* Configure sysfs attributes */
10339 vport = phba->pport;
10340 error = lpfc_alloc_sysfs_attr(vport);
10342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10343 "1416 Failed to allocate sysfs attr\n");
10344 goto out_destroy_shost;
10347 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
10348 /* Now, trying to enable interrupt and bring up the device */
10349 cfg_mode = phba->cfg_use_msi;
10351 /* Put device to a known state before enabling interrupt */
10352 lpfc_stop_port(phba);
10353 /* Configure and enable interrupt */
10354 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10355 if (intr_mode == LPFC_INTR_ERROR) {
10356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10357 "0426 Failed to enable interrupt.\n");
10359 goto out_free_sysfs_attr;
10361 /* Default to single EQ for non-MSI-X */
10362 if (phba->intr_type != MSIX)
10363 adjusted_fcp_io_channel = 1;
10365 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10366 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10367 /* Set up SLI-4 HBA */
10368 if (lpfc_sli4_hba_setup(phba)) {
10369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10370 "1421 Failed to set up hba\n");
10372 goto out_disable_intr;
10375 /* Log the current active interrupt mode */
10376 phba->intr_mode = intr_mode;
10377 lpfc_log_intr_mode(phba, intr_mode);
10379 /* Perform post initialization setup */
10380 lpfc_post_init_setup(phba);
10382 /* check for firmware upgrade or downgrade */
10383 if (phba->cfg_request_firmware_upgrade)
10384 ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
10386 /* Check if there are static vports to be created. */
10387 lpfc_create_static_vport(phba);
10391 lpfc_sli4_disable_intr(phba);
10392 out_free_sysfs_attr:
10393 lpfc_free_sysfs_attr(vport);
10395 lpfc_destroy_shost(phba);
10396 out_unset_driver_resource:
10397 lpfc_unset_driver_resource_phase2(phba);
10398 out_free_iocb_list:
10399 lpfc_free_iocb_list(phba);
10400 out_unset_driver_resource_s4:
10401 lpfc_sli4_driver_resource_unset(phba);
10402 out_unset_pci_mem_s4:
10403 lpfc_sli4_pci_mem_unset(phba);
10404 out_disable_pci_dev:
10405 lpfc_disable_pci_dev(phba);
10407 scsi_host_put(shost);
10409 lpfc_hba_free(phba);
10414 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10415 * @pdev: pointer to PCI device
10417 * This routine is called from the kernel's PCI subsystem to device with
10418 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10419 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10420 * device to be removed from the PCI subsystem properly.
10423 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10425 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10426 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10427 struct lpfc_vport **vports;
10428 struct lpfc_hba *phba = vport->phba;
10431 /* Mark the device unloading flag */
10432 spin_lock_irq(&phba->hbalock);
10433 vport->load_flag |= FC_UNLOADING;
10434 spin_unlock_irq(&phba->hbalock);
10436 /* Free the HBA sysfs attributes */
10437 lpfc_free_sysfs_attr(vport);
10439 /* Release all the vports against this physical port */
10440 vports = lpfc_create_vport_work_array(phba);
10441 if (vports != NULL)
10442 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10443 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10445 fc_vport_terminate(vports[i]->fc_vport);
10447 lpfc_destroy_vport_work_array(phba, vports);
10449 /* Remove FC host and then SCSI host with the physical port */
10450 fc_remove_host(shost);
10451 scsi_remove_host(shost);
10453 /* Perform cleanup on the physical port */
10454 lpfc_cleanup(vport);
10457 * Bring down the SLI Layer. This step disables all interrupts,
10458 * clears the rings, discards all mailbox commands, and resets
10459 * the HBA FCoE function.
10461 lpfc_debugfs_terminate(vport);
10462 lpfc_sli4_hba_unset(phba);
10464 spin_lock_irq(&phba->hbalock);
10465 list_del_init(&vport->listentry);
10466 spin_unlock_irq(&phba->hbalock);
10468 /* Perform scsi free before driver resource_unset since scsi
10469 * buffers are released to their corresponding pools here.
10471 lpfc_scsi_free(phba);
10473 lpfc_sli4_driver_resource_unset(phba);
10475 /* Unmap adapter Control and Doorbell registers */
10476 lpfc_sli4_pci_mem_unset(phba);
10478 /* Release PCI resources and disable device's PCI function */
10479 scsi_host_put(shost);
10480 lpfc_disable_pci_dev(phba);
10482 /* Finally, free the driver's device data structure */
10483 lpfc_hba_free(phba);
10489 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10490 * @pdev: pointer to PCI device
10491 * @msg: power management message
10493 * This routine is called from the kernel's PCI subsystem to support system
10494 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10495 * this method, it quiesces the device by stopping the driver's worker
10496 * thread for the device, turning off device's interrupt and DMA, and bring
10497 * the device offline. Note that as the driver implements the minimum PM
10498 * requirements to a power-aware driver's PM support for suspend/resume -- all
10499 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10500 * method call will be treated as SUSPEND and the driver will fully
10501 * reinitialize its device during resume() method call, the driver will set
10502 * device to PCI_D3hot state in PCI config space instead of setting it
10503 * according to the @msg provided by the PM.
10506 * 0 - driver suspended the device
10510 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10512 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10513 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10515 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10516 "2843 PCI device Power Management suspend.\n");
10518 /* Bring down the device */
10519 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10520 lpfc_offline(phba);
10521 kthread_stop(phba->worker_thread);
10523 /* Disable interrupt from device */
10524 lpfc_sli4_disable_intr(phba);
10525 lpfc_sli4_queue_destroy(phba);
10527 /* Save device state to PCI config space */
10528 pci_save_state(pdev);
10529 pci_set_power_state(pdev, PCI_D3hot);
10535 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10536 * @pdev: pointer to PCI device
10538 * This routine is called from the kernel's PCI subsystem to support system
10539 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10540 * this method, it restores the device's PCI config space state and fully
10541 * reinitializes the device and brings it online. Note that as the driver
10542 * implements the minimum PM requirements to a power-aware driver's PM for
10543 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10544 * to the suspend() method call will be treated as SUSPEND and the driver
10545 * will fully reinitialize its device during resume() method call, the device
10546 * will be set to PCI_D0 directly in PCI config space before restoring the
10550 * 0 - driver suspended the device
10554 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10556 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10557 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10558 uint32_t intr_mode;
10561 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10562 "0292 PCI device Power Management resume.\n");
10564 /* Restore device state from PCI config space */
10565 pci_set_power_state(pdev, PCI_D0);
10566 pci_restore_state(pdev);
10569 * As the new kernel behavior of pci_restore_state() API call clears
10570 * device saved_state flag, need to save the restored state again.
10572 pci_save_state(pdev);
10574 if (pdev->is_busmaster)
10575 pci_set_master(pdev);
10577 /* Startup the kernel thread for this host adapter. */
10578 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10579 "lpfc_worker_%d", phba->brd_no);
10580 if (IS_ERR(phba->worker_thread)) {
10581 error = PTR_ERR(phba->worker_thread);
10582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10583 "0293 PM resume failed to start worker "
10584 "thread: error=x%x.\n", error);
10588 /* Configure and enable interrupt */
10589 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10590 if (intr_mode == LPFC_INTR_ERROR) {
10591 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10592 "0294 PM resume Failed to enable interrupt\n");
10595 phba->intr_mode = intr_mode;
10597 /* Restart HBA and bring it online */
10598 lpfc_sli_brdrestart(phba);
10601 /* Log the current active interrupt mode */
10602 lpfc_log_intr_mode(phba, phba->intr_mode);
10608 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10609 * @phba: pointer to lpfc hba data structure.
10611 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10612 * aborts all the outstanding SCSI I/Os to the pci device.
10615 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10618 "2828 PCI channel I/O abort preparing for recovery\n");
10620 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10621 * and let the SCSI mid-layer to retry them to recover.
10623 lpfc_sli_abort_fcp_rings(phba);
10627 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10628 * @phba: pointer to lpfc hba data structure.
10630 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10631 * disables the device interrupt and pci device, and aborts the internal FCP
10635 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10638 "2826 PCI channel disable preparing for reset\n");
10640 /* Block any management I/Os to the device */
10641 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
10643 /* Block all SCSI devices' I/Os on the host */
10644 lpfc_scsi_dev_block(phba);
10646 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10647 lpfc_sli_flush_fcp_rings(phba);
10649 /* stop all timers */
10650 lpfc_stop_hba_timers(phba);
10652 /* Disable interrupt and pci device */
10653 lpfc_sli4_disable_intr(phba);
10654 lpfc_sli4_queue_destroy(phba);
10655 pci_disable_device(phba->pcidev);
10659 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10660 * @phba: pointer to lpfc hba data structure.
10662 * This routine is called to prepare the SLI4 device for PCI slot permanently
10663 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10667 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10670 "2827 PCI channel permanent disable for failure\n");
10672 /* Block all SCSI devices' I/Os on the host */
10673 lpfc_scsi_dev_block(phba);
10675 /* stop all timers */
10676 lpfc_stop_hba_timers(phba);
10678 /* Clean up all driver's outstanding SCSI I/Os */
10679 lpfc_sli_flush_fcp_rings(phba);
10683 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10684 * @pdev: pointer to PCI device.
10685 * @state: the current PCI connection state.
10687 * This routine is called from the PCI subsystem for error handling to device
10688 * with SLI-4 interface spec. This function is called by the PCI subsystem
10689 * after a PCI bus error affecting this device has been detected. When this
10690 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10691 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10692 * for the PCI subsystem to perform proper recovery as desired.
10695 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10696 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10698 static pci_ers_result_t
10699 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10701 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10702 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10705 case pci_channel_io_normal:
10706 /* Non-fatal error, prepare for recovery */
10707 lpfc_sli4_prep_dev_for_recover(phba);
10708 return PCI_ERS_RESULT_CAN_RECOVER;
10709 case pci_channel_io_frozen:
10710 /* Fatal error, prepare for slot reset */
10711 lpfc_sli4_prep_dev_for_reset(phba);
10712 return PCI_ERS_RESULT_NEED_RESET;
10713 case pci_channel_io_perm_failure:
10714 /* Permanent failure, prepare for device down */
10715 lpfc_sli4_prep_dev_for_perm_failure(phba);
10716 return PCI_ERS_RESULT_DISCONNECT;
10718 /* Unknown state, prepare and request slot reset */
10719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10720 "2825 Unknown PCI error state: x%x\n", state);
10721 lpfc_sli4_prep_dev_for_reset(phba);
10722 return PCI_ERS_RESULT_NEED_RESET;
10727 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10728 * @pdev: pointer to PCI device.
10730 * This routine is called from the PCI subsystem for error handling to device
10731 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10732 * restart the PCI card from scratch, as if from a cold-boot. During the
10733 * PCI subsystem error recovery, after the driver returns
10734 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10735 * recovery and then call this routine before calling the .resume method to
10736 * recover the device. This function will initialize the HBA device, enable
10737 * the interrupt, but it will just put the HBA to offline state without
10738 * passing any I/O traffic.
10741 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10742 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10744 static pci_ers_result_t
10745 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10747 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10748 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10749 struct lpfc_sli *psli = &phba->sli;
10750 uint32_t intr_mode;
10752 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10753 if (pci_enable_device_mem(pdev)) {
10754 printk(KERN_ERR "lpfc: Cannot re-enable "
10755 "PCI device after reset.\n");
10756 return PCI_ERS_RESULT_DISCONNECT;
10759 pci_restore_state(pdev);
10762 * As the new kernel behavior of pci_restore_state() API call clears
10763 * device saved_state flag, need to save the restored state again.
10765 pci_save_state(pdev);
10767 if (pdev->is_busmaster)
10768 pci_set_master(pdev);
10770 spin_lock_irq(&phba->hbalock);
10771 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10772 spin_unlock_irq(&phba->hbalock);
10774 /* Configure and enable interrupt */
10775 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10776 if (intr_mode == LPFC_INTR_ERROR) {
10777 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10778 "2824 Cannot re-enable interrupt after "
10780 return PCI_ERS_RESULT_DISCONNECT;
10782 phba->intr_mode = intr_mode;
10784 /* Log the current active interrupt mode */
10785 lpfc_log_intr_mode(phba, phba->intr_mode);
10787 return PCI_ERS_RESULT_RECOVERED;
10791 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10792 * @pdev: pointer to PCI device
10794 * This routine is called from the PCI subsystem for error handling to device
10795 * with SLI-4 interface spec. It is called when kernel error recovery tells
10796 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10797 * error recovery. After this call, traffic can start to flow from this device
10801 lpfc_io_resume_s4(struct pci_dev *pdev)
10803 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10804 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10807 * In case of slot reset, as function reset is performed through
10808 * mailbox command which needs DMA to be enabled, this operation
10809 * has to be moved to the io resume phase. Taking device offline
10810 * will perform the necessary cleanup.
10812 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10813 /* Perform device reset */
10814 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
10815 lpfc_offline(phba);
10816 lpfc_sli_brdrestart(phba);
10817 /* Bring the device back online */
10821 /* Clean up Advanced Error Reporting (AER) if needed */
10822 if (phba->hba_flag & HBA_AER_ENABLED)
10823 pci_cleanup_aer_uncorrect_error_status(pdev);
10827 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10828 * @pdev: pointer to PCI device
10829 * @pid: pointer to PCI device identifier
10831 * This routine is to be registered to the kernel's PCI subsystem. When an
10832 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10833 * at PCI device-specific information of the device and driver to see if the
10834 * driver state that it can support this kind of device. If the match is
10835 * successful, the driver core invokes this routine. This routine dispatches
10836 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10837 * do all the initialization that it needs to do to handle the HBA device
10841 * 0 - driver can claim the device
10842 * negative value - driver can not claim the device
10845 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10848 struct lpfc_sli_intf intf;
10850 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
10853 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
10854 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
10855 rc = lpfc_pci_probe_one_s4(pdev, pid);
10857 rc = lpfc_pci_probe_one_s3(pdev, pid);
10863 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10864 * @pdev: pointer to PCI device
10866 * This routine is to be registered to the kernel's PCI subsystem. When an
10867 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10868 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10869 * remove routine, which will perform all the necessary cleanup for the
10870 * device to be removed from the PCI subsystem properly.
10873 lpfc_pci_remove_one(struct pci_dev *pdev)
10875 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10876 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10878 switch (phba->pci_dev_grp) {
10879 case LPFC_PCI_DEV_LP:
10880 lpfc_pci_remove_one_s3(pdev);
10882 case LPFC_PCI_DEV_OC:
10883 lpfc_pci_remove_one_s4(pdev);
10886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10887 "1424 Invalid PCI device group: 0x%x\n",
10888 phba->pci_dev_grp);
10895 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10896 * @pdev: pointer to PCI device
10897 * @msg: power management message
10899 * This routine is to be registered to the kernel's PCI subsystem to support
10900 * system Power Management (PM). When PM invokes this method, it dispatches
10901 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10902 * suspend the device.
10905 * 0 - driver suspended the device
10909 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10911 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10912 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10915 switch (phba->pci_dev_grp) {
10916 case LPFC_PCI_DEV_LP:
10917 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10919 case LPFC_PCI_DEV_OC:
10920 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10924 "1425 Invalid PCI device group: 0x%x\n",
10925 phba->pci_dev_grp);
10932 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10933 * @pdev: pointer to PCI device
10935 * This routine is to be registered to the kernel's PCI subsystem to support
10936 * system Power Management (PM). When PM invokes this method, it dispatches
10937 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10938 * resume the device.
10941 * 0 - driver suspended the device
10945 lpfc_pci_resume_one(struct pci_dev *pdev)
10947 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10948 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10951 switch (phba->pci_dev_grp) {
10952 case LPFC_PCI_DEV_LP:
10953 rc = lpfc_pci_resume_one_s3(pdev);
10955 case LPFC_PCI_DEV_OC:
10956 rc = lpfc_pci_resume_one_s4(pdev);
10959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10960 "1426 Invalid PCI device group: 0x%x\n",
10961 phba->pci_dev_grp);
10968 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10969 * @pdev: pointer to PCI device.
10970 * @state: the current PCI connection state.
10972 * This routine is registered to the PCI subsystem for error handling. This
10973 * function is called by the PCI subsystem after a PCI bus error affecting
10974 * this device has been detected. When this routine is invoked, it dispatches
10975 * the action to the proper SLI-3 or SLI-4 device error detected handling
10976 * routine, which will perform the proper error detected operation.
10979 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10980 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10982 static pci_ers_result_t
10983 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10985 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10986 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10987 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10989 switch (phba->pci_dev_grp) {
10990 case LPFC_PCI_DEV_LP:
10991 rc = lpfc_io_error_detected_s3(pdev, state);
10993 case LPFC_PCI_DEV_OC:
10994 rc = lpfc_io_error_detected_s4(pdev, state);
10997 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10998 "1427 Invalid PCI device group: 0x%x\n",
10999 phba->pci_dev_grp);
11006 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11007 * @pdev: pointer to PCI device.
11009 * This routine is registered to the PCI subsystem for error handling. This
11010 * function is called after PCI bus has been reset to restart the PCI card
11011 * from scratch, as if from a cold-boot. When this routine is invoked, it
11012 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11013 * routine, which will perform the proper device reset.
11016 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11017 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11019 static pci_ers_result_t
11020 lpfc_io_slot_reset(struct pci_dev *pdev)
11022 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11023 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11024 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11026 switch (phba->pci_dev_grp) {
11027 case LPFC_PCI_DEV_LP:
11028 rc = lpfc_io_slot_reset_s3(pdev);
11030 case LPFC_PCI_DEV_OC:
11031 rc = lpfc_io_slot_reset_s4(pdev);
11034 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11035 "1428 Invalid PCI device group: 0x%x\n",
11036 phba->pci_dev_grp);
11043 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11044 * @pdev: pointer to PCI device
11046 * This routine is registered to the PCI subsystem for error handling. It
11047 * is called when kernel error recovery tells the lpfc driver that it is
11048 * OK to resume normal PCI operation after PCI bus error recovery. When
11049 * this routine is invoked, it dispatches the action to the proper SLI-3
11050 * or SLI-4 device io_resume routine, which will resume the device operation.
11053 lpfc_io_resume(struct pci_dev *pdev)
11055 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11056 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11058 switch (phba->pci_dev_grp) {
11059 case LPFC_PCI_DEV_LP:
11060 lpfc_io_resume_s3(pdev);
11062 case LPFC_PCI_DEV_OC:
11063 lpfc_io_resume_s4(pdev);
11066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11067 "1429 Invalid PCI device group: 0x%x\n",
11068 phba->pci_dev_grp);
11075 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11076 * @phba: pointer to lpfc hba data structure.
11078 * This routine checks to see if OAS is supported for this adapter. If
11079 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11080 * the enable oas flag is cleared and the pool created for OAS device data
11085 lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11088 if (!phba->cfg_EnableXLane)
11091 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11095 if (phba->device_data_mem_pool)
11096 mempool_destroy(phba->device_data_mem_pool);
11097 phba->device_data_mem_pool = NULL;
11104 * lpfc_fof_queue_setup - Set up all the fof queues
11105 * @phba: pointer to lpfc hba data structure.
11107 * This routine is invoked to set up all the fof queues for the FC HBA
11112 * -ENOMEM - No available memory
11115 lpfc_fof_queue_setup(struct lpfc_hba *phba)
11117 struct lpfc_sli *psli = &phba->sli;
11120 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11124 if (phba->cfg_fof) {
11126 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11127 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11131 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11132 phba->sli4_hba.oas_cq, LPFC_FCP);
11136 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11137 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11143 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
11145 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11151 * lpfc_fof_queue_create - Create all the fof queues
11152 * @phba: pointer to lpfc hba data structure.
11154 * This routine is invoked to allocate all the fof queues for the FC HBA
11155 * operation. For each SLI4 queue type, the parameters such as queue entry
11156 * count (queue depth) shall be taken from the module parameter. For now,
11157 * we just use some constant number as place holder.
11161 * -ENOMEM - No availble memory
11162 * -EIO - The mailbox failed to complete successfully.
11165 lpfc_fof_queue_create(struct lpfc_hba *phba)
11167 struct lpfc_queue *qdesc;
11169 /* Create FOF EQ */
11170 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11171 phba->sli4_hba.eq_ecount);
11175 phba->sli4_hba.fof_eq = qdesc;
11177 if (phba->cfg_fof) {
11179 /* Create OAS CQ */
11180 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11181 phba->sli4_hba.cq_ecount);
11185 phba->sli4_hba.oas_cq = qdesc;
11187 /* Create OAS WQ */
11188 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11189 phba->sli4_hba.wq_ecount);
11193 phba->sli4_hba.oas_wq = qdesc;
11199 lpfc_fof_queue_destroy(phba);
11204 * lpfc_fof_queue_destroy - Destroy all the fof queues
11205 * @phba: pointer to lpfc hba data structure.
11207 * This routine is invoked to release all the SLI4 queues with the FC HBA
11214 lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11216 /* Release FOF Event queue */
11217 if (phba->sli4_hba.fof_eq != NULL) {
11218 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11219 phba->sli4_hba.fof_eq = NULL;
11222 /* Release OAS Completion queue */
11223 if (phba->sli4_hba.oas_cq != NULL) {
11224 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11225 phba->sli4_hba.oas_cq = NULL;
11228 /* Release OAS Work queue */
11229 if (phba->sli4_hba.oas_wq != NULL) {
11230 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11231 phba->sli4_hba.oas_wq = NULL;
11236 static struct pci_device_id lpfc_id_table[] = {
11237 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11238 PCI_ANY_ID, PCI_ANY_ID, },
11239 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11240 PCI_ANY_ID, PCI_ANY_ID, },
11241 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11242 PCI_ANY_ID, PCI_ANY_ID, },
11243 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11244 PCI_ANY_ID, PCI_ANY_ID, },
11245 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11246 PCI_ANY_ID, PCI_ANY_ID, },
11247 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11248 PCI_ANY_ID, PCI_ANY_ID, },
11249 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11250 PCI_ANY_ID, PCI_ANY_ID, },
11251 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11252 PCI_ANY_ID, PCI_ANY_ID, },
11253 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11254 PCI_ANY_ID, PCI_ANY_ID, },
11255 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11256 PCI_ANY_ID, PCI_ANY_ID, },
11257 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11258 PCI_ANY_ID, PCI_ANY_ID, },
11259 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11260 PCI_ANY_ID, PCI_ANY_ID, },
11261 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11262 PCI_ANY_ID, PCI_ANY_ID, },
11263 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11264 PCI_ANY_ID, PCI_ANY_ID, },
11265 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11266 PCI_ANY_ID, PCI_ANY_ID, },
11267 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11268 PCI_ANY_ID, PCI_ANY_ID, },
11269 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11270 PCI_ANY_ID, PCI_ANY_ID, },
11271 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11272 PCI_ANY_ID, PCI_ANY_ID, },
11273 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11274 PCI_ANY_ID, PCI_ANY_ID, },
11275 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11276 PCI_ANY_ID, PCI_ANY_ID, },
11277 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11278 PCI_ANY_ID, PCI_ANY_ID, },
11279 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11280 PCI_ANY_ID, PCI_ANY_ID, },
11281 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11282 PCI_ANY_ID, PCI_ANY_ID, },
11283 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11284 PCI_ANY_ID, PCI_ANY_ID, },
11285 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11286 PCI_ANY_ID, PCI_ANY_ID, },
11287 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11288 PCI_ANY_ID, PCI_ANY_ID, },
11289 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11290 PCI_ANY_ID, PCI_ANY_ID, },
11291 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11292 PCI_ANY_ID, PCI_ANY_ID, },
11293 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11294 PCI_ANY_ID, PCI_ANY_ID, },
11295 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11296 PCI_ANY_ID, PCI_ANY_ID, },
11297 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11298 PCI_ANY_ID, PCI_ANY_ID, },
11299 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11300 PCI_ANY_ID, PCI_ANY_ID, },
11301 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11302 PCI_ANY_ID, PCI_ANY_ID, },
11303 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11304 PCI_ANY_ID, PCI_ANY_ID, },
11305 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11306 PCI_ANY_ID, PCI_ANY_ID, },
11307 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11308 PCI_ANY_ID, PCI_ANY_ID, },
11309 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11310 PCI_ANY_ID, PCI_ANY_ID, },
11311 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11312 PCI_ANY_ID, PCI_ANY_ID, },
11313 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11314 PCI_ANY_ID, PCI_ANY_ID, },
11315 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
11316 PCI_ANY_ID, PCI_ANY_ID, },
11317 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11318 PCI_ANY_ID, PCI_ANY_ID, },
11319 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11320 PCI_ANY_ID, PCI_ANY_ID, },
11321 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11322 PCI_ANY_ID, PCI_ANY_ID, },
11323 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11324 PCI_ANY_ID, PCI_ANY_ID, },
11325 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11326 PCI_ANY_ID, PCI_ANY_ID, },
11327 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11328 PCI_ANY_ID, PCI_ANY_ID, },
11329 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11330 PCI_ANY_ID, PCI_ANY_ID, },
11334 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11336 static const struct pci_error_handlers lpfc_err_handler = {
11337 .error_detected = lpfc_io_error_detected,
11338 .slot_reset = lpfc_io_slot_reset,
11339 .resume = lpfc_io_resume,
11342 static struct pci_driver lpfc_driver = {
11343 .name = LPFC_DRIVER_NAME,
11344 .id_table = lpfc_id_table,
11345 .probe = lpfc_pci_probe_one,
11346 .remove = lpfc_pci_remove_one,
11347 .suspend = lpfc_pci_suspend_one,
11348 .resume = lpfc_pci_resume_one,
11349 .err_handler = &lpfc_err_handler,
11352 static const struct file_operations lpfc_mgmt_fop = {
11353 .owner = THIS_MODULE,
11356 static struct miscdevice lpfc_mgmt_dev = {
11357 .minor = MISC_DYNAMIC_MINOR,
11358 .name = "lpfcmgmt",
11359 .fops = &lpfc_mgmt_fop,
11363 * lpfc_init - lpfc module initialization routine
11365 * This routine is to be invoked when the lpfc module is loaded into the
11366 * kernel. The special kernel macro module_init() is used to indicate the
11367 * role of this routine to the kernel as lpfc module entry point.
11371 * -ENOMEM - FC attach transport failed
11372 * all others - failed
11380 printk(LPFC_MODULE_DESC "\n");
11381 printk(LPFC_COPYRIGHT "\n");
11383 error = misc_register(&lpfc_mgmt_dev);
11385 printk(KERN_ERR "Could not register lpfcmgmt device, "
11386 "misc_register returned with status %d", error);
11388 if (lpfc_enable_npiv) {
11389 lpfc_transport_functions.vport_create = lpfc_vport_create;
11390 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11392 lpfc_transport_template =
11393 fc_attach_transport(&lpfc_transport_functions);
11394 if (lpfc_transport_template == NULL)
11396 if (lpfc_enable_npiv) {
11397 lpfc_vport_transport_template =
11398 fc_attach_transport(&lpfc_vport_transport_functions);
11399 if (lpfc_vport_transport_template == NULL) {
11400 fc_release_transport(lpfc_transport_template);
11405 /* Initialize in case vector mapping is needed */
11406 lpfc_used_cpu = NULL;
11407 lpfc_present_cpu = 0;
11408 for_each_present_cpu(cpu)
11409 lpfc_present_cpu++;
11411 error = pci_register_driver(&lpfc_driver);
11413 fc_release_transport(lpfc_transport_template);
11414 if (lpfc_enable_npiv)
11415 fc_release_transport(lpfc_vport_transport_template);
11422 * lpfc_exit - lpfc module removal routine
11424 * This routine is invoked when the lpfc module is removed from the kernel.
11425 * The special kernel macro module_exit() is used to indicate the role of
11426 * this routine to the kernel as lpfc module exit point.
11431 misc_deregister(&lpfc_mgmt_dev);
11432 pci_unregister_driver(&lpfc_driver);
11433 fc_release_transport(lpfc_transport_template);
11434 if (lpfc_enable_npiv)
11435 fc_release_transport(lpfc_vport_transport_template);
11436 if (_dump_buf_data) {
11437 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11438 "_dump_buf_data at 0x%p\n",
11439 (1L << _dump_buf_data_order), _dump_buf_data);
11440 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11443 if (_dump_buf_dif) {
11444 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11445 "_dump_buf_dif at 0x%p\n",
11446 (1L << _dump_buf_dif_order), _dump_buf_dif);
11447 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11449 kfree(lpfc_used_cpu);
11452 module_init(lpfc_init);
11453 module_exit(lpfc_exit);
11454 MODULE_LICENSE("GPL");
11455 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11456 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11457 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);