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