7e5ea0774e58cf3a18cfeb94ba93ce6bae4d17f0
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_init.c
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.                        *
6  * www.emulex.com                                                  *
7  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
8  *                                                                 *
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  *******************************************************************/
21
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
31
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
36
37 #include "lpfc_hw.h"
38 #include "lpfc_sli.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
41 #include "lpfc.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_version.h"
46 #include "lpfc_vport.h"
47
48 static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
49 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
50 static int lpfc_post_rcv_buf(struct lpfc_hba *);
51
52 static struct scsi_transport_template *lpfc_transport_template = NULL;
53 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
54 static DEFINE_IDR(lpfc_hba_index);
55
56
57
58 /************************************************************************/
59 /*                                                                      */
60 /*    lpfc_config_port_prep                                             */
61 /*    This routine will do LPFC initialization prior to the             */
62 /*    CONFIG_PORT mailbox command. This will be initialized             */
63 /*    as a SLI layer callback routine.                                  */
64 /*    This routine returns 0 on success or -ERESTART if it wants        */
65 /*    the SLI layer to reset the HBA and try again. Any                 */
66 /*    other return value indicates an error.                            */
67 /*                                                                      */
68 /************************************************************************/
69 int
70 lpfc_config_port_prep(struct lpfc_hba *phba)
71 {
72         lpfc_vpd_t *vp = &phba->vpd;
73         int i = 0, rc;
74         LPFC_MBOXQ_t *pmb;
75         MAILBOX_t *mb;
76         char *lpfc_vpd_data = NULL;
77         uint16_t offset = 0;
78         static char licensed[56] =
79                     "key unlock for use with gnu public licensed code only\0";
80         static int init_key = 1;
81
82         pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
83         if (!pmb) {
84                 phba->link_state = LPFC_HBA_ERROR;
85                 return -ENOMEM;
86         }
87
88         mb = &pmb->mb;
89         phba->link_state = LPFC_INIT_MBX_CMDS;
90
91         if (lpfc_is_LC_HBA(phba->pcidev->device)) {
92                 if (init_key) {
93                         uint32_t *ptext = (uint32_t *) licensed;
94
95                         for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
96                                 *ptext = cpu_to_be32(*ptext);
97                         init_key = 0;
98                 }
99
100                 lpfc_read_nv(phba, pmb);
101                 memset((char*)mb->un.varRDnvp.rsvd3, 0,
102                         sizeof (mb->un.varRDnvp.rsvd3));
103                 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
104                          sizeof (licensed));
105
106                 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
107
108                 if (rc != MBX_SUCCESS) {
109                         lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
110                                         "0324 Config Port initialization "
111                                         "error, mbxCmd x%x READ_NVPARM, "
112                                         "mbxStatus x%x\n",
113                                         mb->mbxCommand, mb->mbxStatus);
114                         mempool_free(pmb, phba->mbox_mem_pool);
115                         return -ERESTART;
116                 }
117                 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
118                        sizeof(phba->wwnn));
119                 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
120                        sizeof(phba->wwpn));
121         }
122
123         phba->sli3_options = 0x0;
124
125         /* Setup and issue mailbox READ REV command */
126         lpfc_read_rev(phba, pmb);
127         rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
128         if (rc != MBX_SUCCESS) {
129                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
130                                 "0439 Adapter failed to init, mbxCmd x%x "
131                                 "READ_REV, mbxStatus x%x\n",
132                                 mb->mbxCommand, mb->mbxStatus);
133                 mempool_free( pmb, phba->mbox_mem_pool);
134                 return -ERESTART;
135         }
136
137
138         /*
139          * The value of rr must be 1 since the driver set the cv field to 1.
140          * This setting requires the FW to set all revision fields.
141          */
142         if (mb->un.varRdRev.rr == 0) {
143                 vp->rev.rBit = 0;
144                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
145                                 "0440 Adapter failed to init, READ_REV has "
146                                 "missing revision information.\n");
147                 mempool_free(pmb, phba->mbox_mem_pool);
148                 return -ERESTART;
149         }
150
151         if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
152                 return -EINVAL;
153
154         /* Save information as VPD data */
155         vp->rev.rBit = 1;
156         memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
157         vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
158         memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
159         vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
160         memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
161         vp->rev.biuRev = mb->un.varRdRev.biuRev;
162         vp->rev.smRev = mb->un.varRdRev.smRev;
163         vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
164         vp->rev.endecRev = mb->un.varRdRev.endecRev;
165         vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
166         vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
167         vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
168         vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
169         vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
170         vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
171
172         /* If the sli feature level is less then 9, we must
173          * tear down all RPIs and VPIs on link down if NPIV
174          * is enabled.
175          */
176         if (vp->rev.feaLevelHigh < 9)
177                 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
178
179         if (lpfc_is_LC_HBA(phba->pcidev->device))
180                 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
181                                                 sizeof (phba->RandomData));
182
183         /* Get adapter VPD information */
184         pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
185         if (!pmb->context2)
186                 goto out_free_mbox;
187         lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
188         if (!lpfc_vpd_data)
189                 goto out_free_context2;
190
191         do {
192                 lpfc_dump_mem(phba, pmb, offset);
193                 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
194
195                 if (rc != MBX_SUCCESS) {
196                         lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
197                                         "0441 VPD not present on adapter, "
198                                         "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
199                                         mb->mbxCommand, mb->mbxStatus);
200                         mb->un.varDmp.word_cnt = 0;
201                 }
202                 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
203                         mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
204                 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
205                                       mb->un.varDmp.word_cnt);
206                 offset += mb->un.varDmp.word_cnt;
207         } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
208         lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
209
210         kfree(lpfc_vpd_data);
211 out_free_context2:
212         kfree(pmb->context2);
213 out_free_mbox:
214         mempool_free(pmb, phba->mbox_mem_pool);
215         return 0;
216 }
217
218 /************************************************************************/
219 /*                                                                      */
220 /*    lpfc_config_port_post                                             */
221 /*    This routine will do LPFC initialization after the                */
222 /*    CONFIG_PORT mailbox command. This will be initialized             */
223 /*    as a SLI layer callback routine.                                  */
224 /*    This routine returns 0 on success. Any other return value         */
225 /*    indicates an error.                                               */
226 /*                                                                      */
227 /************************************************************************/
228 int
229 lpfc_config_port_post(struct lpfc_hba *phba)
230 {
231         struct lpfc_vport *vport = phba->pport;
232         LPFC_MBOXQ_t *pmb;
233         MAILBOX_t *mb;
234         struct lpfc_dmabuf *mp;
235         struct lpfc_sli *psli = &phba->sli;
236         uint32_t status, timeout;
237         int i, j;
238         int rc;
239
240         pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
241         if (!pmb) {
242                 phba->link_state = LPFC_HBA_ERROR;
243                 return -ENOMEM;
244         }
245         mb = &pmb->mb;
246
247         /* Get login parameters for NID.  */
248         lpfc_read_sparam(phba, pmb, 0);
249         pmb->vport = vport;
250         if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
251                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
252                                 "0448 Adapter failed init, mbxCmd x%x "
253                                 "READ_SPARM mbxStatus x%x\n",
254                                 mb->mbxCommand, mb->mbxStatus);
255                 phba->link_state = LPFC_HBA_ERROR;
256                 mp = (struct lpfc_dmabuf *) pmb->context1;
257                 mempool_free( pmb, phba->mbox_mem_pool);
258                 lpfc_mbuf_free(phba, mp->virt, mp->phys);
259                 kfree(mp);
260                 return -EIO;
261         }
262
263         mp = (struct lpfc_dmabuf *) pmb->context1;
264
265         memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
266         lpfc_mbuf_free(phba, mp->virt, mp->phys);
267         kfree(mp);
268         pmb->context1 = NULL;
269
270         if (phba->cfg_soft_wwnn)
271                 u64_to_wwn(phba->cfg_soft_wwnn,
272                            vport->fc_sparam.nodeName.u.wwn);
273         if (phba->cfg_soft_wwpn)
274                 u64_to_wwn(phba->cfg_soft_wwpn,
275                            vport->fc_sparam.portName.u.wwn);
276         memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
277                sizeof (struct lpfc_name));
278         memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
279                sizeof (struct lpfc_name));
280         /* If no serial number in VPD data, use low 6 bytes of WWNN */
281         /* This should be consolidated into parse_vpd ? - mr */
282         if (phba->SerialNumber[0] == 0) {
283                 uint8_t *outptr;
284
285                 outptr = &vport->fc_nodename.u.s.IEEE[0];
286                 for (i = 0; i < 12; i++) {
287                         status = *outptr++;
288                         j = ((status & 0xf0) >> 4);
289                         if (j <= 9)
290                                 phba->SerialNumber[i] =
291                                     (char)((uint8_t) 0x30 + (uint8_t) j);
292                         else
293                                 phba->SerialNumber[i] =
294                                     (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
295                         i++;
296                         j = (status & 0xf);
297                         if (j <= 9)
298                                 phba->SerialNumber[i] =
299                                     (char)((uint8_t) 0x30 + (uint8_t) j);
300                         else
301                                 phba->SerialNumber[i] =
302                                     (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
303                 }
304         }
305
306         lpfc_read_config(phba, pmb);
307         pmb->vport = vport;
308         if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
309                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
310                                 "0453 Adapter failed to init, mbxCmd x%x "
311                                 "READ_CONFIG, mbxStatus x%x\n",
312                                 mb->mbxCommand, mb->mbxStatus);
313                 phba->link_state = LPFC_HBA_ERROR;
314                 mempool_free( pmb, phba->mbox_mem_pool);
315                 return -EIO;
316         }
317
318         /* Reset the DFT_HBA_Q_DEPTH to the max xri  */
319         if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
320                 phba->cfg_hba_queue_depth =
321                         mb->un.varRdConfig.max_xri + 1;
322
323         phba->lmt = mb->un.varRdConfig.lmt;
324
325         /* Get the default values for Model Name and Description */
326         lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
327
328         if ((phba->cfg_link_speed > LINK_SPEED_10G)
329             || ((phba->cfg_link_speed == LINK_SPEED_1G)
330                 && !(phba->lmt & LMT_1Gb))
331             || ((phba->cfg_link_speed == LINK_SPEED_2G)
332                 && !(phba->lmt & LMT_2Gb))
333             || ((phba->cfg_link_speed == LINK_SPEED_4G)
334                 && !(phba->lmt & LMT_4Gb))
335             || ((phba->cfg_link_speed == LINK_SPEED_8G)
336                 && !(phba->lmt & LMT_8Gb))
337             || ((phba->cfg_link_speed == LINK_SPEED_10G)
338                 && !(phba->lmt & LMT_10Gb))) {
339                 /* Reset link speed to auto */
340                 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
341                         "1302 Invalid speed for this board: "
342                         "Reset link speed to auto: x%x\n",
343                         phba->cfg_link_speed);
344                         phba->cfg_link_speed = LINK_SPEED_AUTO;
345         }
346
347         phba->link_state = LPFC_LINK_DOWN;
348
349         /* Only process IOCBs on ring 0 till hba_state is READY */
350         if (psli->ring[psli->extra_ring].cmdringaddr)
351                 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
352         if (psli->ring[psli->fcp_ring].cmdringaddr)
353                 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
354         if (psli->ring[psli->next_ring].cmdringaddr)
355                 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
356
357         /* Post receive buffers for desired rings */
358         if (phba->sli_rev != 3)
359                 lpfc_post_rcv_buf(phba);
360
361         /* Enable appropriate host interrupts */
362         spin_lock_irq(&phba->hbalock);
363         status = readl(phba->HCregaddr);
364         status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
365         if (psli->num_rings > 0)
366                 status |= HC_R0INT_ENA;
367         if (psli->num_rings > 1)
368                 status |= HC_R1INT_ENA;
369         if (psli->num_rings > 2)
370                 status |= HC_R2INT_ENA;
371         if (psli->num_rings > 3)
372                 status |= HC_R3INT_ENA;
373
374         if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
375             (phba->cfg_poll & DISABLE_FCP_RING_INT))
376                 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
377
378         writel(status, phba->HCregaddr);
379         readl(phba->HCregaddr); /* flush */
380         spin_unlock_irq(&phba->hbalock);
381
382         /*
383          * Setup the ring 0 (els)  timeout handler
384          */
385         timeout = phba->fc_ratov << 1;
386         mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
387         mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
388         phba->hb_outstanding = 0;
389         phba->last_completion_time = jiffies;
390
391         lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
392         pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393         pmb->vport = vport;
394         rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
395         lpfc_set_loopback_flag(phba);
396         if (rc != MBX_SUCCESS) {
397                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
398                                 "0454 Adapter failed to init, mbxCmd x%x "
399                                 "INIT_LINK, mbxStatus x%x\n",
400                                 mb->mbxCommand, mb->mbxStatus);
401
402                 /* Clear all interrupt enable conditions */
403                 writel(0, phba->HCregaddr);
404                 readl(phba->HCregaddr); /* flush */
405                 /* Clear all pending interrupts */
406                 writel(0xffffffff, phba->HAregaddr);
407                 readl(phba->HAregaddr); /* flush */
408
409                 phba->link_state = LPFC_HBA_ERROR;
410                 if (rc != MBX_BUSY)
411                         mempool_free(pmb, phba->mbox_mem_pool);
412                 return -EIO;
413         }
414         /* MBOX buffer will be freed in mbox compl */
415
416         return (0);
417 }
418
419 /************************************************************************/
420 /*                                                                      */
421 /*    lpfc_hba_down_prep                                                */
422 /*    This routine will do LPFC uninitialization before the             */
423 /*    HBA is reset when bringing down the SLI Layer. This will be       */
424 /*    initialized as a SLI layer callback routine.                      */
425 /*    This routine returns 0 on success. Any other return value         */
426 /*    indicates an error.                                               */
427 /*                                                                      */
428 /************************************************************************/
429 int
430 lpfc_hba_down_prep(struct lpfc_hba *phba)
431 {
432         struct lpfc_vport **vports;
433         int i;
434
435         /* Disable interrupts */
436         writel(0, phba->HCregaddr);
437         readl(phba->HCregaddr); /* flush */
438
439         vports = lpfc_create_vport_work_array(phba);
440         if (vports != NULL)
441                 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
442                         lpfc_cleanup_discovery_resources(vports[i]);
443         lpfc_destroy_vport_work_array(vports);
444         return 0;
445 }
446
447 /************************************************************************/
448 /*                                                                      */
449 /*    lpfc_hba_down_post                                                */
450 /*    This routine will do uninitialization after the HBA is reset      */
451 /*    when bringing down the SLI Layer.                                 */
452 /*    This routine returns 0 on success. Any other return value         */
453 /*    indicates an error.                                               */
454 /*                                                                      */
455 /************************************************************************/
456 int
457 lpfc_hba_down_post(struct lpfc_hba *phba)
458 {
459         struct lpfc_sli *psli = &phba->sli;
460         struct lpfc_sli_ring *pring;
461         struct lpfc_dmabuf *mp, *next_mp;
462         int i;
463
464         if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
465                 lpfc_sli_hbqbuf_free_all(phba);
466         else {
467                 /* Cleanup preposted buffers on the ELS ring */
468                 pring = &psli->ring[LPFC_ELS_RING];
469                 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
470                         list_del(&mp->list);
471                         pring->postbufq_cnt--;
472                         lpfc_mbuf_free(phba, mp->virt, mp->phys);
473                         kfree(mp);
474                 }
475         }
476
477         for (i = 0; i < psli->num_rings; i++) {
478                 pring = &psli->ring[i];
479                 lpfc_sli_abort_iocb_ring(phba, pring);
480         }
481
482         return 0;
483 }
484
485 /* HBA heart beat timeout handler */
486 void
487 lpfc_hb_timeout(unsigned long ptr)
488 {
489         struct lpfc_hba *phba;
490         unsigned long iflag;
491
492         phba = (struct lpfc_hba *)ptr;
493         spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
494         if (!(phba->pport->work_port_events & WORKER_HB_TMO))
495                 phba->pport->work_port_events |= WORKER_HB_TMO;
496         spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
497
498         if (phba->work_wait)
499                 wake_up(phba->work_wait);
500         return;
501 }
502
503 static void
504 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
505 {
506         unsigned long drvr_flag;
507
508         spin_lock_irqsave(&phba->hbalock, drvr_flag);
509         phba->hb_outstanding = 0;
510         spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
511
512         mempool_free(pmboxq, phba->mbox_mem_pool);
513         if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
514                 !(phba->link_state == LPFC_HBA_ERROR) &&
515                 !(phba->pport->fc_flag & FC_UNLOADING))
516                 mod_timer(&phba->hb_tmofunc,
517                         jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
518         return;
519 }
520
521 void
522 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
523 {
524         LPFC_MBOXQ_t *pmboxq;
525         int retval;
526         struct lpfc_sli *psli = &phba->sli;
527
528         if ((phba->link_state == LPFC_HBA_ERROR) ||
529                 (phba->pport->fc_flag & FC_UNLOADING) ||
530                 (phba->pport->fc_flag & FC_OFFLINE_MODE))
531                 return;
532
533         spin_lock_irq(&phba->pport->work_port_lock);
534         /* If the timer is already canceled do nothing */
535         if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
536                 spin_unlock_irq(&phba->pport->work_port_lock);
537                 return;
538         }
539
540         if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
541                 jiffies)) {
542                 spin_unlock_irq(&phba->pport->work_port_lock);
543                 if (!phba->hb_outstanding)
544                         mod_timer(&phba->hb_tmofunc,
545                                 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
546                 else
547                         mod_timer(&phba->hb_tmofunc,
548                                 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
549                 return;
550         }
551         spin_unlock_irq(&phba->pport->work_port_lock);
552
553         /* If there is no heart beat outstanding, issue a heartbeat command */
554         if (!phba->hb_outstanding) {
555                 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
556                 if (!pmboxq) {
557                         mod_timer(&phba->hb_tmofunc,
558                                 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
559                         return;
560                 }
561
562                 lpfc_heart_beat(phba, pmboxq);
563                 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
564                 pmboxq->vport = phba->pport;
565                 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
566
567                 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
568                         mempool_free(pmboxq, phba->mbox_mem_pool);
569                         mod_timer(&phba->hb_tmofunc,
570                                 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
571                         return;
572                 }
573                 mod_timer(&phba->hb_tmofunc,
574                         jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
575                 phba->hb_outstanding = 1;
576                 return;
577         } else {
578                 /*
579                  * If heart beat timeout called with hb_outstanding set we
580                  * need to take the HBA offline.
581                  */
582                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
583                                 "0459 Adapter heartbeat failure, taking "
584                                 "this port offline.\n");
585
586                 spin_lock_irq(&phba->hbalock);
587                 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
588                 spin_unlock_irq(&phba->hbalock);
589
590                 lpfc_offline_prep(phba);
591                 lpfc_offline(phba);
592                 lpfc_unblock_mgmt_io(phba);
593                 phba->link_state = LPFC_HBA_ERROR;
594                 lpfc_hba_down_post(phba);
595         }
596 }
597
598 /************************************************************************/
599 /*                                                                      */
600 /*    lpfc_handle_eratt                                                 */
601 /*    This routine will handle processing a Host Attention              */
602 /*    Error Status event. This will be initialized                      */
603 /*    as a SLI layer callback routine.                                  */
604 /*                                                                      */
605 /************************************************************************/
606 void
607 lpfc_handle_eratt(struct lpfc_hba *phba)
608 {
609         struct lpfc_vport *vport = phba->pport;
610         struct lpfc_sli   *psli = &phba->sli;
611         struct lpfc_sli_ring  *pring;
612         struct lpfc_vport **vports;
613         uint32_t event_data;
614         struct Scsi_Host  *shost;
615         int i;
616
617         /* If the pci channel is offline, ignore possible errors,
618          * since we cannot communicate with the pci card anyway. */
619         if (pci_channel_offline(phba->pcidev))
620                 return;
621
622         if (phba->work_hs & HS_FFER6 ||
623             phba->work_hs & HS_FFER5) {
624                 /* Re-establishing Link */
625                 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
626                                 "1301 Re-establishing Link "
627                                 "Data: x%x x%x x%x\n",
628                                 phba->work_hs,
629                                 phba->work_status[0], phba->work_status[1]);
630                 vports = lpfc_create_vport_work_array(phba);
631                 if (vports != NULL)
632                         for(i = 0;
633                             i < LPFC_MAX_VPORTS && vports[i] != NULL;
634                             i++){
635                                 shost = lpfc_shost_from_vport(vports[i]);
636                                 spin_lock_irq(shost->host_lock);
637                                 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
638                                 spin_unlock_irq(shost->host_lock);
639                         }
640                 lpfc_destroy_vport_work_array(vports);
641                 spin_lock_irq(&phba->hbalock);
642                 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
643                 spin_unlock_irq(&phba->hbalock);
644
645                 /*
646                 * Firmware stops when it triggled erratt with HS_FFER6.
647                 * That could cause the I/Os dropped by the firmware.
648                 * Error iocb (I/O) on txcmplq and let the SCSI layer
649                 * retry it after re-establishing link.
650                 */
651                 pring = &psli->ring[psli->fcp_ring];
652                 lpfc_sli_abort_iocb_ring(phba, pring);
653
654
655                 /*
656                  * There was a firmware error.  Take the hba offline and then
657                  * attempt to restart it.
658                  */
659                 lpfc_offline_prep(phba);
660                 lpfc_offline(phba);
661                 lpfc_sli_brdrestart(phba);
662                 if (lpfc_online(phba) == 0) {   /* Initialize the HBA */
663                         mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
664                         lpfc_unblock_mgmt_io(phba);
665                         return;
666                 }
667                 lpfc_unblock_mgmt_io(phba);
668         } else {
669                 /* The if clause above forces this code path when the status
670                  * failure is a value other than FFER6.  Do not call the offline
671                  *  twice. This is the adapter hardware error path.
672                  */
673                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
674                                 "0457 Adapter Hardware Error "
675                                 "Data: x%x x%x x%x\n",
676                                 phba->work_hs,
677                                 phba->work_status[0], phba->work_status[1]);
678
679                 event_data = FC_REG_DUMP_EVENT;
680                 shost = lpfc_shost_from_vport(vport);
681                 fc_host_post_vendor_event(shost, fc_get_event_number(),
682                                 sizeof(event_data), (char *) &event_data,
683                                 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
684
685                 spin_lock_irq(&phba->hbalock);
686                 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
687                 spin_unlock_irq(&phba->hbalock);
688                 lpfc_offline_prep(phba);
689                 lpfc_offline(phba);
690                 lpfc_unblock_mgmt_io(phba);
691                 phba->link_state = LPFC_HBA_ERROR;
692                 lpfc_hba_down_post(phba);
693         }
694 }
695
696 /************************************************************************/
697 /*                                                                      */
698 /*    lpfc_handle_latt                                                  */
699 /*    This routine will handle processing a Host Attention              */
700 /*    Link Status event. This will be initialized                       */
701 /*    as a SLI layer callback routine.                                  */
702 /*                                                                      */
703 /************************************************************************/
704 void
705 lpfc_handle_latt(struct lpfc_hba *phba)
706 {
707         struct lpfc_vport *vport = phba->pport;
708         struct lpfc_sli   *psli = &phba->sli;
709         LPFC_MBOXQ_t *pmb;
710         volatile uint32_t control;
711         struct lpfc_dmabuf *mp;
712         int rc = -ENOMEM;
713
714         pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
715         if (!pmb)
716                 goto lpfc_handle_latt_err_exit;
717
718         mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
719         if (!mp)
720                 goto lpfc_handle_latt_free_pmb;
721
722         mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
723         if (!mp->virt)
724                 goto lpfc_handle_latt_free_mp;
725
726         rc = -EIO;
727
728         /* Cleanup any outstanding ELS commands */
729         lpfc_els_flush_all_cmd(phba);
730
731         psli->slistat.link_event++;
732         lpfc_read_la(phba, pmb, mp);
733         pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
734         pmb->vport = vport;
735         rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
736         if (rc == MBX_NOT_FINISHED)
737                 goto lpfc_handle_latt_free_mbuf;
738
739         /* Clear Link Attention in HA REG */
740         spin_lock_irq(&phba->hbalock);
741         writel(HA_LATT, phba->HAregaddr);
742         readl(phba->HAregaddr); /* flush */
743         spin_unlock_irq(&phba->hbalock);
744
745         return;
746
747 lpfc_handle_latt_free_mbuf:
748         lpfc_mbuf_free(phba, mp->virt, mp->phys);
749 lpfc_handle_latt_free_mp:
750         kfree(mp);
751 lpfc_handle_latt_free_pmb:
752         mempool_free(pmb, phba->mbox_mem_pool);
753 lpfc_handle_latt_err_exit:
754         /* Enable Link attention interrupts */
755         spin_lock_irq(&phba->hbalock);
756         psli->sli_flag |= LPFC_PROCESS_LA;
757         control = readl(phba->HCregaddr);
758         control |= HC_LAINT_ENA;
759         writel(control, phba->HCregaddr);
760         readl(phba->HCregaddr); /* flush */
761
762         /* Clear Link Attention in HA REG */
763         writel(HA_LATT, phba->HAregaddr);
764         readl(phba->HAregaddr); /* flush */
765         spin_unlock_irq(&phba->hbalock);
766         lpfc_linkdown(phba);
767         phba->link_state = LPFC_HBA_ERROR;
768
769         /* The other case is an error from issue_mbox */
770         if (rc == -ENOMEM)
771                 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
772                                 "0300 READ_LA: no buffers\n");
773
774         return;
775 }
776
777 /************************************************************************/
778 /*                                                                      */
779 /*   lpfc_parse_vpd                                                     */
780 /*   This routine will parse the VPD data                               */
781 /*                                                                      */
782 /************************************************************************/
783 static int
784 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
785 {
786         uint8_t lenlo, lenhi;
787         int Length;
788         int i, j;
789         int finished = 0;
790         int index = 0;
791
792         if (!vpd)
793                 return 0;
794
795         /* Vital Product */
796         lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
797                         "0455 Vital Product Data: x%x x%x x%x x%x\n",
798                         (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
799                         (uint32_t) vpd[3]);
800         while (!finished && (index < (len - 4))) {
801                 switch (vpd[index]) {
802                 case 0x82:
803                 case 0x91:
804                         index += 1;
805                         lenlo = vpd[index];
806                         index += 1;
807                         lenhi = vpd[index];
808                         index += 1;
809                         i = ((((unsigned short)lenhi) << 8) + lenlo);
810                         index += i;
811                         break;
812                 case 0x90:
813                         index += 1;
814                         lenlo = vpd[index];
815                         index += 1;
816                         lenhi = vpd[index];
817                         index += 1;
818                         Length = ((((unsigned short)lenhi) << 8) + lenlo);
819                         if (Length > len - index)
820                                 Length = len - index;
821                         while (Length > 0) {
822                         /* Look for Serial Number */
823                         if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
824                                 index += 2;
825                                 i = vpd[index];
826                                 index += 1;
827                                 j = 0;
828                                 Length -= (3+i);
829                                 while(i--) {
830                                         phba->SerialNumber[j++] = vpd[index++];
831                                         if (j == 31)
832                                                 break;
833                                 }
834                                 phba->SerialNumber[j] = 0;
835                                 continue;
836                         }
837                         else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
838                                 phba->vpd_flag |= VPD_MODEL_DESC;
839                                 index += 2;
840                                 i = vpd[index];
841                                 index += 1;
842                                 j = 0;
843                                 Length -= (3+i);
844                                 while(i--) {
845                                         phba->ModelDesc[j++] = vpd[index++];
846                                         if (j == 255)
847                                                 break;
848                                 }
849                                 phba->ModelDesc[j] = 0;
850                                 continue;
851                         }
852                         else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
853                                 phba->vpd_flag |= VPD_MODEL_NAME;
854                                 index += 2;
855                                 i = vpd[index];
856                                 index += 1;
857                                 j = 0;
858                                 Length -= (3+i);
859                                 while(i--) {
860                                         phba->ModelName[j++] = vpd[index++];
861                                         if (j == 79)
862                                                 break;
863                                 }
864                                 phba->ModelName[j] = 0;
865                                 continue;
866                         }
867                         else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
868                                 phba->vpd_flag |= VPD_PROGRAM_TYPE;
869                                 index += 2;
870                                 i = vpd[index];
871                                 index += 1;
872                                 j = 0;
873                                 Length -= (3+i);
874                                 while(i--) {
875                                         phba->ProgramType[j++] = vpd[index++];
876                                         if (j == 255)
877                                                 break;
878                                 }
879                                 phba->ProgramType[j] = 0;
880                                 continue;
881                         }
882                         else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
883                                 phba->vpd_flag |= VPD_PORT;
884                                 index += 2;
885                                 i = vpd[index];
886                                 index += 1;
887                                 j = 0;
888                                 Length -= (3+i);
889                                 while(i--) {
890                                 phba->Port[j++] = vpd[index++];
891                                 if (j == 19)
892                                         break;
893                                 }
894                                 phba->Port[j] = 0;
895                                 continue;
896                         }
897                         else {
898                                 index += 2;
899                                 i = vpd[index];
900                                 index += 1;
901                                 index += i;
902                                 Length -= (3 + i);
903                         }
904                 }
905                 finished = 0;
906                 break;
907                 case 0x78:
908                         finished = 1;
909                         break;
910                 default:
911                         index ++;
912                         break;
913                 }
914         }
915
916         return(1);
917 }
918
919 static void
920 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
921 {
922         lpfc_vpd_t *vp;
923         uint16_t dev_id = phba->pcidev->device;
924         int max_speed;
925         struct {
926                 char * name;
927                 int    max_speed;
928                 char * bus;
929         } m = {"<Unknown>", 0, ""};
930
931         if (mdp && mdp[0] != '\0'
932                 && descp && descp[0] != '\0')
933                 return;
934
935         if (phba->lmt & LMT_10Gb)
936                 max_speed = 10;
937         else if (phba->lmt & LMT_8Gb)
938                 max_speed = 8;
939         else if (phba->lmt & LMT_4Gb)
940                 max_speed = 4;
941         else if (phba->lmt & LMT_2Gb)
942                 max_speed = 2;
943         else
944                 max_speed = 1;
945
946         vp = &phba->vpd;
947
948         switch (dev_id) {
949         case PCI_DEVICE_ID_FIREFLY:
950                 m = (typeof(m)){"LP6000", max_speed, "PCI"};
951                 break;
952         case PCI_DEVICE_ID_SUPERFLY:
953                 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
954                         m = (typeof(m)){"LP7000", max_speed,  "PCI"};
955                 else
956                         m = (typeof(m)){"LP7000E", max_speed, "PCI"};
957                 break;
958         case PCI_DEVICE_ID_DRAGONFLY:
959                 m = (typeof(m)){"LP8000", max_speed, "PCI"};
960                 break;
961         case PCI_DEVICE_ID_CENTAUR:
962                 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
963                         m = (typeof(m)){"LP9002", max_speed, "PCI"};
964                 else
965                         m = (typeof(m)){"LP9000", max_speed, "PCI"};
966                 break;
967         case PCI_DEVICE_ID_RFLY:
968                 m = (typeof(m)){"LP952", max_speed, "PCI"};
969                 break;
970         case PCI_DEVICE_ID_PEGASUS:
971                 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
972                 break;
973         case PCI_DEVICE_ID_THOR:
974                 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
975                 break;
976         case PCI_DEVICE_ID_VIPER:
977                 m = (typeof(m)){"LPX1000", max_speed,  "PCI-X"};
978                 break;
979         case PCI_DEVICE_ID_PFLY:
980                 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
981                 break;
982         case PCI_DEVICE_ID_TFLY:
983                 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
984                 break;
985         case PCI_DEVICE_ID_HELIOS:
986                 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
987                 break;
988         case PCI_DEVICE_ID_HELIOS_SCSP:
989                 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
990                 break;
991         case PCI_DEVICE_ID_HELIOS_DCSP:
992                 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
993                 break;
994         case PCI_DEVICE_ID_NEPTUNE:
995                 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
996                 break;
997         case PCI_DEVICE_ID_NEPTUNE_SCSP:
998                 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
999                 break;
1000         case PCI_DEVICE_ID_NEPTUNE_DCSP:
1001                 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
1002                 break;
1003         case PCI_DEVICE_ID_BMID:
1004                 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
1005                 break;
1006         case PCI_DEVICE_ID_BSMB:
1007                 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
1008                 break;
1009         case PCI_DEVICE_ID_ZEPHYR:
1010                 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1011                 break;
1012         case PCI_DEVICE_ID_ZEPHYR_SCSP:
1013                 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1014                 break;
1015         case PCI_DEVICE_ID_ZEPHYR_DCSP:
1016                 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
1017                 break;
1018         case PCI_DEVICE_ID_ZMID:
1019                 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
1020                 break;
1021         case PCI_DEVICE_ID_ZSMB:
1022                 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
1023                 break;
1024         case PCI_DEVICE_ID_LP101:
1025                 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
1026                 break;
1027         case PCI_DEVICE_ID_LP10000S:
1028                 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
1029                 break;
1030         case PCI_DEVICE_ID_LP11000S:
1031                 m = (typeof(m)){"LP11000-S", max_speed,
1032                         "PCI-X2"};
1033                 break;
1034         case PCI_DEVICE_ID_LPE11000S:
1035                 m = (typeof(m)){"LPe11000-S", max_speed,
1036                         "PCIe"};
1037                 break;
1038         case PCI_DEVICE_ID_SAT:
1039                 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1040                 break;
1041         case PCI_DEVICE_ID_SAT_MID:
1042                 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1043                 break;
1044         case PCI_DEVICE_ID_SAT_SMB:
1045                 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1046                 break;
1047         case PCI_DEVICE_ID_SAT_DCSP:
1048                 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1049                 break;
1050         case PCI_DEVICE_ID_SAT_SCSP:
1051                 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1052                 break;
1053         case PCI_DEVICE_ID_SAT_S:
1054                 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1055                 break;
1056         default:
1057                 m = (typeof(m)){ NULL };
1058                 break;
1059         }
1060
1061         if (mdp && mdp[0] == '\0')
1062                 snprintf(mdp, 79,"%s", m.name);
1063         if (descp && descp[0] == '\0')
1064                 snprintf(descp, 255,
1065                          "Emulex %s %dGb %s Fibre Channel Adapter",
1066                          m.name, m.max_speed, m.bus);
1067 }
1068
1069 /**************************************************/
1070 /*   lpfc_post_buffer                             */
1071 /*                                                */
1072 /*   This routine will post count buffers to the  */
1073 /*   ring with the QUE_RING_BUF_CN command. This  */
1074 /*   allows 3 buffers / command to be posted.     */
1075 /*   Returns the number of buffers NOT posted.    */
1076 /**************************************************/
1077 int
1078 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
1079                  int type)
1080 {
1081         IOCB_t *icmd;
1082         struct lpfc_iocbq *iocb;
1083         struct lpfc_dmabuf *mp1, *mp2;
1084
1085         cnt += pring->missbufcnt;
1086
1087         /* While there are buffers to post */
1088         while (cnt > 0) {
1089                 /* Allocate buffer for  command iocb */
1090                 iocb = lpfc_sli_get_iocbq(phba);
1091                 if (iocb == NULL) {
1092                         pring->missbufcnt = cnt;
1093                         return cnt;
1094                 }
1095                 icmd = &iocb->iocb;
1096
1097                 /* 2 buffers can be posted per command */
1098                 /* Allocate buffer to post */
1099                 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1100                 if (mp1)
1101                     mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1102                                                 &mp1->phys);
1103                 if (mp1 == 0 || mp1->virt == 0) {
1104                         kfree(mp1);
1105                         lpfc_sli_release_iocbq(phba, iocb);
1106                         pring->missbufcnt = cnt;
1107                         return cnt;
1108                 }
1109
1110                 INIT_LIST_HEAD(&mp1->list);
1111                 /* Allocate buffer to post */
1112                 if (cnt > 1) {
1113                         mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1114                         if (mp2)
1115                                 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1116                                                             &mp2->phys);
1117                         if (mp2 == 0 || mp2->virt == 0) {
1118                                 kfree(mp2);
1119                                 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1120                                 kfree(mp1);
1121                                 lpfc_sli_release_iocbq(phba, iocb);
1122                                 pring->missbufcnt = cnt;
1123                                 return cnt;
1124                         }
1125
1126                         INIT_LIST_HEAD(&mp2->list);
1127                 } else {
1128                         mp2 = NULL;
1129                 }
1130
1131                 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1132                 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1133                 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1134                 icmd->ulpBdeCount = 1;
1135                 cnt--;
1136                 if (mp2) {
1137                         icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1138                         icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1139                         icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1140                         cnt--;
1141                         icmd->ulpBdeCount = 2;
1142                 }
1143
1144                 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1145                 icmd->ulpLe = 1;
1146
1147                 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1148                         lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1149                         kfree(mp1);
1150                         cnt++;
1151                         if (mp2) {
1152                                 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1153                                 kfree(mp2);
1154                                 cnt++;
1155                         }
1156                         lpfc_sli_release_iocbq(phba, iocb);
1157                         pring->missbufcnt = cnt;
1158                         return cnt;
1159                 }
1160                 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1161                 if (mp2)
1162                         lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1163         }
1164         pring->missbufcnt = 0;
1165         return 0;
1166 }
1167
1168 /************************************************************************/
1169 /*                                                                      */
1170 /*   lpfc_post_rcv_buf                                                  */
1171 /*   This routine post initial rcv buffers to the configured rings      */
1172 /*                                                                      */
1173 /************************************************************************/
1174 static int
1175 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1176 {
1177         struct lpfc_sli *psli = &phba->sli;
1178
1179         /* Ring 0, ELS / CT buffers */
1180         lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1181         /* Ring 2 - FCP no buffers needed */
1182
1183         return 0;
1184 }
1185
1186 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1187
1188 /************************************************************************/
1189 /*                                                                      */
1190 /*   lpfc_sha_init                                                      */
1191 /*                                                                      */
1192 /************************************************************************/
1193 static void
1194 lpfc_sha_init(uint32_t * HashResultPointer)
1195 {
1196         HashResultPointer[0] = 0x67452301;
1197         HashResultPointer[1] = 0xEFCDAB89;
1198         HashResultPointer[2] = 0x98BADCFE;
1199         HashResultPointer[3] = 0x10325476;
1200         HashResultPointer[4] = 0xC3D2E1F0;
1201 }
1202
1203 /************************************************************************/
1204 /*                                                                      */
1205 /*   lpfc_sha_iterate                                                   */
1206 /*                                                                      */
1207 /************************************************************************/
1208 static void
1209 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1210 {
1211         int t;
1212         uint32_t TEMP;
1213         uint32_t A, B, C, D, E;
1214         t = 16;
1215         do {
1216                 HashWorkingPointer[t] =
1217                     S(1,
1218                       HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1219                                                                      8] ^
1220                       HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1221         } while (++t <= 79);
1222         t = 0;
1223         A = HashResultPointer[0];
1224         B = HashResultPointer[1];
1225         C = HashResultPointer[2];
1226         D = HashResultPointer[3];
1227         E = HashResultPointer[4];
1228
1229         do {
1230                 if (t < 20) {
1231                         TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1232                 } else if (t < 40) {
1233                         TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1234                 } else if (t < 60) {
1235                         TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1236                 } else {
1237                         TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1238                 }
1239                 TEMP += S(5, A) + E + HashWorkingPointer[t];
1240                 E = D;
1241                 D = C;
1242                 C = S(30, B);
1243                 B = A;
1244                 A = TEMP;
1245         } while (++t <= 79);
1246
1247         HashResultPointer[0] += A;
1248         HashResultPointer[1] += B;
1249         HashResultPointer[2] += C;
1250         HashResultPointer[3] += D;
1251         HashResultPointer[4] += E;
1252
1253 }
1254
1255 /************************************************************************/
1256 /*                                                                      */
1257 /*   lpfc_challenge_key                                                 */
1258 /*                                                                      */
1259 /************************************************************************/
1260 static void
1261 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1262 {
1263         *HashWorking = (*RandomChallenge ^ *HashWorking);
1264 }
1265
1266 /************************************************************************/
1267 /*                                                                      */
1268 /*   lpfc_hba_init                                                      */
1269 /*                                                                      */
1270 /************************************************************************/
1271 void
1272 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1273 {
1274         int t;
1275         uint32_t *HashWorking;
1276         uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1277
1278         HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1279         if (!HashWorking)
1280                 return;
1281
1282         memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1283         HashWorking[0] = HashWorking[78] = *pwwnn++;
1284         HashWorking[1] = HashWorking[79] = *pwwnn;
1285
1286         for (t = 0; t < 7; t++)
1287                 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1288
1289         lpfc_sha_init(hbainit);
1290         lpfc_sha_iterate(hbainit, HashWorking);
1291         kfree(HashWorking);
1292 }
1293
1294 static void
1295 lpfc_cleanup(struct lpfc_vport *vport)
1296 {
1297         struct lpfc_nodelist *ndlp, *next_ndlp;
1298
1299         /* clean up phba - lpfc specific */
1300         lpfc_can_disctmo(vport);
1301         list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1302                 lpfc_nlp_put(ndlp);
1303         return;
1304 }
1305
1306 static void
1307 lpfc_establish_link_tmo(unsigned long ptr)
1308 {
1309         struct lpfc_hba   *phba = (struct lpfc_hba *) ptr;
1310         struct lpfc_vport **vports;
1311         unsigned long iflag;
1312         int i;
1313
1314         /* Re-establishing Link, timer expired */
1315         lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1316                         "1300 Re-establishing Link, timer expired "
1317                         "Data: x%x x%x\n",
1318                         phba->pport->fc_flag, phba->pport->port_state);
1319         vports = lpfc_create_vport_work_array(phba);
1320         if (vports != NULL)
1321                 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1322                         struct Scsi_Host *shost;
1323                         shost = lpfc_shost_from_vport(vports[i]);
1324                         spin_lock_irqsave(shost->host_lock, iflag);
1325                         vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1326                         spin_unlock_irqrestore(shost->host_lock, iflag);
1327                 }
1328         lpfc_destroy_vport_work_array(vports);
1329 }
1330
1331 void
1332 lpfc_stop_vport_timers(struct lpfc_vport *vport)
1333 {
1334         del_timer_sync(&vport->els_tmofunc);
1335         del_timer_sync(&vport->fc_fdmitmo);
1336         lpfc_can_disctmo(vport);
1337         return;
1338 }
1339
1340 static void
1341 lpfc_stop_phba_timers(struct lpfc_hba *phba)
1342 {
1343         struct lpfc_vport **vports;
1344         int i;
1345
1346         del_timer_sync(&phba->fcp_poll_timer);
1347         del_timer_sync(&phba->fc_estabtmo);
1348         vports = lpfc_create_vport_work_array(phba);
1349         if (vports != NULL)
1350                 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
1351                         lpfc_stop_vport_timers(vports[i]);
1352         lpfc_destroy_vport_work_array(vports);
1353         del_timer_sync(&phba->sli.mbox_tmo);
1354         del_timer_sync(&phba->fabric_block_timer);
1355         phba->hb_outstanding = 0;
1356         del_timer_sync(&phba->hb_tmofunc);
1357         return;
1358 }
1359
1360 int
1361 lpfc_online(struct lpfc_hba *phba)
1362 {
1363         struct lpfc_vport *vport = phba->pport;
1364         struct lpfc_vport **vports;
1365         int i;
1366
1367         if (!phba)
1368                 return 0;
1369
1370         if (!(vport->fc_flag & FC_OFFLINE_MODE))
1371                 return 0;
1372
1373         lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1374                         "0458 Bring Adapter online\n");
1375
1376         lpfc_block_mgmt_io(phba);
1377
1378         if (!lpfc_sli_queue_setup(phba)) {
1379                 lpfc_unblock_mgmt_io(phba);
1380                 return 1;
1381         }
1382
1383         if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1384                 lpfc_unblock_mgmt_io(phba);
1385                 return 1;
1386         }
1387
1388         vports = lpfc_create_vport_work_array(phba);
1389         if (vports != NULL)
1390                 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1391                         struct Scsi_Host *shost;
1392                         shost = lpfc_shost_from_vport(vports[i]);
1393                         spin_lock_irq(shost->host_lock);
1394                         vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1395                         if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1396                                 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1397                         spin_unlock_irq(shost->host_lock);
1398                 }
1399                 lpfc_destroy_vport_work_array(vports);
1400
1401         lpfc_unblock_mgmt_io(phba);
1402         return 0;
1403 }
1404
1405 void
1406 lpfc_block_mgmt_io(struct lpfc_hba * phba)
1407 {
1408         unsigned long iflag;
1409
1410         spin_lock_irqsave(&phba->hbalock, iflag);
1411         phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1412         spin_unlock_irqrestore(&phba->hbalock, iflag);
1413 }
1414
1415 void
1416 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1417 {
1418         unsigned long iflag;
1419
1420         spin_lock_irqsave(&phba->hbalock, iflag);
1421         phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1422         spin_unlock_irqrestore(&phba->hbalock, iflag);
1423 }
1424
1425 void
1426 lpfc_offline_prep(struct lpfc_hba * phba)
1427 {
1428         struct lpfc_vport *vport = phba->pport;
1429         struct lpfc_nodelist  *ndlp, *next_ndlp;
1430
1431         if (vport->fc_flag & FC_OFFLINE_MODE)
1432                 return;
1433
1434         lpfc_block_mgmt_io(phba);
1435
1436         lpfc_linkdown(phba);
1437
1438         /* Issue an unreg_login to all nodes */
1439         list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1440                 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
1441                         lpfc_unreg_rpi(vport, ndlp);
1442
1443         lpfc_sli_flush_mbox_queue(phba);
1444 }
1445
1446 void
1447 lpfc_offline(struct lpfc_hba *phba)
1448 {
1449         struct Scsi_Host  *shost;
1450         struct lpfc_vport **vports;
1451         int i;
1452
1453         if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1454                 return;
1455
1456         /* stop all timers associated with this hba */
1457         lpfc_stop_phba_timers(phba);
1458         lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1459                         "0460 Bring Adapter offline\n");
1460         /* Bring down the SLI Layer and cleanup.  The HBA is offline
1461            now.  */
1462         lpfc_sli_hba_down(phba);
1463         spin_lock_irq(&phba->hbalock);
1464         phba->work_ha = 0;
1465         spin_unlock_irq(&phba->hbalock);
1466         vports = lpfc_create_vport_work_array(phba);
1467         if (vports != NULL)
1468                 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1469                         shost = lpfc_shost_from_vport(vports[i]);
1470                         lpfc_cleanup(vports[i]);
1471                         spin_lock_irq(shost->host_lock);
1472                         vports[i]->work_port_events = 0;
1473                         vports[i]->fc_flag |= FC_OFFLINE_MODE;
1474                         spin_unlock_irq(shost->host_lock);
1475                 }
1476         lpfc_destroy_vport_work_array(vports);
1477 }
1478
1479 /******************************************************************************
1480 * Function name: lpfc_scsi_free
1481 *
1482 * Description: Called from lpfc_pci_remove_one free internal driver resources
1483 *
1484 ******************************************************************************/
1485 static int
1486 lpfc_scsi_free(struct lpfc_hba *phba)
1487 {
1488         struct lpfc_scsi_buf *sb, *sb_next;
1489         struct lpfc_iocbq *io, *io_next;
1490
1491         spin_lock_irq(&phba->hbalock);
1492         /* Release all the lpfc_scsi_bufs maintained by this host. */
1493         list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1494                 list_del(&sb->list);
1495                 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1496                               sb->dma_handle);
1497                 kfree(sb);
1498                 phba->total_scsi_bufs--;
1499         }
1500
1501         /* Release all the lpfc_iocbq entries maintained by this host. */
1502         list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1503                 list_del(&io->list);
1504                 kfree(io);
1505                 phba->total_iocbq_bufs--;
1506         }
1507
1508         spin_unlock_irq(&phba->hbalock);
1509
1510         return 0;
1511 }
1512
1513 struct lpfc_vport *
1514 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
1515 {
1516         struct lpfc_vport *vport;
1517         struct Scsi_Host  *shost;
1518         int error = 0;
1519
1520         if (dev != &phba->pcidev->dev)
1521                 shost = scsi_host_alloc(&lpfc_vport_template,
1522                                         sizeof(struct lpfc_vport));
1523         else
1524                 shost = scsi_host_alloc(&lpfc_template,
1525                                         sizeof(struct lpfc_vport));
1526         if (!shost)
1527                 goto out;
1528
1529         vport = (struct lpfc_vport *) shost->hostdata;
1530         vport->phba = phba;
1531
1532         vport->load_flag |= FC_LOADING;
1533         vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1534
1535         lpfc_get_vport_cfgparam(vport);
1536         shost->unique_id = instance;
1537         shost->max_id = LPFC_MAX_TARGET;
1538         shost->max_lun = vport->cfg_max_luns;
1539         shost->this_id = -1;
1540         shost->max_cmd_len = 16;
1541         /*
1542          * Set initial can_queue value since 0 is no longer supported and
1543          * scsi_add_host will fail. This will be adjusted later based on the
1544          * max xri value determined in hba setup.
1545          */
1546         shost->can_queue = phba->cfg_hba_queue_depth - 10;
1547         if (dev != &phba->pcidev->dev) {
1548                 shost->transportt = lpfc_vport_transport_template;
1549                 vport->port_type = LPFC_NPIV_PORT;
1550         } else {
1551                 shost->transportt = lpfc_transport_template;
1552                 vport->port_type = LPFC_PHYSICAL_PORT;
1553         }
1554
1555         /* Initialize all internally managed lists. */
1556         INIT_LIST_HEAD(&vport->fc_nodes);
1557         spin_lock_init(&vport->work_port_lock);
1558
1559         init_timer(&vport->fc_disctmo);
1560         vport->fc_disctmo.function = lpfc_disc_timeout;
1561         vport->fc_disctmo.data = (unsigned long)vport;
1562
1563         init_timer(&vport->fc_fdmitmo);
1564         vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1565         vport->fc_fdmitmo.data = (unsigned long)vport;
1566
1567         init_timer(&vport->els_tmofunc);
1568         vport->els_tmofunc.function = lpfc_els_timeout;
1569         vport->els_tmofunc.data = (unsigned long)vport;
1570
1571         error = scsi_add_host(shost, dev);
1572         if (error)
1573                 goto out_put_shost;
1574
1575         spin_lock_irq(&phba->hbalock);
1576         list_add_tail(&vport->listentry, &phba->port_list);
1577         spin_unlock_irq(&phba->hbalock);
1578         return vport;
1579
1580 out_put_shost:
1581         scsi_host_put(shost);
1582 out:
1583         return NULL;
1584 }
1585
1586 void
1587 destroy_port(struct lpfc_vport *vport)
1588 {
1589         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1590         struct lpfc_hba  *phba = vport->phba;
1591
1592         kfree(vport->vname);
1593
1594         lpfc_debugfs_terminate(vport);
1595         fc_remove_host(shost);
1596         scsi_remove_host(shost);
1597
1598         spin_lock_irq(&phba->hbalock);
1599         list_del_init(&vport->listentry);
1600         spin_unlock_irq(&phba->hbalock);
1601
1602         lpfc_cleanup(vport);
1603         return;
1604 }
1605
1606 int
1607 lpfc_get_instance(void)
1608 {
1609         int instance = 0;
1610
1611         /* Assign an unused number */
1612         if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1613                 return -1;
1614         if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1615                 return -1;
1616         return instance;
1617 }
1618
1619 /*
1620  * Note: there is no scan_start function as adapter initialization
1621  * will have asynchronously kicked off the link initialization.
1622  */
1623
1624 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1625 {
1626         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1627         struct lpfc_hba   *phba = vport->phba;
1628         int stat = 0;
1629
1630         spin_lock_irq(shost->host_lock);
1631
1632         if (vport->fc_flag & FC_UNLOADING) {
1633                 stat = 1;
1634                 goto finished;
1635         }
1636         if (time >= 30 * HZ) {
1637                 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1638                                 "0461 Scanning longer than 30 "
1639                                 "seconds.  Continuing initialization\n");
1640                 stat = 1;
1641                 goto finished;
1642         }
1643         if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1644                 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1645                                 "0465 Link down longer than 15 "
1646                                 "seconds.  Continuing initialization\n");
1647                 stat = 1;
1648                 goto finished;
1649         }
1650
1651         if (vport->port_state != LPFC_VPORT_READY)
1652                 goto finished;
1653         if (vport->num_disc_nodes || vport->fc_prli_sent)
1654                 goto finished;
1655         if (vport->fc_map_cnt == 0 && time < 2 * HZ)
1656                 goto finished;
1657         if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
1658                 goto finished;
1659
1660         stat = 1;
1661
1662 finished:
1663         spin_unlock_irq(shost->host_lock);
1664         return stat;
1665 }
1666
1667 void lpfc_host_attrib_init(struct Scsi_Host *shost)
1668 {
1669         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1670         struct lpfc_hba   *phba = vport->phba;
1671         /*
1672          * Set fixed host attributes.  Must done after lpfc_sli_hba_setup().
1673          */
1674
1675         fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1676         fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
1677         fc_host_supported_classes(shost) = FC_COS_CLASS3;
1678
1679         memset(fc_host_supported_fc4s(shost), 0,
1680                sizeof(fc_host_supported_fc4s(shost)));
1681         fc_host_supported_fc4s(shost)[2] = 1;
1682         fc_host_supported_fc4s(shost)[7] = 1;
1683
1684         lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1685                                  sizeof fc_host_symbolic_name(shost));
1686
1687         fc_host_supported_speeds(shost) = 0;
1688         if (phba->lmt & LMT_10Gb)
1689                 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1690         if (phba->lmt & LMT_4Gb)
1691                 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1692         if (phba->lmt & LMT_2Gb)
1693                 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1694         if (phba->lmt & LMT_1Gb)
1695                 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1696
1697         fc_host_maxframe_size(shost) =
1698                 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1699                 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
1700
1701         /* This value is also unchanging */
1702         memset(fc_host_active_fc4s(shost), 0,
1703                sizeof(fc_host_active_fc4s(shost)));
1704         fc_host_active_fc4s(shost)[2] = 1;
1705         fc_host_active_fc4s(shost)[7] = 1;
1706
1707         fc_host_max_npiv_vports(shost) = phba->max_vpi;
1708         spin_lock_irq(shost->host_lock);
1709         vport->fc_flag &= ~FC_LOADING;
1710         spin_unlock_irq(shost->host_lock);
1711 }
1712
1713 static int __devinit
1714 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1715 {
1716         struct lpfc_vport *vport = NULL;
1717         struct lpfc_hba   *phba;
1718         struct lpfc_sli   *psli;
1719         struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1720         struct Scsi_Host  *shost = NULL;
1721         unsigned long bar0map_len, bar2map_len;
1722         int error = -ENODEV;
1723         int i;
1724         uint16_t iotag;
1725
1726         if (pci_enable_device(pdev))
1727                 goto out;
1728         if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1729                 goto out_disable_device;
1730
1731         phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1732         if (!phba)
1733                 goto out_release_regions;
1734
1735         spin_lock_init(&phba->hbalock);
1736
1737         phba->pcidev = pdev;
1738
1739         /* Assign an unused board number */
1740         if ((phba->brd_no = lpfc_get_instance()) < 0)
1741                 goto out_free_phba;
1742
1743         INIT_LIST_HEAD(&phba->port_list);
1744         INIT_LIST_HEAD(&phba->hbq_buffer_list);
1745         /*
1746          * Get all the module params for configuring this host and then
1747          * establish the host.
1748          */
1749         lpfc_get_cfgparam(phba);
1750         phba->max_vpi = LPFC_MAX_VPI;
1751
1752         /* Initialize timers used by driver */
1753         init_timer(&phba->fc_estabtmo);
1754         phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1755         phba->fc_estabtmo.data = (unsigned long)phba;
1756
1757         init_timer(&phba->hb_tmofunc);
1758         phba->hb_tmofunc.function = lpfc_hb_timeout;
1759         phba->hb_tmofunc.data = (unsigned long)phba;
1760
1761         psli = &phba->sli;
1762         init_timer(&psli->mbox_tmo);
1763         psli->mbox_tmo.function = lpfc_mbox_timeout;
1764         psli->mbox_tmo.data = (unsigned long) phba;
1765         init_timer(&phba->fcp_poll_timer);
1766         phba->fcp_poll_timer.function = lpfc_poll_timeout;
1767         phba->fcp_poll_timer.data = (unsigned long) phba;
1768         init_timer(&phba->fabric_block_timer);
1769         phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1770         phba->fabric_block_timer.data = (unsigned long) phba;
1771
1772         pci_set_master(pdev);
1773         pci_try_set_mwi(pdev);
1774
1775         if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1776                 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1777                         goto out_idr_remove;
1778
1779         /*
1780          * Get the bus address of Bar0 and Bar2 and the number of bytes
1781          * required by each mapping.
1782          */
1783         phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1784         bar0map_len        = pci_resource_len(phba->pcidev, 0);
1785
1786         phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1787         bar2map_len        = pci_resource_len(phba->pcidev, 2);
1788
1789         /* Map HBA SLIM to a kernel virtual address. */
1790         phba->slim_memmap_p      = ioremap(phba->pci_bar0_map, bar0map_len);
1791         if (!phba->slim_memmap_p) {
1792                 error = -ENODEV;
1793                 dev_printk(KERN_ERR, &pdev->dev,
1794                            "ioremap failed for SLIM memory.\n");
1795                 goto out_idr_remove;
1796         }
1797
1798         /* Map HBA Control Registers to a kernel virtual address. */
1799         phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
1800         if (!phba->ctrl_regs_memmap_p) {
1801                 error = -ENODEV;
1802                 dev_printk(KERN_ERR, &pdev->dev,
1803                            "ioremap failed for HBA control registers.\n");
1804                 goto out_iounmap_slim;
1805         }
1806
1807         /* Allocate memory for SLI-2 structures */
1808         phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1809                                           &phba->slim2p_mapping, GFP_KERNEL);
1810         if (!phba->slim2p)
1811                 goto out_iounmap;
1812
1813         memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
1814
1815         phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1816                                                  lpfc_sli_hbq_size(),
1817                                                  &phba->hbqslimp.phys,
1818                                                  GFP_KERNEL);
1819         if (!phba->hbqslimp.virt)
1820                 goto out_free_slim;
1821
1822         memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
1823
1824         /* Initialize the SLI Layer to run with lpfc HBAs. */
1825         lpfc_sli_setup(phba);
1826         lpfc_sli_queue_setup(phba);
1827
1828         error = lpfc_mem_alloc(phba);
1829         if (error)
1830                 goto out_free_hbqslimp;
1831
1832         /* Initialize and populate the iocb list per host.  */
1833         INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1834         for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1835                 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1836                 if (iocbq_entry == NULL) {
1837                         printk(KERN_ERR "%s: only allocated %d iocbs of "
1838                                 "expected %d count. Unloading driver.\n",
1839                                 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1840                         error = -ENOMEM;
1841                         goto out_free_iocbq;
1842                 }
1843
1844                 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1845                 if (iotag == 0) {
1846                         kfree (iocbq_entry);
1847                         printk(KERN_ERR "%s: failed to allocate IOTAG. "
1848                                "Unloading driver.\n",
1849                                 __FUNCTION__);
1850                         error = -ENOMEM;
1851                         goto out_free_iocbq;
1852                 }
1853
1854                 spin_lock_irq(&phba->hbalock);
1855                 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1856                 phba->total_iocbq_bufs++;
1857                 spin_unlock_irq(&phba->hbalock);
1858         }
1859
1860         /* Initialize HBA structure */
1861         phba->fc_edtov = FF_DEF_EDTOV;
1862         phba->fc_ratov = FF_DEF_RATOV;
1863         phba->fc_altov = FF_DEF_ALTOV;
1864         phba->fc_arbtov = FF_DEF_ARBTOV;
1865
1866         INIT_LIST_HEAD(&phba->work_list);
1867         phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1868         phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1869
1870         /* Startup the kernel thread for this host adapter. */
1871         phba->worker_thread = kthread_run(lpfc_do_work, phba,
1872                                        "lpfc_worker_%d", phba->brd_no);
1873         if (IS_ERR(phba->worker_thread)) {
1874                 error = PTR_ERR(phba->worker_thread);
1875                 goto out_free_iocbq;
1876         }
1877
1878         /* Initialize the list of scsi buffers used by driver for scsi IO. */
1879         spin_lock_init(&phba->scsi_buf_list_lock);
1880         INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1881
1882         /* Initialize list of fabric iocbs */
1883         INIT_LIST_HEAD(&phba->fabric_iocb_list);
1884
1885         vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
1886         if (!vport)
1887                 goto out_kthread_stop;
1888
1889         shost = lpfc_shost_from_vport(vport);
1890         phba->pport = vport;
1891         lpfc_debugfs_initialize(vport);
1892
1893         pci_set_drvdata(pdev, shost);
1894
1895         if (phba->cfg_use_msi) {
1896                 error = pci_enable_msi(phba->pcidev);
1897                 if (error)
1898                         lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1899                                         "0452 Enable MSI failed, continuing "
1900                                         "with IRQ\n");
1901         }
1902
1903         error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
1904                             LPFC_DRIVER_NAME, phba);
1905         if (error) {
1906                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1907                         "0451 Enable interrupt handler failed\n");
1908                 goto out_disable_msi;
1909         }
1910
1911         phba->MBslimaddr = phba->slim_memmap_p;
1912         phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1913         phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1914         phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1915         phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1916
1917         if (lpfc_alloc_sysfs_attr(vport))
1918                 goto out_free_irq;
1919
1920         if (lpfc_sli_hba_setup(phba))
1921                 goto out_remove_device;
1922
1923         /*
1924          * hba setup may have changed the hba_queue_depth so we need to adjust
1925          * the value of can_queue.
1926          */
1927         shost->can_queue = phba->cfg_hba_queue_depth - 10;
1928
1929         lpfc_host_attrib_init(shost);
1930
1931         if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1932                 spin_lock_irq(shost->host_lock);
1933                 lpfc_poll_start_timer(phba);
1934                 spin_unlock_irq(shost->host_lock);
1935         }
1936
1937         scsi_scan_host(shost);
1938
1939         return 0;
1940
1941 out_remove_device:
1942         lpfc_free_sysfs_attr(vport);
1943         spin_lock_irq(shost->host_lock);
1944         vport->fc_flag |= FC_UNLOADING;
1945         spin_unlock_irq(shost->host_lock);
1946 out_free_irq:
1947         lpfc_stop_phba_timers(phba);
1948         phba->pport->work_port_events = 0;
1949         free_irq(phba->pcidev->irq, phba);
1950 out_disable_msi:
1951         pci_disable_msi(phba->pcidev);
1952         destroy_port(vport);
1953 out_kthread_stop:
1954         kthread_stop(phba->worker_thread);
1955 out_free_iocbq:
1956         list_for_each_entry_safe(iocbq_entry, iocbq_next,
1957                                                 &phba->lpfc_iocb_list, list) {
1958                 kfree(iocbq_entry);
1959                 phba->total_iocbq_bufs--;
1960         }
1961         lpfc_mem_free(phba);
1962 out_free_hbqslimp:
1963         dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
1964                           phba->hbqslimp.phys);
1965 out_free_slim:
1966         dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1967                                                         phba->slim2p_mapping);
1968 out_iounmap:
1969         iounmap(phba->ctrl_regs_memmap_p);
1970 out_iounmap_slim:
1971         iounmap(phba->slim_memmap_p);
1972 out_idr_remove:
1973         idr_remove(&lpfc_hba_index, phba->brd_no);
1974 out_free_phba:
1975         kfree(phba);
1976 out_release_regions:
1977         pci_release_regions(pdev);
1978 out_disable_device:
1979         pci_disable_device(pdev);
1980 out:
1981         pci_set_drvdata(pdev, NULL);
1982         if (shost)
1983                 scsi_host_put(shost);
1984         return error;
1985 }
1986
1987 static void __devexit
1988 lpfc_pci_remove_one(struct pci_dev *pdev)
1989 {
1990         struct Scsi_Host  *shost = pci_get_drvdata(pdev);
1991         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1992         struct lpfc_hba   *phba = vport->phba;
1993         struct lpfc_vport *port_iterator;
1994         spin_lock_irq(&phba->hbalock);
1995         list_for_each_entry(port_iterator, &phba->port_list, listentry)
1996                 port_iterator->load_flag |= FC_UNLOADING;
1997         spin_unlock_irq(&phba->hbalock);
1998
1999         kfree(vport->vname);
2000         lpfc_free_sysfs_attr(vport);
2001
2002         fc_remove_host(shost);
2003         scsi_remove_host(shost);
2004
2005         /*
2006          * Bring down the SLI Layer. This step disable all interrupts,
2007          * clears the rings, discards all mailbox commands, and resets
2008          * the HBA.
2009          */
2010         lpfc_sli_hba_down(phba);
2011         lpfc_sli_brdrestart(phba);
2012
2013         lpfc_stop_phba_timers(phba);
2014         spin_lock_irq(&phba->hbalock);
2015         list_del_init(&vport->listentry);
2016         spin_unlock_irq(&phba->hbalock);
2017
2018         lpfc_debugfs_terminate(vport);
2019         lpfc_cleanup(vport);
2020
2021         kthread_stop(phba->worker_thread);
2022
2023         /* Release the irq reservation */
2024         free_irq(phba->pcidev->irq, phba);
2025         pci_disable_msi(phba->pcidev);
2026
2027         pci_set_drvdata(pdev, NULL);
2028         scsi_host_put(shost);
2029
2030         /*
2031          * Call scsi_free before mem_free since scsi bufs are released to their
2032          * corresponding pools here.
2033          */
2034         lpfc_scsi_free(phba);
2035         lpfc_mem_free(phba);
2036
2037         dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2038                           phba->hbqslimp.phys);
2039
2040         /* Free resources associated with SLI2 interface */
2041         dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2042                           phba->slim2p, phba->slim2p_mapping);
2043
2044         /* unmap adapter SLIM and Control Registers */
2045         iounmap(phba->ctrl_regs_memmap_p);
2046         iounmap(phba->slim_memmap_p);
2047
2048         idr_remove(&lpfc_hba_index, phba->brd_no);
2049
2050         kfree(phba);
2051
2052         pci_release_regions(pdev);
2053         pci_disable_device(pdev);
2054 }
2055
2056 /**
2057  * lpfc_io_error_detected - called when PCI error is detected
2058  * @pdev: Pointer to PCI device
2059  * @state: The current pci conneection state
2060  *
2061  * This function is called after a PCI bus error affecting
2062  * this device has been detected.
2063  */
2064 static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2065                                 pci_channel_state_t state)
2066 {
2067         struct Scsi_Host *host = pci_get_drvdata(pdev);
2068         struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2069         struct lpfc_sli *psli = &phba->sli;
2070         struct lpfc_sli_ring  *pring;
2071
2072         if (state == pci_channel_io_perm_failure)
2073                 return PCI_ERS_RESULT_DISCONNECT;
2074
2075         pci_disable_device(pdev);
2076         /*
2077          * There may be I/Os dropped by the firmware.
2078          * Error iocb (I/O) on txcmplq and let the SCSI layer
2079          * retry it after re-establishing link.
2080          */
2081         pring = &psli->ring[psli->fcp_ring];
2082         lpfc_sli_abort_iocb_ring(phba, pring);
2083
2084         /* Request a slot reset. */
2085         return PCI_ERS_RESULT_NEED_RESET;
2086 }
2087
2088 /**
2089  * lpfc_io_slot_reset - called after the pci bus has been reset.
2090  * @pdev: Pointer to PCI device
2091  *
2092  * Restart the card from scratch, as if from a cold-boot.
2093  */
2094 static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2095 {
2096         struct Scsi_Host *host = pci_get_drvdata(pdev);
2097         struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2098         struct lpfc_sli *psli = &phba->sli;
2099         int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2100
2101         dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2102         if (pci_enable_device_bars(pdev, bars)) {
2103                 printk(KERN_ERR "lpfc: Cannot re-enable "
2104                         "PCI device after reset.\n");
2105                 return PCI_ERS_RESULT_DISCONNECT;
2106         }
2107
2108         pci_set_master(pdev);
2109
2110         /* Re-establishing Link */
2111         spin_lock_irq(host->host_lock);
2112         phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2113         spin_unlock_irq(host->host_lock);
2114
2115         spin_lock_irq(&phba->hbalock);
2116         psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2117         spin_unlock_irq(&phba->hbalock);
2118
2119
2120         /* Take device offline; this will perform cleanup */
2121         lpfc_offline(phba);
2122         lpfc_sli_brdrestart(phba);
2123
2124         return PCI_ERS_RESULT_RECOVERED;
2125 }
2126
2127 /**
2128  * lpfc_io_resume - called when traffic can start flowing again.
2129  * @pdev: Pointer to PCI device
2130  *
2131  * This callback is called when the error recovery driver tells us that
2132  * its OK to resume normal operation.
2133  */
2134 static void lpfc_io_resume(struct pci_dev *pdev)
2135 {
2136         struct Scsi_Host *host = pci_get_drvdata(pdev);
2137         struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2138
2139         if (lpfc_online(phba) == 0) {
2140                 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2141         }
2142 }
2143
2144 static struct pci_device_id lpfc_id_table[] = {
2145         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2146                 PCI_ANY_ID, PCI_ANY_ID, },
2147         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2148                 PCI_ANY_ID, PCI_ANY_ID, },
2149         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2150                 PCI_ANY_ID, PCI_ANY_ID, },
2151         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2152                 PCI_ANY_ID, PCI_ANY_ID, },
2153         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2154                 PCI_ANY_ID, PCI_ANY_ID, },
2155         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2156                 PCI_ANY_ID, PCI_ANY_ID, },
2157         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2158                 PCI_ANY_ID, PCI_ANY_ID, },
2159         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2160                 PCI_ANY_ID, PCI_ANY_ID, },
2161         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2162                 PCI_ANY_ID, PCI_ANY_ID, },
2163         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2164                 PCI_ANY_ID, PCI_ANY_ID, },
2165         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2166                 PCI_ANY_ID, PCI_ANY_ID, },
2167         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2168                 PCI_ANY_ID, PCI_ANY_ID, },
2169         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2170                 PCI_ANY_ID, PCI_ANY_ID, },
2171         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2172                 PCI_ANY_ID, PCI_ANY_ID, },
2173         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2174                 PCI_ANY_ID, PCI_ANY_ID, },
2175         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2176                 PCI_ANY_ID, PCI_ANY_ID, },
2177         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2178                 PCI_ANY_ID, PCI_ANY_ID, },
2179         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2180                 PCI_ANY_ID, PCI_ANY_ID, },
2181         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2182                 PCI_ANY_ID, PCI_ANY_ID, },
2183         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2184                 PCI_ANY_ID, PCI_ANY_ID, },
2185         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2186                 PCI_ANY_ID, PCI_ANY_ID, },
2187         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2188                 PCI_ANY_ID, PCI_ANY_ID, },
2189         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2190                 PCI_ANY_ID, PCI_ANY_ID, },
2191         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2192                 PCI_ANY_ID, PCI_ANY_ID, },
2193         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2194                 PCI_ANY_ID, PCI_ANY_ID, },
2195         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2196                 PCI_ANY_ID, PCI_ANY_ID, },
2197         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2198                 PCI_ANY_ID, PCI_ANY_ID, },
2199         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2200                 PCI_ANY_ID, PCI_ANY_ID, },
2201         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2202                 PCI_ANY_ID, PCI_ANY_ID, },
2203         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2204                 PCI_ANY_ID, PCI_ANY_ID, },
2205         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2206                 PCI_ANY_ID, PCI_ANY_ID, },
2207         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2208                 PCI_ANY_ID, PCI_ANY_ID, },
2209         {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2210                 PCI_ANY_ID, PCI_ANY_ID, },
2211         { 0 }
2212 };
2213
2214 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2215
2216 static struct pci_error_handlers lpfc_err_handler = {
2217         .error_detected = lpfc_io_error_detected,
2218         .slot_reset = lpfc_io_slot_reset,
2219         .resume = lpfc_io_resume,
2220 };
2221
2222 static struct pci_driver lpfc_driver = {
2223         .name           = LPFC_DRIVER_NAME,
2224         .id_table       = lpfc_id_table,
2225         .probe          = lpfc_pci_probe_one,
2226         .remove         = __devexit_p(lpfc_pci_remove_one),
2227         .err_handler    = &lpfc_err_handler,
2228 };
2229
2230 static int __init
2231 lpfc_init(void)
2232 {
2233         int error = 0;
2234
2235         printk(LPFC_MODULE_DESC "\n");
2236         printk(LPFC_COPYRIGHT "\n");
2237
2238         lpfc_transport_template =
2239                                 fc_attach_transport(&lpfc_transport_functions);
2240         lpfc_vport_transport_template =
2241                         fc_attach_transport(&lpfc_vport_transport_functions);
2242         if (!lpfc_transport_template || !lpfc_vport_transport_template)
2243                 return -ENOMEM;
2244         error = pci_register_driver(&lpfc_driver);
2245         if (error) {
2246                 fc_release_transport(lpfc_transport_template);
2247                 fc_release_transport(lpfc_vport_transport_template);
2248         }
2249
2250         return error;
2251 }
2252
2253 static void __exit
2254 lpfc_exit(void)
2255 {
2256         pci_unregister_driver(&lpfc_driver);
2257         fc_release_transport(lpfc_transport_template);
2258         fc_release_transport(lpfc_vport_transport_template);
2259 }
2260
2261 module_init(lpfc_init);
2262 module_exit(lpfc_exit);
2263 MODULE_LICENSE("GPL");
2264 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2265 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2266 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);