1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_version.h"
46 #include "lpfc_vport.h"
48 static int lpfc_parse_vpd(struct lpfc_hba
*, uint8_t *, int);
49 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
50 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
52 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
53 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
54 static DEFINE_IDR(lpfc_hba_index
);
56 /************************************************************************/
58 /* lpfc_config_port_prep */
59 /* This routine will do LPFC initialization prior to the */
60 /* CONFIG_PORT mailbox command. This will be initialized */
61 /* as a SLI layer callback routine. */
62 /* This routine returns 0 on success or -ERESTART if it wants */
63 /* the SLI layer to reset the HBA and try again. Any */
64 /* other return value indicates an error. */
66 /************************************************************************/
68 lpfc_config_port_prep(struct lpfc_hba
*phba
)
70 lpfc_vpd_t
*vp
= &phba
->vpd
;
74 char *lpfc_vpd_data
= NULL
;
76 static char licensed
[56] =
77 "key unlock for use with gnu public licensed code only\0";
78 static int init_key
= 1;
80 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
82 phba
->link_state
= LPFC_HBA_ERROR
;
87 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
89 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
91 uint32_t *ptext
= (uint32_t *) licensed
;
93 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
94 *ptext
= cpu_to_be32(*ptext
);
98 lpfc_read_nv(phba
, pmb
);
99 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
100 sizeof (mb
->un
.varRDnvp
.rsvd3
));
101 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
104 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
106 if (rc
!= MBX_SUCCESS
) {
107 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
108 "0324 Config Port initialization "
109 "error, mbxCmd x%x READ_NVPARM, "
111 mb
->mbxCommand
, mb
->mbxStatus
);
112 mempool_free(pmb
, phba
->mbox_mem_pool
);
115 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
117 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
121 phba
->sli3_options
= 0x0;
123 /* Setup and issue mailbox READ REV command */
124 lpfc_read_rev(phba
, pmb
);
125 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
126 if (rc
!= MBX_SUCCESS
) {
127 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
128 "0439 Adapter failed to init, mbxCmd x%x "
129 "READ_REV, mbxStatus x%x\n",
130 mb
->mbxCommand
, mb
->mbxStatus
);
131 mempool_free( pmb
, phba
->mbox_mem_pool
);
137 * The value of rr must be 1 since the driver set the cv field to 1.
138 * This setting requires the FW to set all revision fields.
140 if (mb
->un
.varRdRev
.rr
== 0) {
142 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
143 "0440 Adapter failed to init, READ_REV has "
144 "missing revision information.\n");
145 mempool_free(pmb
, phba
->mbox_mem_pool
);
149 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
)
152 /* Save information as VPD data */
154 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
155 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
156 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
157 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
158 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
159 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
160 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
161 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
162 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
163 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
164 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
165 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
166 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
167 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
168 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
170 /* If the sli feature level is less then 9, we must
171 * tear down all RPIs and VPIs on link down if NPIV
174 if (vp
->rev
.feaLevelHigh
< 9)
175 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
177 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
178 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
179 sizeof (phba
->RandomData
));
181 /* Get adapter VPD information */
182 pmb
->context2
= kmalloc(DMP_RSP_SIZE
, GFP_KERNEL
);
185 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
187 goto out_free_context2
;
190 lpfc_dump_mem(phba
, pmb
, offset
);
191 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
193 if (rc
!= MBX_SUCCESS
) {
194 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
195 "0441 VPD not present on adapter, "
196 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
197 mb
->mbxCommand
, mb
->mbxStatus
);
198 mb
->un
.varDmp
.word_cnt
= 0;
200 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
201 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
202 lpfc_sli_pcimem_bcopy(pmb
->context2
, lpfc_vpd_data
+ offset
,
203 mb
->un
.varDmp
.word_cnt
);
204 offset
+= mb
->un
.varDmp
.word_cnt
;
205 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
206 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
208 kfree(lpfc_vpd_data
);
210 kfree(pmb
->context2
);
212 mempool_free(pmb
, phba
->mbox_mem_pool
);
216 /************************************************************************/
218 /* lpfc_config_port_post */
219 /* This routine will do LPFC initialization after the */
220 /* CONFIG_PORT mailbox command. This will be initialized */
221 /* as a SLI layer callback routine. */
222 /* This routine returns 0 on success. Any other return value */
223 /* indicates an error. */
225 /************************************************************************/
227 lpfc_config_port_post(struct lpfc_hba
*phba
)
229 struct lpfc_vport
*vport
= phba
->pport
;
232 struct lpfc_dmabuf
*mp
;
233 struct lpfc_sli
*psli
= &phba
->sli
;
234 uint32_t status
, timeout
;
238 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
240 phba
->link_state
= LPFC_HBA_ERROR
;
245 /* Get login parameters for NID. */
246 lpfc_read_sparam(phba
, pmb
, 0);
248 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
249 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
250 "0448 Adapter failed init, mbxCmd x%x "
251 "READ_SPARM mbxStatus x%x\n",
252 mb
->mbxCommand
, mb
->mbxStatus
);
253 phba
->link_state
= LPFC_HBA_ERROR
;
254 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
255 mempool_free( pmb
, phba
->mbox_mem_pool
);
256 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
261 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
263 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
264 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
266 pmb
->context1
= NULL
;
268 if (phba
->cfg_soft_wwnn
)
269 u64_to_wwn(phba
->cfg_soft_wwnn
,
270 vport
->fc_sparam
.nodeName
.u
.wwn
);
271 if (phba
->cfg_soft_wwpn
)
272 u64_to_wwn(phba
->cfg_soft_wwpn
,
273 vport
->fc_sparam
.portName
.u
.wwn
);
274 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
275 sizeof (struct lpfc_name
));
276 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
277 sizeof (struct lpfc_name
));
278 /* If no serial number in VPD data, use low 6 bytes of WWNN */
279 /* This should be consolidated into parse_vpd ? - mr */
280 if (phba
->SerialNumber
[0] == 0) {
283 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
284 for (i
= 0; i
< 12; i
++) {
286 j
= ((status
& 0xf0) >> 4);
288 phba
->SerialNumber
[i
] =
289 (char)((uint8_t) 0x30 + (uint8_t) j
);
291 phba
->SerialNumber
[i
] =
292 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
296 phba
->SerialNumber
[i
] =
297 (char)((uint8_t) 0x30 + (uint8_t) j
);
299 phba
->SerialNumber
[i
] =
300 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
304 lpfc_read_config(phba
, pmb
);
306 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
307 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
308 "0453 Adapter failed to init, mbxCmd x%x "
309 "READ_CONFIG, mbxStatus x%x\n",
310 mb
->mbxCommand
, mb
->mbxStatus
);
311 phba
->link_state
= LPFC_HBA_ERROR
;
312 mempool_free( pmb
, phba
->mbox_mem_pool
);
316 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
317 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
318 phba
->cfg_hba_queue_depth
=
319 mb
->un
.varRdConfig
.max_xri
+ 1;
321 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
323 /* Get the default values for Model Name and Description */
324 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
326 if ((phba
->cfg_link_speed
> LINK_SPEED_10G
)
327 || ((phba
->cfg_link_speed
== LINK_SPEED_1G
)
328 && !(phba
->lmt
& LMT_1Gb
))
329 || ((phba
->cfg_link_speed
== LINK_SPEED_2G
)
330 && !(phba
->lmt
& LMT_2Gb
))
331 || ((phba
->cfg_link_speed
== LINK_SPEED_4G
)
332 && !(phba
->lmt
& LMT_4Gb
))
333 || ((phba
->cfg_link_speed
== LINK_SPEED_8G
)
334 && !(phba
->lmt
& LMT_8Gb
))
335 || ((phba
->cfg_link_speed
== LINK_SPEED_10G
)
336 && !(phba
->lmt
& LMT_10Gb
))) {
337 /* Reset link speed to auto */
338 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LINK_EVENT
,
339 "1302 Invalid speed for this board: "
340 "Reset link speed to auto: x%x\n",
341 phba
->cfg_link_speed
);
342 phba
->cfg_link_speed
= LINK_SPEED_AUTO
;
345 phba
->link_state
= LPFC_LINK_DOWN
;
347 /* Only process IOCBs on ring 0 till hba_state is READY */
348 if (psli
->ring
[psli
->extra_ring
].cmdringaddr
)
349 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
350 if (psli
->ring
[psli
->fcp_ring
].cmdringaddr
)
351 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
352 if (psli
->ring
[psli
->next_ring
].cmdringaddr
)
353 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
355 /* Post receive buffers for desired rings */
356 if (phba
->sli_rev
!= 3)
357 lpfc_post_rcv_buf(phba
);
359 /* Enable appropriate host interrupts */
360 spin_lock_irq(&phba
->hbalock
);
361 status
= readl(phba
->HCregaddr
);
362 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
363 if (psli
->num_rings
> 0)
364 status
|= HC_R0INT_ENA
;
365 if (psli
->num_rings
> 1)
366 status
|= HC_R1INT_ENA
;
367 if (psli
->num_rings
> 2)
368 status
|= HC_R2INT_ENA
;
369 if (psli
->num_rings
> 3)
370 status
|= HC_R3INT_ENA
;
372 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
373 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
374 status
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
376 writel(status
, phba
->HCregaddr
);
377 readl(phba
->HCregaddr
); /* flush */
378 spin_unlock_irq(&phba
->hbalock
);
381 * Setup the ring 0 (els) timeout handler
383 timeout
= phba
->fc_ratov
<< 1;
384 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
385 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
386 phba
->hb_outstanding
= 0;
387 phba
->last_completion_time
= jiffies
;
389 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
, phba
->cfg_link_speed
);
390 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
392 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
393 lpfc_set_loopback_flag(phba
);
394 if (rc
!= MBX_SUCCESS
) {
395 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
396 "0454 Adapter failed to init, mbxCmd x%x "
397 "INIT_LINK, mbxStatus x%x\n",
398 mb
->mbxCommand
, mb
->mbxStatus
);
400 /* Clear all interrupt enable conditions */
401 writel(0, phba
->HCregaddr
);
402 readl(phba
->HCregaddr
); /* flush */
403 /* Clear all pending interrupts */
404 writel(0xffffffff, phba
->HAregaddr
);
405 readl(phba
->HAregaddr
); /* flush */
407 phba
->link_state
= LPFC_HBA_ERROR
;
409 mempool_free(pmb
, phba
->mbox_mem_pool
);
412 /* MBOX buffer will be freed in mbox compl */
417 /************************************************************************/
419 /* lpfc_hba_down_prep */
420 /* This routine will do LPFC uninitialization before the */
421 /* HBA is reset when bringing down the SLI Layer. This will be */
422 /* initialized as a SLI layer callback routine. */
423 /* This routine returns 0 on success. Any other return value */
424 /* indicates an error. */
426 /************************************************************************/
428 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
430 /* Disable interrupts */
431 writel(0, phba
->HCregaddr
);
432 readl(phba
->HCregaddr
); /* flush */
434 lpfc_cleanup_discovery_resources(phba
->pport
);
438 /************************************************************************/
440 /* lpfc_hba_down_post */
441 /* This routine will do uninitialization after the HBA is reset */
442 /* when bringing down the SLI Layer. */
443 /* This routine returns 0 on success. Any other return value */
444 /* indicates an error. */
446 /************************************************************************/
448 lpfc_hba_down_post(struct lpfc_hba
*phba
)
450 struct lpfc_sli
*psli
= &phba
->sli
;
451 struct lpfc_sli_ring
*pring
;
452 struct lpfc_dmabuf
*mp
, *next_mp
;
455 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
456 lpfc_sli_hbqbuf_free_all(phba
);
458 /* Cleanup preposted buffers on the ELS ring */
459 pring
= &psli
->ring
[LPFC_ELS_RING
];
460 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
462 pring
->postbufq_cnt
--;
463 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
468 for (i
= 0; i
< psli
->num_rings
; i
++) {
469 pring
= &psli
->ring
[i
];
470 lpfc_sli_abort_iocb_ring(phba
, pring
);
476 /* HBA heart beat timeout handler */
478 lpfc_hb_timeout(unsigned long ptr
)
480 struct lpfc_hba
*phba
;
483 phba
= (struct lpfc_hba
*)ptr
;
484 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
485 if (!(phba
->pport
->work_port_events
& WORKER_HB_TMO
))
486 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
487 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
490 wake_up(phba
->work_wait
);
495 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
497 unsigned long drvr_flag
;
499 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
500 phba
->hb_outstanding
= 0;
501 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
503 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
504 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
505 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
506 !(phba
->pport
->load_flag
& FC_UNLOADING
))
507 mod_timer(&phba
->hb_tmofunc
,
508 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
513 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
515 LPFC_MBOXQ_t
*pmboxq
;
517 struct lpfc_sli
*psli
= &phba
->sli
;
519 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
520 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
521 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
524 spin_lock_irq(&phba
->pport
->work_port_lock
);
525 /* If the timer is already canceled do nothing */
526 if (!(phba
->pport
->work_port_events
& WORKER_HB_TMO
)) {
527 spin_unlock_irq(&phba
->pport
->work_port_lock
);
531 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
533 spin_unlock_irq(&phba
->pport
->work_port_lock
);
534 if (!phba
->hb_outstanding
)
535 mod_timer(&phba
->hb_tmofunc
,
536 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
538 mod_timer(&phba
->hb_tmofunc
,
539 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
542 spin_unlock_irq(&phba
->pport
->work_port_lock
);
544 /* If there is no heart beat outstanding, issue a heartbeat command */
545 if (!phba
->hb_outstanding
) {
546 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
548 mod_timer(&phba
->hb_tmofunc
,
549 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
553 lpfc_heart_beat(phba
, pmboxq
);
554 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
555 pmboxq
->vport
= phba
->pport
;
556 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
558 if (retval
!= MBX_BUSY
&& retval
!= MBX_SUCCESS
) {
559 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
560 mod_timer(&phba
->hb_tmofunc
,
561 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
564 mod_timer(&phba
->hb_tmofunc
,
565 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
566 phba
->hb_outstanding
= 1;
570 * If heart beat timeout called with hb_outstanding set we
571 * need to take the HBA offline.
573 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
574 "0459 Adapter heartbeat failure, taking "
575 "this port offline.\n");
577 spin_lock_irq(&phba
->hbalock
);
578 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
579 spin_unlock_irq(&phba
->hbalock
);
581 lpfc_offline_prep(phba
);
583 lpfc_unblock_mgmt_io(phba
);
584 phba
->link_state
= LPFC_HBA_ERROR
;
585 lpfc_hba_down_post(phba
);
589 /************************************************************************/
591 /* lpfc_handle_eratt */
592 /* This routine will handle processing a Host Attention */
593 /* Error Status event. This will be initialized */
594 /* as a SLI layer callback routine. */
596 /************************************************************************/
598 lpfc_handle_eratt(struct lpfc_hba
*phba
)
600 struct lpfc_vport
*vport
= phba
->pport
;
601 struct lpfc_sli
*psli
= &phba
->sli
;
602 struct lpfc_sli_ring
*pring
;
603 struct lpfc_vport
**vports
;
605 struct Scsi_Host
*shost
;
608 /* If the pci channel is offline, ignore possible errors,
609 * since we cannot communicate with the pci card anyway. */
610 if (pci_channel_offline(phba
->pcidev
))
613 if (phba
->work_hs
& HS_FFER6
||
614 phba
->work_hs
& HS_FFER5
) {
615 /* Re-establishing Link */
616 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
617 "1301 Re-establishing Link "
618 "Data: x%x x%x x%x\n",
620 phba
->work_status
[0], phba
->work_status
[1]);
621 vports
= lpfc_create_vport_work_array(phba
);
624 i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
;
626 shost
= lpfc_shost_from_vport(vports
[i
]);
627 spin_lock_irq(shost
->host_lock
);
628 vports
[i
]->fc_flag
|= FC_ESTABLISH_LINK
;
629 spin_unlock_irq(shost
->host_lock
);
631 lpfc_destroy_vport_work_array(vports
);
632 spin_lock_irq(&phba
->hbalock
);
633 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
634 spin_unlock_irq(&phba
->hbalock
);
637 * Firmware stops when it triggled erratt with HS_FFER6.
638 * That could cause the I/Os dropped by the firmware.
639 * Error iocb (I/O) on txcmplq and let the SCSI layer
640 * retry it after re-establishing link.
642 pring
= &psli
->ring
[psli
->fcp_ring
];
643 lpfc_sli_abort_iocb_ring(phba
, pring
);
647 * There was a firmware error. Take the hba offline and then
648 * attempt to restart it.
650 lpfc_offline_prep(phba
);
652 lpfc_sli_brdrestart(phba
);
653 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
654 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
655 lpfc_unblock_mgmt_io(phba
);
658 lpfc_unblock_mgmt_io(phba
);
660 /* The if clause above forces this code path when the status
661 * failure is a value other than FFER6. Do not call the offline
662 * twice. This is the adapter hardware error path.
664 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
665 "0457 Adapter Hardware Error "
666 "Data: x%x x%x x%x\n",
668 phba
->work_status
[0], phba
->work_status
[1]);
670 event_data
= FC_REG_DUMP_EVENT
;
671 shost
= lpfc_shost_from_vport(vport
);
672 fc_host_post_vendor_event(shost
, fc_get_event_number(),
673 sizeof(event_data
), (char *) &event_data
,
674 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
676 spin_lock_irq(&phba
->hbalock
);
677 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
678 spin_unlock_irq(&phba
->hbalock
);
679 lpfc_offline_prep(phba
);
681 lpfc_unblock_mgmt_io(phba
);
682 phba
->link_state
= LPFC_HBA_ERROR
;
683 lpfc_hba_down_post(phba
);
687 /************************************************************************/
689 /* lpfc_handle_latt */
690 /* This routine will handle processing a Host Attention */
691 /* Link Status event. This will be initialized */
692 /* as a SLI layer callback routine. */
694 /************************************************************************/
696 lpfc_handle_latt(struct lpfc_hba
*phba
)
698 struct lpfc_vport
*vport
= phba
->pport
;
699 struct lpfc_sli
*psli
= &phba
->sli
;
701 volatile uint32_t control
;
702 struct lpfc_dmabuf
*mp
;
705 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
707 goto lpfc_handle_latt_err_exit
;
709 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
711 goto lpfc_handle_latt_free_pmb
;
713 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
715 goto lpfc_handle_latt_free_mp
;
719 /* Cleanup any outstanding ELS commands */
720 lpfc_els_flush_all_cmd(phba
);
722 psli
->slistat
.link_event
++;
723 lpfc_read_la(phba
, pmb
, mp
);
724 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_la
;
726 rc
= lpfc_sli_issue_mbox (phba
, pmb
, (MBX_NOWAIT
| MBX_STOP_IOCB
));
727 if (rc
== MBX_NOT_FINISHED
)
728 goto lpfc_handle_latt_free_mbuf
;
730 /* Clear Link Attention in HA REG */
731 spin_lock_irq(&phba
->hbalock
);
732 writel(HA_LATT
, phba
->HAregaddr
);
733 readl(phba
->HAregaddr
); /* flush */
734 spin_unlock_irq(&phba
->hbalock
);
738 lpfc_handle_latt_free_mbuf
:
739 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
740 lpfc_handle_latt_free_mp
:
742 lpfc_handle_latt_free_pmb
:
743 mempool_free(pmb
, phba
->mbox_mem_pool
);
744 lpfc_handle_latt_err_exit
:
745 /* Enable Link attention interrupts */
746 spin_lock_irq(&phba
->hbalock
);
747 psli
->sli_flag
|= LPFC_PROCESS_LA
;
748 control
= readl(phba
->HCregaddr
);
749 control
|= HC_LAINT_ENA
;
750 writel(control
, phba
->HCregaddr
);
751 readl(phba
->HCregaddr
); /* flush */
753 /* Clear Link Attention in HA REG */
754 writel(HA_LATT
, phba
->HAregaddr
);
755 readl(phba
->HAregaddr
); /* flush */
756 spin_unlock_irq(&phba
->hbalock
);
758 phba
->link_state
= LPFC_HBA_ERROR
;
760 /* The other case is an error from issue_mbox */
762 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
763 "0300 READ_LA: no buffers\n");
768 /************************************************************************/
771 /* This routine will parse the VPD data */
773 /************************************************************************/
775 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
777 uint8_t lenlo
, lenhi
;
787 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
788 "0455 Vital Product Data: x%x x%x x%x x%x\n",
789 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
791 while (!finished
&& (index
< (len
- 4))) {
792 switch (vpd
[index
]) {
800 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
809 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
810 if (Length
> len
- index
)
811 Length
= len
- index
;
813 /* Look for Serial Number */
814 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
821 phba
->SerialNumber
[j
++] = vpd
[index
++];
825 phba
->SerialNumber
[j
] = 0;
828 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
829 phba
->vpd_flag
|= VPD_MODEL_DESC
;
836 phba
->ModelDesc
[j
++] = vpd
[index
++];
840 phba
->ModelDesc
[j
] = 0;
843 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
844 phba
->vpd_flag
|= VPD_MODEL_NAME
;
851 phba
->ModelName
[j
++] = vpd
[index
++];
855 phba
->ModelName
[j
] = 0;
858 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
859 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
866 phba
->ProgramType
[j
++] = vpd
[index
++];
870 phba
->ProgramType
[j
] = 0;
873 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
874 phba
->vpd_flag
|= VPD_PORT
;
881 phba
->Port
[j
++] = vpd
[index
++];
911 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
914 uint16_t dev_id
= phba
->pcidev
->device
;
920 } m
= {"<Unknown>", 0, ""};
922 if (mdp
&& mdp
[0] != '\0'
923 && descp
&& descp
[0] != '\0')
926 if (phba
->lmt
& LMT_10Gb
)
928 else if (phba
->lmt
& LMT_8Gb
)
930 else if (phba
->lmt
& LMT_4Gb
)
932 else if (phba
->lmt
& LMT_2Gb
)
940 case PCI_DEVICE_ID_FIREFLY
:
941 m
= (typeof(m
)){"LP6000", max_speed
, "PCI"};
943 case PCI_DEVICE_ID_SUPERFLY
:
944 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
945 m
= (typeof(m
)){"LP7000", max_speed
, "PCI"};
947 m
= (typeof(m
)){"LP7000E", max_speed
, "PCI"};
949 case PCI_DEVICE_ID_DRAGONFLY
:
950 m
= (typeof(m
)){"LP8000", max_speed
, "PCI"};
952 case PCI_DEVICE_ID_CENTAUR
:
953 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
954 m
= (typeof(m
)){"LP9002", max_speed
, "PCI"};
956 m
= (typeof(m
)){"LP9000", max_speed
, "PCI"};
958 case PCI_DEVICE_ID_RFLY
:
959 m
= (typeof(m
)){"LP952", max_speed
, "PCI"};
961 case PCI_DEVICE_ID_PEGASUS
:
962 m
= (typeof(m
)){"LP9802", max_speed
, "PCI-X"};
964 case PCI_DEVICE_ID_THOR
:
965 m
= (typeof(m
)){"LP10000", max_speed
, "PCI-X"};
967 case PCI_DEVICE_ID_VIPER
:
968 m
= (typeof(m
)){"LPX1000", max_speed
, "PCI-X"};
970 case PCI_DEVICE_ID_PFLY
:
971 m
= (typeof(m
)){"LP982", max_speed
, "PCI-X"};
973 case PCI_DEVICE_ID_TFLY
:
974 m
= (typeof(m
)){"LP1050", max_speed
, "PCI-X"};
976 case PCI_DEVICE_ID_HELIOS
:
977 m
= (typeof(m
)){"LP11000", max_speed
, "PCI-X2"};
979 case PCI_DEVICE_ID_HELIOS_SCSP
:
980 m
= (typeof(m
)){"LP11000-SP", max_speed
, "PCI-X2"};
982 case PCI_DEVICE_ID_HELIOS_DCSP
:
983 m
= (typeof(m
)){"LP11002-SP", max_speed
, "PCI-X2"};
985 case PCI_DEVICE_ID_NEPTUNE
:
986 m
= (typeof(m
)){"LPe1000", max_speed
, "PCIe"};
988 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
989 m
= (typeof(m
)){"LPe1000-SP", max_speed
, "PCIe"};
991 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
992 m
= (typeof(m
)){"LPe1002-SP", max_speed
, "PCIe"};
994 case PCI_DEVICE_ID_BMID
:
995 m
= (typeof(m
)){"LP1150", max_speed
, "PCI-X2"};
997 case PCI_DEVICE_ID_BSMB
:
998 m
= (typeof(m
)){"LP111", max_speed
, "PCI-X2"};
1000 case PCI_DEVICE_ID_ZEPHYR
:
1001 m
= (typeof(m
)){"LPe11000", max_speed
, "PCIe"};
1003 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1004 m
= (typeof(m
)){"LPe11000", max_speed
, "PCIe"};
1006 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1007 m
= (typeof(m
)){"LPe11002-SP", max_speed
, "PCIe"};
1009 case PCI_DEVICE_ID_ZMID
:
1010 m
= (typeof(m
)){"LPe1150", max_speed
, "PCIe"};
1012 case PCI_DEVICE_ID_ZSMB
:
1013 m
= (typeof(m
)){"LPe111", max_speed
, "PCIe"};
1015 case PCI_DEVICE_ID_LP101
:
1016 m
= (typeof(m
)){"LP101", max_speed
, "PCI-X"};
1018 case PCI_DEVICE_ID_LP10000S
:
1019 m
= (typeof(m
)){"LP10000-S", max_speed
, "PCI"};
1021 case PCI_DEVICE_ID_LP11000S
:
1022 m
= (typeof(m
)){"LP11000-S", max_speed
,
1025 case PCI_DEVICE_ID_LPE11000S
:
1026 m
= (typeof(m
)){"LPe11000-S", max_speed
,
1029 case PCI_DEVICE_ID_SAT
:
1030 m
= (typeof(m
)){"LPe12000", max_speed
, "PCIe"};
1032 case PCI_DEVICE_ID_SAT_MID
:
1033 m
= (typeof(m
)){"LPe1250", max_speed
, "PCIe"};
1035 case PCI_DEVICE_ID_SAT_SMB
:
1036 m
= (typeof(m
)){"LPe121", max_speed
, "PCIe"};
1038 case PCI_DEVICE_ID_SAT_DCSP
:
1039 m
= (typeof(m
)){"LPe12002-SP", max_speed
, "PCIe"};
1041 case PCI_DEVICE_ID_SAT_SCSP
:
1042 m
= (typeof(m
)){"LPe12000-SP", max_speed
, "PCIe"};
1044 case PCI_DEVICE_ID_SAT_S
:
1045 m
= (typeof(m
)){"LPe12000-S", max_speed
, "PCIe"};
1048 m
= (typeof(m
)){ NULL
};
1052 if (mdp
&& mdp
[0] == '\0')
1053 snprintf(mdp
, 79,"%s", m
.name
);
1054 if (descp
&& descp
[0] == '\0')
1055 snprintf(descp
, 255,
1056 "Emulex %s %dGb %s Fibre Channel Adapter",
1057 m
.name
, m
.max_speed
, m
.bus
);
1060 /**************************************************/
1061 /* lpfc_post_buffer */
1063 /* This routine will post count buffers to the */
1064 /* ring with the QUE_RING_BUF_CN command. This */
1065 /* allows 3 buffers / command to be posted. */
1066 /* Returns the number of buffers NOT posted. */
1067 /**************************************************/
1069 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
,
1073 struct lpfc_iocbq
*iocb
;
1074 struct lpfc_dmabuf
*mp1
, *mp2
;
1076 cnt
+= pring
->missbufcnt
;
1078 /* While there are buffers to post */
1080 /* Allocate buffer for command iocb */
1081 iocb
= lpfc_sli_get_iocbq(phba
);
1083 pring
->missbufcnt
= cnt
;
1088 /* 2 buffers can be posted per command */
1089 /* Allocate buffer to post */
1090 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1092 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1094 if (mp1
== 0 || mp1
->virt
== 0) {
1096 lpfc_sli_release_iocbq(phba
, iocb
);
1097 pring
->missbufcnt
= cnt
;
1101 INIT_LIST_HEAD(&mp1
->list
);
1102 /* Allocate buffer to post */
1104 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1106 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1108 if (mp2
== 0 || mp2
->virt
== 0) {
1110 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1112 lpfc_sli_release_iocbq(phba
, iocb
);
1113 pring
->missbufcnt
= cnt
;
1117 INIT_LIST_HEAD(&mp2
->list
);
1122 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
1123 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
1124 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
1125 icmd
->ulpBdeCount
= 1;
1128 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
1129 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
1130 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
1132 icmd
->ulpBdeCount
= 2;
1135 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
1138 if (lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0) == IOCB_ERROR
) {
1139 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1143 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
1147 lpfc_sli_release_iocbq(phba
, iocb
);
1148 pring
->missbufcnt
= cnt
;
1151 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
1153 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
1155 pring
->missbufcnt
= 0;
1159 /************************************************************************/
1161 /* lpfc_post_rcv_buf */
1162 /* This routine post initial rcv buffers to the configured rings */
1164 /************************************************************************/
1166 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
1168 struct lpfc_sli
*psli
= &phba
->sli
;
1170 /* Ring 0, ELS / CT buffers */
1171 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
, 1);
1172 /* Ring 2 - FCP no buffers needed */
1177 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1179 /************************************************************************/
1183 /************************************************************************/
1185 lpfc_sha_init(uint32_t * HashResultPointer
)
1187 HashResultPointer
[0] = 0x67452301;
1188 HashResultPointer
[1] = 0xEFCDAB89;
1189 HashResultPointer
[2] = 0x98BADCFE;
1190 HashResultPointer
[3] = 0x10325476;
1191 HashResultPointer
[4] = 0xC3D2E1F0;
1194 /************************************************************************/
1196 /* lpfc_sha_iterate */
1198 /************************************************************************/
1200 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
1204 uint32_t A
, B
, C
, D
, E
;
1207 HashWorkingPointer
[t
] =
1209 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
1211 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
1212 } while (++t
<= 79);
1214 A
= HashResultPointer
[0];
1215 B
= HashResultPointer
[1];
1216 C
= HashResultPointer
[2];
1217 D
= HashResultPointer
[3];
1218 E
= HashResultPointer
[4];
1222 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
1223 } else if (t
< 40) {
1224 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
1225 } else if (t
< 60) {
1226 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
1228 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
1230 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
1236 } while (++t
<= 79);
1238 HashResultPointer
[0] += A
;
1239 HashResultPointer
[1] += B
;
1240 HashResultPointer
[2] += C
;
1241 HashResultPointer
[3] += D
;
1242 HashResultPointer
[4] += E
;
1246 /************************************************************************/
1248 /* lpfc_challenge_key */
1250 /************************************************************************/
1252 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
1254 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
1257 /************************************************************************/
1261 /************************************************************************/
1263 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
1266 uint32_t *HashWorking
;
1267 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
1269 HashWorking
= kmalloc(80 * sizeof(uint32_t), GFP_KERNEL
);
1273 memset(HashWorking
, 0, (80 * sizeof(uint32_t)));
1274 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
1275 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
1277 for (t
= 0; t
< 7; t
++)
1278 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
1280 lpfc_sha_init(hbainit
);
1281 lpfc_sha_iterate(hbainit
, HashWorking
);
1286 lpfc_cleanup(struct lpfc_vport
*vport
)
1288 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1290 /* clean up phba - lpfc specific */
1291 lpfc_can_disctmo(vport
);
1292 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
)
1298 lpfc_establish_link_tmo(unsigned long ptr
)
1300 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
1301 struct lpfc_vport
**vports
;
1302 unsigned long iflag
;
1305 /* Re-establishing Link, timer expired */
1306 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1307 "1300 Re-establishing Link, timer expired "
1309 phba
->pport
->fc_flag
, phba
->pport
->port_state
);
1310 vports
= lpfc_create_vport_work_array(phba
);
1312 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1313 struct Scsi_Host
*shost
;
1314 shost
= lpfc_shost_from_vport(vports
[i
]);
1315 spin_lock_irqsave(shost
->host_lock
, iflag
);
1316 vports
[i
]->fc_flag
&= ~FC_ESTABLISH_LINK
;
1317 spin_unlock_irqrestore(shost
->host_lock
, iflag
);
1319 lpfc_destroy_vport_work_array(vports
);
1323 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
1325 del_timer_sync(&vport
->els_tmofunc
);
1326 del_timer_sync(&vport
->fc_fdmitmo
);
1327 lpfc_can_disctmo(vport
);
1332 lpfc_stop_phba_timers(struct lpfc_hba
*phba
)
1334 del_timer_sync(&phba
->fcp_poll_timer
);
1335 del_timer_sync(&phba
->fc_estabtmo
);
1336 lpfc_stop_vport_timers(phba
->pport
);
1337 del_timer_sync(&phba
->sli
.mbox_tmo
);
1338 del_timer_sync(&phba
->fabric_block_timer
);
1339 phba
->hb_outstanding
= 0;
1340 del_timer_sync(&phba
->hb_tmofunc
);
1345 lpfc_online(struct lpfc_hba
*phba
)
1347 struct lpfc_vport
*vport
= phba
->pport
;
1348 struct lpfc_vport
**vports
;
1354 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
1357 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1358 "0458 Bring Adapter online\n");
1360 lpfc_block_mgmt_io(phba
);
1362 if (!lpfc_sli_queue_setup(phba
)) {
1363 lpfc_unblock_mgmt_io(phba
);
1367 if (lpfc_sli_hba_setup(phba
)) { /* Initialize the HBA */
1368 lpfc_unblock_mgmt_io(phba
);
1372 vports
= lpfc_create_vport_work_array(phba
);
1374 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1375 struct Scsi_Host
*shost
;
1376 shost
= lpfc_shost_from_vport(vports
[i
]);
1377 spin_lock_irq(shost
->host_lock
);
1378 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
1379 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
1380 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
1381 spin_unlock_irq(shost
->host_lock
);
1383 lpfc_destroy_vport_work_array(vports
);
1385 lpfc_unblock_mgmt_io(phba
);
1390 lpfc_block_mgmt_io(struct lpfc_hba
* phba
)
1392 unsigned long iflag
;
1394 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1395 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
1396 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1400 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
1402 unsigned long iflag
;
1404 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1405 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
1406 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1410 lpfc_offline_prep(struct lpfc_hba
* phba
)
1412 struct lpfc_vport
*vport
= phba
->pport
;
1413 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1415 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
1418 lpfc_block_mgmt_io(phba
);
1420 lpfc_linkdown(phba
);
1422 /* Issue an unreg_login to all nodes */
1423 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
)
1424 if (ndlp
->nlp_state
!= NLP_STE_UNUSED_NODE
)
1425 lpfc_unreg_rpi(vport
, ndlp
);
1427 lpfc_sli_flush_mbox_queue(phba
);
1431 lpfc_offline(struct lpfc_hba
*phba
)
1433 struct Scsi_Host
*shost
;
1434 struct lpfc_vport
**vports
;
1437 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1440 /* stop all timers associated with this hba */
1441 lpfc_stop_phba_timers(phba
);
1442 vports
= lpfc_create_vport_work_array(phba
);
1444 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++)
1445 lpfc_stop_vport_timers(vports
[i
]);
1446 lpfc_destroy_vport_work_array(vports
);
1447 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1448 "0460 Bring Adapter offline\n");
1449 /* Bring down the SLI Layer and cleanup. The HBA is offline
1451 lpfc_sli_hba_down(phba
);
1452 spin_lock_irq(&phba
->hbalock
);
1454 spin_unlock_irq(&phba
->hbalock
);
1455 vports
= lpfc_create_vport_work_array(phba
);
1457 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1458 shost
= lpfc_shost_from_vport(vports
[i
]);
1459 lpfc_cleanup(vports
[i
]);
1460 spin_lock_irq(shost
->host_lock
);
1461 vports
[i
]->work_port_events
= 0;
1462 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
1463 spin_unlock_irq(shost
->host_lock
);
1465 lpfc_destroy_vport_work_array(vports
);
1468 /******************************************************************************
1469 * Function name: lpfc_scsi_free
1471 * Description: Called from lpfc_pci_remove_one free internal driver resources
1473 ******************************************************************************/
1475 lpfc_scsi_free(struct lpfc_hba
*phba
)
1477 struct lpfc_scsi_buf
*sb
, *sb_next
;
1478 struct lpfc_iocbq
*io
, *io_next
;
1480 spin_lock_irq(&phba
->hbalock
);
1481 /* Release all the lpfc_scsi_bufs maintained by this host. */
1482 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
1483 list_del(&sb
->list
);
1484 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
1487 phba
->total_scsi_bufs
--;
1490 /* Release all the lpfc_iocbq entries maintained by this host. */
1491 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
1492 list_del(&io
->list
);
1494 phba
->total_iocbq_bufs
--;
1497 spin_unlock_irq(&phba
->hbalock
);
1503 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
1505 struct lpfc_vport
*vport
;
1506 struct Scsi_Host
*shost
;
1509 if (dev
!= &phba
->pcidev
->dev
)
1510 shost
= scsi_host_alloc(&lpfc_vport_template
,
1511 sizeof(struct lpfc_vport
));
1513 shost
= scsi_host_alloc(&lpfc_template
,
1514 sizeof(struct lpfc_vport
));
1518 vport
= (struct lpfc_vport
*) shost
->hostdata
;
1521 vport
->load_flag
|= FC_LOADING
;
1522 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
1524 lpfc_get_vport_cfgparam(vport
);
1525 shost
->unique_id
= instance
;
1526 shost
->max_id
= LPFC_MAX_TARGET
;
1527 shost
->max_lun
= vport
->cfg_max_luns
;
1528 shost
->this_id
= -1;
1529 shost
->max_cmd_len
= 16;
1531 * Set initial can_queue value since 0 is no longer supported and
1532 * scsi_add_host will fail. This will be adjusted later based on the
1533 * max xri value determined in hba setup.
1535 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
1536 if (dev
!= &phba
->pcidev
->dev
) {
1537 shost
->transportt
= lpfc_vport_transport_template
;
1538 vport
->port_type
= LPFC_NPIV_PORT
;
1540 shost
->transportt
= lpfc_transport_template
;
1541 vport
->port_type
= LPFC_PHYSICAL_PORT
;
1544 /* Initialize all internally managed lists. */
1545 INIT_LIST_HEAD(&vport
->fc_nodes
);
1546 spin_lock_init(&vport
->work_port_lock
);
1548 init_timer(&vport
->fc_disctmo
);
1549 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
1550 vport
->fc_disctmo
.data
= (unsigned long)vport
;
1552 init_timer(&vport
->fc_fdmitmo
);
1553 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
1554 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
1556 init_timer(&vport
->els_tmofunc
);
1557 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
1558 vport
->els_tmofunc
.data
= (unsigned long)vport
;
1560 error
= scsi_add_host(shost
, dev
);
1564 spin_lock_irq(&phba
->hbalock
);
1565 list_add_tail(&vport
->listentry
, &phba
->port_list
);
1566 spin_unlock_irq(&phba
->hbalock
);
1570 scsi_host_put(shost
);
1576 destroy_port(struct lpfc_vport
*vport
)
1578 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1579 struct lpfc_hba
*phba
= vport
->phba
;
1581 kfree(vport
->vname
);
1583 lpfc_debugfs_terminate(vport
);
1584 fc_remove_host(shost
);
1585 scsi_remove_host(shost
);
1587 spin_lock_irq(&phba
->hbalock
);
1588 list_del_init(&vport
->listentry
);
1589 spin_unlock_irq(&phba
->hbalock
);
1591 lpfc_cleanup(vport
);
1596 lpfc_get_instance(void)
1600 /* Assign an unused number */
1601 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
1603 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
1609 * Note: there is no scan_start function as adapter initialization
1610 * will have asynchronously kicked off the link initialization.
1613 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1615 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1616 struct lpfc_hba
*phba
= vport
->phba
;
1619 spin_lock_irq(shost
->host_lock
);
1621 if (vport
->load_flag
& FC_UNLOADING
) {
1625 if (time
>= 30 * HZ
) {
1626 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1627 "0461 Scanning longer than 30 "
1628 "seconds. Continuing initialization\n");
1632 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
1633 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1634 "0465 Link down longer than 15 "
1635 "seconds. Continuing initialization\n");
1640 if (vport
->port_state
!= LPFC_VPORT_READY
)
1642 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
1644 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
1646 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
1652 spin_unlock_irq(shost
->host_lock
);
1656 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
1658 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1659 struct lpfc_hba
*phba
= vport
->phba
;
1661 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1664 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
1665 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
1666 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
1668 memset(fc_host_supported_fc4s(shost
), 0,
1669 sizeof(fc_host_supported_fc4s(shost
)));
1670 fc_host_supported_fc4s(shost
)[2] = 1;
1671 fc_host_supported_fc4s(shost
)[7] = 1;
1673 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
1674 sizeof fc_host_symbolic_name(shost
));
1676 fc_host_supported_speeds(shost
) = 0;
1677 if (phba
->lmt
& LMT_10Gb
)
1678 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
1679 if (phba
->lmt
& LMT_4Gb
)
1680 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
1681 if (phba
->lmt
& LMT_2Gb
)
1682 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
1683 if (phba
->lmt
& LMT_1Gb
)
1684 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
1686 fc_host_maxframe_size(shost
) =
1687 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
1688 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
1690 /* This value is also unchanging */
1691 memset(fc_host_active_fc4s(shost
), 0,
1692 sizeof(fc_host_active_fc4s(shost
)));
1693 fc_host_active_fc4s(shost
)[2] = 1;
1694 fc_host_active_fc4s(shost
)[7] = 1;
1696 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
1697 spin_lock_irq(shost
->host_lock
);
1698 vport
->load_flag
&= ~FC_LOADING
;
1699 spin_unlock_irq(shost
->host_lock
);
1702 static int __devinit
1703 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
1705 struct lpfc_vport
*vport
= NULL
;
1706 struct lpfc_hba
*phba
;
1707 struct lpfc_sli
*psli
;
1708 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
1709 struct Scsi_Host
*shost
= NULL
;
1711 unsigned long bar0map_len
, bar2map_len
;
1712 int error
= -ENODEV
;
1716 if (pci_enable_device(pdev
))
1718 if (pci_request_regions(pdev
, LPFC_DRIVER_NAME
))
1719 goto out_disable_device
;
1721 phba
= kzalloc(sizeof (struct lpfc_hba
), GFP_KERNEL
);
1723 goto out_release_regions
;
1725 spin_lock_init(&phba
->hbalock
);
1727 phba
->pcidev
= pdev
;
1729 /* Assign an unused board number */
1730 if ((phba
->brd_no
= lpfc_get_instance()) < 0)
1733 INIT_LIST_HEAD(&phba
->port_list
);
1735 * Get all the module params for configuring this host and then
1736 * establish the host.
1738 lpfc_get_cfgparam(phba
);
1739 phba
->max_vpi
= LPFC_MAX_VPI
;
1741 /* Initialize timers used by driver */
1742 init_timer(&phba
->fc_estabtmo
);
1743 phba
->fc_estabtmo
.function
= lpfc_establish_link_tmo
;
1744 phba
->fc_estabtmo
.data
= (unsigned long)phba
;
1746 init_timer(&phba
->hb_tmofunc
);
1747 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
1748 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
1751 init_timer(&psli
->mbox_tmo
);
1752 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
1753 psli
->mbox_tmo
.data
= (unsigned long) phba
;
1754 init_timer(&phba
->fcp_poll_timer
);
1755 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
1756 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
1757 init_timer(&phba
->fabric_block_timer
);
1758 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
1759 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
1761 pci_set_master(pdev
);
1762 pci_try_set_mwi(pdev
);
1764 if (pci_set_dma_mask(phba
->pcidev
, DMA_64BIT_MASK
) != 0)
1765 if (pci_set_dma_mask(phba
->pcidev
, DMA_32BIT_MASK
) != 0)
1766 goto out_idr_remove
;
1769 * Get the bus address of Bar0 and Bar2 and the number of bytes
1770 * required by each mapping.
1772 phba
->pci_bar0_map
= pci_resource_start(phba
->pcidev
, 0);
1773 bar0map_len
= pci_resource_len(phba
->pcidev
, 0);
1775 phba
->pci_bar2_map
= pci_resource_start(phba
->pcidev
, 2);
1776 bar2map_len
= pci_resource_len(phba
->pcidev
, 2);
1778 /* Map HBA SLIM to a kernel virtual address. */
1779 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
1780 if (!phba
->slim_memmap_p
) {
1782 dev_printk(KERN_ERR
, &pdev
->dev
,
1783 "ioremap failed for SLIM memory.\n");
1784 goto out_idr_remove
;
1787 /* Map HBA Control Registers to a kernel virtual address. */
1788 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
1789 if (!phba
->ctrl_regs_memmap_p
) {
1791 dev_printk(KERN_ERR
, &pdev
->dev
,
1792 "ioremap failed for HBA control registers.\n");
1793 goto out_iounmap_slim
;
1796 /* Allocate memory for SLI-2 structures */
1797 phba
->slim2p
= dma_alloc_coherent(&phba
->pcidev
->dev
, SLI2_SLIM_SIZE
,
1798 &phba
->slim2p_mapping
, GFP_KERNEL
);
1802 memset(phba
->slim2p
, 0, SLI2_SLIM_SIZE
);
1804 phba
->hbqslimp
.virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
1805 lpfc_sli_hbq_size(),
1806 &phba
->hbqslimp
.phys
,
1808 if (!phba
->hbqslimp
.virt
)
1811 hbq_count
= lpfc_sli_hbq_count();
1812 ptr
= phba
->hbqslimp
.virt
;
1813 for (i
= 0; i
< hbq_count
; ++i
) {
1814 phba
->hbqs
[i
].hbq_virt
= ptr
;
1815 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
1816 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
1817 sizeof(struct lpfc_hbq_entry
));
1819 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
1820 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
1822 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
1824 /* Initialize the SLI Layer to run with lpfc HBAs. */
1825 lpfc_sli_setup(phba
);
1826 lpfc_sli_queue_setup(phba
);
1828 error
= lpfc_mem_alloc(phba
);
1830 goto out_free_hbqslimp
;
1832 /* Initialize and populate the iocb list per host. */
1833 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
1834 for (i
= 0; i
< LPFC_IOCB_LIST_CNT
; i
++) {
1835 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
1836 if (iocbq_entry
== NULL
) {
1837 printk(KERN_ERR
"%s: only allocated %d iocbs of "
1838 "expected %d count. Unloading driver.\n",
1839 __FUNCTION__
, i
, LPFC_IOCB_LIST_CNT
);
1841 goto out_free_iocbq
;
1844 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
1846 kfree (iocbq_entry
);
1847 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
1848 "Unloading driver.\n",
1851 goto out_free_iocbq
;
1854 spin_lock_irq(&phba
->hbalock
);
1855 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
1856 phba
->total_iocbq_bufs
++;
1857 spin_unlock_irq(&phba
->hbalock
);
1860 /* Initialize HBA structure */
1861 phba
->fc_edtov
= FF_DEF_EDTOV
;
1862 phba
->fc_ratov
= FF_DEF_RATOV
;
1863 phba
->fc_altov
= FF_DEF_ALTOV
;
1864 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
1866 INIT_LIST_HEAD(&phba
->work_list
);
1867 phba
->work_ha_mask
= (HA_ERATT
|HA_MBATT
|HA_LATT
);
1868 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
1870 /* Startup the kernel thread for this host adapter. */
1871 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
1872 "lpfc_worker_%d", phba
->brd_no
);
1873 if (IS_ERR(phba
->worker_thread
)) {
1874 error
= PTR_ERR(phba
->worker_thread
);
1875 goto out_free_iocbq
;
1878 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1879 spin_lock_init(&phba
->scsi_buf_list_lock
);
1880 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
1882 /* Initialize list of fabric iocbs */
1883 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
1885 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
1887 goto out_kthread_stop
;
1889 shost
= lpfc_shost_from_vport(vport
);
1890 phba
->pport
= vport
;
1891 lpfc_debugfs_initialize(vport
);
1893 pci_set_drvdata(pdev
, shost
);
1895 if (phba
->cfg_use_msi
) {
1896 error
= pci_enable_msi(phba
->pcidev
);
1898 phba
->using_msi
= 1;
1900 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1901 "0452 Enable MSI failed, continuing "
1905 error
= request_irq(phba
->pcidev
->irq
, lpfc_intr_handler
, IRQF_SHARED
,
1906 LPFC_DRIVER_NAME
, phba
);
1908 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1909 "0451 Enable interrupt handler failed\n");
1910 goto out_disable_msi
;
1913 phba
->MBslimaddr
= phba
->slim_memmap_p
;
1914 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
1915 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
1916 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
1917 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
1919 if (lpfc_alloc_sysfs_attr(vport
))
1922 if (lpfc_sli_hba_setup(phba
))
1923 goto out_remove_device
;
1926 * hba setup may have changed the hba_queue_depth so we need to adjust
1927 * the value of can_queue.
1929 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
1931 lpfc_host_attrib_init(shost
);
1933 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1934 spin_lock_irq(shost
->host_lock
);
1935 lpfc_poll_start_timer(phba
);
1936 spin_unlock_irq(shost
->host_lock
);
1939 scsi_scan_host(shost
);
1944 lpfc_free_sysfs_attr(vport
);
1945 spin_lock_irq(shost
->host_lock
);
1946 vport
->load_flag
|= FC_UNLOADING
;
1947 spin_unlock_irq(shost
->host_lock
);
1949 lpfc_stop_phba_timers(phba
);
1950 phba
->pport
->work_port_events
= 0;
1951 free_irq(phba
->pcidev
->irq
, phba
);
1953 if (phba
->using_msi
)
1954 pci_disable_msi(phba
->pcidev
);
1955 destroy_port(vport
);
1957 kthread_stop(phba
->worker_thread
);
1959 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
1960 &phba
->lpfc_iocb_list
, list
) {
1962 phba
->total_iocbq_bufs
--;
1964 lpfc_mem_free(phba
);
1966 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(), phba
->hbqslimp
.virt
,
1967 phba
->hbqslimp
.phys
);
1969 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
, phba
->slim2p
,
1970 phba
->slim2p_mapping
);
1972 iounmap(phba
->ctrl_regs_memmap_p
);
1974 iounmap(phba
->slim_memmap_p
);
1976 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
1979 out_release_regions
:
1980 pci_release_regions(pdev
);
1982 pci_disable_device(pdev
);
1984 pci_set_drvdata(pdev
, NULL
);
1986 scsi_host_put(shost
);
1990 static void __devexit
1991 lpfc_pci_remove_one(struct pci_dev
*pdev
)
1993 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
1994 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1995 struct lpfc_hba
*phba
= vport
->phba
;
1996 spin_lock_irq(&phba
->hbalock
);
1997 vport
->load_flag
|= FC_UNLOADING
;
1998 spin_unlock_irq(&phba
->hbalock
);
2000 kfree(vport
->vname
);
2001 lpfc_free_sysfs_attr(vport
);
2003 fc_remove_host(shost
);
2004 scsi_remove_host(shost
);
2006 * Bring down the SLI Layer. This step disable all interrupts,
2007 * clears the rings, discards all mailbox commands, and resets
2010 lpfc_sli_hba_down(phba
);
2011 lpfc_sli_brdrestart(phba
);
2013 lpfc_stop_phba_timers(phba
);
2014 spin_lock_irq(&phba
->hbalock
);
2015 list_del_init(&vport
->listentry
);
2016 spin_unlock_irq(&phba
->hbalock
);
2018 lpfc_debugfs_terminate(vport
);
2019 lpfc_cleanup(vport
);
2021 kthread_stop(phba
->worker_thread
);
2023 /* Release the irq reservation */
2024 free_irq(phba
->pcidev
->irq
, phba
);
2025 if (phba
->using_msi
)
2026 pci_disable_msi(phba
->pcidev
);
2028 pci_set_drvdata(pdev
, NULL
);
2029 scsi_host_put(shost
);
2032 * Call scsi_free before mem_free since scsi bufs are released to their
2033 * corresponding pools here.
2035 lpfc_scsi_free(phba
);
2036 lpfc_mem_free(phba
);
2038 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(), phba
->hbqslimp
.virt
,
2039 phba
->hbqslimp
.phys
);
2041 /* Free resources associated with SLI2 interface */
2042 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
2043 phba
->slim2p
, phba
->slim2p_mapping
);
2045 /* unmap adapter SLIM and Control Registers */
2046 iounmap(phba
->ctrl_regs_memmap_p
);
2047 iounmap(phba
->slim_memmap_p
);
2049 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
2053 pci_release_regions(pdev
);
2054 pci_disable_device(pdev
);
2058 * lpfc_io_error_detected - called when PCI error is detected
2059 * @pdev: Pointer to PCI device
2060 * @state: The current pci conneection state
2062 * This function is called after a PCI bus error affecting
2063 * this device has been detected.
2065 static pci_ers_result_t
lpfc_io_error_detected(struct pci_dev
*pdev
,
2066 pci_channel_state_t state
)
2068 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2069 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2070 struct lpfc_sli
*psli
= &phba
->sli
;
2071 struct lpfc_sli_ring
*pring
;
2073 if (state
== pci_channel_io_perm_failure
)
2074 return PCI_ERS_RESULT_DISCONNECT
;
2076 pci_disable_device(pdev
);
2078 * There may be I/Os dropped by the firmware.
2079 * Error iocb (I/O) on txcmplq and let the SCSI layer
2080 * retry it after re-establishing link.
2082 pring
= &psli
->ring
[psli
->fcp_ring
];
2083 lpfc_sli_abort_iocb_ring(phba
, pring
);
2085 /* Release the irq reservation */
2086 free_irq(phba
->pcidev
->irq
, phba
);
2087 if (phba
->using_msi
)
2088 pci_disable_msi(phba
->pcidev
);
2090 /* Request a slot reset. */
2091 return PCI_ERS_RESULT_NEED_RESET
;
2095 * lpfc_io_slot_reset - called after the pci bus has been reset.
2096 * @pdev: Pointer to PCI device
2098 * Restart the card from scratch, as if from a cold-boot.
2100 static pci_ers_result_t
lpfc_io_slot_reset(struct pci_dev
*pdev
)
2102 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2103 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2104 struct lpfc_sli
*psli
= &phba
->sli
;
2105 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2107 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
2108 if (pci_enable_device_bars(pdev
, bars
)) {
2109 printk(KERN_ERR
"lpfc: Cannot re-enable "
2110 "PCI device after reset.\n");
2111 return PCI_ERS_RESULT_DISCONNECT
;
2114 pci_set_master(pdev
);
2116 /* Re-establishing Link */
2117 spin_lock_irq(shost
->host_lock
);
2118 phba
->pport
->fc_flag
|= FC_ESTABLISH_LINK
;
2119 spin_unlock_irq(shost
->host_lock
);
2121 spin_lock_irq(&phba
->hbalock
);
2122 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2123 spin_unlock_irq(&phba
->hbalock
);
2126 /* Take device offline; this will perform cleanup */
2128 lpfc_sli_brdrestart(phba
);
2130 return PCI_ERS_RESULT_RECOVERED
;
2134 * lpfc_io_resume - called when traffic can start flowing again.
2135 * @pdev: Pointer to PCI device
2137 * This callback is called when the error recovery driver tells us that
2138 * its OK to resume normal operation.
2140 static void lpfc_io_resume(struct pci_dev
*pdev
)
2142 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2143 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2145 if (lpfc_online(phba
) == 0) {
2146 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
2150 static struct pci_device_id lpfc_id_table
[] = {
2151 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
2152 PCI_ANY_ID
, PCI_ANY_ID
, },
2153 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
2154 PCI_ANY_ID
, PCI_ANY_ID
, },
2155 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
2156 PCI_ANY_ID
, PCI_ANY_ID
, },
2157 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
2158 PCI_ANY_ID
, PCI_ANY_ID
, },
2159 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
2160 PCI_ANY_ID
, PCI_ANY_ID
, },
2161 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
2162 PCI_ANY_ID
, PCI_ANY_ID
, },
2163 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
2164 PCI_ANY_ID
, PCI_ANY_ID
, },
2165 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
2166 PCI_ANY_ID
, PCI_ANY_ID
, },
2167 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
2168 PCI_ANY_ID
, PCI_ANY_ID
, },
2169 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
2170 PCI_ANY_ID
, PCI_ANY_ID
, },
2171 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
2172 PCI_ANY_ID
, PCI_ANY_ID
, },
2173 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
2174 PCI_ANY_ID
, PCI_ANY_ID
, },
2175 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
2176 PCI_ANY_ID
, PCI_ANY_ID
, },
2177 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
2178 PCI_ANY_ID
, PCI_ANY_ID
, },
2179 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
2180 PCI_ANY_ID
, PCI_ANY_ID
, },
2181 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
2182 PCI_ANY_ID
, PCI_ANY_ID
, },
2183 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
2184 PCI_ANY_ID
, PCI_ANY_ID
, },
2185 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
2186 PCI_ANY_ID
, PCI_ANY_ID
, },
2187 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
2188 PCI_ANY_ID
, PCI_ANY_ID
, },
2189 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
2190 PCI_ANY_ID
, PCI_ANY_ID
, },
2191 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
2192 PCI_ANY_ID
, PCI_ANY_ID
, },
2193 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
2194 PCI_ANY_ID
, PCI_ANY_ID
, },
2195 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
2196 PCI_ANY_ID
, PCI_ANY_ID
, },
2197 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
2198 PCI_ANY_ID
, PCI_ANY_ID
, },
2199 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
2200 PCI_ANY_ID
, PCI_ANY_ID
, },
2201 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
2202 PCI_ANY_ID
, PCI_ANY_ID
, },
2203 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
2204 PCI_ANY_ID
, PCI_ANY_ID
, },
2205 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
2206 PCI_ANY_ID
, PCI_ANY_ID
, },
2207 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
2208 PCI_ANY_ID
, PCI_ANY_ID
, },
2209 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
2210 PCI_ANY_ID
, PCI_ANY_ID
, },
2211 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
2212 PCI_ANY_ID
, PCI_ANY_ID
, },
2213 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
2214 PCI_ANY_ID
, PCI_ANY_ID
, },
2215 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
2216 PCI_ANY_ID
, PCI_ANY_ID
, },
2220 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
2222 static struct pci_error_handlers lpfc_err_handler
= {
2223 .error_detected
= lpfc_io_error_detected
,
2224 .slot_reset
= lpfc_io_slot_reset
,
2225 .resume
= lpfc_io_resume
,
2228 static struct pci_driver lpfc_driver
= {
2229 .name
= LPFC_DRIVER_NAME
,
2230 .id_table
= lpfc_id_table
,
2231 .probe
= lpfc_pci_probe_one
,
2232 .remove
= __devexit_p(lpfc_pci_remove_one
),
2233 .err_handler
= &lpfc_err_handler
,
2241 printk(LPFC_MODULE_DESC
"\n");
2242 printk(LPFC_COPYRIGHT
"\n");
2244 lpfc_transport_template
=
2245 fc_attach_transport(&lpfc_transport_functions
);
2246 lpfc_vport_transport_template
=
2247 fc_attach_transport(&lpfc_vport_transport_functions
);
2248 if (!lpfc_transport_template
|| !lpfc_vport_transport_template
)
2250 error
= pci_register_driver(&lpfc_driver
);
2252 fc_release_transport(lpfc_transport_template
);
2253 fc_release_transport(lpfc_vport_transport_template
);
2262 pci_unregister_driver(&lpfc_driver
);
2263 fc_release_transport(lpfc_transport_template
);
2264 fc_release_transport(lpfc_vport_transport_template
);
2267 module_init(lpfc_init
);
2268 module_exit(lpfc_exit
);
2269 MODULE_LICENSE("GPL");
2270 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
2271 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2272 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);