1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2010 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>
31 #include <linux/aer.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_version.h"
52 unsigned long _dump_buf_data_order
;
54 unsigned long _dump_buf_dif_order
;
55 spinlock_t _dump_buf_lock
;
57 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
58 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
59 static int lpfc_sli4_queue_create(struct lpfc_hba
*);
60 static void lpfc_sli4_queue_destroy(struct lpfc_hba
*);
61 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
62 static int lpfc_setup_endian_order(struct lpfc_hba
*);
63 static int lpfc_sli4_read_config(struct lpfc_hba
*);
64 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
65 static void lpfc_free_sgl_list(struct lpfc_hba
*);
66 static int lpfc_init_sgl_list(struct lpfc_hba
*);
67 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
68 static void lpfc_free_active_sgl(struct lpfc_hba
*);
69 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
70 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
71 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
72 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
73 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
75 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
76 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
77 static DEFINE_IDR(lpfc_hba_index
);
80 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
81 * @phba: pointer to lpfc hba data structure.
83 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
84 * mailbox command. It retrieves the revision information from the HBA and
85 * collects the Vital Product Data (VPD) about the HBA for preparing the
86 * configuration of the HBA.
90 * -ERESTART - requests the SLI layer to reset the HBA and try again.
91 * Any other value - indicates an error.
94 lpfc_config_port_prep(struct lpfc_hba
*phba
)
96 lpfc_vpd_t
*vp
= &phba
->vpd
;
100 char *lpfc_vpd_data
= NULL
;
102 static char licensed
[56] =
103 "key unlock for use with gnu public licensed code only\0";
104 static int init_key
= 1;
106 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
108 phba
->link_state
= LPFC_HBA_ERROR
;
113 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
115 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
117 uint32_t *ptext
= (uint32_t *) licensed
;
119 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
120 *ptext
= cpu_to_be32(*ptext
);
124 lpfc_read_nv(phba
, pmb
);
125 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
126 sizeof (mb
->un
.varRDnvp
.rsvd3
));
127 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
130 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
132 if (rc
!= MBX_SUCCESS
) {
133 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
134 "0324 Config Port initialization "
135 "error, mbxCmd x%x READ_NVPARM, "
137 mb
->mbxCommand
, mb
->mbxStatus
);
138 mempool_free(pmb
, phba
->mbox_mem_pool
);
141 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
143 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
147 phba
->sli3_options
= 0x0;
149 /* Setup and issue mailbox READ REV command */
150 lpfc_read_rev(phba
, pmb
);
151 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
152 if (rc
!= MBX_SUCCESS
) {
153 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
154 "0439 Adapter failed to init, mbxCmd x%x "
155 "READ_REV, mbxStatus x%x\n",
156 mb
->mbxCommand
, mb
->mbxStatus
);
157 mempool_free( pmb
, phba
->mbox_mem_pool
);
163 * The value of rr must be 1 since the driver set the cv field to 1.
164 * This setting requires the FW to set all revision fields.
166 if (mb
->un
.varRdRev
.rr
== 0) {
168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
169 "0440 Adapter failed to init, READ_REV has "
170 "missing revision information.\n");
171 mempool_free(pmb
, phba
->mbox_mem_pool
);
175 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
176 mempool_free(pmb
, phba
->mbox_mem_pool
);
180 /* Save information as VPD data */
182 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
183 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
184 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
185 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
186 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
187 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
188 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
189 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
190 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
191 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
192 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
193 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
194 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
195 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
196 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
198 /* If the sli feature level is less then 9, we must
199 * tear down all RPIs and VPIs on link down if NPIV
202 if (vp
->rev
.feaLevelHigh
< 9)
203 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
205 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
206 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
207 sizeof (phba
->RandomData
));
209 /* Get adapter VPD information */
210 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
215 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
216 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
218 if (rc
!= MBX_SUCCESS
) {
219 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
220 "0441 VPD not present on adapter, "
221 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
222 mb
->mbxCommand
, mb
->mbxStatus
);
223 mb
->un
.varDmp
.word_cnt
= 0;
225 /* dump mem may return a zero when finished or we got a
226 * mailbox error, either way we are done.
228 if (mb
->un
.varDmp
.word_cnt
== 0)
230 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
231 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
232 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
233 lpfc_vpd_data
+ offset
,
234 mb
->un
.varDmp
.word_cnt
);
235 offset
+= mb
->un
.varDmp
.word_cnt
;
236 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
237 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
239 kfree(lpfc_vpd_data
);
241 mempool_free(pmb
, phba
->mbox_mem_pool
);
246 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
247 * @phba: pointer to lpfc hba data structure.
248 * @pmboxq: pointer to the driver internal queue element for mailbox command.
250 * This is the completion handler for driver's configuring asynchronous event
251 * mailbox command to the device. If the mailbox command returns successfully,
252 * it will set internal async event support flag to 1; otherwise, it will
253 * set internal async event support flag to 0.
256 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
258 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
259 phba
->temp_sensor_support
= 1;
261 phba
->temp_sensor_support
= 0;
262 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
267 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
268 * @phba: pointer to lpfc hba data structure.
269 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 * This is the completion handler for dump mailbox command for getting
272 * wake up parameters. When this command complete, the response contain
273 * Option rom version of the HBA. This function translate the version number
274 * into a human readable string and store it in OptionROMVersion.
277 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
280 uint32_t prog_id_word
;
282 /* character array used for decoding dist type. */
283 char dist_char
[] = "nabx";
285 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
286 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
290 prg
= (struct prog_id
*) &prog_id_word
;
292 /* word 7 contain option rom version */
293 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
295 /* Decode the Option rom version word to a readable string */
297 dist
= dist_char
[prg
->dist
];
299 if ((prg
->dist
== 3) && (prg
->num
== 0))
300 sprintf(phba
->OptionROMVersion
, "%d.%d%d",
301 prg
->ver
, prg
->rev
, prg
->lev
);
303 sprintf(phba
->OptionROMVersion
, "%d.%d%d%c%d",
304 prg
->ver
, prg
->rev
, prg
->lev
,
306 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
311 * lpfc_config_port_post - Perform lpfc initialization after config port
312 * @phba: pointer to lpfc hba data structure.
314 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
315 * command call. It performs all internal resource and state setups on the
316 * port: post IOCB buffers, enable appropriate host interrupt attentions,
317 * ELS ring timers, etc.
321 * Any other value - error.
324 lpfc_config_port_post(struct lpfc_hba
*phba
)
326 struct lpfc_vport
*vport
= phba
->pport
;
327 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
330 struct lpfc_dmabuf
*mp
;
331 struct lpfc_sli
*psli
= &phba
->sli
;
332 uint32_t status
, timeout
;
336 spin_lock_irq(&phba
->hbalock
);
338 * If the Config port completed correctly the HBA is not
339 * over heated any more.
341 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
342 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
343 spin_unlock_irq(&phba
->hbalock
);
345 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
347 phba
->link_state
= LPFC_HBA_ERROR
;
352 /* Get login parameters for NID. */
353 rc
= lpfc_read_sparam(phba
, pmb
, 0);
355 mempool_free(pmb
, phba
->mbox_mem_pool
);
360 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
361 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
362 "0448 Adapter failed init, mbxCmd x%x "
363 "READ_SPARM mbxStatus x%x\n",
364 mb
->mbxCommand
, mb
->mbxStatus
);
365 phba
->link_state
= LPFC_HBA_ERROR
;
366 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
367 mempool_free(pmb
, phba
->mbox_mem_pool
);
368 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
373 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
375 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
376 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
378 pmb
->context1
= NULL
;
380 if (phba
->cfg_soft_wwnn
)
381 u64_to_wwn(phba
->cfg_soft_wwnn
,
382 vport
->fc_sparam
.nodeName
.u
.wwn
);
383 if (phba
->cfg_soft_wwpn
)
384 u64_to_wwn(phba
->cfg_soft_wwpn
,
385 vport
->fc_sparam
.portName
.u
.wwn
);
386 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
387 sizeof (struct lpfc_name
));
388 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
389 sizeof (struct lpfc_name
));
391 /* Update the fc_host data structures with new wwn. */
392 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
393 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
394 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
396 /* If no serial number in VPD data, use low 6 bytes of WWNN */
397 /* This should be consolidated into parse_vpd ? - mr */
398 if (phba
->SerialNumber
[0] == 0) {
401 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
402 for (i
= 0; i
< 12; i
++) {
404 j
= ((status
& 0xf0) >> 4);
406 phba
->SerialNumber
[i
] =
407 (char)((uint8_t) 0x30 + (uint8_t) j
);
409 phba
->SerialNumber
[i
] =
410 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
414 phba
->SerialNumber
[i
] =
415 (char)((uint8_t) 0x30 + (uint8_t) j
);
417 phba
->SerialNumber
[i
] =
418 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
422 lpfc_read_config(phba
, pmb
);
424 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
425 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
426 "0453 Adapter failed to init, mbxCmd x%x "
427 "READ_CONFIG, mbxStatus x%x\n",
428 mb
->mbxCommand
, mb
->mbxStatus
);
429 phba
->link_state
= LPFC_HBA_ERROR
;
430 mempool_free( pmb
, phba
->mbox_mem_pool
);
434 /* Check if the port is disabled */
435 lpfc_sli_read_link_ste(phba
);
437 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
438 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
439 phba
->cfg_hba_queue_depth
=
440 (mb
->un
.varRdConfig
.max_xri
+ 1) -
441 lpfc_sli4_get_els_iocb_cnt(phba
);
443 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
445 /* Get the default values for Model Name and Description */
446 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
448 if ((phba
->cfg_link_speed
> LINK_SPEED_10G
)
449 || ((phba
->cfg_link_speed
== LINK_SPEED_1G
)
450 && !(phba
->lmt
& LMT_1Gb
))
451 || ((phba
->cfg_link_speed
== LINK_SPEED_2G
)
452 && !(phba
->lmt
& LMT_2Gb
))
453 || ((phba
->cfg_link_speed
== LINK_SPEED_4G
)
454 && !(phba
->lmt
& LMT_4Gb
))
455 || ((phba
->cfg_link_speed
== LINK_SPEED_8G
)
456 && !(phba
->lmt
& LMT_8Gb
))
457 || ((phba
->cfg_link_speed
== LINK_SPEED_10G
)
458 && !(phba
->lmt
& LMT_10Gb
))) {
459 /* Reset link speed to auto */
460 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LINK_EVENT
,
461 "1302 Invalid speed for this board: "
462 "Reset link speed to auto: x%x\n",
463 phba
->cfg_link_speed
);
464 phba
->cfg_link_speed
= LINK_SPEED_AUTO
;
467 phba
->link_state
= LPFC_LINK_DOWN
;
469 /* Only process IOCBs on ELS ring till hba_state is READY */
470 if (psli
->ring
[psli
->extra_ring
].cmdringaddr
)
471 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
472 if (psli
->ring
[psli
->fcp_ring
].cmdringaddr
)
473 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
474 if (psli
->ring
[psli
->next_ring
].cmdringaddr
)
475 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
477 /* Post receive buffers for desired rings */
478 if (phba
->sli_rev
!= 3)
479 lpfc_post_rcv_buf(phba
);
482 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
484 if (phba
->intr_type
== MSIX
) {
485 rc
= lpfc_config_msi(phba
, pmb
);
487 mempool_free(pmb
, phba
->mbox_mem_pool
);
490 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
491 if (rc
!= MBX_SUCCESS
) {
492 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
493 "0352 Config MSI mailbox command "
494 "failed, mbxCmd x%x, mbxStatus x%x\n",
495 pmb
->u
.mb
.mbxCommand
,
496 pmb
->u
.mb
.mbxStatus
);
497 mempool_free(pmb
, phba
->mbox_mem_pool
);
502 spin_lock_irq(&phba
->hbalock
);
503 /* Initialize ERATT handling flag */
504 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
506 /* Enable appropriate host interrupts */
507 status
= readl(phba
->HCregaddr
);
508 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
509 if (psli
->num_rings
> 0)
510 status
|= HC_R0INT_ENA
;
511 if (psli
->num_rings
> 1)
512 status
|= HC_R1INT_ENA
;
513 if (psli
->num_rings
> 2)
514 status
|= HC_R2INT_ENA
;
515 if (psli
->num_rings
> 3)
516 status
|= HC_R3INT_ENA
;
518 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
519 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
520 status
&= ~(HC_R0INT_ENA
);
522 writel(status
, phba
->HCregaddr
);
523 readl(phba
->HCregaddr
); /* flush */
524 spin_unlock_irq(&phba
->hbalock
);
526 /* Set up ring-0 (ELS) timer */
527 timeout
= phba
->fc_ratov
* 2;
528 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
529 /* Set up heart beat (HB) timer */
530 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
531 phba
->hb_outstanding
= 0;
532 phba
->last_completion_time
= jiffies
;
533 /* Set up error attention (ERATT) polling timer */
534 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
536 if (phba
->hba_flag
& LINK_DISABLED
) {
537 lpfc_printf_log(phba
,
539 "2598 Adapter Link is disabled.\n");
540 lpfc_down_link(phba
, pmb
);
541 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
542 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
543 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
544 lpfc_printf_log(phba
,
546 "2599 Adapter failed to issue DOWN_LINK"
547 " mbox command rc 0x%x\n", rc
);
549 mempool_free(pmb
, phba
->mbox_mem_pool
);
552 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
553 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
,
554 phba
->cfg_link_speed
);
555 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
556 lpfc_set_loopback_flag(phba
);
557 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
558 if (rc
!= MBX_SUCCESS
) {
559 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
560 "0454 Adapter failed to init, mbxCmd x%x "
561 "INIT_LINK, mbxStatus x%x\n",
562 mb
->mbxCommand
, mb
->mbxStatus
);
564 /* Clear all interrupt enable conditions */
565 writel(0, phba
->HCregaddr
);
566 readl(phba
->HCregaddr
); /* flush */
567 /* Clear all pending interrupts */
568 writel(0xffffffff, phba
->HAregaddr
);
569 readl(phba
->HAregaddr
); /* flush */
571 phba
->link_state
= LPFC_HBA_ERROR
;
573 mempool_free(pmb
, phba
->mbox_mem_pool
);
577 /* MBOX buffer will be freed in mbox compl */
578 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
580 phba
->link_state
= LPFC_HBA_ERROR
;
584 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
585 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
586 pmb
->vport
= phba
->pport
;
587 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
589 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
590 lpfc_printf_log(phba
,
593 "0456 Adapter failed to issue "
594 "ASYNCEVT_ENABLE mbox status x%x\n",
596 mempool_free(pmb
, phba
->mbox_mem_pool
);
599 /* Get Option rom version */
600 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
602 phba
->link_state
= LPFC_HBA_ERROR
;
606 lpfc_dump_wakeup_param(phba
, pmb
);
607 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
608 pmb
->vport
= phba
->pport
;
609 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
611 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
612 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
613 "to get Option ROM version status x%x\n", rc
);
614 mempool_free(pmb
, phba
->mbox_mem_pool
);
621 * lpfc_hba_init_link - Initialize the FC link
622 * @phba: pointer to lpfc hba data structure.
624 * This routine will issue the INIT_LINK mailbox command call.
625 * It is available to other drivers through the lpfc_hba data
626 * structure for use as a delayed link up mechanism with the
627 * module parameter lpfc_suppress_link_up.
631 * Any other value - error
634 lpfc_hba_init_link(struct lpfc_hba
*phba
)
636 struct lpfc_vport
*vport
= phba
->pport
;
641 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
643 phba
->link_state
= LPFC_HBA_ERROR
;
649 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
,
650 phba
->cfg_link_speed
);
651 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
652 lpfc_set_loopback_flag(phba
);
653 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
654 if (rc
!= MBX_SUCCESS
) {
655 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
656 "0498 Adapter failed to init, mbxCmd x%x "
657 "INIT_LINK, mbxStatus x%x\n",
658 mb
->mbxCommand
, mb
->mbxStatus
);
659 /* Clear all interrupt enable conditions */
660 writel(0, phba
->HCregaddr
);
661 readl(phba
->HCregaddr
); /* flush */
662 /* Clear all pending interrupts */
663 writel(0xffffffff, phba
->HAregaddr
);
664 readl(phba
->HAregaddr
); /* flush */
665 phba
->link_state
= LPFC_HBA_ERROR
;
667 mempool_free(pmb
, phba
->mbox_mem_pool
);
670 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
676 * lpfc_hba_down_link - this routine downs the FC link
678 * This routine will issue the DOWN_LINK mailbox command call.
679 * It is available to other drivers through the lpfc_hba data
680 * structure for use to stop the link.
684 * Any other value - error
687 lpfc_hba_down_link(struct lpfc_hba
*phba
)
692 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
694 phba
->link_state
= LPFC_HBA_ERROR
;
698 lpfc_printf_log(phba
,
700 "0491 Adapter Link is disabled.\n");
701 lpfc_down_link(phba
, pmb
);
702 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
703 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
704 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
705 lpfc_printf_log(phba
,
707 "2522 Adapter failed to issue DOWN_LINK"
708 " mbox command rc 0x%x\n", rc
);
710 mempool_free(pmb
, phba
->mbox_mem_pool
);
717 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
718 * @phba: pointer to lpfc HBA data structure.
720 * This routine will do LPFC uninitialization before the HBA is reset when
721 * bringing down the SLI Layer.
725 * Any other value - error.
728 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
730 struct lpfc_vport
**vports
;
733 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
734 /* Disable interrupts */
735 writel(0, phba
->HCregaddr
);
736 readl(phba
->HCregaddr
); /* flush */
739 if (phba
->pport
->load_flag
& FC_UNLOADING
)
740 lpfc_cleanup_discovery_resources(phba
->pport
);
742 vports
= lpfc_create_vport_work_array(phba
);
744 for (i
= 0; i
<= phba
->max_vports
&&
745 vports
[i
] != NULL
; i
++)
746 lpfc_cleanup_discovery_resources(vports
[i
]);
747 lpfc_destroy_vport_work_array(phba
, vports
);
753 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
754 * @phba: pointer to lpfc HBA data structure.
756 * This routine will do uninitialization after the HBA is reset when bring
757 * down the SLI Layer.
761 * Any other value - error.
764 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
766 struct lpfc_sli
*psli
= &phba
->sli
;
767 struct lpfc_sli_ring
*pring
;
768 struct lpfc_dmabuf
*mp
, *next_mp
;
769 LIST_HEAD(completions
);
772 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
773 lpfc_sli_hbqbuf_free_all(phba
);
775 /* Cleanup preposted buffers on the ELS ring */
776 pring
= &psli
->ring
[LPFC_ELS_RING
];
777 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
779 pring
->postbufq_cnt
--;
780 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
785 spin_lock_irq(&phba
->hbalock
);
786 for (i
= 0; i
< psli
->num_rings
; i
++) {
787 pring
= &psli
->ring
[i
];
789 /* At this point in time the HBA is either reset or DOA. Either
790 * way, nothing should be on txcmplq as it will NEVER complete.
792 list_splice_init(&pring
->txcmplq
, &completions
);
793 pring
->txcmplq_cnt
= 0;
794 spin_unlock_irq(&phba
->hbalock
);
796 /* Cancel all the IOCBs from the completions list */
797 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
800 lpfc_sli_abort_iocb_ring(phba
, pring
);
801 spin_lock_irq(&phba
->hbalock
);
803 spin_unlock_irq(&phba
->hbalock
);
808 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
809 * @phba: pointer to lpfc HBA data structure.
811 * This routine will do uninitialization after the HBA is reset when bring
812 * down the SLI Layer.
816 * Any other value - error.
819 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
821 struct lpfc_scsi_buf
*psb
, *psb_next
;
824 unsigned long iflag
= 0;
825 struct lpfc_sglq
*sglq_entry
= NULL
;
827 ret
= lpfc_hba_down_post_s3(phba
);
830 /* At this point in time the HBA is either reset or DOA. Either
831 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
832 * on the lpfc_sgl_list so that it can either be freed if the
833 * driver is unloading or reposted if the driver is restarting
836 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_sgl_list and */
838 /* abts_sgl_list_lock required because worker thread uses this
841 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
842 list_for_each_entry(sglq_entry
,
843 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
844 sglq_entry
->state
= SGL_FREED
;
846 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
847 &phba
->sli4_hba
.lpfc_sgl_list
);
848 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
849 /* abts_scsi_buf_list_lock required because worker thread uses this
852 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
853 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
855 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
856 spin_unlock_irq(&phba
->hbalock
);
858 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
860 psb
->status
= IOSTAT_SUCCESS
;
862 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
863 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list
);
864 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
869 * lpfc_hba_down_post - Wrapper func for hba down post routine
870 * @phba: pointer to lpfc HBA data structure.
872 * This routine wraps the actual SLI3 or SLI4 routine for performing
873 * uninitialization after the HBA is reset when bring down the SLI Layer.
877 * Any other value - error.
880 lpfc_hba_down_post(struct lpfc_hba
*phba
)
882 return (*phba
->lpfc_hba_down_post
)(phba
);
886 * lpfc_hb_timeout - The HBA-timer timeout handler
887 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
889 * This is the HBA-timer timeout handler registered to the lpfc driver. When
890 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
891 * work-port-events bitmap and the worker thread is notified. This timeout
892 * event will be used by the worker thread to invoke the actual timeout
893 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
894 * be performed in the timeout handler and the HBA timeout event bit shall
895 * be cleared by the worker thread after it has taken the event bitmap out.
898 lpfc_hb_timeout(unsigned long ptr
)
900 struct lpfc_hba
*phba
;
904 phba
= (struct lpfc_hba
*)ptr
;
906 /* Check for heart beat timeout conditions */
907 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
908 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
910 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
911 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
913 /* Tell the worker thread there is work to do */
915 lpfc_worker_wake_up(phba
);
920 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
921 * @phba: pointer to lpfc hba data structure.
922 * @pmboxq: pointer to the driver internal queue element for mailbox command.
924 * This is the callback function to the lpfc heart-beat mailbox command.
925 * If configured, the lpfc driver issues the heart-beat mailbox command to
926 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
927 * heart-beat mailbox command is issued, the driver shall set up heart-beat
928 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
929 * heart-beat outstanding state. Once the mailbox command comes back and
930 * no error conditions detected, the heart-beat mailbox command timer is
931 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
932 * state is cleared for the next heart-beat. If the timer expired with the
933 * heart-beat outstanding state set, the driver will put the HBA offline.
936 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
938 unsigned long drvr_flag
;
940 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
941 phba
->hb_outstanding
= 0;
942 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
944 /* Check and reset heart-beat timer is necessary */
945 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
946 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
947 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
948 !(phba
->pport
->load_flag
& FC_UNLOADING
))
949 mod_timer(&phba
->hb_tmofunc
,
950 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
955 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
956 * @phba: pointer to lpfc hba data structure.
958 * This is the actual HBA-timer timeout handler to be invoked by the worker
959 * thread whenever the HBA timer fired and HBA-timeout event posted. This
960 * handler performs any periodic operations needed for the device. If such
961 * periodic event has already been attended to either in the interrupt handler
962 * or by processing slow-ring or fast-ring events within the HBA-timer
963 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
964 * the timer for the next timeout period. If lpfc heart-beat mailbox command
965 * is configured and there is no heart-beat mailbox command outstanding, a
966 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
967 * has been a heart-beat mailbox command outstanding, the HBA shall be put
971 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
973 struct lpfc_vport
**vports
;
974 LPFC_MBOXQ_t
*pmboxq
;
975 struct lpfc_dmabuf
*buf_ptr
;
977 struct lpfc_sli
*psli
= &phba
->sli
;
978 LIST_HEAD(completions
);
980 vports
= lpfc_create_vport_work_array(phba
);
982 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
983 lpfc_rcv_seq_check_edtov(vports
[i
]);
984 lpfc_destroy_vport_work_array(phba
, vports
);
986 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
987 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
988 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
991 spin_lock_irq(&phba
->pport
->work_port_lock
);
993 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
995 spin_unlock_irq(&phba
->pport
->work_port_lock
);
996 if (!phba
->hb_outstanding
)
997 mod_timer(&phba
->hb_tmofunc
,
998 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1000 mod_timer(&phba
->hb_tmofunc
,
1001 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1004 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1006 if (phba
->elsbuf_cnt
&&
1007 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1008 spin_lock_irq(&phba
->hbalock
);
1009 list_splice_init(&phba
->elsbuf
, &completions
);
1010 phba
->elsbuf_cnt
= 0;
1011 phba
->elsbuf_prev_cnt
= 0;
1012 spin_unlock_irq(&phba
->hbalock
);
1014 while (!list_empty(&completions
)) {
1015 list_remove_head(&completions
, buf_ptr
,
1016 struct lpfc_dmabuf
, list
);
1017 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1021 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1023 /* If there is no heart beat outstanding, issue a heartbeat command */
1024 if (phba
->cfg_enable_hba_heartbeat
) {
1025 if (!phba
->hb_outstanding
) {
1026 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
1028 mod_timer(&phba
->hb_tmofunc
,
1029 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1033 lpfc_heart_beat(phba
, pmboxq
);
1034 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1035 pmboxq
->vport
= phba
->pport
;
1036 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
1038 if (retval
!= MBX_BUSY
&& retval
!= MBX_SUCCESS
) {
1039 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1040 mod_timer(&phba
->hb_tmofunc
,
1041 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1044 mod_timer(&phba
->hb_tmofunc
,
1045 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1046 phba
->hb_outstanding
= 1;
1050 * If heart beat timeout called with hb_outstanding set
1051 * we need to take the HBA offline.
1053 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1054 "0459 Adapter heartbeat failure, "
1055 "taking this port offline.\n");
1057 spin_lock_irq(&phba
->hbalock
);
1058 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1059 spin_unlock_irq(&phba
->hbalock
);
1061 lpfc_offline_prep(phba
);
1063 lpfc_unblock_mgmt_io(phba
);
1064 phba
->link_state
= LPFC_HBA_ERROR
;
1065 lpfc_hba_down_post(phba
);
1071 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1072 * @phba: pointer to lpfc hba data structure.
1074 * This routine is called to bring the HBA offline when HBA hardware error
1075 * other than Port Error 6 has been detected.
1078 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1080 struct lpfc_sli
*psli
= &phba
->sli
;
1082 spin_lock_irq(&phba
->hbalock
);
1083 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1084 spin_unlock_irq(&phba
->hbalock
);
1085 lpfc_offline_prep(phba
);
1088 lpfc_reset_barrier(phba
);
1089 spin_lock_irq(&phba
->hbalock
);
1090 lpfc_sli_brdreset(phba
);
1091 spin_unlock_irq(&phba
->hbalock
);
1092 lpfc_hba_down_post(phba
);
1093 lpfc_sli_brdready(phba
, HS_MBRDY
);
1094 lpfc_unblock_mgmt_io(phba
);
1095 phba
->link_state
= LPFC_HBA_ERROR
;
1100 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1101 * @phba: pointer to lpfc hba data structure.
1103 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1104 * other than Port Error 6 has been detected.
1107 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1109 lpfc_offline_prep(phba
);
1111 lpfc_sli4_brdreset(phba
);
1112 lpfc_hba_down_post(phba
);
1113 lpfc_sli4_post_status_check(phba
);
1114 lpfc_unblock_mgmt_io(phba
);
1115 phba
->link_state
= LPFC_HBA_ERROR
;
1119 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1120 * @phba: pointer to lpfc hba data structure.
1122 * This routine is invoked to handle the deferred HBA hardware error
1123 * conditions. This type of error is indicated by HBA by setting ER1
1124 * and another ER bit in the host status register. The driver will
1125 * wait until the ER1 bit clears before handling the error condition.
1128 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1130 uint32_t old_host_status
= phba
->work_hs
;
1131 struct lpfc_sli_ring
*pring
;
1132 struct lpfc_sli
*psli
= &phba
->sli
;
1134 /* If the pci channel is offline, ignore possible errors,
1135 * since we cannot communicate with the pci card anyway.
1137 if (pci_channel_offline(phba
->pcidev
)) {
1138 spin_lock_irq(&phba
->hbalock
);
1139 phba
->hba_flag
&= ~DEFER_ERATT
;
1140 spin_unlock_irq(&phba
->hbalock
);
1144 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1145 "0479 Deferred Adapter Hardware Error "
1146 "Data: x%x x%x x%x\n",
1148 phba
->work_status
[0], phba
->work_status
[1]);
1150 spin_lock_irq(&phba
->hbalock
);
1151 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1152 spin_unlock_irq(&phba
->hbalock
);
1156 * Firmware stops when it triggred erratt. That could cause the I/Os
1157 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1158 * SCSI layer retry it after re-establishing link.
1160 pring
= &psli
->ring
[psli
->fcp_ring
];
1161 lpfc_sli_abort_iocb_ring(phba
, pring
);
1164 * There was a firmware error. Take the hba offline and then
1165 * attempt to restart it.
1167 lpfc_offline_prep(phba
);
1170 /* Wait for the ER1 bit to clear.*/
1171 while (phba
->work_hs
& HS_FFER1
) {
1173 phba
->work_hs
= readl(phba
->HSregaddr
);
1174 /* If driver is unloading let the worker thread continue */
1175 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1182 * This is to ptrotect against a race condition in which
1183 * first write to the host attention register clear the
1184 * host status register.
1186 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1187 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1189 spin_lock_irq(&phba
->hbalock
);
1190 phba
->hba_flag
&= ~DEFER_ERATT
;
1191 spin_unlock_irq(&phba
->hbalock
);
1192 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1193 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1197 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1199 struct lpfc_board_event_header board_event
;
1200 struct Scsi_Host
*shost
;
1202 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1203 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1204 shost
= lpfc_shost_from_vport(phba
->pport
);
1205 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1206 sizeof(board_event
),
1207 (char *) &board_event
,
1212 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1213 * @phba: pointer to lpfc hba data structure.
1215 * This routine is invoked to handle the following HBA hardware error
1217 * 1 - HBA error attention interrupt
1218 * 2 - DMA ring index out of range
1219 * 3 - Mailbox command came back as unknown
1222 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1224 struct lpfc_vport
*vport
= phba
->pport
;
1225 struct lpfc_sli
*psli
= &phba
->sli
;
1226 struct lpfc_sli_ring
*pring
;
1227 uint32_t event_data
;
1228 unsigned long temperature
;
1229 struct temp_event temp_event_data
;
1230 struct Scsi_Host
*shost
;
1232 /* If the pci channel is offline, ignore possible errors,
1233 * since we cannot communicate with the pci card anyway.
1235 if (pci_channel_offline(phba
->pcidev
)) {
1236 spin_lock_irq(&phba
->hbalock
);
1237 phba
->hba_flag
&= ~DEFER_ERATT
;
1238 spin_unlock_irq(&phba
->hbalock
);
1242 /* If resets are disabled then leave the HBA alone and return */
1243 if (!phba
->cfg_enable_hba_reset
)
1246 /* Send an internal error event to mgmt application */
1247 lpfc_board_errevt_to_mgmt(phba
);
1249 if (phba
->hba_flag
& DEFER_ERATT
)
1250 lpfc_handle_deferred_eratt(phba
);
1252 if (phba
->work_hs
& HS_FFER6
) {
1253 /* Re-establishing Link */
1254 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1255 "1301 Re-establishing Link "
1256 "Data: x%x x%x x%x\n",
1258 phba
->work_status
[0], phba
->work_status
[1]);
1260 spin_lock_irq(&phba
->hbalock
);
1261 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1262 spin_unlock_irq(&phba
->hbalock
);
1265 * Firmware stops when it triggled erratt with HS_FFER6.
1266 * That could cause the I/Os dropped by the firmware.
1267 * Error iocb (I/O) on txcmplq and let the SCSI layer
1268 * retry it after re-establishing link.
1270 pring
= &psli
->ring
[psli
->fcp_ring
];
1271 lpfc_sli_abort_iocb_ring(phba
, pring
);
1274 * There was a firmware error. Take the hba offline and then
1275 * attempt to restart it.
1277 lpfc_offline_prep(phba
);
1279 lpfc_sli_brdrestart(phba
);
1280 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1281 lpfc_unblock_mgmt_io(phba
);
1284 lpfc_unblock_mgmt_io(phba
);
1285 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1286 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1287 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1288 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1289 temp_event_data
.data
= (uint32_t)temperature
;
1291 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1292 "0406 Adapter maximum temperature exceeded "
1293 "(%ld), taking this port offline "
1294 "Data: x%x x%x x%x\n",
1295 temperature
, phba
->work_hs
,
1296 phba
->work_status
[0], phba
->work_status
[1]);
1298 shost
= lpfc_shost_from_vport(phba
->pport
);
1299 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1300 sizeof(temp_event_data
),
1301 (char *) &temp_event_data
,
1302 SCSI_NL_VID_TYPE_PCI
1303 | PCI_VENDOR_ID_EMULEX
);
1305 spin_lock_irq(&phba
->hbalock
);
1306 phba
->over_temp_state
= HBA_OVER_TEMP
;
1307 spin_unlock_irq(&phba
->hbalock
);
1308 lpfc_offline_eratt(phba
);
1311 /* The if clause above forces this code path when the status
1312 * failure is a value other than FFER6. Do not call the offline
1313 * twice. This is the adapter hardware error path.
1315 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1316 "0457 Adapter Hardware Error "
1317 "Data: x%x x%x x%x\n",
1319 phba
->work_status
[0], phba
->work_status
[1]);
1321 event_data
= FC_REG_DUMP_EVENT
;
1322 shost
= lpfc_shost_from_vport(vport
);
1323 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1324 sizeof(event_data
), (char *) &event_data
,
1325 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1327 lpfc_offline_eratt(phba
);
1333 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1334 * @phba: pointer to lpfc hba data structure.
1336 * This routine is invoked to handle the SLI4 HBA hardware error attention
1340 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1342 struct lpfc_vport
*vport
= phba
->pport
;
1343 uint32_t event_data
;
1344 struct Scsi_Host
*shost
;
1346 /* If the pci channel is offline, ignore possible errors, since
1347 * we cannot communicate with the pci card anyway.
1349 if (pci_channel_offline(phba
->pcidev
))
1351 /* If resets are disabled then leave the HBA alone and return */
1352 if (!phba
->cfg_enable_hba_reset
)
1355 /* Send an internal error event to mgmt application */
1356 lpfc_board_errevt_to_mgmt(phba
);
1358 /* For now, the actual action for SLI4 device handling is not
1359 * specified yet, just treated it as adaptor hardware failure
1361 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1362 "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
1363 phba
->work_status
[0], phba
->work_status
[1]);
1365 event_data
= FC_REG_DUMP_EVENT
;
1366 shost
= lpfc_shost_from_vport(vport
);
1367 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1368 sizeof(event_data
), (char *) &event_data
,
1369 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1371 lpfc_sli4_offline_eratt(phba
);
1375 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1376 * @phba: pointer to lpfc HBA data structure.
1378 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1379 * routine from the API jump table function pointer from the lpfc_hba struct.
1383 * Any other value - error.
1386 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1388 (*phba
->lpfc_handle_eratt
)(phba
);
1392 * lpfc_handle_latt - The HBA link event handler
1393 * @phba: pointer to lpfc hba data structure.
1395 * This routine is invoked from the worker thread to handle a HBA host
1396 * attention link event.
1399 lpfc_handle_latt(struct lpfc_hba
*phba
)
1401 struct lpfc_vport
*vport
= phba
->pport
;
1402 struct lpfc_sli
*psli
= &phba
->sli
;
1404 volatile uint32_t control
;
1405 struct lpfc_dmabuf
*mp
;
1408 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1411 goto lpfc_handle_latt_err_exit
;
1414 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1417 goto lpfc_handle_latt_free_pmb
;
1420 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1423 goto lpfc_handle_latt_free_mp
;
1426 /* Cleanup any outstanding ELS commands */
1427 lpfc_els_flush_all_cmd(phba
);
1429 psli
->slistat
.link_event
++;
1430 lpfc_read_la(phba
, pmb
, mp
);
1431 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_la
;
1433 /* Block ELS IOCBs until we have processed this mbox command */
1434 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1435 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1436 if (rc
== MBX_NOT_FINISHED
) {
1438 goto lpfc_handle_latt_free_mbuf
;
1441 /* Clear Link Attention in HA REG */
1442 spin_lock_irq(&phba
->hbalock
);
1443 writel(HA_LATT
, phba
->HAregaddr
);
1444 readl(phba
->HAregaddr
); /* flush */
1445 spin_unlock_irq(&phba
->hbalock
);
1449 lpfc_handle_latt_free_mbuf
:
1450 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1451 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1452 lpfc_handle_latt_free_mp
:
1454 lpfc_handle_latt_free_pmb
:
1455 mempool_free(pmb
, phba
->mbox_mem_pool
);
1456 lpfc_handle_latt_err_exit
:
1457 /* Enable Link attention interrupts */
1458 spin_lock_irq(&phba
->hbalock
);
1459 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1460 control
= readl(phba
->HCregaddr
);
1461 control
|= HC_LAINT_ENA
;
1462 writel(control
, phba
->HCregaddr
);
1463 readl(phba
->HCregaddr
); /* flush */
1465 /* Clear Link Attention in HA REG */
1466 writel(HA_LATT
, phba
->HAregaddr
);
1467 readl(phba
->HAregaddr
); /* flush */
1468 spin_unlock_irq(&phba
->hbalock
);
1469 lpfc_linkdown(phba
);
1470 phba
->link_state
= LPFC_HBA_ERROR
;
1472 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1473 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1479 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1480 * @phba: pointer to lpfc hba data structure.
1481 * @vpd: pointer to the vital product data.
1482 * @len: length of the vital product data in bytes.
1484 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1485 * an array of characters. In this routine, the ModelName, ProgramType, and
1486 * ModelDesc, etc. fields of the phba data structure will be populated.
1489 * 0 - pointer to the VPD passed in is NULL
1493 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1495 uint8_t lenlo
, lenhi
;
1505 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1506 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1507 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1509 while (!finished
&& (index
< (len
- 4))) {
1510 switch (vpd
[index
]) {
1518 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1527 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1528 if (Length
> len
- index
)
1529 Length
= len
- index
;
1530 while (Length
> 0) {
1531 /* Look for Serial Number */
1532 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
1539 phba
->SerialNumber
[j
++] = vpd
[index
++];
1543 phba
->SerialNumber
[j
] = 0;
1546 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
1547 phba
->vpd_flag
|= VPD_MODEL_DESC
;
1554 phba
->ModelDesc
[j
++] = vpd
[index
++];
1558 phba
->ModelDesc
[j
] = 0;
1561 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
1562 phba
->vpd_flag
|= VPD_MODEL_NAME
;
1569 phba
->ModelName
[j
++] = vpd
[index
++];
1573 phba
->ModelName
[j
] = 0;
1576 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
1577 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
1584 phba
->ProgramType
[j
++] = vpd
[index
++];
1588 phba
->ProgramType
[j
] = 0;
1591 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
1592 phba
->vpd_flag
|= VPD_PORT
;
1599 phba
->Port
[j
++] = vpd
[index
++];
1629 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1630 * @phba: pointer to lpfc hba data structure.
1631 * @mdp: pointer to the data structure to hold the derived model name.
1632 * @descp: pointer to the data structure to hold the derived description.
1634 * This routine retrieves HBA's description based on its registered PCI device
1635 * ID. The @descp passed into this function points to an array of 256 chars. It
1636 * shall be returned with the model name, maximum speed, and the host bus type.
1637 * The @mdp passed into this function points to an array of 80 chars. When the
1638 * function returns, the @mdp will be filled with the model name.
1641 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
1644 uint16_t dev_id
= phba
->pcidev
->device
;
1647 int oneConnect
= 0; /* default is not a oneConnect */
1652 } m
= {"<Unknown>", "", ""};
1654 if (mdp
&& mdp
[0] != '\0'
1655 && descp
&& descp
[0] != '\0')
1658 if (phba
->lmt
& LMT_10Gb
)
1660 else if (phba
->lmt
& LMT_8Gb
)
1662 else if (phba
->lmt
& LMT_4Gb
)
1664 else if (phba
->lmt
& LMT_2Gb
)
1672 case PCI_DEVICE_ID_FIREFLY
:
1673 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1675 case PCI_DEVICE_ID_SUPERFLY
:
1676 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1677 m
= (typeof(m
)){"LP7000", "PCI",
1678 "Fibre Channel Adapter"};
1680 m
= (typeof(m
)){"LP7000E", "PCI",
1681 "Fibre Channel Adapter"};
1683 case PCI_DEVICE_ID_DRAGONFLY
:
1684 m
= (typeof(m
)){"LP8000", "PCI",
1685 "Fibre Channel Adapter"};
1687 case PCI_DEVICE_ID_CENTAUR
:
1688 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1689 m
= (typeof(m
)){"LP9002", "PCI",
1690 "Fibre Channel Adapter"};
1692 m
= (typeof(m
)){"LP9000", "PCI",
1693 "Fibre Channel Adapter"};
1695 case PCI_DEVICE_ID_RFLY
:
1696 m
= (typeof(m
)){"LP952", "PCI",
1697 "Fibre Channel Adapter"};
1699 case PCI_DEVICE_ID_PEGASUS
:
1700 m
= (typeof(m
)){"LP9802", "PCI-X",
1701 "Fibre Channel Adapter"};
1703 case PCI_DEVICE_ID_THOR
:
1704 m
= (typeof(m
)){"LP10000", "PCI-X",
1705 "Fibre Channel Adapter"};
1707 case PCI_DEVICE_ID_VIPER
:
1708 m
= (typeof(m
)){"LPX1000", "PCI-X",
1709 "Fibre Channel Adapter"};
1711 case PCI_DEVICE_ID_PFLY
:
1712 m
= (typeof(m
)){"LP982", "PCI-X",
1713 "Fibre Channel Adapter"};
1715 case PCI_DEVICE_ID_TFLY
:
1716 m
= (typeof(m
)){"LP1050", "PCI-X",
1717 "Fibre Channel Adapter"};
1719 case PCI_DEVICE_ID_HELIOS
:
1720 m
= (typeof(m
)){"LP11000", "PCI-X2",
1721 "Fibre Channel Adapter"};
1723 case PCI_DEVICE_ID_HELIOS_SCSP
:
1724 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1725 "Fibre Channel Adapter"};
1727 case PCI_DEVICE_ID_HELIOS_DCSP
:
1728 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1729 "Fibre Channel Adapter"};
1731 case PCI_DEVICE_ID_NEPTUNE
:
1732 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1734 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1735 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1737 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1738 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1740 case PCI_DEVICE_ID_BMID
:
1741 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1743 case PCI_DEVICE_ID_BSMB
:
1744 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1746 case PCI_DEVICE_ID_ZEPHYR
:
1747 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1749 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1750 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1752 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1753 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
1756 case PCI_DEVICE_ID_ZMID
:
1757 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
1759 case PCI_DEVICE_ID_ZSMB
:
1760 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
1762 case PCI_DEVICE_ID_LP101
:
1763 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
1765 case PCI_DEVICE_ID_LP10000S
:
1766 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
1768 case PCI_DEVICE_ID_LP11000S
:
1769 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
1771 case PCI_DEVICE_ID_LPE11000S
:
1772 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
1774 case PCI_DEVICE_ID_SAT
:
1775 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
1777 case PCI_DEVICE_ID_SAT_MID
:
1778 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
1780 case PCI_DEVICE_ID_SAT_SMB
:
1781 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
1783 case PCI_DEVICE_ID_SAT_DCSP
:
1784 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
1786 case PCI_DEVICE_ID_SAT_SCSP
:
1787 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
1789 case PCI_DEVICE_ID_SAT_S
:
1790 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
1792 case PCI_DEVICE_ID_HORNET
:
1793 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
1796 case PCI_DEVICE_ID_PROTEUS_VF
:
1797 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1798 "Fibre Channel Adapter"};
1800 case PCI_DEVICE_ID_PROTEUS_PF
:
1801 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1802 "Fibre Channel Adapter"};
1804 case PCI_DEVICE_ID_PROTEUS_S
:
1805 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
1806 "Fibre Channel Adapter"};
1808 case PCI_DEVICE_ID_TIGERSHARK
:
1810 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
1812 case PCI_DEVICE_ID_TOMCAT
:
1814 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
1816 case PCI_DEVICE_ID_FALCON
:
1817 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
1818 "EmulexSecure Fibre"};
1821 m
= (typeof(m
)){"Unknown", "", ""};
1825 if (mdp
&& mdp
[0] == '\0')
1826 snprintf(mdp
, 79,"%s", m
.name
);
1827 /* oneConnect hba requires special processing, they are all initiators
1828 * and we put the port number on the end
1830 if (descp
&& descp
[0] == '\0') {
1832 snprintf(descp
, 255,
1833 "Emulex OneConnect %s, %s Initiator, Port %s",
1837 snprintf(descp
, 255,
1838 "Emulex %s %d%s %s %s",
1839 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
1845 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
1846 * @phba: pointer to lpfc hba data structure.
1847 * @pring: pointer to a IOCB ring.
1848 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1850 * This routine posts a given number of IOCBs with the associated DMA buffer
1851 * descriptors specified by the cnt argument to the given IOCB ring.
1854 * The number of IOCBs NOT able to be posted to the IOCB ring.
1857 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
1860 struct lpfc_iocbq
*iocb
;
1861 struct lpfc_dmabuf
*mp1
, *mp2
;
1863 cnt
+= pring
->missbufcnt
;
1865 /* While there are buffers to post */
1867 /* Allocate buffer for command iocb */
1868 iocb
= lpfc_sli_get_iocbq(phba
);
1870 pring
->missbufcnt
= cnt
;
1875 /* 2 buffers can be posted per command */
1876 /* Allocate buffer to post */
1877 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1879 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
1880 if (!mp1
|| !mp1
->virt
) {
1882 lpfc_sli_release_iocbq(phba
, iocb
);
1883 pring
->missbufcnt
= cnt
;
1887 INIT_LIST_HEAD(&mp1
->list
);
1888 /* Allocate buffer to post */
1890 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1892 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1894 if (!mp2
|| !mp2
->virt
) {
1896 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1898 lpfc_sli_release_iocbq(phba
, iocb
);
1899 pring
->missbufcnt
= cnt
;
1903 INIT_LIST_HEAD(&mp2
->list
);
1908 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
1909 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
1910 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
1911 icmd
->ulpBdeCount
= 1;
1914 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
1915 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
1916 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
1918 icmd
->ulpBdeCount
= 2;
1921 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
1924 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
1926 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1930 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
1934 lpfc_sli_release_iocbq(phba
, iocb
);
1935 pring
->missbufcnt
= cnt
;
1938 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
1940 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
1942 pring
->missbufcnt
= 0;
1947 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
1948 * @phba: pointer to lpfc hba data structure.
1950 * This routine posts initial receive IOCB buffers to the ELS ring. The
1951 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1955 * 0 - success (currently always success)
1958 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
1960 struct lpfc_sli
*psli
= &phba
->sli
;
1962 /* Ring 0, ELS / CT buffers */
1963 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
1964 /* Ring 2 - FCP no buffers needed */
1969 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1972 * lpfc_sha_init - Set up initial array of hash table entries
1973 * @HashResultPointer: pointer to an array as hash table.
1975 * This routine sets up the initial values to the array of hash table entries
1979 lpfc_sha_init(uint32_t * HashResultPointer
)
1981 HashResultPointer
[0] = 0x67452301;
1982 HashResultPointer
[1] = 0xEFCDAB89;
1983 HashResultPointer
[2] = 0x98BADCFE;
1984 HashResultPointer
[3] = 0x10325476;
1985 HashResultPointer
[4] = 0xC3D2E1F0;
1989 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
1990 * @HashResultPointer: pointer to an initial/result hash table.
1991 * @HashWorkingPointer: pointer to an working hash table.
1993 * This routine iterates an initial hash table pointed by @HashResultPointer
1994 * with the values from the working hash table pointeed by @HashWorkingPointer.
1995 * The results are putting back to the initial hash table, returned through
1996 * the @HashResultPointer as the result hash table.
1999 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2003 uint32_t A
, B
, C
, D
, E
;
2006 HashWorkingPointer
[t
] =
2008 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2010 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2011 } while (++t
<= 79);
2013 A
= HashResultPointer
[0];
2014 B
= HashResultPointer
[1];
2015 C
= HashResultPointer
[2];
2016 D
= HashResultPointer
[3];
2017 E
= HashResultPointer
[4];
2021 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2022 } else if (t
< 40) {
2023 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2024 } else if (t
< 60) {
2025 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2027 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2029 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2035 } while (++t
<= 79);
2037 HashResultPointer
[0] += A
;
2038 HashResultPointer
[1] += B
;
2039 HashResultPointer
[2] += C
;
2040 HashResultPointer
[3] += D
;
2041 HashResultPointer
[4] += E
;
2046 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2047 * @RandomChallenge: pointer to the entry of host challenge random number array.
2048 * @HashWorking: pointer to the entry of the working hash array.
2050 * This routine calculates the working hash array referred by @HashWorking
2051 * from the challenge random numbers associated with the host, referred by
2052 * @RandomChallenge. The result is put into the entry of the working hash
2053 * array and returned by reference through @HashWorking.
2056 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2058 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2062 * lpfc_hba_init - Perform special handling for LC HBA initialization
2063 * @phba: pointer to lpfc hba data structure.
2064 * @hbainit: pointer to an array of unsigned 32-bit integers.
2066 * This routine performs the special handling for LC HBA initialization.
2069 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2072 uint32_t *HashWorking
;
2073 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2075 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2079 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2080 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2082 for (t
= 0; t
< 7; t
++)
2083 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2085 lpfc_sha_init(hbainit
);
2086 lpfc_sha_iterate(hbainit
, HashWorking
);
2091 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2092 * @vport: pointer to a virtual N_Port data structure.
2094 * This routine performs the necessary cleanups before deleting the @vport.
2095 * It invokes the discovery state machine to perform necessary state
2096 * transitions and to release the ndlps associated with the @vport. Note,
2097 * the physical port is treated as @vport 0.
2100 lpfc_cleanup(struct lpfc_vport
*vport
)
2102 struct lpfc_hba
*phba
= vport
->phba
;
2103 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2106 if (phba
->link_state
> LPFC_LINK_DOWN
)
2107 lpfc_port_link_failure(vport
);
2109 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2110 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2111 ndlp
= lpfc_enable_node(vport
, ndlp
,
2112 NLP_STE_UNUSED_NODE
);
2115 spin_lock_irq(&phba
->ndlp_lock
);
2116 NLP_SET_FREE_REQ(ndlp
);
2117 spin_unlock_irq(&phba
->ndlp_lock
);
2118 /* Trigger the release of the ndlp memory */
2122 spin_lock_irq(&phba
->ndlp_lock
);
2123 if (NLP_CHK_FREE_REQ(ndlp
)) {
2124 /* The ndlp should not be in memory free mode already */
2125 spin_unlock_irq(&phba
->ndlp_lock
);
2128 /* Indicate request for freeing ndlp memory */
2129 NLP_SET_FREE_REQ(ndlp
);
2130 spin_unlock_irq(&phba
->ndlp_lock
);
2132 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2133 ndlp
->nlp_DID
== Fabric_DID
) {
2134 /* Just free up ndlp with Fabric_DID for vports */
2139 if (ndlp
->nlp_type
& NLP_FABRIC
)
2140 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2141 NLP_EVT_DEVICE_RECOVERY
);
2143 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2148 /* At this point, ALL ndlp's should be gone
2149 * because of the previous NLP_EVT_DEVICE_RM.
2150 * Lets wait for this to happen, if needed.
2152 while (!list_empty(&vport
->fc_nodes
)) {
2154 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2155 "0233 Nodelist not empty\n");
2156 list_for_each_entry_safe(ndlp
, next_ndlp
,
2157 &vport
->fc_nodes
, nlp_listp
) {
2158 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2160 "0282 did:x%x ndlp:x%p "
2161 "usgmap:x%x refcnt:%d\n",
2162 ndlp
->nlp_DID
, (void *)ndlp
,
2165 &ndlp
->kref
.refcount
));
2170 /* Wait for any activity on ndlps to settle */
2176 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2177 * @vport: pointer to a virtual N_Port data structure.
2179 * This routine stops all the timers associated with a @vport. This function
2180 * is invoked before disabling or deleting a @vport. Note that the physical
2181 * port is treated as @vport 0.
2184 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2186 del_timer_sync(&vport
->els_tmofunc
);
2187 del_timer_sync(&vport
->fc_fdmitmo
);
2188 lpfc_can_disctmo(vport
);
2193 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2194 * @phba: pointer to lpfc hba data structure.
2196 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2197 * caller of this routine should already hold the host lock.
2200 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2202 /* Clear pending FCF rediscovery wait and failover in progress flags */
2203 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_PEND
|
2206 /* Now, try to stop the timer */
2207 del_timer(&phba
->fcf
.redisc_wait
);
2211 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2212 * @phba: pointer to lpfc hba data structure.
2214 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2215 * checks whether the FCF rediscovery wait timer is pending with the host
2216 * lock held before proceeding with disabling the timer and clearing the
2217 * wait timer pendig flag.
2220 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2222 spin_lock_irq(&phba
->hbalock
);
2223 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2224 /* FCF rediscovery timer already fired or stopped */
2225 spin_unlock_irq(&phba
->hbalock
);
2228 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2229 spin_unlock_irq(&phba
->hbalock
);
2233 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2234 * @phba: pointer to lpfc hba data structure.
2236 * This routine stops all the timers associated with a HBA. This function is
2237 * invoked before either putting a HBA offline or unloading the driver.
2240 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2242 lpfc_stop_vport_timers(phba
->pport
);
2243 del_timer_sync(&phba
->sli
.mbox_tmo
);
2244 del_timer_sync(&phba
->fabric_block_timer
);
2245 del_timer_sync(&phba
->eratt_poll
);
2246 del_timer_sync(&phba
->hb_tmofunc
);
2247 phba
->hb_outstanding
= 0;
2249 switch (phba
->pci_dev_grp
) {
2250 case LPFC_PCI_DEV_LP
:
2251 /* Stop any LightPulse device specific driver timers */
2252 del_timer_sync(&phba
->fcp_poll_timer
);
2254 case LPFC_PCI_DEV_OC
:
2255 /* Stop any OneConnect device sepcific driver timers */
2256 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2259 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2260 "0297 Invalid device group (x%x)\n",
2268 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2269 * @phba: pointer to lpfc hba data structure.
2271 * This routine marks a HBA's management interface as blocked. Once the HBA's
2272 * management interface is marked as blocked, all the user space access to
2273 * the HBA, whether they are from sysfs interface or libdfc interface will
2274 * all be blocked. The HBA is set to block the management interface when the
2275 * driver prepares the HBA interface for online or offline.
2278 lpfc_block_mgmt_io(struct lpfc_hba
* phba
)
2280 unsigned long iflag
;
2282 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2283 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2284 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2288 * lpfc_online - Initialize and bring a HBA online
2289 * @phba: pointer to lpfc hba data structure.
2291 * This routine initializes the HBA and brings a HBA online. During this
2292 * process, the management interface is blocked to prevent user space access
2293 * to the HBA interfering with the driver initialization.
2300 lpfc_online(struct lpfc_hba
*phba
)
2302 struct lpfc_vport
*vport
;
2303 struct lpfc_vport
**vports
;
2308 vport
= phba
->pport
;
2310 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2313 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2314 "0458 Bring Adapter online\n");
2316 lpfc_block_mgmt_io(phba
);
2318 if (!lpfc_sli_queue_setup(phba
)) {
2319 lpfc_unblock_mgmt_io(phba
);
2323 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2324 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2325 lpfc_unblock_mgmt_io(phba
);
2329 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2330 lpfc_unblock_mgmt_io(phba
);
2335 vports
= lpfc_create_vport_work_array(phba
);
2337 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2338 struct Scsi_Host
*shost
;
2339 shost
= lpfc_shost_from_vport(vports
[i
]);
2340 spin_lock_irq(shost
->host_lock
);
2341 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2342 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2343 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2344 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2345 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2346 spin_unlock_irq(shost
->host_lock
);
2348 lpfc_destroy_vport_work_array(phba
, vports
);
2350 lpfc_unblock_mgmt_io(phba
);
2355 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2356 * @phba: pointer to lpfc hba data structure.
2358 * This routine marks a HBA's management interface as not blocked. Once the
2359 * HBA's management interface is marked as not blocked, all the user space
2360 * access to the HBA, whether they are from sysfs interface or libdfc
2361 * interface will be allowed. The HBA is set to block the management interface
2362 * when the driver prepares the HBA interface for online or offline and then
2363 * set to unblock the management interface afterwards.
2366 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2368 unsigned long iflag
;
2370 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2371 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2372 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2376 * lpfc_offline_prep - Prepare a HBA to be brought offline
2377 * @phba: pointer to lpfc hba data structure.
2379 * This routine is invoked to prepare a HBA to be brought offline. It performs
2380 * unregistration login to all the nodes on all vports and flushes the mailbox
2381 * queue to make it ready to be brought offline.
2384 lpfc_offline_prep(struct lpfc_hba
* phba
)
2386 struct lpfc_vport
*vport
= phba
->pport
;
2387 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2388 struct lpfc_vport
**vports
;
2389 struct Scsi_Host
*shost
;
2392 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2395 lpfc_block_mgmt_io(phba
);
2397 lpfc_linkdown(phba
);
2399 /* Issue an unreg_login to all nodes on all vports */
2400 vports
= lpfc_create_vport_work_array(phba
);
2401 if (vports
!= NULL
) {
2402 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2403 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2405 shost
= lpfc_shost_from_vport(vports
[i
]);
2406 spin_lock_irq(shost
->host_lock
);
2407 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2408 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2409 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2410 spin_unlock_irq(shost
->host_lock
);
2412 shost
= lpfc_shost_from_vport(vports
[i
]);
2413 list_for_each_entry_safe(ndlp
, next_ndlp
,
2414 &vports
[i
]->fc_nodes
,
2416 if (!NLP_CHK_NODE_ACT(ndlp
))
2418 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2420 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2421 lpfc_disc_state_machine(vports
[i
], ndlp
,
2422 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2423 lpfc_disc_state_machine(vports
[i
], ndlp
,
2424 NULL
, NLP_EVT_DEVICE_RM
);
2426 spin_lock_irq(shost
->host_lock
);
2427 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2428 spin_unlock_irq(shost
->host_lock
);
2429 lpfc_unreg_rpi(vports
[i
], ndlp
);
2433 lpfc_destroy_vport_work_array(phba
, vports
);
2435 lpfc_sli_mbox_sys_shutdown(phba
);
2439 * lpfc_offline - Bring a HBA offline
2440 * @phba: pointer to lpfc hba data structure.
2442 * This routine actually brings a HBA offline. It stops all the timers
2443 * associated with the HBA, brings down the SLI layer, and eventually
2444 * marks the HBA as in offline state for the upper layer protocol.
2447 lpfc_offline(struct lpfc_hba
*phba
)
2449 struct Scsi_Host
*shost
;
2450 struct lpfc_vport
**vports
;
2453 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2456 /* stop port and all timers associated with this hba */
2457 lpfc_stop_port(phba
);
2458 vports
= lpfc_create_vport_work_array(phba
);
2460 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2461 lpfc_stop_vport_timers(vports
[i
]);
2462 lpfc_destroy_vport_work_array(phba
, vports
);
2463 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2464 "0460 Bring Adapter offline\n");
2465 /* Bring down the SLI Layer and cleanup. The HBA is offline
2467 lpfc_sli_hba_down(phba
);
2468 spin_lock_irq(&phba
->hbalock
);
2470 spin_unlock_irq(&phba
->hbalock
);
2471 vports
= lpfc_create_vport_work_array(phba
);
2473 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2474 shost
= lpfc_shost_from_vport(vports
[i
]);
2475 spin_lock_irq(shost
->host_lock
);
2476 vports
[i
]->work_port_events
= 0;
2477 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2478 spin_unlock_irq(shost
->host_lock
);
2480 lpfc_destroy_vport_work_array(phba
, vports
);
2484 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2485 * @phba: pointer to lpfc hba data structure.
2487 * This routine is to free all the SCSI buffers and IOCBs from the driver
2488 * list back to kernel. It is called from lpfc_pci_remove_one to free
2489 * the internal resources before the device is removed from the system.
2492 * 0 - successful (for now, it always returns 0)
2495 lpfc_scsi_free(struct lpfc_hba
*phba
)
2497 struct lpfc_scsi_buf
*sb
, *sb_next
;
2498 struct lpfc_iocbq
*io
, *io_next
;
2500 spin_lock_irq(&phba
->hbalock
);
2501 /* Release all the lpfc_scsi_bufs maintained by this host. */
2502 spin_lock(&phba
->scsi_buf_list_lock
);
2503 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
2504 list_del(&sb
->list
);
2505 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2508 phba
->total_scsi_bufs
--;
2510 spin_unlock(&phba
->scsi_buf_list_lock
);
2512 /* Release all the lpfc_iocbq entries maintained by this host. */
2513 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2514 list_del(&io
->list
);
2516 phba
->total_iocbq_bufs
--;
2518 spin_unlock_irq(&phba
->hbalock
);
2523 * lpfc_create_port - Create an FC port
2524 * @phba: pointer to lpfc hba data structure.
2525 * @instance: a unique integer ID to this FC port.
2526 * @dev: pointer to the device data structure.
2528 * This routine creates a FC port for the upper layer protocol. The FC port
2529 * can be created on top of either a physical port or a virtual port provided
2530 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2531 * and associates the FC port created before adding the shost into the SCSI
2535 * @vport - pointer to the virtual N_Port data structure.
2536 * NULL - port create failed.
2539 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
2541 struct lpfc_vport
*vport
;
2542 struct Scsi_Host
*shost
;
2545 if (dev
!= &phba
->pcidev
->dev
)
2546 shost
= scsi_host_alloc(&lpfc_vport_template
,
2547 sizeof(struct lpfc_vport
));
2549 shost
= scsi_host_alloc(&lpfc_template
,
2550 sizeof(struct lpfc_vport
));
2554 vport
= (struct lpfc_vport
*) shost
->hostdata
;
2556 vport
->load_flag
|= FC_LOADING
;
2557 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2558 vport
->fc_rscn_flush
= 0;
2560 lpfc_get_vport_cfgparam(vport
);
2561 shost
->unique_id
= instance
;
2562 shost
->max_id
= LPFC_MAX_TARGET
;
2563 shost
->max_lun
= vport
->cfg_max_luns
;
2564 shost
->this_id
= -1;
2565 shost
->max_cmd_len
= 16;
2566 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2567 shost
->dma_boundary
=
2568 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
;
2569 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
2573 * Set initial can_queue value since 0 is no longer supported and
2574 * scsi_add_host will fail. This will be adjusted later based on the
2575 * max xri value determined in hba setup.
2577 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
2578 if (dev
!= &phba
->pcidev
->dev
) {
2579 shost
->transportt
= lpfc_vport_transport_template
;
2580 vport
->port_type
= LPFC_NPIV_PORT
;
2582 shost
->transportt
= lpfc_transport_template
;
2583 vport
->port_type
= LPFC_PHYSICAL_PORT
;
2586 /* Initialize all internally managed lists. */
2587 INIT_LIST_HEAD(&vport
->fc_nodes
);
2588 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
2589 spin_lock_init(&vport
->work_port_lock
);
2591 init_timer(&vport
->fc_disctmo
);
2592 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
2593 vport
->fc_disctmo
.data
= (unsigned long)vport
;
2595 init_timer(&vport
->fc_fdmitmo
);
2596 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
2597 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
2599 init_timer(&vport
->els_tmofunc
);
2600 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
2601 vport
->els_tmofunc
.data
= (unsigned long)vport
;
2602 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
2603 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
2604 /* check for menlo minimum sg count */
2605 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
) {
2606 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
2607 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
2611 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
2615 spin_lock_irq(&phba
->hbalock
);
2616 list_add_tail(&vport
->listentry
, &phba
->port_list
);
2617 spin_unlock_irq(&phba
->hbalock
);
2621 scsi_host_put(shost
);
2627 * destroy_port - destroy an FC port
2628 * @vport: pointer to an lpfc virtual N_Port data structure.
2630 * This routine destroys a FC port from the upper layer protocol. All the
2631 * resources associated with the port are released.
2634 destroy_port(struct lpfc_vport
*vport
)
2636 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2637 struct lpfc_hba
*phba
= vport
->phba
;
2639 lpfc_debugfs_terminate(vport
);
2640 fc_remove_host(shost
);
2641 scsi_remove_host(shost
);
2643 spin_lock_irq(&phba
->hbalock
);
2644 list_del_init(&vport
->listentry
);
2645 spin_unlock_irq(&phba
->hbalock
);
2647 lpfc_cleanup(vport
);
2652 * lpfc_get_instance - Get a unique integer ID
2654 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2655 * uses the kernel idr facility to perform the task.
2658 * instance - a unique integer ID allocated as the new instance.
2659 * -1 - lpfc get instance failed.
2662 lpfc_get_instance(void)
2666 /* Assign an unused number */
2667 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
2669 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
2675 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
2676 * @shost: pointer to SCSI host data structure.
2677 * @time: elapsed time of the scan in jiffies.
2679 * This routine is called by the SCSI layer with a SCSI host to determine
2680 * whether the scan host is finished.
2682 * Note: there is no scan_start function as adapter initialization will have
2683 * asynchronously kicked off the link initialization.
2686 * 0 - SCSI host scan is not over yet.
2687 * 1 - SCSI host scan is over.
2689 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
2691 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2692 struct lpfc_hba
*phba
= vport
->phba
;
2695 spin_lock_irq(shost
->host_lock
);
2697 if (vport
->load_flag
& FC_UNLOADING
) {
2701 if (time
>= 30 * HZ
) {
2702 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2703 "0461 Scanning longer than 30 "
2704 "seconds. Continuing initialization\n");
2708 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
2709 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2710 "0465 Link down longer than 15 "
2711 "seconds. Continuing initialization\n");
2716 if (vport
->port_state
!= LPFC_VPORT_READY
)
2718 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
2720 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
2722 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
2728 spin_unlock_irq(shost
->host_lock
);
2733 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
2734 * @shost: pointer to SCSI host data structure.
2736 * This routine initializes a given SCSI host attributes on a FC port. The
2737 * SCSI host can be either on top of a physical port or a virtual port.
2739 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
2741 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2742 struct lpfc_hba
*phba
= vport
->phba
;
2744 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
2747 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
2748 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
2749 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
2751 memset(fc_host_supported_fc4s(shost
), 0,
2752 sizeof(fc_host_supported_fc4s(shost
)));
2753 fc_host_supported_fc4s(shost
)[2] = 1;
2754 fc_host_supported_fc4s(shost
)[7] = 1;
2756 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
2757 sizeof fc_host_symbolic_name(shost
));
2759 fc_host_supported_speeds(shost
) = 0;
2760 if (phba
->lmt
& LMT_10Gb
)
2761 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
2762 if (phba
->lmt
& LMT_8Gb
)
2763 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
2764 if (phba
->lmt
& LMT_4Gb
)
2765 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
2766 if (phba
->lmt
& LMT_2Gb
)
2767 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
2768 if (phba
->lmt
& LMT_1Gb
)
2769 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
2771 fc_host_maxframe_size(shost
) =
2772 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
2773 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
2775 /* This value is also unchanging */
2776 memset(fc_host_active_fc4s(shost
), 0,
2777 sizeof(fc_host_active_fc4s(shost
)));
2778 fc_host_active_fc4s(shost
)[2] = 1;
2779 fc_host_active_fc4s(shost
)[7] = 1;
2781 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
2782 spin_lock_irq(shost
->host_lock
);
2783 vport
->load_flag
&= ~FC_LOADING
;
2784 spin_unlock_irq(shost
->host_lock
);
2788 * lpfc_stop_port_s3 - Stop SLI3 device port
2789 * @phba: pointer to lpfc hba data structure.
2791 * This routine is invoked to stop an SLI3 device port, it stops the device
2792 * from generating interrupts and stops the device driver's timers for the
2796 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
2798 /* Clear all interrupt enable conditions */
2799 writel(0, phba
->HCregaddr
);
2800 readl(phba
->HCregaddr
); /* flush */
2801 /* Clear all pending interrupts */
2802 writel(0xffffffff, phba
->HAregaddr
);
2803 readl(phba
->HAregaddr
); /* flush */
2805 /* Reset some HBA SLI setup states */
2806 lpfc_stop_hba_timers(phba
);
2807 phba
->pport
->work_port_events
= 0;
2811 * lpfc_stop_port_s4 - Stop SLI4 device port
2812 * @phba: pointer to lpfc hba data structure.
2814 * This routine is invoked to stop an SLI4 device port, it stops the device
2815 * from generating interrupts and stops the device driver's timers for the
2819 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
2821 /* Reset some HBA SLI4 setup states */
2822 lpfc_stop_hba_timers(phba
);
2823 phba
->pport
->work_port_events
= 0;
2824 phba
->sli4_hba
.intr_enable
= 0;
2828 * lpfc_stop_port - Wrapper function for stopping hba port
2829 * @phba: Pointer to HBA context object.
2831 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
2832 * the API jump table function pointer from the lpfc_hba struct.
2835 lpfc_stop_port(struct lpfc_hba
*phba
)
2837 phba
->lpfc_stop_port(phba
);
2841 * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
2842 * @phba: pointer to lpfc hba data structure.
2844 * This routine is invoked to remove the driver default fcf record from
2845 * the port. This routine currently acts on FCF Index 0.
2849 lpfc_sli_remove_dflt_fcf(struct lpfc_hba
*phba
)
2852 LPFC_MBOXQ_t
*mboxq
;
2853 struct lpfc_mbx_del_fcf_tbl_entry
*del_fcf_record
;
2854 uint32_t mbox_tmo
, req_len
;
2855 uint32_t shdr_status
, shdr_add_status
;
2857 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2859 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2860 "2020 Failed to allocate mbox for ADD_FCF cmd\n");
2864 req_len
= sizeof(struct lpfc_mbx_del_fcf_tbl_entry
) -
2865 sizeof(struct lpfc_sli4_cfg_mhdr
);
2866 rc
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2867 LPFC_MBOX_OPCODE_FCOE_DELETE_FCF
,
2868 req_len
, LPFC_SLI4_MBX_EMBED
);
2870 * In phase 1, there is a single FCF index, 0. In phase2, the driver
2871 * supports multiple FCF indices.
2873 del_fcf_record
= &mboxq
->u
.mqe
.un
.del_fcf_entry
;
2874 bf_set(lpfc_mbx_del_fcf_tbl_count
, del_fcf_record
, 1);
2875 bf_set(lpfc_mbx_del_fcf_tbl_index
, del_fcf_record
,
2876 phba
->fcf
.current_rec
.fcf_indx
);
2878 if (!phba
->sli4_hba
.intr_enable
)
2879 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
2881 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
2882 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
2884 /* The IOCTL status is embedded in the mailbox subheader. */
2885 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
2886 &del_fcf_record
->header
.cfg_shdr
.response
);
2887 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
2888 &del_fcf_record
->header
.cfg_shdr
.response
);
2889 if (shdr_status
|| shdr_add_status
|| rc
!= MBX_SUCCESS
) {
2890 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2891 "2516 DEL FCF of default FCF Index failed "
2892 "mbx status x%x, status x%x add_status x%x\n",
2893 rc
, shdr_status
, shdr_add_status
);
2895 if (rc
!= MBX_TIMEOUT
)
2896 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2900 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
2901 * @phba: Pointer to hba for which this call is being executed.
2903 * This routine starts the timer waiting for the FCF rediscovery to complete.
2906 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
2908 unsigned long fcf_redisc_wait_tmo
=
2909 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
2910 /* Start fcf rediscovery wait period timer */
2911 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
2912 spin_lock_irq(&phba
->hbalock
);
2913 /* Allow action to new fcf asynchronous event */
2914 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
2915 /* Mark the FCF rediscovery pending state */
2916 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
2917 spin_unlock_irq(&phba
->hbalock
);
2921 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
2922 * @ptr: Map to lpfc_hba data structure pointer.
2924 * This routine is invoked when waiting for FCF table rediscover has been
2925 * timed out. If new FCF record(s) has (have) been discovered during the
2926 * wait period, a new FCF event shall be added to the FCOE async event
2927 * list, and then worker thread shall be waked up for processing from the
2928 * worker thread context.
2931 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
2933 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
2935 /* Don't send FCF rediscovery event if timer cancelled */
2936 spin_lock_irq(&phba
->hbalock
);
2937 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2938 spin_unlock_irq(&phba
->hbalock
);
2941 /* Clear FCF rediscovery timer pending flag */
2942 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2943 /* FCF rediscovery event to worker thread */
2944 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
2945 spin_unlock_irq(&phba
->hbalock
);
2946 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2947 "2776 FCF rediscover wait timer expired, post "
2948 "a worker thread event for FCF table scan\n");
2949 /* wake up worker thread */
2950 lpfc_worker_wake_up(phba
);
2954 * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support
2955 * @phba: pointer to lpfc hba data structure.
2957 * This function uses the QUERY_FW_CFG mailbox command to determine if the
2958 * firmware loaded supports FCoE. A return of zero indicates that the mailbox
2959 * was successful and the firmware supports FCoE. Any other return indicates
2960 * a error. It is assumed that this function will be called before interrupts
2964 lpfc_sli4_fw_cfg_check(struct lpfc_hba
*phba
)
2967 LPFC_MBOXQ_t
*mboxq
;
2968 struct lpfc_mbx_query_fw_cfg
*query_fw_cfg
;
2970 uint32_t shdr_status
, shdr_add_status
;
2972 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2974 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2975 "2621 Failed to allocate mbox for "
2976 "query firmware config cmd\n");
2979 query_fw_cfg
= &mboxq
->u
.mqe
.un
.query_fw_cfg
;
2980 length
= (sizeof(struct lpfc_mbx_query_fw_cfg
) -
2981 sizeof(struct lpfc_sli4_cfg_mhdr
));
2982 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
2983 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
2984 length
, LPFC_SLI4_MBX_EMBED
);
2985 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
2986 /* The IOCTL status is embedded in the mailbox subheader. */
2987 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
2988 &query_fw_cfg
->header
.cfg_shdr
.response
);
2989 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
2990 &query_fw_cfg
->header
.cfg_shdr
.response
);
2991 if (shdr_status
|| shdr_add_status
|| rc
!= MBX_SUCCESS
) {
2992 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2993 "2622 Query Firmware Config failed "
2994 "mbx status x%x, status x%x add_status x%x\n",
2995 rc
, shdr_status
, shdr_add_status
);
2998 if (!bf_get(lpfc_function_mode_fcoe_i
, query_fw_cfg
)) {
2999 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3000 "2623 FCoE Function not supported by firmware. "
3001 "Function mode = %08x\n",
3002 query_fw_cfg
->function_mode
);
3005 if (rc
!= MBX_TIMEOUT
)
3006 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3011 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3012 * @phba: pointer to lpfc hba data structure.
3013 * @acqe_link: pointer to the async link completion queue entry.
3015 * This routine is to parse the SLI4 link-attention link fault code and
3016 * translate it into the base driver's read link attention mailbox command
3019 * Return: Link-attention status in terms of base driver's coding.
3022 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
3023 struct lpfc_acqe_link
*acqe_link
)
3025 uint16_t latt_fault
;
3027 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
3028 case LPFC_ASYNC_LINK_FAULT_NONE
:
3029 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
3030 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
3034 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3035 "0398 Invalid link fault code: x%x\n",
3036 bf_get(lpfc_acqe_link_fault
, acqe_link
));
3037 latt_fault
= MBXERR_ERROR
;
3044 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3045 * @phba: pointer to lpfc hba data structure.
3046 * @acqe_link: pointer to the async link completion queue entry.
3048 * This routine is to parse the SLI4 link attention type and translate it
3049 * into the base driver's link attention type coding.
3051 * Return: Link attention type in terms of base driver's coding.
3054 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
3055 struct lpfc_acqe_link
*acqe_link
)
3059 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
3060 case LPFC_ASYNC_LINK_STATUS_DOWN
:
3061 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
3062 att_type
= AT_LINK_DOWN
;
3064 case LPFC_ASYNC_LINK_STATUS_UP
:
3065 /* Ignore physical link up events - wait for logical link up */
3066 att_type
= AT_RESERVED
;
3068 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
3069 att_type
= AT_LINK_UP
;
3072 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3073 "0399 Invalid link attention type: x%x\n",
3074 bf_get(lpfc_acqe_link_status
, acqe_link
));
3075 att_type
= AT_RESERVED
;
3082 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3083 * @phba: pointer to lpfc hba data structure.
3084 * @acqe_link: pointer to the async link completion queue entry.
3086 * This routine is to parse the SLI4 link-attention link speed and translate
3087 * it into the base driver's link-attention link speed coding.
3089 * Return: Link-attention link speed in terms of base driver's coding.
3092 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
3093 struct lpfc_acqe_link
*acqe_link
)
3097 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
3098 case LPFC_ASYNC_LINK_SPEED_ZERO
:
3099 link_speed
= LA_UNKNW_LINK
;
3101 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
3102 link_speed
= LA_UNKNW_LINK
;
3104 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
3105 link_speed
= LA_UNKNW_LINK
;
3107 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
3108 link_speed
= LA_1GHZ_LINK
;
3110 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
3111 link_speed
= LA_10GHZ_LINK
;
3114 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3115 "0483 Invalid link-attention link speed: x%x\n",
3116 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3117 link_speed
= LA_UNKNW_LINK
;
3124 * lpfc_sli4_async_link_evt - Process the asynchronous link event
3125 * @phba: pointer to lpfc hba data structure.
3126 * @acqe_link: pointer to the async link completion queue entry.
3128 * This routine is to handle the SLI4 asynchronous link event.
3131 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
3132 struct lpfc_acqe_link
*acqe_link
)
3134 struct lpfc_dmabuf
*mp
;
3140 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
3141 if (att_type
!= AT_LINK_DOWN
&& att_type
!= AT_LINK_UP
)
3143 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
3144 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3146 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3147 "0395 The mboxq allocation failed\n");
3150 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3152 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3153 "0396 The lpfc_dmabuf allocation failed\n");
3156 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3158 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3159 "0397 The mbuf allocation failed\n");
3160 goto out_free_dmabuf
;
3163 /* Cleanup any outstanding ELS commands */
3164 lpfc_els_flush_all_cmd(phba
);
3166 /* Block ELS IOCBs until we have done process link event */
3167 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3169 /* Update link event statistics */
3170 phba
->sli
.slistat
.link_event
++;
3172 /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
3173 lpfc_read_la(phba
, pmb
, mp
);
3174 pmb
->vport
= phba
->pport
;
3176 /* Parse and translate status field */
3178 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
3180 /* Parse and translate link attention fields */
3181 la
= (READ_LA_VAR
*) &pmb
->u
.mb
.un
.varReadLA
;
3182 la
->eventTag
= acqe_link
->event_tag
;
3183 la
->attType
= att_type
;
3184 la
->UlnkSpeed
= lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
);
3186 /* Fake the the following irrelvant fields */
3187 la
->topology
= TOPOLOGY_PT_PT
;
3188 la
->granted_AL_PA
= 0;
3194 /* Keep the link status for extra SLI4 state machine reference */
3195 phba
->sli4_hba
.link_state
.speed
=
3196 bf_get(lpfc_acqe_link_speed
, acqe_link
);
3197 phba
->sli4_hba
.link_state
.duplex
=
3198 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
3199 phba
->sli4_hba
.link_state
.status
=
3200 bf_get(lpfc_acqe_link_status
, acqe_link
);
3201 phba
->sli4_hba
.link_state
.physical
=
3202 bf_get(lpfc_acqe_link_physical
, acqe_link
);
3203 phba
->sli4_hba
.link_state
.fault
=
3204 bf_get(lpfc_acqe_link_fault
, acqe_link
);
3205 phba
->sli4_hba
.link_state
.logical_speed
=
3206 bf_get(lpfc_acqe_qos_link_speed
, acqe_link
);
3208 /* Invoke the lpfc_handle_latt mailbox command callback function */
3209 lpfc_mbx_cmpl_read_la(phba
, pmb
);
3216 mempool_free(pmb
, phba
->mbox_mem_pool
);
3220 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3221 * @vport: pointer to vport data structure.
3223 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3224 * response to a CVL event.
3226 * Return the pointer to the ndlp with the vport if successful, otherwise
3229 static struct lpfc_nodelist
*
3230 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
3232 struct lpfc_nodelist
*ndlp
;
3233 struct Scsi_Host
*shost
;
3234 struct lpfc_hba
*phba
;
3238 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3244 if (phba
->pport
->port_state
<= LPFC_FLOGI
)
3246 /* If virtual link is not yet instantiated ignore CVL */
3247 if (vport
->port_state
<= LPFC_FDISC
)
3249 shost
= lpfc_shost_from_vport(vport
);
3252 lpfc_linkdown_port(vport
);
3253 lpfc_cleanup_pending_mbox(vport
);
3254 spin_lock_irq(shost
->host_lock
);
3255 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
3256 spin_unlock_irq(shost
->host_lock
);
3262 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3263 * @vport: pointer to lpfc hba data structure.
3265 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3266 * response to a FCF dead event.
3269 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
3271 struct lpfc_vport
**vports
;
3274 vports
= lpfc_create_vport_work_array(phba
);
3276 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3277 lpfc_sli4_perform_vport_cvl(vports
[i
]);
3278 lpfc_destroy_vport_work_array(phba
, vports
);
3282 * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
3283 * @phba: pointer to lpfc hba data structure.
3284 * @acqe_link: pointer to the async fcoe completion queue entry.
3286 * This routine is to handle the SLI4 asynchronous fcoe event.
3289 lpfc_sli4_async_fcoe_evt(struct lpfc_hba
*phba
,
3290 struct lpfc_acqe_fcoe
*acqe_fcoe
)
3292 uint8_t event_type
= bf_get(lpfc_acqe_fcoe_event_type
, acqe_fcoe
);
3294 struct lpfc_vport
*vport
;
3295 struct lpfc_nodelist
*ndlp
;
3296 struct Scsi_Host
*shost
;
3297 int active_vlink_present
;
3298 struct lpfc_vport
**vports
;
3301 phba
->fc_eventTag
= acqe_fcoe
->event_tag
;
3302 phba
->fcoe_eventtag
= acqe_fcoe
->event_tag
;
3303 switch (event_type
) {
3304 case LPFC_FCOE_EVENT_TYPE_NEW_FCF
:
3305 case LPFC_FCOE_EVENT_TYPE_FCF_PARAM_MOD
:
3306 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3307 "2546 New FCF found/FCF parameter modified event: "
3308 "evt_tag:x%x, fcf_index:x%x\n",
3309 acqe_fcoe
->event_tag
, acqe_fcoe
->index
);
3311 spin_lock_irq(&phba
->hbalock
);
3312 if ((phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) ||
3313 (phba
->hba_flag
& FCF_DISC_INPROGRESS
)) {
3315 * If the current FCF is in discovered state or
3316 * FCF discovery is in progress, do nothing.
3318 spin_unlock_irq(&phba
->hbalock
);
3322 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
3324 * If fast FCF failover rescan event is pending,
3327 spin_unlock_irq(&phba
->hbalock
);
3330 spin_unlock_irq(&phba
->hbalock
);
3332 if ((phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
3333 !(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
3335 * During period of FCF discovery, read the FCF
3336 * table record indexed by the event to update
3337 * FCF round robin failover eligible FCF bmask.
3339 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
3341 "2779 Read new FCF record with "
3342 "fcf_index:x%x for updating FCF "
3343 "round robin failover bmask\n",
3345 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fcoe
->index
);
3348 /* Otherwise, scan the entire FCF table and re-discover SAN */
3349 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3350 "2770 Start FCF table scan due to new FCF "
3351 "event: evt_tag:x%x, fcf_index:x%x\n",
3352 acqe_fcoe
->event_tag
, acqe_fcoe
->index
);
3353 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3354 LPFC_FCOE_FCF_GET_FIRST
);
3356 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3357 "2547 Issue FCF scan read FCF mailbox "
3358 "command failed 0x%x\n", rc
);
3361 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL
:
3362 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3363 "2548 FCF Table full count 0x%x tag 0x%x\n",
3364 bf_get(lpfc_acqe_fcoe_fcf_count
, acqe_fcoe
),
3365 acqe_fcoe
->event_tag
);
3368 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD
:
3369 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3370 "2549 FCF disconnected from network index 0x%x"
3371 " tag 0x%x\n", acqe_fcoe
->index
,
3372 acqe_fcoe
->event_tag
);
3373 /* If the event is not for currently used fcf do nothing */
3374 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fcoe
->index
)
3376 /* We request port to rediscover the entire FCF table for
3377 * a fast recovery from case that the current FCF record
3378 * is no longer valid if we are not in the middle of FCF
3379 * failover process already.
3381 spin_lock_irq(&phba
->hbalock
);
3382 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3383 spin_unlock_irq(&phba
->hbalock
);
3384 /* Update FLOGI FCF failover eligible FCF bmask */
3385 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fcoe
->index
);
3388 /* Mark the fast failover process in progress */
3389 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
3390 spin_unlock_irq(&phba
->hbalock
);
3391 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3392 "2771 Start FCF fast failover process due to "
3393 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
3394 "\n", acqe_fcoe
->event_tag
, acqe_fcoe
->index
);
3395 rc
= lpfc_sli4_redisc_fcf_table(phba
);
3397 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3399 "2772 Issue FCF rediscover mabilbox "
3400 "command failed, fail through to FCF "
3402 spin_lock_irq(&phba
->hbalock
);
3403 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
3404 spin_unlock_irq(&phba
->hbalock
);
3406 * Last resort will fail over by treating this
3407 * as a link down to FCF registration.
3409 lpfc_sli4_fcf_dead_failthrough(phba
);
3411 /* Handling fast FCF failover to a DEAD FCF event
3412 * is considered equalivant to receiving CVL to all
3415 lpfc_sli4_perform_all_vport_cvl(phba
);
3417 case LPFC_FCOE_EVENT_TYPE_CVL
:
3418 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3419 "2718 Clear Virtual Link Received for VPI 0x%x"
3420 " tag 0x%x\n", acqe_fcoe
->index
, acqe_fcoe
->event_tag
);
3421 vport
= lpfc_find_vport_by_vpid(phba
,
3422 acqe_fcoe
->index
- phba
->vpi_base
);
3423 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
3426 active_vlink_present
= 0;
3428 vports
= lpfc_create_vport_work_array(phba
);
3430 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
3432 if ((!(vports
[i
]->fc_flag
&
3433 FC_VPORT_CVL_RCVD
)) &&
3434 (vports
[i
]->port_state
> LPFC_FDISC
)) {
3435 active_vlink_present
= 1;
3439 lpfc_destroy_vport_work_array(phba
, vports
);
3442 if (active_vlink_present
) {
3444 * If there are other active VLinks present,
3445 * re-instantiate the Vlink using FDISC.
3447 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
3448 shost
= lpfc_shost_from_vport(vport
);
3449 spin_lock_irq(shost
->host_lock
);
3450 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3451 spin_unlock_irq(shost
->host_lock
);
3452 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
3453 vport
->port_state
= LPFC_FDISC
;
3456 * Otherwise, we request port to rediscover
3457 * the entire FCF table for a fast recovery
3458 * from possible case that the current FCF
3459 * is no longer valid if we are not already
3460 * in the FCF failover process.
3462 spin_lock_irq(&phba
->hbalock
);
3463 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3464 spin_unlock_irq(&phba
->hbalock
);
3467 /* Mark the fast failover process in progress */
3468 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
3469 spin_unlock_irq(&phba
->hbalock
);
3470 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
3472 "2773 Start FCF fast failover due "
3473 "to CVL event: evt_tag:x%x\n",
3474 acqe_fcoe
->event_tag
);
3475 rc
= lpfc_sli4_redisc_fcf_table(phba
);
3477 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3479 "2774 Issue FCF rediscover "
3480 "mabilbox command failed, "
3481 "through to CVL event\n");
3482 spin_lock_irq(&phba
->hbalock
);
3483 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
3484 spin_unlock_irq(&phba
->hbalock
);
3486 * Last resort will be re-try on the
3487 * the current registered FCF entry.
3489 lpfc_retry_pport_discovery(phba
);
3494 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3495 "0288 Unknown FCoE event type 0x%x event tag "
3496 "0x%x\n", event_type
, acqe_fcoe
->event_tag
);
3502 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
3503 * @phba: pointer to lpfc hba data structure.
3504 * @acqe_link: pointer to the async dcbx completion queue entry.
3506 * This routine is to handle the SLI4 asynchronous dcbx event.
3509 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
3510 struct lpfc_acqe_dcbx
*acqe_dcbx
)
3512 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
3513 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3514 "0290 The SLI4 DCBX asynchronous event is not "
3519 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
3520 * @phba: pointer to lpfc hba data structure.
3522 * This routine is invoked by the worker thread to process all the pending
3523 * SLI4 asynchronous events.
3525 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
3527 struct lpfc_cq_event
*cq_event
;
3529 /* First, declare the async event has been handled */
3530 spin_lock_irq(&phba
->hbalock
);
3531 phba
->hba_flag
&= ~ASYNC_EVENT
;
3532 spin_unlock_irq(&phba
->hbalock
);
3533 /* Now, handle all the async events */
3534 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
3535 /* Get the first event from the head of the event queue */
3536 spin_lock_irq(&phba
->hbalock
);
3537 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
3538 cq_event
, struct lpfc_cq_event
, list
);
3539 spin_unlock_irq(&phba
->hbalock
);
3540 /* Process the asynchronous event */
3541 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
3542 case LPFC_TRAILER_CODE_LINK
:
3543 lpfc_sli4_async_link_evt(phba
,
3544 &cq_event
->cqe
.acqe_link
);
3546 case LPFC_TRAILER_CODE_FCOE
:
3547 lpfc_sli4_async_fcoe_evt(phba
,
3548 &cq_event
->cqe
.acqe_fcoe
);
3550 case LPFC_TRAILER_CODE_DCBX
:
3551 lpfc_sli4_async_dcbx_evt(phba
,
3552 &cq_event
->cqe
.acqe_dcbx
);
3555 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3556 "1804 Invalid asynchrous event code: "
3557 "x%x\n", bf_get(lpfc_trailer_code
,
3558 &cq_event
->cqe
.mcqe_cmpl
));
3561 /* Free the completion event processed to the free pool */
3562 lpfc_sli4_cq_event_release(phba
, cq_event
);
3567 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
3568 * @phba: pointer to lpfc hba data structure.
3570 * This routine is invoked by the worker thread to process FCF table
3571 * rediscovery pending completion event.
3573 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
3577 spin_lock_irq(&phba
->hbalock
);
3578 /* Clear FCF rediscovery timeout event */
3579 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
3580 /* Clear driver fast failover FCF record flag */
3581 phba
->fcf
.failover_rec
.flag
= 0;
3582 /* Set state for FCF fast failover */
3583 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
3584 spin_unlock_irq(&phba
->hbalock
);
3586 /* Scan FCF table from the first entry to re-discover SAN */
3587 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3588 "2777 Start FCF table scan after FCF "
3589 "rediscovery quiescent period over\n");
3590 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
3592 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3593 "2747 Issue FCF scan read FCF mailbox "
3594 "command failed 0x%x\n", rc
);
3598 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3599 * @phba: pointer to lpfc hba data structure.
3600 * @dev_grp: The HBA PCI-Device group number.
3602 * This routine is invoked to set up the per HBA PCI-Device group function
3603 * API jump table entries.
3605 * Return: 0 if success, otherwise -ENODEV
3608 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
3612 /* Set up lpfc PCI-device group */
3613 phba
->pci_dev_grp
= dev_grp
;
3615 /* The LPFC_PCI_DEV_OC uses SLI4 */
3616 if (dev_grp
== LPFC_PCI_DEV_OC
)
3617 phba
->sli_rev
= LPFC_SLI_REV4
;
3619 /* Set up device INIT API function jump table */
3620 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
3623 /* Set up SCSI API function jump table */
3624 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
3627 /* Set up SLI API function jump table */
3628 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
3631 /* Set up MBOX API function jump table */
3632 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
3640 * lpfc_log_intr_mode - Log the active interrupt mode
3641 * @phba: pointer to lpfc hba data structure.
3642 * @intr_mode: active interrupt mode adopted.
3644 * This routine it invoked to log the currently used active interrupt mode
3647 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
3649 switch (intr_mode
) {
3651 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3652 "0470 Enable INTx interrupt mode.\n");
3655 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3656 "0481 Enabled MSI interrupt mode.\n");
3659 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3660 "0480 Enabled MSI-X interrupt mode.\n");
3663 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3664 "0482 Illegal interrupt mode.\n");
3671 * lpfc_enable_pci_dev - Enable a generic PCI device.
3672 * @phba: pointer to lpfc hba data structure.
3674 * This routine is invoked to enable the PCI device that is common to all
3679 * other values - error
3682 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
3684 struct pci_dev
*pdev
;
3687 /* Obtain PCI device reference */
3691 pdev
= phba
->pcidev
;
3692 /* Select PCI BARs */
3693 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
3694 /* Enable PCI device */
3695 if (pci_enable_device_mem(pdev
))
3697 /* Request PCI resource for the device */
3698 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
3699 goto out_disable_device
;
3700 /* Set up device as PCI master and save state for EEH */
3701 pci_set_master(pdev
);
3702 pci_try_set_mwi(pdev
);
3703 pci_save_state(pdev
);
3708 pci_disable_device(pdev
);
3714 * lpfc_disable_pci_dev - Disable a generic PCI device.
3715 * @phba: pointer to lpfc hba data structure.
3717 * This routine is invoked to disable the PCI device that is common to all
3721 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
3723 struct pci_dev
*pdev
;
3726 /* Obtain PCI device reference */
3730 pdev
= phba
->pcidev
;
3731 /* Select PCI BARs */
3732 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
3733 /* Release PCI resource and disable PCI device */
3734 pci_release_selected_regions(pdev
, bars
);
3735 pci_disable_device(pdev
);
3736 /* Null out PCI private reference to driver */
3737 pci_set_drvdata(pdev
, NULL
);
3743 * lpfc_reset_hba - Reset a hba
3744 * @phba: pointer to lpfc hba data structure.
3746 * This routine is invoked to reset a hba device. It brings the HBA
3747 * offline, performs a board restart, and then brings the board back
3748 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
3749 * on outstanding mailbox commands.
3752 lpfc_reset_hba(struct lpfc_hba
*phba
)
3754 /* If resets are disabled then set error state and return. */
3755 if (!phba
->cfg_enable_hba_reset
) {
3756 phba
->link_state
= LPFC_HBA_ERROR
;
3759 lpfc_offline_prep(phba
);
3761 lpfc_sli_brdrestart(phba
);
3763 lpfc_unblock_mgmt_io(phba
);
3767 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
3768 * @phba: pointer to lpfc hba data structure.
3770 * This routine is invoked to set up the driver internal resources specific to
3771 * support the SLI-3 HBA device it attached to.
3775 * other values - error
3778 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
3780 struct lpfc_sli
*psli
;
3783 * Initialize timers used by driver
3786 /* Heartbeat timer */
3787 init_timer(&phba
->hb_tmofunc
);
3788 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
3789 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
3792 /* MBOX heartbeat timer */
3793 init_timer(&psli
->mbox_tmo
);
3794 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
3795 psli
->mbox_tmo
.data
= (unsigned long) phba
;
3796 /* FCP polling mode timer */
3797 init_timer(&phba
->fcp_poll_timer
);
3798 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
3799 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
3800 /* Fabric block timer */
3801 init_timer(&phba
->fabric_block_timer
);
3802 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
3803 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
3804 /* EA polling mode timer */
3805 init_timer(&phba
->eratt_poll
);
3806 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
3807 phba
->eratt_poll
.data
= (unsigned long) phba
;
3809 /* Host attention work mask setup */
3810 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
3811 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
3813 /* Get all the module params for configuring this host */
3814 lpfc_get_cfgparam(phba
);
3816 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3817 * used to create the sg_dma_buf_pool must be dynamically calculated.
3818 * 2 segments are added since the IOCB needs a command and response bde.
3820 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
3821 sizeof(struct fcp_rsp
) +
3822 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
3824 if (phba
->cfg_enable_bg
) {
3825 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
3826 phba
->cfg_sg_dma_buf_size
+=
3827 phba
->cfg_prot_sg_seg_cnt
* sizeof(struct ulp_bde64
);
3830 /* Also reinitialize the host templates with new values. */
3831 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3832 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3834 phba
->max_vpi
= LPFC_MAX_VPI
;
3835 /* This will be set to correct value after config_port mbox */
3836 phba
->max_vports
= 0;
3839 * Initialize the SLI Layer to run with lpfc HBAs.
3841 lpfc_sli_setup(phba
);
3842 lpfc_sli_queue_setup(phba
);
3844 /* Allocate device driver memory */
3845 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
3852 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
3853 * @phba: pointer to lpfc hba data structure.
3855 * This routine is invoked to unset the driver internal resources set up
3856 * specific for supporting the SLI-3 HBA device it attached to.
3859 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
3861 /* Free device driver memory allocated */
3862 lpfc_mem_free_all(phba
);
3868 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
3869 * @phba: pointer to lpfc hba data structure.
3871 * This routine is invoked to set up the driver internal resources specific to
3872 * support the SLI-4 HBA device it attached to.
3876 * other values - error
3879 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
3881 struct lpfc_sli
*psli
;
3882 LPFC_MBOXQ_t
*mboxq
;
3883 int rc
, i
, hbq_count
, buf_size
, dma_buf_size
, max_buf_size
;
3884 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
3885 struct lpfc_mqe
*mqe
;
3888 /* Before proceed, wait for POST done and device ready */
3889 rc
= lpfc_sli4_post_status_check(phba
);
3894 * Initialize timers used by driver
3897 /* Heartbeat timer */
3898 init_timer(&phba
->hb_tmofunc
);
3899 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
3900 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
3903 /* MBOX heartbeat timer */
3904 init_timer(&psli
->mbox_tmo
);
3905 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
3906 psli
->mbox_tmo
.data
= (unsigned long) phba
;
3907 /* Fabric block timer */
3908 init_timer(&phba
->fabric_block_timer
);
3909 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
3910 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
3911 /* EA polling mode timer */
3912 init_timer(&phba
->eratt_poll
);
3913 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
3914 phba
->eratt_poll
.data
= (unsigned long) phba
;
3915 /* FCF rediscover timer */
3916 init_timer(&phba
->fcf
.redisc_wait
);
3917 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
3918 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
3921 * We need to do a READ_CONFIG mailbox command here before
3922 * calling lpfc_get_cfgparam. For VFs this will report the
3923 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
3924 * All of the resources allocated
3925 * for this Port are tied to these values.
3927 /* Get all the module params for configuring this host */
3928 lpfc_get_cfgparam(phba
);
3929 phba
->max_vpi
= LPFC_MAX_VPI
;
3930 /* This will be set to correct value after the read_config mbox */
3931 phba
->max_vports
= 0;
3933 /* Program the default value of vlan_id and fc_map */
3934 phba
->valid_vlan
= 0;
3935 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
3936 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
3937 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
3940 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3941 * used to create the sg_dma_buf_pool must be dynamically calculated.
3942 * 2 segments are added since the IOCB needs a command and response bde.
3943 * To insure that the scsi sgl does not cross a 4k page boundary only
3944 * sgl sizes of must be a power of 2.
3946 buf_size
= (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
) +
3947 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct sli4_sge
)));
3948 /* Feature Level 1 hardware is limited to 2 pages */
3949 if ((bf_get(lpfc_sli_intf_featurelevel1
, &phba
->sli4_hba
.sli_intf
) ==
3950 LPFC_SLI_INTF_FEATURELEVEL1_1
))
3951 max_buf_size
= LPFC_SLI4_FL1_MAX_BUF_SIZE
;
3953 max_buf_size
= LPFC_SLI4_MAX_BUF_SIZE
;
3954 for (dma_buf_size
= LPFC_SLI4_MIN_BUF_SIZE
;
3955 dma_buf_size
< max_buf_size
&& buf_size
> dma_buf_size
;
3956 dma_buf_size
= dma_buf_size
<< 1)
3958 if (dma_buf_size
== max_buf_size
)
3959 phba
->cfg_sg_seg_cnt
= (dma_buf_size
-
3960 sizeof(struct fcp_cmnd
) - sizeof(struct fcp_rsp
) -
3961 (2 * sizeof(struct sli4_sge
))) /
3962 sizeof(struct sli4_sge
);
3963 phba
->cfg_sg_dma_buf_size
= dma_buf_size
;
3965 /* Initialize buffer queue management fields */
3966 hbq_count
= lpfc_sli_hbq_count();
3967 for (i
= 0; i
< hbq_count
; ++i
)
3968 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
3969 INIT_LIST_HEAD(&phba
->rb_pend_list
);
3970 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
3971 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
3974 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
3976 /* Initialize the Abort scsi buffer list used by driver */
3977 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
3978 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
3979 /* This abort list used by worker thread */
3980 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
3983 * Initialize dirver internal slow-path work queues
3986 /* Driver internel slow-path CQ Event pool */
3987 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
3988 /* Response IOCB work queue list */
3989 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
3990 /* Asynchronous event CQ Event work queue list */
3991 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
3992 /* Fast-path XRI aborted CQ Event work queue list */
3993 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
3994 /* Slow-path XRI aborted CQ Event work queue list */
3995 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
3996 /* Receive queue CQ Event work queue list */
3997 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
3999 /* Initialize the driver internal SLI layer lists. */
4000 lpfc_sli_setup(phba
);
4001 lpfc_sli_queue_setup(phba
);
4003 /* Allocate device driver memory */
4004 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
4008 /* Create the bootstrap mailbox command */
4009 rc
= lpfc_create_bootstrap_mbox(phba
);
4013 /* Set up the host's endian order with the device. */
4014 rc
= lpfc_setup_endian_order(phba
);
4016 goto out_free_bsmbx
;
4018 rc
= lpfc_sli4_fw_cfg_check(phba
);
4020 goto out_free_bsmbx
;
4022 /* Set up the hba's configuration parameters. */
4023 rc
= lpfc_sli4_read_config(phba
);
4025 goto out_free_bsmbx
;
4027 /* Perform a function reset */
4028 rc
= lpfc_pci_function_reset(phba
);
4030 goto out_free_bsmbx
;
4032 /* Create all the SLI4 queues */
4033 rc
= lpfc_sli4_queue_create(phba
);
4035 goto out_free_bsmbx
;
4037 /* Create driver internal CQE event pool */
4038 rc
= lpfc_sli4_cq_event_pool_create(phba
);
4040 goto out_destroy_queue
;
4042 /* Initialize and populate the iocb list per host */
4043 rc
= lpfc_init_sgl_list(phba
);
4045 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4046 "1400 Failed to initialize sgl list.\n");
4047 goto out_destroy_cq_event_pool
;
4049 rc
= lpfc_init_active_sgl_array(phba
);
4051 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4052 "1430 Failed to initialize sgl list.\n");
4053 goto out_free_sgl_list
;
4056 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
4058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4059 "1432 Failed to initialize rpi headers.\n");
4060 goto out_free_active_sgl
;
4063 /* Allocate eligible FCF bmask memory for FCF round robin failover */
4064 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
4065 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
4067 if (!phba
->fcf
.fcf_rr_bmask
) {
4068 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4069 "2759 Failed allocate memory for FCF round "
4070 "robin failover bmask\n");
4071 goto out_remove_rpi_hdrs
;
4074 phba
->sli4_hba
.fcp_eq_hdl
= kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
4075 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
4076 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
4077 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4078 "2572 Failed allocate memory for fast-path "
4079 "per-EQ handle array\n");
4080 goto out_free_fcf_rr_bmask
;
4083 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
4084 phba
->sli4_hba
.cfg_eqn
), GFP_KERNEL
);
4085 if (!phba
->sli4_hba
.msix_entries
) {
4086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4087 "2573 Failed allocate memory for msi-x "
4088 "interrupt vector entries\n");
4089 goto out_free_fcp_eq_hdl
;
4092 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
4096 goto out_free_fcp_eq_hdl
;
4099 /* Get the Supported Pages. It is always available. */
4100 lpfc_supported_pages(mboxq
);
4101 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4104 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4105 goto out_free_fcp_eq_hdl
;
4108 mqe
= &mboxq
->u
.mqe
;
4109 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
4110 LPFC_MAX_SUPPORTED_PAGES
);
4111 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
4112 switch (pn_page
[i
]) {
4113 case LPFC_SLI4_PARAMETERS
:
4114 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
4121 /* Read the port's SLI4 Parameters capabilities if supported. */
4122 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
4123 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
4124 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4127 goto out_free_fcp_eq_hdl
;
4131 out_free_fcp_eq_hdl
:
4132 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
4133 out_free_fcf_rr_bmask
:
4134 kfree(phba
->fcf
.fcf_rr_bmask
);
4135 out_remove_rpi_hdrs
:
4136 lpfc_sli4_remove_rpi_hdrs(phba
);
4137 out_free_active_sgl
:
4138 lpfc_free_active_sgl(phba
);
4140 lpfc_free_sgl_list(phba
);
4141 out_destroy_cq_event_pool
:
4142 lpfc_sli4_cq_event_pool_destroy(phba
);
4144 lpfc_sli4_queue_destroy(phba
);
4146 lpfc_destroy_bootstrap_mbox(phba
);
4148 lpfc_mem_free(phba
);
4153 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4154 * @phba: pointer to lpfc hba data structure.
4156 * This routine is invoked to unset the driver internal resources set up
4157 * specific for supporting the SLI-4 HBA device it attached to.
4160 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
4162 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
4164 /* unregister default FCFI from the HBA */
4165 lpfc_sli4_fcfi_unreg(phba
, phba
->fcf
.fcfi
);
4167 /* Free the default FCR table */
4168 lpfc_sli_remove_dflt_fcf(phba
);
4170 /* Free memory allocated for msi-x interrupt vector entries */
4171 kfree(phba
->sli4_hba
.msix_entries
);
4173 /* Free memory allocated for fast-path work queue handles */
4174 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
4176 /* Free the allocated rpi headers. */
4177 lpfc_sli4_remove_rpi_hdrs(phba
);
4178 lpfc_sli4_remove_rpis(phba
);
4180 /* Free eligible FCF index bmask */
4181 kfree(phba
->fcf
.fcf_rr_bmask
);
4183 /* Free the ELS sgl list */
4184 lpfc_free_active_sgl(phba
);
4185 lpfc_free_sgl_list(phba
);
4187 /* Free the SCSI sgl management array */
4188 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
4190 /* Free the SLI4 queues */
4191 lpfc_sli4_queue_destroy(phba
);
4193 /* Free the completion queue EQ event pool */
4194 lpfc_sli4_cq_event_release_all(phba
);
4195 lpfc_sli4_cq_event_pool_destroy(phba
);
4197 /* Reset SLI4 HBA FCoE function */
4198 lpfc_pci_function_reset(phba
);
4200 /* Free the bsmbx region. */
4201 lpfc_destroy_bootstrap_mbox(phba
);
4203 /* Free the SLI Layer memory with SLI4 HBAs */
4204 lpfc_mem_free_all(phba
);
4206 /* Free the current connect table */
4207 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
4208 &phba
->fcf_conn_rec_list
, list
) {
4209 list_del_init(&conn_entry
->list
);
4217 * lpfc_init_api_table_setup - Set up init api fucntion jump table
4218 * @phba: The hba struct for which this call is being executed.
4219 * @dev_grp: The HBA PCI-Device group number.
4221 * This routine sets up the device INIT interface API function jump table
4224 * Returns: 0 - success, -ENODEV - failure.
4227 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4229 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
4230 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
4232 case LPFC_PCI_DEV_LP
:
4233 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
4234 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
4235 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
4237 case LPFC_PCI_DEV_OC
:
4238 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
4239 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
4240 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
4243 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4244 "1431 Invalid HBA PCI-device group: 0x%x\n",
4253 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
4254 * @phba: pointer to lpfc hba data structure.
4256 * This routine is invoked to set up the driver internal resources before the
4257 * device specific resource setup to support the HBA device it attached to.
4261 * other values - error
4264 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
4267 * Driver resources common to all SLI revisions
4269 atomic_set(&phba
->fast_event_count
, 0);
4270 spin_lock_init(&phba
->hbalock
);
4272 /* Initialize ndlp management spinlock */
4273 spin_lock_init(&phba
->ndlp_lock
);
4275 INIT_LIST_HEAD(&phba
->port_list
);
4276 INIT_LIST_HEAD(&phba
->work_list
);
4277 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
4279 /* Initialize the wait queue head for the kernel thread */
4280 init_waitqueue_head(&phba
->work_waitq
);
4282 /* Initialize the scsi buffer list used by driver for scsi IO */
4283 spin_lock_init(&phba
->scsi_buf_list_lock
);
4284 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
4286 /* Initialize the fabric iocb list */
4287 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
4289 /* Initialize list to save ELS buffers */
4290 INIT_LIST_HEAD(&phba
->elsbuf
);
4292 /* Initialize FCF connection rec list */
4293 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
4299 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
4300 * @phba: pointer to lpfc hba data structure.
4302 * This routine is invoked to set up the driver internal resources after the
4303 * device specific resource setup to support the HBA device it attached to.
4307 * other values - error
4310 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
4314 /* Startup the kernel thread for this host adapter. */
4315 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
4316 "lpfc_worker_%d", phba
->brd_no
);
4317 if (IS_ERR(phba
->worker_thread
)) {
4318 error
= PTR_ERR(phba
->worker_thread
);
4326 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
4327 * @phba: pointer to lpfc hba data structure.
4329 * This routine is invoked to unset the driver internal resources set up after
4330 * the device specific resource setup for supporting the HBA device it
4334 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
4336 /* Stop kernel worker thread */
4337 kthread_stop(phba
->worker_thread
);
4341 * lpfc_free_iocb_list - Free iocb list.
4342 * @phba: pointer to lpfc hba data structure.
4344 * This routine is invoked to free the driver's IOCB list and memory.
4347 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
4349 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
4351 spin_lock_irq(&phba
->hbalock
);
4352 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
4353 &phba
->lpfc_iocb_list
, list
) {
4354 list_del(&iocbq_entry
->list
);
4356 phba
->total_iocbq_bufs
--;
4358 spin_unlock_irq(&phba
->hbalock
);
4364 * lpfc_init_iocb_list - Allocate and initialize iocb list.
4365 * @phba: pointer to lpfc hba data structure.
4367 * This routine is invoked to allocate and initizlize the driver's IOCB
4368 * list and set up the IOCB tag array accordingly.
4372 * other values - error
4375 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
4377 struct lpfc_iocbq
*iocbq_entry
= NULL
;
4381 /* Initialize and populate the iocb list per host. */
4382 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
4383 for (i
= 0; i
< iocb_count
; i
++) {
4384 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
4385 if (iocbq_entry
== NULL
) {
4386 printk(KERN_ERR
"%s: only allocated %d iocbs of "
4387 "expected %d count. Unloading driver.\n",
4388 __func__
, i
, LPFC_IOCB_LIST_CNT
);
4389 goto out_free_iocbq
;
4392 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
4395 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
4396 "Unloading driver.\n", __func__
);
4397 goto out_free_iocbq
;
4399 iocbq_entry
->sli4_xritag
= NO_XRI
;
4401 spin_lock_irq(&phba
->hbalock
);
4402 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
4403 phba
->total_iocbq_bufs
++;
4404 spin_unlock_irq(&phba
->hbalock
);
4410 lpfc_free_iocb_list(phba
);
4416 * lpfc_free_sgl_list - Free sgl list.
4417 * @phba: pointer to lpfc hba data structure.
4419 * This routine is invoked to free the driver's sgl list and memory.
4422 lpfc_free_sgl_list(struct lpfc_hba
*phba
)
4424 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
4425 LIST_HEAD(sglq_list
);
4428 spin_lock_irq(&phba
->hbalock
);
4429 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
4430 spin_unlock_irq(&phba
->hbalock
);
4432 list_for_each_entry_safe(sglq_entry
, sglq_next
,
4434 list_del(&sglq_entry
->list
);
4435 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
4437 phba
->sli4_hba
.total_sglq_bufs
--;
4439 rc
= lpfc_sli4_remove_all_sgl_pages(phba
);
4441 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4442 "2005 Unable to deregister pages from HBA: %x\n", rc
);
4444 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
4448 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
4449 * @phba: pointer to lpfc hba data structure.
4451 * This routine is invoked to allocate the driver's active sgl memory.
4452 * This array will hold the sglq_entry's for active IOs.
4455 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
4458 size
= sizeof(struct lpfc_sglq
*);
4459 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
4461 phba
->sli4_hba
.lpfc_sglq_active_list
=
4462 kzalloc(size
, GFP_KERNEL
);
4463 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
4469 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
4470 * @phba: pointer to lpfc hba data structure.
4472 * This routine is invoked to walk through the array of active sglq entries
4473 * and free all of the resources.
4474 * This is just a place holder for now.
4477 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
4479 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
4483 * lpfc_init_sgl_list - Allocate and initialize sgl list.
4484 * @phba: pointer to lpfc hba data structure.
4486 * This routine is invoked to allocate and initizlize the driver's sgl
4487 * list and set up the sgl xritag tag array accordingly.
4491 * other values - error
4494 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
4496 struct lpfc_sglq
*sglq_entry
= NULL
;
4500 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
4501 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4502 "2400 lpfc_init_sgl_list els %d.\n",
4504 /* Initialize and populate the sglq list per host/VF. */
4505 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
4506 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
4508 /* Sanity check on XRI management */
4509 if (phba
->sli4_hba
.max_cfg_param
.max_xri
<= els_xri_cnt
) {
4510 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4511 "2562 No room left for SCSI XRI allocation: "
4512 "max_xri=%d, els_xri=%d\n",
4513 phba
->sli4_hba
.max_cfg_param
.max_xri
,
4518 /* Allocate memory for the ELS XRI management array */
4519 phba
->sli4_hba
.lpfc_els_sgl_array
=
4520 kzalloc((sizeof(struct lpfc_sglq
*) * els_xri_cnt
),
4523 if (!phba
->sli4_hba
.lpfc_els_sgl_array
) {
4524 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4525 "2401 Failed to allocate memory for ELS "
4526 "XRI management array of size %d.\n",
4531 /* Keep the SCSI XRI into the XRI management array */
4532 phba
->sli4_hba
.scsi_xri_max
=
4533 phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
4534 phba
->sli4_hba
.scsi_xri_cnt
= 0;
4536 phba
->sli4_hba
.lpfc_scsi_psb_array
=
4537 kzalloc((sizeof(struct lpfc_scsi_buf
*) *
4538 phba
->sli4_hba
.scsi_xri_max
), GFP_KERNEL
);
4540 if (!phba
->sli4_hba
.lpfc_scsi_psb_array
) {
4541 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4542 "2563 Failed to allocate memory for SCSI "
4543 "XRI management array of size %d.\n",
4544 phba
->sli4_hba
.scsi_xri_max
);
4545 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
4549 for (i
= 0; i
< els_xri_cnt
; i
++) {
4550 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
), GFP_KERNEL
);
4551 if (sglq_entry
== NULL
) {
4552 printk(KERN_ERR
"%s: only allocated %d sgls of "
4553 "expected %d count. Unloading driver.\n",
4554 __func__
, i
, els_xri_cnt
);
4558 sglq_entry
->sli4_xritag
= lpfc_sli4_next_xritag(phba
);
4559 if (sglq_entry
->sli4_xritag
== NO_XRI
) {
4561 printk(KERN_ERR
"%s: failed to allocate XRI.\n"
4562 "Unloading driver.\n", __func__
);
4565 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
4566 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0, &sglq_entry
->phys
);
4567 if (sglq_entry
->virt
== NULL
) {
4569 printk(KERN_ERR
"%s: failed to allocate mbuf.\n"
4570 "Unloading driver.\n", __func__
);
4573 sglq_entry
->sgl
= sglq_entry
->virt
;
4574 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
4576 /* The list order is used by later block SGL registraton */
4577 spin_lock_irq(&phba
->hbalock
);
4578 sglq_entry
->state
= SGL_FREED
;
4579 list_add_tail(&sglq_entry
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
4580 phba
->sli4_hba
.lpfc_els_sgl_array
[i
] = sglq_entry
;
4581 phba
->sli4_hba
.total_sglq_bufs
++;
4582 spin_unlock_irq(&phba
->hbalock
);
4587 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
4588 lpfc_free_sgl_list(phba
);
4593 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
4594 * @phba: pointer to lpfc hba data structure.
4596 * This routine is invoked to post rpi header templates to the
4597 * HBA consistent with the SLI-4 interface spec. This routine
4598 * posts a PAGE_SIZE memory region to the port to hold up to
4599 * PAGE_SIZE modulo 64 rpi context headers.
4600 * No locks are held here because this is an initialization routine
4601 * called only from probe or lpfc_online when interrupts are not
4602 * enabled and the driver is reinitializing the device.
4606 * ENOMEM - No availble memory
4607 * EIO - The mailbox failed to complete successfully.
4610 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
4615 struct lpfc_rpi_hdr
*rpi_hdr
;
4617 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
4620 * Provision an rpi bitmask range for discovery. The total count
4621 * is the difference between max and base + 1.
4623 rpi_count
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
4624 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
4626 longs
= ((rpi_count
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
4627 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4629 if (!phba
->sli4_hba
.rpi_bmask
)
4632 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
4634 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4635 "0391 Error during rpi post operation\n");
4636 lpfc_sli4_remove_rpis(phba
);
4644 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
4645 * @phba: pointer to lpfc hba data structure.
4647 * This routine is invoked to allocate a single 4KB memory region to
4648 * support rpis and stores them in the phba. This single region
4649 * provides support for up to 64 rpis. The region is used globally
4653 * A valid rpi hdr on success.
4654 * A NULL pointer on any failure.
4656 struct lpfc_rpi_hdr
*
4657 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
4659 uint16_t rpi_limit
, curr_rpi_range
;
4660 struct lpfc_dmabuf
*dmabuf
;
4661 struct lpfc_rpi_hdr
*rpi_hdr
;
4663 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
4664 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
4666 spin_lock_irq(&phba
->hbalock
);
4667 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
4668 spin_unlock_irq(&phba
->hbalock
);
4671 * The port has a limited number of rpis. The increment here
4672 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
4673 * and to allow the full max_rpi range per port.
4675 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
4679 * First allocate the protocol header region for the port. The
4680 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
4682 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4686 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4687 LPFC_HDR_TEMPLATE_SIZE
,
4690 if (!dmabuf
->virt
) {
4692 goto err_free_dmabuf
;
4695 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
4696 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
4698 goto err_free_coherent
;
4701 /* Save the rpi header data for cleanup later. */
4702 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
4704 goto err_free_coherent
;
4706 rpi_hdr
->dmabuf
= dmabuf
;
4707 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
4708 rpi_hdr
->page_count
= 1;
4709 spin_lock_irq(&phba
->hbalock
);
4710 rpi_hdr
->start_rpi
= phba
->sli4_hba
.next_rpi
;
4711 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
4714 * The next_rpi stores the next module-64 rpi value to post
4715 * in any subsequent rpi memory region postings.
4717 phba
->sli4_hba
.next_rpi
+= LPFC_RPI_HDR_COUNT
;
4718 spin_unlock_irq(&phba
->hbalock
);
4722 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
4723 dmabuf
->virt
, dmabuf
->phys
);
4730 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
4731 * @phba: pointer to lpfc hba data structure.
4733 * This routine is invoked to remove all memory resources allocated
4734 * to support rpis. This routine presumes the caller has released all
4735 * rpis consumed by fabric or port logins and is prepared to have
4736 * the header pages removed.
4739 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
4741 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
4743 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
4744 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
4745 list_del(&rpi_hdr
->list
);
4746 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
4747 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
4748 kfree(rpi_hdr
->dmabuf
);
4752 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
4753 memset(phba
->sli4_hba
.rpi_bmask
, 0, sizeof(*phba
->sli4_hba
.rpi_bmask
));
4757 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
4758 * @pdev: pointer to pci device data structure.
4760 * This routine is invoked to allocate the driver hba data structure for an
4761 * HBA device. If the allocation is successful, the phba reference to the
4762 * PCI device data structure is set.
4765 * pointer to @phba - successful
4768 static struct lpfc_hba
*
4769 lpfc_hba_alloc(struct pci_dev
*pdev
)
4771 struct lpfc_hba
*phba
;
4773 /* Allocate memory for HBA structure */
4774 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
4776 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
4780 /* Set reference to PCI device in HBA structure */
4781 phba
->pcidev
= pdev
;
4783 /* Assign an unused board number */
4784 phba
->brd_no
= lpfc_get_instance();
4785 if (phba
->brd_no
< 0) {
4790 spin_lock_init(&phba
->ct_ev_lock
);
4791 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
4797 * lpfc_hba_free - Free driver hba data structure with a device.
4798 * @phba: pointer to lpfc hba data structure.
4800 * This routine is invoked to free the driver hba data structure with an
4804 lpfc_hba_free(struct lpfc_hba
*phba
)
4806 /* Release the driver assigned board number */
4807 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
4814 * lpfc_create_shost - Create hba physical port with associated scsi host.
4815 * @phba: pointer to lpfc hba data structure.
4817 * This routine is invoked to create HBA physical port and associate a SCSI
4822 * other values - error
4825 lpfc_create_shost(struct lpfc_hba
*phba
)
4827 struct lpfc_vport
*vport
;
4828 struct Scsi_Host
*shost
;
4830 /* Initialize HBA FC structure */
4831 phba
->fc_edtov
= FF_DEF_EDTOV
;
4832 phba
->fc_ratov
= FF_DEF_RATOV
;
4833 phba
->fc_altov
= FF_DEF_ALTOV
;
4834 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
4836 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
4840 shost
= lpfc_shost_from_vport(vport
);
4841 phba
->pport
= vport
;
4842 lpfc_debugfs_initialize(vport
);
4843 /* Put reference to SCSI host to driver's device private data */
4844 pci_set_drvdata(phba
->pcidev
, shost
);
4850 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
4851 * @phba: pointer to lpfc hba data structure.
4853 * This routine is invoked to destroy HBA physical port and the associated
4857 lpfc_destroy_shost(struct lpfc_hba
*phba
)
4859 struct lpfc_vport
*vport
= phba
->pport
;
4861 /* Destroy physical port that associated with the SCSI host */
4862 destroy_port(vport
);
4868 * lpfc_setup_bg - Setup Block guard structures and debug areas.
4869 * @phba: pointer to lpfc hba data structure.
4870 * @shost: the shost to be used to detect Block guard settings.
4872 * This routine sets up the local Block guard protocol settings for @shost.
4873 * This routine also allocates memory for debugging bg buffers.
4876 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
4879 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
4880 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4881 "1478 Registering BlockGuard with the "
4883 scsi_host_set_prot(shost
, lpfc_prot_mask
);
4884 scsi_host_set_guard(shost
, lpfc_prot_guard
);
4886 if (!_dump_buf_data
) {
4888 spin_lock_init(&_dump_buf_lock
);
4890 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
4891 if (_dump_buf_data
) {
4892 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4893 "9043 BLKGRD: allocated %d pages for "
4894 "_dump_buf_data at 0x%p\n",
4895 (1 << pagecnt
), _dump_buf_data
);
4896 _dump_buf_data_order
= pagecnt
;
4897 memset(_dump_buf_data
, 0,
4898 ((1 << PAGE_SHIFT
) << pagecnt
));
4903 if (!_dump_buf_data_order
)
4904 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4905 "9044 BLKGRD: ERROR unable to allocate "
4906 "memory for hexdump\n");
4908 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4909 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
4910 "\n", _dump_buf_data
);
4911 if (!_dump_buf_dif
) {
4914 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
4915 if (_dump_buf_dif
) {
4916 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4917 "9046 BLKGRD: allocated %d pages for "
4918 "_dump_buf_dif at 0x%p\n",
4919 (1 << pagecnt
), _dump_buf_dif
);
4920 _dump_buf_dif_order
= pagecnt
;
4921 memset(_dump_buf_dif
, 0,
4922 ((1 << PAGE_SHIFT
) << pagecnt
));
4927 if (!_dump_buf_dif_order
)
4928 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4929 "9047 BLKGRD: ERROR unable to allocate "
4930 "memory for hexdump\n");
4932 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4933 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
4938 * lpfc_post_init_setup - Perform necessary device post initialization setup.
4939 * @phba: pointer to lpfc hba data structure.
4941 * This routine is invoked to perform all the necessary post initialization
4942 * setup for the device.
4945 lpfc_post_init_setup(struct lpfc_hba
*phba
)
4947 struct Scsi_Host
*shost
;
4948 struct lpfc_adapter_event_header adapter_event
;
4950 /* Get the default values for Model Name and Description */
4951 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
4954 * hba setup may have changed the hba_queue_depth so we need to
4955 * adjust the value of can_queue.
4957 shost
= pci_get_drvdata(phba
->pcidev
);
4958 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
4959 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
4960 lpfc_setup_bg(phba
, shost
);
4962 lpfc_host_attrib_init(shost
);
4964 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
4965 spin_lock_irq(shost
->host_lock
);
4966 lpfc_poll_start_timer(phba
);
4967 spin_unlock_irq(shost
->host_lock
);
4970 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4971 "0428 Perform SCSI scan\n");
4972 /* Send board arrival event to upper layer */
4973 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
4974 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
4975 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4976 sizeof(adapter_event
),
4977 (char *) &adapter_event
,
4983 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
4984 * @phba: pointer to lpfc hba data structure.
4986 * This routine is invoked to set up the PCI device memory space for device
4987 * with SLI-3 interface spec.
4991 * other values - error
4994 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
4996 struct pci_dev
*pdev
;
4997 unsigned long bar0map_len
, bar2map_len
;
5000 int error
= -ENODEV
;
5002 /* Obtain PCI device reference */
5006 pdev
= phba
->pcidev
;
5008 /* Set the device DMA mask size */
5009 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
5010 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
5011 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
5012 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
5017 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5018 * required by each mapping.
5020 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
5021 bar0map_len
= pci_resource_len(pdev
, 0);
5023 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
5024 bar2map_len
= pci_resource_len(pdev
, 2);
5026 /* Map HBA SLIM to a kernel virtual address. */
5027 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
5028 if (!phba
->slim_memmap_p
) {
5029 dev_printk(KERN_ERR
, &pdev
->dev
,
5030 "ioremap failed for SLIM memory.\n");
5034 /* Map HBA Control Registers to a kernel virtual address. */
5035 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
5036 if (!phba
->ctrl_regs_memmap_p
) {
5037 dev_printk(KERN_ERR
, &pdev
->dev
,
5038 "ioremap failed for HBA control registers.\n");
5039 goto out_iounmap_slim
;
5042 /* Allocate memory for SLI-2 structures */
5043 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
5047 if (!phba
->slim2p
.virt
)
5050 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
5051 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
5052 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
5053 phba
->IOCBs
= (phba
->slim2p
.virt
+
5054 offsetof(struct lpfc_sli2_slim
, IOCBs
));
5056 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
5057 lpfc_sli_hbq_size(),
5058 &phba
->hbqslimp
.phys
,
5060 if (!phba
->hbqslimp
.virt
)
5063 hbq_count
= lpfc_sli_hbq_count();
5064 ptr
= phba
->hbqslimp
.virt
;
5065 for (i
= 0; i
< hbq_count
; ++i
) {
5066 phba
->hbqs
[i
].hbq_virt
= ptr
;
5067 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
5068 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
5069 sizeof(struct lpfc_hbq_entry
));
5071 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
5072 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
5074 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
5076 INIT_LIST_HEAD(&phba
->rb_pend_list
);
5078 phba
->MBslimaddr
= phba
->slim_memmap_p
;
5079 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
5080 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
5081 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
5082 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
5087 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5088 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5090 iounmap(phba
->ctrl_regs_memmap_p
);
5092 iounmap(phba
->slim_memmap_p
);
5098 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5099 * @phba: pointer to lpfc hba data structure.
5101 * This routine is invoked to unset the PCI device memory space for device
5102 * with SLI-3 interface spec.
5105 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
5107 struct pci_dev
*pdev
;
5109 /* Obtain PCI device reference */
5113 pdev
= phba
->pcidev
;
5115 /* Free coherent DMA memory allocated */
5116 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
5117 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
5118 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5119 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5121 /* I/O memory unmap */
5122 iounmap(phba
->ctrl_regs_memmap_p
);
5123 iounmap(phba
->slim_memmap_p
);
5129 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5130 * @phba: pointer to lpfc hba data structure.
5132 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5133 * done and check status.
5135 * Return 0 if successful, otherwise -ENODEV.
5138 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
5140 struct lpfc_register sta_reg
, uerrlo_reg
, uerrhi_reg
;
5141 int i
, port_error
= -ENODEV
;
5143 if (!phba
->sli4_hba
.STAregaddr
)
5146 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5147 for (i
= 0; i
< 3000; i
++) {
5148 sta_reg
.word0
= readl(phba
->sli4_hba
.STAregaddr
);
5149 /* Encounter fatal POST error, break out */
5150 if (bf_get(lpfc_hst_state_perr
, &sta_reg
)) {
5151 port_error
= -ENODEV
;
5154 if (LPFC_POST_STAGE_ARMFW_READY
==
5155 bf_get(lpfc_hst_state_port_status
, &sta_reg
)) {
5163 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5164 "1408 Failure HBA POST Status: sta_reg=0x%x, "
5165 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
5166 "dl=x%x, pstatus=x%x\n", sta_reg
.word0
,
5167 bf_get(lpfc_hst_state_perr
, &sta_reg
),
5168 bf_get(lpfc_hst_state_sfi
, &sta_reg
),
5169 bf_get(lpfc_hst_state_nip
, &sta_reg
),
5170 bf_get(lpfc_hst_state_ipc
, &sta_reg
),
5171 bf_get(lpfc_hst_state_xrom
, &sta_reg
),
5172 bf_get(lpfc_hst_state_dl
, &sta_reg
),
5173 bf_get(lpfc_hst_state_port_status
, &sta_reg
));
5175 /* Log device information */
5176 phba
->sli4_hba
.sli_intf
.word0
= readl(phba
->sli4_hba
.SLIINTFregaddr
);
5177 if (bf_get(lpfc_sli_intf_valid
,
5178 &phba
->sli4_hba
.sli_intf
) == LPFC_SLI_INTF_VALID
) {
5179 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5180 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
5181 "FeatureL1=0x%x, FeatureL2=0x%x\n",
5182 bf_get(lpfc_sli_intf_sli_family
,
5183 &phba
->sli4_hba
.sli_intf
),
5184 bf_get(lpfc_sli_intf_slirev
,
5185 &phba
->sli4_hba
.sli_intf
),
5186 bf_get(lpfc_sli_intf_featurelevel1
,
5187 &phba
->sli4_hba
.sli_intf
),
5188 bf_get(lpfc_sli_intf_featurelevel2
,
5189 &phba
->sli4_hba
.sli_intf
));
5191 phba
->sli4_hba
.ue_mask_lo
= readl(phba
->sli4_hba
.UEMASKLOregaddr
);
5192 phba
->sli4_hba
.ue_mask_hi
= readl(phba
->sli4_hba
.UEMASKHIregaddr
);
5193 /* With uncoverable error, log the error message and return error */
5194 uerrlo_reg
.word0
= readl(phba
->sli4_hba
.UERRLOregaddr
);
5195 uerrhi_reg
.word0
= readl(phba
->sli4_hba
.UERRHIregaddr
);
5196 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
5197 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
5198 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5199 "1422 HBA Unrecoverable error: "
5200 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
5201 "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
5202 uerrlo_reg
.word0
, uerrhi_reg
.word0
,
5203 phba
->sli4_hba
.ue_mask_lo
,
5204 phba
->sli4_hba
.ue_mask_hi
);
5212 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
5213 * @phba: pointer to lpfc hba data structure.
5215 * This routine is invoked to set up SLI4 BAR0 PCI config space register
5219 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
)
5221 phba
->sli4_hba
.UERRLOregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
5222 LPFC_UERR_STATUS_LO
;
5223 phba
->sli4_hba
.UERRHIregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
5224 LPFC_UERR_STATUS_HI
;
5225 phba
->sli4_hba
.UEMASKLOregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
5227 phba
->sli4_hba
.UEMASKHIregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
5229 phba
->sli4_hba
.SLIINTFregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
5234 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
5235 * @phba: pointer to lpfc hba data structure.
5237 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
5241 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
5244 phba
->sli4_hba
.STAregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5246 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5248 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5250 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5256 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
5257 * @phba: pointer to lpfc hba data structure.
5258 * @vf: virtual function number
5260 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
5261 * based on the given viftual function number, @vf.
5263 * Return 0 if successful, otherwise -ENODEV.
5266 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
5268 if (vf
> LPFC_VIR_FUNC_MAX
)
5271 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5272 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_RQ_DOORBELL
);
5273 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5274 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_WQ_DOORBELL
);
5275 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5276 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
5277 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5278 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
5279 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5280 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
5285 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
5286 * @phba: pointer to lpfc hba data structure.
5288 * This routine is invoked to create the bootstrap mailbox
5289 * region consistent with the SLI-4 interface spec. This
5290 * routine allocates all memory necessary to communicate
5291 * mailbox commands to the port and sets up all alignment
5292 * needs. No locks are expected to be held when calling
5297 * ENOMEM - could not allocated memory.
5300 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
5303 struct lpfc_dmabuf
*dmabuf
;
5304 struct dma_address
*dma_address
;
5308 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5313 * The bootstrap mailbox region is comprised of 2 parts
5314 * plus an alignment restriction of 16 bytes.
5316 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
5317 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5321 if (!dmabuf
->virt
) {
5325 memset(dmabuf
->virt
, 0, bmbx_size
);
5328 * Initialize the bootstrap mailbox pointers now so that the register
5329 * operations are simple later. The mailbox dma address is required
5330 * to be 16-byte aligned. Also align the virtual memory as each
5331 * maibox is copied into the bmbx mailbox region before issuing the
5332 * command to the port.
5334 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
5335 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
5337 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
5338 LPFC_ALIGN_16_BYTE
);
5339 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
5340 LPFC_ALIGN_16_BYTE
);
5343 * Set the high and low physical addresses now. The SLI4 alignment
5344 * requirement is 16 bytes and the mailbox is posted to the port
5345 * as two 30-bit addresses. The other data is a bit marking whether
5346 * the 30-bit address is the high or low address.
5347 * Upcast bmbx aphys to 64bits so shift instruction compiles
5348 * clean on 32 bit machines.
5350 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5351 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
5352 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
5353 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
5354 LPFC_BMBX_BIT1_ADDR_HI
);
5356 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
5357 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
5358 LPFC_BMBX_BIT1_ADDR_LO
);
5363 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
5364 * @phba: pointer to lpfc hba data structure.
5366 * This routine is invoked to teardown the bootstrap mailbox
5367 * region and release all host resources. This routine requires
5368 * the caller to ensure all mailbox commands recovered, no
5369 * additional mailbox comands are sent, and interrupts are disabled
5370 * before calling this routine.
5374 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
5376 dma_free_coherent(&phba
->pcidev
->dev
,
5377 phba
->sli4_hba
.bmbx
.bmbx_size
,
5378 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
5379 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
5381 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
5382 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
5386 * lpfc_sli4_read_config - Get the config parameters.
5387 * @phba: pointer to lpfc hba data structure.
5389 * This routine is invoked to read the configuration parameters from the HBA.
5390 * The configuration parameters are used to set the base and maximum values
5391 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
5392 * allocation for the port.
5396 * ENOMEM - No availble memory
5397 * EIO - The mailbox failed to complete successfully.
5400 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
5403 struct lpfc_mbx_read_config
*rd_config
;
5406 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5408 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5409 "2011 Unable to allocate memory for issuing "
5410 "SLI_CONFIG_SPECIAL mailbox command\n");
5414 lpfc_read_config(phba
, pmb
);
5416 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
5417 if (rc
!= MBX_SUCCESS
) {
5418 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5419 "2012 Mailbox failed , mbxCmd x%x "
5420 "READ_CONFIG, mbxStatus x%x\n",
5421 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
5422 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
5425 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
5426 phba
->sli4_hba
.max_cfg_param
.max_xri
=
5427 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
5428 phba
->sli4_hba
.max_cfg_param
.xri_base
=
5429 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
5430 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
5431 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
5432 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
5433 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
5434 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
5435 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
5436 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
5437 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
5438 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
5439 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
5440 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
5441 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
5442 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
5443 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
5444 phba
->sli4_hba
.max_cfg_param
.fcfi_base
=
5445 bf_get(lpfc_mbx_rd_conf_fcfi_base
, rd_config
);
5446 phba
->sli4_hba
.max_cfg_param
.max_eq
=
5447 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
5448 phba
->sli4_hba
.max_cfg_param
.max_rq
=
5449 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
5450 phba
->sli4_hba
.max_cfg_param
.max_wq
=
5451 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
5452 phba
->sli4_hba
.max_cfg_param
.max_cq
=
5453 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
5454 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
5455 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5456 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5457 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5458 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5459 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
5460 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
5461 phba
->max_vports
= phba
->max_vpi
;
5462 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5463 "2003 cfg params XRI(B:%d M:%d), "
5467 "FCFI(B:%d M:%d)\n",
5468 phba
->sli4_hba
.max_cfg_param
.xri_base
,
5469 phba
->sli4_hba
.max_cfg_param
.max_xri
,
5470 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
5471 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
5472 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
5473 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
5474 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
5475 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
5476 phba
->sli4_hba
.max_cfg_param
.fcfi_base
,
5477 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
5479 mempool_free(pmb
, phba
->mbox_mem_pool
);
5481 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
5482 if (phba
->cfg_hba_queue_depth
> (phba
->sli4_hba
.max_cfg_param
.max_xri
))
5483 phba
->cfg_hba_queue_depth
=
5484 phba
->sli4_hba
.max_cfg_param
.max_xri
;
5489 * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
5490 * @phba: pointer to lpfc hba data structure.
5492 * This routine is invoked to setup the host-side endian order to the
5493 * HBA consistent with the SLI-4 interface spec.
5497 * ENOMEM - No availble memory
5498 * EIO - The mailbox failed to complete successfully.
5501 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
5503 LPFC_MBOXQ_t
*mboxq
;
5505 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
5506 HOST_ENDIAN_HIGH_WORD1
};
5508 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5510 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5511 "0492 Unable to allocate memory for issuing "
5512 "SLI_CONFIG_SPECIAL mailbox command\n");
5517 * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
5518 * words to contain special data values and no other data.
5520 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
5521 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
5522 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5523 if (rc
!= MBX_SUCCESS
) {
5524 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5525 "0493 SLI_CONFIG_SPECIAL mailbox failed with "
5531 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5536 * lpfc_sli4_queue_create - Create all the SLI4 queues
5537 * @phba: pointer to lpfc hba data structure.
5539 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
5540 * operation. For each SLI4 queue type, the parameters such as queue entry
5541 * count (queue depth) shall be taken from the module parameter. For now,
5542 * we just use some constant number as place holder.
5546 * ENOMEM - No availble memory
5547 * EIO - The mailbox failed to complete successfully.
5550 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
5552 struct lpfc_queue
*qdesc
;
5553 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
5554 int cfg_fcp_wq_count
;
5555 int cfg_fcp_eq_count
;
5558 * Sanity check for confiugred queue parameters against the run-time
5562 /* Sanity check on FCP fast-path WQ parameters */
5563 cfg_fcp_wq_count
= phba
->cfg_fcp_wq_count
;
5564 if (cfg_fcp_wq_count
>
5565 (phba
->sli4_hba
.max_cfg_param
.max_wq
- LPFC_SP_WQN_DEF
)) {
5566 cfg_fcp_wq_count
= phba
->sli4_hba
.max_cfg_param
.max_wq
-
5568 if (cfg_fcp_wq_count
< LPFC_FP_WQN_MIN
) {
5569 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5570 "2581 Not enough WQs (%d) from "
5571 "the pci function for supporting "
5573 phba
->sli4_hba
.max_cfg_param
.max_wq
,
5574 phba
->cfg_fcp_wq_count
);
5577 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5578 "2582 Not enough WQs (%d) from the pci "
5579 "function for supporting the requested "
5580 "FCP WQs (%d), the actual FCP WQs can "
5581 "be supported: %d\n",
5582 phba
->sli4_hba
.max_cfg_param
.max_wq
,
5583 phba
->cfg_fcp_wq_count
, cfg_fcp_wq_count
);
5585 /* The actual number of FCP work queues adopted */
5586 phba
->cfg_fcp_wq_count
= cfg_fcp_wq_count
;
5588 /* Sanity check on FCP fast-path EQ parameters */
5589 cfg_fcp_eq_count
= phba
->cfg_fcp_eq_count
;
5590 if (cfg_fcp_eq_count
>
5591 (phba
->sli4_hba
.max_cfg_param
.max_eq
- LPFC_SP_EQN_DEF
)) {
5592 cfg_fcp_eq_count
= phba
->sli4_hba
.max_cfg_param
.max_eq
-
5594 if (cfg_fcp_eq_count
< LPFC_FP_EQN_MIN
) {
5595 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5596 "2574 Not enough EQs (%d) from the "
5597 "pci function for supporting FCP "
5599 phba
->sli4_hba
.max_cfg_param
.max_eq
,
5600 phba
->cfg_fcp_eq_count
);
5603 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5604 "2575 Not enough EQs (%d) from the pci "
5605 "function for supporting the requested "
5606 "FCP EQs (%d), the actual FCP EQs can "
5607 "be supported: %d\n",
5608 phba
->sli4_hba
.max_cfg_param
.max_eq
,
5609 phba
->cfg_fcp_eq_count
, cfg_fcp_eq_count
);
5611 /* It does not make sense to have more EQs than WQs */
5612 if (cfg_fcp_eq_count
> phba
->cfg_fcp_wq_count
) {
5613 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5614 "2593 The FCP EQ count(%d) cannot be greater "
5615 "than the FCP WQ count(%d), limiting the "
5616 "FCP EQ count to %d\n", cfg_fcp_eq_count
,
5617 phba
->cfg_fcp_wq_count
,
5618 phba
->cfg_fcp_wq_count
);
5619 cfg_fcp_eq_count
= phba
->cfg_fcp_wq_count
;
5621 /* The actual number of FCP event queues adopted */
5622 phba
->cfg_fcp_eq_count
= cfg_fcp_eq_count
;
5623 /* The overall number of event queues used */
5624 phba
->sli4_hba
.cfg_eqn
= phba
->cfg_fcp_eq_count
+ LPFC_SP_EQN_DEF
;
5627 * Create Event Queues (EQs)
5630 /* Get EQ depth from module parameter, fake the default for now */
5631 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
5632 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
5634 /* Create slow path event queue */
5635 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
5636 phba
->sli4_hba
.eq_ecount
);
5638 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5639 "0496 Failed allocate slow-path EQ\n");
5642 phba
->sli4_hba
.sp_eq
= qdesc
;
5644 /* Create fast-path FCP Event Queue(s) */
5645 phba
->sli4_hba
.fp_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
5646 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
5647 if (!phba
->sli4_hba
.fp_eq
) {
5648 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5649 "2576 Failed allocate memory for fast-path "
5650 "EQ record array\n");
5651 goto out_free_sp_eq
;
5653 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
5654 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
5655 phba
->sli4_hba
.eq_ecount
);
5657 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5658 "0497 Failed allocate fast-path EQ\n");
5659 goto out_free_fp_eq
;
5661 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = qdesc
;
5665 * Create Complete Queues (CQs)
5668 /* Get CQ depth from module parameter, fake the default for now */
5669 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
5670 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
5672 /* Create slow-path Mailbox Command Complete Queue */
5673 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5674 phba
->sli4_hba
.cq_ecount
);
5676 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5677 "0500 Failed allocate slow-path mailbox CQ\n");
5678 goto out_free_fp_eq
;
5680 phba
->sli4_hba
.mbx_cq
= qdesc
;
5682 /* Create slow-path ELS Complete Queue */
5683 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5684 phba
->sli4_hba
.cq_ecount
);
5686 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5687 "0501 Failed allocate slow-path ELS CQ\n");
5688 goto out_free_mbx_cq
;
5690 phba
->sli4_hba
.els_cq
= qdesc
;
5693 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
5694 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
5695 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
5696 if (!phba
->sli4_hba
.fcp_cq
) {
5697 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5698 "2577 Failed allocate memory for fast-path "
5699 "CQ record array\n");
5700 goto out_free_els_cq
;
5702 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_eq_count
; fcp_cqidx
++) {
5703 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5704 phba
->sli4_hba
.cq_ecount
);
5706 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5707 "0499 Failed allocate fast-path FCP "
5708 "CQ (%d)\n", fcp_cqidx
);
5709 goto out_free_fcp_cq
;
5711 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = qdesc
;
5714 /* Create Mailbox Command Queue */
5715 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
5716 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
5718 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
5719 phba
->sli4_hba
.mq_ecount
);
5721 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5722 "0505 Failed allocate slow-path MQ\n");
5723 goto out_free_fcp_cq
;
5725 phba
->sli4_hba
.mbx_wq
= qdesc
;
5728 * Create all the Work Queues (WQs)
5730 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
5731 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
5733 /* Create slow-path ELS Work Queue */
5734 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
5735 phba
->sli4_hba
.wq_ecount
);
5737 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5738 "0504 Failed allocate slow-path ELS WQ\n");
5739 goto out_free_mbx_wq
;
5741 phba
->sli4_hba
.els_wq
= qdesc
;
5743 /* Create fast-path FCP Work Queue(s) */
5744 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
5745 phba
->cfg_fcp_wq_count
), GFP_KERNEL
);
5746 if (!phba
->sli4_hba
.fcp_wq
) {
5747 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5748 "2578 Failed allocate memory for fast-path "
5749 "WQ record array\n");
5750 goto out_free_els_wq
;
5752 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
5753 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
5754 phba
->sli4_hba
.wq_ecount
);
5756 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5757 "0503 Failed allocate fast-path FCP "
5758 "WQ (%d)\n", fcp_wqidx
);
5759 goto out_free_fcp_wq
;
5761 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = qdesc
;
5765 * Create Receive Queue (RQ)
5767 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
5768 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
5770 /* Create Receive Queue for header */
5771 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
5772 phba
->sli4_hba
.rq_ecount
);
5774 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5775 "0506 Failed allocate receive HRQ\n");
5776 goto out_free_fcp_wq
;
5778 phba
->sli4_hba
.hdr_rq
= qdesc
;
5780 /* Create Receive Queue for data */
5781 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
5782 phba
->sli4_hba
.rq_ecount
);
5784 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5785 "0507 Failed allocate receive DRQ\n");
5786 goto out_free_hdr_rq
;
5788 phba
->sli4_hba
.dat_rq
= qdesc
;
5793 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
5794 phba
->sli4_hba
.hdr_rq
= NULL
;
5796 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--) {
5797 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
5798 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = NULL
;
5800 kfree(phba
->sli4_hba
.fcp_wq
);
5802 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
5803 phba
->sli4_hba
.els_wq
= NULL
;
5805 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
5806 phba
->sli4_hba
.mbx_wq
= NULL
;
5808 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--) {
5809 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
5810 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = NULL
;
5812 kfree(phba
->sli4_hba
.fcp_cq
);
5814 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
5815 phba
->sli4_hba
.els_cq
= NULL
;
5817 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
5818 phba
->sli4_hba
.mbx_cq
= NULL
;
5820 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--) {
5821 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
5822 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = NULL
;
5824 kfree(phba
->sli4_hba
.fp_eq
);
5826 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
5827 phba
->sli4_hba
.sp_eq
= NULL
;
5833 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
5834 * @phba: pointer to lpfc hba data structure.
5836 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
5841 * ENOMEM - No availble memory
5842 * EIO - The mailbox failed to complete successfully.
5845 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
5849 /* Release mailbox command work queue */
5850 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
5851 phba
->sli4_hba
.mbx_wq
= NULL
;
5853 /* Release ELS work queue */
5854 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
5855 phba
->sli4_hba
.els_wq
= NULL
;
5857 /* Release FCP work queue */
5858 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
5859 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
5860 kfree(phba
->sli4_hba
.fcp_wq
);
5861 phba
->sli4_hba
.fcp_wq
= NULL
;
5863 /* Release unsolicited receive queue */
5864 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
5865 phba
->sli4_hba
.hdr_rq
= NULL
;
5866 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
5867 phba
->sli4_hba
.dat_rq
= NULL
;
5869 /* Release ELS complete queue */
5870 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
5871 phba
->sli4_hba
.els_cq
= NULL
;
5873 /* Release mailbox command complete queue */
5874 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
5875 phba
->sli4_hba
.mbx_cq
= NULL
;
5877 /* Release FCP response complete queue */
5878 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5879 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
5880 kfree(phba
->sli4_hba
.fcp_cq
);
5881 phba
->sli4_hba
.fcp_cq
= NULL
;
5883 /* Release fast-path event queue */
5884 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5885 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
5886 kfree(phba
->sli4_hba
.fp_eq
);
5887 phba
->sli4_hba
.fp_eq
= NULL
;
5889 /* Release slow-path event queue */
5890 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
5891 phba
->sli4_hba
.sp_eq
= NULL
;
5897 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
5898 * @phba: pointer to lpfc hba data structure.
5900 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
5905 * ENOMEM - No availble memory
5906 * EIO - The mailbox failed to complete successfully.
5909 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
5912 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
5913 int fcp_cq_index
= 0;
5916 * Set up Event Queues (EQs)
5919 /* Set up slow-path event queue */
5920 if (!phba
->sli4_hba
.sp_eq
) {
5921 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5922 "0520 Slow-path EQ not allocated\n");
5925 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.sp_eq
,
5928 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5929 "0521 Failed setup of slow-path EQ: "
5933 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5934 "2583 Slow-path EQ setup: queue-id=%d\n",
5935 phba
->sli4_hba
.sp_eq
->queue_id
);
5937 /* Set up fast-path event queue */
5938 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
5939 if (!phba
->sli4_hba
.fp_eq
[fcp_eqidx
]) {
5940 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5941 "0522 Fast-path EQ (%d) not "
5942 "allocated\n", fcp_eqidx
);
5943 goto out_destroy_fp_eq
;
5945 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
5946 phba
->cfg_fcp_imax
);
5948 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5949 "0523 Failed setup of fast-path EQ "
5950 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
5951 goto out_destroy_fp_eq
;
5953 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5954 "2584 Fast-path EQ setup: "
5955 "queue[%d]-id=%d\n", fcp_eqidx
,
5956 phba
->sli4_hba
.fp_eq
[fcp_eqidx
]->queue_id
);
5960 * Set up Complete Queues (CQs)
5963 /* Set up slow-path MBOX Complete Queue as the first CQ */
5964 if (!phba
->sli4_hba
.mbx_cq
) {
5965 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5966 "0528 Mailbox CQ not allocated\n");
5967 goto out_destroy_fp_eq
;
5969 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
, phba
->sli4_hba
.sp_eq
,
5970 LPFC_MCQ
, LPFC_MBOX
);
5972 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5973 "0529 Failed setup of slow-path mailbox CQ: "
5975 goto out_destroy_fp_eq
;
5977 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5978 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
5979 phba
->sli4_hba
.mbx_cq
->queue_id
,
5980 phba
->sli4_hba
.sp_eq
->queue_id
);
5982 /* Set up slow-path ELS Complete Queue */
5983 if (!phba
->sli4_hba
.els_cq
) {
5984 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5985 "0530 ELS CQ not allocated\n");
5986 goto out_destroy_mbx_cq
;
5988 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
, phba
->sli4_hba
.sp_eq
,
5989 LPFC_WCQ
, LPFC_ELS
);
5991 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5992 "0531 Failed setup of slow-path ELS CQ: "
5994 goto out_destroy_mbx_cq
;
5996 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5997 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
5998 phba
->sli4_hba
.els_cq
->queue_id
,
5999 phba
->sli4_hba
.sp_eq
->queue_id
);
6001 /* Set up fast-path FCP Response Complete Queue */
6002 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_eq_count
; fcp_cqidx
++) {
6003 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
6004 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6005 "0526 Fast-path FCP CQ (%d) not "
6006 "allocated\n", fcp_cqidx
);
6007 goto out_destroy_fcp_cq
;
6009 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
6010 phba
->sli4_hba
.fp_eq
[fcp_cqidx
],
6011 LPFC_WCQ
, LPFC_FCP
);
6013 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6014 "0527 Failed setup of fast-path FCP "
6015 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
6016 goto out_destroy_fcp_cq
;
6018 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6019 "2588 FCP CQ setup: cq[%d]-id=%d, "
6020 "parent eq[%d]-id=%d\n",
6022 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
6024 phba
->sli4_hba
.fp_eq
[fcp_cqidx
]->queue_id
);
6028 * Set up all the Work Queues (WQs)
6031 /* Set up Mailbox Command Queue */
6032 if (!phba
->sli4_hba
.mbx_wq
) {
6033 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6034 "0538 Slow-path MQ not allocated\n");
6035 goto out_destroy_fcp_cq
;
6037 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
6038 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
6040 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6041 "0539 Failed setup of slow-path MQ: "
6043 goto out_destroy_fcp_cq
;
6045 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6046 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
6047 phba
->sli4_hba
.mbx_wq
->queue_id
,
6048 phba
->sli4_hba
.mbx_cq
->queue_id
);
6050 /* Set up slow-path ELS Work Queue */
6051 if (!phba
->sli4_hba
.els_wq
) {
6052 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6053 "0536 Slow-path ELS WQ not allocated\n");
6054 goto out_destroy_mbx_wq
;
6056 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
6057 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
6059 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6060 "0537 Failed setup of slow-path ELS WQ: "
6062 goto out_destroy_mbx_wq
;
6064 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6065 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
6066 phba
->sli4_hba
.els_wq
->queue_id
,
6067 phba
->sli4_hba
.els_cq
->queue_id
);
6069 /* Set up fast-path FCP Work Queue */
6070 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
6071 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
6072 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6073 "0534 Fast-path FCP WQ (%d) not "
6074 "allocated\n", fcp_wqidx
);
6075 goto out_destroy_fcp_wq
;
6077 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
6078 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
],
6081 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6082 "0535 Failed setup of fast-path FCP "
6083 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
6084 goto out_destroy_fcp_wq
;
6086 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6087 "2591 FCP WQ setup: wq[%d]-id=%d, "
6088 "parent cq[%d]-id=%d\n",
6090 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
6092 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
]->queue_id
);
6093 /* Round robin FCP Work Queue's Completion Queue assignment */
6094 fcp_cq_index
= ((fcp_cq_index
+ 1) % phba
->cfg_fcp_eq_count
);
6098 * Create Receive Queue (RQ)
6100 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
6101 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6102 "0540 Receive Queue not allocated\n");
6103 goto out_destroy_fcp_wq
;
6105 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
6106 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
6108 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6109 "0541 Failed setup of Receive Queue: "
6111 goto out_destroy_fcp_wq
;
6113 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6114 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
6115 "parent cq-id=%d\n",
6116 phba
->sli4_hba
.hdr_rq
->queue_id
,
6117 phba
->sli4_hba
.dat_rq
->queue_id
,
6118 phba
->sli4_hba
.els_cq
->queue_id
);
6122 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
6123 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
6124 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
6126 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
6128 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
6129 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
6130 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
6132 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
6134 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
6135 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
6136 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
6142 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
6143 * @phba: pointer to lpfc hba data structure.
6145 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
6150 * ENOMEM - No availble memory
6151 * EIO - The mailbox failed to complete successfully.
6154 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
6158 /* Unset mailbox command work queue */
6159 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
6160 /* Unset ELS work queue */
6161 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
6162 /* Unset unsolicited receive queue */
6163 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
6164 /* Unset FCP work queue */
6165 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
6166 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
6167 /* Unset mailbox command complete queue */
6168 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
6169 /* Unset ELS complete queue */
6170 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
6171 /* Unset FCP response complete queue */
6172 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
6173 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
6174 /* Unset fast-path event queue */
6175 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
6176 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
6177 /* Unset slow-path event queue */
6178 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
6182 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
6183 * @phba: pointer to lpfc hba data structure.
6185 * This routine is invoked to allocate and set up a pool of completion queue
6186 * events. The body of the completion queue event is a completion queue entry
6187 * CQE. For now, this pool is used for the interrupt service routine to queue
6188 * the following HBA completion queue events for the worker thread to process:
6189 * - Mailbox asynchronous events
6190 * - Receive queue completion unsolicited events
6191 * Later, this can be used for all the slow-path events.
6195 * -ENOMEM - No availble memory
6198 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
6200 struct lpfc_cq_event
*cq_event
;
6203 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
6204 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
6206 goto out_pool_create_fail
;
6207 list_add_tail(&cq_event
->list
,
6208 &phba
->sli4_hba
.sp_cqe_event_pool
);
6212 out_pool_create_fail
:
6213 lpfc_sli4_cq_event_pool_destroy(phba
);
6218 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
6219 * @phba: pointer to lpfc hba data structure.
6221 * This routine is invoked to free the pool of completion queue events at
6222 * driver unload time. Note that, it is the responsibility of the driver
6223 * cleanup routine to free all the outstanding completion-queue events
6224 * allocated from this pool back into the pool before invoking this routine
6225 * to destroy the pool.
6228 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
6230 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
6232 list_for_each_entry_safe(cq_event
, next_cq_event
,
6233 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
6234 list_del(&cq_event
->list
);
6240 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6241 * @phba: pointer to lpfc hba data structure.
6243 * This routine is the lock free version of the API invoked to allocate a
6244 * completion-queue event from the free pool.
6246 * Return: Pointer to the newly allocated completion-queue event if successful
6249 struct lpfc_cq_event
*
6250 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
6252 struct lpfc_cq_event
*cq_event
= NULL
;
6254 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
6255 struct lpfc_cq_event
, list
);
6260 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6261 * @phba: pointer to lpfc hba data structure.
6263 * This routine is the lock version of the API invoked to allocate a
6264 * completion-queue event from the free pool.
6266 * Return: Pointer to the newly allocated completion-queue event if successful
6269 struct lpfc_cq_event
*
6270 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
6272 struct lpfc_cq_event
*cq_event
;
6273 unsigned long iflags
;
6275 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6276 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
6277 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6282 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6283 * @phba: pointer to lpfc hba data structure.
6284 * @cq_event: pointer to the completion queue event to be freed.
6286 * This routine is the lock free version of the API invoked to release a
6287 * completion-queue event back into the free pool.
6290 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
6291 struct lpfc_cq_event
*cq_event
)
6293 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
6297 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6298 * @phba: pointer to lpfc hba data structure.
6299 * @cq_event: pointer to the completion queue event to be freed.
6301 * This routine is the lock version of the API invoked to release a
6302 * completion-queue event back into the free pool.
6305 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
6306 struct lpfc_cq_event
*cq_event
)
6308 unsigned long iflags
;
6309 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6310 __lpfc_sli4_cq_event_release(phba
, cq_event
);
6311 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6315 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
6316 * @phba: pointer to lpfc hba data structure.
6318 * This routine is to free all the pending completion-queue events to the
6319 * back into the free pool for device reset.
6322 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
6325 struct lpfc_cq_event
*cqe
;
6326 unsigned long iflags
;
6328 /* Retrieve all the pending WCQEs from pending WCQE lists */
6329 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6330 /* Pending FCP XRI abort events */
6331 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
6333 /* Pending ELS XRI abort events */
6334 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
6336 /* Pending asynnc events */
6337 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
6339 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6341 while (!list_empty(&cqelist
)) {
6342 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
6343 lpfc_sli4_cq_event_release(phba
, cqe
);
6348 * lpfc_pci_function_reset - Reset pci function.
6349 * @phba: pointer to lpfc hba data structure.
6351 * This routine is invoked to request a PCI function reset. It will destroys
6352 * all resources assigned to the PCI function which originates this request.
6356 * ENOMEM - No availble memory
6357 * EIO - The mailbox failed to complete successfully.
6360 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
6362 LPFC_MBOXQ_t
*mboxq
;
6364 uint32_t shdr_status
, shdr_add_status
;
6365 union lpfc_sli4_cfg_shdr
*shdr
;
6367 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6370 "0494 Unable to allocate memory for issuing "
6371 "SLI_FUNCTION_RESET mailbox command\n");
6375 /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
6376 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6377 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
6378 LPFC_SLI4_MBX_EMBED
);
6379 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6380 shdr
= (union lpfc_sli4_cfg_shdr
*)
6381 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6382 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6383 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
6384 if (rc
!= MBX_TIMEOUT
)
6385 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6386 if (shdr_status
|| shdr_add_status
|| rc
) {
6387 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6388 "0495 SLI_FUNCTION_RESET mailbox failed with "
6389 "status x%x add_status x%x, mbx status x%x\n",
6390 shdr_status
, shdr_add_status
, rc
);
6397 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
6398 * @phba: pointer to lpfc hba data structure.
6399 * @cnt: number of nop mailbox commands to send.
6401 * This routine is invoked to send a number @cnt of NOP mailbox command and
6402 * wait for each command to complete.
6404 * Return: the number of NOP mailbox command completed.
6407 lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba
*phba
, uint32_t cnt
)
6409 LPFC_MBOXQ_t
*mboxq
;
6410 int length
, cmdsent
;
6413 uint32_t shdr_status
, shdr_add_status
;
6414 union lpfc_sli4_cfg_shdr
*shdr
;
6417 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6418 "2518 Requested to send 0 NOP mailbox cmd\n");
6422 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6424 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6425 "2519 Unable to allocate memory for issuing "
6426 "NOP mailbox command\n");
6430 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
6431 length
= (sizeof(struct lpfc_mbx_nop
) -
6432 sizeof(struct lpfc_sli4_cfg_mhdr
));
6433 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6434 LPFC_MBOX_OPCODE_NOP
, length
, LPFC_SLI4_MBX_EMBED
);
6436 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
6437 for (cmdsent
= 0; cmdsent
< cnt
; cmdsent
++) {
6438 if (!phba
->sli4_hba
.intr_enable
)
6439 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6441 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
6442 if (rc
== MBX_TIMEOUT
)
6444 /* Check return status */
6445 shdr
= (union lpfc_sli4_cfg_shdr
*)
6446 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6447 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6448 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
6450 if (shdr_status
|| shdr_add_status
|| rc
) {
6451 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6452 "2520 NOP mailbox command failed "
6453 "status x%x add_status x%x mbx "
6454 "status x%x\n", shdr_status
,
6455 shdr_add_status
, rc
);
6460 if (rc
!= MBX_TIMEOUT
)
6461 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6467 * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
6468 * @phba: pointer to lpfc hba data structure.
6471 * This routine is invoked to unregister a FCFI from device.
6474 lpfc_sli4_fcfi_unreg(struct lpfc_hba
*phba
, uint16_t fcfi
)
6479 unsigned long flags
;
6481 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6486 lpfc_unreg_fcfi(mbox
, fcfi
);
6488 if (!phba
->sli4_hba
.intr_enable
)
6489 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6491 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
6492 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6494 if (rc
!= MBX_TIMEOUT
)
6495 mempool_free(mbox
, phba
->mbox_mem_pool
);
6496 if (rc
!= MBX_SUCCESS
)
6497 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6498 "2517 Unregister FCFI command failed "
6499 "status %d, mbxStatus x%x\n", rc
,
6500 bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
));
6502 spin_lock_irqsave(&phba
->hbalock
, flags
);
6503 /* Mark the FCFI is no longer registered */
6504 phba
->fcf
.fcf_flag
&=
6505 ~(FCF_AVAILABLE
| FCF_REGISTERED
| FCF_SCAN_DONE
);
6506 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6511 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
6512 * @phba: pointer to lpfc hba data structure.
6514 * This routine is invoked to set up the PCI device memory space for device
6515 * with SLI-4 interface spec.
6519 * other values - error
6522 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
6524 struct pci_dev
*pdev
;
6525 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
6526 int error
= -ENODEV
;
6528 /* Obtain PCI device reference */
6532 pdev
= phba
->pcidev
;
6534 /* Set the device DMA mask size */
6535 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
6536 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
6537 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
6538 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
6543 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
6544 * number of bytes required by each mapping. They are actually
6545 * mapping to the PCI BAR regions 0 or 1, 2, and 4 by the SLI4 device.
6547 if (pci_resource_start(pdev
, 0)) {
6548 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
6549 bar0map_len
= pci_resource_len(pdev
, 0);
6551 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
6552 bar0map_len
= pci_resource_len(pdev
, 1);
6554 phba
->pci_bar1_map
= pci_resource_start(pdev
, 2);
6555 bar1map_len
= pci_resource_len(pdev
, 2);
6557 phba
->pci_bar2_map
= pci_resource_start(pdev
, 4);
6558 bar2map_len
= pci_resource_len(pdev
, 4);
6560 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
6561 phba
->sli4_hba
.conf_regs_memmap_p
=
6562 ioremap(phba
->pci_bar0_map
, bar0map_len
);
6563 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
6564 dev_printk(KERN_ERR
, &pdev
->dev
,
6565 "ioremap failed for SLI4 PCI config registers.\n");
6569 /* Map SLI4 HBA Control Register base to a kernel virtual address. */
6570 phba
->sli4_hba
.ctrl_regs_memmap_p
=
6571 ioremap(phba
->pci_bar1_map
, bar1map_len
);
6572 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
6573 dev_printk(KERN_ERR
, &pdev
->dev
,
6574 "ioremap failed for SLI4 HBA control registers.\n");
6575 goto out_iounmap_conf
;
6578 /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
6579 phba
->sli4_hba
.drbl_regs_memmap_p
=
6580 ioremap(phba
->pci_bar2_map
, bar2map_len
);
6581 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
6582 dev_printk(KERN_ERR
, &pdev
->dev
,
6583 "ioremap failed for SLI4 HBA doorbell registers.\n");
6584 goto out_iounmap_ctrl
;
6587 /* Set up BAR0 PCI config space register memory map */
6588 lpfc_sli4_bar0_register_memmap(phba
);
6590 /* Set up BAR1 register memory map */
6591 lpfc_sli4_bar1_register_memmap(phba
);
6593 /* Set up BAR2 register memory map */
6594 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
6596 goto out_iounmap_all
;
6601 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
6603 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
6605 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
6611 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
6612 * @phba: pointer to lpfc hba data structure.
6614 * This routine is invoked to unset the PCI device memory space for device
6615 * with SLI-4 interface spec.
6618 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
6620 struct pci_dev
*pdev
;
6622 /* Obtain PCI device reference */
6626 pdev
= phba
->pcidev
;
6628 /* Free coherent DMA memory allocated */
6630 /* Unmap I/O memory space */
6631 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
6632 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
6633 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
6639 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
6640 * @phba: pointer to lpfc hba data structure.
6642 * This routine is invoked to enable the MSI-X interrupt vectors to device
6643 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
6644 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
6645 * invoked, enables either all or nothing, depending on the current
6646 * availability of PCI vector resources. The device driver is responsible
6647 * for calling the individual request_irq() to register each MSI-X vector
6648 * with a interrupt handler, which is done in this function. Note that
6649 * later when device is unloading, the driver should always call free_irq()
6650 * on all MSI-X vectors it has done request_irq() on before calling
6651 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
6652 * will be left with MSI-X enabled and leaks its vectors.
6656 * other values - error
6659 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
6664 /* Set up MSI-X multi-message vectors */
6665 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6666 phba
->msix_entries
[i
].entry
= i
;
6668 /* Configure MSI-X capability structure */
6669 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
6670 ARRAY_SIZE(phba
->msix_entries
));
6672 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6673 "0420 PCI enable MSI-X failed (%d)\n", rc
);
6676 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6677 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6678 "0477 MSI-X entry[%d]: vector=x%x "
6680 phba
->msix_entries
[i
].vector
,
6681 phba
->msix_entries
[i
].entry
);
6683 * Assign MSI-X vectors to interrupt handlers
6686 /* vector-0 is associated to slow-path handler */
6687 rc
= request_irq(phba
->msix_entries
[0].vector
,
6688 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
6689 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
6691 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6692 "0421 MSI-X slow-path request_irq failed "
6697 /* vector-1 is associated to fast-path handler */
6698 rc
= request_irq(phba
->msix_entries
[1].vector
,
6699 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
6700 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
6703 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6704 "0429 MSI-X fast-path request_irq failed "
6710 * Configure HBA MSI-X attention conditions to messages
6712 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6716 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6717 "0474 Unable to allocate memory for issuing "
6718 "MBOX_CONFIG_MSI command\n");
6721 rc
= lpfc_config_msi(phba
, pmb
);
6724 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6725 if (rc
!= MBX_SUCCESS
) {
6726 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
6727 "0351 Config MSI mailbox command failed, "
6728 "mbxCmd x%x, mbxStatus x%x\n",
6729 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
6733 /* Free memory allocated for mailbox command */
6734 mempool_free(pmb
, phba
->mbox_mem_pool
);
6738 /* Free memory allocated for mailbox command */
6739 mempool_free(pmb
, phba
->mbox_mem_pool
);
6742 /* free the irq already requested */
6743 free_irq(phba
->msix_entries
[1].vector
, phba
);
6746 /* free the irq already requested */
6747 free_irq(phba
->msix_entries
[0].vector
, phba
);
6750 /* Unconfigure MSI-X capability structure */
6751 pci_disable_msix(phba
->pcidev
);
6756 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
6757 * @phba: pointer to lpfc hba data structure.
6759 * This routine is invoked to release the MSI-X vectors and then disable the
6760 * MSI-X interrupt mode to device with SLI-3 interface spec.
6763 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
6767 /* Free up MSI-X multi-message vectors */
6768 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6769 free_irq(phba
->msix_entries
[i
].vector
, phba
);
6771 pci_disable_msix(phba
->pcidev
);
6777 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
6778 * @phba: pointer to lpfc hba data structure.
6780 * This routine is invoked to enable the MSI interrupt mode to device with
6781 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
6782 * enable the MSI vector. The device driver is responsible for calling the
6783 * request_irq() to register MSI vector with a interrupt the handler, which
6784 * is done in this function.
6788 * other values - error
6791 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
6795 rc
= pci_enable_msi(phba
->pcidev
);
6797 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6798 "0462 PCI enable MSI mode success.\n");
6800 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6801 "0471 PCI enable MSI mode failed (%d)\n", rc
);
6805 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
6806 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6808 pci_disable_msi(phba
->pcidev
);
6809 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6810 "0478 MSI request_irq failed (%d)\n", rc
);
6816 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
6817 * @phba: pointer to lpfc hba data structure.
6819 * This routine is invoked to disable the MSI interrupt mode to device with
6820 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
6821 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6822 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6826 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
6828 free_irq(phba
->pcidev
->irq
, phba
);
6829 pci_disable_msi(phba
->pcidev
);
6834 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
6835 * @phba: pointer to lpfc hba data structure.
6837 * This routine is invoked to enable device interrupt and associate driver's
6838 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
6839 * spec. Depends on the interrupt mode configured to the driver, the driver
6840 * will try to fallback from the configured interrupt mode to an interrupt
6841 * mode which is supported by the platform, kernel, and device in the order
6843 * MSI-X -> MSI -> IRQ.
6847 * other values - error
6850 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
6852 uint32_t intr_mode
= LPFC_INTR_ERROR
;
6855 if (cfg_mode
== 2) {
6856 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
6857 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
6859 /* Now, try to enable MSI-X interrupt mode */
6860 retval
= lpfc_sli_enable_msix(phba
);
6862 /* Indicate initialization to MSI-X mode */
6863 phba
->intr_type
= MSIX
;
6869 /* Fallback to MSI if MSI-X initialization failed */
6870 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
6871 retval
= lpfc_sli_enable_msi(phba
);
6873 /* Indicate initialization to MSI mode */
6874 phba
->intr_type
= MSI
;
6879 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6880 if (phba
->intr_type
== NONE
) {
6881 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
6882 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6884 /* Indicate initialization to INTx mode */
6885 phba
->intr_type
= INTx
;
6893 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
6894 * @phba: pointer to lpfc hba data structure.
6896 * This routine is invoked to disable device interrupt and disassociate the
6897 * driver's interrupt handler(s) from interrupt vector(s) to device with
6898 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
6899 * release the interrupt vector(s) for the message signaled interrupt.
6902 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
6904 /* Disable the currently initialized interrupt mode */
6905 if (phba
->intr_type
== MSIX
)
6906 lpfc_sli_disable_msix(phba
);
6907 else if (phba
->intr_type
== MSI
)
6908 lpfc_sli_disable_msi(phba
);
6909 else if (phba
->intr_type
== INTx
)
6910 free_irq(phba
->pcidev
->irq
, phba
);
6912 /* Reset interrupt management states */
6913 phba
->intr_type
= NONE
;
6914 phba
->sli
.slistat
.sli_intr
= 0;
6920 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
6921 * @phba: pointer to lpfc hba data structure.
6923 * This routine is invoked to enable the MSI-X interrupt vectors to device
6924 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
6925 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
6926 * enables either all or nothing, depending on the current availability of
6927 * PCI vector resources. The device driver is responsible for calling the
6928 * individual request_irq() to register each MSI-X vector with a interrupt
6929 * handler, which is done in this function. Note that later when device is
6930 * unloading, the driver should always call free_irq() on all MSI-X vectors
6931 * it has done request_irq() on before calling pci_disable_msix(). Failure
6932 * to do so results in a BUG_ON() and a device will be left with MSI-X
6933 * enabled and leaks its vectors.
6937 * other values - error
6940 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
6944 /* Set up MSI-X multi-message vectors */
6945 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
6946 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
6948 /* Configure MSI-X capability structure */
6949 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
6950 phba
->sli4_hba
.cfg_eqn
);
6952 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6953 "0484 PCI enable MSI-X failed (%d)\n", rc
);
6956 /* Log MSI-X vector assignment */
6957 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
6958 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6959 "0489 MSI-X entry[%d]: vector=x%x "
6960 "message=%d\n", index
,
6961 phba
->sli4_hba
.msix_entries
[index
].vector
,
6962 phba
->sli4_hba
.msix_entries
[index
].entry
);
6964 * Assign MSI-X vectors to interrupt handlers
6967 /* The first vector must associated to slow-path handler for MQ */
6968 rc
= request_irq(phba
->sli4_hba
.msix_entries
[0].vector
,
6969 &lpfc_sli4_sp_intr_handler
, IRQF_SHARED
,
6970 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
6972 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6973 "0485 MSI-X slow-path request_irq failed "
6978 /* The rest of the vector(s) are associated to fast-path handler(s) */
6979 for (index
= 1; index
< phba
->sli4_hba
.cfg_eqn
; index
++) {
6980 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].idx
= index
- 1;
6981 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].phba
= phba
;
6982 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
6983 &lpfc_sli4_fp_intr_handler
, IRQF_SHARED
,
6984 LPFC_FP_DRIVER_HANDLER_NAME
,
6985 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
6987 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6988 "0486 MSI-X fast-path (%d) "
6989 "request_irq failed (%d)\n", index
, rc
);
6997 /* free the irq already requested */
6998 for (--index
; index
>= 1; index
--)
6999 free_irq(phba
->sli4_hba
.msix_entries
[index
- 1].vector
,
7000 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
7002 /* free the irq already requested */
7003 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
7006 /* Unconfigure MSI-X capability structure */
7007 pci_disable_msix(phba
->pcidev
);
7012 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
7013 * @phba: pointer to lpfc hba data structure.
7015 * This routine is invoked to release the MSI-X vectors and then disable the
7016 * MSI-X interrupt mode to device with SLI-4 interface spec.
7019 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
7023 /* Free up MSI-X multi-message vectors */
7024 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
7026 for (index
= 1; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
7027 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
7028 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
7030 pci_disable_msix(phba
->pcidev
);
7036 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
7037 * @phba: pointer to lpfc hba data structure.
7039 * This routine is invoked to enable the MSI interrupt mode to device with
7040 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
7041 * to enable the MSI vector. The device driver is responsible for calling
7042 * the request_irq() to register MSI vector with a interrupt the handler,
7043 * which is done in this function.
7047 * other values - error
7050 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
7054 rc
= pci_enable_msi(phba
->pcidev
);
7056 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7057 "0487 PCI enable MSI mode success.\n");
7059 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7060 "0488 PCI enable MSI mode failed (%d)\n", rc
);
7064 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
7065 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7067 pci_disable_msi(phba
->pcidev
);
7068 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7069 "0490 MSI request_irq failed (%d)\n", rc
);
7072 for (index
= 0; index
< phba
->cfg_fcp_eq_count
; index
++) {
7073 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
7074 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
7081 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
7082 * @phba: pointer to lpfc hba data structure.
7084 * This routine is invoked to disable the MSI interrupt mode to device with
7085 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
7086 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7087 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7091 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
7093 free_irq(phba
->pcidev
->irq
, phba
);
7094 pci_disable_msi(phba
->pcidev
);
7099 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
7100 * @phba: pointer to lpfc hba data structure.
7102 * This routine is invoked to enable device interrupt and associate driver's
7103 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
7104 * interface spec. Depends on the interrupt mode configured to the driver,
7105 * the driver will try to fallback from the configured interrupt mode to an
7106 * interrupt mode which is supported by the platform, kernel, and device in
7108 * MSI-X -> MSI -> IRQ.
7112 * other values - error
7115 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
7117 uint32_t intr_mode
= LPFC_INTR_ERROR
;
7120 if (cfg_mode
== 2) {
7121 /* Preparation before conf_msi mbox cmd */
7124 /* Now, try to enable MSI-X interrupt mode */
7125 retval
= lpfc_sli4_enable_msix(phba
);
7127 /* Indicate initialization to MSI-X mode */
7128 phba
->intr_type
= MSIX
;
7134 /* Fallback to MSI if MSI-X initialization failed */
7135 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
7136 retval
= lpfc_sli4_enable_msi(phba
);
7138 /* Indicate initialization to MSI mode */
7139 phba
->intr_type
= MSI
;
7144 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7145 if (phba
->intr_type
== NONE
) {
7146 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
7147 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7149 /* Indicate initialization to INTx mode */
7150 phba
->intr_type
= INTx
;
7152 for (index
= 0; index
< phba
->cfg_fcp_eq_count
;
7154 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
7155 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
7163 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
7164 * @phba: pointer to lpfc hba data structure.
7166 * This routine is invoked to disable device interrupt and disassociate
7167 * the driver's interrupt handler(s) from interrupt vector(s) to device
7168 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
7169 * will release the interrupt vector(s) for the message signaled interrupt.
7172 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
7174 /* Disable the currently initialized interrupt mode */
7175 if (phba
->intr_type
== MSIX
)
7176 lpfc_sli4_disable_msix(phba
);
7177 else if (phba
->intr_type
== MSI
)
7178 lpfc_sli4_disable_msi(phba
);
7179 else if (phba
->intr_type
== INTx
)
7180 free_irq(phba
->pcidev
->irq
, phba
);
7182 /* Reset interrupt management states */
7183 phba
->intr_type
= NONE
;
7184 phba
->sli
.slistat
.sli_intr
= 0;
7190 * lpfc_unset_hba - Unset SLI3 hba device initialization
7191 * @phba: pointer to lpfc hba data structure.
7193 * This routine is invoked to unset the HBA device initialization steps to
7194 * a device with SLI-3 interface spec.
7197 lpfc_unset_hba(struct lpfc_hba
*phba
)
7199 struct lpfc_vport
*vport
= phba
->pport
;
7200 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7202 spin_lock_irq(shost
->host_lock
);
7203 vport
->load_flag
|= FC_UNLOADING
;
7204 spin_unlock_irq(shost
->host_lock
);
7206 lpfc_stop_hba_timers(phba
);
7208 phba
->pport
->work_port_events
= 0;
7210 lpfc_sli_hba_down(phba
);
7212 lpfc_sli_brdrestart(phba
);
7214 lpfc_sli_disable_intr(phba
);
7220 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
7221 * @phba: pointer to lpfc hba data structure.
7223 * This routine is invoked to unset the HBA device initialization steps to
7224 * a device with SLI-4 interface spec.
7227 lpfc_sli4_unset_hba(struct lpfc_hba
*phba
)
7229 struct lpfc_vport
*vport
= phba
->pport
;
7230 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7232 spin_lock_irq(shost
->host_lock
);
7233 vport
->load_flag
|= FC_UNLOADING
;
7234 spin_unlock_irq(shost
->host_lock
);
7236 phba
->pport
->work_port_events
= 0;
7238 lpfc_sli4_hba_down(phba
);
7240 lpfc_sli4_disable_intr(phba
);
7246 * lpfc_sli4_hba_unset - Unset the fcoe hba
7247 * @phba: Pointer to HBA context object.
7249 * This function is called in the SLI4 code path to reset the HBA's FCoE
7250 * function. The caller is not required to hold any lock. This routine
7251 * issues PCI function reset mailbox command to reset the FCoE function.
7252 * At the end of the function, it calls lpfc_hba_down_post function to
7253 * free any pending commands.
7256 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
7259 LPFC_MBOXQ_t
*mboxq
;
7261 lpfc_stop_hba_timers(phba
);
7262 phba
->sli4_hba
.intr_enable
= 0;
7265 * Gracefully wait out the potential current outstanding asynchronous
7269 /* First, block any pending async mailbox command from posted */
7270 spin_lock_irq(&phba
->hbalock
);
7271 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7272 spin_unlock_irq(&phba
->hbalock
);
7273 /* Now, trying to wait it out if we can */
7274 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7276 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
7279 /* Forcefully release the outstanding mailbox command if timed out */
7280 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7281 spin_lock_irq(&phba
->hbalock
);
7282 mboxq
= phba
->sli
.mbox_active
;
7283 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7284 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7285 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7286 phba
->sli
.mbox_active
= NULL
;
7287 spin_unlock_irq(&phba
->hbalock
);
7290 /* Tear down the queues in the HBA */
7291 lpfc_sli4_queue_unset(phba
);
7293 /* Disable PCI subsystem interrupt */
7294 lpfc_sli4_disable_intr(phba
);
7296 /* Stop kthread signal shall trigger work_done one more time */
7297 kthread_stop(phba
->worker_thread
);
7299 /* Stop the SLI4 device port */
7300 phba
->pport
->work_port_events
= 0;
7304 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
7305 * @phba: Pointer to HBA context object.
7306 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
7308 * This function is called in the SLI4 code path to read the port's
7309 * sli4 capabilities.
7311 * This function may be be called from any context that can block-wait
7312 * for the completion. The expectation is that this routine is called
7313 * typically from probe_one or from the online routine.
7316 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7319 struct lpfc_mqe
*mqe
;
7320 struct lpfc_pc_sli4_params
*sli4_params
;
7324 mqe
= &mboxq
->u
.mqe
;
7326 /* Read the port's SLI4 Parameters port capabilities */
7327 lpfc_sli4_params(mboxq
);
7328 if (!phba
->sli4_hba
.intr_enable
)
7329 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7331 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_PORT_CAPABILITIES
);
7332 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
7338 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
7339 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
7340 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
7341 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
7342 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
7343 &mqe
->un
.sli4_params
);
7344 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
7345 &mqe
->un
.sli4_params
);
7346 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
7347 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
7348 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
7349 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
7350 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
7351 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
7352 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
7353 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
7354 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
7355 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
7356 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
7357 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
7358 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
7359 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
7360 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
7361 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
7362 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
7363 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
7364 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
7365 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
7366 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
7371 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
7372 * @pdev: pointer to PCI device
7373 * @pid: pointer to PCI device identifier
7375 * This routine is to be called to attach a device with SLI-3 interface spec
7376 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
7377 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7378 * information of the device and driver to see if the driver state that it can
7379 * support this kind of device. If the match is successful, the driver core
7380 * invokes this routine. If this routine determines it can claim the HBA, it
7381 * does all the initialization that it needs to do to handle the HBA properly.
7384 * 0 - driver can claim the device
7385 * negative value - driver can not claim the device
7387 static int __devinit
7388 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
7390 struct lpfc_hba
*phba
;
7391 struct lpfc_vport
*vport
= NULL
;
7392 struct Scsi_Host
*shost
= NULL
;
7394 uint32_t cfg_mode
, intr_mode
;
7396 /* Allocate memory for HBA structure */
7397 phba
= lpfc_hba_alloc(pdev
);
7401 /* Perform generic PCI device enabling operation */
7402 error
= lpfc_enable_pci_dev(phba
);
7404 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7405 "1401 Failed to enable pci device.\n");
7409 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
7410 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
7412 goto out_disable_pci_dev
;
7414 /* Set up SLI-3 specific device PCI memory space */
7415 error
= lpfc_sli_pci_mem_setup(phba
);
7417 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7418 "1402 Failed to set up pci memory space.\n");
7419 goto out_disable_pci_dev
;
7422 /* Set up phase-1 common device driver resources */
7423 error
= lpfc_setup_driver_resource_phase1(phba
);
7425 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7426 "1403 Failed to set up driver resource.\n");
7427 goto out_unset_pci_mem_s3
;
7430 /* Set up SLI-3 specific device driver resources */
7431 error
= lpfc_sli_driver_resource_setup(phba
);
7433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7434 "1404 Failed to set up driver resource.\n");
7435 goto out_unset_pci_mem_s3
;
7438 /* Initialize and populate the iocb list per host */
7439 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
7441 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7442 "1405 Failed to initialize iocb list.\n");
7443 goto out_unset_driver_resource_s3
;
7446 /* Set up common device driver resources */
7447 error
= lpfc_setup_driver_resource_phase2(phba
);
7449 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7450 "1406 Failed to set up driver resource.\n");
7451 goto out_free_iocb_list
;
7454 /* Create SCSI host to the physical port */
7455 error
= lpfc_create_shost(phba
);
7457 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7458 "1407 Failed to create scsi host.\n");
7459 goto out_unset_driver_resource
;
7462 /* Configure sysfs attributes */
7463 vport
= phba
->pport
;
7464 error
= lpfc_alloc_sysfs_attr(vport
);
7466 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7467 "1476 Failed to allocate sysfs attr\n");
7468 goto out_destroy_shost
;
7471 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
7472 /* Now, trying to enable interrupt and bring up the device */
7473 cfg_mode
= phba
->cfg_use_msi
;
7475 /* Put device to a known state before enabling interrupt */
7476 lpfc_stop_port(phba
);
7477 /* Configure and enable interrupt */
7478 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
7479 if (intr_mode
== LPFC_INTR_ERROR
) {
7480 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7481 "0431 Failed to enable interrupt.\n");
7483 goto out_free_sysfs_attr
;
7485 /* SLI-3 HBA setup */
7486 if (lpfc_sli_hba_setup(phba
)) {
7487 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7488 "1477 Failed to set up hba\n");
7490 goto out_remove_device
;
7493 /* Wait 50ms for the interrupts of previous mailbox commands */
7495 /* Check active interrupts on message signaled interrupts */
7496 if (intr_mode
== 0 ||
7497 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
7498 /* Log the current active interrupt mode */
7499 phba
->intr_mode
= intr_mode
;
7500 lpfc_log_intr_mode(phba
, intr_mode
);
7503 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7504 "0447 Configure interrupt mode (%d) "
7505 "failed active interrupt test.\n",
7507 /* Disable the current interrupt mode */
7508 lpfc_sli_disable_intr(phba
);
7509 /* Try next level of interrupt mode */
7510 cfg_mode
= --intr_mode
;
7514 /* Perform post initialization setup */
7515 lpfc_post_init_setup(phba
);
7517 /* Check if there are static vports to be created. */
7518 lpfc_create_static_vport(phba
);
7523 lpfc_unset_hba(phba
);
7524 out_free_sysfs_attr
:
7525 lpfc_free_sysfs_attr(vport
);
7527 lpfc_destroy_shost(phba
);
7528 out_unset_driver_resource
:
7529 lpfc_unset_driver_resource_phase2(phba
);
7531 lpfc_free_iocb_list(phba
);
7532 out_unset_driver_resource_s3
:
7533 lpfc_sli_driver_resource_unset(phba
);
7534 out_unset_pci_mem_s3
:
7535 lpfc_sli_pci_mem_unset(phba
);
7536 out_disable_pci_dev
:
7537 lpfc_disable_pci_dev(phba
);
7539 scsi_host_put(shost
);
7541 lpfc_hba_free(phba
);
7546 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
7547 * @pdev: pointer to PCI device
7549 * This routine is to be called to disattach a device with SLI-3 interface
7550 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
7551 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7552 * device to be removed from the PCI subsystem properly.
7554 static void __devexit
7555 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
7557 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7558 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
7559 struct lpfc_vport
**vports
;
7560 struct lpfc_hba
*phba
= vport
->phba
;
7562 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
7564 spin_lock_irq(&phba
->hbalock
);
7565 vport
->load_flag
|= FC_UNLOADING
;
7566 spin_unlock_irq(&phba
->hbalock
);
7568 lpfc_free_sysfs_attr(vport
);
7570 /* Release all the vports against this physical port */
7571 vports
= lpfc_create_vport_work_array(phba
);
7573 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
7574 fc_vport_terminate(vports
[i
]->fc_vport
);
7575 lpfc_destroy_vport_work_array(phba
, vports
);
7577 /* Remove FC host and then SCSI host with the physical port */
7578 fc_remove_host(shost
);
7579 scsi_remove_host(shost
);
7580 lpfc_cleanup(vport
);
7583 * Bring down the SLI Layer. This step disable all interrupts,
7584 * clears the rings, discards all mailbox commands, and resets
7588 /* HBA interrupt will be diabled after this call */
7589 lpfc_sli_hba_down(phba
);
7590 /* Stop kthread signal shall trigger work_done one more time */
7591 kthread_stop(phba
->worker_thread
);
7592 /* Final cleanup of txcmplq and reset the HBA */
7593 lpfc_sli_brdrestart(phba
);
7595 lpfc_stop_hba_timers(phba
);
7596 spin_lock_irq(&phba
->hbalock
);
7597 list_del_init(&vport
->listentry
);
7598 spin_unlock_irq(&phba
->hbalock
);
7600 lpfc_debugfs_terminate(vport
);
7602 /* Disable interrupt */
7603 lpfc_sli_disable_intr(phba
);
7605 pci_set_drvdata(pdev
, NULL
);
7606 scsi_host_put(shost
);
7609 * Call scsi_free before mem_free since scsi bufs are released to their
7610 * corresponding pools here.
7612 lpfc_scsi_free(phba
);
7613 lpfc_mem_free_all(phba
);
7615 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
7616 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
7618 /* Free resources associated with SLI2 interface */
7619 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7620 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
7622 /* unmap adapter SLIM and Control Registers */
7623 iounmap(phba
->ctrl_regs_memmap_p
);
7624 iounmap(phba
->slim_memmap_p
);
7626 lpfc_hba_free(phba
);
7628 pci_release_selected_regions(pdev
, bars
);
7629 pci_disable_device(pdev
);
7633 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
7634 * @pdev: pointer to PCI device
7635 * @msg: power management message
7637 * This routine is to be called from the kernel's PCI subsystem to support
7638 * system Power Management (PM) to device with SLI-3 interface spec. When
7639 * PM invokes this method, it quiesces the device by stopping the driver's
7640 * worker thread for the device, turning off device's interrupt and DMA,
7641 * and bring the device offline. Note that as the driver implements the
7642 * minimum PM requirements to a power-aware driver's PM support for the
7643 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7644 * to the suspend() method call will be treated as SUSPEND and the driver will
7645 * fully reinitialize its device during resume() method call, the driver will
7646 * set device to PCI_D3hot state in PCI config space instead of setting it
7647 * according to the @msg provided by the PM.
7650 * 0 - driver suspended the device
7654 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
7656 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7657 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7659 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7660 "0473 PCI device Power Management suspend.\n");
7662 /* Bring down the device */
7663 lpfc_offline_prep(phba
);
7665 kthread_stop(phba
->worker_thread
);
7667 /* Disable interrupt from device */
7668 lpfc_sli_disable_intr(phba
);
7670 /* Save device state to PCI config space */
7671 pci_save_state(pdev
);
7672 pci_set_power_state(pdev
, PCI_D3hot
);
7678 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
7679 * @pdev: pointer to PCI device
7681 * This routine is to be called from the kernel's PCI subsystem to support
7682 * system Power Management (PM) to device with SLI-3 interface spec. When PM
7683 * invokes this method, it restores the device's PCI config space state and
7684 * fully reinitializes the device and brings it online. Note that as the
7685 * driver implements the minimum PM requirements to a power-aware driver's
7686 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
7687 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
7688 * driver will fully reinitialize its device during resume() method call,
7689 * the device will be set to PCI_D0 directly in PCI config space before
7690 * restoring the state.
7693 * 0 - driver suspended the device
7697 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
7699 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7700 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7704 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7705 "0452 PCI device Power Management resume.\n");
7707 /* Restore device state from PCI config space */
7708 pci_set_power_state(pdev
, PCI_D0
);
7709 pci_restore_state(pdev
);
7712 * As the new kernel behavior of pci_restore_state() API call clears
7713 * device saved_state flag, need to save the restored state again.
7715 pci_save_state(pdev
);
7717 if (pdev
->is_busmaster
)
7718 pci_set_master(pdev
);
7720 /* Startup the kernel thread for this host adapter. */
7721 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
7722 "lpfc_worker_%d", phba
->brd_no
);
7723 if (IS_ERR(phba
->worker_thread
)) {
7724 error
= PTR_ERR(phba
->worker_thread
);
7725 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7726 "0434 PM resume failed to start worker "
7727 "thread: error=x%x.\n", error
);
7731 /* Configure and enable interrupt */
7732 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
7733 if (intr_mode
== LPFC_INTR_ERROR
) {
7734 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7735 "0430 PM resume Failed to enable interrupt\n");
7738 phba
->intr_mode
= intr_mode
;
7740 /* Restart HBA and bring it online */
7741 lpfc_sli_brdrestart(phba
);
7744 /* Log the current active interrupt mode */
7745 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
7751 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
7752 * @phba: pointer to lpfc hba data structure.
7754 * This routine is called to prepare the SLI3 device for PCI slot recover. It
7755 * aborts and stops all the on-going I/Os on the pci device.
7758 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
7760 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7761 "2723 PCI channel I/O abort preparing for recovery\n");
7762 /* Prepare for bringing HBA offline */
7763 lpfc_offline_prep(phba
);
7764 /* Clear sli active flag to prevent sysfs access to HBA */
7765 spin_lock_irq(&phba
->hbalock
);
7766 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
7767 spin_unlock_irq(&phba
->hbalock
);
7768 /* Stop and flush all I/Os and bring HBA offline */
7773 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
7774 * @phba: pointer to lpfc hba data structure.
7776 * This routine is called to prepare the SLI3 device for PCI slot reset. It
7777 * disables the device interrupt and pci device, and aborts the internal FCP
7781 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
7783 struct lpfc_sli
*psli
= &phba
->sli
;
7784 struct lpfc_sli_ring
*pring
;
7786 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7787 "2710 PCI channel disable preparing for reset\n");
7788 /* Disable interrupt and pci device */
7789 lpfc_sli_disable_intr(phba
);
7790 pci_disable_device(phba
->pcidev
);
7792 * There may be I/Os dropped by the firmware.
7793 * Error iocb (I/O) on txcmplq and let the SCSI layer
7794 * retry it after re-establishing link.
7796 pring
= &psli
->ring
[psli
->fcp_ring
];
7797 lpfc_sli_abort_iocb_ring(phba
, pring
);
7801 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
7802 * @phba: pointer to lpfc hba data structure.
7804 * This routine is called to prepare the SLI3 device for PCI slot permanently
7805 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
7809 lpfc_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
7811 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7812 "2711 PCI channel permanent disable for failure\n");
7813 /* Clean up all driver's outstanding SCSI I/Os */
7814 lpfc_sli_flush_fcp_rings(phba
);
7818 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
7819 * @pdev: pointer to PCI device.
7820 * @state: the current PCI connection state.
7822 * This routine is called from the PCI subsystem for I/O error handling to
7823 * device with SLI-3 interface spec. This function is called by the PCI
7824 * subsystem after a PCI bus error affecting this device has been detected.
7825 * When this function is invoked, it will need to stop all the I/Os and
7826 * interrupt(s) to the device. Once that is done, it will return
7827 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
7831 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
7832 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7833 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7835 static pci_ers_result_t
7836 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
7838 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7839 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7841 /* Block all SCSI devices' I/Os on the host */
7842 lpfc_scsi_dev_block(phba
);
7845 case pci_channel_io_normal
:
7846 /* Non-fatal error, prepare for recovery */
7847 lpfc_sli_prep_dev_for_recover(phba
);
7848 return PCI_ERS_RESULT_CAN_RECOVER
;
7849 case pci_channel_io_frozen
:
7850 /* Fatal error, prepare for slot reset */
7851 lpfc_sli_prep_dev_for_reset(phba
);
7852 return PCI_ERS_RESULT_NEED_RESET
;
7853 case pci_channel_io_perm_failure
:
7854 /* Permanent failure, prepare for device down */
7855 lpfc_prep_dev_for_perm_failure(phba
);
7856 return PCI_ERS_RESULT_DISCONNECT
;
7858 /* Unknown state, prepare and request slot reset */
7859 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7860 "0472 Unknown PCI error state: x%x\n", state
);
7861 lpfc_sli_prep_dev_for_reset(phba
);
7862 return PCI_ERS_RESULT_NEED_RESET
;
7867 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
7868 * @pdev: pointer to PCI device.
7870 * This routine is called from the PCI subsystem for error handling to
7871 * device with SLI-3 interface spec. This is called after PCI bus has been
7872 * reset to restart the PCI card from scratch, as if from a cold-boot.
7873 * During the PCI subsystem error recovery, after driver returns
7874 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7875 * recovery and then call this routine before calling the .resume method
7876 * to recover the device. This function will initialize the HBA device,
7877 * enable the interrupt, but it will just put the HBA to offline state
7878 * without passing any I/O traffic.
7881 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7882 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7884 static pci_ers_result_t
7885 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
7887 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7888 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7889 struct lpfc_sli
*psli
= &phba
->sli
;
7892 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
7893 if (pci_enable_device_mem(pdev
)) {
7894 printk(KERN_ERR
"lpfc: Cannot re-enable "
7895 "PCI device after reset.\n");
7896 return PCI_ERS_RESULT_DISCONNECT
;
7899 pci_restore_state(pdev
);
7902 * As the new kernel behavior of pci_restore_state() API call clears
7903 * device saved_state flag, need to save the restored state again.
7905 pci_save_state(pdev
);
7907 if (pdev
->is_busmaster
)
7908 pci_set_master(pdev
);
7910 spin_lock_irq(&phba
->hbalock
);
7911 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
7912 spin_unlock_irq(&phba
->hbalock
);
7914 /* Configure and enable interrupt */
7915 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
7916 if (intr_mode
== LPFC_INTR_ERROR
) {
7917 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7918 "0427 Cannot re-enable interrupt after "
7920 return PCI_ERS_RESULT_DISCONNECT
;
7922 phba
->intr_mode
= intr_mode
;
7924 /* Take device offline; this will perform cleanup */
7926 lpfc_sli_brdrestart(phba
);
7928 /* Log the current active interrupt mode */
7929 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
7931 return PCI_ERS_RESULT_RECOVERED
;
7935 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
7936 * @pdev: pointer to PCI device
7938 * This routine is called from the PCI subsystem for error handling to device
7939 * with SLI-3 interface spec. It is called when kernel error recovery tells
7940 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7941 * error recovery. After this call, traffic can start to flow from this device
7945 lpfc_io_resume_s3(struct pci_dev
*pdev
)
7947 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7948 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7950 /* Bring the device online */
7953 /* Clean up Advanced Error Reporting (AER) if needed */
7954 if (phba
->hba_flag
& HBA_AER_ENABLED
)
7955 pci_cleanup_aer_uncorrect_error_status(pdev
);
7959 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
7960 * @phba: pointer to lpfc hba data structure.
7962 * returns the number of ELS/CT IOCBs to reserve
7965 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
7967 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
7969 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7972 else if (max_xri
<= 256)
7974 else if (max_xri
<= 512)
7976 else if (max_xri
<= 1024)
7985 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
7986 * @pdev: pointer to PCI device
7987 * @pid: pointer to PCI device identifier
7989 * This routine is called from the kernel's PCI subsystem to device with
7990 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7991 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7992 * information of the device and driver to see if the driver state that it
7993 * can support this kind of device. If the match is successful, the driver
7994 * core invokes this routine. If this routine determines it can claim the HBA,
7995 * it does all the initialization that it needs to do to handle the HBA
7999 * 0 - driver can claim the device
8000 * negative value - driver can not claim the device
8002 static int __devinit
8003 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8005 struct lpfc_hba
*phba
;
8006 struct lpfc_vport
*vport
= NULL
;
8007 struct Scsi_Host
*shost
= NULL
;
8009 uint32_t cfg_mode
, intr_mode
;
8012 /* Allocate memory for HBA structure */
8013 phba
= lpfc_hba_alloc(pdev
);
8017 /* Perform generic PCI device enabling operation */
8018 error
= lpfc_enable_pci_dev(phba
);
8020 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8021 "1409 Failed to enable pci device.\n");
8025 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
8026 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
8028 goto out_disable_pci_dev
;
8030 /* Set up SLI-4 specific device PCI memory space */
8031 error
= lpfc_sli4_pci_mem_setup(phba
);
8033 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8034 "1410 Failed to set up pci memory space.\n");
8035 goto out_disable_pci_dev
;
8038 /* Set up phase-1 common device driver resources */
8039 error
= lpfc_setup_driver_resource_phase1(phba
);
8041 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8042 "1411 Failed to set up driver resource.\n");
8043 goto out_unset_pci_mem_s4
;
8046 /* Set up SLI-4 Specific device driver resources */
8047 error
= lpfc_sli4_driver_resource_setup(phba
);
8049 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8050 "1412 Failed to set up driver resource.\n");
8051 goto out_unset_pci_mem_s4
;
8054 /* Initialize and populate the iocb list per host */
8055 error
= lpfc_init_iocb_list(phba
,
8056 phba
->sli4_hba
.max_cfg_param
.max_xri
);
8058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8059 "1413 Failed to initialize iocb list.\n");
8060 goto out_unset_driver_resource_s4
;
8063 /* Set up common device driver resources */
8064 error
= lpfc_setup_driver_resource_phase2(phba
);
8066 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8067 "1414 Failed to set up driver resource.\n");
8068 goto out_free_iocb_list
;
8071 /* Create SCSI host to the physical port */
8072 error
= lpfc_create_shost(phba
);
8074 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8075 "1415 Failed to create scsi host.\n");
8076 goto out_unset_driver_resource
;
8079 /* Configure sysfs attributes */
8080 vport
= phba
->pport
;
8081 error
= lpfc_alloc_sysfs_attr(vport
);
8083 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8084 "1416 Failed to allocate sysfs attr\n");
8085 goto out_destroy_shost
;
8088 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
8089 /* Now, trying to enable interrupt and bring up the device */
8090 cfg_mode
= phba
->cfg_use_msi
;
8092 /* Put device to a known state before enabling interrupt */
8093 lpfc_stop_port(phba
);
8094 /* Configure and enable interrupt */
8095 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
8096 if (intr_mode
== LPFC_INTR_ERROR
) {
8097 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8098 "0426 Failed to enable interrupt.\n");
8100 goto out_free_sysfs_attr
;
8102 /* Default to single FCP EQ for non-MSI-X */
8103 if (phba
->intr_type
!= MSIX
)
8104 phba
->cfg_fcp_eq_count
= 1;
8105 /* Set up SLI-4 HBA */
8106 if (lpfc_sli4_hba_setup(phba
)) {
8107 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8108 "1421 Failed to set up hba\n");
8110 goto out_disable_intr
;
8113 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
8115 mcnt
= lpfc_sli4_send_nop_mbox_cmds(phba
,
8118 /* Check active interrupts received only for MSI/MSI-X */
8119 if (intr_mode
== 0 ||
8120 phba
->sli
.slistat
.sli_intr
>= LPFC_ACT_INTR_CNT
) {
8121 /* Log the current active interrupt mode */
8122 phba
->intr_mode
= intr_mode
;
8123 lpfc_log_intr_mode(phba
, intr_mode
);
8126 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8127 "0451 Configure interrupt mode (%d) "
8128 "failed active interrupt test.\n",
8130 /* Unset the preivous SLI-4 HBA setup */
8131 lpfc_sli4_unset_hba(phba
);
8132 /* Try next level of interrupt mode */
8133 cfg_mode
= --intr_mode
;
8136 /* Perform post initialization setup */
8137 lpfc_post_init_setup(phba
);
8139 /* Check if there are static vports to be created. */
8140 lpfc_create_static_vport(phba
);
8145 lpfc_sli4_disable_intr(phba
);
8146 out_free_sysfs_attr
:
8147 lpfc_free_sysfs_attr(vport
);
8149 lpfc_destroy_shost(phba
);
8150 out_unset_driver_resource
:
8151 lpfc_unset_driver_resource_phase2(phba
);
8153 lpfc_free_iocb_list(phba
);
8154 out_unset_driver_resource_s4
:
8155 lpfc_sli4_driver_resource_unset(phba
);
8156 out_unset_pci_mem_s4
:
8157 lpfc_sli4_pci_mem_unset(phba
);
8158 out_disable_pci_dev
:
8159 lpfc_disable_pci_dev(phba
);
8161 scsi_host_put(shost
);
8163 lpfc_hba_free(phba
);
8168 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
8169 * @pdev: pointer to PCI device
8171 * This routine is called from the kernel's PCI subsystem to device with
8172 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
8173 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8174 * device to be removed from the PCI subsystem properly.
8176 static void __devexit
8177 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
8179 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8180 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
8181 struct lpfc_vport
**vports
;
8182 struct lpfc_hba
*phba
= vport
->phba
;
8185 /* Mark the device unloading flag */
8186 spin_lock_irq(&phba
->hbalock
);
8187 vport
->load_flag
|= FC_UNLOADING
;
8188 spin_unlock_irq(&phba
->hbalock
);
8190 /* Free the HBA sysfs attributes */
8191 lpfc_free_sysfs_attr(vport
);
8193 /* Release all the vports against this physical port */
8194 vports
= lpfc_create_vport_work_array(phba
);
8196 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
8197 fc_vport_terminate(vports
[i
]->fc_vport
);
8198 lpfc_destroy_vport_work_array(phba
, vports
);
8200 /* Remove FC host and then SCSI host with the physical port */
8201 fc_remove_host(shost
);
8202 scsi_remove_host(shost
);
8204 /* Perform cleanup on the physical port */
8205 lpfc_cleanup(vport
);
8208 * Bring down the SLI Layer. This step disables all interrupts,
8209 * clears the rings, discards all mailbox commands, and resets
8210 * the HBA FCoE function.
8212 lpfc_debugfs_terminate(vport
);
8213 lpfc_sli4_hba_unset(phba
);
8215 spin_lock_irq(&phba
->hbalock
);
8216 list_del_init(&vport
->listentry
);
8217 spin_unlock_irq(&phba
->hbalock
);
8219 /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
8220 * buffers are released to their corresponding pools here.
8222 lpfc_scsi_free(phba
);
8223 lpfc_sli4_driver_resource_unset(phba
);
8225 /* Unmap adapter Control and Doorbell registers */
8226 lpfc_sli4_pci_mem_unset(phba
);
8228 /* Release PCI resources and disable device's PCI function */
8229 scsi_host_put(shost
);
8230 lpfc_disable_pci_dev(phba
);
8232 /* Finally, free the driver's device data structure */
8233 lpfc_hba_free(phba
);
8239 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
8240 * @pdev: pointer to PCI device
8241 * @msg: power management message
8243 * This routine is called from the kernel's PCI subsystem to support system
8244 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
8245 * this method, it quiesces the device by stopping the driver's worker
8246 * thread for the device, turning off device's interrupt and DMA, and bring
8247 * the device offline. Note that as the driver implements the minimum PM
8248 * requirements to a power-aware driver's PM support for suspend/resume -- all
8249 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
8250 * method call will be treated as SUSPEND and the driver will fully
8251 * reinitialize its device during resume() method call, the driver will set
8252 * device to PCI_D3hot state in PCI config space instead of setting it
8253 * according to the @msg provided by the PM.
8256 * 0 - driver suspended the device
8260 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
8262 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8263 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8265 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8266 "0298 PCI device Power Management suspend.\n");
8268 /* Bring down the device */
8269 lpfc_offline_prep(phba
);
8271 kthread_stop(phba
->worker_thread
);
8273 /* Disable interrupt from device */
8274 lpfc_sli4_disable_intr(phba
);
8276 /* Save device state to PCI config space */
8277 pci_save_state(pdev
);
8278 pci_set_power_state(pdev
, PCI_D3hot
);
8284 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
8285 * @pdev: pointer to PCI device
8287 * This routine is called from the kernel's PCI subsystem to support system
8288 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
8289 * this method, it restores the device's PCI config space state and fully
8290 * reinitializes the device and brings it online. Note that as the driver
8291 * implements the minimum PM requirements to a power-aware driver's PM for
8292 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8293 * to the suspend() method call will be treated as SUSPEND and the driver
8294 * will fully reinitialize its device during resume() method call, the device
8295 * will be set to PCI_D0 directly in PCI config space before restoring the
8299 * 0 - driver suspended the device
8303 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
8305 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8306 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8310 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8311 "0292 PCI device Power Management resume.\n");
8313 /* Restore device state from PCI config space */
8314 pci_set_power_state(pdev
, PCI_D0
);
8315 pci_restore_state(pdev
);
8318 * As the new kernel behavior of pci_restore_state() API call clears
8319 * device saved_state flag, need to save the restored state again.
8321 pci_save_state(pdev
);
8323 if (pdev
->is_busmaster
)
8324 pci_set_master(pdev
);
8326 /* Startup the kernel thread for this host adapter. */
8327 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
8328 "lpfc_worker_%d", phba
->brd_no
);
8329 if (IS_ERR(phba
->worker_thread
)) {
8330 error
= PTR_ERR(phba
->worker_thread
);
8331 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8332 "0293 PM resume failed to start worker "
8333 "thread: error=x%x.\n", error
);
8337 /* Configure and enable interrupt */
8338 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
8339 if (intr_mode
== LPFC_INTR_ERROR
) {
8340 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8341 "0294 PM resume Failed to enable interrupt\n");
8344 phba
->intr_mode
= intr_mode
;
8346 /* Restart HBA and bring it online */
8347 lpfc_sli_brdrestart(phba
);
8350 /* Log the current active interrupt mode */
8351 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
8357 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
8358 * @pdev: pointer to PCI device.
8359 * @state: the current PCI connection state.
8361 * This routine is called from the PCI subsystem for error handling to device
8362 * with SLI-4 interface spec. This function is called by the PCI subsystem
8363 * after a PCI bus error affecting this device has been detected. When this
8364 * function is invoked, it will need to stop all the I/Os and interrupt(s)
8365 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
8366 * for the PCI subsystem to perform proper recovery as desired.
8369 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8370 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8372 static pci_ers_result_t
8373 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
8375 return PCI_ERS_RESULT_NEED_RESET
;
8379 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
8380 * @pdev: pointer to PCI device.
8382 * This routine is called from the PCI subsystem for error handling to device
8383 * with SLI-4 interface spec. It is called after PCI bus has been reset to
8384 * restart the PCI card from scratch, as if from a cold-boot. During the
8385 * PCI subsystem error recovery, after the driver returns
8386 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
8387 * recovery and then call this routine before calling the .resume method to
8388 * recover the device. This function will initialize the HBA device, enable
8389 * the interrupt, but it will just put the HBA to offline state without
8390 * passing any I/O traffic.
8393 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8394 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8396 static pci_ers_result_t
8397 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
8399 return PCI_ERS_RESULT_RECOVERED
;
8403 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
8404 * @pdev: pointer to PCI device
8406 * This routine is called from the PCI subsystem for error handling to device
8407 * with SLI-4 interface spec. It is called when kernel error recovery tells
8408 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
8409 * error recovery. After this call, traffic can start to flow from this device
8413 lpfc_io_resume_s4(struct pci_dev
*pdev
)
8419 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
8420 * @pdev: pointer to PCI device
8421 * @pid: pointer to PCI device identifier
8423 * This routine is to be registered to the kernel's PCI subsystem. When an
8424 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
8425 * at PCI device-specific information of the device and driver to see if the
8426 * driver state that it can support this kind of device. If the match is
8427 * successful, the driver core invokes this routine. This routine dispatches
8428 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
8429 * do all the initialization that it needs to do to handle the HBA device
8433 * 0 - driver can claim the device
8434 * negative value - driver can not claim the device
8436 static int __devinit
8437 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8440 struct lpfc_sli_intf intf
;
8442 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
8445 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
8446 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
8447 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
8449 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
8455 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
8456 * @pdev: pointer to PCI device
8458 * This routine is to be registered to the kernel's PCI subsystem. When an
8459 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
8460 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
8461 * remove routine, which will perform all the necessary cleanup for the
8462 * device to be removed from the PCI subsystem properly.
8464 static void __devexit
8465 lpfc_pci_remove_one(struct pci_dev
*pdev
)
8467 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8468 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8470 switch (phba
->pci_dev_grp
) {
8471 case LPFC_PCI_DEV_LP
:
8472 lpfc_pci_remove_one_s3(pdev
);
8474 case LPFC_PCI_DEV_OC
:
8475 lpfc_pci_remove_one_s4(pdev
);
8478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8479 "1424 Invalid PCI device group: 0x%x\n",
8487 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
8488 * @pdev: pointer to PCI device
8489 * @msg: power management message
8491 * This routine is to be registered to the kernel's PCI subsystem to support
8492 * system Power Management (PM). When PM invokes this method, it dispatches
8493 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
8494 * suspend the device.
8497 * 0 - driver suspended the device
8501 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
8503 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8504 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8507 switch (phba
->pci_dev_grp
) {
8508 case LPFC_PCI_DEV_LP
:
8509 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
8511 case LPFC_PCI_DEV_OC
:
8512 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
8515 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8516 "1425 Invalid PCI device group: 0x%x\n",
8524 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
8525 * @pdev: pointer to PCI device
8527 * This routine is to be registered to the kernel's PCI subsystem to support
8528 * system Power Management (PM). When PM invokes this method, it dispatches
8529 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
8530 * resume the device.
8533 * 0 - driver suspended the device
8537 lpfc_pci_resume_one(struct pci_dev
*pdev
)
8539 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8540 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8543 switch (phba
->pci_dev_grp
) {
8544 case LPFC_PCI_DEV_LP
:
8545 rc
= lpfc_pci_resume_one_s3(pdev
);
8547 case LPFC_PCI_DEV_OC
:
8548 rc
= lpfc_pci_resume_one_s4(pdev
);
8551 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8552 "1426 Invalid PCI device group: 0x%x\n",
8560 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
8561 * @pdev: pointer to PCI device.
8562 * @state: the current PCI connection state.
8564 * This routine is registered to the PCI subsystem for error handling. This
8565 * function is called by the PCI subsystem after a PCI bus error affecting
8566 * this device has been detected. When this routine is invoked, it dispatches
8567 * the action to the proper SLI-3 or SLI-4 device error detected handling
8568 * routine, which will perform the proper error detected operation.
8571 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8572 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8574 static pci_ers_result_t
8575 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8577 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8578 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8579 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
8581 switch (phba
->pci_dev_grp
) {
8582 case LPFC_PCI_DEV_LP
:
8583 rc
= lpfc_io_error_detected_s3(pdev
, state
);
8585 case LPFC_PCI_DEV_OC
:
8586 rc
= lpfc_io_error_detected_s4(pdev
, state
);
8589 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8590 "1427 Invalid PCI device group: 0x%x\n",
8598 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
8599 * @pdev: pointer to PCI device.
8601 * This routine is registered to the PCI subsystem for error handling. This
8602 * function is called after PCI bus has been reset to restart the PCI card
8603 * from scratch, as if from a cold-boot. When this routine is invoked, it
8604 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
8605 * routine, which will perform the proper device reset.
8608 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8609 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8611 static pci_ers_result_t
8612 lpfc_io_slot_reset(struct pci_dev
*pdev
)
8614 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8615 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8616 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
8618 switch (phba
->pci_dev_grp
) {
8619 case LPFC_PCI_DEV_LP
:
8620 rc
= lpfc_io_slot_reset_s3(pdev
);
8622 case LPFC_PCI_DEV_OC
:
8623 rc
= lpfc_io_slot_reset_s4(pdev
);
8626 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8627 "1428 Invalid PCI device group: 0x%x\n",
8635 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
8636 * @pdev: pointer to PCI device
8638 * This routine is registered to the PCI subsystem for error handling. It
8639 * is called when kernel error recovery tells the lpfc driver that it is
8640 * OK to resume normal PCI operation after PCI bus error recovery. When
8641 * this routine is invoked, it dispatches the action to the proper SLI-3
8642 * or SLI-4 device io_resume routine, which will resume the device operation.
8645 lpfc_io_resume(struct pci_dev
*pdev
)
8647 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8648 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8650 switch (phba
->pci_dev_grp
) {
8651 case LPFC_PCI_DEV_LP
:
8652 lpfc_io_resume_s3(pdev
);
8654 case LPFC_PCI_DEV_OC
:
8655 lpfc_io_resume_s4(pdev
);
8658 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8659 "1429 Invalid PCI device group: 0x%x\n",
8666 static struct pci_device_id lpfc_id_table
[] = {
8667 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
8668 PCI_ANY_ID
, PCI_ANY_ID
, },
8669 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
8670 PCI_ANY_ID
, PCI_ANY_ID
, },
8671 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
8672 PCI_ANY_ID
, PCI_ANY_ID
, },
8673 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
8674 PCI_ANY_ID
, PCI_ANY_ID
, },
8675 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
8676 PCI_ANY_ID
, PCI_ANY_ID
, },
8677 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
8678 PCI_ANY_ID
, PCI_ANY_ID
, },
8679 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
8680 PCI_ANY_ID
, PCI_ANY_ID
, },
8681 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
8682 PCI_ANY_ID
, PCI_ANY_ID
, },
8683 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
8684 PCI_ANY_ID
, PCI_ANY_ID
, },
8685 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
8686 PCI_ANY_ID
, PCI_ANY_ID
, },
8687 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
8688 PCI_ANY_ID
, PCI_ANY_ID
, },
8689 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
8690 PCI_ANY_ID
, PCI_ANY_ID
, },
8691 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
8692 PCI_ANY_ID
, PCI_ANY_ID
, },
8693 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
8694 PCI_ANY_ID
, PCI_ANY_ID
, },
8695 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
8696 PCI_ANY_ID
, PCI_ANY_ID
, },
8697 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
8698 PCI_ANY_ID
, PCI_ANY_ID
, },
8699 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
8700 PCI_ANY_ID
, PCI_ANY_ID
, },
8701 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
8702 PCI_ANY_ID
, PCI_ANY_ID
, },
8703 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
8704 PCI_ANY_ID
, PCI_ANY_ID
, },
8705 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
8706 PCI_ANY_ID
, PCI_ANY_ID
, },
8707 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
8708 PCI_ANY_ID
, PCI_ANY_ID
, },
8709 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
8710 PCI_ANY_ID
, PCI_ANY_ID
, },
8711 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
8712 PCI_ANY_ID
, PCI_ANY_ID
, },
8713 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
8714 PCI_ANY_ID
, PCI_ANY_ID
, },
8715 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
8716 PCI_ANY_ID
, PCI_ANY_ID
, },
8717 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
8718 PCI_ANY_ID
, PCI_ANY_ID
, },
8719 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
8720 PCI_ANY_ID
, PCI_ANY_ID
, },
8721 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
8722 PCI_ANY_ID
, PCI_ANY_ID
, },
8723 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
8724 PCI_ANY_ID
, PCI_ANY_ID
, },
8725 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
8726 PCI_ANY_ID
, PCI_ANY_ID
, },
8727 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
8728 PCI_ANY_ID
, PCI_ANY_ID
, },
8729 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
8730 PCI_ANY_ID
, PCI_ANY_ID
, },
8731 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
8732 PCI_ANY_ID
, PCI_ANY_ID
, },
8733 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
8734 PCI_ANY_ID
, PCI_ANY_ID
, },
8735 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
8736 PCI_ANY_ID
, PCI_ANY_ID
, },
8737 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
8738 PCI_ANY_ID
, PCI_ANY_ID
, },
8739 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
8740 PCI_ANY_ID
, PCI_ANY_ID
, },
8741 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
8742 PCI_ANY_ID
, PCI_ANY_ID
, },
8743 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
8744 PCI_ANY_ID
, PCI_ANY_ID
, },
8745 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
8746 PCI_ANY_ID
, PCI_ANY_ID
, },
8750 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
8752 static struct pci_error_handlers lpfc_err_handler
= {
8753 .error_detected
= lpfc_io_error_detected
,
8754 .slot_reset
= lpfc_io_slot_reset
,
8755 .resume
= lpfc_io_resume
,
8758 static struct pci_driver lpfc_driver
= {
8759 .name
= LPFC_DRIVER_NAME
,
8760 .id_table
= lpfc_id_table
,
8761 .probe
= lpfc_pci_probe_one
,
8762 .remove
= __devexit_p(lpfc_pci_remove_one
),
8763 .suspend
= lpfc_pci_suspend_one
,
8764 .resume
= lpfc_pci_resume_one
,
8765 .err_handler
= &lpfc_err_handler
,
8769 * lpfc_init - lpfc module initialization routine
8771 * This routine is to be invoked when the lpfc module is loaded into the
8772 * kernel. The special kernel macro module_init() is used to indicate the
8773 * role of this routine to the kernel as lpfc module entry point.
8777 * -ENOMEM - FC attach transport failed
8778 * all others - failed
8785 printk(LPFC_MODULE_DESC
"\n");
8786 printk(LPFC_COPYRIGHT
"\n");
8788 if (lpfc_enable_npiv
) {
8789 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
8790 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
8792 lpfc_transport_template
=
8793 fc_attach_transport(&lpfc_transport_functions
);
8794 if (lpfc_transport_template
== NULL
)
8796 if (lpfc_enable_npiv
) {
8797 lpfc_vport_transport_template
=
8798 fc_attach_transport(&lpfc_vport_transport_functions
);
8799 if (lpfc_vport_transport_template
== NULL
) {
8800 fc_release_transport(lpfc_transport_template
);
8804 error
= pci_register_driver(&lpfc_driver
);
8806 fc_release_transport(lpfc_transport_template
);
8807 if (lpfc_enable_npiv
)
8808 fc_release_transport(lpfc_vport_transport_template
);
8815 * lpfc_exit - lpfc module removal routine
8817 * This routine is invoked when the lpfc module is removed from the kernel.
8818 * The special kernel macro module_exit() is used to indicate the role of
8819 * this routine to the kernel as lpfc module exit point.
8824 pci_unregister_driver(&lpfc_driver
);
8825 fc_release_transport(lpfc_transport_template
);
8826 if (lpfc_enable_npiv
)
8827 fc_release_transport(lpfc_vport_transport_template
);
8828 if (_dump_buf_data
) {
8829 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
8830 "_dump_buf_data at 0x%p\n",
8831 (1L << _dump_buf_data_order
), _dump_buf_data
);
8832 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
8835 if (_dump_buf_dif
) {
8836 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
8837 "_dump_buf_dif at 0x%p\n",
8838 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
8839 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
8843 module_init(lpfc_init
);
8844 module_exit(lpfc_exit
);
8845 MODULE_LICENSE("GPL");
8846 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
8847 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
8848 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);