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>
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);
54 /************************************************************************/
56 /* lpfc_config_port_prep */
57 /* This routine will do LPFC initialization prior to the */
58 /* CONFIG_PORT mailbox command. This will be initialized */
59 /* as a SLI layer callback routine. */
60 /* This routine returns 0 on success or -ERESTART if it wants */
61 /* the SLI layer to reset the HBA and try again. Any */
62 /* other return value indicates an error. */
64 /************************************************************************/
66 lpfc_config_port_prep(struct lpfc_hba *phba)
68 lpfc_vpd_t *vp = &phba->vpd;
72 char *lpfc_vpd_data = NULL;
74 static char licensed[56] =
75 "key unlock for use with gnu public licensed code only\0";
76 static int init_key = 1;
78 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
80 phba->link_state = LPFC_HBA_ERROR;
85 phba->link_state = LPFC_INIT_MBX_CMDS;
87 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
89 uint32_t *ptext = (uint32_t *) licensed;
91 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
92 *ptext = cpu_to_be32(*ptext);
96 lpfc_read_nv(phba, pmb);
97 memset((char*)mb->un.varRDnvp.rsvd3, 0,
98 sizeof (mb->un.varRDnvp.rsvd3));
99 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
102 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
104 if (rc != MBX_SUCCESS) {
105 lpfc_printf_log(phba,
108 "%d:0324 Config Port initialization "
109 "error, mbxCmd x%x READ_NVPARM, "
112 mb->mbxCommand, mb->mbxStatus);
113 mempool_free(pmb, phba->mbox_mem_pool);
116 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
118 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
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,
129 "%d:0439 Adapter failed to init, mbxCmd x%x "
130 "READ_REV, mbxStatus x%x\n",
132 mb->mbxCommand, mb->mbxStatus);
133 mempool_free( pmb, phba->mbox_mem_pool);
138 * The value of rr must be 1 since the driver set the cv field to 1.
139 * This setting requires the FW to set all revision fields.
141 if (mb->un.varRdRev.rr == 0) {
143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
144 "%d:0440 Adapter failed to init, READ_REV has "
145 "missing revision information.\n",
147 mempool_free(pmb, phba->mbox_mem_pool);
151 /* Save information as VPD data */
153 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
154 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
155 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
156 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
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 adapter VPD information */
173 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
176 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
178 goto out_free_context2;
181 lpfc_dump_mem(phba, pmb, offset);
182 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
184 if (rc != MBX_SUCCESS) {
185 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
186 "%d:0441 VPD not present on adapter, "
187 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
189 mb->mbxCommand, mb->mbxStatus);
190 mb->un.varDmp.word_cnt = 0;
192 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
193 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
194 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
195 mb->un.varDmp.word_cnt);
196 offset += mb->un.varDmp.word_cnt;
197 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
198 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
200 kfree(lpfc_vpd_data);
202 kfree(pmb->context2);
204 mempool_free(pmb, phba->mbox_mem_pool);
208 /************************************************************************/
210 /* lpfc_config_port_post */
211 /* This routine will do LPFC initialization after the */
212 /* CONFIG_PORT mailbox command. This will be initialized */
213 /* as a SLI layer callback routine. */
214 /* This routine returns 0 on success. Any other return value */
215 /* indicates an error. */
217 /************************************************************************/
219 lpfc_config_port_post(struct lpfc_hba *phba)
221 struct lpfc_vport *vport = phba->pport;
224 struct lpfc_dmabuf *mp;
225 struct lpfc_sli *psli = &phba->sli;
226 uint32_t status, timeout;
230 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
232 phba->link_state = LPFC_HBA_ERROR;
237 /* Get login parameters for NID. */
238 lpfc_read_sparam(phba, pmb);
239 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
240 lpfc_printf_log(phba,
243 "%d:0448 Adapter failed init, mbxCmd x%x "
244 "READ_SPARM mbxStatus x%x\n",
246 mb->mbxCommand, mb->mbxStatus);
247 phba->link_state = LPFC_HBA_ERROR;
248 mp = (struct lpfc_dmabuf *) pmb->context1;
249 mempool_free( pmb, phba->mbox_mem_pool);
250 lpfc_mbuf_free(phba, mp->virt, mp->phys);
255 mp = (struct lpfc_dmabuf *) pmb->context1;
257 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
258 lpfc_mbuf_free(phba, mp->virt, mp->phys);
260 pmb->context1 = NULL;
262 if (phba->cfg_soft_wwnn)
263 u64_to_wwn(phba->cfg_soft_wwnn,
264 vport->fc_sparam.nodeName.u.wwn);
265 if (phba->cfg_soft_wwpn)
266 u64_to_wwn(phba->cfg_soft_wwpn,
267 vport->fc_sparam.portName.u.wwn);
268 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
269 sizeof (struct lpfc_name));
270 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
271 sizeof (struct lpfc_name));
272 /* If no serial number in VPD data, use low 6 bytes of WWNN */
273 /* This should be consolidated into parse_vpd ? - mr */
274 if (phba->SerialNumber[0] == 0) {
277 outptr = &vport->fc_nodename.u.s.IEEE[0];
278 for (i = 0; i < 12; i++) {
280 j = ((status & 0xf0) >> 4);
282 phba->SerialNumber[i] =
283 (char)((uint8_t) 0x30 + (uint8_t) j);
285 phba->SerialNumber[i] =
286 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
290 phba->SerialNumber[i] =
291 (char)((uint8_t) 0x30 + (uint8_t) j);
293 phba->SerialNumber[i] =
294 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
298 lpfc_read_config(phba, pmb);
299 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
300 lpfc_printf_log(phba,
303 "%d:0453 Adapter failed to init, mbxCmd x%x "
304 "READ_CONFIG, mbxStatus x%x\n",
306 mb->mbxCommand, mb->mbxStatus);
307 phba->link_state = LPFC_HBA_ERROR;
308 mempool_free( pmb, phba->mbox_mem_pool);
312 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
313 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
314 phba->cfg_hba_queue_depth =
315 mb->un.varRdConfig.max_xri + 1;
317 phba->lmt = mb->un.varRdConfig.lmt;
319 /* Get the default values for Model Name and Description */
320 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
322 if ((phba->cfg_link_speed > LINK_SPEED_10G)
323 || ((phba->cfg_link_speed == LINK_SPEED_1G)
324 && !(phba->lmt & LMT_1Gb))
325 || ((phba->cfg_link_speed == LINK_SPEED_2G)
326 && !(phba->lmt & LMT_2Gb))
327 || ((phba->cfg_link_speed == LINK_SPEED_4G)
328 && !(phba->lmt & LMT_4Gb))
329 || ((phba->cfg_link_speed == LINK_SPEED_8G)
330 && !(phba->lmt & LMT_8Gb))
331 || ((phba->cfg_link_speed == LINK_SPEED_10G)
332 && !(phba->lmt & LMT_10Gb))) {
333 /* Reset link speed to auto */
334 lpfc_printf_log(phba,
337 "%d:1302 Invalid speed for this board: "
338 "Reset link speed to auto: x%x\n",
340 phba->cfg_link_speed);
341 phba->cfg_link_speed = LINK_SPEED_AUTO;
344 phba->link_state = LPFC_LINK_DOWN;
346 /* Only process IOCBs on ring 0 till hba_state is READY */
347 if (psli->ring[psli->extra_ring].cmdringaddr)
348 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
349 if (psli->ring[psli->fcp_ring].cmdringaddr)
350 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
351 if (psli->ring[psli->next_ring].cmdringaddr)
352 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
354 /* Post receive buffers for desired rings */
355 lpfc_post_rcv_buf(phba);
357 /* Enable appropriate host interrupts */
358 spin_lock_irq(&phba->hbalock);
359 status = readl(phba->HCregaddr);
360 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
361 if (psli->num_rings > 0)
362 status |= HC_R0INT_ENA;
363 if (psli->num_rings > 1)
364 status |= HC_R1INT_ENA;
365 if (psli->num_rings > 2)
366 status |= HC_R2INT_ENA;
367 if (psli->num_rings > 3)
368 status |= HC_R3INT_ENA;
370 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
371 (phba->cfg_poll & DISABLE_FCP_RING_INT))
372 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
374 writel(status, phba->HCregaddr);
375 readl(phba->HCregaddr); /* flush */
376 spin_unlock_irq(&phba->hbalock);
379 * Setup the ring 0 (els) timeout handler
381 timeout = phba->fc_ratov << 1;
382 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
384 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
385 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
386 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
387 lpfc_set_loopback_flag(phba);
388 if (rc != MBX_SUCCESS) {
389 lpfc_printf_log(phba,
392 "%d:0454 Adapter failed to init, mbxCmd x%x "
393 "INIT_LINK, mbxStatus x%x\n",
395 mb->mbxCommand, mb->mbxStatus);
397 /* Clear all interrupt enable conditions */
398 writel(0, phba->HCregaddr);
399 readl(phba->HCregaddr); /* flush */
400 /* Clear all pending interrupts */
401 writel(0xffffffff, phba->HAregaddr);
402 readl(phba->HAregaddr); /* flush */
404 phba->link_state = LPFC_HBA_ERROR;
406 mempool_free(pmb, phba->mbox_mem_pool);
409 /* MBOX buffer will be freed in mbox compl */
414 /************************************************************************/
416 /* lpfc_hba_down_prep */
417 /* This routine will do LPFC uninitialization before the */
418 /* HBA is reset when bringing down the SLI Layer. This will be */
419 /* initialized as a SLI layer callback routine. */
420 /* This routine returns 0 on success. Any other return value */
421 /* indicates an error. */
423 /************************************************************************/
425 lpfc_hba_down_prep(struct lpfc_hba *phba)
427 struct lpfc_vport *vport = phba->pport;
429 /* Disable interrupts */
430 writel(0, phba->HCregaddr);
431 readl(phba->HCregaddr); /* flush */
433 /* Cleanup potential discovery resources */
434 lpfc_els_flush_rscn(vport);
435 lpfc_els_flush_cmd(vport);
436 lpfc_disc_flush_list(vport);
441 /************************************************************************/
443 /* lpfc_hba_down_post */
444 /* This routine will do uninitialization after the HBA is reset */
445 /* when bringing down the SLI Layer. */
446 /* This routine returns 0 on success. Any other return value */
447 /* indicates an error. */
449 /************************************************************************/
451 lpfc_hba_down_post(struct lpfc_hba *phba)
453 struct lpfc_sli *psli = &phba->sli;
454 struct lpfc_sli_ring *pring;
455 struct lpfc_dmabuf *mp, *next_mp;
458 /* Cleanup preposted buffers on the ELS ring */
459 pring = &psli->ring[LPFC_ELS_RING];
460 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
462 pring->postbufq_cnt--;
463 lpfc_mbuf_free(phba, mp->virt, mp->phys);
467 for (i = 0; i < psli->num_rings; i++) {
468 pring = &psli->ring[i];
469 lpfc_sli_abort_iocb_ring(phba, pring);
475 /************************************************************************/
477 /* lpfc_handle_eratt */
478 /* This routine will handle processing a Host Attention */
479 /* Error Status event. This will be initialized */
480 /* as a SLI layer callback routine. */
482 /************************************************************************/
484 lpfc_handle_eratt(struct lpfc_hba *phba)
486 struct lpfc_vport *vport = phba->pport;
487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
488 struct lpfc_sli *psli = &phba->sli;
489 struct lpfc_sli_ring *pring;
492 /* If the pci channel is offline, ignore possible errors,
493 * since we cannot communicate with the pci card anyway. */
494 if (pci_channel_offline(phba->pcidev))
497 if (phba->work_hs & HS_FFER6 ||
498 phba->work_hs & HS_FFER5) {
499 /* Re-establishing Link */
500 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
501 "%d:1301 Re-establishing Link "
502 "Data: x%x x%x x%x\n",
503 phba->brd_no, phba->work_hs,
504 phba->work_status[0], phba->work_status[1]);
505 spin_lock_irq(shost->host_lock);
506 vport->fc_flag |= FC_ESTABLISH_LINK;
507 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
508 spin_unlock_irq(shost->host_lock);
511 * Firmware stops when it triggled erratt with HS_FFER6.
512 * That could cause the I/Os dropped by the firmware.
513 * Error iocb (I/O) on txcmplq and let the SCSI layer
514 * retry it after re-establishing link.
516 pring = &psli->ring[psli->fcp_ring];
517 lpfc_sli_abort_iocb_ring(phba, pring);
521 * There was a firmware error. Take the hba offline and then
522 * attempt to restart it.
524 lpfc_offline_prep(phba);
526 lpfc_sli_brdrestart(phba);
527 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
528 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
529 lpfc_unblock_mgmt_io(phba);
532 lpfc_unblock_mgmt_io(phba);
534 /* The if clause above forces this code path when the status
535 * failure is a value other than FFER6. Do not call the offline
536 * twice. This is the adapter hardware error path.
538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
539 "%d:0457 Adapter Hardware Error "
540 "Data: x%x x%x x%x\n",
541 phba->brd_no, phba->work_hs,
542 phba->work_status[0], phba->work_status[1]);
544 event_data = FC_REG_DUMP_EVENT;
545 fc_host_post_vendor_event(shost, fc_get_event_number(),
546 sizeof(event_data), (char *) &event_data,
547 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
549 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
550 lpfc_offline_prep(phba);
552 lpfc_unblock_mgmt_io(phba);
553 phba->link_state = LPFC_HBA_ERROR;
554 lpfc_hba_down_post(phba);
558 /************************************************************************/
560 /* lpfc_handle_latt */
561 /* This routine will handle processing a Host Attention */
562 /* Link Status event. This will be initialized */
563 /* as a SLI layer callback routine. */
565 /************************************************************************/
567 lpfc_handle_latt(struct lpfc_hba *phba)
569 struct lpfc_vport *vport = phba->pport;
570 struct lpfc_sli *psli = &phba->sli;
572 volatile uint32_t control;
573 struct lpfc_dmabuf *mp;
576 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
578 goto lpfc_handle_latt_err_exit;
580 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
582 goto lpfc_handle_latt_free_pmb;
584 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
586 goto lpfc_handle_latt_free_mp;
590 /* Cleanup any outstanding ELS commands */
591 lpfc_els_flush_cmd(vport);
593 psli->slistat.link_event++;
594 lpfc_read_la(phba, pmb, mp);
595 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
597 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
598 if (rc == MBX_NOT_FINISHED)
599 goto lpfc_handle_latt_free_mbuf;
601 /* Clear Link Attention in HA REG */
602 spin_lock_irq(&phba->hbalock);
603 writel(HA_LATT, phba->HAregaddr);
604 readl(phba->HAregaddr); /* flush */
605 spin_unlock_irq(&phba->hbalock);
609 lpfc_handle_latt_free_mbuf:
610 lpfc_mbuf_free(phba, mp->virt, mp->phys);
611 lpfc_handle_latt_free_mp:
613 lpfc_handle_latt_free_pmb:
614 mempool_free(pmb, phba->mbox_mem_pool);
615 lpfc_handle_latt_err_exit:
616 /* Enable Link attention interrupts */
617 spin_lock_irq(&phba->hbalock);
618 psli->sli_flag |= LPFC_PROCESS_LA;
619 control = readl(phba->HCregaddr);
620 control |= HC_LAINT_ENA;
621 writel(control, phba->HCregaddr);
622 readl(phba->HCregaddr); /* flush */
624 /* Clear Link Attention in HA REG */
625 writel(HA_LATT, phba->HAregaddr);
626 readl(phba->HAregaddr); /* flush */
627 spin_unlock_irq(&phba->hbalock);
629 phba->link_state = LPFC_HBA_ERROR;
631 /* The other case is an error from issue_mbox */
633 lpfc_printf_log(phba,
636 "%d:0300 READ_LA: no buffers\n",
642 /************************************************************************/
645 /* This routine will parse the VPD data */
647 /************************************************************************/
649 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
651 uint8_t lenlo, lenhi;
661 lpfc_printf_log(phba,
664 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
666 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
668 while (!finished && (index < (len - 4))) {
669 switch (vpd[index]) {
677 i = ((((unsigned short)lenhi) << 8) + lenlo);
686 Length = ((((unsigned short)lenhi) << 8) + lenlo);
687 if (Length > len - index)
688 Length = len - index;
690 /* Look for Serial Number */
691 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
698 phba->SerialNumber[j++] = vpd[index++];
702 phba->SerialNumber[j] = 0;
705 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
706 phba->vpd_flag |= VPD_MODEL_DESC;
713 phba->ModelDesc[j++] = vpd[index++];
717 phba->ModelDesc[j] = 0;
720 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
721 phba->vpd_flag |= VPD_MODEL_NAME;
728 phba->ModelName[j++] = vpd[index++];
732 phba->ModelName[j] = 0;
735 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
736 phba->vpd_flag |= VPD_PROGRAM_TYPE;
743 phba->ProgramType[j++] = vpd[index++];
747 phba->ProgramType[j] = 0;
750 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
751 phba->vpd_flag |= VPD_PORT;
758 phba->Port[j++] = vpd[index++];
788 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
791 uint16_t dev_id = phba->pcidev->device;
797 } m = {"<Unknown>", 0, ""};
799 if (mdp && mdp[0] != '\0'
800 && descp && descp[0] != '\0')
803 if (phba->lmt & LMT_10Gb)
805 else if (phba->lmt & LMT_8Gb)
807 else if (phba->lmt & LMT_4Gb)
809 else if (phba->lmt & LMT_2Gb)
817 case PCI_DEVICE_ID_FIREFLY:
818 m = (typeof(m)){"LP6000", max_speed, "PCI"};
820 case PCI_DEVICE_ID_SUPERFLY:
821 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
822 m = (typeof(m)){"LP7000", max_speed, "PCI"};
824 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
826 case PCI_DEVICE_ID_DRAGONFLY:
827 m = (typeof(m)){"LP8000", max_speed, "PCI"};
829 case PCI_DEVICE_ID_CENTAUR:
830 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
831 m = (typeof(m)){"LP9002", max_speed, "PCI"};
833 m = (typeof(m)){"LP9000", max_speed, "PCI"};
835 case PCI_DEVICE_ID_RFLY:
836 m = (typeof(m)){"LP952", max_speed, "PCI"};
838 case PCI_DEVICE_ID_PEGASUS:
839 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
841 case PCI_DEVICE_ID_THOR:
842 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
844 case PCI_DEVICE_ID_VIPER:
845 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
847 case PCI_DEVICE_ID_PFLY:
848 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
850 case PCI_DEVICE_ID_TFLY:
851 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
853 case PCI_DEVICE_ID_HELIOS:
854 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
856 case PCI_DEVICE_ID_HELIOS_SCSP:
857 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
859 case PCI_DEVICE_ID_HELIOS_DCSP:
860 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
862 case PCI_DEVICE_ID_NEPTUNE:
863 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
865 case PCI_DEVICE_ID_NEPTUNE_SCSP:
866 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
868 case PCI_DEVICE_ID_NEPTUNE_DCSP:
869 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
871 case PCI_DEVICE_ID_BMID:
872 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
874 case PCI_DEVICE_ID_BSMB:
875 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
877 case PCI_DEVICE_ID_ZEPHYR:
878 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
880 case PCI_DEVICE_ID_ZEPHYR_SCSP:
881 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
883 case PCI_DEVICE_ID_ZEPHYR_DCSP:
884 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
886 case PCI_DEVICE_ID_ZMID:
887 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
889 case PCI_DEVICE_ID_ZSMB:
890 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
892 case PCI_DEVICE_ID_LP101:
893 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
895 case PCI_DEVICE_ID_LP10000S:
896 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
898 case PCI_DEVICE_ID_LP11000S:
899 m = (typeof(m)){"LP11000-S", max_speed,
902 case PCI_DEVICE_ID_LPE11000S:
903 m = (typeof(m)){"LPe11000-S", max_speed,
906 case PCI_DEVICE_ID_SAT:
907 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
909 case PCI_DEVICE_ID_SAT_MID:
910 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
912 case PCI_DEVICE_ID_SAT_SMB:
913 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
915 case PCI_DEVICE_ID_SAT_DCSP:
916 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
918 case PCI_DEVICE_ID_SAT_SCSP:
919 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
921 case PCI_DEVICE_ID_SAT_S:
922 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
925 m = (typeof(m)){ NULL };
929 if (mdp && mdp[0] == '\0')
930 snprintf(mdp, 79,"%s", m.name);
931 if (descp && descp[0] == '\0')
933 "Emulex %s %dGb %s Fibre Channel Adapter",
934 m.name, m.max_speed, m.bus);
937 /**************************************************/
938 /* lpfc_post_buffer */
940 /* This routine will post count buffers to the */
941 /* ring with the QUE_RING_BUF_CN command. This */
942 /* allows 3 buffers / command to be posted. */
943 /* Returns the number of buffers NOT posted. */
944 /**************************************************/
946 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
950 struct lpfc_iocbq *iocb;
951 struct lpfc_dmabuf *mp1, *mp2;
953 cnt += pring->missbufcnt;
955 /* While there are buffers to post */
957 /* Allocate buffer for command iocb */
958 iocb = lpfc_sli_get_iocbq(phba);
960 pring->missbufcnt = cnt;
965 /* 2 buffers can be posted per command */
966 /* Allocate buffer to post */
967 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
969 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
971 if (mp1 == 0 || mp1->virt == 0) {
973 lpfc_sli_release_iocbq(phba, iocb);
974 pring->missbufcnt = cnt;
978 INIT_LIST_HEAD(&mp1->list);
979 /* Allocate buffer to post */
981 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
983 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
985 if (mp2 == 0 || mp2->virt == 0) {
987 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
989 lpfc_sli_release_iocbq(phba, iocb);
990 pring->missbufcnt = cnt;
994 INIT_LIST_HEAD(&mp2->list);
999 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1000 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1001 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1002 icmd->ulpBdeCount = 1;
1005 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1006 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1007 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1009 icmd->ulpBdeCount = 2;
1012 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1015 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1016 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1020 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1024 lpfc_sli_release_iocbq(phba, iocb);
1025 pring->missbufcnt = cnt;
1028 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1030 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1033 pring->missbufcnt = 0;
1037 /************************************************************************/
1039 /* lpfc_post_rcv_buf */
1040 /* This routine post initial rcv buffers to the configured rings */
1042 /************************************************************************/
1044 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1046 struct lpfc_sli *psli = &phba->sli;
1048 /* Ring 0, ELS / CT buffers */
1049 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1050 /* Ring 2 - FCP no buffers needed */
1055 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1057 /************************************************************************/
1061 /************************************************************************/
1063 lpfc_sha_init(uint32_t * HashResultPointer)
1065 HashResultPointer[0] = 0x67452301;
1066 HashResultPointer[1] = 0xEFCDAB89;
1067 HashResultPointer[2] = 0x98BADCFE;
1068 HashResultPointer[3] = 0x10325476;
1069 HashResultPointer[4] = 0xC3D2E1F0;
1072 /************************************************************************/
1074 /* lpfc_sha_iterate */
1076 /************************************************************************/
1078 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1082 uint32_t A, B, C, D, E;
1085 HashWorkingPointer[t] =
1087 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1089 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1090 } while (++t <= 79);
1092 A = HashResultPointer[0];
1093 B = HashResultPointer[1];
1094 C = HashResultPointer[2];
1095 D = HashResultPointer[3];
1096 E = HashResultPointer[4];
1100 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1101 } else if (t < 40) {
1102 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1103 } else if (t < 60) {
1104 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1106 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1108 TEMP += S(5, A) + E + HashWorkingPointer[t];
1114 } while (++t <= 79);
1116 HashResultPointer[0] += A;
1117 HashResultPointer[1] += B;
1118 HashResultPointer[2] += C;
1119 HashResultPointer[3] += D;
1120 HashResultPointer[4] += E;
1124 /************************************************************************/
1126 /* lpfc_challenge_key */
1128 /************************************************************************/
1130 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1132 *HashWorking = (*RandomChallenge ^ *HashWorking);
1135 /************************************************************************/
1139 /************************************************************************/
1141 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1144 uint32_t *HashWorking;
1145 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1147 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1151 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1152 HashWorking[0] = HashWorking[78] = *pwwnn++;
1153 HashWorking[1] = HashWorking[79] = *pwwnn;
1155 for (t = 0; t < 7; t++)
1156 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1158 lpfc_sha_init(hbainit);
1159 lpfc_sha_iterate(hbainit, HashWorking);
1164 lpfc_cleanup(struct lpfc_vport *vport)
1166 struct lpfc_nodelist *ndlp, *next_ndlp;
1168 /* clean up phba - lpfc specific */
1169 lpfc_can_disctmo(vport);
1170 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1173 INIT_LIST_HEAD(&vport->fc_nodes);
1179 lpfc_establish_link_tmo(unsigned long ptr)
1181 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1182 struct lpfc_vport *vport = phba->pport;
1183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1184 unsigned long iflag;
1187 /* Re-establishing Link, timer expired */
1188 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1189 "%d:1300 Re-establishing Link, timer expired "
1191 phba->brd_no, vport->fc_flag,
1193 spin_lock_irqsave(shost->host_lock, iflag);
1194 vport->fc_flag &= ~FC_ESTABLISH_LINK;
1195 spin_unlock_irqrestore(shost->host_lock, iflag);
1199 lpfc_stop_timer(struct lpfc_hba *phba)
1201 struct lpfc_vport *vport = phba->pport;
1203 del_timer_sync(&phba->fcp_poll_timer);
1204 del_timer_sync(&phba->fc_estabtmo);
1205 del_timer_sync(&vport->els_tmofunc);
1206 del_timer_sync(&vport->fc_fdmitmo);
1207 del_timer_sync(&vport->fc_disctmo);
1208 del_timer_sync(&phba->sli.mbox_tmo);
1213 lpfc_online(struct lpfc_hba *phba)
1215 struct lpfc_vport *vport = phba->pport;
1216 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1221 if (!(vport->fc_flag & FC_OFFLINE_MODE))
1224 lpfc_printf_log(phba,
1227 "%d:0458 Bring Adapter online\n",
1230 lpfc_block_mgmt_io(phba);
1232 if (!lpfc_sli_queue_setup(phba)) {
1233 lpfc_unblock_mgmt_io(phba);
1237 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1238 lpfc_unblock_mgmt_io(phba);
1242 spin_lock_irq(shost->host_lock);
1243 vport->fc_flag &= ~FC_OFFLINE_MODE;
1244 spin_unlock_irq(shost->host_lock);
1246 lpfc_unblock_mgmt_io(phba);
1251 lpfc_block_mgmt_io(struct lpfc_hba * phba)
1253 unsigned long iflag;
1255 spin_lock_irqsave(&phba->hbalock, iflag);
1256 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1257 spin_unlock_irqrestore(&phba->hbalock, iflag);
1261 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1263 unsigned long iflag;
1265 spin_lock_irqsave(&phba->hbalock, iflag);
1266 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1267 spin_unlock_irqrestore(&phba->hbalock, iflag);
1271 lpfc_offline_prep(struct lpfc_hba * phba)
1273 struct lpfc_vport *vport = phba->pport;
1274 struct lpfc_nodelist *ndlp, *next_ndlp;
1276 if (vport->fc_flag & FC_OFFLINE_MODE)
1279 lpfc_block_mgmt_io(phba);
1281 lpfc_linkdown(phba);
1283 /* Issue an unreg_login to all nodes */
1284 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1285 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
1286 lpfc_unreg_rpi(vport, ndlp);
1288 lpfc_sli_flush_mbox_queue(phba);
1292 lpfc_offline(struct lpfc_hba *phba)
1294 struct lpfc_vport *vport = phba->pport;
1295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1296 unsigned long iflag;
1298 if (vport->fc_flag & FC_OFFLINE_MODE)
1301 /* stop all timers associated with this hba */
1302 lpfc_stop_timer(phba);
1304 lpfc_printf_log(phba,
1307 "%d:0460 Bring Adapter offline\n",
1310 /* Bring down the SLI Layer and cleanup. The HBA is offline
1312 lpfc_sli_hba_down(phba);
1313 lpfc_cleanup(vport);
1314 spin_lock_irqsave(shost->host_lock, iflag);
1315 spin_lock(&phba->hbalock);
1317 vport->work_port_events = 0;
1318 vport->fc_flag |= FC_OFFLINE_MODE;
1319 spin_unlock(&phba->hbalock);
1320 spin_unlock_irqrestore(shost->host_lock, iflag);
1323 /******************************************************************************
1324 * Function name: lpfc_scsi_free
1326 * Description: Called from lpfc_pci_remove_one free internal driver resources
1328 ******************************************************************************/
1330 lpfc_scsi_free(struct lpfc_hba *phba)
1332 struct lpfc_scsi_buf *sb, *sb_next;
1333 struct lpfc_iocbq *io, *io_next;
1335 spin_lock_irq(&phba->hbalock);
1336 /* Release all the lpfc_scsi_bufs maintained by this host. */
1337 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1338 list_del(&sb->list);
1339 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1342 phba->total_scsi_bufs--;
1345 /* Release all the lpfc_iocbq entries maintained by this host. */
1346 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1347 list_del(&io->list);
1349 phba->total_iocbq_bufs--;
1352 spin_unlock_irq(&phba->hbalock);
1358 lpfc_create_port(struct lpfc_hba *phba, int instance)
1360 struct lpfc_vport *vport;
1361 struct Scsi_Host *shost;
1364 shost = scsi_host_alloc(&lpfc_template, sizeof(struct lpfc_vport));
1368 vport = (struct lpfc_vport *) shost->hostdata;
1371 vport->load_flag |= FC_LOADING;
1373 shost->unique_id = instance;
1374 shost->max_id = LPFC_MAX_TARGET;
1375 shost->max_lun = phba->cfg_max_luns;
1376 shost->this_id = -1;
1377 shost->max_cmd_len = 16;
1379 * Set initial can_queue value since 0 is no longer supported and
1380 * scsi_add_host will fail. This will be adjusted later based on the
1381 * max xri value determined in hba setup.
1383 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1384 shost->transportt = lpfc_transport_template;
1386 /* Initialize all internally managed lists. */
1387 INIT_LIST_HEAD(&vport->fc_nodes);
1388 spin_lock_init(&vport->work_port_lock);
1390 init_timer(&vport->fc_disctmo);
1391 vport->fc_disctmo.function = lpfc_disc_timeout;
1392 vport->fc_disctmo.data = (unsigned long) vport;
1394 init_timer(&vport->fc_fdmitmo);
1395 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1396 vport->fc_fdmitmo.data = (unsigned long) vport;
1398 init_timer(&vport->els_tmofunc);
1399 vport->els_tmofunc.function = lpfc_els_timeout;
1400 vport->els_tmofunc.data = (unsigned long) vport;
1402 error = scsi_add_host(shost, &phba->pcidev->dev);
1406 list_add_tail(&vport->listentry, &phba->port_list);
1407 scsi_scan_host(shost);
1411 scsi_host_put(shost);
1417 destroy_port(struct lpfc_vport *vport)
1419 lpfc_cleanup(vport);
1420 list_del(&vport->listentry);
1421 lpfc_free_sysfs_attr(vport);
1422 fc_remove_host(lpfc_shost_from_vport(vport));
1423 scsi_remove_host(lpfc_shost_from_vport(vport));
1428 lpfc_remove_device(struct lpfc_vport *vport)
1430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1431 struct lpfc_hba *phba = vport->phba;
1433 lpfc_free_sysfs_attr(vport);
1435 spin_lock_irq(shost->host_lock);
1436 vport->fc_flag |= FC_UNLOADING;
1437 spin_unlock_irq(shost->host_lock);
1439 fc_remove_host(shost);
1440 scsi_remove_host(shost);
1442 kthread_stop(phba->worker_thread);
1445 void lpfc_scan_start(struct Scsi_Host *shost)
1447 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1448 struct lpfc_hba *phba = vport->phba;
1450 if (lpfc_alloc_sysfs_attr(vport))
1454 * hba setup may have changed the hba_queue_depth so we need to adjust
1455 * the value of can_queue.
1457 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1461 lpfc_remove_device(vport);
1464 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1467 struct lpfc_hba *phba = vport->phba;
1469 if (time >= 30 * HZ) {
1470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1471 "%d:0461 Scanning longer than 30 "
1472 "seconds. Continuing initialization\n",
1476 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1477 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1478 "%d:0465 Link down longer than 15 "
1479 "seconds. Continuing initialization\n",
1484 if (vport->port_state != LPFC_VPORT_READY)
1486 if (vport->num_disc_nodes || vport->fc_prli_sent)
1488 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
1490 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
1495 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1498 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1499 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
1500 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1502 memset(fc_host_supported_fc4s(shost), 0,
1503 sizeof(fc_host_supported_fc4s(shost)));
1504 fc_host_supported_fc4s(shost)[2] = 1;
1505 fc_host_supported_fc4s(shost)[7] = 1;
1507 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1509 fc_host_supported_speeds(shost) = 0;
1510 if (phba->lmt & LMT_10Gb)
1511 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1512 if (phba->lmt & LMT_4Gb)
1513 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1514 if (phba->lmt & LMT_2Gb)
1515 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1516 if (phba->lmt & LMT_1Gb)
1517 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1519 fc_host_maxframe_size(shost) =
1520 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1521 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
1523 /* This value is also unchanging */
1524 memset(fc_host_active_fc4s(shost), 0,
1525 sizeof(fc_host_active_fc4s(shost)));
1526 fc_host_active_fc4s(shost)[2] = 1;
1527 fc_host_active_fc4s(shost)[7] = 1;
1529 spin_lock_irq(shost->host_lock);
1530 vport->fc_flag &= ~FC_LOADING;
1531 spin_unlock_irq(shost->host_lock);
1536 static int __devinit
1537 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1539 struct lpfc_vport *vport = NULL;
1540 struct lpfc_hba *phba;
1541 struct lpfc_sli *psli;
1542 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1543 struct Scsi_Host *shost = NULL;
1544 unsigned long bar0map_len, bar2map_len;
1545 int error = -ENODEV, retval;
1549 if (pci_enable_device(pdev))
1551 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1552 goto out_disable_device;
1554 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1556 goto out_release_regions;
1558 spin_lock_init(&phba->hbalock);
1560 phba->pcidev = pdev;
1562 /* Assign an unused board number */
1563 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1566 error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
1570 INIT_LIST_HEAD(&phba->port_list);
1573 * Get all the module params for configuring this host and then
1574 * establish the host.
1576 lpfc_get_cfgparam(phba);
1578 /* Initialize timers used by driver */
1579 init_timer(&phba->fc_estabtmo);
1580 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1581 phba->fc_estabtmo.data = (unsigned long) phba;
1583 init_timer(&psli->mbox_tmo);
1584 psli->mbox_tmo.function = lpfc_mbox_timeout;
1585 psli->mbox_tmo.data = (unsigned long) phba;
1586 init_timer(&phba->fcp_poll_timer);
1587 phba->fcp_poll_timer.function = lpfc_poll_timeout;
1588 phba->fcp_poll_timer.data = (unsigned long) phba;
1590 pci_set_master(pdev);
1591 retval = pci_set_mwi(pdev);
1593 dev_printk(KERN_WARNING, &pdev->dev,
1594 "Warning: pci_set_mwi returned %d\n", retval);
1596 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1597 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1598 goto out_idr_remove;
1601 * Get the bus address of Bar0 and Bar2 and the number of bytes
1602 * required by each mapping.
1604 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1605 bar0map_len = pci_resource_len(phba->pcidev, 0);
1607 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1608 bar2map_len = pci_resource_len(phba->pcidev, 2);
1610 /* Map HBA SLIM to a kernel virtual address. */
1611 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
1612 if (!phba->slim_memmap_p) {
1614 dev_printk(KERN_ERR, &pdev->dev,
1615 "ioremap failed for SLIM memory.\n");
1616 goto out_idr_remove;
1619 /* Map HBA Control Registers to a kernel virtual address. */
1620 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
1621 if (!phba->ctrl_regs_memmap_p) {
1623 dev_printk(KERN_ERR, &pdev->dev,
1624 "ioremap failed for HBA control registers.\n");
1625 goto out_iounmap_slim;
1628 /* Allocate memory for SLI-2 structures */
1629 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1630 &phba->slim2p_mapping, GFP_KERNEL);
1634 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
1636 /* Initialize the SLI Layer to run with lpfc HBAs. */
1637 lpfc_sli_setup(phba);
1638 lpfc_sli_queue_setup(phba);
1640 error = lpfc_mem_alloc(phba);
1644 /* Initialize and populate the iocb list per host. */
1645 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1646 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1647 iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1648 if (iocbq_entry == NULL) {
1649 printk(KERN_ERR "%s: only allocated %d iocbs of "
1650 "expected %d count. Unloading driver.\n",
1651 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1653 goto out_free_iocbq;
1656 memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
1657 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1659 kfree (iocbq_entry);
1660 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1661 "Unloading driver.\n",
1664 goto out_free_iocbq;
1667 spin_lock_irq(&phba->hbalock);
1668 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1669 phba->total_iocbq_bufs++;
1670 spin_unlock_irq(&phba->hbalock);
1673 /* Initialize HBA structure */
1674 phba->fc_edtov = FF_DEF_EDTOV;
1675 phba->fc_ratov = FF_DEF_RATOV;
1676 phba->fc_altov = FF_DEF_ALTOV;
1677 phba->fc_arbtov = FF_DEF_ARBTOV;
1679 INIT_LIST_HEAD(&phba->work_list);
1680 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1681 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1683 /* Startup the kernel thread for this host adapter. */
1684 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1685 "lpfc_worker_%d", phba->brd_no);
1686 if (IS_ERR(phba->worker_thread)) {
1687 error = PTR_ERR(phba->worker_thread);
1688 goto out_free_iocbq;
1691 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1692 spin_lock_init(&phba->scsi_buf_list_lock);
1693 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1695 vport = lpfc_create_port(phba, phba->brd_no);
1697 goto out_kthread_stop;
1699 shost = lpfc_shost_from_vport(vport);
1700 vport->port_type = LPFC_PHYSICAL_PORT;
1701 phba->pport = vport;
1703 pci_set_drvdata(pdev, lpfc_shost_from_vport(vport));
1705 if (phba->cfg_use_msi) {
1706 error = pci_enable_msi(phba->pcidev);
1708 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "%d:0452 "
1709 "Enable MSI failed, continuing with "
1710 "IRQ\n", phba->brd_no);
1713 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
1714 LPFC_DRIVER_NAME, phba);
1716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1717 "%d:0451 Enable interrupt handler failed\n",
1719 goto out_destroy_port;
1722 phba->MBslimaddr = phba->slim_memmap_p;
1723 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1724 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1725 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1726 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1728 error = lpfc_sli_hba_setup(phba);
1732 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1733 spin_lock_irq(shost->host_lock);
1734 lpfc_poll_start_timer(phba);
1735 spin_unlock_irq(shost->host_lock);
1741 lpfc_stop_timer(phba);
1742 phba->pport->work_port_events = 0;
1743 free_irq(phba->pcidev->irq, phba);
1744 pci_disable_msi(phba->pcidev);
1746 destroy_port(vport);
1748 kthread_stop(phba->worker_thread);
1750 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1751 &phba->lpfc_iocb_list, list) {
1753 phba->total_iocbq_bufs--;
1755 lpfc_mem_free(phba);
1757 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1758 phba->slim2p_mapping);
1760 iounmap(phba->ctrl_regs_memmap_p);
1762 iounmap(phba->slim_memmap_p);
1764 idr_remove(&lpfc_hba_index, phba->brd_no);
1767 out_release_regions:
1768 pci_release_regions(pdev);
1770 pci_disable_device(pdev);
1772 pci_set_drvdata(pdev, NULL);
1776 static void __devexit
1777 lpfc_pci_remove_one(struct pci_dev *pdev)
1779 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1780 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1781 struct lpfc_hba *phba = vport->phba;
1783 vport->load_flag |= FC_UNLOADING;
1784 lpfc_remove_device(vport);
1787 * Bring down the SLI Layer. This step disable all interrupts,
1788 * clears the rings, discards all mailbox commands, and resets
1791 lpfc_sli_hba_down(phba);
1792 lpfc_sli_brdrestart(phba);
1794 lpfc_stop_timer(phba);
1796 kthread_stop(phba->worker_thread);
1798 /* Release the irq reservation */
1799 free_irq(phba->pcidev->irq, phba);
1800 pci_disable_msi(phba->pcidev);
1802 vport->work_port_events = 0;
1803 destroy_port(vport);
1805 pci_set_drvdata(pdev, NULL);
1808 * Call scsi_free before mem_free since scsi bufs are released to their
1809 * corresponding pools here.
1811 lpfc_scsi_free(phba);
1812 lpfc_mem_free(phba);
1814 /* Free resources associated with SLI2 interface */
1815 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
1816 phba->slim2p, phba->slim2p_mapping);
1818 /* unmap adapter SLIM and Control Registers */
1819 iounmap(phba->ctrl_regs_memmap_p);
1820 iounmap(phba->slim_memmap_p);
1822 idr_remove(&lpfc_hba_index, phba->brd_no);
1826 pci_release_regions(pdev);
1827 pci_disable_device(pdev);
1831 * lpfc_io_error_detected - called when PCI error is detected
1832 * @pdev: Pointer to PCI device
1833 * @state: The current pci conneection state
1835 * This function is called after a PCI bus error affecting
1836 * this device has been detected.
1838 static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
1839 pci_channel_state_t state)
1841 struct Scsi_Host *host = pci_get_drvdata(pdev);
1842 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1843 struct lpfc_sli *psli = &phba->sli;
1844 struct lpfc_sli_ring *pring;
1846 if (state == pci_channel_io_perm_failure)
1847 return PCI_ERS_RESULT_DISCONNECT;
1849 pci_disable_device(pdev);
1851 * There may be I/Os dropped by the firmware.
1852 * Error iocb (I/O) on txcmplq and let the SCSI layer
1853 * retry it after re-establishing link.
1855 pring = &psli->ring[psli->fcp_ring];
1856 lpfc_sli_abort_iocb_ring(phba, pring);
1858 /* Request a slot reset. */
1859 return PCI_ERS_RESULT_NEED_RESET;
1863 * lpfc_io_slot_reset - called after the pci bus has been reset.
1864 * @pdev: Pointer to PCI device
1866 * Restart the card from scratch, as if from a cold-boot.
1868 static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
1870 struct Scsi_Host *host = pci_get_drvdata(pdev);
1871 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1872 struct lpfc_sli *psli = &phba->sli;
1873 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1875 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
1876 if (pci_enable_device_bars(pdev, bars)) {
1877 printk(KERN_ERR "lpfc: Cannot re-enable "
1878 "PCI device after reset.\n");
1879 return PCI_ERS_RESULT_DISCONNECT;
1882 pci_set_master(pdev);
1884 /* Re-establishing Link */
1885 spin_lock_irq(&phba->hbalock);
1886 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
1887 spin_unlock_irq(&phba->hbalock);
1888 spin_lock_irq(host->host_lock);
1889 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1890 spin_unlock_irq(host->host_lock);
1893 /* Take device offline; this will perform cleanup */
1895 lpfc_sli_brdrestart(phba);
1897 return PCI_ERS_RESULT_RECOVERED;
1901 * lpfc_io_resume - called when traffic can start flowing again.
1902 * @pdev: Pointer to PCI device
1904 * This callback is called when the error recovery driver tells us that
1905 * its OK to resume normal operation.
1907 static void lpfc_io_resume(struct pci_dev *pdev)
1909 struct Scsi_Host *host = pci_get_drvdata(pdev);
1910 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1912 if (lpfc_online(phba) == 0) {
1913 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
1917 static struct pci_device_id lpfc_id_table[] = {
1918 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1919 PCI_ANY_ID, PCI_ANY_ID, },
1920 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
1921 PCI_ANY_ID, PCI_ANY_ID, },
1922 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
1923 PCI_ANY_ID, PCI_ANY_ID, },
1924 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
1925 PCI_ANY_ID, PCI_ANY_ID, },
1926 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
1927 PCI_ANY_ID, PCI_ANY_ID, },
1928 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
1929 PCI_ANY_ID, PCI_ANY_ID, },
1930 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
1931 PCI_ANY_ID, PCI_ANY_ID, },
1932 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
1933 PCI_ANY_ID, PCI_ANY_ID, },
1934 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
1935 PCI_ANY_ID, PCI_ANY_ID, },
1936 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
1937 PCI_ANY_ID, PCI_ANY_ID, },
1938 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
1939 PCI_ANY_ID, PCI_ANY_ID, },
1940 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
1941 PCI_ANY_ID, PCI_ANY_ID, },
1942 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
1943 PCI_ANY_ID, PCI_ANY_ID, },
1944 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
1945 PCI_ANY_ID, PCI_ANY_ID, },
1946 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
1947 PCI_ANY_ID, PCI_ANY_ID, },
1948 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
1949 PCI_ANY_ID, PCI_ANY_ID, },
1950 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
1951 PCI_ANY_ID, PCI_ANY_ID, },
1952 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
1953 PCI_ANY_ID, PCI_ANY_ID, },
1954 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
1955 PCI_ANY_ID, PCI_ANY_ID, },
1956 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
1957 PCI_ANY_ID, PCI_ANY_ID, },
1958 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
1959 PCI_ANY_ID, PCI_ANY_ID, },
1960 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
1961 PCI_ANY_ID, PCI_ANY_ID, },
1962 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
1963 PCI_ANY_ID, PCI_ANY_ID, },
1964 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
1965 PCI_ANY_ID, PCI_ANY_ID, },
1966 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
1967 PCI_ANY_ID, PCI_ANY_ID, },
1968 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
1969 PCI_ANY_ID, PCI_ANY_ID, },
1970 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
1971 PCI_ANY_ID, PCI_ANY_ID, },
1972 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
1973 PCI_ANY_ID, PCI_ANY_ID, },
1974 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
1975 PCI_ANY_ID, PCI_ANY_ID, },
1976 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
1977 PCI_ANY_ID, PCI_ANY_ID, },
1978 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
1979 PCI_ANY_ID, PCI_ANY_ID, },
1980 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
1981 PCI_ANY_ID, PCI_ANY_ID, },
1982 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
1983 PCI_ANY_ID, PCI_ANY_ID, },
1987 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1989 static struct pci_error_handlers lpfc_err_handler = {
1990 .error_detected = lpfc_io_error_detected,
1991 .slot_reset = lpfc_io_slot_reset,
1992 .resume = lpfc_io_resume,
1995 static struct pci_driver lpfc_driver = {
1996 .name = LPFC_DRIVER_NAME,
1997 .id_table = lpfc_id_table,
1998 .probe = lpfc_pci_probe_one,
1999 .remove = __devexit_p(lpfc_pci_remove_one),
2000 .err_handler = &lpfc_err_handler,
2008 printk(LPFC_MODULE_DESC "\n");
2009 printk(LPFC_COPYRIGHT "\n");
2011 lpfc_transport_template =
2012 fc_attach_transport(&lpfc_transport_functions);
2013 if (!lpfc_transport_template)
2015 error = pci_register_driver(&lpfc_driver);
2017 fc_release_transport(lpfc_transport_template);
2025 pci_unregister_driver(&lpfc_driver);
2026 fc_release_transport(lpfc_transport_template);
2029 module_init(lpfc_init);
2030 module_exit(lpfc_exit);
2031 MODULE_LICENSE("GPL");
2032 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2033 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2034 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);