1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_version.h"
51 unsigned long _dump_buf_data_order;
53 unsigned long _dump_buf_dif_order;
54 spinlock_t _dump_buf_lock;
56 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
57 static int lpfc_post_rcv_buf(struct lpfc_hba *);
58 static int lpfc_sli4_queue_create(struct lpfc_hba *);
59 static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
60 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
61 static int lpfc_setup_endian_order(struct lpfc_hba *);
62 static int lpfc_sli4_read_config(struct lpfc_hba *);
63 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
64 static void lpfc_free_sgl_list(struct lpfc_hba *);
65 static int lpfc_init_sgl_list(struct lpfc_hba *);
66 static int lpfc_init_active_sgl_array(struct lpfc_hba *);
67 static void lpfc_free_active_sgl(struct lpfc_hba *);
68 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
69 static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
70 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
71 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
72 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
74 static struct scsi_transport_template *lpfc_transport_template = NULL;
75 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
76 static DEFINE_IDR(lpfc_hba_index);
79 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
80 * @phba: pointer to lpfc hba data structure.
82 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
83 * mailbox command. It retrieves the revision information from the HBA and
84 * collects the Vital Product Data (VPD) about the HBA for preparing the
85 * configuration of the HBA.
89 * -ERESTART - requests the SLI layer to reset the HBA and try again.
90 * Any other value - indicates an error.
93 lpfc_config_port_prep(struct lpfc_hba *phba)
95 lpfc_vpd_t *vp = &phba->vpd;
99 char *lpfc_vpd_data = NULL;
101 static char licensed[56] =
102 "key unlock for use with gnu public licensed code only\0";
103 static int init_key = 1;
105 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
107 phba->link_state = LPFC_HBA_ERROR;
112 phba->link_state = LPFC_INIT_MBX_CMDS;
114 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
116 uint32_t *ptext = (uint32_t *) licensed;
118 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
119 *ptext = cpu_to_be32(*ptext);
123 lpfc_read_nv(phba, pmb);
124 memset((char*)mb->un.varRDnvp.rsvd3, 0,
125 sizeof (mb->un.varRDnvp.rsvd3));
126 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
129 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
131 if (rc != MBX_SUCCESS) {
132 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
133 "0324 Config Port initialization "
134 "error, mbxCmd x%x READ_NVPARM, "
136 mb->mbxCommand, mb->mbxStatus);
137 mempool_free(pmb, phba->mbox_mem_pool);
140 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
142 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
146 phba->sli3_options = 0x0;
148 /* Setup and issue mailbox READ REV command */
149 lpfc_read_rev(phba, pmb);
150 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
151 if (rc != MBX_SUCCESS) {
152 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
153 "0439 Adapter failed to init, mbxCmd x%x "
154 "READ_REV, mbxStatus x%x\n",
155 mb->mbxCommand, mb->mbxStatus);
156 mempool_free( pmb, phba->mbox_mem_pool);
162 * The value of rr must be 1 since the driver set the cv field to 1.
163 * This setting requires the FW to set all revision fields.
165 if (mb->un.varRdRev.rr == 0) {
167 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
168 "0440 Adapter failed to init, READ_REV has "
169 "missing revision information.\n");
170 mempool_free(pmb, phba->mbox_mem_pool);
174 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
175 mempool_free(pmb, phba->mbox_mem_pool);
179 /* Save information as VPD data */
181 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
182 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
183 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
184 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
185 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
186 vp->rev.biuRev = mb->un.varRdRev.biuRev;
187 vp->rev.smRev = mb->un.varRdRev.smRev;
188 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
189 vp->rev.endecRev = mb->un.varRdRev.endecRev;
190 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
191 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
192 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
193 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
194 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
195 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
197 /* If the sli feature level is less then 9, we must
198 * tear down all RPIs and VPIs on link down if NPIV
201 if (vp->rev.feaLevelHigh < 9)
202 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
204 if (lpfc_is_LC_HBA(phba->pcidev->device))
205 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
206 sizeof (phba->RandomData));
208 /* Get adapter VPD information */
209 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
214 lpfc_dump_mem(phba, pmb, offset);
215 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
217 if (rc != MBX_SUCCESS) {
218 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
219 "0441 VPD not present on adapter, "
220 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
221 mb->mbxCommand, mb->mbxStatus);
222 mb->un.varDmp.word_cnt = 0;
224 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
225 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
226 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
227 lpfc_vpd_data + offset,
228 mb->un.varDmp.word_cnt);
229 offset += mb->un.varDmp.word_cnt;
230 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
231 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
233 kfree(lpfc_vpd_data);
235 mempool_free(pmb, phba->mbox_mem_pool);
240 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
241 * @phba: pointer to lpfc hba data structure.
242 * @pmboxq: pointer to the driver internal queue element for mailbox command.
244 * This is the completion handler for driver's configuring asynchronous event
245 * mailbox command to the device. If the mailbox command returns successfully,
246 * it will set internal async event support flag to 1; otherwise, it will
247 * set internal async event support flag to 0.
250 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
252 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
253 phba->temp_sensor_support = 1;
255 phba->temp_sensor_support = 0;
256 mempool_free(pmboxq, phba->mbox_mem_pool);
261 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
262 * @phba: pointer to lpfc hba data structure.
263 * @pmboxq: pointer to the driver internal queue element for mailbox command.
265 * This is the completion handler for dump mailbox command for getting
266 * wake up parameters. When this command complete, the response contain
267 * Option rom version of the HBA. This function translate the version number
268 * into a human readable string and store it in OptionROMVersion.
271 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
274 uint32_t prog_id_word;
276 /* character array used for decoding dist type. */
277 char dist_char[] = "nabx";
279 if (pmboxq->mb.mbxStatus != MBX_SUCCESS) {
280 mempool_free(pmboxq, phba->mbox_mem_pool);
284 prg = (struct prog_id *) &prog_id_word;
286 /* word 7 contain option rom version */
287 prog_id_word = pmboxq->mb.un.varWords[7];
289 /* Decode the Option rom version word to a readable string */
291 dist = dist_char[prg->dist];
293 if ((prg->dist == 3) && (prg->num == 0))
294 sprintf(phba->OptionROMVersion, "%d.%d%d",
295 prg->ver, prg->rev, prg->lev);
297 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
298 prg->ver, prg->rev, prg->lev,
300 mempool_free(pmboxq, phba->mbox_mem_pool);
305 * lpfc_config_port_post - Perform lpfc initialization after config port
306 * @phba: pointer to lpfc hba data structure.
308 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
309 * command call. It performs all internal resource and state setups on the
310 * port: post IOCB buffers, enable appropriate host interrupt attentions,
311 * ELS ring timers, etc.
315 * Any other value - error.
318 lpfc_config_port_post(struct lpfc_hba *phba)
320 struct lpfc_vport *vport = phba->pport;
321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
324 struct lpfc_dmabuf *mp;
325 struct lpfc_sli *psli = &phba->sli;
326 uint32_t status, timeout;
330 spin_lock_irq(&phba->hbalock);
332 * If the Config port completed correctly the HBA is not
333 * over heated any more.
335 if (phba->over_temp_state == HBA_OVER_TEMP)
336 phba->over_temp_state = HBA_NORMAL_TEMP;
337 spin_unlock_irq(&phba->hbalock);
339 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
341 phba->link_state = LPFC_HBA_ERROR;
346 /* Get login parameters for NID. */
347 lpfc_read_sparam(phba, pmb, 0);
349 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
351 "0448 Adapter failed init, mbxCmd x%x "
352 "READ_SPARM mbxStatus x%x\n",
353 mb->mbxCommand, mb->mbxStatus);
354 phba->link_state = LPFC_HBA_ERROR;
355 mp = (struct lpfc_dmabuf *) pmb->context1;
356 mempool_free( pmb, phba->mbox_mem_pool);
357 lpfc_mbuf_free(phba, mp->virt, mp->phys);
362 mp = (struct lpfc_dmabuf *) pmb->context1;
364 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
365 lpfc_mbuf_free(phba, mp->virt, mp->phys);
367 pmb->context1 = NULL;
369 if (phba->cfg_soft_wwnn)
370 u64_to_wwn(phba->cfg_soft_wwnn,
371 vport->fc_sparam.nodeName.u.wwn);
372 if (phba->cfg_soft_wwpn)
373 u64_to_wwn(phba->cfg_soft_wwpn,
374 vport->fc_sparam.portName.u.wwn);
375 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
376 sizeof (struct lpfc_name));
377 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
378 sizeof (struct lpfc_name));
380 /* Update the fc_host data structures with new wwn. */
381 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
382 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
384 /* If no serial number in VPD data, use low 6 bytes of WWNN */
385 /* This should be consolidated into parse_vpd ? - mr */
386 if (phba->SerialNumber[0] == 0) {
389 outptr = &vport->fc_nodename.u.s.IEEE[0];
390 for (i = 0; i < 12; i++) {
392 j = ((status & 0xf0) >> 4);
394 phba->SerialNumber[i] =
395 (char)((uint8_t) 0x30 + (uint8_t) j);
397 phba->SerialNumber[i] =
398 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
402 phba->SerialNumber[i] =
403 (char)((uint8_t) 0x30 + (uint8_t) j);
405 phba->SerialNumber[i] =
406 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
410 lpfc_read_config(phba, pmb);
412 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
414 "0453 Adapter failed to init, mbxCmd x%x "
415 "READ_CONFIG, mbxStatus x%x\n",
416 mb->mbxCommand, mb->mbxStatus);
417 phba->link_state = LPFC_HBA_ERROR;
418 mempool_free( pmb, phba->mbox_mem_pool);
422 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
423 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
424 phba->cfg_hba_queue_depth =
425 mb->un.varRdConfig.max_xri + 1;
427 phba->lmt = mb->un.varRdConfig.lmt;
429 /* Get the default values for Model Name and Description */
430 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
432 if ((phba->cfg_link_speed > LINK_SPEED_10G)
433 || ((phba->cfg_link_speed == LINK_SPEED_1G)
434 && !(phba->lmt & LMT_1Gb))
435 || ((phba->cfg_link_speed == LINK_SPEED_2G)
436 && !(phba->lmt & LMT_2Gb))
437 || ((phba->cfg_link_speed == LINK_SPEED_4G)
438 && !(phba->lmt & LMT_4Gb))
439 || ((phba->cfg_link_speed == LINK_SPEED_8G)
440 && !(phba->lmt & LMT_8Gb))
441 || ((phba->cfg_link_speed == LINK_SPEED_10G)
442 && !(phba->lmt & LMT_10Gb))) {
443 /* Reset link speed to auto */
444 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
445 "1302 Invalid speed for this board: "
446 "Reset link speed to auto: x%x\n",
447 phba->cfg_link_speed);
448 phba->cfg_link_speed = LINK_SPEED_AUTO;
451 phba->link_state = LPFC_LINK_DOWN;
453 /* Only process IOCBs on ELS ring till hba_state is READY */
454 if (psli->ring[psli->extra_ring].cmdringaddr)
455 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
456 if (psli->ring[psli->fcp_ring].cmdringaddr)
457 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
458 if (psli->ring[psli->next_ring].cmdringaddr)
459 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
461 /* Post receive buffers for desired rings */
462 if (phba->sli_rev != 3)
463 lpfc_post_rcv_buf(phba);
466 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
468 if (phba->intr_type == MSIX) {
469 rc = lpfc_config_msi(phba, pmb);
471 mempool_free(pmb, phba->mbox_mem_pool);
474 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
475 if (rc != MBX_SUCCESS) {
476 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
477 "0352 Config MSI mailbox command "
478 "failed, mbxCmd x%x, mbxStatus x%x\n",
479 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
480 mempool_free(pmb, phba->mbox_mem_pool);
485 /* Initialize ERATT handling flag */
486 phba->hba_flag &= ~HBA_ERATT_HANDLED;
488 /* Enable appropriate host interrupts */
489 spin_lock_irq(&phba->hbalock);
490 status = readl(phba->HCregaddr);
491 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
492 if (psli->num_rings > 0)
493 status |= HC_R0INT_ENA;
494 if (psli->num_rings > 1)
495 status |= HC_R1INT_ENA;
496 if (psli->num_rings > 2)
497 status |= HC_R2INT_ENA;
498 if (psli->num_rings > 3)
499 status |= HC_R3INT_ENA;
501 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
502 (phba->cfg_poll & DISABLE_FCP_RING_INT))
503 status &= ~(HC_R0INT_ENA);
505 writel(status, phba->HCregaddr);
506 readl(phba->HCregaddr); /* flush */
507 spin_unlock_irq(&phba->hbalock);
509 /* Set up ring-0 (ELS) timer */
510 timeout = phba->fc_ratov * 2;
511 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
512 /* Set up heart beat (HB) timer */
513 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
514 phba->hb_outstanding = 0;
515 phba->last_completion_time = jiffies;
516 /* Set up error attention (ERATT) polling timer */
517 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
519 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
520 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
521 lpfc_set_loopback_flag(phba);
522 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
523 if (rc != MBX_SUCCESS) {
524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
525 "0454 Adapter failed to init, mbxCmd x%x "
526 "INIT_LINK, mbxStatus x%x\n",
527 mb->mbxCommand, mb->mbxStatus);
529 /* Clear all interrupt enable conditions */
530 writel(0, phba->HCregaddr);
531 readl(phba->HCregaddr); /* flush */
532 /* Clear all pending interrupts */
533 writel(0xffffffff, phba->HAregaddr);
534 readl(phba->HAregaddr); /* flush */
536 phba->link_state = LPFC_HBA_ERROR;
538 mempool_free(pmb, phba->mbox_mem_pool);
541 /* MBOX buffer will be freed in mbox compl */
542 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
543 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
544 pmb->mbox_cmpl = lpfc_config_async_cmpl;
545 pmb->vport = phba->pport;
546 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
548 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
549 lpfc_printf_log(phba,
552 "0456 Adapter failed to issue "
553 "ASYNCEVT_ENABLE mbox status x%x \n.",
555 mempool_free(pmb, phba->mbox_mem_pool);
558 /* Get Option rom version */
559 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
560 lpfc_dump_wakeup_param(phba, pmb);
561 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
562 pmb->vport = phba->pport;
563 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
565 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
567 "to get Option ROM version status x%x\n.", rc);
568 mempool_free(pmb, phba->mbox_mem_pool);
575 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
576 * @phba: pointer to lpfc HBA data structure.
578 * This routine will do LPFC uninitialization before the HBA is reset when
579 * bringing down the SLI Layer.
583 * Any other value - error.
586 lpfc_hba_down_prep(struct lpfc_hba *phba)
588 struct lpfc_vport **vports;
591 if (phba->sli_rev <= LPFC_SLI_REV3) {
592 /* Disable interrupts */
593 writel(0, phba->HCregaddr);
594 readl(phba->HCregaddr); /* flush */
597 if (phba->pport->load_flag & FC_UNLOADING)
598 lpfc_cleanup_discovery_resources(phba->pport);
600 vports = lpfc_create_vport_work_array(phba);
602 for (i = 0; i <= phba->max_vports &&
603 vports[i] != NULL; i++)
604 lpfc_cleanup_discovery_resources(vports[i]);
605 lpfc_destroy_vport_work_array(phba, vports);
611 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
612 * @phba: pointer to lpfc HBA data structure.
614 * This routine will do uninitialization after the HBA is reset when bring
615 * down the SLI Layer.
619 * Any other value - error.
622 lpfc_hba_down_post_s3(struct lpfc_hba *phba)
624 struct lpfc_sli *psli = &phba->sli;
625 struct lpfc_sli_ring *pring;
626 struct lpfc_dmabuf *mp, *next_mp;
627 LIST_HEAD(completions);
630 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
631 lpfc_sli_hbqbuf_free_all(phba);
633 /* Cleanup preposted buffers on the ELS ring */
634 pring = &psli->ring[LPFC_ELS_RING];
635 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
637 pring->postbufq_cnt--;
638 lpfc_mbuf_free(phba, mp->virt, mp->phys);
643 spin_lock_irq(&phba->hbalock);
644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
647 /* At this point in time the HBA is either reset or DOA. Either
648 * way, nothing should be on txcmplq as it will NEVER complete.
650 list_splice_init(&pring->txcmplq, &completions);
651 pring->txcmplq_cnt = 0;
652 spin_unlock_irq(&phba->hbalock);
654 /* Cancel all the IOCBs from the completions list */
655 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
658 lpfc_sli_abort_iocb_ring(phba, pring);
659 spin_lock_irq(&phba->hbalock);
661 spin_unlock_irq(&phba->hbalock);
666 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
667 * @phba: pointer to lpfc HBA data structure.
669 * This routine will do uninitialization after the HBA is reset when bring
670 * down the SLI Layer.
674 * Any other value - error.
677 lpfc_hba_down_post_s4(struct lpfc_hba *phba)
679 struct lpfc_scsi_buf *psb, *psb_next;
682 unsigned long iflag = 0;
683 ret = lpfc_hba_down_post_s3(phba);
686 /* At this point in time the HBA is either reset or DOA. Either
687 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
688 * on the lpfc_sgl_list so that it can either be freed if the
689 * driver is unloading or reposted if the driver is restarting
692 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
694 /* abts_sgl_list_lock required because worker thread uses this
697 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
698 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
699 &phba->sli4_hba.lpfc_sgl_list);
700 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
701 /* abts_scsi_buf_list_lock required because worker thread uses this
704 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
705 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
707 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
708 spin_unlock_irq(&phba->hbalock);
710 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
712 psb->status = IOSTAT_SUCCESS;
714 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
715 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
716 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
721 * lpfc_hba_down_post - Wrapper func for hba down post routine
722 * @phba: pointer to lpfc HBA data structure.
724 * This routine wraps the actual SLI3 or SLI4 routine for performing
725 * uninitialization after the HBA is reset when bring down the SLI Layer.
729 * Any other value - error.
732 lpfc_hba_down_post(struct lpfc_hba *phba)
734 return (*phba->lpfc_hba_down_post)(phba);
738 * lpfc_hb_timeout - The HBA-timer timeout handler
739 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
741 * This is the HBA-timer timeout handler registered to the lpfc driver. When
742 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
743 * work-port-events bitmap and the worker thread is notified. This timeout
744 * event will be used by the worker thread to invoke the actual timeout
745 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
746 * be performed in the timeout handler and the HBA timeout event bit shall
747 * be cleared by the worker thread after it has taken the event bitmap out.
750 lpfc_hb_timeout(unsigned long ptr)
752 struct lpfc_hba *phba;
756 phba = (struct lpfc_hba *)ptr;
758 /* Check for heart beat timeout conditions */
759 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
760 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
762 phba->pport->work_port_events |= WORKER_HB_TMO;
763 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
765 /* Tell the worker thread there is work to do */
767 lpfc_worker_wake_up(phba);
772 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
773 * @phba: pointer to lpfc hba data structure.
774 * @pmboxq: pointer to the driver internal queue element for mailbox command.
776 * This is the callback function to the lpfc heart-beat mailbox command.
777 * If configured, the lpfc driver issues the heart-beat mailbox command to
778 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
779 * heart-beat mailbox command is issued, the driver shall set up heart-beat
780 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
781 * heart-beat outstanding state. Once the mailbox command comes back and
782 * no error conditions detected, the heart-beat mailbox command timer is
783 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
784 * state is cleared for the next heart-beat. If the timer expired with the
785 * heart-beat outstanding state set, the driver will put the HBA offline.
788 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
790 unsigned long drvr_flag;
792 spin_lock_irqsave(&phba->hbalock, drvr_flag);
793 phba->hb_outstanding = 0;
794 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
796 /* Check and reset heart-beat timer is necessary */
797 mempool_free(pmboxq, phba->mbox_mem_pool);
798 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
799 !(phba->link_state == LPFC_HBA_ERROR) &&
800 !(phba->pport->load_flag & FC_UNLOADING))
801 mod_timer(&phba->hb_tmofunc,
802 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
807 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
808 * @phba: pointer to lpfc hba data structure.
810 * This is the actual HBA-timer timeout handler to be invoked by the worker
811 * thread whenever the HBA timer fired and HBA-timeout event posted. This
812 * handler performs any periodic operations needed for the device. If such
813 * periodic event has already been attended to either in the interrupt handler
814 * or by processing slow-ring or fast-ring events within the HBA-timer
815 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
816 * the timer for the next timeout period. If lpfc heart-beat mailbox command
817 * is configured and there is no heart-beat mailbox command outstanding, a
818 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
819 * has been a heart-beat mailbox command outstanding, the HBA shall be put
823 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
825 LPFC_MBOXQ_t *pmboxq;
826 struct lpfc_dmabuf *buf_ptr;
828 struct lpfc_sli *psli = &phba->sli;
829 LIST_HEAD(completions);
831 if ((phba->link_state == LPFC_HBA_ERROR) ||
832 (phba->pport->load_flag & FC_UNLOADING) ||
833 (phba->pport->fc_flag & FC_OFFLINE_MODE))
836 spin_lock_irq(&phba->pport->work_port_lock);
838 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
840 spin_unlock_irq(&phba->pport->work_port_lock);
841 if (!phba->hb_outstanding)
842 mod_timer(&phba->hb_tmofunc,
843 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
845 mod_timer(&phba->hb_tmofunc,
846 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
849 spin_unlock_irq(&phba->pport->work_port_lock);
851 if (phba->elsbuf_cnt &&
852 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
853 spin_lock_irq(&phba->hbalock);
854 list_splice_init(&phba->elsbuf, &completions);
855 phba->elsbuf_cnt = 0;
856 phba->elsbuf_prev_cnt = 0;
857 spin_unlock_irq(&phba->hbalock);
859 while (!list_empty(&completions)) {
860 list_remove_head(&completions, buf_ptr,
861 struct lpfc_dmabuf, list);
862 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
866 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
868 /* If there is no heart beat outstanding, issue a heartbeat command */
869 if (phba->cfg_enable_hba_heartbeat) {
870 if (!phba->hb_outstanding) {
871 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
873 mod_timer(&phba->hb_tmofunc,
874 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
878 lpfc_heart_beat(phba, pmboxq);
879 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
880 pmboxq->vport = phba->pport;
881 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
883 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
884 mempool_free(pmboxq, phba->mbox_mem_pool);
885 mod_timer(&phba->hb_tmofunc,
886 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
889 mod_timer(&phba->hb_tmofunc,
890 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
891 phba->hb_outstanding = 1;
895 * If heart beat timeout called with hb_outstanding set
896 * we need to take the HBA offline.
898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
899 "0459 Adapter heartbeat failure, "
900 "taking this port offline.\n");
902 spin_lock_irq(&phba->hbalock);
903 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
904 spin_unlock_irq(&phba->hbalock);
906 lpfc_offline_prep(phba);
908 lpfc_unblock_mgmt_io(phba);
909 phba->link_state = LPFC_HBA_ERROR;
910 lpfc_hba_down_post(phba);
916 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
917 * @phba: pointer to lpfc hba data structure.
919 * This routine is called to bring the HBA offline when HBA hardware error
920 * other than Port Error 6 has been detected.
923 lpfc_offline_eratt(struct lpfc_hba *phba)
925 struct lpfc_sli *psli = &phba->sli;
927 spin_lock_irq(&phba->hbalock);
928 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
929 spin_unlock_irq(&phba->hbalock);
930 lpfc_offline_prep(phba);
933 lpfc_reset_barrier(phba);
934 lpfc_sli_brdreset(phba);
935 lpfc_hba_down_post(phba);
936 lpfc_sli_brdready(phba, HS_MBRDY);
937 lpfc_unblock_mgmt_io(phba);
938 phba->link_state = LPFC_HBA_ERROR;
943 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
944 * @phba: pointer to lpfc hba data structure.
946 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
947 * other than Port Error 6 has been detected.
950 lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
952 lpfc_offline_prep(phba);
954 lpfc_sli4_brdreset(phba);
955 lpfc_hba_down_post(phba);
956 lpfc_sli4_post_status_check(phba);
957 lpfc_unblock_mgmt_io(phba);
958 phba->link_state = LPFC_HBA_ERROR;
962 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
963 * @phba: pointer to lpfc hba data structure.
965 * This routine is invoked to handle the deferred HBA hardware error
966 * conditions. This type of error is indicated by HBA by setting ER1
967 * and another ER bit in the host status register. The driver will
968 * wait until the ER1 bit clears before handling the error condition.
971 lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
973 uint32_t old_host_status = phba->work_hs;
974 struct lpfc_sli_ring *pring;
975 struct lpfc_sli *psli = &phba->sli;
977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
978 "0479 Deferred Adapter Hardware Error "
979 "Data: x%x x%x x%x\n",
981 phba->work_status[0], phba->work_status[1]);
983 spin_lock_irq(&phba->hbalock);
984 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
985 spin_unlock_irq(&phba->hbalock);
989 * Firmware stops when it triggred erratt. That could cause the I/Os
990 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
991 * SCSI layer retry it after re-establishing link.
993 pring = &psli->ring[psli->fcp_ring];
994 lpfc_sli_abort_iocb_ring(phba, pring);
997 * There was a firmware error. Take the hba offline and then
998 * attempt to restart it.
1000 lpfc_offline_prep(phba);
1003 /* Wait for the ER1 bit to clear.*/
1004 while (phba->work_hs & HS_FFER1) {
1006 phba->work_hs = readl(phba->HSregaddr);
1007 /* If driver is unloading let the worker thread continue */
1008 if (phba->pport->load_flag & FC_UNLOADING) {
1015 * This is to ptrotect against a race condition in which
1016 * first write to the host attention register clear the
1017 * host status register.
1019 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1020 phba->work_hs = old_host_status & ~HS_FFER1;
1022 spin_lock_irq(&phba->hbalock);
1023 phba->hba_flag &= ~DEFER_ERATT;
1024 spin_unlock_irq(&phba->hbalock);
1025 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1026 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1030 lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1032 struct lpfc_board_event_header board_event;
1033 struct Scsi_Host *shost;
1035 board_event.event_type = FC_REG_BOARD_EVENT;
1036 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1037 shost = lpfc_shost_from_vport(phba->pport);
1038 fc_host_post_vendor_event(shost, fc_get_event_number(),
1039 sizeof(board_event),
1040 (char *) &board_event,
1045 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1046 * @phba: pointer to lpfc hba data structure.
1048 * This routine is invoked to handle the following HBA hardware error
1050 * 1 - HBA error attention interrupt
1051 * 2 - DMA ring index out of range
1052 * 3 - Mailbox command came back as unknown
1055 lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1057 struct lpfc_vport *vport = phba->pport;
1058 struct lpfc_sli *psli = &phba->sli;
1059 struct lpfc_sli_ring *pring;
1060 uint32_t event_data;
1061 unsigned long temperature;
1062 struct temp_event temp_event_data;
1063 struct Scsi_Host *shost;
1065 /* If the pci channel is offline, ignore possible errors,
1066 * since we cannot communicate with the pci card anyway.
1068 if (pci_channel_offline(phba->pcidev)) {
1069 spin_lock_irq(&phba->hbalock);
1070 phba->hba_flag &= ~DEFER_ERATT;
1071 spin_unlock_irq(&phba->hbalock);
1075 /* If resets are disabled then leave the HBA alone and return */
1076 if (!phba->cfg_enable_hba_reset)
1079 /* Send an internal error event to mgmt application */
1080 lpfc_board_errevt_to_mgmt(phba);
1082 if (phba->hba_flag & DEFER_ERATT)
1083 lpfc_handle_deferred_eratt(phba);
1085 if (phba->work_hs & HS_FFER6) {
1086 /* Re-establishing Link */
1087 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1088 "1301 Re-establishing Link "
1089 "Data: x%x x%x x%x\n",
1091 phba->work_status[0], phba->work_status[1]);
1093 spin_lock_irq(&phba->hbalock);
1094 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1095 spin_unlock_irq(&phba->hbalock);
1098 * Firmware stops when it triggled erratt with HS_FFER6.
1099 * That could cause the I/Os dropped by the firmware.
1100 * Error iocb (I/O) on txcmplq and let the SCSI layer
1101 * retry it after re-establishing link.
1103 pring = &psli->ring[psli->fcp_ring];
1104 lpfc_sli_abort_iocb_ring(phba, pring);
1107 * There was a firmware error. Take the hba offline and then
1108 * attempt to restart it.
1110 lpfc_offline_prep(phba);
1112 lpfc_sli_brdrestart(phba);
1113 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
1114 lpfc_unblock_mgmt_io(phba);
1117 lpfc_unblock_mgmt_io(phba);
1118 } else if (phba->work_hs & HS_CRIT_TEMP) {
1119 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1120 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1121 temp_event_data.event_code = LPFC_CRIT_TEMP;
1122 temp_event_data.data = (uint32_t)temperature;
1124 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1125 "0406 Adapter maximum temperature exceeded "
1126 "(%ld), taking this port offline "
1127 "Data: x%x x%x x%x\n",
1128 temperature, phba->work_hs,
1129 phba->work_status[0], phba->work_status[1]);
1131 shost = lpfc_shost_from_vport(phba->pport);
1132 fc_host_post_vendor_event(shost, fc_get_event_number(),
1133 sizeof(temp_event_data),
1134 (char *) &temp_event_data,
1135 SCSI_NL_VID_TYPE_PCI
1136 | PCI_VENDOR_ID_EMULEX);
1138 spin_lock_irq(&phba->hbalock);
1139 phba->over_temp_state = HBA_OVER_TEMP;
1140 spin_unlock_irq(&phba->hbalock);
1141 lpfc_offline_eratt(phba);
1144 /* The if clause above forces this code path when the status
1145 * failure is a value other than FFER6. Do not call the offline
1146 * twice. This is the adapter hardware error path.
1148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1149 "0457 Adapter Hardware Error "
1150 "Data: x%x x%x x%x\n",
1152 phba->work_status[0], phba->work_status[1]);
1154 event_data = FC_REG_DUMP_EVENT;
1155 shost = lpfc_shost_from_vport(vport);
1156 fc_host_post_vendor_event(shost, fc_get_event_number(),
1157 sizeof(event_data), (char *) &event_data,
1158 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1160 lpfc_offline_eratt(phba);
1166 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1167 * @phba: pointer to lpfc hba data structure.
1169 * This routine is invoked to handle the SLI4 HBA hardware error attention
1173 lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1175 struct lpfc_vport *vport = phba->pport;
1176 uint32_t event_data;
1177 struct Scsi_Host *shost;
1179 /* If the pci channel is offline, ignore possible errors, since
1180 * we cannot communicate with the pci card anyway.
1182 if (pci_channel_offline(phba->pcidev))
1184 /* If resets are disabled then leave the HBA alone and return */
1185 if (!phba->cfg_enable_hba_reset)
1188 /* Send an internal error event to mgmt application */
1189 lpfc_board_errevt_to_mgmt(phba);
1191 /* For now, the actual action for SLI4 device handling is not
1192 * specified yet, just treated it as adaptor hardware failure
1194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1195 "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
1196 phba->work_status[0], phba->work_status[1]);
1198 event_data = FC_REG_DUMP_EVENT;
1199 shost = lpfc_shost_from_vport(vport);
1200 fc_host_post_vendor_event(shost, fc_get_event_number(),
1201 sizeof(event_data), (char *) &event_data,
1202 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1204 lpfc_sli4_offline_eratt(phba);
1208 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1209 * @phba: pointer to lpfc HBA data structure.
1211 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1212 * routine from the API jump table function pointer from the lpfc_hba struct.
1216 * Any other value - error.
1219 lpfc_handle_eratt(struct lpfc_hba *phba)
1221 (*phba->lpfc_handle_eratt)(phba);
1225 * lpfc_handle_latt - The HBA link event handler
1226 * @phba: pointer to lpfc hba data structure.
1228 * This routine is invoked from the worker thread to handle a HBA host
1229 * attention link event.
1232 lpfc_handle_latt(struct lpfc_hba *phba)
1234 struct lpfc_vport *vport = phba->pport;
1235 struct lpfc_sli *psli = &phba->sli;
1237 volatile uint32_t control;
1238 struct lpfc_dmabuf *mp;
1241 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1244 goto lpfc_handle_latt_err_exit;
1247 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1250 goto lpfc_handle_latt_free_pmb;
1253 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1256 goto lpfc_handle_latt_free_mp;
1259 /* Cleanup any outstanding ELS commands */
1260 lpfc_els_flush_all_cmd(phba);
1262 psli->slistat.link_event++;
1263 lpfc_read_la(phba, pmb, mp);
1264 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
1266 /* Block ELS IOCBs until we have processed this mbox command */
1267 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
1268 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
1269 if (rc == MBX_NOT_FINISHED) {
1271 goto lpfc_handle_latt_free_mbuf;
1274 /* Clear Link Attention in HA REG */
1275 spin_lock_irq(&phba->hbalock);
1276 writel(HA_LATT, phba->HAregaddr);
1277 readl(phba->HAregaddr); /* flush */
1278 spin_unlock_irq(&phba->hbalock);
1282 lpfc_handle_latt_free_mbuf:
1283 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1284 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1285 lpfc_handle_latt_free_mp:
1287 lpfc_handle_latt_free_pmb:
1288 mempool_free(pmb, phba->mbox_mem_pool);
1289 lpfc_handle_latt_err_exit:
1290 /* Enable Link attention interrupts */
1291 spin_lock_irq(&phba->hbalock);
1292 psli->sli_flag |= LPFC_PROCESS_LA;
1293 control = readl(phba->HCregaddr);
1294 control |= HC_LAINT_ENA;
1295 writel(control, phba->HCregaddr);
1296 readl(phba->HCregaddr); /* flush */
1298 /* Clear Link Attention in HA REG */
1299 writel(HA_LATT, phba->HAregaddr);
1300 readl(phba->HAregaddr); /* flush */
1301 spin_unlock_irq(&phba->hbalock);
1302 lpfc_linkdown(phba);
1303 phba->link_state = LPFC_HBA_ERROR;
1305 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1306 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
1312 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1313 * @phba: pointer to lpfc hba data structure.
1314 * @vpd: pointer to the vital product data.
1315 * @len: length of the vital product data in bytes.
1317 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1318 * an array of characters. In this routine, the ModelName, ProgramType, and
1319 * ModelDesc, etc. fields of the phba data structure will be populated.
1322 * 0 - pointer to the VPD passed in is NULL
1326 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
1328 uint8_t lenlo, lenhi;
1338 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1339 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1340 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1342 while (!finished && (index < (len - 4))) {
1343 switch (vpd[index]) {
1351 i = ((((unsigned short)lenhi) << 8) + lenlo);
1360 Length = ((((unsigned short)lenhi) << 8) + lenlo);
1361 if (Length > len - index)
1362 Length = len - index;
1363 while (Length > 0) {
1364 /* Look for Serial Number */
1365 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1372 phba->SerialNumber[j++] = vpd[index++];
1376 phba->SerialNumber[j] = 0;
1379 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1380 phba->vpd_flag |= VPD_MODEL_DESC;
1387 phba->ModelDesc[j++] = vpd[index++];
1391 phba->ModelDesc[j] = 0;
1394 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1395 phba->vpd_flag |= VPD_MODEL_NAME;
1402 phba->ModelName[j++] = vpd[index++];
1406 phba->ModelName[j] = 0;
1409 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1410 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1417 phba->ProgramType[j++] = vpd[index++];
1421 phba->ProgramType[j] = 0;
1424 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1425 phba->vpd_flag |= VPD_PORT;
1432 phba->Port[j++] = vpd[index++];
1462 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1463 * @phba: pointer to lpfc hba data structure.
1464 * @mdp: pointer to the data structure to hold the derived model name.
1465 * @descp: pointer to the data structure to hold the derived description.
1467 * This routine retrieves HBA's description based on its registered PCI device
1468 * ID. The @descp passed into this function points to an array of 256 chars. It
1469 * shall be returned with the model name, maximum speed, and the host bus type.
1470 * The @mdp passed into this function points to an array of 80 chars. When the
1471 * function returns, the @mdp will be filled with the model name.
1474 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1477 uint16_t dev_id = phba->pcidev->device;
1480 int oneConnect = 0; /* default is not a oneConnect */
1485 } m = {"<Unknown>", 0, ""};
1487 if (mdp && mdp[0] != '\0'
1488 && descp && descp[0] != '\0')
1491 if (phba->lmt & LMT_10Gb)
1493 else if (phba->lmt & LMT_8Gb)
1495 else if (phba->lmt & LMT_4Gb)
1497 else if (phba->lmt & LMT_2Gb)
1505 case PCI_DEVICE_ID_FIREFLY:
1506 m = (typeof(m)){"LP6000", max_speed, "PCI"};
1508 case PCI_DEVICE_ID_SUPERFLY:
1509 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1510 m = (typeof(m)){"LP7000", max_speed, "PCI"};
1512 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
1514 case PCI_DEVICE_ID_DRAGONFLY:
1515 m = (typeof(m)){"LP8000", max_speed, "PCI"};
1517 case PCI_DEVICE_ID_CENTAUR:
1518 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1519 m = (typeof(m)){"LP9002", max_speed, "PCI"};
1521 m = (typeof(m)){"LP9000", max_speed, "PCI"};
1523 case PCI_DEVICE_ID_RFLY:
1524 m = (typeof(m)){"LP952", max_speed, "PCI"};
1526 case PCI_DEVICE_ID_PEGASUS:
1527 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
1529 case PCI_DEVICE_ID_THOR:
1530 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
1532 case PCI_DEVICE_ID_VIPER:
1533 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
1535 case PCI_DEVICE_ID_PFLY:
1536 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
1538 case PCI_DEVICE_ID_TFLY:
1539 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
1541 case PCI_DEVICE_ID_HELIOS:
1542 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
1544 case PCI_DEVICE_ID_HELIOS_SCSP:
1545 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
1547 case PCI_DEVICE_ID_HELIOS_DCSP:
1548 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
1550 case PCI_DEVICE_ID_NEPTUNE:
1551 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
1553 case PCI_DEVICE_ID_NEPTUNE_SCSP:
1554 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
1556 case PCI_DEVICE_ID_NEPTUNE_DCSP:
1557 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
1559 case PCI_DEVICE_ID_BMID:
1560 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
1562 case PCI_DEVICE_ID_BSMB:
1563 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
1565 case PCI_DEVICE_ID_ZEPHYR:
1566 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1568 case PCI_DEVICE_ID_ZEPHYR_SCSP:
1569 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1571 case PCI_DEVICE_ID_ZEPHYR_DCSP:
1572 m = (typeof(m)){"LP2105", max_speed, "PCIe"};
1575 case PCI_DEVICE_ID_ZMID:
1576 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
1578 case PCI_DEVICE_ID_ZSMB:
1579 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
1581 case PCI_DEVICE_ID_LP101:
1582 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
1584 case PCI_DEVICE_ID_LP10000S:
1585 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
1587 case PCI_DEVICE_ID_LP11000S:
1588 m = (typeof(m)){"LP11000-S", max_speed,
1591 case PCI_DEVICE_ID_LPE11000S:
1592 m = (typeof(m)){"LPe11000-S", max_speed,
1595 case PCI_DEVICE_ID_SAT:
1596 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1598 case PCI_DEVICE_ID_SAT_MID:
1599 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1601 case PCI_DEVICE_ID_SAT_SMB:
1602 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1604 case PCI_DEVICE_ID_SAT_DCSP:
1605 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1607 case PCI_DEVICE_ID_SAT_SCSP:
1608 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1610 case PCI_DEVICE_ID_SAT_S:
1611 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1613 case PCI_DEVICE_ID_HORNET:
1614 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1617 case PCI_DEVICE_ID_PROTEUS_VF:
1618 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1620 case PCI_DEVICE_ID_PROTEUS_PF:
1621 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1623 case PCI_DEVICE_ID_PROTEUS_S:
1624 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1626 case PCI_DEVICE_ID_TIGERSHARK:
1628 m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"};
1630 case PCI_DEVICE_ID_TIGERSHARK_S:
1632 m = (typeof(m)) {"OCe10100-F-S", max_speed, "PCIe"};
1635 m = (typeof(m)){ NULL };
1639 if (mdp && mdp[0] == '\0')
1640 snprintf(mdp, 79,"%s", m.name);
1641 /* oneConnect hba requires special processing, they are all initiators
1642 * and we put the port number on the end
1644 if (descp && descp[0] == '\0') {
1646 snprintf(descp, 255,
1647 "Emulex OneConnect %s, FCoE Initiator, Port %s",
1651 snprintf(descp, 255,
1652 "Emulex %s %d%s %s %s",
1653 m.name, m.max_speed,
1656 (GE) ? "FCoE Adapter" :
1657 "Fibre Channel Adapter");
1662 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
1663 * @phba: pointer to lpfc hba data structure.
1664 * @pring: pointer to a IOCB ring.
1665 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1667 * This routine posts a given number of IOCBs with the associated DMA buffer
1668 * descriptors specified by the cnt argument to the given IOCB ring.
1671 * The number of IOCBs NOT able to be posted to the IOCB ring.
1674 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1677 struct lpfc_iocbq *iocb;
1678 struct lpfc_dmabuf *mp1, *mp2;
1680 cnt += pring->missbufcnt;
1682 /* While there are buffers to post */
1684 /* Allocate buffer for command iocb */
1685 iocb = lpfc_sli_get_iocbq(phba);
1687 pring->missbufcnt = cnt;
1692 /* 2 buffers can be posted per command */
1693 /* Allocate buffer to post */
1694 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1696 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1697 if (!mp1 || !mp1->virt) {
1699 lpfc_sli_release_iocbq(phba, iocb);
1700 pring->missbufcnt = cnt;
1704 INIT_LIST_HEAD(&mp1->list);
1705 /* Allocate buffer to post */
1707 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1709 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1711 if (!mp2 || !mp2->virt) {
1713 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1715 lpfc_sli_release_iocbq(phba, iocb);
1716 pring->missbufcnt = cnt;
1720 INIT_LIST_HEAD(&mp2->list);
1725 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1726 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1727 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1728 icmd->ulpBdeCount = 1;
1731 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1732 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1733 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1735 icmd->ulpBdeCount = 2;
1738 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1741 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
1743 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1747 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1751 lpfc_sli_release_iocbq(phba, iocb);
1752 pring->missbufcnt = cnt;
1755 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1757 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1759 pring->missbufcnt = 0;
1764 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
1765 * @phba: pointer to lpfc hba data structure.
1767 * This routine posts initial receive IOCB buffers to the ELS ring. The
1768 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1772 * 0 - success (currently always success)
1775 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1777 struct lpfc_sli *psli = &phba->sli;
1779 /* Ring 0, ELS / CT buffers */
1780 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
1781 /* Ring 2 - FCP no buffers needed */
1786 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1789 * lpfc_sha_init - Set up initial array of hash table entries
1790 * @HashResultPointer: pointer to an array as hash table.
1792 * This routine sets up the initial values to the array of hash table entries
1796 lpfc_sha_init(uint32_t * HashResultPointer)
1798 HashResultPointer[0] = 0x67452301;
1799 HashResultPointer[1] = 0xEFCDAB89;
1800 HashResultPointer[2] = 0x98BADCFE;
1801 HashResultPointer[3] = 0x10325476;
1802 HashResultPointer[4] = 0xC3D2E1F0;
1806 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
1807 * @HashResultPointer: pointer to an initial/result hash table.
1808 * @HashWorkingPointer: pointer to an working hash table.
1810 * This routine iterates an initial hash table pointed by @HashResultPointer
1811 * with the values from the working hash table pointeed by @HashWorkingPointer.
1812 * The results are putting back to the initial hash table, returned through
1813 * the @HashResultPointer as the result hash table.
1816 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1820 uint32_t A, B, C, D, E;
1823 HashWorkingPointer[t] =
1825 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1827 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1828 } while (++t <= 79);
1830 A = HashResultPointer[0];
1831 B = HashResultPointer[1];
1832 C = HashResultPointer[2];
1833 D = HashResultPointer[3];
1834 E = HashResultPointer[4];
1838 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1839 } else if (t < 40) {
1840 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1841 } else if (t < 60) {
1842 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1844 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1846 TEMP += S(5, A) + E + HashWorkingPointer[t];
1852 } while (++t <= 79);
1854 HashResultPointer[0] += A;
1855 HashResultPointer[1] += B;
1856 HashResultPointer[2] += C;
1857 HashResultPointer[3] += D;
1858 HashResultPointer[4] += E;
1863 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
1864 * @RandomChallenge: pointer to the entry of host challenge random number array.
1865 * @HashWorking: pointer to the entry of the working hash array.
1867 * This routine calculates the working hash array referred by @HashWorking
1868 * from the challenge random numbers associated with the host, referred by
1869 * @RandomChallenge. The result is put into the entry of the working hash
1870 * array and returned by reference through @HashWorking.
1873 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1875 *HashWorking = (*RandomChallenge ^ *HashWorking);
1879 * lpfc_hba_init - Perform special handling for LC HBA initialization
1880 * @phba: pointer to lpfc hba data structure.
1881 * @hbainit: pointer to an array of unsigned 32-bit integers.
1883 * This routine performs the special handling for LC HBA initialization.
1886 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1889 uint32_t *HashWorking;
1890 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1892 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
1896 HashWorking[0] = HashWorking[78] = *pwwnn++;
1897 HashWorking[1] = HashWorking[79] = *pwwnn;
1899 for (t = 0; t < 7; t++)
1900 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1902 lpfc_sha_init(hbainit);
1903 lpfc_sha_iterate(hbainit, HashWorking);
1908 * lpfc_cleanup - Performs vport cleanups before deleting a vport
1909 * @vport: pointer to a virtual N_Port data structure.
1911 * This routine performs the necessary cleanups before deleting the @vport.
1912 * It invokes the discovery state machine to perform necessary state
1913 * transitions and to release the ndlps associated with the @vport. Note,
1914 * the physical port is treated as @vport 0.
1917 lpfc_cleanup(struct lpfc_vport *vport)
1919 struct lpfc_hba *phba = vport->phba;
1920 struct lpfc_nodelist *ndlp, *next_ndlp;
1923 if (phba->link_state > LPFC_LINK_DOWN)
1924 lpfc_port_link_failure(vport);
1926 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1927 if (!NLP_CHK_NODE_ACT(ndlp)) {
1928 ndlp = lpfc_enable_node(vport, ndlp,
1929 NLP_STE_UNUSED_NODE);
1932 spin_lock_irq(&phba->ndlp_lock);
1933 NLP_SET_FREE_REQ(ndlp);
1934 spin_unlock_irq(&phba->ndlp_lock);
1935 /* Trigger the release of the ndlp memory */
1939 spin_lock_irq(&phba->ndlp_lock);
1940 if (NLP_CHK_FREE_REQ(ndlp)) {
1941 /* The ndlp should not be in memory free mode already */
1942 spin_unlock_irq(&phba->ndlp_lock);
1945 /* Indicate request for freeing ndlp memory */
1946 NLP_SET_FREE_REQ(ndlp);
1947 spin_unlock_irq(&phba->ndlp_lock);
1949 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1950 ndlp->nlp_DID == Fabric_DID) {
1951 /* Just free up ndlp with Fabric_DID for vports */
1956 if (ndlp->nlp_type & NLP_FABRIC)
1957 lpfc_disc_state_machine(vport, ndlp, NULL,
1958 NLP_EVT_DEVICE_RECOVERY);
1960 lpfc_disc_state_machine(vport, ndlp, NULL,
1965 /* At this point, ALL ndlp's should be gone
1966 * because of the previous NLP_EVT_DEVICE_RM.
1967 * Lets wait for this to happen, if needed.
1969 while (!list_empty(&vport->fc_nodes)) {
1971 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1972 "0233 Nodelist not empty\n");
1973 list_for_each_entry_safe(ndlp, next_ndlp,
1974 &vport->fc_nodes, nlp_listp) {
1975 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1977 "0282 did:x%x ndlp:x%p "
1978 "usgmap:x%x refcnt:%d\n",
1979 ndlp->nlp_DID, (void *)ndlp,
1982 &ndlp->kref.refcount));
1987 /* Wait for any activity on ndlps to settle */
1993 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
1994 * @vport: pointer to a virtual N_Port data structure.
1996 * This routine stops all the timers associated with a @vport. This function
1997 * is invoked before disabling or deleting a @vport. Note that the physical
1998 * port is treated as @vport 0.
2001 lpfc_stop_vport_timers(struct lpfc_vport *vport)
2003 del_timer_sync(&vport->els_tmofunc);
2004 del_timer_sync(&vport->fc_fdmitmo);
2005 lpfc_can_disctmo(vport);
2010 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2011 * @phba: pointer to lpfc hba data structure.
2013 * This routine stops all the timers associated with a HBA. This function is
2014 * invoked before either putting a HBA offline or unloading the driver.
2017 lpfc_stop_hba_timers(struct lpfc_hba *phba)
2019 lpfc_stop_vport_timers(phba->pport);
2020 del_timer_sync(&phba->sli.mbox_tmo);
2021 del_timer_sync(&phba->fabric_block_timer);
2022 del_timer_sync(&phba->eratt_poll);
2023 del_timer_sync(&phba->hb_tmofunc);
2024 phba->hb_outstanding = 0;
2026 switch (phba->pci_dev_grp) {
2027 case LPFC_PCI_DEV_LP:
2028 /* Stop any LightPulse device specific driver timers */
2029 del_timer_sync(&phba->fcp_poll_timer);
2031 case LPFC_PCI_DEV_OC:
2032 /* Stop any OneConnect device sepcific driver timers */
2035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2036 "0297 Invalid device group (x%x)\n",
2044 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2045 * @phba: pointer to lpfc hba data structure.
2047 * This routine marks a HBA's management interface as blocked. Once the HBA's
2048 * management interface is marked as blocked, all the user space access to
2049 * the HBA, whether they are from sysfs interface or libdfc interface will
2050 * all be blocked. The HBA is set to block the management interface when the
2051 * driver prepares the HBA interface for online or offline.
2054 lpfc_block_mgmt_io(struct lpfc_hba * phba)
2056 unsigned long iflag;
2058 spin_lock_irqsave(&phba->hbalock, iflag);
2059 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2060 spin_unlock_irqrestore(&phba->hbalock, iflag);
2064 * lpfc_online - Initialize and bring a HBA online
2065 * @phba: pointer to lpfc hba data structure.
2067 * This routine initializes the HBA and brings a HBA online. During this
2068 * process, the management interface is blocked to prevent user space access
2069 * to the HBA interfering with the driver initialization.
2076 lpfc_online(struct lpfc_hba *phba)
2078 struct lpfc_vport *vport;
2079 struct lpfc_vport **vports;
2084 vport = phba->pport;
2086 if (!(vport->fc_flag & FC_OFFLINE_MODE))
2089 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2090 "0458 Bring Adapter online\n");
2092 lpfc_block_mgmt_io(phba);
2094 if (!lpfc_sli_queue_setup(phba)) {
2095 lpfc_unblock_mgmt_io(phba);
2099 if (phba->sli_rev == LPFC_SLI_REV4) {
2100 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2101 lpfc_unblock_mgmt_io(phba);
2105 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2106 lpfc_unblock_mgmt_io(phba);
2111 vports = lpfc_create_vport_work_array(phba);
2113 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2114 struct Scsi_Host *shost;
2115 shost = lpfc_shost_from_vport(vports[i]);
2116 spin_lock_irq(shost->host_lock);
2117 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2118 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2119 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2120 spin_unlock_irq(shost->host_lock);
2122 lpfc_destroy_vport_work_array(phba, vports);
2124 lpfc_unblock_mgmt_io(phba);
2129 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2130 * @phba: pointer to lpfc hba data structure.
2132 * This routine marks a HBA's management interface as not blocked. Once the
2133 * HBA's management interface is marked as not blocked, all the user space
2134 * access to the HBA, whether they are from sysfs interface or libdfc
2135 * interface will be allowed. The HBA is set to block the management interface
2136 * when the driver prepares the HBA interface for online or offline and then
2137 * set to unblock the management interface afterwards.
2140 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2142 unsigned long iflag;
2144 spin_lock_irqsave(&phba->hbalock, iflag);
2145 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2146 spin_unlock_irqrestore(&phba->hbalock, iflag);
2150 * lpfc_offline_prep - Prepare a HBA to be brought offline
2151 * @phba: pointer to lpfc hba data structure.
2153 * This routine is invoked to prepare a HBA to be brought offline. It performs
2154 * unregistration login to all the nodes on all vports and flushes the mailbox
2155 * queue to make it ready to be brought offline.
2158 lpfc_offline_prep(struct lpfc_hba * phba)
2160 struct lpfc_vport *vport = phba->pport;
2161 struct lpfc_nodelist *ndlp, *next_ndlp;
2162 struct lpfc_vport **vports;
2165 if (vport->fc_flag & FC_OFFLINE_MODE)
2168 lpfc_block_mgmt_io(phba);
2170 lpfc_linkdown(phba);
2172 /* Issue an unreg_login to all nodes on all vports */
2173 vports = lpfc_create_vport_work_array(phba);
2174 if (vports != NULL) {
2175 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2176 struct Scsi_Host *shost;
2178 if (vports[i]->load_flag & FC_UNLOADING)
2180 vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
2181 shost = lpfc_shost_from_vport(vports[i]);
2182 list_for_each_entry_safe(ndlp, next_ndlp,
2183 &vports[i]->fc_nodes,
2185 if (!NLP_CHK_NODE_ACT(ndlp))
2187 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2189 if (ndlp->nlp_type & NLP_FABRIC) {
2190 lpfc_disc_state_machine(vports[i], ndlp,
2191 NULL, NLP_EVT_DEVICE_RECOVERY);
2192 lpfc_disc_state_machine(vports[i], ndlp,
2193 NULL, NLP_EVT_DEVICE_RM);
2195 spin_lock_irq(shost->host_lock);
2196 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2197 spin_unlock_irq(shost->host_lock);
2198 lpfc_unreg_rpi(vports[i], ndlp);
2202 lpfc_destroy_vport_work_array(phba, vports);
2204 lpfc_sli_flush_mbox_queue(phba);
2208 * lpfc_offline - Bring a HBA offline
2209 * @phba: pointer to lpfc hba data structure.
2211 * This routine actually brings a HBA offline. It stops all the timers
2212 * associated with the HBA, brings down the SLI layer, and eventually
2213 * marks the HBA as in offline state for the upper layer protocol.
2216 lpfc_offline(struct lpfc_hba *phba)
2218 struct Scsi_Host *shost;
2219 struct lpfc_vport **vports;
2222 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2225 /* stop port and all timers associated with this hba */
2226 lpfc_stop_port(phba);
2227 vports = lpfc_create_vport_work_array(phba);
2229 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
2230 lpfc_stop_vport_timers(vports[i]);
2231 lpfc_destroy_vport_work_array(phba, vports);
2232 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2233 "0460 Bring Adapter offline\n");
2234 /* Bring down the SLI Layer and cleanup. The HBA is offline
2236 lpfc_sli_hba_down(phba);
2237 spin_lock_irq(&phba->hbalock);
2239 spin_unlock_irq(&phba->hbalock);
2240 vports = lpfc_create_vport_work_array(phba);
2242 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2243 shost = lpfc_shost_from_vport(vports[i]);
2244 spin_lock_irq(shost->host_lock);
2245 vports[i]->work_port_events = 0;
2246 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2247 spin_unlock_irq(shost->host_lock);
2249 lpfc_destroy_vport_work_array(phba, vports);
2253 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2254 * @phba: pointer to lpfc hba data structure.
2256 * This routine is to free all the SCSI buffers and IOCBs from the driver
2257 * list back to kernel. It is called from lpfc_pci_remove_one to free
2258 * the internal resources before the device is removed from the system.
2261 * 0 - successful (for now, it always returns 0)
2264 lpfc_scsi_free(struct lpfc_hba *phba)
2266 struct lpfc_scsi_buf *sb, *sb_next;
2267 struct lpfc_iocbq *io, *io_next;
2269 spin_lock_irq(&phba->hbalock);
2270 /* Release all the lpfc_scsi_bufs maintained by this host. */
2271 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2272 list_del(&sb->list);
2273 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
2276 phba->total_scsi_bufs--;
2279 /* Release all the lpfc_iocbq entries maintained by this host. */
2280 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2281 list_del(&io->list);
2283 phba->total_iocbq_bufs--;
2286 spin_unlock_irq(&phba->hbalock);
2292 * lpfc_create_port - Create an FC port
2293 * @phba: pointer to lpfc hba data structure.
2294 * @instance: a unique integer ID to this FC port.
2295 * @dev: pointer to the device data structure.
2297 * This routine creates a FC port for the upper layer protocol. The FC port
2298 * can be created on top of either a physical port or a virtual port provided
2299 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2300 * and associates the FC port created before adding the shost into the SCSI
2304 * @vport - pointer to the virtual N_Port data structure.
2305 * NULL - port create failed.
2308 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
2310 struct lpfc_vport *vport;
2311 struct Scsi_Host *shost;
2314 if (dev != &phba->pcidev->dev)
2315 shost = scsi_host_alloc(&lpfc_vport_template,
2316 sizeof(struct lpfc_vport));
2318 shost = scsi_host_alloc(&lpfc_template,
2319 sizeof(struct lpfc_vport));
2323 vport = (struct lpfc_vport *) shost->hostdata;
2325 vport->load_flag |= FC_LOADING;
2326 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2327 vport->fc_rscn_flush = 0;
2329 lpfc_get_vport_cfgparam(vport);
2330 shost->unique_id = instance;
2331 shost->max_id = LPFC_MAX_TARGET;
2332 shost->max_lun = vport->cfg_max_luns;
2333 shost->this_id = -1;
2334 shost->max_cmd_len = 16;
2335 if (phba->sli_rev == LPFC_SLI_REV4) {
2336 shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
2337 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2341 * Set initial can_queue value since 0 is no longer supported and
2342 * scsi_add_host will fail. This will be adjusted later based on the
2343 * max xri value determined in hba setup.
2345 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2346 if (dev != &phba->pcidev->dev) {
2347 shost->transportt = lpfc_vport_transport_template;
2348 vport->port_type = LPFC_NPIV_PORT;
2350 shost->transportt = lpfc_transport_template;
2351 vport->port_type = LPFC_PHYSICAL_PORT;
2354 /* Initialize all internally managed lists. */
2355 INIT_LIST_HEAD(&vport->fc_nodes);
2356 INIT_LIST_HEAD(&vport->rcv_buffer_list);
2357 spin_lock_init(&vport->work_port_lock);
2359 init_timer(&vport->fc_disctmo);
2360 vport->fc_disctmo.function = lpfc_disc_timeout;
2361 vport->fc_disctmo.data = (unsigned long)vport;
2363 init_timer(&vport->fc_fdmitmo);
2364 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
2365 vport->fc_fdmitmo.data = (unsigned long)vport;
2367 init_timer(&vport->els_tmofunc);
2368 vport->els_tmofunc.function = lpfc_els_timeout;
2369 vport->els_tmofunc.data = (unsigned long)vport;
2371 error = scsi_add_host(shost, dev);
2375 spin_lock_irq(&phba->hbalock);
2376 list_add_tail(&vport->listentry, &phba->port_list);
2377 spin_unlock_irq(&phba->hbalock);
2381 scsi_host_put(shost);
2387 * destroy_port - destroy an FC port
2388 * @vport: pointer to an lpfc virtual N_Port data structure.
2390 * This routine destroys a FC port from the upper layer protocol. All the
2391 * resources associated with the port are released.
2394 destroy_port(struct lpfc_vport *vport)
2396 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2397 struct lpfc_hba *phba = vport->phba;
2399 lpfc_debugfs_terminate(vport);
2400 fc_remove_host(shost);
2401 scsi_remove_host(shost);
2403 spin_lock_irq(&phba->hbalock);
2404 list_del_init(&vport->listentry);
2405 spin_unlock_irq(&phba->hbalock);
2407 lpfc_cleanup(vport);
2412 * lpfc_get_instance - Get a unique integer ID
2414 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2415 * uses the kernel idr facility to perform the task.
2418 * instance - a unique integer ID allocated as the new instance.
2419 * -1 - lpfc get instance failed.
2422 lpfc_get_instance(void)
2426 /* Assign an unused number */
2427 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2429 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2435 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
2436 * @shost: pointer to SCSI host data structure.
2437 * @time: elapsed time of the scan in jiffies.
2439 * This routine is called by the SCSI layer with a SCSI host to determine
2440 * whether the scan host is finished.
2442 * Note: there is no scan_start function as adapter initialization will have
2443 * asynchronously kicked off the link initialization.
2446 * 0 - SCSI host scan is not over yet.
2447 * 1 - SCSI host scan is over.
2449 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2452 struct lpfc_hba *phba = vport->phba;
2455 spin_lock_irq(shost->host_lock);
2457 if (vport->load_flag & FC_UNLOADING) {
2461 if (time >= 30 * HZ) {
2462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2463 "0461 Scanning longer than 30 "
2464 "seconds. Continuing initialization\n");
2468 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2469 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2470 "0465 Link down longer than 15 "
2471 "seconds. Continuing initialization\n");
2476 if (vport->port_state != LPFC_VPORT_READY)
2478 if (vport->num_disc_nodes || vport->fc_prli_sent)
2480 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
2482 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
2488 spin_unlock_irq(shost->host_lock);
2493 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
2494 * @shost: pointer to SCSI host data structure.
2496 * This routine initializes a given SCSI host attributes on a FC port. The
2497 * SCSI host can be either on top of a physical port or a virtual port.
2499 void lpfc_host_attrib_init(struct Scsi_Host *shost)
2501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2502 struct lpfc_hba *phba = vport->phba;
2504 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
2507 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2508 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
2509 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2511 memset(fc_host_supported_fc4s(shost), 0,
2512 sizeof(fc_host_supported_fc4s(shost)));
2513 fc_host_supported_fc4s(shost)[2] = 1;
2514 fc_host_supported_fc4s(shost)[7] = 1;
2516 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2517 sizeof fc_host_symbolic_name(shost));
2519 fc_host_supported_speeds(shost) = 0;
2520 if (phba->lmt & LMT_10Gb)
2521 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
2522 if (phba->lmt & LMT_8Gb)
2523 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
2524 if (phba->lmt & LMT_4Gb)
2525 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2526 if (phba->lmt & LMT_2Gb)
2527 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2528 if (phba->lmt & LMT_1Gb)
2529 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2531 fc_host_maxframe_size(shost) =
2532 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2533 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
2535 /* This value is also unchanging */
2536 memset(fc_host_active_fc4s(shost), 0,
2537 sizeof(fc_host_active_fc4s(shost)));
2538 fc_host_active_fc4s(shost)[2] = 1;
2539 fc_host_active_fc4s(shost)[7] = 1;
2541 fc_host_max_npiv_vports(shost) = phba->max_vpi;
2542 spin_lock_irq(shost->host_lock);
2543 vport->load_flag &= ~FC_LOADING;
2544 spin_unlock_irq(shost->host_lock);
2548 * lpfc_stop_port_s3 - Stop SLI3 device port
2549 * @phba: pointer to lpfc hba data structure.
2551 * This routine is invoked to stop an SLI3 device port, it stops the device
2552 * from generating interrupts and stops the device driver's timers for the
2556 lpfc_stop_port_s3(struct lpfc_hba *phba)
2558 /* Clear all interrupt enable conditions */
2559 writel(0, phba->HCregaddr);
2560 readl(phba->HCregaddr); /* flush */
2561 /* Clear all pending interrupts */
2562 writel(0xffffffff, phba->HAregaddr);
2563 readl(phba->HAregaddr); /* flush */
2565 /* Reset some HBA SLI setup states */
2566 lpfc_stop_hba_timers(phba);
2567 phba->pport->work_port_events = 0;
2571 * lpfc_stop_port_s4 - Stop SLI4 device port
2572 * @phba: pointer to lpfc hba data structure.
2574 * This routine is invoked to stop an SLI4 device port, it stops the device
2575 * from generating interrupts and stops the device driver's timers for the
2579 lpfc_stop_port_s4(struct lpfc_hba *phba)
2581 /* Reset some HBA SLI4 setup states */
2582 lpfc_stop_hba_timers(phba);
2583 phba->pport->work_port_events = 0;
2584 phba->sli4_hba.intr_enable = 0;
2585 /* Hard clear it for now, shall have more graceful way to wait later */
2586 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2590 * lpfc_stop_port - Wrapper function for stopping hba port
2591 * @phba: Pointer to HBA context object.
2593 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
2594 * the API jump table function pointer from the lpfc_hba struct.
2597 lpfc_stop_port(struct lpfc_hba *phba)
2599 phba->lpfc_stop_port(phba);
2603 * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
2604 * @phba: pointer to lpfc hba data structure.
2606 * This routine is invoked to remove the driver default fcf record from
2607 * the port. This routine currently acts on FCF Index 0.
2611 lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
2614 LPFC_MBOXQ_t *mboxq;
2615 struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
2616 uint32_t mbox_tmo, req_len;
2617 uint32_t shdr_status, shdr_add_status;
2619 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2622 "2020 Failed to allocate mbox for ADD_FCF cmd\n");
2626 req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
2627 sizeof(struct lpfc_sli4_cfg_mhdr);
2628 rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2629 LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
2630 req_len, LPFC_SLI4_MBX_EMBED);
2632 * In phase 1, there is a single FCF index, 0. In phase2, the driver
2633 * supports multiple FCF indices.
2635 del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
2636 bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
2637 bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
2638 phba->fcf.fcf_indx);
2640 if (!phba->sli4_hba.intr_enable)
2641 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
2643 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
2644 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
2646 /* The IOCTL status is embedded in the mailbox subheader. */
2647 shdr_status = bf_get(lpfc_mbox_hdr_status,
2648 &del_fcf_record->header.cfg_shdr.response);
2649 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
2650 &del_fcf_record->header.cfg_shdr.response);
2651 if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
2652 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2653 "2516 DEL FCF of default FCF Index failed "
2654 "mbx status x%x, status x%x add_status x%x\n",
2655 rc, shdr_status, shdr_add_status);
2657 if (rc != MBX_TIMEOUT)
2658 mempool_free(mboxq, phba->mbox_mem_pool);
2662 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
2663 * @phba: pointer to lpfc hba data structure.
2664 * @acqe_link: pointer to the async link completion queue entry.
2666 * This routine is to parse the SLI4 link-attention link fault code and
2667 * translate it into the base driver's read link attention mailbox command
2670 * Return: Link-attention status in terms of base driver's coding.
2673 lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
2674 struct lpfc_acqe_link *acqe_link)
2676 uint16_t latt_fault;
2678 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
2679 case LPFC_ASYNC_LINK_FAULT_NONE:
2680 case LPFC_ASYNC_LINK_FAULT_LOCAL:
2681 case LPFC_ASYNC_LINK_FAULT_REMOTE:
2685 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2686 "0398 Invalid link fault code: x%x\n",
2687 bf_get(lpfc_acqe_link_fault, acqe_link));
2688 latt_fault = MBXERR_ERROR;
2695 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
2696 * @phba: pointer to lpfc hba data structure.
2697 * @acqe_link: pointer to the async link completion queue entry.
2699 * This routine is to parse the SLI4 link attention type and translate it
2700 * into the base driver's link attention type coding.
2702 * Return: Link attention type in terms of base driver's coding.
2705 lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
2706 struct lpfc_acqe_link *acqe_link)
2710 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
2711 case LPFC_ASYNC_LINK_STATUS_DOWN:
2712 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
2713 att_type = AT_LINK_DOWN;
2715 case LPFC_ASYNC_LINK_STATUS_UP:
2716 /* Ignore physical link up events - wait for logical link up */
2717 att_type = AT_RESERVED;
2719 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
2720 att_type = AT_LINK_UP;
2723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2724 "0399 Invalid link attention type: x%x\n",
2725 bf_get(lpfc_acqe_link_status, acqe_link));
2726 att_type = AT_RESERVED;
2733 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
2734 * @phba: pointer to lpfc hba data structure.
2735 * @acqe_link: pointer to the async link completion queue entry.
2737 * This routine is to parse the SLI4 link-attention link speed and translate
2738 * it into the base driver's link-attention link speed coding.
2740 * Return: Link-attention link speed in terms of base driver's coding.
2743 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
2744 struct lpfc_acqe_link *acqe_link)
2748 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
2749 case LPFC_ASYNC_LINK_SPEED_ZERO:
2750 link_speed = LA_UNKNW_LINK;
2752 case LPFC_ASYNC_LINK_SPEED_10MBPS:
2753 link_speed = LA_UNKNW_LINK;
2755 case LPFC_ASYNC_LINK_SPEED_100MBPS:
2756 link_speed = LA_UNKNW_LINK;
2758 case LPFC_ASYNC_LINK_SPEED_1GBPS:
2759 link_speed = LA_1GHZ_LINK;
2761 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2762 link_speed = LA_10GHZ_LINK;
2765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2766 "0483 Invalid link-attention link speed: x%x\n",
2767 bf_get(lpfc_acqe_link_speed, acqe_link));
2768 link_speed = LA_UNKNW_LINK;
2775 * lpfc_sli4_async_link_evt - Process the asynchronous link event
2776 * @phba: pointer to lpfc hba data structure.
2777 * @acqe_link: pointer to the async link completion queue entry.
2779 * This routine is to handle the SLI4 asynchronous link event.
2782 lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
2783 struct lpfc_acqe_link *acqe_link)
2785 struct lpfc_dmabuf *mp;
2791 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
2792 if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
2794 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2796 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2797 "0395 The mboxq allocation failed\n");
2800 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2802 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2803 "0396 The lpfc_dmabuf allocation failed\n");
2806 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2808 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2809 "0397 The mbuf allocation failed\n");
2810 goto out_free_dmabuf;
2813 /* Cleanup any outstanding ELS commands */
2814 lpfc_els_flush_all_cmd(phba);
2816 /* Block ELS IOCBs until we have done process link event */
2817 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2819 /* Update link event statistics */
2820 phba->sli.slistat.link_event++;
2822 /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
2823 lpfc_read_la(phba, pmb, mp);
2824 pmb->vport = phba->pport;
2826 /* Parse and translate status field */
2828 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
2830 /* Parse and translate link attention fields */
2831 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
2832 la->eventTag = acqe_link->event_tag;
2833 la->attType = att_type;
2834 la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
2836 /* Fake the the following irrelvant fields */
2837 la->topology = TOPOLOGY_PT_PT;
2838 la->granted_AL_PA = 0;
2844 /* Keep the link status for extra SLI4 state machine reference */
2845 phba->sli4_hba.link_state.speed =
2846 bf_get(lpfc_acqe_link_speed, acqe_link);
2847 phba->sli4_hba.link_state.duplex =
2848 bf_get(lpfc_acqe_link_duplex, acqe_link);
2849 phba->sli4_hba.link_state.status =
2850 bf_get(lpfc_acqe_link_status, acqe_link);
2851 phba->sli4_hba.link_state.physical =
2852 bf_get(lpfc_acqe_link_physical, acqe_link);
2853 phba->sli4_hba.link_state.fault =
2854 bf_get(lpfc_acqe_link_fault, acqe_link);
2856 /* Invoke the lpfc_handle_latt mailbox command callback function */
2857 lpfc_mbx_cmpl_read_la(phba, pmb);
2864 mempool_free(pmb, phba->mbox_mem_pool);
2868 * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
2869 * @phba: pointer to lpfc hba data structure.
2870 * @acqe_link: pointer to the async fcoe completion queue entry.
2872 * This routine is to handle the SLI4 asynchronous fcoe event.
2875 lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
2876 struct lpfc_acqe_fcoe *acqe_fcoe)
2878 uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
2881 switch (event_type) {
2882 case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
2883 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2884 "2546 New FCF found index 0x%x tag 0x%x \n",
2885 acqe_fcoe->fcf_index,
2886 acqe_fcoe->event_tag);
2888 * If the current FCF is in discovered state,
2891 spin_lock_irq(&phba->hbalock);
2892 if (phba->fcf.fcf_flag & FCF_DISCOVERED) {
2893 spin_unlock_irq(&phba->hbalock);
2896 spin_unlock_irq(&phba->hbalock);
2898 /* Read the FCF table and re-discover SAN. */
2899 rc = lpfc_sli4_read_fcf_record(phba,
2900 LPFC_FCOE_FCF_GET_FIRST);
2902 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2903 "2547 Read FCF record failed 0x%x\n",
2907 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
2908 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2909 "2548 FCF Table full count 0x%x tag 0x%x \n",
2910 bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
2911 acqe_fcoe->event_tag);
2914 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
2915 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2916 "2549 FCF disconnected fron network index 0x%x"
2917 " tag 0x%x \n", acqe_fcoe->fcf_index,
2918 acqe_fcoe->event_tag);
2919 /* If the event is not for currently used fcf do nothing */
2920 if (phba->fcf.fcf_indx != acqe_fcoe->fcf_index)
2923 * Currently, driver support only one FCF - so treat this as
2926 lpfc_linkdown(phba);
2927 /* Unregister FCF if no devices connected to it */
2928 lpfc_unregister_unused_fcf(phba);
2932 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2933 "0288 Unknown FCoE event type 0x%x event tag "
2934 "0x%x\n", event_type, acqe_fcoe->event_tag);
2940 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
2941 * @phba: pointer to lpfc hba data structure.
2942 * @acqe_link: pointer to the async dcbx completion queue entry.
2944 * This routine is to handle the SLI4 asynchronous dcbx event.
2947 lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
2948 struct lpfc_acqe_dcbx *acqe_dcbx)
2950 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2951 "0290 The SLI4 DCBX asynchronous event is not "
2956 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
2957 * @phba: pointer to lpfc hba data structure.
2959 * This routine is invoked by the worker thread to process all the pending
2960 * SLI4 asynchronous events.
2962 void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
2964 struct lpfc_cq_event *cq_event;
2966 /* First, declare the async event has been handled */
2967 spin_lock_irq(&phba->hbalock);
2968 phba->hba_flag &= ~ASYNC_EVENT;
2969 spin_unlock_irq(&phba->hbalock);
2970 /* Now, handle all the async events */
2971 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
2972 /* Get the first event from the head of the event queue */
2973 spin_lock_irq(&phba->hbalock);
2974 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
2975 cq_event, struct lpfc_cq_event, list);
2976 spin_unlock_irq(&phba->hbalock);
2977 /* Process the asynchronous event */
2978 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
2979 case LPFC_TRAILER_CODE_LINK:
2980 lpfc_sli4_async_link_evt(phba,
2981 &cq_event->cqe.acqe_link);
2983 case LPFC_TRAILER_CODE_FCOE:
2984 lpfc_sli4_async_fcoe_evt(phba,
2985 &cq_event->cqe.acqe_fcoe);
2987 case LPFC_TRAILER_CODE_DCBX:
2988 lpfc_sli4_async_dcbx_evt(phba,
2989 &cq_event->cqe.acqe_dcbx);
2992 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2993 "1804 Invalid asynchrous event code: "
2994 "x%x\n", bf_get(lpfc_trailer_code,
2995 &cq_event->cqe.mcqe_cmpl));
2998 /* Free the completion event processed to the free pool */
2999 lpfc_sli4_cq_event_release(phba, cq_event);
3004 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3005 * @phba: pointer to lpfc hba data structure.
3006 * @dev_grp: The HBA PCI-Device group number.
3008 * This routine is invoked to set up the per HBA PCI-Device group function
3009 * API jump table entries.
3011 * Return: 0 if success, otherwise -ENODEV
3014 lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
3018 /* Set up lpfc PCI-device group */
3019 phba->pci_dev_grp = dev_grp;
3021 /* The LPFC_PCI_DEV_OC uses SLI4 */
3022 if (dev_grp == LPFC_PCI_DEV_OC)
3023 phba->sli_rev = LPFC_SLI_REV4;
3025 /* Set up device INIT API function jump table */
3026 rc = lpfc_init_api_table_setup(phba, dev_grp);
3029 /* Set up SCSI API function jump table */
3030 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
3033 /* Set up SLI API function jump table */
3034 rc = lpfc_sli_api_table_setup(phba, dev_grp);
3037 /* Set up MBOX API function jump table */
3038 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
3046 * lpfc_log_intr_mode - Log the active interrupt mode
3047 * @phba: pointer to lpfc hba data structure.
3048 * @intr_mode: active interrupt mode adopted.
3050 * This routine it invoked to log the currently used active interrupt mode
3053 static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
3055 switch (intr_mode) {
3057 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3058 "0470 Enable INTx interrupt mode.\n");
3061 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3062 "0481 Enabled MSI interrupt mode.\n");
3065 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3066 "0480 Enabled MSI-X interrupt mode.\n");
3069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3070 "0482 Illegal interrupt mode.\n");
3077 * lpfc_enable_pci_dev - Enable a generic PCI device.
3078 * @phba: pointer to lpfc hba data structure.
3080 * This routine is invoked to enable the PCI device that is common to all
3085 * other values - error
3088 lpfc_enable_pci_dev(struct lpfc_hba *phba)
3090 struct pci_dev *pdev;
3093 /* Obtain PCI device reference */
3097 pdev = phba->pcidev;
3098 /* Select PCI BARs */
3099 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3100 /* Enable PCI device */
3101 if (pci_enable_device_mem(pdev))
3103 /* Request PCI resource for the device */
3104 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
3105 goto out_disable_device;
3106 /* Set up device as PCI master and save state for EEH */
3107 pci_set_master(pdev);
3108 pci_try_set_mwi(pdev);
3109 pci_save_state(pdev);
3114 pci_disable_device(pdev);
3120 * lpfc_disable_pci_dev - Disable a generic PCI device.
3121 * @phba: pointer to lpfc hba data structure.
3123 * This routine is invoked to disable the PCI device that is common to all
3127 lpfc_disable_pci_dev(struct lpfc_hba *phba)
3129 struct pci_dev *pdev;
3132 /* Obtain PCI device reference */
3136 pdev = phba->pcidev;
3137 /* Select PCI BARs */
3138 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3139 /* Release PCI resource and disable PCI device */
3140 pci_release_selected_regions(pdev, bars);
3141 pci_disable_device(pdev);
3142 /* Null out PCI private reference to driver */
3143 pci_set_drvdata(pdev, NULL);
3149 * lpfc_reset_hba - Reset a hba
3150 * @phba: pointer to lpfc hba data structure.
3152 * This routine is invoked to reset a hba device. It brings the HBA
3153 * offline, performs a board restart, and then brings the board back
3154 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
3155 * on outstanding mailbox commands.
3158 lpfc_reset_hba(struct lpfc_hba *phba)
3160 /* If resets are disabled then set error state and return. */
3161 if (!phba->cfg_enable_hba_reset) {
3162 phba->link_state = LPFC_HBA_ERROR;
3165 lpfc_offline_prep(phba);
3167 lpfc_sli_brdrestart(phba);
3169 lpfc_unblock_mgmt_io(phba);
3173 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
3174 * @phba: pointer to lpfc hba data structure.
3176 * This routine is invoked to set up the driver internal resources specific to
3177 * support the SLI-3 HBA device it attached to.
3181 * other values - error
3184 lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
3186 struct lpfc_sli *psli;
3189 * Initialize timers used by driver
3192 /* Heartbeat timer */
3193 init_timer(&phba->hb_tmofunc);
3194 phba->hb_tmofunc.function = lpfc_hb_timeout;
3195 phba->hb_tmofunc.data = (unsigned long)phba;
3198 /* MBOX heartbeat timer */
3199 init_timer(&psli->mbox_tmo);
3200 psli->mbox_tmo.function = lpfc_mbox_timeout;
3201 psli->mbox_tmo.data = (unsigned long) phba;
3202 /* FCP polling mode timer */
3203 init_timer(&phba->fcp_poll_timer);
3204 phba->fcp_poll_timer.function = lpfc_poll_timeout;
3205 phba->fcp_poll_timer.data = (unsigned long) phba;
3206 /* Fabric block timer */
3207 init_timer(&phba->fabric_block_timer);
3208 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
3209 phba->fabric_block_timer.data = (unsigned long) phba;
3210 /* EA polling mode timer */
3211 init_timer(&phba->eratt_poll);
3212 phba->eratt_poll.function = lpfc_poll_eratt;
3213 phba->eratt_poll.data = (unsigned long) phba;
3215 /* Host attention work mask setup */
3216 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
3217 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
3219 /* Get all the module params for configuring this host */
3220 lpfc_get_cfgparam(phba);
3222 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3223 * used to create the sg_dma_buf_pool must be dynamically calculated.
3224 * 2 segments are added since the IOCB needs a command and response bde.
3226 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3227 sizeof(struct fcp_rsp) +
3228 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
3230 if (phba->cfg_enable_bg) {
3231 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
3232 phba->cfg_sg_dma_buf_size +=
3233 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
3236 /* Also reinitialize the host templates with new values. */
3237 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3238 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3240 phba->max_vpi = LPFC_MAX_VPI;
3241 /* This will be set to correct value after config_port mbox */
3242 phba->max_vports = 0;
3245 * Initialize the SLI Layer to run with lpfc HBAs.
3247 lpfc_sli_setup(phba);
3248 lpfc_sli_queue_setup(phba);
3250 /* Allocate device driver memory */
3251 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
3258 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
3259 * @phba: pointer to lpfc hba data structure.
3261 * This routine is invoked to unset the driver internal resources set up
3262 * specific for supporting the SLI-3 HBA device it attached to.
3265 lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
3267 /* Free device driver memory allocated */
3268 lpfc_mem_free_all(phba);
3274 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
3275 * @phba: pointer to lpfc hba data structure.
3277 * This routine is invoked to set up the driver internal resources specific to
3278 * support the SLI-4 HBA device it attached to.
3282 * other values - error
3285 lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3287 struct lpfc_sli *psli;
3291 /* Before proceed, wait for POST done and device ready */
3292 rc = lpfc_sli4_post_status_check(phba);
3297 * Initialize timers used by driver
3300 /* Heartbeat timer */
3301 init_timer(&phba->hb_tmofunc);
3302 phba->hb_tmofunc.function = lpfc_hb_timeout;
3303 phba->hb_tmofunc.data = (unsigned long)phba;
3306 /* MBOX heartbeat timer */
3307 init_timer(&psli->mbox_tmo);
3308 psli->mbox_tmo.function = lpfc_mbox_timeout;
3309 psli->mbox_tmo.data = (unsigned long) phba;
3310 /* Fabric block timer */
3311 init_timer(&phba->fabric_block_timer);
3312 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
3313 phba->fabric_block_timer.data = (unsigned long) phba;
3314 /* EA polling mode timer */
3315 init_timer(&phba->eratt_poll);
3316 phba->eratt_poll.function = lpfc_poll_eratt;
3317 phba->eratt_poll.data = (unsigned long) phba;
3319 * We need to do a READ_CONFIG mailbox command here before
3320 * calling lpfc_get_cfgparam. For VFs this will report the
3321 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
3322 * All of the resources allocated
3323 * for this Port are tied to these values.
3325 /* Get all the module params for configuring this host */
3326 lpfc_get_cfgparam(phba);
3327 phba->max_vpi = LPFC_MAX_VPI;
3328 /* This will be set to correct value after the read_config mbox */
3329 phba->max_vports = 0;
3331 /* Program the default value of vlan_id and fc_map */
3332 phba->valid_vlan = 0;
3333 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
3334 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
3335 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
3338 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3339 * used to create the sg_dma_buf_pool must be dynamically calculated.
3340 * 2 segments are added since the IOCB needs a command and response bde.
3341 * To insure that the scsi sgl does not cross a 4k page boundary only
3342 * sgl sizes of 1k, 2k, 4k, and 8k are supported.
3343 * Table of sgl sizes and seg_cnt:
3344 * sgl size, sg_seg_cnt total seg
3349 * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
3350 * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
3351 * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
3352 * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
3354 if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
3355 phba->cfg_sg_seg_cnt = 50;
3356 else if (phba->cfg_sg_seg_cnt <= 114)
3357 phba->cfg_sg_seg_cnt = 114;
3358 else if (phba->cfg_sg_seg_cnt <= 242)
3359 phba->cfg_sg_seg_cnt = 242;
3361 phba->cfg_sg_seg_cnt = 498;
3363 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
3364 + sizeof(struct fcp_rsp);
3365 phba->cfg_sg_dma_buf_size +=
3366 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
3368 /* Initialize buffer queue management fields */
3369 hbq_count = lpfc_sli_hbq_count();
3370 for (i = 0; i < hbq_count; ++i)
3371 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
3372 INIT_LIST_HEAD(&phba->rb_pend_list);
3373 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
3374 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
3377 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
3379 /* Initialize the Abort scsi buffer list used by driver */
3380 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
3381 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
3382 /* This abort list used by worker thread */
3383 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
3386 * Initialize dirver internal slow-path work queues
3389 /* Driver internel slow-path CQ Event pool */
3390 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
3391 /* Response IOCB work queue list */
3392 INIT_LIST_HEAD(&phba->sli4_hba.sp_rspiocb_work_queue);
3393 /* Asynchronous event CQ Event work queue list */
3394 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
3395 /* Fast-path XRI aborted CQ Event work queue list */
3396 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
3397 /* Slow-path XRI aborted CQ Event work queue list */
3398 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
3399 /* Receive queue CQ Event work queue list */
3400 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
3402 /* Initialize the driver internal SLI layer lists. */
3403 lpfc_sli_setup(phba);
3404 lpfc_sli_queue_setup(phba);
3406 /* Allocate device driver memory */
3407 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
3411 /* Create the bootstrap mailbox command */
3412 rc = lpfc_create_bootstrap_mbox(phba);
3416 /* Set up the host's endian order with the device. */
3417 rc = lpfc_setup_endian_order(phba);
3419 goto out_free_bsmbx;
3421 /* Set up the hba's configuration parameters. */
3422 rc = lpfc_sli4_read_config(phba);
3424 goto out_free_bsmbx;
3426 /* Perform a function reset */
3427 rc = lpfc_pci_function_reset(phba);
3429 goto out_free_bsmbx;
3431 /* Create all the SLI4 queues */
3432 rc = lpfc_sli4_queue_create(phba);
3434 goto out_free_bsmbx;
3436 /* Create driver internal CQE event pool */
3437 rc = lpfc_sli4_cq_event_pool_create(phba);
3439 goto out_destroy_queue;
3441 /* Initialize and populate the iocb list per host */
3442 rc = lpfc_init_sgl_list(phba);
3444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3445 "1400 Failed to initialize sgl list.\n");
3446 goto out_destroy_cq_event_pool;
3448 rc = lpfc_init_active_sgl_array(phba);
3450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3451 "1430 Failed to initialize sgl list.\n");
3452 goto out_free_sgl_list;
3455 rc = lpfc_sli4_init_rpi_hdrs(phba);
3457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3458 "1432 Failed to initialize rpi headers.\n");
3459 goto out_free_active_sgl;
3462 phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
3463 phba->cfg_fcp_eq_count), GFP_KERNEL);
3464 if (!phba->sli4_hba.fcp_eq_hdl) {
3465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3466 "2572 Failed allocate memory for fast-path "
3467 "per-EQ handle array\n");
3468 goto out_remove_rpi_hdrs;
3471 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
3472 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
3473 if (!phba->sli4_hba.msix_entries) {
3474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3475 "2573 Failed allocate memory for msi-x "
3476 "interrupt vector entries\n");
3477 goto out_free_fcp_eq_hdl;
3482 out_free_fcp_eq_hdl:
3483 kfree(phba->sli4_hba.fcp_eq_hdl);
3484 out_remove_rpi_hdrs:
3485 lpfc_sli4_remove_rpi_hdrs(phba);
3486 out_free_active_sgl:
3487 lpfc_free_active_sgl(phba);
3489 lpfc_free_sgl_list(phba);
3490 out_destroy_cq_event_pool:
3491 lpfc_sli4_cq_event_pool_destroy(phba);
3493 lpfc_sli4_queue_destroy(phba);
3495 lpfc_destroy_bootstrap_mbox(phba);
3497 lpfc_mem_free(phba);
3502 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
3503 * @phba: pointer to lpfc hba data structure.
3505 * This routine is invoked to unset the driver internal resources set up
3506 * specific for supporting the SLI-4 HBA device it attached to.
3509 lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
3511 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
3513 /* unregister default FCFI from the HBA */
3514 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
3516 /* Free the default FCR table */
3517 lpfc_sli_remove_dflt_fcf(phba);
3519 /* Free memory allocated for msi-x interrupt vector entries */
3520 kfree(phba->sli4_hba.msix_entries);
3522 /* Free memory allocated for fast-path work queue handles */
3523 kfree(phba->sli4_hba.fcp_eq_hdl);
3525 /* Free the allocated rpi headers. */
3526 lpfc_sli4_remove_rpi_hdrs(phba);
3528 /* Free the ELS sgl list */
3529 lpfc_free_active_sgl(phba);
3530 lpfc_free_sgl_list(phba);
3532 /* Free the SCSI sgl management array */
3533 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3535 /* Free the SLI4 queues */
3536 lpfc_sli4_queue_destroy(phba);
3538 /* Free the completion queue EQ event pool */
3539 lpfc_sli4_cq_event_release_all(phba);
3540 lpfc_sli4_cq_event_pool_destroy(phba);
3542 /* Reset SLI4 HBA FCoE function */
3543 lpfc_pci_function_reset(phba);
3545 /* Free the bsmbx region. */
3546 lpfc_destroy_bootstrap_mbox(phba);
3548 /* Free the SLI Layer memory with SLI4 HBAs */
3549 lpfc_mem_free_all(phba);
3551 /* Free the current connect table */
3552 list_for_each_entry_safe(conn_entry, next_conn_entry,
3553 &phba->fcf_conn_rec_list, list)
3560 * lpfc_init_api_table_setup - Set up init api fucntion jump table
3561 * @phba: The hba struct for which this call is being executed.
3562 * @dev_grp: The HBA PCI-Device group number.
3564 * This routine sets up the device INIT interface API function jump table
3567 * Returns: 0 - success, -ENODEV - failure.
3570 lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
3573 case LPFC_PCI_DEV_LP:
3574 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
3575 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
3576 phba->lpfc_stop_port = lpfc_stop_port_s3;
3578 case LPFC_PCI_DEV_OC:
3579 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
3580 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
3581 phba->lpfc_stop_port = lpfc_stop_port_s4;
3584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3585 "1431 Invalid HBA PCI-device group: 0x%x\n",
3594 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
3595 * @phba: pointer to lpfc hba data structure.
3597 * This routine is invoked to set up the driver internal resources before the
3598 * device specific resource setup to support the HBA device it attached to.
3602 * other values - error
3605 lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
3608 * Driver resources common to all SLI revisions
3610 atomic_set(&phba->fast_event_count, 0);
3611 spin_lock_init(&phba->hbalock);
3613 /* Initialize ndlp management spinlock */
3614 spin_lock_init(&phba->ndlp_lock);
3616 INIT_LIST_HEAD(&phba->port_list);
3617 INIT_LIST_HEAD(&phba->work_list);
3618 init_waitqueue_head(&phba->wait_4_mlo_m_q);
3620 /* Initialize the wait queue head for the kernel thread */
3621 init_waitqueue_head(&phba->work_waitq);
3623 /* Initialize the scsi buffer list used by driver for scsi IO */
3624 spin_lock_init(&phba->scsi_buf_list_lock);
3625 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
3627 /* Initialize the fabric iocb list */
3628 INIT_LIST_HEAD(&phba->fabric_iocb_list);
3630 /* Initialize list to save ELS buffers */
3631 INIT_LIST_HEAD(&phba->elsbuf);
3633 /* Initialize FCF connection rec list */
3634 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
3640 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
3641 * @phba: pointer to lpfc hba data structure.
3643 * This routine is invoked to set up the driver internal resources after the
3644 * device specific resource setup to support the HBA device it attached to.
3648 * other values - error
3651 lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
3655 /* Startup the kernel thread for this host adapter. */
3656 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3657 "lpfc_worker_%d", phba->brd_no);
3658 if (IS_ERR(phba->worker_thread)) {
3659 error = PTR_ERR(phba->worker_thread);
3667 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
3668 * @phba: pointer to lpfc hba data structure.
3670 * This routine is invoked to unset the driver internal resources set up after
3671 * the device specific resource setup for supporting the HBA device it
3675 lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
3677 /* Stop kernel worker thread */
3678 kthread_stop(phba->worker_thread);
3682 * lpfc_free_iocb_list - Free iocb list.
3683 * @phba: pointer to lpfc hba data structure.
3685 * This routine is invoked to free the driver's IOCB list and memory.
3688 lpfc_free_iocb_list(struct lpfc_hba *phba)
3690 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
3692 spin_lock_irq(&phba->hbalock);
3693 list_for_each_entry_safe(iocbq_entry, iocbq_next,
3694 &phba->lpfc_iocb_list, list) {
3695 list_del(&iocbq_entry->list);
3697 phba->total_iocbq_bufs--;
3699 spin_unlock_irq(&phba->hbalock);
3705 * lpfc_init_iocb_list - Allocate and initialize iocb list.
3706 * @phba: pointer to lpfc hba data structure.
3708 * This routine is invoked to allocate and initizlize the driver's IOCB
3709 * list and set up the IOCB tag array accordingly.
3713 * other values - error
3716 lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
3718 struct lpfc_iocbq *iocbq_entry = NULL;
3722 /* Initialize and populate the iocb list per host. */
3723 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
3724 for (i = 0; i < iocb_count; i++) {
3725 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
3726 if (iocbq_entry == NULL) {
3727 printk(KERN_ERR "%s: only allocated %d iocbs of "
3728 "expected %d count. Unloading driver.\n",
3729 __func__, i, LPFC_IOCB_LIST_CNT);
3730 goto out_free_iocbq;
3733 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
3736 printk(KERN_ERR "%s: failed to allocate IOTAG. "
3737 "Unloading driver.\n", __func__);
3738 goto out_free_iocbq;
3740 iocbq_entry->sli4_xritag = NO_XRI;
3742 spin_lock_irq(&phba->hbalock);
3743 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
3744 phba->total_iocbq_bufs++;
3745 spin_unlock_irq(&phba->hbalock);
3751 lpfc_free_iocb_list(phba);
3757 * lpfc_free_sgl_list - Free sgl list.
3758 * @phba: pointer to lpfc hba data structure.
3760 * This routine is invoked to free the driver's sgl list and memory.
3763 lpfc_free_sgl_list(struct lpfc_hba *phba)
3765 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
3766 LIST_HEAD(sglq_list);
3769 spin_lock_irq(&phba->hbalock);
3770 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
3771 spin_unlock_irq(&phba->hbalock);
3773 list_for_each_entry_safe(sglq_entry, sglq_next,
3775 list_del(&sglq_entry->list);
3776 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
3778 phba->sli4_hba.total_sglq_bufs--;
3780 rc = lpfc_sli4_remove_all_sgl_pages(phba);
3782 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3783 "2005 Unable to deregister pages from HBA: %x", rc);
3785 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3789 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
3790 * @phba: pointer to lpfc hba data structure.
3792 * This routine is invoked to allocate the driver's active sgl memory.
3793 * This array will hold the sglq_entry's for active IOs.
3796 lpfc_init_active_sgl_array(struct lpfc_hba *phba)
3799 size = sizeof(struct lpfc_sglq *);
3800 size *= phba->sli4_hba.max_cfg_param.max_xri;
3802 phba->sli4_hba.lpfc_sglq_active_list =
3803 kzalloc(size, GFP_KERNEL);
3804 if (!phba->sli4_hba.lpfc_sglq_active_list)
3810 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
3811 * @phba: pointer to lpfc hba data structure.
3813 * This routine is invoked to walk through the array of active sglq entries
3814 * and free all of the resources.
3815 * This is just a place holder for now.
3818 lpfc_free_active_sgl(struct lpfc_hba *phba)
3820 kfree(phba->sli4_hba.lpfc_sglq_active_list);
3824 * lpfc_init_sgl_list - Allocate and initialize sgl list.
3825 * @phba: pointer to lpfc hba data structure.
3827 * This routine is invoked to allocate and initizlize the driver's sgl
3828 * list and set up the sgl xritag tag array accordingly.
3832 * other values - error
3835 lpfc_init_sgl_list(struct lpfc_hba *phba)
3837 struct lpfc_sglq *sglq_entry = NULL;
3841 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3842 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3843 "2400 lpfc_init_sgl_list els %d.\n",
3845 /* Initialize and populate the sglq list per host/VF. */
3846 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
3847 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
3849 /* Sanity check on XRI management */
3850 if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
3851 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3852 "2562 No room left for SCSI XRI allocation: "
3853 "max_xri=%d, els_xri=%d\n",
3854 phba->sli4_hba.max_cfg_param.max_xri,
3859 /* Allocate memory for the ELS XRI management array */
3860 phba->sli4_hba.lpfc_els_sgl_array =
3861 kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
3864 if (!phba->sli4_hba.lpfc_els_sgl_array) {
3865 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3866 "2401 Failed to allocate memory for ELS "
3867 "XRI management array of size %d.\n",
3872 /* Keep the SCSI XRI into the XRI management array */
3873 phba->sli4_hba.scsi_xri_max =
3874 phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3875 phba->sli4_hba.scsi_xri_cnt = 0;
3877 phba->sli4_hba.lpfc_scsi_psb_array =
3878 kzalloc((sizeof(struct lpfc_scsi_buf *) *
3879 phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
3881 if (!phba->sli4_hba.lpfc_scsi_psb_array) {
3882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3883 "2563 Failed to allocate memory for SCSI "
3884 "XRI management array of size %d.\n",
3885 phba->sli4_hba.scsi_xri_max);
3886 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3890 for (i = 0; i < els_xri_cnt; i++) {
3891 sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
3892 if (sglq_entry == NULL) {
3893 printk(KERN_ERR "%s: only allocated %d sgls of "
3894 "expected %d count. Unloading driver.\n",
3895 __func__, i, els_xri_cnt);
3899 sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
3900 if (sglq_entry->sli4_xritag == NO_XRI) {
3902 printk(KERN_ERR "%s: failed to allocate XRI.\n"
3903 "Unloading driver.\n", __func__);
3906 sglq_entry->buff_type = GEN_BUFF_TYPE;
3907 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
3908 if (sglq_entry->virt == NULL) {
3910 printk(KERN_ERR "%s: failed to allocate mbuf.\n"
3911 "Unloading driver.\n", __func__);
3914 sglq_entry->sgl = sglq_entry->virt;
3915 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3917 /* The list order is used by later block SGL registraton */
3918 spin_lock_irq(&phba->hbalock);
3919 list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
3920 phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
3921 phba->sli4_hba.total_sglq_bufs++;
3922 spin_unlock_irq(&phba->hbalock);
3927 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3928 lpfc_free_sgl_list(phba);
3933 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
3934 * @phba: pointer to lpfc hba data structure.
3936 * This routine is invoked to post rpi header templates to the
3937 * HBA consistent with the SLI-4 interface spec. This routine
3938 * posts a PAGE_SIZE memory region to the port to hold up to
3939 * PAGE_SIZE modulo 64 rpi context headers.
3940 * No locks are held here because this is an initialization routine
3941 * called only from probe or lpfc_online when interrupts are not
3942 * enabled and the driver is reinitializing the device.
3946 * ENOMEM - No availble memory
3947 * EIO - The mailbox failed to complete successfully.
3950 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
3955 struct lpfc_rpi_hdr *rpi_hdr;
3957 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
3960 * Provision an rpi bitmask range for discovery. The total count
3961 * is the difference between max and base + 1.
3963 rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
3964 phba->sli4_hba.max_cfg_param.max_rpi - 1;
3966 longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
3967 phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
3969 if (!phba->sli4_hba.rpi_bmask)
3972 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
3974 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
3975 "0391 Error during rpi post operation\n");
3976 lpfc_sli4_remove_rpis(phba);
3984 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
3985 * @phba: pointer to lpfc hba data structure.
3987 * This routine is invoked to allocate a single 4KB memory region to
3988 * support rpis and stores them in the phba. This single region
3989 * provides support for up to 64 rpis. The region is used globally
3993 * A valid rpi hdr on success.
3994 * A NULL pointer on any failure.
3996 struct lpfc_rpi_hdr *
3997 lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
3999 uint16_t rpi_limit, curr_rpi_range;
4000 struct lpfc_dmabuf *dmabuf;
4001 struct lpfc_rpi_hdr *rpi_hdr;
4003 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
4004 phba->sli4_hba.max_cfg_param.max_rpi - 1;
4006 spin_lock_irq(&phba->hbalock);
4007 curr_rpi_range = phba->sli4_hba.next_rpi;
4008 spin_unlock_irq(&phba->hbalock);
4011 * The port has a limited number of rpis. The increment here
4012 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
4013 * and to allow the full max_rpi range per port.
4015 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
4019 * First allocate the protocol header region for the port. The
4020 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
4022 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4026 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4027 LPFC_HDR_TEMPLATE_SIZE,
4030 if (!dmabuf->virt) {
4032 goto err_free_dmabuf;
4035 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
4036 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
4038 goto err_free_coherent;
4041 /* Save the rpi header data for cleanup later. */
4042 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
4044 goto err_free_coherent;
4046 rpi_hdr->dmabuf = dmabuf;
4047 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
4048 rpi_hdr->page_count = 1;
4049 spin_lock_irq(&phba->hbalock);
4050 rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
4051 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
4054 * The next_rpi stores the next module-64 rpi value to post
4055 * in any subsequent rpi memory region postings.
4057 phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
4058 spin_unlock_irq(&phba->hbalock);
4062 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
4063 dmabuf->virt, dmabuf->phys);
4070 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
4071 * @phba: pointer to lpfc hba data structure.
4073 * This routine is invoked to remove all memory resources allocated
4074 * to support rpis. This routine presumes the caller has released all
4075 * rpis consumed by fabric or port logins and is prepared to have
4076 * the header pages removed.
4079 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
4081 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
4083 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
4084 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
4085 list_del(&rpi_hdr->list);
4086 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
4087 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
4088 kfree(rpi_hdr->dmabuf);
4092 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4093 memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
4097 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
4098 * @pdev: pointer to pci device data structure.
4100 * This routine is invoked to allocate the driver hba data structure for an
4101 * HBA device. If the allocation is successful, the phba reference to the
4102 * PCI device data structure is set.
4105 * pointer to @phba - sucessful
4108 static struct lpfc_hba *
4109 lpfc_hba_alloc(struct pci_dev *pdev)
4111 struct lpfc_hba *phba;
4113 /* Allocate memory for HBA structure */
4114 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
4116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4117 "1417 Failed to allocate hba struct.\n");
4121 /* Set reference to PCI device in HBA structure */
4122 phba->pcidev = pdev;
4124 /* Assign an unused board number */
4125 phba->brd_no = lpfc_get_instance();
4126 if (phba->brd_no < 0) {
4135 * lpfc_hba_free - Free driver hba data structure with a device.
4136 * @phba: pointer to lpfc hba data structure.
4138 * This routine is invoked to free the driver hba data structure with an
4142 lpfc_hba_free(struct lpfc_hba *phba)
4144 /* Release the driver assigned board number */
4145 idr_remove(&lpfc_hba_index, phba->brd_no);
4152 * lpfc_create_shost - Create hba physical port with associated scsi host.
4153 * @phba: pointer to lpfc hba data structure.
4155 * This routine is invoked to create HBA physical port and associate a SCSI
4160 * other values - error
4163 lpfc_create_shost(struct lpfc_hba *phba)
4165 struct lpfc_vport *vport;
4166 struct Scsi_Host *shost;
4168 /* Initialize HBA FC structure */
4169 phba->fc_edtov = FF_DEF_EDTOV;
4170 phba->fc_ratov = FF_DEF_RATOV;
4171 phba->fc_altov = FF_DEF_ALTOV;
4172 phba->fc_arbtov = FF_DEF_ARBTOV;
4174 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
4178 shost = lpfc_shost_from_vport(vport);
4179 phba->pport = vport;
4180 lpfc_debugfs_initialize(vport);
4181 /* Put reference to SCSI host to driver's device private data */
4182 pci_set_drvdata(phba->pcidev, shost);
4188 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
4189 * @phba: pointer to lpfc hba data structure.
4191 * This routine is invoked to destroy HBA physical port and the associated
4195 lpfc_destroy_shost(struct lpfc_hba *phba)
4197 struct lpfc_vport *vport = phba->pport;
4199 /* Destroy physical port that associated with the SCSI host */
4200 destroy_port(vport);
4206 * lpfc_setup_bg - Setup Block guard structures and debug areas.
4207 * @phba: pointer to lpfc hba data structure.
4208 * @shost: the shost to be used to detect Block guard settings.
4210 * This routine sets up the local Block guard protocol settings for @shost.
4211 * This routine also allocates memory for debugging bg buffers.
4214 lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
4217 if (lpfc_prot_mask && lpfc_prot_guard) {
4218 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4219 "1478 Registering BlockGuard with the "
4221 scsi_host_set_prot(shost, lpfc_prot_mask);
4222 scsi_host_set_guard(shost, lpfc_prot_guard);
4224 if (!_dump_buf_data) {
4226 spin_lock_init(&_dump_buf_lock);
4228 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
4229 if (_dump_buf_data) {
4230 printk(KERN_ERR "BLKGRD allocated %d pages for "
4231 "_dump_buf_data at 0x%p\n",
4232 (1 << pagecnt), _dump_buf_data);
4233 _dump_buf_data_order = pagecnt;
4234 memset(_dump_buf_data, 0,
4235 ((1 << PAGE_SHIFT) << pagecnt));
4240 if (!_dump_buf_data_order)
4241 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
4242 "memory for hexdump\n");
4244 printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p"
4245 "\n", _dump_buf_data);
4246 if (!_dump_buf_dif) {
4249 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
4250 if (_dump_buf_dif) {
4251 printk(KERN_ERR "BLKGRD allocated %d pages for "
4252 "_dump_buf_dif at 0x%p\n",
4253 (1 << pagecnt), _dump_buf_dif);
4254 _dump_buf_dif_order = pagecnt;
4255 memset(_dump_buf_dif, 0,
4256 ((1 << PAGE_SHIFT) << pagecnt));
4261 if (!_dump_buf_dif_order)
4262 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
4263 "memory for hexdump\n");
4265 printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n",
4270 * lpfc_post_init_setup - Perform necessary device post initialization setup.
4271 * @phba: pointer to lpfc hba data structure.
4273 * This routine is invoked to perform all the necessary post initialization
4274 * setup for the device.
4277 lpfc_post_init_setup(struct lpfc_hba *phba)
4279 struct Scsi_Host *shost;
4280 struct lpfc_adapter_event_header adapter_event;
4282 /* Get the default values for Model Name and Description */
4283 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
4286 * hba setup may have changed the hba_queue_depth so we need to
4287 * adjust the value of can_queue.
4289 shost = pci_get_drvdata(phba->pcidev);
4290 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4291 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4292 lpfc_setup_bg(phba, shost);
4294 lpfc_host_attrib_init(shost);
4296 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
4297 spin_lock_irq(shost->host_lock);
4298 lpfc_poll_start_timer(phba);
4299 spin_unlock_irq(shost->host_lock);
4302 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4303 "0428 Perform SCSI scan\n");
4304 /* Send board arrival event to upper layer */
4305 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
4306 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
4307 fc_host_post_vendor_event(shost, fc_get_event_number(),
4308 sizeof(adapter_event),
4309 (char *) &adapter_event,
4315 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
4316 * @phba: pointer to lpfc hba data structure.
4318 * This routine is invoked to set up the PCI device memory space for device
4319 * with SLI-3 interface spec.
4323 * other values - error
4326 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
4328 struct pci_dev *pdev;
4329 unsigned long bar0map_len, bar2map_len;
4332 int error = -ENODEV;
4334 /* Obtain PCI device reference */
4338 pdev = phba->pcidev;
4340 /* Set the device DMA mask size */
4341 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
4342 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
4345 /* Get the bus address of Bar0 and Bar2 and the number of bytes
4346 * required by each mapping.
4348 phba->pci_bar0_map = pci_resource_start(pdev, 0);
4349 bar0map_len = pci_resource_len(pdev, 0);
4351 phba->pci_bar2_map = pci_resource_start(pdev, 2);
4352 bar2map_len = pci_resource_len(pdev, 2);
4354 /* Map HBA SLIM to a kernel virtual address. */
4355 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
4356 if (!phba->slim_memmap_p) {
4357 dev_printk(KERN_ERR, &pdev->dev,
4358 "ioremap failed for SLIM memory.\n");
4362 /* Map HBA Control Registers to a kernel virtual address. */
4363 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
4364 if (!phba->ctrl_regs_memmap_p) {
4365 dev_printk(KERN_ERR, &pdev->dev,
4366 "ioremap failed for HBA control registers.\n");
4367 goto out_iounmap_slim;
4370 /* Allocate memory for SLI-2 structures */
4371 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
4375 if (!phba->slim2p.virt)
4378 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
4379 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
4380 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
4381 phba->IOCBs = (phba->slim2p.virt +
4382 offsetof(struct lpfc_sli2_slim, IOCBs));
4384 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
4385 lpfc_sli_hbq_size(),
4386 &phba->hbqslimp.phys,
4388 if (!phba->hbqslimp.virt)
4391 hbq_count = lpfc_sli_hbq_count();
4392 ptr = phba->hbqslimp.virt;
4393 for (i = 0; i < hbq_count; ++i) {
4394 phba->hbqs[i].hbq_virt = ptr;
4395 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4396 ptr += (lpfc_hbq_defs[i]->entry_count *
4397 sizeof(struct lpfc_hbq_entry));
4399 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
4400 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
4402 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
4404 INIT_LIST_HEAD(&phba->rb_pend_list);
4406 phba->MBslimaddr = phba->slim_memmap_p;
4407 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
4408 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
4409 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
4410 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
4415 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
4416 phba->slim2p.virt, phba->slim2p.phys);
4418 iounmap(phba->ctrl_regs_memmap_p);
4420 iounmap(phba->slim_memmap_p);
4426 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
4427 * @phba: pointer to lpfc hba data structure.
4429 * This routine is invoked to unset the PCI device memory space for device
4430 * with SLI-3 interface spec.
4433 lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
4435 struct pci_dev *pdev;
4437 /* Obtain PCI device reference */
4441 pdev = phba->pcidev;
4443 /* Free coherent DMA memory allocated */
4444 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
4445 phba->hbqslimp.virt, phba->hbqslimp.phys);
4446 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
4447 phba->slim2p.virt, phba->slim2p.phys);
4449 /* I/O memory unmap */
4450 iounmap(phba->ctrl_regs_memmap_p);
4451 iounmap(phba->slim_memmap_p);
4457 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
4458 * @phba: pointer to lpfc hba data structure.
4460 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
4461 * done and check status.
4463 * Return 0 if successful, otherwise -ENODEV.
4466 lpfc_sli4_post_status_check(struct lpfc_hba *phba)
4468 struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
4469 uint32_t onlnreg0, onlnreg1;
4470 int i, port_error = -ENODEV;
4472 if (!phba->sli4_hba.STAregaddr)
4475 /* With uncoverable error, log the error message and return error */
4476 onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
4477 onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
4478 if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
4479 uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
4480 uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
4481 if (uerrlo_reg.word0 || uerrhi_reg.word0) {
4482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4483 "1422 HBA Unrecoverable error: "
4484 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
4485 "online0_reg=0x%x, online1_reg=0x%x\n",
4486 uerrlo_reg.word0, uerrhi_reg.word0,
4487 onlnreg0, onlnreg1);
4492 /* Wait up to 30 seconds for the SLI Port POST done and ready */
4493 for (i = 0; i < 3000; i++) {
4494 sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
4495 /* Encounter fatal POST error, break out */
4496 if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
4497 port_error = -ENODEV;
4500 if (LPFC_POST_STAGE_ARMFW_READY ==
4501 bf_get(lpfc_hst_state_port_status, &sta_reg)) {
4509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4510 "1408 Failure HBA POST Status: sta_reg=0x%x, "
4511 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
4512 "dl=x%x, pstatus=x%x\n", sta_reg.word0,
4513 bf_get(lpfc_hst_state_perr, &sta_reg),
4514 bf_get(lpfc_hst_state_sfi, &sta_reg),
4515 bf_get(lpfc_hst_state_nip, &sta_reg),
4516 bf_get(lpfc_hst_state_ipc, &sta_reg),
4517 bf_get(lpfc_hst_state_xrom, &sta_reg),
4518 bf_get(lpfc_hst_state_dl, &sta_reg),
4519 bf_get(lpfc_hst_state_port_status, &sta_reg));
4521 /* Log device information */
4522 scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
4523 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4524 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
4525 "FeatureL1=0x%x, FeatureL2=0x%x\n",
4526 bf_get(lpfc_scratchpad_chiptype, &scratchpad),
4527 bf_get(lpfc_scratchpad_slirev, &scratchpad),
4528 bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
4529 bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
4535 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
4536 * @phba: pointer to lpfc hba data structure.
4538 * This routine is invoked to set up SLI4 BAR0 PCI config space register
4542 lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
4544 phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
4545 LPFC_UERR_STATUS_LO;
4546 phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
4547 LPFC_UERR_STATUS_HI;
4548 phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p +
4550 phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p +
4552 phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
4557 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
4558 * @phba: pointer to lpfc hba data structure.
4560 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
4564 lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
4567 phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4569 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4571 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4573 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4579 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
4580 * @phba: pointer to lpfc hba data structure.
4581 * @vf: virtual function number
4583 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
4584 * based on the given viftual function number, @vf.
4586 * Return 0 if successful, otherwise -ENODEV.
4589 lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
4591 if (vf > LPFC_VIR_FUNC_MAX)
4594 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4595 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
4596 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4597 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
4598 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4599 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
4600 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4601 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
4602 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4603 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
4608 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
4609 * @phba: pointer to lpfc hba data structure.
4611 * This routine is invoked to create the bootstrap mailbox
4612 * region consistent with the SLI-4 interface spec. This
4613 * routine allocates all memory necessary to communicate
4614 * mailbox commands to the port and sets up all alignment
4615 * needs. No locks are expected to be held when calling
4620 * ENOMEM - could not allocated memory.
4623 lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
4626 struct lpfc_dmabuf *dmabuf;
4627 struct dma_address *dma_address;
4631 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4636 * The bootstrap mailbox region is comprised of 2 parts
4637 * plus an alignment restriction of 16 bytes.
4639 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
4640 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4644 if (!dmabuf->virt) {
4648 memset(dmabuf->virt, 0, bmbx_size);
4651 * Initialize the bootstrap mailbox pointers now so that the register
4652 * operations are simple later. The mailbox dma address is required
4653 * to be 16-byte aligned. Also align the virtual memory as each
4654 * maibox is copied into the bmbx mailbox region before issuing the
4655 * command to the port.
4657 phba->sli4_hba.bmbx.dmabuf = dmabuf;
4658 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
4660 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
4661 LPFC_ALIGN_16_BYTE);
4662 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
4663 LPFC_ALIGN_16_BYTE);
4666 * Set the high and low physical addresses now. The SLI4 alignment
4667 * requirement is 16 bytes and the mailbox is posted to the port
4668 * as two 30-bit addresses. The other data is a bit marking whether
4669 * the 30-bit address is the high or low address.
4670 * Upcast bmbx aphys to 64bits so shift instruction compiles
4671 * clean on 32 bit machines.
4673 dma_address = &phba->sli4_hba.bmbx.dma_address;
4674 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
4675 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
4676 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
4677 LPFC_BMBX_BIT1_ADDR_HI);
4679 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
4680 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
4681 LPFC_BMBX_BIT1_ADDR_LO);
4686 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
4687 * @phba: pointer to lpfc hba data structure.
4689 * This routine is invoked to teardown the bootstrap mailbox
4690 * region and release all host resources. This routine requires
4691 * the caller to ensure all mailbox commands recovered, no
4692 * additional mailbox comands are sent, and interrupts are disabled
4693 * before calling this routine.
4697 lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
4699 dma_free_coherent(&phba->pcidev->dev,
4700 phba->sli4_hba.bmbx.bmbx_size,
4701 phba->sli4_hba.bmbx.dmabuf->virt,
4702 phba->sli4_hba.bmbx.dmabuf->phys);
4704 kfree(phba->sli4_hba.bmbx.dmabuf);
4705 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
4709 * lpfc_sli4_read_config - Get the config parameters.
4710 * @phba: pointer to lpfc hba data structure.
4712 * This routine is invoked to read the configuration parameters from the HBA.
4713 * The configuration parameters are used to set the base and maximum values
4714 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
4715 * allocation for the port.
4719 * ENOMEM - No availble memory
4720 * EIO - The mailbox failed to complete successfully.
4723 lpfc_sli4_read_config(struct lpfc_hba *phba)
4726 struct lpfc_mbx_read_config *rd_config;
4729 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4731 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4732 "2011 Unable to allocate memory for issuing "
4733 "SLI_CONFIG_SPECIAL mailbox command\n");
4737 lpfc_read_config(phba, pmb);
4739 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4740 if (rc != MBX_SUCCESS) {
4741 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4742 "2012 Mailbox failed , mbxCmd x%x "
4743 "READ_CONFIG, mbxStatus x%x\n",
4744 bf_get(lpfc_mqe_command, &pmb->u.mqe),
4745 bf_get(lpfc_mqe_status, &pmb->u.mqe));
4748 rd_config = &pmb->u.mqe.un.rd_config;
4749 phba->sli4_hba.max_cfg_param.max_xri =
4750 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
4751 phba->sli4_hba.max_cfg_param.xri_base =
4752 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
4753 phba->sli4_hba.max_cfg_param.max_vpi =
4754 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
4755 phba->sli4_hba.max_cfg_param.vpi_base =
4756 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
4757 phba->sli4_hba.max_cfg_param.max_rpi =
4758 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
4759 phba->sli4_hba.max_cfg_param.rpi_base =
4760 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
4761 phba->sli4_hba.max_cfg_param.max_vfi =
4762 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
4763 phba->sli4_hba.max_cfg_param.vfi_base =
4764 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
4765 phba->sli4_hba.max_cfg_param.max_fcfi =
4766 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
4767 phba->sli4_hba.max_cfg_param.fcfi_base =
4768 bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
4769 phba->sli4_hba.max_cfg_param.max_eq =
4770 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
4771 phba->sli4_hba.max_cfg_param.max_rq =
4772 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
4773 phba->sli4_hba.max_cfg_param.max_wq =
4774 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
4775 phba->sli4_hba.max_cfg_param.max_cq =
4776 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
4777 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
4778 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
4779 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
4780 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
4781 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4782 phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi;
4783 phba->max_vports = phba->max_vpi;
4784 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4785 "2003 cfg params XRI(B:%d M:%d), "
4789 "FCFI(B:%d M:%d)\n",
4790 phba->sli4_hba.max_cfg_param.xri_base,
4791 phba->sli4_hba.max_cfg_param.max_xri,
4792 phba->sli4_hba.max_cfg_param.vpi_base,
4793 phba->sli4_hba.max_cfg_param.max_vpi,
4794 phba->sli4_hba.max_cfg_param.vfi_base,
4795 phba->sli4_hba.max_cfg_param.max_vfi,
4796 phba->sli4_hba.max_cfg_param.rpi_base,
4797 phba->sli4_hba.max_cfg_param.max_rpi,
4798 phba->sli4_hba.max_cfg_param.fcfi_base,
4799 phba->sli4_hba.max_cfg_param.max_fcfi);
4801 mempool_free(pmb, phba->mbox_mem_pool);
4803 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
4804 if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
4805 phba->cfg_hba_queue_depth =
4806 phba->sli4_hba.max_cfg_param.max_xri;
4811 * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
4812 * @phba: pointer to lpfc hba data structure.
4814 * This routine is invoked to setup the host-side endian order to the
4815 * HBA consistent with the SLI-4 interface spec.
4819 * ENOMEM - No availble memory
4820 * EIO - The mailbox failed to complete successfully.
4823 lpfc_setup_endian_order(struct lpfc_hba *phba)
4825 LPFC_MBOXQ_t *mboxq;
4827 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
4828 HOST_ENDIAN_HIGH_WORD1};
4830 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4833 "0492 Unable to allocate memory for issuing "
4834 "SLI_CONFIG_SPECIAL mailbox command\n");
4839 * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
4840 * words to contain special data values and no other data.
4842 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
4843 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
4844 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4845 if (rc != MBX_SUCCESS) {
4846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4847 "0493 SLI_CONFIG_SPECIAL mailbox failed with "
4853 mempool_free(mboxq, phba->mbox_mem_pool);
4858 * lpfc_sli4_queue_create - Create all the SLI4 queues
4859 * @phba: pointer to lpfc hba data structure.
4861 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
4862 * operation. For each SLI4 queue type, the parameters such as queue entry
4863 * count (queue depth) shall be taken from the module parameter. For now,
4864 * we just use some constant number as place holder.
4868 * ENOMEM - No availble memory
4869 * EIO - The mailbox failed to complete successfully.
4872 lpfc_sli4_queue_create(struct lpfc_hba *phba)
4874 struct lpfc_queue *qdesc;
4875 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
4876 int cfg_fcp_wq_count;
4877 int cfg_fcp_eq_count;
4880 * Sanity check for confiugred queue parameters against the run-time
4884 /* Sanity check on FCP fast-path WQ parameters */
4885 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
4886 if (cfg_fcp_wq_count >
4887 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
4888 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
4890 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
4891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4892 "2581 Not enough WQs (%d) from "
4893 "the pci function for supporting "
4895 phba->sli4_hba.max_cfg_param.max_wq,
4896 phba->cfg_fcp_wq_count);
4899 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4900 "2582 Not enough WQs (%d) from the pci "
4901 "function for supporting the requested "
4902 "FCP WQs (%d), the actual FCP WQs can "
4903 "be supported: %d\n",
4904 phba->sli4_hba.max_cfg_param.max_wq,
4905 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
4907 /* The actual number of FCP work queues adopted */
4908 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
4910 /* Sanity check on FCP fast-path EQ parameters */
4911 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
4912 if (cfg_fcp_eq_count >
4913 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
4914 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
4916 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
4917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4918 "2574 Not enough EQs (%d) from the "
4919 "pci function for supporting FCP "
4921 phba->sli4_hba.max_cfg_param.max_eq,
4922 phba->cfg_fcp_eq_count);
4925 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4926 "2575 Not enough EQs (%d) from the pci "
4927 "function for supporting the requested "
4928 "FCP EQs (%d), the actual FCP EQs can "
4929 "be supported: %d\n",
4930 phba->sli4_hba.max_cfg_param.max_eq,
4931 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
4933 /* It does not make sense to have more EQs than WQs */
4934 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
4935 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4936 "2593 The number of FCP EQs (%d) is more "
4937 "than the number of FCP WQs (%d), take "
4938 "the number of FCP EQs same as than of "
4939 "WQs (%d)\n", cfg_fcp_eq_count,
4940 phba->cfg_fcp_wq_count,
4941 phba->cfg_fcp_wq_count);
4942 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
4944 /* The actual number of FCP event queues adopted */
4945 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
4946 /* The overall number of event queues used */
4947 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
4950 * Create Event Queues (EQs)
4953 /* Get EQ depth from module parameter, fake the default for now */
4954 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
4955 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
4957 /* Create slow path event queue */
4958 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4959 phba->sli4_hba.eq_ecount);
4961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4962 "0496 Failed allocate slow-path EQ\n");
4965 phba->sli4_hba.sp_eq = qdesc;
4967 /* Create fast-path FCP Event Queue(s) */
4968 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
4969 phba->cfg_fcp_eq_count), GFP_KERNEL);
4970 if (!phba->sli4_hba.fp_eq) {
4971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4972 "2576 Failed allocate memory for fast-path "
4973 "EQ record array\n");
4974 goto out_free_sp_eq;
4976 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
4977 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4978 phba->sli4_hba.eq_ecount);
4980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4981 "0497 Failed allocate fast-path EQ\n");
4982 goto out_free_fp_eq;
4984 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
4988 * Create Complete Queues (CQs)
4991 /* Get CQ depth from module parameter, fake the default for now */
4992 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
4993 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
4995 /* Create slow-path Mailbox Command Complete Queue */
4996 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
4997 phba->sli4_hba.cq_ecount);
4999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5000 "0500 Failed allocate slow-path mailbox CQ\n");
5001 goto out_free_fp_eq;
5003 phba->sli4_hba.mbx_cq = qdesc;
5005 /* Create slow-path ELS Complete Queue */
5006 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5007 phba->sli4_hba.cq_ecount);
5009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5010 "0501 Failed allocate slow-path ELS CQ\n");
5011 goto out_free_mbx_cq;
5013 phba->sli4_hba.els_cq = qdesc;
5015 /* Create slow-path Unsolicited Receive Complete Queue */
5016 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5017 phba->sli4_hba.cq_ecount);
5019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5020 "0502 Failed allocate slow-path USOL RX CQ\n");
5021 goto out_free_els_cq;
5023 phba->sli4_hba.rxq_cq = qdesc;
5025 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
5026 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
5027 phba->cfg_fcp_eq_count), GFP_KERNEL);
5028 if (!phba->sli4_hba.fcp_cq) {
5029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5030 "2577 Failed allocate memory for fast-path "
5031 "CQ record array\n");
5032 goto out_free_rxq_cq;
5034 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5035 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5036 phba->sli4_hba.cq_ecount);
5038 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5039 "0499 Failed allocate fast-path FCP "
5040 "CQ (%d)\n", fcp_cqidx);
5041 goto out_free_fcp_cq;
5043 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
5046 /* Create Mailbox Command Queue */
5047 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
5048 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
5050 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
5051 phba->sli4_hba.mq_ecount);
5053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5054 "0505 Failed allocate slow-path MQ\n");
5055 goto out_free_fcp_cq;
5057 phba->sli4_hba.mbx_wq = qdesc;
5060 * Create all the Work Queues (WQs)
5062 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
5063 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
5065 /* Create slow-path ELS Work Queue */
5066 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5067 phba->sli4_hba.wq_ecount);
5069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5070 "0504 Failed allocate slow-path ELS WQ\n");
5071 goto out_free_mbx_wq;
5073 phba->sli4_hba.els_wq = qdesc;
5075 /* Create fast-path FCP Work Queue(s) */
5076 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
5077 phba->cfg_fcp_wq_count), GFP_KERNEL);
5078 if (!phba->sli4_hba.fcp_wq) {
5079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5080 "2578 Failed allocate memory for fast-path "
5081 "WQ record array\n");
5082 goto out_free_els_wq;
5084 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5085 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5086 phba->sli4_hba.wq_ecount);
5088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5089 "0503 Failed allocate fast-path FCP "
5090 "WQ (%d)\n", fcp_wqidx);
5091 goto out_free_fcp_wq;
5093 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
5097 * Create Receive Queue (RQ)
5099 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
5100 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
5102 /* Create Receive Queue for header */
5103 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5104 phba->sli4_hba.rq_ecount);
5106 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5107 "0506 Failed allocate receive HRQ\n");
5108 goto out_free_fcp_wq;
5110 phba->sli4_hba.hdr_rq = qdesc;
5112 /* Create Receive Queue for data */
5113 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5114 phba->sli4_hba.rq_ecount);
5116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5117 "0507 Failed allocate receive DRQ\n");
5118 goto out_free_hdr_rq;
5120 phba->sli4_hba.dat_rq = qdesc;
5125 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5126 phba->sli4_hba.hdr_rq = NULL;
5128 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
5129 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
5130 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
5132 kfree(phba->sli4_hba.fcp_wq);
5134 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5135 phba->sli4_hba.els_wq = NULL;
5137 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5138 phba->sli4_hba.mbx_wq = NULL;
5140 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
5141 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
5142 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
5144 kfree(phba->sli4_hba.fcp_cq);
5146 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5147 phba->sli4_hba.rxq_cq = NULL;
5149 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5150 phba->sli4_hba.els_cq = NULL;
5152 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5153 phba->sli4_hba.mbx_cq = NULL;
5155 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
5156 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
5157 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
5159 kfree(phba->sli4_hba.fp_eq);
5161 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5162 phba->sli4_hba.sp_eq = NULL;
5168 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
5169 * @phba: pointer to lpfc hba data structure.
5171 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
5176 * ENOMEM - No availble memory
5177 * EIO - The mailbox failed to complete successfully.
5180 lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
5184 /* Release mailbox command work queue */
5185 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5186 phba->sli4_hba.mbx_wq = NULL;
5188 /* Release ELS work queue */
5189 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5190 phba->sli4_hba.els_wq = NULL;
5192 /* Release FCP work queue */
5193 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5194 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
5195 kfree(phba->sli4_hba.fcp_wq);
5196 phba->sli4_hba.fcp_wq = NULL;
5198 /* Release unsolicited receive queue */
5199 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5200 phba->sli4_hba.hdr_rq = NULL;
5201 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
5202 phba->sli4_hba.dat_rq = NULL;
5204 /* Release unsolicited receive complete queue */
5205 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5206 phba->sli4_hba.rxq_cq = NULL;
5208 /* Release ELS complete queue */
5209 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5210 phba->sli4_hba.els_cq = NULL;
5212 /* Release mailbox command complete queue */
5213 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5214 phba->sli4_hba.mbx_cq = NULL;
5216 /* Release FCP response complete queue */
5217 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5218 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
5219 kfree(phba->sli4_hba.fcp_cq);
5220 phba->sli4_hba.fcp_cq = NULL;
5222 /* Release fast-path event queue */
5223 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5224 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
5225 kfree(phba->sli4_hba.fp_eq);
5226 phba->sli4_hba.fp_eq = NULL;
5228 /* Release slow-path event queue */
5229 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5230 phba->sli4_hba.sp_eq = NULL;
5236 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
5237 * @phba: pointer to lpfc hba data structure.
5239 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
5244 * ENOMEM - No availble memory
5245 * EIO - The mailbox failed to complete successfully.
5248 lpfc_sli4_queue_setup(struct lpfc_hba *phba)
5251 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
5252 int fcp_cq_index = 0;
5255 * Set up Event Queues (EQs)
5258 /* Set up slow-path event queue */
5259 if (!phba->sli4_hba.sp_eq) {
5260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5261 "0520 Slow-path EQ not allocated\n");
5264 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
5267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5268 "0521 Failed setup of slow-path EQ: "
5272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5273 "2583 Slow-path EQ setup: queue-id=%d\n",
5274 phba->sli4_hba.sp_eq->queue_id);
5276 /* Set up fast-path event queue */
5277 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
5278 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
5279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5280 "0522 Fast-path EQ (%d) not "
5281 "allocated\n", fcp_eqidx);
5282 goto out_destroy_fp_eq;
5284 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
5285 phba->cfg_fcp_imax);
5287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5288 "0523 Failed setup of fast-path EQ "
5289 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
5290 goto out_destroy_fp_eq;
5292 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5293 "2584 Fast-path EQ setup: "
5294 "queue[%d]-id=%d\n", fcp_eqidx,
5295 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
5299 * Set up Complete Queues (CQs)
5302 /* Set up slow-path MBOX Complete Queue as the first CQ */
5303 if (!phba->sli4_hba.mbx_cq) {
5304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5305 "0528 Mailbox CQ not allocated\n");
5306 goto out_destroy_fp_eq;
5308 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
5309 LPFC_MCQ, LPFC_MBOX);
5311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5312 "0529 Failed setup of slow-path mailbox CQ: "
5314 goto out_destroy_fp_eq;
5316 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5317 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
5318 phba->sli4_hba.mbx_cq->queue_id,
5319 phba->sli4_hba.sp_eq->queue_id);
5321 /* Set up slow-path ELS Complete Queue */
5322 if (!phba->sli4_hba.els_cq) {
5323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5324 "0530 ELS CQ not allocated\n");
5325 goto out_destroy_mbx_cq;
5327 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
5328 LPFC_WCQ, LPFC_ELS);
5330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5331 "0531 Failed setup of slow-path ELS CQ: "
5333 goto out_destroy_mbx_cq;
5335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5336 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
5337 phba->sli4_hba.els_cq->queue_id,
5338 phba->sli4_hba.sp_eq->queue_id);
5340 /* Set up slow-path Unsolicited Receive Complete Queue */
5341 if (!phba->sli4_hba.rxq_cq) {
5342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5343 "0532 USOL RX CQ not allocated\n");
5344 goto out_destroy_els_cq;
5346 rc = lpfc_cq_create(phba, phba->sli4_hba.rxq_cq, phba->sli4_hba.sp_eq,
5347 LPFC_RCQ, LPFC_USOL);
5349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5350 "0533 Failed setup of slow-path USOL RX CQ: "
5352 goto out_destroy_els_cq;
5354 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5355 "2587 USL CQ setup: cq-id=%d, parent eq-id=%d\n",
5356 phba->sli4_hba.rxq_cq->queue_id,
5357 phba->sli4_hba.sp_eq->queue_id);
5359 /* Set up fast-path FCP Response Complete Queue */
5360 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5361 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
5362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5363 "0526 Fast-path FCP CQ (%d) not "
5364 "allocated\n", fcp_cqidx);
5365 goto out_destroy_fcp_cq;
5367 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
5368 phba->sli4_hba.fp_eq[fcp_cqidx],
5369 LPFC_WCQ, LPFC_FCP);
5371 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5372 "0527 Failed setup of fast-path FCP "
5373 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
5374 goto out_destroy_fcp_cq;
5376 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5377 "2588 FCP CQ setup: cq[%d]-id=%d, "
5378 "parent eq[%d]-id=%d\n",
5380 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
5382 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
5386 * Set up all the Work Queues (WQs)
5389 /* Set up Mailbox Command Queue */
5390 if (!phba->sli4_hba.mbx_wq) {
5391 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5392 "0538 Slow-path MQ not allocated\n");
5393 goto out_destroy_fcp_cq;
5395 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
5396 phba->sli4_hba.mbx_cq, LPFC_MBOX);
5398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5399 "0539 Failed setup of slow-path MQ: "
5401 goto out_destroy_fcp_cq;
5403 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5404 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
5405 phba->sli4_hba.mbx_wq->queue_id,
5406 phba->sli4_hba.mbx_cq->queue_id);
5408 /* Set up slow-path ELS Work Queue */
5409 if (!phba->sli4_hba.els_wq) {
5410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5411 "0536 Slow-path ELS WQ not allocated\n");
5412 goto out_destroy_mbx_wq;
5414 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
5415 phba->sli4_hba.els_cq, LPFC_ELS);
5417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5418 "0537 Failed setup of slow-path ELS WQ: "
5420 goto out_destroy_mbx_wq;
5422 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5423 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
5424 phba->sli4_hba.els_wq->queue_id,
5425 phba->sli4_hba.els_cq->queue_id);
5427 /* Set up fast-path FCP Work Queue */
5428 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5429 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
5430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5431 "0534 Fast-path FCP WQ (%d) not "
5432 "allocated\n", fcp_wqidx);
5433 goto out_destroy_fcp_wq;
5435 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
5436 phba->sli4_hba.fcp_cq[fcp_cq_index],
5439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5440 "0535 Failed setup of fast-path FCP "
5441 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
5442 goto out_destroy_fcp_wq;
5444 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5445 "2591 FCP WQ setup: wq[%d]-id=%d, "
5446 "parent cq[%d]-id=%d\n",
5448 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
5450 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
5451 /* Round robin FCP Work Queue's Completion Queue assignment */
5452 fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
5456 * Create Receive Queue (RQ)
5458 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
5459 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5460 "0540 Receive Queue not allocated\n");
5461 goto out_destroy_fcp_wq;
5463 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
5464 phba->sli4_hba.rxq_cq, LPFC_USOL);
5466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5467 "0541 Failed setup of Receive Queue: "
5469 goto out_destroy_fcp_wq;
5471 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5472 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
5473 "parent cq-id=%d\n",
5474 phba->sli4_hba.hdr_rq->queue_id,
5475 phba->sli4_hba.dat_rq->queue_id,
5476 phba->sli4_hba.rxq_cq->queue_id);
5480 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
5481 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
5482 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5484 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5486 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
5487 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
5488 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5490 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5492 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5494 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
5495 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
5496 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5502 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
5503 * @phba: pointer to lpfc hba data structure.
5505 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
5510 * ENOMEM - No availble memory
5511 * EIO - The mailbox failed to complete successfully.
5514 lpfc_sli4_queue_unset(struct lpfc_hba *phba)
5518 /* Unset mailbox command work queue */
5519 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5520 /* Unset ELS work queue */
5521 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5522 /* Unset unsolicited receive queue */
5523 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
5524 /* Unset FCP work queue */
5525 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5526 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
5527 /* Unset mailbox command complete queue */
5528 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5529 /* Unset ELS complete queue */
5530 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5531 /* Unset unsolicited receive complete queue */
5532 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5533 /* Unset FCP response complete queue */
5534 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5535 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
5536 /* Unset fast-path event queue */
5537 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5538 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
5539 /* Unset slow-path event queue */
5540 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5544 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
5545 * @phba: pointer to lpfc hba data structure.
5547 * This routine is invoked to allocate and set up a pool of completion queue
5548 * events. The body of the completion queue event is a completion queue entry
5549 * CQE. For now, this pool is used for the interrupt service routine to queue
5550 * the following HBA completion queue events for the worker thread to process:
5551 * - Mailbox asynchronous events
5552 * - Receive queue completion unsolicited events
5553 * Later, this can be used for all the slow-path events.
5557 * -ENOMEM - No availble memory
5560 lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
5562 struct lpfc_cq_event *cq_event;
5565 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
5566 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
5568 goto out_pool_create_fail;
5569 list_add_tail(&cq_event->list,
5570 &phba->sli4_hba.sp_cqe_event_pool);
5574 out_pool_create_fail:
5575 lpfc_sli4_cq_event_pool_destroy(phba);
5580 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
5581 * @phba: pointer to lpfc hba data structure.
5583 * This routine is invoked to free the pool of completion queue events at
5584 * driver unload time. Note that, it is the responsibility of the driver
5585 * cleanup routine to free all the outstanding completion-queue events
5586 * allocated from this pool back into the pool before invoking this routine
5587 * to destroy the pool.
5590 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
5592 struct lpfc_cq_event *cq_event, *next_cq_event;
5594 list_for_each_entry_safe(cq_event, next_cq_event,
5595 &phba->sli4_hba.sp_cqe_event_pool, list) {
5596 list_del(&cq_event->list);
5602 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5603 * @phba: pointer to lpfc hba data structure.
5605 * This routine is the lock free version of the API invoked to allocate a
5606 * completion-queue event from the free pool.
5608 * Return: Pointer to the newly allocated completion-queue event if successful
5611 struct lpfc_cq_event *
5612 __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5614 struct lpfc_cq_event *cq_event = NULL;
5616 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
5617 struct lpfc_cq_event, list);
5622 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5623 * @phba: pointer to lpfc hba data structure.
5625 * This routine is the lock version of the API invoked to allocate a
5626 * completion-queue event from the free pool.
5628 * Return: Pointer to the newly allocated completion-queue event if successful
5631 struct lpfc_cq_event *
5632 lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5634 struct lpfc_cq_event *cq_event;
5635 unsigned long iflags;
5637 spin_lock_irqsave(&phba->hbalock, iflags);
5638 cq_event = __lpfc_sli4_cq_event_alloc(phba);
5639 spin_unlock_irqrestore(&phba->hbalock, iflags);
5644 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5645 * @phba: pointer to lpfc hba data structure.
5646 * @cq_event: pointer to the completion queue event to be freed.
5648 * This routine is the lock free version of the API invoked to release a
5649 * completion-queue event back into the free pool.
5652 __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5653 struct lpfc_cq_event *cq_event)
5655 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
5659 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5660 * @phba: pointer to lpfc hba data structure.
5661 * @cq_event: pointer to the completion queue event to be freed.
5663 * This routine is the lock version of the API invoked to release a
5664 * completion-queue event back into the free pool.
5667 lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5668 struct lpfc_cq_event *cq_event)
5670 unsigned long iflags;
5671 spin_lock_irqsave(&phba->hbalock, iflags);
5672 __lpfc_sli4_cq_event_release(phba, cq_event);
5673 spin_unlock_irqrestore(&phba->hbalock, iflags);
5677 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
5678 * @phba: pointer to lpfc hba data structure.
5680 * This routine is to free all the pending completion-queue events to the
5681 * back into the free pool for device reset.
5684 lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
5687 struct lpfc_cq_event *cqe;
5688 unsigned long iflags;
5690 /* Retrieve all the pending WCQEs from pending WCQE lists */
5691 spin_lock_irqsave(&phba->hbalock, iflags);
5692 /* Pending FCP XRI abort events */
5693 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
5695 /* Pending ELS XRI abort events */
5696 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
5698 /* Pending asynnc events */
5699 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
5701 spin_unlock_irqrestore(&phba->hbalock, iflags);
5703 while (!list_empty(&cqelist)) {
5704 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
5705 lpfc_sli4_cq_event_release(phba, cqe);
5710 * lpfc_pci_function_reset - Reset pci function.
5711 * @phba: pointer to lpfc hba data structure.
5713 * This routine is invoked to request a PCI function reset. It will destroys
5714 * all resources assigned to the PCI function which originates this request.
5718 * ENOMEM - No availble memory
5719 * EIO - The mailbox failed to complete successfully.
5722 lpfc_pci_function_reset(struct lpfc_hba *phba)
5724 LPFC_MBOXQ_t *mboxq;
5726 uint32_t shdr_status, shdr_add_status;
5727 union lpfc_sli4_cfg_shdr *shdr;
5729 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5732 "0494 Unable to allocate memory for issuing "
5733 "SLI_FUNCTION_RESET mailbox command\n");
5737 /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
5738 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5739 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
5740 LPFC_SLI4_MBX_EMBED);
5741 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5742 shdr = (union lpfc_sli4_cfg_shdr *)
5743 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5744 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5745 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5746 if (rc != MBX_TIMEOUT)
5747 mempool_free(mboxq, phba->mbox_mem_pool);
5748 if (shdr_status || shdr_add_status || rc) {
5749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5750 "0495 SLI_FUNCTION_RESET mailbox failed with "
5751 "status x%x add_status x%x, mbx status x%x\n",
5752 shdr_status, shdr_add_status, rc);
5759 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
5760 * @phba: pointer to lpfc hba data structure.
5761 * @cnt: number of nop mailbox commands to send.
5763 * This routine is invoked to send a number @cnt of NOP mailbox command and
5764 * wait for each command to complete.
5766 * Return: the number of NOP mailbox command completed.
5769 lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
5771 LPFC_MBOXQ_t *mboxq;
5772 int length, cmdsent;
5775 uint32_t shdr_status, shdr_add_status;
5776 union lpfc_sli4_cfg_shdr *shdr;
5779 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5780 "2518 Requested to send 0 NOP mailbox cmd\n");
5784 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5787 "2519 Unable to allocate memory for issuing "
5788 "NOP mailbox command\n");
5792 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
5793 length = (sizeof(struct lpfc_mbx_nop) -
5794 sizeof(struct lpfc_sli4_cfg_mhdr));
5795 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5796 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
5798 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5799 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
5800 if (!phba->sli4_hba.intr_enable)
5801 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5803 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
5804 if (rc == MBX_TIMEOUT)
5806 /* Check return status */
5807 shdr = (union lpfc_sli4_cfg_shdr *)
5808 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5809 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5810 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
5812 if (shdr_status || shdr_add_status || rc) {
5813 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5814 "2520 NOP mailbox command failed "
5815 "status x%x add_status x%x mbx "
5816 "status x%x\n", shdr_status,
5817 shdr_add_status, rc);
5822 if (rc != MBX_TIMEOUT)
5823 mempool_free(mboxq, phba->mbox_mem_pool);
5829 * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
5830 * @phba: pointer to lpfc hba data structure.
5833 * This routine is invoked to unregister a FCFI from device.
5836 lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
5841 unsigned long flags;
5843 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5848 lpfc_unreg_fcfi(mbox, fcfi);
5850 if (!phba->sli4_hba.intr_enable)
5851 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5853 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5854 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5856 if (rc != MBX_TIMEOUT)
5857 mempool_free(mbox, phba->mbox_mem_pool);
5858 if (rc != MBX_SUCCESS)
5859 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5860 "2517 Unregister FCFI command failed "
5861 "status %d, mbxStatus x%x\n", rc,
5862 bf_get(lpfc_mqe_status, &mbox->u.mqe));
5864 spin_lock_irqsave(&phba->hbalock, flags);
5865 /* Mark the FCFI is no longer registered */
5866 phba->fcf.fcf_flag &=
5867 ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
5868 spin_unlock_irqrestore(&phba->hbalock, flags);
5873 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
5874 * @phba: pointer to lpfc hba data structure.
5876 * This routine is invoked to set up the PCI device memory space for device
5877 * with SLI-4 interface spec.
5881 * other values - error
5884 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
5886 struct pci_dev *pdev;
5887 unsigned long bar0map_len, bar1map_len, bar2map_len;
5888 int error = -ENODEV;
5890 /* Obtain PCI device reference */
5894 pdev = phba->pcidev;
5896 /* Set the device DMA mask size */
5897 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
5898 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
5901 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
5902 * number of bytes required by each mapping. They are actually
5903 * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
5905 phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
5906 bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
5908 phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
5909 bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
5911 phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
5912 bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
5914 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
5915 phba->sli4_hba.conf_regs_memmap_p =
5916 ioremap(phba->pci_bar0_map, bar0map_len);
5917 if (!phba->sli4_hba.conf_regs_memmap_p) {
5918 dev_printk(KERN_ERR, &pdev->dev,
5919 "ioremap failed for SLI4 PCI config registers.\n");
5923 /* Map SLI4 HBA Control Register base to a kernel virtual address. */
5924 phba->sli4_hba.ctrl_regs_memmap_p =
5925 ioremap(phba->pci_bar1_map, bar1map_len);
5926 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
5927 dev_printk(KERN_ERR, &pdev->dev,
5928 "ioremap failed for SLI4 HBA control registers.\n");
5929 goto out_iounmap_conf;
5932 /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
5933 phba->sli4_hba.drbl_regs_memmap_p =
5934 ioremap(phba->pci_bar2_map, bar2map_len);
5935 if (!phba->sli4_hba.drbl_regs_memmap_p) {
5936 dev_printk(KERN_ERR, &pdev->dev,
5937 "ioremap failed for SLI4 HBA doorbell registers.\n");
5938 goto out_iounmap_ctrl;
5941 /* Set up BAR0 PCI config space register memory map */
5942 lpfc_sli4_bar0_register_memmap(phba);
5944 /* Set up BAR1 register memory map */
5945 lpfc_sli4_bar1_register_memmap(phba);
5947 /* Set up BAR2 register memory map */
5948 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
5950 goto out_iounmap_all;
5955 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
5957 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
5959 iounmap(phba->sli4_hba.conf_regs_memmap_p);
5965 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
5966 * @phba: pointer to lpfc hba data structure.
5968 * This routine is invoked to unset the PCI device memory space for device
5969 * with SLI-4 interface spec.
5972 lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
5974 struct pci_dev *pdev;
5976 /* Obtain PCI device reference */
5980 pdev = phba->pcidev;
5982 /* Free coherent DMA memory allocated */
5984 /* Unmap I/O memory space */
5985 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
5986 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
5987 iounmap(phba->sli4_hba.conf_regs_memmap_p);
5993 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
5994 * @phba: pointer to lpfc hba data structure.
5996 * This routine is invoked to enable the MSI-X interrupt vectors to device
5997 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
5998 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
5999 * invoked, enables either all or nothing, depending on the current
6000 * availability of PCI vector resources. The device driver is responsible
6001 * for calling the individual request_irq() to register each MSI-X vector
6002 * with a interrupt handler, which is done in this function. Note that
6003 * later when device is unloading, the driver should always call free_irq()
6004 * on all MSI-X vectors it has done request_irq() on before calling
6005 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
6006 * will be left with MSI-X enabled and leaks its vectors.
6010 * other values - error
6013 lpfc_sli_enable_msix(struct lpfc_hba *phba)
6018 /* Set up MSI-X multi-message vectors */
6019 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6020 phba->msix_entries[i].entry = i;
6022 /* Configure MSI-X capability structure */
6023 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
6024 ARRAY_SIZE(phba->msix_entries));
6026 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6027 "0420 PCI enable MSI-X failed (%d)\n", rc);
6030 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6031 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6032 "0477 MSI-X entry[%d]: vector=x%x "
6034 phba->msix_entries[i].vector,
6035 phba->msix_entries[i].entry);
6037 * Assign MSI-X vectors to interrupt handlers
6040 /* vector-0 is associated to slow-path handler */
6041 rc = request_irq(phba->msix_entries[0].vector,
6042 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
6043 LPFC_SP_DRIVER_HANDLER_NAME, phba);
6045 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6046 "0421 MSI-X slow-path request_irq failed "
6051 /* vector-1 is associated to fast-path handler */
6052 rc = request_irq(phba->msix_entries[1].vector,
6053 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
6054 LPFC_FP_DRIVER_HANDLER_NAME, phba);
6057 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6058 "0429 MSI-X fast-path request_irq failed "
6064 * Configure HBA MSI-X attention conditions to messages
6066 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6071 "0474 Unable to allocate memory for issuing "
6072 "MBOX_CONFIG_MSI command\n");
6075 rc = lpfc_config_msi(phba, pmb);
6078 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6079 if (rc != MBX_SUCCESS) {
6080 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
6081 "0351 Config MSI mailbox command failed, "
6082 "mbxCmd x%x, mbxStatus x%x\n",
6083 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
6087 /* Free memory allocated for mailbox command */
6088 mempool_free(pmb, phba->mbox_mem_pool);
6092 /* Free memory allocated for mailbox command */
6093 mempool_free(pmb, phba->mbox_mem_pool);
6096 /* free the irq already requested */
6097 free_irq(phba->msix_entries[1].vector, phba);
6100 /* free the irq already requested */
6101 free_irq(phba->msix_entries[0].vector, phba);
6104 /* Unconfigure MSI-X capability structure */
6105 pci_disable_msix(phba->pcidev);
6110 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
6111 * @phba: pointer to lpfc hba data structure.
6113 * This routine is invoked to release the MSI-X vectors and then disable the
6114 * MSI-X interrupt mode to device with SLI-3 interface spec.
6117 lpfc_sli_disable_msix(struct lpfc_hba *phba)
6121 /* Free up MSI-X multi-message vectors */
6122 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6123 free_irq(phba->msix_entries[i].vector, phba);
6125 pci_disable_msix(phba->pcidev);
6131 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
6132 * @phba: pointer to lpfc hba data structure.
6134 * This routine is invoked to enable the MSI interrupt mode to device with
6135 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
6136 * enable the MSI vector. The device driver is responsible for calling the
6137 * request_irq() to register MSI vector with a interrupt the handler, which
6138 * is done in this function.
6142 * other values - error
6145 lpfc_sli_enable_msi(struct lpfc_hba *phba)
6149 rc = pci_enable_msi(phba->pcidev);
6151 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6152 "0462 PCI enable MSI mode success.\n");
6154 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6155 "0471 PCI enable MSI mode failed (%d)\n", rc);
6159 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
6160 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6162 pci_disable_msi(phba->pcidev);
6163 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6164 "0478 MSI request_irq failed (%d)\n", rc);
6170 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
6171 * @phba: pointer to lpfc hba data structure.
6173 * This routine is invoked to disable the MSI interrupt mode to device with
6174 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
6175 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6176 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6180 lpfc_sli_disable_msi(struct lpfc_hba *phba)
6182 free_irq(phba->pcidev->irq, phba);
6183 pci_disable_msi(phba->pcidev);
6188 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
6189 * @phba: pointer to lpfc hba data structure.
6191 * This routine is invoked to enable device interrupt and associate driver's
6192 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
6193 * spec. Depends on the interrupt mode configured to the driver, the driver
6194 * will try to fallback from the configured interrupt mode to an interrupt
6195 * mode which is supported by the platform, kernel, and device in the order
6197 * MSI-X -> MSI -> IRQ.
6201 * other values - error
6204 lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
6206 uint32_t intr_mode = LPFC_INTR_ERROR;
6209 if (cfg_mode == 2) {
6210 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
6211 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
6213 /* Now, try to enable MSI-X interrupt mode */
6214 retval = lpfc_sli_enable_msix(phba);
6216 /* Indicate initialization to MSI-X mode */
6217 phba->intr_type = MSIX;
6223 /* Fallback to MSI if MSI-X initialization failed */
6224 if (cfg_mode >= 1 && phba->intr_type == NONE) {
6225 retval = lpfc_sli_enable_msi(phba);
6227 /* Indicate initialization to MSI mode */
6228 phba->intr_type = MSI;
6233 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6234 if (phba->intr_type == NONE) {
6235 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
6236 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6238 /* Indicate initialization to INTx mode */
6239 phba->intr_type = INTx;
6247 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
6248 * @phba: pointer to lpfc hba data structure.
6250 * This routine is invoked to disable device interrupt and disassociate the
6251 * driver's interrupt handler(s) from interrupt vector(s) to device with
6252 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
6253 * release the interrupt vector(s) for the message signaled interrupt.
6256 lpfc_sli_disable_intr(struct lpfc_hba *phba)
6258 /* Disable the currently initialized interrupt mode */
6259 if (phba->intr_type == MSIX)
6260 lpfc_sli_disable_msix(phba);
6261 else if (phba->intr_type == MSI)
6262 lpfc_sli_disable_msi(phba);
6263 else if (phba->intr_type == INTx)
6264 free_irq(phba->pcidev->irq, phba);
6266 /* Reset interrupt management states */
6267 phba->intr_type = NONE;
6268 phba->sli.slistat.sli_intr = 0;
6274 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
6275 * @phba: pointer to lpfc hba data structure.
6277 * This routine is invoked to enable the MSI-X interrupt vectors to device
6278 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
6279 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
6280 * enables either all or nothing, depending on the current availability of
6281 * PCI vector resources. The device driver is responsible for calling the
6282 * individual request_irq() to register each MSI-X vector with a interrupt
6283 * handler, which is done in this function. Note that later when device is
6284 * unloading, the driver should always call free_irq() on all MSI-X vectors
6285 * it has done request_irq() on before calling pci_disable_msix(). Failure
6286 * to do so results in a BUG_ON() and a device will be left with MSI-X
6287 * enabled and leaks its vectors.
6291 * other values - error
6294 lpfc_sli4_enable_msix(struct lpfc_hba *phba)
6298 /* Set up MSI-X multi-message vectors */
6299 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6300 phba->sli4_hba.msix_entries[index].entry = index;
6302 /* Configure MSI-X capability structure */
6303 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
6304 phba->sli4_hba.cfg_eqn);
6306 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6307 "0484 PCI enable MSI-X failed (%d)\n", rc);
6310 /* Log MSI-X vector assignment */
6311 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6312 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6313 "0489 MSI-X entry[%d]: vector=x%x "
6314 "message=%d\n", index,
6315 phba->sli4_hba.msix_entries[index].vector,
6316 phba->sli4_hba.msix_entries[index].entry);
6318 * Assign MSI-X vectors to interrupt handlers
6321 /* The first vector must associated to slow-path handler for MQ */
6322 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
6323 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
6324 LPFC_SP_DRIVER_HANDLER_NAME, phba);
6326 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6327 "0485 MSI-X slow-path request_irq failed "
6332 /* The rest of the vector(s) are associated to fast-path handler(s) */
6333 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
6334 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
6335 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
6336 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
6337 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
6338 LPFC_FP_DRIVER_HANDLER_NAME,
6339 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6341 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6342 "0486 MSI-X fast-path (%d) "
6343 "request_irq failed (%d)\n", index, rc);
6351 /* free the irq already requested */
6352 for (--index; index >= 1; index--)
6353 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
6354 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6356 /* free the irq already requested */
6357 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6360 /* Unconfigure MSI-X capability structure */
6361 pci_disable_msix(phba->pcidev);
6366 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
6367 * @phba: pointer to lpfc hba data structure.
6369 * This routine is invoked to release the MSI-X vectors and then disable the
6370 * MSI-X interrupt mode to device with SLI-4 interface spec.
6373 lpfc_sli4_disable_msix(struct lpfc_hba *phba)
6377 /* Free up MSI-X multi-message vectors */
6378 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6380 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
6381 free_irq(phba->sli4_hba.msix_entries[index].vector,
6382 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6384 pci_disable_msix(phba->pcidev);
6390 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
6391 * @phba: pointer to lpfc hba data structure.
6393 * This routine is invoked to enable the MSI interrupt mode to device with
6394 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
6395 * to enable the MSI vector. The device driver is responsible for calling
6396 * the request_irq() to register MSI vector with a interrupt the handler,
6397 * which is done in this function.
6401 * other values - error
6404 lpfc_sli4_enable_msi(struct lpfc_hba *phba)
6408 rc = pci_enable_msi(phba->pcidev);
6410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6411 "0487 PCI enable MSI mode success.\n");
6413 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6414 "0488 PCI enable MSI mode failed (%d)\n", rc);
6418 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6419 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6421 pci_disable_msi(phba->pcidev);
6422 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6423 "0490 MSI request_irq failed (%d)\n", rc);
6426 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
6427 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6428 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6435 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
6436 * @phba: pointer to lpfc hba data structure.
6438 * This routine is invoked to disable the MSI interrupt mode to device with
6439 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
6440 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6441 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6445 lpfc_sli4_disable_msi(struct lpfc_hba *phba)
6447 free_irq(phba->pcidev->irq, phba);
6448 pci_disable_msi(phba->pcidev);
6453 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
6454 * @phba: pointer to lpfc hba data structure.
6456 * This routine is invoked to enable device interrupt and associate driver's
6457 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
6458 * interface spec. Depends on the interrupt mode configured to the driver,
6459 * the driver will try to fallback from the configured interrupt mode to an
6460 * interrupt mode which is supported by the platform, kernel, and device in
6462 * MSI-X -> MSI -> IRQ.
6466 * other values - error
6469 lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
6471 uint32_t intr_mode = LPFC_INTR_ERROR;
6474 if (cfg_mode == 2) {
6475 /* Preparation before conf_msi mbox cmd */
6478 /* Now, try to enable MSI-X interrupt mode */
6479 retval = lpfc_sli4_enable_msix(phba);
6481 /* Indicate initialization to MSI-X mode */
6482 phba->intr_type = MSIX;
6488 /* Fallback to MSI if MSI-X initialization failed */
6489 if (cfg_mode >= 1 && phba->intr_type == NONE) {
6490 retval = lpfc_sli4_enable_msi(phba);
6492 /* Indicate initialization to MSI mode */
6493 phba->intr_type = MSI;
6498 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6499 if (phba->intr_type == NONE) {
6500 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6501 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6503 /* Indicate initialization to INTx mode */
6504 phba->intr_type = INTx;
6506 for (index = 0; index < phba->cfg_fcp_eq_count;
6508 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6509 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6517 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
6518 * @phba: pointer to lpfc hba data structure.
6520 * This routine is invoked to disable device interrupt and disassociate
6521 * the driver's interrupt handler(s) from interrupt vector(s) to device
6522 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
6523 * will release the interrupt vector(s) for the message signaled interrupt.
6526 lpfc_sli4_disable_intr(struct lpfc_hba *phba)
6528 /* Disable the currently initialized interrupt mode */
6529 if (phba->intr_type == MSIX)
6530 lpfc_sli4_disable_msix(phba);
6531 else if (phba->intr_type == MSI)
6532 lpfc_sli4_disable_msi(phba);
6533 else if (phba->intr_type == INTx)
6534 free_irq(phba->pcidev->irq, phba);
6536 /* Reset interrupt management states */
6537 phba->intr_type = NONE;
6538 phba->sli.slistat.sli_intr = 0;
6544 * lpfc_unset_hba - Unset SLI3 hba device initialization
6545 * @phba: pointer to lpfc hba data structure.
6547 * This routine is invoked to unset the HBA device initialization steps to
6548 * a device with SLI-3 interface spec.
6551 lpfc_unset_hba(struct lpfc_hba *phba)
6553 struct lpfc_vport *vport = phba->pport;
6554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6556 spin_lock_irq(shost->host_lock);
6557 vport->load_flag |= FC_UNLOADING;
6558 spin_unlock_irq(shost->host_lock);
6560 lpfc_stop_hba_timers(phba);
6562 phba->pport->work_port_events = 0;
6564 lpfc_sli_hba_down(phba);
6566 lpfc_sli_brdrestart(phba);
6568 lpfc_sli_disable_intr(phba);
6574 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
6575 * @phba: pointer to lpfc hba data structure.
6577 * This routine is invoked to unset the HBA device initialization steps to
6578 * a device with SLI-4 interface spec.
6581 lpfc_sli4_unset_hba(struct lpfc_hba *phba)
6583 struct lpfc_vport *vport = phba->pport;
6584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6586 spin_lock_irq(shost->host_lock);
6587 vport->load_flag |= FC_UNLOADING;
6588 spin_unlock_irq(shost->host_lock);
6590 phba->pport->work_port_events = 0;
6592 lpfc_sli4_hba_down(phba);
6594 lpfc_sli4_disable_intr(phba);
6600 * lpfc_sli4_hba_unset - Unset the fcoe hba
6601 * @phba: Pointer to HBA context object.
6603 * This function is called in the SLI4 code path to reset the HBA's FCoE
6604 * function. The caller is not required to hold any lock. This routine
6605 * issues PCI function reset mailbox command to reset the FCoE function.
6606 * At the end of the function, it calls lpfc_hba_down_post function to
6607 * free any pending commands.
6610 lpfc_sli4_hba_unset(struct lpfc_hba *phba)
6613 LPFC_MBOXQ_t *mboxq;
6615 lpfc_stop_hba_timers(phba);
6616 phba->sli4_hba.intr_enable = 0;
6619 * Gracefully wait out the potential current outstanding asynchronous
6623 /* First, block any pending async mailbox command from posted */
6624 spin_lock_irq(&phba->hbalock);
6625 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
6626 spin_unlock_irq(&phba->hbalock);
6627 /* Now, trying to wait it out if we can */
6628 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6630 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
6633 /* Forcefully release the outstanding mailbox command if timed out */
6634 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6635 spin_lock_irq(&phba->hbalock);
6636 mboxq = phba->sli.mbox_active;
6637 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
6638 __lpfc_mbox_cmpl_put(phba, mboxq);
6639 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6640 phba->sli.mbox_active = NULL;
6641 spin_unlock_irq(&phba->hbalock);
6644 /* Tear down the queues in the HBA */
6645 lpfc_sli4_queue_unset(phba);
6647 /* Disable PCI subsystem interrupt */
6648 lpfc_sli4_disable_intr(phba);
6650 /* Stop kthread signal shall trigger work_done one more time */
6651 kthread_stop(phba->worker_thread);
6653 /* Stop the SLI4 device port */
6654 phba->pport->work_port_events = 0;
6658 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
6659 * @pdev: pointer to PCI device
6660 * @pid: pointer to PCI device identifier
6662 * This routine is to be called to attach a device with SLI-3 interface spec
6663 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
6664 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
6665 * information of the device and driver to see if the driver state that it can
6666 * support this kind of device. If the match is successful, the driver core
6667 * invokes this routine. If this routine determines it can claim the HBA, it
6668 * does all the initialization that it needs to do to handle the HBA properly.
6671 * 0 - driver can claim the device
6672 * negative value - driver can not claim the device
6674 static int __devinit
6675 lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
6677 struct lpfc_hba *phba;
6678 struct lpfc_vport *vport = NULL;
6680 uint32_t cfg_mode, intr_mode;
6682 /* Allocate memory for HBA structure */
6683 phba = lpfc_hba_alloc(pdev);
6687 /* Perform generic PCI device enabling operation */
6688 error = lpfc_enable_pci_dev(phba);
6690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6691 "1401 Failed to enable pci device.\n");
6695 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
6696 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
6698 goto out_disable_pci_dev;
6700 /* Set up SLI-3 specific device PCI memory space */
6701 error = lpfc_sli_pci_mem_setup(phba);
6703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6704 "1402 Failed to set up pci memory space.\n");
6705 goto out_disable_pci_dev;
6708 /* Set up phase-1 common device driver resources */
6709 error = lpfc_setup_driver_resource_phase1(phba);
6711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6712 "1403 Failed to set up driver resource.\n");
6713 goto out_unset_pci_mem_s3;
6716 /* Set up SLI-3 specific device driver resources */
6717 error = lpfc_sli_driver_resource_setup(phba);
6719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6720 "1404 Failed to set up driver resource.\n");
6721 goto out_unset_pci_mem_s3;
6724 /* Initialize and populate the iocb list per host */
6725 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
6727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6728 "1405 Failed to initialize iocb list.\n");
6729 goto out_unset_driver_resource_s3;
6732 /* Set up common device driver resources */
6733 error = lpfc_setup_driver_resource_phase2(phba);
6735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6736 "1406 Failed to set up driver resource.\n");
6737 goto out_free_iocb_list;
6740 /* Create SCSI host to the physical port */
6741 error = lpfc_create_shost(phba);
6743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6744 "1407 Failed to create scsi host.\n");
6745 goto out_unset_driver_resource;
6748 /* Configure sysfs attributes */
6749 vport = phba->pport;
6750 error = lpfc_alloc_sysfs_attr(vport);
6752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6753 "1476 Failed to allocate sysfs attr\n");
6754 goto out_destroy_shost;
6757 /* Now, trying to enable interrupt and bring up the device */
6758 cfg_mode = phba->cfg_use_msi;
6760 /* Put device to a known state before enabling interrupt */
6761 lpfc_stop_port(phba);
6762 /* Configure and enable interrupt */
6763 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
6764 if (intr_mode == LPFC_INTR_ERROR) {
6765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6766 "0431 Failed to enable interrupt.\n");
6768 goto out_free_sysfs_attr;
6770 /* SLI-3 HBA setup */
6771 if (lpfc_sli_hba_setup(phba)) {
6772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6773 "1477 Failed to set up hba\n");
6775 goto out_remove_device;
6778 /* Wait 50ms for the interrupts of previous mailbox commands */
6780 /* Check active interrupts on message signaled interrupts */
6781 if (intr_mode == 0 ||
6782 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
6783 /* Log the current active interrupt mode */
6784 phba->intr_mode = intr_mode;
6785 lpfc_log_intr_mode(phba, intr_mode);
6788 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6789 "0447 Configure interrupt mode (%d) "
6790 "failed active interrupt test.\n",
6792 /* Disable the current interrupt mode */
6793 lpfc_sli_disable_intr(phba);
6794 /* Try next level of interrupt mode */
6795 cfg_mode = --intr_mode;
6799 /* Perform post initialization setup */
6800 lpfc_post_init_setup(phba);
6802 /* Check if there are static vports to be created. */
6803 lpfc_create_static_vport(phba);
6808 lpfc_unset_hba(phba);
6809 out_free_sysfs_attr:
6810 lpfc_free_sysfs_attr(vport);
6812 lpfc_destroy_shost(phba);
6813 out_unset_driver_resource:
6814 lpfc_unset_driver_resource_phase2(phba);
6816 lpfc_free_iocb_list(phba);
6817 out_unset_driver_resource_s3:
6818 lpfc_sli_driver_resource_unset(phba);
6819 out_unset_pci_mem_s3:
6820 lpfc_sli_pci_mem_unset(phba);
6821 out_disable_pci_dev:
6822 lpfc_disable_pci_dev(phba);
6824 lpfc_hba_free(phba);
6829 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
6830 * @pdev: pointer to PCI device
6832 * This routine is to be called to disattach a device with SLI-3 interface
6833 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
6834 * removed from PCI bus, it performs all the necessary cleanup for the HBA
6835 * device to be removed from the PCI subsystem properly.
6837 static void __devexit
6838 lpfc_pci_remove_one_s3(struct pci_dev *pdev)
6840 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6841 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6842 struct lpfc_vport **vports;
6843 struct lpfc_hba *phba = vport->phba;
6845 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
6847 spin_lock_irq(&phba->hbalock);
6848 vport->load_flag |= FC_UNLOADING;
6849 spin_unlock_irq(&phba->hbalock);
6851 lpfc_free_sysfs_attr(vport);
6853 /* Release all the vports against this physical port */
6854 vports = lpfc_create_vport_work_array(phba);
6856 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
6857 fc_vport_terminate(vports[i]->fc_vport);
6858 lpfc_destroy_vport_work_array(phba, vports);
6860 /* Remove FC host and then SCSI host with the physical port */
6861 fc_remove_host(shost);
6862 scsi_remove_host(shost);
6863 lpfc_cleanup(vport);
6866 * Bring down the SLI Layer. This step disable all interrupts,
6867 * clears the rings, discards all mailbox commands, and resets
6871 /* HBA interrupt will be diabled after this call */
6872 lpfc_sli_hba_down(phba);
6873 /* Stop kthread signal shall trigger work_done one more time */
6874 kthread_stop(phba->worker_thread);
6875 /* Final cleanup of txcmplq and reset the HBA */
6876 lpfc_sli_brdrestart(phba);
6878 lpfc_stop_hba_timers(phba);
6879 spin_lock_irq(&phba->hbalock);
6880 list_del_init(&vport->listentry);
6881 spin_unlock_irq(&phba->hbalock);
6883 lpfc_debugfs_terminate(vport);
6885 /* Disable interrupt */
6886 lpfc_sli_disable_intr(phba);
6888 pci_set_drvdata(pdev, NULL);
6889 scsi_host_put(shost);
6892 * Call scsi_free before mem_free since scsi bufs are released to their
6893 * corresponding pools here.
6895 lpfc_scsi_free(phba);
6896 lpfc_mem_free_all(phba);
6898 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6899 phba->hbqslimp.virt, phba->hbqslimp.phys);
6901 /* Free resources associated with SLI2 interface */
6902 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6903 phba->slim2p.virt, phba->slim2p.phys);
6905 /* unmap adapter SLIM and Control Registers */
6906 iounmap(phba->ctrl_regs_memmap_p);
6907 iounmap(phba->slim_memmap_p);
6909 lpfc_hba_free(phba);
6911 pci_release_selected_regions(pdev, bars);
6912 pci_disable_device(pdev);
6916 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
6917 * @pdev: pointer to PCI device
6918 * @msg: power management message
6920 * This routine is to be called from the kernel's PCI subsystem to support
6921 * system Power Management (PM) to device with SLI-3 interface spec. When
6922 * PM invokes this method, it quiesces the device by stopping the driver's
6923 * worker thread for the device, turning off device's interrupt and DMA,
6924 * and bring the device offline. Note that as the driver implements the
6925 * minimum PM requirements to a power-aware driver's PM support for the
6926 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
6927 * to the suspend() method call will be treated as SUSPEND and the driver will
6928 * fully reinitialize its device during resume() method call, the driver will
6929 * set device to PCI_D3hot state in PCI config space instead of setting it
6930 * according to the @msg provided by the PM.
6933 * 0 - driver suspended the device
6937 lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
6939 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6940 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
6942 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6943 "0473 PCI device Power Management suspend.\n");
6945 /* Bring down the device */
6946 lpfc_offline_prep(phba);
6948 kthread_stop(phba->worker_thread);
6950 /* Disable interrupt from device */
6951 lpfc_sli_disable_intr(phba);
6953 /* Save device state to PCI config space */
6954 pci_save_state(pdev);
6955 pci_set_power_state(pdev, PCI_D3hot);
6961 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
6962 * @pdev: pointer to PCI device
6964 * This routine is to be called from the kernel's PCI subsystem to support
6965 * system Power Management (PM) to device with SLI-3 interface spec. When PM
6966 * invokes this method, it restores the device's PCI config space state and
6967 * fully reinitializes the device and brings it online. Note that as the
6968 * driver implements the minimum PM requirements to a power-aware driver's
6969 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
6970 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
6971 * driver will fully reinitialize its device during resume() method call,
6972 * the device will be set to PCI_D0 directly in PCI config space before
6973 * restoring the state.
6976 * 0 - driver suspended the device
6980 lpfc_pci_resume_one_s3(struct pci_dev *pdev)
6982 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6983 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
6987 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6988 "0452 PCI device Power Management resume.\n");
6990 /* Restore device state from PCI config space */
6991 pci_set_power_state(pdev, PCI_D0);
6992 pci_restore_state(pdev);
6993 if (pdev->is_busmaster)
6994 pci_set_master(pdev);
6996 /* Startup the kernel thread for this host adapter. */
6997 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6998 "lpfc_worker_%d", phba->brd_no);
6999 if (IS_ERR(phba->worker_thread)) {
7000 error = PTR_ERR(phba->worker_thread);
7001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7002 "0434 PM resume failed to start worker "
7003 "thread: error=x%x.\n", error);
7007 /* Configure and enable interrupt */
7008 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
7009 if (intr_mode == LPFC_INTR_ERROR) {
7010 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7011 "0430 PM resume Failed to enable interrupt\n");
7014 phba->intr_mode = intr_mode;
7016 /* Restart HBA and bring it online */
7017 lpfc_sli_brdrestart(phba);
7020 /* Log the current active interrupt mode */
7021 lpfc_log_intr_mode(phba, phba->intr_mode);
7027 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
7028 * @pdev: pointer to PCI device.
7029 * @state: the current PCI connection state.
7031 * This routine is called from the PCI subsystem for I/O error handling to
7032 * device with SLI-3 interface spec. This function is called by the PCI
7033 * subsystem after a PCI bus error affecting this device has been detected.
7034 * When this function is invoked, it will need to stop all the I/Os and
7035 * interrupt(s) to the device. Once that is done, it will return
7036 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
7040 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7041 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7043 static pci_ers_result_t
7044 lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
7046 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7047 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7048 struct lpfc_sli *psli = &phba->sli;
7049 struct lpfc_sli_ring *pring;
7051 if (state == pci_channel_io_perm_failure) {
7052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7053 "0472 PCI channel I/O permanent failure\n");
7054 /* Block all SCSI devices' I/Os on the host */
7055 lpfc_scsi_dev_block(phba);
7056 /* Clean up all driver's outstanding SCSI I/Os */
7057 lpfc_sli_flush_fcp_rings(phba);
7058 return PCI_ERS_RESULT_DISCONNECT;
7061 pci_disable_device(pdev);
7063 * There may be I/Os dropped by the firmware.
7064 * Error iocb (I/O) on txcmplq and let the SCSI layer
7065 * retry it after re-establishing link.
7067 pring = &psli->ring[psli->fcp_ring];
7068 lpfc_sli_abort_iocb_ring(phba, pring);
7070 /* Disable interrupt */
7071 lpfc_sli_disable_intr(phba);
7073 /* Request a slot reset. */
7074 return PCI_ERS_RESULT_NEED_RESET;
7078 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
7079 * @pdev: pointer to PCI device.
7081 * This routine is called from the PCI subsystem for error handling to
7082 * device with SLI-3 interface spec. This is called after PCI bus has been
7083 * reset to restart the PCI card from scratch, as if from a cold-boot.
7084 * During the PCI subsystem error recovery, after driver returns
7085 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7086 * recovery and then call this routine before calling the .resume method
7087 * to recover the device. This function will initialize the HBA device,
7088 * enable the interrupt, but it will just put the HBA to offline state
7089 * without passing any I/O traffic.
7092 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7093 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7095 static pci_ers_result_t
7096 lpfc_io_slot_reset_s3(struct pci_dev *pdev)
7098 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7099 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7100 struct lpfc_sli *psli = &phba->sli;
7103 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
7104 if (pci_enable_device_mem(pdev)) {
7105 printk(KERN_ERR "lpfc: Cannot re-enable "
7106 "PCI device after reset.\n");
7107 return PCI_ERS_RESULT_DISCONNECT;
7110 pci_restore_state(pdev);
7111 if (pdev->is_busmaster)
7112 pci_set_master(pdev);
7114 spin_lock_irq(&phba->hbalock);
7115 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
7116 spin_unlock_irq(&phba->hbalock);
7118 /* Configure and enable interrupt */
7119 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
7120 if (intr_mode == LPFC_INTR_ERROR) {
7121 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7122 "0427 Cannot re-enable interrupt after "
7124 return PCI_ERS_RESULT_DISCONNECT;
7126 phba->intr_mode = intr_mode;
7128 /* Take device offline; this will perform cleanup */
7130 lpfc_sli_brdrestart(phba);
7132 /* Log the current active interrupt mode */
7133 lpfc_log_intr_mode(phba, phba->intr_mode);
7135 return PCI_ERS_RESULT_RECOVERED;
7139 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
7140 * @pdev: pointer to PCI device
7142 * This routine is called from the PCI subsystem for error handling to device
7143 * with SLI-3 interface spec. It is called when kernel error recovery tells
7144 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7145 * error recovery. After this call, traffic can start to flow from this device
7149 lpfc_io_resume_s3(struct pci_dev *pdev)
7151 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7152 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7158 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
7159 * @phba: pointer to lpfc hba data structure.
7161 * returns the number of ELS/CT IOCBs to reserve
7164 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
7166 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
7170 else if (max_xri <= 256)
7172 else if (max_xri <= 512)
7174 else if (max_xri <= 1024)
7181 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
7182 * @pdev: pointer to PCI device
7183 * @pid: pointer to PCI device identifier
7185 * This routine is called from the kernel's PCI subsystem to device with
7186 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7187 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7188 * information of the device and driver to see if the driver state that it
7189 * can support this kind of device. If the match is successful, the driver
7190 * core invokes this routine. If this routine determines it can claim the HBA,
7191 * it does all the initialization that it needs to do to handle the HBA
7195 * 0 - driver can claim the device
7196 * negative value - driver can not claim the device
7198 static int __devinit
7199 lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
7201 struct lpfc_hba *phba;
7202 struct lpfc_vport *vport = NULL;
7204 uint32_t cfg_mode, intr_mode;
7207 /* Allocate memory for HBA structure */
7208 phba = lpfc_hba_alloc(pdev);
7212 /* Perform generic PCI device enabling operation */
7213 error = lpfc_enable_pci_dev(phba);
7215 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7216 "1409 Failed to enable pci device.\n");
7220 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
7221 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
7223 goto out_disable_pci_dev;
7225 /* Set up SLI-4 specific device PCI memory space */
7226 error = lpfc_sli4_pci_mem_setup(phba);
7228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7229 "1410 Failed to set up pci memory space.\n");
7230 goto out_disable_pci_dev;
7233 /* Set up phase-1 common device driver resources */
7234 error = lpfc_setup_driver_resource_phase1(phba);
7236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7237 "1411 Failed to set up driver resource.\n");
7238 goto out_unset_pci_mem_s4;
7241 /* Set up SLI-4 Specific device driver resources */
7242 error = lpfc_sli4_driver_resource_setup(phba);
7244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7245 "1412 Failed to set up driver resource.\n");
7246 goto out_unset_pci_mem_s4;
7249 /* Initialize and populate the iocb list per host */
7250 error = lpfc_init_iocb_list(phba,
7251 phba->sli4_hba.max_cfg_param.max_xri);
7253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7254 "1413 Failed to initialize iocb list.\n");
7255 goto out_unset_driver_resource_s4;
7258 /* Set up common device driver resources */
7259 error = lpfc_setup_driver_resource_phase2(phba);
7261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7262 "1414 Failed to set up driver resource.\n");
7263 goto out_free_iocb_list;
7266 /* Create SCSI host to the physical port */
7267 error = lpfc_create_shost(phba);
7269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7270 "1415 Failed to create scsi host.\n");
7271 goto out_unset_driver_resource;
7274 /* Configure sysfs attributes */
7275 vport = phba->pport;
7276 error = lpfc_alloc_sysfs_attr(vport);
7278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7279 "1416 Failed to allocate sysfs attr\n");
7280 goto out_destroy_shost;
7283 /* Now, trying to enable interrupt and bring up the device */
7284 cfg_mode = phba->cfg_use_msi;
7286 /* Put device to a known state before enabling interrupt */
7287 lpfc_stop_port(phba);
7288 /* Configure and enable interrupt */
7289 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
7290 if (intr_mode == LPFC_INTR_ERROR) {
7291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7292 "0426 Failed to enable interrupt.\n");
7294 goto out_free_sysfs_attr;
7296 /* Set up SLI-4 HBA */
7297 if (lpfc_sli4_hba_setup(phba)) {
7298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7299 "1421 Failed to set up hba\n");
7301 goto out_disable_intr;
7304 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
7306 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
7309 /* Check active interrupts received only for MSI/MSI-X */
7310 if (intr_mode == 0 ||
7311 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
7312 /* Log the current active interrupt mode */
7313 phba->intr_mode = intr_mode;
7314 lpfc_log_intr_mode(phba, intr_mode);
7317 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7318 "0451 Configure interrupt mode (%d) "
7319 "failed active interrupt test.\n",
7321 /* Unset the preivous SLI-4 HBA setup */
7322 lpfc_sli4_unset_hba(phba);
7323 /* Try next level of interrupt mode */
7324 cfg_mode = --intr_mode;
7327 /* Perform post initialization setup */
7328 lpfc_post_init_setup(phba);
7333 lpfc_sli4_disable_intr(phba);
7334 out_free_sysfs_attr:
7335 lpfc_free_sysfs_attr(vport);
7337 lpfc_destroy_shost(phba);
7338 out_unset_driver_resource:
7339 lpfc_unset_driver_resource_phase2(phba);
7341 lpfc_free_iocb_list(phba);
7342 out_unset_driver_resource_s4:
7343 lpfc_sli4_driver_resource_unset(phba);
7344 out_unset_pci_mem_s4:
7345 lpfc_sli4_pci_mem_unset(phba);
7346 out_disable_pci_dev:
7347 lpfc_disable_pci_dev(phba);
7349 lpfc_hba_free(phba);
7354 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
7355 * @pdev: pointer to PCI device
7357 * This routine is called from the kernel's PCI subsystem to device with
7358 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7359 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7360 * device to be removed from the PCI subsystem properly.
7362 static void __devexit
7363 lpfc_pci_remove_one_s4(struct pci_dev *pdev)
7365 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
7367 struct lpfc_vport **vports;
7368 struct lpfc_hba *phba = vport->phba;
7371 /* Mark the device unloading flag */
7372 spin_lock_irq(&phba->hbalock);
7373 vport->load_flag |= FC_UNLOADING;
7374 spin_unlock_irq(&phba->hbalock);
7376 /* Free the HBA sysfs attributes */
7377 lpfc_free_sysfs_attr(vport);
7379 /* Release all the vports against this physical port */
7380 vports = lpfc_create_vport_work_array(phba);
7382 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
7383 fc_vport_terminate(vports[i]->fc_vport);
7384 lpfc_destroy_vport_work_array(phba, vports);
7386 /* Remove FC host and then SCSI host with the physical port */
7387 fc_remove_host(shost);
7388 scsi_remove_host(shost);
7390 /* Perform cleanup on the physical port */
7391 lpfc_cleanup(vport);
7394 * Bring down the SLI Layer. This step disables all interrupts,
7395 * clears the rings, discards all mailbox commands, and resets
7396 * the HBA FCoE function.
7398 lpfc_debugfs_terminate(vport);
7399 lpfc_sli4_hba_unset(phba);
7401 spin_lock_irq(&phba->hbalock);
7402 list_del_init(&vport->listentry);
7403 spin_unlock_irq(&phba->hbalock);
7405 /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
7406 * buffers are released to their corresponding pools here.
7408 lpfc_scsi_free(phba);
7409 lpfc_sli4_driver_resource_unset(phba);
7411 /* Unmap adapter Control and Doorbell registers */
7412 lpfc_sli4_pci_mem_unset(phba);
7414 /* Release PCI resources and disable device's PCI function */
7415 scsi_host_put(shost);
7416 lpfc_disable_pci_dev(phba);
7418 /* Finally, free the driver's device data structure */
7419 lpfc_hba_free(phba);
7425 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
7426 * @pdev: pointer to PCI device
7427 * @msg: power management message
7429 * This routine is called from the kernel's PCI subsystem to support system
7430 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
7431 * this method, it quiesces the device by stopping the driver's worker
7432 * thread for the device, turning off device's interrupt and DMA, and bring
7433 * the device offline. Note that as the driver implements the minimum PM
7434 * requirements to a power-aware driver's PM support for suspend/resume -- all
7435 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
7436 * method call will be treated as SUSPEND and the driver will fully
7437 * reinitialize its device during resume() method call, the driver will set
7438 * device to PCI_D3hot state in PCI config space instead of setting it
7439 * according to the @msg provided by the PM.
7442 * 0 - driver suspended the device
7446 lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
7448 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7449 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7451 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7452 "0298 PCI device Power Management suspend.\n");
7454 /* Bring down the device */
7455 lpfc_offline_prep(phba);
7457 kthread_stop(phba->worker_thread);
7459 /* Disable interrupt from device */
7460 lpfc_sli4_disable_intr(phba);
7462 /* Save device state to PCI config space */
7463 pci_save_state(pdev);
7464 pci_set_power_state(pdev, PCI_D3hot);
7470 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
7471 * @pdev: pointer to PCI device
7473 * This routine is called from the kernel's PCI subsystem to support system
7474 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
7475 * this method, it restores the device's PCI config space state and fully
7476 * reinitializes the device and brings it online. Note that as the driver
7477 * implements the minimum PM requirements to a power-aware driver's PM for
7478 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7479 * to the suspend() method call will be treated as SUSPEND and the driver
7480 * will fully reinitialize its device during resume() method call, the device
7481 * will be set to PCI_D0 directly in PCI config space before restoring the
7485 * 0 - driver suspended the device
7489 lpfc_pci_resume_one_s4(struct pci_dev *pdev)
7491 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7492 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7496 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7497 "0292 PCI device Power Management resume.\n");
7499 /* Restore device state from PCI config space */
7500 pci_set_power_state(pdev, PCI_D0);
7501 pci_restore_state(pdev);
7502 if (pdev->is_busmaster)
7503 pci_set_master(pdev);
7505 /* Startup the kernel thread for this host adapter. */
7506 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7507 "lpfc_worker_%d", phba->brd_no);
7508 if (IS_ERR(phba->worker_thread)) {
7509 error = PTR_ERR(phba->worker_thread);
7510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7511 "0293 PM resume failed to start worker "
7512 "thread: error=x%x.\n", error);
7516 /* Configure and enable interrupt */
7517 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
7518 if (intr_mode == LPFC_INTR_ERROR) {
7519 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7520 "0294 PM resume Failed to enable interrupt\n");
7523 phba->intr_mode = intr_mode;
7525 /* Restart HBA and bring it online */
7526 lpfc_sli_brdrestart(phba);
7529 /* Log the current active interrupt mode */
7530 lpfc_log_intr_mode(phba, phba->intr_mode);
7536 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
7537 * @pdev: pointer to PCI device.
7538 * @state: the current PCI connection state.
7540 * This routine is called from the PCI subsystem for error handling to device
7541 * with SLI-4 interface spec. This function is called by the PCI subsystem
7542 * after a PCI bus error affecting this device has been detected. When this
7543 * function is invoked, it will need to stop all the I/Os and interrupt(s)
7544 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
7545 * for the PCI subsystem to perform proper recovery as desired.
7548 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7549 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7551 static pci_ers_result_t
7552 lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
7554 return PCI_ERS_RESULT_NEED_RESET;
7558 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
7559 * @pdev: pointer to PCI device.
7561 * This routine is called from the PCI subsystem for error handling to device
7562 * with SLI-4 interface spec. It is called after PCI bus has been reset to
7563 * restart the PCI card from scratch, as if from a cold-boot. During the
7564 * PCI subsystem error recovery, after the driver returns
7565 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7566 * recovery and then call this routine before calling the .resume method to
7567 * recover the device. This function will initialize the HBA device, enable
7568 * the interrupt, but it will just put the HBA to offline state without
7569 * passing any I/O traffic.
7572 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7573 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7575 static pci_ers_result_t
7576 lpfc_io_slot_reset_s4(struct pci_dev *pdev)
7578 return PCI_ERS_RESULT_RECOVERED;
7582 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
7583 * @pdev: pointer to PCI device
7585 * This routine is called from the PCI subsystem for error handling to device
7586 * with SLI-4 interface spec. It is called when kernel error recovery tells
7587 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7588 * error recovery. After this call, traffic can start to flow from this device
7592 lpfc_io_resume_s4(struct pci_dev *pdev)
7598 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
7599 * @pdev: pointer to PCI device
7600 * @pid: pointer to PCI device identifier
7602 * This routine is to be registered to the kernel's PCI subsystem. When an
7603 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
7604 * at PCI device-specific information of the device and driver to see if the
7605 * driver state that it can support this kind of device. If the match is
7606 * successful, the driver core invokes this routine. This routine dispatches
7607 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
7608 * do all the initialization that it needs to do to handle the HBA device
7612 * 0 - driver can claim the device
7613 * negative value - driver can not claim the device
7615 static int __devinit
7616 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
7621 if (pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id))
7625 case PCI_DEVICE_ID_TIGERSHARK:
7626 case PCI_DEVICE_ID_TIGERSHARK_S:
7627 rc = lpfc_pci_probe_one_s4(pdev, pid);
7630 rc = lpfc_pci_probe_one_s3(pdev, pid);
7637 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
7638 * @pdev: pointer to PCI device
7640 * This routine is to be registered to the kernel's PCI subsystem. When an
7641 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
7642 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
7643 * remove routine, which will perform all the necessary cleanup for the
7644 * device to be removed from the PCI subsystem properly.
7646 static void __devexit
7647 lpfc_pci_remove_one(struct pci_dev *pdev)
7649 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7650 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7652 switch (phba->pci_dev_grp) {
7653 case LPFC_PCI_DEV_LP:
7654 lpfc_pci_remove_one_s3(pdev);
7656 case LPFC_PCI_DEV_OC:
7657 lpfc_pci_remove_one_s4(pdev);
7660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7661 "1424 Invalid PCI device group: 0x%x\n",
7669 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
7670 * @pdev: pointer to PCI device
7671 * @msg: power management message
7673 * This routine is to be registered to the kernel's PCI subsystem to support
7674 * system Power Management (PM). When PM invokes this method, it dispatches
7675 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
7676 * suspend the device.
7679 * 0 - driver suspended the device
7683 lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
7685 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7686 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7689 switch (phba->pci_dev_grp) {
7690 case LPFC_PCI_DEV_LP:
7691 rc = lpfc_pci_suspend_one_s3(pdev, msg);
7693 case LPFC_PCI_DEV_OC:
7694 rc = lpfc_pci_suspend_one_s4(pdev, msg);
7697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7698 "1425 Invalid PCI device group: 0x%x\n",
7706 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
7707 * @pdev: pointer to PCI device
7709 * This routine is to be registered to the kernel's PCI subsystem to support
7710 * system Power Management (PM). When PM invokes this method, it dispatches
7711 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
7712 * resume the device.
7715 * 0 - driver suspended the device
7719 lpfc_pci_resume_one(struct pci_dev *pdev)
7721 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7722 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7725 switch (phba->pci_dev_grp) {
7726 case LPFC_PCI_DEV_LP:
7727 rc = lpfc_pci_resume_one_s3(pdev);
7729 case LPFC_PCI_DEV_OC:
7730 rc = lpfc_pci_resume_one_s4(pdev);
7733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7734 "1426 Invalid PCI device group: 0x%x\n",
7742 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
7743 * @pdev: pointer to PCI device.
7744 * @state: the current PCI connection state.
7746 * This routine is registered to the PCI subsystem for error handling. This
7747 * function is called by the PCI subsystem after a PCI bus error affecting
7748 * this device has been detected. When this routine is invoked, it dispatches
7749 * the action to the proper SLI-3 or SLI-4 device error detected handling
7750 * routine, which will perform the proper error detected operation.
7753 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7754 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7756 static pci_ers_result_t
7757 lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7759 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7760 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7761 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
7763 switch (phba->pci_dev_grp) {
7764 case LPFC_PCI_DEV_LP:
7765 rc = lpfc_io_error_detected_s3(pdev, state);
7767 case LPFC_PCI_DEV_OC:
7768 rc = lpfc_io_error_detected_s4(pdev, state);
7771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7772 "1427 Invalid PCI device group: 0x%x\n",
7780 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
7781 * @pdev: pointer to PCI device.
7783 * This routine is registered to the PCI subsystem for error handling. This
7784 * function is called after PCI bus has been reset to restart the PCI card
7785 * from scratch, as if from a cold-boot. When this routine is invoked, it
7786 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
7787 * routine, which will perform the proper device reset.
7790 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7791 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7793 static pci_ers_result_t
7794 lpfc_io_slot_reset(struct pci_dev *pdev)
7796 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7797 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7798 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
7800 switch (phba->pci_dev_grp) {
7801 case LPFC_PCI_DEV_LP:
7802 rc = lpfc_io_slot_reset_s3(pdev);
7804 case LPFC_PCI_DEV_OC:
7805 rc = lpfc_io_slot_reset_s4(pdev);
7808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7809 "1428 Invalid PCI device group: 0x%x\n",
7817 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
7818 * @pdev: pointer to PCI device
7820 * This routine is registered to the PCI subsystem for error handling. It
7821 * is called when kernel error recovery tells the lpfc driver that it is
7822 * OK to resume normal PCI operation after PCI bus error recovery. When
7823 * this routine is invoked, it dispatches the action to the proper SLI-3
7824 * or SLI-4 device io_resume routine, which will resume the device operation.
7827 lpfc_io_resume(struct pci_dev *pdev)
7829 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7830 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7832 switch (phba->pci_dev_grp) {
7833 case LPFC_PCI_DEV_LP:
7834 lpfc_io_resume_s3(pdev);
7836 case LPFC_PCI_DEV_OC:
7837 lpfc_io_resume_s4(pdev);
7840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7841 "1429 Invalid PCI device group: 0x%x\n",
7848 static struct pci_device_id lpfc_id_table[] = {
7849 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
7850 PCI_ANY_ID, PCI_ANY_ID, },
7851 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
7852 PCI_ANY_ID, PCI_ANY_ID, },
7853 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
7854 PCI_ANY_ID, PCI_ANY_ID, },
7855 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
7856 PCI_ANY_ID, PCI_ANY_ID, },
7857 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
7858 PCI_ANY_ID, PCI_ANY_ID, },
7859 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
7860 PCI_ANY_ID, PCI_ANY_ID, },
7861 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
7862 PCI_ANY_ID, PCI_ANY_ID, },
7863 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
7864 PCI_ANY_ID, PCI_ANY_ID, },
7865 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
7866 PCI_ANY_ID, PCI_ANY_ID, },
7867 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
7868 PCI_ANY_ID, PCI_ANY_ID, },
7869 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
7870 PCI_ANY_ID, PCI_ANY_ID, },
7871 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
7872 PCI_ANY_ID, PCI_ANY_ID, },
7873 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
7874 PCI_ANY_ID, PCI_ANY_ID, },
7875 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
7876 PCI_ANY_ID, PCI_ANY_ID, },
7877 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
7878 PCI_ANY_ID, PCI_ANY_ID, },
7879 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
7880 PCI_ANY_ID, PCI_ANY_ID, },
7881 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
7882 PCI_ANY_ID, PCI_ANY_ID, },
7883 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
7884 PCI_ANY_ID, PCI_ANY_ID, },
7885 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
7886 PCI_ANY_ID, PCI_ANY_ID, },
7887 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
7888 PCI_ANY_ID, PCI_ANY_ID, },
7889 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
7890 PCI_ANY_ID, PCI_ANY_ID, },
7891 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
7892 PCI_ANY_ID, PCI_ANY_ID, },
7893 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
7894 PCI_ANY_ID, PCI_ANY_ID, },
7895 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
7896 PCI_ANY_ID, PCI_ANY_ID, },
7897 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
7898 PCI_ANY_ID, PCI_ANY_ID, },
7899 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
7900 PCI_ANY_ID, PCI_ANY_ID, },
7901 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
7902 PCI_ANY_ID, PCI_ANY_ID, },
7903 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
7904 PCI_ANY_ID, PCI_ANY_ID, },
7905 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
7906 PCI_ANY_ID, PCI_ANY_ID, },
7907 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
7908 PCI_ANY_ID, PCI_ANY_ID, },
7909 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
7910 PCI_ANY_ID, PCI_ANY_ID, },
7911 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
7912 PCI_ANY_ID, PCI_ANY_ID, },
7913 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
7914 PCI_ANY_ID, PCI_ANY_ID, },
7915 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
7916 PCI_ANY_ID, PCI_ANY_ID, },
7917 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
7918 PCI_ANY_ID, PCI_ANY_ID, },
7919 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
7920 PCI_ANY_ID, PCI_ANY_ID, },
7921 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
7922 PCI_ANY_ID, PCI_ANY_ID, },
7923 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
7924 PCI_ANY_ID, PCI_ANY_ID, },
7925 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK_S,
7926 PCI_ANY_ID, PCI_ANY_ID, },
7930 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
7932 static struct pci_error_handlers lpfc_err_handler = {
7933 .error_detected = lpfc_io_error_detected,
7934 .slot_reset = lpfc_io_slot_reset,
7935 .resume = lpfc_io_resume,
7938 static struct pci_driver lpfc_driver = {
7939 .name = LPFC_DRIVER_NAME,
7940 .id_table = lpfc_id_table,
7941 .probe = lpfc_pci_probe_one,
7942 .remove = __devexit_p(lpfc_pci_remove_one),
7943 .suspend = lpfc_pci_suspend_one,
7944 .resume = lpfc_pci_resume_one,
7945 .err_handler = &lpfc_err_handler,
7949 * lpfc_init - lpfc module initialization routine
7951 * This routine is to be invoked when the lpfc module is loaded into the
7952 * kernel. The special kernel macro module_init() is used to indicate the
7953 * role of this routine to the kernel as lpfc module entry point.
7957 * -ENOMEM - FC attach transport failed
7958 * all others - failed
7965 printk(LPFC_MODULE_DESC "\n");
7966 printk(LPFC_COPYRIGHT "\n");
7968 if (lpfc_enable_npiv) {
7969 lpfc_transport_functions.vport_create = lpfc_vport_create;
7970 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
7972 lpfc_transport_template =
7973 fc_attach_transport(&lpfc_transport_functions);
7974 if (lpfc_transport_template == NULL)
7976 if (lpfc_enable_npiv) {
7977 lpfc_vport_transport_template =
7978 fc_attach_transport(&lpfc_vport_transport_functions);
7979 if (lpfc_vport_transport_template == NULL) {
7980 fc_release_transport(lpfc_transport_template);
7984 error = pci_register_driver(&lpfc_driver);
7986 fc_release_transport(lpfc_transport_template);
7987 if (lpfc_enable_npiv)
7988 fc_release_transport(lpfc_vport_transport_template);
7995 * lpfc_exit - lpfc module removal routine
7997 * This routine is invoked when the lpfc module is removed from the kernel.
7998 * The special kernel macro module_exit() is used to indicate the role of
7999 * this routine to the kernel as lpfc module exit point.
8004 pci_unregister_driver(&lpfc_driver);
8005 fc_release_transport(lpfc_transport_template);
8006 if (lpfc_enable_npiv)
8007 fc_release_transport(lpfc_vport_transport_template);
8008 if (_dump_buf_data) {
8009 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data "
8011 (1L << _dump_buf_data_order), _dump_buf_data);
8012 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
8015 if (_dump_buf_dif) {
8016 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif "
8018 (1L << _dump_buf_dif_order), _dump_buf_dif);
8019 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
8023 module_init(lpfc_init);
8024 module_exit(lpfc_exit);
8025 MODULE_LICENSE("GPL");
8026 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
8027 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
8028 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);