1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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)
151 /* Save information as VPD data */
153 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
154 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
155 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
156 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
157 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
158 vp->rev.biuRev = mb->un.varRdRev.biuRev;
159 vp->rev.smRev = mb->un.varRdRev.smRev;
160 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
161 vp->rev.endecRev = mb->un.varRdRev.endecRev;
162 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
163 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
164 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
165 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
166 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
167 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
169 /* If the sli feature level is less then 9, we must
170 * tear down all RPIs and VPIs on link down if NPIV
173 if (vp->rev.feaLevelHigh < 9)
174 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
176 if (lpfc_is_LC_HBA(phba->pcidev->device))
177 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
178 sizeof (phba->RandomData));
180 /* Get adapter VPD information */
181 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
184 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
186 goto out_free_context2;
189 lpfc_dump_mem(phba, pmb, offset);
190 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
192 if (rc != MBX_SUCCESS) {
193 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
194 "0441 VPD not present on adapter, "
195 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
196 mb->mbxCommand, mb->mbxStatus);
197 mb->un.varDmp.word_cnt = 0;
199 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
200 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
201 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
202 mb->un.varDmp.word_cnt);
203 offset += mb->un.varDmp.word_cnt;
204 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
205 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
207 kfree(lpfc_vpd_data);
209 kfree(pmb->context2);
211 mempool_free(pmb, phba->mbox_mem_pool);
215 /* Completion handler for config async event mailbox command. */
217 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
219 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
220 phba->temp_sensor_support = 1;
222 phba->temp_sensor_support = 0;
223 mempool_free(pmboxq, phba->mbox_mem_pool);
227 /************************************************************************/
229 /* lpfc_config_port_post */
230 /* This routine will do LPFC initialization after the */
231 /* CONFIG_PORT mailbox command. This will be initialized */
232 /* as a SLI layer callback routine. */
233 /* This routine returns 0 on success. Any other return value */
234 /* indicates an error. */
236 /************************************************************************/
238 lpfc_config_port_post(struct lpfc_hba *phba)
240 struct lpfc_vport *vport = phba->pport;
243 struct lpfc_dmabuf *mp;
244 struct lpfc_sli *psli = &phba->sli;
245 uint32_t status, timeout;
249 spin_lock_irq(&phba->hbalock);
251 * If the Config port completed correctly the HBA is not
252 * over heated any more.
254 if (phba->over_temp_state == HBA_OVER_TEMP)
255 phba->over_temp_state = HBA_NORMAL_TEMP;
256 spin_unlock_irq(&phba->hbalock);
258 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
260 phba->link_state = LPFC_HBA_ERROR;
265 /* Get login parameters for NID. */
266 lpfc_read_sparam(phba, pmb, 0);
268 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
270 "0448 Adapter failed init, mbxCmd x%x "
271 "READ_SPARM mbxStatus x%x\n",
272 mb->mbxCommand, mb->mbxStatus);
273 phba->link_state = LPFC_HBA_ERROR;
274 mp = (struct lpfc_dmabuf *) pmb->context1;
275 mempool_free( pmb, phba->mbox_mem_pool);
276 lpfc_mbuf_free(phba, mp->virt, mp->phys);
281 mp = (struct lpfc_dmabuf *) pmb->context1;
283 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
284 lpfc_mbuf_free(phba, mp->virt, mp->phys);
286 pmb->context1 = NULL;
288 if (phba->cfg_soft_wwnn)
289 u64_to_wwn(phba->cfg_soft_wwnn,
290 vport->fc_sparam.nodeName.u.wwn);
291 if (phba->cfg_soft_wwpn)
292 u64_to_wwn(phba->cfg_soft_wwpn,
293 vport->fc_sparam.portName.u.wwn);
294 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
295 sizeof (struct lpfc_name));
296 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
297 sizeof (struct lpfc_name));
298 /* If no serial number in VPD data, use low 6 bytes of WWNN */
299 /* This should be consolidated into parse_vpd ? - mr */
300 if (phba->SerialNumber[0] == 0) {
303 outptr = &vport->fc_nodename.u.s.IEEE[0];
304 for (i = 0; i < 12; i++) {
306 j = ((status & 0xf0) >> 4);
308 phba->SerialNumber[i] =
309 (char)((uint8_t) 0x30 + (uint8_t) j);
311 phba->SerialNumber[i] =
312 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
316 phba->SerialNumber[i] =
317 (char)((uint8_t) 0x30 + (uint8_t) j);
319 phba->SerialNumber[i] =
320 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
324 lpfc_read_config(phba, pmb);
326 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
328 "0453 Adapter failed to init, mbxCmd x%x "
329 "READ_CONFIG, mbxStatus x%x\n",
330 mb->mbxCommand, mb->mbxStatus);
331 phba->link_state = LPFC_HBA_ERROR;
332 mempool_free( pmb, phba->mbox_mem_pool);
336 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
337 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
338 phba->cfg_hba_queue_depth =
339 mb->un.varRdConfig.max_xri + 1;
341 phba->lmt = mb->un.varRdConfig.lmt;
343 /* Get the default values for Model Name and Description */
344 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
346 if ((phba->cfg_link_speed > LINK_SPEED_10G)
347 || ((phba->cfg_link_speed == LINK_SPEED_1G)
348 && !(phba->lmt & LMT_1Gb))
349 || ((phba->cfg_link_speed == LINK_SPEED_2G)
350 && !(phba->lmt & LMT_2Gb))
351 || ((phba->cfg_link_speed == LINK_SPEED_4G)
352 && !(phba->lmt & LMT_4Gb))
353 || ((phba->cfg_link_speed == LINK_SPEED_8G)
354 && !(phba->lmt & LMT_8Gb))
355 || ((phba->cfg_link_speed == LINK_SPEED_10G)
356 && !(phba->lmt & LMT_10Gb))) {
357 /* Reset link speed to auto */
358 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
359 "1302 Invalid speed for this board: "
360 "Reset link speed to auto: x%x\n",
361 phba->cfg_link_speed);
362 phba->cfg_link_speed = LINK_SPEED_AUTO;
365 phba->link_state = LPFC_LINK_DOWN;
367 /* Only process IOCBs on ELS ring till hba_state is READY */
368 if (psli->ring[psli->extra_ring].cmdringaddr)
369 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
370 if (psli->ring[psli->fcp_ring].cmdringaddr)
371 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
372 if (psli->ring[psli->next_ring].cmdringaddr)
373 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
375 /* Post receive buffers for desired rings */
376 if (phba->sli_rev != 3)
377 lpfc_post_rcv_buf(phba);
379 /* Enable appropriate host interrupts */
380 spin_lock_irq(&phba->hbalock);
381 status = readl(phba->HCregaddr);
382 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
383 if (psli->num_rings > 0)
384 status |= HC_R0INT_ENA;
385 if (psli->num_rings > 1)
386 status |= HC_R1INT_ENA;
387 if (psli->num_rings > 2)
388 status |= HC_R2INT_ENA;
389 if (psli->num_rings > 3)
390 status |= HC_R3INT_ENA;
392 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
393 (phba->cfg_poll & DISABLE_FCP_RING_INT))
394 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
396 writel(status, phba->HCregaddr);
397 readl(phba->HCregaddr); /* flush */
398 spin_unlock_irq(&phba->hbalock);
401 * Setup the ring 0 (els) timeout handler
403 timeout = phba->fc_ratov << 1;
404 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
405 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
406 phba->hb_outstanding = 0;
407 phba->last_completion_time = jiffies;
409 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
410 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
412 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
413 lpfc_set_loopback_flag(phba);
414 if (rc != MBX_SUCCESS) {
415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
416 "0454 Adapter failed to init, mbxCmd x%x "
417 "INIT_LINK, mbxStatus x%x\n",
418 mb->mbxCommand, mb->mbxStatus);
420 /* Clear all interrupt enable conditions */
421 writel(0, phba->HCregaddr);
422 readl(phba->HCregaddr); /* flush */
423 /* Clear all pending interrupts */
424 writel(0xffffffff, phba->HAregaddr);
425 readl(phba->HAregaddr); /* flush */
427 phba->link_state = LPFC_HBA_ERROR;
429 mempool_free(pmb, phba->mbox_mem_pool);
432 /* MBOX buffer will be freed in mbox compl */
433 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
434 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
435 pmb->mbox_cmpl = lpfc_config_async_cmpl;
436 pmb->vport = phba->pport;
437 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
439 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
440 lpfc_printf_log(phba,
443 "0456 Adapter failed to issue "
444 "ASYNCEVT_ENABLE mbox status x%x \n.",
446 mempool_free(pmb, phba->mbox_mem_pool);
451 /************************************************************************/
453 /* lpfc_hba_down_prep */
454 /* This routine will do LPFC uninitialization before the */
455 /* HBA is reset when bringing down the SLI Layer. This will be */
456 /* initialized as a SLI layer callback routine. */
457 /* This routine returns 0 on success. Any other return value */
458 /* indicates an error. */
460 /************************************************************************/
462 lpfc_hba_down_prep(struct lpfc_hba *phba)
464 /* Disable interrupts */
465 writel(0, phba->HCregaddr);
466 readl(phba->HCregaddr); /* flush */
468 lpfc_cleanup_discovery_resources(phba->pport);
472 /************************************************************************/
474 /* lpfc_hba_down_post */
475 /* This routine will do uninitialization after the HBA is reset */
476 /* when bringing down the SLI Layer. */
477 /* This routine returns 0 on success. Any other return value */
478 /* indicates an error. */
480 /************************************************************************/
482 lpfc_hba_down_post(struct lpfc_hba *phba)
484 struct lpfc_sli *psli = &phba->sli;
485 struct lpfc_sli_ring *pring;
486 struct lpfc_dmabuf *mp, *next_mp;
489 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
490 lpfc_sli_hbqbuf_free_all(phba);
492 /* Cleanup preposted buffers on the ELS ring */
493 pring = &psli->ring[LPFC_ELS_RING];
494 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
496 pring->postbufq_cnt--;
497 lpfc_mbuf_free(phba, mp->virt, mp->phys);
502 for (i = 0; i < psli->num_rings; i++) {
503 pring = &psli->ring[i];
504 lpfc_sli_abort_iocb_ring(phba, pring);
510 /* HBA heart beat timeout handler */
512 lpfc_hb_timeout(unsigned long ptr)
514 struct lpfc_hba *phba;
517 phba = (struct lpfc_hba *)ptr;
518 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
519 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
520 phba->pport->work_port_events |= WORKER_HB_TMO;
521 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
524 wake_up(phba->work_wait);
529 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
531 unsigned long drvr_flag;
533 spin_lock_irqsave(&phba->hbalock, drvr_flag);
534 phba->hb_outstanding = 0;
535 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
537 mempool_free(pmboxq, phba->mbox_mem_pool);
538 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
539 !(phba->link_state == LPFC_HBA_ERROR) &&
540 !(phba->pport->load_flag & FC_UNLOADING))
541 mod_timer(&phba->hb_tmofunc,
542 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
547 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
549 LPFC_MBOXQ_t *pmboxq;
550 struct lpfc_dmabuf *buf_ptr;
552 struct lpfc_sli *psli = &phba->sli;
553 LIST_HEAD(completions);
555 if ((phba->link_state == LPFC_HBA_ERROR) ||
556 (phba->pport->load_flag & FC_UNLOADING) ||
557 (phba->pport->fc_flag & FC_OFFLINE_MODE))
560 spin_lock_irq(&phba->pport->work_port_lock);
561 /* If the timer is already canceled do nothing */
562 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
563 spin_unlock_irq(&phba->pport->work_port_lock);
567 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
569 spin_unlock_irq(&phba->pport->work_port_lock);
570 if (!phba->hb_outstanding)
571 mod_timer(&phba->hb_tmofunc,
572 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
574 mod_timer(&phba->hb_tmofunc,
575 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
578 spin_unlock_irq(&phba->pport->work_port_lock);
580 if (phba->elsbuf_cnt &&
581 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
582 spin_lock_irq(&phba->hbalock);
583 list_splice_init(&phba->elsbuf, &completions);
584 phba->elsbuf_cnt = 0;
585 phba->elsbuf_prev_cnt = 0;
586 spin_unlock_irq(&phba->hbalock);
588 while (!list_empty(&completions)) {
589 list_remove_head(&completions, buf_ptr,
590 struct lpfc_dmabuf, list);
591 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
595 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
597 /* If there is no heart beat outstanding, issue a heartbeat command */
598 if (phba->cfg_enable_hba_heartbeat) {
599 if (!phba->hb_outstanding) {
600 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
602 mod_timer(&phba->hb_tmofunc,
603 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
607 lpfc_heart_beat(phba, pmboxq);
608 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
609 pmboxq->vport = phba->pport;
610 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
612 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
613 mempool_free(pmboxq, phba->mbox_mem_pool);
614 mod_timer(&phba->hb_tmofunc,
615 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
618 mod_timer(&phba->hb_tmofunc,
619 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
620 phba->hb_outstanding = 1;
624 * If heart beat timeout called with hb_outstanding set
625 * we need to take the HBA offline.
627 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
628 "0459 Adapter heartbeat failure, "
629 "taking this port offline.\n");
631 spin_lock_irq(&phba->hbalock);
632 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
633 spin_unlock_irq(&phba->hbalock);
635 lpfc_offline_prep(phba);
637 lpfc_unblock_mgmt_io(phba);
638 phba->link_state = LPFC_HBA_ERROR;
639 lpfc_hba_down_post(phba);
644 /************************************************************************/
646 /* lpfc_handle_eratt */
647 /* This routine will handle processing a Host Attention */
648 /* Error Status event. This will be initialized */
649 /* as a SLI layer callback routine. */
651 /************************************************************************/
653 lpfc_handle_eratt(struct lpfc_hba *phba)
655 struct lpfc_vport *vport = phba->pport;
656 struct lpfc_sli *psli = &phba->sli;
657 struct lpfc_sli_ring *pring;
658 struct lpfc_vport **vports;
660 unsigned long temperature;
661 struct temp_event temp_event_data;
662 struct Scsi_Host *shost;
665 /* If the pci channel is offline, ignore possible errors,
666 * since we cannot communicate with the pci card anyway. */
667 if (pci_channel_offline(phba->pcidev))
669 /* If resets are disabled then leave the HBA alone and return */
670 if (!phba->cfg_enable_hba_reset)
673 if (phba->work_hs & HS_FFER6 ||
674 phba->work_hs & HS_FFER5) {
675 /* Re-establishing Link */
676 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
677 "1301 Re-establishing Link "
678 "Data: x%x x%x x%x\n",
680 phba->work_status[0], phba->work_status[1]);
681 vports = lpfc_create_vport_work_array(phba);
684 i < LPFC_MAX_VPORTS && vports[i] != NULL;
686 shost = lpfc_shost_from_vport(vports[i]);
687 spin_lock_irq(shost->host_lock);
688 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
689 spin_unlock_irq(shost->host_lock);
691 lpfc_destroy_vport_work_array(vports);
692 spin_lock_irq(&phba->hbalock);
693 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
694 spin_unlock_irq(&phba->hbalock);
697 * Firmware stops when it triggled erratt with HS_FFER6.
698 * That could cause the I/Os dropped by the firmware.
699 * Error iocb (I/O) on txcmplq and let the SCSI layer
700 * retry it after re-establishing link.
702 pring = &psli->ring[psli->fcp_ring];
703 lpfc_sli_abort_iocb_ring(phba, pring);
707 * There was a firmware error. Take the hba offline and then
708 * attempt to restart it.
710 lpfc_offline_prep(phba);
712 lpfc_sli_brdrestart(phba);
713 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
714 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
715 lpfc_unblock_mgmt_io(phba);
718 lpfc_unblock_mgmt_io(phba);
719 } else if (phba->work_hs & HS_CRIT_TEMP) {
720 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
721 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
722 temp_event_data.event_code = LPFC_CRIT_TEMP;
723 temp_event_data.data = (uint32_t)temperature;
725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
726 "0459 Adapter maximum temperature exceeded "
727 "(%ld), taking this port offline "
728 "Data: x%x x%x x%x\n",
729 temperature, phba->work_hs,
730 phba->work_status[0], phba->work_status[1]);
732 shost = lpfc_shost_from_vport(phba->pport);
733 fc_host_post_vendor_event(shost, fc_get_event_number(),
734 sizeof(temp_event_data),
735 (char *) &temp_event_data,
737 | PCI_VENDOR_ID_EMULEX);
739 spin_lock_irq(&phba->hbalock);
740 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
741 phba->over_temp_state = HBA_OVER_TEMP;
742 spin_unlock_irq(&phba->hbalock);
743 lpfc_offline_prep(phba);
745 lpfc_unblock_mgmt_io(phba);
746 phba->link_state = LPFC_HBA_ERROR;
747 lpfc_hba_down_post(phba);
750 /* The if clause above forces this code path when the status
751 * failure is a value other than FFER6. Do not call the offline
752 * twice. This is the adapter hardware error path.
754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
755 "0457 Adapter Hardware Error "
756 "Data: x%x x%x x%x\n",
758 phba->work_status[0], phba->work_status[1]);
760 event_data = FC_REG_DUMP_EVENT;
761 shost = lpfc_shost_from_vport(vport);
762 fc_host_post_vendor_event(shost, fc_get_event_number(),
763 sizeof(event_data), (char *) &event_data,
764 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
766 spin_lock_irq(&phba->hbalock);
767 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
768 spin_unlock_irq(&phba->hbalock);
769 lpfc_offline_prep(phba);
771 lpfc_unblock_mgmt_io(phba);
772 phba->link_state = LPFC_HBA_ERROR;
773 lpfc_hba_down_post(phba);
777 /************************************************************************/
779 /* lpfc_handle_latt */
780 /* This routine will handle processing a Host Attention */
781 /* Link Status event. This will be initialized */
782 /* as a SLI layer callback routine. */
784 /************************************************************************/
786 lpfc_handle_latt(struct lpfc_hba *phba)
788 struct lpfc_vport *vport = phba->pport;
789 struct lpfc_sli *psli = &phba->sli;
791 volatile uint32_t control;
792 struct lpfc_dmabuf *mp;
795 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
797 goto lpfc_handle_latt_err_exit;
799 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
801 goto lpfc_handle_latt_free_pmb;
803 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
805 goto lpfc_handle_latt_free_mp;
809 /* Cleanup any outstanding ELS commands */
810 lpfc_els_flush_all_cmd(phba);
812 psli->slistat.link_event++;
813 lpfc_read_la(phba, pmb, mp);
814 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
816 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
817 if (rc == MBX_NOT_FINISHED)
818 goto lpfc_handle_latt_free_mbuf;
820 /* Clear Link Attention in HA REG */
821 spin_lock_irq(&phba->hbalock);
822 writel(HA_LATT, phba->HAregaddr);
823 readl(phba->HAregaddr); /* flush */
824 spin_unlock_irq(&phba->hbalock);
828 lpfc_handle_latt_free_mbuf:
829 lpfc_mbuf_free(phba, mp->virt, mp->phys);
830 lpfc_handle_latt_free_mp:
832 lpfc_handle_latt_free_pmb:
833 mempool_free(pmb, phba->mbox_mem_pool);
834 lpfc_handle_latt_err_exit:
835 /* Enable Link attention interrupts */
836 spin_lock_irq(&phba->hbalock);
837 psli->sli_flag |= LPFC_PROCESS_LA;
838 control = readl(phba->HCregaddr);
839 control |= HC_LAINT_ENA;
840 writel(control, phba->HCregaddr);
841 readl(phba->HCregaddr); /* flush */
843 /* Clear Link Attention in HA REG */
844 writel(HA_LATT, phba->HAregaddr);
845 readl(phba->HAregaddr); /* flush */
846 spin_unlock_irq(&phba->hbalock);
848 phba->link_state = LPFC_HBA_ERROR;
850 /* The other case is an error from issue_mbox */
852 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
853 "0300 READ_LA: no buffers\n");
858 /************************************************************************/
861 /* This routine will parse the VPD data */
863 /************************************************************************/
865 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
867 uint8_t lenlo, lenhi;
877 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
878 "0455 Vital Product Data: x%x x%x x%x x%x\n",
879 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
881 while (!finished && (index < (len - 4))) {
882 switch (vpd[index]) {
890 i = ((((unsigned short)lenhi) << 8) + lenlo);
899 Length = ((((unsigned short)lenhi) << 8) + lenlo);
900 if (Length > len - index)
901 Length = len - index;
903 /* Look for Serial Number */
904 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
911 phba->SerialNumber[j++] = vpd[index++];
915 phba->SerialNumber[j] = 0;
918 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
919 phba->vpd_flag |= VPD_MODEL_DESC;
926 phba->ModelDesc[j++] = vpd[index++];
930 phba->ModelDesc[j] = 0;
933 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
934 phba->vpd_flag |= VPD_MODEL_NAME;
941 phba->ModelName[j++] = vpd[index++];
945 phba->ModelName[j] = 0;
948 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
949 phba->vpd_flag |= VPD_PROGRAM_TYPE;
956 phba->ProgramType[j++] = vpd[index++];
960 phba->ProgramType[j] = 0;
963 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
964 phba->vpd_flag |= VPD_PORT;
971 phba->Port[j++] = vpd[index++];
1001 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1004 uint16_t dev_id = phba->pcidev->device;
1010 } m = {"<Unknown>", 0, ""};
1012 if (mdp && mdp[0] != '\0'
1013 && descp && descp[0] != '\0')
1016 if (phba->lmt & LMT_10Gb)
1018 else if (phba->lmt & LMT_8Gb)
1020 else if (phba->lmt & LMT_4Gb)
1022 else if (phba->lmt & LMT_2Gb)
1030 case PCI_DEVICE_ID_FIREFLY:
1031 m = (typeof(m)){"LP6000", max_speed, "PCI"};
1033 case PCI_DEVICE_ID_SUPERFLY:
1034 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1035 m = (typeof(m)){"LP7000", max_speed, "PCI"};
1037 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
1039 case PCI_DEVICE_ID_DRAGONFLY:
1040 m = (typeof(m)){"LP8000", max_speed, "PCI"};
1042 case PCI_DEVICE_ID_CENTAUR:
1043 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1044 m = (typeof(m)){"LP9002", max_speed, "PCI"};
1046 m = (typeof(m)){"LP9000", max_speed, "PCI"};
1048 case PCI_DEVICE_ID_RFLY:
1049 m = (typeof(m)){"LP952", max_speed, "PCI"};
1051 case PCI_DEVICE_ID_PEGASUS:
1052 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
1054 case PCI_DEVICE_ID_THOR:
1055 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
1057 case PCI_DEVICE_ID_VIPER:
1058 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
1060 case PCI_DEVICE_ID_PFLY:
1061 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
1063 case PCI_DEVICE_ID_TFLY:
1064 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
1066 case PCI_DEVICE_ID_HELIOS:
1067 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
1069 case PCI_DEVICE_ID_HELIOS_SCSP:
1070 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
1072 case PCI_DEVICE_ID_HELIOS_DCSP:
1073 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
1075 case PCI_DEVICE_ID_NEPTUNE:
1076 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
1078 case PCI_DEVICE_ID_NEPTUNE_SCSP:
1079 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
1081 case PCI_DEVICE_ID_NEPTUNE_DCSP:
1082 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
1084 case PCI_DEVICE_ID_BMID:
1085 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
1087 case PCI_DEVICE_ID_BSMB:
1088 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
1090 case PCI_DEVICE_ID_ZEPHYR:
1091 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1093 case PCI_DEVICE_ID_ZEPHYR_SCSP:
1094 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1096 case PCI_DEVICE_ID_ZEPHYR_DCSP:
1097 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
1099 case PCI_DEVICE_ID_ZMID:
1100 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
1102 case PCI_DEVICE_ID_ZSMB:
1103 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
1105 case PCI_DEVICE_ID_LP101:
1106 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
1108 case PCI_DEVICE_ID_LP10000S:
1109 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
1111 case PCI_DEVICE_ID_LP11000S:
1112 m = (typeof(m)){"LP11000-S", max_speed,
1115 case PCI_DEVICE_ID_LPE11000S:
1116 m = (typeof(m)){"LPe11000-S", max_speed,
1119 case PCI_DEVICE_ID_SAT:
1120 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1122 case PCI_DEVICE_ID_SAT_MID:
1123 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1125 case PCI_DEVICE_ID_SAT_SMB:
1126 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1128 case PCI_DEVICE_ID_SAT_DCSP:
1129 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1131 case PCI_DEVICE_ID_SAT_SCSP:
1132 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1134 case PCI_DEVICE_ID_SAT_S:
1135 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1138 m = (typeof(m)){ NULL };
1142 if (mdp && mdp[0] == '\0')
1143 snprintf(mdp, 79,"%s", m.name);
1144 if (descp && descp[0] == '\0')
1145 snprintf(descp, 255,
1146 "Emulex %s %dGb %s Fibre Channel Adapter",
1147 m.name, m.max_speed, m.bus);
1150 /**************************************************/
1151 /* lpfc_post_buffer */
1153 /* This routine will post count buffers to the */
1154 /* ring with the QUE_RING_BUF_CN command. This */
1155 /* allows 3 buffers / command to be posted. */
1156 /* Returns the number of buffers NOT posted. */
1157 /**************************************************/
1159 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
1163 struct lpfc_iocbq *iocb;
1164 struct lpfc_dmabuf *mp1, *mp2;
1166 cnt += pring->missbufcnt;
1168 /* While there are buffers to post */
1170 /* Allocate buffer for command iocb */
1171 iocb = lpfc_sli_get_iocbq(phba);
1173 pring->missbufcnt = cnt;
1178 /* 2 buffers can be posted per command */
1179 /* Allocate buffer to post */
1180 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1182 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1183 if (!mp1 || !mp1->virt) {
1185 lpfc_sli_release_iocbq(phba, iocb);
1186 pring->missbufcnt = cnt;
1190 INIT_LIST_HEAD(&mp1->list);
1191 /* Allocate buffer to post */
1193 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1195 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1197 if (!mp2 || !mp2->virt) {
1199 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1201 lpfc_sli_release_iocbq(phba, iocb);
1202 pring->missbufcnt = cnt;
1206 INIT_LIST_HEAD(&mp2->list);
1211 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1212 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1213 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1214 icmd->ulpBdeCount = 1;
1217 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1218 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1219 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1221 icmd->ulpBdeCount = 2;
1224 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1227 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1228 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1232 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1236 lpfc_sli_release_iocbq(phba, iocb);
1237 pring->missbufcnt = cnt;
1240 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1242 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1244 pring->missbufcnt = 0;
1248 /************************************************************************/
1250 /* lpfc_post_rcv_buf */
1251 /* This routine post initial rcv buffers to the configured rings */
1253 /************************************************************************/
1255 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1257 struct lpfc_sli *psli = &phba->sli;
1259 /* Ring 0, ELS / CT buffers */
1260 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1261 /* Ring 2 - FCP no buffers needed */
1266 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1268 /************************************************************************/
1272 /************************************************************************/
1274 lpfc_sha_init(uint32_t * HashResultPointer)
1276 HashResultPointer[0] = 0x67452301;
1277 HashResultPointer[1] = 0xEFCDAB89;
1278 HashResultPointer[2] = 0x98BADCFE;
1279 HashResultPointer[3] = 0x10325476;
1280 HashResultPointer[4] = 0xC3D2E1F0;
1283 /************************************************************************/
1285 /* lpfc_sha_iterate */
1287 /************************************************************************/
1289 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1293 uint32_t A, B, C, D, E;
1296 HashWorkingPointer[t] =
1298 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1300 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1301 } while (++t <= 79);
1303 A = HashResultPointer[0];
1304 B = HashResultPointer[1];
1305 C = HashResultPointer[2];
1306 D = HashResultPointer[3];
1307 E = HashResultPointer[4];
1311 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1312 } else if (t < 40) {
1313 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1314 } else if (t < 60) {
1315 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1317 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1319 TEMP += S(5, A) + E + HashWorkingPointer[t];
1325 } while (++t <= 79);
1327 HashResultPointer[0] += A;
1328 HashResultPointer[1] += B;
1329 HashResultPointer[2] += C;
1330 HashResultPointer[3] += D;
1331 HashResultPointer[4] += E;
1335 /************************************************************************/
1337 /* lpfc_challenge_key */
1339 /************************************************************************/
1341 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1343 *HashWorking = (*RandomChallenge ^ *HashWorking);
1346 /************************************************************************/
1350 /************************************************************************/
1352 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1355 uint32_t *HashWorking;
1356 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1358 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
1362 HashWorking[0] = HashWorking[78] = *pwwnn++;
1363 HashWorking[1] = HashWorking[79] = *pwwnn;
1365 for (t = 0; t < 7; t++)
1366 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1368 lpfc_sha_init(hbainit);
1369 lpfc_sha_iterate(hbainit, HashWorking);
1374 lpfc_cleanup(struct lpfc_vport *vport)
1376 struct lpfc_hba *phba = vport->phba;
1377 struct lpfc_nodelist *ndlp, *next_ndlp;
1380 if (phba->link_state > LPFC_LINK_DOWN)
1381 lpfc_port_link_failure(vport);
1383 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1384 if (ndlp->nlp_type & NLP_FABRIC)
1385 lpfc_disc_state_machine(vport, ndlp, NULL,
1386 NLP_EVT_DEVICE_RECOVERY);
1387 lpfc_disc_state_machine(vport, ndlp, NULL,
1391 /* At this point, ALL ndlp's should be gone
1392 * because of the previous NLP_EVT_DEVICE_RM.
1393 * Lets wait for this to happen, if needed.
1395 while (!list_empty(&vport->fc_nodes)) {
1398 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1399 "0233 Nodelist not empty\n");
1403 /* Wait for any activity on ndlps to settle */
1410 lpfc_establish_link_tmo(unsigned long ptr)
1412 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
1413 struct lpfc_vport **vports;
1414 unsigned long iflag;
1417 /* Re-establishing Link, timer expired */
1418 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1419 "1300 Re-establishing Link, timer expired "
1421 phba->pport->fc_flag, phba->pport->port_state);
1422 vports = lpfc_create_vport_work_array(phba);
1424 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1425 struct Scsi_Host *shost;
1426 shost = lpfc_shost_from_vport(vports[i]);
1427 spin_lock_irqsave(shost->host_lock, iflag);
1428 vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1429 spin_unlock_irqrestore(shost->host_lock, iflag);
1431 lpfc_destroy_vport_work_array(vports);
1435 lpfc_stop_vport_timers(struct lpfc_vport *vport)
1437 del_timer_sync(&vport->els_tmofunc);
1438 del_timer_sync(&vport->fc_fdmitmo);
1439 lpfc_can_disctmo(vport);
1444 lpfc_stop_phba_timers(struct lpfc_hba *phba)
1446 del_timer_sync(&phba->fcp_poll_timer);
1447 del_timer_sync(&phba->fc_estabtmo);
1448 lpfc_stop_vport_timers(phba->pport);
1449 del_timer_sync(&phba->sli.mbox_tmo);
1450 del_timer_sync(&phba->fabric_block_timer);
1451 phba->hb_outstanding = 0;
1452 del_timer_sync(&phba->hb_tmofunc);
1457 lpfc_block_mgmt_io(struct lpfc_hba * phba)
1459 unsigned long iflag;
1461 spin_lock_irqsave(&phba->hbalock, iflag);
1462 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1463 spin_unlock_irqrestore(&phba->hbalock, iflag);
1467 lpfc_online(struct lpfc_hba *phba)
1469 struct lpfc_vport *vport = phba->pport;
1470 struct lpfc_vport **vports;
1476 if (!(vport->fc_flag & FC_OFFLINE_MODE))
1479 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1480 "0458 Bring Adapter online\n");
1482 lpfc_block_mgmt_io(phba);
1484 if (!lpfc_sli_queue_setup(phba)) {
1485 lpfc_unblock_mgmt_io(phba);
1489 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1490 lpfc_unblock_mgmt_io(phba);
1494 vports = lpfc_create_vport_work_array(phba);
1496 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1497 struct Scsi_Host *shost;
1498 shost = lpfc_shost_from_vport(vports[i]);
1499 spin_lock_irq(shost->host_lock);
1500 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1501 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1502 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1503 spin_unlock_irq(shost->host_lock);
1505 lpfc_destroy_vport_work_array(vports);
1507 lpfc_unblock_mgmt_io(phba);
1512 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1514 unsigned long iflag;
1516 spin_lock_irqsave(&phba->hbalock, iflag);
1517 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1518 spin_unlock_irqrestore(&phba->hbalock, iflag);
1522 lpfc_offline_prep(struct lpfc_hba * phba)
1524 struct lpfc_vport *vport = phba->pport;
1525 struct lpfc_nodelist *ndlp, *next_ndlp;
1526 struct lpfc_vport **vports;
1529 if (vport->fc_flag & FC_OFFLINE_MODE)
1532 lpfc_block_mgmt_io(phba);
1534 lpfc_linkdown(phba);
1536 /* Issue an unreg_login to all nodes on all vports */
1537 vports = lpfc_create_vport_work_array(phba);
1538 if (vports != NULL) {
1539 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1540 struct Scsi_Host *shost;
1542 if (vports[i]->load_flag & FC_UNLOADING)
1544 shost = lpfc_shost_from_vport(vports[i]);
1545 list_for_each_entry_safe(ndlp, next_ndlp,
1546 &vports[i]->fc_nodes,
1548 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1550 if (ndlp->nlp_type & NLP_FABRIC) {
1551 lpfc_disc_state_machine(vports[i], ndlp,
1552 NULL, NLP_EVT_DEVICE_RECOVERY);
1553 lpfc_disc_state_machine(vports[i], ndlp,
1554 NULL, NLP_EVT_DEVICE_RM);
1556 spin_lock_irq(shost->host_lock);
1557 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1558 spin_unlock_irq(shost->host_lock);
1559 lpfc_unreg_rpi(vports[i], ndlp);
1563 lpfc_destroy_vport_work_array(vports);
1565 lpfc_sli_flush_mbox_queue(phba);
1569 lpfc_offline(struct lpfc_hba *phba)
1571 struct Scsi_Host *shost;
1572 struct lpfc_vport **vports;
1575 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1578 /* stop all timers associated with this hba */
1579 lpfc_stop_phba_timers(phba);
1580 vports = lpfc_create_vport_work_array(phba);
1582 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
1583 lpfc_stop_vport_timers(vports[i]);
1584 lpfc_destroy_vport_work_array(vports);
1585 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1586 "0460 Bring Adapter offline\n");
1587 /* Bring down the SLI Layer and cleanup. The HBA is offline
1589 lpfc_sli_hba_down(phba);
1590 spin_lock_irq(&phba->hbalock);
1592 spin_unlock_irq(&phba->hbalock);
1593 vports = lpfc_create_vport_work_array(phba);
1595 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1596 shost = lpfc_shost_from_vport(vports[i]);
1597 spin_lock_irq(shost->host_lock);
1598 vports[i]->work_port_events = 0;
1599 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1600 spin_unlock_irq(shost->host_lock);
1602 lpfc_destroy_vport_work_array(vports);
1605 /******************************************************************************
1606 * Function name: lpfc_scsi_free
1608 * Description: Called from lpfc_pci_remove_one free internal driver resources
1610 ******************************************************************************/
1612 lpfc_scsi_free(struct lpfc_hba *phba)
1614 struct lpfc_scsi_buf *sb, *sb_next;
1615 struct lpfc_iocbq *io, *io_next;
1617 spin_lock_irq(&phba->hbalock);
1618 /* Release all the lpfc_scsi_bufs maintained by this host. */
1619 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1620 list_del(&sb->list);
1621 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1624 phba->total_scsi_bufs--;
1627 /* Release all the lpfc_iocbq entries maintained by this host. */
1628 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1629 list_del(&io->list);
1631 phba->total_iocbq_bufs--;
1634 spin_unlock_irq(&phba->hbalock);
1640 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
1642 struct lpfc_vport *vport;
1643 struct Scsi_Host *shost;
1646 if (dev != &phba->pcidev->dev)
1647 shost = scsi_host_alloc(&lpfc_vport_template,
1648 sizeof(struct lpfc_vport));
1650 shost = scsi_host_alloc(&lpfc_template,
1651 sizeof(struct lpfc_vport));
1655 vport = (struct lpfc_vport *) shost->hostdata;
1658 vport->load_flag |= FC_LOADING;
1659 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1661 lpfc_get_vport_cfgparam(vport);
1662 shost->unique_id = instance;
1663 shost->max_id = LPFC_MAX_TARGET;
1664 shost->max_lun = vport->cfg_max_luns;
1665 shost->this_id = -1;
1666 shost->max_cmd_len = 16;
1668 * Set initial can_queue value since 0 is no longer supported and
1669 * scsi_add_host will fail. This will be adjusted later based on the
1670 * max xri value determined in hba setup.
1672 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1673 if (dev != &phba->pcidev->dev) {
1674 shost->transportt = lpfc_vport_transport_template;
1675 vport->port_type = LPFC_NPIV_PORT;
1677 shost->transportt = lpfc_transport_template;
1678 vport->port_type = LPFC_PHYSICAL_PORT;
1681 /* Initialize all internally managed lists. */
1682 INIT_LIST_HEAD(&vport->fc_nodes);
1683 spin_lock_init(&vport->work_port_lock);
1685 init_timer(&vport->fc_disctmo);
1686 vport->fc_disctmo.function = lpfc_disc_timeout;
1687 vport->fc_disctmo.data = (unsigned long)vport;
1689 init_timer(&vport->fc_fdmitmo);
1690 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1691 vport->fc_fdmitmo.data = (unsigned long)vport;
1693 init_timer(&vport->els_tmofunc);
1694 vport->els_tmofunc.function = lpfc_els_timeout;
1695 vport->els_tmofunc.data = (unsigned long)vport;
1697 error = scsi_add_host(shost, dev);
1701 spin_lock_irq(&phba->hbalock);
1702 list_add_tail(&vport->listentry, &phba->port_list);
1703 spin_unlock_irq(&phba->hbalock);
1707 scsi_host_put(shost);
1713 destroy_port(struct lpfc_vport *vport)
1715 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1716 struct lpfc_hba *phba = vport->phba;
1718 kfree(vport->vname);
1720 lpfc_debugfs_terminate(vport);
1721 fc_remove_host(shost);
1722 scsi_remove_host(shost);
1724 spin_lock_irq(&phba->hbalock);
1725 list_del_init(&vport->listentry);
1726 spin_unlock_irq(&phba->hbalock);
1728 lpfc_cleanup(vport);
1733 lpfc_get_instance(void)
1737 /* Assign an unused number */
1738 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1740 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1746 * Note: there is no scan_start function as adapter initialization
1747 * will have asynchronously kicked off the link initialization.
1750 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1752 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1753 struct lpfc_hba *phba = vport->phba;
1756 spin_lock_irq(shost->host_lock);
1758 if (vport->load_flag & FC_UNLOADING) {
1762 if (time >= 30 * HZ) {
1763 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1764 "0461 Scanning longer than 30 "
1765 "seconds. Continuing initialization\n");
1769 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1770 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1771 "0465 Link down longer than 15 "
1772 "seconds. Continuing initialization\n");
1777 if (vport->port_state != LPFC_VPORT_READY)
1779 if (vport->num_disc_nodes || vport->fc_prli_sent)
1781 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
1783 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
1789 spin_unlock_irq(shost->host_lock);
1793 void lpfc_host_attrib_init(struct Scsi_Host *shost)
1795 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1796 struct lpfc_hba *phba = vport->phba;
1798 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1801 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1802 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
1803 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1805 memset(fc_host_supported_fc4s(shost), 0,
1806 sizeof(fc_host_supported_fc4s(shost)));
1807 fc_host_supported_fc4s(shost)[2] = 1;
1808 fc_host_supported_fc4s(shost)[7] = 1;
1810 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1811 sizeof fc_host_symbolic_name(shost));
1813 fc_host_supported_speeds(shost) = 0;
1814 if (phba->lmt & LMT_10Gb)
1815 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1816 if (phba->lmt & LMT_8Gb)
1817 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
1818 if (phba->lmt & LMT_4Gb)
1819 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1820 if (phba->lmt & LMT_2Gb)
1821 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1822 if (phba->lmt & LMT_1Gb)
1823 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1825 fc_host_maxframe_size(shost) =
1826 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1827 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
1829 /* This value is also unchanging */
1830 memset(fc_host_active_fc4s(shost), 0,
1831 sizeof(fc_host_active_fc4s(shost)));
1832 fc_host_active_fc4s(shost)[2] = 1;
1833 fc_host_active_fc4s(shost)[7] = 1;
1835 fc_host_max_npiv_vports(shost) = phba->max_vpi;
1836 spin_lock_irq(shost->host_lock);
1837 vport->load_flag &= ~FC_LOADING;
1838 spin_unlock_irq(shost->host_lock);
1841 static int __devinit
1842 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1844 struct lpfc_vport *vport = NULL;
1845 struct lpfc_hba *phba;
1846 struct lpfc_sli *psli;
1847 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1848 struct Scsi_Host *shost = NULL;
1850 unsigned long bar0map_len, bar2map_len;
1851 int error = -ENODEV, retval;
1855 if (pci_enable_device(pdev))
1857 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1858 goto out_disable_device;
1860 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1862 goto out_release_regions;
1864 spin_lock_init(&phba->hbalock);
1866 phba->pcidev = pdev;
1868 /* Assign an unused board number */
1869 if ((phba->brd_no = lpfc_get_instance()) < 0)
1872 INIT_LIST_HEAD(&phba->port_list);
1874 * Get all the module params for configuring this host and then
1875 * establish the host.
1877 lpfc_get_cfgparam(phba);
1878 phba->max_vpi = LPFC_MAX_VPI;
1880 /* Initialize timers used by driver */
1881 init_timer(&phba->fc_estabtmo);
1882 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1883 phba->fc_estabtmo.data = (unsigned long)phba;
1885 init_timer(&phba->hb_tmofunc);
1886 phba->hb_tmofunc.function = lpfc_hb_timeout;
1887 phba->hb_tmofunc.data = (unsigned long)phba;
1890 init_timer(&psli->mbox_tmo);
1891 psli->mbox_tmo.function = lpfc_mbox_timeout;
1892 psli->mbox_tmo.data = (unsigned long) phba;
1893 init_timer(&phba->fcp_poll_timer);
1894 phba->fcp_poll_timer.function = lpfc_poll_timeout;
1895 phba->fcp_poll_timer.data = (unsigned long) phba;
1896 init_timer(&phba->fabric_block_timer);
1897 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1898 phba->fabric_block_timer.data = (unsigned long) phba;
1900 pci_set_master(pdev);
1901 pci_try_set_mwi(pdev);
1903 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1904 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1905 goto out_idr_remove;
1908 * Get the bus address of Bar0 and Bar2 and the number of bytes
1909 * required by each mapping.
1911 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1912 bar0map_len = pci_resource_len(phba->pcidev, 0);
1914 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1915 bar2map_len = pci_resource_len(phba->pcidev, 2);
1917 /* Map HBA SLIM to a kernel virtual address. */
1918 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
1919 if (!phba->slim_memmap_p) {
1921 dev_printk(KERN_ERR, &pdev->dev,
1922 "ioremap failed for SLIM memory.\n");
1923 goto out_idr_remove;
1926 /* Map HBA Control Registers to a kernel virtual address. */
1927 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
1928 if (!phba->ctrl_regs_memmap_p) {
1930 dev_printk(KERN_ERR, &pdev->dev,
1931 "ioremap failed for HBA control registers.\n");
1932 goto out_iounmap_slim;
1935 /* Allocate memory for SLI-2 structures */
1936 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1937 &phba->slim2p_mapping, GFP_KERNEL);
1941 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
1943 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1944 lpfc_sli_hbq_size(),
1945 &phba->hbqslimp.phys,
1947 if (!phba->hbqslimp.virt)
1950 hbq_count = lpfc_sli_hbq_count();
1951 ptr = phba->hbqslimp.virt;
1952 for (i = 0; i < hbq_count; ++i) {
1953 phba->hbqs[i].hbq_virt = ptr;
1954 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
1955 ptr += (lpfc_hbq_defs[i]->entry_count *
1956 sizeof(struct lpfc_hbq_entry));
1958 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
1959 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
1961 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
1963 /* Initialize the SLI Layer to run with lpfc HBAs. */
1964 lpfc_sli_setup(phba);
1965 lpfc_sli_queue_setup(phba);
1967 retval = lpfc_mem_alloc(phba);
1970 goto out_free_hbqslimp;
1973 /* Initialize and populate the iocb list per host. */
1974 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1975 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1976 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1977 if (iocbq_entry == NULL) {
1978 printk(KERN_ERR "%s: only allocated %d iocbs of "
1979 "expected %d count. Unloading driver.\n",
1980 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1982 goto out_free_iocbq;
1985 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1987 kfree (iocbq_entry);
1988 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1989 "Unloading driver.\n",
1992 goto out_free_iocbq;
1995 spin_lock_irq(&phba->hbalock);
1996 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1997 phba->total_iocbq_bufs++;
1998 spin_unlock_irq(&phba->hbalock);
2001 /* Initialize HBA structure */
2002 phba->fc_edtov = FF_DEF_EDTOV;
2003 phba->fc_ratov = FF_DEF_RATOV;
2004 phba->fc_altov = FF_DEF_ALTOV;
2005 phba->fc_arbtov = FF_DEF_ARBTOV;
2007 INIT_LIST_HEAD(&phba->work_list);
2008 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2009 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2011 /* Startup the kernel thread for this host adapter. */
2012 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2013 "lpfc_worker_%d", phba->brd_no);
2014 if (IS_ERR(phba->worker_thread)) {
2015 error = PTR_ERR(phba->worker_thread);
2016 goto out_free_iocbq;
2019 /* Initialize the list of scsi buffers used by driver for scsi IO. */
2020 spin_lock_init(&phba->scsi_buf_list_lock);
2021 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2023 /* Initialize list of fabric iocbs */
2024 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2026 /* Initialize list to save ELS buffers */
2027 INIT_LIST_HEAD(&phba->elsbuf);
2029 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
2031 goto out_kthread_stop;
2033 shost = lpfc_shost_from_vport(vport);
2034 phba->pport = vport;
2035 lpfc_debugfs_initialize(vport);
2037 pci_set_drvdata(pdev, shost);
2039 if (phba->cfg_use_msi) {
2040 retval = pci_enable_msi(phba->pcidev);
2042 phba->using_msi = 1;
2044 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2045 "0452 Enable MSI failed, continuing "
2049 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
2050 LPFC_DRIVER_NAME, phba);
2052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2053 "0451 Enable interrupt handler failed\n");
2055 goto out_disable_msi;
2058 phba->MBslimaddr = phba->slim_memmap_p;
2059 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2060 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2061 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2062 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2064 if (lpfc_alloc_sysfs_attr(vport)) {
2069 if (lpfc_sli_hba_setup(phba)) {
2071 goto out_remove_device;
2075 * hba setup may have changed the hba_queue_depth so we need to adjust
2076 * the value of can_queue.
2078 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2080 lpfc_host_attrib_init(shost);
2082 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2083 spin_lock_irq(shost->host_lock);
2084 lpfc_poll_start_timer(phba);
2085 spin_unlock_irq(shost->host_lock);
2088 scsi_scan_host(shost);
2093 lpfc_free_sysfs_attr(vport);
2094 spin_lock_irq(shost->host_lock);
2095 vport->load_flag |= FC_UNLOADING;
2096 spin_unlock_irq(shost->host_lock);
2098 lpfc_stop_phba_timers(phba);
2099 phba->pport->work_port_events = 0;
2100 free_irq(phba->pcidev->irq, phba);
2102 if (phba->using_msi)
2103 pci_disable_msi(phba->pcidev);
2104 destroy_port(vport);
2106 kthread_stop(phba->worker_thread);
2108 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2109 &phba->lpfc_iocb_list, list) {
2111 phba->total_iocbq_bufs--;
2113 lpfc_mem_free(phba);
2115 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2116 phba->hbqslimp.phys);
2118 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2119 phba->slim2p_mapping);
2121 iounmap(phba->ctrl_regs_memmap_p);
2123 iounmap(phba->slim_memmap_p);
2125 idr_remove(&lpfc_hba_index, phba->brd_no);
2128 out_release_regions:
2129 pci_release_regions(pdev);
2131 pci_disable_device(pdev);
2133 pci_set_drvdata(pdev, NULL);
2135 scsi_host_put(shost);
2139 static void __devexit
2140 lpfc_pci_remove_one(struct pci_dev *pdev)
2142 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2143 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2144 struct lpfc_hba *phba = vport->phba;
2145 spin_lock_irq(&phba->hbalock);
2146 vport->load_flag |= FC_UNLOADING;
2147 spin_unlock_irq(&phba->hbalock);
2149 kfree(vport->vname);
2150 lpfc_free_sysfs_attr(vport);
2152 fc_remove_host(shost);
2153 scsi_remove_host(shost);
2154 lpfc_cleanup(vport);
2157 * Bring down the SLI Layer. This step disable all interrupts,
2158 * clears the rings, discards all mailbox commands, and resets
2161 lpfc_sli_hba_down(phba);
2162 lpfc_sli_brdrestart(phba);
2164 lpfc_stop_phba_timers(phba);
2165 spin_lock_irq(&phba->hbalock);
2166 list_del_init(&vport->listentry);
2167 spin_unlock_irq(&phba->hbalock);
2169 lpfc_debugfs_terminate(vport);
2171 kthread_stop(phba->worker_thread);
2173 /* Release the irq reservation */
2174 free_irq(phba->pcidev->irq, phba);
2175 if (phba->using_msi)
2176 pci_disable_msi(phba->pcidev);
2178 pci_set_drvdata(pdev, NULL);
2179 scsi_host_put(shost);
2182 * Call scsi_free before mem_free since scsi bufs are released to their
2183 * corresponding pools here.
2185 lpfc_scsi_free(phba);
2186 lpfc_mem_free(phba);
2188 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2189 phba->hbqslimp.phys);
2191 /* Free resources associated with SLI2 interface */
2192 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2193 phba->slim2p, phba->slim2p_mapping);
2195 /* unmap adapter SLIM and Control Registers */
2196 iounmap(phba->ctrl_regs_memmap_p);
2197 iounmap(phba->slim_memmap_p);
2199 idr_remove(&lpfc_hba_index, phba->brd_no);
2203 pci_release_regions(pdev);
2204 pci_disable_device(pdev);
2208 * lpfc_io_error_detected - called when PCI error is detected
2209 * @pdev: Pointer to PCI device
2210 * @state: The current pci conneection state
2212 * This function is called after a PCI bus error affecting
2213 * this device has been detected.
2215 static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2216 pci_channel_state_t state)
2218 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2219 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2220 struct lpfc_sli *psli = &phba->sli;
2221 struct lpfc_sli_ring *pring;
2223 if (state == pci_channel_io_perm_failure)
2224 return PCI_ERS_RESULT_DISCONNECT;
2226 pci_disable_device(pdev);
2228 * There may be I/Os dropped by the firmware.
2229 * Error iocb (I/O) on txcmplq and let the SCSI layer
2230 * retry it after re-establishing link.
2232 pring = &psli->ring[psli->fcp_ring];
2233 lpfc_sli_abort_iocb_ring(phba, pring);
2235 /* Release the irq reservation */
2236 free_irq(phba->pcidev->irq, phba);
2237 if (phba->using_msi)
2238 pci_disable_msi(phba->pcidev);
2240 /* Request a slot reset. */
2241 return PCI_ERS_RESULT_NEED_RESET;
2245 * lpfc_io_slot_reset - called after the pci bus has been reset.
2246 * @pdev: Pointer to PCI device
2248 * Restart the card from scratch, as if from a cold-boot.
2250 static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2252 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2253 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2254 struct lpfc_sli *psli = &phba->sli;
2255 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2257 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2258 if (pci_enable_device_bars(pdev, bars)) {
2259 printk(KERN_ERR "lpfc: Cannot re-enable "
2260 "PCI device after reset.\n");
2261 return PCI_ERS_RESULT_DISCONNECT;
2264 pci_set_master(pdev);
2266 /* Re-establishing Link */
2267 spin_lock_irq(shost->host_lock);
2268 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2269 spin_unlock_irq(shost->host_lock);
2271 spin_lock_irq(&phba->hbalock);
2272 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2273 spin_unlock_irq(&phba->hbalock);
2276 /* Take device offline; this will perform cleanup */
2278 lpfc_sli_brdrestart(phba);
2280 return PCI_ERS_RESULT_RECOVERED;
2284 * lpfc_io_resume - called when traffic can start flowing again.
2285 * @pdev: Pointer to PCI device
2287 * This callback is called when the error recovery driver tells us that
2288 * its OK to resume normal operation.
2290 static void lpfc_io_resume(struct pci_dev *pdev)
2292 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2293 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2295 if (lpfc_online(phba) == 0) {
2296 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2300 static struct pci_device_id lpfc_id_table[] = {
2301 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2302 PCI_ANY_ID, PCI_ANY_ID, },
2303 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2304 PCI_ANY_ID, PCI_ANY_ID, },
2305 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2306 PCI_ANY_ID, PCI_ANY_ID, },
2307 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2308 PCI_ANY_ID, PCI_ANY_ID, },
2309 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2310 PCI_ANY_ID, PCI_ANY_ID, },
2311 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2312 PCI_ANY_ID, PCI_ANY_ID, },
2313 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2314 PCI_ANY_ID, PCI_ANY_ID, },
2315 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2316 PCI_ANY_ID, PCI_ANY_ID, },
2317 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2318 PCI_ANY_ID, PCI_ANY_ID, },
2319 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2320 PCI_ANY_ID, PCI_ANY_ID, },
2321 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2322 PCI_ANY_ID, PCI_ANY_ID, },
2323 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2324 PCI_ANY_ID, PCI_ANY_ID, },
2325 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2326 PCI_ANY_ID, PCI_ANY_ID, },
2327 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2328 PCI_ANY_ID, PCI_ANY_ID, },
2329 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2330 PCI_ANY_ID, PCI_ANY_ID, },
2331 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2332 PCI_ANY_ID, PCI_ANY_ID, },
2333 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2334 PCI_ANY_ID, PCI_ANY_ID, },
2335 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2336 PCI_ANY_ID, PCI_ANY_ID, },
2337 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2338 PCI_ANY_ID, PCI_ANY_ID, },
2339 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2340 PCI_ANY_ID, PCI_ANY_ID, },
2341 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2342 PCI_ANY_ID, PCI_ANY_ID, },
2343 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2344 PCI_ANY_ID, PCI_ANY_ID, },
2345 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2346 PCI_ANY_ID, PCI_ANY_ID, },
2347 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2348 PCI_ANY_ID, PCI_ANY_ID, },
2349 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2350 PCI_ANY_ID, PCI_ANY_ID, },
2351 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2352 PCI_ANY_ID, PCI_ANY_ID, },
2353 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2354 PCI_ANY_ID, PCI_ANY_ID, },
2355 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2356 PCI_ANY_ID, PCI_ANY_ID, },
2357 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2358 PCI_ANY_ID, PCI_ANY_ID, },
2359 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2360 PCI_ANY_ID, PCI_ANY_ID, },
2361 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2362 PCI_ANY_ID, PCI_ANY_ID, },
2363 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2364 PCI_ANY_ID, PCI_ANY_ID, },
2365 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2366 PCI_ANY_ID, PCI_ANY_ID, },
2370 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2372 static struct pci_error_handlers lpfc_err_handler = {
2373 .error_detected = lpfc_io_error_detected,
2374 .slot_reset = lpfc_io_slot_reset,
2375 .resume = lpfc_io_resume,
2378 static struct pci_driver lpfc_driver = {
2379 .name = LPFC_DRIVER_NAME,
2380 .id_table = lpfc_id_table,
2381 .probe = lpfc_pci_probe_one,
2382 .remove = __devexit_p(lpfc_pci_remove_one),
2383 .err_handler = &lpfc_err_handler,
2391 printk(LPFC_MODULE_DESC "\n");
2392 printk(LPFC_COPYRIGHT "\n");
2394 if (lpfc_enable_npiv) {
2395 lpfc_transport_functions.vport_create = lpfc_vport_create;
2396 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2398 lpfc_transport_template =
2399 fc_attach_transport(&lpfc_transport_functions);
2400 if (lpfc_transport_template == NULL)
2402 if (lpfc_enable_npiv) {
2403 lpfc_vport_transport_template =
2404 fc_attach_transport(&lpfc_vport_transport_functions);
2405 if (lpfc_vport_transport_template == NULL) {
2406 fc_release_transport(lpfc_transport_template);
2410 error = pci_register_driver(&lpfc_driver);
2412 fc_release_transport(lpfc_transport_template);
2413 fc_release_transport(lpfc_vport_transport_template);
2422 pci_unregister_driver(&lpfc_driver);
2423 fc_release_transport(lpfc_transport_template);
2424 if (lpfc_enable_npiv)
2425 fc_release_transport(lpfc_vport_transport_template);
2428 module_init(lpfc_init);
2429 module_exit(lpfc_exit);
2430 MODULE_LICENSE("GPL");
2431 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2432 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2433 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);