1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
28 #include <linux/kthread.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
32 #include <linux/aer.h>
33 #include <linux/slab.h>
34 #include <linux/firmware.h>
35 #include <linux/miscdevice.h>
36 #include <linux/percpu.h>
37 #include <linux/msi.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
42 #include <scsi/scsi_transport_fc.h>
47 #include "lpfc_sli4.h"
49 #include "lpfc_disc.h"
51 #include "lpfc_scsi.h"
52 #include "lpfc_nvme.h"
53 #include "lpfc_logmsg.h"
54 #include "lpfc_crtn.h"
55 #include "lpfc_vport.h"
56 #include "lpfc_version.h"
60 unsigned long _dump_buf_data_order
;
62 unsigned long _dump_buf_dif_order
;
63 spinlock_t _dump_buf_lock
;
65 /* Used when mapping IRQ vectors in a driver centric manner */
66 uint16_t *lpfc_used_cpu
;
67 uint32_t lpfc_present_cpu
;
69 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
70 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
71 static int lpfc_sli4_queue_verify(struct lpfc_hba
*);
72 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
73 static int lpfc_setup_endian_order(struct lpfc_hba
*);
74 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
75 static void lpfc_free_els_sgl_list(struct lpfc_hba
*);
76 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba
*);
77 static void lpfc_init_sgl_list(struct lpfc_hba
*);
78 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
79 static void lpfc_free_active_sgl(struct lpfc_hba
*);
80 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
81 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
82 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
83 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
84 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
85 static void lpfc_sli4_disable_intr(struct lpfc_hba
*);
86 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba
*, uint32_t);
87 static void lpfc_sli4_oas_verify(struct lpfc_hba
*phba
);
89 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
90 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
91 static DEFINE_IDR(lpfc_hba_index
);
92 #define LPFC_NVMET_BUF_POST 254
95 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
96 * @phba: pointer to lpfc hba data structure.
98 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
99 * mailbox command. It retrieves the revision information from the HBA and
100 * collects the Vital Product Data (VPD) about the HBA for preparing the
101 * configuration of the HBA.
105 * -ERESTART - requests the SLI layer to reset the HBA and try again.
106 * Any other value - indicates an error.
109 lpfc_config_port_prep(struct lpfc_hba
*phba
)
111 lpfc_vpd_t
*vp
= &phba
->vpd
;
115 char *lpfc_vpd_data
= NULL
;
117 static char licensed
[56] =
118 "key unlock for use with gnu public licensed code only\0";
119 static int init_key
= 1;
121 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
123 phba
->link_state
= LPFC_HBA_ERROR
;
128 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
130 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
132 uint32_t *ptext
= (uint32_t *) licensed
;
134 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
135 *ptext
= cpu_to_be32(*ptext
);
139 lpfc_read_nv(phba
, pmb
);
140 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
141 sizeof (mb
->un
.varRDnvp
.rsvd3
));
142 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
145 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
147 if (rc
!= MBX_SUCCESS
) {
148 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
149 "0324 Config Port initialization "
150 "error, mbxCmd x%x READ_NVPARM, "
152 mb
->mbxCommand
, mb
->mbxStatus
);
153 mempool_free(pmb
, phba
->mbox_mem_pool
);
156 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
158 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
162 phba
->sli3_options
= 0x0;
164 /* Setup and issue mailbox READ REV command */
165 lpfc_read_rev(phba
, pmb
);
166 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
167 if (rc
!= MBX_SUCCESS
) {
168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
169 "0439 Adapter failed to init, mbxCmd x%x "
170 "READ_REV, mbxStatus x%x\n",
171 mb
->mbxCommand
, mb
->mbxStatus
);
172 mempool_free( pmb
, phba
->mbox_mem_pool
);
178 * The value of rr must be 1 since the driver set the cv field to 1.
179 * This setting requires the FW to set all revision fields.
181 if (mb
->un
.varRdRev
.rr
== 0) {
183 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
184 "0440 Adapter failed to init, READ_REV has "
185 "missing revision information.\n");
186 mempool_free(pmb
, phba
->mbox_mem_pool
);
190 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
191 mempool_free(pmb
, phba
->mbox_mem_pool
);
195 /* Save information as VPD data */
197 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
198 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
199 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
200 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
201 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
202 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
203 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
204 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
205 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
206 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
207 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
208 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
209 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
210 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
211 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
213 /* If the sli feature level is less then 9, we must
214 * tear down all RPIs and VPIs on link down if NPIV
217 if (vp
->rev
.feaLevelHigh
< 9)
218 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
220 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
221 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
222 sizeof (phba
->RandomData
));
224 /* Get adapter VPD information */
225 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
229 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
230 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
232 if (rc
!= MBX_SUCCESS
) {
233 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
234 "0441 VPD not present on adapter, "
235 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
236 mb
->mbxCommand
, mb
->mbxStatus
);
237 mb
->un
.varDmp
.word_cnt
= 0;
239 /* dump mem may return a zero when finished or we got a
240 * mailbox error, either way we are done.
242 if (mb
->un
.varDmp
.word_cnt
== 0)
244 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
245 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
246 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
247 lpfc_vpd_data
+ offset
,
248 mb
->un
.varDmp
.word_cnt
);
249 offset
+= mb
->un
.varDmp
.word_cnt
;
250 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
251 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
253 kfree(lpfc_vpd_data
);
255 mempool_free(pmb
, phba
->mbox_mem_pool
);
260 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
261 * @phba: pointer to lpfc hba data structure.
262 * @pmboxq: pointer to the driver internal queue element for mailbox command.
264 * This is the completion handler for driver's configuring asynchronous event
265 * mailbox command to the device. If the mailbox command returns successfully,
266 * it will set internal async event support flag to 1; otherwise, it will
267 * set internal async event support flag to 0.
270 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
272 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
273 phba
->temp_sensor_support
= 1;
275 phba
->temp_sensor_support
= 0;
276 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
281 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
282 * @phba: pointer to lpfc hba data structure.
283 * @pmboxq: pointer to the driver internal queue element for mailbox command.
285 * This is the completion handler for dump mailbox command for getting
286 * wake up parameters. When this command complete, the response contain
287 * Option rom version of the HBA. This function translate the version number
288 * into a human readable string and store it in OptionROMVersion.
291 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
294 uint32_t prog_id_word
;
296 /* character array used for decoding dist type. */
297 char dist_char
[] = "nabx";
299 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
300 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
304 prg
= (struct prog_id
*) &prog_id_word
;
306 /* word 7 contain option rom version */
307 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
309 /* Decode the Option rom version word to a readable string */
311 dist
= dist_char
[prg
->dist
];
313 if ((prg
->dist
== 3) && (prg
->num
== 0))
314 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d",
315 prg
->ver
, prg
->rev
, prg
->lev
);
317 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d%c%d",
318 prg
->ver
, prg
->rev
, prg
->lev
,
320 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
325 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
326 * cfg_soft_wwnn, cfg_soft_wwpn
327 * @vport: pointer to lpfc vport data structure.
334 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
336 /* If the soft name exists then update it using the service params */
337 if (vport
->phba
->cfg_soft_wwnn
)
338 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
339 vport
->fc_sparam
.nodeName
.u
.wwn
);
340 if (vport
->phba
->cfg_soft_wwpn
)
341 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
342 vport
->fc_sparam
.portName
.u
.wwn
);
345 * If the name is empty or there exists a soft name
346 * then copy the service params name, otherwise use the fc name
348 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
349 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
350 sizeof(struct lpfc_name
));
352 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
353 sizeof(struct lpfc_name
));
355 if (vport
->fc_portname
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwpn
)
356 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
357 sizeof(struct lpfc_name
));
359 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
360 sizeof(struct lpfc_name
));
364 * lpfc_config_port_post - Perform lpfc initialization after config port
365 * @phba: pointer to lpfc hba data structure.
367 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
368 * command call. It performs all internal resource and state setups on the
369 * port: post IOCB buffers, enable appropriate host interrupt attentions,
370 * ELS ring timers, etc.
374 * Any other value - error.
377 lpfc_config_port_post(struct lpfc_hba
*phba
)
379 struct lpfc_vport
*vport
= phba
->pport
;
380 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
383 struct lpfc_dmabuf
*mp
;
384 struct lpfc_sli
*psli
= &phba
->sli
;
385 uint32_t status
, timeout
;
389 spin_lock_irq(&phba
->hbalock
);
391 * If the Config port completed correctly the HBA is not
392 * over heated any more.
394 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
395 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
396 spin_unlock_irq(&phba
->hbalock
);
398 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
400 phba
->link_state
= LPFC_HBA_ERROR
;
405 /* Get login parameters for NID. */
406 rc
= lpfc_read_sparam(phba
, pmb
, 0);
408 mempool_free(pmb
, phba
->mbox_mem_pool
);
413 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
414 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
415 "0448 Adapter failed init, mbxCmd x%x "
416 "READ_SPARM mbxStatus x%x\n",
417 mb
->mbxCommand
, mb
->mbxStatus
);
418 phba
->link_state
= LPFC_HBA_ERROR
;
419 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
420 mempool_free(pmb
, phba
->mbox_mem_pool
);
421 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
426 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
428 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
429 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
431 pmb
->context1
= NULL
;
432 lpfc_update_vport_wwn(vport
);
434 /* Update the fc_host data structures with new wwn. */
435 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
436 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
437 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
439 /* If no serial number in VPD data, use low 6 bytes of WWNN */
440 /* This should be consolidated into parse_vpd ? - mr */
441 if (phba
->SerialNumber
[0] == 0) {
444 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
445 for (i
= 0; i
< 12; i
++) {
447 j
= ((status
& 0xf0) >> 4);
449 phba
->SerialNumber
[i
] =
450 (char)((uint8_t) 0x30 + (uint8_t) j
);
452 phba
->SerialNumber
[i
] =
453 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
457 phba
->SerialNumber
[i
] =
458 (char)((uint8_t) 0x30 + (uint8_t) j
);
460 phba
->SerialNumber
[i
] =
461 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
465 lpfc_read_config(phba
, pmb
);
467 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
468 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
469 "0453 Adapter failed to init, mbxCmd x%x "
470 "READ_CONFIG, mbxStatus x%x\n",
471 mb
->mbxCommand
, mb
->mbxStatus
);
472 phba
->link_state
= LPFC_HBA_ERROR
;
473 mempool_free( pmb
, phba
->mbox_mem_pool
);
477 /* Check if the port is disabled */
478 lpfc_sli_read_link_ste(phba
);
480 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
481 i
= (mb
->un
.varRdConfig
.max_xri
+ 1);
482 if (phba
->cfg_hba_queue_depth
> i
) {
483 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
484 "3359 HBA queue depth changed from %d to %d\n",
485 phba
->cfg_hba_queue_depth
, i
);
486 phba
->cfg_hba_queue_depth
= i
;
489 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
490 i
= (mb
->un
.varRdConfig
.max_xri
>> 3);
491 if (phba
->pport
->cfg_lun_queue_depth
> i
) {
492 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
493 "3360 LUN queue depth changed from %d to %d\n",
494 phba
->pport
->cfg_lun_queue_depth
, i
);
495 phba
->pport
->cfg_lun_queue_depth
= i
;
498 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
500 /* Get the default values for Model Name and Description */
501 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
503 phba
->link_state
= LPFC_LINK_DOWN
;
505 /* Only process IOCBs on ELS ring till hba_state is READY */
506 if (psli
->sli3_ring
[LPFC_EXTRA_RING
].sli
.sli3
.cmdringaddr
)
507 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
508 if (psli
->sli3_ring
[LPFC_FCP_RING
].sli
.sli3
.cmdringaddr
)
509 psli
->sli3_ring
[LPFC_FCP_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
511 /* Post receive buffers for desired rings */
512 if (phba
->sli_rev
!= 3)
513 lpfc_post_rcv_buf(phba
);
516 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
518 if (phba
->intr_type
== MSIX
) {
519 rc
= lpfc_config_msi(phba
, pmb
);
521 mempool_free(pmb
, phba
->mbox_mem_pool
);
524 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
525 if (rc
!= MBX_SUCCESS
) {
526 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
527 "0352 Config MSI mailbox command "
528 "failed, mbxCmd x%x, mbxStatus x%x\n",
529 pmb
->u
.mb
.mbxCommand
,
530 pmb
->u
.mb
.mbxStatus
);
531 mempool_free(pmb
, phba
->mbox_mem_pool
);
536 spin_lock_irq(&phba
->hbalock
);
537 /* Initialize ERATT handling flag */
538 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
540 /* Enable appropriate host interrupts */
541 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
542 spin_unlock_irq(&phba
->hbalock
);
545 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
546 if (psli
->num_rings
> 0)
547 status
|= HC_R0INT_ENA
;
548 if (psli
->num_rings
> 1)
549 status
|= HC_R1INT_ENA
;
550 if (psli
->num_rings
> 2)
551 status
|= HC_R2INT_ENA
;
552 if (psli
->num_rings
> 3)
553 status
|= HC_R3INT_ENA
;
555 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
556 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
557 status
&= ~(HC_R0INT_ENA
);
559 writel(status
, phba
->HCregaddr
);
560 readl(phba
->HCregaddr
); /* flush */
561 spin_unlock_irq(&phba
->hbalock
);
563 /* Set up ring-0 (ELS) timer */
564 timeout
= phba
->fc_ratov
* 2;
565 mod_timer(&vport
->els_tmofunc
,
566 jiffies
+ msecs_to_jiffies(1000 * timeout
));
567 /* Set up heart beat (HB) timer */
568 mod_timer(&phba
->hb_tmofunc
,
569 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
570 phba
->hb_outstanding
= 0;
571 phba
->last_completion_time
= jiffies
;
572 /* Set up error attention (ERATT) polling timer */
573 mod_timer(&phba
->eratt_poll
,
574 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
576 if (phba
->hba_flag
& LINK_DISABLED
) {
577 lpfc_printf_log(phba
,
579 "2598 Adapter Link is disabled.\n");
580 lpfc_down_link(phba
, pmb
);
581 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
582 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
583 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
584 lpfc_printf_log(phba
,
586 "2599 Adapter failed to issue DOWN_LINK"
587 " mbox command rc 0x%x\n", rc
);
589 mempool_free(pmb
, phba
->mbox_mem_pool
);
592 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
593 mempool_free(pmb
, phba
->mbox_mem_pool
);
594 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
598 /* MBOX buffer will be freed in mbox compl */
599 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
601 phba
->link_state
= LPFC_HBA_ERROR
;
605 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
606 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
607 pmb
->vport
= phba
->pport
;
608 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
610 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
611 lpfc_printf_log(phba
,
614 "0456 Adapter failed to issue "
615 "ASYNCEVT_ENABLE mbox status x%x\n",
617 mempool_free(pmb
, phba
->mbox_mem_pool
);
620 /* Get Option rom version */
621 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
623 phba
->link_state
= LPFC_HBA_ERROR
;
627 lpfc_dump_wakeup_param(phba
, pmb
);
628 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_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_INIT
, "0435 Adapter failed "
634 "to get Option ROM version status x%x\n", rc
);
635 mempool_free(pmb
, phba
->mbox_mem_pool
);
642 * lpfc_hba_init_link - Initialize the FC link
643 * @phba: pointer to lpfc hba data structure.
644 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
646 * This routine will issue the INIT_LINK mailbox command call.
647 * It is available to other drivers through the lpfc_hba data
648 * structure for use as a delayed link up mechanism with the
649 * module parameter lpfc_suppress_link_up.
653 * Any other value - error
656 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
658 return lpfc_hba_init_link_fc_topology(phba
, phba
->cfg_topology
, flag
);
662 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
663 * @phba: pointer to lpfc hba data structure.
664 * @fc_topology: desired fc topology.
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_fc_topology(struct lpfc_hba
*phba
, uint32_t fc_topology
,
680 struct lpfc_vport
*vport
= phba
->pport
;
685 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
687 phba
->link_state
= LPFC_HBA_ERROR
;
693 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_MAX
) ||
694 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
) &&
695 !(phba
->lmt
& LMT_1Gb
)) ||
696 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
) &&
697 !(phba
->lmt
& LMT_2Gb
)) ||
698 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
) &&
699 !(phba
->lmt
& LMT_4Gb
)) ||
700 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
) &&
701 !(phba
->lmt
& LMT_8Gb
)) ||
702 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
) &&
703 !(phba
->lmt
& LMT_10Gb
)) ||
704 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
) &&
705 !(phba
->lmt
& LMT_16Gb
)) ||
706 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_32G
) &&
707 !(phba
->lmt
& LMT_32Gb
))) {
708 /* Reset link speed to auto */
709 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
710 "1302 Invalid speed for this board:%d "
711 "Reset link speed to auto.\n",
712 phba
->cfg_link_speed
);
713 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
715 lpfc_init_link(phba
, pmb
, fc_topology
, phba
->cfg_link_speed
);
716 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
717 if (phba
->sli_rev
< LPFC_SLI_REV4
)
718 lpfc_set_loopback_flag(phba
);
719 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
720 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
721 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
722 "0498 Adapter failed to init, mbxCmd x%x "
723 "INIT_LINK, mbxStatus x%x\n",
724 mb
->mbxCommand
, mb
->mbxStatus
);
725 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
726 /* Clear all interrupt enable conditions */
727 writel(0, phba
->HCregaddr
);
728 readl(phba
->HCregaddr
); /* flush */
729 /* Clear all pending interrupts */
730 writel(0xffffffff, phba
->HAregaddr
);
731 readl(phba
->HAregaddr
); /* flush */
733 phba
->link_state
= LPFC_HBA_ERROR
;
734 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
735 mempool_free(pmb
, phba
->mbox_mem_pool
);
738 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
739 if (flag
== MBX_POLL
)
740 mempool_free(pmb
, phba
->mbox_mem_pool
);
746 * lpfc_hba_down_link - this routine downs the FC link
747 * @phba: pointer to lpfc hba data structure.
748 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
750 * This routine will issue the DOWN_LINK mailbox command call.
751 * It is available to other drivers through the lpfc_hba data
752 * structure for use to stop the link.
756 * Any other value - error
759 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
764 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
766 phba
->link_state
= LPFC_HBA_ERROR
;
770 lpfc_printf_log(phba
,
772 "0491 Adapter Link is disabled.\n");
773 lpfc_down_link(phba
, pmb
);
774 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
775 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
776 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
777 lpfc_printf_log(phba
,
779 "2522 Adapter failed to issue DOWN_LINK"
780 " mbox command rc 0x%x\n", rc
);
782 mempool_free(pmb
, phba
->mbox_mem_pool
);
785 if (flag
== MBX_POLL
)
786 mempool_free(pmb
, phba
->mbox_mem_pool
);
792 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
793 * @phba: pointer to lpfc HBA data structure.
795 * This routine will do LPFC uninitialization before the HBA is reset when
796 * bringing down the SLI Layer.
800 * Any other value - error.
803 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
805 struct lpfc_vport
**vports
;
808 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
809 /* Disable interrupts */
810 writel(0, phba
->HCregaddr
);
811 readl(phba
->HCregaddr
); /* flush */
814 if (phba
->pport
->load_flag
& FC_UNLOADING
)
815 lpfc_cleanup_discovery_resources(phba
->pport
);
817 vports
= lpfc_create_vport_work_array(phba
);
819 for (i
= 0; i
<= phba
->max_vports
&&
820 vports
[i
] != NULL
; i
++)
821 lpfc_cleanup_discovery_resources(vports
[i
]);
822 lpfc_destroy_vport_work_array(phba
, vports
);
828 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
829 * rspiocb which got deferred
831 * @phba: pointer to lpfc HBA data structure.
833 * This routine will cleanup completed slow path events after HBA is reset
834 * when bringing down the SLI Layer.
841 lpfc_sli4_free_sp_events(struct lpfc_hba
*phba
)
843 struct lpfc_iocbq
*rspiocbq
;
844 struct hbq_dmabuf
*dmabuf
;
845 struct lpfc_cq_event
*cq_event
;
847 spin_lock_irq(&phba
->hbalock
);
848 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
849 spin_unlock_irq(&phba
->hbalock
);
851 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
852 /* Get the response iocb from the head of work queue */
853 spin_lock_irq(&phba
->hbalock
);
854 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
855 cq_event
, struct lpfc_cq_event
, list
);
856 spin_unlock_irq(&phba
->hbalock
);
858 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
859 case CQE_CODE_COMPL_WQE
:
860 rspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
862 lpfc_sli_release_iocbq(phba
, rspiocbq
);
864 case CQE_CODE_RECEIVE
:
865 case CQE_CODE_RECEIVE_V1
:
866 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
868 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
874 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
875 * @phba: pointer to lpfc HBA data structure.
877 * This routine will cleanup posted ELS buffers after the HBA is reset
878 * when bringing down the SLI Layer.
885 lpfc_hba_free_post_buf(struct lpfc_hba
*phba
)
887 struct lpfc_sli
*psli
= &phba
->sli
;
888 struct lpfc_sli_ring
*pring
;
889 struct lpfc_dmabuf
*mp
, *next_mp
;
893 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
894 lpfc_sli_hbqbuf_free_all(phba
);
896 /* Cleanup preposted buffers on the ELS ring */
897 pring
= &psli
->sli3_ring
[LPFC_ELS_RING
];
898 spin_lock_irq(&phba
->hbalock
);
899 list_splice_init(&pring
->postbufq
, &buflist
);
900 spin_unlock_irq(&phba
->hbalock
);
903 list_for_each_entry_safe(mp
, next_mp
, &buflist
, list
) {
906 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
910 spin_lock_irq(&phba
->hbalock
);
911 pring
->postbufq_cnt
-= count
;
912 spin_unlock_irq(&phba
->hbalock
);
917 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
918 * @phba: pointer to lpfc HBA data structure.
920 * This routine will cleanup the txcmplq after the HBA is reset when bringing
921 * down the SLI Layer.
927 lpfc_hba_clean_txcmplq(struct lpfc_hba
*phba
)
929 struct lpfc_sli
*psli
= &phba
->sli
;
930 struct lpfc_queue
*qp
= NULL
;
931 struct lpfc_sli_ring
*pring
;
932 LIST_HEAD(completions
);
935 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
936 for (i
= 0; i
< psli
->num_rings
; i
++) {
937 pring
= &psli
->sli3_ring
[i
];
938 spin_lock_irq(&phba
->hbalock
);
939 /* At this point in time the HBA is either reset or DOA
940 * Nothing should be on txcmplq as it will
943 list_splice_init(&pring
->txcmplq
, &completions
);
944 pring
->txcmplq_cnt
= 0;
945 spin_unlock_irq(&phba
->hbalock
);
947 lpfc_sli_abort_iocb_ring(phba
, pring
);
949 /* Cancel all the IOCBs from the completions list */
950 lpfc_sli_cancel_iocbs(phba
, &completions
,
951 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
954 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
958 spin_lock_irq(&pring
->ring_lock
);
959 list_splice_init(&pring
->txcmplq
, &completions
);
960 pring
->txcmplq_cnt
= 0;
961 spin_unlock_irq(&pring
->ring_lock
);
962 lpfc_sli_abort_iocb_ring(phba
, pring
);
964 /* Cancel all the IOCBs from the completions list */
965 lpfc_sli_cancel_iocbs(phba
, &completions
,
966 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
970 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
972 * @phba: pointer to lpfc HBA data structure.
974 * This routine will do uninitialization after the HBA is reset when bring
975 * down the SLI Layer.
979 * Any other value - error.
982 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
984 lpfc_hba_free_post_buf(phba
);
985 lpfc_hba_clean_txcmplq(phba
);
990 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
991 * @phba: pointer to lpfc HBA data structure.
993 * This routine will do uninitialization after the HBA is reset when bring
994 * down the SLI Layer.
998 * Any other value - error.
1001 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
1003 struct lpfc_scsi_buf
*psb
, *psb_next
;
1005 LIST_HEAD(nvme_aborts
);
1006 unsigned long iflag
= 0;
1007 struct lpfc_sglq
*sglq_entry
= NULL
;
1010 lpfc_sli_hbqbuf_free_all(phba
);
1011 lpfc_hba_clean_txcmplq(phba
);
1013 /* At this point in time the HBA is either reset or DOA. Either
1014 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1015 * on the lpfc_els_sgl_list so that it can either be freed if the
1016 * driver is unloading or reposted if the driver is restarting
1019 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_els_sgl_list and */
1021 /* sgl_list_lock required because worker thread uses this
1024 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
1025 list_for_each_entry(sglq_entry
,
1026 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
1027 sglq_entry
->state
= SGL_FREED
;
1028 list_for_each_entry(sglq_entry
,
1029 &phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
, list
)
1030 sglq_entry
->state
= SGL_FREED
;
1032 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
1033 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1035 if (phba
->sli4_hba
.nvme_wq
)
1036 list_splice_init(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
,
1037 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
1039 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
1040 /* abts_scsi_buf_list_lock required because worker thread uses this
1043 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
1044 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
1045 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
1047 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
1050 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
1051 spin_lock(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
1052 list_splice_init(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
,
1054 spin_unlock(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
1057 spin_unlock_irq(&phba
->hbalock
);
1059 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
1061 psb
->status
= IOSTAT_SUCCESS
;
1063 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
1064 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list_put
);
1065 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
1067 list_for_each_entry_safe(psb
, psb_next
, &nvme_aborts
, list
) {
1069 psb
->status
= IOSTAT_SUCCESS
;
1071 spin_lock_irqsave(&phba
->nvme_buf_list_put_lock
, iflag
);
1072 list_splice(&nvme_aborts
, &phba
->lpfc_nvme_buf_list_put
);
1073 spin_unlock_irqrestore(&phba
->nvme_buf_list_put_lock
, iflag
);
1075 lpfc_sli4_free_sp_events(phba
);
1080 * lpfc_hba_down_post - Wrapper func for hba down post routine
1081 * @phba: pointer to lpfc HBA data structure.
1083 * This routine wraps the actual SLI3 or SLI4 routine for performing
1084 * uninitialization after the HBA is reset when bring down the SLI Layer.
1088 * Any other value - error.
1091 lpfc_hba_down_post(struct lpfc_hba
*phba
)
1093 return (*phba
->lpfc_hba_down_post
)(phba
);
1097 * lpfc_hb_timeout - The HBA-timer timeout handler
1098 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1100 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1101 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1102 * work-port-events bitmap and the worker thread is notified. This timeout
1103 * event will be used by the worker thread to invoke the actual timeout
1104 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1105 * be performed in the timeout handler and the HBA timeout event bit shall
1106 * be cleared by the worker thread after it has taken the event bitmap out.
1109 lpfc_hb_timeout(unsigned long ptr
)
1111 struct lpfc_hba
*phba
;
1112 uint32_t tmo_posted
;
1113 unsigned long iflag
;
1115 phba
= (struct lpfc_hba
*)ptr
;
1117 /* Check for heart beat timeout conditions */
1118 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1119 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
1121 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
1122 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1124 /* Tell the worker thread there is work to do */
1126 lpfc_worker_wake_up(phba
);
1131 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1132 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1134 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1135 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1136 * work-port-events bitmap and the worker thread is notified. This timeout
1137 * event will be used by the worker thread to invoke the actual timeout
1138 * handler routine, lpfc_rrq_handler. Any periodical operations will
1139 * be performed in the timeout handler and the RRQ timeout event bit shall
1140 * be cleared by the worker thread after it has taken the event bitmap out.
1143 lpfc_rrq_timeout(unsigned long ptr
)
1145 struct lpfc_hba
*phba
;
1146 unsigned long iflag
;
1148 phba
= (struct lpfc_hba
*)ptr
;
1149 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1150 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1151 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
1153 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
1154 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1156 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1157 lpfc_worker_wake_up(phba
);
1161 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1162 * @phba: pointer to lpfc hba data structure.
1163 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1165 * This is the callback function to the lpfc heart-beat mailbox command.
1166 * If configured, the lpfc driver issues the heart-beat mailbox command to
1167 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1168 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1169 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1170 * heart-beat outstanding state. Once the mailbox command comes back and
1171 * no error conditions detected, the heart-beat mailbox command timer is
1172 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1173 * state is cleared for the next heart-beat. If the timer expired with the
1174 * heart-beat outstanding state set, the driver will put the HBA offline.
1177 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1179 unsigned long drvr_flag
;
1181 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1182 phba
->hb_outstanding
= 0;
1183 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1185 /* Check and reset heart-beat timer is necessary */
1186 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1187 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1188 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1189 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1190 mod_timer(&phba
->hb_tmofunc
,
1192 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1197 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1198 * @phba: pointer to lpfc hba data structure.
1200 * This is the actual HBA-timer timeout handler to be invoked by the worker
1201 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1202 * handler performs any periodic operations needed for the device. If such
1203 * periodic event has already been attended to either in the interrupt handler
1204 * or by processing slow-ring or fast-ring events within the HBA-timer
1205 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1206 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1207 * is configured and there is no heart-beat mailbox command outstanding, a
1208 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1209 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1213 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1215 struct lpfc_vport
**vports
;
1216 LPFC_MBOXQ_t
*pmboxq
;
1217 struct lpfc_dmabuf
*buf_ptr
;
1219 struct lpfc_sli
*psli
= &phba
->sli
;
1220 LIST_HEAD(completions
);
1222 vports
= lpfc_create_vport_work_array(phba
);
1224 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
1225 lpfc_rcv_seq_check_edtov(vports
[i
]);
1226 lpfc_fdmi_num_disc_check(vports
[i
]);
1228 lpfc_destroy_vport_work_array(phba
, vports
);
1230 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1231 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1232 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1235 spin_lock_irq(&phba
->pport
->work_port_lock
);
1237 if (time_after(phba
->last_completion_time
+
1238 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
),
1240 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1241 if (!phba
->hb_outstanding
)
1242 mod_timer(&phba
->hb_tmofunc
,
1244 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1246 mod_timer(&phba
->hb_tmofunc
,
1248 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1251 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1253 if (phba
->elsbuf_cnt
&&
1254 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1255 spin_lock_irq(&phba
->hbalock
);
1256 list_splice_init(&phba
->elsbuf
, &completions
);
1257 phba
->elsbuf_cnt
= 0;
1258 phba
->elsbuf_prev_cnt
= 0;
1259 spin_unlock_irq(&phba
->hbalock
);
1261 while (!list_empty(&completions
)) {
1262 list_remove_head(&completions
, buf_ptr
,
1263 struct lpfc_dmabuf
, list
);
1264 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1268 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1270 /* If there is no heart beat outstanding, issue a heartbeat command */
1271 if (phba
->cfg_enable_hba_heartbeat
) {
1272 if (!phba
->hb_outstanding
) {
1273 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1274 (list_empty(&psli
->mboxq
))) {
1275 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1278 mod_timer(&phba
->hb_tmofunc
,
1280 msecs_to_jiffies(1000 *
1281 LPFC_HB_MBOX_INTERVAL
));
1285 lpfc_heart_beat(phba
, pmboxq
);
1286 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1287 pmboxq
->vport
= phba
->pport
;
1288 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1291 if (retval
!= MBX_BUSY
&&
1292 retval
!= MBX_SUCCESS
) {
1293 mempool_free(pmboxq
,
1294 phba
->mbox_mem_pool
);
1295 mod_timer(&phba
->hb_tmofunc
,
1297 msecs_to_jiffies(1000 *
1298 LPFC_HB_MBOX_INTERVAL
));
1301 phba
->skipped_hb
= 0;
1302 phba
->hb_outstanding
= 1;
1303 } else if (time_before_eq(phba
->last_completion_time
,
1304 phba
->skipped_hb
)) {
1305 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1306 "2857 Last completion time not "
1307 " updated in %d ms\n",
1308 jiffies_to_msecs(jiffies
1309 - phba
->last_completion_time
));
1311 phba
->skipped_hb
= jiffies
;
1313 mod_timer(&phba
->hb_tmofunc
,
1315 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1319 * If heart beat timeout called with hb_outstanding set
1320 * we need to give the hb mailbox cmd a chance to
1323 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1324 "0459 Adapter heartbeat still out"
1325 "standing:last compl time was %d ms.\n",
1326 jiffies_to_msecs(jiffies
1327 - phba
->last_completion_time
));
1328 mod_timer(&phba
->hb_tmofunc
,
1330 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1333 mod_timer(&phba
->hb_tmofunc
,
1335 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1340 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1341 * @phba: pointer to lpfc hba data structure.
1343 * This routine is called to bring the HBA offline when HBA hardware error
1344 * other than Port Error 6 has been detected.
1347 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1349 struct lpfc_sli
*psli
= &phba
->sli
;
1351 spin_lock_irq(&phba
->hbalock
);
1352 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1353 spin_unlock_irq(&phba
->hbalock
);
1354 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1357 lpfc_reset_barrier(phba
);
1358 spin_lock_irq(&phba
->hbalock
);
1359 lpfc_sli_brdreset(phba
);
1360 spin_unlock_irq(&phba
->hbalock
);
1361 lpfc_hba_down_post(phba
);
1362 lpfc_sli_brdready(phba
, HS_MBRDY
);
1363 lpfc_unblock_mgmt_io(phba
);
1364 phba
->link_state
= LPFC_HBA_ERROR
;
1369 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1370 * @phba: pointer to lpfc hba data structure.
1372 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1373 * other than Port Error 6 has been detected.
1376 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1378 spin_lock_irq(&phba
->hbalock
);
1379 phba
->link_state
= LPFC_HBA_ERROR
;
1380 spin_unlock_irq(&phba
->hbalock
);
1382 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1384 lpfc_hba_down_post(phba
);
1385 lpfc_unblock_mgmt_io(phba
);
1389 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1390 * @phba: pointer to lpfc hba data structure.
1392 * This routine is invoked to handle the deferred HBA hardware error
1393 * conditions. This type of error is indicated by HBA by setting ER1
1394 * and another ER bit in the host status register. The driver will
1395 * wait until the ER1 bit clears before handling the error condition.
1398 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1400 uint32_t old_host_status
= phba
->work_hs
;
1401 struct lpfc_sli
*psli
= &phba
->sli
;
1403 /* If the pci channel is offline, ignore possible errors,
1404 * since we cannot communicate with the pci card anyway.
1406 if (pci_channel_offline(phba
->pcidev
)) {
1407 spin_lock_irq(&phba
->hbalock
);
1408 phba
->hba_flag
&= ~DEFER_ERATT
;
1409 spin_unlock_irq(&phba
->hbalock
);
1413 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1414 "0479 Deferred Adapter Hardware Error "
1415 "Data: x%x x%x x%x\n",
1417 phba
->work_status
[0], phba
->work_status
[1]);
1419 spin_lock_irq(&phba
->hbalock
);
1420 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1421 spin_unlock_irq(&phba
->hbalock
);
1425 * Firmware stops when it triggred erratt. That could cause the I/Os
1426 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1427 * SCSI layer retry it after re-establishing link.
1429 lpfc_sli_abort_fcp_rings(phba
);
1432 * There was a firmware error. Take the hba offline and then
1433 * attempt to restart it.
1435 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
1438 /* Wait for the ER1 bit to clear.*/
1439 while (phba
->work_hs
& HS_FFER1
) {
1441 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1442 phba
->work_hs
= UNPLUG_ERR
;
1445 /* If driver is unloading let the worker thread continue */
1446 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1453 * This is to ptrotect against a race condition in which
1454 * first write to the host attention register clear the
1455 * host status register.
1457 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1458 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1460 spin_lock_irq(&phba
->hbalock
);
1461 phba
->hba_flag
&= ~DEFER_ERATT
;
1462 spin_unlock_irq(&phba
->hbalock
);
1463 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1464 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1468 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1470 struct lpfc_board_event_header board_event
;
1471 struct Scsi_Host
*shost
;
1473 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1474 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1475 shost
= lpfc_shost_from_vport(phba
->pport
);
1476 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1477 sizeof(board_event
),
1478 (char *) &board_event
,
1483 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1484 * @phba: pointer to lpfc hba data structure.
1486 * This routine is invoked to handle the following HBA hardware error
1488 * 1 - HBA error attention interrupt
1489 * 2 - DMA ring index out of range
1490 * 3 - Mailbox command came back as unknown
1493 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1495 struct lpfc_vport
*vport
= phba
->pport
;
1496 struct lpfc_sli
*psli
= &phba
->sli
;
1497 uint32_t event_data
;
1498 unsigned long temperature
;
1499 struct temp_event temp_event_data
;
1500 struct Scsi_Host
*shost
;
1502 /* If the pci channel is offline, ignore possible errors,
1503 * since we cannot communicate with the pci card anyway.
1505 if (pci_channel_offline(phba
->pcidev
)) {
1506 spin_lock_irq(&phba
->hbalock
);
1507 phba
->hba_flag
&= ~DEFER_ERATT
;
1508 spin_unlock_irq(&phba
->hbalock
);
1512 /* If resets are disabled then leave the HBA alone and return */
1513 if (!phba
->cfg_enable_hba_reset
)
1516 /* Send an internal error event to mgmt application */
1517 lpfc_board_errevt_to_mgmt(phba
);
1519 if (phba
->hba_flag
& DEFER_ERATT
)
1520 lpfc_handle_deferred_eratt(phba
);
1522 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1523 if (phba
->work_hs
& HS_FFER6
)
1524 /* Re-establishing Link */
1525 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1526 "1301 Re-establishing Link "
1527 "Data: x%x x%x x%x\n",
1528 phba
->work_hs
, phba
->work_status
[0],
1529 phba
->work_status
[1]);
1530 if (phba
->work_hs
& HS_FFER8
)
1531 /* Device Zeroization */
1532 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1533 "2861 Host Authentication device "
1534 "zeroization Data:x%x x%x x%x\n",
1535 phba
->work_hs
, phba
->work_status
[0],
1536 phba
->work_status
[1]);
1538 spin_lock_irq(&phba
->hbalock
);
1539 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1540 spin_unlock_irq(&phba
->hbalock
);
1543 * Firmware stops when it triggled erratt with HS_FFER6.
1544 * That could cause the I/Os dropped by the firmware.
1545 * Error iocb (I/O) on txcmplq and let the SCSI layer
1546 * retry it after re-establishing link.
1548 lpfc_sli_abort_fcp_rings(phba
);
1551 * There was a firmware error. Take the hba offline and then
1552 * attempt to restart it.
1554 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1556 lpfc_sli_brdrestart(phba
);
1557 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1558 lpfc_unblock_mgmt_io(phba
);
1561 lpfc_unblock_mgmt_io(phba
);
1562 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1563 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1564 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1565 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1566 temp_event_data
.data
= (uint32_t)temperature
;
1568 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1569 "0406 Adapter maximum temperature exceeded "
1570 "(%ld), taking this port offline "
1571 "Data: x%x x%x x%x\n",
1572 temperature
, phba
->work_hs
,
1573 phba
->work_status
[0], phba
->work_status
[1]);
1575 shost
= lpfc_shost_from_vport(phba
->pport
);
1576 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1577 sizeof(temp_event_data
),
1578 (char *) &temp_event_data
,
1579 SCSI_NL_VID_TYPE_PCI
1580 | PCI_VENDOR_ID_EMULEX
);
1582 spin_lock_irq(&phba
->hbalock
);
1583 phba
->over_temp_state
= HBA_OVER_TEMP
;
1584 spin_unlock_irq(&phba
->hbalock
);
1585 lpfc_offline_eratt(phba
);
1588 /* The if clause above forces this code path when the status
1589 * failure is a value other than FFER6. Do not call the offline
1590 * twice. This is the adapter hardware error path.
1592 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1593 "0457 Adapter Hardware Error "
1594 "Data: x%x x%x x%x\n",
1596 phba
->work_status
[0], phba
->work_status
[1]);
1598 event_data
= FC_REG_DUMP_EVENT
;
1599 shost
= lpfc_shost_from_vport(vport
);
1600 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1601 sizeof(event_data
), (char *) &event_data
,
1602 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1604 lpfc_offline_eratt(phba
);
1610 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1611 * @phba: pointer to lpfc hba data structure.
1612 * @mbx_action: flag for mailbox shutdown action.
1614 * This routine is invoked to perform an SLI4 port PCI function reset in
1615 * response to port status register polling attention. It waits for port
1616 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1617 * During this process, interrupt vectors are freed and later requested
1618 * for handling possible port resource change.
1621 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba
*phba
, int mbx_action
,
1627 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1628 LPFC_SLI_INTF_IF_TYPE_2
) {
1630 * On error status condition, driver need to wait for port
1631 * ready before performing reset.
1633 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1638 /* need reset: attempt for port recovery */
1640 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1641 "2887 Reset Needed: Attempting Port "
1643 lpfc_offline_prep(phba
, mbx_action
);
1645 /* release interrupt for possible resource change */
1646 lpfc_sli4_disable_intr(phba
);
1647 lpfc_sli_brdrestart(phba
);
1648 /* request and enable interrupt */
1649 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
1650 if (intr_mode
== LPFC_INTR_ERROR
) {
1651 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1652 "3175 Failed to enable interrupt\n");
1655 phba
->intr_mode
= intr_mode
;
1656 rc
= lpfc_online(phba
);
1658 lpfc_unblock_mgmt_io(phba
);
1664 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1665 * @phba: pointer to lpfc hba data structure.
1667 * This routine is invoked to handle the SLI4 HBA hardware error attention
1671 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1673 struct lpfc_vport
*vport
= phba
->pport
;
1674 uint32_t event_data
;
1675 struct Scsi_Host
*shost
;
1677 struct lpfc_register portstat_reg
= {0};
1678 uint32_t reg_err1
, reg_err2
;
1679 uint32_t uerrlo_reg
, uemasklo_reg
;
1680 uint32_t smphr_port_status
= 0, pci_rd_rc1
, pci_rd_rc2
;
1681 bool en_rn_msg
= true;
1682 struct temp_event temp_event_data
;
1683 struct lpfc_register portsmphr_reg
;
1686 /* If the pci channel is offline, ignore possible errors, since
1687 * we cannot communicate with the pci card anyway.
1689 if (pci_channel_offline(phba
->pcidev
))
1692 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
1693 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1695 case LPFC_SLI_INTF_IF_TYPE_0
:
1696 pci_rd_rc1
= lpfc_readl(
1697 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
1699 pci_rd_rc2
= lpfc_readl(
1700 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
,
1702 /* consider PCI bus read error as pci_channel_offline */
1703 if (pci_rd_rc1
== -EIO
&& pci_rd_rc2
== -EIO
)
1705 if (!(phba
->hba_flag
& HBA_RECOVERABLE_UE
)) {
1706 lpfc_sli4_offline_eratt(phba
);
1709 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1710 "7623 Checking UE recoverable");
1712 for (i
= 0; i
< phba
->sli4_hba
.ue_to_sr
/ 1000; i
++) {
1713 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1714 &portsmphr_reg
.word0
))
1717 smphr_port_status
= bf_get(lpfc_port_smphr_port_status
,
1719 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1720 LPFC_PORT_SEM_UE_RECOVERABLE
)
1722 /*Sleep for 1Sec, before checking SEMAPHORE */
1726 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1727 "4827 smphr_port_status x%x : Waited %dSec",
1728 smphr_port_status
, i
);
1730 /* Recoverable UE, reset the HBA device */
1731 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1732 LPFC_PORT_SEM_UE_RECOVERABLE
) {
1733 for (i
= 0; i
< 20; i
++) {
1735 if (!lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1736 &portsmphr_reg
.word0
) &&
1737 (LPFC_POST_STAGE_PORT_READY
==
1738 bf_get(lpfc_port_smphr_port_status
,
1740 rc
= lpfc_sli4_port_sta_fn_reset(phba
,
1741 LPFC_MBX_NO_WAIT
, en_rn_msg
);
1744 lpfc_printf_log(phba
,
1746 "4215 Failed to recover UE");
1751 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1752 "7624 Firmware not ready: Failing UE recovery,"
1753 " waited %dSec", i
);
1754 lpfc_sli4_offline_eratt(phba
);
1757 case LPFC_SLI_INTF_IF_TYPE_2
:
1758 pci_rd_rc1
= lpfc_readl(
1759 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1760 &portstat_reg
.word0
);
1761 /* consider PCI bus read error as pci_channel_offline */
1762 if (pci_rd_rc1
== -EIO
) {
1763 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1764 "3151 PCI bus read access failure: x%x\n",
1765 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
));
1768 reg_err1
= readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
1769 reg_err2
= readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
1770 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1771 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1772 "2889 Port Overtemperature event, "
1773 "taking port offline Data: x%x x%x\n",
1774 reg_err1
, reg_err2
);
1776 phba
->sfp_alarm
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
1777 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1778 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1779 temp_event_data
.data
= 0xFFFFFFFF;
1781 shost
= lpfc_shost_from_vport(phba
->pport
);
1782 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1783 sizeof(temp_event_data
),
1784 (char *)&temp_event_data
,
1785 SCSI_NL_VID_TYPE_PCI
1786 | PCI_VENDOR_ID_EMULEX
);
1788 spin_lock_irq(&phba
->hbalock
);
1789 phba
->over_temp_state
= HBA_OVER_TEMP
;
1790 spin_unlock_irq(&phba
->hbalock
);
1791 lpfc_sli4_offline_eratt(phba
);
1794 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1795 reg_err2
== SLIPORT_ERR2_REG_FW_RESTART
) {
1796 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1797 "3143 Port Down: Firmware Update "
1800 } else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1801 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1802 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1803 "3144 Port Down: Debug Dump\n");
1804 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1805 reg_err2
== SLIPORT_ERR2_REG_FUNC_PROVISON
)
1806 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1807 "3145 Port Down: Provisioning\n");
1809 /* If resets are disabled then leave the HBA alone and return */
1810 if (!phba
->cfg_enable_hba_reset
)
1813 /* Check port status register for function reset */
1814 rc
= lpfc_sli4_port_sta_fn_reset(phba
, LPFC_MBX_NO_WAIT
,
1817 /* don't report event on forced debug dump */
1818 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1819 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1824 /* fall through for not able to recover */
1825 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1826 "3152 Unrecoverable error, bring the port "
1828 lpfc_sli4_offline_eratt(phba
);
1830 case LPFC_SLI_INTF_IF_TYPE_1
:
1834 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1835 "3123 Report dump event to upper layer\n");
1836 /* Send an internal error event to mgmt application */
1837 lpfc_board_errevt_to_mgmt(phba
);
1839 event_data
= FC_REG_DUMP_EVENT
;
1840 shost
= lpfc_shost_from_vport(vport
);
1841 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1842 sizeof(event_data
), (char *) &event_data
,
1843 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1847 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1848 * @phba: pointer to lpfc HBA data structure.
1850 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1851 * routine from the API jump table function pointer from the lpfc_hba struct.
1855 * Any other value - error.
1858 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1860 (*phba
->lpfc_handle_eratt
)(phba
);
1864 * lpfc_handle_latt - The HBA link event handler
1865 * @phba: pointer to lpfc hba data structure.
1867 * This routine is invoked from the worker thread to handle a HBA host
1868 * attention link event. SLI3 only.
1871 lpfc_handle_latt(struct lpfc_hba
*phba
)
1873 struct lpfc_vport
*vport
= phba
->pport
;
1874 struct lpfc_sli
*psli
= &phba
->sli
;
1876 volatile uint32_t control
;
1877 struct lpfc_dmabuf
*mp
;
1880 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1883 goto lpfc_handle_latt_err_exit
;
1886 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1889 goto lpfc_handle_latt_free_pmb
;
1892 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1895 goto lpfc_handle_latt_free_mp
;
1898 /* Cleanup any outstanding ELS commands */
1899 lpfc_els_flush_all_cmd(phba
);
1901 psli
->slistat
.link_event
++;
1902 lpfc_read_topology(phba
, pmb
, mp
);
1903 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
1905 /* Block ELS IOCBs until we have processed this mbox command */
1906 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1907 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1908 if (rc
== MBX_NOT_FINISHED
) {
1910 goto lpfc_handle_latt_free_mbuf
;
1913 /* Clear Link Attention in HA REG */
1914 spin_lock_irq(&phba
->hbalock
);
1915 writel(HA_LATT
, phba
->HAregaddr
);
1916 readl(phba
->HAregaddr
); /* flush */
1917 spin_unlock_irq(&phba
->hbalock
);
1921 lpfc_handle_latt_free_mbuf
:
1922 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1923 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1924 lpfc_handle_latt_free_mp
:
1926 lpfc_handle_latt_free_pmb
:
1927 mempool_free(pmb
, phba
->mbox_mem_pool
);
1928 lpfc_handle_latt_err_exit
:
1929 /* Enable Link attention interrupts */
1930 spin_lock_irq(&phba
->hbalock
);
1931 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1932 control
= readl(phba
->HCregaddr
);
1933 control
|= HC_LAINT_ENA
;
1934 writel(control
, phba
->HCregaddr
);
1935 readl(phba
->HCregaddr
); /* flush */
1937 /* Clear Link Attention in HA REG */
1938 writel(HA_LATT
, phba
->HAregaddr
);
1939 readl(phba
->HAregaddr
); /* flush */
1940 spin_unlock_irq(&phba
->hbalock
);
1941 lpfc_linkdown(phba
);
1942 phba
->link_state
= LPFC_HBA_ERROR
;
1944 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1945 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1951 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1952 * @phba: pointer to lpfc hba data structure.
1953 * @vpd: pointer to the vital product data.
1954 * @len: length of the vital product data in bytes.
1956 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1957 * an array of characters. In this routine, the ModelName, ProgramType, and
1958 * ModelDesc, etc. fields of the phba data structure will be populated.
1961 * 0 - pointer to the VPD passed in is NULL
1965 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1967 uint8_t lenlo
, lenhi
;
1977 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1978 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1979 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1981 while (!finished
&& (index
< (len
- 4))) {
1982 switch (vpd
[index
]) {
1990 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1999 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
2000 if (Length
> len
- index
)
2001 Length
= len
- index
;
2002 while (Length
> 0) {
2003 /* Look for Serial Number */
2004 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
2011 phba
->SerialNumber
[j
++] = vpd
[index
++];
2015 phba
->SerialNumber
[j
] = 0;
2018 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
2019 phba
->vpd_flag
|= VPD_MODEL_DESC
;
2026 phba
->ModelDesc
[j
++] = vpd
[index
++];
2030 phba
->ModelDesc
[j
] = 0;
2033 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
2034 phba
->vpd_flag
|= VPD_MODEL_NAME
;
2041 phba
->ModelName
[j
++] = vpd
[index
++];
2045 phba
->ModelName
[j
] = 0;
2048 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
2049 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
2056 phba
->ProgramType
[j
++] = vpd
[index
++];
2060 phba
->ProgramType
[j
] = 0;
2063 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
2064 phba
->vpd_flag
|= VPD_PORT
;
2071 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
2072 (phba
->sli4_hba
.pport_name_sta
==
2073 LPFC_SLI4_PPNAME_GET
)) {
2077 phba
->Port
[j
++] = vpd
[index
++];
2081 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
2082 (phba
->sli4_hba
.pport_name_sta
==
2083 LPFC_SLI4_PPNAME_NON
))
2110 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2111 * @phba: pointer to lpfc hba data structure.
2112 * @mdp: pointer to the data structure to hold the derived model name.
2113 * @descp: pointer to the data structure to hold the derived description.
2115 * This routine retrieves HBA's description based on its registered PCI device
2116 * ID. The @descp passed into this function points to an array of 256 chars. It
2117 * shall be returned with the model name, maximum speed, and the host bus type.
2118 * The @mdp passed into this function points to an array of 80 chars. When the
2119 * function returns, the @mdp will be filled with the model name.
2122 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
2125 uint16_t dev_id
= phba
->pcidev
->device
;
2128 int oneConnect
= 0; /* default is not a oneConnect */
2133 } m
= {"<Unknown>", "", ""};
2135 if (mdp
&& mdp
[0] != '\0'
2136 && descp
&& descp
[0] != '\0')
2139 if (phba
->lmt
& LMT_32Gb
)
2141 else if (phba
->lmt
& LMT_16Gb
)
2143 else if (phba
->lmt
& LMT_10Gb
)
2145 else if (phba
->lmt
& LMT_8Gb
)
2147 else if (phba
->lmt
& LMT_4Gb
)
2149 else if (phba
->lmt
& LMT_2Gb
)
2151 else if (phba
->lmt
& LMT_1Gb
)
2159 case PCI_DEVICE_ID_FIREFLY
:
2160 m
= (typeof(m
)){"LP6000", "PCI",
2161 "Obsolete, Unsupported Fibre Channel Adapter"};
2163 case PCI_DEVICE_ID_SUPERFLY
:
2164 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
2165 m
= (typeof(m
)){"LP7000", "PCI", ""};
2167 m
= (typeof(m
)){"LP7000E", "PCI", ""};
2168 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2170 case PCI_DEVICE_ID_DRAGONFLY
:
2171 m
= (typeof(m
)){"LP8000", "PCI",
2172 "Obsolete, Unsupported Fibre Channel Adapter"};
2174 case PCI_DEVICE_ID_CENTAUR
:
2175 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
2176 m
= (typeof(m
)){"LP9002", "PCI", ""};
2178 m
= (typeof(m
)){"LP9000", "PCI", ""};
2179 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2181 case PCI_DEVICE_ID_RFLY
:
2182 m
= (typeof(m
)){"LP952", "PCI",
2183 "Obsolete, Unsupported Fibre Channel Adapter"};
2185 case PCI_DEVICE_ID_PEGASUS
:
2186 m
= (typeof(m
)){"LP9802", "PCI-X",
2187 "Obsolete, Unsupported Fibre Channel Adapter"};
2189 case PCI_DEVICE_ID_THOR
:
2190 m
= (typeof(m
)){"LP10000", "PCI-X",
2191 "Obsolete, Unsupported Fibre Channel Adapter"};
2193 case PCI_DEVICE_ID_VIPER
:
2194 m
= (typeof(m
)){"LPX1000", "PCI-X",
2195 "Obsolete, Unsupported Fibre Channel Adapter"};
2197 case PCI_DEVICE_ID_PFLY
:
2198 m
= (typeof(m
)){"LP982", "PCI-X",
2199 "Obsolete, Unsupported Fibre Channel Adapter"};
2201 case PCI_DEVICE_ID_TFLY
:
2202 m
= (typeof(m
)){"LP1050", "PCI-X",
2203 "Obsolete, Unsupported Fibre Channel Adapter"};
2205 case PCI_DEVICE_ID_HELIOS
:
2206 m
= (typeof(m
)){"LP11000", "PCI-X2",
2207 "Obsolete, Unsupported Fibre Channel Adapter"};
2209 case PCI_DEVICE_ID_HELIOS_SCSP
:
2210 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
2211 "Obsolete, Unsupported Fibre Channel Adapter"};
2213 case PCI_DEVICE_ID_HELIOS_DCSP
:
2214 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
2215 "Obsolete, Unsupported Fibre Channel Adapter"};
2217 case PCI_DEVICE_ID_NEPTUNE
:
2218 m
= (typeof(m
)){"LPe1000", "PCIe",
2219 "Obsolete, Unsupported Fibre Channel Adapter"};
2221 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
2222 m
= (typeof(m
)){"LPe1000-SP", "PCIe",
2223 "Obsolete, Unsupported Fibre Channel Adapter"};
2225 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
2226 m
= (typeof(m
)){"LPe1002-SP", "PCIe",
2227 "Obsolete, Unsupported Fibre Channel Adapter"};
2229 case PCI_DEVICE_ID_BMID
:
2230 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2232 case PCI_DEVICE_ID_BSMB
:
2233 m
= (typeof(m
)){"LP111", "PCI-X2",
2234 "Obsolete, Unsupported Fibre Channel Adapter"};
2236 case PCI_DEVICE_ID_ZEPHYR
:
2237 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2239 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
2240 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2242 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
2243 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
2246 case PCI_DEVICE_ID_ZMID
:
2247 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2249 case PCI_DEVICE_ID_ZSMB
:
2250 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2252 case PCI_DEVICE_ID_LP101
:
2253 m
= (typeof(m
)){"LP101", "PCI-X",
2254 "Obsolete, Unsupported Fibre Channel Adapter"};
2256 case PCI_DEVICE_ID_LP10000S
:
2257 m
= (typeof(m
)){"LP10000-S", "PCI",
2258 "Obsolete, Unsupported Fibre Channel Adapter"};
2260 case PCI_DEVICE_ID_LP11000S
:
2261 m
= (typeof(m
)){"LP11000-S", "PCI-X2",
2262 "Obsolete, Unsupported Fibre Channel Adapter"};
2264 case PCI_DEVICE_ID_LPE11000S
:
2265 m
= (typeof(m
)){"LPe11000-S", "PCIe",
2266 "Obsolete, Unsupported Fibre Channel Adapter"};
2268 case PCI_DEVICE_ID_SAT
:
2269 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2271 case PCI_DEVICE_ID_SAT_MID
:
2272 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2274 case PCI_DEVICE_ID_SAT_SMB
:
2275 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2277 case PCI_DEVICE_ID_SAT_DCSP
:
2278 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2280 case PCI_DEVICE_ID_SAT_SCSP
:
2281 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2283 case PCI_DEVICE_ID_SAT_S
:
2284 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2286 case PCI_DEVICE_ID_HORNET
:
2287 m
= (typeof(m
)){"LP21000", "PCIe",
2288 "Obsolete, Unsupported FCoE Adapter"};
2291 case PCI_DEVICE_ID_PROTEUS_VF
:
2292 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2293 "Obsolete, Unsupported Fibre Channel Adapter"};
2295 case PCI_DEVICE_ID_PROTEUS_PF
:
2296 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2297 "Obsolete, Unsupported Fibre Channel Adapter"};
2299 case PCI_DEVICE_ID_PROTEUS_S
:
2300 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2301 "Obsolete, Unsupported Fibre Channel Adapter"};
2303 case PCI_DEVICE_ID_TIGERSHARK
:
2305 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2307 case PCI_DEVICE_ID_TOMCAT
:
2309 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2311 case PCI_DEVICE_ID_FALCON
:
2312 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2313 "EmulexSecure Fibre"};
2315 case PCI_DEVICE_ID_BALIUS
:
2316 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2317 "Obsolete, Unsupported Fibre Channel Adapter"};
2319 case PCI_DEVICE_ID_LANCER_FC
:
2320 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2322 case PCI_DEVICE_ID_LANCER_FC_VF
:
2323 m
= (typeof(m
)){"LPe16000", "PCIe",
2324 "Obsolete, Unsupported Fibre Channel Adapter"};
2326 case PCI_DEVICE_ID_LANCER_FCOE
:
2328 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2330 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2332 m
= (typeof(m
)){"OCe15100", "PCIe",
2333 "Obsolete, Unsupported FCoE"};
2335 case PCI_DEVICE_ID_LANCER_G6_FC
:
2336 m
= (typeof(m
)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2338 case PCI_DEVICE_ID_SKYHAWK
:
2339 case PCI_DEVICE_ID_SKYHAWK_VF
:
2341 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2344 m
= (typeof(m
)){"Unknown", "", ""};
2348 if (mdp
&& mdp
[0] == '\0')
2349 snprintf(mdp
, 79,"%s", m
.name
);
2351 * oneConnect hba requires special processing, they are all initiators
2352 * and we put the port number on the end
2354 if (descp
&& descp
[0] == '\0') {
2356 snprintf(descp
, 255,
2357 "Emulex OneConnect %s, %s Initiator %s",
2360 else if (max_speed
== 0)
2361 snprintf(descp
, 255,
2363 m
.name
, m
.bus
, m
.function
);
2365 snprintf(descp
, 255,
2366 "Emulex %s %d%s %s %s",
2367 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2373 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2374 * @phba: pointer to lpfc hba data structure.
2375 * @pring: pointer to a IOCB ring.
2376 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2378 * This routine posts a given number of IOCBs with the associated DMA buffer
2379 * descriptors specified by the cnt argument to the given IOCB ring.
2382 * The number of IOCBs NOT able to be posted to the IOCB ring.
2385 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2388 struct lpfc_iocbq
*iocb
;
2389 struct lpfc_dmabuf
*mp1
, *mp2
;
2391 cnt
+= pring
->missbufcnt
;
2393 /* While there are buffers to post */
2395 /* Allocate buffer for command iocb */
2396 iocb
= lpfc_sli_get_iocbq(phba
);
2398 pring
->missbufcnt
= cnt
;
2403 /* 2 buffers can be posted per command */
2404 /* Allocate buffer to post */
2405 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2407 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2408 if (!mp1
|| !mp1
->virt
) {
2410 lpfc_sli_release_iocbq(phba
, iocb
);
2411 pring
->missbufcnt
= cnt
;
2415 INIT_LIST_HEAD(&mp1
->list
);
2416 /* Allocate buffer to post */
2418 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2420 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2422 if (!mp2
|| !mp2
->virt
) {
2424 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2426 lpfc_sli_release_iocbq(phba
, iocb
);
2427 pring
->missbufcnt
= cnt
;
2431 INIT_LIST_HEAD(&mp2
->list
);
2436 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2437 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2438 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2439 icmd
->ulpBdeCount
= 1;
2442 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2443 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2444 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2446 icmd
->ulpBdeCount
= 2;
2449 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2452 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2454 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2458 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2462 lpfc_sli_release_iocbq(phba
, iocb
);
2463 pring
->missbufcnt
= cnt
;
2466 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2468 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2470 pring
->missbufcnt
= 0;
2475 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2476 * @phba: pointer to lpfc hba data structure.
2478 * This routine posts initial receive IOCB buffers to the ELS ring. The
2479 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2480 * set to 64 IOCBs. SLI3 only.
2483 * 0 - success (currently always success)
2486 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2488 struct lpfc_sli
*psli
= &phba
->sli
;
2490 /* Ring 0, ELS / CT buffers */
2491 lpfc_post_buffer(phba
, &psli
->sli3_ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2492 /* Ring 2 - FCP no buffers needed */
2497 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2500 * lpfc_sha_init - Set up initial array of hash table entries
2501 * @HashResultPointer: pointer to an array as hash table.
2503 * This routine sets up the initial values to the array of hash table entries
2507 lpfc_sha_init(uint32_t * HashResultPointer
)
2509 HashResultPointer
[0] = 0x67452301;
2510 HashResultPointer
[1] = 0xEFCDAB89;
2511 HashResultPointer
[2] = 0x98BADCFE;
2512 HashResultPointer
[3] = 0x10325476;
2513 HashResultPointer
[4] = 0xC3D2E1F0;
2517 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2518 * @HashResultPointer: pointer to an initial/result hash table.
2519 * @HashWorkingPointer: pointer to an working hash table.
2521 * This routine iterates an initial hash table pointed by @HashResultPointer
2522 * with the values from the working hash table pointeed by @HashWorkingPointer.
2523 * The results are putting back to the initial hash table, returned through
2524 * the @HashResultPointer as the result hash table.
2527 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2531 uint32_t A
, B
, C
, D
, E
;
2534 HashWorkingPointer
[t
] =
2536 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2538 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2539 } while (++t
<= 79);
2541 A
= HashResultPointer
[0];
2542 B
= HashResultPointer
[1];
2543 C
= HashResultPointer
[2];
2544 D
= HashResultPointer
[3];
2545 E
= HashResultPointer
[4];
2549 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2550 } else if (t
< 40) {
2551 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2552 } else if (t
< 60) {
2553 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2555 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2557 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2563 } while (++t
<= 79);
2565 HashResultPointer
[0] += A
;
2566 HashResultPointer
[1] += B
;
2567 HashResultPointer
[2] += C
;
2568 HashResultPointer
[3] += D
;
2569 HashResultPointer
[4] += E
;
2574 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2575 * @RandomChallenge: pointer to the entry of host challenge random number array.
2576 * @HashWorking: pointer to the entry of the working hash array.
2578 * This routine calculates the working hash array referred by @HashWorking
2579 * from the challenge random numbers associated with the host, referred by
2580 * @RandomChallenge. The result is put into the entry of the working hash
2581 * array and returned by reference through @HashWorking.
2584 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2586 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2590 * lpfc_hba_init - Perform special handling for LC HBA initialization
2591 * @phba: pointer to lpfc hba data structure.
2592 * @hbainit: pointer to an array of unsigned 32-bit integers.
2594 * This routine performs the special handling for LC HBA initialization.
2597 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2600 uint32_t *HashWorking
;
2601 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2603 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2607 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2608 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2610 for (t
= 0; t
< 7; t
++)
2611 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2613 lpfc_sha_init(hbainit
);
2614 lpfc_sha_iterate(hbainit
, HashWorking
);
2619 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2620 * @vport: pointer to a virtual N_Port data structure.
2622 * This routine performs the necessary cleanups before deleting the @vport.
2623 * It invokes the discovery state machine to perform necessary state
2624 * transitions and to release the ndlps associated with the @vport. Note,
2625 * the physical port is treated as @vport 0.
2628 lpfc_cleanup(struct lpfc_vport
*vport
)
2630 struct lpfc_hba
*phba
= vport
->phba
;
2631 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2634 if (phba
->link_state
> LPFC_LINK_DOWN
)
2635 lpfc_port_link_failure(vport
);
2637 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2638 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2639 ndlp
= lpfc_enable_node(vport
, ndlp
,
2640 NLP_STE_UNUSED_NODE
);
2643 spin_lock_irq(&phba
->ndlp_lock
);
2644 NLP_SET_FREE_REQ(ndlp
);
2645 spin_unlock_irq(&phba
->ndlp_lock
);
2646 /* Trigger the release of the ndlp memory */
2650 spin_lock_irq(&phba
->ndlp_lock
);
2651 if (NLP_CHK_FREE_REQ(ndlp
)) {
2652 /* The ndlp should not be in memory free mode already */
2653 spin_unlock_irq(&phba
->ndlp_lock
);
2656 /* Indicate request for freeing ndlp memory */
2657 NLP_SET_FREE_REQ(ndlp
);
2658 spin_unlock_irq(&phba
->ndlp_lock
);
2660 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2661 ndlp
->nlp_DID
== Fabric_DID
) {
2662 /* Just free up ndlp with Fabric_DID for vports */
2667 /* take care of nodes in unused state before the state
2668 * machine taking action.
2670 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2675 if (ndlp
->nlp_type
& NLP_FABRIC
)
2676 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2677 NLP_EVT_DEVICE_RECOVERY
);
2679 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
2680 /* Remove the NVME transport reference now and
2681 * continue to remove the node.
2686 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2690 /* At this point, ALL ndlp's should be gone
2691 * because of the previous NLP_EVT_DEVICE_RM.
2692 * Lets wait for this to happen, if needed.
2694 while (!list_empty(&vport
->fc_nodes
)) {
2696 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2697 "0233 Nodelist not empty\n");
2698 list_for_each_entry_safe(ndlp
, next_ndlp
,
2699 &vport
->fc_nodes
, nlp_listp
) {
2700 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2702 "0282 did:x%x ndlp:x%p "
2703 "usgmap:x%x refcnt:%d\n",
2704 ndlp
->nlp_DID
, (void *)ndlp
,
2706 kref_read(&ndlp
->kref
));
2711 /* Wait for any activity on ndlps to settle */
2714 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2718 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2719 * @vport: pointer to a virtual N_Port data structure.
2721 * This routine stops all the timers associated with a @vport. This function
2722 * is invoked before disabling or deleting a @vport. Note that the physical
2723 * port is treated as @vport 0.
2726 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2728 del_timer_sync(&vport
->els_tmofunc
);
2729 del_timer_sync(&vport
->delayed_disc_tmo
);
2730 lpfc_can_disctmo(vport
);
2735 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2736 * @phba: pointer to lpfc hba data structure.
2738 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2739 * caller of this routine should already hold the host lock.
2742 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2744 /* Clear pending FCF rediscovery wait flag */
2745 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2747 /* Now, try to stop the timer */
2748 del_timer(&phba
->fcf
.redisc_wait
);
2752 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2753 * @phba: pointer to lpfc hba data structure.
2755 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2756 * checks whether the FCF rediscovery wait timer is pending with the host
2757 * lock held before proceeding with disabling the timer and clearing the
2758 * wait timer pendig flag.
2761 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2763 spin_lock_irq(&phba
->hbalock
);
2764 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2765 /* FCF rediscovery timer already fired or stopped */
2766 spin_unlock_irq(&phba
->hbalock
);
2769 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2770 /* Clear failover in progress flags */
2771 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2772 spin_unlock_irq(&phba
->hbalock
);
2776 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2777 * @phba: pointer to lpfc hba data structure.
2779 * This routine stops all the timers associated with a HBA. This function is
2780 * invoked before either putting a HBA offline or unloading the driver.
2783 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2785 lpfc_stop_vport_timers(phba
->pport
);
2786 del_timer_sync(&phba
->sli
.mbox_tmo
);
2787 del_timer_sync(&phba
->fabric_block_timer
);
2788 del_timer_sync(&phba
->eratt_poll
);
2789 del_timer_sync(&phba
->hb_tmofunc
);
2790 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2791 del_timer_sync(&phba
->rrq_tmr
);
2792 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2794 phba
->hb_outstanding
= 0;
2796 switch (phba
->pci_dev_grp
) {
2797 case LPFC_PCI_DEV_LP
:
2798 /* Stop any LightPulse device specific driver timers */
2799 del_timer_sync(&phba
->fcp_poll_timer
);
2801 case LPFC_PCI_DEV_OC
:
2802 /* Stop any OneConnect device sepcific driver timers */
2803 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2806 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2807 "0297 Invalid device group (x%x)\n",
2815 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2816 * @phba: pointer to lpfc hba data structure.
2818 * This routine marks a HBA's management interface as blocked. Once the HBA's
2819 * management interface is marked as blocked, all the user space access to
2820 * the HBA, whether they are from sysfs interface or libdfc interface will
2821 * all be blocked. The HBA is set to block the management interface when the
2822 * driver prepares the HBA interface for online or offline.
2825 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
2827 unsigned long iflag
;
2828 uint8_t actcmd
= MBX_HEARTBEAT
;
2829 unsigned long timeout
;
2831 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2832 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2833 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2834 if (mbx_action
== LPFC_MBX_NO_WAIT
)
2836 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
2837 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2838 if (phba
->sli
.mbox_active
) {
2839 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2840 /* Determine how long we might wait for the active mailbox
2841 * command to be gracefully completed by firmware.
2843 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2844 phba
->sli
.mbox_active
) * 1000) + jiffies
;
2846 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2848 /* Wait for the outstnading mailbox command to complete */
2849 while (phba
->sli
.mbox_active
) {
2850 /* Check active mailbox complete status every 2ms */
2852 if (time_after(jiffies
, timeout
)) {
2853 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2854 "2813 Mgmt IO is Blocked %x "
2855 "- mbox cmd %x still active\n",
2856 phba
->sli
.sli_flag
, actcmd
);
2863 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2864 * @phba: pointer to lpfc hba data structure.
2866 * Allocate RPIs for all active remote nodes. This is needed whenever
2867 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2868 * is to fixup the temporary rpi assignments.
2871 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
2873 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2874 struct lpfc_vport
**vports
;
2877 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
2880 vports
= lpfc_create_vport_work_array(phba
);
2881 if (vports
!= NULL
) {
2882 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2883 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2886 list_for_each_entry_safe(ndlp
, next_ndlp
,
2887 &vports
[i
]->fc_nodes
,
2889 if (NLP_CHK_NODE_ACT(ndlp
)) {
2891 lpfc_sli4_alloc_rpi(phba
);
2892 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
,
2894 "0009 rpi:%x DID:%x "
2895 "flg:%x map:%x %p\n",
2905 lpfc_destroy_vport_work_array(phba
, vports
);
2909 * lpfc_online - Initialize and bring a HBA online
2910 * @phba: pointer to lpfc hba data structure.
2912 * This routine initializes the HBA and brings a HBA online. During this
2913 * process, the management interface is blocked to prevent user space access
2914 * to the HBA interfering with the driver initialization.
2921 lpfc_online(struct lpfc_hba
*phba
)
2923 struct lpfc_vport
*vport
;
2924 struct lpfc_vport
**vports
;
2926 bool vpis_cleared
= false;
2930 vport
= phba
->pport
;
2932 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2935 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2936 "0458 Bring Adapter online\n");
2938 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
2940 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2941 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2942 lpfc_unblock_mgmt_io(phba
);
2945 spin_lock_irq(&phba
->hbalock
);
2946 if (!phba
->sli4_hba
.max_cfg_param
.vpi_used
)
2947 vpis_cleared
= true;
2948 spin_unlock_irq(&phba
->hbalock
);
2950 lpfc_sli_queue_init(phba
);
2951 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2952 lpfc_unblock_mgmt_io(phba
);
2957 vports
= lpfc_create_vport_work_array(phba
);
2958 if (vports
!= NULL
) {
2959 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2960 struct Scsi_Host
*shost
;
2961 shost
= lpfc_shost_from_vport(vports
[i
]);
2962 spin_lock_irq(shost
->host_lock
);
2963 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2964 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2965 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2966 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2967 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2968 if ((vpis_cleared
) &&
2969 (vports
[i
]->port_type
!=
2970 LPFC_PHYSICAL_PORT
))
2973 spin_unlock_irq(shost
->host_lock
);
2976 lpfc_destroy_vport_work_array(phba
, vports
);
2978 lpfc_unblock_mgmt_io(phba
);
2983 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2984 * @phba: pointer to lpfc hba data structure.
2986 * This routine marks a HBA's management interface as not blocked. Once the
2987 * HBA's management interface is marked as not blocked, all the user space
2988 * access to the HBA, whether they are from sysfs interface or libdfc
2989 * interface will be allowed. The HBA is set to block the management interface
2990 * when the driver prepares the HBA interface for online or offline and then
2991 * set to unblock the management interface afterwards.
2994 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2996 unsigned long iflag
;
2998 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2999 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
3000 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3004 * lpfc_offline_prep - Prepare a HBA to be brought offline
3005 * @phba: pointer to lpfc hba data structure.
3007 * This routine is invoked to prepare a HBA to be brought offline. It performs
3008 * unregistration login to all the nodes on all vports and flushes the mailbox
3009 * queue to make it ready to be brought offline.
3012 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
3014 struct lpfc_vport
*vport
= phba
->pport
;
3015 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3016 struct lpfc_vport
**vports
;
3017 struct Scsi_Host
*shost
;
3020 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
3023 lpfc_block_mgmt_io(phba
, mbx_action
);
3025 lpfc_linkdown(phba
);
3027 /* Issue an unreg_login to all nodes on all vports */
3028 vports
= lpfc_create_vport_work_array(phba
);
3029 if (vports
!= NULL
) {
3030 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3031 if (vports
[i
]->load_flag
& FC_UNLOADING
)
3033 shost
= lpfc_shost_from_vport(vports
[i
]);
3034 spin_lock_irq(shost
->host_lock
);
3035 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3036 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3037 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
3038 spin_unlock_irq(shost
->host_lock
);
3040 shost
= lpfc_shost_from_vport(vports
[i
]);
3041 list_for_each_entry_safe(ndlp
, next_ndlp
,
3042 &vports
[i
]->fc_nodes
,
3044 if (!NLP_CHK_NODE_ACT(ndlp
))
3046 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3048 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3049 lpfc_disc_state_machine(vports
[i
], ndlp
,
3050 NULL
, NLP_EVT_DEVICE_RECOVERY
);
3051 lpfc_disc_state_machine(vports
[i
], ndlp
,
3052 NULL
, NLP_EVT_DEVICE_RM
);
3054 spin_lock_irq(shost
->host_lock
);
3055 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3056 spin_unlock_irq(shost
->host_lock
);
3058 * Whenever an SLI4 port goes offline, free the
3059 * RPI. Get a new RPI when the adapter port
3060 * comes back online.
3062 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3063 lpfc_printf_vlog(ndlp
->vport
,
3064 KERN_INFO
, LOG_NODE
,
3065 "0011 lpfc_offline: "
3067 "usgmap:x%x rpi:%x\n",
3068 ndlp
, ndlp
->nlp_DID
,
3072 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
3074 lpfc_unreg_rpi(vports
[i
], ndlp
);
3078 lpfc_destroy_vport_work_array(phba
, vports
);
3080 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
3084 * lpfc_offline - Bring a HBA offline
3085 * @phba: pointer to lpfc hba data structure.
3087 * This routine actually brings a HBA offline. It stops all the timers
3088 * associated with the HBA, brings down the SLI layer, and eventually
3089 * marks the HBA as in offline state for the upper layer protocol.
3092 lpfc_offline(struct lpfc_hba
*phba
)
3094 struct Scsi_Host
*shost
;
3095 struct lpfc_vport
**vports
;
3098 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
3101 /* stop port and all timers associated with this hba */
3102 lpfc_stop_port(phba
);
3103 vports
= lpfc_create_vport_work_array(phba
);
3105 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3106 lpfc_stop_vport_timers(vports
[i
]);
3107 lpfc_destroy_vport_work_array(phba
, vports
);
3108 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3109 "0460 Bring Adapter offline\n");
3110 /* Bring down the SLI Layer and cleanup. The HBA is offline
3112 lpfc_sli_hba_down(phba
);
3113 spin_lock_irq(&phba
->hbalock
);
3115 spin_unlock_irq(&phba
->hbalock
);
3116 vports
= lpfc_create_vport_work_array(phba
);
3118 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3119 shost
= lpfc_shost_from_vport(vports
[i
]);
3120 spin_lock_irq(shost
->host_lock
);
3121 vports
[i
]->work_port_events
= 0;
3122 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
3123 spin_unlock_irq(shost
->host_lock
);
3125 lpfc_destroy_vport_work_array(phba
, vports
);
3129 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3130 * @phba: pointer to lpfc hba data structure.
3132 * This routine is to free all the SCSI buffers and IOCBs from the driver
3133 * list back to kernel. It is called from lpfc_pci_remove_one to free
3134 * the internal resources before the device is removed from the system.
3137 lpfc_scsi_free(struct lpfc_hba
*phba
)
3139 struct lpfc_scsi_buf
*sb
, *sb_next
;
3141 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
3144 spin_lock_irq(&phba
->hbalock
);
3146 /* Release all the lpfc_scsi_bufs maintained by this host. */
3148 spin_lock(&phba
->scsi_buf_list_put_lock
);
3149 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_put
,
3151 list_del(&sb
->list
);
3152 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3155 phba
->total_scsi_bufs
--;
3157 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3159 spin_lock(&phba
->scsi_buf_list_get_lock
);
3160 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_get
,
3162 list_del(&sb
->list
);
3163 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3166 phba
->total_scsi_bufs
--;
3168 spin_unlock(&phba
->scsi_buf_list_get_lock
);
3169 spin_unlock_irq(&phba
->hbalock
);
3172 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3173 * @phba: pointer to lpfc hba data structure.
3175 * This routine is to free all the NVME buffers and IOCBs from the driver
3176 * list back to kernel. It is called from lpfc_pci_remove_one to free
3177 * the internal resources before the device is removed from the system.
3180 lpfc_nvme_free(struct lpfc_hba
*phba
)
3182 struct lpfc_nvme_buf
*lpfc_ncmd
, *lpfc_ncmd_next
;
3184 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
))
3187 spin_lock_irq(&phba
->hbalock
);
3189 /* Release all the lpfc_nvme_bufs maintained by this host. */
3190 spin_lock(&phba
->nvme_buf_list_put_lock
);
3191 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3192 &phba
->lpfc_nvme_buf_list_put
, list
) {
3193 list_del(&lpfc_ncmd
->list
);
3194 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, lpfc_ncmd
->data
,
3195 lpfc_ncmd
->dma_handle
);
3197 phba
->total_nvme_bufs
--;
3199 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3201 spin_lock(&phba
->nvme_buf_list_get_lock
);
3202 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3203 &phba
->lpfc_nvme_buf_list_get
, list
) {
3204 list_del(&lpfc_ncmd
->list
);
3205 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, lpfc_ncmd
->data
,
3206 lpfc_ncmd
->dma_handle
);
3208 phba
->total_nvme_bufs
--;
3210 spin_unlock(&phba
->nvme_buf_list_get_lock
);
3211 spin_unlock_irq(&phba
->hbalock
);
3214 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3215 * @phba: pointer to lpfc hba data structure.
3217 * This routine first calculates the sizes of the current els and allocated
3218 * scsi sgl lists, and then goes through all sgls to updates the physical
3219 * XRIs assigned due to port function reset. During port initialization, the
3220 * current els and allocated scsi sgl lists are 0s.
3223 * 0 - successful (for now, it always returns 0)
3226 lpfc_sli4_els_sgl_update(struct lpfc_hba
*phba
)
3228 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3229 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3230 LIST_HEAD(els_sgl_list
);
3234 * update on pci function's els xri-sgl list
3236 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3238 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
3239 /* els xri-sgl expanded */
3240 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
3241 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3242 "3157 ELS xri-sgl count increased from "
3243 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3245 /* allocate the additional els sgls */
3246 for (i
= 0; i
< xri_cnt
; i
++) {
3247 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3249 if (sglq_entry
== NULL
) {
3250 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3251 "2562 Failure to allocate an "
3252 "ELS sgl entry:%d\n", i
);
3256 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
3257 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
3259 if (sglq_entry
->virt
== NULL
) {
3261 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3262 "2563 Failure to allocate an "
3263 "ELS mbuf:%d\n", i
);
3267 sglq_entry
->sgl
= sglq_entry
->virt
;
3268 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
3269 sglq_entry
->state
= SGL_FREED
;
3270 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
3272 spin_lock_irq(&phba
->hbalock
);
3273 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3274 list_splice_init(&els_sgl_list
,
3275 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3276 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3277 spin_unlock_irq(&phba
->hbalock
);
3278 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
3279 /* els xri-sgl shrinked */
3280 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
3281 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3282 "3158 ELS xri-sgl count decreased from "
3283 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3285 spin_lock_irq(&phba
->hbalock
);
3286 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3287 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
,
3289 /* release extra els sgls from list */
3290 for (i
= 0; i
< xri_cnt
; i
++) {
3291 list_remove_head(&els_sgl_list
,
3292 sglq_entry
, struct lpfc_sglq
, list
);
3294 __lpfc_mbuf_free(phba
, sglq_entry
->virt
,
3299 list_splice_init(&els_sgl_list
,
3300 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3301 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3302 spin_unlock_irq(&phba
->hbalock
);
3304 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3305 "3163 ELS xri-sgl count unchanged: %d\n",
3307 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
3309 /* update xris to els sgls on the list */
3311 sglq_entry_next
= NULL
;
3312 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3313 &phba
->sli4_hba
.lpfc_els_sgl_list
, list
) {
3314 lxri
= lpfc_sli4_next_xritag(phba
);
3315 if (lxri
== NO_XRI
) {
3316 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3317 "2400 Failed to allocate xri for "
3322 sglq_entry
->sli4_lxritag
= lxri
;
3323 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3328 lpfc_free_els_sgl_list(phba
);
3333 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3334 * @phba: pointer to lpfc hba data structure.
3336 * This routine first calculates the sizes of the current els and allocated
3337 * scsi sgl lists, and then goes through all sgls to updates the physical
3338 * XRIs assigned due to port function reset. During port initialization, the
3339 * current els and allocated scsi sgl lists are 0s.
3342 * 0 - successful (for now, it always returns 0)
3345 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba
*phba
)
3347 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3348 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3349 uint16_t nvmet_xri_cnt
, tot_cnt
;
3350 LIST_HEAD(nvmet_sgl_list
);
3354 * update on pci function's nvmet xri-sgl list
3356 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3358 tot_cnt
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
3360 if (nvmet_xri_cnt
> phba
->sli4_hba
.nvmet_xri_cnt
) {
3361 /* els xri-sgl expanded */
3362 xri_cnt
= nvmet_xri_cnt
- phba
->sli4_hba
.nvmet_xri_cnt
;
3363 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3364 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3365 phba
->sli4_hba
.nvmet_xri_cnt
, nvmet_xri_cnt
);
3366 /* allocate the additional nvmet sgls */
3367 for (i
= 0; i
< xri_cnt
; i
++) {
3368 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3370 if (sglq_entry
== NULL
) {
3371 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3372 "6303 Failure to allocate an "
3373 "NVMET sgl entry:%d\n", i
);
3377 sglq_entry
->buff_type
= NVMET_BUFF_TYPE
;
3378 sglq_entry
->virt
= lpfc_nvmet_buf_alloc(phba
, 0,
3380 if (sglq_entry
->virt
== NULL
) {
3382 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3383 "6304 Failure to allocate an "
3384 "NVMET buf:%d\n", i
);
3388 sglq_entry
->sgl
= sglq_entry
->virt
;
3389 memset(sglq_entry
->sgl
, 0,
3390 phba
->cfg_sg_dma_buf_size
);
3391 sglq_entry
->state
= SGL_FREED
;
3392 list_add_tail(&sglq_entry
->list
, &nvmet_sgl_list
);
3394 spin_lock_irq(&phba
->hbalock
);
3395 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3396 list_splice_init(&nvmet_sgl_list
,
3397 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3398 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3399 spin_unlock_irq(&phba
->hbalock
);
3400 } else if (nvmet_xri_cnt
< phba
->sli4_hba
.nvmet_xri_cnt
) {
3401 /* nvmet xri-sgl shrunk */
3402 xri_cnt
= phba
->sli4_hba
.nvmet_xri_cnt
- nvmet_xri_cnt
;
3403 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3404 "6305 NVMET xri-sgl count decreased from "
3405 "%d to %d\n", phba
->sli4_hba
.nvmet_xri_cnt
,
3407 spin_lock_irq(&phba
->hbalock
);
3408 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3409 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
3411 /* release extra nvmet sgls from list */
3412 for (i
= 0; i
< xri_cnt
; i
++) {
3413 list_remove_head(&nvmet_sgl_list
,
3414 sglq_entry
, struct lpfc_sglq
, list
);
3416 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
,
3421 list_splice_init(&nvmet_sgl_list
,
3422 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3423 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3424 spin_unlock_irq(&phba
->hbalock
);
3426 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3427 "6306 NVMET xri-sgl count unchanged: %d\n",
3429 phba
->sli4_hba
.nvmet_xri_cnt
= nvmet_xri_cnt
;
3431 /* update xris to nvmet sgls on the list */
3433 sglq_entry_next
= NULL
;
3434 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3435 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
, list
) {
3436 lxri
= lpfc_sli4_next_xritag(phba
);
3437 if (lxri
== NO_XRI
) {
3438 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3439 "6307 Failed to allocate xri for "
3444 sglq_entry
->sli4_lxritag
= lxri
;
3445 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3450 lpfc_free_nvmet_sgl_list(phba
);
3455 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3456 * @phba: pointer to lpfc hba data structure.
3458 * This routine first calculates the sizes of the current els and allocated
3459 * scsi sgl lists, and then goes through all sgls to updates the physical
3460 * XRIs assigned due to port function reset. During port initialization, the
3461 * current els and allocated scsi sgl lists are 0s.
3464 * 0 - successful (for now, it always returns 0)
3467 lpfc_sli4_scsi_sgl_update(struct lpfc_hba
*phba
)
3469 struct lpfc_scsi_buf
*psb
, *psb_next
;
3470 uint16_t i
, lxri
, els_xri_cnt
, scsi_xri_cnt
;
3471 LIST_HEAD(scsi_sgl_list
);
3475 * update on pci function's els xri-sgl list
3477 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3478 phba
->total_scsi_bufs
= 0;
3481 * update on pci function's allocated scsi xri-sgl list
3483 /* maximum number of xris available for scsi buffers */
3484 phba
->sli4_hba
.scsi_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
3487 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
3490 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
3491 phba
->sli4_hba
.scsi_xri_max
= /* Split them up */
3492 (phba
->sli4_hba
.scsi_xri_max
*
3493 phba
->cfg_xri_split
) / 100;
3495 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3496 spin_lock(&phba
->scsi_buf_list_put_lock
);
3497 list_splice_init(&phba
->lpfc_scsi_buf_list_get
, &scsi_sgl_list
);
3498 list_splice(&phba
->lpfc_scsi_buf_list_put
, &scsi_sgl_list
);
3499 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3500 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3502 if (phba
->sli4_hba
.scsi_xri_cnt
> phba
->sli4_hba
.scsi_xri_max
) {
3503 /* max scsi xri shrinked below the allocated scsi buffers */
3504 scsi_xri_cnt
= phba
->sli4_hba
.scsi_xri_cnt
-
3505 phba
->sli4_hba
.scsi_xri_max
;
3506 /* release the extra allocated scsi buffers */
3507 for (i
= 0; i
< scsi_xri_cnt
; i
++) {
3508 list_remove_head(&scsi_sgl_list
, psb
,
3509 struct lpfc_scsi_buf
, list
);
3511 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3512 psb
->data
, psb
->dma_handle
);
3516 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3517 phba
->sli4_hba
.scsi_xri_cnt
-= scsi_xri_cnt
;
3518 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3521 /* update xris associated to remaining allocated scsi buffers */
3524 list_for_each_entry_safe(psb
, psb_next
, &scsi_sgl_list
, list
) {
3525 lxri
= lpfc_sli4_next_xritag(phba
);
3526 if (lxri
== NO_XRI
) {
3527 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3528 "2560 Failed to allocate xri for "
3533 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
3534 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3536 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3537 spin_lock(&phba
->scsi_buf_list_put_lock
);
3538 list_splice_init(&scsi_sgl_list
, &phba
->lpfc_scsi_buf_list_get
);
3539 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
3540 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3541 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3545 lpfc_scsi_free(phba
);
3550 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3551 * @phba: pointer to lpfc hba data structure.
3553 * This routine first calculates the sizes of the current els and allocated
3554 * scsi sgl lists, and then goes through all sgls to updates the physical
3555 * XRIs assigned due to port function reset. During port initialization, the
3556 * current els and allocated scsi sgl lists are 0s.
3559 * 0 - successful (for now, it always returns 0)
3562 lpfc_sli4_nvme_sgl_update(struct lpfc_hba
*phba
)
3564 struct lpfc_nvme_buf
*lpfc_ncmd
= NULL
, *lpfc_ncmd_next
= NULL
;
3565 uint16_t i
, lxri
, els_xri_cnt
;
3566 uint16_t nvme_xri_cnt
, nvme_xri_max
;
3567 LIST_HEAD(nvme_sgl_list
);
3570 phba
->total_nvme_bufs
= 0;
3572 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
))
3575 * update on pci function's allocated nvme xri-sgl list
3578 /* maximum number of xris available for nvme buffers */
3579 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3580 nvme_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
3581 phba
->sli4_hba
.nvme_xri_max
= nvme_xri_max
;
3582 phba
->sli4_hba
.nvme_xri_max
-= phba
->sli4_hba
.scsi_xri_max
;
3584 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3585 "6074 Current allocated NVME xri-sgl count:%d, "
3586 "maximum NVME xri count:%d\n",
3587 phba
->sli4_hba
.nvme_xri_cnt
,
3588 phba
->sli4_hba
.nvme_xri_max
);
3590 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3591 spin_lock(&phba
->nvme_buf_list_put_lock
);
3592 list_splice_init(&phba
->lpfc_nvme_buf_list_get
, &nvme_sgl_list
);
3593 list_splice(&phba
->lpfc_nvme_buf_list_put
, &nvme_sgl_list
);
3594 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3595 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3597 if (phba
->sli4_hba
.nvme_xri_cnt
> phba
->sli4_hba
.nvme_xri_max
) {
3598 /* max nvme xri shrunk below the allocated nvme buffers */
3599 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3600 nvme_xri_cnt
= phba
->sli4_hba
.nvme_xri_cnt
-
3601 phba
->sli4_hba
.nvme_xri_max
;
3602 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3603 /* release the extra allocated nvme buffers */
3604 for (i
= 0; i
< nvme_xri_cnt
; i
++) {
3605 list_remove_head(&nvme_sgl_list
, lpfc_ncmd
,
3606 struct lpfc_nvme_buf
, list
);
3608 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3610 lpfc_ncmd
->dma_handle
);
3614 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3615 phba
->sli4_hba
.nvme_xri_cnt
-= nvme_xri_cnt
;
3616 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3619 /* update xris associated to remaining allocated nvme buffers */
3621 lpfc_ncmd_next
= NULL
;
3622 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3623 &nvme_sgl_list
, list
) {
3624 lxri
= lpfc_sli4_next_xritag(phba
);
3625 if (lxri
== NO_XRI
) {
3626 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3627 "6075 Failed to allocate xri for "
3632 lpfc_ncmd
->cur_iocbq
.sli4_lxritag
= lxri
;
3633 lpfc_ncmd
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3635 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3636 spin_lock(&phba
->nvme_buf_list_put_lock
);
3637 list_splice_init(&nvme_sgl_list
, &phba
->lpfc_nvme_buf_list_get
);
3638 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_put
);
3639 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3640 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3644 lpfc_nvme_free(phba
);
3649 * lpfc_create_port - Create an FC port
3650 * @phba: pointer to lpfc hba data structure.
3651 * @instance: a unique integer ID to this FC port.
3652 * @dev: pointer to the device data structure.
3654 * This routine creates a FC port for the upper layer protocol. The FC port
3655 * can be created on top of either a physical port or a virtual port provided
3656 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3657 * and associates the FC port created before adding the shost into the SCSI
3661 * @vport - pointer to the virtual N_Port data structure.
3662 * NULL - port create failed.
3665 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
3667 struct lpfc_vport
*vport
;
3668 struct Scsi_Host
*shost
= NULL
;
3671 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
3672 if (dev
!= &phba
->pcidev
->dev
) {
3673 shost
= scsi_host_alloc(&lpfc_vport_template
,
3674 sizeof(struct lpfc_vport
));
3676 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3677 shost
= scsi_host_alloc(&lpfc_template
,
3678 sizeof(struct lpfc_vport
));
3680 shost
= scsi_host_alloc(&lpfc_template_s3
,
3681 sizeof(struct lpfc_vport
));
3683 } else if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
3684 shost
= scsi_host_alloc(&lpfc_template_nvme
,
3685 sizeof(struct lpfc_vport
));
3690 vport
= (struct lpfc_vport
*) shost
->hostdata
;
3692 vport
->load_flag
|= FC_LOADING
;
3693 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3694 vport
->fc_rscn_flush
= 0;
3695 lpfc_get_vport_cfgparam(vport
);
3697 shost
->unique_id
= instance
;
3698 shost
->max_id
= LPFC_MAX_TARGET
;
3699 shost
->max_lun
= vport
->cfg_max_luns
;
3700 shost
->this_id
= -1;
3701 shost
->max_cmd_len
= 16;
3702 shost
->nr_hw_queues
= phba
->cfg_fcp_io_channel
;
3703 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3704 shost
->dma_boundary
=
3705 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
3706 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3710 * Set initial can_queue value since 0 is no longer supported and
3711 * scsi_add_host will fail. This will be adjusted later based on the
3712 * max xri value determined in hba setup.
3714 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
3715 if (dev
!= &phba
->pcidev
->dev
) {
3716 shost
->transportt
= lpfc_vport_transport_template
;
3717 vport
->port_type
= LPFC_NPIV_PORT
;
3719 shost
->transportt
= lpfc_transport_template
;
3720 vport
->port_type
= LPFC_PHYSICAL_PORT
;
3723 /* Initialize all internally managed lists. */
3724 INIT_LIST_HEAD(&vport
->fc_nodes
);
3725 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
3726 spin_lock_init(&vport
->work_port_lock
);
3728 init_timer(&vport
->fc_disctmo
);
3729 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
3730 vport
->fc_disctmo
.data
= (unsigned long)vport
;
3732 init_timer(&vport
->els_tmofunc
);
3733 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
3734 vport
->els_tmofunc
.data
= (unsigned long)vport
;
3736 init_timer(&vport
->delayed_disc_tmo
);
3737 vport
->delayed_disc_tmo
.function
= lpfc_delayed_disc_tmo
;
3738 vport
->delayed_disc_tmo
.data
= (unsigned long)vport
;
3740 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
3744 spin_lock_irq(&phba
->hbalock
);
3745 list_add_tail(&vport
->listentry
, &phba
->port_list
);
3746 spin_unlock_irq(&phba
->hbalock
);
3750 scsi_host_put(shost
);
3756 * destroy_port - destroy an FC port
3757 * @vport: pointer to an lpfc virtual N_Port data structure.
3759 * This routine destroys a FC port from the upper layer protocol. All the
3760 * resources associated with the port are released.
3763 destroy_port(struct lpfc_vport
*vport
)
3765 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3766 struct lpfc_hba
*phba
= vport
->phba
;
3768 lpfc_debugfs_terminate(vport
);
3769 fc_remove_host(shost
);
3770 scsi_remove_host(shost
);
3772 spin_lock_irq(&phba
->hbalock
);
3773 list_del_init(&vport
->listentry
);
3774 spin_unlock_irq(&phba
->hbalock
);
3776 lpfc_cleanup(vport
);
3781 * lpfc_get_instance - Get a unique integer ID
3783 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3784 * uses the kernel idr facility to perform the task.
3787 * instance - a unique integer ID allocated as the new instance.
3788 * -1 - lpfc get instance failed.
3791 lpfc_get_instance(void)
3795 ret
= idr_alloc(&lpfc_hba_index
, NULL
, 0, 0, GFP_KERNEL
);
3796 return ret
< 0 ? -1 : ret
;
3800 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3801 * @shost: pointer to SCSI host data structure.
3802 * @time: elapsed time of the scan in jiffies.
3804 * This routine is called by the SCSI layer with a SCSI host to determine
3805 * whether the scan host is finished.
3807 * Note: there is no scan_start function as adapter initialization will have
3808 * asynchronously kicked off the link initialization.
3811 * 0 - SCSI host scan is not over yet.
3812 * 1 - SCSI host scan is over.
3814 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
3816 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3817 struct lpfc_hba
*phba
= vport
->phba
;
3820 spin_lock_irq(shost
->host_lock
);
3822 if (vport
->load_flag
& FC_UNLOADING
) {
3826 if (time
>= msecs_to_jiffies(30 * 1000)) {
3827 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3828 "0461 Scanning longer than 30 "
3829 "seconds. Continuing initialization\n");
3833 if (time
>= msecs_to_jiffies(15 * 1000) &&
3834 phba
->link_state
<= LPFC_LINK_DOWN
) {
3835 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3836 "0465 Link down longer than 15 "
3837 "seconds. Continuing initialization\n");
3842 if (vport
->port_state
!= LPFC_VPORT_READY
)
3844 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
3846 if (vport
->fc_map_cnt
== 0 && time
< msecs_to_jiffies(2 * 1000))
3848 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
3854 spin_unlock_irq(shost
->host_lock
);
3859 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3860 * @shost: pointer to SCSI host data structure.
3862 * This routine initializes a given SCSI host attributes on a FC port. The
3863 * SCSI host can be either on top of a physical port or a virtual port.
3865 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
3867 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3868 struct lpfc_hba
*phba
= vport
->phba
;
3870 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3873 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
3874 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3875 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
3877 memset(fc_host_supported_fc4s(shost
), 0,
3878 sizeof(fc_host_supported_fc4s(shost
)));
3879 fc_host_supported_fc4s(shost
)[2] = 1;
3880 fc_host_supported_fc4s(shost
)[7] = 1;
3882 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
3883 sizeof fc_host_symbolic_name(shost
));
3885 fc_host_supported_speeds(shost
) = 0;
3886 if (phba
->lmt
& LMT_32Gb
)
3887 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_32GBIT
;
3888 if (phba
->lmt
& LMT_16Gb
)
3889 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
3890 if (phba
->lmt
& LMT_10Gb
)
3891 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
3892 if (phba
->lmt
& LMT_8Gb
)
3893 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
3894 if (phba
->lmt
& LMT_4Gb
)
3895 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
3896 if (phba
->lmt
& LMT_2Gb
)
3897 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
3898 if (phba
->lmt
& LMT_1Gb
)
3899 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
3901 fc_host_maxframe_size(shost
) =
3902 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
3903 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
3905 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
3907 /* This value is also unchanging */
3908 memset(fc_host_active_fc4s(shost
), 0,
3909 sizeof(fc_host_active_fc4s(shost
)));
3910 fc_host_active_fc4s(shost
)[2] = 1;
3911 fc_host_active_fc4s(shost
)[7] = 1;
3913 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
3914 spin_lock_irq(shost
->host_lock
);
3915 vport
->load_flag
&= ~FC_LOADING
;
3916 spin_unlock_irq(shost
->host_lock
);
3920 * lpfc_stop_port_s3 - Stop SLI3 device port
3921 * @phba: pointer to lpfc hba data structure.
3923 * This routine is invoked to stop an SLI3 device port, it stops the device
3924 * from generating interrupts and stops the device driver's timers for the
3928 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
3930 /* Clear all interrupt enable conditions */
3931 writel(0, phba
->HCregaddr
);
3932 readl(phba
->HCregaddr
); /* flush */
3933 /* Clear all pending interrupts */
3934 writel(0xffffffff, phba
->HAregaddr
);
3935 readl(phba
->HAregaddr
); /* flush */
3937 /* Reset some HBA SLI setup states */
3938 lpfc_stop_hba_timers(phba
);
3939 phba
->pport
->work_port_events
= 0;
3943 * lpfc_stop_port_s4 - Stop SLI4 device port
3944 * @phba: pointer to lpfc hba data structure.
3946 * This routine is invoked to stop an SLI4 device port, it stops the device
3947 * from generating interrupts and stops the device driver's timers for the
3951 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
3953 /* Reset some HBA SLI4 setup states */
3954 lpfc_stop_hba_timers(phba
);
3955 phba
->pport
->work_port_events
= 0;
3956 phba
->sli4_hba
.intr_enable
= 0;
3960 * lpfc_stop_port - Wrapper function for stopping hba port
3961 * @phba: Pointer to HBA context object.
3963 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3964 * the API jump table function pointer from the lpfc_hba struct.
3967 lpfc_stop_port(struct lpfc_hba
*phba
)
3969 phba
->lpfc_stop_port(phba
);
3973 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3974 * @phba: Pointer to hba for which this call is being executed.
3976 * This routine starts the timer waiting for the FCF rediscovery to complete.
3979 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
3981 unsigned long fcf_redisc_wait_tmo
=
3982 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
3983 /* Start fcf rediscovery wait period timer */
3984 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
3985 spin_lock_irq(&phba
->hbalock
);
3986 /* Allow action to new fcf asynchronous event */
3987 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
3988 /* Mark the FCF rediscovery pending state */
3989 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
3990 spin_unlock_irq(&phba
->hbalock
);
3994 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3995 * @ptr: Map to lpfc_hba data structure pointer.
3997 * This routine is invoked when waiting for FCF table rediscover has been
3998 * timed out. If new FCF record(s) has (have) been discovered during the
3999 * wait period, a new FCF event shall be added to the FCOE async event
4000 * list, and then worker thread shall be waked up for processing from the
4001 * worker thread context.
4004 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
4006 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
4008 /* Don't send FCF rediscovery event if timer cancelled */
4009 spin_lock_irq(&phba
->hbalock
);
4010 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
4011 spin_unlock_irq(&phba
->hbalock
);
4014 /* Clear FCF rediscovery timer pending flag */
4015 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
4016 /* FCF rediscovery event to worker thread */
4017 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
4018 spin_unlock_irq(&phba
->hbalock
);
4019 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
4020 "2776 FCF rediscover quiescent timer expired\n");
4021 /* wake up worker thread */
4022 lpfc_worker_wake_up(phba
);
4026 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4027 * @phba: pointer to lpfc hba data structure.
4028 * @acqe_link: pointer to the async link completion queue entry.
4030 * This routine is to parse the SLI4 link-attention link fault code and
4031 * translate it into the base driver's read link attention mailbox command
4034 * Return: Link-attention status in terms of base driver's coding.
4037 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
4038 struct lpfc_acqe_link
*acqe_link
)
4040 uint16_t latt_fault
;
4042 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
4043 case LPFC_ASYNC_LINK_FAULT_NONE
:
4044 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
4045 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
4049 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4050 "0398 Invalid link fault code: x%x\n",
4051 bf_get(lpfc_acqe_link_fault
, acqe_link
));
4052 latt_fault
= MBXERR_ERROR
;
4059 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4060 * @phba: pointer to lpfc hba data structure.
4061 * @acqe_link: pointer to the async link completion queue entry.
4063 * This routine is to parse the SLI4 link attention type and translate it
4064 * into the base driver's link attention type coding.
4066 * Return: Link attention type in terms of base driver's coding.
4069 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
4070 struct lpfc_acqe_link
*acqe_link
)
4074 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
4075 case LPFC_ASYNC_LINK_STATUS_DOWN
:
4076 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
4077 att_type
= LPFC_ATT_LINK_DOWN
;
4079 case LPFC_ASYNC_LINK_STATUS_UP
:
4080 /* Ignore physical link up events - wait for logical link up */
4081 att_type
= LPFC_ATT_RESERVED
;
4083 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
4084 att_type
= LPFC_ATT_LINK_UP
;
4087 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4088 "0399 Invalid link attention type: x%x\n",
4089 bf_get(lpfc_acqe_link_status
, acqe_link
));
4090 att_type
= LPFC_ATT_RESERVED
;
4097 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4098 * @phba: pointer to lpfc hba data structure.
4100 * This routine is to get an SLI3 FC port's link speed in Mbps.
4102 * Return: link speed in terms of Mbps.
4105 lpfc_sli_port_speed_get(struct lpfc_hba
*phba
)
4107 uint32_t link_speed
;
4109 if (!lpfc_is_link_up(phba
))
4112 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
4113 switch (phba
->fc_linkspeed
) {
4114 case LPFC_LINK_SPEED_1GHZ
:
4117 case LPFC_LINK_SPEED_2GHZ
:
4120 case LPFC_LINK_SPEED_4GHZ
:
4123 case LPFC_LINK_SPEED_8GHZ
:
4126 case LPFC_LINK_SPEED_10GHZ
:
4129 case LPFC_LINK_SPEED_16GHZ
:
4136 if (phba
->sli4_hba
.link_state
.logical_speed
)
4138 phba
->sli4_hba
.link_state
.logical_speed
;
4140 link_speed
= phba
->sli4_hba
.link_state
.speed
;
4146 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4147 * @phba: pointer to lpfc hba data structure.
4148 * @evt_code: asynchronous event code.
4149 * @speed_code: asynchronous event link speed code.
4151 * This routine is to parse the giving SLI4 async event link speed code into
4152 * value of Mbps for the link speed.
4154 * Return: link speed in terms of Mbps.
4157 lpfc_sli4_port_speed_parse(struct lpfc_hba
*phba
, uint32_t evt_code
,
4160 uint32_t port_speed
;
4163 case LPFC_TRAILER_CODE_LINK
:
4164 switch (speed_code
) {
4165 case LPFC_ASYNC_LINK_SPEED_ZERO
:
4168 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
4171 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
4174 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
4177 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
4180 case LPFC_ASYNC_LINK_SPEED_20GBPS
:
4183 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
4186 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
4193 case LPFC_TRAILER_CODE_FC
:
4194 switch (speed_code
) {
4195 case LPFC_FC_LA_SPEED_UNKNOWN
:
4198 case LPFC_FC_LA_SPEED_1G
:
4201 case LPFC_FC_LA_SPEED_2G
:
4204 case LPFC_FC_LA_SPEED_4G
:
4207 case LPFC_FC_LA_SPEED_8G
:
4210 case LPFC_FC_LA_SPEED_10G
:
4213 case LPFC_FC_LA_SPEED_16G
:
4216 case LPFC_FC_LA_SPEED_32G
:
4230 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4231 * @phba: pointer to lpfc hba data structure.
4232 * @acqe_link: pointer to the async link completion queue entry.
4234 * This routine is to handle the SLI4 asynchronous FCoE link event.
4237 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
4238 struct lpfc_acqe_link
*acqe_link
)
4240 struct lpfc_dmabuf
*mp
;
4243 struct lpfc_mbx_read_top
*la
;
4247 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
4248 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
4250 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
4251 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4253 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4254 "0395 The mboxq allocation failed\n");
4257 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4259 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4260 "0396 The lpfc_dmabuf allocation failed\n");
4263 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
4265 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4266 "0397 The mbuf allocation failed\n");
4267 goto out_free_dmabuf
;
4270 /* Cleanup any outstanding ELS commands */
4271 lpfc_els_flush_all_cmd(phba
);
4273 /* Block ELS IOCBs until we have done process link event */
4274 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
4276 /* Update link event statistics */
4277 phba
->sli
.slistat
.link_event
++;
4279 /* Create lpfc_handle_latt mailbox command from link ACQE */
4280 lpfc_read_topology(phba
, pmb
, mp
);
4281 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
4282 pmb
->vport
= phba
->pport
;
4284 /* Keep the link status for extra SLI4 state machine reference */
4285 phba
->sli4_hba
.link_state
.speed
=
4286 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_LINK
,
4287 bf_get(lpfc_acqe_link_speed
, acqe_link
));
4288 phba
->sli4_hba
.link_state
.duplex
=
4289 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
4290 phba
->sli4_hba
.link_state
.status
=
4291 bf_get(lpfc_acqe_link_status
, acqe_link
);
4292 phba
->sli4_hba
.link_state
.type
=
4293 bf_get(lpfc_acqe_link_type
, acqe_link
);
4294 phba
->sli4_hba
.link_state
.number
=
4295 bf_get(lpfc_acqe_link_number
, acqe_link
);
4296 phba
->sli4_hba
.link_state
.fault
=
4297 bf_get(lpfc_acqe_link_fault
, acqe_link
);
4298 phba
->sli4_hba
.link_state
.logical_speed
=
4299 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
) * 10;
4301 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4302 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4303 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4304 "Logical speed:%dMbps Fault:%d\n",
4305 phba
->sli4_hba
.link_state
.speed
,
4306 phba
->sli4_hba
.link_state
.topology
,
4307 phba
->sli4_hba
.link_state
.status
,
4308 phba
->sli4_hba
.link_state
.type
,
4309 phba
->sli4_hba
.link_state
.number
,
4310 phba
->sli4_hba
.link_state
.logical_speed
,
4311 phba
->sli4_hba
.link_state
.fault
);
4313 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4314 * topology info. Note: Optional for non FC-AL ports.
4316 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
4317 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4318 if (rc
== MBX_NOT_FINISHED
)
4319 goto out_free_dmabuf
;
4323 * For FCoE Mode: fill in all the topology information we need and call
4324 * the READ_TOPOLOGY completion routine to continue without actually
4325 * sending the READ_TOPOLOGY mailbox command to the port.
4327 /* Parse and translate status field */
4329 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
4331 /* Parse and translate link attention fields */
4332 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
4333 la
->eventTag
= acqe_link
->event_tag
;
4334 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
4335 bf_set(lpfc_mbx_read_top_link_spd
, la
,
4336 (bf_get(lpfc_acqe_link_speed
, acqe_link
)));
4338 /* Fake the the following irrelvant fields */
4339 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
4340 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
4341 bf_set(lpfc_mbx_read_top_il
, la
, 0);
4342 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
4343 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
4344 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
4346 /* Invoke the lpfc_handle_latt mailbox command callback function */
4347 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
4354 mempool_free(pmb
, phba
->mbox_mem_pool
);
4358 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4359 * @phba: pointer to lpfc hba data structure.
4360 * @acqe_fc: pointer to the async fc completion queue entry.
4362 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4363 * that the event was received and then issue a read_topology mailbox command so
4364 * that the rest of the driver will treat it the same as SLI3.
4367 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
4369 struct lpfc_dmabuf
*mp
;
4372 struct lpfc_mbx_read_top
*la
;
4375 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
4376 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
4377 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4378 "2895 Non FC link Event detected.(%d)\n",
4379 bf_get(lpfc_trailer_type
, acqe_fc
));
4382 /* Keep the link status for extra SLI4 state machine reference */
4383 phba
->sli4_hba
.link_state
.speed
=
4384 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
4385 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
4386 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
4387 phba
->sli4_hba
.link_state
.topology
=
4388 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
4389 phba
->sli4_hba
.link_state
.status
=
4390 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
4391 phba
->sli4_hba
.link_state
.type
=
4392 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
4393 phba
->sli4_hba
.link_state
.number
=
4394 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
4395 phba
->sli4_hba
.link_state
.fault
=
4396 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
4397 phba
->sli4_hba
.link_state
.logical_speed
=
4398 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
4399 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4400 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4401 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4402 "%dMbps Fault:%d\n",
4403 phba
->sli4_hba
.link_state
.speed
,
4404 phba
->sli4_hba
.link_state
.topology
,
4405 phba
->sli4_hba
.link_state
.status
,
4406 phba
->sli4_hba
.link_state
.type
,
4407 phba
->sli4_hba
.link_state
.number
,
4408 phba
->sli4_hba
.link_state
.logical_speed
,
4409 phba
->sli4_hba
.link_state
.fault
);
4410 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4412 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4413 "2897 The mboxq allocation failed\n");
4416 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4418 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4419 "2898 The lpfc_dmabuf allocation failed\n");
4422 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
4424 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4425 "2899 The mbuf allocation failed\n");
4426 goto out_free_dmabuf
;
4429 /* Cleanup any outstanding ELS commands */
4430 lpfc_els_flush_all_cmd(phba
);
4432 /* Block ELS IOCBs until we have done process link event */
4433 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
4435 /* Update link event statistics */
4436 phba
->sli
.slistat
.link_event
++;
4438 /* Create lpfc_handle_latt mailbox command from link ACQE */
4439 lpfc_read_topology(phba
, pmb
, mp
);
4440 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
4441 pmb
->vport
= phba
->pport
;
4443 if (phba
->sli4_hba
.link_state
.status
!= LPFC_FC_LA_TYPE_LINK_UP
) {
4444 /* Parse and translate status field */
4446 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
,
4449 /* Parse and translate link attention fields */
4450 la
= (struct lpfc_mbx_read_top
*)&pmb
->u
.mb
.un
.varReadTop
;
4451 la
->eventTag
= acqe_fc
->event_tag
;
4452 bf_set(lpfc_mbx_read_top_att_type
, la
,
4453 LPFC_FC_LA_TYPE_LINK_DOWN
);
4455 /* Invoke the mailbox command callback function */
4456 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
4461 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4462 if (rc
== MBX_NOT_FINISHED
)
4463 goto out_free_dmabuf
;
4469 mempool_free(pmb
, phba
->mbox_mem_pool
);
4473 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4474 * @phba: pointer to lpfc hba data structure.
4475 * @acqe_fc: pointer to the async SLI completion queue entry.
4477 * This routine is to handle the SLI4 asynchronous SLI events.
4480 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
4486 uint8_t operational
= 0;
4487 struct temp_event temp_event_data
;
4488 struct lpfc_acqe_misconfigured_event
*misconfigured
;
4489 struct Scsi_Host
*shost
;
4491 evt_type
= bf_get(lpfc_trailer_type
, acqe_sli
);
4493 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4494 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4495 "x%08x SLI Event Type:%d\n",
4496 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
4499 port_name
= phba
->Port
[0];
4500 if (port_name
== 0x00)
4501 port_name
= '?'; /* get port name is empty */
4504 case LPFC_SLI_EVENT_TYPE_OVER_TEMP
:
4505 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
4506 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
4507 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
4509 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4510 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4511 acqe_sli
->event_data1
, port_name
);
4513 phba
->sfp_warning
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
4514 shost
= lpfc_shost_from_vport(phba
->pport
);
4515 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4516 sizeof(temp_event_data
),
4517 (char *)&temp_event_data
,
4518 SCSI_NL_VID_TYPE_PCI
4519 | PCI_VENDOR_ID_EMULEX
);
4521 case LPFC_SLI_EVENT_TYPE_NORM_TEMP
:
4522 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
4523 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
4524 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
4526 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4527 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4528 acqe_sli
->event_data1
, port_name
);
4530 shost
= lpfc_shost_from_vport(phba
->pport
);
4531 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4532 sizeof(temp_event_data
),
4533 (char *)&temp_event_data
,
4534 SCSI_NL_VID_TYPE_PCI
4535 | PCI_VENDOR_ID_EMULEX
);
4537 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED
:
4538 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
4539 &acqe_sli
->event_data1
;
4541 /* fetch the status for this port */
4542 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4543 case LPFC_LINK_NUMBER_0
:
4544 status
= bf_get(lpfc_sli_misconfigured_port0_state
,
4545 &misconfigured
->theEvent
);
4546 operational
= bf_get(lpfc_sli_misconfigured_port0_op
,
4547 &misconfigured
->theEvent
);
4549 case LPFC_LINK_NUMBER_1
:
4550 status
= bf_get(lpfc_sli_misconfigured_port1_state
,
4551 &misconfigured
->theEvent
);
4552 operational
= bf_get(lpfc_sli_misconfigured_port1_op
,
4553 &misconfigured
->theEvent
);
4555 case LPFC_LINK_NUMBER_2
:
4556 status
= bf_get(lpfc_sli_misconfigured_port2_state
,
4557 &misconfigured
->theEvent
);
4558 operational
= bf_get(lpfc_sli_misconfigured_port2_op
,
4559 &misconfigured
->theEvent
);
4561 case LPFC_LINK_NUMBER_3
:
4562 status
= bf_get(lpfc_sli_misconfigured_port3_state
,
4563 &misconfigured
->theEvent
);
4564 operational
= bf_get(lpfc_sli_misconfigured_port3_op
,
4565 &misconfigured
->theEvent
);
4568 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4570 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4571 "event: Invalid link %d",
4572 phba
->sli4_hba
.lnk_info
.lnk_no
);
4576 /* Skip if optic state unchanged */
4577 if (phba
->sli4_hba
.lnk_info
.optic_state
== status
)
4581 case LPFC_SLI_EVENT_STATUS_VALID
:
4582 sprintf(message
, "Physical Link is functional");
4584 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
4585 sprintf(message
, "Optics faulted/incorrectly "
4586 "installed/not installed - Reseat optics, "
4587 "if issue not resolved, replace.");
4589 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
4591 "Optics of two types installed - Remove one "
4592 "optic or install matching pair of optics.");
4594 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
4595 sprintf(message
, "Incompatible optics - Replace with "
4596 "compatible optics for card to function.");
4598 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED
:
4599 sprintf(message
, "Unqualified optics - Replace with "
4600 "Avago optics for Warranty and Technical "
4601 "Support - Link is%s operational",
4602 (operational
) ? " not" : "");
4604 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED
:
4605 sprintf(message
, "Uncertified optics - Replace with "
4606 "Avago-certified optics to enable link "
4607 "operation - Link is%s operational",
4608 (operational
) ? " not" : "");
4611 /* firmware is reporting a status we don't know about */
4612 sprintf(message
, "Unknown event status x%02x", status
);
4615 phba
->sli4_hba
.lnk_info
.optic_state
= status
;
4616 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4617 "3176 Port Name %c %s\n", port_name
, message
);
4619 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT
:
4620 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4621 "3192 Remote DPort Test Initiated - "
4622 "Event Data1:x%08x Event Data2: x%08x\n",
4623 acqe_sli
->event_data1
, acqe_sli
->event_data2
);
4626 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4627 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4628 "x%08x SLI Event Type:%d\n",
4629 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
4636 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4637 * @vport: pointer to vport data structure.
4639 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4640 * response to a CVL event.
4642 * Return the pointer to the ndlp with the vport if successful, otherwise
4645 static struct lpfc_nodelist
*
4646 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
4648 struct lpfc_nodelist
*ndlp
;
4649 struct Scsi_Host
*shost
;
4650 struct lpfc_hba
*phba
;
4657 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
4659 /* Cannot find existing Fabric ndlp, so allocate a new one */
4660 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4663 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
4664 /* Set the node type */
4665 ndlp
->nlp_type
|= NLP_FABRIC
;
4666 /* Put ndlp onto node list */
4667 lpfc_enqueue_node(vport
, ndlp
);
4668 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4669 /* re-setup ndlp without removing from node list */
4670 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4674 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
4675 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
4677 /* If virtual link is not yet instantiated ignore CVL */
4678 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
4679 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
4681 shost
= lpfc_shost_from_vport(vport
);
4684 lpfc_linkdown_port(vport
);
4685 lpfc_cleanup_pending_mbox(vport
);
4686 spin_lock_irq(shost
->host_lock
);
4687 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
4688 spin_unlock_irq(shost
->host_lock
);
4694 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4695 * @vport: pointer to lpfc hba data structure.
4697 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4698 * response to a FCF dead event.
4701 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
4703 struct lpfc_vport
**vports
;
4706 vports
= lpfc_create_vport_work_array(phba
);
4708 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
4709 lpfc_sli4_perform_vport_cvl(vports
[i
]);
4710 lpfc_destroy_vport_work_array(phba
, vports
);
4714 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4715 * @phba: pointer to lpfc hba data structure.
4716 * @acqe_link: pointer to the async fcoe completion queue entry.
4718 * This routine is to handle the SLI4 asynchronous fcoe event.
4721 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
4722 struct lpfc_acqe_fip
*acqe_fip
)
4724 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
4726 struct lpfc_vport
*vport
;
4727 struct lpfc_nodelist
*ndlp
;
4728 struct Scsi_Host
*shost
;
4729 int active_vlink_present
;
4730 struct lpfc_vport
**vports
;
4733 phba
->fc_eventTag
= acqe_fip
->event_tag
;
4734 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
4735 switch (event_type
) {
4736 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
4737 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
4738 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
4739 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4741 "2546 New FCF event, evt_tag:x%x, "
4743 acqe_fip
->event_tag
,
4746 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
4748 "2788 FCF param modified event, "
4749 "evt_tag:x%x, index:x%x\n",
4750 acqe_fip
->event_tag
,
4752 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4754 * During period of FCF discovery, read the FCF
4755 * table record indexed by the event to update
4756 * FCF roundrobin failover eligible FCF bmask.
4758 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4760 "2779 Read FCF (x%x) for updating "
4761 "roundrobin FCF failover bmask\n",
4763 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
4766 /* If the FCF discovery is in progress, do nothing. */
4767 spin_lock_irq(&phba
->hbalock
);
4768 if (phba
->hba_flag
& FCF_TS_INPROG
) {
4769 spin_unlock_irq(&phba
->hbalock
);
4772 /* If fast FCF failover rescan event is pending, do nothing */
4773 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
4774 spin_unlock_irq(&phba
->hbalock
);
4778 /* If the FCF has been in discovered state, do nothing. */
4779 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
4780 spin_unlock_irq(&phba
->hbalock
);
4783 spin_unlock_irq(&phba
->hbalock
);
4785 /* Otherwise, scan the entire FCF table and re-discover SAN */
4786 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4787 "2770 Start FCF table scan per async FCF "
4788 "event, evt_tag:x%x, index:x%x\n",
4789 acqe_fip
->event_tag
, acqe_fip
->index
);
4790 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
4791 LPFC_FCOE_FCF_GET_FIRST
);
4793 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4794 "2547 Issue FCF scan read FCF mailbox "
4795 "command failed (x%x)\n", rc
);
4798 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
4799 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4800 "2548 FCF Table full count 0x%x tag 0x%x\n",
4801 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
4802 acqe_fip
->event_tag
);
4805 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
4806 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4807 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4808 "2549 FCF (x%x) disconnected from network, "
4809 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4811 * If we are in the middle of FCF failover process, clear
4812 * the corresponding FCF bit in the roundrobin bitmap.
4814 spin_lock_irq(&phba
->hbalock
);
4815 if ((phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
4816 (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)) {
4817 spin_unlock_irq(&phba
->hbalock
);
4818 /* Update FLOGI FCF failover eligible FCF bmask */
4819 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
4822 spin_unlock_irq(&phba
->hbalock
);
4824 /* If the event is not for currently used fcf do nothing */
4825 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
4829 * Otherwise, request the port to rediscover the entire FCF
4830 * table for a fast recovery from case that the current FCF
4831 * is no longer valid as we are not in the middle of FCF
4832 * failover process already.
4834 spin_lock_irq(&phba
->hbalock
);
4835 /* Mark the fast failover process in progress */
4836 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
4837 spin_unlock_irq(&phba
->hbalock
);
4839 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4840 "2771 Start FCF fast failover process due to "
4841 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4842 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
4843 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4845 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4847 "2772 Issue FCF rediscover mabilbox "
4848 "command failed, fail through to FCF "
4850 spin_lock_irq(&phba
->hbalock
);
4851 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
4852 spin_unlock_irq(&phba
->hbalock
);
4854 * Last resort will fail over by treating this
4855 * as a link down to FCF registration.
4857 lpfc_sli4_fcf_dead_failthrough(phba
);
4859 /* Reset FCF roundrobin bmask for new discovery */
4860 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4862 * Handling fast FCF failover to a DEAD FCF event is
4863 * considered equalivant to receiving CVL to all vports.
4865 lpfc_sli4_perform_all_vport_cvl(phba
);
4868 case LPFC_FIP_EVENT_TYPE_CVL
:
4869 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4870 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4871 "2718 Clear Virtual Link Received for VPI 0x%x"
4872 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4874 vport
= lpfc_find_vport_by_vpid(phba
,
4876 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
4879 active_vlink_present
= 0;
4881 vports
= lpfc_create_vport_work_array(phba
);
4883 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
4885 if ((!(vports
[i
]->fc_flag
&
4886 FC_VPORT_CVL_RCVD
)) &&
4887 (vports
[i
]->port_state
> LPFC_FDISC
)) {
4888 active_vlink_present
= 1;
4892 lpfc_destroy_vport_work_array(phba
, vports
);
4896 * Don't re-instantiate if vport is marked for deletion.
4897 * If we are here first then vport_delete is going to wait
4898 * for discovery to complete.
4900 if (!(vport
->load_flag
& FC_UNLOADING
) &&
4901 active_vlink_present
) {
4903 * If there are other active VLinks present,
4904 * re-instantiate the Vlink using FDISC.
4906 mod_timer(&ndlp
->nlp_delayfunc
,
4907 jiffies
+ msecs_to_jiffies(1000));
4908 shost
= lpfc_shost_from_vport(vport
);
4909 spin_lock_irq(shost
->host_lock
);
4910 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
4911 spin_unlock_irq(shost
->host_lock
);
4912 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
4913 vport
->port_state
= LPFC_FDISC
;
4916 * Otherwise, we request port to rediscover
4917 * the entire FCF table for a fast recovery
4918 * from possible case that the current FCF
4919 * is no longer valid if we are not already
4920 * in the FCF failover process.
4922 spin_lock_irq(&phba
->hbalock
);
4923 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4924 spin_unlock_irq(&phba
->hbalock
);
4927 /* Mark the fast failover process in progress */
4928 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
4929 spin_unlock_irq(&phba
->hbalock
);
4930 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4932 "2773 Start FCF failover per CVL, "
4933 "evt_tag:x%x\n", acqe_fip
->event_tag
);
4934 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4936 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4938 "2774 Issue FCF rediscover "
4939 "mabilbox command failed, "
4940 "through to CVL event\n");
4941 spin_lock_irq(&phba
->hbalock
);
4942 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
4943 spin_unlock_irq(&phba
->hbalock
);
4945 * Last resort will be re-try on the
4946 * the current registered FCF entry.
4948 lpfc_retry_pport_discovery(phba
);
4951 * Reset FCF roundrobin bmask for new
4954 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4958 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4959 "0288 Unknown FCoE event type 0x%x event tag "
4960 "0x%x\n", event_type
, acqe_fip
->event_tag
);
4966 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4967 * @phba: pointer to lpfc hba data structure.
4968 * @acqe_link: pointer to the async dcbx completion queue entry.
4970 * This routine is to handle the SLI4 asynchronous dcbx event.
4973 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
4974 struct lpfc_acqe_dcbx
*acqe_dcbx
)
4976 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
4977 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4978 "0290 The SLI4 DCBX asynchronous event is not "
4983 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4984 * @phba: pointer to lpfc hba data structure.
4985 * @acqe_link: pointer to the async grp5 completion queue entry.
4987 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4988 * is an asynchronous notified of a logical link speed change. The Port
4989 * reports the logical link speed in units of 10Mbps.
4992 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
4993 struct lpfc_acqe_grp5
*acqe_grp5
)
4995 uint16_t prev_ll_spd
;
4997 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
4998 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
4999 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
5000 phba
->sli4_hba
.link_state
.logical_speed
=
5001 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
)) * 10;
5002 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5003 "2789 GRP5 Async Event: Updating logical link speed "
5004 "from %dMbps to %dMbps\n", prev_ll_spd
,
5005 phba
->sli4_hba
.link_state
.logical_speed
);
5009 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5010 * @phba: pointer to lpfc hba data structure.
5012 * This routine is invoked by the worker thread to process all the pending
5013 * SLI4 asynchronous events.
5015 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
5017 struct lpfc_cq_event
*cq_event
;
5019 /* First, declare the async event has been handled */
5020 spin_lock_irq(&phba
->hbalock
);
5021 phba
->hba_flag
&= ~ASYNC_EVENT
;
5022 spin_unlock_irq(&phba
->hbalock
);
5023 /* Now, handle all the async events */
5024 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
5025 /* Get the first event from the head of the event queue */
5026 spin_lock_irq(&phba
->hbalock
);
5027 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
5028 cq_event
, struct lpfc_cq_event
, list
);
5029 spin_unlock_irq(&phba
->hbalock
);
5030 /* Process the asynchronous event */
5031 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
5032 case LPFC_TRAILER_CODE_LINK
:
5033 lpfc_sli4_async_link_evt(phba
,
5034 &cq_event
->cqe
.acqe_link
);
5036 case LPFC_TRAILER_CODE_FCOE
:
5037 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
5039 case LPFC_TRAILER_CODE_DCBX
:
5040 lpfc_sli4_async_dcbx_evt(phba
,
5041 &cq_event
->cqe
.acqe_dcbx
);
5043 case LPFC_TRAILER_CODE_GRP5
:
5044 lpfc_sli4_async_grp5_evt(phba
,
5045 &cq_event
->cqe
.acqe_grp5
);
5047 case LPFC_TRAILER_CODE_FC
:
5048 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
5050 case LPFC_TRAILER_CODE_SLI
:
5051 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
5054 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5055 "1804 Invalid asynchrous event code: "
5056 "x%x\n", bf_get(lpfc_trailer_code
,
5057 &cq_event
->cqe
.mcqe_cmpl
));
5060 /* Free the completion event processed to the free pool */
5061 lpfc_sli4_cq_event_release(phba
, cq_event
);
5066 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5067 * @phba: pointer to lpfc hba data structure.
5069 * This routine is invoked by the worker thread to process FCF table
5070 * rediscovery pending completion event.
5072 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
5076 spin_lock_irq(&phba
->hbalock
);
5077 /* Clear FCF rediscovery timeout event */
5078 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
5079 /* Clear driver fast failover FCF record flag */
5080 phba
->fcf
.failover_rec
.flag
= 0;
5081 /* Set state for FCF fast failover */
5082 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
5083 spin_unlock_irq(&phba
->hbalock
);
5085 /* Scan FCF table from the first entry to re-discover SAN */
5086 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
5087 "2777 Start post-quiescent FCF table scan\n");
5088 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
5090 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
5091 "2747 Issue FCF scan read FCF mailbox "
5092 "command failed 0x%x\n", rc
);
5096 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5097 * @phba: pointer to lpfc hba data structure.
5098 * @dev_grp: The HBA PCI-Device group number.
5100 * This routine is invoked to set up the per HBA PCI-Device group function
5101 * API jump table entries.
5103 * Return: 0 if success, otherwise -ENODEV
5106 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5110 /* Set up lpfc PCI-device group */
5111 phba
->pci_dev_grp
= dev_grp
;
5113 /* The LPFC_PCI_DEV_OC uses SLI4 */
5114 if (dev_grp
== LPFC_PCI_DEV_OC
)
5115 phba
->sli_rev
= LPFC_SLI_REV4
;
5117 /* Set up device INIT API function jump table */
5118 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
5121 /* Set up SCSI API function jump table */
5122 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
5125 /* Set up SLI API function jump table */
5126 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
5129 /* Set up MBOX API function jump table */
5130 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
5138 * lpfc_log_intr_mode - Log the active interrupt mode
5139 * @phba: pointer to lpfc hba data structure.
5140 * @intr_mode: active interrupt mode adopted.
5142 * This routine it invoked to log the currently used active interrupt mode
5145 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
5147 switch (intr_mode
) {
5149 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5150 "0470 Enable INTx interrupt mode.\n");
5153 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5154 "0481 Enabled MSI interrupt mode.\n");
5157 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5158 "0480 Enabled MSI-X interrupt mode.\n");
5161 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5162 "0482 Illegal interrupt mode.\n");
5169 * lpfc_enable_pci_dev - Enable a generic PCI device.
5170 * @phba: pointer to lpfc hba data structure.
5172 * This routine is invoked to enable the PCI device that is common to all
5177 * other values - error
5180 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
5182 struct pci_dev
*pdev
;
5184 /* Obtain PCI device reference */
5188 pdev
= phba
->pcidev
;
5189 /* Enable PCI device */
5190 if (pci_enable_device_mem(pdev
))
5192 /* Request PCI resource for the device */
5193 if (pci_request_mem_regions(pdev
, LPFC_DRIVER_NAME
))
5194 goto out_disable_device
;
5195 /* Set up device as PCI master and save state for EEH */
5196 pci_set_master(pdev
);
5197 pci_try_set_mwi(pdev
);
5198 pci_save_state(pdev
);
5200 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5201 if (pci_is_pcie(pdev
))
5202 pdev
->needs_freset
= 1;
5207 pci_disable_device(pdev
);
5209 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5210 "1401 Failed to enable pci device\n");
5215 * lpfc_disable_pci_dev - Disable a generic PCI device.
5216 * @phba: pointer to lpfc hba data structure.
5218 * This routine is invoked to disable the PCI device that is common to all
5222 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
5224 struct pci_dev
*pdev
;
5226 /* Obtain PCI device reference */
5230 pdev
= phba
->pcidev
;
5231 /* Release PCI resource and disable PCI device */
5232 pci_release_mem_regions(pdev
);
5233 pci_disable_device(pdev
);
5239 * lpfc_reset_hba - Reset a hba
5240 * @phba: pointer to lpfc hba data structure.
5242 * This routine is invoked to reset a hba device. It brings the HBA
5243 * offline, performs a board restart, and then brings the board back
5244 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5245 * on outstanding mailbox commands.
5248 lpfc_reset_hba(struct lpfc_hba
*phba
)
5250 /* If resets are disabled then set error state and return. */
5251 if (!phba
->cfg_enable_hba_reset
) {
5252 phba
->link_state
= LPFC_HBA_ERROR
;
5255 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
5256 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
5258 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
5260 lpfc_sli_brdrestart(phba
);
5262 lpfc_unblock_mgmt_io(phba
);
5266 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5267 * @phba: pointer to lpfc hba data structure.
5269 * This function enables the PCI SR-IOV virtual functions to a physical
5270 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5271 * enable the number of virtual functions to the physical function. As
5272 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5273 * API call does not considered as an error condition for most of the device.
5276 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
5278 struct pci_dev
*pdev
= phba
->pcidev
;
5282 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
5286 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
5291 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5292 * @phba: pointer to lpfc hba data structure.
5293 * @nr_vfn: number of virtual functions to be enabled.
5295 * This function enables the PCI SR-IOV virtual functions to a physical
5296 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5297 * enable the number of virtual functions to the physical function. As
5298 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5299 * API call does not considered as an error condition for most of the device.
5302 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
5304 struct pci_dev
*pdev
= phba
->pcidev
;
5305 uint16_t max_nr_vfn
;
5308 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
5309 if (nr_vfn
> max_nr_vfn
) {
5310 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5311 "3057 Requested vfs (%d) greater than "
5312 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
5316 rc
= pci_enable_sriov(pdev
, nr_vfn
);
5318 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5319 "2806 Failed to enable sriov on this device "
5320 "with vfn number nr_vf:%d, rc:%d\n",
5323 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5324 "2807 Successful enable sriov on this device "
5325 "with vfn number nr_vf:%d\n", nr_vfn
);
5330 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5331 * @phba: pointer to lpfc hba data structure.
5333 * This routine is invoked to set up the driver internal resources before the
5334 * device specific resource setup to support the HBA device it attached to.
5338 * other values - error
5341 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
5343 struct lpfc_sli
*psli
= &phba
->sli
;
5346 * Driver resources common to all SLI revisions
5348 atomic_set(&phba
->fast_event_count
, 0);
5349 spin_lock_init(&phba
->hbalock
);
5351 /* Initialize ndlp management spinlock */
5352 spin_lock_init(&phba
->ndlp_lock
);
5354 INIT_LIST_HEAD(&phba
->port_list
);
5355 INIT_LIST_HEAD(&phba
->work_list
);
5356 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
5358 /* Initialize the wait queue head for the kernel thread */
5359 init_waitqueue_head(&phba
->work_waitq
);
5361 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5362 "1403 Protocols supported %s %s %s\n",
5363 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) ?
5365 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) ?
5367 (phba
->nvmet_support
? "NVMET" : " "));
5369 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
5370 /* Initialize the scsi buffer list used by driver for scsi IO */
5371 spin_lock_init(&phba
->scsi_buf_list_get_lock
);
5372 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_get
);
5373 spin_lock_init(&phba
->scsi_buf_list_put_lock
);
5374 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
5377 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
5378 (phba
->nvmet_support
== 0)) {
5379 /* Initialize the NVME buffer list used by driver for NVME IO */
5380 spin_lock_init(&phba
->nvme_buf_list_get_lock
);
5381 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_get
);
5382 spin_lock_init(&phba
->nvme_buf_list_put_lock
);
5383 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_put
);
5386 /* Initialize the fabric iocb list */
5387 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
5389 /* Initialize list to save ELS buffers */
5390 INIT_LIST_HEAD(&phba
->elsbuf
);
5392 /* Initialize FCF connection rec list */
5393 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
5395 /* Initialize OAS configuration list */
5396 spin_lock_init(&phba
->devicelock
);
5397 INIT_LIST_HEAD(&phba
->luns
);
5399 /* MBOX heartbeat timer */
5400 init_timer(&psli
->mbox_tmo
);
5401 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
5402 psli
->mbox_tmo
.data
= (unsigned long) phba
;
5403 /* Fabric block timer */
5404 init_timer(&phba
->fabric_block_timer
);
5405 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
5406 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
5407 /* EA polling mode timer */
5408 init_timer(&phba
->eratt_poll
);
5409 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
5410 phba
->eratt_poll
.data
= (unsigned long) phba
;
5411 /* Heartbeat timer */
5412 init_timer(&phba
->hb_tmofunc
);
5413 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
5414 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
5420 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5421 * @phba: pointer to lpfc hba data structure.
5423 * This routine is invoked to set up the driver internal resources specific to
5424 * support the SLI-3 HBA device it attached to.
5428 * other values - error
5431 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
5436 * Initialize timers used by driver
5439 /* FCP polling mode timer */
5440 init_timer(&phba
->fcp_poll_timer
);
5441 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
5442 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
5444 /* Host attention work mask setup */
5445 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
5446 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
5448 /* Get all the module params for configuring this host */
5449 lpfc_get_cfgparam(phba
);
5450 /* Set up phase-1 common device driver resources */
5452 rc
= lpfc_setup_driver_resource_phase1(phba
);
5456 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
5457 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
5458 /* check for menlo minimum sg count */
5459 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
5460 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
5463 if (!phba
->sli
.sli3_ring
)
5464 phba
->sli
.sli3_ring
= kzalloc(LPFC_SLI3_MAX_RING
*
5465 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
5466 if (!phba
->sli
.sli3_ring
)
5470 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5471 * used to create the sg_dma_buf_pool must be dynamically calculated.
5474 /* Initialize the host templates the configured values. */
5475 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5476 lpfc_template_s3
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5478 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5479 if (phba
->cfg_enable_bg
) {
5481 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5482 * the FCP rsp, and a BDE for each. Sice we have no control
5483 * over how many protection data segments the SCSI Layer
5484 * will hand us (ie: there could be one for every block
5485 * in the IO), we just allocate enough BDEs to accomidate
5486 * our max amount and we need to limit lpfc_sg_seg_cnt to
5487 * minimize the risk of running out.
5489 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5490 sizeof(struct fcp_rsp
) +
5491 (LPFC_MAX_SG_SEG_CNT
* sizeof(struct ulp_bde64
));
5493 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SEG_CNT_DIF
)
5494 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT_DIF
;
5496 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5497 phba
->cfg_total_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
5500 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5501 * the FCP rsp, a BDE for each, and a BDE for up to
5502 * cfg_sg_seg_cnt data segments.
5504 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5505 sizeof(struct fcp_rsp
) +
5506 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
5508 /* Total BDEs in BPL for scsi_sg_list */
5509 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
5512 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
5513 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5514 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
5515 phba
->cfg_total_seg_cnt
);
5517 phba
->max_vpi
= LPFC_MAX_VPI
;
5518 /* This will be set to correct value after config_port mbox */
5519 phba
->max_vports
= 0;
5522 * Initialize the SLI Layer to run with lpfc HBAs.
5524 lpfc_sli_setup(phba
);
5525 lpfc_sli_queue_init(phba
);
5527 /* Allocate device driver memory */
5528 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
5532 * Enable sr-iov virtual functions if supported and configured
5533 * through the module parameter.
5535 if (phba
->cfg_sriov_nr_virtfn
> 0) {
5536 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
5537 phba
->cfg_sriov_nr_virtfn
);
5539 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5540 "2808 Requested number of SR-IOV "
5541 "virtual functions (%d) is not "
5543 phba
->cfg_sriov_nr_virtfn
);
5544 phba
->cfg_sriov_nr_virtfn
= 0;
5552 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5553 * @phba: pointer to lpfc hba data structure.
5555 * This routine is invoked to unset the driver internal resources set up
5556 * specific for supporting the SLI-3 HBA device it attached to.
5559 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
5561 /* Free device driver memory allocated */
5562 lpfc_mem_free_all(phba
);
5568 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5569 * @phba: pointer to lpfc hba data structure.
5571 * This routine is invoked to set up the driver internal resources specific to
5572 * support the SLI-4 HBA device it attached to.
5576 * other values - error
5579 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
5581 LPFC_MBOXQ_t
*mboxq
;
5583 int rc
, i
, max_buf_size
;
5584 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
5585 struct lpfc_mqe
*mqe
;
5587 int fof_vectors
= 0;
5590 phba
->sli4_hba
.num_online_cpu
= num_online_cpus();
5591 phba
->sli4_hba
.num_present_cpu
= lpfc_present_cpu
;
5592 phba
->sli4_hba
.curr_disp_cpu
= 0;
5594 /* Get all the module params for configuring this host */
5595 lpfc_get_cfgparam(phba
);
5597 /* Set up phase-1 common device driver resources */
5598 rc
= lpfc_setup_driver_resource_phase1(phba
);
5602 /* Before proceed, wait for POST done and device ready */
5603 rc
= lpfc_sli4_post_status_check(phba
);
5608 * Initialize timers used by driver
5611 init_timer(&phba
->rrq_tmr
);
5612 phba
->rrq_tmr
.function
= lpfc_rrq_timeout
;
5613 phba
->rrq_tmr
.data
= (unsigned long)phba
;
5615 /* FCF rediscover timer */
5616 init_timer(&phba
->fcf
.redisc_wait
);
5617 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
5618 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
5621 * Control structure for handling external multi-buffer mailbox
5622 * command pass-through.
5624 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
5625 sizeof(struct lpfc_mbox_ext_buf_ctx
));
5626 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
5628 phba
->max_vpi
= LPFC_MAX_VPI
;
5630 /* This will be set to correct value after the read_config mbox */
5631 phba
->max_vports
= 0;
5633 /* Program the default value of vlan_id and fc_map */
5634 phba
->valid_vlan
= 0;
5635 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
5636 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
5637 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
5640 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5641 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5642 * The WQ create will allocate the ring.
5646 * It doesn't matter what family our adapter is in, we are
5647 * limited to 2 Pages, 512 SGEs, for our SGL.
5648 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5650 max_buf_size
= (2 * SLI4_PAGE_SIZE
);
5651 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SGL_SEG_CNT
- 2)
5652 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
- 2;
5655 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5656 * used to create the sg_dma_buf_pool must be calculated.
5658 if (phba
->cfg_enable_bg
) {
5660 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5661 * the FCP rsp, and a SGE. Sice we have no control
5662 * over how many protection segments the SCSI Layer
5663 * will hand us (ie: there could be one for every block
5664 * in the IO), just allocate enough SGEs to accomidate
5665 * our max amount and we need to limit lpfc_sg_seg_cnt
5666 * to minimize the risk of running out.
5668 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5669 sizeof(struct fcp_rsp
) + max_buf_size
;
5671 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5672 phba
->cfg_total_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
;
5674 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SLI4_SEG_CNT_DIF
)
5675 phba
->cfg_sg_seg_cnt
=
5676 LPFC_MAX_SG_SLI4_SEG_CNT_DIF
;
5679 * The scsi_buf for a regular I/O holds the FCP cmnd,
5680 * the FCP rsp, a SGE for each, and a SGE for up to
5681 * cfg_sg_seg_cnt data segments.
5683 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5684 sizeof(struct fcp_rsp
) +
5685 ((phba
->cfg_sg_seg_cnt
+ 2) *
5686 sizeof(struct sli4_sge
));
5688 /* Total SGEs for scsi_sg_list */
5689 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
5692 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5693 * need to post 1 page for the SGL.
5697 /* Initialize the host templates with the updated values. */
5698 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5699 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5701 if (phba
->cfg_sg_dma_buf_size
<= LPFC_MIN_SG_SLI4_BUF_SZ
)
5702 phba
->cfg_sg_dma_buf_size
= LPFC_MIN_SG_SLI4_BUF_SZ
;
5704 phba
->cfg_sg_dma_buf_size
=
5705 SLI4_PAGE_ALIGN(phba
->cfg_sg_dma_buf_size
);
5707 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
5708 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5709 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
5710 phba
->cfg_total_seg_cnt
);
5712 /* Initialize buffer queue management fields */
5713 INIT_LIST_HEAD(&phba
->hbqs
[LPFC_ELS_HBQ
].hbq_buffer_list
);
5714 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
5715 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
5718 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5720 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
5721 /* Initialize the Abort scsi buffer list used by driver */
5722 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
5723 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
5726 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
5727 /* Initialize the Abort nvme buffer list used by driver */
5728 spin_lock_init(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
5729 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
5732 /* This abort list used by worker thread */
5733 spin_lock_init(&phba
->sli4_hba
.sgl_list_lock
);
5734 spin_lock_init(&phba
->sli4_hba
.nvmet_io_lock
);
5737 * Initialize driver internal slow-path work queues
5740 /* Driver internel slow-path CQ Event pool */
5741 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
5742 /* Response IOCB work queue list */
5743 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
5744 /* Asynchronous event CQ Event work queue list */
5745 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
5746 /* Fast-path XRI aborted CQ Event work queue list */
5747 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
5748 /* Slow-path XRI aborted CQ Event work queue list */
5749 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
5750 /* Receive queue CQ Event work queue list */
5751 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
5753 /* Initialize extent block lists. */
5754 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
5755 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
5756 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
5757 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
5759 /* initialize optic_state to 0xFF */
5760 phba
->sli4_hba
.lnk_info
.optic_state
= 0xff;
5762 /* Allocate device driver memory */
5763 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
5767 /* IF Type 2 ports get initialized now. */
5768 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5769 LPFC_SLI_INTF_IF_TYPE_2
) {
5770 rc
= lpfc_pci_function_reset(phba
);
5775 phba
->temp_sensor_support
= 1;
5778 /* Create the bootstrap mailbox command */
5779 rc
= lpfc_create_bootstrap_mbox(phba
);
5783 /* Set up the host's endian order with the device. */
5784 rc
= lpfc_setup_endian_order(phba
);
5786 goto out_free_bsmbx
;
5788 /* Set up the hba's configuration parameters. */
5789 rc
= lpfc_sli4_read_config(phba
);
5791 goto out_free_bsmbx
;
5792 rc
= lpfc_mem_alloc_active_rrq_pool_s4(phba
);
5794 goto out_free_bsmbx
;
5796 /* IF Type 0 ports get initialized now. */
5797 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5798 LPFC_SLI_INTF_IF_TYPE_0
) {
5799 rc
= lpfc_pci_function_reset(phba
);
5801 goto out_free_bsmbx
;
5804 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
5808 goto out_free_bsmbx
;
5811 /* Check for NVMET being configured */
5812 phba
->nvmet_support
= 0;
5813 if (lpfc_enable_nvmet_cnt
) {
5815 /* First get WWN of HBA instance */
5816 lpfc_read_nv(phba
, mboxq
);
5817 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5818 if (rc
!= MBX_SUCCESS
) {
5819 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5820 "6016 Mailbox failed , mbxCmd x%x "
5821 "READ_NV, mbxStatus x%x\n",
5822 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5823 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
5825 goto out_free_bsmbx
;
5828 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.nodename
,
5830 wwn
= cpu_to_be64(wwn
);
5831 phba
->sli4_hba
.wwnn
.u
.name
= wwn
;
5832 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.portname
,
5834 /* wwn is WWPN of HBA instance */
5835 wwn
= cpu_to_be64(wwn
);
5836 phba
->sli4_hba
.wwpn
.u
.name
= wwn
;
5838 /* Check to see if it matches any module parameter */
5839 for (i
= 0; i
< lpfc_enable_nvmet_cnt
; i
++) {
5840 if (wwn
== lpfc_enable_nvmet
[i
]) {
5841 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5842 "6017 NVME Target %016llx\n",
5844 phba
->nvmet_support
= 1; /* a match */
5849 lpfc_nvme_mod_param_dep(phba
);
5851 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
5852 lpfc_supported_pages(mboxq
);
5853 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5855 mqe
= &mboxq
->u
.mqe
;
5856 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
5857 LPFC_MAX_SUPPORTED_PAGES
);
5858 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
5859 switch (pn_page
[i
]) {
5860 case LPFC_SLI4_PARAMETERS
:
5861 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
5867 /* Read the port's SLI4 Parameters capabilities if supported. */
5868 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
5869 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
5871 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5873 goto out_free_bsmbx
;
5878 * Get sli4 parameters that override parameters from Port capabilities.
5879 * If this call fails, it isn't critical unless the SLI4 parameters come
5882 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
5884 if (phba
->sli4_hba
.extents_in_use
&&
5885 phba
->sli4_hba
.rpi_hdrs_in_use
) {
5886 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5887 "2999 Unsupported SLI4 Parameters "
5888 "Extents and RPI headers enabled.\n");
5890 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5891 goto out_free_bsmbx
;
5894 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5896 /* Verify OAS is supported */
5897 lpfc_sli4_oas_verify(phba
);
5901 /* Verify all the SLI4 queues */
5902 rc
= lpfc_sli4_queue_verify(phba
);
5904 goto out_free_bsmbx
;
5906 /* Create driver internal CQE event pool */
5907 rc
= lpfc_sli4_cq_event_pool_create(phba
);
5909 goto out_free_bsmbx
;
5911 /* Initialize sgl lists per host */
5912 lpfc_init_sgl_list(phba
);
5914 /* Allocate and initialize active sgl array */
5915 rc
= lpfc_init_active_sgl_array(phba
);
5917 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5918 "1430 Failed to initialize sgl list.\n");
5919 goto out_destroy_cq_event_pool
;
5921 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
5923 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5924 "1432 Failed to initialize rpi headers.\n");
5925 goto out_free_active_sgl
;
5928 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5929 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
5930 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
5932 if (!phba
->fcf
.fcf_rr_bmask
) {
5933 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5934 "2759 Failed allocate memory for FCF round "
5935 "robin failover bmask\n");
5937 goto out_remove_rpi_hdrs
;
5940 phba
->sli4_hba
.hba_eq_hdl
= kcalloc(fof_vectors
+ phba
->io_channel_irqs
,
5941 sizeof(struct lpfc_hba_eq_hdl
),
5943 if (!phba
->sli4_hba
.hba_eq_hdl
) {
5944 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5945 "2572 Failed allocate memory for "
5946 "fast-path per-EQ handle array\n");
5948 goto out_free_fcf_rr_bmask
;
5951 phba
->sli4_hba
.cpu_map
= kcalloc(phba
->sli4_hba
.num_present_cpu
,
5952 sizeof(struct lpfc_vector_map_info
),
5954 if (!phba
->sli4_hba
.cpu_map
) {
5955 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5956 "3327 Failed allocate memory for msi-x "
5957 "interrupt vector mapping\n");
5959 goto out_free_hba_eq_hdl
;
5961 if (lpfc_used_cpu
== NULL
) {
5962 lpfc_used_cpu
= kcalloc(lpfc_present_cpu
, sizeof(uint16_t),
5964 if (!lpfc_used_cpu
) {
5965 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5966 "3335 Failed allocate memory for msi-x "
5967 "interrupt vector mapping\n");
5968 kfree(phba
->sli4_hba
.cpu_map
);
5970 goto out_free_hba_eq_hdl
;
5972 for (i
= 0; i
< lpfc_present_cpu
; i
++)
5973 lpfc_used_cpu
[i
] = LPFC_VECTOR_MAP_EMPTY
;
5977 * Enable sr-iov virtual functions if supported and configured
5978 * through the module parameter.
5980 if (phba
->cfg_sriov_nr_virtfn
> 0) {
5981 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
5982 phba
->cfg_sriov_nr_virtfn
);
5984 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5985 "3020 Requested number of SR-IOV "
5986 "virtual functions (%d) is not "
5988 phba
->cfg_sriov_nr_virtfn
);
5989 phba
->cfg_sriov_nr_virtfn
= 0;
5995 out_free_hba_eq_hdl
:
5996 kfree(phba
->sli4_hba
.hba_eq_hdl
);
5997 out_free_fcf_rr_bmask
:
5998 kfree(phba
->fcf
.fcf_rr_bmask
);
5999 out_remove_rpi_hdrs
:
6000 lpfc_sli4_remove_rpi_hdrs(phba
);
6001 out_free_active_sgl
:
6002 lpfc_free_active_sgl(phba
);
6003 out_destroy_cq_event_pool
:
6004 lpfc_sli4_cq_event_pool_destroy(phba
);
6006 lpfc_destroy_bootstrap_mbox(phba
);
6008 lpfc_mem_free(phba
);
6013 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6014 * @phba: pointer to lpfc hba data structure.
6016 * This routine is invoked to unset the driver internal resources set up
6017 * specific for supporting the SLI-4 HBA device it attached to.
6020 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
6022 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
6024 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6025 kfree(phba
->sli4_hba
.cpu_map
);
6026 phba
->sli4_hba
.num_present_cpu
= 0;
6027 phba
->sli4_hba
.num_online_cpu
= 0;
6028 phba
->sli4_hba
.curr_disp_cpu
= 0;
6030 /* Free memory allocated for fast-path work queue handles */
6031 kfree(phba
->sli4_hba
.hba_eq_hdl
);
6033 /* Free the allocated rpi headers. */
6034 lpfc_sli4_remove_rpi_hdrs(phba
);
6035 lpfc_sli4_remove_rpis(phba
);
6037 /* Free eligible FCF index bmask */
6038 kfree(phba
->fcf
.fcf_rr_bmask
);
6040 /* Free the ELS sgl list */
6041 lpfc_free_active_sgl(phba
);
6042 lpfc_free_els_sgl_list(phba
);
6043 lpfc_free_nvmet_sgl_list(phba
);
6045 /* Free the completion queue EQ event pool */
6046 lpfc_sli4_cq_event_release_all(phba
);
6047 lpfc_sli4_cq_event_pool_destroy(phba
);
6049 /* Release resource identifiers. */
6050 lpfc_sli4_dealloc_resource_identifiers(phba
);
6052 /* Free the bsmbx region. */
6053 lpfc_destroy_bootstrap_mbox(phba
);
6055 /* Free the SLI Layer memory with SLI4 HBAs */
6056 lpfc_mem_free_all(phba
);
6058 /* Free the current connect table */
6059 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
6060 &phba
->fcf_conn_rec_list
, list
) {
6061 list_del_init(&conn_entry
->list
);
6069 * lpfc_init_api_table_setup - Set up init api function jump table
6070 * @phba: The hba struct for which this call is being executed.
6071 * @dev_grp: The HBA PCI-Device group number.
6073 * This routine sets up the device INIT interface API function jump table
6076 * Returns: 0 - success, -ENODEV - failure.
6079 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6081 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
6082 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
6083 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
6085 case LPFC_PCI_DEV_LP
:
6086 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
6087 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
6088 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
6090 case LPFC_PCI_DEV_OC
:
6091 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
6092 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
6093 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
6096 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6097 "1431 Invalid HBA PCI-device group: 0x%x\n",
6106 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6107 * @phba: pointer to lpfc hba data structure.
6109 * This routine is invoked to set up the driver internal resources after the
6110 * device specific resource setup to support the HBA device it attached to.
6114 * other values - error
6117 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
6121 /* Startup the kernel thread for this host adapter. */
6122 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
6123 "lpfc_worker_%d", phba
->brd_no
);
6124 if (IS_ERR(phba
->worker_thread
)) {
6125 error
= PTR_ERR(phba
->worker_thread
);
6133 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6134 * @phba: pointer to lpfc hba data structure.
6136 * This routine is invoked to unset the driver internal resources set up after
6137 * the device specific resource setup for supporting the HBA device it
6141 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
6143 /* Stop kernel worker thread */
6144 kthread_stop(phba
->worker_thread
);
6148 * lpfc_free_iocb_list - Free iocb list.
6149 * @phba: pointer to lpfc hba data structure.
6151 * This routine is invoked to free the driver's IOCB list and memory.
6154 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
6156 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
6158 spin_lock_irq(&phba
->hbalock
);
6159 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
6160 &phba
->lpfc_iocb_list
, list
) {
6161 list_del(&iocbq_entry
->list
);
6163 phba
->total_iocbq_bufs
--;
6165 spin_unlock_irq(&phba
->hbalock
);
6171 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6172 * @phba: pointer to lpfc hba data structure.
6174 * This routine is invoked to allocate and initizlize the driver's IOCB
6175 * list and set up the IOCB tag array accordingly.
6179 * other values - error
6182 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
6184 struct lpfc_iocbq
*iocbq_entry
= NULL
;
6188 /* Initialize and populate the iocb list per host. */
6189 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
6190 for (i
= 0; i
< iocb_count
; i
++) {
6191 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
6192 if (iocbq_entry
== NULL
) {
6193 printk(KERN_ERR
"%s: only allocated %d iocbs of "
6194 "expected %d count. Unloading driver.\n",
6195 __func__
, i
, LPFC_IOCB_LIST_CNT
);
6196 goto out_free_iocbq
;
6199 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
6202 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
6203 "Unloading driver.\n", __func__
);
6204 goto out_free_iocbq
;
6206 iocbq_entry
->sli4_lxritag
= NO_XRI
;
6207 iocbq_entry
->sli4_xritag
= NO_XRI
;
6209 spin_lock_irq(&phba
->hbalock
);
6210 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
6211 phba
->total_iocbq_bufs
++;
6212 spin_unlock_irq(&phba
->hbalock
);
6218 lpfc_free_iocb_list(phba
);
6224 * lpfc_free_sgl_list - Free a given sgl list.
6225 * @phba: pointer to lpfc hba data structure.
6226 * @sglq_list: pointer to the head of sgl list.
6228 * This routine is invoked to free a give sgl list and memory.
6231 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
6233 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6235 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
6236 list_del(&sglq_entry
->list
);
6237 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
6243 * lpfc_free_els_sgl_list - Free els sgl list.
6244 * @phba: pointer to lpfc hba data structure.
6246 * This routine is invoked to free the driver's els sgl list and memory.
6249 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
6251 LIST_HEAD(sglq_list
);
6253 /* Retrieve all els sgls from driver list */
6254 spin_lock_irq(&phba
->hbalock
);
6255 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6256 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
, &sglq_list
);
6257 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6258 spin_unlock_irq(&phba
->hbalock
);
6260 /* Now free the sgl list */
6261 lpfc_free_sgl_list(phba
, &sglq_list
);
6265 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6266 * @phba: pointer to lpfc hba data structure.
6268 * This routine is invoked to free the driver's nvmet sgl list and memory.
6271 lpfc_free_nvmet_sgl_list(struct lpfc_hba
*phba
)
6273 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6274 LIST_HEAD(sglq_list
);
6276 /* Retrieve all nvmet sgls from driver list */
6277 spin_lock_irq(&phba
->hbalock
);
6278 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6279 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
, &sglq_list
);
6280 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6281 spin_unlock_irq(&phba
->hbalock
);
6283 /* Now free the sgl list */
6284 list_for_each_entry_safe(sglq_entry
, sglq_next
, &sglq_list
, list
) {
6285 list_del(&sglq_entry
->list
);
6286 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
6292 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6293 * @phba: pointer to lpfc hba data structure.
6295 * This routine is invoked to allocate the driver's active sgl memory.
6296 * This array will hold the sglq_entry's for active IOs.
6299 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
6302 size
= sizeof(struct lpfc_sglq
*);
6303 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
6305 phba
->sli4_hba
.lpfc_sglq_active_list
=
6306 kzalloc(size
, GFP_KERNEL
);
6307 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
6313 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6314 * @phba: pointer to lpfc hba data structure.
6316 * This routine is invoked to walk through the array of active sglq entries
6317 * and free all of the resources.
6318 * This is just a place holder for now.
6321 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
6323 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
6327 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6328 * @phba: pointer to lpfc hba data structure.
6330 * This routine is invoked to allocate and initizlize the driver's sgl
6331 * list and set up the sgl xritag tag array accordingly.
6335 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
6337 /* Initialize and populate the sglq list per host/VF. */
6338 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_els_sgl_list
);
6339 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
6340 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
6341 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
6343 /* els xri-sgl book keeping */
6344 phba
->sli4_hba
.els_xri_cnt
= 0;
6346 /* scsi xri-buffer book keeping */
6347 phba
->sli4_hba
.scsi_xri_cnt
= 0;
6349 /* nvme xri-buffer book keeping */
6350 phba
->sli4_hba
.nvme_xri_cnt
= 0;
6354 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6355 * @phba: pointer to lpfc hba data structure.
6357 * This routine is invoked to post rpi header templates to the
6358 * port for those SLI4 ports that do not support extents. This routine
6359 * posts a PAGE_SIZE memory region to the port to hold up to
6360 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6361 * and should be called only when interrupts are disabled.
6365 * -ERROR - otherwise.
6368 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
6371 struct lpfc_rpi_hdr
*rpi_hdr
;
6373 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
6374 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6376 if (phba
->sli4_hba
.extents_in_use
)
6379 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
6381 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6382 "0391 Error during rpi post operation\n");
6383 lpfc_sli4_remove_rpis(phba
);
6391 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6392 * @phba: pointer to lpfc hba data structure.
6394 * This routine is invoked to allocate a single 4KB memory region to
6395 * support rpis and stores them in the phba. This single region
6396 * provides support for up to 64 rpis. The region is used globally
6400 * A valid rpi hdr on success.
6401 * A NULL pointer on any failure.
6403 struct lpfc_rpi_hdr
*
6404 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
6406 uint16_t rpi_limit
, curr_rpi_range
;
6407 struct lpfc_dmabuf
*dmabuf
;
6408 struct lpfc_rpi_hdr
*rpi_hdr
;
6412 * If the SLI4 port supports extents, posting the rpi header isn't
6413 * required. Set the expected maximum count and let the actual value
6414 * get set when extents are fully allocated.
6416 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6418 if (phba
->sli4_hba
.extents_in_use
)
6421 /* The limit on the logical index is just the max_rpi count. */
6422 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
6423 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
6425 spin_lock_irq(&phba
->hbalock
);
6427 * Establish the starting RPI in this header block. The starting
6428 * rpi is normalized to a zero base because the physical rpi is
6431 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
6432 spin_unlock_irq(&phba
->hbalock
);
6435 * The port has a limited number of rpis. The increment here
6436 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6437 * and to allow the full max_rpi range per port.
6439 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
6440 rpi_count
= rpi_limit
- curr_rpi_range
;
6442 rpi_count
= LPFC_RPI_HDR_COUNT
;
6447 * First allocate the protocol header region for the port. The
6448 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6450 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
6454 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
6455 LPFC_HDR_TEMPLATE_SIZE
,
6456 &dmabuf
->phys
, GFP_KERNEL
);
6457 if (!dmabuf
->virt
) {
6459 goto err_free_dmabuf
;
6462 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
6464 goto err_free_coherent
;
6467 /* Save the rpi header data for cleanup later. */
6468 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
6470 goto err_free_coherent
;
6472 rpi_hdr
->dmabuf
= dmabuf
;
6473 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
6474 rpi_hdr
->page_count
= 1;
6475 spin_lock_irq(&phba
->hbalock
);
6477 /* The rpi_hdr stores the logical index only. */
6478 rpi_hdr
->start_rpi
= curr_rpi_range
;
6479 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
6482 * The next_rpi stores the next logical module-64 rpi value used
6483 * to post physical rpis in subsequent rpi postings.
6485 phba
->sli4_hba
.next_rpi
+= rpi_count
;
6486 spin_unlock_irq(&phba
->hbalock
);
6490 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
6491 dmabuf
->virt
, dmabuf
->phys
);
6498 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6499 * @phba: pointer to lpfc hba data structure.
6501 * This routine is invoked to remove all memory resources allocated
6502 * to support rpis for SLI4 ports not supporting extents. This routine
6503 * presumes the caller has released all rpis consumed by fabric or port
6504 * logins and is prepared to have the header pages removed.
6507 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
6509 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
6511 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6514 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
6515 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
6516 list_del(&rpi_hdr
->list
);
6517 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
6518 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
6519 kfree(rpi_hdr
->dmabuf
);
6523 /* There are no rpis available to the port now. */
6524 phba
->sli4_hba
.next_rpi
= 0;
6528 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6529 * @pdev: pointer to pci device data structure.
6531 * This routine is invoked to allocate the driver hba data structure for an
6532 * HBA device. If the allocation is successful, the phba reference to the
6533 * PCI device data structure is set.
6536 * pointer to @phba - successful
6539 static struct lpfc_hba
*
6540 lpfc_hba_alloc(struct pci_dev
*pdev
)
6542 struct lpfc_hba
*phba
;
6544 /* Allocate memory for HBA structure */
6545 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
6547 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
6551 /* Set reference to PCI device in HBA structure */
6552 phba
->pcidev
= pdev
;
6554 /* Assign an unused board number */
6555 phba
->brd_no
= lpfc_get_instance();
6556 if (phba
->brd_no
< 0) {
6560 phba
->eratt_poll_interval
= LPFC_ERATT_POLL_INTERVAL
;
6562 spin_lock_init(&phba
->ct_ev_lock
);
6563 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
6569 * lpfc_hba_free - Free driver hba data structure with a device.
6570 * @phba: pointer to lpfc hba data structure.
6572 * This routine is invoked to free the driver hba data structure with an
6576 lpfc_hba_free(struct lpfc_hba
*phba
)
6578 /* Release the driver assigned board number */
6579 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
6581 /* Free memory allocated with sli3 rings */
6582 kfree(phba
->sli
.sli3_ring
);
6583 phba
->sli
.sli3_ring
= NULL
;
6590 * lpfc_create_shost - Create hba physical port with associated scsi host.
6591 * @phba: pointer to lpfc hba data structure.
6593 * This routine is invoked to create HBA physical port and associate a SCSI
6598 * other values - error
6601 lpfc_create_shost(struct lpfc_hba
*phba
)
6603 struct lpfc_vport
*vport
;
6604 struct Scsi_Host
*shost
;
6606 /* Initialize HBA FC structure */
6607 phba
->fc_edtov
= FF_DEF_EDTOV
;
6608 phba
->fc_ratov
= FF_DEF_RATOV
;
6609 phba
->fc_altov
= FF_DEF_ALTOV
;
6610 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
6612 atomic_set(&phba
->sdev_cnt
, 0);
6613 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
6617 shost
= lpfc_shost_from_vport(vport
);
6618 phba
->pport
= vport
;
6620 if (phba
->nvmet_support
) {
6621 /* Only 1 vport (pport) will support NVME target */
6622 if (phba
->txrdy_payload_pool
== NULL
) {
6623 phba
->txrdy_payload_pool
= pci_pool_create(
6624 "txrdy_pool", phba
->pcidev
,
6625 TXRDY_PAYLOAD_LEN
, 16, 0);
6626 if (phba
->txrdy_payload_pool
) {
6627 phba
->targetport
= NULL
;
6628 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_NVME
;
6629 lpfc_printf_log(phba
, KERN_INFO
,
6630 LOG_INIT
| LOG_NVME_DISC
,
6631 "6076 NVME Target Found\n");
6636 lpfc_debugfs_initialize(vport
);
6637 /* Put reference to SCSI host to driver's device private data */
6638 pci_set_drvdata(phba
->pcidev
, shost
);
6641 * At this point we are fully registered with PSA. In addition,
6642 * any initial discovery should be completed.
6644 vport
->load_flag
|= FC_ALLOW_FDMI
;
6645 if (phba
->cfg_enable_SmartSAN
||
6646 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
6648 /* Setup appropriate attribute masks */
6649 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
6650 if (phba
->cfg_enable_SmartSAN
)
6651 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
6653 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
6659 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6660 * @phba: pointer to lpfc hba data structure.
6662 * This routine is invoked to destroy HBA physical port and the associated
6666 lpfc_destroy_shost(struct lpfc_hba
*phba
)
6668 struct lpfc_vport
*vport
= phba
->pport
;
6670 /* Destroy physical port that associated with the SCSI host */
6671 destroy_port(vport
);
6677 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6678 * @phba: pointer to lpfc hba data structure.
6679 * @shost: the shost to be used to detect Block guard settings.
6681 * This routine sets up the local Block guard protocol settings for @shost.
6682 * This routine also allocates memory for debugging bg buffers.
6685 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
6691 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
6692 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6693 "1478 Registering BlockGuard with the "
6696 old_mask
= phba
->cfg_prot_mask
;
6697 old_guard
= phba
->cfg_prot_guard
;
6699 /* Only allow supported values */
6700 phba
->cfg_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
6701 SHOST_DIX_TYPE0_PROTECTION
|
6702 SHOST_DIX_TYPE1_PROTECTION
);
6703 phba
->cfg_prot_guard
&= (SHOST_DIX_GUARD_IP
|
6704 SHOST_DIX_GUARD_CRC
);
6706 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6707 if (phba
->cfg_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
6708 phba
->cfg_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
6710 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
6711 if ((old_mask
!= phba
->cfg_prot_mask
) ||
6712 (old_guard
!= phba
->cfg_prot_guard
))
6713 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6714 "1475 Registering BlockGuard with the "
6715 "SCSI layer: mask %d guard %d\n",
6716 phba
->cfg_prot_mask
,
6717 phba
->cfg_prot_guard
);
6719 scsi_host_set_prot(shost
, phba
->cfg_prot_mask
);
6720 scsi_host_set_guard(shost
, phba
->cfg_prot_guard
);
6722 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6723 "1479 Not Registering BlockGuard with the SCSI "
6724 "layer, Bad protection parameters: %d %d\n",
6725 old_mask
, old_guard
);
6728 if (!_dump_buf_data
) {
6730 spin_lock_init(&_dump_buf_lock
);
6732 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
6733 if (_dump_buf_data
) {
6734 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6735 "9043 BLKGRD: allocated %d pages for "
6736 "_dump_buf_data at 0x%p\n",
6737 (1 << pagecnt
), _dump_buf_data
);
6738 _dump_buf_data_order
= pagecnt
;
6739 memset(_dump_buf_data
, 0,
6740 ((1 << PAGE_SHIFT
) << pagecnt
));
6745 if (!_dump_buf_data_order
)
6746 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6747 "9044 BLKGRD: ERROR unable to allocate "
6748 "memory for hexdump\n");
6750 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6751 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6752 "\n", _dump_buf_data
);
6753 if (!_dump_buf_dif
) {
6756 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
6757 if (_dump_buf_dif
) {
6758 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6759 "9046 BLKGRD: allocated %d pages for "
6760 "_dump_buf_dif at 0x%p\n",
6761 (1 << pagecnt
), _dump_buf_dif
);
6762 _dump_buf_dif_order
= pagecnt
;
6763 memset(_dump_buf_dif
, 0,
6764 ((1 << PAGE_SHIFT
) << pagecnt
));
6769 if (!_dump_buf_dif_order
)
6770 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6771 "9047 BLKGRD: ERROR unable to allocate "
6772 "memory for hexdump\n");
6774 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6775 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
6780 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6781 * @phba: pointer to lpfc hba data structure.
6783 * This routine is invoked to perform all the necessary post initialization
6784 * setup for the device.
6787 lpfc_post_init_setup(struct lpfc_hba
*phba
)
6789 struct Scsi_Host
*shost
;
6790 struct lpfc_adapter_event_header adapter_event
;
6792 /* Get the default values for Model Name and Description */
6793 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
6796 * hba setup may have changed the hba_queue_depth so we need to
6797 * adjust the value of can_queue.
6799 shost
= pci_get_drvdata(phba
->pcidev
);
6800 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
6801 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
6802 lpfc_setup_bg(phba
, shost
);
6804 lpfc_host_attrib_init(shost
);
6806 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
6807 spin_lock_irq(shost
->host_lock
);
6808 lpfc_poll_start_timer(phba
);
6809 spin_unlock_irq(shost
->host_lock
);
6812 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6813 "0428 Perform SCSI scan\n");
6814 /* Send board arrival event to upper layer */
6815 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
6816 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
6817 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6818 sizeof(adapter_event
),
6819 (char *) &adapter_event
,
6825 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6826 * @phba: pointer to lpfc hba data structure.
6828 * This routine is invoked to set up the PCI device memory space for device
6829 * with SLI-3 interface spec.
6833 * other values - error
6836 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
6838 struct pci_dev
*pdev
;
6839 unsigned long bar0map_len
, bar2map_len
;
6842 int error
= -ENODEV
;
6844 /* Obtain PCI device reference */
6848 pdev
= phba
->pcidev
;
6850 /* Set the device DMA mask size */
6851 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
6852 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
6853 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
6854 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
6859 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6860 * required by each mapping.
6862 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
6863 bar0map_len
= pci_resource_len(pdev
, 0);
6865 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
6866 bar2map_len
= pci_resource_len(pdev
, 2);
6868 /* Map HBA SLIM to a kernel virtual address. */
6869 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
6870 if (!phba
->slim_memmap_p
) {
6871 dev_printk(KERN_ERR
, &pdev
->dev
,
6872 "ioremap failed for SLIM memory.\n");
6876 /* Map HBA Control Registers to a kernel virtual address. */
6877 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
6878 if (!phba
->ctrl_regs_memmap_p
) {
6879 dev_printk(KERN_ERR
, &pdev
->dev
,
6880 "ioremap failed for HBA control registers.\n");
6881 goto out_iounmap_slim
;
6884 /* Allocate memory for SLI-2 structures */
6885 phba
->slim2p
.virt
= dma_zalloc_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6886 &phba
->slim2p
.phys
, GFP_KERNEL
);
6887 if (!phba
->slim2p
.virt
)
6890 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
6891 phba
->mbox_ext
= (phba
->slim2p
.virt
+
6892 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
6893 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
6894 phba
->IOCBs
= (phba
->slim2p
.virt
+
6895 offsetof(struct lpfc_sli2_slim
, IOCBs
));
6897 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
6898 lpfc_sli_hbq_size(),
6899 &phba
->hbqslimp
.phys
,
6901 if (!phba
->hbqslimp
.virt
)
6904 hbq_count
= lpfc_sli_hbq_count();
6905 ptr
= phba
->hbqslimp
.virt
;
6906 for (i
= 0; i
< hbq_count
; ++i
) {
6907 phba
->hbqs
[i
].hbq_virt
= ptr
;
6908 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
6909 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
6910 sizeof(struct lpfc_hbq_entry
));
6912 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
6913 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
6915 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
6917 phba
->MBslimaddr
= phba
->slim_memmap_p
;
6918 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
6919 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
6920 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
6921 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
6926 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6927 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6929 iounmap(phba
->ctrl_regs_memmap_p
);
6931 iounmap(phba
->slim_memmap_p
);
6937 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6938 * @phba: pointer to lpfc hba data structure.
6940 * This routine is invoked to unset the PCI device memory space for device
6941 * with SLI-3 interface spec.
6944 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
6946 struct pci_dev
*pdev
;
6948 /* Obtain PCI device reference */
6952 pdev
= phba
->pcidev
;
6954 /* Free coherent DMA memory allocated */
6955 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
6956 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
6957 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6958 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6960 /* I/O memory unmap */
6961 iounmap(phba
->ctrl_regs_memmap_p
);
6962 iounmap(phba
->slim_memmap_p
);
6968 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6969 * @phba: pointer to lpfc hba data structure.
6971 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6972 * done and check status.
6974 * Return 0 if successful, otherwise -ENODEV.
6977 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
6979 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
6980 struct lpfc_register reg_data
;
6981 int i
, port_error
= 0;
6984 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
6985 memset(®_data
, 0, sizeof(reg_data
));
6986 if (!phba
->sli4_hba
.PSMPHRregaddr
)
6989 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6990 for (i
= 0; i
< 3000; i
++) {
6991 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
6992 &portsmphr_reg
.word0
) ||
6993 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
6994 /* Port has a fatal POST error, break out */
6995 port_error
= -ENODEV
;
6998 if (LPFC_POST_STAGE_PORT_READY
==
6999 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
7005 * If there was a port error during POST, then don't proceed with
7006 * other register reads as the data may not be valid. Just exit.
7009 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7010 "1408 Port Failed POST - portsmphr=0x%x, "
7011 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7012 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7013 portsmphr_reg
.word0
,
7014 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
7015 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
7016 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
7017 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
7018 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
7019 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
7020 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
7021 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
7023 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7024 "2534 Device Info: SLIFamily=0x%x, "
7025 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7026 "SLIHint_2=0x%x, FT=0x%x\n",
7027 bf_get(lpfc_sli_intf_sli_family
,
7028 &phba
->sli4_hba
.sli_intf
),
7029 bf_get(lpfc_sli_intf_slirev
,
7030 &phba
->sli4_hba
.sli_intf
),
7031 bf_get(lpfc_sli_intf_if_type
,
7032 &phba
->sli4_hba
.sli_intf
),
7033 bf_get(lpfc_sli_intf_sli_hint1
,
7034 &phba
->sli4_hba
.sli_intf
),
7035 bf_get(lpfc_sli_intf_sli_hint2
,
7036 &phba
->sli4_hba
.sli_intf
),
7037 bf_get(lpfc_sli_intf_func_type
,
7038 &phba
->sli4_hba
.sli_intf
));
7040 * Check for other Port errors during the initialization
7041 * process. Fail the load if the port did not come up
7044 if_type
= bf_get(lpfc_sli_intf_if_type
,
7045 &phba
->sli4_hba
.sli_intf
);
7047 case LPFC_SLI_INTF_IF_TYPE_0
:
7048 phba
->sli4_hba
.ue_mask_lo
=
7049 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
7050 phba
->sli4_hba
.ue_mask_hi
=
7051 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
7053 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
7055 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
7056 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
7057 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
7058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7059 "1422 Unrecoverable Error "
7060 "Detected during POST "
7061 "uerr_lo_reg=0x%x, "
7062 "uerr_hi_reg=0x%x, "
7063 "ue_mask_lo_reg=0x%x, "
7064 "ue_mask_hi_reg=0x%x\n",
7067 phba
->sli4_hba
.ue_mask_lo
,
7068 phba
->sli4_hba
.ue_mask_hi
);
7069 port_error
= -ENODEV
;
7072 case LPFC_SLI_INTF_IF_TYPE_2
:
7073 /* Final checks. The port status should be clean. */
7074 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
7076 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
7077 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
7078 phba
->work_status
[0] =
7079 readl(phba
->sli4_hba
.u
.if_type2
.
7081 phba
->work_status
[1] =
7082 readl(phba
->sli4_hba
.u
.if_type2
.
7084 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7085 "2888 Unrecoverable port error "
7086 "following POST: port status reg "
7087 "0x%x, port_smphr reg 0x%x, "
7088 "error 1=0x%x, error 2=0x%x\n",
7090 portsmphr_reg
.word0
,
7091 phba
->work_status
[0],
7092 phba
->work_status
[1]);
7093 port_error
= -ENODEV
;
7096 case LPFC_SLI_INTF_IF_TYPE_1
:
7105 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7106 * @phba: pointer to lpfc hba data structure.
7107 * @if_type: The SLI4 interface type getting configured.
7109 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7113 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
7116 case LPFC_SLI_INTF_IF_TYPE_0
:
7117 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
7118 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
7119 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
7120 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
7121 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
7122 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
7123 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
7124 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
7125 phba
->sli4_hba
.SLIINTFregaddr
=
7126 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
7128 case LPFC_SLI_INTF_IF_TYPE_2
:
7129 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
7130 phba
->sli4_hba
.conf_regs_memmap_p
+
7131 LPFC_CTL_PORT_ER1_OFFSET
;
7132 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
7133 phba
->sli4_hba
.conf_regs_memmap_p
+
7134 LPFC_CTL_PORT_ER2_OFFSET
;
7135 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
7136 phba
->sli4_hba
.conf_regs_memmap_p
+
7137 LPFC_CTL_PORT_CTL_OFFSET
;
7138 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
7139 phba
->sli4_hba
.conf_regs_memmap_p
+
7140 LPFC_CTL_PORT_STA_OFFSET
;
7141 phba
->sli4_hba
.SLIINTFregaddr
=
7142 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
7143 phba
->sli4_hba
.PSMPHRregaddr
=
7144 phba
->sli4_hba
.conf_regs_memmap_p
+
7145 LPFC_CTL_PORT_SEM_OFFSET
;
7146 phba
->sli4_hba
.RQDBregaddr
=
7147 phba
->sli4_hba
.conf_regs_memmap_p
+
7148 LPFC_ULP0_RQ_DOORBELL
;
7149 phba
->sli4_hba
.WQDBregaddr
=
7150 phba
->sli4_hba
.conf_regs_memmap_p
+
7151 LPFC_ULP0_WQ_DOORBELL
;
7152 phba
->sli4_hba
.EQCQDBregaddr
=
7153 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
7154 phba
->sli4_hba
.MQDBregaddr
=
7155 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
7156 phba
->sli4_hba
.BMBXregaddr
=
7157 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
7159 case LPFC_SLI_INTF_IF_TYPE_1
:
7161 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
7162 "FATAL - unsupported SLI4 interface type - %d\n",
7169 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7170 * @phba: pointer to lpfc hba data structure.
7172 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7176 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
7178 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7179 LPFC_SLIPORT_IF0_SMPHR
;
7180 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7182 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7184 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7189 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7190 * @phba: pointer to lpfc hba data structure.
7191 * @vf: virtual function number
7193 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7194 * based on the given viftual function number, @vf.
7196 * Return 0 if successful, otherwise -ENODEV.
7199 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
7201 if (vf
> LPFC_VIR_FUNC_MAX
)
7204 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7205 vf
* LPFC_VFR_PAGE_SIZE
+
7206 LPFC_ULP0_RQ_DOORBELL
);
7207 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7208 vf
* LPFC_VFR_PAGE_SIZE
+
7209 LPFC_ULP0_WQ_DOORBELL
);
7210 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7211 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
7212 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7213 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
7214 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7215 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
7220 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7221 * @phba: pointer to lpfc hba data structure.
7223 * This routine is invoked to create the bootstrap mailbox
7224 * region consistent with the SLI-4 interface spec. This
7225 * routine allocates all memory necessary to communicate
7226 * mailbox commands to the port and sets up all alignment
7227 * needs. No locks are expected to be held when calling
7232 * -ENOMEM - could not allocated memory.
7235 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
7238 struct lpfc_dmabuf
*dmabuf
;
7239 struct dma_address
*dma_address
;
7243 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
7248 * The bootstrap mailbox region is comprised of 2 parts
7249 * plus an alignment restriction of 16 bytes.
7251 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
7252 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, bmbx_size
,
7253 &dmabuf
->phys
, GFP_KERNEL
);
7254 if (!dmabuf
->virt
) {
7260 * Initialize the bootstrap mailbox pointers now so that the register
7261 * operations are simple later. The mailbox dma address is required
7262 * to be 16-byte aligned. Also align the virtual memory as each
7263 * maibox is copied into the bmbx mailbox region before issuing the
7264 * command to the port.
7266 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
7267 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
7269 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
7270 LPFC_ALIGN_16_BYTE
);
7271 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
7272 LPFC_ALIGN_16_BYTE
);
7275 * Set the high and low physical addresses now. The SLI4 alignment
7276 * requirement is 16 bytes and the mailbox is posted to the port
7277 * as two 30-bit addresses. The other data is a bit marking whether
7278 * the 30-bit address is the high or low address.
7279 * Upcast bmbx aphys to 64bits so shift instruction compiles
7280 * clean on 32 bit machines.
7282 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7283 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
7284 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
7285 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
7286 LPFC_BMBX_BIT1_ADDR_HI
);
7288 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
7289 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
7290 LPFC_BMBX_BIT1_ADDR_LO
);
7295 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7296 * @phba: pointer to lpfc hba data structure.
7298 * This routine is invoked to teardown the bootstrap mailbox
7299 * region and release all host resources. This routine requires
7300 * the caller to ensure all mailbox commands recovered, no
7301 * additional mailbox comands are sent, and interrupts are disabled
7302 * before calling this routine.
7306 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
7308 dma_free_coherent(&phba
->pcidev
->dev
,
7309 phba
->sli4_hba
.bmbx
.bmbx_size
,
7310 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
7311 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
7313 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
7314 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
7318 * lpfc_sli4_read_config - Get the config parameters.
7319 * @phba: pointer to lpfc hba data structure.
7321 * This routine is invoked to read the configuration parameters from the HBA.
7322 * The configuration parameters are used to set the base and maximum values
7323 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7324 * allocation for the port.
7328 * -ENOMEM - No available memory
7329 * -EIO - The mailbox failed to complete successfully.
7332 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
7335 struct lpfc_mbx_read_config
*rd_config
;
7336 union lpfc_sli4_cfg_shdr
*shdr
;
7337 uint32_t shdr_status
, shdr_add_status
;
7338 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
7339 struct lpfc_rsrc_desc_fcfcoe
*desc
;
7341 uint16_t forced_link_speed
;
7343 int length
, i
, rc
= 0, rc2
;
7345 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7347 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7348 "2011 Unable to allocate memory for issuing "
7349 "SLI_CONFIG_SPECIAL mailbox command\n");
7353 lpfc_read_config(phba
, pmb
);
7355 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7356 if (rc
!= MBX_SUCCESS
) {
7357 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7358 "2012 Mailbox failed , mbxCmd x%x "
7359 "READ_CONFIG, mbxStatus x%x\n",
7360 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
7361 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
7364 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
7365 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
7366 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
7367 phba
->sli4_hba
.lnk_info
.lnk_tp
=
7368 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
7369 phba
->sli4_hba
.lnk_info
.lnk_no
=
7370 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
7371 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7372 "3081 lnk_type:%d, lnk_numb:%d\n",
7373 phba
->sli4_hba
.lnk_info
.lnk_tp
,
7374 phba
->sli4_hba
.lnk_info
.lnk_no
);
7376 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
7377 "3082 Mailbox (x%x) returned ldv:x0\n",
7378 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
7379 phba
->sli4_hba
.extents_in_use
=
7380 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
7381 phba
->sli4_hba
.max_cfg_param
.max_xri
=
7382 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
7383 phba
->sli4_hba
.max_cfg_param
.xri_base
=
7384 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
7385 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
7386 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
7387 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
7388 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
7389 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
7390 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
7391 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
7392 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
7393 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
7394 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
7395 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
7396 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
7397 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
7398 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
7399 phba
->sli4_hba
.max_cfg_param
.max_eq
=
7400 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
7401 phba
->sli4_hba
.max_cfg_param
.max_rq
=
7402 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
7403 phba
->sli4_hba
.max_cfg_param
.max_wq
=
7404 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
7405 phba
->sli4_hba
.max_cfg_param
.max_cq
=
7406 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
7407 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
7408 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
7409 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
7410 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
7411 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
7412 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
7413 phba
->max_vports
= phba
->max_vpi
;
7414 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7415 "2003 cfg params Extents? %d "
7420 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7421 phba
->sli4_hba
.extents_in_use
,
7422 phba
->sli4_hba
.max_cfg_param
.xri_base
,
7423 phba
->sli4_hba
.max_cfg_param
.max_xri
,
7424 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
7425 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
7426 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
7427 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
7428 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
7429 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
7430 phba
->sli4_hba
.max_cfg_param
.max_fcfi
,
7431 phba
->sli4_hba
.max_cfg_param
.max_eq
,
7432 phba
->sli4_hba
.max_cfg_param
.max_cq
,
7433 phba
->sli4_hba
.max_cfg_param
.max_wq
,
7434 phba
->sli4_hba
.max_cfg_param
.max_rq
);
7441 /* Update link speed if forced link speed is supported */
7442 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7443 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7445 bf_get(lpfc_mbx_rd_conf_link_speed
, rd_config
);
7446 if (forced_link_speed
) {
7447 phba
->hba_flag
|= HBA_FORCED_LINK_SPEED
;
7449 switch (forced_link_speed
) {
7451 phba
->cfg_link_speed
=
7452 LPFC_USER_LINK_SPEED_1G
;
7455 phba
->cfg_link_speed
=
7456 LPFC_USER_LINK_SPEED_2G
;
7459 phba
->cfg_link_speed
=
7460 LPFC_USER_LINK_SPEED_4G
;
7463 phba
->cfg_link_speed
=
7464 LPFC_USER_LINK_SPEED_8G
;
7466 case LINK_SPEED_10G
:
7467 phba
->cfg_link_speed
=
7468 LPFC_USER_LINK_SPEED_10G
;
7470 case LINK_SPEED_16G
:
7471 phba
->cfg_link_speed
=
7472 LPFC_USER_LINK_SPEED_16G
;
7474 case LINK_SPEED_32G
:
7475 phba
->cfg_link_speed
=
7476 LPFC_USER_LINK_SPEED_32G
;
7479 phba
->cfg_link_speed
=
7480 LPFC_USER_LINK_SPEED_AUTO
;
7483 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7484 "0047 Unrecognized link "
7487 phba
->cfg_link_speed
=
7488 LPFC_USER_LINK_SPEED_AUTO
;
7493 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7494 length
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
7495 lpfc_sli4_get_els_iocb_cnt(phba
);
7496 if (phba
->cfg_hba_queue_depth
> length
) {
7497 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7498 "3361 HBA queue depth changed from %d to %d\n",
7499 phba
->cfg_hba_queue_depth
, length
);
7500 phba
->cfg_hba_queue_depth
= length
;
7503 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
7504 LPFC_SLI_INTF_IF_TYPE_2
)
7507 /* get the pf# and vf# for SLI4 if_type 2 port */
7508 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
7509 sizeof(struct lpfc_sli4_cfg_mhdr
));
7510 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7511 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
7512 length
, LPFC_SLI4_MBX_EMBED
);
7514 rc2
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7515 shdr
= (union lpfc_sli4_cfg_shdr
*)
7516 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7517 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7518 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
7519 if (rc2
|| shdr_status
|| shdr_add_status
) {
7520 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7521 "3026 Mailbox failed , mbxCmd x%x "
7522 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7523 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
7524 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
7528 /* search for fc_fcoe resrouce descriptor */
7529 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
7531 pdesc_0
= (char *)&get_func_cfg
->func_cfg
.desc
[0];
7532 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)pdesc_0
;
7533 length
= bf_get(lpfc_rsrc_desc_fcfcoe_length
, desc
);
7534 if (length
== LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD
)
7535 length
= LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH
;
7536 else if (length
!= LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH
)
7539 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
7540 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)(pdesc_0
+ length
* i
);
7541 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
7542 bf_get(lpfc_rsrc_desc_fcfcoe_type
, desc
)) {
7543 phba
->sli4_hba
.iov
.pf_number
=
7544 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
7545 phba
->sli4_hba
.iov
.vf_number
=
7546 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
7551 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
7552 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7553 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7554 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
7555 phba
->sli4_hba
.iov
.vf_number
);
7557 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7558 "3028 GET_FUNCTION_CONFIG: failed to find "
7559 "Resrouce Descriptor:x%x\n",
7560 LPFC_RSRC_DESC_TYPE_FCFCOE
);
7563 mempool_free(pmb
, phba
->mbox_mem_pool
);
7568 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7569 * @phba: pointer to lpfc hba data structure.
7571 * This routine is invoked to setup the port-side endian order when
7572 * the port if_type is 0. This routine has no function for other
7577 * -ENOMEM - No available memory
7578 * -EIO - The mailbox failed to complete successfully.
7581 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
7583 LPFC_MBOXQ_t
*mboxq
;
7584 uint32_t if_type
, rc
= 0;
7585 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
7586 HOST_ENDIAN_HIGH_WORD1
};
7588 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7590 case LPFC_SLI_INTF_IF_TYPE_0
:
7591 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
7594 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7595 "0492 Unable to allocate memory for "
7596 "issuing SLI_CONFIG_SPECIAL mailbox "
7602 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7603 * two words to contain special data values and no other data.
7605 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
7606 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
7607 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7608 if (rc
!= MBX_SUCCESS
) {
7609 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7610 "0493 SLI_CONFIG_SPECIAL mailbox "
7611 "failed with status x%x\n",
7615 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7617 case LPFC_SLI_INTF_IF_TYPE_2
:
7618 case LPFC_SLI_INTF_IF_TYPE_1
:
7626 * lpfc_sli4_queue_verify - Verify and update EQ counts
7627 * @phba: pointer to lpfc hba data structure.
7629 * This routine is invoked to check the user settable queue counts for EQs.
7630 * After this routine is called the counts will be set to valid values that
7631 * adhere to the constraints of the system's interrupt vectors and the port's
7636 * -ENOMEM - No available memory
7639 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
7642 int fof_vectors
= phba
->cfg_fof
? 1 : 0;
7645 * Sanity check for configured queue parameters against the run-time
7649 /* Sanity check on HBA EQ parameters */
7650 io_channel
= phba
->io_channel_irqs
;
7652 if (phba
->sli4_hba
.num_online_cpu
< io_channel
) {
7653 lpfc_printf_log(phba
,
7655 "3188 Reducing IO channels to match number of "
7656 "online CPUs: from %d to %d\n",
7657 io_channel
, phba
->sli4_hba
.num_online_cpu
);
7658 io_channel
= phba
->sli4_hba
.num_online_cpu
;
7661 if (io_channel
+ fof_vectors
> phba
->sli4_hba
.max_cfg_param
.max_eq
) {
7662 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7663 "2575 Reducing IO channels to match number of "
7664 "available EQs: from %d to %d\n",
7666 phba
->sli4_hba
.max_cfg_param
.max_eq
);
7667 io_channel
= phba
->sli4_hba
.max_cfg_param
.max_eq
- fof_vectors
;
7670 /* The actual number of FCP / NVME event queues adopted */
7671 if (io_channel
!= phba
->io_channel_irqs
)
7672 phba
->io_channel_irqs
= io_channel
;
7673 if (phba
->cfg_fcp_io_channel
> io_channel
)
7674 phba
->cfg_fcp_io_channel
= io_channel
;
7675 if (phba
->cfg_nvme_io_channel
> io_channel
)
7676 phba
->cfg_nvme_io_channel
= io_channel
;
7678 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7679 "2574 IO channels: irqs %d fcp %d nvme %d\n",
7680 phba
->io_channel_irqs
, phba
->cfg_fcp_io_channel
,
7681 phba
->cfg_nvme_io_channel
);
7683 /* Get EQ depth from module parameter, fake the default for now */
7684 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
7685 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
7687 /* Get CQ depth from module parameter, fake the default for now */
7688 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
7689 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
7694 lpfc_alloc_nvme_wq_cq(struct lpfc_hba
*phba
, int wqidx
)
7696 struct lpfc_queue
*qdesc
;
7699 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7700 phba
->sli4_hba
.cq_ecount
);
7702 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7703 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7707 phba
->sli4_hba
.nvme_cq
[wqidx
] = qdesc
;
7709 cnt
= LPFC_NVME_WQSIZE
;
7710 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_WQE128_SIZE
, cnt
);
7712 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7713 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7717 phba
->sli4_hba
.nvme_wq
[wqidx
] = qdesc
;
7718 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7723 lpfc_alloc_fcp_wq_cq(struct lpfc_hba
*phba
, int wqidx
)
7725 struct lpfc_queue
*qdesc
;
7728 /* Create Fast Path FCP CQs */
7729 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7730 phba
->sli4_hba
.cq_ecount
);
7732 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7733 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx
);
7736 phba
->sli4_hba
.fcp_cq
[wqidx
] = qdesc
;
7738 /* Create Fast Path FCP WQs */
7739 wqesize
= (phba
->fcp_embed_io
) ?
7740 LPFC_WQE128_SIZE
: phba
->sli4_hba
.wq_esize
;
7741 qdesc
= lpfc_sli4_queue_alloc(phba
, wqesize
, phba
->sli4_hba
.wq_ecount
);
7743 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7744 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7748 phba
->sli4_hba
.fcp_wq
[wqidx
] = qdesc
;
7749 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7754 * lpfc_sli4_queue_create - Create all the SLI4 queues
7755 * @phba: pointer to lpfc hba data structure.
7757 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7758 * operation. For each SLI4 queue type, the parameters such as queue entry
7759 * count (queue depth) shall be taken from the module parameter. For now,
7760 * we just use some constant number as place holder.
7764 * -ENOMEM - No availble memory
7765 * -EIO - The mailbox failed to complete successfully.
7768 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
7770 struct lpfc_queue
*qdesc
;
7771 int idx
, io_channel
;
7774 * Create HBA Record arrays.
7775 * Both NVME and FCP will share that same vectors / EQs
7777 io_channel
= phba
->io_channel_irqs
;
7781 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
7782 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
7783 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
7784 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
7785 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
7786 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
7787 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
7788 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
7789 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
7790 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
7792 phba
->sli4_hba
.hba_eq
= kcalloc(io_channel
,
7793 sizeof(struct lpfc_queue
*),
7795 if (!phba
->sli4_hba
.hba_eq
) {
7796 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7797 "2576 Failed allocate memory for "
7798 "fast-path EQ record array\n");
7802 if (phba
->cfg_fcp_io_channel
) {
7803 phba
->sli4_hba
.fcp_cq
= kcalloc(phba
->cfg_fcp_io_channel
,
7804 sizeof(struct lpfc_queue
*),
7806 if (!phba
->sli4_hba
.fcp_cq
) {
7807 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7808 "2577 Failed allocate memory for "
7809 "fast-path CQ record array\n");
7812 phba
->sli4_hba
.fcp_wq
= kcalloc(phba
->cfg_fcp_io_channel
,
7813 sizeof(struct lpfc_queue
*),
7815 if (!phba
->sli4_hba
.fcp_wq
) {
7816 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7817 "2578 Failed allocate memory for "
7818 "fast-path FCP WQ record array\n");
7822 * Since the first EQ can have multiple CQs associated with it,
7823 * this array is used to quickly see if we have a FCP fast-path
7826 phba
->sli4_hba
.fcp_cq_map
= kcalloc(phba
->cfg_fcp_io_channel
,
7829 if (!phba
->sli4_hba
.fcp_cq_map
) {
7830 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7831 "2545 Failed allocate memory for "
7832 "fast-path CQ map\n");
7837 if (phba
->cfg_nvme_io_channel
) {
7838 phba
->sli4_hba
.nvme_cq
= kcalloc(phba
->cfg_nvme_io_channel
,
7839 sizeof(struct lpfc_queue
*),
7841 if (!phba
->sli4_hba
.nvme_cq
) {
7842 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7843 "6077 Failed allocate memory for "
7844 "fast-path CQ record array\n");
7849 phba
->sli4_hba
.nvme_wq
= kcalloc(phba
->cfg_nvme_io_channel
,
7850 sizeof(struct lpfc_queue
*),
7852 if (!phba
->sli4_hba
.nvme_wq
) {
7853 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7854 "2581 Failed allocate memory for "
7855 "fast-path NVME WQ record array\n");
7860 * Since the first EQ can have multiple CQs associated with it,
7861 * this array is used to quickly see if we have a NVME fast-path
7864 phba
->sli4_hba
.nvme_cq_map
= kcalloc(phba
->cfg_nvme_io_channel
,
7867 if (!phba
->sli4_hba
.nvme_cq_map
) {
7868 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7869 "6078 Failed allocate memory for "
7870 "fast-path CQ map\n");
7875 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
7877 /* Create HBA Event Queues (EQs) */
7878 for (idx
= 0; idx
< io_channel
; idx
++) {
7880 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
7881 phba
->sli4_hba
.eq_ecount
);
7883 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7884 "0497 Failed allocate EQ (%d)\n", idx
);
7887 phba
->sli4_hba
.hba_eq
[idx
] = qdesc
;
7890 /* FCP and NVME io channels are not required to be balanced */
7892 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++)
7893 if (lpfc_alloc_fcp_wq_cq(phba
, idx
))
7896 for (idx
= 0; idx
< phba
->cfg_nvme_io_channel
; idx
++)
7897 if (lpfc_alloc_nvme_wq_cq(phba
, idx
))
7901 * Create Slow Path Completion Queues (CQs)
7904 /* Create slow-path Mailbox Command Complete Queue */
7905 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7906 phba
->sli4_hba
.cq_ecount
);
7908 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7909 "0500 Failed allocate slow-path mailbox CQ\n");
7912 phba
->sli4_hba
.mbx_cq
= qdesc
;
7914 /* Create slow-path ELS Complete Queue */
7915 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7916 phba
->sli4_hba
.cq_ecount
);
7918 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7919 "0501 Failed allocate slow-path ELS CQ\n");
7922 phba
->sli4_hba
.els_cq
= qdesc
;
7926 * Create Slow Path Work Queues (WQs)
7929 /* Create Mailbox Command Queue */
7931 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
7932 phba
->sli4_hba
.mq_ecount
);
7934 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7935 "0505 Failed allocate slow-path MQ\n");
7938 phba
->sli4_hba
.mbx_wq
= qdesc
;
7941 * Create ELS Work Queues
7944 /* Create slow-path ELS Work Queue */
7945 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
7946 phba
->sli4_hba
.wq_ecount
);
7948 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7949 "0504 Failed allocate slow-path ELS WQ\n");
7952 phba
->sli4_hba
.els_wq
= qdesc
;
7953 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7955 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
7956 /* Create NVME LS Complete Queue */
7957 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7958 phba
->sli4_hba
.cq_ecount
);
7960 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7961 "6079 Failed allocate NVME LS CQ\n");
7964 phba
->sli4_hba
.nvmels_cq
= qdesc
;
7966 /* Create NVME LS Work Queue */
7967 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
7968 phba
->sli4_hba
.wq_ecount
);
7970 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7971 "6080 Failed allocate NVME LS WQ\n");
7974 phba
->sli4_hba
.nvmels_wq
= qdesc
;
7975 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7979 * Create Receive Queue (RQ)
7982 /* Create Receive Queue for header */
7983 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
7984 phba
->sli4_hba
.rq_ecount
);
7986 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7987 "0506 Failed allocate receive HRQ\n");
7990 phba
->sli4_hba
.hdr_rq
= qdesc
;
7992 /* Create Receive Queue for data */
7993 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
7994 phba
->sli4_hba
.rq_ecount
);
7996 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7997 "0507 Failed allocate receive DRQ\n");
8000 phba
->sli4_hba
.dat_rq
= qdesc
;
8002 /* Create the Queues needed for Flash Optimized Fabric operations */
8004 lpfc_fof_queue_create(phba
);
8008 lpfc_sli4_queue_destroy(phba
);
8013 __lpfc_sli4_release_queue(struct lpfc_queue
**qp
)
8016 lpfc_sli4_queue_free(*qp
);
8022 lpfc_sli4_release_queues(struct lpfc_queue
***qs
, int max
)
8029 for (idx
= 0; idx
< max
; idx
++)
8030 __lpfc_sli4_release_queue(&(*qs
)[idx
]);
8037 lpfc_sli4_release_queue_map(uint16_t **qmap
)
8039 if (*qmap
!= NULL
) {
8046 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8047 * @phba: pointer to lpfc hba data structure.
8049 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8054 * -ENOMEM - No available memory
8055 * -EIO - The mailbox failed to complete successfully.
8058 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
8061 lpfc_fof_queue_destroy(phba
);
8063 /* Release HBA eqs */
8064 lpfc_sli4_release_queues(&phba
->sli4_hba
.hba_eq
, phba
->io_channel_irqs
);
8066 /* Release FCP cqs */
8067 lpfc_sli4_release_queues(&phba
->sli4_hba
.fcp_cq
,
8068 phba
->cfg_fcp_io_channel
);
8070 /* Release FCP wqs */
8071 lpfc_sli4_release_queues(&phba
->sli4_hba
.fcp_wq
,
8072 phba
->cfg_fcp_io_channel
);
8074 /* Release FCP CQ mapping array */
8075 lpfc_sli4_release_queue_map(&phba
->sli4_hba
.fcp_cq_map
);
8077 /* Release NVME cqs */
8078 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvme_cq
,
8079 phba
->cfg_nvme_io_channel
);
8081 /* Release NVME wqs */
8082 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvme_wq
,
8083 phba
->cfg_nvme_io_channel
);
8085 /* Release NVME CQ mapping array */
8086 lpfc_sli4_release_queue_map(&phba
->sli4_hba
.nvme_cq_map
);
8088 /* Release mailbox command work queue */
8089 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_wq
);
8091 /* Release ELS work queue */
8092 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_wq
);
8094 /* Release ELS work queue */
8095 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_wq
);
8097 /* Release unsolicited receive queue */
8098 __lpfc_sli4_release_queue(&phba
->sli4_hba
.hdr_rq
);
8099 __lpfc_sli4_release_queue(&phba
->sli4_hba
.dat_rq
);
8101 /* Release ELS complete queue */
8102 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_cq
);
8104 /* Release NVME LS complete queue */
8105 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_cq
);
8107 /* Release mailbox command complete queue */
8108 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_cq
);
8110 /* Everything on this list has been freed */
8111 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
8115 lpfc_post_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
8116 struct lpfc_queue
*drq
, int count
)
8119 struct lpfc_rqe hrqe
;
8120 struct lpfc_rqe drqe
;
8121 struct lpfc_rqb
*rqbp
;
8122 struct rqb_dmabuf
*rqb_buffer
;
8123 LIST_HEAD(rqb_buf_list
);
8126 for (i
= 0; i
< count
; i
++) {
8127 rqb_buffer
= (rqbp
->rqb_alloc_buffer
)(phba
);
8130 rqb_buffer
->hrq
= hrq
;
8131 rqb_buffer
->drq
= drq
;
8132 list_add_tail(&rqb_buffer
->hbuf
.list
, &rqb_buf_list
);
8134 while (!list_empty(&rqb_buf_list
)) {
8135 list_remove_head(&rqb_buf_list
, rqb_buffer
, struct rqb_dmabuf
,
8138 hrqe
.address_lo
= putPaddrLow(rqb_buffer
->hbuf
.phys
);
8139 hrqe
.address_hi
= putPaddrHigh(rqb_buffer
->hbuf
.phys
);
8140 drqe
.address_lo
= putPaddrLow(rqb_buffer
->dbuf
.phys
);
8141 drqe
.address_hi
= putPaddrHigh(rqb_buffer
->dbuf
.phys
);
8142 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
8144 (rqbp
->rqb_free_buffer
)(phba
, rqb_buffer
);
8146 list_add_tail(&rqb_buffer
->hbuf
.list
,
8147 &rqbp
->rqb_buffer_list
);
8148 rqbp
->buffer_count
++;
8155 lpfc_free_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
)
8157 struct lpfc_rqb
*rqbp
;
8158 struct lpfc_dmabuf
*h_buf
;
8159 struct rqb_dmabuf
*rqb_buffer
;
8162 while (!list_empty(&rqbp
->rqb_buffer_list
)) {
8163 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
8164 struct lpfc_dmabuf
, list
);
8166 rqb_buffer
= container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
8167 (rqbp
->rqb_free_buffer
)(phba
, rqb_buffer
);
8168 rqbp
->buffer_count
--;
8174 lpfc_create_wq_cq(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
,
8175 struct lpfc_queue
*cq
, struct lpfc_queue
*wq
, uint16_t *cq_map
,
8176 int qidx
, uint32_t qtype
)
8178 struct lpfc_sli_ring
*pring
;
8181 if (!eq
|| !cq
|| !wq
) {
8182 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8183 "6085 Fast-path %s (%d) not allocated\n",
8184 ((eq
) ? ((cq
) ? "WQ" : "CQ") : "EQ"), qidx
);
8188 /* create the Cq first */
8189 rc
= lpfc_cq_create(phba
, cq
, eq
,
8190 (qtype
== LPFC_MBOX
) ? LPFC_MCQ
: LPFC_WCQ
, qtype
);
8192 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8193 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8194 qidx
, (uint32_t)rc
);
8198 if (qtype
!= LPFC_MBOX
) {
8199 /* Setup nvme_cq_map for fast lookup */
8201 *cq_map
= cq
->queue_id
;
8203 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8204 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8205 qidx
, cq
->queue_id
, qidx
, eq
->queue_id
);
8208 rc
= lpfc_wq_create(phba
, wq
, cq
, qtype
);
8210 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8211 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8212 qidx
, (uint32_t)rc
);
8213 /* no need to tear down cq - caller will do so */
8217 /* Bind this CQ/WQ to the NVME ring */
8219 pring
->sli
.sli4
.wqp
= (void *)wq
;
8222 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8223 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8224 qidx
, wq
->queue_id
, wq
->assoc_qid
, qidx
, cq
->queue_id
);
8226 rc
= lpfc_mq_create(phba
, wq
, cq
, LPFC_MBOX
);
8228 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8229 "0539 Failed setup of slow-path MQ: "
8231 /* no need to tear down cq - caller will do so */
8235 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8236 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8237 phba
->sli4_hba
.mbx_wq
->queue_id
,
8238 phba
->sli4_hba
.mbx_cq
->queue_id
);
8245 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8246 * @phba: pointer to lpfc hba data structure.
8248 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8253 * -ENOMEM - No available memory
8254 * -EIO - The mailbox failed to complete successfully.
8257 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
8259 uint32_t shdr_status
, shdr_add_status
;
8260 union lpfc_sli4_cfg_shdr
*shdr
;
8261 LPFC_MBOXQ_t
*mboxq
;
8263 uint32_t length
, io_channel
;
8266 /* Check for dual-ULP support */
8267 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8269 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8270 "3249 Unable to allocate memory for "
8271 "QUERY_FW_CFG mailbox command\n");
8274 length
= (sizeof(struct lpfc_mbx_query_fw_config
) -
8275 sizeof(struct lpfc_sli4_cfg_mhdr
));
8276 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8277 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
8278 length
, LPFC_SLI4_MBX_EMBED
);
8280 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8282 shdr
= (union lpfc_sli4_cfg_shdr
*)
8283 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
8284 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
8285 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
8286 if (shdr_status
|| shdr_add_status
|| rc
) {
8287 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8288 "3250 QUERY_FW_CFG mailbox failed with status "
8289 "x%x add_status x%x, mbx status x%x\n",
8290 shdr_status
, shdr_add_status
, rc
);
8291 if (rc
!= MBX_TIMEOUT
)
8292 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8297 phba
->sli4_hba
.fw_func_mode
=
8298 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.function_mode
;
8299 phba
->sli4_hba
.ulp0_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp0_mode
;
8300 phba
->sli4_hba
.ulp1_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp1_mode
;
8301 phba
->sli4_hba
.physical_port
=
8302 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.physical_port
;
8303 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8304 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8305 "ulp1_mode:x%x\n", phba
->sli4_hba
.fw_func_mode
,
8306 phba
->sli4_hba
.ulp0_mode
, phba
->sli4_hba
.ulp1_mode
);
8308 if (rc
!= MBX_TIMEOUT
)
8309 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8312 * Set up HBA Event Queues (EQs)
8314 io_channel
= phba
->io_channel_irqs
;
8316 /* Set up HBA event queue */
8317 if (io_channel
&& !phba
->sli4_hba
.hba_eq
) {
8318 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8319 "3147 Fast-path EQs not allocated\n");
8323 for (qidx
= 0; qidx
< io_channel
; qidx
++) {
8324 if (!phba
->sli4_hba
.hba_eq
[qidx
]) {
8325 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8326 "0522 Fast-path EQ (%d) not "
8327 "allocated\n", qidx
);
8331 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.hba_eq
[qidx
],
8332 phba
->cfg_fcp_imax
);
8334 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8335 "0523 Failed setup of fast-path EQ "
8336 "(%d), rc = 0x%x\n", qidx
,
8340 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8341 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8342 qidx
, phba
->sli4_hba
.hba_eq
[qidx
]->queue_id
);
8345 if (phba
->cfg_nvme_io_channel
) {
8346 if (!phba
->sli4_hba
.nvme_cq
|| !phba
->sli4_hba
.nvme_wq
) {
8347 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8348 "6084 Fast-path NVME %s array not allocated\n",
8349 (phba
->sli4_hba
.nvme_cq
) ? "CQ" : "WQ");
8354 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++) {
8355 rc
= lpfc_create_wq_cq(phba
,
8356 phba
->sli4_hba
.hba_eq
[
8358 phba
->sli4_hba
.nvme_cq
[qidx
],
8359 phba
->sli4_hba
.nvme_wq
[qidx
],
8360 &phba
->sli4_hba
.nvme_cq_map
[qidx
],
8363 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8364 "6123 Failed to setup fastpath "
8365 "NVME WQ/CQ (%d), rc = 0x%x\n",
8366 qidx
, (uint32_t)rc
);
8372 if (phba
->cfg_fcp_io_channel
) {
8373 /* Set up fast-path FCP Response Complete Queue */
8374 if (!phba
->sli4_hba
.fcp_cq
|| !phba
->sli4_hba
.fcp_wq
) {
8375 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8376 "3148 Fast-path FCP %s array not allocated\n",
8377 phba
->sli4_hba
.fcp_cq
? "WQ" : "CQ");
8382 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++) {
8383 rc
= lpfc_create_wq_cq(phba
,
8384 phba
->sli4_hba
.hba_eq
[
8386 phba
->sli4_hba
.fcp_cq
[qidx
],
8387 phba
->sli4_hba
.fcp_wq
[qidx
],
8388 &phba
->sli4_hba
.fcp_cq_map
[qidx
],
8391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8392 "0535 Failed to setup fastpath "
8393 "FCP WQ/CQ (%d), rc = 0x%x\n",
8394 qidx
, (uint32_t)rc
);
8401 * Set up Slow Path Complete Queues (CQs)
8404 /* Set up slow-path MBOX CQ/MQ */
8406 if (!phba
->sli4_hba
.mbx_cq
|| !phba
->sli4_hba
.mbx_wq
) {
8407 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8408 "0528 %s not allocated\n",
8409 phba
->sli4_hba
.mbx_cq
?
8410 "Mailbox WQ" : "Mailbox CQ");
8415 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8416 phba
->sli4_hba
.mbx_cq
,
8417 phba
->sli4_hba
.mbx_wq
,
8418 NULL
, 0, LPFC_MBOX
);
8420 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8421 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8426 /* Set up slow-path ELS WQ/CQ */
8427 if (!phba
->sli4_hba
.els_cq
|| !phba
->sli4_hba
.els_wq
) {
8428 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8429 "0530 ELS %s not allocated\n",
8430 phba
->sli4_hba
.els_cq
? "WQ" : "CQ");
8434 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8435 phba
->sli4_hba
.els_cq
,
8436 phba
->sli4_hba
.els_wq
,
8439 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8440 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8444 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8445 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8446 phba
->sli4_hba
.els_wq
->queue_id
,
8447 phba
->sli4_hba
.els_cq
->queue_id
);
8449 if (phba
->cfg_nvme_io_channel
) {
8450 /* Set up NVME LS Complete Queue */
8451 if (!phba
->sli4_hba
.nvmels_cq
|| !phba
->sli4_hba
.nvmels_wq
) {
8452 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8453 "6091 LS %s not allocated\n",
8454 phba
->sli4_hba
.nvmels_cq
? "WQ" : "CQ");
8458 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8459 phba
->sli4_hba
.nvmels_cq
,
8460 phba
->sli4_hba
.nvmels_wq
,
8461 NULL
, 0, LPFC_NVME_LS
);
8463 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8464 "0529 Failed setup of NVVME LS WQ/CQ: "
8465 "rc = 0x%x\n", (uint32_t)rc
);
8469 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8470 "6096 ELS WQ setup: wq-id=%d, "
8471 "parent cq-id=%d\n",
8472 phba
->sli4_hba
.nvmels_wq
->queue_id
,
8473 phba
->sli4_hba
.nvmels_cq
->queue_id
);
8476 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
8477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8478 "0540 Receive Queue not allocated\n");
8483 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.hdr_rq
, LPFC_ELS_HBQ
);
8484 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.dat_rq
, LPFC_ELS_HBQ
);
8486 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
8487 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
8489 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8490 "0541 Failed setup of Receive Queue: "
8491 "rc = 0x%x\n", (uint32_t)rc
);
8495 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8496 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8497 "parent cq-id=%d\n",
8498 phba
->sli4_hba
.hdr_rq
->queue_id
,
8499 phba
->sli4_hba
.dat_rq
->queue_id
,
8500 phba
->sli4_hba
.els_cq
->queue_id
);
8502 if (phba
->cfg_fof
) {
8503 rc
= lpfc_fof_queue_setup(phba
);
8505 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8506 "0549 Failed setup of FOF Queues: "
8513 * Configure EQ delay multipier for interrupt coalescing using
8514 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8516 for (qidx
= 0; qidx
< io_channel
; qidx
+= LPFC_MAX_EQ_DELAY
)
8517 lpfc_modify_hba_eq_delay(phba
, qidx
);
8521 lpfc_sli4_queue_unset(phba
);
8527 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8528 * @phba: pointer to lpfc hba data structure.
8530 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8535 * -ENOMEM - No available memory
8536 * -EIO - The mailbox failed to complete successfully.
8539 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
8543 /* Unset the queues created for Flash Optimized Fabric operations */
8545 lpfc_fof_queue_destroy(phba
);
8547 /* Unset mailbox command work queue */
8548 if (phba
->sli4_hba
.mbx_wq
)
8549 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
8551 /* Unset NVME LS work queue */
8552 if (phba
->sli4_hba
.nvmels_wq
)
8553 lpfc_wq_destroy(phba
, phba
->sli4_hba
.nvmels_wq
);
8555 /* Unset ELS work queue */
8556 if (phba
->sli4_hba
.els_cq
)
8557 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
8559 /* Unset unsolicited receive queue */
8560 if (phba
->sli4_hba
.hdr_rq
)
8561 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
,
8562 phba
->sli4_hba
.dat_rq
);
8564 /* Unset FCP work queue */
8565 if (phba
->sli4_hba
.fcp_wq
)
8566 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
8567 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[qidx
]);
8569 /* Unset NVME work queue */
8570 if (phba
->sli4_hba
.nvme_wq
) {
8571 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
8572 lpfc_wq_destroy(phba
, phba
->sli4_hba
.nvme_wq
[qidx
]);
8575 /* Unset mailbox command complete queue */
8576 if (phba
->sli4_hba
.mbx_cq
)
8577 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
8579 /* Unset ELS complete queue */
8580 if (phba
->sli4_hba
.els_cq
)
8581 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
8583 /* Unset NVME LS complete queue */
8584 if (phba
->sli4_hba
.nvmels_cq
)
8585 lpfc_cq_destroy(phba
, phba
->sli4_hba
.nvmels_cq
);
8587 /* Unset NVME response complete queue */
8588 if (phba
->sli4_hba
.nvme_cq
)
8589 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
8590 lpfc_cq_destroy(phba
, phba
->sli4_hba
.nvme_cq
[qidx
]);
8592 /* Unset FCP response complete queue */
8593 if (phba
->sli4_hba
.fcp_cq
)
8594 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
8595 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[qidx
]);
8597 /* Unset fast-path event queue */
8598 if (phba
->sli4_hba
.hba_eq
)
8599 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++)
8600 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[qidx
]);
8604 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8605 * @phba: pointer to lpfc hba data structure.
8607 * This routine is invoked to allocate and set up a pool of completion queue
8608 * events. The body of the completion queue event is a completion queue entry
8609 * CQE. For now, this pool is used for the interrupt service routine to queue
8610 * the following HBA completion queue events for the worker thread to process:
8611 * - Mailbox asynchronous events
8612 * - Receive queue completion unsolicited events
8613 * Later, this can be used for all the slow-path events.
8617 * -ENOMEM - No available memory
8620 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
8622 struct lpfc_cq_event
*cq_event
;
8625 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
8626 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
8628 goto out_pool_create_fail
;
8629 list_add_tail(&cq_event
->list
,
8630 &phba
->sli4_hba
.sp_cqe_event_pool
);
8634 out_pool_create_fail
:
8635 lpfc_sli4_cq_event_pool_destroy(phba
);
8640 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8641 * @phba: pointer to lpfc hba data structure.
8643 * This routine is invoked to free the pool of completion queue events at
8644 * driver unload time. Note that, it is the responsibility of the driver
8645 * cleanup routine to free all the outstanding completion-queue events
8646 * allocated from this pool back into the pool before invoking this routine
8647 * to destroy the pool.
8650 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
8652 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
8654 list_for_each_entry_safe(cq_event
, next_cq_event
,
8655 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
8656 list_del(&cq_event
->list
);
8662 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8663 * @phba: pointer to lpfc hba data structure.
8665 * This routine is the lock free version of the API invoked to allocate a
8666 * completion-queue event from the free pool.
8668 * Return: Pointer to the newly allocated completion-queue event if successful
8671 struct lpfc_cq_event
*
8672 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
8674 struct lpfc_cq_event
*cq_event
= NULL
;
8676 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
8677 struct lpfc_cq_event
, list
);
8682 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8683 * @phba: pointer to lpfc hba data structure.
8685 * This routine is the lock version of the API invoked to allocate a
8686 * completion-queue event from the free pool.
8688 * Return: Pointer to the newly allocated completion-queue event if successful
8691 struct lpfc_cq_event
*
8692 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
8694 struct lpfc_cq_event
*cq_event
;
8695 unsigned long iflags
;
8697 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8698 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
8699 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8704 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8705 * @phba: pointer to lpfc hba data structure.
8706 * @cq_event: pointer to the completion queue event to be freed.
8708 * This routine is the lock free version of the API invoked to release a
8709 * completion-queue event back into the free pool.
8712 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
8713 struct lpfc_cq_event
*cq_event
)
8715 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
8719 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8720 * @phba: pointer to lpfc hba data structure.
8721 * @cq_event: pointer to the completion queue event to be freed.
8723 * This routine is the lock version of the API invoked to release a
8724 * completion-queue event back into the free pool.
8727 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
8728 struct lpfc_cq_event
*cq_event
)
8730 unsigned long iflags
;
8731 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8732 __lpfc_sli4_cq_event_release(phba
, cq_event
);
8733 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8737 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8738 * @phba: pointer to lpfc hba data structure.
8740 * This routine is to free all the pending completion-queue events to the
8741 * back into the free pool for device reset.
8744 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
8747 struct lpfc_cq_event
*cqe
;
8748 unsigned long iflags
;
8750 /* Retrieve all the pending WCQEs from pending WCQE lists */
8751 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8752 /* Pending FCP XRI abort events */
8753 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
8755 /* Pending ELS XRI abort events */
8756 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
8758 /* Pending asynnc events */
8759 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
8761 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8763 while (!list_empty(&cqelist
)) {
8764 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
8765 lpfc_sli4_cq_event_release(phba
, cqe
);
8770 * lpfc_pci_function_reset - Reset pci function.
8771 * @phba: pointer to lpfc hba data structure.
8773 * This routine is invoked to request a PCI function reset. It will destroys
8774 * all resources assigned to the PCI function which originates this request.
8778 * -ENOMEM - No available memory
8779 * -EIO - The mailbox failed to complete successfully.
8782 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
8784 LPFC_MBOXQ_t
*mboxq
;
8785 uint32_t rc
= 0, if_type
;
8786 uint32_t shdr_status
, shdr_add_status
;
8788 uint32_t port_reset
= 0;
8789 union lpfc_sli4_cfg_shdr
*shdr
;
8790 struct lpfc_register reg_data
;
8793 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8795 case LPFC_SLI_INTF_IF_TYPE_0
:
8796 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
8799 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8800 "0494 Unable to allocate memory for "
8801 "issuing SLI_FUNCTION_RESET mailbox "
8806 /* Setup PCI function reset mailbox-ioctl command */
8807 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8808 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
8809 LPFC_SLI4_MBX_EMBED
);
8810 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8811 shdr
= (union lpfc_sli4_cfg_shdr
*)
8812 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
8813 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
8814 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
8816 if (rc
!= MBX_TIMEOUT
)
8817 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8818 if (shdr_status
|| shdr_add_status
|| rc
) {
8819 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8820 "0495 SLI_FUNCTION_RESET mailbox "
8821 "failed with status x%x add_status x%x,"
8822 " mbx status x%x\n",
8823 shdr_status
, shdr_add_status
, rc
);
8827 case LPFC_SLI_INTF_IF_TYPE_2
:
8830 * Poll the Port Status Register and wait for RDY for
8831 * up to 30 seconds. If the port doesn't respond, treat
8834 for (rdy_chk
= 0; rdy_chk
< 1500; rdy_chk
++) {
8835 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
8836 STATUSregaddr
, ®_data
.word0
)) {
8840 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
8845 if (!bf_get(lpfc_sliport_status_rdy
, ®_data
)) {
8846 phba
->work_status
[0] = readl(
8847 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
8848 phba
->work_status
[1] = readl(
8849 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
8850 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8851 "2890 Port not ready, port status reg "
8852 "0x%x error 1=0x%x, error 2=0x%x\n",
8854 phba
->work_status
[0],
8855 phba
->work_status
[1]);
8862 * Reset the port now
8865 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
8866 LPFC_SLIPORT_LITTLE_ENDIAN
);
8867 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
8868 LPFC_SLIPORT_INIT_PORT
);
8869 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
8872 pci_read_config_word(phba
->pcidev
,
8873 PCI_DEVICE_ID
, &devid
);
8878 } else if (bf_get(lpfc_sliport_status_rn
, ®_data
)) {
8884 case LPFC_SLI_INTF_IF_TYPE_1
:
8890 /* Catch the not-ready port failure after a port reset. */
8892 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8893 "3317 HBA not functional: IP Reset Failed "
8894 "try: echo fw_reset > board_mode\n");
8902 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8903 * @phba: pointer to lpfc hba data structure.
8905 * This routine is invoked to set up the PCI device memory space for device
8906 * with SLI-4 interface spec.
8910 * other values - error
8913 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
8915 struct pci_dev
*pdev
;
8916 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
8917 int error
= -ENODEV
;
8920 /* Obtain PCI device reference */
8924 pdev
= phba
->pcidev
;
8926 /* Set the device DMA mask size */
8927 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
8928 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
8929 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
8930 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
8936 * The BARs and register set definitions and offset locations are
8937 * dependent on the if_type.
8939 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
8940 &phba
->sli4_hba
.sli_intf
.word0
)) {
8944 /* There is no SLI3 failback for SLI4 devices. */
8945 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
8946 LPFC_SLI_INTF_VALID
) {
8947 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8948 "2894 SLI_INTF reg contents invalid "
8949 "sli_intf reg 0x%x\n",
8950 phba
->sli4_hba
.sli_intf
.word0
);
8954 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8956 * Get the bus address of SLI4 device Bar regions and the
8957 * number of bytes required by each mapping. The mapping of the
8958 * particular PCI BARs regions is dependent on the type of
8961 if (pci_resource_start(pdev
, PCI_64BIT_BAR0
)) {
8962 phba
->pci_bar0_map
= pci_resource_start(pdev
, PCI_64BIT_BAR0
);
8963 bar0map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR0
);
8966 * Map SLI4 PCI Config Space Register base to a kernel virtual
8969 phba
->sli4_hba
.conf_regs_memmap_p
=
8970 ioremap(phba
->pci_bar0_map
, bar0map_len
);
8971 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
8972 dev_printk(KERN_ERR
, &pdev
->dev
,
8973 "ioremap failed for SLI4 PCI config "
8977 phba
->pci_bar0_memmap_p
= phba
->sli4_hba
.conf_regs_memmap_p
;
8978 /* Set up BAR0 PCI config space register memory map */
8979 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
8981 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
8982 bar0map_len
= pci_resource_len(pdev
, 1);
8983 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8984 dev_printk(KERN_ERR
, &pdev
->dev
,
8985 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8988 phba
->sli4_hba
.conf_regs_memmap_p
=
8989 ioremap(phba
->pci_bar0_map
, bar0map_len
);
8990 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
8991 dev_printk(KERN_ERR
, &pdev
->dev
,
8992 "ioremap failed for SLI4 PCI config "
8996 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
8999 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
9000 (pci_resource_start(pdev
, PCI_64BIT_BAR2
))) {
9002 * Map SLI4 if type 0 HBA Control Register base to a kernel
9003 * virtual address and setup the registers.
9005 phba
->pci_bar1_map
= pci_resource_start(pdev
, PCI_64BIT_BAR2
);
9006 bar1map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR2
);
9007 phba
->sli4_hba
.ctrl_regs_memmap_p
=
9008 ioremap(phba
->pci_bar1_map
, bar1map_len
);
9009 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
9010 dev_printk(KERN_ERR
, &pdev
->dev
,
9011 "ioremap failed for SLI4 HBA control registers.\n");
9012 goto out_iounmap_conf
;
9014 phba
->pci_bar2_memmap_p
= phba
->sli4_hba
.ctrl_regs_memmap_p
;
9015 lpfc_sli4_bar1_register_memmap(phba
);
9018 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
9019 (pci_resource_start(pdev
, PCI_64BIT_BAR4
))) {
9021 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
9022 * virtual address and setup the registers.
9024 phba
->pci_bar2_map
= pci_resource_start(pdev
, PCI_64BIT_BAR4
);
9025 bar2map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR4
);
9026 phba
->sli4_hba
.drbl_regs_memmap_p
=
9027 ioremap(phba
->pci_bar2_map
, bar2map_len
);
9028 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
9029 dev_printk(KERN_ERR
, &pdev
->dev
,
9030 "ioremap failed for SLI4 HBA doorbell registers.\n");
9031 goto out_iounmap_ctrl
;
9033 phba
->pci_bar4_memmap_p
= phba
->sli4_hba
.drbl_regs_memmap_p
;
9034 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
9036 goto out_iounmap_all
;
9042 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
9044 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
9046 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9052 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9053 * @phba: pointer to lpfc hba data structure.
9055 * This routine is invoked to unset the PCI device memory space for device
9056 * with SLI-4 interface spec.
9059 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
9062 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9065 case LPFC_SLI_INTF_IF_TYPE_0
:
9066 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
9067 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
9068 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9070 case LPFC_SLI_INTF_IF_TYPE_2
:
9071 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9073 case LPFC_SLI_INTF_IF_TYPE_1
:
9075 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
9076 "FATAL - unsupported SLI4 interface type - %d\n",
9083 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9084 * @phba: pointer to lpfc hba data structure.
9086 * This routine is invoked to enable the MSI-X interrupt vectors to device
9087 * with SLI-3 interface specs.
9091 * other values - error
9094 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
9099 /* Set up MSI-X multi-message vectors */
9100 rc
= pci_alloc_irq_vectors(phba
->pcidev
,
9101 LPFC_MSIX_VECTORS
, LPFC_MSIX_VECTORS
, PCI_IRQ_MSIX
);
9103 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9104 "0420 PCI enable MSI-X failed (%d)\n", rc
);
9109 * Assign MSI-X vectors to interrupt handlers
9112 /* vector-0 is associated to slow-path handler */
9113 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 0),
9114 &lpfc_sli_sp_intr_handler
, 0,
9115 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
9117 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9118 "0421 MSI-X slow-path request_irq failed "
9123 /* vector-1 is associated to fast-path handler */
9124 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 1),
9125 &lpfc_sli_fp_intr_handler
, 0,
9126 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
9129 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9130 "0429 MSI-X fast-path request_irq failed "
9136 * Configure HBA MSI-X attention conditions to messages
9138 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9142 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9143 "0474 Unable to allocate memory for issuing "
9144 "MBOX_CONFIG_MSI command\n");
9147 rc
= lpfc_config_msi(phba
, pmb
);
9150 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
9151 if (rc
!= MBX_SUCCESS
) {
9152 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
9153 "0351 Config MSI mailbox command failed, "
9154 "mbxCmd x%x, mbxStatus x%x\n",
9155 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
9159 /* Free memory allocated for mailbox command */
9160 mempool_free(pmb
, phba
->mbox_mem_pool
);
9164 /* Free memory allocated for mailbox command */
9165 mempool_free(pmb
, phba
->mbox_mem_pool
);
9168 /* free the irq already requested */
9169 free_irq(pci_irq_vector(phba
->pcidev
, 1), phba
);
9172 /* free the irq already requested */
9173 free_irq(pci_irq_vector(phba
->pcidev
, 0), phba
);
9176 /* Unconfigure MSI-X capability structure */
9177 pci_free_irq_vectors(phba
->pcidev
);
9184 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9185 * @phba: pointer to lpfc hba data structure.
9187 * This routine is invoked to enable the MSI interrupt mode to device with
9188 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9189 * enable the MSI vector. The device driver is responsible for calling the
9190 * request_irq() to register MSI vector with a interrupt the handler, which
9191 * is done in this function.
9195 * other values - error
9198 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
9202 rc
= pci_enable_msi(phba
->pcidev
);
9204 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9205 "0462 PCI enable MSI mode success.\n");
9207 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9208 "0471 PCI enable MSI mode failed (%d)\n", rc
);
9212 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
9213 0, LPFC_DRIVER_NAME
, phba
);
9215 pci_disable_msi(phba
->pcidev
);
9216 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9217 "0478 MSI request_irq failed (%d)\n", rc
);
9223 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9224 * @phba: pointer to lpfc hba data structure.
9226 * This routine is invoked to enable device interrupt and associate driver's
9227 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9228 * spec. Depends on the interrupt mode configured to the driver, the driver
9229 * will try to fallback from the configured interrupt mode to an interrupt
9230 * mode which is supported by the platform, kernel, and device in the order
9232 * MSI-X -> MSI -> IRQ.
9236 * other values - error
9239 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
9241 uint32_t intr_mode
= LPFC_INTR_ERROR
;
9244 if (cfg_mode
== 2) {
9245 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9246 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
9248 /* Now, try to enable MSI-X interrupt mode */
9249 retval
= lpfc_sli_enable_msix(phba
);
9251 /* Indicate initialization to MSI-X mode */
9252 phba
->intr_type
= MSIX
;
9258 /* Fallback to MSI if MSI-X initialization failed */
9259 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
9260 retval
= lpfc_sli_enable_msi(phba
);
9262 /* Indicate initialization to MSI mode */
9263 phba
->intr_type
= MSI
;
9268 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9269 if (phba
->intr_type
== NONE
) {
9270 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
9271 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
9273 /* Indicate initialization to INTx mode */
9274 phba
->intr_type
= INTx
;
9282 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9283 * @phba: pointer to lpfc hba data structure.
9285 * This routine is invoked to disable device interrupt and disassociate the
9286 * driver's interrupt handler(s) from interrupt vector(s) to device with
9287 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9288 * release the interrupt vector(s) for the message signaled interrupt.
9291 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
9295 if (phba
->intr_type
== MSIX
)
9296 nr_irqs
= LPFC_MSIX_VECTORS
;
9300 for (i
= 0; i
< nr_irqs
; i
++)
9301 free_irq(pci_irq_vector(phba
->pcidev
, i
), phba
);
9302 pci_free_irq_vectors(phba
->pcidev
);
9304 /* Reset interrupt management states */
9305 phba
->intr_type
= NONE
;
9306 phba
->sli
.slistat
.sli_intr
= 0;
9310 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
9311 * @phba: pointer to lpfc hba data structure.
9312 * @vectors: number of msix vectors allocated.
9314 * The routine will figure out the CPU affinity assignment for every
9315 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9316 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9317 * can be associated with. If the vector can be unquely associated with
9318 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9319 * In addition, the CPU to IO channel mapping will be calculated
9320 * and the phba->sli4_hba.cpu_map array will reflect this.
9323 lpfc_cpu_affinity_check(struct lpfc_hba
*phba
, int vectors
)
9325 struct lpfc_vector_map_info
*cpup
;
9330 struct cpuinfo_x86
*cpuinfo
;
9333 /* Init cpu_map array */
9334 memset(phba
->sli4_hba
.cpu_map
, 0xff,
9335 (sizeof(struct lpfc_vector_map_info
) *
9336 phba
->sli4_hba
.num_present_cpu
));
9338 /* Update CPU map with physical id and core id of each CPU */
9339 cpup
= phba
->sli4_hba
.cpu_map
;
9340 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
9342 cpuinfo
= &cpu_data(cpu
);
9343 cpup
->phys_id
= cpuinfo
->phys_proc_id
;
9344 cpup
->core_id
= cpuinfo
->cpu_core_id
;
9346 /* No distinction between CPUs for other platforms */
9350 cpup
->channel_id
= index
; /* For now round robin */
9351 cpup
->irq
= pci_irq_vector(phba
->pcidev
, vec
);
9356 if (index
>= phba
->cfg_fcp_io_channel
)
9364 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9365 * @phba: pointer to lpfc hba data structure.
9367 * This routine is invoked to enable the MSI-X interrupt vectors to device
9368 * with SLI-4 interface spec.
9372 * other values - error
9375 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
9377 int vectors
, rc
, index
;
9379 /* Set up MSI-X multi-message vectors */
9380 vectors
= phba
->io_channel_irqs
;
9384 rc
= pci_alloc_irq_vectors(phba
->pcidev
,
9385 (phba
->nvmet_support
) ? 1 : 2,
9386 vectors
, PCI_IRQ_MSIX
| PCI_IRQ_AFFINITY
);
9388 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9389 "0484 PCI enable MSI-X failed (%d)\n", rc
);
9394 /* Assign MSI-X vectors to interrupt handlers */
9395 for (index
= 0; index
< vectors
; index
++) {
9396 memset(&phba
->sli4_hba
.handler_name
[index
], 0, 16);
9397 snprintf((char *)&phba
->sli4_hba
.handler_name
[index
],
9398 LPFC_SLI4_HANDLER_NAME_SZ
,
9399 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
9401 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9402 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9403 atomic_set(&phba
->sli4_hba
.hba_eq_hdl
[index
].hba_eq_in_use
, 1);
9404 if (phba
->cfg_fof
&& (index
== (vectors
- 1)))
9405 rc
= request_irq(pci_irq_vector(phba
->pcidev
, index
),
9406 &lpfc_sli4_fof_intr_handler
, 0,
9407 (char *)&phba
->sli4_hba
.handler_name
[index
],
9408 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9410 rc
= request_irq(pci_irq_vector(phba
->pcidev
, index
),
9411 &lpfc_sli4_hba_intr_handler
, 0,
9412 (char *)&phba
->sli4_hba
.handler_name
[index
],
9413 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9415 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9416 "0486 MSI-X fast-path (%d) "
9417 "request_irq failed (%d)\n", index
, rc
);
9425 if (vectors
!= phba
->io_channel_irqs
) {
9426 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9427 "3238 Reducing IO channels to match number of "
9428 "MSI-X vectors, requested %d got %d\n",
9429 phba
->io_channel_irqs
, vectors
);
9430 if (phba
->cfg_fcp_io_channel
> vectors
)
9431 phba
->cfg_fcp_io_channel
= vectors
;
9432 if (phba
->cfg_nvme_io_channel
> vectors
)
9433 phba
->cfg_nvme_io_channel
= vectors
;
9434 if (phba
->cfg_fcp_io_channel
> phba
->cfg_nvme_io_channel
)
9435 phba
->io_channel_irqs
= phba
->cfg_fcp_io_channel
;
9437 phba
->io_channel_irqs
= phba
->cfg_nvme_io_channel
;
9439 lpfc_cpu_affinity_check(phba
, vectors
);
9444 /* free the irq already requested */
9445 for (--index
; index
>= 0; index
--)
9446 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9447 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9449 /* Unconfigure MSI-X capability structure */
9450 pci_free_irq_vectors(phba
->pcidev
);
9457 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9458 * @phba: pointer to lpfc hba data structure.
9460 * This routine is invoked to enable the MSI interrupt mode to device with
9461 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9462 * to enable the MSI vector. The device driver is responsible for calling
9463 * the request_irq() to register MSI vector with a interrupt the handler,
9464 * which is done in this function.
9468 * other values - error
9471 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
9475 rc
= pci_enable_msi(phba
->pcidev
);
9477 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9478 "0487 PCI enable MSI mode success.\n");
9480 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9481 "0488 PCI enable MSI mode failed (%d)\n", rc
);
9485 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
9486 0, LPFC_DRIVER_NAME
, phba
);
9488 pci_disable_msi(phba
->pcidev
);
9489 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9490 "0490 MSI request_irq failed (%d)\n", rc
);
9494 for (index
= 0; index
< phba
->io_channel_irqs
; index
++) {
9495 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9496 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9499 if (phba
->cfg_fof
) {
9500 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9501 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9507 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9508 * @phba: pointer to lpfc hba data structure.
9510 * This routine is invoked to enable device interrupt and associate driver's
9511 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9512 * interface spec. Depends on the interrupt mode configured to the driver,
9513 * the driver will try to fallback from the configured interrupt mode to an
9514 * interrupt mode which is supported by the platform, kernel, and device in
9516 * MSI-X -> MSI -> IRQ.
9520 * other values - error
9523 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
9525 uint32_t intr_mode
= LPFC_INTR_ERROR
;
9528 if (cfg_mode
== 2) {
9529 /* Preparation before conf_msi mbox cmd */
9532 /* Now, try to enable MSI-X interrupt mode */
9533 retval
= lpfc_sli4_enable_msix(phba
);
9535 /* Indicate initialization to MSI-X mode */
9536 phba
->intr_type
= MSIX
;
9542 /* Fallback to MSI if MSI-X initialization failed */
9543 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
9544 retval
= lpfc_sli4_enable_msi(phba
);
9546 /* Indicate initialization to MSI mode */
9547 phba
->intr_type
= MSI
;
9552 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9553 if (phba
->intr_type
== NONE
) {
9554 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
9555 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
9557 struct lpfc_hba_eq_hdl
*eqhdl
;
9559 /* Indicate initialization to INTx mode */
9560 phba
->intr_type
= INTx
;
9563 for (idx
= 0; idx
< phba
->io_channel_irqs
; idx
++) {
9564 eqhdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9567 atomic_set(&eqhdl
->hba_eq_in_use
, 1);
9569 if (phba
->cfg_fof
) {
9570 eqhdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9573 atomic_set(&eqhdl
->hba_eq_in_use
, 1);
9581 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9582 * @phba: pointer to lpfc hba data structure.
9584 * This routine is invoked to disable device interrupt and disassociate
9585 * the driver's interrupt handler(s) from interrupt vector(s) to device
9586 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9587 * will release the interrupt vector(s) for the message signaled interrupt.
9590 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
9592 /* Disable the currently initialized interrupt mode */
9593 if (phba
->intr_type
== MSIX
) {
9596 /* Free up MSI-X multi-message vectors */
9597 for (index
= 0; index
< phba
->io_channel_irqs
; index
++)
9598 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9599 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9602 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9603 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9605 free_irq(phba
->pcidev
->irq
, phba
);
9608 pci_free_irq_vectors(phba
->pcidev
);
9610 /* Reset interrupt management states */
9611 phba
->intr_type
= NONE
;
9612 phba
->sli
.slistat
.sli_intr
= 0;
9616 * lpfc_unset_hba - Unset SLI3 hba device initialization
9617 * @phba: pointer to lpfc hba data structure.
9619 * This routine is invoked to unset the HBA device initialization steps to
9620 * a device with SLI-3 interface spec.
9623 lpfc_unset_hba(struct lpfc_hba
*phba
)
9625 struct lpfc_vport
*vport
= phba
->pport
;
9626 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
9628 spin_lock_irq(shost
->host_lock
);
9629 vport
->load_flag
|= FC_UNLOADING
;
9630 spin_unlock_irq(shost
->host_lock
);
9632 kfree(phba
->vpi_bmask
);
9633 kfree(phba
->vpi_ids
);
9635 lpfc_stop_hba_timers(phba
);
9637 phba
->pport
->work_port_events
= 0;
9639 lpfc_sli_hba_down(phba
);
9641 lpfc_sli_brdrestart(phba
);
9643 lpfc_sli_disable_intr(phba
);
9649 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9650 * @phba: Pointer to HBA context object.
9652 * This function is called in the SLI4 code path to wait for completion
9653 * of device's XRIs exchange busy. It will check the XRI exchange busy
9654 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9655 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9656 * I/Os every 30 seconds, log error message, and wait forever. Only when
9657 * all XRI exchange busy complete, the driver unload shall proceed with
9658 * invoking the function reset ioctl mailbox command to the CNA and the
9659 * the rest of the driver unload resource release.
9662 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
9665 int nvme_xri_cmpl
= 1;
9666 int fcp_xri_cmpl
= 1;
9667 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
9668 int nvmet_xri_cmpl
=
9669 list_empty(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
9671 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
9673 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
9674 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
9676 list_empty(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
9678 while (!fcp_xri_cmpl
|| !els_xri_cmpl
|| !nvme_xri_cmpl
||
9680 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
9682 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9683 "6100 NVME XRI exchange busy "
9684 "wait time: %d seconds.\n",
9687 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9688 "2877 FCP XRI exchange busy "
9689 "wait time: %d seconds.\n",
9692 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9693 "2878 ELS XRI exchange busy "
9694 "wait time: %d seconds.\n",
9696 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
9697 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
9699 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
9700 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
9702 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
9703 nvme_xri_cmpl
= list_empty(
9704 &phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
9706 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
9707 fcp_xri_cmpl
= list_empty(
9708 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
9711 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
9714 list_empty(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
9719 * lpfc_sli4_hba_unset - Unset the fcoe hba
9720 * @phba: Pointer to HBA context object.
9722 * This function is called in the SLI4 code path to reset the HBA's FCoE
9723 * function. The caller is not required to hold any lock. This routine
9724 * issues PCI function reset mailbox command to reset the FCoE function.
9725 * At the end of the function, it calls lpfc_hba_down_post function to
9726 * free any pending commands.
9729 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
9732 LPFC_MBOXQ_t
*mboxq
;
9733 struct pci_dev
*pdev
= phba
->pcidev
;
9735 lpfc_stop_hba_timers(phba
);
9736 phba
->sli4_hba
.intr_enable
= 0;
9739 * Gracefully wait out the potential current outstanding asynchronous
9743 /* First, block any pending async mailbox command from posted */
9744 spin_lock_irq(&phba
->hbalock
);
9745 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
9746 spin_unlock_irq(&phba
->hbalock
);
9747 /* Now, trying to wait it out if we can */
9748 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
9750 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
9753 /* Forcefully release the outstanding mailbox command if timed out */
9754 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
9755 spin_lock_irq(&phba
->hbalock
);
9756 mboxq
= phba
->sli
.mbox_active
;
9757 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9758 __lpfc_mbox_cmpl_put(phba
, mboxq
);
9759 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9760 phba
->sli
.mbox_active
= NULL
;
9761 spin_unlock_irq(&phba
->hbalock
);
9764 /* Abort all iocbs associated with the hba */
9765 lpfc_sli_hba_iocb_abort(phba
);
9767 /* Wait for completion of device XRI exchange busy */
9768 lpfc_sli4_xri_exchange_busy_wait(phba
);
9770 /* Disable PCI subsystem interrupt */
9771 lpfc_sli4_disable_intr(phba
);
9773 /* Disable SR-IOV if enabled */
9774 if (phba
->cfg_sriov_nr_virtfn
)
9775 pci_disable_sriov(pdev
);
9777 /* Stop kthread signal shall trigger work_done one more time */
9778 kthread_stop(phba
->worker_thread
);
9780 /* Reset SLI4 HBA FCoE function */
9781 lpfc_pci_function_reset(phba
);
9782 lpfc_sli4_queue_destroy(phba
);
9784 /* Stop the SLI4 device port */
9785 phba
->pport
->work_port_events
= 0;
9789 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9790 * @phba: Pointer to HBA context object.
9791 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9793 * This function is called in the SLI4 code path to read the port's
9794 * sli4 capabilities.
9796 * This function may be be called from any context that can block-wait
9797 * for the completion. The expectation is that this routine is called
9798 * typically from probe_one or from the online routine.
9801 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
9804 struct lpfc_mqe
*mqe
;
9805 struct lpfc_pc_sli4_params
*sli4_params
;
9809 mqe
= &mboxq
->u
.mqe
;
9811 /* Read the port's SLI4 Parameters port capabilities */
9812 lpfc_pc_sli4_params(mboxq
);
9813 if (!phba
->sli4_hba
.intr_enable
)
9814 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9816 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
9817 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
9823 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
9824 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
9825 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
9826 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
9827 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
9828 &mqe
->un
.sli4_params
);
9829 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
9830 &mqe
->un
.sli4_params
);
9831 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
9832 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
9833 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
9834 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
9835 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
9836 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
9837 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
9838 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
9839 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
9840 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
9841 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
9842 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
9843 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
9844 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
9845 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
9846 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
9847 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
9848 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
9849 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
9850 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
9851 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
9853 /* Make sure that sge_supp_len can be handled by the driver */
9854 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
9855 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
9861 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9862 * @phba: Pointer to HBA context object.
9863 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9865 * This function is called in the SLI4 code path to read the port's
9866 * sli4 capabilities.
9868 * This function may be be called from any context that can block-wait
9869 * for the completion. The expectation is that this routine is called
9870 * typically from probe_one or from the online routine.
9873 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
9876 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
9877 struct lpfc_pc_sli4_params
*sli4_params
;
9880 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
9883 * By default, the driver assumes the SLI4 port requires RPI
9884 * header postings. The SLI4_PARAM response will correct this
9887 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
9889 /* Read the port's SLI4 Config Parameters */
9890 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
9891 sizeof(struct lpfc_sli4_cfg_mhdr
));
9892 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9893 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
9894 length
, LPFC_SLI4_MBX_EMBED
);
9895 if (!phba
->sli4_hba
.intr_enable
)
9896 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9898 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
9899 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
9903 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
9904 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
9905 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
9906 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
9907 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
9908 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
9909 mbx_sli4_parameters
);
9910 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
9911 mbx_sli4_parameters
);
9912 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
9913 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
9915 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
9916 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
9917 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
9918 sli4_params
->oas_supported
= bf_get(cfg_oas
, mbx_sli4_parameters
);
9919 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
9920 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
9921 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
9922 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
9923 sli4_params
->wqsize
= bf_get(cfg_wqsize
, mbx_sli4_parameters
);
9924 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
9925 mbx_sli4_parameters
);
9926 sli4_params
->wqpcnt
= bf_get(cfg_wqpcnt
, mbx_sli4_parameters
);
9927 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
9928 mbx_sli4_parameters
);
9929 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
9930 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
9931 phba
->nvme_support
= (bf_get(cfg_nvme
, mbx_sli4_parameters
) &&
9932 bf_get(cfg_xib
, mbx_sli4_parameters
));
9934 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
) ||
9935 !phba
->nvme_support
) {
9936 phba
->nvme_support
= 0;
9937 phba
->nvmet_support
= 0;
9938 phba
->cfg_nvme_io_channel
= 0;
9939 phba
->io_channel_irqs
= phba
->cfg_fcp_io_channel
;
9940 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_NVME
,
9941 "6101 Disabling NVME support: "
9942 "Not supported by firmware: %d %d\n",
9943 bf_get(cfg_nvme
, mbx_sli4_parameters
),
9944 bf_get(cfg_xib
, mbx_sli4_parameters
));
9946 /* If firmware doesn't support NVME, just use SCSI support */
9947 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
9949 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_FCP
;
9952 if (bf_get(cfg_xib
, mbx_sli4_parameters
) && phba
->cfg_suppress_rsp
)
9953 phba
->sli
.sli_flag
|= LPFC_SLI_SUPPRESS_RSP
;
9955 /* Make sure that sge_supp_len can be handled by the driver */
9956 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
9957 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
9960 * Issue IOs with CDB embedded in WQE to minimized the number
9961 * of DMAs the firmware has to do. Setting this to 1 also forces
9962 * the driver to use 128 bytes WQEs for FCP IOs.
9964 if (bf_get(cfg_ext_embed_cb
, mbx_sli4_parameters
))
9965 phba
->fcp_embed_io
= 1;
9967 phba
->fcp_embed_io
= 0;
9970 * Check if the SLI port supports MDS Diagnostics
9972 if (bf_get(cfg_mds_diags
, mbx_sli4_parameters
))
9973 phba
->mds_diags_support
= 1;
9975 phba
->mds_diags_support
= 0;
9980 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9981 * @pdev: pointer to PCI device
9982 * @pid: pointer to PCI device identifier
9984 * This routine is to be called to attach a device with SLI-3 interface spec
9985 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9986 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9987 * information of the device and driver to see if the driver state that it can
9988 * support this kind of device. If the match is successful, the driver core
9989 * invokes this routine. If this routine determines it can claim the HBA, it
9990 * does all the initialization that it needs to do to handle the HBA properly.
9993 * 0 - driver can claim the device
9994 * negative value - driver can not claim the device
9997 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9999 struct lpfc_hba
*phba
;
10000 struct lpfc_vport
*vport
= NULL
;
10001 struct Scsi_Host
*shost
= NULL
;
10003 uint32_t cfg_mode
, intr_mode
;
10005 /* Allocate memory for HBA structure */
10006 phba
= lpfc_hba_alloc(pdev
);
10010 /* Perform generic PCI device enabling operation */
10011 error
= lpfc_enable_pci_dev(phba
);
10013 goto out_free_phba
;
10015 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10016 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
10018 goto out_disable_pci_dev
;
10020 /* Set up SLI-3 specific device PCI memory space */
10021 error
= lpfc_sli_pci_mem_setup(phba
);
10023 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10024 "1402 Failed to set up pci memory space.\n");
10025 goto out_disable_pci_dev
;
10028 /* Set up SLI-3 specific device driver resources */
10029 error
= lpfc_sli_driver_resource_setup(phba
);
10031 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10032 "1404 Failed to set up driver resource.\n");
10033 goto out_unset_pci_mem_s3
;
10036 /* Initialize and populate the iocb list per host */
10037 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
10039 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10040 "1405 Failed to initialize iocb list.\n");
10041 goto out_unset_driver_resource_s3
;
10044 /* Set up common device driver resources */
10045 error
= lpfc_setup_driver_resource_phase2(phba
);
10047 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10048 "1406 Failed to set up driver resource.\n");
10049 goto out_free_iocb_list
;
10052 /* Get the default values for Model Name and Description */
10053 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
10055 /* Create SCSI host to the physical port */
10056 error
= lpfc_create_shost(phba
);
10058 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10059 "1407 Failed to create scsi host.\n");
10060 goto out_unset_driver_resource
;
10063 /* Configure sysfs attributes */
10064 vport
= phba
->pport
;
10065 error
= lpfc_alloc_sysfs_attr(vport
);
10067 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10068 "1476 Failed to allocate sysfs attr\n");
10069 goto out_destroy_shost
;
10072 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
10073 /* Now, trying to enable interrupt and bring up the device */
10074 cfg_mode
= phba
->cfg_use_msi
;
10076 /* Put device to a known state before enabling interrupt */
10077 lpfc_stop_port(phba
);
10078 /* Configure and enable interrupt */
10079 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
10080 if (intr_mode
== LPFC_INTR_ERROR
) {
10081 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10082 "0431 Failed to enable interrupt.\n");
10084 goto out_free_sysfs_attr
;
10086 /* SLI-3 HBA setup */
10087 if (lpfc_sli_hba_setup(phba
)) {
10088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10089 "1477 Failed to set up hba\n");
10091 goto out_remove_device
;
10094 /* Wait 50ms for the interrupts of previous mailbox commands */
10096 /* Check active interrupts on message signaled interrupts */
10097 if (intr_mode
== 0 ||
10098 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
10099 /* Log the current active interrupt mode */
10100 phba
->intr_mode
= intr_mode
;
10101 lpfc_log_intr_mode(phba
, intr_mode
);
10104 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10105 "0447 Configure interrupt mode (%d) "
10106 "failed active interrupt test.\n",
10108 /* Disable the current interrupt mode */
10109 lpfc_sli_disable_intr(phba
);
10110 /* Try next level of interrupt mode */
10111 cfg_mode
= --intr_mode
;
10115 /* Perform post initialization setup */
10116 lpfc_post_init_setup(phba
);
10118 /* Check if there are static vports to be created. */
10119 lpfc_create_static_vport(phba
);
10124 lpfc_unset_hba(phba
);
10125 out_free_sysfs_attr
:
10126 lpfc_free_sysfs_attr(vport
);
10128 lpfc_destroy_shost(phba
);
10129 out_unset_driver_resource
:
10130 lpfc_unset_driver_resource_phase2(phba
);
10131 out_free_iocb_list
:
10132 lpfc_free_iocb_list(phba
);
10133 out_unset_driver_resource_s3
:
10134 lpfc_sli_driver_resource_unset(phba
);
10135 out_unset_pci_mem_s3
:
10136 lpfc_sli_pci_mem_unset(phba
);
10137 out_disable_pci_dev
:
10138 lpfc_disable_pci_dev(phba
);
10140 scsi_host_put(shost
);
10142 lpfc_hba_free(phba
);
10147 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10148 * @pdev: pointer to PCI device
10150 * This routine is to be called to disattach a device with SLI-3 interface
10151 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10152 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10153 * device to be removed from the PCI subsystem properly.
10156 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
10158 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10159 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
10160 struct lpfc_vport
**vports
;
10161 struct lpfc_hba
*phba
= vport
->phba
;
10164 spin_lock_irq(&phba
->hbalock
);
10165 vport
->load_flag
|= FC_UNLOADING
;
10166 spin_unlock_irq(&phba
->hbalock
);
10168 lpfc_free_sysfs_attr(vport
);
10170 /* Release all the vports against this physical port */
10171 vports
= lpfc_create_vport_work_array(phba
);
10172 if (vports
!= NULL
)
10173 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
10174 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
10176 fc_vport_terminate(vports
[i
]->fc_vport
);
10178 lpfc_destroy_vport_work_array(phba
, vports
);
10180 /* Remove FC host and then SCSI host with the physical port */
10181 fc_remove_host(shost
);
10182 scsi_remove_host(shost
);
10183 lpfc_cleanup(vport
);
10186 * Bring down the SLI Layer. This step disable all interrupts,
10187 * clears the rings, discards all mailbox commands, and resets
10191 /* HBA interrupt will be disabled after this call */
10192 lpfc_sli_hba_down(phba
);
10193 /* Stop kthread signal shall trigger work_done one more time */
10194 kthread_stop(phba
->worker_thread
);
10195 /* Final cleanup of txcmplq and reset the HBA */
10196 lpfc_sli_brdrestart(phba
);
10198 kfree(phba
->vpi_bmask
);
10199 kfree(phba
->vpi_ids
);
10201 lpfc_stop_hba_timers(phba
);
10202 spin_lock_irq(&phba
->hbalock
);
10203 list_del_init(&vport
->listentry
);
10204 spin_unlock_irq(&phba
->hbalock
);
10206 lpfc_debugfs_terminate(vport
);
10208 /* Disable SR-IOV if enabled */
10209 if (phba
->cfg_sriov_nr_virtfn
)
10210 pci_disable_sriov(pdev
);
10212 /* Disable interrupt */
10213 lpfc_sli_disable_intr(phba
);
10215 scsi_host_put(shost
);
10218 * Call scsi_free before mem_free since scsi bufs are released to their
10219 * corresponding pools here.
10221 lpfc_scsi_free(phba
);
10222 lpfc_mem_free_all(phba
);
10224 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
10225 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
10227 /* Free resources associated with SLI2 interface */
10228 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
10229 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
10231 /* unmap adapter SLIM and Control Registers */
10232 iounmap(phba
->ctrl_regs_memmap_p
);
10233 iounmap(phba
->slim_memmap_p
);
10235 lpfc_hba_free(phba
);
10237 pci_release_mem_regions(pdev
);
10238 pci_disable_device(pdev
);
10242 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
10243 * @pdev: pointer to PCI device
10244 * @msg: power management message
10246 * This routine is to be called from the kernel's PCI subsystem to support
10247 * system Power Management (PM) to device with SLI-3 interface spec. When
10248 * PM invokes this method, it quiesces the device by stopping the driver's
10249 * worker thread for the device, turning off device's interrupt and DMA,
10250 * and bring the device offline. Note that as the driver implements the
10251 * minimum PM requirements to a power-aware driver's PM support for the
10252 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10253 * to the suspend() method call will be treated as SUSPEND and the driver will
10254 * fully reinitialize its device during resume() method call, the driver will
10255 * set device to PCI_D3hot state in PCI config space instead of setting it
10256 * according to the @msg provided by the PM.
10259 * 0 - driver suspended the device
10263 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
10265 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10266 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10268 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10269 "0473 PCI device Power Management suspend.\n");
10271 /* Bring down the device */
10272 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10273 lpfc_offline(phba
);
10274 kthread_stop(phba
->worker_thread
);
10276 /* Disable interrupt from device */
10277 lpfc_sli_disable_intr(phba
);
10279 /* Save device state to PCI config space */
10280 pci_save_state(pdev
);
10281 pci_set_power_state(pdev
, PCI_D3hot
);
10287 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
10288 * @pdev: pointer to PCI device
10290 * This routine is to be called from the kernel's PCI subsystem to support
10291 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10292 * invokes this method, it restores the device's PCI config space state and
10293 * fully reinitializes the device and brings it online. Note that as the
10294 * driver implements the minimum PM requirements to a power-aware driver's
10295 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10296 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10297 * driver will fully reinitialize its device during resume() method call,
10298 * the device will be set to PCI_D0 directly in PCI config space before
10299 * restoring the state.
10302 * 0 - driver suspended the device
10306 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
10308 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10309 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10310 uint32_t intr_mode
;
10313 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10314 "0452 PCI device Power Management resume.\n");
10316 /* Restore device state from PCI config space */
10317 pci_set_power_state(pdev
, PCI_D0
);
10318 pci_restore_state(pdev
);
10321 * As the new kernel behavior of pci_restore_state() API call clears
10322 * device saved_state flag, need to save the restored state again.
10324 pci_save_state(pdev
);
10326 if (pdev
->is_busmaster
)
10327 pci_set_master(pdev
);
10329 /* Startup the kernel thread for this host adapter. */
10330 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
10331 "lpfc_worker_%d", phba
->brd_no
);
10332 if (IS_ERR(phba
->worker_thread
)) {
10333 error
= PTR_ERR(phba
->worker_thread
);
10334 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10335 "0434 PM resume failed to start worker "
10336 "thread: error=x%x.\n", error
);
10340 /* Configure and enable interrupt */
10341 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
10342 if (intr_mode
== LPFC_INTR_ERROR
) {
10343 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10344 "0430 PM resume Failed to enable interrupt\n");
10347 phba
->intr_mode
= intr_mode
;
10349 /* Restart HBA and bring it online */
10350 lpfc_sli_brdrestart(phba
);
10353 /* Log the current active interrupt mode */
10354 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10360 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10361 * @phba: pointer to lpfc hba data structure.
10363 * This routine is called to prepare the SLI3 device for PCI slot recover. It
10364 * aborts all the outstanding SCSI I/Os to the pci device.
10367 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
10369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10370 "2723 PCI channel I/O abort preparing for recovery\n");
10373 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10374 * and let the SCSI mid-layer to retry them to recover.
10376 lpfc_sli_abort_fcp_rings(phba
);
10380 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10381 * @phba: pointer to lpfc hba data structure.
10383 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10384 * disables the device interrupt and pci device, and aborts the internal FCP
10388 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
10390 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10391 "2710 PCI channel disable preparing for reset\n");
10393 /* Block any management I/Os to the device */
10394 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
10396 /* Block all SCSI devices' I/Os on the host */
10397 lpfc_scsi_dev_block(phba
);
10399 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10400 lpfc_sli_flush_fcp_rings(phba
);
10402 /* stop all timers */
10403 lpfc_stop_hba_timers(phba
);
10405 /* Disable interrupt and pci device */
10406 lpfc_sli_disable_intr(phba
);
10407 pci_disable_device(phba
->pcidev
);
10411 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10412 * @phba: pointer to lpfc hba data structure.
10414 * This routine is called to prepare the SLI3 device for PCI slot permanently
10415 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10419 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
10421 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10422 "2711 PCI channel permanent disable for failure\n");
10423 /* Block all SCSI devices' I/Os on the host */
10424 lpfc_scsi_dev_block(phba
);
10426 /* stop all timers */
10427 lpfc_stop_hba_timers(phba
);
10429 /* Clean up all driver's outstanding SCSI I/Os */
10430 lpfc_sli_flush_fcp_rings(phba
);
10434 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
10435 * @pdev: pointer to PCI device.
10436 * @state: the current PCI connection state.
10438 * This routine is called from the PCI subsystem for I/O error handling to
10439 * device with SLI-3 interface spec. This function is called by the PCI
10440 * subsystem after a PCI bus error affecting this device has been detected.
10441 * When this function is invoked, it will need to stop all the I/Os and
10442 * interrupt(s) to the device. Once that is done, it will return
10443 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10447 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
10448 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10449 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10451 static pci_ers_result_t
10452 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
10454 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10455 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10458 case pci_channel_io_normal
:
10459 /* Non-fatal error, prepare for recovery */
10460 lpfc_sli_prep_dev_for_recover(phba
);
10461 return PCI_ERS_RESULT_CAN_RECOVER
;
10462 case pci_channel_io_frozen
:
10463 /* Fatal error, prepare for slot reset */
10464 lpfc_sli_prep_dev_for_reset(phba
);
10465 return PCI_ERS_RESULT_NEED_RESET
;
10466 case pci_channel_io_perm_failure
:
10467 /* Permanent failure, prepare for device down */
10468 lpfc_sli_prep_dev_for_perm_failure(phba
);
10469 return PCI_ERS_RESULT_DISCONNECT
;
10471 /* Unknown state, prepare and request slot reset */
10472 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10473 "0472 Unknown PCI error state: x%x\n", state
);
10474 lpfc_sli_prep_dev_for_reset(phba
);
10475 return PCI_ERS_RESULT_NEED_RESET
;
10480 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
10481 * @pdev: pointer to PCI device.
10483 * This routine is called from the PCI subsystem for error handling to
10484 * device with SLI-3 interface spec. This is called after PCI bus has been
10485 * reset to restart the PCI card from scratch, as if from a cold-boot.
10486 * During the PCI subsystem error recovery, after driver returns
10487 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10488 * recovery and then call this routine before calling the .resume method
10489 * to recover the device. This function will initialize the HBA device,
10490 * enable the interrupt, but it will just put the HBA to offline state
10491 * without passing any I/O traffic.
10494 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10495 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10497 static pci_ers_result_t
10498 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
10500 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10501 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10502 struct lpfc_sli
*psli
= &phba
->sli
;
10503 uint32_t intr_mode
;
10505 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
10506 if (pci_enable_device_mem(pdev
)) {
10507 printk(KERN_ERR
"lpfc: Cannot re-enable "
10508 "PCI device after reset.\n");
10509 return PCI_ERS_RESULT_DISCONNECT
;
10512 pci_restore_state(pdev
);
10515 * As the new kernel behavior of pci_restore_state() API call clears
10516 * device saved_state flag, need to save the restored state again.
10518 pci_save_state(pdev
);
10520 if (pdev
->is_busmaster
)
10521 pci_set_master(pdev
);
10523 spin_lock_irq(&phba
->hbalock
);
10524 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
10525 spin_unlock_irq(&phba
->hbalock
);
10527 /* Configure and enable interrupt */
10528 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
10529 if (intr_mode
== LPFC_INTR_ERROR
) {
10530 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10531 "0427 Cannot re-enable interrupt after "
10533 return PCI_ERS_RESULT_DISCONNECT
;
10535 phba
->intr_mode
= intr_mode
;
10537 /* Take device offline, it will perform cleanup */
10538 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10539 lpfc_offline(phba
);
10540 lpfc_sli_brdrestart(phba
);
10542 /* Log the current active interrupt mode */
10543 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10545 return PCI_ERS_RESULT_RECOVERED
;
10549 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
10550 * @pdev: pointer to PCI device
10552 * This routine is called from the PCI subsystem for error handling to device
10553 * with SLI-3 interface spec. It is called when kernel error recovery tells
10554 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10555 * error recovery. After this call, traffic can start to flow from this device
10559 lpfc_io_resume_s3(struct pci_dev
*pdev
)
10561 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10562 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10564 /* Bring device online, it will be no-op for non-fatal error resume */
10567 /* Clean up Advanced Error Reporting (AER) if needed */
10568 if (phba
->hba_flag
& HBA_AER_ENABLED
)
10569 pci_cleanup_aer_uncorrect_error_status(pdev
);
10573 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10574 * @phba: pointer to lpfc hba data structure.
10576 * returns the number of ELS/CT IOCBs to reserve
10579 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
10581 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
10583 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10584 if (max_xri
<= 100)
10586 else if (max_xri
<= 256)
10588 else if (max_xri
<= 512)
10590 else if (max_xri
<= 1024)
10592 else if (max_xri
<= 1536)
10594 else if (max_xri
<= 2048)
10603 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10604 * @phba: pointer to lpfc hba data structure.
10606 * returns the number of ELS/CT + NVMET IOCBs to reserve
10609 lpfc_sli4_get_iocb_cnt(struct lpfc_hba
*phba
)
10611 int max_xri
= lpfc_sli4_get_els_iocb_cnt(phba
);
10613 if (phba
->nvmet_support
)
10614 max_xri
+= LPFC_NVMET_BUF_POST
;
10620 * lpfc_write_firmware - attempt to write a firmware image to the port
10621 * @fw: pointer to firmware image returned from request_firmware.
10622 * @phba: pointer to lpfc hba data structure.
10626 lpfc_write_firmware(const struct firmware
*fw
, void *context
)
10628 struct lpfc_hba
*phba
= (struct lpfc_hba
*)context
;
10629 char fwrev
[FW_REV_STR_SIZE
];
10630 struct lpfc_grp_hdr
*image
;
10631 struct list_head dma_buffer_list
;
10633 struct lpfc_dmabuf
*dmabuf
, *next
;
10634 uint32_t offset
= 0, temp_offset
= 0;
10635 uint32_t magic_number
, ftype
, fid
, fsize
;
10637 /* It can be null in no-wait mode, sanity check */
10642 image
= (struct lpfc_grp_hdr
*)fw
->data
;
10644 magic_number
= be32_to_cpu(image
->magic_number
);
10645 ftype
= bf_get_be32(lpfc_grp_hdr_file_type
, image
);
10646 fid
= bf_get_be32(lpfc_grp_hdr_id
, image
),
10647 fsize
= be32_to_cpu(image
->size
);
10649 INIT_LIST_HEAD(&dma_buffer_list
);
10650 if ((magic_number
!= LPFC_GROUP_OJECT_MAGIC_G5
&&
10651 magic_number
!= LPFC_GROUP_OJECT_MAGIC_G6
) ||
10652 ftype
!= LPFC_FILE_TYPE_GROUP
|| fsize
!= fw
->size
) {
10653 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10654 "3022 Invalid FW image found. "
10655 "Magic:%x Type:%x ID:%x Size %d %zd\n",
10656 magic_number
, ftype
, fid
, fsize
, fw
->size
);
10660 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
10661 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
10662 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10663 "3023 Updating Firmware, Current Version:%s "
10664 "New Version:%s\n",
10665 fwrev
, image
->revision
);
10666 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
10667 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
10673 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
10677 if (!dmabuf
->virt
) {
10682 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
10684 while (offset
< fw
->size
) {
10685 temp_offset
= offset
;
10686 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
10687 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
10688 memcpy(dmabuf
->virt
,
10689 fw
->data
+ temp_offset
,
10690 fw
->size
- temp_offset
);
10691 temp_offset
= fw
->size
;
10694 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
10696 temp_offset
+= SLI4_PAGE_SIZE
;
10698 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
10699 (fw
->size
- offset
), &offset
);
10707 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
10708 list_del(&dmabuf
->list
);
10709 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
10710 dmabuf
->virt
, dmabuf
->phys
);
10713 release_firmware(fw
);
10715 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10716 "3024 Firmware update done: %d.\n", rc
);
10721 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10722 * @phba: pointer to lpfc hba data structure.
10724 * This routine is called to perform Linux generic firmware upgrade on device
10725 * that supports such feature.
10728 lpfc_sli4_request_firmware_update(struct lpfc_hba
*phba
, uint8_t fw_upgrade
)
10730 uint8_t file_name
[ELX_MODEL_NAME_SIZE
];
10732 const struct firmware
*fw
;
10734 /* Only supported on SLI4 interface type 2 for now */
10735 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
10736 LPFC_SLI_INTF_IF_TYPE_2
)
10739 snprintf(file_name
, ELX_MODEL_NAME_SIZE
, "%s.grp", phba
->ModelName
);
10741 if (fw_upgrade
== INT_FW_UPGRADE
) {
10742 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
10743 file_name
, &phba
->pcidev
->dev
,
10744 GFP_KERNEL
, (void *)phba
,
10745 lpfc_write_firmware
);
10746 } else if (fw_upgrade
== RUN_FW_UPGRADE
) {
10747 ret
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
10749 lpfc_write_firmware(fw
, (void *)phba
);
10758 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10759 * @pdev: pointer to PCI device
10760 * @pid: pointer to PCI device identifier
10762 * This routine is called from the kernel's PCI subsystem to device with
10763 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10764 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10765 * information of the device and driver to see if the driver state that it
10766 * can support this kind of device. If the match is successful, the driver
10767 * core invokes this routine. If this routine determines it can claim the HBA,
10768 * it does all the initialization that it needs to do to handle the HBA
10772 * 0 - driver can claim the device
10773 * negative value - driver can not claim the device
10776 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
10778 struct lpfc_hba
*phba
;
10779 struct lpfc_vport
*vport
= NULL
;
10780 struct Scsi_Host
*shost
= NULL
;
10782 uint32_t cfg_mode
, intr_mode
;
10784 /* Allocate memory for HBA structure */
10785 phba
= lpfc_hba_alloc(pdev
);
10789 /* Perform generic PCI device enabling operation */
10790 error
= lpfc_enable_pci_dev(phba
);
10792 goto out_free_phba
;
10794 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10795 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
10797 goto out_disable_pci_dev
;
10799 /* Set up SLI-4 specific device PCI memory space */
10800 error
= lpfc_sli4_pci_mem_setup(phba
);
10802 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10803 "1410 Failed to set up pci memory space.\n");
10804 goto out_disable_pci_dev
;
10807 /* Set up SLI-4 Specific device driver resources */
10808 error
= lpfc_sli4_driver_resource_setup(phba
);
10810 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10811 "1412 Failed to set up driver resource.\n");
10812 goto out_unset_pci_mem_s4
;
10815 /* Initialize and populate the iocb list per host */
10817 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10818 "2821 initialize iocb list %d.\n",
10819 phba
->cfg_iocb_cnt
*1024);
10820 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
10823 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10824 "1413 Failed to initialize iocb list.\n");
10825 goto out_unset_driver_resource_s4
;
10828 INIT_LIST_HEAD(&phba
->active_rrq_list
);
10829 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
10831 /* Set up common device driver resources */
10832 error
= lpfc_setup_driver_resource_phase2(phba
);
10834 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10835 "1414 Failed to set up driver resource.\n");
10836 goto out_free_iocb_list
;
10839 /* Get the default values for Model Name and Description */
10840 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
10842 /* Create SCSI host to the physical port */
10843 error
= lpfc_create_shost(phba
);
10845 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10846 "1415 Failed to create scsi host.\n");
10847 goto out_unset_driver_resource
;
10850 /* Configure sysfs attributes */
10851 vport
= phba
->pport
;
10852 error
= lpfc_alloc_sysfs_attr(vport
);
10854 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10855 "1416 Failed to allocate sysfs attr\n");
10856 goto out_destroy_shost
;
10859 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
10860 /* Now, trying to enable interrupt and bring up the device */
10861 cfg_mode
= phba
->cfg_use_msi
;
10863 /* Put device to a known state before enabling interrupt */
10864 lpfc_stop_port(phba
);
10866 /* Configure and enable interrupt */
10867 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
10868 if (intr_mode
== LPFC_INTR_ERROR
) {
10869 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10870 "0426 Failed to enable interrupt.\n");
10872 goto out_free_sysfs_attr
;
10874 /* Default to single EQ for non-MSI-X */
10875 if (phba
->intr_type
!= MSIX
) {
10876 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
10877 phba
->cfg_fcp_io_channel
= 1;
10878 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
10879 phba
->cfg_nvme_io_channel
= 1;
10880 phba
->io_channel_irqs
= 1;
10884 /* Set up SLI-4 HBA */
10885 if (lpfc_sli4_hba_setup(phba
)) {
10886 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10887 "1421 Failed to set up hba\n");
10889 goto out_disable_intr
;
10892 /* Log the current active interrupt mode */
10893 phba
->intr_mode
= intr_mode
;
10894 lpfc_log_intr_mode(phba
, intr_mode
);
10896 /* Perform post initialization setup */
10897 lpfc_post_init_setup(phba
);
10899 /* NVME support in FW earlier in the driver load corrects the
10900 * FC4 type making a check for nvme_support unnecessary.
10902 if ((phba
->nvmet_support
== 0) &&
10903 (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)) {
10904 /* Create NVME binding with nvme_fc_transport. This
10905 * ensures the vport is initialized.
10907 error
= lpfc_nvme_create_localport(vport
);
10909 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10910 "6004 NVME registration failed, "
10913 goto out_disable_intr
;
10917 /* check for firmware upgrade or downgrade */
10918 if (phba
->cfg_request_firmware_upgrade
)
10919 lpfc_sli4_request_firmware_update(phba
, INT_FW_UPGRADE
);
10921 /* Check if there are static vports to be created. */
10922 lpfc_create_static_vport(phba
);
10926 lpfc_sli4_disable_intr(phba
);
10927 out_free_sysfs_attr
:
10928 lpfc_free_sysfs_attr(vport
);
10930 lpfc_destroy_shost(phba
);
10931 out_unset_driver_resource
:
10932 lpfc_unset_driver_resource_phase2(phba
);
10933 out_free_iocb_list
:
10934 lpfc_free_iocb_list(phba
);
10935 out_unset_driver_resource_s4
:
10936 lpfc_sli4_driver_resource_unset(phba
);
10937 out_unset_pci_mem_s4
:
10938 lpfc_sli4_pci_mem_unset(phba
);
10939 out_disable_pci_dev
:
10940 lpfc_disable_pci_dev(phba
);
10942 scsi_host_put(shost
);
10944 lpfc_hba_free(phba
);
10949 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10950 * @pdev: pointer to PCI device
10952 * This routine is called from the kernel's PCI subsystem to device with
10953 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10954 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10955 * device to be removed from the PCI subsystem properly.
10958 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
10960 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10961 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
10962 struct lpfc_vport
**vports
;
10963 struct lpfc_hba
*phba
= vport
->phba
;
10966 /* Mark the device unloading flag */
10967 spin_lock_irq(&phba
->hbalock
);
10968 vport
->load_flag
|= FC_UNLOADING
;
10969 spin_unlock_irq(&phba
->hbalock
);
10971 /* Free the HBA sysfs attributes */
10972 lpfc_free_sysfs_attr(vport
);
10974 /* Release all the vports against this physical port */
10975 vports
= lpfc_create_vport_work_array(phba
);
10976 if (vports
!= NULL
)
10977 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
10978 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
10980 fc_vport_terminate(vports
[i
]->fc_vport
);
10982 lpfc_destroy_vport_work_array(phba
, vports
);
10984 /* Remove FC host and then SCSI host with the physical port */
10985 fc_remove_host(shost
);
10986 scsi_remove_host(shost
);
10987 /* todo: tgt: remove targetport */
10989 /* Perform ndlp cleanup on the physical port. The nvme localport
10990 * is destroyed after to ensure all rports are io-disabled.
10992 lpfc_nvme_destroy_localport(vport
);
10993 lpfc_cleanup(vport
);
10996 * Bring down the SLI Layer. This step disables all interrupts,
10997 * clears the rings, discards all mailbox commands, and resets
10998 * the HBA FCoE function.
11000 lpfc_debugfs_terminate(vport
);
11001 lpfc_sli4_hba_unset(phba
);
11003 spin_lock_irq(&phba
->hbalock
);
11004 list_del_init(&vport
->listentry
);
11005 spin_unlock_irq(&phba
->hbalock
);
11007 /* Perform scsi free before driver resource_unset since scsi
11008 * buffers are released to their corresponding pools here.
11010 lpfc_scsi_free(phba
);
11011 lpfc_nvme_free(phba
);
11012 lpfc_free_iocb_list(phba
);
11014 lpfc_sli4_driver_resource_unset(phba
);
11016 /* Unmap adapter Control and Doorbell registers */
11017 lpfc_sli4_pci_mem_unset(phba
);
11019 /* Release PCI resources and disable device's PCI function */
11020 scsi_host_put(shost
);
11021 lpfc_disable_pci_dev(phba
);
11023 /* Finally, free the driver's device data structure */
11024 lpfc_hba_free(phba
);
11030 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11031 * @pdev: pointer to PCI device
11032 * @msg: power management message
11034 * This routine is called from the kernel's PCI subsystem to support system
11035 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11036 * this method, it quiesces the device by stopping the driver's worker
11037 * thread for the device, turning off device's interrupt and DMA, and bring
11038 * the device offline. Note that as the driver implements the minimum PM
11039 * requirements to a power-aware driver's PM support for suspend/resume -- all
11040 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11041 * method call will be treated as SUSPEND and the driver will fully
11042 * reinitialize its device during resume() method call, the driver will set
11043 * device to PCI_D3hot state in PCI config space instead of setting it
11044 * according to the @msg provided by the PM.
11047 * 0 - driver suspended the device
11051 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
11053 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11054 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11056 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11057 "2843 PCI device Power Management suspend.\n");
11059 /* Bring down the device */
11060 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
11061 lpfc_offline(phba
);
11062 kthread_stop(phba
->worker_thread
);
11064 /* Disable interrupt from device */
11065 lpfc_sli4_disable_intr(phba
);
11066 lpfc_sli4_queue_destroy(phba
);
11068 /* Save device state to PCI config space */
11069 pci_save_state(pdev
);
11070 pci_set_power_state(pdev
, PCI_D3hot
);
11076 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11077 * @pdev: pointer to PCI device
11079 * This routine is called from the kernel's PCI subsystem to support system
11080 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11081 * this method, it restores the device's PCI config space state and fully
11082 * reinitializes the device and brings it online. Note that as the driver
11083 * implements the minimum PM requirements to a power-aware driver's PM for
11084 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11085 * to the suspend() method call will be treated as SUSPEND and the driver
11086 * will fully reinitialize its device during resume() method call, the device
11087 * will be set to PCI_D0 directly in PCI config space before restoring the
11091 * 0 - driver suspended the device
11095 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
11097 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11098 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11099 uint32_t intr_mode
;
11102 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11103 "0292 PCI device Power Management resume.\n");
11105 /* Restore device state from PCI config space */
11106 pci_set_power_state(pdev
, PCI_D0
);
11107 pci_restore_state(pdev
);
11110 * As the new kernel behavior of pci_restore_state() API call clears
11111 * device saved_state flag, need to save the restored state again.
11113 pci_save_state(pdev
);
11115 if (pdev
->is_busmaster
)
11116 pci_set_master(pdev
);
11118 /* Startup the kernel thread for this host adapter. */
11119 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
11120 "lpfc_worker_%d", phba
->brd_no
);
11121 if (IS_ERR(phba
->worker_thread
)) {
11122 error
= PTR_ERR(phba
->worker_thread
);
11123 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11124 "0293 PM resume failed to start worker "
11125 "thread: error=x%x.\n", error
);
11129 /* Configure and enable interrupt */
11130 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
11131 if (intr_mode
== LPFC_INTR_ERROR
) {
11132 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11133 "0294 PM resume Failed to enable interrupt\n");
11136 phba
->intr_mode
= intr_mode
;
11138 /* Restart HBA and bring it online */
11139 lpfc_sli_brdrestart(phba
);
11142 /* Log the current active interrupt mode */
11143 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
11149 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11150 * @phba: pointer to lpfc hba data structure.
11152 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11153 * aborts all the outstanding SCSI I/Os to the pci device.
11156 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
11158 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11159 "2828 PCI channel I/O abort preparing for recovery\n");
11161 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11162 * and let the SCSI mid-layer to retry them to recover.
11164 lpfc_sli_abort_fcp_rings(phba
);
11168 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11169 * @phba: pointer to lpfc hba data structure.
11171 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11172 * disables the device interrupt and pci device, and aborts the internal FCP
11176 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
11178 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11179 "2826 PCI channel disable preparing for reset\n");
11181 /* Block any management I/Os to the device */
11182 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
11184 /* Block all SCSI devices' I/Os on the host */
11185 lpfc_scsi_dev_block(phba
);
11187 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11188 lpfc_sli_flush_fcp_rings(phba
);
11190 /* stop all timers */
11191 lpfc_stop_hba_timers(phba
);
11193 /* Disable interrupt and pci device */
11194 lpfc_sli4_disable_intr(phba
);
11195 lpfc_sli4_queue_destroy(phba
);
11196 pci_disable_device(phba
->pcidev
);
11200 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11201 * @phba: pointer to lpfc hba data structure.
11203 * This routine is called to prepare the SLI4 device for PCI slot permanently
11204 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11208 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
11210 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11211 "2827 PCI channel permanent disable for failure\n");
11213 /* Block all SCSI devices' I/Os on the host */
11214 lpfc_scsi_dev_block(phba
);
11216 /* stop all timers */
11217 lpfc_stop_hba_timers(phba
);
11219 /* Clean up all driver's outstanding SCSI I/Os */
11220 lpfc_sli_flush_fcp_rings(phba
);
11224 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11225 * @pdev: pointer to PCI device.
11226 * @state: the current PCI connection state.
11228 * This routine is called from the PCI subsystem for error handling to device
11229 * with SLI-4 interface spec. This function is called by the PCI subsystem
11230 * after a PCI bus error affecting this device has been detected. When this
11231 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11232 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11233 * for the PCI subsystem to perform proper recovery as desired.
11236 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11237 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11239 static pci_ers_result_t
11240 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
11242 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11243 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11246 case pci_channel_io_normal
:
11247 /* Non-fatal error, prepare for recovery */
11248 lpfc_sli4_prep_dev_for_recover(phba
);
11249 return PCI_ERS_RESULT_CAN_RECOVER
;
11250 case pci_channel_io_frozen
:
11251 /* Fatal error, prepare for slot reset */
11252 lpfc_sli4_prep_dev_for_reset(phba
);
11253 return PCI_ERS_RESULT_NEED_RESET
;
11254 case pci_channel_io_perm_failure
:
11255 /* Permanent failure, prepare for device down */
11256 lpfc_sli4_prep_dev_for_perm_failure(phba
);
11257 return PCI_ERS_RESULT_DISCONNECT
;
11259 /* Unknown state, prepare and request slot reset */
11260 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11261 "2825 Unknown PCI error state: x%x\n", state
);
11262 lpfc_sli4_prep_dev_for_reset(phba
);
11263 return PCI_ERS_RESULT_NEED_RESET
;
11268 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11269 * @pdev: pointer to PCI device.
11271 * This routine is called from the PCI subsystem for error handling to device
11272 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11273 * restart the PCI card from scratch, as if from a cold-boot. During the
11274 * PCI subsystem error recovery, after the driver returns
11275 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11276 * recovery and then call this routine before calling the .resume method to
11277 * recover the device. This function will initialize the HBA device, enable
11278 * the interrupt, but it will just put the HBA to offline state without
11279 * passing any I/O traffic.
11282 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11283 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11285 static pci_ers_result_t
11286 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
11288 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11289 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11290 struct lpfc_sli
*psli
= &phba
->sli
;
11291 uint32_t intr_mode
;
11293 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
11294 if (pci_enable_device_mem(pdev
)) {
11295 printk(KERN_ERR
"lpfc: Cannot re-enable "
11296 "PCI device after reset.\n");
11297 return PCI_ERS_RESULT_DISCONNECT
;
11300 pci_restore_state(pdev
);
11303 * As the new kernel behavior of pci_restore_state() API call clears
11304 * device saved_state flag, need to save the restored state again.
11306 pci_save_state(pdev
);
11308 if (pdev
->is_busmaster
)
11309 pci_set_master(pdev
);
11311 spin_lock_irq(&phba
->hbalock
);
11312 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
11313 spin_unlock_irq(&phba
->hbalock
);
11315 /* Configure and enable interrupt */
11316 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
11317 if (intr_mode
== LPFC_INTR_ERROR
) {
11318 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11319 "2824 Cannot re-enable interrupt after "
11321 return PCI_ERS_RESULT_DISCONNECT
;
11323 phba
->intr_mode
= intr_mode
;
11325 /* Log the current active interrupt mode */
11326 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
11328 return PCI_ERS_RESULT_RECOVERED
;
11332 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11333 * @pdev: pointer to PCI device
11335 * This routine is called from the PCI subsystem for error handling to device
11336 * with SLI-4 interface spec. It is called when kernel error recovery tells
11337 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11338 * error recovery. After this call, traffic can start to flow from this device
11342 lpfc_io_resume_s4(struct pci_dev
*pdev
)
11344 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11345 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11348 * In case of slot reset, as function reset is performed through
11349 * mailbox command which needs DMA to be enabled, this operation
11350 * has to be moved to the io resume phase. Taking device offline
11351 * will perform the necessary cleanup.
11353 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
11354 /* Perform device reset */
11355 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
11356 lpfc_offline(phba
);
11357 lpfc_sli_brdrestart(phba
);
11358 /* Bring the device back online */
11362 /* Clean up Advanced Error Reporting (AER) if needed */
11363 if (phba
->hba_flag
& HBA_AER_ENABLED
)
11364 pci_cleanup_aer_uncorrect_error_status(pdev
);
11368 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11369 * @pdev: pointer to PCI device
11370 * @pid: pointer to PCI device identifier
11372 * This routine is to be registered to the kernel's PCI subsystem. When an
11373 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11374 * at PCI device-specific information of the device and driver to see if the
11375 * driver state that it can support this kind of device. If the match is
11376 * successful, the driver core invokes this routine. This routine dispatches
11377 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11378 * do all the initialization that it needs to do to handle the HBA device
11382 * 0 - driver can claim the device
11383 * negative value - driver can not claim the device
11386 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
11389 struct lpfc_sli_intf intf
;
11391 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
11394 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
11395 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
11396 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
11398 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
11404 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11405 * @pdev: pointer to PCI device
11407 * This routine is to be registered to the kernel's PCI subsystem. When an
11408 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11409 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11410 * remove routine, which will perform all the necessary cleanup for the
11411 * device to be removed from the PCI subsystem properly.
11414 lpfc_pci_remove_one(struct pci_dev
*pdev
)
11416 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11417 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11419 switch (phba
->pci_dev_grp
) {
11420 case LPFC_PCI_DEV_LP
:
11421 lpfc_pci_remove_one_s3(pdev
);
11423 case LPFC_PCI_DEV_OC
:
11424 lpfc_pci_remove_one_s4(pdev
);
11427 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11428 "1424 Invalid PCI device group: 0x%x\n",
11429 phba
->pci_dev_grp
);
11436 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11437 * @pdev: pointer to PCI device
11438 * @msg: power management message
11440 * This routine is to be registered to the kernel's PCI subsystem to support
11441 * system Power Management (PM). When PM invokes this method, it dispatches
11442 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11443 * suspend the device.
11446 * 0 - driver suspended the device
11450 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
11452 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11453 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11456 switch (phba
->pci_dev_grp
) {
11457 case LPFC_PCI_DEV_LP
:
11458 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
11460 case LPFC_PCI_DEV_OC
:
11461 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
11464 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11465 "1425 Invalid PCI device group: 0x%x\n",
11466 phba
->pci_dev_grp
);
11473 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11474 * @pdev: pointer to PCI device
11476 * This routine is to be registered to the kernel's PCI subsystem to support
11477 * system Power Management (PM). When PM invokes this method, it dispatches
11478 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11479 * resume the device.
11482 * 0 - driver suspended the device
11486 lpfc_pci_resume_one(struct pci_dev
*pdev
)
11488 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11489 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11492 switch (phba
->pci_dev_grp
) {
11493 case LPFC_PCI_DEV_LP
:
11494 rc
= lpfc_pci_resume_one_s3(pdev
);
11496 case LPFC_PCI_DEV_OC
:
11497 rc
= lpfc_pci_resume_one_s4(pdev
);
11500 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11501 "1426 Invalid PCI device group: 0x%x\n",
11502 phba
->pci_dev_grp
);
11509 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11510 * @pdev: pointer to PCI device.
11511 * @state: the current PCI connection state.
11513 * This routine is registered to the PCI subsystem for error handling. This
11514 * function is called by the PCI subsystem after a PCI bus error affecting
11515 * this device has been detected. When this routine is invoked, it dispatches
11516 * the action to the proper SLI-3 or SLI-4 device error detected handling
11517 * routine, which will perform the proper error detected operation.
11520 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11521 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11523 static pci_ers_result_t
11524 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
11526 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11527 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11528 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
11530 switch (phba
->pci_dev_grp
) {
11531 case LPFC_PCI_DEV_LP
:
11532 rc
= lpfc_io_error_detected_s3(pdev
, state
);
11534 case LPFC_PCI_DEV_OC
:
11535 rc
= lpfc_io_error_detected_s4(pdev
, state
);
11538 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11539 "1427 Invalid PCI device group: 0x%x\n",
11540 phba
->pci_dev_grp
);
11547 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11548 * @pdev: pointer to PCI device.
11550 * This routine is registered to the PCI subsystem for error handling. This
11551 * function is called after PCI bus has been reset to restart the PCI card
11552 * from scratch, as if from a cold-boot. When this routine is invoked, it
11553 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11554 * routine, which will perform the proper device reset.
11557 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11558 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11560 static pci_ers_result_t
11561 lpfc_io_slot_reset(struct pci_dev
*pdev
)
11563 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11564 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11565 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
11567 switch (phba
->pci_dev_grp
) {
11568 case LPFC_PCI_DEV_LP
:
11569 rc
= lpfc_io_slot_reset_s3(pdev
);
11571 case LPFC_PCI_DEV_OC
:
11572 rc
= lpfc_io_slot_reset_s4(pdev
);
11575 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11576 "1428 Invalid PCI device group: 0x%x\n",
11577 phba
->pci_dev_grp
);
11584 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11585 * @pdev: pointer to PCI device
11587 * This routine is registered to the PCI subsystem for error handling. It
11588 * is called when kernel error recovery tells the lpfc driver that it is
11589 * OK to resume normal PCI operation after PCI bus error recovery. When
11590 * this routine is invoked, it dispatches the action to the proper SLI-3
11591 * or SLI-4 device io_resume routine, which will resume the device operation.
11594 lpfc_io_resume(struct pci_dev
*pdev
)
11596 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11597 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11599 switch (phba
->pci_dev_grp
) {
11600 case LPFC_PCI_DEV_LP
:
11601 lpfc_io_resume_s3(pdev
);
11603 case LPFC_PCI_DEV_OC
:
11604 lpfc_io_resume_s4(pdev
);
11607 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11608 "1429 Invalid PCI device group: 0x%x\n",
11609 phba
->pci_dev_grp
);
11616 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11617 * @phba: pointer to lpfc hba data structure.
11619 * This routine checks to see if OAS is supported for this adapter. If
11620 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11621 * the enable oas flag is cleared and the pool created for OAS device data
11626 lpfc_sli4_oas_verify(struct lpfc_hba
*phba
)
11629 if (!phba
->cfg_EnableXLane
)
11632 if (phba
->sli4_hba
.pc_sli4_params
.oas_supported
) {
11636 if (phba
->device_data_mem_pool
)
11637 mempool_destroy(phba
->device_data_mem_pool
);
11638 phba
->device_data_mem_pool
= NULL
;
11645 * lpfc_fof_queue_setup - Set up all the fof queues
11646 * @phba: pointer to lpfc hba data structure.
11648 * This routine is invoked to set up all the fof queues for the FC HBA
11653 * -ENOMEM - No available memory
11656 lpfc_fof_queue_setup(struct lpfc_hba
*phba
)
11658 struct lpfc_sli_ring
*pring
;
11661 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.fof_eq
, LPFC_MAX_IMAX
);
11665 if (phba
->cfg_fof
) {
11667 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.oas_cq
,
11668 phba
->sli4_hba
.fof_eq
, LPFC_WCQ
, LPFC_FCP
);
11672 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.oas_wq
,
11673 phba
->sli4_hba
.oas_cq
, LPFC_FCP
);
11677 /* Bind this CQ/WQ to the NVME ring */
11678 pring
= phba
->sli4_hba
.oas_wq
->pring
;
11679 pring
->sli
.sli4
.wqp
=
11680 (void *)phba
->sli4_hba
.oas_wq
;
11681 phba
->sli4_hba
.oas_cq
->pring
= pring
;
11687 lpfc_cq_destroy(phba
, phba
->sli4_hba
.oas_cq
);
11689 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fof_eq
);
11695 * lpfc_fof_queue_create - Create all the fof queues
11696 * @phba: pointer to lpfc hba data structure.
11698 * This routine is invoked to allocate all the fof queues for the FC HBA
11699 * operation. For each SLI4 queue type, the parameters such as queue entry
11700 * count (queue depth) shall be taken from the module parameter. For now,
11701 * we just use some constant number as place holder.
11705 * -ENOMEM - No availble memory
11706 * -EIO - The mailbox failed to complete successfully.
11709 lpfc_fof_queue_create(struct lpfc_hba
*phba
)
11711 struct lpfc_queue
*qdesc
;
11713 /* Create FOF EQ */
11714 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
11715 phba
->sli4_hba
.eq_ecount
);
11719 phba
->sli4_hba
.fof_eq
= qdesc
;
11721 if (phba
->cfg_fof
) {
11723 /* Create OAS CQ */
11724 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
11725 phba
->sli4_hba
.cq_ecount
);
11729 phba
->sli4_hba
.oas_cq
= qdesc
;
11731 /* Create OAS WQ */
11732 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
11733 phba
->sli4_hba
.wq_ecount
);
11737 phba
->sli4_hba
.oas_wq
= qdesc
;
11738 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
11744 lpfc_fof_queue_destroy(phba
);
11749 * lpfc_fof_queue_destroy - Destroy all the fof queues
11750 * @phba: pointer to lpfc hba data structure.
11752 * This routine is invoked to release all the SLI4 queues with the FC HBA
11759 lpfc_fof_queue_destroy(struct lpfc_hba
*phba
)
11761 /* Release FOF Event queue */
11762 if (phba
->sli4_hba
.fof_eq
!= NULL
) {
11763 lpfc_sli4_queue_free(phba
->sli4_hba
.fof_eq
);
11764 phba
->sli4_hba
.fof_eq
= NULL
;
11767 /* Release OAS Completion queue */
11768 if (phba
->sli4_hba
.oas_cq
!= NULL
) {
11769 lpfc_sli4_queue_free(phba
->sli4_hba
.oas_cq
);
11770 phba
->sli4_hba
.oas_cq
= NULL
;
11773 /* Release OAS Work queue */
11774 if (phba
->sli4_hba
.oas_wq
!= NULL
) {
11775 lpfc_sli4_queue_free(phba
->sli4_hba
.oas_wq
);
11776 phba
->sli4_hba
.oas_wq
= NULL
;
11781 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
11783 static const struct pci_error_handlers lpfc_err_handler
= {
11784 .error_detected
= lpfc_io_error_detected
,
11785 .slot_reset
= lpfc_io_slot_reset
,
11786 .resume
= lpfc_io_resume
,
11789 static struct pci_driver lpfc_driver
= {
11790 .name
= LPFC_DRIVER_NAME
,
11791 .id_table
= lpfc_id_table
,
11792 .probe
= lpfc_pci_probe_one
,
11793 .remove
= lpfc_pci_remove_one
,
11794 .suspend
= lpfc_pci_suspend_one
,
11795 .resume
= lpfc_pci_resume_one
,
11796 .err_handler
= &lpfc_err_handler
,
11799 static const struct file_operations lpfc_mgmt_fop
= {
11800 .owner
= THIS_MODULE
,
11803 static struct miscdevice lpfc_mgmt_dev
= {
11804 .minor
= MISC_DYNAMIC_MINOR
,
11805 .name
= "lpfcmgmt",
11806 .fops
= &lpfc_mgmt_fop
,
11810 * lpfc_init - lpfc module initialization routine
11812 * This routine is to be invoked when the lpfc module is loaded into the
11813 * kernel. The special kernel macro module_init() is used to indicate the
11814 * role of this routine to the kernel as lpfc module entry point.
11818 * -ENOMEM - FC attach transport failed
11819 * all others - failed
11826 printk(LPFC_MODULE_DESC
"\n");
11827 printk(LPFC_COPYRIGHT
"\n");
11829 error
= misc_register(&lpfc_mgmt_dev
);
11831 printk(KERN_ERR
"Could not register lpfcmgmt device, "
11832 "misc_register returned with status %d", error
);
11834 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
11835 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
11836 lpfc_transport_template
=
11837 fc_attach_transport(&lpfc_transport_functions
);
11838 if (lpfc_transport_template
== NULL
)
11840 lpfc_vport_transport_template
=
11841 fc_attach_transport(&lpfc_vport_transport_functions
);
11842 if (lpfc_vport_transport_template
== NULL
) {
11843 fc_release_transport(lpfc_transport_template
);
11847 /* Initialize in case vector mapping is needed */
11848 lpfc_used_cpu
= NULL
;
11849 lpfc_present_cpu
= num_present_cpus();
11851 error
= pci_register_driver(&lpfc_driver
);
11853 fc_release_transport(lpfc_transport_template
);
11854 fc_release_transport(lpfc_vport_transport_template
);
11861 * lpfc_exit - lpfc module removal routine
11863 * This routine is invoked when the lpfc module is removed from the kernel.
11864 * The special kernel macro module_exit() is used to indicate the role of
11865 * this routine to the kernel as lpfc module exit point.
11870 misc_deregister(&lpfc_mgmt_dev
);
11871 pci_unregister_driver(&lpfc_driver
);
11872 fc_release_transport(lpfc_transport_template
);
11873 fc_release_transport(lpfc_vport_transport_template
);
11874 if (_dump_buf_data
) {
11875 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
11876 "_dump_buf_data at 0x%p\n",
11877 (1L << _dump_buf_data_order
), _dump_buf_data
);
11878 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
11881 if (_dump_buf_dif
) {
11882 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
11883 "_dump_buf_dif at 0x%p\n",
11884 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
11885 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
11887 kfree(lpfc_used_cpu
);
11888 idr_destroy(&lpfc_hba_index
);
11891 module_init(lpfc_init
);
11892 module_exit(lpfc_exit
);
11893 MODULE_LICENSE("GPL");
11894 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
11895 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11896 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);