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>
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_version.h"
47 static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
48 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
49 static int lpfc_post_rcv_buf(struct lpfc_hba *);
51 static struct scsi_transport_template *lpfc_transport_template = NULL;
52 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
53 static DEFINE_IDR(lpfc_hba_index);
55 /************************************************************************/
57 /* lpfc_config_port_prep */
58 /* This routine will do LPFC initialization prior to the */
59 /* CONFIG_PORT mailbox command. This will be initialized */
60 /* as a SLI layer callback routine. */
61 /* This routine returns 0 on success or -ERESTART if it wants */
62 /* the SLI layer to reset the HBA and try again. Any */
63 /* other return value indicates an error. */
65 /************************************************************************/
67 lpfc_config_port_prep(struct lpfc_hba *phba)
69 lpfc_vpd_t *vp = &phba->vpd;
73 char *lpfc_vpd_data = NULL;
75 static char licensed[56] =
76 "key unlock for use with gnu public licensed code only\0";
77 static int init_key = 1;
79 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
81 phba->link_state = LPFC_HBA_ERROR;
86 phba->link_state = LPFC_INIT_MBX_CMDS;
88 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
90 uint32_t *ptext = (uint32_t *) licensed;
92 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
93 *ptext = cpu_to_be32(*ptext);
97 lpfc_read_nv(phba, pmb);
98 memset((char*)mb->un.varRDnvp.rsvd3, 0,
99 sizeof (mb->un.varRDnvp.rsvd3));
100 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
103 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
105 if (rc != MBX_SUCCESS) {
106 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
107 "0324 Config Port initialization "
108 "error, mbxCmd x%x READ_NVPARM, "
110 mb->mbxCommand, mb->mbxStatus);
111 mempool_free(pmb, phba->mbox_mem_pool);
114 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
116 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
120 phba->sli3_options = 0x0;
122 /* Setup and issue mailbox READ REV command */
123 lpfc_read_rev(phba, pmb);
124 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
125 if (rc != MBX_SUCCESS) {
126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
127 "0439 Adapter failed to init, mbxCmd x%x "
128 "READ_REV, mbxStatus x%x\n",
129 mb->mbxCommand, mb->mbxStatus);
130 mempool_free( pmb, phba->mbox_mem_pool);
136 * The value of rr must be 1 since the driver set the cv field to 1.
137 * This setting requires the FW to set all revision fields.
139 if (mb->un.varRdRev.rr == 0) {
141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
142 "0440 Adapter failed to init, READ_REV has "
143 "missing revision information.\n");
144 mempool_free(pmb, phba->mbox_mem_pool);
148 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
149 mempool_free(pmb, phba->mbox_mem_pool);
153 /* Save information as VPD data */
155 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
156 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
157 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
158 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
159 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
160 vp->rev.biuRev = mb->un.varRdRev.biuRev;
161 vp->rev.smRev = mb->un.varRdRev.smRev;
162 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
163 vp->rev.endecRev = mb->un.varRdRev.endecRev;
164 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
165 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
166 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
167 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
168 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
169 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
171 /* If the sli feature level is less then 9, we must
172 * tear down all RPIs and VPIs on link down if NPIV
175 if (vp->rev.feaLevelHigh < 9)
176 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
178 if (lpfc_is_LC_HBA(phba->pcidev->device))
179 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
180 sizeof (phba->RandomData));
182 /* Get adapter VPD information */
183 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
186 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
188 goto out_free_context2;
191 lpfc_dump_mem(phba, pmb, offset);
192 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
194 if (rc != MBX_SUCCESS) {
195 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
196 "0441 VPD not present on adapter, "
197 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
198 mb->mbxCommand, mb->mbxStatus);
199 mb->un.varDmp.word_cnt = 0;
201 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
202 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
203 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
204 mb->un.varDmp.word_cnt);
205 offset += mb->un.varDmp.word_cnt;
206 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
207 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
209 kfree(lpfc_vpd_data);
211 kfree(pmb->context2);
213 mempool_free(pmb, phba->mbox_mem_pool);
217 /* Completion handler for config async event mailbox command. */
219 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
221 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
222 phba->temp_sensor_support = 1;
224 phba->temp_sensor_support = 0;
225 mempool_free(pmboxq, phba->mbox_mem_pool);
229 /************************************************************************/
231 /* lpfc_config_port_post */
232 /* This routine will do LPFC initialization after the */
233 /* CONFIG_PORT mailbox command. This will be initialized */
234 /* as a SLI layer callback routine. */
235 /* This routine returns 0 on success. Any other return value */
236 /* indicates an error. */
238 /************************************************************************/
240 lpfc_config_port_post(struct lpfc_hba *phba)
242 struct lpfc_vport *vport = phba->pport;
245 struct lpfc_dmabuf *mp;
246 struct lpfc_sli *psli = &phba->sli;
247 uint32_t status, timeout;
251 spin_lock_irq(&phba->hbalock);
253 * If the Config port completed correctly the HBA is not
254 * over heated any more.
256 if (phba->over_temp_state == HBA_OVER_TEMP)
257 phba->over_temp_state = HBA_NORMAL_TEMP;
258 spin_unlock_irq(&phba->hbalock);
260 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
262 phba->link_state = LPFC_HBA_ERROR;
267 /* Get login parameters for NID. */
268 lpfc_read_sparam(phba, pmb, 0);
270 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
272 "0448 Adapter failed init, mbxCmd x%x "
273 "READ_SPARM mbxStatus x%x\n",
274 mb->mbxCommand, mb->mbxStatus);
275 phba->link_state = LPFC_HBA_ERROR;
276 mp = (struct lpfc_dmabuf *) pmb->context1;
277 mempool_free( pmb, phba->mbox_mem_pool);
278 lpfc_mbuf_free(phba, mp->virt, mp->phys);
283 mp = (struct lpfc_dmabuf *) pmb->context1;
285 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
286 lpfc_mbuf_free(phba, mp->virt, mp->phys);
288 pmb->context1 = NULL;
290 if (phba->cfg_soft_wwnn)
291 u64_to_wwn(phba->cfg_soft_wwnn,
292 vport->fc_sparam.nodeName.u.wwn);
293 if (phba->cfg_soft_wwpn)
294 u64_to_wwn(phba->cfg_soft_wwpn,
295 vport->fc_sparam.portName.u.wwn);
296 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
297 sizeof (struct lpfc_name));
298 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
299 sizeof (struct lpfc_name));
300 /* If no serial number in VPD data, use low 6 bytes of WWNN */
301 /* This should be consolidated into parse_vpd ? - mr */
302 if (phba->SerialNumber[0] == 0) {
305 outptr = &vport->fc_nodename.u.s.IEEE[0];
306 for (i = 0; i < 12; i++) {
308 j = ((status & 0xf0) >> 4);
310 phba->SerialNumber[i] =
311 (char)((uint8_t) 0x30 + (uint8_t) j);
313 phba->SerialNumber[i] =
314 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
318 phba->SerialNumber[i] =
319 (char)((uint8_t) 0x30 + (uint8_t) j);
321 phba->SerialNumber[i] =
322 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
326 lpfc_read_config(phba, pmb);
328 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
330 "0453 Adapter failed to init, mbxCmd x%x "
331 "READ_CONFIG, mbxStatus x%x\n",
332 mb->mbxCommand, mb->mbxStatus);
333 phba->link_state = LPFC_HBA_ERROR;
334 mempool_free( pmb, phba->mbox_mem_pool);
338 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
339 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
340 phba->cfg_hba_queue_depth =
341 mb->un.varRdConfig.max_xri + 1;
343 phba->lmt = mb->un.varRdConfig.lmt;
345 /* Get the default values for Model Name and Description */
346 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
348 if ((phba->cfg_link_speed > LINK_SPEED_10G)
349 || ((phba->cfg_link_speed == LINK_SPEED_1G)
350 && !(phba->lmt & LMT_1Gb))
351 || ((phba->cfg_link_speed == LINK_SPEED_2G)
352 && !(phba->lmt & LMT_2Gb))
353 || ((phba->cfg_link_speed == LINK_SPEED_4G)
354 && !(phba->lmt & LMT_4Gb))
355 || ((phba->cfg_link_speed == LINK_SPEED_8G)
356 && !(phba->lmt & LMT_8Gb))
357 || ((phba->cfg_link_speed == LINK_SPEED_10G)
358 && !(phba->lmt & LMT_10Gb))) {
359 /* Reset link speed to auto */
360 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
361 "1302 Invalid speed for this board: "
362 "Reset link speed to auto: x%x\n",
363 phba->cfg_link_speed);
364 phba->cfg_link_speed = LINK_SPEED_AUTO;
367 phba->link_state = LPFC_LINK_DOWN;
369 /* Only process IOCBs on ELS ring till hba_state is READY */
370 if (psli->ring[psli->extra_ring].cmdringaddr)
371 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
372 if (psli->ring[psli->fcp_ring].cmdringaddr)
373 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
374 if (psli->ring[psli->next_ring].cmdringaddr)
375 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
377 /* Post receive buffers for desired rings */
378 if (phba->sli_rev != 3)
379 lpfc_post_rcv_buf(phba);
381 /* Enable appropriate host interrupts */
382 spin_lock_irq(&phba->hbalock);
383 status = readl(phba->HCregaddr);
384 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
385 if (psli->num_rings > 0)
386 status |= HC_R0INT_ENA;
387 if (psli->num_rings > 1)
388 status |= HC_R1INT_ENA;
389 if (psli->num_rings > 2)
390 status |= HC_R2INT_ENA;
391 if (psli->num_rings > 3)
392 status |= HC_R3INT_ENA;
394 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
395 (phba->cfg_poll & DISABLE_FCP_RING_INT))
396 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
398 writel(status, phba->HCregaddr);
399 readl(phba->HCregaddr); /* flush */
400 spin_unlock_irq(&phba->hbalock);
403 * Setup the ring 0 (els) timeout handler
405 timeout = phba->fc_ratov << 1;
406 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
407 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
408 phba->hb_outstanding = 0;
409 phba->last_completion_time = jiffies;
411 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
412 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
414 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
415 lpfc_set_loopback_flag(phba);
416 if (rc != MBX_SUCCESS) {
417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
418 "0454 Adapter failed to init, mbxCmd x%x "
419 "INIT_LINK, mbxStatus x%x\n",
420 mb->mbxCommand, mb->mbxStatus);
422 /* Clear all interrupt enable conditions */
423 writel(0, phba->HCregaddr);
424 readl(phba->HCregaddr); /* flush */
425 /* Clear all pending interrupts */
426 writel(0xffffffff, phba->HAregaddr);
427 readl(phba->HAregaddr); /* flush */
429 phba->link_state = LPFC_HBA_ERROR;
431 mempool_free(pmb, phba->mbox_mem_pool);
434 /* MBOX buffer will be freed in mbox compl */
435 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
436 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
437 pmb->mbox_cmpl = lpfc_config_async_cmpl;
438 pmb->vport = phba->pport;
439 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
441 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
442 lpfc_printf_log(phba,
445 "0456 Adapter failed to issue "
446 "ASYNCEVT_ENABLE mbox status x%x \n.",
448 mempool_free(pmb, phba->mbox_mem_pool);
453 /************************************************************************/
455 /* lpfc_hba_down_prep */
456 /* This routine will do LPFC uninitialization before the */
457 /* HBA is reset when bringing down the SLI Layer. This will be */
458 /* initialized as a SLI layer callback routine. */
459 /* This routine returns 0 on success. Any other return value */
460 /* indicates an error. */
462 /************************************************************************/
464 lpfc_hba_down_prep(struct lpfc_hba *phba)
466 struct lpfc_vport **vports;
468 /* Disable interrupts */
469 writel(0, phba->HCregaddr);
470 readl(phba->HCregaddr); /* flush */
472 if (phba->pport->load_flag & FC_UNLOADING)
473 lpfc_cleanup_discovery_resources(phba->pport);
475 vports = lpfc_create_vport_work_array(phba);
477 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
478 lpfc_cleanup_discovery_resources(vports[i]);
479 lpfc_destroy_vport_work_array(phba, vports);
484 /************************************************************************/
486 /* lpfc_hba_down_post */
487 /* This routine will do uninitialization after the HBA is reset */
488 /* when bringing down the SLI Layer. */
489 /* This routine returns 0 on success. Any other return value */
490 /* indicates an error. */
492 /************************************************************************/
494 lpfc_hba_down_post(struct lpfc_hba *phba)
496 struct lpfc_sli *psli = &phba->sli;
497 struct lpfc_sli_ring *pring;
498 struct lpfc_dmabuf *mp, *next_mp;
499 struct lpfc_iocbq *iocb;
501 LIST_HEAD(completions);
504 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
505 lpfc_sli_hbqbuf_free_all(phba);
507 /* Cleanup preposted buffers on the ELS ring */
508 pring = &psli->ring[LPFC_ELS_RING];
509 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
511 pring->postbufq_cnt--;
512 lpfc_mbuf_free(phba, mp->virt, mp->phys);
517 spin_lock_irq(&phba->hbalock);
518 for (i = 0; i < psli->num_rings; i++) {
519 pring = &psli->ring[i];
521 /* At this point in time the HBA is either reset or DOA. Either
522 * way, nothing should be on txcmplq as it will NEVER complete.
524 list_splice_init(&pring->txcmplq, &completions);
525 pring->txcmplq_cnt = 0;
526 spin_unlock_irq(&phba->hbalock);
528 while (!list_empty(&completions)) {
529 iocb = list_get_first(&completions, struct lpfc_iocbq,
532 list_del_init(&iocb->list);
534 if (!iocb->iocb_cmpl)
535 lpfc_sli_release_iocbq(phba, iocb);
537 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
538 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
539 (iocb->iocb_cmpl) (phba, iocb, iocb);
543 lpfc_sli_abort_iocb_ring(phba, pring);
544 spin_lock_irq(&phba->hbalock);
546 spin_unlock_irq(&phba->hbalock);
551 /* HBA heart beat timeout handler */
553 lpfc_hb_timeout(unsigned long ptr)
555 struct lpfc_hba *phba;
559 phba = (struct lpfc_hba *)ptr;
560 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
561 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
563 phba->pport->work_port_events |= WORKER_HB_TMO;
564 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
567 lpfc_worker_wake_up(phba);
572 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
574 unsigned long drvr_flag;
576 spin_lock_irqsave(&phba->hbalock, drvr_flag);
577 phba->hb_outstanding = 0;
578 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
580 mempool_free(pmboxq, phba->mbox_mem_pool);
581 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
582 !(phba->link_state == LPFC_HBA_ERROR) &&
583 !(phba->pport->load_flag & FC_UNLOADING))
584 mod_timer(&phba->hb_tmofunc,
585 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
590 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
592 LPFC_MBOXQ_t *pmboxq;
593 struct lpfc_dmabuf *buf_ptr;
595 struct lpfc_sli *psli = &phba->sli;
596 LIST_HEAD(completions);
598 if ((phba->link_state == LPFC_HBA_ERROR) ||
599 (phba->pport->load_flag & FC_UNLOADING) ||
600 (phba->pport->fc_flag & FC_OFFLINE_MODE))
603 spin_lock_irq(&phba->pport->work_port_lock);
604 /* If the timer is already canceled do nothing */
605 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
606 spin_unlock_irq(&phba->pport->work_port_lock);
610 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
612 spin_unlock_irq(&phba->pport->work_port_lock);
613 if (!phba->hb_outstanding)
614 mod_timer(&phba->hb_tmofunc,
615 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
617 mod_timer(&phba->hb_tmofunc,
618 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
621 spin_unlock_irq(&phba->pport->work_port_lock);
623 if (phba->elsbuf_cnt &&
624 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
625 spin_lock_irq(&phba->hbalock);
626 list_splice_init(&phba->elsbuf, &completions);
627 phba->elsbuf_cnt = 0;
628 phba->elsbuf_prev_cnt = 0;
629 spin_unlock_irq(&phba->hbalock);
631 while (!list_empty(&completions)) {
632 list_remove_head(&completions, buf_ptr,
633 struct lpfc_dmabuf, list);
634 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
638 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
640 /* If there is no heart beat outstanding, issue a heartbeat command */
641 if (phba->cfg_enable_hba_heartbeat) {
642 if (!phba->hb_outstanding) {
643 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
645 mod_timer(&phba->hb_tmofunc,
646 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
650 lpfc_heart_beat(phba, pmboxq);
651 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
652 pmboxq->vport = phba->pport;
653 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
655 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
656 mempool_free(pmboxq, phba->mbox_mem_pool);
657 mod_timer(&phba->hb_tmofunc,
658 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
661 mod_timer(&phba->hb_tmofunc,
662 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
663 phba->hb_outstanding = 1;
667 * If heart beat timeout called with hb_outstanding set
668 * we need to take the HBA offline.
670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
671 "0459 Adapter heartbeat failure, "
672 "taking this port offline.\n");
674 spin_lock_irq(&phba->hbalock);
675 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
676 spin_unlock_irq(&phba->hbalock);
678 lpfc_offline_prep(phba);
680 lpfc_unblock_mgmt_io(phba);
681 phba->link_state = LPFC_HBA_ERROR;
682 lpfc_hba_down_post(phba);
688 lpfc_offline_eratt(struct lpfc_hba *phba)
690 struct lpfc_sli *psli = &phba->sli;
692 spin_lock_irq(&phba->hbalock);
693 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
694 spin_unlock_irq(&phba->hbalock);
695 lpfc_offline_prep(phba);
698 lpfc_reset_barrier(phba);
699 lpfc_sli_brdreset(phba);
700 lpfc_hba_down_post(phba);
701 lpfc_sli_brdready(phba, HS_MBRDY);
702 lpfc_unblock_mgmt_io(phba);
703 phba->link_state = LPFC_HBA_ERROR;
707 /************************************************************************/
709 /* lpfc_handle_eratt */
710 /* This routine will handle processing a Host Attention */
711 /* Error Status event. This will be initialized */
712 /* as a SLI layer callback routine. */
714 /************************************************************************/
716 lpfc_handle_eratt(struct lpfc_hba *phba)
718 struct lpfc_vport *vport = phba->pport;
719 struct lpfc_sli *psli = &phba->sli;
720 struct lpfc_sli_ring *pring;
722 unsigned long temperature;
723 struct temp_event temp_event_data;
724 struct Scsi_Host *shost;
726 /* If the pci channel is offline, ignore possible errors,
727 * since we cannot communicate with the pci card anyway. */
728 if (pci_channel_offline(phba->pcidev))
730 /* If resets are disabled then leave the HBA alone and return */
731 if (!phba->cfg_enable_hba_reset)
734 if (phba->work_hs & HS_FFER6) {
735 /* Re-establishing Link */
736 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
737 "1301 Re-establishing Link "
738 "Data: x%x x%x x%x\n",
740 phba->work_status[0], phba->work_status[1]);
742 spin_lock_irq(&phba->hbalock);
743 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
744 spin_unlock_irq(&phba->hbalock);
747 * Firmware stops when it triggled erratt with HS_FFER6.
748 * That could cause the I/Os dropped by the firmware.
749 * Error iocb (I/O) on txcmplq and let the SCSI layer
750 * retry it after re-establishing link.
752 pring = &psli->ring[psli->fcp_ring];
753 lpfc_sli_abort_iocb_ring(phba, pring);
756 * There was a firmware error. Take the hba offline and then
757 * attempt to restart it.
759 lpfc_offline_prep(phba);
761 lpfc_sli_brdrestart(phba);
762 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
763 lpfc_unblock_mgmt_io(phba);
766 lpfc_unblock_mgmt_io(phba);
767 } else if (phba->work_hs & HS_CRIT_TEMP) {
768 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
769 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
770 temp_event_data.event_code = LPFC_CRIT_TEMP;
771 temp_event_data.data = (uint32_t)temperature;
773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
774 "0459 Adapter maximum temperature exceeded "
775 "(%ld), taking this port offline "
776 "Data: x%x x%x x%x\n",
777 temperature, phba->work_hs,
778 phba->work_status[0], phba->work_status[1]);
780 shost = lpfc_shost_from_vport(phba->pport);
781 fc_host_post_vendor_event(shost, fc_get_event_number(),
782 sizeof(temp_event_data),
783 (char *) &temp_event_data,
785 | PCI_VENDOR_ID_EMULEX);
787 spin_lock_irq(&phba->hbalock);
788 phba->over_temp_state = HBA_OVER_TEMP;
789 spin_unlock_irq(&phba->hbalock);
790 lpfc_offline_eratt(phba);
793 /* The if clause above forces this code path when the status
794 * failure is a value other than FFER6. Do not call the offline
795 * twice. This is the adapter hardware error path.
797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
798 "0457 Adapter Hardware Error "
799 "Data: x%x x%x x%x\n",
801 phba->work_status[0], phba->work_status[1]);
803 event_data = FC_REG_DUMP_EVENT;
804 shost = lpfc_shost_from_vport(vport);
805 fc_host_post_vendor_event(shost, fc_get_event_number(),
806 sizeof(event_data), (char *) &event_data,
807 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
809 lpfc_offline_eratt(phba);
813 /************************************************************************/
815 /* lpfc_handle_latt */
816 /* This routine will handle processing a Host Attention */
817 /* Link Status event. This will be initialized */
818 /* as a SLI layer callback routine. */
820 /************************************************************************/
822 lpfc_handle_latt(struct lpfc_hba *phba)
824 struct lpfc_vport *vport = phba->pport;
825 struct lpfc_sli *psli = &phba->sli;
827 volatile uint32_t control;
828 struct lpfc_dmabuf *mp;
831 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
834 goto lpfc_handle_latt_err_exit;
837 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
840 goto lpfc_handle_latt_free_pmb;
843 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
846 goto lpfc_handle_latt_free_mp;
849 /* Cleanup any outstanding ELS commands */
850 lpfc_els_flush_all_cmd(phba);
852 psli->slistat.link_event++;
853 lpfc_read_la(phba, pmb, mp);
854 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
856 /* Block ELS IOCBs until we have processed this mbox command */
857 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
858 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
859 if (rc == MBX_NOT_FINISHED) {
861 goto lpfc_handle_latt_free_mbuf;
864 /* Clear Link Attention in HA REG */
865 spin_lock_irq(&phba->hbalock);
866 writel(HA_LATT, phba->HAregaddr);
867 readl(phba->HAregaddr); /* flush */
868 spin_unlock_irq(&phba->hbalock);
872 lpfc_handle_latt_free_mbuf:
873 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
874 lpfc_mbuf_free(phba, mp->virt, mp->phys);
875 lpfc_handle_latt_free_mp:
877 lpfc_handle_latt_free_pmb:
878 mempool_free(pmb, phba->mbox_mem_pool);
879 lpfc_handle_latt_err_exit:
880 /* Enable Link attention interrupts */
881 spin_lock_irq(&phba->hbalock);
882 psli->sli_flag |= LPFC_PROCESS_LA;
883 control = readl(phba->HCregaddr);
884 control |= HC_LAINT_ENA;
885 writel(control, phba->HCregaddr);
886 readl(phba->HCregaddr); /* flush */
888 /* Clear Link Attention in HA REG */
889 writel(HA_LATT, phba->HAregaddr);
890 readl(phba->HAregaddr); /* flush */
891 spin_unlock_irq(&phba->hbalock);
893 phba->link_state = LPFC_HBA_ERROR;
895 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
896 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
901 /************************************************************************/
904 /* This routine will parse the VPD data */
906 /************************************************************************/
908 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
910 uint8_t lenlo, lenhi;
920 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
921 "0455 Vital Product Data: x%x x%x x%x x%x\n",
922 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
924 while (!finished && (index < (len - 4))) {
925 switch (vpd[index]) {
933 i = ((((unsigned short)lenhi) << 8) + lenlo);
942 Length = ((((unsigned short)lenhi) << 8) + lenlo);
943 if (Length > len - index)
944 Length = len - index;
946 /* Look for Serial Number */
947 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
954 phba->SerialNumber[j++] = vpd[index++];
958 phba->SerialNumber[j] = 0;
961 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
962 phba->vpd_flag |= VPD_MODEL_DESC;
969 phba->ModelDesc[j++] = vpd[index++];
973 phba->ModelDesc[j] = 0;
976 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
977 phba->vpd_flag |= VPD_MODEL_NAME;
984 phba->ModelName[j++] = vpd[index++];
988 phba->ModelName[j] = 0;
991 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
992 phba->vpd_flag |= VPD_PROGRAM_TYPE;
999 phba->ProgramType[j++] = vpd[index++];
1003 phba->ProgramType[j] = 0;
1006 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1007 phba->vpd_flag |= VPD_PORT;
1014 phba->Port[j++] = vpd[index++];
1044 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1047 uint16_t dev_id = phba->pcidev->device;
1053 } m = {"<Unknown>", 0, ""};
1055 if (mdp && mdp[0] != '\0'
1056 && descp && descp[0] != '\0')
1059 if (phba->lmt & LMT_10Gb)
1061 else if (phba->lmt & LMT_8Gb)
1063 else if (phba->lmt & LMT_4Gb)
1065 else if (phba->lmt & LMT_2Gb)
1073 case PCI_DEVICE_ID_FIREFLY:
1074 m = (typeof(m)){"LP6000", max_speed, "PCI"};
1076 case PCI_DEVICE_ID_SUPERFLY:
1077 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1078 m = (typeof(m)){"LP7000", max_speed, "PCI"};
1080 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
1082 case PCI_DEVICE_ID_DRAGONFLY:
1083 m = (typeof(m)){"LP8000", max_speed, "PCI"};
1085 case PCI_DEVICE_ID_CENTAUR:
1086 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1087 m = (typeof(m)){"LP9002", max_speed, "PCI"};
1089 m = (typeof(m)){"LP9000", max_speed, "PCI"};
1091 case PCI_DEVICE_ID_RFLY:
1092 m = (typeof(m)){"LP952", max_speed, "PCI"};
1094 case PCI_DEVICE_ID_PEGASUS:
1095 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
1097 case PCI_DEVICE_ID_THOR:
1098 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
1100 case PCI_DEVICE_ID_VIPER:
1101 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
1103 case PCI_DEVICE_ID_PFLY:
1104 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
1106 case PCI_DEVICE_ID_TFLY:
1107 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
1109 case PCI_DEVICE_ID_HELIOS:
1110 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
1112 case PCI_DEVICE_ID_HELIOS_SCSP:
1113 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
1115 case PCI_DEVICE_ID_HELIOS_DCSP:
1116 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
1118 case PCI_DEVICE_ID_NEPTUNE:
1119 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
1121 case PCI_DEVICE_ID_NEPTUNE_SCSP:
1122 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
1124 case PCI_DEVICE_ID_NEPTUNE_DCSP:
1125 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
1127 case PCI_DEVICE_ID_BMID:
1128 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
1130 case PCI_DEVICE_ID_BSMB:
1131 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
1133 case PCI_DEVICE_ID_ZEPHYR:
1134 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1136 case PCI_DEVICE_ID_ZEPHYR_SCSP:
1137 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1139 case PCI_DEVICE_ID_ZEPHYR_DCSP:
1140 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
1142 case PCI_DEVICE_ID_ZMID:
1143 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
1145 case PCI_DEVICE_ID_ZSMB:
1146 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
1148 case PCI_DEVICE_ID_LP101:
1149 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
1151 case PCI_DEVICE_ID_LP10000S:
1152 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
1154 case PCI_DEVICE_ID_LP11000S:
1155 m = (typeof(m)){"LP11000-S", max_speed,
1158 case PCI_DEVICE_ID_LPE11000S:
1159 m = (typeof(m)){"LPe11000-S", max_speed,
1162 case PCI_DEVICE_ID_SAT:
1163 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1165 case PCI_DEVICE_ID_SAT_MID:
1166 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1168 case PCI_DEVICE_ID_SAT_SMB:
1169 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1171 case PCI_DEVICE_ID_SAT_DCSP:
1172 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1174 case PCI_DEVICE_ID_SAT_SCSP:
1175 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1177 case PCI_DEVICE_ID_SAT_S:
1178 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1181 m = (typeof(m)){ NULL };
1185 if (mdp && mdp[0] == '\0')
1186 snprintf(mdp, 79,"%s", m.name);
1187 if (descp && descp[0] == '\0')
1188 snprintf(descp, 255,
1189 "Emulex %s %dGb %s Fibre Channel Adapter",
1190 m.name, m.max_speed, m.bus);
1193 /**************************************************/
1194 /* lpfc_post_buffer */
1196 /* This routine will post count buffers to the */
1197 /* ring with the QUE_RING_BUF_CN command. This */
1198 /* allows 3 buffers / command to be posted. */
1199 /* Returns the number of buffers NOT posted. */
1200 /**************************************************/
1202 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1205 struct lpfc_iocbq *iocb;
1206 struct lpfc_dmabuf *mp1, *mp2;
1208 cnt += pring->missbufcnt;
1210 /* While there are buffers to post */
1212 /* Allocate buffer for command iocb */
1213 iocb = lpfc_sli_get_iocbq(phba);
1215 pring->missbufcnt = cnt;
1220 /* 2 buffers can be posted per command */
1221 /* Allocate buffer to post */
1222 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1224 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1225 if (!mp1 || !mp1->virt) {
1227 lpfc_sli_release_iocbq(phba, iocb);
1228 pring->missbufcnt = cnt;
1232 INIT_LIST_HEAD(&mp1->list);
1233 /* Allocate buffer to post */
1235 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1237 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1239 if (!mp2 || !mp2->virt) {
1241 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1243 lpfc_sli_release_iocbq(phba, iocb);
1244 pring->missbufcnt = cnt;
1248 INIT_LIST_HEAD(&mp2->list);
1253 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1254 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1255 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1256 icmd->ulpBdeCount = 1;
1259 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1260 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1261 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1263 icmd->ulpBdeCount = 2;
1266 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1269 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1270 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1274 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1278 lpfc_sli_release_iocbq(phba, iocb);
1279 pring->missbufcnt = cnt;
1282 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1284 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1286 pring->missbufcnt = 0;
1290 /************************************************************************/
1292 /* lpfc_post_rcv_buf */
1293 /* This routine post initial rcv buffers to the configured rings */
1295 /************************************************************************/
1297 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1299 struct lpfc_sli *psli = &phba->sli;
1301 /* Ring 0, ELS / CT buffers */
1302 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
1303 /* Ring 2 - FCP no buffers needed */
1308 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1310 /************************************************************************/
1314 /************************************************************************/
1316 lpfc_sha_init(uint32_t * HashResultPointer)
1318 HashResultPointer[0] = 0x67452301;
1319 HashResultPointer[1] = 0xEFCDAB89;
1320 HashResultPointer[2] = 0x98BADCFE;
1321 HashResultPointer[3] = 0x10325476;
1322 HashResultPointer[4] = 0xC3D2E1F0;
1325 /************************************************************************/
1327 /* lpfc_sha_iterate */
1329 /************************************************************************/
1331 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1335 uint32_t A, B, C, D, E;
1338 HashWorkingPointer[t] =
1340 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1342 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1343 } while (++t <= 79);
1345 A = HashResultPointer[0];
1346 B = HashResultPointer[1];
1347 C = HashResultPointer[2];
1348 D = HashResultPointer[3];
1349 E = HashResultPointer[4];
1353 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1354 } else if (t < 40) {
1355 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1356 } else if (t < 60) {
1357 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1359 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1361 TEMP += S(5, A) + E + HashWorkingPointer[t];
1367 } while (++t <= 79);
1369 HashResultPointer[0] += A;
1370 HashResultPointer[1] += B;
1371 HashResultPointer[2] += C;
1372 HashResultPointer[3] += D;
1373 HashResultPointer[4] += E;
1377 /************************************************************************/
1379 /* lpfc_challenge_key */
1381 /************************************************************************/
1383 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1385 *HashWorking = (*RandomChallenge ^ *HashWorking);
1388 /************************************************************************/
1392 /************************************************************************/
1394 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1397 uint32_t *HashWorking;
1398 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1400 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
1404 HashWorking[0] = HashWorking[78] = *pwwnn++;
1405 HashWorking[1] = HashWorking[79] = *pwwnn;
1407 for (t = 0; t < 7; t++)
1408 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1410 lpfc_sha_init(hbainit);
1411 lpfc_sha_iterate(hbainit, HashWorking);
1416 lpfc_cleanup(struct lpfc_vport *vport)
1418 struct lpfc_hba *phba = vport->phba;
1419 struct lpfc_nodelist *ndlp, *next_ndlp;
1422 if (phba->link_state > LPFC_LINK_DOWN)
1423 lpfc_port_link_failure(vport);
1425 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1426 if (!NLP_CHK_NODE_ACT(ndlp)) {
1427 ndlp = lpfc_enable_node(vport, ndlp,
1428 NLP_STE_UNUSED_NODE);
1431 spin_lock_irq(&phba->ndlp_lock);
1432 NLP_SET_FREE_REQ(ndlp);
1433 spin_unlock_irq(&phba->ndlp_lock);
1434 /* Trigger the release of the ndlp memory */
1438 spin_lock_irq(&phba->ndlp_lock);
1439 if (NLP_CHK_FREE_REQ(ndlp)) {
1440 /* The ndlp should not be in memory free mode already */
1441 spin_unlock_irq(&phba->ndlp_lock);
1444 /* Indicate request for freeing ndlp memory */
1445 NLP_SET_FREE_REQ(ndlp);
1446 spin_unlock_irq(&phba->ndlp_lock);
1448 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1449 ndlp->nlp_DID == Fabric_DID) {
1450 /* Just free up ndlp with Fabric_DID for vports */
1455 if (ndlp->nlp_type & NLP_FABRIC)
1456 lpfc_disc_state_machine(vport, ndlp, NULL,
1457 NLP_EVT_DEVICE_RECOVERY);
1459 lpfc_disc_state_machine(vport, ndlp, NULL,
1462 /* nlp_type zero is not defined, nlp_flag zero also not defined,
1463 * nlp_state is unused, this happens when
1464 * an initiator has logged
1465 * into us so cleanup this ndlp.
1467 if ((ndlp->nlp_type == 0) && (ndlp->nlp_flag == 0) &&
1468 (ndlp->nlp_state == 0))
1472 /* At this point, ALL ndlp's should be gone
1473 * because of the previous NLP_EVT_DEVICE_RM.
1474 * Lets wait for this to happen, if needed.
1476 while (!list_empty(&vport->fc_nodes)) {
1479 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1480 "0233 Nodelist not empty\n");
1481 list_for_each_entry_safe(ndlp, next_ndlp,
1482 &vport->fc_nodes, nlp_listp) {
1483 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1485 "0282: did:x%x ndlp:x%p "
1486 "usgmap:x%x refcnt:%d\n",
1487 ndlp->nlp_DID, (void *)ndlp,
1490 &ndlp->kref.refcount));
1495 /* Wait for any activity on ndlps to settle */
1502 lpfc_stop_vport_timers(struct lpfc_vport *vport)
1504 del_timer_sync(&vport->els_tmofunc);
1505 del_timer_sync(&vport->fc_fdmitmo);
1506 lpfc_can_disctmo(vport);
1511 lpfc_stop_phba_timers(struct lpfc_hba *phba)
1513 del_timer_sync(&phba->fcp_poll_timer);
1514 lpfc_stop_vport_timers(phba->pport);
1515 del_timer_sync(&phba->sli.mbox_tmo);
1516 del_timer_sync(&phba->fabric_block_timer);
1517 phba->hb_outstanding = 0;
1518 del_timer_sync(&phba->hb_tmofunc);
1523 lpfc_block_mgmt_io(struct lpfc_hba * phba)
1525 unsigned long iflag;
1527 spin_lock_irqsave(&phba->hbalock, iflag);
1528 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1529 spin_unlock_irqrestore(&phba->hbalock, iflag);
1533 lpfc_online(struct lpfc_hba *phba)
1535 struct lpfc_vport *vport = phba->pport;
1536 struct lpfc_vport **vports;
1542 if (!(vport->fc_flag & FC_OFFLINE_MODE))
1545 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1546 "0458 Bring Adapter online\n");
1548 lpfc_block_mgmt_io(phba);
1550 if (!lpfc_sli_queue_setup(phba)) {
1551 lpfc_unblock_mgmt_io(phba);
1555 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1556 lpfc_unblock_mgmt_io(phba);
1560 vports = lpfc_create_vport_work_array(phba);
1562 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1563 struct Scsi_Host *shost;
1564 shost = lpfc_shost_from_vport(vports[i]);
1565 spin_lock_irq(shost->host_lock);
1566 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1567 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1568 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1569 spin_unlock_irq(shost->host_lock);
1571 lpfc_destroy_vport_work_array(phba, vports);
1573 lpfc_unblock_mgmt_io(phba);
1578 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1580 unsigned long iflag;
1582 spin_lock_irqsave(&phba->hbalock, iflag);
1583 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1584 spin_unlock_irqrestore(&phba->hbalock, iflag);
1588 lpfc_offline_prep(struct lpfc_hba * phba)
1590 struct lpfc_vport *vport = phba->pport;
1591 struct lpfc_nodelist *ndlp, *next_ndlp;
1592 struct lpfc_vport **vports;
1595 if (vport->fc_flag & FC_OFFLINE_MODE)
1598 lpfc_block_mgmt_io(phba);
1600 lpfc_linkdown(phba);
1602 /* Issue an unreg_login to all nodes on all vports */
1603 vports = lpfc_create_vport_work_array(phba);
1604 if (vports != NULL) {
1605 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1606 struct Scsi_Host *shost;
1608 if (vports[i]->load_flag & FC_UNLOADING)
1610 shost = lpfc_shost_from_vport(vports[i]);
1611 list_for_each_entry_safe(ndlp, next_ndlp,
1612 &vports[i]->fc_nodes,
1614 if (!NLP_CHK_NODE_ACT(ndlp))
1616 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1618 if (ndlp->nlp_type & NLP_FABRIC) {
1619 lpfc_disc_state_machine(vports[i], ndlp,
1620 NULL, NLP_EVT_DEVICE_RECOVERY);
1621 lpfc_disc_state_machine(vports[i], ndlp,
1622 NULL, NLP_EVT_DEVICE_RM);
1624 spin_lock_irq(shost->host_lock);
1625 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1626 spin_unlock_irq(shost->host_lock);
1627 lpfc_unreg_rpi(vports[i], ndlp);
1631 lpfc_destroy_vport_work_array(phba, vports);
1633 lpfc_sli_flush_mbox_queue(phba);
1637 lpfc_offline(struct lpfc_hba *phba)
1639 struct Scsi_Host *shost;
1640 struct lpfc_vport **vports;
1643 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1646 /* stop all timers associated with this hba */
1647 lpfc_stop_phba_timers(phba);
1648 vports = lpfc_create_vport_work_array(phba);
1650 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
1651 lpfc_stop_vport_timers(vports[i]);
1652 lpfc_destroy_vport_work_array(phba, vports);
1653 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1654 "0460 Bring Adapter offline\n");
1655 /* Bring down the SLI Layer and cleanup. The HBA is offline
1657 lpfc_sli_hba_down(phba);
1658 spin_lock_irq(&phba->hbalock);
1660 spin_unlock_irq(&phba->hbalock);
1661 vports = lpfc_create_vport_work_array(phba);
1663 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1664 shost = lpfc_shost_from_vport(vports[i]);
1665 spin_lock_irq(shost->host_lock);
1666 vports[i]->work_port_events = 0;
1667 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1668 spin_unlock_irq(shost->host_lock);
1670 lpfc_destroy_vport_work_array(phba, vports);
1673 /******************************************************************************
1674 * Function name: lpfc_scsi_free
1676 * Description: Called from lpfc_pci_remove_one free internal driver resources
1678 ******************************************************************************/
1680 lpfc_scsi_free(struct lpfc_hba *phba)
1682 struct lpfc_scsi_buf *sb, *sb_next;
1683 struct lpfc_iocbq *io, *io_next;
1685 spin_lock_irq(&phba->hbalock);
1686 /* Release all the lpfc_scsi_bufs maintained by this host. */
1687 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1688 list_del(&sb->list);
1689 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1692 phba->total_scsi_bufs--;
1695 /* Release all the lpfc_iocbq entries maintained by this host. */
1696 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1697 list_del(&io->list);
1699 phba->total_iocbq_bufs--;
1702 spin_unlock_irq(&phba->hbalock);
1708 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
1710 struct lpfc_vport *vport;
1711 struct Scsi_Host *shost;
1714 if (dev != &phba->pcidev->dev)
1715 shost = scsi_host_alloc(&lpfc_vport_template,
1716 sizeof(struct lpfc_vport));
1718 shost = scsi_host_alloc(&lpfc_template,
1719 sizeof(struct lpfc_vport));
1723 vport = (struct lpfc_vport *) shost->hostdata;
1725 vport->load_flag |= FC_LOADING;
1726 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1727 vport->fc_rscn_flush = 0;
1729 lpfc_get_vport_cfgparam(vport);
1730 shost->unique_id = instance;
1731 shost->max_id = LPFC_MAX_TARGET;
1732 shost->max_lun = vport->cfg_max_luns;
1733 shost->this_id = -1;
1734 shost->max_cmd_len = 16;
1736 * Set initial can_queue value since 0 is no longer supported and
1737 * scsi_add_host will fail. This will be adjusted later based on the
1738 * max xri value determined in hba setup.
1740 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1741 if (dev != &phba->pcidev->dev) {
1742 shost->transportt = lpfc_vport_transport_template;
1743 vport->port_type = LPFC_NPIV_PORT;
1745 shost->transportt = lpfc_transport_template;
1746 vport->port_type = LPFC_PHYSICAL_PORT;
1749 /* Initialize all internally managed lists. */
1750 INIT_LIST_HEAD(&vport->fc_nodes);
1751 spin_lock_init(&vport->work_port_lock);
1753 init_timer(&vport->fc_disctmo);
1754 vport->fc_disctmo.function = lpfc_disc_timeout;
1755 vport->fc_disctmo.data = (unsigned long)vport;
1757 init_timer(&vport->fc_fdmitmo);
1758 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1759 vport->fc_fdmitmo.data = (unsigned long)vport;
1761 init_timer(&vport->els_tmofunc);
1762 vport->els_tmofunc.function = lpfc_els_timeout;
1763 vport->els_tmofunc.data = (unsigned long)vport;
1765 error = scsi_add_host(shost, dev);
1769 spin_lock_irq(&phba->hbalock);
1770 list_add_tail(&vport->listentry, &phba->port_list);
1771 spin_unlock_irq(&phba->hbalock);
1775 scsi_host_put(shost);
1781 destroy_port(struct lpfc_vport *vport)
1783 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1784 struct lpfc_hba *phba = vport->phba;
1786 kfree(vport->vname);
1788 lpfc_debugfs_terminate(vport);
1789 fc_remove_host(shost);
1790 scsi_remove_host(shost);
1792 spin_lock_irq(&phba->hbalock);
1793 list_del_init(&vport->listentry);
1794 spin_unlock_irq(&phba->hbalock);
1796 lpfc_cleanup(vport);
1801 lpfc_get_instance(void)
1805 /* Assign an unused number */
1806 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1808 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1814 * Note: there is no scan_start function as adapter initialization
1815 * will have asynchronously kicked off the link initialization.
1818 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1821 struct lpfc_hba *phba = vport->phba;
1824 spin_lock_irq(shost->host_lock);
1826 if (vport->load_flag & FC_UNLOADING) {
1830 if (time >= 30 * HZ) {
1831 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1832 "0461 Scanning longer than 30 "
1833 "seconds. Continuing initialization\n");
1837 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1838 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1839 "0465 Link down longer than 15 "
1840 "seconds. Continuing initialization\n");
1845 if (vport->port_state != LPFC_VPORT_READY)
1847 if (vport->num_disc_nodes || vport->fc_prli_sent)
1849 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
1851 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
1857 spin_unlock_irq(shost->host_lock);
1861 void lpfc_host_attrib_init(struct Scsi_Host *shost)
1863 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1864 struct lpfc_hba *phba = vport->phba;
1866 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1869 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1870 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
1871 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1873 memset(fc_host_supported_fc4s(shost), 0,
1874 sizeof(fc_host_supported_fc4s(shost)));
1875 fc_host_supported_fc4s(shost)[2] = 1;
1876 fc_host_supported_fc4s(shost)[7] = 1;
1878 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1879 sizeof fc_host_symbolic_name(shost));
1881 fc_host_supported_speeds(shost) = 0;
1882 if (phba->lmt & LMT_10Gb)
1883 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1884 if (phba->lmt & LMT_8Gb)
1885 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
1886 if (phba->lmt & LMT_4Gb)
1887 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1888 if (phba->lmt & LMT_2Gb)
1889 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1890 if (phba->lmt & LMT_1Gb)
1891 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1893 fc_host_maxframe_size(shost) =
1894 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1895 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
1897 /* This value is also unchanging */
1898 memset(fc_host_active_fc4s(shost), 0,
1899 sizeof(fc_host_active_fc4s(shost)));
1900 fc_host_active_fc4s(shost)[2] = 1;
1901 fc_host_active_fc4s(shost)[7] = 1;
1903 fc_host_max_npiv_vports(shost) = phba->max_vpi;
1904 spin_lock_irq(shost->host_lock);
1905 vport->load_flag &= ~FC_LOADING;
1906 spin_unlock_irq(shost->host_lock);
1910 lpfc_enable_msix(struct lpfc_hba *phba)
1914 phba->msix_entries[0].entry = 0;
1915 phba->msix_entries[0].vector = 0;
1917 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
1918 ARRAY_SIZE(phba->msix_entries));
1920 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1921 "0420 Enable MSI-X failed (%d), continuing "
1922 "with MSI\n", error);
1923 pci_disable_msix(phba->pcidev);
1927 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
1928 LPFC_DRIVER_NAME, phba);
1930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1931 "0421 MSI-X request_irq failed (%d), "
1932 "continuing with MSI\n", error);
1933 pci_disable_msix(phba->pcidev);
1939 lpfc_disable_msix(struct lpfc_hba *phba)
1941 free_irq(phba->msix_entries[0].vector, phba);
1942 pci_disable_msix(phba->pcidev);
1945 static int __devinit
1946 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1948 struct lpfc_vport *vport = NULL;
1949 struct lpfc_hba *phba;
1950 struct lpfc_sli *psli;
1951 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1952 struct Scsi_Host *shost = NULL;
1954 unsigned long bar0map_len, bar2map_len;
1955 int error = -ENODEV, retval;
1958 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1960 if (pci_enable_device_mem(pdev))
1962 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
1963 goto out_disable_device;
1965 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1967 goto out_release_regions;
1969 spin_lock_init(&phba->hbalock);
1971 /* Initialize ndlp management spinlock */
1972 spin_lock_init(&phba->ndlp_lock);
1974 phba->pcidev = pdev;
1976 /* Assign an unused board number */
1977 if ((phba->brd_no = lpfc_get_instance()) < 0)
1980 INIT_LIST_HEAD(&phba->port_list);
1982 * Get all the module params for configuring this host and then
1983 * establish the host.
1985 lpfc_get_cfgparam(phba);
1986 phba->max_vpi = LPFC_MAX_VPI;
1988 /* Initialize timers used by driver */
1989 init_timer(&phba->hb_tmofunc);
1990 phba->hb_tmofunc.function = lpfc_hb_timeout;
1991 phba->hb_tmofunc.data = (unsigned long)phba;
1994 init_timer(&psli->mbox_tmo);
1995 psli->mbox_tmo.function = lpfc_mbox_timeout;
1996 psli->mbox_tmo.data = (unsigned long) phba;
1997 init_timer(&phba->fcp_poll_timer);
1998 phba->fcp_poll_timer.function = lpfc_poll_timeout;
1999 phba->fcp_poll_timer.data = (unsigned long) phba;
2000 init_timer(&phba->fabric_block_timer);
2001 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2002 phba->fabric_block_timer.data = (unsigned long) phba;
2004 pci_set_master(pdev);
2005 pci_try_set_mwi(pdev);
2007 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2008 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2009 goto out_idr_remove;
2012 * Get the bus address of Bar0 and Bar2 and the number of bytes
2013 * required by each mapping.
2015 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2016 bar0map_len = pci_resource_len(phba->pcidev, 0);
2018 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2019 bar2map_len = pci_resource_len(phba->pcidev, 2);
2021 /* Map HBA SLIM to a kernel virtual address. */
2022 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
2023 if (!phba->slim_memmap_p) {
2025 dev_printk(KERN_ERR, &pdev->dev,
2026 "ioremap failed for SLIM memory.\n");
2027 goto out_idr_remove;
2030 /* Map HBA Control Registers to a kernel virtual address. */
2031 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
2032 if (!phba->ctrl_regs_memmap_p) {
2034 dev_printk(KERN_ERR, &pdev->dev,
2035 "ioremap failed for HBA control registers.\n");
2036 goto out_iounmap_slim;
2039 /* Allocate memory for SLI-2 structures */
2040 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
2041 &phba->slim2p_mapping, GFP_KERNEL);
2045 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
2047 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2048 lpfc_sli_hbq_size(),
2049 &phba->hbqslimp.phys,
2051 if (!phba->hbqslimp.virt)
2054 hbq_count = lpfc_sli_hbq_count();
2055 ptr = phba->hbqslimp.virt;
2056 for (i = 0; i < hbq_count; ++i) {
2057 phba->hbqs[i].hbq_virt = ptr;
2058 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2059 ptr += (lpfc_hbq_defs[i]->entry_count *
2060 sizeof(struct lpfc_hbq_entry));
2062 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2063 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2065 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2067 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2069 /* Initialize the SLI Layer to run with lpfc HBAs. */
2070 lpfc_sli_setup(phba);
2071 lpfc_sli_queue_setup(phba);
2073 retval = lpfc_mem_alloc(phba);
2076 goto out_free_hbqslimp;
2079 /* Initialize and populate the iocb list per host. */
2080 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2081 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
2082 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
2083 if (iocbq_entry == NULL) {
2084 printk(KERN_ERR "%s: only allocated %d iocbs of "
2085 "expected %d count. Unloading driver.\n",
2086 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
2088 goto out_free_iocbq;
2091 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2093 kfree (iocbq_entry);
2094 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2095 "Unloading driver.\n",
2098 goto out_free_iocbq;
2101 spin_lock_irq(&phba->hbalock);
2102 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2103 phba->total_iocbq_bufs++;
2104 spin_unlock_irq(&phba->hbalock);
2107 /* Initialize HBA structure */
2108 phba->fc_edtov = FF_DEF_EDTOV;
2109 phba->fc_ratov = FF_DEF_RATOV;
2110 phba->fc_altov = FF_DEF_ALTOV;
2111 phba->fc_arbtov = FF_DEF_ARBTOV;
2113 INIT_LIST_HEAD(&phba->work_list);
2114 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2115 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2117 /* Initialize the wait queue head for the kernel thread */
2118 init_waitqueue_head(&phba->work_waitq);
2120 /* Startup the kernel thread for this host adapter. */
2121 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2122 "lpfc_worker_%d", phba->brd_no);
2123 if (IS_ERR(phba->worker_thread)) {
2124 error = PTR_ERR(phba->worker_thread);
2125 goto out_free_iocbq;
2128 /* Initialize the list of scsi buffers used by driver for scsi IO. */
2129 spin_lock_init(&phba->scsi_buf_list_lock);
2130 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2132 /* Initialize list of fabric iocbs */
2133 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2135 /* Initialize list to save ELS buffers */
2136 INIT_LIST_HEAD(&phba->elsbuf);
2138 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
2140 goto out_kthread_stop;
2142 shost = lpfc_shost_from_vport(vport);
2143 phba->pport = vport;
2144 lpfc_debugfs_initialize(vport);
2146 pci_set_drvdata(pdev, shost);
2147 phba->intr_type = NONE;
2149 if (phba->cfg_use_msi == 2) {
2150 error = lpfc_enable_msix(phba);
2152 phba->intr_type = MSIX;
2155 /* Fallback to MSI if MSI-X initialization failed */
2156 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2157 retval = pci_enable_msi(phba->pcidev);
2159 phba->intr_type = MSI;
2161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2162 "0452 Enable MSI failed, continuing "
2166 /* MSI-X is the only case the doesn't need to call request_irq */
2167 if (phba->intr_type != MSIX) {
2168 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2169 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2172 "interrupt handler failed\n");
2174 goto out_disable_msi;
2175 } else if (phba->intr_type != MSI)
2176 phba->intr_type = INTx;
2179 phba->MBslimaddr = phba->slim_memmap_p;
2180 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2181 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2182 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2183 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2185 if (lpfc_alloc_sysfs_attr(vport)) {
2190 if (lpfc_sli_hba_setup(phba)) {
2192 goto out_remove_device;
2196 * hba setup may have changed the hba_queue_depth so we need to adjust
2197 * the value of can_queue.
2199 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2201 lpfc_host_attrib_init(shost);
2203 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2204 spin_lock_irq(shost->host_lock);
2205 lpfc_poll_start_timer(phba);
2206 spin_unlock_irq(shost->host_lock);
2209 scsi_scan_host(shost);
2214 lpfc_free_sysfs_attr(vport);
2215 spin_lock_irq(shost->host_lock);
2216 vport->load_flag |= FC_UNLOADING;
2217 spin_unlock_irq(shost->host_lock);
2219 lpfc_stop_phba_timers(phba);
2220 phba->pport->work_port_events = 0;
2222 if (phba->intr_type == MSIX)
2223 lpfc_disable_msix(phba);
2225 free_irq(phba->pcidev->irq, phba);
2228 if (phba->intr_type == MSI)
2229 pci_disable_msi(phba->pcidev);
2230 destroy_port(vport);
2232 kthread_stop(phba->worker_thread);
2234 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2235 &phba->lpfc_iocb_list, list) {
2237 phba->total_iocbq_bufs--;
2239 lpfc_mem_free(phba);
2241 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2242 phba->hbqslimp.phys);
2244 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2245 phba->slim2p_mapping);
2247 iounmap(phba->ctrl_regs_memmap_p);
2249 iounmap(phba->slim_memmap_p);
2251 idr_remove(&lpfc_hba_index, phba->brd_no);
2254 out_release_regions:
2255 pci_release_selected_regions(pdev, bars);
2257 pci_disable_device(pdev);
2259 pci_set_drvdata(pdev, NULL);
2261 scsi_host_put(shost);
2265 static void __devexit
2266 lpfc_pci_remove_one(struct pci_dev *pdev)
2268 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2269 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2270 struct lpfc_hba *phba = vport->phba;
2271 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2273 spin_lock_irq(&phba->hbalock);
2274 vport->load_flag |= FC_UNLOADING;
2275 spin_unlock_irq(&phba->hbalock);
2277 kfree(vport->vname);
2278 lpfc_free_sysfs_attr(vport);
2280 kthread_stop(phba->worker_thread);
2282 fc_remove_host(shost);
2283 scsi_remove_host(shost);
2284 lpfc_cleanup(vport);
2287 * Bring down the SLI Layer. This step disable all interrupts,
2288 * clears the rings, discards all mailbox commands, and resets
2291 lpfc_sli_hba_down(phba);
2292 lpfc_sli_brdrestart(phba);
2294 lpfc_stop_phba_timers(phba);
2295 spin_lock_irq(&phba->hbalock);
2296 list_del_init(&vport->listentry);
2297 spin_unlock_irq(&phba->hbalock);
2299 lpfc_debugfs_terminate(vport);
2301 if (phba->intr_type == MSIX)
2302 lpfc_disable_msix(phba);
2304 free_irq(phba->pcidev->irq, phba);
2305 if (phba->intr_type == MSI)
2306 pci_disable_msi(phba->pcidev);
2309 pci_set_drvdata(pdev, NULL);
2310 scsi_host_put(shost);
2313 * Call scsi_free before mem_free since scsi bufs are released to their
2314 * corresponding pools here.
2316 lpfc_scsi_free(phba);
2317 lpfc_mem_free(phba);
2319 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2320 phba->hbqslimp.phys);
2322 /* Free resources associated with SLI2 interface */
2323 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2324 phba->slim2p, phba->slim2p_mapping);
2326 /* unmap adapter SLIM and Control Registers */
2327 iounmap(phba->ctrl_regs_memmap_p);
2328 iounmap(phba->slim_memmap_p);
2330 idr_remove(&lpfc_hba_index, phba->brd_no);
2334 pci_release_selected_regions(pdev, bars);
2335 pci_disable_device(pdev);
2339 * lpfc_io_error_detected - called when PCI error is detected
2340 * @pdev: Pointer to PCI device
2341 * @state: The current pci conneection state
2343 * This function is called after a PCI bus error affecting
2344 * this device has been detected.
2346 static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2347 pci_channel_state_t state)
2349 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2350 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2351 struct lpfc_sli *psli = &phba->sli;
2352 struct lpfc_sli_ring *pring;
2354 if (state == pci_channel_io_perm_failure)
2355 return PCI_ERS_RESULT_DISCONNECT;
2357 pci_disable_device(pdev);
2359 * There may be I/Os dropped by the firmware.
2360 * Error iocb (I/O) on txcmplq and let the SCSI layer
2361 * retry it after re-establishing link.
2363 pring = &psli->ring[psli->fcp_ring];
2364 lpfc_sli_abort_iocb_ring(phba, pring);
2366 if (phba->intr_type == MSIX)
2367 lpfc_disable_msix(phba);
2369 free_irq(phba->pcidev->irq, phba);
2370 if (phba->intr_type == MSI)
2371 pci_disable_msi(phba->pcidev);
2374 /* Request a slot reset. */
2375 return PCI_ERS_RESULT_NEED_RESET;
2379 * lpfc_io_slot_reset - called after the pci bus has been reset.
2380 * @pdev: Pointer to PCI device
2382 * Restart the card from scratch, as if from a cold-boot.
2384 static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2386 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2387 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2388 struct lpfc_sli *psli = &phba->sli;
2391 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2392 if (pci_enable_device_mem(pdev)) {
2393 printk(KERN_ERR "lpfc: Cannot re-enable "
2394 "PCI device after reset.\n");
2395 return PCI_ERS_RESULT_DISCONNECT;
2398 pci_set_master(pdev);
2400 spin_lock_irq(&phba->hbalock);
2401 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2402 spin_unlock_irq(&phba->hbalock);
2404 /* Enable configured interrupt method */
2405 phba->intr_type = NONE;
2406 if (phba->cfg_use_msi == 2) {
2407 error = lpfc_enable_msix(phba);
2409 phba->intr_type = MSIX;
2412 /* Fallback to MSI if MSI-X initialization failed */
2413 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2414 retval = pci_enable_msi(phba->pcidev);
2416 phba->intr_type = MSI;
2418 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2419 "0470 Enable MSI failed, continuing "
2423 /* MSI-X is the only case the doesn't need to call request_irq */
2424 if (phba->intr_type != MSIX) {
2425 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2426 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2428 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2429 "0471 Enable interrupt handler "
2431 } else if (phba->intr_type != MSI)
2432 phba->intr_type = INTx;
2435 /* Take device offline; this will perform cleanup */
2437 lpfc_sli_brdrestart(phba);
2439 return PCI_ERS_RESULT_RECOVERED;
2443 * lpfc_io_resume - called when traffic can start flowing again.
2444 * @pdev: Pointer to PCI device
2446 * This callback is called when the error recovery driver tells us that
2447 * its OK to resume normal operation.
2449 static void lpfc_io_resume(struct pci_dev *pdev)
2451 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2452 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2457 static struct pci_device_id lpfc_id_table[] = {
2458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2459 PCI_ANY_ID, PCI_ANY_ID, },
2460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2461 PCI_ANY_ID, PCI_ANY_ID, },
2462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2463 PCI_ANY_ID, PCI_ANY_ID, },
2464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2465 PCI_ANY_ID, PCI_ANY_ID, },
2466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2467 PCI_ANY_ID, PCI_ANY_ID, },
2468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2469 PCI_ANY_ID, PCI_ANY_ID, },
2470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2471 PCI_ANY_ID, PCI_ANY_ID, },
2472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2473 PCI_ANY_ID, PCI_ANY_ID, },
2474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2475 PCI_ANY_ID, PCI_ANY_ID, },
2476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2477 PCI_ANY_ID, PCI_ANY_ID, },
2478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2479 PCI_ANY_ID, PCI_ANY_ID, },
2480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2481 PCI_ANY_ID, PCI_ANY_ID, },
2482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2483 PCI_ANY_ID, PCI_ANY_ID, },
2484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2485 PCI_ANY_ID, PCI_ANY_ID, },
2486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2487 PCI_ANY_ID, PCI_ANY_ID, },
2488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2489 PCI_ANY_ID, PCI_ANY_ID, },
2490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2491 PCI_ANY_ID, PCI_ANY_ID, },
2492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2493 PCI_ANY_ID, PCI_ANY_ID, },
2494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2495 PCI_ANY_ID, PCI_ANY_ID, },
2496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2497 PCI_ANY_ID, PCI_ANY_ID, },
2498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2499 PCI_ANY_ID, PCI_ANY_ID, },
2500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2501 PCI_ANY_ID, PCI_ANY_ID, },
2502 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2503 PCI_ANY_ID, PCI_ANY_ID, },
2504 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2505 PCI_ANY_ID, PCI_ANY_ID, },
2506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2507 PCI_ANY_ID, PCI_ANY_ID, },
2508 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2509 PCI_ANY_ID, PCI_ANY_ID, },
2510 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2511 PCI_ANY_ID, PCI_ANY_ID, },
2512 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2513 PCI_ANY_ID, PCI_ANY_ID, },
2514 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2515 PCI_ANY_ID, PCI_ANY_ID, },
2516 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2517 PCI_ANY_ID, PCI_ANY_ID, },
2518 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2519 PCI_ANY_ID, PCI_ANY_ID, },
2520 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2521 PCI_ANY_ID, PCI_ANY_ID, },
2522 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2523 PCI_ANY_ID, PCI_ANY_ID, },
2527 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2529 static struct pci_error_handlers lpfc_err_handler = {
2530 .error_detected = lpfc_io_error_detected,
2531 .slot_reset = lpfc_io_slot_reset,
2532 .resume = lpfc_io_resume,
2535 static struct pci_driver lpfc_driver = {
2536 .name = LPFC_DRIVER_NAME,
2537 .id_table = lpfc_id_table,
2538 .probe = lpfc_pci_probe_one,
2539 .remove = __devexit_p(lpfc_pci_remove_one),
2540 .err_handler = &lpfc_err_handler,
2548 printk(LPFC_MODULE_DESC "\n");
2549 printk(LPFC_COPYRIGHT "\n");
2551 if (lpfc_enable_npiv) {
2552 lpfc_transport_functions.vport_create = lpfc_vport_create;
2553 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2555 lpfc_transport_template =
2556 fc_attach_transport(&lpfc_transport_functions);
2557 if (lpfc_transport_template == NULL)
2559 if (lpfc_enable_npiv) {
2560 lpfc_vport_transport_template =
2561 fc_attach_transport(&lpfc_vport_transport_functions);
2562 if (lpfc_vport_transport_template == NULL) {
2563 fc_release_transport(lpfc_transport_template);
2567 error = pci_register_driver(&lpfc_driver);
2569 fc_release_transport(lpfc_transport_template);
2570 fc_release_transport(lpfc_vport_transport_template);
2579 pci_unregister_driver(&lpfc_driver);
2580 fc_release_transport(lpfc_transport_template);
2581 if (lpfc_enable_npiv)
2582 fc_release_transport(lpfc_vport_transport_template);
2585 module_init(lpfc_init);
2586 module_exit(lpfc_exit);
2587 MODULE_LICENSE("GPL");
2588 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2589 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2590 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);