1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/idr.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/kthread.h>
31 #include <linux/pci.h>
32 #include <linux/spinlock.h>
33 #include <linux/ctype.h>
34 #include <linux/aer.h>
35 #include <linux/slab.h>
36 #include <linux/firmware.h>
37 #include <linux/miscdevice.h>
38 #include <linux/percpu.h>
39 #include <linux/msi.h>
41 #include <scsi/scsi.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
44 #include <scsi/scsi_transport_fc.h>
49 #include "lpfc_sli4.h"
51 #include "lpfc_disc.h"
53 #include "lpfc_scsi.h"
54 #include "lpfc_nvme.h"
55 #include "lpfc_logmsg.h"
56 #include "lpfc_crtn.h"
57 #include "lpfc_vport.h"
58 #include "lpfc_version.h"
62 unsigned long _dump_buf_data_order
;
64 unsigned long _dump_buf_dif_order
;
65 spinlock_t _dump_buf_lock
;
67 /* Used when mapping IRQ vectors in a driver centric manner */
68 uint16_t *lpfc_used_cpu
;
69 uint32_t lpfc_present_cpu
;
71 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
72 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
73 static int lpfc_sli4_queue_verify(struct lpfc_hba
*);
74 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
75 static int lpfc_setup_endian_order(struct lpfc_hba
*);
76 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
77 static void lpfc_free_els_sgl_list(struct lpfc_hba
*);
78 static void lpfc_free_nvmet_sgl_list(struct lpfc_hba
*);
79 static void lpfc_init_sgl_list(struct lpfc_hba
*);
80 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
81 static void lpfc_free_active_sgl(struct lpfc_hba
*);
82 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
83 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
84 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
85 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
86 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
87 static void lpfc_sli4_disable_intr(struct lpfc_hba
*);
88 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba
*, uint32_t);
89 static void lpfc_sli4_oas_verify(struct lpfc_hba
*phba
);
91 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
92 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
93 static DEFINE_IDR(lpfc_hba_index
);
94 #define LPFC_NVMET_BUF_POST 254
97 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
98 * @phba: pointer to lpfc hba data structure.
100 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
101 * mailbox command. It retrieves the revision information from the HBA and
102 * collects the Vital Product Data (VPD) about the HBA for preparing the
103 * configuration of the HBA.
107 * -ERESTART - requests the SLI layer to reset the HBA and try again.
108 * Any other value - indicates an error.
111 lpfc_config_port_prep(struct lpfc_hba
*phba
)
113 lpfc_vpd_t
*vp
= &phba
->vpd
;
117 char *lpfc_vpd_data
= NULL
;
119 static char licensed
[56] =
120 "key unlock for use with gnu public licensed code only\0";
121 static int init_key
= 1;
123 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
125 phba
->link_state
= LPFC_HBA_ERROR
;
130 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
132 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
134 uint32_t *ptext
= (uint32_t *) licensed
;
136 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
137 *ptext
= cpu_to_be32(*ptext
);
141 lpfc_read_nv(phba
, pmb
);
142 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
143 sizeof (mb
->un
.varRDnvp
.rsvd3
));
144 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
147 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
149 if (rc
!= MBX_SUCCESS
) {
150 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
151 "0324 Config Port initialization "
152 "error, mbxCmd x%x READ_NVPARM, "
154 mb
->mbxCommand
, mb
->mbxStatus
);
155 mempool_free(pmb
, phba
->mbox_mem_pool
);
158 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
160 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
164 phba
->sli3_options
= 0x0;
166 /* Setup and issue mailbox READ REV command */
167 lpfc_read_rev(phba
, pmb
);
168 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
169 if (rc
!= MBX_SUCCESS
) {
170 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
171 "0439 Adapter failed to init, mbxCmd x%x "
172 "READ_REV, mbxStatus x%x\n",
173 mb
->mbxCommand
, mb
->mbxStatus
);
174 mempool_free( pmb
, phba
->mbox_mem_pool
);
180 * The value of rr must be 1 since the driver set the cv field to 1.
181 * This setting requires the FW to set all revision fields.
183 if (mb
->un
.varRdRev
.rr
== 0) {
185 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
186 "0440 Adapter failed to init, READ_REV has "
187 "missing revision information.\n");
188 mempool_free(pmb
, phba
->mbox_mem_pool
);
192 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
193 mempool_free(pmb
, phba
->mbox_mem_pool
);
197 /* Save information as VPD data */
199 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
200 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
201 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
202 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
203 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
204 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
205 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
206 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
207 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
208 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
209 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
210 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
211 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
212 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
213 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
215 /* If the sli feature level is less then 9, we must
216 * tear down all RPIs and VPIs on link down if NPIV
219 if (vp
->rev
.feaLevelHigh
< 9)
220 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
222 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
223 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
224 sizeof (phba
->RandomData
));
226 /* Get adapter VPD information */
227 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
231 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
232 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
234 if (rc
!= MBX_SUCCESS
) {
235 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
236 "0441 VPD not present on adapter, "
237 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
238 mb
->mbxCommand
, mb
->mbxStatus
);
239 mb
->un
.varDmp
.word_cnt
= 0;
241 /* dump mem may return a zero when finished or we got a
242 * mailbox error, either way we are done.
244 if (mb
->un
.varDmp
.word_cnt
== 0)
246 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
247 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
248 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
249 lpfc_vpd_data
+ offset
,
250 mb
->un
.varDmp
.word_cnt
);
251 offset
+= mb
->un
.varDmp
.word_cnt
;
252 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
253 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
255 kfree(lpfc_vpd_data
);
257 mempool_free(pmb
, phba
->mbox_mem_pool
);
262 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
263 * @phba: pointer to lpfc hba data structure.
264 * @pmboxq: pointer to the driver internal queue element for mailbox command.
266 * This is the completion handler for driver's configuring asynchronous event
267 * mailbox command to the device. If the mailbox command returns successfully,
268 * it will set internal async event support flag to 1; otherwise, it will
269 * set internal async event support flag to 0.
272 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
274 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
275 phba
->temp_sensor_support
= 1;
277 phba
->temp_sensor_support
= 0;
278 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
283 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
284 * @phba: pointer to lpfc hba data structure.
285 * @pmboxq: pointer to the driver internal queue element for mailbox command.
287 * This is the completion handler for dump mailbox command for getting
288 * wake up parameters. When this command complete, the response contain
289 * Option rom version of the HBA. This function translate the version number
290 * into a human readable string and store it in OptionROMVersion.
293 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
296 uint32_t prog_id_word
;
298 /* character array used for decoding dist type. */
299 char dist_char
[] = "nabx";
301 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
302 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
306 prg
= (struct prog_id
*) &prog_id_word
;
308 /* word 7 contain option rom version */
309 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
311 /* Decode the Option rom version word to a readable string */
313 dist
= dist_char
[prg
->dist
];
315 if ((prg
->dist
== 3) && (prg
->num
== 0))
316 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d",
317 prg
->ver
, prg
->rev
, prg
->lev
);
319 snprintf(phba
->OptionROMVersion
, 32, "%d.%d%d%c%d",
320 prg
->ver
, prg
->rev
, prg
->lev
,
322 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
327 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
328 * cfg_soft_wwnn, cfg_soft_wwpn
329 * @vport: pointer to lpfc vport data structure.
336 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
338 /* If the soft name exists then update it using the service params */
339 if (vport
->phba
->cfg_soft_wwnn
)
340 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
341 vport
->fc_sparam
.nodeName
.u
.wwn
);
342 if (vport
->phba
->cfg_soft_wwpn
)
343 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
344 vport
->fc_sparam
.portName
.u
.wwn
);
347 * If the name is empty or there exists a soft name
348 * then copy the service params name, otherwise use the fc name
350 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
351 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
352 sizeof(struct lpfc_name
));
354 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
355 sizeof(struct lpfc_name
));
357 if (vport
->fc_portname
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwpn
)
358 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
359 sizeof(struct lpfc_name
));
361 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
362 sizeof(struct lpfc_name
));
366 * lpfc_config_port_post - Perform lpfc initialization after config port
367 * @phba: pointer to lpfc hba data structure.
369 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
370 * command call. It performs all internal resource and state setups on the
371 * port: post IOCB buffers, enable appropriate host interrupt attentions,
372 * ELS ring timers, etc.
376 * Any other value - error.
379 lpfc_config_port_post(struct lpfc_hba
*phba
)
381 struct lpfc_vport
*vport
= phba
->pport
;
382 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
385 struct lpfc_dmabuf
*mp
;
386 struct lpfc_sli
*psli
= &phba
->sli
;
387 uint32_t status
, timeout
;
391 spin_lock_irq(&phba
->hbalock
);
393 * If the Config port completed correctly the HBA is not
394 * over heated any more.
396 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
397 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
398 spin_unlock_irq(&phba
->hbalock
);
400 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
402 phba
->link_state
= LPFC_HBA_ERROR
;
407 /* Get login parameters for NID. */
408 rc
= lpfc_read_sparam(phba
, pmb
, 0);
410 mempool_free(pmb
, phba
->mbox_mem_pool
);
415 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
416 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
417 "0448 Adapter failed init, mbxCmd x%x "
418 "READ_SPARM mbxStatus x%x\n",
419 mb
->mbxCommand
, mb
->mbxStatus
);
420 phba
->link_state
= LPFC_HBA_ERROR
;
421 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
422 mempool_free(pmb
, phba
->mbox_mem_pool
);
423 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
428 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
430 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
431 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
433 pmb
->context1
= NULL
;
434 lpfc_update_vport_wwn(vport
);
436 /* Update the fc_host data structures with new wwn. */
437 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
438 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
439 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
441 /* If no serial number in VPD data, use low 6 bytes of WWNN */
442 /* This should be consolidated into parse_vpd ? - mr */
443 if (phba
->SerialNumber
[0] == 0) {
446 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
447 for (i
= 0; i
< 12; i
++) {
449 j
= ((status
& 0xf0) >> 4);
451 phba
->SerialNumber
[i
] =
452 (char)((uint8_t) 0x30 + (uint8_t) j
);
454 phba
->SerialNumber
[i
] =
455 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
459 phba
->SerialNumber
[i
] =
460 (char)((uint8_t) 0x30 + (uint8_t) j
);
462 phba
->SerialNumber
[i
] =
463 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
467 lpfc_read_config(phba
, pmb
);
469 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
470 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
471 "0453 Adapter failed to init, mbxCmd x%x "
472 "READ_CONFIG, mbxStatus x%x\n",
473 mb
->mbxCommand
, mb
->mbxStatus
);
474 phba
->link_state
= LPFC_HBA_ERROR
;
475 mempool_free( pmb
, phba
->mbox_mem_pool
);
479 /* Check if the port is disabled */
480 lpfc_sli_read_link_ste(phba
);
482 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
483 i
= (mb
->un
.varRdConfig
.max_xri
+ 1);
484 if (phba
->cfg_hba_queue_depth
> i
) {
485 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
486 "3359 HBA queue depth changed from %d to %d\n",
487 phba
->cfg_hba_queue_depth
, i
);
488 phba
->cfg_hba_queue_depth
= i
;
491 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
492 i
= (mb
->un
.varRdConfig
.max_xri
>> 3);
493 if (phba
->pport
->cfg_lun_queue_depth
> i
) {
494 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
495 "3360 LUN queue depth changed from %d to %d\n",
496 phba
->pport
->cfg_lun_queue_depth
, i
);
497 phba
->pport
->cfg_lun_queue_depth
= i
;
500 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
502 /* Get the default values for Model Name and Description */
503 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
505 phba
->link_state
= LPFC_LINK_DOWN
;
507 /* Only process IOCBs on ELS ring till hba_state is READY */
508 if (psli
->sli3_ring
[LPFC_EXTRA_RING
].sli
.sli3
.cmdringaddr
)
509 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
510 if (psli
->sli3_ring
[LPFC_FCP_RING
].sli
.sli3
.cmdringaddr
)
511 psli
->sli3_ring
[LPFC_FCP_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
513 /* Post receive buffers for desired rings */
514 if (phba
->sli_rev
!= 3)
515 lpfc_post_rcv_buf(phba
);
518 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
520 if (phba
->intr_type
== MSIX
) {
521 rc
= lpfc_config_msi(phba
, pmb
);
523 mempool_free(pmb
, phba
->mbox_mem_pool
);
526 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
527 if (rc
!= MBX_SUCCESS
) {
528 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
529 "0352 Config MSI mailbox command "
530 "failed, mbxCmd x%x, mbxStatus x%x\n",
531 pmb
->u
.mb
.mbxCommand
,
532 pmb
->u
.mb
.mbxStatus
);
533 mempool_free(pmb
, phba
->mbox_mem_pool
);
538 spin_lock_irq(&phba
->hbalock
);
539 /* Initialize ERATT handling flag */
540 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
542 /* Enable appropriate host interrupts */
543 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
544 spin_unlock_irq(&phba
->hbalock
);
547 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
548 if (psli
->num_rings
> 0)
549 status
|= HC_R0INT_ENA
;
550 if (psli
->num_rings
> 1)
551 status
|= HC_R1INT_ENA
;
552 if (psli
->num_rings
> 2)
553 status
|= HC_R2INT_ENA
;
554 if (psli
->num_rings
> 3)
555 status
|= HC_R3INT_ENA
;
557 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
558 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
559 status
&= ~(HC_R0INT_ENA
);
561 writel(status
, phba
->HCregaddr
);
562 readl(phba
->HCregaddr
); /* flush */
563 spin_unlock_irq(&phba
->hbalock
);
565 /* Set up ring-0 (ELS) timer */
566 timeout
= phba
->fc_ratov
* 2;
567 mod_timer(&vport
->els_tmofunc
,
568 jiffies
+ msecs_to_jiffies(1000 * timeout
));
569 /* Set up heart beat (HB) timer */
570 mod_timer(&phba
->hb_tmofunc
,
571 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
572 phba
->hb_outstanding
= 0;
573 phba
->last_completion_time
= jiffies
;
574 /* Set up error attention (ERATT) polling timer */
575 mod_timer(&phba
->eratt_poll
,
576 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
578 if (phba
->hba_flag
& LINK_DISABLED
) {
579 lpfc_printf_log(phba
,
581 "2598 Adapter Link is disabled.\n");
582 lpfc_down_link(phba
, pmb
);
583 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
584 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
585 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
586 lpfc_printf_log(phba
,
588 "2599 Adapter failed to issue DOWN_LINK"
589 " mbox command rc 0x%x\n", rc
);
591 mempool_free(pmb
, phba
->mbox_mem_pool
);
594 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
595 mempool_free(pmb
, phba
->mbox_mem_pool
);
596 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
600 /* MBOX buffer will be freed in mbox compl */
601 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
603 phba
->link_state
= LPFC_HBA_ERROR
;
607 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
608 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
609 pmb
->vport
= phba
->pport
;
610 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
612 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
613 lpfc_printf_log(phba
,
616 "0456 Adapter failed to issue "
617 "ASYNCEVT_ENABLE mbox status x%x\n",
619 mempool_free(pmb
, phba
->mbox_mem_pool
);
622 /* Get Option rom version */
623 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
625 phba
->link_state
= LPFC_HBA_ERROR
;
629 lpfc_dump_wakeup_param(phba
, pmb
);
630 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
631 pmb
->vport
= phba
->pport
;
632 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
634 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
635 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
636 "to get Option ROM version status x%x\n", rc
);
637 mempool_free(pmb
, phba
->mbox_mem_pool
);
644 * lpfc_hba_init_link - Initialize the FC link
645 * @phba: pointer to lpfc hba data structure.
646 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
648 * This routine will issue the INIT_LINK mailbox command call.
649 * It is available to other drivers through the lpfc_hba data
650 * structure for use as a delayed link up mechanism with the
651 * module parameter lpfc_suppress_link_up.
655 * Any other value - error
658 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
660 return lpfc_hba_init_link_fc_topology(phba
, phba
->cfg_topology
, flag
);
664 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
665 * @phba: pointer to lpfc hba data structure.
666 * @fc_topology: desired fc topology.
667 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
669 * This routine will issue the INIT_LINK mailbox command call.
670 * It is available to other drivers through the lpfc_hba data
671 * structure for use as a delayed link up mechanism with the
672 * module parameter lpfc_suppress_link_up.
676 * Any other value - error
679 lpfc_hba_init_link_fc_topology(struct lpfc_hba
*phba
, uint32_t fc_topology
,
682 struct lpfc_vport
*vport
= phba
->pport
;
687 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
689 phba
->link_state
= LPFC_HBA_ERROR
;
695 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_MAX
) ||
696 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
) &&
697 !(phba
->lmt
& LMT_1Gb
)) ||
698 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
) &&
699 !(phba
->lmt
& LMT_2Gb
)) ||
700 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
) &&
701 !(phba
->lmt
& LMT_4Gb
)) ||
702 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
) &&
703 !(phba
->lmt
& LMT_8Gb
)) ||
704 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
) &&
705 !(phba
->lmt
& LMT_10Gb
)) ||
706 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
) &&
707 !(phba
->lmt
& LMT_16Gb
)) ||
708 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_32G
) &&
709 !(phba
->lmt
& LMT_32Gb
))) {
710 /* Reset link speed to auto */
711 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
712 "1302 Invalid speed for this board:%d "
713 "Reset link speed to auto.\n",
714 phba
->cfg_link_speed
);
715 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
717 lpfc_init_link(phba
, pmb
, fc_topology
, phba
->cfg_link_speed
);
718 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
719 if (phba
->sli_rev
< LPFC_SLI_REV4
)
720 lpfc_set_loopback_flag(phba
);
721 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
722 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
723 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
724 "0498 Adapter failed to init, mbxCmd x%x "
725 "INIT_LINK, mbxStatus x%x\n",
726 mb
->mbxCommand
, mb
->mbxStatus
);
727 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
728 /* Clear all interrupt enable conditions */
729 writel(0, phba
->HCregaddr
);
730 readl(phba
->HCregaddr
); /* flush */
731 /* Clear all pending interrupts */
732 writel(0xffffffff, phba
->HAregaddr
);
733 readl(phba
->HAregaddr
); /* flush */
735 phba
->link_state
= LPFC_HBA_ERROR
;
736 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
737 mempool_free(pmb
, phba
->mbox_mem_pool
);
740 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
741 if (flag
== MBX_POLL
)
742 mempool_free(pmb
, phba
->mbox_mem_pool
);
748 * lpfc_hba_down_link - this routine downs the FC link
749 * @phba: pointer to lpfc hba data structure.
750 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
752 * This routine will issue the DOWN_LINK mailbox command call.
753 * It is available to other drivers through the lpfc_hba data
754 * structure for use to stop the link.
758 * Any other value - error
761 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
766 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
768 phba
->link_state
= LPFC_HBA_ERROR
;
772 lpfc_printf_log(phba
,
774 "0491 Adapter Link is disabled.\n");
775 lpfc_down_link(phba
, pmb
);
776 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
777 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
778 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
779 lpfc_printf_log(phba
,
781 "2522 Adapter failed to issue DOWN_LINK"
782 " mbox command rc 0x%x\n", rc
);
784 mempool_free(pmb
, phba
->mbox_mem_pool
);
787 if (flag
== MBX_POLL
)
788 mempool_free(pmb
, phba
->mbox_mem_pool
);
794 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
795 * @phba: pointer to lpfc HBA data structure.
797 * This routine will do LPFC uninitialization before the HBA is reset when
798 * bringing down the SLI Layer.
802 * Any other value - error.
805 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
807 struct lpfc_vport
**vports
;
810 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
811 /* Disable interrupts */
812 writel(0, phba
->HCregaddr
);
813 readl(phba
->HCregaddr
); /* flush */
816 if (phba
->pport
->load_flag
& FC_UNLOADING
)
817 lpfc_cleanup_discovery_resources(phba
->pport
);
819 vports
= lpfc_create_vport_work_array(phba
);
821 for (i
= 0; i
<= phba
->max_vports
&&
822 vports
[i
] != NULL
; i
++)
823 lpfc_cleanup_discovery_resources(vports
[i
]);
824 lpfc_destroy_vport_work_array(phba
, vports
);
830 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
831 * rspiocb which got deferred
833 * @phba: pointer to lpfc HBA data structure.
835 * This routine will cleanup completed slow path events after HBA is reset
836 * when bringing down the SLI Layer.
843 lpfc_sli4_free_sp_events(struct lpfc_hba
*phba
)
845 struct lpfc_iocbq
*rspiocbq
;
846 struct hbq_dmabuf
*dmabuf
;
847 struct lpfc_cq_event
*cq_event
;
849 spin_lock_irq(&phba
->hbalock
);
850 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
851 spin_unlock_irq(&phba
->hbalock
);
853 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
854 /* Get the response iocb from the head of work queue */
855 spin_lock_irq(&phba
->hbalock
);
856 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
857 cq_event
, struct lpfc_cq_event
, list
);
858 spin_unlock_irq(&phba
->hbalock
);
860 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
861 case CQE_CODE_COMPL_WQE
:
862 rspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
864 lpfc_sli_release_iocbq(phba
, rspiocbq
);
866 case CQE_CODE_RECEIVE
:
867 case CQE_CODE_RECEIVE_V1
:
868 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
870 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
876 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
877 * @phba: pointer to lpfc HBA data structure.
879 * This routine will cleanup posted ELS buffers after the HBA is reset
880 * when bringing down the SLI Layer.
887 lpfc_hba_free_post_buf(struct lpfc_hba
*phba
)
889 struct lpfc_sli
*psli
= &phba
->sli
;
890 struct lpfc_sli_ring
*pring
;
891 struct lpfc_dmabuf
*mp
, *next_mp
;
895 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
896 lpfc_sli_hbqbuf_free_all(phba
);
898 /* Cleanup preposted buffers on the ELS ring */
899 pring
= &psli
->sli3_ring
[LPFC_ELS_RING
];
900 spin_lock_irq(&phba
->hbalock
);
901 list_splice_init(&pring
->postbufq
, &buflist
);
902 spin_unlock_irq(&phba
->hbalock
);
905 list_for_each_entry_safe(mp
, next_mp
, &buflist
, list
) {
908 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
912 spin_lock_irq(&phba
->hbalock
);
913 pring
->postbufq_cnt
-= count
;
914 spin_unlock_irq(&phba
->hbalock
);
919 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
920 * @phba: pointer to lpfc HBA data structure.
922 * This routine will cleanup the txcmplq after the HBA is reset when bringing
923 * down the SLI Layer.
929 lpfc_hba_clean_txcmplq(struct lpfc_hba
*phba
)
931 struct lpfc_sli
*psli
= &phba
->sli
;
932 struct lpfc_queue
*qp
= NULL
;
933 struct lpfc_sli_ring
*pring
;
934 LIST_HEAD(completions
);
937 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
938 for (i
= 0; i
< psli
->num_rings
; i
++) {
939 pring
= &psli
->sli3_ring
[i
];
940 spin_lock_irq(&phba
->hbalock
);
941 /* At this point in time the HBA is either reset or DOA
942 * Nothing should be on txcmplq as it will
945 list_splice_init(&pring
->txcmplq
, &completions
);
946 pring
->txcmplq_cnt
= 0;
947 spin_unlock_irq(&phba
->hbalock
);
949 lpfc_sli_abort_iocb_ring(phba
, pring
);
951 /* Cancel all the IOCBs from the completions list */
952 lpfc_sli_cancel_iocbs(phba
, &completions
,
953 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
956 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
960 spin_lock_irq(&pring
->ring_lock
);
961 list_splice_init(&pring
->txcmplq
, &completions
);
962 pring
->txcmplq_cnt
= 0;
963 spin_unlock_irq(&pring
->ring_lock
);
964 lpfc_sli_abort_iocb_ring(phba
, pring
);
966 /* Cancel all the IOCBs from the completions list */
967 lpfc_sli_cancel_iocbs(phba
, &completions
,
968 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
972 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
974 * @phba: pointer to lpfc HBA data structure.
976 * This routine will do uninitialization after the HBA is reset when bring
977 * down the SLI Layer.
981 * Any other value - error.
984 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
986 lpfc_hba_free_post_buf(phba
);
987 lpfc_hba_clean_txcmplq(phba
);
992 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
993 * @phba: pointer to lpfc HBA data structure.
995 * This routine will do uninitialization after the HBA is reset when bring
996 * down the SLI Layer.
1000 * Any other value - error.
1003 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
1005 struct lpfc_scsi_buf
*psb
, *psb_next
;
1007 LIST_HEAD(nvme_aborts
);
1008 unsigned long iflag
= 0;
1009 struct lpfc_sglq
*sglq_entry
= NULL
;
1012 lpfc_sli_hbqbuf_free_all(phba
);
1013 lpfc_hba_clean_txcmplq(phba
);
1015 /* At this point in time the HBA is either reset or DOA. Either
1016 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1017 * on the lpfc_els_sgl_list so that it can either be freed if the
1018 * driver is unloading or reposted if the driver is restarting
1021 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_els_sgl_list and */
1023 /* sgl_list_lock required because worker thread uses this
1026 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
1027 list_for_each_entry(sglq_entry
,
1028 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
1029 sglq_entry
->state
= SGL_FREED
;
1030 list_for_each_entry(sglq_entry
,
1031 &phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
, list
)
1032 sglq_entry
->state
= SGL_FREED
;
1034 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
1035 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1037 if (phba
->sli4_hba
.nvme_wq
)
1038 list_splice_init(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
,
1039 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
1041 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
1042 /* abts_scsi_buf_list_lock required because worker thread uses this
1045 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
1046 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
1047 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
1049 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
1052 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
1053 spin_lock(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
1054 list_splice_init(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
,
1056 spin_unlock(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
1059 spin_unlock_irq(&phba
->hbalock
);
1061 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
1063 psb
->status
= IOSTAT_SUCCESS
;
1065 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
1066 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list_put
);
1067 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
1069 list_for_each_entry_safe(psb
, psb_next
, &nvme_aborts
, list
) {
1071 psb
->status
= IOSTAT_SUCCESS
;
1073 spin_lock_irqsave(&phba
->nvme_buf_list_put_lock
, iflag
);
1074 list_splice(&nvme_aborts
, &phba
->lpfc_nvme_buf_list_put
);
1075 spin_unlock_irqrestore(&phba
->nvme_buf_list_put_lock
, iflag
);
1077 lpfc_sli4_free_sp_events(phba
);
1082 * lpfc_hba_down_post - Wrapper func for hba down post routine
1083 * @phba: pointer to lpfc HBA data structure.
1085 * This routine wraps the actual SLI3 or SLI4 routine for performing
1086 * uninitialization after the HBA is reset when bring down the SLI Layer.
1090 * Any other value - error.
1093 lpfc_hba_down_post(struct lpfc_hba
*phba
)
1095 return (*phba
->lpfc_hba_down_post
)(phba
);
1099 * lpfc_hb_timeout - The HBA-timer timeout handler
1100 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1102 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1103 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1104 * work-port-events bitmap and the worker thread is notified. This timeout
1105 * event will be used by the worker thread to invoke the actual timeout
1106 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1107 * be performed in the timeout handler and the HBA timeout event bit shall
1108 * be cleared by the worker thread after it has taken the event bitmap out.
1111 lpfc_hb_timeout(unsigned long ptr
)
1113 struct lpfc_hba
*phba
;
1114 uint32_t tmo_posted
;
1115 unsigned long iflag
;
1117 phba
= (struct lpfc_hba
*)ptr
;
1119 /* Check for heart beat timeout conditions */
1120 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1121 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
1123 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
1124 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1126 /* Tell the worker thread there is work to do */
1128 lpfc_worker_wake_up(phba
);
1133 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1134 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1136 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1137 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1138 * work-port-events bitmap and the worker thread is notified. This timeout
1139 * event will be used by the worker thread to invoke the actual timeout
1140 * handler routine, lpfc_rrq_handler. Any periodical operations will
1141 * be performed in the timeout handler and the RRQ timeout event bit shall
1142 * be cleared by the worker thread after it has taken the event bitmap out.
1145 lpfc_rrq_timeout(unsigned long ptr
)
1147 struct lpfc_hba
*phba
;
1148 unsigned long iflag
;
1150 phba
= (struct lpfc_hba
*)ptr
;
1151 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
1152 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1153 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
1155 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
1156 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
1158 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
1159 lpfc_worker_wake_up(phba
);
1163 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1164 * @phba: pointer to lpfc hba data structure.
1165 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1167 * This is the callback function to the lpfc heart-beat mailbox command.
1168 * If configured, the lpfc driver issues the heart-beat mailbox command to
1169 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1170 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1171 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1172 * heart-beat outstanding state. Once the mailbox command comes back and
1173 * no error conditions detected, the heart-beat mailbox command timer is
1174 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1175 * state is cleared for the next heart-beat. If the timer expired with the
1176 * heart-beat outstanding state set, the driver will put the HBA offline.
1179 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1181 unsigned long drvr_flag
;
1183 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1184 phba
->hb_outstanding
= 0;
1185 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1187 /* Check and reset heart-beat timer is necessary */
1188 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1189 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1190 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1191 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1192 mod_timer(&phba
->hb_tmofunc
,
1194 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1199 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1200 * @phba: pointer to lpfc hba data structure.
1202 * This is the actual HBA-timer timeout handler to be invoked by the worker
1203 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1204 * handler performs any periodic operations needed for the device. If such
1205 * periodic event has already been attended to either in the interrupt handler
1206 * or by processing slow-ring or fast-ring events within the HBA-timer
1207 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1208 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1209 * is configured and there is no heart-beat mailbox command outstanding, a
1210 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1211 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1215 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1217 struct lpfc_vport
**vports
;
1218 LPFC_MBOXQ_t
*pmboxq
;
1219 struct lpfc_dmabuf
*buf_ptr
;
1221 struct lpfc_sli
*psli
= &phba
->sli
;
1222 LIST_HEAD(completions
);
1224 vports
= lpfc_create_vport_work_array(phba
);
1226 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
1227 lpfc_rcv_seq_check_edtov(vports
[i
]);
1228 lpfc_fdmi_num_disc_check(vports
[i
]);
1230 lpfc_destroy_vport_work_array(phba
, vports
);
1232 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1233 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1234 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1237 spin_lock_irq(&phba
->pport
->work_port_lock
);
1239 if (time_after(phba
->last_completion_time
+
1240 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
),
1242 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1243 if (!phba
->hb_outstanding
)
1244 mod_timer(&phba
->hb_tmofunc
,
1246 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1248 mod_timer(&phba
->hb_tmofunc
,
1250 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1253 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1255 if (phba
->elsbuf_cnt
&&
1256 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1257 spin_lock_irq(&phba
->hbalock
);
1258 list_splice_init(&phba
->elsbuf
, &completions
);
1259 phba
->elsbuf_cnt
= 0;
1260 phba
->elsbuf_prev_cnt
= 0;
1261 spin_unlock_irq(&phba
->hbalock
);
1263 while (!list_empty(&completions
)) {
1264 list_remove_head(&completions
, buf_ptr
,
1265 struct lpfc_dmabuf
, list
);
1266 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1270 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1272 /* If there is no heart beat outstanding, issue a heartbeat command */
1273 if (phba
->cfg_enable_hba_heartbeat
) {
1274 if (!phba
->hb_outstanding
) {
1275 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1276 (list_empty(&psli
->mboxq
))) {
1277 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1280 mod_timer(&phba
->hb_tmofunc
,
1282 msecs_to_jiffies(1000 *
1283 LPFC_HB_MBOX_INTERVAL
));
1287 lpfc_heart_beat(phba
, pmboxq
);
1288 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1289 pmboxq
->vport
= phba
->pport
;
1290 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1293 if (retval
!= MBX_BUSY
&&
1294 retval
!= MBX_SUCCESS
) {
1295 mempool_free(pmboxq
,
1296 phba
->mbox_mem_pool
);
1297 mod_timer(&phba
->hb_tmofunc
,
1299 msecs_to_jiffies(1000 *
1300 LPFC_HB_MBOX_INTERVAL
));
1303 phba
->skipped_hb
= 0;
1304 phba
->hb_outstanding
= 1;
1305 } else if (time_before_eq(phba
->last_completion_time
,
1306 phba
->skipped_hb
)) {
1307 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1308 "2857 Last completion time not "
1309 " updated in %d ms\n",
1310 jiffies_to_msecs(jiffies
1311 - phba
->last_completion_time
));
1313 phba
->skipped_hb
= jiffies
;
1315 mod_timer(&phba
->hb_tmofunc
,
1317 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1321 * If heart beat timeout called with hb_outstanding set
1322 * we need to give the hb mailbox cmd a chance to
1325 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1326 "0459 Adapter heartbeat still out"
1327 "standing:last compl time was %d ms.\n",
1328 jiffies_to_msecs(jiffies
1329 - phba
->last_completion_time
));
1330 mod_timer(&phba
->hb_tmofunc
,
1332 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1335 mod_timer(&phba
->hb_tmofunc
,
1337 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1342 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1343 * @phba: pointer to lpfc hba data structure.
1345 * This routine is called to bring the HBA offline when HBA hardware error
1346 * other than Port Error 6 has been detected.
1349 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1351 struct lpfc_sli
*psli
= &phba
->sli
;
1353 spin_lock_irq(&phba
->hbalock
);
1354 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1355 spin_unlock_irq(&phba
->hbalock
);
1356 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1359 lpfc_reset_barrier(phba
);
1360 spin_lock_irq(&phba
->hbalock
);
1361 lpfc_sli_brdreset(phba
);
1362 spin_unlock_irq(&phba
->hbalock
);
1363 lpfc_hba_down_post(phba
);
1364 lpfc_sli_brdready(phba
, HS_MBRDY
);
1365 lpfc_unblock_mgmt_io(phba
);
1366 phba
->link_state
= LPFC_HBA_ERROR
;
1371 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1372 * @phba: pointer to lpfc hba data structure.
1374 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1375 * other than Port Error 6 has been detected.
1378 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1380 spin_lock_irq(&phba
->hbalock
);
1381 phba
->link_state
= LPFC_HBA_ERROR
;
1382 spin_unlock_irq(&phba
->hbalock
);
1384 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1386 lpfc_hba_down_post(phba
);
1387 lpfc_unblock_mgmt_io(phba
);
1391 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1392 * @phba: pointer to lpfc hba data structure.
1394 * This routine is invoked to handle the deferred HBA hardware error
1395 * conditions. This type of error is indicated by HBA by setting ER1
1396 * and another ER bit in the host status register. The driver will
1397 * wait until the ER1 bit clears before handling the error condition.
1400 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1402 uint32_t old_host_status
= phba
->work_hs
;
1403 struct lpfc_sli
*psli
= &phba
->sli
;
1405 /* If the pci channel is offline, ignore possible errors,
1406 * since we cannot communicate with the pci card anyway.
1408 if (pci_channel_offline(phba
->pcidev
)) {
1409 spin_lock_irq(&phba
->hbalock
);
1410 phba
->hba_flag
&= ~DEFER_ERATT
;
1411 spin_unlock_irq(&phba
->hbalock
);
1415 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1416 "0479 Deferred Adapter Hardware Error "
1417 "Data: x%x x%x x%x\n",
1419 phba
->work_status
[0], phba
->work_status
[1]);
1421 spin_lock_irq(&phba
->hbalock
);
1422 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1423 spin_unlock_irq(&phba
->hbalock
);
1427 * Firmware stops when it triggred erratt. That could cause the I/Os
1428 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1429 * SCSI layer retry it after re-establishing link.
1431 lpfc_sli_abort_fcp_rings(phba
);
1434 * There was a firmware error. Take the hba offline and then
1435 * attempt to restart it.
1437 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
1440 /* Wait for the ER1 bit to clear.*/
1441 while (phba
->work_hs
& HS_FFER1
) {
1443 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1444 phba
->work_hs
= UNPLUG_ERR
;
1447 /* If driver is unloading let the worker thread continue */
1448 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1455 * This is to ptrotect against a race condition in which
1456 * first write to the host attention register clear the
1457 * host status register.
1459 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1460 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1462 spin_lock_irq(&phba
->hbalock
);
1463 phba
->hba_flag
&= ~DEFER_ERATT
;
1464 spin_unlock_irq(&phba
->hbalock
);
1465 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1466 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1470 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1472 struct lpfc_board_event_header board_event
;
1473 struct Scsi_Host
*shost
;
1475 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1476 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1477 shost
= lpfc_shost_from_vport(phba
->pport
);
1478 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1479 sizeof(board_event
),
1480 (char *) &board_event
,
1485 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1486 * @phba: pointer to lpfc hba data structure.
1488 * This routine is invoked to handle the following HBA hardware error
1490 * 1 - HBA error attention interrupt
1491 * 2 - DMA ring index out of range
1492 * 3 - Mailbox command came back as unknown
1495 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1497 struct lpfc_vport
*vport
= phba
->pport
;
1498 struct lpfc_sli
*psli
= &phba
->sli
;
1499 uint32_t event_data
;
1500 unsigned long temperature
;
1501 struct temp_event temp_event_data
;
1502 struct Scsi_Host
*shost
;
1504 /* If the pci channel is offline, ignore possible errors,
1505 * since we cannot communicate with the pci card anyway.
1507 if (pci_channel_offline(phba
->pcidev
)) {
1508 spin_lock_irq(&phba
->hbalock
);
1509 phba
->hba_flag
&= ~DEFER_ERATT
;
1510 spin_unlock_irq(&phba
->hbalock
);
1514 /* If resets are disabled then leave the HBA alone and return */
1515 if (!phba
->cfg_enable_hba_reset
)
1518 /* Send an internal error event to mgmt application */
1519 lpfc_board_errevt_to_mgmt(phba
);
1521 if (phba
->hba_flag
& DEFER_ERATT
)
1522 lpfc_handle_deferred_eratt(phba
);
1524 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1525 if (phba
->work_hs
& HS_FFER6
)
1526 /* Re-establishing Link */
1527 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1528 "1301 Re-establishing Link "
1529 "Data: x%x x%x x%x\n",
1530 phba
->work_hs
, phba
->work_status
[0],
1531 phba
->work_status
[1]);
1532 if (phba
->work_hs
& HS_FFER8
)
1533 /* Device Zeroization */
1534 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1535 "2861 Host Authentication device "
1536 "zeroization Data:x%x x%x x%x\n",
1537 phba
->work_hs
, phba
->work_status
[0],
1538 phba
->work_status
[1]);
1540 spin_lock_irq(&phba
->hbalock
);
1541 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1542 spin_unlock_irq(&phba
->hbalock
);
1545 * Firmware stops when it triggled erratt with HS_FFER6.
1546 * That could cause the I/Os dropped by the firmware.
1547 * Error iocb (I/O) on txcmplq and let the SCSI layer
1548 * retry it after re-establishing link.
1550 lpfc_sli_abort_fcp_rings(phba
);
1553 * There was a firmware error. Take the hba offline and then
1554 * attempt to restart it.
1556 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1558 lpfc_sli_brdrestart(phba
);
1559 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1560 lpfc_unblock_mgmt_io(phba
);
1563 lpfc_unblock_mgmt_io(phba
);
1564 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1565 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1566 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1567 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1568 temp_event_data
.data
= (uint32_t)temperature
;
1570 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1571 "0406 Adapter maximum temperature exceeded "
1572 "(%ld), taking this port offline "
1573 "Data: x%x x%x x%x\n",
1574 temperature
, phba
->work_hs
,
1575 phba
->work_status
[0], phba
->work_status
[1]);
1577 shost
= lpfc_shost_from_vport(phba
->pport
);
1578 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1579 sizeof(temp_event_data
),
1580 (char *) &temp_event_data
,
1581 SCSI_NL_VID_TYPE_PCI
1582 | PCI_VENDOR_ID_EMULEX
);
1584 spin_lock_irq(&phba
->hbalock
);
1585 phba
->over_temp_state
= HBA_OVER_TEMP
;
1586 spin_unlock_irq(&phba
->hbalock
);
1587 lpfc_offline_eratt(phba
);
1590 /* The if clause above forces this code path when the status
1591 * failure is a value other than FFER6. Do not call the offline
1592 * twice. This is the adapter hardware error path.
1594 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1595 "0457 Adapter Hardware Error "
1596 "Data: x%x x%x x%x\n",
1598 phba
->work_status
[0], phba
->work_status
[1]);
1600 event_data
= FC_REG_DUMP_EVENT
;
1601 shost
= lpfc_shost_from_vport(vport
);
1602 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1603 sizeof(event_data
), (char *) &event_data
,
1604 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1606 lpfc_offline_eratt(phba
);
1612 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1613 * @phba: pointer to lpfc hba data structure.
1614 * @mbx_action: flag for mailbox shutdown action.
1616 * This routine is invoked to perform an SLI4 port PCI function reset in
1617 * response to port status register polling attention. It waits for port
1618 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1619 * During this process, interrupt vectors are freed and later requested
1620 * for handling possible port resource change.
1623 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba
*phba
, int mbx_action
,
1629 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1630 LPFC_SLI_INTF_IF_TYPE_2
) {
1632 * On error status condition, driver need to wait for port
1633 * ready before performing reset.
1635 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1640 /* need reset: attempt for port recovery */
1642 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1643 "2887 Reset Needed: Attempting Port "
1645 lpfc_offline_prep(phba
, mbx_action
);
1647 /* release interrupt for possible resource change */
1648 lpfc_sli4_disable_intr(phba
);
1649 lpfc_sli_brdrestart(phba
);
1650 /* request and enable interrupt */
1651 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
1652 if (intr_mode
== LPFC_INTR_ERROR
) {
1653 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1654 "3175 Failed to enable interrupt\n");
1657 phba
->intr_mode
= intr_mode
;
1658 rc
= lpfc_online(phba
);
1660 lpfc_unblock_mgmt_io(phba
);
1666 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1667 * @phba: pointer to lpfc hba data structure.
1669 * This routine is invoked to handle the SLI4 HBA hardware error attention
1673 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1675 struct lpfc_vport
*vport
= phba
->pport
;
1676 uint32_t event_data
;
1677 struct Scsi_Host
*shost
;
1679 struct lpfc_register portstat_reg
= {0};
1680 uint32_t reg_err1
, reg_err2
;
1681 uint32_t uerrlo_reg
, uemasklo_reg
;
1682 uint32_t smphr_port_status
= 0, pci_rd_rc1
, pci_rd_rc2
;
1683 bool en_rn_msg
= true;
1684 struct temp_event temp_event_data
;
1685 struct lpfc_register portsmphr_reg
;
1688 /* If the pci channel is offline, ignore possible errors, since
1689 * we cannot communicate with the pci card anyway.
1691 if (pci_channel_offline(phba
->pcidev
))
1694 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
1695 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1697 case LPFC_SLI_INTF_IF_TYPE_0
:
1698 pci_rd_rc1
= lpfc_readl(
1699 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
1701 pci_rd_rc2
= lpfc_readl(
1702 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
,
1704 /* consider PCI bus read error as pci_channel_offline */
1705 if (pci_rd_rc1
== -EIO
&& pci_rd_rc2
== -EIO
)
1707 if (!(phba
->hba_flag
& HBA_RECOVERABLE_UE
)) {
1708 lpfc_sli4_offline_eratt(phba
);
1711 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1712 "7623 Checking UE recoverable");
1714 for (i
= 0; i
< phba
->sli4_hba
.ue_to_sr
/ 1000; i
++) {
1715 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1716 &portsmphr_reg
.word0
))
1719 smphr_port_status
= bf_get(lpfc_port_smphr_port_status
,
1721 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1722 LPFC_PORT_SEM_UE_RECOVERABLE
)
1724 /*Sleep for 1Sec, before checking SEMAPHORE */
1728 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1729 "4827 smphr_port_status x%x : Waited %dSec",
1730 smphr_port_status
, i
);
1732 /* Recoverable UE, reset the HBA device */
1733 if ((smphr_port_status
& LPFC_PORT_SEM_MASK
) ==
1734 LPFC_PORT_SEM_UE_RECOVERABLE
) {
1735 for (i
= 0; i
< 20; i
++) {
1737 if (!lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
1738 &portsmphr_reg
.word0
) &&
1739 (LPFC_POST_STAGE_PORT_READY
==
1740 bf_get(lpfc_port_smphr_port_status
,
1742 rc
= lpfc_sli4_port_sta_fn_reset(phba
,
1743 LPFC_MBX_NO_WAIT
, en_rn_msg
);
1746 lpfc_printf_log(phba
,
1748 "4215 Failed to recover UE");
1753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1754 "7624 Firmware not ready: Failing UE recovery,"
1755 " waited %dSec", i
);
1756 lpfc_sli4_offline_eratt(phba
);
1759 case LPFC_SLI_INTF_IF_TYPE_2
:
1760 pci_rd_rc1
= lpfc_readl(
1761 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1762 &portstat_reg
.word0
);
1763 /* consider PCI bus read error as pci_channel_offline */
1764 if (pci_rd_rc1
== -EIO
) {
1765 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1766 "3151 PCI bus read access failure: x%x\n",
1767 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
));
1770 reg_err1
= readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
1771 reg_err2
= readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
1772 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1773 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1774 "2889 Port Overtemperature event, "
1775 "taking port offline Data: x%x x%x\n",
1776 reg_err1
, reg_err2
);
1778 phba
->sfp_alarm
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
1779 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1780 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1781 temp_event_data
.data
= 0xFFFFFFFF;
1783 shost
= lpfc_shost_from_vport(phba
->pport
);
1784 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1785 sizeof(temp_event_data
),
1786 (char *)&temp_event_data
,
1787 SCSI_NL_VID_TYPE_PCI
1788 | PCI_VENDOR_ID_EMULEX
);
1790 spin_lock_irq(&phba
->hbalock
);
1791 phba
->over_temp_state
= HBA_OVER_TEMP
;
1792 spin_unlock_irq(&phba
->hbalock
);
1793 lpfc_sli4_offline_eratt(phba
);
1796 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1797 reg_err2
== SLIPORT_ERR2_REG_FW_RESTART
) {
1798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1799 "3143 Port Down: Firmware Update "
1802 } else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1803 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1804 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1805 "3144 Port Down: Debug Dump\n");
1806 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1807 reg_err2
== SLIPORT_ERR2_REG_FUNC_PROVISON
)
1808 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1809 "3145 Port Down: Provisioning\n");
1811 /* If resets are disabled then leave the HBA alone and return */
1812 if (!phba
->cfg_enable_hba_reset
)
1815 /* Check port status register for function reset */
1816 rc
= lpfc_sli4_port_sta_fn_reset(phba
, LPFC_MBX_NO_WAIT
,
1819 /* don't report event on forced debug dump */
1820 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1821 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1826 /* fall through for not able to recover */
1827 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1828 "3152 Unrecoverable error, bring the port "
1830 lpfc_sli4_offline_eratt(phba
);
1832 case LPFC_SLI_INTF_IF_TYPE_1
:
1836 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1837 "3123 Report dump event to upper layer\n");
1838 /* Send an internal error event to mgmt application */
1839 lpfc_board_errevt_to_mgmt(phba
);
1841 event_data
= FC_REG_DUMP_EVENT
;
1842 shost
= lpfc_shost_from_vport(vport
);
1843 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1844 sizeof(event_data
), (char *) &event_data
,
1845 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1849 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1850 * @phba: pointer to lpfc HBA data structure.
1852 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1853 * routine from the API jump table function pointer from the lpfc_hba struct.
1857 * Any other value - error.
1860 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1862 (*phba
->lpfc_handle_eratt
)(phba
);
1866 * lpfc_handle_latt - The HBA link event handler
1867 * @phba: pointer to lpfc hba data structure.
1869 * This routine is invoked from the worker thread to handle a HBA host
1870 * attention link event. SLI3 only.
1873 lpfc_handle_latt(struct lpfc_hba
*phba
)
1875 struct lpfc_vport
*vport
= phba
->pport
;
1876 struct lpfc_sli
*psli
= &phba
->sli
;
1878 volatile uint32_t control
;
1879 struct lpfc_dmabuf
*mp
;
1882 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1885 goto lpfc_handle_latt_err_exit
;
1888 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1891 goto lpfc_handle_latt_free_pmb
;
1894 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1897 goto lpfc_handle_latt_free_mp
;
1900 /* Cleanup any outstanding ELS commands */
1901 lpfc_els_flush_all_cmd(phba
);
1903 psli
->slistat
.link_event
++;
1904 lpfc_read_topology(phba
, pmb
, mp
);
1905 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
1907 /* Block ELS IOCBs until we have processed this mbox command */
1908 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1909 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1910 if (rc
== MBX_NOT_FINISHED
) {
1912 goto lpfc_handle_latt_free_mbuf
;
1915 /* Clear Link Attention in HA REG */
1916 spin_lock_irq(&phba
->hbalock
);
1917 writel(HA_LATT
, phba
->HAregaddr
);
1918 readl(phba
->HAregaddr
); /* flush */
1919 spin_unlock_irq(&phba
->hbalock
);
1923 lpfc_handle_latt_free_mbuf
:
1924 phba
->sli
.sli3_ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1925 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1926 lpfc_handle_latt_free_mp
:
1928 lpfc_handle_latt_free_pmb
:
1929 mempool_free(pmb
, phba
->mbox_mem_pool
);
1930 lpfc_handle_latt_err_exit
:
1931 /* Enable Link attention interrupts */
1932 spin_lock_irq(&phba
->hbalock
);
1933 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1934 control
= readl(phba
->HCregaddr
);
1935 control
|= HC_LAINT_ENA
;
1936 writel(control
, phba
->HCregaddr
);
1937 readl(phba
->HCregaddr
); /* flush */
1939 /* Clear Link Attention in HA REG */
1940 writel(HA_LATT
, phba
->HAregaddr
);
1941 readl(phba
->HAregaddr
); /* flush */
1942 spin_unlock_irq(&phba
->hbalock
);
1943 lpfc_linkdown(phba
);
1944 phba
->link_state
= LPFC_HBA_ERROR
;
1946 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1947 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1953 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1954 * @phba: pointer to lpfc hba data structure.
1955 * @vpd: pointer to the vital product data.
1956 * @len: length of the vital product data in bytes.
1958 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1959 * an array of characters. In this routine, the ModelName, ProgramType, and
1960 * ModelDesc, etc. fields of the phba data structure will be populated.
1963 * 0 - pointer to the VPD passed in is NULL
1967 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1969 uint8_t lenlo
, lenhi
;
1979 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1980 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1981 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1983 while (!finished
&& (index
< (len
- 4))) {
1984 switch (vpd
[index
]) {
1992 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
2001 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
2002 if (Length
> len
- index
)
2003 Length
= len
- index
;
2004 while (Length
> 0) {
2005 /* Look for Serial Number */
2006 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
2013 phba
->SerialNumber
[j
++] = vpd
[index
++];
2017 phba
->SerialNumber
[j
] = 0;
2020 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
2021 phba
->vpd_flag
|= VPD_MODEL_DESC
;
2028 phba
->ModelDesc
[j
++] = vpd
[index
++];
2032 phba
->ModelDesc
[j
] = 0;
2035 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
2036 phba
->vpd_flag
|= VPD_MODEL_NAME
;
2043 phba
->ModelName
[j
++] = vpd
[index
++];
2047 phba
->ModelName
[j
] = 0;
2050 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
2051 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
2058 phba
->ProgramType
[j
++] = vpd
[index
++];
2062 phba
->ProgramType
[j
] = 0;
2065 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
2066 phba
->vpd_flag
|= VPD_PORT
;
2073 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
2074 (phba
->sli4_hba
.pport_name_sta
==
2075 LPFC_SLI4_PPNAME_GET
)) {
2079 phba
->Port
[j
++] = vpd
[index
++];
2083 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
2084 (phba
->sli4_hba
.pport_name_sta
==
2085 LPFC_SLI4_PPNAME_NON
))
2112 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
2113 * @phba: pointer to lpfc hba data structure.
2114 * @mdp: pointer to the data structure to hold the derived model name.
2115 * @descp: pointer to the data structure to hold the derived description.
2117 * This routine retrieves HBA's description based on its registered PCI device
2118 * ID. The @descp passed into this function points to an array of 256 chars. It
2119 * shall be returned with the model name, maximum speed, and the host bus type.
2120 * The @mdp passed into this function points to an array of 80 chars. When the
2121 * function returns, the @mdp will be filled with the model name.
2124 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
2127 uint16_t dev_id
= phba
->pcidev
->device
;
2130 int oneConnect
= 0; /* default is not a oneConnect */
2135 } m
= {"<Unknown>", "", ""};
2137 if (mdp
&& mdp
[0] != '\0'
2138 && descp
&& descp
[0] != '\0')
2141 if (phba
->lmt
& LMT_32Gb
)
2143 else if (phba
->lmt
& LMT_16Gb
)
2145 else if (phba
->lmt
& LMT_10Gb
)
2147 else if (phba
->lmt
& LMT_8Gb
)
2149 else if (phba
->lmt
& LMT_4Gb
)
2151 else if (phba
->lmt
& LMT_2Gb
)
2153 else if (phba
->lmt
& LMT_1Gb
)
2161 case PCI_DEVICE_ID_FIREFLY
:
2162 m
= (typeof(m
)){"LP6000", "PCI",
2163 "Obsolete, Unsupported Fibre Channel Adapter"};
2165 case PCI_DEVICE_ID_SUPERFLY
:
2166 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
2167 m
= (typeof(m
)){"LP7000", "PCI", ""};
2169 m
= (typeof(m
)){"LP7000E", "PCI", ""};
2170 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2172 case PCI_DEVICE_ID_DRAGONFLY
:
2173 m
= (typeof(m
)){"LP8000", "PCI",
2174 "Obsolete, Unsupported Fibre Channel Adapter"};
2176 case PCI_DEVICE_ID_CENTAUR
:
2177 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
2178 m
= (typeof(m
)){"LP9002", "PCI", ""};
2180 m
= (typeof(m
)){"LP9000", "PCI", ""};
2181 m
.function
= "Obsolete, Unsupported Fibre Channel Adapter";
2183 case PCI_DEVICE_ID_RFLY
:
2184 m
= (typeof(m
)){"LP952", "PCI",
2185 "Obsolete, Unsupported Fibre Channel Adapter"};
2187 case PCI_DEVICE_ID_PEGASUS
:
2188 m
= (typeof(m
)){"LP9802", "PCI-X",
2189 "Obsolete, Unsupported Fibre Channel Adapter"};
2191 case PCI_DEVICE_ID_THOR
:
2192 m
= (typeof(m
)){"LP10000", "PCI-X",
2193 "Obsolete, Unsupported Fibre Channel Adapter"};
2195 case PCI_DEVICE_ID_VIPER
:
2196 m
= (typeof(m
)){"LPX1000", "PCI-X",
2197 "Obsolete, Unsupported Fibre Channel Adapter"};
2199 case PCI_DEVICE_ID_PFLY
:
2200 m
= (typeof(m
)){"LP982", "PCI-X",
2201 "Obsolete, Unsupported Fibre Channel Adapter"};
2203 case PCI_DEVICE_ID_TFLY
:
2204 m
= (typeof(m
)){"LP1050", "PCI-X",
2205 "Obsolete, Unsupported Fibre Channel Adapter"};
2207 case PCI_DEVICE_ID_HELIOS
:
2208 m
= (typeof(m
)){"LP11000", "PCI-X2",
2209 "Obsolete, Unsupported Fibre Channel Adapter"};
2211 case PCI_DEVICE_ID_HELIOS_SCSP
:
2212 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
2213 "Obsolete, Unsupported Fibre Channel Adapter"};
2215 case PCI_DEVICE_ID_HELIOS_DCSP
:
2216 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
2217 "Obsolete, Unsupported Fibre Channel Adapter"};
2219 case PCI_DEVICE_ID_NEPTUNE
:
2220 m
= (typeof(m
)){"LPe1000", "PCIe",
2221 "Obsolete, Unsupported Fibre Channel Adapter"};
2223 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
2224 m
= (typeof(m
)){"LPe1000-SP", "PCIe",
2225 "Obsolete, Unsupported Fibre Channel Adapter"};
2227 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
2228 m
= (typeof(m
)){"LPe1002-SP", "PCIe",
2229 "Obsolete, Unsupported Fibre Channel Adapter"};
2231 case PCI_DEVICE_ID_BMID
:
2232 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
2234 case PCI_DEVICE_ID_BSMB
:
2235 m
= (typeof(m
)){"LP111", "PCI-X2",
2236 "Obsolete, Unsupported Fibre Channel Adapter"};
2238 case PCI_DEVICE_ID_ZEPHYR
:
2239 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2241 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
2242 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
2244 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
2245 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
2248 case PCI_DEVICE_ID_ZMID
:
2249 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2251 case PCI_DEVICE_ID_ZSMB
:
2252 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2254 case PCI_DEVICE_ID_LP101
:
2255 m
= (typeof(m
)){"LP101", "PCI-X",
2256 "Obsolete, Unsupported Fibre Channel Adapter"};
2258 case PCI_DEVICE_ID_LP10000S
:
2259 m
= (typeof(m
)){"LP10000-S", "PCI",
2260 "Obsolete, Unsupported Fibre Channel Adapter"};
2262 case PCI_DEVICE_ID_LP11000S
:
2263 m
= (typeof(m
)){"LP11000-S", "PCI-X2",
2264 "Obsolete, Unsupported Fibre Channel Adapter"};
2266 case PCI_DEVICE_ID_LPE11000S
:
2267 m
= (typeof(m
)){"LPe11000-S", "PCIe",
2268 "Obsolete, Unsupported Fibre Channel Adapter"};
2270 case PCI_DEVICE_ID_SAT
:
2271 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2273 case PCI_DEVICE_ID_SAT_MID
:
2274 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2276 case PCI_DEVICE_ID_SAT_SMB
:
2277 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2279 case PCI_DEVICE_ID_SAT_DCSP
:
2280 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2282 case PCI_DEVICE_ID_SAT_SCSP
:
2283 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2285 case PCI_DEVICE_ID_SAT_S
:
2286 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2288 case PCI_DEVICE_ID_HORNET
:
2289 m
= (typeof(m
)){"LP21000", "PCIe",
2290 "Obsolete, Unsupported FCoE Adapter"};
2293 case PCI_DEVICE_ID_PROTEUS_VF
:
2294 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2295 "Obsolete, Unsupported Fibre Channel Adapter"};
2297 case PCI_DEVICE_ID_PROTEUS_PF
:
2298 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2299 "Obsolete, Unsupported Fibre Channel Adapter"};
2301 case PCI_DEVICE_ID_PROTEUS_S
:
2302 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2303 "Obsolete, Unsupported Fibre Channel Adapter"};
2305 case PCI_DEVICE_ID_TIGERSHARK
:
2307 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2309 case PCI_DEVICE_ID_TOMCAT
:
2311 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2313 case PCI_DEVICE_ID_FALCON
:
2314 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2315 "EmulexSecure Fibre"};
2317 case PCI_DEVICE_ID_BALIUS
:
2318 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2319 "Obsolete, Unsupported Fibre Channel Adapter"};
2321 case PCI_DEVICE_ID_LANCER_FC
:
2322 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2324 case PCI_DEVICE_ID_LANCER_FC_VF
:
2325 m
= (typeof(m
)){"LPe16000", "PCIe",
2326 "Obsolete, Unsupported Fibre Channel Adapter"};
2328 case PCI_DEVICE_ID_LANCER_FCOE
:
2330 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2332 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2334 m
= (typeof(m
)){"OCe15100", "PCIe",
2335 "Obsolete, Unsupported FCoE"};
2337 case PCI_DEVICE_ID_LANCER_G6_FC
:
2338 m
= (typeof(m
)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2340 case PCI_DEVICE_ID_SKYHAWK
:
2341 case PCI_DEVICE_ID_SKYHAWK_VF
:
2343 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2346 m
= (typeof(m
)){"Unknown", "", ""};
2350 if (mdp
&& mdp
[0] == '\0')
2351 snprintf(mdp
, 79,"%s", m
.name
);
2353 * oneConnect hba requires special processing, they are all initiators
2354 * and we put the port number on the end
2356 if (descp
&& descp
[0] == '\0') {
2358 snprintf(descp
, 255,
2359 "Emulex OneConnect %s, %s Initiator %s",
2362 else if (max_speed
== 0)
2363 snprintf(descp
, 255,
2365 m
.name
, m
.bus
, m
.function
);
2367 snprintf(descp
, 255,
2368 "Emulex %s %d%s %s %s",
2369 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2375 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2376 * @phba: pointer to lpfc hba data structure.
2377 * @pring: pointer to a IOCB ring.
2378 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2380 * This routine posts a given number of IOCBs with the associated DMA buffer
2381 * descriptors specified by the cnt argument to the given IOCB ring.
2384 * The number of IOCBs NOT able to be posted to the IOCB ring.
2387 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2390 struct lpfc_iocbq
*iocb
;
2391 struct lpfc_dmabuf
*mp1
, *mp2
;
2393 cnt
+= pring
->missbufcnt
;
2395 /* While there are buffers to post */
2397 /* Allocate buffer for command iocb */
2398 iocb
= lpfc_sli_get_iocbq(phba
);
2400 pring
->missbufcnt
= cnt
;
2405 /* 2 buffers can be posted per command */
2406 /* Allocate buffer to post */
2407 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2409 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2410 if (!mp1
|| !mp1
->virt
) {
2412 lpfc_sli_release_iocbq(phba
, iocb
);
2413 pring
->missbufcnt
= cnt
;
2417 INIT_LIST_HEAD(&mp1
->list
);
2418 /* Allocate buffer to post */
2420 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2422 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2424 if (!mp2
|| !mp2
->virt
) {
2426 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2428 lpfc_sli_release_iocbq(phba
, iocb
);
2429 pring
->missbufcnt
= cnt
;
2433 INIT_LIST_HEAD(&mp2
->list
);
2438 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2439 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2440 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2441 icmd
->ulpBdeCount
= 1;
2444 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2445 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2446 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2448 icmd
->ulpBdeCount
= 2;
2451 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2454 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2456 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2460 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2464 lpfc_sli_release_iocbq(phba
, iocb
);
2465 pring
->missbufcnt
= cnt
;
2468 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2470 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2472 pring
->missbufcnt
= 0;
2477 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2478 * @phba: pointer to lpfc hba data structure.
2480 * This routine posts initial receive IOCB buffers to the ELS ring. The
2481 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2482 * set to 64 IOCBs. SLI3 only.
2485 * 0 - success (currently always success)
2488 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2490 struct lpfc_sli
*psli
= &phba
->sli
;
2492 /* Ring 0, ELS / CT buffers */
2493 lpfc_post_buffer(phba
, &psli
->sli3_ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2494 /* Ring 2 - FCP no buffers needed */
2499 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2502 * lpfc_sha_init - Set up initial array of hash table entries
2503 * @HashResultPointer: pointer to an array as hash table.
2505 * This routine sets up the initial values to the array of hash table entries
2509 lpfc_sha_init(uint32_t * HashResultPointer
)
2511 HashResultPointer
[0] = 0x67452301;
2512 HashResultPointer
[1] = 0xEFCDAB89;
2513 HashResultPointer
[2] = 0x98BADCFE;
2514 HashResultPointer
[3] = 0x10325476;
2515 HashResultPointer
[4] = 0xC3D2E1F0;
2519 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2520 * @HashResultPointer: pointer to an initial/result hash table.
2521 * @HashWorkingPointer: pointer to an working hash table.
2523 * This routine iterates an initial hash table pointed by @HashResultPointer
2524 * with the values from the working hash table pointeed by @HashWorkingPointer.
2525 * The results are putting back to the initial hash table, returned through
2526 * the @HashResultPointer as the result hash table.
2529 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2533 uint32_t A
, B
, C
, D
, E
;
2536 HashWorkingPointer
[t
] =
2538 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2540 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2541 } while (++t
<= 79);
2543 A
= HashResultPointer
[0];
2544 B
= HashResultPointer
[1];
2545 C
= HashResultPointer
[2];
2546 D
= HashResultPointer
[3];
2547 E
= HashResultPointer
[4];
2551 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2552 } else if (t
< 40) {
2553 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2554 } else if (t
< 60) {
2555 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2557 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2559 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2565 } while (++t
<= 79);
2567 HashResultPointer
[0] += A
;
2568 HashResultPointer
[1] += B
;
2569 HashResultPointer
[2] += C
;
2570 HashResultPointer
[3] += D
;
2571 HashResultPointer
[4] += E
;
2576 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2577 * @RandomChallenge: pointer to the entry of host challenge random number array.
2578 * @HashWorking: pointer to the entry of the working hash array.
2580 * This routine calculates the working hash array referred by @HashWorking
2581 * from the challenge random numbers associated with the host, referred by
2582 * @RandomChallenge. The result is put into the entry of the working hash
2583 * array and returned by reference through @HashWorking.
2586 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2588 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2592 * lpfc_hba_init - Perform special handling for LC HBA initialization
2593 * @phba: pointer to lpfc hba data structure.
2594 * @hbainit: pointer to an array of unsigned 32-bit integers.
2596 * This routine performs the special handling for LC HBA initialization.
2599 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2602 uint32_t *HashWorking
;
2603 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2605 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2609 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2610 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2612 for (t
= 0; t
< 7; t
++)
2613 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2615 lpfc_sha_init(hbainit
);
2616 lpfc_sha_iterate(hbainit
, HashWorking
);
2621 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2622 * @vport: pointer to a virtual N_Port data structure.
2624 * This routine performs the necessary cleanups before deleting the @vport.
2625 * It invokes the discovery state machine to perform necessary state
2626 * transitions and to release the ndlps associated with the @vport. Note,
2627 * the physical port is treated as @vport 0.
2630 lpfc_cleanup(struct lpfc_vport
*vport
)
2632 struct lpfc_hba
*phba
= vport
->phba
;
2633 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2636 if (phba
->link_state
> LPFC_LINK_DOWN
)
2637 lpfc_port_link_failure(vport
);
2639 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2640 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2641 ndlp
= lpfc_enable_node(vport
, ndlp
,
2642 NLP_STE_UNUSED_NODE
);
2645 spin_lock_irq(&phba
->ndlp_lock
);
2646 NLP_SET_FREE_REQ(ndlp
);
2647 spin_unlock_irq(&phba
->ndlp_lock
);
2648 /* Trigger the release of the ndlp memory */
2652 spin_lock_irq(&phba
->ndlp_lock
);
2653 if (NLP_CHK_FREE_REQ(ndlp
)) {
2654 /* The ndlp should not be in memory free mode already */
2655 spin_unlock_irq(&phba
->ndlp_lock
);
2658 /* Indicate request for freeing ndlp memory */
2659 NLP_SET_FREE_REQ(ndlp
);
2660 spin_unlock_irq(&phba
->ndlp_lock
);
2662 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2663 ndlp
->nlp_DID
== Fabric_DID
) {
2664 /* Just free up ndlp with Fabric_DID for vports */
2669 /* take care of nodes in unused state before the state
2670 * machine taking action.
2672 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2677 if (ndlp
->nlp_type
& NLP_FABRIC
)
2678 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2679 NLP_EVT_DEVICE_RECOVERY
);
2681 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
2682 /* Remove the NVME transport reference now and
2683 * continue to remove the node.
2688 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2692 /* At this point, ALL ndlp's should be gone
2693 * because of the previous NLP_EVT_DEVICE_RM.
2694 * Lets wait for this to happen, if needed.
2696 while (!list_empty(&vport
->fc_nodes
)) {
2698 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2699 "0233 Nodelist not empty\n");
2700 list_for_each_entry_safe(ndlp
, next_ndlp
,
2701 &vport
->fc_nodes
, nlp_listp
) {
2702 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2704 "0282 did:x%x ndlp:x%p "
2705 "usgmap:x%x refcnt:%d\n",
2706 ndlp
->nlp_DID
, (void *)ndlp
,
2708 kref_read(&ndlp
->kref
));
2713 /* Wait for any activity on ndlps to settle */
2716 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2720 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2721 * @vport: pointer to a virtual N_Port data structure.
2723 * This routine stops all the timers associated with a @vport. This function
2724 * is invoked before disabling or deleting a @vport. Note that the physical
2725 * port is treated as @vport 0.
2728 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2730 del_timer_sync(&vport
->els_tmofunc
);
2731 del_timer_sync(&vport
->delayed_disc_tmo
);
2732 lpfc_can_disctmo(vport
);
2737 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2738 * @phba: pointer to lpfc hba data structure.
2740 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2741 * caller of this routine should already hold the host lock.
2744 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2746 /* Clear pending FCF rediscovery wait flag */
2747 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2749 /* Now, try to stop the timer */
2750 del_timer(&phba
->fcf
.redisc_wait
);
2754 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2755 * @phba: pointer to lpfc hba data structure.
2757 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2758 * checks whether the FCF rediscovery wait timer is pending with the host
2759 * lock held before proceeding with disabling the timer and clearing the
2760 * wait timer pendig flag.
2763 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2765 spin_lock_irq(&phba
->hbalock
);
2766 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2767 /* FCF rediscovery timer already fired or stopped */
2768 spin_unlock_irq(&phba
->hbalock
);
2771 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2772 /* Clear failover in progress flags */
2773 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2774 spin_unlock_irq(&phba
->hbalock
);
2778 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2779 * @phba: pointer to lpfc hba data structure.
2781 * This routine stops all the timers associated with a HBA. This function is
2782 * invoked before either putting a HBA offline or unloading the driver.
2785 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2787 lpfc_stop_vport_timers(phba
->pport
);
2788 del_timer_sync(&phba
->sli
.mbox_tmo
);
2789 del_timer_sync(&phba
->fabric_block_timer
);
2790 del_timer_sync(&phba
->eratt_poll
);
2791 del_timer_sync(&phba
->hb_tmofunc
);
2792 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2793 del_timer_sync(&phba
->rrq_tmr
);
2794 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2796 phba
->hb_outstanding
= 0;
2798 switch (phba
->pci_dev_grp
) {
2799 case LPFC_PCI_DEV_LP
:
2800 /* Stop any LightPulse device specific driver timers */
2801 del_timer_sync(&phba
->fcp_poll_timer
);
2803 case LPFC_PCI_DEV_OC
:
2804 /* Stop any OneConnect device sepcific driver timers */
2805 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2808 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2809 "0297 Invalid device group (x%x)\n",
2817 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2818 * @phba: pointer to lpfc hba data structure.
2820 * This routine marks a HBA's management interface as blocked. Once the HBA's
2821 * management interface is marked as blocked, all the user space access to
2822 * the HBA, whether they are from sysfs interface or libdfc interface will
2823 * all be blocked. The HBA is set to block the management interface when the
2824 * driver prepares the HBA interface for online or offline.
2827 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
2829 unsigned long iflag
;
2830 uint8_t actcmd
= MBX_HEARTBEAT
;
2831 unsigned long timeout
;
2833 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2834 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2835 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2836 if (mbx_action
== LPFC_MBX_NO_WAIT
)
2838 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
2839 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2840 if (phba
->sli
.mbox_active
) {
2841 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2842 /* Determine how long we might wait for the active mailbox
2843 * command to be gracefully completed by firmware.
2845 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2846 phba
->sli
.mbox_active
) * 1000) + jiffies
;
2848 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2850 /* Wait for the outstnading mailbox command to complete */
2851 while (phba
->sli
.mbox_active
) {
2852 /* Check active mailbox complete status every 2ms */
2854 if (time_after(jiffies
, timeout
)) {
2855 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2856 "2813 Mgmt IO is Blocked %x "
2857 "- mbox cmd %x still active\n",
2858 phba
->sli
.sli_flag
, actcmd
);
2865 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2866 * @phba: pointer to lpfc hba data structure.
2868 * Allocate RPIs for all active remote nodes. This is needed whenever
2869 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2870 * is to fixup the temporary rpi assignments.
2873 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
2875 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2876 struct lpfc_vport
**vports
;
2879 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
2882 vports
= lpfc_create_vport_work_array(phba
);
2883 if (vports
!= NULL
) {
2884 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2885 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2888 list_for_each_entry_safe(ndlp
, next_ndlp
,
2889 &vports
[i
]->fc_nodes
,
2891 if (NLP_CHK_NODE_ACT(ndlp
)) {
2893 lpfc_sli4_alloc_rpi(phba
);
2894 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
,
2896 "0009 rpi:%x DID:%x "
2897 "flg:%x map:%x %p\n",
2907 lpfc_destroy_vport_work_array(phba
, vports
);
2911 * lpfc_online - Initialize and bring a HBA online
2912 * @phba: pointer to lpfc hba data structure.
2914 * This routine initializes the HBA and brings a HBA online. During this
2915 * process, the management interface is blocked to prevent user space access
2916 * to the HBA interfering with the driver initialization.
2923 lpfc_online(struct lpfc_hba
*phba
)
2925 struct lpfc_vport
*vport
;
2926 struct lpfc_vport
**vports
;
2928 bool vpis_cleared
= false;
2932 vport
= phba
->pport
;
2934 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2937 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2938 "0458 Bring Adapter online\n");
2940 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
2942 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2943 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2944 lpfc_unblock_mgmt_io(phba
);
2947 spin_lock_irq(&phba
->hbalock
);
2948 if (!phba
->sli4_hba
.max_cfg_param
.vpi_used
)
2949 vpis_cleared
= true;
2950 spin_unlock_irq(&phba
->hbalock
);
2952 lpfc_sli_queue_init(phba
);
2953 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2954 lpfc_unblock_mgmt_io(phba
);
2959 vports
= lpfc_create_vport_work_array(phba
);
2960 if (vports
!= NULL
) {
2961 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2962 struct Scsi_Host
*shost
;
2963 shost
= lpfc_shost_from_vport(vports
[i
]);
2964 spin_lock_irq(shost
->host_lock
);
2965 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2966 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2967 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2968 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2969 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2970 if ((vpis_cleared
) &&
2971 (vports
[i
]->port_type
!=
2972 LPFC_PHYSICAL_PORT
))
2975 spin_unlock_irq(shost
->host_lock
);
2978 lpfc_destroy_vport_work_array(phba
, vports
);
2980 lpfc_unblock_mgmt_io(phba
);
2985 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2986 * @phba: pointer to lpfc hba data structure.
2988 * This routine marks a HBA's management interface as not blocked. Once the
2989 * HBA's management interface is marked as not blocked, all the user space
2990 * access to the HBA, whether they are from sysfs interface or libdfc
2991 * interface will be allowed. The HBA is set to block the management interface
2992 * when the driver prepares the HBA interface for online or offline and then
2993 * set to unblock the management interface afterwards.
2996 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2998 unsigned long iflag
;
3000 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3001 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
3002 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3006 * lpfc_offline_prep - Prepare a HBA to be brought offline
3007 * @phba: pointer to lpfc hba data structure.
3009 * This routine is invoked to prepare a HBA to be brought offline. It performs
3010 * unregistration login to all the nodes on all vports and flushes the mailbox
3011 * queue to make it ready to be brought offline.
3014 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
3016 struct lpfc_vport
*vport
= phba
->pport
;
3017 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3018 struct lpfc_vport
**vports
;
3019 struct Scsi_Host
*shost
;
3022 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
3025 lpfc_block_mgmt_io(phba
, mbx_action
);
3027 lpfc_linkdown(phba
);
3029 /* Issue an unreg_login to all nodes on all vports */
3030 vports
= lpfc_create_vport_work_array(phba
);
3031 if (vports
!= NULL
) {
3032 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3033 if (vports
[i
]->load_flag
& FC_UNLOADING
)
3035 shost
= lpfc_shost_from_vport(vports
[i
]);
3036 spin_lock_irq(shost
->host_lock
);
3037 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3038 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3039 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
3040 spin_unlock_irq(shost
->host_lock
);
3042 shost
= lpfc_shost_from_vport(vports
[i
]);
3043 list_for_each_entry_safe(ndlp
, next_ndlp
,
3044 &vports
[i
]->fc_nodes
,
3046 if (!NLP_CHK_NODE_ACT(ndlp
))
3048 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3050 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3051 lpfc_disc_state_machine(vports
[i
], ndlp
,
3052 NULL
, NLP_EVT_DEVICE_RECOVERY
);
3053 lpfc_disc_state_machine(vports
[i
], ndlp
,
3054 NULL
, NLP_EVT_DEVICE_RM
);
3056 spin_lock_irq(shost
->host_lock
);
3057 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3058 spin_unlock_irq(shost
->host_lock
);
3060 * Whenever an SLI4 port goes offline, free the
3061 * RPI. Get a new RPI when the adapter port
3062 * comes back online.
3064 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3065 lpfc_printf_vlog(ndlp
->vport
,
3066 KERN_INFO
, LOG_NODE
,
3067 "0011 lpfc_offline: "
3069 "usgmap:x%x rpi:%x\n",
3070 ndlp
, ndlp
->nlp_DID
,
3074 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
3076 lpfc_unreg_rpi(vports
[i
], ndlp
);
3080 lpfc_destroy_vport_work_array(phba
, vports
);
3082 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
3086 * lpfc_offline - Bring a HBA offline
3087 * @phba: pointer to lpfc hba data structure.
3089 * This routine actually brings a HBA offline. It stops all the timers
3090 * associated with the HBA, brings down the SLI layer, and eventually
3091 * marks the HBA as in offline state for the upper layer protocol.
3094 lpfc_offline(struct lpfc_hba
*phba
)
3096 struct Scsi_Host
*shost
;
3097 struct lpfc_vport
**vports
;
3100 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
3103 /* stop port and all timers associated with this hba */
3104 lpfc_stop_port(phba
);
3105 vports
= lpfc_create_vport_work_array(phba
);
3107 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3108 lpfc_stop_vport_timers(vports
[i
]);
3109 lpfc_destroy_vport_work_array(phba
, vports
);
3110 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3111 "0460 Bring Adapter offline\n");
3112 /* Bring down the SLI Layer and cleanup. The HBA is offline
3114 lpfc_sli_hba_down(phba
);
3115 spin_lock_irq(&phba
->hbalock
);
3117 spin_unlock_irq(&phba
->hbalock
);
3118 vports
= lpfc_create_vport_work_array(phba
);
3120 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3121 shost
= lpfc_shost_from_vport(vports
[i
]);
3122 spin_lock_irq(shost
->host_lock
);
3123 vports
[i
]->work_port_events
= 0;
3124 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
3125 spin_unlock_irq(shost
->host_lock
);
3127 lpfc_destroy_vport_work_array(phba
, vports
);
3131 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
3132 * @phba: pointer to lpfc hba data structure.
3134 * This routine is to free all the SCSI buffers and IOCBs from the driver
3135 * list back to kernel. It is called from lpfc_pci_remove_one to free
3136 * the internal resources before the device is removed from the system.
3139 lpfc_scsi_free(struct lpfc_hba
*phba
)
3141 struct lpfc_scsi_buf
*sb
, *sb_next
;
3143 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
3146 spin_lock_irq(&phba
->hbalock
);
3148 /* Release all the lpfc_scsi_bufs maintained by this host. */
3150 spin_lock(&phba
->scsi_buf_list_put_lock
);
3151 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_put
,
3153 list_del(&sb
->list
);
3154 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3157 phba
->total_scsi_bufs
--;
3159 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3161 spin_lock(&phba
->scsi_buf_list_get_lock
);
3162 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_get
,
3164 list_del(&sb
->list
);
3165 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, sb
->data
,
3168 phba
->total_scsi_bufs
--;
3170 spin_unlock(&phba
->scsi_buf_list_get_lock
);
3171 spin_unlock_irq(&phba
->hbalock
);
3174 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3175 * @phba: pointer to lpfc hba data structure.
3177 * This routine is to free all the NVME buffers and IOCBs from the driver
3178 * list back to kernel. It is called from lpfc_pci_remove_one to free
3179 * the internal resources before the device is removed from the system.
3182 lpfc_nvme_free(struct lpfc_hba
*phba
)
3184 struct lpfc_nvme_buf
*lpfc_ncmd
, *lpfc_ncmd_next
;
3186 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
))
3189 spin_lock_irq(&phba
->hbalock
);
3191 /* Release all the lpfc_nvme_bufs maintained by this host. */
3192 spin_lock(&phba
->nvme_buf_list_put_lock
);
3193 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3194 &phba
->lpfc_nvme_buf_list_put
, list
) {
3195 list_del(&lpfc_ncmd
->list
);
3196 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, lpfc_ncmd
->data
,
3197 lpfc_ncmd
->dma_handle
);
3199 phba
->total_nvme_bufs
--;
3201 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3203 spin_lock(&phba
->nvme_buf_list_get_lock
);
3204 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3205 &phba
->lpfc_nvme_buf_list_get
, list
) {
3206 list_del(&lpfc_ncmd
->list
);
3207 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
, lpfc_ncmd
->data
,
3208 lpfc_ncmd
->dma_handle
);
3210 phba
->total_nvme_bufs
--;
3212 spin_unlock(&phba
->nvme_buf_list_get_lock
);
3213 spin_unlock_irq(&phba
->hbalock
);
3216 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
3217 * @phba: pointer to lpfc hba data structure.
3219 * This routine first calculates the sizes of the current els and allocated
3220 * scsi sgl lists, and then goes through all sgls to updates the physical
3221 * XRIs assigned due to port function reset. During port initialization, the
3222 * current els and allocated scsi sgl lists are 0s.
3225 * 0 - successful (for now, it always returns 0)
3228 lpfc_sli4_els_sgl_update(struct lpfc_hba
*phba
)
3230 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3231 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3232 LIST_HEAD(els_sgl_list
);
3236 * update on pci function's els xri-sgl list
3238 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3240 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
3241 /* els xri-sgl expanded */
3242 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
3243 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3244 "3157 ELS xri-sgl count increased from "
3245 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3247 /* allocate the additional els sgls */
3248 for (i
= 0; i
< xri_cnt
; i
++) {
3249 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3251 if (sglq_entry
== NULL
) {
3252 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3253 "2562 Failure to allocate an "
3254 "ELS sgl entry:%d\n", i
);
3258 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
3259 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
3261 if (sglq_entry
->virt
== NULL
) {
3263 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3264 "2563 Failure to allocate an "
3265 "ELS mbuf:%d\n", i
);
3269 sglq_entry
->sgl
= sglq_entry
->virt
;
3270 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
3271 sglq_entry
->state
= SGL_FREED
;
3272 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
3274 spin_lock_irq(&phba
->hbalock
);
3275 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3276 list_splice_init(&els_sgl_list
,
3277 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3278 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3279 spin_unlock_irq(&phba
->hbalock
);
3280 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
3281 /* els xri-sgl shrinked */
3282 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
3283 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3284 "3158 ELS xri-sgl count decreased from "
3285 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
3287 spin_lock_irq(&phba
->hbalock
);
3288 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3289 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
,
3291 /* release extra els sgls from list */
3292 for (i
= 0; i
< xri_cnt
; i
++) {
3293 list_remove_head(&els_sgl_list
,
3294 sglq_entry
, struct lpfc_sglq
, list
);
3296 __lpfc_mbuf_free(phba
, sglq_entry
->virt
,
3301 list_splice_init(&els_sgl_list
,
3302 &phba
->sli4_hba
.lpfc_els_sgl_list
);
3303 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3304 spin_unlock_irq(&phba
->hbalock
);
3306 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3307 "3163 ELS xri-sgl count unchanged: %d\n",
3309 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
3311 /* update xris to els sgls on the list */
3313 sglq_entry_next
= NULL
;
3314 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3315 &phba
->sli4_hba
.lpfc_els_sgl_list
, list
) {
3316 lxri
= lpfc_sli4_next_xritag(phba
);
3317 if (lxri
== NO_XRI
) {
3318 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3319 "2400 Failed to allocate xri for "
3324 sglq_entry
->sli4_lxritag
= lxri
;
3325 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3330 lpfc_free_els_sgl_list(phba
);
3335 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3336 * @phba: pointer to lpfc hba data structure.
3338 * This routine first calculates the sizes of the current els and allocated
3339 * scsi sgl lists, and then goes through all sgls to updates the physical
3340 * XRIs assigned due to port function reset. During port initialization, the
3341 * current els and allocated scsi sgl lists are 0s.
3344 * 0 - successful (for now, it always returns 0)
3347 lpfc_sli4_nvmet_sgl_update(struct lpfc_hba
*phba
)
3349 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
3350 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
;
3351 uint16_t nvmet_xri_cnt
, tot_cnt
;
3352 LIST_HEAD(nvmet_sgl_list
);
3356 * update on pci function's nvmet xri-sgl list
3358 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3359 nvmet_xri_cnt
= phba
->cfg_nvmet_mrq
* phba
->cfg_nvmet_mrq_post
;
3360 tot_cnt
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
3361 if (nvmet_xri_cnt
> tot_cnt
) {
3362 phba
->cfg_nvmet_mrq_post
= tot_cnt
/ phba
->cfg_nvmet_mrq
;
3363 nvmet_xri_cnt
= phba
->cfg_nvmet_mrq
* phba
->cfg_nvmet_mrq_post
;
3364 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3365 "6301 NVMET post-sgl count changed to %d\n",
3366 phba
->cfg_nvmet_mrq_post
);
3369 if (nvmet_xri_cnt
> phba
->sli4_hba
.nvmet_xri_cnt
) {
3370 /* els xri-sgl expanded */
3371 xri_cnt
= nvmet_xri_cnt
- phba
->sli4_hba
.nvmet_xri_cnt
;
3372 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3373 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3374 phba
->sli4_hba
.nvmet_xri_cnt
, nvmet_xri_cnt
);
3375 /* allocate the additional nvmet sgls */
3376 for (i
= 0; i
< xri_cnt
; i
++) {
3377 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
3379 if (sglq_entry
== NULL
) {
3380 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3381 "6303 Failure to allocate an "
3382 "NVMET sgl entry:%d\n", i
);
3386 sglq_entry
->buff_type
= NVMET_BUFF_TYPE
;
3387 sglq_entry
->virt
= lpfc_nvmet_buf_alloc(phba
, 0,
3389 if (sglq_entry
->virt
== NULL
) {
3391 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3392 "6304 Failure to allocate an "
3393 "NVMET buf:%d\n", i
);
3397 sglq_entry
->sgl
= sglq_entry
->virt
;
3398 memset(sglq_entry
->sgl
, 0,
3399 phba
->cfg_sg_dma_buf_size
);
3400 sglq_entry
->state
= SGL_FREED
;
3401 list_add_tail(&sglq_entry
->list
, &nvmet_sgl_list
);
3403 spin_lock_irq(&phba
->hbalock
);
3404 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3405 list_splice_init(&nvmet_sgl_list
,
3406 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3407 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3408 spin_unlock_irq(&phba
->hbalock
);
3409 } else if (nvmet_xri_cnt
< phba
->sli4_hba
.nvmet_xri_cnt
) {
3410 /* nvmet xri-sgl shrunk */
3411 xri_cnt
= phba
->sli4_hba
.nvmet_xri_cnt
- nvmet_xri_cnt
;
3412 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3413 "6305 NVMET xri-sgl count decreased from "
3414 "%d to %d\n", phba
->sli4_hba
.nvmet_xri_cnt
,
3416 spin_lock_irq(&phba
->hbalock
);
3417 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
3418 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
3420 /* release extra nvmet sgls from list */
3421 for (i
= 0; i
< xri_cnt
; i
++) {
3422 list_remove_head(&nvmet_sgl_list
,
3423 sglq_entry
, struct lpfc_sglq
, list
);
3425 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
,
3430 list_splice_init(&nvmet_sgl_list
,
3431 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
3432 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
3433 spin_unlock_irq(&phba
->hbalock
);
3435 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3436 "6306 NVMET xri-sgl count unchanged: %d\n",
3438 phba
->sli4_hba
.nvmet_xri_cnt
= nvmet_xri_cnt
;
3440 /* update xris to nvmet sgls on the list */
3442 sglq_entry_next
= NULL
;
3443 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
3444 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
, list
) {
3445 lxri
= lpfc_sli4_next_xritag(phba
);
3446 if (lxri
== NO_XRI
) {
3447 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3448 "6307 Failed to allocate xri for "
3453 sglq_entry
->sli4_lxritag
= lxri
;
3454 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3459 lpfc_free_nvmet_sgl_list(phba
);
3464 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3465 * @phba: pointer to lpfc hba data structure.
3467 * This routine first calculates the sizes of the current els and allocated
3468 * scsi sgl lists, and then goes through all sgls to updates the physical
3469 * XRIs assigned due to port function reset. During port initialization, the
3470 * current els and allocated scsi sgl lists are 0s.
3473 * 0 - successful (for now, it always returns 0)
3476 lpfc_sli4_scsi_sgl_update(struct lpfc_hba
*phba
)
3478 struct lpfc_scsi_buf
*psb
, *psb_next
;
3479 uint16_t i
, lxri
, els_xri_cnt
, scsi_xri_cnt
;
3480 LIST_HEAD(scsi_sgl_list
);
3484 * update on pci function's els xri-sgl list
3486 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3487 phba
->total_scsi_bufs
= 0;
3490 * update on pci function's allocated scsi xri-sgl list
3492 /* maximum number of xris available for scsi buffers */
3493 phba
->sli4_hba
.scsi_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
3496 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
3499 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
3500 phba
->sli4_hba
.scsi_xri_max
= /* Split them up */
3501 (phba
->sli4_hba
.scsi_xri_max
*
3502 phba
->cfg_xri_split
) / 100;
3504 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3505 spin_lock(&phba
->scsi_buf_list_put_lock
);
3506 list_splice_init(&phba
->lpfc_scsi_buf_list_get
, &scsi_sgl_list
);
3507 list_splice(&phba
->lpfc_scsi_buf_list_put
, &scsi_sgl_list
);
3508 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3509 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3511 if (phba
->sli4_hba
.scsi_xri_cnt
> phba
->sli4_hba
.scsi_xri_max
) {
3512 /* max scsi xri shrinked below the allocated scsi buffers */
3513 scsi_xri_cnt
= phba
->sli4_hba
.scsi_xri_cnt
-
3514 phba
->sli4_hba
.scsi_xri_max
;
3515 /* release the extra allocated scsi buffers */
3516 for (i
= 0; i
< scsi_xri_cnt
; i
++) {
3517 list_remove_head(&scsi_sgl_list
, psb
,
3518 struct lpfc_scsi_buf
, list
);
3520 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3521 psb
->data
, psb
->dma_handle
);
3525 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3526 phba
->sli4_hba
.scsi_xri_cnt
-= scsi_xri_cnt
;
3527 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3530 /* update xris associated to remaining allocated scsi buffers */
3533 list_for_each_entry_safe(psb
, psb_next
, &scsi_sgl_list
, list
) {
3534 lxri
= lpfc_sli4_next_xritag(phba
);
3535 if (lxri
== NO_XRI
) {
3536 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3537 "2560 Failed to allocate xri for "
3542 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
3543 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3545 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3546 spin_lock(&phba
->scsi_buf_list_put_lock
);
3547 list_splice_init(&scsi_sgl_list
, &phba
->lpfc_scsi_buf_list_get
);
3548 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
3549 spin_unlock(&phba
->scsi_buf_list_put_lock
);
3550 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3554 lpfc_scsi_free(phba
);
3559 lpfc_get_wwpn(struct lpfc_hba
*phba
)
3563 LPFC_MBOXQ_t
*mboxq
;
3567 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
3570 return (uint64_t)-1;
3572 /* First get WWN of HBA instance */
3573 lpfc_read_nv(phba
, mboxq
);
3574 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
3575 if (rc
!= MBX_SUCCESS
) {
3576 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3577 "6019 Mailbox failed , mbxCmd x%x "
3578 "READ_NV, mbxStatus x%x\n",
3579 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
3580 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
3581 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3582 return (uint64_t) -1;
3585 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.portname
, sizeof(uint64_t));
3586 /* wwn is WWPN of HBA instance */
3587 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3588 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3589 return be64_to_cpu(wwn
);
3591 return (((wwn
& 0xffffffff00000000) >> 32) |
3592 ((wwn
& 0x00000000ffffffff) << 32));
3597 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3598 * @phba: pointer to lpfc hba data structure.
3600 * This routine first calculates the sizes of the current els and allocated
3601 * scsi sgl lists, and then goes through all sgls to updates the physical
3602 * XRIs assigned due to port function reset. During port initialization, the
3603 * current els and allocated scsi sgl lists are 0s.
3606 * 0 - successful (for now, it always returns 0)
3609 lpfc_sli4_nvme_sgl_update(struct lpfc_hba
*phba
)
3611 struct lpfc_nvme_buf
*lpfc_ncmd
= NULL
, *lpfc_ncmd_next
= NULL
;
3612 uint16_t i
, lxri
, els_xri_cnt
;
3613 uint16_t nvme_xri_cnt
, nvme_xri_max
;
3614 LIST_HEAD(nvme_sgl_list
);
3617 phba
->total_nvme_bufs
= 0;
3619 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
))
3622 * update on pci function's allocated nvme xri-sgl list
3625 /* maximum number of xris available for nvme buffers */
3626 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
3627 nvme_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
3628 phba
->sli4_hba
.nvme_xri_max
= nvme_xri_max
;
3629 phba
->sli4_hba
.nvme_xri_max
-= phba
->sli4_hba
.scsi_xri_max
;
3631 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3632 "6074 Current allocated NVME xri-sgl count:%d, "
3633 "maximum NVME xri count:%d\n",
3634 phba
->sli4_hba
.nvme_xri_cnt
,
3635 phba
->sli4_hba
.nvme_xri_max
);
3637 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3638 spin_lock(&phba
->nvme_buf_list_put_lock
);
3639 list_splice_init(&phba
->lpfc_nvme_buf_list_get
, &nvme_sgl_list
);
3640 list_splice(&phba
->lpfc_nvme_buf_list_put
, &nvme_sgl_list
);
3641 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3642 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3644 if (phba
->sli4_hba
.nvme_xri_cnt
> phba
->sli4_hba
.nvme_xri_max
) {
3645 /* max nvme xri shrunk below the allocated nvme buffers */
3646 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3647 nvme_xri_cnt
= phba
->sli4_hba
.nvme_xri_cnt
-
3648 phba
->sli4_hba
.nvme_xri_max
;
3649 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3650 /* release the extra allocated nvme buffers */
3651 for (i
= 0; i
< nvme_xri_cnt
; i
++) {
3652 list_remove_head(&nvme_sgl_list
, lpfc_ncmd
,
3653 struct lpfc_nvme_buf
, list
);
3655 pci_pool_free(phba
->lpfc_sg_dma_buf_pool
,
3657 lpfc_ncmd
->dma_handle
);
3661 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3662 phba
->sli4_hba
.nvme_xri_cnt
-= nvme_xri_cnt
;
3663 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3666 /* update xris associated to remaining allocated nvme buffers */
3668 lpfc_ncmd_next
= NULL
;
3669 list_for_each_entry_safe(lpfc_ncmd
, lpfc_ncmd_next
,
3670 &nvme_sgl_list
, list
) {
3671 lxri
= lpfc_sli4_next_xritag(phba
);
3672 if (lxri
== NO_XRI
) {
3673 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3674 "6075 Failed to allocate xri for "
3679 lpfc_ncmd
->cur_iocbq
.sli4_lxritag
= lxri
;
3680 lpfc_ncmd
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3682 spin_lock_irq(&phba
->nvme_buf_list_get_lock
);
3683 spin_lock(&phba
->nvme_buf_list_put_lock
);
3684 list_splice_init(&nvme_sgl_list
, &phba
->lpfc_nvme_buf_list_get
);
3685 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_put
);
3686 spin_unlock(&phba
->nvme_buf_list_put_lock
);
3687 spin_unlock_irq(&phba
->nvme_buf_list_get_lock
);
3691 lpfc_nvme_free(phba
);
3696 * lpfc_create_port - Create an FC port
3697 * @phba: pointer to lpfc hba data structure.
3698 * @instance: a unique integer ID to this FC port.
3699 * @dev: pointer to the device data structure.
3701 * This routine creates a FC port for the upper layer protocol. The FC port
3702 * can be created on top of either a physical port or a virtual port provided
3703 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3704 * and associates the FC port created before adding the shost into the SCSI
3708 * @vport - pointer to the virtual N_Port data structure.
3709 * NULL - port create failed.
3712 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
3714 struct lpfc_vport
*vport
;
3715 struct Scsi_Host
*shost
= NULL
;
3719 bool use_no_reset_hba
= false;
3721 wwn
= lpfc_get_wwpn(phba
);
3723 for (i
= 0; i
< lpfc_no_hba_reset_cnt
; i
++) {
3724 if (wwn
== lpfc_no_hba_reset
[i
]) {
3725 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3726 "6020 Setting use_no_reset port=%llx\n",
3728 use_no_reset_hba
= true;
3733 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
3734 if (dev
!= &phba
->pcidev
->dev
) {
3735 shost
= scsi_host_alloc(&lpfc_vport_template
,
3736 sizeof(struct lpfc_vport
));
3738 if (!use_no_reset_hba
)
3739 shost
= scsi_host_alloc(&lpfc_template
,
3740 sizeof(struct lpfc_vport
));
3742 shost
= scsi_host_alloc(&lpfc_template_no_hr
,
3743 sizeof(struct lpfc_vport
));
3745 } else if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
3746 shost
= scsi_host_alloc(&lpfc_template_nvme
,
3747 sizeof(struct lpfc_vport
));
3752 vport
= (struct lpfc_vport
*) shost
->hostdata
;
3754 vport
->load_flag
|= FC_LOADING
;
3755 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3756 vport
->fc_rscn_flush
= 0;
3757 lpfc_get_vport_cfgparam(vport
);
3759 shost
->unique_id
= instance
;
3760 shost
->max_id
= LPFC_MAX_TARGET
;
3761 shost
->max_lun
= vport
->cfg_max_luns
;
3762 shost
->this_id
= -1;
3763 shost
->max_cmd_len
= 16;
3764 shost
->nr_hw_queues
= phba
->cfg_fcp_io_channel
;
3765 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3766 shost
->dma_boundary
=
3767 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
3768 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3772 * Set initial can_queue value since 0 is no longer supported and
3773 * scsi_add_host will fail. This will be adjusted later based on the
3774 * max xri value determined in hba setup.
3776 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
3777 if (dev
!= &phba
->pcidev
->dev
) {
3778 shost
->transportt
= lpfc_vport_transport_template
;
3779 vport
->port_type
= LPFC_NPIV_PORT
;
3781 shost
->transportt
= lpfc_transport_template
;
3782 vport
->port_type
= LPFC_PHYSICAL_PORT
;
3785 /* Initialize all internally managed lists. */
3786 INIT_LIST_HEAD(&vport
->fc_nodes
);
3787 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
3788 spin_lock_init(&vport
->work_port_lock
);
3790 setup_timer(&vport
->fc_disctmo
, lpfc_disc_timeout
,
3791 (unsigned long)vport
);
3793 setup_timer(&vport
->els_tmofunc
, lpfc_els_timeout
,
3794 (unsigned long)vport
);
3796 setup_timer(&vport
->delayed_disc_tmo
, lpfc_delayed_disc_tmo
,
3797 (unsigned long)vport
);
3799 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
3803 spin_lock_irq(&phba
->hbalock
);
3804 list_add_tail(&vport
->listentry
, &phba
->port_list
);
3805 spin_unlock_irq(&phba
->hbalock
);
3809 scsi_host_put(shost
);
3815 * destroy_port - destroy an FC port
3816 * @vport: pointer to an lpfc virtual N_Port data structure.
3818 * This routine destroys a FC port from the upper layer protocol. All the
3819 * resources associated with the port are released.
3822 destroy_port(struct lpfc_vport
*vport
)
3824 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3825 struct lpfc_hba
*phba
= vport
->phba
;
3827 lpfc_debugfs_terminate(vport
);
3828 fc_remove_host(shost
);
3829 scsi_remove_host(shost
);
3831 spin_lock_irq(&phba
->hbalock
);
3832 list_del_init(&vport
->listentry
);
3833 spin_unlock_irq(&phba
->hbalock
);
3835 lpfc_cleanup(vport
);
3840 * lpfc_get_instance - Get a unique integer ID
3842 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3843 * uses the kernel idr facility to perform the task.
3846 * instance - a unique integer ID allocated as the new instance.
3847 * -1 - lpfc get instance failed.
3850 lpfc_get_instance(void)
3854 ret
= idr_alloc(&lpfc_hba_index
, NULL
, 0, 0, GFP_KERNEL
);
3855 return ret
< 0 ? -1 : ret
;
3859 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3860 * @shost: pointer to SCSI host data structure.
3861 * @time: elapsed time of the scan in jiffies.
3863 * This routine is called by the SCSI layer with a SCSI host to determine
3864 * whether the scan host is finished.
3866 * Note: there is no scan_start function as adapter initialization will have
3867 * asynchronously kicked off the link initialization.
3870 * 0 - SCSI host scan is not over yet.
3871 * 1 - SCSI host scan is over.
3873 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
3875 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3876 struct lpfc_hba
*phba
= vport
->phba
;
3879 spin_lock_irq(shost
->host_lock
);
3881 if (vport
->load_flag
& FC_UNLOADING
) {
3885 if (time
>= msecs_to_jiffies(30 * 1000)) {
3886 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3887 "0461 Scanning longer than 30 "
3888 "seconds. Continuing initialization\n");
3892 if (time
>= msecs_to_jiffies(15 * 1000) &&
3893 phba
->link_state
<= LPFC_LINK_DOWN
) {
3894 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3895 "0465 Link down longer than 15 "
3896 "seconds. Continuing initialization\n");
3901 if (vport
->port_state
!= LPFC_VPORT_READY
)
3903 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
3905 if (vport
->fc_map_cnt
== 0 && time
< msecs_to_jiffies(2 * 1000))
3907 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
3913 spin_unlock_irq(shost
->host_lock
);
3918 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3919 * @shost: pointer to SCSI host data structure.
3921 * This routine initializes a given SCSI host attributes on a FC port. The
3922 * SCSI host can be either on top of a physical port or a virtual port.
3924 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
3926 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3927 struct lpfc_hba
*phba
= vport
->phba
;
3929 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3932 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
3933 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3934 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
3936 memset(fc_host_supported_fc4s(shost
), 0,
3937 sizeof(fc_host_supported_fc4s(shost
)));
3938 fc_host_supported_fc4s(shost
)[2] = 1;
3939 fc_host_supported_fc4s(shost
)[7] = 1;
3941 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
3942 sizeof fc_host_symbolic_name(shost
));
3944 fc_host_supported_speeds(shost
) = 0;
3945 if (phba
->lmt
& LMT_32Gb
)
3946 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_32GBIT
;
3947 if (phba
->lmt
& LMT_16Gb
)
3948 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
3949 if (phba
->lmt
& LMT_10Gb
)
3950 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
3951 if (phba
->lmt
& LMT_8Gb
)
3952 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
3953 if (phba
->lmt
& LMT_4Gb
)
3954 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
3955 if (phba
->lmt
& LMT_2Gb
)
3956 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
3957 if (phba
->lmt
& LMT_1Gb
)
3958 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
3960 fc_host_maxframe_size(shost
) =
3961 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
3962 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
3964 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
3966 /* This value is also unchanging */
3967 memset(fc_host_active_fc4s(shost
), 0,
3968 sizeof(fc_host_active_fc4s(shost
)));
3969 fc_host_active_fc4s(shost
)[2] = 1;
3970 fc_host_active_fc4s(shost
)[7] = 1;
3972 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
3973 spin_lock_irq(shost
->host_lock
);
3974 vport
->load_flag
&= ~FC_LOADING
;
3975 spin_unlock_irq(shost
->host_lock
);
3979 * lpfc_stop_port_s3 - Stop SLI3 device port
3980 * @phba: pointer to lpfc hba data structure.
3982 * This routine is invoked to stop an SLI3 device port, it stops the device
3983 * from generating interrupts and stops the device driver's timers for the
3987 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
3989 /* Clear all interrupt enable conditions */
3990 writel(0, phba
->HCregaddr
);
3991 readl(phba
->HCregaddr
); /* flush */
3992 /* Clear all pending interrupts */
3993 writel(0xffffffff, phba
->HAregaddr
);
3994 readl(phba
->HAregaddr
); /* flush */
3996 /* Reset some HBA SLI setup states */
3997 lpfc_stop_hba_timers(phba
);
3998 phba
->pport
->work_port_events
= 0;
4002 * lpfc_stop_port_s4 - Stop SLI4 device port
4003 * @phba: pointer to lpfc hba data structure.
4005 * This routine is invoked to stop an SLI4 device port, it stops the device
4006 * from generating interrupts and stops the device driver's timers for the
4010 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
4012 /* Reset some HBA SLI4 setup states */
4013 lpfc_stop_hba_timers(phba
);
4014 phba
->pport
->work_port_events
= 0;
4015 phba
->sli4_hba
.intr_enable
= 0;
4019 * lpfc_stop_port - Wrapper function for stopping hba port
4020 * @phba: Pointer to HBA context object.
4022 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4023 * the API jump table function pointer from the lpfc_hba struct.
4026 lpfc_stop_port(struct lpfc_hba
*phba
)
4028 phba
->lpfc_stop_port(phba
);
4032 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4033 * @phba: Pointer to hba for which this call is being executed.
4035 * This routine starts the timer waiting for the FCF rediscovery to complete.
4038 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
4040 unsigned long fcf_redisc_wait_tmo
=
4041 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
4042 /* Start fcf rediscovery wait period timer */
4043 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
4044 spin_lock_irq(&phba
->hbalock
);
4045 /* Allow action to new fcf asynchronous event */
4046 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
4047 /* Mark the FCF rediscovery pending state */
4048 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
4049 spin_unlock_irq(&phba
->hbalock
);
4053 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4054 * @ptr: Map to lpfc_hba data structure pointer.
4056 * This routine is invoked when waiting for FCF table rediscover has been
4057 * timed out. If new FCF record(s) has (have) been discovered during the
4058 * wait period, a new FCF event shall be added to the FCOE async event
4059 * list, and then worker thread shall be waked up for processing from the
4060 * worker thread context.
4063 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
4065 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
4067 /* Don't send FCF rediscovery event if timer cancelled */
4068 spin_lock_irq(&phba
->hbalock
);
4069 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
4070 spin_unlock_irq(&phba
->hbalock
);
4073 /* Clear FCF rediscovery timer pending flag */
4074 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
4075 /* FCF rediscovery event to worker thread */
4076 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
4077 spin_unlock_irq(&phba
->hbalock
);
4078 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
4079 "2776 FCF rediscover quiescent timer expired\n");
4080 /* wake up worker thread */
4081 lpfc_worker_wake_up(phba
);
4085 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4086 * @phba: pointer to lpfc hba data structure.
4087 * @acqe_link: pointer to the async link completion queue entry.
4089 * This routine is to parse the SLI4 link-attention link fault code and
4090 * translate it into the base driver's read link attention mailbox command
4093 * Return: Link-attention status in terms of base driver's coding.
4096 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
4097 struct lpfc_acqe_link
*acqe_link
)
4099 uint16_t latt_fault
;
4101 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
4102 case LPFC_ASYNC_LINK_FAULT_NONE
:
4103 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
4104 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
4108 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4109 "0398 Invalid link fault code: x%x\n",
4110 bf_get(lpfc_acqe_link_fault
, acqe_link
));
4111 latt_fault
= MBXERR_ERROR
;
4118 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4119 * @phba: pointer to lpfc hba data structure.
4120 * @acqe_link: pointer to the async link completion queue entry.
4122 * This routine is to parse the SLI4 link attention type and translate it
4123 * into the base driver's link attention type coding.
4125 * Return: Link attention type in terms of base driver's coding.
4128 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
4129 struct lpfc_acqe_link
*acqe_link
)
4133 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
4134 case LPFC_ASYNC_LINK_STATUS_DOWN
:
4135 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
4136 att_type
= LPFC_ATT_LINK_DOWN
;
4138 case LPFC_ASYNC_LINK_STATUS_UP
:
4139 /* Ignore physical link up events - wait for logical link up */
4140 att_type
= LPFC_ATT_RESERVED
;
4142 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
4143 att_type
= LPFC_ATT_LINK_UP
;
4146 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4147 "0399 Invalid link attention type: x%x\n",
4148 bf_get(lpfc_acqe_link_status
, acqe_link
));
4149 att_type
= LPFC_ATT_RESERVED
;
4156 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4157 * @phba: pointer to lpfc hba data structure.
4159 * This routine is to get an SLI3 FC port's link speed in Mbps.
4161 * Return: link speed in terms of Mbps.
4164 lpfc_sli_port_speed_get(struct lpfc_hba
*phba
)
4166 uint32_t link_speed
;
4168 if (!lpfc_is_link_up(phba
))
4171 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
4172 switch (phba
->fc_linkspeed
) {
4173 case LPFC_LINK_SPEED_1GHZ
:
4176 case LPFC_LINK_SPEED_2GHZ
:
4179 case LPFC_LINK_SPEED_4GHZ
:
4182 case LPFC_LINK_SPEED_8GHZ
:
4185 case LPFC_LINK_SPEED_10GHZ
:
4188 case LPFC_LINK_SPEED_16GHZ
:
4195 if (phba
->sli4_hba
.link_state
.logical_speed
)
4197 phba
->sli4_hba
.link_state
.logical_speed
;
4199 link_speed
= phba
->sli4_hba
.link_state
.speed
;
4205 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4206 * @phba: pointer to lpfc hba data structure.
4207 * @evt_code: asynchronous event code.
4208 * @speed_code: asynchronous event link speed code.
4210 * This routine is to parse the giving SLI4 async event link speed code into
4211 * value of Mbps for the link speed.
4213 * Return: link speed in terms of Mbps.
4216 lpfc_sli4_port_speed_parse(struct lpfc_hba
*phba
, uint32_t evt_code
,
4219 uint32_t port_speed
;
4222 case LPFC_TRAILER_CODE_LINK
:
4223 switch (speed_code
) {
4224 case LPFC_ASYNC_LINK_SPEED_ZERO
:
4227 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
4230 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
4233 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
4236 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
4239 case LPFC_ASYNC_LINK_SPEED_20GBPS
:
4242 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
4245 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
4252 case LPFC_TRAILER_CODE_FC
:
4253 switch (speed_code
) {
4254 case LPFC_FC_LA_SPEED_UNKNOWN
:
4257 case LPFC_FC_LA_SPEED_1G
:
4260 case LPFC_FC_LA_SPEED_2G
:
4263 case LPFC_FC_LA_SPEED_4G
:
4266 case LPFC_FC_LA_SPEED_8G
:
4269 case LPFC_FC_LA_SPEED_10G
:
4272 case LPFC_FC_LA_SPEED_16G
:
4275 case LPFC_FC_LA_SPEED_32G
:
4289 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
4290 * @phba: pointer to lpfc hba data structure.
4291 * @acqe_link: pointer to the async link completion queue entry.
4293 * This routine is to handle the SLI4 asynchronous FCoE link event.
4296 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
4297 struct lpfc_acqe_link
*acqe_link
)
4299 struct lpfc_dmabuf
*mp
;
4302 struct lpfc_mbx_read_top
*la
;
4306 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
4307 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
4309 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
4310 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4312 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4313 "0395 The mboxq allocation failed\n");
4316 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4318 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4319 "0396 The lpfc_dmabuf allocation failed\n");
4322 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
4324 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4325 "0397 The mbuf allocation failed\n");
4326 goto out_free_dmabuf
;
4329 /* Cleanup any outstanding ELS commands */
4330 lpfc_els_flush_all_cmd(phba
);
4332 /* Block ELS IOCBs until we have done process link event */
4333 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
4335 /* Update link event statistics */
4336 phba
->sli
.slistat
.link_event
++;
4338 /* Create lpfc_handle_latt mailbox command from link ACQE */
4339 lpfc_read_topology(phba
, pmb
, mp
);
4340 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
4341 pmb
->vport
= phba
->pport
;
4343 /* Keep the link status for extra SLI4 state machine reference */
4344 phba
->sli4_hba
.link_state
.speed
=
4345 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_LINK
,
4346 bf_get(lpfc_acqe_link_speed
, acqe_link
));
4347 phba
->sli4_hba
.link_state
.duplex
=
4348 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
4349 phba
->sli4_hba
.link_state
.status
=
4350 bf_get(lpfc_acqe_link_status
, acqe_link
);
4351 phba
->sli4_hba
.link_state
.type
=
4352 bf_get(lpfc_acqe_link_type
, acqe_link
);
4353 phba
->sli4_hba
.link_state
.number
=
4354 bf_get(lpfc_acqe_link_number
, acqe_link
);
4355 phba
->sli4_hba
.link_state
.fault
=
4356 bf_get(lpfc_acqe_link_fault
, acqe_link
);
4357 phba
->sli4_hba
.link_state
.logical_speed
=
4358 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
) * 10;
4360 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4361 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4362 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4363 "Logical speed:%dMbps Fault:%d\n",
4364 phba
->sli4_hba
.link_state
.speed
,
4365 phba
->sli4_hba
.link_state
.topology
,
4366 phba
->sli4_hba
.link_state
.status
,
4367 phba
->sli4_hba
.link_state
.type
,
4368 phba
->sli4_hba
.link_state
.number
,
4369 phba
->sli4_hba
.link_state
.logical_speed
,
4370 phba
->sli4_hba
.link_state
.fault
);
4372 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4373 * topology info. Note: Optional for non FC-AL ports.
4375 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
4376 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4377 if (rc
== MBX_NOT_FINISHED
)
4378 goto out_free_dmabuf
;
4382 * For FCoE Mode: fill in all the topology information we need and call
4383 * the READ_TOPOLOGY completion routine to continue without actually
4384 * sending the READ_TOPOLOGY mailbox command to the port.
4386 /* Parse and translate status field */
4388 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
4390 /* Parse and translate link attention fields */
4391 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
4392 la
->eventTag
= acqe_link
->event_tag
;
4393 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
4394 bf_set(lpfc_mbx_read_top_link_spd
, la
,
4395 (bf_get(lpfc_acqe_link_speed
, acqe_link
)));
4397 /* Fake the the following irrelvant fields */
4398 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
4399 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
4400 bf_set(lpfc_mbx_read_top_il
, la
, 0);
4401 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
4402 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
4403 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
4405 /* Invoke the lpfc_handle_latt mailbox command callback function */
4406 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
4413 mempool_free(pmb
, phba
->mbox_mem_pool
);
4417 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4418 * @phba: pointer to lpfc hba data structure.
4419 * @acqe_fc: pointer to the async fc completion queue entry.
4421 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4422 * that the event was received and then issue a read_topology mailbox command so
4423 * that the rest of the driver will treat it the same as SLI3.
4426 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
4428 struct lpfc_dmabuf
*mp
;
4431 struct lpfc_mbx_read_top
*la
;
4434 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
4435 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
4436 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4437 "2895 Non FC link Event detected.(%d)\n",
4438 bf_get(lpfc_trailer_type
, acqe_fc
));
4441 /* Keep the link status for extra SLI4 state machine reference */
4442 phba
->sli4_hba
.link_state
.speed
=
4443 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
4444 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
4445 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
4446 phba
->sli4_hba
.link_state
.topology
=
4447 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
4448 phba
->sli4_hba
.link_state
.status
=
4449 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
4450 phba
->sli4_hba
.link_state
.type
=
4451 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
4452 phba
->sli4_hba
.link_state
.number
=
4453 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
4454 phba
->sli4_hba
.link_state
.fault
=
4455 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
4456 phba
->sli4_hba
.link_state
.logical_speed
=
4457 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
4458 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4459 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4460 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4461 "%dMbps Fault:%d\n",
4462 phba
->sli4_hba
.link_state
.speed
,
4463 phba
->sli4_hba
.link_state
.topology
,
4464 phba
->sli4_hba
.link_state
.status
,
4465 phba
->sli4_hba
.link_state
.type
,
4466 phba
->sli4_hba
.link_state
.number
,
4467 phba
->sli4_hba
.link_state
.logical_speed
,
4468 phba
->sli4_hba
.link_state
.fault
);
4469 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4471 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4472 "2897 The mboxq allocation failed\n");
4475 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4477 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4478 "2898 The lpfc_dmabuf allocation failed\n");
4481 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
4483 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4484 "2899 The mbuf allocation failed\n");
4485 goto out_free_dmabuf
;
4488 /* Cleanup any outstanding ELS commands */
4489 lpfc_els_flush_all_cmd(phba
);
4491 /* Block ELS IOCBs until we have done process link event */
4492 phba
->sli4_hba
.els_wq
->pring
->flag
|= LPFC_STOP_IOCB_EVENT
;
4494 /* Update link event statistics */
4495 phba
->sli
.slistat
.link_event
++;
4497 /* Create lpfc_handle_latt mailbox command from link ACQE */
4498 lpfc_read_topology(phba
, pmb
, mp
);
4499 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
4500 pmb
->vport
= phba
->pport
;
4502 if (phba
->sli4_hba
.link_state
.status
!= LPFC_FC_LA_TYPE_LINK_UP
) {
4503 /* Parse and translate status field */
4505 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
,
4508 /* Parse and translate link attention fields */
4509 la
= (struct lpfc_mbx_read_top
*)&pmb
->u
.mb
.un
.varReadTop
;
4510 la
->eventTag
= acqe_fc
->event_tag
;
4511 bf_set(lpfc_mbx_read_top_att_type
, la
,
4512 LPFC_FC_LA_TYPE_LINK_DOWN
);
4514 /* Invoke the mailbox command callback function */
4515 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
4520 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4521 if (rc
== MBX_NOT_FINISHED
)
4522 goto out_free_dmabuf
;
4528 mempool_free(pmb
, phba
->mbox_mem_pool
);
4532 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4533 * @phba: pointer to lpfc hba data structure.
4534 * @acqe_fc: pointer to the async SLI completion queue entry.
4536 * This routine is to handle the SLI4 asynchronous SLI events.
4539 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
4545 uint8_t operational
= 0;
4546 struct temp_event temp_event_data
;
4547 struct lpfc_acqe_misconfigured_event
*misconfigured
;
4548 struct Scsi_Host
*shost
;
4550 evt_type
= bf_get(lpfc_trailer_type
, acqe_sli
);
4552 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4553 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4554 "x%08x SLI Event Type:%d\n",
4555 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
4558 port_name
= phba
->Port
[0];
4559 if (port_name
== 0x00)
4560 port_name
= '?'; /* get port name is empty */
4563 case LPFC_SLI_EVENT_TYPE_OVER_TEMP
:
4564 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
4565 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
4566 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
4568 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4569 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4570 acqe_sli
->event_data1
, port_name
);
4572 phba
->sfp_warning
|= LPFC_TRANSGRESSION_HIGH_TEMPERATURE
;
4573 shost
= lpfc_shost_from_vport(phba
->pport
);
4574 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4575 sizeof(temp_event_data
),
4576 (char *)&temp_event_data
,
4577 SCSI_NL_VID_TYPE_PCI
4578 | PCI_VENDOR_ID_EMULEX
);
4580 case LPFC_SLI_EVENT_TYPE_NORM_TEMP
:
4581 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
4582 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
4583 temp_event_data
.data
= (uint32_t)acqe_sli
->event_data1
;
4585 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4586 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4587 acqe_sli
->event_data1
, port_name
);
4589 shost
= lpfc_shost_from_vport(phba
->pport
);
4590 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4591 sizeof(temp_event_data
),
4592 (char *)&temp_event_data
,
4593 SCSI_NL_VID_TYPE_PCI
4594 | PCI_VENDOR_ID_EMULEX
);
4596 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED
:
4597 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
4598 &acqe_sli
->event_data1
;
4600 /* fetch the status for this port */
4601 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4602 case LPFC_LINK_NUMBER_0
:
4603 status
= bf_get(lpfc_sli_misconfigured_port0_state
,
4604 &misconfigured
->theEvent
);
4605 operational
= bf_get(lpfc_sli_misconfigured_port0_op
,
4606 &misconfigured
->theEvent
);
4608 case LPFC_LINK_NUMBER_1
:
4609 status
= bf_get(lpfc_sli_misconfigured_port1_state
,
4610 &misconfigured
->theEvent
);
4611 operational
= bf_get(lpfc_sli_misconfigured_port1_op
,
4612 &misconfigured
->theEvent
);
4614 case LPFC_LINK_NUMBER_2
:
4615 status
= bf_get(lpfc_sli_misconfigured_port2_state
,
4616 &misconfigured
->theEvent
);
4617 operational
= bf_get(lpfc_sli_misconfigured_port2_op
,
4618 &misconfigured
->theEvent
);
4620 case LPFC_LINK_NUMBER_3
:
4621 status
= bf_get(lpfc_sli_misconfigured_port3_state
,
4622 &misconfigured
->theEvent
);
4623 operational
= bf_get(lpfc_sli_misconfigured_port3_op
,
4624 &misconfigured
->theEvent
);
4627 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4629 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4630 "event: Invalid link %d",
4631 phba
->sli4_hba
.lnk_info
.lnk_no
);
4635 /* Skip if optic state unchanged */
4636 if (phba
->sli4_hba
.lnk_info
.optic_state
== status
)
4640 case LPFC_SLI_EVENT_STATUS_VALID
:
4641 sprintf(message
, "Physical Link is functional");
4643 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
4644 sprintf(message
, "Optics faulted/incorrectly "
4645 "installed/not installed - Reseat optics, "
4646 "if issue not resolved, replace.");
4648 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
4650 "Optics of two types installed - Remove one "
4651 "optic or install matching pair of optics.");
4653 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
4654 sprintf(message
, "Incompatible optics - Replace with "
4655 "compatible optics for card to function.");
4657 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED
:
4658 sprintf(message
, "Unqualified optics - Replace with "
4659 "Avago optics for Warranty and Technical "
4660 "Support - Link is%s operational",
4661 (operational
) ? " not" : "");
4663 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED
:
4664 sprintf(message
, "Uncertified optics - Replace with "
4665 "Avago-certified optics to enable link "
4666 "operation - Link is%s operational",
4667 (operational
) ? " not" : "");
4670 /* firmware is reporting a status we don't know about */
4671 sprintf(message
, "Unknown event status x%02x", status
);
4674 phba
->sli4_hba
.lnk_info
.optic_state
= status
;
4675 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4676 "3176 Port Name %c %s\n", port_name
, message
);
4678 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT
:
4679 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4680 "3192 Remote DPort Test Initiated - "
4681 "Event Data1:x%08x Event Data2: x%08x\n",
4682 acqe_sli
->event_data1
, acqe_sli
->event_data2
);
4685 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4686 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4687 "x%08x SLI Event Type:%d\n",
4688 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
4695 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4696 * @vport: pointer to vport data structure.
4698 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4699 * response to a CVL event.
4701 * Return the pointer to the ndlp with the vport if successful, otherwise
4704 static struct lpfc_nodelist
*
4705 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
4707 struct lpfc_nodelist
*ndlp
;
4708 struct Scsi_Host
*shost
;
4709 struct lpfc_hba
*phba
;
4716 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
4718 /* Cannot find existing Fabric ndlp, so allocate a new one */
4719 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4722 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
4723 /* Set the node type */
4724 ndlp
->nlp_type
|= NLP_FABRIC
;
4725 /* Put ndlp onto node list */
4726 lpfc_enqueue_node(vport
, ndlp
);
4727 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4728 /* re-setup ndlp without removing from node list */
4729 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4733 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
4734 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
4736 /* If virtual link is not yet instantiated ignore CVL */
4737 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
4738 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
4740 shost
= lpfc_shost_from_vport(vport
);
4743 lpfc_linkdown_port(vport
);
4744 lpfc_cleanup_pending_mbox(vport
);
4745 spin_lock_irq(shost
->host_lock
);
4746 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
4747 spin_unlock_irq(shost
->host_lock
);
4753 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4754 * @vport: pointer to lpfc hba data structure.
4756 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4757 * response to a FCF dead event.
4760 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
4762 struct lpfc_vport
**vports
;
4765 vports
= lpfc_create_vport_work_array(phba
);
4767 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
4768 lpfc_sli4_perform_vport_cvl(vports
[i
]);
4769 lpfc_destroy_vport_work_array(phba
, vports
);
4773 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4774 * @phba: pointer to lpfc hba data structure.
4775 * @acqe_link: pointer to the async fcoe completion queue entry.
4777 * This routine is to handle the SLI4 asynchronous fcoe event.
4780 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
4781 struct lpfc_acqe_fip
*acqe_fip
)
4783 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
4785 struct lpfc_vport
*vport
;
4786 struct lpfc_nodelist
*ndlp
;
4787 struct Scsi_Host
*shost
;
4788 int active_vlink_present
;
4789 struct lpfc_vport
**vports
;
4792 phba
->fc_eventTag
= acqe_fip
->event_tag
;
4793 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
4794 switch (event_type
) {
4795 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
4796 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
4797 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
4798 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4800 "2546 New FCF event, evt_tag:x%x, "
4802 acqe_fip
->event_tag
,
4805 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
4807 "2788 FCF param modified event, "
4808 "evt_tag:x%x, index:x%x\n",
4809 acqe_fip
->event_tag
,
4811 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4813 * During period of FCF discovery, read the FCF
4814 * table record indexed by the event to update
4815 * FCF roundrobin failover eligible FCF bmask.
4817 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4819 "2779 Read FCF (x%x) for updating "
4820 "roundrobin FCF failover bmask\n",
4822 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
4825 /* If the FCF discovery is in progress, do nothing. */
4826 spin_lock_irq(&phba
->hbalock
);
4827 if (phba
->hba_flag
& FCF_TS_INPROG
) {
4828 spin_unlock_irq(&phba
->hbalock
);
4831 /* If fast FCF failover rescan event is pending, do nothing */
4832 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
4833 spin_unlock_irq(&phba
->hbalock
);
4837 /* If the FCF has been in discovered state, do nothing. */
4838 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
4839 spin_unlock_irq(&phba
->hbalock
);
4842 spin_unlock_irq(&phba
->hbalock
);
4844 /* Otherwise, scan the entire FCF table and re-discover SAN */
4845 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4846 "2770 Start FCF table scan per async FCF "
4847 "event, evt_tag:x%x, index:x%x\n",
4848 acqe_fip
->event_tag
, acqe_fip
->index
);
4849 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
4850 LPFC_FCOE_FCF_GET_FIRST
);
4852 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4853 "2547 Issue FCF scan read FCF mailbox "
4854 "command failed (x%x)\n", rc
);
4857 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
4858 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4859 "2548 FCF Table full count 0x%x tag 0x%x\n",
4860 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
4861 acqe_fip
->event_tag
);
4864 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
4865 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4866 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4867 "2549 FCF (x%x) disconnected from network, "
4868 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4870 * If we are in the middle of FCF failover process, clear
4871 * the corresponding FCF bit in the roundrobin bitmap.
4873 spin_lock_irq(&phba
->hbalock
);
4874 if ((phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
4875 (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)) {
4876 spin_unlock_irq(&phba
->hbalock
);
4877 /* Update FLOGI FCF failover eligible FCF bmask */
4878 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
4881 spin_unlock_irq(&phba
->hbalock
);
4883 /* If the event is not for currently used fcf do nothing */
4884 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
4888 * Otherwise, request the port to rediscover the entire FCF
4889 * table for a fast recovery from case that the current FCF
4890 * is no longer valid as we are not in the middle of FCF
4891 * failover process already.
4893 spin_lock_irq(&phba
->hbalock
);
4894 /* Mark the fast failover process in progress */
4895 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
4896 spin_unlock_irq(&phba
->hbalock
);
4898 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4899 "2771 Start FCF fast failover process due to "
4900 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4901 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
4902 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4904 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4906 "2772 Issue FCF rediscover mabilbox "
4907 "command failed, fail through to FCF "
4909 spin_lock_irq(&phba
->hbalock
);
4910 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
4911 spin_unlock_irq(&phba
->hbalock
);
4913 * Last resort will fail over by treating this
4914 * as a link down to FCF registration.
4916 lpfc_sli4_fcf_dead_failthrough(phba
);
4918 /* Reset FCF roundrobin bmask for new discovery */
4919 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4921 * Handling fast FCF failover to a DEAD FCF event is
4922 * considered equalivant to receiving CVL to all vports.
4924 lpfc_sli4_perform_all_vport_cvl(phba
);
4927 case LPFC_FIP_EVENT_TYPE_CVL
:
4928 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4929 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4930 "2718 Clear Virtual Link Received for VPI 0x%x"
4931 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4933 vport
= lpfc_find_vport_by_vpid(phba
,
4935 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
4938 active_vlink_present
= 0;
4940 vports
= lpfc_create_vport_work_array(phba
);
4942 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
4944 if ((!(vports
[i
]->fc_flag
&
4945 FC_VPORT_CVL_RCVD
)) &&
4946 (vports
[i
]->port_state
> LPFC_FDISC
)) {
4947 active_vlink_present
= 1;
4951 lpfc_destroy_vport_work_array(phba
, vports
);
4955 * Don't re-instantiate if vport is marked for deletion.
4956 * If we are here first then vport_delete is going to wait
4957 * for discovery to complete.
4959 if (!(vport
->load_flag
& FC_UNLOADING
) &&
4960 active_vlink_present
) {
4962 * If there are other active VLinks present,
4963 * re-instantiate the Vlink using FDISC.
4965 mod_timer(&ndlp
->nlp_delayfunc
,
4966 jiffies
+ msecs_to_jiffies(1000));
4967 shost
= lpfc_shost_from_vport(vport
);
4968 spin_lock_irq(shost
->host_lock
);
4969 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
4970 spin_unlock_irq(shost
->host_lock
);
4971 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
4972 vport
->port_state
= LPFC_FDISC
;
4975 * Otherwise, we request port to rediscover
4976 * the entire FCF table for a fast recovery
4977 * from possible case that the current FCF
4978 * is no longer valid if we are not already
4979 * in the FCF failover process.
4981 spin_lock_irq(&phba
->hbalock
);
4982 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4983 spin_unlock_irq(&phba
->hbalock
);
4986 /* Mark the fast failover process in progress */
4987 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
4988 spin_unlock_irq(&phba
->hbalock
);
4989 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4991 "2773 Start FCF failover per CVL, "
4992 "evt_tag:x%x\n", acqe_fip
->event_tag
);
4993 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4995 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4997 "2774 Issue FCF rediscover "
4998 "mabilbox command failed, "
4999 "through to CVL event\n");
5000 spin_lock_irq(&phba
->hbalock
);
5001 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
5002 spin_unlock_irq(&phba
->hbalock
);
5004 * Last resort will be re-try on the
5005 * the current registered FCF entry.
5007 lpfc_retry_pport_discovery(phba
);
5010 * Reset FCF roundrobin bmask for new
5013 lpfc_sli4_clear_fcf_rr_bmask(phba
);
5017 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5018 "0288 Unknown FCoE event type 0x%x event tag "
5019 "0x%x\n", event_type
, acqe_fip
->event_tag
);
5025 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5026 * @phba: pointer to lpfc hba data structure.
5027 * @acqe_link: pointer to the async dcbx completion queue entry.
5029 * This routine is to handle the SLI4 asynchronous dcbx event.
5032 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
5033 struct lpfc_acqe_dcbx
*acqe_dcbx
)
5035 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
5036 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5037 "0290 The SLI4 DCBX asynchronous event is not "
5042 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5043 * @phba: pointer to lpfc hba data structure.
5044 * @acqe_link: pointer to the async grp5 completion queue entry.
5046 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5047 * is an asynchronous notified of a logical link speed change. The Port
5048 * reports the logical link speed in units of 10Mbps.
5051 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
5052 struct lpfc_acqe_grp5
*acqe_grp5
)
5054 uint16_t prev_ll_spd
;
5056 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
5057 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
5058 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
5059 phba
->sli4_hba
.link_state
.logical_speed
=
5060 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
)) * 10;
5061 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5062 "2789 GRP5 Async Event: Updating logical link speed "
5063 "from %dMbps to %dMbps\n", prev_ll_spd
,
5064 phba
->sli4_hba
.link_state
.logical_speed
);
5068 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5069 * @phba: pointer to lpfc hba data structure.
5071 * This routine is invoked by the worker thread to process all the pending
5072 * SLI4 asynchronous events.
5074 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
5076 struct lpfc_cq_event
*cq_event
;
5078 /* First, declare the async event has been handled */
5079 spin_lock_irq(&phba
->hbalock
);
5080 phba
->hba_flag
&= ~ASYNC_EVENT
;
5081 spin_unlock_irq(&phba
->hbalock
);
5082 /* Now, handle all the async events */
5083 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
5084 /* Get the first event from the head of the event queue */
5085 spin_lock_irq(&phba
->hbalock
);
5086 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
5087 cq_event
, struct lpfc_cq_event
, list
);
5088 spin_unlock_irq(&phba
->hbalock
);
5089 /* Process the asynchronous event */
5090 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
5091 case LPFC_TRAILER_CODE_LINK
:
5092 lpfc_sli4_async_link_evt(phba
,
5093 &cq_event
->cqe
.acqe_link
);
5095 case LPFC_TRAILER_CODE_FCOE
:
5096 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
5098 case LPFC_TRAILER_CODE_DCBX
:
5099 lpfc_sli4_async_dcbx_evt(phba
,
5100 &cq_event
->cqe
.acqe_dcbx
);
5102 case LPFC_TRAILER_CODE_GRP5
:
5103 lpfc_sli4_async_grp5_evt(phba
,
5104 &cq_event
->cqe
.acqe_grp5
);
5106 case LPFC_TRAILER_CODE_FC
:
5107 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
5109 case LPFC_TRAILER_CODE_SLI
:
5110 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
5113 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5114 "1804 Invalid asynchrous event code: "
5115 "x%x\n", bf_get(lpfc_trailer_code
,
5116 &cq_event
->cqe
.mcqe_cmpl
));
5119 /* Free the completion event processed to the free pool */
5120 lpfc_sli4_cq_event_release(phba
, cq_event
);
5125 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5126 * @phba: pointer to lpfc hba data structure.
5128 * This routine is invoked by the worker thread to process FCF table
5129 * rediscovery pending completion event.
5131 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
5135 spin_lock_irq(&phba
->hbalock
);
5136 /* Clear FCF rediscovery timeout event */
5137 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
5138 /* Clear driver fast failover FCF record flag */
5139 phba
->fcf
.failover_rec
.flag
= 0;
5140 /* Set state for FCF fast failover */
5141 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
5142 spin_unlock_irq(&phba
->hbalock
);
5144 /* Scan FCF table from the first entry to re-discover SAN */
5145 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
5146 "2777 Start post-quiescent FCF table scan\n");
5147 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
5149 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
5150 "2747 Issue FCF scan read FCF mailbox "
5151 "command failed 0x%x\n", rc
);
5155 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5156 * @phba: pointer to lpfc hba data structure.
5157 * @dev_grp: The HBA PCI-Device group number.
5159 * This routine is invoked to set up the per HBA PCI-Device group function
5160 * API jump table entries.
5162 * Return: 0 if success, otherwise -ENODEV
5165 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5169 /* Set up lpfc PCI-device group */
5170 phba
->pci_dev_grp
= dev_grp
;
5172 /* The LPFC_PCI_DEV_OC uses SLI4 */
5173 if (dev_grp
== LPFC_PCI_DEV_OC
)
5174 phba
->sli_rev
= LPFC_SLI_REV4
;
5176 /* Set up device INIT API function jump table */
5177 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
5180 /* Set up SCSI API function jump table */
5181 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
5184 /* Set up SLI API function jump table */
5185 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
5188 /* Set up MBOX API function jump table */
5189 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
5197 * lpfc_log_intr_mode - Log the active interrupt mode
5198 * @phba: pointer to lpfc hba data structure.
5199 * @intr_mode: active interrupt mode adopted.
5201 * This routine it invoked to log the currently used active interrupt mode
5204 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
5206 switch (intr_mode
) {
5208 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5209 "0470 Enable INTx interrupt mode.\n");
5212 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5213 "0481 Enabled MSI interrupt mode.\n");
5216 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5217 "0480 Enabled MSI-X interrupt mode.\n");
5220 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5221 "0482 Illegal interrupt mode.\n");
5228 * lpfc_enable_pci_dev - Enable a generic PCI device.
5229 * @phba: pointer to lpfc hba data structure.
5231 * This routine is invoked to enable the PCI device that is common to all
5236 * other values - error
5239 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
5241 struct pci_dev
*pdev
;
5243 /* Obtain PCI device reference */
5247 pdev
= phba
->pcidev
;
5248 /* Enable PCI device */
5249 if (pci_enable_device_mem(pdev
))
5251 /* Request PCI resource for the device */
5252 if (pci_request_mem_regions(pdev
, LPFC_DRIVER_NAME
))
5253 goto out_disable_device
;
5254 /* Set up device as PCI master and save state for EEH */
5255 pci_set_master(pdev
);
5256 pci_try_set_mwi(pdev
);
5257 pci_save_state(pdev
);
5259 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5260 if (pci_is_pcie(pdev
))
5261 pdev
->needs_freset
= 1;
5266 pci_disable_device(pdev
);
5268 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5269 "1401 Failed to enable pci device\n");
5274 * lpfc_disable_pci_dev - Disable a generic PCI device.
5275 * @phba: pointer to lpfc hba data structure.
5277 * This routine is invoked to disable the PCI device that is common to all
5281 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
5283 struct pci_dev
*pdev
;
5285 /* Obtain PCI device reference */
5289 pdev
= phba
->pcidev
;
5290 /* Release PCI resource and disable PCI device */
5291 pci_release_mem_regions(pdev
);
5292 pci_disable_device(pdev
);
5298 * lpfc_reset_hba - Reset a hba
5299 * @phba: pointer to lpfc hba data structure.
5301 * This routine is invoked to reset a hba device. It brings the HBA
5302 * offline, performs a board restart, and then brings the board back
5303 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5304 * on outstanding mailbox commands.
5307 lpfc_reset_hba(struct lpfc_hba
*phba
)
5309 /* If resets are disabled then set error state and return. */
5310 if (!phba
->cfg_enable_hba_reset
) {
5311 phba
->link_state
= LPFC_HBA_ERROR
;
5314 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
5315 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
5317 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
5319 lpfc_sli_brdrestart(phba
);
5321 lpfc_unblock_mgmt_io(phba
);
5325 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5326 * @phba: pointer to lpfc hba data structure.
5328 * This function enables the PCI SR-IOV virtual functions to a physical
5329 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5330 * enable the number of virtual functions to the physical function. As
5331 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5332 * API call does not considered as an error condition for most of the device.
5335 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
5337 struct pci_dev
*pdev
= phba
->pcidev
;
5341 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
5345 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
5350 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5351 * @phba: pointer to lpfc hba data structure.
5352 * @nr_vfn: number of virtual functions to be enabled.
5354 * This function enables the PCI SR-IOV virtual functions to a physical
5355 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5356 * enable the number of virtual functions to the physical function. As
5357 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5358 * API call does not considered as an error condition for most of the device.
5361 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
5363 struct pci_dev
*pdev
= phba
->pcidev
;
5364 uint16_t max_nr_vfn
;
5367 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
5368 if (nr_vfn
> max_nr_vfn
) {
5369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5370 "3057 Requested vfs (%d) greater than "
5371 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
5375 rc
= pci_enable_sriov(pdev
, nr_vfn
);
5377 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5378 "2806 Failed to enable sriov on this device "
5379 "with vfn number nr_vf:%d, rc:%d\n",
5382 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5383 "2807 Successful enable sriov on this device "
5384 "with vfn number nr_vf:%d\n", nr_vfn
);
5389 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5390 * @phba: pointer to lpfc hba data structure.
5392 * This routine is invoked to set up the driver internal resources before the
5393 * device specific resource setup to support the HBA device it attached to.
5397 * other values - error
5400 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
5402 struct lpfc_sli
*psli
= &phba
->sli
;
5405 * Driver resources common to all SLI revisions
5407 atomic_set(&phba
->fast_event_count
, 0);
5408 spin_lock_init(&phba
->hbalock
);
5410 /* Initialize ndlp management spinlock */
5411 spin_lock_init(&phba
->ndlp_lock
);
5413 INIT_LIST_HEAD(&phba
->port_list
);
5414 INIT_LIST_HEAD(&phba
->work_list
);
5415 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
5417 /* Initialize the wait queue head for the kernel thread */
5418 init_waitqueue_head(&phba
->work_waitq
);
5420 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5421 "1403 Protocols supported %s %s %s\n",
5422 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) ?
5424 ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) ?
5426 (phba
->nvmet_support
? "NVMET" : " "));
5428 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
5429 /* Initialize the scsi buffer list used by driver for scsi IO */
5430 spin_lock_init(&phba
->scsi_buf_list_get_lock
);
5431 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_get
);
5432 spin_lock_init(&phba
->scsi_buf_list_put_lock
);
5433 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
5436 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
5437 (phba
->nvmet_support
== 0)) {
5438 /* Initialize the NVME buffer list used by driver for NVME IO */
5439 spin_lock_init(&phba
->nvme_buf_list_get_lock
);
5440 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_get
);
5441 spin_lock_init(&phba
->nvme_buf_list_put_lock
);
5442 INIT_LIST_HEAD(&phba
->lpfc_nvme_buf_list_put
);
5445 /* Initialize the fabric iocb list */
5446 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
5448 /* Initialize list to save ELS buffers */
5449 INIT_LIST_HEAD(&phba
->elsbuf
);
5451 /* Initialize FCF connection rec list */
5452 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
5454 /* Initialize OAS configuration list */
5455 spin_lock_init(&phba
->devicelock
);
5456 INIT_LIST_HEAD(&phba
->luns
);
5458 /* MBOX heartbeat timer */
5459 setup_timer(&psli
->mbox_tmo
, lpfc_mbox_timeout
, (unsigned long)phba
);
5460 /* Fabric block timer */
5461 setup_timer(&phba
->fabric_block_timer
, lpfc_fabric_block_timeout
,
5462 (unsigned long)phba
);
5463 /* EA polling mode timer */
5464 setup_timer(&phba
->eratt_poll
, lpfc_poll_eratt
,
5465 (unsigned long)phba
);
5466 /* Heartbeat timer */
5467 setup_timer(&phba
->hb_tmofunc
, lpfc_hb_timeout
, (unsigned long)phba
);
5473 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5474 * @phba: pointer to lpfc hba data structure.
5476 * This routine is invoked to set up the driver internal resources specific to
5477 * support the SLI-3 HBA device it attached to.
5481 * other values - error
5484 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
5489 * Initialize timers used by driver
5492 /* FCP polling mode timer */
5493 setup_timer(&phba
->fcp_poll_timer
, lpfc_poll_timeout
,
5494 (unsigned long)phba
);
5496 /* Host attention work mask setup */
5497 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
5498 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
5500 /* Get all the module params for configuring this host */
5501 lpfc_get_cfgparam(phba
);
5502 /* Set up phase-1 common device driver resources */
5504 rc
= lpfc_setup_driver_resource_phase1(phba
);
5508 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
5509 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
5510 /* check for menlo minimum sg count */
5511 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
5512 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
5515 if (!phba
->sli
.sli3_ring
)
5516 phba
->sli
.sli3_ring
= kzalloc(LPFC_SLI3_MAX_RING
*
5517 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
5518 if (!phba
->sli
.sli3_ring
)
5522 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
5523 * used to create the sg_dma_buf_pool must be dynamically calculated.
5526 /* Initialize the host templates the configured values. */
5527 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5528 lpfc_template_no_hr
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5529 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5531 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5532 if (phba
->cfg_enable_bg
) {
5534 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5535 * the FCP rsp, and a BDE for each. Sice we have no control
5536 * over how many protection data segments the SCSI Layer
5537 * will hand us (ie: there could be one for every block
5538 * in the IO), we just allocate enough BDEs to accomidate
5539 * our max amount and we need to limit lpfc_sg_seg_cnt to
5540 * minimize the risk of running out.
5542 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5543 sizeof(struct fcp_rsp
) +
5544 (LPFC_MAX_SG_SEG_CNT
* sizeof(struct ulp_bde64
));
5546 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SEG_CNT_DIF
)
5547 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT_DIF
;
5549 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5550 phba
->cfg_total_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
5553 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5554 * the FCP rsp, a BDE for each, and a BDE for up to
5555 * cfg_sg_seg_cnt data segments.
5557 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5558 sizeof(struct fcp_rsp
) +
5559 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
5561 /* Total BDEs in BPL for scsi_sg_list */
5562 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
5565 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
5566 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5567 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
5568 phba
->cfg_total_seg_cnt
);
5570 phba
->max_vpi
= LPFC_MAX_VPI
;
5571 /* This will be set to correct value after config_port mbox */
5572 phba
->max_vports
= 0;
5575 * Initialize the SLI Layer to run with lpfc HBAs.
5577 lpfc_sli_setup(phba
);
5578 lpfc_sli_queue_init(phba
);
5580 /* Allocate device driver memory */
5581 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
5585 * Enable sr-iov virtual functions if supported and configured
5586 * through the module parameter.
5588 if (phba
->cfg_sriov_nr_virtfn
> 0) {
5589 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
5590 phba
->cfg_sriov_nr_virtfn
);
5592 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5593 "2808 Requested number of SR-IOV "
5594 "virtual functions (%d) is not "
5596 phba
->cfg_sriov_nr_virtfn
);
5597 phba
->cfg_sriov_nr_virtfn
= 0;
5605 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5606 * @phba: pointer to lpfc hba data structure.
5608 * This routine is invoked to unset the driver internal resources set up
5609 * specific for supporting the SLI-3 HBA device it attached to.
5612 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
5614 /* Free device driver memory allocated */
5615 lpfc_mem_free_all(phba
);
5621 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5622 * @phba: pointer to lpfc hba data structure.
5624 * This routine is invoked to set up the driver internal resources specific to
5625 * support the SLI-4 HBA device it attached to.
5629 * other values - error
5632 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
5634 LPFC_MBOXQ_t
*mboxq
;
5636 int rc
, i
, max_buf_size
;
5637 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
5638 struct lpfc_mqe
*mqe
;
5640 int fof_vectors
= 0;
5643 phba
->sli4_hba
.num_online_cpu
= num_online_cpus();
5644 phba
->sli4_hba
.num_present_cpu
= lpfc_present_cpu
;
5645 phba
->sli4_hba
.curr_disp_cpu
= 0;
5647 /* Get all the module params for configuring this host */
5648 lpfc_get_cfgparam(phba
);
5650 /* Set up phase-1 common device driver resources */
5651 rc
= lpfc_setup_driver_resource_phase1(phba
);
5655 /* Before proceed, wait for POST done and device ready */
5656 rc
= lpfc_sli4_post_status_check(phba
);
5661 * Initialize timers used by driver
5664 setup_timer(&phba
->rrq_tmr
, lpfc_rrq_timeout
, (unsigned long)phba
);
5666 /* FCF rediscover timer */
5667 setup_timer(&phba
->fcf
.redisc_wait
, lpfc_sli4_fcf_redisc_wait_tmo
,
5668 (unsigned long)phba
);
5671 * Control structure for handling external multi-buffer mailbox
5672 * command pass-through.
5674 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
5675 sizeof(struct lpfc_mbox_ext_buf_ctx
));
5676 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
5678 phba
->max_vpi
= LPFC_MAX_VPI
;
5680 /* This will be set to correct value after the read_config mbox */
5681 phba
->max_vports
= 0;
5683 /* Program the default value of vlan_id and fc_map */
5684 phba
->valid_vlan
= 0;
5685 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
5686 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
5687 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
5690 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5691 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5692 * The WQ create will allocate the ring.
5696 * It doesn't matter what family our adapter is in, we are
5697 * limited to 2 Pages, 512 SGEs, for our SGL.
5698 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5700 max_buf_size
= (2 * SLI4_PAGE_SIZE
);
5701 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SGL_SEG_CNT
- 2)
5702 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
- 2;
5705 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5706 * used to create the sg_dma_buf_pool must be calculated.
5708 if (phba
->cfg_enable_bg
) {
5710 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5711 * the FCP rsp, and a SGE. Sice we have no control
5712 * over how many protection segments the SCSI Layer
5713 * will hand us (ie: there could be one for every block
5714 * in the IO), just allocate enough SGEs to accomidate
5715 * our max amount and we need to limit lpfc_sg_seg_cnt
5716 * to minimize the risk of running out.
5718 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5719 sizeof(struct fcp_rsp
) + max_buf_size
;
5721 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5722 phba
->cfg_total_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
;
5724 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SLI4_SEG_CNT_DIF
)
5725 phba
->cfg_sg_seg_cnt
=
5726 LPFC_MAX_SG_SLI4_SEG_CNT_DIF
;
5729 * The scsi_buf for a regular I/O holds the FCP cmnd,
5730 * the FCP rsp, a SGE for each, and a SGE for up to
5731 * cfg_sg_seg_cnt data segments.
5733 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
5734 sizeof(struct fcp_rsp
) +
5735 ((phba
->cfg_sg_seg_cnt
+ 2) *
5736 sizeof(struct sli4_sge
));
5738 /* Total SGEs for scsi_sg_list */
5739 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
5742 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5743 * need to post 1 page for the SGL.
5747 /* Initialize the host templates with the updated values. */
5748 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5749 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5750 lpfc_template_no_hr
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5752 if (phba
->cfg_sg_dma_buf_size
<= LPFC_MIN_SG_SLI4_BUF_SZ
)
5753 phba
->cfg_sg_dma_buf_size
= LPFC_MIN_SG_SLI4_BUF_SZ
;
5755 phba
->cfg_sg_dma_buf_size
=
5756 SLI4_PAGE_ALIGN(phba
->cfg_sg_dma_buf_size
);
5758 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
5759 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5760 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
5761 phba
->cfg_total_seg_cnt
);
5763 /* Initialize buffer queue management fields */
5764 INIT_LIST_HEAD(&phba
->hbqs
[LPFC_ELS_HBQ
].hbq_buffer_list
);
5765 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
5766 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
5769 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5771 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
5772 /* Initialize the Abort scsi buffer list used by driver */
5773 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
5774 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
5777 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
5778 /* Initialize the Abort nvme buffer list used by driver */
5779 spin_lock_init(&phba
->sli4_hba
.abts_nvme_buf_list_lock
);
5780 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
5781 /* Fast-path XRI aborted CQ Event work queue list */
5782 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_nvme_xri_aborted_work_queue
);
5785 /* This abort list used by worker thread */
5786 spin_lock_init(&phba
->sli4_hba
.sgl_list_lock
);
5787 spin_lock_init(&phba
->sli4_hba
.nvmet_io_lock
);
5790 * Initialize driver internal slow-path work queues
5793 /* Driver internel slow-path CQ Event pool */
5794 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
5795 /* Response IOCB work queue list */
5796 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
5797 /* Asynchronous event CQ Event work queue list */
5798 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
5799 /* Fast-path XRI aborted CQ Event work queue list */
5800 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
5801 /* Slow-path XRI aborted CQ Event work queue list */
5802 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
5803 /* Receive queue CQ Event work queue list */
5804 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
5806 /* Initialize extent block lists. */
5807 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
5808 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
5809 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
5810 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
5812 /* initialize optic_state to 0xFF */
5813 phba
->sli4_hba
.lnk_info
.optic_state
= 0xff;
5815 /* Allocate device driver memory */
5816 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
5820 /* IF Type 2 ports get initialized now. */
5821 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5822 LPFC_SLI_INTF_IF_TYPE_2
) {
5823 rc
= lpfc_pci_function_reset(phba
);
5828 phba
->temp_sensor_support
= 1;
5831 /* Create the bootstrap mailbox command */
5832 rc
= lpfc_create_bootstrap_mbox(phba
);
5836 /* Set up the host's endian order with the device. */
5837 rc
= lpfc_setup_endian_order(phba
);
5839 goto out_free_bsmbx
;
5841 /* Set up the hba's configuration parameters. */
5842 rc
= lpfc_sli4_read_config(phba
);
5844 goto out_free_bsmbx
;
5845 rc
= lpfc_mem_alloc_active_rrq_pool_s4(phba
);
5847 goto out_free_bsmbx
;
5849 /* IF Type 0 ports get initialized now. */
5850 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5851 LPFC_SLI_INTF_IF_TYPE_0
) {
5852 rc
= lpfc_pci_function_reset(phba
);
5854 goto out_free_bsmbx
;
5857 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
5861 goto out_free_bsmbx
;
5864 /* Check for NVMET being configured */
5865 phba
->nvmet_support
= 0;
5866 if (lpfc_enable_nvmet_cnt
) {
5868 /* First get WWN of HBA instance */
5869 lpfc_read_nv(phba
, mboxq
);
5870 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5871 if (rc
!= MBX_SUCCESS
) {
5872 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5873 "6016 Mailbox failed , mbxCmd x%x "
5874 "READ_NV, mbxStatus x%x\n",
5875 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5876 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
5878 goto out_free_bsmbx
;
5881 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.nodename
,
5883 wwn
= cpu_to_be64(wwn
);
5884 phba
->sli4_hba
.wwnn
.u
.name
= wwn
;
5885 memcpy(&wwn
, (char *)mb
->un
.varRDnvp
.portname
,
5887 /* wwn is WWPN of HBA instance */
5888 wwn
= cpu_to_be64(wwn
);
5889 phba
->sli4_hba
.wwpn
.u
.name
= wwn
;
5891 /* Check to see if it matches any module parameter */
5892 for (i
= 0; i
< lpfc_enable_nvmet_cnt
; i
++) {
5893 if (wwn
== lpfc_enable_nvmet
[i
]) {
5894 #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
5895 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5896 "6017 NVME Target %016llx\n",
5898 phba
->nvmet_support
= 1; /* a match */
5900 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5901 "6021 Can't enable NVME Target."
5902 " NVME_TARGET_FC infrastructure"
5903 " is not in kernel\n");
5909 lpfc_nvme_mod_param_dep(phba
);
5911 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
5912 lpfc_supported_pages(mboxq
);
5913 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5915 mqe
= &mboxq
->u
.mqe
;
5916 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
5917 LPFC_MAX_SUPPORTED_PAGES
);
5918 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
5919 switch (pn_page
[i
]) {
5920 case LPFC_SLI4_PARAMETERS
:
5921 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
5927 /* Read the port's SLI4 Parameters capabilities if supported. */
5928 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
5929 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
5931 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5933 goto out_free_bsmbx
;
5938 * Get sli4 parameters that override parameters from Port capabilities.
5939 * If this call fails, it isn't critical unless the SLI4 parameters come
5942 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
5944 if (phba
->sli4_hba
.extents_in_use
&&
5945 phba
->sli4_hba
.rpi_hdrs_in_use
) {
5946 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5947 "2999 Unsupported SLI4 Parameters "
5948 "Extents and RPI headers enabled.\n");
5950 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5951 goto out_free_bsmbx
;
5954 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5956 /* Verify OAS is supported */
5957 lpfc_sli4_oas_verify(phba
);
5961 /* Verify all the SLI4 queues */
5962 rc
= lpfc_sli4_queue_verify(phba
);
5964 goto out_free_bsmbx
;
5966 /* Create driver internal CQE event pool */
5967 rc
= lpfc_sli4_cq_event_pool_create(phba
);
5969 goto out_free_bsmbx
;
5971 /* Initialize sgl lists per host */
5972 lpfc_init_sgl_list(phba
);
5974 /* Allocate and initialize active sgl array */
5975 rc
= lpfc_init_active_sgl_array(phba
);
5977 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5978 "1430 Failed to initialize sgl list.\n");
5979 goto out_destroy_cq_event_pool
;
5981 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
5983 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5984 "1432 Failed to initialize rpi headers.\n");
5985 goto out_free_active_sgl
;
5988 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5989 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
5990 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
5992 if (!phba
->fcf
.fcf_rr_bmask
) {
5993 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5994 "2759 Failed allocate memory for FCF round "
5995 "robin failover bmask\n");
5997 goto out_remove_rpi_hdrs
;
6000 phba
->sli4_hba
.hba_eq_hdl
= kcalloc(fof_vectors
+ phba
->io_channel_irqs
,
6001 sizeof(struct lpfc_hba_eq_hdl
),
6003 if (!phba
->sli4_hba
.hba_eq_hdl
) {
6004 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6005 "2572 Failed allocate memory for "
6006 "fast-path per-EQ handle array\n");
6008 goto out_free_fcf_rr_bmask
;
6011 phba
->sli4_hba
.cpu_map
= kcalloc(phba
->sli4_hba
.num_present_cpu
,
6012 sizeof(struct lpfc_vector_map_info
),
6014 if (!phba
->sli4_hba
.cpu_map
) {
6015 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6016 "3327 Failed allocate memory for msi-x "
6017 "interrupt vector mapping\n");
6019 goto out_free_hba_eq_hdl
;
6021 if (lpfc_used_cpu
== NULL
) {
6022 lpfc_used_cpu
= kcalloc(lpfc_present_cpu
, sizeof(uint16_t),
6024 if (!lpfc_used_cpu
) {
6025 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6026 "3335 Failed allocate memory for msi-x "
6027 "interrupt vector mapping\n");
6028 kfree(phba
->sli4_hba
.cpu_map
);
6030 goto out_free_hba_eq_hdl
;
6032 for (i
= 0; i
< lpfc_present_cpu
; i
++)
6033 lpfc_used_cpu
[i
] = LPFC_VECTOR_MAP_EMPTY
;
6037 * Enable sr-iov virtual functions if supported and configured
6038 * through the module parameter.
6040 if (phba
->cfg_sriov_nr_virtfn
> 0) {
6041 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
6042 phba
->cfg_sriov_nr_virtfn
);
6044 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6045 "3020 Requested number of SR-IOV "
6046 "virtual functions (%d) is not "
6048 phba
->cfg_sriov_nr_virtfn
);
6049 phba
->cfg_sriov_nr_virtfn
= 0;
6055 out_free_hba_eq_hdl
:
6056 kfree(phba
->sli4_hba
.hba_eq_hdl
);
6057 out_free_fcf_rr_bmask
:
6058 kfree(phba
->fcf
.fcf_rr_bmask
);
6059 out_remove_rpi_hdrs
:
6060 lpfc_sli4_remove_rpi_hdrs(phba
);
6061 out_free_active_sgl
:
6062 lpfc_free_active_sgl(phba
);
6063 out_destroy_cq_event_pool
:
6064 lpfc_sli4_cq_event_pool_destroy(phba
);
6066 lpfc_destroy_bootstrap_mbox(phba
);
6068 lpfc_mem_free(phba
);
6073 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6074 * @phba: pointer to lpfc hba data structure.
6076 * This routine is invoked to unset the driver internal resources set up
6077 * specific for supporting the SLI-4 HBA device it attached to.
6080 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
6082 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
6084 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6085 kfree(phba
->sli4_hba
.cpu_map
);
6086 phba
->sli4_hba
.num_present_cpu
= 0;
6087 phba
->sli4_hba
.num_online_cpu
= 0;
6088 phba
->sli4_hba
.curr_disp_cpu
= 0;
6090 /* Free memory allocated for fast-path work queue handles */
6091 kfree(phba
->sli4_hba
.hba_eq_hdl
);
6093 /* Free the allocated rpi headers. */
6094 lpfc_sli4_remove_rpi_hdrs(phba
);
6095 lpfc_sli4_remove_rpis(phba
);
6097 /* Free eligible FCF index bmask */
6098 kfree(phba
->fcf
.fcf_rr_bmask
);
6100 /* Free the ELS sgl list */
6101 lpfc_free_active_sgl(phba
);
6102 lpfc_free_els_sgl_list(phba
);
6103 lpfc_free_nvmet_sgl_list(phba
);
6105 /* Free the completion queue EQ event pool */
6106 lpfc_sli4_cq_event_release_all(phba
);
6107 lpfc_sli4_cq_event_pool_destroy(phba
);
6109 /* Release resource identifiers. */
6110 lpfc_sli4_dealloc_resource_identifiers(phba
);
6112 /* Free the bsmbx region. */
6113 lpfc_destroy_bootstrap_mbox(phba
);
6115 /* Free the SLI Layer memory with SLI4 HBAs */
6116 lpfc_mem_free_all(phba
);
6118 /* Free the current connect table */
6119 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
6120 &phba
->fcf_conn_rec_list
, list
) {
6121 list_del_init(&conn_entry
->list
);
6129 * lpfc_init_api_table_setup - Set up init api function jump table
6130 * @phba: The hba struct for which this call is being executed.
6131 * @dev_grp: The HBA PCI-Device group number.
6133 * This routine sets up the device INIT interface API function jump table
6136 * Returns: 0 - success, -ENODEV - failure.
6139 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
6141 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
6142 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
6143 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
6145 case LPFC_PCI_DEV_LP
:
6146 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
6147 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
6148 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
6150 case LPFC_PCI_DEV_OC
:
6151 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
6152 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
6153 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
6156 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6157 "1431 Invalid HBA PCI-device group: 0x%x\n",
6166 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6167 * @phba: pointer to lpfc hba data structure.
6169 * This routine is invoked to set up the driver internal resources after the
6170 * device specific resource setup to support the HBA device it attached to.
6174 * other values - error
6177 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
6181 /* Startup the kernel thread for this host adapter. */
6182 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
6183 "lpfc_worker_%d", phba
->brd_no
);
6184 if (IS_ERR(phba
->worker_thread
)) {
6185 error
= PTR_ERR(phba
->worker_thread
);
6193 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6194 * @phba: pointer to lpfc hba data structure.
6196 * This routine is invoked to unset the driver internal resources set up after
6197 * the device specific resource setup for supporting the HBA device it
6201 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
6203 /* Stop kernel worker thread */
6204 kthread_stop(phba
->worker_thread
);
6208 * lpfc_free_iocb_list - Free iocb list.
6209 * @phba: pointer to lpfc hba data structure.
6211 * This routine is invoked to free the driver's IOCB list and memory.
6214 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
6216 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
6218 spin_lock_irq(&phba
->hbalock
);
6219 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
6220 &phba
->lpfc_iocb_list
, list
) {
6221 list_del(&iocbq_entry
->list
);
6223 phba
->total_iocbq_bufs
--;
6225 spin_unlock_irq(&phba
->hbalock
);
6231 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6232 * @phba: pointer to lpfc hba data structure.
6234 * This routine is invoked to allocate and initizlize the driver's IOCB
6235 * list and set up the IOCB tag array accordingly.
6239 * other values - error
6242 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
6244 struct lpfc_iocbq
*iocbq_entry
= NULL
;
6248 /* Initialize and populate the iocb list per host. */
6249 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
6250 for (i
= 0; i
< iocb_count
; i
++) {
6251 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
6252 if (iocbq_entry
== NULL
) {
6253 printk(KERN_ERR
"%s: only allocated %d iocbs of "
6254 "expected %d count. Unloading driver.\n",
6255 __func__
, i
, LPFC_IOCB_LIST_CNT
);
6256 goto out_free_iocbq
;
6259 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
6262 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
6263 "Unloading driver.\n", __func__
);
6264 goto out_free_iocbq
;
6266 iocbq_entry
->sli4_lxritag
= NO_XRI
;
6267 iocbq_entry
->sli4_xritag
= NO_XRI
;
6269 spin_lock_irq(&phba
->hbalock
);
6270 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
6271 phba
->total_iocbq_bufs
++;
6272 spin_unlock_irq(&phba
->hbalock
);
6278 lpfc_free_iocb_list(phba
);
6284 * lpfc_free_sgl_list - Free a given sgl list.
6285 * @phba: pointer to lpfc hba data structure.
6286 * @sglq_list: pointer to the head of sgl list.
6288 * This routine is invoked to free a give sgl list and memory.
6291 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
6293 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6295 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
6296 list_del(&sglq_entry
->list
);
6297 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
6303 * lpfc_free_els_sgl_list - Free els sgl list.
6304 * @phba: pointer to lpfc hba data structure.
6306 * This routine is invoked to free the driver's els sgl list and memory.
6309 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
6311 LIST_HEAD(sglq_list
);
6313 /* Retrieve all els sgls from driver list */
6314 spin_lock_irq(&phba
->hbalock
);
6315 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6316 list_splice_init(&phba
->sli4_hba
.lpfc_els_sgl_list
, &sglq_list
);
6317 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6318 spin_unlock_irq(&phba
->hbalock
);
6320 /* Now free the sgl list */
6321 lpfc_free_sgl_list(phba
, &sglq_list
);
6325 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6326 * @phba: pointer to lpfc hba data structure.
6328 * This routine is invoked to free the driver's nvmet sgl list and memory.
6331 lpfc_free_nvmet_sgl_list(struct lpfc_hba
*phba
)
6333 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
6334 LIST_HEAD(sglq_list
);
6336 /* Retrieve all nvmet sgls from driver list */
6337 spin_lock_irq(&phba
->hbalock
);
6338 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6339 list_splice_init(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
, &sglq_list
);
6340 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6341 spin_unlock_irq(&phba
->hbalock
);
6343 /* Now free the sgl list */
6344 list_for_each_entry_safe(sglq_entry
, sglq_next
, &sglq_list
, list
) {
6345 list_del(&sglq_entry
->list
);
6346 lpfc_nvmet_buf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
6352 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6353 * @phba: pointer to lpfc hba data structure.
6355 * This routine is invoked to allocate the driver's active sgl memory.
6356 * This array will hold the sglq_entry's for active IOs.
6359 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
6362 size
= sizeof(struct lpfc_sglq
*);
6363 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
6365 phba
->sli4_hba
.lpfc_sglq_active_list
=
6366 kzalloc(size
, GFP_KERNEL
);
6367 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
6373 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6374 * @phba: pointer to lpfc hba data structure.
6376 * This routine is invoked to walk through the array of active sglq entries
6377 * and free all of the resources.
6378 * This is just a place holder for now.
6381 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
6383 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
6387 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6388 * @phba: pointer to lpfc hba data structure.
6390 * This routine is invoked to allocate and initizlize the driver's sgl
6391 * list and set up the sgl xritag tag array accordingly.
6395 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
6397 /* Initialize and populate the sglq list per host/VF. */
6398 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_els_sgl_list
);
6399 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
6400 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
6401 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
6403 /* els xri-sgl book keeping */
6404 phba
->sli4_hba
.els_xri_cnt
= 0;
6406 /* scsi xri-buffer book keeping */
6407 phba
->sli4_hba
.scsi_xri_cnt
= 0;
6409 /* nvme xri-buffer book keeping */
6410 phba
->sli4_hba
.nvme_xri_cnt
= 0;
6414 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6415 * @phba: pointer to lpfc hba data structure.
6417 * This routine is invoked to post rpi header templates to the
6418 * port for those SLI4 ports that do not support extents. This routine
6419 * posts a PAGE_SIZE memory region to the port to hold up to
6420 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6421 * and should be called only when interrupts are disabled.
6425 * -ERROR - otherwise.
6428 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
6431 struct lpfc_rpi_hdr
*rpi_hdr
;
6433 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
6434 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6436 if (phba
->sli4_hba
.extents_in_use
)
6439 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
6441 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6442 "0391 Error during rpi post operation\n");
6443 lpfc_sli4_remove_rpis(phba
);
6451 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6452 * @phba: pointer to lpfc hba data structure.
6454 * This routine is invoked to allocate a single 4KB memory region to
6455 * support rpis and stores them in the phba. This single region
6456 * provides support for up to 64 rpis. The region is used globally
6460 * A valid rpi hdr on success.
6461 * A NULL pointer on any failure.
6463 struct lpfc_rpi_hdr
*
6464 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
6466 uint16_t rpi_limit
, curr_rpi_range
;
6467 struct lpfc_dmabuf
*dmabuf
;
6468 struct lpfc_rpi_hdr
*rpi_hdr
;
6472 * If the SLI4 port supports extents, posting the rpi header isn't
6473 * required. Set the expected maximum count and let the actual value
6474 * get set when extents are fully allocated.
6476 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6478 if (phba
->sli4_hba
.extents_in_use
)
6481 /* The limit on the logical index is just the max_rpi count. */
6482 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
6483 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
6485 spin_lock_irq(&phba
->hbalock
);
6487 * Establish the starting RPI in this header block. The starting
6488 * rpi is normalized to a zero base because the physical rpi is
6491 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
6492 spin_unlock_irq(&phba
->hbalock
);
6495 * The port has a limited number of rpis. The increment here
6496 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6497 * and to allow the full max_rpi range per port.
6499 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
6500 rpi_count
= rpi_limit
- curr_rpi_range
;
6502 rpi_count
= LPFC_RPI_HDR_COUNT
;
6507 * First allocate the protocol header region for the port. The
6508 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6510 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
6514 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
6515 LPFC_HDR_TEMPLATE_SIZE
,
6516 &dmabuf
->phys
, GFP_KERNEL
);
6517 if (!dmabuf
->virt
) {
6519 goto err_free_dmabuf
;
6522 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
6524 goto err_free_coherent
;
6527 /* Save the rpi header data for cleanup later. */
6528 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
6530 goto err_free_coherent
;
6532 rpi_hdr
->dmabuf
= dmabuf
;
6533 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
6534 rpi_hdr
->page_count
= 1;
6535 spin_lock_irq(&phba
->hbalock
);
6537 /* The rpi_hdr stores the logical index only. */
6538 rpi_hdr
->start_rpi
= curr_rpi_range
;
6539 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
6542 * The next_rpi stores the next logical module-64 rpi value used
6543 * to post physical rpis in subsequent rpi postings.
6545 phba
->sli4_hba
.next_rpi
+= rpi_count
;
6546 spin_unlock_irq(&phba
->hbalock
);
6550 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
6551 dmabuf
->virt
, dmabuf
->phys
);
6558 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6559 * @phba: pointer to lpfc hba data structure.
6561 * This routine is invoked to remove all memory resources allocated
6562 * to support rpis for SLI4 ports not supporting extents. This routine
6563 * presumes the caller has released all rpis consumed by fabric or port
6564 * logins and is prepared to have the header pages removed.
6567 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
6569 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
6571 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6574 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
6575 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
6576 list_del(&rpi_hdr
->list
);
6577 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
6578 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
6579 kfree(rpi_hdr
->dmabuf
);
6583 /* There are no rpis available to the port now. */
6584 phba
->sli4_hba
.next_rpi
= 0;
6588 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6589 * @pdev: pointer to pci device data structure.
6591 * This routine is invoked to allocate the driver hba data structure for an
6592 * HBA device. If the allocation is successful, the phba reference to the
6593 * PCI device data structure is set.
6596 * pointer to @phba - successful
6599 static struct lpfc_hba
*
6600 lpfc_hba_alloc(struct pci_dev
*pdev
)
6602 struct lpfc_hba
*phba
;
6604 /* Allocate memory for HBA structure */
6605 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
6607 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
6611 /* Set reference to PCI device in HBA structure */
6612 phba
->pcidev
= pdev
;
6614 /* Assign an unused board number */
6615 phba
->brd_no
= lpfc_get_instance();
6616 if (phba
->brd_no
< 0) {
6620 phba
->eratt_poll_interval
= LPFC_ERATT_POLL_INTERVAL
;
6622 spin_lock_init(&phba
->ct_ev_lock
);
6623 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
6629 * lpfc_hba_free - Free driver hba data structure with a device.
6630 * @phba: pointer to lpfc hba data structure.
6632 * This routine is invoked to free the driver hba data structure with an
6636 lpfc_hba_free(struct lpfc_hba
*phba
)
6638 /* Release the driver assigned board number */
6639 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
6641 /* Free memory allocated with sli3 rings */
6642 kfree(phba
->sli
.sli3_ring
);
6643 phba
->sli
.sli3_ring
= NULL
;
6650 * lpfc_create_shost - Create hba physical port with associated scsi host.
6651 * @phba: pointer to lpfc hba data structure.
6653 * This routine is invoked to create HBA physical port and associate a SCSI
6658 * other values - error
6661 lpfc_create_shost(struct lpfc_hba
*phba
)
6663 struct lpfc_vport
*vport
;
6664 struct Scsi_Host
*shost
;
6666 /* Initialize HBA FC structure */
6667 phba
->fc_edtov
= FF_DEF_EDTOV
;
6668 phba
->fc_ratov
= FF_DEF_RATOV
;
6669 phba
->fc_altov
= FF_DEF_ALTOV
;
6670 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
6672 atomic_set(&phba
->sdev_cnt
, 0);
6673 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
6677 shost
= lpfc_shost_from_vport(vport
);
6678 phba
->pport
= vport
;
6680 if (phba
->nvmet_support
) {
6681 /* Only 1 vport (pport) will support NVME target */
6682 if (phba
->txrdy_payload_pool
== NULL
) {
6683 phba
->txrdy_payload_pool
= pci_pool_create(
6684 "txrdy_pool", phba
->pcidev
,
6685 TXRDY_PAYLOAD_LEN
, 16, 0);
6686 if (phba
->txrdy_payload_pool
) {
6687 phba
->targetport
= NULL
;
6688 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_NVME
;
6689 lpfc_printf_log(phba
, KERN_INFO
,
6690 LOG_INIT
| LOG_NVME_DISC
,
6691 "6076 NVME Target Found\n");
6696 lpfc_debugfs_initialize(vport
);
6697 /* Put reference to SCSI host to driver's device private data */
6698 pci_set_drvdata(phba
->pcidev
, shost
);
6701 * At this point we are fully registered with PSA. In addition,
6702 * any initial discovery should be completed.
6704 vport
->load_flag
|= FC_ALLOW_FDMI
;
6705 if (phba
->cfg_enable_SmartSAN
||
6706 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
6708 /* Setup appropriate attribute masks */
6709 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
6710 if (phba
->cfg_enable_SmartSAN
)
6711 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
6713 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
6719 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6720 * @phba: pointer to lpfc hba data structure.
6722 * This routine is invoked to destroy HBA physical port and the associated
6726 lpfc_destroy_shost(struct lpfc_hba
*phba
)
6728 struct lpfc_vport
*vport
= phba
->pport
;
6730 /* Destroy physical port that associated with the SCSI host */
6731 destroy_port(vport
);
6737 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6738 * @phba: pointer to lpfc hba data structure.
6739 * @shost: the shost to be used to detect Block guard settings.
6741 * This routine sets up the local Block guard protocol settings for @shost.
6742 * This routine also allocates memory for debugging bg buffers.
6745 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
6751 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
6752 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6753 "1478 Registering BlockGuard with the "
6756 old_mask
= phba
->cfg_prot_mask
;
6757 old_guard
= phba
->cfg_prot_guard
;
6759 /* Only allow supported values */
6760 phba
->cfg_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
6761 SHOST_DIX_TYPE0_PROTECTION
|
6762 SHOST_DIX_TYPE1_PROTECTION
);
6763 phba
->cfg_prot_guard
&= (SHOST_DIX_GUARD_IP
|
6764 SHOST_DIX_GUARD_CRC
);
6766 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6767 if (phba
->cfg_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
6768 phba
->cfg_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
6770 if (phba
->cfg_prot_mask
&& phba
->cfg_prot_guard
) {
6771 if ((old_mask
!= phba
->cfg_prot_mask
) ||
6772 (old_guard
!= phba
->cfg_prot_guard
))
6773 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6774 "1475 Registering BlockGuard with the "
6775 "SCSI layer: mask %d guard %d\n",
6776 phba
->cfg_prot_mask
,
6777 phba
->cfg_prot_guard
);
6779 scsi_host_set_prot(shost
, phba
->cfg_prot_mask
);
6780 scsi_host_set_guard(shost
, phba
->cfg_prot_guard
);
6782 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6783 "1479 Not Registering BlockGuard with the SCSI "
6784 "layer, Bad protection parameters: %d %d\n",
6785 old_mask
, old_guard
);
6788 if (!_dump_buf_data
) {
6790 spin_lock_init(&_dump_buf_lock
);
6792 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
6793 if (_dump_buf_data
) {
6794 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6795 "9043 BLKGRD: allocated %d pages for "
6796 "_dump_buf_data at 0x%p\n",
6797 (1 << pagecnt
), _dump_buf_data
);
6798 _dump_buf_data_order
= pagecnt
;
6799 memset(_dump_buf_data
, 0,
6800 ((1 << PAGE_SHIFT
) << pagecnt
));
6805 if (!_dump_buf_data_order
)
6806 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6807 "9044 BLKGRD: ERROR unable to allocate "
6808 "memory for hexdump\n");
6810 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6811 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6812 "\n", _dump_buf_data
);
6813 if (!_dump_buf_dif
) {
6816 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
6817 if (_dump_buf_dif
) {
6818 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6819 "9046 BLKGRD: allocated %d pages for "
6820 "_dump_buf_dif at 0x%p\n",
6821 (1 << pagecnt
), _dump_buf_dif
);
6822 _dump_buf_dif_order
= pagecnt
;
6823 memset(_dump_buf_dif
, 0,
6824 ((1 << PAGE_SHIFT
) << pagecnt
));
6829 if (!_dump_buf_dif_order
)
6830 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6831 "9047 BLKGRD: ERROR unable to allocate "
6832 "memory for hexdump\n");
6834 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6835 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
6840 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6841 * @phba: pointer to lpfc hba data structure.
6843 * This routine is invoked to perform all the necessary post initialization
6844 * setup for the device.
6847 lpfc_post_init_setup(struct lpfc_hba
*phba
)
6849 struct Scsi_Host
*shost
;
6850 struct lpfc_adapter_event_header adapter_event
;
6852 /* Get the default values for Model Name and Description */
6853 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
6856 * hba setup may have changed the hba_queue_depth so we need to
6857 * adjust the value of can_queue.
6859 shost
= pci_get_drvdata(phba
->pcidev
);
6860 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
6861 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
6862 lpfc_setup_bg(phba
, shost
);
6864 lpfc_host_attrib_init(shost
);
6866 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
6867 spin_lock_irq(shost
->host_lock
);
6868 lpfc_poll_start_timer(phba
);
6869 spin_unlock_irq(shost
->host_lock
);
6872 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6873 "0428 Perform SCSI scan\n");
6874 /* Send board arrival event to upper layer */
6875 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
6876 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
6877 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6878 sizeof(adapter_event
),
6879 (char *) &adapter_event
,
6885 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6886 * @phba: pointer to lpfc hba data structure.
6888 * This routine is invoked to set up the PCI device memory space for device
6889 * with SLI-3 interface spec.
6893 * other values - error
6896 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
6898 struct pci_dev
*pdev
;
6899 unsigned long bar0map_len
, bar2map_len
;
6902 int error
= -ENODEV
;
6904 /* Obtain PCI device reference */
6908 pdev
= phba
->pcidev
;
6910 /* Set the device DMA mask size */
6911 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
6912 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
6913 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
6914 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
6919 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6920 * required by each mapping.
6922 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
6923 bar0map_len
= pci_resource_len(pdev
, 0);
6925 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
6926 bar2map_len
= pci_resource_len(pdev
, 2);
6928 /* Map HBA SLIM to a kernel virtual address. */
6929 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
6930 if (!phba
->slim_memmap_p
) {
6931 dev_printk(KERN_ERR
, &pdev
->dev
,
6932 "ioremap failed for SLIM memory.\n");
6936 /* Map HBA Control Registers to a kernel virtual address. */
6937 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
6938 if (!phba
->ctrl_regs_memmap_p
) {
6939 dev_printk(KERN_ERR
, &pdev
->dev
,
6940 "ioremap failed for HBA control registers.\n");
6941 goto out_iounmap_slim
;
6944 /* Allocate memory for SLI-2 structures */
6945 phba
->slim2p
.virt
= dma_zalloc_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6946 &phba
->slim2p
.phys
, GFP_KERNEL
);
6947 if (!phba
->slim2p
.virt
)
6950 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
6951 phba
->mbox_ext
= (phba
->slim2p
.virt
+
6952 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
6953 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
6954 phba
->IOCBs
= (phba
->slim2p
.virt
+
6955 offsetof(struct lpfc_sli2_slim
, IOCBs
));
6957 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
6958 lpfc_sli_hbq_size(),
6959 &phba
->hbqslimp
.phys
,
6961 if (!phba
->hbqslimp
.virt
)
6964 hbq_count
= lpfc_sli_hbq_count();
6965 ptr
= phba
->hbqslimp
.virt
;
6966 for (i
= 0; i
< hbq_count
; ++i
) {
6967 phba
->hbqs
[i
].hbq_virt
= ptr
;
6968 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
6969 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
6970 sizeof(struct lpfc_hbq_entry
));
6972 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
6973 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
6975 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
6977 phba
->MBslimaddr
= phba
->slim_memmap_p
;
6978 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
6979 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
6980 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
6981 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
6986 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6987 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6989 iounmap(phba
->ctrl_regs_memmap_p
);
6991 iounmap(phba
->slim_memmap_p
);
6997 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6998 * @phba: pointer to lpfc hba data structure.
7000 * This routine is invoked to unset the PCI device memory space for device
7001 * with SLI-3 interface spec.
7004 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
7006 struct pci_dev
*pdev
;
7008 /* Obtain PCI device reference */
7012 pdev
= phba
->pcidev
;
7014 /* Free coherent DMA memory allocated */
7015 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
7016 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
7017 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7018 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
7020 /* I/O memory unmap */
7021 iounmap(phba
->ctrl_regs_memmap_p
);
7022 iounmap(phba
->slim_memmap_p
);
7028 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7029 * @phba: pointer to lpfc hba data structure.
7031 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7032 * done and check status.
7034 * Return 0 if successful, otherwise -ENODEV.
7037 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
7039 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
7040 struct lpfc_register reg_data
;
7041 int i
, port_error
= 0;
7044 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
7045 memset(®_data
, 0, sizeof(reg_data
));
7046 if (!phba
->sli4_hba
.PSMPHRregaddr
)
7049 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7050 for (i
= 0; i
< 3000; i
++) {
7051 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
7052 &portsmphr_reg
.word0
) ||
7053 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
7054 /* Port has a fatal POST error, break out */
7055 port_error
= -ENODEV
;
7058 if (LPFC_POST_STAGE_PORT_READY
==
7059 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
7065 * If there was a port error during POST, then don't proceed with
7066 * other register reads as the data may not be valid. Just exit.
7069 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7070 "1408 Port Failed POST - portsmphr=0x%x, "
7071 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7072 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7073 portsmphr_reg
.word0
,
7074 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
7075 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
7076 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
7077 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
7078 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
7079 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
7080 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
7081 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
7083 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7084 "2534 Device Info: SLIFamily=0x%x, "
7085 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7086 "SLIHint_2=0x%x, FT=0x%x\n",
7087 bf_get(lpfc_sli_intf_sli_family
,
7088 &phba
->sli4_hba
.sli_intf
),
7089 bf_get(lpfc_sli_intf_slirev
,
7090 &phba
->sli4_hba
.sli_intf
),
7091 bf_get(lpfc_sli_intf_if_type
,
7092 &phba
->sli4_hba
.sli_intf
),
7093 bf_get(lpfc_sli_intf_sli_hint1
,
7094 &phba
->sli4_hba
.sli_intf
),
7095 bf_get(lpfc_sli_intf_sli_hint2
,
7096 &phba
->sli4_hba
.sli_intf
),
7097 bf_get(lpfc_sli_intf_func_type
,
7098 &phba
->sli4_hba
.sli_intf
));
7100 * Check for other Port errors during the initialization
7101 * process. Fail the load if the port did not come up
7104 if_type
= bf_get(lpfc_sli_intf_if_type
,
7105 &phba
->sli4_hba
.sli_intf
);
7107 case LPFC_SLI_INTF_IF_TYPE_0
:
7108 phba
->sli4_hba
.ue_mask_lo
=
7109 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
7110 phba
->sli4_hba
.ue_mask_hi
=
7111 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
7113 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
7115 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
7116 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
7117 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
7118 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7119 "1422 Unrecoverable Error "
7120 "Detected during POST "
7121 "uerr_lo_reg=0x%x, "
7122 "uerr_hi_reg=0x%x, "
7123 "ue_mask_lo_reg=0x%x, "
7124 "ue_mask_hi_reg=0x%x\n",
7127 phba
->sli4_hba
.ue_mask_lo
,
7128 phba
->sli4_hba
.ue_mask_hi
);
7129 port_error
= -ENODEV
;
7132 case LPFC_SLI_INTF_IF_TYPE_2
:
7133 /* Final checks. The port status should be clean. */
7134 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
7136 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
7137 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
7138 phba
->work_status
[0] =
7139 readl(phba
->sli4_hba
.u
.if_type2
.
7141 phba
->work_status
[1] =
7142 readl(phba
->sli4_hba
.u
.if_type2
.
7144 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7145 "2888 Unrecoverable port error "
7146 "following POST: port status reg "
7147 "0x%x, port_smphr reg 0x%x, "
7148 "error 1=0x%x, error 2=0x%x\n",
7150 portsmphr_reg
.word0
,
7151 phba
->work_status
[0],
7152 phba
->work_status
[1]);
7153 port_error
= -ENODEV
;
7156 case LPFC_SLI_INTF_IF_TYPE_1
:
7165 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7166 * @phba: pointer to lpfc hba data structure.
7167 * @if_type: The SLI4 interface type getting configured.
7169 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7173 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
7176 case LPFC_SLI_INTF_IF_TYPE_0
:
7177 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
7178 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
7179 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
7180 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
7181 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
7182 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
7183 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
7184 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
7185 phba
->sli4_hba
.SLIINTFregaddr
=
7186 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
7188 case LPFC_SLI_INTF_IF_TYPE_2
:
7189 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
7190 phba
->sli4_hba
.conf_regs_memmap_p
+
7191 LPFC_CTL_PORT_ER1_OFFSET
;
7192 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
7193 phba
->sli4_hba
.conf_regs_memmap_p
+
7194 LPFC_CTL_PORT_ER2_OFFSET
;
7195 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
7196 phba
->sli4_hba
.conf_regs_memmap_p
+
7197 LPFC_CTL_PORT_CTL_OFFSET
;
7198 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
7199 phba
->sli4_hba
.conf_regs_memmap_p
+
7200 LPFC_CTL_PORT_STA_OFFSET
;
7201 phba
->sli4_hba
.SLIINTFregaddr
=
7202 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
7203 phba
->sli4_hba
.PSMPHRregaddr
=
7204 phba
->sli4_hba
.conf_regs_memmap_p
+
7205 LPFC_CTL_PORT_SEM_OFFSET
;
7206 phba
->sli4_hba
.RQDBregaddr
=
7207 phba
->sli4_hba
.conf_regs_memmap_p
+
7208 LPFC_ULP0_RQ_DOORBELL
;
7209 phba
->sli4_hba
.WQDBregaddr
=
7210 phba
->sli4_hba
.conf_regs_memmap_p
+
7211 LPFC_ULP0_WQ_DOORBELL
;
7212 phba
->sli4_hba
.EQCQDBregaddr
=
7213 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
7214 phba
->sli4_hba
.MQDBregaddr
=
7215 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
7216 phba
->sli4_hba
.BMBXregaddr
=
7217 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
7219 case LPFC_SLI_INTF_IF_TYPE_1
:
7221 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
7222 "FATAL - unsupported SLI4 interface type - %d\n",
7229 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7230 * @phba: pointer to lpfc hba data structure.
7232 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7236 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
7238 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7239 LPFC_SLIPORT_IF0_SMPHR
;
7240 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7242 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7244 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
7249 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7250 * @phba: pointer to lpfc hba data structure.
7251 * @vf: virtual function number
7253 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7254 * based on the given viftual function number, @vf.
7256 * Return 0 if successful, otherwise -ENODEV.
7259 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
7261 if (vf
> LPFC_VIR_FUNC_MAX
)
7264 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7265 vf
* LPFC_VFR_PAGE_SIZE
+
7266 LPFC_ULP0_RQ_DOORBELL
);
7267 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7268 vf
* LPFC_VFR_PAGE_SIZE
+
7269 LPFC_ULP0_WQ_DOORBELL
);
7270 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7271 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
7272 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7273 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
7274 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
7275 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
7280 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7281 * @phba: pointer to lpfc hba data structure.
7283 * This routine is invoked to create the bootstrap mailbox
7284 * region consistent with the SLI-4 interface spec. This
7285 * routine allocates all memory necessary to communicate
7286 * mailbox commands to the port and sets up all alignment
7287 * needs. No locks are expected to be held when calling
7292 * -ENOMEM - could not allocated memory.
7295 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
7298 struct lpfc_dmabuf
*dmabuf
;
7299 struct dma_address
*dma_address
;
7303 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
7308 * The bootstrap mailbox region is comprised of 2 parts
7309 * plus an alignment restriction of 16 bytes.
7311 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
7312 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, bmbx_size
,
7313 &dmabuf
->phys
, GFP_KERNEL
);
7314 if (!dmabuf
->virt
) {
7320 * Initialize the bootstrap mailbox pointers now so that the register
7321 * operations are simple later. The mailbox dma address is required
7322 * to be 16-byte aligned. Also align the virtual memory as each
7323 * maibox is copied into the bmbx mailbox region before issuing the
7324 * command to the port.
7326 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
7327 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
7329 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
7330 LPFC_ALIGN_16_BYTE
);
7331 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
7332 LPFC_ALIGN_16_BYTE
);
7335 * Set the high and low physical addresses now. The SLI4 alignment
7336 * requirement is 16 bytes and the mailbox is posted to the port
7337 * as two 30-bit addresses. The other data is a bit marking whether
7338 * the 30-bit address is the high or low address.
7339 * Upcast bmbx aphys to 64bits so shift instruction compiles
7340 * clean on 32 bit machines.
7342 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7343 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
7344 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
7345 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
7346 LPFC_BMBX_BIT1_ADDR_HI
);
7348 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
7349 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
7350 LPFC_BMBX_BIT1_ADDR_LO
);
7355 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7356 * @phba: pointer to lpfc hba data structure.
7358 * This routine is invoked to teardown the bootstrap mailbox
7359 * region and release all host resources. This routine requires
7360 * the caller to ensure all mailbox commands recovered, no
7361 * additional mailbox comands are sent, and interrupts are disabled
7362 * before calling this routine.
7366 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
7368 dma_free_coherent(&phba
->pcidev
->dev
,
7369 phba
->sli4_hba
.bmbx
.bmbx_size
,
7370 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
7371 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
7373 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
7374 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
7378 * lpfc_sli4_read_config - Get the config parameters.
7379 * @phba: pointer to lpfc hba data structure.
7381 * This routine is invoked to read the configuration parameters from the HBA.
7382 * The configuration parameters are used to set the base and maximum values
7383 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7384 * allocation for the port.
7388 * -ENOMEM - No available memory
7389 * -EIO - The mailbox failed to complete successfully.
7392 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
7395 struct lpfc_mbx_read_config
*rd_config
;
7396 union lpfc_sli4_cfg_shdr
*shdr
;
7397 uint32_t shdr_status
, shdr_add_status
;
7398 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
7399 struct lpfc_rsrc_desc_fcfcoe
*desc
;
7401 uint16_t forced_link_speed
;
7403 int length
, i
, rc
= 0, rc2
;
7405 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7407 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7408 "2011 Unable to allocate memory for issuing "
7409 "SLI_CONFIG_SPECIAL mailbox command\n");
7413 lpfc_read_config(phba
, pmb
);
7415 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7416 if (rc
!= MBX_SUCCESS
) {
7417 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7418 "2012 Mailbox failed , mbxCmd x%x "
7419 "READ_CONFIG, mbxStatus x%x\n",
7420 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
7421 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
7424 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
7425 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
7426 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
7427 phba
->sli4_hba
.lnk_info
.lnk_tp
=
7428 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
7429 phba
->sli4_hba
.lnk_info
.lnk_no
=
7430 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
7431 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7432 "3081 lnk_type:%d, lnk_numb:%d\n",
7433 phba
->sli4_hba
.lnk_info
.lnk_tp
,
7434 phba
->sli4_hba
.lnk_info
.lnk_no
);
7436 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
7437 "3082 Mailbox (x%x) returned ldv:x0\n",
7438 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
7439 phba
->sli4_hba
.extents_in_use
=
7440 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
7441 phba
->sli4_hba
.max_cfg_param
.max_xri
=
7442 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
7443 phba
->sli4_hba
.max_cfg_param
.xri_base
=
7444 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
7445 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
7446 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
7447 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
7448 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
7449 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
7450 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
7451 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
7452 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
7453 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
7454 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
7455 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
7456 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
7457 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
7458 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
7459 phba
->sli4_hba
.max_cfg_param
.max_eq
=
7460 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
7461 phba
->sli4_hba
.max_cfg_param
.max_rq
=
7462 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
7463 phba
->sli4_hba
.max_cfg_param
.max_wq
=
7464 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
7465 phba
->sli4_hba
.max_cfg_param
.max_cq
=
7466 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
7467 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
7468 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
7469 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
7470 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
7471 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
7472 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
7473 phba
->max_vports
= phba
->max_vpi
;
7474 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7475 "2003 cfg params Extents? %d "
7480 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
7481 phba
->sli4_hba
.extents_in_use
,
7482 phba
->sli4_hba
.max_cfg_param
.xri_base
,
7483 phba
->sli4_hba
.max_cfg_param
.max_xri
,
7484 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
7485 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
7486 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
7487 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
7488 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
7489 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
7490 phba
->sli4_hba
.max_cfg_param
.max_fcfi
,
7491 phba
->sli4_hba
.max_cfg_param
.max_eq
,
7492 phba
->sli4_hba
.max_cfg_param
.max_cq
,
7493 phba
->sli4_hba
.max_cfg_param
.max_wq
,
7494 phba
->sli4_hba
.max_cfg_param
.max_rq
);
7501 /* Update link speed if forced link speed is supported */
7502 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7503 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7505 bf_get(lpfc_mbx_rd_conf_link_speed
, rd_config
);
7506 if (forced_link_speed
) {
7507 phba
->hba_flag
|= HBA_FORCED_LINK_SPEED
;
7509 switch (forced_link_speed
) {
7511 phba
->cfg_link_speed
=
7512 LPFC_USER_LINK_SPEED_1G
;
7515 phba
->cfg_link_speed
=
7516 LPFC_USER_LINK_SPEED_2G
;
7519 phba
->cfg_link_speed
=
7520 LPFC_USER_LINK_SPEED_4G
;
7523 phba
->cfg_link_speed
=
7524 LPFC_USER_LINK_SPEED_8G
;
7526 case LINK_SPEED_10G
:
7527 phba
->cfg_link_speed
=
7528 LPFC_USER_LINK_SPEED_10G
;
7530 case LINK_SPEED_16G
:
7531 phba
->cfg_link_speed
=
7532 LPFC_USER_LINK_SPEED_16G
;
7534 case LINK_SPEED_32G
:
7535 phba
->cfg_link_speed
=
7536 LPFC_USER_LINK_SPEED_32G
;
7539 phba
->cfg_link_speed
=
7540 LPFC_USER_LINK_SPEED_AUTO
;
7543 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7544 "0047 Unrecognized link "
7547 phba
->cfg_link_speed
=
7548 LPFC_USER_LINK_SPEED_AUTO
;
7553 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
7554 length
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
7555 lpfc_sli4_get_els_iocb_cnt(phba
);
7556 if (phba
->cfg_hba_queue_depth
> length
) {
7557 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7558 "3361 HBA queue depth changed from %d to %d\n",
7559 phba
->cfg_hba_queue_depth
, length
);
7560 phba
->cfg_hba_queue_depth
= length
;
7563 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
7564 LPFC_SLI_INTF_IF_TYPE_2
)
7567 /* get the pf# and vf# for SLI4 if_type 2 port */
7568 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
7569 sizeof(struct lpfc_sli4_cfg_mhdr
));
7570 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7571 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
7572 length
, LPFC_SLI4_MBX_EMBED
);
7574 rc2
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7575 shdr
= (union lpfc_sli4_cfg_shdr
*)
7576 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7577 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7578 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
7579 if (rc2
|| shdr_status
|| shdr_add_status
) {
7580 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7581 "3026 Mailbox failed , mbxCmd x%x "
7582 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7583 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
7584 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
7588 /* search for fc_fcoe resrouce descriptor */
7589 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
7591 pdesc_0
= (char *)&get_func_cfg
->func_cfg
.desc
[0];
7592 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)pdesc_0
;
7593 length
= bf_get(lpfc_rsrc_desc_fcfcoe_length
, desc
);
7594 if (length
== LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD
)
7595 length
= LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH
;
7596 else if (length
!= LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH
)
7599 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
7600 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)(pdesc_0
+ length
* i
);
7601 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
7602 bf_get(lpfc_rsrc_desc_fcfcoe_type
, desc
)) {
7603 phba
->sli4_hba
.iov
.pf_number
=
7604 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
7605 phba
->sli4_hba
.iov
.vf_number
=
7606 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
7611 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
7612 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
7613 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7614 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
7615 phba
->sli4_hba
.iov
.vf_number
);
7617 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7618 "3028 GET_FUNCTION_CONFIG: failed to find "
7619 "Resrouce Descriptor:x%x\n",
7620 LPFC_RSRC_DESC_TYPE_FCFCOE
);
7623 mempool_free(pmb
, phba
->mbox_mem_pool
);
7628 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
7629 * @phba: pointer to lpfc hba data structure.
7631 * This routine is invoked to setup the port-side endian order when
7632 * the port if_type is 0. This routine has no function for other
7637 * -ENOMEM - No available memory
7638 * -EIO - The mailbox failed to complete successfully.
7641 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
7643 LPFC_MBOXQ_t
*mboxq
;
7644 uint32_t if_type
, rc
= 0;
7645 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
7646 HOST_ENDIAN_HIGH_WORD1
};
7648 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7650 case LPFC_SLI_INTF_IF_TYPE_0
:
7651 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
7654 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7655 "0492 Unable to allocate memory for "
7656 "issuing SLI_CONFIG_SPECIAL mailbox "
7662 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7663 * two words to contain special data values and no other data.
7665 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
7666 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
7667 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7668 if (rc
!= MBX_SUCCESS
) {
7669 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7670 "0493 SLI_CONFIG_SPECIAL mailbox "
7671 "failed with status x%x\n",
7675 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7677 case LPFC_SLI_INTF_IF_TYPE_2
:
7678 case LPFC_SLI_INTF_IF_TYPE_1
:
7686 * lpfc_sli4_queue_verify - Verify and update EQ counts
7687 * @phba: pointer to lpfc hba data structure.
7689 * This routine is invoked to check the user settable queue counts for EQs.
7690 * After this routine is called the counts will be set to valid values that
7691 * adhere to the constraints of the system's interrupt vectors and the port's
7696 * -ENOMEM - No available memory
7699 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
7702 int fof_vectors
= phba
->cfg_fof
? 1 : 0;
7705 * Sanity check for configured queue parameters against the run-time
7709 /* Sanity check on HBA EQ parameters */
7710 io_channel
= phba
->io_channel_irqs
;
7712 if (phba
->sli4_hba
.num_online_cpu
< io_channel
) {
7713 lpfc_printf_log(phba
,
7715 "3188 Reducing IO channels to match number of "
7716 "online CPUs: from %d to %d\n",
7717 io_channel
, phba
->sli4_hba
.num_online_cpu
);
7718 io_channel
= phba
->sli4_hba
.num_online_cpu
;
7721 if (io_channel
+ fof_vectors
> phba
->sli4_hba
.max_cfg_param
.max_eq
) {
7722 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7723 "2575 Reducing IO channels to match number of "
7724 "available EQs: from %d to %d\n",
7726 phba
->sli4_hba
.max_cfg_param
.max_eq
);
7727 io_channel
= phba
->sli4_hba
.max_cfg_param
.max_eq
- fof_vectors
;
7730 /* The actual number of FCP / NVME event queues adopted */
7731 if (io_channel
!= phba
->io_channel_irqs
)
7732 phba
->io_channel_irqs
= io_channel
;
7733 if (phba
->cfg_fcp_io_channel
> io_channel
)
7734 phba
->cfg_fcp_io_channel
= io_channel
;
7735 if (phba
->cfg_nvme_io_channel
> io_channel
)
7736 phba
->cfg_nvme_io_channel
= io_channel
;
7737 if (phba
->cfg_nvme_io_channel
< phba
->cfg_nvmet_mrq
)
7738 phba
->cfg_nvmet_mrq
= phba
->cfg_nvme_io_channel
;
7740 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7741 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
7742 phba
->io_channel_irqs
, phba
->cfg_fcp_io_channel
,
7743 phba
->cfg_nvme_io_channel
, phba
->cfg_nvmet_mrq
);
7745 /* Get EQ depth from module parameter, fake the default for now */
7746 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
7747 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
7749 /* Get CQ depth from module parameter, fake the default for now */
7750 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
7751 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
7756 lpfc_alloc_nvme_wq_cq(struct lpfc_hba
*phba
, int wqidx
)
7758 struct lpfc_queue
*qdesc
;
7761 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7762 phba
->sli4_hba
.cq_ecount
);
7764 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7765 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7769 phba
->sli4_hba
.nvme_cq
[wqidx
] = qdesc
;
7771 cnt
= LPFC_NVME_WQSIZE
;
7772 qdesc
= lpfc_sli4_queue_alloc(phba
, LPFC_WQE128_SIZE
, cnt
);
7774 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7775 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7779 phba
->sli4_hba
.nvme_wq
[wqidx
] = qdesc
;
7780 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7785 lpfc_alloc_fcp_wq_cq(struct lpfc_hba
*phba
, int wqidx
)
7787 struct lpfc_queue
*qdesc
;
7790 /* Create Fast Path FCP CQs */
7791 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7792 phba
->sli4_hba
.cq_ecount
);
7794 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7795 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx
);
7798 phba
->sli4_hba
.fcp_cq
[wqidx
] = qdesc
;
7800 /* Create Fast Path FCP WQs */
7801 wqesize
= (phba
->fcp_embed_io
) ?
7802 LPFC_WQE128_SIZE
: phba
->sli4_hba
.wq_esize
;
7803 qdesc
= lpfc_sli4_queue_alloc(phba
, wqesize
, phba
->sli4_hba
.wq_ecount
);
7805 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7806 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7810 phba
->sli4_hba
.fcp_wq
[wqidx
] = qdesc
;
7811 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
7816 * lpfc_sli4_queue_create - Create all the SLI4 queues
7817 * @phba: pointer to lpfc hba data structure.
7819 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7820 * operation. For each SLI4 queue type, the parameters such as queue entry
7821 * count (queue depth) shall be taken from the module parameter. For now,
7822 * we just use some constant number as place holder.
7826 * -ENOMEM - No availble memory
7827 * -EIO - The mailbox failed to complete successfully.
7830 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
7832 struct lpfc_queue
*qdesc
;
7833 int idx
, io_channel
, max
;
7836 * Create HBA Record arrays.
7837 * Both NVME and FCP will share that same vectors / EQs
7839 io_channel
= phba
->io_channel_irqs
;
7843 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
7844 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
7845 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
7846 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
7847 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
7848 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
7849 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
7850 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
7851 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
7852 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
7854 phba
->sli4_hba
.hba_eq
= kcalloc(io_channel
,
7855 sizeof(struct lpfc_queue
*),
7857 if (!phba
->sli4_hba
.hba_eq
) {
7858 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7859 "2576 Failed allocate memory for "
7860 "fast-path EQ record array\n");
7864 if (phba
->cfg_fcp_io_channel
) {
7865 phba
->sli4_hba
.fcp_cq
= kcalloc(phba
->cfg_fcp_io_channel
,
7866 sizeof(struct lpfc_queue
*),
7868 if (!phba
->sli4_hba
.fcp_cq
) {
7869 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7870 "2577 Failed allocate memory for "
7871 "fast-path CQ record array\n");
7874 phba
->sli4_hba
.fcp_wq
= kcalloc(phba
->cfg_fcp_io_channel
,
7875 sizeof(struct lpfc_queue
*),
7877 if (!phba
->sli4_hba
.fcp_wq
) {
7878 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7879 "2578 Failed allocate memory for "
7880 "fast-path FCP WQ record array\n");
7884 * Since the first EQ can have multiple CQs associated with it,
7885 * this array is used to quickly see if we have a FCP fast-path
7888 phba
->sli4_hba
.fcp_cq_map
= kcalloc(phba
->cfg_fcp_io_channel
,
7891 if (!phba
->sli4_hba
.fcp_cq_map
) {
7892 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7893 "2545 Failed allocate memory for "
7894 "fast-path CQ map\n");
7899 if (phba
->cfg_nvme_io_channel
) {
7900 phba
->sli4_hba
.nvme_cq
= kcalloc(phba
->cfg_nvme_io_channel
,
7901 sizeof(struct lpfc_queue
*),
7903 if (!phba
->sli4_hba
.nvme_cq
) {
7904 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7905 "6077 Failed allocate memory for "
7906 "fast-path CQ record array\n");
7910 phba
->sli4_hba
.nvme_wq
= kcalloc(phba
->cfg_nvme_io_channel
,
7911 sizeof(struct lpfc_queue
*),
7913 if (!phba
->sli4_hba
.nvme_wq
) {
7914 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7915 "2581 Failed allocate memory for "
7916 "fast-path NVME WQ record array\n");
7921 * Since the first EQ can have multiple CQs associated with it,
7922 * this array is used to quickly see if we have a NVME fast-path
7925 phba
->sli4_hba
.nvme_cq_map
= kcalloc(phba
->cfg_nvme_io_channel
,
7928 if (!phba
->sli4_hba
.nvme_cq_map
) {
7929 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7930 "6078 Failed allocate memory for "
7931 "fast-path CQ map\n");
7935 if (phba
->nvmet_support
) {
7936 phba
->sli4_hba
.nvmet_cqset
= kcalloc(
7937 phba
->cfg_nvmet_mrq
,
7938 sizeof(struct lpfc_queue
*),
7940 if (!phba
->sli4_hba
.nvmet_cqset
) {
7941 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7942 "3121 Fail allocate memory for "
7943 "fast-path CQ set array\n");
7946 phba
->sli4_hba
.nvmet_mrq_hdr
= kcalloc(
7947 phba
->cfg_nvmet_mrq
,
7948 sizeof(struct lpfc_queue
*),
7950 if (!phba
->sli4_hba
.nvmet_mrq_hdr
) {
7951 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7952 "3122 Fail allocate memory for "
7953 "fast-path RQ set hdr array\n");
7956 phba
->sli4_hba
.nvmet_mrq_data
= kcalloc(
7957 phba
->cfg_nvmet_mrq
,
7958 sizeof(struct lpfc_queue
*),
7960 if (!phba
->sli4_hba
.nvmet_mrq_data
) {
7961 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7962 "3124 Fail allocate memory for "
7963 "fast-path RQ set data array\n");
7969 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
7971 /* Create HBA Event Queues (EQs) */
7972 for (idx
= 0; idx
< io_channel
; idx
++) {
7974 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
7975 phba
->sli4_hba
.eq_ecount
);
7977 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7978 "0497 Failed allocate EQ (%d)\n", idx
);
7981 phba
->sli4_hba
.hba_eq
[idx
] = qdesc
;
7984 /* FCP and NVME io channels are not required to be balanced */
7986 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++)
7987 if (lpfc_alloc_fcp_wq_cq(phba
, idx
))
7990 for (idx
= 0; idx
< phba
->cfg_nvme_io_channel
; idx
++)
7991 if (lpfc_alloc_nvme_wq_cq(phba
, idx
))
7994 /* allocate MRQ CQs */
7995 max
= phba
->cfg_nvme_io_channel
;
7996 if (max
< phba
->cfg_nvmet_mrq
)
7997 max
= phba
->cfg_nvmet_mrq
;
7999 for (idx
= 0; idx
< max
; idx
++)
8000 if (lpfc_alloc_nvme_wq_cq(phba
, idx
))
8003 if (phba
->nvmet_support
) {
8004 for (idx
= 0; idx
< phba
->cfg_nvmet_mrq
; idx
++) {
8005 qdesc
= lpfc_sli4_queue_alloc(phba
,
8006 phba
->sli4_hba
.cq_esize
,
8007 phba
->sli4_hba
.cq_ecount
);
8009 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8010 "3142 Failed allocate NVME "
8011 "CQ Set (%d)\n", idx
);
8014 phba
->sli4_hba
.nvmet_cqset
[idx
] = qdesc
;
8019 * Create Slow Path Completion Queues (CQs)
8022 /* Create slow-path Mailbox Command Complete Queue */
8023 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
8024 phba
->sli4_hba
.cq_ecount
);
8026 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8027 "0500 Failed allocate slow-path mailbox CQ\n");
8030 phba
->sli4_hba
.mbx_cq
= qdesc
;
8032 /* Create slow-path ELS Complete Queue */
8033 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
8034 phba
->sli4_hba
.cq_ecount
);
8036 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8037 "0501 Failed allocate slow-path ELS CQ\n");
8040 phba
->sli4_hba
.els_cq
= qdesc
;
8044 * Create Slow Path Work Queues (WQs)
8047 /* Create Mailbox Command Queue */
8049 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
8050 phba
->sli4_hba
.mq_ecount
);
8052 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8053 "0505 Failed allocate slow-path MQ\n");
8056 phba
->sli4_hba
.mbx_wq
= qdesc
;
8059 * Create ELS Work Queues
8062 /* Create slow-path ELS Work Queue */
8063 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
8064 phba
->sli4_hba
.wq_ecount
);
8066 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8067 "0504 Failed allocate slow-path ELS WQ\n");
8070 phba
->sli4_hba
.els_wq
= qdesc
;
8071 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
8073 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
8074 /* Create NVME LS Complete Queue */
8075 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
8076 phba
->sli4_hba
.cq_ecount
);
8078 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8079 "6079 Failed allocate NVME LS CQ\n");
8082 phba
->sli4_hba
.nvmels_cq
= qdesc
;
8084 /* Create NVME LS Work Queue */
8085 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
8086 phba
->sli4_hba
.wq_ecount
);
8088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8089 "6080 Failed allocate NVME LS WQ\n");
8092 phba
->sli4_hba
.nvmels_wq
= qdesc
;
8093 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
8097 * Create Receive Queue (RQ)
8100 /* Create Receive Queue for header */
8101 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
8102 phba
->sli4_hba
.rq_ecount
);
8104 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8105 "0506 Failed allocate receive HRQ\n");
8108 phba
->sli4_hba
.hdr_rq
= qdesc
;
8110 /* Create Receive Queue for data */
8111 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
8112 phba
->sli4_hba
.rq_ecount
);
8114 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8115 "0507 Failed allocate receive DRQ\n");
8118 phba
->sli4_hba
.dat_rq
= qdesc
;
8120 if (phba
->nvmet_support
) {
8121 for (idx
= 0; idx
< phba
->cfg_nvmet_mrq
; idx
++) {
8122 /* Create NVMET Receive Queue for header */
8123 qdesc
= lpfc_sli4_queue_alloc(phba
,
8124 phba
->sli4_hba
.rq_esize
,
8125 phba
->sli4_hba
.rq_ecount
);
8127 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8128 "3146 Failed allocate "
8132 phba
->sli4_hba
.nvmet_mrq_hdr
[idx
] = qdesc
;
8134 /* Only needed for header of RQ pair */
8135 qdesc
->rqbp
= kzalloc(sizeof(struct lpfc_rqb
),
8137 if (qdesc
->rqbp
== NULL
) {
8138 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8139 "6131 Failed allocate "
8144 /* Create NVMET Receive Queue for data */
8145 qdesc
= lpfc_sli4_queue_alloc(phba
,
8146 phba
->sli4_hba
.rq_esize
,
8147 phba
->sli4_hba
.rq_ecount
);
8149 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8150 "3156 Failed allocate "
8154 phba
->sli4_hba
.nvmet_mrq_data
[idx
] = qdesc
;
8158 /* Create the Queues needed for Flash Optimized Fabric operations */
8160 lpfc_fof_queue_create(phba
);
8164 lpfc_sli4_queue_destroy(phba
);
8169 __lpfc_sli4_release_queue(struct lpfc_queue
**qp
)
8172 lpfc_sli4_queue_free(*qp
);
8178 lpfc_sli4_release_queues(struct lpfc_queue
***qs
, int max
)
8185 for (idx
= 0; idx
< max
; idx
++)
8186 __lpfc_sli4_release_queue(&(*qs
)[idx
]);
8193 lpfc_sli4_release_queue_map(uint16_t **qmap
)
8195 if (*qmap
!= NULL
) {
8202 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8203 * @phba: pointer to lpfc hba data structure.
8205 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8210 * -ENOMEM - No available memory
8211 * -EIO - The mailbox failed to complete successfully.
8214 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
8217 lpfc_fof_queue_destroy(phba
);
8219 /* Release HBA eqs */
8220 lpfc_sli4_release_queues(&phba
->sli4_hba
.hba_eq
, phba
->io_channel_irqs
);
8222 /* Release FCP cqs */
8223 lpfc_sli4_release_queues(&phba
->sli4_hba
.fcp_cq
,
8224 phba
->cfg_fcp_io_channel
);
8226 /* Release FCP wqs */
8227 lpfc_sli4_release_queues(&phba
->sli4_hba
.fcp_wq
,
8228 phba
->cfg_fcp_io_channel
);
8230 /* Release FCP CQ mapping array */
8231 lpfc_sli4_release_queue_map(&phba
->sli4_hba
.fcp_cq_map
);
8233 /* Release NVME cqs */
8234 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvme_cq
,
8235 phba
->cfg_nvme_io_channel
);
8237 /* Release NVME wqs */
8238 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvme_wq
,
8239 phba
->cfg_nvme_io_channel
);
8241 /* Release NVME CQ mapping array */
8242 lpfc_sli4_release_queue_map(&phba
->sli4_hba
.nvme_cq_map
);
8244 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_cqset
,
8245 phba
->cfg_nvmet_mrq
);
8247 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_mrq_hdr
,
8248 phba
->cfg_nvmet_mrq
);
8249 lpfc_sli4_release_queues(&phba
->sli4_hba
.nvmet_mrq_data
,
8250 phba
->cfg_nvmet_mrq
);
8252 /* Release mailbox command work queue */
8253 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_wq
);
8255 /* Release ELS work queue */
8256 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_wq
);
8258 /* Release ELS work queue */
8259 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_wq
);
8261 /* Release unsolicited receive queue */
8262 __lpfc_sli4_release_queue(&phba
->sli4_hba
.hdr_rq
);
8263 __lpfc_sli4_release_queue(&phba
->sli4_hba
.dat_rq
);
8265 /* Release ELS complete queue */
8266 __lpfc_sli4_release_queue(&phba
->sli4_hba
.els_cq
);
8268 /* Release NVME LS complete queue */
8269 __lpfc_sli4_release_queue(&phba
->sli4_hba
.nvmels_cq
);
8271 /* Release mailbox command complete queue */
8272 __lpfc_sli4_release_queue(&phba
->sli4_hba
.mbx_cq
);
8274 /* Everything on this list has been freed */
8275 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_wq_list
);
8279 lpfc_post_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
8280 struct lpfc_queue
*drq
, int count
)
8283 struct lpfc_rqe hrqe
;
8284 struct lpfc_rqe drqe
;
8285 struct lpfc_rqb
*rqbp
;
8286 struct rqb_dmabuf
*rqb_buffer
;
8287 LIST_HEAD(rqb_buf_list
);
8290 for (i
= 0; i
< count
; i
++) {
8291 rqb_buffer
= (rqbp
->rqb_alloc_buffer
)(phba
);
8294 rqb_buffer
->hrq
= hrq
;
8295 rqb_buffer
->drq
= drq
;
8296 list_add_tail(&rqb_buffer
->hbuf
.list
, &rqb_buf_list
);
8298 while (!list_empty(&rqb_buf_list
)) {
8299 list_remove_head(&rqb_buf_list
, rqb_buffer
, struct rqb_dmabuf
,
8302 hrqe
.address_lo
= putPaddrLow(rqb_buffer
->hbuf
.phys
);
8303 hrqe
.address_hi
= putPaddrHigh(rqb_buffer
->hbuf
.phys
);
8304 drqe
.address_lo
= putPaddrLow(rqb_buffer
->dbuf
.phys
);
8305 drqe
.address_hi
= putPaddrHigh(rqb_buffer
->dbuf
.phys
);
8306 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
8308 (rqbp
->rqb_free_buffer
)(phba
, rqb_buffer
);
8310 list_add_tail(&rqb_buffer
->hbuf
.list
,
8311 &rqbp
->rqb_buffer_list
);
8312 rqbp
->buffer_count
++;
8319 lpfc_free_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
)
8321 struct lpfc_rqb
*rqbp
;
8322 struct lpfc_dmabuf
*h_buf
;
8323 struct rqb_dmabuf
*rqb_buffer
;
8326 while (!list_empty(&rqbp
->rqb_buffer_list
)) {
8327 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
8328 struct lpfc_dmabuf
, list
);
8330 rqb_buffer
= container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
8331 (rqbp
->rqb_free_buffer
)(phba
, rqb_buffer
);
8332 rqbp
->buffer_count
--;
8338 lpfc_create_wq_cq(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
,
8339 struct lpfc_queue
*cq
, struct lpfc_queue
*wq
, uint16_t *cq_map
,
8340 int qidx
, uint32_t qtype
)
8342 struct lpfc_sli_ring
*pring
;
8345 if (!eq
|| !cq
|| !wq
) {
8346 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8347 "6085 Fast-path %s (%d) not allocated\n",
8348 ((eq
) ? ((cq
) ? "WQ" : "CQ") : "EQ"), qidx
);
8352 /* create the Cq first */
8353 rc
= lpfc_cq_create(phba
, cq
, eq
,
8354 (qtype
== LPFC_MBOX
) ? LPFC_MCQ
: LPFC_WCQ
, qtype
);
8356 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8357 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8358 qidx
, (uint32_t)rc
);
8362 if (qtype
!= LPFC_MBOX
) {
8363 /* Setup nvme_cq_map for fast lookup */
8365 *cq_map
= cq
->queue_id
;
8367 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8368 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8369 qidx
, cq
->queue_id
, qidx
, eq
->queue_id
);
8372 rc
= lpfc_wq_create(phba
, wq
, cq
, qtype
);
8374 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8375 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8376 qidx
, (uint32_t)rc
);
8377 /* no need to tear down cq - caller will do so */
8381 /* Bind this CQ/WQ to the NVME ring */
8383 pring
->sli
.sli4
.wqp
= (void *)wq
;
8386 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8387 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8388 qidx
, wq
->queue_id
, wq
->assoc_qid
, qidx
, cq
->queue_id
);
8390 rc
= lpfc_mq_create(phba
, wq
, cq
, LPFC_MBOX
);
8392 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8393 "0539 Failed setup of slow-path MQ: "
8395 /* no need to tear down cq - caller will do so */
8399 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8400 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8401 phba
->sli4_hba
.mbx_wq
->queue_id
,
8402 phba
->sli4_hba
.mbx_cq
->queue_id
);
8409 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8410 * @phba: pointer to lpfc hba data structure.
8412 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8417 * -ENOMEM - No available memory
8418 * -EIO - The mailbox failed to complete successfully.
8421 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
8423 uint32_t shdr_status
, shdr_add_status
;
8424 union lpfc_sli4_cfg_shdr
*shdr
;
8425 LPFC_MBOXQ_t
*mboxq
;
8427 uint32_t length
, io_channel
;
8430 /* Check for dual-ULP support */
8431 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8434 "3249 Unable to allocate memory for "
8435 "QUERY_FW_CFG mailbox command\n");
8438 length
= (sizeof(struct lpfc_mbx_query_fw_config
) -
8439 sizeof(struct lpfc_sli4_cfg_mhdr
));
8440 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8441 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
8442 length
, LPFC_SLI4_MBX_EMBED
);
8444 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8446 shdr
= (union lpfc_sli4_cfg_shdr
*)
8447 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
8448 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
8449 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
8450 if (shdr_status
|| shdr_add_status
|| rc
) {
8451 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8452 "3250 QUERY_FW_CFG mailbox failed with status "
8453 "x%x add_status x%x, mbx status x%x\n",
8454 shdr_status
, shdr_add_status
, rc
);
8455 if (rc
!= MBX_TIMEOUT
)
8456 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8461 phba
->sli4_hba
.fw_func_mode
=
8462 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.function_mode
;
8463 phba
->sli4_hba
.ulp0_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp0_mode
;
8464 phba
->sli4_hba
.ulp1_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp1_mode
;
8465 phba
->sli4_hba
.physical_port
=
8466 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.physical_port
;
8467 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8468 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8469 "ulp1_mode:x%x\n", phba
->sli4_hba
.fw_func_mode
,
8470 phba
->sli4_hba
.ulp0_mode
, phba
->sli4_hba
.ulp1_mode
);
8472 if (rc
!= MBX_TIMEOUT
)
8473 mempool_free(mboxq
, phba
->mbox_mem_pool
);
8476 * Set up HBA Event Queues (EQs)
8478 io_channel
= phba
->io_channel_irqs
;
8480 /* Set up HBA event queue */
8481 if (io_channel
&& !phba
->sli4_hba
.hba_eq
) {
8482 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8483 "3147 Fast-path EQs not allocated\n");
8487 for (qidx
= 0; qidx
< io_channel
; qidx
++) {
8488 if (!phba
->sli4_hba
.hba_eq
[qidx
]) {
8489 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8490 "0522 Fast-path EQ (%d) not "
8491 "allocated\n", qidx
);
8495 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.hba_eq
[qidx
],
8496 phba
->cfg_fcp_imax
);
8498 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8499 "0523 Failed setup of fast-path EQ "
8500 "(%d), rc = 0x%x\n", qidx
,
8504 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8505 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8506 qidx
, phba
->sli4_hba
.hba_eq
[qidx
]->queue_id
);
8509 if (phba
->cfg_nvme_io_channel
) {
8510 if (!phba
->sli4_hba
.nvme_cq
|| !phba
->sli4_hba
.nvme_wq
) {
8511 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8512 "6084 Fast-path NVME %s array not allocated\n",
8513 (phba
->sli4_hba
.nvme_cq
) ? "CQ" : "WQ");
8518 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++) {
8519 rc
= lpfc_create_wq_cq(phba
,
8520 phba
->sli4_hba
.hba_eq
[
8522 phba
->sli4_hba
.nvme_cq
[qidx
],
8523 phba
->sli4_hba
.nvme_wq
[qidx
],
8524 &phba
->sli4_hba
.nvme_cq_map
[qidx
],
8527 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8528 "6123 Failed to setup fastpath "
8529 "NVME WQ/CQ (%d), rc = 0x%x\n",
8530 qidx
, (uint32_t)rc
);
8536 if (phba
->cfg_fcp_io_channel
) {
8537 /* Set up fast-path FCP Response Complete Queue */
8538 if (!phba
->sli4_hba
.fcp_cq
|| !phba
->sli4_hba
.fcp_wq
) {
8539 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8540 "3148 Fast-path FCP %s array not allocated\n",
8541 phba
->sli4_hba
.fcp_cq
? "WQ" : "CQ");
8546 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++) {
8547 rc
= lpfc_create_wq_cq(phba
,
8548 phba
->sli4_hba
.hba_eq
[
8550 phba
->sli4_hba
.fcp_cq
[qidx
],
8551 phba
->sli4_hba
.fcp_wq
[qidx
],
8552 &phba
->sli4_hba
.fcp_cq_map
[qidx
],
8555 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8556 "0535 Failed to setup fastpath "
8557 "FCP WQ/CQ (%d), rc = 0x%x\n",
8558 qidx
, (uint32_t)rc
);
8565 * Set up Slow Path Complete Queues (CQs)
8568 /* Set up slow-path MBOX CQ/MQ */
8570 if (!phba
->sli4_hba
.mbx_cq
|| !phba
->sli4_hba
.mbx_wq
) {
8571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8572 "0528 %s not allocated\n",
8573 phba
->sli4_hba
.mbx_cq
?
8574 "Mailbox WQ" : "Mailbox CQ");
8579 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8580 phba
->sli4_hba
.mbx_cq
,
8581 phba
->sli4_hba
.mbx_wq
,
8582 NULL
, 0, LPFC_MBOX
);
8584 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8585 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8589 if (phba
->nvmet_support
) {
8590 if (!phba
->sli4_hba
.nvmet_cqset
) {
8591 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8592 "3165 Fast-path NVME CQ Set "
8593 "array not allocated\n");
8597 if (phba
->cfg_nvmet_mrq
> 1) {
8598 rc
= lpfc_cq_create_set(phba
,
8599 phba
->sli4_hba
.nvmet_cqset
,
8600 phba
->sli4_hba
.hba_eq
,
8601 LPFC_WCQ
, LPFC_NVMET
);
8603 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8604 "3164 Failed setup of NVME CQ "
8610 /* Set up NVMET Receive Complete Queue */
8611 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.nvmet_cqset
[0],
8612 phba
->sli4_hba
.hba_eq
[0],
8613 LPFC_WCQ
, LPFC_NVMET
);
8615 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8616 "6089 Failed setup NVMET CQ: "
8617 "rc = 0x%x\n", (uint32_t)rc
);
8620 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8621 "6090 NVMET CQ setup: cq-id=%d, "
8622 "parent eq-id=%d\n",
8623 phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
,
8624 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
8628 /* Set up slow-path ELS WQ/CQ */
8629 if (!phba
->sli4_hba
.els_cq
|| !phba
->sli4_hba
.els_wq
) {
8630 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8631 "0530 ELS %s not allocated\n",
8632 phba
->sli4_hba
.els_cq
? "WQ" : "CQ");
8636 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8637 phba
->sli4_hba
.els_cq
,
8638 phba
->sli4_hba
.els_wq
,
8641 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8642 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8646 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8647 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8648 phba
->sli4_hba
.els_wq
->queue_id
,
8649 phba
->sli4_hba
.els_cq
->queue_id
);
8651 if (phba
->cfg_nvme_io_channel
) {
8652 /* Set up NVME LS Complete Queue */
8653 if (!phba
->sli4_hba
.nvmels_cq
|| !phba
->sli4_hba
.nvmels_wq
) {
8654 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8655 "6091 LS %s not allocated\n",
8656 phba
->sli4_hba
.nvmels_cq
? "WQ" : "CQ");
8660 rc
= lpfc_create_wq_cq(phba
, phba
->sli4_hba
.hba_eq
[0],
8661 phba
->sli4_hba
.nvmels_cq
,
8662 phba
->sli4_hba
.nvmels_wq
,
8663 NULL
, 0, LPFC_NVME_LS
);
8665 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8666 "0529 Failed setup of NVVME LS WQ/CQ: "
8667 "rc = 0x%x\n", (uint32_t)rc
);
8671 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8672 "6096 ELS WQ setup: wq-id=%d, "
8673 "parent cq-id=%d\n",
8674 phba
->sli4_hba
.nvmels_wq
->queue_id
,
8675 phba
->sli4_hba
.nvmels_cq
->queue_id
);
8679 * Create NVMET Receive Queue (RQ)
8681 if (phba
->nvmet_support
) {
8682 if ((!phba
->sli4_hba
.nvmet_cqset
) ||
8683 (!phba
->sli4_hba
.nvmet_mrq_hdr
) ||
8684 (!phba
->sli4_hba
.nvmet_mrq_data
)) {
8685 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8686 "6130 MRQ CQ Queues not "
8691 if (phba
->cfg_nvmet_mrq
> 1) {
8692 rc
= lpfc_mrq_create(phba
,
8693 phba
->sli4_hba
.nvmet_mrq_hdr
,
8694 phba
->sli4_hba
.nvmet_mrq_data
,
8695 phba
->sli4_hba
.nvmet_cqset
,
8698 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8699 "6098 Failed setup of NVMET "
8706 rc
= lpfc_rq_create(phba
,
8707 phba
->sli4_hba
.nvmet_mrq_hdr
[0],
8708 phba
->sli4_hba
.nvmet_mrq_data
[0],
8709 phba
->sli4_hba
.nvmet_cqset
[0],
8712 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8713 "6057 Failed setup of NVMET "
8714 "Receive Queue: rc = 0x%x\n",
8720 phba
, KERN_INFO
, LOG_INIT
,
8721 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8722 "dat-rq-id=%d parent cq-id=%d\n",
8723 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
,
8724 phba
->sli4_hba
.nvmet_mrq_data
[0]->queue_id
,
8725 phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
);
8730 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
8731 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8732 "0540 Receive Queue not allocated\n");
8737 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.hdr_rq
, LPFC_ELS_HBQ
);
8738 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.dat_rq
, LPFC_ELS_HBQ
);
8740 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
8741 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
8743 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8744 "0541 Failed setup of Receive Queue: "
8745 "rc = 0x%x\n", (uint32_t)rc
);
8749 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8750 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8751 "parent cq-id=%d\n",
8752 phba
->sli4_hba
.hdr_rq
->queue_id
,
8753 phba
->sli4_hba
.dat_rq
->queue_id
,
8754 phba
->sli4_hba
.els_cq
->queue_id
);
8756 if (phba
->cfg_fof
) {
8757 rc
= lpfc_fof_queue_setup(phba
);
8759 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8760 "0549 Failed setup of FOF Queues: "
8766 for (qidx
= 0; qidx
< io_channel
; qidx
+= LPFC_MAX_EQ_DELAY_EQID_CNT
)
8767 lpfc_modify_hba_eq_delay(phba
, qidx
);
8772 lpfc_sli4_queue_unset(phba
);
8778 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8779 * @phba: pointer to lpfc hba data structure.
8781 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8786 * -ENOMEM - No available memory
8787 * -EIO - The mailbox failed to complete successfully.
8790 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
8794 /* Unset the queues created for Flash Optimized Fabric operations */
8796 lpfc_fof_queue_destroy(phba
);
8798 /* Unset mailbox command work queue */
8799 if (phba
->sli4_hba
.mbx_wq
)
8800 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
8802 /* Unset NVME LS work queue */
8803 if (phba
->sli4_hba
.nvmels_wq
)
8804 lpfc_wq_destroy(phba
, phba
->sli4_hba
.nvmels_wq
);
8806 /* Unset ELS work queue */
8807 if (phba
->sli4_hba
.els_cq
)
8808 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
8810 /* Unset unsolicited receive queue */
8811 if (phba
->sli4_hba
.hdr_rq
)
8812 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
,
8813 phba
->sli4_hba
.dat_rq
);
8815 /* Unset FCP work queue */
8816 if (phba
->sli4_hba
.fcp_wq
)
8817 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
8818 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[qidx
]);
8820 /* Unset NVME work queue */
8821 if (phba
->sli4_hba
.nvme_wq
) {
8822 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
8823 lpfc_wq_destroy(phba
, phba
->sli4_hba
.nvme_wq
[qidx
]);
8826 /* Unset mailbox command complete queue */
8827 if (phba
->sli4_hba
.mbx_cq
)
8828 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
8830 /* Unset ELS complete queue */
8831 if (phba
->sli4_hba
.els_cq
)
8832 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
8834 /* Unset NVME LS complete queue */
8835 if (phba
->sli4_hba
.nvmels_cq
)
8836 lpfc_cq_destroy(phba
, phba
->sli4_hba
.nvmels_cq
);
8838 /* Unset NVME response complete queue */
8839 if (phba
->sli4_hba
.nvme_cq
)
8840 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
8841 lpfc_cq_destroy(phba
, phba
->sli4_hba
.nvme_cq
[qidx
]);
8843 /* Unset NVMET MRQ queue */
8844 if (phba
->sli4_hba
.nvmet_mrq_hdr
) {
8845 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++)
8846 lpfc_rq_destroy(phba
,
8847 phba
->sli4_hba
.nvmet_mrq_hdr
[qidx
],
8848 phba
->sli4_hba
.nvmet_mrq_data
[qidx
]);
8851 /* Unset NVMET CQ Set complete queue */
8852 if (phba
->sli4_hba
.nvmet_cqset
) {
8853 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++)
8854 lpfc_cq_destroy(phba
,
8855 phba
->sli4_hba
.nvmet_cqset
[qidx
]);
8858 /* Unset FCP response complete queue */
8859 if (phba
->sli4_hba
.fcp_cq
)
8860 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
8861 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[qidx
]);
8863 /* Unset fast-path event queue */
8864 if (phba
->sli4_hba
.hba_eq
)
8865 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++)
8866 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[qidx
]);
8870 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8871 * @phba: pointer to lpfc hba data structure.
8873 * This routine is invoked to allocate and set up a pool of completion queue
8874 * events. The body of the completion queue event is a completion queue entry
8875 * CQE. For now, this pool is used for the interrupt service routine to queue
8876 * the following HBA completion queue events for the worker thread to process:
8877 * - Mailbox asynchronous events
8878 * - Receive queue completion unsolicited events
8879 * Later, this can be used for all the slow-path events.
8883 * -ENOMEM - No available memory
8886 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
8888 struct lpfc_cq_event
*cq_event
;
8891 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
8892 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
8894 goto out_pool_create_fail
;
8895 list_add_tail(&cq_event
->list
,
8896 &phba
->sli4_hba
.sp_cqe_event_pool
);
8900 out_pool_create_fail
:
8901 lpfc_sli4_cq_event_pool_destroy(phba
);
8906 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8907 * @phba: pointer to lpfc hba data structure.
8909 * This routine is invoked to free the pool of completion queue events at
8910 * driver unload time. Note that, it is the responsibility of the driver
8911 * cleanup routine to free all the outstanding completion-queue events
8912 * allocated from this pool back into the pool before invoking this routine
8913 * to destroy the pool.
8916 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
8918 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
8920 list_for_each_entry_safe(cq_event
, next_cq_event
,
8921 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
8922 list_del(&cq_event
->list
);
8928 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8929 * @phba: pointer to lpfc hba data structure.
8931 * This routine is the lock free version of the API invoked to allocate a
8932 * completion-queue event from the free pool.
8934 * Return: Pointer to the newly allocated completion-queue event if successful
8937 struct lpfc_cq_event
*
8938 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
8940 struct lpfc_cq_event
*cq_event
= NULL
;
8942 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
8943 struct lpfc_cq_event
, list
);
8948 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8949 * @phba: pointer to lpfc hba data structure.
8951 * This routine is the lock version of the API invoked to allocate a
8952 * completion-queue event from the free pool.
8954 * Return: Pointer to the newly allocated completion-queue event if successful
8957 struct lpfc_cq_event
*
8958 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
8960 struct lpfc_cq_event
*cq_event
;
8961 unsigned long iflags
;
8963 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8964 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
8965 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8970 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8971 * @phba: pointer to lpfc hba data structure.
8972 * @cq_event: pointer to the completion queue event to be freed.
8974 * This routine is the lock free version of the API invoked to release a
8975 * completion-queue event back into the free pool.
8978 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
8979 struct lpfc_cq_event
*cq_event
)
8981 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
8985 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8986 * @phba: pointer to lpfc hba data structure.
8987 * @cq_event: pointer to the completion queue event to be freed.
8989 * This routine is the lock version of the API invoked to release a
8990 * completion-queue event back into the free pool.
8993 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
8994 struct lpfc_cq_event
*cq_event
)
8996 unsigned long iflags
;
8997 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8998 __lpfc_sli4_cq_event_release(phba
, cq_event
);
8999 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9003 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9004 * @phba: pointer to lpfc hba data structure.
9006 * This routine is to free all the pending completion-queue events to the
9007 * back into the free pool for device reset.
9010 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
9013 struct lpfc_cq_event
*cqe
;
9014 unsigned long iflags
;
9016 /* Retrieve all the pending WCQEs from pending WCQE lists */
9017 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9018 /* Pending FCP XRI abort events */
9019 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
9021 /* Pending ELS XRI abort events */
9022 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
9024 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
9025 /* Pending NVME XRI abort events */
9026 list_splice_init(&phba
->sli4_hba
.sp_nvme_xri_aborted_work_queue
,
9029 /* Pending asynnc events */
9030 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
9032 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9034 while (!list_empty(&cqelist
)) {
9035 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
9036 lpfc_sli4_cq_event_release(phba
, cqe
);
9041 * lpfc_pci_function_reset - Reset pci function.
9042 * @phba: pointer to lpfc hba data structure.
9044 * This routine is invoked to request a PCI function reset. It will destroys
9045 * all resources assigned to the PCI function which originates this request.
9049 * -ENOMEM - No available memory
9050 * -EIO - The mailbox failed to complete successfully.
9053 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
9055 LPFC_MBOXQ_t
*mboxq
;
9056 uint32_t rc
= 0, if_type
;
9057 uint32_t shdr_status
, shdr_add_status
;
9059 uint32_t port_reset
= 0;
9060 union lpfc_sli4_cfg_shdr
*shdr
;
9061 struct lpfc_register reg_data
;
9064 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9066 case LPFC_SLI_INTF_IF_TYPE_0
:
9067 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
9070 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9071 "0494 Unable to allocate memory for "
9072 "issuing SLI_FUNCTION_RESET mailbox "
9077 /* Setup PCI function reset mailbox-ioctl command */
9078 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9079 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
9080 LPFC_SLI4_MBX_EMBED
);
9081 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9082 shdr
= (union lpfc_sli4_cfg_shdr
*)
9083 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
9084 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
9085 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
9087 if (rc
!= MBX_TIMEOUT
)
9088 mempool_free(mboxq
, phba
->mbox_mem_pool
);
9089 if (shdr_status
|| shdr_add_status
|| rc
) {
9090 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9091 "0495 SLI_FUNCTION_RESET mailbox "
9092 "failed with status x%x add_status x%x,"
9093 " mbx status x%x\n",
9094 shdr_status
, shdr_add_status
, rc
);
9098 case LPFC_SLI_INTF_IF_TYPE_2
:
9101 * Poll the Port Status Register and wait for RDY for
9102 * up to 30 seconds. If the port doesn't respond, treat
9105 for (rdy_chk
= 0; rdy_chk
< 1500; rdy_chk
++) {
9106 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
9107 STATUSregaddr
, ®_data
.word0
)) {
9111 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
9116 if (!bf_get(lpfc_sliport_status_rdy
, ®_data
)) {
9117 phba
->work_status
[0] = readl(
9118 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
9119 phba
->work_status
[1] = readl(
9120 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
9121 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9122 "2890 Port not ready, port status reg "
9123 "0x%x error 1=0x%x, error 2=0x%x\n",
9125 phba
->work_status
[0],
9126 phba
->work_status
[1]);
9133 * Reset the port now
9136 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
9137 LPFC_SLIPORT_LITTLE_ENDIAN
);
9138 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
9139 LPFC_SLIPORT_INIT_PORT
);
9140 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
9143 pci_read_config_word(phba
->pcidev
,
9144 PCI_DEVICE_ID
, &devid
);
9149 } else if (bf_get(lpfc_sliport_status_rn
, ®_data
)) {
9155 case LPFC_SLI_INTF_IF_TYPE_1
:
9161 /* Catch the not-ready port failure after a port reset. */
9163 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9164 "3317 HBA not functional: IP Reset Failed "
9165 "try: echo fw_reset > board_mode\n");
9173 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9174 * @phba: pointer to lpfc hba data structure.
9176 * This routine is invoked to set up the PCI device memory space for device
9177 * with SLI-4 interface spec.
9181 * other values - error
9184 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
9186 struct pci_dev
*pdev
;
9187 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
9188 int error
= -ENODEV
;
9191 /* Obtain PCI device reference */
9195 pdev
= phba
->pcidev
;
9197 /* Set the device DMA mask size */
9198 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
9199 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
9200 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
9201 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
9207 * The BARs and register set definitions and offset locations are
9208 * dependent on the if_type.
9210 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
9211 &phba
->sli4_hba
.sli_intf
.word0
)) {
9215 /* There is no SLI3 failback for SLI4 devices. */
9216 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
9217 LPFC_SLI_INTF_VALID
) {
9218 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9219 "2894 SLI_INTF reg contents invalid "
9220 "sli_intf reg 0x%x\n",
9221 phba
->sli4_hba
.sli_intf
.word0
);
9225 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9227 * Get the bus address of SLI4 device Bar regions and the
9228 * number of bytes required by each mapping. The mapping of the
9229 * particular PCI BARs regions is dependent on the type of
9232 if (pci_resource_start(pdev
, PCI_64BIT_BAR0
)) {
9233 phba
->pci_bar0_map
= pci_resource_start(pdev
, PCI_64BIT_BAR0
);
9234 bar0map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR0
);
9237 * Map SLI4 PCI Config Space Register base to a kernel virtual
9240 phba
->sli4_hba
.conf_regs_memmap_p
=
9241 ioremap(phba
->pci_bar0_map
, bar0map_len
);
9242 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
9243 dev_printk(KERN_ERR
, &pdev
->dev
,
9244 "ioremap failed for SLI4 PCI config "
9248 phba
->pci_bar0_memmap_p
= phba
->sli4_hba
.conf_regs_memmap_p
;
9249 /* Set up BAR0 PCI config space register memory map */
9250 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
9252 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
9253 bar0map_len
= pci_resource_len(pdev
, 1);
9254 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
9255 dev_printk(KERN_ERR
, &pdev
->dev
,
9256 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9259 phba
->sli4_hba
.conf_regs_memmap_p
=
9260 ioremap(phba
->pci_bar0_map
, bar0map_len
);
9261 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
9262 dev_printk(KERN_ERR
, &pdev
->dev
,
9263 "ioremap failed for SLI4 PCI config "
9267 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
9270 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
9271 (pci_resource_start(pdev
, PCI_64BIT_BAR2
))) {
9273 * Map SLI4 if type 0 HBA Control Register base to a kernel
9274 * virtual address and setup the registers.
9276 phba
->pci_bar1_map
= pci_resource_start(pdev
, PCI_64BIT_BAR2
);
9277 bar1map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR2
);
9278 phba
->sli4_hba
.ctrl_regs_memmap_p
=
9279 ioremap(phba
->pci_bar1_map
, bar1map_len
);
9280 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
9281 dev_printk(KERN_ERR
, &pdev
->dev
,
9282 "ioremap failed for SLI4 HBA control registers.\n");
9283 goto out_iounmap_conf
;
9285 phba
->pci_bar2_memmap_p
= phba
->sli4_hba
.ctrl_regs_memmap_p
;
9286 lpfc_sli4_bar1_register_memmap(phba
);
9289 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
9290 (pci_resource_start(pdev
, PCI_64BIT_BAR4
))) {
9292 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
9293 * virtual address and setup the registers.
9295 phba
->pci_bar2_map
= pci_resource_start(pdev
, PCI_64BIT_BAR4
);
9296 bar2map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR4
);
9297 phba
->sli4_hba
.drbl_regs_memmap_p
=
9298 ioremap(phba
->pci_bar2_map
, bar2map_len
);
9299 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
9300 dev_printk(KERN_ERR
, &pdev
->dev
,
9301 "ioremap failed for SLI4 HBA doorbell registers.\n");
9302 goto out_iounmap_ctrl
;
9304 phba
->pci_bar4_memmap_p
= phba
->sli4_hba
.drbl_regs_memmap_p
;
9305 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
9307 goto out_iounmap_all
;
9313 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
9315 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
9317 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9323 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9324 * @phba: pointer to lpfc hba data structure.
9326 * This routine is invoked to unset the PCI device memory space for device
9327 * with SLI-4 interface spec.
9330 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
9333 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
9336 case LPFC_SLI_INTF_IF_TYPE_0
:
9337 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
9338 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
9339 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9341 case LPFC_SLI_INTF_IF_TYPE_2
:
9342 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
9344 case LPFC_SLI_INTF_IF_TYPE_1
:
9346 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
9347 "FATAL - unsupported SLI4 interface type - %d\n",
9354 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9355 * @phba: pointer to lpfc hba data structure.
9357 * This routine is invoked to enable the MSI-X interrupt vectors to device
9358 * with SLI-3 interface specs.
9362 * other values - error
9365 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
9370 /* Set up MSI-X multi-message vectors */
9371 rc
= pci_alloc_irq_vectors(phba
->pcidev
,
9372 LPFC_MSIX_VECTORS
, LPFC_MSIX_VECTORS
, PCI_IRQ_MSIX
);
9374 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9375 "0420 PCI enable MSI-X failed (%d)\n", rc
);
9380 * Assign MSI-X vectors to interrupt handlers
9383 /* vector-0 is associated to slow-path handler */
9384 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 0),
9385 &lpfc_sli_sp_intr_handler
, 0,
9386 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
9388 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9389 "0421 MSI-X slow-path request_irq failed "
9394 /* vector-1 is associated to fast-path handler */
9395 rc
= request_irq(pci_irq_vector(phba
->pcidev
, 1),
9396 &lpfc_sli_fp_intr_handler
, 0,
9397 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
9400 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9401 "0429 MSI-X fast-path request_irq failed "
9407 * Configure HBA MSI-X attention conditions to messages
9409 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
9413 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9414 "0474 Unable to allocate memory for issuing "
9415 "MBOX_CONFIG_MSI command\n");
9418 rc
= lpfc_config_msi(phba
, pmb
);
9421 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
9422 if (rc
!= MBX_SUCCESS
) {
9423 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
9424 "0351 Config MSI mailbox command failed, "
9425 "mbxCmd x%x, mbxStatus x%x\n",
9426 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
9430 /* Free memory allocated for mailbox command */
9431 mempool_free(pmb
, phba
->mbox_mem_pool
);
9435 /* Free memory allocated for mailbox command */
9436 mempool_free(pmb
, phba
->mbox_mem_pool
);
9439 /* free the irq already requested */
9440 free_irq(pci_irq_vector(phba
->pcidev
, 1), phba
);
9443 /* free the irq already requested */
9444 free_irq(pci_irq_vector(phba
->pcidev
, 0), phba
);
9447 /* Unconfigure MSI-X capability structure */
9448 pci_free_irq_vectors(phba
->pcidev
);
9455 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9456 * @phba: pointer to lpfc hba data structure.
9458 * This routine is invoked to enable the MSI interrupt mode to device with
9459 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9460 * enable the MSI vector. The device driver is responsible for calling the
9461 * request_irq() to register MSI vector with a interrupt the handler, which
9462 * is done in this function.
9466 * other values - error
9469 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
9473 rc
= pci_enable_msi(phba
->pcidev
);
9475 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9476 "0462 PCI enable MSI mode success.\n");
9478 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9479 "0471 PCI enable MSI mode failed (%d)\n", rc
);
9483 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
9484 0, LPFC_DRIVER_NAME
, phba
);
9486 pci_disable_msi(phba
->pcidev
);
9487 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9488 "0478 MSI request_irq failed (%d)\n", rc
);
9494 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9495 * @phba: pointer to lpfc hba data structure.
9497 * This routine is invoked to enable device interrupt and associate driver's
9498 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9499 * spec. Depends on the interrupt mode configured to the driver, the driver
9500 * will try to fallback from the configured interrupt mode to an interrupt
9501 * mode which is supported by the platform, kernel, and device in the order
9503 * MSI-X -> MSI -> IRQ.
9507 * other values - error
9510 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
9512 uint32_t intr_mode
= LPFC_INTR_ERROR
;
9515 if (cfg_mode
== 2) {
9516 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9517 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
9519 /* Now, try to enable MSI-X interrupt mode */
9520 retval
= lpfc_sli_enable_msix(phba
);
9522 /* Indicate initialization to MSI-X mode */
9523 phba
->intr_type
= MSIX
;
9529 /* Fallback to MSI if MSI-X initialization failed */
9530 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
9531 retval
= lpfc_sli_enable_msi(phba
);
9533 /* Indicate initialization to MSI mode */
9534 phba
->intr_type
= MSI
;
9539 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9540 if (phba
->intr_type
== NONE
) {
9541 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
9542 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
9544 /* Indicate initialization to INTx mode */
9545 phba
->intr_type
= INTx
;
9553 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9554 * @phba: pointer to lpfc hba data structure.
9556 * This routine is invoked to disable device interrupt and disassociate the
9557 * driver's interrupt handler(s) from interrupt vector(s) to device with
9558 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9559 * release the interrupt vector(s) for the message signaled interrupt.
9562 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
9566 if (phba
->intr_type
== MSIX
)
9567 nr_irqs
= LPFC_MSIX_VECTORS
;
9571 for (i
= 0; i
< nr_irqs
; i
++)
9572 free_irq(pci_irq_vector(phba
->pcidev
, i
), phba
);
9573 pci_free_irq_vectors(phba
->pcidev
);
9575 /* Reset interrupt management states */
9576 phba
->intr_type
= NONE
;
9577 phba
->sli
.slistat
.sli_intr
= 0;
9581 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
9582 * @phba: pointer to lpfc hba data structure.
9583 * @vectors: number of msix vectors allocated.
9585 * The routine will figure out the CPU affinity assignment for every
9586 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9587 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9588 * can be associated with. If the vector can be unquely associated with
9589 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9590 * In addition, the CPU to IO channel mapping will be calculated
9591 * and the phba->sli4_hba.cpu_map array will reflect this.
9594 lpfc_cpu_affinity_check(struct lpfc_hba
*phba
, int vectors
)
9596 struct lpfc_vector_map_info
*cpup
;
9601 struct cpuinfo_x86
*cpuinfo
;
9604 /* Init cpu_map array */
9605 memset(phba
->sli4_hba
.cpu_map
, 0xff,
9606 (sizeof(struct lpfc_vector_map_info
) *
9607 phba
->sli4_hba
.num_present_cpu
));
9609 /* Update CPU map with physical id and core id of each CPU */
9610 cpup
= phba
->sli4_hba
.cpu_map
;
9611 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
9613 cpuinfo
= &cpu_data(cpu
);
9614 cpup
->phys_id
= cpuinfo
->phys_proc_id
;
9615 cpup
->core_id
= cpuinfo
->cpu_core_id
;
9617 /* No distinction between CPUs for other platforms */
9621 cpup
->channel_id
= index
; /* For now round robin */
9622 cpup
->irq
= pci_irq_vector(phba
->pcidev
, vec
);
9627 if (index
>= phba
->cfg_fcp_io_channel
)
9635 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9636 * @phba: pointer to lpfc hba data structure.
9638 * This routine is invoked to enable the MSI-X interrupt vectors to device
9639 * with SLI-4 interface spec.
9643 * other values - error
9646 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
9648 int vectors
, rc
, index
;
9650 /* Set up MSI-X multi-message vectors */
9651 vectors
= phba
->io_channel_irqs
;
9655 rc
= pci_alloc_irq_vectors(phba
->pcidev
,
9656 (phba
->nvmet_support
) ? 1 : 2,
9657 vectors
, PCI_IRQ_MSIX
| PCI_IRQ_AFFINITY
);
9659 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9660 "0484 PCI enable MSI-X failed (%d)\n", rc
);
9665 /* Assign MSI-X vectors to interrupt handlers */
9666 for (index
= 0; index
< vectors
; index
++) {
9667 memset(&phba
->sli4_hba
.handler_name
[index
], 0, 16);
9668 snprintf((char *)&phba
->sli4_hba
.handler_name
[index
],
9669 LPFC_SLI4_HANDLER_NAME_SZ
,
9670 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
9672 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9673 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9674 atomic_set(&phba
->sli4_hba
.hba_eq_hdl
[index
].hba_eq_in_use
, 1);
9675 if (phba
->cfg_fof
&& (index
== (vectors
- 1)))
9676 rc
= request_irq(pci_irq_vector(phba
->pcidev
, index
),
9677 &lpfc_sli4_fof_intr_handler
, 0,
9678 (char *)&phba
->sli4_hba
.handler_name
[index
],
9679 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9681 rc
= request_irq(pci_irq_vector(phba
->pcidev
, index
),
9682 &lpfc_sli4_hba_intr_handler
, 0,
9683 (char *)&phba
->sli4_hba
.handler_name
[index
],
9684 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9686 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9687 "0486 MSI-X fast-path (%d) "
9688 "request_irq failed (%d)\n", index
, rc
);
9696 if (vectors
!= phba
->io_channel_irqs
) {
9697 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9698 "3238 Reducing IO channels to match number of "
9699 "MSI-X vectors, requested %d got %d\n",
9700 phba
->io_channel_irqs
, vectors
);
9701 if (phba
->cfg_fcp_io_channel
> vectors
)
9702 phba
->cfg_fcp_io_channel
= vectors
;
9703 if (phba
->cfg_nvme_io_channel
> vectors
)
9704 phba
->cfg_nvme_io_channel
= vectors
;
9705 if (phba
->cfg_fcp_io_channel
> phba
->cfg_nvme_io_channel
)
9706 phba
->io_channel_irqs
= phba
->cfg_fcp_io_channel
;
9708 phba
->io_channel_irqs
= phba
->cfg_nvme_io_channel
;
9710 lpfc_cpu_affinity_check(phba
, vectors
);
9715 /* free the irq already requested */
9716 for (--index
; index
>= 0; index
--)
9717 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9718 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9720 /* Unconfigure MSI-X capability structure */
9721 pci_free_irq_vectors(phba
->pcidev
);
9728 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9729 * @phba: pointer to lpfc hba data structure.
9731 * This routine is invoked to enable the MSI interrupt mode to device with
9732 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9733 * to enable the MSI vector. The device driver is responsible for calling
9734 * the request_irq() to register MSI vector with a interrupt the handler,
9735 * which is done in this function.
9739 * other values - error
9742 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
9746 rc
= pci_enable_msi(phba
->pcidev
);
9748 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9749 "0487 PCI enable MSI mode success.\n");
9751 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9752 "0488 PCI enable MSI mode failed (%d)\n", rc
);
9756 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
9757 0, LPFC_DRIVER_NAME
, phba
);
9759 pci_disable_msi(phba
->pcidev
);
9760 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
9761 "0490 MSI request_irq failed (%d)\n", rc
);
9765 for (index
= 0; index
< phba
->io_channel_irqs
; index
++) {
9766 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9767 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9770 if (phba
->cfg_fof
) {
9771 phba
->sli4_hba
.hba_eq_hdl
[index
].idx
= index
;
9772 phba
->sli4_hba
.hba_eq_hdl
[index
].phba
= phba
;
9778 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9779 * @phba: pointer to lpfc hba data structure.
9781 * This routine is invoked to enable device interrupt and associate driver's
9782 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9783 * interface spec. Depends on the interrupt mode configured to the driver,
9784 * the driver will try to fallback from the configured interrupt mode to an
9785 * interrupt mode which is supported by the platform, kernel, and device in
9787 * MSI-X -> MSI -> IRQ.
9791 * other values - error
9794 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
9796 uint32_t intr_mode
= LPFC_INTR_ERROR
;
9799 if (cfg_mode
== 2) {
9800 /* Preparation before conf_msi mbox cmd */
9803 /* Now, try to enable MSI-X interrupt mode */
9804 retval
= lpfc_sli4_enable_msix(phba
);
9806 /* Indicate initialization to MSI-X mode */
9807 phba
->intr_type
= MSIX
;
9813 /* Fallback to MSI if MSI-X initialization failed */
9814 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
9815 retval
= lpfc_sli4_enable_msi(phba
);
9817 /* Indicate initialization to MSI mode */
9818 phba
->intr_type
= MSI
;
9823 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9824 if (phba
->intr_type
== NONE
) {
9825 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
9826 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
9828 struct lpfc_hba_eq_hdl
*eqhdl
;
9830 /* Indicate initialization to INTx mode */
9831 phba
->intr_type
= INTx
;
9834 for (idx
= 0; idx
< phba
->io_channel_irqs
; idx
++) {
9835 eqhdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9838 atomic_set(&eqhdl
->hba_eq_in_use
, 1);
9840 if (phba
->cfg_fof
) {
9841 eqhdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9844 atomic_set(&eqhdl
->hba_eq_in_use
, 1);
9852 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9853 * @phba: pointer to lpfc hba data structure.
9855 * This routine is invoked to disable device interrupt and disassociate
9856 * the driver's interrupt handler(s) from interrupt vector(s) to device
9857 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9858 * will release the interrupt vector(s) for the message signaled interrupt.
9861 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
9863 /* Disable the currently initialized interrupt mode */
9864 if (phba
->intr_type
== MSIX
) {
9867 /* Free up MSI-X multi-message vectors */
9868 for (index
= 0; index
< phba
->io_channel_irqs
; index
++)
9869 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9870 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9873 free_irq(pci_irq_vector(phba
->pcidev
, index
),
9874 &phba
->sli4_hba
.hba_eq_hdl
[index
]);
9876 free_irq(phba
->pcidev
->irq
, phba
);
9879 pci_free_irq_vectors(phba
->pcidev
);
9881 /* Reset interrupt management states */
9882 phba
->intr_type
= NONE
;
9883 phba
->sli
.slistat
.sli_intr
= 0;
9887 * lpfc_unset_hba - Unset SLI3 hba device initialization
9888 * @phba: pointer to lpfc hba data structure.
9890 * This routine is invoked to unset the HBA device initialization steps to
9891 * a device with SLI-3 interface spec.
9894 lpfc_unset_hba(struct lpfc_hba
*phba
)
9896 struct lpfc_vport
*vport
= phba
->pport
;
9897 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
9899 spin_lock_irq(shost
->host_lock
);
9900 vport
->load_flag
|= FC_UNLOADING
;
9901 spin_unlock_irq(shost
->host_lock
);
9903 kfree(phba
->vpi_bmask
);
9904 kfree(phba
->vpi_ids
);
9906 lpfc_stop_hba_timers(phba
);
9908 phba
->pport
->work_port_events
= 0;
9910 lpfc_sli_hba_down(phba
);
9912 lpfc_sli_brdrestart(phba
);
9914 lpfc_sli_disable_intr(phba
);
9920 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9921 * @phba: Pointer to HBA context object.
9923 * This function is called in the SLI4 code path to wait for completion
9924 * of device's XRIs exchange busy. It will check the XRI exchange busy
9925 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9926 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9927 * I/Os every 30 seconds, log error message, and wait forever. Only when
9928 * all XRI exchange busy complete, the driver unload shall proceed with
9929 * invoking the function reset ioctl mailbox command to the CNA and the
9930 * the rest of the driver unload resource release.
9933 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
9936 int nvme_xri_cmpl
= 1;
9937 int fcp_xri_cmpl
= 1;
9938 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
9939 int nvmet_xri_cmpl
=
9940 list_empty(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
9942 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
9944 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
9945 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
9947 list_empty(&phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
9949 while (!fcp_xri_cmpl
|| !els_xri_cmpl
|| !nvme_xri_cmpl
||
9951 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
9953 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9954 "6100 NVME XRI exchange busy "
9955 "wait time: %d seconds.\n",
9958 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9959 "2877 FCP XRI exchange busy "
9960 "wait time: %d seconds.\n",
9963 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9964 "2878 ELS XRI exchange busy "
9965 "wait time: %d seconds.\n",
9967 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
9968 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
9970 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
9971 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
9973 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)
9974 nvme_xri_cmpl
= list_empty(
9975 &phba
->sli4_hba
.lpfc_abts_nvme_buf_list
);
9977 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
9978 fcp_xri_cmpl
= list_empty(
9979 &phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
9982 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
9985 list_empty(&phba
->sli4_hba
.lpfc_abts_nvmet_sgl_list
);
9990 * lpfc_sli4_hba_unset - Unset the fcoe hba
9991 * @phba: Pointer to HBA context object.
9993 * This function is called in the SLI4 code path to reset the HBA's FCoE
9994 * function. The caller is not required to hold any lock. This routine
9995 * issues PCI function reset mailbox command to reset the FCoE function.
9996 * At the end of the function, it calls lpfc_hba_down_post function to
9997 * free any pending commands.
10000 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
10003 LPFC_MBOXQ_t
*mboxq
;
10004 struct pci_dev
*pdev
= phba
->pcidev
;
10006 lpfc_stop_hba_timers(phba
);
10007 phba
->sli4_hba
.intr_enable
= 0;
10010 * Gracefully wait out the potential current outstanding asynchronous
10014 /* First, block any pending async mailbox command from posted */
10015 spin_lock_irq(&phba
->hbalock
);
10016 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10017 spin_unlock_irq(&phba
->hbalock
);
10018 /* Now, trying to wait it out if we can */
10019 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
10021 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
10024 /* Forcefully release the outstanding mailbox command if timed out */
10025 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
10026 spin_lock_irq(&phba
->hbalock
);
10027 mboxq
= phba
->sli
.mbox_active
;
10028 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
10029 __lpfc_mbox_cmpl_put(phba
, mboxq
);
10030 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10031 phba
->sli
.mbox_active
= NULL
;
10032 spin_unlock_irq(&phba
->hbalock
);
10035 /* Abort all iocbs associated with the hba */
10036 lpfc_sli_hba_iocb_abort(phba
);
10038 /* Wait for completion of device XRI exchange busy */
10039 lpfc_sli4_xri_exchange_busy_wait(phba
);
10041 /* Disable PCI subsystem interrupt */
10042 lpfc_sli4_disable_intr(phba
);
10044 /* Disable SR-IOV if enabled */
10045 if (phba
->cfg_sriov_nr_virtfn
)
10046 pci_disable_sriov(pdev
);
10048 /* Stop kthread signal shall trigger work_done one more time */
10049 kthread_stop(phba
->worker_thread
);
10051 /* Reset SLI4 HBA FCoE function */
10052 lpfc_pci_function_reset(phba
);
10053 lpfc_sli4_queue_destroy(phba
);
10055 /* Stop the SLI4 device port */
10056 phba
->pport
->work_port_events
= 0;
10060 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10061 * @phba: Pointer to HBA context object.
10062 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10064 * This function is called in the SLI4 code path to read the port's
10065 * sli4 capabilities.
10067 * This function may be be called from any context that can block-wait
10068 * for the completion. The expectation is that this routine is called
10069 * typically from probe_one or from the online routine.
10072 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
10075 struct lpfc_mqe
*mqe
;
10076 struct lpfc_pc_sli4_params
*sli4_params
;
10080 mqe
= &mboxq
->u
.mqe
;
10082 /* Read the port's SLI4 Parameters port capabilities */
10083 lpfc_pc_sli4_params(mboxq
);
10084 if (!phba
->sli4_hba
.intr_enable
)
10085 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
10087 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
10088 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
10094 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
10095 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
10096 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
10097 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
10098 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
10099 &mqe
->un
.sli4_params
);
10100 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
10101 &mqe
->un
.sli4_params
);
10102 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
10103 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
10104 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
10105 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
10106 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
10107 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
10108 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
10109 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
10110 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
10111 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
10112 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
10113 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
10114 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
10115 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
10116 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
10117 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
10118 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
10119 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
10120 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
10121 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
10122 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
10124 /* Make sure that sge_supp_len can be handled by the driver */
10125 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
10126 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
10132 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10133 * @phba: Pointer to HBA context object.
10134 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10136 * This function is called in the SLI4 code path to read the port's
10137 * sli4 capabilities.
10139 * This function may be be called from any context that can block-wait
10140 * for the completion. The expectation is that this routine is called
10141 * typically from probe_one or from the online routine.
10144 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
10147 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
10148 struct lpfc_pc_sli4_params
*sli4_params
;
10151 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
10154 * By default, the driver assumes the SLI4 port requires RPI
10155 * header postings. The SLI4_PARAM response will correct this
10158 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
10160 /* Read the port's SLI4 Config Parameters */
10161 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
10162 sizeof(struct lpfc_sli4_cfg_mhdr
));
10163 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
10164 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
10165 length
, LPFC_SLI4_MBX_EMBED
);
10166 if (!phba
->sli4_hba
.intr_enable
)
10167 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
10169 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
10170 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
10174 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
10175 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
10176 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
10177 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
10178 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
10179 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
10180 mbx_sli4_parameters
);
10181 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
10182 mbx_sli4_parameters
);
10183 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
10184 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
10186 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
10187 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
10188 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
10189 sli4_params
->oas_supported
= bf_get(cfg_oas
, mbx_sli4_parameters
);
10190 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
10191 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
10192 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
10193 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
10194 sli4_params
->wqsize
= bf_get(cfg_wqsize
, mbx_sli4_parameters
);
10195 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
10196 mbx_sli4_parameters
);
10197 sli4_params
->wqpcnt
= bf_get(cfg_wqpcnt
, mbx_sli4_parameters
);
10198 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
10199 mbx_sli4_parameters
);
10200 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
10201 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
10202 phba
->nvme_support
= (bf_get(cfg_nvme
, mbx_sli4_parameters
) &&
10203 bf_get(cfg_xib
, mbx_sli4_parameters
));
10205 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
) ||
10206 !phba
->nvme_support
) {
10207 phba
->nvme_support
= 0;
10208 phba
->nvmet_support
= 0;
10209 phba
->cfg_nvmet_mrq
= 0;
10210 phba
->cfg_nvme_io_channel
= 0;
10211 phba
->io_channel_irqs
= phba
->cfg_fcp_io_channel
;
10212 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_NVME
,
10213 "6101 Disabling NVME support: "
10214 "Not supported by firmware: %d %d\n",
10215 bf_get(cfg_nvme
, mbx_sli4_parameters
),
10216 bf_get(cfg_xib
, mbx_sli4_parameters
));
10218 /* If firmware doesn't support NVME, just use SCSI support */
10219 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
10221 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_FCP
;
10224 if (bf_get(cfg_xib
, mbx_sli4_parameters
) && phba
->cfg_suppress_rsp
)
10225 phba
->sli
.sli_flag
|= LPFC_SLI_SUPPRESS_RSP
;
10227 /* Make sure that sge_supp_len can be handled by the driver */
10228 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
10229 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
10232 * Issue IOs with CDB embedded in WQE to minimized the number
10233 * of DMAs the firmware has to do. Setting this to 1 also forces
10234 * the driver to use 128 bytes WQEs for FCP IOs.
10236 if (bf_get(cfg_ext_embed_cb
, mbx_sli4_parameters
))
10237 phba
->fcp_embed_io
= 1;
10239 phba
->fcp_embed_io
= 0;
10242 * Check if the SLI port supports MDS Diagnostics
10244 if (bf_get(cfg_mds_diags
, mbx_sli4_parameters
))
10245 phba
->mds_diags_support
= 1;
10247 phba
->mds_diags_support
= 0;
10252 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10253 * @pdev: pointer to PCI device
10254 * @pid: pointer to PCI device identifier
10256 * This routine is to be called to attach a device with SLI-3 interface spec
10257 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10258 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10259 * information of the device and driver to see if the driver state that it can
10260 * support this kind of device. If the match is successful, the driver core
10261 * invokes this routine. If this routine determines it can claim the HBA, it
10262 * does all the initialization that it needs to do to handle the HBA properly.
10265 * 0 - driver can claim the device
10266 * negative value - driver can not claim the device
10269 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
10271 struct lpfc_hba
*phba
;
10272 struct lpfc_vport
*vport
= NULL
;
10273 struct Scsi_Host
*shost
= NULL
;
10275 uint32_t cfg_mode
, intr_mode
;
10277 /* Allocate memory for HBA structure */
10278 phba
= lpfc_hba_alloc(pdev
);
10282 /* Perform generic PCI device enabling operation */
10283 error
= lpfc_enable_pci_dev(phba
);
10285 goto out_free_phba
;
10287 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10288 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
10290 goto out_disable_pci_dev
;
10292 /* Set up SLI-3 specific device PCI memory space */
10293 error
= lpfc_sli_pci_mem_setup(phba
);
10295 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10296 "1402 Failed to set up pci memory space.\n");
10297 goto out_disable_pci_dev
;
10300 /* Set up SLI-3 specific device driver resources */
10301 error
= lpfc_sli_driver_resource_setup(phba
);
10303 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10304 "1404 Failed to set up driver resource.\n");
10305 goto out_unset_pci_mem_s3
;
10308 /* Initialize and populate the iocb list per host */
10309 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
10311 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10312 "1405 Failed to initialize iocb list.\n");
10313 goto out_unset_driver_resource_s3
;
10316 /* Set up common device driver resources */
10317 error
= lpfc_setup_driver_resource_phase2(phba
);
10319 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10320 "1406 Failed to set up driver resource.\n");
10321 goto out_free_iocb_list
;
10324 /* Get the default values for Model Name and Description */
10325 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
10327 /* Create SCSI host to the physical port */
10328 error
= lpfc_create_shost(phba
);
10330 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10331 "1407 Failed to create scsi host.\n");
10332 goto out_unset_driver_resource
;
10335 /* Configure sysfs attributes */
10336 vport
= phba
->pport
;
10337 error
= lpfc_alloc_sysfs_attr(vport
);
10339 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10340 "1476 Failed to allocate sysfs attr\n");
10341 goto out_destroy_shost
;
10344 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
10345 /* Now, trying to enable interrupt and bring up the device */
10346 cfg_mode
= phba
->cfg_use_msi
;
10348 /* Put device to a known state before enabling interrupt */
10349 lpfc_stop_port(phba
);
10350 /* Configure and enable interrupt */
10351 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
10352 if (intr_mode
== LPFC_INTR_ERROR
) {
10353 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10354 "0431 Failed to enable interrupt.\n");
10356 goto out_free_sysfs_attr
;
10358 /* SLI-3 HBA setup */
10359 if (lpfc_sli_hba_setup(phba
)) {
10360 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10361 "1477 Failed to set up hba\n");
10363 goto out_remove_device
;
10366 /* Wait 50ms for the interrupts of previous mailbox commands */
10368 /* Check active interrupts on message signaled interrupts */
10369 if (intr_mode
== 0 ||
10370 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
10371 /* Log the current active interrupt mode */
10372 phba
->intr_mode
= intr_mode
;
10373 lpfc_log_intr_mode(phba
, intr_mode
);
10376 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10377 "0447 Configure interrupt mode (%d) "
10378 "failed active interrupt test.\n",
10380 /* Disable the current interrupt mode */
10381 lpfc_sli_disable_intr(phba
);
10382 /* Try next level of interrupt mode */
10383 cfg_mode
= --intr_mode
;
10387 /* Perform post initialization setup */
10388 lpfc_post_init_setup(phba
);
10390 /* Check if there are static vports to be created. */
10391 lpfc_create_static_vport(phba
);
10396 lpfc_unset_hba(phba
);
10397 out_free_sysfs_attr
:
10398 lpfc_free_sysfs_attr(vport
);
10400 lpfc_destroy_shost(phba
);
10401 out_unset_driver_resource
:
10402 lpfc_unset_driver_resource_phase2(phba
);
10403 out_free_iocb_list
:
10404 lpfc_free_iocb_list(phba
);
10405 out_unset_driver_resource_s3
:
10406 lpfc_sli_driver_resource_unset(phba
);
10407 out_unset_pci_mem_s3
:
10408 lpfc_sli_pci_mem_unset(phba
);
10409 out_disable_pci_dev
:
10410 lpfc_disable_pci_dev(phba
);
10412 scsi_host_put(shost
);
10414 lpfc_hba_free(phba
);
10419 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
10420 * @pdev: pointer to PCI device
10422 * This routine is to be called to disattach a device with SLI-3 interface
10423 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10424 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10425 * device to be removed from the PCI subsystem properly.
10428 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
10430 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10431 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
10432 struct lpfc_vport
**vports
;
10433 struct lpfc_hba
*phba
= vport
->phba
;
10436 spin_lock_irq(&phba
->hbalock
);
10437 vport
->load_flag
|= FC_UNLOADING
;
10438 spin_unlock_irq(&phba
->hbalock
);
10440 lpfc_free_sysfs_attr(vport
);
10442 /* Release all the vports against this physical port */
10443 vports
= lpfc_create_vport_work_array(phba
);
10444 if (vports
!= NULL
)
10445 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
10446 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
10448 fc_vport_terminate(vports
[i
]->fc_vport
);
10450 lpfc_destroy_vport_work_array(phba
, vports
);
10452 /* Remove FC host and then SCSI host with the physical port */
10453 fc_remove_host(shost
);
10454 scsi_remove_host(shost
);
10456 lpfc_cleanup(vport
);
10459 * Bring down the SLI Layer. This step disable all interrupts,
10460 * clears the rings, discards all mailbox commands, and resets
10464 /* HBA interrupt will be disabled after this call */
10465 lpfc_sli_hba_down(phba
);
10466 /* Stop kthread signal shall trigger work_done one more time */
10467 kthread_stop(phba
->worker_thread
);
10468 /* Final cleanup of txcmplq and reset the HBA */
10469 lpfc_sli_brdrestart(phba
);
10471 kfree(phba
->vpi_bmask
);
10472 kfree(phba
->vpi_ids
);
10474 lpfc_stop_hba_timers(phba
);
10475 spin_lock_irq(&phba
->hbalock
);
10476 list_del_init(&vport
->listentry
);
10477 spin_unlock_irq(&phba
->hbalock
);
10479 lpfc_debugfs_terminate(vport
);
10481 /* Disable SR-IOV if enabled */
10482 if (phba
->cfg_sriov_nr_virtfn
)
10483 pci_disable_sriov(pdev
);
10485 /* Disable interrupt */
10486 lpfc_sli_disable_intr(phba
);
10488 scsi_host_put(shost
);
10491 * Call scsi_free before mem_free since scsi bufs are released to their
10492 * corresponding pools here.
10494 lpfc_scsi_free(phba
);
10495 lpfc_mem_free_all(phba
);
10497 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
10498 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
10500 /* Free resources associated with SLI2 interface */
10501 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
10502 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
10504 /* unmap adapter SLIM and Control Registers */
10505 iounmap(phba
->ctrl_regs_memmap_p
);
10506 iounmap(phba
->slim_memmap_p
);
10508 lpfc_hba_free(phba
);
10510 pci_release_mem_regions(pdev
);
10511 pci_disable_device(pdev
);
10515 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
10516 * @pdev: pointer to PCI device
10517 * @msg: power management message
10519 * This routine is to be called from the kernel's PCI subsystem to support
10520 * system Power Management (PM) to device with SLI-3 interface spec. When
10521 * PM invokes this method, it quiesces the device by stopping the driver's
10522 * worker thread for the device, turning off device's interrupt and DMA,
10523 * and bring the device offline. Note that as the driver implements the
10524 * minimum PM requirements to a power-aware driver's PM support for the
10525 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10526 * to the suspend() method call will be treated as SUSPEND and the driver will
10527 * fully reinitialize its device during resume() method call, the driver will
10528 * set device to PCI_D3hot state in PCI config space instead of setting it
10529 * according to the @msg provided by the PM.
10532 * 0 - driver suspended the device
10536 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
10538 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10539 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10541 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10542 "0473 PCI device Power Management suspend.\n");
10544 /* Bring down the device */
10545 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10546 lpfc_offline(phba
);
10547 kthread_stop(phba
->worker_thread
);
10549 /* Disable interrupt from device */
10550 lpfc_sli_disable_intr(phba
);
10552 /* Save device state to PCI config space */
10553 pci_save_state(pdev
);
10554 pci_set_power_state(pdev
, PCI_D3hot
);
10560 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
10561 * @pdev: pointer to PCI device
10563 * This routine is to be called from the kernel's PCI subsystem to support
10564 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10565 * invokes this method, it restores the device's PCI config space state and
10566 * fully reinitializes the device and brings it online. Note that as the
10567 * driver implements the minimum PM requirements to a power-aware driver's
10568 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10569 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10570 * driver will fully reinitialize its device during resume() method call,
10571 * the device will be set to PCI_D0 directly in PCI config space before
10572 * restoring the state.
10575 * 0 - driver suspended the device
10579 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
10581 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10582 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10583 uint32_t intr_mode
;
10586 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10587 "0452 PCI device Power Management resume.\n");
10589 /* Restore device state from PCI config space */
10590 pci_set_power_state(pdev
, PCI_D0
);
10591 pci_restore_state(pdev
);
10594 * As the new kernel behavior of pci_restore_state() API call clears
10595 * device saved_state flag, need to save the restored state again.
10597 pci_save_state(pdev
);
10599 if (pdev
->is_busmaster
)
10600 pci_set_master(pdev
);
10602 /* Startup the kernel thread for this host adapter. */
10603 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
10604 "lpfc_worker_%d", phba
->brd_no
);
10605 if (IS_ERR(phba
->worker_thread
)) {
10606 error
= PTR_ERR(phba
->worker_thread
);
10607 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10608 "0434 PM resume failed to start worker "
10609 "thread: error=x%x.\n", error
);
10613 /* Configure and enable interrupt */
10614 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
10615 if (intr_mode
== LPFC_INTR_ERROR
) {
10616 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10617 "0430 PM resume Failed to enable interrupt\n");
10620 phba
->intr_mode
= intr_mode
;
10622 /* Restart HBA and bring it online */
10623 lpfc_sli_brdrestart(phba
);
10626 /* Log the current active interrupt mode */
10627 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10633 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10634 * @phba: pointer to lpfc hba data structure.
10636 * This routine is called to prepare the SLI3 device for PCI slot recover. It
10637 * aborts all the outstanding SCSI I/Os to the pci device.
10640 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
10642 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10643 "2723 PCI channel I/O abort preparing for recovery\n");
10646 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10647 * and let the SCSI mid-layer to retry them to recover.
10649 lpfc_sli_abort_fcp_rings(phba
);
10653 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10654 * @phba: pointer to lpfc hba data structure.
10656 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10657 * disables the device interrupt and pci device, and aborts the internal FCP
10661 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
10663 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10664 "2710 PCI channel disable preparing for reset\n");
10666 /* Block any management I/Os to the device */
10667 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
10669 /* Block all SCSI devices' I/Os on the host */
10670 lpfc_scsi_dev_block(phba
);
10672 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10673 lpfc_sli_flush_fcp_rings(phba
);
10675 /* stop all timers */
10676 lpfc_stop_hba_timers(phba
);
10678 /* Disable interrupt and pci device */
10679 lpfc_sli_disable_intr(phba
);
10680 pci_disable_device(phba
->pcidev
);
10684 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10685 * @phba: pointer to lpfc hba data structure.
10687 * This routine is called to prepare the SLI3 device for PCI slot permanently
10688 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10692 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
10694 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10695 "2711 PCI channel permanent disable for failure\n");
10696 /* Block all SCSI devices' I/Os on the host */
10697 lpfc_scsi_dev_block(phba
);
10699 /* stop all timers */
10700 lpfc_stop_hba_timers(phba
);
10702 /* Clean up all driver's outstanding SCSI I/Os */
10703 lpfc_sli_flush_fcp_rings(phba
);
10707 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
10708 * @pdev: pointer to PCI device.
10709 * @state: the current PCI connection state.
10711 * This routine is called from the PCI subsystem for I/O error handling to
10712 * device with SLI-3 interface spec. This function is called by the PCI
10713 * subsystem after a PCI bus error affecting this device has been detected.
10714 * When this function is invoked, it will need to stop all the I/Os and
10715 * interrupt(s) to the device. Once that is done, it will return
10716 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10720 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
10721 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10722 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10724 static pci_ers_result_t
10725 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
10727 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10728 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10731 case pci_channel_io_normal
:
10732 /* Non-fatal error, prepare for recovery */
10733 lpfc_sli_prep_dev_for_recover(phba
);
10734 return PCI_ERS_RESULT_CAN_RECOVER
;
10735 case pci_channel_io_frozen
:
10736 /* Fatal error, prepare for slot reset */
10737 lpfc_sli_prep_dev_for_reset(phba
);
10738 return PCI_ERS_RESULT_NEED_RESET
;
10739 case pci_channel_io_perm_failure
:
10740 /* Permanent failure, prepare for device down */
10741 lpfc_sli_prep_dev_for_perm_failure(phba
);
10742 return PCI_ERS_RESULT_DISCONNECT
;
10744 /* Unknown state, prepare and request slot reset */
10745 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10746 "0472 Unknown PCI error state: x%x\n", state
);
10747 lpfc_sli_prep_dev_for_reset(phba
);
10748 return PCI_ERS_RESULT_NEED_RESET
;
10753 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
10754 * @pdev: pointer to PCI device.
10756 * This routine is called from the PCI subsystem for error handling to
10757 * device with SLI-3 interface spec. This is called after PCI bus has been
10758 * reset to restart the PCI card from scratch, as if from a cold-boot.
10759 * During the PCI subsystem error recovery, after driver returns
10760 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10761 * recovery and then call this routine before calling the .resume method
10762 * to recover the device. This function will initialize the HBA device,
10763 * enable the interrupt, but it will just put the HBA to offline state
10764 * without passing any I/O traffic.
10767 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10768 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10770 static pci_ers_result_t
10771 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
10773 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10774 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10775 struct lpfc_sli
*psli
= &phba
->sli
;
10776 uint32_t intr_mode
;
10778 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
10779 if (pci_enable_device_mem(pdev
)) {
10780 printk(KERN_ERR
"lpfc: Cannot re-enable "
10781 "PCI device after reset.\n");
10782 return PCI_ERS_RESULT_DISCONNECT
;
10785 pci_restore_state(pdev
);
10788 * As the new kernel behavior of pci_restore_state() API call clears
10789 * device saved_state flag, need to save the restored state again.
10791 pci_save_state(pdev
);
10793 if (pdev
->is_busmaster
)
10794 pci_set_master(pdev
);
10796 spin_lock_irq(&phba
->hbalock
);
10797 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
10798 spin_unlock_irq(&phba
->hbalock
);
10800 /* Configure and enable interrupt */
10801 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
10802 if (intr_mode
== LPFC_INTR_ERROR
) {
10803 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10804 "0427 Cannot re-enable interrupt after "
10806 return PCI_ERS_RESULT_DISCONNECT
;
10808 phba
->intr_mode
= intr_mode
;
10810 /* Take device offline, it will perform cleanup */
10811 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10812 lpfc_offline(phba
);
10813 lpfc_sli_brdrestart(phba
);
10815 /* Log the current active interrupt mode */
10816 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10818 return PCI_ERS_RESULT_RECOVERED
;
10822 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
10823 * @pdev: pointer to PCI device
10825 * This routine is called from the PCI subsystem for error handling to device
10826 * with SLI-3 interface spec. It is called when kernel error recovery tells
10827 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10828 * error recovery. After this call, traffic can start to flow from this device
10832 lpfc_io_resume_s3(struct pci_dev
*pdev
)
10834 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10835 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10837 /* Bring device online, it will be no-op for non-fatal error resume */
10840 /* Clean up Advanced Error Reporting (AER) if needed */
10841 if (phba
->hba_flag
& HBA_AER_ENABLED
)
10842 pci_cleanup_aer_uncorrect_error_status(pdev
);
10846 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10847 * @phba: pointer to lpfc hba data structure.
10849 * returns the number of ELS/CT IOCBs to reserve
10852 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
10854 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
10856 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10857 if (max_xri
<= 100)
10859 else if (max_xri
<= 256)
10861 else if (max_xri
<= 512)
10863 else if (max_xri
<= 1024)
10865 else if (max_xri
<= 1536)
10867 else if (max_xri
<= 2048)
10876 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10877 * @phba: pointer to lpfc hba data structure.
10879 * returns the number of ELS/CT + NVMET IOCBs to reserve
10882 lpfc_sli4_get_iocb_cnt(struct lpfc_hba
*phba
)
10884 int max_xri
= lpfc_sli4_get_els_iocb_cnt(phba
);
10886 if (phba
->nvmet_support
)
10887 max_xri
+= LPFC_NVMET_BUF_POST
;
10893 * lpfc_write_firmware - attempt to write a firmware image to the port
10894 * @fw: pointer to firmware image returned from request_firmware.
10895 * @phba: pointer to lpfc hba data structure.
10899 lpfc_write_firmware(const struct firmware
*fw
, void *context
)
10901 struct lpfc_hba
*phba
= (struct lpfc_hba
*)context
;
10902 char fwrev
[FW_REV_STR_SIZE
];
10903 struct lpfc_grp_hdr
*image
;
10904 struct list_head dma_buffer_list
;
10906 struct lpfc_dmabuf
*dmabuf
, *next
;
10907 uint32_t offset
= 0, temp_offset
= 0;
10908 uint32_t magic_number
, ftype
, fid
, fsize
;
10910 /* It can be null in no-wait mode, sanity check */
10915 image
= (struct lpfc_grp_hdr
*)fw
->data
;
10917 magic_number
= be32_to_cpu(image
->magic_number
);
10918 ftype
= bf_get_be32(lpfc_grp_hdr_file_type
, image
);
10919 fid
= bf_get_be32(lpfc_grp_hdr_id
, image
),
10920 fsize
= be32_to_cpu(image
->size
);
10922 INIT_LIST_HEAD(&dma_buffer_list
);
10923 if ((magic_number
!= LPFC_GROUP_OJECT_MAGIC_G5
&&
10924 magic_number
!= LPFC_GROUP_OJECT_MAGIC_G6
) ||
10925 ftype
!= LPFC_FILE_TYPE_GROUP
|| fsize
!= fw
->size
) {
10926 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10927 "3022 Invalid FW image found. "
10928 "Magic:%x Type:%x ID:%x Size %d %zd\n",
10929 magic_number
, ftype
, fid
, fsize
, fw
->size
);
10933 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
10934 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
10935 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10936 "3023 Updating Firmware, Current Version:%s "
10937 "New Version:%s\n",
10938 fwrev
, image
->revision
);
10939 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
10940 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
10946 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
10950 if (!dmabuf
->virt
) {
10955 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
10957 while (offset
< fw
->size
) {
10958 temp_offset
= offset
;
10959 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
10960 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
10961 memcpy(dmabuf
->virt
,
10962 fw
->data
+ temp_offset
,
10963 fw
->size
- temp_offset
);
10964 temp_offset
= fw
->size
;
10967 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
10969 temp_offset
+= SLI4_PAGE_SIZE
;
10971 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
10972 (fw
->size
- offset
), &offset
);
10980 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
10981 list_del(&dmabuf
->list
);
10982 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
10983 dmabuf
->virt
, dmabuf
->phys
);
10986 release_firmware(fw
);
10988 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10989 "3024 Firmware update done: %d.\n", rc
);
10994 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10995 * @phba: pointer to lpfc hba data structure.
10997 * This routine is called to perform Linux generic firmware upgrade on device
10998 * that supports such feature.
11001 lpfc_sli4_request_firmware_update(struct lpfc_hba
*phba
, uint8_t fw_upgrade
)
11003 uint8_t file_name
[ELX_MODEL_NAME_SIZE
];
11005 const struct firmware
*fw
;
11007 /* Only supported on SLI4 interface type 2 for now */
11008 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
11009 LPFC_SLI_INTF_IF_TYPE_2
)
11012 snprintf(file_name
, ELX_MODEL_NAME_SIZE
, "%s.grp", phba
->ModelName
);
11014 if (fw_upgrade
== INT_FW_UPGRADE
) {
11015 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
11016 file_name
, &phba
->pcidev
->dev
,
11017 GFP_KERNEL
, (void *)phba
,
11018 lpfc_write_firmware
);
11019 } else if (fw_upgrade
== RUN_FW_UPGRADE
) {
11020 ret
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
11022 lpfc_write_firmware(fw
, (void *)phba
);
11031 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11032 * @pdev: pointer to PCI device
11033 * @pid: pointer to PCI device identifier
11035 * This routine is called from the kernel's PCI subsystem to device with
11036 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11037 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11038 * information of the device and driver to see if the driver state that it
11039 * can support this kind of device. If the match is successful, the driver
11040 * core invokes this routine. If this routine determines it can claim the HBA,
11041 * it does all the initialization that it needs to do to handle the HBA
11045 * 0 - driver can claim the device
11046 * negative value - driver can not claim the device
11049 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
11051 struct lpfc_hba
*phba
;
11052 struct lpfc_vport
*vport
= NULL
;
11053 struct Scsi_Host
*shost
= NULL
;
11055 uint32_t cfg_mode
, intr_mode
;
11057 /* Allocate memory for HBA structure */
11058 phba
= lpfc_hba_alloc(pdev
);
11062 /* Perform generic PCI device enabling operation */
11063 error
= lpfc_enable_pci_dev(phba
);
11065 goto out_free_phba
;
11067 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11068 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
11070 goto out_disable_pci_dev
;
11072 /* Set up SLI-4 specific device PCI memory space */
11073 error
= lpfc_sli4_pci_mem_setup(phba
);
11075 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11076 "1410 Failed to set up pci memory space.\n");
11077 goto out_disable_pci_dev
;
11080 /* Set up SLI-4 Specific device driver resources */
11081 error
= lpfc_sli4_driver_resource_setup(phba
);
11083 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11084 "1412 Failed to set up driver resource.\n");
11085 goto out_unset_pci_mem_s4
;
11088 /* Initialize and populate the iocb list per host */
11090 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11091 "2821 initialize iocb list %d.\n",
11092 phba
->cfg_iocb_cnt
*1024);
11093 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
11096 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11097 "1413 Failed to initialize iocb list.\n");
11098 goto out_unset_driver_resource_s4
;
11101 INIT_LIST_HEAD(&phba
->active_rrq_list
);
11102 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
11104 /* Set up common device driver resources */
11105 error
= lpfc_setup_driver_resource_phase2(phba
);
11107 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11108 "1414 Failed to set up driver resource.\n");
11109 goto out_free_iocb_list
;
11112 /* Get the default values for Model Name and Description */
11113 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
11115 /* Create SCSI host to the physical port */
11116 error
= lpfc_create_shost(phba
);
11118 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11119 "1415 Failed to create scsi host.\n");
11120 goto out_unset_driver_resource
;
11123 /* Configure sysfs attributes */
11124 vport
= phba
->pport
;
11125 error
= lpfc_alloc_sysfs_attr(vport
);
11127 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11128 "1416 Failed to allocate sysfs attr\n");
11129 goto out_destroy_shost
;
11132 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
11133 /* Now, trying to enable interrupt and bring up the device */
11134 cfg_mode
= phba
->cfg_use_msi
;
11136 /* Put device to a known state before enabling interrupt */
11137 lpfc_stop_port(phba
);
11139 /* Configure and enable interrupt */
11140 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
11141 if (intr_mode
== LPFC_INTR_ERROR
) {
11142 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11143 "0426 Failed to enable interrupt.\n");
11145 goto out_free_sysfs_attr
;
11147 /* Default to single EQ for non-MSI-X */
11148 if (phba
->intr_type
!= MSIX
) {
11149 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
)
11150 phba
->cfg_fcp_io_channel
= 1;
11151 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) {
11152 phba
->cfg_nvme_io_channel
= 1;
11153 if (phba
->nvmet_support
)
11154 phba
->cfg_nvmet_mrq
= 1;
11156 phba
->io_channel_irqs
= 1;
11159 /* Set up SLI-4 HBA */
11160 if (lpfc_sli4_hba_setup(phba
)) {
11161 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11162 "1421 Failed to set up hba\n");
11164 goto out_disable_intr
;
11167 /* Log the current active interrupt mode */
11168 phba
->intr_mode
= intr_mode
;
11169 lpfc_log_intr_mode(phba
, intr_mode
);
11171 /* Perform post initialization setup */
11172 lpfc_post_init_setup(phba
);
11174 /* NVME support in FW earlier in the driver load corrects the
11175 * FC4 type making a check for nvme_support unnecessary.
11177 if ((phba
->nvmet_support
== 0) &&
11178 (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)) {
11179 /* Create NVME binding with nvme_fc_transport. This
11180 * ensures the vport is initialized.
11182 error
= lpfc_nvme_create_localport(vport
);
11184 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11185 "6004 NVME registration failed, "
11188 goto out_disable_intr
;
11192 /* check for firmware upgrade or downgrade */
11193 if (phba
->cfg_request_firmware_upgrade
)
11194 lpfc_sli4_request_firmware_update(phba
, INT_FW_UPGRADE
);
11196 /* Check if there are static vports to be created. */
11197 lpfc_create_static_vport(phba
);
11201 lpfc_sli4_disable_intr(phba
);
11202 out_free_sysfs_attr
:
11203 lpfc_free_sysfs_attr(vport
);
11205 lpfc_destroy_shost(phba
);
11206 out_unset_driver_resource
:
11207 lpfc_unset_driver_resource_phase2(phba
);
11208 out_free_iocb_list
:
11209 lpfc_free_iocb_list(phba
);
11210 out_unset_driver_resource_s4
:
11211 lpfc_sli4_driver_resource_unset(phba
);
11212 out_unset_pci_mem_s4
:
11213 lpfc_sli4_pci_mem_unset(phba
);
11214 out_disable_pci_dev
:
11215 lpfc_disable_pci_dev(phba
);
11217 scsi_host_put(shost
);
11219 lpfc_hba_free(phba
);
11224 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11225 * @pdev: pointer to PCI device
11227 * This routine is called from the kernel's PCI subsystem to device with
11228 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11229 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11230 * device to be removed from the PCI subsystem properly.
11233 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
11235 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11236 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
11237 struct lpfc_vport
**vports
;
11238 struct lpfc_hba
*phba
= vport
->phba
;
11241 /* Mark the device unloading flag */
11242 spin_lock_irq(&phba
->hbalock
);
11243 vport
->load_flag
|= FC_UNLOADING
;
11244 spin_unlock_irq(&phba
->hbalock
);
11246 /* Free the HBA sysfs attributes */
11247 lpfc_free_sysfs_attr(vport
);
11249 /* Release all the vports against this physical port */
11250 vports
= lpfc_create_vport_work_array(phba
);
11251 if (vports
!= NULL
)
11252 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
11253 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
11255 fc_vport_terminate(vports
[i
]->fc_vport
);
11257 lpfc_destroy_vport_work_array(phba
, vports
);
11259 /* Remove FC host and then SCSI host with the physical port */
11260 fc_remove_host(shost
);
11261 scsi_remove_host(shost
);
11263 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11264 * localports are destroyed after to cleanup all transport memory.
11266 lpfc_cleanup(vport
);
11267 lpfc_nvmet_destroy_targetport(phba
);
11268 lpfc_nvme_destroy_localport(vport
);
11271 * Bring down the SLI Layer. This step disables all interrupts,
11272 * clears the rings, discards all mailbox commands, and resets
11273 * the HBA FCoE function.
11275 lpfc_debugfs_terminate(vport
);
11276 lpfc_sli4_hba_unset(phba
);
11278 spin_lock_irq(&phba
->hbalock
);
11279 list_del_init(&vport
->listentry
);
11280 spin_unlock_irq(&phba
->hbalock
);
11282 /* Perform scsi free before driver resource_unset since scsi
11283 * buffers are released to their corresponding pools here.
11285 lpfc_scsi_free(phba
);
11286 lpfc_nvme_free(phba
);
11287 lpfc_free_iocb_list(phba
);
11289 lpfc_sli4_driver_resource_unset(phba
);
11291 /* Unmap adapter Control and Doorbell registers */
11292 lpfc_sli4_pci_mem_unset(phba
);
11294 /* Release PCI resources and disable device's PCI function */
11295 scsi_host_put(shost
);
11296 lpfc_disable_pci_dev(phba
);
11298 /* Finally, free the driver's device data structure */
11299 lpfc_hba_free(phba
);
11305 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11306 * @pdev: pointer to PCI device
11307 * @msg: power management message
11309 * This routine is called from the kernel's PCI subsystem to support system
11310 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11311 * this method, it quiesces the device by stopping the driver's worker
11312 * thread for the device, turning off device's interrupt and DMA, and bring
11313 * the device offline. Note that as the driver implements the minimum PM
11314 * requirements to a power-aware driver's PM support for suspend/resume -- all
11315 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11316 * method call will be treated as SUSPEND and the driver will fully
11317 * reinitialize its device during resume() method call, the driver will set
11318 * device to PCI_D3hot state in PCI config space instead of setting it
11319 * according to the @msg provided by the PM.
11322 * 0 - driver suspended the device
11326 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
11328 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11329 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11331 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11332 "2843 PCI device Power Management suspend.\n");
11334 /* Bring down the device */
11335 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
11336 lpfc_offline(phba
);
11337 kthread_stop(phba
->worker_thread
);
11339 /* Disable interrupt from device */
11340 lpfc_sli4_disable_intr(phba
);
11341 lpfc_sli4_queue_destroy(phba
);
11343 /* Save device state to PCI config space */
11344 pci_save_state(pdev
);
11345 pci_set_power_state(pdev
, PCI_D3hot
);
11351 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11352 * @pdev: pointer to PCI device
11354 * This routine is called from the kernel's PCI subsystem to support system
11355 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11356 * this method, it restores the device's PCI config space state and fully
11357 * reinitializes the device and brings it online. Note that as the driver
11358 * implements the minimum PM requirements to a power-aware driver's PM for
11359 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11360 * to the suspend() method call will be treated as SUSPEND and the driver
11361 * will fully reinitialize its device during resume() method call, the device
11362 * will be set to PCI_D0 directly in PCI config space before restoring the
11366 * 0 - driver suspended the device
11370 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
11372 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11373 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11374 uint32_t intr_mode
;
11377 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
11378 "0292 PCI device Power Management resume.\n");
11380 /* Restore device state from PCI config space */
11381 pci_set_power_state(pdev
, PCI_D0
);
11382 pci_restore_state(pdev
);
11385 * As the new kernel behavior of pci_restore_state() API call clears
11386 * device saved_state flag, need to save the restored state again.
11388 pci_save_state(pdev
);
11390 if (pdev
->is_busmaster
)
11391 pci_set_master(pdev
);
11393 /* Startup the kernel thread for this host adapter. */
11394 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
11395 "lpfc_worker_%d", phba
->brd_no
);
11396 if (IS_ERR(phba
->worker_thread
)) {
11397 error
= PTR_ERR(phba
->worker_thread
);
11398 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11399 "0293 PM resume failed to start worker "
11400 "thread: error=x%x.\n", error
);
11404 /* Configure and enable interrupt */
11405 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
11406 if (intr_mode
== LPFC_INTR_ERROR
) {
11407 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11408 "0294 PM resume Failed to enable interrupt\n");
11411 phba
->intr_mode
= intr_mode
;
11413 /* Restart HBA and bring it online */
11414 lpfc_sli_brdrestart(phba
);
11417 /* Log the current active interrupt mode */
11418 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
11424 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11425 * @phba: pointer to lpfc hba data structure.
11427 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11428 * aborts all the outstanding SCSI I/Os to the pci device.
11431 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
11433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11434 "2828 PCI channel I/O abort preparing for recovery\n");
11436 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11437 * and let the SCSI mid-layer to retry them to recover.
11439 lpfc_sli_abort_fcp_rings(phba
);
11443 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11444 * @phba: pointer to lpfc hba data structure.
11446 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11447 * disables the device interrupt and pci device, and aborts the internal FCP
11451 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
11453 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11454 "2826 PCI channel disable preparing for reset\n");
11456 /* Block any management I/Os to the device */
11457 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
11459 /* Block all SCSI devices' I/Os on the host */
11460 lpfc_scsi_dev_block(phba
);
11462 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11463 lpfc_sli_flush_fcp_rings(phba
);
11465 /* stop all timers */
11466 lpfc_stop_hba_timers(phba
);
11468 /* Disable interrupt and pci device */
11469 lpfc_sli4_disable_intr(phba
);
11470 lpfc_sli4_queue_destroy(phba
);
11471 pci_disable_device(phba
->pcidev
);
11475 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11476 * @phba: pointer to lpfc hba data structure.
11478 * This routine is called to prepare the SLI4 device for PCI slot permanently
11479 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11483 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
11485 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11486 "2827 PCI channel permanent disable for failure\n");
11488 /* Block all SCSI devices' I/Os on the host */
11489 lpfc_scsi_dev_block(phba
);
11491 /* stop all timers */
11492 lpfc_stop_hba_timers(phba
);
11494 /* Clean up all driver's outstanding SCSI I/Os */
11495 lpfc_sli_flush_fcp_rings(phba
);
11499 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11500 * @pdev: pointer to PCI device.
11501 * @state: the current PCI connection state.
11503 * This routine is called from the PCI subsystem for error handling to device
11504 * with SLI-4 interface spec. This function is called by the PCI subsystem
11505 * after a PCI bus error affecting this device has been detected. When this
11506 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11507 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11508 * for the PCI subsystem to perform proper recovery as desired.
11511 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11512 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11514 static pci_ers_result_t
11515 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
11517 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11518 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11521 case pci_channel_io_normal
:
11522 /* Non-fatal error, prepare for recovery */
11523 lpfc_sli4_prep_dev_for_recover(phba
);
11524 return PCI_ERS_RESULT_CAN_RECOVER
;
11525 case pci_channel_io_frozen
:
11526 /* Fatal error, prepare for slot reset */
11527 lpfc_sli4_prep_dev_for_reset(phba
);
11528 return PCI_ERS_RESULT_NEED_RESET
;
11529 case pci_channel_io_perm_failure
:
11530 /* Permanent failure, prepare for device down */
11531 lpfc_sli4_prep_dev_for_perm_failure(phba
);
11532 return PCI_ERS_RESULT_DISCONNECT
;
11534 /* Unknown state, prepare and request slot reset */
11535 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11536 "2825 Unknown PCI error state: x%x\n", state
);
11537 lpfc_sli4_prep_dev_for_reset(phba
);
11538 return PCI_ERS_RESULT_NEED_RESET
;
11543 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11544 * @pdev: pointer to PCI device.
11546 * This routine is called from the PCI subsystem for error handling to device
11547 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11548 * restart the PCI card from scratch, as if from a cold-boot. During the
11549 * PCI subsystem error recovery, after the driver returns
11550 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11551 * recovery and then call this routine before calling the .resume method to
11552 * recover the device. This function will initialize the HBA device, enable
11553 * the interrupt, but it will just put the HBA to offline state without
11554 * passing any I/O traffic.
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_s4(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 struct lpfc_sli
*psli
= &phba
->sli
;
11566 uint32_t intr_mode
;
11568 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
11569 if (pci_enable_device_mem(pdev
)) {
11570 printk(KERN_ERR
"lpfc: Cannot re-enable "
11571 "PCI device after reset.\n");
11572 return PCI_ERS_RESULT_DISCONNECT
;
11575 pci_restore_state(pdev
);
11578 * As the new kernel behavior of pci_restore_state() API call clears
11579 * device saved_state flag, need to save the restored state again.
11581 pci_save_state(pdev
);
11583 if (pdev
->is_busmaster
)
11584 pci_set_master(pdev
);
11586 spin_lock_irq(&phba
->hbalock
);
11587 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
11588 spin_unlock_irq(&phba
->hbalock
);
11590 /* Configure and enable interrupt */
11591 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
11592 if (intr_mode
== LPFC_INTR_ERROR
) {
11593 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11594 "2824 Cannot re-enable interrupt after "
11596 return PCI_ERS_RESULT_DISCONNECT
;
11598 phba
->intr_mode
= intr_mode
;
11600 /* Log the current active interrupt mode */
11601 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
11603 return PCI_ERS_RESULT_RECOVERED
;
11607 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11608 * @pdev: pointer to PCI device
11610 * This routine is called from the PCI subsystem for error handling to device
11611 * with SLI-4 interface spec. It is called when kernel error recovery tells
11612 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11613 * error recovery. After this call, traffic can start to flow from this device
11617 lpfc_io_resume_s4(struct pci_dev
*pdev
)
11619 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11620 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11623 * In case of slot reset, as function reset is performed through
11624 * mailbox command which needs DMA to be enabled, this operation
11625 * has to be moved to the io resume phase. Taking device offline
11626 * will perform the necessary cleanup.
11628 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
11629 /* Perform device reset */
11630 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
11631 lpfc_offline(phba
);
11632 lpfc_sli_brdrestart(phba
);
11633 /* Bring the device back online */
11637 /* Clean up Advanced Error Reporting (AER) if needed */
11638 if (phba
->hba_flag
& HBA_AER_ENABLED
)
11639 pci_cleanup_aer_uncorrect_error_status(pdev
);
11643 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11644 * @pdev: pointer to PCI device
11645 * @pid: pointer to PCI device identifier
11647 * This routine is to be registered to the kernel's PCI subsystem. When an
11648 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11649 * at PCI device-specific information of the device and driver to see if the
11650 * driver state that it can support this kind of device. If the match is
11651 * successful, the driver core invokes this routine. This routine dispatches
11652 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11653 * do all the initialization that it needs to do to handle the HBA device
11657 * 0 - driver can claim the device
11658 * negative value - driver can not claim the device
11661 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
11664 struct lpfc_sli_intf intf
;
11666 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
11669 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
11670 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
11671 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
11673 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
11679 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11680 * @pdev: pointer to PCI device
11682 * This routine is to be registered to the kernel's PCI subsystem. When an
11683 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11684 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11685 * remove routine, which will perform all the necessary cleanup for the
11686 * device to be removed from the PCI subsystem properly.
11689 lpfc_pci_remove_one(struct pci_dev
*pdev
)
11691 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11692 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11694 switch (phba
->pci_dev_grp
) {
11695 case LPFC_PCI_DEV_LP
:
11696 lpfc_pci_remove_one_s3(pdev
);
11698 case LPFC_PCI_DEV_OC
:
11699 lpfc_pci_remove_one_s4(pdev
);
11702 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11703 "1424 Invalid PCI device group: 0x%x\n",
11704 phba
->pci_dev_grp
);
11711 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11712 * @pdev: pointer to PCI device
11713 * @msg: power management message
11715 * This routine is to be registered to the kernel's PCI subsystem to support
11716 * system Power Management (PM). When PM invokes this method, it dispatches
11717 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11718 * suspend the device.
11721 * 0 - driver suspended the device
11725 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
11727 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11728 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11731 switch (phba
->pci_dev_grp
) {
11732 case LPFC_PCI_DEV_LP
:
11733 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
11735 case LPFC_PCI_DEV_OC
:
11736 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
11739 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11740 "1425 Invalid PCI device group: 0x%x\n",
11741 phba
->pci_dev_grp
);
11748 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11749 * @pdev: pointer to PCI device
11751 * This routine is to be registered to the kernel's PCI subsystem to support
11752 * system Power Management (PM). When PM invokes this method, it dispatches
11753 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11754 * resume the device.
11757 * 0 - driver suspended the device
11761 lpfc_pci_resume_one(struct pci_dev
*pdev
)
11763 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11764 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11767 switch (phba
->pci_dev_grp
) {
11768 case LPFC_PCI_DEV_LP
:
11769 rc
= lpfc_pci_resume_one_s3(pdev
);
11771 case LPFC_PCI_DEV_OC
:
11772 rc
= lpfc_pci_resume_one_s4(pdev
);
11775 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11776 "1426 Invalid PCI device group: 0x%x\n",
11777 phba
->pci_dev_grp
);
11784 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11785 * @pdev: pointer to PCI device.
11786 * @state: the current PCI connection state.
11788 * This routine is registered to the PCI subsystem for error handling. This
11789 * function is called by the PCI subsystem after a PCI bus error affecting
11790 * this device has been detected. When this routine is invoked, it dispatches
11791 * the action to the proper SLI-3 or SLI-4 device error detected handling
11792 * routine, which will perform the proper error detected operation.
11795 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11796 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11798 static pci_ers_result_t
11799 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
11801 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11802 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11803 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
11805 switch (phba
->pci_dev_grp
) {
11806 case LPFC_PCI_DEV_LP
:
11807 rc
= lpfc_io_error_detected_s3(pdev
, state
);
11809 case LPFC_PCI_DEV_OC
:
11810 rc
= lpfc_io_error_detected_s4(pdev
, state
);
11813 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11814 "1427 Invalid PCI device group: 0x%x\n",
11815 phba
->pci_dev_grp
);
11822 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11823 * @pdev: pointer to PCI device.
11825 * This routine is registered to the PCI subsystem for error handling. This
11826 * function is called after PCI bus has been reset to restart the PCI card
11827 * from scratch, as if from a cold-boot. When this routine is invoked, it
11828 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11829 * routine, which will perform the proper device reset.
11832 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11833 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11835 static pci_ers_result_t
11836 lpfc_io_slot_reset(struct pci_dev
*pdev
)
11838 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11839 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11840 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
11842 switch (phba
->pci_dev_grp
) {
11843 case LPFC_PCI_DEV_LP
:
11844 rc
= lpfc_io_slot_reset_s3(pdev
);
11846 case LPFC_PCI_DEV_OC
:
11847 rc
= lpfc_io_slot_reset_s4(pdev
);
11850 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11851 "1428 Invalid PCI device group: 0x%x\n",
11852 phba
->pci_dev_grp
);
11859 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11860 * @pdev: pointer to PCI device
11862 * This routine is registered to the PCI subsystem for error handling. It
11863 * is called when kernel error recovery tells the lpfc driver that it is
11864 * OK to resume normal PCI operation after PCI bus error recovery. When
11865 * this routine is invoked, it dispatches the action to the proper SLI-3
11866 * or SLI-4 device io_resume routine, which will resume the device operation.
11869 lpfc_io_resume(struct pci_dev
*pdev
)
11871 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
11872 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
11874 switch (phba
->pci_dev_grp
) {
11875 case LPFC_PCI_DEV_LP
:
11876 lpfc_io_resume_s3(pdev
);
11878 case LPFC_PCI_DEV_OC
:
11879 lpfc_io_resume_s4(pdev
);
11882 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11883 "1429 Invalid PCI device group: 0x%x\n",
11884 phba
->pci_dev_grp
);
11891 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11892 * @phba: pointer to lpfc hba data structure.
11894 * This routine checks to see if OAS is supported for this adapter. If
11895 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11896 * the enable oas flag is cleared and the pool created for OAS device data
11901 lpfc_sli4_oas_verify(struct lpfc_hba
*phba
)
11904 if (!phba
->cfg_EnableXLane
)
11907 if (phba
->sli4_hba
.pc_sli4_params
.oas_supported
) {
11911 if (phba
->device_data_mem_pool
)
11912 mempool_destroy(phba
->device_data_mem_pool
);
11913 phba
->device_data_mem_pool
= NULL
;
11920 * lpfc_fof_queue_setup - Set up all the fof queues
11921 * @phba: pointer to lpfc hba data structure.
11923 * This routine is invoked to set up all the fof queues for the FC HBA
11928 * -ENOMEM - No available memory
11931 lpfc_fof_queue_setup(struct lpfc_hba
*phba
)
11933 struct lpfc_sli_ring
*pring
;
11936 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.fof_eq
, LPFC_MAX_IMAX
);
11940 if (phba
->cfg_fof
) {
11942 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.oas_cq
,
11943 phba
->sli4_hba
.fof_eq
, LPFC_WCQ
, LPFC_FCP
);
11947 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.oas_wq
,
11948 phba
->sli4_hba
.oas_cq
, LPFC_FCP
);
11952 /* Bind this CQ/WQ to the NVME ring */
11953 pring
= phba
->sli4_hba
.oas_wq
->pring
;
11954 pring
->sli
.sli4
.wqp
=
11955 (void *)phba
->sli4_hba
.oas_wq
;
11956 phba
->sli4_hba
.oas_cq
->pring
= pring
;
11962 lpfc_cq_destroy(phba
, phba
->sli4_hba
.oas_cq
);
11964 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fof_eq
);
11970 * lpfc_fof_queue_create - Create all the fof queues
11971 * @phba: pointer to lpfc hba data structure.
11973 * This routine is invoked to allocate all the fof queues for the FC HBA
11974 * operation. For each SLI4 queue type, the parameters such as queue entry
11975 * count (queue depth) shall be taken from the module parameter. For now,
11976 * we just use some constant number as place holder.
11980 * -ENOMEM - No availble memory
11981 * -EIO - The mailbox failed to complete successfully.
11984 lpfc_fof_queue_create(struct lpfc_hba
*phba
)
11986 struct lpfc_queue
*qdesc
;
11988 /* Create FOF EQ */
11989 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
11990 phba
->sli4_hba
.eq_ecount
);
11994 phba
->sli4_hba
.fof_eq
= qdesc
;
11996 if (phba
->cfg_fof
) {
11998 /* Create OAS CQ */
11999 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
12000 phba
->sli4_hba
.cq_ecount
);
12004 phba
->sli4_hba
.oas_cq
= qdesc
;
12006 /* Create OAS WQ */
12007 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
12008 phba
->sli4_hba
.wq_ecount
);
12012 phba
->sli4_hba
.oas_wq
= qdesc
;
12013 list_add_tail(&qdesc
->wq_list
, &phba
->sli4_hba
.lpfc_wq_list
);
12019 lpfc_fof_queue_destroy(phba
);
12024 * lpfc_fof_queue_destroy - Destroy all the fof queues
12025 * @phba: pointer to lpfc hba data structure.
12027 * This routine is invoked to release all the SLI4 queues with the FC HBA
12034 lpfc_fof_queue_destroy(struct lpfc_hba
*phba
)
12036 /* Release FOF Event queue */
12037 if (phba
->sli4_hba
.fof_eq
!= NULL
) {
12038 lpfc_sli4_queue_free(phba
->sli4_hba
.fof_eq
);
12039 phba
->sli4_hba
.fof_eq
= NULL
;
12042 /* Release OAS Completion queue */
12043 if (phba
->sli4_hba
.oas_cq
!= NULL
) {
12044 lpfc_sli4_queue_free(phba
->sli4_hba
.oas_cq
);
12045 phba
->sli4_hba
.oas_cq
= NULL
;
12048 /* Release OAS Work queue */
12049 if (phba
->sli4_hba
.oas_wq
!= NULL
) {
12050 lpfc_sli4_queue_free(phba
->sli4_hba
.oas_wq
);
12051 phba
->sli4_hba
.oas_wq
= NULL
;
12056 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
12058 static const struct pci_error_handlers lpfc_err_handler
= {
12059 .error_detected
= lpfc_io_error_detected
,
12060 .slot_reset
= lpfc_io_slot_reset
,
12061 .resume
= lpfc_io_resume
,
12064 static struct pci_driver lpfc_driver
= {
12065 .name
= LPFC_DRIVER_NAME
,
12066 .id_table
= lpfc_id_table
,
12067 .probe
= lpfc_pci_probe_one
,
12068 .remove
= lpfc_pci_remove_one
,
12069 .shutdown
= lpfc_pci_remove_one
,
12070 .suspend
= lpfc_pci_suspend_one
,
12071 .resume
= lpfc_pci_resume_one
,
12072 .err_handler
= &lpfc_err_handler
,
12075 static const struct file_operations lpfc_mgmt_fop
= {
12076 .owner
= THIS_MODULE
,
12079 static struct miscdevice lpfc_mgmt_dev
= {
12080 .minor
= MISC_DYNAMIC_MINOR
,
12081 .name
= "lpfcmgmt",
12082 .fops
= &lpfc_mgmt_fop
,
12086 * lpfc_init - lpfc module initialization routine
12088 * This routine is to be invoked when the lpfc module is loaded into the
12089 * kernel. The special kernel macro module_init() is used to indicate the
12090 * role of this routine to the kernel as lpfc module entry point.
12094 * -ENOMEM - FC attach transport failed
12095 * all others - failed
12102 printk(LPFC_MODULE_DESC
"\n");
12103 printk(LPFC_COPYRIGHT
"\n");
12105 error
= misc_register(&lpfc_mgmt_dev
);
12107 printk(KERN_ERR
"Could not register lpfcmgmt device, "
12108 "misc_register returned with status %d", error
);
12110 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
12111 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
12112 lpfc_transport_template
=
12113 fc_attach_transport(&lpfc_transport_functions
);
12114 if (lpfc_transport_template
== NULL
)
12116 lpfc_vport_transport_template
=
12117 fc_attach_transport(&lpfc_vport_transport_functions
);
12118 if (lpfc_vport_transport_template
== NULL
) {
12119 fc_release_transport(lpfc_transport_template
);
12123 /* Initialize in case vector mapping is needed */
12124 lpfc_used_cpu
= NULL
;
12125 lpfc_present_cpu
= num_present_cpus();
12127 error
= pci_register_driver(&lpfc_driver
);
12129 fc_release_transport(lpfc_transport_template
);
12130 fc_release_transport(lpfc_vport_transport_template
);
12137 * lpfc_exit - lpfc module removal routine
12139 * This routine is invoked when the lpfc module is removed from the kernel.
12140 * The special kernel macro module_exit() is used to indicate the role of
12141 * this routine to the kernel as lpfc module exit point.
12146 misc_deregister(&lpfc_mgmt_dev
);
12147 pci_unregister_driver(&lpfc_driver
);
12148 fc_release_transport(lpfc_transport_template
);
12149 fc_release_transport(lpfc_vport_transport_template
);
12150 if (_dump_buf_data
) {
12151 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
12152 "_dump_buf_data at 0x%p\n",
12153 (1L << _dump_buf_data_order
), _dump_buf_data
);
12154 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
12157 if (_dump_buf_dif
) {
12158 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
12159 "_dump_buf_dif at 0x%p\n",
12160 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
12161 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
12163 kfree(lpfc_used_cpu
);
12164 idr_destroy(&lpfc_hba_index
);
12167 module_init(lpfc_init
);
12168 module_exit(lpfc_exit
);
12169 MODULE_LICENSE("GPL");
12170 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
12171 MODULE_AUTHOR("Broadcom");
12172 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);