1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 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 *);
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";
75 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
77 phba->hba_state = LPFC_HBA_ERROR;
82 phba->hba_state = LPFC_INIT_MBX_CMDS;
84 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
85 uint32_t *ptext = (uint32_t *) licensed;
87 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
88 *ptext = cpu_to_be32(*ptext);
90 lpfc_read_nv(phba, pmb);
91 memset((char*)mb->un.varRDnvp.rsvd3, 0,
92 sizeof (mb->un.varRDnvp.rsvd3));
93 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
96 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
98 if (rc != MBX_SUCCESS) {
102 "%d:0324 Config Port initialization "
103 "error, mbxCmd x%x READ_NVPARM, "
106 mb->mbxCommand, mb->mbxStatus);
107 mempool_free(pmb, phba->mbox_mem_pool);
110 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
111 sizeof (mb->un.varRDnvp.nodename));
114 /* Setup and issue mailbox READ REV command */
115 lpfc_read_rev(phba, pmb);
116 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
117 if (rc != MBX_SUCCESS) {
118 lpfc_printf_log(phba,
121 "%d:0439 Adapter failed to init, mbxCmd x%x "
122 "READ_REV, mbxStatus x%x\n",
124 mb->mbxCommand, mb->mbxStatus);
125 mempool_free( pmb, phba->mbox_mem_pool);
129 /* The HBA's current state is provided by the ProgType and rr fields.
130 * Read and check the value of these fields before continuing to config
133 if (mb->un.varRdRev.rr == 0 || mb->un.varRdRev.un.b.ProgType != 2) {
136 lpfc_printf_log(phba,
139 "%d:0440 Adapter failed to init, mbxCmd x%x "
140 "READ_REV detected outdated firmware"
144 mempool_free(pmb, phba->mbox_mem_pool);
148 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
149 memcpy(vp->rev.sli1FwName,
150 (char*)mb->un.varRdRev.sli1FwName, 16);
151 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
152 memcpy(vp->rev.sli2FwName,
153 (char *)mb->un.varRdRev.sli2FwName, 16);
156 /* Save information as VPD data */
157 vp->rev.biuRev = mb->un.varRdRev.biuRev;
158 vp->rev.smRev = mb->un.varRdRev.smRev;
159 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
160 vp->rev.endecRev = mb->un.varRdRev.endecRev;
161 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
162 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
163 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
164 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
165 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
166 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
168 if (lpfc_is_LC_HBA(phba->pcidev->device))
169 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
170 sizeof (phba->RandomData));
172 /* Get the default values for Model Name and Description */
173 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
175 /* Get adapter VPD information */
176 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
179 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
181 goto out_free_context2;
184 lpfc_dump_mem(phba, pmb, offset);
185 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
187 if (rc != MBX_SUCCESS) {
188 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
189 "%d:0441 VPD not present on adapter, "
190 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
192 mb->mbxCommand, mb->mbxStatus);
193 kfree(lpfc_vpd_data);
194 lpfc_vpd_data = NULL;
198 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
199 mb->un.varDmp.word_cnt);
200 offset += mb->un.varDmp.word_cnt;
201 } while (mb->un.varDmp.word_cnt);
202 lpfc_parse_vpd(phba, lpfc_vpd_data);
204 kfree(lpfc_vpd_data);
206 kfree(pmb->context2);
208 mempool_free(pmb, phba->mbox_mem_pool);
212 /************************************************************************/
214 /* lpfc_config_port_post */
215 /* This routine will do LPFC initialization after the */
216 /* CONFIG_PORT mailbox command. This will be initialized */
217 /* as a SLI layer callback routine. */
218 /* This routine returns 0 on success. Any other return value */
219 /* indicates an error. */
221 /************************************************************************/
223 lpfc_config_port_post(struct lpfc_hba * phba)
227 struct lpfc_dmabuf *mp;
228 struct lpfc_sli *psli = &phba->sli;
229 uint32_t status, timeout;
232 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
234 phba->hba_state = LPFC_HBA_ERROR;
239 lpfc_config_link(phba, pmb);
240 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
241 if (rc != MBX_SUCCESS) {
242 lpfc_printf_log(phba,
245 "%d:0447 Adapter failed init, mbxCmd x%x "
246 "CONFIG_LINK mbxStatus x%x\n",
248 mb->mbxCommand, mb->mbxStatus);
249 phba->hba_state = LPFC_HBA_ERROR;
250 mempool_free( pmb, phba->mbox_mem_pool);
254 /* Get login parameters for NID. */
255 lpfc_read_sparam(phba, pmb);
256 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
257 lpfc_printf_log(phba,
260 "%d:0448 Adapter failed init, mbxCmd x%x "
261 "READ_SPARM mbxStatus x%x\n",
263 mb->mbxCommand, mb->mbxStatus);
264 phba->hba_state = LPFC_HBA_ERROR;
265 mp = (struct lpfc_dmabuf *) pmb->context1;
266 mempool_free( pmb, phba->mbox_mem_pool);
267 lpfc_mbuf_free(phba, mp->virt, mp->phys);
272 mp = (struct lpfc_dmabuf *) pmb->context1;
274 memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
275 lpfc_mbuf_free(phba, mp->virt, mp->phys);
277 pmb->context1 = NULL;
279 memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
280 sizeof (struct lpfc_name));
281 memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
282 sizeof (struct lpfc_name));
283 /* If no serial number in VPD data, use low 6 bytes of WWNN */
284 /* This should be consolidated into parse_vpd ? - mr */
285 if (phba->SerialNumber[0] == 0) {
288 outptr = &phba->fc_nodename.u.s.IEEE[0];
289 for (i = 0; i < 12; i++) {
291 j = ((status & 0xf0) >> 4);
293 phba->SerialNumber[i] =
294 (char)((uint8_t) 0x30 + (uint8_t) j);
296 phba->SerialNumber[i] =
297 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
301 phba->SerialNumber[i] =
302 (char)((uint8_t) 0x30 + (uint8_t) j);
304 phba->SerialNumber[i] =
305 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
309 /* This should turn on DELAYED ABTS for ELS timeouts */
310 lpfc_set_slim(phba, pmb, 0x052198, 0x1);
311 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
312 phba->hba_state = LPFC_HBA_ERROR;
313 mempool_free( pmb, phba->mbox_mem_pool);
318 lpfc_read_config(phba, pmb);
319 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
320 lpfc_printf_log(phba,
323 "%d:0453 Adapter failed to init, mbxCmd x%x "
324 "READ_CONFIG, mbxStatus x%x\n",
326 mb->mbxCommand, mb->mbxStatus);
327 phba->hba_state = LPFC_HBA_ERROR;
328 mempool_free( pmb, phba->mbox_mem_pool);
332 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
333 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
334 phba->cfg_hba_queue_depth =
335 mb->un.varRdConfig.max_xri + 1;
337 phba->lmt = mb->un.varRdConfig.lmt;
338 /* HBA is not 4GB capable, or HBA is not 2GB capable,
339 don't let link speed ask for it */
340 if ((((phba->lmt & LMT_4250_10bit) != LMT_4250_10bit) &&
341 (phba->cfg_link_speed > LINK_SPEED_2G)) ||
342 (((phba->lmt & LMT_2125_10bit) != LMT_2125_10bit) &&
343 (phba->cfg_link_speed > LINK_SPEED_1G))) {
344 /* Reset link speed to auto. 1G/2GB HBA cfg'd for 4G */
345 lpfc_printf_log(phba,
348 "%d:1302 Invalid speed for this board: "
349 "Reset link speed to auto: x%x\n",
351 phba->cfg_link_speed);
352 phba->cfg_link_speed = LINK_SPEED_AUTO;
355 phba->hba_state = LPFC_LINK_DOWN;
357 /* Only process IOCBs on ring 0 till hba_state is READY */
358 if (psli->ring[psli->ip_ring].cmdringaddr)
359 psli->ring[psli->ip_ring].flag |= LPFC_STOP_IOCB_EVENT;
360 if (psli->ring[psli->fcp_ring].cmdringaddr)
361 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
362 if (psli->ring[psli->next_ring].cmdringaddr)
363 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
365 /* Post receive buffers for desired rings */
366 lpfc_post_rcv_buf(phba);
368 /* Enable appropriate host interrupts */
369 spin_lock_irq(phba->host->host_lock);
370 status = readl(phba->HCregaddr);
371 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
372 if (psli->num_rings > 0)
373 status |= HC_R0INT_ENA;
374 if (psli->num_rings > 1)
375 status |= HC_R1INT_ENA;
376 if (psli->num_rings > 2)
377 status |= HC_R2INT_ENA;
378 if (psli->num_rings > 3)
379 status |= HC_R3INT_ENA;
381 writel(status, phba->HCregaddr);
382 readl(phba->HCregaddr); /* flush */
383 spin_unlock_irq(phba->host->host_lock);
386 * Setup the ring 0 (els) timeout handler
388 timeout = phba->fc_ratov << 1;
389 phba->els_tmofunc.expires = jiffies + HZ * timeout;
390 add_timer(&phba->els_tmofunc);
392 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
393 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
394 if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
395 lpfc_printf_log(phba,
398 "%d:0454 Adapter failed to init, mbxCmd x%x "
399 "INIT_LINK, mbxStatus x%x\n",
401 mb->mbxCommand, mb->mbxStatus);
403 /* Clear all interrupt enable conditions */
404 writel(0, phba->HCregaddr);
405 readl(phba->HCregaddr); /* flush */
406 /* Clear all pending interrupts */
407 writel(0xffffffff, phba->HAregaddr);
408 readl(phba->HAregaddr); /* flush */
410 phba->hba_state = LPFC_HBA_ERROR;
411 mempool_free(pmb, phba->mbox_mem_pool);
414 /* MBOX buffer will be freed in mbox compl */
417 while ((phba->hba_state != LPFC_HBA_READY) ||
418 (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
419 ((phba->fc_map_cnt == 0) && (i<2)) ||
420 (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
421 /* Check every second for 30 retries. */
426 if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
427 /* The link is down. Set linkdown timeout */
431 /* Delay for 1 second to give discovery time to complete. */
436 /* Since num_disc_nodes keys off of PLOGI, delay a bit to let
437 * any potential PRLIs to flush thru the SLI sub-system.
444 /************************************************************************/
446 /* lpfc_hba_down_prep */
447 /* This routine will do LPFC uninitialization before the */
448 /* HBA is reset when bringing down the SLI Layer. This will be */
449 /* initialized as a SLI layer callback routine. */
450 /* This routine returns 0 on success. Any other return value */
451 /* indicates an error. */
453 /************************************************************************/
455 lpfc_hba_down_prep(struct lpfc_hba * phba)
457 /* Disable interrupts */
458 writel(0, phba->HCregaddr);
459 readl(phba->HCregaddr); /* flush */
461 /* Cleanup potential discovery resources */
462 lpfc_els_flush_rscn(phba);
463 lpfc_els_flush_cmd(phba);
464 lpfc_disc_flush_list(phba);
469 /************************************************************************/
471 /* lpfc_handle_eratt */
472 /* This routine will handle processing a Host Attention */
473 /* Error Status event. This will be initialized */
474 /* as a SLI layer callback routine. */
476 /************************************************************************/
478 lpfc_handle_eratt(struct lpfc_hba * phba)
480 struct lpfc_sli *psli = &phba->sli;
481 struct lpfc_sli_ring *pring;
484 * If a reset is sent to the HBA restore PCI configuration registers.
486 if ( phba->hba_state == LPFC_INIT_START ) {
488 readl(phba->HCregaddr); /* flush */
489 writel(0, phba->HCregaddr);
490 readl(phba->HCregaddr); /* flush */
492 /* Restore PCI cmd register */
493 pci_write_config_word(phba->pcidev,
494 PCI_COMMAND, phba->pci_cfg_value);
497 if (phba->work_hs & HS_FFER6) {
498 /* Re-establishing Link */
499 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
500 "%d:1301 Re-establishing Link "
501 "Data: x%x x%x x%x\n",
502 phba->brd_no, phba->work_hs,
503 phba->work_status[0], phba->work_status[1]);
504 spin_lock_irq(phba->host->host_lock);
505 phba->fc_flag |= FC_ESTABLISH_LINK;
506 spin_unlock_irq(phba->host->host_lock);
509 * Firmware stops when it triggled erratt with HS_FFER6.
510 * That could cause the I/Os dropped by the firmware.
511 * Error iocb (I/O) on txcmplq and let the SCSI layer
512 * retry it after re-establishing link.
514 pring = &psli->ring[psli->fcp_ring];
515 lpfc_sli_abort_iocb_ring(phba, pring);
519 * There was a firmware error. Take the hba offline and then
520 * attempt to restart it.
523 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
524 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
528 /* The if clause above forces this code path when the status
529 * failure is a value other than FFER6. Do not call the offline
530 * twice. This is the adapter hardware error path.
532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
533 "%d:0457 Adapter Hardware Error "
534 "Data: x%x x%x x%x\n",
535 phba->brd_no, phba->work_hs,
536 phba->work_status[0], phba->work_status[1]);
543 /************************************************************************/
545 /* lpfc_handle_latt */
546 /* This routine will handle processing a Host Attention */
547 /* Link Status event. This will be initialized */
548 /* as a SLI layer callback routine. */
550 /************************************************************************/
552 lpfc_handle_latt(struct lpfc_hba * phba)
554 struct lpfc_sli *psli = &phba->sli;
556 volatile uint32_t control;
557 struct lpfc_dmabuf *mp;
560 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
562 goto lpfc_handle_latt_err_exit;
564 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
566 goto lpfc_handle_latt_free_pmb;
568 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
570 goto lpfc_handle_latt_free_mp;
575 psli->slistat.link_event++;
576 lpfc_read_la(phba, pmb, mp);
577 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
578 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
579 if (rc == MBX_NOT_FINISHED)
580 goto lpfc_handle_latt_free_mp;
582 /* Clear Link Attention in HA REG */
583 spin_lock_irq(phba->host->host_lock);
584 writel(HA_LATT, phba->HAregaddr);
585 readl(phba->HAregaddr); /* flush */
586 spin_unlock_irq(phba->host->host_lock);
590 lpfc_handle_latt_free_mp:
592 lpfc_handle_latt_free_pmb:
594 lpfc_handle_latt_err_exit:
595 /* Enable Link attention interrupts */
596 spin_lock_irq(phba->host->host_lock);
597 psli->sli_flag |= LPFC_PROCESS_LA;
598 control = readl(phba->HCregaddr);
599 control |= HC_LAINT_ENA;
600 writel(control, phba->HCregaddr);
601 readl(phba->HCregaddr); /* flush */
603 /* Clear Link Attention in HA REG */
604 writel(HA_LATT, phba->HAregaddr);
605 readl(phba->HAregaddr); /* flush */
606 spin_unlock_irq(phba->host->host_lock);
608 phba->hba_state = LPFC_HBA_ERROR;
610 /* The other case is an error from issue_mbox */
612 lpfc_printf_log(phba,
615 "%d:0300 READ_LA: no buffers\n",
621 /************************************************************************/
624 /* This routine will parse the VPD data */
626 /************************************************************************/
628 lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd)
630 uint8_t lenlo, lenhi;
640 lpfc_printf_log(phba,
643 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
645 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
648 switch (vpd[index]) {
655 i = ((((unsigned short)lenhi) << 8) + lenlo);
664 Length = ((((unsigned short)lenhi) << 8) + lenlo);
667 /* Look for Serial Number */
668 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
675 phba->SerialNumber[j++] = vpd[index++];
679 phba->SerialNumber[j] = 0;
682 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
683 phba->vpd_flag |= VPD_MODEL_DESC;
690 phba->ModelDesc[j++] = vpd[index++];
694 phba->ModelDesc[j] = 0;
697 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
698 phba->vpd_flag |= VPD_MODEL_NAME;
705 phba->ModelName[j++] = vpd[index++];
709 phba->ModelName[j] = 0;
712 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
713 phba->vpd_flag |= VPD_PROGRAM_TYPE;
720 phba->ProgramType[j++] = vpd[index++];
724 phba->ProgramType[j] = 0;
727 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
728 phba->vpd_flag |= VPD_PORT;
735 phba->Port[j++] = vpd[index++];
759 } while (!finished && (index < 108));
765 lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
772 pci_read_config_dword(phba->pcidev, PCI_VENDOR_ID, &id);
774 switch ((id >> 16) & 0xffff) {
775 case PCI_DEVICE_ID_FIREFLY:
776 strcpy(str, "LP6000 1");
778 case PCI_DEVICE_ID_SUPERFLY:
779 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
780 strcpy(str, "LP7000 1");
782 strcpy(str, "LP7000E 1");
784 case PCI_DEVICE_ID_DRAGONFLY:
785 strcpy(str, "LP8000 1");
787 case PCI_DEVICE_ID_CENTAUR:
788 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
789 strcpy(str, "LP9002 2");
791 strcpy(str, "LP9000 1");
793 case PCI_DEVICE_ID_RFLY:
794 strcpy(str, "LP952 2");
796 case PCI_DEVICE_ID_PEGASUS:
797 strcpy(str, "LP9802 2");
799 case PCI_DEVICE_ID_THOR:
800 strcpy(str, "LP10000 2");
802 case PCI_DEVICE_ID_VIPER:
803 strcpy(str, "LPX1000 10");
805 case PCI_DEVICE_ID_PFLY:
806 strcpy(str, "LP982 2");
808 case PCI_DEVICE_ID_TFLY:
809 strcpy(str, "LP1050 2");
811 case PCI_DEVICE_ID_HELIOS:
812 strcpy(str, "LP11000 4");
814 case PCI_DEVICE_ID_BMID:
815 strcpy(str, "LP1150 4");
817 case PCI_DEVICE_ID_BSMB:
818 strcpy(str, "LP111 4");
820 case PCI_DEVICE_ID_ZEPHYR:
821 strcpy(str, "LP11000e 4");
823 case PCI_DEVICE_ID_ZMID:
824 strcpy(str, "LP1150e 4");
826 case PCI_DEVICE_ID_ZSMB:
827 strcpy(str, "LP111e 4");
829 case PCI_DEVICE_ID_LP101:
830 strcpy(str, "LP101 2");
832 case PCI_DEVICE_ID_LP10000S:
833 strcpy(str, "LP10000-S 2");
840 sscanf(str, "%s", mdp);
842 sprintf(descp, "Emulex LightPulse %s Gigabit PCI Fibre "
843 "Channel Adapter", str);
846 /**************************************************/
847 /* lpfc_post_buffer */
849 /* This routine will post count buffers to the */
850 /* ring with the QUE_RING_BUF_CN command. This */
851 /* allows 3 buffers / command to be posted. */
852 /* Returns the number of buffers NOT posted. */
853 /**************************************************/
855 lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
859 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
860 struct lpfc_iocbq *iocb = NULL;
861 struct lpfc_dmabuf *mp1, *mp2;
863 cnt += pring->missbufcnt;
865 /* While there are buffers to post */
867 /* Allocate buffer for command iocb */
868 spin_lock_irq(phba->host->host_lock);
869 list_remove_head(lpfc_iocb_list, iocb, struct lpfc_iocbq, list);
870 spin_unlock_irq(phba->host->host_lock);
872 pring->missbufcnt = cnt;
875 memset(iocb, 0, sizeof (struct lpfc_iocbq));
878 /* 2 buffers can be posted per command */
879 /* Allocate buffer to post */
880 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
882 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
884 if (mp1 == 0 || mp1->virt == 0) {
887 spin_lock_irq(phba->host->host_lock);
888 list_add_tail(&iocb->list, lpfc_iocb_list);
889 spin_unlock_irq(phba->host->host_lock);
890 pring->missbufcnt = cnt;
894 INIT_LIST_HEAD(&mp1->list);
895 /* Allocate buffer to post */
897 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
899 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
901 if (mp2 == 0 || mp2->virt == 0) {
904 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
906 spin_lock_irq(phba->host->host_lock);
907 list_add_tail(&iocb->list, lpfc_iocb_list);
908 spin_unlock_irq(phba->host->host_lock);
909 pring->missbufcnt = cnt;
913 INIT_LIST_HEAD(&mp2->list);
918 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
919 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
920 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
921 icmd->ulpBdeCount = 1;
924 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
925 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
926 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
928 icmd->ulpBdeCount = 2;
931 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
934 spin_lock_irq(phba->host->host_lock);
935 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
936 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
940 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
944 list_add_tail(&iocb->list, lpfc_iocb_list);
945 pring->missbufcnt = cnt;
946 spin_unlock_irq(phba->host->host_lock);
949 spin_unlock_irq(phba->host->host_lock);
950 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
952 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
955 pring->missbufcnt = 0;
959 /************************************************************************/
961 /* lpfc_post_rcv_buf */
962 /* This routine post initial rcv buffers to the configured rings */
964 /************************************************************************/
966 lpfc_post_rcv_buf(struct lpfc_hba * phba)
968 struct lpfc_sli *psli = &phba->sli;
970 /* Ring 0, ELS / CT buffers */
971 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
972 /* Ring 2 - FCP no buffers needed */
977 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
979 /************************************************************************/
983 /************************************************************************/
985 lpfc_sha_init(uint32_t * HashResultPointer)
987 HashResultPointer[0] = 0x67452301;
988 HashResultPointer[1] = 0xEFCDAB89;
989 HashResultPointer[2] = 0x98BADCFE;
990 HashResultPointer[3] = 0x10325476;
991 HashResultPointer[4] = 0xC3D2E1F0;
994 /************************************************************************/
996 /* lpfc_sha_iterate */
998 /************************************************************************/
1000 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1004 uint32_t A, B, C, D, E;
1007 HashWorkingPointer[t] =
1009 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1011 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1012 } while (++t <= 79);
1014 A = HashResultPointer[0];
1015 B = HashResultPointer[1];
1016 C = HashResultPointer[2];
1017 D = HashResultPointer[3];
1018 E = HashResultPointer[4];
1022 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1023 } else if (t < 40) {
1024 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1025 } else if (t < 60) {
1026 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1028 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1030 TEMP += S(5, A) + E + HashWorkingPointer[t];
1036 } while (++t <= 79);
1038 HashResultPointer[0] += A;
1039 HashResultPointer[1] += B;
1040 HashResultPointer[2] += C;
1041 HashResultPointer[3] += D;
1042 HashResultPointer[4] += E;
1046 /************************************************************************/
1048 /* lpfc_challenge_key */
1050 /************************************************************************/
1052 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1054 *HashWorking = (*RandomChallenge ^ *HashWorking);
1057 /************************************************************************/
1061 /************************************************************************/
1063 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1066 uint32_t *HashWorking;
1067 uint32_t *pwwnn = phba->wwnn;
1069 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1073 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1074 HashWorking[0] = HashWorking[78] = *pwwnn++;
1075 HashWorking[1] = HashWorking[79] = *pwwnn;
1077 for (t = 0; t < 7; t++)
1078 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1080 lpfc_sha_init(hbainit);
1081 lpfc_sha_iterate(hbainit, HashWorking);
1086 lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
1088 struct lpfc_nodelist *ndlp, *next_ndlp;
1090 /* clean up phba - lpfc specific */
1091 lpfc_can_disctmo(phba);
1092 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
1094 lpfc_nlp_remove(phba, ndlp);
1097 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1099 lpfc_nlp_remove(phba, ndlp);
1102 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
1104 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1107 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1109 lpfc_nlp_remove(phba, ndlp);
1112 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1114 lpfc_nlp_remove(phba, ndlp);
1117 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
1119 lpfc_nlp_remove(phba, ndlp);
1122 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1124 lpfc_nlp_remove(phba, ndlp);
1127 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1129 lpfc_nlp_remove(phba, ndlp);
1132 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1133 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1134 INIT_LIST_HEAD(&phba->fc_unused_list);
1135 INIT_LIST_HEAD(&phba->fc_plogi_list);
1136 INIT_LIST_HEAD(&phba->fc_adisc_list);
1137 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1138 INIT_LIST_HEAD(&phba->fc_prli_list);
1139 INIT_LIST_HEAD(&phba->fc_npr_list);
1141 phba->fc_map_cnt = 0;
1142 phba->fc_unmap_cnt = 0;
1143 phba->fc_plogi_cnt = 0;
1144 phba->fc_adisc_cnt = 0;
1145 phba->fc_reglogin_cnt = 0;
1146 phba->fc_prli_cnt = 0;
1147 phba->fc_npr_cnt = 0;
1148 phba->fc_unused_cnt= 0;
1153 lpfc_establish_link_tmo(unsigned long ptr)
1155 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1156 unsigned long iflag;
1159 /* Re-establishing Link, timer expired */
1160 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1161 "%d:1300 Re-establishing Link, timer expired "
1163 phba->brd_no, phba->fc_flag, phba->hba_state);
1164 spin_lock_irqsave(phba->host->host_lock, iflag);
1165 phba->fc_flag &= ~FC_ESTABLISH_LINK;
1166 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1170 lpfc_stop_timer(struct lpfc_hba * phba)
1172 struct lpfc_sli *psli = &phba->sli;
1174 /* Instead of a timer, this has been converted to a
1175 * deferred procedding list.
1177 while (!list_empty(&phba->freebufList)) {
1179 struct lpfc_dmabuf *mp = NULL;
1181 list_remove_head((&phba->freebufList), mp,
1182 struct lpfc_dmabuf, list);
1184 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1189 del_timer_sync(&phba->fc_estabtmo);
1190 del_timer_sync(&phba->fc_disctmo);
1191 del_timer_sync(&phba->fc_fdmitmo);
1192 del_timer_sync(&phba->els_tmofunc);
1194 del_timer_sync(&psli->mbox_tmo);
1199 lpfc_online(struct lpfc_hba * phba)
1204 if (!(phba->fc_flag & FC_OFFLINE_MODE))
1207 lpfc_printf_log(phba,
1210 "%d:0458 Bring Adapter online\n",
1213 if (!lpfc_sli_queue_setup(phba))
1216 if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */
1219 spin_lock_irq(phba->host->host_lock);
1220 phba->fc_flag &= ~FC_OFFLINE_MODE;
1221 spin_unlock_irq(phba->host->host_lock);
1227 lpfc_offline(struct lpfc_hba * phba)
1229 struct lpfc_sli_ring *pring;
1230 struct lpfc_sli *psli;
1231 unsigned long iflag;
1237 if (phba->fc_flag & FC_OFFLINE_MODE)
1241 pring = &psli->ring[psli->fcp_ring];
1243 lpfc_linkdown(phba);
1245 /* The linkdown event takes 30 seconds to timeout. */
1246 while (pring->txcmplq_cnt) {
1252 /* stop all timers associated with this hba */
1253 lpfc_stop_timer(phba);
1254 phba->work_hba_events = 0;
1256 lpfc_printf_log(phba,
1259 "%d:0460 Bring Adapter offline\n",
1262 /* Bring down the SLI Layer and cleanup. The HBA is offline
1264 lpfc_sli_hba_down(phba);
1265 lpfc_cleanup(phba, 1);
1266 spin_lock_irqsave(phba->host->host_lock, iflag);
1267 phba->fc_flag |= FC_OFFLINE_MODE;
1268 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1272 /******************************************************************************
1273 * Function name: lpfc_scsi_free
1275 * Description: Called from lpfc_pci_remove_one free internal driver resources
1277 ******************************************************************************/
1279 lpfc_scsi_free(struct lpfc_hba * phba)
1281 struct lpfc_scsi_buf *sb, *sb_next;
1282 struct lpfc_iocbq *io, *io_next;
1284 spin_lock_irq(phba->host->host_lock);
1285 /* Release all the lpfc_scsi_bufs maintained by this host. */
1286 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1287 list_del(&sb->list);
1288 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1291 phba->total_scsi_bufs--;
1294 /* Release all the lpfc_iocbq entries maintained by this host. */
1295 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1296 list_del(&io->list);
1298 phba->total_iocbq_bufs--;
1301 spin_unlock_irq(phba->host->host_lock);
1307 static int __devinit
1308 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1310 struct Scsi_Host *host;
1311 struct lpfc_hba *phba;
1312 struct lpfc_sli *psli;
1313 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1314 unsigned long bar0map_len, bar2map_len;
1315 int error = -ENODEV, retval;
1318 if (pci_enable_device(pdev))
1320 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1321 goto out_disable_device;
1323 host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
1325 goto out_release_regions;
1327 phba = (struct lpfc_hba*)host->hostdata;
1328 memset(phba, 0, sizeof (struct lpfc_hba));
1331 phba->fc_flag |= FC_LOADING;
1332 phba->pcidev = pdev;
1334 /* Assign an unused board number */
1335 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1338 error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
1342 host->unique_id = phba->brd_no;
1344 INIT_LIST_HEAD(&phba->ctrspbuflist);
1345 INIT_LIST_HEAD(&phba->rnidrspbuflist);
1346 INIT_LIST_HEAD(&phba->freebufList);
1348 /* Initialize timers used by driver */
1349 init_timer(&phba->fc_estabtmo);
1350 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1351 phba->fc_estabtmo.data = (unsigned long)phba;
1352 init_timer(&phba->fc_disctmo);
1353 phba->fc_disctmo.function = lpfc_disc_timeout;
1354 phba->fc_disctmo.data = (unsigned long)phba;
1356 init_timer(&phba->fc_fdmitmo);
1357 phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
1358 phba->fc_fdmitmo.data = (unsigned long)phba;
1359 init_timer(&phba->els_tmofunc);
1360 phba->els_tmofunc.function = lpfc_els_timeout;
1361 phba->els_tmofunc.data = (unsigned long)phba;
1363 init_timer(&psli->mbox_tmo);
1364 psli->mbox_tmo.function = lpfc_mbox_timeout;
1365 psli->mbox_tmo.data = (unsigned long)phba;
1368 * Get all the module params for configuring this host and then
1369 * establish the host parameters.
1371 lpfc_get_cfgparam(phba);
1373 host->max_id = LPFC_MAX_TARGET;
1374 host->max_lun = phba->cfg_max_luns;
1377 /* Initialize all internally managed lists. */
1378 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1379 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1380 INIT_LIST_HEAD(&phba->fc_unused_list);
1381 INIT_LIST_HEAD(&phba->fc_plogi_list);
1382 INIT_LIST_HEAD(&phba->fc_adisc_list);
1383 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1384 INIT_LIST_HEAD(&phba->fc_prli_list);
1385 INIT_LIST_HEAD(&phba->fc_npr_list);
1388 pci_set_master(pdev);
1389 retval = pci_set_mwi(pdev);
1391 dev_printk(KERN_WARNING, &pdev->dev,
1392 "Warning: pci_set_mwi returned %d\n", retval);
1394 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1395 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1396 goto out_idr_remove;
1399 * Get the bus address of Bar0 and Bar2 and the number of bytes
1400 * required by each mapping.
1402 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1403 bar0map_len = pci_resource_len(phba->pcidev, 0);
1405 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1406 bar2map_len = pci_resource_len(phba->pcidev, 2);
1408 /* Map HBA SLIM and Control Registers to a kernel virtual address. */
1409 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
1410 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
1412 /* Allocate memory for SLI-2 structures */
1413 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1414 &phba->slim2p_mapping, GFP_KERNEL);
1419 /* Initialize the SLI Layer to run with lpfc HBAs. */
1420 lpfc_sli_setup(phba);
1421 lpfc_sli_queue_setup(phba);
1423 error = lpfc_mem_alloc(phba);
1427 /* Initialize and populate the iocb list per host. */
1428 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1429 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1430 iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1431 if (iocbq_entry == NULL) {
1432 printk(KERN_ERR "%s: only allocated %d iocbs of "
1433 "expected %d count. Unloading driver.\n",
1434 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1436 goto out_free_iocbq;
1439 memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
1440 spin_lock_irq(phba->host->host_lock);
1441 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1442 phba->total_iocbq_bufs++;
1443 spin_unlock_irq(phba->host->host_lock);
1446 /* Initialize HBA structure */
1447 phba->fc_edtov = FF_DEF_EDTOV;
1448 phba->fc_ratov = FF_DEF_RATOV;
1449 phba->fc_altov = FF_DEF_ALTOV;
1450 phba->fc_arbtov = FF_DEF_ARBTOV;
1452 INIT_LIST_HEAD(&phba->work_list);
1453 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1454 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1456 /* Startup the kernel thread for this host adapter. */
1457 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1458 "lpfc_worker_%d", phba->brd_no);
1459 if (IS_ERR(phba->worker_thread)) {
1460 error = PTR_ERR(phba->worker_thread);
1461 goto out_free_iocbq;
1464 /* We can rely on a queue depth attribute only after SLI HBA setup */
1465 host->can_queue = phba->cfg_hba_queue_depth - 10;
1467 /* Tell the midlayer we support 16 byte commands */
1468 host->max_cmd_len = 16;
1470 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1471 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1473 host->transportt = lpfc_transport_template;
1474 host->hostdata[0] = (unsigned long)phba;
1475 pci_set_drvdata(pdev, host);
1476 error = scsi_add_host(host, &pdev->dev);
1478 goto out_kthread_stop;
1480 error = lpfc_alloc_sysfs_attr(phba);
1482 goto out_kthread_stop;
1484 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, SA_SHIRQ,
1485 LPFC_DRIVER_NAME, phba);
1487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1488 "%d:0451 Enable interrupt handler failed\n",
1490 goto out_free_sysfs_attr;
1492 phba->MBslimaddr = phba->slim_memmap_p;
1493 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1494 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1495 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1496 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1498 error = lpfc_sli_hba_setup(phba);
1503 * set fixed host attributes
1504 * Must done after lpfc_sli_hba_setup()
1507 fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
1508 fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
1509 fc_host_supported_classes(host) = FC_COS_CLASS3;
1511 memset(fc_host_supported_fc4s(host), 0,
1512 sizeof(fc_host_supported_fc4s(host)));
1513 fc_host_supported_fc4s(host)[2] = 1;
1514 fc_host_supported_fc4s(host)[7] = 1;
1516 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
1518 fc_host_supported_speeds(host) = 0;
1519 switch (FC_JEDEC_ID(phba->vpd.rev.biuRev)) {
1520 case VIPER_JEDEC_ID:
1521 fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
1523 case HELIOS_JEDEC_ID:
1524 fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
1526 case CENTAUR_2G_JEDEC_ID:
1527 case PEGASUS_JEDEC_ID:
1529 fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
1532 fc_host_supported_speeds(host) = FC_PORTSPEED_1GBIT;
1535 fc_host_maxframe_size(host) =
1536 ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1537 (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
1539 /* This value is also unchanging */
1540 memset(fc_host_active_fc4s(host), 0,
1541 sizeof(fc_host_active_fc4s(host)));
1542 fc_host_active_fc4s(host)[2] = 1;
1543 fc_host_active_fc4s(host)[7] = 1;
1545 spin_lock_irq(phba->host->host_lock);
1546 phba->fc_flag &= ~FC_LOADING;
1547 spin_unlock_irq(phba->host->host_lock);
1551 lpfc_stop_timer(phba);
1552 phba->work_hba_events = 0;
1553 free_irq(phba->pcidev->irq, phba);
1554 out_free_sysfs_attr:
1555 lpfc_free_sysfs_attr(phba);
1557 kthread_stop(phba->worker_thread);
1559 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1560 &phba->lpfc_iocb_list, list) {
1561 spin_lock_irq(phba->host->host_lock);
1563 phba->total_iocbq_bufs--;
1564 spin_unlock_irq(phba->host->host_lock);
1566 lpfc_mem_free(phba);
1568 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1569 phba->slim2p_mapping);
1571 iounmap(phba->ctrl_regs_memmap_p);
1572 iounmap(phba->slim_memmap_p);
1574 idr_remove(&lpfc_hba_index, phba->brd_no);
1576 scsi_host_put(host);
1577 out_release_regions:
1578 pci_release_regions(pdev);
1580 pci_disable_device(pdev);
1585 static void __devexit
1586 lpfc_pci_remove_one(struct pci_dev *pdev)
1588 struct Scsi_Host *host = pci_get_drvdata(pdev);
1589 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata[0];
1590 unsigned long iflag;
1592 lpfc_free_sysfs_attr(phba);
1594 spin_lock_irqsave(phba->host->host_lock, iflag);
1595 phba->fc_flag |= FC_UNLOADING;
1597 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1599 fc_remove_host(phba->host);
1600 scsi_remove_host(phba->host);
1602 kthread_stop(phba->worker_thread);
1605 * Bring down the SLI Layer. This step disable all interrupts,
1606 * clears the rings, discards all mailbox commands, and resets
1609 lpfc_sli_hba_down(phba);
1611 /* Release the irq reservation */
1612 free_irq(phba->pcidev->irq, phba);
1614 lpfc_cleanup(phba, 0);
1615 lpfc_stop_timer(phba);
1616 phba->work_hba_events = 0;
1619 * Call scsi_free before mem_free since scsi bufs are released to their
1620 * corresponding pools here.
1622 lpfc_scsi_free(phba);
1623 lpfc_mem_free(phba);
1625 /* Free resources associated with SLI2 interface */
1626 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
1627 phba->slim2p, phba->slim2p_mapping);
1629 /* unmap adapter SLIM and Control Registers */
1630 iounmap(phba->ctrl_regs_memmap_p);
1631 iounmap(phba->slim_memmap_p);
1633 pci_release_regions(phba->pcidev);
1634 pci_disable_device(phba->pcidev);
1636 idr_remove(&lpfc_hba_index, phba->brd_no);
1637 scsi_host_put(phba->host);
1639 pci_set_drvdata(pdev, NULL);
1642 static struct pci_device_id lpfc_id_table[] = {
1643 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1644 PCI_ANY_ID, PCI_ANY_ID, },
1645 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
1646 PCI_ANY_ID, PCI_ANY_ID, },
1647 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
1648 PCI_ANY_ID, PCI_ANY_ID, },
1649 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
1650 PCI_ANY_ID, PCI_ANY_ID, },
1651 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
1652 PCI_ANY_ID, PCI_ANY_ID, },
1653 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
1654 PCI_ANY_ID, PCI_ANY_ID, },
1655 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
1656 PCI_ANY_ID, PCI_ANY_ID, },
1657 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
1658 PCI_ANY_ID, PCI_ANY_ID, },
1659 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
1660 PCI_ANY_ID, PCI_ANY_ID, },
1661 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
1662 PCI_ANY_ID, PCI_ANY_ID, },
1663 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
1664 PCI_ANY_ID, PCI_ANY_ID, },
1665 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
1666 PCI_ANY_ID, PCI_ANY_ID, },
1667 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
1668 PCI_ANY_ID, PCI_ANY_ID, },
1669 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
1670 PCI_ANY_ID, PCI_ANY_ID, },
1671 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
1672 PCI_ANY_ID, PCI_ANY_ID, },
1673 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
1674 PCI_ANY_ID, PCI_ANY_ID, },
1675 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
1676 PCI_ANY_ID, PCI_ANY_ID, },
1677 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
1678 PCI_ANY_ID, PCI_ANY_ID, },
1682 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1684 static struct pci_driver lpfc_driver = {
1685 .name = LPFC_DRIVER_NAME,
1686 .id_table = lpfc_id_table,
1687 .probe = lpfc_pci_probe_one,
1688 .remove = __devexit_p(lpfc_pci_remove_one),
1696 printk(LPFC_MODULE_DESC "\n");
1697 printk(LPFC_COPYRIGHT "\n");
1699 lpfc_transport_template =
1700 fc_attach_transport(&lpfc_transport_functions);
1701 if (!lpfc_transport_template)
1703 error = pci_register_driver(&lpfc_driver);
1705 fc_release_transport(lpfc_transport_template);
1713 pci_unregister_driver(&lpfc_driver);
1714 fc_release_transport(lpfc_transport_template);
1717 module_init(lpfc_init);
1718 module_exit(lpfc_exit);
1719 MODULE_LICENSE("GPL");
1720 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
1721 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
1722 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);