1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/kthread.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/ctype.h>
34 #include <linux/aer.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/msi.h>
40 #include <linux/irq.h>
41 #include <linux/bitops.h>
42 #include <linux/crash_dump.h>
43 #include <linux/cpu.h>
44 #include <linux/cpuhotplug.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_transport_fc.h>
50 #include <scsi/scsi_tcq.h>
51 #include <scsi/fc/fc_fs.h>
56 #include "lpfc_sli4.h"
58 #include "lpfc_disc.h"
60 #include "lpfc_scsi.h"
61 #include "lpfc_nvme.h"
62 #include "lpfc_logmsg.h"
63 #include "lpfc_crtn.h"
64 #include "lpfc_vport.h"
65 #include "lpfc_version.h"
68 static enum cpuhp_state lpfc_cpuhp_state
;
69 /* Used when mapping IRQ vectors in a driver centric manner */
70 static uint32_t lpfc_present_cpu
;
72 static void __lpfc_cpuhp_remove(struct lpfc_hba
*phba
);
73 static void lpfc_cpuhp_remove(struct lpfc_hba
*phba
);
74 static void lpfc_cpuhp_add(struct lpfc_hba
*phba
);
75 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
76 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
77 static int lpfc_sli4_queue_verify(struct lpfc_hba
*);
78 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
79 static int lpfc_setup_endian_order(struct lpfc_hba
*);
80 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
81 static void lpfc_free_els_sgl_list(struct lpfc_hba
*);
82 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba
*);
83 static void lpfc_init_sgl_list(struct lpfc_hba
*);
84 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
85 static void lpfc_free_active_sgl(struct lpfc_hba
*);
86 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
87 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
88 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
89 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
90 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
91 static void lpfc_sli4_disable_intr(struct lpfc_hba
*);
92 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba
*, uint32_t);
93 static void lpfc_sli4_oas_verify(struct lpfc_hba
*phba
);
94 static uint16_t lpfc_find_cpu_handle(struct lpfc_hba
*, uint16_t, int);
95 static void lpfc_setup_bg(struct lpfc_hba
*, struct Scsi_Host
*);
97 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
98 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
99 static DEFINE_IDR(lpfc_hba_index
);
100 #define LPFC_NVMET_BUF_POST 254
103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
104 * @phba: pointer to lpfc hba data structure.
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
117 lpfc_config_port_prep(struct lpfc_hba
*phba
)
119 lpfc_vpd_t
*vp
= &phba
->vpd
;
123 char *lpfc_vpd_data
= NULL
;
125 static char licensed
[56] =
126 "key unlock for use with gnu public licensed code only\0";
127 static int init_key
= 1;
129 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
131 phba
->link_state
= LPFC_HBA_ERROR
;
136 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
138 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
140 uint32_t *ptext
= (uint32_t *) licensed
;
142 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
143 *ptext
= cpu_to_be32(*ptext
);
147 lpfc_read_nv(phba
, pmb
);
148 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
149 sizeof (mb
->un
.varRDnvp
.rsvd3
));
150 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
153 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
155 if (rc
!= MBX_SUCCESS
) {
156 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
157 "0324 Config Port initialization "
158 "error, mbxCmd x%x READ_NVPARM, "
160 mb
->mbxCommand
, mb
->mbxStatus
);
161 mempool_free(pmb
, phba
->mbox_mem_pool
);
164 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
166 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
171 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
172 * which was already set in lpfc_get_cfgparam()
174 phba
->sli3_options
&= (uint32_t)LPFC_SLI3_BG_ENABLED
;
176 /* Setup and issue mailbox READ REV command */
177 lpfc_read_rev(phba
, pmb
);
178 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
179 if (rc
!= MBX_SUCCESS
) {
180 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
181 "0439 Adapter failed to init, mbxCmd x%x "
182 "READ_REV, mbxStatus x%x\n",
183 mb
->mbxCommand
, mb
->mbxStatus
);
184 mempool_free( pmb
, phba
->mbox_mem_pool
);
190 * The value of rr must be 1 since the driver set the cv field to 1.
191 * This setting requires the FW to set all revision fields.
193 if (mb
->un
.varRdRev
.rr
== 0) {
195 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
196 "0440 Adapter failed to init, READ_REV has "
197 "missing revision information.\n");
198 mempool_free(pmb
, phba
->mbox_mem_pool
);
202 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
203 mempool_free(pmb
, phba
->mbox_mem_pool
);
207 /* Save information as VPD data */
209 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
210 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
211 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
212 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
213 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
214 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
215 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
216 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
217 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
218 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
219 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
220 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
221 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
222 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
223 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
225 /* If the sli feature level is less then 9, we must
226 * tear down all RPIs and VPIs on link down if NPIV
229 if (vp
->rev
.feaLevelHigh
< 9)
230 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
232 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
233 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
234 sizeof (phba
->RandomData
));
236 /* Get adapter VPD information */
237 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
241 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
242 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
244 if (rc
!= MBX_SUCCESS
) {
245 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
246 "0441 VPD not present on adapter, "
247 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
248 mb
->mbxCommand
, mb
->mbxStatus
);
249 mb
->un
.varDmp
.word_cnt
= 0;
251 /* dump mem may return a zero when finished or we got a
252 * mailbox error, either way we are done.
254 if (mb
->un
.varDmp
.word_cnt
== 0)
257 i
= mb
->un
.varDmp
.word_cnt
* sizeof(uint32_t);
258 if (offset
+ i
> DMP_VPD_SIZE
)
259 i
= DMP_VPD_SIZE
- offset
;
260 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
261 lpfc_vpd_data
+ offset
, i
);
263 } while (offset
< DMP_VPD_SIZE
);
265 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
267 kfree(lpfc_vpd_data
);
269 mempool_free(pmb
, phba
->mbox_mem_pool
);
274 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
275 * @phba: pointer to lpfc hba data structure.
276 * @pmboxq: pointer to the driver internal queue element for mailbox command.
278 * This is the completion handler for driver's configuring asynchronous event
279 * mailbox command to the device. If the mailbox command returns successfully,
280 * it will set internal async event support flag to 1; otherwise, it will
281 * set internal async event support flag to 0.
284 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
286 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
287 phba
->temp_sensor_support
= 1;
289 phba
->temp_sensor_support
= 0;
290 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
295 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
296 * @phba: pointer to lpfc hba data structure.
297 * @pmboxq: pointer to the driver internal queue element for mailbox command.
299 * This is the completion handler for dump mailbox command for getting
300 * wake up parameters. When this command complete, the response contain
301 * Option rom version of the HBA. This function translate the version number
302 * into a human readable string and store it in OptionROMVersion.
305 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
308 uint32_t prog_id_word
;
310 /* character array used for decoding dist type. */
311 char dist_char
[] = "nabx";
313 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
314 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
318 prg
= (struct prog_id
*) &prog_id_word
;
320 /* word 7 contain option rom version */
321 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
323 /* Decode the Option rom version word to a readable string */
325 dist
= dist_char
[prg
->dist
];
327 if ((prg
->dist
== 3) && (prg
->num
== 0))
328 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d",
329 prg
->ver
, prg
->rev
, prg
->lev
);
331 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d%c%d",
332 prg
->ver
, prg
->rev
, prg
->lev
,
334 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
339 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
340 * cfg_soft_wwnn, cfg_soft_wwpn
341 * @vport: pointer to lpfc vport data structure.
348 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
350 uint8_t vvvl
= vport
->fc_sparam
.cmn
.valid_vendor_ver_level
;
351 u32
*fawwpn_key
= (u32
*)&vport
->fc_sparam
.un
.vendorVersion
[0];
353 /* If the soft name exists then update it using the service params */
354 if (vport
->phba
->cfg_soft_wwnn
)
355 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
356 vport
->fc_sparam
.nodeName
.u
.wwn
);
357 if (vport
->phba
->cfg_soft_wwpn
)
358 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
359 vport
->fc_sparam
.portName
.u
.wwn
);
362 * If the name is empty or there exists a soft name
363 * then copy the service params name, otherwise use the fc name
365 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
366 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
367 sizeof(struct lpfc_name
));
369 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
370 sizeof(struct lpfc_name
));
373 * If the port name has changed, then set the Param changes flag
376 if (vport
->fc_portname
.u
.wwn
[0] != 0 &&
377 memcmp(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
378 sizeof(struct lpfc_name
)))
379 vport
->vport_flag
|= FAWWPN_PARAM_CHG
;
381 if (vport
->fc_portname
.u
.wwn
[0] == 0 ||
382 vport
->phba
->cfg_soft_wwpn
||
383 (vvvl
== 1 && cpu_to_be32(*fawwpn_key
) == FAPWWN_KEY_VENDOR
) ||
384 vport
->vport_flag
& FAWWPN_SET
) {
385 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
386 sizeof(struct lpfc_name
));
387 vport
->vport_flag
&= ~FAWWPN_SET
;
388 if (vvvl
== 1 && cpu_to_be32(*fawwpn_key
) == FAPWWN_KEY_VENDOR
)
389 vport
->vport_flag
|= FAWWPN_SET
;
392 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
393 sizeof(struct lpfc_name
));
397 * lpfc_config_port_post - Perform lpfc initialization after config port
398 * @phba: pointer to lpfc hba data structure.
400 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
401 * command call. It performs all internal resource and state setups on the
402 * port: post IOCB buffers, enable appropriate host interrupt attentions,
403 * ELS ring timers, etc.
407 * Any other value - error.
410 lpfc_config_port_post(struct lpfc_hba
*phba
)
412 struct lpfc_vport
*vport
= phba
->pport
;
413 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
416 struct lpfc_dmabuf
*mp
;
417 struct lpfc_sli
*psli
= &phba
->sli
;
418 uint32_t status
, timeout
;
422 spin_lock_irq(&phba
->hbalock
);
424 * If the Config port completed correctly the HBA is not
425 * over heated any more.
427 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
428 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
429 spin_unlock_irq(&phba
->hbalock
);
431 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
433 phba
->link_state
= LPFC_HBA_ERROR
;
438 /* Get login parameters for NID. */
439 rc
= lpfc_read_sparam(phba
, pmb
, 0);
441 mempool_free(pmb
, phba
->mbox_mem_pool
);
446 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
447 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
448 "0448 Adapter failed init, mbxCmd x%x "
449 "READ_SPARM mbxStatus x%x\n",
450 mb
->mbxCommand
, mb
->mbxStatus
);
451 phba
->link_state
= LPFC_HBA_ERROR
;
452 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
453 mempool_free(pmb
, phba
->mbox_mem_pool
);
454 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
459 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
461 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
462 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
465 lpfc_update_vport_wwn(vport
);
467 /* Update the fc_host data structures with new wwn. */
468 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
469 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
470 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
472 /* If no serial number in VPD data, use low 6 bytes of WWNN */
473 /* This should be consolidated into parse_vpd ? - mr */
474 if (phba
->SerialNumber
[0] == 0) {
477 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
478 for (i
= 0; i
< 12; i
++) {
480 j
= ((status
& 0xf0) >> 4);
482 phba
->SerialNumber
[i
] =
483 (char)((uint8_t) 0x30 + (uint8_t) j
);
485 phba
->SerialNumber
[i
] =
486 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
490 phba
->SerialNumber
[i
] =
491 (char)((uint8_t) 0x30 + (uint8_t) j
);
493 phba
->SerialNumber
[i
] =
494 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
498 lpfc_read_config(phba
, pmb
);
500 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
501 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
502 "0453 Adapter failed to init, mbxCmd x%x "
503 "READ_CONFIG, mbxStatus x%x\n",
504 mb
->mbxCommand
, mb
->mbxStatus
);
505 phba
->link_state
= LPFC_HBA_ERROR
;
506 mempool_free( pmb
, phba
->mbox_mem_pool
);
510 /* Check if the port is disabled */
511 lpfc_sli_read_link_ste(phba
);
513 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
514 if (phba
->cfg_hba_queue_depth
> mb
->un
.varRdConfig
.max_xri
) {
515 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
516 "3359 HBA queue depth changed from %d to %d\n",
517 phba
->cfg_hba_queue_depth
,
518 mb
->un
.varRdConfig
.max_xri
);
519 phba
->cfg_hba_queue_depth
= mb
->un
.varRdConfig
.max_xri
;
522 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
524 /* Get the default values for Model Name and Description */
525 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
527 phba
->link_state
= LPFC_LINK_DOWN
;
529 /* Only process IOCBs on ELS ring till hba_state is READY */
530 if (psli
->sli3_ring
[LPFC_EXTRA_RING
].sli
.sli3
.cmdringaddr
)
531 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
532 if (psli
->sli3_ring
[LPFC_FCP_RING
].sli
.sli3
.cmdringaddr
)
533 psli
->sli3_ring
[LPFC_FCP_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
535 /* Post receive buffers for desired rings */
536 if (phba
->sli_rev
!= 3)
537 lpfc_post_rcv_buf(phba
);
540 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
542 if (phba
->intr_type
== MSIX
) {
543 rc
= lpfc_config_msi(phba
, pmb
);
545 mempool_free(pmb
, phba
->mbox_mem_pool
);
548 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
549 if (rc
!= MBX_SUCCESS
) {
550 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
551 "0352 Config MSI mailbox command "
552 "failed, mbxCmd x%x, mbxStatus x%x\n",
553 pmb
->u
.mb
.mbxCommand
,
554 pmb
->u
.mb
.mbxStatus
);
555 mempool_free(pmb
, phba
->mbox_mem_pool
);
560 spin_lock_irq(&phba
->hbalock
);
561 /* Initialize ERATT handling flag */
562 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
564 /* Enable appropriate host interrupts */
565 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
566 spin_unlock_irq(&phba
->hbalock
);
569 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
570 if (psli
->num_rings
> 0)
571 status
|= HC_R0INT_ENA
;
572 if (psli
->num_rings
> 1)
573 status
|= HC_R1INT_ENA
;
574 if (psli
->num_rings
> 2)
575 status
|= HC_R2INT_ENA
;
576 if (psli
->num_rings
> 3)
577 status
|= HC_R3INT_ENA
;
579 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
580 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
581 status
&= ~(HC_R0INT_ENA
);
583 writel(status
, phba
->HCregaddr
);
584 readl(phba
->HCregaddr
); /* flush */
585 spin_unlock_irq(&phba
->hbalock
);
587 /* Set up ring-0 (ELS) timer */
588 timeout
= phba
->fc_ratov
* 2;
589 mod_timer(&vport
->els_tmofunc
,
590 jiffies
+ msecs_to_jiffies(1000 * timeout
));
591 /* Set up heart beat (HB) timer */
592 mod_timer(&phba
->hb_tmofunc
,
593 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
594 phba
->hb_outstanding
= 0;
595 phba
->last_completion_time
= jiffies
;
596 /* Set up error attention (ERATT) polling timer */
597 mod_timer(&phba
->eratt_poll
,
598 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
600 if (phba
->hba_flag
& LINK_DISABLED
) {
601 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
602 "2598 Adapter Link is disabled.\n");
603 lpfc_down_link(phba
, pmb
);
604 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
605 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
606 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
607 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
608 "2599 Adapter failed to issue DOWN_LINK"
609 " mbox command rc 0x%x\n", rc
);
611 mempool_free(pmb
, phba
->mbox_mem_pool
);
614 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
615 mempool_free(pmb
, phba
->mbox_mem_pool
);
616 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
620 /* MBOX buffer will be freed in mbox compl */
621 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
623 phba
->link_state
= LPFC_HBA_ERROR
;
627 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
628 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
629 pmb
->vport
= phba
->pport
;
630 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
632 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
633 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
634 "0456 Adapter failed to issue "
635 "ASYNCEVT_ENABLE mbox status x%x\n",
637 mempool_free(pmb
, phba
->mbox_mem_pool
);
640 /* Get Option rom version */
641 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
643 phba
->link_state
= LPFC_HBA_ERROR
;
647 lpfc_dump_wakeup_param(phba
, pmb
);
648 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
649 pmb
->vport
= phba
->pport
;
650 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
652 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
653 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
654 "0435 Adapter failed "
655 "to get Option ROM version status x%x\n", rc
);
656 mempool_free(pmb
, phba
->mbox_mem_pool
);
663 * lpfc_hba_init_link - Initialize the FC link
664 * @phba: pointer to lpfc hba data structure.
665 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
667 * This routine will issue the INIT_LINK mailbox command call.
668 * It is available to other drivers through the lpfc_hba data
669 * structure for use as a delayed link up mechanism with the
670 * module parameter lpfc_suppress_link_up.
674 * Any other value - error
677 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
679 return lpfc_hba_init_link_fc_topology(phba
, phba
->cfg_topology
, flag
);
683 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
684 * @phba: pointer to lpfc hba data structure.
685 * @fc_topology: desired fc topology.
686 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
688 * This routine will issue the INIT_LINK mailbox command call.
689 * It is available to other drivers through the lpfc_hba data
690 * structure for use as a delayed link up mechanism with the
691 * module parameter lpfc_suppress_link_up.
695 * Any other value - error
698 lpfc_hba_init_link_fc_topology(struct lpfc_hba
*phba
, uint32_t fc_topology
,
701 struct lpfc_vport
*vport
= phba
->pport
;
706 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
708 phba
->link_state
= LPFC_HBA_ERROR
;
714 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_MAX
) ||
715 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
) &&
716 !(phba
->lmt
& LMT_1Gb
)) ||
717 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
) &&
718 !(phba
->lmt
& LMT_2Gb
)) ||
719 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
) &&
720 !(phba
->lmt
& LMT_4Gb
)) ||
721 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
) &&
722 !(phba
->lmt
& LMT_8Gb
)) ||
723 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
) &&
724 !(phba
->lmt
& LMT_10Gb
)) ||
725 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
) &&
726 !(phba
->lmt
& LMT_16Gb
)) ||
727 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_32G
) &&
728 !(phba
->lmt
& LMT_32Gb
)) ||
729 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_64G
) &&
730 !(phba
->lmt
& LMT_64Gb
))) {
731 /* Reset link speed to auto */
732 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
733 "1302 Invalid speed for this board:%d "
734 "Reset link speed to auto.\n",
735 phba
->cfg_link_speed
);
736 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
738 lpfc_init_link(phba
, pmb
, fc_topology
, phba
->cfg_link_speed
);
739 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
740 if (phba
->sli_rev
< LPFC_SLI_REV4
)
741 lpfc_set_loopback_flag(phba
);
742 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
743 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
744 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
745 "0498 Adapter failed to init, mbxCmd x%x "
746 "INIT_LINK, mbxStatus x%x\n",
747 mb
->mbxCommand
, mb
->mbxStatus
);
748 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
749 /* Clear all interrupt enable conditions */
750 writel(0, phba
->HCregaddr
);
751 readl(phba
->HCregaddr
); /* flush */
752 /* Clear all pending interrupts */
753 writel(0xffffffff, phba
->HAregaddr
);
754 readl(phba
->HAregaddr
); /* flush */
756 phba
->link_state
= LPFC_HBA_ERROR
;
757 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
758 mempool_free(pmb
, phba
->mbox_mem_pool
);
761 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
762 if (flag
== MBX_POLL
)
763 mempool_free(pmb
, phba
->mbox_mem_pool
);
769 * lpfc_hba_down_link - this routine downs the FC link
770 * @phba: pointer to lpfc hba data structure.
771 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
773 * This routine will issue the DOWN_LINK mailbox command call.
774 * It is available to other drivers through the lpfc_hba data
775 * structure for use to stop the link.
779 * Any other value - error
782 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
787 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
789 phba
->link_state
= LPFC_HBA_ERROR
;
793 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
794 "0491 Adapter Link is disabled.\n");
795 lpfc_down_link(phba
, pmb
);
796 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
797 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
798 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
799 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
800 "2522 Adapter failed to issue DOWN_LINK"
801 " mbox command rc 0x%x\n", rc
);
803 mempool_free(pmb
, phba
->mbox_mem_pool
);
806 if (flag
== MBX_POLL
)
807 mempool_free(pmb
, phba
->mbox_mem_pool
);
813 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
814 * @phba: pointer to lpfc HBA data structure.
816 * This routine will do LPFC uninitialization before the HBA is reset when
817 * bringing down the SLI Layer.
821 * Any other value - error.
824 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
826 struct lpfc_vport
**vports
;
829 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
830 /* Disable interrupts */
831 writel(0, phba
->HCregaddr
);
832 readl(phba
->HCregaddr
); /* flush */
835 if (phba
->pport
->load_flag
& FC_UNLOADING
)
836 lpfc_cleanup_discovery_resources(phba
->pport
);
838 vports
= lpfc_create_vport_work_array(phba
);
840 for (i
= 0; i
<= phba
->max_vports
&&
841 vports
[i
] != NULL
; i
++)
842 lpfc_cleanup_discovery_resources(vports
[i
]);
843 lpfc_destroy_vport_work_array(phba
, vports
);
849 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
850 * rspiocb which got deferred
852 * @phba: pointer to lpfc HBA data structure.
854 * This routine will cleanup completed slow path events after HBA is reset
855 * when bringing down the SLI Layer.
862 lpfc_sli4_free_sp_events(struct lpfc_hba
*phba
)
864 struct lpfc_iocbq
*rspiocbq
;
865 struct hbq_dmabuf
*dmabuf
;
866 struct lpfc_cq_event
*cq_event
;
868 spin_lock_irq(&phba
->hbalock
);
869 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
870 spin_unlock_irq(&phba
->hbalock
);
872 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
873 /* Get the response iocb from the head of work queue */
874 spin_lock_irq(&phba
->hbalock
);
875 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
876 cq_event
, struct lpfc_cq_event
, list
);
877 spin_unlock_irq(&phba
->hbalock
);
879 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
880 case CQE_CODE_COMPL_WQE
:
881 rspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
883 lpfc_sli_release_iocbq(phba
, rspiocbq
);
885 case CQE_CODE_RECEIVE
:
886 case CQE_CODE_RECEIVE_V1
:
887 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
889 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
895 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
896 * @phba: pointer to lpfc HBA data structure.
898 * This routine will cleanup posted ELS buffers after the HBA is reset
899 * when bringing down the SLI Layer.
906 lpfc_hba_free_post_buf(struct lpfc_hba
*phba
)
908 struct lpfc_sli
*psli
= &phba
->sli
;
909 struct lpfc_sli_ring
*pring
;
910 struct lpfc_dmabuf
*mp
, *next_mp
;
914 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
915 lpfc_sli_hbqbuf_free_all(phba
);
917 /* Cleanup preposted buffers on the ELS ring */
918 pring
= &psli
->sli3_ring
[LPFC_ELS_RING
];
919 spin_lock_irq(&phba
->hbalock
);
920 list_splice_init(&pring
->postbufq
, &buflist
);
921 spin_unlock_irq(&phba
->hbalock
);
924 list_for_each_entry_safe(mp
, next_mp
, &buflist
, list
) {
927 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
931 spin_lock_irq(&phba
->hbalock
);
932 pring
->postbufq_cnt
-= count
;
933 spin_unlock_irq(&phba
->hbalock
);
938 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
939 * @phba: pointer to lpfc HBA data structure.
941 * This routine will cleanup the txcmplq after the HBA is reset when bringing
942 * down the SLI Layer.
948 lpfc_hba_clean_txcmplq(struct lpfc_hba
*phba
)
950 struct lpfc_sli
*psli
= &phba
->sli
;
951 struct lpfc_queue
*qp
= NULL
;
952 struct lpfc_sli_ring
*pring
;
953 LIST_HEAD(completions
);
955 struct lpfc_iocbq
*piocb
, *next_iocb
;
957 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
958 for (i
= 0; i
< psli
->num_rings
; i
++) {
959 pring
= &psli
->sli3_ring
[i
];
960 spin_lock_irq(&phba
->hbalock
);
961 /* At this point in time the HBA is either reset or DOA
962 * Nothing should be on txcmplq as it will
965 list_splice_init(&pring
->txcmplq
, &completions
);
966 pring
->txcmplq_cnt
= 0;
967 spin_unlock_irq(&phba
->hbalock
);
969 lpfc_sli_abort_iocb_ring(phba
, pring
);
971 /* Cancel all the IOCBs from the completions list */
972 lpfc_sli_cancel_iocbs(phba
, &completions
,
973 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
976 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
980 spin_lock_irq(&pring
->ring_lock
);
981 list_for_each_entry_safe(piocb
, next_iocb
,
982 &pring
->txcmplq
, list
)
983 piocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
984 list_splice_init(&pring
->txcmplq
, &completions
);
985 pring
->txcmplq_cnt
= 0;
986 spin_unlock_irq(&pring
->ring_lock
);
987 lpfc_sli_abort_iocb_ring(phba
, pring
);
989 /* Cancel all the IOCBs from the completions list */
990 lpfc_sli_cancel_iocbs(phba
, &completions
,
991 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
995 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
996 * @phba: pointer to lpfc HBA data structure.
998 * This routine will do uninitialization after the HBA is reset when bring
999 * down the SLI Layer.
1003 * Any other value - error.
1006 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
1008 lpfc_hba_free_post_buf(phba
);
1009 lpfc_hba_clean_txcmplq(phba
);
1014 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1015 * @phba: pointer to lpfc HBA data structure.
1017 * This routine will do uninitialization after the HBA is reset when bring
1018 * down the SLI Layer.
1022 * Any other value - error.
1025 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
1027 struct lpfc_io_buf
*psb
, *psb_next
;
1028 struct lpfc_async_xchg_ctx
*ctxp
, *ctxp_next
;
1029 struct lpfc_sli4_hdw_queue
*qp
;
1031 LIST_HEAD(nvme_aborts
);
1032 LIST_HEAD(nvmet_aborts
);
1033 struct lpfc_sglq
*sglq_entry
= NULL
;
1037 lpfc_sli_hbqbuf_free_all(phba
);
1038 lpfc_hba_clean_txcmplq(phba
);
1040 /* At this point in time the HBA is either reset or DOA. Either
1041 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1042 * on the lpfc_els_sgl_list so that it can either be freed if the
1043 * driver is unloading or reposted if the driver is restarting
1046 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_els_sgl_list and */
1048 /* sgl_list_lock required because worker thread uses this
1051 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
1052 list_for_each_entry(sglq_entry
,
1053 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
1054 sglq_entry
->state
= SGL_FREED
;
1056 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
1057 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1060 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
1062 /* abts_xxxx_buf_list_lock required because worker thread uses this
1066 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
1067 qp
= &phba
->sli4_hba
.hdwq
[idx
];
1069 spin_lock(&qp
->abts_io_buf_list_lock
);
1070 list_splice_init(&qp
->lpfc_abts_io_buf_list
,
1073 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
1075 psb
->status
= IOSTAT_SUCCESS
;
1078 spin_lock(&qp
->io_buf_list_put_lock
);
1079 list_splice_init(&aborts
, &qp
->lpfc_io_buf_list_put
);
1080 qp
->put_io_bufs
+= qp
->abts_scsi_io_bufs
;
1081 qp
->put_io_bufs
+= qp
->abts_nvme_io_bufs
;
1082 qp
->abts_scsi_io_bufs
= 0;
1083 qp
->abts_nvme_io_bufs
= 0;
1084 spin_unlock(&qp
->io_buf_list_put_lock
);
1085 spin_unlock(&qp
->abts_io_buf_list_lock
);
1087 spin_unlock_irq(&phba
->hbalock
);
1089 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
1090 spin_lock_irq(&phba
->sli4_hba
.abts_nvmet_buf_list_lock
);
1091 list_splice_init(&phba
->sli4_hba
.lpfc_abts_nvmet_ctx_list
,
1093 spin_unlock_irq(&phba
->sli4_hba
.abts_nvmet_buf_list_lock
);
1094 list_for_each_entry_safe(ctxp
, ctxp_next
, &nvmet_aborts
, list
) {
1095 ctxp
->flag
&= ~(LPFC_NVME_XBUSY
| LPFC_NVME_ABORT_OP
);
1096 lpfc_nvmet_ctxbuf_post(phba
, ctxp
->ctxbuf
);
1100 lpfc_sli4_free_sp_events(phba
);
1105 * lpfc_hba_down_post - Wrapper func for hba down post routine
1106 * @phba: pointer to lpfc HBA data structure.
1108 * This routine wraps the actual SLI3 or SLI4 routine for performing
1109 * uninitialization after the HBA is reset when bring down the SLI Layer.
1113 * Any other value - error.
1116 lpfc_hba_down_post(struct lpfc_hba
*phba
)
1118 return (*phba
->lpfc_hba_down_post
)(phba
);
1122 * lpfc_hb_timeout - The HBA-timer timeout handler
1123 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1125 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1126 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1127 * work-port-events bitmap and the worker thread is notified. This timeout
1128 * event will be used by the worker thread to invoke the actual timeout
1129 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1130 * be performed in the timeout handler and the HBA timeout event bit shall
1131 * be cleared by the worker thread after it has taken the event bitmap out.
1134 lpfc_hb_timeout(struct timer_list
*t
)
1136 struct lpfc_hba
*phba
;
1137 uint32_t tmo_posted
;
1138 unsigned long iflag
;
1140 phba
= from_timer(phba
, t
, hb_tmofunc
);
1142 /* Check for heart beat timeout conditions */
1143 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1144 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
1146 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
1147 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1149 /* Tell the worker thread there is work to do */
1151 lpfc_worker_wake_up(phba
);
1156 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1157 * @t: timer context used to obtain the pointer to lpfc hba data structure.
1159 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1160 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1161 * work-port-events bitmap and the worker thread is notified. This timeout
1162 * event will be used by the worker thread to invoke the actual timeout
1163 * handler routine, lpfc_rrq_handler. Any periodical operations will
1164 * be performed in the timeout handler and the RRQ timeout event bit shall
1165 * be cleared by the worker thread after it has taken the event bitmap out.
1168 lpfc_rrq_timeout(struct timer_list
*t
)
1170 struct lpfc_hba
*phba
;
1171 unsigned long iflag
;
1173 phba
= from_timer(phba
, t
, rrq_tmr
);
1174 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1175 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1176 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
1178 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
1179 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1181 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1182 lpfc_worker_wake_up(phba
);
1186 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1187 * @phba: pointer to lpfc hba data structure.
1188 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1190 * This is the callback function to the lpfc heart-beat mailbox command.
1191 * If configured, the lpfc driver issues the heart-beat mailbox command to
1192 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1193 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1194 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1195 * heart-beat outstanding state. Once the mailbox command comes back and
1196 * no error conditions detected, the heart-beat mailbox command timer is
1197 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1198 * state is cleared for the next heart-beat. If the timer expired with the
1199 * heart-beat outstanding state set, the driver will put the HBA offline.
1202 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1204 unsigned long drvr_flag
;
1206 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1207 phba
->hb_outstanding
= 0;
1208 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1210 /* Check and reset heart-beat timer is necessary */
1211 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1212 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1213 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1214 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1215 mod_timer(&phba
->hb_tmofunc
,
1217 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1222 * lpfc_idle_stat_delay_work - idle_stat tracking
1224 * This routine tracks per-cq idle_stat and determines polling decisions.
1230 lpfc_idle_stat_delay_work(struct work_struct
*work
)
1232 struct lpfc_hba
*phba
= container_of(to_delayed_work(work
),
1234 idle_stat_delay_work
);
1235 struct lpfc_queue
*cq
;
1236 struct lpfc_sli4_hdw_queue
*hdwq
;
1237 struct lpfc_idle_stat
*idle_stat
;
1238 u32 i
, idle_percent
;
1239 u64 wall
, wall_idle
, diff_wall
, diff_idle
, busy_time
;
1241 if (phba
->pport
->load_flag
& FC_UNLOADING
)
1244 if (phba
->link_state
== LPFC_HBA_ERROR
||
1245 phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1248 for_each_present_cpu(i
) {
1249 hdwq
= &phba
->sli4_hba
.hdwq
[phba
->sli4_hba
.cpu_map
[i
].hdwq
];
1252 /* Skip if we've already handled this cq's primary CPU */
1256 idle_stat
= &phba
->sli4_hba
.idle_stat
[i
];
1258 /* get_cpu_idle_time returns values as running counters. Thus,
1259 * to know the amount for this period, the prior counter values
1260 * need to be subtracted from the current counter values.
1261 * From there, the idle time stat can be calculated as a
1262 * percentage of 100 - the sum of the other consumption times.
1264 wall_idle
= get_cpu_idle_time(i
, &wall
, 1);
1265 diff_idle
= wall_idle
- idle_stat
->prev_idle
;
1266 diff_wall
= wall
- idle_stat
->prev_wall
;
1268 if (diff_wall
<= diff_idle
)
1271 busy_time
= diff_wall
- diff_idle
;
1273 idle_percent
= div64_u64(100 * busy_time
, diff_wall
);
1274 idle_percent
= 100 - idle_percent
;
1276 if (idle_percent
< 15)
1277 cq
->poll_mode
= LPFC_QUEUE_WORK
;
1279 cq
->poll_mode
= LPFC_IRQ_POLL
;
1281 idle_stat
->prev_idle
= wall_idle
;
1282 idle_stat
->prev_wall
= wall
;
1286 schedule_delayed_work(&phba
->idle_stat_delay_work
,
1287 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY
));
1291 lpfc_hb_eq_delay_work(struct work_struct
*work
)
1293 struct lpfc_hba
*phba
= container_of(to_delayed_work(work
),
1294 struct lpfc_hba
, eq_delay_work
);
1295 struct lpfc_eq_intr_info
*eqi
, *eqi_new
;
1296 struct lpfc_queue
*eq
, *eq_next
;
1297 unsigned char *ena_delay
= NULL
;
1301 if (!phba
->cfg_auto_imax
|| phba
->pport
->load_flag
& FC_UNLOADING
)
1304 if (phba
->link_state
== LPFC_HBA_ERROR
||
1305 phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1308 ena_delay
= kcalloc(phba
->sli4_hba
.num_possible_cpu
, sizeof(*ena_delay
),
1313 for (i
= 0; i
< phba
->cfg_irq_chann
; i
++) {
1314 /* Get the EQ corresponding to the IRQ vector */
1315 eq
= phba
->sli4_hba
.hba_eq_hdl
[i
].eq
;
1318 if (eq
->q_mode
|| eq
->q_flag
& HBA_EQ_DELAY_CHK
) {
1319 eq
->q_flag
&= ~HBA_EQ_DELAY_CHK
;
1320 ena_delay
[eq
->last_cpu
] = 1;
1324 for_each_present_cpu(i
) {
1325 eqi
= per_cpu_ptr(phba
->sli4_hba
.eq_info
, i
);
1327 usdelay
= (eqi
->icnt
>> 10) * LPFC_EQ_DELAY_STEP
;
1328 if (usdelay
> LPFC_MAX_AUTO_EQ_DELAY
)
1329 usdelay
= LPFC_MAX_AUTO_EQ_DELAY
;
1336 list_for_each_entry_safe(eq
, eq_next
, &eqi
->list
, cpu_list
) {
1337 if (unlikely(eq
->last_cpu
!= i
)) {
1338 eqi_new
= per_cpu_ptr(phba
->sli4_hba
.eq_info
,
1340 list_move_tail(&eq
->cpu_list
, &eqi_new
->list
);
1343 if (usdelay
!= eq
->q_mode
)
1344 lpfc_modify_hba_eq_delay(phba
, eq
->hdwq
, 1,
1352 queue_delayed_work(phba
->wq
, &phba
->eq_delay_work
,
1353 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS
));
1357 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1358 * @phba: pointer to lpfc hba data structure.
1360 * For each heartbeat, this routine does some heuristic methods to adjust
1361 * XRI distribution. The goal is to fully utilize free XRIs.
1363 static void lpfc_hb_mxp_handler(struct lpfc_hba
*phba
)
1368 hwq_count
= phba
->cfg_hdw_queue
;
1369 for (i
= 0; i
< hwq_count
; i
++) {
1370 /* Adjust XRIs in private pool */
1371 lpfc_adjust_pvt_pool_count(phba
, i
);
1373 /* Adjust high watermark */
1374 lpfc_adjust_high_watermark(phba
, i
);
1376 #ifdef LPFC_MXP_STAT
1377 /* Snapshot pbl, pvt and busy count */
1378 lpfc_snapshot_mxp(phba
, i
);
1384 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1385 * @phba: pointer to lpfc hba data structure.
1387 * This is the actual HBA-timer timeout handler to be invoked by the worker
1388 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1389 * handler performs any periodic operations needed for the device. If such
1390 * periodic event has already been attended to either in the interrupt handler
1391 * or by processing slow-ring or fast-ring events within the HBA-timer
1392 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1393 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1394 * is configured and there is no heart-beat mailbox command outstanding, a
1395 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1396 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1400 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1402 struct lpfc_vport
**vports
;
1403 LPFC_MBOXQ_t
*pmboxq
;
1404 struct lpfc_dmabuf
*buf_ptr
;
1406 struct lpfc_sli
*psli
= &phba
->sli
;
1407 LIST_HEAD(completions
);
1409 if (phba
->cfg_xri_rebalancing
) {
1410 /* Multi-XRI pools handler */
1411 lpfc_hb_mxp_handler(phba
);
1414 vports
= lpfc_create_vport_work_array(phba
);
1416 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
1417 lpfc_rcv_seq_check_edtov(vports
[i
]);
1418 lpfc_fdmi_change_check(vports
[i
]);
1420 lpfc_destroy_vport_work_array(phba
, vports
);
1422 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1423 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1424 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1427 spin_lock_irq(&phba
->pport
->work_port_lock
);
1429 if (time_after(phba
->last_completion_time
+
1430 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
),
1432 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1433 if (!phba
->hb_outstanding
)
1434 mod_timer(&phba
->hb_tmofunc
,
1436 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1438 mod_timer(&phba
->hb_tmofunc
,
1440 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1443 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1445 if (phba
->elsbuf_cnt
&&
1446 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1447 spin_lock_irq(&phba
->hbalock
);
1448 list_splice_init(&phba
->elsbuf
, &completions
);
1449 phba
->elsbuf_cnt
= 0;
1450 phba
->elsbuf_prev_cnt
= 0;
1451 spin_unlock_irq(&phba
->hbalock
);
1453 while (!list_empty(&completions
)) {
1454 list_remove_head(&completions
, buf_ptr
,
1455 struct lpfc_dmabuf
, list
);
1456 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1460 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1462 /* If there is no heart beat outstanding, issue a heartbeat command */
1463 if (phba
->cfg_enable_hba_heartbeat
) {
1464 if (!phba
->hb_outstanding
) {
1465 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1466 (list_empty(&psli
->mboxq
))) {
1467 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1470 mod_timer(&phba
->hb_tmofunc
,
1472 msecs_to_jiffies(1000 *
1473 LPFC_HB_MBOX_INTERVAL
));
1477 lpfc_heart_beat(phba
, pmboxq
);
1478 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1479 pmboxq
->vport
= phba
->pport
;
1480 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1483 if (retval
!= MBX_BUSY
&&
1484 retval
!= MBX_SUCCESS
) {
1485 mempool_free(pmboxq
,
1486 phba
->mbox_mem_pool
);
1487 mod_timer(&phba
->hb_tmofunc
,
1489 msecs_to_jiffies(1000 *
1490 LPFC_HB_MBOX_INTERVAL
));
1493 phba
->skipped_hb
= 0;
1494 phba
->hb_outstanding
= 1;
1495 } else if (time_before_eq(phba
->last_completion_time
,
1496 phba
->skipped_hb
)) {
1497 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1498 "2857 Last completion time not "
1499 " updated in %d ms\n",
1500 jiffies_to_msecs(jiffies
1501 - phba
->last_completion_time
));
1503 phba
->skipped_hb
= jiffies
;
1505 mod_timer(&phba
->hb_tmofunc
,
1507 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1511 * If heart beat timeout called with hb_outstanding set
1512 * we need to give the hb mailbox cmd a chance to
1515 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1516 "0459 Adapter heartbeat still out"
1517 "standing:last compl time was %d ms.\n",
1518 jiffies_to_msecs(jiffies
1519 - phba
->last_completion_time
));
1520 mod_timer(&phba
->hb_tmofunc
,
1522 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1525 mod_timer(&phba
->hb_tmofunc
,
1527 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1532 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1533 * @phba: pointer to lpfc hba data structure.
1535 * This routine is called to bring the HBA offline when HBA hardware error
1536 * other than Port Error 6 has been detected.
1539 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1541 struct lpfc_sli
*psli
= &phba
->sli
;
1543 spin_lock_irq(&phba
->hbalock
);
1544 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1545 spin_unlock_irq(&phba
->hbalock
);
1546 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1549 lpfc_reset_barrier(phba
);
1550 spin_lock_irq(&phba
->hbalock
);
1551 lpfc_sli_brdreset(phba
);
1552 spin_unlock_irq(&phba
->hbalock
);
1553 lpfc_hba_down_post(phba
);
1554 lpfc_sli_brdready(phba
, HS_MBRDY
);
1555 lpfc_unblock_mgmt_io(phba
);
1556 phba
->link_state
= LPFC_HBA_ERROR
;
1561 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1562 * @phba: pointer to lpfc hba data structure.
1564 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1565 * other than Port Error 6 has been detected.
1568 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1570 spin_lock_irq(&phba
->hbalock
);
1571 phba
->link_state
= LPFC_HBA_ERROR
;
1572 spin_unlock_irq(&phba
->hbalock
);
1574 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1575 lpfc_sli_flush_io_rings(phba
);
1577 lpfc_hba_down_post(phba
);
1578 lpfc_unblock_mgmt_io(phba
);
1582 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1583 * @phba: pointer to lpfc hba data structure.
1585 * This routine is invoked to handle the deferred HBA hardware error
1586 * conditions. This type of error is indicated by HBA by setting ER1
1587 * and another ER bit in the host status register. The driver will
1588 * wait until the ER1 bit clears before handling the error condition.
1591 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1593 uint32_t old_host_status
= phba
->work_hs
;
1594 struct lpfc_sli
*psli
= &phba
->sli
;
1596 /* If the pci channel is offline, ignore possible errors,
1597 * since we cannot communicate with the pci card anyway.
1599 if (pci_channel_offline(phba
->pcidev
)) {
1600 spin_lock_irq(&phba
->hbalock
);
1601 phba
->hba_flag
&= ~DEFER_ERATT
;
1602 spin_unlock_irq(&phba
->hbalock
);
1606 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1607 "0479 Deferred Adapter Hardware Error "
1608 "Data: x%x x%x x%x\n",
1609 phba
->work_hs
, phba
->work_status
[0],
1610 phba
->work_status
[1]);
1612 spin_lock_irq(&phba
->hbalock
);
1613 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1614 spin_unlock_irq(&phba
->hbalock
);
1618 * Firmware stops when it triggred erratt. That could cause the I/Os
1619 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1620 * SCSI layer retry it after re-establishing link.
1622 lpfc_sli_abort_fcp_rings(phba
);
1625 * There was a firmware error. Take the hba offline and then
1626 * attempt to restart it.
1628 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
1631 /* Wait for the ER1 bit to clear.*/
1632 while (phba
->work_hs
& HS_FFER1
) {
1634 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1635 phba
->work_hs
= UNPLUG_ERR
;
1638 /* If driver is unloading let the worker thread continue */
1639 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1646 * This is to ptrotect against a race condition in which
1647 * first write to the host attention register clear the
1648 * host status register.
1650 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1651 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1653 spin_lock_irq(&phba
->hbalock
);
1654 phba
->hba_flag
&= ~DEFER_ERATT
;
1655 spin_unlock_irq(&phba
->hbalock
);
1656 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1657 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1661 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1663 struct lpfc_board_event_header board_event
;
1664 struct Scsi_Host
*shost
;
1666 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1667 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1668 shost
= lpfc_shost_from_vport(phba
->pport
);
1669 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1670 sizeof(board_event
),
1671 (char *) &board_event
,
1676 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1677 * @phba: pointer to lpfc hba data structure.
1679 * This routine is invoked to handle the following HBA hardware error
1681 * 1 - HBA error attention interrupt
1682 * 2 - DMA ring index out of range
1683 * 3 - Mailbox command came back as unknown
1686 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1688 struct lpfc_vport
*vport
= phba
->pport
;
1689 struct lpfc_sli
*psli
= &phba
->sli
;
1690 uint32_t event_data
;
1691 unsigned long temperature
;
1692 struct temp_event temp_event_data
;
1693 struct Scsi_Host
*shost
;
1695 /* If the pci channel is offline, ignore possible errors,
1696 * since we cannot communicate with the pci card anyway.
1698 if (pci_channel_offline(phba
->pcidev
)) {
1699 spin_lock_irq(&phba
->hbalock
);
1700 phba
->hba_flag
&= ~DEFER_ERATT
;
1701 spin_unlock_irq(&phba
->hbalock
);
1705 /* If resets are disabled then leave the HBA alone and return */
1706 if (!phba
->cfg_enable_hba_reset
)
1709 /* Send an internal error event to mgmt application */
1710 lpfc_board_errevt_to_mgmt(phba
);
1712 if (phba
->hba_flag
& DEFER_ERATT
)
1713 lpfc_handle_deferred_eratt(phba
);
1715 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1716 if (phba
->work_hs
& HS_FFER6
)
1717 /* Re-establishing Link */
1718 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1719 "1301 Re-establishing Link "
1720 "Data: x%x x%x x%x\n",
1721 phba
->work_hs
, phba
->work_status
[0],
1722 phba
->work_status
[1]);
1723 if (phba
->work_hs
& HS_FFER8
)
1724 /* Device Zeroization */
1725 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1726 "2861 Host Authentication device "
1727 "zeroization Data:x%x x%x x%x\n",
1728 phba
->work_hs
, phba
->work_status
[0],
1729 phba
->work_status
[1]);
1731 spin_lock_irq(&phba
->hbalock
);
1732 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1733 spin_unlock_irq(&phba
->hbalock
);
1736 * Firmware stops when it triggled erratt with HS_FFER6.
1737 * That could cause the I/Os dropped by the firmware.
1738 * Error iocb (I/O) on txcmplq and let the SCSI layer
1739 * retry it after re-establishing link.
1741 lpfc_sli_abort_fcp_rings(phba
);
1744 * There was a firmware error. Take the hba offline and then
1745 * attempt to restart it.
1747 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1749 lpfc_sli_brdrestart(phba
);
1750 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1751 lpfc_unblock_mgmt_io(phba
);
1754 lpfc_unblock_mgmt_io(phba
);
1755 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1756 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1757 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1758 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1759 temp_event_data
.data
= (uint32_t)temperature
;
1761 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1762 "0406 Adapter maximum temperature exceeded "
1763 "(%ld), taking this port offline "
1764 "Data: x%x x%x x%x\n",
1765 temperature
, phba
->work_hs
,
1766 phba
->work_status
[0], phba
->work_status
[1]);
1768 shost
= lpfc_shost_from_vport(phba
->pport
);
1769 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1770 sizeof(temp_event_data
),
1771 (char *) &temp_event_data
,
1772 SCSI_NL_VID_TYPE_PCI
1773 | PCI_VENDOR_ID_EMULEX
);
1775 spin_lock_irq(&phba
->hbalock
);
1776 phba
->over_temp_state
= HBA_OVER_TEMP
;
1777 spin_unlock_irq(&phba
->hbalock
);
1778 lpfc_offline_eratt(phba
);
1781 /* The if clause above forces this code path when the status
1782 * failure is a value other than FFER6. Do not call the offline
1783 * twice. This is the adapter hardware error path.
1785 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1786 "0457 Adapter Hardware Error "
1787 "Data: x%x x%x x%x\n",
1789 phba
->work_status
[0], phba
->work_status
[1]);
1791 event_data
= FC_REG_DUMP_EVENT
;
1792 shost
= lpfc_shost_from_vport(vport
);
1793 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1794 sizeof(event_data
), (char *) &event_data
,
1795 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1797 lpfc_offline_eratt(phba
);
1803 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1804 * @phba: pointer to lpfc hba data structure.
1805 * @mbx_action: flag for mailbox shutdown action.
1806 * @en_rn_msg: send reset/port recovery message.
1807 * This routine is invoked to perform an SLI4 port PCI function reset in
1808 * response to port status register polling attention. It waits for port
1809 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1810 * During this process, interrupt vectors are freed and later requested
1811 * for handling possible port resource change.
1814 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba
*phba
, int mbx_action
,
1820 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) >=
1821 LPFC_SLI_INTF_IF_TYPE_2
) {
1823 * On error status condition, driver need to wait for port
1824 * ready before performing reset.
1826 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1831 /* need reset: attempt for port recovery */
1833 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1834 "2887 Reset Needed: Attempting Port "
1836 lpfc_offline_prep(phba
, mbx_action
);
1837 lpfc_sli_flush_io_rings(phba
);
1839 /* release interrupt for possible resource change */
1840 lpfc_sli4_disable_intr(phba
);
1841 rc
= lpfc_sli_brdrestart(phba
);
1843 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1844 "6309 Failed to restart board\n");
1847 /* request and enable interrupt */
1848 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
1849 if (intr_mode
== LPFC_INTR_ERROR
) {
1850 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1851 "3175 Failed to enable interrupt\n");
1854 phba
->intr_mode
= intr_mode
;
1855 rc
= lpfc_online(phba
);
1857 lpfc_unblock_mgmt_io(phba
);
1863 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1864 * @phba: pointer to lpfc hba data structure.
1866 * This routine is invoked to handle the SLI4 HBA hardware error attention
1870 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1872 struct lpfc_vport
*vport
= phba
->pport
;
1873 uint32_t event_data
;
1874 struct Scsi_Host
*shost
;
1876 struct lpfc_register portstat_reg
= {0};
1877 uint32_t reg_err1
, reg_err2
;
1878 uint32_t uerrlo_reg
, uemasklo_reg
;
1879 uint32_t smphr_port_status
= 0, pci_rd_rc1
, pci_rd_rc2
;
1880 bool en_rn_msg
= true;
1881 struct temp_event temp_event_data
;
1882 struct lpfc_register portsmphr_reg
;
1885 /* If the pci channel is offline, ignore possible errors, since
1886 * we cannot communicate with the pci card anyway.
1888 if (pci_channel_offline(phba
->pcidev
)) {
1889 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1890 "3166 pci channel is offline\n");
1891 lpfc_sli4_offline_eratt(phba
);
1895 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
1896 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1898 case LPFC_SLI_INTF_IF_TYPE_0
:
1899 pci_rd_rc1
= lpfc_readl(
1900 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
1902 pci_rd_rc2
= lpfc_readl(
1903 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
,
1905 /* consider PCI bus read error as pci_channel_offline */
1906 if (pci_rd_rc1
== -EIO
&& pci_rd_rc2
== -EIO
)
1908 if (!(phba
->hba_flag
& HBA_RECOVERABLE_UE
)) {
1909 lpfc_sli4_offline_eratt(phba
);
1912 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1913 "7623 Checking UE recoverable");
1915 for (i
= 0; i
< phba
->sli4_hba
.ue_to_sr
/ 1000; i
++) {
1916 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1917 &portsmphr_reg
.word0
))
1920 smphr_port_status
= bf_get(lpfc_port_smphr_port_status
,
1922 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1923 LPFC_PORT_SEM_UE_RECOVERABLE
)
1925 /*Sleep for 1Sec, before checking SEMAPHORE */
1929 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1930 "4827 smphr_port_status x%x : Waited %dSec",
1931 smphr_port_status
, i
);
1933 /* Recoverable UE, reset the HBA device */
1934 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1935 LPFC_PORT_SEM_UE_RECOVERABLE
) {
1936 for (i
= 0; i
< 20; i
++) {
1938 if (!lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1939 &portsmphr_reg
.word0
) &&
1940 (LPFC_POST_STAGE_PORT_READY
==
1941 bf_get(lpfc_port_smphr_port_status
,
1943 rc
= lpfc_sli4_port_sta_fn_reset(phba
,
1944 LPFC_MBX_NO_WAIT
, en_rn_msg
);
1947 lpfc_printf_log(phba
, KERN_ERR
,
1949 "4215 Failed to recover UE");
1954 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1955 "7624 Firmware not ready: Failing UE recovery,"
1956 " waited %dSec", i
);
1957 phba
->link_state
= LPFC_HBA_ERROR
;
1960 case LPFC_SLI_INTF_IF_TYPE_2
:
1961 case LPFC_SLI_INTF_IF_TYPE_6
:
1962 pci_rd_rc1
= lpfc_readl(
1963 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1964 &portstat_reg
.word0
);
1965 /* consider PCI bus read error as pci_channel_offline */
1966 if (pci_rd_rc1
== -EIO
) {
1967 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1968 "3151 PCI bus read access failure: x%x\n",
1969 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
));
1970 lpfc_sli4_offline_eratt(phba
);
1973 reg_err1
= readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
1974 reg_err2
= readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
1975 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1976 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1977 "2889 Port Overtemperature event, "
1978 "taking port offline Data: x%x x%x\n",
1979 reg_err1
, reg_err2
);
1981 phba
->sfp_alarm
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
1982 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1983 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1984 temp_event_data
.data
= 0xFFFFFFFF;
1986 shost
= lpfc_shost_from_vport(phba
->pport
);
1987 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1988 sizeof(temp_event_data
),
1989 (char *)&temp_event_data
,
1990 SCSI_NL_VID_TYPE_PCI
1991 | PCI_VENDOR_ID_EMULEX
);
1993 spin_lock_irq(&phba
->hbalock
);
1994 phba
->over_temp_state
= HBA_OVER_TEMP
;
1995 spin_unlock_irq(&phba
->hbalock
);
1996 lpfc_sli4_offline_eratt(phba
);
1999 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
2000 reg_err2
== SLIPORT_ERR2_REG_FW_RESTART
) {
2001 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2002 "3143 Port Down: Firmware Update "
2005 } else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
2006 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
2007 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2008 "3144 Port Down: Debug Dump\n");
2009 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
2010 reg_err2
== SLIPORT_ERR2_REG_FUNC_PROVISON
)
2011 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2012 "3145 Port Down: Provisioning\n");
2014 /* If resets are disabled then leave the HBA alone and return */
2015 if (!phba
->cfg_enable_hba_reset
)
2018 /* Check port status register for function reset */
2019 rc
= lpfc_sli4_port_sta_fn_reset(phba
, LPFC_MBX_NO_WAIT
,
2022 /* don't report event on forced debug dump */
2023 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
2024 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
2029 /* fall through for not able to recover */
2030 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2031 "3152 Unrecoverable error\n");
2032 phba
->link_state
= LPFC_HBA_ERROR
;
2034 case LPFC_SLI_INTF_IF_TYPE_1
:
2038 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2039 "3123 Report dump event to upper layer\n");
2040 /* Send an internal error event to mgmt application */
2041 lpfc_board_errevt_to_mgmt(phba
);
2043 event_data
= FC_REG_DUMP_EVENT
;
2044 shost
= lpfc_shost_from_vport(vport
);
2045 fc_host_post_vendor_event(shost
, fc_get_event_number(),
2046 sizeof(event_data
), (char *) &event_data
,
2047 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
2051 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2052 * @phba: pointer to lpfc HBA data structure.
2054 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2055 * routine from the API jump table function pointer from the lpfc_hba struct.
2059 * Any other value - error.
2062 lpfc_handle_eratt(struct lpfc_hba
*phba
)
2064 (*phba
->lpfc_handle_eratt
)(phba
);
2068 * lpfc_handle_latt - The HBA link event handler
2069 * @phba: pointer to lpfc hba data structure.
2071 * This routine is invoked from the worker thread to handle a HBA host
2072 * attention link event. SLI3 only.
2075 lpfc_handle_latt(struct lpfc_hba
*phba
)
2077 struct lpfc_vport
*vport
= phba
->pport
;
2078 struct lpfc_sli
*psli
= &phba
->sli
;
2080 volatile uint32_t control
;
2081 struct lpfc_dmabuf
*mp
;
2084 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2087 goto lpfc_handle_latt_err_exit
;
2090 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2093 goto lpfc_handle_latt_free_pmb
;
2096 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2099 goto lpfc_handle_latt_free_mp
;
2102 /* Cleanup any outstanding ELS commands */
2103 lpfc_els_flush_all_cmd(phba
);
2105 psli
->slistat
.link_event
++;
2106 lpfc_read_topology(phba
, pmb
, mp
);
2107 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
2109 /* Block ELS IOCBs until we have processed this mbox command */
2110 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
2111 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
2112 if (rc
== MBX_NOT_FINISHED
) {
2114 goto lpfc_handle_latt_free_mbuf
;
2117 /* Clear Link Attention in HA REG */
2118 spin_lock_irq(&phba
->hbalock
);
2119 writel(HA_LATT
, phba
->HAregaddr
);
2120 readl(phba
->HAregaddr
); /* flush */
2121 spin_unlock_irq(&phba
->hbalock
);
2125 lpfc_handle_latt_free_mbuf
:
2126 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2127 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2128 lpfc_handle_latt_free_mp
:
2130 lpfc_handle_latt_free_pmb
:
2131 mempool_free(pmb
, phba
->mbox_mem_pool
);
2132 lpfc_handle_latt_err_exit
:
2133 /* Enable Link attention interrupts */
2134 spin_lock_irq(&phba
->hbalock
);
2135 psli
->sli_flag
|= LPFC_PROCESS_LA
;
2136 control
= readl(phba
->HCregaddr
);
2137 control
|= HC_LAINT_ENA
;
2138 writel(control
, phba
->HCregaddr
);
2139 readl(phba
->HCregaddr
); /* flush */
2141 /* Clear Link Attention in HA REG */
2142 writel(HA_LATT
, phba
->HAregaddr
);
2143 readl(phba
->HAregaddr
); /* flush */
2144 spin_unlock_irq(&phba
->hbalock
);
2145 lpfc_linkdown(phba
);
2146 phba
->link_state
= LPFC_HBA_ERROR
;
2148 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2149 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
2155 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
2156 * @phba: pointer to lpfc hba data structure.
2157 * @vpd: pointer to the vital product data.
2158 * @len: length of the vital product data in bytes.
2160 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2161 * an array of characters. In this routine, the ModelName, ProgramType, and
2162 * ModelDesc, etc. fields of the phba data structure will be populated.
2165 * 0 - pointer to the VPD passed in is NULL
2169 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
2171 uint8_t lenlo
, lenhi
;
2181 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2182 "0455 Vital Product Data: x%x x%x x%x x%x\n",
2183 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
2185 while (!finished
&& (index
< (len
- 4))) {
2186 switch (vpd
[index
]) {
2194 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
2203 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
2204 if (Length
> len
- index
)
2205 Length
= len
- index
;
2206 while (Length
> 0) {
2207 /* Look for Serial Number */
2208 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
2215 phba
->SerialNumber
[j
++] = vpd
[index
++];
2219 phba
->SerialNumber
[j
] = 0;
2222 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
2223 phba
->vpd_flag
|= VPD_MODEL_DESC
;
2230 phba
->ModelDesc
[j
++] = vpd
[index
++];
2234 phba
->ModelDesc
[j
] = 0;
2237 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
2238 phba
->vpd_flag
|= VPD_MODEL_NAME
;
2245 phba
->ModelName
[j
++] = vpd
[index
++];
2249 phba
->ModelName
[j
] = 0;
2252 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
2253 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
2260 phba
->ProgramType
[j
++] = vpd
[index
++];
2264 phba
->ProgramType
[j
] = 0;
2267 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
2268 phba
->vpd_flag
|= VPD_PORT
;
2275 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
2276 (phba
->sli4_hba
.pport_name_sta
==
2277 LPFC_SLI4_PPNAME_GET
)) {
2281 phba
->Port
[j
++] = vpd
[index
++];
2285 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
2286 (phba
->sli4_hba
.pport_name_sta
==
2287 LPFC_SLI4_PPNAME_NON
))
2314 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2315 * @phba: pointer to lpfc hba data structure.
2316 * @mdp: pointer to the data structure to hold the derived model name.
2317 * @descp: pointer to the data structure to hold the derived description.
2319 * This routine retrieves HBA's description based on its registered PCI device
2320 * ID. The @descp passed into this function points to an array of 256 chars. It
2321 * shall be returned with the model name, maximum speed, and the host bus type.
2322 * The @mdp passed into this function points to an array of 80 chars. When the
2323 * function returns, the @mdp will be filled with the model name.
2326 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
2329 uint16_t dev_id
= phba
->pcidev
->device
;
2332 int oneConnect
= 0; /* default is not a oneConnect */
2337 } m
= {"<Unknown>", "", ""};
2339 if (mdp
&& mdp
[0] != '\0'
2340 && descp
&& descp
[0] != '\0')
2343 if (phba
->lmt
& LMT_64Gb
)
2345 else if (phba
->lmt
& LMT_32Gb
)
2347 else if (phba
->lmt
& LMT_16Gb
)
2349 else if (phba
->lmt
& LMT_10Gb
)
2351 else if (phba
->lmt
& LMT_8Gb
)
2353 else if (phba
->lmt
& LMT_4Gb
)
2355 else if (phba
->lmt
& LMT_2Gb
)
2357 else if (phba
->lmt
& LMT_1Gb
)
2365 case PCI_DEVICE_ID_FIREFLY
:
2366 m
= (typeof(m
)){"LP6000", "PCI",
2367 "Obsolete, Unsupported Fibre Channel Adapter"};
2369 case PCI_DEVICE_ID_SUPERFLY
:
2370 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
2371 m
= (typeof(m
)){"LP7000", "PCI", ""};
2373 m
= (typeof(m
)){"LP7000E", "PCI", ""};
2374 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2376 case PCI_DEVICE_ID_DRAGONFLY
:
2377 m
= (typeof(m
)){"LP8000", "PCI",
2378 "Obsolete, Unsupported Fibre Channel Adapter"};
2380 case PCI_DEVICE_ID_CENTAUR
:
2381 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
2382 m
= (typeof(m
)){"LP9002", "PCI", ""};
2384 m
= (typeof(m
)){"LP9000", "PCI", ""};
2385 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2387 case PCI_DEVICE_ID_RFLY
:
2388 m
= (typeof(m
)){"LP952", "PCI",
2389 "Obsolete, Unsupported Fibre Channel Adapter"};
2391 case PCI_DEVICE_ID_PEGASUS
:
2392 m
= (typeof(m
)){"LP9802", "PCI-X",
2393 "Obsolete, Unsupported Fibre Channel Adapter"};
2395 case PCI_DEVICE_ID_THOR
:
2396 m
= (typeof(m
)){"LP10000", "PCI-X",
2397 "Obsolete, Unsupported Fibre Channel Adapter"};
2399 case PCI_DEVICE_ID_VIPER
:
2400 m
= (typeof(m
)){"LPX1000", "PCI-X",
2401 "Obsolete, Unsupported Fibre Channel Adapter"};
2403 case PCI_DEVICE_ID_PFLY
:
2404 m
= (typeof(m
)){"LP982", "PCI-X",
2405 "Obsolete, Unsupported Fibre Channel Adapter"};
2407 case PCI_DEVICE_ID_TFLY
:
2408 m
= (typeof(m
)){"LP1050", "PCI-X",
2409 "Obsolete, Unsupported Fibre Channel Adapter"};
2411 case PCI_DEVICE_ID_HELIOS
:
2412 m
= (typeof(m
)){"LP11000", "PCI-X2",
2413 "Obsolete, Unsupported Fibre Channel Adapter"};
2415 case PCI_DEVICE_ID_HELIOS_SCSP
:
2416 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
2417 "Obsolete, Unsupported Fibre Channel Adapter"};
2419 case PCI_DEVICE_ID_HELIOS_DCSP
:
2420 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
2421 "Obsolete, Unsupported Fibre Channel Adapter"};
2423 case PCI_DEVICE_ID_NEPTUNE
:
2424 m
= (typeof(m
)){"LPe1000", "PCIe",
2425 "Obsolete, Unsupported Fibre Channel Adapter"};
2427 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
2428 m
= (typeof(m
)){"LPe1000-SP", "PCIe",
2429 "Obsolete, Unsupported Fibre Channel Adapter"};
2431 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
2432 m
= (typeof(m
)){"LPe1002-SP", "PCIe",
2433 "Obsolete, Unsupported Fibre Channel Adapter"};
2435 case PCI_DEVICE_ID_BMID
:
2436 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2438 case PCI_DEVICE_ID_BSMB
:
2439 m
= (typeof(m
)){"LP111", "PCI-X2",
2440 "Obsolete, Unsupported Fibre Channel Adapter"};
2442 case PCI_DEVICE_ID_ZEPHYR
:
2443 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2445 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
2446 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2448 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
2449 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
2452 case PCI_DEVICE_ID_ZMID
:
2453 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2455 case PCI_DEVICE_ID_ZSMB
:
2456 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2458 case PCI_DEVICE_ID_LP101
:
2459 m
= (typeof(m
)){"LP101", "PCI-X",
2460 "Obsolete, Unsupported Fibre Channel Adapter"};
2462 case PCI_DEVICE_ID_LP10000S
:
2463 m
= (typeof(m
)){"LP10000-S", "PCI",
2464 "Obsolete, Unsupported Fibre Channel Adapter"};
2466 case PCI_DEVICE_ID_LP11000S
:
2467 m
= (typeof(m
)){"LP11000-S", "PCI-X2",
2468 "Obsolete, Unsupported Fibre Channel Adapter"};
2470 case PCI_DEVICE_ID_LPE11000S
:
2471 m
= (typeof(m
)){"LPe11000-S", "PCIe",
2472 "Obsolete, Unsupported Fibre Channel Adapter"};
2474 case PCI_DEVICE_ID_SAT
:
2475 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2477 case PCI_DEVICE_ID_SAT_MID
:
2478 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2480 case PCI_DEVICE_ID_SAT_SMB
:
2481 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2483 case PCI_DEVICE_ID_SAT_DCSP
:
2484 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2486 case PCI_DEVICE_ID_SAT_SCSP
:
2487 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2489 case PCI_DEVICE_ID_SAT_S
:
2490 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2492 case PCI_DEVICE_ID_HORNET
:
2493 m
= (typeof(m
)){"LP21000", "PCIe",
2494 "Obsolete, Unsupported FCoE Adapter"};
2497 case PCI_DEVICE_ID_PROTEUS_VF
:
2498 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2499 "Obsolete, Unsupported Fibre Channel Adapter"};
2501 case PCI_DEVICE_ID_PROTEUS_PF
:
2502 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2503 "Obsolete, Unsupported Fibre Channel Adapter"};
2505 case PCI_DEVICE_ID_PROTEUS_S
:
2506 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2507 "Obsolete, Unsupported Fibre Channel Adapter"};
2509 case PCI_DEVICE_ID_TIGERSHARK
:
2511 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2513 case PCI_DEVICE_ID_TOMCAT
:
2515 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2517 case PCI_DEVICE_ID_FALCON
:
2518 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2519 "EmulexSecure Fibre"};
2521 case PCI_DEVICE_ID_BALIUS
:
2522 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2523 "Obsolete, Unsupported Fibre Channel Adapter"};
2525 case PCI_DEVICE_ID_LANCER_FC
:
2526 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2528 case PCI_DEVICE_ID_LANCER_FC_VF
:
2529 m
= (typeof(m
)){"LPe16000", "PCIe",
2530 "Obsolete, Unsupported Fibre Channel Adapter"};
2532 case PCI_DEVICE_ID_LANCER_FCOE
:
2534 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2536 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2538 m
= (typeof(m
)){"OCe15100", "PCIe",
2539 "Obsolete, Unsupported FCoE"};
2541 case PCI_DEVICE_ID_LANCER_G6_FC
:
2542 m
= (typeof(m
)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2544 case PCI_DEVICE_ID_LANCER_G7_FC
:
2545 m
= (typeof(m
)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2547 case PCI_DEVICE_ID_SKYHAWK
:
2548 case PCI_DEVICE_ID_SKYHAWK_VF
:
2550 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2553 m
= (typeof(m
)){"Unknown", "", ""};
2557 if (mdp
&& mdp
[0] == '\0')
2558 snprintf(mdp
, 79,"%s", m
.name
);
2560 * oneConnect hba requires special processing, they are all initiators
2561 * and we put the port number on the end
2563 if (descp
&& descp
[0] == '\0') {
2565 snprintf(descp
, 255,
2566 "Emulex OneConnect %s, %s Initiator %s",
2569 else if (max_speed
== 0)
2570 snprintf(descp
, 255,
2572 m
.name
, m
.bus
, m
.function
);
2574 snprintf(descp
, 255,
2575 "Emulex %s %d%s %s %s",
2576 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2582 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2583 * @phba: pointer to lpfc hba data structure.
2584 * @pring: pointer to a IOCB ring.
2585 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2587 * This routine posts a given number of IOCBs with the associated DMA buffer
2588 * descriptors specified by the cnt argument to the given IOCB ring.
2591 * The number of IOCBs NOT able to be posted to the IOCB ring.
2594 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2597 struct lpfc_iocbq
*iocb
;
2598 struct lpfc_dmabuf
*mp1
, *mp2
;
2600 cnt
+= pring
->missbufcnt
;
2602 /* While there are buffers to post */
2604 /* Allocate buffer for command iocb */
2605 iocb
= lpfc_sli_get_iocbq(phba
);
2607 pring
->missbufcnt
= cnt
;
2612 /* 2 buffers can be posted per command */
2613 /* Allocate buffer to post */
2614 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2616 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2617 if (!mp1
|| !mp1
->virt
) {
2619 lpfc_sli_release_iocbq(phba
, iocb
);
2620 pring
->missbufcnt
= cnt
;
2624 INIT_LIST_HEAD(&mp1
->list
);
2625 /* Allocate buffer to post */
2627 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2629 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2631 if (!mp2
|| !mp2
->virt
) {
2633 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2635 lpfc_sli_release_iocbq(phba
, iocb
);
2636 pring
->missbufcnt
= cnt
;
2640 INIT_LIST_HEAD(&mp2
->list
);
2645 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2646 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2647 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2648 icmd
->ulpBdeCount
= 1;
2651 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2652 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2653 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2655 icmd
->ulpBdeCount
= 2;
2658 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2661 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2663 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2667 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2671 lpfc_sli_release_iocbq(phba
, iocb
);
2672 pring
->missbufcnt
= cnt
;
2675 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2677 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2679 pring
->missbufcnt
= 0;
2684 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2685 * @phba: pointer to lpfc hba data structure.
2687 * This routine posts initial receive IOCB buffers to the ELS ring. The
2688 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2689 * set to 64 IOCBs. SLI3 only.
2692 * 0 - success (currently always success)
2695 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2697 struct lpfc_sli
*psli
= &phba
->sli
;
2699 /* Ring 0, ELS / CT buffers */
2700 lpfc_post_buffer(phba
, &psli
->sli3_ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2701 /* Ring 2 - FCP no buffers needed */
2706 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2709 * lpfc_sha_init - Set up initial array of hash table entries
2710 * @HashResultPointer: pointer to an array as hash table.
2712 * This routine sets up the initial values to the array of hash table entries
2716 lpfc_sha_init(uint32_t * HashResultPointer
)
2718 HashResultPointer
[0] = 0x67452301;
2719 HashResultPointer
[1] = 0xEFCDAB89;
2720 HashResultPointer
[2] = 0x98BADCFE;
2721 HashResultPointer
[3] = 0x10325476;
2722 HashResultPointer
[4] = 0xC3D2E1F0;
2726 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2727 * @HashResultPointer: pointer to an initial/result hash table.
2728 * @HashWorkingPointer: pointer to an working hash table.
2730 * This routine iterates an initial hash table pointed by @HashResultPointer
2731 * with the values from the working hash table pointeed by @HashWorkingPointer.
2732 * The results are putting back to the initial hash table, returned through
2733 * the @HashResultPointer as the result hash table.
2736 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2740 uint32_t A
, B
, C
, D
, E
;
2743 HashWorkingPointer
[t
] =
2745 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2747 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2748 } while (++t
<= 79);
2750 A
= HashResultPointer
[0];
2751 B
= HashResultPointer
[1];
2752 C
= HashResultPointer
[2];
2753 D
= HashResultPointer
[3];
2754 E
= HashResultPointer
[4];
2758 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2759 } else if (t
< 40) {
2760 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2761 } else if (t
< 60) {
2762 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2764 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2766 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2772 } while (++t
<= 79);
2774 HashResultPointer
[0] += A
;
2775 HashResultPointer
[1] += B
;
2776 HashResultPointer
[2] += C
;
2777 HashResultPointer
[3] += D
;
2778 HashResultPointer
[4] += E
;
2783 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2784 * @RandomChallenge: pointer to the entry of host challenge random number array.
2785 * @HashWorking: pointer to the entry of the working hash array.
2787 * This routine calculates the working hash array referred by @HashWorking
2788 * from the challenge random numbers associated with the host, referred by
2789 * @RandomChallenge. The result is put into the entry of the working hash
2790 * array and returned by reference through @HashWorking.
2793 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2795 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2799 * lpfc_hba_init - Perform special handling for LC HBA initialization
2800 * @phba: pointer to lpfc hba data structure.
2801 * @hbainit: pointer to an array of unsigned 32-bit integers.
2803 * This routine performs the special handling for LC HBA initialization.
2806 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2809 uint32_t *HashWorking
;
2810 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2812 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2816 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2817 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2819 for (t
= 0; t
< 7; t
++)
2820 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2822 lpfc_sha_init(hbainit
);
2823 lpfc_sha_iterate(hbainit
, HashWorking
);
2828 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2829 * @vport: pointer to a virtual N_Port data structure.
2831 * This routine performs the necessary cleanups before deleting the @vport.
2832 * It invokes the discovery state machine to perform necessary state
2833 * transitions and to release the ndlps associated with the @vport. Note,
2834 * the physical port is treated as @vport 0.
2837 lpfc_cleanup(struct lpfc_vport
*vport
)
2839 struct lpfc_hba
*phba
= vport
->phba
;
2840 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2843 if (phba
->link_state
> LPFC_LINK_DOWN
)
2844 lpfc_port_link_failure(vport
);
2846 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2847 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2848 ndlp
= lpfc_enable_node(vport
, ndlp
,
2849 NLP_STE_UNUSED_NODE
);
2852 spin_lock_irq(&phba
->ndlp_lock
);
2853 NLP_SET_FREE_REQ(ndlp
);
2854 spin_unlock_irq(&phba
->ndlp_lock
);
2855 /* Trigger the release of the ndlp memory */
2859 spin_lock_irq(&phba
->ndlp_lock
);
2860 if (NLP_CHK_FREE_REQ(ndlp
)) {
2861 /* The ndlp should not be in memory free mode already */
2862 spin_unlock_irq(&phba
->ndlp_lock
);
2865 /* Indicate request for freeing ndlp memory */
2866 NLP_SET_FREE_REQ(ndlp
);
2867 spin_unlock_irq(&phba
->ndlp_lock
);
2869 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2870 ndlp
->nlp_DID
== Fabric_DID
) {
2871 /* Just free up ndlp with Fabric_DID for vports */
2876 /* take care of nodes in unused state before the state
2877 * machine taking action.
2879 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2884 if (ndlp
->nlp_type
& NLP_FABRIC
)
2885 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2886 NLP_EVT_DEVICE_RECOVERY
);
2888 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2892 /* At this point, ALL ndlp's should be gone
2893 * because of the previous NLP_EVT_DEVICE_RM.
2894 * Lets wait for this to happen, if needed.
2896 while (!list_empty(&vport
->fc_nodes
)) {
2898 lpfc_printf_vlog(vport
, KERN_ERR
,
2900 "0233 Nodelist not empty\n");
2901 list_for_each_entry_safe(ndlp
, next_ndlp
,
2902 &vport
->fc_nodes
, nlp_listp
) {
2903 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2905 "0282 did:x%x ndlp:x%px "
2906 "usgmap:x%x refcnt:%d\n",
2907 ndlp
->nlp_DID
, (void *)ndlp
,
2909 kref_read(&ndlp
->kref
));
2914 /* Wait for any activity on ndlps to settle */
2917 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2921 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2922 * @vport: pointer to a virtual N_Port data structure.
2924 * This routine stops all the timers associated with a @vport. This function
2925 * is invoked before disabling or deleting a @vport. Note that the physical
2926 * port is treated as @vport 0.
2929 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2931 del_timer_sync(&vport
->els_tmofunc
);
2932 del_timer_sync(&vport
->delayed_disc_tmo
);
2933 lpfc_can_disctmo(vport
);
2938 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2939 * @phba: pointer to lpfc hba data structure.
2941 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2942 * caller of this routine should already hold the host lock.
2945 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2947 /* Clear pending FCF rediscovery wait flag */
2948 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2950 /* Now, try to stop the timer */
2951 del_timer(&phba
->fcf
.redisc_wait
);
2955 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2956 * @phba: pointer to lpfc hba data structure.
2958 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2959 * checks whether the FCF rediscovery wait timer is pending with the host
2960 * lock held before proceeding with disabling the timer and clearing the
2961 * wait timer pendig flag.
2964 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2966 spin_lock_irq(&phba
->hbalock
);
2967 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2968 /* FCF rediscovery timer already fired or stopped */
2969 spin_unlock_irq(&phba
->hbalock
);
2972 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2973 /* Clear failover in progress flags */
2974 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2975 spin_unlock_irq(&phba
->hbalock
);
2979 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2980 * @phba: pointer to lpfc hba data structure.
2982 * This routine stops all the timers associated with a HBA. This function is
2983 * invoked before either putting a HBA offline or unloading the driver.
2986 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2989 lpfc_stop_vport_timers(phba
->pport
);
2990 cancel_delayed_work_sync(&phba
->eq_delay_work
);
2991 cancel_delayed_work_sync(&phba
->idle_stat_delay_work
);
2992 del_timer_sync(&phba
->sli
.mbox_tmo
);
2993 del_timer_sync(&phba
->fabric_block_timer
);
2994 del_timer_sync(&phba
->eratt_poll
);
2995 del_timer_sync(&phba
->hb_tmofunc
);
2996 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2997 del_timer_sync(&phba
->rrq_tmr
);
2998 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
3000 phba
->hb_outstanding
= 0;
3002 switch (phba
->pci_dev_grp
) {
3003 case LPFC_PCI_DEV_LP
:
3004 /* Stop any LightPulse device specific driver timers */
3005 del_timer_sync(&phba
->fcp_poll_timer
);
3007 case LPFC_PCI_DEV_OC
:
3008 /* Stop any OneConnect device specific driver timers */
3009 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
3012 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3013 "0297 Invalid device group (x%x)\n",
3021 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
3022 * @phba: pointer to lpfc hba data structure.
3023 * @mbx_action: flag for mailbox no wait action.
3025 * This routine marks a HBA's management interface as blocked. Once the HBA's
3026 * management interface is marked as blocked, all the user space access to
3027 * the HBA, whether they are from sysfs interface or libdfc interface will
3028 * all be blocked. The HBA is set to block the management interface when the
3029 * driver prepares the HBA interface for online or offline.
3032 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
3034 unsigned long iflag
;
3035 uint8_t actcmd
= MBX_HEARTBEAT
;
3036 unsigned long timeout
;
3038 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3039 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
3040 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3041 if (mbx_action
== LPFC_MBX_NO_WAIT
)
3043 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
3044 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3045 if (phba
->sli
.mbox_active
) {
3046 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
3047 /* Determine how long we might wait for the active mailbox
3048 * command to be gracefully completed by firmware.
3050 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
3051 phba
->sli
.mbox_active
) * 1000) + jiffies
;
3053 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3055 /* Wait for the outstnading mailbox command to complete */
3056 while (phba
->sli
.mbox_active
) {
3057 /* Check active mailbox complete status every 2ms */
3059 if (time_after(jiffies
, timeout
)) {
3060 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3061 "2813 Mgmt IO is Blocked %x "
3062 "- mbox cmd %x still active\n",
3063 phba
->sli
.sli_flag
, actcmd
);
3070 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3071 * @phba: pointer to lpfc hba data structure.
3073 * Allocate RPIs for all active remote nodes. This is needed whenever
3074 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3075 * is to fixup the temporary rpi assignments.
3078 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
3080 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3081 struct lpfc_vport
**vports
;
3083 unsigned long flags
;
3085 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
3088 vports
= lpfc_create_vport_work_array(phba
);
3092 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3093 if (vports
[i
]->load_flag
& FC_UNLOADING
)
3096 list_for_each_entry_safe(ndlp
, next_ndlp
,
3097 &vports
[i
]->fc_nodes
,
3099 if (!NLP_CHK_NODE_ACT(ndlp
))
3101 rpi
= lpfc_sli4_alloc_rpi(phba
);
3102 if (rpi
== LPFC_RPI_ALLOC_ERROR
) {
3103 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3104 NLP_CLR_NODE_ACT(ndlp
);
3105 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3108 ndlp
->nlp_rpi
= rpi
;
3109 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
,
3110 LOG_NODE
| LOG_DISCOVERY
,
3111 "0009 Assign RPI x%x to ndlp x%px "
3112 "DID:x%06x flg:x%x map:x%x\n",
3113 ndlp
->nlp_rpi
, ndlp
, ndlp
->nlp_DID
,
3114 ndlp
->nlp_flag
, ndlp
->nlp_usg_map
);
3117 lpfc_destroy_vport_work_array(phba
, vports
);
3121 * lpfc_create_expedite_pool - create expedite pool
3122 * @phba: pointer to lpfc hba data structure.
3124 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3125 * to expedite pool. Mark them as expedite.
3127 static void lpfc_create_expedite_pool(struct lpfc_hba
*phba
)
3129 struct lpfc_sli4_hdw_queue
*qp
;
3130 struct lpfc_io_buf
*lpfc_ncmd
;
3131 struct lpfc_io_buf
*lpfc_ncmd_next
;
3132 struct lpfc_epd_pool
*epd_pool
;
3133 unsigned long iflag
;
3135 epd_pool
= &phba
->epd_pool
;
3136 qp
= &phba
->sli4_hba
.hdwq
[0];
3138 spin_lock_init(&epd_pool
->lock
);
3139 spin_lock_irqsave(&qp
->io_buf_list_put_lock
, iflag
);
3140 spin_lock(&epd_pool
->lock
);
3141 INIT_LIST_HEAD(&epd_pool
->list
);
3142 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3143 &qp
->lpfc_io_buf_list_put
, list
) {
3144 list_move_tail(&lpfc_ncmd
->list
, &epd_pool
->list
);
3145 lpfc_ncmd
->expedite
= true;
3148 if (epd_pool
->count
>= XRI_BATCH
)
3151 spin_unlock(&epd_pool
->lock
);
3152 spin_unlock_irqrestore(&qp
->io_buf_list_put_lock
, iflag
);
3156 * lpfc_destroy_expedite_pool - destroy expedite pool
3157 * @phba: pointer to lpfc hba data structure.
3159 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3160 * of HWQ 0. Clear the mark.
3162 static void lpfc_destroy_expedite_pool(struct lpfc_hba
*phba
)
3164 struct lpfc_sli4_hdw_queue
*qp
;
3165 struct lpfc_io_buf
*lpfc_ncmd
;
3166 struct lpfc_io_buf
*lpfc_ncmd_next
;
3167 struct lpfc_epd_pool
*epd_pool
;
3168 unsigned long iflag
;
3170 epd_pool
= &phba
->epd_pool
;
3171 qp
= &phba
->sli4_hba
.hdwq
[0];
3173 spin_lock_irqsave(&qp
->io_buf_list_put_lock
, iflag
);
3174 spin_lock(&epd_pool
->lock
);
3175 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3176 &epd_pool
->list
, list
) {
3177 list_move_tail(&lpfc_ncmd
->list
,
3178 &qp
->lpfc_io_buf_list_put
);
3179 lpfc_ncmd
->flags
= false;
3183 spin_unlock(&epd_pool
->lock
);
3184 spin_unlock_irqrestore(&qp
->io_buf_list_put_lock
, iflag
);
3188 * lpfc_create_multixri_pools - create multi-XRI pools
3189 * @phba: pointer to lpfc hba data structure.
3191 * This routine initialize public, private per HWQ. Then, move XRIs from
3192 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3195 void lpfc_create_multixri_pools(struct lpfc_hba
*phba
)
3200 struct lpfc_io_buf
*lpfc_ncmd
;
3201 struct lpfc_io_buf
*lpfc_ncmd_next
;
3202 unsigned long iflag
;
3203 struct lpfc_sli4_hdw_queue
*qp
;
3204 struct lpfc_multixri_pool
*multixri_pool
;
3205 struct lpfc_pbl_pool
*pbl_pool
;
3206 struct lpfc_pvt_pool
*pvt_pool
;
3208 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3209 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3210 phba
->cfg_hdw_queue
, phba
->sli4_hba
.num_present_cpu
,
3211 phba
->sli4_hba
.io_xri_cnt
);
3213 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
3214 lpfc_create_expedite_pool(phba
);
3216 hwq_count
= phba
->cfg_hdw_queue
;
3217 count_per_hwq
= phba
->sli4_hba
.io_xri_cnt
/ hwq_count
;
3219 for (i
= 0; i
< hwq_count
; i
++) {
3220 multixri_pool
= kzalloc(sizeof(*multixri_pool
), GFP_KERNEL
);
3222 if (!multixri_pool
) {
3223 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3224 "1238 Failed to allocate memory for "
3227 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
3228 lpfc_destroy_expedite_pool(phba
);
3232 qp
= &phba
->sli4_hba
.hdwq
[j
];
3233 kfree(qp
->p_multixri_pool
);
3236 phba
->cfg_xri_rebalancing
= 0;
3240 qp
= &phba
->sli4_hba
.hdwq
[i
];
3241 qp
->p_multixri_pool
= multixri_pool
;
3243 multixri_pool
->xri_limit
= count_per_hwq
;
3244 multixri_pool
->rrb_next_hwqid
= i
;
3246 /* Deal with public free xri pool */
3247 pbl_pool
= &multixri_pool
->pbl_pool
;
3248 spin_lock_init(&pbl_pool
->lock
);
3249 spin_lock_irqsave(&qp
->io_buf_list_put_lock
, iflag
);
3250 spin_lock(&pbl_pool
->lock
);
3251 INIT_LIST_HEAD(&pbl_pool
->list
);
3252 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3253 &qp
->lpfc_io_buf_list_put
, list
) {
3254 list_move_tail(&lpfc_ncmd
->list
, &pbl_pool
->list
);
3258 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3259 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3260 pbl_pool
->count
, i
);
3261 spin_unlock(&pbl_pool
->lock
);
3262 spin_unlock_irqrestore(&qp
->io_buf_list_put_lock
, iflag
);
3264 /* Deal with private free xri pool */
3265 pvt_pool
= &multixri_pool
->pvt_pool
;
3266 pvt_pool
->high_watermark
= multixri_pool
->xri_limit
/ 2;
3267 pvt_pool
->low_watermark
= XRI_BATCH
;
3268 spin_lock_init(&pvt_pool
->lock
);
3269 spin_lock_irqsave(&pvt_pool
->lock
, iflag
);
3270 INIT_LIST_HEAD(&pvt_pool
->list
);
3271 pvt_pool
->count
= 0;
3272 spin_unlock_irqrestore(&pvt_pool
->lock
, iflag
);
3277 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3278 * @phba: pointer to lpfc hba data structure.
3280 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3282 static void lpfc_destroy_multixri_pools(struct lpfc_hba
*phba
)
3286 struct lpfc_io_buf
*lpfc_ncmd
;
3287 struct lpfc_io_buf
*lpfc_ncmd_next
;
3288 unsigned long iflag
;
3289 struct lpfc_sli4_hdw_queue
*qp
;
3290 struct lpfc_multixri_pool
*multixri_pool
;
3291 struct lpfc_pbl_pool
*pbl_pool
;
3292 struct lpfc_pvt_pool
*pvt_pool
;
3294 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
3295 lpfc_destroy_expedite_pool(phba
);
3297 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
3298 lpfc_sli_flush_io_rings(phba
);
3300 hwq_count
= phba
->cfg_hdw_queue
;
3302 for (i
= 0; i
< hwq_count
; i
++) {
3303 qp
= &phba
->sli4_hba
.hdwq
[i
];
3304 multixri_pool
= qp
->p_multixri_pool
;
3308 qp
->p_multixri_pool
= NULL
;
3310 spin_lock_irqsave(&qp
->io_buf_list_put_lock
, iflag
);
3312 /* Deal with public free xri pool */
3313 pbl_pool
= &multixri_pool
->pbl_pool
;
3314 spin_lock(&pbl_pool
->lock
);
3316 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3317 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3318 pbl_pool
->count
, i
);
3320 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3321 &pbl_pool
->list
, list
) {
3322 list_move_tail(&lpfc_ncmd
->list
,
3323 &qp
->lpfc_io_buf_list_put
);
3328 INIT_LIST_HEAD(&pbl_pool
->list
);
3329 pbl_pool
->count
= 0;
3331 spin_unlock(&pbl_pool
->lock
);
3333 /* Deal with private free xri pool */
3334 pvt_pool
= &multixri_pool
->pvt_pool
;
3335 spin_lock(&pvt_pool
->lock
);
3337 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3338 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3339 pvt_pool
->count
, i
);
3341 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3342 &pvt_pool
->list
, list
) {
3343 list_move_tail(&lpfc_ncmd
->list
,
3344 &qp
->lpfc_io_buf_list_put
);
3349 INIT_LIST_HEAD(&pvt_pool
->list
);
3350 pvt_pool
->count
= 0;
3352 spin_unlock(&pvt_pool
->lock
);
3353 spin_unlock_irqrestore(&qp
->io_buf_list_put_lock
, iflag
);
3355 kfree(multixri_pool
);
3360 * lpfc_online - Initialize and bring a HBA online
3361 * @phba: pointer to lpfc hba data structure.
3363 * This routine initializes the HBA and brings a HBA online. During this
3364 * process, the management interface is blocked to prevent user space access
3365 * to the HBA interfering with the driver initialization.
3372 lpfc_online(struct lpfc_hba
*phba
)
3374 struct lpfc_vport
*vport
;
3375 struct lpfc_vport
**vports
;
3377 bool vpis_cleared
= false;
3381 vport
= phba
->pport
;
3383 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
3386 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3387 "0458 Bring Adapter online\n");
3389 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
3391 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3392 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
3393 lpfc_unblock_mgmt_io(phba
);
3396 spin_lock_irq(&phba
->hbalock
);
3397 if (!phba
->sli4_hba
.max_cfg_param
.vpi_used
)
3398 vpis_cleared
= true;
3399 spin_unlock_irq(&phba
->hbalock
);
3401 /* Reestablish the local initiator port.
3402 * The offline process destroyed the previous lport.
3404 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
&&
3405 !phba
->nvmet_support
) {
3406 error
= lpfc_nvme_create_localport(phba
->pport
);
3408 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3409 "6132 NVME restore reg failed "
3410 "on nvmei error x%x\n", error
);
3413 lpfc_sli_queue_init(phba
);
3414 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
3415 lpfc_unblock_mgmt_io(phba
);
3420 vports
= lpfc_create_vport_work_array(phba
);
3421 if (vports
!= NULL
) {
3422 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3423 struct Scsi_Host
*shost
;
3424 shost
= lpfc_shost_from_vport(vports
[i
]);
3425 spin_lock_irq(shost
->host_lock
);
3426 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
3427 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
3428 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3429 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3430 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
3431 if ((vpis_cleared
) &&
3432 (vports
[i
]->port_type
!=
3433 LPFC_PHYSICAL_PORT
))
3436 spin_unlock_irq(shost
->host_lock
);
3439 lpfc_destroy_vport_work_array(phba
, vports
);
3441 if (phba
->cfg_xri_rebalancing
)
3442 lpfc_create_multixri_pools(phba
);
3444 lpfc_cpuhp_add(phba
);
3446 lpfc_unblock_mgmt_io(phba
);
3451 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
3452 * @phba: pointer to lpfc hba data structure.
3454 * This routine marks a HBA's management interface as not blocked. Once the
3455 * HBA's management interface is marked as not blocked, all the user space
3456 * access to the HBA, whether they are from sysfs interface or libdfc
3457 * interface will be allowed. The HBA is set to block the management interface
3458 * when the driver prepares the HBA interface for online or offline and then
3459 * set to unblock the management interface afterwards.
3462 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
3464 unsigned long iflag
;
3466 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3467 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
3468 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3472 * lpfc_offline_prep - Prepare a HBA to be brought offline
3473 * @phba: pointer to lpfc hba data structure.
3474 * @mbx_action: flag for mailbox shutdown action.
3476 * This routine is invoked to prepare a HBA to be brought offline. It performs
3477 * unregistration login to all the nodes on all vports and flushes the mailbox
3478 * queue to make it ready to be brought offline.
3481 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
3483 struct lpfc_vport
*vport
= phba
->pport
;
3484 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3485 struct lpfc_vport
**vports
;
3486 struct Scsi_Host
*shost
;
3489 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
3492 lpfc_block_mgmt_io(phba
, mbx_action
);
3494 lpfc_linkdown(phba
);
3496 /* Issue an unreg_login to all nodes on all vports */
3497 vports
= lpfc_create_vport_work_array(phba
);
3498 if (vports
!= NULL
) {
3499 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3500 if (vports
[i
]->load_flag
& FC_UNLOADING
)
3502 shost
= lpfc_shost_from_vport(vports
[i
]);
3503 spin_lock_irq(shost
->host_lock
);
3504 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3505 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3506 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
3507 spin_unlock_irq(shost
->host_lock
);
3509 shost
= lpfc_shost_from_vport(vports
[i
]);
3510 list_for_each_entry_safe(ndlp
, next_ndlp
,
3511 &vports
[i
]->fc_nodes
,
3513 if ((!NLP_CHK_NODE_ACT(ndlp
)) ||
3514 ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
3515 /* Driver must assume RPI is invalid for
3516 * any unused or inactive node.
3518 ndlp
->nlp_rpi
= LPFC_RPI_ALLOC_ERROR
;
3522 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3523 lpfc_disc_state_machine(vports
[i
], ndlp
,
3524 NULL
, NLP_EVT_DEVICE_RECOVERY
);
3525 lpfc_disc_state_machine(vports
[i
], ndlp
,
3526 NULL
, NLP_EVT_DEVICE_RM
);
3528 spin_lock_irq(shost
->host_lock
);
3529 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3530 spin_unlock_irq(shost
->host_lock
);
3532 * Whenever an SLI4 port goes offline, free the
3533 * RPI. Get a new RPI when the adapter port
3534 * comes back online.
3536 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3537 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
,
3538 LOG_NODE
| LOG_DISCOVERY
,
3539 "0011 Free RPI x%x on "
3540 "ndlp:x%px did x%x "
3542 ndlp
->nlp_rpi
, ndlp
,
3545 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
3546 ndlp
->nlp_rpi
= LPFC_RPI_ALLOC_ERROR
;
3548 lpfc_unreg_rpi(vports
[i
], ndlp
);
3552 lpfc_destroy_vport_work_array(phba
, vports
);
3554 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
3557 flush_workqueue(phba
->wq
);
3561 * lpfc_offline - Bring a HBA offline
3562 * @phba: pointer to lpfc hba data structure.
3564 * This routine actually brings a HBA offline. It stops all the timers
3565 * associated with the HBA, brings down the SLI layer, and eventually
3566 * marks the HBA as in offline state for the upper layer protocol.
3569 lpfc_offline(struct lpfc_hba
*phba
)
3571 struct Scsi_Host
*shost
;
3572 struct lpfc_vport
**vports
;
3575 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
3578 /* stop port and all timers associated with this hba */
3579 lpfc_stop_port(phba
);
3581 /* Tear down the local and target port registrations. The
3582 * nvme transports need to cleanup.
3584 lpfc_nvmet_destroy_targetport(phba
);
3585 lpfc_nvme_destroy_localport(phba
->pport
);
3587 vports
= lpfc_create_vport_work_array(phba
);
3589 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3590 lpfc_stop_vport_timers(vports
[i
]);
3591 lpfc_destroy_vport_work_array(phba
, vports
);
3592 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3593 "0460 Bring Adapter offline\n");
3594 /* Bring down the SLI Layer and cleanup. The HBA is offline
3596 lpfc_sli_hba_down(phba
);
3597 spin_lock_irq(&phba
->hbalock
);
3599 spin_unlock_irq(&phba
->hbalock
);
3600 vports
= lpfc_create_vport_work_array(phba
);
3602 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3603 shost
= lpfc_shost_from_vport(vports
[i
]);
3604 spin_lock_irq(shost
->host_lock
);
3605 vports
[i
]->work_port_events
= 0;
3606 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
3607 spin_unlock_irq(shost
->host_lock
);
3609 lpfc_destroy_vport_work_array(phba
, vports
);
3610 __lpfc_cpuhp_remove(phba
);
3612 if (phba
->cfg_xri_rebalancing
)
3613 lpfc_destroy_multixri_pools(phba
);
3617 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3618 * @phba: pointer to lpfc hba data structure.
3620 * This routine is to free all the SCSI buffers and IOCBs from the driver
3621 * list back to kernel. It is called from lpfc_pci_remove_one to free
3622 * the internal resources before the device is removed from the system.
3625 lpfc_scsi_free(struct lpfc_hba
*phba
)
3627 struct lpfc_io_buf
*sb
, *sb_next
;
3629 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
3632 spin_lock_irq(&phba
->hbalock
);
3634 /* Release all the lpfc_scsi_bufs maintained by this host. */
3636 spin_lock(&phba
->scsi_buf_list_put_lock
);
3637 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_put
,
3639 list_del(&sb
->list
);
3640 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3643 phba
->total_scsi_bufs
--;
3645 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3647 spin_lock(&phba
->scsi_buf_list_get_lock
);
3648 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_get
,
3650 list_del(&sb
->list
);
3651 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3654 phba
->total_scsi_bufs
--;
3656 spin_unlock(&phba
->scsi_buf_list_get_lock
);
3657 spin_unlock_irq(&phba
->hbalock
);
3661 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
3662 * @phba: pointer to lpfc hba data structure.
3664 * This routine is to free all the IO buffers and IOCBs from the driver
3665 * list back to kernel. It is called from lpfc_pci_remove_one to free
3666 * the internal resources before the device is removed from the system.
3669 lpfc_io_free(struct lpfc_hba
*phba
)
3671 struct lpfc_io_buf
*lpfc_ncmd
, *lpfc_ncmd_next
;
3672 struct lpfc_sli4_hdw_queue
*qp
;
3675 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
3676 qp
= &phba
->sli4_hba
.hdwq
[idx
];
3677 /* Release all the lpfc_nvme_bufs maintained by this host. */
3678 spin_lock(&qp
->io_buf_list_put_lock
);
3679 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3680 &qp
->lpfc_io_buf_list_put
,
3682 list_del(&lpfc_ncmd
->list
);
3684 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3685 lpfc_ncmd
->data
, lpfc_ncmd
->dma_handle
);
3686 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
)
3687 lpfc_put_sgl_per_hdwq(phba
, lpfc_ncmd
);
3688 lpfc_put_cmd_rsp_buf_per_hdwq(phba
, lpfc_ncmd
);
3690 qp
->total_io_bufs
--;
3692 spin_unlock(&qp
->io_buf_list_put_lock
);
3694 spin_lock(&qp
->io_buf_list_get_lock
);
3695 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3696 &qp
->lpfc_io_buf_list_get
,
3698 list_del(&lpfc_ncmd
->list
);
3700 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3701 lpfc_ncmd
->data
, lpfc_ncmd
->dma_handle
);
3702 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
)
3703 lpfc_put_sgl_per_hdwq(phba
, lpfc_ncmd
);
3704 lpfc_put_cmd_rsp_buf_per_hdwq(phba
, lpfc_ncmd
);
3706 qp
->total_io_bufs
--;
3708 spin_unlock(&qp
->io_buf_list_get_lock
);
3713 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3714 * @phba: pointer to lpfc hba data structure.
3716 * This routine first calculates the sizes of the current els and allocated
3717 * scsi sgl lists, and then goes through all sgls to updates the physical
3718 * XRIs assigned due to port function reset. During port initialization, the
3719 * current els and allocated scsi sgl lists are 0s.
3722 * 0 - successful (for now, it always returns 0)
3725 lpfc_sli4_els_sgl_update(struct lpfc_hba
*phba
)
3727 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3728 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3729 LIST_HEAD(els_sgl_list
);
3733 * update on pci function's els xri-sgl list
3735 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3737 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
3738 /* els xri-sgl expanded */
3739 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
3740 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3741 "3157 ELS xri-sgl count increased from "
3742 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3744 /* allocate the additional els sgls */
3745 for (i
= 0; i
< xri_cnt
; i
++) {
3746 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3748 if (sglq_entry
== NULL
) {
3749 lpfc_printf_log(phba
, KERN_ERR
,
3751 "2562 Failure to allocate an "
3752 "ELS sgl entry:%d\n", i
);
3756 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
3757 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
3759 if (sglq_entry
->virt
== NULL
) {
3761 lpfc_printf_log(phba
, KERN_ERR
,
3763 "2563 Failure to allocate an "
3764 "ELS mbuf:%d\n", i
);
3768 sglq_entry
->sgl
= sglq_entry
->virt
;
3769 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
3770 sglq_entry
->state
= SGL_FREED
;
3771 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
3773 spin_lock_irq(&phba
->hbalock
);
3774 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3775 list_splice_init(&els_sgl_list
,
3776 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3777 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3778 spin_unlock_irq(&phba
->hbalock
);
3779 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
3780 /* els xri-sgl shrinked */
3781 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
3782 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3783 "3158 ELS xri-sgl count decreased from "
3784 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3786 spin_lock_irq(&phba
->hbalock
);
3787 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3788 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
,
3790 /* release extra els sgls from list */
3791 for (i
= 0; i
< xri_cnt
; i
++) {
3792 list_remove_head(&els_sgl_list
,
3793 sglq_entry
, struct lpfc_sglq
, list
);
3795 __lpfc_mbuf_free(phba
, sglq_entry
->virt
,
3800 list_splice_init(&els_sgl_list
,
3801 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3802 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3803 spin_unlock_irq(&phba
->hbalock
);
3805 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3806 "3163 ELS xri-sgl count unchanged: %d\n",
3808 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
3810 /* update xris to els sgls on the list */
3812 sglq_entry_next
= NULL
;
3813 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3814 &phba
->sli4_hba
.lpfc_els_sgl_list
, list
) {
3815 lxri
= lpfc_sli4_next_xritag(phba
);
3816 if (lxri
== NO_XRI
) {
3817 lpfc_printf_log(phba
, KERN_ERR
,
3819 "2400 Failed to allocate xri for "
3824 sglq_entry
->sli4_lxritag
= lxri
;
3825 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3830 lpfc_free_els_sgl_list(phba
);
3835 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3836 * @phba: pointer to lpfc hba data structure.
3838 * This routine first calculates the sizes of the current els and allocated
3839 * scsi sgl lists, and then goes through all sgls to updates the physical
3840 * XRIs assigned due to port function reset. During port initialization, the
3841 * current els and allocated scsi sgl lists are 0s.
3844 * 0 - successful (for now, it always returns 0)
3847 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba
*phba
)
3849 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3850 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3851 uint16_t nvmet_xri_cnt
;
3852 LIST_HEAD(nvmet_sgl_list
);
3856 * update on pci function's nvmet xri-sgl list
3858 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3860 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3861 nvmet_xri_cnt
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
3862 if (nvmet_xri_cnt
> phba
->sli4_hba
.nvmet_xri_cnt
) {
3863 /* els xri-sgl expanded */
3864 xri_cnt
= nvmet_xri_cnt
- phba
->sli4_hba
.nvmet_xri_cnt
;
3865 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3866 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3867 phba
->sli4_hba
.nvmet_xri_cnt
, nvmet_xri_cnt
);
3868 /* allocate the additional nvmet sgls */
3869 for (i
= 0; i
< xri_cnt
; i
++) {
3870 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3872 if (sglq_entry
== NULL
) {
3873 lpfc_printf_log(phba
, KERN_ERR
,
3875 "6303 Failure to allocate an "
3876 "NVMET sgl entry:%d\n", i
);
3880 sglq_entry
->buff_type
= NVMET_BUFF_TYPE
;
3881 sglq_entry
->virt
= lpfc_nvmet_buf_alloc(phba
, 0,
3883 if (sglq_entry
->virt
== NULL
) {
3885 lpfc_printf_log(phba
, KERN_ERR
,
3887 "6304 Failure to allocate an "
3888 "NVMET buf:%d\n", i
);
3892 sglq_entry
->sgl
= sglq_entry
->virt
;
3893 memset(sglq_entry
->sgl
, 0,
3894 phba
->cfg_sg_dma_buf_size
);
3895 sglq_entry
->state
= SGL_FREED
;
3896 list_add_tail(&sglq_entry
->list
, &nvmet_sgl_list
);
3898 spin_lock_irq(&phba
->hbalock
);
3899 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3900 list_splice_init(&nvmet_sgl_list
,
3901 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3902 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3903 spin_unlock_irq(&phba
->hbalock
);
3904 } else if (nvmet_xri_cnt
< phba
->sli4_hba
.nvmet_xri_cnt
) {
3905 /* nvmet xri-sgl shrunk */
3906 xri_cnt
= phba
->sli4_hba
.nvmet_xri_cnt
- nvmet_xri_cnt
;
3907 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3908 "6305 NVMET xri-sgl count decreased from "
3909 "%d to %d\n", phba
->sli4_hba
.nvmet_xri_cnt
,
3911 spin_lock_irq(&phba
->hbalock
);
3912 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3913 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
3915 /* release extra nvmet sgls from list */
3916 for (i
= 0; i
< xri_cnt
; i
++) {
3917 list_remove_head(&nvmet_sgl_list
,
3918 sglq_entry
, struct lpfc_sglq
, list
);
3920 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
,
3925 list_splice_init(&nvmet_sgl_list
,
3926 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3927 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3928 spin_unlock_irq(&phba
->hbalock
);
3930 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3931 "6306 NVMET xri-sgl count unchanged: %d\n",
3933 phba
->sli4_hba
.nvmet_xri_cnt
= nvmet_xri_cnt
;
3935 /* update xris to nvmet sgls on the list */
3937 sglq_entry_next
= NULL
;
3938 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3939 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
, list
) {
3940 lxri
= lpfc_sli4_next_xritag(phba
);
3941 if (lxri
== NO_XRI
) {
3942 lpfc_printf_log(phba
, KERN_ERR
,
3944 "6307 Failed to allocate xri for "
3949 sglq_entry
->sli4_lxritag
= lxri
;
3950 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3955 lpfc_free_nvmet_sgl_list(phba
);
3960 lpfc_io_buf_flush(struct lpfc_hba
*phba
, struct list_head
*cbuf
)
3963 struct lpfc_sli4_hdw_queue
*qp
;
3964 struct lpfc_io_buf
*lpfc_cmd
;
3965 struct lpfc_io_buf
*iobufp
, *prev_iobufp
;
3966 int idx
, cnt
, xri
, inserted
;
3969 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
3970 qp
= &phba
->sli4_hba
.hdwq
[idx
];
3971 spin_lock_irq(&qp
->io_buf_list_get_lock
);
3972 spin_lock(&qp
->io_buf_list_put_lock
);
3974 /* Take everything off the get and put lists */
3975 list_splice_init(&qp
->lpfc_io_buf_list_get
, &blist
);
3976 list_splice(&qp
->lpfc_io_buf_list_put
, &blist
);
3977 INIT_LIST_HEAD(&qp
->lpfc_io_buf_list_get
);
3978 INIT_LIST_HEAD(&qp
->lpfc_io_buf_list_put
);
3979 cnt
+= qp
->get_io_bufs
+ qp
->put_io_bufs
;
3980 qp
->get_io_bufs
= 0;
3981 qp
->put_io_bufs
= 0;
3982 qp
->total_io_bufs
= 0;
3983 spin_unlock(&qp
->io_buf_list_put_lock
);
3984 spin_unlock_irq(&qp
->io_buf_list_get_lock
);
3988 * Take IO buffers off blist and put on cbuf sorted by XRI.
3989 * This is because POST_SGL takes a sequential range of XRIs
3990 * to post to the firmware.
3992 for (idx
= 0; idx
< cnt
; idx
++) {
3993 list_remove_head(&blist
, lpfc_cmd
, struct lpfc_io_buf
, list
);
3997 list_add_tail(&lpfc_cmd
->list
, cbuf
);
4000 xri
= lpfc_cmd
->cur_iocbq
.sli4_xritag
;
4003 list_for_each_entry(iobufp
, cbuf
, list
) {
4004 if (xri
< iobufp
->cur_iocbq
.sli4_xritag
) {
4006 list_add(&lpfc_cmd
->list
,
4007 &prev_iobufp
->list
);
4009 list_add(&lpfc_cmd
->list
, cbuf
);
4013 prev_iobufp
= iobufp
;
4016 list_add_tail(&lpfc_cmd
->list
, cbuf
);
4022 lpfc_io_buf_replenish(struct lpfc_hba
*phba
, struct list_head
*cbuf
)
4024 struct lpfc_sli4_hdw_queue
*qp
;
4025 struct lpfc_io_buf
*lpfc_cmd
;
4028 qp
= phba
->sli4_hba
.hdwq
;
4030 while (!list_empty(cbuf
)) {
4031 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
4032 list_remove_head(cbuf
, lpfc_cmd
,
4033 struct lpfc_io_buf
, list
);
4037 qp
= &phba
->sli4_hba
.hdwq
[idx
];
4038 lpfc_cmd
->hdwq_no
= idx
;
4039 lpfc_cmd
->hdwq
= qp
;
4040 lpfc_cmd
->cur_iocbq
.wqe_cmpl
= NULL
;
4041 lpfc_cmd
->cur_iocbq
.iocb_cmpl
= NULL
;
4042 spin_lock(&qp
->io_buf_list_put_lock
);
4043 list_add_tail(&lpfc_cmd
->list
,
4044 &qp
->lpfc_io_buf_list_put
);
4046 qp
->total_io_bufs
++;
4047 spin_unlock(&qp
->io_buf_list_put_lock
);
4054 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
4055 * @phba: pointer to lpfc hba data structure.
4057 * This routine first calculates the sizes of the current els and allocated
4058 * scsi sgl lists, and then goes through all sgls to updates the physical
4059 * XRIs assigned due to port function reset. During port initialization, the
4060 * current els and allocated scsi sgl lists are 0s.
4063 * 0 - successful (for now, it always returns 0)
4066 lpfc_sli4_io_sgl_update(struct lpfc_hba
*phba
)
4068 struct lpfc_io_buf
*lpfc_ncmd
= NULL
, *lpfc_ncmd_next
= NULL
;
4069 uint16_t i
, lxri
, els_xri_cnt
;
4070 uint16_t io_xri_cnt
, io_xri_max
;
4071 LIST_HEAD(io_sgl_list
);
4075 * update on pci function's allocated nvme xri-sgl list
4078 /* maximum number of xris available for nvme buffers */
4079 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
4080 io_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
4081 phba
->sli4_hba
.io_xri_max
= io_xri_max
;
4083 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4084 "6074 Current allocated XRI sgl count:%d, "
4085 "maximum XRI count:%d\n",
4086 phba
->sli4_hba
.io_xri_cnt
,
4087 phba
->sli4_hba
.io_xri_max
);
4089 cnt
= lpfc_io_buf_flush(phba
, &io_sgl_list
);
4091 if (phba
->sli4_hba
.io_xri_cnt
> phba
->sli4_hba
.io_xri_max
) {
4092 /* max nvme xri shrunk below the allocated nvme buffers */
4093 io_xri_cnt
= phba
->sli4_hba
.io_xri_cnt
-
4094 phba
->sli4_hba
.io_xri_max
;
4095 /* release the extra allocated nvme buffers */
4096 for (i
= 0; i
< io_xri_cnt
; i
++) {
4097 list_remove_head(&io_sgl_list
, lpfc_ncmd
,
4098 struct lpfc_io_buf
, list
);
4100 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
4102 lpfc_ncmd
->dma_handle
);
4106 phba
->sli4_hba
.io_xri_cnt
-= io_xri_cnt
;
4109 /* update xris associated to remaining allocated nvme buffers */
4111 lpfc_ncmd_next
= NULL
;
4112 phba
->sli4_hba
.io_xri_cnt
= cnt
;
4113 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
4114 &io_sgl_list
, list
) {
4115 lxri
= lpfc_sli4_next_xritag(phba
);
4116 if (lxri
== NO_XRI
) {
4117 lpfc_printf_log(phba
, KERN_ERR
,
4119 "6075 Failed to allocate xri for "
4124 lpfc_ncmd
->cur_iocbq
.sli4_lxritag
= lxri
;
4125 lpfc_ncmd
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
4127 cnt
= lpfc_io_buf_replenish(phba
, &io_sgl_list
);
4136 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
4137 * @phba: Pointer to lpfc hba data structure.
4138 * @num_to_alloc: The requested number of buffers to allocate.
4140 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4141 * the nvme buffer contains all the necessary information needed to initiate
4142 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4143 * them on a list, it post them to the port by using SGL block post.
4146 * int - number of IO buffers that were allocated and posted.
4147 * 0 = failure, less than num_to_alloc is a partial failure.
4150 lpfc_new_io_buf(struct lpfc_hba
*phba
, int num_to_alloc
)
4152 struct lpfc_io_buf
*lpfc_ncmd
;
4153 struct lpfc_iocbq
*pwqeq
;
4154 uint16_t iotag
, lxri
= 0;
4155 int bcnt
, num_posted
;
4156 LIST_HEAD(prep_nblist
);
4157 LIST_HEAD(post_nblist
);
4158 LIST_HEAD(nvme_nblist
);
4160 phba
->sli4_hba
.io_xri_cnt
= 0;
4161 for (bcnt
= 0; bcnt
< num_to_alloc
; bcnt
++) {
4162 lpfc_ncmd
= kzalloc(sizeof(*lpfc_ncmd
), GFP_KERNEL
);
4166 * Get memory from the pci pool to map the virt space to
4167 * pci bus space for an I/O. The DMA buffer includes the
4168 * number of SGE's necessary to support the sg_tablesize.
4170 lpfc_ncmd
->data
= dma_pool_zalloc(phba
->lpfc_sg_dma_buf_pool
,
4172 &lpfc_ncmd
->dma_handle
);
4173 if (!lpfc_ncmd
->data
) {
4178 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
) {
4179 INIT_LIST_HEAD(&lpfc_ncmd
->dma_sgl_xtra_list
);
4182 * 4K Page alignment is CRITICAL to BlockGuard, double
4185 if ((phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) &&
4186 (((unsigned long)(lpfc_ncmd
->data
) &
4187 (unsigned long)(SLI4_PAGE_SIZE
- 1)) != 0)) {
4188 lpfc_printf_log(phba
, KERN_ERR
,
4190 "3369 Memory alignment err: "
4192 (unsigned long)lpfc_ncmd
->data
);
4193 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
4195 lpfc_ncmd
->dma_handle
);
4201 INIT_LIST_HEAD(&lpfc_ncmd
->dma_cmd_rsp_list
);
4203 lxri
= lpfc_sli4_next_xritag(phba
);
4204 if (lxri
== NO_XRI
) {
4205 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
4206 lpfc_ncmd
->data
, lpfc_ncmd
->dma_handle
);
4210 pwqeq
= &lpfc_ncmd
->cur_iocbq
;
4212 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4213 iotag
= lpfc_sli_next_iotag(phba
, pwqeq
);
4215 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
,
4216 lpfc_ncmd
->data
, lpfc_ncmd
->dma_handle
);
4218 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4219 "6121 Failed to allocate IOTAG for"
4220 " XRI:0x%x\n", lxri
);
4221 lpfc_sli4_free_xri(phba
, lxri
);
4224 pwqeq
->sli4_lxritag
= lxri
;
4225 pwqeq
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
4226 pwqeq
->context1
= lpfc_ncmd
;
4228 /* Initialize local short-hand pointers. */
4229 lpfc_ncmd
->dma_sgl
= lpfc_ncmd
->data
;
4230 lpfc_ncmd
->dma_phys_sgl
= lpfc_ncmd
->dma_handle
;
4231 lpfc_ncmd
->cur_iocbq
.context1
= lpfc_ncmd
;
4232 spin_lock_init(&lpfc_ncmd
->buf_lock
);
4234 /* add the nvme buffer to a post list */
4235 list_add_tail(&lpfc_ncmd
->list
, &post_nblist
);
4236 phba
->sli4_hba
.io_xri_cnt
++;
4238 lpfc_printf_log(phba
, KERN_INFO
, LOG_NVME
,
4239 "6114 Allocate %d out of %d requested new NVME "
4240 "buffers\n", bcnt
, num_to_alloc
);
4242 /* post the list of nvme buffer sgls to port if available */
4243 if (!list_empty(&post_nblist
))
4244 num_posted
= lpfc_sli4_post_io_sgl_list(
4245 phba
, &post_nblist
, bcnt
);
4253 lpfc_get_wwpn(struct lpfc_hba
*phba
)
4257 LPFC_MBOXQ_t
*mboxq
;
4260 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
4263 return (uint64_t)-1;
4265 /* First get WWN of HBA instance */
4266 lpfc_read_nv(phba
, mboxq
);
4267 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4268 if (rc
!= MBX_SUCCESS
) {
4269 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4270 "6019 Mailbox failed , mbxCmd x%x "
4271 "READ_NV, mbxStatus x%x\n",
4272 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4273 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
4274 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4275 return (uint64_t) -1;
4278 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.portname
, sizeof(uint64_t));
4279 /* wwn is WWPN of HBA instance */
4280 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4281 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4282 return be64_to_cpu(wwn
);
4284 return rol64(wwn
, 32);
4288 * lpfc_create_port - Create an FC port
4289 * @phba: pointer to lpfc hba data structure.
4290 * @instance: a unique integer ID to this FC port.
4291 * @dev: pointer to the device data structure.
4293 * This routine creates a FC port for the upper layer protocol. The FC port
4294 * can be created on top of either a physical port or a virtual port provided
4295 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4296 * and associates the FC port created before adding the shost into the SCSI
4300 * @vport - pointer to the virtual N_Port data structure.
4301 * NULL - port create failed.
4304 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
4306 struct lpfc_vport
*vport
;
4307 struct Scsi_Host
*shost
= NULL
;
4308 struct scsi_host_template
*template;
4312 bool use_no_reset_hba
= false;
4315 if (lpfc_no_hba_reset_cnt
) {
4316 if (phba
->sli_rev
< LPFC_SLI_REV4
&&
4317 dev
== &phba
->pcidev
->dev
) {
4318 /* Reset the port first */
4319 lpfc_sli_brdrestart(phba
);
4320 rc
= lpfc_sli_chipset_init(phba
);
4324 wwn
= lpfc_get_wwpn(phba
);
4327 for (i
= 0; i
< lpfc_no_hba_reset_cnt
; i
++) {
4328 if (wwn
== lpfc_no_hba_reset
[i
]) {
4329 lpfc_printf_log(phba
, KERN_ERR
,
4331 "6020 Setting use_no_reset port=%llx\n",
4333 use_no_reset_hba
= true;
4338 /* Seed template for SCSI host registration */
4339 if (dev
== &phba
->pcidev
->dev
) {
4340 template = &phba
->port_template
;
4342 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
4343 /* Seed physical port template */
4344 memcpy(template, &lpfc_template
, sizeof(*template));
4346 if (use_no_reset_hba
) {
4347 /* template is for a no reset SCSI Host */
4348 template->max_sectors
= 0xffff;
4349 template->eh_host_reset_handler
= NULL
;
4352 /* Template for all vports this physical port creates */
4353 memcpy(&phba
->vport_template
, &lpfc_template
,
4355 phba
->vport_template
.max_sectors
= 0xffff;
4356 phba
->vport_template
.shost_attrs
= lpfc_vport_attrs
;
4357 phba
->vport_template
.eh_bus_reset_handler
= NULL
;
4358 phba
->vport_template
.eh_host_reset_handler
= NULL
;
4359 phba
->vport_template
.vendor_id
= 0;
4361 /* Initialize the host templates with updated value */
4362 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4363 template->sg_tablesize
= phba
->cfg_scsi_seg_cnt
;
4364 phba
->vport_template
.sg_tablesize
=
4365 phba
->cfg_scsi_seg_cnt
;
4367 template->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4368 phba
->vport_template
.sg_tablesize
=
4369 phba
->cfg_sg_seg_cnt
;
4373 /* NVMET is for physical port only */
4374 memcpy(template, &lpfc_template_nvme
,
4378 template = &phba
->vport_template
;
4381 shost
= scsi_host_alloc(template, sizeof(struct lpfc_vport
));
4385 vport
= (struct lpfc_vport
*) shost
->hostdata
;
4387 vport
->load_flag
|= FC_LOADING
;
4388 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4389 vport
->fc_rscn_flush
= 0;
4390 lpfc_get_vport_cfgparam(vport
);
4392 /* Adjust value in vport */
4393 vport
->cfg_enable_fc4_type
= phba
->cfg_enable_fc4_type
;
4395 shost
->unique_id
= instance
;
4396 shost
->max_id
= LPFC_MAX_TARGET
;
4397 shost
->max_lun
= vport
->cfg_max_luns
;
4398 shost
->this_id
= -1;
4399 shost
->max_cmd_len
= 16;
4401 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4402 if (!phba
->cfg_fcp_mq_threshold
||
4403 phba
->cfg_fcp_mq_threshold
> phba
->cfg_hdw_queue
)
4404 phba
->cfg_fcp_mq_threshold
= phba
->cfg_hdw_queue
;
4406 shost
->nr_hw_queues
= min_t(int, 2 * num_possible_nodes(),
4407 phba
->cfg_fcp_mq_threshold
);
4409 shost
->dma_boundary
=
4410 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
4412 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
)
4413 shost
->sg_tablesize
= LPFC_MAX_SG_TABLESIZE
;
4415 shost
->sg_tablesize
= phba
->cfg_scsi_seg_cnt
;
4417 /* SLI-3 has a limited number of hardware queues (3),
4418 * thus there is only one for FCP processing.
4420 shost
->nr_hw_queues
= 1;
4423 * Set initial can_queue value since 0 is no longer supported and
4424 * scsi_add_host will fail. This will be adjusted later based on the
4425 * max xri value determined in hba setup.
4427 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
4428 if (dev
!= &phba
->pcidev
->dev
) {
4429 shost
->transportt
= lpfc_vport_transport_template
;
4430 vport
->port_type
= LPFC_NPIV_PORT
;
4432 shost
->transportt
= lpfc_transport_template
;
4433 vport
->port_type
= LPFC_PHYSICAL_PORT
;
4436 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
4437 "9081 CreatePort TMPLATE type %x TBLsize %d "
4439 vport
->port_type
, shost
->sg_tablesize
,
4440 phba
->cfg_scsi_seg_cnt
, phba
->cfg_sg_seg_cnt
);
4442 /* Initialize all internally managed lists. */
4443 INIT_LIST_HEAD(&vport
->fc_nodes
);
4444 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
4445 spin_lock_init(&vport
->work_port_lock
);
4447 timer_setup(&vport
->fc_disctmo
, lpfc_disc_timeout
, 0);
4449 timer_setup(&vport
->els_tmofunc
, lpfc_els_timeout
, 0);
4451 timer_setup(&vport
->delayed_disc_tmo
, lpfc_delayed_disc_tmo
, 0);
4453 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
4454 lpfc_setup_bg(phba
, shost
);
4456 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
4460 spin_lock_irq(&phba
->port_list_lock
);
4461 list_add_tail(&vport
->listentry
, &phba
->port_list
);
4462 spin_unlock_irq(&phba
->port_list_lock
);
4466 scsi_host_put(shost
);
4472 * destroy_port - destroy an FC port
4473 * @vport: pointer to an lpfc virtual N_Port data structure.
4475 * This routine destroys a FC port from the upper layer protocol. All the
4476 * resources associated with the port are released.
4479 destroy_port(struct lpfc_vport
*vport
)
4481 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4482 struct lpfc_hba
*phba
= vport
->phba
;
4484 lpfc_debugfs_terminate(vport
);
4485 fc_remove_host(shost
);
4486 scsi_remove_host(shost
);
4488 spin_lock_irq(&phba
->port_list_lock
);
4489 list_del_init(&vport
->listentry
);
4490 spin_unlock_irq(&phba
->port_list_lock
);
4492 lpfc_cleanup(vport
);
4497 * lpfc_get_instance - Get a unique integer ID
4499 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4500 * uses the kernel idr facility to perform the task.
4503 * instance - a unique integer ID allocated as the new instance.
4504 * -1 - lpfc get instance failed.
4507 lpfc_get_instance(void)
4511 ret
= idr_alloc(&lpfc_hba_index
, NULL
, 0, 0, GFP_KERNEL
);
4512 return ret
< 0 ? -1 : ret
;
4516 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
4517 * @shost: pointer to SCSI host data structure.
4518 * @time: elapsed time of the scan in jiffies.
4520 * This routine is called by the SCSI layer with a SCSI host to determine
4521 * whether the scan host is finished.
4523 * Note: there is no scan_start function as adapter initialization will have
4524 * asynchronously kicked off the link initialization.
4527 * 0 - SCSI host scan is not over yet.
4528 * 1 - SCSI host scan is over.
4530 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
4532 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4533 struct lpfc_hba
*phba
= vport
->phba
;
4536 spin_lock_irq(shost
->host_lock
);
4538 if (vport
->load_flag
& FC_UNLOADING
) {
4542 if (time
>= msecs_to_jiffies(30 * 1000)) {
4543 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4544 "0461 Scanning longer than 30 "
4545 "seconds. Continuing initialization\n");
4549 if (time
>= msecs_to_jiffies(15 * 1000) &&
4550 phba
->link_state
<= LPFC_LINK_DOWN
) {
4551 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4552 "0465 Link down longer than 15 "
4553 "seconds. Continuing initialization\n");
4558 if (vport
->port_state
!= LPFC_VPORT_READY
)
4560 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
4562 if (vport
->fc_map_cnt
== 0 && time
< msecs_to_jiffies(2 * 1000))
4564 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
4570 spin_unlock_irq(shost
->host_lock
);
4574 static void lpfc_host_supported_speeds_set(struct Scsi_Host
*shost
)
4576 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
4577 struct lpfc_hba
*phba
= vport
->phba
;
4579 fc_host_supported_speeds(shost
) = 0;
4581 * Avoid reporting supported link speed for FCoE as it can't be
4582 * controlled via FCoE.
4584 if (phba
->hba_flag
& HBA_FCOE_MODE
)
4587 if (phba
->lmt
& LMT_128Gb
)
4588 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_128GBIT
;
4589 if (phba
->lmt
& LMT_64Gb
)
4590 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_64GBIT
;
4591 if (phba
->lmt
& LMT_32Gb
)
4592 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_32GBIT
;
4593 if (phba
->lmt
& LMT_16Gb
)
4594 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
4595 if (phba
->lmt
& LMT_10Gb
)
4596 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
4597 if (phba
->lmt
& LMT_8Gb
)
4598 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
4599 if (phba
->lmt
& LMT_4Gb
)
4600 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
4601 if (phba
->lmt
& LMT_2Gb
)
4602 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
4603 if (phba
->lmt
& LMT_1Gb
)
4604 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
4608 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
4609 * @shost: pointer to SCSI host data structure.
4611 * This routine initializes a given SCSI host attributes on a FC port. The
4612 * SCSI host can be either on top of a physical port or a virtual port.
4614 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
4616 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4617 struct lpfc_hba
*phba
= vport
->phba
;
4619 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
4622 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
4623 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
4624 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
4626 memset(fc_host_supported_fc4s(shost
), 0,
4627 sizeof(fc_host_supported_fc4s(shost
)));
4628 fc_host_supported_fc4s(shost
)[2] = 1;
4629 fc_host_supported_fc4s(shost
)[7] = 1;
4631 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
4632 sizeof fc_host_symbolic_name(shost
));
4634 lpfc_host_supported_speeds_set(shost
);
4636 fc_host_maxframe_size(shost
) =
4637 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
4638 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
4640 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
4642 /* This value is also unchanging */
4643 memset(fc_host_active_fc4s(shost
), 0,
4644 sizeof(fc_host_active_fc4s(shost
)));
4645 fc_host_active_fc4s(shost
)[2] = 1;
4646 fc_host_active_fc4s(shost
)[7] = 1;
4648 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
4649 spin_lock_irq(shost
->host_lock
);
4650 vport
->load_flag
&= ~FC_LOADING
;
4651 spin_unlock_irq(shost
->host_lock
);
4655 * lpfc_stop_port_s3 - Stop SLI3 device port
4656 * @phba: pointer to lpfc hba data structure.
4658 * This routine is invoked to stop an SLI3 device port, it stops the device
4659 * from generating interrupts and stops the device driver's timers for the
4663 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
4665 /* Clear all interrupt enable conditions */
4666 writel(0, phba
->HCregaddr
);
4667 readl(phba
->HCregaddr
); /* flush */
4668 /* Clear all pending interrupts */
4669 writel(0xffffffff, phba
->HAregaddr
);
4670 readl(phba
->HAregaddr
); /* flush */
4672 /* Reset some HBA SLI setup states */
4673 lpfc_stop_hba_timers(phba
);
4674 phba
->pport
->work_port_events
= 0;
4678 * lpfc_stop_port_s4 - Stop SLI4 device port
4679 * @phba: pointer to lpfc hba data structure.
4681 * This routine is invoked to stop an SLI4 device port, it stops the device
4682 * from generating interrupts and stops the device driver's timers for the
4686 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
4688 /* Reset some HBA SLI4 setup states */
4689 lpfc_stop_hba_timers(phba
);
4691 phba
->pport
->work_port_events
= 0;
4692 phba
->sli4_hba
.intr_enable
= 0;
4696 * lpfc_stop_port - Wrapper function for stopping hba port
4697 * @phba: Pointer to HBA context object.
4699 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4700 * the API jump table function pointer from the lpfc_hba struct.
4703 lpfc_stop_port(struct lpfc_hba
*phba
)
4705 phba
->lpfc_stop_port(phba
);
4708 flush_workqueue(phba
->wq
);
4712 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4713 * @phba: Pointer to hba for which this call is being executed.
4715 * This routine starts the timer waiting for the FCF rediscovery to complete.
4718 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
4720 unsigned long fcf_redisc_wait_tmo
=
4721 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
4722 /* Start fcf rediscovery wait period timer */
4723 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
4724 spin_lock_irq(&phba
->hbalock
);
4725 /* Allow action to new fcf asynchronous event */
4726 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
4727 /* Mark the FCF rediscovery pending state */
4728 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
4729 spin_unlock_irq(&phba
->hbalock
);
4733 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4734 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
4736 * This routine is invoked when waiting for FCF table rediscover has been
4737 * timed out. If new FCF record(s) has (have) been discovered during the
4738 * wait period, a new FCF event shall be added to the FCOE async event
4739 * list, and then worker thread shall be waked up for processing from the
4740 * worker thread context.
4743 lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list
*t
)
4745 struct lpfc_hba
*phba
= from_timer(phba
, t
, fcf
.redisc_wait
);
4747 /* Don't send FCF rediscovery event if timer cancelled */
4748 spin_lock_irq(&phba
->hbalock
);
4749 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
4750 spin_unlock_irq(&phba
->hbalock
);
4753 /* Clear FCF rediscovery timer pending flag */
4754 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
4755 /* FCF rediscovery event to worker thread */
4756 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
4757 spin_unlock_irq(&phba
->hbalock
);
4758 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
4759 "2776 FCF rediscover quiescent timer expired\n");
4760 /* wake up worker thread */
4761 lpfc_worker_wake_up(phba
);
4765 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4766 * @phba: pointer to lpfc hba data structure.
4767 * @acqe_link: pointer to the async link completion queue entry.
4769 * This routine is to parse the SLI4 link-attention link fault code.
4772 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
4773 struct lpfc_acqe_link
*acqe_link
)
4775 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
4776 case LPFC_ASYNC_LINK_FAULT_NONE
:
4777 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
4778 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
4779 case LPFC_ASYNC_LINK_FAULT_LR_LRR
:
4782 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4783 "0398 Unknown link fault code: x%x\n",
4784 bf_get(lpfc_acqe_link_fault
, acqe_link
));
4790 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4791 * @phba: pointer to lpfc hba data structure.
4792 * @acqe_link: pointer to the async link completion queue entry.
4794 * This routine is to parse the SLI4 link attention type and translate it
4795 * into the base driver's link attention type coding.
4797 * Return: Link attention type in terms of base driver's coding.
4800 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
4801 struct lpfc_acqe_link
*acqe_link
)
4805 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
4806 case LPFC_ASYNC_LINK_STATUS_DOWN
:
4807 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
4808 att_type
= LPFC_ATT_LINK_DOWN
;
4810 case LPFC_ASYNC_LINK_STATUS_UP
:
4811 /* Ignore physical link up events - wait for logical link up */
4812 att_type
= LPFC_ATT_RESERVED
;
4814 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
4815 att_type
= LPFC_ATT_LINK_UP
;
4818 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4819 "0399 Invalid link attention type: x%x\n",
4820 bf_get(lpfc_acqe_link_status
, acqe_link
));
4821 att_type
= LPFC_ATT_RESERVED
;
4828 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4829 * @phba: pointer to lpfc hba data structure.
4831 * This routine is to get an SLI3 FC port's link speed in Mbps.
4833 * Return: link speed in terms of Mbps.
4836 lpfc_sli_port_speed_get(struct lpfc_hba
*phba
)
4838 uint32_t link_speed
;
4840 if (!lpfc_is_link_up(phba
))
4843 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
4844 switch (phba
->fc_linkspeed
) {
4845 case LPFC_LINK_SPEED_1GHZ
:
4848 case LPFC_LINK_SPEED_2GHZ
:
4851 case LPFC_LINK_SPEED_4GHZ
:
4854 case LPFC_LINK_SPEED_8GHZ
:
4857 case LPFC_LINK_SPEED_10GHZ
:
4860 case LPFC_LINK_SPEED_16GHZ
:
4867 if (phba
->sli4_hba
.link_state
.logical_speed
)
4869 phba
->sli4_hba
.link_state
.logical_speed
;
4871 link_speed
= phba
->sli4_hba
.link_state
.speed
;
4877 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4878 * @phba: pointer to lpfc hba data structure.
4879 * @evt_code: asynchronous event code.
4880 * @speed_code: asynchronous event link speed code.
4882 * This routine is to parse the giving SLI4 async event link speed code into
4883 * value of Mbps for the link speed.
4885 * Return: link speed in terms of Mbps.
4888 lpfc_sli4_port_speed_parse(struct lpfc_hba
*phba
, uint32_t evt_code
,
4891 uint32_t port_speed
;
4894 case LPFC_TRAILER_CODE_LINK
:
4895 switch (speed_code
) {
4896 case LPFC_ASYNC_LINK_SPEED_ZERO
:
4899 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
4902 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
4905 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
4908 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
4911 case LPFC_ASYNC_LINK_SPEED_20GBPS
:
4914 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
4917 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
4920 case LPFC_ASYNC_LINK_SPEED_100GBPS
:
4921 port_speed
= 100000;
4927 case LPFC_TRAILER_CODE_FC
:
4928 switch (speed_code
) {
4929 case LPFC_FC_LA_SPEED_UNKNOWN
:
4932 case LPFC_FC_LA_SPEED_1G
:
4935 case LPFC_FC_LA_SPEED_2G
:
4938 case LPFC_FC_LA_SPEED_4G
:
4941 case LPFC_FC_LA_SPEED_8G
:
4944 case LPFC_FC_LA_SPEED_10G
:
4947 case LPFC_FC_LA_SPEED_16G
:
4950 case LPFC_FC_LA_SPEED_32G
:
4953 case LPFC_FC_LA_SPEED_64G
:
4956 case LPFC_FC_LA_SPEED_128G
:
4957 port_speed
= 128000;
4970 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4971 * @phba: pointer to lpfc hba data structure.
4972 * @acqe_link: pointer to the async link completion queue entry.
4974 * This routine is to handle the SLI4 asynchronous FCoE link event.
4977 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
4978 struct lpfc_acqe_link
*acqe_link
)
4980 struct lpfc_dmabuf
*mp
;
4983 struct lpfc_mbx_read_top
*la
;
4987 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
4988 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
4990 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
4991 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4993 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4994 "0395 The mboxq allocation failed\n");
4997 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4999 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5000 "0396 The lpfc_dmabuf allocation failed\n");
5003 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
5005 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5006 "0397 The mbuf allocation failed\n");
5007 goto out_free_dmabuf
;
5010 /* Cleanup any outstanding ELS commands */
5011 lpfc_els_flush_all_cmd(phba
);
5013 /* Block ELS IOCBs until we have done process link event */
5014 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
5016 /* Update link event statistics */
5017 phba
->sli
.slistat
.link_event
++;
5019 /* Create lpfc_handle_latt mailbox command from link ACQE */
5020 lpfc_read_topology(phba
, pmb
, mp
);
5021 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
5022 pmb
->vport
= phba
->pport
;
5024 /* Keep the link status for extra SLI4 state machine reference */
5025 phba
->sli4_hba
.link_state
.speed
=
5026 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_LINK
,
5027 bf_get(lpfc_acqe_link_speed
, acqe_link
));
5028 phba
->sli4_hba
.link_state
.duplex
=
5029 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
5030 phba
->sli4_hba
.link_state
.status
=
5031 bf_get(lpfc_acqe_link_status
, acqe_link
);
5032 phba
->sli4_hba
.link_state
.type
=
5033 bf_get(lpfc_acqe_link_type
, acqe_link
);
5034 phba
->sli4_hba
.link_state
.number
=
5035 bf_get(lpfc_acqe_link_number
, acqe_link
);
5036 phba
->sli4_hba
.link_state
.fault
=
5037 bf_get(lpfc_acqe_link_fault
, acqe_link
);
5038 phba
->sli4_hba
.link_state
.logical_speed
=
5039 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
) * 10;
5041 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5042 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5043 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5044 "Logical speed:%dMbps Fault:%d\n",
5045 phba
->sli4_hba
.link_state
.speed
,
5046 phba
->sli4_hba
.link_state
.topology
,
5047 phba
->sli4_hba
.link_state
.status
,
5048 phba
->sli4_hba
.link_state
.type
,
5049 phba
->sli4_hba
.link_state
.number
,
5050 phba
->sli4_hba
.link_state
.logical_speed
,
5051 phba
->sli4_hba
.link_state
.fault
);
5053 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5054 * topology info. Note: Optional for non FC-AL ports.
5056 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
5057 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
5058 if (rc
== MBX_NOT_FINISHED
)
5059 goto out_free_dmabuf
;
5063 * For FCoE Mode: fill in all the topology information we need and call
5064 * the READ_TOPOLOGY completion routine to continue without actually
5065 * sending the READ_TOPOLOGY mailbox command to the port.
5067 /* Initialize completion status */
5069 mb
->mbxStatus
= MBX_SUCCESS
;
5071 /* Parse port fault information field */
5072 lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
5074 /* Parse and translate link attention fields */
5075 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
5076 la
->eventTag
= acqe_link
->event_tag
;
5077 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
5078 bf_set(lpfc_mbx_read_top_link_spd
, la
,
5079 (bf_get(lpfc_acqe_link_speed
, acqe_link
)));
5081 /* Fake the the following irrelvant fields */
5082 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
5083 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
5084 bf_set(lpfc_mbx_read_top_il
, la
, 0);
5085 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
5086 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
5087 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
5089 /* Invoke the lpfc_handle_latt mailbox command callback function */
5090 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
5097 mempool_free(pmb
, phba
->mbox_mem_pool
);
5101 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5103 * @phba: pointer to lpfc hba data structure.
5104 * @speed_code: asynchronous event link speed code.
5106 * This routine is to parse the giving SLI4 async event link speed code into
5107 * value of Read topology link speed.
5109 * Return: link speed in terms of Read topology.
5112 lpfc_async_link_speed_to_read_top(struct lpfc_hba
*phba
, uint8_t speed_code
)
5116 switch (speed_code
) {
5117 case LPFC_FC_LA_SPEED_1G
:
5118 port_speed
= LPFC_LINK_SPEED_1GHZ
;
5120 case LPFC_FC_LA_SPEED_2G
:
5121 port_speed
= LPFC_LINK_SPEED_2GHZ
;
5123 case LPFC_FC_LA_SPEED_4G
:
5124 port_speed
= LPFC_LINK_SPEED_4GHZ
;
5126 case LPFC_FC_LA_SPEED_8G
:
5127 port_speed
= LPFC_LINK_SPEED_8GHZ
;
5129 case LPFC_FC_LA_SPEED_16G
:
5130 port_speed
= LPFC_LINK_SPEED_16GHZ
;
5132 case LPFC_FC_LA_SPEED_32G
:
5133 port_speed
= LPFC_LINK_SPEED_32GHZ
;
5135 case LPFC_FC_LA_SPEED_64G
:
5136 port_speed
= LPFC_LINK_SPEED_64GHZ
;
5138 case LPFC_FC_LA_SPEED_128G
:
5139 port_speed
= LPFC_LINK_SPEED_128GHZ
;
5141 case LPFC_FC_LA_SPEED_256G
:
5142 port_speed
= LPFC_LINK_SPEED_256GHZ
;
5152 #define trunk_link_status(__idx)\
5153 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5154 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5155 "Link up" : "Link down") : "NA"
5156 /* Did port __idx reported an error */
5157 #define trunk_port_fault(__idx)\
5158 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5159 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5162 lpfc_update_trunk_link_status(struct lpfc_hba
*phba
,
5163 struct lpfc_acqe_fc_la
*acqe_fc
)
5165 uint8_t port_fault
= bf_get(lpfc_acqe_fc_la_trunk_linkmask
, acqe_fc
);
5166 uint8_t err
= bf_get(lpfc_acqe_fc_la_trunk_fault
, acqe_fc
);
5168 phba
->sli4_hba
.link_state
.speed
=
5169 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
5170 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
5172 phba
->sli4_hba
.link_state
.logical_speed
=
5173 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
5174 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5175 phba
->fc_linkspeed
=
5176 lpfc_async_link_speed_to_read_top(
5178 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
5180 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0
, acqe_fc
)) {
5181 phba
->trunk_link
.link0
.state
=
5182 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0
, acqe_fc
)
5183 ? LPFC_LINK_UP
: LPFC_LINK_DOWN
;
5184 phba
->trunk_link
.link0
.fault
= port_fault
& 0x1 ? err
: 0;
5186 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1
, acqe_fc
)) {
5187 phba
->trunk_link
.link1
.state
=
5188 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1
, acqe_fc
)
5189 ? LPFC_LINK_UP
: LPFC_LINK_DOWN
;
5190 phba
->trunk_link
.link1
.fault
= port_fault
& 0x2 ? err
: 0;
5192 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2
, acqe_fc
)) {
5193 phba
->trunk_link
.link2
.state
=
5194 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2
, acqe_fc
)
5195 ? LPFC_LINK_UP
: LPFC_LINK_DOWN
;
5196 phba
->trunk_link
.link2
.fault
= port_fault
& 0x4 ? err
: 0;
5198 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3
, acqe_fc
)) {
5199 phba
->trunk_link
.link3
.state
=
5200 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3
, acqe_fc
)
5201 ? LPFC_LINK_UP
: LPFC_LINK_DOWN
;
5202 phba
->trunk_link
.link3
.fault
= port_fault
& 0x8 ? err
: 0;
5205 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5206 "2910 Async FC Trunking Event - Speed:%d\n"
5207 "\tLogical speed:%d "
5208 "port0: %s port1: %s port2: %s port3: %s\n",
5209 phba
->sli4_hba
.link_state
.speed
,
5210 phba
->sli4_hba
.link_state
.logical_speed
,
5211 trunk_link_status(0), trunk_link_status(1),
5212 trunk_link_status(2), trunk_link_status(3));
5215 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5216 "3202 trunk error:0x%x (%s) seen on port0:%s "
5218 * SLI-4: We have only 0xA error codes
5219 * defined as of now. print an appropriate
5220 * message in case driver needs to be updated.
5222 "port1:%s port2:%s port3:%s\n", err
, err
> 0xA ?
5223 "UNDEFINED. update driver." : trunk_errmsg
[err
],
5224 trunk_port_fault(0), trunk_port_fault(1),
5225 trunk_port_fault(2), trunk_port_fault(3));
5230 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5231 * @phba: pointer to lpfc hba data structure.
5232 * @acqe_fc: pointer to the async fc completion queue entry.
5234 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5235 * that the event was received and then issue a read_topology mailbox command so
5236 * that the rest of the driver will treat it the same as SLI3.
5239 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
5241 struct lpfc_dmabuf
*mp
;
5244 struct lpfc_mbx_read_top
*la
;
5247 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
5248 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
5249 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5250 "2895 Non FC link Event detected.(%d)\n",
5251 bf_get(lpfc_trailer_type
, acqe_fc
));
5255 if (bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
) ==
5256 LPFC_FC_LA_TYPE_TRUNKING_EVENT
) {
5257 lpfc_update_trunk_link_status(phba
, acqe_fc
);
5261 /* Keep the link status for extra SLI4 state machine reference */
5262 phba
->sli4_hba
.link_state
.speed
=
5263 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
5264 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
5265 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
5266 phba
->sli4_hba
.link_state
.topology
=
5267 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
5268 phba
->sli4_hba
.link_state
.status
=
5269 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
5270 phba
->sli4_hba
.link_state
.type
=
5271 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
5272 phba
->sli4_hba
.link_state
.number
=
5273 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
5274 phba
->sli4_hba
.link_state
.fault
=
5275 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
5277 if (bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
) ==
5278 LPFC_FC_LA_TYPE_LINK_DOWN
)
5279 phba
->sli4_hba
.link_state
.logical_speed
= 0;
5280 else if (!phba
->sli4_hba
.conf_trunk
)
5281 phba
->sli4_hba
.link_state
.logical_speed
=
5282 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
5284 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5285 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5286 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5287 "%dMbps Fault:%d\n",
5288 phba
->sli4_hba
.link_state
.speed
,
5289 phba
->sli4_hba
.link_state
.topology
,
5290 phba
->sli4_hba
.link_state
.status
,
5291 phba
->sli4_hba
.link_state
.type
,
5292 phba
->sli4_hba
.link_state
.number
,
5293 phba
->sli4_hba
.link_state
.logical_speed
,
5294 phba
->sli4_hba
.link_state
.fault
);
5295 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5297 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5298 "2897 The mboxq allocation failed\n");
5301 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5303 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5304 "2898 The lpfc_dmabuf allocation failed\n");
5307 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
5309 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5310 "2899 The mbuf allocation failed\n");
5311 goto out_free_dmabuf
;
5314 /* Cleanup any outstanding ELS commands */
5315 lpfc_els_flush_all_cmd(phba
);
5317 /* Block ELS IOCBs until we have done process link event */
5318 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
5320 /* Update link event statistics */
5321 phba
->sli
.slistat
.link_event
++;
5323 /* Create lpfc_handle_latt mailbox command from link ACQE */
5324 lpfc_read_topology(phba
, pmb
, mp
);
5325 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
5326 pmb
->vport
= phba
->pport
;
5328 if (phba
->sli4_hba
.link_state
.status
!= LPFC_FC_LA_TYPE_LINK_UP
) {
5329 phba
->link_flag
&= ~(LS_MDS_LINK_DOWN
| LS_MDS_LOOPBACK
);
5331 switch (phba
->sli4_hba
.link_state
.status
) {
5332 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN
:
5333 phba
->link_flag
|= LS_MDS_LINK_DOWN
;
5335 case LPFC_FC_LA_TYPE_MDS_LOOPBACK
:
5336 phba
->link_flag
|= LS_MDS_LOOPBACK
;
5342 /* Initialize completion status */
5344 mb
->mbxStatus
= MBX_SUCCESS
;
5346 /* Parse port fault information field */
5347 lpfc_sli4_parse_latt_fault(phba
, (void *)acqe_fc
);
5349 /* Parse and translate link attention fields */
5350 la
= (struct lpfc_mbx_read_top
*)&pmb
->u
.mb
.un
.varReadTop
;
5351 la
->eventTag
= acqe_fc
->event_tag
;
5353 if (phba
->sli4_hba
.link_state
.status
==
5354 LPFC_FC_LA_TYPE_UNEXP_WWPN
) {
5355 bf_set(lpfc_mbx_read_top_att_type
, la
,
5356 LPFC_FC_LA_TYPE_UNEXP_WWPN
);
5358 bf_set(lpfc_mbx_read_top_att_type
, la
,
5359 LPFC_FC_LA_TYPE_LINK_DOWN
);
5361 /* Invoke the mailbox command callback function */
5362 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
5367 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
5368 if (rc
== MBX_NOT_FINISHED
)
5369 goto out_free_dmabuf
;
5375 mempool_free(pmb
, phba
->mbox_mem_pool
);
5379 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5380 * @phba: pointer to lpfc hba data structure.
5381 * @acqe_sli: pointer to the async SLI completion queue entry.
5383 * This routine is to handle the SLI4 asynchronous SLI events.
5386 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
5392 uint8_t operational
= 0;
5393 struct temp_event temp_event_data
;
5394 struct lpfc_acqe_misconfigured_event
*misconfigured
;
5395 struct Scsi_Host
*shost
;
5396 struct lpfc_vport
**vports
;
5399 evt_type
= bf_get(lpfc_trailer_type
, acqe_sli
);
5401 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5402 "2901 Async SLI event - Type:%d, Event Data: x%08x "
5403 "x%08x x%08x x%08x\n", evt_type
,
5404 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
5405 acqe_sli
->reserved
, acqe_sli
->trailer
);
5407 port_name
= phba
->Port
[0];
5408 if (port_name
== 0x00)
5409 port_name
= '?'; /* get port name is empty */
5412 case LPFC_SLI_EVENT_TYPE_OVER_TEMP
:
5413 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
5414 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
5415 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
5417 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5418 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5419 acqe_sli
->event_data1
, port_name
);
5421 phba
->sfp_warning
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
5422 shost
= lpfc_shost_from_vport(phba
->pport
);
5423 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5424 sizeof(temp_event_data
),
5425 (char *)&temp_event_data
,
5426 SCSI_NL_VID_TYPE_PCI
5427 | PCI_VENDOR_ID_EMULEX
);
5429 case LPFC_SLI_EVENT_TYPE_NORM_TEMP
:
5430 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
5431 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
5432 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
5434 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5435 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5436 acqe_sli
->event_data1
, port_name
);
5438 shost
= lpfc_shost_from_vport(phba
->pport
);
5439 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5440 sizeof(temp_event_data
),
5441 (char *)&temp_event_data
,
5442 SCSI_NL_VID_TYPE_PCI
5443 | PCI_VENDOR_ID_EMULEX
);
5445 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED
:
5446 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
5447 &acqe_sli
->event_data1
;
5449 /* fetch the status for this port */
5450 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5451 case LPFC_LINK_NUMBER_0
:
5452 status
= bf_get(lpfc_sli_misconfigured_port0_state
,
5453 &misconfigured
->theEvent
);
5454 operational
= bf_get(lpfc_sli_misconfigured_port0_op
,
5455 &misconfigured
->theEvent
);
5457 case LPFC_LINK_NUMBER_1
:
5458 status
= bf_get(lpfc_sli_misconfigured_port1_state
,
5459 &misconfigured
->theEvent
);
5460 operational
= bf_get(lpfc_sli_misconfigured_port1_op
,
5461 &misconfigured
->theEvent
);
5463 case LPFC_LINK_NUMBER_2
:
5464 status
= bf_get(lpfc_sli_misconfigured_port2_state
,
5465 &misconfigured
->theEvent
);
5466 operational
= bf_get(lpfc_sli_misconfigured_port2_op
,
5467 &misconfigured
->theEvent
);
5469 case LPFC_LINK_NUMBER_3
:
5470 status
= bf_get(lpfc_sli_misconfigured_port3_state
,
5471 &misconfigured
->theEvent
);
5472 operational
= bf_get(lpfc_sli_misconfigured_port3_op
,
5473 &misconfigured
->theEvent
);
5476 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5478 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5479 "event: Invalid link %d",
5480 phba
->sli4_hba
.lnk_info
.lnk_no
);
5484 /* Skip if optic state unchanged */
5485 if (phba
->sli4_hba
.lnk_info
.optic_state
== status
)
5489 case LPFC_SLI_EVENT_STATUS_VALID
:
5490 sprintf(message
, "Physical Link is functional");
5492 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
5493 sprintf(message
, "Optics faulted/incorrectly "
5494 "installed/not installed - Reseat optics, "
5495 "if issue not resolved, replace.");
5497 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
5499 "Optics of two types installed - Remove one "
5500 "optic or install matching pair of optics.");
5502 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
5503 sprintf(message
, "Incompatible optics - Replace with "
5504 "compatible optics for card to function.");
5506 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED
:
5507 sprintf(message
, "Unqualified optics - Replace with "
5508 "Avago optics for Warranty and Technical "
5509 "Support - Link is%s operational",
5510 (operational
) ? " not" : "");
5512 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED
:
5513 sprintf(message
, "Uncertified optics - Replace with "
5514 "Avago-certified optics to enable link "
5515 "operation - Link is%s operational",
5516 (operational
) ? " not" : "");
5519 /* firmware is reporting a status we don't know about */
5520 sprintf(message
, "Unknown event status x%02x", status
);
5524 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5525 rc
= lpfc_sli4_read_config(phba
);
5528 lpfc_printf_log(phba
, KERN_ERR
,
5530 "3194 Unable to retrieve supported "
5531 "speeds, rc = 0x%x\n", rc
);
5533 vports
= lpfc_create_vport_work_array(phba
);
5534 if (vports
!= NULL
) {
5535 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
5537 shost
= lpfc_shost_from_vport(vports
[i
]);
5538 lpfc_host_supported_speeds_set(shost
);
5541 lpfc_destroy_vport_work_array(phba
, vports
);
5543 phba
->sli4_hba
.lnk_info
.optic_state
= status
;
5544 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5545 "3176 Port Name %c %s\n", port_name
, message
);
5547 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT
:
5548 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5549 "3192 Remote DPort Test Initiated - "
5550 "Event Data1:x%08x Event Data2: x%08x\n",
5551 acqe_sli
->event_data1
, acqe_sli
->event_data2
);
5553 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN
:
5554 /* Misconfigured WWN. Reports that the SLI Port is configured
5555 * to use FA-WWN, but the attached device doesn’t support it.
5556 * No driver action is required.
5557 * Event Data1 - N.A, Event Data2 - N.A
5559 lpfc_log_msg(phba
, KERN_WARNING
, LOG_SLI
,
5560 "2699 Misconfigured FA-WWN - Attached device does "
5561 "not support FA-WWN\n");
5563 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE
:
5564 /* EEPROM failure. No driver action is required */
5565 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5566 "2518 EEPROM failure - "
5567 "Event Data1: x%08x Event Data2: x%08x\n",
5568 acqe_sli
->event_data1
, acqe_sli
->event_data2
);
5571 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5572 "3193 Unrecognized SLI event, type: 0x%x",
5579 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5580 * @vport: pointer to vport data structure.
5582 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5583 * response to a CVL event.
5585 * Return the pointer to the ndlp with the vport if successful, otherwise
5588 static struct lpfc_nodelist
*
5589 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
5591 struct lpfc_nodelist
*ndlp
;
5592 struct Scsi_Host
*shost
;
5593 struct lpfc_hba
*phba
;
5600 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
5602 /* Cannot find existing Fabric ndlp, so allocate a new one */
5603 ndlp
= lpfc_nlp_init(vport
, Fabric_DID
);
5606 /* Set the node type */
5607 ndlp
->nlp_type
|= NLP_FABRIC
;
5608 /* Put ndlp onto node list */
5609 lpfc_enqueue_node(vport
, ndlp
);
5610 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5611 /* re-setup ndlp without removing from node list */
5612 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
5616 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
5617 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
5619 /* If virtual link is not yet instantiated ignore CVL */
5620 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
5621 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
5623 shost
= lpfc_shost_from_vport(vport
);
5626 lpfc_linkdown_port(vport
);
5627 lpfc_cleanup_pending_mbox(vport
);
5628 spin_lock_irq(shost
->host_lock
);
5629 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
5630 spin_unlock_irq(shost
->host_lock
);
5636 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
5637 * @phba: pointer to lpfc hba data structure.
5639 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5640 * response to a FCF dead event.
5643 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
5645 struct lpfc_vport
**vports
;
5648 vports
= lpfc_create_vport_work_array(phba
);
5650 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
5651 lpfc_sli4_perform_vport_cvl(vports
[i
]);
5652 lpfc_destroy_vport_work_array(phba
, vports
);
5656 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
5657 * @phba: pointer to lpfc hba data structure.
5658 * @acqe_fip: pointer to the async fcoe completion queue entry.
5660 * This routine is to handle the SLI4 asynchronous fcoe event.
5663 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
5664 struct lpfc_acqe_fip
*acqe_fip
)
5666 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
5668 struct lpfc_vport
*vport
;
5669 struct lpfc_nodelist
*ndlp
;
5670 struct Scsi_Host
*shost
;
5671 int active_vlink_present
;
5672 struct lpfc_vport
**vports
;
5675 phba
->fc_eventTag
= acqe_fip
->event_tag
;
5676 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
5677 switch (event_type
) {
5678 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
5679 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
5680 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
5681 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5682 "2546 New FCF event, evt_tag:x%x, "
5684 acqe_fip
->event_tag
,
5687 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
5689 "2788 FCF param modified event, "
5690 "evt_tag:x%x, index:x%x\n",
5691 acqe_fip
->event_tag
,
5693 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
5695 * During period of FCF discovery, read the FCF
5696 * table record indexed by the event to update
5697 * FCF roundrobin failover eligible FCF bmask.
5699 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
5701 "2779 Read FCF (x%x) for updating "
5702 "roundrobin FCF failover bmask\n",
5704 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
5707 /* If the FCF discovery is in progress, do nothing. */
5708 spin_lock_irq(&phba
->hbalock
);
5709 if (phba
->hba_flag
& FCF_TS_INPROG
) {
5710 spin_unlock_irq(&phba
->hbalock
);
5713 /* If fast FCF failover rescan event is pending, do nothing */
5714 if (phba
->fcf
.fcf_flag
& (FCF_REDISC_EVT
| FCF_REDISC_PEND
)) {
5715 spin_unlock_irq(&phba
->hbalock
);
5719 /* If the FCF has been in discovered state, do nothing. */
5720 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
5721 spin_unlock_irq(&phba
->hbalock
);
5724 spin_unlock_irq(&phba
->hbalock
);
5726 /* Otherwise, scan the entire FCF table and re-discover SAN */
5727 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
5728 "2770 Start FCF table scan per async FCF "
5729 "event, evt_tag:x%x, index:x%x\n",
5730 acqe_fip
->event_tag
, acqe_fip
->index
);
5731 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
5732 LPFC_FCOE_FCF_GET_FIRST
);
5734 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5735 "2547 Issue FCF scan read FCF mailbox "
5736 "command failed (x%x)\n", rc
);
5739 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
5740 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5741 "2548 FCF Table full count 0x%x tag 0x%x\n",
5742 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
5743 acqe_fip
->event_tag
);
5746 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
5747 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
5748 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5749 "2549 FCF (x%x) disconnected from network, "
5750 "tag:x%x\n", acqe_fip
->index
,
5751 acqe_fip
->event_tag
);
5753 * If we are in the middle of FCF failover process, clear
5754 * the corresponding FCF bit in the roundrobin bitmap.
5756 spin_lock_irq(&phba
->hbalock
);
5757 if ((phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
5758 (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)) {
5759 spin_unlock_irq(&phba
->hbalock
);
5760 /* Update FLOGI FCF failover eligible FCF bmask */
5761 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
5764 spin_unlock_irq(&phba
->hbalock
);
5766 /* If the event is not for currently used fcf do nothing */
5767 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
5771 * Otherwise, request the port to rediscover the entire FCF
5772 * table for a fast recovery from case that the current FCF
5773 * is no longer valid as we are not in the middle of FCF
5774 * failover process already.
5776 spin_lock_irq(&phba
->hbalock
);
5777 /* Mark the fast failover process in progress */
5778 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
5779 spin_unlock_irq(&phba
->hbalock
);
5781 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
5782 "2771 Start FCF fast failover process due to "
5783 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5784 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
5785 rc
= lpfc_sli4_redisc_fcf_table(phba
);
5787 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
5789 "2772 Issue FCF rediscover mailbox "
5790 "command failed, fail through to FCF "
5792 spin_lock_irq(&phba
->hbalock
);
5793 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
5794 spin_unlock_irq(&phba
->hbalock
);
5796 * Last resort will fail over by treating this
5797 * as a link down to FCF registration.
5799 lpfc_sli4_fcf_dead_failthrough(phba
);
5801 /* Reset FCF roundrobin bmask for new discovery */
5802 lpfc_sli4_clear_fcf_rr_bmask(phba
);
5804 * Handling fast FCF failover to a DEAD FCF event is
5805 * considered equalivant to receiving CVL to all vports.
5807 lpfc_sli4_perform_all_vport_cvl(phba
);
5810 case LPFC_FIP_EVENT_TYPE_CVL
:
5811 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
5812 lpfc_printf_log(phba
, KERN_ERR
,
5814 "2718 Clear Virtual Link Received for VPI 0x%x"
5815 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
5817 vport
= lpfc_find_vport_by_vpid(phba
,
5819 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
5822 active_vlink_present
= 0;
5824 vports
= lpfc_create_vport_work_array(phba
);
5826 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
5828 if ((!(vports
[i
]->fc_flag
&
5829 FC_VPORT_CVL_RCVD
)) &&
5830 (vports
[i
]->port_state
> LPFC_FDISC
)) {
5831 active_vlink_present
= 1;
5835 lpfc_destroy_vport_work_array(phba
, vports
);
5839 * Don't re-instantiate if vport is marked for deletion.
5840 * If we are here first then vport_delete is going to wait
5841 * for discovery to complete.
5843 if (!(vport
->load_flag
& FC_UNLOADING
) &&
5844 active_vlink_present
) {
5846 * If there are other active VLinks present,
5847 * re-instantiate the Vlink using FDISC.
5849 mod_timer(&ndlp
->nlp_delayfunc
,
5850 jiffies
+ msecs_to_jiffies(1000));
5851 shost
= lpfc_shost_from_vport(vport
);
5852 spin_lock_irq(shost
->host_lock
);
5853 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
5854 spin_unlock_irq(shost
->host_lock
);
5855 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
5856 vport
->port_state
= LPFC_FDISC
;
5859 * Otherwise, we request port to rediscover
5860 * the entire FCF table for a fast recovery
5861 * from possible case that the current FCF
5862 * is no longer valid if we are not already
5863 * in the FCF failover process.
5865 spin_lock_irq(&phba
->hbalock
);
5866 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
5867 spin_unlock_irq(&phba
->hbalock
);
5870 /* Mark the fast failover process in progress */
5871 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
5872 spin_unlock_irq(&phba
->hbalock
);
5873 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
5875 "2773 Start FCF failover per CVL, "
5876 "evt_tag:x%x\n", acqe_fip
->event_tag
);
5877 rc
= lpfc_sli4_redisc_fcf_table(phba
);
5879 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
5881 "2774 Issue FCF rediscover "
5882 "mailbox command failed, "
5883 "through to CVL event\n");
5884 spin_lock_irq(&phba
->hbalock
);
5885 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
5886 spin_unlock_irq(&phba
->hbalock
);
5888 * Last resort will be re-try on the
5889 * the current registered FCF entry.
5891 lpfc_retry_pport_discovery(phba
);
5894 * Reset FCF roundrobin bmask for new
5897 lpfc_sli4_clear_fcf_rr_bmask(phba
);
5901 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5902 "0288 Unknown FCoE event type 0x%x event tag "
5903 "0x%x\n", event_type
, acqe_fip
->event_tag
);
5909 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5910 * @phba: pointer to lpfc hba data structure.
5911 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
5913 * This routine is to handle the SLI4 asynchronous dcbx event.
5916 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
5917 struct lpfc_acqe_dcbx
*acqe_dcbx
)
5919 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
5920 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
5921 "0290 The SLI4 DCBX asynchronous event is not "
5926 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5927 * @phba: pointer to lpfc hba data structure.
5928 * @acqe_grp5: pointer to the async grp5 completion queue entry.
5930 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5931 * is an asynchronous notified of a logical link speed change. The Port
5932 * reports the logical link speed in units of 10Mbps.
5935 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
5936 struct lpfc_acqe_grp5
*acqe_grp5
)
5938 uint16_t prev_ll_spd
;
5940 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
5941 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
5942 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
5943 phba
->sli4_hba
.link_state
.logical_speed
=
5944 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
)) * 10;
5945 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5946 "2789 GRP5 Async Event: Updating logical link speed "
5947 "from %dMbps to %dMbps\n", prev_ll_spd
,
5948 phba
->sli4_hba
.link_state
.logical_speed
);
5952 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5953 * @phba: pointer to lpfc hba data structure.
5955 * This routine is invoked by the worker thread to process all the pending
5956 * SLI4 asynchronous events.
5958 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
5960 struct lpfc_cq_event
*cq_event
;
5962 /* First, declare the async event has been handled */
5963 spin_lock_irq(&phba
->hbalock
);
5964 phba
->hba_flag
&= ~ASYNC_EVENT
;
5965 spin_unlock_irq(&phba
->hbalock
);
5966 /* Now, handle all the async events */
5967 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
5968 /* Get the first event from the head of the event queue */
5969 spin_lock_irq(&phba
->hbalock
);
5970 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
5971 cq_event
, struct lpfc_cq_event
, list
);
5972 spin_unlock_irq(&phba
->hbalock
);
5973 /* Process the asynchronous event */
5974 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
5975 case LPFC_TRAILER_CODE_LINK
:
5976 lpfc_sli4_async_link_evt(phba
,
5977 &cq_event
->cqe
.acqe_link
);
5979 case LPFC_TRAILER_CODE_FCOE
:
5980 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
5982 case LPFC_TRAILER_CODE_DCBX
:
5983 lpfc_sli4_async_dcbx_evt(phba
,
5984 &cq_event
->cqe
.acqe_dcbx
);
5986 case LPFC_TRAILER_CODE_GRP5
:
5987 lpfc_sli4_async_grp5_evt(phba
,
5988 &cq_event
->cqe
.acqe_grp5
);
5990 case LPFC_TRAILER_CODE_FC
:
5991 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
5993 case LPFC_TRAILER_CODE_SLI
:
5994 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
5997 lpfc_printf_log(phba
, KERN_ERR
,
5999 "1804 Invalid asynchronous event code: "
6000 "x%x\n", bf_get(lpfc_trailer_code
,
6001 &cq_event
->cqe
.mcqe_cmpl
));
6004 /* Free the completion event processed to the free pool */
6005 lpfc_sli4_cq_event_release(phba
, cq_event
);
6010 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
6011 * @phba: pointer to lpfc hba data structure.
6013 * This routine is invoked by the worker thread to process FCF table
6014 * rediscovery pending completion event.
6016 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
6020 spin_lock_irq(&phba
->hbalock
);
6021 /* Clear FCF rediscovery timeout event */
6022 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
6023 /* Clear driver fast failover FCF record flag */
6024 phba
->fcf
.failover_rec
.flag
= 0;
6025 /* Set state for FCF fast failover */
6026 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
6027 spin_unlock_irq(&phba
->hbalock
);
6029 /* Scan FCF table from the first entry to re-discover SAN */
6030 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
6031 "2777 Start post-quiescent FCF table scan\n");
6032 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
6034 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6035 "2747 Issue FCF scan read FCF mailbox "
6036 "command failed 0x%x\n", rc
);
6040 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
6041 * @phba: pointer to lpfc hba data structure.
6042 * @dev_grp: The HBA PCI-Device group number.
6044 * This routine is invoked to set up the per HBA PCI-Device group function
6045 * API jump table entries.
6047 * Return: 0 if success, otherwise -ENODEV
6050 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6054 /* Set up lpfc PCI-device group */
6055 phba
->pci_dev_grp
= dev_grp
;
6057 /* The LPFC_PCI_DEV_OC uses SLI4 */
6058 if (dev_grp
== LPFC_PCI_DEV_OC
)
6059 phba
->sli_rev
= LPFC_SLI_REV4
;
6061 /* Set up device INIT API function jump table */
6062 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
6065 /* Set up SCSI API function jump table */
6066 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
6069 /* Set up SLI API function jump table */
6070 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
6073 /* Set up MBOX API function jump table */
6074 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
6082 * lpfc_log_intr_mode - Log the active interrupt mode
6083 * @phba: pointer to lpfc hba data structure.
6084 * @intr_mode: active interrupt mode adopted.
6086 * This routine it invoked to log the currently used active interrupt mode
6089 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
6091 switch (intr_mode
) {
6093 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6094 "0470 Enable INTx interrupt mode.\n");
6097 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6098 "0481 Enabled MSI interrupt mode.\n");
6101 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6102 "0480 Enabled MSI-X interrupt mode.\n");
6105 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6106 "0482 Illegal interrupt mode.\n");
6113 * lpfc_enable_pci_dev - Enable a generic PCI device.
6114 * @phba: pointer to lpfc hba data structure.
6116 * This routine is invoked to enable the PCI device that is common to all
6121 * other values - error
6124 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
6126 struct pci_dev
*pdev
;
6128 /* Obtain PCI device reference */
6132 pdev
= phba
->pcidev
;
6133 /* Enable PCI device */
6134 if (pci_enable_device_mem(pdev
))
6136 /* Request PCI resource for the device */
6137 if (pci_request_mem_regions(pdev
, LPFC_DRIVER_NAME
))
6138 goto out_disable_device
;
6139 /* Set up device as PCI master and save state for EEH */
6140 pci_set_master(pdev
);
6141 pci_try_set_mwi(pdev
);
6142 pci_save_state(pdev
);
6144 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
6145 if (pci_is_pcie(pdev
))
6146 pdev
->needs_freset
= 1;
6151 pci_disable_device(pdev
);
6153 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6154 "1401 Failed to enable pci device\n");
6159 * lpfc_disable_pci_dev - Disable a generic PCI device.
6160 * @phba: pointer to lpfc hba data structure.
6162 * This routine is invoked to disable the PCI device that is common to all
6166 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
6168 struct pci_dev
*pdev
;
6170 /* Obtain PCI device reference */
6174 pdev
= phba
->pcidev
;
6175 /* Release PCI resource and disable PCI device */
6176 pci_release_mem_regions(pdev
);
6177 pci_disable_device(pdev
);
6183 * lpfc_reset_hba - Reset a hba
6184 * @phba: pointer to lpfc hba data structure.
6186 * This routine is invoked to reset a hba device. It brings the HBA
6187 * offline, performs a board restart, and then brings the board back
6188 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6189 * on outstanding mailbox commands.
6192 lpfc_reset_hba(struct lpfc_hba
*phba
)
6194 /* If resets are disabled then set error state and return. */
6195 if (!phba
->cfg_enable_hba_reset
) {
6196 phba
->link_state
= LPFC_HBA_ERROR
;
6199 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
6200 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
6202 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
6204 lpfc_sli_brdrestart(phba
);
6206 lpfc_unblock_mgmt_io(phba
);
6210 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6211 * @phba: pointer to lpfc hba data structure.
6213 * This function enables the PCI SR-IOV virtual functions to a physical
6214 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6215 * enable the number of virtual functions to the physical function. As
6216 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6217 * API call does not considered as an error condition for most of the device.
6220 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
6222 struct pci_dev
*pdev
= phba
->pcidev
;
6226 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
6230 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
6235 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6236 * @phba: pointer to lpfc hba data structure.
6237 * @nr_vfn: number of virtual functions to be enabled.
6239 * This function enables the PCI SR-IOV virtual functions to a physical
6240 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6241 * enable the number of virtual functions to the physical function. As
6242 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6243 * API call does not considered as an error condition for most of the device.
6246 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
6248 struct pci_dev
*pdev
= phba
->pcidev
;
6249 uint16_t max_nr_vfn
;
6252 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
6253 if (nr_vfn
> max_nr_vfn
) {
6254 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6255 "3057 Requested vfs (%d) greater than "
6256 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
6260 rc
= pci_enable_sriov(pdev
, nr_vfn
);
6262 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6263 "2806 Failed to enable sriov on this device "
6264 "with vfn number nr_vf:%d, rc:%d\n",
6267 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6268 "2807 Successful enable sriov on this device "
6269 "with vfn number nr_vf:%d\n", nr_vfn
);
6274 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
6275 * @phba: pointer to lpfc hba data structure.
6277 * This routine is invoked to set up the driver internal resources before the
6278 * device specific resource setup to support the HBA device it attached to.
6282 * other values - error
6285 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
6287 struct lpfc_sli
*psli
= &phba
->sli
;
6290 * Driver resources common to all SLI revisions
6292 atomic_set(&phba
->fast_event_count
, 0);
6293 atomic_set(&phba
->dbg_log_idx
, 0);
6294 atomic_set(&phba
->dbg_log_cnt
, 0);
6295 atomic_set(&phba
->dbg_log_dmping
, 0);
6296 spin_lock_init(&phba
->hbalock
);
6298 /* Initialize ndlp management spinlock */
6299 spin_lock_init(&phba
->ndlp_lock
);
6301 /* Initialize port_list spinlock */
6302 spin_lock_init(&phba
->port_list_lock
);
6303 INIT_LIST_HEAD(&phba
->port_list
);
6305 INIT_LIST_HEAD(&phba
->work_list
);
6306 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
6308 /* Initialize the wait queue head for the kernel thread */
6309 init_waitqueue_head(&phba
->work_waitq
);
6311 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6312 "1403 Protocols supported %s %s %s\n",
6313 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) ?
6315 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) ?
6317 (phba
->nvmet_support
? "NVMET" : " "));
6319 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
6320 spin_lock_init(&phba
->scsi_buf_list_get_lock
);
6321 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_get
);
6322 spin_lock_init(&phba
->scsi_buf_list_put_lock
);
6323 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
6325 /* Initialize the fabric iocb list */
6326 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
6328 /* Initialize list to save ELS buffers */
6329 INIT_LIST_HEAD(&phba
->elsbuf
);
6331 /* Initialize FCF connection rec list */
6332 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
6334 /* Initialize OAS configuration list */
6335 spin_lock_init(&phba
->devicelock
);
6336 INIT_LIST_HEAD(&phba
->luns
);
6338 /* MBOX heartbeat timer */
6339 timer_setup(&psli
->mbox_tmo
, lpfc_mbox_timeout
, 0);
6340 /* Fabric block timer */
6341 timer_setup(&phba
->fabric_block_timer
, lpfc_fabric_block_timeout
, 0);
6342 /* EA polling mode timer */
6343 timer_setup(&phba
->eratt_poll
, lpfc_poll_eratt
, 0);
6344 /* Heartbeat timer */
6345 timer_setup(&phba
->hb_tmofunc
, lpfc_hb_timeout
, 0);
6347 INIT_DELAYED_WORK(&phba
->eq_delay_work
, lpfc_hb_eq_delay_work
);
6349 INIT_DELAYED_WORK(&phba
->idle_stat_delay_work
,
6350 lpfc_idle_stat_delay_work
);
6356 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
6357 * @phba: pointer to lpfc hba data structure.
6359 * This routine is invoked to set up the driver internal resources specific to
6360 * support the SLI-3 HBA device it attached to.
6364 * other values - error
6367 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
6372 * Initialize timers used by driver
6375 /* FCP polling mode timer */
6376 timer_setup(&phba
->fcp_poll_timer
, lpfc_poll_timeout
, 0);
6378 /* Host attention work mask setup */
6379 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
6380 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
6382 /* Get all the module params for configuring this host */
6383 lpfc_get_cfgparam(phba
);
6384 /* Set up phase-1 common device driver resources */
6386 rc
= lpfc_setup_driver_resource_phase1(phba
);
6390 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
6391 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
6392 /* check for menlo minimum sg count */
6393 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
6394 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
6397 if (!phba
->sli
.sli3_ring
)
6398 phba
->sli
.sli3_ring
= kcalloc(LPFC_SLI3_MAX_RING
,
6399 sizeof(struct lpfc_sli_ring
),
6401 if (!phba
->sli
.sli3_ring
)
6405 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
6406 * used to create the sg_dma_buf_pool must be dynamically calculated.
6409 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6410 entry_sz
= sizeof(struct sli4_sge
);
6412 entry_sz
= sizeof(struct ulp_bde64
);
6414 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
6415 if (phba
->cfg_enable_bg
) {
6417 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
6418 * the FCP rsp, and a BDE for each. Sice we have no control
6419 * over how many protection data segments the SCSI Layer
6420 * will hand us (ie: there could be one for every block
6421 * in the IO), we just allocate enough BDEs to accomidate
6422 * our max amount and we need to limit lpfc_sg_seg_cnt to
6423 * minimize the risk of running out.
6425 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
6426 sizeof(struct fcp_rsp
) +
6427 (LPFC_MAX_SG_SEG_CNT
* entry_sz
);
6429 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SEG_CNT_DIF
)
6430 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT_DIF
;
6432 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
6433 phba
->cfg_total_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
6436 * The scsi_buf for a regular I/O will hold the FCP cmnd,
6437 * the FCP rsp, a BDE for each, and a BDE for up to
6438 * cfg_sg_seg_cnt data segments.
6440 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
6441 sizeof(struct fcp_rsp
) +
6442 ((phba
->cfg_sg_seg_cnt
+ 2) * entry_sz
);
6444 /* Total BDEs in BPL for scsi_sg_list */
6445 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
6448 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
6449 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
6450 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
6451 phba
->cfg_total_seg_cnt
);
6453 phba
->max_vpi
= LPFC_MAX_VPI
;
6454 /* This will be set to correct value after config_port mbox */
6455 phba
->max_vports
= 0;
6458 * Initialize the SLI Layer to run with lpfc HBAs.
6460 lpfc_sli_setup(phba
);
6461 lpfc_sli_queue_init(phba
);
6463 /* Allocate device driver memory */
6464 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
6467 phba
->lpfc_sg_dma_buf_pool
=
6468 dma_pool_create("lpfc_sg_dma_buf_pool",
6469 &phba
->pcidev
->dev
, phba
->cfg_sg_dma_buf_size
,
6472 if (!phba
->lpfc_sg_dma_buf_pool
)
6475 phba
->lpfc_cmd_rsp_buf_pool
=
6476 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6478 sizeof(struct fcp_cmnd
) +
6479 sizeof(struct fcp_rsp
),
6482 if (!phba
->lpfc_cmd_rsp_buf_pool
)
6483 goto fail_free_dma_buf_pool
;
6486 * Enable sr-iov virtual functions if supported and configured
6487 * through the module parameter.
6489 if (phba
->cfg_sriov_nr_virtfn
> 0) {
6490 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
6491 phba
->cfg_sriov_nr_virtfn
);
6493 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6494 "2808 Requested number of SR-IOV "
6495 "virtual functions (%d) is not "
6497 phba
->cfg_sriov_nr_virtfn
);
6498 phba
->cfg_sriov_nr_virtfn
= 0;
6504 fail_free_dma_buf_pool
:
6505 dma_pool_destroy(phba
->lpfc_sg_dma_buf_pool
);
6506 phba
->lpfc_sg_dma_buf_pool
= NULL
;
6508 lpfc_mem_free(phba
);
6513 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6514 * @phba: pointer to lpfc hba data structure.
6516 * This routine is invoked to unset the driver internal resources set up
6517 * specific for supporting the SLI-3 HBA device it attached to.
6520 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
6522 /* Free device driver memory allocated */
6523 lpfc_mem_free_all(phba
);
6529 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6530 * @phba: pointer to lpfc hba data structure.
6532 * This routine is invoked to set up the driver internal resources specific to
6533 * support the SLI-4 HBA device it attached to.
6537 * other values - error
6540 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
6542 LPFC_MBOXQ_t
*mboxq
;
6544 int rc
, i
, max_buf_size
;
6545 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
6546 struct lpfc_mqe
*mqe
;
6553 phba
->sli4_hba
.num_present_cpu
= lpfc_present_cpu
;
6554 phba
->sli4_hba
.num_possible_cpu
= cpumask_last(cpu_possible_mask
) + 1;
6555 phba
->sli4_hba
.curr_disp_cpu
= 0;
6557 /* Get all the module params for configuring this host */
6558 lpfc_get_cfgparam(phba
);
6560 /* Set up phase-1 common device driver resources */
6561 rc
= lpfc_setup_driver_resource_phase1(phba
);
6565 /* Before proceed, wait for POST done and device ready */
6566 rc
= lpfc_sli4_post_status_check(phba
);
6570 /* Allocate all driver workqueues here */
6572 /* The lpfc_wq workqueue for deferred irq use */
6573 phba
->wq
= alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM
, 0);
6576 * Initialize timers used by driver
6579 timer_setup(&phba
->rrq_tmr
, lpfc_rrq_timeout
, 0);
6581 /* FCF rediscover timer */
6582 timer_setup(&phba
->fcf
.redisc_wait
, lpfc_sli4_fcf_redisc_wait_tmo
, 0);
6585 * Control structure for handling external multi-buffer mailbox
6586 * command pass-through.
6588 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
6589 sizeof(struct lpfc_mbox_ext_buf_ctx
));
6590 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
6592 phba
->max_vpi
= LPFC_MAX_VPI
;
6594 /* This will be set to correct value after the read_config mbox */
6595 phba
->max_vports
= 0;
6597 /* Program the default value of vlan_id and fc_map */
6598 phba
->valid_vlan
= 0;
6599 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
6600 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
6601 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
6604 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
6605 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6606 * The WQ create will allocate the ring.
6609 /* Initialize buffer queue management fields */
6610 INIT_LIST_HEAD(&phba
->hbqs
[LPFC_ELS_HBQ
].hbq_buffer_list
);
6611 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
6612 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
6615 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6617 /* Initialize the Abort buffer list used by driver */
6618 spin_lock_init(&phba
->sli4_hba
.abts_io_buf_list_lock
);
6619 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_io_buf_list
);
6621 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
6622 /* Initialize the Abort nvme buffer list used by driver */
6623 spin_lock_init(&phba
->sli4_hba
.abts_nvmet_buf_list_lock
);
6624 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvmet_ctx_list
);
6625 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_nvmet_io_wait_list
);
6626 spin_lock_init(&phba
->sli4_hba
.t_active_list_lock
);
6627 INIT_LIST_HEAD(&phba
->sli4_hba
.t_active_ctx_list
);
6630 /* This abort list used by worker thread */
6631 spin_lock_init(&phba
->sli4_hba
.sgl_list_lock
);
6632 spin_lock_init(&phba
->sli4_hba
.nvmet_io_wait_lock
);
6635 * Initialize driver internal slow-path work queues
6638 /* Driver internel slow-path CQ Event pool */
6639 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
6640 /* Response IOCB work queue list */
6641 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
6642 /* Asynchronous event CQ Event work queue list */
6643 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
6644 /* Fast-path XRI aborted CQ Event work queue list */
6645 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
6646 /* Slow-path XRI aborted CQ Event work queue list */
6647 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
6648 /* Receive queue CQ Event work queue list */
6649 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
6651 /* Initialize extent block lists. */
6652 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
6653 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
6654 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
6655 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
6657 /* Initialize mboxq lists. If the early init routines fail
6658 * these lists need to be correctly initialized.
6660 INIT_LIST_HEAD(&phba
->sli
.mboxq
);
6661 INIT_LIST_HEAD(&phba
->sli
.mboxq_cmpl
);
6663 /* initialize optic_state to 0xFF */
6664 phba
->sli4_hba
.lnk_info
.optic_state
= 0xff;
6666 /* Allocate device driver memory */
6667 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
6671 /* IF Type 2 ports get initialized now. */
6672 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) >=
6673 LPFC_SLI_INTF_IF_TYPE_2
) {
6674 rc
= lpfc_pci_function_reset(phba
);
6679 phba
->temp_sensor_support
= 1;
6682 /* Create the bootstrap mailbox command */
6683 rc
= lpfc_create_bootstrap_mbox(phba
);
6687 /* Set up the host's endian order with the device. */
6688 rc
= lpfc_setup_endian_order(phba
);
6690 goto out_free_bsmbx
;
6692 /* Set up the hba's configuration parameters. */
6693 rc
= lpfc_sli4_read_config(phba
);
6695 goto out_free_bsmbx
;
6696 rc
= lpfc_mem_alloc_active_rrq_pool_s4(phba
);
6698 goto out_free_bsmbx
;
6700 /* IF Type 0 ports get initialized now. */
6701 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6702 LPFC_SLI_INTF_IF_TYPE_0
) {
6703 rc
= lpfc_pci_function_reset(phba
);
6705 goto out_free_bsmbx
;
6708 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6712 goto out_free_bsmbx
;
6715 /* Check for NVMET being configured */
6716 phba
->nvmet_support
= 0;
6717 if (lpfc_enable_nvmet_cnt
) {
6719 /* First get WWN of HBA instance */
6720 lpfc_read_nv(phba
, mboxq
);
6721 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6722 if (rc
!= MBX_SUCCESS
) {
6723 lpfc_printf_log(phba
, KERN_ERR
,
6725 "6016 Mailbox failed , mbxCmd x%x "
6726 "READ_NV, mbxStatus x%x\n",
6727 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
6728 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
6729 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6731 goto out_free_bsmbx
;
6734 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.nodename
,
6736 wwn
= cpu_to_be64(wwn
);
6737 phba
->sli4_hba
.wwnn
.u
.name
= wwn
;
6738 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.portname
,
6740 /* wwn is WWPN of HBA instance */
6741 wwn
= cpu_to_be64(wwn
);
6742 phba
->sli4_hba
.wwpn
.u
.name
= wwn
;
6744 /* Check to see if it matches any module parameter */
6745 for (i
= 0; i
< lpfc_enable_nvmet_cnt
; i
++) {
6746 if (wwn
== lpfc_enable_nvmet
[i
]) {
6747 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
6748 if (lpfc_nvmet_mem_alloc(phba
))
6751 phba
->nvmet_support
= 1; /* a match */
6753 lpfc_printf_log(phba
, KERN_ERR
,
6755 "6017 NVME Target %016llx\n",
6758 lpfc_printf_log(phba
, KERN_ERR
,
6760 "6021 Can't enable NVME Target."
6761 " NVME_TARGET_FC infrastructure"
6762 " is not in kernel\n");
6764 /* Not supported for NVMET */
6765 phba
->cfg_xri_rebalancing
= 0;
6766 if (phba
->irq_chann_mode
== NHT_MODE
) {
6767 phba
->cfg_irq_chann
=
6768 phba
->sli4_hba
.num_present_cpu
;
6769 phba
->cfg_hdw_queue
=
6770 phba
->sli4_hba
.num_present_cpu
;
6771 phba
->irq_chann_mode
= NORMAL_MODE
;
6778 lpfc_nvme_mod_param_dep(phba
);
6780 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
6781 lpfc_supported_pages(mboxq
);
6782 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6784 mqe
= &mboxq
->u
.mqe
;
6785 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
6786 LPFC_MAX_SUPPORTED_PAGES
);
6787 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
6788 switch (pn_page
[i
]) {
6789 case LPFC_SLI4_PARAMETERS
:
6790 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
6796 /* Read the port's SLI4 Parameters capabilities if supported. */
6797 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
6798 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
6800 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6802 goto out_free_bsmbx
;
6807 * Get sli4 parameters that override parameters from Port capabilities.
6808 * If this call fails, it isn't critical unless the SLI4 parameters come
6811 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
6813 if_type
= bf_get(lpfc_sli_intf_if_type
,
6814 &phba
->sli4_hba
.sli_intf
);
6815 if_fam
= bf_get(lpfc_sli_intf_sli_family
,
6816 &phba
->sli4_hba
.sli_intf
);
6817 if (phba
->sli4_hba
.extents_in_use
&&
6818 phba
->sli4_hba
.rpi_hdrs_in_use
) {
6819 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6820 "2999 Unsupported SLI4 Parameters "
6821 "Extents and RPI headers enabled.\n");
6822 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
&&
6823 if_fam
== LPFC_SLI_INTF_FAMILY_BE2
) {
6824 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6826 goto out_free_bsmbx
;
6829 if (!(if_type
== LPFC_SLI_INTF_IF_TYPE_0
&&
6830 if_fam
== LPFC_SLI_INTF_FAMILY_BE2
)) {
6831 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6833 goto out_free_bsmbx
;
6838 * 1 for cmd, 1 for rsp, NVME adds an extra one
6839 * for boundary conditions in its max_sgl_segment template.
6842 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
6846 * It doesn't matter what family our adapter is in, we are
6847 * limited to 2 Pages, 512 SGEs, for our SGL.
6848 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6850 max_buf_size
= (2 * SLI4_PAGE_SIZE
);
6853 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6854 * used to create the sg_dma_buf_pool must be calculated.
6856 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) {
6857 /* Both cfg_enable_bg and cfg_external_dif code paths */
6860 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6861 * the FCP rsp, and a SGE. Sice we have no control
6862 * over how many protection segments the SCSI Layer
6863 * will hand us (ie: there could be one for every block
6864 * in the IO), just allocate enough SGEs to accomidate
6865 * our max amount and we need to limit lpfc_sg_seg_cnt
6866 * to minimize the risk of running out.
6868 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
6869 sizeof(struct fcp_rsp
) + max_buf_size
;
6871 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6872 phba
->cfg_total_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
;
6875 * If supporting DIF, reduce the seg count for scsi to
6876 * allow room for the DIF sges.
6878 if (phba
->cfg_enable_bg
&&
6879 phba
->cfg_sg_seg_cnt
> LPFC_MAX_BG_SLI4_SEG_CNT_DIF
)
6880 phba
->cfg_scsi_seg_cnt
= LPFC_MAX_BG_SLI4_SEG_CNT_DIF
;
6882 phba
->cfg_scsi_seg_cnt
= phba
->cfg_sg_seg_cnt
;
6886 * The scsi_buf for a regular I/O holds the FCP cmnd,
6887 * the FCP rsp, a SGE for each, and a SGE for up to
6888 * cfg_sg_seg_cnt data segments.
6890 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
6891 sizeof(struct fcp_rsp
) +
6892 ((phba
->cfg_sg_seg_cnt
+ extra
) *
6893 sizeof(struct sli4_sge
));
6895 /* Total SGEs for scsi_sg_list */
6896 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ extra
;
6897 phba
->cfg_scsi_seg_cnt
= phba
->cfg_sg_seg_cnt
;
6900 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
6901 * need to post 1 page for the SGL.
6905 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
)
6906 phba
->cfg_sg_dma_buf_size
= LPFC_DEFAULT_XPSGL_SIZE
;
6907 else if (phba
->cfg_sg_dma_buf_size
<= LPFC_MIN_SG_SLI4_BUF_SZ
)
6908 phba
->cfg_sg_dma_buf_size
= LPFC_MIN_SG_SLI4_BUF_SZ
;
6910 phba
->cfg_sg_dma_buf_size
=
6911 SLI4_PAGE_ALIGN(phba
->cfg_sg_dma_buf_size
);
6913 phba
->border_sge_num
= phba
->cfg_sg_dma_buf_size
/
6914 sizeof(struct sli4_sge
);
6916 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6917 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
6918 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_NVME_SEG_CNT
) {
6919 lpfc_printf_log(phba
, KERN_INFO
, LOG_NVME
| LOG_INIT
,
6920 "6300 Reducing NVME sg segment "
6922 LPFC_MAX_NVME_SEG_CNT
);
6923 phba
->cfg_nvme_seg_cnt
= LPFC_MAX_NVME_SEG_CNT
;
6925 phba
->cfg_nvme_seg_cnt
= phba
->cfg_sg_seg_cnt
;
6928 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
6929 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6930 "total:%d scsi:%d nvme:%d\n",
6931 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
6932 phba
->cfg_total_seg_cnt
, phba
->cfg_scsi_seg_cnt
,
6933 phba
->cfg_nvme_seg_cnt
);
6935 if (phba
->cfg_sg_dma_buf_size
< SLI4_PAGE_SIZE
)
6936 i
= phba
->cfg_sg_dma_buf_size
;
6940 phba
->lpfc_sg_dma_buf_pool
=
6941 dma_pool_create("lpfc_sg_dma_buf_pool",
6943 phba
->cfg_sg_dma_buf_size
,
6945 if (!phba
->lpfc_sg_dma_buf_pool
)
6946 goto out_free_bsmbx
;
6948 phba
->lpfc_cmd_rsp_buf_pool
=
6949 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6951 sizeof(struct fcp_cmnd
) +
6952 sizeof(struct fcp_rsp
),
6954 if (!phba
->lpfc_cmd_rsp_buf_pool
)
6955 goto out_free_sg_dma_buf
;
6957 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6959 /* Verify OAS is supported */
6960 lpfc_sli4_oas_verify(phba
);
6962 /* Verify RAS support on adapter */
6963 lpfc_sli4_ras_init(phba
);
6965 /* Verify all the SLI4 queues */
6966 rc
= lpfc_sli4_queue_verify(phba
);
6968 goto out_free_cmd_rsp_buf
;
6970 /* Create driver internal CQE event pool */
6971 rc
= lpfc_sli4_cq_event_pool_create(phba
);
6973 goto out_free_cmd_rsp_buf
;
6975 /* Initialize sgl lists per host */
6976 lpfc_init_sgl_list(phba
);
6978 /* Allocate and initialize active sgl array */
6979 rc
= lpfc_init_active_sgl_array(phba
);
6981 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6982 "1430 Failed to initialize sgl list.\n");
6983 goto out_destroy_cq_event_pool
;
6985 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
6987 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6988 "1432 Failed to initialize rpi headers.\n");
6989 goto out_free_active_sgl
;
6992 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
6993 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
6994 phba
->fcf
.fcf_rr_bmask
= kcalloc(longs
, sizeof(unsigned long),
6996 if (!phba
->fcf
.fcf_rr_bmask
) {
6997 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6998 "2759 Failed allocate memory for FCF round "
6999 "robin failover bmask\n");
7001 goto out_remove_rpi_hdrs
;
7004 phba
->sli4_hba
.hba_eq_hdl
= kcalloc(phba
->cfg_irq_chann
,
7005 sizeof(struct lpfc_hba_eq_hdl
),
7007 if (!phba
->sli4_hba
.hba_eq_hdl
) {
7008 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7009 "2572 Failed allocate memory for "
7010 "fast-path per-EQ handle array\n");
7012 goto out_free_fcf_rr_bmask
;
7015 phba
->sli4_hba
.cpu_map
= kcalloc(phba
->sli4_hba
.num_possible_cpu
,
7016 sizeof(struct lpfc_vector_map_info
),
7018 if (!phba
->sli4_hba
.cpu_map
) {
7019 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7020 "3327 Failed allocate memory for msi-x "
7021 "interrupt vector mapping\n");
7023 goto out_free_hba_eq_hdl
;
7026 phba
->sli4_hba
.eq_info
= alloc_percpu(struct lpfc_eq_intr_info
);
7027 if (!phba
->sli4_hba
.eq_info
) {
7028 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7029 "3321 Failed allocation for per_cpu stats\n");
7031 goto out_free_hba_cpu_map
;
7034 phba
->sli4_hba
.idle_stat
= kcalloc(phba
->sli4_hba
.num_possible_cpu
,
7035 sizeof(*phba
->sli4_hba
.idle_stat
),
7037 if (!phba
->sli4_hba
.idle_stat
) {
7038 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7039 "3390 Failed allocation for idle_stat\n");
7041 goto out_free_hba_eq_info
;
7044 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7045 phba
->sli4_hba
.c_stat
= alloc_percpu(struct lpfc_hdwq_stat
);
7046 if (!phba
->sli4_hba
.c_stat
) {
7047 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7048 "3332 Failed allocating per cpu hdwq stats\n");
7050 goto out_free_hba_idle_stat
;
7055 * Enable sr-iov virtual functions if supported and configured
7056 * through the module parameter.
7058 if (phba
->cfg_sriov_nr_virtfn
> 0) {
7059 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
7060 phba
->cfg_sriov_nr_virtfn
);
7062 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7063 "3020 Requested number of SR-IOV "
7064 "virtual functions (%d) is not "
7066 phba
->cfg_sriov_nr_virtfn
);
7067 phba
->cfg_sriov_nr_virtfn
= 0;
7073 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7074 out_free_hba_idle_stat
:
7075 kfree(phba
->sli4_hba
.idle_stat
);
7077 out_free_hba_eq_info
:
7078 free_percpu(phba
->sli4_hba
.eq_info
);
7079 out_free_hba_cpu_map
:
7080 kfree(phba
->sli4_hba
.cpu_map
);
7081 out_free_hba_eq_hdl
:
7082 kfree(phba
->sli4_hba
.hba_eq_hdl
);
7083 out_free_fcf_rr_bmask
:
7084 kfree(phba
->fcf
.fcf_rr_bmask
);
7085 out_remove_rpi_hdrs
:
7086 lpfc_sli4_remove_rpi_hdrs(phba
);
7087 out_free_active_sgl
:
7088 lpfc_free_active_sgl(phba
);
7089 out_destroy_cq_event_pool
:
7090 lpfc_sli4_cq_event_pool_destroy(phba
);
7091 out_free_cmd_rsp_buf
:
7092 dma_pool_destroy(phba
->lpfc_cmd_rsp_buf_pool
);
7093 phba
->lpfc_cmd_rsp_buf_pool
= NULL
;
7094 out_free_sg_dma_buf
:
7095 dma_pool_destroy(phba
->lpfc_sg_dma_buf_pool
);
7096 phba
->lpfc_sg_dma_buf_pool
= NULL
;
7098 lpfc_destroy_bootstrap_mbox(phba
);
7100 lpfc_mem_free(phba
);
7105 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
7106 * @phba: pointer to lpfc hba data structure.
7108 * This routine is invoked to unset the driver internal resources set up
7109 * specific for supporting the SLI-4 HBA device it attached to.
7112 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
7114 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
7116 free_percpu(phba
->sli4_hba
.eq_info
);
7117 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7118 free_percpu(phba
->sli4_hba
.c_stat
);
7120 kfree(phba
->sli4_hba
.idle_stat
);
7122 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
7123 kfree(phba
->sli4_hba
.cpu_map
);
7124 phba
->sli4_hba
.num_possible_cpu
= 0;
7125 phba
->sli4_hba
.num_present_cpu
= 0;
7126 phba
->sli4_hba
.curr_disp_cpu
= 0;
7127 cpumask_clear(&phba
->sli4_hba
.irq_aff_mask
);
7129 /* Free memory allocated for fast-path work queue handles */
7130 kfree(phba
->sli4_hba
.hba_eq_hdl
);
7132 /* Free the allocated rpi headers. */
7133 lpfc_sli4_remove_rpi_hdrs(phba
);
7134 lpfc_sli4_remove_rpis(phba
);
7136 /* Free eligible FCF index bmask */
7137 kfree(phba
->fcf
.fcf_rr_bmask
);
7139 /* Free the ELS sgl list */
7140 lpfc_free_active_sgl(phba
);
7141 lpfc_free_els_sgl_list(phba
);
7142 lpfc_free_nvmet_sgl_list(phba
);
7144 /* Free the completion queue EQ event pool */
7145 lpfc_sli4_cq_event_release_all(phba
);
7146 lpfc_sli4_cq_event_pool_destroy(phba
);
7148 /* Release resource identifiers. */
7149 lpfc_sli4_dealloc_resource_identifiers(phba
);
7151 /* Free the bsmbx region. */
7152 lpfc_destroy_bootstrap_mbox(phba
);
7154 /* Free the SLI Layer memory with SLI4 HBAs */
7155 lpfc_mem_free_all(phba
);
7157 /* Free the current connect table */
7158 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
7159 &phba
->fcf_conn_rec_list
, list
) {
7160 list_del_init(&conn_entry
->list
);
7168 * lpfc_init_api_table_setup - Set up init api function jump table
7169 * @phba: The hba struct for which this call is being executed.
7170 * @dev_grp: The HBA PCI-Device group number.
7172 * This routine sets up the device INIT interface API function jump table
7175 * Returns: 0 - success, -ENODEV - failure.
7178 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7180 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
7181 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
7182 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
7184 case LPFC_PCI_DEV_LP
:
7185 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
7186 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
7187 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
7189 case LPFC_PCI_DEV_OC
:
7190 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
7191 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
7192 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
7195 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7196 "1431 Invalid HBA PCI-device group: 0x%x\n",
7205 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
7206 * @phba: pointer to lpfc hba data structure.
7208 * This routine is invoked to set up the driver internal resources after the
7209 * device specific resource setup to support the HBA device it attached to.
7213 * other values - error
7216 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
7220 /* Startup the kernel thread for this host adapter. */
7221 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
7222 "lpfc_worker_%d", phba
->brd_no
);
7223 if (IS_ERR(phba
->worker_thread
)) {
7224 error
= PTR_ERR(phba
->worker_thread
);
7232 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7233 * @phba: pointer to lpfc hba data structure.
7235 * This routine is invoked to unset the driver internal resources set up after
7236 * the device specific resource setup for supporting the HBA device it
7240 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
7243 flush_workqueue(phba
->wq
);
7244 destroy_workqueue(phba
->wq
);
7248 /* Stop kernel worker thread */
7249 if (phba
->worker_thread
)
7250 kthread_stop(phba
->worker_thread
);
7254 * lpfc_free_iocb_list - Free iocb list.
7255 * @phba: pointer to lpfc hba data structure.
7257 * This routine is invoked to free the driver's IOCB list and memory.
7260 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
7262 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
7264 spin_lock_irq(&phba
->hbalock
);
7265 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
7266 &phba
->lpfc_iocb_list
, list
) {
7267 list_del(&iocbq_entry
->list
);
7269 phba
->total_iocbq_bufs
--;
7271 spin_unlock_irq(&phba
->hbalock
);
7277 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7278 * @phba: pointer to lpfc hba data structure.
7279 * @iocb_count: number of requested iocbs
7281 * This routine is invoked to allocate and initizlize the driver's IOCB
7282 * list and set up the IOCB tag array accordingly.
7286 * other values - error
7289 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
7291 struct lpfc_iocbq
*iocbq_entry
= NULL
;
7295 /* Initialize and populate the iocb list per host. */
7296 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
7297 for (i
= 0; i
< iocb_count
; i
++) {
7298 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
7299 if (iocbq_entry
== NULL
) {
7300 printk(KERN_ERR
"%s: only allocated %d iocbs of "
7301 "expected %d count. Unloading driver.\n",
7302 __func__
, i
, iocb_count
);
7303 goto out_free_iocbq
;
7306 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
7309 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
7310 "Unloading driver.\n", __func__
);
7311 goto out_free_iocbq
;
7313 iocbq_entry
->sli4_lxritag
= NO_XRI
;
7314 iocbq_entry
->sli4_xritag
= NO_XRI
;
7316 spin_lock_irq(&phba
->hbalock
);
7317 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
7318 phba
->total_iocbq_bufs
++;
7319 spin_unlock_irq(&phba
->hbalock
);
7325 lpfc_free_iocb_list(phba
);
7331 * lpfc_free_sgl_list - Free a given sgl list.
7332 * @phba: pointer to lpfc hba data structure.
7333 * @sglq_list: pointer to the head of sgl list.
7335 * This routine is invoked to free a give sgl list and memory.
7338 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
7340 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7342 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
7343 list_del(&sglq_entry
->list
);
7344 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
7350 * lpfc_free_els_sgl_list - Free els sgl list.
7351 * @phba: pointer to lpfc hba data structure.
7353 * This routine is invoked to free the driver's els sgl list and memory.
7356 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
7358 LIST_HEAD(sglq_list
);
7360 /* Retrieve all els sgls from driver list */
7361 spin_lock_irq(&phba
->hbalock
);
7362 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
7363 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
, &sglq_list
);
7364 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
7365 spin_unlock_irq(&phba
->hbalock
);
7367 /* Now free the sgl list */
7368 lpfc_free_sgl_list(phba
, &sglq_list
);
7372 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
7373 * @phba: pointer to lpfc hba data structure.
7375 * This routine is invoked to free the driver's nvmet sgl list and memory.
7378 lpfc_free_nvmet_sgl_list(struct lpfc_hba
*phba
)
7380 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7381 LIST_HEAD(sglq_list
);
7383 /* Retrieve all nvmet sgls from driver list */
7384 spin_lock_irq(&phba
->hbalock
);
7385 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
7386 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
, &sglq_list
);
7387 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
7388 spin_unlock_irq(&phba
->hbalock
);
7390 /* Now free the sgl list */
7391 list_for_each_entry_safe(sglq_entry
, sglq_next
, &sglq_list
, list
) {
7392 list_del(&sglq_entry
->list
);
7393 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
7397 /* Update the nvmet_xri_cnt to reflect no current sgls.
7398 * The next initialization cycle sets the count and allocates
7399 * the sgls over again.
7401 phba
->sli4_hba
.nvmet_xri_cnt
= 0;
7405 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
7406 * @phba: pointer to lpfc hba data structure.
7408 * This routine is invoked to allocate the driver's active sgl memory.
7409 * This array will hold the sglq_entry's for active IOs.
7412 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
7415 size
= sizeof(struct lpfc_sglq
*);
7416 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
7418 phba
->sli4_hba
.lpfc_sglq_active_list
=
7419 kzalloc(size
, GFP_KERNEL
);
7420 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
7426 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
7427 * @phba: pointer to lpfc hba data structure.
7429 * This routine is invoked to walk through the array of active sglq entries
7430 * and free all of the resources.
7431 * This is just a place holder for now.
7434 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
7436 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
7440 * lpfc_init_sgl_list - Allocate and initialize sgl list.
7441 * @phba: pointer to lpfc hba data structure.
7443 * This routine is invoked to allocate and initizlize the driver's sgl
7444 * list and set up the sgl xritag tag array accordingly.
7448 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
7450 /* Initialize and populate the sglq list per host/VF. */
7451 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_els_sgl_list
);
7452 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
7453 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
7454 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvmet_ctx_list
);
7456 /* els xri-sgl book keeping */
7457 phba
->sli4_hba
.els_xri_cnt
= 0;
7459 /* nvme xri-buffer book keeping */
7460 phba
->sli4_hba
.io_xri_cnt
= 0;
7464 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
7465 * @phba: pointer to lpfc hba data structure.
7467 * This routine is invoked to post rpi header templates to the
7468 * port for those SLI4 ports that do not support extents. This routine
7469 * posts a PAGE_SIZE memory region to the port to hold up to
7470 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
7471 * and should be called only when interrupts are disabled.
7475 * -ERROR - otherwise.
7478 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
7481 struct lpfc_rpi_hdr
*rpi_hdr
;
7483 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
7484 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
7486 if (phba
->sli4_hba
.extents_in_use
)
7489 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
7491 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7492 "0391 Error during rpi post operation\n");
7493 lpfc_sli4_remove_rpis(phba
);
7501 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
7502 * @phba: pointer to lpfc hba data structure.
7504 * This routine is invoked to allocate a single 4KB memory region to
7505 * support rpis and stores them in the phba. This single region
7506 * provides support for up to 64 rpis. The region is used globally
7510 * A valid rpi hdr on success.
7511 * A NULL pointer on any failure.
7513 struct lpfc_rpi_hdr
*
7514 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
7516 uint16_t rpi_limit
, curr_rpi_range
;
7517 struct lpfc_dmabuf
*dmabuf
;
7518 struct lpfc_rpi_hdr
*rpi_hdr
;
7521 * If the SLI4 port supports extents, posting the rpi header isn't
7522 * required. Set the expected maximum count and let the actual value
7523 * get set when extents are fully allocated.
7525 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
7527 if (phba
->sli4_hba
.extents_in_use
)
7530 /* The limit on the logical index is just the max_rpi count. */
7531 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
7533 spin_lock_irq(&phba
->hbalock
);
7535 * Establish the starting RPI in this header block. The starting
7536 * rpi is normalized to a zero base because the physical rpi is
7539 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
7540 spin_unlock_irq(&phba
->hbalock
);
7542 /* Reached full RPI range */
7543 if (curr_rpi_range
== rpi_limit
)
7547 * First allocate the protocol header region for the port. The
7548 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
7550 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
7554 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
7555 LPFC_HDR_TEMPLATE_SIZE
,
7556 &dmabuf
->phys
, GFP_KERNEL
);
7557 if (!dmabuf
->virt
) {
7559 goto err_free_dmabuf
;
7562 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
7564 goto err_free_coherent
;
7567 /* Save the rpi header data for cleanup later. */
7568 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
7570 goto err_free_coherent
;
7572 rpi_hdr
->dmabuf
= dmabuf
;
7573 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
7574 rpi_hdr
->page_count
= 1;
7575 spin_lock_irq(&phba
->hbalock
);
7577 /* The rpi_hdr stores the logical index only. */
7578 rpi_hdr
->start_rpi
= curr_rpi_range
;
7579 rpi_hdr
->next_rpi
= phba
->sli4_hba
.next_rpi
+ LPFC_RPI_HDR_COUNT
;
7580 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
7582 spin_unlock_irq(&phba
->hbalock
);
7586 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
7587 dmabuf
->virt
, dmabuf
->phys
);
7594 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7595 * @phba: pointer to lpfc hba data structure.
7597 * This routine is invoked to remove all memory resources allocated
7598 * to support rpis for SLI4 ports not supporting extents. This routine
7599 * presumes the caller has released all rpis consumed by fabric or port
7600 * logins and is prepared to have the header pages removed.
7603 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
7605 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
7607 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
7610 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
7611 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
7612 list_del(&rpi_hdr
->list
);
7613 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
7614 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
7615 kfree(rpi_hdr
->dmabuf
);
7619 /* There are no rpis available to the port now. */
7620 phba
->sli4_hba
.next_rpi
= 0;
7624 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7625 * @pdev: pointer to pci device data structure.
7627 * This routine is invoked to allocate the driver hba data structure for an
7628 * HBA device. If the allocation is successful, the phba reference to the
7629 * PCI device data structure is set.
7632 * pointer to @phba - successful
7635 static struct lpfc_hba
*
7636 lpfc_hba_alloc(struct pci_dev
*pdev
)
7638 struct lpfc_hba
*phba
;
7640 /* Allocate memory for HBA structure */
7641 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
7643 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
7647 /* Set reference to PCI device in HBA structure */
7648 phba
->pcidev
= pdev
;
7650 /* Assign an unused board number */
7651 phba
->brd_no
= lpfc_get_instance();
7652 if (phba
->brd_no
< 0) {
7656 phba
->eratt_poll_interval
= LPFC_ERATT_POLL_INTERVAL
;
7658 spin_lock_init(&phba
->ct_ev_lock
);
7659 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
7665 * lpfc_hba_free - Free driver hba data structure with a device.
7666 * @phba: pointer to lpfc hba data structure.
7668 * This routine is invoked to free the driver hba data structure with an
7672 lpfc_hba_free(struct lpfc_hba
*phba
)
7674 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7675 kfree(phba
->sli4_hba
.hdwq
);
7677 /* Release the driver assigned board number */
7678 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
7680 /* Free memory allocated with sli3 rings */
7681 kfree(phba
->sli
.sli3_ring
);
7682 phba
->sli
.sli3_ring
= NULL
;
7689 * lpfc_create_shost - Create hba physical port with associated scsi host.
7690 * @phba: pointer to lpfc hba data structure.
7692 * This routine is invoked to create HBA physical port and associate a SCSI
7697 * other values - error
7700 lpfc_create_shost(struct lpfc_hba
*phba
)
7702 struct lpfc_vport
*vport
;
7703 struct Scsi_Host
*shost
;
7705 /* Initialize HBA FC structure */
7706 phba
->fc_edtov
= FF_DEF_EDTOV
;
7707 phba
->fc_ratov
= FF_DEF_RATOV
;
7708 phba
->fc_altov
= FF_DEF_ALTOV
;
7709 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
7711 atomic_set(&phba
->sdev_cnt
, 0);
7712 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
7716 shost
= lpfc_shost_from_vport(vport
);
7717 phba
->pport
= vport
;
7719 if (phba
->nvmet_support
) {
7720 /* Only 1 vport (pport) will support NVME target */
7721 phba
->targetport
= NULL
;
7722 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_NVME
;
7723 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_NVME_DISC
,
7724 "6076 NVME Target Found\n");
7727 lpfc_debugfs_initialize(vport
);
7728 /* Put reference to SCSI host to driver's device private data */
7729 pci_set_drvdata(phba
->pcidev
, shost
);
7732 * At this point we are fully registered with PSA. In addition,
7733 * any initial discovery should be completed.
7735 vport
->load_flag
|= FC_ALLOW_FDMI
;
7736 if (phba
->cfg_enable_SmartSAN
||
7737 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
7739 /* Setup appropriate attribute masks */
7740 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
7741 if (phba
->cfg_enable_SmartSAN
)
7742 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
7744 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
7750 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7751 * @phba: pointer to lpfc hba data structure.
7753 * This routine is invoked to destroy HBA physical port and the associated
7757 lpfc_destroy_shost(struct lpfc_hba
*phba
)
7759 struct lpfc_vport
*vport
= phba
->pport
;
7761 /* Destroy physical port that associated with the SCSI host */
7762 destroy_port(vport
);
7768 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7769 * @phba: pointer to lpfc hba data structure.
7770 * @shost: the shost to be used to detect Block guard settings.
7772 * This routine sets up the local Block guard protocol settings for @shost.
7773 * This routine also allocates memory for debugging bg buffers.
7776 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
7781 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
7782 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7783 "1478 Registering BlockGuard with the "
7786 old_mask
= phba
->cfg_prot_mask
;
7787 old_guard
= phba
->cfg_prot_guard
;
7789 /* Only allow supported values */
7790 phba
->cfg_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
7791 SHOST_DIX_TYPE0_PROTECTION
|
7792 SHOST_DIX_TYPE1_PROTECTION
);
7793 phba
->cfg_prot_guard
&= (SHOST_DIX_GUARD_IP
|
7794 SHOST_DIX_GUARD_CRC
);
7796 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
7797 if (phba
->cfg_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
7798 phba
->cfg_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
7800 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
7801 if ((old_mask
!= phba
->cfg_prot_mask
) ||
7802 (old_guard
!= phba
->cfg_prot_guard
))
7803 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7804 "1475 Registering BlockGuard with the "
7805 "SCSI layer: mask %d guard %d\n",
7806 phba
->cfg_prot_mask
,
7807 phba
->cfg_prot_guard
);
7809 scsi_host_set_prot(shost
, phba
->cfg_prot_mask
);
7810 scsi_host_set_guard(shost
, phba
->cfg_prot_guard
);
7812 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
7813 "1479 Not Registering BlockGuard with the SCSI "
7814 "layer, Bad protection parameters: %d %d\n",
7815 old_mask
, old_guard
);
7820 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7821 * @phba: pointer to lpfc hba data structure.
7823 * This routine is invoked to perform all the necessary post initialization
7824 * setup for the device.
7827 lpfc_post_init_setup(struct lpfc_hba
*phba
)
7829 struct Scsi_Host
*shost
;
7830 struct lpfc_adapter_event_header adapter_event
;
7832 /* Get the default values for Model Name and Description */
7833 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
7836 * hba setup may have changed the hba_queue_depth so we need to
7837 * adjust the value of can_queue.
7839 shost
= pci_get_drvdata(phba
->pcidev
);
7840 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
7842 lpfc_host_attrib_init(shost
);
7844 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
7845 spin_lock_irq(shost
->host_lock
);
7846 lpfc_poll_start_timer(phba
);
7847 spin_unlock_irq(shost
->host_lock
);
7850 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7851 "0428 Perform SCSI scan\n");
7852 /* Send board arrival event to upper layer */
7853 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
7854 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
7855 fc_host_post_vendor_event(shost
, fc_get_event_number(),
7856 sizeof(adapter_event
),
7857 (char *) &adapter_event
,
7863 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7864 * @phba: pointer to lpfc hba data structure.
7866 * This routine is invoked to set up the PCI device memory space for device
7867 * with SLI-3 interface spec.
7871 * other values - error
7874 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
7876 struct pci_dev
*pdev
= phba
->pcidev
;
7877 unsigned long bar0map_len
, bar2map_len
;
7885 /* Set the device DMA mask size */
7886 error
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
7888 error
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
7893 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7894 * required by each mapping.
7896 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
7897 bar0map_len
= pci_resource_len(pdev
, 0);
7899 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
7900 bar2map_len
= pci_resource_len(pdev
, 2);
7902 /* Map HBA SLIM to a kernel virtual address. */
7903 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
7904 if (!phba
->slim_memmap_p
) {
7905 dev_printk(KERN_ERR
, &pdev
->dev
,
7906 "ioremap failed for SLIM memory.\n");
7910 /* Map HBA Control Registers to a kernel virtual address. */
7911 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
7912 if (!phba
->ctrl_regs_memmap_p
) {
7913 dev_printk(KERN_ERR
, &pdev
->dev
,
7914 "ioremap failed for HBA control registers.\n");
7915 goto out_iounmap_slim
;
7918 /* Allocate memory for SLI-2 structures */
7919 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7920 &phba
->slim2p
.phys
, GFP_KERNEL
);
7921 if (!phba
->slim2p
.virt
)
7924 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
7925 phba
->mbox_ext
= (phba
->slim2p
.virt
+
7926 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
7927 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
7928 phba
->IOCBs
= (phba
->slim2p
.virt
+
7929 offsetof(struct lpfc_sli2_slim
, IOCBs
));
7931 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
7932 lpfc_sli_hbq_size(),
7933 &phba
->hbqslimp
.phys
,
7935 if (!phba
->hbqslimp
.virt
)
7938 hbq_count
= lpfc_sli_hbq_count();
7939 ptr
= phba
->hbqslimp
.virt
;
7940 for (i
= 0; i
< hbq_count
; ++i
) {
7941 phba
->hbqs
[i
].hbq_virt
= ptr
;
7942 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
7943 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
7944 sizeof(struct lpfc_hbq_entry
));
7946 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
7947 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
7949 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
7951 phba
->MBslimaddr
= phba
->slim_memmap_p
;
7952 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
7953 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
7954 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
7955 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
7960 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7961 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
7963 iounmap(phba
->ctrl_regs_memmap_p
);
7965 iounmap(phba
->slim_memmap_p
);
7971 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7972 * @phba: pointer to lpfc hba data structure.
7974 * This routine is invoked to unset the PCI device memory space for device
7975 * with SLI-3 interface spec.
7978 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
7980 struct pci_dev
*pdev
;
7982 /* Obtain PCI device reference */
7986 pdev
= phba
->pcidev
;
7988 /* Free coherent DMA memory allocated */
7989 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
7990 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
7991 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7992 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
7994 /* I/O memory unmap */
7995 iounmap(phba
->ctrl_regs_memmap_p
);
7996 iounmap(phba
->slim_memmap_p
);
8002 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
8003 * @phba: pointer to lpfc hba data structure.
8005 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
8006 * done and check status.
8008 * Return 0 if successful, otherwise -ENODEV.
8011 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
8013 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
8014 struct lpfc_register reg_data
;
8015 int i
, port_error
= 0;
8018 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
8019 memset(®_data
, 0, sizeof(reg_data
));
8020 if (!phba
->sli4_hba
.PSMPHRregaddr
)
8023 /* Wait up to 30 seconds for the SLI Port POST done and ready */
8024 for (i
= 0; i
< 3000; i
++) {
8025 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
8026 &portsmphr_reg
.word0
) ||
8027 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
8028 /* Port has a fatal POST error, break out */
8029 port_error
= -ENODEV
;
8032 if (LPFC_POST_STAGE_PORT_READY
==
8033 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
8039 * If there was a port error during POST, then don't proceed with
8040 * other register reads as the data may not be valid. Just exit.
8043 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8044 "1408 Port Failed POST - portsmphr=0x%x, "
8045 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
8046 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
8047 portsmphr_reg
.word0
,
8048 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
8049 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
8050 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
8051 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
8052 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
8053 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
8054 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
8055 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
8057 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8058 "2534 Device Info: SLIFamily=0x%x, "
8059 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
8060 "SLIHint_2=0x%x, FT=0x%x\n",
8061 bf_get(lpfc_sli_intf_sli_family
,
8062 &phba
->sli4_hba
.sli_intf
),
8063 bf_get(lpfc_sli_intf_slirev
,
8064 &phba
->sli4_hba
.sli_intf
),
8065 bf_get(lpfc_sli_intf_if_type
,
8066 &phba
->sli4_hba
.sli_intf
),
8067 bf_get(lpfc_sli_intf_sli_hint1
,
8068 &phba
->sli4_hba
.sli_intf
),
8069 bf_get(lpfc_sli_intf_sli_hint2
,
8070 &phba
->sli4_hba
.sli_intf
),
8071 bf_get(lpfc_sli_intf_func_type
,
8072 &phba
->sli4_hba
.sli_intf
));
8074 * Check for other Port errors during the initialization
8075 * process. Fail the load if the port did not come up
8078 if_type
= bf_get(lpfc_sli_intf_if_type
,
8079 &phba
->sli4_hba
.sli_intf
);
8081 case LPFC_SLI_INTF_IF_TYPE_0
:
8082 phba
->sli4_hba
.ue_mask_lo
=
8083 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
8084 phba
->sli4_hba
.ue_mask_hi
=
8085 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
8087 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
8089 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
8090 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
8091 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
8092 lpfc_printf_log(phba
, KERN_ERR
,
8094 "1422 Unrecoverable Error "
8095 "Detected during POST "
8096 "uerr_lo_reg=0x%x, "
8097 "uerr_hi_reg=0x%x, "
8098 "ue_mask_lo_reg=0x%x, "
8099 "ue_mask_hi_reg=0x%x\n",
8102 phba
->sli4_hba
.ue_mask_lo
,
8103 phba
->sli4_hba
.ue_mask_hi
);
8104 port_error
= -ENODEV
;
8107 case LPFC_SLI_INTF_IF_TYPE_2
:
8108 case LPFC_SLI_INTF_IF_TYPE_6
:
8109 /* Final checks. The port status should be clean. */
8110 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
8112 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
8113 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
8114 phba
->work_status
[0] =
8115 readl(phba
->sli4_hba
.u
.if_type2
.
8117 phba
->work_status
[1] =
8118 readl(phba
->sli4_hba
.u
.if_type2
.
8120 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8121 "2888 Unrecoverable port error "
8122 "following POST: port status reg "
8123 "0x%x, port_smphr reg 0x%x, "
8124 "error 1=0x%x, error 2=0x%x\n",
8126 portsmphr_reg
.word0
,
8127 phba
->work_status
[0],
8128 phba
->work_status
[1]);
8129 port_error
= -ENODEV
;
8132 case LPFC_SLI_INTF_IF_TYPE_1
:
8141 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
8142 * @phba: pointer to lpfc hba data structure.
8143 * @if_type: The SLI4 interface type getting configured.
8145 * This routine is invoked to set up SLI4 BAR0 PCI config space register
8149 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
8152 case LPFC_SLI_INTF_IF_TYPE_0
:
8153 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
8154 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
8155 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
8156 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
8157 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
8158 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
8159 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
8160 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
8161 phba
->sli4_hba
.SLIINTFregaddr
=
8162 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
8164 case LPFC_SLI_INTF_IF_TYPE_2
:
8165 phba
->sli4_hba
.u
.if_type2
.EQDregaddr
=
8166 phba
->sli4_hba
.conf_regs_memmap_p
+
8167 LPFC_CTL_PORT_EQ_DELAY_OFFSET
;
8168 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
8169 phba
->sli4_hba
.conf_regs_memmap_p
+
8170 LPFC_CTL_PORT_ER1_OFFSET
;
8171 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
8172 phba
->sli4_hba
.conf_regs_memmap_p
+
8173 LPFC_CTL_PORT_ER2_OFFSET
;
8174 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
8175 phba
->sli4_hba
.conf_regs_memmap_p
+
8176 LPFC_CTL_PORT_CTL_OFFSET
;
8177 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
8178 phba
->sli4_hba
.conf_regs_memmap_p
+
8179 LPFC_CTL_PORT_STA_OFFSET
;
8180 phba
->sli4_hba
.SLIINTFregaddr
=
8181 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
8182 phba
->sli4_hba
.PSMPHRregaddr
=
8183 phba
->sli4_hba
.conf_regs_memmap_p
+
8184 LPFC_CTL_PORT_SEM_OFFSET
;
8185 phba
->sli4_hba
.RQDBregaddr
=
8186 phba
->sli4_hba
.conf_regs_memmap_p
+
8187 LPFC_ULP0_RQ_DOORBELL
;
8188 phba
->sli4_hba
.WQDBregaddr
=
8189 phba
->sli4_hba
.conf_regs_memmap_p
+
8190 LPFC_ULP0_WQ_DOORBELL
;
8191 phba
->sli4_hba
.CQDBregaddr
=
8192 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
8193 phba
->sli4_hba
.EQDBregaddr
= phba
->sli4_hba
.CQDBregaddr
;
8194 phba
->sli4_hba
.MQDBregaddr
=
8195 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
8196 phba
->sli4_hba
.BMBXregaddr
=
8197 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
8199 case LPFC_SLI_INTF_IF_TYPE_6
:
8200 phba
->sli4_hba
.u
.if_type2
.EQDregaddr
=
8201 phba
->sli4_hba
.conf_regs_memmap_p
+
8202 LPFC_CTL_PORT_EQ_DELAY_OFFSET
;
8203 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
8204 phba
->sli4_hba
.conf_regs_memmap_p
+
8205 LPFC_CTL_PORT_ER1_OFFSET
;
8206 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
8207 phba
->sli4_hba
.conf_regs_memmap_p
+
8208 LPFC_CTL_PORT_ER2_OFFSET
;
8209 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
8210 phba
->sli4_hba
.conf_regs_memmap_p
+
8211 LPFC_CTL_PORT_CTL_OFFSET
;
8212 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
8213 phba
->sli4_hba
.conf_regs_memmap_p
+
8214 LPFC_CTL_PORT_STA_OFFSET
;
8215 phba
->sli4_hba
.PSMPHRregaddr
=
8216 phba
->sli4_hba
.conf_regs_memmap_p
+
8217 LPFC_CTL_PORT_SEM_OFFSET
;
8218 phba
->sli4_hba
.BMBXregaddr
=
8219 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
8221 case LPFC_SLI_INTF_IF_TYPE_1
:
8223 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
8224 "FATAL - unsupported SLI4 interface type - %d\n",
8231 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8232 * @phba: pointer to lpfc hba data structure.
8233 * @if_type: sli if type to operate on.
8235 * This routine is invoked to set up SLI4 BAR1 register memory map.
8238 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
8241 case LPFC_SLI_INTF_IF_TYPE_0
:
8242 phba
->sli4_hba
.PSMPHRregaddr
=
8243 phba
->sli4_hba
.ctrl_regs_memmap_p
+
8244 LPFC_SLIPORT_IF0_SMPHR
;
8245 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
8247 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
8249 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
8252 case LPFC_SLI_INTF_IF_TYPE_6
:
8253 phba
->sli4_hba
.RQDBregaddr
= phba
->sli4_hba
.drbl_regs_memmap_p
+
8254 LPFC_IF6_RQ_DOORBELL
;
8255 phba
->sli4_hba
.WQDBregaddr
= phba
->sli4_hba
.drbl_regs_memmap_p
+
8256 LPFC_IF6_WQ_DOORBELL
;
8257 phba
->sli4_hba
.CQDBregaddr
= phba
->sli4_hba
.drbl_regs_memmap_p
+
8258 LPFC_IF6_CQ_DOORBELL
;
8259 phba
->sli4_hba
.EQDBregaddr
= phba
->sli4_hba
.drbl_regs_memmap_p
+
8260 LPFC_IF6_EQ_DOORBELL
;
8261 phba
->sli4_hba
.MQDBregaddr
= phba
->sli4_hba
.drbl_regs_memmap_p
+
8262 LPFC_IF6_MQ_DOORBELL
;
8264 case LPFC_SLI_INTF_IF_TYPE_2
:
8265 case LPFC_SLI_INTF_IF_TYPE_1
:
8267 dev_err(&phba
->pcidev
->dev
,
8268 "FATAL - unsupported SLI4 interface type - %d\n",
8275 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8276 * @phba: pointer to lpfc hba data structure.
8277 * @vf: virtual function number
8279 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8280 * based on the given viftual function number, @vf.
8282 * Return 0 if successful, otherwise -ENODEV.
8285 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
8287 if (vf
> LPFC_VIR_FUNC_MAX
)
8290 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
8291 vf
* LPFC_VFR_PAGE_SIZE
+
8292 LPFC_ULP0_RQ_DOORBELL
);
8293 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
8294 vf
* LPFC_VFR_PAGE_SIZE
+
8295 LPFC_ULP0_WQ_DOORBELL
);
8296 phba
->sli4_hba
.CQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
8297 vf
* LPFC_VFR_PAGE_SIZE
+
8298 LPFC_EQCQ_DOORBELL
);
8299 phba
->sli4_hba
.EQDBregaddr
= phba
->sli4_hba
.CQDBregaddr
;
8300 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
8301 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
8302 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
8303 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
8308 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
8309 * @phba: pointer to lpfc hba data structure.
8311 * This routine is invoked to create the bootstrap mailbox
8312 * region consistent with the SLI-4 interface spec. This
8313 * routine allocates all memory necessary to communicate
8314 * mailbox commands to the port and sets up all alignment
8315 * needs. No locks are expected to be held when calling
8320 * -ENOMEM - could not allocated memory.
8323 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
8326 struct lpfc_dmabuf
*dmabuf
;
8327 struct dma_address
*dma_address
;
8331 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
8336 * The bootstrap mailbox region is comprised of 2 parts
8337 * plus an alignment restriction of 16 bytes.
8339 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
8340 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
, bmbx_size
,
8341 &dmabuf
->phys
, GFP_KERNEL
);
8342 if (!dmabuf
->virt
) {
8348 * Initialize the bootstrap mailbox pointers now so that the register
8349 * operations are simple later. The mailbox dma address is required
8350 * to be 16-byte aligned. Also align the virtual memory as each
8351 * maibox is copied into the bmbx mailbox region before issuing the
8352 * command to the port.
8354 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
8355 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
8357 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
8358 LPFC_ALIGN_16_BYTE
);
8359 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
8360 LPFC_ALIGN_16_BYTE
);
8363 * Set the high and low physical addresses now. The SLI4 alignment
8364 * requirement is 16 bytes and the mailbox is posted to the port
8365 * as two 30-bit addresses. The other data is a bit marking whether
8366 * the 30-bit address is the high or low address.
8367 * Upcast bmbx aphys to 64bits so shift instruction compiles
8368 * clean on 32 bit machines.
8370 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
8371 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
8372 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
8373 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
8374 LPFC_BMBX_BIT1_ADDR_HI
);
8376 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
8377 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
8378 LPFC_BMBX_BIT1_ADDR_LO
);
8383 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
8384 * @phba: pointer to lpfc hba data structure.
8386 * This routine is invoked to teardown the bootstrap mailbox
8387 * region and release all host resources. This routine requires
8388 * the caller to ensure all mailbox commands recovered, no
8389 * additional mailbox comands are sent, and interrupts are disabled
8390 * before calling this routine.
8394 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
8396 dma_free_coherent(&phba
->pcidev
->dev
,
8397 phba
->sli4_hba
.bmbx
.bmbx_size
,
8398 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
8399 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
8401 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
8402 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
8405 static const char * const lpfc_topo_to_str
[] = {
8415 #define LINK_FLAGS_DEF 0x0
8416 #define LINK_FLAGS_P2P 0x1
8417 #define LINK_FLAGS_LOOP 0x2
8419 * lpfc_map_topology - Map the topology read from READ_CONFIG
8420 * @phba: pointer to lpfc hba data structure.
8421 * @rd_config: pointer to read config data
8423 * This routine is invoked to map the topology values as read
8424 * from the read config mailbox command. If the persistent
8425 * topology feature is supported, the firmware will provide the
8426 * saved topology information to be used in INIT_LINK
8429 lpfc_map_topology(struct lpfc_hba
*phba
, struct lpfc_mbx_read_config
*rd_config
)
8433 ptv
= bf_get(lpfc_mbx_rd_conf_ptv
, rd_config
);
8434 tf
= bf_get(lpfc_mbx_rd_conf_tf
, rd_config
);
8435 pt
= bf_get(lpfc_mbx_rd_conf_pt
, rd_config
);
8437 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8438 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
8441 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8442 "2019 FW does not support persistent topology "
8443 "Using driver parameter defined value [%s]",
8444 lpfc_topo_to_str
[phba
->cfg_topology
]);
8447 /* FW supports persistent topology - override module parameter value */
8448 phba
->hba_flag
|= HBA_PERSISTENT_TOPO
;
8449 switch (phba
->pcidev
->device
) {
8450 case PCI_DEVICE_ID_LANCER_G7_FC
:
8451 case PCI_DEVICE_ID_LANCER_G6_FC
:
8453 phba
->cfg_topology
= ((pt
== LINK_FLAGS_LOOP
)
8454 ? FLAGS_TOPOLOGY_MODE_LOOP
8455 : FLAGS_TOPOLOGY_MODE_PT_PT
);
8457 phba
->hba_flag
&= ~HBA_PERSISTENT_TOPO
;
8462 /* If topology failover set - pt is '0' or '1' */
8463 phba
->cfg_topology
= (pt
? FLAGS_TOPOLOGY_MODE_PT_LOOP
:
8464 FLAGS_TOPOLOGY_MODE_LOOP_PT
);
8466 phba
->cfg_topology
= ((pt
== LINK_FLAGS_P2P
)
8467 ? FLAGS_TOPOLOGY_MODE_PT_PT
8468 : FLAGS_TOPOLOGY_MODE_LOOP
);
8472 if (phba
->hba_flag
& HBA_PERSISTENT_TOPO
) {
8473 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8474 "2020 Using persistent topology value [%s]",
8475 lpfc_topo_to_str
[phba
->cfg_topology
]);
8477 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8478 "2021 Invalid topology values from FW "
8479 "Using driver parameter defined value [%s]",
8480 lpfc_topo_to_str
[phba
->cfg_topology
]);
8485 * lpfc_sli4_read_config - Get the config parameters.
8486 * @phba: pointer to lpfc hba data structure.
8488 * This routine is invoked to read the configuration parameters from the HBA.
8489 * The configuration parameters are used to set the base and maximum values
8490 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
8491 * allocation for the port.
8495 * -ENOMEM - No available memory
8496 * -EIO - The mailbox failed to complete successfully.
8499 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
8502 struct lpfc_mbx_read_config
*rd_config
;
8503 union lpfc_sli4_cfg_shdr
*shdr
;
8504 uint32_t shdr_status
, shdr_add_status
;
8505 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
8506 struct lpfc_rsrc_desc_fcfcoe
*desc
;
8508 uint16_t forced_link_speed
;
8509 uint32_t if_type
, qmin
;
8510 int length
, i
, rc
= 0, rc2
;
8512 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8514 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8515 "2011 Unable to allocate memory for issuing "
8516 "SLI_CONFIG_SPECIAL mailbox command\n");
8520 lpfc_read_config(phba
, pmb
);
8522 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
8523 if (rc
!= MBX_SUCCESS
) {
8524 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8525 "2012 Mailbox failed , mbxCmd x%x "
8526 "READ_CONFIG, mbxStatus x%x\n",
8527 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
8528 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
8531 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
8532 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
8533 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
8534 phba
->sli4_hba
.lnk_info
.lnk_tp
=
8535 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
8536 phba
->sli4_hba
.lnk_info
.lnk_no
=
8537 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
8538 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8539 "3081 lnk_type:%d, lnk_numb:%d\n",
8540 phba
->sli4_hba
.lnk_info
.lnk_tp
,
8541 phba
->sli4_hba
.lnk_info
.lnk_no
);
8543 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8544 "3082 Mailbox (x%x) returned ldv:x0\n",
8545 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
8546 if (bf_get(lpfc_mbx_rd_conf_bbscn_def
, rd_config
)) {
8547 phba
->bbcredit_support
= 1;
8548 phba
->sli4_hba
.bbscn_params
.word0
= rd_config
->word8
;
8551 phba
->sli4_hba
.conf_trunk
=
8552 bf_get(lpfc_mbx_rd_conf_trunk
, rd_config
);
8553 phba
->sli4_hba
.extents_in_use
=
8554 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
8555 phba
->sli4_hba
.max_cfg_param
.max_xri
=
8556 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
8557 /* Reduce resource usage in kdump environment */
8558 if (is_kdump_kernel() &&
8559 phba
->sli4_hba
.max_cfg_param
.max_xri
> 512)
8560 phba
->sli4_hba
.max_cfg_param
.max_xri
= 512;
8561 phba
->sli4_hba
.max_cfg_param
.xri_base
=
8562 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
8563 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
8564 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
8565 /* Limit the max we support */
8566 if (phba
->sli4_hba
.max_cfg_param
.max_vpi
> LPFC_MAX_VPORTS
)
8567 phba
->sli4_hba
.max_cfg_param
.max_vpi
= LPFC_MAX_VPORTS
;
8568 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
8569 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
8570 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
8571 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
8572 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
8573 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
8574 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
8575 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
8576 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
8577 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
8578 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
8579 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
8580 phba
->sli4_hba
.max_cfg_param
.max_eq
=
8581 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
8582 phba
->sli4_hba
.max_cfg_param
.max_rq
=
8583 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
8584 phba
->sli4_hba
.max_cfg_param
.max_wq
=
8585 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
8586 phba
->sli4_hba
.max_cfg_param
.max_cq
=
8587 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
8588 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
8589 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
8590 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
8591 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
8592 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
8593 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
8594 phba
->max_vports
= phba
->max_vpi
;
8595 lpfc_map_topology(phba
, rd_config
);
8596 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8597 "2003 cfg params Extents? %d "
8602 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
8603 phba
->sli4_hba
.extents_in_use
,
8604 phba
->sli4_hba
.max_cfg_param
.xri_base
,
8605 phba
->sli4_hba
.max_cfg_param
.max_xri
,
8606 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
8607 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
8608 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
8609 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
8610 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
8611 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
8612 phba
->sli4_hba
.max_cfg_param
.max_fcfi
,
8613 phba
->sli4_hba
.max_cfg_param
.max_eq
,
8614 phba
->sli4_hba
.max_cfg_param
.max_cq
,
8615 phba
->sli4_hba
.max_cfg_param
.max_wq
,
8616 phba
->sli4_hba
.max_cfg_param
.max_rq
,
8620 * Calculate queue resources based on how
8621 * many WQ/CQ/EQs are available.
8623 qmin
= phba
->sli4_hba
.max_cfg_param
.max_wq
;
8624 if (phba
->sli4_hba
.max_cfg_param
.max_cq
< qmin
)
8625 qmin
= phba
->sli4_hba
.max_cfg_param
.max_cq
;
8626 if (phba
->sli4_hba
.max_cfg_param
.max_eq
< qmin
)
8627 qmin
= phba
->sli4_hba
.max_cfg_param
.max_eq
;
8629 * Whats left after this can go toward NVME / FCP.
8630 * The minus 4 accounts for ELS, NVME LS, MBOX
8631 * plus one extra. When configured for
8632 * NVMET, FCP io channel WQs are not created.
8636 /* Check to see if there is enough for NVME */
8637 if ((phba
->cfg_irq_chann
> qmin
) ||
8638 (phba
->cfg_hdw_queue
> qmin
)) {
8639 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8640 "2005 Reducing Queues - "
8641 "FW resource limitation: "
8642 "WQ %d CQ %d EQ %d: min %d: "
8644 phba
->sli4_hba
.max_cfg_param
.max_wq
,
8645 phba
->sli4_hba
.max_cfg_param
.max_cq
,
8646 phba
->sli4_hba
.max_cfg_param
.max_eq
,
8647 qmin
, phba
->cfg_irq_chann
,
8648 phba
->cfg_hdw_queue
);
8650 if (phba
->cfg_irq_chann
> qmin
)
8651 phba
->cfg_irq_chann
= qmin
;
8652 if (phba
->cfg_hdw_queue
> qmin
)
8653 phba
->cfg_hdw_queue
= qmin
;
8660 /* Update link speed if forced link speed is supported */
8661 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8662 if (if_type
>= LPFC_SLI_INTF_IF_TYPE_2
) {
8664 bf_get(lpfc_mbx_rd_conf_link_speed
, rd_config
);
8665 if (forced_link_speed
) {
8666 phba
->hba_flag
|= HBA_FORCED_LINK_SPEED
;
8668 switch (forced_link_speed
) {
8670 phba
->cfg_link_speed
=
8671 LPFC_USER_LINK_SPEED_1G
;
8674 phba
->cfg_link_speed
=
8675 LPFC_USER_LINK_SPEED_2G
;
8678 phba
->cfg_link_speed
=
8679 LPFC_USER_LINK_SPEED_4G
;
8682 phba
->cfg_link_speed
=
8683 LPFC_USER_LINK_SPEED_8G
;
8685 case LINK_SPEED_10G
:
8686 phba
->cfg_link_speed
=
8687 LPFC_USER_LINK_SPEED_10G
;
8689 case LINK_SPEED_16G
:
8690 phba
->cfg_link_speed
=
8691 LPFC_USER_LINK_SPEED_16G
;
8693 case LINK_SPEED_32G
:
8694 phba
->cfg_link_speed
=
8695 LPFC_USER_LINK_SPEED_32G
;
8697 case LINK_SPEED_64G
:
8698 phba
->cfg_link_speed
=
8699 LPFC_USER_LINK_SPEED_64G
;
8702 phba
->cfg_link_speed
=
8703 LPFC_USER_LINK_SPEED_AUTO
;
8706 lpfc_printf_log(phba
, KERN_ERR
,
8708 "0047 Unrecognized link "
8711 phba
->cfg_link_speed
=
8712 LPFC_USER_LINK_SPEED_AUTO
;
8717 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
8718 length
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
8719 lpfc_sli4_get_els_iocb_cnt(phba
);
8720 if (phba
->cfg_hba_queue_depth
> length
) {
8721 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8722 "3361 HBA queue depth changed from %d to %d\n",
8723 phba
->cfg_hba_queue_depth
, length
);
8724 phba
->cfg_hba_queue_depth
= length
;
8727 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
8728 LPFC_SLI_INTF_IF_TYPE_2
)
8731 /* get the pf# and vf# for SLI4 if_type 2 port */
8732 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
8733 sizeof(struct lpfc_sli4_cfg_mhdr
));
8734 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8735 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
8736 length
, LPFC_SLI4_MBX_EMBED
);
8738 rc2
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
8739 shdr
= (union lpfc_sli4_cfg_shdr
*)
8740 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
8741 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
8742 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
8743 if (rc2
|| shdr_status
|| shdr_add_status
) {
8744 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8745 "3026 Mailbox failed , mbxCmd x%x "
8746 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8747 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
8748 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
8752 /* search for fc_fcoe resrouce descriptor */
8753 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
8755 pdesc_0
= (char *)&get_func_cfg
->func_cfg
.desc
[0];
8756 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)pdesc_0
;
8757 length
= bf_get(lpfc_rsrc_desc_fcfcoe_length
, desc
);
8758 if (length
== LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD
)
8759 length
= LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH
;
8760 else if (length
!= LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH
)
8763 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
8764 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)(pdesc_0
+ length
* i
);
8765 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
8766 bf_get(lpfc_rsrc_desc_fcfcoe_type
, desc
)) {
8767 phba
->sli4_hba
.iov
.pf_number
=
8768 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
8769 phba
->sli4_hba
.iov
.vf_number
=
8770 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
8775 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
8776 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8777 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8778 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
8779 phba
->sli4_hba
.iov
.vf_number
);
8781 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8782 "3028 GET_FUNCTION_CONFIG: failed to find "
8783 "Resource Descriptor:x%x\n",
8784 LPFC_RSRC_DESC_TYPE_FCFCOE
);
8787 mempool_free(pmb
, phba
->mbox_mem_pool
);
8792 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
8793 * @phba: pointer to lpfc hba data structure.
8795 * This routine is invoked to setup the port-side endian order when
8796 * the port if_type is 0. This routine has no function for other
8801 * -ENOMEM - No available memory
8802 * -EIO - The mailbox failed to complete successfully.
8805 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
8807 LPFC_MBOXQ_t
*mboxq
;
8808 uint32_t if_type
, rc
= 0;
8809 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
8810 HOST_ENDIAN_HIGH_WORD1
};
8812 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8814 case LPFC_SLI_INTF_IF_TYPE_0
:
8815 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
8818 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8819 "0492 Unable to allocate memory for "
8820 "issuing SLI_CONFIG_SPECIAL mailbox "
8826 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8827 * two words to contain special data values and no other data.
8829 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
8830 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
8831 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8832 if (rc
!= MBX_SUCCESS
) {
8833 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8834 "0493 SLI_CONFIG_SPECIAL mailbox "
8835 "failed with status x%x\n",
8839 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8841 case LPFC_SLI_INTF_IF_TYPE_6
:
8842 case LPFC_SLI_INTF_IF_TYPE_2
:
8843 case LPFC_SLI_INTF_IF_TYPE_1
:
8851 * lpfc_sli4_queue_verify - Verify and update EQ counts
8852 * @phba: pointer to lpfc hba data structure.
8854 * This routine is invoked to check the user settable queue counts for EQs.
8855 * After this routine is called the counts will be set to valid values that
8856 * adhere to the constraints of the system's interrupt vectors and the port's
8861 * -ENOMEM - No available memory
8864 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
8867 * Sanity check for configured queue parameters against the run-time
8871 if (phba
->nvmet_support
) {
8872 if (phba
->cfg_hdw_queue
< phba
->cfg_nvmet_mrq
)
8873 phba
->cfg_nvmet_mrq
= phba
->cfg_hdw_queue
;
8874 if (phba
->cfg_nvmet_mrq
> LPFC_NVMET_MRQ_MAX
)
8875 phba
->cfg_nvmet_mrq
= LPFC_NVMET_MRQ_MAX
;
8878 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8879 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
8880 phba
->cfg_hdw_queue
, phba
->cfg_irq_chann
,
8881 phba
->cfg_nvmet_mrq
);
8883 /* Get EQ depth from module parameter, fake the default for now */
8884 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
8885 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
8887 /* Get CQ depth from module parameter, fake the default for now */
8888 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
8889 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
8894 lpfc_alloc_io_wq_cq(struct lpfc_hba
*phba
, int idx
)
8896 struct lpfc_queue
*qdesc
;
8900 cpu
= lpfc_find_cpu_handle(phba
, idx
, LPFC_FIND_BY_HDWQ
);
8901 /* Create Fast Path IO CQs */
8902 if (phba
->enab_exp_wqcq_pages
)
8903 /* Increase the CQ size when WQEs contain an embedded cdb */
8904 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_EXPANDED_PAGE_SIZE
,
8905 phba
->sli4_hba
.cq_esize
,
8906 LPFC_CQE_EXP_COUNT
, cpu
);
8909 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
8910 phba
->sli4_hba
.cq_esize
,
8911 phba
->sli4_hba
.cq_ecount
, cpu
);
8913 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8914 "0499 Failed allocate fast-path IO CQ (%d)\n",
8918 qdesc
->qe_valid
= 1;
8921 phba
->sli4_hba
.hdwq
[idx
].io_cq
= qdesc
;
8923 /* Create Fast Path IO WQs */
8924 if (phba
->enab_exp_wqcq_pages
) {
8925 /* Increase the WQ size when WQEs contain an embedded cdb */
8926 wqesize
= (phba
->fcp_embed_io
) ?
8927 LPFC_WQE128_SIZE
: phba
->sli4_hba
.wq_esize
;
8928 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_EXPANDED_PAGE_SIZE
,
8930 LPFC_WQE_EXP_COUNT
, cpu
);
8932 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
8933 phba
->sli4_hba
.wq_esize
,
8934 phba
->sli4_hba
.wq_ecount
, cpu
);
8937 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8938 "0503 Failed allocate fast-path IO WQ (%d)\n",
8944 phba
->sli4_hba
.hdwq
[idx
].io_wq
= qdesc
;
8945 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
8950 * lpfc_sli4_queue_create - Create all the SLI4 queues
8951 * @phba: pointer to lpfc hba data structure.
8953 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8954 * operation. For each SLI4 queue type, the parameters such as queue entry
8955 * count (queue depth) shall be taken from the module parameter. For now,
8956 * we just use some constant number as place holder.
8960 * -ENOMEM - No availble memory
8961 * -EIO - The mailbox failed to complete successfully.
8964 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
8966 struct lpfc_queue
*qdesc
;
8967 int idx
, cpu
, eqcpu
;
8968 struct lpfc_sli4_hdw_queue
*qp
;
8969 struct lpfc_vector_map_info
*cpup
;
8970 struct lpfc_vector_map_info
*eqcpup
;
8971 struct lpfc_eq_intr_info
*eqi
;
8974 * Create HBA Record arrays.
8975 * Both NVME and FCP will share that same vectors / EQs
8977 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
8978 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
8979 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
8980 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
8981 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
8982 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
8983 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
8984 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
8985 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
8986 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
8988 if (!phba
->sli4_hba
.hdwq
) {
8989 phba
->sli4_hba
.hdwq
= kcalloc(
8990 phba
->cfg_hdw_queue
, sizeof(struct lpfc_sli4_hdw_queue
),
8992 if (!phba
->sli4_hba
.hdwq
) {
8993 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
8994 "6427 Failed allocate memory for "
8995 "fast-path Hardware Queue array\n");
8998 /* Prepare hardware queues to take IO buffers */
8999 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
9000 qp
= &phba
->sli4_hba
.hdwq
[idx
];
9001 spin_lock_init(&qp
->io_buf_list_get_lock
);
9002 spin_lock_init(&qp
->io_buf_list_put_lock
);
9003 INIT_LIST_HEAD(&qp
->lpfc_io_buf_list_get
);
9004 INIT_LIST_HEAD(&qp
->lpfc_io_buf_list_put
);
9005 qp
->get_io_bufs
= 0;
9006 qp
->put_io_bufs
= 0;
9007 qp
->total_io_bufs
= 0;
9008 spin_lock_init(&qp
->abts_io_buf_list_lock
);
9009 INIT_LIST_HEAD(&qp
->lpfc_abts_io_buf_list
);
9010 qp
->abts_scsi_io_bufs
= 0;
9011 qp
->abts_nvme_io_bufs
= 0;
9012 INIT_LIST_HEAD(&qp
->sgl_list
);
9013 INIT_LIST_HEAD(&qp
->cmd_rsp_buf_list
);
9014 spin_lock_init(&qp
->hdwq_lock
);
9018 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
9019 if (phba
->nvmet_support
) {
9020 phba
->sli4_hba
.nvmet_cqset
= kcalloc(
9021 phba
->cfg_nvmet_mrq
,
9022 sizeof(struct lpfc_queue
*),
9024 if (!phba
->sli4_hba
.nvmet_cqset
) {
9025 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9026 "3121 Fail allocate memory for "
9027 "fast-path CQ set array\n");
9030 phba
->sli4_hba
.nvmet_mrq_hdr
= kcalloc(
9031 phba
->cfg_nvmet_mrq
,
9032 sizeof(struct lpfc_queue
*),
9034 if (!phba
->sli4_hba
.nvmet_mrq_hdr
) {
9035 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9036 "3122 Fail allocate memory for "
9037 "fast-path RQ set hdr array\n");
9040 phba
->sli4_hba
.nvmet_mrq_data
= kcalloc(
9041 phba
->cfg_nvmet_mrq
,
9042 sizeof(struct lpfc_queue
*),
9044 if (!phba
->sli4_hba
.nvmet_mrq_data
) {
9045 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9046 "3124 Fail allocate memory for "
9047 "fast-path RQ set data array\n");
9053 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
9055 /* Create HBA Event Queues (EQs) */
9056 for_each_present_cpu(cpu
) {
9057 /* We only want to create 1 EQ per vector, even though
9058 * multiple CPUs might be using that vector. so only
9059 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
9061 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
9062 if (!(cpup
->flag
& LPFC_CPU_FIRST_IRQ
))
9065 /* Get a ptr to the Hardware Queue associated with this CPU */
9066 qp
= &phba
->sli4_hba
.hdwq
[cpup
->hdwq
];
9068 /* Allocate an EQ */
9069 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9070 phba
->sli4_hba
.eq_esize
,
9071 phba
->sli4_hba
.eq_ecount
, cpu
);
9073 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9074 "0497 Failed allocate EQ (%d)\n",
9078 qdesc
->qe_valid
= 1;
9079 qdesc
->hdwq
= cpup
->hdwq
;
9080 qdesc
->chann
= cpu
; /* First CPU this EQ is affinitized to */
9081 qdesc
->last_cpu
= qdesc
->chann
;
9083 /* Save the allocated EQ in the Hardware Queue */
9086 eqi
= per_cpu_ptr(phba
->sli4_hba
.eq_info
, qdesc
->last_cpu
);
9087 list_add(&qdesc
->cpu_list
, &eqi
->list
);
9090 /* Now we need to populate the other Hardware Queues, that share
9091 * an IRQ vector, with the associated EQ ptr.
9093 for_each_present_cpu(cpu
) {
9094 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
9096 /* Check for EQ already allocated in previous loop */
9097 if (cpup
->flag
& LPFC_CPU_FIRST_IRQ
)
9100 /* Check for multiple CPUs per hdwq */
9101 qp
= &phba
->sli4_hba
.hdwq
[cpup
->hdwq
];
9105 /* We need to share an EQ for this hdwq */
9106 eqcpu
= lpfc_find_cpu_handle(phba
, cpup
->eq
, LPFC_FIND_BY_EQ
);
9107 eqcpup
= &phba
->sli4_hba
.cpu_map
[eqcpu
];
9108 qp
->hba_eq
= phba
->sli4_hba
.hdwq
[eqcpup
->hdwq
].hba_eq
;
9111 /* Allocate IO Path SLI4 CQ/WQs */
9112 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
9113 if (lpfc_alloc_io_wq_cq(phba
, idx
))
9117 if (phba
->nvmet_support
) {
9118 for (idx
= 0; idx
< phba
->cfg_nvmet_mrq
; idx
++) {
9119 cpu
= lpfc_find_cpu_handle(phba
, idx
,
9121 qdesc
= lpfc_sli4_queue_alloc(phba
,
9122 LPFC_DEFAULT_PAGE_SIZE
,
9123 phba
->sli4_hba
.cq_esize
,
9124 phba
->sli4_hba
.cq_ecount
,
9127 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9128 "3142 Failed allocate NVME "
9129 "CQ Set (%d)\n", idx
);
9132 qdesc
->qe_valid
= 1;
9135 phba
->sli4_hba
.nvmet_cqset
[idx
] = qdesc
;
9140 * Create Slow Path Completion Queues (CQs)
9143 cpu
= lpfc_find_cpu_handle(phba
, 0, LPFC_FIND_BY_EQ
);
9144 /* Create slow-path Mailbox Command Complete Queue */
9145 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9146 phba
->sli4_hba
.cq_esize
,
9147 phba
->sli4_hba
.cq_ecount
, cpu
);
9149 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9150 "0500 Failed allocate slow-path mailbox CQ\n");
9153 qdesc
->qe_valid
= 1;
9154 phba
->sli4_hba
.mbx_cq
= qdesc
;
9156 /* Create slow-path ELS Complete Queue */
9157 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9158 phba
->sli4_hba
.cq_esize
,
9159 phba
->sli4_hba
.cq_ecount
, cpu
);
9161 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9162 "0501 Failed allocate slow-path ELS CQ\n");
9165 qdesc
->qe_valid
= 1;
9167 phba
->sli4_hba
.els_cq
= qdesc
;
9171 * Create Slow Path Work Queues (WQs)
9174 /* Create Mailbox Command Queue */
9176 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9177 phba
->sli4_hba
.mq_esize
,
9178 phba
->sli4_hba
.mq_ecount
, cpu
);
9180 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9181 "0505 Failed allocate slow-path MQ\n");
9185 phba
->sli4_hba
.mbx_wq
= qdesc
;
9188 * Create ELS Work Queues
9191 /* Create slow-path ELS Work Queue */
9192 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9193 phba
->sli4_hba
.wq_esize
,
9194 phba
->sli4_hba
.wq_ecount
, cpu
);
9196 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9197 "0504 Failed allocate slow-path ELS WQ\n");
9201 phba
->sli4_hba
.els_wq
= qdesc
;
9202 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
9204 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
9205 /* Create NVME LS Complete Queue */
9206 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9207 phba
->sli4_hba
.cq_esize
,
9208 phba
->sli4_hba
.cq_ecount
, cpu
);
9210 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9211 "6079 Failed allocate NVME LS CQ\n");
9215 qdesc
->qe_valid
= 1;
9216 phba
->sli4_hba
.nvmels_cq
= qdesc
;
9218 /* Create NVME LS Work Queue */
9219 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9220 phba
->sli4_hba
.wq_esize
,
9221 phba
->sli4_hba
.wq_ecount
, cpu
);
9223 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9224 "6080 Failed allocate NVME LS WQ\n");
9228 phba
->sli4_hba
.nvmels_wq
= qdesc
;
9229 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
9233 * Create Receive Queue (RQ)
9236 /* Create Receive Queue for header */
9237 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9238 phba
->sli4_hba
.rq_esize
,
9239 phba
->sli4_hba
.rq_ecount
, cpu
);
9241 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9242 "0506 Failed allocate receive HRQ\n");
9245 phba
->sli4_hba
.hdr_rq
= qdesc
;
9247 /* Create Receive Queue for data */
9248 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_DEFAULT_PAGE_SIZE
,
9249 phba
->sli4_hba
.rq_esize
,
9250 phba
->sli4_hba
.rq_ecount
, cpu
);
9252 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9253 "0507 Failed allocate receive DRQ\n");
9256 phba
->sli4_hba
.dat_rq
= qdesc
;
9258 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
9259 phba
->nvmet_support
) {
9260 for (idx
= 0; idx
< phba
->cfg_nvmet_mrq
; idx
++) {
9261 cpu
= lpfc_find_cpu_handle(phba
, idx
,
9263 /* Create NVMET Receive Queue for header */
9264 qdesc
= lpfc_sli4_queue_alloc(phba
,
9265 LPFC_DEFAULT_PAGE_SIZE
,
9266 phba
->sli4_hba
.rq_esize
,
9267 LPFC_NVMET_RQE_DEF_COUNT
,
9270 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9271 "3146 Failed allocate "
9276 phba
->sli4_hba
.nvmet_mrq_hdr
[idx
] = qdesc
;
9278 /* Only needed for header of RQ pair */
9279 qdesc
->rqbp
= kzalloc_node(sizeof(*qdesc
->rqbp
),
9282 if (qdesc
->rqbp
== NULL
) {
9283 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9284 "6131 Failed allocate "
9289 /* Put list in known state in case driver load fails. */
9290 INIT_LIST_HEAD(&qdesc
->rqbp
->rqb_buffer_list
);
9292 /* Create NVMET Receive Queue for data */
9293 qdesc
= lpfc_sli4_queue_alloc(phba
,
9294 LPFC_DEFAULT_PAGE_SIZE
,
9295 phba
->sli4_hba
.rq_esize
,
9296 LPFC_NVMET_RQE_DEF_COUNT
,
9299 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9300 "3156 Failed allocate "
9305 phba
->sli4_hba
.nvmet_mrq_data
[idx
] = qdesc
;
9309 /* Clear NVME stats */
9310 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
9311 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
9312 memset(&phba
->sli4_hba
.hdwq
[idx
].nvme_cstat
, 0,
9313 sizeof(phba
->sli4_hba
.hdwq
[idx
].nvme_cstat
));
9317 /* Clear SCSI stats */
9318 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
9319 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
9320 memset(&phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
, 0,
9321 sizeof(phba
->sli4_hba
.hdwq
[idx
].scsi_cstat
));
9328 lpfc_sli4_queue_destroy(phba
);
9333 __lpfc_sli4_release_queue(struct lpfc_queue
**qp
)
9336 lpfc_sli4_queue_free(*qp
);
9342 lpfc_sli4_release_queues(struct lpfc_queue
***qs
, int max
)
9349 for (idx
= 0; idx
< max
; idx
++)
9350 __lpfc_sli4_release_queue(&(*qs
)[idx
]);
9357 lpfc_sli4_release_hdwq(struct lpfc_hba
*phba
)
9359 struct lpfc_sli4_hdw_queue
*hdwq
;
9360 struct lpfc_queue
*eq
;
9363 hdwq
= phba
->sli4_hba
.hdwq
;
9365 /* Loop thru all Hardware Queues */
9366 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
9367 /* Free the CQ/WQ corresponding to the Hardware Queue */
9368 lpfc_sli4_queue_free(hdwq
[idx
].io_cq
);
9369 lpfc_sli4_queue_free(hdwq
[idx
].io_wq
);
9370 hdwq
[idx
].hba_eq
= NULL
;
9371 hdwq
[idx
].io_cq
= NULL
;
9372 hdwq
[idx
].io_wq
= NULL
;
9373 if (phba
->cfg_xpsgl
&& !phba
->nvmet_support
)
9374 lpfc_free_sgl_per_hdwq(phba
, &hdwq
[idx
]);
9375 lpfc_free_cmd_rsp_buf_per_hdwq(phba
, &hdwq
[idx
]);
9377 /* Loop thru all IRQ vectors */
9378 for (idx
= 0; idx
< phba
->cfg_irq_chann
; idx
++) {
9379 /* Free the EQ corresponding to the IRQ vector */
9380 eq
= phba
->sli4_hba
.hba_eq_hdl
[idx
].eq
;
9381 lpfc_sli4_queue_free(eq
);
9382 phba
->sli4_hba
.hba_eq_hdl
[idx
].eq
= NULL
;
9387 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
9388 * @phba: pointer to lpfc hba data structure.
9390 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
9395 * -ENOMEM - No available memory
9396 * -EIO - The mailbox failed to complete successfully.
9399 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
9402 * Set FREE_INIT before beginning to free the queues.
9403 * Wait until the users of queues to acknowledge to
9404 * release queues by clearing FREE_WAIT.
9406 spin_lock_irq(&phba
->hbalock
);
9407 phba
->sli
.sli_flag
|= LPFC_QUEUE_FREE_INIT
;
9408 while (phba
->sli
.sli_flag
& LPFC_QUEUE_FREE_WAIT
) {
9409 spin_unlock_irq(&phba
->hbalock
);
9411 spin_lock_irq(&phba
->hbalock
);
9413 spin_unlock_irq(&phba
->hbalock
);
9415 lpfc_sli4_cleanup_poll_list(phba
);
9417 /* Release HBA eqs */
9418 if (phba
->sli4_hba
.hdwq
)
9419 lpfc_sli4_release_hdwq(phba
);
9421 if (phba
->nvmet_support
) {
9422 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_cqset
,
9423 phba
->cfg_nvmet_mrq
);
9425 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_mrq_hdr
,
9426 phba
->cfg_nvmet_mrq
);
9427 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_mrq_data
,
9428 phba
->cfg_nvmet_mrq
);
9431 /* Release mailbox command work queue */
9432 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_wq
);
9434 /* Release ELS work queue */
9435 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_wq
);
9437 /* Release ELS work queue */
9438 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_wq
);
9440 /* Release unsolicited receive queue */
9441 __lpfc_sli4_release_queue(&phba
->sli4_hba
.hdr_rq
);
9442 __lpfc_sli4_release_queue(&phba
->sli4_hba
.dat_rq
);
9444 /* Release ELS complete queue */
9445 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_cq
);
9447 /* Release NVME LS complete queue */
9448 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_cq
);
9450 /* Release mailbox command complete queue */
9451 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_cq
);
9453 /* Everything on this list has been freed */
9454 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
9456 /* Done with freeing the queues */
9457 spin_lock_irq(&phba
->hbalock
);
9458 phba
->sli
.sli_flag
&= ~LPFC_QUEUE_FREE_INIT
;
9459 spin_unlock_irq(&phba
->hbalock
);
9463 lpfc_free_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
)
9465 struct lpfc_rqb
*rqbp
;
9466 struct lpfc_dmabuf
*h_buf
;
9467 struct rqb_dmabuf
*rqb_buffer
;
9470 while (!list_empty(&rqbp
->rqb_buffer_list
)) {
9471 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
9472 struct lpfc_dmabuf
, list
);
9474 rqb_buffer
= container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
9475 (rqbp
->rqb_free_buffer
)(phba
, rqb_buffer
);
9476 rqbp
->buffer_count
--;
9482 lpfc_create_wq_cq(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
,
9483 struct lpfc_queue
*cq
, struct lpfc_queue
*wq
, uint16_t *cq_map
,
9484 int qidx
, uint32_t qtype
)
9486 struct lpfc_sli_ring
*pring
;
9489 if (!eq
|| !cq
|| !wq
) {
9490 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9491 "6085 Fast-path %s (%d) not allocated\n",
9492 ((eq
) ? ((cq
) ? "WQ" : "CQ") : "EQ"), qidx
);
9496 /* create the Cq first */
9497 rc
= lpfc_cq_create(phba
, cq
, eq
,
9498 (qtype
== LPFC_MBOX
) ? LPFC_MCQ
: LPFC_WCQ
, qtype
);
9500 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9501 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
9502 qidx
, (uint32_t)rc
);
9506 if (qtype
!= LPFC_MBOX
) {
9507 /* Setup cq_map for fast lookup */
9509 *cq_map
= cq
->queue_id
;
9511 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9512 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
9513 qidx
, cq
->queue_id
, qidx
, eq
->queue_id
);
9516 rc
= lpfc_wq_create(phba
, wq
, cq
, qtype
);
9518 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9519 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
9520 qidx
, (uint32_t)rc
);
9521 /* no need to tear down cq - caller will do so */
9525 /* Bind this CQ/WQ to the NVME ring */
9527 pring
->sli
.sli4
.wqp
= (void *)wq
;
9530 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9531 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
9532 qidx
, wq
->queue_id
, wq
->assoc_qid
, qidx
, cq
->queue_id
);
9534 rc
= lpfc_mq_create(phba
, wq
, cq
, LPFC_MBOX
);
9536 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9537 "0539 Failed setup of slow-path MQ: "
9539 /* no need to tear down cq - caller will do so */
9543 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9544 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
9545 phba
->sli4_hba
.mbx_wq
->queue_id
,
9546 phba
->sli4_hba
.mbx_cq
->queue_id
);
9553 * lpfc_setup_cq_lookup - Setup the CQ lookup table
9554 * @phba: pointer to lpfc hba data structure.
9556 * This routine will populate the cq_lookup table by all
9557 * available CQ queue_id's.
9560 lpfc_setup_cq_lookup(struct lpfc_hba
*phba
)
9562 struct lpfc_queue
*eq
, *childq
;
9565 memset(phba
->sli4_hba
.cq_lookup
, 0,
9566 (sizeof(struct lpfc_queue
*) * (phba
->sli4_hba
.cq_max
+ 1)));
9567 /* Loop thru all IRQ vectors */
9568 for (qidx
= 0; qidx
< phba
->cfg_irq_chann
; qidx
++) {
9569 /* Get the EQ corresponding to the IRQ vector */
9570 eq
= phba
->sli4_hba
.hba_eq_hdl
[qidx
].eq
;
9573 /* Loop through all CQs associated with that EQ */
9574 list_for_each_entry(childq
, &eq
->child_list
, list
) {
9575 if (childq
->queue_id
> phba
->sli4_hba
.cq_max
)
9577 if (childq
->subtype
== LPFC_IO
)
9578 phba
->sli4_hba
.cq_lookup
[childq
->queue_id
] =
9585 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
9586 * @phba: pointer to lpfc hba data structure.
9588 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
9593 * -ENOMEM - No available memory
9594 * -EIO - The mailbox failed to complete successfully.
9597 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
9599 uint32_t shdr_status
, shdr_add_status
;
9600 union lpfc_sli4_cfg_shdr
*shdr
;
9601 struct lpfc_vector_map_info
*cpup
;
9602 struct lpfc_sli4_hdw_queue
*qp
;
9603 LPFC_MBOXQ_t
*mboxq
;
9605 uint32_t length
, usdelay
;
9608 /* Check for dual-ULP support */
9609 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9611 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9612 "3249 Unable to allocate memory for "
9613 "QUERY_FW_CFG mailbox command\n");
9616 length
= (sizeof(struct lpfc_mbx_query_fw_config
) -
9617 sizeof(struct lpfc_sli4_cfg_mhdr
));
9618 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9619 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
9620 length
, LPFC_SLI4_MBX_EMBED
);
9622 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9624 shdr
= (union lpfc_sli4_cfg_shdr
*)
9625 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
9626 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9627 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
9628 if (shdr_status
|| shdr_add_status
|| rc
) {
9629 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9630 "3250 QUERY_FW_CFG mailbox failed with status "
9631 "x%x add_status x%x, mbx status x%x\n",
9632 shdr_status
, shdr_add_status
, rc
);
9633 if (rc
!= MBX_TIMEOUT
)
9634 mempool_free(mboxq
, phba
->mbox_mem_pool
);
9639 phba
->sli4_hba
.fw_func_mode
=
9640 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.function_mode
;
9641 phba
->sli4_hba
.ulp0_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp0_mode
;
9642 phba
->sli4_hba
.ulp1_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp1_mode
;
9643 phba
->sli4_hba
.physical_port
=
9644 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.physical_port
;
9645 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9646 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9647 "ulp1_mode:x%x\n", phba
->sli4_hba
.fw_func_mode
,
9648 phba
->sli4_hba
.ulp0_mode
, phba
->sli4_hba
.ulp1_mode
);
9650 if (rc
!= MBX_TIMEOUT
)
9651 mempool_free(mboxq
, phba
->mbox_mem_pool
);
9654 * Set up HBA Event Queues (EQs)
9656 qp
= phba
->sli4_hba
.hdwq
;
9658 /* Set up HBA event queue */
9660 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9661 "3147 Fast-path EQs not allocated\n");
9666 /* Loop thru all IRQ vectors */
9667 for (qidx
= 0; qidx
< phba
->cfg_irq_chann
; qidx
++) {
9668 /* Create HBA Event Queues (EQs) in order */
9669 for_each_present_cpu(cpu
) {
9670 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
9672 /* Look for the CPU thats using that vector with
9673 * LPFC_CPU_FIRST_IRQ set.
9675 if (!(cpup
->flag
& LPFC_CPU_FIRST_IRQ
))
9677 if (qidx
!= cpup
->eq
)
9680 /* Create an EQ for that vector */
9681 rc
= lpfc_eq_create(phba
, qp
[cpup
->hdwq
].hba_eq
,
9682 phba
->cfg_fcp_imax
);
9684 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9685 "0523 Failed setup of fast-path"
9686 " EQ (%d), rc = 0x%x\n",
9687 cpup
->eq
, (uint32_t)rc
);
9691 /* Save the EQ for that vector in the hba_eq_hdl */
9692 phba
->sli4_hba
.hba_eq_hdl
[cpup
->eq
].eq
=
9693 qp
[cpup
->hdwq
].hba_eq
;
9695 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9696 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9698 qp
[cpup
->hdwq
].hba_eq
->queue_id
);
9702 /* Loop thru all Hardware Queues */
9703 for (qidx
= 0; qidx
< phba
->cfg_hdw_queue
; qidx
++) {
9704 cpu
= lpfc_find_cpu_handle(phba
, qidx
, LPFC_FIND_BY_HDWQ
);
9705 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
9707 /* Create the CQ/WQ corresponding to the Hardware Queue */
9708 rc
= lpfc_create_wq_cq(phba
,
9709 phba
->sli4_hba
.hdwq
[cpup
->hdwq
].hba_eq
,
9712 &phba
->sli4_hba
.hdwq
[qidx
].io_cq_map
,
9716 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9717 "0535 Failed to setup fastpath "
9718 "IO WQ/CQ (%d), rc = 0x%x\n",
9719 qidx
, (uint32_t)rc
);
9725 * Set up Slow Path Complete Queues (CQs)
9728 /* Set up slow-path MBOX CQ/MQ */
9730 if (!phba
->sli4_hba
.mbx_cq
|| !phba
->sli4_hba
.mbx_wq
) {
9731 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9732 "0528 %s not allocated\n",
9733 phba
->sli4_hba
.mbx_cq
?
9734 "Mailbox WQ" : "Mailbox CQ");
9739 rc
= lpfc_create_wq_cq(phba
, qp
[0].hba_eq
,
9740 phba
->sli4_hba
.mbx_cq
,
9741 phba
->sli4_hba
.mbx_wq
,
9742 NULL
, 0, LPFC_MBOX
);
9744 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9745 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9749 if (phba
->nvmet_support
) {
9750 if (!phba
->sli4_hba
.nvmet_cqset
) {
9751 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9752 "3165 Fast-path NVME CQ Set "
9753 "array not allocated\n");
9757 if (phba
->cfg_nvmet_mrq
> 1) {
9758 rc
= lpfc_cq_create_set(phba
,
9759 phba
->sli4_hba
.nvmet_cqset
,
9761 LPFC_WCQ
, LPFC_NVMET
);
9763 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9764 "3164 Failed setup of NVME CQ "
9770 /* Set up NVMET Receive Complete Queue */
9771 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.nvmet_cqset
[0],
9773 LPFC_WCQ
, LPFC_NVMET
);
9775 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9776 "6089 Failed setup NVMET CQ: "
9777 "rc = 0x%x\n", (uint32_t)rc
);
9780 phba
->sli4_hba
.nvmet_cqset
[0]->chann
= 0;
9782 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9783 "6090 NVMET CQ setup: cq-id=%d, "
9784 "parent eq-id=%d\n",
9785 phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
,
9786 qp
[0].hba_eq
->queue_id
);
9790 /* Set up slow-path ELS WQ/CQ */
9791 if (!phba
->sli4_hba
.els_cq
|| !phba
->sli4_hba
.els_wq
) {
9792 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9793 "0530 ELS %s not allocated\n",
9794 phba
->sli4_hba
.els_cq
? "WQ" : "CQ");
9798 rc
= lpfc_create_wq_cq(phba
, qp
[0].hba_eq
,
9799 phba
->sli4_hba
.els_cq
,
9800 phba
->sli4_hba
.els_wq
,
9803 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9804 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9808 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9809 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9810 phba
->sli4_hba
.els_wq
->queue_id
,
9811 phba
->sli4_hba
.els_cq
->queue_id
);
9813 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
9814 /* Set up NVME LS Complete Queue */
9815 if (!phba
->sli4_hba
.nvmels_cq
|| !phba
->sli4_hba
.nvmels_wq
) {
9816 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9817 "6091 LS %s not allocated\n",
9818 phba
->sli4_hba
.nvmels_cq
? "WQ" : "CQ");
9822 rc
= lpfc_create_wq_cq(phba
, qp
[0].hba_eq
,
9823 phba
->sli4_hba
.nvmels_cq
,
9824 phba
->sli4_hba
.nvmels_wq
,
9825 NULL
, 0, LPFC_NVME_LS
);
9827 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9828 "0526 Failed setup of NVVME LS WQ/CQ: "
9829 "rc = 0x%x\n", (uint32_t)rc
);
9833 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9834 "6096 ELS WQ setup: wq-id=%d, "
9835 "parent cq-id=%d\n",
9836 phba
->sli4_hba
.nvmels_wq
->queue_id
,
9837 phba
->sli4_hba
.nvmels_cq
->queue_id
);
9841 * Create NVMET Receive Queue (RQ)
9843 if (phba
->nvmet_support
) {
9844 if ((!phba
->sli4_hba
.nvmet_cqset
) ||
9845 (!phba
->sli4_hba
.nvmet_mrq_hdr
) ||
9846 (!phba
->sli4_hba
.nvmet_mrq_data
)) {
9847 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9848 "6130 MRQ CQ Queues not "
9853 if (phba
->cfg_nvmet_mrq
> 1) {
9854 rc
= lpfc_mrq_create(phba
,
9855 phba
->sli4_hba
.nvmet_mrq_hdr
,
9856 phba
->sli4_hba
.nvmet_mrq_data
,
9857 phba
->sli4_hba
.nvmet_cqset
,
9860 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9861 "6098 Failed setup of NVMET "
9868 rc
= lpfc_rq_create(phba
,
9869 phba
->sli4_hba
.nvmet_mrq_hdr
[0],
9870 phba
->sli4_hba
.nvmet_mrq_data
[0],
9871 phba
->sli4_hba
.nvmet_cqset
[0],
9874 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9875 "6057 Failed setup of NVMET "
9876 "Receive Queue: rc = 0x%x\n",
9882 phba
, KERN_INFO
, LOG_INIT
,
9883 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9884 "dat-rq-id=%d parent cq-id=%d\n",
9885 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
,
9886 phba
->sli4_hba
.nvmet_mrq_data
[0]->queue_id
,
9887 phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
);
9892 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
9893 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9894 "0540 Receive Queue not allocated\n");
9899 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
9900 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
9902 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9903 "0541 Failed setup of Receive Queue: "
9904 "rc = 0x%x\n", (uint32_t)rc
);
9908 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9909 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9910 "parent cq-id=%d\n",
9911 phba
->sli4_hba
.hdr_rq
->queue_id
,
9912 phba
->sli4_hba
.dat_rq
->queue_id
,
9913 phba
->sli4_hba
.els_cq
->queue_id
);
9915 if (phba
->cfg_fcp_imax
)
9916 usdelay
= LPFC_SEC_TO_USEC
/ phba
->cfg_fcp_imax
;
9920 for (qidx
= 0; qidx
< phba
->cfg_irq_chann
;
9921 qidx
+= LPFC_MAX_EQ_DELAY_EQID_CNT
)
9922 lpfc_modify_hba_eq_delay(phba
, qidx
, LPFC_MAX_EQ_DELAY_EQID_CNT
,
9925 if (phba
->sli4_hba
.cq_max
) {
9926 kfree(phba
->sli4_hba
.cq_lookup
);
9927 phba
->sli4_hba
.cq_lookup
= kcalloc((phba
->sli4_hba
.cq_max
+ 1),
9928 sizeof(struct lpfc_queue
*), GFP_KERNEL
);
9929 if (!phba
->sli4_hba
.cq_lookup
) {
9930 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
9931 "0549 Failed setup of CQ Lookup table: "
9932 "size 0x%x\n", phba
->sli4_hba
.cq_max
);
9936 lpfc_setup_cq_lookup(phba
);
9941 lpfc_sli4_queue_unset(phba
);
9947 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9948 * @phba: pointer to lpfc hba data structure.
9950 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9955 * -ENOMEM - No available memory
9956 * -EIO - The mailbox failed to complete successfully.
9959 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
9961 struct lpfc_sli4_hdw_queue
*qp
;
9962 struct lpfc_queue
*eq
;
9965 /* Unset mailbox command work queue */
9966 if (phba
->sli4_hba
.mbx_wq
)
9967 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
9969 /* Unset NVME LS work queue */
9970 if (phba
->sli4_hba
.nvmels_wq
)
9971 lpfc_wq_destroy(phba
, phba
->sli4_hba
.nvmels_wq
);
9973 /* Unset ELS work queue */
9974 if (phba
->sli4_hba
.els_wq
)
9975 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
9977 /* Unset unsolicited receive queue */
9978 if (phba
->sli4_hba
.hdr_rq
)
9979 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
,
9980 phba
->sli4_hba
.dat_rq
);
9982 /* Unset mailbox command complete queue */
9983 if (phba
->sli4_hba
.mbx_cq
)
9984 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
9986 /* Unset ELS complete queue */
9987 if (phba
->sli4_hba
.els_cq
)
9988 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
9990 /* Unset NVME LS complete queue */
9991 if (phba
->sli4_hba
.nvmels_cq
)
9992 lpfc_cq_destroy(phba
, phba
->sli4_hba
.nvmels_cq
);
9994 if (phba
->nvmet_support
) {
9995 /* Unset NVMET MRQ queue */
9996 if (phba
->sli4_hba
.nvmet_mrq_hdr
) {
9997 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++)
10000 phba
->sli4_hba
.nvmet_mrq_hdr
[qidx
],
10001 phba
->sli4_hba
.nvmet_mrq_data
[qidx
]);
10004 /* Unset NVMET CQ Set complete queue */
10005 if (phba
->sli4_hba
.nvmet_cqset
) {
10006 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++)
10008 phba
, phba
->sli4_hba
.nvmet_cqset
[qidx
]);
10012 /* Unset fast-path SLI4 queues */
10013 if (phba
->sli4_hba
.hdwq
) {
10014 /* Loop thru all Hardware Queues */
10015 for (qidx
= 0; qidx
< phba
->cfg_hdw_queue
; qidx
++) {
10016 /* Destroy the CQ/WQ corresponding to Hardware Queue */
10017 qp
= &phba
->sli4_hba
.hdwq
[qidx
];
10018 lpfc_wq_destroy(phba
, qp
->io_wq
);
10019 lpfc_cq_destroy(phba
, qp
->io_cq
);
10021 /* Loop thru all IRQ vectors */
10022 for (qidx
= 0; qidx
< phba
->cfg_irq_chann
; qidx
++) {
10023 /* Destroy the EQ corresponding to the IRQ vector */
10024 eq
= phba
->sli4_hba
.hba_eq_hdl
[qidx
].eq
;
10025 lpfc_eq_destroy(phba
, eq
);
10029 kfree(phba
->sli4_hba
.cq_lookup
);
10030 phba
->sli4_hba
.cq_lookup
= NULL
;
10031 phba
->sli4_hba
.cq_max
= 0;
10035 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
10036 * @phba: pointer to lpfc hba data structure.
10038 * This routine is invoked to allocate and set up a pool of completion queue
10039 * events. The body of the completion queue event is a completion queue entry
10040 * CQE. For now, this pool is used for the interrupt service routine to queue
10041 * the following HBA completion queue events for the worker thread to process:
10042 * - Mailbox asynchronous events
10043 * - Receive queue completion unsolicited events
10044 * Later, this can be used for all the slow-path events.
10048 * -ENOMEM - No available memory
10051 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
10053 struct lpfc_cq_event
*cq_event
;
10056 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
10057 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
10059 goto out_pool_create_fail
;
10060 list_add_tail(&cq_event
->list
,
10061 &phba
->sli4_hba
.sp_cqe_event_pool
);
10065 out_pool_create_fail
:
10066 lpfc_sli4_cq_event_pool_destroy(phba
);
10071 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
10072 * @phba: pointer to lpfc hba data structure.
10074 * This routine is invoked to free the pool of completion queue events at
10075 * driver unload time. Note that, it is the responsibility of the driver
10076 * cleanup routine to free all the outstanding completion-queue events
10077 * allocated from this pool back into the pool before invoking this routine
10078 * to destroy the pool.
10081 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
10083 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
10085 list_for_each_entry_safe(cq_event
, next_cq_event
,
10086 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
10087 list_del(&cq_event
->list
);
10093 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10094 * @phba: pointer to lpfc hba data structure.
10096 * This routine is the lock free version of the API invoked to allocate a
10097 * completion-queue event from the free pool.
10099 * Return: Pointer to the newly allocated completion-queue event if successful
10102 struct lpfc_cq_event
*
10103 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
10105 struct lpfc_cq_event
*cq_event
= NULL
;
10107 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
10108 struct lpfc_cq_event
, list
);
10113 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10114 * @phba: pointer to lpfc hba data structure.
10116 * This routine is the lock version of the API invoked to allocate a
10117 * completion-queue event from the free pool.
10119 * Return: Pointer to the newly allocated completion-queue event if successful
10122 struct lpfc_cq_event
*
10123 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
10125 struct lpfc_cq_event
*cq_event
;
10126 unsigned long iflags
;
10128 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10129 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
10130 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10135 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10136 * @phba: pointer to lpfc hba data structure.
10137 * @cq_event: pointer to the completion queue event to be freed.
10139 * This routine is the lock free version of the API invoked to release a
10140 * completion-queue event back into the free pool.
10143 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
10144 struct lpfc_cq_event
*cq_event
)
10146 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
10150 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10151 * @phba: pointer to lpfc hba data structure.
10152 * @cq_event: pointer to the completion queue event to be freed.
10154 * This routine is the lock version of the API invoked to release a
10155 * completion-queue event back into the free pool.
10158 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
10159 struct lpfc_cq_event
*cq_event
)
10161 unsigned long iflags
;
10162 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10163 __lpfc_sli4_cq_event_release(phba
, cq_event
);
10164 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10168 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
10169 * @phba: pointer to lpfc hba data structure.
10171 * This routine is to free all the pending completion-queue events to the
10172 * back into the free pool for device reset.
10175 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
10177 LIST_HEAD(cqelist
);
10178 struct lpfc_cq_event
*cqe
;
10179 unsigned long iflags
;
10181 /* Retrieve all the pending WCQEs from pending WCQE lists */
10182 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10183 /* Pending FCP XRI abort events */
10184 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10186 /* Pending ELS XRI abort events */
10187 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10189 /* Pending asynnc events */
10190 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
10192 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10194 while (!list_empty(&cqelist
)) {
10195 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
10196 lpfc_sli4_cq_event_release(phba
, cqe
);
10201 * lpfc_pci_function_reset - Reset pci function.
10202 * @phba: pointer to lpfc hba data structure.
10204 * This routine is invoked to request a PCI function reset. It will destroys
10205 * all resources assigned to the PCI function which originates this request.
10209 * -ENOMEM - No available memory
10210 * -EIO - The mailbox failed to complete successfully.
10213 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
10215 LPFC_MBOXQ_t
*mboxq
;
10216 uint32_t rc
= 0, if_type
;
10217 uint32_t shdr_status
, shdr_add_status
;
10219 uint32_t port_reset
= 0;
10220 union lpfc_sli4_cfg_shdr
*shdr
;
10221 struct lpfc_register reg_data
;
10224 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10226 case LPFC_SLI_INTF_IF_TYPE_0
:
10227 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
10230 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10231 "0494 Unable to allocate memory for "
10232 "issuing SLI_FUNCTION_RESET mailbox "
10237 /* Setup PCI function reset mailbox-ioctl command */
10238 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10239 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
10240 LPFC_SLI4_MBX_EMBED
);
10241 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
10242 shdr
= (union lpfc_sli4_cfg_shdr
*)
10243 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
10244 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
10245 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
10247 if (rc
!= MBX_TIMEOUT
)
10248 mempool_free(mboxq
, phba
->mbox_mem_pool
);
10249 if (shdr_status
|| shdr_add_status
|| rc
) {
10250 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10251 "0495 SLI_FUNCTION_RESET mailbox "
10252 "failed with status x%x add_status x%x,"
10253 " mbx status x%x\n",
10254 shdr_status
, shdr_add_status
, rc
);
10258 case LPFC_SLI_INTF_IF_TYPE_2
:
10259 case LPFC_SLI_INTF_IF_TYPE_6
:
10262 * Poll the Port Status Register and wait for RDY for
10263 * up to 30 seconds. If the port doesn't respond, treat
10266 for (rdy_chk
= 0; rdy_chk
< 1500; rdy_chk
++) {
10267 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
10268 STATUSregaddr
, ®_data
.word0
)) {
10272 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
10277 if (!bf_get(lpfc_sliport_status_rdy
, ®_data
)) {
10278 phba
->work_status
[0] = readl(
10279 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10280 phba
->work_status
[1] = readl(
10281 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10282 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10283 "2890 Port not ready, port status reg "
10284 "0x%x error 1=0x%x, error 2=0x%x\n",
10286 phba
->work_status
[0],
10287 phba
->work_status
[1]);
10294 * Reset the port now
10296 reg_data
.word0
= 0;
10297 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
10298 LPFC_SLIPORT_LITTLE_ENDIAN
);
10299 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
10300 LPFC_SLIPORT_INIT_PORT
);
10301 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
10304 pci_read_config_word(phba
->pcidev
,
10305 PCI_DEVICE_ID
, &devid
);
10310 } else if (bf_get(lpfc_sliport_status_rn
, ®_data
)) {
10316 case LPFC_SLI_INTF_IF_TYPE_1
:
10322 /* Catch the not-ready port failure after a port reset. */
10324 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10325 "3317 HBA not functional: IP Reset Failed "
10326 "try: echo fw_reset > board_mode\n");
10334 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
10335 * @phba: pointer to lpfc hba data structure.
10337 * This routine is invoked to set up the PCI device memory space for device
10338 * with SLI-4 interface spec.
10342 * other values - error
10345 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
10347 struct pci_dev
*pdev
= phba
->pcidev
;
10348 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
10355 /* Set the device DMA mask size */
10356 error
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
10358 error
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
10363 * The BARs and register set definitions and offset locations are
10364 * dependent on the if_type.
10366 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
10367 &phba
->sli4_hba
.sli_intf
.word0
)) {
10371 /* There is no SLI3 failback for SLI4 devices. */
10372 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
10373 LPFC_SLI_INTF_VALID
) {
10374 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10375 "2894 SLI_INTF reg contents invalid "
10376 "sli_intf reg 0x%x\n",
10377 phba
->sli4_hba
.sli_intf
.word0
);
10381 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10383 * Get the bus address of SLI4 device Bar regions and the
10384 * number of bytes required by each mapping. The mapping of the
10385 * particular PCI BARs regions is dependent on the type of
10388 if (pci_resource_start(pdev
, PCI_64BIT_BAR0
)) {
10389 phba
->pci_bar0_map
= pci_resource_start(pdev
, PCI_64BIT_BAR0
);
10390 bar0map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR0
);
10393 * Map SLI4 PCI Config Space Register base to a kernel virtual
10396 phba
->sli4_hba
.conf_regs_memmap_p
=
10397 ioremap(phba
->pci_bar0_map
, bar0map_len
);
10398 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
10399 dev_printk(KERN_ERR
, &pdev
->dev
,
10400 "ioremap failed for SLI4 PCI config "
10404 phba
->pci_bar0_memmap_p
= phba
->sli4_hba
.conf_regs_memmap_p
;
10405 /* Set up BAR0 PCI config space register memory map */
10406 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
10408 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
10409 bar0map_len
= pci_resource_len(pdev
, 1);
10410 if (if_type
>= LPFC_SLI_INTF_IF_TYPE_2
) {
10411 dev_printk(KERN_ERR
, &pdev
->dev
,
10412 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
10415 phba
->sli4_hba
.conf_regs_memmap_p
=
10416 ioremap(phba
->pci_bar0_map
, bar0map_len
);
10417 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
10418 dev_printk(KERN_ERR
, &pdev
->dev
,
10419 "ioremap failed for SLI4 PCI config "
10423 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
10426 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
) {
10427 if (pci_resource_start(pdev
, PCI_64BIT_BAR2
)) {
10429 * Map SLI4 if type 0 HBA Control Register base to a
10430 * kernel virtual address and setup the registers.
10432 phba
->pci_bar1_map
= pci_resource_start(pdev
,
10434 bar1map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR2
);
10435 phba
->sli4_hba
.ctrl_regs_memmap_p
=
10436 ioremap(phba
->pci_bar1_map
,
10438 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
10439 dev_err(&pdev
->dev
,
10440 "ioremap failed for SLI4 HBA "
10441 "control registers.\n");
10443 goto out_iounmap_conf
;
10445 phba
->pci_bar2_memmap_p
=
10446 phba
->sli4_hba
.ctrl_regs_memmap_p
;
10447 lpfc_sli4_bar1_register_memmap(phba
, if_type
);
10450 goto out_iounmap_conf
;
10454 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_6
) &&
10455 (pci_resource_start(pdev
, PCI_64BIT_BAR2
))) {
10457 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
10458 * virtual address and setup the registers.
10460 phba
->pci_bar1_map
= pci_resource_start(pdev
, PCI_64BIT_BAR2
);
10461 bar1map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR2
);
10462 phba
->sli4_hba
.drbl_regs_memmap_p
=
10463 ioremap(phba
->pci_bar1_map
, bar1map_len
);
10464 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
10465 dev_err(&pdev
->dev
,
10466 "ioremap failed for SLI4 HBA doorbell registers.\n");
10468 goto out_iounmap_conf
;
10470 phba
->pci_bar2_memmap_p
= phba
->sli4_hba
.drbl_regs_memmap_p
;
10471 lpfc_sli4_bar1_register_memmap(phba
, if_type
);
10474 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
) {
10475 if (pci_resource_start(pdev
, PCI_64BIT_BAR4
)) {
10477 * Map SLI4 if type 0 HBA Doorbell Register base to
10478 * a kernel virtual address and setup the registers.
10480 phba
->pci_bar2_map
= pci_resource_start(pdev
,
10482 bar2map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR4
);
10483 phba
->sli4_hba
.drbl_regs_memmap_p
=
10484 ioremap(phba
->pci_bar2_map
,
10486 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
10487 dev_err(&pdev
->dev
,
10488 "ioremap failed for SLI4 HBA"
10489 " doorbell registers.\n");
10491 goto out_iounmap_ctrl
;
10493 phba
->pci_bar4_memmap_p
=
10494 phba
->sli4_hba
.drbl_regs_memmap_p
;
10495 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
10497 goto out_iounmap_all
;
10500 goto out_iounmap_all
;
10504 if (if_type
== LPFC_SLI_INTF_IF_TYPE_6
&&
10505 pci_resource_start(pdev
, PCI_64BIT_BAR4
)) {
10507 * Map SLI4 if type 6 HBA DPP Register base to a kernel
10508 * virtual address and setup the registers.
10510 phba
->pci_bar2_map
= pci_resource_start(pdev
, PCI_64BIT_BAR4
);
10511 bar2map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR4
);
10512 phba
->sli4_hba
.dpp_regs_memmap_p
=
10513 ioremap(phba
->pci_bar2_map
, bar2map_len
);
10514 if (!phba
->sli4_hba
.dpp_regs_memmap_p
) {
10515 dev_err(&pdev
->dev
,
10516 "ioremap failed for SLI4 HBA dpp registers.\n");
10518 goto out_iounmap_ctrl
;
10520 phba
->pci_bar4_memmap_p
= phba
->sli4_hba
.dpp_regs_memmap_p
;
10523 /* Set up the EQ/CQ register handeling functions now */
10525 case LPFC_SLI_INTF_IF_TYPE_0
:
10526 case LPFC_SLI_INTF_IF_TYPE_2
:
10527 phba
->sli4_hba
.sli4_eq_clr_intr
= lpfc_sli4_eq_clr_intr
;
10528 phba
->sli4_hba
.sli4_write_eq_db
= lpfc_sli4_write_eq_db
;
10529 phba
->sli4_hba
.sli4_write_cq_db
= lpfc_sli4_write_cq_db
;
10531 case LPFC_SLI_INTF_IF_TYPE_6
:
10532 phba
->sli4_hba
.sli4_eq_clr_intr
= lpfc_sli4_if6_eq_clr_intr
;
10533 phba
->sli4_hba
.sli4_write_eq_db
= lpfc_sli4_if6_write_eq_db
;
10534 phba
->sli4_hba
.sli4_write_cq_db
= lpfc_sli4_if6_write_cq_db
;
10543 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
10545 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
10547 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
10553 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
10554 * @phba: pointer to lpfc hba data structure.
10556 * This routine is invoked to unset the PCI device memory space for device
10557 * with SLI-4 interface spec.
10560 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
10563 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10566 case LPFC_SLI_INTF_IF_TYPE_0
:
10567 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
10568 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
10569 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
10571 case LPFC_SLI_INTF_IF_TYPE_2
:
10572 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
10574 case LPFC_SLI_INTF_IF_TYPE_6
:
10575 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
10576 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
10577 if (phba
->sli4_hba
.dpp_regs_memmap_p
)
10578 iounmap(phba
->sli4_hba
.dpp_regs_memmap_p
);
10580 case LPFC_SLI_INTF_IF_TYPE_1
:
10582 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
10583 "FATAL - unsupported SLI4 interface type - %d\n",
10590 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
10591 * @phba: pointer to lpfc hba data structure.
10593 * This routine is invoked to enable the MSI-X interrupt vectors to device
10594 * with SLI-3 interface specs.
10598 * other values - error
10601 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
10606 /* Set up MSI-X multi-message vectors */
10607 rc
= pci_alloc_irq_vectors(phba
->pcidev
,
10608 LPFC_MSIX_VECTORS
, LPFC_MSIX_VECTORS
, PCI_IRQ_MSIX
);
10610 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10611 "0420 PCI enable MSI-X failed (%d)\n", rc
);
10616 * Assign MSI-X vectors to interrupt handlers
10619 /* vector-0 is associated to slow-path handler */
10620 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 0),
10621 &lpfc_sli_sp_intr_handler
, 0,
10622 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
10624 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10625 "0421 MSI-X slow-path request_irq failed "
10630 /* vector-1 is associated to fast-path handler */
10631 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 1),
10632 &lpfc_sli_fp_intr_handler
, 0,
10633 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
10636 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10637 "0429 MSI-X fast-path request_irq failed "
10643 * Configure HBA MSI-X attention conditions to messages
10645 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10649 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
10650 "0474 Unable to allocate memory for issuing "
10651 "MBOX_CONFIG_MSI command\n");
10654 rc
= lpfc_config_msi(phba
, pmb
);
10657 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
10658 if (rc
!= MBX_SUCCESS
) {
10659 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
10660 "0351 Config MSI mailbox command failed, "
10661 "mbxCmd x%x, mbxStatus x%x\n",
10662 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
10666 /* Free memory allocated for mailbox command */
10667 mempool_free(pmb
, phba
->mbox_mem_pool
);
10671 /* Free memory allocated for mailbox command */
10672 mempool_free(pmb
, phba
->mbox_mem_pool
);
10675 /* free the irq already requested */
10676 free_irq(pci_irq_vector(phba
->pcidev
, 1), phba
);
10679 /* free the irq already requested */
10680 free_irq(pci_irq_vector(phba
->pcidev
, 0), phba
);
10683 /* Unconfigure MSI-X capability structure */
10684 pci_free_irq_vectors(phba
->pcidev
);
10691 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10692 * @phba: pointer to lpfc hba data structure.
10694 * This routine is invoked to enable the MSI interrupt mode to device with
10695 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10696 * enable the MSI vector. The device driver is responsible for calling the
10697 * request_irq() to register MSI vector with a interrupt the handler, which
10698 * is done in this function.
10702 * other values - error
10705 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
10709 rc
= pci_enable_msi(phba
->pcidev
);
10711 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10712 "0462 PCI enable MSI mode success.\n");
10714 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10715 "0471 PCI enable MSI mode failed (%d)\n", rc
);
10719 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
10720 0, LPFC_DRIVER_NAME
, phba
);
10722 pci_disable_msi(phba
->pcidev
);
10723 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
10724 "0478 MSI request_irq failed (%d)\n", rc
);
10730 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10731 * @phba: pointer to lpfc hba data structure.
10732 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
10734 * This routine is invoked to enable device interrupt and associate driver's
10735 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10736 * spec. Depends on the interrupt mode configured to the driver, the driver
10737 * will try to fallback from the configured interrupt mode to an interrupt
10738 * mode which is supported by the platform, kernel, and device in the order
10740 * MSI-X -> MSI -> IRQ.
10744 * other values - error
10747 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
10749 uint32_t intr_mode
= LPFC_INTR_ERROR
;
10752 if (cfg_mode
== 2) {
10753 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10754 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
10756 /* Now, try to enable MSI-X interrupt mode */
10757 retval
= lpfc_sli_enable_msix(phba
);
10759 /* Indicate initialization to MSI-X mode */
10760 phba
->intr_type
= MSIX
;
10766 /* Fallback to MSI if MSI-X initialization failed */
10767 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
10768 retval
= lpfc_sli_enable_msi(phba
);
10770 /* Indicate initialization to MSI mode */
10771 phba
->intr_type
= MSI
;
10776 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10777 if (phba
->intr_type
== NONE
) {
10778 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
10779 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
10781 /* Indicate initialization to INTx mode */
10782 phba
->intr_type
= INTx
;
10790 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10791 * @phba: pointer to lpfc hba data structure.
10793 * This routine is invoked to disable device interrupt and disassociate the
10794 * driver's interrupt handler(s) from interrupt vector(s) to device with
10795 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10796 * release the interrupt vector(s) for the message signaled interrupt.
10799 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
10803 if (phba
->intr_type
== MSIX
)
10804 nr_irqs
= LPFC_MSIX_VECTORS
;
10808 for (i
= 0; i
< nr_irqs
; i
++)
10809 free_irq(pci_irq_vector(phba
->pcidev
, i
), phba
);
10810 pci_free_irq_vectors(phba
->pcidev
);
10812 /* Reset interrupt management states */
10813 phba
->intr_type
= NONE
;
10814 phba
->sli
.slistat
.sli_intr
= 0;
10818 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
10819 * @phba: pointer to lpfc hba data structure.
10820 * @id: EQ vector index or Hardware Queue index
10821 * @match: LPFC_FIND_BY_EQ = match by EQ
10822 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
10823 * Return the CPU that matches the selection criteria
10826 lpfc_find_cpu_handle(struct lpfc_hba
*phba
, uint16_t id
, int match
)
10828 struct lpfc_vector_map_info
*cpup
;
10831 /* Loop through all CPUs */
10832 for_each_present_cpu(cpu
) {
10833 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
10835 /* If we are matching by EQ, there may be multiple CPUs using
10836 * using the same vector, so select the one with
10837 * LPFC_CPU_FIRST_IRQ set.
10839 if ((match
== LPFC_FIND_BY_EQ
) &&
10840 (cpup
->flag
& LPFC_CPU_FIRST_IRQ
) &&
10844 /* If matching by HDWQ, select the first CPU that matches */
10845 if ((match
== LPFC_FIND_BY_HDWQ
) && (cpup
->hdwq
== id
))
10853 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
10854 * @phba: pointer to lpfc hba data structure.
10855 * @cpu: CPU map index
10856 * @phys_id: CPU package physical id
10857 * @core_id: CPU core id
10860 lpfc_find_hyper(struct lpfc_hba
*phba
, int cpu
,
10861 uint16_t phys_id
, uint16_t core_id
)
10863 struct lpfc_vector_map_info
*cpup
;
10866 for_each_present_cpu(idx
) {
10867 cpup
= &phba
->sli4_hba
.cpu_map
[idx
];
10868 /* Does the cpup match the one we are looking for */
10869 if ((cpup
->phys_id
== phys_id
) &&
10870 (cpup
->core_id
== core_id
) &&
10879 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
10880 * @phba: pointer to lpfc hba data structure.
10881 * @eqidx: index for eq and irq vector
10882 * @flag: flags to set for vector_map structure
10883 * @cpu: cpu used to index vector_map structure
10885 * The routine assigns eq info into vector_map structure
10888 lpfc_assign_eq_map_info(struct lpfc_hba
*phba
, uint16_t eqidx
, uint16_t flag
,
10891 struct lpfc_vector_map_info
*cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
10892 struct lpfc_hba_eq_hdl
*eqhdl
= lpfc_get_eq_hdl(eqidx
);
10895 cpup
->flag
|= flag
;
10897 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10898 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
10899 cpu
, eqhdl
->irq
, cpup
->eq
, cpup
->flag
);
10903 * lpfc_cpu_map_array_init - Initialize cpu_map structure
10904 * @phba: pointer to lpfc hba data structure.
10906 * The routine initializes the cpu_map array structure
10909 lpfc_cpu_map_array_init(struct lpfc_hba
*phba
)
10911 struct lpfc_vector_map_info
*cpup
;
10912 struct lpfc_eq_intr_info
*eqi
;
10915 for_each_possible_cpu(cpu
) {
10916 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
10917 cpup
->phys_id
= LPFC_VECTOR_MAP_EMPTY
;
10918 cpup
->core_id
= LPFC_VECTOR_MAP_EMPTY
;
10919 cpup
->hdwq
= LPFC_VECTOR_MAP_EMPTY
;
10920 cpup
->eq
= LPFC_VECTOR_MAP_EMPTY
;
10922 eqi
= per_cpu_ptr(phba
->sli4_hba
.eq_info
, cpu
);
10923 INIT_LIST_HEAD(&eqi
->list
);
10929 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
10930 * @phba: pointer to lpfc hba data structure.
10932 * The routine initializes the hba_eq_hdl array structure
10935 lpfc_hba_eq_hdl_array_init(struct lpfc_hba
*phba
)
10937 struct lpfc_hba_eq_hdl
*eqhdl
;
10940 for (i
= 0; i
< phba
->cfg_irq_chann
; i
++) {
10941 eqhdl
= lpfc_get_eq_hdl(i
);
10942 eqhdl
->irq
= LPFC_VECTOR_MAP_EMPTY
;
10943 eqhdl
->phba
= phba
;
10948 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
10949 * @phba: pointer to lpfc hba data structure.
10950 * @vectors: number of msix vectors allocated.
10952 * The routine will figure out the CPU affinity assignment for every
10953 * MSI-X vector allocated for the HBA.
10954 * In addition, the CPU to IO channel mapping will be calculated
10955 * and the phba->sli4_hba.cpu_map array will reflect this.
10958 lpfc_cpu_affinity_check(struct lpfc_hba
*phba
, int vectors
)
10960 int i
, cpu
, idx
, next_idx
, new_cpu
, start_cpu
, first_cpu
;
10961 int max_phys_id
, min_phys_id
;
10962 int max_core_id
, min_core_id
;
10963 struct lpfc_vector_map_info
*cpup
;
10964 struct lpfc_vector_map_info
*new_cpup
;
10966 struct cpuinfo_x86
*cpuinfo
;
10968 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
10969 struct lpfc_hdwq_stat
*c_stat
;
10973 min_phys_id
= LPFC_VECTOR_MAP_EMPTY
;
10975 min_core_id
= LPFC_VECTOR_MAP_EMPTY
;
10977 /* Update CPU map with physical id and core id of each CPU */
10978 for_each_present_cpu(cpu
) {
10979 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
10981 cpuinfo
= &cpu_data(cpu
);
10982 cpup
->phys_id
= cpuinfo
->phys_proc_id
;
10983 cpup
->core_id
= cpuinfo
->cpu_core_id
;
10984 if (lpfc_find_hyper(phba
, cpu
, cpup
->phys_id
, cpup
->core_id
))
10985 cpup
->flag
|= LPFC_CPU_MAP_HYPER
;
10987 /* No distinction between CPUs for other platforms */
10989 cpup
->core_id
= cpu
;
10992 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10993 "3328 CPU %d physid %d coreid %d flag x%x\n",
10994 cpu
, cpup
->phys_id
, cpup
->core_id
, cpup
->flag
);
10996 if (cpup
->phys_id
> max_phys_id
)
10997 max_phys_id
= cpup
->phys_id
;
10998 if (cpup
->phys_id
< min_phys_id
)
10999 min_phys_id
= cpup
->phys_id
;
11001 if (cpup
->core_id
> max_core_id
)
11002 max_core_id
= cpup
->core_id
;
11003 if (cpup
->core_id
< min_core_id
)
11004 min_core_id
= cpup
->core_id
;
11007 /* After looking at each irq vector assigned to this pcidev, its
11008 * possible to see that not ALL CPUs have been accounted for.
11009 * Next we will set any unassigned (unaffinitized) cpu map
11010 * entries to a IRQ on the same phys_id.
11012 first_cpu
= cpumask_first(cpu_present_mask
);
11013 start_cpu
= first_cpu
;
11015 for_each_present_cpu(cpu
) {
11016 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11018 /* Is this CPU entry unassigned */
11019 if (cpup
->eq
== LPFC_VECTOR_MAP_EMPTY
) {
11020 /* Mark CPU as IRQ not assigned by the kernel */
11021 cpup
->flag
|= LPFC_CPU_MAP_UNASSIGN
;
11023 /* If so, find a new_cpup thats on the the SAME
11024 * phys_id as cpup. start_cpu will start where we
11025 * left off so all unassigned entries don't get assgined
11026 * the IRQ of the first entry.
11028 new_cpu
= start_cpu
;
11029 for (i
= 0; i
< phba
->sli4_hba
.num_present_cpu
; i
++) {
11030 new_cpup
= &phba
->sli4_hba
.cpu_map
[new_cpu
];
11031 if (!(new_cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
) &&
11032 (new_cpup
->eq
!= LPFC_VECTOR_MAP_EMPTY
) &&
11033 (new_cpup
->phys_id
== cpup
->phys_id
))
11035 new_cpu
= cpumask_next(
11036 new_cpu
, cpu_present_mask
);
11037 if (new_cpu
== nr_cpumask_bits
)
11038 new_cpu
= first_cpu
;
11040 /* At this point, we leave the CPU as unassigned */
11043 /* We found a matching phys_id, so copy the IRQ info */
11044 cpup
->eq
= new_cpup
->eq
;
11046 /* Bump start_cpu to the next slot to minmize the
11047 * chance of having multiple unassigned CPU entries
11048 * selecting the same IRQ.
11050 start_cpu
= cpumask_next(new_cpu
, cpu_present_mask
);
11051 if (start_cpu
== nr_cpumask_bits
)
11052 start_cpu
= first_cpu
;
11054 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11055 "3337 Set Affinity: CPU %d "
11056 "eq %d from peer cpu %d same "
11058 cpu
, cpup
->eq
, new_cpu
,
11063 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
11064 start_cpu
= first_cpu
;
11066 for_each_present_cpu(cpu
) {
11067 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11069 /* Is this entry unassigned */
11070 if (cpup
->eq
== LPFC_VECTOR_MAP_EMPTY
) {
11071 /* Mark it as IRQ not assigned by the kernel */
11072 cpup
->flag
|= LPFC_CPU_MAP_UNASSIGN
;
11074 /* If so, find a new_cpup thats on ANY phys_id
11075 * as the cpup. start_cpu will start where we
11076 * left off so all unassigned entries don't get
11077 * assigned the IRQ of the first entry.
11079 new_cpu
= start_cpu
;
11080 for (i
= 0; i
< phba
->sli4_hba
.num_present_cpu
; i
++) {
11081 new_cpup
= &phba
->sli4_hba
.cpu_map
[new_cpu
];
11082 if (!(new_cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
) &&
11083 (new_cpup
->eq
!= LPFC_VECTOR_MAP_EMPTY
))
11085 new_cpu
= cpumask_next(
11086 new_cpu
, cpu_present_mask
);
11087 if (new_cpu
== nr_cpumask_bits
)
11088 new_cpu
= first_cpu
;
11090 /* We should never leave an entry unassigned */
11091 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11092 "3339 Set Affinity: CPU %d "
11093 "eq %d UNASSIGNED\n",
11094 cpup
->hdwq
, cpup
->eq
);
11097 /* We found an available entry, copy the IRQ info */
11098 cpup
->eq
= new_cpup
->eq
;
11100 /* Bump start_cpu to the next slot to minmize the
11101 * chance of having multiple unassigned CPU entries
11102 * selecting the same IRQ.
11104 start_cpu
= cpumask_next(new_cpu
, cpu_present_mask
);
11105 if (start_cpu
== nr_cpumask_bits
)
11106 start_cpu
= first_cpu
;
11108 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11109 "3338 Set Affinity: CPU %d "
11110 "eq %d from peer cpu %d (%d/%d)\n",
11111 cpu
, cpup
->eq
, new_cpu
,
11112 new_cpup
->phys_id
, new_cpup
->core_id
);
11116 /* Assign hdwq indices that are unique across all cpus in the map
11117 * that are also FIRST_CPUs.
11120 for_each_present_cpu(cpu
) {
11121 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11123 /* Only FIRST IRQs get a hdwq index assignment. */
11124 if (!(cpup
->flag
& LPFC_CPU_FIRST_IRQ
))
11127 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
11130 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11131 "3333 Set Affinity: CPU %d (phys %d core %d): "
11132 "hdwq %d eq %d flg x%x\n",
11133 cpu
, cpup
->phys_id
, cpup
->core_id
,
11134 cpup
->hdwq
, cpup
->eq
, cpup
->flag
);
11136 /* Associate a hdwq with each cpu_map entry
11137 * This will be 1 to 1 - hdwq to cpu, unless there are less
11138 * hardware queues then CPUs. For that case we will just round-robin
11139 * the available hardware queues as they get assigned to CPUs.
11140 * The next_idx is the idx from the FIRST_CPU loop above to account
11141 * for irq_chann < hdwq. The idx is used for round-robin assignments
11142 * and needs to start at 0.
11147 for_each_present_cpu(cpu
) {
11148 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11150 /* FIRST cpus are already mapped. */
11151 if (cpup
->flag
& LPFC_CPU_FIRST_IRQ
)
11154 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
11155 * of the unassigned cpus to the next idx so that all
11156 * hdw queues are fully utilized.
11158 if (next_idx
< phba
->cfg_hdw_queue
) {
11159 cpup
->hdwq
= next_idx
;
11164 /* Not a First CPU and all hdw_queues are used. Reuse a
11165 * Hardware Queue for another CPU, so be smart about it
11166 * and pick one that has its IRQ/EQ mapped to the same phys_id
11167 * (CPU package) and core_id.
11169 new_cpu
= start_cpu
;
11170 for (i
= 0; i
< phba
->sli4_hba
.num_present_cpu
; i
++) {
11171 new_cpup
= &phba
->sli4_hba
.cpu_map
[new_cpu
];
11172 if (new_cpup
->hdwq
!= LPFC_VECTOR_MAP_EMPTY
&&
11173 new_cpup
->phys_id
== cpup
->phys_id
&&
11174 new_cpup
->core_id
== cpup
->core_id
) {
11177 new_cpu
= cpumask_next(new_cpu
, cpu_present_mask
);
11178 if (new_cpu
== nr_cpumask_bits
)
11179 new_cpu
= first_cpu
;
11182 /* If we can't match both phys_id and core_id,
11183 * settle for just a phys_id match.
11185 new_cpu
= start_cpu
;
11186 for (i
= 0; i
< phba
->sli4_hba
.num_present_cpu
; i
++) {
11187 new_cpup
= &phba
->sli4_hba
.cpu_map
[new_cpu
];
11188 if (new_cpup
->hdwq
!= LPFC_VECTOR_MAP_EMPTY
&&
11189 new_cpup
->phys_id
== cpup
->phys_id
)
11192 new_cpu
= cpumask_next(new_cpu
, cpu_present_mask
);
11193 if (new_cpu
== nr_cpumask_bits
)
11194 new_cpu
= first_cpu
;
11197 /* Otherwise just round robin on cfg_hdw_queue */
11198 cpup
->hdwq
= idx
% phba
->cfg_hdw_queue
;
11202 /* We found an available entry, copy the IRQ info */
11203 start_cpu
= cpumask_next(new_cpu
, cpu_present_mask
);
11204 if (start_cpu
== nr_cpumask_bits
)
11205 start_cpu
= first_cpu
;
11206 cpup
->hdwq
= new_cpup
->hdwq
;
11208 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11209 "3335 Set Affinity: CPU %d (phys %d core %d): "
11210 "hdwq %d eq %d flg x%x\n",
11211 cpu
, cpup
->phys_id
, cpup
->core_id
,
11212 cpup
->hdwq
, cpup
->eq
, cpup
->flag
);
11216 * Initialize the cpu_map slots for not-present cpus in case
11217 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
11220 for_each_possible_cpu(cpu
) {
11221 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11222 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11223 c_stat
= per_cpu_ptr(phba
->sli4_hba
.c_stat
, cpu
);
11224 c_stat
->hdwq_no
= cpup
->hdwq
;
11226 if (cpup
->hdwq
!= LPFC_VECTOR_MAP_EMPTY
)
11229 cpup
->hdwq
= idx
++ % phba
->cfg_hdw_queue
;
11230 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11231 c_stat
->hdwq_no
= cpup
->hdwq
;
11233 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11234 "3340 Set Affinity: not present "
11235 "CPU %d hdwq %d\n",
11239 /* The cpu_map array will be used later during initialization
11240 * when EQ / CQ / WQs are allocated and configured.
11246 * lpfc_cpuhp_get_eq
11248 * @phba: pointer to lpfc hba data structure.
11249 * @cpu: cpu going offline
11250 * @eqlist: eq list to append to
11253 lpfc_cpuhp_get_eq(struct lpfc_hba
*phba
, unsigned int cpu
,
11254 struct list_head
*eqlist
)
11256 const struct cpumask
*maskp
;
11257 struct lpfc_queue
*eq
;
11258 struct cpumask
*tmp
;
11261 tmp
= kzalloc(cpumask_size(), GFP_KERNEL
);
11265 for (idx
= 0; idx
< phba
->cfg_irq_chann
; idx
++) {
11266 maskp
= pci_irq_get_affinity(phba
->pcidev
, idx
);
11270 * if irq is not affinitized to the cpu going
11271 * then we don't need to poll the eq attached
11274 if (!cpumask_and(tmp
, maskp
, cpumask_of(cpu
)))
11276 /* get the cpus that are online and are affini-
11277 * tized to this irq vector. If the count is
11278 * more than 1 then cpuhp is not going to shut-
11279 * down this vector. Since this cpu has not
11280 * gone offline yet, we need >1.
11282 cpumask_and(tmp
, maskp
, cpu_online_mask
);
11283 if (cpumask_weight(tmp
) > 1)
11286 /* Now that we have an irq to shutdown, get the eq
11287 * mapped to this irq. Note: multiple hdwq's in
11288 * the software can share an eq, but eventually
11289 * only eq will be mapped to this vector
11291 eq
= phba
->sli4_hba
.hba_eq_hdl
[idx
].eq
;
11292 list_add(&eq
->_poll_list
, eqlist
);
11298 static void __lpfc_cpuhp_remove(struct lpfc_hba
*phba
)
11300 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
11303 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state
,
11306 * unregistering the instance doesn't stop the polling
11307 * timer. Wait for the poll timer to retire.
11310 del_timer_sync(&phba
->cpuhp_poll_timer
);
11313 static void lpfc_cpuhp_remove(struct lpfc_hba
*phba
)
11315 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
11318 __lpfc_cpuhp_remove(phba
);
11321 static void lpfc_cpuhp_add(struct lpfc_hba
*phba
)
11323 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
11328 if (!list_empty(&phba
->poll_list
))
11329 mod_timer(&phba
->cpuhp_poll_timer
,
11330 jiffies
+ msecs_to_jiffies(LPFC_POLL_HB
));
11334 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state
,
11338 static int __lpfc_cpuhp_checks(struct lpfc_hba
*phba
, int *retval
)
11340 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
11345 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
11350 /* proceed with the hotplug */
11355 * lpfc_irq_set_aff - set IRQ affinity
11356 * @eqhdl: EQ handle
11357 * @cpu: cpu to set affinity
11361 lpfc_irq_set_aff(struct lpfc_hba_eq_hdl
*eqhdl
, unsigned int cpu
)
11363 cpumask_clear(&eqhdl
->aff_mask
);
11364 cpumask_set_cpu(cpu
, &eqhdl
->aff_mask
);
11365 irq_set_status_flags(eqhdl
->irq
, IRQ_NO_BALANCING
);
11366 irq_set_affinity_hint(eqhdl
->irq
, &eqhdl
->aff_mask
);
11370 * lpfc_irq_clear_aff - clear IRQ affinity
11371 * @eqhdl: EQ handle
11375 lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl
*eqhdl
)
11377 cpumask_clear(&eqhdl
->aff_mask
);
11378 irq_clear_status_flags(eqhdl
->irq
, IRQ_NO_BALANCING
);
11379 irq_set_affinity_hint(eqhdl
->irq
, &eqhdl
->aff_mask
);
11383 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
11384 * @phba: pointer to HBA context object.
11385 * @cpu: cpu going offline/online
11386 * @offline: true, cpu is going offline. false, cpu is coming online.
11388 * If cpu is going offline, we'll try our best effort to find the next
11389 * online cpu on the phba's original_mask and migrate all offlining IRQ
11392 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
11394 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
11395 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
11399 lpfc_irq_rebalance(struct lpfc_hba
*phba
, unsigned int cpu
, bool offline
)
11401 struct lpfc_vector_map_info
*cpup
;
11402 struct cpumask
*aff_mask
;
11403 unsigned int cpu_select
, cpu_next
, idx
;
11404 const struct cpumask
*orig_mask
;
11406 if (phba
->irq_chann_mode
== NORMAL_MODE
)
11409 orig_mask
= &phba
->sli4_hba
.irq_aff_mask
;
11411 if (!cpumask_test_cpu(cpu
, orig_mask
))
11414 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11416 if (!(cpup
->flag
& LPFC_CPU_FIRST_IRQ
))
11420 /* Find next online CPU on original mask */
11421 cpu_next
= cpumask_next_wrap(cpu
, orig_mask
, cpu
, true);
11422 cpu_select
= lpfc_next_online_cpu(orig_mask
, cpu_next
);
11424 /* Found a valid CPU */
11425 if ((cpu_select
< nr_cpu_ids
) && (cpu_select
!= cpu
)) {
11426 /* Go through each eqhdl and ensure offlining
11427 * cpu aff_mask is migrated
11429 for (idx
= 0; idx
< phba
->cfg_irq_chann
; idx
++) {
11430 aff_mask
= lpfc_get_aff_mask(idx
);
11432 /* Migrate affinity */
11433 if (cpumask_test_cpu(cpu
, aff_mask
))
11434 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx
),
11438 /* Rely on irqbalance if no online CPUs left on NUMA */
11439 for (idx
= 0; idx
< phba
->cfg_irq_chann
; idx
++)
11440 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx
));
11443 /* Migrate affinity back to this CPU */
11444 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup
->eq
), cpu
);
11448 static int lpfc_cpu_offline(unsigned int cpu
, struct hlist_node
*node
)
11450 struct lpfc_hba
*phba
= hlist_entry_safe(node
, struct lpfc_hba
, cpuhp
);
11451 struct lpfc_queue
*eq
, *next
;
11456 WARN_ONCE(!phba
, "cpu: %u. phba:NULL", raw_smp_processor_id());
11460 if (__lpfc_cpuhp_checks(phba
, &retval
))
11463 lpfc_irq_rebalance(phba
, cpu
, true);
11465 retval
= lpfc_cpuhp_get_eq(phba
, cpu
, &eqlist
);
11469 /* start polling on these eq's */
11470 list_for_each_entry_safe(eq
, next
, &eqlist
, _poll_list
) {
11471 list_del_init(&eq
->_poll_list
);
11472 lpfc_sli4_start_polling(eq
);
11478 static int lpfc_cpu_online(unsigned int cpu
, struct hlist_node
*node
)
11480 struct lpfc_hba
*phba
= hlist_entry_safe(node
, struct lpfc_hba
, cpuhp
);
11481 struct lpfc_queue
*eq
, *next
;
11486 WARN_ONCE(!phba
, "cpu: %u. phba:NULL", raw_smp_processor_id());
11490 if (__lpfc_cpuhp_checks(phba
, &retval
))
11493 lpfc_irq_rebalance(phba
, cpu
, false);
11495 list_for_each_entry_safe(eq
, next
, &phba
->poll_list
, _poll_list
) {
11496 n
= lpfc_find_cpu_handle(phba
, eq
->hdwq
, LPFC_FIND_BY_HDWQ
);
11498 lpfc_sli4_stop_polling(eq
);
11505 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
11506 * @phba: pointer to lpfc hba data structure.
11508 * This routine is invoked to enable the MSI-X interrupt vectors to device
11509 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
11510 * to cpus on the system.
11512 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
11513 * the number of cpus on the same numa node as this adapter. The vectors are
11514 * allocated without requesting OS affinity mapping. A vector will be
11515 * allocated and assigned to each online and offline cpu. If the cpu is
11516 * online, then affinity will be set to that cpu. If the cpu is offline, then
11517 * affinity will be set to the nearest peer cpu within the numa node that is
11518 * online. If there are no online cpus within the numa node, affinity is not
11519 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
11520 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
11523 * If numa mode is not enabled and there is more than 1 vector allocated, then
11524 * the driver relies on the managed irq interface where the OS assigns vector to
11525 * cpu affinity. The driver will then use that affinity mapping to setup its
11526 * cpu mapping table.
11530 * other values - error
11533 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
11535 int vectors
, rc
, index
;
11537 const struct cpumask
*aff_mask
= NULL
;
11538 unsigned int cpu
= 0, cpu_cnt
= 0, cpu_select
= nr_cpu_ids
;
11539 struct lpfc_vector_map_info
*cpup
;
11540 struct lpfc_hba_eq_hdl
*eqhdl
;
11541 const struct cpumask
*maskp
;
11542 unsigned int flags
= PCI_IRQ_MSIX
;
11544 /* Set up MSI-X multi-message vectors */
11545 vectors
= phba
->cfg_irq_chann
;
11547 if (phba
->irq_chann_mode
!= NORMAL_MODE
)
11548 aff_mask
= &phba
->sli4_hba
.irq_aff_mask
;
11551 cpu_cnt
= cpumask_weight(aff_mask
);
11552 vectors
= min(phba
->cfg_irq_chann
, cpu_cnt
);
11554 /* cpu: iterates over aff_mask including offline or online
11555 * cpu_select: iterates over online aff_mask to set affinity
11557 cpu
= cpumask_first(aff_mask
);
11558 cpu_select
= lpfc_next_online_cpu(aff_mask
, cpu
);
11560 flags
|= PCI_IRQ_AFFINITY
;
11563 rc
= pci_alloc_irq_vectors(phba
->pcidev
, 1, vectors
, flags
);
11565 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11566 "0484 PCI enable MSI-X failed (%d)\n", rc
);
11571 /* Assign MSI-X vectors to interrupt handlers */
11572 for (index
= 0; index
< vectors
; index
++) {
11573 eqhdl
= lpfc_get_eq_hdl(index
);
11574 name
= eqhdl
->handler_name
;
11575 memset(name
, 0, LPFC_SLI4_HANDLER_NAME_SZ
);
11576 snprintf(name
, LPFC_SLI4_HANDLER_NAME_SZ
,
11577 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
11579 eqhdl
->idx
= index
;
11580 rc
= request_irq(pci_irq_vector(phba
->pcidev
, index
),
11581 &lpfc_sli4_hba_intr_handler
, 0,
11584 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
11585 "0486 MSI-X fast-path (%d) "
11586 "request_irq failed (%d)\n", index
, rc
);
11590 eqhdl
->irq
= pci_irq_vector(phba
->pcidev
, index
);
11593 /* If found a neighboring online cpu, set affinity */
11594 if (cpu_select
< nr_cpu_ids
)
11595 lpfc_irq_set_aff(eqhdl
, cpu_select
);
11597 /* Assign EQ to cpu_map */
11598 lpfc_assign_eq_map_info(phba
, index
,
11599 LPFC_CPU_FIRST_IRQ
,
11602 /* Iterate to next offline or online cpu in aff_mask */
11603 cpu
= cpumask_next(cpu
, aff_mask
);
11605 /* Find next online cpu in aff_mask to set affinity */
11606 cpu_select
= lpfc_next_online_cpu(aff_mask
, cpu
);
11607 } else if (vectors
== 1) {
11608 cpu
= cpumask_first(cpu_present_mask
);
11609 lpfc_assign_eq_map_info(phba
, index
, LPFC_CPU_FIRST_IRQ
,
11612 maskp
= pci_irq_get_affinity(phba
->pcidev
, index
);
11614 /* Loop through all CPUs associated with vector index */
11615 for_each_cpu_and(cpu
, maskp
, cpu_present_mask
) {
11616 cpup
= &phba
->sli4_hba
.cpu_map
[cpu
];
11618 /* If this is the first CPU thats assigned to
11619 * this vector, set LPFC_CPU_FIRST_IRQ.
11621 * With certain platforms its possible that irq
11622 * vectors are affinitized to all the cpu's.
11623 * This can result in each cpu_map.eq to be set
11624 * to the last vector, resulting in overwrite
11625 * of all the previous cpu_map.eq. Ensure that
11626 * each vector receives a place in cpu_map.
11627 * Later call to lpfc_cpu_affinity_check will
11628 * ensure we are nicely balanced out.
11630 if (cpup
->eq
!= LPFC_VECTOR_MAP_EMPTY
)
11632 lpfc_assign_eq_map_info(phba
, index
,
11633 LPFC_CPU_FIRST_IRQ
,
11640 if (vectors
!= phba
->cfg_irq_chann
) {
11641 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
11642 "3238 Reducing IO channels to match number of "
11643 "MSI-X vectors, requested %d got %d\n",
11644 phba
->cfg_irq_chann
, vectors
);
11645 if (phba
->cfg_irq_chann
> vectors
)
11646 phba
->cfg_irq_chann
= vectors
;
11652 /* free the irq already requested */
11653 for (--index
; index
>= 0; index
--) {
11654 eqhdl
= lpfc_get_eq_hdl(index
);
11655 lpfc_irq_clear_aff(eqhdl
);
11656 irq_set_affinity_hint(eqhdl
->irq
, NULL
);
11657 free_irq(eqhdl
->irq
, eqhdl
);
11660 /* Unconfigure MSI-X capability structure */
11661 pci_free_irq_vectors(phba
->pcidev
);
11668 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
11669 * @phba: pointer to lpfc hba data structure.
11671 * This routine is invoked to enable the MSI interrupt mode to device with
11672 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
11673 * called to enable the MSI vector. The device driver is responsible for
11674 * calling the request_irq() to register MSI vector with a interrupt the
11675 * handler, which is done in this function.
11679 * other values - error
11682 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
11686 struct lpfc_hba_eq_hdl
*eqhdl
;
11688 rc
= pci_alloc_irq_vectors(phba
->pcidev
, 1, 1,
11689 PCI_IRQ_MSI
| PCI_IRQ_AFFINITY
);
11691 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11692 "0487 PCI enable MSI mode success.\n");
11694 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11695 "0488 PCI enable MSI mode failed (%d)\n", rc
);
11696 return rc
? rc
: -1;
11699 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
11700 0, LPFC_DRIVER_NAME
, phba
);
11702 pci_free_irq_vectors(phba
->pcidev
);
11703 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
11704 "0490 MSI request_irq failed (%d)\n", rc
);
11708 eqhdl
= lpfc_get_eq_hdl(0);
11709 eqhdl
->irq
= pci_irq_vector(phba
->pcidev
, 0);
11711 cpu
= cpumask_first(cpu_present_mask
);
11712 lpfc_assign_eq_map_info(phba
, 0, LPFC_CPU_FIRST_IRQ
, cpu
);
11714 for (index
= 0; index
< phba
->cfg_irq_chann
; index
++) {
11715 eqhdl
= lpfc_get_eq_hdl(index
);
11716 eqhdl
->idx
= index
;
11723 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
11724 * @phba: pointer to lpfc hba data structure.
11725 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
11727 * This routine is invoked to enable device interrupt and associate driver's
11728 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
11729 * interface spec. Depends on the interrupt mode configured to the driver,
11730 * the driver will try to fallback from the configured interrupt mode to an
11731 * interrupt mode which is supported by the platform, kernel, and device in
11733 * MSI-X -> MSI -> IRQ.
11737 * other values - error
11740 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
11742 uint32_t intr_mode
= LPFC_INTR_ERROR
;
11745 if (cfg_mode
== 2) {
11746 /* Preparation before conf_msi mbox cmd */
11749 /* Now, try to enable MSI-X interrupt mode */
11750 retval
= lpfc_sli4_enable_msix(phba
);
11752 /* Indicate initialization to MSI-X mode */
11753 phba
->intr_type
= MSIX
;
11759 /* Fallback to MSI if MSI-X initialization failed */
11760 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
11761 retval
= lpfc_sli4_enable_msi(phba
);
11763 /* Indicate initialization to MSI mode */
11764 phba
->intr_type
= MSI
;
11769 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11770 if (phba
->intr_type
== NONE
) {
11771 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
11772 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
11774 struct lpfc_hba_eq_hdl
*eqhdl
;
11777 /* Indicate initialization to INTx mode */
11778 phba
->intr_type
= INTx
;
11781 eqhdl
= lpfc_get_eq_hdl(0);
11782 eqhdl
->irq
= pci_irq_vector(phba
->pcidev
, 0);
11784 cpu
= cpumask_first(cpu_present_mask
);
11785 lpfc_assign_eq_map_info(phba
, 0, LPFC_CPU_FIRST_IRQ
,
11787 for (idx
= 0; idx
< phba
->cfg_irq_chann
; idx
++) {
11788 eqhdl
= lpfc_get_eq_hdl(idx
);
11797 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
11798 * @phba: pointer to lpfc hba data structure.
11800 * This routine is invoked to disable device interrupt and disassociate
11801 * the driver's interrupt handler(s) from interrupt vector(s) to device
11802 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
11803 * will release the interrupt vector(s) for the message signaled interrupt.
11806 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
11808 /* Disable the currently initialized interrupt mode */
11809 if (phba
->intr_type
== MSIX
) {
11811 struct lpfc_hba_eq_hdl
*eqhdl
;
11813 /* Free up MSI-X multi-message vectors */
11814 for (index
= 0; index
< phba
->cfg_irq_chann
; index
++) {
11815 eqhdl
= lpfc_get_eq_hdl(index
);
11816 lpfc_irq_clear_aff(eqhdl
);
11817 irq_set_affinity_hint(eqhdl
->irq
, NULL
);
11818 free_irq(eqhdl
->irq
, eqhdl
);
11821 free_irq(phba
->pcidev
->irq
, phba
);
11824 pci_free_irq_vectors(phba
->pcidev
);
11826 /* Reset interrupt management states */
11827 phba
->intr_type
= NONE
;
11828 phba
->sli
.slistat
.sli_intr
= 0;
11832 * lpfc_unset_hba - Unset SLI3 hba device initialization
11833 * @phba: pointer to lpfc hba data structure.
11835 * This routine is invoked to unset the HBA device initialization steps to
11836 * a device with SLI-3 interface spec.
11839 lpfc_unset_hba(struct lpfc_hba
*phba
)
11841 struct lpfc_vport
*vport
= phba
->pport
;
11842 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
11844 spin_lock_irq(shost
->host_lock
);
11845 vport
->load_flag
|= FC_UNLOADING
;
11846 spin_unlock_irq(shost
->host_lock
);
11848 kfree(phba
->vpi_bmask
);
11849 kfree(phba
->vpi_ids
);
11851 lpfc_stop_hba_timers(phba
);
11853 phba
->pport
->work_port_events
= 0;
11855 lpfc_sli_hba_down(phba
);
11857 lpfc_sli_brdrestart(phba
);
11859 lpfc_sli_disable_intr(phba
);
11865 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
11866 * @phba: Pointer to HBA context object.
11868 * This function is called in the SLI4 code path to wait for completion
11869 * of device's XRIs exchange busy. It will check the XRI exchange busy
11870 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
11871 * that, it will check the XRI exchange busy on outstanding FCP and ELS
11872 * I/Os every 30 seconds, log error message, and wait forever. Only when
11873 * all XRI exchange busy complete, the driver unload shall proceed with
11874 * invoking the function reset ioctl mailbox command to the CNA and the
11875 * the rest of the driver unload resource release.
11878 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
11880 struct lpfc_sli4_hdw_queue
*qp
;
11883 int io_xri_cmpl
= 1;
11884 int nvmet_xri_cmpl
= 1;
11885 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
11887 /* Driver just aborted IOs during the hba_unset process. Pause
11888 * here to give the HBA time to complete the IO and get entries
11889 * into the abts lists.
11891 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
* 5);
11893 /* Wait for NVME pending IO to flush back to transport. */
11894 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
11895 lpfc_nvme_wait_for_io_drain(phba
);
11898 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
11899 qp
= &phba
->sli4_hba
.hdwq
[idx
];
11900 io_xri_cmpl
= list_empty(&qp
->lpfc_abts_io_buf_list
);
11901 if (!io_xri_cmpl
) /* if list is NOT empty */
11907 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
11909 list_empty(&phba
->sli4_hba
.lpfc_abts_nvmet_ctx_list
);
11912 while (!els_xri_cmpl
|| !io_xri_cmpl
|| !nvmet_xri_cmpl
) {
11913 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
11914 if (!nvmet_xri_cmpl
)
11915 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
11916 "6424 NVMET XRI exchange busy "
11917 "wait time: %d seconds.\n",
11920 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
11921 "6100 IO XRI exchange busy "
11922 "wait time: %d seconds.\n",
11925 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
11926 "2878 ELS XRI exchange busy "
11927 "wait time: %d seconds.\n",
11929 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
11930 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
11932 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
11933 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
11937 for (idx
= 0; idx
< phba
->cfg_hdw_queue
; idx
++) {
11938 qp
= &phba
->sli4_hba
.hdwq
[idx
];
11939 io_xri_cmpl
= list_empty(
11940 &qp
->lpfc_abts_io_buf_list
);
11941 if (!io_xri_cmpl
) /* if list is NOT empty */
11947 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
11948 nvmet_xri_cmpl
= list_empty(
11949 &phba
->sli4_hba
.lpfc_abts_nvmet_ctx_list
);
11952 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
11958 * lpfc_sli4_hba_unset - Unset the fcoe hba
11959 * @phba: Pointer to HBA context object.
11961 * This function is called in the SLI4 code path to reset the HBA's FCoE
11962 * function. The caller is not required to hold any lock. This routine
11963 * issues PCI function reset mailbox command to reset the FCoE function.
11964 * At the end of the function, it calls lpfc_hba_down_post function to
11965 * free any pending commands.
11968 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
11971 LPFC_MBOXQ_t
*mboxq
;
11972 struct pci_dev
*pdev
= phba
->pcidev
;
11974 lpfc_stop_hba_timers(phba
);
11976 phba
->sli4_hba
.intr_enable
= 0;
11979 * Gracefully wait out the potential current outstanding asynchronous
11983 /* First, block any pending async mailbox command from posted */
11984 spin_lock_irq(&phba
->hbalock
);
11985 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
11986 spin_unlock_irq(&phba
->hbalock
);
11987 /* Now, trying to wait it out if we can */
11988 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
11990 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
11993 /* Forcefully release the outstanding mailbox command if timed out */
11994 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
11995 spin_lock_irq(&phba
->hbalock
);
11996 mboxq
= phba
->sli
.mbox_active
;
11997 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
11998 __lpfc_mbox_cmpl_put(phba
, mboxq
);
11999 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
12000 phba
->sli
.mbox_active
= NULL
;
12001 spin_unlock_irq(&phba
->hbalock
);
12004 /* Abort all iocbs associated with the hba */
12005 lpfc_sli_hba_iocb_abort(phba
);
12007 /* Wait for completion of device XRI exchange busy */
12008 lpfc_sli4_xri_exchange_busy_wait(phba
);
12010 /* per-phba callback de-registration for hotplug event */
12012 lpfc_cpuhp_remove(phba
);
12014 /* Disable PCI subsystem interrupt */
12015 lpfc_sli4_disable_intr(phba
);
12017 /* Disable SR-IOV if enabled */
12018 if (phba
->cfg_sriov_nr_virtfn
)
12019 pci_disable_sriov(pdev
);
12021 /* Stop kthread signal shall trigger work_done one more time */
12022 kthread_stop(phba
->worker_thread
);
12024 /* Disable FW logging to host memory */
12025 lpfc_ras_stop_fwlog(phba
);
12027 /* Unset the queues shared with the hardware then release all
12028 * allocated resources.
12030 lpfc_sli4_queue_unset(phba
);
12031 lpfc_sli4_queue_destroy(phba
);
12033 /* Reset SLI4 HBA FCoE function */
12034 lpfc_pci_function_reset(phba
);
12036 /* Free RAS DMA memory */
12037 if (phba
->ras_fwlog
.ras_enabled
)
12038 lpfc_sli4_ras_dma_free(phba
);
12040 /* Stop the SLI4 device port */
12042 phba
->pport
->work_port_events
= 0;
12046 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
12047 * @phba: Pointer to HBA context object.
12048 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
12050 * This function is called in the SLI4 code path to read the port's
12051 * sli4 capabilities.
12053 * This function may be be called from any context that can block-wait
12054 * for the completion. The expectation is that this routine is called
12055 * typically from probe_one or from the online routine.
12058 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
12061 struct lpfc_mqe
*mqe
;
12062 struct lpfc_pc_sli4_params
*sli4_params
;
12066 mqe
= &mboxq
->u
.mqe
;
12068 /* Read the port's SLI4 Parameters port capabilities */
12069 lpfc_pc_sli4_params(mboxq
);
12070 if (!phba
->sli4_hba
.intr_enable
)
12071 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
12073 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
12074 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
12080 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
12081 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
12082 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
12083 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
12084 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
12085 &mqe
->un
.sli4_params
);
12086 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
12087 &mqe
->un
.sli4_params
);
12088 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
12089 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
12090 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
12091 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
12092 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
12093 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
12094 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
12095 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
12096 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
12097 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
12098 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
12099 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
12100 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
12101 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
12102 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
12103 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
12104 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
12105 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
12106 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
12107 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
12108 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
12110 /* Make sure that sge_supp_len can be handled by the driver */
12111 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
12112 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
12118 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
12119 * @phba: Pointer to HBA context object.
12120 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
12122 * This function is called in the SLI4 code path to read the port's
12123 * sli4 capabilities.
12125 * This function may be be called from any context that can block-wait
12126 * for the completion. The expectation is that this routine is called
12127 * typically from probe_one or from the online routine.
12130 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
12133 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
12134 struct lpfc_pc_sli4_params
*sli4_params
;
12137 bool exp_wqcq_pages
= true;
12138 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
12141 * By default, the driver assumes the SLI4 port requires RPI
12142 * header postings. The SLI4_PARAM response will correct this
12145 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
12147 /* Read the port's SLI4 Config Parameters */
12148 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
12149 sizeof(struct lpfc_sli4_cfg_mhdr
));
12150 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12151 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
12152 length
, LPFC_SLI4_MBX_EMBED
);
12153 if (!phba
->sli4_hba
.intr_enable
)
12154 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
12156 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
12157 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
12161 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
12162 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
12163 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
12164 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
12165 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
12166 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
12167 mbx_sli4_parameters
);
12168 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
12169 mbx_sli4_parameters
);
12170 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
12171 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
12173 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
12174 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
12175 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
12176 sli4_params
->oas_supported
= bf_get(cfg_oas
, mbx_sli4_parameters
);
12177 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
12178 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
12179 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
12180 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
12181 sli4_params
->eqav
= bf_get(cfg_eqav
, mbx_sli4_parameters
);
12182 sli4_params
->cqav
= bf_get(cfg_cqav
, mbx_sli4_parameters
);
12183 sli4_params
->wqsize
= bf_get(cfg_wqsize
, mbx_sli4_parameters
);
12184 sli4_params
->bv1s
= bf_get(cfg_bv1s
, mbx_sli4_parameters
);
12185 sli4_params
->pls
= bf_get(cfg_pvl
, mbx_sli4_parameters
);
12186 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
12187 mbx_sli4_parameters
);
12188 sli4_params
->wqpcnt
= bf_get(cfg_wqpcnt
, mbx_sli4_parameters
);
12189 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
12190 mbx_sli4_parameters
);
12191 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
12192 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
12194 /* Check for Extended Pre-Registered SGL support */
12195 phba
->cfg_xpsgl
= bf_get(cfg_xpsgl
, mbx_sli4_parameters
);
12197 /* Check for firmware nvme support */
12198 rc
= (bf_get(cfg_nvme
, mbx_sli4_parameters
) &&
12199 bf_get(cfg_xib
, mbx_sli4_parameters
));
12202 /* Save this to indicate the Firmware supports NVME */
12203 sli4_params
->nvme
= 1;
12205 /* Firmware NVME support, check driver FC4 NVME support */
12206 if (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
) {
12207 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_NVME
,
12208 "6133 Disabling NVME support: "
12209 "FC4 type not supported: x%x\n",
12210 phba
->cfg_enable_fc4_type
);
12214 /* No firmware NVME support, check driver FC4 NVME support */
12215 sli4_params
->nvme
= 0;
12216 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
12217 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_NVME
,
12218 "6101 Disabling NVME support: Not "
12219 "supported by firmware (%d %d) x%x\n",
12220 bf_get(cfg_nvme
, mbx_sli4_parameters
),
12221 bf_get(cfg_xib
, mbx_sli4_parameters
),
12222 phba
->cfg_enable_fc4_type
);
12224 phba
->nvme_support
= 0;
12225 phba
->nvmet_support
= 0;
12226 phba
->cfg_nvmet_mrq
= 0;
12227 phba
->cfg_nvme_seg_cnt
= 0;
12229 /* If no FC4 type support, move to just SCSI support */
12230 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
12232 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_FCP
;
12236 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
12237 * accommodate 512K and 1M IOs in a single nvme buf.
12239 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
12240 phba
->cfg_sg_seg_cnt
= LPFC_MAX_NVME_SEG_CNT
;
12242 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
12243 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
12244 LPFC_SLI_INTF_IF_TYPE_6
) || (!bf_get(cfg_xib
, mbx_sli4_parameters
)))
12245 phba
->cfg_enable_pbde
= 0;
12248 * To support Suppress Response feature we must satisfy 3 conditions.
12249 * lpfc_suppress_rsp module parameter must be set (default).
12250 * In SLI4-Parameters Descriptor:
12251 * Extended Inline Buffers (XIB) must be supported.
12252 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
12253 * (double negative).
12255 if (phba
->cfg_suppress_rsp
&& bf_get(cfg_xib
, mbx_sli4_parameters
) &&
12256 !(bf_get(cfg_nosr
, mbx_sli4_parameters
)))
12257 phba
->sli
.sli_flag
|= LPFC_SLI_SUPPRESS_RSP
;
12259 phba
->cfg_suppress_rsp
= 0;
12261 if (bf_get(cfg_eqdr
, mbx_sli4_parameters
))
12262 phba
->sli
.sli_flag
|= LPFC_SLI_USE_EQDR
;
12264 /* Make sure that sge_supp_len can be handled by the driver */
12265 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
12266 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
12269 * Check whether the adapter supports an embedded copy of the
12270 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
12271 * to use this option, 128-byte WQEs must be used.
12273 if (bf_get(cfg_ext_embed_cb
, mbx_sli4_parameters
))
12274 phba
->fcp_embed_io
= 1;
12276 phba
->fcp_embed_io
= 0;
12278 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_NVME
,
12279 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
12280 bf_get(cfg_xib
, mbx_sli4_parameters
),
12281 phba
->cfg_enable_pbde
,
12282 phba
->fcp_embed_io
, phba
->nvme_support
,
12283 phba
->cfg_nvme_embed_cmd
, phba
->cfg_suppress_rsp
);
12285 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
12286 LPFC_SLI_INTF_IF_TYPE_2
) &&
12287 (bf_get(lpfc_sli_intf_sli_family
, &phba
->sli4_hba
.sli_intf
) ==
12288 LPFC_SLI_INTF_FAMILY_LNCR_A0
))
12289 exp_wqcq_pages
= false;
12291 if ((bf_get(cfg_cqpsize
, mbx_sli4_parameters
) & LPFC_CQ_16K_PAGE_SZ
) &&
12292 (bf_get(cfg_wqpsize
, mbx_sli4_parameters
) & LPFC_WQ_16K_PAGE_SZ
) &&
12294 (sli4_params
->wqsize
& LPFC_WQ_SZ128_SUPPORT
))
12295 phba
->enab_exp_wqcq_pages
= 1;
12297 phba
->enab_exp_wqcq_pages
= 0;
12299 * Check if the SLI port supports MDS Diagnostics
12301 if (bf_get(cfg_mds_diags
, mbx_sli4_parameters
))
12302 phba
->mds_diags_support
= 1;
12304 phba
->mds_diags_support
= 0;
12307 * Check if the SLI port supports NSLER
12309 if (bf_get(cfg_nsler
, mbx_sli4_parameters
))
12318 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
12319 * @pdev: pointer to PCI device
12320 * @pid: pointer to PCI device identifier
12322 * This routine is to be called to attach a device with SLI-3 interface spec
12323 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12324 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12325 * information of the device and driver to see if the driver state that it can
12326 * support this kind of device. If the match is successful, the driver core
12327 * invokes this routine. If this routine determines it can claim the HBA, it
12328 * does all the initialization that it needs to do to handle the HBA properly.
12331 * 0 - driver can claim the device
12332 * negative value - driver can not claim the device
12335 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
12337 struct lpfc_hba
*phba
;
12338 struct lpfc_vport
*vport
= NULL
;
12339 struct Scsi_Host
*shost
= NULL
;
12341 uint32_t cfg_mode
, intr_mode
;
12343 /* Allocate memory for HBA structure */
12344 phba
= lpfc_hba_alloc(pdev
);
12348 /* Perform generic PCI device enabling operation */
12349 error
= lpfc_enable_pci_dev(phba
);
12351 goto out_free_phba
;
12353 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
12354 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
12356 goto out_disable_pci_dev
;
12358 /* Set up SLI-3 specific device PCI memory space */
12359 error
= lpfc_sli_pci_mem_setup(phba
);
12361 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12362 "1402 Failed to set up pci memory space.\n");
12363 goto out_disable_pci_dev
;
12366 /* Set up SLI-3 specific device driver resources */
12367 error
= lpfc_sli_driver_resource_setup(phba
);
12369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12370 "1404 Failed to set up driver resource.\n");
12371 goto out_unset_pci_mem_s3
;
12374 /* Initialize and populate the iocb list per host */
12376 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
12378 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12379 "1405 Failed to initialize iocb list.\n");
12380 goto out_unset_driver_resource_s3
;
12383 /* Set up common device driver resources */
12384 error
= lpfc_setup_driver_resource_phase2(phba
);
12386 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12387 "1406 Failed to set up driver resource.\n");
12388 goto out_free_iocb_list
;
12391 /* Get the default values for Model Name and Description */
12392 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
12394 /* Create SCSI host to the physical port */
12395 error
= lpfc_create_shost(phba
);
12397 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12398 "1407 Failed to create scsi host.\n");
12399 goto out_unset_driver_resource
;
12402 /* Configure sysfs attributes */
12403 vport
= phba
->pport
;
12404 error
= lpfc_alloc_sysfs_attr(vport
);
12406 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12407 "1476 Failed to allocate sysfs attr\n");
12408 goto out_destroy_shost
;
12411 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
12412 /* Now, trying to enable interrupt and bring up the device */
12413 cfg_mode
= phba
->cfg_use_msi
;
12415 /* Put device to a known state before enabling interrupt */
12416 lpfc_stop_port(phba
);
12417 /* Configure and enable interrupt */
12418 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
12419 if (intr_mode
== LPFC_INTR_ERROR
) {
12420 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12421 "0431 Failed to enable interrupt.\n");
12423 goto out_free_sysfs_attr
;
12425 /* SLI-3 HBA setup */
12426 if (lpfc_sli_hba_setup(phba
)) {
12427 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12428 "1477 Failed to set up hba\n");
12430 goto out_remove_device
;
12433 /* Wait 50ms for the interrupts of previous mailbox commands */
12435 /* Check active interrupts on message signaled interrupts */
12436 if (intr_mode
== 0 ||
12437 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
12438 /* Log the current active interrupt mode */
12439 phba
->intr_mode
= intr_mode
;
12440 lpfc_log_intr_mode(phba
, intr_mode
);
12443 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12444 "0447 Configure interrupt mode (%d) "
12445 "failed active interrupt test.\n",
12447 /* Disable the current interrupt mode */
12448 lpfc_sli_disable_intr(phba
);
12449 /* Try next level of interrupt mode */
12450 cfg_mode
= --intr_mode
;
12454 /* Perform post initialization setup */
12455 lpfc_post_init_setup(phba
);
12457 /* Check if there are static vports to be created. */
12458 lpfc_create_static_vport(phba
);
12463 lpfc_unset_hba(phba
);
12464 out_free_sysfs_attr
:
12465 lpfc_free_sysfs_attr(vport
);
12467 lpfc_destroy_shost(phba
);
12468 out_unset_driver_resource
:
12469 lpfc_unset_driver_resource_phase2(phba
);
12470 out_free_iocb_list
:
12471 lpfc_free_iocb_list(phba
);
12472 out_unset_driver_resource_s3
:
12473 lpfc_sli_driver_resource_unset(phba
);
12474 out_unset_pci_mem_s3
:
12475 lpfc_sli_pci_mem_unset(phba
);
12476 out_disable_pci_dev
:
12477 lpfc_disable_pci_dev(phba
);
12479 scsi_host_put(shost
);
12481 lpfc_hba_free(phba
);
12486 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
12487 * @pdev: pointer to PCI device
12489 * This routine is to be called to disattach a device with SLI-3 interface
12490 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12491 * removed from PCI bus, it performs all the necessary cleanup for the HBA
12492 * device to be removed from the PCI subsystem properly.
12495 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
12497 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12498 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
12499 struct lpfc_vport
**vports
;
12500 struct lpfc_hba
*phba
= vport
->phba
;
12503 spin_lock_irq(&phba
->hbalock
);
12504 vport
->load_flag
|= FC_UNLOADING
;
12505 spin_unlock_irq(&phba
->hbalock
);
12507 lpfc_free_sysfs_attr(vport
);
12509 /* Release all the vports against this physical port */
12510 vports
= lpfc_create_vport_work_array(phba
);
12511 if (vports
!= NULL
)
12512 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
12513 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
12515 fc_vport_terminate(vports
[i
]->fc_vport
);
12517 lpfc_destroy_vport_work_array(phba
, vports
);
12519 /* Remove FC host and then SCSI host with the physical port */
12520 fc_remove_host(shost
);
12521 scsi_remove_host(shost
);
12523 lpfc_cleanup(vport
);
12526 * Bring down the SLI Layer. This step disable all interrupts,
12527 * clears the rings, discards all mailbox commands, and resets
12531 /* HBA interrupt will be disabled after this call */
12532 lpfc_sli_hba_down(phba
);
12533 /* Stop kthread signal shall trigger work_done one more time */
12534 kthread_stop(phba
->worker_thread
);
12535 /* Final cleanup of txcmplq and reset the HBA */
12536 lpfc_sli_brdrestart(phba
);
12538 kfree(phba
->vpi_bmask
);
12539 kfree(phba
->vpi_ids
);
12541 lpfc_stop_hba_timers(phba
);
12542 spin_lock_irq(&phba
->port_list_lock
);
12543 list_del_init(&vport
->listentry
);
12544 spin_unlock_irq(&phba
->port_list_lock
);
12546 lpfc_debugfs_terminate(vport
);
12548 /* Disable SR-IOV if enabled */
12549 if (phba
->cfg_sriov_nr_virtfn
)
12550 pci_disable_sriov(pdev
);
12552 /* Disable interrupt */
12553 lpfc_sli_disable_intr(phba
);
12555 scsi_host_put(shost
);
12558 * Call scsi_free before mem_free since scsi bufs are released to their
12559 * corresponding pools here.
12561 lpfc_scsi_free(phba
);
12562 lpfc_free_iocb_list(phba
);
12564 lpfc_mem_free_all(phba
);
12566 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
12567 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
12569 /* Free resources associated with SLI2 interface */
12570 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
12571 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
12573 /* unmap adapter SLIM and Control Registers */
12574 iounmap(phba
->ctrl_regs_memmap_p
);
12575 iounmap(phba
->slim_memmap_p
);
12577 lpfc_hba_free(phba
);
12579 pci_release_mem_regions(pdev
);
12580 pci_disable_device(pdev
);
12584 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
12585 * @pdev: pointer to PCI device
12586 * @msg: power management message
12588 * This routine is to be called from the kernel's PCI subsystem to support
12589 * system Power Management (PM) to device with SLI-3 interface spec. When
12590 * PM invokes this method, it quiesces the device by stopping the driver's
12591 * worker thread for the device, turning off device's interrupt and DMA,
12592 * and bring the device offline. Note that as the driver implements the
12593 * minimum PM requirements to a power-aware driver's PM support for the
12594 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12595 * to the suspend() method call will be treated as SUSPEND and the driver will
12596 * fully reinitialize its device during resume() method call, the driver will
12597 * set device to PCI_D3hot state in PCI config space instead of setting it
12598 * according to the @msg provided by the PM.
12601 * 0 - driver suspended the device
12605 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
12607 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12608 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
12610 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12611 "0473 PCI device Power Management suspend.\n");
12613 /* Bring down the device */
12614 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
12615 lpfc_offline(phba
);
12616 kthread_stop(phba
->worker_thread
);
12618 /* Disable interrupt from device */
12619 lpfc_sli_disable_intr(phba
);
12621 /* Save device state to PCI config space */
12622 pci_save_state(pdev
);
12623 pci_set_power_state(pdev
, PCI_D3hot
);
12629 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
12630 * @pdev: pointer to PCI device
12632 * This routine is to be called from the kernel's PCI subsystem to support
12633 * system Power Management (PM) to device with SLI-3 interface spec. When PM
12634 * invokes this method, it restores the device's PCI config space state and
12635 * fully reinitializes the device and brings it online. Note that as the
12636 * driver implements the minimum PM requirements to a power-aware driver's
12637 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
12638 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
12639 * driver will fully reinitialize its device during resume() method call,
12640 * the device will be set to PCI_D0 directly in PCI config space before
12641 * restoring the state.
12644 * 0 - driver suspended the device
12648 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
12650 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12651 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
12652 uint32_t intr_mode
;
12655 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12656 "0452 PCI device Power Management resume.\n");
12658 /* Restore device state from PCI config space */
12659 pci_set_power_state(pdev
, PCI_D0
);
12660 pci_restore_state(pdev
);
12663 * As the new kernel behavior of pci_restore_state() API call clears
12664 * device saved_state flag, need to save the restored state again.
12666 pci_save_state(pdev
);
12668 if (pdev
->is_busmaster
)
12669 pci_set_master(pdev
);
12671 /* Startup the kernel thread for this host adapter. */
12672 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
12673 "lpfc_worker_%d", phba
->brd_no
);
12674 if (IS_ERR(phba
->worker_thread
)) {
12675 error
= PTR_ERR(phba
->worker_thread
);
12676 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12677 "0434 PM resume failed to start worker "
12678 "thread: error=x%x.\n", error
);
12682 /* Configure and enable interrupt */
12683 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
12684 if (intr_mode
== LPFC_INTR_ERROR
) {
12685 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12686 "0430 PM resume Failed to enable interrupt\n");
12689 phba
->intr_mode
= intr_mode
;
12691 /* Restart HBA and bring it online */
12692 lpfc_sli_brdrestart(phba
);
12695 /* Log the current active interrupt mode */
12696 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
12702 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
12703 * @phba: pointer to lpfc hba data structure.
12705 * This routine is called to prepare the SLI3 device for PCI slot recover. It
12706 * aborts all the outstanding SCSI I/Os to the pci device.
12709 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
12711 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12712 "2723 PCI channel I/O abort preparing for recovery\n");
12715 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12716 * and let the SCSI mid-layer to retry them to recover.
12718 lpfc_sli_abort_fcp_rings(phba
);
12722 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
12723 * @phba: pointer to lpfc hba data structure.
12725 * This routine is called to prepare the SLI3 device for PCI slot reset. It
12726 * disables the device interrupt and pci device, and aborts the internal FCP
12730 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
12732 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12733 "2710 PCI channel disable preparing for reset\n");
12735 /* Block any management I/Os to the device */
12736 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
12738 /* Block all SCSI devices' I/Os on the host */
12739 lpfc_scsi_dev_block(phba
);
12741 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12742 lpfc_sli_flush_io_rings(phba
);
12744 /* stop all timers */
12745 lpfc_stop_hba_timers(phba
);
12747 /* Disable interrupt and pci device */
12748 lpfc_sli_disable_intr(phba
);
12749 pci_disable_device(phba
->pcidev
);
12753 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
12754 * @phba: pointer to lpfc hba data structure.
12756 * This routine is called to prepare the SLI3 device for PCI slot permanently
12757 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12761 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
12763 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12764 "2711 PCI channel permanent disable for failure\n");
12765 /* Block all SCSI devices' I/Os on the host */
12766 lpfc_scsi_dev_block(phba
);
12768 /* stop all timers */
12769 lpfc_stop_hba_timers(phba
);
12771 /* Clean up all driver's outstanding SCSI I/Os */
12772 lpfc_sli_flush_io_rings(phba
);
12776 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
12777 * @pdev: pointer to PCI device.
12778 * @state: the current PCI connection state.
12780 * This routine is called from the PCI subsystem for I/O error handling to
12781 * device with SLI-3 interface spec. This function is called by the PCI
12782 * subsystem after a PCI bus error affecting this device has been detected.
12783 * When this function is invoked, it will need to stop all the I/Os and
12784 * interrupt(s) to the device. Once that is done, it will return
12785 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
12789 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
12790 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12791 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12793 static pci_ers_result_t
12794 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
12796 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12797 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
12800 case pci_channel_io_normal
:
12801 /* Non-fatal error, prepare for recovery */
12802 lpfc_sli_prep_dev_for_recover(phba
);
12803 return PCI_ERS_RESULT_CAN_RECOVER
;
12804 case pci_channel_io_frozen
:
12805 /* Fatal error, prepare for slot reset */
12806 lpfc_sli_prep_dev_for_reset(phba
);
12807 return PCI_ERS_RESULT_NEED_RESET
;
12808 case pci_channel_io_perm_failure
:
12809 /* Permanent failure, prepare for device down */
12810 lpfc_sli_prep_dev_for_perm_failure(phba
);
12811 return PCI_ERS_RESULT_DISCONNECT
;
12813 /* Unknown state, prepare and request slot reset */
12814 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12815 "0472 Unknown PCI error state: x%x\n", state
);
12816 lpfc_sli_prep_dev_for_reset(phba
);
12817 return PCI_ERS_RESULT_NEED_RESET
;
12822 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
12823 * @pdev: pointer to PCI device.
12825 * This routine is called from the PCI subsystem for error handling to
12826 * device with SLI-3 interface spec. This is called after PCI bus has been
12827 * reset to restart the PCI card from scratch, as if from a cold-boot.
12828 * During the PCI subsystem error recovery, after driver returns
12829 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12830 * recovery and then call this routine before calling the .resume method
12831 * to recover the device. This function will initialize the HBA device,
12832 * enable the interrupt, but it will just put the HBA to offline state
12833 * without passing any I/O traffic.
12836 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12837 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12839 static pci_ers_result_t
12840 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
12842 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12843 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
12844 struct lpfc_sli
*psli
= &phba
->sli
;
12845 uint32_t intr_mode
;
12847 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
12848 if (pci_enable_device_mem(pdev
)) {
12849 printk(KERN_ERR
"lpfc: Cannot re-enable "
12850 "PCI device after reset.\n");
12851 return PCI_ERS_RESULT_DISCONNECT
;
12854 pci_restore_state(pdev
);
12857 * As the new kernel behavior of pci_restore_state() API call clears
12858 * device saved_state flag, need to save the restored state again.
12860 pci_save_state(pdev
);
12862 if (pdev
->is_busmaster
)
12863 pci_set_master(pdev
);
12865 spin_lock_irq(&phba
->hbalock
);
12866 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
12867 spin_unlock_irq(&phba
->hbalock
);
12869 /* Configure and enable interrupt */
12870 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
12871 if (intr_mode
== LPFC_INTR_ERROR
) {
12872 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12873 "0427 Cannot re-enable interrupt after "
12875 return PCI_ERS_RESULT_DISCONNECT
;
12877 phba
->intr_mode
= intr_mode
;
12879 /* Take device offline, it will perform cleanup */
12880 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
12881 lpfc_offline(phba
);
12882 lpfc_sli_brdrestart(phba
);
12884 /* Log the current active interrupt mode */
12885 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
12887 return PCI_ERS_RESULT_RECOVERED
;
12891 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
12892 * @pdev: pointer to PCI device
12894 * This routine is called from the PCI subsystem for error handling to device
12895 * with SLI-3 interface spec. It is called when kernel error recovery tells
12896 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12897 * error recovery. After this call, traffic can start to flow from this device
12901 lpfc_io_resume_s3(struct pci_dev
*pdev
)
12903 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
12904 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
12906 /* Bring device online, it will be no-op for non-fatal error resume */
12911 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
12912 * @phba: pointer to lpfc hba data structure.
12914 * returns the number of ELS/CT IOCBs to reserve
12917 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
12919 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
12921 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
12922 if (max_xri
<= 100)
12924 else if (max_xri
<= 256)
12926 else if (max_xri
<= 512)
12928 else if (max_xri
<= 1024)
12930 else if (max_xri
<= 1536)
12932 else if (max_xri
<= 2048)
12941 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
12942 * @phba: pointer to lpfc hba data structure.
12944 * returns the number of ELS/CT + NVMET IOCBs to reserve
12947 lpfc_sli4_get_iocb_cnt(struct lpfc_hba
*phba
)
12949 int max_xri
= lpfc_sli4_get_els_iocb_cnt(phba
);
12951 if (phba
->nvmet_support
)
12952 max_xri
+= LPFC_NVMET_BUF_POST
;
12958 lpfc_log_write_firmware_error(struct lpfc_hba
*phba
, uint32_t offset
,
12959 uint32_t magic_number
, uint32_t ftype
, uint32_t fid
, uint32_t fsize
,
12960 const struct firmware
*fw
)
12964 /* Three cases: (1) FW was not supported on the detected adapter.
12965 * (2) FW update has been locked out administratively.
12966 * (3) Some other error during FW update.
12967 * In each case, an unmaskable message is written to the console
12968 * for admin diagnosis.
12970 if (offset
== ADD_STATUS_FW_NOT_SUPPORTED
||
12971 (phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G6_FC
&&
12972 magic_number
!= MAGIC_NUMBER_G6
) ||
12973 (phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G7_FC
&&
12974 magic_number
!= MAGIC_NUMBER_G7
)) {
12975 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12976 "3030 This firmware version is not supported on"
12977 " this HBA model. Device:%x Magic:%x Type:%x "
12978 "ID:%x Size %d %zd\n",
12979 phba
->pcidev
->device
, magic_number
, ftype
, fid
,
12982 } else if (offset
== ADD_STATUS_FW_DOWNLOAD_HW_DISABLED
) {
12983 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12984 "3021 Firmware downloads have been prohibited "
12985 "by a system configuration setting on "
12986 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12988 phba
->pcidev
->device
, magic_number
, ftype
, fid
,
12992 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12993 "3022 FW Download failed. Add Status x%x "
12994 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12996 offset
, phba
->pcidev
->device
, magic_number
,
12997 ftype
, fid
, fsize
, fw
->size
);
13004 * lpfc_write_firmware - attempt to write a firmware image to the port
13005 * @fw: pointer to firmware image returned from request_firmware.
13006 * @context: pointer to firmware image returned from request_firmware.
13010 lpfc_write_firmware(const struct firmware
*fw
, void *context
)
13012 struct lpfc_hba
*phba
= (struct lpfc_hba
*)context
;
13013 char fwrev
[FW_REV_STR_SIZE
];
13014 struct lpfc_grp_hdr
*image
;
13015 struct list_head dma_buffer_list
;
13017 struct lpfc_dmabuf
*dmabuf
, *next
;
13018 uint32_t offset
= 0, temp_offset
= 0;
13019 uint32_t magic_number
, ftype
, fid
, fsize
;
13021 /* It can be null in no-wait mode, sanity check */
13026 image
= (struct lpfc_grp_hdr
*)fw
->data
;
13028 magic_number
= be32_to_cpu(image
->magic_number
);
13029 ftype
= bf_get_be32(lpfc_grp_hdr_file_type
, image
);
13030 fid
= bf_get_be32(lpfc_grp_hdr_id
, image
);
13031 fsize
= be32_to_cpu(image
->size
);
13033 INIT_LIST_HEAD(&dma_buffer_list
);
13034 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
13035 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
13036 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13037 "3023 Updating Firmware, Current Version:%s "
13038 "New Version:%s\n",
13039 fwrev
, image
->revision
);
13040 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
13041 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
13047 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
13051 if (!dmabuf
->virt
) {
13056 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
13058 while (offset
< fw
->size
) {
13059 temp_offset
= offset
;
13060 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
13061 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
13062 memcpy(dmabuf
->virt
,
13063 fw
->data
+ temp_offset
,
13064 fw
->size
- temp_offset
);
13065 temp_offset
= fw
->size
;
13068 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
13070 temp_offset
+= SLI4_PAGE_SIZE
;
13072 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
13073 (fw
->size
- offset
), &offset
);
13075 rc
= lpfc_log_write_firmware_error(phba
, offset
,
13086 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13087 "3029 Skipped Firmware update, Current "
13088 "Version:%s New Version:%s\n",
13089 fwrev
, image
->revision
);
13092 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
13093 list_del(&dmabuf
->list
);
13094 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
13095 dmabuf
->virt
, dmabuf
->phys
);
13098 release_firmware(fw
);
13101 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13102 "3062 Firmware update error, status %d.\n", rc
);
13104 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13105 "3024 Firmware update success: size %d.\n", rc
);
13109 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
13110 * @phba: pointer to lpfc hba data structure.
13111 * @fw_upgrade: which firmware to update.
13113 * This routine is called to perform Linux generic firmware upgrade on device
13114 * that supports such feature.
13117 lpfc_sli4_request_firmware_update(struct lpfc_hba
*phba
, uint8_t fw_upgrade
)
13119 uint8_t file_name
[ELX_MODEL_NAME_SIZE
];
13121 const struct firmware
*fw
;
13123 /* Only supported on SLI4 interface type 2 for now */
13124 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
13125 LPFC_SLI_INTF_IF_TYPE_2
)
13128 snprintf(file_name
, ELX_MODEL_NAME_SIZE
, "%s.grp", phba
->ModelName
);
13130 if (fw_upgrade
== INT_FW_UPGRADE
) {
13131 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
13132 file_name
, &phba
->pcidev
->dev
,
13133 GFP_KERNEL
, (void *)phba
,
13134 lpfc_write_firmware
);
13135 } else if (fw_upgrade
== RUN_FW_UPGRADE
) {
13136 ret
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
13138 lpfc_write_firmware(fw
, (void *)phba
);
13147 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
13148 * @pdev: pointer to PCI device
13149 * @pid: pointer to PCI device identifier
13151 * This routine is called from the kernel's PCI subsystem to device with
13152 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13153 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13154 * information of the device and driver to see if the driver state that it
13155 * can support this kind of device. If the match is successful, the driver
13156 * core invokes this routine. If this routine determines it can claim the HBA,
13157 * it does all the initialization that it needs to do to handle the HBA
13161 * 0 - driver can claim the device
13162 * negative value - driver can not claim the device
13165 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
13167 struct lpfc_hba
*phba
;
13168 struct lpfc_vport
*vport
= NULL
;
13169 struct Scsi_Host
*shost
= NULL
;
13171 uint32_t cfg_mode
, intr_mode
;
13173 /* Allocate memory for HBA structure */
13174 phba
= lpfc_hba_alloc(pdev
);
13178 /* Perform generic PCI device enabling operation */
13179 error
= lpfc_enable_pci_dev(phba
);
13181 goto out_free_phba
;
13183 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
13184 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
13186 goto out_disable_pci_dev
;
13188 /* Set up SLI-4 specific device PCI memory space */
13189 error
= lpfc_sli4_pci_mem_setup(phba
);
13191 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13192 "1410 Failed to set up pci memory space.\n");
13193 goto out_disable_pci_dev
;
13196 /* Set up SLI-4 Specific device driver resources */
13197 error
= lpfc_sli4_driver_resource_setup(phba
);
13199 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13200 "1412 Failed to set up driver resource.\n");
13201 goto out_unset_pci_mem_s4
;
13204 INIT_LIST_HEAD(&phba
->active_rrq_list
);
13205 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
13207 /* Set up common device driver resources */
13208 error
= lpfc_setup_driver_resource_phase2(phba
);
13210 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13211 "1414 Failed to set up driver resource.\n");
13212 goto out_unset_driver_resource_s4
;
13215 /* Get the default values for Model Name and Description */
13216 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
13218 /* Now, trying to enable interrupt and bring up the device */
13219 cfg_mode
= phba
->cfg_use_msi
;
13221 /* Put device to a known state before enabling interrupt */
13222 phba
->pport
= NULL
;
13223 lpfc_stop_port(phba
);
13225 /* Init cpu_map array */
13226 lpfc_cpu_map_array_init(phba
);
13228 /* Init hba_eq_hdl array */
13229 lpfc_hba_eq_hdl_array_init(phba
);
13231 /* Configure and enable interrupt */
13232 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
13233 if (intr_mode
== LPFC_INTR_ERROR
) {
13234 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13235 "0426 Failed to enable interrupt.\n");
13237 goto out_unset_driver_resource
;
13239 /* Default to single EQ for non-MSI-X */
13240 if (phba
->intr_type
!= MSIX
) {
13241 phba
->cfg_irq_chann
= 1;
13242 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
13243 if (phba
->nvmet_support
)
13244 phba
->cfg_nvmet_mrq
= 1;
13247 lpfc_cpu_affinity_check(phba
, phba
->cfg_irq_chann
);
13249 /* Create SCSI host to the physical port */
13250 error
= lpfc_create_shost(phba
);
13252 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13253 "1415 Failed to create scsi host.\n");
13254 goto out_disable_intr
;
13256 vport
= phba
->pport
;
13257 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
13259 /* Configure sysfs attributes */
13260 error
= lpfc_alloc_sysfs_attr(vport
);
13262 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13263 "1416 Failed to allocate sysfs attr\n");
13264 goto out_destroy_shost
;
13267 /* Set up SLI-4 HBA */
13268 if (lpfc_sli4_hba_setup(phba
)) {
13269 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13270 "1421 Failed to set up hba\n");
13272 goto out_free_sysfs_attr
;
13275 /* Log the current active interrupt mode */
13276 phba
->intr_mode
= intr_mode
;
13277 lpfc_log_intr_mode(phba
, intr_mode
);
13279 /* Perform post initialization setup */
13280 lpfc_post_init_setup(phba
);
13282 /* NVME support in FW earlier in the driver load corrects the
13283 * FC4 type making a check for nvme_support unnecessary.
13285 if (phba
->nvmet_support
== 0) {
13286 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
13287 /* Create NVME binding with nvme_fc_transport. This
13288 * ensures the vport is initialized. If the localport
13289 * create fails, it should not unload the driver to
13290 * support field issues.
13292 error
= lpfc_nvme_create_localport(vport
);
13294 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13295 "6004 NVME registration "
13296 "failed, error x%x\n",
13302 /* check for firmware upgrade or downgrade */
13303 if (phba
->cfg_request_firmware_upgrade
)
13304 lpfc_sli4_request_firmware_update(phba
, INT_FW_UPGRADE
);
13306 /* Check if there are static vports to be created. */
13307 lpfc_create_static_vport(phba
);
13309 /* Enable RAS FW log support */
13310 lpfc_sli4_ras_setup(phba
);
13312 INIT_LIST_HEAD(&phba
->poll_list
);
13313 timer_setup(&phba
->cpuhp_poll_timer
, lpfc_sli4_poll_hbtimer
, 0);
13314 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state
, &phba
->cpuhp
);
13318 out_free_sysfs_attr
:
13319 lpfc_free_sysfs_attr(vport
);
13321 lpfc_destroy_shost(phba
);
13323 lpfc_sli4_disable_intr(phba
);
13324 out_unset_driver_resource
:
13325 lpfc_unset_driver_resource_phase2(phba
);
13326 out_unset_driver_resource_s4
:
13327 lpfc_sli4_driver_resource_unset(phba
);
13328 out_unset_pci_mem_s4
:
13329 lpfc_sli4_pci_mem_unset(phba
);
13330 out_disable_pci_dev
:
13331 lpfc_disable_pci_dev(phba
);
13333 scsi_host_put(shost
);
13335 lpfc_hba_free(phba
);
13340 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
13341 * @pdev: pointer to PCI device
13343 * This routine is called from the kernel's PCI subsystem to device with
13344 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13345 * removed from PCI bus, it performs all the necessary cleanup for the HBA
13346 * device to be removed from the PCI subsystem properly.
13349 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
13351 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13352 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
13353 struct lpfc_vport
**vports
;
13354 struct lpfc_hba
*phba
= vport
->phba
;
13357 /* Mark the device unloading flag */
13358 spin_lock_irq(&phba
->hbalock
);
13359 vport
->load_flag
|= FC_UNLOADING
;
13360 spin_unlock_irq(&phba
->hbalock
);
13362 /* Free the HBA sysfs attributes */
13363 lpfc_free_sysfs_attr(vport
);
13365 /* Release all the vports against this physical port */
13366 vports
= lpfc_create_vport_work_array(phba
);
13367 if (vports
!= NULL
)
13368 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
13369 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
13371 fc_vport_terminate(vports
[i
]->fc_vport
);
13373 lpfc_destroy_vport_work_array(phba
, vports
);
13375 /* Remove FC host and then SCSI host with the physical port */
13376 fc_remove_host(shost
);
13377 scsi_remove_host(shost
);
13379 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
13380 * localports are destroyed after to cleanup all transport memory.
13382 lpfc_cleanup(vport
);
13383 lpfc_nvmet_destroy_targetport(phba
);
13384 lpfc_nvme_destroy_localport(vport
);
13386 /* De-allocate multi-XRI pools */
13387 if (phba
->cfg_xri_rebalancing
)
13388 lpfc_destroy_multixri_pools(phba
);
13391 * Bring down the SLI Layer. This step disables all interrupts,
13392 * clears the rings, discards all mailbox commands, and resets
13393 * the HBA FCoE function.
13395 lpfc_debugfs_terminate(vport
);
13397 lpfc_stop_hba_timers(phba
);
13398 spin_lock_irq(&phba
->port_list_lock
);
13399 list_del_init(&vport
->listentry
);
13400 spin_unlock_irq(&phba
->port_list_lock
);
13402 /* Perform scsi free before driver resource_unset since scsi
13403 * buffers are released to their corresponding pools here.
13405 lpfc_io_free(phba
);
13406 lpfc_free_iocb_list(phba
);
13407 lpfc_sli4_hba_unset(phba
);
13409 lpfc_unset_driver_resource_phase2(phba
);
13410 lpfc_sli4_driver_resource_unset(phba
);
13412 /* Unmap adapter Control and Doorbell registers */
13413 lpfc_sli4_pci_mem_unset(phba
);
13415 /* Release PCI resources and disable device's PCI function */
13416 scsi_host_put(shost
);
13417 lpfc_disable_pci_dev(phba
);
13419 /* Finally, free the driver's device data structure */
13420 lpfc_hba_free(phba
);
13426 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
13427 * @pdev: pointer to PCI device
13428 * @msg: power management message
13430 * This routine is called from the kernel's PCI subsystem to support system
13431 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
13432 * this method, it quiesces the device by stopping the driver's worker
13433 * thread for the device, turning off device's interrupt and DMA, and bring
13434 * the device offline. Note that as the driver implements the minimum PM
13435 * requirements to a power-aware driver's PM support for suspend/resume -- all
13436 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
13437 * method call will be treated as SUSPEND and the driver will fully
13438 * reinitialize its device during resume() method call, the driver will set
13439 * device to PCI_D3hot state in PCI config space instead of setting it
13440 * according to the @msg provided by the PM.
13443 * 0 - driver suspended the device
13447 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
13449 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13450 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13452 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13453 "2843 PCI device Power Management suspend.\n");
13455 /* Bring down the device */
13456 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
13457 lpfc_offline(phba
);
13458 kthread_stop(phba
->worker_thread
);
13460 /* Disable interrupt from device */
13461 lpfc_sli4_disable_intr(phba
);
13462 lpfc_sli4_queue_destroy(phba
);
13464 /* Save device state to PCI config space */
13465 pci_save_state(pdev
);
13466 pci_set_power_state(pdev
, PCI_D3hot
);
13472 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
13473 * @pdev: pointer to PCI device
13475 * This routine is called from the kernel's PCI subsystem to support system
13476 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
13477 * this method, it restores the device's PCI config space state and fully
13478 * reinitializes the device and brings it online. Note that as the driver
13479 * implements the minimum PM requirements to a power-aware driver's PM for
13480 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
13481 * to the suspend() method call will be treated as SUSPEND and the driver
13482 * will fully reinitialize its device during resume() method call, the device
13483 * will be set to PCI_D0 directly in PCI config space before restoring the
13487 * 0 - driver suspended the device
13491 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
13493 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13494 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13495 uint32_t intr_mode
;
13498 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13499 "0292 PCI device Power Management resume.\n");
13501 /* Restore device state from PCI config space */
13502 pci_set_power_state(pdev
, PCI_D0
);
13503 pci_restore_state(pdev
);
13506 * As the new kernel behavior of pci_restore_state() API call clears
13507 * device saved_state flag, need to save the restored state again.
13509 pci_save_state(pdev
);
13511 if (pdev
->is_busmaster
)
13512 pci_set_master(pdev
);
13514 /* Startup the kernel thread for this host adapter. */
13515 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
13516 "lpfc_worker_%d", phba
->brd_no
);
13517 if (IS_ERR(phba
->worker_thread
)) {
13518 error
= PTR_ERR(phba
->worker_thread
);
13519 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13520 "0293 PM resume failed to start worker "
13521 "thread: error=x%x.\n", error
);
13525 /* Configure and enable interrupt */
13526 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
13527 if (intr_mode
== LPFC_INTR_ERROR
) {
13528 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13529 "0294 PM resume Failed to enable interrupt\n");
13532 phba
->intr_mode
= intr_mode
;
13534 /* Restart HBA and bring it online */
13535 lpfc_sli_brdrestart(phba
);
13538 /* Log the current active interrupt mode */
13539 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
13545 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
13546 * @phba: pointer to lpfc hba data structure.
13548 * This routine is called to prepare the SLI4 device for PCI slot recover. It
13549 * aborts all the outstanding SCSI I/Os to the pci device.
13552 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
13554 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13555 "2828 PCI channel I/O abort preparing for recovery\n");
13557 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
13558 * and let the SCSI mid-layer to retry them to recover.
13560 lpfc_sli_abort_fcp_rings(phba
);
13564 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
13565 * @phba: pointer to lpfc hba data structure.
13567 * This routine is called to prepare the SLI4 device for PCI slot reset. It
13568 * disables the device interrupt and pci device, and aborts the internal FCP
13572 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
13574 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13575 "2826 PCI channel disable preparing for reset\n");
13577 /* Block any management I/Os to the device */
13578 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
13580 /* Block all SCSI devices' I/Os on the host */
13581 lpfc_scsi_dev_block(phba
);
13583 /* Flush all driver's outstanding I/Os as we are to reset */
13584 lpfc_sli_flush_io_rings(phba
);
13586 /* stop all timers */
13587 lpfc_stop_hba_timers(phba
);
13589 /* Disable interrupt and pci device */
13590 lpfc_sli4_disable_intr(phba
);
13591 lpfc_sli4_queue_destroy(phba
);
13592 pci_disable_device(phba
->pcidev
);
13596 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
13597 * @phba: pointer to lpfc hba data structure.
13599 * This routine is called to prepare the SLI4 device for PCI slot permanently
13600 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
13604 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
13606 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13607 "2827 PCI channel permanent disable for failure\n");
13609 /* Block all SCSI devices' I/Os on the host */
13610 lpfc_scsi_dev_block(phba
);
13612 /* stop all timers */
13613 lpfc_stop_hba_timers(phba
);
13615 /* Clean up all driver's outstanding I/Os */
13616 lpfc_sli_flush_io_rings(phba
);
13620 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
13621 * @pdev: pointer to PCI device.
13622 * @state: the current PCI connection state.
13624 * This routine is called from the PCI subsystem for error handling to device
13625 * with SLI-4 interface spec. This function is called by the PCI subsystem
13626 * after a PCI bus error affecting this device has been detected. When this
13627 * function is invoked, it will need to stop all the I/Os and interrupt(s)
13628 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
13629 * for the PCI subsystem to perform proper recovery as desired.
13632 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13633 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13635 static pci_ers_result_t
13636 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
13638 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13639 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13642 case pci_channel_io_normal
:
13643 /* Non-fatal error, prepare for recovery */
13644 lpfc_sli4_prep_dev_for_recover(phba
);
13645 return PCI_ERS_RESULT_CAN_RECOVER
;
13646 case pci_channel_io_frozen
:
13647 /* Fatal error, prepare for slot reset */
13648 lpfc_sli4_prep_dev_for_reset(phba
);
13649 return PCI_ERS_RESULT_NEED_RESET
;
13650 case pci_channel_io_perm_failure
:
13651 /* Permanent failure, prepare for device down */
13652 lpfc_sli4_prep_dev_for_perm_failure(phba
);
13653 return PCI_ERS_RESULT_DISCONNECT
;
13655 /* Unknown state, prepare and request slot reset */
13656 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13657 "2825 Unknown PCI error state: x%x\n", state
);
13658 lpfc_sli4_prep_dev_for_reset(phba
);
13659 return PCI_ERS_RESULT_NEED_RESET
;
13664 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
13665 * @pdev: pointer to PCI device.
13667 * This routine is called from the PCI subsystem for error handling to device
13668 * with SLI-4 interface spec. It is called after PCI bus has been reset to
13669 * restart the PCI card from scratch, as if from a cold-boot. During the
13670 * PCI subsystem error recovery, after the driver returns
13671 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13672 * recovery and then call this routine before calling the .resume method to
13673 * recover the device. This function will initialize the HBA device, enable
13674 * the interrupt, but it will just put the HBA to offline state without
13675 * passing any I/O traffic.
13678 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13679 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13681 static pci_ers_result_t
13682 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
13684 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13685 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13686 struct lpfc_sli
*psli
= &phba
->sli
;
13687 uint32_t intr_mode
;
13689 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
13690 if (pci_enable_device_mem(pdev
)) {
13691 printk(KERN_ERR
"lpfc: Cannot re-enable "
13692 "PCI device after reset.\n");
13693 return PCI_ERS_RESULT_DISCONNECT
;
13696 pci_restore_state(pdev
);
13699 * As the new kernel behavior of pci_restore_state() API call clears
13700 * device saved_state flag, need to save the restored state again.
13702 pci_save_state(pdev
);
13704 if (pdev
->is_busmaster
)
13705 pci_set_master(pdev
);
13707 spin_lock_irq(&phba
->hbalock
);
13708 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
13709 spin_unlock_irq(&phba
->hbalock
);
13711 /* Configure and enable interrupt */
13712 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
13713 if (intr_mode
== LPFC_INTR_ERROR
) {
13714 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13715 "2824 Cannot re-enable interrupt after "
13717 return PCI_ERS_RESULT_DISCONNECT
;
13719 phba
->intr_mode
= intr_mode
;
13721 /* Log the current active interrupt mode */
13722 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
13724 return PCI_ERS_RESULT_RECOVERED
;
13728 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
13729 * @pdev: pointer to PCI device
13731 * This routine is called from the PCI subsystem for error handling to device
13732 * with SLI-4 interface spec. It is called when kernel error recovery tells
13733 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13734 * error recovery. After this call, traffic can start to flow from this device
13738 lpfc_io_resume_s4(struct pci_dev
*pdev
)
13740 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13741 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13744 * In case of slot reset, as function reset is performed through
13745 * mailbox command which needs DMA to be enabled, this operation
13746 * has to be moved to the io resume phase. Taking device offline
13747 * will perform the necessary cleanup.
13749 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
13750 /* Perform device reset */
13751 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
13752 lpfc_offline(phba
);
13753 lpfc_sli_brdrestart(phba
);
13754 /* Bring the device back online */
13760 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
13761 * @pdev: pointer to PCI device
13762 * @pid: pointer to PCI device identifier
13764 * This routine is to be registered to the kernel's PCI subsystem. When an
13765 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
13766 * at PCI device-specific information of the device and driver to see if the
13767 * driver state that it can support this kind of device. If the match is
13768 * successful, the driver core invokes this routine. This routine dispatches
13769 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
13770 * do all the initialization that it needs to do to handle the HBA device
13774 * 0 - driver can claim the device
13775 * negative value - driver can not claim the device
13778 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
13781 struct lpfc_sli_intf intf
;
13783 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
13786 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
13787 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
13788 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
13790 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
13796 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
13797 * @pdev: pointer to PCI device
13799 * This routine is to be registered to the kernel's PCI subsystem. When an
13800 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
13801 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
13802 * remove routine, which will perform all the necessary cleanup for the
13803 * device to be removed from the PCI subsystem properly.
13806 lpfc_pci_remove_one(struct pci_dev
*pdev
)
13808 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13809 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13811 switch (phba
->pci_dev_grp
) {
13812 case LPFC_PCI_DEV_LP
:
13813 lpfc_pci_remove_one_s3(pdev
);
13815 case LPFC_PCI_DEV_OC
:
13816 lpfc_pci_remove_one_s4(pdev
);
13819 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13820 "1424 Invalid PCI device group: 0x%x\n",
13821 phba
->pci_dev_grp
);
13828 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
13829 * @pdev: pointer to PCI device
13830 * @msg: power management message
13832 * This routine is to be registered to the kernel's PCI subsystem to support
13833 * system Power Management (PM). When PM invokes this method, it dispatches
13834 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
13835 * suspend the device.
13838 * 0 - driver suspended the device
13842 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
13844 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13845 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13848 switch (phba
->pci_dev_grp
) {
13849 case LPFC_PCI_DEV_LP
:
13850 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
13852 case LPFC_PCI_DEV_OC
:
13853 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
13856 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13857 "1425 Invalid PCI device group: 0x%x\n",
13858 phba
->pci_dev_grp
);
13865 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
13866 * @pdev: pointer to PCI device
13868 * This routine is to be registered to the kernel's PCI subsystem to support
13869 * system Power Management (PM). When PM invokes this method, it dispatches
13870 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
13871 * resume the device.
13874 * 0 - driver suspended the device
13878 lpfc_pci_resume_one(struct pci_dev
*pdev
)
13880 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13881 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13884 switch (phba
->pci_dev_grp
) {
13885 case LPFC_PCI_DEV_LP
:
13886 rc
= lpfc_pci_resume_one_s3(pdev
);
13888 case LPFC_PCI_DEV_OC
:
13889 rc
= lpfc_pci_resume_one_s4(pdev
);
13892 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13893 "1426 Invalid PCI device group: 0x%x\n",
13894 phba
->pci_dev_grp
);
13901 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
13902 * @pdev: pointer to PCI device.
13903 * @state: the current PCI connection state.
13905 * This routine is registered to the PCI subsystem for error handling. This
13906 * function is called by the PCI subsystem after a PCI bus error affecting
13907 * this device has been detected. When this routine is invoked, it dispatches
13908 * the action to the proper SLI-3 or SLI-4 device error detected handling
13909 * routine, which will perform the proper error detected operation.
13912 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13913 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13915 static pci_ers_result_t
13916 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
13918 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13919 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13920 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
13922 switch (phba
->pci_dev_grp
) {
13923 case LPFC_PCI_DEV_LP
:
13924 rc
= lpfc_io_error_detected_s3(pdev
, state
);
13926 case LPFC_PCI_DEV_OC
:
13927 rc
= lpfc_io_error_detected_s4(pdev
, state
);
13930 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13931 "1427 Invalid PCI device group: 0x%x\n",
13932 phba
->pci_dev_grp
);
13939 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
13940 * @pdev: pointer to PCI device.
13942 * This routine is registered to the PCI subsystem for error handling. This
13943 * function is called after PCI bus has been reset to restart the PCI card
13944 * from scratch, as if from a cold-boot. When this routine is invoked, it
13945 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
13946 * routine, which will perform the proper device reset.
13949 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13950 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13952 static pci_ers_result_t
13953 lpfc_io_slot_reset(struct pci_dev
*pdev
)
13955 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13956 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13957 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
13959 switch (phba
->pci_dev_grp
) {
13960 case LPFC_PCI_DEV_LP
:
13961 rc
= lpfc_io_slot_reset_s3(pdev
);
13963 case LPFC_PCI_DEV_OC
:
13964 rc
= lpfc_io_slot_reset_s4(pdev
);
13967 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
13968 "1428 Invalid PCI device group: 0x%x\n",
13969 phba
->pci_dev_grp
);
13976 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
13977 * @pdev: pointer to PCI device
13979 * This routine is registered to the PCI subsystem for error handling. It
13980 * is called when kernel error recovery tells the lpfc driver that it is
13981 * OK to resume normal PCI operation after PCI bus error recovery. When
13982 * this routine is invoked, it dispatches the action to the proper SLI-3
13983 * or SLI-4 device io_resume routine, which will resume the device operation.
13986 lpfc_io_resume(struct pci_dev
*pdev
)
13988 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
13989 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
13991 switch (phba
->pci_dev_grp
) {
13992 case LPFC_PCI_DEV_LP
:
13993 lpfc_io_resume_s3(pdev
);
13995 case LPFC_PCI_DEV_OC
:
13996 lpfc_io_resume_s4(pdev
);
13999 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
14000 "1429 Invalid PCI device group: 0x%x\n",
14001 phba
->pci_dev_grp
);
14008 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
14009 * @phba: pointer to lpfc hba data structure.
14011 * This routine checks to see if OAS is supported for this adapter. If
14012 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
14013 * the enable oas flag is cleared and the pool created for OAS device data
14018 lpfc_sli4_oas_verify(struct lpfc_hba
*phba
)
14021 if (!phba
->cfg_EnableXLane
)
14024 if (phba
->sli4_hba
.pc_sli4_params
.oas_supported
) {
14028 mempool_destroy(phba
->device_data_mem_pool
);
14029 phba
->device_data_mem_pool
= NULL
;
14036 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
14037 * @phba: pointer to lpfc hba data structure.
14039 * This routine checks to see if RAS is supported by the adapter. Check the
14040 * function through which RAS support enablement is to be done.
14043 lpfc_sli4_ras_init(struct lpfc_hba
*phba
)
14045 switch (phba
->pcidev
->device
) {
14046 case PCI_DEVICE_ID_LANCER_G6_FC
:
14047 case PCI_DEVICE_ID_LANCER_G7_FC
:
14048 phba
->ras_fwlog
.ras_hwsupport
= true;
14049 if (phba
->cfg_ras_fwlog_func
== PCI_FUNC(phba
->pcidev
->devfn
) &&
14050 phba
->cfg_ras_fwlog_buffsize
)
14051 phba
->ras_fwlog
.ras_enabled
= true;
14053 phba
->ras_fwlog
.ras_enabled
= false;
14056 phba
->ras_fwlog
.ras_hwsupport
= false;
14061 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
14063 static const struct pci_error_handlers lpfc_err_handler
= {
14064 .error_detected
= lpfc_io_error_detected
,
14065 .slot_reset
= lpfc_io_slot_reset
,
14066 .resume
= lpfc_io_resume
,
14069 static struct pci_driver lpfc_driver
= {
14070 .name
= LPFC_DRIVER_NAME
,
14071 .id_table
= lpfc_id_table
,
14072 .probe
= lpfc_pci_probe_one
,
14073 .remove
= lpfc_pci_remove_one
,
14074 .shutdown
= lpfc_pci_remove_one
,
14075 .suspend
= lpfc_pci_suspend_one
,
14076 .resume
= lpfc_pci_resume_one
,
14077 .err_handler
= &lpfc_err_handler
,
14080 static const struct file_operations lpfc_mgmt_fop
= {
14081 .owner
= THIS_MODULE
,
14084 static struct miscdevice lpfc_mgmt_dev
= {
14085 .minor
= MISC_DYNAMIC_MINOR
,
14086 .name
= "lpfcmgmt",
14087 .fops
= &lpfc_mgmt_fop
,
14091 * lpfc_init - lpfc module initialization routine
14093 * This routine is to be invoked when the lpfc module is loaded into the
14094 * kernel. The special kernel macro module_init() is used to indicate the
14095 * role of this routine to the kernel as lpfc module entry point.
14099 * -ENOMEM - FC attach transport failed
14100 * all others - failed
14107 pr_info(LPFC_MODULE_DESC
"\n");
14108 pr_info(LPFC_COPYRIGHT
"\n");
14110 error
= misc_register(&lpfc_mgmt_dev
);
14112 printk(KERN_ERR
"Could not register lpfcmgmt device, "
14113 "misc_register returned with status %d", error
);
14116 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
14117 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
14118 lpfc_transport_template
=
14119 fc_attach_transport(&lpfc_transport_functions
);
14120 if (lpfc_transport_template
== NULL
)
14122 lpfc_vport_transport_template
=
14123 fc_attach_transport(&lpfc_vport_transport_functions
);
14124 if (lpfc_vport_transport_template
== NULL
) {
14125 fc_release_transport(lpfc_transport_template
);
14128 lpfc_nvme_cmd_template();
14129 lpfc_nvmet_cmd_template();
14131 /* Initialize in case vector mapping is needed */
14132 lpfc_present_cpu
= num_present_cpus();
14134 error
= cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN
,
14135 "lpfc/sli4:online",
14136 lpfc_cpu_online
, lpfc_cpu_offline
);
14138 goto cpuhp_failure
;
14139 lpfc_cpuhp_state
= error
;
14141 error
= pci_register_driver(&lpfc_driver
);
14148 cpuhp_remove_multi_state(lpfc_cpuhp_state
);
14150 fc_release_transport(lpfc_transport_template
);
14151 fc_release_transport(lpfc_vport_transport_template
);
14153 misc_deregister(&lpfc_mgmt_dev
);
14158 void lpfc_dmp_dbg(struct lpfc_hba
*phba
)
14160 unsigned int start_idx
;
14161 unsigned int dbg_cnt
;
14162 unsigned int temp_idx
;
14165 unsigned long rem_nsec
;
14167 if (phba
->cfg_log_verbose
)
14170 if (atomic_cmpxchg(&phba
->dbg_log_dmping
, 0, 1) != 0)
14173 start_idx
= (unsigned int)atomic_read(&phba
->dbg_log_idx
) % DBG_LOG_SZ
;
14174 dbg_cnt
= (unsigned int)atomic_read(&phba
->dbg_log_cnt
);
14175 temp_idx
= start_idx
;
14176 if (dbg_cnt
>= DBG_LOG_SZ
) {
14177 dbg_cnt
= DBG_LOG_SZ
;
14180 if ((start_idx
+ dbg_cnt
) > (DBG_LOG_SZ
- 1)) {
14181 temp_idx
= (start_idx
+ dbg_cnt
) % DBG_LOG_SZ
;
14183 if (start_idx
< dbg_cnt
)
14184 start_idx
= DBG_LOG_SZ
- (dbg_cnt
- start_idx
);
14186 start_idx
-= dbg_cnt
;
14189 dev_info(&phba
->pcidev
->dev
, "start %d end %d cnt %d\n",
14190 start_idx
, temp_idx
, dbg_cnt
);
14192 for (i
= 0; i
< dbg_cnt
; i
++) {
14193 if ((start_idx
+ i
) < DBG_LOG_SZ
)
14194 temp_idx
= (start_idx
+ i
) % DBG_LOG_SZ
;
14197 rem_nsec
= do_div(phba
->dbg_log
[temp_idx
].t_ns
, NSEC_PER_SEC
);
14198 dev_info(&phba
->pcidev
->dev
, "%d: [%5lu.%06lu] %s",
14200 (unsigned long)phba
->dbg_log
[temp_idx
].t_ns
,
14202 phba
->dbg_log
[temp_idx
].log
);
14204 atomic_set(&phba
->dbg_log_cnt
, 0);
14205 atomic_set(&phba
->dbg_log_dmping
, 0);
14209 void lpfc_dbg_print(struct lpfc_hba
*phba
, const char *fmt
, ...)
14213 int dbg_dmping
= atomic_read(&phba
->dbg_log_dmping
);
14214 struct va_format vaf
;
14217 va_start(args
, fmt
);
14218 if (unlikely(dbg_dmping
)) {
14221 dev_info(&phba
->pcidev
->dev
, "%pV", &vaf
);
14225 idx
= (unsigned int)atomic_fetch_add(1, &phba
->dbg_log_idx
) %
14228 atomic_inc(&phba
->dbg_log_cnt
);
14230 vscnprintf(phba
->dbg_log
[idx
].log
,
14231 sizeof(phba
->dbg_log
[idx
].log
), fmt
, args
);
14234 phba
->dbg_log
[idx
].t_ns
= local_clock();
14238 * lpfc_exit - lpfc module removal routine
14240 * This routine is invoked when the lpfc module is removed from the kernel.
14241 * The special kernel macro module_exit() is used to indicate the role of
14242 * this routine to the kernel as lpfc module exit point.
14247 misc_deregister(&lpfc_mgmt_dev
);
14248 pci_unregister_driver(&lpfc_driver
);
14249 cpuhp_remove_multi_state(lpfc_cpuhp_state
);
14250 fc_release_transport(lpfc_transport_template
);
14251 fc_release_transport(lpfc_vport_transport_template
);
14252 idr_destroy(&lpfc_hba_index
);
14255 module_init(lpfc_init
);
14256 module_exit(lpfc_exit
);
14257 MODULE_LICENSE("GPL");
14258 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
14259 MODULE_AUTHOR("Broadcom");
14260 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);