blob: 1f0a62ecfad8f9960d3e17f8b6a091f197ba8207 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
James Smart3e21d1c2018-05-04 20:37:59 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * 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. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#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>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
James Smart6a828b02019-01-28 11:14:31 -080040#include <linux/irq.h>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070041#include <linux/bitops.h>
James Smart31f06d22019-08-14 16:56:31 -070042#include <linux/crash_dump.h>
James Smartdcaa2132019-11-04 16:57:06 -080043#include <linux/cpu.h>
James Smart93a4d6f2019-11-04 16:57:05 -080044#include <linux/cpuhotplug.h>
dea31012005-04-17 16:05:31 -050045
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040046#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050047#include <scsi/scsi_device.h>
48#include <scsi/scsi_host.h>
49#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070050#include <scsi/scsi_tcq.h>
51#include <scsi/fc/fc_fs.h>
52
James Smartda0436e2009-05-22 14:51:39 -040053#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050054#include "lpfc_hw.h"
55#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040056#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040057#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050058#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050059#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080060#include "lpfc_scsi.h"
61#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050062#include "lpfc_logmsg.h"
63#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050064#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050065#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070066#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050067
James Smart93a4d6f2019-11-04 16:57:05 -080068static enum cpuhp_state lpfc_cpuhp_state;
James Smart7bb03bb2013-04-17 20:19:16 -040069/* Used when mapping IRQ vectors in a driver centric manner */
YueHaibingd7b761b2019-05-31 23:28:41 +080070static uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040071
James Smart93a4d6f2019-11-04 16:57:05 -080072static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
73static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
74static void lpfc_cpuhp_add(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050075static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
76static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040077static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040078static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
79static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040081static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080082static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040084static int lpfc_init_active_sgl_array(struct lpfc_hba *);
85static void lpfc_free_active_sgl(struct lpfc_hba *);
86static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
87static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
88static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
89static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
90static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040091static void lpfc_sli4_disable_intr(struct lpfc_hba *);
92static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050093static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
James Smart6a828b02019-01-28 11:14:31 -080094static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
James Smartaa6ff302019-05-21 17:49:09 -070095static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700156 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
Martin Wilckdfb75132018-11-12 09:58:37 +0100170 /*
171 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
172 * which was already set in lpfc_get_cfgparam()
173 */
174 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500175
dea31012005-04-17 16:05:31 -0500176 /* Setup and issue mailbox READ REV command */
177 lpfc_read_rev(phba, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700180 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400181 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500182 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500183 mb->mbxCommand, mb->mbxStatus);
184 mempool_free( pmb, phba->mbox_mem_pool);
185 return -ERESTART;
186 }
187
James Smart92d7f7b2007-06-17 19:56:38 -0500188
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 /*
190 * The value of rr must be 1 since the driver set the cv field to 1.
191 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500192 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500193 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500194 vp->rev.rBit = 0;
Dick Kennedy372c1872020-06-30 14:50:00 -0700195 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400196 "0440 Adapter failed to init, READ_REV has "
197 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500198 mempool_free(pmb, phba->mbox_mem_pool);
199 return -ERESTART;
dea31012005-04-17 16:05:31 -0500200 }
201
James Smart495a7142008-06-14 22:52:59 -0400202 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
203 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500204 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400205 }
James Smarted957682007-06-17 19:56:37 -0500206
dea31012005-04-17 16:05:31 -0500207 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500208 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500209 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500210 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
211 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
212 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
213 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500214 vp->rev.biuRev = mb->un.varRdRev.biuRev;
215 vp->rev.smRev = mb->un.varRdRev.smRev;
216 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
217 vp->rev.endecRev = mb->un.varRdRev.endecRev;
218 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
219 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
220 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
221 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
222 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
223 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
224
James Smart92d7f7b2007-06-17 19:56:38 -0500225 /* If the sli feature level is less then 9, we must
226 * tear down all RPIs and VPIs on link down if NPIV
227 * is enabled.
228 */
229 if (vp->rev.feaLevelHigh < 9)
230 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
231
dea31012005-04-17 16:05:31 -0500232 if (lpfc_is_LC_HBA(phba->pcidev->device))
233 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
234 sizeof (phba->RandomData));
235
dea31012005-04-17 16:05:31 -0500236 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500237 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
238 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400239 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500240 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400241 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500242 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
243
244 if (rc != MBX_SUCCESS) {
245 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400246 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500247 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500248 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500249 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500250 }
James Smart04c68492009-05-22 14:52:52 -0400251 /* dump mem may return a zero when finished or we got a
252 * mailbox error, either way we are done.
253 */
254 if (mb->un.varDmp.word_cnt == 0)
255 break;
Dick Kennedyd91e3ab2020-06-30 14:49:52 -0700256
257 i = mb->un.varDmp.word_cnt * sizeof(uint32_t);
258 if (offset + i > DMP_VPD_SIZE)
259 i = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400260 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
Dick Kennedyd91e3ab2020-06-30 14:49:52 -0700261 lpfc_vpd_data + offset, i);
262 offset += i;
263 } while (offset < DMP_VPD_SIZE);
264
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500265 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500266
267 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500268out_free_mbox:
269 mempool_free(pmb, phba->mbox_mem_pool);
270 return 0;
271}
272
James Smarte59058c2008-08-24 21:49:00 -0400273/**
James Smart3621a712009-04-06 18:47:14 -0400274 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400275 * @phba: pointer to lpfc hba data structure.
276 * @pmboxq: pointer to the driver internal queue element for mailbox command.
277 *
278 * This is the completion handler for driver's configuring asynchronous event
279 * mailbox command to the device. If the mailbox command returns successfully,
280 * it will set internal async event support flag to 1; otherwise, it will
281 * set internal async event support flag to 0.
282 **/
James Smart57127f12007-10-27 13:37:05 -0400283static void
284lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
285{
James Smart04c68492009-05-22 14:52:52 -0400286 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400287 phba->temp_sensor_support = 1;
288 else
289 phba->temp_sensor_support = 0;
290 mempool_free(pmboxq, phba->mbox_mem_pool);
291 return;
292}
293
James Smarte59058c2008-08-24 21:49:00 -0400294/**
James Smart3621a712009-04-06 18:47:14 -0400295 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500296 * @phba: pointer to lpfc hba data structure.
297 * @pmboxq: pointer to the driver internal queue element for mailbox command.
298 *
299 * This is the completion handler for dump mailbox command for getting
300 * wake up parameters. When this command complete, the response contain
301 * Option rom version of the HBA. This function translate the version number
302 * into a human readable string and store it in OptionROMVersion.
303 **/
304static void
305lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
306{
307 struct prog_id *prg;
308 uint32_t prog_id_word;
309 char dist = ' ';
310 /* character array used for decoding dist type. */
311 char dist_char[] = "nabx";
312
James Smart04c68492009-05-22 14:52:52 -0400313 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500314 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500315 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500316 }
James Smart97207482008-12-04 22:39:19 -0500317
318 prg = (struct prog_id *) &prog_id_word;
319
320 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400321 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500322
323 /* Decode the Option rom version word to a readable string */
324 if (prg->dist < 4)
325 dist = dist_char[prg->dist];
326
327 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400328 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500329 prg->ver, prg->rev, prg->lev);
330 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400331 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500332 prg->ver, prg->rev, prg->lev,
333 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500334 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500335 return;
336}
337
338/**
James Smart05580562011-05-24 11:40:48 -0400339 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
340 * cfg_soft_wwnn, cfg_soft_wwpn
341 * @vport: pointer to lpfc vport data structure.
342 *
343 *
344 * Return codes
345 * None.
346 **/
347void
348lpfc_update_vport_wwn(struct lpfc_vport *vport)
349{
James Smartaeb3c812017-04-21 16:05:02 -0700350 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
351 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
352
James Smart05580562011-05-24 11:40:48 -0400353 /* If the soft name exists then update it using the service params */
354 if (vport->phba->cfg_soft_wwnn)
355 u64_to_wwn(vport->phba->cfg_soft_wwnn,
356 vport->fc_sparam.nodeName.u.wwn);
357 if (vport->phba->cfg_soft_wwpn)
358 u64_to_wwn(vport->phba->cfg_soft_wwpn,
359 vport->fc_sparam.portName.u.wwn);
360
361 /*
362 * If the name is empty or there exists a soft name
363 * then copy the service params name, otherwise use the fc name
364 */
365 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
366 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
367 sizeof(struct lpfc_name));
368 else
369 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
370 sizeof(struct lpfc_name));
371
James Smartaeb3c812017-04-21 16:05:02 -0700372 /*
373 * If the port name has changed, then set the Param changes flag
374 * to unreg the login
375 */
376 if (vport->fc_portname.u.wwn[0] != 0 &&
377 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
378 sizeof(struct lpfc_name)))
379 vport->vport_flag |= FAWWPN_PARAM_CHG;
380
381 if (vport->fc_portname.u.wwn[0] == 0 ||
382 vport->phba->cfg_soft_wwpn ||
383 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
384 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400385 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
386 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700387 vport->vport_flag &= ~FAWWPN_SET;
388 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
389 vport->vport_flag |= FAWWPN_SET;
390 }
James Smart05580562011-05-24 11:40:48 -0400391 else
392 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
393 sizeof(struct lpfc_name));
394}
395
396/**
James Smart3621a712009-04-06 18:47:14 -0400397 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400398 * @phba: pointer to lpfc hba data structure.
399 *
400 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
401 * command call. It performs all internal resource and state setups on the
402 * port: post IOCB buffers, enable appropriate host interrupt attentions,
403 * ELS ring timers, etc.
404 *
405 * Return codes
406 * 0 - success.
407 * Any other value - error.
408 **/
dea31012005-04-17 16:05:31 -0500409int
James Smart2e0fef82007-06-17 19:56:36 -0500410lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500414 LPFC_MBOXQ_t *pmb;
415 MAILBOX_t *mb;
416 struct lpfc_dmabuf *mp;
417 struct lpfc_sli *psli = &phba->sli;
418 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500419 int i, j;
420 int rc;
dea31012005-04-17 16:05:31 -0500421
James Smart7af67052007-10-27 13:38:11 -0400422 spin_lock_irq(&phba->hbalock);
423 /*
424 * If the Config port completed correctly the HBA is not
425 * over heated any more.
426 */
427 if (phba->over_temp_state == HBA_OVER_TEMP)
428 phba->over_temp_state = HBA_NORMAL_TEMP;
429 spin_unlock_irq(&phba->hbalock);
430
dea31012005-04-17 16:05:31 -0500431 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
432 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500433 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500434 return -ENOMEM;
435 }
James Smart04c68492009-05-22 14:52:52 -0400436 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500437
dea31012005-04-17 16:05:31 -0500438 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500439 rc = lpfc_read_sparam(phba, pmb, 0);
440 if (rc) {
441 mempool_free(pmb, phba->mbox_mem_pool);
442 return -ENOMEM;
443 }
444
James Smarted957682007-06-17 19:56:37 -0500445 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500446 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700447 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400448 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500449 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500450 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500451 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800452 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -0500453 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500454 lpfc_mbuf_free(phba, mp->virt, mp->phys);
455 kfree(mp);
456 return -EIO;
457 }
458
James Smart3e1f0712018-11-29 16:09:29 -0800459 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500460
James Smart2e0fef82007-06-17 19:56:36 -0500461 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500462 lpfc_mbuf_free(phba, mp->virt, mp->phys);
463 kfree(mp);
James Smart3e1f0712018-11-29 16:09:29 -0800464 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400465 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400466
467 /* Update the fc_host data structures with new wwn. */
468 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
469 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400470 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400471
dea31012005-04-17 16:05:31 -0500472 /* If no serial number in VPD data, use low 6 bytes of WWNN */
473 /* This should be consolidated into parse_vpd ? - mr */
474 if (phba->SerialNumber[0] == 0) {
475 uint8_t *outptr;
476
James Smart2e0fef82007-06-17 19:56:36 -0500477 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500478 for (i = 0; i < 12; i++) {
479 status = *outptr++;
480 j = ((status & 0xf0) >> 4);
481 if (j <= 9)
482 phba->SerialNumber[i] =
483 (char)((uint8_t) 0x30 + (uint8_t) j);
484 else
485 phba->SerialNumber[i] =
486 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
487 i++;
488 j = (status & 0xf);
489 if (j <= 9)
490 phba->SerialNumber[i] =
491 (char)((uint8_t) 0x30 + (uint8_t) j);
492 else
493 phba->SerialNumber[i] =
494 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
495 }
496 }
497
dea31012005-04-17 16:05:31 -0500498 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500499 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500500 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700501 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400502 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500503 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500504 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500505 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500506 mempool_free( pmb, phba->mbox_mem_pool);
507 return -EIO;
508 }
509
James Smarta0c87cb2009-07-19 10:01:10 -0400510 /* Check if the port is disabled */
511 lpfc_sli_read_link_ste(phba);
512
dea31012005-04-17 16:05:31 -0500513 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartf6770e72020-01-27 16:23:09 -0800514 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
James Smart572709e2013-07-15 18:32:43 -0400515 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
516 "3359 HBA queue depth changed from %d to %d\n",
James Smartf6770e72020-01-27 16:23:09 -0800517 phba->cfg_hba_queue_depth,
518 mb->un.varRdConfig.max_xri);
519 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
James Smart572709e2013-07-15 18:32:43 -0400520 }
dea31012005-04-17 16:05:31 -0500521
522 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500523
524 /* Get the default values for Model Name and Description */
525 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
526
James Smart2e0fef82007-06-17 19:56:36 -0500527 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500528
James Smart0b727fe2007-10-27 13:37:25 -0400529 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800530 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
531 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
532 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
533 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500534
535 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500536 if (phba->sli_rev != 3)
537 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500538
James Smart93996272008-08-24 21:50:30 -0400539 /*
540 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
541 */
542 if (phba->intr_type == MSIX) {
543 rc = lpfc_config_msi(phba, pmb);
544 if (rc) {
545 mempool_free(pmb, phba->mbox_mem_pool);
546 return -EIO;
547 }
548 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
549 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700550 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart93996272008-08-24 21:50:30 -0400551 "0352 Config MSI mailbox command "
552 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400553 pmb->u.mb.mbxCommand,
554 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400555 mempool_free(pmb, phba->mbox_mem_pool);
556 return -EIO;
557 }
558 }
559
James Smart04c68492009-05-22 14:52:52 -0400560 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400561 /* Initialize ERATT handling flag */
562 phba->hba_flag &= ~HBA_ERATT_HANDLED;
563
dea31012005-04-17 16:05:31 -0500564 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500565 if (lpfc_readl(phba->HCregaddr, &status)) {
566 spin_unlock_irq(&phba->hbalock);
567 return -EIO;
568 }
dea31012005-04-17 16:05:31 -0500569 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
570 if (psli->num_rings > 0)
571 status |= HC_R0INT_ENA;
572 if (psli->num_rings > 1)
573 status |= HC_R1INT_ENA;
574 if (psli->num_rings > 2)
575 status |= HC_R2INT_ENA;
576 if (psli->num_rings > 3)
577 status |= HC_R3INT_ENA;
578
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500579 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
580 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400581 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500582
dea31012005-04-17 16:05:31 -0500583 writel(status, phba->HCregaddr);
584 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500585 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500586
James Smart93996272008-08-24 21:50:30 -0400587 /* Set up ring-0 (ELS) timer */
588 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400589 mod_timer(&vport->els_tmofunc,
590 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400591 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400592 mod_timer(&phba->hb_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500594 phba->hb_outstanding = 0;
595 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400596 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400597 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700598 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500599
James Smarta0c87cb2009-07-19 10:01:10 -0400600 if (phba->hba_flag & LINK_DISABLED) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700601 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
602 "2598 Adapter Link is disabled.\n");
James Smarta0c87cb2009-07-19 10:01:10 -0400603 lpfc_down_link(phba, pmb);
604 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
605 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
606 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700607 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
608 "2599 Adapter failed to issue DOWN_LINK"
609 " mbox command rc 0x%x\n", rc);
James Smarta0c87cb2009-07-19 10:01:10 -0400610
611 mempool_free(pmb, phba->mbox_mem_pool);
612 return -EIO;
613 }
James Smarte40a02c2010-02-26 14:13:54 -0500614 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500615 mempool_free(pmb, phba->mbox_mem_pool);
616 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
617 if (rc)
618 return rc;
dea31012005-04-17 16:05:31 -0500619 }
620 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400621 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500622 if (!pmb) {
623 phba->link_state = LPFC_HBA_ERROR;
624 return -ENOMEM;
625 }
626
James Smart57127f12007-10-27 13:37:05 -0400627 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
628 pmb->mbox_cmpl = lpfc_config_async_cmpl;
629 pmb->vport = phba->pport;
630 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500631
James Smart57127f12007-10-27 13:37:05 -0400632 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700633 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart57127f12007-10-27 13:37:05 -0400634 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400635 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400636 rc);
637 mempool_free(pmb, phba->mbox_mem_pool);
638 }
James Smart97207482008-12-04 22:39:19 -0500639
640 /* Get Option rom version */
641 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500642 if (!pmb) {
643 phba->link_state = LPFC_HBA_ERROR;
644 return -ENOMEM;
645 }
646
James Smart97207482008-12-04 22:39:19 -0500647 lpfc_dump_wakeup_param(phba, pmb);
648 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
649 pmb->vport = phba->pport;
650 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
651
652 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700653 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
654 "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400655 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500656 mempool_free(pmb, phba->mbox_mem_pool);
657 }
658
James Smartd7c255b2008-08-24 21:50:00 -0400659 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400660}
661
James Smarte59058c2008-08-24 21:49:00 -0400662/**
James Smart84d1b002010-02-12 14:42:33 -0500663 * lpfc_hba_init_link - Initialize the FC link
664 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400665 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500666 *
667 * This routine will issue the INIT_LINK mailbox command call.
668 * It is available to other drivers through the lpfc_hba data
669 * structure for use as a delayed link up mechanism with the
670 * module parameter lpfc_suppress_link_up.
671 *
672 * Return code
673 * 0 - success
674 * Any other value - error
675 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400676static int
James Smart6e7288d2010-06-07 15:23:35 -0400677lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500678{
James Smart1b511972011-12-13 13:23:09 -0500679 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
680}
681
682/**
683 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
684 * @phba: pointer to lpfc hba data structure.
685 * @fc_topology: desired fc topology.
686 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
687 *
688 * This routine will issue the INIT_LINK mailbox command call.
689 * It is available to other drivers through the lpfc_hba data
690 * structure for use as a delayed link up mechanism with the
691 * module parameter lpfc_suppress_link_up.
692 *
693 * Return code
694 * 0 - success
695 * Any other value - error
696 **/
697int
698lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
699 uint32_t flag)
700{
James Smart84d1b002010-02-12 14:42:33 -0500701 struct lpfc_vport *vport = phba->pport;
702 LPFC_MBOXQ_t *pmb;
703 MAILBOX_t *mb;
704 int rc;
705
706 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
707 if (!pmb) {
708 phba->link_state = LPFC_HBA_ERROR;
709 return -ENOMEM;
710 }
711 mb = &pmb->u.mb;
712 pmb->vport = vport;
713
James Smart026abb82011-12-13 13:20:45 -0500714 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
715 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
716 !(phba->lmt & LMT_1Gb)) ||
717 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
718 !(phba->lmt & LMT_2Gb)) ||
719 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
720 !(phba->lmt & LMT_4Gb)) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
722 !(phba->lmt & LMT_8Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
724 !(phba->lmt & LMT_10Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400726 !(phba->lmt & LMT_16Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800728 !(phba->lmt & LMT_32Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
730 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500731 /* Reset link speed to auto */
Dick Kennedy372c1872020-06-30 14:50:00 -0700732 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
733 "1302 Invalid speed for this board:%d "
734 "Reset link speed to auto.\n",
735 phba->cfg_link_speed);
James Smart026abb82011-12-13 13:20:45 -0500736 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
737 }
James Smart1b511972011-12-13 13:23:09 -0500738 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500739 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500740 if (phba->sli_rev < LPFC_SLI_REV4)
741 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400742 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500743 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700744 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
745 "0498 Adapter failed to init, mbxCmd x%x "
746 "INIT_LINK, mbxStatus x%x\n",
747 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500748 if (phba->sli_rev <= LPFC_SLI_REV3) {
749 /* Clear all interrupt enable conditions */
750 writel(0, phba->HCregaddr);
751 readl(phba->HCregaddr); /* flush */
752 /* Clear all pending interrupts */
753 writel(0xffffffff, phba->HAregaddr);
754 readl(phba->HAregaddr); /* flush */
755 }
James Smart84d1b002010-02-12 14:42:33 -0500756 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400757 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500758 mempool_free(pmb, phba->mbox_mem_pool);
759 return -EIO;
760 }
James Smarte40a02c2010-02-26 14:13:54 -0500761 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400762 if (flag == MBX_POLL)
763 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500764
765 return 0;
766}
767
768/**
769 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400770 * @phba: pointer to lpfc hba data structure.
771 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500772 *
773 * This routine will issue the DOWN_LINK mailbox command call.
774 * It is available to other drivers through the lpfc_hba data
775 * structure for use to stop the link.
776 *
777 * Return code
778 * 0 - success
779 * Any other value - error
780 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400781static int
James Smart6e7288d2010-06-07 15:23:35 -0400782lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500783{
784 LPFC_MBOXQ_t *pmb;
785 int rc;
786
787 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
788 if (!pmb) {
789 phba->link_state = LPFC_HBA_ERROR;
790 return -ENOMEM;
791 }
792
Dick Kennedy372c1872020-06-30 14:50:00 -0700793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
794 "0491 Adapter Link is disabled.\n");
James Smart84d1b002010-02-12 14:42:33 -0500795 lpfc_down_link(phba, pmb);
796 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400797 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500798 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700799 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
800 "2522 Adapter failed to issue DOWN_LINK"
801 " mbox command rc 0x%x\n", rc);
James Smart84d1b002010-02-12 14:42:33 -0500802
803 mempool_free(pmb, phba->mbox_mem_pool);
804 return -EIO;
805 }
James Smart6e7288d2010-06-07 15:23:35 -0400806 if (flag == MBX_POLL)
807 mempool_free(pmb, phba->mbox_mem_pool);
808
James Smart84d1b002010-02-12 14:42:33 -0500809 return 0;
810}
811
812/**
James Smart3621a712009-04-06 18:47:14 -0400813 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400814 * @phba: pointer to lpfc HBA data structure.
815 *
816 * This routine will do LPFC uninitialization before the HBA is reset when
817 * bringing down the SLI Layer.
818 *
819 * Return codes
820 * 0 - success.
821 * Any other value - error.
822 **/
dea31012005-04-17 16:05:31 -0500823int
James Smart2e0fef82007-06-17 19:56:36 -0500824lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500825{
James Smart1b32f6a2008-02-08 18:49:39 -0500826 struct lpfc_vport **vports;
827 int i;
James Smart3772a992009-05-22 14:50:54 -0400828
829 if (phba->sli_rev <= LPFC_SLI_REV3) {
830 /* Disable interrupts */
831 writel(0, phba->HCregaddr);
832 readl(phba->HCregaddr); /* flush */
833 }
dea31012005-04-17 16:05:31 -0500834
James Smart1b32f6a2008-02-08 18:49:39 -0500835 if (phba->pport->load_flag & FC_UNLOADING)
836 lpfc_cleanup_discovery_resources(phba->pport);
837 else {
838 vports = lpfc_create_vport_work_array(phba);
839 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400840 for (i = 0; i <= phba->max_vports &&
841 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500842 lpfc_cleanup_discovery_resources(vports[i]);
843 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500844 }
845 return 0;
dea31012005-04-17 16:05:31 -0500846}
847
James Smarte59058c2008-08-24 21:49:00 -0400848/**
James Smart68e814f2014-05-21 08:04:59 -0400849 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
850 * rspiocb which got deferred
851 *
852 * @phba: pointer to lpfc HBA data structure.
853 *
854 * This routine will cleanup completed slow path events after HBA is reset
855 * when bringing down the SLI Layer.
856 *
857 *
858 * Return codes
859 * void.
860 **/
861static void
862lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
863{
864 struct lpfc_iocbq *rspiocbq;
865 struct hbq_dmabuf *dmabuf;
866 struct lpfc_cq_event *cq_event;
867
868 spin_lock_irq(&phba->hbalock);
869 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
870 spin_unlock_irq(&phba->hbalock);
871
872 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
873 /* Get the response iocb from the head of work queue */
874 spin_lock_irq(&phba->hbalock);
875 list_remove_head(&phba->sli4_hba.sp_queue_event,
876 cq_event, struct lpfc_cq_event, list);
877 spin_unlock_irq(&phba->hbalock);
878
879 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
880 case CQE_CODE_COMPL_WQE:
881 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
882 cq_event);
883 lpfc_sli_release_iocbq(phba, rspiocbq);
884 break;
885 case CQE_CODE_RECEIVE:
886 case CQE_CODE_RECEIVE_V1:
887 dmabuf = container_of(cq_event, struct hbq_dmabuf,
888 cq_event);
889 lpfc_in_buf_free(phba, &dmabuf->dbuf);
890 }
891 }
892}
893
894/**
James Smartbcece5f2014-04-04 13:51:34 -0400895 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
896 * @phba: pointer to lpfc HBA data structure.
897 *
898 * This routine will cleanup posted ELS buffers after the HBA is reset
899 * when bringing down the SLI Layer.
900 *
901 *
902 * Return codes
903 * void.
904 **/
905static void
906lpfc_hba_free_post_buf(struct lpfc_hba *phba)
907{
908 struct lpfc_sli *psli = &phba->sli;
909 struct lpfc_sli_ring *pring;
910 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400911 LIST_HEAD(buflist);
912 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400913
914 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
915 lpfc_sli_hbqbuf_free_all(phba);
916 else {
917 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800918 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400919 spin_lock_irq(&phba->hbalock);
920 list_splice_init(&pring->postbufq, &buflist);
921 spin_unlock_irq(&phba->hbalock);
922
923 count = 0;
924 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400925 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400926 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400927 lpfc_mbuf_free(phba, mp->virt, mp->phys);
928 kfree(mp);
929 }
James Smart07eab622014-04-04 13:51:44 -0400930
931 spin_lock_irq(&phba->hbalock);
932 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400933 spin_unlock_irq(&phba->hbalock);
934 }
935}
936
937/**
938 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
939 * @phba: pointer to lpfc HBA data structure.
940 *
941 * This routine will cleanup the txcmplq after the HBA is reset when bringing
942 * down the SLI Layer.
943 *
944 * Return codes
945 * void
946 **/
947static void
948lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
949{
950 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800951 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400952 struct lpfc_sli_ring *pring;
953 LIST_HEAD(completions);
954 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800955 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400956
James Smart895427b2017-02-12 13:52:30 -0800957 if (phba->sli_rev != LPFC_SLI_REV4) {
958 for (i = 0; i < psli->num_rings; i++) {
959 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400960 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800961 /* At this point in time the HBA is either reset or DOA
962 * Nothing should be on txcmplq as it will
963 * NEVER complete.
964 */
965 list_splice_init(&pring->txcmplq, &completions);
966 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400967 spin_unlock_irq(&phba->hbalock);
968
James Smart895427b2017-02-12 13:52:30 -0800969 lpfc_sli_abort_iocb_ring(phba, pring);
970 }
James Smartbcece5f2014-04-04 13:51:34 -0400971 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800972 lpfc_sli_cancel_iocbs(phba, &completions,
973 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
974 return;
975 }
976 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
977 pring = qp->pring;
978 if (!pring)
979 continue;
980 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800981 list_for_each_entry_safe(piocb, next_iocb,
982 &pring->txcmplq, list)
983 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800984 list_splice_init(&pring->txcmplq, &completions);
985 pring->txcmplq_cnt = 0;
986 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400987 lpfc_sli_abort_iocb_ring(phba, pring);
988 }
James Smart895427b2017-02-12 13:52:30 -0800989 /* Cancel all the IOCBs from the completions list */
990 lpfc_sli_cancel_iocbs(phba, &completions,
991 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400992}
993
994/**
James Smart3772a992009-05-22 14:50:54 -0400995 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400996 * @phba: pointer to lpfc HBA data structure.
997 *
998 * This routine will do uninitialization after the HBA is reset when bring
999 * down the SLI Layer.
1000 *
1001 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001002 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001003 * Any other value - error.
1004 **/
James Smart3772a992009-05-22 14:50:54 -04001005static int
1006lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001007{
James Smartbcece5f2014-04-04 13:51:34 -04001008 lpfc_hba_free_post_buf(phba);
1009 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001010 return 0;
1011}
James Smart5af5eee2010-10-22 11:06:38 -04001012
James Smartda0436e2009-05-22 14:51:39 -04001013/**
1014 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1015 * @phba: pointer to lpfc HBA data structure.
1016 *
1017 * This routine will do uninitialization after the HBA is reset when bring
1018 * down the SLI Layer.
1019 *
1020 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001021 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001022 * Any other value - error.
1023 **/
1024static int
1025lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1026{
James Smartc4908502019-01-28 11:14:28 -08001027 struct lpfc_io_buf *psb, *psb_next;
James Smart7cacae22020-03-31 09:50:03 -07001028 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
James Smart5e5b5112019-01-28 11:14:22 -08001029 struct lpfc_sli4_hdw_queue *qp;
James Smartda0436e2009-05-22 14:51:39 -04001030 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001031 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001032 LIST_HEAD(nvmet_aborts);
James Smart0f65ff62010-02-26 14:14:23 -05001033 struct lpfc_sglq *sglq_entry = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08001034 int cnt, idx;
James Smart0f65ff62010-02-26 14:14:23 -05001035
James Smart895427b2017-02-12 13:52:30 -08001036
1037 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001038 lpfc_hba_clean_txcmplq(phba);
1039
James Smartda0436e2009-05-22 14:51:39 -04001040 /* At this point in time the HBA is either reset or DOA. Either
1041 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001042 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001043 * driver is unloading or reposted if the driver is restarting
1044 * the port.
1045 */
James Smart895427b2017-02-12 13:52:30 -08001046 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001047 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001048 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001049 * list.
1050 */
James Smart895427b2017-02-12 13:52:30 -08001051 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001052 list_for_each_entry(sglq_entry,
1053 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1054 sglq_entry->state = SGL_FREED;
1055
James Smartda0436e2009-05-22 14:51:39 -04001056 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001057 &phba->sli4_hba.lpfc_els_sgl_list);
1058
James Smartf358dd02017-02-12 13:52:34 -08001059
James Smart895427b2017-02-12 13:52:30 -08001060 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001061
1062 /* abts_xxxx_buf_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001063 * list.
1064 */
James Smart5e5b5112019-01-28 11:14:22 -08001065 cnt = 0;
1066 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1067 qp = &phba->sli4_hba.hdwq[idx];
1068
James Smartc00f62e2019-08-14 16:57:11 -07001069 spin_lock(&qp->abts_io_buf_list_lock);
1070 list_splice_init(&qp->lpfc_abts_io_buf_list,
James Smart895427b2017-02-12 13:52:30 -08001071 &aborts);
James Smart895427b2017-02-12 13:52:30 -08001072
James Smart0794d602019-01-28 11:14:19 -08001073 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
James Smart86c67372017-04-21 16:05:04 -07001074 psb->pCmd = NULL;
1075 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001076 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001077 }
James Smart5e5b5112019-01-28 11:14:22 -08001078 spin_lock(&qp->io_buf_list_put_lock);
1079 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1080 qp->put_io_bufs += qp->abts_scsi_io_bufs;
James Smartc00f62e2019-08-14 16:57:11 -07001081 qp->put_io_bufs += qp->abts_nvme_io_bufs;
James Smart5e5b5112019-01-28 11:14:22 -08001082 qp->abts_scsi_io_bufs = 0;
James Smartc00f62e2019-08-14 16:57:11 -07001083 qp->abts_nvme_io_bufs = 0;
James Smart5e5b5112019-01-28 11:14:22 -08001084 spin_unlock(&qp->io_buf_list_put_lock);
James Smartc00f62e2019-08-14 16:57:11 -07001085 spin_unlock(&qp->abts_io_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001086 }
James Smart731eedc2019-03-12 16:30:12 -07001087 spin_unlock_irq(&phba->hbalock);
James Smart5e5b5112019-01-28 11:14:22 -08001088
1089 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart731eedc2019-03-12 16:30:12 -07001090 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001091 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1092 &nvmet_aborts);
James Smart731eedc2019-03-12 16:30:12 -07001093 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001094 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
James Smart7b7f5512020-03-31 09:50:04 -07001095 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001096 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001097 }
James Smart895427b2017-02-12 13:52:30 -08001098 }
James Smart895427b2017-02-12 13:52:30 -08001099
James Smart68e814f2014-05-21 08:04:59 -04001100 lpfc_sli4_free_sp_events(phba);
James Smart5e5b5112019-01-28 11:14:22 -08001101 return cnt;
James Smartda0436e2009-05-22 14:51:39 -04001102}
1103
1104/**
1105 * lpfc_hba_down_post - Wrapper func for hba down post routine
1106 * @phba: pointer to lpfc HBA data structure.
1107 *
1108 * This routine wraps the actual SLI3 or SLI4 routine for performing
1109 * uninitialization after the HBA is reset when bring down the SLI Layer.
1110 *
1111 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001112 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001113 * Any other value - error.
1114 **/
1115int
1116lpfc_hba_down_post(struct lpfc_hba *phba)
1117{
1118 return (*phba->lpfc_hba_down_post)(phba);
1119}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001120
James Smarte59058c2008-08-24 21:49:00 -04001121/**
James Smart3621a712009-04-06 18:47:14 -04001122 * lpfc_hb_timeout - The HBA-timer timeout handler
Lee Jonesfe614ac2020-07-23 13:24:22 +01001123 * @t: timer context used to obtain the pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04001124 *
1125 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1126 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1127 * work-port-events bitmap and the worker thread is notified. This timeout
1128 * event will be used by the worker thread to invoke the actual timeout
1129 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1130 * be performed in the timeout handler and the HBA timeout event bit shall
1131 * be cleared by the worker thread after it has taken the event bitmap out.
1132 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001133static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001134lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001135{
1136 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001137 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001138 unsigned long iflag;
1139
Kees Cookf22eb4d2017-09-06 20:24:26 -07001140 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001141
1142 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001143 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001144 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1145 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001146 phba->pport->work_port_events |= WORKER_HB_TMO;
1147 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1148
James Smart93996272008-08-24 21:50:30 -04001149 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001150 if (!tmo_posted)
1151 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001152 return;
1153}
1154
James Smarte59058c2008-08-24 21:49:00 -04001155/**
James Smart19ca7602010-11-20 23:11:55 -05001156 * lpfc_rrq_timeout - The RRQ-timer timeout handler
Lee Jonesfe614ac2020-07-23 13:24:22 +01001157 * @t: timer context used to obtain the pointer to lpfc hba data structure.
James Smart19ca7602010-11-20 23:11:55 -05001158 *
1159 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1160 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1161 * work-port-events bitmap and the worker thread is notified. This timeout
1162 * event will be used by the worker thread to invoke the actual timeout
1163 * handler routine, lpfc_rrq_handler. Any periodical operations will
1164 * be performed in the timeout handler and the RRQ timeout event bit shall
1165 * be cleared by the worker thread after it has taken the event bitmap out.
1166 **/
1167static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001168lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001169{
1170 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001171 unsigned long iflag;
1172
Kees Cookf22eb4d2017-09-06 20:24:26 -07001173 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001174 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001175 if (!(phba->pport->load_flag & FC_UNLOADING))
1176 phba->hba_flag |= HBA_RRQ_ACTIVE;
1177 else
1178 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001179 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001180
1181 if (!(phba->pport->load_flag & FC_UNLOADING))
1182 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001183}
1184
1185/**
James Smart3621a712009-04-06 18:47:14 -04001186 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001187 * @phba: pointer to lpfc hba data structure.
1188 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1189 *
1190 * This is the callback function to the lpfc heart-beat mailbox command.
1191 * If configured, the lpfc driver issues the heart-beat mailbox command to
1192 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1193 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1194 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1195 * heart-beat outstanding state. Once the mailbox command comes back and
1196 * no error conditions detected, the heart-beat mailbox command timer is
1197 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1198 * state is cleared for the next heart-beat. If the timer expired with the
1199 * heart-beat outstanding state set, the driver will put the HBA offline.
1200 **/
James Smart858c9f62007-06-17 19:56:39 -05001201static void
1202lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1203{
1204 unsigned long drvr_flag;
1205
1206 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1207 phba->hb_outstanding = 0;
1208 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1209
James Smart93996272008-08-24 21:50:30 -04001210 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001211 mempool_free(pmboxq, phba->mbox_mem_pool);
1212 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1213 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001214 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001215 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001216 jiffies +
1217 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001218 return;
1219}
1220
Lee Jonesfe614ac2020-07-23 13:24:22 +01001221/*
Dick Kennedy317aeb82020-06-30 14:49:59 -07001222 * lpfc_idle_stat_delay_work - idle_stat tracking
1223 *
1224 * This routine tracks per-cq idle_stat and determines polling decisions.
1225 *
1226 * Return codes:
1227 * None
1228 **/
1229static void
1230lpfc_idle_stat_delay_work(struct work_struct *work)
1231{
1232 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1233 struct lpfc_hba,
1234 idle_stat_delay_work);
1235 struct lpfc_queue *cq;
1236 struct lpfc_sli4_hdw_queue *hdwq;
1237 struct lpfc_idle_stat *idle_stat;
1238 u32 i, idle_percent;
1239 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1240
1241 if (phba->pport->load_flag & FC_UNLOADING)
1242 return;
1243
1244 if (phba->link_state == LPFC_HBA_ERROR ||
1245 phba->pport->fc_flag & FC_OFFLINE_MODE)
1246 goto requeue;
1247
1248 for_each_present_cpu(i) {
1249 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1250 cq = hdwq->io_cq;
1251
1252 /* Skip if we've already handled this cq's primary CPU */
1253 if (cq->chann != i)
1254 continue;
1255
1256 idle_stat = &phba->sli4_hba.idle_stat[i];
1257
1258 /* get_cpu_idle_time returns values as running counters. Thus,
1259 * to know the amount for this period, the prior counter values
1260 * need to be subtracted from the current counter values.
1261 * From there, the idle time stat can be calculated as a
1262 * percentage of 100 - the sum of the other consumption times.
1263 */
1264 wall_idle = get_cpu_idle_time(i, &wall, 1);
1265 diff_idle = wall_idle - idle_stat->prev_idle;
1266 diff_wall = wall - idle_stat->prev_wall;
1267
1268 if (diff_wall <= diff_idle)
1269 busy_time = 0;
1270 else
1271 busy_time = diff_wall - diff_idle;
1272
1273 idle_percent = div64_u64(100 * busy_time, diff_wall);
1274 idle_percent = 100 - idle_percent;
1275
1276 if (idle_percent < 15)
1277 cq->poll_mode = LPFC_QUEUE_WORK;
1278 else
1279 cq->poll_mode = LPFC_IRQ_POLL;
1280
1281 idle_stat->prev_idle = wall_idle;
1282 idle_stat->prev_wall = wall;
1283 }
1284
1285requeue:
1286 schedule_delayed_work(&phba->idle_stat_delay_work,
1287 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1288}
1289
James Smart32517fc2019-01-28 11:14:33 -08001290static void
1291lpfc_hb_eq_delay_work(struct work_struct *work)
1292{
1293 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1294 struct lpfc_hba, eq_delay_work);
1295 struct lpfc_eq_intr_info *eqi, *eqi_new;
1296 struct lpfc_queue *eq, *eq_next;
James Smart8156d372019-10-18 14:18:26 -07001297 unsigned char *ena_delay = NULL;
James Smart32517fc2019-01-28 11:14:33 -08001298 uint32_t usdelay;
1299 int i;
1300
1301 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1302 return;
1303
1304 if (phba->link_state == LPFC_HBA_ERROR ||
1305 phba->pport->fc_flag & FC_OFFLINE_MODE)
1306 goto requeue;
1307
James Smart8156d372019-10-18 14:18:26 -07001308 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1309 GFP_KERNEL);
1310 if (!ena_delay)
James Smart32517fc2019-01-28 11:14:33 -08001311 goto requeue;
1312
James Smart8156d372019-10-18 14:18:26 -07001313 for (i = 0; i < phba->cfg_irq_chann; i++) {
1314 /* Get the EQ corresponding to the IRQ vector */
1315 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1316 if (!eq)
1317 continue;
1318 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1319 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1320 ena_delay[eq->last_cpu] = 1;
James Smart8d34a592019-08-14 16:56:35 -07001321 }
James Smart8156d372019-10-18 14:18:26 -07001322 }
James Smart32517fc2019-01-28 11:14:33 -08001323
1324 for_each_present_cpu(i) {
James Smart32517fc2019-01-28 11:14:33 -08001325 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
James Smart8156d372019-10-18 14:18:26 -07001326 if (ena_delay[i]) {
1327 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1328 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1329 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1330 } else {
1331 usdelay = 0;
James Smart8d34a592019-08-14 16:56:35 -07001332 }
James Smart32517fc2019-01-28 11:14:33 -08001333
James Smart32517fc2019-01-28 11:14:33 -08001334 eqi->icnt = 0;
1335
1336 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
James Smart8156d372019-10-18 14:18:26 -07001337 if (unlikely(eq->last_cpu != i)) {
James Smart32517fc2019-01-28 11:14:33 -08001338 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1339 eq->last_cpu);
1340 list_move_tail(&eq->cpu_list, &eqi_new->list);
1341 continue;
1342 }
1343 if (usdelay != eq->q_mode)
1344 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1345 usdelay);
1346 }
1347 }
1348
James Smart8156d372019-10-18 14:18:26 -07001349 kfree(ena_delay);
James Smart32517fc2019-01-28 11:14:33 -08001350
1351requeue:
1352 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1353 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1354}
1355
James Smarte59058c2008-08-24 21:49:00 -04001356/**
James Smartc4908502019-01-28 11:14:28 -08001357 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1358 * @phba: pointer to lpfc hba data structure.
1359 *
1360 * For each heartbeat, this routine does some heuristic methods to adjust
1361 * XRI distribution. The goal is to fully utilize free XRIs.
1362 **/
1363static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1364{
1365 u32 i;
1366 u32 hwq_count;
1367
1368 hwq_count = phba->cfg_hdw_queue;
1369 for (i = 0; i < hwq_count; i++) {
1370 /* Adjust XRIs in private pool */
1371 lpfc_adjust_pvt_pool_count(phba, i);
1372
1373 /* Adjust high watermark */
1374 lpfc_adjust_high_watermark(phba, i);
1375
1376#ifdef LPFC_MXP_STAT
1377 /* Snapshot pbl, pvt and busy count */
1378 lpfc_snapshot_mxp(phba, i);
1379#endif
1380 }
1381}
1382
James Smarte59058c2008-08-24 21:49:00 -04001383/**
James Smart3621a712009-04-06 18:47:14 -04001384 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001385 * @phba: pointer to lpfc hba data structure.
1386 *
1387 * This is the actual HBA-timer timeout handler to be invoked by the worker
1388 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1389 * handler performs any periodic operations needed for the device. If such
1390 * periodic event has already been attended to either in the interrupt handler
1391 * or by processing slow-ring or fast-ring events within the HBA-timer
1392 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1393 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1394 * is configured and there is no heart-beat mailbox command outstanding, a
1395 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1396 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1397 * to offline.
1398 **/
James Smart858c9f62007-06-17 19:56:39 -05001399void
1400lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1401{
James Smart45ed1192009-10-02 15:17:02 -04001402 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001403 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001404 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001405 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001406 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001407 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001408
James Smartc4908502019-01-28 11:14:28 -08001409 if (phba->cfg_xri_rebalancing) {
1410 /* Multi-XRI pools handler */
1411 lpfc_hb_mxp_handler(phba);
1412 }
James Smart858c9f62007-06-17 19:56:39 -05001413
James Smart45ed1192009-10-02 15:17:02 -04001414 vports = lpfc_create_vport_work_array(phba);
1415 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001416 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001417 lpfc_rcv_seq_check_edtov(vports[i]);
James Smarte3ba04c2019-12-18 15:58:02 -08001418 lpfc_fdmi_change_check(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001419 }
James Smart45ed1192009-10-02 15:17:02 -04001420 lpfc_destroy_vport_work_array(phba, vports);
1421
James Smart858c9f62007-06-17 19:56:39 -05001422 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001423 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001424 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1425 return;
1426
1427 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001428
James Smart256ec0d2013-04-17 20:14:58 -04001429 if (time_after(phba->last_completion_time +
1430 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1431 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001432 spin_unlock_irq(&phba->pport->work_port_lock);
1433 if (!phba->hb_outstanding)
1434 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001435 jiffies +
1436 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001437 else
1438 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001439 jiffies +
1440 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001441 return;
1442 }
1443 spin_unlock_irq(&phba->pport->work_port_lock);
1444
James Smart0ff10d42008-01-11 01:52:36 -05001445 if (phba->elsbuf_cnt &&
1446 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1447 spin_lock_irq(&phba->hbalock);
1448 list_splice_init(&phba->elsbuf, &completions);
1449 phba->elsbuf_cnt = 0;
1450 phba->elsbuf_prev_cnt = 0;
1451 spin_unlock_irq(&phba->hbalock);
1452
1453 while (!list_empty(&completions)) {
1454 list_remove_head(&completions, buf_ptr,
1455 struct lpfc_dmabuf, list);
1456 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1457 kfree(buf_ptr);
1458 }
1459 }
1460 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1461
James Smart858c9f62007-06-17 19:56:39 -05001462 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001463 if (phba->cfg_enable_hba_heartbeat) {
1464 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001465 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1466 (list_empty(&psli->mboxq))) {
1467 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1468 GFP_KERNEL);
1469 if (!pmboxq) {
1470 mod_timer(&phba->hb_tmofunc,
1471 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001472 msecs_to_jiffies(1000 *
1473 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001474 return;
1475 }
James Smart13815c82008-01-11 01:52:48 -05001476
James Smartbc739052010-08-04 16:11:18 -04001477 lpfc_heart_beat(phba, pmboxq);
1478 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1479 pmboxq->vport = phba->pport;
1480 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1481 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001482
James Smartbc739052010-08-04 16:11:18 -04001483 if (retval != MBX_BUSY &&
1484 retval != MBX_SUCCESS) {
1485 mempool_free(pmboxq,
1486 phba->mbox_mem_pool);
1487 mod_timer(&phba->hb_tmofunc,
1488 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001489 msecs_to_jiffies(1000 *
1490 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001491 return;
1492 }
1493 phba->skipped_hb = 0;
1494 phba->hb_outstanding = 1;
1495 } else if (time_before_eq(phba->last_completion_time,
1496 phba->skipped_hb)) {
1497 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1498 "2857 Last completion time not "
1499 " updated in %d ms\n",
1500 jiffies_to_msecs(jiffies
1501 - phba->last_completion_time));
1502 } else
1503 phba->skipped_hb = jiffies;
1504
James Smart858c9f62007-06-17 19:56:39 -05001505 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001506 jiffies +
1507 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001508 return;
James Smart13815c82008-01-11 01:52:48 -05001509 } else {
1510 /*
1511 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001512 * we need to give the hb mailbox cmd a chance to
1513 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001514 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001515 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1516 "0459 Adapter heartbeat still out"
1517 "standing:last compl time was %d ms.\n",
1518 jiffies_to_msecs(jiffies
1519 - phba->last_completion_time));
1520 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001521 jiffies +
1522 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001523 }
James Smart4258e982015-12-16 18:11:58 -05001524 } else {
1525 mod_timer(&phba->hb_tmofunc,
1526 jiffies +
1527 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001528 }
1529}
1530
James Smarte59058c2008-08-24 21:49:00 -04001531/**
James Smart3621a712009-04-06 18:47:14 -04001532 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001533 * @phba: pointer to lpfc hba data structure.
1534 *
1535 * This routine is called to bring the HBA offline when HBA hardware error
1536 * other than Port Error 6 has been detected.
1537 **/
James Smart09372822008-01-11 01:52:54 -05001538static void
1539lpfc_offline_eratt(struct lpfc_hba *phba)
1540{
1541 struct lpfc_sli *psli = &phba->sli;
1542
1543 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001544 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001545 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001546 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001547
1548 lpfc_offline(phba);
1549 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001550 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001551 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001552 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001553 lpfc_hba_down_post(phba);
1554 lpfc_sli_brdready(phba, HS_MBRDY);
1555 lpfc_unblock_mgmt_io(phba);
1556 phba->link_state = LPFC_HBA_ERROR;
1557 return;
1558}
1559
James Smarte59058c2008-08-24 21:49:00 -04001560/**
James Smartda0436e2009-05-22 14:51:39 -04001561 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1562 * @phba: pointer to lpfc hba data structure.
1563 *
1564 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1565 * other than Port Error 6 has been detected.
1566 **/
James Smarta88dbb62013-04-17 20:18:39 -04001567void
James Smartda0436e2009-05-22 14:51:39 -04001568lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1569{
James Smart946727d2015-04-07 15:07:09 -04001570 spin_lock_irq(&phba->hbalock);
1571 phba->link_state = LPFC_HBA_ERROR;
1572 spin_unlock_irq(&phba->hbalock);
1573
James Smart618a5232012-06-12 13:54:36 -04001574 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartc00f62e2019-08-14 16:57:11 -07001575 lpfc_sli_flush_io_rings(phba);
James Smartda0436e2009-05-22 14:51:39 -04001576 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001577 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001578 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001579}
1580
1581/**
James Smarta257bf92009-04-06 18:48:10 -04001582 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1583 * @phba: pointer to lpfc hba data structure.
1584 *
1585 * This routine is invoked to handle the deferred HBA hardware error
1586 * conditions. This type of error is indicated by HBA by setting ER1
1587 * and another ER bit in the host status register. The driver will
1588 * wait until the ER1 bit clears before handling the error condition.
1589 **/
1590static void
1591lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1592{
1593 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001594 struct lpfc_sli *psli = &phba->sli;
1595
James Smartf4b4c682009-05-22 14:53:12 -04001596 /* If the pci channel is offline, ignore possible errors,
1597 * since we cannot communicate with the pci card anyway.
1598 */
1599 if (pci_channel_offline(phba->pcidev)) {
1600 spin_lock_irq(&phba->hbalock);
1601 phba->hba_flag &= ~DEFER_ERATT;
1602 spin_unlock_irq(&phba->hbalock);
1603 return;
1604 }
1605
Dick Kennedy372c1872020-06-30 14:50:00 -07001606 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1607 "0479 Deferred Adapter Hardware Error "
1608 "Data: x%x x%x x%x\n",
1609 phba->work_hs, phba->work_status[0],
1610 phba->work_status[1]);
James Smarta257bf92009-04-06 18:48:10 -04001611
1612 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001613 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001614 spin_unlock_irq(&phba->hbalock);
1615
1616
1617 /*
1618 * Firmware stops when it triggred erratt. That could cause the I/Os
1619 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1620 * SCSI layer retry it after re-establishing link.
1621 */
James Smartdb55fba2014-04-04 13:52:02 -04001622 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001623
1624 /*
1625 * There was a firmware error. Take the hba offline and then
1626 * attempt to restart it.
1627 */
James Smart618a5232012-06-12 13:54:36 -04001628 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001629 lpfc_offline(phba);
1630
1631 /* Wait for the ER1 bit to clear.*/
1632 while (phba->work_hs & HS_FFER1) {
1633 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001634 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1635 phba->work_hs = UNPLUG_ERR ;
1636 break;
1637 }
James Smarta257bf92009-04-06 18:48:10 -04001638 /* If driver is unloading let the worker thread continue */
1639 if (phba->pport->load_flag & FC_UNLOADING) {
1640 phba->work_hs = 0;
1641 break;
1642 }
1643 }
1644
1645 /*
1646 * This is to ptrotect against a race condition in which
1647 * first write to the host attention register clear the
1648 * host status register.
1649 */
1650 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1651 phba->work_hs = old_host_status & ~HS_FFER1;
1652
James Smart3772a992009-05-22 14:50:54 -04001653 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001654 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001655 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001656 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1657 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1658}
1659
James Smart3772a992009-05-22 14:50:54 -04001660static void
1661lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1662{
1663 struct lpfc_board_event_header board_event;
1664 struct Scsi_Host *shost;
1665
1666 board_event.event_type = FC_REG_BOARD_EVENT;
1667 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1668 shost = lpfc_shost_from_vport(phba->pport);
1669 fc_host_post_vendor_event(shost, fc_get_event_number(),
1670 sizeof(board_event),
1671 (char *) &board_event,
1672 LPFC_NL_VENDOR_ID);
1673}
1674
James Smarta257bf92009-04-06 18:48:10 -04001675/**
James Smart3772a992009-05-22 14:50:54 -04001676 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001677 * @phba: pointer to lpfc hba data structure.
1678 *
1679 * This routine is invoked to handle the following HBA hardware error
1680 * conditions:
1681 * 1 - HBA error attention interrupt
1682 * 2 - DMA ring index out of range
1683 * 3 - Mailbox command came back as unknown
1684 **/
James Smart3772a992009-05-22 14:50:54 -04001685static void
1686lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001690 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001691 unsigned long temperature;
1692 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001693 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001694
Linas Vepstas8d63f372007-02-14 14:28:36 -06001695 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001696 * since we cannot communicate with the pci card anyway.
1697 */
1698 if (pci_channel_offline(phba->pcidev)) {
1699 spin_lock_irq(&phba->hbalock);
1700 phba->hba_flag &= ~DEFER_ERATT;
1701 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001702 return;
James Smart3772a992009-05-22 14:50:54 -04001703 }
1704
James Smart13815c82008-01-11 01:52:48 -05001705 /* If resets are disabled then leave the HBA alone and return */
1706 if (!phba->cfg_enable_hba_reset)
1707 return;
dea31012005-04-17 16:05:31 -05001708
James Smartea2151b2008-09-07 11:52:10 -04001709 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001710 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001711
James Smarta257bf92009-04-06 18:48:10 -04001712 if (phba->hba_flag & DEFER_ERATT)
1713 lpfc_handle_deferred_eratt(phba);
1714
James Smartdcf2a4e2010-09-29 11:18:53 -04001715 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1716 if (phba->work_hs & HS_FFER6)
1717 /* Re-establishing Link */
1718 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1719 "1301 Re-establishing Link "
1720 "Data: x%x x%x x%x\n",
1721 phba->work_hs, phba->work_status[0],
1722 phba->work_status[1]);
1723 if (phba->work_hs & HS_FFER8)
1724 /* Device Zeroization */
1725 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1726 "2861 Host Authentication device "
1727 "zeroization Data:x%x x%x x%x\n",
1728 phba->work_hs, phba->work_status[0],
1729 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001730
James Smart92d7f7b2007-06-17 19:56:38 -05001731 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001732 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001733 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001734
1735 /*
1736 * Firmware stops when it triggled erratt with HS_FFER6.
1737 * That could cause the I/Os dropped by the firmware.
1738 * Error iocb (I/O) on txcmplq and let the SCSI layer
1739 * retry it after re-establishing link.
1740 */
James Smartdb55fba2014-04-04 13:52:02 -04001741 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001742
dea31012005-04-17 16:05:31 -05001743 /*
1744 * There was a firmware error. Take the hba offline and then
1745 * attempt to restart it.
1746 */
James Smart618a5232012-06-12 13:54:36 -04001747 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001748 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001749 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001750 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001751 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001752 return;
1753 }
James Smart46fa3112007-04-25 09:51:45 -04001754 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001755 } else if (phba->work_hs & HS_CRIT_TEMP) {
1756 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1757 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1758 temp_event_data.event_code = LPFC_CRIT_TEMP;
1759 temp_event_data.data = (uint32_t)temperature;
1760
Dick Kennedy372c1872020-06-30 14:50:00 -07001761 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04001762 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001763 "(%ld), taking this port offline "
1764 "Data: x%x x%x x%x\n",
1765 temperature, phba->work_hs,
1766 phba->work_status[0], phba->work_status[1]);
1767
1768 shost = lpfc_shost_from_vport(phba->pport);
1769 fc_host_post_vendor_event(shost, fc_get_event_number(),
1770 sizeof(temp_event_data),
1771 (char *) &temp_event_data,
1772 SCSI_NL_VID_TYPE_PCI
1773 | PCI_VENDOR_ID_EMULEX);
1774
James Smart7af67052007-10-27 13:38:11 -04001775 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001776 phba->over_temp_state = HBA_OVER_TEMP;
1777 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001778 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001779
dea31012005-04-17 16:05:31 -05001780 } else {
1781 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001782 * failure is a value other than FFER6. Do not call the offline
1783 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001784 */
Dick Kennedy372c1872020-06-30 14:50:00 -07001785 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001786 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001787 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001788 phba->work_hs,
dea31012005-04-17 16:05:31 -05001789 phba->work_status[0], phba->work_status[1]);
1790
James Smartd2873e42006-08-18 17:46:43 -04001791 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001792 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001793 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001794 sizeof(event_data), (char *) &event_data,
1795 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1796
James Smart09372822008-01-11 01:52:54 -05001797 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001798 }
James Smart93996272008-08-24 21:50:30 -04001799 return;
dea31012005-04-17 16:05:31 -05001800}
1801
James Smarte59058c2008-08-24 21:49:00 -04001802/**
James Smart618a5232012-06-12 13:54:36 -04001803 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1804 * @phba: pointer to lpfc hba data structure.
1805 * @mbx_action: flag for mailbox shutdown action.
Lee Jonesfe614ac2020-07-23 13:24:22 +01001806 * @en_rn_msg: send reset/port recovery message.
James Smart618a5232012-06-12 13:54:36 -04001807 * This routine is invoked to perform an SLI4 port PCI function reset in
1808 * response to port status register polling attention. It waits for port
1809 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1810 * During this process, interrupt vectors are freed and later requested
1811 * for handling possible port resource change.
1812 **/
1813static int
James Smarte10b2022014-02-20 09:57:43 -05001814lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1815 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001816{
1817 int rc;
1818 uint32_t intr_mode;
1819
James Smart27d6ac02018-02-22 08:18:42 -08001820 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001821 LPFC_SLI_INTF_IF_TYPE_2) {
1822 /*
1823 * On error status condition, driver need to wait for port
1824 * ready before performing reset.
1825 */
1826 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001827 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001828 return rc;
James Smart618a5232012-06-12 13:54:36 -04001829 }
James Smart0e916ee2016-07-06 12:36:06 -07001830
James Smart65791f12016-07-06 12:35:56 -07001831 /* need reset: attempt for port recovery */
1832 if (en_rn_msg)
Dick Kennedy372c1872020-06-30 14:50:00 -07001833 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001834 "2887 Reset Needed: Attempting Port "
1835 "Recovery...\n");
1836 lpfc_offline_prep(phba, mbx_action);
James Smartc00f62e2019-08-14 16:57:11 -07001837 lpfc_sli_flush_io_rings(phba);
James Smart65791f12016-07-06 12:35:56 -07001838 lpfc_offline(phba);
1839 /* release interrupt for possible resource change */
1840 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001841 rc = lpfc_sli_brdrestart(phba);
1842 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001843 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5a9eeff2018-11-29 16:09:32 -08001844 "6309 Failed to restart board\n");
1845 return rc;
1846 }
James Smart65791f12016-07-06 12:35:56 -07001847 /* request and enable interrupt */
1848 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1849 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001850 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001851 "3175 Failed to enable interrupt\n");
1852 return -EIO;
1853 }
1854 phba->intr_mode = intr_mode;
1855 rc = lpfc_online(phba);
1856 if (rc == 0)
1857 lpfc_unblock_mgmt_io(phba);
1858
James Smart618a5232012-06-12 13:54:36 -04001859 return rc;
1860}
1861
1862/**
James Smartda0436e2009-05-22 14:51:39 -04001863 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1864 * @phba: pointer to lpfc hba data structure.
1865 *
1866 * This routine is invoked to handle the SLI4 HBA hardware error attention
1867 * conditions.
1868 **/
1869static void
1870lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1871{
1872 struct lpfc_vport *vport = phba->pport;
1873 uint32_t event_data;
1874 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001875 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001876 struct lpfc_register portstat_reg = {0};
1877 uint32_t reg_err1, reg_err2;
1878 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001879 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001880 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001881 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001882 struct lpfc_register portsmphr_reg;
1883 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001884
1885 /* If the pci channel is offline, ignore possible errors, since
1886 * we cannot communicate with the pci card anyway.
1887 */
James Smart32a93102019-03-12 16:30:13 -07001888 if (pci_channel_offline(phba->pcidev)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001889 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart32a93102019-03-12 16:30:13 -07001890 "3166 pci channel is offline\n");
1891 lpfc_sli4_offline_eratt(phba);
James Smartda0436e2009-05-22 14:51:39 -04001892 return;
James Smart32a93102019-03-12 16:30:13 -07001893 }
James Smartda0436e2009-05-22 14:51:39 -04001894
James Smart65791f12016-07-06 12:35:56 -07001895 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001896 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1897 switch (if_type) {
1898 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001899 pci_rd_rc1 = lpfc_readl(
1900 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1901 &uerrlo_reg);
1902 pci_rd_rc2 = lpfc_readl(
1903 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1904 &uemasklo_reg);
1905 /* consider PCI bus read error as pci_channel_offline */
1906 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1907 return;
James Smart65791f12016-07-06 12:35:56 -07001908 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1909 lpfc_sli4_offline_eratt(phba);
1910 return;
1911 }
Dick Kennedy372c1872020-06-30 14:50:00 -07001912 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001913 "7623 Checking UE recoverable");
1914
1915 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1916 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1917 &portsmphr_reg.word0))
1918 continue;
1919
1920 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1921 &portsmphr_reg);
1922 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1923 LPFC_PORT_SEM_UE_RECOVERABLE)
1924 break;
1925 /*Sleep for 1Sec, before checking SEMAPHORE */
1926 msleep(1000);
1927 }
1928
Dick Kennedy372c1872020-06-30 14:50:00 -07001929 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001930 "4827 smphr_port_status x%x : Waited %dSec",
1931 smphr_port_status, i);
1932
1933 /* Recoverable UE, reset the HBA device */
1934 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1935 LPFC_PORT_SEM_UE_RECOVERABLE) {
1936 for (i = 0; i < 20; i++) {
1937 msleep(1000);
1938 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1939 &portsmphr_reg.word0) &&
1940 (LPFC_POST_STAGE_PORT_READY ==
1941 bf_get(lpfc_port_smphr_port_status,
1942 &portsmphr_reg))) {
1943 rc = lpfc_sli4_port_sta_fn_reset(phba,
1944 LPFC_MBX_NO_WAIT, en_rn_msg);
1945 if (rc == 0)
1946 return;
Dick Kennedy372c1872020-06-30 14:50:00 -07001947 lpfc_printf_log(phba, KERN_ERR,
1948 LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001949 "4215 Failed to recover UE");
1950 break;
1951 }
1952 }
1953 }
Dick Kennedy372c1872020-06-30 14:50:00 -07001954 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001955 "7624 Firmware not ready: Failing UE recovery,"
1956 " waited %dSec", i);
James Smart8c24a4f2019-08-14 16:56:53 -07001957 phba->link_state = LPFC_HBA_ERROR;
James Smart2fcee4b2010-12-15 17:57:46 -05001958 break;
James Smart946727d2015-04-07 15:07:09 -04001959
James Smart2fcee4b2010-12-15 17:57:46 -05001960 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001961 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001962 pci_rd_rc1 = lpfc_readl(
1963 phba->sli4_hba.u.if_type2.STATUSregaddr,
1964 &portstat_reg.word0);
1965 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001966 if (pci_rd_rc1 == -EIO) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001967 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6b5151f2012-01-18 16:24:06 -05001968 "3151 PCI bus read access failure: x%x\n",
1969 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart32a93102019-03-12 16:30:13 -07001970 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001971 return;
James Smart6b5151f2012-01-18 16:24:06 -05001972 }
James Smart2e90f4b2011-12-13 13:22:37 -05001973 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1974 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001975 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001976 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1977 "2889 Port Overtemperature event, "
1978 "taking port offline Data: x%x x%x\n",
1979 reg_err1, reg_err2);
James Smart946727d2015-04-07 15:07:09 -04001980
James Smart310429e2016-07-06 12:35:54 -07001981 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001982 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1983 temp_event_data.event_code = LPFC_CRIT_TEMP;
1984 temp_event_data.data = 0xFFFFFFFF;
1985
1986 shost = lpfc_shost_from_vport(phba->pport);
1987 fc_host_post_vendor_event(shost, fc_get_event_number(),
1988 sizeof(temp_event_data),
1989 (char *)&temp_event_data,
1990 SCSI_NL_VID_TYPE_PCI
1991 | PCI_VENDOR_ID_EMULEX);
1992
James Smart2fcee4b2010-12-15 17:57:46 -05001993 spin_lock_irq(&phba->hbalock);
1994 phba->over_temp_state = HBA_OVER_TEMP;
1995 spin_unlock_irq(&phba->hbalock);
1996 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001997 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001998 }
James Smart2e90f4b2011-12-13 13:22:37 -05001999 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05002000 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002001 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte10b2022014-02-20 09:57:43 -05002002 "3143 Port Down: Firmware Update "
2003 "Detected\n");
2004 en_rn_msg = false;
2005 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05002006 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
Dick Kennedy372c1872020-06-30 14:50:00 -07002007 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -05002008 "3144 Port Down: Debug Dump\n");
2009 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2010 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
Dick Kennedy372c1872020-06-30 14:50:00 -07002011 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -05002012 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04002013
James Smart946727d2015-04-07 15:07:09 -04002014 /* If resets are disabled then leave the HBA alone and return */
2015 if (!phba->cfg_enable_hba_reset)
2016 return;
2017
James Smart618a5232012-06-12 13:54:36 -04002018 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05002019 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2020 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04002021 if (rc == 0) {
2022 /* don't report event on forced debug dump */
2023 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2024 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2025 return;
2026 else
2027 break;
James Smart2fcee4b2010-12-15 17:57:46 -05002028 }
James Smart618a5232012-06-12 13:54:36 -04002029 /* fall through for not able to recover */
Dick Kennedy372c1872020-06-30 14:50:00 -07002030 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart8c24a4f2019-08-14 16:56:53 -07002031 "3152 Unrecoverable error\n");
2032 phba->link_state = LPFC_HBA_ERROR;
James Smart2fcee4b2010-12-15 17:57:46 -05002033 break;
2034 case LPFC_SLI_INTF_IF_TYPE_1:
2035 default:
2036 break;
2037 }
James Smart2e90f4b2011-12-13 13:22:37 -05002038 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2039 "3123 Report dump event to upper layer\n");
2040 /* Send an internal error event to mgmt application */
2041 lpfc_board_errevt_to_mgmt(phba);
2042
2043 event_data = FC_REG_DUMP_EVENT;
2044 shost = lpfc_shost_from_vport(vport);
2045 fc_host_post_vendor_event(shost, fc_get_event_number(),
2046 sizeof(event_data), (char *) &event_data,
2047 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002048}
2049
2050/**
2051 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2052 * @phba: pointer to lpfc HBA data structure.
2053 *
2054 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2055 * routine from the API jump table function pointer from the lpfc_hba struct.
2056 *
2057 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002058 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002059 * Any other value - error.
2060 **/
2061void
2062lpfc_handle_eratt(struct lpfc_hba *phba)
2063{
2064 (*phba->lpfc_handle_eratt)(phba);
2065}
2066
2067/**
James Smart3621a712009-04-06 18:47:14 -04002068 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002069 * @phba: pointer to lpfc hba data structure.
2070 *
2071 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002072 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002073 **/
dea31012005-04-17 16:05:31 -05002074void
James Smart2e0fef82007-06-17 19:56:36 -05002075lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002076{
James Smart2e0fef82007-06-17 19:56:36 -05002077 struct lpfc_vport *vport = phba->pport;
2078 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002079 LPFC_MBOXQ_t *pmb;
2080 volatile uint32_t control;
2081 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002082 int rc = 0;
dea31012005-04-17 16:05:31 -05002083
2084 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002085 if (!pmb) {
2086 rc = 1;
dea31012005-04-17 16:05:31 -05002087 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002088 }
dea31012005-04-17 16:05:31 -05002089
2090 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002091 if (!mp) {
2092 rc = 2;
dea31012005-04-17 16:05:31 -05002093 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002094 }
dea31012005-04-17 16:05:31 -05002095
2096 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002097 if (!mp->virt) {
2098 rc = 3;
dea31012005-04-17 16:05:31 -05002099 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002100 }
dea31012005-04-17 16:05:31 -05002101
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002102 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002103 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002104
2105 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002106 lpfc_read_topology(phba, pmb, mp);
2107 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002108 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002109 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002110 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002111 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002112 if (rc == MBX_NOT_FINISHED) {
2113 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002114 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002115 }
dea31012005-04-17 16:05:31 -05002116
2117 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002118 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002119 writel(HA_LATT, phba->HAregaddr);
2120 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002121 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002122
2123 return;
2124
James Smart14691152006-12-02 13:34:28 -05002125lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002126 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002127 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002128lpfc_handle_latt_free_mp:
2129 kfree(mp);
2130lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002131 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002132lpfc_handle_latt_err_exit:
2133 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002134 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002135 psli->sli_flag |= LPFC_PROCESS_LA;
2136 control = readl(phba->HCregaddr);
2137 control |= HC_LAINT_ENA;
2138 writel(control, phba->HCregaddr);
2139 readl(phba->HCregaddr); /* flush */
2140
2141 /* Clear Link Attention in HA REG */
2142 writel(HA_LATT, phba->HAregaddr);
2143 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002144 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002145 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002146 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002147
Dick Kennedy372c1872020-06-30 14:50:00 -07002148 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2149 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002150
2151 return;
2152}
2153
James Smarte59058c2008-08-24 21:49:00 -04002154/**
James Smart3621a712009-04-06 18:47:14 -04002155 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002156 * @phba: pointer to lpfc hba data structure.
2157 * @vpd: pointer to the vital product data.
2158 * @len: length of the vital product data in bytes.
2159 *
2160 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2161 * an array of characters. In this routine, the ModelName, ProgramType, and
2162 * ModelDesc, etc. fields of the phba data structure will be populated.
2163 *
2164 * Return codes
2165 * 0 - pointer to the VPD passed in is NULL
2166 * 1 - success
2167 **/
James Smart3772a992009-05-22 14:50:54 -04002168int
James Smart2e0fef82007-06-17 19:56:36 -05002169lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002170{
2171 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002172 int Length;
dea31012005-04-17 16:05:31 -05002173 int i, j;
2174 int finished = 0;
2175 int index = 0;
2176
2177 if (!vpd)
2178 return 0;
2179
2180 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002181 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002182 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002183 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2184 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002185 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002186 switch (vpd[index]) {
2187 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002188 case 0x91:
dea31012005-04-17 16:05:31 -05002189 index += 1;
2190 lenlo = vpd[index];
2191 index += 1;
2192 lenhi = vpd[index];
2193 index += 1;
2194 i = ((((unsigned short)lenhi) << 8) + lenlo);
2195 index += i;
2196 break;
2197 case 0x90:
2198 index += 1;
2199 lenlo = vpd[index];
2200 index += 1;
2201 lenhi = vpd[index];
2202 index += 1;
2203 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002204 if (Length > len - index)
2205 Length = len - index;
dea31012005-04-17 16:05:31 -05002206 while (Length > 0) {
2207 /* Look for Serial Number */
2208 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2209 index += 2;
2210 i = vpd[index];
2211 index += 1;
2212 j = 0;
2213 Length -= (3+i);
2214 while(i--) {
2215 phba->SerialNumber[j++] = vpd[index++];
2216 if (j == 31)
2217 break;
2218 }
2219 phba->SerialNumber[j] = 0;
2220 continue;
2221 }
2222 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2223 phba->vpd_flag |= VPD_MODEL_DESC;
2224 index += 2;
2225 i = vpd[index];
2226 index += 1;
2227 j = 0;
2228 Length -= (3+i);
2229 while(i--) {
2230 phba->ModelDesc[j++] = vpd[index++];
2231 if (j == 255)
2232 break;
2233 }
2234 phba->ModelDesc[j] = 0;
2235 continue;
2236 }
2237 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2238 phba->vpd_flag |= VPD_MODEL_NAME;
2239 index += 2;
2240 i = vpd[index];
2241 index += 1;
2242 j = 0;
2243 Length -= (3+i);
2244 while(i--) {
2245 phba->ModelName[j++] = vpd[index++];
2246 if (j == 79)
2247 break;
2248 }
2249 phba->ModelName[j] = 0;
2250 continue;
2251 }
2252 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2253 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2254 index += 2;
2255 i = vpd[index];
2256 index += 1;
2257 j = 0;
2258 Length -= (3+i);
2259 while(i--) {
2260 phba->ProgramType[j++] = vpd[index++];
2261 if (j == 255)
2262 break;
2263 }
2264 phba->ProgramType[j] = 0;
2265 continue;
2266 }
2267 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2268 phba->vpd_flag |= VPD_PORT;
2269 index += 2;
2270 i = vpd[index];
2271 index += 1;
2272 j = 0;
2273 Length -= (3+i);
2274 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002275 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2276 (phba->sli4_hba.pport_name_sta ==
2277 LPFC_SLI4_PPNAME_GET)) {
2278 j++;
2279 index++;
2280 } else
2281 phba->Port[j++] = vpd[index++];
2282 if (j == 19)
2283 break;
dea31012005-04-17 16:05:31 -05002284 }
James Smartcd1c8302011-10-10 21:33:25 -04002285 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2286 (phba->sli4_hba.pport_name_sta ==
2287 LPFC_SLI4_PPNAME_NON))
2288 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002289 continue;
2290 }
2291 else {
2292 index += 2;
2293 i = vpd[index];
2294 index += 1;
2295 index += i;
2296 Length -= (3 + i);
2297 }
2298 }
2299 finished = 0;
2300 break;
2301 case 0x78:
2302 finished = 1;
2303 break;
2304 default:
2305 index ++;
2306 break;
2307 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002308 }
dea31012005-04-17 16:05:31 -05002309
2310 return(1);
2311}
2312
James Smarte59058c2008-08-24 21:49:00 -04002313/**
James Smart3621a712009-04-06 18:47:14 -04002314 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002315 * @phba: pointer to lpfc hba data structure.
2316 * @mdp: pointer to the data structure to hold the derived model name.
2317 * @descp: pointer to the data structure to hold the derived description.
2318 *
2319 * This routine retrieves HBA's description based on its registered PCI device
2320 * ID. The @descp passed into this function points to an array of 256 chars. It
2321 * shall be returned with the model name, maximum speed, and the host bus type.
2322 * The @mdp passed into this function points to an array of 80 chars. When the
2323 * function returns, the @mdp will be filled with the model name.
2324 **/
dea31012005-04-17 16:05:31 -05002325static void
James Smart2e0fef82007-06-17 19:56:36 -05002326lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002327{
2328 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002329 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002330 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002331 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002332 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002333 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002334 char *name;
2335 char *bus;
2336 char *function;
2337 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002338
2339 if (mdp && mdp[0] != '\0'
2340 && descp && descp[0] != '\0')
2341 return;
2342
James Smartfbd8a6b2018-02-22 08:18:45 -08002343 if (phba->lmt & LMT_64Gb)
2344 max_speed = 64;
2345 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002346 max_speed = 32;
2347 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002348 max_speed = 16;
2349 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002350 max_speed = 10;
2351 else if (phba->lmt & LMT_8Gb)
2352 max_speed = 8;
2353 else if (phba->lmt & LMT_4Gb)
2354 max_speed = 4;
2355 else if (phba->lmt & LMT_2Gb)
2356 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002357 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002358 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002359 else
2360 max_speed = 0;
dea31012005-04-17 16:05:31 -05002361
2362 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002363
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002364 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002365 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002366 m = (typeof(m)){"LP6000", "PCI",
2367 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002368 break;
dea31012005-04-17 16:05:31 -05002369 case PCI_DEVICE_ID_SUPERFLY:
2370 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002371 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002372 else
James Smart12222f42014-05-21 08:05:19 -04002373 m = (typeof(m)){"LP7000E", "PCI", ""};
2374 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002375 break;
2376 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002377 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002378 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002379 break;
2380 case PCI_DEVICE_ID_CENTAUR:
2381 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002382 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002383 else
James Smart12222f42014-05-21 08:05:19 -04002384 m = (typeof(m)){"LP9000", "PCI", ""};
2385 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002386 break;
2387 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002388 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002389 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002390 break;
2391 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002392 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002393 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002394 break;
2395 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002396 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002397 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002398 break;
2399 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002400 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002401 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002402 break;
2403 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002404 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002405 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002406 break;
2407 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002408 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002409 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002410 break;
2411 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002412 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002413 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002414 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002415 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002416 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002417 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002418 break;
2419 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002420 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002421 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002422 break;
2423 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002424 m = (typeof(m)){"LPe1000", "PCIe",
2425 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002426 break;
2427 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002428 m = (typeof(m)){"LPe1000-SP", "PCIe",
2429 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002430 break;
2431 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002432 m = (typeof(m)){"LPe1002-SP", "PCIe",
2433 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002434 break;
dea31012005-04-17 16:05:31 -05002435 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002436 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002437 break;
2438 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002439 m = (typeof(m)){"LP111", "PCI-X2",
2440 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002441 break;
2442 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002443 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002444 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002445 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002446 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002447 break;
2448 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002449 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002450 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002451 break;
dea31012005-04-17 16:05:31 -05002452 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002453 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002454 break;
2455 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002456 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002457 break;
2458 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002459 m = (typeof(m)){"LP101", "PCI-X",
2460 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002461 break;
2462 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002463 m = (typeof(m)){"LP10000-S", "PCI",
2464 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002465 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002466 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002467 m = (typeof(m)){"LP11000-S", "PCI-X2",
2468 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002469 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002470 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002471 m = (typeof(m)){"LPe11000-S", "PCIe",
2472 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002473 break;
James Smartb87eab32007-04-25 09:53:28 -04002474 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002475 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002476 break;
2477 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002478 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002479 break;
2480 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002481 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002482 break;
2483 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002484 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002485 break;
2486 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002487 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002488 break;
2489 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002490 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002491 break;
James Smart84774a42008-08-24 21:50:06 -04002492 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002493 m = (typeof(m)){"LP21000", "PCIe",
2494 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002495 GE = 1;
2496 break;
2497 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002498 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002499 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002500 break;
2501 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002502 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002503 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002504 break;
2505 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002506 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002507 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002508 break;
James Smartda0436e2009-05-22 14:51:39 -04002509 case PCI_DEVICE_ID_TIGERSHARK:
2510 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002511 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002512 break;
James Smarta747c9c2009-11-18 15:41:10 -05002513 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002514 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002515 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2516 break;
2517 case PCI_DEVICE_ID_FALCON:
2518 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2519 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002520 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002521 case PCI_DEVICE_ID_BALIUS:
2522 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002523 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002524 break;
James Smart085c6472010-11-20 23:11:37 -05002525 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002526 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002527 break;
James Smart12222f42014-05-21 08:05:19 -04002528 case PCI_DEVICE_ID_LANCER_FC_VF:
2529 m = (typeof(m)){"LPe16000", "PCIe",
2530 "Obsolete, Unsupported Fibre Channel Adapter"};
2531 break;
James Smart085c6472010-11-20 23:11:37 -05002532 case PCI_DEVICE_ID_LANCER_FCOE:
2533 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002534 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002535 break;
James Smart12222f42014-05-21 08:05:19 -04002536 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2537 oneConnect = 1;
2538 m = (typeof(m)){"OCe15100", "PCIe",
2539 "Obsolete, Unsupported FCoE"};
2540 break;
James Smartd38dd522015-08-31 16:48:17 -04002541 case PCI_DEVICE_ID_LANCER_G6_FC:
2542 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2543 break;
James Smartc238b9b2018-02-22 08:18:44 -08002544 case PCI_DEVICE_ID_LANCER_G7_FC:
2545 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2546 break;
James Smartf8cafd32012-08-03 12:42:51 -04002547 case PCI_DEVICE_ID_SKYHAWK:
2548 case PCI_DEVICE_ID_SKYHAWK_VF:
2549 oneConnect = 1;
2550 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2551 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002552 default:
James Smarta747c9c2009-11-18 15:41:10 -05002553 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002554 break;
dea31012005-04-17 16:05:31 -05002555 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002556
2557 if (mdp && mdp[0] == '\0')
2558 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002559 /*
2560 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002561 * and we put the port number on the end
2562 */
2563 if (descp && descp[0] == '\0') {
2564 if (oneConnect)
2565 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002566 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002567 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002568 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002569 else if (max_speed == 0)
2570 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002571 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002572 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002573 else
2574 snprintf(descp, 255,
2575 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002576 m.name, max_speed, (GE) ? "GE" : "Gb",
2577 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002578 }
dea31012005-04-17 16:05:31 -05002579}
2580
James Smarte59058c2008-08-24 21:49:00 -04002581/**
James Smart3621a712009-04-06 18:47:14 -04002582 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002583 * @phba: pointer to lpfc hba data structure.
2584 * @pring: pointer to a IOCB ring.
2585 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2586 *
2587 * This routine posts a given number of IOCBs with the associated DMA buffer
2588 * descriptors specified by the cnt argument to the given IOCB ring.
2589 *
2590 * Return codes
2591 * The number of IOCBs NOT able to be posted to the IOCB ring.
2592 **/
dea31012005-04-17 16:05:31 -05002593int
James Smart495a7142008-06-14 22:52:59 -04002594lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002595{
2596 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002597 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002598 struct lpfc_dmabuf *mp1, *mp2;
2599
2600 cnt += pring->missbufcnt;
2601
2602 /* While there are buffers to post */
2603 while (cnt > 0) {
2604 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002605 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002606 if (iocb == NULL) {
2607 pring->missbufcnt = cnt;
2608 return cnt;
2609 }
dea31012005-04-17 16:05:31 -05002610 icmd = &iocb->iocb;
2611
2612 /* 2 buffers can be posted per command */
2613 /* Allocate buffer to post */
2614 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2615 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002616 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2617 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002618 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002619 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002620 pring->missbufcnt = cnt;
2621 return cnt;
2622 }
2623
2624 INIT_LIST_HEAD(&mp1->list);
2625 /* Allocate buffer to post */
2626 if (cnt > 1) {
2627 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2628 if (mp2)
2629 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2630 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002631 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002632 kfree(mp2);
dea31012005-04-17 16:05:31 -05002633 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2634 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002635 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002636 pring->missbufcnt = cnt;
2637 return cnt;
2638 }
2639
2640 INIT_LIST_HEAD(&mp2->list);
2641 } else {
2642 mp2 = NULL;
2643 }
2644
2645 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2646 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2647 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2648 icmd->ulpBdeCount = 1;
2649 cnt--;
2650 if (mp2) {
2651 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2652 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2653 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2654 cnt--;
2655 icmd->ulpBdeCount = 2;
2656 }
2657
2658 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2659 icmd->ulpLe = 1;
2660
James Smart3772a992009-05-22 14:50:54 -04002661 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2662 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002663 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2664 kfree(mp1);
2665 cnt++;
2666 if (mp2) {
2667 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2668 kfree(mp2);
2669 cnt++;
2670 }
James Bottomley604a3e32005-10-29 10:28:33 -05002671 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002672 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002673 return cnt;
2674 }
dea31012005-04-17 16:05:31 -05002675 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002676 if (mp2)
dea31012005-04-17 16:05:31 -05002677 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002678 }
2679 pring->missbufcnt = 0;
2680 return 0;
2681}
2682
James Smarte59058c2008-08-24 21:49:00 -04002683/**
James Smart3621a712009-04-06 18:47:14 -04002684 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002685 * @phba: pointer to lpfc hba data structure.
2686 *
2687 * This routine posts initial receive IOCB buffers to the ELS ring. The
2688 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002689 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002690 *
2691 * Return codes
2692 * 0 - success (currently always success)
2693 **/
dea31012005-04-17 16:05:31 -05002694static int
James Smart2e0fef82007-06-17 19:56:36 -05002695lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002696{
2697 struct lpfc_sli *psli = &phba->sli;
2698
2699 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002700 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002701 /* Ring 2 - FCP no buffers needed */
2702
2703 return 0;
2704}
2705
2706#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2707
James Smarte59058c2008-08-24 21:49:00 -04002708/**
James Smart3621a712009-04-06 18:47:14 -04002709 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002710 * @HashResultPointer: pointer to an array as hash table.
2711 *
2712 * This routine sets up the initial values to the array of hash table entries
2713 * for the LC HBAs.
2714 **/
dea31012005-04-17 16:05:31 -05002715static void
2716lpfc_sha_init(uint32_t * HashResultPointer)
2717{
2718 HashResultPointer[0] = 0x67452301;
2719 HashResultPointer[1] = 0xEFCDAB89;
2720 HashResultPointer[2] = 0x98BADCFE;
2721 HashResultPointer[3] = 0x10325476;
2722 HashResultPointer[4] = 0xC3D2E1F0;
2723}
2724
James Smarte59058c2008-08-24 21:49:00 -04002725/**
James Smart3621a712009-04-06 18:47:14 -04002726 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002727 * @HashResultPointer: pointer to an initial/result hash table.
2728 * @HashWorkingPointer: pointer to an working hash table.
2729 *
2730 * This routine iterates an initial hash table pointed by @HashResultPointer
2731 * with the values from the working hash table pointeed by @HashWorkingPointer.
2732 * The results are putting back to the initial hash table, returned through
2733 * the @HashResultPointer as the result hash table.
2734 **/
dea31012005-04-17 16:05:31 -05002735static void
2736lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2737{
2738 int t;
2739 uint32_t TEMP;
2740 uint32_t A, B, C, D, E;
2741 t = 16;
2742 do {
2743 HashWorkingPointer[t] =
2744 S(1,
2745 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2746 8] ^
2747 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2748 } while (++t <= 79);
2749 t = 0;
2750 A = HashResultPointer[0];
2751 B = HashResultPointer[1];
2752 C = HashResultPointer[2];
2753 D = HashResultPointer[3];
2754 E = HashResultPointer[4];
2755
2756 do {
2757 if (t < 20) {
2758 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2759 } else if (t < 40) {
2760 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2761 } else if (t < 60) {
2762 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2763 } else {
2764 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2765 }
2766 TEMP += S(5, A) + E + HashWorkingPointer[t];
2767 E = D;
2768 D = C;
2769 C = S(30, B);
2770 B = A;
2771 A = TEMP;
2772 } while (++t <= 79);
2773
2774 HashResultPointer[0] += A;
2775 HashResultPointer[1] += B;
2776 HashResultPointer[2] += C;
2777 HashResultPointer[3] += D;
2778 HashResultPointer[4] += E;
2779
2780}
2781
James Smarte59058c2008-08-24 21:49:00 -04002782/**
James Smart3621a712009-04-06 18:47:14 -04002783 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002784 * @RandomChallenge: pointer to the entry of host challenge random number array.
2785 * @HashWorking: pointer to the entry of the working hash array.
2786 *
2787 * This routine calculates the working hash array referred by @HashWorking
2788 * from the challenge random numbers associated with the host, referred by
2789 * @RandomChallenge. The result is put into the entry of the working hash
2790 * array and returned by reference through @HashWorking.
2791 **/
dea31012005-04-17 16:05:31 -05002792static void
2793lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2794{
2795 *HashWorking = (*RandomChallenge ^ *HashWorking);
2796}
2797
James Smarte59058c2008-08-24 21:49:00 -04002798/**
James Smart3621a712009-04-06 18:47:14 -04002799 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002800 * @phba: pointer to lpfc hba data structure.
2801 * @hbainit: pointer to an array of unsigned 32-bit integers.
2802 *
2803 * This routine performs the special handling for LC HBA initialization.
2804 **/
dea31012005-04-17 16:05:31 -05002805void
2806lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2807{
2808 int t;
2809 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002810 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002811
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002812 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002813 if (!HashWorking)
2814 return;
2815
dea31012005-04-17 16:05:31 -05002816 HashWorking[0] = HashWorking[78] = *pwwnn++;
2817 HashWorking[1] = HashWorking[79] = *pwwnn;
2818
2819 for (t = 0; t < 7; t++)
2820 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2821
2822 lpfc_sha_init(hbainit);
2823 lpfc_sha_iterate(hbainit, HashWorking);
2824 kfree(HashWorking);
2825}
2826
James Smarte59058c2008-08-24 21:49:00 -04002827/**
James Smart3621a712009-04-06 18:47:14 -04002828 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002829 * @vport: pointer to a virtual N_Port data structure.
2830 *
2831 * This routine performs the necessary cleanups before deleting the @vport.
2832 * It invokes the discovery state machine to perform necessary state
2833 * transitions and to release the ndlps associated with the @vport. Note,
2834 * the physical port is treated as @vport 0.
2835 **/
James Smart87af33f2007-10-27 13:37:43 -04002836void
James Smart2e0fef82007-06-17 19:56:36 -05002837lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002838{
James Smart87af33f2007-10-27 13:37:43 -04002839 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002840 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002841 int i = 0;
dea31012005-04-17 16:05:31 -05002842
James Smart87af33f2007-10-27 13:37:43 -04002843 if (phba->link_state > LPFC_LINK_DOWN)
2844 lpfc_port_link_failure(vport);
2845
2846 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart58da1ff2008-04-07 10:15:56 -04002847 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2848 ndlp->nlp_DID == Fabric_DID) {
2849 /* Just free up ndlp with Fabric_DID for vports */
2850 lpfc_nlp_put(ndlp);
2851 continue;
2852 }
2853
James Smarta70e63e2020-11-15 11:26:38 -08002854 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
2855 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
James Smarteff4a012012-01-18 16:25:25 -05002856 lpfc_nlp_put(ndlp);
2857 continue;
2858 }
2859
James Smarte9b11082020-11-15 11:26:33 -08002860 /* Fabric Ports not in UNMAPPED state are cleaned up in the
2861 * DEVICE_RM event.
2862 */
2863 if (ndlp->nlp_type & NLP_FABRIC &&
2864 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
James Smart87af33f2007-10-27 13:37:43 -04002865 lpfc_disc_state_machine(vport, ndlp, NULL,
2866 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002867
James Smarte9b11082020-11-15 11:26:33 -08002868 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
2869 lpfc_disc_state_machine(vport, ndlp, NULL,
2870 NLP_EVT_DEVICE_RM);
James Smart87af33f2007-10-27 13:37:43 -04002871 }
2872
James Smarta8adb832007-10-27 13:37:53 -04002873 /* At this point, ALL ndlp's should be gone
2874 * because of the previous NLP_EVT_DEVICE_RM.
2875 * Lets wait for this to happen, if needed.
2876 */
James Smart87af33f2007-10-27 13:37:43 -04002877 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002878 if (i++ > 3000) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002879 lpfc_printf_vlog(vport, KERN_ERR,
2880 LOG_TRACE_EVENT,
James Smarta8adb832007-10-27 13:37:53 -04002881 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002882 list_for_each_entry_safe(ndlp, next_ndlp,
2883 &vport->fc_nodes, nlp_listp) {
2884 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
James Smarte9b11082020-11-15 11:26:33 -08002885 LOG_TRACE_EVENT,
2886 "0282 did:x%x ndlp:x%px "
2887 "refcnt:%d xflags x%x nflag x%x\n",
2888 ndlp->nlp_DID, (void *)ndlp,
2889 kref_read(&ndlp->kref),
2890 ndlp->fc4_xpt_flags,
2891 ndlp->nlp_flag);
James Smarte47c9092008-02-08 18:49:26 -05002892 }
James Smarta8adb832007-10-27 13:37:53 -04002893 break;
James Smart87af33f2007-10-27 13:37:43 -04002894 }
James Smarta8adb832007-10-27 13:37:53 -04002895
2896 /* Wait for any activity on ndlps to settle */
2897 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002898 }
James Smart1151e3e2011-02-16 12:39:35 -05002899 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002900}
2901
James Smarte59058c2008-08-24 21:49:00 -04002902/**
James Smart3621a712009-04-06 18:47:14 -04002903 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002904 * @vport: pointer to a virtual N_Port data structure.
2905 *
2906 * This routine stops all the timers associated with a @vport. This function
2907 * is invoked before disabling or deleting a @vport. Note that the physical
2908 * port is treated as @vport 0.
2909 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002910void
2911lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002912{
James Smart92d7f7b2007-06-17 19:56:38 -05002913 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002914 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002915 lpfc_can_disctmo(vport);
2916 return;
dea31012005-04-17 16:05:31 -05002917}
2918
James Smarte59058c2008-08-24 21:49:00 -04002919/**
James Smartecfd03c2010-02-12 14:41:27 -05002920 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2921 * @phba: pointer to lpfc hba data structure.
2922 *
2923 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2924 * caller of this routine should already hold the host lock.
2925 **/
2926void
2927__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2928{
James Smart5ac6b302010-10-22 11:05:36 -04002929 /* Clear pending FCF rediscovery wait flag */
2930 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2931
James Smartecfd03c2010-02-12 14:41:27 -05002932 /* Now, try to stop the timer */
2933 del_timer(&phba->fcf.redisc_wait);
2934}
2935
2936/**
2937 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2938 * @phba: pointer to lpfc hba data structure.
2939 *
2940 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2941 * checks whether the FCF rediscovery wait timer is pending with the host
2942 * lock held before proceeding with disabling the timer and clearing the
2943 * wait timer pendig flag.
2944 **/
2945void
2946lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2947{
2948 spin_lock_irq(&phba->hbalock);
2949 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2950 /* FCF rediscovery timer already fired or stopped */
2951 spin_unlock_irq(&phba->hbalock);
2952 return;
2953 }
2954 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002955 /* Clear failover in progress flags */
2956 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002957 spin_unlock_irq(&phba->hbalock);
2958}
2959
2960/**
James Smart3772a992009-05-22 14:50:54 -04002961 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002962 * @phba: pointer to lpfc hba data structure.
2963 *
2964 * This routine stops all the timers associated with a HBA. This function is
2965 * invoked before either putting a HBA offline or unloading the driver.
2966 **/
James Smart3772a992009-05-22 14:50:54 -04002967void
2968lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002969{
James Smartcdb42be2019-01-28 11:14:21 -08002970 if (phba->pport)
2971 lpfc_stop_vport_timers(phba->pport);
James Smart32517fc2019-01-28 11:14:33 -08002972 cancel_delayed_work_sync(&phba->eq_delay_work);
Dick Kennedy317aeb82020-06-30 14:49:59 -07002973 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
James Smart2e0fef82007-06-17 19:56:36 -05002974 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002975 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002976 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002977 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002978 if (phba->sli_rev == LPFC_SLI_REV4) {
2979 del_timer_sync(&phba->rrq_tmr);
2980 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2981 }
James Smart3772a992009-05-22 14:50:54 -04002982 phba->hb_outstanding = 0;
2983
2984 switch (phba->pci_dev_grp) {
2985 case LPFC_PCI_DEV_LP:
2986 /* Stop any LightPulse device specific driver timers */
2987 del_timer_sync(&phba->fcp_poll_timer);
2988 break;
2989 case LPFC_PCI_DEV_OC:
Paul Walmsleycc0e5f12019-07-11 20:52:33 -07002990 /* Stop any OneConnect device specific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002991 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002992 break;
2993 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07002994 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -04002995 "0297 Invalid device group (x%x)\n",
2996 phba->pci_dev_grp);
2997 break;
2998 }
James Smart2e0fef82007-06-17 19:56:36 -05002999 return;
dea31012005-04-17 16:05:31 -05003000}
3001
James Smarte59058c2008-08-24 21:49:00 -04003002/**
James Smart3621a712009-04-06 18:47:14 -04003003 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04003004 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01003005 * @mbx_action: flag for mailbox no wait action.
James Smarte59058c2008-08-24 21:49:00 -04003006 *
3007 * This routine marks a HBA's management interface as blocked. Once the HBA's
3008 * management interface is marked as blocked, all the user space access to
3009 * the HBA, whether they are from sysfs interface or libdfc interface will
3010 * all be blocked. The HBA is set to block the management interface when the
3011 * driver prepares the HBA interface for online or offline.
3012 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01003013static void
James Smart618a5232012-06-12 13:54:36 -04003014lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01003015{
3016 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04003017 uint8_t actcmd = MBX_HEARTBEAT;
3018 unsigned long timeout;
3019
Adrian Bunka6ababd2007-11-05 18:07:33 +01003020 spin_lock_irqsave(&phba->hbalock, iflag);
3021 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04003022 spin_unlock_irqrestore(&phba->hbalock, iflag);
3023 if (mbx_action == LPFC_MBX_NO_WAIT)
3024 return;
3025 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3026 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003027 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04003028 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04003029 /* Determine how long we might wait for the active mailbox
3030 * command to be gracefully completed by firmware.
3031 */
3032 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3033 phba->sli.mbox_active) * 1000) + jiffies;
3034 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003035 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003036
James Smart6e7288d2010-06-07 15:23:35 -04003037 /* Wait for the outstnading mailbox command to complete */
3038 while (phba->sli.mbox_active) {
3039 /* Check active mailbox complete status every 2ms */
3040 msleep(2);
3041 if (time_after(jiffies, timeout)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003042 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3043 "2813 Mgmt IO is Blocked %x "
3044 "- mbox cmd %x still active\n",
3045 phba->sli.sli_flag, actcmd);
James Smart6e7288d2010-06-07 15:23:35 -04003046 break;
3047 }
3048 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003049}
3050
James Smarte59058c2008-08-24 21:49:00 -04003051/**
James Smart6b5151f2012-01-18 16:24:06 -05003052 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3053 * @phba: pointer to lpfc hba data structure.
3054 *
3055 * Allocate RPIs for all active remote nodes. This is needed whenever
3056 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3057 * is to fixup the temporary rpi assignments.
3058 **/
3059void
3060lpfc_sli4_node_prep(struct lpfc_hba *phba)
3061{
3062 struct lpfc_nodelist *ndlp, *next_ndlp;
3063 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003064 int i, rpi;
James Smart6b5151f2012-01-18 16:24:06 -05003065
3066 if (phba->sli_rev != LPFC_SLI_REV4)
3067 return;
3068
3069 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003070 if (vports == NULL)
3071 return;
James Smart6b5151f2012-01-18 16:24:06 -05003072
James Smart9d3d3402017-04-21 16:05:00 -07003073 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3074 if (vports[i]->load_flag & FC_UNLOADING)
3075 continue;
3076
3077 list_for_each_entry_safe(ndlp, next_ndlp,
3078 &vports[i]->fc_nodes,
3079 nlp_listp) {
James Smart9d3d3402017-04-21 16:05:00 -07003080 rpi = lpfc_sli4_alloc_rpi(phba);
3081 if (rpi == LPFC_RPI_ALLOC_ERROR) {
James Smart307e3382020-11-15 11:26:30 -08003082 /* TODO print log? */
James Smart9d3d3402017-04-21 16:05:00 -07003083 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003084 }
James Smart9d3d3402017-04-21 16:05:00 -07003085 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07003086 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3087 LOG_NODE | LOG_DISCOVERY,
3088 "0009 Assign RPI x%x to ndlp x%px "
James Smart307e3382020-11-15 11:26:30 -08003089 "DID:x%06x flg:x%x\n",
James Smart0f154222019-09-21 20:58:52 -07003090 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
James Smart307e3382020-11-15 11:26:30 -08003091 ndlp->nlp_flag);
James Smart6b5151f2012-01-18 16:24:06 -05003092 }
3093 }
3094 lpfc_destroy_vport_work_array(phba, vports);
3095}
3096
3097/**
James Smartc4908502019-01-28 11:14:28 -08003098 * lpfc_create_expedite_pool - create expedite pool
3099 * @phba: pointer to lpfc hba data structure.
3100 *
3101 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3102 * to expedite pool. Mark them as expedite.
3103 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003104static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003105{
3106 struct lpfc_sli4_hdw_queue *qp;
3107 struct lpfc_io_buf *lpfc_ncmd;
3108 struct lpfc_io_buf *lpfc_ncmd_next;
3109 struct lpfc_epd_pool *epd_pool;
3110 unsigned long iflag;
3111
3112 epd_pool = &phba->epd_pool;
3113 qp = &phba->sli4_hba.hdwq[0];
3114
3115 spin_lock_init(&epd_pool->lock);
3116 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3117 spin_lock(&epd_pool->lock);
3118 INIT_LIST_HEAD(&epd_pool->list);
3119 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3120 &qp->lpfc_io_buf_list_put, list) {
3121 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3122 lpfc_ncmd->expedite = true;
3123 qp->put_io_bufs--;
3124 epd_pool->count++;
3125 if (epd_pool->count >= XRI_BATCH)
3126 break;
3127 }
3128 spin_unlock(&epd_pool->lock);
3129 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3130}
3131
3132/**
3133 * lpfc_destroy_expedite_pool - destroy expedite pool
3134 * @phba: pointer to lpfc hba data structure.
3135 *
3136 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3137 * of HWQ 0. Clear the mark.
3138 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003139static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003140{
3141 struct lpfc_sli4_hdw_queue *qp;
3142 struct lpfc_io_buf *lpfc_ncmd;
3143 struct lpfc_io_buf *lpfc_ncmd_next;
3144 struct lpfc_epd_pool *epd_pool;
3145 unsigned long iflag;
3146
3147 epd_pool = &phba->epd_pool;
3148 qp = &phba->sli4_hba.hdwq[0];
3149
3150 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3151 spin_lock(&epd_pool->lock);
3152 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3153 &epd_pool->list, list) {
3154 list_move_tail(&lpfc_ncmd->list,
3155 &qp->lpfc_io_buf_list_put);
3156 lpfc_ncmd->flags = false;
3157 qp->put_io_bufs++;
3158 epd_pool->count--;
3159 }
3160 spin_unlock(&epd_pool->lock);
3161 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3162}
3163
3164/**
3165 * lpfc_create_multixri_pools - create multi-XRI pools
3166 * @phba: pointer to lpfc hba data structure.
3167 *
3168 * This routine initialize public, private per HWQ. Then, move XRIs from
3169 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3170 * Initialized.
3171 **/
3172void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3173{
3174 u32 i, j;
3175 u32 hwq_count;
3176 u32 count_per_hwq;
3177 struct lpfc_io_buf *lpfc_ncmd;
3178 struct lpfc_io_buf *lpfc_ncmd_next;
3179 unsigned long iflag;
3180 struct lpfc_sli4_hdw_queue *qp;
3181 struct lpfc_multixri_pool *multixri_pool;
3182 struct lpfc_pbl_pool *pbl_pool;
3183 struct lpfc_pvt_pool *pvt_pool;
3184
3185 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3186 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3187 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3188 phba->sli4_hba.io_xri_cnt);
3189
3190 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3191 lpfc_create_expedite_pool(phba);
3192
3193 hwq_count = phba->cfg_hdw_queue;
3194 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3195
3196 for (i = 0; i < hwq_count; i++) {
3197 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3198
3199 if (!multixri_pool) {
3200 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3201 "1238 Failed to allocate memory for "
3202 "multixri_pool\n");
3203
3204 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3205 lpfc_destroy_expedite_pool(phba);
3206
3207 j = 0;
3208 while (j < i) {
3209 qp = &phba->sli4_hba.hdwq[j];
3210 kfree(qp->p_multixri_pool);
3211 j++;
3212 }
3213 phba->cfg_xri_rebalancing = 0;
3214 return;
3215 }
3216
3217 qp = &phba->sli4_hba.hdwq[i];
3218 qp->p_multixri_pool = multixri_pool;
3219
3220 multixri_pool->xri_limit = count_per_hwq;
3221 multixri_pool->rrb_next_hwqid = i;
3222
3223 /* Deal with public free xri pool */
3224 pbl_pool = &multixri_pool->pbl_pool;
3225 spin_lock_init(&pbl_pool->lock);
3226 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3227 spin_lock(&pbl_pool->lock);
3228 INIT_LIST_HEAD(&pbl_pool->list);
3229 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3230 &qp->lpfc_io_buf_list_put, list) {
3231 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3232 qp->put_io_bufs--;
3233 pbl_pool->count++;
3234 }
3235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3236 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3237 pbl_pool->count, i);
3238 spin_unlock(&pbl_pool->lock);
3239 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3240
3241 /* Deal with private free xri pool */
3242 pvt_pool = &multixri_pool->pvt_pool;
3243 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3244 pvt_pool->low_watermark = XRI_BATCH;
3245 spin_lock_init(&pvt_pool->lock);
3246 spin_lock_irqsave(&pvt_pool->lock, iflag);
3247 INIT_LIST_HEAD(&pvt_pool->list);
3248 pvt_pool->count = 0;
3249 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3250 }
3251}
3252
3253/**
3254 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3255 * @phba: pointer to lpfc hba data structure.
3256 *
3257 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3258 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003259static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003260{
3261 u32 i;
3262 u32 hwq_count;
3263 struct lpfc_io_buf *lpfc_ncmd;
3264 struct lpfc_io_buf *lpfc_ncmd_next;
3265 unsigned long iflag;
3266 struct lpfc_sli4_hdw_queue *qp;
3267 struct lpfc_multixri_pool *multixri_pool;
3268 struct lpfc_pbl_pool *pbl_pool;
3269 struct lpfc_pvt_pool *pvt_pool;
3270
3271 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3272 lpfc_destroy_expedite_pool(phba);
3273
James Smartc00f62e2019-08-14 16:57:11 -07003274 if (!(phba->pport->load_flag & FC_UNLOADING))
3275 lpfc_sli_flush_io_rings(phba);
James Smartc66a9192019-03-12 16:30:19 -07003276
James Smartc4908502019-01-28 11:14:28 -08003277 hwq_count = phba->cfg_hdw_queue;
3278
3279 for (i = 0; i < hwq_count; i++) {
3280 qp = &phba->sli4_hba.hdwq[i];
3281 multixri_pool = qp->p_multixri_pool;
3282 if (!multixri_pool)
3283 continue;
3284
3285 qp->p_multixri_pool = NULL;
3286
3287 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3288
3289 /* Deal with public free xri pool */
3290 pbl_pool = &multixri_pool->pbl_pool;
3291 spin_lock(&pbl_pool->lock);
3292
3293 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3294 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3295 pbl_pool->count, i);
3296
3297 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3298 &pbl_pool->list, list) {
3299 list_move_tail(&lpfc_ncmd->list,
3300 &qp->lpfc_io_buf_list_put);
3301 qp->put_io_bufs++;
3302 pbl_pool->count--;
3303 }
3304
3305 INIT_LIST_HEAD(&pbl_pool->list);
3306 pbl_pool->count = 0;
3307
3308 spin_unlock(&pbl_pool->lock);
3309
3310 /* Deal with private free xri pool */
3311 pvt_pool = &multixri_pool->pvt_pool;
3312 spin_lock(&pvt_pool->lock);
3313
3314 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3315 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3316 pvt_pool->count, i);
3317
3318 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3319 &pvt_pool->list, list) {
3320 list_move_tail(&lpfc_ncmd->list,
3321 &qp->lpfc_io_buf_list_put);
3322 qp->put_io_bufs++;
3323 pvt_pool->count--;
3324 }
3325
3326 INIT_LIST_HEAD(&pvt_pool->list);
3327 pvt_pool->count = 0;
3328
3329 spin_unlock(&pvt_pool->lock);
3330 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3331
3332 kfree(multixri_pool);
3333 }
3334}
3335
3336/**
James Smart3621a712009-04-06 18:47:14 -04003337 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003338 * @phba: pointer to lpfc hba data structure.
3339 *
3340 * This routine initializes the HBA and brings a HBA online. During this
3341 * process, the management interface is blocked to prevent user space access
3342 * to the HBA interfering with the driver initialization.
3343 *
3344 * Return codes
3345 * 0 - successful
3346 * 1 - failed
3347 **/
dea31012005-04-17 16:05:31 -05003348int
James Smart2e0fef82007-06-17 19:56:36 -05003349lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003350{
Julia Lawall372bd282008-12-16 16:15:08 +01003351 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003352 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003353 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003354 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003355
dea31012005-04-17 16:05:31 -05003356 if (!phba)
3357 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003358 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003359
James Smart2e0fef82007-06-17 19:56:36 -05003360 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003361 return 0;
3362
James Smarted957682007-06-17 19:56:37 -05003363 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003364 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003365
James Smart618a5232012-06-12 13:54:36 -04003366 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003367
James Smartda0436e2009-05-22 14:51:39 -04003368 if (phba->sli_rev == LPFC_SLI_REV4) {
3369 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3370 lpfc_unblock_mgmt_io(phba);
3371 return 1;
3372 }
James Smart16a3a202013-04-17 20:14:38 -04003373 spin_lock_irq(&phba->hbalock);
3374 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3375 vpis_cleared = true;
3376 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003377
3378 /* Reestablish the local initiator port.
3379 * The offline process destroyed the previous lport.
3380 */
3381 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3382 !phba->nvmet_support) {
3383 error = lpfc_nvme_create_localport(phba->pport);
3384 if (error)
Dick Kennedy372c1872020-06-30 14:50:00 -07003385 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedya145fda2017-08-23 16:55:44 -07003386 "6132 NVME restore reg failed "
3387 "on nvmei error x%x\n", error);
3388 }
James Smartda0436e2009-05-22 14:51:39 -04003389 } else {
James Smart895427b2017-02-12 13:52:30 -08003390 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003391 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3392 lpfc_unblock_mgmt_io(phba);
3393 return 1;
3394 }
James Smart46fa3112007-04-25 09:51:45 -04003395 }
dea31012005-04-17 16:05:31 -05003396
James Smart549e55c2007-08-02 11:09:51 -04003397 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003398 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003399 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003400 struct Scsi_Host *shost;
3401 shost = lpfc_shost_from_vport(vports[i]);
3402 spin_lock_irq(shost->host_lock);
3403 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3404 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3405 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003406 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003407 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003408 if ((vpis_cleared) &&
3409 (vports[i]->port_type !=
3410 LPFC_PHYSICAL_PORT))
3411 vports[i]->vpi = 0;
3412 }
James Smart549e55c2007-08-02 11:09:51 -04003413 spin_unlock_irq(shost->host_lock);
3414 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003415 }
3416 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003417
James Smartc4908502019-01-28 11:14:28 -08003418 if (phba->cfg_xri_rebalancing)
3419 lpfc_create_multixri_pools(phba);
3420
James Smart93a4d6f2019-11-04 16:57:05 -08003421 lpfc_cpuhp_add(phba);
3422
James Smart46fa3112007-04-25 09:51:45 -04003423 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003424 return 0;
3425}
3426
James Smarte59058c2008-08-24 21:49:00 -04003427/**
James Smart3621a712009-04-06 18:47:14 -04003428 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003429 * @phba: pointer to lpfc hba data structure.
3430 *
3431 * This routine marks a HBA's management interface as not blocked. Once the
3432 * HBA's management interface is marked as not blocked, all the user space
3433 * access to the HBA, whether they are from sysfs interface or libdfc
3434 * interface will be allowed. The HBA is set to block the management interface
3435 * when the driver prepares the HBA interface for online or offline and then
3436 * set to unblock the management interface afterwards.
3437 **/
James Smart46fa3112007-04-25 09:51:45 -04003438void
James Smart46fa3112007-04-25 09:51:45 -04003439lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3440{
3441 unsigned long iflag;
3442
James Smart2e0fef82007-06-17 19:56:36 -05003443 spin_lock_irqsave(&phba->hbalock, iflag);
3444 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3445 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003446}
3447
James Smarte59058c2008-08-24 21:49:00 -04003448/**
James Smart3621a712009-04-06 18:47:14 -04003449 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003450 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01003451 * @mbx_action: flag for mailbox shutdown action.
James Smarte59058c2008-08-24 21:49:00 -04003452 *
3453 * This routine is invoked to prepare a HBA to be brought offline. It performs
3454 * unregistration login to all the nodes on all vports and flushes the mailbox
3455 * queue to make it ready to be brought offline.
3456 **/
James Smart46fa3112007-04-25 09:51:45 -04003457void
James Smart618a5232012-06-12 13:54:36 -04003458lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003459{
James Smart2e0fef82007-06-17 19:56:36 -05003460 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003461 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003462 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003463 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003464 int i;
dea31012005-04-17 16:05:31 -05003465
James Smart2e0fef82007-06-17 19:56:36 -05003466 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003467 return;
dea31012005-04-17 16:05:31 -05003468
James Smart618a5232012-06-12 13:54:36 -04003469 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003470
3471 lpfc_linkdown(phba);
3472
James Smart87af33f2007-10-27 13:37:43 -04003473 /* Issue an unreg_login to all nodes on all vports */
3474 vports = lpfc_create_vport_work_array(phba);
3475 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003476 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003477 if (vports[i]->load_flag & FC_UNLOADING)
3478 continue;
James Smart72100cc2010-02-12 14:43:01 -05003479 shost = lpfc_shost_from_vport(vports[i]);
3480 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003481 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003482 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3483 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003484 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003485
James Smart87af33f2007-10-27 13:37:43 -04003486 shost = lpfc_shost_from_vport(vports[i]);
3487 list_for_each_entry_safe(ndlp, next_ndlp,
3488 &vports[i]->fc_nodes,
3489 nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08003490 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
James Smart0f154222019-09-21 20:58:52 -07003491 /* Driver must assume RPI is invalid for
3492 * any unused or inactive node.
3493 */
3494 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05003495 continue;
James Smart0f154222019-09-21 20:58:52 -07003496 }
3497
James Smartc6adba12020-11-15 11:26:34 -08003498 spin_lock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04003499 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -08003500 spin_unlock_irq(&ndlp->lock);
James Smart6b5151f2012-01-18 16:24:06 -05003501 /*
3502 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003503 * RPI. Get a new RPI when the adapter port
3504 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003505 */
James Smartbe6bb942015-04-07 15:07:22 -04003506 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smarte9b11082020-11-15 11:26:33 -08003507 lpfc_printf_vlog(vports[i], KERN_INFO,
James Smart0f154222019-09-21 20:58:52 -07003508 LOG_NODE | LOG_DISCOVERY,
3509 "0011 Free RPI x%x on "
James Smarte9b11082020-11-15 11:26:33 -08003510 "ndlp: %p did x%x\n",
James Smart0f154222019-09-21 20:58:52 -07003511 ndlp->nlp_rpi, ndlp,
James Smart307e3382020-11-15 11:26:30 -08003512 ndlp->nlp_DID);
James Smart6b5151f2012-01-18 16:24:06 -05003513 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart0f154222019-09-21 20:58:52 -07003514 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smartbe6bb942015-04-07 15:07:22 -04003515 }
James Smart87af33f2007-10-27 13:37:43 -04003516 lpfc_unreg_rpi(vports[i], ndlp);
James Smart307e3382020-11-15 11:26:30 -08003517
3518 if (ndlp->nlp_type & NLP_FABRIC) {
3519 lpfc_disc_state_machine(vports[i], ndlp,
3520 NULL, NLP_EVT_DEVICE_RECOVERY);
James Smarte9b11082020-11-15 11:26:33 -08003521
3522 /* Don't remove the node unless the
3523 * has been unregistered with the
3524 * transport. If so, let dev_loss
3525 * take care of the node.
3526 */
3527 if (!(ndlp->fc4_xpt_flags &
3528 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3529 lpfc_disc_state_machine
3530 (vports[i], ndlp,
3531 NULL,
3532 NLP_EVT_DEVICE_RM);
James Smart307e3382020-11-15 11:26:30 -08003533 }
James Smart87af33f2007-10-27 13:37:43 -04003534 }
3535 }
3536 }
James Smart09372822008-01-11 01:52:54 -05003537 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003538
James Smart618a5232012-06-12 13:54:36 -04003539 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003540
3541 if (phba->wq)
3542 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003543}
3544
James Smarte59058c2008-08-24 21:49:00 -04003545/**
James Smart3621a712009-04-06 18:47:14 -04003546 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003547 * @phba: pointer to lpfc hba data structure.
3548 *
3549 * This routine actually brings a HBA offline. It stops all the timers
3550 * associated with the HBA, brings down the SLI layer, and eventually
3551 * marks the HBA as in offline state for the upper layer protocol.
3552 **/
James Smart46fa3112007-04-25 09:51:45 -04003553void
James Smart2e0fef82007-06-17 19:56:36 -05003554lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003555{
James Smart549e55c2007-08-02 11:09:51 -04003556 struct Scsi_Host *shost;
3557 struct lpfc_vport **vports;
3558 int i;
James Smart46fa3112007-04-25 09:51:45 -04003559
James Smart549e55c2007-08-02 11:09:51 -04003560 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003561 return;
James Smart688a8862006-07-06 15:49:56 -04003562
James Smartda0436e2009-05-22 14:51:39 -04003563 /* stop port and all timers associated with this hba */
3564 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003565
3566 /* Tear down the local and target port registrations. The
3567 * nvme transports need to cleanup.
3568 */
3569 lpfc_nvmet_destroy_targetport(phba);
3570 lpfc_nvme_destroy_localport(phba->pport);
3571
James Smart51ef4c22007-08-02 11:10:31 -04003572 vports = lpfc_create_vport_work_array(phba);
3573 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003574 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003575 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003576 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003577 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003578 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003579 /* Bring down the SLI Layer and cleanup. The HBA is offline
3580 now. */
3581 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003582 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003583 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003584 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003585 vports = lpfc_create_vport_work_array(phba);
3586 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003587 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003588 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003589 spin_lock_irq(shost->host_lock);
3590 vports[i]->work_port_events = 0;
3591 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3592 spin_unlock_irq(shost->host_lock);
3593 }
James Smart09372822008-01-11 01:52:54 -05003594 lpfc_destroy_vport_work_array(phba, vports);
James Smart93a4d6f2019-11-04 16:57:05 -08003595 __lpfc_cpuhp_remove(phba);
James Smartc4908502019-01-28 11:14:28 -08003596
3597 if (phba->cfg_xri_rebalancing)
3598 lpfc_destroy_multixri_pools(phba);
dea31012005-04-17 16:05:31 -05003599}
3600
James Smarte59058c2008-08-24 21:49:00 -04003601/**
James Smart3621a712009-04-06 18:47:14 -04003602 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003603 * @phba: pointer to lpfc hba data structure.
3604 *
3605 * This routine is to free all the SCSI buffers and IOCBs from the driver
3606 * list back to kernel. It is called from lpfc_pci_remove_one to free
3607 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003608 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003609static void
James Smart2e0fef82007-06-17 19:56:36 -05003610lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003611{
James Smartc4908502019-01-28 11:14:28 -08003612 struct lpfc_io_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003613
James Smart895427b2017-02-12 13:52:30 -08003614 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3615 return;
3616
James Smart2e0fef82007-06-17 19:56:36 -05003617 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003618
dea31012005-04-17 16:05:31 -05003619 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003620
3621 spin_lock(&phba->scsi_buf_list_put_lock);
3622 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3623 list) {
dea31012005-04-17 16:05:31 -05003624 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003625 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003626 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003627 kfree(sb);
3628 phba->total_scsi_bufs--;
3629 }
James Smarta40fc5f2013-04-17 20:17:40 -04003630 spin_unlock(&phba->scsi_buf_list_put_lock);
3631
3632 spin_lock(&phba->scsi_buf_list_get_lock);
3633 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3634 list) {
3635 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003636 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003637 sb->dma_handle);
3638 kfree(sb);
3639 phba->total_scsi_bufs--;
3640 }
3641 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003642 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003643}
James Smart0794d602019-01-28 11:14:19 -08003644
James Smart8a9d2e82012-05-09 21:16:12 -04003645/**
James Smart5e5b5112019-01-28 11:14:22 -08003646 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
James Smart895427b2017-02-12 13:52:30 -08003647 * @phba: pointer to lpfc hba data structure.
3648 *
James Smart0794d602019-01-28 11:14:19 -08003649 * This routine is to free all the IO buffers and IOCBs from the driver
James Smart895427b2017-02-12 13:52:30 -08003650 * list back to kernel. It is called from lpfc_pci_remove_one to free
3651 * the internal resources before the device is removed from the system.
3652 **/
James Smartc4908502019-01-28 11:14:28 -08003653void
James Smart5e5b5112019-01-28 11:14:22 -08003654lpfc_io_free(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08003655{
James Smartc4908502019-01-28 11:14:28 -08003656 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart5e5b5112019-01-28 11:14:22 -08003657 struct lpfc_sli4_hdw_queue *qp;
3658 int idx;
James Smart895427b2017-02-12 13:52:30 -08003659
James Smart5e5b5112019-01-28 11:14:22 -08003660 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3661 qp = &phba->sli4_hba.hdwq[idx];
3662 /* Release all the lpfc_nvme_bufs maintained by this host. */
3663 spin_lock(&qp->io_buf_list_put_lock);
3664 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3665 &qp->lpfc_io_buf_list_put,
3666 list) {
3667 list_del(&lpfc_ncmd->list);
3668 qp->put_io_bufs--;
3669 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3670 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
James Smartd79c9e92019-08-14 16:57:09 -07003671 if (phba->cfg_xpsgl && !phba->nvmet_support)
3672 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3673 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
James Smart5e5b5112019-01-28 11:14:22 -08003674 kfree(lpfc_ncmd);
3675 qp->total_io_bufs--;
3676 }
3677 spin_unlock(&qp->io_buf_list_put_lock);
James Smart895427b2017-02-12 13:52:30 -08003678
James Smart5e5b5112019-01-28 11:14:22 -08003679 spin_lock(&qp->io_buf_list_get_lock);
3680 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3681 &qp->lpfc_io_buf_list_get,
3682 list) {
3683 list_del(&lpfc_ncmd->list);
3684 qp->get_io_bufs--;
3685 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3686 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
James Smartd79c9e92019-08-14 16:57:09 -07003687 if (phba->cfg_xpsgl && !phba->nvmet_support)
3688 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3689 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
James Smart5e5b5112019-01-28 11:14:22 -08003690 kfree(lpfc_ncmd);
3691 qp->total_io_bufs--;
3692 }
3693 spin_unlock(&qp->io_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003694 }
James Smart895427b2017-02-12 13:52:30 -08003695}
James Smart0794d602019-01-28 11:14:19 -08003696
James Smart895427b2017-02-12 13:52:30 -08003697/**
3698 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003699 * @phba: pointer to lpfc hba data structure.
3700 *
3701 * This routine first calculates the sizes of the current els and allocated
3702 * scsi sgl lists, and then goes through all sgls to updates the physical
3703 * XRIs assigned due to port function reset. During port initialization, the
3704 * current els and allocated scsi sgl lists are 0s.
3705 *
3706 * Return codes
3707 * 0 - successful (for now, it always returns 0)
3708 **/
3709int
James Smart895427b2017-02-12 13:52:30 -08003710lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003711{
3712 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003713 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003714 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003715 int rc;
3716
3717 /*
3718 * update on pci function's els xri-sgl list
3719 */
3720 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003721
James Smart8a9d2e82012-05-09 21:16:12 -04003722 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3723 /* els xri-sgl expanded */
3724 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3725 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3726 "3157 ELS xri-sgl count increased from "
3727 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3728 els_xri_cnt);
3729 /* allocate the additional els sgls */
3730 for (i = 0; i < xri_cnt; i++) {
3731 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3732 GFP_KERNEL);
3733 if (sglq_entry == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003734 lpfc_printf_log(phba, KERN_ERR,
3735 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003736 "2562 Failure to allocate an "
3737 "ELS sgl entry:%d\n", i);
3738 rc = -ENOMEM;
3739 goto out_free_mem;
3740 }
3741 sglq_entry->buff_type = GEN_BUFF_TYPE;
3742 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3743 &sglq_entry->phys);
3744 if (sglq_entry->virt == NULL) {
3745 kfree(sglq_entry);
Dick Kennedy372c1872020-06-30 14:50:00 -07003746 lpfc_printf_log(phba, KERN_ERR,
3747 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003748 "2563 Failure to allocate an "
3749 "ELS mbuf:%d\n", i);
3750 rc = -ENOMEM;
3751 goto out_free_mem;
3752 }
3753 sglq_entry->sgl = sglq_entry->virt;
3754 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3755 sglq_entry->state = SGL_FREED;
3756 list_add_tail(&sglq_entry->list, &els_sgl_list);
3757 }
James Smart38c20672013-03-01 16:37:44 -05003758 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003759 spin_lock(&phba->sli4_hba.sgl_list_lock);
3760 list_splice_init(&els_sgl_list,
3761 &phba->sli4_hba.lpfc_els_sgl_list);
3762 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003763 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003764 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3765 /* els xri-sgl shrinked */
3766 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3767 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3768 "3158 ELS xri-sgl count decreased from "
3769 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3770 els_xri_cnt);
3771 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003772 spin_lock(&phba->sli4_hba.sgl_list_lock);
3773 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3774 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003775 /* release extra els sgls from list */
3776 for (i = 0; i < xri_cnt; i++) {
3777 list_remove_head(&els_sgl_list,
3778 sglq_entry, struct lpfc_sglq, list);
3779 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003780 __lpfc_mbuf_free(phba, sglq_entry->virt,
3781 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003782 kfree(sglq_entry);
3783 }
3784 }
James Smart895427b2017-02-12 13:52:30 -08003785 list_splice_init(&els_sgl_list,
3786 &phba->sli4_hba.lpfc_els_sgl_list);
3787 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003788 spin_unlock_irq(&phba->hbalock);
3789 } else
3790 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3791 "3163 ELS xri-sgl count unchanged: %d\n",
3792 els_xri_cnt);
3793 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3794
3795 /* update xris to els sgls on the list */
3796 sglq_entry = NULL;
3797 sglq_entry_next = NULL;
3798 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003799 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003800 lxri = lpfc_sli4_next_xritag(phba);
3801 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003802 lpfc_printf_log(phba, KERN_ERR,
3803 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003804 "2400 Failed to allocate xri for "
3805 "ELS sgl\n");
3806 rc = -ENOMEM;
3807 goto out_free_mem;
3808 }
3809 sglq_entry->sli4_lxritag = lxri;
3810 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3811 }
James Smart895427b2017-02-12 13:52:30 -08003812 return 0;
3813
3814out_free_mem:
3815 lpfc_free_els_sgl_list(phba);
3816 return rc;
3817}
3818
3819/**
James Smartf358dd02017-02-12 13:52:34 -08003820 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3821 * @phba: pointer to lpfc hba data structure.
3822 *
3823 * This routine first calculates the sizes of the current els and allocated
3824 * scsi sgl lists, and then goes through all sgls to updates the physical
3825 * XRIs assigned due to port function reset. During port initialization, the
3826 * current els and allocated scsi sgl lists are 0s.
3827 *
3828 * Return codes
3829 * 0 - successful (for now, it always returns 0)
3830 **/
3831int
3832lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3833{
3834 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3835 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003836 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003837 LIST_HEAD(nvmet_sgl_list);
3838 int rc;
3839
3840 /*
3841 * update on pci function's nvmet xri-sgl list
3842 */
3843 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003844
James Smart6c621a22017-05-15 15:20:45 -07003845 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3846 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003847 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3848 /* els xri-sgl expanded */
3849 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3850 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3851 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3852 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3853 /* allocate the additional nvmet sgls */
3854 for (i = 0; i < xri_cnt; i++) {
3855 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3856 GFP_KERNEL);
3857 if (sglq_entry == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003858 lpfc_printf_log(phba, KERN_ERR,
3859 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08003860 "6303 Failure to allocate an "
3861 "NVMET sgl entry:%d\n", i);
3862 rc = -ENOMEM;
3863 goto out_free_mem;
3864 }
3865 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3866 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3867 &sglq_entry->phys);
3868 if (sglq_entry->virt == NULL) {
3869 kfree(sglq_entry);
Dick Kennedy372c1872020-06-30 14:50:00 -07003870 lpfc_printf_log(phba, KERN_ERR,
3871 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08003872 "6304 Failure to allocate an "
3873 "NVMET buf:%d\n", i);
3874 rc = -ENOMEM;
3875 goto out_free_mem;
3876 }
3877 sglq_entry->sgl = sglq_entry->virt;
3878 memset(sglq_entry->sgl, 0,
3879 phba->cfg_sg_dma_buf_size);
3880 sglq_entry->state = SGL_FREED;
3881 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3882 }
3883 spin_lock_irq(&phba->hbalock);
3884 spin_lock(&phba->sli4_hba.sgl_list_lock);
3885 list_splice_init(&nvmet_sgl_list,
3886 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3887 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3888 spin_unlock_irq(&phba->hbalock);
3889 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3890 /* nvmet xri-sgl shrunk */
3891 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3892 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3893 "6305 NVMET xri-sgl count decreased from "
3894 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3895 nvmet_xri_cnt);
3896 spin_lock_irq(&phba->hbalock);
3897 spin_lock(&phba->sli4_hba.sgl_list_lock);
3898 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3899 &nvmet_sgl_list);
3900 /* release extra nvmet sgls from list */
3901 for (i = 0; i < xri_cnt; i++) {
3902 list_remove_head(&nvmet_sgl_list,
3903 sglq_entry, struct lpfc_sglq, list);
3904 if (sglq_entry) {
3905 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3906 sglq_entry->phys);
3907 kfree(sglq_entry);
3908 }
3909 }
3910 list_splice_init(&nvmet_sgl_list,
3911 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3912 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3913 spin_unlock_irq(&phba->hbalock);
3914 } else
3915 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3916 "6306 NVMET xri-sgl count unchanged: %d\n",
3917 nvmet_xri_cnt);
3918 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3919
3920 /* update xris to nvmet sgls on the list */
3921 sglq_entry = NULL;
3922 sglq_entry_next = NULL;
3923 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3924 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3925 lxri = lpfc_sli4_next_xritag(phba);
3926 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003927 lpfc_printf_log(phba, KERN_ERR,
3928 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08003929 "6307 Failed to allocate xri for "
3930 "NVMET sgl\n");
3931 rc = -ENOMEM;
3932 goto out_free_mem;
3933 }
3934 sglq_entry->sli4_lxritag = lxri;
3935 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3936 }
3937 return 0;
3938
3939out_free_mem:
3940 lpfc_free_nvmet_sgl_list(phba);
3941 return rc;
3942}
3943
James Smart5e5b5112019-01-28 11:14:22 -08003944int
3945lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
3946{
3947 LIST_HEAD(blist);
3948 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08003949 struct lpfc_io_buf *lpfc_cmd;
3950 struct lpfc_io_buf *iobufp, *prev_iobufp;
James Smart5e5b5112019-01-28 11:14:22 -08003951 int idx, cnt, xri, inserted;
3952
3953 cnt = 0;
3954 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3955 qp = &phba->sli4_hba.hdwq[idx];
3956 spin_lock_irq(&qp->io_buf_list_get_lock);
3957 spin_lock(&qp->io_buf_list_put_lock);
3958
3959 /* Take everything off the get and put lists */
3960 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
3961 list_splice(&qp->lpfc_io_buf_list_put, &blist);
3962 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
3963 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
3964 cnt += qp->get_io_bufs + qp->put_io_bufs;
3965 qp->get_io_bufs = 0;
3966 qp->put_io_bufs = 0;
3967 qp->total_io_bufs = 0;
3968 spin_unlock(&qp->io_buf_list_put_lock);
3969 spin_unlock_irq(&qp->io_buf_list_get_lock);
3970 }
3971
3972 /*
3973 * Take IO buffers off blist and put on cbuf sorted by XRI.
3974 * This is because POST_SGL takes a sequential range of XRIs
3975 * to post to the firmware.
3976 */
3977 for (idx = 0; idx < cnt; idx++) {
James Smartc4908502019-01-28 11:14:28 -08003978 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08003979 if (!lpfc_cmd)
3980 return cnt;
3981 if (idx == 0) {
3982 list_add_tail(&lpfc_cmd->list, cbuf);
3983 continue;
3984 }
3985 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
3986 inserted = 0;
3987 prev_iobufp = NULL;
3988 list_for_each_entry(iobufp, cbuf, list) {
3989 if (xri < iobufp->cur_iocbq.sli4_xritag) {
3990 if (prev_iobufp)
3991 list_add(&lpfc_cmd->list,
3992 &prev_iobufp->list);
3993 else
3994 list_add(&lpfc_cmd->list, cbuf);
3995 inserted = 1;
3996 break;
3997 }
3998 prev_iobufp = iobufp;
3999 }
4000 if (!inserted)
4001 list_add_tail(&lpfc_cmd->list, cbuf);
4002 }
4003 return cnt;
4004}
4005
4006int
4007lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4008{
4009 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08004010 struct lpfc_io_buf *lpfc_cmd;
James Smart5e5b5112019-01-28 11:14:22 -08004011 int idx, cnt;
4012
4013 qp = phba->sli4_hba.hdwq;
4014 cnt = 0;
4015 while (!list_empty(cbuf)) {
4016 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4017 list_remove_head(cbuf, lpfc_cmd,
James Smartc4908502019-01-28 11:14:28 -08004018 struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08004019 if (!lpfc_cmd)
4020 return cnt;
4021 cnt++;
4022 qp = &phba->sli4_hba.hdwq[idx];
James Smart1fbf9742019-01-28 11:14:26 -08004023 lpfc_cmd->hdwq_no = idx;
4024 lpfc_cmd->hdwq = qp;
James Smart5e5b5112019-01-28 11:14:22 -08004025 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
4026 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
4027 spin_lock(&qp->io_buf_list_put_lock);
4028 list_add_tail(&lpfc_cmd->list,
4029 &qp->lpfc_io_buf_list_put);
4030 qp->put_io_bufs++;
4031 qp->total_io_bufs++;
4032 spin_unlock(&qp->io_buf_list_put_lock);
4033 }
4034 }
4035 return cnt;
4036}
4037
James Smartf358dd02017-02-12 13:52:34 -08004038/**
James Smart5e5b5112019-01-28 11:14:22 -08004039 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
James Smart895427b2017-02-12 13:52:30 -08004040 * @phba: pointer to lpfc hba data structure.
4041 *
4042 * This routine first calculates the sizes of the current els and allocated
4043 * scsi sgl lists, and then goes through all sgls to updates the physical
4044 * XRIs assigned due to port function reset. During port initialization, the
4045 * current els and allocated scsi sgl lists are 0s.
4046 *
4047 * Return codes
4048 * 0 - successful (for now, it always returns 0)
4049 **/
4050int
James Smart5e5b5112019-01-28 11:14:22 -08004051lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08004052{
James Smartc4908502019-01-28 11:14:28 -08004053 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
James Smart0794d602019-01-28 11:14:19 -08004054 uint16_t i, lxri, els_xri_cnt;
James Smart5e5b5112019-01-28 11:14:22 -08004055 uint16_t io_xri_cnt, io_xri_max;
4056 LIST_HEAD(io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004057 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08004058
4059 /*
James Smart0794d602019-01-28 11:14:19 -08004060 * update on pci function's allocated nvme xri-sgl list
James Smart895427b2017-02-12 13:52:30 -08004061 */
James Smart0794d602019-01-28 11:14:19 -08004062
4063 /* maximum number of xris available for nvme buffers */
James Smart895427b2017-02-12 13:52:30 -08004064 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart5e5b5112019-01-28 11:14:22 -08004065 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4066 phba->sli4_hba.io_xri_max = io_xri_max;
James Smart8a9d2e82012-05-09 21:16:12 -04004067
James Smarte8c0a772017-04-21 16:04:49 -07004068 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004069 "6074 Current allocated XRI sgl count:%d, "
4070 "maximum XRI count:%d\n",
James Smart5e5b5112019-01-28 11:14:22 -08004071 phba->sli4_hba.io_xri_cnt,
4072 phba->sli4_hba.io_xri_max);
James Smarte8c0a772017-04-21 16:04:49 -07004073
James Smart5e5b5112019-01-28 11:14:22 -08004074 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004075
James Smart5e5b5112019-01-28 11:14:22 -08004076 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
James Smart0794d602019-01-28 11:14:19 -08004077 /* max nvme xri shrunk below the allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004078 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4079 phba->sli4_hba.io_xri_max;
James Smart0794d602019-01-28 11:14:19 -08004080 /* release the extra allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004081 for (i = 0; i < io_xri_cnt; i++) {
4082 list_remove_head(&io_sgl_list, lpfc_ncmd,
James Smartc4908502019-01-28 11:14:28 -08004083 struct lpfc_io_buf, list);
James Smart0794d602019-01-28 11:14:19 -08004084 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02004085 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart0794d602019-01-28 11:14:19 -08004086 lpfc_ncmd->data,
4087 lpfc_ncmd->dma_handle);
4088 kfree(lpfc_ncmd);
James Smarta2fc4aef2014-09-03 12:57:55 -04004089 }
James Smart8a9d2e82012-05-09 21:16:12 -04004090 }
James Smart5e5b5112019-01-28 11:14:22 -08004091 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04004092 }
4093
James Smart0794d602019-01-28 11:14:19 -08004094 /* update xris associated to remaining allocated nvme buffers */
4095 lpfc_ncmd = NULL;
4096 lpfc_ncmd_next = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08004097 phba->sli4_hba.io_xri_cnt = cnt;
James Smart0794d602019-01-28 11:14:19 -08004098 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
James Smart5e5b5112019-01-28 11:14:22 -08004099 &io_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04004100 lxri = lpfc_sli4_next_xritag(phba);
4101 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004102 lpfc_printf_log(phba, KERN_ERR,
4103 LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -08004104 "6075 Failed to allocate xri for "
4105 "nvme buffer\n");
James Smart8a9d2e82012-05-09 21:16:12 -04004106 rc = -ENOMEM;
4107 goto out_free_mem;
4108 }
James Smart0794d602019-01-28 11:14:19 -08004109 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4110 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
James Smart8a9d2e82012-05-09 21:16:12 -04004111 }
James Smart5e5b5112019-01-28 11:14:22 -08004112 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
dea31012005-04-17 16:05:31 -05004113 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04004114
4115out_free_mem:
James Smart5e5b5112019-01-28 11:14:22 -08004116 lpfc_io_free(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04004117 return rc;
dea31012005-04-17 16:05:31 -05004118}
4119
James Smart0794d602019-01-28 11:14:19 -08004120/**
James Smart5e5b5112019-01-28 11:14:22 -08004121 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
Lee Jonesfe614ac2020-07-23 13:24:22 +01004122 * @phba: Pointer to lpfc hba data structure.
4123 * @num_to_alloc: The requested number of buffers to allocate.
James Smart0794d602019-01-28 11:14:19 -08004124 *
4125 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4126 * the nvme buffer contains all the necessary information needed to initiate
4127 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4128 * them on a list, it post them to the port by using SGL block post.
4129 *
4130 * Return codes:
James Smart5e5b5112019-01-28 11:14:22 -08004131 * int - number of IO buffers that were allocated and posted.
James Smart0794d602019-01-28 11:14:19 -08004132 * 0 = failure, less than num_to_alloc is a partial failure.
4133 **/
4134int
James Smart5e5b5112019-01-28 11:14:22 -08004135lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
James Smart0794d602019-01-28 11:14:19 -08004136{
James Smartc4908502019-01-28 11:14:28 -08004137 struct lpfc_io_buf *lpfc_ncmd;
James Smart0794d602019-01-28 11:14:19 -08004138 struct lpfc_iocbq *pwqeq;
4139 uint16_t iotag, lxri = 0;
4140 int bcnt, num_posted;
4141 LIST_HEAD(prep_nblist);
4142 LIST_HEAD(post_nblist);
4143 LIST_HEAD(nvme_nblist);
4144
James Smart5e5b5112019-01-28 11:14:22 -08004145 phba->sli4_hba.io_xri_cnt = 0;
James Smart0794d602019-01-28 11:14:19 -08004146 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
James Smart7f9989b2019-08-27 14:27:46 -07004147 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
James Smart0794d602019-01-28 11:14:19 -08004148 if (!lpfc_ncmd)
4149 break;
4150 /*
4151 * Get memory from the pci pool to map the virt space to
4152 * pci bus space for an I/O. The DMA buffer includes the
4153 * number of SGE's necessary to support the sg_tablesize.
4154 */
Thomas Meyera5c990e2019-05-29 22:21:36 +02004155 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4156 GFP_KERNEL,
4157 &lpfc_ncmd->dma_handle);
James Smart0794d602019-01-28 11:14:19 -08004158 if (!lpfc_ncmd->data) {
4159 kfree(lpfc_ncmd);
4160 break;
4161 }
James Smart0794d602019-01-28 11:14:19 -08004162
James Smartd79c9e92019-08-14 16:57:09 -07004163 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4164 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4165 } else {
4166 /*
4167 * 4K Page alignment is CRITICAL to BlockGuard, double
4168 * check to be sure.
4169 */
4170 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4171 (((unsigned long)(lpfc_ncmd->data) &
4172 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004173 lpfc_printf_log(phba, KERN_ERR,
4174 LOG_TRACE_EVENT,
James Smartd79c9e92019-08-14 16:57:09 -07004175 "3369 Memory alignment err: "
4176 "addr=%lx\n",
4177 (unsigned long)lpfc_ncmd->data);
4178 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4179 lpfc_ncmd->data,
4180 lpfc_ncmd->dma_handle);
4181 kfree(lpfc_ncmd);
4182 break;
4183 }
James Smart0794d602019-01-28 11:14:19 -08004184 }
4185
James Smartd79c9e92019-08-14 16:57:09 -07004186 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4187
James Smart0794d602019-01-28 11:14:19 -08004188 lxri = lpfc_sli4_next_xritag(phba);
4189 if (lxri == NO_XRI) {
4190 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4191 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4192 kfree(lpfc_ncmd);
4193 break;
4194 }
4195 pwqeq = &lpfc_ncmd->cur_iocbq;
4196
4197 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4198 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4199 if (iotag == 0) {
4200 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4201 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4202 kfree(lpfc_ncmd);
Dick Kennedy372c1872020-06-30 14:50:00 -07004203 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -08004204 "6121 Failed to allocate IOTAG for"
4205 " XRI:0x%x\n", lxri);
4206 lpfc_sli4_free_xri(phba, lxri);
4207 break;
4208 }
4209 pwqeq->sli4_lxritag = lxri;
4210 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4211 pwqeq->context1 = lpfc_ncmd;
4212
4213 /* Initialize local short-hand pointers. */
4214 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4215 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4216 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
James Smartc2017262019-01-28 11:14:37 -08004217 spin_lock_init(&lpfc_ncmd->buf_lock);
James Smart0794d602019-01-28 11:14:19 -08004218
4219 /* add the nvme buffer to a post list */
4220 list_add_tail(&lpfc_ncmd->list, &post_nblist);
James Smart5e5b5112019-01-28 11:14:22 -08004221 phba->sli4_hba.io_xri_cnt++;
James Smart0794d602019-01-28 11:14:19 -08004222 }
4223 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4224 "6114 Allocate %d out of %d requested new NVME "
4225 "buffers\n", bcnt, num_to_alloc);
4226
4227 /* post the list of nvme buffer sgls to port if available */
4228 if (!list_empty(&post_nblist))
James Smart5e5b5112019-01-28 11:14:22 -08004229 num_posted = lpfc_sli4_post_io_sgl_list(
James Smart0794d602019-01-28 11:14:19 -08004230 phba, &post_nblist, bcnt);
4231 else
4232 num_posted = 0;
4233
4234 return num_posted;
4235}
4236
James Smart96418b52017-03-04 09:30:31 -08004237static uint64_t
4238lpfc_get_wwpn(struct lpfc_hba *phba)
4239{
4240 uint64_t wwn;
4241 int rc;
4242 LPFC_MBOXQ_t *mboxq;
4243 MAILBOX_t *mb;
4244
James Smart96418b52017-03-04 09:30:31 -08004245 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4246 GFP_KERNEL);
4247 if (!mboxq)
4248 return (uint64_t)-1;
4249
4250 /* First get WWN of HBA instance */
4251 lpfc_read_nv(phba, mboxq);
4252 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4253 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004254 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart96418b52017-03-04 09:30:31 -08004255 "6019 Mailbox failed , mbxCmd x%x "
4256 "READ_NV, mbxStatus x%x\n",
4257 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4258 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4259 mempool_free(mboxq, phba->mbox_mem_pool);
4260 return (uint64_t) -1;
4261 }
4262 mb = &mboxq->u.mb;
4263 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4264 /* wwn is WWPN of HBA instance */
4265 mempool_free(mboxq, phba->mbox_mem_pool);
4266 if (phba->sli_rev == LPFC_SLI_REV4)
4267 return be64_to_cpu(wwn);
4268 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07004269 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08004270}
4271
James Smarte59058c2008-08-24 21:49:00 -04004272/**
James Smart3621a712009-04-06 18:47:14 -04004273 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04004274 * @phba: pointer to lpfc hba data structure.
4275 * @instance: a unique integer ID to this FC port.
4276 * @dev: pointer to the device data structure.
4277 *
4278 * This routine creates a FC port for the upper layer protocol. The FC port
4279 * can be created on top of either a physical port or a virtual port provided
4280 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4281 * and associates the FC port created before adding the shost into the SCSI
4282 * layer.
4283 *
4284 * Return codes
4285 * @vport - pointer to the virtual N_Port data structure.
4286 * NULL - port create failed.
4287 **/
James Smart2e0fef82007-06-17 19:56:36 -05004288struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04004289lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04004290{
James Smart2e0fef82007-06-17 19:56:36 -05004291 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08004292 struct Scsi_Host *shost = NULL;
James Smartc90b4482020-03-22 11:12:56 -07004293 struct scsi_host_template *template;
James Smart2e0fef82007-06-17 19:56:36 -05004294 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08004295 int i;
4296 uint64_t wwn;
4297 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07004298 int rc;
James Smart96418b52017-03-04 09:30:31 -08004299
James Smart56bc8022017-06-15 22:56:43 -07004300 if (lpfc_no_hba_reset_cnt) {
4301 if (phba->sli_rev < LPFC_SLI_REV4 &&
4302 dev == &phba->pcidev->dev) {
4303 /* Reset the port first */
4304 lpfc_sli_brdrestart(phba);
4305 rc = lpfc_sli_chipset_init(phba);
4306 if (rc)
4307 return NULL;
4308 }
4309 wwn = lpfc_get_wwpn(phba);
4310 }
James Smart96418b52017-03-04 09:30:31 -08004311
4312 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4313 if (wwn == lpfc_no_hba_reset[i]) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004314 lpfc_printf_log(phba, KERN_ERR,
4315 LOG_TRACE_EVENT,
James Smart96418b52017-03-04 09:30:31 -08004316 "6020 Setting use_no_reset port=%llx\n",
4317 wwn);
4318 use_no_reset_hba = true;
4319 break;
4320 }
4321 }
James Smart47a86172007-04-25 09:53:22 -04004322
James Smartc90b4482020-03-22 11:12:56 -07004323 /* Seed template for SCSI host registration */
4324 if (dev == &phba->pcidev->dev) {
4325 template = &phba->port_template;
4326
4327 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4328 /* Seed physical port template */
4329 memcpy(template, &lpfc_template, sizeof(*template));
4330
James Smart7c30bb62020-10-20 13:27:16 -07004331 if (use_no_reset_hba)
James Smartc90b4482020-03-22 11:12:56 -07004332 /* template is for a no reset SCSI Host */
James Smartc90b4482020-03-22 11:12:56 -07004333 template->eh_host_reset_handler = NULL;
James Smartc90b4482020-03-22 11:12:56 -07004334
4335 /* Template for all vports this physical port creates */
4336 memcpy(&phba->vport_template, &lpfc_template,
4337 sizeof(*template));
James Smartc90b4482020-03-22 11:12:56 -07004338 phba->vport_template.shost_attrs = lpfc_vport_attrs;
4339 phba->vport_template.eh_bus_reset_handler = NULL;
4340 phba->vport_template.eh_host_reset_handler = NULL;
4341 phba->vport_template.vendor_id = 0;
4342
4343 /* Initialize the host templates with updated value */
4344 if (phba->sli_rev == LPFC_SLI_REV4) {
4345 template->sg_tablesize = phba->cfg_scsi_seg_cnt;
4346 phba->vport_template.sg_tablesize =
4347 phba->cfg_scsi_seg_cnt;
4348 } else {
4349 template->sg_tablesize = phba->cfg_sg_seg_cnt;
4350 phba->vport_template.sg_tablesize =
4351 phba->cfg_sg_seg_cnt;
4352 }
4353
James Smart895427b2017-02-12 13:52:30 -08004354 } else {
James Smartc90b4482020-03-22 11:12:56 -07004355 /* NVMET is for physical port only */
4356 memcpy(template, &lpfc_template_nvme,
4357 sizeof(*template));
James Smart895427b2017-02-12 13:52:30 -08004358 }
James Smartc90b4482020-03-22 11:12:56 -07004359 } else {
4360 template = &phba->vport_template;
James Smartea4142f2015-04-07 15:07:13 -04004361 }
James Smartc90b4482020-03-22 11:12:56 -07004362
4363 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05004364 if (!shost)
4365 goto out;
James Smart47a86172007-04-25 09:53:22 -04004366
James Smart2e0fef82007-06-17 19:56:36 -05004367 vport = (struct lpfc_vport *) shost->hostdata;
4368 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05004369 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05004370 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05004371 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04004372 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08004373
James Smartf6e84792019-01-28 11:14:38 -08004374 /* Adjust value in vport */
4375 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4376
James Smart2e0fef82007-06-17 19:56:36 -05004377 shost->unique_id = instance;
4378 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04004379 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05004380 shost->this_id = -1;
4381 shost->max_cmd_len = 16;
James Smart6a828b02019-01-28 11:14:31 -08004382
James Smartda0436e2009-05-22 14:51:39 -04004383 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart77ffd342019-08-15 19:36:49 -07004384 if (!phba->cfg_fcp_mq_threshold ||
4385 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4386 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4387
4388 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4389 phba->cfg_fcp_mq_threshold);
James Smart6a828b02019-01-28 11:14:31 -08004390
James Smart28baac72010-02-12 14:42:03 -05004391 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04004392 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartd79c9e92019-08-14 16:57:09 -07004393
4394 if (phba->cfg_xpsgl && !phba->nvmet_support)
4395 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4396 else
4397 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartace44e42019-01-28 11:14:27 -08004398 } else
4399 /* SLI-3 has a limited number of hardware queues (3),
4400 * thus there is only one for FCP processing.
4401 */
4402 shost->nr_hw_queues = 1;
James Smart81301a92008-12-04 22:39:46 -05004403
James Smart47a86172007-04-25 09:53:22 -04004404 /*
James Smart2e0fef82007-06-17 19:56:36 -05004405 * Set initial can_queue value since 0 is no longer supported and
4406 * scsi_add_host will fail. This will be adjusted later based on the
4407 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04004408 */
James Smart2e0fef82007-06-17 19:56:36 -05004409 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04004410 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05004411 shost->transportt = lpfc_vport_transport_template;
4412 vport->port_type = LPFC_NPIV_PORT;
4413 } else {
4414 shost->transportt = lpfc_transport_template;
4415 vport->port_type = LPFC_PHYSICAL_PORT;
4416 }
James Smart47a86172007-04-25 09:53:22 -04004417
James Smartc90b4482020-03-22 11:12:56 -07004418 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4419 "9081 CreatePort TMPLATE type %x TBLsize %d "
4420 "SEGcnt %d/%d\n",
4421 vport->port_type, shost->sg_tablesize,
4422 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4423
James Smart2e0fef82007-06-17 19:56:36 -05004424 /* Initialize all internally managed lists. */
4425 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04004426 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05004427 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04004428
Kees Cookf22eb4d2017-09-06 20:24:26 -07004429 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04004430
Kees Cookf22eb4d2017-09-06 20:24:26 -07004431 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05004432
Kees Cookf22eb4d2017-09-06 20:24:26 -07004433 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05004434
James Smartaa6ff302019-05-21 17:49:09 -07004435 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4436 lpfc_setup_bg(phba, shost);
4437
James Bottomleyd139b9b2009-11-05 13:33:12 -06004438 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05004439 if (error)
4440 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04004441
James Smart523128e2018-09-10 10:30:46 -07004442 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004443 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07004444 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004445 return vport;
James Smart47a86172007-04-25 09:53:22 -04004446
James Smart2e0fef82007-06-17 19:56:36 -05004447out_put_shost:
4448 scsi_host_put(shost);
4449out:
4450 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004451}
4452
James Smarte59058c2008-08-24 21:49:00 -04004453/**
James Smart3621a712009-04-06 18:47:14 -04004454 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004455 * @vport: pointer to an lpfc virtual N_Port data structure.
4456 *
4457 * This routine destroys a FC port from the upper layer protocol. All the
4458 * resources associated with the port are released.
4459 **/
James Smart2e0fef82007-06-17 19:56:36 -05004460void
4461destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004462{
James Smart92d7f7b2007-06-17 19:56:38 -05004463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4464 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004465
James Smart858c9f62007-06-17 19:56:39 -05004466 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004467 fc_remove_host(shost);
4468 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004469
James Smart523128e2018-09-10 10:30:46 -07004470 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004471 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004472 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004473
James Smart92d7f7b2007-06-17 19:56:38 -05004474 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004475 return;
James Smart47a86172007-04-25 09:53:22 -04004476}
4477
James Smarte59058c2008-08-24 21:49:00 -04004478/**
James Smart3621a712009-04-06 18:47:14 -04004479 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004480 *
4481 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4482 * uses the kernel idr facility to perform the task.
4483 *
4484 * Return codes:
4485 * instance - a unique integer ID allocated as the new instance.
4486 * -1 - lpfc get instance failed.
4487 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004488int
4489lpfc_get_instance(void)
4490{
Tejun Heoab516032013-02-27 17:04:44 -08004491 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004492
Tejun Heoab516032013-02-27 17:04:44 -08004493 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4494 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004495}
4496
James Smarte59058c2008-08-24 21:49:00 -04004497/**
James Smart3621a712009-04-06 18:47:14 -04004498 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004499 * @shost: pointer to SCSI host data structure.
4500 * @time: elapsed time of the scan in jiffies.
4501 *
4502 * This routine is called by the SCSI layer with a SCSI host to determine
4503 * whether the scan host is finished.
4504 *
4505 * Note: there is no scan_start function as adapter initialization will have
4506 * asynchronously kicked off the link initialization.
4507 *
4508 * Return codes
4509 * 0 - SCSI host scan is not over yet.
4510 * 1 - SCSI host scan is over.
4511 **/
James Smart47a86172007-04-25 09:53:22 -04004512int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4513{
James Smart2e0fef82007-06-17 19:56:36 -05004514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4515 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004516 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004517
James Smart858c9f62007-06-17 19:56:39 -05004518 spin_lock_irq(shost->host_lock);
4519
James Smart51ef4c22007-08-02 11:10:31 -04004520 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004521 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004522 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004523 }
James Smart256ec0d2013-04-17 20:14:58 -04004524 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004525 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004526 "0461 Scanning longer than 30 "
4527 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004528 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004529 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004530 }
James Smart256ec0d2013-04-17 20:14:58 -04004531 if (time >= msecs_to_jiffies(15 * 1000) &&
4532 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004533 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004534 "0465 Link down longer than 15 "
4535 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004536 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004537 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004538 }
4539
James Smart2e0fef82007-06-17 19:56:36 -05004540 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004541 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004542 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004543 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004544 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004545 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004546 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004547 goto finished;
4548
4549 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004550
4551finished:
James Smart858c9f62007-06-17 19:56:39 -05004552 spin_unlock_irq(shost->host_lock);
4553 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004554}
4555
Bart Van Assche3999df72019-03-28 11:06:16 -07004556static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
James Smartcd713482018-10-23 13:41:01 -07004557{
4558 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4559 struct lpfc_hba *phba = vport->phba;
4560
4561 fc_host_supported_speeds(shost) = 0;
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07004562 /*
4563 * Avoid reporting supported link speed for FCoE as it can't be
4564 * controlled via FCoE.
4565 */
4566 if (phba->hba_flag & HBA_FCOE_MODE)
4567 return;
4568
James Smart1dc5ec22018-10-23 13:41:11 -07004569 if (phba->lmt & LMT_128Gb)
4570 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004571 if (phba->lmt & LMT_64Gb)
4572 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4573 if (phba->lmt & LMT_32Gb)
4574 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4575 if (phba->lmt & LMT_16Gb)
4576 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4577 if (phba->lmt & LMT_10Gb)
4578 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4579 if (phba->lmt & LMT_8Gb)
4580 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4581 if (phba->lmt & LMT_4Gb)
4582 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4583 if (phba->lmt & LMT_2Gb)
4584 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4585 if (phba->lmt & LMT_1Gb)
4586 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4587}
4588
James Smarte59058c2008-08-24 21:49:00 -04004589/**
James Smart3621a712009-04-06 18:47:14 -04004590 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004591 * @shost: pointer to SCSI host data structure.
4592 *
4593 * This routine initializes a given SCSI host attributes on a FC port. The
4594 * SCSI host can be either on top of a physical port or a virtual port.
4595 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004596void lpfc_host_attrib_init(struct Scsi_Host *shost)
4597{
4598 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4599 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004600 /*
James Smart2e0fef82007-06-17 19:56:36 -05004601 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004602 */
4603
James Smart2e0fef82007-06-17 19:56:36 -05004604 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4605 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004606 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4607
4608 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004609 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004610 fc_host_supported_fc4s(shost)[2] = 1;
4611 fc_host_supported_fc4s(shost)[7] = 1;
4612
James Smart92d7f7b2007-06-17 19:56:38 -05004613 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4614 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004615
James Smartcd713482018-10-23 13:41:01 -07004616 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004617
4618 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004619 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4620 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004621
Mike Christie0af5d702010-09-15 16:52:31 -05004622 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4623
James Smart47a86172007-04-25 09:53:22 -04004624 /* This value is also unchanging */
4625 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004626 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004627 fc_host_active_fc4s(shost)[2] = 1;
4628 fc_host_active_fc4s(shost)[7] = 1;
4629
James Smart92d7f7b2007-06-17 19:56:38 -05004630 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004631 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004632 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004633 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004634}
dea31012005-04-17 16:05:31 -05004635
James Smarte59058c2008-08-24 21:49:00 -04004636/**
James Smartda0436e2009-05-22 14:51:39 -04004637 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004638 * @phba: pointer to lpfc hba data structure.
4639 *
James Smartda0436e2009-05-22 14:51:39 -04004640 * This routine is invoked to stop an SLI3 device port, it stops the device
4641 * from generating interrupts and stops the device driver's timers for the
4642 * device.
James Smarte59058c2008-08-24 21:49:00 -04004643 **/
James Smartdb2378e2008-02-08 18:49:51 -05004644static void
James Smartda0436e2009-05-22 14:51:39 -04004645lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004646{
James Smartda0436e2009-05-22 14:51:39 -04004647 /* Clear all interrupt enable conditions */
4648 writel(0, phba->HCregaddr);
4649 readl(phba->HCregaddr); /* flush */
4650 /* Clear all pending interrupts */
4651 writel(0xffffffff, phba->HAregaddr);
4652 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004653
James Smartda0436e2009-05-22 14:51:39 -04004654 /* Reset some HBA SLI setup states */
4655 lpfc_stop_hba_timers(phba);
4656 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004657}
4658
James Smarte59058c2008-08-24 21:49:00 -04004659/**
James Smartda0436e2009-05-22 14:51:39 -04004660 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004661 * @phba: pointer to lpfc hba data structure.
4662 *
James Smartda0436e2009-05-22 14:51:39 -04004663 * This routine is invoked to stop an SLI4 device port, it stops the device
4664 * from generating interrupts and stops the device driver's timers for the
4665 * device.
4666 **/
4667static void
4668lpfc_stop_port_s4(struct lpfc_hba *phba)
4669{
4670 /* Reset some HBA SLI4 setup states */
4671 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -08004672 if (phba->pport)
4673 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -04004674 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004675}
4676
4677/**
4678 * lpfc_stop_port - Wrapper function for stopping hba port
4679 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004680 *
James Smartda0436e2009-05-22 14:51:39 -04004681 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4682 * the API jump table function pointer from the lpfc_hba struct.
4683 **/
4684void
4685lpfc_stop_port(struct lpfc_hba *phba)
4686{
4687 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004688
4689 if (phba->wq)
4690 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004691}
4692
4693/**
James Smartecfd03c2010-02-12 14:41:27 -05004694 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4695 * @phba: Pointer to hba for which this call is being executed.
4696 *
4697 * This routine starts the timer waiting for the FCF rediscovery to complete.
4698 **/
4699void
4700lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4701{
4702 unsigned long fcf_redisc_wait_tmo =
4703 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4704 /* Start fcf rediscovery wait period timer */
4705 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4706 spin_lock_irq(&phba->hbalock);
4707 /* Allow action to new fcf asynchronous event */
4708 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4709 /* Mark the FCF rediscovery pending state */
4710 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4711 spin_unlock_irq(&phba->hbalock);
4712}
4713
4714/**
4715 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
Lee Jonesfe614ac2020-07-23 13:24:22 +01004716 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
James Smartecfd03c2010-02-12 14:41:27 -05004717 *
4718 * This routine is invoked when waiting for FCF table rediscover has been
4719 * timed out. If new FCF record(s) has (have) been discovered during the
4720 * wait period, a new FCF event shall be added to the FCOE async event
4721 * list, and then worker thread shall be waked up for processing from the
4722 * worker thread context.
4723 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004724static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004725lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004726{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004727 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004728
4729 /* Don't send FCF rediscovery event if timer cancelled */
4730 spin_lock_irq(&phba->hbalock);
4731 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4732 spin_unlock_irq(&phba->hbalock);
4733 return;
4734 }
4735 /* Clear FCF rediscovery timer pending flag */
4736 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4737 /* FCF rediscovery event to worker thread */
4738 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4739 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004740 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004741 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004742 /* wake up worker thread */
4743 lpfc_worker_wake_up(phba);
4744}
4745
4746/**
James Smartda0436e2009-05-22 14:51:39 -04004747 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4748 * @phba: pointer to lpfc hba data structure.
4749 * @acqe_link: pointer to the async link completion queue entry.
4750 *
James Smart23288b72018-05-04 20:37:53 -07004751 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004752 **/
James Smart23288b72018-05-04 20:37:53 -07004753static void
James Smartda0436e2009-05-22 14:51:39 -04004754lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4755 struct lpfc_acqe_link *acqe_link)
4756{
James Smartda0436e2009-05-22 14:51:39 -04004757 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4758 case LPFC_ASYNC_LINK_FAULT_NONE:
4759 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4760 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004761 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004762 break;
4763 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07004764 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart23288b72018-05-04 20:37:53 -07004765 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004766 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004767 break;
4768 }
James Smartda0436e2009-05-22 14:51:39 -04004769}
4770
4771/**
4772 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4773 * @phba: pointer to lpfc hba data structure.
4774 * @acqe_link: pointer to the async link completion queue entry.
4775 *
4776 * This routine is to parse the SLI4 link attention type and translate it
4777 * into the base driver's link attention type coding.
4778 *
4779 * Return: Link attention type in terms of base driver's coding.
4780 **/
4781static uint8_t
4782lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4783 struct lpfc_acqe_link *acqe_link)
4784{
4785 uint8_t att_type;
4786
4787 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4788 case LPFC_ASYNC_LINK_STATUS_DOWN:
4789 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004790 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004791 break;
4792 case LPFC_ASYNC_LINK_STATUS_UP:
4793 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004794 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004795 break;
4796 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004797 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004798 break;
4799 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07004800 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04004801 "0399 Invalid link attention type: x%x\n",
4802 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004803 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004804 break;
4805 }
4806 return att_type;
4807}
4808
4809/**
James Smart8b68cd52012-09-29 11:32:37 -04004810 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4811 * @phba: pointer to lpfc hba data structure.
4812 *
4813 * This routine is to get an SLI3 FC port's link speed in Mbps.
4814 *
4815 * Return: link speed in terms of Mbps.
4816 **/
4817uint32_t
4818lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4819{
4820 uint32_t link_speed;
4821
4822 if (!lpfc_is_link_up(phba))
4823 return 0;
4824
James Smarta085e872015-12-16 18:12:02 -05004825 if (phba->sli_rev <= LPFC_SLI_REV3) {
4826 switch (phba->fc_linkspeed) {
4827 case LPFC_LINK_SPEED_1GHZ:
4828 link_speed = 1000;
4829 break;
4830 case LPFC_LINK_SPEED_2GHZ:
4831 link_speed = 2000;
4832 break;
4833 case LPFC_LINK_SPEED_4GHZ:
4834 link_speed = 4000;
4835 break;
4836 case LPFC_LINK_SPEED_8GHZ:
4837 link_speed = 8000;
4838 break;
4839 case LPFC_LINK_SPEED_10GHZ:
4840 link_speed = 10000;
4841 break;
4842 case LPFC_LINK_SPEED_16GHZ:
4843 link_speed = 16000;
4844 break;
4845 default:
4846 link_speed = 0;
4847 }
4848 } else {
4849 if (phba->sli4_hba.link_state.logical_speed)
4850 link_speed =
4851 phba->sli4_hba.link_state.logical_speed;
4852 else
4853 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004854 }
4855 return link_speed;
4856}
4857
4858/**
4859 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4860 * @phba: pointer to lpfc hba data structure.
4861 * @evt_code: asynchronous event code.
4862 * @speed_code: asynchronous event link speed code.
4863 *
4864 * This routine is to parse the giving SLI4 async event link speed code into
4865 * value of Mbps for the link speed.
4866 *
4867 * Return: link speed in terms of Mbps.
4868 **/
4869static uint32_t
4870lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4871 uint8_t speed_code)
4872{
4873 uint32_t port_speed;
4874
4875 switch (evt_code) {
4876 case LPFC_TRAILER_CODE_LINK:
4877 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004878 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004879 port_speed = 0;
4880 break;
James Smart26d830e2015-04-07 15:07:17 -04004881 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004882 port_speed = 10;
4883 break;
James Smart26d830e2015-04-07 15:07:17 -04004884 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004885 port_speed = 100;
4886 break;
James Smart26d830e2015-04-07 15:07:17 -04004887 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004888 port_speed = 1000;
4889 break;
James Smart26d830e2015-04-07 15:07:17 -04004890 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004891 port_speed = 10000;
4892 break;
James Smart26d830e2015-04-07 15:07:17 -04004893 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4894 port_speed = 20000;
4895 break;
4896 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4897 port_speed = 25000;
4898 break;
4899 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4900 port_speed = 40000;
4901 break;
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07004902 case LPFC_ASYNC_LINK_SPEED_100GBPS:
4903 port_speed = 100000;
4904 break;
James Smart8b68cd52012-09-29 11:32:37 -04004905 default:
4906 port_speed = 0;
4907 }
4908 break;
4909 case LPFC_TRAILER_CODE_FC:
4910 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004911 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004912 port_speed = 0;
4913 break;
James Smart26d830e2015-04-07 15:07:17 -04004914 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004915 port_speed = 1000;
4916 break;
James Smart26d830e2015-04-07 15:07:17 -04004917 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004918 port_speed = 2000;
4919 break;
James Smart26d830e2015-04-07 15:07:17 -04004920 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004921 port_speed = 4000;
4922 break;
James Smart26d830e2015-04-07 15:07:17 -04004923 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004924 port_speed = 8000;
4925 break;
James Smart26d830e2015-04-07 15:07:17 -04004926 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004927 port_speed = 10000;
4928 break;
James Smart26d830e2015-04-07 15:07:17 -04004929 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004930 port_speed = 16000;
4931 break;
James Smartd38dd522015-08-31 16:48:17 -04004932 case LPFC_FC_LA_SPEED_32G:
4933 port_speed = 32000;
4934 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004935 case LPFC_FC_LA_SPEED_64G:
4936 port_speed = 64000;
4937 break;
James Smart1dc5ec22018-10-23 13:41:11 -07004938 case LPFC_FC_LA_SPEED_128G:
4939 port_speed = 128000;
4940 break;
James Smart8b68cd52012-09-29 11:32:37 -04004941 default:
4942 port_speed = 0;
4943 }
4944 break;
4945 default:
4946 port_speed = 0;
4947 }
4948 return port_speed;
4949}
4950
4951/**
James Smart70f3c072010-12-15 17:57:33 -05004952 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004953 * @phba: pointer to lpfc hba data structure.
4954 * @acqe_link: pointer to the async link completion queue entry.
4955 *
James Smart70f3c072010-12-15 17:57:33 -05004956 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004957 **/
4958static void
4959lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4960 struct lpfc_acqe_link *acqe_link)
4961{
4962 struct lpfc_dmabuf *mp;
4963 LPFC_MBOXQ_t *pmb;
4964 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004965 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004966 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004967 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004968
4969 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004970 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004971 return;
James Smart32b97932009-07-19 10:01:21 -04004972 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004973 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4974 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004975 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04004976 "0395 The mboxq allocation failed\n");
4977 return;
4978 }
4979 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4980 if (!mp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004981 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04004982 "0396 The lpfc_dmabuf allocation failed\n");
4983 goto out_free_pmb;
4984 }
4985 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4986 if (!mp->virt) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004987 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04004988 "0397 The mbuf allocation failed\n");
4989 goto out_free_dmabuf;
4990 }
4991
4992 /* Cleanup any outstanding ELS commands */
4993 lpfc_els_flush_all_cmd(phba);
4994
4995 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004996 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004997
4998 /* Update link event statistics */
4999 phba->sli.slistat.link_event++;
5000
James Smart76a95d72010-11-20 23:11:48 -05005001 /* Create lpfc_handle_latt mailbox command from link ACQE */
5002 lpfc_read_topology(phba, pmb, mp);
5003 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04005004 pmb->vport = phba->pport;
5005
James Smartda0436e2009-05-22 14:51:39 -04005006 /* Keep the link status for extra SLI4 state machine reference */
5007 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04005008 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5009 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04005010 phba->sli4_hba.link_state.duplex =
5011 bf_get(lpfc_acqe_link_duplex, acqe_link);
5012 phba->sli4_hba.link_state.status =
5013 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05005014 phba->sli4_hba.link_state.type =
5015 bf_get(lpfc_acqe_link_type, acqe_link);
5016 phba->sli4_hba.link_state.number =
5017 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04005018 phba->sli4_hba.link_state.fault =
5019 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05005020 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005021 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5022
James Smart70f3c072010-12-15 17:57:33 -05005023 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04005024 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5025 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5026 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05005027 phba->sli4_hba.link_state.speed,
5028 phba->sli4_hba.link_state.topology,
5029 phba->sli4_hba.link_state.status,
5030 phba->sli4_hba.link_state.type,
5031 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04005032 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05005033 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05005034 /*
5035 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5036 * topology info. Note: Optional for non FC-AL ports.
5037 */
5038 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5039 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5040 if (rc == MBX_NOT_FINISHED)
5041 goto out_free_dmabuf;
5042 return;
5043 }
5044 /*
5045 * For FCoE Mode: fill in all the topology information we need and call
5046 * the READ_TOPOLOGY completion routine to continue without actually
5047 * sending the READ_TOPOLOGY mailbox command to the port.
5048 */
James Smart23288b72018-05-04 20:37:53 -07005049 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05005050 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07005051 mb->mbxStatus = MBX_SUCCESS;
5052
5053 /* Parse port fault information field */
5054 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05005055
5056 /* Parse and translate link attention fields */
5057 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5058 la->eventTag = acqe_link->event_tag;
5059 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5060 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05005061 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05005062
5063 /* Fake the the following irrelvant fields */
5064 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5065 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5066 bf_set(lpfc_mbx_read_top_il, la, 0);
5067 bf_set(lpfc_mbx_read_top_pb, la, 0);
5068 bf_set(lpfc_mbx_read_top_fa, la, 0);
5069 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04005070
5071 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05005072 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04005073
5074 return;
5075
5076out_free_dmabuf:
5077 kfree(mp);
5078out_free_pmb:
5079 mempool_free(pmb, phba->mbox_mem_pool);
5080}
5081
5082/**
James Smart1dc5ec22018-10-23 13:41:11 -07005083 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5084 * topology.
5085 * @phba: pointer to lpfc hba data structure.
James Smart1dc5ec22018-10-23 13:41:11 -07005086 * @speed_code: asynchronous event link speed code.
5087 *
5088 * This routine is to parse the giving SLI4 async event link speed code into
5089 * value of Read topology link speed.
5090 *
5091 * Return: link speed in terms of Read topology.
5092 **/
5093static uint8_t
5094lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5095{
5096 uint8_t port_speed;
5097
5098 switch (speed_code) {
5099 case LPFC_FC_LA_SPEED_1G:
5100 port_speed = LPFC_LINK_SPEED_1GHZ;
5101 break;
5102 case LPFC_FC_LA_SPEED_2G:
5103 port_speed = LPFC_LINK_SPEED_2GHZ;
5104 break;
5105 case LPFC_FC_LA_SPEED_4G:
5106 port_speed = LPFC_LINK_SPEED_4GHZ;
5107 break;
5108 case LPFC_FC_LA_SPEED_8G:
5109 port_speed = LPFC_LINK_SPEED_8GHZ;
5110 break;
5111 case LPFC_FC_LA_SPEED_16G:
5112 port_speed = LPFC_LINK_SPEED_16GHZ;
5113 break;
5114 case LPFC_FC_LA_SPEED_32G:
5115 port_speed = LPFC_LINK_SPEED_32GHZ;
5116 break;
5117 case LPFC_FC_LA_SPEED_64G:
5118 port_speed = LPFC_LINK_SPEED_64GHZ;
5119 break;
5120 case LPFC_FC_LA_SPEED_128G:
5121 port_speed = LPFC_LINK_SPEED_128GHZ;
5122 break;
5123 case LPFC_FC_LA_SPEED_256G:
5124 port_speed = LPFC_LINK_SPEED_256GHZ;
5125 break;
5126 default:
5127 port_speed = 0;
5128 break;
5129 }
5130
5131 return port_speed;
5132}
5133
5134#define trunk_link_status(__idx)\
5135 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5136 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5137 "Link up" : "Link down") : "NA"
5138/* Did port __idx reported an error */
5139#define trunk_port_fault(__idx)\
5140 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5141 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5142
5143static void
5144lpfc_update_trunk_link_status(struct lpfc_hba *phba,
5145 struct lpfc_acqe_fc_la *acqe_fc)
5146{
5147 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
5148 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
5149
5150 phba->sli4_hba.link_state.speed =
5151 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5152 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5153
5154 phba->sli4_hba.link_state.logical_speed =
James Smartb8e6f132019-05-21 17:49:04 -07005155 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart1dc5ec22018-10-23 13:41:11 -07005156 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5157 phba->fc_linkspeed =
5158 lpfc_async_link_speed_to_read_top(
5159 phba,
5160 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5161
5162 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
5163 phba->trunk_link.link0.state =
5164 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
5165 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005166 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005167 }
5168 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
5169 phba->trunk_link.link1.state =
5170 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
5171 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005172 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005173 }
5174 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
5175 phba->trunk_link.link2.state =
5176 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
5177 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005178 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005179 }
5180 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
5181 phba->trunk_link.link3.state =
5182 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
5183 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005184 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005185 }
5186
Dick Kennedy372c1872020-06-30 14:50:00 -07005187 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1dc5ec22018-10-23 13:41:11 -07005188 "2910 Async FC Trunking Event - Speed:%d\n"
5189 "\tLogical speed:%d "
5190 "port0: %s port1: %s port2: %s port3: %s\n",
5191 phba->sli4_hba.link_state.speed,
5192 phba->sli4_hba.link_state.logical_speed,
5193 trunk_link_status(0), trunk_link_status(1),
5194 trunk_link_status(2), trunk_link_status(3));
5195
5196 if (port_fault)
Dick Kennedy372c1872020-06-30 14:50:00 -07005197 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1dc5ec22018-10-23 13:41:11 -07005198 "3202 trunk error:0x%x (%s) seen on port0:%s "
5199 /*
5200 * SLI-4: We have only 0xA error codes
5201 * defined as of now. print an appropriate
5202 * message in case driver needs to be updated.
5203 */
5204 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
5205 "UNDEFINED. update driver." : trunk_errmsg[err],
5206 trunk_port_fault(0), trunk_port_fault(1),
5207 trunk_port_fault(2), trunk_port_fault(3));
5208}
5209
5210
5211/**
James Smart70f3c072010-12-15 17:57:33 -05005212 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5213 * @phba: pointer to lpfc hba data structure.
5214 * @acqe_fc: pointer to the async fc completion queue entry.
5215 *
5216 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5217 * that the event was received and then issue a read_topology mailbox command so
5218 * that the rest of the driver will treat it the same as SLI3.
5219 **/
5220static void
5221lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
5222{
5223 struct lpfc_dmabuf *mp;
5224 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07005225 MAILBOX_t *mb;
5226 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05005227 int rc;
5228
5229 if (bf_get(lpfc_trailer_type, acqe_fc) !=
5230 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005231 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05005232 "2895 Non FC link Event detected.(%d)\n",
5233 bf_get(lpfc_trailer_type, acqe_fc));
5234 return;
5235 }
James Smart1dc5ec22018-10-23 13:41:11 -07005236
5237 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5238 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
5239 lpfc_update_trunk_link_status(phba, acqe_fc);
5240 return;
5241 }
5242
James Smart70f3c072010-12-15 17:57:33 -05005243 /* Keep the link status for extra SLI4 state machine reference */
5244 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04005245 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5246 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05005247 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
5248 phba->sli4_hba.link_state.topology =
5249 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
5250 phba->sli4_hba.link_state.status =
5251 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
5252 phba->sli4_hba.link_state.type =
5253 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
5254 phba->sli4_hba.link_state.number =
5255 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
5256 phba->sli4_hba.link_state.fault =
5257 bf_get(lpfc_acqe_link_fault, acqe_fc);
James Smartb8e6f132019-05-21 17:49:04 -07005258
5259 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5260 LPFC_FC_LA_TYPE_LINK_DOWN)
5261 phba->sli4_hba.link_state.logical_speed = 0;
5262 else if (!phba->sli4_hba.conf_trunk)
5263 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005264 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smartb8e6f132019-05-21 17:49:04 -07005265
James Smart70f3c072010-12-15 17:57:33 -05005266 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5267 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5268 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5269 "%dMbps Fault:%d\n",
5270 phba->sli4_hba.link_state.speed,
5271 phba->sli4_hba.link_state.topology,
5272 phba->sli4_hba.link_state.status,
5273 phba->sli4_hba.link_state.type,
5274 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04005275 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05005276 phba->sli4_hba.link_state.fault);
5277 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5278 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05005280 "2897 The mboxq allocation failed\n");
5281 return;
5282 }
5283 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5284 if (!mp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005285 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05005286 "2898 The lpfc_dmabuf allocation failed\n");
5287 goto out_free_pmb;
5288 }
5289 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5290 if (!mp->virt) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005291 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05005292 "2899 The mbuf allocation failed\n");
5293 goto out_free_dmabuf;
5294 }
5295
5296 /* Cleanup any outstanding ELS commands */
5297 lpfc_els_flush_all_cmd(phba);
5298
5299 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08005300 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05005301
5302 /* Update link event statistics */
5303 phba->sli.slistat.link_event++;
5304
5305 /* Create lpfc_handle_latt mailbox command from link ACQE */
5306 lpfc_read_topology(phba, pmb, mp);
5307 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5308 pmb->vport = phba->pport;
5309
James Smart7bdedb32016-07-06 12:36:00 -07005310 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07005311 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
5312
5313 switch (phba->sli4_hba.link_state.status) {
5314 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
5315 phba->link_flag |= LS_MDS_LINK_DOWN;
5316 break;
5317 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
5318 phba->link_flag |= LS_MDS_LOOPBACK;
5319 break;
5320 default:
5321 break;
5322 }
5323
James Smart23288b72018-05-04 20:37:53 -07005324 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07005325 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07005326 mb->mbxStatus = MBX_SUCCESS;
5327
5328 /* Parse port fault information field */
5329 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07005330
5331 /* Parse and translate link attention fields */
5332 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
5333 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07005334
James Smartaeb3c812017-04-21 16:05:02 -07005335 if (phba->sli4_hba.link_state.status ==
5336 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
5337 bf_set(lpfc_mbx_read_top_att_type, la,
5338 LPFC_FC_LA_TYPE_UNEXP_WWPN);
5339 } else {
5340 bf_set(lpfc_mbx_read_top_att_type, la,
5341 LPFC_FC_LA_TYPE_LINK_DOWN);
5342 }
James Smart7bdedb32016-07-06 12:36:00 -07005343 /* Invoke the mailbox command callback function */
5344 lpfc_mbx_cmpl_read_topology(phba, pmb);
5345
5346 return;
5347 }
5348
James Smart70f3c072010-12-15 17:57:33 -05005349 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5350 if (rc == MBX_NOT_FINISHED)
5351 goto out_free_dmabuf;
5352 return;
5353
5354out_free_dmabuf:
5355 kfree(mp);
5356out_free_pmb:
5357 mempool_free(pmb, phba->mbox_mem_pool);
5358}
5359
5360/**
5361 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5362 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01005363 * @acqe_sli: pointer to the async SLI completion queue entry.
James Smart70f3c072010-12-15 17:57:33 -05005364 *
5365 * This routine is to handle the SLI4 asynchronous SLI events.
5366 **/
5367static void
5368lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
5369{
James Smart4b8bae02012-06-12 13:55:07 -04005370 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04005371 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04005372 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04005373 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05005374 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04005375 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04005376 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04005377 struct Scsi_Host *shost;
James Smartcd713482018-10-23 13:41:01 -07005378 struct lpfc_vport **vports;
5379 int rc, i;
James Smart4b8bae02012-06-12 13:55:07 -04005380
James Smart946727d2015-04-07 15:07:09 -04005381 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
5382
James Smart448193b2015-12-16 18:12:05 -05005383 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartd11ed162019-09-21 20:59:03 -07005384 "2901 Async SLI event - Type:%d, Event Data: x%08x "
5385 "x%08x x%08x x%08x\n", evt_type,
James Smart448193b2015-12-16 18:12:05 -05005386 acqe_sli->event_data1, acqe_sli->event_data2,
James Smartd11ed162019-09-21 20:59:03 -07005387 acqe_sli->reserved, acqe_sli->trailer);
James Smart4b8bae02012-06-12 13:55:07 -04005388
5389 port_name = phba->Port[0];
5390 if (port_name == 0x00)
5391 port_name = '?'; /* get port name is empty */
5392
James Smart946727d2015-04-07 15:07:09 -04005393 switch (evt_type) {
5394 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
5395 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5396 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
5397 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5398
5399 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5400 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5401 acqe_sli->event_data1, port_name);
5402
James Smart310429e2016-07-06 12:35:54 -07005403 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04005404 shost = lpfc_shost_from_vport(phba->pport);
5405 fc_host_post_vendor_event(shost, fc_get_event_number(),
5406 sizeof(temp_event_data),
5407 (char *)&temp_event_data,
5408 SCSI_NL_VID_TYPE_PCI
5409 | PCI_VENDOR_ID_EMULEX);
5410 break;
5411 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
5412 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5413 temp_event_data.event_code = LPFC_NORMAL_TEMP;
5414 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5415
5416 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5417 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5418 acqe_sli->event_data1, port_name);
5419
5420 shost = lpfc_shost_from_vport(phba->pport);
5421 fc_host_post_vendor_event(shost, fc_get_event_number(),
5422 sizeof(temp_event_data),
5423 (char *)&temp_event_data,
5424 SCSI_NL_VID_TYPE_PCI
5425 | PCI_VENDOR_ID_EMULEX);
5426 break;
5427 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
5428 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04005429 &acqe_sli->event_data1;
5430
James Smart946727d2015-04-07 15:07:09 -04005431 /* fetch the status for this port */
5432 switch (phba->sli4_hba.lnk_info.lnk_no) {
5433 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05005434 status = bf_get(lpfc_sli_misconfigured_port0_state,
5435 &misconfigured->theEvent);
5436 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04005437 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005438 break;
5439 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05005440 status = bf_get(lpfc_sli_misconfigured_port1_state,
5441 &misconfigured->theEvent);
5442 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04005443 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005444 break;
5445 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05005446 status = bf_get(lpfc_sli_misconfigured_port2_state,
5447 &misconfigured->theEvent);
5448 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04005449 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005450 break;
5451 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05005452 status = bf_get(lpfc_sli_misconfigured_port3_state,
5453 &misconfigured->theEvent);
5454 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04005455 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005456 break;
5457 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005458 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart448193b2015-12-16 18:12:05 -05005459 "3296 "
5460 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5461 "event: Invalid link %d",
5462 phba->sli4_hba.lnk_info.lnk_no);
5463 return;
James Smart946727d2015-04-07 15:07:09 -04005464 }
James Smart4b8bae02012-06-12 13:55:07 -04005465
James Smart448193b2015-12-16 18:12:05 -05005466 /* Skip if optic state unchanged */
5467 if (phba->sli4_hba.lnk_info.optic_state == status)
5468 return;
5469
James Smart946727d2015-04-07 15:07:09 -04005470 switch (status) {
5471 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05005472 sprintf(message, "Physical Link is functional");
5473 break;
James Smart946727d2015-04-07 15:07:09 -04005474 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5475 sprintf(message, "Optics faulted/incorrectly "
5476 "installed/not installed - Reseat optics, "
5477 "if issue not resolved, replace.");
5478 break;
5479 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5480 sprintf(message,
5481 "Optics of two types installed - Remove one "
5482 "optic or install matching pair of optics.");
5483 break;
5484 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5485 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04005486 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04005487 break;
James Smart448193b2015-12-16 18:12:05 -05005488 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5489 sprintf(message, "Unqualified optics - Replace with "
5490 "Avago optics for Warranty and Technical "
5491 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005492 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005493 break;
5494 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5495 sprintf(message, "Uncertified optics - Replace with "
5496 "Avago-certified optics to enable link "
5497 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005498 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005499 break;
James Smart946727d2015-04-07 15:07:09 -04005500 default:
5501 /* firmware is reporting a status we don't know about */
5502 sprintf(message, "Unknown event status x%02x", status);
5503 break;
5504 }
James Smartcd713482018-10-23 13:41:01 -07005505
5506 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5507 rc = lpfc_sli4_read_config(phba);
James Smart3952e912018-10-23 13:41:02 -07005508 if (rc) {
James Smartcd713482018-10-23 13:41:01 -07005509 phba->lmt = 0;
Dick Kennedy372c1872020-06-30 14:50:00 -07005510 lpfc_printf_log(phba, KERN_ERR,
5511 LOG_TRACE_EVENT,
James Smartcd713482018-10-23 13:41:01 -07005512 "3194 Unable to retrieve supported "
James Smart3952e912018-10-23 13:41:02 -07005513 "speeds, rc = 0x%x\n", rc);
James Smartcd713482018-10-23 13:41:01 -07005514 }
5515 vports = lpfc_create_vport_work_array(phba);
5516 if (vports != NULL) {
5517 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5518 i++) {
5519 shost = lpfc_shost_from_vport(vports[i]);
5520 lpfc_host_supported_speeds_set(shost);
5521 }
5522 }
5523 lpfc_destroy_vport_work_array(phba, vports);
5524
James Smart448193b2015-12-16 18:12:05 -05005525 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04005526 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05005527 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04005528 break;
5529 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5530 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5531 "3192 Remote DPort Test Initiated - "
5532 "Event Data1:x%08x Event Data2: x%08x\n",
5533 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04005534 break;
James Smarte7d85952019-10-18 14:18:29 -07005535 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
5536 /* Misconfigured WWN. Reports that the SLI Port is configured
5537 * to use FA-WWN, but the attached device doesn’t support it.
5538 * No driver action is required.
5539 * Event Data1 - N.A, Event Data2 - N.A
5540 */
5541 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI,
5542 "2699 Misconfigured FA-WWN - Attached device does "
5543 "not support FA-WWN\n");
5544 break;
James Smartd11ed162019-09-21 20:59:03 -07005545 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
5546 /* EEPROM failure. No driver action is required */
5547 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5548 "2518 EEPROM failure - "
5549 "Event Data1: x%08x Event Data2: x%08x\n",
5550 acqe_sli->event_data1, acqe_sli->event_data2);
5551 break;
James Smart4b8bae02012-06-12 13:55:07 -04005552 default:
James Smart946727d2015-04-07 15:07:09 -04005553 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartd11ed162019-09-21 20:59:03 -07005554 "3193 Unrecognized SLI event, type: 0x%x",
James Smart946727d2015-04-07 15:07:09 -04005555 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005556 break;
5557 }
James Smart70f3c072010-12-15 17:57:33 -05005558}
5559
5560/**
James Smartfc2b9892010-02-26 14:15:29 -05005561 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5562 * @vport: pointer to vport data structure.
5563 *
5564 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5565 * response to a CVL event.
5566 *
5567 * Return the pointer to the ndlp with the vport if successful, otherwise
5568 * return NULL.
5569 **/
5570static struct lpfc_nodelist *
5571lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
5572{
5573 struct lpfc_nodelist *ndlp;
5574 struct Scsi_Host *shost;
5575 struct lpfc_hba *phba;
5576
5577 if (!vport)
5578 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05005579 phba = vport->phba;
5580 if (!phba)
5581 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04005582 ndlp = lpfc_findnode_did(vport, Fabric_DID);
5583 if (!ndlp) {
5584 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07005585 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04005586 if (!ndlp)
5587 return 0;
James Smart78730cf2010-04-06 15:06:30 -04005588 /* Set the node type */
5589 ndlp->nlp_type |= NLP_FABRIC;
5590 /* Put ndlp onto node list */
5591 lpfc_enqueue_node(vport, ndlp);
James Smart78730cf2010-04-06 15:06:30 -04005592 }
James Smart63e801c2010-11-20 23:14:19 -05005593 if ((phba->pport->port_state < LPFC_FLOGI) &&
5594 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005595 return NULL;
5596 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05005597 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
5598 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005599 return NULL;
5600 shost = lpfc_shost_from_vport(vport);
5601 if (!shost)
5602 return NULL;
5603 lpfc_linkdown_port(vport);
5604 lpfc_cleanup_pending_mbox(vport);
5605 spin_lock_irq(shost->host_lock);
5606 vport->fc_flag |= FC_VPORT_CVL_RCVD;
5607 spin_unlock_irq(shost->host_lock);
5608
5609 return ndlp;
5610}
5611
5612/**
5613 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
Lee Jonesfe614ac2020-07-23 13:24:22 +01005614 * @phba: pointer to lpfc hba data structure.
James Smartfc2b9892010-02-26 14:15:29 -05005615 *
5616 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5617 * response to a FCF dead event.
5618 **/
5619static void
5620lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
5621{
5622 struct lpfc_vport **vports;
5623 int i;
5624
5625 vports = lpfc_create_vport_work_array(phba);
5626 if (vports)
5627 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
5628 lpfc_sli4_perform_vport_cvl(vports[i]);
5629 lpfc_destroy_vport_work_array(phba, vports);
5630}
5631
5632/**
James Smart76a95d72010-11-20 23:11:48 -05005633 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04005634 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01005635 * @acqe_fip: pointer to the async fcoe completion queue entry.
James Smartda0436e2009-05-22 14:51:39 -04005636 *
5637 * This routine is to handle the SLI4 asynchronous fcoe event.
5638 **/
5639static void
James Smart76a95d72010-11-20 23:11:48 -05005640lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05005641 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04005642{
James Smart70f3c072010-12-15 17:57:33 -05005643 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005644 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04005645 struct lpfc_vport *vport;
5646 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05005647 int active_vlink_present;
5648 struct lpfc_vport **vports;
5649 int i;
James Smartda0436e2009-05-22 14:51:39 -04005650
James Smart70f3c072010-12-15 17:57:33 -05005651 phba->fc_eventTag = acqe_fip->event_tag;
5652 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005653 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005654 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5655 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5656 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
Dick Kennedy372c1872020-06-30 14:50:00 -07005657 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarta93ff372010-10-22 11:06:08 -04005658 "2546 New FCF event, evt_tag:x%x, "
5659 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005660 acqe_fip->event_tag,
5661 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005662 else
5663 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5664 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005665 "2788 FCF param modified event, "
5666 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005667 acqe_fip->event_tag,
5668 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005669 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005670 /*
5671 * During period of FCF discovery, read the FCF
5672 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005673 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005674 */
5675 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5676 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005677 "2779 Read FCF (x%x) for updating "
5678 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005679 acqe_fip->index);
5680 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005681 }
James Smart38b92ef2010-08-04 16:11:39 -04005682
5683 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005684 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005685 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005686 spin_unlock_irq(&phba->hbalock);
5687 break;
5688 }
5689 /* If fast FCF failover rescan event is pending, do nothing */
James Smart036cad12018-10-23 13:41:06 -07005690 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
James Smart38b92ef2010-08-04 16:11:39 -04005691 spin_unlock_irq(&phba->hbalock);
5692 break;
5693 }
5694
James Smartc2b97122013-05-31 17:05:36 -04005695 /* If the FCF has been in discovered state, do nothing. */
5696 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005697 spin_unlock_irq(&phba->hbalock);
5698 break;
5699 }
5700 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005701
James Smart0c9ab6f2010-02-26 14:15:57 -05005702 /* Otherwise, scan the entire FCF table and re-discover SAN */
5703 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005704 "2770 Start FCF table scan per async FCF "
5705 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005706 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005707 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5708 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005709 if (rc)
Dick Kennedy372c1872020-06-30 14:50:00 -07005710 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05005711 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005712 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005713 break;
5714
James Smart70f3c072010-12-15 17:57:33 -05005715 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
Dick Kennedy372c1872020-06-30 14:50:00 -07005716 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5717 "2548 FCF Table full count 0x%x tag 0x%x\n",
5718 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5719 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005720 break;
5721
James Smart70f3c072010-12-15 17:57:33 -05005722 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005723 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07005724 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5725 "2549 FCF (x%x) disconnected from network, "
5726 "tag:x%x\n", acqe_fip->index,
5727 acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005728 /*
5729 * If we are in the middle of FCF failover process, clear
5730 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005731 */
James Smartfc2b9892010-02-26 14:15:29 -05005732 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005733 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5734 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005735 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005736 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005737 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005738 break;
5739 }
James Smart38b92ef2010-08-04 16:11:39 -04005740 spin_unlock_irq(&phba->hbalock);
5741
5742 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005743 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005744 break;
5745
5746 /*
5747 * Otherwise, request the port to rediscover the entire FCF
5748 * table for a fast recovery from case that the current FCF
5749 * is no longer valid as we are not in the middle of FCF
5750 * failover process already.
5751 */
James Smartc2b97122013-05-31 17:05:36 -04005752 spin_lock_irq(&phba->hbalock);
5753 /* Mark the fast failover process in progress */
5754 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5755 spin_unlock_irq(&phba->hbalock);
5756
5757 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5758 "2771 Start FCF fast failover process due to "
5759 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5760 "\n", acqe_fip->event_tag, acqe_fip->index);
5761 rc = lpfc_sli4_redisc_fcf_table(phba);
5762 if (rc) {
5763 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
Dick Kennedy372c1872020-06-30 14:50:00 -07005764 LOG_TRACE_EVENT,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005765 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005766 "command failed, fail through to FCF "
5767 "dead event\n");
5768 spin_lock_irq(&phba->hbalock);
5769 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5770 spin_unlock_irq(&phba->hbalock);
5771 /*
5772 * Last resort will fail over by treating this
5773 * as a link down to FCF registration.
5774 */
5775 lpfc_sli4_fcf_dead_failthrough(phba);
5776 } else {
5777 /* Reset FCF roundrobin bmask for new discovery */
5778 lpfc_sli4_clear_fcf_rr_bmask(phba);
5779 /*
5780 * Handling fast FCF failover to a DEAD FCF event is
5781 * considered equalivant to receiving CVL to all vports.
5782 */
5783 lpfc_sli4_perform_all_vport_cvl(phba);
5784 }
James Smartda0436e2009-05-22 14:51:39 -04005785 break;
James Smart70f3c072010-12-15 17:57:33 -05005786 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005787 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07005788 lpfc_printf_log(phba, KERN_ERR,
5789 LOG_TRACE_EVENT,
James Smart6669f9b2009-10-02 15:16:45 -04005790 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005791 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005792
James Smart6669f9b2009-10-02 15:16:45 -04005793 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005794 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005795 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005796 if (!ndlp)
5797 break;
James Smart695a8142010-01-26 23:08:03 -05005798 active_vlink_present = 0;
5799
5800 vports = lpfc_create_vport_work_array(phba);
5801 if (vports) {
5802 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5803 i++) {
5804 if ((!(vports[i]->fc_flag &
5805 FC_VPORT_CVL_RCVD)) &&
5806 (vports[i]->port_state > LPFC_FDISC)) {
5807 active_vlink_present = 1;
5808 break;
5809 }
5810 }
5811 lpfc_destroy_vport_work_array(phba, vports);
5812 }
5813
James Smartcc823552015-05-21 13:55:26 -04005814 /*
5815 * Don't re-instantiate if vport is marked for deletion.
5816 * If we are here first then vport_delete is going to wait
5817 * for discovery to complete.
5818 */
5819 if (!(vport->load_flag & FC_UNLOADING) &&
5820 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005821 /*
5822 * If there are other active VLinks present,
5823 * re-instantiate the Vlink using FDISC.
5824 */
James Smart256ec0d2013-04-17 20:14:58 -04005825 mod_timer(&ndlp->nlp_delayfunc,
5826 jiffies + msecs_to_jiffies(1000));
James Smartc6adba12020-11-15 11:26:34 -08005827 spin_lock_irq(&ndlp->lock);
James Smart6669f9b2009-10-02 15:16:45 -04005828 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08005829 spin_unlock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -05005830 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5831 vport->port_state = LPFC_FDISC;
5832 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005833 /*
5834 * Otherwise, we request port to rediscover
5835 * the entire FCF table for a fast recovery
5836 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005837 * is no longer valid if we are not already
5838 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005839 */
James Smartfc2b9892010-02-26 14:15:29 -05005840 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005841 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005842 spin_unlock_irq(&phba->hbalock);
5843 break;
5844 }
5845 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005846 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005847 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005848 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5849 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005850 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005851 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005852 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005853 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005854 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
Dick Kennedy372c1872020-06-30 14:50:00 -07005855 LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05005856 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005857 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005858 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005859 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005860 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005861 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005862 /*
5863 * Last resort will be re-try on the
5864 * the current registered FCF entry.
5865 */
5866 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005867 } else
5868 /*
5869 * Reset FCF roundrobin bmask for new
5870 * discovery.
5871 */
James Smart7d791df2011-07-22 18:37:52 -04005872 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005873 }
5874 break;
James Smartda0436e2009-05-22 14:51:39 -04005875 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005876 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5877 "0288 Unknown FCoE event type 0x%x event tag "
5878 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005879 break;
5880 }
5881}
5882
5883/**
5884 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5885 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01005886 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
James Smartda0436e2009-05-22 14:51:39 -04005887 *
5888 * This routine is to handle the SLI4 asynchronous dcbx event.
5889 **/
5890static void
5891lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5892 struct lpfc_acqe_dcbx *acqe_dcbx)
5893{
James Smart4d9ab992009-10-02 15:16:39 -04005894 phba->fc_eventTag = acqe_dcbx->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07005895 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04005896 "0290 The SLI4 DCBX asynchronous event is not "
5897 "handled yet\n");
5898}
5899
5900/**
James Smartb19a0612010-04-06 14:48:51 -04005901 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5902 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01005903 * @acqe_grp5: pointer to the async grp5 completion queue entry.
James Smartb19a0612010-04-06 14:48:51 -04005904 *
5905 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5906 * is an asynchronous notified of a logical link speed change. The Port
5907 * reports the logical link speed in units of 10Mbps.
5908 **/
5909static void
5910lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5911 struct lpfc_acqe_grp5 *acqe_grp5)
5912{
5913 uint16_t prev_ll_spd;
5914
5915 phba->fc_eventTag = acqe_grp5->event_tag;
5916 phba->fcoe_eventtag = acqe_grp5->event_tag;
5917 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5918 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005919 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005920 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5921 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005922 "from %dMbps to %dMbps\n", prev_ll_spd,
5923 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005924}
5925
5926/**
James Smartda0436e2009-05-22 14:51:39 -04005927 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5928 * @phba: pointer to lpfc hba data structure.
5929 *
5930 * This routine is invoked by the worker thread to process all the pending
5931 * SLI4 asynchronous events.
5932 **/
5933void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5934{
5935 struct lpfc_cq_event *cq_event;
James Smarte7dab162020-10-20 13:27:12 -07005936 unsigned long iflags;
James Smartda0436e2009-05-22 14:51:39 -04005937
5938 /* First, declare the async event has been handled */
James Smarte7dab162020-10-20 13:27:12 -07005939 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04005940 phba->hba_flag &= ~ASYNC_EVENT;
James Smarte7dab162020-10-20 13:27:12 -07005941 spin_unlock_irqrestore(&phba->hbalock, iflags);
5942
James Smartda0436e2009-05-22 14:51:39 -04005943 /* Now, handle all the async events */
James Smarte7dab162020-10-20 13:27:12 -07005944 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04005945 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
James Smartda0436e2009-05-22 14:51:39 -04005946 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5947 cq_event, struct lpfc_cq_event, list);
James Smarte7dab162020-10-20 13:27:12 -07005948 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
5949 iflags);
5950
James Smartda0436e2009-05-22 14:51:39 -04005951 /* Process the asynchronous event */
5952 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5953 case LPFC_TRAILER_CODE_LINK:
5954 lpfc_sli4_async_link_evt(phba,
5955 &cq_event->cqe.acqe_link);
5956 break;
5957 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005958 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005959 break;
5960 case LPFC_TRAILER_CODE_DCBX:
5961 lpfc_sli4_async_dcbx_evt(phba,
5962 &cq_event->cqe.acqe_dcbx);
5963 break;
James Smartb19a0612010-04-06 14:48:51 -04005964 case LPFC_TRAILER_CODE_GRP5:
5965 lpfc_sli4_async_grp5_evt(phba,
5966 &cq_event->cqe.acqe_grp5);
5967 break;
James Smart70f3c072010-12-15 17:57:33 -05005968 case LPFC_TRAILER_CODE_FC:
5969 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5970 break;
5971 case LPFC_TRAILER_CODE_SLI:
5972 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5973 break;
James Smartda0436e2009-05-22 14:51:39 -04005974 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005975 lpfc_printf_log(phba, KERN_ERR,
5976 LOG_TRACE_EVENT,
Colin Ian King291c2542019-12-18 08:43:01 +00005977 "1804 Invalid asynchronous event code: "
James Smartda0436e2009-05-22 14:51:39 -04005978 "x%x\n", bf_get(lpfc_trailer_code,
5979 &cq_event->cqe.mcqe_cmpl));
5980 break;
5981 }
James Smarte7dab162020-10-20 13:27:12 -07005982
James Smartda0436e2009-05-22 14:51:39 -04005983 /* Free the completion event processed to the free pool */
5984 lpfc_sli4_cq_event_release(phba, cq_event);
James Smarte7dab162020-10-20 13:27:12 -07005985 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04005986 }
James Smarte7dab162020-10-20 13:27:12 -07005987 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04005988}
5989
5990/**
James Smartecfd03c2010-02-12 14:41:27 -05005991 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5992 * @phba: pointer to lpfc hba data structure.
5993 *
5994 * This routine is invoked by the worker thread to process FCF table
5995 * rediscovery pending completion event.
5996 **/
5997void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5998{
5999 int rc;
6000
6001 spin_lock_irq(&phba->hbalock);
6002 /* Clear FCF rediscovery timeout event */
6003 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
6004 /* Clear driver fast failover FCF record flag */
6005 phba->fcf.failover_rec.flag = 0;
6006 /* Set state for FCF fast failover */
6007 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
6008 spin_unlock_irq(&phba->hbalock);
6009
6010 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05006011 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04006012 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05006013 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05006014 if (rc)
Dick Kennedy372c1872020-06-30 14:50:00 -07006015 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05006016 "2747 Issue FCF scan read FCF mailbox "
6017 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05006018}
6019
6020/**
James Smartda0436e2009-05-22 14:51:39 -04006021 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
6022 * @phba: pointer to lpfc hba data structure.
6023 * @dev_grp: The HBA PCI-Device group number.
6024 *
6025 * This routine is invoked to set up the per HBA PCI-Device group function
6026 * API jump table entries.
6027 *
6028 * Return: 0 if success, otherwise -ENODEV
6029 **/
6030int
6031lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05006032{
6033 int rc;
6034
James Smartda0436e2009-05-22 14:51:39 -04006035 /* Set up lpfc PCI-device group */
6036 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05006037
James Smartda0436e2009-05-22 14:51:39 -04006038 /* The LPFC_PCI_DEV_OC uses SLI4 */
6039 if (dev_grp == LPFC_PCI_DEV_OC)
6040 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05006041
James Smartda0436e2009-05-22 14:51:39 -04006042 /* Set up device INIT API function jump table */
6043 rc = lpfc_init_api_table_setup(phba, dev_grp);
6044 if (rc)
6045 return -ENODEV;
6046 /* Set up SCSI API function jump table */
6047 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
6048 if (rc)
6049 return -ENODEV;
6050 /* Set up SLI API function jump table */
6051 rc = lpfc_sli_api_table_setup(phba, dev_grp);
6052 if (rc)
6053 return -ENODEV;
6054 /* Set up MBOX API function jump table */
6055 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
6056 if (rc)
6057 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05006058
James Smartda0436e2009-05-22 14:51:39 -04006059 return 0;
James Smart5b75da22008-12-04 22:39:35 -05006060}
6061
6062/**
James Smart3621a712009-04-06 18:47:14 -04006063 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05006064 * @phba: pointer to lpfc hba data structure.
6065 * @intr_mode: active interrupt mode adopted.
6066 *
6067 * This routine it invoked to log the currently used active interrupt mode
6068 * to the device.
James Smart3772a992009-05-22 14:50:54 -04006069 **/
6070static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05006071{
6072 switch (intr_mode) {
6073 case 0:
6074 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6075 "0470 Enable INTx interrupt mode.\n");
6076 break;
6077 case 1:
6078 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6079 "0481 Enabled MSI interrupt mode.\n");
6080 break;
6081 case 2:
6082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6083 "0480 Enabled MSI-X interrupt mode.\n");
6084 break;
6085 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07006086 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -05006087 "0482 Illegal interrupt mode.\n");
6088 break;
6089 }
6090 return;
6091}
6092
James Smart5b75da22008-12-04 22:39:35 -05006093/**
James Smart3772a992009-05-22 14:50:54 -04006094 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05006095 * @phba: pointer to lpfc hba data structure.
6096 *
James Smart3772a992009-05-22 14:50:54 -04006097 * This routine is invoked to enable the PCI device that is common to all
6098 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05006099 *
6100 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006101 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006102 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05006103 **/
James Smart3772a992009-05-22 14:50:54 -04006104static int
6105lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05006106{
James Smart3772a992009-05-22 14:50:54 -04006107 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05006108
James Smart3772a992009-05-22 14:50:54 -04006109 /* Obtain PCI device reference */
6110 if (!phba->pcidev)
6111 goto out_error;
6112 else
6113 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006114 /* Enable PCI device */
6115 if (pci_enable_device_mem(pdev))
6116 goto out_error;
6117 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006118 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04006119 goto out_disable_device;
6120 /* Set up device as PCI master and save state for EEH */
6121 pci_set_master(pdev);
6122 pci_try_set_mwi(pdev);
6123 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006124
James Smart05580562011-05-24 11:40:48 -04006125 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07006126 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04006127 pdev->needs_freset = 1;
6128
James Smart3772a992009-05-22 14:50:54 -04006129 return 0;
James Smart5b75da22008-12-04 22:39:35 -05006130
James Smart3772a992009-05-22 14:50:54 -04006131out_disable_device:
6132 pci_disable_device(pdev);
6133out_error:
Dick Kennedy372c1872020-06-30 14:50:00 -07006134 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006135 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04006136 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05006137}
6138
6139/**
James Smart3772a992009-05-22 14:50:54 -04006140 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05006141 * @phba: pointer to lpfc hba data structure.
6142 *
James Smart3772a992009-05-22 14:50:54 -04006143 * This routine is invoked to disable the PCI device that is common to all
6144 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05006145 **/
6146static void
James Smart3772a992009-05-22 14:50:54 -04006147lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05006148{
James Smart3772a992009-05-22 14:50:54 -04006149 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05006150
James Smart3772a992009-05-22 14:50:54 -04006151 /* Obtain PCI device reference */
6152 if (!phba->pcidev)
6153 return;
6154 else
6155 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006156 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006157 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04006158 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006159
6160 return;
6161}
6162
6163/**
James Smart3772a992009-05-22 14:50:54 -04006164 * lpfc_reset_hba - Reset a hba
6165 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04006166 *
James Smart3772a992009-05-22 14:50:54 -04006167 * This routine is invoked to reset a hba device. It brings the HBA
6168 * offline, performs a board restart, and then brings the board back
6169 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6170 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04006171 **/
James Smart3772a992009-05-22 14:50:54 -04006172void
6173lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05006174{
James Smart3772a992009-05-22 14:50:54 -04006175 /* If resets are disabled then set error state and return. */
6176 if (!phba->cfg_enable_hba_reset) {
6177 phba->link_state = LPFC_HBA_ERROR;
6178 return;
6179 }
James Smartee620212014-04-04 13:51:53 -04006180 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
6181 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6182 else
6183 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04006184 lpfc_offline(phba);
6185 lpfc_sli_brdrestart(phba);
6186 lpfc_online(phba);
6187 lpfc_unblock_mgmt_io(phba);
6188}
dea31012005-04-17 16:05:31 -05006189
James Smart3772a992009-05-22 14:50:54 -04006190/**
James Smart0a96e972011-07-22 18:37:28 -04006191 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6192 * @phba: pointer to lpfc hba data structure.
6193 *
6194 * This function enables the PCI SR-IOV virtual functions to a physical
6195 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6196 * enable the number of virtual functions to the physical function. As
6197 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6198 * API call does not considered as an error condition for most of the device.
6199 **/
6200uint16_t
6201lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
6202{
6203 struct pci_dev *pdev = phba->pcidev;
6204 uint16_t nr_virtfn;
6205 int pos;
6206
James Smart0a96e972011-07-22 18:37:28 -04006207 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6208 if (pos == 0)
6209 return 0;
6210
6211 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
6212 return nr_virtfn;
6213}
6214
6215/**
James Smart912e3ac2011-05-24 11:42:11 -04006216 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6217 * @phba: pointer to lpfc hba data structure.
6218 * @nr_vfn: number of virtual functions to be enabled.
6219 *
6220 * This function enables the PCI SR-IOV virtual functions to a physical
6221 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6222 * enable the number of virtual functions to the physical function. As
6223 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6224 * API call does not considered as an error condition for most of the device.
6225 **/
6226int
6227lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
6228{
6229 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04006230 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04006231 int rc;
6232
James Smart0a96e972011-07-22 18:37:28 -04006233 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
6234 if (nr_vfn > max_nr_vfn) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006235 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a96e972011-07-22 18:37:28 -04006236 "3057 Requested vfs (%d) greater than "
6237 "supported vfs (%d)", nr_vfn, max_nr_vfn);
6238 return -EINVAL;
6239 }
6240
James Smart912e3ac2011-05-24 11:42:11 -04006241 rc = pci_enable_sriov(pdev, nr_vfn);
6242 if (rc) {
6243 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6244 "2806 Failed to enable sriov on this device "
6245 "with vfn number nr_vf:%d, rc:%d\n",
6246 nr_vfn, rc);
6247 } else
6248 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6249 "2807 Successful enable sriov on this device "
6250 "with vfn number nr_vf:%d\n", nr_vfn);
6251 return rc;
6252}
6253
6254/**
James Smart895427b2017-02-12 13:52:30 -08006255 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04006256 * @phba: pointer to lpfc hba data structure.
6257 *
James Smart895427b2017-02-12 13:52:30 -08006258 * This routine is invoked to set up the driver internal resources before the
6259 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04006260 *
6261 * Return codes
James Smart895427b2017-02-12 13:52:30 -08006262 * 0 - successful
6263 * other values - error
James Smart3772a992009-05-22 14:50:54 -04006264 **/
6265static int
James Smart895427b2017-02-12 13:52:30 -08006266lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04006267{
James Smart895427b2017-02-12 13:52:30 -08006268 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05006269
James Smart3772a992009-05-22 14:50:54 -04006270 /*
James Smart895427b2017-02-12 13:52:30 -08006271 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04006272 */
James Smart895427b2017-02-12 13:52:30 -08006273 atomic_set(&phba->fast_event_count, 0);
Dick Kennedy372c1872020-06-30 14:50:00 -07006274 atomic_set(&phba->dbg_log_idx, 0);
6275 atomic_set(&phba->dbg_log_cnt, 0);
6276 atomic_set(&phba->dbg_log_dmping, 0);
James Smart895427b2017-02-12 13:52:30 -08006277 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006278
James Smart523128e2018-09-10 10:30:46 -07006279 /* Initialize port_list spinlock */
6280 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08006281 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07006282
James Smart895427b2017-02-12 13:52:30 -08006283 INIT_LIST_HEAD(&phba->work_list);
6284 init_waitqueue_head(&phba->wait_4_mlo_m_q);
6285
6286 /* Initialize the wait queue head for the kernel thread */
6287 init_waitqueue_head(&phba->work_waitq);
6288
6289 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08006290 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08006291 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
6292 "SCSI" : " "),
6293 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08006294 "NVME" : " "),
6295 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08006296
James Smart0794d602019-01-28 11:14:19 -08006297 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
6298 spin_lock_init(&phba->scsi_buf_list_get_lock);
6299 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
6300 spin_lock_init(&phba->scsi_buf_list_put_lock);
6301 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart895427b2017-02-12 13:52:30 -08006302
6303 /* Initialize the fabric iocb list */
6304 INIT_LIST_HEAD(&phba->fabric_iocb_list);
6305
6306 /* Initialize list to save ELS buffers */
6307 INIT_LIST_HEAD(&phba->elsbuf);
6308
6309 /* Initialize FCF connection rec list */
6310 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
6311
6312 /* Initialize OAS configuration list */
6313 spin_lock_init(&phba->devicelock);
6314 INIT_LIST_HEAD(&phba->luns);
6315
James Smart3772a992009-05-22 14:50:54 -04006316 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006317 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006318 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006319 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006320 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006321 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08006322 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006323 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08006324
James Smart32517fc2019-01-28 11:14:33 -08006325 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
6326
Dick Kennedy317aeb82020-06-30 14:49:59 -07006327 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
6328 lpfc_idle_stat_delay_work);
6329
James Smart895427b2017-02-12 13:52:30 -08006330 return 0;
6331}
6332
6333/**
6334 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
6335 * @phba: pointer to lpfc hba data structure.
6336 *
6337 * This routine is invoked to set up the driver internal resources specific to
6338 * support the SLI-3 HBA device it attached to.
6339 *
6340 * Return codes
6341 * 0 - successful
6342 * other values - error
6343 **/
6344static int
6345lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
6346{
James Smart0794d602019-01-28 11:14:19 -08006347 int rc, entry_sz;
James Smart895427b2017-02-12 13:52:30 -08006348
6349 /*
6350 * Initialize timers used by driver
6351 */
6352
6353 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006354 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006355
6356 /* Host attention work mask setup */
6357 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
6358 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
6359
6360 /* Get all the module params for configuring this host */
6361 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08006362 /* Set up phase-1 common device driver resources */
6363
6364 rc = lpfc_setup_driver_resource_phase1(phba);
6365 if (rc)
6366 return -ENODEV;
6367
James Smart49198b32010-04-06 15:04:33 -04006368 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
6369 phba->menlo_flag |= HBA_MENLO_SUPPORT;
6370 /* check for menlo minimum sg count */
6371 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
6372 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
6373 }
6374
James Smart895427b2017-02-12 13:52:30 -08006375 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07006376 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
6377 sizeof(struct lpfc_sli_ring),
6378 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006379 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04006380 return -ENOMEM;
6381
James Smart3772a992009-05-22 14:50:54 -04006382 /*
James Smart96f70772013-04-17 20:16:15 -04006383 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04006384 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04006385 */
James Smart3772a992009-05-22 14:50:54 -04006386
James Smart0794d602019-01-28 11:14:19 -08006387 if (phba->sli_rev == LPFC_SLI_REV4)
6388 entry_sz = sizeof(struct sli4_sge);
6389 else
6390 entry_sz = sizeof(struct ulp_bde64);
6391
James Smart96f70772013-04-17 20:16:15 -04006392 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
6393 if (phba->cfg_enable_bg) {
6394 /*
6395 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
6396 * the FCP rsp, and a BDE for each. Sice we have no control
6397 * over how many protection data segments the SCSI Layer
6398 * will hand us (ie: there could be one for every block
6399 * in the IO), we just allocate enough BDEs to accomidate
6400 * our max amount and we need to limit lpfc_sg_seg_cnt to
6401 * minimize the risk of running out.
6402 */
6403 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6404 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006405 (LPFC_MAX_SG_SEG_CNT * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006406
6407 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
6408 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
6409
6410 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
6411 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
6412 } else {
6413 /*
6414 * The scsi_buf for a regular I/O will hold the FCP cmnd,
6415 * the FCP rsp, a BDE for each, and a BDE for up to
6416 * cfg_sg_seg_cnt data segments.
6417 */
6418 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6419 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006420 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006421
6422 /* Total BDEs in BPL for scsi_sg_list */
6423 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
6424 }
6425
6426 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smartc90b4482020-03-22 11:12:56 -07006427 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006428 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6429 phba->cfg_total_seg_cnt);
6430
James Smart3772a992009-05-22 14:50:54 -04006431 phba->max_vpi = LPFC_MAX_VPI;
6432 /* This will be set to correct value after config_port mbox */
6433 phba->max_vports = 0;
6434
6435 /*
6436 * Initialize the SLI Layer to run with lpfc HBAs.
6437 */
6438 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08006439 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04006440
6441 /* Allocate device driver memory */
6442 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
6443 return -ENOMEM;
6444
James Smartd79c9e92019-08-14 16:57:09 -07006445 phba->lpfc_sg_dma_buf_pool =
6446 dma_pool_create("lpfc_sg_dma_buf_pool",
6447 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
6448 BPL_ALIGN_SZ, 0);
6449
6450 if (!phba->lpfc_sg_dma_buf_pool)
6451 goto fail_free_mem;
6452
6453 phba->lpfc_cmd_rsp_buf_pool =
6454 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6455 &phba->pcidev->dev,
6456 sizeof(struct fcp_cmnd) +
6457 sizeof(struct fcp_rsp),
6458 BPL_ALIGN_SZ, 0);
6459
6460 if (!phba->lpfc_cmd_rsp_buf_pool)
6461 goto fail_free_dma_buf_pool;
6462
James Smart912e3ac2011-05-24 11:42:11 -04006463 /*
6464 * Enable sr-iov virtual functions if supported and configured
6465 * through the module parameter.
6466 */
6467 if (phba->cfg_sriov_nr_virtfn > 0) {
6468 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6469 phba->cfg_sriov_nr_virtfn);
6470 if (rc) {
6471 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6472 "2808 Requested number of SR-IOV "
6473 "virtual functions (%d) is not "
6474 "supported\n",
6475 phba->cfg_sriov_nr_virtfn);
6476 phba->cfg_sriov_nr_virtfn = 0;
6477 }
6478 }
6479
James Smart3772a992009-05-22 14:50:54 -04006480 return 0;
James Smartd79c9e92019-08-14 16:57:09 -07006481
6482fail_free_dma_buf_pool:
6483 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
6484 phba->lpfc_sg_dma_buf_pool = NULL;
6485fail_free_mem:
6486 lpfc_mem_free(phba);
6487 return -ENOMEM;
James Smart3772a992009-05-22 14:50:54 -04006488}
6489
6490/**
6491 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6492 * @phba: pointer to lpfc hba data structure.
6493 *
6494 * This routine is invoked to unset the driver internal resources set up
6495 * specific for supporting the SLI-3 HBA device it attached to.
6496 **/
6497static void
6498lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
6499{
6500 /* Free device driver memory allocated */
6501 lpfc_mem_free_all(phba);
6502
6503 return;
6504}
6505
6506/**
James Smartda0436e2009-05-22 14:51:39 -04006507 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6508 * @phba: pointer to lpfc hba data structure.
6509 *
6510 * This routine is invoked to set up the driver internal resources specific to
6511 * support the SLI-4 HBA device it attached to.
6512 *
6513 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006514 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04006515 * other values - error
6516 **/
6517static int
6518lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
6519{
James Smart28baac72010-02-12 14:42:03 -05006520 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08006521 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08006522 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05006523 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
6524 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04006525 int longs;
James Smart81e6a632017-11-20 16:00:43 -08006526 int extra;
James Smartf358dd02017-02-12 13:52:34 -08006527 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07006528 u32 if_type;
6529 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04006530
James Smart895427b2017-02-12 13:52:30 -08006531 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smarteede4972019-11-21 09:55:56 -08006532 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
James Smart895427b2017-02-12 13:52:30 -08006533 phba->sli4_hba.curr_disp_cpu = 0;
6534
James Smart716d3bc2013-09-06 12:18:28 -04006535 /* Get all the module params for configuring this host */
6536 lpfc_get_cfgparam(phba);
6537
James Smart895427b2017-02-12 13:52:30 -08006538 /* Set up phase-1 common device driver resources */
6539 rc = lpfc_setup_driver_resource_phase1(phba);
6540 if (rc)
6541 return -ENODEV;
6542
James Smartda0436e2009-05-22 14:51:39 -04006543 /* Before proceed, wait for POST done and device ready */
6544 rc = lpfc_sli4_post_status_check(phba);
6545 if (rc)
6546 return -ENODEV;
6547
James Smart3cee98d2019-08-14 16:56:34 -07006548 /* Allocate all driver workqueues here */
6549
6550 /* The lpfc_wq workqueue for deferred irq use */
6551 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6552
James Smartda0436e2009-05-22 14:51:39 -04006553 /*
6554 * Initialize timers used by driver
6555 */
6556
Kees Cookf22eb4d2017-09-06 20:24:26 -07006557 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04006558
James Smartecfd03c2010-02-12 14:41:27 -05006559 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006560 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05006561
James Smartda0436e2009-05-22 14:51:39 -04006562 /*
James Smart7ad20aa2011-05-24 11:44:28 -04006563 * Control structure for handling external multi-buffer mailbox
6564 * command pass-through.
6565 */
6566 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
6567 sizeof(struct lpfc_mbox_ext_buf_ctx));
6568 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
6569
James Smartda0436e2009-05-22 14:51:39 -04006570 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04006571
James Smartda0436e2009-05-22 14:51:39 -04006572 /* This will be set to correct value after the read_config mbox */
6573 phba->max_vports = 0;
6574
6575 /* Program the default value of vlan_id and fc_map */
6576 phba->valid_vlan = 0;
6577 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
6578 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
6579 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
6580
6581 /*
James Smart2a76a282012-08-03 12:35:54 -04006582 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08006583 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6584 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04006585 */
James Smart085c6472010-11-20 23:11:37 -05006586
James Smartda0436e2009-05-22 14:51:39 -04006587 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006588 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006589 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6590 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6591
6592 /*
6593 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6594 */
James Smartc00f62e2019-08-14 16:57:11 -07006595 /* Initialize the Abort buffer list used by driver */
6596 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
6597 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
James Smart895427b2017-02-12 13:52:30 -08006598
6599 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6600 /* Initialize the Abort nvme buffer list used by driver */
James Smart5e5b5112019-01-28 11:14:22 -08006601 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07006602 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006603 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart79d8c4c2019-05-21 17:48:56 -07006604 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
6605 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
James Smart895427b2017-02-12 13:52:30 -08006606 }
6607
James Smartda0436e2009-05-22 14:51:39 -04006608 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006609 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006610 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smarte7dab162020-10-20 13:27:12 -07006611 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
6612 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006613
6614 /*
James Smart6d368e52011-05-24 11:44:12 -04006615 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006616 */
6617
6618 /* Driver internel slow-path CQ Event pool */
6619 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6620 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006621 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006622 /* Asynchronous event CQ Event work queue list */
6623 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
James Smartda0436e2009-05-22 14:51:39 -04006624 /* Slow-path XRI aborted CQ Event work queue list */
6625 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6626 /* Receive queue CQ Event work queue list */
6627 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6628
James Smart6d368e52011-05-24 11:44:12 -04006629 /* Initialize extent block lists. */
6630 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6631 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6632 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6633 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6634
James Smartd1f525a2017-04-21 16:04:55 -07006635 /* Initialize mboxq lists. If the early init routines fail
6636 * these lists need to be correctly initialized.
6637 */
6638 INIT_LIST_HEAD(&phba->sli.mboxq);
6639 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6640
James Smart448193b2015-12-16 18:12:05 -05006641 /* initialize optic_state to 0xFF */
6642 phba->sli4_hba.lnk_info.optic_state = 0xff;
6643
James Smartda0436e2009-05-22 14:51:39 -04006644 /* Allocate device driver memory */
6645 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6646 if (rc)
6647 return -ENOMEM;
6648
James Smart2fcee4b2010-12-15 17:57:46 -05006649 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006650 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006651 LPFC_SLI_INTF_IF_TYPE_2) {
6652 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006653 if (unlikely(rc)) {
6654 rc = -ENODEV;
6655 goto out_free_mem;
6656 }
James Smart946727d2015-04-07 15:07:09 -04006657 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006658 }
6659
James Smartda0436e2009-05-22 14:51:39 -04006660 /* Create the bootstrap mailbox command */
6661 rc = lpfc_create_bootstrap_mbox(phba);
6662 if (unlikely(rc))
6663 goto out_free_mem;
6664
6665 /* Set up the host's endian order with the device. */
6666 rc = lpfc_setup_endian_order(phba);
6667 if (unlikely(rc))
6668 goto out_free_bsmbx;
6669
6670 /* Set up the hba's configuration parameters. */
6671 rc = lpfc_sli4_read_config(phba);
6672 if (unlikely(rc))
6673 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006674 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6675 if (unlikely(rc))
6676 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006677
James Smart2fcee4b2010-12-15 17:57:46 -05006678 /* IF Type 0 ports get initialized now. */
6679 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6680 LPFC_SLI_INTF_IF_TYPE_0) {
6681 rc = lpfc_pci_function_reset(phba);
6682 if (unlikely(rc))
6683 goto out_free_bsmbx;
6684 }
James Smartda0436e2009-05-22 14:51:39 -04006685
James Smartcb5172e2010-03-15 11:25:07 -04006686 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6687 GFP_KERNEL);
6688 if (!mboxq) {
6689 rc = -ENOMEM;
6690 goto out_free_bsmbx;
6691 }
6692
James Smartf358dd02017-02-12 13:52:34 -08006693 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006694 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006695 if (lpfc_enable_nvmet_cnt) {
6696
6697 /* First get WWN of HBA instance */
6698 lpfc_read_nv(phba, mboxq);
6699 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6700 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006701 lpfc_printf_log(phba, KERN_ERR,
6702 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08006703 "6016 Mailbox failed , mbxCmd x%x "
6704 "READ_NV, mbxStatus x%x\n",
6705 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6706 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006707 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006708 rc = -EIO;
6709 goto out_free_bsmbx;
6710 }
6711 mb = &mboxq->u.mb;
6712 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6713 sizeof(uint64_t));
6714 wwn = cpu_to_be64(wwn);
6715 phba->sli4_hba.wwnn.u.name = wwn;
6716 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6717 sizeof(uint64_t));
6718 /* wwn is WWPN of HBA instance */
6719 wwn = cpu_to_be64(wwn);
6720 phba->sli4_hba.wwpn.u.name = wwn;
6721
6722 /* Check to see if it matches any module parameter */
6723 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6724 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006725#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006726 if (lpfc_nvmet_mem_alloc(phba))
6727 break;
6728
6729 phba->nvmet_support = 1; /* a match */
6730
Dick Kennedy372c1872020-06-30 14:50:00 -07006731 lpfc_printf_log(phba, KERN_ERR,
6732 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08006733 "6017 NVME Target %016llx\n",
6734 wwn);
James Smart7d708032017-03-08 14:36:01 -08006735#else
Dick Kennedy372c1872020-06-30 14:50:00 -07006736 lpfc_printf_log(phba, KERN_ERR,
6737 LOG_TRACE_EVENT,
James Smart7d708032017-03-08 14:36:01 -08006738 "6021 Can't enable NVME Target."
6739 " NVME_TARGET_FC infrastructure"
6740 " is not in kernel\n");
6741#endif
James Smartc4908502019-01-28 11:14:28 -08006742 /* Not supported for NVMET */
6743 phba->cfg_xri_rebalancing = 0;
Dick Kennedy3048e3e2020-05-01 14:43:06 -07006744 if (phba->irq_chann_mode == NHT_MODE) {
6745 phba->cfg_irq_chann =
6746 phba->sli4_hba.num_present_cpu;
6747 phba->cfg_hdw_queue =
6748 phba->sli4_hba.num_present_cpu;
6749 phba->irq_chann_mode = NORMAL_MODE;
6750 }
James Smart3c603be2017-05-15 15:20:44 -07006751 break;
James Smartf358dd02017-02-12 13:52:34 -08006752 }
6753 }
6754 }
James Smart895427b2017-02-12 13:52:30 -08006755
6756 lpfc_nvme_mod_param_dep(phba);
6757
James Smartfedd3b72011-02-16 12:39:24 -05006758 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006759 lpfc_supported_pages(mboxq);
6760 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006761 if (!rc) {
6762 mqe = &mboxq->u.mqe;
6763 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6764 LPFC_MAX_SUPPORTED_PAGES);
6765 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6766 switch (pn_page[i]) {
6767 case LPFC_SLI4_PARAMETERS:
6768 phba->sli4_hba.pc_sli4_params.supported = 1;
6769 break;
6770 default:
6771 break;
6772 }
6773 }
6774 /* Read the port's SLI4 Parameters capabilities if supported. */
6775 if (phba->sli4_hba.pc_sli4_params.supported)
6776 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6777 if (rc) {
6778 mempool_free(mboxq, phba->mbox_mem_pool);
6779 rc = -EIO;
6780 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006781 }
6782 }
James Smart65791f12016-07-06 12:35:56 -07006783
James Smartfedd3b72011-02-16 12:39:24 -05006784 /*
6785 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006786 * If this call fails, it isn't critical unless the SLI4 parameters come
6787 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006788 */
James Smart6d368e52011-05-24 11:44:12 -04006789 rc = lpfc_get_sli4_parameters(phba, mboxq);
6790 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006791 if_type = bf_get(lpfc_sli_intf_if_type,
6792 &phba->sli4_hba.sli_intf);
6793 if_fam = bf_get(lpfc_sli_intf_sli_family,
6794 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006795 if (phba->sli4_hba.extents_in_use &&
6796 phba->sli4_hba.rpi_hdrs_in_use) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006797 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6798 "2999 Unsupported SLI4 Parameters "
6799 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006800 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6801 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6802 mempool_free(mboxq, phba->mbox_mem_pool);
6803 rc = -EIO;
6804 goto out_free_bsmbx;
6805 }
James Smart6d368e52011-05-24 11:44:12 -04006806 }
James Smartb92dc722018-05-24 21:09:01 -07006807 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6808 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6809 mempool_free(mboxq, phba->mbox_mem_pool);
6810 rc = -EIO;
6811 goto out_free_bsmbx;
6812 }
James Smart6d368e52011-05-24 11:44:12 -04006813 }
James Smart895427b2017-02-12 13:52:30 -08006814
James Smartd79c9e92019-08-14 16:57:09 -07006815 /*
6816 * 1 for cmd, 1 for rsp, NVME adds an extra one
6817 * for boundary conditions in its max_sgl_segment template.
6818 */
6819 extra = 2;
6820 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
6821 extra++;
6822
6823 /*
6824 * It doesn't matter what family our adapter is in, we are
6825 * limited to 2 Pages, 512 SGEs, for our SGL.
6826 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6827 */
6828 max_buf_size = (2 * SLI4_PAGE_SIZE);
6829
6830 /*
6831 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6832 * used to create the sg_dma_buf_pool must be calculated.
6833 */
6834 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
6835 /* Both cfg_enable_bg and cfg_external_dif code paths */
6836
6837 /*
6838 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6839 * the FCP rsp, and a SGE. Sice we have no control
6840 * over how many protection segments the SCSI Layer
6841 * will hand us (ie: there could be one for every block
6842 * in the IO), just allocate enough SGEs to accomidate
6843 * our max amount and we need to limit lpfc_sg_seg_cnt
6844 * to minimize the risk of running out.
6845 */
6846 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6847 sizeof(struct fcp_rsp) + max_buf_size;
6848
6849 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6850 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
6851
6852 /*
6853 * If supporting DIF, reduce the seg count for scsi to
6854 * allow room for the DIF sges.
6855 */
6856 if (phba->cfg_enable_bg &&
6857 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
6858 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
6859 else
6860 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6861
6862 } else {
6863 /*
6864 * The scsi_buf for a regular I/O holds the FCP cmnd,
6865 * the FCP rsp, a SGE for each, and a SGE for up to
6866 * cfg_sg_seg_cnt data segments.
6867 */
6868 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6869 sizeof(struct fcp_rsp) +
6870 ((phba->cfg_sg_seg_cnt + extra) *
6871 sizeof(struct sli4_sge));
6872
6873 /* Total SGEs for scsi_sg_list */
6874 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
6875 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6876
6877 /*
6878 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
6879 * need to post 1 page for the SGL.
6880 */
6881 }
6882
6883 if (phba->cfg_xpsgl && !phba->nvmet_support)
6884 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
6885 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
6886 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6887 else
6888 phba->cfg_sg_dma_buf_size =
6889 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6890
6891 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
6892 sizeof(struct sli4_sge);
6893
6894 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6895 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6896 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
6897 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
6898 "6300 Reducing NVME sg segment "
6899 "cnt to %d\n",
6900 LPFC_MAX_NVME_SEG_CNT);
6901 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6902 } else
6903 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
6904 }
6905
James Smartd79c9e92019-08-14 16:57:09 -07006906 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
6907 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6908 "total:%d scsi:%d nvme:%d\n",
6909 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6910 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6911 phba->cfg_nvme_seg_cnt);
6912
6913 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
6914 i = phba->cfg_sg_dma_buf_size;
6915 else
6916 i = SLI4_PAGE_SIZE;
6917
6918 phba->lpfc_sg_dma_buf_pool =
6919 dma_pool_create("lpfc_sg_dma_buf_pool",
6920 &phba->pcidev->dev,
6921 phba->cfg_sg_dma_buf_size,
6922 i, 0);
6923 if (!phba->lpfc_sg_dma_buf_pool)
6924 goto out_free_bsmbx;
6925
6926 phba->lpfc_cmd_rsp_buf_pool =
6927 dma_pool_create("lpfc_cmd_rsp_buf_pool",
6928 &phba->pcidev->dev,
6929 sizeof(struct fcp_cmnd) +
6930 sizeof(struct fcp_rsp),
6931 i, 0);
6932 if (!phba->lpfc_cmd_rsp_buf_pool)
6933 goto out_free_sg_dma_buf;
6934
James Smartcb5172e2010-03-15 11:25:07 -04006935 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006936
6937 /* Verify OAS is supported */
6938 lpfc_sli4_oas_verify(phba);
James Smart1ba981f2014-02-20 09:56:45 -05006939
James Smartd2cc9bc2018-09-10 10:30:50 -07006940 /* Verify RAS support on adapter */
6941 lpfc_sli4_ras_init(phba);
6942
James Smart5350d872011-10-10 21:33:49 -04006943 /* Verify all the SLI4 queues */
6944 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006945 if (rc)
James Smartd79c9e92019-08-14 16:57:09 -07006946 goto out_free_cmd_rsp_buf;
James Smartda0436e2009-05-22 14:51:39 -04006947
6948 /* Create driver internal CQE event pool */
6949 rc = lpfc_sli4_cq_event_pool_create(phba);
6950 if (rc)
James Smartd79c9e92019-08-14 16:57:09 -07006951 goto out_free_cmd_rsp_buf;
James Smartda0436e2009-05-22 14:51:39 -04006952
James Smart8a9d2e82012-05-09 21:16:12 -04006953 /* Initialize sgl lists per host */
6954 lpfc_init_sgl_list(phba);
6955
6956 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006957 rc = lpfc_init_active_sgl_array(phba);
6958 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006959 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04006960 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006961 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006962 }
James Smartda0436e2009-05-22 14:51:39 -04006963 rc = lpfc_sli4_init_rpi_hdrs(phba);
6964 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006965 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04006966 "1432 Failed to initialize rpi headers.\n");
6967 goto out_free_active_sgl;
6968 }
6969
James Smarta93ff372010-10-22 11:06:08 -04006970 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006971 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006972 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006973 GFP_KERNEL);
6974 if (!phba->fcf.fcf_rr_bmask) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006975 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05006976 "2759 Failed allocate memory for FCF round "
6977 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006978 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006979 goto out_remove_rpi_hdrs;
6980 }
6981
James Smart6a828b02019-01-28 11:14:31 -08006982 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08006983 sizeof(struct lpfc_hba_eq_hdl),
6984 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006985 if (!phba->sli4_hba.hba_eq_hdl) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006986 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart67d12732012-08-03 12:36:13 -04006987 "2572 Failed allocate memory for "
6988 "fast-path per-EQ handle array\n");
6989 rc = -ENOMEM;
6990 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006991 }
6992
James Smart222e9232019-01-28 11:14:35 -08006993 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
James Smart895427b2017-02-12 13:52:30 -08006994 sizeof(struct lpfc_vector_map_info),
6995 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006996 if (!phba->sli4_hba.cpu_map) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006997 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7bb03bb2013-04-17 20:19:16 -04006998 "3327 Failed allocate memory for msi-x "
6999 "interrupt vector mapping\n");
7000 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08007001 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04007002 }
James Smartb246de12013-05-31 17:03:07 -04007003
James Smart32517fc2019-01-28 11:14:33 -08007004 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
7005 if (!phba->sli4_hba.eq_info) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007006 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart32517fc2019-01-28 11:14:33 -08007007 "3321 Failed allocation for per_cpu stats\n");
7008 rc = -ENOMEM;
7009 goto out_free_hba_cpu_map;
7010 }
James Smart840eda92020-03-22 11:13:00 -07007011
Dick Kennedy317aeb82020-06-30 14:49:59 -07007012 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
7013 sizeof(*phba->sli4_hba.idle_stat),
7014 GFP_KERNEL);
7015 if (!phba->sli4_hba.idle_stat) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007016 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedy317aeb82020-06-30 14:49:59 -07007017 "3390 Failed allocation for idle_stat\n");
7018 rc = -ENOMEM;
7019 goto out_free_hba_eq_info;
7020 }
7021
James Smart840eda92020-03-22 11:13:00 -07007022#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7023 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
7024 if (!phba->sli4_hba.c_stat) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007025 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart840eda92020-03-22 11:13:00 -07007026 "3332 Failed allocating per cpu hdwq stats\n");
7027 rc = -ENOMEM;
Dick Kennedy317aeb82020-06-30 14:49:59 -07007028 goto out_free_hba_idle_stat;
James Smart840eda92020-03-22 11:13:00 -07007029 }
7030#endif
7031
James Smart912e3ac2011-05-24 11:42:11 -04007032 /*
7033 * Enable sr-iov virtual functions if supported and configured
7034 * through the module parameter.
7035 */
7036 if (phba->cfg_sriov_nr_virtfn > 0) {
7037 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7038 phba->cfg_sriov_nr_virtfn);
7039 if (rc) {
7040 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7041 "3020 Requested number of SR-IOV "
7042 "virtual functions (%d) is not "
7043 "supported\n",
7044 phba->cfg_sriov_nr_virtfn);
7045 phba->cfg_sriov_nr_virtfn = 0;
7046 }
7047 }
7048
James Smart5248a742011-07-22 18:37:06 -04007049 return 0;
James Smartda0436e2009-05-22 14:51:39 -04007050
James Smart840eda92020-03-22 11:13:00 -07007051#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
Dick Kennedy317aeb82020-06-30 14:49:59 -07007052out_free_hba_idle_stat:
7053 kfree(phba->sli4_hba.idle_stat);
7054#endif
James Smart840eda92020-03-22 11:13:00 -07007055out_free_hba_eq_info:
7056 free_percpu(phba->sli4_hba.eq_info);
James Smart32517fc2019-01-28 11:14:33 -08007057out_free_hba_cpu_map:
7058 kfree(phba->sli4_hba.cpu_map);
James Smart895427b2017-02-12 13:52:30 -08007059out_free_hba_eq_hdl:
7060 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05007061out_free_fcf_rr_bmask:
7062 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04007063out_remove_rpi_hdrs:
7064 lpfc_sli4_remove_rpi_hdrs(phba);
7065out_free_active_sgl:
7066 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04007067out_destroy_cq_event_pool:
7068 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartd79c9e92019-08-14 16:57:09 -07007069out_free_cmd_rsp_buf:
7070 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
7071 phba->lpfc_cmd_rsp_buf_pool = NULL;
7072out_free_sg_dma_buf:
7073 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7074 phba->lpfc_sg_dma_buf_pool = NULL;
James Smartda0436e2009-05-22 14:51:39 -04007075out_free_bsmbx:
7076 lpfc_destroy_bootstrap_mbox(phba);
7077out_free_mem:
7078 lpfc_mem_free(phba);
7079 return rc;
7080}
7081
7082/**
7083 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
7084 * @phba: pointer to lpfc hba data structure.
7085 *
7086 * This routine is invoked to unset the driver internal resources set up
7087 * specific for supporting the SLI-4 HBA device it attached to.
7088 **/
7089static void
7090lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
7091{
7092 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7093
James Smart32517fc2019-01-28 11:14:33 -08007094 free_percpu(phba->sli4_hba.eq_info);
James Smart840eda92020-03-22 11:13:00 -07007095#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
7096 free_percpu(phba->sli4_hba.c_stat);
7097#endif
Dick Kennedy317aeb82020-06-30 14:49:59 -07007098 kfree(phba->sli4_hba.idle_stat);
James Smart32517fc2019-01-28 11:14:33 -08007099
James Smart7bb03bb2013-04-17 20:19:16 -04007100 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
7101 kfree(phba->sli4_hba.cpu_map);
James Smart222e9232019-01-28 11:14:35 -08007102 phba->sli4_hba.num_possible_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007103 phba->sli4_hba.num_present_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05007104 phba->sli4_hba.curr_disp_cpu = 0;
Dick Kennedy3048e3e2020-05-01 14:43:06 -07007105 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
James Smart7bb03bb2013-04-17 20:19:16 -04007106
James Smartda0436e2009-05-22 14:51:39 -04007107 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08007108 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04007109
7110 /* Free the allocated rpi headers. */
7111 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04007112 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04007113
James Smart0c9ab6f2010-02-26 14:15:57 -05007114 /* Free eligible FCF index bmask */
7115 kfree(phba->fcf.fcf_rr_bmask);
7116
James Smartda0436e2009-05-22 14:51:39 -04007117 /* Free the ELS sgl list */
7118 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04007119 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08007120 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04007121
James Smartda0436e2009-05-22 14:51:39 -04007122 /* Free the completion queue EQ event pool */
7123 lpfc_sli4_cq_event_release_all(phba);
7124 lpfc_sli4_cq_event_pool_destroy(phba);
7125
James Smart6d368e52011-05-24 11:44:12 -04007126 /* Release resource identifiers. */
7127 lpfc_sli4_dealloc_resource_identifiers(phba);
7128
James Smartda0436e2009-05-22 14:51:39 -04007129 /* Free the bsmbx region. */
7130 lpfc_destroy_bootstrap_mbox(phba);
7131
7132 /* Free the SLI Layer memory with SLI4 HBAs */
7133 lpfc_mem_free_all(phba);
7134
7135 /* Free the current connect table */
7136 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04007137 &phba->fcf_conn_rec_list, list) {
7138 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04007139 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04007140 }
James Smartda0436e2009-05-22 14:51:39 -04007141
7142 return;
7143}
7144
7145/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007146 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04007147 * @phba: The hba struct for which this call is being executed.
7148 * @dev_grp: The HBA PCI-Device group number.
7149 *
7150 * This routine sets up the device INIT interface API function jump table
7151 * in @phba struct.
7152 *
7153 * Returns: 0 - success, -ENODEV - failure.
7154 **/
7155int
7156lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
7157{
James Smart84d1b002010-02-12 14:42:33 -05007158 phba->lpfc_hba_init_link = lpfc_hba_init_link;
7159 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05007160 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04007161 switch (dev_grp) {
7162 case LPFC_PCI_DEV_LP:
7163 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
7164 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
7165 phba->lpfc_stop_port = lpfc_stop_port_s3;
7166 break;
James Smartda0436e2009-05-22 14:51:39 -04007167 case LPFC_PCI_DEV_OC:
7168 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
7169 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
7170 phba->lpfc_stop_port = lpfc_stop_port_s4;
7171 break;
James Smart3772a992009-05-22 14:50:54 -04007172 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07007173 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -04007174 "1431 Invalid HBA PCI-device group: 0x%x\n",
7175 dev_grp);
7176 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007177 }
7178 return 0;
7179}
7180
7181/**
James Smart3772a992009-05-22 14:50:54 -04007182 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
7183 * @phba: pointer to lpfc hba data structure.
7184 *
7185 * This routine is invoked to set up the driver internal resources after the
7186 * device specific resource setup to support the HBA device it attached to.
7187 *
7188 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007189 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007190 * other values - error
7191 **/
7192static int
7193lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
7194{
7195 int error;
7196
7197 /* Startup the kernel thread for this host adapter. */
7198 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7199 "lpfc_worker_%d", phba->brd_no);
7200 if (IS_ERR(phba->worker_thread)) {
7201 error = PTR_ERR(phba->worker_thread);
7202 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007203 }
7204
James Smart3772a992009-05-22 14:50:54 -04007205 return 0;
7206}
7207
7208/**
7209 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7210 * @phba: pointer to lpfc hba data structure.
7211 *
7212 * This routine is invoked to unset the driver internal resources set up after
7213 * the device specific resource setup for supporting the HBA device it
7214 * attached to.
7215 **/
7216static void
7217lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
7218{
Dick Kennedyf485c182017-09-29 17:34:34 -07007219 if (phba->wq) {
7220 flush_workqueue(phba->wq);
7221 destroy_workqueue(phba->wq);
7222 phba->wq = NULL;
7223 }
7224
James Smart3772a992009-05-22 14:50:54 -04007225 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07007226 if (phba->worker_thread)
7227 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04007228}
7229
7230/**
7231 * lpfc_free_iocb_list - Free iocb list.
7232 * @phba: pointer to lpfc hba data structure.
7233 *
7234 * This routine is invoked to free the driver's IOCB list and memory.
7235 **/
James Smart6c621a22017-05-15 15:20:45 -07007236void
James Smart3772a992009-05-22 14:50:54 -04007237lpfc_free_iocb_list(struct lpfc_hba *phba)
7238{
7239 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
7240
7241 spin_lock_irq(&phba->hbalock);
7242 list_for_each_entry_safe(iocbq_entry, iocbq_next,
7243 &phba->lpfc_iocb_list, list) {
7244 list_del(&iocbq_entry->list);
7245 kfree(iocbq_entry);
7246 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007247 }
James Smart3772a992009-05-22 14:50:54 -04007248 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007249
James Smart3772a992009-05-22 14:50:54 -04007250 return;
7251}
dea31012005-04-17 16:05:31 -05007252
James Smart3772a992009-05-22 14:50:54 -04007253/**
7254 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7255 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01007256 * @iocb_count: number of requested iocbs
James Smart3772a992009-05-22 14:50:54 -04007257 *
7258 * This routine is invoked to allocate and initizlize the driver's IOCB
7259 * list and set up the IOCB tag array accordingly.
7260 *
7261 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007262 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007263 * other values - error
7264 **/
James Smart6c621a22017-05-15 15:20:45 -07007265int
James Smart3772a992009-05-22 14:50:54 -04007266lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
7267{
7268 struct lpfc_iocbq *iocbq_entry = NULL;
7269 uint16_t iotag;
7270 int i;
dea31012005-04-17 16:05:31 -05007271
7272 /* Initialize and populate the iocb list per host. */
7273 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04007274 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07007275 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05007276 if (iocbq_entry == NULL) {
7277 printk(KERN_ERR "%s: only allocated %d iocbs of "
7278 "expected %d count. Unloading driver.\n",
James Smarta5f73372019-09-21 20:58:50 -07007279 __func__, i, iocb_count);
dea31012005-04-17 16:05:31 -05007280 goto out_free_iocbq;
7281 }
7282
James Bottomley604a3e32005-10-29 10:28:33 -05007283 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
7284 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04007285 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05007286 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04007287 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05007288 goto out_free_iocbq;
7289 }
James Smart6d368e52011-05-24 11:44:12 -04007290 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04007291 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05007292
7293 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007294 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
7295 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05007296 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007297 }
7298
James Smart3772a992009-05-22 14:50:54 -04007299 return 0;
7300
7301out_free_iocbq:
7302 lpfc_free_iocb_list(phba);
7303
7304 return -ENOMEM;
7305}
7306
7307/**
James Smart8a9d2e82012-05-09 21:16:12 -04007308 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007309 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04007310 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007311 *
James Smart8a9d2e82012-05-09 21:16:12 -04007312 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04007313 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007314void
7315lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04007316{
7317 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04007318
7319 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
7320 list_del(&sglq_entry->list);
7321 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
7322 kfree(sglq_entry);
7323 }
7324}
7325
7326/**
7327 * lpfc_free_els_sgl_list - Free els sgl list.
7328 * @phba: pointer to lpfc hba data structure.
7329 *
7330 * This routine is invoked to free the driver's els sgl list and memory.
7331 **/
7332static void
7333lpfc_free_els_sgl_list(struct lpfc_hba *phba)
7334{
James Smartda0436e2009-05-22 14:51:39 -04007335 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007336
James Smart8a9d2e82012-05-09 21:16:12 -04007337 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04007338 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007339 spin_lock(&phba->sli4_hba.sgl_list_lock);
7340 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
7341 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04007342 spin_unlock_irq(&phba->hbalock);
7343
James Smart8a9d2e82012-05-09 21:16:12 -04007344 /* Now free the sgl list */
7345 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007346}
7347
7348/**
James Smartf358dd02017-02-12 13:52:34 -08007349 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
7350 * @phba: pointer to lpfc hba data structure.
7351 *
7352 * This routine is invoked to free the driver's nvmet sgl list and memory.
7353 **/
7354static void
7355lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
7356{
7357 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7358 LIST_HEAD(sglq_list);
7359
7360 /* Retrieve all nvmet sgls from driver list */
7361 spin_lock_irq(&phba->hbalock);
7362 spin_lock(&phba->sli4_hba.sgl_list_lock);
7363 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
7364 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7365 spin_unlock_irq(&phba->hbalock);
7366
7367 /* Now free the sgl list */
7368 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
7369 list_del(&sglq_entry->list);
7370 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
7371 kfree(sglq_entry);
7372 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07007373
7374 /* Update the nvmet_xri_cnt to reflect no current sgls.
7375 * The next initialization cycle sets the count and allocates
7376 * the sgls over again.
7377 */
7378 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08007379}
7380
7381/**
James Smartda0436e2009-05-22 14:51:39 -04007382 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
7383 * @phba: pointer to lpfc hba data structure.
7384 *
7385 * This routine is invoked to allocate the driver's active sgl memory.
7386 * This array will hold the sglq_entry's for active IOs.
7387 **/
7388static int
7389lpfc_init_active_sgl_array(struct lpfc_hba *phba)
7390{
7391 int size;
7392 size = sizeof(struct lpfc_sglq *);
7393 size *= phba->sli4_hba.max_cfg_param.max_xri;
7394
7395 phba->sli4_hba.lpfc_sglq_active_list =
7396 kzalloc(size, GFP_KERNEL);
7397 if (!phba->sli4_hba.lpfc_sglq_active_list)
7398 return -ENOMEM;
7399 return 0;
7400}
7401
7402/**
7403 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
7404 * @phba: pointer to lpfc hba data structure.
7405 *
7406 * This routine is invoked to walk through the array of active sglq entries
7407 * and free all of the resources.
7408 * This is just a place holder for now.
7409 **/
7410static void
7411lpfc_free_active_sgl(struct lpfc_hba *phba)
7412{
7413 kfree(phba->sli4_hba.lpfc_sglq_active_list);
7414}
7415
7416/**
7417 * lpfc_init_sgl_list - Allocate and initialize sgl list.
7418 * @phba: pointer to lpfc hba data structure.
7419 *
7420 * This routine is invoked to allocate and initizlize the driver's sgl
7421 * list and set up the sgl xritag tag array accordingly.
7422 *
James Smartda0436e2009-05-22 14:51:39 -04007423 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007424static void
James Smartda0436e2009-05-22 14:51:39 -04007425lpfc_init_sgl_list(struct lpfc_hba *phba)
7426{
James Smartda0436e2009-05-22 14:51:39 -04007427 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08007428 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04007429 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08007430 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07007431 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04007432
James Smart8a9d2e82012-05-09 21:16:12 -04007433 /* els xri-sgl book keeping */
7434 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007435
James Smart895427b2017-02-12 13:52:30 -08007436 /* nvme xri-buffer book keeping */
James Smart5e5b5112019-01-28 11:14:22 -08007437 phba->sli4_hba.io_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007438}
7439
7440/**
7441 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
7442 * @phba: pointer to lpfc hba data structure.
7443 *
7444 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04007445 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04007446 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04007447 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
7448 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04007449 *
7450 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007451 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04007452 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04007453 **/
7454int
7455lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
7456{
7457 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007458 struct lpfc_rpi_hdr *rpi_hdr;
7459
7460 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05007461 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04007462 return rc;
James Smart6d368e52011-05-24 11:44:12 -04007463 if (phba->sli4_hba.extents_in_use)
7464 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04007465
7466 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
7467 if (!rpi_hdr) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007468 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04007469 "0391 Error during rpi post operation\n");
7470 lpfc_sli4_remove_rpis(phba);
7471 rc = -ENODEV;
7472 }
7473
7474 return rc;
7475}
7476
7477/**
7478 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
7479 * @phba: pointer to lpfc hba data structure.
7480 *
7481 * This routine is invoked to allocate a single 4KB memory region to
7482 * support rpis and stores them in the phba. This single region
7483 * provides support for up to 64 rpis. The region is used globally
7484 * by the device.
7485 *
7486 * Returns:
7487 * A valid rpi hdr on success.
7488 * A NULL pointer on any failure.
7489 **/
7490struct lpfc_rpi_hdr *
7491lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
7492{
7493 uint16_t rpi_limit, curr_rpi_range;
7494 struct lpfc_dmabuf *dmabuf;
7495 struct lpfc_rpi_hdr *rpi_hdr;
7496
James Smart6d368e52011-05-24 11:44:12 -04007497 /*
7498 * If the SLI4 port supports extents, posting the rpi header isn't
7499 * required. Set the expected maximum count and let the actual value
7500 * get set when extents are fully allocated.
7501 */
7502 if (!phba->sli4_hba.rpi_hdrs_in_use)
7503 return NULL;
7504 if (phba->sli4_hba.extents_in_use)
7505 return NULL;
7506
7507 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07007508 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007509
7510 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007511 /*
7512 * Establish the starting RPI in this header block. The starting
7513 * rpi is normalized to a zero base because the physical rpi is
7514 * port based.
7515 */
James Smart97f2ecf2012-03-01 22:35:23 -05007516 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007517 spin_unlock_irq(&phba->hbalock);
7518
James Smart845d9e82017-05-15 15:20:38 -07007519 /* Reached full RPI range */
7520 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04007521 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07007522
James Smartda0436e2009-05-22 14:51:39 -04007523 /*
7524 * First allocate the protocol header region for the port. The
7525 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
7526 */
7527 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7528 if (!dmabuf)
7529 return NULL;
7530
Luis Chamberlain750afb02019-01-04 09:23:09 +01007531 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
7532 LPFC_HDR_TEMPLATE_SIZE,
7533 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007534 if (!dmabuf->virt) {
7535 rpi_hdr = NULL;
7536 goto err_free_dmabuf;
7537 }
7538
James Smartda0436e2009-05-22 14:51:39 -04007539 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
7540 rpi_hdr = NULL;
7541 goto err_free_coherent;
7542 }
7543
7544 /* Save the rpi header data for cleanup later. */
7545 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
7546 if (!rpi_hdr)
7547 goto err_free_coherent;
7548
7549 rpi_hdr->dmabuf = dmabuf;
7550 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
7551 rpi_hdr->page_count = 1;
7552 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007553
7554 /* The rpi_hdr stores the logical index only. */
7555 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07007556 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04007557 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
7558
James Smartda0436e2009-05-22 14:51:39 -04007559 spin_unlock_irq(&phba->hbalock);
7560 return rpi_hdr;
7561
7562 err_free_coherent:
7563 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
7564 dmabuf->virt, dmabuf->phys);
7565 err_free_dmabuf:
7566 kfree(dmabuf);
7567 return NULL;
7568}
7569
7570/**
7571 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7572 * @phba: pointer to lpfc hba data structure.
7573 *
7574 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04007575 * to support rpis for SLI4 ports not supporting extents. This routine
7576 * presumes the caller has released all rpis consumed by fabric or port
7577 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04007578 **/
7579void
7580lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
7581{
7582 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
7583
James Smart6d368e52011-05-24 11:44:12 -04007584 if (!phba->sli4_hba.rpi_hdrs_in_use)
7585 goto exit;
7586
James Smartda0436e2009-05-22 14:51:39 -04007587 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
7588 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
7589 list_del(&rpi_hdr->list);
7590 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
7591 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
7592 kfree(rpi_hdr->dmabuf);
7593 kfree(rpi_hdr);
7594 }
James Smart6d368e52011-05-24 11:44:12 -04007595 exit:
7596 /* There are no rpis available to the port now. */
7597 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04007598}
7599
7600/**
James Smart3772a992009-05-22 14:50:54 -04007601 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7602 * @pdev: pointer to pci device data structure.
7603 *
7604 * This routine is invoked to allocate the driver hba data structure for an
7605 * HBA device. If the allocation is successful, the phba reference to the
7606 * PCI device data structure is set.
7607 *
7608 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007609 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04007610 * NULL - error
7611 **/
7612static struct lpfc_hba *
7613lpfc_hba_alloc(struct pci_dev *pdev)
7614{
7615 struct lpfc_hba *phba;
7616
7617 /* Allocate memory for HBA structure */
7618 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
7619 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02007620 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04007621 return NULL;
7622 }
7623
7624 /* Set reference to PCI device in HBA structure */
7625 phba->pcidev = pdev;
7626
7627 /* Assign an unused board number */
7628 phba->brd_no = lpfc_get_instance();
7629 if (phba->brd_no < 0) {
7630 kfree(phba);
7631 return NULL;
7632 }
James Smart65791f12016-07-06 12:35:56 -07007633 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04007634
James Smart4fede782010-01-26 23:08:55 -05007635 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04007636 INIT_LIST_HEAD(&phba->ct_ev_waiters);
7637
James Smart3772a992009-05-22 14:50:54 -04007638 return phba;
7639}
7640
7641/**
7642 * lpfc_hba_free - Free driver hba data structure with a device.
7643 * @phba: pointer to lpfc hba data structure.
7644 *
7645 * This routine is invoked to free the driver hba data structure with an
7646 * HBA device.
7647 **/
7648static void
7649lpfc_hba_free(struct lpfc_hba *phba)
7650{
James Smart5e5b5112019-01-28 11:14:22 -08007651 if (phba->sli_rev == LPFC_SLI_REV4)
7652 kfree(phba->sli4_hba.hdwq);
7653
James Smart3772a992009-05-22 14:50:54 -04007654 /* Release the driver assigned board number */
7655 idr_remove(&lpfc_hba_index, phba->brd_no);
7656
James Smart895427b2017-02-12 13:52:30 -08007657 /* Free memory allocated with sli3 rings */
7658 kfree(phba->sli.sli3_ring);
7659 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04007660
James Smart3772a992009-05-22 14:50:54 -04007661 kfree(phba);
7662 return;
7663}
7664
7665/**
7666 * lpfc_create_shost - Create hba physical port with associated scsi host.
7667 * @phba: pointer to lpfc hba data structure.
7668 *
7669 * This routine is invoked to create HBA physical port and associate a SCSI
7670 * host with it.
7671 *
7672 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007673 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007674 * other values - error
7675 **/
7676static int
7677lpfc_create_shost(struct lpfc_hba *phba)
7678{
7679 struct lpfc_vport *vport;
7680 struct Scsi_Host *shost;
7681
7682 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05007683 phba->fc_edtov = FF_DEF_EDTOV;
7684 phba->fc_ratov = FF_DEF_RATOV;
7685 phba->fc_altov = FF_DEF_ALTOV;
7686 phba->fc_arbtov = FF_DEF_ARBTOV;
7687
James Smartd7c47992010-06-08 18:31:54 -04007688 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04007689 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05007690 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04007691 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05007692
7693 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05007694 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08007695
James Smartf358dd02017-02-12 13:52:34 -08007696 if (phba->nvmet_support) {
7697 /* Only 1 vport (pport) will support NVME target */
James Smartea85a202019-10-18 14:18:25 -07007698 phba->targetport = NULL;
7699 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
7700 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
7701 "6076 NVME Target Found\n");
James Smartf358dd02017-02-12 13:52:34 -08007702 }
7703
James Smart858c9f62007-06-17 19:56:39 -05007704 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04007705 /* Put reference to SCSI host to driver's device private data */
7706 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05007707
James Smart4258e982015-12-16 18:11:58 -05007708 /*
7709 * At this point we are fully registered with PSA. In addition,
7710 * any initial discovery should be completed.
7711 */
7712 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07007713 if (phba->cfg_enable_SmartSAN ||
7714 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05007715
7716 /* Setup appropriate attribute masks */
7717 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07007718 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05007719 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
7720 else
7721 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7722 }
James Smart3772a992009-05-22 14:50:54 -04007723 return 0;
7724}
dea31012005-04-17 16:05:31 -05007725
James Smart3772a992009-05-22 14:50:54 -04007726/**
7727 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7728 * @phba: pointer to lpfc hba data structure.
7729 *
7730 * This routine is invoked to destroy HBA physical port and the associated
7731 * SCSI host.
7732 **/
7733static void
7734lpfc_destroy_shost(struct lpfc_hba *phba)
7735{
7736 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007737
James Smart3772a992009-05-22 14:50:54 -04007738 /* Destroy physical port that associated with the SCSI host */
7739 destroy_port(vport);
7740
7741 return;
7742}
7743
7744/**
7745 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7746 * @phba: pointer to lpfc hba data structure.
7747 * @shost: the shost to be used to detect Block guard settings.
7748 *
7749 * This routine sets up the local Block guard protocol settings for @shost.
7750 * This routine also allocates memory for debugging bg buffers.
7751 **/
7752static void
7753lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7754{
James Smartbbeb79b2012-06-12 13:54:27 -04007755 uint32_t old_mask;
7756 uint32_t old_guard;
7757
James Smartb3b98b72016-10-13 15:06:06 -07007758 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007759 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7760 "1478 Registering BlockGuard with the "
7761 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007762
James Smartb3b98b72016-10-13 15:06:06 -07007763 old_mask = phba->cfg_prot_mask;
7764 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007765
7766 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007767 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007768 SHOST_DIX_TYPE0_PROTECTION |
7769 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007770 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7771 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007772
7773 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007774 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7775 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007776
James Smartb3b98b72016-10-13 15:06:06 -07007777 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7778 if ((old_mask != phba->cfg_prot_mask) ||
7779 (old_guard != phba->cfg_prot_guard))
Dick Kennedy372c1872020-06-30 14:50:00 -07007780 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartbbeb79b2012-06-12 13:54:27 -04007781 "1475 Registering BlockGuard with the "
7782 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007783 phba->cfg_prot_mask,
7784 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007785
James Smartb3b98b72016-10-13 15:06:06 -07007786 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7787 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007788 } else
Dick Kennedy372c1872020-06-30 14:50:00 -07007789 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartbbeb79b2012-06-12 13:54:27 -04007790 "1479 Not Registering BlockGuard with the SCSI "
7791 "layer, Bad protection parameters: %d %d\n",
7792 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007793 }
James Smart3772a992009-05-22 14:50:54 -04007794}
7795
7796/**
7797 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7798 * @phba: pointer to lpfc hba data structure.
7799 *
7800 * This routine is invoked to perform all the necessary post initialization
7801 * setup for the device.
7802 **/
7803static void
7804lpfc_post_init_setup(struct lpfc_hba *phba)
7805{
7806 struct Scsi_Host *shost;
7807 struct lpfc_adapter_event_header adapter_event;
7808
7809 /* Get the default values for Model Name and Description */
7810 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7811
7812 /*
7813 * hba setup may have changed the hba_queue_depth so we need to
7814 * adjust the value of can_queue.
7815 */
7816 shost = pci_get_drvdata(phba->pcidev);
7817 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart858c9f62007-06-17 19:56:39 -05007818
7819 lpfc_host_attrib_init(shost);
7820
James Smart2e0fef82007-06-17 19:56:36 -05007821 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7822 spin_lock_irq(shost->host_lock);
7823 lpfc_poll_start_timer(phba);
7824 spin_unlock_irq(shost->host_lock);
7825 }
James Smart8f6d98d2006-08-01 07:34:00 -04007826
James Smart93996272008-08-24 21:50:30 -04007827 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7828 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007829 /* Send board arrival event to upper layer */
7830 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7831 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7832 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007833 sizeof(adapter_event),
7834 (char *) &adapter_event,
7835 LPFC_NL_VENDOR_ID);
7836 return;
7837}
7838
7839/**
7840 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7841 * @phba: pointer to lpfc hba data structure.
7842 *
7843 * This routine is invoked to set up the PCI device memory space for device
7844 * with SLI-3 interface spec.
7845 *
7846 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007847 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007848 * other values - error
7849 **/
7850static int
7851lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7852{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007853 struct pci_dev *pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007854 unsigned long bar0map_len, bar2map_len;
7855 int i, hbq_count;
7856 void *ptr;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007857 int error;
James Smart3772a992009-05-22 14:50:54 -04007858
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007859 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01007860 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007861
7862 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01007863 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7864 if (error)
7865 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7866 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007867 return error;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007868 error = -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007869
7870 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7871 * required by each mapping.
7872 */
7873 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7874 bar0map_len = pci_resource_len(pdev, 0);
7875
7876 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7877 bar2map_len = pci_resource_len(pdev, 2);
7878
7879 /* Map HBA SLIM to a kernel virtual address. */
7880 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7881 if (!phba->slim_memmap_p) {
7882 dev_printk(KERN_ERR, &pdev->dev,
7883 "ioremap failed for SLIM memory.\n");
7884 goto out;
7885 }
7886
7887 /* Map HBA Control Registers to a kernel virtual address. */
7888 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7889 if (!phba->ctrl_regs_memmap_p) {
7890 dev_printk(KERN_ERR, &pdev->dev,
7891 "ioremap failed for HBA control registers.\n");
7892 goto out_iounmap_slim;
7893 }
7894
7895 /* Allocate memory for SLI-2 structures */
Luis Chamberlain750afb02019-01-04 09:23:09 +01007896 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7897 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007898 if (!phba->slim2p.virt)
7899 goto out_iounmap;
7900
James Smart3772a992009-05-22 14:50:54 -04007901 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007902 phba->mbox_ext = (phba->slim2p.virt +
7903 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007904 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7905 phba->IOCBs = (phba->slim2p.virt +
7906 offsetof(struct lpfc_sli2_slim, IOCBs));
7907
7908 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7909 lpfc_sli_hbq_size(),
7910 &phba->hbqslimp.phys,
7911 GFP_KERNEL);
7912 if (!phba->hbqslimp.virt)
7913 goto out_free_slim;
7914
7915 hbq_count = lpfc_sli_hbq_count();
7916 ptr = phba->hbqslimp.virt;
7917 for (i = 0; i < hbq_count; ++i) {
7918 phba->hbqs[i].hbq_virt = ptr;
7919 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7920 ptr += (lpfc_hbq_defs[i]->entry_count *
7921 sizeof(struct lpfc_hbq_entry));
7922 }
7923 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7924 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7925
7926 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7927
James Smart3772a992009-05-22 14:50:54 -04007928 phba->MBslimaddr = phba->slim_memmap_p;
7929 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7930 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7931 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7932 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007933
dea31012005-04-17 16:05:31 -05007934 return 0;
7935
dea31012005-04-17 16:05:31 -05007936out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007937 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7938 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007939out_iounmap:
7940 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007941out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007942 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007943out:
7944 return error;
7945}
7946
James Smarte59058c2008-08-24 21:49:00 -04007947/**
James Smart3772a992009-05-22 14:50:54 -04007948 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7949 * @phba: pointer to lpfc hba data structure.
7950 *
7951 * This routine is invoked to unset the PCI device memory space for device
7952 * with SLI-3 interface spec.
7953 **/
7954static void
7955lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7956{
7957 struct pci_dev *pdev;
7958
7959 /* Obtain PCI device reference */
7960 if (!phba->pcidev)
7961 return;
7962 else
7963 pdev = phba->pcidev;
7964
7965 /* Free coherent DMA memory allocated */
7966 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7967 phba->hbqslimp.virt, phba->hbqslimp.phys);
7968 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7969 phba->slim2p.virt, phba->slim2p.phys);
7970
7971 /* I/O memory unmap */
7972 iounmap(phba->ctrl_regs_memmap_p);
7973 iounmap(phba->slim_memmap_p);
7974
7975 return;
7976}
7977
7978/**
James Smartda0436e2009-05-22 14:51:39 -04007979 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7980 * @phba: pointer to lpfc hba data structure.
7981 *
7982 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7983 * done and check status.
7984 *
7985 * Return 0 if successful, otherwise -ENODEV.
7986 **/
7987int
7988lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7989{
James Smart2fcee4b2010-12-15 17:57:46 -05007990 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7991 struct lpfc_register reg_data;
7992 int i, port_error = 0;
7993 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007994
James Smart9940b972011-03-11 16:06:12 -05007995 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7996 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007997 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007998 return -ENODEV;
7999
James Smartda0436e2009-05-22 14:51:39 -04008000 /* Wait up to 30 seconds for the SLI Port POST done and ready */
8001 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05008002 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
8003 &portsmphr_reg.word0) ||
8004 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008005 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04008006 port_error = -ENODEV;
8007 break;
8008 }
James Smart2fcee4b2010-12-15 17:57:46 -05008009 if (LPFC_POST_STAGE_PORT_READY ==
8010 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04008011 break;
James Smartda0436e2009-05-22 14:51:39 -04008012 msleep(10);
8013 }
8014
James Smart2fcee4b2010-12-15 17:57:46 -05008015 /*
8016 * If there was a port error during POST, then don't proceed with
8017 * other register reads as the data may not be valid. Just exit.
8018 */
8019 if (port_error) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008020 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05008021 "1408 Port Failed POST - portsmphr=0x%x, "
8022 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
8023 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
8024 portsmphr_reg.word0,
8025 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
8026 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
8027 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
8028 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
8029 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
8030 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
8031 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
8032 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
8033 } else {
James Smart28baac72010-02-12 14:42:03 -05008034 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05008035 "2534 Device Info: SLIFamily=0x%x, "
8036 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
8037 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05008038 bf_get(lpfc_sli_intf_sli_family,
8039 &phba->sli4_hba.sli_intf),
8040 bf_get(lpfc_sli_intf_slirev,
8041 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05008042 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05008043 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05008044 bf_get(lpfc_sli_intf_sli_hint1,
8045 &phba->sli4_hba.sli_intf),
8046 bf_get(lpfc_sli_intf_sli_hint2,
8047 &phba->sli4_hba.sli_intf),
8048 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05008049 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05008050 /*
8051 * Check for other Port errors during the initialization
8052 * process. Fail the load if the port did not come up
8053 * correctly.
8054 */
8055 if_type = bf_get(lpfc_sli_intf_if_type,
8056 &phba->sli4_hba.sli_intf);
8057 switch (if_type) {
8058 case LPFC_SLI_INTF_IF_TYPE_0:
8059 phba->sli4_hba.ue_mask_lo =
8060 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
8061 phba->sli4_hba.ue_mask_hi =
8062 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
8063 uerrlo_reg.word0 =
8064 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
8065 uerrhi_reg.word0 =
8066 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
8067 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
8068 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008069 lpfc_printf_log(phba, KERN_ERR,
8070 LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05008071 "1422 Unrecoverable Error "
8072 "Detected during POST "
8073 "uerr_lo_reg=0x%x, "
8074 "uerr_hi_reg=0x%x, "
8075 "ue_mask_lo_reg=0x%x, "
8076 "ue_mask_hi_reg=0x%x\n",
8077 uerrlo_reg.word0,
8078 uerrhi_reg.word0,
8079 phba->sli4_hba.ue_mask_lo,
8080 phba->sli4_hba.ue_mask_hi);
8081 port_error = -ENODEV;
8082 }
8083 break;
8084 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08008085 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008086 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05008087 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
8088 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04008089 (bf_get(lpfc_sliport_status_err, &reg_data) &&
8090 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008091 phba->work_status[0] =
8092 readl(phba->sli4_hba.u.if_type2.
8093 ERR1regaddr);
8094 phba->work_status[1] =
8095 readl(phba->sli4_hba.u.if_type2.
8096 ERR2regaddr);
Dick Kennedy372c1872020-06-30 14:50:00 -07008097 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart8fcb8ac2012-03-01 22:35:58 -05008098 "2888 Unrecoverable port error "
8099 "following POST: port status reg "
8100 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05008101 "error 1=0x%x, error 2=0x%x\n",
8102 reg_data.word0,
8103 portsmphr_reg.word0,
8104 phba->work_status[0],
8105 phba->work_status[1]);
8106 port_error = -ENODEV;
8107 }
8108 break;
8109 case LPFC_SLI_INTF_IF_TYPE_1:
8110 default:
8111 break;
8112 }
James Smart28baac72010-02-12 14:42:03 -05008113 }
James Smartda0436e2009-05-22 14:51:39 -04008114 return port_error;
8115}
8116
8117/**
8118 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
8119 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05008120 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04008121 *
8122 * This routine is invoked to set up SLI4 BAR0 PCI config space register
8123 * memory map.
8124 **/
8125static void
James Smart2fcee4b2010-12-15 17:57:46 -05008126lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04008127{
James Smart2fcee4b2010-12-15 17:57:46 -05008128 switch (if_type) {
8129 case LPFC_SLI_INTF_IF_TYPE_0:
8130 phba->sli4_hba.u.if_type0.UERRLOregaddr =
8131 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
8132 phba->sli4_hba.u.if_type0.UERRHIregaddr =
8133 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
8134 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
8135 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
8136 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
8137 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
8138 phba->sli4_hba.SLIINTFregaddr =
8139 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8140 break;
8141 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07008142 phba->sli4_hba.u.if_type2.EQDregaddr =
8143 phba->sli4_hba.conf_regs_memmap_p +
8144 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008145 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008146 phba->sli4_hba.conf_regs_memmap_p +
8147 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008148 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008149 phba->sli4_hba.conf_regs_memmap_p +
8150 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008151 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008152 phba->sli4_hba.conf_regs_memmap_p +
8153 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008154 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008155 phba->sli4_hba.conf_regs_memmap_p +
8156 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008157 phba->sli4_hba.SLIINTFregaddr =
8158 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8159 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008160 phba->sli4_hba.conf_regs_memmap_p +
8161 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008162 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008163 phba->sli4_hba.conf_regs_memmap_p +
8164 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05008165 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008166 phba->sli4_hba.conf_regs_memmap_p +
8167 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008168 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05008169 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008170 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05008171 phba->sli4_hba.MQDBregaddr =
8172 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
8173 phba->sli4_hba.BMBXregaddr =
8174 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8175 break;
James Smart27d6ac02018-02-22 08:18:42 -08008176 case LPFC_SLI_INTF_IF_TYPE_6:
8177 phba->sli4_hba.u.if_type2.EQDregaddr =
8178 phba->sli4_hba.conf_regs_memmap_p +
8179 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8180 phba->sli4_hba.u.if_type2.ERR1regaddr =
8181 phba->sli4_hba.conf_regs_memmap_p +
8182 LPFC_CTL_PORT_ER1_OFFSET;
8183 phba->sli4_hba.u.if_type2.ERR2regaddr =
8184 phba->sli4_hba.conf_regs_memmap_p +
8185 LPFC_CTL_PORT_ER2_OFFSET;
8186 phba->sli4_hba.u.if_type2.CTRLregaddr =
8187 phba->sli4_hba.conf_regs_memmap_p +
8188 LPFC_CTL_PORT_CTL_OFFSET;
8189 phba->sli4_hba.u.if_type2.STATUSregaddr =
8190 phba->sli4_hba.conf_regs_memmap_p +
8191 LPFC_CTL_PORT_STA_OFFSET;
8192 phba->sli4_hba.PSMPHRregaddr =
8193 phba->sli4_hba.conf_regs_memmap_p +
8194 LPFC_CTL_PORT_SEM_OFFSET;
8195 phba->sli4_hba.BMBXregaddr =
8196 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8197 break;
James Smart2fcee4b2010-12-15 17:57:46 -05008198 case LPFC_SLI_INTF_IF_TYPE_1:
8199 default:
8200 dev_printk(KERN_ERR, &phba->pcidev->dev,
8201 "FATAL - unsupported SLI4 interface type - %d\n",
8202 if_type);
8203 break;
8204 }
James Smartda0436e2009-05-22 14:51:39 -04008205}
8206
8207/**
8208 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8209 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01008210 * @if_type: sli if type to operate on.
James Smartda0436e2009-05-22 14:51:39 -04008211 *
James Smart27d6ac02018-02-22 08:18:42 -08008212 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04008213 **/
8214static void
James Smart27d6ac02018-02-22 08:18:42 -08008215lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04008216{
James Smart27d6ac02018-02-22 08:18:42 -08008217 switch (if_type) {
8218 case LPFC_SLI_INTF_IF_TYPE_0:
8219 phba->sli4_hba.PSMPHRregaddr =
8220 phba->sli4_hba.ctrl_regs_memmap_p +
8221 LPFC_SLIPORT_IF0_SMPHR;
8222 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8223 LPFC_HST_ISR0;
8224 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8225 LPFC_HST_IMR0;
8226 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8227 LPFC_HST_ISCR0;
8228 break;
8229 case LPFC_SLI_INTF_IF_TYPE_6:
8230 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8231 LPFC_IF6_RQ_DOORBELL;
8232 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8233 LPFC_IF6_WQ_DOORBELL;
8234 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8235 LPFC_IF6_CQ_DOORBELL;
8236 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8237 LPFC_IF6_EQ_DOORBELL;
8238 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8239 LPFC_IF6_MQ_DOORBELL;
8240 break;
8241 case LPFC_SLI_INTF_IF_TYPE_2:
8242 case LPFC_SLI_INTF_IF_TYPE_1:
8243 default:
8244 dev_err(&phba->pcidev->dev,
8245 "FATAL - unsupported SLI4 interface type - %d\n",
8246 if_type);
8247 break;
8248 }
James Smartda0436e2009-05-22 14:51:39 -04008249}
8250
8251/**
8252 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8253 * @phba: pointer to lpfc hba data structure.
8254 * @vf: virtual function number
8255 *
8256 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8257 * based on the given viftual function number, @vf.
8258 *
8259 * Return 0 if successful, otherwise -ENODEV.
8260 **/
8261static int
8262lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
8263{
8264 if (vf > LPFC_VIR_FUNC_MAX)
8265 return -ENODEV;
8266
8267 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008268 vf * LPFC_VFR_PAGE_SIZE +
8269 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04008270 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008271 vf * LPFC_VFR_PAGE_SIZE +
8272 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08008273 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8274 vf * LPFC_VFR_PAGE_SIZE +
8275 LPFC_EQCQ_DOORBELL);
8276 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04008277 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8278 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
8279 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8280 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
8281 return 0;
8282}
8283
8284/**
8285 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
8286 * @phba: pointer to lpfc hba data structure.
8287 *
8288 * This routine is invoked to create the bootstrap mailbox
8289 * region consistent with the SLI-4 interface spec. This
8290 * routine allocates all memory necessary to communicate
8291 * mailbox commands to the port and sets up all alignment
8292 * needs. No locks are expected to be held when calling
8293 * this routine.
8294 *
8295 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008296 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04008297 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04008298 **/
8299static int
8300lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
8301{
8302 uint32_t bmbx_size;
8303 struct lpfc_dmabuf *dmabuf;
8304 struct dma_address *dma_address;
8305 uint32_t pa_addr;
8306 uint64_t phys_addr;
8307
8308 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8309 if (!dmabuf)
8310 return -ENOMEM;
8311
8312 /*
8313 * The bootstrap mailbox region is comprised of 2 parts
8314 * plus an alignment restriction of 16 bytes.
8315 */
8316 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Luis Chamberlain750afb02019-01-04 09:23:09 +01008317 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
8318 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04008319 if (!dmabuf->virt) {
8320 kfree(dmabuf);
8321 return -ENOMEM;
8322 }
James Smartda0436e2009-05-22 14:51:39 -04008323
8324 /*
8325 * Initialize the bootstrap mailbox pointers now so that the register
8326 * operations are simple later. The mailbox dma address is required
8327 * to be 16-byte aligned. Also align the virtual memory as each
8328 * maibox is copied into the bmbx mailbox region before issuing the
8329 * command to the port.
8330 */
8331 phba->sli4_hba.bmbx.dmabuf = dmabuf;
8332 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
8333
8334 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
8335 LPFC_ALIGN_16_BYTE);
8336 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
8337 LPFC_ALIGN_16_BYTE);
8338
8339 /*
8340 * Set the high and low physical addresses now. The SLI4 alignment
8341 * requirement is 16 bytes and the mailbox is posted to the port
8342 * as two 30-bit addresses. The other data is a bit marking whether
8343 * the 30-bit address is the high or low address.
8344 * Upcast bmbx aphys to 64bits so shift instruction compiles
8345 * clean on 32 bit machines.
8346 */
8347 dma_address = &phba->sli4_hba.bmbx.dma_address;
8348 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
8349 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
8350 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
8351 LPFC_BMBX_BIT1_ADDR_HI);
8352
8353 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
8354 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
8355 LPFC_BMBX_BIT1_ADDR_LO);
8356 return 0;
8357}
8358
8359/**
8360 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
8361 * @phba: pointer to lpfc hba data structure.
8362 *
8363 * This routine is invoked to teardown the bootstrap mailbox
8364 * region and release all host resources. This routine requires
8365 * the caller to ensure all mailbox commands recovered, no
8366 * additional mailbox comands are sent, and interrupts are disabled
8367 * before calling this routine.
8368 *
8369 **/
8370static void
8371lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
8372{
8373 dma_free_coherent(&phba->pcidev->dev,
8374 phba->sli4_hba.bmbx.bmbx_size,
8375 phba->sli4_hba.bmbx.dmabuf->virt,
8376 phba->sli4_hba.bmbx.dmabuf->phys);
8377
8378 kfree(phba->sli4_hba.bmbx.dmabuf);
8379 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
8380}
8381
James Smart83c6cb12019-10-18 14:18:30 -07008382static const char * const lpfc_topo_to_str[] = {
8383 "Loop then P2P",
8384 "Loopback",
8385 "P2P Only",
8386 "Unsupported",
8387 "Loop Only",
8388 "Unsupported",
8389 "P2P then Loop",
8390};
8391
Lee Jonesfe614ac2020-07-23 13:24:22 +01008392#define LINK_FLAGS_DEF 0x0
8393#define LINK_FLAGS_P2P 0x1
8394#define LINK_FLAGS_LOOP 0x2
James Smart83c6cb12019-10-18 14:18:30 -07008395/**
8396 * lpfc_map_topology - Map the topology read from READ_CONFIG
8397 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01008398 * @rd_config: pointer to read config data
James Smart83c6cb12019-10-18 14:18:30 -07008399 *
8400 * This routine is invoked to map the topology values as read
8401 * from the read config mailbox command. If the persistent
8402 * topology feature is supported, the firmware will provide the
8403 * saved topology information to be used in INIT_LINK
James Smart83c6cb12019-10-18 14:18:30 -07008404 **/
James Smart83c6cb12019-10-18 14:18:30 -07008405static void
8406lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
8407{
8408 u8 ptv, tf, pt;
8409
8410 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
8411 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
8412 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
8413
8414 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8415 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
8416 ptv, tf, pt);
8417 if (!ptv) {
8418 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8419 "2019 FW does not support persistent topology "
8420 "Using driver parameter defined value [%s]",
8421 lpfc_topo_to_str[phba->cfg_topology]);
8422 return;
8423 }
8424 /* FW supports persistent topology - override module parameter value */
8425 phba->hba_flag |= HBA_PERSISTENT_TOPO;
8426 switch (phba->pcidev->device) {
8427 case PCI_DEVICE_ID_LANCER_G7_FC:
James Smart83c6cb12019-10-18 14:18:30 -07008428 case PCI_DEVICE_ID_LANCER_G6_FC:
8429 if (!tf) {
8430 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
8431 ? FLAGS_TOPOLOGY_MODE_LOOP
8432 : FLAGS_TOPOLOGY_MODE_PT_PT);
8433 } else {
8434 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
8435 }
8436 break;
8437 default: /* G5 */
8438 if (tf) {
8439 /* If topology failover set - pt is '0' or '1' */
8440 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
8441 FLAGS_TOPOLOGY_MODE_LOOP_PT);
8442 } else {
8443 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
8444 ? FLAGS_TOPOLOGY_MODE_PT_PT
8445 : FLAGS_TOPOLOGY_MODE_LOOP);
8446 }
8447 break;
8448 }
8449 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
8450 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8451 "2020 Using persistent topology value [%s]",
8452 lpfc_topo_to_str[phba->cfg_topology]);
8453 } else {
8454 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8455 "2021 Invalid topology values from FW "
8456 "Using driver parameter defined value [%s]",
8457 lpfc_topo_to_str[phba->cfg_topology]);
8458 }
8459}
8460
James Smartda0436e2009-05-22 14:51:39 -04008461/**
8462 * lpfc_sli4_read_config - Get the config parameters.
8463 * @phba: pointer to lpfc hba data structure.
8464 *
8465 * This routine is invoked to read the configuration parameters from the HBA.
8466 * The configuration parameters are used to set the base and maximum values
8467 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
8468 * allocation for the port.
8469 *
8470 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008471 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008472 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008473 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008474 **/
James Smartff78d8f2011-12-13 13:21:35 -05008475int
James Smartda0436e2009-05-22 14:51:39 -04008476lpfc_sli4_read_config(struct lpfc_hba *phba)
8477{
8478 LPFC_MBOXQ_t *pmb;
8479 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04008480 union lpfc_sli4_cfg_shdr *shdr;
8481 uint32_t shdr_status, shdr_add_status;
8482 struct lpfc_mbx_get_func_cfg *get_func_cfg;
8483 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04008484 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07008485 uint16_t forced_link_speed;
James Smart6a828b02019-01-28 11:14:31 -08008486 uint32_t if_type, qmin;
James Smart8aa134a2012-08-14 14:25:29 -04008487 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04008488
8489 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8490 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008491 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04008492 "2011 Unable to allocate memory for issuing "
8493 "SLI_CONFIG_SPECIAL mailbox command\n");
8494 return -ENOMEM;
8495 }
8496
8497 lpfc_read_config(phba, pmb);
8498
8499 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8500 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008501 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8502 "2012 Mailbox failed , mbxCmd x%x "
8503 "READ_CONFIG, mbxStatus x%x\n",
8504 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8505 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smartda0436e2009-05-22 14:51:39 -04008506 rc = -EIO;
8507 } else {
8508 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05008509 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
8510 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
8511 phba->sli4_hba.lnk_info.lnk_tp =
8512 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
8513 phba->sli4_hba.lnk_info.lnk_no =
8514 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
8515 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8516 "3081 lnk_type:%d, lnk_numb:%d\n",
8517 phba->sli4_hba.lnk_info.lnk_tp,
8518 phba->sli4_hba.lnk_info.lnk_no);
8519 } else
8520 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8521 "3082 Mailbox (x%x) returned ldv:x0\n",
8522 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07008523 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
8524 phba->bbcredit_support = 1;
8525 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
8526 }
8527
James Smart1dc5ec22018-10-23 13:41:11 -07008528 phba->sli4_hba.conf_trunk =
8529 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04008530 phba->sli4_hba.extents_in_use =
8531 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008532 phba->sli4_hba.max_cfg_param.max_xri =
8533 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
James Smart31f06d22019-08-14 16:56:31 -07008534 /* Reduce resource usage in kdump environment */
8535 if (is_kdump_kernel() &&
8536 phba->sli4_hba.max_cfg_param.max_xri > 512)
8537 phba->sli4_hba.max_cfg_param.max_xri = 512;
James Smartda0436e2009-05-22 14:51:39 -04008538 phba->sli4_hba.max_cfg_param.xri_base =
8539 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
8540 phba->sli4_hba.max_cfg_param.max_vpi =
8541 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08008542 /* Limit the max we support */
8543 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
8544 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04008545 phba->sli4_hba.max_cfg_param.vpi_base =
8546 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
8547 phba->sli4_hba.max_cfg_param.max_rpi =
8548 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
8549 phba->sli4_hba.max_cfg_param.rpi_base =
8550 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
8551 phba->sli4_hba.max_cfg_param.max_vfi =
8552 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
8553 phba->sli4_hba.max_cfg_param.vfi_base =
8554 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
8555 phba->sli4_hba.max_cfg_param.max_fcfi =
8556 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008557 phba->sli4_hba.max_cfg_param.max_eq =
8558 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
8559 phba->sli4_hba.max_cfg_param.max_rq =
8560 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
8561 phba->sli4_hba.max_cfg_param.max_wq =
8562 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
8563 phba->sli4_hba.max_cfg_param.max_cq =
8564 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
8565 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
8566 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
8567 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
8568 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05008569 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
8570 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04008571 phba->max_vports = phba->max_vpi;
James Smart83c6cb12019-10-18 14:18:30 -07008572 lpfc_map_topology(phba, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008573 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04008574 "2003 cfg params Extents? %d "
8575 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04008576 "VPI(B:%d M:%d) "
8577 "VFI(B:%d M:%d) "
8578 "RPI(B:%d M:%d) "
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07008579 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
James Smart6d368e52011-05-24 11:44:12 -04008580 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04008581 phba->sli4_hba.max_cfg_param.xri_base,
8582 phba->sli4_hba.max_cfg_param.max_xri,
8583 phba->sli4_hba.max_cfg_param.vpi_base,
8584 phba->sli4_hba.max_cfg_param.max_vpi,
8585 phba->sli4_hba.max_cfg_param.vfi_base,
8586 phba->sli4_hba.max_cfg_param.max_vfi,
8587 phba->sli4_hba.max_cfg_param.rpi_base,
8588 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08008589 phba->sli4_hba.max_cfg_param.max_fcfi,
8590 phba->sli4_hba.max_cfg_param.max_eq,
8591 phba->sli4_hba.max_cfg_param.max_cq,
8592 phba->sli4_hba.max_cfg_param.max_wq,
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07008593 phba->sli4_hba.max_cfg_param.max_rq,
8594 phba->lmt);
James Smart2ea259e2017-02-12 13:52:27 -08008595
James Smartd38f33b2018-05-04 20:37:54 -07008596 /*
James Smart6a828b02019-01-28 11:14:31 -08008597 * Calculate queue resources based on how
8598 * many WQ/CQ/EQs are available.
James Smartd38f33b2018-05-04 20:37:54 -07008599 */
James Smart6a828b02019-01-28 11:14:31 -08008600 qmin = phba->sli4_hba.max_cfg_param.max_wq;
8601 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
8602 qmin = phba->sli4_hba.max_cfg_param.max_cq;
8603 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
8604 qmin = phba->sli4_hba.max_cfg_param.max_eq;
8605 /*
8606 * Whats left after this can go toward NVME / FCP.
8607 * The minus 4 accounts for ELS, NVME LS, MBOX
8608 * plus one extra. When configured for
8609 * NVMET, FCP io channel WQs are not created.
8610 */
8611 qmin -= 4;
James Smartd38f33b2018-05-04 20:37:54 -07008612
James Smart6a828b02019-01-28 11:14:31 -08008613 /* Check to see if there is enough for NVME */
8614 if ((phba->cfg_irq_chann > qmin) ||
8615 (phba->cfg_hdw_queue > qmin)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008616 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedy9e3e3652020-08-03 14:02:23 -07008617 "2005 Reducing Queues - "
8618 "FW resource limitation: "
James Smart6a828b02019-01-28 11:14:31 -08008619 "WQ %d CQ %d EQ %d: min %d: "
8620 "IRQ %d HDWQ %d\n",
James Smartd38f33b2018-05-04 20:37:54 -07008621 phba->sli4_hba.max_cfg_param.max_wq,
8622 phba->sli4_hba.max_cfg_param.max_cq,
James Smart6a828b02019-01-28 11:14:31 -08008623 phba->sli4_hba.max_cfg_param.max_eq,
8624 qmin, phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08008625 phba->cfg_hdw_queue);
James Smartd38f33b2018-05-04 20:37:54 -07008626
James Smart6a828b02019-01-28 11:14:31 -08008627 if (phba->cfg_irq_chann > qmin)
8628 phba->cfg_irq_chann = qmin;
8629 if (phba->cfg_hdw_queue > qmin)
8630 phba->cfg_hdw_queue = qmin;
James Smartd38f33b2018-05-04 20:37:54 -07008631 }
James Smartda0436e2009-05-22 14:51:39 -04008632 }
James Smart912e3ac2011-05-24 11:42:11 -04008633
8634 if (rc)
8635 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04008636
James Smartc6918162016-10-13 15:06:16 -07008637 /* Update link speed if forced link speed is supported */
8638 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08008639 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07008640 forced_link_speed =
8641 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8642 if (forced_link_speed) {
8643 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8644
8645 switch (forced_link_speed) {
8646 case LINK_SPEED_1G:
8647 phba->cfg_link_speed =
8648 LPFC_USER_LINK_SPEED_1G;
8649 break;
8650 case LINK_SPEED_2G:
8651 phba->cfg_link_speed =
8652 LPFC_USER_LINK_SPEED_2G;
8653 break;
8654 case LINK_SPEED_4G:
8655 phba->cfg_link_speed =
8656 LPFC_USER_LINK_SPEED_4G;
8657 break;
8658 case LINK_SPEED_8G:
8659 phba->cfg_link_speed =
8660 LPFC_USER_LINK_SPEED_8G;
8661 break;
8662 case LINK_SPEED_10G:
8663 phba->cfg_link_speed =
8664 LPFC_USER_LINK_SPEED_10G;
8665 break;
8666 case LINK_SPEED_16G:
8667 phba->cfg_link_speed =
8668 LPFC_USER_LINK_SPEED_16G;
8669 break;
8670 case LINK_SPEED_32G:
8671 phba->cfg_link_speed =
8672 LPFC_USER_LINK_SPEED_32G;
8673 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08008674 case LINK_SPEED_64G:
8675 phba->cfg_link_speed =
8676 LPFC_USER_LINK_SPEED_64G;
8677 break;
James Smartc6918162016-10-13 15:06:16 -07008678 case 0xffff:
8679 phba->cfg_link_speed =
8680 LPFC_USER_LINK_SPEED_AUTO;
8681 break;
8682 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07008683 lpfc_printf_log(phba, KERN_ERR,
8684 LOG_TRACE_EVENT,
James Smartc6918162016-10-13 15:06:16 -07008685 "0047 Unrecognized link "
8686 "speed : %d\n",
8687 forced_link_speed);
8688 phba->cfg_link_speed =
8689 LPFC_USER_LINK_SPEED_AUTO;
8690 }
8691 }
8692 }
8693
James Smartda0436e2009-05-22 14:51:39 -04008694 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04008695 length = phba->sli4_hba.max_cfg_param.max_xri -
8696 lpfc_sli4_get_els_iocb_cnt(phba);
8697 if (phba->cfg_hba_queue_depth > length) {
8698 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8699 "3361 HBA queue depth changed from %d to %d\n",
8700 phba->cfg_hba_queue_depth, length);
8701 phba->cfg_hba_queue_depth = length;
8702 }
James Smart912e3ac2011-05-24 11:42:11 -04008703
James Smart27d6ac02018-02-22 08:18:42 -08008704 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04008705 LPFC_SLI_INTF_IF_TYPE_2)
8706 goto read_cfg_out;
8707
8708 /* get the pf# and vf# for SLI4 if_type 2 port */
8709 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8710 sizeof(struct lpfc_sli4_cfg_mhdr));
8711 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8712 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8713 length, LPFC_SLI4_MBX_EMBED);
8714
James Smart8aa134a2012-08-14 14:25:29 -04008715 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04008716 shdr = (union lpfc_sli4_cfg_shdr *)
8717 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8718 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8719 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04008720 if (rc2 || shdr_status || shdr_add_status) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008721 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart912e3ac2011-05-24 11:42:11 -04008722 "3026 Mailbox failed , mbxCmd x%x "
8723 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8724 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8725 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04008726 goto read_cfg_out;
8727 }
8728
8729 /* search for fc_fcoe resrouce descriptor */
8730 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04008731
James Smart8aa134a2012-08-14 14:25:29 -04008732 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8733 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8734 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8735 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8736 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8737 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8738 goto read_cfg_out;
8739
James Smart912e3ac2011-05-24 11:42:11 -04008740 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04008741 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04008742 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04008743 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04008744 phba->sli4_hba.iov.pf_number =
8745 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8746 phba->sli4_hba.iov.vf_number =
8747 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8748 break;
8749 }
8750 }
8751
8752 if (i < LPFC_RSRC_DESC_MAX_NUM)
8753 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8754 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8755 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8756 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04008757 else
Dick Kennedy372c1872020-06-30 14:50:00 -07008758 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart912e3ac2011-05-24 11:42:11 -04008759 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008760 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008761 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008762
8763read_cfg_out:
8764 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008765 return rc;
8766}
8767
8768/**
James Smart2fcee4b2010-12-15 17:57:46 -05008769 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008770 * @phba: pointer to lpfc hba data structure.
8771 *
James Smart2fcee4b2010-12-15 17:57:46 -05008772 * This routine is invoked to setup the port-side endian order when
8773 * the port if_type is 0. This routine has no function for other
8774 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008775 *
8776 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008777 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008778 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008779 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008780 **/
8781static int
8782lpfc_setup_endian_order(struct lpfc_hba *phba)
8783{
8784 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008785 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008786 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8787 HOST_ENDIAN_HIGH_WORD1};
8788
James Smart2fcee4b2010-12-15 17:57:46 -05008789 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8790 switch (if_type) {
8791 case LPFC_SLI_INTF_IF_TYPE_0:
8792 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8793 GFP_KERNEL);
8794 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008795 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05008796 "0492 Unable to allocate memory for "
8797 "issuing SLI_CONFIG_SPECIAL mailbox "
8798 "command\n");
8799 return -ENOMEM;
8800 }
James Smartda0436e2009-05-22 14:51:39 -04008801
James Smart2fcee4b2010-12-15 17:57:46 -05008802 /*
8803 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8804 * two words to contain special data values and no other data.
8805 */
8806 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8807 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8808 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8809 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008810 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05008811 "0493 SLI_CONFIG_SPECIAL mailbox "
8812 "failed with status x%x\n",
8813 rc);
8814 rc = -EIO;
8815 }
8816 mempool_free(mboxq, phba->mbox_mem_pool);
8817 break;
James Smart27d6ac02018-02-22 08:18:42 -08008818 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008819 case LPFC_SLI_INTF_IF_TYPE_2:
8820 case LPFC_SLI_INTF_IF_TYPE_1:
8821 default:
8822 break;
James Smartda0436e2009-05-22 14:51:39 -04008823 }
James Smartda0436e2009-05-22 14:51:39 -04008824 return rc;
8825}
8826
8827/**
James Smart895427b2017-02-12 13:52:30 -08008828 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008829 * @phba: pointer to lpfc hba data structure.
8830 *
James Smart895427b2017-02-12 13:52:30 -08008831 * This routine is invoked to check the user settable queue counts for EQs.
8832 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008833 * adhere to the constraints of the system's interrupt vectors and the port's
8834 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008835 *
8836 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008837 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008838 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008839 **/
8840static int
James Smart5350d872011-10-10 21:33:49 -04008841lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008842{
James Smartda0436e2009-05-22 14:51:39 -04008843 /*
James Smart67d12732012-08-03 12:36:13 -04008844 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008845 * device parameters
8846 */
8847
James Smartbcb24f62017-11-20 16:00:36 -08008848 if (phba->nvmet_support) {
James Smart97a9ed32019-10-18 14:18:17 -07008849 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
8850 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
James Smart982ab122019-03-12 16:30:10 -07008851 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8852 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smartbcb24f62017-11-20 16:00:36 -08008853 }
James Smart895427b2017-02-12 13:52:30 -08008854
8855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -08008856 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
8857 phba->cfg_hdw_queue, phba->cfg_irq_chann,
8858 phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008859
James Smartda0436e2009-05-22 14:51:39 -04008860 /* Get EQ depth from module parameter, fake the default for now */
8861 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8862 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8863
James Smart5350d872011-10-10 21:33:49 -04008864 /* Get CQ depth from module parameter, fake the default for now */
8865 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8866 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008867 return 0;
James Smart895427b2017-02-12 13:52:30 -08008868}
8869
8870static int
James Smartc00f62e2019-08-14 16:57:11 -07008871lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
James Smart895427b2017-02-12 13:52:30 -08008872{
8873 struct lpfc_queue *qdesc;
James Smartc00f62e2019-08-14 16:57:11 -07008874 u32 wqesize;
James Smartc1a21eb2019-03-12 16:30:29 -07008875 int cpu;
James Smart895427b2017-02-12 13:52:30 -08008876
James Smartc00f62e2019-08-14 16:57:11 -07008877 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
8878 /* Create Fast Path IO CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008879 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008880 /* Increase the CQ size when WQEs contain an embedded cdb */
8881 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8882 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008883 LPFC_CQE_EXP_COUNT, cpu);
James Smarta51e41b2017-12-08 17:18:06 -08008884
8885 else
8886 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8887 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008888 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08008889 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008890 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8891 "0499 Failed allocate fast-path IO CQ (%d)\n",
8892 idx);
James Smart895427b2017-02-12 13:52:30 -08008893 return 1;
8894 }
James Smart7365f6f2018-02-22 08:18:46 -08008895 qdesc->qe_valid = 1;
James Smartc00f62e2019-08-14 16:57:11 -07008896 qdesc->hdwq = idx;
James Smartc1a21eb2019-03-12 16:30:29 -07008897 qdesc->chann = cpu;
James Smartc00f62e2019-08-14 16:57:11 -07008898 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008899
James Smartc00f62e2019-08-14 16:57:11 -07008900 /* Create Fast Path IO WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008901 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008902 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008903 wqesize = (phba->fcp_embed_io) ?
8904 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008905 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008906 wqesize,
James Smartc1a21eb2019-03-12 16:30:29 -07008907 LPFC_WQE_EXP_COUNT, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008908 } else
James Smarta51e41b2017-12-08 17:18:06 -08008909 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8910 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008911 phba->sli4_hba.wq_ecount, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008912
James Smart895427b2017-02-12 13:52:30 -08008913 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008914 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc00f62e2019-08-14 16:57:11 -07008915 "0503 Failed allocate fast-path IO WQ (%d)\n",
8916 idx);
James Smart895427b2017-02-12 13:52:30 -08008917 return 1;
8918 }
James Smartc00f62e2019-08-14 16:57:11 -07008919 qdesc->hdwq = idx;
8920 qdesc->chann = cpu;
8921 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008922 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8923 return 0;
James Smart5350d872011-10-10 21:33:49 -04008924}
8925
8926/**
8927 * lpfc_sli4_queue_create - Create all the SLI4 queues
8928 * @phba: pointer to lpfc hba data structure.
8929 *
8930 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8931 * operation. For each SLI4 queue type, the parameters such as queue entry
8932 * count (queue depth) shall be taken from the module parameter. For now,
8933 * we just use some constant number as place holder.
8934 *
8935 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008936 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008937 * -ENOMEM - No availble memory
8938 * -EIO - The mailbox failed to complete successfully.
8939 **/
8940int
8941lpfc_sli4_queue_create(struct lpfc_hba *phba)
8942{
8943 struct lpfc_queue *qdesc;
James Smart657add42019-05-21 17:49:06 -07008944 int idx, cpu, eqcpu;
James Smart5e5b5112019-01-28 11:14:22 -08008945 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07008946 struct lpfc_vector_map_info *cpup;
8947 struct lpfc_vector_map_info *eqcpup;
James Smart32517fc2019-01-28 11:14:33 -08008948 struct lpfc_eq_intr_info *eqi;
James Smart5350d872011-10-10 21:33:49 -04008949
8950 /*
James Smart67d12732012-08-03 12:36:13 -04008951 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008952 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008953 */
James Smart67d12732012-08-03 12:36:13 -04008954 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8955 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8956 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8957 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8958 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8959 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008960 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8961 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8962 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8963 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008964
James Smartcdb42be2019-01-28 11:14:21 -08008965 if (!phba->sli4_hba.hdwq) {
James Smart5e5b5112019-01-28 11:14:22 -08008966 phba->sli4_hba.hdwq = kcalloc(
8967 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
8968 GFP_KERNEL);
8969 if (!phba->sli4_hba.hdwq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008970 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5e5b5112019-01-28 11:14:22 -08008971 "6427 Failed allocate memory for "
8972 "fast-path Hardware Queue array\n");
James Smart895427b2017-02-12 13:52:30 -08008973 goto out_error;
8974 }
James Smart5e5b5112019-01-28 11:14:22 -08008975 /* Prepare hardware queues to take IO buffers */
8976 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
8977 qp = &phba->sli4_hba.hdwq[idx];
8978 spin_lock_init(&qp->io_buf_list_get_lock);
8979 spin_lock_init(&qp->io_buf_list_put_lock);
8980 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
8981 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
8982 qp->get_io_bufs = 0;
8983 qp->put_io_bufs = 0;
8984 qp->total_io_bufs = 0;
James Smartc00f62e2019-08-14 16:57:11 -07008985 spin_lock_init(&qp->abts_io_buf_list_lock);
8986 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
James Smart5e5b5112019-01-28 11:14:22 -08008987 qp->abts_scsi_io_bufs = 0;
James Smart5e5b5112019-01-28 11:14:22 -08008988 qp->abts_nvme_io_bufs = 0;
James Smartd79c9e92019-08-14 16:57:09 -07008989 INIT_LIST_HEAD(&qp->sgl_list);
8990 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
8991 spin_lock_init(&qp->hdwq_lock);
James Smart895427b2017-02-12 13:52:30 -08008992 }
James Smart67d12732012-08-03 12:36:13 -04008993 }
8994
James Smartcdb42be2019-01-28 11:14:21 -08008995 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -08008996 if (phba->nvmet_support) {
8997 phba->sli4_hba.nvmet_cqset = kcalloc(
8998 phba->cfg_nvmet_mrq,
8999 sizeof(struct lpfc_queue *),
9000 GFP_KERNEL);
9001 if (!phba->sli4_hba.nvmet_cqset) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009002 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009003 "3121 Fail allocate memory for "
9004 "fast-path CQ set array\n");
9005 goto out_error;
9006 }
9007 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
9008 phba->cfg_nvmet_mrq,
9009 sizeof(struct lpfc_queue *),
9010 GFP_KERNEL);
9011 if (!phba->sli4_hba.nvmet_mrq_hdr) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009012 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009013 "3122 Fail allocate memory for "
9014 "fast-path RQ set hdr array\n");
9015 goto out_error;
9016 }
9017 phba->sli4_hba.nvmet_mrq_data = kcalloc(
9018 phba->cfg_nvmet_mrq,
9019 sizeof(struct lpfc_queue *),
9020 GFP_KERNEL);
9021 if (!phba->sli4_hba.nvmet_mrq_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009022 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009023 "3124 Fail allocate memory for "
9024 "fast-path RQ set data array\n");
9025 goto out_error;
9026 }
9027 }
James Smart67d12732012-08-03 12:36:13 -04009028 }
James Smartda0436e2009-05-22 14:51:39 -04009029
James Smart895427b2017-02-12 13:52:30 -08009030 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04009031
James Smart895427b2017-02-12 13:52:30 -08009032 /* Create HBA Event Queues (EQs) */
James Smart657add42019-05-21 17:49:06 -07009033 for_each_present_cpu(cpu) {
9034 /* We only want to create 1 EQ per vector, even though
9035 * multiple CPUs might be using that vector. so only
9036 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
James Smart6a828b02019-01-28 11:14:31 -08009037 */
James Smart657add42019-05-21 17:49:06 -07009038 cpup = &phba->sli4_hba.cpu_map[cpu];
9039 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
James Smart6a828b02019-01-28 11:14:31 -08009040 continue;
James Smart657add42019-05-21 17:49:06 -07009041
9042 /* Get a ptr to the Hardware Queue associated with this CPU */
9043 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
9044
9045 /* Allocate an EQ */
James Smart81b96ed2017-11-20 16:00:29 -08009046 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9047 phba->sli4_hba.eq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009048 phba->sli4_hba.eq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009049 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009050 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart657add42019-05-21 17:49:06 -07009051 "0497 Failed allocate EQ (%d)\n",
9052 cpup->hdwq);
James Smart67d12732012-08-03 12:36:13 -04009053 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009054 }
James Smart7365f6f2018-02-22 08:18:46 -08009055 qdesc->qe_valid = 1;
James Smart657add42019-05-21 17:49:06 -07009056 qdesc->hdwq = cpup->hdwq;
James Smart3ad348d2019-08-14 16:56:43 -07009057 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
James Smart32517fc2019-01-28 11:14:33 -08009058 qdesc->last_cpu = qdesc->chann;
James Smart657add42019-05-21 17:49:06 -07009059
9060 /* Save the allocated EQ in the Hardware Queue */
9061 qp->hba_eq = qdesc;
9062
James Smart32517fc2019-01-28 11:14:33 -08009063 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
9064 list_add(&qdesc->cpu_list, &eqi->list);
James Smartda0436e2009-05-22 14:51:39 -04009065 }
9066
James Smart657add42019-05-21 17:49:06 -07009067 /* Now we need to populate the other Hardware Queues, that share
9068 * an IRQ vector, with the associated EQ ptr.
9069 */
9070 for_each_present_cpu(cpu) {
9071 cpup = &phba->sli4_hba.cpu_map[cpu];
9072
9073 /* Check for EQ already allocated in previous loop */
9074 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
9075 continue;
9076
9077 /* Check for multiple CPUs per hdwq */
9078 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
9079 if (qp->hba_eq)
9080 continue;
9081
9082 /* We need to share an EQ for this hdwq */
9083 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
9084 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
9085 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
9086 }
James Smart895427b2017-02-12 13:52:30 -08009087
James Smartc00f62e2019-08-14 16:57:11 -07009088 /* Allocate IO Path SLI4 CQ/WQs */
James Smart6a828b02019-01-28 11:14:31 -08009089 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smartc00f62e2019-08-14 16:57:11 -07009090 if (lpfc_alloc_io_wq_cq(phba, idx))
James Smart895427b2017-02-12 13:52:30 -08009091 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -08009092 }
James Smart895427b2017-02-12 13:52:30 -08009093
James Smartc00f62e2019-08-14 16:57:11 -07009094 if (phba->nvmet_support) {
9095 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
9096 cpu = lpfc_find_cpu_handle(phba, idx,
9097 LPFC_FIND_BY_HDWQ);
9098 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009099 LPFC_DEFAULT_PAGE_SIZE,
9100 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009101 phba->sli4_hba.cq_ecount,
9102 cpu);
James Smartc00f62e2019-08-14 16:57:11 -07009103 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009104 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -08009105 "3142 Failed allocate NVME "
9106 "CQ Set (%d)\n", idx);
James Smartc00f62e2019-08-14 16:57:11 -07009107 goto out_error;
James Smart2d7dbc42017-02-12 13:52:35 -08009108 }
James Smartc00f62e2019-08-14 16:57:11 -07009109 qdesc->qe_valid = 1;
9110 qdesc->hdwq = idx;
9111 qdesc->chann = cpu;
9112 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
James Smart2d7dbc42017-02-12 13:52:35 -08009113 }
9114 }
9115
James Smartda0436e2009-05-22 14:51:39 -04009116 /*
James Smart67d12732012-08-03 12:36:13 -04009117 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009118 */
9119
James Smartc1a21eb2019-03-12 16:30:29 -07009120 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
James Smartda0436e2009-05-22 14:51:39 -04009121 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009122 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9123 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009124 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009125 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009126 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009127 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04009128 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009129 }
James Smart7365f6f2018-02-22 08:18:46 -08009130 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04009131 phba->sli4_hba.mbx_cq = qdesc;
9132
9133 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009134 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9135 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009136 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009137 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009138 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009139 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04009140 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009141 }
James Smart7365f6f2018-02-22 08:18:46 -08009142 qdesc->qe_valid = 1;
James Smartc00f62e2019-08-14 16:57:11 -07009143 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -04009144 phba->sli4_hba.els_cq = qdesc;
9145
James Smartda0436e2009-05-22 14:51:39 -04009146
James Smart5350d872011-10-10 21:33:49 -04009147 /*
James Smart67d12732012-08-03 12:36:13 -04009148 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04009149 */
James Smartda0436e2009-05-22 14:51:39 -04009150
9151 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04009152
James Smart81b96ed2017-11-20 16:00:29 -08009153 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9154 phba->sli4_hba.mq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009155 phba->sli4_hba.mq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009156 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009157 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009158 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04009159 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009160 }
James Smartc00f62e2019-08-14 16:57:11 -07009161 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -04009162 phba->sli4_hba.mbx_wq = qdesc;
9163
9164 /*
James Smart67d12732012-08-03 12:36:13 -04009165 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04009166 */
James Smartda0436e2009-05-22 14:51:39 -04009167
9168 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009169 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9170 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009171 phba->sli4_hba.wq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009172 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009173 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009174 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04009175 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009176 }
James Smartc00f62e2019-08-14 16:57:11 -07009177 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -04009178 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08009179 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9180
9181 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9182 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009183 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9184 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009185 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009186 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009187 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009188 "6079 Failed allocate NVME LS CQ\n");
9189 goto out_error;
9190 }
James Smartc00f62e2019-08-14 16:57:11 -07009191 qdesc->chann = cpu;
James Smart7365f6f2018-02-22 08:18:46 -08009192 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08009193 phba->sli4_hba.nvmels_cq = qdesc;
9194
9195 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009196 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9197 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009198 phba->sli4_hba.wq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009199 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009200 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009201 "6080 Failed allocate NVME LS WQ\n");
9202 goto out_error;
9203 }
James Smartc00f62e2019-08-14 16:57:11 -07009204 qdesc->chann = cpu;
James Smart895427b2017-02-12 13:52:30 -08009205 phba->sli4_hba.nvmels_wq = qdesc;
9206 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9207 }
James Smartda0436e2009-05-22 14:51:39 -04009208
James Smartda0436e2009-05-22 14:51:39 -04009209 /*
9210 * Create Receive Queue (RQ)
9211 */
James Smartda0436e2009-05-22 14:51:39 -04009212
9213 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08009214 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9215 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009216 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009217 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009218 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009219 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009220 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009221 }
9222 phba->sli4_hba.hdr_rq = qdesc;
9223
9224 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08009225 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9226 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009227 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009228 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009229 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009230 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009231 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009232 }
9233 phba->sli4_hba.dat_rq = qdesc;
9234
James Smartcdb42be2019-01-28 11:14:21 -08009235 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
9236 phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08009237 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -07009238 cpu = lpfc_find_cpu_handle(phba, idx,
9239 LPFC_FIND_BY_HDWQ);
James Smart2d7dbc42017-02-12 13:52:35 -08009240 /* Create NVMET Receive Queue for header */
9241 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009242 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009243 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009244 LPFC_NVMET_RQE_DEF_COUNT,
9245 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009246 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009247 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009248 "3146 Failed allocate "
9249 "receive HRQ\n");
9250 goto out_error;
9251 }
James Smart5e5b5112019-01-28 11:14:22 -08009252 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009253 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
9254
9255 /* Only needed for header of RQ pair */
James Smartc1a21eb2019-03-12 16:30:29 -07009256 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
9257 GFP_KERNEL,
9258 cpu_to_node(cpu));
James Smart2d7dbc42017-02-12 13:52:35 -08009259 if (qdesc->rqbp == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009260 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009261 "6131 Failed allocate "
9262 "Header RQBP\n");
9263 goto out_error;
9264 }
9265
Dick Kennedy4b40d022017-08-23 16:55:38 -07009266 /* Put list in known state in case driver load fails. */
9267 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
9268
James Smart2d7dbc42017-02-12 13:52:35 -08009269 /* Create NVMET Receive Queue for data */
9270 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009271 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009272 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009273 LPFC_NVMET_RQE_DEF_COUNT,
9274 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009275 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009276 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009277 "3156 Failed allocate "
9278 "receive DRQ\n");
9279 goto out_error;
9280 }
James Smart5e5b5112019-01-28 11:14:22 -08009281 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009282 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
9283 }
9284 }
9285
James Smart4c47efc2019-01-28 11:14:25 -08009286 /* Clear NVME stats */
9287 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9288 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9289 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
9290 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
9291 }
9292 }
James Smart4c47efc2019-01-28 11:14:25 -08009293
9294 /* Clear SCSI stats */
9295 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
9296 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9297 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
9298 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
9299 }
9300 }
9301
James Smartda0436e2009-05-22 14:51:39 -04009302 return 0;
9303
James Smartda0436e2009-05-22 14:51:39 -04009304out_error:
James Smart67d12732012-08-03 12:36:13 -04009305 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009306 return -ENOMEM;
9307}
9308
James Smart895427b2017-02-12 13:52:30 -08009309static inline void
9310__lpfc_sli4_release_queue(struct lpfc_queue **qp)
9311{
9312 if (*qp != NULL) {
9313 lpfc_sli4_queue_free(*qp);
9314 *qp = NULL;
9315 }
9316}
9317
9318static inline void
9319lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
9320{
9321 int idx;
9322
9323 if (*qs == NULL)
9324 return;
9325
9326 for (idx = 0; idx < max; idx++)
9327 __lpfc_sli4_release_queue(&(*qs)[idx]);
9328
9329 kfree(*qs);
9330 *qs = NULL;
9331}
9332
9333static inline void
James Smart6a828b02019-01-28 11:14:31 -08009334lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08009335{
James Smart6a828b02019-01-28 11:14:31 -08009336 struct lpfc_sli4_hdw_queue *hdwq;
James Smart657add42019-05-21 17:49:06 -07009337 struct lpfc_queue *eq;
James Smartcdb42be2019-01-28 11:14:21 -08009338 uint32_t idx;
9339
James Smart6a828b02019-01-28 11:14:31 -08009340 hdwq = phba->sli4_hba.hdwq;
James Smart6a828b02019-01-28 11:14:31 -08009341
James Smart657add42019-05-21 17:49:06 -07009342 /* Loop thru all Hardware Queues */
9343 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9344 /* Free the CQ/WQ corresponding to the Hardware Queue */
James Smartc00f62e2019-08-14 16:57:11 -07009345 lpfc_sli4_queue_free(hdwq[idx].io_cq);
9346 lpfc_sli4_queue_free(hdwq[idx].io_wq);
James Smart821bc882020-01-27 16:23:05 -08009347 hdwq[idx].hba_eq = NULL;
James Smartc00f62e2019-08-14 16:57:11 -07009348 hdwq[idx].io_cq = NULL;
9349 hdwq[idx].io_wq = NULL;
James Smartd79c9e92019-08-14 16:57:09 -07009350 if (phba->cfg_xpsgl && !phba->nvmet_support)
9351 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
9352 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
James Smart895427b2017-02-12 13:52:30 -08009353 }
James Smart657add42019-05-21 17:49:06 -07009354 /* Loop thru all IRQ vectors */
9355 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
9356 /* Free the EQ corresponding to the IRQ vector */
9357 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
9358 lpfc_sli4_queue_free(eq);
9359 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
9360 }
James Smart895427b2017-02-12 13:52:30 -08009361}
9362
James Smartda0436e2009-05-22 14:51:39 -04009363/**
9364 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
9365 * @phba: pointer to lpfc hba data structure.
9366 *
9367 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
9368 * operation.
9369 *
9370 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009371 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009372 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009373 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009374 **/
James Smart5350d872011-10-10 21:33:49 -04009375void
James Smartda0436e2009-05-22 14:51:39 -04009376lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
9377{
James Smart4645f7b2019-03-12 16:30:14 -07009378 /*
9379 * Set FREE_INIT before beginning to free the queues.
9380 * Wait until the users of queues to acknowledge to
9381 * release queues by clearing FREE_WAIT.
9382 */
9383 spin_lock_irq(&phba->hbalock);
9384 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
9385 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
9386 spin_unlock_irq(&phba->hbalock);
9387 msleep(20);
9388 spin_lock_irq(&phba->hbalock);
9389 }
9390 spin_unlock_irq(&phba->hbalock);
9391
James Smart93a4d6f2019-11-04 16:57:05 -08009392 lpfc_sli4_cleanup_poll_list(phba);
9393
James Smart895427b2017-02-12 13:52:30 -08009394 /* Release HBA eqs */
James Smartcdb42be2019-01-28 11:14:21 -08009395 if (phba->sli4_hba.hdwq)
James Smart6a828b02019-01-28 11:14:31 -08009396 lpfc_sli4_release_hdwq(phba);
James Smartda0436e2009-05-22 14:51:39 -04009397
James Smartbcb24f62017-11-20 16:00:36 -08009398 if (phba->nvmet_support) {
9399 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
9400 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08009401
James Smartbcb24f62017-11-20 16:00:36 -08009402 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
9403 phba->cfg_nvmet_mrq);
9404 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
9405 phba->cfg_nvmet_mrq);
9406 }
James Smart2d7dbc42017-02-12 13:52:35 -08009407
James Smartda0436e2009-05-22 14:51:39 -04009408 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009409 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04009410
9411 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08009412 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
9413
9414 /* Release ELS work queue */
9415 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04009416
9417 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009418 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
9419 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04009420
James Smartda0436e2009-05-22 14:51:39 -04009421 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009422 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
9423
9424 /* Release NVME LS complete queue */
9425 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04009426
9427 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009428 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
9429
9430 /* Everything on this list has been freed */
9431 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart4645f7b2019-03-12 16:30:14 -07009432
9433 /* Done with freeing the queues */
9434 spin_lock_irq(&phba->hbalock);
9435 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
9436 spin_unlock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08009437}
9438
9439int
James Smart895427b2017-02-12 13:52:30 -08009440lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
9441{
9442 struct lpfc_rqb *rqbp;
9443 struct lpfc_dmabuf *h_buf;
9444 struct rqb_dmabuf *rqb_buffer;
9445
9446 rqbp = rq->rqbp;
9447 while (!list_empty(&rqbp->rqb_buffer_list)) {
9448 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
9449 struct lpfc_dmabuf, list);
9450
9451 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
9452 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
9453 rqbp->buffer_count--;
9454 }
9455 return 1;
9456}
9457
9458static int
9459lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
9460 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
9461 int qidx, uint32_t qtype)
9462{
9463 struct lpfc_sli_ring *pring;
9464 int rc;
9465
9466 if (!eq || !cq || !wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009467 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009468 "6085 Fast-path %s (%d) not allocated\n",
9469 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
9470 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009471 }
James Smartda0436e2009-05-22 14:51:39 -04009472
James Smart895427b2017-02-12 13:52:30 -08009473 /* create the Cq first */
9474 rc = lpfc_cq_create(phba, cq, eq,
9475 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
9476 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009477 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9478 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
9479 qidx, (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009480 return rc;
9481 }
9482
9483 if (qtype != LPFC_MBOX) {
James Smartcdb42be2019-01-28 11:14:21 -08009484 /* Setup cq_map for fast lookup */
James Smart895427b2017-02-12 13:52:30 -08009485 if (cq_map)
9486 *cq_map = cq->queue_id;
9487
9488 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9489 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
9490 qidx, cq->queue_id, qidx, eq->queue_id);
9491
9492 /* create the wq */
9493 rc = lpfc_wq_create(phba, wq, cq, qtype);
9494 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009495 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc835c082019-03-12 16:30:30 -07009496 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -08009497 qidx, (uint32_t)rc);
9498 /* no need to tear down cq - caller will do so */
9499 return rc;
9500 }
9501
9502 /* Bind this CQ/WQ to the NVME ring */
9503 pring = wq->pring;
9504 pring->sli.sli4.wqp = (void *)wq;
9505 cq->pring = pring;
9506
9507 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9508 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
9509 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
9510 } else {
9511 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
9512 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009513 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9514 "0539 Failed setup of slow-path MQ: "
9515 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009516 /* no need to tear down cq - caller will do so */
9517 return rc;
9518 }
9519
9520 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9521 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
9522 phba->sli4_hba.mbx_wq->queue_id,
9523 phba->sli4_hba.mbx_cq->queue_id);
9524 }
9525
9526 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009527}
9528
9529/**
James Smart6a828b02019-01-28 11:14:31 -08009530 * lpfc_setup_cq_lookup - Setup the CQ lookup table
9531 * @phba: pointer to lpfc hba data structure.
9532 *
9533 * This routine will populate the cq_lookup table by all
9534 * available CQ queue_id's.
9535 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07009536static void
James Smart6a828b02019-01-28 11:14:31 -08009537lpfc_setup_cq_lookup(struct lpfc_hba *phba)
9538{
9539 struct lpfc_queue *eq, *childq;
James Smart6a828b02019-01-28 11:14:31 -08009540 int qidx;
9541
James Smart6a828b02019-01-28 11:14:31 -08009542 memset(phba->sli4_hba.cq_lookup, 0,
9543 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
James Smart657add42019-05-21 17:49:06 -07009544 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009545 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009546 /* Get the EQ corresponding to the IRQ vector */
9547 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
James Smart6a828b02019-01-28 11:14:31 -08009548 if (!eq)
9549 continue;
James Smart657add42019-05-21 17:49:06 -07009550 /* Loop through all CQs associated with that EQ */
James Smart6a828b02019-01-28 11:14:31 -08009551 list_for_each_entry(childq, &eq->child_list, list) {
9552 if (childq->queue_id > phba->sli4_hba.cq_max)
9553 continue;
James Smartc00f62e2019-08-14 16:57:11 -07009554 if (childq->subtype == LPFC_IO)
James Smart6a828b02019-01-28 11:14:31 -08009555 phba->sli4_hba.cq_lookup[childq->queue_id] =
9556 childq;
9557 }
9558 }
9559}
9560
9561/**
James Smartda0436e2009-05-22 14:51:39 -04009562 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
9563 * @phba: pointer to lpfc hba data structure.
9564 *
9565 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
9566 * operation.
9567 *
9568 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009569 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009570 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009571 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009572 **/
9573int
9574lpfc_sli4_queue_setup(struct lpfc_hba *phba)
9575{
James Smart962bc512013-01-03 15:44:00 -05009576 uint32_t shdr_status, shdr_add_status;
9577 union lpfc_sli4_cfg_shdr *shdr;
James Smart657add42019-05-21 17:49:06 -07009578 struct lpfc_vector_map_info *cpup;
James Smartcdb42be2019-01-28 11:14:21 -08009579 struct lpfc_sli4_hdw_queue *qp;
James Smart962bc512013-01-03 15:44:00 -05009580 LPFC_MBOXQ_t *mboxq;
James Smart657add42019-05-21 17:49:06 -07009581 int qidx, cpu;
James Smartcb733e32019-01-28 11:14:32 -08009582 uint32_t length, usdelay;
James Smart895427b2017-02-12 13:52:30 -08009583 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05009584
9585 /* Check for dual-ULP support */
9586 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9587 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009588 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart962bc512013-01-03 15:44:00 -05009589 "3249 Unable to allocate memory for "
9590 "QUERY_FW_CFG mailbox command\n");
9591 return -ENOMEM;
9592 }
9593 length = (sizeof(struct lpfc_mbx_query_fw_config) -
9594 sizeof(struct lpfc_sli4_cfg_mhdr));
9595 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9596 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
9597 length, LPFC_SLI4_MBX_EMBED);
9598
9599 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9600
9601 shdr = (union lpfc_sli4_cfg_shdr *)
9602 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9603 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9604 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9605 if (shdr_status || shdr_add_status || rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009606 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart962bc512013-01-03 15:44:00 -05009607 "3250 QUERY_FW_CFG mailbox failed with status "
9608 "x%x add_status x%x, mbx status x%x\n",
9609 shdr_status, shdr_add_status, rc);
9610 if (rc != MBX_TIMEOUT)
9611 mempool_free(mboxq, phba->mbox_mem_pool);
9612 rc = -ENXIO;
9613 goto out_error;
9614 }
9615
9616 phba->sli4_hba.fw_func_mode =
9617 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9618 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9619 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04009620 phba->sli4_hba.physical_port =
9621 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05009622 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9623 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9624 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9625 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9626
9627 if (rc != MBX_TIMEOUT)
9628 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04009629
9630 /*
James Smart67d12732012-08-03 12:36:13 -04009631 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04009632 */
James Smartcdb42be2019-01-28 11:14:21 -08009633 qp = phba->sli4_hba.hdwq;
James Smartda0436e2009-05-22 14:51:39 -04009634
James Smart67d12732012-08-03 12:36:13 -04009635 /* Set up HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -08009636 if (!qp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009637 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -05009638 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009639 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009640 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05009641 }
James Smart657add42019-05-21 17:49:06 -07009642
9643 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009644 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009645 /* Create HBA Event Queues (EQs) in order */
9646 for_each_present_cpu(cpu) {
9647 cpup = &phba->sli4_hba.cpu_map[cpu];
9648
9649 /* Look for the CPU thats using that vector with
9650 * LPFC_CPU_FIRST_IRQ set.
9651 */
9652 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
9653 continue;
9654 if (qidx != cpup->eq)
9655 continue;
9656
9657 /* Create an EQ for that vector */
9658 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
9659 phba->cfg_fcp_imax);
9660 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009661 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart657add42019-05-21 17:49:06 -07009662 "0523 Failed setup of fast-path"
9663 " EQ (%d), rc = 0x%x\n",
9664 cpup->eq, (uint32_t)rc);
9665 goto out_destroy;
9666 }
9667
9668 /* Save the EQ for that vector in the hba_eq_hdl */
9669 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
9670 qp[cpup->hdwq].hba_eq;
9671
9672 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9673 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9674 cpup->eq,
9675 qp[cpup->hdwq].hba_eq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04009676 }
James Smartda0436e2009-05-22 14:51:39 -04009677 }
9678
James Smart657add42019-05-21 17:49:06 -07009679 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009680 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009681 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
9682 cpup = &phba->sli4_hba.cpu_map[cpu];
9683
9684 /* Create the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009685 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -07009686 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartc00f62e2019-08-14 16:57:11 -07009687 qp[qidx].io_cq,
9688 qp[qidx].io_wq,
9689 &phba->sli4_hba.hdwq[qidx].io_cq_map,
9690 qidx,
9691 LPFC_IO);
James Smartcdb42be2019-01-28 11:14:21 -08009692 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009693 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009694 "0535 Failed to setup fastpath "
James Smartc00f62e2019-08-14 16:57:11 -07009695 "IO WQ/CQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -08009696 qidx, (uint32_t)rc);
James Smartcdb42be2019-01-28 11:14:21 -08009697 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009698 }
James Smart67d12732012-08-03 12:36:13 -04009699 }
James Smartda0436e2009-05-22 14:51:39 -04009700
9701 /*
James Smart895427b2017-02-12 13:52:30 -08009702 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009703 */
9704
James Smart895427b2017-02-12 13:52:30 -08009705 /* Set up slow-path MBOX CQ/MQ */
9706
9707 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009708 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009709 "0528 %s not allocated\n",
9710 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07009711 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05009712 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009713 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009714 }
James Smart895427b2017-02-12 13:52:30 -08009715
James Smartcdb42be2019-01-28 11:14:21 -08009716 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
James Smartd1f525a2017-04-21 16:04:55 -07009717 phba->sli4_hba.mbx_cq,
9718 phba->sli4_hba.mbx_wq,
9719 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04009720 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009721 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009722 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9723 (uint32_t)rc);
9724 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009725 }
James Smart2d7dbc42017-02-12 13:52:35 -08009726 if (phba->nvmet_support) {
9727 if (!phba->sli4_hba.nvmet_cqset) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009728 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009729 "3165 Fast-path NVME CQ Set "
9730 "array not allocated\n");
9731 rc = -ENOMEM;
9732 goto out_destroy;
9733 }
9734 if (phba->cfg_nvmet_mrq > 1) {
9735 rc = lpfc_cq_create_set(phba,
9736 phba->sli4_hba.nvmet_cqset,
James Smartcdb42be2019-01-28 11:14:21 -08009737 qp,
James Smart2d7dbc42017-02-12 13:52:35 -08009738 LPFC_WCQ, LPFC_NVMET);
9739 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009740 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009741 "3164 Failed setup of NVME CQ "
9742 "Set, rc = 0x%x\n",
9743 (uint32_t)rc);
9744 goto out_destroy;
9745 }
9746 } else {
9747 /* Set up NVMET Receive Complete Queue */
9748 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
James Smartcdb42be2019-01-28 11:14:21 -08009749 qp[0].hba_eq,
James Smart2d7dbc42017-02-12 13:52:35 -08009750 LPFC_WCQ, LPFC_NVMET);
9751 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009752 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009753 "6089 Failed setup NVMET CQ: "
9754 "rc = 0x%x\n", (uint32_t)rc);
9755 goto out_destroy;
9756 }
James Smart81b96ed2017-11-20 16:00:29 -08009757 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9758
James Smart2d7dbc42017-02-12 13:52:35 -08009759 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9760 "6090 NVMET CQ setup: cq-id=%d, "
9761 "parent eq-id=%d\n",
9762 phba->sli4_hba.nvmet_cqset[0]->queue_id,
James Smartcdb42be2019-01-28 11:14:21 -08009763 qp[0].hba_eq->queue_id);
James Smart2d7dbc42017-02-12 13:52:35 -08009764 }
9765 }
James Smartda0436e2009-05-22 14:51:39 -04009766
James Smart895427b2017-02-12 13:52:30 -08009767 /* Set up slow-path ELS WQ/CQ */
9768 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009769 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009770 "0530 ELS %s not allocated\n",
9771 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009772 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009773 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009774 }
James Smartcdb42be2019-01-28 11:14:21 -08009775 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9776 phba->sli4_hba.els_cq,
9777 phba->sli4_hba.els_wq,
9778 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009779 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009780 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -08009781 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9782 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009783 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009784 }
9785 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9786 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9787 phba->sli4_hba.els_wq->queue_id,
9788 phba->sli4_hba.els_cq->queue_id);
9789
James Smartcdb42be2019-01-28 11:14:21 -08009790 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -08009791 /* Set up NVME LS Complete Queue */
9792 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -08009794 "6091 LS %s not allocated\n",
9795 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9796 rc = -ENOMEM;
9797 goto out_destroy;
9798 }
James Smartcdb42be2019-01-28 11:14:21 -08009799 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9800 phba->sli4_hba.nvmels_cq,
9801 phba->sli4_hba.nvmels_wq,
9802 NULL, 0, LPFC_NVME_LS);
James Smart895427b2017-02-12 13:52:30 -08009803 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009804 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -08009805 "0526 Failed setup of NVVME LS WQ/CQ: "
9806 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009807 goto out_destroy;
9808 }
9809
9810 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9811 "6096 ELS WQ setup: wq-id=%d, "
9812 "parent cq-id=%d\n",
9813 phba->sli4_hba.nvmels_wq->queue_id,
9814 phba->sli4_hba.nvmels_cq->queue_id);
9815 }
9816
James Smart2d7dbc42017-02-12 13:52:35 -08009817 /*
9818 * Create NVMET Receive Queue (RQ)
9819 */
9820 if (phba->nvmet_support) {
9821 if ((!phba->sli4_hba.nvmet_cqset) ||
9822 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9823 (!phba->sli4_hba.nvmet_mrq_data)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009824 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009825 "6130 MRQ CQ Queues not "
9826 "allocated\n");
9827 rc = -ENOMEM;
9828 goto out_destroy;
9829 }
9830 if (phba->cfg_nvmet_mrq > 1) {
9831 rc = lpfc_mrq_create(phba,
9832 phba->sli4_hba.nvmet_mrq_hdr,
9833 phba->sli4_hba.nvmet_mrq_data,
9834 phba->sli4_hba.nvmet_cqset,
9835 LPFC_NVMET);
9836 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009837 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009838 "6098 Failed setup of NVMET "
9839 "MRQ: rc = 0x%x\n",
9840 (uint32_t)rc);
9841 goto out_destroy;
9842 }
9843
9844 } else {
9845 rc = lpfc_rq_create(phba,
9846 phba->sli4_hba.nvmet_mrq_hdr[0],
9847 phba->sli4_hba.nvmet_mrq_data[0],
9848 phba->sli4_hba.nvmet_cqset[0],
9849 LPFC_NVMET);
9850 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009851 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -08009852 "6057 Failed setup of NVMET "
9853 "Receive Queue: rc = 0x%x\n",
9854 (uint32_t)rc);
9855 goto out_destroy;
9856 }
9857
9858 lpfc_printf_log(
9859 phba, KERN_INFO, LOG_INIT,
9860 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9861 "dat-rq-id=%d parent cq-id=%d\n",
9862 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9863 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9864 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9865
9866 }
9867 }
9868
James Smartda0436e2009-05-22 14:51:39 -04009869 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009870 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009871 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009872 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009873 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009874 }
James Smart73d91e52011-10-10 21:32:10 -04009875
James Smartda0436e2009-05-22 14:51:39 -04009876 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009877 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009878 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009879 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009880 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009881 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009882 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009883 }
James Smart73d91e52011-10-10 21:32:10 -04009884
James Smartda0436e2009-05-22 14:51:39 -04009885 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9886 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9887 "parent cq-id=%d\n",
9888 phba->sli4_hba.hdr_rq->queue_id,
9889 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009890 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009891
James Smartcb733e32019-01-28 11:14:32 -08009892 if (phba->cfg_fcp_imax)
9893 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
9894 else
9895 usdelay = 0;
9896
James Smart6a828b02019-01-28 11:14:31 -08009897 for (qidx = 0; qidx < phba->cfg_irq_chann;
James Smartcdb42be2019-01-28 11:14:21 -08009898 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009899 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -08009900 usdelay);
James Smart43140ca2017-03-04 09:30:34 -08009901
James Smart6a828b02019-01-28 11:14:31 -08009902 if (phba->sli4_hba.cq_max) {
9903 kfree(phba->sli4_hba.cq_lookup);
9904 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
9905 sizeof(struct lpfc_queue *), GFP_KERNEL);
9906 if (!phba->sli4_hba.cq_lookup) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009907 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6a828b02019-01-28 11:14:31 -08009908 "0549 Failed setup of CQ Lookup table: "
9909 "size 0x%x\n", phba->sli4_hba.cq_max);
Dan Carpenterfad28e32019-02-11 21:43:00 +03009910 rc = -ENOMEM;
James Smart1ba981f2014-02-20 09:56:45 -05009911 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009912 }
James Smart6a828b02019-01-28 11:14:31 -08009913 lpfc_setup_cq_lookup(phba);
James Smart1ba981f2014-02-20 09:56:45 -05009914 }
James Smartda0436e2009-05-22 14:51:39 -04009915 return 0;
9916
James Smart895427b2017-02-12 13:52:30 -08009917out_destroy:
9918 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009919out_error:
9920 return rc;
9921}
9922
9923/**
9924 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9925 * @phba: pointer to lpfc hba data structure.
9926 *
9927 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9928 * operation.
9929 *
9930 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009931 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009932 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009933 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009934 **/
9935void
9936lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9937{
James Smartcdb42be2019-01-28 11:14:21 -08009938 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07009939 struct lpfc_queue *eq;
James Smart895427b2017-02-12 13:52:30 -08009940 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009941
9942 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009943 if (phba->sli4_hba.mbx_wq)
9944 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9945
9946 /* Unset NVME LS work queue */
9947 if (phba->sli4_hba.nvmels_wq)
9948 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9949
James Smartda0436e2009-05-22 14:51:39 -04009950 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009951 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009952 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9953
James Smartda0436e2009-05-22 14:51:39 -04009954 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009955 if (phba->sli4_hba.hdr_rq)
9956 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9957 phba->sli4_hba.dat_rq);
9958
James Smartda0436e2009-05-22 14:51:39 -04009959 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009960 if (phba->sli4_hba.mbx_cq)
9961 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9962
James Smartda0436e2009-05-22 14:51:39 -04009963 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009964 if (phba->sli4_hba.els_cq)
9965 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9966
9967 /* Unset NVME LS complete queue */
9968 if (phba->sli4_hba.nvmels_cq)
9969 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9970
James Smartbcb24f62017-11-20 16:00:36 -08009971 if (phba->nvmet_support) {
9972 /* Unset NVMET MRQ queue */
9973 if (phba->sli4_hba.nvmet_mrq_hdr) {
9974 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9975 lpfc_rq_destroy(
9976 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009977 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9978 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009979 }
James Smart2d7dbc42017-02-12 13:52:35 -08009980
James Smartbcb24f62017-11-20 16:00:36 -08009981 /* Unset NVMET CQ Set complete queue */
9982 if (phba->sli4_hba.nvmet_cqset) {
9983 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9984 lpfc_cq_destroy(
9985 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9986 }
James Smart2d7dbc42017-02-12 13:52:35 -08009987 }
9988
James Smartcdb42be2019-01-28 11:14:21 -08009989 /* Unset fast-path SLI4 queues */
9990 if (phba->sli4_hba.hdwq) {
James Smart657add42019-05-21 17:49:06 -07009991 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009992 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009993 /* Destroy the CQ/WQ corresponding to Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009994 qp = &phba->sli4_hba.hdwq[qidx];
James Smartc00f62e2019-08-14 16:57:11 -07009995 lpfc_wq_destroy(phba, qp->io_wq);
9996 lpfc_cq_destroy(phba, qp->io_cq);
James Smart657add42019-05-21 17:49:06 -07009997 }
9998 /* Loop thru all IRQ vectors */
9999 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
10000 /* Destroy the EQ corresponding to the IRQ vector */
10001 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
10002 lpfc_eq_destroy(phba, eq);
James Smartcdb42be2019-01-28 11:14:21 -080010003 }
10004 }
James Smart895427b2017-02-12 13:52:30 -080010005
James Smart6a828b02019-01-28 11:14:31 -080010006 kfree(phba->sli4_hba.cq_lookup);
10007 phba->sli4_hba.cq_lookup = NULL;
10008 phba->sli4_hba.cq_max = 0;
James Smartda0436e2009-05-22 14:51:39 -040010009}
10010
10011/**
10012 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
10013 * @phba: pointer to lpfc hba data structure.
10014 *
10015 * This routine is invoked to allocate and set up a pool of completion queue
10016 * events. The body of the completion queue event is a completion queue entry
10017 * CQE. For now, this pool is used for the interrupt service routine to queue
10018 * the following HBA completion queue events for the worker thread to process:
10019 * - Mailbox asynchronous events
10020 * - Receive queue completion unsolicited events
10021 * Later, this can be used for all the slow-path events.
10022 *
10023 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010024 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010025 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -040010026 **/
10027static int
10028lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
10029{
10030 struct lpfc_cq_event *cq_event;
10031 int i;
10032
10033 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
10034 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
10035 if (!cq_event)
10036 goto out_pool_create_fail;
10037 list_add_tail(&cq_event->list,
10038 &phba->sli4_hba.sp_cqe_event_pool);
10039 }
10040 return 0;
10041
10042out_pool_create_fail:
10043 lpfc_sli4_cq_event_pool_destroy(phba);
10044 return -ENOMEM;
10045}
10046
10047/**
10048 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
10049 * @phba: pointer to lpfc hba data structure.
10050 *
10051 * This routine is invoked to free the pool of completion queue events at
10052 * driver unload time. Note that, it is the responsibility of the driver
10053 * cleanup routine to free all the outstanding completion-queue events
10054 * allocated from this pool back into the pool before invoking this routine
10055 * to destroy the pool.
10056 **/
10057static void
10058lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
10059{
10060 struct lpfc_cq_event *cq_event, *next_cq_event;
10061
10062 list_for_each_entry_safe(cq_event, next_cq_event,
10063 &phba->sli4_hba.sp_cqe_event_pool, list) {
10064 list_del(&cq_event->list);
10065 kfree(cq_event);
10066 }
10067}
10068
10069/**
10070 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10071 * @phba: pointer to lpfc hba data structure.
10072 *
10073 * This routine is the lock free version of the API invoked to allocate a
10074 * completion-queue event from the free pool.
10075 *
10076 * Return: Pointer to the newly allocated completion-queue event if successful
10077 * NULL otherwise.
10078 **/
10079struct lpfc_cq_event *
10080__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
10081{
10082 struct lpfc_cq_event *cq_event = NULL;
10083
10084 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
10085 struct lpfc_cq_event, list);
10086 return cq_event;
10087}
10088
10089/**
10090 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
10091 * @phba: pointer to lpfc hba data structure.
10092 *
10093 * This routine is the lock version of the API invoked to allocate a
10094 * completion-queue event from the free pool.
10095 *
10096 * Return: Pointer to the newly allocated completion-queue event if successful
10097 * NULL otherwise.
10098 **/
10099struct lpfc_cq_event *
10100lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
10101{
10102 struct lpfc_cq_event *cq_event;
10103 unsigned long iflags;
10104
10105 spin_lock_irqsave(&phba->hbalock, iflags);
10106 cq_event = __lpfc_sli4_cq_event_alloc(phba);
10107 spin_unlock_irqrestore(&phba->hbalock, iflags);
10108 return cq_event;
10109}
10110
10111/**
10112 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10113 * @phba: pointer to lpfc hba data structure.
10114 * @cq_event: pointer to the completion queue event to be freed.
10115 *
10116 * This routine is the lock free version of the API invoked to release a
10117 * completion-queue event back into the free pool.
10118 **/
10119void
10120__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10121 struct lpfc_cq_event *cq_event)
10122{
10123 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
10124}
10125
10126/**
10127 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
10128 * @phba: pointer to lpfc hba data structure.
10129 * @cq_event: pointer to the completion queue event to be freed.
10130 *
10131 * This routine is the lock version of the API invoked to release a
10132 * completion-queue event back into the free pool.
10133 **/
10134void
10135lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
10136 struct lpfc_cq_event *cq_event)
10137{
10138 unsigned long iflags;
10139 spin_lock_irqsave(&phba->hbalock, iflags);
10140 __lpfc_sli4_cq_event_release(phba, cq_event);
10141 spin_unlock_irqrestore(&phba->hbalock, iflags);
10142}
10143
10144/**
10145 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
10146 * @phba: pointer to lpfc hba data structure.
10147 *
10148 * This routine is to free all the pending completion-queue events to the
10149 * back into the free pool for device reset.
10150 **/
10151static void
10152lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
10153{
James Smarte7dab162020-10-20 13:27:12 -070010154 LIST_HEAD(cq_event_list);
10155 struct lpfc_cq_event *cq_event;
James Smartda0436e2009-05-22 14:51:39 -040010156 unsigned long iflags;
10157
10158 /* Retrieve all the pending WCQEs from pending WCQE lists */
James Smartda0436e2009-05-22 14:51:39 -040010159
James Smarte7dab162020-10-20 13:27:12 -070010160 /* Pending ELS XRI abort events */
10161 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
10162 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10163 &cq_event_list);
10164 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
10165
10166 /* Pending asynnc events */
10167 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
10168 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
10169 &cq_event_list);
10170 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
10171
10172 while (!list_empty(&cq_event_list)) {
10173 list_remove_head(&cq_event_list, cq_event,
10174 struct lpfc_cq_event, list);
10175 lpfc_sli4_cq_event_release(phba, cq_event);
James Smartda0436e2009-05-22 14:51:39 -040010176 }
10177}
10178
10179/**
10180 * lpfc_pci_function_reset - Reset pci function.
10181 * @phba: pointer to lpfc hba data structure.
10182 *
10183 * This routine is invoked to request a PCI function reset. It will destroys
10184 * all resources assigned to the PCI function which originates this request.
10185 *
10186 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010187 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010188 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010189 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010190 **/
10191int
10192lpfc_pci_function_reset(struct lpfc_hba *phba)
10193{
10194 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -050010195 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -040010196 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -040010197 uint32_t rdy_chk;
10198 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -040010199 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -050010200 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -050010201 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -040010202
James Smart2fcee4b2010-12-15 17:57:46 -050010203 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10204 switch (if_type) {
10205 case LPFC_SLI_INTF_IF_TYPE_0:
10206 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10207 GFP_KERNEL);
10208 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010209 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050010210 "0494 Unable to allocate memory for "
10211 "issuing SLI_FUNCTION_RESET mailbox "
10212 "command\n");
10213 return -ENOMEM;
10214 }
10215
10216 /* Setup PCI function reset mailbox-ioctl command */
10217 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10218 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
10219 LPFC_SLI4_MBX_EMBED);
10220 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10221 shdr = (union lpfc_sli4_cfg_shdr *)
10222 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10223 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10224 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
10225 &shdr->response);
10226 if (rc != MBX_TIMEOUT)
10227 mempool_free(mboxq, phba->mbox_mem_pool);
10228 if (shdr_status || shdr_add_status || rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010229 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050010230 "0495 SLI_FUNCTION_RESET mailbox "
10231 "failed with status x%x add_status x%x,"
10232 " mbx status x%x\n",
10233 shdr_status, shdr_add_status, rc);
10234 rc = -ENXIO;
10235 }
10236 break;
10237 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -080010238 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -040010239wait:
10240 /*
10241 * Poll the Port Status Register and wait for RDY for
10242 * up to 30 seconds. If the port doesn't respond, treat
10243 * it as an error.
10244 */
James Smart77d093f2015-04-07 15:07:08 -040010245 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -040010246 if (lpfc_readl(phba->sli4_hba.u.if_type2.
10247 STATUSregaddr, &reg_data.word0)) {
10248 rc = -ENODEV;
10249 goto out;
10250 }
10251 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
10252 break;
10253 msleep(20);
10254 }
10255
10256 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
10257 phba->work_status[0] = readl(
10258 phba->sli4_hba.u.if_type2.ERR1regaddr);
10259 phba->work_status[1] = readl(
10260 phba->sli4_hba.u.if_type2.ERR2regaddr);
Dick Kennedy372c1872020-06-30 14:50:00 -070010261 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2f6fa2c2014-09-03 12:57:08 -040010262 "2890 Port not ready, port status reg "
10263 "0x%x error 1=0x%x, error 2=0x%x\n",
10264 reg_data.word0,
10265 phba->work_status[0],
10266 phba->work_status[1]);
10267 rc = -ENODEV;
10268 goto out;
10269 }
10270
10271 if (!port_reset) {
10272 /*
10273 * Reset the port now
10274 */
James Smart2fcee4b2010-12-15 17:57:46 -050010275 reg_data.word0 = 0;
10276 bf_set(lpfc_sliport_ctrl_end, &reg_data,
10277 LPFC_SLIPORT_LITTLE_ENDIAN);
10278 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
10279 LPFC_SLIPORT_INIT_PORT);
10280 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
10281 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -050010282 /* flush */
James Smart2b81f942012-03-01 22:37:18 -050010283 pci_read_config_word(phba->pcidev,
10284 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -050010285
James Smart2f6fa2c2014-09-03 12:57:08 -040010286 port_reset = 1;
10287 msleep(20);
10288 goto wait;
10289 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
10290 rc = -ENODEV;
10291 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -050010292 }
10293 break;
James Smart2f6fa2c2014-09-03 12:57:08 -040010294
James Smart2fcee4b2010-12-15 17:57:46 -050010295 case LPFC_SLI_INTF_IF_TYPE_1:
10296 default:
10297 break;
James Smartda0436e2009-05-22 14:51:39 -040010298 }
10299
James Smart73d91e52011-10-10 21:32:10 -040010300out:
James Smart2fcee4b2010-12-15 17:57:46 -050010301 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -040010302 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010303 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart229adb02013-04-17 20:16:51 -040010304 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -040010305 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -050010306 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -040010307 }
James Smart2fcee4b2010-12-15 17:57:46 -050010308
James Smartda0436e2009-05-22 14:51:39 -040010309 return rc;
10310}
10311
10312/**
James Smartda0436e2009-05-22 14:51:39 -040010313 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
10314 * @phba: pointer to lpfc hba data structure.
10315 *
10316 * This routine is invoked to set up the PCI device memory space for device
10317 * with SLI-4 interface spec.
10318 *
10319 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010320 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010321 * other values - error
10322 **/
10323static int
10324lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10325{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010326 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010327 unsigned long bar0map_len, bar1map_len, bar2map_len;
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010328 int error;
James Smart2fcee4b2010-12-15 17:57:46 -050010329 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -040010330
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010331 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +010010332 return -ENODEV;
James Smartda0436e2009-05-22 14:51:39 -040010333
10334 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +010010335 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
10336 if (error)
10337 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10338 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010339 return error;
James Smartda0436e2009-05-22 14:51:39 -040010340
James Smart2fcee4b2010-12-15 17:57:46 -050010341 /*
10342 * The BARs and register set definitions and offset locations are
10343 * dependent on the if_type.
10344 */
10345 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
10346 &phba->sli4_hba.sli_intf.word0)) {
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010347 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010348 }
10349
10350 /* There is no SLI3 failback for SLI4 devices. */
10351 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
10352 LPFC_SLI_INTF_VALID) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010353 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050010354 "2894 SLI_INTF reg contents invalid "
10355 "sli_intf reg 0x%x\n",
10356 phba->sli4_hba.sli_intf.word0);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010357 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010358 }
10359
10360 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10361 /*
10362 * Get the bus address of SLI4 device Bar regions and the
10363 * number of bytes required by each mapping. The mapping of the
10364 * particular PCI BARs regions is dependent on the type of
10365 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -040010366 */
James Smartf5ca6f22013-09-06 12:21:09 -040010367 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
10368 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
10369 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -050010370
10371 /*
10372 * Map SLI4 PCI Config Space Register base to a kernel virtual
10373 * addr
10374 */
10375 phba->sli4_hba.conf_regs_memmap_p =
10376 ioremap(phba->pci_bar0_map, bar0map_len);
10377 if (!phba->sli4_hba.conf_regs_memmap_p) {
10378 dev_printk(KERN_ERR, &pdev->dev,
10379 "ioremap failed for SLI4 PCI config "
10380 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010381 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010382 }
James Smartf5ca6f22013-09-06 12:21:09 -040010383 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -050010384 /* Set up BAR0 PCI config space register memory map */
10385 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -050010386 } else {
10387 phba->pci_bar0_map = pci_resource_start(pdev, 1);
10388 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -080010389 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -050010390 dev_printk(KERN_ERR, &pdev->dev,
10391 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010392 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010393 }
10394 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -040010395 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -050010396 if (!phba->sli4_hba.conf_regs_memmap_p) {
10397 dev_printk(KERN_ERR, &pdev->dev,
10398 "ioremap failed for SLI4 PCI config "
10399 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010400 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010401 }
10402 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -040010403 }
10404
James Smarte4b97942017-11-20 16:00:31 -080010405 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10406 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
10407 /*
10408 * Map SLI4 if type 0 HBA Control Register base to a
10409 * kernel virtual address and setup the registers.
10410 */
10411 phba->pci_bar1_map = pci_resource_start(pdev,
10412 PCI_64BIT_BAR2);
10413 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10414 phba->sli4_hba.ctrl_regs_memmap_p =
10415 ioremap(phba->pci_bar1_map,
10416 bar1map_len);
10417 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
10418 dev_err(&pdev->dev,
10419 "ioremap failed for SLI4 HBA "
10420 "control registers.\n");
10421 error = -ENOMEM;
10422 goto out_iounmap_conf;
10423 }
10424 phba->pci_bar2_memmap_p =
10425 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -080010426 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -080010427 } else {
10428 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010429 goto out_iounmap_conf;
10430 }
James Smartda0436e2009-05-22 14:51:39 -040010431 }
10432
James Smart27d6ac02018-02-22 08:18:42 -080010433 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
10434 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
10435 /*
10436 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
10437 * virtual address and setup the registers.
10438 */
10439 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
10440 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10441 phba->sli4_hba.drbl_regs_memmap_p =
10442 ioremap(phba->pci_bar1_map, bar1map_len);
10443 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10444 dev_err(&pdev->dev,
10445 "ioremap failed for SLI4 HBA doorbell registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010446 error = -ENOMEM;
James Smart27d6ac02018-02-22 08:18:42 -080010447 goto out_iounmap_conf;
10448 }
10449 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
10450 lpfc_sli4_bar1_register_memmap(phba, if_type);
10451 }
10452
James Smarte4b97942017-11-20 16:00:31 -080010453 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10454 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10455 /*
10456 * Map SLI4 if type 0 HBA Doorbell Register base to
10457 * a kernel virtual address and setup the registers.
10458 */
10459 phba->pci_bar2_map = pci_resource_start(pdev,
10460 PCI_64BIT_BAR4);
10461 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10462 phba->sli4_hba.drbl_regs_memmap_p =
10463 ioremap(phba->pci_bar2_map,
10464 bar2map_len);
10465 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10466 dev_err(&pdev->dev,
10467 "ioremap failed for SLI4 HBA"
10468 " doorbell registers.\n");
10469 error = -ENOMEM;
10470 goto out_iounmap_ctrl;
10471 }
10472 phba->pci_bar4_memmap_p =
10473 phba->sli4_hba.drbl_regs_memmap_p;
10474 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
10475 if (error)
10476 goto out_iounmap_all;
10477 } else {
10478 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010479 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -080010480 }
James Smartda0436e2009-05-22 14:51:39 -040010481 }
10482
James Smart1351e692018-02-22 08:18:43 -080010483 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
10484 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10485 /*
10486 * Map SLI4 if type 6 HBA DPP Register base to a kernel
10487 * virtual address and setup the registers.
10488 */
10489 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
10490 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10491 phba->sli4_hba.dpp_regs_memmap_p =
10492 ioremap(phba->pci_bar2_map, bar2map_len);
10493 if (!phba->sli4_hba.dpp_regs_memmap_p) {
10494 dev_err(&pdev->dev,
10495 "ioremap failed for SLI4 HBA dpp registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010496 error = -ENOMEM;
James Smart1351e692018-02-22 08:18:43 -080010497 goto out_iounmap_ctrl;
10498 }
10499 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
10500 }
10501
James Smartb71413d2018-02-22 08:18:40 -080010502 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -080010503 switch (if_type) {
10504 case LPFC_SLI_INTF_IF_TYPE_0:
10505 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -080010506 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010507 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
10508 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010509 break;
10510 case LPFC_SLI_INTF_IF_TYPE_6:
10511 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010512 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
10513 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010514 break;
10515 default:
10516 break;
James Smartb71413d2018-02-22 08:18:40 -080010517 }
10518
James Smartda0436e2009-05-22 14:51:39 -040010519 return 0;
10520
10521out_iounmap_all:
10522 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10523out_iounmap_ctrl:
10524 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10525out_iounmap_conf:
10526 iounmap(phba->sli4_hba.conf_regs_memmap_p);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010527
James Smartda0436e2009-05-22 14:51:39 -040010528 return error;
10529}
10530
10531/**
10532 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
10533 * @phba: pointer to lpfc hba data structure.
10534 *
10535 * This routine is invoked to unset the PCI device memory space for device
10536 * with SLI-4 interface spec.
10537 **/
10538static void
10539lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
10540{
James Smart2e90f4b2011-12-13 13:22:37 -050010541 uint32_t if_type;
10542 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -040010543
James Smart2e90f4b2011-12-13 13:22:37 -050010544 switch (if_type) {
10545 case LPFC_SLI_INTF_IF_TYPE_0:
10546 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10547 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10548 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10549 break;
10550 case LPFC_SLI_INTF_IF_TYPE_2:
10551 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10552 break;
James Smart27d6ac02018-02-22 08:18:42 -080010553 case LPFC_SLI_INTF_IF_TYPE_6:
10554 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10555 iounmap(phba->sli4_hba.conf_regs_memmap_p);
James Smart0b439192019-12-18 15:58:05 -080010556 if (phba->sli4_hba.dpp_regs_memmap_p)
10557 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
James Smart27d6ac02018-02-22 08:18:42 -080010558 break;
James Smart2e90f4b2011-12-13 13:22:37 -050010559 case LPFC_SLI_INTF_IF_TYPE_1:
10560 default:
10561 dev_printk(KERN_ERR, &phba->pcidev->dev,
10562 "FATAL - unsupported SLI4 interface type - %d\n",
10563 if_type);
10564 break;
10565 }
James Smartda0436e2009-05-22 14:51:39 -040010566}
10567
10568/**
James Smart3772a992009-05-22 14:50:54 -040010569 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
10570 * @phba: pointer to lpfc hba data structure.
10571 *
10572 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010573 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -040010574 *
10575 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010576 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010577 * other values - error
10578 **/
10579static int
10580lpfc_sli_enable_msix(struct lpfc_hba *phba)
10581{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010582 int rc;
James Smart3772a992009-05-22 14:50:54 -040010583 LPFC_MBOXQ_t *pmb;
10584
10585 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010586 rc = pci_alloc_irq_vectors(phba->pcidev,
10587 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
10588 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -040010589 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10590 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010591 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -040010592 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010593
James Smart3772a992009-05-22 14:50:54 -040010594 /*
10595 * Assign MSI-X vectors to interrupt handlers
10596 */
10597
10598 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010599 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040010600 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010601 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10602 if (rc) {
10603 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10604 "0421 MSI-X slow-path request_irq failed "
10605 "(%d)\n", rc);
10606 goto msi_fail_out;
10607 }
10608
10609 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010610 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040010611 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010612 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10613
10614 if (rc) {
10615 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10616 "0429 MSI-X fast-path request_irq failed "
10617 "(%d)\n", rc);
10618 goto irq_fail_out;
10619 }
10620
10621 /*
10622 * Configure HBA MSI-X attention conditions to messages
10623 */
10624 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10625
10626 if (!pmb) {
10627 rc = -ENOMEM;
Dick Kennedy372c1872020-06-30 14:50:00 -070010628 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040010629 "0474 Unable to allocate memory for issuing "
10630 "MBOX_CONFIG_MSI command\n");
10631 goto mem_fail_out;
10632 }
10633 rc = lpfc_config_msi(phba, pmb);
10634 if (rc)
10635 goto mbx_fail_out;
10636 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10637 if (rc != MBX_SUCCESS) {
10638 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10639 "0351 Config MSI mailbox command failed, "
10640 "mbxCmd x%x, mbxStatus x%x\n",
10641 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10642 goto mbx_fail_out;
10643 }
10644
10645 /* Free memory allocated for mailbox command */
10646 mempool_free(pmb, phba->mbox_mem_pool);
10647 return rc;
10648
10649mbx_fail_out:
10650 /* Free memory allocated for mailbox command */
10651 mempool_free(pmb, phba->mbox_mem_pool);
10652
10653mem_fail_out:
10654 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010655 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040010656
10657irq_fail_out:
10658 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010659 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040010660
10661msi_fail_out:
10662 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010663 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010664
10665vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040010666 return rc;
10667}
10668
10669/**
James Smart3772a992009-05-22 14:50:54 -040010670 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10671 * @phba: pointer to lpfc hba data structure.
10672 *
10673 * This routine is invoked to enable the MSI interrupt mode to device with
10674 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10675 * enable the MSI vector. The device driver is responsible for calling the
10676 * request_irq() to register MSI vector with a interrupt the handler, which
10677 * is done in this function.
10678 *
10679 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010680 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010681 * other values - error
10682 */
10683static int
10684lpfc_sli_enable_msi(struct lpfc_hba *phba)
10685{
10686 int rc;
10687
10688 rc = pci_enable_msi(phba->pcidev);
10689 if (!rc)
10690 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10691 "0462 PCI enable MSI mode success.\n");
10692 else {
10693 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10694 "0471 PCI enable MSI mode failed (%d)\n", rc);
10695 return rc;
10696 }
10697
10698 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010699 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040010700 if (rc) {
10701 pci_disable_msi(phba->pcidev);
10702 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10703 "0478 MSI request_irq failed (%d)\n", rc);
10704 }
10705 return rc;
10706}
10707
10708/**
James Smart3772a992009-05-22 14:50:54 -040010709 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10710 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010010711 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
James Smart3772a992009-05-22 14:50:54 -040010712 *
10713 * This routine is invoked to enable device interrupt and associate driver's
10714 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10715 * spec. Depends on the interrupt mode configured to the driver, the driver
10716 * will try to fallback from the configured interrupt mode to an interrupt
10717 * mode which is supported by the platform, kernel, and device in the order
10718 * of:
10719 * MSI-X -> MSI -> IRQ.
10720 *
10721 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010722 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010723 * other values - error
10724 **/
10725static uint32_t
10726lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10727{
10728 uint32_t intr_mode = LPFC_INTR_ERROR;
10729 int retval;
10730
James Smartd2f25472021-01-04 10:02:27 -080010731 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10732 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10733 if (retval)
10734 return intr_mode;
10735 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
10736
James Smart3772a992009-05-22 14:50:54 -040010737 if (cfg_mode == 2) {
James Smartd2f25472021-01-04 10:02:27 -080010738 /* Now, try to enable MSI-X interrupt mode */
10739 retval = lpfc_sli_enable_msix(phba);
James Smart3772a992009-05-22 14:50:54 -040010740 if (!retval) {
James Smartd2f25472021-01-04 10:02:27 -080010741 /* Indicate initialization to MSI-X mode */
10742 phba->intr_type = MSIX;
10743 intr_mode = 2;
James Smart3772a992009-05-22 14:50:54 -040010744 }
10745 }
10746
10747 /* Fallback to MSI if MSI-X initialization failed */
10748 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10749 retval = lpfc_sli_enable_msi(phba);
10750 if (!retval) {
10751 /* Indicate initialization to MSI mode */
10752 phba->intr_type = MSI;
10753 intr_mode = 1;
10754 }
10755 }
10756
10757 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10758 if (phba->intr_type == NONE) {
10759 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10760 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10761 if (!retval) {
10762 /* Indicate initialization to INTx mode */
10763 phba->intr_type = INTx;
10764 intr_mode = 0;
10765 }
10766 }
10767 return intr_mode;
10768}
10769
10770/**
10771 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10772 * @phba: pointer to lpfc hba data structure.
10773 *
10774 * This routine is invoked to disable device interrupt and disassociate the
10775 * driver's interrupt handler(s) from interrupt vector(s) to device with
10776 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10777 * release the interrupt vector(s) for the message signaled interrupt.
10778 **/
10779static void
10780lpfc_sli_disable_intr(struct lpfc_hba *phba)
10781{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010782 int nr_irqs, i;
10783
James Smart3772a992009-05-22 14:50:54 -040010784 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010785 nr_irqs = LPFC_MSIX_VECTORS;
10786 else
10787 nr_irqs = 1;
10788
10789 for (i = 0; i < nr_irqs; i++)
10790 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10791 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010792
10793 /* Reset interrupt management states */
10794 phba->intr_type = NONE;
10795 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010796}
10797
10798/**
James Smart657add42019-05-21 17:49:06 -070010799 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
James Smart6a828b02019-01-28 11:14:31 -080010800 * @phba: pointer to lpfc hba data structure.
10801 * @id: EQ vector index or Hardware Queue index
10802 * @match: LPFC_FIND_BY_EQ = match by EQ
10803 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
James Smart657add42019-05-21 17:49:06 -070010804 * Return the CPU that matches the selection criteria
James Smart6a828b02019-01-28 11:14:31 -080010805 */
10806static uint16_t
10807lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
10808{
10809 struct lpfc_vector_map_info *cpup;
10810 int cpu;
10811
James Smart657add42019-05-21 17:49:06 -070010812 /* Loop through all CPUs */
James Smart222e9232019-01-28 11:14:35 -080010813 for_each_present_cpu(cpu) {
10814 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070010815
10816 /* If we are matching by EQ, there may be multiple CPUs using
10817 * using the same vector, so select the one with
10818 * LPFC_CPU_FIRST_IRQ set.
10819 */
James Smart6a828b02019-01-28 11:14:31 -080010820 if ((match == LPFC_FIND_BY_EQ) &&
James Smart657add42019-05-21 17:49:06 -070010821 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
James Smart6a828b02019-01-28 11:14:31 -080010822 (cpup->eq == id))
10823 return cpu;
James Smart657add42019-05-21 17:49:06 -070010824
10825 /* If matching by HDWQ, select the first CPU that matches */
James Smart6a828b02019-01-28 11:14:31 -080010826 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
10827 return cpu;
James Smart6a828b02019-01-28 11:14:31 -080010828 }
10829 return 0;
10830}
10831
James Smart6a828b02019-01-28 11:14:31 -080010832#ifdef CONFIG_X86
10833/**
10834 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
10835 * @phba: pointer to lpfc hba data structure.
10836 * @cpu: CPU map index
10837 * @phys_id: CPU package physical id
10838 * @core_id: CPU core id
10839 */
10840static int
10841lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
10842 uint16_t phys_id, uint16_t core_id)
10843{
10844 struct lpfc_vector_map_info *cpup;
10845 int idx;
10846
James Smart222e9232019-01-28 11:14:35 -080010847 for_each_present_cpu(idx) {
10848 cpup = &phba->sli4_hba.cpu_map[idx];
James Smart6a828b02019-01-28 11:14:31 -080010849 /* Does the cpup match the one we are looking for */
10850 if ((cpup->phys_id == phys_id) &&
10851 (cpup->core_id == core_id) &&
James Smart222e9232019-01-28 11:14:35 -080010852 (cpu != idx))
James Smart6a828b02019-01-28 11:14:31 -080010853 return 1;
James Smart6a828b02019-01-28 11:14:31 -080010854 }
10855 return 0;
10856}
10857#endif
10858
James Smartdcaa2132019-11-04 16:57:06 -080010859/*
10860 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
10861 * @phba: pointer to lpfc hba data structure.
10862 * @eqidx: index for eq and irq vector
10863 * @flag: flags to set for vector_map structure
10864 * @cpu: cpu used to index vector_map structure
10865 *
10866 * The routine assigns eq info into vector_map structure
10867 */
10868static inline void
10869lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
10870 unsigned int cpu)
10871{
10872 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
10873 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
10874
10875 cpup->eq = eqidx;
10876 cpup->flag |= flag;
10877
10878 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10879 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
10880 cpu, eqhdl->irq, cpup->eq, cpup->flag);
10881}
10882
10883/**
10884 * lpfc_cpu_map_array_init - Initialize cpu_map structure
10885 * @phba: pointer to lpfc hba data structure.
10886 *
10887 * The routine initializes the cpu_map array structure
10888 */
10889static void
10890lpfc_cpu_map_array_init(struct lpfc_hba *phba)
10891{
10892 struct lpfc_vector_map_info *cpup;
10893 struct lpfc_eq_intr_info *eqi;
10894 int cpu;
10895
10896 for_each_possible_cpu(cpu) {
10897 cpup = &phba->sli4_hba.cpu_map[cpu];
10898 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
10899 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
10900 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
10901 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
10902 cpup->flag = 0;
10903 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
10904 INIT_LIST_HEAD(&eqi->list);
10905 eqi->icnt = 0;
10906 }
10907}
10908
10909/**
10910 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
10911 * @phba: pointer to lpfc hba data structure.
10912 *
10913 * The routine initializes the hba_eq_hdl array structure
10914 */
10915static void
10916lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
10917{
10918 struct lpfc_hba_eq_hdl *eqhdl;
10919 int i;
10920
10921 for (i = 0; i < phba->cfg_irq_chann; i++) {
10922 eqhdl = lpfc_get_eq_hdl(i);
10923 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
10924 eqhdl->phba = phba;
10925 }
10926}
10927
James Smart6a828b02019-01-28 11:14:31 -080010928/**
James Smart895427b2017-02-12 13:52:30 -080010929 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010930 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010931 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010932 *
James Smart895427b2017-02-12 13:52:30 -080010933 * The routine will figure out the CPU affinity assignment for every
James Smart6a828b02019-01-28 11:14:31 -080010934 * MSI-X vector allocated for the HBA.
James Smart895427b2017-02-12 13:52:30 -080010935 * In addition, the CPU to IO channel mapping will be calculated
10936 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010937 */
James Smart895427b2017-02-12 13:52:30 -080010938static void
10939lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010940{
James Smart3ad348d2019-08-14 16:56:43 -070010941 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
James Smart6a828b02019-01-28 11:14:31 -080010942 int max_phys_id, min_phys_id;
10943 int max_core_id, min_core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010944 struct lpfc_vector_map_info *cpup;
James Smartd9954a22019-05-21 17:49:05 -070010945 struct lpfc_vector_map_info *new_cpup;
James Smart7bb03bb2013-04-17 20:19:16 -040010946#ifdef CONFIG_X86
10947 struct cpuinfo_x86 *cpuinfo;
10948#endif
James Smart840eda92020-03-22 11:13:00 -070010949#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
10950 struct lpfc_hdwq_stat *c_stat;
10951#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010952
James Smart6a828b02019-01-28 11:14:31 -080010953 max_phys_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010954 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
James Smart6a828b02019-01-28 11:14:31 -080010955 max_core_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010956 min_core_id = LPFC_VECTOR_MAP_EMPTY;
James Smart7bb03bb2013-04-17 20:19:16 -040010957
10958 /* Update CPU map with physical id and core id of each CPU */
James Smart222e9232019-01-28 11:14:35 -080010959 for_each_present_cpu(cpu) {
10960 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart7bb03bb2013-04-17 20:19:16 -040010961#ifdef CONFIG_X86
10962 cpuinfo = &cpu_data(cpu);
10963 cpup->phys_id = cpuinfo->phys_proc_id;
10964 cpup->core_id = cpuinfo->cpu_core_id;
James Smartd9954a22019-05-21 17:49:05 -070010965 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
10966 cpup->flag |= LPFC_CPU_MAP_HYPER;
James Smart7bb03bb2013-04-17 20:19:16 -040010967#else
10968 /* No distinction between CPUs for other platforms */
10969 cpup->phys_id = 0;
James Smart6a828b02019-01-28 11:14:31 -080010970 cpup->core_id = cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010971#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010972
James Smartb3295c22019-01-28 11:14:30 -080010973 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart3ad348d2019-08-14 16:56:43 -070010974 "3328 CPU %d physid %d coreid %d flag x%x\n",
10975 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
James Smart6a828b02019-01-28 11:14:31 -080010976
10977 if (cpup->phys_id > max_phys_id)
10978 max_phys_id = cpup->phys_id;
10979 if (cpup->phys_id < min_phys_id)
10980 min_phys_id = cpup->phys_id;
10981
10982 if (cpup->core_id > max_core_id)
10983 max_core_id = cpup->core_id;
10984 if (cpup->core_id < min_core_id)
10985 min_core_id = cpup->core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010986 }
James Smartb3295c22019-01-28 11:14:30 -080010987
James Smartd9954a22019-05-21 17:49:05 -070010988 /* After looking at each irq vector assigned to this pcidev, its
10989 * possible to see that not ALL CPUs have been accounted for.
James Smart657add42019-05-21 17:49:06 -070010990 * Next we will set any unassigned (unaffinitized) cpu map
10991 * entries to a IRQ on the same phys_id.
James Smartd9954a22019-05-21 17:49:05 -070010992 */
10993 first_cpu = cpumask_first(cpu_present_mask);
10994 start_cpu = first_cpu;
10995
10996 for_each_present_cpu(cpu) {
10997 cpup = &phba->sli4_hba.cpu_map[cpu];
10998
10999 /* Is this CPU entry unassigned */
11000 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
11001 /* Mark CPU as IRQ not assigned by the kernel */
11002 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
11003
James Smart657add42019-05-21 17:49:06 -070011004 /* If so, find a new_cpup thats on the the SAME
James Smartd9954a22019-05-21 17:49:05 -070011005 * phys_id as cpup. start_cpu will start where we
11006 * left off so all unassigned entries don't get assgined
11007 * the IRQ of the first entry.
11008 */
11009 new_cpu = start_cpu;
11010 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11011 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11012 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
James Smartdcaa2132019-11-04 16:57:06 -080011013 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
James Smartd9954a22019-05-21 17:49:05 -070011014 (new_cpup->phys_id == cpup->phys_id))
11015 goto found_same;
11016 new_cpu = cpumask_next(
11017 new_cpu, cpu_present_mask);
11018 if (new_cpu == nr_cpumask_bits)
11019 new_cpu = first_cpu;
11020 }
11021 /* At this point, we leave the CPU as unassigned */
11022 continue;
11023found_same:
11024 /* We found a matching phys_id, so copy the IRQ info */
11025 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070011026
11027 /* Bump start_cpu to the next slot to minmize the
11028 * chance of having multiple unassigned CPU entries
11029 * selecting the same IRQ.
11030 */
11031 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11032 if (start_cpu == nr_cpumask_bits)
11033 start_cpu = first_cpu;
11034
James Smart657add42019-05-21 17:49:06 -070011035 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070011036 "3337 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080011037 "eq %d from peer cpu %d same "
James Smartd9954a22019-05-21 17:49:05 -070011038 "phys_id (%d)\n",
James Smartdcaa2132019-11-04 16:57:06 -080011039 cpu, cpup->eq, new_cpu,
11040 cpup->phys_id);
James Smartd9954a22019-05-21 17:49:05 -070011041 }
11042 }
11043
11044 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
11045 start_cpu = first_cpu;
11046
11047 for_each_present_cpu(cpu) {
11048 cpup = &phba->sli4_hba.cpu_map[cpu];
11049
11050 /* Is this entry unassigned */
11051 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
11052 /* Mark it as IRQ not assigned by the kernel */
11053 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
11054
James Smart657add42019-05-21 17:49:06 -070011055 /* If so, find a new_cpup thats on ANY phys_id
James Smartd9954a22019-05-21 17:49:05 -070011056 * as the cpup. start_cpu will start where we
11057 * left off so all unassigned entries don't get
11058 * assigned the IRQ of the first entry.
11059 */
11060 new_cpu = start_cpu;
11061 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11062 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11063 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
James Smartdcaa2132019-11-04 16:57:06 -080011064 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
James Smartd9954a22019-05-21 17:49:05 -070011065 goto found_any;
11066 new_cpu = cpumask_next(
11067 new_cpu, cpu_present_mask);
11068 if (new_cpu == nr_cpumask_bits)
11069 new_cpu = first_cpu;
11070 }
11071 /* We should never leave an entry unassigned */
11072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11073 "3339 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080011074 "eq %d UNASSIGNED\n",
11075 cpup->hdwq, cpup->eq);
James Smartd9954a22019-05-21 17:49:05 -070011076 continue;
11077found_any:
11078 /* We found an available entry, copy the IRQ info */
11079 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070011080
11081 /* Bump start_cpu to the next slot to minmize the
11082 * chance of having multiple unassigned CPU entries
11083 * selecting the same IRQ.
11084 */
11085 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11086 if (start_cpu == nr_cpumask_bits)
11087 start_cpu = first_cpu;
11088
James Smart657add42019-05-21 17:49:06 -070011089 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070011090 "3338 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080011091 "eq %d from peer cpu %d (%d/%d)\n",
11092 cpu, cpup->eq, new_cpu,
James Smartd9954a22019-05-21 17:49:05 -070011093 new_cpup->phys_id, new_cpup->core_id);
11094 }
11095 }
James Smart657add42019-05-21 17:49:06 -070011096
James Smart3ad348d2019-08-14 16:56:43 -070011097 /* Assign hdwq indices that are unique across all cpus in the map
11098 * that are also FIRST_CPUs.
11099 */
11100 idx = 0;
11101 for_each_present_cpu(cpu) {
11102 cpup = &phba->sli4_hba.cpu_map[cpu];
11103
11104 /* Only FIRST IRQs get a hdwq index assignment. */
11105 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11106 continue;
11107
11108 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
11109 cpup->hdwq = idx;
11110 idx++;
Anton Blanchardbc2736e2020-07-13 18:39:08 +100011111 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart3ad348d2019-08-14 16:56:43 -070011112 "3333 Set Affinity: CPU %d (phys %d core %d): "
James Smartdcaa2132019-11-04 16:57:06 -080011113 "hdwq %d eq %d flg x%x\n",
James Smart3ad348d2019-08-14 16:56:43 -070011114 cpu, cpup->phys_id, cpup->core_id,
James Smartdcaa2132019-11-04 16:57:06 -080011115 cpup->hdwq, cpup->eq, cpup->flag);
James Smart3ad348d2019-08-14 16:56:43 -070011116 }
James Smartbc227dd2019-11-11 15:03:59 -080011117 /* Associate a hdwq with each cpu_map entry
James Smart657add42019-05-21 17:49:06 -070011118 * This will be 1 to 1 - hdwq to cpu, unless there are less
11119 * hardware queues then CPUs. For that case we will just round-robin
11120 * the available hardware queues as they get assigned to CPUs.
James Smart3ad348d2019-08-14 16:56:43 -070011121 * The next_idx is the idx from the FIRST_CPU loop above to account
11122 * for irq_chann < hdwq. The idx is used for round-robin assignments
11123 * and needs to start at 0.
James Smart657add42019-05-21 17:49:06 -070011124 */
James Smart3ad348d2019-08-14 16:56:43 -070011125 next_idx = idx;
James Smart657add42019-05-21 17:49:06 -070011126 start_cpu = 0;
James Smart3ad348d2019-08-14 16:56:43 -070011127 idx = 0;
James Smart657add42019-05-21 17:49:06 -070011128 for_each_present_cpu(cpu) {
11129 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070011130
James Smart3ad348d2019-08-14 16:56:43 -070011131 /* FIRST cpus are already mapped. */
11132 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
11133 continue;
James Smart657add42019-05-21 17:49:06 -070011134
James Smart3ad348d2019-08-14 16:56:43 -070011135 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
11136 * of the unassigned cpus to the next idx so that all
11137 * hdw queues are fully utilized.
11138 */
11139 if (next_idx < phba->cfg_hdw_queue) {
11140 cpup->hdwq = next_idx;
11141 next_idx++;
11142 continue;
James Smart657add42019-05-21 17:49:06 -070011143 }
James Smart3ad348d2019-08-14 16:56:43 -070011144
11145 /* Not a First CPU and all hdw_queues are used. Reuse a
11146 * Hardware Queue for another CPU, so be smart about it
11147 * and pick one that has its IRQ/EQ mapped to the same phys_id
11148 * (CPU package) and core_id.
11149 */
11150 new_cpu = start_cpu;
11151 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11152 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11153 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11154 new_cpup->phys_id == cpup->phys_id &&
11155 new_cpup->core_id == cpup->core_id) {
11156 goto found_hdwq;
11157 }
11158 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11159 if (new_cpu == nr_cpumask_bits)
11160 new_cpu = first_cpu;
11161 }
11162
11163 /* If we can't match both phys_id and core_id,
11164 * settle for just a phys_id match.
11165 */
11166 new_cpu = start_cpu;
11167 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
11168 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
11169 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
11170 new_cpup->phys_id == cpup->phys_id)
11171 goto found_hdwq;
11172
11173 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
11174 if (new_cpu == nr_cpumask_bits)
11175 new_cpu = first_cpu;
11176 }
11177
11178 /* Otherwise just round robin on cfg_hdw_queue */
11179 cpup->hdwq = idx % phba->cfg_hdw_queue;
11180 idx++;
11181 goto logit;
11182 found_hdwq:
11183 /* We found an available entry, copy the IRQ info */
11184 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
11185 if (start_cpu == nr_cpumask_bits)
11186 start_cpu = first_cpu;
11187 cpup->hdwq = new_cpup->hdwq;
11188 logit:
Anton Blanchardbc2736e2020-07-13 18:39:08 +100011189 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart657add42019-05-21 17:49:06 -070011190 "3335 Set Affinity: CPU %d (phys %d core %d): "
James Smartdcaa2132019-11-04 16:57:06 -080011191 "hdwq %d eq %d flg x%x\n",
James Smart657add42019-05-21 17:49:06 -070011192 cpu, cpup->phys_id, cpup->core_id,
James Smartdcaa2132019-11-04 16:57:06 -080011193 cpup->hdwq, cpup->eq, cpup->flag);
James Smart657add42019-05-21 17:49:06 -070011194 }
11195
James Smartbc227dd2019-11-11 15:03:59 -080011196 /*
11197 * Initialize the cpu_map slots for not-present cpus in case
11198 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
11199 */
11200 idx = 0;
11201 for_each_possible_cpu(cpu) {
11202 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart840eda92020-03-22 11:13:00 -070011203#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11204 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
11205 c_stat->hdwq_no = cpup->hdwq;
11206#endif
James Smartbc227dd2019-11-11 15:03:59 -080011207 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
11208 continue;
11209
11210 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
James Smart840eda92020-03-22 11:13:00 -070011211#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
11212 c_stat->hdwq_no = cpup->hdwq;
11213#endif
James Smartbc227dd2019-11-11 15:03:59 -080011214 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11215 "3340 Set Affinity: not present "
11216 "CPU %d hdwq %d\n",
11217 cpu, cpup->hdwq);
James Smart657add42019-05-21 17:49:06 -070011218 }
11219
11220 /* The cpu_map array will be used later during initialization
11221 * when EQ / CQ / WQs are allocated and configured.
11222 */
James Smartb3295c22019-01-28 11:14:30 -080011223 return;
James Smart7bb03bb2013-04-17 20:19:16 -040011224}
James Smart7bb03bb2013-04-17 20:19:16 -040011225
11226/**
James Smart93a4d6f2019-11-04 16:57:05 -080011227 * lpfc_cpuhp_get_eq
11228 *
11229 * @phba: pointer to lpfc hba data structure.
11230 * @cpu: cpu going offline
Lee Jonesfe614ac2020-07-23 13:24:22 +010011231 * @eqlist: eq list to append to
James Smart93a4d6f2019-11-04 16:57:05 -080011232 */
James Smarta99c8072020-01-27 16:23:06 -080011233static int
James Smart93a4d6f2019-11-04 16:57:05 -080011234lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
11235 struct list_head *eqlist)
11236{
James Smart93a4d6f2019-11-04 16:57:05 -080011237 const struct cpumask *maskp;
11238 struct lpfc_queue *eq;
James Smarta99c8072020-01-27 16:23:06 -080011239 struct cpumask *tmp;
James Smart93a4d6f2019-11-04 16:57:05 -080011240 u16 idx;
11241
James Smarta99c8072020-01-27 16:23:06 -080011242 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
11243 if (!tmp)
11244 return -ENOMEM;
11245
James Smart93a4d6f2019-11-04 16:57:05 -080011246 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
11247 maskp = pci_irq_get_affinity(phba->pcidev, idx);
11248 if (!maskp)
11249 continue;
11250 /*
11251 * if irq is not affinitized to the cpu going
11252 * then we don't need to poll the eq attached
11253 * to it.
11254 */
James Smarta99c8072020-01-27 16:23:06 -080011255 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
James Smart93a4d6f2019-11-04 16:57:05 -080011256 continue;
11257 /* get the cpus that are online and are affini-
11258 * tized to this irq vector. If the count is
11259 * more than 1 then cpuhp is not going to shut-
11260 * down this vector. Since this cpu has not
11261 * gone offline yet, we need >1.
11262 */
James Smarta99c8072020-01-27 16:23:06 -080011263 cpumask_and(tmp, maskp, cpu_online_mask);
11264 if (cpumask_weight(tmp) > 1)
James Smart93a4d6f2019-11-04 16:57:05 -080011265 continue;
11266
11267 /* Now that we have an irq to shutdown, get the eq
11268 * mapped to this irq. Note: multiple hdwq's in
11269 * the software can share an eq, but eventually
11270 * only eq will be mapped to this vector
11271 */
James Smartdcaa2132019-11-04 16:57:06 -080011272 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
11273 list_add(&eq->_poll_list, eqlist);
James Smart93a4d6f2019-11-04 16:57:05 -080011274 }
James Smarta99c8072020-01-27 16:23:06 -080011275 kfree(tmp);
11276 return 0;
James Smart93a4d6f2019-11-04 16:57:05 -080011277}
11278
11279static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
11280{
11281 if (phba->sli_rev != LPFC_SLI_REV4)
11282 return;
11283
11284 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
11285 &phba->cpuhp);
11286 /*
11287 * unregistering the instance doesn't stop the polling
11288 * timer. Wait for the poll timer to retire.
11289 */
11290 synchronize_rcu();
11291 del_timer_sync(&phba->cpuhp_poll_timer);
11292}
11293
11294static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
11295{
11296 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
11297 return;
11298
11299 __lpfc_cpuhp_remove(phba);
11300}
11301
11302static void lpfc_cpuhp_add(struct lpfc_hba *phba)
11303{
11304 if (phba->sli_rev != LPFC_SLI_REV4)
11305 return;
11306
11307 rcu_read_lock();
11308
James Smartf861f592020-03-22 11:12:54 -070011309 if (!list_empty(&phba->poll_list))
James Smart93a4d6f2019-11-04 16:57:05 -080011310 mod_timer(&phba->cpuhp_poll_timer,
11311 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
James Smart93a4d6f2019-11-04 16:57:05 -080011312
11313 rcu_read_unlock();
11314
11315 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
11316 &phba->cpuhp);
11317}
11318
11319static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
11320{
11321 if (phba->pport->load_flag & FC_UNLOADING) {
11322 *retval = -EAGAIN;
11323 return true;
11324 }
11325
11326 if (phba->sli_rev != LPFC_SLI_REV4) {
11327 *retval = 0;
11328 return true;
11329 }
11330
11331 /* proceed with the hotplug */
11332 return false;
11333}
11334
James Smartdcaa2132019-11-04 16:57:06 -080011335/**
11336 * lpfc_irq_set_aff - set IRQ affinity
11337 * @eqhdl: EQ handle
11338 * @cpu: cpu to set affinity
11339 *
11340 **/
11341static inline void
11342lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
11343{
11344 cpumask_clear(&eqhdl->aff_mask);
11345 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
11346 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
11347 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
11348}
11349
11350/**
11351 * lpfc_irq_clear_aff - clear IRQ affinity
11352 * @eqhdl: EQ handle
11353 *
11354 **/
11355static inline void
11356lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
11357{
11358 cpumask_clear(&eqhdl->aff_mask);
11359 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
James Smartdcaa2132019-11-04 16:57:06 -080011360}
11361
11362/**
11363 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
11364 * @phba: pointer to HBA context object.
11365 * @cpu: cpu going offline/online
11366 * @offline: true, cpu is going offline. false, cpu is coming online.
11367 *
11368 * If cpu is going offline, we'll try our best effort to find the next
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011369 * online cpu on the phba's original_mask and migrate all offlining IRQ
11370 * affinities.
James Smartdcaa2132019-11-04 16:57:06 -080011371 *
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011372 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
James Smartdcaa2132019-11-04 16:57:06 -080011373 *
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011374 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
James Smartdcaa2132019-11-04 16:57:06 -080011375 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
11376 *
11377 **/
11378static void
11379lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
11380{
11381 struct lpfc_vector_map_info *cpup;
11382 struct cpumask *aff_mask;
11383 unsigned int cpu_select, cpu_next, idx;
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011384 const struct cpumask *orig_mask;
James Smartdcaa2132019-11-04 16:57:06 -080011385
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011386 if (phba->irq_chann_mode == NORMAL_MODE)
James Smartdcaa2132019-11-04 16:57:06 -080011387 return;
11388
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011389 orig_mask = &phba->sli4_hba.irq_aff_mask;
James Smartdcaa2132019-11-04 16:57:06 -080011390
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011391 if (!cpumask_test_cpu(cpu, orig_mask))
James Smartdcaa2132019-11-04 16:57:06 -080011392 return;
11393
11394 cpup = &phba->sli4_hba.cpu_map[cpu];
11395
11396 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
11397 return;
11398
11399 if (offline) {
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011400 /* Find next online CPU on original mask */
11401 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
11402 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
James Smartdcaa2132019-11-04 16:57:06 -080011403
11404 /* Found a valid CPU */
11405 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
11406 /* Go through each eqhdl and ensure offlining
11407 * cpu aff_mask is migrated
11408 */
11409 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
11410 aff_mask = lpfc_get_aff_mask(idx);
11411
11412 /* Migrate affinity */
11413 if (cpumask_test_cpu(cpu, aff_mask))
11414 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
11415 cpu_select);
11416 }
11417 } else {
11418 /* Rely on irqbalance if no online CPUs left on NUMA */
11419 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
11420 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
11421 }
11422 } else {
11423 /* Migrate affinity back to this CPU */
11424 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
11425 }
11426}
11427
James Smart93a4d6f2019-11-04 16:57:05 -080011428static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
11429{
11430 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
11431 struct lpfc_queue *eq, *next;
11432 LIST_HEAD(eqlist);
11433 int retval;
11434
11435 if (!phba) {
11436 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
11437 return 0;
11438 }
11439
11440 if (__lpfc_cpuhp_checks(phba, &retval))
11441 return retval;
11442
James Smartdcaa2132019-11-04 16:57:06 -080011443 lpfc_irq_rebalance(phba, cpu, true);
11444
James Smarta99c8072020-01-27 16:23:06 -080011445 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
11446 if (retval)
11447 return retval;
James Smart93a4d6f2019-11-04 16:57:05 -080011448
11449 /* start polling on these eq's */
11450 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
11451 list_del_init(&eq->_poll_list);
11452 lpfc_sli4_start_polling(eq);
11453 }
11454
11455 return 0;
11456}
11457
11458static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
11459{
11460 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
11461 struct lpfc_queue *eq, *next;
11462 unsigned int n;
11463 int retval;
11464
11465 if (!phba) {
11466 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
11467 return 0;
11468 }
11469
11470 if (__lpfc_cpuhp_checks(phba, &retval))
11471 return retval;
11472
James Smartdcaa2132019-11-04 16:57:06 -080011473 lpfc_irq_rebalance(phba, cpu, false);
11474
James Smart93a4d6f2019-11-04 16:57:05 -080011475 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
11476 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
11477 if (n == cpu)
11478 lpfc_sli4_stop_polling(eq);
11479 }
11480
11481 return 0;
11482}
11483
11484/**
James Smartda0436e2009-05-22 14:51:39 -040011485 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
11486 * @phba: pointer to lpfc hba data structure.
11487 *
11488 * This routine is invoked to enable the MSI-X interrupt vectors to device
James Smartdcaa2132019-11-04 16:57:06 -080011489 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
11490 * to cpus on the system.
11491 *
11492 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
11493 * the number of cpus on the same numa node as this adapter. The vectors are
11494 * allocated without requesting OS affinity mapping. A vector will be
11495 * allocated and assigned to each online and offline cpu. If the cpu is
11496 * online, then affinity will be set to that cpu. If the cpu is offline, then
11497 * affinity will be set to the nearest peer cpu within the numa node that is
11498 * online. If there are no online cpus within the numa node, affinity is not
11499 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
11500 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
11501 * configured.
11502 *
11503 * If numa mode is not enabled and there is more than 1 vector allocated, then
11504 * the driver relies on the managed irq interface where the OS assigns vector to
11505 * cpu affinity. The driver will then use that affinity mapping to setup its
11506 * cpu mapping table.
James Smartda0436e2009-05-22 14:51:39 -040011507 *
11508 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011509 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011510 * other values - error
11511 **/
11512static int
11513lpfc_sli4_enable_msix(struct lpfc_hba *phba)
11514{
James Smart75baf692010-06-08 18:31:21 -040011515 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070011516 char *name;
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011517 const struct cpumask *aff_mask = NULL;
James Smartdcaa2132019-11-04 16:57:06 -080011518 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
Dick Kennedy17105d92020-07-06 13:42:30 -070011519 struct lpfc_vector_map_info *cpup;
James Smartdcaa2132019-11-04 16:57:06 -080011520 struct lpfc_hba_eq_hdl *eqhdl;
11521 const struct cpumask *maskp;
James Smartdcaa2132019-11-04 16:57:06 -080011522 unsigned int flags = PCI_IRQ_MSIX;
James Smartda0436e2009-05-22 14:51:39 -040011523
11524 /* Set up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011525 vectors = phba->cfg_irq_chann;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011526
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011527 if (phba->irq_chann_mode != NORMAL_MODE)
11528 aff_mask = &phba->sli4_hba.irq_aff_mask;
11529
11530 if (aff_mask) {
11531 cpu_cnt = cpumask_weight(aff_mask);
James Smartdcaa2132019-11-04 16:57:06 -080011532 vectors = min(phba->cfg_irq_chann, cpu_cnt);
11533
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011534 /* cpu: iterates over aff_mask including offline or online
11535 * cpu_select: iterates over online aff_mask to set affinity
James Smartdcaa2132019-11-04 16:57:06 -080011536 */
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011537 cpu = cpumask_first(aff_mask);
11538 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
James Smartdcaa2132019-11-04 16:57:06 -080011539 } else {
11540 flags |= PCI_IRQ_AFFINITY;
11541 }
11542
11543 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011544 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040011545 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11546 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011547 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040011548 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011549 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040011550
James Smart7bb03bb2013-04-17 20:19:16 -040011551 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040011552 for (index = 0; index < vectors; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080011553 eqhdl = lpfc_get_eq_hdl(index);
11554 name = eqhdl->handler_name;
James Smartb83d0052017-06-01 21:07:05 -070011555 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
11556 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040011557 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040011558
James Smartdcaa2132019-11-04 16:57:06 -080011559 eqhdl->idx = index;
James Smart7370d102019-01-28 11:14:20 -080011560 rc = request_irq(pci_irq_vector(phba->pcidev, index),
11561 &lpfc_sli4_hba_intr_handler, 0,
James Smartdcaa2132019-11-04 16:57:06 -080011562 name, eqhdl);
James Smartda0436e2009-05-22 14:51:39 -040011563 if (rc) {
11564 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11565 "0486 MSI-X fast-path (%d) "
11566 "request_irq failed (%d)\n", index, rc);
11567 goto cfg_fail_out;
11568 }
James Smartdcaa2132019-11-04 16:57:06 -080011569
11570 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
11571
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011572 if (aff_mask) {
James Smartdcaa2132019-11-04 16:57:06 -080011573 /* If found a neighboring online cpu, set affinity */
11574 if (cpu_select < nr_cpu_ids)
11575 lpfc_irq_set_aff(eqhdl, cpu_select);
11576
11577 /* Assign EQ to cpu_map */
11578 lpfc_assign_eq_map_info(phba, index,
11579 LPFC_CPU_FIRST_IRQ,
11580 cpu);
11581
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011582 /* Iterate to next offline or online cpu in aff_mask */
11583 cpu = cpumask_next(cpu, aff_mask);
James Smartdcaa2132019-11-04 16:57:06 -080011584
Dick Kennedy3048e3e2020-05-01 14:43:06 -070011585 /* Find next online cpu in aff_mask to set affinity */
11586 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
James Smartdcaa2132019-11-04 16:57:06 -080011587 } else if (vectors == 1) {
11588 cpu = cpumask_first(cpu_present_mask);
11589 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
11590 cpu);
11591 } else {
11592 maskp = pci_irq_get_affinity(phba->pcidev, index);
11593
James Smartdcaa2132019-11-04 16:57:06 -080011594 /* Loop through all CPUs associated with vector index */
11595 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
Dick Kennedy17105d92020-07-06 13:42:30 -070011596 cpup = &phba->sli4_hba.cpu_map[cpu];
11597
James Smartdcaa2132019-11-04 16:57:06 -080011598 /* If this is the first CPU thats assigned to
11599 * this vector, set LPFC_CPU_FIRST_IRQ.
Dick Kennedy17105d92020-07-06 13:42:30 -070011600 *
11601 * With certain platforms its possible that irq
11602 * vectors are affinitized to all the cpu's.
11603 * This can result in each cpu_map.eq to be set
11604 * to the last vector, resulting in overwrite
11605 * of all the previous cpu_map.eq. Ensure that
11606 * each vector receives a place in cpu_map.
11607 * Later call to lpfc_cpu_affinity_check will
11608 * ensure we are nicely balanced out.
James Smartdcaa2132019-11-04 16:57:06 -080011609 */
Dick Kennedy17105d92020-07-06 13:42:30 -070011610 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
11611 continue;
James Smartdcaa2132019-11-04 16:57:06 -080011612 lpfc_assign_eq_map_info(phba, index,
Dick Kennedy17105d92020-07-06 13:42:30 -070011613 LPFC_CPU_FIRST_IRQ,
James Smartdcaa2132019-11-04 16:57:06 -080011614 cpu);
Dick Kennedy17105d92020-07-06 13:42:30 -070011615 break;
James Smartdcaa2132019-11-04 16:57:06 -080011616 }
11617 }
James Smartda0436e2009-05-22 14:51:39 -040011618 }
11619
James Smart6a828b02019-01-28 11:14:31 -080011620 if (vectors != phba->cfg_irq_chann) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011621 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart82c3e9b2012-09-29 11:29:50 -040011622 "3238 Reducing IO channels to match number of "
11623 "MSI-X vectors, requested %d got %d\n",
James Smart6a828b02019-01-28 11:14:31 -080011624 phba->cfg_irq_chann, vectors);
11625 if (phba->cfg_irq_chann > vectors)
11626 phba->cfg_irq_chann = vectors;
James Smart82c3e9b2012-09-29 11:29:50 -040011627 }
James Smart7bb03bb2013-04-17 20:19:16 -040011628
James Smartda0436e2009-05-22 14:51:39 -040011629 return rc;
11630
11631cfg_fail_out:
11632 /* free the irq already requested */
James Smartdcaa2132019-11-04 16:57:06 -080011633 for (--index; index >= 0; index--) {
11634 eqhdl = lpfc_get_eq_hdl(index);
11635 lpfc_irq_clear_aff(eqhdl);
11636 irq_set_affinity_hint(eqhdl->irq, NULL);
11637 free_irq(eqhdl->irq, eqhdl);
11638 }
James Smartda0436e2009-05-22 14:51:39 -040011639
James Smartda0436e2009-05-22 14:51:39 -040011640 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011641 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011642
11643vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040011644 return rc;
11645}
11646
11647/**
James Smartda0436e2009-05-22 14:51:39 -040011648 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
11649 * @phba: pointer to lpfc hba data structure.
11650 *
11651 * This routine is invoked to enable the MSI interrupt mode to device with
James Smart07b1b912019-08-14 16:56:58 -070011652 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
11653 * called to enable the MSI vector. The device driver is responsible for
11654 * calling the request_irq() to register MSI vector with a interrupt the
11655 * handler, which is done in this function.
James Smartda0436e2009-05-22 14:51:39 -040011656 *
11657 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011658 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011659 * other values - error
11660 **/
11661static int
11662lpfc_sli4_enable_msi(struct lpfc_hba *phba)
11663{
11664 int rc, index;
James Smartdcaa2132019-11-04 16:57:06 -080011665 unsigned int cpu;
11666 struct lpfc_hba_eq_hdl *eqhdl;
James Smartda0436e2009-05-22 14:51:39 -040011667
James Smart07b1b912019-08-14 16:56:58 -070011668 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
11669 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
11670 if (rc > 0)
James Smartda0436e2009-05-22 14:51:39 -040011671 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11672 "0487 PCI enable MSI mode success.\n");
11673 else {
11674 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11675 "0488 PCI enable MSI mode failed (%d)\n", rc);
James Smart07b1b912019-08-14 16:56:58 -070011676 return rc ? rc : -1;
James Smartda0436e2009-05-22 14:51:39 -040011677 }
11678
11679 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040011680 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040011681 if (rc) {
James Smart07b1b912019-08-14 16:56:58 -070011682 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040011683 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11684 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040011685 return rc;
James Smartda0436e2009-05-22 14:51:39 -040011686 }
11687
James Smartdcaa2132019-11-04 16:57:06 -080011688 eqhdl = lpfc_get_eq_hdl(0);
11689 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
11690
11691 cpu = cpumask_first(cpu_present_mask);
11692 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
11693
James Smart6a828b02019-01-28 11:14:31 -080011694 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080011695 eqhdl = lpfc_get_eq_hdl(index);
11696 eqhdl->idx = index;
James Smartda0436e2009-05-22 14:51:39 -040011697 }
11698
James Smart75baf692010-06-08 18:31:21 -040011699 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011700}
11701
11702/**
James Smartda0436e2009-05-22 14:51:39 -040011703 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
11704 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010011705 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
James Smartda0436e2009-05-22 14:51:39 -040011706 *
11707 * This routine is invoked to enable device interrupt and associate driver's
11708 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
11709 * interface spec. Depends on the interrupt mode configured to the driver,
11710 * the driver will try to fallback from the configured interrupt mode to an
11711 * interrupt mode which is supported by the platform, kernel, and device in
11712 * the order of:
11713 * MSI-X -> MSI -> IRQ.
11714 *
11715 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011716 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011717 * other values - error
11718 **/
11719static uint32_t
11720lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
11721{
11722 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080011723 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040011724
11725 if (cfg_mode == 2) {
11726 /* Preparation before conf_msi mbox cmd */
11727 retval = 0;
11728 if (!retval) {
11729 /* Now, try to enable MSI-X interrupt mode */
11730 retval = lpfc_sli4_enable_msix(phba);
11731 if (!retval) {
11732 /* Indicate initialization to MSI-X mode */
11733 phba->intr_type = MSIX;
11734 intr_mode = 2;
11735 }
11736 }
11737 }
11738
11739 /* Fallback to MSI if MSI-X initialization failed */
11740 if (cfg_mode >= 1 && phba->intr_type == NONE) {
11741 retval = lpfc_sli4_enable_msi(phba);
11742 if (!retval) {
11743 /* Indicate initialization to MSI mode */
11744 phba->intr_type = MSI;
11745 intr_mode = 1;
11746 }
11747 }
11748
11749 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11750 if (phba->intr_type == NONE) {
11751 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
11752 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
11753 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080011754 struct lpfc_hba_eq_hdl *eqhdl;
James Smartdcaa2132019-11-04 16:57:06 -080011755 unsigned int cpu;
James Smart895427b2017-02-12 13:52:30 -080011756
James Smartda0436e2009-05-22 14:51:39 -040011757 /* Indicate initialization to INTx mode */
11758 phba->intr_type = INTx;
11759 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080011760
James Smartdcaa2132019-11-04 16:57:06 -080011761 eqhdl = lpfc_get_eq_hdl(0);
11762 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
11763
11764 cpu = cpumask_first(cpu_present_mask);
11765 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
11766 cpu);
James Smart6a828b02019-01-28 11:14:31 -080011767 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smartdcaa2132019-11-04 16:57:06 -080011768 eqhdl = lpfc_get_eq_hdl(idx);
James Smart895427b2017-02-12 13:52:30 -080011769 eqhdl->idx = idx;
James Smart1ba981f2014-02-20 09:56:45 -050011770 }
James Smartda0436e2009-05-22 14:51:39 -040011771 }
11772 }
11773 return intr_mode;
11774}
11775
11776/**
11777 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
11778 * @phba: pointer to lpfc hba data structure.
11779 *
11780 * This routine is invoked to disable device interrupt and disassociate
11781 * the driver's interrupt handler(s) from interrupt vector(s) to device
11782 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
11783 * will release the interrupt vector(s) for the message signaled interrupt.
11784 **/
11785static void
11786lpfc_sli4_disable_intr(struct lpfc_hba *phba)
11787{
11788 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011789 if (phba->intr_type == MSIX) {
11790 int index;
James Smartdcaa2132019-11-04 16:57:06 -080011791 struct lpfc_hba_eq_hdl *eqhdl;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011792
11793 /* Free up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011794 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080011795 eqhdl = lpfc_get_eq_hdl(index);
11796 lpfc_irq_clear_aff(eqhdl);
11797 irq_set_affinity_hint(eqhdl->irq, NULL);
11798 free_irq(eqhdl->irq, eqhdl);
James Smartb3295c22019-01-28 11:14:30 -080011799 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011800 } else {
James Smartda0436e2009-05-22 14:51:39 -040011801 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011802 }
11803
11804 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040011805
11806 /* Reset interrupt management states */
11807 phba->intr_type = NONE;
11808 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040011809}
11810
11811/**
James Smart3772a992009-05-22 14:50:54 -040011812 * lpfc_unset_hba - Unset SLI3 hba device initialization
11813 * @phba: pointer to lpfc hba data structure.
11814 *
11815 * This routine is invoked to unset the HBA device initialization steps to
11816 * a device with SLI-3 interface spec.
11817 **/
11818static void
11819lpfc_unset_hba(struct lpfc_hba *phba)
11820{
11821 struct lpfc_vport *vport = phba->pport;
11822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11823
11824 spin_lock_irq(shost->host_lock);
11825 vport->load_flag |= FC_UNLOADING;
11826 spin_unlock_irq(shost->host_lock);
11827
James Smart72859902012-01-18 16:25:38 -050011828 kfree(phba->vpi_bmask);
11829 kfree(phba->vpi_ids);
11830
James Smart3772a992009-05-22 14:50:54 -040011831 lpfc_stop_hba_timers(phba);
11832
11833 phba->pport->work_port_events = 0;
11834
11835 lpfc_sli_hba_down(phba);
11836
11837 lpfc_sli_brdrestart(phba);
11838
11839 lpfc_sli_disable_intr(phba);
11840
11841 return;
11842}
11843
11844/**
James Smart5af5eee2010-10-22 11:06:38 -040011845 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
11846 * @phba: Pointer to HBA context object.
11847 *
11848 * This function is called in the SLI4 code path to wait for completion
11849 * of device's XRIs exchange busy. It will check the XRI exchange busy
11850 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
11851 * that, it will check the XRI exchange busy on outstanding FCP and ELS
11852 * I/Os every 30 seconds, log error message, and wait forever. Only when
11853 * all XRI exchange busy complete, the driver unload shall proceed with
11854 * invoking the function reset ioctl mailbox command to the CNA and the
11855 * the rest of the driver unload resource release.
11856 **/
11857static void
11858lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
11859{
James Smart5e5b5112019-01-28 11:14:22 -080011860 struct lpfc_sli4_hdw_queue *qp;
James Smartc00f62e2019-08-14 16:57:11 -070011861 int idx, ccnt;
James Smart5af5eee2010-10-22 11:06:38 -040011862 int wait_time = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011863 int io_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070011864 int nvmet_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040011865 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
11866
James Smartc3725bd2017-11-20 16:00:42 -080011867 /* Driver just aborted IOs during the hba_unset process. Pause
11868 * here to give the HBA time to complete the IO and get entries
11869 * into the abts lists.
11870 */
11871 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
11872
11873 /* Wait for NVME pending IO to flush back to transport. */
11874 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11875 lpfc_nvme_wait_for_io_drain(phba);
11876
James Smart5e5b5112019-01-28 11:14:22 -080011877 ccnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011878 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11879 qp = &phba->sli4_hba.hdwq[idx];
James Smartc00f62e2019-08-14 16:57:11 -070011880 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
11881 if (!io_xri_cmpl) /* if list is NOT empty */
11882 ccnt++;
James Smart5e5b5112019-01-28 11:14:22 -080011883 }
11884 if (ccnt)
11885 io_xri_cmpl = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011886
James Smart86c67372017-04-21 16:05:04 -070011887 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011888 nvmet_xri_cmpl =
11889 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11890 }
James Smart895427b2017-02-12 13:52:30 -080011891
James Smartc00f62e2019-08-14 16:57:11 -070011892 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040011893 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070011894 if (!nvmet_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070011895 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart68c9b552018-06-26 08:24:25 -070011896 "6424 NVMET XRI exchange busy "
11897 "wait time: %d seconds.\n",
11898 wait_time/1000);
James Smart5e5b5112019-01-28 11:14:22 -080011899 if (!io_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070011900 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc00f62e2019-08-14 16:57:11 -070011901 "6100 IO XRI exchange busy "
James Smart5af5eee2010-10-22 11:06:38 -040011902 "wait time: %d seconds.\n",
11903 wait_time/1000);
11904 if (!els_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070011905 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5af5eee2010-10-22 11:06:38 -040011906 "2878 ELS XRI exchange busy "
11907 "wait time: %d seconds.\n",
11908 wait_time/1000);
11909 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
11910 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
11911 } else {
11912 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
11913 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
11914 }
James Smart5e5b5112019-01-28 11:14:22 -080011915
11916 ccnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011917 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11918 qp = &phba->sli4_hba.hdwq[idx];
James Smartc00f62e2019-08-14 16:57:11 -070011919 io_xri_cmpl = list_empty(
11920 &qp->lpfc_abts_io_buf_list);
11921 if (!io_xri_cmpl) /* if list is NOT empty */
11922 ccnt++;
James Smart5e5b5112019-01-28 11:14:22 -080011923 }
11924 if (ccnt)
11925 io_xri_cmpl = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011926
James Smart86c67372017-04-21 16:05:04 -070011927 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011928 nvmet_xri_cmpl = list_empty(
11929 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11930 }
James Smart5af5eee2010-10-22 11:06:38 -040011931 els_xri_cmpl =
11932 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080011933
James Smart5af5eee2010-10-22 11:06:38 -040011934 }
11935}
11936
11937/**
James Smartda0436e2009-05-22 14:51:39 -040011938 * lpfc_sli4_hba_unset - Unset the fcoe hba
11939 * @phba: Pointer to HBA context object.
11940 *
11941 * This function is called in the SLI4 code path to reset the HBA's FCoE
11942 * function. The caller is not required to hold any lock. This routine
11943 * issues PCI function reset mailbox command to reset the FCoE function.
11944 * At the end of the function, it calls lpfc_hba_down_post function to
11945 * free any pending commands.
11946 **/
11947static void
11948lpfc_sli4_hba_unset(struct lpfc_hba *phba)
11949{
11950 int wait_cnt = 0;
11951 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040011952 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040011953
11954 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -080011955 if (phba->pport)
11956 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -040011957
11958 /*
11959 * Gracefully wait out the potential current outstanding asynchronous
11960 * mailbox command.
11961 */
11962
11963 /* First, block any pending async mailbox command from posted */
11964 spin_lock_irq(&phba->hbalock);
11965 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
11966 spin_unlock_irq(&phba->hbalock);
11967 /* Now, trying to wait it out if we can */
11968 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11969 msleep(10);
11970 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
11971 break;
11972 }
11973 /* Forcefully release the outstanding mailbox command if timed out */
11974 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11975 spin_lock_irq(&phba->hbalock);
11976 mboxq = phba->sli.mbox_active;
11977 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
11978 __lpfc_mbox_cmpl_put(phba, mboxq);
11979 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11980 phba->sli.mbox_active = NULL;
11981 spin_unlock_irq(&phba->hbalock);
11982 }
11983
James Smart5af5eee2010-10-22 11:06:38 -040011984 /* Abort all iocbs associated with the hba */
11985 lpfc_sli_hba_iocb_abort(phba);
11986
11987 /* Wait for completion of device XRI exchange busy */
11988 lpfc_sli4_xri_exchange_busy_wait(phba);
11989
James Smart93a4d6f2019-11-04 16:57:05 -080011990 /* per-phba callback de-registration for hotplug event */
SeongJae Park46da5472020-06-23 10:41:22 +020011991 if (phba->pport)
11992 lpfc_cpuhp_remove(phba);
James Smart93a4d6f2019-11-04 16:57:05 -080011993
James Smartda0436e2009-05-22 14:51:39 -040011994 /* Disable PCI subsystem interrupt */
11995 lpfc_sli4_disable_intr(phba);
11996
James Smart912e3ac2011-05-24 11:42:11 -040011997 /* Disable SR-IOV if enabled */
11998 if (phba->cfg_sriov_nr_virtfn)
11999 pci_disable_sriov(pdev);
12000
James Smartda0436e2009-05-22 14:51:39 -040012001 /* Stop kthread signal shall trigger work_done one more time */
12002 kthread_stop(phba->worker_thread);
12003
James Smartd2cc9bc2018-09-10 10:30:50 -070012004 /* Disable FW logging to host memory */
James Smart1165a5c2018-11-29 16:09:39 -080012005 lpfc_ras_stop_fwlog(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070012006
James Smartd1f525a2017-04-21 16:04:55 -070012007 /* Unset the queues shared with the hardware then release all
12008 * allocated resources.
12009 */
12010 lpfc_sli4_queue_unset(phba);
12011 lpfc_sli4_queue_destroy(phba);
12012
James Smart3677a3a2010-09-29 11:19:14 -040012013 /* Reset SLI4 HBA FCoE function */
12014 lpfc_pci_function_reset(phba);
12015
James Smart1165a5c2018-11-29 16:09:39 -080012016 /* Free RAS DMA memory */
12017 if (phba->ras_fwlog.ras_enabled)
12018 lpfc_sli4_ras_dma_free(phba);
12019
James Smartda0436e2009-05-22 14:51:39 -040012020 /* Stop the SLI4 device port */
James Smart1ffdd2c2019-03-04 15:27:51 -080012021 if (phba->pport)
12022 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -040012023}
12024
James Smart28baac72010-02-12 14:42:03 -050012025 /**
12026 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
12027 * @phba: Pointer to HBA context object.
12028 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
12029 *
12030 * This function is called in the SLI4 code path to read the port's
12031 * sli4 capabilities.
12032 *
12033 * This function may be be called from any context that can block-wait
12034 * for the completion. The expectation is that this routine is called
12035 * typically from probe_one or from the online routine.
12036 **/
12037int
12038lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
12039{
12040 int rc;
12041 struct lpfc_mqe *mqe;
12042 struct lpfc_pc_sli4_params *sli4_params;
12043 uint32_t mbox_tmo;
12044
12045 rc = 0;
12046 mqe = &mboxq->u.mqe;
12047
12048 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050012049 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050012050 if (!phba->sli4_hba.intr_enable)
12051 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
12052 else {
James Smarta183a152011-10-10 21:32:43 -040012053 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050012054 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
12055 }
12056
12057 if (unlikely(rc))
12058 return 1;
12059
12060 sli4_params = &phba->sli4_hba.pc_sli4_params;
12061 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
12062 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
12063 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
12064 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
12065 &mqe->un.sli4_params);
12066 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
12067 &mqe->un.sli4_params);
12068 sli4_params->proto_types = mqe->un.sli4_params.word3;
12069 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
12070 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
12071 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
12072 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
12073 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
12074 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
12075 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
12076 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
12077 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
12078 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
12079 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
12080 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
12081 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
12082 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
12083 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
12084 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
12085 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
12086 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
12087 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
12088 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040012089
12090 /* Make sure that sge_supp_len can be handled by the driver */
12091 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
12092 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
12093
James Smart28baac72010-02-12 14:42:03 -050012094 return rc;
12095}
12096
James Smartda0436e2009-05-22 14:51:39 -040012097/**
James Smartfedd3b72011-02-16 12:39:24 -050012098 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
12099 * @phba: Pointer to HBA context object.
12100 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
12101 *
12102 * This function is called in the SLI4 code path to read the port's
12103 * sli4 capabilities.
12104 *
12105 * This function may be be called from any context that can block-wait
12106 * for the completion. The expectation is that this routine is called
12107 * typically from probe_one or from the online routine.
12108 **/
12109int
12110lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
12111{
12112 int rc;
12113 struct lpfc_mqe *mqe = &mboxq->u.mqe;
12114 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040012115 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050012116 int length;
James Smartbf316c72018-04-09 14:24:28 -070012117 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050012118 struct lpfc_sli4_parameters *mbx_sli4_parameters;
12119
James Smart6d368e52011-05-24 11:44:12 -040012120 /*
12121 * By default, the driver assumes the SLI4 port requires RPI
12122 * header postings. The SLI4_PARAM response will correct this
12123 * assumption.
12124 */
12125 phba->sli4_hba.rpi_hdrs_in_use = 1;
12126
James Smartfedd3b72011-02-16 12:39:24 -050012127 /* Read the port's SLI4 Config Parameters */
12128 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
12129 sizeof(struct lpfc_sli4_cfg_mhdr));
12130 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
12131 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
12132 length, LPFC_SLI4_MBX_EMBED);
12133 if (!phba->sli4_hba.intr_enable)
12134 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040012135 else {
12136 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
12137 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
12138 }
James Smartfedd3b72011-02-16 12:39:24 -050012139 if (unlikely(rc))
12140 return rc;
12141 sli4_params = &phba->sli4_hba.pc_sli4_params;
12142 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
12143 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
12144 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
12145 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
12146 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
12147 mbx_sli4_parameters);
12148 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
12149 mbx_sli4_parameters);
12150 if (bf_get(cfg_phwq, mbx_sli4_parameters))
12151 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
12152 else
12153 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
12154 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
12155 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050012156 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050012157 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
12158 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
12159 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
12160 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080012161 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
12162 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040012163 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070012164 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smart83c6cb12019-10-18 14:18:30 -070012165 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050012166 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
12167 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080012168 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050012169 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
12170 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040012171 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
12172 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080012173
James Smartd79c9e92019-08-14 16:57:09 -070012174 /* Check for Extended Pre-Registered SGL support */
12175 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
12176
James Smartc15e0702019-05-21 17:49:02 -070012177 /* Check for firmware nvme support */
12178 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
12179 bf_get(cfg_xib, mbx_sli4_parameters));
James Smart895427b2017-02-12 13:52:30 -080012180
James Smartc15e0702019-05-21 17:49:02 -070012181 if (rc) {
12182 /* Save this to indicate the Firmware supports NVME */
12183 sli4_params->nvme = 1;
12184
12185 /* Firmware NVME support, check driver FC4 NVME support */
12186 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
12187 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
12188 "6133 Disabling NVME support: "
12189 "FC4 type not supported: x%x\n",
12190 phba->cfg_enable_fc4_type);
12191 goto fcponly;
12192 }
12193 } else {
12194 /* No firmware NVME support, check driver FC4 NVME support */
12195 sli4_params->nvme = 0;
12196 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
12198 "6101 Disabling NVME support: Not "
12199 "supported by firmware (%d %d) x%x\n",
12200 bf_get(cfg_nvme, mbx_sli4_parameters),
12201 bf_get(cfg_xib, mbx_sli4_parameters),
12202 phba->cfg_enable_fc4_type);
12203fcponly:
12204 phba->nvme_support = 0;
12205 phba->nvmet_support = 0;
12206 phba->cfg_nvmet_mrq = 0;
James Smart6a224b42019-08-14 16:56:57 -070012207 phba->cfg_nvme_seg_cnt = 0;
James Smartc15e0702019-05-21 17:49:02 -070012208
12209 /* If no FC4 type support, move to just SCSI support */
12210 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
12211 return -ENODEV;
12212 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
12213 }
James Smart895427b2017-02-12 13:52:30 -080012214 }
James Smart05580562011-05-24 11:40:48 -040012215
James Smartc26c2652019-08-14 16:56:49 -070012216 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
James Smarta5f73372019-09-21 20:58:50 -070012217 * accommodate 512K and 1M IOs in a single nvme buf.
James Smartc26c2652019-08-14 16:56:49 -070012218 */
James Smarta5f73372019-09-21 20:58:50 -070012219 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
James Smartc26c2652019-08-14 16:56:49 -070012220 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
James Smartc26c2652019-08-14 16:56:49 -070012221
James Smart414abe02018-06-26 08:24:26 -070012222 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
12223 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
12224 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
12225 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080012226
James Smart20aefac2018-01-30 15:58:58 -080012227 /*
12228 * To support Suppress Response feature we must satisfy 3 conditions.
12229 * lpfc_suppress_rsp module parameter must be set (default).
12230 * In SLI4-Parameters Descriptor:
12231 * Extended Inline Buffers (XIB) must be supported.
12232 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
12233 * (double negative).
12234 */
12235 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
12236 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080012237 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080012238 else
12239 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080012240
James Smart0cf07f842017-06-01 21:07:10 -070012241 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
12242 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
12243
James Smart05580562011-05-24 11:40:48 -040012244 /* Make sure that sge_supp_len can be handled by the driver */
12245 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
12246 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
12247
James Smartb5c53952016-03-31 14:12:30 -070012248 /*
James Smartc176ffa2018-01-30 15:58:46 -080012249 * Check whether the adapter supports an embedded copy of the
12250 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
12251 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070012252 */
12253 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
12254 phba->fcp_embed_io = 1;
12255 else
12256 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070012257
James Smart0bc2b7c2018-02-22 08:18:48 -080012258 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070012259 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080012260 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070012261 phba->cfg_enable_pbde,
12262 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080012263 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080012264
James Smartbf316c72018-04-09 14:24:28 -070012265 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
12266 LPFC_SLI_INTF_IF_TYPE_2) &&
12267 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070012268 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070012269 exp_wqcq_pages = false;
12270
James Smartc176ffa2018-01-30 15:58:46 -080012271 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
12272 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070012273 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080012274 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
12275 phba->enab_exp_wqcq_pages = 1;
12276 else
12277 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070012278 /*
12279 * Check if the SLI port supports MDS Diagnostics
12280 */
12281 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
12282 phba->mds_diags_support = 1;
12283 else
12284 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070012285
James Smart0d8af092019-08-14 16:57:10 -070012286 /*
12287 * Check if the SLI port supports NSLER
12288 */
12289 if (bf_get(cfg_nsler, mbx_sli4_parameters))
12290 phba->nsler = 1;
12291 else
12292 phba->nsler = 0;
12293
James Smart8aaa7bc2020-10-20 13:27:17 -070012294 /* Save PB info for use during HBA setup */
12295 sli4_params->mi_ver = bf_get(cfg_mi_ver, mbx_sli4_parameters);
12296 sli4_params->mib_bde_cnt = bf_get(cfg_mib_bde_cnt, mbx_sli4_parameters);
12297 sli4_params->mib_size = mbx_sli4_parameters->mib_size;
12298 sli4_params->mi_value = LPFC_DFLT_MIB_VAL;
12299
12300 /* Next we check for Vendor MIB support */
12301 if (sli4_params->mi_ver && phba->cfg_enable_mi)
12302 phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT;
12303
12304 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12305 "6461 MIB attr %d enable %d FDMI %d buf %d:%d\n",
12306 sli4_params->mi_ver, phba->cfg_enable_mi,
12307 sli4_params->mi_value, sli4_params->mib_bde_cnt,
12308 sli4_params->mib_size);
James Smartfedd3b72011-02-16 12:39:24 -050012309 return 0;
12310}
12311
12312/**
James Smart3772a992009-05-22 14:50:54 -040012313 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
12314 * @pdev: pointer to PCI device
12315 * @pid: pointer to PCI device identifier
12316 *
12317 * This routine is to be called to attach a device with SLI-3 interface spec
12318 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12319 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12320 * information of the device and driver to see if the driver state that it can
12321 * support this kind of device. If the match is successful, the driver core
12322 * invokes this routine. If this routine determines it can claim the HBA, it
12323 * does all the initialization that it needs to do to handle the HBA properly.
12324 *
12325 * Return code
12326 * 0 - driver can claim the device
12327 * negative value - driver can not claim the device
12328 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012329static int
James Smart3772a992009-05-22 14:50:54 -040012330lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
12331{
12332 struct lpfc_hba *phba;
12333 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040012334 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040012335 int error;
12336 uint32_t cfg_mode, intr_mode;
12337
12338 /* Allocate memory for HBA structure */
12339 phba = lpfc_hba_alloc(pdev);
12340 if (!phba)
12341 return -ENOMEM;
12342
12343 /* Perform generic PCI device enabling operation */
12344 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040012345 if (error)
James Smart3772a992009-05-22 14:50:54 -040012346 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040012347
12348 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
12349 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
12350 if (error)
12351 goto out_disable_pci_dev;
12352
12353 /* Set up SLI-3 specific device PCI memory space */
12354 error = lpfc_sli_pci_mem_setup(phba);
12355 if (error) {
12356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12357 "1402 Failed to set up pci memory space.\n");
12358 goto out_disable_pci_dev;
12359 }
12360
James Smart3772a992009-05-22 14:50:54 -040012361 /* Set up SLI-3 specific device driver resources */
12362 error = lpfc_sli_driver_resource_setup(phba);
12363 if (error) {
12364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12365 "1404 Failed to set up driver resource.\n");
12366 goto out_unset_pci_mem_s3;
12367 }
12368
12369 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070012370
James Smart3772a992009-05-22 14:50:54 -040012371 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
12372 if (error) {
12373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12374 "1405 Failed to initialize iocb list.\n");
12375 goto out_unset_driver_resource_s3;
12376 }
12377
12378 /* Set up common device driver resources */
12379 error = lpfc_setup_driver_resource_phase2(phba);
12380 if (error) {
12381 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12382 "1406 Failed to set up driver resource.\n");
12383 goto out_free_iocb_list;
12384 }
12385
James Smart079b5c92011-08-21 21:48:49 -040012386 /* Get the default values for Model Name and Description */
12387 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
12388
James Smart3772a992009-05-22 14:50:54 -040012389 /* Create SCSI host to the physical port */
12390 error = lpfc_create_shost(phba);
12391 if (error) {
12392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12393 "1407 Failed to create scsi host.\n");
12394 goto out_unset_driver_resource;
12395 }
12396
12397 /* Configure sysfs attributes */
12398 vport = phba->pport;
12399 error = lpfc_alloc_sysfs_attr(vport);
12400 if (error) {
12401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12402 "1476 Failed to allocate sysfs attr\n");
12403 goto out_destroy_shost;
12404 }
12405
James Smart6669f9b2009-10-02 15:16:45 -040012406 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040012407 /* Now, trying to enable interrupt and bring up the device */
12408 cfg_mode = phba->cfg_use_msi;
12409 while (true) {
12410 /* Put device to a known state before enabling interrupt */
12411 lpfc_stop_port(phba);
12412 /* Configure and enable interrupt */
12413 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
12414 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012415 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040012416 "0431 Failed to enable interrupt.\n");
12417 error = -ENODEV;
12418 goto out_free_sysfs_attr;
12419 }
12420 /* SLI-3 HBA setup */
12421 if (lpfc_sli_hba_setup(phba)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012422 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040012423 "1477 Failed to set up hba\n");
12424 error = -ENODEV;
12425 goto out_remove_device;
12426 }
12427
12428 /* Wait 50ms for the interrupts of previous mailbox commands */
12429 msleep(50);
12430 /* Check active interrupts on message signaled interrupts */
12431 if (intr_mode == 0 ||
12432 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
12433 /* Log the current active interrupt mode */
12434 phba->intr_mode = intr_mode;
12435 lpfc_log_intr_mode(phba, intr_mode);
12436 break;
12437 } else {
12438 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12439 "0447 Configure interrupt mode (%d) "
12440 "failed active interrupt test.\n",
12441 intr_mode);
12442 /* Disable the current interrupt mode */
12443 lpfc_sli_disable_intr(phba);
12444 /* Try next level of interrupt mode */
12445 cfg_mode = --intr_mode;
12446 }
12447 }
12448
12449 /* Perform post initialization setup */
12450 lpfc_post_init_setup(phba);
12451
12452 /* Check if there are static vports to be created. */
12453 lpfc_create_static_vport(phba);
12454
12455 return 0;
12456
12457out_remove_device:
12458 lpfc_unset_hba(phba);
12459out_free_sysfs_attr:
12460 lpfc_free_sysfs_attr(vport);
12461out_destroy_shost:
12462 lpfc_destroy_shost(phba);
12463out_unset_driver_resource:
12464 lpfc_unset_driver_resource_phase2(phba);
12465out_free_iocb_list:
12466 lpfc_free_iocb_list(phba);
12467out_unset_driver_resource_s3:
12468 lpfc_sli_driver_resource_unset(phba);
12469out_unset_pci_mem_s3:
12470 lpfc_sli_pci_mem_unset(phba);
12471out_disable_pci_dev:
12472 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040012473 if (shost)
12474 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040012475out_free_phba:
12476 lpfc_hba_free(phba);
12477 return error;
12478}
12479
12480/**
12481 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040012482 * @pdev: pointer to PCI device
12483 *
James Smart3772a992009-05-22 14:50:54 -040012484 * This routine is to be called to disattach a device with SLI-3 interface
12485 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
12486 * removed from PCI bus, it performs all the necessary cleanup for the HBA
12487 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040012488 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012489static void
James Smart3772a992009-05-22 14:50:54 -040012490lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050012491{
James Smart2e0fef82007-06-17 19:56:36 -050012492 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050012494 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050012495 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050012496 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050012497
James Smart549e55c2007-08-02 11:09:51 -040012498 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040012499 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040012500 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050012501
James Smart858c9f62007-06-17 19:56:39 -050012502 lpfc_free_sysfs_attr(vport);
12503
James Smarteada2722008-12-04 22:39:13 -050012504 /* Release all the vports against this physical port */
12505 vports = lpfc_create_vport_work_array(phba);
12506 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040012507 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
12508 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
12509 continue;
James Smarteada2722008-12-04 22:39:13 -050012510 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040012511 }
James Smarteada2722008-12-04 22:39:13 -050012512 lpfc_destroy_vport_work_array(phba, vports);
12513
James Smart95f0ef82020-11-15 11:26:32 -080012514 /* Remove FC host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050012515 fc_remove_host(shost);
James Smarte9b11082020-11-15 11:26:33 -080012516 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080012517
James Smart95f0ef82020-11-15 11:26:32 -080012518 /* Clean up all nodes, mailboxes and IOs. */
James Smart87af33f2007-10-27 13:37:43 -040012519 lpfc_cleanup(vport);
12520
James Smart2e0fef82007-06-17 19:56:36 -050012521 /*
12522 * Bring down the SLI Layer. This step disable all interrupts,
12523 * clears the rings, discards all mailbox commands, and resets
12524 * the HBA.
12525 */
James Smarta257bf92009-04-06 18:48:10 -040012526
Justin P. Mattock48e34d02010-12-30 15:07:58 -080012527 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050012528 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040012529 /* Stop kthread signal shall trigger work_done one more time */
12530 kthread_stop(phba->worker_thread);
12531 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050012532 lpfc_sli_brdrestart(phba);
12533
James Smart72859902012-01-18 16:25:38 -050012534 kfree(phba->vpi_bmask);
12535 kfree(phba->vpi_ids);
12536
James Smart3772a992009-05-22 14:50:54 -040012537 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070012538 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050012539 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070012540 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050012541
James Smart858c9f62007-06-17 19:56:39 -050012542 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050012543
James Smart912e3ac2011-05-24 11:42:11 -040012544 /* Disable SR-IOV if enabled */
12545 if (phba->cfg_sriov_nr_virtfn)
12546 pci_disable_sriov(pdev);
12547
James Smart5b75da22008-12-04 22:39:35 -050012548 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012549 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050012550
James Smart858c9f62007-06-17 19:56:39 -050012551 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050012552
12553 /*
12554 * Call scsi_free before mem_free since scsi bufs are released to their
12555 * corresponding pools here.
12556 */
12557 lpfc_scsi_free(phba);
James Smart0794d602019-01-28 11:14:19 -080012558 lpfc_free_iocb_list(phba);
12559
James Smart3772a992009-05-22 14:50:54 -040012560 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050012561
James Smart34b02dc2008-08-24 21:49:55 -040012562 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
12563 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050012564
James Smart2e0fef82007-06-17 19:56:36 -050012565 /* Free resources associated with SLI2 interface */
12566 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040012567 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050012568
12569 /* unmap adapter SLIM and Control Registers */
12570 iounmap(phba->ctrl_regs_memmap_p);
12571 iounmap(phba->slim_memmap_p);
12572
James Smart3772a992009-05-22 14:50:54 -040012573 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050012574
Johannes Thumshirne0c04832016-06-07 09:44:03 +020012575 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050012576 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050012577}
12578
Linas Vepstas8d63f372007-02-14 14:28:36 -060012579/**
James Smart3772a992009-05-22 14:50:54 -040012580 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012581 * @dev_d: pointer to device
James Smart3a55b532008-12-04 22:38:54 -050012582 *
James Smart3772a992009-05-22 14:50:54 -040012583 * This routine is to be called from the kernel's PCI subsystem to support
12584 * system Power Management (PM) to device with SLI-3 interface spec. When
12585 * PM invokes this method, it quiesces the device by stopping the driver's
12586 * worker thread for the device, turning off device's interrupt and DMA,
12587 * and bring the device offline. Note that as the driver implements the
12588 * minimum PM requirements to a power-aware driver's PM support for the
12589 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12590 * to the suspend() method call will be treated as SUSPEND and the driver will
12591 * fully reinitialize its device during resume() method call, the driver will
12592 * set device to PCI_D3hot state in PCI config space instead of setting it
12593 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050012594 *
12595 * Return code
James Smart3772a992009-05-22 14:50:54 -040012596 * 0 - driver suspended the device
12597 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012598 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012599static int __maybe_unused
12600lpfc_pci_suspend_one_s3(struct device *dev_d)
James Smart3a55b532008-12-04 22:38:54 -050012601{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012602 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smart3a55b532008-12-04 22:38:54 -050012603 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12604
12605 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12606 "0473 PCI device Power Management suspend.\n");
12607
12608 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012609 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050012610 lpfc_offline(phba);
12611 kthread_stop(phba->worker_thread);
12612
12613 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040012614 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050012615
James Smart3a55b532008-12-04 22:38:54 -050012616 return 0;
12617}
12618
12619/**
James Smart3772a992009-05-22 14:50:54 -040012620 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012621 * @dev_d: pointer to device
James Smart3a55b532008-12-04 22:38:54 -050012622 *
James Smart3772a992009-05-22 14:50:54 -040012623 * This routine is to be called from the kernel's PCI subsystem to support
12624 * system Power Management (PM) to device with SLI-3 interface spec. When PM
12625 * invokes this method, it restores the device's PCI config space state and
12626 * fully reinitializes the device and brings it online. Note that as the
12627 * driver implements the minimum PM requirements to a power-aware driver's
12628 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
12629 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
12630 * driver will fully reinitialize its device during resume() method call,
12631 * the device will be set to PCI_D0 directly in PCI config space before
12632 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050012633 *
12634 * Return code
James Smart3772a992009-05-22 14:50:54 -040012635 * 0 - driver suspended the device
12636 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012637 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012638static int __maybe_unused
12639lpfc_pci_resume_one_s3(struct device *dev_d)
James Smart3a55b532008-12-04 22:38:54 -050012640{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053012641 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smart3a55b532008-12-04 22:38:54 -050012642 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050012643 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012644 int error;
12645
12646 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12647 "0452 PCI device Power Management resume.\n");
12648
James Smart3a55b532008-12-04 22:38:54 -050012649 /* Startup the kernel thread for this host adapter. */
12650 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12651 "lpfc_worker_%d", phba->brd_no);
12652 if (IS_ERR(phba->worker_thread)) {
12653 error = PTR_ERR(phba->worker_thread);
12654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12655 "0434 PM resume failed to start worker "
12656 "thread: error=x%x.\n", error);
12657 return error;
12658 }
12659
James Smart5b75da22008-12-04 22:39:35 -050012660 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012661 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012662 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012663 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -050012664 "0430 PM resume Failed to enable interrupt\n");
12665 return -EIO;
12666 } else
12667 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012668
12669 /* Restart HBA and bring it online */
12670 lpfc_sli_brdrestart(phba);
12671 lpfc_online(phba);
12672
James Smart5b75da22008-12-04 22:39:35 -050012673 /* Log the current active interrupt mode */
12674 lpfc_log_intr_mode(phba, phba->intr_mode);
12675
James Smart3a55b532008-12-04 22:38:54 -050012676 return 0;
12677}
12678
12679/**
James Smart891478a2009-11-18 15:40:23 -050012680 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
12681 * @phba: pointer to lpfc hba data structure.
12682 *
12683 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040012684 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050012685 **/
12686static void
12687lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
12688{
Dick Kennedy372c1872020-06-30 14:50:00 -070012689 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050012690 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040012691
12692 /*
12693 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12694 * and let the SCSI mid-layer to retry them to recover.
12695 */
James Smartdb55fba2014-04-04 13:52:02 -040012696 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050012697}
12698
12699/**
James Smart0d878412009-10-02 15:16:56 -040012700 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
12701 * @phba: pointer to lpfc hba data structure.
12702 *
12703 * This routine is called to prepare the SLI3 device for PCI slot reset. It
12704 * disables the device interrupt and pci device, and aborts the internal FCP
12705 * pending I/Os.
12706 **/
12707static void
12708lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
12709{
Dick Kennedy372c1872020-06-30 14:50:00 -070012710 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050012711 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040012712
James Smart75baf692010-06-08 18:31:21 -040012713 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012714 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012715
James Smarte2af0d22010-03-15 11:25:32 -040012716 /* Block all SCSI devices' I/Os on the host */
12717 lpfc_scsi_dev_block(phba);
12718
James Smartea714f32013-04-17 20:18:47 -040012719 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
James Smartc00f62e2019-08-14 16:57:11 -070012720 lpfc_sli_flush_io_rings(phba);
James Smartea714f32013-04-17 20:18:47 -040012721
James Smarte2af0d22010-03-15 11:25:32 -040012722 /* stop all timers */
12723 lpfc_stop_hba_timers(phba);
12724
James Smart0d878412009-10-02 15:16:56 -040012725 /* Disable interrupt and pci device */
12726 lpfc_sli_disable_intr(phba);
12727 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040012728}
12729
12730/**
12731 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
12732 * @phba: pointer to lpfc hba data structure.
12733 *
12734 * This routine is called to prepare the SLI3 device for PCI slot permanently
12735 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12736 * pending I/Os.
12737 **/
12738static void
James Smart75baf692010-06-08 18:31:21 -040012739lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040012740{
Dick Kennedy372c1872020-06-30 14:50:00 -070012741 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050012742 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040012743 /* Block all SCSI devices' I/Os on the host */
12744 lpfc_scsi_dev_block(phba);
12745
12746 /* stop all timers */
12747 lpfc_stop_hba_timers(phba);
12748
James Smart0d878412009-10-02 15:16:56 -040012749 /* Clean up all driver's outstanding SCSI I/Os */
James Smartc00f62e2019-08-14 16:57:11 -070012750 lpfc_sli_flush_io_rings(phba);
James Smart0d878412009-10-02 15:16:56 -040012751}
12752
12753/**
James Smart3772a992009-05-22 14:50:54 -040012754 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040012755 * @pdev: pointer to PCI device.
12756 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012757 *
James Smart3772a992009-05-22 14:50:54 -040012758 * This routine is called from the PCI subsystem for I/O error handling to
12759 * device with SLI-3 interface spec. This function is called by the PCI
12760 * subsystem after a PCI bus error affecting this device has been detected.
12761 * When this function is invoked, it will need to stop all the I/Os and
12762 * interrupt(s) to the device. Once that is done, it will return
12763 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
12764 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040012765 *
12766 * Return codes
James Smart0d878412009-10-02 15:16:56 -040012767 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040012768 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12769 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040012770 **/
James Smart3772a992009-05-22 14:50:54 -040012771static pci_ers_result_t
12772lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012773{
James Smart51ef4c22007-08-02 11:10:31 -040012774 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12775 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012776
James Smart0d878412009-10-02 15:16:56 -040012777 switch (state) {
12778 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050012779 /* Non-fatal error, prepare for recovery */
12780 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040012781 return PCI_ERS_RESULT_CAN_RECOVER;
12782 case pci_channel_io_frozen:
12783 /* Fatal error, prepare for slot reset */
12784 lpfc_sli_prep_dev_for_reset(phba);
12785 return PCI_ERS_RESULT_NEED_RESET;
12786 case pci_channel_io_perm_failure:
12787 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040012788 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012789 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040012790 default:
12791 /* Unknown state, prepare and request slot reset */
Dick Kennedy372c1872020-06-30 14:50:00 -070012792 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0d878412009-10-02 15:16:56 -040012793 "0472 Unknown PCI error state: x%x\n", state);
12794 lpfc_sli_prep_dev_for_reset(phba);
12795 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040012796 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060012797}
12798
12799/**
James Smart3772a992009-05-22 14:50:54 -040012800 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040012801 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012802 *
James Smart3772a992009-05-22 14:50:54 -040012803 * This routine is called from the PCI subsystem for error handling to
12804 * device with SLI-3 interface spec. This is called after PCI bus has been
12805 * reset to restart the PCI card from scratch, as if from a cold-boot.
12806 * During the PCI subsystem error recovery, after driver returns
12807 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12808 * recovery and then call this routine before calling the .resume method
12809 * to recover the device. This function will initialize the HBA device,
12810 * enable the interrupt, but it will just put the HBA to offline state
12811 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040012812 *
12813 * Return codes
James Smart3772a992009-05-22 14:50:54 -040012814 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12815 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060012816 */
James Smart3772a992009-05-22 14:50:54 -040012817static pci_ers_result_t
12818lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012819{
James Smart51ef4c22007-08-02 11:10:31 -040012820 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12821 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012822 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050012823 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012824
12825 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110012826 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012827 printk(KERN_ERR "lpfc: Cannot re-enable "
12828 "PCI device after reset.\n");
12829 return PCI_ERS_RESULT_DISCONNECT;
12830 }
12831
James Smart97207482008-12-04 22:39:19 -050012832 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012833
12834 /*
12835 * As the new kernel behavior of pci_restore_state() API call clears
12836 * device saved_state flag, need to save the restored state again.
12837 */
12838 pci_save_state(pdev);
12839
James Smart97207482008-12-04 22:39:19 -050012840 if (pdev->is_busmaster)
12841 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012842
James Smart92d7f7b2007-06-17 19:56:38 -050012843 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040012844 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050012845 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012846
James Smart5b75da22008-12-04 22:39:35 -050012847 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012848 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012849 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012850 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -050012851 "0427 Cannot re-enable interrupt after "
12852 "slot reset.\n");
12853 return PCI_ERS_RESULT_DISCONNECT;
12854 } else
12855 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012856
James Smart75baf692010-06-08 18:31:21 -040012857 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040012858 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012859 lpfc_offline(phba);
12860 lpfc_sli_brdrestart(phba);
12861
James Smart5b75da22008-12-04 22:39:35 -050012862 /* Log the current active interrupt mode */
12863 lpfc_log_intr_mode(phba, phba->intr_mode);
12864
Linas Vepstas8d63f372007-02-14 14:28:36 -060012865 return PCI_ERS_RESULT_RECOVERED;
12866}
12867
12868/**
James Smart3772a992009-05-22 14:50:54 -040012869 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040012870 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060012871 *
James Smart3772a992009-05-22 14:50:54 -040012872 * This routine is called from the PCI subsystem for error handling to device
12873 * with SLI-3 interface spec. It is called when kernel error recovery tells
12874 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12875 * error recovery. After this call, traffic can start to flow from this device
12876 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012877 */
James Smart3772a992009-05-22 14:50:54 -040012878static void
12879lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012880{
James Smart51ef4c22007-08-02 11:10:31 -040012881 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12882 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012883
James Smarte2af0d22010-03-15 11:25:32 -040012884 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040012885 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012886}
12887
James Smart3772a992009-05-22 14:50:54 -040012888/**
James Smartda0436e2009-05-22 14:51:39 -040012889 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
12890 * @phba: pointer to lpfc hba data structure.
12891 *
12892 * returns the number of ELS/CT IOCBs to reserve
12893 **/
12894int
12895lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
12896{
12897 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
12898
James Smartf1126682009-06-10 17:22:44 -040012899 if (phba->sli_rev == LPFC_SLI_REV4) {
12900 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040012901 return 10;
James Smartf1126682009-06-10 17:22:44 -040012902 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040012903 return 25;
James Smartf1126682009-06-10 17:22:44 -040012904 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040012905 return 50;
James Smartf1126682009-06-10 17:22:44 -040012906 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040012907 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040012908 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040012909 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040012910 else if (max_xri <= 2048)
12911 return 200;
12912 else
12913 return 250;
James Smartf1126682009-06-10 17:22:44 -040012914 } else
12915 return 0;
James Smartda0436e2009-05-22 14:51:39 -040012916}
12917
12918/**
James Smart895427b2017-02-12 13:52:30 -080012919 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
12920 * @phba: pointer to lpfc hba data structure.
12921 *
James Smartf358dd02017-02-12 13:52:34 -080012922 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080012923 **/
12924int
12925lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
12926{
12927 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
12928
James Smartf358dd02017-02-12 13:52:34 -080012929 if (phba->nvmet_support)
12930 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080012931 return max_xri;
12932}
12933
12934
James Smart0a5ce732019-10-18 14:18:18 -070012935static int
James Smart1feb8202018-02-22 08:18:47 -080012936lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
12937 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
12938 const struct firmware *fw)
12939{
James Smart0a5ce732019-10-18 14:18:18 -070012940 int rc;
James Smart1feb8202018-02-22 08:18:47 -080012941
James Smart0a5ce732019-10-18 14:18:18 -070012942 /* Three cases: (1) FW was not supported on the detected adapter.
12943 * (2) FW update has been locked out administratively.
12944 * (3) Some other error during FW update.
12945 * In each case, an unmaskable message is written to the console
12946 * for admin diagnosis.
12947 */
12948 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
James Smart1feb8202018-02-22 08:18:47 -080012949 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
James Smart5792a0e2019-10-25 11:43:42 -070012950 magic_number != MAGIC_NUMBER_G6) ||
James Smart1feb8202018-02-22 08:18:47 -080012951 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
James Smart5792a0e2019-10-25 11:43:42 -070012952 magic_number != MAGIC_NUMBER_G7)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012953 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070012954 "3030 This firmware version is not supported on"
12955 " this HBA model. Device:%x Magic:%x Type:%x "
12956 "ID:%x Size %d %zd\n",
12957 phba->pcidev->device, magic_number, ftype, fid,
12958 fsize, fw->size);
12959 rc = -EINVAL;
12960 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012961 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070012962 "3021 Firmware downloads have been prohibited "
12963 "by a system configuration setting on "
12964 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12965 "%zd\n",
12966 phba->pcidev->device, magic_number, ftype, fid,
12967 fsize, fw->size);
12968 rc = -EACCES;
12969 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -070012970 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070012971 "3022 FW Download failed. Add Status x%x "
12972 "Device:%x Magic:%x Type:%x ID:%x Size %d "
12973 "%zd\n",
12974 offset, phba->pcidev->device, magic_number,
12975 ftype, fid, fsize, fw->size);
12976 rc = -EIO;
12977 }
12978 return rc;
James Smart1feb8202018-02-22 08:18:47 -080012979}
James Smart1feb8202018-02-22 08:18:47 -080012980
James Smart895427b2017-02-12 13:52:30 -080012981/**
James Smart52d52442011-05-24 11:42:45 -040012982 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040012983 * @fw: pointer to firmware image returned from request_firmware.
James Smart0a5ce732019-10-18 14:18:18 -070012984 * @context: pointer to firmware image returned from request_firmware.
James Smart52d52442011-05-24 11:42:45 -040012985 *
James Smart52d52442011-05-24 11:42:45 -040012986 **/
James Smartce396282012-09-29 11:30:56 -040012987static void
12988lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040012989{
James Smartce396282012-09-29 11:30:56 -040012990 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050012991 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040012992 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040012993 struct list_head dma_buffer_list;
12994 int i, rc = 0;
12995 struct lpfc_dmabuf *dmabuf, *next;
12996 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070012997 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040012998
James Smartc71ab862012-10-31 14:44:33 -040012999 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040013000 if (!fw) {
13001 rc = -ENXIO;
13002 goto out;
13003 }
13004 image = (struct lpfc_grp_hdr *)fw->data;
13005
James Smart6b6ef5d2016-10-13 15:06:17 -070013006 magic_number = be32_to_cpu(image->magic_number);
13007 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080013008 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070013009 fsize = be32_to_cpu(image->size);
13010
James Smart52d52442011-05-24 11:42:45 -040013011 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040013012 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040013013 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013014 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartce396282012-09-29 11:30:56 -040013015 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040013016 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040013017 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040013018 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
13019 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
13020 GFP_KERNEL);
13021 if (!dmabuf) {
13022 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040013023 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040013024 }
13025 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
13026 SLI4_PAGE_SIZE,
13027 &dmabuf->phys,
13028 GFP_KERNEL);
13029 if (!dmabuf->virt) {
13030 kfree(dmabuf);
13031 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040013032 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040013033 }
13034 list_add_tail(&dmabuf->list, &dma_buffer_list);
13035 }
13036 while (offset < fw->size) {
13037 temp_offset = offset;
13038 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040013039 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040013040 memcpy(dmabuf->virt,
13041 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040013042 fw->size - temp_offset);
13043 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040013044 break;
13045 }
James Smart52d52442011-05-24 11:42:45 -040013046 memcpy(dmabuf->virt, fw->data + temp_offset,
13047 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040013048 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040013049 }
13050 rc = lpfc_wr_object(phba, &dma_buffer_list,
13051 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080013052 if (rc) {
James Smart0a5ce732019-10-18 14:18:18 -070013053 rc = lpfc_log_write_firmware_error(phba, offset,
13054 magic_number,
13055 ftype,
13056 fid,
13057 fsize,
13058 fw);
James Smartce396282012-09-29 11:30:56 -040013059 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080013060 }
James Smart52d52442011-05-24 11:42:45 -040013061 }
13062 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080013063 } else
Dick Kennedy372c1872020-06-30 14:50:00 -070013064 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1feb8202018-02-22 08:18:47 -080013065 "3029 Skipped Firmware update, Current "
13066 "Version:%s New Version:%s\n",
13067 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040013068
13069release_out:
James Smart52d52442011-05-24 11:42:45 -040013070 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
13071 list_del(&dmabuf->list);
13072 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
13073 dmabuf->virt, dmabuf->phys);
13074 kfree(dmabuf);
13075 }
James Smartce396282012-09-29 11:30:56 -040013076 release_firmware(fw);
13077out:
James Smart0a5ce732019-10-18 14:18:18 -070013078 if (rc < 0)
Dick Kennedy372c1872020-06-30 14:50:00 -070013079 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070013080 "3062 Firmware update error, status %d.\n", rc);
13081 else
Dick Kennedy372c1872020-06-30 14:50:00 -070013082 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070013083 "3024 Firmware update success: size %d.\n", rc);
James Smart52d52442011-05-24 11:42:45 -040013084}
13085
13086/**
James Smartc71ab862012-10-31 14:44:33 -040013087 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
13088 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010013089 * @fw_upgrade: which firmware to update.
James Smartc71ab862012-10-31 14:44:33 -040013090 *
13091 * This routine is called to perform Linux generic firmware upgrade on device
13092 * that supports such feature.
13093 **/
13094int
13095lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
13096{
13097 uint8_t file_name[ELX_MODEL_NAME_SIZE];
13098 int ret;
13099 const struct firmware *fw;
13100
13101 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080013102 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040013103 LPFC_SLI_INTF_IF_TYPE_2)
13104 return -EPERM;
13105
13106 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
13107
13108 if (fw_upgrade == INT_FW_UPGRADE) {
13109 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
13110 file_name, &phba->pcidev->dev,
13111 GFP_KERNEL, (void *)phba,
13112 lpfc_write_firmware);
13113 } else if (fw_upgrade == RUN_FW_UPGRADE) {
13114 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
13115 if (!ret)
13116 lpfc_write_firmware(fw, (void *)phba);
13117 } else {
13118 ret = -EINVAL;
13119 }
13120
13121 return ret;
13122}
13123
13124/**
James Smartda0436e2009-05-22 14:51:39 -040013125 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
13126 * @pdev: pointer to PCI device
13127 * @pid: pointer to PCI device identifier
13128 *
13129 * This routine is called from the kernel's PCI subsystem to device with
13130 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13131 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13132 * information of the device and driver to see if the driver state that it
13133 * can support this kind of device. If the match is successful, the driver
13134 * core invokes this routine. If this routine determines it can claim the HBA,
13135 * it does all the initialization that it needs to do to handle the HBA
13136 * properly.
13137 *
13138 * Return code
13139 * 0 - driver can claim the device
13140 * negative value - driver can not claim the device
13141 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013142static int
James Smartda0436e2009-05-22 14:51:39 -040013143lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
13144{
13145 struct lpfc_hba *phba;
13146 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040013147 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070013148 int error;
James Smartda0436e2009-05-22 14:51:39 -040013149 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040013150
13151 /* Allocate memory for HBA structure */
13152 phba = lpfc_hba_alloc(pdev);
13153 if (!phba)
13154 return -ENOMEM;
13155
13156 /* Perform generic PCI device enabling operation */
13157 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040013158 if (error)
James Smartda0436e2009-05-22 14:51:39 -040013159 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040013160
13161 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
13162 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
13163 if (error)
13164 goto out_disable_pci_dev;
13165
13166 /* Set up SLI-4 specific device PCI memory space */
13167 error = lpfc_sli4_pci_mem_setup(phba);
13168 if (error) {
13169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13170 "1410 Failed to set up pci memory space.\n");
13171 goto out_disable_pci_dev;
13172 }
13173
James Smartda0436e2009-05-22 14:51:39 -040013174 /* Set up SLI-4 Specific device driver resources */
13175 error = lpfc_sli4_driver_resource_setup(phba);
13176 if (error) {
13177 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13178 "1412 Failed to set up driver resource.\n");
13179 goto out_unset_pci_mem_s4;
13180 }
13181
James Smart19ca7602010-11-20 23:11:55 -050013182 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040013183 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050013184
James Smartda0436e2009-05-22 14:51:39 -040013185 /* Set up common device driver resources */
13186 error = lpfc_setup_driver_resource_phase2(phba);
13187 if (error) {
13188 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13189 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070013190 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040013191 }
13192
James Smart079b5c92011-08-21 21:48:49 -040013193 /* Get the default values for Model Name and Description */
13194 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13195
James Smartda0436e2009-05-22 14:51:39 -040013196 /* Now, trying to enable interrupt and bring up the device */
13197 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040013198
James Smart7b15db32013-01-03 15:43:29 -050013199 /* Put device to a known state before enabling interrupt */
James Smartcdb42be2019-01-28 11:14:21 -080013200 phba->pport = NULL;
James Smart7b15db32013-01-03 15:43:29 -050013201 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080013202
James Smartdcaa2132019-11-04 16:57:06 -080013203 /* Init cpu_map array */
13204 lpfc_cpu_map_array_init(phba);
13205
13206 /* Init hba_eq_hdl array */
13207 lpfc_hba_eq_hdl_array_init(phba);
13208
James Smart7b15db32013-01-03 15:43:29 -050013209 /* Configure and enable interrupt */
13210 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
13211 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013212 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7b15db32013-01-03 15:43:29 -050013213 "0426 Failed to enable interrupt.\n");
13214 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080013215 goto out_unset_driver_resource;
James Smartda0436e2009-05-22 14:51:39 -040013216 }
James Smart7b15db32013-01-03 15:43:29 -050013217 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080013218 if (phba->intr_type != MSIX) {
James Smart6a828b02019-01-28 11:14:31 -080013219 phba->cfg_irq_chann = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080013220 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -080013221 if (phba->nvmet_support)
13222 phba->cfg_nvmet_mrq = 1;
13223 }
James Smartcdb42be2019-01-28 11:14:21 -080013224 }
James Smart6a828b02019-01-28 11:14:31 -080013225 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
James Smartcdb42be2019-01-28 11:14:21 -080013226
13227 /* Create SCSI host to the physical port */
13228 error = lpfc_create_shost(phba);
13229 if (error) {
13230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13231 "1415 Failed to create scsi host.\n");
13232 goto out_disable_intr;
13233 }
13234 vport = phba->pport;
13235 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
13236
13237 /* Configure sysfs attributes */
13238 error = lpfc_alloc_sysfs_attr(vport);
13239 if (error) {
13240 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13241 "1416 Failed to allocate sysfs attr\n");
13242 goto out_destroy_shost;
James Smart895427b2017-02-12 13:52:30 -080013243 }
13244
James Smart7b15db32013-01-03 15:43:29 -050013245 /* Set up SLI-4 HBA */
13246 if (lpfc_sli4_hba_setup(phba)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013247 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7b15db32013-01-03 15:43:29 -050013248 "1421 Failed to set up hba\n");
13249 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080013250 goto out_free_sysfs_attr;
James Smart7b15db32013-01-03 15:43:29 -050013251 }
13252
13253 /* Log the current active interrupt mode */
13254 phba->intr_mode = intr_mode;
13255 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040013256
13257 /* Perform post initialization setup */
13258 lpfc_post_init_setup(phba);
13259
James Smart01649562017-02-12 13:52:32 -080013260 /* NVME support in FW earlier in the driver load corrects the
13261 * FC4 type making a check for nvme_support unnecessary.
13262 */
James Smart0794d602019-01-28 11:14:19 -080013263 if (phba->nvmet_support == 0) {
13264 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13265 /* Create NVME binding with nvme_fc_transport. This
13266 * ensures the vport is initialized. If the localport
13267 * create fails, it should not unload the driver to
13268 * support field issues.
13269 */
13270 error = lpfc_nvme_create_localport(vport);
13271 if (error) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013272 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -080013273 "6004 NVME registration "
13274 "failed, error x%x\n",
13275 error);
13276 }
James Smart01649562017-02-12 13:52:32 -080013277 }
13278 }
James Smart895427b2017-02-12 13:52:30 -080013279
James Smartc71ab862012-10-31 14:44:33 -040013280 /* check for firmware upgrade or downgrade */
13281 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040013282 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040013283
James Smart1c6834a2009-07-19 10:01:26 -040013284 /* Check if there are static vports to be created. */
13285 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070013286
13287 /* Enable RAS FW log support */
13288 lpfc_sli4_ras_setup(phba);
13289
James Smart93a4d6f2019-11-04 16:57:05 -080013290 INIT_LIST_HEAD(&phba->poll_list);
James Smartf861f592020-03-22 11:12:54 -070013291 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
James Smart93a4d6f2019-11-04 16:57:05 -080013292 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
13293
James Smartda0436e2009-05-22 14:51:39 -040013294 return 0;
13295
James Smartda0436e2009-05-22 14:51:39 -040013296out_free_sysfs_attr:
13297 lpfc_free_sysfs_attr(vport);
13298out_destroy_shost:
13299 lpfc_destroy_shost(phba);
James Smartcdb42be2019-01-28 11:14:21 -080013300out_disable_intr:
13301 lpfc_sli4_disable_intr(phba);
James Smartda0436e2009-05-22 14:51:39 -040013302out_unset_driver_resource:
13303 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040013304out_unset_driver_resource_s4:
13305 lpfc_sli4_driver_resource_unset(phba);
13306out_unset_pci_mem_s4:
13307 lpfc_sli4_pci_mem_unset(phba);
13308out_disable_pci_dev:
13309 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040013310 if (shost)
13311 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040013312out_free_phba:
13313 lpfc_hba_free(phba);
13314 return error;
13315}
13316
13317/**
13318 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
13319 * @pdev: pointer to PCI device
13320 *
13321 * This routine is called from the kernel's PCI subsystem to device with
13322 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
13323 * removed from PCI bus, it performs all the necessary cleanup for the HBA
13324 * device to be removed from the PCI subsystem properly.
13325 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013326static void
James Smartda0436e2009-05-22 14:51:39 -040013327lpfc_pci_remove_one_s4(struct pci_dev *pdev)
13328{
13329 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13330 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
13331 struct lpfc_vport **vports;
13332 struct lpfc_hba *phba = vport->phba;
13333 int i;
13334
13335 /* Mark the device unloading flag */
13336 spin_lock_irq(&phba->hbalock);
13337 vport->load_flag |= FC_UNLOADING;
13338 spin_unlock_irq(&phba->hbalock);
13339
James Smartda0436e2009-05-22 14:51:39 -040013340 lpfc_free_sysfs_attr(vport);
13341
13342 /* Release all the vports against this physical port */
13343 vports = lpfc_create_vport_work_array(phba);
13344 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040013345 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
13346 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
13347 continue;
James Smartda0436e2009-05-22 14:51:39 -040013348 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040013349 }
James Smartda0436e2009-05-22 14:51:39 -040013350 lpfc_destroy_vport_work_array(phba, vports);
13351
James Smart95f0ef82020-11-15 11:26:32 -080013352 /* Remove FC host with the physical port */
James Smartda0436e2009-05-22 14:51:39 -040013353 fc_remove_host(shost);
James Smarte9b11082020-11-15 11:26:33 -080013354 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040013355
James Smartda0436e2009-05-22 14:51:39 -040013356 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
13357 * localports are destroyed after to cleanup all transport memory.
13358 */
13359 lpfc_cleanup(vport);
13360 lpfc_nvmet_destroy_targetport(phba);
13361 lpfc_nvme_destroy_localport(vport);
13362
James Smartc4908502019-01-28 11:14:28 -080013363 /* De-allocate multi-XRI pools */
13364 if (phba->cfg_xri_rebalancing)
13365 lpfc_destroy_multixri_pools(phba);
13366
James Smart281d6192018-01-30 15:58:47 -080013367 /*
13368 * Bring down the SLI Layer. This step disables all interrupts,
13369 * clears the rings, discards all mailbox commands, and resets
13370 * the HBA FCoE function.
13371 */
13372 lpfc_debugfs_terminate(vport);
James Smartda0436e2009-05-22 14:51:39 -040013373
Dick Kennedy19017622017-09-29 17:34:27 -070013374 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070013375 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040013376 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070013377 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040013378
James Smart3677a3a2010-09-29 11:19:14 -040013379 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040013380 * buffers are released to their corresponding pools here.
13381 */
James Smart5e5b5112019-01-28 11:14:22 -080013382 lpfc_io_free(phba);
James Smart01649562017-02-12 13:52:32 -080013383 lpfc_free_iocb_list(phba);
James Smart5e5b5112019-01-28 11:14:22 -080013384 lpfc_sli4_hba_unset(phba);
James Smart67d12732012-08-03 12:36:13 -040013385
James Smart0cdb84e2018-04-09 14:24:26 -070013386 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040013387 lpfc_sli4_driver_resource_unset(phba);
13388
13389 /* Unmap adapter Control and Doorbell registers */
13390 lpfc_sli4_pci_mem_unset(phba);
13391
13392 /* Release PCI resources and disable device's PCI function */
13393 scsi_host_put(shost);
13394 lpfc_disable_pci_dev(phba);
13395
13396 /* Finally, free the driver's device data structure */
13397 lpfc_hba_free(phba);
13398
13399 return;
13400}
13401
13402/**
13403 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013404 * @dev_d: pointer to device
James Smartda0436e2009-05-22 14:51:39 -040013405 *
13406 * This routine is called from the kernel's PCI subsystem to support system
13407 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
13408 * this method, it quiesces the device by stopping the driver's worker
13409 * thread for the device, turning off device's interrupt and DMA, and bring
13410 * the device offline. Note that as the driver implements the minimum PM
13411 * requirements to a power-aware driver's PM support for suspend/resume -- all
13412 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
13413 * method call will be treated as SUSPEND and the driver will fully
13414 * reinitialize its device during resume() method call, the driver will set
13415 * device to PCI_D3hot state in PCI config space instead of setting it
13416 * according to the @msg provided by the PM.
13417 *
13418 * Return code
13419 * 0 - driver suspended the device
13420 * Error otherwise
13421 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013422static int __maybe_unused
13423lpfc_pci_suspend_one_s4(struct device *dev_d)
James Smartda0436e2009-05-22 14:51:39 -040013424{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013425 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smartda0436e2009-05-22 14:51:39 -040013426 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13427
13428 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040013429 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040013430
13431 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040013432 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040013433 lpfc_offline(phba);
13434 kthread_stop(phba->worker_thread);
13435
13436 /* Disable interrupt from device */
13437 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040013438 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040013439
James Smartda0436e2009-05-22 14:51:39 -040013440 return 0;
13441}
13442
13443/**
13444 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013445 * @dev_d: pointer to device
James Smartda0436e2009-05-22 14:51:39 -040013446 *
13447 * This routine is called from the kernel's PCI subsystem to support system
13448 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
13449 * this method, it restores the device's PCI config space state and fully
13450 * reinitializes the device and brings it online. Note that as the driver
13451 * implements the minimum PM requirements to a power-aware driver's PM for
13452 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
13453 * to the suspend() method call will be treated as SUSPEND and the driver
13454 * will fully reinitialize its device during resume() method call, the device
13455 * will be set to PCI_D0 directly in PCI config space before restoring the
13456 * state.
13457 *
13458 * Return code
13459 * 0 - driver suspended the device
13460 * Error otherwise
13461 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013462static int __maybe_unused
13463lpfc_pci_resume_one_s4(struct device *dev_d)
James Smartda0436e2009-05-22 14:51:39 -040013464{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013465 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smartda0436e2009-05-22 14:51:39 -040013466 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13467 uint32_t intr_mode;
13468 int error;
13469
13470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13471 "0292 PCI device Power Management resume.\n");
13472
James Smartda0436e2009-05-22 14:51:39 -040013473 /* Startup the kernel thread for this host adapter. */
13474 phba->worker_thread = kthread_run(lpfc_do_work, phba,
13475 "lpfc_worker_%d", phba->brd_no);
13476 if (IS_ERR(phba->worker_thread)) {
13477 error = PTR_ERR(phba->worker_thread);
13478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13479 "0293 PM resume failed to start worker "
13480 "thread: error=x%x.\n", error);
13481 return error;
13482 }
13483
13484 /* Configure and enable interrupt */
13485 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13486 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013487 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040013488 "0294 PM resume Failed to enable interrupt\n");
13489 return -EIO;
13490 } else
13491 phba->intr_mode = intr_mode;
13492
13493 /* Restart HBA and bring it online */
13494 lpfc_sli_brdrestart(phba);
13495 lpfc_online(phba);
13496
13497 /* Log the current active interrupt mode */
13498 lpfc_log_intr_mode(phba, phba->intr_mode);
13499
13500 return 0;
13501}
13502
13503/**
James Smart75baf692010-06-08 18:31:21 -040013504 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
13505 * @phba: pointer to lpfc hba data structure.
13506 *
13507 * This routine is called to prepare the SLI4 device for PCI slot recover. It
13508 * aborts all the outstanding SCSI I/Os to the pci device.
13509 **/
13510static void
13511lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
13512{
Dick Kennedy372c1872020-06-30 14:50:00 -070013513 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040013514 "2828 PCI channel I/O abort preparing for recovery\n");
13515 /*
13516 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
13517 * and let the SCSI mid-layer to retry them to recover.
13518 */
James Smartdb55fba2014-04-04 13:52:02 -040013519 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040013520}
13521
13522/**
13523 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
13524 * @phba: pointer to lpfc hba data structure.
13525 *
13526 * This routine is called to prepare the SLI4 device for PCI slot reset. It
13527 * disables the device interrupt and pci device, and aborts the internal FCP
13528 * pending I/Os.
13529 **/
13530static void
13531lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
13532{
Dick Kennedy372c1872020-06-30 14:50:00 -070013533 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040013534 "2826 PCI channel disable preparing for reset\n");
13535
13536 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040013537 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040013538
13539 /* Block all SCSI devices' I/Os on the host */
13540 lpfc_scsi_dev_block(phba);
13541
James Smartc00f62e2019-08-14 16:57:11 -070013542 /* Flush all driver's outstanding I/Os as we are to reset */
13543 lpfc_sli_flush_io_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080013544
James Smart75baf692010-06-08 18:31:21 -040013545 /* stop all timers */
13546 lpfc_stop_hba_timers(phba);
13547
13548 /* Disable interrupt and pci device */
13549 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040013550 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040013551 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040013552}
13553
13554/**
13555 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
13556 * @phba: pointer to lpfc hba data structure.
13557 *
13558 * This routine is called to prepare the SLI4 device for PCI slot permanently
13559 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
13560 * pending I/Os.
13561 **/
13562static void
13563lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
13564{
Dick Kennedy372c1872020-06-30 14:50:00 -070013565 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040013566 "2827 PCI channel permanent disable for failure\n");
13567
13568 /* Block all SCSI devices' I/Os on the host */
13569 lpfc_scsi_dev_block(phba);
13570
13571 /* stop all timers */
13572 lpfc_stop_hba_timers(phba);
13573
James Smartc00f62e2019-08-14 16:57:11 -070013574 /* Clean up all driver's outstanding I/Os */
13575 lpfc_sli_flush_io_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040013576}
13577
13578/**
James Smartda0436e2009-05-22 14:51:39 -040013579 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
13580 * @pdev: pointer to PCI device.
13581 * @state: the current PCI connection state.
13582 *
13583 * This routine is called from the PCI subsystem for error handling to device
13584 * with SLI-4 interface spec. This function is called by the PCI subsystem
13585 * after a PCI bus error affecting this device has been detected. When this
13586 * function is invoked, it will need to stop all the I/Os and interrupt(s)
13587 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
13588 * for the PCI subsystem to perform proper recovery as desired.
13589 *
13590 * Return codes
13591 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13592 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13593 **/
13594static pci_ers_result_t
13595lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
13596{
James Smart75baf692010-06-08 18:31:21 -040013597 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13598 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13599
13600 switch (state) {
13601 case pci_channel_io_normal:
13602 /* Non-fatal error, prepare for recovery */
13603 lpfc_sli4_prep_dev_for_recover(phba);
13604 return PCI_ERS_RESULT_CAN_RECOVER;
13605 case pci_channel_io_frozen:
13606 /* Fatal error, prepare for slot reset */
13607 lpfc_sli4_prep_dev_for_reset(phba);
13608 return PCI_ERS_RESULT_NEED_RESET;
13609 case pci_channel_io_perm_failure:
13610 /* Permanent failure, prepare for device down */
13611 lpfc_sli4_prep_dev_for_perm_failure(phba);
13612 return PCI_ERS_RESULT_DISCONNECT;
13613 default:
13614 /* Unknown state, prepare and request slot reset */
Dick Kennedy372c1872020-06-30 14:50:00 -070013615 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040013616 "2825 Unknown PCI error state: x%x\n", state);
13617 lpfc_sli4_prep_dev_for_reset(phba);
13618 return PCI_ERS_RESULT_NEED_RESET;
13619 }
James Smartda0436e2009-05-22 14:51:39 -040013620}
13621
13622/**
13623 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
13624 * @pdev: pointer to PCI device.
13625 *
13626 * This routine is called from the PCI subsystem for error handling to device
13627 * with SLI-4 interface spec. It is called after PCI bus has been reset to
13628 * restart the PCI card from scratch, as if from a cold-boot. During the
13629 * PCI subsystem error recovery, after the driver returns
13630 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13631 * recovery and then call this routine before calling the .resume method to
13632 * recover the device. This function will initialize the HBA device, enable
13633 * the interrupt, but it will just put the HBA to offline state without
13634 * passing any I/O traffic.
13635 *
13636 * Return codes
13637 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13638 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13639 */
13640static pci_ers_result_t
13641lpfc_io_slot_reset_s4(struct pci_dev *pdev)
13642{
James Smart75baf692010-06-08 18:31:21 -040013643 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13644 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13645 struct lpfc_sli *psli = &phba->sli;
13646 uint32_t intr_mode;
13647
13648 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
13649 if (pci_enable_device_mem(pdev)) {
13650 printk(KERN_ERR "lpfc: Cannot re-enable "
13651 "PCI device after reset.\n");
13652 return PCI_ERS_RESULT_DISCONNECT;
13653 }
13654
13655 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040013656
13657 /*
13658 * As the new kernel behavior of pci_restore_state() API call clears
13659 * device saved_state flag, need to save the restored state again.
13660 */
13661 pci_save_state(pdev);
13662
James Smart75baf692010-06-08 18:31:21 -040013663 if (pdev->is_busmaster)
13664 pci_set_master(pdev);
13665
13666 spin_lock_irq(&phba->hbalock);
13667 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
13668 spin_unlock_irq(&phba->hbalock);
13669
13670 /* Configure and enable interrupt */
13671 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13672 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013673 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040013674 "2824 Cannot re-enable interrupt after "
13675 "slot reset.\n");
13676 return PCI_ERS_RESULT_DISCONNECT;
13677 } else
13678 phba->intr_mode = intr_mode;
13679
13680 /* Log the current active interrupt mode */
13681 lpfc_log_intr_mode(phba, phba->intr_mode);
13682
James Smartda0436e2009-05-22 14:51:39 -040013683 return PCI_ERS_RESULT_RECOVERED;
13684}
13685
13686/**
13687 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
13688 * @pdev: pointer to PCI device
13689 *
13690 * This routine is called from the PCI subsystem for error handling to device
13691 * with SLI-4 interface spec. It is called when kernel error recovery tells
13692 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13693 * error recovery. After this call, traffic can start to flow from this device
13694 * again.
13695 **/
13696static void
13697lpfc_io_resume_s4(struct pci_dev *pdev)
13698{
James Smart75baf692010-06-08 18:31:21 -040013699 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13700 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13701
13702 /*
13703 * In case of slot reset, as function reset is performed through
13704 * mailbox command which needs DMA to be enabled, this operation
13705 * has to be moved to the io resume phase. Taking device offline
13706 * will perform the necessary cleanup.
13707 */
13708 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
13709 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040013710 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040013711 lpfc_offline(phba);
13712 lpfc_sli_brdrestart(phba);
13713 /* Bring the device back online */
13714 lpfc_online(phba);
13715 }
James Smartda0436e2009-05-22 14:51:39 -040013716}
13717
13718/**
James Smart3772a992009-05-22 14:50:54 -040013719 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
13720 * @pdev: pointer to PCI device
13721 * @pid: pointer to PCI device identifier
13722 *
13723 * This routine is to be registered to the kernel's PCI subsystem. When an
13724 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
13725 * at PCI device-specific information of the device and driver to see if the
13726 * driver state that it can support this kind of device. If the match is
13727 * successful, the driver core invokes this routine. This routine dispatches
13728 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
13729 * do all the initialization that it needs to do to handle the HBA device
13730 * properly.
13731 *
13732 * Return code
13733 * 0 - driver can claim the device
13734 * negative value - driver can not claim the device
13735 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013736static int
James Smart3772a992009-05-22 14:50:54 -040013737lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
13738{
13739 int rc;
James Smart8fa38512009-07-19 10:01:03 -040013740 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040013741
James Smart28baac72010-02-12 14:42:03 -050013742 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040013743 return -ENODEV;
13744
James Smart8fa38512009-07-19 10:01:03 -040013745 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050013746 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040013747 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013748 else
James Smart3772a992009-05-22 14:50:54 -040013749 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013750
James Smart3772a992009-05-22 14:50:54 -040013751 return rc;
13752}
13753
13754/**
13755 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
13756 * @pdev: pointer to PCI device
13757 *
13758 * This routine is to be registered to the kernel's PCI subsystem. When an
13759 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
13760 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
13761 * remove routine, which will perform all the necessary cleanup for the
13762 * device to be removed from the PCI subsystem properly.
13763 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013764static void
James Smart3772a992009-05-22 14:50:54 -040013765lpfc_pci_remove_one(struct pci_dev *pdev)
13766{
13767 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13768 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13769
13770 switch (phba->pci_dev_grp) {
13771 case LPFC_PCI_DEV_LP:
13772 lpfc_pci_remove_one_s3(pdev);
13773 break;
James Smartda0436e2009-05-22 14:51:39 -040013774 case LPFC_PCI_DEV_OC:
13775 lpfc_pci_remove_one_s4(pdev);
13776 break;
James Smart3772a992009-05-22 14:50:54 -040013777 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013778 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013779 "1424 Invalid PCI device group: 0x%x\n",
13780 phba->pci_dev_grp);
13781 break;
13782 }
13783 return;
13784}
13785
13786/**
13787 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013788 * @dev: pointer to device
James Smart3772a992009-05-22 14:50:54 -040013789 *
13790 * This routine is to be registered to the kernel's PCI subsystem to support
13791 * system Power Management (PM). When PM invokes this method, it dispatches
13792 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
13793 * suspend the device.
13794 *
13795 * Return code
13796 * 0 - driver suspended the device
13797 * Error otherwise
13798 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013799static int __maybe_unused
13800lpfc_pci_suspend_one(struct device *dev)
James Smart3772a992009-05-22 14:50:54 -040013801{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013802 struct Scsi_Host *shost = dev_get_drvdata(dev);
James Smart3772a992009-05-22 14:50:54 -040013803 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13804 int rc = -ENODEV;
13805
13806 switch (phba->pci_dev_grp) {
13807 case LPFC_PCI_DEV_LP:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013808 rc = lpfc_pci_suspend_one_s3(dev);
James Smart3772a992009-05-22 14:50:54 -040013809 break;
James Smartda0436e2009-05-22 14:51:39 -040013810 case LPFC_PCI_DEV_OC:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013811 rc = lpfc_pci_suspend_one_s4(dev);
James Smartda0436e2009-05-22 14:51:39 -040013812 break;
James Smart3772a992009-05-22 14:50:54 -040013813 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013814 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013815 "1425 Invalid PCI device group: 0x%x\n",
13816 phba->pci_dev_grp);
13817 break;
13818 }
13819 return rc;
13820}
13821
13822/**
13823 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013824 * @dev: pointer to device
James Smart3772a992009-05-22 14:50:54 -040013825 *
13826 * This routine is to be registered to the kernel's PCI subsystem to support
13827 * system Power Management (PM). When PM invokes this method, it dispatches
13828 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
13829 * resume the device.
13830 *
13831 * Return code
13832 * 0 - driver suspended the device
13833 * Error otherwise
13834 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013835static int __maybe_unused
13836lpfc_pci_resume_one(struct device *dev)
James Smart3772a992009-05-22 14:50:54 -040013837{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013838 struct Scsi_Host *shost = dev_get_drvdata(dev);
James Smart3772a992009-05-22 14:50:54 -040013839 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13840 int rc = -ENODEV;
13841
13842 switch (phba->pci_dev_grp) {
13843 case LPFC_PCI_DEV_LP:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013844 rc = lpfc_pci_resume_one_s3(dev);
James Smart3772a992009-05-22 14:50:54 -040013845 break;
James Smartda0436e2009-05-22 14:51:39 -040013846 case LPFC_PCI_DEV_OC:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053013847 rc = lpfc_pci_resume_one_s4(dev);
James Smartda0436e2009-05-22 14:51:39 -040013848 break;
James Smart3772a992009-05-22 14:50:54 -040013849 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013850 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013851 "1426 Invalid PCI device group: 0x%x\n",
13852 phba->pci_dev_grp);
13853 break;
13854 }
13855 return rc;
13856}
13857
13858/**
13859 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
13860 * @pdev: pointer to PCI device.
13861 * @state: the current PCI connection state.
13862 *
13863 * This routine is registered to the PCI subsystem for error handling. This
13864 * function is called by the PCI subsystem after a PCI bus error affecting
13865 * this device has been detected. When this routine is invoked, it dispatches
13866 * the action to the proper SLI-3 or SLI-4 device error detected handling
13867 * routine, which will perform the proper error detected operation.
13868 *
13869 * Return codes
13870 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13871 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13872 **/
13873static pci_ers_result_t
13874lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
13875{
13876 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13877 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13878 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13879
13880 switch (phba->pci_dev_grp) {
13881 case LPFC_PCI_DEV_LP:
13882 rc = lpfc_io_error_detected_s3(pdev, state);
13883 break;
James Smartda0436e2009-05-22 14:51:39 -040013884 case LPFC_PCI_DEV_OC:
13885 rc = lpfc_io_error_detected_s4(pdev, state);
13886 break;
James Smart3772a992009-05-22 14:50:54 -040013887 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013888 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013889 "1427 Invalid PCI device group: 0x%x\n",
13890 phba->pci_dev_grp);
13891 break;
13892 }
13893 return rc;
13894}
13895
13896/**
13897 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
13898 * @pdev: pointer to PCI device.
13899 *
13900 * This routine is registered to the PCI subsystem for error handling. This
13901 * function is called after PCI bus has been reset to restart the PCI card
13902 * from scratch, as if from a cold-boot. When this routine is invoked, it
13903 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
13904 * routine, which will perform the proper device reset.
13905 *
13906 * Return codes
13907 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13908 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13909 **/
13910static pci_ers_result_t
13911lpfc_io_slot_reset(struct pci_dev *pdev)
13912{
13913 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13914 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13915 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13916
13917 switch (phba->pci_dev_grp) {
13918 case LPFC_PCI_DEV_LP:
13919 rc = lpfc_io_slot_reset_s3(pdev);
13920 break;
James Smartda0436e2009-05-22 14:51:39 -040013921 case LPFC_PCI_DEV_OC:
13922 rc = lpfc_io_slot_reset_s4(pdev);
13923 break;
James Smart3772a992009-05-22 14:50:54 -040013924 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013925 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013926 "1428 Invalid PCI device group: 0x%x\n",
13927 phba->pci_dev_grp);
13928 break;
13929 }
13930 return rc;
13931}
13932
13933/**
13934 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
13935 * @pdev: pointer to PCI device
13936 *
13937 * This routine is registered to the PCI subsystem for error handling. It
13938 * is called when kernel error recovery tells the lpfc driver that it is
13939 * OK to resume normal PCI operation after PCI bus error recovery. When
13940 * this routine is invoked, it dispatches the action to the proper SLI-3
13941 * or SLI-4 device io_resume routine, which will resume the device operation.
13942 **/
13943static void
13944lpfc_io_resume(struct pci_dev *pdev)
13945{
13946 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13947 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13948
13949 switch (phba->pci_dev_grp) {
13950 case LPFC_PCI_DEV_LP:
13951 lpfc_io_resume_s3(pdev);
13952 break;
James Smartda0436e2009-05-22 14:51:39 -040013953 case LPFC_PCI_DEV_OC:
13954 lpfc_io_resume_s4(pdev);
13955 break;
James Smart3772a992009-05-22 14:50:54 -040013956 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070013957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013958 "1429 Invalid PCI device group: 0x%x\n",
13959 phba->pci_dev_grp);
13960 break;
13961 }
13962 return;
13963}
13964
James Smart1ba981f2014-02-20 09:56:45 -050013965/**
13966 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
13967 * @phba: pointer to lpfc hba data structure.
13968 *
13969 * This routine checks to see if OAS is supported for this adapter. If
13970 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
13971 * the enable oas flag is cleared and the pool created for OAS device data
13972 * is destroyed.
13973 *
13974 **/
YueHaibingc7092972019-04-17 23:05:54 +080013975static void
James Smart1ba981f2014-02-20 09:56:45 -050013976lpfc_sli4_oas_verify(struct lpfc_hba *phba)
13977{
13978
13979 if (!phba->cfg_EnableXLane)
13980 return;
13981
13982 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
13983 phba->cfg_fof = 1;
13984 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040013985 phba->cfg_fof = 0;
Saurav Girepunjec3e5aac2019-10-27 01:17:17 +053013986 mempool_destroy(phba->device_data_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -050013987 phba->device_data_mem_pool = NULL;
13988 }
13989
13990 return;
13991}
13992
13993/**
James Smartd2cc9bc2018-09-10 10:30:50 -070013994 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
13995 * @phba: pointer to lpfc hba data structure.
13996 *
13997 * This routine checks to see if RAS is supported by the adapter. Check the
13998 * function through which RAS support enablement is to be done.
13999 **/
14000void
14001lpfc_sli4_ras_init(struct lpfc_hba *phba)
14002{
14003 switch (phba->pcidev->device) {
14004 case PCI_DEVICE_ID_LANCER_G6_FC:
14005 case PCI_DEVICE_ID_LANCER_G7_FC:
14006 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080014007 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
14008 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070014009 phba->ras_fwlog.ras_enabled = true;
14010 else
14011 phba->ras_fwlog.ras_enabled = false;
14012 break;
14013 default:
14014 phba->ras_fwlog.ras_hwsupport = false;
14015 }
14016}
14017
James Smart1ba981f2014-02-20 09:56:45 -050014018
dea31012005-04-17 16:05:31 -050014019MODULE_DEVICE_TABLE(pci, lpfc_id_table);
14020
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070014021static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060014022 .error_detected = lpfc_io_error_detected,
14023 .slot_reset = lpfc_io_slot_reset,
14024 .resume = lpfc_io_resume,
14025};
14026
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014027static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
14028 lpfc_pci_suspend_one,
14029 lpfc_pci_resume_one);
14030
dea31012005-04-17 16:05:31 -050014031static struct pci_driver lpfc_driver = {
14032 .name = LPFC_DRIVER_NAME,
14033 .id_table = lpfc_id_table,
14034 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080014035 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110014036 .shutdown = lpfc_pci_remove_one,
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014037 .driver.pm = &lpfc_pci_pm_ops_one,
James Smart2e0fef82007-06-17 19:56:36 -050014038 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050014039};
14040
James Smart3ef6d242012-01-18 16:23:48 -050014041static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040014042 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050014043};
14044
14045static struct miscdevice lpfc_mgmt_dev = {
14046 .minor = MISC_DYNAMIC_MINOR,
14047 .name = "lpfcmgmt",
14048 .fops = &lpfc_mgmt_fop,
14049};
14050
James Smarte59058c2008-08-24 21:49:00 -040014051/**
James Smart3621a712009-04-06 18:47:14 -040014052 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040014053 *
14054 * This routine is to be invoked when the lpfc module is loaded into the
14055 * kernel. The special kernel macro module_init() is used to indicate the
14056 * role of this routine to the kernel as lpfc module entry point.
14057 *
14058 * Return codes
14059 * 0 - successful
14060 * -ENOMEM - FC attach transport failed
14061 * all others - failed
14062 */
dea31012005-04-17 16:05:31 -050014063static int __init
14064lpfc_init(void)
14065{
14066 int error = 0;
14067
Anton Blanchardbc2736e2020-07-13 18:39:08 +100014068 pr_info(LPFC_MODULE_DESC "\n");
14069 pr_info(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050014070
James Smart3ef6d242012-01-18 16:23:48 -050014071 error = misc_register(&lpfc_mgmt_dev);
14072 if (error)
14073 printk(KERN_ERR "Could not register lpfcmgmt device, "
14074 "misc_register returned with status %d", error);
14075
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080014076 error = -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070014077 lpfc_transport_functions.vport_create = lpfc_vport_create;
14078 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050014079 lpfc_transport_template =
14080 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040014081 if (lpfc_transport_template == NULL)
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080014082 goto unregister;
James Smart458c0832016-07-06 12:36:07 -070014083 lpfc_vport_transport_template =
14084 fc_attach_transport(&lpfc_vport_transport_functions);
14085 if (lpfc_vport_transport_template == NULL) {
14086 fc_release_transport(lpfc_transport_template);
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080014087 goto unregister;
James Smart7ee5d432007-10-27 13:37:17 -040014088 }
James Smart840a4702020-11-15 11:26:40 -080014089 lpfc_wqe_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080014090 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040014091
14092 /* Initialize in case vector mapping is needed */
James Smart2ea259e2017-02-12 13:52:27 -080014093 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040014094
James Smart93a4d6f2019-11-04 16:57:05 -080014095 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
14096 "lpfc/sli4:online",
14097 lpfc_cpu_online, lpfc_cpu_offline);
14098 if (error < 0)
14099 goto cpuhp_failure;
14100 lpfc_cpuhp_state = error;
14101
dea31012005-04-17 16:05:31 -050014102 error = pci_register_driver(&lpfc_driver);
James Smart93a4d6f2019-11-04 16:57:05 -080014103 if (error)
14104 goto unwind;
14105
14106 return error;
14107
14108unwind:
14109 cpuhp_remove_multi_state(lpfc_cpuhp_state);
14110cpuhp_failure:
14111 fc_release_transport(lpfc_transport_template);
14112 fc_release_transport(lpfc_vport_transport_template);
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080014113unregister:
14114 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050014115
14116 return error;
14117}
14118
Dick Kennedy372c1872020-06-30 14:50:00 -070014119void lpfc_dmp_dbg(struct lpfc_hba *phba)
14120{
14121 unsigned int start_idx;
14122 unsigned int dbg_cnt;
14123 unsigned int temp_idx;
14124 int i;
14125 int j = 0;
14126 unsigned long rem_nsec;
14127
14128 if (phba->cfg_log_verbose)
14129 return;
14130
14131 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
14132 return;
14133
14134 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
14135 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
14136 temp_idx = start_idx;
14137 if (dbg_cnt >= DBG_LOG_SZ) {
14138 dbg_cnt = DBG_LOG_SZ;
14139 temp_idx -= 1;
14140 } else {
14141 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
14142 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
14143 } else {
Dick Kennedy77dd7d72020-07-06 13:42:46 -070014144 if (start_idx < dbg_cnt)
Dick Kennedy372c1872020-06-30 14:50:00 -070014145 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
Dick Kennedy77dd7d72020-07-06 13:42:46 -070014146 else
Dick Kennedy372c1872020-06-30 14:50:00 -070014147 start_idx -= dbg_cnt;
Dick Kennedy372c1872020-06-30 14:50:00 -070014148 }
14149 }
14150 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
14151 start_idx, temp_idx, dbg_cnt);
14152
14153 for (i = 0; i < dbg_cnt; i++) {
14154 if ((start_idx + i) < DBG_LOG_SZ)
Dick Kennedy77dd7d72020-07-06 13:42:46 -070014155 temp_idx = (start_idx + i) % DBG_LOG_SZ;
Dick Kennedy372c1872020-06-30 14:50:00 -070014156 else
14157 temp_idx = j++;
14158 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
14159 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
14160 temp_idx,
14161 (unsigned long)phba->dbg_log[temp_idx].t_ns,
14162 rem_nsec / 1000,
14163 phba->dbg_log[temp_idx].log);
14164 }
14165 atomic_set(&phba->dbg_log_cnt, 0);
14166 atomic_set(&phba->dbg_log_dmping, 0);
14167}
14168
Lee Jones7fa03c72020-07-23 13:24:21 +010014169__printf(2, 3)
Dick Kennedy372c1872020-06-30 14:50:00 -070014170void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
14171{
14172 unsigned int idx;
14173 va_list args;
14174 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
14175 struct va_format vaf;
14176
14177
14178 va_start(args, fmt);
14179 if (unlikely(dbg_dmping)) {
14180 vaf.fmt = fmt;
14181 vaf.va = &args;
14182 dev_info(&phba->pcidev->dev, "%pV", &vaf);
14183 va_end(args);
14184 return;
14185 }
14186 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
14187 DBG_LOG_SZ;
14188
14189 atomic_inc(&phba->dbg_log_cnt);
14190
14191 vscnprintf(phba->dbg_log[idx].log,
14192 sizeof(phba->dbg_log[idx].log), fmt, args);
14193 va_end(args);
14194
14195 phba->dbg_log[idx].t_ns = local_clock();
14196}
14197
James Smarte59058c2008-08-24 21:49:00 -040014198/**
James Smart3621a712009-04-06 18:47:14 -040014199 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040014200 *
14201 * This routine is invoked when the lpfc module is removed from the kernel.
14202 * The special kernel macro module_exit() is used to indicate the role of
14203 * this routine to the kernel as lpfc module exit point.
14204 */
dea31012005-04-17 16:05:31 -050014205static void __exit
14206lpfc_exit(void)
14207{
James Smart3ef6d242012-01-18 16:23:48 -050014208 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050014209 pci_unregister_driver(&lpfc_driver);
James Smart93a4d6f2019-11-04 16:57:05 -080014210 cpuhp_remove_multi_state(lpfc_cpuhp_state);
dea31012005-04-17 16:05:31 -050014211 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070014212 fc_release_transport(lpfc_vport_transport_template);
Johannes Thumshirn79739672015-08-31 16:48:11 -040014213 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050014214}
14215
14216module_init(lpfc_init);
14217module_exit(lpfc_exit);
14218MODULE_LICENSE("GPL");
14219MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080014220MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050014221MODULE_VERSION("0:" LPFC_DRIVER_VERSION);