1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 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>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_version.h"
45 static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
46 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
47 static int lpfc_post_rcv_buf(struct lpfc_hba *);
49 static struct scsi_transport_template *lpfc_transport_template = NULL;
50 static DEFINE_IDR(lpfc_hba_index);
52 /************************************************************************/
54 /* lpfc_config_port_prep */
55 /* This routine will do LPFC initialization prior to the */
56 /* CONFIG_PORT mailbox command. This will be initialized */
57 /* as a SLI layer callback routine. */
58 /* This routine returns 0 on success or -ERESTART if it wants */
59 /* the SLI layer to reset the HBA and try again. Any */
60 /* other return value indicates an error. */
62 /************************************************************************/
64 lpfc_config_port_prep(struct lpfc_hba * phba)
66 lpfc_vpd_t *vp = &phba->vpd;
70 char *lpfc_vpd_data = NULL;
72 static char licensed[56] =
73 "key unlock for use with gnu public licensed code only\0";
74 static int init_key = 1;
76 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
78 phba->hba_state = LPFC_HBA_ERROR;
83 phba->hba_state = LPFC_INIT_MBX_CMDS;
85 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
87 uint32_t *ptext = (uint32_t *) licensed;
89 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
90 *ptext = cpu_to_be32(*ptext);
94 lpfc_read_nv(phba, pmb);
95 memset((char*)mb->un.varRDnvp.rsvd3, 0,
96 sizeof (mb->un.varRDnvp.rsvd3));
97 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
100 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
102 if (rc != MBX_SUCCESS) {
103 lpfc_printf_log(phba,
106 "%d:0324 Config Port initialization "
107 "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,
115 sizeof (mb->un.varRDnvp.nodename));
118 /* Setup and issue mailbox READ REV command */
119 lpfc_read_rev(phba, pmb);
120 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
121 if (rc != MBX_SUCCESS) {
122 lpfc_printf_log(phba,
125 "%d:0439 Adapter failed to init, mbxCmd x%x "
126 "READ_REV, mbxStatus x%x\n",
128 mb->mbxCommand, mb->mbxStatus);
129 mempool_free( pmb, phba->mbox_mem_pool);
134 * The value of rr must be 1 since the driver set the cv field to 1.
135 * This setting requires the FW to set all revision fields.
137 if (mb->un.varRdRev.rr == 0) {
139 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
140 "%d:0440 Adapter failed to init, READ_REV has "
141 "missing revision information.\n",
143 mempool_free(pmb, phba->mbox_mem_pool);
147 /* Save information as VPD data */
149 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
150 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
151 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
152 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
153 vp->rev.biuRev = mb->un.varRdRev.biuRev;
154 vp->rev.smRev = mb->un.varRdRev.smRev;
155 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
156 vp->rev.endecRev = mb->un.varRdRev.endecRev;
157 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
158 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
159 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
160 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
161 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
162 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
164 if (lpfc_is_LC_HBA(phba->pcidev->device))
165 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
166 sizeof (phba->RandomData));
168 /* Get adapter VPD information */
169 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
172 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
174 goto out_free_context2;
177 lpfc_dump_mem(phba, pmb, offset);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
180 if (rc != MBX_SUCCESS) {
181 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
182 "%d:0441 VPD not present on adapter, "
183 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
185 mb->mbxCommand, mb->mbxStatus);
186 mb->un.varDmp.word_cnt = 0;
188 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
189 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
190 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
191 mb->un.varDmp.word_cnt);
192 offset += mb->un.varDmp.word_cnt;
193 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
194 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
196 kfree(lpfc_vpd_data);
198 kfree(pmb->context2);
200 mempool_free(pmb, phba->mbox_mem_pool);
204 /************************************************************************/
206 /* lpfc_config_port_post */
207 /* This routine will do LPFC initialization after the */
208 /* CONFIG_PORT mailbox command. This will be initialized */
209 /* as a SLI layer callback routine. */
210 /* This routine returns 0 on success. Any other return value */
211 /* indicates an error. */
213 /************************************************************************/
215 lpfc_config_port_post(struct lpfc_hba * phba)
219 struct lpfc_dmabuf *mp;
220 struct lpfc_sli *psli = &phba->sli;
221 uint32_t status, timeout;
224 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
226 phba->hba_state = LPFC_HBA_ERROR;
231 lpfc_config_link(phba, pmb);
232 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
233 if (rc != MBX_SUCCESS) {
234 lpfc_printf_log(phba,
237 "%d:0447 Adapter failed init, mbxCmd x%x "
238 "CONFIG_LINK mbxStatus x%x\n",
240 mb->mbxCommand, mb->mbxStatus);
241 phba->hba_state = LPFC_HBA_ERROR;
242 mempool_free( pmb, phba->mbox_mem_pool);
246 /* Get login parameters for NID. */
247 lpfc_read_sparam(phba, pmb);
248 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
249 lpfc_printf_log(phba,
252 "%d:0448 Adapter failed init, mbxCmd x%x "
253 "READ_SPARM mbxStatus x%x\n",
255 mb->mbxCommand, mb->mbxStatus);
256 phba->hba_state = LPFC_HBA_ERROR;
257 mp = (struct lpfc_dmabuf *) pmb->context1;
258 mempool_free( pmb, phba->mbox_mem_pool);
259 lpfc_mbuf_free(phba, mp->virt, mp->phys);
264 mp = (struct lpfc_dmabuf *) pmb->context1;
266 memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
267 lpfc_mbuf_free(phba, mp->virt, mp->phys);
269 pmb->context1 = NULL;
271 if (phba->cfg_soft_wwpn)
272 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
273 memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
274 sizeof (struct lpfc_name));
275 memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
276 sizeof (struct lpfc_name));
277 /* If no serial number in VPD data, use low 6 bytes of WWNN */
278 /* This should be consolidated into parse_vpd ? - mr */
279 if (phba->SerialNumber[0] == 0) {
282 outptr = &phba->fc_nodename.u.s.IEEE[0];
283 for (i = 0; i < 12; i++) {
285 j = ((status & 0xf0) >> 4);
287 phba->SerialNumber[i] =
288 (char)((uint8_t) 0x30 + (uint8_t) j);
290 phba->SerialNumber[i] =
291 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
295 phba->SerialNumber[i] =
296 (char)((uint8_t) 0x30 + (uint8_t) j);
298 phba->SerialNumber[i] =
299 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
303 lpfc_read_config(phba, pmb);
304 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
305 lpfc_printf_log(phba,
308 "%d:0453 Adapter failed to init, mbxCmd x%x "
309 "READ_CONFIG, mbxStatus x%x\n",
311 mb->mbxCommand, mb->mbxStatus);
312 phba->hba_state = LPFC_HBA_ERROR;
313 mempool_free( pmb, phba->mbox_mem_pool);
317 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
318 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
319 phba->cfg_hba_queue_depth =
320 mb->un.varRdConfig.max_xri + 1;
322 phba->lmt = mb->un.varRdConfig.lmt;
324 /* Get the default values for Model Name and Description */
325 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
327 if ((phba->cfg_link_speed > LINK_SPEED_10G)
328 || ((phba->cfg_link_speed == LINK_SPEED_1G)
329 && !(phba->lmt & LMT_1Gb))
330 || ((phba->cfg_link_speed == LINK_SPEED_2G)
331 && !(phba->lmt & LMT_2Gb))
332 || ((phba->cfg_link_speed == LINK_SPEED_4G)
333 && !(phba->lmt & LMT_4Gb))
334 || ((phba->cfg_link_speed == LINK_SPEED_8G)
335 && !(phba->lmt & LMT_8Gb))
336 || ((phba->cfg_link_speed == LINK_SPEED_10G)
337 && !(phba->lmt & LMT_10Gb))) {
338 /* Reset link speed to auto */
339 lpfc_printf_log(phba,
342 "%d:1302 Invalid speed for this board: "
343 "Reset link speed to auto: x%x\n",
345 phba->cfg_link_speed);
346 phba->cfg_link_speed = LINK_SPEED_AUTO;
349 phba->hba_state = LPFC_LINK_DOWN;
351 /* Only process IOCBs on ring 0 till hba_state is READY */
352 if (psli->ring[psli->extra_ring].cmdringaddr)
353 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
354 if (psli->ring[psli->fcp_ring].cmdringaddr)
355 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
356 if (psli->ring[psli->next_ring].cmdringaddr)
357 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
359 /* Post receive buffers for desired rings */
360 lpfc_post_rcv_buf(phba);
362 /* Enable appropriate host interrupts */
363 spin_lock_irq(phba->host->host_lock);
364 status = readl(phba->HCregaddr);
365 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
366 if (psli->num_rings > 0)
367 status |= HC_R0INT_ENA;
368 if (psli->num_rings > 1)
369 status |= HC_R1INT_ENA;
370 if (psli->num_rings > 2)
371 status |= HC_R2INT_ENA;
372 if (psli->num_rings > 3)
373 status |= HC_R3INT_ENA;
375 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
376 (phba->cfg_poll & DISABLE_FCP_RING_INT))
377 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
379 writel(status, phba->HCregaddr);
380 readl(phba->HCregaddr); /* flush */
381 spin_unlock_irq(phba->host->host_lock);
384 * Setup the ring 0 (els) timeout handler
386 timeout = phba->fc_ratov << 1;
387 phba->els_tmofunc.expires = jiffies + HZ * timeout;
388 add_timer(&phba->els_tmofunc);
390 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
391 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
392 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
393 if (rc != MBX_SUCCESS) {
394 lpfc_printf_log(phba,
397 "%d:0454 Adapter failed to init, mbxCmd x%x "
398 "INIT_LINK, mbxStatus x%x\n",
400 mb->mbxCommand, mb->mbxStatus);
402 /* Clear all interrupt enable conditions */
403 writel(0, phba->HCregaddr);
404 readl(phba->HCregaddr); /* flush */
405 /* Clear all pending interrupts */
406 writel(0xffffffff, phba->HAregaddr);
407 readl(phba->HAregaddr); /* flush */
409 phba->hba_state = LPFC_HBA_ERROR;
411 mempool_free(pmb, phba->mbox_mem_pool);
414 /* MBOX buffer will be freed in mbox compl */
420 lpfc_discovery_wait(struct lpfc_hba *phba)
424 while ((phba->hba_state != LPFC_HBA_READY) ||
425 (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
426 ((phba->fc_map_cnt == 0) && (i<2)) ||
427 (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
428 /* Check every second for 30 retries. */
433 if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
434 /* The link is down. Set linkdown timeout */
438 /* Delay for 1 second to give discovery time to complete. */
446 /************************************************************************/
448 /* lpfc_hba_down_prep */
449 /* This routine will do LPFC uninitialization before the */
450 /* HBA is reset when bringing down the SLI Layer. This will be */
451 /* initialized as a SLI layer callback routine. */
452 /* This routine returns 0 on success. Any other return value */
453 /* indicates an error. */
455 /************************************************************************/
457 lpfc_hba_down_prep(struct lpfc_hba * phba)
459 /* Disable interrupts */
460 writel(0, phba->HCregaddr);
461 readl(phba->HCregaddr); /* flush */
463 /* Cleanup potential discovery resources */
464 lpfc_els_flush_rscn(phba);
465 lpfc_els_flush_cmd(phba);
466 lpfc_disc_flush_list(phba);
471 /************************************************************************/
473 /* lpfc_hba_down_post */
474 /* This routine will do uninitialization after the HBA is reset */
475 /* when bringing down the SLI Layer. */
476 /* This routine returns 0 on success. Any other return value */
477 /* indicates an error. */
479 /************************************************************************/
481 lpfc_hba_down_post(struct lpfc_hba * phba)
483 struct lpfc_sli *psli = &phba->sli;
484 struct lpfc_sli_ring *pring;
485 struct lpfc_dmabuf *mp, *next_mp;
488 /* Cleanup preposted buffers on the ELS ring */
489 pring = &psli->ring[LPFC_ELS_RING];
490 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
492 pring->postbufq_cnt--;
493 lpfc_mbuf_free(phba, mp->virt, mp->phys);
497 for (i = 0; i < psli->num_rings; i++) {
498 pring = &psli->ring[i];
499 lpfc_sli_abort_iocb_ring(phba, pring);
505 /************************************************************************/
507 /* lpfc_handle_eratt */
508 /* This routine will handle processing a Host Attention */
509 /* Error Status event. This will be initialized */
510 /* as a SLI layer callback routine. */
512 /************************************************************************/
514 lpfc_handle_eratt(struct lpfc_hba * phba)
516 struct lpfc_sli *psli = &phba->sli;
517 struct lpfc_sli_ring *pring;
520 if (phba->work_hs & HS_FFER6) {
521 /* Re-establishing Link */
522 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
523 "%d:1301 Re-establishing Link "
524 "Data: x%x x%x x%x\n",
525 phba->brd_no, phba->work_hs,
526 phba->work_status[0], phba->work_status[1]);
527 spin_lock_irq(phba->host->host_lock);
528 phba->fc_flag |= FC_ESTABLISH_LINK;
529 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
530 spin_unlock_irq(phba->host->host_lock);
533 * Firmware stops when it triggled erratt with HS_FFER6.
534 * That could cause the I/Os dropped by the firmware.
535 * Error iocb (I/O) on txcmplq and let the SCSI layer
536 * retry it after re-establishing link.
538 pring = &psli->ring[psli->fcp_ring];
539 lpfc_sli_abort_iocb_ring(phba, pring);
543 * There was a firmware error. Take the hba offline and then
544 * attempt to restart it.
547 lpfc_sli_brdrestart(phba);
548 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
549 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
553 /* The if clause above forces this code path when the status
554 * failure is a value other than FFER6. Do not call the offline
555 * twice. This is the adapter hardware error path.
557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
558 "%d:0457 Adapter Hardware Error "
559 "Data: x%x x%x x%x\n",
560 phba->brd_no, phba->work_hs,
561 phba->work_status[0], phba->work_status[1]);
563 event_data = FC_REG_DUMP_EVENT;
564 fc_host_post_vendor_event(phba->host, fc_get_event_number(),
565 sizeof(event_data), (char *) &event_data,
566 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
568 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
570 phba->hba_state = LPFC_HBA_ERROR;
571 lpfc_hba_down_post(phba);
575 /************************************************************************/
577 /* lpfc_handle_latt */
578 /* This routine will handle processing a Host Attention */
579 /* Link Status event. This will be initialized */
580 /* as a SLI layer callback routine. */
582 /************************************************************************/
584 lpfc_handle_latt(struct lpfc_hba * phba)
586 struct lpfc_sli *psli = &phba->sli;
588 volatile uint32_t control;
589 struct lpfc_dmabuf *mp;
592 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
594 goto lpfc_handle_latt_err_exit;
596 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
598 goto lpfc_handle_latt_free_pmb;
600 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
602 goto lpfc_handle_latt_free_mp;
606 /* Cleanup any outstanding ELS commands */
607 lpfc_els_flush_cmd(phba);
609 psli->slistat.link_event++;
610 lpfc_read_la(phba, pmb, mp);
611 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
612 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
613 if (rc == MBX_NOT_FINISHED)
614 goto lpfc_handle_latt_free_mbuf;
616 /* Clear Link Attention in HA REG */
617 spin_lock_irq(phba->host->host_lock);
618 writel(HA_LATT, phba->HAregaddr);
619 readl(phba->HAregaddr); /* flush */
620 spin_unlock_irq(phba->host->host_lock);
624 lpfc_handle_latt_free_mbuf:
625 lpfc_mbuf_free(phba, mp->virt, mp->phys);
626 lpfc_handle_latt_free_mp:
628 lpfc_handle_latt_free_pmb:
630 lpfc_handle_latt_err_exit:
631 /* Enable Link attention interrupts */
632 spin_lock_irq(phba->host->host_lock);
633 psli->sli_flag |= LPFC_PROCESS_LA;
634 control = readl(phba->HCregaddr);
635 control |= HC_LAINT_ENA;
636 writel(control, phba->HCregaddr);
637 readl(phba->HCregaddr); /* flush */
639 /* Clear Link Attention in HA REG */
640 writel(HA_LATT, phba->HAregaddr);
641 readl(phba->HAregaddr); /* flush */
642 spin_unlock_irq(phba->host->host_lock);
644 phba->hba_state = LPFC_HBA_ERROR;
646 /* The other case is an error from issue_mbox */
648 lpfc_printf_log(phba,
651 "%d:0300 READ_LA: no buffers\n",
657 /************************************************************************/
660 /* This routine will parse the VPD data */
662 /************************************************************************/
664 lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len)
666 uint8_t lenlo, lenhi;
676 lpfc_printf_log(phba,
679 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
681 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
683 while (!finished && (index < (len - 4))) {
684 switch (vpd[index]) {
692 i = ((((unsigned short)lenhi) << 8) + lenlo);
701 Length = ((((unsigned short)lenhi) << 8) + lenlo);
702 if (Length > len - index)
703 Length = len - index;
705 /* Look for Serial Number */
706 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
713 phba->SerialNumber[j++] = vpd[index++];
717 phba->SerialNumber[j] = 0;
720 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
721 phba->vpd_flag |= VPD_MODEL_DESC;
728 phba->ModelDesc[j++] = vpd[index++];
732 phba->ModelDesc[j] = 0;
735 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
736 phba->vpd_flag |= VPD_MODEL_NAME;
743 phba->ModelName[j++] = vpd[index++];
747 phba->ModelName[j] = 0;
750 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
751 phba->vpd_flag |= VPD_PROGRAM_TYPE;
758 phba->ProgramType[j++] = vpd[index++];
762 phba->ProgramType[j] = 0;
765 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
766 phba->vpd_flag |= VPD_PORT;
773 phba->Port[j++] = vpd[index++];
803 lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
806 uint16_t dev_id = phba->pcidev->device;
807 uint16_t dev_subid = phba->pcidev->subsystem_device;
816 } m = {"<Unknown>", 0, "", ""};
818 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
819 ports = (hdrtype == 0x80) ? "2-port " : "";
820 if (mdp && mdp[0] != '\0'
821 && descp && descp[0] != '\0')
824 if (phba->lmt & LMT_10Gb)
826 else if (phba->lmt & LMT_8Gb)
828 else if (phba->lmt & LMT_4Gb)
830 else if (phba->lmt & LMT_2Gb)
838 case PCI_DEVICE_ID_FIREFLY:
839 m = (typeof(m)){"LP6000", max_speed, "", "PCI"};
841 case PCI_DEVICE_ID_SUPERFLY:
842 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
843 m = (typeof(m)){"LP7000", max_speed, "", "PCI"};
845 m = (typeof(m)){"LP7000E", max_speed, "", "PCI"};
847 case PCI_DEVICE_ID_DRAGONFLY:
848 m = (typeof(m)){"LP8000", max_speed, "", "PCI"};
850 case PCI_DEVICE_ID_CENTAUR:
851 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
852 m = (typeof(m)){"LP9002", max_speed, "", "PCI"};
854 m = (typeof(m)){"LP9000", max_speed, "", "PCI"};
856 case PCI_DEVICE_ID_RFLY:
857 m = (typeof(m)){"LP952", max_speed, "", "PCI"};
859 case PCI_DEVICE_ID_PEGASUS:
860 m = (typeof(m)){"LP9802", max_speed, "", "PCI-X"};
862 case PCI_DEVICE_ID_THOR:
864 m = (typeof(m)){"LP10000DC",
865 max_speed, ports, "PCI-X"};
867 m = (typeof(m)){"LP10000",
868 max_speed, ports, "PCI-X"};
870 case PCI_DEVICE_ID_VIPER:
871 m = (typeof(m)){"LPX1000", max_speed, "", "PCI-X"};
873 case PCI_DEVICE_ID_PFLY:
874 m = (typeof(m)){"LP982", max_speed, "", "PCI-X"};
876 case PCI_DEVICE_ID_TFLY:
878 m = (typeof(m)){"LP1050DC", max_speed, ports, "PCI-X"};
880 m = (typeof(m)){"LP1050", max_speed, ports, "PCI-X"};
882 case PCI_DEVICE_ID_HELIOS:
884 m = (typeof(m)){"LP11002", max_speed, ports, "PCI-X2"};
886 m = (typeof(m)){"LP11000", max_speed, ports, "PCI-X2"};
888 case PCI_DEVICE_ID_HELIOS_SCSP:
889 m = (typeof(m)){"LP11000-SP", max_speed, ports, "PCI-X2"};
891 case PCI_DEVICE_ID_HELIOS_DCSP:
892 m = (typeof(m)){"LP11002-SP", max_speed, ports, "PCI-X2"};
894 case PCI_DEVICE_ID_NEPTUNE:
896 m = (typeof(m)){"LPe1002", max_speed, ports, "PCIe"};
898 m = (typeof(m)){"LPe1000", max_speed, ports, "PCIe"};
900 case PCI_DEVICE_ID_NEPTUNE_SCSP:
901 m = (typeof(m)){"LPe1000-SP", max_speed, ports, "PCIe"};
903 case PCI_DEVICE_ID_NEPTUNE_DCSP:
904 m = (typeof(m)){"LPe1002-SP", max_speed, ports, "PCIe"};
906 case PCI_DEVICE_ID_BMID:
907 m = (typeof(m)){"LP1150", max_speed, ports, "PCI-X2"};
909 case PCI_DEVICE_ID_BSMB:
910 m = (typeof(m)){"LP111", max_speed, ports, "PCI-X2"};
912 case PCI_DEVICE_ID_ZEPHYR:
914 m = (typeof(m)){"LPe11002", max_speed, ports, "PCIe"};
916 m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
918 case PCI_DEVICE_ID_ZEPHYR_SCSP:
919 m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
921 case PCI_DEVICE_ID_ZEPHYR_DCSP:
922 m = (typeof(m)){"LPe11002-SP", max_speed, ports, "PCIe"};
924 case PCI_DEVICE_ID_ZMID:
925 m = (typeof(m)){"LPe1150", max_speed, ports, "PCIe"};
927 case PCI_DEVICE_ID_ZSMB:
928 m = (typeof(m)){"LPe111", max_speed, ports, "PCIe"};
930 case PCI_DEVICE_ID_LP101:
931 m = (typeof(m)){"LP101", max_speed, ports, "PCI-X"};
933 case PCI_DEVICE_ID_LP10000S:
934 m = (typeof(m)){"LP10000-S", max_speed, ports, "PCI"};
936 case PCI_DEVICE_ID_LP11000S:
937 case PCI_DEVICE_ID_LPE11000S:
939 case PCI_SUBSYSTEM_ID_LP11000S:
940 m = (typeof(m)){"LP11000-S", max_speed,
943 case PCI_SUBSYSTEM_ID_LP11002S:
944 m = (typeof(m)){"LP11002-S", max_speed,
947 case PCI_SUBSYSTEM_ID_LPE11000S:
948 m = (typeof(m)){"LPe11000-S", max_speed,
951 case PCI_SUBSYSTEM_ID_LPE11002S:
952 m = (typeof(m)){"LPe11002-S", max_speed,
955 case PCI_SUBSYSTEM_ID_LPE11010S:
956 m = (typeof(m)){"LPe11010-S", max_speed,
960 m = (typeof(m)){ NULL };
965 m = (typeof(m)){ NULL };
969 if (mdp && mdp[0] == '\0')
970 snprintf(mdp, 79,"%s", m.name);
971 if (descp && descp[0] == '\0')
973 "Emulex %s %dGb %s%s Fibre Channel Adapter",
974 m.name, m.max_speed, m.ports, m.bus);
977 /**************************************************/
978 /* lpfc_post_buffer */
980 /* This routine will post count buffers to the */
981 /* ring with the QUE_RING_BUF_CN command. This */
982 /* allows 3 buffers / command to be posted. */
983 /* Returns the number of buffers NOT posted. */
984 /**************************************************/
986 lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
990 struct lpfc_iocbq *iocb;
991 struct lpfc_dmabuf *mp1, *mp2;
993 cnt += pring->missbufcnt;
995 /* While there are buffers to post */
997 /* Allocate buffer for command iocb */
998 spin_lock_irq(phba->host->host_lock);
999 iocb = lpfc_sli_get_iocbq(phba);
1000 spin_unlock_irq(phba->host->host_lock);
1002 pring->missbufcnt = cnt;
1007 /* 2 buffers can be posted per command */
1008 /* Allocate buffer to post */
1009 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1011 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1013 if (mp1 == 0 || mp1->virt == 0) {
1015 spin_lock_irq(phba->host->host_lock);
1016 lpfc_sli_release_iocbq(phba, iocb);
1017 spin_unlock_irq(phba->host->host_lock);
1018 pring->missbufcnt = cnt;
1022 INIT_LIST_HEAD(&mp1->list);
1023 /* Allocate buffer to post */
1025 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1027 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1029 if (mp2 == 0 || mp2->virt == 0) {
1031 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1033 spin_lock_irq(phba->host->host_lock);
1034 lpfc_sli_release_iocbq(phba, iocb);
1035 spin_unlock_irq(phba->host->host_lock);
1036 pring->missbufcnt = cnt;
1040 INIT_LIST_HEAD(&mp2->list);
1045 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1046 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1047 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1048 icmd->ulpBdeCount = 1;
1051 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1052 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1053 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1055 icmd->ulpBdeCount = 2;
1058 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1061 spin_lock_irq(phba->host->host_lock);
1062 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1063 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1067 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1071 lpfc_sli_release_iocbq(phba, iocb);
1072 pring->missbufcnt = cnt;
1073 spin_unlock_irq(phba->host->host_lock);
1076 spin_unlock_irq(phba->host->host_lock);
1077 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1079 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1082 pring->missbufcnt = 0;
1086 /************************************************************************/
1088 /* lpfc_post_rcv_buf */
1089 /* This routine post initial rcv buffers to the configured rings */
1091 /************************************************************************/
1093 lpfc_post_rcv_buf(struct lpfc_hba * phba)
1095 struct lpfc_sli *psli = &phba->sli;
1097 /* Ring 0, ELS / CT buffers */
1098 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1099 /* Ring 2 - FCP no buffers needed */
1104 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1106 /************************************************************************/
1110 /************************************************************************/
1112 lpfc_sha_init(uint32_t * HashResultPointer)
1114 HashResultPointer[0] = 0x67452301;
1115 HashResultPointer[1] = 0xEFCDAB89;
1116 HashResultPointer[2] = 0x98BADCFE;
1117 HashResultPointer[3] = 0x10325476;
1118 HashResultPointer[4] = 0xC3D2E1F0;
1121 /************************************************************************/
1123 /* lpfc_sha_iterate */
1125 /************************************************************************/
1127 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1131 uint32_t A, B, C, D, E;
1134 HashWorkingPointer[t] =
1136 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1138 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1139 } while (++t <= 79);
1141 A = HashResultPointer[0];
1142 B = HashResultPointer[1];
1143 C = HashResultPointer[2];
1144 D = HashResultPointer[3];
1145 E = HashResultPointer[4];
1149 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1150 } else if (t < 40) {
1151 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1152 } else if (t < 60) {
1153 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1155 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1157 TEMP += S(5, A) + E + HashWorkingPointer[t];
1163 } while (++t <= 79);
1165 HashResultPointer[0] += A;
1166 HashResultPointer[1] += B;
1167 HashResultPointer[2] += C;
1168 HashResultPointer[3] += D;
1169 HashResultPointer[4] += E;
1173 /************************************************************************/
1175 /* lpfc_challenge_key */
1177 /************************************************************************/
1179 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1181 *HashWorking = (*RandomChallenge ^ *HashWorking);
1184 /************************************************************************/
1188 /************************************************************************/
1190 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1193 uint32_t *HashWorking;
1194 uint32_t *pwwnn = phba->wwnn;
1196 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1200 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1201 HashWorking[0] = HashWorking[78] = *pwwnn++;
1202 HashWorking[1] = HashWorking[79] = *pwwnn;
1204 for (t = 0; t < 7; t++)
1205 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1207 lpfc_sha_init(hbainit);
1208 lpfc_sha_iterate(hbainit, HashWorking);
1213 lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
1215 struct lpfc_nodelist *ndlp, *next_ndlp;
1217 /* clean up phba - lpfc specific */
1218 lpfc_can_disctmo(phba);
1219 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
1221 lpfc_nlp_remove(phba, ndlp);
1224 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1226 lpfc_nlp_remove(phba, ndlp);
1229 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
1231 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1234 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1236 lpfc_nlp_remove(phba, ndlp);
1239 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1241 lpfc_nlp_remove(phba, ndlp);
1244 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
1246 lpfc_nlp_remove(phba, ndlp);
1249 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1251 lpfc_nlp_remove(phba, ndlp);
1254 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1256 lpfc_nlp_remove(phba, ndlp);
1259 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1260 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1261 INIT_LIST_HEAD(&phba->fc_unused_list);
1262 INIT_LIST_HEAD(&phba->fc_plogi_list);
1263 INIT_LIST_HEAD(&phba->fc_adisc_list);
1264 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1265 INIT_LIST_HEAD(&phba->fc_prli_list);
1266 INIT_LIST_HEAD(&phba->fc_npr_list);
1268 phba->fc_map_cnt = 0;
1269 phba->fc_unmap_cnt = 0;
1270 phba->fc_plogi_cnt = 0;
1271 phba->fc_adisc_cnt = 0;
1272 phba->fc_reglogin_cnt = 0;
1273 phba->fc_prli_cnt = 0;
1274 phba->fc_npr_cnt = 0;
1275 phba->fc_unused_cnt= 0;
1280 lpfc_establish_link_tmo(unsigned long ptr)
1282 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1283 unsigned long iflag;
1286 /* Re-establishing Link, timer expired */
1287 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1288 "%d:1300 Re-establishing Link, timer expired "
1290 phba->brd_no, phba->fc_flag, phba->hba_state);
1291 spin_lock_irqsave(phba->host->host_lock, iflag);
1292 phba->fc_flag &= ~FC_ESTABLISH_LINK;
1293 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1297 lpfc_stop_timer(struct lpfc_hba * phba)
1299 struct lpfc_sli *psli = &phba->sli;
1301 /* Instead of a timer, this has been converted to a
1302 * deferred procedding list.
1304 while (!list_empty(&phba->freebufList)) {
1306 struct lpfc_dmabuf *mp = NULL;
1308 list_remove_head((&phba->freebufList), mp,
1309 struct lpfc_dmabuf, list);
1311 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1316 del_timer_sync(&phba->fcp_poll_timer);
1317 del_timer_sync(&phba->fc_estabtmo);
1318 del_timer_sync(&phba->fc_disctmo);
1319 del_timer_sync(&phba->fc_fdmitmo);
1320 del_timer_sync(&phba->els_tmofunc);
1322 del_timer_sync(&psli->mbox_tmo);
1327 lpfc_online(struct lpfc_hba * phba)
1332 if (!(phba->fc_flag & FC_OFFLINE_MODE))
1335 lpfc_printf_log(phba,
1338 "%d:0458 Bring Adapter online\n",
1341 if (!lpfc_sli_queue_setup(phba))
1344 if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */
1347 spin_lock_irq(phba->host->host_lock);
1348 phba->fc_flag &= ~FC_OFFLINE_MODE;
1349 spin_unlock_irq(phba->host->host_lock);
1355 lpfc_offline(struct lpfc_hba * phba)
1357 struct lpfc_sli_ring *pring;
1358 struct lpfc_sli *psli;
1359 unsigned long iflag;
1366 if (phba->fc_flag & FC_OFFLINE_MODE)
1371 lpfc_linkdown(phba);
1372 lpfc_sli_flush_mbox_queue(phba);
1374 for (i = 0; i < psli->num_rings; i++) {
1375 pring = &psli->ring[i];
1376 /* The linkdown event takes 30 seconds to timeout. */
1377 while (pring->txcmplq_cnt) {
1380 lpfc_printf_log(phba,
1381 KERN_WARNING, LOG_INIT,
1382 "%d:0466 Outstanding IO when "
1383 "bringing Adapter offline\n",
1391 /* stop all timers associated with this hba */
1392 lpfc_stop_timer(phba);
1393 phba->work_hba_events = 0;
1396 lpfc_printf_log(phba,
1399 "%d:0460 Bring Adapter offline\n",
1402 /* Bring down the SLI Layer and cleanup. The HBA is offline
1404 lpfc_sli_hba_down(phba);
1405 lpfc_cleanup(phba, 1);
1406 spin_lock_irqsave(phba->host->host_lock, iflag);
1407 phba->fc_flag |= FC_OFFLINE_MODE;
1408 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1412 /******************************************************************************
1413 * Function name: lpfc_scsi_free
1415 * Description: Called from lpfc_pci_remove_one free internal driver resources
1417 ******************************************************************************/
1419 lpfc_scsi_free(struct lpfc_hba * phba)
1421 struct lpfc_scsi_buf *sb, *sb_next;
1422 struct lpfc_iocbq *io, *io_next;
1424 spin_lock_irq(phba->host->host_lock);
1425 /* Release all the lpfc_scsi_bufs maintained by this host. */
1426 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1427 list_del(&sb->list);
1428 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1431 phba->total_scsi_bufs--;
1434 /* Release all the lpfc_iocbq entries maintained by this host. */
1435 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1436 list_del(&io->list);
1438 phba->total_iocbq_bufs--;
1441 spin_unlock_irq(phba->host->host_lock);
1447 static int __devinit
1448 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1450 struct Scsi_Host *host;
1451 struct lpfc_hba *phba;
1452 struct lpfc_sli *psli;
1453 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1454 unsigned long bar0map_len, bar2map_len;
1455 int error = -ENODEV, retval;
1459 if (pci_enable_device(pdev))
1461 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1462 goto out_disable_device;
1464 host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
1466 goto out_release_regions;
1468 phba = (struct lpfc_hba*)host->hostdata;
1469 memset(phba, 0, sizeof (struct lpfc_hba));
1472 phba->fc_flag |= FC_LOADING;
1473 phba->pcidev = pdev;
1475 /* Assign an unused board number */
1476 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1479 error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
1483 host->unique_id = phba->brd_no;
1484 INIT_LIST_HEAD(&phba->ctrspbuflist);
1485 INIT_LIST_HEAD(&phba->rnidrspbuflist);
1486 INIT_LIST_HEAD(&phba->freebufList);
1488 /* Initialize timers used by driver */
1489 init_timer(&phba->fc_estabtmo);
1490 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1491 phba->fc_estabtmo.data = (unsigned long)phba;
1492 init_timer(&phba->fc_disctmo);
1493 phba->fc_disctmo.function = lpfc_disc_timeout;
1494 phba->fc_disctmo.data = (unsigned long)phba;
1496 init_timer(&phba->fc_fdmitmo);
1497 phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
1498 phba->fc_fdmitmo.data = (unsigned long)phba;
1499 init_timer(&phba->els_tmofunc);
1500 phba->els_tmofunc.function = lpfc_els_timeout;
1501 phba->els_tmofunc.data = (unsigned long)phba;
1503 init_timer(&psli->mbox_tmo);
1504 psli->mbox_tmo.function = lpfc_mbox_timeout;
1505 psli->mbox_tmo.data = (unsigned long)phba;
1507 init_timer(&phba->fcp_poll_timer);
1508 phba->fcp_poll_timer.function = lpfc_poll_timeout;
1509 phba->fcp_poll_timer.data = (unsigned long)phba;
1512 * Get all the module params for configuring this host and then
1513 * establish the host parameters.
1515 lpfc_get_cfgparam(phba);
1517 host->max_id = LPFC_MAX_TARGET;
1518 host->max_lun = phba->cfg_max_luns;
1521 /* Initialize all internally managed lists. */
1522 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1523 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1524 INIT_LIST_HEAD(&phba->fc_unused_list);
1525 INIT_LIST_HEAD(&phba->fc_plogi_list);
1526 INIT_LIST_HEAD(&phba->fc_adisc_list);
1527 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1528 INIT_LIST_HEAD(&phba->fc_prli_list);
1529 INIT_LIST_HEAD(&phba->fc_npr_list);
1532 pci_set_master(pdev);
1533 retval = pci_set_mwi(pdev);
1535 dev_printk(KERN_WARNING, &pdev->dev,
1536 "Warning: pci_set_mwi returned %d\n", retval);
1538 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1539 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1540 goto out_idr_remove;
1543 * Get the bus address of Bar0 and Bar2 and the number of bytes
1544 * required by each mapping.
1546 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1547 bar0map_len = pci_resource_len(phba->pcidev, 0);
1549 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1550 bar2map_len = pci_resource_len(phba->pcidev, 2);
1552 /* Map HBA SLIM to a kernel virtual address. */
1553 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
1554 if (!phba->slim_memmap_p) {
1556 dev_printk(KERN_ERR, &pdev->dev,
1557 "ioremap failed for SLIM memory.\n");
1558 goto out_idr_remove;
1561 /* Map HBA Control Registers to a kernel virtual address. */
1562 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
1563 if (!phba->ctrl_regs_memmap_p) {
1565 dev_printk(KERN_ERR, &pdev->dev,
1566 "ioremap failed for HBA control registers.\n");
1567 goto out_iounmap_slim;
1570 /* Allocate memory for SLI-2 structures */
1571 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1572 &phba->slim2p_mapping, GFP_KERNEL);
1576 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
1578 /* Initialize the SLI Layer to run with lpfc HBAs. */
1579 lpfc_sli_setup(phba);
1580 lpfc_sli_queue_setup(phba);
1582 error = lpfc_mem_alloc(phba);
1586 /* Initialize and populate the iocb list per host. */
1587 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1588 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1589 iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1590 if (iocbq_entry == NULL) {
1591 printk(KERN_ERR "%s: only allocated %d iocbs of "
1592 "expected %d count. Unloading driver.\n",
1593 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1595 goto out_free_iocbq;
1598 memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
1599 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1601 kfree (iocbq_entry);
1602 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1603 "Unloading driver.\n",
1606 goto out_free_iocbq;
1608 spin_lock_irq(phba->host->host_lock);
1609 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1610 phba->total_iocbq_bufs++;
1611 spin_unlock_irq(phba->host->host_lock);
1614 /* Initialize HBA structure */
1615 phba->fc_edtov = FF_DEF_EDTOV;
1616 phba->fc_ratov = FF_DEF_RATOV;
1617 phba->fc_altov = FF_DEF_ALTOV;
1618 phba->fc_arbtov = FF_DEF_ARBTOV;
1620 INIT_LIST_HEAD(&phba->work_list);
1621 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1622 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1624 /* Startup the kernel thread for this host adapter. */
1625 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1626 "lpfc_worker_%d", phba->brd_no);
1627 if (IS_ERR(phba->worker_thread)) {
1628 error = PTR_ERR(phba->worker_thread);
1629 goto out_free_iocbq;
1633 * Set initial can_queue value since 0 is no longer supported and
1634 * scsi_add_host will fail. This will be adjusted later based on the
1635 * max xri value determined in hba setup.
1637 host->can_queue = phba->cfg_hba_queue_depth - 10;
1639 /* Tell the midlayer we support 16 byte commands */
1640 host->max_cmd_len = 16;
1642 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1643 spin_lock_init(&phba->scsi_buf_list_lock);
1644 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1646 host->transportt = lpfc_transport_template;
1647 pci_set_drvdata(pdev, host);
1648 error = scsi_add_host(host, &pdev->dev);
1650 goto out_kthread_stop;
1652 error = lpfc_alloc_sysfs_attr(phba);
1654 goto out_remove_host;
1656 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
1657 LPFC_DRIVER_NAME, phba);
1659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1660 "%d:0451 Enable interrupt handler failed\n",
1662 goto out_free_sysfs_attr;
1664 phba->MBslimaddr = phba->slim_memmap_p;
1665 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1666 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1667 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1668 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1670 error = lpfc_sli_hba_setup(phba);
1677 * hba setup may have changed the hba_queue_depth so we need to adjust
1678 * the value of can_queue.
1680 host->can_queue = phba->cfg_hba_queue_depth - 10;
1682 lpfc_discovery_wait(phba);
1684 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1685 spin_lock_irq(phba->host->host_lock);
1686 lpfc_poll_start_timer(phba);
1687 spin_unlock_irq(phba->host->host_lock);
1691 * set fixed host attributes
1692 * Must done after lpfc_sli_hba_setup()
1695 fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
1696 fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
1697 fc_host_supported_classes(host) = FC_COS_CLASS3;
1699 memset(fc_host_supported_fc4s(host), 0,
1700 sizeof(fc_host_supported_fc4s(host)));
1701 fc_host_supported_fc4s(host)[2] = 1;
1702 fc_host_supported_fc4s(host)[7] = 1;
1704 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
1706 fc_host_supported_speeds(host) = 0;
1707 if (phba->lmt & LMT_10Gb)
1708 fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
1709 if (phba->lmt & LMT_4Gb)
1710 fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
1711 if (phba->lmt & LMT_2Gb)
1712 fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
1713 if (phba->lmt & LMT_1Gb)
1714 fc_host_supported_speeds(host) |= FC_PORTSPEED_1GBIT;
1716 fc_host_maxframe_size(host) =
1717 ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1718 (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
1720 /* This value is also unchanging */
1721 memset(fc_host_active_fc4s(host), 0,
1722 sizeof(fc_host_active_fc4s(host)));
1723 fc_host_active_fc4s(host)[2] = 1;
1724 fc_host_active_fc4s(host)[7] = 1;
1726 spin_lock_irq(phba->host->host_lock);
1727 phba->fc_flag &= ~FC_LOADING;
1728 spin_unlock_irq(phba->host->host_lock);
1732 lpfc_stop_timer(phba);
1733 phba->work_hba_events = 0;
1734 free_irq(phba->pcidev->irq, phba);
1735 out_free_sysfs_attr:
1736 lpfc_free_sysfs_attr(phba);
1738 fc_remove_host(phba->host);
1739 scsi_remove_host(phba->host);
1741 kthread_stop(phba->worker_thread);
1743 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1744 &phba->lpfc_iocb_list, list) {
1745 spin_lock_irq(phba->host->host_lock);
1747 phba->total_iocbq_bufs--;
1748 spin_unlock_irq(phba->host->host_lock);
1750 lpfc_mem_free(phba);
1752 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1753 phba->slim2p_mapping);
1755 iounmap(phba->ctrl_regs_memmap_p);
1757 iounmap(phba->slim_memmap_p);
1759 idr_remove(&lpfc_hba_index, phba->brd_no);
1762 scsi_host_put(host);
1763 out_release_regions:
1764 pci_release_regions(pdev);
1766 pci_disable_device(pdev);
1768 pci_set_drvdata(pdev, NULL);
1772 static void __devexit
1773 lpfc_pci_remove_one(struct pci_dev *pdev)
1775 struct Scsi_Host *host = pci_get_drvdata(pdev);
1776 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1777 unsigned long iflag;
1779 lpfc_free_sysfs_attr(phba);
1781 spin_lock_irqsave(phba->host->host_lock, iflag);
1782 phba->fc_flag |= FC_UNLOADING;
1784 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1786 fc_remove_host(phba->host);
1787 scsi_remove_host(phba->host);
1789 kthread_stop(phba->worker_thread);
1792 * Bring down the SLI Layer. This step disable all interrupts,
1793 * clears the rings, discards all mailbox commands, and resets
1796 lpfc_sli_hba_down(phba);
1797 lpfc_sli_brdrestart(phba);
1799 /* Release the irq reservation */
1800 free_irq(phba->pcidev->irq, phba);
1802 lpfc_cleanup(phba, 0);
1803 lpfc_stop_timer(phba);
1804 phba->work_hba_events = 0;
1807 * Call scsi_free before mem_free since scsi bufs are released to their
1808 * corresponding pools here.
1810 lpfc_scsi_free(phba);
1811 lpfc_mem_free(phba);
1813 /* Free resources associated with SLI2 interface */
1814 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
1815 phba->slim2p, phba->slim2p_mapping);
1817 /* unmap adapter SLIM and Control Registers */
1818 iounmap(phba->ctrl_regs_memmap_p);
1819 iounmap(phba->slim_memmap_p);
1821 pci_release_regions(phba->pcidev);
1822 pci_disable_device(phba->pcidev);
1824 idr_remove(&lpfc_hba_index, phba->brd_no);
1825 scsi_host_put(phba->host);
1827 pci_set_drvdata(pdev, NULL);
1830 static struct pci_device_id lpfc_id_table[] = {
1831 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1832 PCI_ANY_ID, PCI_ANY_ID, },
1833 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
1834 PCI_ANY_ID, PCI_ANY_ID, },
1835 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
1836 PCI_ANY_ID, PCI_ANY_ID, },
1837 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
1838 PCI_ANY_ID, PCI_ANY_ID, },
1839 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
1840 PCI_ANY_ID, PCI_ANY_ID, },
1841 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
1842 PCI_ANY_ID, PCI_ANY_ID, },
1843 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
1844 PCI_ANY_ID, PCI_ANY_ID, },
1845 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
1846 PCI_ANY_ID, PCI_ANY_ID, },
1847 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
1848 PCI_ANY_ID, PCI_ANY_ID, },
1849 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
1850 PCI_ANY_ID, PCI_ANY_ID, },
1851 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
1852 PCI_ANY_ID, PCI_ANY_ID, },
1853 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
1854 PCI_ANY_ID, PCI_ANY_ID, },
1855 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
1856 PCI_ANY_ID, PCI_ANY_ID, },
1857 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
1858 PCI_ANY_ID, PCI_ANY_ID, },
1859 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
1860 PCI_ANY_ID, PCI_ANY_ID, },
1861 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
1862 PCI_ANY_ID, PCI_ANY_ID, },
1863 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
1864 PCI_ANY_ID, PCI_ANY_ID, },
1865 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
1866 PCI_ANY_ID, PCI_ANY_ID, },
1867 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
1868 PCI_ANY_ID, PCI_ANY_ID, },
1869 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
1870 PCI_ANY_ID, PCI_ANY_ID, },
1871 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
1872 PCI_ANY_ID, PCI_ANY_ID, },
1873 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
1874 PCI_ANY_ID, PCI_ANY_ID, },
1875 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
1876 PCI_ANY_ID, PCI_ANY_ID, },
1877 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
1878 PCI_ANY_ID, PCI_ANY_ID, },
1879 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
1880 PCI_ANY_ID, PCI_ANY_ID, },
1881 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
1882 PCI_ANY_ID, PCI_ANY_ID, },
1883 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
1884 PCI_ANY_ID, PCI_ANY_ID, },
1888 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1890 static struct pci_driver lpfc_driver = {
1891 .name = LPFC_DRIVER_NAME,
1892 .id_table = lpfc_id_table,
1893 .probe = lpfc_pci_probe_one,
1894 .remove = __devexit_p(lpfc_pci_remove_one),
1902 printk(LPFC_MODULE_DESC "\n");
1903 printk(LPFC_COPYRIGHT "\n");
1905 lpfc_transport_template =
1906 fc_attach_transport(&lpfc_transport_functions);
1907 if (!lpfc_transport_template)
1909 error = pci_register_driver(&lpfc_driver);
1911 fc_release_transport(lpfc_transport_template);
1919 pci_unregister_driver(&lpfc_driver);
1920 fc_release_transport(lpfc_transport_template);
1923 module_init(lpfc_init);
1924 module_exit(lpfc_exit);
1925 MODULE_LICENSE("GPL");
1926 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
1927 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
1928 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);