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
);
58 extern struct lpfc_hbq_init
*lpfc_hbq_defs
[];
60 /************************************************************************/
62 /* lpfc_config_port_prep */
63 /* This routine will do LPFC initialization prior to the */
64 /* CONFIG_PORT mailbox command. This will be initialized */
65 /* as a SLI layer callback routine. */
66 /* This routine returns 0 on success or -ERESTART if it wants */
67 /* the SLI layer to reset the HBA and try again. Any */
68 /* other return value indicates an error. */
70 /************************************************************************/
72 lpfc_config_port_prep(struct lpfc_hba
*phba
)
74 lpfc_vpd_t
*vp
= &phba
->vpd
;
78 char *lpfc_vpd_data
= NULL
;
80 static char licensed
[56] =
81 "key unlock for use with gnu public licensed code only\0";
82 static int init_key
= 1;
84 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
86 phba
->link_state
= LPFC_HBA_ERROR
;
91 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
93 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
95 uint32_t *ptext
= (uint32_t *) licensed
;
97 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
98 *ptext
= cpu_to_be32(*ptext
);
102 lpfc_read_nv(phba
, pmb
);
103 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
104 sizeof (mb
->un
.varRDnvp
.rsvd3
));
105 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
108 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
110 if (rc
!= MBX_SUCCESS
) {
111 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
112 "0324 Config Port initialization "
113 "error, mbxCmd x%x READ_NVPARM, "
115 mb
->mbxCommand
, mb
->mbxStatus
);
116 mempool_free(pmb
, phba
->mbox_mem_pool
);
119 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
121 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
125 phba
->sli3_options
= 0x0;
127 /* Setup and issue mailbox READ REV command */
128 lpfc_read_rev(phba
, pmb
);
129 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
130 if (rc
!= MBX_SUCCESS
) {
131 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
132 "0439 Adapter failed to init, mbxCmd x%x "
133 "READ_REV, mbxStatus x%x\n",
134 mb
->mbxCommand
, mb
->mbxStatus
);
135 mempool_free( pmb
, phba
->mbox_mem_pool
);
141 * The value of rr must be 1 since the driver set the cv field to 1.
142 * This setting requires the FW to set all revision fields.
144 if (mb
->un
.varRdRev
.rr
== 0) {
146 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
147 "0440 Adapter failed to init, READ_REV has "
148 "missing revision information.\n");
149 mempool_free(pmb
, phba
->mbox_mem_pool
);
153 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
)
156 /* Save information as VPD data */
158 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
159 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
160 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
161 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
162 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
163 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
164 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
165 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
166 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
167 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
168 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
169 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
170 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
171 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
172 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
174 /* If the sli feature level is less then 9, we must
175 * tear down all RPIs and VPIs on link down if NPIV
178 if (vp
->rev
.feaLevelHigh
< 9)
179 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
181 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
182 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
183 sizeof (phba
->RandomData
));
185 /* Get adapter VPD information */
186 pmb
->context2
= kmalloc(DMP_RSP_SIZE
, GFP_KERNEL
);
189 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
191 goto out_free_context2
;
194 lpfc_dump_mem(phba
, pmb
, offset
);
195 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
197 if (rc
!= MBX_SUCCESS
) {
198 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
199 "0441 VPD not present on adapter, "
200 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
201 mb
->mbxCommand
, mb
->mbxStatus
);
202 mb
->un
.varDmp
.word_cnt
= 0;
204 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
205 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
206 lpfc_sli_pcimem_bcopy(pmb
->context2
, lpfc_vpd_data
+ offset
,
207 mb
->un
.varDmp
.word_cnt
);
208 offset
+= mb
->un
.varDmp
.word_cnt
;
209 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
210 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
212 kfree(lpfc_vpd_data
);
214 kfree(pmb
->context2
);
216 mempool_free(pmb
, phba
->mbox_mem_pool
);
220 /************************************************************************/
222 /* lpfc_config_port_post */
223 /* This routine will do LPFC initialization after the */
224 /* CONFIG_PORT mailbox command. This will be initialized */
225 /* as a SLI layer callback routine. */
226 /* This routine returns 0 on success. Any other return value */
227 /* indicates an error. */
229 /************************************************************************/
231 lpfc_config_port_post(struct lpfc_hba
*phba
)
233 struct lpfc_vport
*vport
= phba
->pport
;
236 struct lpfc_dmabuf
*mp
;
237 struct lpfc_sli
*psli
= &phba
->sli
;
238 uint32_t status
, timeout
;
242 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
244 phba
->link_state
= LPFC_HBA_ERROR
;
249 /* Get login parameters for NID. */
250 lpfc_read_sparam(phba
, pmb
, 0);
252 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
253 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
254 "0448 Adapter failed init, mbxCmd x%x "
255 "READ_SPARM mbxStatus x%x\n",
256 mb
->mbxCommand
, mb
->mbxStatus
);
257 phba
->link_state
= LPFC_HBA_ERROR
;
258 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
259 mempool_free( pmb
, phba
->mbox_mem_pool
);
260 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
265 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
267 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
268 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
270 pmb
->context1
= NULL
;
272 if (phba
->cfg_soft_wwnn
)
273 u64_to_wwn(phba
->cfg_soft_wwnn
,
274 vport
->fc_sparam
.nodeName
.u
.wwn
);
275 if (phba
->cfg_soft_wwpn
)
276 u64_to_wwn(phba
->cfg_soft_wwpn
,
277 vport
->fc_sparam
.portName
.u
.wwn
);
278 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
279 sizeof (struct lpfc_name
));
280 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
281 sizeof (struct lpfc_name
));
282 /* If no serial number in VPD data, use low 6 bytes of WWNN */
283 /* This should be consolidated into parse_vpd ? - mr */
284 if (phba
->SerialNumber
[0] == 0) {
287 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
288 for (i
= 0; i
< 12; i
++) {
290 j
= ((status
& 0xf0) >> 4);
292 phba
->SerialNumber
[i
] =
293 (char)((uint8_t) 0x30 + (uint8_t) j
);
295 phba
->SerialNumber
[i
] =
296 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
300 phba
->SerialNumber
[i
] =
301 (char)((uint8_t) 0x30 + (uint8_t) j
);
303 phba
->SerialNumber
[i
] =
304 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
308 lpfc_read_config(phba
, pmb
);
310 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
311 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
312 "0453 Adapter failed to init, mbxCmd x%x "
313 "READ_CONFIG, mbxStatus x%x\n",
314 mb
->mbxCommand
, mb
->mbxStatus
);
315 phba
->link_state
= LPFC_HBA_ERROR
;
316 mempool_free( pmb
, phba
->mbox_mem_pool
);
320 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
321 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
322 phba
->cfg_hba_queue_depth
=
323 mb
->un
.varRdConfig
.max_xri
+ 1;
325 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
327 /* Get the default values for Model Name and Description */
328 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
330 if ((phba
->cfg_link_speed
> LINK_SPEED_10G
)
331 || ((phba
->cfg_link_speed
== LINK_SPEED_1G
)
332 && !(phba
->lmt
& LMT_1Gb
))
333 || ((phba
->cfg_link_speed
== LINK_SPEED_2G
)
334 && !(phba
->lmt
& LMT_2Gb
))
335 || ((phba
->cfg_link_speed
== LINK_SPEED_4G
)
336 && !(phba
->lmt
& LMT_4Gb
))
337 || ((phba
->cfg_link_speed
== LINK_SPEED_8G
)
338 && !(phba
->lmt
& LMT_8Gb
))
339 || ((phba
->cfg_link_speed
== LINK_SPEED_10G
)
340 && !(phba
->lmt
& LMT_10Gb
))) {
341 /* Reset link speed to auto */
342 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LINK_EVENT
,
343 "1302 Invalid speed for this board: "
344 "Reset link speed to auto: x%x\n",
345 phba
->cfg_link_speed
);
346 phba
->cfg_link_speed
= LINK_SPEED_AUTO
;
349 phba
->link_state
= LPFC_LINK_DOWN
;
351 /* Only process IOCBs on ring 0 till hba_state is READY */
352 if (psli
->ring
[psli
->extra_ring
].cmdringaddr
)
353 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
354 if (psli
->ring
[psli
->fcp_ring
].cmdringaddr
)
355 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
356 if (psli
->ring
[psli
->next_ring
].cmdringaddr
)
357 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
359 /* Post receive buffers for desired rings */
360 if (phba
->sli_rev
!= 3)
361 lpfc_post_rcv_buf(phba
);
363 /* Enable appropriate host interrupts */
364 spin_lock_irq(&phba
->hbalock
);
365 status
= readl(phba
->HCregaddr
);
366 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
367 if (psli
->num_rings
> 0)
368 status
|= HC_R0INT_ENA
;
369 if (psli
->num_rings
> 1)
370 status
|= HC_R1INT_ENA
;
371 if (psli
->num_rings
> 2)
372 status
|= HC_R2INT_ENA
;
373 if (psli
->num_rings
> 3)
374 status
|= HC_R3INT_ENA
;
376 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
377 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
378 status
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
380 writel(status
, phba
->HCregaddr
);
381 readl(phba
->HCregaddr
); /* flush */
382 spin_unlock_irq(&phba
->hbalock
);
385 * Setup the ring 0 (els) timeout handler
387 timeout
= phba
->fc_ratov
<< 1;
388 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
389 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
390 phba
->hb_outstanding
= 0;
391 phba
->last_completion_time
= jiffies
;
393 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
, phba
->cfg_link_speed
);
394 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
396 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
397 lpfc_set_loopback_flag(phba
);
398 if (rc
!= MBX_SUCCESS
) {
399 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
400 "0454 Adapter failed to init, mbxCmd x%x "
401 "INIT_LINK, mbxStatus x%x\n",
402 mb
->mbxCommand
, mb
->mbxStatus
);
404 /* Clear all interrupt enable conditions */
405 writel(0, phba
->HCregaddr
);
406 readl(phba
->HCregaddr
); /* flush */
407 /* Clear all pending interrupts */
408 writel(0xffffffff, phba
->HAregaddr
);
409 readl(phba
->HAregaddr
); /* flush */
411 phba
->link_state
= LPFC_HBA_ERROR
;
413 mempool_free(pmb
, phba
->mbox_mem_pool
);
416 /* MBOX buffer will be freed in mbox compl */
421 /************************************************************************/
423 /* lpfc_hba_down_prep */
424 /* This routine will do LPFC uninitialization before the */
425 /* HBA is reset when bringing down the SLI Layer. This will be */
426 /* initialized as a SLI layer callback routine. */
427 /* This routine returns 0 on success. Any other return value */
428 /* indicates an error. */
430 /************************************************************************/
432 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
434 /* Disable interrupts */
435 writel(0, phba
->HCregaddr
);
436 readl(phba
->HCregaddr
); /* flush */
438 lpfc_cleanup_discovery_resources(phba
->pport
);
442 /************************************************************************/
444 /* lpfc_hba_down_post */
445 /* This routine will do uninitialization after the HBA is reset */
446 /* when bringing down the SLI Layer. */
447 /* This routine returns 0 on success. Any other return value */
448 /* indicates an error. */
450 /************************************************************************/
452 lpfc_hba_down_post(struct lpfc_hba
*phba
)
454 struct lpfc_sli
*psli
= &phba
->sli
;
455 struct lpfc_sli_ring
*pring
;
456 struct lpfc_dmabuf
*mp
, *next_mp
;
459 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
460 lpfc_sli_hbqbuf_free_all(phba
);
462 /* Cleanup preposted buffers on the ELS ring */
463 pring
= &psli
->ring
[LPFC_ELS_RING
];
464 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
466 pring
->postbufq_cnt
--;
467 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
472 for (i
= 0; i
< psli
->num_rings
; i
++) {
473 pring
= &psli
->ring
[i
];
474 lpfc_sli_abort_iocb_ring(phba
, pring
);
480 /* HBA heart beat timeout handler */
482 lpfc_hb_timeout(unsigned long ptr
)
484 struct lpfc_hba
*phba
;
487 phba
= (struct lpfc_hba
*)ptr
;
488 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
489 if (!(phba
->pport
->work_port_events
& WORKER_HB_TMO
))
490 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
491 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
494 wake_up(phba
->work_wait
);
499 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
501 unsigned long drvr_flag
;
503 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
504 phba
->hb_outstanding
= 0;
505 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
507 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
508 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
509 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
510 !(phba
->pport
->load_flag
& FC_UNLOADING
))
511 mod_timer(&phba
->hb_tmofunc
,
512 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
517 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
519 LPFC_MBOXQ_t
*pmboxq
;
521 struct lpfc_sli
*psli
= &phba
->sli
;
523 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
524 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
525 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
528 spin_lock_irq(&phba
->pport
->work_port_lock
);
529 /* If the timer is already canceled do nothing */
530 if (!(phba
->pport
->work_port_events
& WORKER_HB_TMO
)) {
531 spin_unlock_irq(&phba
->pport
->work_port_lock
);
535 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
537 spin_unlock_irq(&phba
->pport
->work_port_lock
);
538 if (!phba
->hb_outstanding
)
539 mod_timer(&phba
->hb_tmofunc
,
540 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
542 mod_timer(&phba
->hb_tmofunc
,
543 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
546 spin_unlock_irq(&phba
->pport
->work_port_lock
);
548 /* If there is no heart beat outstanding, issue a heartbeat command */
549 if (!phba
->hb_outstanding
) {
550 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
552 mod_timer(&phba
->hb_tmofunc
,
553 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
557 lpfc_heart_beat(phba
, pmboxq
);
558 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
559 pmboxq
->vport
= phba
->pport
;
560 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
562 if (retval
!= MBX_BUSY
&& retval
!= MBX_SUCCESS
) {
563 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
564 mod_timer(&phba
->hb_tmofunc
,
565 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
568 mod_timer(&phba
->hb_tmofunc
,
569 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
570 phba
->hb_outstanding
= 1;
574 * If heart beat timeout called with hb_outstanding set we
575 * need to take the HBA offline.
577 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
578 "0459 Adapter heartbeat failure, taking "
579 "this port offline.\n");
581 spin_lock_irq(&phba
->hbalock
);
582 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
583 spin_unlock_irq(&phba
->hbalock
);
585 lpfc_offline_prep(phba
);
587 lpfc_unblock_mgmt_io(phba
);
588 phba
->link_state
= LPFC_HBA_ERROR
;
589 lpfc_hba_down_post(phba
);
593 /************************************************************************/
595 /* lpfc_handle_eratt */
596 /* This routine will handle processing a Host Attention */
597 /* Error Status event. This will be initialized */
598 /* as a SLI layer callback routine. */
600 /************************************************************************/
602 lpfc_handle_eratt(struct lpfc_hba
*phba
)
604 struct lpfc_vport
*vport
= phba
->pport
;
605 struct lpfc_sli
*psli
= &phba
->sli
;
606 struct lpfc_sli_ring
*pring
;
607 struct lpfc_vport
**vports
;
609 struct Scsi_Host
*shost
;
612 /* If the pci channel is offline, ignore possible errors,
613 * since we cannot communicate with the pci card anyway. */
614 if (pci_channel_offline(phba
->pcidev
))
617 if (phba
->work_hs
& HS_FFER6
||
618 phba
->work_hs
& HS_FFER5
) {
619 /* Re-establishing Link */
620 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
621 "1301 Re-establishing Link "
622 "Data: x%x x%x x%x\n",
624 phba
->work_status
[0], phba
->work_status
[1]);
625 vports
= lpfc_create_vport_work_array(phba
);
628 i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
;
630 shost
= lpfc_shost_from_vport(vports
[i
]);
631 spin_lock_irq(shost
->host_lock
);
632 vports
[i
]->fc_flag
|= FC_ESTABLISH_LINK
;
633 spin_unlock_irq(shost
->host_lock
);
635 lpfc_destroy_vport_work_array(vports
);
636 spin_lock_irq(&phba
->hbalock
);
637 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
638 spin_unlock_irq(&phba
->hbalock
);
641 * Firmware stops when it triggled erratt with HS_FFER6.
642 * That could cause the I/Os dropped by the firmware.
643 * Error iocb (I/O) on txcmplq and let the SCSI layer
644 * retry it after re-establishing link.
646 pring
= &psli
->ring
[psli
->fcp_ring
];
647 lpfc_sli_abort_iocb_ring(phba
, pring
);
651 * There was a firmware error. Take the hba offline and then
652 * attempt to restart it.
654 lpfc_offline_prep(phba
);
656 lpfc_sli_brdrestart(phba
);
657 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
658 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
659 lpfc_unblock_mgmt_io(phba
);
662 lpfc_unblock_mgmt_io(phba
);
664 /* The if clause above forces this code path when the status
665 * failure is a value other than FFER6. Do not call the offline
666 * twice. This is the adapter hardware error path.
668 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
669 "0457 Adapter Hardware Error "
670 "Data: x%x x%x x%x\n",
672 phba
->work_status
[0], phba
->work_status
[1]);
674 event_data
= FC_REG_DUMP_EVENT
;
675 shost
= lpfc_shost_from_vport(vport
);
676 fc_host_post_vendor_event(shost
, fc_get_event_number(),
677 sizeof(event_data
), (char *) &event_data
,
678 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
680 spin_lock_irq(&phba
->hbalock
);
681 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
682 spin_unlock_irq(&phba
->hbalock
);
683 lpfc_offline_prep(phba
);
685 lpfc_unblock_mgmt_io(phba
);
686 phba
->link_state
= LPFC_HBA_ERROR
;
687 lpfc_hba_down_post(phba
);
691 /************************************************************************/
693 /* lpfc_handle_latt */
694 /* This routine will handle processing a Host Attention */
695 /* Link Status event. This will be initialized */
696 /* as a SLI layer callback routine. */
698 /************************************************************************/
700 lpfc_handle_latt(struct lpfc_hba
*phba
)
702 struct lpfc_vport
*vport
= phba
->pport
;
703 struct lpfc_sli
*psli
= &phba
->sli
;
705 volatile uint32_t control
;
706 struct lpfc_dmabuf
*mp
;
709 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
711 goto lpfc_handle_latt_err_exit
;
713 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
715 goto lpfc_handle_latt_free_pmb
;
717 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
719 goto lpfc_handle_latt_free_mp
;
723 /* Cleanup any outstanding ELS commands */
724 lpfc_els_flush_all_cmd(phba
);
726 psli
->slistat
.link_event
++;
727 lpfc_read_la(phba
, pmb
, mp
);
728 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_la
;
730 rc
= lpfc_sli_issue_mbox (phba
, pmb
, (MBX_NOWAIT
| MBX_STOP_IOCB
));
731 if (rc
== MBX_NOT_FINISHED
)
732 goto lpfc_handle_latt_free_mbuf
;
734 /* Clear Link Attention in HA REG */
735 spin_lock_irq(&phba
->hbalock
);
736 writel(HA_LATT
, phba
->HAregaddr
);
737 readl(phba
->HAregaddr
); /* flush */
738 spin_unlock_irq(&phba
->hbalock
);
742 lpfc_handle_latt_free_mbuf
:
743 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
744 lpfc_handle_latt_free_mp
:
746 lpfc_handle_latt_free_pmb
:
747 mempool_free(pmb
, phba
->mbox_mem_pool
);
748 lpfc_handle_latt_err_exit
:
749 /* Enable Link attention interrupts */
750 spin_lock_irq(&phba
->hbalock
);
751 psli
->sli_flag
|= LPFC_PROCESS_LA
;
752 control
= readl(phba
->HCregaddr
);
753 control
|= HC_LAINT_ENA
;
754 writel(control
, phba
->HCregaddr
);
755 readl(phba
->HCregaddr
); /* flush */
757 /* Clear Link Attention in HA REG */
758 writel(HA_LATT
, phba
->HAregaddr
);
759 readl(phba
->HAregaddr
); /* flush */
760 spin_unlock_irq(&phba
->hbalock
);
762 phba
->link_state
= LPFC_HBA_ERROR
;
764 /* The other case is an error from issue_mbox */
766 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
767 "0300 READ_LA: no buffers\n");
772 /************************************************************************/
775 /* This routine will parse the VPD data */
777 /************************************************************************/
779 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
781 uint8_t lenlo
, lenhi
;
791 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
792 "0455 Vital Product Data: x%x x%x x%x x%x\n",
793 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
795 while (!finished
&& (index
< (len
- 4))) {
796 switch (vpd
[index
]) {
804 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
813 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
814 if (Length
> len
- index
)
815 Length
= len
- index
;
817 /* Look for Serial Number */
818 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
825 phba
->SerialNumber
[j
++] = vpd
[index
++];
829 phba
->SerialNumber
[j
] = 0;
832 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
833 phba
->vpd_flag
|= VPD_MODEL_DESC
;
840 phba
->ModelDesc
[j
++] = vpd
[index
++];
844 phba
->ModelDesc
[j
] = 0;
847 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
848 phba
->vpd_flag
|= VPD_MODEL_NAME
;
855 phba
->ModelName
[j
++] = vpd
[index
++];
859 phba
->ModelName
[j
] = 0;
862 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
863 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
870 phba
->ProgramType
[j
++] = vpd
[index
++];
874 phba
->ProgramType
[j
] = 0;
877 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
878 phba
->vpd_flag
|= VPD_PORT
;
885 phba
->Port
[j
++] = vpd
[index
++];
915 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
918 uint16_t dev_id
= phba
->pcidev
->device
;
924 } m
= {"<Unknown>", 0, ""};
926 if (mdp
&& mdp
[0] != '\0'
927 && descp
&& descp
[0] != '\0')
930 if (phba
->lmt
& LMT_10Gb
)
932 else if (phba
->lmt
& LMT_8Gb
)
934 else if (phba
->lmt
& LMT_4Gb
)
936 else if (phba
->lmt
& LMT_2Gb
)
944 case PCI_DEVICE_ID_FIREFLY
:
945 m
= (typeof(m
)){"LP6000", max_speed
, "PCI"};
947 case PCI_DEVICE_ID_SUPERFLY
:
948 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
949 m
= (typeof(m
)){"LP7000", max_speed
, "PCI"};
951 m
= (typeof(m
)){"LP7000E", max_speed
, "PCI"};
953 case PCI_DEVICE_ID_DRAGONFLY
:
954 m
= (typeof(m
)){"LP8000", max_speed
, "PCI"};
956 case PCI_DEVICE_ID_CENTAUR
:
957 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
958 m
= (typeof(m
)){"LP9002", max_speed
, "PCI"};
960 m
= (typeof(m
)){"LP9000", max_speed
, "PCI"};
962 case PCI_DEVICE_ID_RFLY
:
963 m
= (typeof(m
)){"LP952", max_speed
, "PCI"};
965 case PCI_DEVICE_ID_PEGASUS
:
966 m
= (typeof(m
)){"LP9802", max_speed
, "PCI-X"};
968 case PCI_DEVICE_ID_THOR
:
969 m
= (typeof(m
)){"LP10000", max_speed
, "PCI-X"};
971 case PCI_DEVICE_ID_VIPER
:
972 m
= (typeof(m
)){"LPX1000", max_speed
, "PCI-X"};
974 case PCI_DEVICE_ID_PFLY
:
975 m
= (typeof(m
)){"LP982", max_speed
, "PCI-X"};
977 case PCI_DEVICE_ID_TFLY
:
978 m
= (typeof(m
)){"LP1050", max_speed
, "PCI-X"};
980 case PCI_DEVICE_ID_HELIOS
:
981 m
= (typeof(m
)){"LP11000", max_speed
, "PCI-X2"};
983 case PCI_DEVICE_ID_HELIOS_SCSP
:
984 m
= (typeof(m
)){"LP11000-SP", max_speed
, "PCI-X2"};
986 case PCI_DEVICE_ID_HELIOS_DCSP
:
987 m
= (typeof(m
)){"LP11002-SP", max_speed
, "PCI-X2"};
989 case PCI_DEVICE_ID_NEPTUNE
:
990 m
= (typeof(m
)){"LPe1000", max_speed
, "PCIe"};
992 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
993 m
= (typeof(m
)){"LPe1000-SP", max_speed
, "PCIe"};
995 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
996 m
= (typeof(m
)){"LPe1002-SP", max_speed
, "PCIe"};
998 case PCI_DEVICE_ID_BMID
:
999 m
= (typeof(m
)){"LP1150", max_speed
, "PCI-X2"};
1001 case PCI_DEVICE_ID_BSMB
:
1002 m
= (typeof(m
)){"LP111", max_speed
, "PCI-X2"};
1004 case PCI_DEVICE_ID_ZEPHYR
:
1005 m
= (typeof(m
)){"LPe11000", max_speed
, "PCIe"};
1007 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1008 m
= (typeof(m
)){"LPe11000", max_speed
, "PCIe"};
1010 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1011 m
= (typeof(m
)){"LPe11002-SP", max_speed
, "PCIe"};
1013 case PCI_DEVICE_ID_ZMID
:
1014 m
= (typeof(m
)){"LPe1150", max_speed
, "PCIe"};
1016 case PCI_DEVICE_ID_ZSMB
:
1017 m
= (typeof(m
)){"LPe111", max_speed
, "PCIe"};
1019 case PCI_DEVICE_ID_LP101
:
1020 m
= (typeof(m
)){"LP101", max_speed
, "PCI-X"};
1022 case PCI_DEVICE_ID_LP10000S
:
1023 m
= (typeof(m
)){"LP10000-S", max_speed
, "PCI"};
1025 case PCI_DEVICE_ID_LP11000S
:
1026 m
= (typeof(m
)){"LP11000-S", max_speed
,
1029 case PCI_DEVICE_ID_LPE11000S
:
1030 m
= (typeof(m
)){"LPe11000-S", max_speed
,
1033 case PCI_DEVICE_ID_SAT
:
1034 m
= (typeof(m
)){"LPe12000", max_speed
, "PCIe"};
1036 case PCI_DEVICE_ID_SAT_MID
:
1037 m
= (typeof(m
)){"LPe1250", max_speed
, "PCIe"};
1039 case PCI_DEVICE_ID_SAT_SMB
:
1040 m
= (typeof(m
)){"LPe121", max_speed
, "PCIe"};
1042 case PCI_DEVICE_ID_SAT_DCSP
:
1043 m
= (typeof(m
)){"LPe12002-SP", max_speed
, "PCIe"};
1045 case PCI_DEVICE_ID_SAT_SCSP
:
1046 m
= (typeof(m
)){"LPe12000-SP", max_speed
, "PCIe"};
1048 case PCI_DEVICE_ID_SAT_S
:
1049 m
= (typeof(m
)){"LPe12000-S", max_speed
, "PCIe"};
1052 m
= (typeof(m
)){ NULL
};
1056 if (mdp
&& mdp
[0] == '\0')
1057 snprintf(mdp
, 79,"%s", m
.name
);
1058 if (descp
&& descp
[0] == '\0')
1059 snprintf(descp
, 255,
1060 "Emulex %s %dGb %s Fibre Channel Adapter",
1061 m
.name
, m
.max_speed
, m
.bus
);
1064 /**************************************************/
1065 /* lpfc_post_buffer */
1067 /* This routine will post count buffers to the */
1068 /* ring with the QUE_RING_BUF_CN command. This */
1069 /* allows 3 buffers / command to be posted. */
1070 /* Returns the number of buffers NOT posted. */
1071 /**************************************************/
1073 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
,
1077 struct lpfc_iocbq
*iocb
;
1078 struct lpfc_dmabuf
*mp1
, *mp2
;
1080 cnt
+= pring
->missbufcnt
;
1082 /* While there are buffers to post */
1084 /* Allocate buffer for command iocb */
1085 iocb
= lpfc_sli_get_iocbq(phba
);
1087 pring
->missbufcnt
= cnt
;
1092 /* 2 buffers can be posted per command */
1093 /* Allocate buffer to post */
1094 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1096 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1098 if (mp1
== 0 || mp1
->virt
== 0) {
1100 lpfc_sli_release_iocbq(phba
, iocb
);
1101 pring
->missbufcnt
= cnt
;
1105 INIT_LIST_HEAD(&mp1
->list
);
1106 /* Allocate buffer to post */
1108 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1110 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1112 if (mp2
== 0 || mp2
->virt
== 0) {
1114 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1116 lpfc_sli_release_iocbq(phba
, iocb
);
1117 pring
->missbufcnt
= cnt
;
1121 INIT_LIST_HEAD(&mp2
->list
);
1126 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
1127 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
1128 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
1129 icmd
->ulpBdeCount
= 1;
1132 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
1133 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
1134 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
1136 icmd
->ulpBdeCount
= 2;
1139 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
1142 if (lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0) == IOCB_ERROR
) {
1143 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1147 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
1151 lpfc_sli_release_iocbq(phba
, iocb
);
1152 pring
->missbufcnt
= cnt
;
1155 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
1157 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
1159 pring
->missbufcnt
= 0;
1163 /************************************************************************/
1165 /* lpfc_post_rcv_buf */
1166 /* This routine post initial rcv buffers to the configured rings */
1168 /************************************************************************/
1170 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
1172 struct lpfc_sli
*psli
= &phba
->sli
;
1174 /* Ring 0, ELS / CT buffers */
1175 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
, 1);
1176 /* Ring 2 - FCP no buffers needed */
1181 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1183 /************************************************************************/
1187 /************************************************************************/
1189 lpfc_sha_init(uint32_t * HashResultPointer
)
1191 HashResultPointer
[0] = 0x67452301;
1192 HashResultPointer
[1] = 0xEFCDAB89;
1193 HashResultPointer
[2] = 0x98BADCFE;
1194 HashResultPointer
[3] = 0x10325476;
1195 HashResultPointer
[4] = 0xC3D2E1F0;
1198 /************************************************************************/
1200 /* lpfc_sha_iterate */
1202 /************************************************************************/
1204 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
1208 uint32_t A
, B
, C
, D
, E
;
1211 HashWorkingPointer
[t
] =
1213 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
1215 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
1216 } while (++t
<= 79);
1218 A
= HashResultPointer
[0];
1219 B
= HashResultPointer
[1];
1220 C
= HashResultPointer
[2];
1221 D
= HashResultPointer
[3];
1222 E
= HashResultPointer
[4];
1226 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
1227 } else if (t
< 40) {
1228 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
1229 } else if (t
< 60) {
1230 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
1232 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
1234 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
1240 } while (++t
<= 79);
1242 HashResultPointer
[0] += A
;
1243 HashResultPointer
[1] += B
;
1244 HashResultPointer
[2] += C
;
1245 HashResultPointer
[3] += D
;
1246 HashResultPointer
[4] += E
;
1250 /************************************************************************/
1252 /* lpfc_challenge_key */
1254 /************************************************************************/
1256 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
1258 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
1261 /************************************************************************/
1265 /************************************************************************/
1267 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
1270 uint32_t *HashWorking
;
1271 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
1273 HashWorking
= kmalloc(80 * sizeof(uint32_t), GFP_KERNEL
);
1277 memset(HashWorking
, 0, (80 * sizeof(uint32_t)));
1278 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
1279 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
1281 for (t
= 0; t
< 7; t
++)
1282 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
1284 lpfc_sha_init(hbainit
);
1285 lpfc_sha_iterate(hbainit
, HashWorking
);
1290 lpfc_cleanup(struct lpfc_vport
*vport
)
1292 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1294 /* clean up phba - lpfc specific */
1295 lpfc_can_disctmo(vport
);
1296 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
)
1302 lpfc_establish_link_tmo(unsigned long ptr
)
1304 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
1305 struct lpfc_vport
**vports
;
1306 unsigned long iflag
;
1309 /* Re-establishing Link, timer expired */
1310 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1311 "1300 Re-establishing Link, timer expired "
1313 phba
->pport
->fc_flag
, phba
->pport
->port_state
);
1314 vports
= lpfc_create_vport_work_array(phba
);
1316 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1317 struct Scsi_Host
*shost
;
1318 shost
= lpfc_shost_from_vport(vports
[i
]);
1319 spin_lock_irqsave(shost
->host_lock
, iflag
);
1320 vports
[i
]->fc_flag
&= ~FC_ESTABLISH_LINK
;
1321 spin_unlock_irqrestore(shost
->host_lock
, iflag
);
1323 lpfc_destroy_vport_work_array(vports
);
1327 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
1329 del_timer_sync(&vport
->els_tmofunc
);
1330 del_timer_sync(&vport
->fc_fdmitmo
);
1331 lpfc_can_disctmo(vport
);
1336 lpfc_stop_phba_timers(struct lpfc_hba
*phba
)
1338 del_timer_sync(&phba
->fcp_poll_timer
);
1339 del_timer_sync(&phba
->fc_estabtmo
);
1340 lpfc_stop_vport_timers(phba
->pport
);
1341 del_timer_sync(&phba
->sli
.mbox_tmo
);
1342 del_timer_sync(&phba
->fabric_block_timer
);
1343 phba
->hb_outstanding
= 0;
1344 del_timer_sync(&phba
->hb_tmofunc
);
1349 lpfc_online(struct lpfc_hba
*phba
)
1351 struct lpfc_vport
*vport
= phba
->pport
;
1352 struct lpfc_vport
**vports
;
1358 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
1361 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1362 "0458 Bring Adapter online\n");
1364 lpfc_block_mgmt_io(phba
);
1366 if (!lpfc_sli_queue_setup(phba
)) {
1367 lpfc_unblock_mgmt_io(phba
);
1371 if (lpfc_sli_hba_setup(phba
)) { /* Initialize the HBA */
1372 lpfc_unblock_mgmt_io(phba
);
1376 vports
= lpfc_create_vport_work_array(phba
);
1378 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1379 struct Scsi_Host
*shost
;
1380 shost
= lpfc_shost_from_vport(vports
[i
]);
1381 spin_lock_irq(shost
->host_lock
);
1382 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
1383 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
1384 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
1385 spin_unlock_irq(shost
->host_lock
);
1387 lpfc_destroy_vport_work_array(vports
);
1389 lpfc_unblock_mgmt_io(phba
);
1394 lpfc_block_mgmt_io(struct lpfc_hba
* phba
)
1396 unsigned long iflag
;
1398 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1399 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
1400 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1404 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
1406 unsigned long iflag
;
1408 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1409 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
1410 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1414 lpfc_offline_prep(struct lpfc_hba
* phba
)
1416 struct lpfc_vport
*vport
= phba
->pport
;
1417 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1419 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
1422 lpfc_block_mgmt_io(phba
);
1424 lpfc_linkdown(phba
);
1426 /* Issue an unreg_login to all nodes */
1427 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
)
1428 if (ndlp
->nlp_state
!= NLP_STE_UNUSED_NODE
)
1429 lpfc_unreg_rpi(vport
, ndlp
);
1431 lpfc_sli_flush_mbox_queue(phba
);
1435 lpfc_offline(struct lpfc_hba
*phba
)
1437 struct Scsi_Host
*shost
;
1438 struct lpfc_vport
**vports
;
1441 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1444 /* stop all timers associated with this hba */
1445 lpfc_stop_phba_timers(phba
);
1446 vports
= lpfc_create_vport_work_array(phba
);
1448 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++)
1449 lpfc_stop_vport_timers(vports
[i
]);
1450 lpfc_destroy_vport_work_array(vports
);
1451 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1452 "0460 Bring Adapter offline\n");
1453 /* Bring down the SLI Layer and cleanup. The HBA is offline
1455 lpfc_sli_hba_down(phba
);
1456 spin_lock_irq(&phba
->hbalock
);
1458 spin_unlock_irq(&phba
->hbalock
);
1459 vports
= lpfc_create_vport_work_array(phba
);
1461 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1462 shost
= lpfc_shost_from_vport(vports
[i
]);
1463 lpfc_cleanup(vports
[i
]);
1464 spin_lock_irq(shost
->host_lock
);
1465 vports
[i
]->work_port_events
= 0;
1466 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
1467 spin_unlock_irq(shost
->host_lock
);
1469 lpfc_destroy_vport_work_array(vports
);
1472 /******************************************************************************
1473 * Function name: lpfc_scsi_free
1475 * Description: Called from lpfc_pci_remove_one free internal driver resources
1477 ******************************************************************************/
1479 lpfc_scsi_free(struct lpfc_hba
*phba
)
1481 struct lpfc_scsi_buf
*sb
, *sb_next
;
1482 struct lpfc_iocbq
*io
, *io_next
;
1484 spin_lock_irq(&phba
->hbalock
);
1485 /* Release all the lpfc_scsi_bufs maintained by this host. */
1486 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
1487 list_del(&sb
->list
);
1488 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
1491 phba
->total_scsi_bufs
--;
1494 /* Release all the lpfc_iocbq entries maintained by this host. */
1495 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
1496 list_del(&io
->list
);
1498 phba
->total_iocbq_bufs
--;
1501 spin_unlock_irq(&phba
->hbalock
);
1507 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
1509 struct lpfc_vport
*vport
;
1510 struct Scsi_Host
*shost
;
1513 if (dev
!= &phba
->pcidev
->dev
)
1514 shost
= scsi_host_alloc(&lpfc_vport_template
,
1515 sizeof(struct lpfc_vport
));
1517 shost
= scsi_host_alloc(&lpfc_template
,
1518 sizeof(struct lpfc_vport
));
1522 vport
= (struct lpfc_vport
*) shost
->hostdata
;
1525 vport
->load_flag
|= FC_LOADING
;
1526 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
1528 lpfc_get_vport_cfgparam(vport
);
1529 shost
->unique_id
= instance
;
1530 shost
->max_id
= LPFC_MAX_TARGET
;
1531 shost
->max_lun
= vport
->cfg_max_luns
;
1532 shost
->this_id
= -1;
1533 shost
->max_cmd_len
= 16;
1535 * Set initial can_queue value since 0 is no longer supported and
1536 * scsi_add_host will fail. This will be adjusted later based on the
1537 * max xri value determined in hba setup.
1539 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
1540 if (dev
!= &phba
->pcidev
->dev
) {
1541 shost
->transportt
= lpfc_vport_transport_template
;
1542 vport
->port_type
= LPFC_NPIV_PORT
;
1544 shost
->transportt
= lpfc_transport_template
;
1545 vport
->port_type
= LPFC_PHYSICAL_PORT
;
1548 /* Initialize all internally managed lists. */
1549 INIT_LIST_HEAD(&vport
->fc_nodes
);
1550 spin_lock_init(&vport
->work_port_lock
);
1552 init_timer(&vport
->fc_disctmo
);
1553 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
1554 vport
->fc_disctmo
.data
= (unsigned long)vport
;
1556 init_timer(&vport
->fc_fdmitmo
);
1557 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
1558 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
1560 init_timer(&vport
->els_tmofunc
);
1561 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
1562 vport
->els_tmofunc
.data
= (unsigned long)vport
;
1564 error
= scsi_add_host(shost
, dev
);
1568 spin_lock_irq(&phba
->hbalock
);
1569 list_add_tail(&vport
->listentry
, &phba
->port_list
);
1570 spin_unlock_irq(&phba
->hbalock
);
1574 scsi_host_put(shost
);
1580 destroy_port(struct lpfc_vport
*vport
)
1582 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1583 struct lpfc_hba
*phba
= vport
->phba
;
1585 kfree(vport
->vname
);
1587 lpfc_debugfs_terminate(vport
);
1588 fc_remove_host(shost
);
1589 scsi_remove_host(shost
);
1591 spin_lock_irq(&phba
->hbalock
);
1592 list_del_init(&vport
->listentry
);
1593 spin_unlock_irq(&phba
->hbalock
);
1595 lpfc_cleanup(vport
);
1600 lpfc_get_instance(void)
1604 /* Assign an unused number */
1605 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
1607 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
1613 * Note: there is no scan_start function as adapter initialization
1614 * will have asynchronously kicked off the link initialization.
1617 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1619 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1620 struct lpfc_hba
*phba
= vport
->phba
;
1623 spin_lock_irq(shost
->host_lock
);
1625 if (vport
->load_flag
& FC_UNLOADING
) {
1629 if (time
>= 30 * HZ
) {
1630 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1631 "0461 Scanning longer than 30 "
1632 "seconds. Continuing initialization\n");
1636 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
1637 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1638 "0465 Link down longer than 15 "
1639 "seconds. Continuing initialization\n");
1644 if (vport
->port_state
!= LPFC_VPORT_READY
)
1646 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
1648 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
1650 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
1656 spin_unlock_irq(shost
->host_lock
);
1660 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
1662 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1663 struct lpfc_hba
*phba
= vport
->phba
;
1665 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1668 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
1669 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
1670 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
1672 memset(fc_host_supported_fc4s(shost
), 0,
1673 sizeof(fc_host_supported_fc4s(shost
)));
1674 fc_host_supported_fc4s(shost
)[2] = 1;
1675 fc_host_supported_fc4s(shost
)[7] = 1;
1677 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
1678 sizeof fc_host_symbolic_name(shost
));
1680 fc_host_supported_speeds(shost
) = 0;
1681 if (phba
->lmt
& LMT_10Gb
)
1682 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
1683 if (phba
->lmt
& LMT_4Gb
)
1684 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
1685 if (phba
->lmt
& LMT_2Gb
)
1686 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
1687 if (phba
->lmt
& LMT_1Gb
)
1688 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
1690 fc_host_maxframe_size(shost
) =
1691 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
1692 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
1694 /* This value is also unchanging */
1695 memset(fc_host_active_fc4s(shost
), 0,
1696 sizeof(fc_host_active_fc4s(shost
)));
1697 fc_host_active_fc4s(shost
)[2] = 1;
1698 fc_host_active_fc4s(shost
)[7] = 1;
1700 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
1701 spin_lock_irq(shost
->host_lock
);
1702 vport
->load_flag
&= ~FC_LOADING
;
1703 spin_unlock_irq(shost
->host_lock
);
1706 static int __devinit
1707 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
1709 struct lpfc_vport
*vport
= NULL
;
1710 struct lpfc_hba
*phba
;
1711 struct lpfc_sli
*psli
;
1712 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
1713 struct Scsi_Host
*shost
= NULL
;
1715 unsigned long bar0map_len
, bar2map_len
;
1716 int error
= -ENODEV
;
1720 if (pci_enable_device(pdev
))
1722 if (pci_request_regions(pdev
, LPFC_DRIVER_NAME
))
1723 goto out_disable_device
;
1725 phba
= kzalloc(sizeof (struct lpfc_hba
), GFP_KERNEL
);
1727 goto out_release_regions
;
1729 spin_lock_init(&phba
->hbalock
);
1731 phba
->pcidev
= pdev
;
1733 /* Assign an unused board number */
1734 if ((phba
->brd_no
= lpfc_get_instance()) < 0)
1737 INIT_LIST_HEAD(&phba
->port_list
);
1739 * Get all the module params for configuring this host and then
1740 * establish the host.
1742 lpfc_get_cfgparam(phba
);
1743 phba
->max_vpi
= LPFC_MAX_VPI
;
1745 /* Initialize timers used by driver */
1746 init_timer(&phba
->fc_estabtmo
);
1747 phba
->fc_estabtmo
.function
= lpfc_establish_link_tmo
;
1748 phba
->fc_estabtmo
.data
= (unsigned long)phba
;
1750 init_timer(&phba
->hb_tmofunc
);
1751 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
1752 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
1755 init_timer(&psli
->mbox_tmo
);
1756 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
1757 psli
->mbox_tmo
.data
= (unsigned long) phba
;
1758 init_timer(&phba
->fcp_poll_timer
);
1759 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
1760 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
1761 init_timer(&phba
->fabric_block_timer
);
1762 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
1763 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
1765 pci_set_master(pdev
);
1766 pci_try_set_mwi(pdev
);
1768 if (pci_set_dma_mask(phba
->pcidev
, DMA_64BIT_MASK
) != 0)
1769 if (pci_set_dma_mask(phba
->pcidev
, DMA_32BIT_MASK
) != 0)
1770 goto out_idr_remove
;
1773 * Get the bus address of Bar0 and Bar2 and the number of bytes
1774 * required by each mapping.
1776 phba
->pci_bar0_map
= pci_resource_start(phba
->pcidev
, 0);
1777 bar0map_len
= pci_resource_len(phba
->pcidev
, 0);
1779 phba
->pci_bar2_map
= pci_resource_start(phba
->pcidev
, 2);
1780 bar2map_len
= pci_resource_len(phba
->pcidev
, 2);
1782 /* Map HBA SLIM to a kernel virtual address. */
1783 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
1784 if (!phba
->slim_memmap_p
) {
1786 dev_printk(KERN_ERR
, &pdev
->dev
,
1787 "ioremap failed for SLIM memory.\n");
1788 goto out_idr_remove
;
1791 /* Map HBA Control Registers to a kernel virtual address. */
1792 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
1793 if (!phba
->ctrl_regs_memmap_p
) {
1795 dev_printk(KERN_ERR
, &pdev
->dev
,
1796 "ioremap failed for HBA control registers.\n");
1797 goto out_iounmap_slim
;
1800 /* Allocate memory for SLI-2 structures */
1801 phba
->slim2p
= dma_alloc_coherent(&phba
->pcidev
->dev
, SLI2_SLIM_SIZE
,
1802 &phba
->slim2p_mapping
, GFP_KERNEL
);
1806 memset(phba
->slim2p
, 0, SLI2_SLIM_SIZE
);
1808 phba
->hbqslimp
.virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
1809 lpfc_sli_hbq_size(),
1810 &phba
->hbqslimp
.phys
,
1812 if (!phba
->hbqslimp
.virt
)
1815 hbq_count
= lpfc_sli_hbq_count();
1816 ptr
= phba
->hbqslimp
.virt
;
1817 for (i
= 0; i
< hbq_count
; ++i
) {
1818 phba
->hbqs
[i
].hbq_virt
= ptr
;
1819 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
1820 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
1821 sizeof(struct lpfc_hbq_entry
));
1823 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
1824 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
1826 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
1828 /* Initialize the SLI Layer to run with lpfc HBAs. */
1829 lpfc_sli_setup(phba
);
1830 lpfc_sli_queue_setup(phba
);
1832 error
= lpfc_mem_alloc(phba
);
1834 goto out_free_hbqslimp
;
1836 /* Initialize and populate the iocb list per host. */
1837 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
1838 for (i
= 0; i
< LPFC_IOCB_LIST_CNT
; i
++) {
1839 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
1840 if (iocbq_entry
== NULL
) {
1841 printk(KERN_ERR
"%s: only allocated %d iocbs of "
1842 "expected %d count. Unloading driver.\n",
1843 __FUNCTION__
, i
, LPFC_IOCB_LIST_CNT
);
1845 goto out_free_iocbq
;
1848 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
1850 kfree (iocbq_entry
);
1851 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
1852 "Unloading driver.\n",
1855 goto out_free_iocbq
;
1858 spin_lock_irq(&phba
->hbalock
);
1859 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
1860 phba
->total_iocbq_bufs
++;
1861 spin_unlock_irq(&phba
->hbalock
);
1864 /* Initialize HBA structure */
1865 phba
->fc_edtov
= FF_DEF_EDTOV
;
1866 phba
->fc_ratov
= FF_DEF_RATOV
;
1867 phba
->fc_altov
= FF_DEF_ALTOV
;
1868 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
1870 INIT_LIST_HEAD(&phba
->work_list
);
1871 phba
->work_ha_mask
= (HA_ERATT
|HA_MBATT
|HA_LATT
);
1872 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
1874 /* Startup the kernel thread for this host adapter. */
1875 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
1876 "lpfc_worker_%d", phba
->brd_no
);
1877 if (IS_ERR(phba
->worker_thread
)) {
1878 error
= PTR_ERR(phba
->worker_thread
);
1879 goto out_free_iocbq
;
1882 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1883 spin_lock_init(&phba
->scsi_buf_list_lock
);
1884 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
1886 /* Initialize list of fabric iocbs */
1887 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
1889 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
1891 goto out_kthread_stop
;
1893 shost
= lpfc_shost_from_vport(vport
);
1894 phba
->pport
= vport
;
1895 lpfc_debugfs_initialize(vport
);
1897 pci_set_drvdata(pdev
, shost
);
1899 if (phba
->cfg_use_msi
) {
1900 error
= pci_enable_msi(phba
->pcidev
);
1902 phba
->using_msi
= 1;
1904 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1905 "0452 Enable MSI failed, continuing "
1909 error
= request_irq(phba
->pcidev
->irq
, lpfc_intr_handler
, IRQF_SHARED
,
1910 LPFC_DRIVER_NAME
, phba
);
1912 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1913 "0451 Enable interrupt handler failed\n");
1914 goto out_disable_msi
;
1917 phba
->MBslimaddr
= phba
->slim_memmap_p
;
1918 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
1919 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
1920 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
1921 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
1923 if (lpfc_alloc_sysfs_attr(vport
))
1926 if (lpfc_sli_hba_setup(phba
))
1927 goto out_remove_device
;
1930 * hba setup may have changed the hba_queue_depth so we need to adjust
1931 * the value of can_queue.
1933 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
1935 lpfc_host_attrib_init(shost
);
1937 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1938 spin_lock_irq(shost
->host_lock
);
1939 lpfc_poll_start_timer(phba
);
1940 spin_unlock_irq(shost
->host_lock
);
1943 scsi_scan_host(shost
);
1948 lpfc_free_sysfs_attr(vport
);
1949 spin_lock_irq(shost
->host_lock
);
1950 vport
->load_flag
|= FC_UNLOADING
;
1951 spin_unlock_irq(shost
->host_lock
);
1953 lpfc_stop_phba_timers(phba
);
1954 phba
->pport
->work_port_events
= 0;
1955 free_irq(phba
->pcidev
->irq
, phba
);
1957 if (phba
->using_msi
)
1958 pci_disable_msi(phba
->pcidev
);
1959 destroy_port(vport
);
1961 kthread_stop(phba
->worker_thread
);
1963 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
1964 &phba
->lpfc_iocb_list
, list
) {
1966 phba
->total_iocbq_bufs
--;
1968 lpfc_mem_free(phba
);
1970 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(), phba
->hbqslimp
.virt
,
1971 phba
->hbqslimp
.phys
);
1973 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
, phba
->slim2p
,
1974 phba
->slim2p_mapping
);
1976 iounmap(phba
->ctrl_regs_memmap_p
);
1978 iounmap(phba
->slim_memmap_p
);
1980 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
1983 out_release_regions
:
1984 pci_release_regions(pdev
);
1986 pci_disable_device(pdev
);
1988 pci_set_drvdata(pdev
, NULL
);
1990 scsi_host_put(shost
);
1994 static void __devexit
1995 lpfc_pci_remove_one(struct pci_dev
*pdev
)
1997 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
1998 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1999 struct lpfc_hba
*phba
= vport
->phba
;
2000 spin_lock_irq(&phba
->hbalock
);
2001 vport
->load_flag
|= FC_UNLOADING
;
2002 spin_unlock_irq(&phba
->hbalock
);
2004 kfree(vport
->vname
);
2005 lpfc_free_sysfs_attr(vport
);
2007 fc_remove_host(shost
);
2008 scsi_remove_host(shost
);
2010 * Bring down the SLI Layer. This step disable all interrupts,
2011 * clears the rings, discards all mailbox commands, and resets
2014 lpfc_sli_hba_down(phba
);
2015 lpfc_sli_brdrestart(phba
);
2017 lpfc_stop_phba_timers(phba
);
2018 spin_lock_irq(&phba
->hbalock
);
2019 list_del_init(&vport
->listentry
);
2020 spin_unlock_irq(&phba
->hbalock
);
2022 lpfc_debugfs_terminate(vport
);
2023 lpfc_cleanup(vport
);
2025 kthread_stop(phba
->worker_thread
);
2027 /* Release the irq reservation */
2028 free_irq(phba
->pcidev
->irq
, phba
);
2029 if (phba
->using_msi
)
2030 pci_disable_msi(phba
->pcidev
);
2032 pci_set_drvdata(pdev
, NULL
);
2033 scsi_host_put(shost
);
2036 * Call scsi_free before mem_free since scsi bufs are released to their
2037 * corresponding pools here.
2039 lpfc_scsi_free(phba
);
2040 lpfc_mem_free(phba
);
2042 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(), phba
->hbqslimp
.virt
,
2043 phba
->hbqslimp
.phys
);
2045 /* Free resources associated with SLI2 interface */
2046 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
2047 phba
->slim2p
, phba
->slim2p_mapping
);
2049 /* unmap adapter SLIM and Control Registers */
2050 iounmap(phba
->ctrl_regs_memmap_p
);
2051 iounmap(phba
->slim_memmap_p
);
2053 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
2057 pci_release_regions(pdev
);
2058 pci_disable_device(pdev
);
2062 * lpfc_io_error_detected - called when PCI error is detected
2063 * @pdev: Pointer to PCI device
2064 * @state: The current pci conneection state
2066 * This function is called after a PCI bus error affecting
2067 * this device has been detected.
2069 static pci_ers_result_t
lpfc_io_error_detected(struct pci_dev
*pdev
,
2070 pci_channel_state_t state
)
2072 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2073 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2074 struct lpfc_sli
*psli
= &phba
->sli
;
2075 struct lpfc_sli_ring
*pring
;
2077 if (state
== pci_channel_io_perm_failure
)
2078 return PCI_ERS_RESULT_DISCONNECT
;
2080 pci_disable_device(pdev
);
2082 * There may be I/Os dropped by the firmware.
2083 * Error iocb (I/O) on txcmplq and let the SCSI layer
2084 * retry it after re-establishing link.
2086 pring
= &psli
->ring
[psli
->fcp_ring
];
2087 lpfc_sli_abort_iocb_ring(phba
, pring
);
2089 /* Release the irq reservation */
2090 free_irq(phba
->pcidev
->irq
, phba
);
2091 if (phba
->using_msi
)
2092 pci_disable_msi(phba
->pcidev
);
2094 /* Request a slot reset. */
2095 return PCI_ERS_RESULT_NEED_RESET
;
2099 * lpfc_io_slot_reset - called after the pci bus has been reset.
2100 * @pdev: Pointer to PCI device
2102 * Restart the card from scratch, as if from a cold-boot.
2104 static pci_ers_result_t
lpfc_io_slot_reset(struct pci_dev
*pdev
)
2106 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2107 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2108 struct lpfc_sli
*psli
= &phba
->sli
;
2109 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2111 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
2112 if (pci_enable_device_bars(pdev
, bars
)) {
2113 printk(KERN_ERR
"lpfc: Cannot re-enable "
2114 "PCI device after reset.\n");
2115 return PCI_ERS_RESULT_DISCONNECT
;
2118 pci_set_master(pdev
);
2120 /* Re-establishing Link */
2121 spin_lock_irq(shost
->host_lock
);
2122 phba
->pport
->fc_flag
|= FC_ESTABLISH_LINK
;
2123 spin_unlock_irq(shost
->host_lock
);
2125 spin_lock_irq(&phba
->hbalock
);
2126 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2127 spin_unlock_irq(&phba
->hbalock
);
2130 /* Take device offline; this will perform cleanup */
2132 lpfc_sli_brdrestart(phba
);
2134 return PCI_ERS_RESULT_RECOVERED
;
2138 * lpfc_io_resume - called when traffic can start flowing again.
2139 * @pdev: Pointer to PCI device
2141 * This callback is called when the error recovery driver tells us that
2142 * its OK to resume normal operation.
2144 static void lpfc_io_resume(struct pci_dev
*pdev
)
2146 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
2147 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2149 if (lpfc_online(phba
) == 0) {
2150 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
2154 static struct pci_device_id lpfc_id_table
[] = {
2155 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
2156 PCI_ANY_ID
, PCI_ANY_ID
, },
2157 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
2158 PCI_ANY_ID
, PCI_ANY_ID
, },
2159 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
2160 PCI_ANY_ID
, PCI_ANY_ID
, },
2161 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
2162 PCI_ANY_ID
, PCI_ANY_ID
, },
2163 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
2164 PCI_ANY_ID
, PCI_ANY_ID
, },
2165 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
2166 PCI_ANY_ID
, PCI_ANY_ID
, },
2167 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
2168 PCI_ANY_ID
, PCI_ANY_ID
, },
2169 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
2170 PCI_ANY_ID
, PCI_ANY_ID
, },
2171 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
2172 PCI_ANY_ID
, PCI_ANY_ID
, },
2173 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
2174 PCI_ANY_ID
, PCI_ANY_ID
, },
2175 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
2176 PCI_ANY_ID
, PCI_ANY_ID
, },
2177 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
2178 PCI_ANY_ID
, PCI_ANY_ID
, },
2179 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
2180 PCI_ANY_ID
, PCI_ANY_ID
, },
2181 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
2182 PCI_ANY_ID
, PCI_ANY_ID
, },
2183 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
2184 PCI_ANY_ID
, PCI_ANY_ID
, },
2185 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
2186 PCI_ANY_ID
, PCI_ANY_ID
, },
2187 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
2188 PCI_ANY_ID
, PCI_ANY_ID
, },
2189 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
2190 PCI_ANY_ID
, PCI_ANY_ID
, },
2191 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
2192 PCI_ANY_ID
, PCI_ANY_ID
, },
2193 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
2194 PCI_ANY_ID
, PCI_ANY_ID
, },
2195 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
2196 PCI_ANY_ID
, PCI_ANY_ID
, },
2197 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
2198 PCI_ANY_ID
, PCI_ANY_ID
, },
2199 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
2200 PCI_ANY_ID
, PCI_ANY_ID
, },
2201 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
2202 PCI_ANY_ID
, PCI_ANY_ID
, },
2203 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
2204 PCI_ANY_ID
, PCI_ANY_ID
, },
2205 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
2206 PCI_ANY_ID
, PCI_ANY_ID
, },
2207 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
2208 PCI_ANY_ID
, PCI_ANY_ID
, },
2209 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
2210 PCI_ANY_ID
, PCI_ANY_ID
, },
2211 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
2212 PCI_ANY_ID
, PCI_ANY_ID
, },
2213 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
2214 PCI_ANY_ID
, PCI_ANY_ID
, },
2215 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
2216 PCI_ANY_ID
, PCI_ANY_ID
, },
2217 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
2218 PCI_ANY_ID
, PCI_ANY_ID
, },
2219 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
2220 PCI_ANY_ID
, PCI_ANY_ID
, },
2224 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
2226 static struct pci_error_handlers lpfc_err_handler
= {
2227 .error_detected
= lpfc_io_error_detected
,
2228 .slot_reset
= lpfc_io_slot_reset
,
2229 .resume
= lpfc_io_resume
,
2232 static struct pci_driver lpfc_driver
= {
2233 .name
= LPFC_DRIVER_NAME
,
2234 .id_table
= lpfc_id_table
,
2235 .probe
= lpfc_pci_probe_one
,
2236 .remove
= __devexit_p(lpfc_pci_remove_one
),
2237 .err_handler
= &lpfc_err_handler
,
2245 printk(LPFC_MODULE_DESC
"\n");
2246 printk(LPFC_COPYRIGHT
"\n");
2248 lpfc_transport_template
=
2249 fc_attach_transport(&lpfc_transport_functions
);
2250 lpfc_vport_transport_template
=
2251 fc_attach_transport(&lpfc_vport_transport_functions
);
2252 if (!lpfc_transport_template
|| !lpfc_vport_transport_template
)
2254 error
= pci_register_driver(&lpfc_driver
);
2256 fc_release_transport(lpfc_transport_template
);
2257 fc_release_transport(lpfc_vport_transport_template
);
2266 pci_unregister_driver(&lpfc_driver
);
2267 fc_release_transport(lpfc_transport_template
);
2268 fc_release_transport(lpfc_vport_transport_template
);
2271 module_init(lpfc_init
);
2272 module_exit(lpfc_exit
);
2273 MODULE_LICENSE("GPL");
2274 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
2275 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2276 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);