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