blob: d3a2281cb48b4397b3e7b3f7f9ff27752cc4922e [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 Smart67073c62021-03-01 09:18:21 -08004 * Copyright (C) 2017-2021 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 *);
James Smart02243832021-08-16 09:28:54 -070096static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050097
98static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050099static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -0500100static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800101#define LPFC_NVMET_BUF_POST 254
Gaurav Srivastava5e633302021-06-08 10:05:49 +0530102static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
dea31012005-04-17 16:05:31 -0500103
James Smarte59058c2008-08-24 21:49:00 -0400104/**
James Smart3621a712009-04-06 18:47:14 -0400105 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400106 * @phba: pointer to lpfc hba data structure.
107 *
108 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
109 * mailbox command. It retrieves the revision information from the HBA and
110 * collects the Vital Product Data (VPD) about the HBA for preparing the
111 * configuration of the HBA.
112 *
113 * Return codes:
114 * 0 - success.
115 * -ERESTART - requests the SLI layer to reset the HBA and try again.
116 * Any other value - indicates an error.
117 **/
dea31012005-04-17 16:05:31 -0500118int
James Smart2e0fef82007-06-17 19:56:36 -0500119lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500120{
121 lpfc_vpd_t *vp = &phba->vpd;
122 int i = 0, rc;
123 LPFC_MBOXQ_t *pmb;
124 MAILBOX_t *mb;
125 char *lpfc_vpd_data = NULL;
126 uint16_t offset = 0;
127 static char licensed[56] =
128 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400129 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500130
131 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
132 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500133 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500134 return -ENOMEM;
135 }
136
James Smart04c68492009-05-22 14:52:52 -0400137 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500138 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500139
140 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400141 if (init_key) {
142 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500143
James Smart65a29c12006-07-06 15:50:50 -0400144 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
145 *ptext = cpu_to_be32(*ptext);
146 init_key = 0;
147 }
dea31012005-04-17 16:05:31 -0500148
149 lpfc_read_nv(phba, pmb);
150 memset((char*)mb->un.varRDnvp.rsvd3, 0,
151 sizeof (mb->un.varRDnvp.rsvd3));
152 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
153 sizeof (licensed));
154
155 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
156
157 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700158 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400159 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500160 "error, mbxCmd x%x READ_NVPARM, "
161 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500162 mb->mbxCommand, mb->mbxStatus);
163 mempool_free(pmb, phba->mbox_mem_pool);
164 return -ERESTART;
165 }
166 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500167 sizeof(phba->wwnn));
168 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
169 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500170 }
171
Martin Wilckdfb75132018-11-12 09:58:37 +0100172 /*
173 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
174 * which was already set in lpfc_get_cfgparam()
175 */
176 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500177
dea31012005-04-17 16:05:31 -0500178 /* Setup and issue mailbox READ REV command */
179 lpfc_read_rev(phba, pmb);
180 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
181 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700182 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400183 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500184 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500185 mb->mbxCommand, mb->mbxStatus);
186 mempool_free( pmb, phba->mbox_mem_pool);
187 return -ERESTART;
188 }
189
James Smart92d7f7b2007-06-17 19:56:38 -0500190
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 /*
192 * The value of rr must be 1 since the driver set the cv field to 1.
193 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500194 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500195 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500196 vp->rev.rBit = 0;
Dick Kennedy372c1872020-06-30 14:50:00 -0700197 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400198 "0440 Adapter failed to init, READ_REV has "
199 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500200 mempool_free(pmb, phba->mbox_mem_pool);
201 return -ERESTART;
dea31012005-04-17 16:05:31 -0500202 }
203
James Smart495a7142008-06-14 22:52:59 -0400204 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
205 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500206 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400207 }
James Smarted957682007-06-17 19:56:37 -0500208
dea31012005-04-17 16:05:31 -0500209 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500210 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500211 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500212 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
213 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
214 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
215 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500216 vp->rev.biuRev = mb->un.varRdRev.biuRev;
217 vp->rev.smRev = mb->un.varRdRev.smRev;
218 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
219 vp->rev.endecRev = mb->un.varRdRev.endecRev;
220 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
221 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
222 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
223 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
224 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
225 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
226
James Smart92d7f7b2007-06-17 19:56:38 -0500227 /* If the sli feature level is less then 9, we must
228 * tear down all RPIs and VPIs on link down if NPIV
229 * is enabled.
230 */
231 if (vp->rev.feaLevelHigh < 9)
232 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
233
dea31012005-04-17 16:05:31 -0500234 if (lpfc_is_LC_HBA(phba->pcidev->device))
235 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
236 sizeof (phba->RandomData));
237
dea31012005-04-17 16:05:31 -0500238 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500239 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
240 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400241 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500242 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400243 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500244 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
245
246 if (rc != MBX_SUCCESS) {
247 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400248 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500249 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500250 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500251 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500252 }
James Smart04c68492009-05-22 14:52:52 -0400253 /* dump mem may return a zero when finished or we got a
254 * mailbox error, either way we are done.
255 */
256 if (mb->un.varDmp.word_cnt == 0)
257 break;
Dick Kennedyd91e3ab2020-06-30 14:49:52 -0700258
James Smarte4ec1022021-04-21 16:45:11 -0700259 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
260 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400261 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
James Smarte4ec1022021-04-21 16:45:11 -0700262 lpfc_vpd_data + offset,
263 mb->un.varDmp.word_cnt);
264 offset += mb->un.varDmp.word_cnt;
265 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
Dick Kennedyd91e3ab2020-06-30 14:49:52 -0700266
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500267 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500268
269 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500270out_free_mbox:
271 mempool_free(pmb, phba->mbox_mem_pool);
272 return 0;
273}
274
James Smarte59058c2008-08-24 21:49:00 -0400275/**
James Smart3621a712009-04-06 18:47:14 -0400276 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400277 * @phba: pointer to lpfc hba data structure.
278 * @pmboxq: pointer to the driver internal queue element for mailbox command.
279 *
280 * This is the completion handler for driver's configuring asynchronous event
281 * mailbox command to the device. If the mailbox command returns successfully,
282 * it will set internal async event support flag to 1; otherwise, it will
283 * set internal async event support flag to 0.
284 **/
James Smart57127f12007-10-27 13:37:05 -0400285static void
286lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
287{
James Smart04c68492009-05-22 14:52:52 -0400288 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400289 phba->temp_sensor_support = 1;
290 else
291 phba->temp_sensor_support = 0;
292 mempool_free(pmboxq, phba->mbox_mem_pool);
293 return;
294}
295
James Smarte59058c2008-08-24 21:49:00 -0400296/**
James Smart3621a712009-04-06 18:47:14 -0400297 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500298 * @phba: pointer to lpfc hba data structure.
299 * @pmboxq: pointer to the driver internal queue element for mailbox command.
300 *
301 * This is the completion handler for dump mailbox command for getting
302 * wake up parameters. When this command complete, the response contain
303 * Option rom version of the HBA. This function translate the version number
304 * into a human readable string and store it in OptionROMVersion.
305 **/
306static void
307lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
308{
309 struct prog_id *prg;
310 uint32_t prog_id_word;
311 char dist = ' ';
312 /* character array used for decoding dist type. */
313 char dist_char[] = "nabx";
314
James Smart04c68492009-05-22 14:52:52 -0400315 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500316 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500317 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500318 }
James Smart97207482008-12-04 22:39:19 -0500319
320 prg = (struct prog_id *) &prog_id_word;
321
322 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400323 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500324
325 /* Decode the Option rom version word to a readable string */
326 if (prg->dist < 4)
327 dist = dist_char[prg->dist];
328
329 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400330 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500331 prg->ver, prg->rev, prg->lev);
332 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400333 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500334 prg->ver, prg->rev, prg->lev,
335 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500336 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500337 return;
338}
339
340/**
James Smart05580562011-05-24 11:40:48 -0400341 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
342 * cfg_soft_wwnn, cfg_soft_wwpn
343 * @vport: pointer to lpfc vport data structure.
344 *
345 *
346 * Return codes
347 * None.
348 **/
349void
350lpfc_update_vport_wwn(struct lpfc_vport *vport)
351{
James Smartaeb3c812017-04-21 16:05:02 -0700352 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
353 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
354
James Smart05580562011-05-24 11:40:48 -0400355 /* If the soft name exists then update it using the service params */
356 if (vport->phba->cfg_soft_wwnn)
357 u64_to_wwn(vport->phba->cfg_soft_wwnn,
358 vport->fc_sparam.nodeName.u.wwn);
359 if (vport->phba->cfg_soft_wwpn)
360 u64_to_wwn(vport->phba->cfg_soft_wwpn,
361 vport->fc_sparam.portName.u.wwn);
362
363 /*
364 * If the name is empty or there exists a soft name
365 * then copy the service params name, otherwise use the fc name
366 */
367 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
368 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
369 sizeof(struct lpfc_name));
370 else
371 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
372 sizeof(struct lpfc_name));
373
James Smartaeb3c812017-04-21 16:05:02 -0700374 /*
375 * If the port name has changed, then set the Param changes flag
376 * to unreg the login
377 */
378 if (vport->fc_portname.u.wwn[0] != 0 &&
379 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name)))
381 vport->vport_flag |= FAWWPN_PARAM_CHG;
382
383 if (vport->fc_portname.u.wwn[0] == 0 ||
384 vport->phba->cfg_soft_wwpn ||
385 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
386 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400387 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
388 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700389 vport->vport_flag &= ~FAWWPN_SET;
390 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
391 vport->vport_flag |= FAWWPN_SET;
392 }
James Smart05580562011-05-24 11:40:48 -0400393 else
394 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
395 sizeof(struct lpfc_name));
396}
397
398/**
James Smart3621a712009-04-06 18:47:14 -0400399 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400400 * @phba: pointer to lpfc hba data structure.
401 *
402 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
403 * command call. It performs all internal resource and state setups on the
404 * port: post IOCB buffers, enable appropriate host interrupt attentions,
405 * ELS ring timers, etc.
406 *
407 * Return codes
408 * 0 - success.
409 * Any other value - error.
410 **/
dea31012005-04-17 16:05:31 -0500411int
James Smart2e0fef82007-06-17 19:56:36 -0500412lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500413{
James Smart2e0fef82007-06-17 19:56:36 -0500414 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500416 LPFC_MBOXQ_t *pmb;
417 MAILBOX_t *mb;
418 struct lpfc_dmabuf *mp;
419 struct lpfc_sli *psli = &phba->sli;
420 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500421 int i, j;
422 int rc;
dea31012005-04-17 16:05:31 -0500423
James Smart7af67052007-10-27 13:38:11 -0400424 spin_lock_irq(&phba->hbalock);
425 /*
426 * If the Config port completed correctly the HBA is not
427 * over heated any more.
428 */
429 if (phba->over_temp_state == HBA_OVER_TEMP)
430 phba->over_temp_state = HBA_NORMAL_TEMP;
431 spin_unlock_irq(&phba->hbalock);
432
dea31012005-04-17 16:05:31 -0500433 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
434 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500435 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500436 return -ENOMEM;
437 }
James Smart04c68492009-05-22 14:52:52 -0400438 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500439
dea31012005-04-17 16:05:31 -0500440 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500441 rc = lpfc_read_sparam(phba, pmb, 0);
442 if (rc) {
443 mempool_free(pmb, phba->mbox_mem_pool);
444 return -ENOMEM;
445 }
446
James Smarted957682007-06-17 19:56:37 -0500447 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500448 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700449 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400450 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500451 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500452 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500453 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800454 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -0500455 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
457 kfree(mp);
458 return -EIO;
459 }
460
James Smart3e1f0712018-11-29 16:09:29 -0800461 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500462
James Smart2e0fef82007-06-17 19:56:36 -0500463 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500464 lpfc_mbuf_free(phba, mp->virt, mp->phys);
465 kfree(mp);
James Smart3e1f0712018-11-29 16:09:29 -0800466 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400467 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400468
469 /* Update the fc_host data structures with new wwn. */
470 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
471 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400472 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400473
dea31012005-04-17 16:05:31 -0500474 /* If no serial number in VPD data, use low 6 bytes of WWNN */
475 /* This should be consolidated into parse_vpd ? - mr */
476 if (phba->SerialNumber[0] == 0) {
477 uint8_t *outptr;
478
James Smart2e0fef82007-06-17 19:56:36 -0500479 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500480 for (i = 0; i < 12; i++) {
481 status = *outptr++;
482 j = ((status & 0xf0) >> 4);
483 if (j <= 9)
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
486 else
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
489 i++;
490 j = (status & 0xf);
491 if (j <= 9)
492 phba->SerialNumber[i] =
493 (char)((uint8_t) 0x30 + (uint8_t) j);
494 else
495 phba->SerialNumber[i] =
496 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
497 }
498 }
499
dea31012005-04-17 16:05:31 -0500500 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500501 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500502 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700503 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400504 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500505 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500506 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500507 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500508 mempool_free( pmb, phba->mbox_mem_pool);
509 return -EIO;
510 }
511
James Smarta0c87cb2009-07-19 10:01:10 -0400512 /* Check if the port is disabled */
513 lpfc_sli_read_link_ste(phba);
514
dea31012005-04-17 16:05:31 -0500515 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartf6770e72020-01-27 16:23:09 -0800516 if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
James Smart572709e2013-07-15 18:32:43 -0400517 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
518 "3359 HBA queue depth changed from %d to %d\n",
James Smartf6770e72020-01-27 16:23:09 -0800519 phba->cfg_hba_queue_depth,
520 mb->un.varRdConfig.max_xri);
521 phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
James Smart572709e2013-07-15 18:32:43 -0400522 }
dea31012005-04-17 16:05:31 -0500523
524 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500525
526 /* Get the default values for Model Name and Description */
527 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
528
James Smart2e0fef82007-06-17 19:56:36 -0500529 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500530
James Smart0b727fe2007-10-27 13:37:25 -0400531 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800532 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
533 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
534 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
535 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500536
537 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500538 if (phba->sli_rev != 3)
539 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500540
James Smart93996272008-08-24 21:50:30 -0400541 /*
542 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
543 */
544 if (phba->intr_type == MSIX) {
545 rc = lpfc_config_msi(phba, pmb);
546 if (rc) {
547 mempool_free(pmb, phba->mbox_mem_pool);
548 return -EIO;
549 }
550 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
551 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700552 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart93996272008-08-24 21:50:30 -0400553 "0352 Config MSI mailbox command "
554 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400555 pmb->u.mb.mbxCommand,
556 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400557 mempool_free(pmb, phba->mbox_mem_pool);
558 return -EIO;
559 }
560 }
561
James Smart04c68492009-05-22 14:52:52 -0400562 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400563 /* Initialize ERATT handling flag */
564 phba->hba_flag &= ~HBA_ERATT_HANDLED;
565
dea31012005-04-17 16:05:31 -0500566 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500567 if (lpfc_readl(phba->HCregaddr, &status)) {
568 spin_unlock_irq(&phba->hbalock);
569 return -EIO;
570 }
dea31012005-04-17 16:05:31 -0500571 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
572 if (psli->num_rings > 0)
573 status |= HC_R0INT_ENA;
574 if (psli->num_rings > 1)
575 status |= HC_R1INT_ENA;
576 if (psli->num_rings > 2)
577 status |= HC_R2INT_ENA;
578 if (psli->num_rings > 3)
579 status |= HC_R3INT_ENA;
580
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500581 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
582 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400583 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500584
dea31012005-04-17 16:05:31 -0500585 writel(status, phba->HCregaddr);
586 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500587 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500588
James Smart93996272008-08-24 21:50:30 -0400589 /* Set up ring-0 (ELS) timer */
590 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400591 mod_timer(&vport->els_tmofunc,
592 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400593 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400594 mod_timer(&phba->hb_tmofunc,
595 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smarta22d73b2021-01-04 10:02:38 -0800596 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
James Smart858c9f62007-06-17 19:56:39 -0500597 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400598 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400599 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700600 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500601
James Smarta0c87cb2009-07-19 10:01:10 -0400602 if (phba->hba_flag & LINK_DISABLED) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700603 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
604 "2598 Adapter Link is disabled.\n");
James Smarta0c87cb2009-07-19 10:01:10 -0400605 lpfc_down_link(phba, pmb);
606 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
607 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
608 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700609 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
610 "2599 Adapter failed to issue DOWN_LINK"
611 " mbox command rc 0x%x\n", rc);
James Smarta0c87cb2009-07-19 10:01:10 -0400612
613 mempool_free(pmb, phba->mbox_mem_pool);
614 return -EIO;
615 }
James Smarte40a02c2010-02-26 14:13:54 -0500616 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500617 mempool_free(pmb, phba->mbox_mem_pool);
618 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
619 if (rc)
620 return rc;
dea31012005-04-17 16:05:31 -0500621 }
622 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400623 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500624 if (!pmb) {
625 phba->link_state = LPFC_HBA_ERROR;
626 return -ENOMEM;
627 }
628
James Smart57127f12007-10-27 13:37:05 -0400629 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
630 pmb->mbox_cmpl = lpfc_config_async_cmpl;
631 pmb->vport = phba->pport;
632 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500633
James Smart57127f12007-10-27 13:37:05 -0400634 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700635 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart57127f12007-10-27 13:37:05 -0400636 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400637 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400638 rc);
639 mempool_free(pmb, phba->mbox_mem_pool);
640 }
James Smart97207482008-12-04 22:39:19 -0500641
642 /* Get Option rom version */
643 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500644 if (!pmb) {
645 phba->link_state = LPFC_HBA_ERROR;
646 return -ENOMEM;
647 }
648
James Smart97207482008-12-04 22:39:19 -0500649 lpfc_dump_wakeup_param(phba, pmb);
650 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
651 pmb->vport = phba->pport;
652 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
653
654 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700655 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
656 "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400657 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500658 mempool_free(pmb, phba->mbox_mem_pool);
659 }
660
James Smartd7c255b2008-08-24 21:50:00 -0400661 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400662}
663
James Smarte59058c2008-08-24 21:49:00 -0400664/**
James Smart84d1b002010-02-12 14:42:33 -0500665 * lpfc_hba_init_link - Initialize the FC link
666 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400667 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500668 *
669 * This routine will issue the INIT_LINK mailbox command call.
670 * It is available to other drivers through the lpfc_hba data
671 * structure for use as a delayed link up mechanism with the
672 * module parameter lpfc_suppress_link_up.
673 *
674 * Return code
675 * 0 - success
676 * Any other value - error
677 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400678static int
James Smart6e7288d2010-06-07 15:23:35 -0400679lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500680{
James Smart1b511972011-12-13 13:23:09 -0500681 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
682}
683
684/**
685 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
686 * @phba: pointer to lpfc hba data structure.
687 * @fc_topology: desired fc topology.
688 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
689 *
690 * This routine will issue the INIT_LINK mailbox command call.
691 * It is available to other drivers through the lpfc_hba data
692 * structure for use as a delayed link up mechanism with the
693 * module parameter lpfc_suppress_link_up.
694 *
695 * Return code
696 * 0 - success
697 * Any other value - error
698 **/
699int
700lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
701 uint32_t flag)
702{
James Smart84d1b002010-02-12 14:42:33 -0500703 struct lpfc_vport *vport = phba->pport;
704 LPFC_MBOXQ_t *pmb;
705 MAILBOX_t *mb;
706 int rc;
707
708 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
709 if (!pmb) {
710 phba->link_state = LPFC_HBA_ERROR;
711 return -ENOMEM;
712 }
713 mb = &pmb->u.mb;
714 pmb->vport = vport;
715
James Smart026abb82011-12-13 13:20:45 -0500716 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
717 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
718 !(phba->lmt & LMT_1Gb)) ||
719 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
720 !(phba->lmt & LMT_2Gb)) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
722 !(phba->lmt & LMT_4Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
724 !(phba->lmt & LMT_8Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
726 !(phba->lmt & LMT_10Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400728 !(phba->lmt & LMT_16Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800730 !(phba->lmt & LMT_32Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
732 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500733 /* Reset link speed to auto */
Dick Kennedy372c1872020-06-30 14:50:00 -0700734 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
735 "1302 Invalid speed for this board:%d "
736 "Reset link speed to auto.\n",
737 phba->cfg_link_speed);
James Smart026abb82011-12-13 13:20:45 -0500738 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
739 }
James Smart1b511972011-12-13 13:23:09 -0500740 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500741 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500742 if (phba->sli_rev < LPFC_SLI_REV4)
743 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400744 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500745 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700746 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
747 "0498 Adapter failed to init, mbxCmd x%x "
748 "INIT_LINK, mbxStatus x%x\n",
749 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500750 if (phba->sli_rev <= LPFC_SLI_REV3) {
751 /* Clear all interrupt enable conditions */
752 writel(0, phba->HCregaddr);
753 readl(phba->HCregaddr); /* flush */
754 /* Clear all pending interrupts */
755 writel(0xffffffff, phba->HAregaddr);
756 readl(phba->HAregaddr); /* flush */
757 }
James Smart84d1b002010-02-12 14:42:33 -0500758 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400759 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500760 mempool_free(pmb, phba->mbox_mem_pool);
761 return -EIO;
762 }
James Smarte40a02c2010-02-26 14:13:54 -0500763 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400764 if (flag == MBX_POLL)
765 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500766
767 return 0;
768}
769
770/**
771 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400772 * @phba: pointer to lpfc hba data structure.
773 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500774 *
775 * This routine will issue the DOWN_LINK mailbox command call.
776 * It is available to other drivers through the lpfc_hba data
777 * structure for use to stop the link.
778 *
779 * Return code
780 * 0 - success
781 * Any other value - error
782 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400783static int
James Smart6e7288d2010-06-07 15:23:35 -0400784lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500785{
786 LPFC_MBOXQ_t *pmb;
787 int rc;
788
789 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
790 if (!pmb) {
791 phba->link_state = LPFC_HBA_ERROR;
792 return -ENOMEM;
793 }
794
Dick Kennedy372c1872020-06-30 14:50:00 -0700795 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
796 "0491 Adapter Link is disabled.\n");
James Smart84d1b002010-02-12 14:42:33 -0500797 lpfc_down_link(phba, pmb);
798 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400799 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500800 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700801 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
802 "2522 Adapter failed to issue DOWN_LINK"
803 " mbox command rc 0x%x\n", rc);
James Smart84d1b002010-02-12 14:42:33 -0500804
805 mempool_free(pmb, phba->mbox_mem_pool);
806 return -EIO;
807 }
James Smart6e7288d2010-06-07 15:23:35 -0400808 if (flag == MBX_POLL)
809 mempool_free(pmb, phba->mbox_mem_pool);
810
James Smart84d1b002010-02-12 14:42:33 -0500811 return 0;
812}
813
814/**
James Smart3621a712009-04-06 18:47:14 -0400815 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400816 * @phba: pointer to lpfc HBA data structure.
817 *
818 * This routine will do LPFC uninitialization before the HBA is reset when
819 * bringing down the SLI Layer.
820 *
821 * Return codes
822 * 0 - success.
823 * Any other value - error.
824 **/
dea31012005-04-17 16:05:31 -0500825int
James Smart2e0fef82007-06-17 19:56:36 -0500826lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500827{
James Smart1b32f6a2008-02-08 18:49:39 -0500828 struct lpfc_vport **vports;
829 int i;
James Smart3772a992009-05-22 14:50:54 -0400830
831 if (phba->sli_rev <= LPFC_SLI_REV3) {
832 /* Disable interrupts */
833 writel(0, phba->HCregaddr);
834 readl(phba->HCregaddr); /* flush */
835 }
dea31012005-04-17 16:05:31 -0500836
James Smart1b32f6a2008-02-08 18:49:39 -0500837 if (phba->pport->load_flag & FC_UNLOADING)
838 lpfc_cleanup_discovery_resources(phba->pport);
839 else {
840 vports = lpfc_create_vport_work_array(phba);
841 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400842 for (i = 0; i <= phba->max_vports &&
843 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500844 lpfc_cleanup_discovery_resources(vports[i]);
845 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500846 }
847 return 0;
dea31012005-04-17 16:05:31 -0500848}
849
James Smarte59058c2008-08-24 21:49:00 -0400850/**
James Smart68e814f2014-05-21 08:04:59 -0400851 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
852 * rspiocb which got deferred
853 *
854 * @phba: pointer to lpfc HBA data structure.
855 *
856 * This routine will cleanup completed slow path events after HBA is reset
857 * when bringing down the SLI Layer.
858 *
859 *
860 * Return codes
861 * void.
862 **/
863static void
864lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
865{
866 struct lpfc_iocbq *rspiocbq;
867 struct hbq_dmabuf *dmabuf;
868 struct lpfc_cq_event *cq_event;
869
870 spin_lock_irq(&phba->hbalock);
871 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
872 spin_unlock_irq(&phba->hbalock);
873
874 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
875 /* Get the response iocb from the head of work queue */
876 spin_lock_irq(&phba->hbalock);
877 list_remove_head(&phba->sli4_hba.sp_queue_event,
878 cq_event, struct lpfc_cq_event, list);
879 spin_unlock_irq(&phba->hbalock);
880
881 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
882 case CQE_CODE_COMPL_WQE:
883 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
884 cq_event);
885 lpfc_sli_release_iocbq(phba, rspiocbq);
886 break;
887 case CQE_CODE_RECEIVE:
888 case CQE_CODE_RECEIVE_V1:
889 dmabuf = container_of(cq_event, struct hbq_dmabuf,
890 cq_event);
891 lpfc_in_buf_free(phba, &dmabuf->dbuf);
892 }
893 }
894}
895
896/**
James Smartbcece5f2014-04-04 13:51:34 -0400897 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
898 * @phba: pointer to lpfc HBA data structure.
899 *
900 * This routine will cleanup posted ELS buffers after the HBA is reset
901 * when bringing down the SLI Layer.
902 *
903 *
904 * Return codes
905 * void.
906 **/
907static void
908lpfc_hba_free_post_buf(struct lpfc_hba *phba)
909{
910 struct lpfc_sli *psli = &phba->sli;
911 struct lpfc_sli_ring *pring;
912 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400913 LIST_HEAD(buflist);
914 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400915
916 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
917 lpfc_sli_hbqbuf_free_all(phba);
918 else {
919 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800920 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400921 spin_lock_irq(&phba->hbalock);
922 list_splice_init(&pring->postbufq, &buflist);
923 spin_unlock_irq(&phba->hbalock);
924
925 count = 0;
926 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400927 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400928 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400929 lpfc_mbuf_free(phba, mp->virt, mp->phys);
930 kfree(mp);
931 }
James Smart07eab622014-04-04 13:51:44 -0400932
933 spin_lock_irq(&phba->hbalock);
934 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400935 spin_unlock_irq(&phba->hbalock);
936 }
937}
938
939/**
940 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
941 * @phba: pointer to lpfc HBA data structure.
942 *
943 * This routine will cleanup the txcmplq after the HBA is reset when bringing
944 * down the SLI Layer.
945 *
946 * Return codes
947 * void
948 **/
949static void
950lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
951{
952 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800953 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400954 struct lpfc_sli_ring *pring;
955 LIST_HEAD(completions);
956 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800957 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400958
James Smart895427b2017-02-12 13:52:30 -0800959 if (phba->sli_rev != LPFC_SLI_REV4) {
960 for (i = 0; i < psli->num_rings; i++) {
961 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400962 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800963 /* At this point in time the HBA is either reset or DOA
964 * Nothing should be on txcmplq as it will
965 * NEVER complete.
966 */
967 list_splice_init(&pring->txcmplq, &completions);
968 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400969 spin_unlock_irq(&phba->hbalock);
970
James Smart895427b2017-02-12 13:52:30 -0800971 lpfc_sli_abort_iocb_ring(phba, pring);
972 }
James Smartbcece5f2014-04-04 13:51:34 -0400973 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800974 lpfc_sli_cancel_iocbs(phba, &completions,
975 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
976 return;
977 }
978 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
979 pring = qp->pring;
980 if (!pring)
981 continue;
982 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800983 list_for_each_entry_safe(piocb, next_iocb,
984 &pring->txcmplq, list)
985 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800986 list_splice_init(&pring->txcmplq, &completions);
987 pring->txcmplq_cnt = 0;
988 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400989 lpfc_sli_abort_iocb_ring(phba, pring);
990 }
James Smart895427b2017-02-12 13:52:30 -0800991 /* Cancel all the IOCBs from the completions list */
992 lpfc_sli_cancel_iocbs(phba, &completions,
993 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400994}
995
996/**
James Smart3772a992009-05-22 14:50:54 -0400997 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400998 * @phba: pointer to lpfc HBA data structure.
999 *
1000 * This routine will do uninitialization after the HBA is reset when bring
1001 * down the SLI Layer.
1002 *
1003 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001004 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001005 * Any other value - error.
1006 **/
James Smart3772a992009-05-22 14:50:54 -04001007static int
1008lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001009{
James Smartbcece5f2014-04-04 13:51:34 -04001010 lpfc_hba_free_post_buf(phba);
1011 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001012 return 0;
1013}
James Smart5af5eee2010-10-22 11:06:38 -04001014
James Smartda0436e2009-05-22 14:51:39 -04001015/**
1016 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1017 * @phba: pointer to lpfc HBA data structure.
1018 *
1019 * This routine will do uninitialization after the HBA is reset when bring
1020 * down the SLI Layer.
1021 *
1022 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001023 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001024 * Any other value - error.
1025 **/
1026static int
1027lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1028{
James Smartc4908502019-01-28 11:14:28 -08001029 struct lpfc_io_buf *psb, *psb_next;
James Smart7cacae22020-03-31 09:50:03 -07001030 struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
James Smart5e5b5112019-01-28 11:14:22 -08001031 struct lpfc_sli4_hdw_queue *qp;
James Smartda0436e2009-05-22 14:51:39 -04001032 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001033 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001034 LIST_HEAD(nvmet_aborts);
James Smart0f65ff62010-02-26 14:14:23 -05001035 struct lpfc_sglq *sglq_entry = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08001036 int cnt, idx;
James Smart0f65ff62010-02-26 14:14:23 -05001037
James Smart895427b2017-02-12 13:52:30 -08001038
1039 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001040 lpfc_hba_clean_txcmplq(phba);
1041
James Smartda0436e2009-05-22 14:51:39 -04001042 /* At this point in time the HBA is either reset or DOA. Either
1043 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001044 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001045 * driver is unloading or reposted if the driver is restarting
1046 * the port.
1047 */
James Smarta7892412021-04-11 18:31:15 -07001048
James Smart895427b2017-02-12 13:52:30 -08001049 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001050 * list.
1051 */
James Smarta7892412021-04-11 18:31:15 -07001052 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001053 list_for_each_entry(sglq_entry,
1054 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1055 sglq_entry->state = SGL_FREED;
1056
James Smartda0436e2009-05-22 14:51:39 -04001057 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001058 &phba->sli4_hba.lpfc_els_sgl_list);
1059
James Smartf358dd02017-02-12 13:52:34 -08001060
James Smarta7892412021-04-11 18:31:15 -07001061 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001062
1063 /* abts_xxxx_buf_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001064 * list.
1065 */
James Smarta7892412021-04-11 18:31:15 -07001066 spin_lock_irq(&phba->hbalock);
James Smart5e5b5112019-01-28 11:14:22 -08001067 cnt = 0;
1068 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1069 qp = &phba->sli4_hba.hdwq[idx];
1070
James Smartc00f62e2019-08-14 16:57:11 -07001071 spin_lock(&qp->abts_io_buf_list_lock);
1072 list_splice_init(&qp->lpfc_abts_io_buf_list,
James Smart895427b2017-02-12 13:52:30 -08001073 &aborts);
James Smart895427b2017-02-12 13:52:30 -08001074
James Smart0794d602019-01-28 11:14:19 -08001075 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
James Smart86c67372017-04-21 16:05:04 -07001076 psb->pCmd = NULL;
1077 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001078 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001079 }
James Smart5e5b5112019-01-28 11:14:22 -08001080 spin_lock(&qp->io_buf_list_put_lock);
1081 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1082 qp->put_io_bufs += qp->abts_scsi_io_bufs;
James Smartc00f62e2019-08-14 16:57:11 -07001083 qp->put_io_bufs += qp->abts_nvme_io_bufs;
James Smart5e5b5112019-01-28 11:14:22 -08001084 qp->abts_scsi_io_bufs = 0;
James Smartc00f62e2019-08-14 16:57:11 -07001085 qp->abts_nvme_io_bufs = 0;
James Smart5e5b5112019-01-28 11:14:22 -08001086 spin_unlock(&qp->io_buf_list_put_lock);
James Smartc00f62e2019-08-14 16:57:11 -07001087 spin_unlock(&qp->abts_io_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001088 }
James Smart731eedc2019-03-12 16:30:12 -07001089 spin_unlock_irq(&phba->hbalock);
James Smart5e5b5112019-01-28 11:14:22 -08001090
1091 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart731eedc2019-03-12 16:30:12 -07001092 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001093 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1094 &nvmet_aborts);
James Smart731eedc2019-03-12 16:30:12 -07001095 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001096 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
James Smart7b7f5512020-03-31 09:50:04 -07001097 ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001098 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001099 }
James Smart895427b2017-02-12 13:52:30 -08001100 }
James Smart895427b2017-02-12 13:52:30 -08001101
James Smart68e814f2014-05-21 08:04:59 -04001102 lpfc_sli4_free_sp_events(phba);
James Smart5e5b5112019-01-28 11:14:22 -08001103 return cnt;
James Smartda0436e2009-05-22 14:51:39 -04001104}
1105
1106/**
1107 * lpfc_hba_down_post - Wrapper func for hba down post routine
1108 * @phba: pointer to lpfc HBA data structure.
1109 *
1110 * This routine wraps the actual SLI3 or SLI4 routine for performing
1111 * uninitialization after the HBA is reset when bring down the SLI Layer.
1112 *
1113 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001114 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001115 * Any other value - error.
1116 **/
1117int
1118lpfc_hba_down_post(struct lpfc_hba *phba)
1119{
1120 return (*phba->lpfc_hba_down_post)(phba);
1121}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001122
James Smarte59058c2008-08-24 21:49:00 -04001123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_hb_timeout - The HBA-timer timeout handler
Lee Jonesfe614ac2020-07-23 13:24:22 +01001125 * @t: timer context used to obtain the pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04001126 *
1127 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1128 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1129 * work-port-events bitmap and the worker thread is notified. This timeout
1130 * event will be used by the worker thread to invoke the actual timeout
1131 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1132 * be performed in the timeout handler and the HBA timeout event bit shall
1133 * be cleared by the worker thread after it has taken the event bitmap out.
1134 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001135static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001136lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001137{
1138 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001139 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001140 unsigned long iflag;
1141
Kees Cookf22eb4d2017-09-06 20:24:26 -07001142 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001143
1144 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001145 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001146 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1147 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001148 phba->pport->work_port_events |= WORKER_HB_TMO;
1149 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1150
James Smart93996272008-08-24 21:50:30 -04001151 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001152 if (!tmo_posted)
1153 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001154 return;
1155}
1156
James Smarte59058c2008-08-24 21:49:00 -04001157/**
James Smart19ca7602010-11-20 23:11:55 -05001158 * lpfc_rrq_timeout - The RRQ-timer timeout handler
Lee Jonesfe614ac2020-07-23 13:24:22 +01001159 * @t: timer context used to obtain the pointer to lpfc hba data structure.
James Smart19ca7602010-11-20 23:11:55 -05001160 *
1161 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1162 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1163 * work-port-events bitmap and the worker thread is notified. This timeout
1164 * event will be used by the worker thread to invoke the actual timeout
1165 * handler routine, lpfc_rrq_handler. Any periodical operations will
1166 * be performed in the timeout handler and the RRQ timeout event bit shall
1167 * be cleared by the worker thread after it has taken the event bitmap out.
1168 **/
1169static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001170lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001171{
1172 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001173 unsigned long iflag;
1174
Kees Cookf22eb4d2017-09-06 20:24:26 -07001175 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001176 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001177 if (!(phba->pport->load_flag & FC_UNLOADING))
1178 phba->hba_flag |= HBA_RRQ_ACTIVE;
1179 else
1180 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001181 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001182
1183 if (!(phba->pport->load_flag & FC_UNLOADING))
1184 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001185}
1186
1187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001189 * @phba: pointer to lpfc hba data structure.
1190 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1191 *
1192 * This is the callback function to the lpfc heart-beat mailbox command.
1193 * If configured, the lpfc driver issues the heart-beat mailbox command to
1194 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1195 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1196 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1197 * heart-beat outstanding state. Once the mailbox command comes back and
1198 * no error conditions detected, the heart-beat mailbox command timer is
1199 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1200 * state is cleared for the next heart-beat. If the timer expired with the
1201 * heart-beat outstanding state set, the driver will put the HBA offline.
1202 **/
James Smart858c9f62007-06-17 19:56:39 -05001203static void
1204lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1205{
1206 unsigned long drvr_flag;
1207
1208 spin_lock_irqsave(&phba->hbalock, drvr_flag);
James Smarta22d73b2021-01-04 10:02:38 -08001209 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
James Smart858c9f62007-06-17 19:56:39 -05001210 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1211
James Smarta22d73b2021-01-04 10:02:38 -08001212 /* Check and reset heart-beat timer if necessary */
James Smart858c9f62007-06-17 19:56:39 -05001213 mempool_free(pmboxq, phba->mbox_mem_pool);
1214 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1215 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001216 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001217 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001218 jiffies +
1219 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001220 return;
1221}
1222
Lee Jonesfe614ac2020-07-23 13:24:22 +01001223/*
Dick Kennedy317aeb82020-06-30 14:49:59 -07001224 * lpfc_idle_stat_delay_work - idle_stat tracking
1225 *
1226 * This routine tracks per-cq idle_stat and determines polling decisions.
1227 *
1228 * Return codes:
1229 * None
1230 **/
1231static void
1232lpfc_idle_stat_delay_work(struct work_struct *work)
1233{
1234 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1235 struct lpfc_hba,
1236 idle_stat_delay_work);
1237 struct lpfc_queue *cq;
1238 struct lpfc_sli4_hdw_queue *hdwq;
1239 struct lpfc_idle_stat *idle_stat;
1240 u32 i, idle_percent;
1241 u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
1242
1243 if (phba->pport->load_flag & FC_UNLOADING)
1244 return;
1245
1246 if (phba->link_state == LPFC_HBA_ERROR ||
James Smart9064aeb2021-08-16 09:28:50 -07001247 phba->pport->fc_flag & FC_OFFLINE_MODE ||
1248 phba->cmf_active_mode != LPFC_CFG_OFF)
Dick Kennedy317aeb82020-06-30 14:49:59 -07001249 goto requeue;
1250
1251 for_each_present_cpu(i) {
1252 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
1253 cq = hdwq->io_cq;
1254
1255 /* Skip if we've already handled this cq's primary CPU */
1256 if (cq->chann != i)
1257 continue;
1258
1259 idle_stat = &phba->sli4_hba.idle_stat[i];
1260
1261 /* get_cpu_idle_time returns values as running counters. Thus,
1262 * to know the amount for this period, the prior counter values
1263 * need to be subtracted from the current counter values.
1264 * From there, the idle time stat can be calculated as a
1265 * percentage of 100 - the sum of the other consumption times.
1266 */
1267 wall_idle = get_cpu_idle_time(i, &wall, 1);
1268 diff_idle = wall_idle - idle_stat->prev_idle;
1269 diff_wall = wall - idle_stat->prev_wall;
1270
1271 if (diff_wall <= diff_idle)
1272 busy_time = 0;
1273 else
1274 busy_time = diff_wall - diff_idle;
1275
1276 idle_percent = div64_u64(100 * busy_time, diff_wall);
1277 idle_percent = 100 - idle_percent;
1278
1279 if (idle_percent < 15)
1280 cq->poll_mode = LPFC_QUEUE_WORK;
1281 else
1282 cq->poll_mode = LPFC_IRQ_POLL;
1283
1284 idle_stat->prev_idle = wall_idle;
1285 idle_stat->prev_wall = wall;
1286 }
1287
1288requeue:
1289 schedule_delayed_work(&phba->idle_stat_delay_work,
1290 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
1291}
1292
James Smart32517fc2019-01-28 11:14:33 -08001293static void
1294lpfc_hb_eq_delay_work(struct work_struct *work)
1295{
1296 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1297 struct lpfc_hba, eq_delay_work);
1298 struct lpfc_eq_intr_info *eqi, *eqi_new;
1299 struct lpfc_queue *eq, *eq_next;
James Smart8156d372019-10-18 14:18:26 -07001300 unsigned char *ena_delay = NULL;
James Smart32517fc2019-01-28 11:14:33 -08001301 uint32_t usdelay;
1302 int i;
1303
1304 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1305 return;
1306
1307 if (phba->link_state == LPFC_HBA_ERROR ||
1308 phba->pport->fc_flag & FC_OFFLINE_MODE)
1309 goto requeue;
1310
James Smart8156d372019-10-18 14:18:26 -07001311 ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
1312 GFP_KERNEL);
1313 if (!ena_delay)
James Smart32517fc2019-01-28 11:14:33 -08001314 goto requeue;
1315
James Smart8156d372019-10-18 14:18:26 -07001316 for (i = 0; i < phba->cfg_irq_chann; i++) {
1317 /* Get the EQ corresponding to the IRQ vector */
1318 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1319 if (!eq)
1320 continue;
1321 if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
1322 eq->q_flag &= ~HBA_EQ_DELAY_CHK;
1323 ena_delay[eq->last_cpu] = 1;
James Smart8d34a592019-08-14 16:56:35 -07001324 }
James Smart8156d372019-10-18 14:18:26 -07001325 }
James Smart32517fc2019-01-28 11:14:33 -08001326
1327 for_each_present_cpu(i) {
James Smart32517fc2019-01-28 11:14:33 -08001328 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
James Smart8156d372019-10-18 14:18:26 -07001329 if (ena_delay[i]) {
1330 usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
1331 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1332 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1333 } else {
1334 usdelay = 0;
James Smart8d34a592019-08-14 16:56:35 -07001335 }
James Smart32517fc2019-01-28 11:14:33 -08001336
James Smart32517fc2019-01-28 11:14:33 -08001337 eqi->icnt = 0;
1338
1339 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
James Smart8156d372019-10-18 14:18:26 -07001340 if (unlikely(eq->last_cpu != i)) {
James Smart32517fc2019-01-28 11:14:33 -08001341 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1342 eq->last_cpu);
1343 list_move_tail(&eq->cpu_list, &eqi_new->list);
1344 continue;
1345 }
1346 if (usdelay != eq->q_mode)
1347 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1348 usdelay);
1349 }
1350 }
1351
James Smart8156d372019-10-18 14:18:26 -07001352 kfree(ena_delay);
James Smart32517fc2019-01-28 11:14:33 -08001353
1354requeue:
1355 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1356 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1357}
1358
James Smarte59058c2008-08-24 21:49:00 -04001359/**
James Smartc4908502019-01-28 11:14:28 -08001360 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1361 * @phba: pointer to lpfc hba data structure.
1362 *
1363 * For each heartbeat, this routine does some heuristic methods to adjust
1364 * XRI distribution. The goal is to fully utilize free XRIs.
1365 **/
1366static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1367{
1368 u32 i;
1369 u32 hwq_count;
1370
1371 hwq_count = phba->cfg_hdw_queue;
1372 for (i = 0; i < hwq_count; i++) {
1373 /* Adjust XRIs in private pool */
1374 lpfc_adjust_pvt_pool_count(phba, i);
1375
1376 /* Adjust high watermark */
1377 lpfc_adjust_high_watermark(phba, i);
1378
1379#ifdef LPFC_MXP_STAT
1380 /* Snapshot pbl, pvt and busy count */
1381 lpfc_snapshot_mxp(phba, i);
1382#endif
1383 }
1384}
1385
James Smarte59058c2008-08-24 21:49:00 -04001386/**
James Smarta22d73b2021-01-04 10:02:38 -08001387 * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
1388 * @phba: pointer to lpfc hba data structure.
1389 *
1390 * If a HB mbox is not already in progrees, this routine will allocate
1391 * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
1392 * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
1393 **/
1394int
1395lpfc_issue_hb_mbox(struct lpfc_hba *phba)
1396{
1397 LPFC_MBOXQ_t *pmboxq;
1398 int retval;
1399
1400 /* Is a Heartbeat mbox already in progress */
1401 if (phba->hba_flag & HBA_HBEAT_INP)
1402 return 0;
1403
1404 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1405 if (!pmboxq)
1406 return -ENOMEM;
1407
1408 lpfc_heart_beat(phba, pmboxq);
1409 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1410 pmboxq->vport = phba->pport;
1411 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
1412
1413 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1414 mempool_free(pmboxq, phba->mbox_mem_pool);
1415 return -ENXIO;
1416 }
1417 phba->hba_flag |= HBA_HBEAT_INP;
1418
1419 return 0;
1420}
1421
1422/**
1423 * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
1424 * @phba: pointer to lpfc hba data structure.
1425 *
1426 * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
1427 * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
1428 * of the value of lpfc_enable_hba_heartbeat.
1429 * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
1430 * try to issue a MBX_HEARTBEAT mbox command.
1431 **/
1432void
1433lpfc_issue_hb_tmo(struct lpfc_hba *phba)
1434{
1435 if (phba->cfg_enable_hba_heartbeat)
1436 return;
1437 phba->hba_flag |= HBA_HBEAT_TMO;
1438}
1439
1440/**
James Smart3621a712009-04-06 18:47:14 -04001441 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001442 * @phba: pointer to lpfc hba data structure.
1443 *
1444 * This is the actual HBA-timer timeout handler to be invoked by the worker
1445 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1446 * handler performs any periodic operations needed for the device. If such
1447 * periodic event has already been attended to either in the interrupt handler
1448 * or by processing slow-ring or fast-ring events within the HBA-timer
1449 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1450 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1451 * is configured and there is no heart-beat mailbox command outstanding, a
1452 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1453 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1454 * to offline.
1455 **/
James Smart858c9f62007-06-17 19:56:39 -05001456void
1457lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1458{
James Smart45ed1192009-10-02 15:17:02 -04001459 struct lpfc_vport **vports;
James Smart0ff10d42008-01-11 01:52:36 -05001460 struct lpfc_dmabuf *buf_ptr;
James Smarta22d73b2021-01-04 10:02:38 -08001461 int retval = 0;
1462 int i, tmo;
James Smart858c9f62007-06-17 19:56:39 -05001463 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001464 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001465
James Smartc4908502019-01-28 11:14:28 -08001466 if (phba->cfg_xri_rebalancing) {
1467 /* Multi-XRI pools handler */
1468 lpfc_hb_mxp_handler(phba);
1469 }
James Smart858c9f62007-06-17 19:56:39 -05001470
James Smart45ed1192009-10-02 15:17:02 -04001471 vports = lpfc_create_vport_work_array(phba);
1472 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001473 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001474 lpfc_rcv_seq_check_edtov(vports[i]);
James Smarte3ba04c2019-12-18 15:58:02 -08001475 lpfc_fdmi_change_check(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001476 }
James Smart45ed1192009-10-02 15:17:02 -04001477 lpfc_destroy_vport_work_array(phba, vports);
1478
James Smart858c9f62007-06-17 19:56:39 -05001479 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001480 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001481 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1482 return;
1483
James Smart0ff10d42008-01-11 01:52:36 -05001484 if (phba->elsbuf_cnt &&
1485 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1486 spin_lock_irq(&phba->hbalock);
1487 list_splice_init(&phba->elsbuf, &completions);
1488 phba->elsbuf_cnt = 0;
1489 phba->elsbuf_prev_cnt = 0;
1490 spin_unlock_irq(&phba->hbalock);
1491
1492 while (!list_empty(&completions)) {
1493 list_remove_head(&completions, buf_ptr,
1494 struct lpfc_dmabuf, list);
1495 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1496 kfree(buf_ptr);
1497 }
1498 }
1499 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1500
James Smart858c9f62007-06-17 19:56:39 -05001501 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001502 if (phba->cfg_enable_hba_heartbeat) {
James Smarta22d73b2021-01-04 10:02:38 -08001503 /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
1504 spin_lock_irq(&phba->pport->work_port_lock);
1505 if (time_after(phba->last_completion_time +
1506 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1507 jiffies)) {
1508 spin_unlock_irq(&phba->pport->work_port_lock);
1509 if (phba->hba_flag & HBA_HBEAT_INP)
1510 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1511 else
1512 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1513 goto out;
1514 }
1515 spin_unlock_irq(&phba->pport->work_port_lock);
1516
1517 /* Check if a MBX_HEARTBEAT is already in progress */
1518 if (phba->hba_flag & HBA_HBEAT_INP) {
1519 /*
1520 * If heart beat timeout called with HBA_HBEAT_INP set
1521 * we need to give the hb mailbox cmd a chance to
1522 * complete or TMO.
1523 */
1524 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1525 "0459 Adapter heartbeat still outstanding: "
1526 "last compl time was %d ms.\n",
1527 jiffies_to_msecs(jiffies
1528 - phba->last_completion_time));
1529 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1530 } else {
James Smartbc739052010-08-04 16:11:18 -04001531 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1532 (list_empty(&psli->mboxq))) {
James Smart13815c82008-01-11 01:52:48 -05001533
James Smarta22d73b2021-01-04 10:02:38 -08001534 retval = lpfc_issue_hb_mbox(phba);
1535 if (retval) {
1536 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1537 goto out;
James Smartbc739052010-08-04 16:11:18 -04001538 }
1539 phba->skipped_hb = 0;
James Smartbc739052010-08-04 16:11:18 -04001540 } else if (time_before_eq(phba->last_completion_time,
1541 phba->skipped_hb)) {
1542 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1543 "2857 Last completion time not "
1544 " updated in %d ms\n",
1545 jiffies_to_msecs(jiffies
1546 - phba->last_completion_time));
1547 } else
1548 phba->skipped_hb = jiffies;
1549
James Smarta22d73b2021-01-04 10:02:38 -08001550 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1551 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001552 }
James Smart4258e982015-12-16 18:11:58 -05001553 } else {
James Smarta22d73b2021-01-04 10:02:38 -08001554 /* Check to see if we want to force a MBX_HEARTBEAT */
1555 if (phba->hba_flag & HBA_HBEAT_TMO) {
1556 retval = lpfc_issue_hb_mbox(phba);
1557 if (retval)
1558 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
1559 else
1560 tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
1561 goto out;
1562 }
1563 tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
James Smart858c9f62007-06-17 19:56:39 -05001564 }
James Smarta22d73b2021-01-04 10:02:38 -08001565out:
1566 mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
James Smart858c9f62007-06-17 19:56:39 -05001567}
1568
James Smarte59058c2008-08-24 21:49:00 -04001569/**
James Smart3621a712009-04-06 18:47:14 -04001570 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001571 * @phba: pointer to lpfc hba data structure.
1572 *
1573 * This routine is called to bring the HBA offline when HBA hardware error
1574 * other than Port Error 6 has been detected.
1575 **/
James Smart09372822008-01-11 01:52:54 -05001576static void
1577lpfc_offline_eratt(struct lpfc_hba *phba)
1578{
1579 struct lpfc_sli *psli = &phba->sli;
1580
1581 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001582 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001583 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001584 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001585
1586 lpfc_offline(phba);
1587 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001588 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001589 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001590 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001591 lpfc_hba_down_post(phba);
1592 lpfc_sli_brdready(phba, HS_MBRDY);
1593 lpfc_unblock_mgmt_io(phba);
1594 phba->link_state = LPFC_HBA_ERROR;
1595 return;
1596}
1597
James Smarte59058c2008-08-24 21:49:00 -04001598/**
James Smartda0436e2009-05-22 14:51:39 -04001599 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1600 * @phba: pointer to lpfc hba data structure.
1601 *
1602 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1603 * other than Port Error 6 has been detected.
1604 **/
James Smarta88dbb62013-04-17 20:18:39 -04001605void
James Smartda0436e2009-05-22 14:51:39 -04001606lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1607{
James Smart946727d2015-04-07 15:07:09 -04001608 spin_lock_irq(&phba->hbalock);
James Smart25ac2c972021-09-10 16:31:54 -07001609 if (phba->link_state == LPFC_HBA_ERROR &&
1610 phba->hba_flag & HBA_PCI_ERR) {
1611 spin_unlock_irq(&phba->hbalock);
1612 return;
1613 }
James Smart946727d2015-04-07 15:07:09 -04001614 phba->link_state = LPFC_HBA_ERROR;
1615 spin_unlock_irq(&phba->hbalock);
1616
James Smart618a5232012-06-12 13:54:36 -04001617 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartc00f62e2019-08-14 16:57:11 -07001618 lpfc_sli_flush_io_rings(phba);
James Smartda0436e2009-05-22 14:51:39 -04001619 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001620 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001621 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001622}
1623
1624/**
James Smarta257bf92009-04-06 18:48:10 -04001625 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1626 * @phba: pointer to lpfc hba data structure.
1627 *
1628 * This routine is invoked to handle the deferred HBA hardware error
1629 * conditions. This type of error is indicated by HBA by setting ER1
1630 * and another ER bit in the host status register. The driver will
1631 * wait until the ER1 bit clears before handling the error condition.
1632 **/
1633static void
1634lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1635{
1636 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001637 struct lpfc_sli *psli = &phba->sli;
1638
James Smartf4b4c682009-05-22 14:53:12 -04001639 /* If the pci channel is offline, ignore possible errors,
1640 * since we cannot communicate with the pci card anyway.
1641 */
1642 if (pci_channel_offline(phba->pcidev)) {
1643 spin_lock_irq(&phba->hbalock);
1644 phba->hba_flag &= ~DEFER_ERATT;
1645 spin_unlock_irq(&phba->hbalock);
1646 return;
1647 }
1648
Dick Kennedy372c1872020-06-30 14:50:00 -07001649 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1650 "0479 Deferred Adapter Hardware Error "
1651 "Data: x%x x%x x%x\n",
1652 phba->work_hs, phba->work_status[0],
1653 phba->work_status[1]);
James Smarta257bf92009-04-06 18:48:10 -04001654
1655 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001656 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001657 spin_unlock_irq(&phba->hbalock);
1658
1659
1660 /*
1661 * Firmware stops when it triggred erratt. That could cause the I/Os
1662 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1663 * SCSI layer retry it after re-establishing link.
1664 */
James Smartdb55fba2014-04-04 13:52:02 -04001665 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001666
1667 /*
1668 * There was a firmware error. Take the hba offline and then
1669 * attempt to restart it.
1670 */
James Smart618a5232012-06-12 13:54:36 -04001671 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001672 lpfc_offline(phba);
1673
1674 /* Wait for the ER1 bit to clear.*/
1675 while (phba->work_hs & HS_FFER1) {
1676 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001677 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1678 phba->work_hs = UNPLUG_ERR ;
1679 break;
1680 }
James Smarta257bf92009-04-06 18:48:10 -04001681 /* If driver is unloading let the worker thread continue */
1682 if (phba->pport->load_flag & FC_UNLOADING) {
1683 phba->work_hs = 0;
1684 break;
1685 }
1686 }
1687
1688 /*
1689 * This is to ptrotect against a race condition in which
1690 * first write to the host attention register clear the
1691 * host status register.
1692 */
1693 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1694 phba->work_hs = old_host_status & ~HS_FFER1;
1695
James Smart3772a992009-05-22 14:50:54 -04001696 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001697 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001698 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001699 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1700 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1701}
1702
James Smart3772a992009-05-22 14:50:54 -04001703static void
1704lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1705{
1706 struct lpfc_board_event_header board_event;
1707 struct Scsi_Host *shost;
1708
1709 board_event.event_type = FC_REG_BOARD_EVENT;
1710 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1711 shost = lpfc_shost_from_vport(phba->pport);
1712 fc_host_post_vendor_event(shost, fc_get_event_number(),
1713 sizeof(board_event),
1714 (char *) &board_event,
1715 LPFC_NL_VENDOR_ID);
1716}
1717
James Smarta257bf92009-04-06 18:48:10 -04001718/**
James Smart3772a992009-05-22 14:50:54 -04001719 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001720 * @phba: pointer to lpfc hba data structure.
1721 *
1722 * This routine is invoked to handle the following HBA hardware error
1723 * conditions:
1724 * 1 - HBA error attention interrupt
1725 * 2 - DMA ring index out of range
1726 * 3 - Mailbox command came back as unknown
1727 **/
James Smart3772a992009-05-22 14:50:54 -04001728static void
1729lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001730{
James Smart2e0fef82007-06-17 19:56:36 -05001731 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001732 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001733 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001734 unsigned long temperature;
1735 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001736 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001737
Linas Vepstas8d63f372007-02-14 14:28:36 -06001738 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001739 * since we cannot communicate with the pci card anyway.
1740 */
1741 if (pci_channel_offline(phba->pcidev)) {
1742 spin_lock_irq(&phba->hbalock);
1743 phba->hba_flag &= ~DEFER_ERATT;
1744 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001745 return;
James Smart3772a992009-05-22 14:50:54 -04001746 }
1747
James Smart13815c82008-01-11 01:52:48 -05001748 /* If resets are disabled then leave the HBA alone and return */
1749 if (!phba->cfg_enable_hba_reset)
1750 return;
dea31012005-04-17 16:05:31 -05001751
James Smartea2151b2008-09-07 11:52:10 -04001752 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001753 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001754
James Smarta257bf92009-04-06 18:48:10 -04001755 if (phba->hba_flag & DEFER_ERATT)
1756 lpfc_handle_deferred_eratt(phba);
1757
James Smartdcf2a4e2010-09-29 11:18:53 -04001758 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1759 if (phba->work_hs & HS_FFER6)
1760 /* Re-establishing Link */
1761 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1762 "1301 Re-establishing Link "
1763 "Data: x%x x%x x%x\n",
1764 phba->work_hs, phba->work_status[0],
1765 phba->work_status[1]);
1766 if (phba->work_hs & HS_FFER8)
1767 /* Device Zeroization */
1768 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1769 "2861 Host Authentication device "
1770 "zeroization Data:x%x x%x x%x\n",
1771 phba->work_hs, phba->work_status[0],
1772 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001773
James Smart92d7f7b2007-06-17 19:56:38 -05001774 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001775 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001776 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001777
1778 /*
1779 * Firmware stops when it triggled erratt with HS_FFER6.
1780 * That could cause the I/Os dropped by the firmware.
1781 * Error iocb (I/O) on txcmplq and let the SCSI layer
1782 * retry it after re-establishing link.
1783 */
James Smartdb55fba2014-04-04 13:52:02 -04001784 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001785
dea31012005-04-17 16:05:31 -05001786 /*
1787 * There was a firmware error. Take the hba offline and then
1788 * attempt to restart it.
1789 */
James Smart618a5232012-06-12 13:54:36 -04001790 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001791 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001792 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001793 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001794 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001795 return;
1796 }
James Smart46fa3112007-04-25 09:51:45 -04001797 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001798 } else if (phba->work_hs & HS_CRIT_TEMP) {
1799 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1800 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1801 temp_event_data.event_code = LPFC_CRIT_TEMP;
1802 temp_event_data.data = (uint32_t)temperature;
1803
Dick Kennedy372c1872020-06-30 14:50:00 -07001804 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04001805 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001806 "(%ld), taking this port offline "
1807 "Data: x%x x%x x%x\n",
1808 temperature, phba->work_hs,
1809 phba->work_status[0], phba->work_status[1]);
1810
1811 shost = lpfc_shost_from_vport(phba->pport);
1812 fc_host_post_vendor_event(shost, fc_get_event_number(),
1813 sizeof(temp_event_data),
1814 (char *) &temp_event_data,
1815 SCSI_NL_VID_TYPE_PCI
1816 | PCI_VENDOR_ID_EMULEX);
1817
James Smart7af67052007-10-27 13:38:11 -04001818 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001819 phba->over_temp_state = HBA_OVER_TEMP;
1820 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001821 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001822
dea31012005-04-17 16:05:31 -05001823 } else {
1824 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001825 * failure is a value other than FFER6. Do not call the offline
1826 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001827 */
Dick Kennedy372c1872020-06-30 14:50:00 -07001828 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001829 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001830 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001831 phba->work_hs,
dea31012005-04-17 16:05:31 -05001832 phba->work_status[0], phba->work_status[1]);
1833
James Smartd2873e42006-08-18 17:46:43 -04001834 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001835 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001836 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001837 sizeof(event_data), (char *) &event_data,
1838 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1839
James Smart09372822008-01-11 01:52:54 -05001840 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001841 }
James Smart93996272008-08-24 21:50:30 -04001842 return;
dea31012005-04-17 16:05:31 -05001843}
1844
James Smarte59058c2008-08-24 21:49:00 -04001845/**
James Smart618a5232012-06-12 13:54:36 -04001846 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1847 * @phba: pointer to lpfc hba data structure.
1848 * @mbx_action: flag for mailbox shutdown action.
Lee Jonesfe614ac2020-07-23 13:24:22 +01001849 * @en_rn_msg: send reset/port recovery message.
James Smart618a5232012-06-12 13:54:36 -04001850 * This routine is invoked to perform an SLI4 port PCI function reset in
1851 * response to port status register polling attention. It waits for port
1852 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1853 * During this process, interrupt vectors are freed and later requested
1854 * for handling possible port resource change.
1855 **/
1856static int
James Smarte10b2022014-02-20 09:57:43 -05001857lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1858 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001859{
1860 int rc;
1861 uint32_t intr_mode;
James Smarta9978e32021-07-07 11:43:43 -07001862 LPFC_MBOXQ_t *mboxq;
James Smart618a5232012-06-12 13:54:36 -04001863
James Smart27d6ac02018-02-22 08:18:42 -08001864 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001865 LPFC_SLI_INTF_IF_TYPE_2) {
1866 /*
1867 * On error status condition, driver need to wait for port
1868 * ready before performing reset.
1869 */
1870 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001871 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001872 return rc;
James Smart618a5232012-06-12 13:54:36 -04001873 }
James Smart0e916ee2016-07-06 12:36:06 -07001874
James Smart65791f12016-07-06 12:35:56 -07001875 /* need reset: attempt for port recovery */
1876 if (en_rn_msg)
James Smart0b3ad322021-01-04 10:02:39 -08001877 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart65791f12016-07-06 12:35:56 -07001878 "2887 Reset Needed: Attempting Port "
1879 "Recovery...\n");
James Smart3ba62162021-01-04 10:02:31 -08001880
1881 /* If we are no wait, the HBA has been reset and is not
James Smarta9978e32021-07-07 11:43:43 -07001882 * functional, thus we should clear
1883 * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
James Smart3ba62162021-01-04 10:02:31 -08001884 */
1885 if (mbx_action == LPFC_MBX_NO_WAIT) {
1886 spin_lock_irq(&phba->hbalock);
1887 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta9978e32021-07-07 11:43:43 -07001888 if (phba->sli.mbox_active) {
1889 mboxq = phba->sli.mbox_active;
1890 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
1891 __lpfc_mbox_cmpl_put(phba, mboxq);
1892 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1893 phba->sli.mbox_active = NULL;
1894 }
James Smart3ba62162021-01-04 10:02:31 -08001895 spin_unlock_irq(&phba->hbalock);
1896 }
1897
James Smart65791f12016-07-06 12:35:56 -07001898 lpfc_offline_prep(phba, mbx_action);
James Smartc00f62e2019-08-14 16:57:11 -07001899 lpfc_sli_flush_io_rings(phba);
James Smart65791f12016-07-06 12:35:56 -07001900 lpfc_offline(phba);
1901 /* release interrupt for possible resource change */
1902 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001903 rc = lpfc_sli_brdrestart(phba);
1904 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001905 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5a9eeff2018-11-29 16:09:32 -08001906 "6309 Failed to restart board\n");
1907 return rc;
1908 }
James Smart65791f12016-07-06 12:35:56 -07001909 /* request and enable interrupt */
1910 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1911 if (intr_mode == LPFC_INTR_ERROR) {
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 "3175 Failed to enable interrupt\n");
1914 return -EIO;
1915 }
1916 phba->intr_mode = intr_mode;
1917 rc = lpfc_online(phba);
1918 if (rc == 0)
1919 lpfc_unblock_mgmt_io(phba);
1920
James Smart618a5232012-06-12 13:54:36 -04001921 return rc;
1922}
1923
1924/**
James Smartda0436e2009-05-22 14:51:39 -04001925 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1926 * @phba: pointer to lpfc hba data structure.
1927 *
1928 * This routine is invoked to handle the SLI4 HBA hardware error attention
1929 * conditions.
1930 **/
1931static void
1932lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1933{
1934 struct lpfc_vport *vport = phba->pport;
1935 uint32_t event_data;
1936 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001937 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001938 struct lpfc_register portstat_reg = {0};
1939 uint32_t reg_err1, reg_err2;
1940 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001941 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001942 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001943 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001944 struct lpfc_register portsmphr_reg;
1945 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001946
1947 /* If the pci channel is offline, ignore possible errors, since
1948 * we cannot communicate with the pci card anyway.
1949 */
James Smart32a93102019-03-12 16:30:13 -07001950 if (pci_channel_offline(phba->pcidev)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001951 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart32a93102019-03-12 16:30:13 -07001952 "3166 pci channel is offline\n");
James Smartda0436e2009-05-22 14:51:39 -04001953 return;
James Smart32a93102019-03-12 16:30:13 -07001954 }
James Smartda0436e2009-05-22 14:51:39 -04001955
James Smart65791f12016-07-06 12:35:56 -07001956 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001957 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1958 switch (if_type) {
1959 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001960 pci_rd_rc1 = lpfc_readl(
1961 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1962 &uerrlo_reg);
1963 pci_rd_rc2 = lpfc_readl(
1964 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1965 &uemasklo_reg);
1966 /* consider PCI bus read error as pci_channel_offline */
1967 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1968 return;
James Smart65791f12016-07-06 12:35:56 -07001969 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1970 lpfc_sli4_offline_eratt(phba);
1971 return;
1972 }
Dick Kennedy372c1872020-06-30 14:50:00 -07001973 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001974 "7623 Checking UE recoverable");
1975
1976 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1977 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1978 &portsmphr_reg.word0))
1979 continue;
1980
1981 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1982 &portsmphr_reg);
1983 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1984 LPFC_PORT_SEM_UE_RECOVERABLE)
1985 break;
1986 /*Sleep for 1Sec, before checking SEMAPHORE */
1987 msleep(1000);
1988 }
1989
Dick Kennedy372c1872020-06-30 14:50:00 -07001990 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07001991 "4827 smphr_port_status x%x : Waited %dSec",
1992 smphr_port_status, i);
1993
1994 /* Recoverable UE, reset the HBA device */
1995 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1996 LPFC_PORT_SEM_UE_RECOVERABLE) {
1997 for (i = 0; i < 20; i++) {
1998 msleep(1000);
1999 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
2000 &portsmphr_reg.word0) &&
2001 (LPFC_POST_STAGE_PORT_READY ==
2002 bf_get(lpfc_port_smphr_port_status,
2003 &portsmphr_reg))) {
2004 rc = lpfc_sli4_port_sta_fn_reset(phba,
2005 LPFC_MBX_NO_WAIT, en_rn_msg);
2006 if (rc == 0)
2007 return;
Dick Kennedy372c1872020-06-30 14:50:00 -07002008 lpfc_printf_log(phba, KERN_ERR,
2009 LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07002010 "4215 Failed to recover UE");
2011 break;
2012 }
2013 }
2014 }
Dick Kennedy372c1872020-06-30 14:50:00 -07002015 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart65791f12016-07-06 12:35:56 -07002016 "7624 Firmware not ready: Failing UE recovery,"
2017 " waited %dSec", i);
James Smart8c24a4f2019-08-14 16:56:53 -07002018 phba->link_state = LPFC_HBA_ERROR;
James Smart2fcee4b2010-12-15 17:57:46 -05002019 break;
James Smart946727d2015-04-07 15:07:09 -04002020
James Smart2fcee4b2010-12-15 17:57:46 -05002021 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08002022 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05002023 pci_rd_rc1 = lpfc_readl(
2024 phba->sli4_hba.u.if_type2.STATUSregaddr,
2025 &portstat_reg.word0);
2026 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05002027 if (pci_rd_rc1 == -EIO) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002028 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6b5151f2012-01-18 16:24:06 -05002029 "3151 PCI bus read access failure: x%x\n",
2030 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart32a93102019-03-12 16:30:13 -07002031 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05002032 return;
James Smart6b5151f2012-01-18 16:24:06 -05002033 }
James Smart2e90f4b2011-12-13 13:22:37 -05002034 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
2035 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05002036 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002037 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2038 "2889 Port Overtemperature event, "
2039 "taking port offline Data: x%x x%x\n",
2040 reg_err1, reg_err2);
James Smart946727d2015-04-07 15:07:09 -04002041
James Smart310429e2016-07-06 12:35:54 -07002042 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04002043 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
2044 temp_event_data.event_code = LPFC_CRIT_TEMP;
2045 temp_event_data.data = 0xFFFFFFFF;
2046
2047 shost = lpfc_shost_from_vport(phba->pport);
2048 fc_host_post_vendor_event(shost, fc_get_event_number(),
2049 sizeof(temp_event_data),
2050 (char *)&temp_event_data,
2051 SCSI_NL_VID_TYPE_PCI
2052 | PCI_VENDOR_ID_EMULEX);
2053
James Smart2fcee4b2010-12-15 17:57:46 -05002054 spin_lock_irq(&phba->hbalock);
2055 phba->over_temp_state = HBA_OVER_TEMP;
2056 spin_unlock_irq(&phba->hbalock);
2057 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04002058 return;
James Smart2fcee4b2010-12-15 17:57:46 -05002059 }
James Smart2e90f4b2011-12-13 13:22:37 -05002060 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05002061 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002062 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarte10b2022014-02-20 09:57:43 -05002063 "3143 Port Down: Firmware Update "
2064 "Detected\n");
2065 en_rn_msg = false;
2066 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05002067 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
Dick Kennedy372c1872020-06-30 14:50:00 -07002068 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -05002069 "3144 Port Down: Debug Dump\n");
2070 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2071 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
Dick Kennedy372c1872020-06-30 14:50:00 -07002072 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -05002073 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04002074
James Smart946727d2015-04-07 15:07:09 -04002075 /* If resets are disabled then leave the HBA alone and return */
2076 if (!phba->cfg_enable_hba_reset)
2077 return;
2078
James Smart618a5232012-06-12 13:54:36 -04002079 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05002080 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
2081 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04002082 if (rc == 0) {
2083 /* don't report event on forced debug dump */
2084 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
2085 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
2086 return;
2087 else
2088 break;
James Smart2fcee4b2010-12-15 17:57:46 -05002089 }
James Smart618a5232012-06-12 13:54:36 -04002090 /* fall through for not able to recover */
Dick Kennedy372c1872020-06-30 14:50:00 -07002091 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart8c24a4f2019-08-14 16:56:53 -07002092 "3152 Unrecoverable error\n");
2093 phba->link_state = LPFC_HBA_ERROR;
James Smart2fcee4b2010-12-15 17:57:46 -05002094 break;
2095 case LPFC_SLI_INTF_IF_TYPE_1:
2096 default:
2097 break;
2098 }
James Smart2e90f4b2011-12-13 13:22:37 -05002099 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2100 "3123 Report dump event to upper layer\n");
2101 /* Send an internal error event to mgmt application */
2102 lpfc_board_errevt_to_mgmt(phba);
2103
2104 event_data = FC_REG_DUMP_EVENT;
2105 shost = lpfc_shost_from_vport(vport);
2106 fc_host_post_vendor_event(shost, fc_get_event_number(),
2107 sizeof(event_data), (char *) &event_data,
2108 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002109}
2110
2111/**
2112 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2113 * @phba: pointer to lpfc HBA data structure.
2114 *
2115 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2116 * routine from the API jump table function pointer from the lpfc_hba struct.
2117 *
2118 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002119 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002120 * Any other value - error.
2121 **/
2122void
2123lpfc_handle_eratt(struct lpfc_hba *phba)
2124{
2125 (*phba->lpfc_handle_eratt)(phba);
2126}
2127
2128/**
James Smart3621a712009-04-06 18:47:14 -04002129 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002130 * @phba: pointer to lpfc hba data structure.
2131 *
2132 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002133 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002134 **/
dea31012005-04-17 16:05:31 -05002135void
James Smart2e0fef82007-06-17 19:56:36 -05002136lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002137{
James Smart2e0fef82007-06-17 19:56:36 -05002138 struct lpfc_vport *vport = phba->pport;
2139 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002140 LPFC_MBOXQ_t *pmb;
2141 volatile uint32_t control;
2142 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002143 int rc = 0;
dea31012005-04-17 16:05:31 -05002144
2145 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002146 if (!pmb) {
2147 rc = 1;
dea31012005-04-17 16:05:31 -05002148 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002149 }
dea31012005-04-17 16:05:31 -05002150
2151 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002152 if (!mp) {
2153 rc = 2;
dea31012005-04-17 16:05:31 -05002154 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002155 }
dea31012005-04-17 16:05:31 -05002156
2157 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002158 if (!mp->virt) {
2159 rc = 3;
dea31012005-04-17 16:05:31 -05002160 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002161 }
dea31012005-04-17 16:05:31 -05002162
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002163 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002164 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002165
2166 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002167 lpfc_read_topology(phba, pmb, mp);
2168 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002169 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002170 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002171 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002172 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002173 if (rc == MBX_NOT_FINISHED) {
2174 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002175 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002176 }
dea31012005-04-17 16:05:31 -05002177
2178 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002179 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002180 writel(HA_LATT, phba->HAregaddr);
2181 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002182 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002183
2184 return;
2185
James Smart14691152006-12-02 13:34:28 -05002186lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002187 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002188 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002189lpfc_handle_latt_free_mp:
2190 kfree(mp);
2191lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002192 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002193lpfc_handle_latt_err_exit:
2194 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002195 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002196 psli->sli_flag |= LPFC_PROCESS_LA;
2197 control = readl(phba->HCregaddr);
2198 control |= HC_LAINT_ENA;
2199 writel(control, phba->HCregaddr);
2200 readl(phba->HCregaddr); /* flush */
2201
2202 /* Clear Link Attention in HA REG */
2203 writel(HA_LATT, phba->HAregaddr);
2204 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002205 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002206 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002207 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002208
Dick Kennedy372c1872020-06-30 14:50:00 -07002209 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2210 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002211
2212 return;
2213}
2214
James Smarte59058c2008-08-24 21:49:00 -04002215/**
James Smart3621a712009-04-06 18:47:14 -04002216 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002217 * @phba: pointer to lpfc hba data structure.
2218 * @vpd: pointer to the vital product data.
2219 * @len: length of the vital product data in bytes.
2220 *
2221 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2222 * an array of characters. In this routine, the ModelName, ProgramType, and
2223 * ModelDesc, etc. fields of the phba data structure will be populated.
2224 *
2225 * Return codes
2226 * 0 - pointer to the VPD passed in is NULL
2227 * 1 - success
2228 **/
James Smart3772a992009-05-22 14:50:54 -04002229int
James Smart2e0fef82007-06-17 19:56:36 -05002230lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002231{
2232 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002233 int Length;
dea31012005-04-17 16:05:31 -05002234 int i, j;
2235 int finished = 0;
2236 int index = 0;
2237
2238 if (!vpd)
2239 return 0;
2240
2241 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002242 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002243 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002244 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2245 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002246 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002247 switch (vpd[index]) {
2248 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002249 case 0x91:
dea31012005-04-17 16:05:31 -05002250 index += 1;
2251 lenlo = vpd[index];
2252 index += 1;
2253 lenhi = vpd[index];
2254 index += 1;
2255 i = ((((unsigned short)lenhi) << 8) + lenlo);
2256 index += i;
2257 break;
2258 case 0x90:
2259 index += 1;
2260 lenlo = vpd[index];
2261 index += 1;
2262 lenhi = vpd[index];
2263 index += 1;
2264 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002265 if (Length > len - index)
2266 Length = len - index;
dea31012005-04-17 16:05:31 -05002267 while (Length > 0) {
2268 /* Look for Serial Number */
2269 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2270 index += 2;
2271 i = vpd[index];
2272 index += 1;
2273 j = 0;
2274 Length -= (3+i);
2275 while(i--) {
2276 phba->SerialNumber[j++] = vpd[index++];
2277 if (j == 31)
2278 break;
2279 }
2280 phba->SerialNumber[j] = 0;
2281 continue;
2282 }
2283 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2284 phba->vpd_flag |= VPD_MODEL_DESC;
2285 index += 2;
2286 i = vpd[index];
2287 index += 1;
2288 j = 0;
2289 Length -= (3+i);
2290 while(i--) {
2291 phba->ModelDesc[j++] = vpd[index++];
2292 if (j == 255)
2293 break;
2294 }
2295 phba->ModelDesc[j] = 0;
2296 continue;
2297 }
2298 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2299 phba->vpd_flag |= VPD_MODEL_NAME;
2300 index += 2;
2301 i = vpd[index];
2302 index += 1;
2303 j = 0;
2304 Length -= (3+i);
2305 while(i--) {
2306 phba->ModelName[j++] = vpd[index++];
2307 if (j == 79)
2308 break;
2309 }
2310 phba->ModelName[j] = 0;
2311 continue;
2312 }
2313 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2314 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2315 index += 2;
2316 i = vpd[index];
2317 index += 1;
2318 j = 0;
2319 Length -= (3+i);
2320 while(i--) {
2321 phba->ProgramType[j++] = vpd[index++];
2322 if (j == 255)
2323 break;
2324 }
2325 phba->ProgramType[j] = 0;
2326 continue;
2327 }
2328 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2329 phba->vpd_flag |= VPD_PORT;
2330 index += 2;
2331 i = vpd[index];
2332 index += 1;
2333 j = 0;
2334 Length -= (3+i);
2335 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002336 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2337 (phba->sli4_hba.pport_name_sta ==
2338 LPFC_SLI4_PPNAME_GET)) {
2339 j++;
2340 index++;
2341 } else
2342 phba->Port[j++] = vpd[index++];
2343 if (j == 19)
2344 break;
dea31012005-04-17 16:05:31 -05002345 }
James Smartcd1c8302011-10-10 21:33:25 -04002346 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2347 (phba->sli4_hba.pport_name_sta ==
2348 LPFC_SLI4_PPNAME_NON))
2349 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002350 continue;
2351 }
2352 else {
2353 index += 2;
2354 i = vpd[index];
2355 index += 1;
2356 index += i;
2357 Length -= (3 + i);
2358 }
2359 }
2360 finished = 0;
2361 break;
2362 case 0x78:
2363 finished = 1;
2364 break;
2365 default:
2366 index ++;
2367 break;
2368 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002369 }
dea31012005-04-17 16:05:31 -05002370
2371 return(1);
2372}
2373
James Smarte59058c2008-08-24 21:49:00 -04002374/**
James Smart3621a712009-04-06 18:47:14 -04002375 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002376 * @phba: pointer to lpfc hba data structure.
2377 * @mdp: pointer to the data structure to hold the derived model name.
2378 * @descp: pointer to the data structure to hold the derived description.
2379 *
2380 * This routine retrieves HBA's description based on its registered PCI device
2381 * ID. The @descp passed into this function points to an array of 256 chars. It
2382 * shall be returned with the model name, maximum speed, and the host bus type.
2383 * The @mdp passed into this function points to an array of 80 chars. When the
2384 * function returns, the @mdp will be filled with the model name.
2385 **/
dea31012005-04-17 16:05:31 -05002386static void
James Smart2e0fef82007-06-17 19:56:36 -05002387lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002388{
2389 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002390 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002391 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002392 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002393 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002394 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002395 char *name;
2396 char *bus;
2397 char *function;
2398 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002399
2400 if (mdp && mdp[0] != '\0'
2401 && descp && descp[0] != '\0')
2402 return;
2403
James Smartfbd8a6b2018-02-22 08:18:45 -08002404 if (phba->lmt & LMT_64Gb)
2405 max_speed = 64;
2406 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002407 max_speed = 32;
2408 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002409 max_speed = 16;
2410 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002411 max_speed = 10;
2412 else if (phba->lmt & LMT_8Gb)
2413 max_speed = 8;
2414 else if (phba->lmt & LMT_4Gb)
2415 max_speed = 4;
2416 else if (phba->lmt & LMT_2Gb)
2417 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002418 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002419 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002420 else
2421 max_speed = 0;
dea31012005-04-17 16:05:31 -05002422
2423 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002424
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002425 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002426 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002427 m = (typeof(m)){"LP6000", "PCI",
2428 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002429 break;
dea31012005-04-17 16:05:31 -05002430 case PCI_DEVICE_ID_SUPERFLY:
2431 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002432 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002433 else
James Smart12222f42014-05-21 08:05:19 -04002434 m = (typeof(m)){"LP7000E", "PCI", ""};
2435 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002436 break;
2437 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002438 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002439 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002440 break;
2441 case PCI_DEVICE_ID_CENTAUR:
2442 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002443 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002444 else
James Smart12222f42014-05-21 08:05:19 -04002445 m = (typeof(m)){"LP9000", "PCI", ""};
2446 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002447 break;
2448 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002449 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002450 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002451 break;
2452 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002453 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002454 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002455 break;
2456 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002457 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002458 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002459 break;
2460 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002461 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002462 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002463 break;
2464 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002465 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002466 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002467 break;
2468 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002469 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002470 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002471 break;
2472 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002473 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002474 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002475 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002476 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002477 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002478 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002479 break;
2480 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002481 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002482 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002483 break;
2484 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002485 m = (typeof(m)){"LPe1000", "PCIe",
2486 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002487 break;
2488 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002489 m = (typeof(m)){"LPe1000-SP", "PCIe",
2490 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002491 break;
2492 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002493 m = (typeof(m)){"LPe1002-SP", "PCIe",
2494 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002495 break;
dea31012005-04-17 16:05:31 -05002496 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002497 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002498 break;
2499 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002500 m = (typeof(m)){"LP111", "PCI-X2",
2501 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002502 break;
2503 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002504 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002505 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002506 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002507 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002508 break;
2509 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002510 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002511 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002512 break;
dea31012005-04-17 16:05:31 -05002513 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002514 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002515 break;
2516 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002517 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002518 break;
2519 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002520 m = (typeof(m)){"LP101", "PCI-X",
2521 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002522 break;
2523 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002524 m = (typeof(m)){"LP10000-S", "PCI",
2525 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002526 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002527 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002528 m = (typeof(m)){"LP11000-S", "PCI-X2",
2529 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002530 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002531 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002532 m = (typeof(m)){"LPe11000-S", "PCIe",
2533 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002534 break;
James Smartb87eab32007-04-25 09:53:28 -04002535 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002536 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002537 break;
2538 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002539 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002540 break;
2541 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002542 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002543 break;
2544 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002545 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002546 break;
2547 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002548 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002549 break;
2550 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002551 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002552 break;
James Smart84774a42008-08-24 21:50:06 -04002553 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002554 m = (typeof(m)){"LP21000", "PCIe",
2555 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002556 GE = 1;
2557 break;
2558 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002559 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002560 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002561 break;
2562 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002563 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002564 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002565 break;
2566 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002567 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002568 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002569 break;
James Smartda0436e2009-05-22 14:51:39 -04002570 case PCI_DEVICE_ID_TIGERSHARK:
2571 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002572 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002573 break;
James Smarta747c9c2009-11-18 15:41:10 -05002574 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002575 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002576 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2577 break;
2578 case PCI_DEVICE_ID_FALCON:
2579 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2580 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002581 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002582 case PCI_DEVICE_ID_BALIUS:
2583 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002584 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002585 break;
James Smart085c6472010-11-20 23:11:37 -05002586 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002587 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002588 break;
James Smart12222f42014-05-21 08:05:19 -04002589 case PCI_DEVICE_ID_LANCER_FC_VF:
2590 m = (typeof(m)){"LPe16000", "PCIe",
2591 "Obsolete, Unsupported Fibre Channel Adapter"};
2592 break;
James Smart085c6472010-11-20 23:11:37 -05002593 case PCI_DEVICE_ID_LANCER_FCOE:
2594 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002595 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002596 break;
James Smart12222f42014-05-21 08:05:19 -04002597 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2598 oneConnect = 1;
2599 m = (typeof(m)){"OCe15100", "PCIe",
2600 "Obsolete, Unsupported FCoE"};
2601 break;
James Smartd38dd522015-08-31 16:48:17 -04002602 case PCI_DEVICE_ID_LANCER_G6_FC:
2603 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2604 break;
James Smartc238b9b2018-02-22 08:18:44 -08002605 case PCI_DEVICE_ID_LANCER_G7_FC:
2606 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2607 break;
James Smartf449a3d2021-07-22 15:17:16 -07002608 case PCI_DEVICE_ID_LANCER_G7P_FC:
2609 m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
2610 break;
James Smartf8cafd32012-08-03 12:42:51 -04002611 case PCI_DEVICE_ID_SKYHAWK:
2612 case PCI_DEVICE_ID_SKYHAWK_VF:
2613 oneConnect = 1;
2614 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2615 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002616 default:
James Smarta747c9c2009-11-18 15:41:10 -05002617 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002618 break;
dea31012005-04-17 16:05:31 -05002619 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002620
2621 if (mdp && mdp[0] == '\0')
2622 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002623 /*
2624 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002625 * and we put the port number on the end
2626 */
2627 if (descp && descp[0] == '\0') {
2628 if (oneConnect)
2629 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002630 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002631 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002632 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002633 else if (max_speed == 0)
2634 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002635 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002636 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002637 else
2638 snprintf(descp, 255,
2639 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002640 m.name, max_speed, (GE) ? "GE" : "Gb",
2641 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002642 }
dea31012005-04-17 16:05:31 -05002643}
2644
James Smarte59058c2008-08-24 21:49:00 -04002645/**
James Smart3621a712009-04-06 18:47:14 -04002646 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002647 * @phba: pointer to lpfc hba data structure.
2648 * @pring: pointer to a IOCB ring.
2649 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2650 *
2651 * This routine posts a given number of IOCBs with the associated DMA buffer
2652 * descriptors specified by the cnt argument to the given IOCB ring.
2653 *
2654 * Return codes
2655 * The number of IOCBs NOT able to be posted to the IOCB ring.
2656 **/
dea31012005-04-17 16:05:31 -05002657int
James Smart495a7142008-06-14 22:52:59 -04002658lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002659{
2660 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002661 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002662 struct lpfc_dmabuf *mp1, *mp2;
2663
2664 cnt += pring->missbufcnt;
2665
2666 /* While there are buffers to post */
2667 while (cnt > 0) {
2668 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002669 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002670 if (iocb == NULL) {
2671 pring->missbufcnt = cnt;
2672 return cnt;
2673 }
dea31012005-04-17 16:05:31 -05002674 icmd = &iocb->iocb;
2675
2676 /* 2 buffers can be posted per command */
2677 /* Allocate buffer to post */
2678 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2679 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002680 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2681 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002682 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002683 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002684 pring->missbufcnt = cnt;
2685 return cnt;
2686 }
2687
2688 INIT_LIST_HEAD(&mp1->list);
2689 /* Allocate buffer to post */
2690 if (cnt > 1) {
2691 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2692 if (mp2)
2693 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2694 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002695 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002696 kfree(mp2);
dea31012005-04-17 16:05:31 -05002697 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2698 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002699 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002700 pring->missbufcnt = cnt;
2701 return cnt;
2702 }
2703
2704 INIT_LIST_HEAD(&mp2->list);
2705 } else {
2706 mp2 = NULL;
2707 }
2708
2709 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2710 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2711 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2712 icmd->ulpBdeCount = 1;
2713 cnt--;
2714 if (mp2) {
2715 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2716 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2717 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2718 cnt--;
2719 icmd->ulpBdeCount = 2;
2720 }
2721
2722 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2723 icmd->ulpLe = 1;
2724
James Smart3772a992009-05-22 14:50:54 -04002725 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2726 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002727 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2728 kfree(mp1);
2729 cnt++;
2730 if (mp2) {
2731 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2732 kfree(mp2);
2733 cnt++;
2734 }
James Bottomley604a3e32005-10-29 10:28:33 -05002735 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002736 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002737 return cnt;
2738 }
dea31012005-04-17 16:05:31 -05002739 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002740 if (mp2)
dea31012005-04-17 16:05:31 -05002741 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002742 }
2743 pring->missbufcnt = 0;
2744 return 0;
2745}
2746
James Smarte59058c2008-08-24 21:49:00 -04002747/**
James Smart3621a712009-04-06 18:47:14 -04002748 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002749 * @phba: pointer to lpfc hba data structure.
2750 *
2751 * This routine posts initial receive IOCB buffers to the ELS ring. The
2752 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002753 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002754 *
2755 * Return codes
2756 * 0 - success (currently always success)
2757 **/
dea31012005-04-17 16:05:31 -05002758static int
James Smart2e0fef82007-06-17 19:56:36 -05002759lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002760{
2761 struct lpfc_sli *psli = &phba->sli;
2762
2763 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002764 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002765 /* Ring 2 - FCP no buffers needed */
2766
2767 return 0;
2768}
2769
2770#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2771
James Smarte59058c2008-08-24 21:49:00 -04002772/**
James Smart3621a712009-04-06 18:47:14 -04002773 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002774 * @HashResultPointer: pointer to an array as hash table.
2775 *
2776 * This routine sets up the initial values to the array of hash table entries
2777 * for the LC HBAs.
2778 **/
dea31012005-04-17 16:05:31 -05002779static void
2780lpfc_sha_init(uint32_t * HashResultPointer)
2781{
2782 HashResultPointer[0] = 0x67452301;
2783 HashResultPointer[1] = 0xEFCDAB89;
2784 HashResultPointer[2] = 0x98BADCFE;
2785 HashResultPointer[3] = 0x10325476;
2786 HashResultPointer[4] = 0xC3D2E1F0;
2787}
2788
James Smarte59058c2008-08-24 21:49:00 -04002789/**
James Smart3621a712009-04-06 18:47:14 -04002790 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002791 * @HashResultPointer: pointer to an initial/result hash table.
2792 * @HashWorkingPointer: pointer to an working hash table.
2793 *
2794 * This routine iterates an initial hash table pointed by @HashResultPointer
2795 * with the values from the working hash table pointeed by @HashWorkingPointer.
2796 * The results are putting back to the initial hash table, returned through
2797 * the @HashResultPointer as the result hash table.
2798 **/
dea31012005-04-17 16:05:31 -05002799static void
2800lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2801{
2802 int t;
2803 uint32_t TEMP;
2804 uint32_t A, B, C, D, E;
2805 t = 16;
2806 do {
2807 HashWorkingPointer[t] =
2808 S(1,
2809 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2810 8] ^
2811 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2812 } while (++t <= 79);
2813 t = 0;
2814 A = HashResultPointer[0];
2815 B = HashResultPointer[1];
2816 C = HashResultPointer[2];
2817 D = HashResultPointer[3];
2818 E = HashResultPointer[4];
2819
2820 do {
2821 if (t < 20) {
2822 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2823 } else if (t < 40) {
2824 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2825 } else if (t < 60) {
2826 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2827 } else {
2828 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2829 }
2830 TEMP += S(5, A) + E + HashWorkingPointer[t];
2831 E = D;
2832 D = C;
2833 C = S(30, B);
2834 B = A;
2835 A = TEMP;
2836 } while (++t <= 79);
2837
2838 HashResultPointer[0] += A;
2839 HashResultPointer[1] += B;
2840 HashResultPointer[2] += C;
2841 HashResultPointer[3] += D;
2842 HashResultPointer[4] += E;
2843
2844}
2845
James Smarte59058c2008-08-24 21:49:00 -04002846/**
James Smart3621a712009-04-06 18:47:14 -04002847 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002848 * @RandomChallenge: pointer to the entry of host challenge random number array.
2849 * @HashWorking: pointer to the entry of the working hash array.
2850 *
2851 * This routine calculates the working hash array referred by @HashWorking
2852 * from the challenge random numbers associated with the host, referred by
2853 * @RandomChallenge. The result is put into the entry of the working hash
2854 * array and returned by reference through @HashWorking.
2855 **/
dea31012005-04-17 16:05:31 -05002856static void
2857lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2858{
2859 *HashWorking = (*RandomChallenge ^ *HashWorking);
2860}
2861
James Smarte59058c2008-08-24 21:49:00 -04002862/**
James Smart3621a712009-04-06 18:47:14 -04002863 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002864 * @phba: pointer to lpfc hba data structure.
2865 * @hbainit: pointer to an array of unsigned 32-bit integers.
2866 *
2867 * This routine performs the special handling for LC HBA initialization.
2868 **/
dea31012005-04-17 16:05:31 -05002869void
2870lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2871{
2872 int t;
2873 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002874 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002875
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002876 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002877 if (!HashWorking)
2878 return;
2879
dea31012005-04-17 16:05:31 -05002880 HashWorking[0] = HashWorking[78] = *pwwnn++;
2881 HashWorking[1] = HashWorking[79] = *pwwnn;
2882
2883 for (t = 0; t < 7; t++)
2884 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2885
2886 lpfc_sha_init(hbainit);
2887 lpfc_sha_iterate(hbainit, HashWorking);
2888 kfree(HashWorking);
2889}
2890
James Smarte59058c2008-08-24 21:49:00 -04002891/**
James Smart3621a712009-04-06 18:47:14 -04002892 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002893 * @vport: pointer to a virtual N_Port data structure.
2894 *
2895 * This routine performs the necessary cleanups before deleting the @vport.
2896 * It invokes the discovery state machine to perform necessary state
2897 * transitions and to release the ndlps associated with the @vport. Note,
2898 * the physical port is treated as @vport 0.
2899 **/
James Smart87af33f2007-10-27 13:37:43 -04002900void
James Smart2e0fef82007-06-17 19:56:36 -05002901lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002902{
James Smart87af33f2007-10-27 13:37:43 -04002903 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002904 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002905 int i = 0;
dea31012005-04-17 16:05:31 -05002906
James Smart87af33f2007-10-27 13:37:43 -04002907 if (phba->link_state > LPFC_LINK_DOWN)
2908 lpfc_port_link_failure(vport);
2909
Gaurav Srivastava5e633302021-06-08 10:05:49 +05302910 /* Clean up VMID resources */
2911 if (lpfc_is_vmid_enabled(phba))
2912 lpfc_vmid_vport_cleanup(vport);
2913
James Smart87af33f2007-10-27 13:37:43 -04002914 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart58da1ff2008-04-07 10:15:56 -04002915 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2916 ndlp->nlp_DID == Fabric_DID) {
2917 /* Just free up ndlp with Fabric_DID for vports */
2918 lpfc_nlp_put(ndlp);
2919 continue;
2920 }
2921
James Smarta70e63e2020-11-15 11:26:38 -08002922 if (ndlp->nlp_DID == Fabric_Cntl_DID &&
2923 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
James Smarteff4a012012-01-18 16:25:25 -05002924 lpfc_nlp_put(ndlp);
2925 continue;
2926 }
2927
James Smarte9b11082020-11-15 11:26:33 -08002928 /* Fabric Ports not in UNMAPPED state are cleaned up in the
2929 * DEVICE_RM event.
2930 */
2931 if (ndlp->nlp_type & NLP_FABRIC &&
2932 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
James Smart87af33f2007-10-27 13:37:43 -04002933 lpfc_disc_state_machine(vport, ndlp, NULL,
2934 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002935
James Smarte9b11082020-11-15 11:26:33 -08002936 if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
2937 lpfc_disc_state_machine(vport, ndlp, NULL,
2938 NLP_EVT_DEVICE_RM);
James Smart87af33f2007-10-27 13:37:43 -04002939 }
2940
James Smarta8adb832007-10-27 13:37:53 -04002941 /* At this point, ALL ndlp's should be gone
2942 * because of the previous NLP_EVT_DEVICE_RM.
2943 * Lets wait for this to happen, if needed.
2944 */
James Smart87af33f2007-10-27 13:37:43 -04002945 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002946 if (i++ > 3000) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002947 lpfc_printf_vlog(vport, KERN_ERR,
2948 LOG_TRACE_EVENT,
James Smarta8adb832007-10-27 13:37:53 -04002949 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002950 list_for_each_entry_safe(ndlp, next_ndlp,
2951 &vport->fc_nodes, nlp_listp) {
2952 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
James Smarte9b11082020-11-15 11:26:33 -08002953 LOG_TRACE_EVENT,
2954 "0282 did:x%x ndlp:x%px "
2955 "refcnt:%d xflags x%x nflag x%x\n",
2956 ndlp->nlp_DID, (void *)ndlp,
2957 kref_read(&ndlp->kref),
2958 ndlp->fc4_xpt_flags,
2959 ndlp->nlp_flag);
James Smarte47c9092008-02-08 18:49:26 -05002960 }
James Smarta8adb832007-10-27 13:37:53 -04002961 break;
James Smart87af33f2007-10-27 13:37:43 -04002962 }
James Smarta8adb832007-10-27 13:37:53 -04002963
2964 /* Wait for any activity on ndlps to settle */
2965 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002966 }
James Smart1151e3e2011-02-16 12:39:35 -05002967 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002968}
2969
James Smarte59058c2008-08-24 21:49:00 -04002970/**
James Smart3621a712009-04-06 18:47:14 -04002971 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002972 * @vport: pointer to a virtual N_Port data structure.
2973 *
2974 * This routine stops all the timers associated with a @vport. This function
2975 * is invoked before disabling or deleting a @vport. Note that the physical
2976 * port is treated as @vport 0.
2977 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002978void
2979lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002980{
James Smart92d7f7b2007-06-17 19:56:38 -05002981 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002982 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002983 lpfc_can_disctmo(vport);
2984 return;
dea31012005-04-17 16:05:31 -05002985}
2986
James Smarte59058c2008-08-24 21:49:00 -04002987/**
James Smartecfd03c2010-02-12 14:41:27 -05002988 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2989 * @phba: pointer to lpfc hba data structure.
2990 *
2991 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2992 * caller of this routine should already hold the host lock.
2993 **/
2994void
2995__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2996{
James Smart5ac6b302010-10-22 11:05:36 -04002997 /* Clear pending FCF rediscovery wait flag */
2998 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2999
James Smartecfd03c2010-02-12 14:41:27 -05003000 /* Now, try to stop the timer */
3001 del_timer(&phba->fcf.redisc_wait);
3002}
3003
3004/**
3005 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
3006 * @phba: pointer to lpfc hba data structure.
3007 *
3008 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
3009 * checks whether the FCF rediscovery wait timer is pending with the host
3010 * lock held before proceeding with disabling the timer and clearing the
3011 * wait timer pendig flag.
3012 **/
3013void
3014lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
3015{
3016 spin_lock_irq(&phba->hbalock);
3017 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3018 /* FCF rediscovery timer already fired or stopped */
3019 spin_unlock_irq(&phba->hbalock);
3020 return;
3021 }
3022 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04003023 /* Clear failover in progress flags */
3024 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05003025 spin_unlock_irq(&phba->hbalock);
3026}
3027
3028/**
James Smart02243832021-08-16 09:28:54 -07003029 * lpfc_cmf_stop - Stop CMF processing
3030 * @phba: pointer to lpfc hba data structure.
3031 *
3032 * This is called when the link goes down or if CMF mode is turned OFF.
3033 * It is also called when going offline or unloaded just before the
3034 * congestion info buffer is unregistered.
3035 **/
3036void
3037lpfc_cmf_stop(struct lpfc_hba *phba)
3038{
3039 int cpu;
3040 struct lpfc_cgn_stat *cgs;
3041
3042 /* We only do something if CMF is enabled */
3043 if (!phba->sli4_hba.pc_sli4_params.cmf)
3044 return;
3045
3046 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3047 "6221 Stop CMF / Cancel Timer\n");
3048
3049 /* Cancel the CMF timer */
3050 hrtimer_cancel(&phba->cmf_timer);
3051
3052 /* Zero CMF counters */
3053 atomic_set(&phba->cmf_busy, 0);
3054 for_each_present_cpu(cpu) {
3055 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3056 atomic64_set(&cgs->total_bytes, 0);
3057 atomic64_set(&cgs->rcv_bytes, 0);
3058 atomic_set(&cgs->rx_io_cnt, 0);
3059 atomic64_set(&cgs->rx_latency, 0);
3060 }
3061 atomic_set(&phba->cmf_bw_wait, 0);
3062
3063 /* Resume any blocked IO - Queue unblock on workqueue */
3064 queue_work(phba->wq, &phba->unblock_request_work);
3065}
3066
3067static inline uint64_t
3068lpfc_get_max_line_rate(struct lpfc_hba *phba)
3069{
3070 uint64_t rate = lpfc_sli_port_speed_get(phba);
3071
3072 return ((((unsigned long)rate) * 1024 * 1024) / 10);
3073}
3074
3075void
3076lpfc_cmf_signal_init(struct lpfc_hba *phba)
3077{
3078 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3079 "6223 Signal CMF init\n");
3080
3081 /* Use the new fc_linkspeed to recalculate */
3082 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
3083 phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
3084 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
3085 phba->cmf_interval_rate, 1000);
3086 phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
3087
3088 /* This is a signal to firmware to sync up CMF BW with link speed */
3089 lpfc_issue_cmf_sync_wqe(phba, 0, 0);
3090}
3091
3092/**
3093 * lpfc_cmf_start - Start CMF processing
3094 * @phba: pointer to lpfc hba data structure.
3095 *
3096 * This is called when the link comes up or if CMF mode is turned OFF
3097 * to Monitor or Managed.
3098 **/
3099void
3100lpfc_cmf_start(struct lpfc_hba *phba)
3101{
3102 struct lpfc_cgn_stat *cgs;
3103 int cpu;
3104
3105 /* We only do something if CMF is enabled */
3106 if (!phba->sli4_hba.pc_sli4_params.cmf ||
3107 phba->cmf_active_mode == LPFC_CFG_OFF)
3108 return;
3109
3110 /* Reinitialize congestion buffer info */
3111 lpfc_init_congestion_buf(phba);
3112
3113 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
3114 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
3115 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
3116 atomic_set(&phba->cgn_sync_warn_cnt, 0);
3117
3118 atomic_set(&phba->cmf_busy, 0);
3119 for_each_present_cpu(cpu) {
3120 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
3121 atomic64_set(&cgs->total_bytes, 0);
3122 atomic64_set(&cgs->rcv_bytes, 0);
3123 atomic_set(&cgs->rx_io_cnt, 0);
3124 atomic64_set(&cgs->rx_latency, 0);
3125 }
3126 phba->cmf_latency.tv_sec = 0;
3127 phba->cmf_latency.tv_nsec = 0;
3128
3129 lpfc_cmf_signal_init(phba);
3130
3131 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
3132 "6222 Start CMF / Timer\n");
3133
3134 phba->cmf_timer_cnt = 0;
3135 hrtimer_start(&phba->cmf_timer,
3136 ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
3137 HRTIMER_MODE_REL);
3138 /* Setup for latency check in IO cmpl routines */
3139 ktime_get_real_ts64(&phba->cmf_latency);
3140
3141 atomic_set(&phba->cmf_bw_wait, 0);
3142 atomic_set(&phba->cmf_stop_io, 0);
3143}
3144
3145/**
James Smart3772a992009-05-22 14:50:54 -04003146 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04003147 * @phba: pointer to lpfc hba data structure.
3148 *
3149 * This routine stops all the timers associated with a HBA. This function is
3150 * invoked before either putting a HBA offline or unloading the driver.
3151 **/
James Smart3772a992009-05-22 14:50:54 -04003152void
3153lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003154{
James Smartcdb42be2019-01-28 11:14:21 -08003155 if (phba->pport)
3156 lpfc_stop_vport_timers(phba->pport);
James Smart32517fc2019-01-28 11:14:33 -08003157 cancel_delayed_work_sync(&phba->eq_delay_work);
Dick Kennedy317aeb82020-06-30 14:49:59 -07003158 cancel_delayed_work_sync(&phba->idle_stat_delay_work);
James Smart2e0fef82007-06-17 19:56:36 -05003159 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05003160 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04003161 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04003162 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05003163 if (phba->sli_rev == LPFC_SLI_REV4) {
3164 del_timer_sync(&phba->rrq_tmr);
3165 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
3166 }
James Smarta22d73b2021-01-04 10:02:38 -08003167 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
James Smart3772a992009-05-22 14:50:54 -04003168
3169 switch (phba->pci_dev_grp) {
3170 case LPFC_PCI_DEV_LP:
3171 /* Stop any LightPulse device specific driver timers */
3172 del_timer_sync(&phba->fcp_poll_timer);
3173 break;
3174 case LPFC_PCI_DEV_OC:
Paul Walmsleycc0e5f12019-07-11 20:52:33 -07003175 /* Stop any OneConnect device specific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05003176 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04003177 break;
3178 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07003179 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -04003180 "0297 Invalid device group (x%x)\n",
3181 phba->pci_dev_grp);
3182 break;
3183 }
James Smart2e0fef82007-06-17 19:56:36 -05003184 return;
dea31012005-04-17 16:05:31 -05003185}
3186
James Smarte59058c2008-08-24 21:49:00 -04003187/**
James Smart3621a712009-04-06 18:47:14 -04003188 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04003189 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01003190 * @mbx_action: flag for mailbox no wait action.
James Smarte59058c2008-08-24 21:49:00 -04003191 *
3192 * This routine marks a HBA's management interface as blocked. Once the HBA's
3193 * management interface is marked as blocked, all the user space access to
3194 * the HBA, whether they are from sysfs interface or libdfc interface will
3195 * all be blocked. The HBA is set to block the management interface when the
3196 * driver prepares the HBA interface for online or offline.
3197 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01003198static void
James Smart618a5232012-06-12 13:54:36 -04003199lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01003200{
3201 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04003202 uint8_t actcmd = MBX_HEARTBEAT;
3203 unsigned long timeout;
3204
Adrian Bunka6ababd2007-11-05 18:07:33 +01003205 spin_lock_irqsave(&phba->hbalock, iflag);
3206 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04003207 spin_unlock_irqrestore(&phba->hbalock, iflag);
3208 if (mbx_action == LPFC_MBX_NO_WAIT)
3209 return;
3210 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3211 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003212 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04003213 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04003214 /* Determine how long we might wait for the active mailbox
3215 * command to be gracefully completed by firmware.
3216 */
3217 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3218 phba->sli.mbox_active) * 1000) + jiffies;
3219 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003220 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003221
James Smart6e7288d2010-06-07 15:23:35 -04003222 /* Wait for the outstnading mailbox command to complete */
3223 while (phba->sli.mbox_active) {
3224 /* Check active mailbox complete status every 2ms */
3225 msleep(2);
3226 if (time_after(jiffies, timeout)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003227 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3228 "2813 Mgmt IO is Blocked %x "
3229 "- mbox cmd %x still active\n",
3230 phba->sli.sli_flag, actcmd);
James Smart6e7288d2010-06-07 15:23:35 -04003231 break;
3232 }
3233 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003234}
3235
James Smarte59058c2008-08-24 21:49:00 -04003236/**
James Smart6b5151f2012-01-18 16:24:06 -05003237 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3238 * @phba: pointer to lpfc hba data structure.
3239 *
3240 * Allocate RPIs for all active remote nodes. This is needed whenever
3241 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3242 * is to fixup the temporary rpi assignments.
3243 **/
3244void
3245lpfc_sli4_node_prep(struct lpfc_hba *phba)
3246{
3247 struct lpfc_nodelist *ndlp, *next_ndlp;
3248 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003249 int i, rpi;
James Smart6b5151f2012-01-18 16:24:06 -05003250
3251 if (phba->sli_rev != LPFC_SLI_REV4)
3252 return;
3253
3254 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003255 if (vports == NULL)
3256 return;
James Smart6b5151f2012-01-18 16:24:06 -05003257
James Smart9d3d3402017-04-21 16:05:00 -07003258 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3259 if (vports[i]->load_flag & FC_UNLOADING)
3260 continue;
3261
3262 list_for_each_entry_safe(ndlp, next_ndlp,
3263 &vports[i]->fc_nodes,
3264 nlp_listp) {
James Smart9d3d3402017-04-21 16:05:00 -07003265 rpi = lpfc_sli4_alloc_rpi(phba);
3266 if (rpi == LPFC_RPI_ALLOC_ERROR) {
James Smart307e3382020-11-15 11:26:30 -08003267 /* TODO print log? */
James Smart9d3d3402017-04-21 16:05:00 -07003268 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003269 }
James Smart9d3d3402017-04-21 16:05:00 -07003270 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07003271 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
3272 LOG_NODE | LOG_DISCOVERY,
3273 "0009 Assign RPI x%x to ndlp x%px "
James Smart307e3382020-11-15 11:26:30 -08003274 "DID:x%06x flg:x%x\n",
James Smart0f154222019-09-21 20:58:52 -07003275 ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
James Smart307e3382020-11-15 11:26:30 -08003276 ndlp->nlp_flag);
James Smart6b5151f2012-01-18 16:24:06 -05003277 }
3278 }
3279 lpfc_destroy_vport_work_array(phba, vports);
3280}
3281
3282/**
James Smartc4908502019-01-28 11:14:28 -08003283 * lpfc_create_expedite_pool - create expedite pool
3284 * @phba: pointer to lpfc hba data structure.
3285 *
3286 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3287 * to expedite pool. Mark them as expedite.
3288 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003289static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003290{
3291 struct lpfc_sli4_hdw_queue *qp;
3292 struct lpfc_io_buf *lpfc_ncmd;
3293 struct lpfc_io_buf *lpfc_ncmd_next;
3294 struct lpfc_epd_pool *epd_pool;
3295 unsigned long iflag;
3296
3297 epd_pool = &phba->epd_pool;
3298 qp = &phba->sli4_hba.hdwq[0];
3299
3300 spin_lock_init(&epd_pool->lock);
3301 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3302 spin_lock(&epd_pool->lock);
3303 INIT_LIST_HEAD(&epd_pool->list);
3304 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3305 &qp->lpfc_io_buf_list_put, list) {
3306 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3307 lpfc_ncmd->expedite = true;
3308 qp->put_io_bufs--;
3309 epd_pool->count++;
3310 if (epd_pool->count >= XRI_BATCH)
3311 break;
3312 }
3313 spin_unlock(&epd_pool->lock);
3314 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3315}
3316
3317/**
3318 * lpfc_destroy_expedite_pool - destroy expedite pool
3319 * @phba: pointer to lpfc hba data structure.
3320 *
3321 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3322 * of HWQ 0. Clear the mark.
3323 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003324static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003325{
3326 struct lpfc_sli4_hdw_queue *qp;
3327 struct lpfc_io_buf *lpfc_ncmd;
3328 struct lpfc_io_buf *lpfc_ncmd_next;
3329 struct lpfc_epd_pool *epd_pool;
3330 unsigned long iflag;
3331
3332 epd_pool = &phba->epd_pool;
3333 qp = &phba->sli4_hba.hdwq[0];
3334
3335 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3336 spin_lock(&epd_pool->lock);
3337 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3338 &epd_pool->list, list) {
3339 list_move_tail(&lpfc_ncmd->list,
3340 &qp->lpfc_io_buf_list_put);
3341 lpfc_ncmd->flags = false;
3342 qp->put_io_bufs++;
3343 epd_pool->count--;
3344 }
3345 spin_unlock(&epd_pool->lock);
3346 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3347}
3348
3349/**
3350 * lpfc_create_multixri_pools - create multi-XRI pools
3351 * @phba: pointer to lpfc hba data structure.
3352 *
3353 * This routine initialize public, private per HWQ. Then, move XRIs from
3354 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3355 * Initialized.
3356 **/
3357void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3358{
3359 u32 i, j;
3360 u32 hwq_count;
3361 u32 count_per_hwq;
3362 struct lpfc_io_buf *lpfc_ncmd;
3363 struct lpfc_io_buf *lpfc_ncmd_next;
3364 unsigned long iflag;
3365 struct lpfc_sli4_hdw_queue *qp;
3366 struct lpfc_multixri_pool *multixri_pool;
3367 struct lpfc_pbl_pool *pbl_pool;
3368 struct lpfc_pvt_pool *pvt_pool;
3369
3370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3371 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3372 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3373 phba->sli4_hba.io_xri_cnt);
3374
3375 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3376 lpfc_create_expedite_pool(phba);
3377
3378 hwq_count = phba->cfg_hdw_queue;
3379 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3380
3381 for (i = 0; i < hwq_count; i++) {
3382 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3383
3384 if (!multixri_pool) {
3385 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3386 "1238 Failed to allocate memory for "
3387 "multixri_pool\n");
3388
3389 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3390 lpfc_destroy_expedite_pool(phba);
3391
3392 j = 0;
3393 while (j < i) {
3394 qp = &phba->sli4_hba.hdwq[j];
3395 kfree(qp->p_multixri_pool);
3396 j++;
3397 }
3398 phba->cfg_xri_rebalancing = 0;
3399 return;
3400 }
3401
3402 qp = &phba->sli4_hba.hdwq[i];
3403 qp->p_multixri_pool = multixri_pool;
3404
3405 multixri_pool->xri_limit = count_per_hwq;
3406 multixri_pool->rrb_next_hwqid = i;
3407
3408 /* Deal with public free xri pool */
3409 pbl_pool = &multixri_pool->pbl_pool;
3410 spin_lock_init(&pbl_pool->lock);
3411 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3412 spin_lock(&pbl_pool->lock);
3413 INIT_LIST_HEAD(&pbl_pool->list);
3414 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3415 &qp->lpfc_io_buf_list_put, list) {
3416 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3417 qp->put_io_bufs--;
3418 pbl_pool->count++;
3419 }
3420 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3421 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3422 pbl_pool->count, i);
3423 spin_unlock(&pbl_pool->lock);
3424 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3425
3426 /* Deal with private free xri pool */
3427 pvt_pool = &multixri_pool->pvt_pool;
3428 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3429 pvt_pool->low_watermark = XRI_BATCH;
3430 spin_lock_init(&pvt_pool->lock);
3431 spin_lock_irqsave(&pvt_pool->lock, iflag);
3432 INIT_LIST_HEAD(&pvt_pool->list);
3433 pvt_pool->count = 0;
3434 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3435 }
3436}
3437
3438/**
3439 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3440 * @phba: pointer to lpfc hba data structure.
3441 *
3442 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3443 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003444static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003445{
3446 u32 i;
3447 u32 hwq_count;
3448 struct lpfc_io_buf *lpfc_ncmd;
3449 struct lpfc_io_buf *lpfc_ncmd_next;
3450 unsigned long iflag;
3451 struct lpfc_sli4_hdw_queue *qp;
3452 struct lpfc_multixri_pool *multixri_pool;
3453 struct lpfc_pbl_pool *pbl_pool;
3454 struct lpfc_pvt_pool *pvt_pool;
3455
3456 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3457 lpfc_destroy_expedite_pool(phba);
3458
James Smartc00f62e2019-08-14 16:57:11 -07003459 if (!(phba->pport->load_flag & FC_UNLOADING))
3460 lpfc_sli_flush_io_rings(phba);
James Smartc66a9192019-03-12 16:30:19 -07003461
James Smartc4908502019-01-28 11:14:28 -08003462 hwq_count = phba->cfg_hdw_queue;
3463
3464 for (i = 0; i < hwq_count; i++) {
3465 qp = &phba->sli4_hba.hdwq[i];
3466 multixri_pool = qp->p_multixri_pool;
3467 if (!multixri_pool)
3468 continue;
3469
3470 qp->p_multixri_pool = NULL;
3471
3472 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3473
3474 /* Deal with public free xri pool */
3475 pbl_pool = &multixri_pool->pbl_pool;
3476 spin_lock(&pbl_pool->lock);
3477
3478 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3479 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3480 pbl_pool->count, i);
3481
3482 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3483 &pbl_pool->list, list) {
3484 list_move_tail(&lpfc_ncmd->list,
3485 &qp->lpfc_io_buf_list_put);
3486 qp->put_io_bufs++;
3487 pbl_pool->count--;
3488 }
3489
3490 INIT_LIST_HEAD(&pbl_pool->list);
3491 pbl_pool->count = 0;
3492
3493 spin_unlock(&pbl_pool->lock);
3494
3495 /* Deal with private free xri pool */
3496 pvt_pool = &multixri_pool->pvt_pool;
3497 spin_lock(&pvt_pool->lock);
3498
3499 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3500 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3501 pvt_pool->count, i);
3502
3503 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3504 &pvt_pool->list, list) {
3505 list_move_tail(&lpfc_ncmd->list,
3506 &qp->lpfc_io_buf_list_put);
3507 qp->put_io_bufs++;
3508 pvt_pool->count--;
3509 }
3510
3511 INIT_LIST_HEAD(&pvt_pool->list);
3512 pvt_pool->count = 0;
3513
3514 spin_unlock(&pvt_pool->lock);
3515 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3516
3517 kfree(multixri_pool);
3518 }
3519}
3520
3521/**
James Smart3621a712009-04-06 18:47:14 -04003522 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003523 * @phba: pointer to lpfc hba data structure.
3524 *
3525 * This routine initializes the HBA and brings a HBA online. During this
3526 * process, the management interface is blocked to prevent user space access
3527 * to the HBA interfering with the driver initialization.
3528 *
3529 * Return codes
3530 * 0 - successful
3531 * 1 - failed
3532 **/
dea31012005-04-17 16:05:31 -05003533int
James Smart2e0fef82007-06-17 19:56:36 -05003534lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003535{
Julia Lawall372bd282008-12-16 16:15:08 +01003536 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003537 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003538 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003539 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003540
dea31012005-04-17 16:05:31 -05003541 if (!phba)
3542 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003543 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003544
James Smart2e0fef82007-06-17 19:56:36 -05003545 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003546 return 0;
3547
James Smarted957682007-06-17 19:56:37 -05003548 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003549 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003550
James Smart618a5232012-06-12 13:54:36 -04003551 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003552
James Smartda0436e2009-05-22 14:51:39 -04003553 if (phba->sli_rev == LPFC_SLI_REV4) {
3554 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3555 lpfc_unblock_mgmt_io(phba);
3556 return 1;
3557 }
James Smart16a3a202013-04-17 20:14:38 -04003558 spin_lock_irq(&phba->hbalock);
3559 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3560 vpis_cleared = true;
3561 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003562
3563 /* Reestablish the local initiator port.
3564 * The offline process destroyed the previous lport.
3565 */
3566 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3567 !phba->nvmet_support) {
3568 error = lpfc_nvme_create_localport(phba->pport);
3569 if (error)
Dick Kennedy372c1872020-06-30 14:50:00 -07003570 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedya145fda2017-08-23 16:55:44 -07003571 "6132 NVME restore reg failed "
3572 "on nvmei error x%x\n", error);
3573 }
James Smartda0436e2009-05-22 14:51:39 -04003574 } else {
James Smart895427b2017-02-12 13:52:30 -08003575 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003576 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3577 lpfc_unblock_mgmt_io(phba);
3578 return 1;
3579 }
James Smart46fa3112007-04-25 09:51:45 -04003580 }
dea31012005-04-17 16:05:31 -05003581
James Smart549e55c2007-08-02 11:09:51 -04003582 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003583 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003584 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003585 struct Scsi_Host *shost;
3586 shost = lpfc_shost_from_vport(vports[i]);
3587 spin_lock_irq(shost->host_lock);
3588 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3589 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3590 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003591 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003592 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003593 if ((vpis_cleared) &&
3594 (vports[i]->port_type !=
3595 LPFC_PHYSICAL_PORT))
3596 vports[i]->vpi = 0;
3597 }
James Smart549e55c2007-08-02 11:09:51 -04003598 spin_unlock_irq(shost->host_lock);
3599 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003600 }
3601 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003602
James Smartc4908502019-01-28 11:14:28 -08003603 if (phba->cfg_xri_rebalancing)
3604 lpfc_create_multixri_pools(phba);
3605
James Smart93a4d6f2019-11-04 16:57:05 -08003606 lpfc_cpuhp_add(phba);
3607
James Smart46fa3112007-04-25 09:51:45 -04003608 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003609 return 0;
3610}
3611
James Smarte59058c2008-08-24 21:49:00 -04003612/**
James Smart3621a712009-04-06 18:47:14 -04003613 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003614 * @phba: pointer to lpfc hba data structure.
3615 *
3616 * This routine marks a HBA's management interface as not blocked. Once the
3617 * HBA's management interface is marked as not blocked, all the user space
3618 * access to the HBA, whether they are from sysfs interface or libdfc
3619 * interface will be allowed. The HBA is set to block the management interface
3620 * when the driver prepares the HBA interface for online or offline and then
3621 * set to unblock the management interface afterwards.
3622 **/
James Smart46fa3112007-04-25 09:51:45 -04003623void
James Smart46fa3112007-04-25 09:51:45 -04003624lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3625{
3626 unsigned long iflag;
3627
James Smart2e0fef82007-06-17 19:56:36 -05003628 spin_lock_irqsave(&phba->hbalock, iflag);
3629 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3630 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003631}
3632
James Smarte59058c2008-08-24 21:49:00 -04003633/**
James Smart3621a712009-04-06 18:47:14 -04003634 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003635 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01003636 * @mbx_action: flag for mailbox shutdown action.
James Smarte59058c2008-08-24 21:49:00 -04003637 *
3638 * This routine is invoked to prepare a HBA to be brought offline. It performs
3639 * unregistration login to all the nodes on all vports and flushes the mailbox
3640 * queue to make it ready to be brought offline.
3641 **/
James Smart46fa3112007-04-25 09:51:45 -04003642void
James Smart618a5232012-06-12 13:54:36 -04003643lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003644{
James Smart2e0fef82007-06-17 19:56:36 -05003645 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003646 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003647 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003648 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003649 int i;
James Smart25ac2c972021-09-10 16:31:54 -07003650 int offline = 0;
dea31012005-04-17 16:05:31 -05003651
James Smart2e0fef82007-06-17 19:56:36 -05003652 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003653 return;
dea31012005-04-17 16:05:31 -05003654
James Smart618a5232012-06-12 13:54:36 -04003655 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003656
3657 lpfc_linkdown(phba);
3658
James Smart25ac2c972021-09-10 16:31:54 -07003659 offline = pci_channel_offline(phba->pcidev);
3660
James Smart87af33f2007-10-27 13:37:43 -04003661 /* Issue an unreg_login to all nodes on all vports */
3662 vports = lpfc_create_vport_work_array(phba);
3663 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003664 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003665 if (vports[i]->load_flag & FC_UNLOADING)
3666 continue;
James Smart72100cc2010-02-12 14:43:01 -05003667 shost = lpfc_shost_from_vport(vports[i]);
3668 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003669 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003670 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3671 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003672 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003673
James Smart87af33f2007-10-27 13:37:43 -04003674 shost = lpfc_shost_from_vport(vports[i]);
3675 list_for_each_entry_safe(ndlp, next_ndlp,
3676 &vports[i]->fc_nodes,
3677 nlp_listp) {
James Smart0f154222019-09-21 20:58:52 -07003678
James Smartc6adba12020-11-15 11:26:34 -08003679 spin_lock_irq(&ndlp->lock);
James Smart87af33f2007-10-27 13:37:43 -04003680 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smartc6adba12020-11-15 11:26:34 -08003681 spin_unlock_irq(&ndlp->lock);
James Smartaffbe242021-07-07 11:43:42 -07003682
James Smart25ac2c972021-09-10 16:31:54 -07003683 if (offline) {
3684 spin_lock_irq(&ndlp->lock);
3685 ndlp->nlp_flag &= ~(NLP_UNREG_INP |
3686 NLP_RPI_REGISTERED);
3687 spin_unlock_irq(&ndlp->lock);
3688 } else {
3689 lpfc_unreg_rpi(vports[i], ndlp);
3690 }
James Smart6b5151f2012-01-18 16:24:06 -05003691 /*
3692 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003693 * RPI. Get a new RPI when the adapter port
3694 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003695 */
James Smartbe6bb942015-04-07 15:07:22 -04003696 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smarte9b11082020-11-15 11:26:33 -08003697 lpfc_printf_vlog(vports[i], KERN_INFO,
James Smart0f154222019-09-21 20:58:52 -07003698 LOG_NODE | LOG_DISCOVERY,
3699 "0011 Free RPI x%x on "
James Smartf1156122021-04-11 18:31:24 -07003700 "ndlp: x%px did x%x\n",
James Smart0f154222019-09-21 20:58:52 -07003701 ndlp->nlp_rpi, ndlp,
James Smart307e3382020-11-15 11:26:30 -08003702 ndlp->nlp_DID);
James Smart6b5151f2012-01-18 16:24:06 -05003703 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart0f154222019-09-21 20:58:52 -07003704 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smartbe6bb942015-04-07 15:07:22 -04003705 }
James Smart307e3382020-11-15 11:26:30 -08003706
3707 if (ndlp->nlp_type & NLP_FABRIC) {
3708 lpfc_disc_state_machine(vports[i], ndlp,
3709 NULL, NLP_EVT_DEVICE_RECOVERY);
James Smarte9b11082020-11-15 11:26:33 -08003710
3711 /* Don't remove the node unless the
3712 * has been unregistered with the
3713 * transport. If so, let dev_loss
3714 * take care of the node.
3715 */
3716 if (!(ndlp->fc4_xpt_flags &
3717 (NVME_XPT_REGD | SCSI_XPT_REGD)))
3718 lpfc_disc_state_machine
3719 (vports[i], ndlp,
3720 NULL,
3721 NLP_EVT_DEVICE_RM);
James Smart307e3382020-11-15 11:26:30 -08003722 }
James Smart87af33f2007-10-27 13:37:43 -04003723 }
3724 }
3725 }
James Smart09372822008-01-11 01:52:54 -05003726 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003727
James Smart618a5232012-06-12 13:54:36 -04003728 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003729
3730 if (phba->wq)
3731 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003732}
3733
James Smarte59058c2008-08-24 21:49:00 -04003734/**
James Smart3621a712009-04-06 18:47:14 -04003735 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003736 * @phba: pointer to lpfc hba data structure.
3737 *
3738 * This routine actually brings a HBA offline. It stops all the timers
3739 * associated with the HBA, brings down the SLI layer, and eventually
3740 * marks the HBA as in offline state for the upper layer protocol.
3741 **/
James Smart46fa3112007-04-25 09:51:45 -04003742void
James Smart2e0fef82007-06-17 19:56:36 -05003743lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003744{
James Smart549e55c2007-08-02 11:09:51 -04003745 struct Scsi_Host *shost;
3746 struct lpfc_vport **vports;
3747 int i;
James Smart46fa3112007-04-25 09:51:45 -04003748
James Smart549e55c2007-08-02 11:09:51 -04003749 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003750 return;
James Smart688a8862006-07-06 15:49:56 -04003751
James Smartda0436e2009-05-22 14:51:39 -04003752 /* stop port and all timers associated with this hba */
3753 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003754
3755 /* Tear down the local and target port registrations. The
3756 * nvme transports need to cleanup.
3757 */
3758 lpfc_nvmet_destroy_targetport(phba);
3759 lpfc_nvme_destroy_localport(phba->pport);
3760
James Smart51ef4c22007-08-02 11:10:31 -04003761 vports = lpfc_create_vport_work_array(phba);
3762 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003763 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003764 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003765 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003766 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003767 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003768 /* Bring down the SLI Layer and cleanup. The HBA is offline
3769 now. */
3770 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003771 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003772 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003773 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003774 vports = lpfc_create_vport_work_array(phba);
3775 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003776 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003777 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003778 spin_lock_irq(shost->host_lock);
3779 vports[i]->work_port_events = 0;
3780 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3781 spin_unlock_irq(shost->host_lock);
3782 }
James Smart09372822008-01-11 01:52:54 -05003783 lpfc_destroy_vport_work_array(phba, vports);
James Smartf0871ab2021-01-04 10:02:32 -08003784 /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
3785 * in hba_unset
3786 */
3787 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
3788 __lpfc_cpuhp_remove(phba);
James Smartc4908502019-01-28 11:14:28 -08003789
3790 if (phba->cfg_xri_rebalancing)
3791 lpfc_destroy_multixri_pools(phba);
dea31012005-04-17 16:05:31 -05003792}
3793
James Smarte59058c2008-08-24 21:49:00 -04003794/**
James Smart3621a712009-04-06 18:47:14 -04003795 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003796 * @phba: pointer to lpfc hba data structure.
3797 *
3798 * This routine is to free all the SCSI buffers and IOCBs from the driver
3799 * list back to kernel. It is called from lpfc_pci_remove_one to free
3800 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003801 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003802static void
James Smart2e0fef82007-06-17 19:56:36 -05003803lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003804{
James Smartc4908502019-01-28 11:14:28 -08003805 struct lpfc_io_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003806
James Smart895427b2017-02-12 13:52:30 -08003807 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3808 return;
3809
James Smart2e0fef82007-06-17 19:56:36 -05003810 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003811
dea31012005-04-17 16:05:31 -05003812 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003813
3814 spin_lock(&phba->scsi_buf_list_put_lock);
3815 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3816 list) {
dea31012005-04-17 16:05:31 -05003817 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003818 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003819 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003820 kfree(sb);
3821 phba->total_scsi_bufs--;
3822 }
James Smarta40fc5f2013-04-17 20:17:40 -04003823 spin_unlock(&phba->scsi_buf_list_put_lock);
3824
3825 spin_lock(&phba->scsi_buf_list_get_lock);
3826 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3827 list) {
3828 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003829 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003830 sb->dma_handle);
3831 kfree(sb);
3832 phba->total_scsi_bufs--;
3833 }
3834 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003835 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003836}
James Smart0794d602019-01-28 11:14:19 -08003837
James Smart8a9d2e82012-05-09 21:16:12 -04003838/**
James Smart5e5b5112019-01-28 11:14:22 -08003839 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
James Smart895427b2017-02-12 13:52:30 -08003840 * @phba: pointer to lpfc hba data structure.
3841 *
James Smart0794d602019-01-28 11:14:19 -08003842 * This routine is to free all the IO buffers and IOCBs from the driver
James Smart895427b2017-02-12 13:52:30 -08003843 * list back to kernel. It is called from lpfc_pci_remove_one to free
3844 * the internal resources before the device is removed from the system.
3845 **/
James Smartc4908502019-01-28 11:14:28 -08003846void
James Smart5e5b5112019-01-28 11:14:22 -08003847lpfc_io_free(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08003848{
James Smartc4908502019-01-28 11:14:28 -08003849 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart5e5b5112019-01-28 11:14:22 -08003850 struct lpfc_sli4_hdw_queue *qp;
3851 int idx;
James Smart895427b2017-02-12 13:52:30 -08003852
James Smart5e5b5112019-01-28 11:14:22 -08003853 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3854 qp = &phba->sli4_hba.hdwq[idx];
3855 /* Release all the lpfc_nvme_bufs maintained by this host. */
3856 spin_lock(&qp->io_buf_list_put_lock);
3857 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3858 &qp->lpfc_io_buf_list_put,
3859 list) {
3860 list_del(&lpfc_ncmd->list);
3861 qp->put_io_bufs--;
3862 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3863 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
James Smartd79c9e92019-08-14 16:57:09 -07003864 if (phba->cfg_xpsgl && !phba->nvmet_support)
3865 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3866 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
James Smart5e5b5112019-01-28 11:14:22 -08003867 kfree(lpfc_ncmd);
3868 qp->total_io_bufs--;
3869 }
3870 spin_unlock(&qp->io_buf_list_put_lock);
James Smart895427b2017-02-12 13:52:30 -08003871
James Smart5e5b5112019-01-28 11:14:22 -08003872 spin_lock(&qp->io_buf_list_get_lock);
3873 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3874 &qp->lpfc_io_buf_list_get,
3875 list) {
3876 list_del(&lpfc_ncmd->list);
3877 qp->get_io_bufs--;
3878 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3879 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
James Smartd79c9e92019-08-14 16:57:09 -07003880 if (phba->cfg_xpsgl && !phba->nvmet_support)
3881 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
3882 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
James Smart5e5b5112019-01-28 11:14:22 -08003883 kfree(lpfc_ncmd);
3884 qp->total_io_bufs--;
3885 }
3886 spin_unlock(&qp->io_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003887 }
James Smart895427b2017-02-12 13:52:30 -08003888}
James Smart0794d602019-01-28 11:14:19 -08003889
James Smart895427b2017-02-12 13:52:30 -08003890/**
3891 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003892 * @phba: pointer to lpfc hba data structure.
3893 *
3894 * This routine first calculates the sizes of the current els and allocated
3895 * scsi sgl lists, and then goes through all sgls to updates the physical
3896 * XRIs assigned due to port function reset. During port initialization, the
3897 * current els and allocated scsi sgl lists are 0s.
3898 *
3899 * Return codes
3900 * 0 - successful (for now, it always returns 0)
3901 **/
3902int
James Smart895427b2017-02-12 13:52:30 -08003903lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003904{
3905 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003906 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003907 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003908 int rc;
3909
3910 /*
3911 * update on pci function's els xri-sgl list
3912 */
3913 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003914
James Smart8a9d2e82012-05-09 21:16:12 -04003915 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3916 /* els xri-sgl expanded */
3917 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3918 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3919 "3157 ELS xri-sgl count increased from "
3920 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3921 els_xri_cnt);
3922 /* allocate the additional els sgls */
3923 for (i = 0; i < xri_cnt; i++) {
3924 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3925 GFP_KERNEL);
3926 if (sglq_entry == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003927 lpfc_printf_log(phba, KERN_ERR,
3928 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003929 "2562 Failure to allocate an "
3930 "ELS sgl entry:%d\n", i);
3931 rc = -ENOMEM;
3932 goto out_free_mem;
3933 }
3934 sglq_entry->buff_type = GEN_BUFF_TYPE;
3935 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3936 &sglq_entry->phys);
3937 if (sglq_entry->virt == NULL) {
3938 kfree(sglq_entry);
Dick Kennedy372c1872020-06-30 14:50:00 -07003939 lpfc_printf_log(phba, KERN_ERR,
3940 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003941 "2563 Failure to allocate an "
3942 "ELS mbuf:%d\n", i);
3943 rc = -ENOMEM;
3944 goto out_free_mem;
3945 }
3946 sglq_entry->sgl = sglq_entry->virt;
3947 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3948 sglq_entry->state = SGL_FREED;
3949 list_add_tail(&sglq_entry->list, &els_sgl_list);
3950 }
James Smarta7892412021-04-11 18:31:15 -07003951 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart895427b2017-02-12 13:52:30 -08003952 list_splice_init(&els_sgl_list,
3953 &phba->sli4_hba.lpfc_els_sgl_list);
James Smarta7892412021-04-11 18:31:15 -07003954 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003955 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3956 /* els xri-sgl shrinked */
3957 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3958 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3959 "3158 ELS xri-sgl count decreased from "
3960 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3961 els_xri_cnt);
James Smarta7892412021-04-11 18:31:15 -07003962 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart895427b2017-02-12 13:52:30 -08003963 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3964 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003965 /* release extra els sgls from list */
3966 for (i = 0; i < xri_cnt; i++) {
3967 list_remove_head(&els_sgl_list,
3968 sglq_entry, struct lpfc_sglq, list);
3969 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003970 __lpfc_mbuf_free(phba, sglq_entry->virt,
3971 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003972 kfree(sglq_entry);
3973 }
3974 }
James Smart895427b2017-02-12 13:52:30 -08003975 list_splice_init(&els_sgl_list,
3976 &phba->sli4_hba.lpfc_els_sgl_list);
James Smarta7892412021-04-11 18:31:15 -07003977 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003978 } else
3979 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3980 "3163 ELS xri-sgl count unchanged: %d\n",
3981 els_xri_cnt);
3982 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3983
3984 /* update xris to els sgls on the list */
3985 sglq_entry = NULL;
3986 sglq_entry_next = NULL;
3987 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003988 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003989 lxri = lpfc_sli4_next_xritag(phba);
3990 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003991 lpfc_printf_log(phba, KERN_ERR,
3992 LOG_TRACE_EVENT,
James Smart8a9d2e82012-05-09 21:16:12 -04003993 "2400 Failed to allocate xri for "
3994 "ELS sgl\n");
3995 rc = -ENOMEM;
3996 goto out_free_mem;
3997 }
3998 sglq_entry->sli4_lxritag = lxri;
3999 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4000 }
James Smart895427b2017-02-12 13:52:30 -08004001 return 0;
4002
4003out_free_mem:
4004 lpfc_free_els_sgl_list(phba);
4005 return rc;
4006}
4007
4008/**
James Smartf358dd02017-02-12 13:52:34 -08004009 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
4010 * @phba: pointer to lpfc hba data structure.
4011 *
4012 * This routine first calculates the sizes of the current els and allocated
4013 * scsi sgl lists, and then goes through all sgls to updates the physical
4014 * XRIs assigned due to port function reset. During port initialization, the
4015 * current els and allocated scsi sgl lists are 0s.
4016 *
4017 * Return codes
4018 * 0 - successful (for now, it always returns 0)
4019 **/
4020int
4021lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
4022{
4023 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
4024 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07004025 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08004026 LIST_HEAD(nvmet_sgl_list);
4027 int rc;
4028
4029 /*
4030 * update on pci function's nvmet xri-sgl list
4031 */
4032 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07004033
James Smart6c621a22017-05-15 15:20:45 -07004034 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
4035 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08004036 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
4037 /* els xri-sgl expanded */
4038 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
4039 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4040 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
4041 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
4042 /* allocate the additional nvmet sgls */
4043 for (i = 0; i < xri_cnt; i++) {
4044 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
4045 GFP_KERNEL);
4046 if (sglq_entry == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004047 lpfc_printf_log(phba, KERN_ERR,
4048 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08004049 "6303 Failure to allocate an "
4050 "NVMET sgl entry:%d\n", i);
4051 rc = -ENOMEM;
4052 goto out_free_mem;
4053 }
4054 sglq_entry->buff_type = NVMET_BUFF_TYPE;
4055 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
4056 &sglq_entry->phys);
4057 if (sglq_entry->virt == NULL) {
4058 kfree(sglq_entry);
Dick Kennedy372c1872020-06-30 14:50:00 -07004059 lpfc_printf_log(phba, KERN_ERR,
4060 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08004061 "6304 Failure to allocate an "
4062 "NVMET buf:%d\n", i);
4063 rc = -ENOMEM;
4064 goto out_free_mem;
4065 }
4066 sglq_entry->sgl = sglq_entry->virt;
4067 memset(sglq_entry->sgl, 0,
4068 phba->cfg_sg_dma_buf_size);
4069 sglq_entry->state = SGL_FREED;
4070 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
4071 }
4072 spin_lock_irq(&phba->hbalock);
4073 spin_lock(&phba->sli4_hba.sgl_list_lock);
4074 list_splice_init(&nvmet_sgl_list,
4075 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4076 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4077 spin_unlock_irq(&phba->hbalock);
4078 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
4079 /* nvmet xri-sgl shrunk */
4080 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
4081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4082 "6305 NVMET xri-sgl count decreased from "
4083 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
4084 nvmet_xri_cnt);
4085 spin_lock_irq(&phba->hbalock);
4086 spin_lock(&phba->sli4_hba.sgl_list_lock);
4087 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
4088 &nvmet_sgl_list);
4089 /* release extra nvmet sgls from list */
4090 for (i = 0; i < xri_cnt; i++) {
4091 list_remove_head(&nvmet_sgl_list,
4092 sglq_entry, struct lpfc_sglq, list);
4093 if (sglq_entry) {
4094 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
4095 sglq_entry->phys);
4096 kfree(sglq_entry);
4097 }
4098 }
4099 list_splice_init(&nvmet_sgl_list,
4100 &phba->sli4_hba.lpfc_nvmet_sgl_list);
4101 spin_unlock(&phba->sli4_hba.sgl_list_lock);
4102 spin_unlock_irq(&phba->hbalock);
4103 } else
4104 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4105 "6306 NVMET xri-sgl count unchanged: %d\n",
4106 nvmet_xri_cnt);
4107 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
4108
4109 /* update xris to nvmet sgls on the list */
4110 sglq_entry = NULL;
4111 sglq_entry_next = NULL;
4112 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
4113 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
4114 lxri = lpfc_sli4_next_xritag(phba);
4115 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004116 lpfc_printf_log(phba, KERN_ERR,
4117 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08004118 "6307 Failed to allocate xri for "
4119 "NVMET sgl\n");
4120 rc = -ENOMEM;
4121 goto out_free_mem;
4122 }
4123 sglq_entry->sli4_lxritag = lxri;
4124 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4125 }
4126 return 0;
4127
4128out_free_mem:
4129 lpfc_free_nvmet_sgl_list(phba);
4130 return rc;
4131}
4132
James Smart5e5b5112019-01-28 11:14:22 -08004133int
4134lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
4135{
4136 LIST_HEAD(blist);
4137 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08004138 struct lpfc_io_buf *lpfc_cmd;
4139 struct lpfc_io_buf *iobufp, *prev_iobufp;
James Smart5e5b5112019-01-28 11:14:22 -08004140 int idx, cnt, xri, inserted;
4141
4142 cnt = 0;
4143 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4144 qp = &phba->sli4_hba.hdwq[idx];
4145 spin_lock_irq(&qp->io_buf_list_get_lock);
4146 spin_lock(&qp->io_buf_list_put_lock);
4147
4148 /* Take everything off the get and put lists */
4149 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
4150 list_splice(&qp->lpfc_io_buf_list_put, &blist);
4151 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
4152 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
4153 cnt += qp->get_io_bufs + qp->put_io_bufs;
4154 qp->get_io_bufs = 0;
4155 qp->put_io_bufs = 0;
4156 qp->total_io_bufs = 0;
4157 spin_unlock(&qp->io_buf_list_put_lock);
4158 spin_unlock_irq(&qp->io_buf_list_get_lock);
4159 }
4160
4161 /*
4162 * Take IO buffers off blist and put on cbuf sorted by XRI.
4163 * This is because POST_SGL takes a sequential range of XRIs
4164 * to post to the firmware.
4165 */
4166 for (idx = 0; idx < cnt; idx++) {
James Smartc4908502019-01-28 11:14:28 -08004167 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08004168 if (!lpfc_cmd)
4169 return cnt;
4170 if (idx == 0) {
4171 list_add_tail(&lpfc_cmd->list, cbuf);
4172 continue;
4173 }
4174 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
4175 inserted = 0;
4176 prev_iobufp = NULL;
4177 list_for_each_entry(iobufp, cbuf, list) {
4178 if (xri < iobufp->cur_iocbq.sli4_xritag) {
4179 if (prev_iobufp)
4180 list_add(&lpfc_cmd->list,
4181 &prev_iobufp->list);
4182 else
4183 list_add(&lpfc_cmd->list, cbuf);
4184 inserted = 1;
4185 break;
4186 }
4187 prev_iobufp = iobufp;
4188 }
4189 if (!inserted)
4190 list_add_tail(&lpfc_cmd->list, cbuf);
4191 }
4192 return cnt;
4193}
4194
4195int
4196lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
4197{
4198 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08004199 struct lpfc_io_buf *lpfc_cmd;
James Smart5e5b5112019-01-28 11:14:22 -08004200 int idx, cnt;
4201
4202 qp = phba->sli4_hba.hdwq;
4203 cnt = 0;
4204 while (!list_empty(cbuf)) {
4205 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
4206 list_remove_head(cbuf, lpfc_cmd,
James Smartc4908502019-01-28 11:14:28 -08004207 struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08004208 if (!lpfc_cmd)
4209 return cnt;
4210 cnt++;
4211 qp = &phba->sli4_hba.hdwq[idx];
James Smart1fbf9742019-01-28 11:14:26 -08004212 lpfc_cmd->hdwq_no = idx;
4213 lpfc_cmd->hdwq = qp;
James Smart5e5b5112019-01-28 11:14:22 -08004214 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
4215 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
4216 spin_lock(&qp->io_buf_list_put_lock);
4217 list_add_tail(&lpfc_cmd->list,
4218 &qp->lpfc_io_buf_list_put);
4219 qp->put_io_bufs++;
4220 qp->total_io_bufs++;
4221 spin_unlock(&qp->io_buf_list_put_lock);
4222 }
4223 }
4224 return cnt;
4225}
4226
James Smartf358dd02017-02-12 13:52:34 -08004227/**
James Smart5e5b5112019-01-28 11:14:22 -08004228 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
James Smart895427b2017-02-12 13:52:30 -08004229 * @phba: pointer to lpfc hba data structure.
4230 *
4231 * This routine first calculates the sizes of the current els and allocated
4232 * scsi sgl lists, and then goes through all sgls to updates the physical
4233 * XRIs assigned due to port function reset. During port initialization, the
4234 * current els and allocated scsi sgl lists are 0s.
4235 *
4236 * Return codes
4237 * 0 - successful (for now, it always returns 0)
4238 **/
4239int
James Smart5e5b5112019-01-28 11:14:22 -08004240lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08004241{
James Smartc4908502019-01-28 11:14:28 -08004242 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
James Smart0794d602019-01-28 11:14:19 -08004243 uint16_t i, lxri, els_xri_cnt;
James Smart5e5b5112019-01-28 11:14:22 -08004244 uint16_t io_xri_cnt, io_xri_max;
4245 LIST_HEAD(io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004246 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08004247
4248 /*
James Smart0794d602019-01-28 11:14:19 -08004249 * update on pci function's allocated nvme xri-sgl list
James Smart895427b2017-02-12 13:52:30 -08004250 */
James Smart0794d602019-01-28 11:14:19 -08004251
4252 /* maximum number of xris available for nvme buffers */
James Smart895427b2017-02-12 13:52:30 -08004253 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart5e5b5112019-01-28 11:14:22 -08004254 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4255 phba->sli4_hba.io_xri_max = io_xri_max;
James Smart8a9d2e82012-05-09 21:16:12 -04004256
James Smarte8c0a772017-04-21 16:04:49 -07004257 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004258 "6074 Current allocated XRI sgl count:%d, "
4259 "maximum XRI count:%d\n",
James Smart5e5b5112019-01-28 11:14:22 -08004260 phba->sli4_hba.io_xri_cnt,
4261 phba->sli4_hba.io_xri_max);
James Smarte8c0a772017-04-21 16:04:49 -07004262
James Smart5e5b5112019-01-28 11:14:22 -08004263 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004264
James Smart5e5b5112019-01-28 11:14:22 -08004265 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
James Smart0794d602019-01-28 11:14:19 -08004266 /* max nvme xri shrunk below the allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004267 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4268 phba->sli4_hba.io_xri_max;
James Smart0794d602019-01-28 11:14:19 -08004269 /* release the extra allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004270 for (i = 0; i < io_xri_cnt; i++) {
4271 list_remove_head(&io_sgl_list, lpfc_ncmd,
James Smartc4908502019-01-28 11:14:28 -08004272 struct lpfc_io_buf, list);
James Smart0794d602019-01-28 11:14:19 -08004273 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02004274 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart0794d602019-01-28 11:14:19 -08004275 lpfc_ncmd->data,
4276 lpfc_ncmd->dma_handle);
4277 kfree(lpfc_ncmd);
James Smarta2fc4aef2014-09-03 12:57:55 -04004278 }
James Smart8a9d2e82012-05-09 21:16:12 -04004279 }
James Smart5e5b5112019-01-28 11:14:22 -08004280 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04004281 }
4282
James Smart0794d602019-01-28 11:14:19 -08004283 /* update xris associated to remaining allocated nvme buffers */
4284 lpfc_ncmd = NULL;
4285 lpfc_ncmd_next = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08004286 phba->sli4_hba.io_xri_cnt = cnt;
James Smart0794d602019-01-28 11:14:19 -08004287 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
James Smart5e5b5112019-01-28 11:14:22 -08004288 &io_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04004289 lxri = lpfc_sli4_next_xritag(phba);
4290 if (lxri == NO_XRI) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004291 lpfc_printf_log(phba, KERN_ERR,
4292 LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -08004293 "6075 Failed to allocate xri for "
4294 "nvme buffer\n");
James Smart8a9d2e82012-05-09 21:16:12 -04004295 rc = -ENOMEM;
4296 goto out_free_mem;
4297 }
James Smart0794d602019-01-28 11:14:19 -08004298 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4299 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
James Smart8a9d2e82012-05-09 21:16:12 -04004300 }
James Smart5e5b5112019-01-28 11:14:22 -08004301 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
dea31012005-04-17 16:05:31 -05004302 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04004303
4304out_free_mem:
James Smart5e5b5112019-01-28 11:14:22 -08004305 lpfc_io_free(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04004306 return rc;
dea31012005-04-17 16:05:31 -05004307}
4308
James Smart0794d602019-01-28 11:14:19 -08004309/**
James Smart5e5b5112019-01-28 11:14:22 -08004310 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
Lee Jonesfe614ac2020-07-23 13:24:22 +01004311 * @phba: Pointer to lpfc hba data structure.
4312 * @num_to_alloc: The requested number of buffers to allocate.
James Smart0794d602019-01-28 11:14:19 -08004313 *
4314 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4315 * the nvme buffer contains all the necessary information needed to initiate
4316 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4317 * them on a list, it post them to the port by using SGL block post.
4318 *
4319 * Return codes:
James Smart5e5b5112019-01-28 11:14:22 -08004320 * int - number of IO buffers that were allocated and posted.
James Smart0794d602019-01-28 11:14:19 -08004321 * 0 = failure, less than num_to_alloc is a partial failure.
4322 **/
4323int
James Smart5e5b5112019-01-28 11:14:22 -08004324lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
James Smart0794d602019-01-28 11:14:19 -08004325{
James Smartc4908502019-01-28 11:14:28 -08004326 struct lpfc_io_buf *lpfc_ncmd;
James Smart0794d602019-01-28 11:14:19 -08004327 struct lpfc_iocbq *pwqeq;
4328 uint16_t iotag, lxri = 0;
4329 int bcnt, num_posted;
4330 LIST_HEAD(prep_nblist);
4331 LIST_HEAD(post_nblist);
4332 LIST_HEAD(nvme_nblist);
4333
James Smart5e5b5112019-01-28 11:14:22 -08004334 phba->sli4_hba.io_xri_cnt = 0;
James Smart0794d602019-01-28 11:14:19 -08004335 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
James Smart7f9989b2019-08-27 14:27:46 -07004336 lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
James Smart0794d602019-01-28 11:14:19 -08004337 if (!lpfc_ncmd)
4338 break;
4339 /*
4340 * Get memory from the pci pool to map the virt space to
4341 * pci bus space for an I/O. The DMA buffer includes the
4342 * number of SGE's necessary to support the sg_tablesize.
4343 */
Thomas Meyera5c990e2019-05-29 22:21:36 +02004344 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4345 GFP_KERNEL,
4346 &lpfc_ncmd->dma_handle);
James Smart0794d602019-01-28 11:14:19 -08004347 if (!lpfc_ncmd->data) {
4348 kfree(lpfc_ncmd);
4349 break;
4350 }
James Smart0794d602019-01-28 11:14:19 -08004351
James Smartd79c9e92019-08-14 16:57:09 -07004352 if (phba->cfg_xpsgl && !phba->nvmet_support) {
4353 INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
4354 } else {
4355 /*
4356 * 4K Page alignment is CRITICAL to BlockGuard, double
4357 * check to be sure.
4358 */
4359 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4360 (((unsigned long)(lpfc_ncmd->data) &
4361 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004362 lpfc_printf_log(phba, KERN_ERR,
4363 LOG_TRACE_EVENT,
James Smartd79c9e92019-08-14 16:57:09 -07004364 "3369 Memory alignment err: "
4365 "addr=%lx\n",
4366 (unsigned long)lpfc_ncmd->data);
4367 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4368 lpfc_ncmd->data,
4369 lpfc_ncmd->dma_handle);
4370 kfree(lpfc_ncmd);
4371 break;
4372 }
James Smart0794d602019-01-28 11:14:19 -08004373 }
4374
James Smartd79c9e92019-08-14 16:57:09 -07004375 INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
4376
James Smart0794d602019-01-28 11:14:19 -08004377 lxri = lpfc_sli4_next_xritag(phba);
4378 if (lxri == NO_XRI) {
4379 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4380 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4381 kfree(lpfc_ncmd);
4382 break;
4383 }
4384 pwqeq = &lpfc_ncmd->cur_iocbq;
4385
4386 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4387 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4388 if (iotag == 0) {
4389 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4390 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4391 kfree(lpfc_ncmd);
Dick Kennedy372c1872020-06-30 14:50:00 -07004392 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -08004393 "6121 Failed to allocate IOTAG for"
4394 " XRI:0x%x\n", lxri);
4395 lpfc_sli4_free_xri(phba, lxri);
4396 break;
4397 }
4398 pwqeq->sli4_lxritag = lxri;
4399 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4400 pwqeq->context1 = lpfc_ncmd;
4401
4402 /* Initialize local short-hand pointers. */
4403 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4404 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4405 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
James Smartc2017262019-01-28 11:14:37 -08004406 spin_lock_init(&lpfc_ncmd->buf_lock);
James Smart0794d602019-01-28 11:14:19 -08004407
4408 /* add the nvme buffer to a post list */
4409 list_add_tail(&lpfc_ncmd->list, &post_nblist);
James Smart5e5b5112019-01-28 11:14:22 -08004410 phba->sli4_hba.io_xri_cnt++;
James Smart0794d602019-01-28 11:14:19 -08004411 }
4412 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4413 "6114 Allocate %d out of %d requested new NVME "
4414 "buffers\n", bcnt, num_to_alloc);
4415
4416 /* post the list of nvme buffer sgls to port if available */
4417 if (!list_empty(&post_nblist))
James Smart5e5b5112019-01-28 11:14:22 -08004418 num_posted = lpfc_sli4_post_io_sgl_list(
James Smart0794d602019-01-28 11:14:19 -08004419 phba, &post_nblist, bcnt);
4420 else
4421 num_posted = 0;
4422
4423 return num_posted;
4424}
4425
James Smart96418b52017-03-04 09:30:31 -08004426static uint64_t
4427lpfc_get_wwpn(struct lpfc_hba *phba)
4428{
4429 uint64_t wwn;
4430 int rc;
4431 LPFC_MBOXQ_t *mboxq;
4432 MAILBOX_t *mb;
4433
James Smart96418b52017-03-04 09:30:31 -08004434 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4435 GFP_KERNEL);
4436 if (!mboxq)
4437 return (uint64_t)-1;
4438
4439 /* First get WWN of HBA instance */
4440 lpfc_read_nv(phba, mboxq);
4441 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4442 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004443 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart96418b52017-03-04 09:30:31 -08004444 "6019 Mailbox failed , mbxCmd x%x "
4445 "READ_NV, mbxStatus x%x\n",
4446 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4447 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4448 mempool_free(mboxq, phba->mbox_mem_pool);
4449 return (uint64_t) -1;
4450 }
4451 mb = &mboxq->u.mb;
4452 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4453 /* wwn is WWPN of HBA instance */
4454 mempool_free(mboxq, phba->mbox_mem_pool);
4455 if (phba->sli_rev == LPFC_SLI_REV4)
4456 return be64_to_cpu(wwn);
4457 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07004458 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08004459}
4460
James Smarte59058c2008-08-24 21:49:00 -04004461/**
Gaurav Srivastava5e633302021-06-08 10:05:49 +05304462 * lpfc_vmid_res_alloc - Allocates resources for VMID
4463 * @phba: pointer to lpfc hba data structure.
4464 * @vport: pointer to vport data structure
4465 *
4466 * This routine allocated the resources needed for the VMID.
4467 *
4468 * Return codes
4469 * 0 on Success
4470 * Non-0 on Failure
4471 */
4472static int
4473lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
4474{
4475 /* VMID feature is supported only on SLI4 */
4476 if (phba->sli_rev == LPFC_SLI_REV3) {
4477 phba->cfg_vmid_app_header = 0;
4478 phba->cfg_vmid_priority_tagging = 0;
4479 }
4480
4481 if (lpfc_is_vmid_enabled(phba)) {
4482 vport->vmid =
4483 kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
4484 GFP_KERNEL);
4485 if (!vport->vmid)
4486 return -ENOMEM;
4487
4488 rwlock_init(&vport->vmid_lock);
4489
4490 /* Set the VMID parameters for the vport */
4491 vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
4492 vport->vmid_inactivity_timeout =
4493 phba->cfg_vmid_inactivity_timeout;
4494 vport->max_vmid = phba->cfg_max_vmid;
4495 vport->cur_vmid_cnt = 0;
4496
4497 vport->vmid_priority_range = bitmap_zalloc
4498 (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
4499
4500 if (!vport->vmid_priority_range) {
4501 kfree(vport->vmid);
4502 return -ENOMEM;
4503 }
4504
4505 hash_init(vport->hash_table);
4506 }
4507 return 0;
4508}
4509
4510/**
James Smart3621a712009-04-06 18:47:14 -04004511 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04004512 * @phba: pointer to lpfc hba data structure.
4513 * @instance: a unique integer ID to this FC port.
4514 * @dev: pointer to the device data structure.
4515 *
4516 * This routine creates a FC port for the upper layer protocol. The FC port
4517 * can be created on top of either a physical port or a virtual port provided
4518 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4519 * and associates the FC port created before adding the shost into the SCSI
4520 * layer.
4521 *
4522 * Return codes
4523 * @vport - pointer to the virtual N_Port data structure.
4524 * NULL - port create failed.
4525 **/
James Smart2e0fef82007-06-17 19:56:36 -05004526struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04004527lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04004528{
James Smart2e0fef82007-06-17 19:56:36 -05004529 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08004530 struct Scsi_Host *shost = NULL;
James Smartc90b4482020-03-22 11:12:56 -07004531 struct scsi_host_template *template;
James Smart2e0fef82007-06-17 19:56:36 -05004532 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08004533 int i;
4534 uint64_t wwn;
4535 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07004536 int rc;
James Smart96418b52017-03-04 09:30:31 -08004537
James Smart56bc8022017-06-15 22:56:43 -07004538 if (lpfc_no_hba_reset_cnt) {
4539 if (phba->sli_rev < LPFC_SLI_REV4 &&
4540 dev == &phba->pcidev->dev) {
4541 /* Reset the port first */
4542 lpfc_sli_brdrestart(phba);
4543 rc = lpfc_sli_chipset_init(phba);
4544 if (rc)
4545 return NULL;
4546 }
4547 wwn = lpfc_get_wwpn(phba);
4548 }
James Smart96418b52017-03-04 09:30:31 -08004549
4550 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4551 if (wwn == lpfc_no_hba_reset[i]) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004552 lpfc_printf_log(phba, KERN_ERR,
4553 LOG_TRACE_EVENT,
James Smart96418b52017-03-04 09:30:31 -08004554 "6020 Setting use_no_reset port=%llx\n",
4555 wwn);
4556 use_no_reset_hba = true;
4557 break;
4558 }
4559 }
James Smart47a86172007-04-25 09:53:22 -04004560
James Smartc90b4482020-03-22 11:12:56 -07004561 /* Seed template for SCSI host registration */
4562 if (dev == &phba->pcidev->dev) {
4563 template = &phba->port_template;
4564
4565 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4566 /* Seed physical port template */
4567 memcpy(template, &lpfc_template, sizeof(*template));
4568
James Smart7c30bb62020-10-20 13:27:16 -07004569 if (use_no_reset_hba)
James Smartc90b4482020-03-22 11:12:56 -07004570 /* template is for a no reset SCSI Host */
James Smartc90b4482020-03-22 11:12:56 -07004571 template->eh_host_reset_handler = NULL;
James Smartc90b4482020-03-22 11:12:56 -07004572
4573 /* Template for all vports this physical port creates */
4574 memcpy(&phba->vport_template, &lpfc_template,
4575 sizeof(*template));
James Smartc90b4482020-03-22 11:12:56 -07004576 phba->vport_template.shost_attrs = lpfc_vport_attrs;
4577 phba->vport_template.eh_bus_reset_handler = NULL;
4578 phba->vport_template.eh_host_reset_handler = NULL;
4579 phba->vport_template.vendor_id = 0;
4580
4581 /* Initialize the host templates with updated value */
4582 if (phba->sli_rev == LPFC_SLI_REV4) {
4583 template->sg_tablesize = phba->cfg_scsi_seg_cnt;
4584 phba->vport_template.sg_tablesize =
4585 phba->cfg_scsi_seg_cnt;
4586 } else {
4587 template->sg_tablesize = phba->cfg_sg_seg_cnt;
4588 phba->vport_template.sg_tablesize =
4589 phba->cfg_sg_seg_cnt;
4590 }
4591
James Smart895427b2017-02-12 13:52:30 -08004592 } else {
James Smartc90b4482020-03-22 11:12:56 -07004593 /* NVMET is for physical port only */
4594 memcpy(template, &lpfc_template_nvme,
4595 sizeof(*template));
James Smart895427b2017-02-12 13:52:30 -08004596 }
James Smartc90b4482020-03-22 11:12:56 -07004597 } else {
4598 template = &phba->vport_template;
James Smartea4142f2015-04-07 15:07:13 -04004599 }
James Smartc90b4482020-03-22 11:12:56 -07004600
4601 shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05004602 if (!shost)
4603 goto out;
James Smart47a86172007-04-25 09:53:22 -04004604
James Smart2e0fef82007-06-17 19:56:36 -05004605 vport = (struct lpfc_vport *) shost->hostdata;
4606 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05004607 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05004608 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05004609 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04004610 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08004611
James Smartf6e84792019-01-28 11:14:38 -08004612 /* Adjust value in vport */
4613 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4614
James Smart2e0fef82007-06-17 19:56:36 -05004615 shost->unique_id = instance;
4616 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04004617 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05004618 shost->this_id = -1;
4619 shost->max_cmd_len = 16;
James Smart6a828b02019-01-28 11:14:31 -08004620
James Smartda0436e2009-05-22 14:51:39 -04004621 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart77ffd342019-08-15 19:36:49 -07004622 if (!phba->cfg_fcp_mq_threshold ||
4623 phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
4624 phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
4625
4626 shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
4627 phba->cfg_fcp_mq_threshold);
James Smart6a828b02019-01-28 11:14:31 -08004628
James Smart28baac72010-02-12 14:42:03 -05004629 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04004630 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartd79c9e92019-08-14 16:57:09 -07004631
4632 if (phba->cfg_xpsgl && !phba->nvmet_support)
4633 shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE;
4634 else
4635 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartace44e42019-01-28 11:14:27 -08004636 } else
4637 /* SLI-3 has a limited number of hardware queues (3),
4638 * thus there is only one for FCP processing.
4639 */
4640 shost->nr_hw_queues = 1;
James Smart81301a92008-12-04 22:39:46 -05004641
James Smart47a86172007-04-25 09:53:22 -04004642 /*
James Smart2e0fef82007-06-17 19:56:36 -05004643 * Set initial can_queue value since 0 is no longer supported and
4644 * scsi_add_host will fail. This will be adjusted later based on the
4645 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04004646 */
James Smart2e0fef82007-06-17 19:56:36 -05004647 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04004648 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05004649 shost->transportt = lpfc_vport_transport_template;
4650 vport->port_type = LPFC_NPIV_PORT;
4651 } else {
4652 shost->transportt = lpfc_transport_template;
4653 vport->port_type = LPFC_PHYSICAL_PORT;
4654 }
James Smart47a86172007-04-25 09:53:22 -04004655
James Smartc90b4482020-03-22 11:12:56 -07004656 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4657 "9081 CreatePort TMPLATE type %x TBLsize %d "
4658 "SEGcnt %d/%d\n",
4659 vport->port_type, shost->sg_tablesize,
4660 phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
4661
Gaurav Srivastava5e633302021-06-08 10:05:49 +05304662 /* Allocate the resources for VMID */
4663 rc = lpfc_vmid_res_alloc(phba, vport);
4664
4665 if (rc)
4666 goto out;
4667
James Smart2e0fef82007-06-17 19:56:36 -05004668 /* Initialize all internally managed lists. */
4669 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04004670 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05004671 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04004672
Kees Cookf22eb4d2017-09-06 20:24:26 -07004673 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04004674
Kees Cookf22eb4d2017-09-06 20:24:26 -07004675 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05004676
Kees Cookf22eb4d2017-09-06 20:24:26 -07004677 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05004678
James Smartaa6ff302019-05-21 17:49:09 -07004679 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4680 lpfc_setup_bg(phba, shost);
4681
James Bottomleyd139b9b2009-11-05 13:33:12 -06004682 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05004683 if (error)
4684 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04004685
James Smart523128e2018-09-10 10:30:46 -07004686 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004687 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07004688 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004689 return vport;
James Smart47a86172007-04-25 09:53:22 -04004690
James Smart2e0fef82007-06-17 19:56:36 -05004691out_put_shost:
Gaurav Srivastava5e633302021-06-08 10:05:49 +05304692 kfree(vport->vmid);
4693 bitmap_free(vport->vmid_priority_range);
James Smart2e0fef82007-06-17 19:56:36 -05004694 scsi_host_put(shost);
4695out:
4696 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004697}
4698
James Smarte59058c2008-08-24 21:49:00 -04004699/**
James Smart3621a712009-04-06 18:47:14 -04004700 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004701 * @vport: pointer to an lpfc virtual N_Port data structure.
4702 *
4703 * This routine destroys a FC port from the upper layer protocol. All the
4704 * resources associated with the port are released.
4705 **/
James Smart2e0fef82007-06-17 19:56:36 -05004706void
4707destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004708{
James Smart92d7f7b2007-06-17 19:56:38 -05004709 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4710 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004711
James Smart858c9f62007-06-17 19:56:39 -05004712 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004713 fc_remove_host(shost);
4714 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004715
James Smart523128e2018-09-10 10:30:46 -07004716 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004717 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004718 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004719
James Smart92d7f7b2007-06-17 19:56:38 -05004720 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004721 return;
James Smart47a86172007-04-25 09:53:22 -04004722}
4723
James Smarte59058c2008-08-24 21:49:00 -04004724/**
James Smart3621a712009-04-06 18:47:14 -04004725 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004726 *
4727 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4728 * uses the kernel idr facility to perform the task.
4729 *
4730 * Return codes:
4731 * instance - a unique integer ID allocated as the new instance.
4732 * -1 - lpfc get instance failed.
4733 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004734int
4735lpfc_get_instance(void)
4736{
Tejun Heoab516032013-02-27 17:04:44 -08004737 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004738
Tejun Heoab516032013-02-27 17:04:44 -08004739 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4740 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004741}
4742
James Smarte59058c2008-08-24 21:49:00 -04004743/**
James Smart3621a712009-04-06 18:47:14 -04004744 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004745 * @shost: pointer to SCSI host data structure.
4746 * @time: elapsed time of the scan in jiffies.
4747 *
4748 * This routine is called by the SCSI layer with a SCSI host to determine
4749 * whether the scan host is finished.
4750 *
4751 * Note: there is no scan_start function as adapter initialization will have
4752 * asynchronously kicked off the link initialization.
4753 *
4754 * Return codes
4755 * 0 - SCSI host scan is not over yet.
4756 * 1 - SCSI host scan is over.
4757 **/
James Smart47a86172007-04-25 09:53:22 -04004758int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4759{
James Smart2e0fef82007-06-17 19:56:36 -05004760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4761 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004762 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004763
James Smart858c9f62007-06-17 19:56:39 -05004764 spin_lock_irq(shost->host_lock);
4765
James Smart51ef4c22007-08-02 11:10:31 -04004766 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004767 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004768 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004769 }
James Smart256ec0d2013-04-17 20:14:58 -04004770 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004771 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004772 "0461 Scanning longer than 30 "
4773 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004774 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004775 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004776 }
James Smart256ec0d2013-04-17 20:14:58 -04004777 if (time >= msecs_to_jiffies(15 * 1000) &&
4778 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004779 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004780 "0465 Link down longer than 15 "
4781 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004782 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004783 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004784 }
4785
James Smart2e0fef82007-06-17 19:56:36 -05004786 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004787 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004788 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004789 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004790 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004791 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004792 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004793 goto finished;
4794
4795 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004796
4797finished:
James Smart858c9f62007-06-17 19:56:39 -05004798 spin_unlock_irq(shost->host_lock);
4799 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004800}
4801
Bart Van Assche3999df72019-03-28 11:06:16 -07004802static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
James Smartcd713482018-10-23 13:41:01 -07004803{
4804 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4805 struct lpfc_hba *phba = vport->phba;
4806
4807 fc_host_supported_speeds(shost) = 0;
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07004808 /*
4809 * Avoid reporting supported link speed for FCoE as it can't be
4810 * controlled via FCoE.
4811 */
4812 if (phba->hba_flag & HBA_FCOE_MODE)
4813 return;
4814
James Smartbfc47782021-07-22 15:17:19 -07004815 if (phba->lmt & LMT_256Gb)
4816 fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
James Smart1dc5ec22018-10-23 13:41:11 -07004817 if (phba->lmt & LMT_128Gb)
4818 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004819 if (phba->lmt & LMT_64Gb)
4820 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4821 if (phba->lmt & LMT_32Gb)
4822 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4823 if (phba->lmt & LMT_16Gb)
4824 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4825 if (phba->lmt & LMT_10Gb)
4826 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4827 if (phba->lmt & LMT_8Gb)
4828 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4829 if (phba->lmt & LMT_4Gb)
4830 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4831 if (phba->lmt & LMT_2Gb)
4832 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4833 if (phba->lmt & LMT_1Gb)
4834 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4835}
4836
James Smarte59058c2008-08-24 21:49:00 -04004837/**
James Smart3621a712009-04-06 18:47:14 -04004838 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004839 * @shost: pointer to SCSI host data structure.
4840 *
4841 * This routine initializes a given SCSI host attributes on a FC port. The
4842 * SCSI host can be either on top of a physical port or a virtual port.
4843 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004844void lpfc_host_attrib_init(struct Scsi_Host *shost)
4845{
4846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4847 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004848 /*
James Smart2e0fef82007-06-17 19:56:36 -05004849 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004850 */
4851
James Smart2e0fef82007-06-17 19:56:36 -05004852 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4853 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004854 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4855
4856 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004857 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004858 fc_host_supported_fc4s(shost)[2] = 1;
4859 fc_host_supported_fc4s(shost)[7] = 1;
4860
James Smart92d7f7b2007-06-17 19:56:38 -05004861 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4862 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004863
James Smartcd713482018-10-23 13:41:01 -07004864 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004865
4866 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004867 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4868 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004869
Mike Christie0af5d702010-09-15 16:52:31 -05004870 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4871
James Smart47a86172007-04-25 09:53:22 -04004872 /* This value is also unchanging */
4873 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004874 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004875 fc_host_active_fc4s(shost)[2] = 1;
4876 fc_host_active_fc4s(shost)[7] = 1;
4877
James Smart92d7f7b2007-06-17 19:56:38 -05004878 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004879 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004880 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004881 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004882}
dea31012005-04-17 16:05:31 -05004883
James Smarte59058c2008-08-24 21:49:00 -04004884/**
James Smartda0436e2009-05-22 14:51:39 -04004885 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004886 * @phba: pointer to lpfc hba data structure.
4887 *
James Smartda0436e2009-05-22 14:51:39 -04004888 * This routine is invoked to stop an SLI3 device port, it stops the device
4889 * from generating interrupts and stops the device driver's timers for the
4890 * device.
James Smarte59058c2008-08-24 21:49:00 -04004891 **/
James Smartdb2378e2008-02-08 18:49:51 -05004892static void
James Smartda0436e2009-05-22 14:51:39 -04004893lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004894{
James Smartda0436e2009-05-22 14:51:39 -04004895 /* Clear all interrupt enable conditions */
4896 writel(0, phba->HCregaddr);
4897 readl(phba->HCregaddr); /* flush */
4898 /* Clear all pending interrupts */
4899 writel(0xffffffff, phba->HAregaddr);
4900 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004901
James Smartda0436e2009-05-22 14:51:39 -04004902 /* Reset some HBA SLI setup states */
4903 lpfc_stop_hba_timers(phba);
4904 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004905}
4906
James Smarte59058c2008-08-24 21:49:00 -04004907/**
James Smartda0436e2009-05-22 14:51:39 -04004908 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004909 * @phba: pointer to lpfc hba data structure.
4910 *
James Smartda0436e2009-05-22 14:51:39 -04004911 * This routine is invoked to stop an SLI4 device port, it stops the device
4912 * from generating interrupts and stops the device driver's timers for the
4913 * device.
4914 **/
4915static void
4916lpfc_stop_port_s4(struct lpfc_hba *phba)
4917{
4918 /* Reset some HBA SLI4 setup states */
4919 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -08004920 if (phba->pport)
4921 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -04004922 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004923}
4924
4925/**
4926 * lpfc_stop_port - Wrapper function for stopping hba port
4927 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004928 *
James Smartda0436e2009-05-22 14:51:39 -04004929 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4930 * the API jump table function pointer from the lpfc_hba struct.
4931 **/
4932void
4933lpfc_stop_port(struct lpfc_hba *phba)
4934{
4935 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004936
4937 if (phba->wq)
4938 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004939}
4940
4941/**
James Smartecfd03c2010-02-12 14:41:27 -05004942 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4943 * @phba: Pointer to hba for which this call is being executed.
4944 *
4945 * This routine starts the timer waiting for the FCF rediscovery to complete.
4946 **/
4947void
4948lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4949{
4950 unsigned long fcf_redisc_wait_tmo =
4951 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4952 /* Start fcf rediscovery wait period timer */
4953 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4954 spin_lock_irq(&phba->hbalock);
4955 /* Allow action to new fcf asynchronous event */
4956 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4957 /* Mark the FCF rediscovery pending state */
4958 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4959 spin_unlock_irq(&phba->hbalock);
4960}
4961
4962/**
4963 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
Lee Jonesfe614ac2020-07-23 13:24:22 +01004964 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
James Smartecfd03c2010-02-12 14:41:27 -05004965 *
4966 * This routine is invoked when waiting for FCF table rediscover has been
4967 * timed out. If new FCF record(s) has (have) been discovered during the
4968 * wait period, a new FCF event shall be added to the FCOE async event
4969 * list, and then worker thread shall be waked up for processing from the
4970 * worker thread context.
4971 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004972static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004973lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004974{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004975 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004976
4977 /* Don't send FCF rediscovery event if timer cancelled */
4978 spin_lock_irq(&phba->hbalock);
4979 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4980 spin_unlock_irq(&phba->hbalock);
4981 return;
4982 }
4983 /* Clear FCF rediscovery timer pending flag */
4984 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4985 /* FCF rediscovery event to worker thread */
4986 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4987 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004988 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004989 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004990 /* wake up worker thread */
4991 lpfc_worker_wake_up(phba);
4992}
4993
4994/**
Gaurav Srivastava20397172021-06-08 10:05:54 +05304995 * lpfc_vmid_poll - VMID timeout detection
James Smart50baa152021-07-07 11:43:35 -07004996 * @t: Timer context used to obtain the pointer to lpfc hba data structure.
Gaurav Srivastava20397172021-06-08 10:05:54 +05304997 *
4998 * This routine is invoked when there is no I/O on by a VM for the specified
4999 * amount of time. When this situation is detected, the VMID has to be
5000 * deregistered from the switch and all the local resources freed. The VMID
5001 * will be reassigned to the VM once the I/O begins.
5002 **/
5003static void
5004lpfc_vmid_poll(struct timer_list *t)
5005{
5006 struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
5007 u32 wake_up = 0;
5008
5009 /* check if there is a need to issue QFPA */
5010 if (phba->pport->vmid_priority_tagging) {
5011 wake_up = 1;
5012 phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
5013 }
5014
5015 /* Is the vmid inactivity timer enabled */
5016 if (phba->pport->vmid_inactivity_timeout ||
5017 phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
5018 wake_up = 1;
5019 phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
5020 }
5021
5022 if (wake_up)
5023 lpfc_worker_wake_up(phba);
5024
5025 /* restart the timer for the next iteration */
5026 mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
5027 LPFC_VMID_TIMER));
5028}
5029
5030/**
James Smartda0436e2009-05-22 14:51:39 -04005031 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
5032 * @phba: pointer to lpfc hba data structure.
5033 * @acqe_link: pointer to the async link completion queue entry.
5034 *
James Smart23288b72018-05-04 20:37:53 -07005035 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04005036 **/
James Smart23288b72018-05-04 20:37:53 -07005037static void
James Smartda0436e2009-05-22 14:51:39 -04005038lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
5039 struct lpfc_acqe_link *acqe_link)
5040{
James Smartda0436e2009-05-22 14:51:39 -04005041 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
5042 case LPFC_ASYNC_LINK_FAULT_NONE:
5043 case LPFC_ASYNC_LINK_FAULT_LOCAL:
5044 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07005045 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04005046 break;
5047 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005048 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart23288b72018-05-04 20:37:53 -07005049 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04005050 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04005051 break;
5052 }
James Smartda0436e2009-05-22 14:51:39 -04005053}
5054
5055/**
5056 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
5057 * @phba: pointer to lpfc hba data structure.
5058 * @acqe_link: pointer to the async link completion queue entry.
5059 *
5060 * This routine is to parse the SLI4 link attention type and translate it
5061 * into the base driver's link attention type coding.
5062 *
5063 * Return: Link attention type in terms of base driver's coding.
5064 **/
5065static uint8_t
5066lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
5067 struct lpfc_acqe_link *acqe_link)
5068{
5069 uint8_t att_type;
5070
5071 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
5072 case LPFC_ASYNC_LINK_STATUS_DOWN:
5073 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05005074 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04005075 break;
5076 case LPFC_ASYNC_LINK_STATUS_UP:
5077 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05005078 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04005079 break;
5080 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05005081 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04005082 break;
5083 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005084 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04005085 "0399 Invalid link attention type: x%x\n",
5086 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05005087 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04005088 break;
5089 }
5090 return att_type;
5091}
5092
5093/**
James Smart8b68cd52012-09-29 11:32:37 -04005094 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
5095 * @phba: pointer to lpfc hba data structure.
5096 *
5097 * This routine is to get an SLI3 FC port's link speed in Mbps.
5098 *
5099 * Return: link speed in terms of Mbps.
5100 **/
5101uint32_t
5102lpfc_sli_port_speed_get(struct lpfc_hba *phba)
5103{
5104 uint32_t link_speed;
5105
5106 if (!lpfc_is_link_up(phba))
5107 return 0;
5108
James Smarta085e872015-12-16 18:12:02 -05005109 if (phba->sli_rev <= LPFC_SLI_REV3) {
5110 switch (phba->fc_linkspeed) {
5111 case LPFC_LINK_SPEED_1GHZ:
5112 link_speed = 1000;
5113 break;
5114 case LPFC_LINK_SPEED_2GHZ:
5115 link_speed = 2000;
5116 break;
5117 case LPFC_LINK_SPEED_4GHZ:
5118 link_speed = 4000;
5119 break;
5120 case LPFC_LINK_SPEED_8GHZ:
5121 link_speed = 8000;
5122 break;
5123 case LPFC_LINK_SPEED_10GHZ:
5124 link_speed = 10000;
5125 break;
5126 case LPFC_LINK_SPEED_16GHZ:
5127 link_speed = 16000;
5128 break;
5129 default:
5130 link_speed = 0;
5131 }
5132 } else {
5133 if (phba->sli4_hba.link_state.logical_speed)
5134 link_speed =
5135 phba->sli4_hba.link_state.logical_speed;
5136 else
5137 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04005138 }
5139 return link_speed;
5140}
5141
5142/**
5143 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
5144 * @phba: pointer to lpfc hba data structure.
5145 * @evt_code: asynchronous event code.
5146 * @speed_code: asynchronous event link speed code.
5147 *
5148 * This routine is to parse the giving SLI4 async event link speed code into
5149 * value of Mbps for the link speed.
5150 *
5151 * Return: link speed in terms of Mbps.
5152 **/
5153static uint32_t
5154lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
5155 uint8_t speed_code)
5156{
5157 uint32_t port_speed;
5158
5159 switch (evt_code) {
5160 case LPFC_TRAILER_CODE_LINK:
5161 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04005162 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04005163 port_speed = 0;
5164 break;
James Smart26d830e2015-04-07 15:07:17 -04005165 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04005166 port_speed = 10;
5167 break;
James Smart26d830e2015-04-07 15:07:17 -04005168 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04005169 port_speed = 100;
5170 break;
James Smart26d830e2015-04-07 15:07:17 -04005171 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04005172 port_speed = 1000;
5173 break;
James Smart26d830e2015-04-07 15:07:17 -04005174 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04005175 port_speed = 10000;
5176 break;
James Smart26d830e2015-04-07 15:07:17 -04005177 case LPFC_ASYNC_LINK_SPEED_20GBPS:
5178 port_speed = 20000;
5179 break;
5180 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5181 port_speed = 25000;
5182 break;
5183 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5184 port_speed = 40000;
5185 break;
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07005186 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5187 port_speed = 100000;
5188 break;
James Smart8b68cd52012-09-29 11:32:37 -04005189 default:
5190 port_speed = 0;
5191 }
5192 break;
5193 case LPFC_TRAILER_CODE_FC:
5194 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04005195 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04005196 port_speed = 0;
5197 break;
James Smart26d830e2015-04-07 15:07:17 -04005198 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04005199 port_speed = 1000;
5200 break;
James Smart26d830e2015-04-07 15:07:17 -04005201 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04005202 port_speed = 2000;
5203 break;
James Smart26d830e2015-04-07 15:07:17 -04005204 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04005205 port_speed = 4000;
5206 break;
James Smart26d830e2015-04-07 15:07:17 -04005207 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04005208 port_speed = 8000;
5209 break;
James Smart26d830e2015-04-07 15:07:17 -04005210 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04005211 port_speed = 10000;
5212 break;
James Smart26d830e2015-04-07 15:07:17 -04005213 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04005214 port_speed = 16000;
5215 break;
James Smartd38dd522015-08-31 16:48:17 -04005216 case LPFC_FC_LA_SPEED_32G:
5217 port_speed = 32000;
5218 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005219 case LPFC_FC_LA_SPEED_64G:
5220 port_speed = 64000;
5221 break;
James Smart1dc5ec22018-10-23 13:41:11 -07005222 case LPFC_FC_LA_SPEED_128G:
5223 port_speed = 128000;
5224 break;
James Smartbfc47782021-07-22 15:17:19 -07005225 case LPFC_FC_LA_SPEED_256G:
5226 port_speed = 256000;
5227 break;
James Smart8b68cd52012-09-29 11:32:37 -04005228 default:
5229 port_speed = 0;
5230 }
5231 break;
5232 default:
5233 port_speed = 0;
5234 }
5235 return port_speed;
5236}
5237
5238/**
James Smart70f3c072010-12-15 17:57:33 -05005239 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04005240 * @phba: pointer to lpfc hba data structure.
5241 * @acqe_link: pointer to the async link completion queue entry.
5242 *
James Smart70f3c072010-12-15 17:57:33 -05005243 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04005244 **/
5245static void
5246lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
5247 struct lpfc_acqe_link *acqe_link)
5248{
5249 struct lpfc_dmabuf *mp;
5250 LPFC_MBOXQ_t *pmb;
5251 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05005252 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04005253 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05005254 int rc;
James Smartda0436e2009-05-22 14:51:39 -04005255
5256 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05005257 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04005258 return;
James Smart32b97932009-07-19 10:01:21 -04005259 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005260 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5261 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005262 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04005263 "0395 The mboxq allocation failed\n");
5264 return;
5265 }
5266 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5267 if (!mp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04005269 "0396 The lpfc_dmabuf allocation failed\n");
5270 goto out_free_pmb;
5271 }
5272 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5273 if (!mp->virt) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005274 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04005275 "0397 The mbuf allocation failed\n");
5276 goto out_free_dmabuf;
5277 }
5278
5279 /* Cleanup any outstanding ELS commands */
5280 lpfc_els_flush_all_cmd(phba);
5281
5282 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08005283 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04005284
5285 /* Update link event statistics */
5286 phba->sli.slistat.link_event++;
5287
James Smart76a95d72010-11-20 23:11:48 -05005288 /* Create lpfc_handle_latt mailbox command from link ACQE */
5289 lpfc_read_topology(phba, pmb, mp);
5290 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04005291 pmb->vport = phba->pport;
5292
James Smartda0436e2009-05-22 14:51:39 -04005293 /* Keep the link status for extra SLI4 state machine reference */
5294 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04005295 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
5296 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04005297 phba->sli4_hba.link_state.duplex =
5298 bf_get(lpfc_acqe_link_duplex, acqe_link);
5299 phba->sli4_hba.link_state.status =
5300 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05005301 phba->sli4_hba.link_state.type =
5302 bf_get(lpfc_acqe_link_type, acqe_link);
5303 phba->sli4_hba.link_state.number =
5304 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04005305 phba->sli4_hba.link_state.fault =
5306 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05005307 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005308 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
5309
James Smart70f3c072010-12-15 17:57:33 -05005310 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04005311 "2900 Async FC/FCoE Link event - Speed:%dGBit "
5312 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
5313 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05005314 phba->sli4_hba.link_state.speed,
5315 phba->sli4_hba.link_state.topology,
5316 phba->sli4_hba.link_state.status,
5317 phba->sli4_hba.link_state.type,
5318 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04005319 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05005320 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05005321 /*
5322 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
5323 * topology info. Note: Optional for non FC-AL ports.
5324 */
5325 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
5326 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5327 if (rc == MBX_NOT_FINISHED)
5328 goto out_free_dmabuf;
5329 return;
5330 }
5331 /*
5332 * For FCoE Mode: fill in all the topology information we need and call
5333 * the READ_TOPOLOGY completion routine to continue without actually
5334 * sending the READ_TOPOLOGY mailbox command to the port.
5335 */
James Smart23288b72018-05-04 20:37:53 -07005336 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05005337 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07005338 mb->mbxStatus = MBX_SUCCESS;
5339
5340 /* Parse port fault information field */
5341 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05005342
5343 /* Parse and translate link attention fields */
5344 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
5345 la->eventTag = acqe_link->event_tag;
5346 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
5347 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05005348 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05005349
5350 /* Fake the the following irrelvant fields */
5351 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
5352 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
5353 bf_set(lpfc_mbx_read_top_il, la, 0);
5354 bf_set(lpfc_mbx_read_top_pb, la, 0);
5355 bf_set(lpfc_mbx_read_top_fa, la, 0);
5356 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04005357
5358 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05005359 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04005360
5361 return;
5362
5363out_free_dmabuf:
5364 kfree(mp);
5365out_free_pmb:
5366 mempool_free(pmb, phba->mbox_mem_pool);
5367}
5368
5369/**
James Smart1dc5ec22018-10-23 13:41:11 -07005370 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5371 * topology.
5372 * @phba: pointer to lpfc hba data structure.
James Smart1dc5ec22018-10-23 13:41:11 -07005373 * @speed_code: asynchronous event link speed code.
5374 *
5375 * This routine is to parse the giving SLI4 async event link speed code into
5376 * value of Read topology link speed.
5377 *
5378 * Return: link speed in terms of Read topology.
5379 **/
5380static uint8_t
5381lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5382{
5383 uint8_t port_speed;
5384
5385 switch (speed_code) {
5386 case LPFC_FC_LA_SPEED_1G:
5387 port_speed = LPFC_LINK_SPEED_1GHZ;
5388 break;
5389 case LPFC_FC_LA_SPEED_2G:
5390 port_speed = LPFC_LINK_SPEED_2GHZ;
5391 break;
5392 case LPFC_FC_LA_SPEED_4G:
5393 port_speed = LPFC_LINK_SPEED_4GHZ;
5394 break;
5395 case LPFC_FC_LA_SPEED_8G:
5396 port_speed = LPFC_LINK_SPEED_8GHZ;
5397 break;
5398 case LPFC_FC_LA_SPEED_16G:
5399 port_speed = LPFC_LINK_SPEED_16GHZ;
5400 break;
5401 case LPFC_FC_LA_SPEED_32G:
5402 port_speed = LPFC_LINK_SPEED_32GHZ;
5403 break;
5404 case LPFC_FC_LA_SPEED_64G:
5405 port_speed = LPFC_LINK_SPEED_64GHZ;
5406 break;
5407 case LPFC_FC_LA_SPEED_128G:
5408 port_speed = LPFC_LINK_SPEED_128GHZ;
5409 break;
5410 case LPFC_FC_LA_SPEED_256G:
5411 port_speed = LPFC_LINK_SPEED_256GHZ;
5412 break;
5413 default:
5414 port_speed = 0;
5415 break;
5416 }
5417
5418 return port_speed;
5419}
5420
James Smart74a7baa2021-08-16 09:28:58 -07005421void
5422lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
5423{
5424 struct rxtable_entry *entry;
5425 int cnt = 0, head, tail, last, start;
5426
5427 head = atomic_read(&phba->rxtable_idx_head);
5428 tail = atomic_read(&phba->rxtable_idx_tail);
5429 if (!phba->rxtable || head == tail) {
5430 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
5431 "4411 Rxtable is empty\n");
5432 return;
5433 }
5434 last = tail;
5435 start = head;
5436
5437 /* Display the last LPFC_MAX_RXMONITOR_DUMP entries from the rxtable */
5438 while (start != last) {
5439 if (start)
5440 start--;
5441 else
5442 start = LPFC_MAX_RXMONITOR_ENTRY - 1;
5443 entry = &phba->rxtable[start];
5444 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5445 "4410 %02d: MBPI %lld Xmit %lld Cmpl %lld "
5446 "Lat %lld ASz %lld Info %02d BWUtil %d "
5447 "Int %d slot %d\n",
5448 cnt, entry->max_bytes_per_interval,
5449 entry->total_bytes, entry->rcv_bytes,
5450 entry->avg_io_latency, entry->avg_io_size,
5451 entry->cmf_info, entry->timer_utilization,
5452 entry->timer_interval, start);
5453 cnt++;
5454 if (cnt >= LPFC_MAX_RXMONITOR_DUMP)
5455 return;
5456 }
5457}
5458
James Smart02243832021-08-16 09:28:54 -07005459/**
James Smart7481811c2021-08-16 09:28:56 -07005460 * lpfc_cgn_update_stat - Save data into congestion stats buffer
5461 * @phba: pointer to lpfc hba data structure.
5462 * @dtag: FPIN descriptor received
5463 *
5464 * Increment the FPIN received counter/time when it happens.
5465 */
5466void
5467lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
5468{
5469 struct lpfc_cgn_info *cp;
5470 struct tm broken;
5471 struct timespec64 cur_time;
5472 u32 cnt;
5473 u16 value;
5474
5475 /* Make sure we have a congestion info buffer */
5476 if (!phba->cgn_i)
5477 return;
5478 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5479 ktime_get_real_ts64(&cur_time);
5480 time64_to_tm(cur_time.tv_sec, 0, &broken);
5481
5482 /* Update congestion statistics */
5483 switch (dtag) {
5484 case ELS_DTAG_LNK_INTEGRITY:
5485 cnt = le32_to_cpu(cp->link_integ_notification);
5486 cnt++;
5487 cp->link_integ_notification = cpu_to_le32(cnt);
5488
5489 cp->cgn_stat_lnk_month = broken.tm_mon + 1;
5490 cp->cgn_stat_lnk_day = broken.tm_mday;
5491 cp->cgn_stat_lnk_year = broken.tm_year - 100;
5492 cp->cgn_stat_lnk_hour = broken.tm_hour;
5493 cp->cgn_stat_lnk_min = broken.tm_min;
5494 cp->cgn_stat_lnk_sec = broken.tm_sec;
5495 break;
5496 case ELS_DTAG_DELIVERY:
5497 cnt = le32_to_cpu(cp->delivery_notification);
5498 cnt++;
5499 cp->delivery_notification = cpu_to_le32(cnt);
5500
5501 cp->cgn_stat_del_month = broken.tm_mon + 1;
5502 cp->cgn_stat_del_day = broken.tm_mday;
5503 cp->cgn_stat_del_year = broken.tm_year - 100;
5504 cp->cgn_stat_del_hour = broken.tm_hour;
5505 cp->cgn_stat_del_min = broken.tm_min;
5506 cp->cgn_stat_del_sec = broken.tm_sec;
5507 break;
5508 case ELS_DTAG_PEER_CONGEST:
5509 cnt = le32_to_cpu(cp->cgn_peer_notification);
5510 cnt++;
5511 cp->cgn_peer_notification = cpu_to_le32(cnt);
5512
5513 cp->cgn_stat_peer_month = broken.tm_mon + 1;
5514 cp->cgn_stat_peer_day = broken.tm_mday;
5515 cp->cgn_stat_peer_year = broken.tm_year - 100;
5516 cp->cgn_stat_peer_hour = broken.tm_hour;
5517 cp->cgn_stat_peer_min = broken.tm_min;
5518 cp->cgn_stat_peer_sec = broken.tm_sec;
5519 break;
5520 case ELS_DTAG_CONGESTION:
5521 cnt = le32_to_cpu(cp->cgn_notification);
5522 cnt++;
5523 cp->cgn_notification = cpu_to_le32(cnt);
5524
5525 cp->cgn_stat_cgn_month = broken.tm_mon + 1;
5526 cp->cgn_stat_cgn_day = broken.tm_mday;
5527 cp->cgn_stat_cgn_year = broken.tm_year - 100;
5528 cp->cgn_stat_cgn_hour = broken.tm_hour;
5529 cp->cgn_stat_cgn_min = broken.tm_min;
5530 cp->cgn_stat_cgn_sec = broken.tm_sec;
5531 }
5532 if (phba->cgn_fpin_frequency &&
5533 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5534 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5535 cp->cgn_stat_npm = cpu_to_le32(value);
5536 }
5537 value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5538 LPFC_CGN_CRC32_SEED);
5539 cp->cgn_info_crc = cpu_to_le32(value);
5540}
5541
5542/**
5543 * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer
5544 * @phba: pointer to lpfc hba data structure.
5545 *
5546 * Save the congestion event data every minute.
5547 * On the hour collapse all the minute data into hour data. Every day
5548 * collapse all the hour data into daily data. Separate driver
5549 * and fabrc congestion event counters that will be saved out
5550 * to the registered congestion buffer every minute.
5551 */
5552static void
5553lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba)
5554{
5555 struct lpfc_cgn_info *cp;
5556 struct tm broken;
5557 struct timespec64 cur_time;
5558 uint32_t i, index;
5559 uint16_t value, mvalue;
5560 uint64_t bps;
5561 uint32_t mbps;
5562 uint32_t dvalue, wvalue, lvalue, avalue;
5563 uint64_t latsum;
5564 uint16_t *ptr;
5565 uint32_t *lptr;
5566 uint16_t *mptr;
5567
5568 /* Make sure we have a congestion info buffer */
5569 if (!phba->cgn_i)
5570 return;
5571 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
5572
5573 if (time_before(jiffies, phba->cgn_evt_timestamp))
5574 return;
5575 phba->cgn_evt_timestamp = jiffies +
5576 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
5577 phba->cgn_evt_minute++;
5578
5579 /* We should get to this point in the routine on 1 minute intervals */
5580
5581 ktime_get_real_ts64(&cur_time);
5582 time64_to_tm(cur_time.tv_sec, 0, &broken);
5583
5584 if (phba->cgn_fpin_frequency &&
5585 phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
5586 value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
5587 cp->cgn_stat_npm = cpu_to_le32(value);
5588 }
5589
5590 /* Read and clear the latency counters for this minute */
5591 lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
5592 latsum = atomic64_read(&phba->cgn_latency_evt);
5593 atomic_set(&phba->cgn_latency_evt_cnt, 0);
5594 atomic64_set(&phba->cgn_latency_evt, 0);
5595
5596 /* We need to store MB/sec bandwidth in the congestion information.
5597 * block_cnt is count of 512 byte blocks for the entire minute,
5598 * bps will get bytes per sec before finally converting to MB/sec.
5599 */
5600 bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
5601 phba->rx_block_cnt = 0;
5602 mvalue = bps / (1024 * 1024); /* convert to MB/sec */
5603
5604 /* Every minute */
5605 /* cgn parameters */
5606 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
5607 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
5608 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
5609 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
5610
5611 /* Fill in default LUN qdepth */
5612 value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
5613 cp->cgn_lunq = cpu_to_le16(value);
5614
5615 /* Record congestion buffer info - every minute
5616 * cgn_driver_evt_cnt (Driver events)
5617 * cgn_fabric_warn_cnt (Congestion Warnings)
5618 * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
5619 * cgn_fabric_alarm_cnt (Congestion Alarms)
5620 */
5621 index = ++cp->cgn_index_minute;
5622 if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
5623 cp->cgn_index_minute = 0;
5624 index = 0;
5625 }
5626
5627 /* Get the number of driver events in this sample and reset counter */
5628 dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
5629 atomic_set(&phba->cgn_driver_evt_cnt, 0);
5630
5631 /* Get the number of warning events - FPIN and Signal for this minute */
5632 wvalue = 0;
5633 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
5634 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5635 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5636 wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
5637 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
5638
5639 /* Get the number of alarm events - FPIN and Signal for this minute */
5640 avalue = 0;
5641 if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
5642 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5643 avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
5644 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
5645
5646 /* Collect the driver, warning, alarm and latency counts for this
5647 * minute into the driver congestion buffer.
5648 */
5649 ptr = &cp->cgn_drvr_min[index];
5650 value = (uint16_t)dvalue;
5651 *ptr = cpu_to_le16(value);
5652
5653 ptr = &cp->cgn_warn_min[index];
5654 value = (uint16_t)wvalue;
5655 *ptr = cpu_to_le16(value);
5656
5657 ptr = &cp->cgn_alarm_min[index];
5658 value = (uint16_t)avalue;
5659 *ptr = cpu_to_le16(value);
5660
5661 lptr = &cp->cgn_latency_min[index];
5662 if (lvalue) {
5663 lvalue = (uint32_t)div_u64(latsum, lvalue);
5664 *lptr = cpu_to_le32(lvalue);
5665 } else {
5666 *lptr = 0;
5667 }
5668
5669 /* Collect the bandwidth value into the driver's congesion buffer. */
5670 mptr = &cp->cgn_bw_min[index];
5671 *mptr = cpu_to_le16(mvalue);
5672
5673 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5674 "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
5675 index, dvalue, wvalue, *lptr, mvalue, avalue);
5676
5677 /* Every hour */
5678 if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
5679 /* Record congestion buffer info - every hour
5680 * Collapse all minutes into an hour
5681 */
5682 index = ++cp->cgn_index_hour;
5683 if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
5684 cp->cgn_index_hour = 0;
5685 index = 0;
5686 }
5687
5688 dvalue = 0;
5689 wvalue = 0;
5690 lvalue = 0;
5691 avalue = 0;
5692 mvalue = 0;
5693 mbps = 0;
5694 for (i = 0; i < LPFC_MIN_HOUR; i++) {
5695 dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
5696 wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
5697 lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
5698 mbps += le16_to_cpu(cp->cgn_bw_min[i]);
5699 avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
5700 }
5701 if (lvalue) /* Avg of latency averages */
5702 lvalue /= LPFC_MIN_HOUR;
5703 if (mbps) /* Avg of Bandwidth averages */
5704 mvalue = mbps / LPFC_MIN_HOUR;
5705
5706 lptr = &cp->cgn_drvr_hr[index];
5707 *lptr = cpu_to_le32(dvalue);
5708 lptr = &cp->cgn_warn_hr[index];
5709 *lptr = cpu_to_le32(wvalue);
5710 lptr = &cp->cgn_latency_hr[index];
5711 *lptr = cpu_to_le32(lvalue);
5712 mptr = &cp->cgn_bw_hr[index];
5713 *mptr = cpu_to_le16(mvalue);
5714 lptr = &cp->cgn_alarm_hr[index];
5715 *lptr = cpu_to_le32(avalue);
5716
5717 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5718 "2419 Congestion Info - hour "
5719 "(%d): %d %d %d %d %d\n",
5720 index, dvalue, wvalue, lvalue, mvalue, avalue);
5721 }
5722
5723 /* Every day */
5724 if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
5725 /* Record congestion buffer info - every hour
5726 * Collapse all hours into a day. Rotate days
5727 * after LPFC_MAX_CGN_DAYS.
5728 */
5729 index = ++cp->cgn_index_day;
5730 if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
5731 cp->cgn_index_day = 0;
5732 index = 0;
5733 }
5734
5735 /* Anytime we overwrite daily index 0, after we wrap,
5736 * we will be overwriting the oldest day, so we must
5737 * update the congestion data start time for that day.
5738 * That start time should have previously been saved after
5739 * we wrote the last days worth of data.
5740 */
5741 if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) {
5742 time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken);
5743
5744 cp->cgn_info_month = broken.tm_mon + 1;
5745 cp->cgn_info_day = broken.tm_mday;
5746 cp->cgn_info_year = broken.tm_year - 100;
5747 cp->cgn_info_hour = broken.tm_hour;
5748 cp->cgn_info_minute = broken.tm_min;
5749 cp->cgn_info_second = broken.tm_sec;
5750
5751 lpfc_printf_log
5752 (phba, KERN_INFO, LOG_CGN_MGMT,
5753 "2646 CGNInfo idx0 Start Time: "
5754 "%d/%d/%d %d:%d:%d\n",
5755 cp->cgn_info_day, cp->cgn_info_month,
5756 cp->cgn_info_year, cp->cgn_info_hour,
5757 cp->cgn_info_minute, cp->cgn_info_second);
5758 }
5759
5760 dvalue = 0;
5761 wvalue = 0;
5762 lvalue = 0;
5763 mvalue = 0;
5764 mbps = 0;
5765 avalue = 0;
5766 for (i = 0; i < LPFC_HOUR_DAY; i++) {
5767 dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
5768 wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
5769 lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
5770 mbps += le32_to_cpu(cp->cgn_bw_hr[i]);
5771 avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
5772 }
5773 if (lvalue) /* Avg of latency averages */
5774 lvalue /= LPFC_HOUR_DAY;
5775 if (mbps) /* Avg of Bandwidth averages */
5776 mvalue = mbps / LPFC_HOUR_DAY;
5777
5778 lptr = &cp->cgn_drvr_day[index];
5779 *lptr = cpu_to_le32(dvalue);
5780 lptr = &cp->cgn_warn_day[index];
5781 *lptr = cpu_to_le32(wvalue);
5782 lptr = &cp->cgn_latency_day[index];
5783 *lptr = cpu_to_le32(lvalue);
5784 mptr = &cp->cgn_bw_day[index];
5785 *mptr = cpu_to_le16(mvalue);
5786 lptr = &cp->cgn_alarm_day[index];
5787 *lptr = cpu_to_le32(avalue);
5788
5789 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5790 "2420 Congestion Info - daily (%d): "
5791 "%d %d %d %d %d\n",
5792 index, dvalue, wvalue, lvalue, mvalue, avalue);
5793
5794 /* We just wrote LPFC_MAX_CGN_DAYS of data,
5795 * so we are wrapped on any data after this.
5796 * Save this as the start time for the next day.
5797 */
5798 if (index == (LPFC_MAX_CGN_DAYS - 1)) {
5799 phba->hba_flag |= HBA_CGN_DAY_WRAP;
5800 ktime_get_real_ts64(&phba->cgn_daily_ts);
5801 }
5802 }
5803
5804 /* Use the frequency found in the last rcv'ed FPIN */
5805 value = phba->cgn_fpin_frequency;
5806 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN)
5807 cp->cgn_warn_freq = cpu_to_le16(value);
5808 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM)
5809 cp->cgn_alarm_freq = cpu_to_le16(value);
5810
5811 /* Frequency (in ms) Signal Warning/Signal Congestion Notifications
5812 * are received by the HBA
5813 */
5814 value = phba->cgn_sig_freq;
5815
5816 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
5817 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5818 cp->cgn_warn_freq = cpu_to_le16(value);
5819 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
5820 cp->cgn_alarm_freq = cpu_to_le16(value);
5821
5822 lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
5823 LPFC_CGN_CRC32_SEED);
5824 cp->cgn_info_crc = cpu_to_le32(lvalue);
5825}
5826
5827/**
James Smart02243832021-08-16 09:28:54 -07005828 * lpfc_calc_cmf_latency - latency from start of rxate timer interval
5829 * @phba: The Hba for which this call is being executed.
5830 *
5831 * The routine calculates the latency from the beginning of the CMF timer
5832 * interval to the current point in time. It is called from IO completion
5833 * when we exceed our Bandwidth limitation for the time interval.
5834 */
5835uint32_t
5836lpfc_calc_cmf_latency(struct lpfc_hba *phba)
5837{
5838 struct timespec64 cmpl_time;
5839 uint32_t msec = 0;
5840
5841 ktime_get_real_ts64(&cmpl_time);
5842
5843 /* This routine works on a ms granularity so sec and usec are
5844 * converted accordingly.
5845 */
5846 if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
5847 msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
5848 NSEC_PER_MSEC;
5849 } else {
5850 if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
5851 msec = (cmpl_time.tv_sec -
5852 phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
5853 msec += ((cmpl_time.tv_nsec -
5854 phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
5855 } else {
5856 msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
5857 1) * MSEC_PER_SEC;
5858 msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
5859 cmpl_time.tv_nsec) / NSEC_PER_MSEC);
5860 }
5861 }
5862 return msec;
5863}
5864
5865/**
5866 * lpfc_cmf_timer - This is the timer function for one congestion
5867 * rate interval.
5868 * @timer: Pointer to the high resolution timer that expired
5869 */
5870static enum hrtimer_restart
5871lpfc_cmf_timer(struct hrtimer *timer)
5872{
5873 struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
5874 cmf_timer);
James Smart17b27ac2021-08-16 09:28:55 -07005875 struct rxtable_entry *entry;
James Smart02243832021-08-16 09:28:54 -07005876 uint32_t io_cnt;
James Smart17b27ac2021-08-16 09:28:55 -07005877 uint32_t head, tail;
5878 uint32_t busy, max_read;
James Smartd5ac69b2021-09-10 16:31:55 -07005879 uint64_t total, rcv, lat, mbpi, extra;
James Smart02243832021-08-16 09:28:54 -07005880 int timer_interval = LPFC_CMF_INTERVAL;
James Smart17b27ac2021-08-16 09:28:55 -07005881 uint32_t ms;
James Smart02243832021-08-16 09:28:54 -07005882 struct lpfc_cgn_stat *cgs;
5883 int cpu;
5884
5885 /* Only restart the timer if congestion mgmt is on */
5886 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
5887 !phba->cmf_latency.tv_sec) {
5888 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
5889 "6224 CMF timer exit: %d %lld\n",
5890 phba->cmf_active_mode,
5891 (uint64_t)phba->cmf_latency.tv_sec);
5892 return HRTIMER_NORESTART;
5893 }
5894
5895 /* If pport is not ready yet, just exit and wait for
5896 * the next timer cycle to hit.
5897 */
5898 if (!phba->pport)
5899 goto skip;
5900
5901 /* Do not block SCSI IO while in the timer routine since
5902 * total_bytes will be cleared
5903 */
5904 atomic_set(&phba->cmf_stop_io, 1);
5905
James Smart17b27ac2021-08-16 09:28:55 -07005906 /* First we need to calculate the actual ms between
5907 * the last timer interrupt and this one. We ask for
5908 * LPFC_CMF_INTERVAL, however the actual time may
5909 * vary depending on system overhead.
5910 */
5911 ms = lpfc_calc_cmf_latency(phba);
5912
5913
James Smart02243832021-08-16 09:28:54 -07005914 /* Immediately after we calculate the time since the last
5915 * timer interrupt, set the start time for the next
5916 * interrupt
5917 */
5918 ktime_get_real_ts64(&phba->cmf_latency);
5919
5920 phba->cmf_link_byte_count =
5921 div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
5922
5923 /* Collect all the stats from the prior timer interval */
5924 total = 0;
5925 io_cnt = 0;
5926 lat = 0;
5927 rcv = 0;
5928 for_each_present_cpu(cpu) {
5929 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
5930 total += atomic64_xchg(&cgs->total_bytes, 0);
5931 io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
5932 lat += atomic64_xchg(&cgs->rx_latency, 0);
5933 rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
5934 }
5935
5936 /* Before we issue another CMF_SYNC_WQE, retrieve the BW
5937 * returned from the last CMF_SYNC_WQE issued, from
5938 * cmf_last_sync_bw. This will be the target BW for
5939 * this next timer interval.
5940 */
5941 if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
5942 phba->link_state != LPFC_LINK_DOWN &&
5943 phba->hba_flag & HBA_SETUP) {
5944 mbpi = phba->cmf_last_sync_bw;
5945 phba->cmf_last_sync_bw = 0;
James Smartd5ac69b2021-09-10 16:31:55 -07005946 extra = 0;
5947
5948 /* Calculate any extra bytes needed to account for the
5949 * timer accuracy. If we are less than LPFC_CMF_INTERVAL
5950 * add an extra 3% slop factor, equal to LPFC_CMF_INTERVAL
5951 * add an extra 2%. The goal is to equalize total with a
5952 * time > LPFC_CMF_INTERVAL or <= LPFC_CMF_INTERVAL + 1
5953 */
5954 if (ms == LPFC_CMF_INTERVAL)
5955 extra = div_u64(total, 50);
5956 else if (ms < LPFC_CMF_INTERVAL)
5957 extra = div_u64(total, 33);
5958 lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
James Smart02243832021-08-16 09:28:54 -07005959 } else {
5960 /* For Monitor mode or link down we want mbpi
5961 * to be the full link speed
5962 */
5963 mbpi = phba->cmf_link_byte_count;
5964 }
5965 phba->cmf_timer_cnt++;
5966
5967 if (io_cnt) {
5968 /* Update congestion info buffer latency in us */
5969 atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
5970 atomic64_add(lat, &phba->cgn_latency_evt);
5971 }
James Smart17b27ac2021-08-16 09:28:55 -07005972 busy = atomic_xchg(&phba->cmf_busy, 0);
5973 max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
James Smart02243832021-08-16 09:28:54 -07005974
5975 /* Calculate MBPI for the next timer interval */
5976 if (mbpi) {
5977 if (mbpi > phba->cmf_link_byte_count ||
5978 phba->cmf_active_mode == LPFC_CFG_MONITOR)
5979 mbpi = phba->cmf_link_byte_count;
5980
5981 /* Change max_bytes_per_interval to what the prior
5982 * CMF_SYNC_WQE cmpl indicated.
5983 */
5984 if (mbpi != phba->cmf_max_bytes_per_interval)
5985 phba->cmf_max_bytes_per_interval = mbpi;
5986 }
5987
James Smart17b27ac2021-08-16 09:28:55 -07005988 /* Save rxmonitor information for debug */
5989 if (phba->rxtable) {
5990 head = atomic_xchg(&phba->rxtable_idx_head,
5991 LPFC_RXMONITOR_TABLE_IN_USE);
5992 entry = &phba->rxtable[head];
5993 entry->total_bytes = total;
5994 entry->rcv_bytes = rcv;
5995 entry->cmf_busy = busy;
5996 entry->cmf_info = phba->cmf_active_info;
5997 if (io_cnt) {
5998 entry->avg_io_latency = div_u64(lat, io_cnt);
5999 entry->avg_io_size = div_u64(rcv, io_cnt);
6000 } else {
6001 entry->avg_io_latency = 0;
6002 entry->avg_io_size = 0;
6003 }
6004 entry->max_read_cnt = max_read;
6005 entry->io_cnt = io_cnt;
6006 entry->max_bytes_per_interval = mbpi;
6007 if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
6008 entry->timer_utilization = phba->cmf_last_ts;
6009 else
6010 entry->timer_utilization = ms;
6011 entry->timer_interval = ms;
6012 phba->cmf_last_ts = 0;
6013
6014 /* Increment rxtable index */
6015 head = (head + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6016 tail = atomic_read(&phba->rxtable_idx_tail);
6017 if (head == tail) {
6018 tail = (tail + 1) % LPFC_MAX_RXMONITOR_ENTRY;
6019 atomic_set(&phba->rxtable_idx_tail, tail);
6020 }
6021 atomic_set(&phba->rxtable_idx_head, head);
6022 }
6023
James Smart02243832021-08-16 09:28:54 -07006024 if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
6025 /* If Monitor mode, check if we are oversubscribed
6026 * against the full line rate.
6027 */
6028 if (mbpi && total > mbpi)
6029 atomic_inc(&phba->cgn_driver_evt_cnt);
6030 }
6031 phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
6032
James Smart7481811c2021-08-16 09:28:56 -07006033 /* Each minute save Fabric and Driver congestion information */
6034 lpfc_cgn_save_evt_cnt(phba);
6035
6036 /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the
6037 * minute, adjust our next timer interval, if needed, to ensure a
6038 * 1 minute granularity when we get the next timer interrupt.
6039 */
6040 if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL),
6041 phba->cgn_evt_timestamp)) {
6042 timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp -
6043 jiffies);
6044 if (timer_interval <= 0)
6045 timer_interval = LPFC_CMF_INTERVAL;
6046
6047 /* If we adjust timer_interval, max_bytes_per_interval
6048 * needs to be adjusted as well.
6049 */
6050 phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
6051 timer_interval, 1000);
6052 if (phba->cmf_active_mode == LPFC_CFG_MONITOR)
6053 phba->cmf_max_bytes_per_interval =
6054 phba->cmf_link_byte_count;
6055 }
6056
James Smart02243832021-08-16 09:28:54 -07006057 /* Since total_bytes has already been zero'ed, its okay to unblock
6058 * after max_bytes_per_interval is setup.
6059 */
6060 if (atomic_xchg(&phba->cmf_bw_wait, 0))
6061 queue_work(phba->wq, &phba->unblock_request_work);
6062
6063 /* SCSI IO is now unblocked */
6064 atomic_set(&phba->cmf_stop_io, 0);
6065
6066skip:
6067 hrtimer_forward_now(timer,
6068 ktime_set(0, timer_interval * NSEC_PER_MSEC));
6069 return HRTIMER_RESTART;
6070}
6071
James Smart1dc5ec22018-10-23 13:41:11 -07006072#define trunk_link_status(__idx)\
6073 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6074 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
6075 "Link up" : "Link down") : "NA"
6076/* Did port __idx reported an error */
6077#define trunk_port_fault(__idx)\
6078 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
6079 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
6080
6081static void
6082lpfc_update_trunk_link_status(struct lpfc_hba *phba,
6083 struct lpfc_acqe_fc_la *acqe_fc)
6084{
6085 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
6086 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
6087
6088 phba->sli4_hba.link_state.speed =
6089 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6090 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6091
6092 phba->sli4_hba.link_state.logical_speed =
James Smartb8e6f132019-05-21 17:49:04 -07006093 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart1dc5ec22018-10-23 13:41:11 -07006094 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
6095 phba->fc_linkspeed =
6096 lpfc_async_link_speed_to_read_top(
6097 phba,
6098 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
6099
6100 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
6101 phba->trunk_link.link0.state =
6102 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
6103 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08006104 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07006105 }
6106 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
6107 phba->trunk_link.link1.state =
6108 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
6109 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08006110 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07006111 }
6112 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
6113 phba->trunk_link.link2.state =
6114 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
6115 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08006116 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07006117 }
6118 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
6119 phba->trunk_link.link3.state =
6120 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
6121 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08006122 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07006123 }
6124
Dick Kennedy372c1872020-06-30 14:50:00 -07006125 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1dc5ec22018-10-23 13:41:11 -07006126 "2910 Async FC Trunking Event - Speed:%d\n"
6127 "\tLogical speed:%d "
6128 "port0: %s port1: %s port2: %s port3: %s\n",
6129 phba->sli4_hba.link_state.speed,
6130 phba->sli4_hba.link_state.logical_speed,
6131 trunk_link_status(0), trunk_link_status(1),
6132 trunk_link_status(2), trunk_link_status(3));
6133
James Smart02243832021-08-16 09:28:54 -07006134 if (phba->cmf_active_mode != LPFC_CFG_OFF)
6135 lpfc_cmf_signal_init(phba);
6136
James Smart1dc5ec22018-10-23 13:41:11 -07006137 if (port_fault)
Dick Kennedy372c1872020-06-30 14:50:00 -07006138 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1dc5ec22018-10-23 13:41:11 -07006139 "3202 trunk error:0x%x (%s) seen on port0:%s "
6140 /*
6141 * SLI-4: We have only 0xA error codes
6142 * defined as of now. print an appropriate
6143 * message in case driver needs to be updated.
6144 */
6145 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
6146 "UNDEFINED. update driver." : trunk_errmsg[err],
6147 trunk_port_fault(0), trunk_port_fault(1),
6148 trunk_port_fault(2), trunk_port_fault(3));
6149}
6150
6151
6152/**
James Smart70f3c072010-12-15 17:57:33 -05006153 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
6154 * @phba: pointer to lpfc hba data structure.
6155 * @acqe_fc: pointer to the async fc completion queue entry.
6156 *
6157 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
6158 * that the event was received and then issue a read_topology mailbox command so
6159 * that the rest of the driver will treat it the same as SLI3.
6160 **/
6161static void
6162lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
6163{
6164 struct lpfc_dmabuf *mp;
6165 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07006166 MAILBOX_t *mb;
6167 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05006168 int rc;
6169
6170 if (bf_get(lpfc_trailer_type, acqe_fc) !=
6171 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006172 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05006173 "2895 Non FC link Event detected.(%d)\n",
6174 bf_get(lpfc_trailer_type, acqe_fc));
6175 return;
6176 }
James Smart1dc5ec22018-10-23 13:41:11 -07006177
6178 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6179 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
6180 lpfc_update_trunk_link_status(phba, acqe_fc);
6181 return;
6182 }
6183
James Smart70f3c072010-12-15 17:57:33 -05006184 /* Keep the link status for extra SLI4 state machine reference */
6185 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04006186 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
6187 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05006188 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
6189 phba->sli4_hba.link_state.topology =
6190 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
6191 phba->sli4_hba.link_state.status =
6192 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
6193 phba->sli4_hba.link_state.type =
6194 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
6195 phba->sli4_hba.link_state.number =
6196 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
6197 phba->sli4_hba.link_state.fault =
6198 bf_get(lpfc_acqe_link_fault, acqe_fc);
James Smartb8e6f132019-05-21 17:49:04 -07006199
6200 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
6201 LPFC_FC_LA_TYPE_LINK_DOWN)
6202 phba->sli4_hba.link_state.logical_speed = 0;
6203 else if (!phba->sli4_hba.conf_trunk)
6204 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04006205 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smartb8e6f132019-05-21 17:49:04 -07006206
James Smart70f3c072010-12-15 17:57:33 -05006207 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6208 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
6209 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
6210 "%dMbps Fault:%d\n",
6211 phba->sli4_hba.link_state.speed,
6212 phba->sli4_hba.link_state.topology,
6213 phba->sli4_hba.link_state.status,
6214 phba->sli4_hba.link_state.type,
6215 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04006216 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05006217 phba->sli4_hba.link_state.fault);
6218 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6219 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006220 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05006221 "2897 The mboxq allocation failed\n");
6222 return;
6223 }
6224 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6225 if (!mp) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006226 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05006227 "2898 The lpfc_dmabuf allocation failed\n");
6228 goto out_free_pmb;
6229 }
6230 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
6231 if (!mp->virt) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006232 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart70f3c072010-12-15 17:57:33 -05006233 "2899 The mbuf allocation failed\n");
6234 goto out_free_dmabuf;
6235 }
6236
6237 /* Cleanup any outstanding ELS commands */
6238 lpfc_els_flush_all_cmd(phba);
6239
6240 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08006241 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05006242
6243 /* Update link event statistics */
6244 phba->sli.slistat.link_event++;
6245
6246 /* Create lpfc_handle_latt mailbox command from link ACQE */
6247 lpfc_read_topology(phba, pmb, mp);
6248 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
6249 pmb->vport = phba->pport;
6250
James Smart7bdedb32016-07-06 12:36:00 -07006251 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07006252 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
6253
6254 switch (phba->sli4_hba.link_state.status) {
6255 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
6256 phba->link_flag |= LS_MDS_LINK_DOWN;
6257 break;
6258 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
6259 phba->link_flag |= LS_MDS_LOOPBACK;
6260 break;
6261 default:
6262 break;
6263 }
6264
James Smart23288b72018-05-04 20:37:53 -07006265 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07006266 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07006267 mb->mbxStatus = MBX_SUCCESS;
6268
6269 /* Parse port fault information field */
6270 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07006271
6272 /* Parse and translate link attention fields */
6273 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
6274 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07006275
James Smartaeb3c812017-04-21 16:05:02 -07006276 if (phba->sli4_hba.link_state.status ==
6277 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
6278 bf_set(lpfc_mbx_read_top_att_type, la,
6279 LPFC_FC_LA_TYPE_UNEXP_WWPN);
6280 } else {
6281 bf_set(lpfc_mbx_read_top_att_type, la,
6282 LPFC_FC_LA_TYPE_LINK_DOWN);
6283 }
James Smart7bdedb32016-07-06 12:36:00 -07006284 /* Invoke the mailbox command callback function */
6285 lpfc_mbx_cmpl_read_topology(phba, pmb);
6286
6287 return;
6288 }
6289
James Smart70f3c072010-12-15 17:57:33 -05006290 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
6291 if (rc == MBX_NOT_FINISHED)
6292 goto out_free_dmabuf;
6293 return;
6294
6295out_free_dmabuf:
6296 kfree(mp);
6297out_free_pmb:
6298 mempool_free(pmb, phba->mbox_mem_pool);
6299}
6300
6301/**
6302 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
6303 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01006304 * @acqe_sli: pointer to the async SLI completion queue entry.
James Smart70f3c072010-12-15 17:57:33 -05006305 *
6306 * This routine is to handle the SLI4 asynchronous SLI events.
6307 **/
6308static void
6309lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
6310{
James Smart4b8bae02012-06-12 13:55:07 -04006311 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04006312 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04006313 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04006314 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05006315 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04006316 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04006317 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart9064aeb2021-08-16 09:28:50 -07006318 struct lpfc_acqe_cgn_signal *cgn_signal;
James Smart946727d2015-04-07 15:07:09 -04006319 struct Scsi_Host *shost;
James Smartcd713482018-10-23 13:41:01 -07006320 struct lpfc_vport **vports;
James Smart9064aeb2021-08-16 09:28:50 -07006321 int rc, i, cnt;
James Smart4b8bae02012-06-12 13:55:07 -04006322
James Smart946727d2015-04-07 15:07:09 -04006323 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
6324
James Smart448193b2015-12-16 18:12:05 -05006325 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartd11ed162019-09-21 20:59:03 -07006326 "2901 Async SLI event - Type:%d, Event Data: x%08x "
6327 "x%08x x%08x x%08x\n", evt_type,
James Smart448193b2015-12-16 18:12:05 -05006328 acqe_sli->event_data1, acqe_sli->event_data2,
James Smartd11ed162019-09-21 20:59:03 -07006329 acqe_sli->reserved, acqe_sli->trailer);
James Smart4b8bae02012-06-12 13:55:07 -04006330
6331 port_name = phba->Port[0];
6332 if (port_name == 0x00)
6333 port_name = '?'; /* get port name is empty */
6334
James Smart946727d2015-04-07 15:07:09 -04006335 switch (evt_type) {
6336 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
6337 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6338 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
6339 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6340
6341 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6342 "3190 Over Temperature:%d Celsius- Port Name %c\n",
6343 acqe_sli->event_data1, port_name);
6344
James Smart310429e2016-07-06 12:35:54 -07006345 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04006346 shost = lpfc_shost_from_vport(phba->pport);
6347 fc_host_post_vendor_event(shost, fc_get_event_number(),
6348 sizeof(temp_event_data),
6349 (char *)&temp_event_data,
6350 SCSI_NL_VID_TYPE_PCI
6351 | PCI_VENDOR_ID_EMULEX);
6352 break;
6353 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
6354 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
6355 temp_event_data.event_code = LPFC_NORMAL_TEMP;
6356 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
6357
6358 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6359 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
6360 acqe_sli->event_data1, port_name);
6361
6362 shost = lpfc_shost_from_vport(phba->pport);
6363 fc_host_post_vendor_event(shost, fc_get_event_number(),
6364 sizeof(temp_event_data),
6365 (char *)&temp_event_data,
6366 SCSI_NL_VID_TYPE_PCI
6367 | PCI_VENDOR_ID_EMULEX);
6368 break;
6369 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
6370 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04006371 &acqe_sli->event_data1;
6372
James Smart946727d2015-04-07 15:07:09 -04006373 /* fetch the status for this port */
6374 switch (phba->sli4_hba.lnk_info.lnk_no) {
6375 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05006376 status = bf_get(lpfc_sli_misconfigured_port0_state,
6377 &misconfigured->theEvent);
6378 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04006379 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04006380 break;
6381 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05006382 status = bf_get(lpfc_sli_misconfigured_port1_state,
6383 &misconfigured->theEvent);
6384 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04006385 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04006386 break;
6387 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05006388 status = bf_get(lpfc_sli_misconfigured_port2_state,
6389 &misconfigured->theEvent);
6390 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04006391 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04006392 break;
6393 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05006394 status = bf_get(lpfc_sli_misconfigured_port3_state,
6395 &misconfigured->theEvent);
6396 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04006397 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04006398 break;
6399 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07006400 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart448193b2015-12-16 18:12:05 -05006401 "3296 "
6402 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
6403 "event: Invalid link %d",
6404 phba->sli4_hba.lnk_info.lnk_no);
6405 return;
James Smart946727d2015-04-07 15:07:09 -04006406 }
James Smart4b8bae02012-06-12 13:55:07 -04006407
James Smart448193b2015-12-16 18:12:05 -05006408 /* Skip if optic state unchanged */
6409 if (phba->sli4_hba.lnk_info.optic_state == status)
6410 return;
6411
James Smart946727d2015-04-07 15:07:09 -04006412 switch (status) {
6413 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05006414 sprintf(message, "Physical Link is functional");
6415 break;
James Smart946727d2015-04-07 15:07:09 -04006416 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
6417 sprintf(message, "Optics faulted/incorrectly "
6418 "installed/not installed - Reseat optics, "
6419 "if issue not resolved, replace.");
6420 break;
6421 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
6422 sprintf(message,
6423 "Optics of two types installed - Remove one "
6424 "optic or install matching pair of optics.");
6425 break;
6426 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
6427 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04006428 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04006429 break;
James Smart448193b2015-12-16 18:12:05 -05006430 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
6431 sprintf(message, "Unqualified optics - Replace with "
6432 "Avago optics for Warranty and Technical "
6433 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08006434 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05006435 break;
6436 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
6437 sprintf(message, "Uncertified optics - Replace with "
6438 "Avago-certified optics to enable link "
6439 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08006440 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05006441 break;
James Smart946727d2015-04-07 15:07:09 -04006442 default:
6443 /* firmware is reporting a status we don't know about */
6444 sprintf(message, "Unknown event status x%02x", status);
6445 break;
6446 }
James Smartcd713482018-10-23 13:41:01 -07006447
6448 /* Issue READ_CONFIG mbox command to refresh supported speeds */
6449 rc = lpfc_sli4_read_config(phba);
James Smart3952e912018-10-23 13:41:02 -07006450 if (rc) {
James Smartcd713482018-10-23 13:41:01 -07006451 phba->lmt = 0;
Dick Kennedy372c1872020-06-30 14:50:00 -07006452 lpfc_printf_log(phba, KERN_ERR,
6453 LOG_TRACE_EVENT,
James Smartcd713482018-10-23 13:41:01 -07006454 "3194 Unable to retrieve supported "
James Smart3952e912018-10-23 13:41:02 -07006455 "speeds, rc = 0x%x\n", rc);
James Smartcd713482018-10-23 13:41:01 -07006456 }
6457 vports = lpfc_create_vport_work_array(phba);
6458 if (vports != NULL) {
6459 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6460 i++) {
6461 shost = lpfc_shost_from_vport(vports[i]);
6462 lpfc_host_supported_speeds_set(shost);
6463 }
6464 }
6465 lpfc_destroy_vport_work_array(phba, vports);
6466
James Smart448193b2015-12-16 18:12:05 -05006467 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04006468 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05006469 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04006470 break;
6471 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
6472 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6473 "3192 Remote DPort Test Initiated - "
6474 "Event Data1:x%08x Event Data2: x%08x\n",
6475 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04006476 break;
James Smart02243832021-08-16 09:28:54 -07006477 case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
6478 /* Call FW to obtain active parms */
6479 lpfc_sli4_cgn_parm_chg_evt(phba);
6480 break;
James Smarte7d85952019-10-18 14:18:29 -07006481 case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
6482 /* Misconfigured WWN. Reports that the SLI Port is configured
6483 * to use FA-WWN, but the attached device doesn’t support it.
6484 * No driver action is required.
6485 * Event Data1 - N.A, Event Data2 - N.A
6486 */
6487 lpfc_log_msg(phba, KERN_WARNING, LOG_SLI,
6488 "2699 Misconfigured FA-WWN - Attached device does "
6489 "not support FA-WWN\n");
6490 break;
James Smartd11ed162019-09-21 20:59:03 -07006491 case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
6492 /* EEPROM failure. No driver action is required */
6493 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6494 "2518 EEPROM failure - "
6495 "Event Data1: x%08x Event Data2: x%08x\n",
6496 acqe_sli->event_data1, acqe_sli->event_data2);
6497 break;
James Smart9064aeb2021-08-16 09:28:50 -07006498 case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
6499 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6500 break;
6501 cgn_signal = (struct lpfc_acqe_cgn_signal *)
6502 &acqe_sli->event_data1;
6503 phba->cgn_acqe_cnt++;
6504
6505 cnt = bf_get(lpfc_warn_acqe, cgn_signal);
6506 atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
6507 atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
6508
6509 /* no threshold for CMF, even 1 signal will trigger an event */
6510
6511 /* Alarm overrides warning, so check that first */
6512 if (cgn_signal->alarm_cnt) {
6513 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6514 /* Keep track of alarm cnt for cgn_info */
6515 atomic_add(cgn_signal->alarm_cnt,
6516 &phba->cgn_fabric_alarm_cnt);
6517 /* Keep track of alarm cnt for CMF_SYNC_WQE */
6518 atomic_add(cgn_signal->alarm_cnt,
6519 &phba->cgn_sync_alarm_cnt);
6520 }
6521 } else if (cnt) {
6522 /* signal action needs to be taken */
6523 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
6524 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6525 /* Keep track of warning cnt for cgn_info */
6526 atomic_add(cnt, &phba->cgn_fabric_warn_cnt);
6527 /* Keep track of warning cnt for CMF_SYNC_WQE */
6528 atomic_add(cnt, &phba->cgn_sync_warn_cnt);
6529 }
6530 }
6531 break;
James Smart4b8bae02012-06-12 13:55:07 -04006532 default:
James Smart946727d2015-04-07 15:07:09 -04006533 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartd11ed162019-09-21 20:59:03 -07006534 "3193 Unrecognized SLI event, type: 0x%x",
James Smart946727d2015-04-07 15:07:09 -04006535 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04006536 break;
6537 }
James Smart70f3c072010-12-15 17:57:33 -05006538}
6539
6540/**
James Smartfc2b9892010-02-26 14:15:29 -05006541 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
6542 * @vport: pointer to vport data structure.
6543 *
6544 * This routine is to perform Clear Virtual Link (CVL) on a vport in
6545 * response to a CVL event.
6546 *
6547 * Return the pointer to the ndlp with the vport if successful, otherwise
6548 * return NULL.
6549 **/
6550static struct lpfc_nodelist *
6551lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
6552{
6553 struct lpfc_nodelist *ndlp;
6554 struct Scsi_Host *shost;
6555 struct lpfc_hba *phba;
6556
6557 if (!vport)
6558 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05006559 phba = vport->phba;
6560 if (!phba)
6561 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04006562 ndlp = lpfc_findnode_did(vport, Fabric_DID);
6563 if (!ndlp) {
6564 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07006565 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04006566 if (!ndlp)
6567 return 0;
James Smart78730cf2010-04-06 15:06:30 -04006568 /* Set the node type */
6569 ndlp->nlp_type |= NLP_FABRIC;
6570 /* Put ndlp onto node list */
6571 lpfc_enqueue_node(vport, ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006572 }
James Smart63e801c2010-11-20 23:14:19 -05006573 if ((phba->pport->port_state < LPFC_FLOGI) &&
6574 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05006575 return NULL;
6576 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05006577 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
6578 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05006579 return NULL;
6580 shost = lpfc_shost_from_vport(vport);
6581 if (!shost)
6582 return NULL;
6583 lpfc_linkdown_port(vport);
6584 lpfc_cleanup_pending_mbox(vport);
6585 spin_lock_irq(shost->host_lock);
6586 vport->fc_flag |= FC_VPORT_CVL_RCVD;
6587 spin_unlock_irq(shost->host_lock);
6588
6589 return ndlp;
6590}
6591
6592/**
6593 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
Lee Jonesfe614ac2020-07-23 13:24:22 +01006594 * @phba: pointer to lpfc hba data structure.
James Smartfc2b9892010-02-26 14:15:29 -05006595 *
6596 * This routine is to perform Clear Virtual Link (CVL) on all vports in
6597 * response to a FCF dead event.
6598 **/
6599static void
6600lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
6601{
6602 struct lpfc_vport **vports;
6603 int i;
6604
6605 vports = lpfc_create_vport_work_array(phba);
6606 if (vports)
6607 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
6608 lpfc_sli4_perform_vport_cvl(vports[i]);
6609 lpfc_destroy_vport_work_array(phba, vports);
6610}
6611
6612/**
James Smart76a95d72010-11-20 23:11:48 -05006613 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04006614 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01006615 * @acqe_fip: pointer to the async fcoe completion queue entry.
James Smartda0436e2009-05-22 14:51:39 -04006616 *
6617 * This routine is to handle the SLI4 asynchronous fcoe event.
6618 **/
6619static void
James Smart76a95d72010-11-20 23:11:48 -05006620lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05006621 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04006622{
James Smart70f3c072010-12-15 17:57:33 -05006623 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04006624 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04006625 struct lpfc_vport *vport;
6626 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006627 int active_vlink_present;
6628 struct lpfc_vport **vports;
6629 int i;
James Smartda0436e2009-05-22 14:51:39 -04006630
James Smart70f3c072010-12-15 17:57:33 -05006631 phba->fc_eventTag = acqe_fip->event_tag;
6632 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04006633 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05006634 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
6635 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
6636 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
Dick Kennedy372c1872020-06-30 14:50:00 -07006637 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smarta93ff372010-10-22 11:06:08 -04006638 "2546 New FCF event, evt_tag:x%x, "
6639 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05006640 acqe_fip->event_tag,
6641 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04006642 else
6643 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
6644 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04006645 "2788 FCF param modified event, "
6646 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05006647 acqe_fip->event_tag,
6648 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04006649 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05006650 /*
6651 * During period of FCF discovery, read the FCF
6652 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04006653 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05006654 */
6655 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6656 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04006657 "2779 Read FCF (x%x) for updating "
6658 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05006659 acqe_fip->index);
6660 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05006661 }
James Smart38b92ef2010-08-04 16:11:39 -04006662
6663 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04006664 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04006665 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04006666 spin_unlock_irq(&phba->hbalock);
6667 break;
6668 }
6669 /* If fast FCF failover rescan event is pending, do nothing */
James Smart036cad12018-10-23 13:41:06 -07006670 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
James Smart38b92ef2010-08-04 16:11:39 -04006671 spin_unlock_irq(&phba->hbalock);
6672 break;
6673 }
6674
James Smartc2b97122013-05-31 17:05:36 -04006675 /* If the FCF has been in discovered state, do nothing. */
6676 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04006677 spin_unlock_irq(&phba->hbalock);
6678 break;
6679 }
6680 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006681
James Smart0c9ab6f2010-02-26 14:15:57 -05006682 /* Otherwise, scan the entire FCF table and re-discover SAN */
6683 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04006684 "2770 Start FCF table scan per async FCF "
6685 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05006686 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05006687 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
6688 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04006689 if (rc)
Dick Kennedy372c1872020-06-30 14:50:00 -07006690 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05006691 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04006692 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04006693 break;
6694
James Smart70f3c072010-12-15 17:57:33 -05006695 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
Dick Kennedy372c1872020-06-30 14:50:00 -07006696 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6697 "2548 FCF Table full count 0x%x tag 0x%x\n",
6698 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
6699 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04006700 break;
6701
James Smart70f3c072010-12-15 17:57:33 -05006702 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05006703 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07006704 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6705 "2549 FCF (x%x) disconnected from network, "
6706 "tag:x%x\n", acqe_fip->index,
6707 acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04006708 /*
6709 * If we are in the middle of FCF failover process, clear
6710 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04006711 */
James Smartfc2b9892010-02-26 14:15:29 -05006712 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07006713 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
6714 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05006715 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05006716 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05006717 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05006718 break;
6719 }
James Smart38b92ef2010-08-04 16:11:39 -04006720 spin_unlock_irq(&phba->hbalock);
6721
6722 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05006723 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04006724 break;
6725
6726 /*
6727 * Otherwise, request the port to rediscover the entire FCF
6728 * table for a fast recovery from case that the current FCF
6729 * is no longer valid as we are not in the middle of FCF
6730 * failover process already.
6731 */
James Smartc2b97122013-05-31 17:05:36 -04006732 spin_lock_irq(&phba->hbalock);
6733 /* Mark the fast failover process in progress */
6734 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
6735 spin_unlock_irq(&phba->hbalock);
6736
6737 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
6738 "2771 Start FCF fast failover process due to "
6739 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
6740 "\n", acqe_fip->event_tag, acqe_fip->index);
6741 rc = lpfc_sli4_redisc_fcf_table(phba);
6742 if (rc) {
6743 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
Dick Kennedy372c1872020-06-30 14:50:00 -07006744 LOG_TRACE_EVENT,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01006745 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04006746 "command failed, fail through to FCF "
6747 "dead event\n");
6748 spin_lock_irq(&phba->hbalock);
6749 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
6750 spin_unlock_irq(&phba->hbalock);
6751 /*
6752 * Last resort will fail over by treating this
6753 * as a link down to FCF registration.
6754 */
6755 lpfc_sli4_fcf_dead_failthrough(phba);
6756 } else {
6757 /* Reset FCF roundrobin bmask for new discovery */
6758 lpfc_sli4_clear_fcf_rr_bmask(phba);
6759 /*
6760 * Handling fast FCF failover to a DEAD FCF event is
6761 * considered equalivant to receiving CVL to all vports.
6762 */
6763 lpfc_sli4_perform_all_vport_cvl(phba);
6764 }
James Smartda0436e2009-05-22 14:51:39 -04006765 break;
James Smart70f3c072010-12-15 17:57:33 -05006766 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05006767 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07006768 lpfc_printf_log(phba, KERN_ERR,
6769 LOG_TRACE_EVENT,
James Smart6669f9b2009-10-02 15:16:45 -04006770 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05006771 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04006772
James Smart6669f9b2009-10-02 15:16:45 -04006773 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04006774 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05006775 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04006776 if (!ndlp)
6777 break;
James Smart695a8142010-01-26 23:08:03 -05006778 active_vlink_present = 0;
6779
6780 vports = lpfc_create_vport_work_array(phba);
6781 if (vports) {
6782 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
6783 i++) {
6784 if ((!(vports[i]->fc_flag &
6785 FC_VPORT_CVL_RCVD)) &&
6786 (vports[i]->port_state > LPFC_FDISC)) {
6787 active_vlink_present = 1;
6788 break;
6789 }
6790 }
6791 lpfc_destroy_vport_work_array(phba, vports);
6792 }
6793
James Smartcc823552015-05-21 13:55:26 -04006794 /*
6795 * Don't re-instantiate if vport is marked for deletion.
6796 * If we are here first then vport_delete is going to wait
6797 * for discovery to complete.
6798 */
6799 if (!(vport->load_flag & FC_UNLOADING) &&
6800 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05006801 /*
6802 * If there are other active VLinks present,
6803 * re-instantiate the Vlink using FDISC.
6804 */
James Smart256ec0d2013-04-17 20:14:58 -04006805 mod_timer(&ndlp->nlp_delayfunc,
6806 jiffies + msecs_to_jiffies(1000));
James Smartc6adba12020-11-15 11:26:34 -08006807 spin_lock_irq(&ndlp->lock);
James Smart6669f9b2009-10-02 15:16:45 -04006808 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08006809 spin_unlock_irq(&ndlp->lock);
James Smart695a8142010-01-26 23:08:03 -05006810 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
6811 vport->port_state = LPFC_FDISC;
6812 } else {
James Smartecfd03c2010-02-12 14:41:27 -05006813 /*
6814 * Otherwise, we request port to rediscover
6815 * the entire FCF table for a fast recovery
6816 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05006817 * is no longer valid if we are not already
6818 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05006819 */
James Smartfc2b9892010-02-26 14:15:29 -05006820 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05006821 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05006822 spin_unlock_irq(&phba->hbalock);
6823 break;
6824 }
6825 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05006826 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05006827 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05006828 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
6829 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04006830 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05006831 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05006832 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05006833 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05006834 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
Dick Kennedy372c1872020-06-30 14:50:00 -07006835 LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05006836 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01006837 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05006838 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05006839 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05006840 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05006841 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05006842 /*
6843 * Last resort will be re-try on the
6844 * the current registered FCF entry.
6845 */
6846 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006847 } else
6848 /*
6849 * Reset FCF roundrobin bmask for new
6850 * discovery.
6851 */
James Smart7d791df2011-07-22 18:37:52 -04006852 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04006853 }
6854 break;
James Smartda0436e2009-05-22 14:51:39 -04006855 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07006856 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6857 "0288 Unknown FCoE event type 0x%x event tag "
6858 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04006859 break;
6860 }
6861}
6862
6863/**
6864 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
6865 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01006866 * @acqe_dcbx: pointer to the async dcbx completion queue entry.
James Smartda0436e2009-05-22 14:51:39 -04006867 *
6868 * This routine is to handle the SLI4 asynchronous dcbx event.
6869 **/
6870static void
6871lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
6872 struct lpfc_acqe_dcbx *acqe_dcbx)
6873{
James Smart4d9ab992009-10-02 15:16:39 -04006874 phba->fc_eventTag = acqe_dcbx->event_tag;
Dick Kennedy372c1872020-06-30 14:50:00 -07006875 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04006876 "0290 The SLI4 DCBX asynchronous event is not "
6877 "handled yet\n");
6878}
6879
6880/**
James Smartb19a0612010-04-06 14:48:51 -04006881 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
6882 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01006883 * @acqe_grp5: pointer to the async grp5 completion queue entry.
James Smartb19a0612010-04-06 14:48:51 -04006884 *
6885 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
6886 * is an asynchronous notified of a logical link speed change. The Port
6887 * reports the logical link speed in units of 10Mbps.
6888 **/
6889static void
6890lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
6891 struct lpfc_acqe_grp5 *acqe_grp5)
6892{
6893 uint16_t prev_ll_spd;
6894
6895 phba->fc_eventTag = acqe_grp5->event_tag;
6896 phba->fcoe_eventtag = acqe_grp5->event_tag;
6897 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
6898 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04006899 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04006900 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6901 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04006902 "from %dMbps to %dMbps\n", prev_ll_spd,
6903 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04006904}
6905
6906/**
James Smart02243832021-08-16 09:28:54 -07006907 * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
6908 * @phba: pointer to lpfc hba data structure.
6909 *
6910 * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
6911 * is an asynchronous notification of a request to reset CM stats.
6912 **/
6913static void
6914lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
6915{
6916 if (!phba->cgn_i)
6917 return;
6918 lpfc_init_congestion_stat(phba);
6919}
6920
6921/**
James Smart72df8a452021-08-16 09:28:52 -07006922 * lpfc_cgn_params_val - Validate FW congestion parameters.
6923 * @phba: pointer to lpfc hba data structure.
6924 * @p_cfg_param: pointer to FW provided congestion parameters.
6925 *
6926 * This routine validates the congestion parameters passed
6927 * by the FW to the driver via an ACQE event.
6928 **/
6929static void
6930lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
6931{
6932 spin_lock_irq(&phba->hbalock);
6933
6934 if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
6935 LPFC_CFG_MONITOR)) {
6936 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
6937 "6225 CMF mode param out of range: %d\n",
6938 p_cfg_param->cgn_param_mode);
6939 p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
6940 }
6941
6942 spin_unlock_irq(&phba->hbalock);
6943}
6944
6945/**
6946 * lpfc_cgn_params_parse - Process a FW cong parm change event
6947 * @phba: pointer to lpfc hba data structure.
6948 * @p_cgn_param: pointer to a data buffer with the FW cong params.
6949 * @len: the size of pdata in bytes.
6950 *
6951 * This routine validates the congestion management buffer signature
6952 * from the FW, validates the contents and makes corrections for
6953 * valid, in-range values. If the signature magic is correct and
6954 * after parameter validation, the contents are copied to the driver's
6955 * @phba structure. If the magic is incorrect, an error message is
6956 * logged.
6957 **/
6958static void
6959lpfc_cgn_params_parse(struct lpfc_hba *phba,
6960 struct lpfc_cgn_param *p_cgn_param, uint32_t len)
6961{
James Smart7481811c2021-08-16 09:28:56 -07006962 struct lpfc_cgn_info *cp;
6963 uint32_t crc, oldmode;
James Smart72df8a452021-08-16 09:28:52 -07006964
6965 /* Make sure the FW has encoded the correct magic number to
6966 * validate the congestion parameter in FW memory.
6967 */
6968 if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
6969 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
6970 "4668 FW cgn parm buffer data: "
6971 "magic 0x%x version %d mode %d "
6972 "level0 %d level1 %d "
6973 "level2 %d byte13 %d "
6974 "byte14 %d byte15 %d "
6975 "byte11 %d byte12 %d activeMode %d\n",
6976 p_cgn_param->cgn_param_magic,
6977 p_cgn_param->cgn_param_version,
6978 p_cgn_param->cgn_param_mode,
6979 p_cgn_param->cgn_param_level0,
6980 p_cgn_param->cgn_param_level1,
6981 p_cgn_param->cgn_param_level2,
6982 p_cgn_param->byte13,
6983 p_cgn_param->byte14,
6984 p_cgn_param->byte15,
6985 p_cgn_param->byte11,
6986 p_cgn_param->byte12,
6987 phba->cmf_active_mode);
6988
6989 oldmode = phba->cmf_active_mode;
6990
6991 /* Any parameters out of range are corrected to defaults
6992 * by this routine. No need to fail.
6993 */
6994 lpfc_cgn_params_val(phba, p_cgn_param);
6995
6996 /* Parameters are verified, move them into driver storage */
6997 spin_lock_irq(&phba->hbalock);
6998 memcpy(&phba->cgn_p, p_cgn_param,
6999 sizeof(struct lpfc_cgn_param));
7000
James Smart7481811c2021-08-16 09:28:56 -07007001 /* Update parameters in congestion info buffer now */
7002 if (phba->cgn_i) {
7003 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
7004 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
7005 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
7006 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
7007 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
7008 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
7009 LPFC_CGN_CRC32_SEED);
7010 cp->cgn_info_crc = cpu_to_le32(crc);
7011 }
James Smart72df8a452021-08-16 09:28:52 -07007012 spin_unlock_irq(&phba->hbalock);
7013
7014 phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
7015
7016 switch (oldmode) {
7017 case LPFC_CFG_OFF:
7018 if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
7019 /* Turning CMF on */
James Smart02243832021-08-16 09:28:54 -07007020 lpfc_cmf_start(phba);
James Smart72df8a452021-08-16 09:28:52 -07007021
7022 if (phba->link_state >= LPFC_LINK_UP) {
7023 phba->cgn_reg_fpin =
7024 phba->cgn_init_reg_fpin;
7025 phba->cgn_reg_signal =
7026 phba->cgn_init_reg_signal;
7027 lpfc_issue_els_edc(phba->pport, 0);
7028 }
7029 }
7030 break;
7031 case LPFC_CFG_MANAGED:
7032 switch (phba->cgn_p.cgn_param_mode) {
7033 case LPFC_CFG_OFF:
7034 /* Turning CMF off */
James Smart02243832021-08-16 09:28:54 -07007035 lpfc_cmf_stop(phba);
James Smart72df8a452021-08-16 09:28:52 -07007036 if (phba->link_state >= LPFC_LINK_UP)
7037 lpfc_issue_els_edc(phba->pport, 0);
7038 break;
7039 case LPFC_CFG_MONITOR:
7040 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7041 "4661 Switch from MANAGED to "
7042 "`MONITOR mode\n");
James Smart02243832021-08-16 09:28:54 -07007043 phba->cmf_max_bytes_per_interval =
7044 phba->cmf_link_byte_count;
7045
7046 /* Resume blocked IO - unblock on workqueue */
7047 queue_work(phba->wq,
7048 &phba->unblock_request_work);
James Smart72df8a452021-08-16 09:28:52 -07007049 break;
7050 }
7051 break;
7052 case LPFC_CFG_MONITOR:
7053 switch (phba->cgn_p.cgn_param_mode) {
7054 case LPFC_CFG_OFF:
7055 /* Turning CMF off */
James Smart02243832021-08-16 09:28:54 -07007056 lpfc_cmf_stop(phba);
James Smart72df8a452021-08-16 09:28:52 -07007057 if (phba->link_state >= LPFC_LINK_UP)
7058 lpfc_issue_els_edc(phba->pport, 0);
7059 break;
7060 case LPFC_CFG_MANAGED:
7061 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7062 "4662 Switch from MONITOR to "
7063 "MANAGED mode\n");
James Smart02243832021-08-16 09:28:54 -07007064 lpfc_cmf_signal_init(phba);
James Smart72df8a452021-08-16 09:28:52 -07007065 break;
7066 }
7067 break;
7068 }
7069 } else {
7070 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7071 "4669 FW cgn parm buf wrong magic 0x%x "
7072 "version %d\n", p_cgn_param->cgn_param_magic,
7073 p_cgn_param->cgn_param_version);
7074 }
7075}
7076
7077/**
7078 * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
7079 * @phba: pointer to lpfc hba data structure.
7080 *
7081 * This routine issues a read_object mailbox command to
7082 * get the congestion management parameters from the FW
7083 * parses it and updates the driver maintained values.
7084 *
7085 * Returns
7086 * 0 if the object was empty
7087 * -Eval if an error was encountered
7088 * Count if bytes were read from object
7089 **/
7090int
7091lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
7092{
7093 int ret = 0;
7094 struct lpfc_cgn_param *p_cgn_param = NULL;
7095 u32 *pdata = NULL;
7096 u32 len = 0;
7097
7098 /* Find out if the FW has a new set of congestion parameters. */
7099 len = sizeof(struct lpfc_cgn_param);
7100 pdata = kzalloc(len, GFP_KERNEL);
7101 ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
7102 pdata, len);
7103
7104 /* 0 means no data. A negative means error. A positive means
7105 * bytes were copied.
7106 */
7107 if (!ret) {
7108 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7109 "4670 CGN RD OBJ returns no data\n");
7110 goto rd_obj_err;
7111 } else if (ret < 0) {
7112 /* Some error. Just exit and return it to the caller.*/
7113 goto rd_obj_err;
7114 }
7115
7116 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
7117 "6234 READ CGN PARAMS Successful %d\n", len);
7118
7119 /* Parse data pointer over len and update the phba congestion
7120 * parameters with values passed back. The receive rate values
7121 * may have been altered in FW, but take no action here.
7122 */
7123 p_cgn_param = (struct lpfc_cgn_param *)pdata;
7124 lpfc_cgn_params_parse(phba, p_cgn_param, len);
7125
7126 rd_obj_err:
7127 kfree(pdata);
7128 return ret;
7129}
7130
7131/**
James Smart02243832021-08-16 09:28:54 -07007132 * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
7133 * @phba: pointer to lpfc hba data structure.
7134 *
7135 * The FW generated Async ACQE SLI event calls this routine when
7136 * the event type is an SLI Internal Port Event and the Event Code
7137 * indicates a change to the FW maintained congestion parameters.
7138 *
7139 * This routine executes a Read_Object mailbox call to obtain the
7140 * current congestion parameters maintained in FW and corrects
7141 * the driver's active congestion parameters.
7142 *
7143 * The acqe event is not passed because there is no further data
7144 * required.
7145 *
7146 * Returns nonzero error if event processing encountered an error.
7147 * Zero otherwise for success.
7148 **/
7149static int
7150lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
7151{
7152 int ret = 0;
7153
7154 if (!phba->sli4_hba.pc_sli4_params.cmf) {
7155 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7156 "4664 Cgn Evt when E2E off. Drop event\n");
7157 return -EACCES;
7158 }
7159
7160 /* If the event is claiming an empty object, it's ok. A write
7161 * could have cleared it. Only error is a negative return
7162 * status.
7163 */
7164 ret = lpfc_sli4_cgn_params_read(phba);
7165 if (ret < 0) {
7166 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7167 "4667 Error reading Cgn Params (%d)\n",
7168 ret);
7169 } else if (!ret) {
7170 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
7171 "4673 CGN Event empty object.\n");
7172 }
7173 return ret;
7174}
7175
7176/**
James Smartda0436e2009-05-22 14:51:39 -04007177 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
7178 * @phba: pointer to lpfc hba data structure.
7179 *
7180 * This routine is invoked by the worker thread to process all the pending
7181 * SLI4 asynchronous events.
7182 **/
7183void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
7184{
7185 struct lpfc_cq_event *cq_event;
James Smarte7dab162020-10-20 13:27:12 -07007186 unsigned long iflags;
James Smartda0436e2009-05-22 14:51:39 -04007187
7188 /* First, declare the async event has been handled */
James Smarte7dab162020-10-20 13:27:12 -07007189 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04007190 phba->hba_flag &= ~ASYNC_EVENT;
James Smarte7dab162020-10-20 13:27:12 -07007191 spin_unlock_irqrestore(&phba->hbalock, iflags);
7192
James Smartda0436e2009-05-22 14:51:39 -04007193 /* Now, handle all the async events */
James Smarte7dab162020-10-20 13:27:12 -07007194 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04007195 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
James Smartda0436e2009-05-22 14:51:39 -04007196 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
7197 cq_event, struct lpfc_cq_event, list);
James Smarte7dab162020-10-20 13:27:12 -07007198 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
7199 iflags);
7200
James Smartda0436e2009-05-22 14:51:39 -04007201 /* Process the asynchronous event */
7202 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
7203 case LPFC_TRAILER_CODE_LINK:
7204 lpfc_sli4_async_link_evt(phba,
7205 &cq_event->cqe.acqe_link);
7206 break;
7207 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05007208 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04007209 break;
7210 case LPFC_TRAILER_CODE_DCBX:
7211 lpfc_sli4_async_dcbx_evt(phba,
7212 &cq_event->cqe.acqe_dcbx);
7213 break;
James Smartb19a0612010-04-06 14:48:51 -04007214 case LPFC_TRAILER_CODE_GRP5:
7215 lpfc_sli4_async_grp5_evt(phba,
7216 &cq_event->cqe.acqe_grp5);
7217 break;
James Smart70f3c072010-12-15 17:57:33 -05007218 case LPFC_TRAILER_CODE_FC:
7219 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
7220 break;
7221 case LPFC_TRAILER_CODE_SLI:
7222 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
7223 break;
James Smart02243832021-08-16 09:28:54 -07007224 case LPFC_TRAILER_CODE_CMSTAT:
7225 lpfc_sli4_async_cmstat_evt(phba);
7226 break;
James Smartda0436e2009-05-22 14:51:39 -04007227 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07007228 lpfc_printf_log(phba, KERN_ERR,
7229 LOG_TRACE_EVENT,
Colin Ian King291c2542019-12-18 08:43:01 +00007230 "1804 Invalid asynchronous event code: "
James Smartda0436e2009-05-22 14:51:39 -04007231 "x%x\n", bf_get(lpfc_trailer_code,
7232 &cq_event->cqe.mcqe_cmpl));
7233 break;
7234 }
James Smarte7dab162020-10-20 13:27:12 -07007235
James Smartda0436e2009-05-22 14:51:39 -04007236 /* Free the completion event processed to the free pool */
7237 lpfc_sli4_cq_event_release(phba, cq_event);
James Smarte7dab162020-10-20 13:27:12 -07007238 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04007239 }
James Smarte7dab162020-10-20 13:27:12 -07007240 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
James Smartda0436e2009-05-22 14:51:39 -04007241}
7242
7243/**
James Smartecfd03c2010-02-12 14:41:27 -05007244 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
7245 * @phba: pointer to lpfc hba data structure.
7246 *
7247 * This routine is invoked by the worker thread to process FCF table
7248 * rediscovery pending completion event.
7249 **/
7250void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
7251{
7252 int rc;
7253
7254 spin_lock_irq(&phba->hbalock);
7255 /* Clear FCF rediscovery timeout event */
7256 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
7257 /* Clear driver fast failover FCF record flag */
7258 phba->fcf.failover_rec.flag = 0;
7259 /* Set state for FCF fast failover */
7260 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
7261 spin_unlock_irq(&phba->hbalock);
7262
7263 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05007264 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04007265 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05007266 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05007267 if (rc)
Dick Kennedy372c1872020-06-30 14:50:00 -07007268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05007269 "2747 Issue FCF scan read FCF mailbox "
7270 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05007271}
7272
7273/**
James Smartda0436e2009-05-22 14:51:39 -04007274 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
7275 * @phba: pointer to lpfc hba data structure.
7276 * @dev_grp: The HBA PCI-Device group number.
7277 *
7278 * This routine is invoked to set up the per HBA PCI-Device group function
7279 * API jump table entries.
7280 *
7281 * Return: 0 if success, otherwise -ENODEV
7282 **/
7283int
7284lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05007285{
7286 int rc;
7287
James Smartda0436e2009-05-22 14:51:39 -04007288 /* Set up lpfc PCI-device group */
7289 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05007290
James Smartda0436e2009-05-22 14:51:39 -04007291 /* The LPFC_PCI_DEV_OC uses SLI4 */
7292 if (dev_grp == LPFC_PCI_DEV_OC)
7293 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05007294
James Smartda0436e2009-05-22 14:51:39 -04007295 /* Set up device INIT API function jump table */
7296 rc = lpfc_init_api_table_setup(phba, dev_grp);
7297 if (rc)
7298 return -ENODEV;
7299 /* Set up SCSI API function jump table */
7300 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
7301 if (rc)
7302 return -ENODEV;
7303 /* Set up SLI API function jump table */
7304 rc = lpfc_sli_api_table_setup(phba, dev_grp);
7305 if (rc)
7306 return -ENODEV;
7307 /* Set up MBOX API function jump table */
7308 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
7309 if (rc)
7310 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05007311
James Smartda0436e2009-05-22 14:51:39 -04007312 return 0;
James Smart5b75da22008-12-04 22:39:35 -05007313}
7314
7315/**
James Smart3621a712009-04-06 18:47:14 -04007316 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05007317 * @phba: pointer to lpfc hba data structure.
7318 * @intr_mode: active interrupt mode adopted.
7319 *
7320 * This routine it invoked to log the currently used active interrupt mode
7321 * to the device.
James Smart3772a992009-05-22 14:50:54 -04007322 **/
7323static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05007324{
7325 switch (intr_mode) {
7326 case 0:
7327 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7328 "0470 Enable INTx interrupt mode.\n");
7329 break;
7330 case 1:
7331 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7332 "0481 Enabled MSI interrupt mode.\n");
7333 break;
7334 case 2:
7335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7336 "0480 Enabled MSI-X interrupt mode.\n");
7337 break;
7338 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07007339 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -05007340 "0482 Illegal interrupt mode.\n");
7341 break;
7342 }
7343 return;
7344}
7345
James Smart5b75da22008-12-04 22:39:35 -05007346/**
James Smart3772a992009-05-22 14:50:54 -04007347 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05007348 * @phba: pointer to lpfc hba data structure.
7349 *
James Smart3772a992009-05-22 14:50:54 -04007350 * This routine is invoked to enable the PCI device that is common to all
7351 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05007352 *
7353 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007354 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007355 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05007356 **/
James Smart3772a992009-05-22 14:50:54 -04007357static int
7358lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05007359{
James Smart3772a992009-05-22 14:50:54 -04007360 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05007361
James Smart3772a992009-05-22 14:50:54 -04007362 /* Obtain PCI device reference */
7363 if (!phba->pcidev)
7364 goto out_error;
7365 else
7366 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007367 /* Enable PCI device */
7368 if (pci_enable_device_mem(pdev))
7369 goto out_error;
7370 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02007371 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04007372 goto out_disable_device;
7373 /* Set up device as PCI master and save state for EEH */
7374 pci_set_master(pdev);
7375 pci_try_set_mwi(pdev);
7376 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05007377
James Smart05580562011-05-24 11:40:48 -04007378 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07007379 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04007380 pdev->needs_freset = 1;
7381
James Smart3772a992009-05-22 14:50:54 -04007382 return 0;
James Smart5b75da22008-12-04 22:39:35 -05007383
James Smart3772a992009-05-22 14:50:54 -04007384out_disable_device:
7385 pci_disable_device(pdev);
7386out_error:
Dick Kennedy372c1872020-06-30 14:50:00 -07007387 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02007388 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04007389 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05007390}
7391
7392/**
James Smart3772a992009-05-22 14:50:54 -04007393 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05007394 * @phba: pointer to lpfc hba data structure.
7395 *
James Smart3772a992009-05-22 14:50:54 -04007396 * This routine is invoked to disable the PCI device that is common to all
7397 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05007398 **/
7399static void
James Smart3772a992009-05-22 14:50:54 -04007400lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05007401{
James Smart3772a992009-05-22 14:50:54 -04007402 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05007403
James Smart3772a992009-05-22 14:50:54 -04007404 /* Obtain PCI device reference */
7405 if (!phba->pcidev)
7406 return;
7407 else
7408 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007409 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02007410 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04007411 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05007412
7413 return;
7414}
7415
7416/**
James Smart3772a992009-05-22 14:50:54 -04007417 * lpfc_reset_hba - Reset a hba
7418 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04007419 *
James Smart3772a992009-05-22 14:50:54 -04007420 * This routine is invoked to reset a hba device. It brings the HBA
7421 * offline, performs a board restart, and then brings the board back
7422 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
7423 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04007424 **/
James Smart3772a992009-05-22 14:50:54 -04007425void
7426lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05007427{
James Smart3772a992009-05-22 14:50:54 -04007428 /* If resets are disabled then set error state and return. */
7429 if (!phba->cfg_enable_hba_reset) {
7430 phba->link_state = LPFC_HBA_ERROR;
7431 return;
7432 }
James Smart9ec58ec2021-01-04 10:02:35 -08007433
7434 /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
7435 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
James Smartee620212014-04-04 13:51:53 -04007436 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart9ec58ec2021-01-04 10:02:35 -08007437 } else {
James Smartee620212014-04-04 13:51:53 -04007438 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart9ec58ec2021-01-04 10:02:35 -08007439 lpfc_sli_flush_io_rings(phba);
7440 }
James Smart3772a992009-05-22 14:50:54 -04007441 lpfc_offline(phba);
7442 lpfc_sli_brdrestart(phba);
7443 lpfc_online(phba);
7444 lpfc_unblock_mgmt_io(phba);
7445}
dea31012005-04-17 16:05:31 -05007446
James Smart3772a992009-05-22 14:50:54 -04007447/**
James Smart0a96e972011-07-22 18:37:28 -04007448 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
7449 * @phba: pointer to lpfc hba data structure.
7450 *
7451 * This function enables the PCI SR-IOV virtual functions to a physical
7452 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7453 * enable the number of virtual functions to the physical function. As
7454 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7455 * API call does not considered as an error condition for most of the device.
7456 **/
7457uint16_t
7458lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
7459{
7460 struct pci_dev *pdev = phba->pcidev;
7461 uint16_t nr_virtfn;
7462 int pos;
7463
James Smart0a96e972011-07-22 18:37:28 -04007464 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
7465 if (pos == 0)
7466 return 0;
7467
7468 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
7469 return nr_virtfn;
7470}
7471
7472/**
James Smart912e3ac2011-05-24 11:42:11 -04007473 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
7474 * @phba: pointer to lpfc hba data structure.
7475 * @nr_vfn: number of virtual functions to be enabled.
7476 *
7477 * This function enables the PCI SR-IOV virtual functions to a physical
7478 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
7479 * enable the number of virtual functions to the physical function. As
7480 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
7481 * API call does not considered as an error condition for most of the device.
7482 **/
7483int
7484lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
7485{
7486 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04007487 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04007488 int rc;
7489
James Smart0a96e972011-07-22 18:37:28 -04007490 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
7491 if (nr_vfn > max_nr_vfn) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007492 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a96e972011-07-22 18:37:28 -04007493 "3057 Requested vfs (%d) greater than "
7494 "supported vfs (%d)", nr_vfn, max_nr_vfn);
7495 return -EINVAL;
7496 }
7497
James Smart912e3ac2011-05-24 11:42:11 -04007498 rc = pci_enable_sriov(pdev, nr_vfn);
7499 if (rc) {
7500 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7501 "2806 Failed to enable sriov on this device "
7502 "with vfn number nr_vf:%d, rc:%d\n",
7503 nr_vfn, rc);
7504 } else
7505 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7506 "2807 Successful enable sriov on this device "
7507 "with vfn number nr_vf:%d\n", nr_vfn);
7508 return rc;
7509}
7510
James Smart02243832021-08-16 09:28:54 -07007511static void
7512lpfc_unblock_requests_work(struct work_struct *work)
7513{
7514 struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
7515 unblock_request_work);
7516
7517 lpfc_unblock_requests(phba);
7518}
7519
James Smart912e3ac2011-05-24 11:42:11 -04007520/**
James Smart895427b2017-02-12 13:52:30 -08007521 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04007522 * @phba: pointer to lpfc hba data structure.
7523 *
James Smart895427b2017-02-12 13:52:30 -08007524 * This routine is invoked to set up the driver internal resources before the
7525 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04007526 *
7527 * Return codes
James Smart895427b2017-02-12 13:52:30 -08007528 * 0 - successful
7529 * other values - error
James Smart3772a992009-05-22 14:50:54 -04007530 **/
7531static int
James Smart895427b2017-02-12 13:52:30 -08007532lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04007533{
James Smart895427b2017-02-12 13:52:30 -08007534 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05007535
James Smart3772a992009-05-22 14:50:54 -04007536 /*
James Smart895427b2017-02-12 13:52:30 -08007537 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04007538 */
James Smart895427b2017-02-12 13:52:30 -08007539 atomic_set(&phba->fast_event_count, 0);
Dick Kennedy372c1872020-06-30 14:50:00 -07007540 atomic_set(&phba->dbg_log_idx, 0);
7541 atomic_set(&phba->dbg_log_cnt, 0);
7542 atomic_set(&phba->dbg_log_dmping, 0);
James Smart895427b2017-02-12 13:52:30 -08007543 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007544
James Smart523128e2018-09-10 10:30:46 -07007545 /* Initialize port_list spinlock */
7546 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08007547 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07007548
James Smart895427b2017-02-12 13:52:30 -08007549 INIT_LIST_HEAD(&phba->work_list);
7550 init_waitqueue_head(&phba->wait_4_mlo_m_q);
7551
7552 /* Initialize the wait queue head for the kernel thread */
7553 init_waitqueue_head(&phba->work_waitq);
7554
7555 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08007556 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08007557 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
7558 "SCSI" : " "),
7559 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08007560 "NVME" : " "),
7561 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08007562
James Smart0794d602019-01-28 11:14:19 -08007563 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
7564 spin_lock_init(&phba->scsi_buf_list_get_lock);
7565 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
7566 spin_lock_init(&phba->scsi_buf_list_put_lock);
7567 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart895427b2017-02-12 13:52:30 -08007568
7569 /* Initialize the fabric iocb list */
7570 INIT_LIST_HEAD(&phba->fabric_iocb_list);
7571
7572 /* Initialize list to save ELS buffers */
7573 INIT_LIST_HEAD(&phba->elsbuf);
7574
7575 /* Initialize FCF connection rec list */
7576 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
7577
7578 /* Initialize OAS configuration list */
7579 spin_lock_init(&phba->devicelock);
7580 INIT_LIST_HEAD(&phba->luns);
7581
James Smart3772a992009-05-22 14:50:54 -04007582 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007583 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04007584 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007585 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04007586 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007587 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08007588 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007589 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08007590
James Smart32517fc2019-01-28 11:14:33 -08007591 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
7592
Dick Kennedy317aeb82020-06-30 14:49:59 -07007593 INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
7594 lpfc_idle_stat_delay_work);
James Smart02243832021-08-16 09:28:54 -07007595 INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
James Smart895427b2017-02-12 13:52:30 -08007596 return 0;
7597}
7598
7599/**
7600 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
7601 * @phba: pointer to lpfc hba data structure.
7602 *
7603 * This routine is invoked to set up the driver internal resources specific to
7604 * support the SLI-3 HBA device it attached to.
7605 *
7606 * Return codes
7607 * 0 - successful
7608 * other values - error
7609 **/
7610static int
7611lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
7612{
James Smart0794d602019-01-28 11:14:19 -08007613 int rc, entry_sz;
James Smart895427b2017-02-12 13:52:30 -08007614
7615 /*
7616 * Initialize timers used by driver
7617 */
7618
7619 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007620 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04007621
7622 /* Host attention work mask setup */
7623 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
7624 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
7625
7626 /* Get all the module params for configuring this host */
7627 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08007628 /* Set up phase-1 common device driver resources */
7629
7630 rc = lpfc_setup_driver_resource_phase1(phba);
7631 if (rc)
7632 return -ENODEV;
7633
James Smart49198b32010-04-06 15:04:33 -04007634 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
7635 phba->menlo_flag |= HBA_MENLO_SUPPORT;
7636 /* check for menlo minimum sg count */
7637 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
7638 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
7639 }
7640
James Smart895427b2017-02-12 13:52:30 -08007641 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07007642 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
7643 sizeof(struct lpfc_sli_ring),
7644 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08007645 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04007646 return -ENOMEM;
7647
James Smart3772a992009-05-22 14:50:54 -04007648 /*
James Smart96f70772013-04-17 20:16:15 -04007649 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04007650 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04007651 */
James Smart3772a992009-05-22 14:50:54 -04007652
James Smart0794d602019-01-28 11:14:19 -08007653 if (phba->sli_rev == LPFC_SLI_REV4)
7654 entry_sz = sizeof(struct sli4_sge);
7655 else
7656 entry_sz = sizeof(struct ulp_bde64);
7657
James Smart96f70772013-04-17 20:16:15 -04007658 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
7659 if (phba->cfg_enable_bg) {
7660 /*
7661 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
7662 * the FCP rsp, and a BDE for each. Sice we have no control
7663 * over how many protection data segments the SCSI Layer
7664 * will hand us (ie: there could be one for every block
7665 * in the IO), we just allocate enough BDEs to accomidate
7666 * our max amount and we need to limit lpfc_sg_seg_cnt to
7667 * minimize the risk of running out.
7668 */
7669 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7670 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08007671 (LPFC_MAX_SG_SEG_CNT * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04007672
7673 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
7674 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
7675
7676 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
7677 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
7678 } else {
7679 /*
7680 * The scsi_buf for a regular I/O will hold the FCP cmnd,
7681 * the FCP rsp, a BDE for each, and a BDE for up to
7682 * cfg_sg_seg_cnt data segments.
7683 */
7684 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
7685 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08007686 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04007687
7688 /* Total BDEs in BPL for scsi_sg_list */
7689 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
7690 }
7691
7692 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smartc90b4482020-03-22 11:12:56 -07007693 "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
James Smart96f70772013-04-17 20:16:15 -04007694 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
7695 phba->cfg_total_seg_cnt);
7696
James Smart3772a992009-05-22 14:50:54 -04007697 phba->max_vpi = LPFC_MAX_VPI;
7698 /* This will be set to correct value after config_port mbox */
7699 phba->max_vports = 0;
7700
7701 /*
7702 * Initialize the SLI Layer to run with lpfc HBAs.
7703 */
7704 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08007705 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04007706
7707 /* Allocate device driver memory */
7708 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
7709 return -ENOMEM;
7710
James Smartd79c9e92019-08-14 16:57:09 -07007711 phba->lpfc_sg_dma_buf_pool =
7712 dma_pool_create("lpfc_sg_dma_buf_pool",
7713 &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
7714 BPL_ALIGN_SZ, 0);
7715
7716 if (!phba->lpfc_sg_dma_buf_pool)
7717 goto fail_free_mem;
7718
7719 phba->lpfc_cmd_rsp_buf_pool =
7720 dma_pool_create("lpfc_cmd_rsp_buf_pool",
7721 &phba->pcidev->dev,
7722 sizeof(struct fcp_cmnd) +
7723 sizeof(struct fcp_rsp),
7724 BPL_ALIGN_SZ, 0);
7725
7726 if (!phba->lpfc_cmd_rsp_buf_pool)
7727 goto fail_free_dma_buf_pool;
7728
James Smart912e3ac2011-05-24 11:42:11 -04007729 /*
7730 * Enable sr-iov virtual functions if supported and configured
7731 * through the module parameter.
7732 */
7733 if (phba->cfg_sriov_nr_virtfn > 0) {
7734 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
7735 phba->cfg_sriov_nr_virtfn);
7736 if (rc) {
7737 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7738 "2808 Requested number of SR-IOV "
7739 "virtual functions (%d) is not "
7740 "supported\n",
7741 phba->cfg_sriov_nr_virtfn);
7742 phba->cfg_sriov_nr_virtfn = 0;
7743 }
7744 }
7745
James Smart3772a992009-05-22 14:50:54 -04007746 return 0;
James Smartd79c9e92019-08-14 16:57:09 -07007747
7748fail_free_dma_buf_pool:
7749 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
7750 phba->lpfc_sg_dma_buf_pool = NULL;
7751fail_free_mem:
7752 lpfc_mem_free(phba);
7753 return -ENOMEM;
James Smart3772a992009-05-22 14:50:54 -04007754}
7755
7756/**
7757 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
7758 * @phba: pointer to lpfc hba data structure.
7759 *
7760 * This routine is invoked to unset the driver internal resources set up
7761 * specific for supporting the SLI-3 HBA device it attached to.
7762 **/
7763static void
7764lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
7765{
7766 /* Free device driver memory allocated */
7767 lpfc_mem_free_all(phba);
7768
7769 return;
7770}
7771
7772/**
James Smartda0436e2009-05-22 14:51:39 -04007773 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
7774 * @phba: pointer to lpfc hba data structure.
7775 *
7776 * This routine is invoked to set up the driver internal resources specific to
7777 * support the SLI-4 HBA device it attached to.
7778 *
7779 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007780 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007781 * other values - error
7782 **/
7783static int
7784lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
7785{
James Smart28baac72010-02-12 14:42:03 -05007786 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08007787 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08007788 int rc, i, max_buf_size;
James Smart09294d42013-04-17 20:16:05 -04007789 int longs;
James Smart81e6a632017-11-20 16:00:43 -08007790 int extra;
James Smartf358dd02017-02-12 13:52:34 -08007791 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07007792 u32 if_type;
7793 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04007794
James Smart895427b2017-02-12 13:52:30 -08007795 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smarteede4972019-11-21 09:55:56 -08007796 phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
James Smart895427b2017-02-12 13:52:30 -08007797 phba->sli4_hba.curr_disp_cpu = 0;
7798
James Smart716d3bc2013-09-06 12:18:28 -04007799 /* Get all the module params for configuring this host */
7800 lpfc_get_cfgparam(phba);
7801
James Smart895427b2017-02-12 13:52:30 -08007802 /* Set up phase-1 common device driver resources */
7803 rc = lpfc_setup_driver_resource_phase1(phba);
7804 if (rc)
7805 return -ENODEV;
7806
James Smartda0436e2009-05-22 14:51:39 -04007807 /* Before proceed, wait for POST done and device ready */
7808 rc = lpfc_sli4_post_status_check(phba);
7809 if (rc)
7810 return -ENODEV;
7811
James Smart3cee98d2019-08-14 16:56:34 -07007812 /* Allocate all driver workqueues here */
7813
7814 /* The lpfc_wq workqueue for deferred irq use */
7815 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7816
James Smartda0436e2009-05-22 14:51:39 -04007817 /*
7818 * Initialize timers used by driver
7819 */
7820
Kees Cookf22eb4d2017-09-06 20:24:26 -07007821 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04007822
James Smartecfd03c2010-02-12 14:41:27 -05007823 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07007824 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05007825
James Smart02243832021-08-16 09:28:54 -07007826 /* CMF congestion timer */
7827 hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
7828 phba->cmf_timer.function = lpfc_cmf_timer;
7829
James Smartda0436e2009-05-22 14:51:39 -04007830 /*
James Smart7ad20aa2011-05-24 11:44:28 -04007831 * Control structure for handling external multi-buffer mailbox
7832 * command pass-through.
7833 */
7834 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
7835 sizeof(struct lpfc_mbox_ext_buf_ctx));
7836 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
7837
James Smartda0436e2009-05-22 14:51:39 -04007838 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04007839
James Smartda0436e2009-05-22 14:51:39 -04007840 /* This will be set to correct value after the read_config mbox */
7841 phba->max_vports = 0;
7842
7843 /* Program the default value of vlan_id and fc_map */
7844 phba->valid_vlan = 0;
7845 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
7846 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
7847 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
7848
7849 /*
James Smart2a76a282012-08-03 12:35:54 -04007850 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08007851 * we will associate a new ring, for each EQ/CQ/WQ tuple.
7852 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04007853 */
James Smart085c6472010-11-20 23:11:37 -05007854
James Smartda0436e2009-05-22 14:51:39 -04007855 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08007856 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04007857 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
7858 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
7859
Gaurav Srivastava20397172021-06-08 10:05:54 +05307860 /* for VMID idle timeout if VMID is enabled */
7861 if (lpfc_is_vmid_enabled(phba))
7862 timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
7863
James Smartda0436e2009-05-22 14:51:39 -04007864 /*
7865 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
7866 */
James Smartc00f62e2019-08-14 16:57:11 -07007867 /* Initialize the Abort buffer list used by driver */
7868 spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
7869 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
James Smart895427b2017-02-12 13:52:30 -08007870
7871 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7872 /* Initialize the Abort nvme buffer list used by driver */
James Smart5e5b5112019-01-28 11:14:22 -08007873 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07007874 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07007875 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart79d8c4c2019-05-21 17:48:56 -07007876 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
7877 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
James Smart895427b2017-02-12 13:52:30 -08007878 }
7879
James Smartda0436e2009-05-22 14:51:39 -04007880 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08007881 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07007882 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smarte7dab162020-10-20 13:27:12 -07007883 spin_lock_init(&phba->sli4_hba.asynce_list_lock);
7884 spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04007885
7886 /*
James Smart6d368e52011-05-24 11:44:12 -04007887 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04007888 */
7889
7890 /* Driver internel slow-path CQ Event pool */
7891 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
7892 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04007893 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04007894 /* Asynchronous event CQ Event work queue list */
7895 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
James Smartda0436e2009-05-22 14:51:39 -04007896 /* Slow-path XRI aborted CQ Event work queue list */
7897 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
7898 /* Receive queue CQ Event work queue list */
7899 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
7900
James Smart6d368e52011-05-24 11:44:12 -04007901 /* Initialize extent block lists. */
7902 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
7903 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
7904 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
7905 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
7906
James Smartd1f525a2017-04-21 16:04:55 -07007907 /* Initialize mboxq lists. If the early init routines fail
7908 * these lists need to be correctly initialized.
7909 */
7910 INIT_LIST_HEAD(&phba->sli.mboxq);
7911 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
7912
James Smart448193b2015-12-16 18:12:05 -05007913 /* initialize optic_state to 0xFF */
7914 phba->sli4_hba.lnk_info.optic_state = 0xff;
7915
James Smartda0436e2009-05-22 14:51:39 -04007916 /* Allocate device driver memory */
7917 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
7918 if (rc)
7919 return -ENOMEM;
7920
James Smart2fcee4b2010-12-15 17:57:46 -05007921 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08007922 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05007923 LPFC_SLI_INTF_IF_TYPE_2) {
7924 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08007925 if (unlikely(rc)) {
7926 rc = -ENODEV;
7927 goto out_free_mem;
7928 }
James Smart946727d2015-04-07 15:07:09 -04007929 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05007930 }
7931
James Smartda0436e2009-05-22 14:51:39 -04007932 /* Create the bootstrap mailbox command */
7933 rc = lpfc_create_bootstrap_mbox(phba);
7934 if (unlikely(rc))
7935 goto out_free_mem;
7936
7937 /* Set up the host's endian order with the device. */
7938 rc = lpfc_setup_endian_order(phba);
7939 if (unlikely(rc))
7940 goto out_free_bsmbx;
7941
7942 /* Set up the hba's configuration parameters. */
7943 rc = lpfc_sli4_read_config(phba);
7944 if (unlikely(rc))
7945 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05007946 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
7947 if (unlikely(rc))
7948 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04007949
James Smart2fcee4b2010-12-15 17:57:46 -05007950 /* IF Type 0 ports get initialized now. */
7951 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7952 LPFC_SLI_INTF_IF_TYPE_0) {
7953 rc = lpfc_pci_function_reset(phba);
7954 if (unlikely(rc))
7955 goto out_free_bsmbx;
7956 }
James Smartda0436e2009-05-22 14:51:39 -04007957
James Smartcb5172e2010-03-15 11:25:07 -04007958 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7959 GFP_KERNEL);
7960 if (!mboxq) {
7961 rc = -ENOMEM;
7962 goto out_free_bsmbx;
7963 }
7964
James Smartf358dd02017-02-12 13:52:34 -08007965 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08007966 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08007967 if (lpfc_enable_nvmet_cnt) {
7968
7969 /* First get WWN of HBA instance */
7970 lpfc_read_nv(phba, mboxq);
7971 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7972 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007973 lpfc_printf_log(phba, KERN_ERR,
7974 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08007975 "6016 Mailbox failed , mbxCmd x%x "
7976 "READ_NV, mbxStatus x%x\n",
7977 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7978 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07007979 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08007980 rc = -EIO;
7981 goto out_free_bsmbx;
7982 }
7983 mb = &mboxq->u.mb;
7984 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
7985 sizeof(uint64_t));
7986 wwn = cpu_to_be64(wwn);
7987 phba->sli4_hba.wwnn.u.name = wwn;
7988 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
7989 sizeof(uint64_t));
7990 /* wwn is WWPN of HBA instance */
7991 wwn = cpu_to_be64(wwn);
7992 phba->sli4_hba.wwpn.u.name = wwn;
7993
7994 /* Check to see if it matches any module parameter */
7995 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
7996 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08007997#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07007998 if (lpfc_nvmet_mem_alloc(phba))
7999 break;
8000
8001 phba->nvmet_support = 1; /* a match */
8002
Dick Kennedy372c1872020-06-30 14:50:00 -07008003 lpfc_printf_log(phba, KERN_ERR,
8004 LOG_TRACE_EVENT,
James Smartf358dd02017-02-12 13:52:34 -08008005 "6017 NVME Target %016llx\n",
8006 wwn);
James Smart7d708032017-03-08 14:36:01 -08008007#else
Dick Kennedy372c1872020-06-30 14:50:00 -07008008 lpfc_printf_log(phba, KERN_ERR,
8009 LOG_TRACE_EVENT,
James Smart7d708032017-03-08 14:36:01 -08008010 "6021 Can't enable NVME Target."
8011 " NVME_TARGET_FC infrastructure"
8012 " is not in kernel\n");
8013#endif
James Smartc4908502019-01-28 11:14:28 -08008014 /* Not supported for NVMET */
8015 phba->cfg_xri_rebalancing = 0;
Dick Kennedy3048e3e2020-05-01 14:43:06 -07008016 if (phba->irq_chann_mode == NHT_MODE) {
8017 phba->cfg_irq_chann =
8018 phba->sli4_hba.num_present_cpu;
8019 phba->cfg_hdw_queue =
8020 phba->sli4_hba.num_present_cpu;
8021 phba->irq_chann_mode = NORMAL_MODE;
8022 }
James Smart3c603be2017-05-15 15:20:44 -07008023 break;
James Smartf358dd02017-02-12 13:52:34 -08008024 }
8025 }
8026 }
James Smart895427b2017-02-12 13:52:30 -08008027
8028 lpfc_nvme_mod_param_dep(phba);
8029
James Smartfedd3b72011-02-16 12:39:24 -05008030 /*
8031 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04008032 * If this call fails, it isn't critical unless the SLI4 parameters come
8033 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05008034 */
James Smart6d368e52011-05-24 11:44:12 -04008035 rc = lpfc_get_sli4_parameters(phba, mboxq);
8036 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07008037 if_type = bf_get(lpfc_sli_intf_if_type,
8038 &phba->sli4_hba.sli_intf);
8039 if_fam = bf_get(lpfc_sli_intf_sli_family,
8040 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04008041 if (phba->sli4_hba.extents_in_use &&
8042 phba->sli4_hba.rpi_hdrs_in_use) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008043 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8044 "2999 Unsupported SLI4 Parameters "
8045 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07008046 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8047 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
8048 mempool_free(mboxq, phba->mbox_mem_pool);
8049 rc = -EIO;
8050 goto out_free_bsmbx;
8051 }
James Smart6d368e52011-05-24 11:44:12 -04008052 }
James Smartb92dc722018-05-24 21:09:01 -07008053 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
8054 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
8055 mempool_free(mboxq, phba->mbox_mem_pool);
8056 rc = -EIO;
8057 goto out_free_bsmbx;
8058 }
James Smart6d368e52011-05-24 11:44:12 -04008059 }
James Smart895427b2017-02-12 13:52:30 -08008060
James Smartd79c9e92019-08-14 16:57:09 -07008061 /*
8062 * 1 for cmd, 1 for rsp, NVME adds an extra one
8063 * for boundary conditions in its max_sgl_segment template.
8064 */
8065 extra = 2;
8066 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
8067 extra++;
8068
8069 /*
8070 * It doesn't matter what family our adapter is in, we are
8071 * limited to 2 Pages, 512 SGEs, for our SGL.
8072 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
8073 */
8074 max_buf_size = (2 * SLI4_PAGE_SIZE);
8075
8076 /*
8077 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
8078 * used to create the sg_dma_buf_pool must be calculated.
8079 */
8080 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8081 /* Both cfg_enable_bg and cfg_external_dif code paths */
8082
8083 /*
8084 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
8085 * the FCP rsp, and a SGE. Sice we have no control
8086 * over how many protection segments the SCSI Layer
8087 * will hand us (ie: there could be one for every block
8088 * in the IO), just allocate enough SGEs to accomidate
8089 * our max amount and we need to limit lpfc_sg_seg_cnt
8090 * to minimize the risk of running out.
8091 */
8092 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8093 sizeof(struct fcp_rsp) + max_buf_size;
8094
8095 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
8096 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
8097
8098 /*
8099 * If supporting DIF, reduce the seg count for scsi to
8100 * allow room for the DIF sges.
8101 */
8102 if (phba->cfg_enable_bg &&
8103 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
8104 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
8105 else
8106 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8107
8108 } else {
8109 /*
8110 * The scsi_buf for a regular I/O holds the FCP cmnd,
8111 * the FCP rsp, a SGE for each, and a SGE for up to
8112 * cfg_sg_seg_cnt data segments.
8113 */
8114 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
8115 sizeof(struct fcp_rsp) +
8116 ((phba->cfg_sg_seg_cnt + extra) *
8117 sizeof(struct sli4_sge));
8118
8119 /* Total SGEs for scsi_sg_list */
8120 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
8121 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
8122
8123 /*
8124 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
8125 * need to post 1 page for the SGL.
8126 */
8127 }
8128
8129 if (phba->cfg_xpsgl && !phba->nvmet_support)
8130 phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
8131 else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
8132 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
8133 else
8134 phba->cfg_sg_dma_buf_size =
8135 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
8136
8137 phba->border_sge_num = phba->cfg_sg_dma_buf_size /
8138 sizeof(struct sli4_sge);
8139
8140 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
8141 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8142 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
8143 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
8144 "6300 Reducing NVME sg segment "
8145 "cnt to %d\n",
8146 LPFC_MAX_NVME_SEG_CNT);
8147 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
8148 } else
8149 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
8150 }
8151
James Smartd79c9e92019-08-14 16:57:09 -07008152 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
8153 "9087 sg_seg_cnt:%d dmabuf_size:%d "
8154 "total:%d scsi:%d nvme:%d\n",
8155 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
8156 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
8157 phba->cfg_nvme_seg_cnt);
8158
8159 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
8160 i = phba->cfg_sg_dma_buf_size;
8161 else
8162 i = SLI4_PAGE_SIZE;
8163
8164 phba->lpfc_sg_dma_buf_pool =
8165 dma_pool_create("lpfc_sg_dma_buf_pool",
8166 &phba->pcidev->dev,
8167 phba->cfg_sg_dma_buf_size,
8168 i, 0);
8169 if (!phba->lpfc_sg_dma_buf_pool)
8170 goto out_free_bsmbx;
8171
8172 phba->lpfc_cmd_rsp_buf_pool =
8173 dma_pool_create("lpfc_cmd_rsp_buf_pool",
8174 &phba->pcidev->dev,
8175 sizeof(struct fcp_cmnd) +
8176 sizeof(struct fcp_rsp),
8177 i, 0);
8178 if (!phba->lpfc_cmd_rsp_buf_pool)
8179 goto out_free_sg_dma_buf;
8180
James Smartcb5172e2010-03-15 11:25:07 -04008181 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05008182
8183 /* Verify OAS is supported */
8184 lpfc_sli4_oas_verify(phba);
James Smart1ba981f2014-02-20 09:56:45 -05008185
James Smartd2cc9bc2018-09-10 10:30:50 -07008186 /* Verify RAS support on adapter */
8187 lpfc_sli4_ras_init(phba);
8188
James Smart5350d872011-10-10 21:33:49 -04008189 /* Verify all the SLI4 queues */
8190 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04008191 if (rc)
James Smartd79c9e92019-08-14 16:57:09 -07008192 goto out_free_cmd_rsp_buf;
James Smartda0436e2009-05-22 14:51:39 -04008193
8194 /* Create driver internal CQE event pool */
8195 rc = lpfc_sli4_cq_event_pool_create(phba);
8196 if (rc)
James Smartd79c9e92019-08-14 16:57:09 -07008197 goto out_free_cmd_rsp_buf;
James Smartda0436e2009-05-22 14:51:39 -04008198
James Smart8a9d2e82012-05-09 21:16:12 -04008199 /* Initialize sgl lists per host */
8200 lpfc_init_sgl_list(phba);
8201
8202 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04008203 rc = lpfc_init_active_sgl_array(phba);
8204 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04008206 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04008207 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04008208 }
James Smartda0436e2009-05-22 14:51:39 -04008209 rc = lpfc_sli4_init_rpi_hdrs(phba);
8210 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008211 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04008212 "1432 Failed to initialize rpi headers.\n");
8213 goto out_free_active_sgl;
8214 }
8215
James Smarta93ff372010-10-22 11:06:08 -04008216 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05008217 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07008218 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05008219 GFP_KERNEL);
8220 if (!phba->fcf.fcf_rr_bmask) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008221 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05008222 "2759 Failed allocate memory for FCF round "
8223 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04008224 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05008225 goto out_remove_rpi_hdrs;
8226 }
8227
James Smart6a828b02019-01-28 11:14:31 -08008228 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08008229 sizeof(struct lpfc_hba_eq_hdl),
8230 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08008231 if (!phba->sli4_hba.hba_eq_hdl) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008232 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart67d12732012-08-03 12:36:13 -04008233 "2572 Failed allocate memory for "
8234 "fast-path per-EQ handle array\n");
8235 rc = -ENOMEM;
8236 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04008237 }
8238
James Smart222e9232019-01-28 11:14:35 -08008239 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
James Smart895427b2017-02-12 13:52:30 -08008240 sizeof(struct lpfc_vector_map_info),
8241 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04008242 if (!phba->sli4_hba.cpu_map) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008243 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7bb03bb2013-04-17 20:19:16 -04008244 "3327 Failed allocate memory for msi-x "
8245 "interrupt vector mapping\n");
8246 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008247 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04008248 }
James Smartb246de12013-05-31 17:03:07 -04008249
James Smart32517fc2019-01-28 11:14:33 -08008250 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
8251 if (!phba->sli4_hba.eq_info) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008252 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart32517fc2019-01-28 11:14:33 -08008253 "3321 Failed allocation for per_cpu stats\n");
8254 rc = -ENOMEM;
8255 goto out_free_hba_cpu_map;
8256 }
James Smart840eda92020-03-22 11:13:00 -07008257
Dick Kennedy317aeb82020-06-30 14:49:59 -07008258 phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
8259 sizeof(*phba->sli4_hba.idle_stat),
8260 GFP_KERNEL);
8261 if (!phba->sli4_hba.idle_stat) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008262 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedy317aeb82020-06-30 14:49:59 -07008263 "3390 Failed allocation for idle_stat\n");
8264 rc = -ENOMEM;
8265 goto out_free_hba_eq_info;
8266 }
8267
James Smart840eda92020-03-22 11:13:00 -07008268#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8269 phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
8270 if (!phba->sli4_hba.c_stat) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008271 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart840eda92020-03-22 11:13:00 -07008272 "3332 Failed allocating per cpu hdwq stats\n");
8273 rc = -ENOMEM;
Dick Kennedy317aeb82020-06-30 14:49:59 -07008274 goto out_free_hba_idle_stat;
James Smart840eda92020-03-22 11:13:00 -07008275 }
8276#endif
8277
James Smart02243832021-08-16 09:28:54 -07008278 phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
8279 if (!phba->cmf_stat) {
8280 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8281 "3331 Failed allocating per cpu cgn stats\n");
8282 rc = -ENOMEM;
8283 goto out_free_hba_hdwq_info;
8284 }
8285
James Smart912e3ac2011-05-24 11:42:11 -04008286 /*
8287 * Enable sr-iov virtual functions if supported and configured
8288 * through the module parameter.
8289 */
8290 if (phba->cfg_sriov_nr_virtfn > 0) {
8291 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
8292 phba->cfg_sriov_nr_virtfn);
8293 if (rc) {
8294 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8295 "3020 Requested number of SR-IOV "
8296 "virtual functions (%d) is not "
8297 "supported\n",
8298 phba->cfg_sriov_nr_virtfn);
8299 phba->cfg_sriov_nr_virtfn = 0;
8300 }
8301 }
8302
James Smart5248a742011-07-22 18:37:06 -04008303 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008304
James Smart02243832021-08-16 09:28:54 -07008305out_free_hba_hdwq_info:
8306 free_percpu(phba->sli4_hba.c_stat);
James Smart840eda92020-03-22 11:13:00 -07008307#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
Dick Kennedy317aeb82020-06-30 14:49:59 -07008308out_free_hba_idle_stat:
8309 kfree(phba->sli4_hba.idle_stat);
8310#endif
James Smart840eda92020-03-22 11:13:00 -07008311out_free_hba_eq_info:
8312 free_percpu(phba->sli4_hba.eq_info);
James Smart32517fc2019-01-28 11:14:33 -08008313out_free_hba_cpu_map:
8314 kfree(phba->sli4_hba.cpu_map);
James Smart895427b2017-02-12 13:52:30 -08008315out_free_hba_eq_hdl:
8316 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05008317out_free_fcf_rr_bmask:
8318 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04008319out_remove_rpi_hdrs:
8320 lpfc_sli4_remove_rpi_hdrs(phba);
8321out_free_active_sgl:
8322 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04008323out_destroy_cq_event_pool:
8324 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartd79c9e92019-08-14 16:57:09 -07008325out_free_cmd_rsp_buf:
8326 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
8327 phba->lpfc_cmd_rsp_buf_pool = NULL;
8328out_free_sg_dma_buf:
8329 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
8330 phba->lpfc_sg_dma_buf_pool = NULL;
James Smartda0436e2009-05-22 14:51:39 -04008331out_free_bsmbx:
8332 lpfc_destroy_bootstrap_mbox(phba);
8333out_free_mem:
8334 lpfc_mem_free(phba);
8335 return rc;
8336}
8337
8338/**
8339 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
8340 * @phba: pointer to lpfc hba data structure.
8341 *
8342 * This routine is invoked to unset the driver internal resources set up
8343 * specific for supporting the SLI-4 HBA device it attached to.
8344 **/
8345static void
8346lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
8347{
8348 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
8349
James Smart32517fc2019-01-28 11:14:33 -08008350 free_percpu(phba->sli4_hba.eq_info);
James Smart840eda92020-03-22 11:13:00 -07008351#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
8352 free_percpu(phba->sli4_hba.c_stat);
8353#endif
James Smart02243832021-08-16 09:28:54 -07008354 free_percpu(phba->cmf_stat);
Dick Kennedy317aeb82020-06-30 14:49:59 -07008355 kfree(phba->sli4_hba.idle_stat);
James Smart32517fc2019-01-28 11:14:33 -08008356
James Smart7bb03bb2013-04-17 20:19:16 -04008357 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
8358 kfree(phba->sli4_hba.cpu_map);
James Smart222e9232019-01-28 11:14:35 -08008359 phba->sli4_hba.num_possible_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04008360 phba->sli4_hba.num_present_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05008361 phba->sli4_hba.curr_disp_cpu = 0;
Dick Kennedy3048e3e2020-05-01 14:43:06 -07008362 cpumask_clear(&phba->sli4_hba.irq_aff_mask);
James Smart7bb03bb2013-04-17 20:19:16 -04008363
James Smartda0436e2009-05-22 14:51:39 -04008364 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08008365 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04008366
8367 /* Free the allocated rpi headers. */
8368 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04008369 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04008370
James Smart0c9ab6f2010-02-26 14:15:57 -05008371 /* Free eligible FCF index bmask */
8372 kfree(phba->fcf.fcf_rr_bmask);
8373
James Smartda0436e2009-05-22 14:51:39 -04008374 /* Free the ELS sgl list */
8375 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04008376 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08008377 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04008378
James Smartda0436e2009-05-22 14:51:39 -04008379 /* Free the completion queue EQ event pool */
8380 lpfc_sli4_cq_event_release_all(phba);
8381 lpfc_sli4_cq_event_pool_destroy(phba);
8382
James Smart6d368e52011-05-24 11:44:12 -04008383 /* Release resource identifiers. */
8384 lpfc_sli4_dealloc_resource_identifiers(phba);
8385
James Smartda0436e2009-05-22 14:51:39 -04008386 /* Free the bsmbx region. */
8387 lpfc_destroy_bootstrap_mbox(phba);
8388
8389 /* Free the SLI Layer memory with SLI4 HBAs */
8390 lpfc_mem_free_all(phba);
8391
8392 /* Free the current connect table */
8393 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04008394 &phba->fcf_conn_rec_list, list) {
8395 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04008396 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04008397 }
James Smartda0436e2009-05-22 14:51:39 -04008398
8399 return;
8400}
8401
8402/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008403 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04008404 * @phba: The hba struct for which this call is being executed.
8405 * @dev_grp: The HBA PCI-Device group number.
8406 *
8407 * This routine sets up the device INIT interface API function jump table
8408 * in @phba struct.
8409 *
8410 * Returns: 0 - success, -ENODEV - failure.
8411 **/
8412int
8413lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8414{
James Smart84d1b002010-02-12 14:42:33 -05008415 phba->lpfc_hba_init_link = lpfc_hba_init_link;
8416 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05008417 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04008418 switch (dev_grp) {
8419 case LPFC_PCI_DEV_LP:
8420 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
8421 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
8422 phba->lpfc_stop_port = lpfc_stop_port_s3;
8423 break;
James Smartda0436e2009-05-22 14:51:39 -04008424 case LPFC_PCI_DEV_OC:
8425 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
8426 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
8427 phba->lpfc_stop_port = lpfc_stop_port_s4;
8428 break;
James Smart3772a992009-05-22 14:50:54 -04008429 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07008430 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -04008431 "1431 Invalid HBA PCI-device group: 0x%x\n",
8432 dev_grp);
8433 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04008434 }
8435 return 0;
8436}
8437
8438/**
James Smart3772a992009-05-22 14:50:54 -04008439 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
8440 * @phba: pointer to lpfc hba data structure.
8441 *
8442 * This routine is invoked to set up the driver internal resources after the
8443 * device specific resource setup to support the HBA device it attached to.
8444 *
8445 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008446 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008447 * other values - error
8448 **/
8449static int
8450lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
8451{
8452 int error;
8453
8454 /* Startup the kernel thread for this host adapter. */
8455 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8456 "lpfc_worker_%d", phba->brd_no);
8457 if (IS_ERR(phba->worker_thread)) {
8458 error = PTR_ERR(phba->worker_thread);
8459 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05008460 }
8461
James Smart3772a992009-05-22 14:50:54 -04008462 return 0;
8463}
8464
8465/**
8466 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
8467 * @phba: pointer to lpfc hba data structure.
8468 *
8469 * This routine is invoked to unset the driver internal resources set up after
8470 * the device specific resource setup for supporting the HBA device it
8471 * attached to.
8472 **/
8473static void
8474lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
8475{
Dick Kennedyf485c182017-09-29 17:34:34 -07008476 if (phba->wq) {
8477 flush_workqueue(phba->wq);
8478 destroy_workqueue(phba->wq);
8479 phba->wq = NULL;
8480 }
8481
James Smart3772a992009-05-22 14:50:54 -04008482 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07008483 if (phba->worker_thread)
8484 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04008485}
8486
8487/**
8488 * lpfc_free_iocb_list - Free iocb list.
8489 * @phba: pointer to lpfc hba data structure.
8490 *
8491 * This routine is invoked to free the driver's IOCB list and memory.
8492 **/
James Smart6c621a22017-05-15 15:20:45 -07008493void
James Smart3772a992009-05-22 14:50:54 -04008494lpfc_free_iocb_list(struct lpfc_hba *phba)
8495{
8496 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
8497
8498 spin_lock_irq(&phba->hbalock);
8499 list_for_each_entry_safe(iocbq_entry, iocbq_next,
8500 &phba->lpfc_iocb_list, list) {
8501 list_del(&iocbq_entry->list);
8502 kfree(iocbq_entry);
8503 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05008504 }
James Smart3772a992009-05-22 14:50:54 -04008505 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008506
James Smart3772a992009-05-22 14:50:54 -04008507 return;
8508}
dea31012005-04-17 16:05:31 -05008509
James Smart3772a992009-05-22 14:50:54 -04008510/**
8511 * lpfc_init_iocb_list - Allocate and initialize iocb list.
8512 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01008513 * @iocb_count: number of requested iocbs
James Smart3772a992009-05-22 14:50:54 -04008514 *
8515 * This routine is invoked to allocate and initizlize the driver's IOCB
8516 * list and set up the IOCB tag array accordingly.
8517 *
8518 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008519 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008520 * other values - error
8521 **/
James Smart6c621a22017-05-15 15:20:45 -07008522int
James Smart3772a992009-05-22 14:50:54 -04008523lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
8524{
8525 struct lpfc_iocbq *iocbq_entry = NULL;
8526 uint16_t iotag;
8527 int i;
dea31012005-04-17 16:05:31 -05008528
8529 /* Initialize and populate the iocb list per host. */
8530 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04008531 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07008532 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05008533 if (iocbq_entry == NULL) {
8534 printk(KERN_ERR "%s: only allocated %d iocbs of "
8535 "expected %d count. Unloading driver.\n",
James Smarta5f73372019-09-21 20:58:50 -07008536 __func__, i, iocb_count);
dea31012005-04-17 16:05:31 -05008537 goto out_free_iocbq;
8538 }
8539
James Bottomley604a3e32005-10-29 10:28:33 -05008540 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
8541 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04008542 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05008543 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04008544 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05008545 goto out_free_iocbq;
8546 }
James Smart6d368e52011-05-24 11:44:12 -04008547 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04008548 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05008549
8550 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008551 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
8552 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05008553 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008554 }
8555
James Smart3772a992009-05-22 14:50:54 -04008556 return 0;
8557
8558out_free_iocbq:
8559 lpfc_free_iocb_list(phba);
8560
8561 return -ENOMEM;
8562}
8563
8564/**
James Smart8a9d2e82012-05-09 21:16:12 -04008565 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04008566 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04008567 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04008568 *
James Smart8a9d2e82012-05-09 21:16:12 -04008569 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04008570 **/
James Smart8a9d2e82012-05-09 21:16:12 -04008571void
8572lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04008573{
8574 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04008575
8576 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
8577 list_del(&sglq_entry->list);
8578 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
8579 kfree(sglq_entry);
8580 }
8581}
8582
8583/**
8584 * lpfc_free_els_sgl_list - Free els sgl list.
8585 * @phba: pointer to lpfc hba data structure.
8586 *
8587 * This routine is invoked to free the driver's els sgl list and memory.
8588 **/
8589static void
8590lpfc_free_els_sgl_list(struct lpfc_hba *phba)
8591{
James Smartda0436e2009-05-22 14:51:39 -04008592 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04008593
James Smart8a9d2e82012-05-09 21:16:12 -04008594 /* Retrieve all els sgls from driver list */
James Smarta7892412021-04-11 18:31:15 -07008595 spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
James Smart895427b2017-02-12 13:52:30 -08008596 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
James Smarta7892412021-04-11 18:31:15 -07008597 spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04008598
James Smart8a9d2e82012-05-09 21:16:12 -04008599 /* Now free the sgl list */
8600 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04008601}
8602
8603/**
James Smartf358dd02017-02-12 13:52:34 -08008604 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
8605 * @phba: pointer to lpfc hba data structure.
8606 *
8607 * This routine is invoked to free the driver's nvmet sgl list and memory.
8608 **/
8609static void
8610lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
8611{
8612 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8613 LIST_HEAD(sglq_list);
8614
8615 /* Retrieve all nvmet sgls from driver list */
8616 spin_lock_irq(&phba->hbalock);
8617 spin_lock(&phba->sli4_hba.sgl_list_lock);
8618 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
8619 spin_unlock(&phba->sli4_hba.sgl_list_lock);
8620 spin_unlock_irq(&phba->hbalock);
8621
8622 /* Now free the sgl list */
8623 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
8624 list_del(&sglq_entry->list);
8625 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
8626 kfree(sglq_entry);
8627 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07008628
8629 /* Update the nvmet_xri_cnt to reflect no current sgls.
8630 * The next initialization cycle sets the count and allocates
8631 * the sgls over again.
8632 */
8633 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08008634}
8635
8636/**
James Smartda0436e2009-05-22 14:51:39 -04008637 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
8638 * @phba: pointer to lpfc hba data structure.
8639 *
8640 * This routine is invoked to allocate the driver's active sgl memory.
8641 * This array will hold the sglq_entry's for active IOs.
8642 **/
8643static int
8644lpfc_init_active_sgl_array(struct lpfc_hba *phba)
8645{
8646 int size;
8647 size = sizeof(struct lpfc_sglq *);
8648 size *= phba->sli4_hba.max_cfg_param.max_xri;
8649
8650 phba->sli4_hba.lpfc_sglq_active_list =
8651 kzalloc(size, GFP_KERNEL);
8652 if (!phba->sli4_hba.lpfc_sglq_active_list)
8653 return -ENOMEM;
8654 return 0;
8655}
8656
8657/**
8658 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
8659 * @phba: pointer to lpfc hba data structure.
8660 *
8661 * This routine is invoked to walk through the array of active sglq entries
8662 * and free all of the resources.
8663 * This is just a place holder for now.
8664 **/
8665static void
8666lpfc_free_active_sgl(struct lpfc_hba *phba)
8667{
8668 kfree(phba->sli4_hba.lpfc_sglq_active_list);
8669}
8670
8671/**
8672 * lpfc_init_sgl_list - Allocate and initialize sgl list.
8673 * @phba: pointer to lpfc hba data structure.
8674 *
8675 * This routine is invoked to allocate and initizlize the driver's sgl
8676 * list and set up the sgl xritag tag array accordingly.
8677 *
James Smartda0436e2009-05-22 14:51:39 -04008678 **/
James Smart8a9d2e82012-05-09 21:16:12 -04008679static void
James Smartda0436e2009-05-22 14:51:39 -04008680lpfc_init_sgl_list(struct lpfc_hba *phba)
8681{
James Smartda0436e2009-05-22 14:51:39 -04008682 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08008683 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04008684 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08008685 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07008686 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04008687
James Smart8a9d2e82012-05-09 21:16:12 -04008688 /* els xri-sgl book keeping */
8689 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04008690
James Smart895427b2017-02-12 13:52:30 -08008691 /* nvme xri-buffer book keeping */
James Smart5e5b5112019-01-28 11:14:22 -08008692 phba->sli4_hba.io_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04008693}
8694
8695/**
8696 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
8697 * @phba: pointer to lpfc hba data structure.
8698 *
8699 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04008700 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04008701 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04008702 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
8703 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04008704 *
8705 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008706 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04008707 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04008708 **/
8709int
8710lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
8711{
8712 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008713 struct lpfc_rpi_hdr *rpi_hdr;
8714
8715 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05008716 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04008717 return rc;
James Smart6d368e52011-05-24 11:44:12 -04008718 if (phba->sli4_hba.extents_in_use)
8719 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04008720
8721 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
8722 if (!rpi_hdr) {
Dick Kennedy372c1872020-06-30 14:50:00 -07008723 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04008724 "0391 Error during rpi post operation\n");
8725 lpfc_sli4_remove_rpis(phba);
8726 rc = -ENODEV;
8727 }
8728
8729 return rc;
8730}
8731
8732/**
8733 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
8734 * @phba: pointer to lpfc hba data structure.
8735 *
8736 * This routine is invoked to allocate a single 4KB memory region to
8737 * support rpis and stores them in the phba. This single region
8738 * provides support for up to 64 rpis. The region is used globally
8739 * by the device.
8740 *
8741 * Returns:
8742 * A valid rpi hdr on success.
8743 * A NULL pointer on any failure.
8744 **/
8745struct lpfc_rpi_hdr *
8746lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
8747{
8748 uint16_t rpi_limit, curr_rpi_range;
8749 struct lpfc_dmabuf *dmabuf;
8750 struct lpfc_rpi_hdr *rpi_hdr;
8751
James Smart6d368e52011-05-24 11:44:12 -04008752 /*
8753 * If the SLI4 port supports extents, posting the rpi header isn't
8754 * required. Set the expected maximum count and let the actual value
8755 * get set when extents are fully allocated.
8756 */
8757 if (!phba->sli4_hba.rpi_hdrs_in_use)
8758 return NULL;
8759 if (phba->sli4_hba.extents_in_use)
8760 return NULL;
8761
8762 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07008763 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04008764
8765 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04008766 /*
8767 * Establish the starting RPI in this header block. The starting
8768 * rpi is normalized to a zero base because the physical rpi is
8769 * port based.
8770 */
James Smart97f2ecf2012-03-01 22:35:23 -05008771 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04008772 spin_unlock_irq(&phba->hbalock);
8773
James Smart845d9e82017-05-15 15:20:38 -07008774 /* Reached full RPI range */
8775 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04008776 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07008777
James Smartda0436e2009-05-22 14:51:39 -04008778 /*
8779 * First allocate the protocol header region for the port. The
8780 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
8781 */
8782 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8783 if (!dmabuf)
8784 return NULL;
8785
Luis Chamberlain750afb02019-01-04 09:23:09 +01008786 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8787 LPFC_HDR_TEMPLATE_SIZE,
8788 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04008789 if (!dmabuf->virt) {
8790 rpi_hdr = NULL;
8791 goto err_free_dmabuf;
8792 }
8793
James Smartda0436e2009-05-22 14:51:39 -04008794 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
8795 rpi_hdr = NULL;
8796 goto err_free_coherent;
8797 }
8798
8799 /* Save the rpi header data for cleanup later. */
8800 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
8801 if (!rpi_hdr)
8802 goto err_free_coherent;
8803
8804 rpi_hdr->dmabuf = dmabuf;
8805 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
8806 rpi_hdr->page_count = 1;
8807 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04008808
8809 /* The rpi_hdr stores the logical index only. */
8810 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07008811 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04008812 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
8813
James Smartda0436e2009-05-22 14:51:39 -04008814 spin_unlock_irq(&phba->hbalock);
8815 return rpi_hdr;
8816
8817 err_free_coherent:
8818 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
8819 dmabuf->virt, dmabuf->phys);
8820 err_free_dmabuf:
8821 kfree(dmabuf);
8822 return NULL;
8823}
8824
8825/**
8826 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
8827 * @phba: pointer to lpfc hba data structure.
8828 *
8829 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04008830 * to support rpis for SLI4 ports not supporting extents. This routine
8831 * presumes the caller has released all rpis consumed by fabric or port
8832 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04008833 **/
8834void
8835lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
8836{
8837 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
8838
James Smart6d368e52011-05-24 11:44:12 -04008839 if (!phba->sli4_hba.rpi_hdrs_in_use)
8840 goto exit;
8841
James Smartda0436e2009-05-22 14:51:39 -04008842 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
8843 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
8844 list_del(&rpi_hdr->list);
8845 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
8846 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
8847 kfree(rpi_hdr->dmabuf);
8848 kfree(rpi_hdr);
8849 }
James Smart6d368e52011-05-24 11:44:12 -04008850 exit:
8851 /* There are no rpis available to the port now. */
8852 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04008853}
8854
8855/**
James Smart3772a992009-05-22 14:50:54 -04008856 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
8857 * @pdev: pointer to pci device data structure.
8858 *
8859 * This routine is invoked to allocate the driver hba data structure for an
8860 * HBA device. If the allocation is successful, the phba reference to the
8861 * PCI device data structure is set.
8862 *
8863 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008864 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04008865 * NULL - error
8866 **/
8867static struct lpfc_hba *
8868lpfc_hba_alloc(struct pci_dev *pdev)
8869{
8870 struct lpfc_hba *phba;
8871
8872 /* Allocate memory for HBA structure */
8873 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
8874 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02008875 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04008876 return NULL;
8877 }
8878
8879 /* Set reference to PCI device in HBA structure */
8880 phba->pcidev = pdev;
8881
8882 /* Assign an unused board number */
8883 phba->brd_no = lpfc_get_instance();
8884 if (phba->brd_no < 0) {
8885 kfree(phba);
8886 return NULL;
8887 }
James Smart65791f12016-07-06 12:35:56 -07008888 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04008889
James Smart4fede782010-01-26 23:08:55 -05008890 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04008891 INIT_LIST_HEAD(&phba->ct_ev_waiters);
8892
James Smart3772a992009-05-22 14:50:54 -04008893 return phba;
8894}
8895
8896/**
8897 * lpfc_hba_free - Free driver hba data structure with a device.
8898 * @phba: pointer to lpfc hba data structure.
8899 *
8900 * This routine is invoked to free the driver hba data structure with an
8901 * HBA device.
8902 **/
8903static void
8904lpfc_hba_free(struct lpfc_hba *phba)
8905{
James Smart5e5b5112019-01-28 11:14:22 -08008906 if (phba->sli_rev == LPFC_SLI_REV4)
8907 kfree(phba->sli4_hba.hdwq);
8908
James Smart3772a992009-05-22 14:50:54 -04008909 /* Release the driver assigned board number */
8910 idr_remove(&lpfc_hba_index, phba->brd_no);
8911
James Smart895427b2017-02-12 13:52:30 -08008912 /* Free memory allocated with sli3 rings */
8913 kfree(phba->sli.sli3_ring);
8914 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04008915
James Smart3772a992009-05-22 14:50:54 -04008916 kfree(phba);
8917 return;
8918}
8919
8920/**
8921 * lpfc_create_shost - Create hba physical port with associated scsi host.
8922 * @phba: pointer to lpfc hba data structure.
8923 *
8924 * This routine is invoked to create HBA physical port and associate a SCSI
8925 * host with it.
8926 *
8927 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008928 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008929 * other values - error
8930 **/
8931static int
8932lpfc_create_shost(struct lpfc_hba *phba)
8933{
8934 struct lpfc_vport *vport;
8935 struct Scsi_Host *shost;
8936
8937 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05008938 phba->fc_edtov = FF_DEF_EDTOV;
8939 phba->fc_ratov = FF_DEF_RATOV;
8940 phba->fc_altov = FF_DEF_ALTOV;
8941 phba->fc_arbtov = FF_DEF_ARBTOV;
8942
James Smartd7c47992010-06-08 18:31:54 -04008943 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04008944 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05008945 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04008946 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05008947
8948 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05008949 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08008950
James Smartf358dd02017-02-12 13:52:34 -08008951 if (phba->nvmet_support) {
8952 /* Only 1 vport (pport) will support NVME target */
James Smartea85a202019-10-18 14:18:25 -07008953 phba->targetport = NULL;
8954 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
8955 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
8956 "6076 NVME Target Found\n");
James Smartf358dd02017-02-12 13:52:34 -08008957 }
8958
James Smart858c9f62007-06-17 19:56:39 -05008959 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04008960 /* Put reference to SCSI host to driver's device private data */
8961 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05008962
James Smart4258e982015-12-16 18:11:58 -05008963 /*
8964 * At this point we are fully registered with PSA. In addition,
8965 * any initial discovery should be completed.
8966 */
8967 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07008968 if (phba->cfg_enable_SmartSAN ||
8969 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05008970
8971 /* Setup appropriate attribute masks */
8972 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07008973 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05008974 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
8975 else
8976 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
8977 }
James Smart3772a992009-05-22 14:50:54 -04008978 return 0;
8979}
dea31012005-04-17 16:05:31 -05008980
James Smart3772a992009-05-22 14:50:54 -04008981/**
8982 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
8983 * @phba: pointer to lpfc hba data structure.
8984 *
8985 * This routine is invoked to destroy HBA physical port and the associated
8986 * SCSI host.
8987 **/
8988static void
8989lpfc_destroy_shost(struct lpfc_hba *phba)
8990{
8991 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04008992
James Smart3772a992009-05-22 14:50:54 -04008993 /* Destroy physical port that associated with the SCSI host */
8994 destroy_port(vport);
8995
8996 return;
8997}
8998
8999/**
9000 * lpfc_setup_bg - Setup Block guard structures and debug areas.
9001 * @phba: pointer to lpfc hba data structure.
9002 * @shost: the shost to be used to detect Block guard settings.
9003 *
9004 * This routine sets up the local Block guard protocol settings for @shost.
9005 * This routine also allocates memory for debugging bg buffers.
9006 **/
9007static void
9008lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
9009{
James Smartbbeb79b2012-06-12 13:54:27 -04009010 uint32_t old_mask;
9011 uint32_t old_guard;
9012
James Smartb3b98b72016-10-13 15:06:06 -07009013 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04009014 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9015 "1478 Registering BlockGuard with the "
9016 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04009017
James Smartb3b98b72016-10-13 15:06:06 -07009018 old_mask = phba->cfg_prot_mask;
9019 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04009020
9021 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07009022 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04009023 SHOST_DIX_TYPE0_PROTECTION |
9024 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07009025 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
9026 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04009027
9028 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07009029 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
9030 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04009031
James Smartb3b98b72016-10-13 15:06:06 -07009032 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
9033 if ((old_mask != phba->cfg_prot_mask) ||
9034 (old_guard != phba->cfg_prot_guard))
Dick Kennedy372c1872020-06-30 14:50:00 -07009035 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartbbeb79b2012-06-12 13:54:27 -04009036 "1475 Registering BlockGuard with the "
9037 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07009038 phba->cfg_prot_mask,
9039 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04009040
James Smartb3b98b72016-10-13 15:06:06 -07009041 scsi_host_set_prot(shost, phba->cfg_prot_mask);
9042 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04009043 } else
Dick Kennedy372c1872020-06-30 14:50:00 -07009044 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartbbeb79b2012-06-12 13:54:27 -04009045 "1479 Not Registering BlockGuard with the SCSI "
9046 "layer, Bad protection parameters: %d %d\n",
9047 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04009048 }
James Smart3772a992009-05-22 14:50:54 -04009049}
9050
9051/**
9052 * lpfc_post_init_setup - Perform necessary device post initialization setup.
9053 * @phba: pointer to lpfc hba data structure.
9054 *
9055 * This routine is invoked to perform all the necessary post initialization
9056 * setup for the device.
9057 **/
9058static void
9059lpfc_post_init_setup(struct lpfc_hba *phba)
9060{
9061 struct Scsi_Host *shost;
9062 struct lpfc_adapter_event_header adapter_event;
9063
9064 /* Get the default values for Model Name and Description */
9065 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9066
9067 /*
9068 * hba setup may have changed the hba_queue_depth so we need to
9069 * adjust the value of can_queue.
9070 */
9071 shost = pci_get_drvdata(phba->pcidev);
9072 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart858c9f62007-06-17 19:56:39 -05009073
9074 lpfc_host_attrib_init(shost);
9075
James Smart2e0fef82007-06-17 19:56:36 -05009076 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
9077 spin_lock_irq(shost->host_lock);
9078 lpfc_poll_start_timer(phba);
9079 spin_unlock_irq(shost->host_lock);
9080 }
James Smart8f6d98d2006-08-01 07:34:00 -04009081
James Smart93996272008-08-24 21:50:30 -04009082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9083 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04009084 /* Send board arrival event to upper layer */
9085 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
9086 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
9087 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04009088 sizeof(adapter_event),
9089 (char *) &adapter_event,
9090 LPFC_NL_VENDOR_ID);
9091 return;
9092}
9093
9094/**
9095 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
9096 * @phba: pointer to lpfc hba data structure.
9097 *
9098 * This routine is invoked to set up the PCI device memory space for device
9099 * with SLI-3 interface spec.
9100 *
9101 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009102 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009103 * other values - error
9104 **/
9105static int
9106lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
9107{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009108 struct pci_dev *pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04009109 unsigned long bar0map_len, bar2map_len;
9110 int i, hbq_count;
9111 void *ptr;
Hannes Reinecke56de8352019-02-18 08:34:19 +01009112 int error;
James Smart3772a992009-05-22 14:50:54 -04009113
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009114 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01009115 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04009116
9117 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01009118 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9119 if (error)
9120 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9121 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009122 return error;
Hannes Reinecke56de8352019-02-18 08:34:19 +01009123 error = -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04009124
9125 /* Get the bus address of Bar0 and Bar2 and the number of bytes
9126 * required by each mapping.
9127 */
9128 phba->pci_bar0_map = pci_resource_start(pdev, 0);
9129 bar0map_len = pci_resource_len(pdev, 0);
9130
9131 phba->pci_bar2_map = pci_resource_start(pdev, 2);
9132 bar2map_len = pci_resource_len(pdev, 2);
9133
9134 /* Map HBA SLIM to a kernel virtual address. */
9135 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
9136 if (!phba->slim_memmap_p) {
9137 dev_printk(KERN_ERR, &pdev->dev,
9138 "ioremap failed for SLIM memory.\n");
9139 goto out;
9140 }
9141
9142 /* Map HBA Control Registers to a kernel virtual address. */
9143 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
9144 if (!phba->ctrl_regs_memmap_p) {
9145 dev_printk(KERN_ERR, &pdev->dev,
9146 "ioremap failed for HBA control registers.\n");
9147 goto out_iounmap_slim;
9148 }
9149
9150 /* Allocate memory for SLI-2 structures */
Luis Chamberlain750afb02019-01-04 09:23:09 +01009151 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9152 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04009153 if (!phba->slim2p.virt)
9154 goto out_iounmap;
9155
James Smart3772a992009-05-22 14:50:54 -04009156 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04009157 phba->mbox_ext = (phba->slim2p.virt +
9158 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04009159 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
9160 phba->IOCBs = (phba->slim2p.virt +
9161 offsetof(struct lpfc_sli2_slim, IOCBs));
9162
9163 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
9164 lpfc_sli_hbq_size(),
9165 &phba->hbqslimp.phys,
9166 GFP_KERNEL);
9167 if (!phba->hbqslimp.virt)
9168 goto out_free_slim;
9169
9170 hbq_count = lpfc_sli_hbq_count();
9171 ptr = phba->hbqslimp.virt;
9172 for (i = 0; i < hbq_count; ++i) {
9173 phba->hbqs[i].hbq_virt = ptr;
9174 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
9175 ptr += (lpfc_hbq_defs[i]->entry_count *
9176 sizeof(struct lpfc_hbq_entry));
9177 }
9178 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
9179 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
9180
9181 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
9182
James Smart3772a992009-05-22 14:50:54 -04009183 phba->MBslimaddr = phba->slim_memmap_p;
9184 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
9185 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
9186 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
9187 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04009188
dea31012005-04-17 16:05:31 -05009189 return 0;
9190
dea31012005-04-17 16:05:31 -05009191out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04009192 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9193 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05009194out_iounmap:
9195 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05009196out_iounmap_slim:
dea31012005-04-17 16:05:31 -05009197 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05009198out:
9199 return error;
9200}
9201
James Smarte59058c2008-08-24 21:49:00 -04009202/**
James Smart3772a992009-05-22 14:50:54 -04009203 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
9204 * @phba: pointer to lpfc hba data structure.
9205 *
9206 * This routine is invoked to unset the PCI device memory space for device
9207 * with SLI-3 interface spec.
9208 **/
9209static void
9210lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
9211{
9212 struct pci_dev *pdev;
9213
9214 /* Obtain PCI device reference */
9215 if (!phba->pcidev)
9216 return;
9217 else
9218 pdev = phba->pcidev;
9219
9220 /* Free coherent DMA memory allocated */
9221 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9222 phba->hbqslimp.virt, phba->hbqslimp.phys);
9223 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
9224 phba->slim2p.virt, phba->slim2p.phys);
9225
9226 /* I/O memory unmap */
9227 iounmap(phba->ctrl_regs_memmap_p);
9228 iounmap(phba->slim_memmap_p);
9229
9230 return;
9231}
9232
9233/**
James Smartda0436e2009-05-22 14:51:39 -04009234 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
9235 * @phba: pointer to lpfc hba data structure.
9236 *
9237 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
9238 * done and check status.
9239 *
9240 * Return 0 if successful, otherwise -ENODEV.
9241 **/
9242int
9243lpfc_sli4_post_status_check(struct lpfc_hba *phba)
9244{
James Smart2fcee4b2010-12-15 17:57:46 -05009245 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
9246 struct lpfc_register reg_data;
9247 int i, port_error = 0;
9248 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009249
James Smart9940b972011-03-11 16:06:12 -05009250 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
9251 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05009252 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04009253 return -ENODEV;
9254
James Smartda0436e2009-05-22 14:51:39 -04009255 /* Wait up to 30 seconds for the SLI Port POST done and ready */
9256 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05009257 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
9258 &portsmphr_reg.word0) ||
9259 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009260 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04009261 port_error = -ENODEV;
9262 break;
9263 }
James Smart2fcee4b2010-12-15 17:57:46 -05009264 if (LPFC_POST_STAGE_PORT_READY ==
9265 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04009266 break;
James Smartda0436e2009-05-22 14:51:39 -04009267 msleep(10);
9268 }
9269
James Smart2fcee4b2010-12-15 17:57:46 -05009270 /*
9271 * If there was a port error during POST, then don't proceed with
9272 * other register reads as the data may not be valid. Just exit.
9273 */
9274 if (port_error) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009275 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05009276 "1408 Port Failed POST - portsmphr=0x%x, "
9277 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
9278 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
9279 portsmphr_reg.word0,
9280 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
9281 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
9282 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
9283 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
9284 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
9285 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
9286 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
9287 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
9288 } else {
James Smart28baac72010-02-12 14:42:03 -05009289 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05009290 "2534 Device Info: SLIFamily=0x%x, "
9291 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
9292 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05009293 bf_get(lpfc_sli_intf_sli_family,
9294 &phba->sli4_hba.sli_intf),
9295 bf_get(lpfc_sli_intf_slirev,
9296 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05009297 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05009298 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05009299 bf_get(lpfc_sli_intf_sli_hint1,
9300 &phba->sli4_hba.sli_intf),
9301 bf_get(lpfc_sli_intf_sli_hint2,
9302 &phba->sli4_hba.sli_intf),
9303 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05009304 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05009305 /*
9306 * Check for other Port errors during the initialization
9307 * process. Fail the load if the port did not come up
9308 * correctly.
9309 */
9310 if_type = bf_get(lpfc_sli_intf_if_type,
9311 &phba->sli4_hba.sli_intf);
9312 switch (if_type) {
9313 case LPFC_SLI_INTF_IF_TYPE_0:
9314 phba->sli4_hba.ue_mask_lo =
9315 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
9316 phba->sli4_hba.ue_mask_hi =
9317 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
9318 uerrlo_reg.word0 =
9319 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
9320 uerrhi_reg.word0 =
9321 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
9322 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
9323 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009324 lpfc_printf_log(phba, KERN_ERR,
9325 LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -05009326 "1422 Unrecoverable Error "
9327 "Detected during POST "
9328 "uerr_lo_reg=0x%x, "
9329 "uerr_hi_reg=0x%x, "
9330 "ue_mask_lo_reg=0x%x, "
9331 "ue_mask_hi_reg=0x%x\n",
9332 uerrlo_reg.word0,
9333 uerrhi_reg.word0,
9334 phba->sli4_hba.ue_mask_lo,
9335 phba->sli4_hba.ue_mask_hi);
9336 port_error = -ENODEV;
9337 }
9338 break;
9339 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009340 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05009341 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05009342 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
9343 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04009344 (bf_get(lpfc_sliport_status_err, &reg_data) &&
9345 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009346 phba->work_status[0] =
9347 readl(phba->sli4_hba.u.if_type2.
9348 ERR1regaddr);
9349 phba->work_status[1] =
9350 readl(phba->sli4_hba.u.if_type2.
9351 ERR2regaddr);
Dick Kennedy372c1872020-06-30 14:50:00 -07009352 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart8fcb8ac2012-03-01 22:35:58 -05009353 "2888 Unrecoverable port error "
9354 "following POST: port status reg "
9355 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05009356 "error 1=0x%x, error 2=0x%x\n",
9357 reg_data.word0,
9358 portsmphr_reg.word0,
9359 phba->work_status[0],
9360 phba->work_status[1]);
9361 port_error = -ENODEV;
9362 }
9363 break;
9364 case LPFC_SLI_INTF_IF_TYPE_1:
9365 default:
9366 break;
9367 }
James Smart28baac72010-02-12 14:42:03 -05009368 }
James Smartda0436e2009-05-22 14:51:39 -04009369 return port_error;
9370}
9371
9372/**
9373 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
9374 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05009375 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04009376 *
9377 * This routine is invoked to set up SLI4 BAR0 PCI config space register
9378 * memory map.
9379 **/
9380static void
James Smart2fcee4b2010-12-15 17:57:46 -05009381lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04009382{
James Smart2fcee4b2010-12-15 17:57:46 -05009383 switch (if_type) {
9384 case LPFC_SLI_INTF_IF_TYPE_0:
9385 phba->sli4_hba.u.if_type0.UERRLOregaddr =
9386 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
9387 phba->sli4_hba.u.if_type0.UERRHIregaddr =
9388 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
9389 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
9390 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
9391 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
9392 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
9393 phba->sli4_hba.SLIINTFregaddr =
9394 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9395 break;
9396 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07009397 phba->sli4_hba.u.if_type2.EQDregaddr =
9398 phba->sli4_hba.conf_regs_memmap_p +
9399 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009400 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04009401 phba->sli4_hba.conf_regs_memmap_p +
9402 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009403 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04009404 phba->sli4_hba.conf_regs_memmap_p +
9405 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009406 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04009407 phba->sli4_hba.conf_regs_memmap_p +
9408 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009409 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04009410 phba->sli4_hba.conf_regs_memmap_p +
9411 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009412 phba->sli4_hba.SLIINTFregaddr =
9413 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
9414 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04009415 phba->sli4_hba.conf_regs_memmap_p +
9416 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05009417 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05009418 phba->sli4_hba.conf_regs_memmap_p +
9419 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05009420 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05009421 phba->sli4_hba.conf_regs_memmap_p +
9422 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08009423 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05009424 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08009425 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05009426 phba->sli4_hba.MQDBregaddr =
9427 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
9428 phba->sli4_hba.BMBXregaddr =
9429 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9430 break;
James Smart27d6ac02018-02-22 08:18:42 -08009431 case LPFC_SLI_INTF_IF_TYPE_6:
9432 phba->sli4_hba.u.if_type2.EQDregaddr =
9433 phba->sli4_hba.conf_regs_memmap_p +
9434 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
9435 phba->sli4_hba.u.if_type2.ERR1regaddr =
9436 phba->sli4_hba.conf_regs_memmap_p +
9437 LPFC_CTL_PORT_ER1_OFFSET;
9438 phba->sli4_hba.u.if_type2.ERR2regaddr =
9439 phba->sli4_hba.conf_regs_memmap_p +
9440 LPFC_CTL_PORT_ER2_OFFSET;
9441 phba->sli4_hba.u.if_type2.CTRLregaddr =
9442 phba->sli4_hba.conf_regs_memmap_p +
9443 LPFC_CTL_PORT_CTL_OFFSET;
9444 phba->sli4_hba.u.if_type2.STATUSregaddr =
9445 phba->sli4_hba.conf_regs_memmap_p +
9446 LPFC_CTL_PORT_STA_OFFSET;
9447 phba->sli4_hba.PSMPHRregaddr =
9448 phba->sli4_hba.conf_regs_memmap_p +
9449 LPFC_CTL_PORT_SEM_OFFSET;
9450 phba->sli4_hba.BMBXregaddr =
9451 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
9452 break;
James Smart2fcee4b2010-12-15 17:57:46 -05009453 case LPFC_SLI_INTF_IF_TYPE_1:
9454 default:
9455 dev_printk(KERN_ERR, &phba->pcidev->dev,
9456 "FATAL - unsupported SLI4 interface type - %d\n",
9457 if_type);
9458 break;
9459 }
James Smartda0436e2009-05-22 14:51:39 -04009460}
9461
9462/**
9463 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
9464 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01009465 * @if_type: sli if type to operate on.
James Smartda0436e2009-05-22 14:51:39 -04009466 *
James Smart27d6ac02018-02-22 08:18:42 -08009467 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04009468 **/
9469static void
James Smart27d6ac02018-02-22 08:18:42 -08009470lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04009471{
James Smart27d6ac02018-02-22 08:18:42 -08009472 switch (if_type) {
9473 case LPFC_SLI_INTF_IF_TYPE_0:
9474 phba->sli4_hba.PSMPHRregaddr =
9475 phba->sli4_hba.ctrl_regs_memmap_p +
9476 LPFC_SLIPORT_IF0_SMPHR;
9477 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9478 LPFC_HST_ISR0;
9479 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9480 LPFC_HST_IMR0;
9481 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
9482 LPFC_HST_ISCR0;
9483 break;
9484 case LPFC_SLI_INTF_IF_TYPE_6:
9485 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9486 LPFC_IF6_RQ_DOORBELL;
9487 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9488 LPFC_IF6_WQ_DOORBELL;
9489 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9490 LPFC_IF6_CQ_DOORBELL;
9491 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9492 LPFC_IF6_EQ_DOORBELL;
9493 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
9494 LPFC_IF6_MQ_DOORBELL;
9495 break;
9496 case LPFC_SLI_INTF_IF_TYPE_2:
9497 case LPFC_SLI_INTF_IF_TYPE_1:
9498 default:
9499 dev_err(&phba->pcidev->dev,
9500 "FATAL - unsupported SLI4 interface type - %d\n",
9501 if_type);
9502 break;
9503 }
James Smartda0436e2009-05-22 14:51:39 -04009504}
9505
9506/**
9507 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
9508 * @phba: pointer to lpfc hba data structure.
9509 * @vf: virtual function number
9510 *
9511 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
9512 * based on the given viftual function number, @vf.
9513 *
9514 * Return 0 if successful, otherwise -ENODEV.
9515 **/
9516static int
9517lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
9518{
9519 if (vf > LPFC_VIR_FUNC_MAX)
9520 return -ENODEV;
9521
9522 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05009523 vf * LPFC_VFR_PAGE_SIZE +
9524 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04009525 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05009526 vf * LPFC_VFR_PAGE_SIZE +
9527 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08009528 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9529 vf * LPFC_VFR_PAGE_SIZE +
9530 LPFC_EQCQ_DOORBELL);
9531 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04009532 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9533 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
9534 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
9535 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
9536 return 0;
9537}
9538
9539/**
9540 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
9541 * @phba: pointer to lpfc hba data structure.
9542 *
9543 * This routine is invoked to create the bootstrap mailbox
9544 * region consistent with the SLI-4 interface spec. This
9545 * routine allocates all memory necessary to communicate
9546 * mailbox commands to the port and sets up all alignment
9547 * needs. No locks are expected to be held when calling
9548 * this routine.
9549 *
9550 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009551 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04009552 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04009553 **/
9554static int
9555lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
9556{
9557 uint32_t bmbx_size;
9558 struct lpfc_dmabuf *dmabuf;
9559 struct dma_address *dma_address;
9560 uint32_t pa_addr;
9561 uint64_t phys_addr;
9562
9563 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
9564 if (!dmabuf)
9565 return -ENOMEM;
9566
9567 /*
9568 * The bootstrap mailbox region is comprised of 2 parts
9569 * plus an alignment restriction of 16 bytes.
9570 */
9571 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Luis Chamberlain750afb02019-01-04 09:23:09 +01009572 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
9573 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04009574 if (!dmabuf->virt) {
9575 kfree(dmabuf);
9576 return -ENOMEM;
9577 }
James Smartda0436e2009-05-22 14:51:39 -04009578
9579 /*
9580 * Initialize the bootstrap mailbox pointers now so that the register
9581 * operations are simple later. The mailbox dma address is required
9582 * to be 16-byte aligned. Also align the virtual memory as each
9583 * maibox is copied into the bmbx mailbox region before issuing the
9584 * command to the port.
9585 */
9586 phba->sli4_hba.bmbx.dmabuf = dmabuf;
9587 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
9588
9589 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
9590 LPFC_ALIGN_16_BYTE);
9591 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
9592 LPFC_ALIGN_16_BYTE);
9593
9594 /*
9595 * Set the high and low physical addresses now. The SLI4 alignment
9596 * requirement is 16 bytes and the mailbox is posted to the port
9597 * as two 30-bit addresses. The other data is a bit marking whether
9598 * the 30-bit address is the high or low address.
9599 * Upcast bmbx aphys to 64bits so shift instruction compiles
9600 * clean on 32 bit machines.
9601 */
9602 dma_address = &phba->sli4_hba.bmbx.dma_address;
9603 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
9604 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
9605 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
9606 LPFC_BMBX_BIT1_ADDR_HI);
9607
9608 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
9609 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
9610 LPFC_BMBX_BIT1_ADDR_LO);
9611 return 0;
9612}
9613
9614/**
9615 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
9616 * @phba: pointer to lpfc hba data structure.
9617 *
9618 * This routine is invoked to teardown the bootstrap mailbox
9619 * region and release all host resources. This routine requires
9620 * the caller to ensure all mailbox commands recovered, no
9621 * additional mailbox comands are sent, and interrupts are disabled
9622 * before calling this routine.
9623 *
9624 **/
9625static void
9626lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
9627{
9628 dma_free_coherent(&phba->pcidev->dev,
9629 phba->sli4_hba.bmbx.bmbx_size,
9630 phba->sli4_hba.bmbx.dmabuf->virt,
9631 phba->sli4_hba.bmbx.dmabuf->phys);
9632
9633 kfree(phba->sli4_hba.bmbx.dmabuf);
9634 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
9635}
9636
James Smart83c6cb12019-10-18 14:18:30 -07009637static const char * const lpfc_topo_to_str[] = {
9638 "Loop then P2P",
9639 "Loopback",
9640 "P2P Only",
9641 "Unsupported",
9642 "Loop Only",
9643 "Unsupported",
9644 "P2P then Loop",
9645};
9646
Lee Jonesfe614ac2020-07-23 13:24:22 +01009647#define LINK_FLAGS_DEF 0x0
9648#define LINK_FLAGS_P2P 0x1
9649#define LINK_FLAGS_LOOP 0x2
James Smart83c6cb12019-10-18 14:18:30 -07009650/**
9651 * lpfc_map_topology - Map the topology read from READ_CONFIG
9652 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +01009653 * @rd_config: pointer to read config data
James Smart83c6cb12019-10-18 14:18:30 -07009654 *
9655 * This routine is invoked to map the topology values as read
9656 * from the read config mailbox command. If the persistent
9657 * topology feature is supported, the firmware will provide the
9658 * saved topology information to be used in INIT_LINK
James Smart83c6cb12019-10-18 14:18:30 -07009659 **/
James Smart83c6cb12019-10-18 14:18:30 -07009660static void
9661lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
9662{
9663 u8 ptv, tf, pt;
9664
9665 ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
9666 tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
9667 pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
9668
9669 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9670 "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
9671 ptv, tf, pt);
9672 if (!ptv) {
9673 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9674 "2019 FW does not support persistent topology "
9675 "Using driver parameter defined value [%s]",
9676 lpfc_topo_to_str[phba->cfg_topology]);
9677 return;
9678 }
9679 /* FW supports persistent topology - override module parameter value */
9680 phba->hba_flag |= HBA_PERSISTENT_TOPO;
James Smartf6c5e6c2021-07-22 15:17:18 -07009681
9682 /* if ASIC_GEN_NUM >= 0xC) */
9683 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9684 LPFC_SLI_INTF_IF_TYPE_6) ||
9685 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
9686 LPFC_SLI_INTF_FAMILY_G6)) {
James Smart83c6cb12019-10-18 14:18:30 -07009687 if (!tf) {
9688 phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
9689 ? FLAGS_TOPOLOGY_MODE_LOOP
9690 : FLAGS_TOPOLOGY_MODE_PT_PT);
9691 } else {
9692 phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
9693 }
James Smartf6c5e6c2021-07-22 15:17:18 -07009694 } else { /* G5 */
James Smart83c6cb12019-10-18 14:18:30 -07009695 if (tf) {
9696 /* If topology failover set - pt is '0' or '1' */
9697 phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
9698 FLAGS_TOPOLOGY_MODE_LOOP_PT);
9699 } else {
9700 phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
9701 ? FLAGS_TOPOLOGY_MODE_PT_PT
9702 : FLAGS_TOPOLOGY_MODE_LOOP);
9703 }
James Smart83c6cb12019-10-18 14:18:30 -07009704 }
9705 if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
9706 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9707 "2020 Using persistent topology value [%s]",
9708 lpfc_topo_to_str[phba->cfg_topology]);
9709 } else {
9710 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9711 "2021 Invalid topology values from FW "
9712 "Using driver parameter defined value [%s]",
9713 lpfc_topo_to_str[phba->cfg_topology]);
9714 }
9715}
9716
James Smartda0436e2009-05-22 14:51:39 -04009717/**
9718 * lpfc_sli4_read_config - Get the config parameters.
9719 * @phba: pointer to lpfc hba data structure.
9720 *
9721 * This routine is invoked to read the configuration parameters from the HBA.
9722 * The configuration parameters are used to set the base and maximum values
9723 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
9724 * allocation for the port.
9725 *
9726 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009727 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009728 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009729 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009730 **/
James Smartff78d8f2011-12-13 13:21:35 -05009731int
James Smartda0436e2009-05-22 14:51:39 -04009732lpfc_sli4_read_config(struct lpfc_hba *phba)
9733{
9734 LPFC_MBOXQ_t *pmb;
9735 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04009736 union lpfc_sli4_cfg_shdr *shdr;
9737 uint32_t shdr_status, shdr_add_status;
9738 struct lpfc_mbx_get_func_cfg *get_func_cfg;
9739 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04009740 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07009741 uint16_t forced_link_speed;
James Smart6a828b02019-01-28 11:14:31 -08009742 uint32_t if_type, qmin;
James Smart8aa134a2012-08-14 14:25:29 -04009743 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04009744
9745 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9746 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009747 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -04009748 "2011 Unable to allocate memory for issuing "
9749 "SLI_CONFIG_SPECIAL mailbox command\n");
9750 return -ENOMEM;
9751 }
9752
9753 lpfc_read_config(phba, pmb);
9754
9755 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9756 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009757 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9758 "2012 Mailbox failed , mbxCmd x%x "
9759 "READ_CONFIG, mbxStatus x%x\n",
9760 bf_get(lpfc_mqe_command, &pmb->u.mqe),
9761 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smartda0436e2009-05-22 14:51:39 -04009762 rc = -EIO;
9763 } else {
9764 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05009765 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
9766 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
9767 phba->sli4_hba.lnk_info.lnk_tp =
9768 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
9769 phba->sli4_hba.lnk_info.lnk_no =
9770 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
9771 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9772 "3081 lnk_type:%d, lnk_numb:%d\n",
9773 phba->sli4_hba.lnk_info.lnk_tp,
9774 phba->sli4_hba.lnk_info.lnk_no);
9775 } else
9776 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9777 "3082 Mailbox (x%x) returned ldv:x0\n",
9778 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07009779 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
9780 phba->bbcredit_support = 1;
9781 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
9782 }
9783
James Smart1dc5ec22018-10-23 13:41:11 -07009784 phba->sli4_hba.conf_trunk =
9785 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04009786 phba->sli4_hba.extents_in_use =
9787 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04009788 phba->sli4_hba.max_cfg_param.max_xri =
9789 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
James Smart31f06d22019-08-14 16:56:31 -07009790 /* Reduce resource usage in kdump environment */
9791 if (is_kdump_kernel() &&
9792 phba->sli4_hba.max_cfg_param.max_xri > 512)
9793 phba->sli4_hba.max_cfg_param.max_xri = 512;
James Smartda0436e2009-05-22 14:51:39 -04009794 phba->sli4_hba.max_cfg_param.xri_base =
9795 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
9796 phba->sli4_hba.max_cfg_param.max_vpi =
9797 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08009798 /* Limit the max we support */
9799 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
9800 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04009801 phba->sli4_hba.max_cfg_param.vpi_base =
9802 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
9803 phba->sli4_hba.max_cfg_param.max_rpi =
9804 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
9805 phba->sli4_hba.max_cfg_param.rpi_base =
9806 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
9807 phba->sli4_hba.max_cfg_param.max_vfi =
9808 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
9809 phba->sli4_hba.max_cfg_param.vfi_base =
9810 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
9811 phba->sli4_hba.max_cfg_param.max_fcfi =
9812 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04009813 phba->sli4_hba.max_cfg_param.max_eq =
9814 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
9815 phba->sli4_hba.max_cfg_param.max_rq =
9816 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
9817 phba->sli4_hba.max_cfg_param.max_wq =
9818 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
9819 phba->sli4_hba.max_cfg_param.max_cq =
9820 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
9821 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
9822 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
9823 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
9824 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05009825 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
9826 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04009827 phba->max_vports = phba->max_vpi;
James Smart9064aeb2021-08-16 09:28:50 -07009828
9829 /* Next decide on FPIN or Signal E2E CGN support
9830 * For congestion alarms and warnings valid combination are:
9831 * 1. FPIN alarms / FPIN warnings
9832 * 2. Signal alarms / Signal warnings
9833 * 3. FPIN alarms / Signal warnings
9834 * 4. Signal alarms / FPIN warnings
9835 *
9836 * Initialize the adapter frequency to 100 mSecs
9837 */
9838 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9839 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9840 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9841
9842 if (lpfc_use_cgn_signal) {
9843 if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
9844 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
9845 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
9846 }
9847 if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
9848 /* MUST support both alarm and warning
9849 * because EDC does not support alarm alone.
9850 */
9851 if (phba->cgn_reg_signal !=
9852 EDC_CG_SIG_WARN_ONLY) {
9853 /* Must support both or none */
9854 phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
9855 phba->cgn_reg_signal =
9856 EDC_CG_SIG_NOTSUPPORTED;
9857 } else {
9858 phba->cgn_reg_signal =
9859 EDC_CG_SIG_WARN_ALARM;
9860 phba->cgn_reg_fpin =
9861 LPFC_CGN_FPIN_NONE;
9862 }
9863 }
9864 }
9865
9866 /* Set the congestion initial signal and fpin values. */
9867 phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
9868 phba->cgn_init_reg_signal = phba->cgn_reg_signal;
9869
9870 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
9871 "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
9872 phba->cgn_reg_signal, phba->cgn_reg_fpin);
9873
James Smart83c6cb12019-10-18 14:18:30 -07009874 lpfc_map_topology(phba, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04009875 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04009876 "2003 cfg params Extents? %d "
9877 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04009878 "VPI(B:%d M:%d) "
9879 "VFI(B:%d M:%d) "
9880 "RPI(B:%d M:%d) "
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07009881 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
James Smart6d368e52011-05-24 11:44:12 -04009882 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04009883 phba->sli4_hba.max_cfg_param.xri_base,
9884 phba->sli4_hba.max_cfg_param.max_xri,
9885 phba->sli4_hba.max_cfg_param.vpi_base,
9886 phba->sli4_hba.max_cfg_param.max_vpi,
9887 phba->sli4_hba.max_cfg_param.vfi_base,
9888 phba->sli4_hba.max_cfg_param.max_vfi,
9889 phba->sli4_hba.max_cfg_param.rpi_base,
9890 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08009891 phba->sli4_hba.max_cfg_param.max_fcfi,
9892 phba->sli4_hba.max_cfg_param.max_eq,
9893 phba->sli4_hba.max_cfg_param.max_cq,
9894 phba->sli4_hba.max_cfg_param.max_wq,
Dick Kennedya1e4d3d2020-08-03 14:02:22 -07009895 phba->sli4_hba.max_cfg_param.max_rq,
9896 phba->lmt);
James Smart2ea259e2017-02-12 13:52:27 -08009897
James Smartd38f33b2018-05-04 20:37:54 -07009898 /*
James Smart6a828b02019-01-28 11:14:31 -08009899 * Calculate queue resources based on how
9900 * many WQ/CQ/EQs are available.
James Smartd38f33b2018-05-04 20:37:54 -07009901 */
James Smart6a828b02019-01-28 11:14:31 -08009902 qmin = phba->sli4_hba.max_cfg_param.max_wq;
9903 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
9904 qmin = phba->sli4_hba.max_cfg_param.max_cq;
9905 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
9906 qmin = phba->sli4_hba.max_cfg_param.max_eq;
9907 /*
9908 * Whats left after this can go toward NVME / FCP.
9909 * The minus 4 accounts for ELS, NVME LS, MBOX
9910 * plus one extra. When configured for
9911 * NVMET, FCP io channel WQs are not created.
9912 */
9913 qmin -= 4;
James Smartd38f33b2018-05-04 20:37:54 -07009914
James Smart6a828b02019-01-28 11:14:31 -08009915 /* Check to see if there is enough for NVME */
9916 if ((phba->cfg_irq_chann > qmin) ||
9917 (phba->cfg_hdw_queue > qmin)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07009918 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
Dick Kennedy9e3e3652020-08-03 14:02:23 -07009919 "2005 Reducing Queues - "
9920 "FW resource limitation: "
James Smart6a828b02019-01-28 11:14:31 -08009921 "WQ %d CQ %d EQ %d: min %d: "
9922 "IRQ %d HDWQ %d\n",
James Smartd38f33b2018-05-04 20:37:54 -07009923 phba->sli4_hba.max_cfg_param.max_wq,
9924 phba->sli4_hba.max_cfg_param.max_cq,
James Smart6a828b02019-01-28 11:14:31 -08009925 phba->sli4_hba.max_cfg_param.max_eq,
9926 qmin, phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08009927 phba->cfg_hdw_queue);
James Smartd38f33b2018-05-04 20:37:54 -07009928
James Smart6a828b02019-01-28 11:14:31 -08009929 if (phba->cfg_irq_chann > qmin)
9930 phba->cfg_irq_chann = qmin;
9931 if (phba->cfg_hdw_queue > qmin)
9932 phba->cfg_hdw_queue = qmin;
James Smartd38f33b2018-05-04 20:37:54 -07009933 }
James Smartda0436e2009-05-22 14:51:39 -04009934 }
James Smart912e3ac2011-05-24 11:42:11 -04009935
9936 if (rc)
9937 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04009938
James Smartc6918162016-10-13 15:06:16 -07009939 /* Update link speed if forced link speed is supported */
9940 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08009941 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07009942 forced_link_speed =
9943 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
9944 if (forced_link_speed) {
9945 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
9946
9947 switch (forced_link_speed) {
9948 case LINK_SPEED_1G:
9949 phba->cfg_link_speed =
9950 LPFC_USER_LINK_SPEED_1G;
9951 break;
9952 case LINK_SPEED_2G:
9953 phba->cfg_link_speed =
9954 LPFC_USER_LINK_SPEED_2G;
9955 break;
9956 case LINK_SPEED_4G:
9957 phba->cfg_link_speed =
9958 LPFC_USER_LINK_SPEED_4G;
9959 break;
9960 case LINK_SPEED_8G:
9961 phba->cfg_link_speed =
9962 LPFC_USER_LINK_SPEED_8G;
9963 break;
9964 case LINK_SPEED_10G:
9965 phba->cfg_link_speed =
9966 LPFC_USER_LINK_SPEED_10G;
9967 break;
9968 case LINK_SPEED_16G:
9969 phba->cfg_link_speed =
9970 LPFC_USER_LINK_SPEED_16G;
9971 break;
9972 case LINK_SPEED_32G:
9973 phba->cfg_link_speed =
9974 LPFC_USER_LINK_SPEED_32G;
9975 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08009976 case LINK_SPEED_64G:
9977 phba->cfg_link_speed =
9978 LPFC_USER_LINK_SPEED_64G;
9979 break;
James Smartc6918162016-10-13 15:06:16 -07009980 case 0xffff:
9981 phba->cfg_link_speed =
9982 LPFC_USER_LINK_SPEED_AUTO;
9983 break;
9984 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07009985 lpfc_printf_log(phba, KERN_ERR,
9986 LOG_TRACE_EVENT,
James Smartc6918162016-10-13 15:06:16 -07009987 "0047 Unrecognized link "
9988 "speed : %d\n",
9989 forced_link_speed);
9990 phba->cfg_link_speed =
9991 LPFC_USER_LINK_SPEED_AUTO;
9992 }
9993 }
9994 }
9995
James Smartda0436e2009-05-22 14:51:39 -04009996 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04009997 length = phba->sli4_hba.max_cfg_param.max_xri -
9998 lpfc_sli4_get_els_iocb_cnt(phba);
9999 if (phba->cfg_hba_queue_depth > length) {
10000 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10001 "3361 HBA queue depth changed from %d to %d\n",
10002 phba->cfg_hba_queue_depth, length);
10003 phba->cfg_hba_queue_depth = length;
10004 }
James Smart912e3ac2011-05-24 11:42:11 -040010005
James Smart27d6ac02018-02-22 08:18:42 -080010006 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -040010007 LPFC_SLI_INTF_IF_TYPE_2)
10008 goto read_cfg_out;
10009
10010 /* get the pf# and vf# for SLI4 if_type 2 port */
10011 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
10012 sizeof(struct lpfc_sli4_cfg_mhdr));
10013 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
10014 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
10015 length, LPFC_SLI4_MBX_EMBED);
10016
James Smart8aa134a2012-08-14 14:25:29 -040010017 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -040010018 shdr = (union lpfc_sli4_cfg_shdr *)
10019 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
10020 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10021 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -040010022 if (rc2 || shdr_status || shdr_add_status) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010023 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart912e3ac2011-05-24 11:42:11 -040010024 "3026 Mailbox failed , mbxCmd x%x "
10025 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
10026 bf_get(lpfc_mqe_command, &pmb->u.mqe),
10027 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -040010028 goto read_cfg_out;
10029 }
10030
10031 /* search for fc_fcoe resrouce descriptor */
10032 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -040010033
James Smart8aa134a2012-08-14 14:25:29 -040010034 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
10035 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
10036 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
10037 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
10038 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
10039 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
10040 goto read_cfg_out;
10041
James Smart912e3ac2011-05-24 11:42:11 -040010042 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -040010043 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -040010044 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -040010045 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -040010046 phba->sli4_hba.iov.pf_number =
10047 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
10048 phba->sli4_hba.iov.vf_number =
10049 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
10050 break;
10051 }
10052 }
10053
10054 if (i < LPFC_RSRC_DESC_MAX_NUM)
10055 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10056 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
10057 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
10058 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -040010059 else
Dick Kennedy372c1872020-06-30 14:50:00 -070010060 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart912e3ac2011-05-24 11:42:11 -040010061 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +010010062 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -040010063 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -040010064
10065read_cfg_out:
10066 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -040010067 return rc;
10068}
10069
10070/**
James Smart2fcee4b2010-12-15 17:57:46 -050010071 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -040010072 * @phba: pointer to lpfc hba data structure.
10073 *
James Smart2fcee4b2010-12-15 17:57:46 -050010074 * This routine is invoked to setup the port-side endian order when
10075 * the port if_type is 0. This routine has no function for other
10076 * if_types.
James Smartda0436e2009-05-22 14:51:39 -040010077 *
10078 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010079 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010080 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010081 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010082 **/
10083static int
10084lpfc_setup_endian_order(struct lpfc_hba *phba)
10085{
10086 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -050010087 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -040010088 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
10089 HOST_ENDIAN_HIGH_WORD1};
10090
James Smart2fcee4b2010-12-15 17:57:46 -050010091 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10092 switch (if_type) {
10093 case LPFC_SLI_INTF_IF_TYPE_0:
10094 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10095 GFP_KERNEL);
10096 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010097 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050010098 "0492 Unable to allocate memory for "
10099 "issuing SLI_CONFIG_SPECIAL mailbox "
10100 "command\n");
10101 return -ENOMEM;
10102 }
James Smartda0436e2009-05-22 14:51:39 -040010103
James Smart2fcee4b2010-12-15 17:57:46 -050010104 /*
10105 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
10106 * two words to contain special data values and no other data.
10107 */
10108 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
10109 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
10110 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10111 if (rc != MBX_SUCCESS) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010112 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050010113 "0493 SLI_CONFIG_SPECIAL mailbox "
10114 "failed with status x%x\n",
10115 rc);
10116 rc = -EIO;
10117 }
10118 mempool_free(mboxq, phba->mbox_mem_pool);
10119 break;
James Smart27d6ac02018-02-22 08:18:42 -080010120 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -050010121 case LPFC_SLI_INTF_IF_TYPE_2:
10122 case LPFC_SLI_INTF_IF_TYPE_1:
10123 default:
10124 break;
James Smartda0436e2009-05-22 14:51:39 -040010125 }
James Smartda0436e2009-05-22 14:51:39 -040010126 return rc;
10127}
10128
10129/**
James Smart895427b2017-02-12 13:52:30 -080010130 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -040010131 * @phba: pointer to lpfc hba data structure.
10132 *
James Smart895427b2017-02-12 13:52:30 -080010133 * This routine is invoked to check the user settable queue counts for EQs.
10134 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -040010135 * adhere to the constraints of the system's interrupt vectors and the port's
10136 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -040010137 *
10138 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010139 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010140 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -040010141 **/
10142static int
James Smart5350d872011-10-10 21:33:49 -040010143lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -040010144{
James Smartda0436e2009-05-22 14:51:39 -040010145 /*
James Smart67d12732012-08-03 12:36:13 -040010146 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -040010147 * device parameters
10148 */
10149
James Smartbcb24f62017-11-20 16:00:36 -080010150 if (phba->nvmet_support) {
James Smart97a9ed32019-10-18 14:18:17 -070010151 if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
10152 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
James Smart982ab122019-03-12 16:30:10 -070010153 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
10154 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smartbcb24f62017-11-20 16:00:36 -080010155 }
James Smart895427b2017-02-12 13:52:30 -080010156
10157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -080010158 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
10159 phba->cfg_hdw_queue, phba->cfg_irq_chann,
10160 phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -040010161
James Smartda0436e2009-05-22 14:51:39 -040010162 /* Get EQ depth from module parameter, fake the default for now */
10163 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10164 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10165
James Smart5350d872011-10-10 21:33:49 -040010166 /* Get CQ depth from module parameter, fake the default for now */
10167 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10168 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -040010169 return 0;
James Smart895427b2017-02-12 13:52:30 -080010170}
10171
10172static int
James Smartc00f62e2019-08-14 16:57:11 -070010173lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
James Smart895427b2017-02-12 13:52:30 -080010174{
10175 struct lpfc_queue *qdesc;
James Smartc00f62e2019-08-14 16:57:11 -070010176 u32 wqesize;
James Smartc1a21eb2019-03-12 16:30:29 -070010177 int cpu;
James Smart895427b2017-02-12 13:52:30 -080010178
James Smartc00f62e2019-08-14 16:57:11 -070010179 cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
10180 /* Create Fast Path IO CQs */
James Smartc176ffa2018-01-30 15:58:46 -080010181 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080010182 /* Increase the CQ size when WQEs contain an embedded cdb */
10183 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
10184 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010185 LPFC_CQE_EXP_COUNT, cpu);
James Smarta51e41b2017-12-08 17:18:06 -080010186
10187 else
10188 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10189 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010190 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -080010191 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010192 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10193 "0499 Failed allocate fast-path IO CQ (%d)\n",
10194 idx);
James Smart895427b2017-02-12 13:52:30 -080010195 return 1;
10196 }
James Smart7365f6f2018-02-22 08:18:46 -080010197 qdesc->qe_valid = 1;
James Smartc00f62e2019-08-14 16:57:11 -070010198 qdesc->hdwq = idx;
James Smartc1a21eb2019-03-12 16:30:29 -070010199 qdesc->chann = cpu;
James Smartc00f62e2019-08-14 16:57:11 -070010200 phba->sli4_hba.hdwq[idx].io_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080010201
James Smartc00f62e2019-08-14 16:57:11 -070010202 /* Create Fast Path IO WQs */
James Smartc176ffa2018-01-30 15:58:46 -080010203 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -080010204 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -080010205 wqesize = (phba->fcp_embed_io) ?
10206 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080010207 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080010208 wqesize,
James Smartc1a21eb2019-03-12 16:30:29 -070010209 LPFC_WQE_EXP_COUNT, cpu);
James Smartc176ffa2018-01-30 15:58:46 -080010210 } else
James Smarta51e41b2017-12-08 17:18:06 -080010211 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10212 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010213 phba->sli4_hba.wq_ecount, cpu);
James Smartc176ffa2018-01-30 15:58:46 -080010214
James Smart895427b2017-02-12 13:52:30 -080010215 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010216 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc00f62e2019-08-14 16:57:11 -070010217 "0503 Failed allocate fast-path IO WQ (%d)\n",
10218 idx);
James Smart895427b2017-02-12 13:52:30 -080010219 return 1;
10220 }
James Smartc00f62e2019-08-14 16:57:11 -070010221 qdesc->hdwq = idx;
10222 qdesc->chann = cpu;
10223 phba->sli4_hba.hdwq[idx].io_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080010224 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10225 return 0;
James Smart5350d872011-10-10 21:33:49 -040010226}
10227
10228/**
10229 * lpfc_sli4_queue_create - Create all the SLI4 queues
10230 * @phba: pointer to lpfc hba data structure.
10231 *
10232 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
10233 * operation. For each SLI4 queue type, the parameters such as queue entry
10234 * count (queue depth) shall be taken from the module parameter. For now,
10235 * we just use some constant number as place holder.
10236 *
10237 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -070010238 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -040010239 * -ENOMEM - No availble memory
10240 * -EIO - The mailbox failed to complete successfully.
10241 **/
10242int
10243lpfc_sli4_queue_create(struct lpfc_hba *phba)
10244{
10245 struct lpfc_queue *qdesc;
James Smart657add42019-05-21 17:49:06 -070010246 int idx, cpu, eqcpu;
James Smart5e5b5112019-01-28 11:14:22 -080010247 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -070010248 struct lpfc_vector_map_info *cpup;
10249 struct lpfc_vector_map_info *eqcpup;
James Smart32517fc2019-01-28 11:14:33 -080010250 struct lpfc_eq_intr_info *eqi;
James Smart5350d872011-10-10 21:33:49 -040010251
10252 /*
James Smart67d12732012-08-03 12:36:13 -040010253 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -080010254 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -040010255 */
James Smart67d12732012-08-03 12:36:13 -040010256 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
10257 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
10258 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
10259 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
10260 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
10261 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -080010262 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
10263 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
10264 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
10265 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -040010266
James Smartcdb42be2019-01-28 11:14:21 -080010267 if (!phba->sli4_hba.hdwq) {
James Smart5e5b5112019-01-28 11:14:22 -080010268 phba->sli4_hba.hdwq = kcalloc(
10269 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
10270 GFP_KERNEL);
10271 if (!phba->sli4_hba.hdwq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010272 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5e5b5112019-01-28 11:14:22 -080010273 "6427 Failed allocate memory for "
10274 "fast-path Hardware Queue array\n");
James Smart895427b2017-02-12 13:52:30 -080010275 goto out_error;
10276 }
James Smart5e5b5112019-01-28 11:14:22 -080010277 /* Prepare hardware queues to take IO buffers */
10278 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10279 qp = &phba->sli4_hba.hdwq[idx];
10280 spin_lock_init(&qp->io_buf_list_get_lock);
10281 spin_lock_init(&qp->io_buf_list_put_lock);
10282 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
10283 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
10284 qp->get_io_bufs = 0;
10285 qp->put_io_bufs = 0;
10286 qp->total_io_bufs = 0;
James Smartc00f62e2019-08-14 16:57:11 -070010287 spin_lock_init(&qp->abts_io_buf_list_lock);
10288 INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
James Smart5e5b5112019-01-28 11:14:22 -080010289 qp->abts_scsi_io_bufs = 0;
James Smart5e5b5112019-01-28 11:14:22 -080010290 qp->abts_nvme_io_bufs = 0;
James Smartd79c9e92019-08-14 16:57:09 -070010291 INIT_LIST_HEAD(&qp->sgl_list);
10292 INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
10293 spin_lock_init(&qp->hdwq_lock);
James Smart895427b2017-02-12 13:52:30 -080010294 }
James Smart67d12732012-08-03 12:36:13 -040010295 }
10296
James Smartcdb42be2019-01-28 11:14:21 -080010297 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -080010298 if (phba->nvmet_support) {
10299 phba->sli4_hba.nvmet_cqset = kcalloc(
10300 phba->cfg_nvmet_mrq,
10301 sizeof(struct lpfc_queue *),
10302 GFP_KERNEL);
10303 if (!phba->sli4_hba.nvmet_cqset) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010304 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010305 "3121 Fail allocate memory for "
10306 "fast-path CQ set array\n");
10307 goto out_error;
10308 }
10309 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
10310 phba->cfg_nvmet_mrq,
10311 sizeof(struct lpfc_queue *),
10312 GFP_KERNEL);
10313 if (!phba->sli4_hba.nvmet_mrq_hdr) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010314 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010315 "3122 Fail allocate memory for "
10316 "fast-path RQ set hdr array\n");
10317 goto out_error;
10318 }
10319 phba->sli4_hba.nvmet_mrq_data = kcalloc(
10320 phba->cfg_nvmet_mrq,
10321 sizeof(struct lpfc_queue *),
10322 GFP_KERNEL);
10323 if (!phba->sli4_hba.nvmet_mrq_data) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010324 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010325 "3124 Fail allocate memory for "
10326 "fast-path RQ set data array\n");
10327 goto out_error;
10328 }
10329 }
James Smart67d12732012-08-03 12:36:13 -040010330 }
James Smartda0436e2009-05-22 14:51:39 -040010331
James Smart895427b2017-02-12 13:52:30 -080010332 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -040010333
James Smart895427b2017-02-12 13:52:30 -080010334 /* Create HBA Event Queues (EQs) */
James Smart657add42019-05-21 17:49:06 -070010335 for_each_present_cpu(cpu) {
10336 /* We only want to create 1 EQ per vector, even though
10337 * multiple CPUs might be using that vector. so only
10338 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
James Smart6a828b02019-01-28 11:14:31 -080010339 */
James Smart657add42019-05-21 17:49:06 -070010340 cpup = &phba->sli4_hba.cpu_map[cpu];
10341 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
James Smart6a828b02019-01-28 11:14:31 -080010342 continue;
James Smart657add42019-05-21 17:49:06 -070010343
10344 /* Get a ptr to the Hardware Queue associated with this CPU */
10345 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10346
10347 /* Allocate an EQ */
James Smart81b96ed2017-11-20 16:00:29 -080010348 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10349 phba->sli4_hba.eq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010350 phba->sli4_hba.eq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010351 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010352 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart657add42019-05-21 17:49:06 -070010353 "0497 Failed allocate EQ (%d)\n",
10354 cpup->hdwq);
James Smart67d12732012-08-03 12:36:13 -040010355 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010356 }
James Smart7365f6f2018-02-22 08:18:46 -080010357 qdesc->qe_valid = 1;
James Smart657add42019-05-21 17:49:06 -070010358 qdesc->hdwq = cpup->hdwq;
James Smart3ad348d2019-08-14 16:56:43 -070010359 qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
James Smart32517fc2019-01-28 11:14:33 -080010360 qdesc->last_cpu = qdesc->chann;
James Smart657add42019-05-21 17:49:06 -070010361
10362 /* Save the allocated EQ in the Hardware Queue */
10363 qp->hba_eq = qdesc;
10364
James Smart32517fc2019-01-28 11:14:33 -080010365 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
10366 list_add(&qdesc->cpu_list, &eqi->list);
James Smartda0436e2009-05-22 14:51:39 -040010367 }
10368
James Smart657add42019-05-21 17:49:06 -070010369 /* Now we need to populate the other Hardware Queues, that share
10370 * an IRQ vector, with the associated EQ ptr.
10371 */
10372 for_each_present_cpu(cpu) {
10373 cpup = &phba->sli4_hba.cpu_map[cpu];
10374
10375 /* Check for EQ already allocated in previous loop */
10376 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
10377 continue;
10378
10379 /* Check for multiple CPUs per hdwq */
10380 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
10381 if (qp->hba_eq)
10382 continue;
10383
10384 /* We need to share an EQ for this hdwq */
10385 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
10386 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
10387 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
10388 }
James Smart895427b2017-02-12 13:52:30 -080010389
James Smartc00f62e2019-08-14 16:57:11 -070010390 /* Allocate IO Path SLI4 CQ/WQs */
James Smart6a828b02019-01-28 11:14:31 -080010391 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smartc00f62e2019-08-14 16:57:11 -070010392 if (lpfc_alloc_io_wq_cq(phba, idx))
James Smart895427b2017-02-12 13:52:30 -080010393 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -080010394 }
James Smart895427b2017-02-12 13:52:30 -080010395
James Smartc00f62e2019-08-14 16:57:11 -070010396 if (phba->nvmet_support) {
10397 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
10398 cpu = lpfc_find_cpu_handle(phba, idx,
10399 LPFC_FIND_BY_HDWQ);
10400 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -080010401 LPFC_DEFAULT_PAGE_SIZE,
10402 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010403 phba->sli4_hba.cq_ecount,
10404 cpu);
James Smartc00f62e2019-08-14 16:57:11 -070010405 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010406 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -080010407 "3142 Failed allocate NVME "
10408 "CQ Set (%d)\n", idx);
James Smartc00f62e2019-08-14 16:57:11 -070010409 goto out_error;
James Smart2d7dbc42017-02-12 13:52:35 -080010410 }
James Smartc00f62e2019-08-14 16:57:11 -070010411 qdesc->qe_valid = 1;
10412 qdesc->hdwq = idx;
10413 qdesc->chann = cpu;
10414 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
James Smart2d7dbc42017-02-12 13:52:35 -080010415 }
10416 }
10417
James Smartda0436e2009-05-22 14:51:39 -040010418 /*
James Smart67d12732012-08-03 12:36:13 -040010419 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -040010420 */
10421
James Smartc1a21eb2019-03-12 16:30:29 -070010422 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
James Smartda0436e2009-05-22 14:51:39 -040010423 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -080010424 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10425 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010426 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010427 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010428 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010429 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -040010430 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010431 }
James Smart7365f6f2018-02-22 08:18:46 -080010432 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -040010433 phba->sli4_hba.mbx_cq = qdesc;
10434
10435 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -080010436 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10437 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010438 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010439 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010440 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010441 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -040010442 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010443 }
James Smart7365f6f2018-02-22 08:18:46 -080010444 qdesc->qe_valid = 1;
James Smartc00f62e2019-08-14 16:57:11 -070010445 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -040010446 phba->sli4_hba.els_cq = qdesc;
10447
James Smartda0436e2009-05-22 14:51:39 -040010448
James Smart5350d872011-10-10 21:33:49 -040010449 /*
James Smart67d12732012-08-03 12:36:13 -040010450 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -040010451 */
James Smartda0436e2009-05-22 14:51:39 -040010452
10453 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -040010454
James Smart81b96ed2017-11-20 16:00:29 -080010455 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10456 phba->sli4_hba.mq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010457 phba->sli4_hba.mq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010458 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010459 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010460 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -040010461 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010462 }
James Smartc00f62e2019-08-14 16:57:11 -070010463 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -040010464 phba->sli4_hba.mbx_wq = qdesc;
10465
10466 /*
James Smart67d12732012-08-03 12:36:13 -040010467 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -040010468 */
James Smartda0436e2009-05-22 14:51:39 -040010469
10470 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -080010471 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10472 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010473 phba->sli4_hba.wq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010474 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010475 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010476 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -040010477 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010478 }
James Smartc00f62e2019-08-14 16:57:11 -070010479 qdesc->chann = cpu;
James Smartda0436e2009-05-22 14:51:39 -040010480 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080010481 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10482
10483 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10484 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -080010485 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10486 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010487 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -080010488 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010489 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080010490 "6079 Failed allocate NVME LS CQ\n");
10491 goto out_error;
10492 }
James Smartc00f62e2019-08-14 16:57:11 -070010493 qdesc->chann = cpu;
James Smart7365f6f2018-02-22 08:18:46 -080010494 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -080010495 phba->sli4_hba.nvmels_cq = qdesc;
10496
10497 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -080010498 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10499 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010500 phba->sli4_hba.wq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -080010501 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010502 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080010503 "6080 Failed allocate NVME LS WQ\n");
10504 goto out_error;
10505 }
James Smartc00f62e2019-08-14 16:57:11 -070010506 qdesc->chann = cpu;
James Smart895427b2017-02-12 13:52:30 -080010507 phba->sli4_hba.nvmels_wq = qdesc;
10508 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
10509 }
James Smartda0436e2009-05-22 14:51:39 -040010510
James Smartda0436e2009-05-22 14:51:39 -040010511 /*
10512 * Create Receive Queue (RQ)
10513 */
James Smartda0436e2009-05-22 14:51:39 -040010514
10515 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -080010516 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10517 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010518 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010519 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010520 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010521 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -040010522 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010523 }
10524 phba->sli4_hba.hdr_rq = qdesc;
10525
10526 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -080010527 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
10528 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010529 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -040010530 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010531 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040010532 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -040010533 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -040010534 }
10535 phba->sli4_hba.dat_rq = qdesc;
10536
James Smartcdb42be2019-01-28 11:14:21 -080010537 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
10538 phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -080010539 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -070010540 cpu = lpfc_find_cpu_handle(phba, idx,
10541 LPFC_FIND_BY_HDWQ);
James Smart2d7dbc42017-02-12 13:52:35 -080010542 /* Create NVMET Receive Queue for header */
10543 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -080010544 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -080010545 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010546 LPFC_NVMET_RQE_DEF_COUNT,
10547 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -080010548 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010549 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010550 "3146 Failed allocate "
10551 "receive HRQ\n");
10552 goto out_error;
10553 }
James Smart5e5b5112019-01-28 11:14:22 -080010554 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -080010555 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
10556
10557 /* Only needed for header of RQ pair */
James Smartc1a21eb2019-03-12 16:30:29 -070010558 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
10559 GFP_KERNEL,
10560 cpu_to_node(cpu));
James Smart2d7dbc42017-02-12 13:52:35 -080010561 if (qdesc->rqbp == NULL) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010562 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010563 "6131 Failed allocate "
10564 "Header RQBP\n");
10565 goto out_error;
10566 }
10567
Dick Kennedy4b40d022017-08-23 16:55:38 -070010568 /* Put list in known state in case driver load fails. */
10569 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
10570
James Smart2d7dbc42017-02-12 13:52:35 -080010571 /* Create NVMET Receive Queue for data */
10572 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -080010573 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -080010574 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -070010575 LPFC_NVMET_RQE_DEF_COUNT,
10576 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -080010577 if (!qdesc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010578 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080010579 "3156 Failed allocate "
10580 "receive DRQ\n");
10581 goto out_error;
10582 }
James Smart5e5b5112019-01-28 11:14:22 -080010583 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -080010584 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
10585 }
10586 }
10587
James Smart4c47efc2019-01-28 11:14:25 -080010588 /* Clear NVME stats */
10589 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10590 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10591 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
10592 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
10593 }
10594 }
James Smart4c47efc2019-01-28 11:14:25 -080010595
10596 /* Clear SCSI stats */
10597 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
10598 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10599 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
10600 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
10601 }
10602 }
10603
James Smartda0436e2009-05-22 14:51:39 -040010604 return 0;
10605
James Smartda0436e2009-05-22 14:51:39 -040010606out_error:
James Smart67d12732012-08-03 12:36:13 -040010607 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010608 return -ENOMEM;
10609}
10610
James Smart895427b2017-02-12 13:52:30 -080010611static inline void
10612__lpfc_sli4_release_queue(struct lpfc_queue **qp)
10613{
10614 if (*qp != NULL) {
10615 lpfc_sli4_queue_free(*qp);
10616 *qp = NULL;
10617 }
10618}
10619
10620static inline void
10621lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
10622{
10623 int idx;
10624
10625 if (*qs == NULL)
10626 return;
10627
10628 for (idx = 0; idx < max; idx++)
10629 __lpfc_sli4_release_queue(&(*qs)[idx]);
10630
10631 kfree(*qs);
10632 *qs = NULL;
10633}
10634
10635static inline void
James Smart6a828b02019-01-28 11:14:31 -080010636lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -080010637{
James Smart6a828b02019-01-28 11:14:31 -080010638 struct lpfc_sli4_hdw_queue *hdwq;
James Smart657add42019-05-21 17:49:06 -070010639 struct lpfc_queue *eq;
James Smartcdb42be2019-01-28 11:14:21 -080010640 uint32_t idx;
10641
James Smart6a828b02019-01-28 11:14:31 -080010642 hdwq = phba->sli4_hba.hdwq;
James Smart6a828b02019-01-28 11:14:31 -080010643
James Smart657add42019-05-21 17:49:06 -070010644 /* Loop thru all Hardware Queues */
10645 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
10646 /* Free the CQ/WQ corresponding to the Hardware Queue */
James Smartc00f62e2019-08-14 16:57:11 -070010647 lpfc_sli4_queue_free(hdwq[idx].io_cq);
10648 lpfc_sli4_queue_free(hdwq[idx].io_wq);
James Smart821bc882020-01-27 16:23:05 -080010649 hdwq[idx].hba_eq = NULL;
James Smartc00f62e2019-08-14 16:57:11 -070010650 hdwq[idx].io_cq = NULL;
10651 hdwq[idx].io_wq = NULL;
James Smartd79c9e92019-08-14 16:57:09 -070010652 if (phba->cfg_xpsgl && !phba->nvmet_support)
10653 lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
10654 lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
James Smart895427b2017-02-12 13:52:30 -080010655 }
James Smart657add42019-05-21 17:49:06 -070010656 /* Loop thru all IRQ vectors */
10657 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
10658 /* Free the EQ corresponding to the IRQ vector */
10659 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
10660 lpfc_sli4_queue_free(eq);
10661 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
10662 }
James Smart895427b2017-02-12 13:52:30 -080010663}
10664
James Smartda0436e2009-05-22 14:51:39 -040010665/**
10666 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
10667 * @phba: pointer to lpfc hba data structure.
10668 *
10669 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
10670 * operation.
10671 *
10672 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010673 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010674 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010675 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010676 **/
James Smart5350d872011-10-10 21:33:49 -040010677void
James Smartda0436e2009-05-22 14:51:39 -040010678lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
10679{
James Smart4645f7b2019-03-12 16:30:14 -070010680 /*
10681 * Set FREE_INIT before beginning to free the queues.
10682 * Wait until the users of queues to acknowledge to
10683 * release queues by clearing FREE_WAIT.
10684 */
10685 spin_lock_irq(&phba->hbalock);
10686 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
10687 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
10688 spin_unlock_irq(&phba->hbalock);
10689 msleep(20);
10690 spin_lock_irq(&phba->hbalock);
10691 }
10692 spin_unlock_irq(&phba->hbalock);
10693
James Smart93a4d6f2019-11-04 16:57:05 -080010694 lpfc_sli4_cleanup_poll_list(phba);
10695
James Smart895427b2017-02-12 13:52:30 -080010696 /* Release HBA eqs */
James Smartcdb42be2019-01-28 11:14:21 -080010697 if (phba->sli4_hba.hdwq)
James Smart6a828b02019-01-28 11:14:31 -080010698 lpfc_sli4_release_hdwq(phba);
James Smartda0436e2009-05-22 14:51:39 -040010699
James Smartbcb24f62017-11-20 16:00:36 -080010700 if (phba->nvmet_support) {
10701 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
10702 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -080010703
James Smartbcb24f62017-11-20 16:00:36 -080010704 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
10705 phba->cfg_nvmet_mrq);
10706 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
10707 phba->cfg_nvmet_mrq);
10708 }
James Smart2d7dbc42017-02-12 13:52:35 -080010709
James Smartda0436e2009-05-22 14:51:39 -040010710 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -080010711 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -040010712
10713 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -080010714 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
10715
10716 /* Release ELS work queue */
10717 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -040010718
10719 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -080010720 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
10721 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -040010722
James Smartda0436e2009-05-22 14:51:39 -040010723 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -080010724 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
10725
10726 /* Release NVME LS complete queue */
10727 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -040010728
10729 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -080010730 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
10731
10732 /* Everything on this list has been freed */
10733 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart4645f7b2019-03-12 16:30:14 -070010734
10735 /* Done with freeing the queues */
10736 spin_lock_irq(&phba->hbalock);
10737 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
10738 spin_unlock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -080010739}
10740
10741int
James Smart895427b2017-02-12 13:52:30 -080010742lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
10743{
10744 struct lpfc_rqb *rqbp;
10745 struct lpfc_dmabuf *h_buf;
10746 struct rqb_dmabuf *rqb_buffer;
10747
10748 rqbp = rq->rqbp;
10749 while (!list_empty(&rqbp->rqb_buffer_list)) {
10750 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
10751 struct lpfc_dmabuf, list);
10752
10753 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
10754 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
10755 rqbp->buffer_count--;
10756 }
10757 return 1;
10758}
10759
10760static int
10761lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
10762 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
10763 int qidx, uint32_t qtype)
10764{
10765 struct lpfc_sli_ring *pring;
10766 int rc;
10767
10768 if (!eq || !cq || !wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010769 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080010770 "6085 Fast-path %s (%d) not allocated\n",
10771 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
10772 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -040010773 }
James Smartda0436e2009-05-22 14:51:39 -040010774
James Smart895427b2017-02-12 13:52:30 -080010775 /* create the Cq first */
10776 rc = lpfc_cq_create(phba, cq, eq,
10777 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
10778 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010779 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10780 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
10781 qidx, (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -080010782 return rc;
10783 }
10784
10785 if (qtype != LPFC_MBOX) {
James Smartcdb42be2019-01-28 11:14:21 -080010786 /* Setup cq_map for fast lookup */
James Smart895427b2017-02-12 13:52:30 -080010787 if (cq_map)
10788 *cq_map = cq->queue_id;
10789
10790 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10791 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
10792 qidx, cq->queue_id, qidx, eq->queue_id);
10793
10794 /* create the wq */
10795 rc = lpfc_wq_create(phba, wq, cq, qtype);
10796 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010797 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc835c082019-03-12 16:30:30 -070010798 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -080010799 qidx, (uint32_t)rc);
10800 /* no need to tear down cq - caller will do so */
10801 return rc;
10802 }
10803
10804 /* Bind this CQ/WQ to the NVME ring */
10805 pring = wq->pring;
10806 pring->sli.sli4.wqp = (void *)wq;
10807 cq->pring = pring;
10808
10809 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10810 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
10811 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
10812 } else {
10813 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
10814 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010815 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10816 "0539 Failed setup of slow-path MQ: "
10817 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -080010818 /* no need to tear down cq - caller will do so */
10819 return rc;
10820 }
10821
10822 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10823 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
10824 phba->sli4_hba.mbx_wq->queue_id,
10825 phba->sli4_hba.mbx_cq->queue_id);
10826 }
10827
10828 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010829}
10830
10831/**
James Smart6a828b02019-01-28 11:14:31 -080010832 * lpfc_setup_cq_lookup - Setup the CQ lookup table
10833 * @phba: pointer to lpfc hba data structure.
10834 *
10835 * This routine will populate the cq_lookup table by all
10836 * available CQ queue_id's.
10837 **/
Bart Van Assche3999df72019-03-28 11:06:16 -070010838static void
James Smart6a828b02019-01-28 11:14:31 -080010839lpfc_setup_cq_lookup(struct lpfc_hba *phba)
10840{
10841 struct lpfc_queue *eq, *childq;
James Smart6a828b02019-01-28 11:14:31 -080010842 int qidx;
10843
James Smart6a828b02019-01-28 11:14:31 -080010844 memset(phba->sli4_hba.cq_lookup, 0,
10845 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
James Smart657add42019-05-21 17:49:06 -070010846 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -080010847 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -070010848 /* Get the EQ corresponding to the IRQ vector */
10849 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
James Smart6a828b02019-01-28 11:14:31 -080010850 if (!eq)
10851 continue;
James Smart657add42019-05-21 17:49:06 -070010852 /* Loop through all CQs associated with that EQ */
James Smart6a828b02019-01-28 11:14:31 -080010853 list_for_each_entry(childq, &eq->child_list, list) {
10854 if (childq->queue_id > phba->sli4_hba.cq_max)
10855 continue;
James Smartc00f62e2019-08-14 16:57:11 -070010856 if (childq->subtype == LPFC_IO)
James Smart6a828b02019-01-28 11:14:31 -080010857 phba->sli4_hba.cq_lookup[childq->queue_id] =
10858 childq;
10859 }
10860 }
10861}
10862
10863/**
James Smartda0436e2009-05-22 14:51:39 -040010864 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
10865 * @phba: pointer to lpfc hba data structure.
10866 *
10867 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
10868 * operation.
10869 *
10870 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010871 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010872 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010873 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010874 **/
10875int
10876lpfc_sli4_queue_setup(struct lpfc_hba *phba)
10877{
James Smart962bc512013-01-03 15:44:00 -050010878 uint32_t shdr_status, shdr_add_status;
10879 union lpfc_sli4_cfg_shdr *shdr;
James Smart657add42019-05-21 17:49:06 -070010880 struct lpfc_vector_map_info *cpup;
James Smartcdb42be2019-01-28 11:14:21 -080010881 struct lpfc_sli4_hdw_queue *qp;
James Smart962bc512013-01-03 15:44:00 -050010882 LPFC_MBOXQ_t *mboxq;
James Smart657add42019-05-21 17:49:06 -070010883 int qidx, cpu;
James Smartcb733e32019-01-28 11:14:32 -080010884 uint32_t length, usdelay;
James Smart895427b2017-02-12 13:52:30 -080010885 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -050010886
10887 /* Check for dual-ULP support */
10888 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10889 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010890 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart962bc512013-01-03 15:44:00 -050010891 "3249 Unable to allocate memory for "
10892 "QUERY_FW_CFG mailbox command\n");
10893 return -ENOMEM;
10894 }
10895 length = (sizeof(struct lpfc_mbx_query_fw_config) -
10896 sizeof(struct lpfc_sli4_cfg_mhdr));
10897 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10898 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
10899 length, LPFC_SLI4_MBX_EMBED);
10900
10901 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10902
10903 shdr = (union lpfc_sli4_cfg_shdr *)
10904 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10905 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10906 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
10907 if (shdr_status || shdr_add_status || rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010908 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart962bc512013-01-03 15:44:00 -050010909 "3250 QUERY_FW_CFG mailbox failed with status "
10910 "x%x add_status x%x, mbx status x%x\n",
10911 shdr_status, shdr_add_status, rc);
James Smart304ee432021-04-11 18:31:17 -070010912 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart962bc512013-01-03 15:44:00 -050010913 rc = -ENXIO;
10914 goto out_error;
10915 }
10916
10917 phba->sli4_hba.fw_func_mode =
10918 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
10919 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
10920 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -040010921 phba->sli4_hba.physical_port =
10922 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -050010923 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10924 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
10925 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
10926 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
10927
James Smart304ee432021-04-11 18:31:17 -070010928 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -040010929
10930 /*
James Smart67d12732012-08-03 12:36:13 -040010931 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -040010932 */
James Smartcdb42be2019-01-28 11:14:21 -080010933 qp = phba->sli4_hba.hdwq;
James Smartda0436e2009-05-22 14:51:39 -040010934
James Smart67d12732012-08-03 12:36:13 -040010935 /* Set up HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -080010936 if (!qp) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010937 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2e90f4b2011-12-13 13:22:37 -050010938 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -050010939 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -040010940 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -050010941 }
James Smart657add42019-05-21 17:49:06 -070010942
10943 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -080010944 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -070010945 /* Create HBA Event Queues (EQs) in order */
10946 for_each_present_cpu(cpu) {
10947 cpup = &phba->sli4_hba.cpu_map[cpu];
10948
10949 /* Look for the CPU thats using that vector with
10950 * LPFC_CPU_FIRST_IRQ set.
10951 */
10952 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
10953 continue;
10954 if (qidx != cpup->eq)
10955 continue;
10956
10957 /* Create an EQ for that vector */
10958 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
10959 phba->cfg_fcp_imax);
10960 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010961 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart657add42019-05-21 17:49:06 -070010962 "0523 Failed setup of fast-path"
10963 " EQ (%d), rc = 0x%x\n",
10964 cpup->eq, (uint32_t)rc);
10965 goto out_destroy;
10966 }
10967
10968 /* Save the EQ for that vector in the hba_eq_hdl */
10969 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
10970 qp[cpup->hdwq].hba_eq;
10971
10972 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10973 "2584 HBA EQ setup: queue[%d]-id=%d\n",
10974 cpup->eq,
10975 qp[cpup->hdwq].hba_eq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -040010976 }
James Smartda0436e2009-05-22 14:51:39 -040010977 }
10978
James Smart657add42019-05-21 17:49:06 -070010979 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -080010980 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -070010981 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
10982 cpup = &phba->sli4_hba.cpu_map[cpu];
10983
10984 /* Create the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -080010985 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -070010986 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartc00f62e2019-08-14 16:57:11 -070010987 qp[qidx].io_cq,
10988 qp[qidx].io_wq,
10989 &phba->sli4_hba.hdwq[qidx].io_cq_map,
10990 qidx,
10991 LPFC_IO);
James Smartcdb42be2019-01-28 11:14:21 -080010992 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070010993 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080010994 "0535 Failed to setup fastpath "
James Smartc00f62e2019-08-14 16:57:11 -070010995 "IO WQ/CQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -080010996 qidx, (uint32_t)rc);
James Smartcdb42be2019-01-28 11:14:21 -080010997 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -080010998 }
James Smart67d12732012-08-03 12:36:13 -040010999 }
James Smartda0436e2009-05-22 14:51:39 -040011000
11001 /*
James Smart895427b2017-02-12 13:52:30 -080011002 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -040011003 */
11004
James Smart895427b2017-02-12 13:52:30 -080011005 /* Set up slow-path MBOX CQ/MQ */
11006
11007 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011008 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080011009 "0528 %s not allocated\n",
11010 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -070011011 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -050011012 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -080011013 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011014 }
James Smart895427b2017-02-12 13:52:30 -080011015
James Smartcdb42be2019-01-28 11:14:21 -080011016 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
James Smartd1f525a2017-04-21 16:04:55 -070011017 phba->sli4_hba.mbx_cq,
11018 phba->sli4_hba.mbx_wq,
11019 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -040011020 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011021 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080011022 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
11023 (uint32_t)rc);
11024 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011025 }
James Smart2d7dbc42017-02-12 13:52:35 -080011026 if (phba->nvmet_support) {
11027 if (!phba->sli4_hba.nvmet_cqset) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011028 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011029 "3165 Fast-path NVME CQ Set "
11030 "array not allocated\n");
11031 rc = -ENOMEM;
11032 goto out_destroy;
11033 }
11034 if (phba->cfg_nvmet_mrq > 1) {
11035 rc = lpfc_cq_create_set(phba,
11036 phba->sli4_hba.nvmet_cqset,
James Smartcdb42be2019-01-28 11:14:21 -080011037 qp,
James Smart2d7dbc42017-02-12 13:52:35 -080011038 LPFC_WCQ, LPFC_NVMET);
11039 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011040 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011041 "3164 Failed setup of NVME CQ "
11042 "Set, rc = 0x%x\n",
11043 (uint32_t)rc);
11044 goto out_destroy;
11045 }
11046 } else {
11047 /* Set up NVMET Receive Complete Queue */
11048 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
James Smartcdb42be2019-01-28 11:14:21 -080011049 qp[0].hba_eq,
James Smart2d7dbc42017-02-12 13:52:35 -080011050 LPFC_WCQ, LPFC_NVMET);
11051 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011052 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011053 "6089 Failed setup NVMET CQ: "
11054 "rc = 0x%x\n", (uint32_t)rc);
11055 goto out_destroy;
11056 }
James Smart81b96ed2017-11-20 16:00:29 -080011057 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
11058
James Smart2d7dbc42017-02-12 13:52:35 -080011059 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11060 "6090 NVMET CQ setup: cq-id=%d, "
11061 "parent eq-id=%d\n",
11062 phba->sli4_hba.nvmet_cqset[0]->queue_id,
James Smartcdb42be2019-01-28 11:14:21 -080011063 qp[0].hba_eq->queue_id);
James Smart2d7dbc42017-02-12 13:52:35 -080011064 }
11065 }
James Smartda0436e2009-05-22 14:51:39 -040011066
James Smart895427b2017-02-12 13:52:30 -080011067 /* Set up slow-path ELS WQ/CQ */
11068 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011069 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080011070 "0530 ELS %s not allocated\n",
11071 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -050011072 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -080011073 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011074 }
James Smartcdb42be2019-01-28 11:14:21 -080011075 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11076 phba->sli4_hba.els_cq,
11077 phba->sli4_hba.els_wq,
11078 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -040011079 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011080 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -080011081 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
11082 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -080011083 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011084 }
11085 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11086 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
11087 phba->sli4_hba.els_wq->queue_id,
11088 phba->sli4_hba.els_cq->queue_id);
11089
James Smartcdb42be2019-01-28 11:14:21 -080011090 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011091 /* Set up NVME LS Complete Queue */
11092 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011093 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart895427b2017-02-12 13:52:30 -080011094 "6091 LS %s not allocated\n",
11095 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
11096 rc = -ENOMEM;
11097 goto out_destroy;
11098 }
James Smartcdb42be2019-01-28 11:14:21 -080011099 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
11100 phba->sli4_hba.nvmels_cq,
11101 phba->sli4_hba.nvmels_wq,
11102 NULL, 0, LPFC_NVME_LS);
James Smart895427b2017-02-12 13:52:30 -080011103 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011104 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartcdb42be2019-01-28 11:14:21 -080011105 "0526 Failed setup of NVVME LS WQ/CQ: "
11106 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -080011107 goto out_destroy;
11108 }
11109
11110 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11111 "6096 ELS WQ setup: wq-id=%d, "
11112 "parent cq-id=%d\n",
11113 phba->sli4_hba.nvmels_wq->queue_id,
11114 phba->sli4_hba.nvmels_cq->queue_id);
11115 }
11116
James Smart2d7dbc42017-02-12 13:52:35 -080011117 /*
11118 * Create NVMET Receive Queue (RQ)
11119 */
11120 if (phba->nvmet_support) {
11121 if ((!phba->sli4_hba.nvmet_cqset) ||
11122 (!phba->sli4_hba.nvmet_mrq_hdr) ||
11123 (!phba->sli4_hba.nvmet_mrq_data)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011124 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011125 "6130 MRQ CQ Queues not "
11126 "allocated\n");
11127 rc = -ENOMEM;
11128 goto out_destroy;
11129 }
11130 if (phba->cfg_nvmet_mrq > 1) {
11131 rc = lpfc_mrq_create(phba,
11132 phba->sli4_hba.nvmet_mrq_hdr,
11133 phba->sli4_hba.nvmet_mrq_data,
11134 phba->sli4_hba.nvmet_cqset,
11135 LPFC_NVMET);
11136 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011137 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011138 "6098 Failed setup of NVMET "
11139 "MRQ: rc = 0x%x\n",
11140 (uint32_t)rc);
11141 goto out_destroy;
11142 }
11143
11144 } else {
11145 rc = lpfc_rq_create(phba,
11146 phba->sli4_hba.nvmet_mrq_hdr[0],
11147 phba->sli4_hba.nvmet_mrq_data[0],
11148 phba->sli4_hba.nvmet_cqset[0],
11149 LPFC_NVMET);
11150 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011151 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2d7dbc42017-02-12 13:52:35 -080011152 "6057 Failed setup of NVMET "
11153 "Receive Queue: rc = 0x%x\n",
11154 (uint32_t)rc);
11155 goto out_destroy;
11156 }
11157
11158 lpfc_printf_log(
11159 phba, KERN_INFO, LOG_INIT,
11160 "6099 NVMET RQ setup: hdr-rq-id=%d, "
11161 "dat-rq-id=%d parent cq-id=%d\n",
11162 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
11163 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
11164 phba->sli4_hba.nvmet_cqset[0]->queue_id);
11165
11166 }
11167 }
11168
James Smartda0436e2009-05-22 14:51:39 -040011169 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011170 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040011171 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -050011172 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -080011173 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011174 }
James Smart73d91e52011-10-10 21:32:10 -040011175
James Smartda0436e2009-05-22 14:51:39 -040011176 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -040011177 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -040011178 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011179 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040011180 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -040011181 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -080011182 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -040011183 }
James Smart73d91e52011-10-10 21:32:10 -040011184
James Smartda0436e2009-05-22 14:51:39 -040011185 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11186 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
11187 "parent cq-id=%d\n",
11188 phba->sli4_hba.hdr_rq->queue_id,
11189 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -040011190 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -050011191
James Smartcb733e32019-01-28 11:14:32 -080011192 if (phba->cfg_fcp_imax)
11193 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
11194 else
11195 usdelay = 0;
11196
James Smart6a828b02019-01-28 11:14:31 -080011197 for (qidx = 0; qidx < phba->cfg_irq_chann;
James Smartcdb42be2019-01-28 11:14:21 -080011198 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -070011199 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -080011200 usdelay);
James Smart43140ca2017-03-04 09:30:34 -080011201
James Smart6a828b02019-01-28 11:14:31 -080011202 if (phba->sli4_hba.cq_max) {
11203 kfree(phba->sli4_hba.cq_lookup);
11204 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
11205 sizeof(struct lpfc_queue *), GFP_KERNEL);
11206 if (!phba->sli4_hba.cq_lookup) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011207 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6a828b02019-01-28 11:14:31 -080011208 "0549 Failed setup of CQ Lookup table: "
11209 "size 0x%x\n", phba->sli4_hba.cq_max);
Dan Carpenterfad28e32019-02-11 21:43:00 +030011210 rc = -ENOMEM;
James Smart1ba981f2014-02-20 09:56:45 -050011211 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -080011212 }
James Smart6a828b02019-01-28 11:14:31 -080011213 lpfc_setup_cq_lookup(phba);
James Smart1ba981f2014-02-20 09:56:45 -050011214 }
James Smartda0436e2009-05-22 14:51:39 -040011215 return 0;
11216
James Smart895427b2017-02-12 13:52:30 -080011217out_destroy:
11218 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011219out_error:
11220 return rc;
11221}
11222
11223/**
11224 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
11225 * @phba: pointer to lpfc hba data structure.
11226 *
11227 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
11228 * operation.
11229 *
11230 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011231 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030011232 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040011233 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040011234 **/
11235void
11236lpfc_sli4_queue_unset(struct lpfc_hba *phba)
11237{
James Smartcdb42be2019-01-28 11:14:21 -080011238 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -070011239 struct lpfc_queue *eq;
James Smart895427b2017-02-12 13:52:30 -080011240 int qidx;
James Smartda0436e2009-05-22 14:51:39 -040011241
11242 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -080011243 if (phba->sli4_hba.mbx_wq)
11244 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
11245
11246 /* Unset NVME LS work queue */
11247 if (phba->sli4_hba.nvmels_wq)
11248 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
11249
James Smartda0436e2009-05-22 14:51:39 -040011250 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +010011251 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -080011252 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
11253
James Smartda0436e2009-05-22 14:51:39 -040011254 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -080011255 if (phba->sli4_hba.hdr_rq)
11256 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
11257 phba->sli4_hba.dat_rq);
11258
James Smartda0436e2009-05-22 14:51:39 -040011259 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -080011260 if (phba->sli4_hba.mbx_cq)
11261 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
11262
James Smartda0436e2009-05-22 14:51:39 -040011263 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -080011264 if (phba->sli4_hba.els_cq)
11265 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
11266
11267 /* Unset NVME LS complete queue */
11268 if (phba->sli4_hba.nvmels_cq)
11269 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
11270
James Smartbcb24f62017-11-20 16:00:36 -080011271 if (phba->nvmet_support) {
11272 /* Unset NVMET MRQ queue */
11273 if (phba->sli4_hba.nvmet_mrq_hdr) {
11274 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11275 lpfc_rq_destroy(
11276 phba,
James Smart2d7dbc42017-02-12 13:52:35 -080011277 phba->sli4_hba.nvmet_mrq_hdr[qidx],
11278 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -080011279 }
James Smart2d7dbc42017-02-12 13:52:35 -080011280
James Smartbcb24f62017-11-20 16:00:36 -080011281 /* Unset NVMET CQ Set complete queue */
11282 if (phba->sli4_hba.nvmet_cqset) {
11283 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
11284 lpfc_cq_destroy(
11285 phba, phba->sli4_hba.nvmet_cqset[qidx]);
11286 }
James Smart2d7dbc42017-02-12 13:52:35 -080011287 }
11288
James Smartcdb42be2019-01-28 11:14:21 -080011289 /* Unset fast-path SLI4 queues */
11290 if (phba->sli4_hba.hdwq) {
James Smart657add42019-05-21 17:49:06 -070011291 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -080011292 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -070011293 /* Destroy the CQ/WQ corresponding to Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -080011294 qp = &phba->sli4_hba.hdwq[qidx];
James Smartc00f62e2019-08-14 16:57:11 -070011295 lpfc_wq_destroy(phba, qp->io_wq);
11296 lpfc_cq_destroy(phba, qp->io_cq);
James Smart657add42019-05-21 17:49:06 -070011297 }
11298 /* Loop thru all IRQ vectors */
11299 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
11300 /* Destroy the EQ corresponding to the IRQ vector */
11301 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
11302 lpfc_eq_destroy(phba, eq);
James Smartcdb42be2019-01-28 11:14:21 -080011303 }
11304 }
James Smart895427b2017-02-12 13:52:30 -080011305
James Smart6a828b02019-01-28 11:14:31 -080011306 kfree(phba->sli4_hba.cq_lookup);
11307 phba->sli4_hba.cq_lookup = NULL;
11308 phba->sli4_hba.cq_max = 0;
James Smartda0436e2009-05-22 14:51:39 -040011309}
11310
11311/**
11312 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
11313 * @phba: pointer to lpfc hba data structure.
11314 *
11315 * This routine is invoked to allocate and set up a pool of completion queue
11316 * events. The body of the completion queue event is a completion queue entry
11317 * CQE. For now, this pool is used for the interrupt service routine to queue
11318 * the following HBA completion queue events for the worker thread to process:
11319 * - Mailbox asynchronous events
11320 * - Receive queue completion unsolicited events
11321 * Later, this can be used for all the slow-path events.
11322 *
11323 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011324 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030011325 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -040011326 **/
11327static int
11328lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
11329{
11330 struct lpfc_cq_event *cq_event;
11331 int i;
11332
11333 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
11334 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
11335 if (!cq_event)
11336 goto out_pool_create_fail;
11337 list_add_tail(&cq_event->list,
11338 &phba->sli4_hba.sp_cqe_event_pool);
11339 }
11340 return 0;
11341
11342out_pool_create_fail:
11343 lpfc_sli4_cq_event_pool_destroy(phba);
11344 return -ENOMEM;
11345}
11346
11347/**
11348 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
11349 * @phba: pointer to lpfc hba data structure.
11350 *
11351 * This routine is invoked to free the pool of completion queue events at
11352 * driver unload time. Note that, it is the responsibility of the driver
11353 * cleanup routine to free all the outstanding completion-queue events
11354 * allocated from this pool back into the pool before invoking this routine
11355 * to destroy the pool.
11356 **/
11357static void
11358lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
11359{
11360 struct lpfc_cq_event *cq_event, *next_cq_event;
11361
11362 list_for_each_entry_safe(cq_event, next_cq_event,
11363 &phba->sli4_hba.sp_cqe_event_pool, list) {
11364 list_del(&cq_event->list);
11365 kfree(cq_event);
11366 }
11367}
11368
11369/**
11370 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11371 * @phba: pointer to lpfc hba data structure.
11372 *
11373 * This routine is the lock free version of the API invoked to allocate a
11374 * completion-queue event from the free pool.
11375 *
11376 * Return: Pointer to the newly allocated completion-queue event if successful
11377 * NULL otherwise.
11378 **/
11379struct lpfc_cq_event *
11380__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11381{
11382 struct lpfc_cq_event *cq_event = NULL;
11383
11384 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
11385 struct lpfc_cq_event, list);
11386 return cq_event;
11387}
11388
11389/**
11390 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
11391 * @phba: pointer to lpfc hba data structure.
11392 *
11393 * This routine is the lock version of the API invoked to allocate a
11394 * completion-queue event from the free pool.
11395 *
11396 * Return: Pointer to the newly allocated completion-queue event if successful
11397 * NULL otherwise.
11398 **/
11399struct lpfc_cq_event *
11400lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
11401{
11402 struct lpfc_cq_event *cq_event;
11403 unsigned long iflags;
11404
11405 spin_lock_irqsave(&phba->hbalock, iflags);
11406 cq_event = __lpfc_sli4_cq_event_alloc(phba);
11407 spin_unlock_irqrestore(&phba->hbalock, iflags);
11408 return cq_event;
11409}
11410
11411/**
11412 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11413 * @phba: pointer to lpfc hba data structure.
11414 * @cq_event: pointer to the completion queue event to be freed.
11415 *
11416 * This routine is the lock free version of the API invoked to release a
11417 * completion-queue event back into the free pool.
11418 **/
11419void
11420__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11421 struct lpfc_cq_event *cq_event)
11422{
11423 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
11424}
11425
11426/**
11427 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
11428 * @phba: pointer to lpfc hba data structure.
11429 * @cq_event: pointer to the completion queue event to be freed.
11430 *
11431 * This routine is the lock version of the API invoked to release a
11432 * completion-queue event back into the free pool.
11433 **/
11434void
11435lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
11436 struct lpfc_cq_event *cq_event)
11437{
11438 unsigned long iflags;
11439 spin_lock_irqsave(&phba->hbalock, iflags);
11440 __lpfc_sli4_cq_event_release(phba, cq_event);
11441 spin_unlock_irqrestore(&phba->hbalock, iflags);
11442}
11443
11444/**
11445 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
11446 * @phba: pointer to lpfc hba data structure.
11447 *
11448 * This routine is to free all the pending completion-queue events to the
11449 * back into the free pool for device reset.
11450 **/
11451static void
11452lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
11453{
James Smarte7dab162020-10-20 13:27:12 -070011454 LIST_HEAD(cq_event_list);
11455 struct lpfc_cq_event *cq_event;
James Smartda0436e2009-05-22 14:51:39 -040011456 unsigned long iflags;
11457
11458 /* Retrieve all the pending WCQEs from pending WCQE lists */
James Smartda0436e2009-05-22 14:51:39 -040011459
James Smarte7dab162020-10-20 13:27:12 -070011460 /* Pending ELS XRI abort events */
11461 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11462 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
11463 &cq_event_list);
11464 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
11465
11466 /* Pending asynnc events */
11467 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
11468 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
11469 &cq_event_list);
11470 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
11471
11472 while (!list_empty(&cq_event_list)) {
11473 list_remove_head(&cq_event_list, cq_event,
11474 struct lpfc_cq_event, list);
11475 lpfc_sli4_cq_event_release(phba, cq_event);
James Smartda0436e2009-05-22 14:51:39 -040011476 }
11477}
11478
11479/**
11480 * lpfc_pci_function_reset - Reset pci function.
11481 * @phba: pointer to lpfc hba data structure.
11482 *
11483 * This routine is invoked to request a PCI function reset. It will destroys
11484 * all resources assigned to the PCI function which originates this request.
11485 *
11486 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011487 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030011488 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040011489 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040011490 **/
11491int
11492lpfc_pci_function_reset(struct lpfc_hba *phba)
11493{
11494 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -050011495 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -040011496 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -040011497 uint32_t rdy_chk;
11498 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -040011499 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -050011500 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -050011501 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -040011502
James Smart2fcee4b2010-12-15 17:57:46 -050011503 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11504 switch (if_type) {
11505 case LPFC_SLI_INTF_IF_TYPE_0:
11506 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
11507 GFP_KERNEL);
11508 if (!mboxq) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011509 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050011510 "0494 Unable to allocate memory for "
11511 "issuing SLI_FUNCTION_RESET mailbox "
11512 "command\n");
11513 return -ENOMEM;
11514 }
11515
11516 /* Setup PCI function reset mailbox-ioctl command */
11517 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11518 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
11519 LPFC_SLI4_MBX_EMBED);
11520 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11521 shdr = (union lpfc_sli4_cfg_shdr *)
11522 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
11523 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
11524 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
11525 &shdr->response);
James Smart304ee432021-04-11 18:31:17 -070011526 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart2fcee4b2010-12-15 17:57:46 -050011527 if (shdr_status || shdr_add_status || rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011528 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050011529 "0495 SLI_FUNCTION_RESET mailbox "
11530 "failed with status x%x add_status x%x,"
11531 " mbx status x%x\n",
11532 shdr_status, shdr_add_status, rc);
11533 rc = -ENXIO;
11534 }
11535 break;
11536 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -080011537 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -040011538wait:
11539 /*
11540 * Poll the Port Status Register and wait for RDY for
11541 * up to 30 seconds. If the port doesn't respond, treat
11542 * it as an error.
11543 */
James Smart77d093f2015-04-07 15:07:08 -040011544 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -040011545 if (lpfc_readl(phba->sli4_hba.u.if_type2.
11546 STATUSregaddr, &reg_data.word0)) {
11547 rc = -ENODEV;
11548 goto out;
11549 }
11550 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
11551 break;
11552 msleep(20);
11553 }
11554
11555 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
11556 phba->work_status[0] = readl(
11557 phba->sli4_hba.u.if_type2.ERR1regaddr);
11558 phba->work_status[1] = readl(
11559 phba->sli4_hba.u.if_type2.ERR2regaddr);
Dick Kennedy372c1872020-06-30 14:50:00 -070011560 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2f6fa2c2014-09-03 12:57:08 -040011561 "2890 Port not ready, port status reg "
11562 "0x%x error 1=0x%x, error 2=0x%x\n",
11563 reg_data.word0,
11564 phba->work_status[0],
11565 phba->work_status[1]);
11566 rc = -ENODEV;
11567 goto out;
11568 }
11569
11570 if (!port_reset) {
11571 /*
11572 * Reset the port now
11573 */
James Smart2fcee4b2010-12-15 17:57:46 -050011574 reg_data.word0 = 0;
11575 bf_set(lpfc_sliport_ctrl_end, &reg_data,
11576 LPFC_SLIPORT_LITTLE_ENDIAN);
11577 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
11578 LPFC_SLIPORT_INIT_PORT);
11579 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
11580 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -050011581 /* flush */
James Smart2b81f942012-03-01 22:37:18 -050011582 pci_read_config_word(phba->pcidev,
11583 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -050011584
James Smart2f6fa2c2014-09-03 12:57:08 -040011585 port_reset = 1;
11586 msleep(20);
11587 goto wait;
11588 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
11589 rc = -ENODEV;
11590 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -050011591 }
11592 break;
James Smart2f6fa2c2014-09-03 12:57:08 -040011593
James Smart2fcee4b2010-12-15 17:57:46 -050011594 case LPFC_SLI_INTF_IF_TYPE_1:
11595 default:
11596 break;
James Smartda0436e2009-05-22 14:51:39 -040011597 }
11598
James Smart73d91e52011-10-10 21:32:10 -040011599out:
James Smart2fcee4b2010-12-15 17:57:46 -050011600 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -040011601 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011602 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart229adb02013-04-17 20:16:51 -040011603 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -040011604 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -050011605 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -040011606 }
James Smart2fcee4b2010-12-15 17:57:46 -050011607
James Smartda0436e2009-05-22 14:51:39 -040011608 return rc;
11609}
11610
11611/**
James Smartda0436e2009-05-22 14:51:39 -040011612 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
11613 * @phba: pointer to lpfc hba data structure.
11614 *
11615 * This routine is invoked to set up the PCI device memory space for device
11616 * with SLI-4 interface spec.
11617 *
11618 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011619 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011620 * other values - error
11621 **/
11622static int
11623lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
11624{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020011625 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040011626 unsigned long bar0map_len, bar1map_len, bar2map_len;
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011627 int error;
James Smart2fcee4b2010-12-15 17:57:46 -050011628 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -040011629
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020011630 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +010011631 return -ENODEV;
James Smartda0436e2009-05-22 14:51:39 -040011632
11633 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +010011634 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
11635 if (error)
11636 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11637 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020011638 return error;
James Smartda0436e2009-05-22 14:51:39 -040011639
James Smart2fcee4b2010-12-15 17:57:46 -050011640 /*
11641 * The BARs and register set definitions and offset locations are
11642 * dependent on the if_type.
11643 */
11644 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
11645 &phba->sli4_hba.sli_intf.word0)) {
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011646 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050011647 }
11648
11649 /* There is no SLI3 failback for SLI4 devices. */
11650 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
11651 LPFC_SLI_INTF_VALID) {
Dick Kennedy372c1872020-06-30 14:50:00 -070011652 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart2fcee4b2010-12-15 17:57:46 -050011653 "2894 SLI_INTF reg contents invalid "
11654 "sli_intf reg 0x%x\n",
11655 phba->sli4_hba.sli_intf.word0);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011656 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050011657 }
11658
11659 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11660 /*
11661 * Get the bus address of SLI4 device Bar regions and the
11662 * number of bytes required by each mapping. The mapping of the
11663 * particular PCI BARs regions is dependent on the type of
11664 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -040011665 */
James Smartf5ca6f22013-09-06 12:21:09 -040011666 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
11667 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
11668 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -050011669
11670 /*
11671 * Map SLI4 PCI Config Space Register base to a kernel virtual
11672 * addr
11673 */
11674 phba->sli4_hba.conf_regs_memmap_p =
11675 ioremap(phba->pci_bar0_map, bar0map_len);
11676 if (!phba->sli4_hba.conf_regs_memmap_p) {
11677 dev_printk(KERN_ERR, &pdev->dev,
11678 "ioremap failed for SLI4 PCI config "
11679 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011680 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050011681 }
James Smartf5ca6f22013-09-06 12:21:09 -040011682 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -050011683 /* Set up BAR0 PCI config space register memory map */
11684 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -050011685 } else {
11686 phba->pci_bar0_map = pci_resource_start(pdev, 1);
11687 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -080011688 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -050011689 dev_printk(KERN_ERR, &pdev->dev,
11690 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011691 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050011692 }
11693 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -040011694 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -050011695 if (!phba->sli4_hba.conf_regs_memmap_p) {
11696 dev_printk(KERN_ERR, &pdev->dev,
11697 "ioremap failed for SLI4 PCI config "
11698 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011699 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050011700 }
11701 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -040011702 }
11703
James Smarte4b97942017-11-20 16:00:31 -080011704 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11705 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
11706 /*
11707 * Map SLI4 if type 0 HBA Control Register base to a
11708 * kernel virtual address and setup the registers.
11709 */
11710 phba->pci_bar1_map = pci_resource_start(pdev,
11711 PCI_64BIT_BAR2);
11712 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11713 phba->sli4_hba.ctrl_regs_memmap_p =
11714 ioremap(phba->pci_bar1_map,
11715 bar1map_len);
11716 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
11717 dev_err(&pdev->dev,
11718 "ioremap failed for SLI4 HBA "
11719 "control registers.\n");
11720 error = -ENOMEM;
11721 goto out_iounmap_conf;
11722 }
11723 phba->pci_bar2_memmap_p =
11724 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -080011725 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -080011726 } else {
11727 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050011728 goto out_iounmap_conf;
11729 }
James Smartda0436e2009-05-22 14:51:39 -040011730 }
11731
James Smart27d6ac02018-02-22 08:18:42 -080011732 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
11733 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
11734 /*
11735 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
11736 * virtual address and setup the registers.
11737 */
11738 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
11739 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
11740 phba->sli4_hba.drbl_regs_memmap_p =
11741 ioremap(phba->pci_bar1_map, bar1map_len);
11742 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11743 dev_err(&pdev->dev,
11744 "ioremap failed for SLI4 HBA doorbell registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011745 error = -ENOMEM;
James Smart27d6ac02018-02-22 08:18:42 -080011746 goto out_iounmap_conf;
11747 }
11748 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
11749 lpfc_sli4_bar1_register_memmap(phba, if_type);
11750 }
11751
James Smarte4b97942017-11-20 16:00:31 -080011752 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
11753 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11754 /*
11755 * Map SLI4 if type 0 HBA Doorbell Register base to
11756 * a kernel virtual address and setup the registers.
11757 */
11758 phba->pci_bar2_map = pci_resource_start(pdev,
11759 PCI_64BIT_BAR4);
11760 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11761 phba->sli4_hba.drbl_regs_memmap_p =
11762 ioremap(phba->pci_bar2_map,
11763 bar2map_len);
11764 if (!phba->sli4_hba.drbl_regs_memmap_p) {
11765 dev_err(&pdev->dev,
11766 "ioremap failed for SLI4 HBA"
11767 " doorbell registers.\n");
11768 error = -ENOMEM;
11769 goto out_iounmap_ctrl;
11770 }
11771 phba->pci_bar4_memmap_p =
11772 phba->sli4_hba.drbl_regs_memmap_p;
11773 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
11774 if (error)
11775 goto out_iounmap_all;
11776 } else {
11777 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050011778 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -080011779 }
James Smartda0436e2009-05-22 14:51:39 -040011780 }
11781
James Smart1351e692018-02-22 08:18:43 -080011782 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
11783 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
11784 /*
11785 * Map SLI4 if type 6 HBA DPP Register base to a kernel
11786 * virtual address and setup the registers.
11787 */
11788 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
11789 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
11790 phba->sli4_hba.dpp_regs_memmap_p =
11791 ioremap(phba->pci_bar2_map, bar2map_len);
11792 if (!phba->sli4_hba.dpp_regs_memmap_p) {
11793 dev_err(&pdev->dev,
11794 "ioremap failed for SLI4 HBA dpp registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011795 error = -ENOMEM;
James Smart1351e692018-02-22 08:18:43 -080011796 goto out_iounmap_ctrl;
11797 }
11798 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
11799 }
11800
James Smartb71413d2018-02-22 08:18:40 -080011801 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -080011802 switch (if_type) {
11803 case LPFC_SLI_INTF_IF_TYPE_0:
11804 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -080011805 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080011806 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
11807 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080011808 break;
11809 case LPFC_SLI_INTF_IF_TYPE_6:
11810 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080011811 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
11812 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080011813 break;
11814 default:
11815 break;
James Smartb71413d2018-02-22 08:18:40 -080011816 }
11817
James Smartda0436e2009-05-22 14:51:39 -040011818 return 0;
11819
11820out_iounmap_all:
11821 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11822out_iounmap_ctrl:
11823 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11824out_iounmap_conf:
11825 iounmap(phba->sli4_hba.conf_regs_memmap_p);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030011826
James Smartda0436e2009-05-22 14:51:39 -040011827 return error;
11828}
11829
11830/**
11831 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
11832 * @phba: pointer to lpfc hba data structure.
11833 *
11834 * This routine is invoked to unset the PCI device memory space for device
11835 * with SLI-4 interface spec.
11836 **/
11837static void
11838lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
11839{
James Smart2e90f4b2011-12-13 13:22:37 -050011840 uint32_t if_type;
11841 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -040011842
James Smart2e90f4b2011-12-13 13:22:37 -050011843 switch (if_type) {
11844 case LPFC_SLI_INTF_IF_TYPE_0:
11845 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11846 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
11847 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11848 break;
11849 case LPFC_SLI_INTF_IF_TYPE_2:
11850 iounmap(phba->sli4_hba.conf_regs_memmap_p);
11851 break;
James Smart27d6ac02018-02-22 08:18:42 -080011852 case LPFC_SLI_INTF_IF_TYPE_6:
11853 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
11854 iounmap(phba->sli4_hba.conf_regs_memmap_p);
James Smart0b439192019-12-18 15:58:05 -080011855 if (phba->sli4_hba.dpp_regs_memmap_p)
11856 iounmap(phba->sli4_hba.dpp_regs_memmap_p);
James Smart27d6ac02018-02-22 08:18:42 -080011857 break;
James Smart2e90f4b2011-12-13 13:22:37 -050011858 case LPFC_SLI_INTF_IF_TYPE_1:
11859 default:
11860 dev_printk(KERN_ERR, &phba->pcidev->dev,
11861 "FATAL - unsupported SLI4 interface type - %d\n",
11862 if_type);
11863 break;
11864 }
James Smartda0436e2009-05-22 14:51:39 -040011865}
11866
11867/**
James Smart3772a992009-05-22 14:50:54 -040011868 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
11869 * @phba: pointer to lpfc hba data structure.
11870 *
11871 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011872 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -040011873 *
11874 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011875 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040011876 * other values - error
11877 **/
11878static int
11879lpfc_sli_enable_msix(struct lpfc_hba *phba)
11880{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011881 int rc;
James Smart3772a992009-05-22 14:50:54 -040011882 LPFC_MBOXQ_t *pmb;
11883
11884 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011885 rc = pci_alloc_irq_vectors(phba->pcidev,
11886 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
11887 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -040011888 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11889 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011890 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -040011891 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011892
James Smart3772a992009-05-22 14:50:54 -040011893 /*
11894 * Assign MSI-X vectors to interrupt handlers
11895 */
11896
11897 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011898 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040011899 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040011900 LPFC_SP_DRIVER_HANDLER_NAME, phba);
11901 if (rc) {
11902 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11903 "0421 MSI-X slow-path request_irq failed "
11904 "(%d)\n", rc);
11905 goto msi_fail_out;
11906 }
11907
11908 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011909 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040011910 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040011911 LPFC_FP_DRIVER_HANDLER_NAME, phba);
11912
11913 if (rc) {
11914 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11915 "0429 MSI-X fast-path request_irq failed "
11916 "(%d)\n", rc);
11917 goto irq_fail_out;
11918 }
11919
11920 /*
11921 * Configure HBA MSI-X attention conditions to messages
11922 */
11923 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11924
11925 if (!pmb) {
11926 rc = -ENOMEM;
Dick Kennedy372c1872020-06-30 14:50:00 -070011927 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040011928 "0474 Unable to allocate memory for issuing "
11929 "MBOX_CONFIG_MSI command\n");
11930 goto mem_fail_out;
11931 }
11932 rc = lpfc_config_msi(phba, pmb);
11933 if (rc)
11934 goto mbx_fail_out;
11935 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
11936 if (rc != MBX_SUCCESS) {
11937 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
11938 "0351 Config MSI mailbox command failed, "
11939 "mbxCmd x%x, mbxStatus x%x\n",
11940 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
11941 goto mbx_fail_out;
11942 }
11943
11944 /* Free memory allocated for mailbox command */
11945 mempool_free(pmb, phba->mbox_mem_pool);
11946 return rc;
11947
11948mbx_fail_out:
11949 /* Free memory allocated for mailbox command */
11950 mempool_free(pmb, phba->mbox_mem_pool);
11951
11952mem_fail_out:
11953 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011954 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040011955
11956irq_fail_out:
11957 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011958 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040011959
11960msi_fail_out:
11961 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011962 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011963
11964vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040011965 return rc;
11966}
11967
11968/**
James Smart3772a992009-05-22 14:50:54 -040011969 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
11970 * @phba: pointer to lpfc hba data structure.
11971 *
11972 * This routine is invoked to enable the MSI interrupt mode to device with
11973 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
11974 * enable the MSI vector. The device driver is responsible for calling the
11975 * request_irq() to register MSI vector with a interrupt the handler, which
11976 * is done in this function.
11977 *
11978 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011979 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040011980 * other values - error
11981 */
11982static int
11983lpfc_sli_enable_msi(struct lpfc_hba *phba)
11984{
11985 int rc;
11986
11987 rc = pci_enable_msi(phba->pcidev);
11988 if (!rc)
11989 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11990 "0462 PCI enable MSI mode success.\n");
11991 else {
11992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11993 "0471 PCI enable MSI mode failed (%d)\n", rc);
11994 return rc;
11995 }
11996
11997 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040011998 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040011999 if (rc) {
12000 pci_disable_msi(phba->pcidev);
12001 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12002 "0478 MSI request_irq failed (%d)\n", rc);
12003 }
12004 return rc;
12005}
12006
12007/**
James Smart3772a992009-05-22 14:50:54 -040012008 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
12009 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010012010 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
James Smart3772a992009-05-22 14:50:54 -040012011 *
12012 * This routine is invoked to enable device interrupt and associate driver's
12013 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
12014 * spec. Depends on the interrupt mode configured to the driver, the driver
12015 * will try to fallback from the configured interrupt mode to an interrupt
12016 * mode which is supported by the platform, kernel, and device in the order
12017 * of:
12018 * MSI-X -> MSI -> IRQ.
12019 *
12020 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020012021 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040012022 * other values - error
12023 **/
12024static uint32_t
12025lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
12026{
12027 uint32_t intr_mode = LPFC_INTR_ERROR;
12028 int retval;
12029
James Smartd2f25472021-01-04 10:02:27 -080012030 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
12031 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
12032 if (retval)
12033 return intr_mode;
12034 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
12035
James Smart3772a992009-05-22 14:50:54 -040012036 if (cfg_mode == 2) {
James Smartd2f25472021-01-04 10:02:27 -080012037 /* Now, try to enable MSI-X interrupt mode */
12038 retval = lpfc_sli_enable_msix(phba);
James Smart3772a992009-05-22 14:50:54 -040012039 if (!retval) {
James Smartd2f25472021-01-04 10:02:27 -080012040 /* Indicate initialization to MSI-X mode */
12041 phba->intr_type = MSIX;
12042 intr_mode = 2;
James Smart3772a992009-05-22 14:50:54 -040012043 }
12044 }
12045
12046 /* Fallback to MSI if MSI-X initialization failed */
12047 if (cfg_mode >= 1 && phba->intr_type == NONE) {
12048 retval = lpfc_sli_enable_msi(phba);
12049 if (!retval) {
12050 /* Indicate initialization to MSI mode */
12051 phba->intr_type = MSI;
12052 intr_mode = 1;
12053 }
12054 }
12055
12056 /* Fallback to INTx if both MSI-X/MSI initalization failed */
12057 if (phba->intr_type == NONE) {
12058 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
12059 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
12060 if (!retval) {
12061 /* Indicate initialization to INTx mode */
12062 phba->intr_type = INTx;
12063 intr_mode = 0;
12064 }
12065 }
12066 return intr_mode;
12067}
12068
12069/**
12070 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
12071 * @phba: pointer to lpfc hba data structure.
12072 *
12073 * This routine is invoked to disable device interrupt and disassociate the
12074 * driver's interrupt handler(s) from interrupt vector(s) to device with
12075 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
12076 * release the interrupt vector(s) for the message signaled interrupt.
12077 **/
12078static void
12079lpfc_sli_disable_intr(struct lpfc_hba *phba)
12080{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080012081 int nr_irqs, i;
12082
James Smart3772a992009-05-22 14:50:54 -040012083 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080012084 nr_irqs = LPFC_MSIX_VECTORS;
12085 else
12086 nr_irqs = 1;
12087
12088 for (i = 0; i < nr_irqs; i++)
12089 free_irq(pci_irq_vector(phba->pcidev, i), phba);
12090 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040012091
12092 /* Reset interrupt management states */
12093 phba->intr_type = NONE;
12094 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040012095}
12096
12097/**
James Smart657add42019-05-21 17:49:06 -070012098 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
James Smart6a828b02019-01-28 11:14:31 -080012099 * @phba: pointer to lpfc hba data structure.
12100 * @id: EQ vector index or Hardware Queue index
12101 * @match: LPFC_FIND_BY_EQ = match by EQ
12102 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
James Smart657add42019-05-21 17:49:06 -070012103 * Return the CPU that matches the selection criteria
James Smart6a828b02019-01-28 11:14:31 -080012104 */
12105static uint16_t
12106lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
12107{
12108 struct lpfc_vector_map_info *cpup;
12109 int cpu;
12110
James Smart657add42019-05-21 17:49:06 -070012111 /* Loop through all CPUs */
James Smart222e9232019-01-28 11:14:35 -080012112 for_each_present_cpu(cpu) {
12113 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070012114
12115 /* If we are matching by EQ, there may be multiple CPUs using
12116 * using the same vector, so select the one with
12117 * LPFC_CPU_FIRST_IRQ set.
12118 */
James Smart6a828b02019-01-28 11:14:31 -080012119 if ((match == LPFC_FIND_BY_EQ) &&
James Smart657add42019-05-21 17:49:06 -070012120 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
James Smart6a828b02019-01-28 11:14:31 -080012121 (cpup->eq == id))
12122 return cpu;
James Smart657add42019-05-21 17:49:06 -070012123
12124 /* If matching by HDWQ, select the first CPU that matches */
James Smart6a828b02019-01-28 11:14:31 -080012125 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
12126 return cpu;
James Smart6a828b02019-01-28 11:14:31 -080012127 }
12128 return 0;
12129}
12130
James Smart6a828b02019-01-28 11:14:31 -080012131#ifdef CONFIG_X86
12132/**
12133 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
12134 * @phba: pointer to lpfc hba data structure.
12135 * @cpu: CPU map index
12136 * @phys_id: CPU package physical id
12137 * @core_id: CPU core id
12138 */
12139static int
12140lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
12141 uint16_t phys_id, uint16_t core_id)
12142{
12143 struct lpfc_vector_map_info *cpup;
12144 int idx;
12145
James Smart222e9232019-01-28 11:14:35 -080012146 for_each_present_cpu(idx) {
12147 cpup = &phba->sli4_hba.cpu_map[idx];
James Smart6a828b02019-01-28 11:14:31 -080012148 /* Does the cpup match the one we are looking for */
12149 if ((cpup->phys_id == phys_id) &&
12150 (cpup->core_id == core_id) &&
James Smart222e9232019-01-28 11:14:35 -080012151 (cpu != idx))
James Smart6a828b02019-01-28 11:14:31 -080012152 return 1;
James Smart6a828b02019-01-28 11:14:31 -080012153 }
12154 return 0;
12155}
12156#endif
12157
James Smartdcaa2132019-11-04 16:57:06 -080012158/*
12159 * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
12160 * @phba: pointer to lpfc hba data structure.
12161 * @eqidx: index for eq and irq vector
12162 * @flag: flags to set for vector_map structure
12163 * @cpu: cpu used to index vector_map structure
12164 *
12165 * The routine assigns eq info into vector_map structure
12166 */
12167static inline void
12168lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
12169 unsigned int cpu)
12170{
12171 struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
12172 struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
12173
12174 cpup->eq = eqidx;
12175 cpup->flag |= flag;
12176
12177 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12178 "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
12179 cpu, eqhdl->irq, cpup->eq, cpup->flag);
12180}
12181
12182/**
12183 * lpfc_cpu_map_array_init - Initialize cpu_map structure
12184 * @phba: pointer to lpfc hba data structure.
12185 *
12186 * The routine initializes the cpu_map array structure
12187 */
12188static void
12189lpfc_cpu_map_array_init(struct lpfc_hba *phba)
12190{
12191 struct lpfc_vector_map_info *cpup;
12192 struct lpfc_eq_intr_info *eqi;
12193 int cpu;
12194
12195 for_each_possible_cpu(cpu) {
12196 cpup = &phba->sli4_hba.cpu_map[cpu];
12197 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
12198 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
12199 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
12200 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
12201 cpup->flag = 0;
12202 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
12203 INIT_LIST_HEAD(&eqi->list);
12204 eqi->icnt = 0;
12205 }
12206}
12207
12208/**
12209 * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
12210 * @phba: pointer to lpfc hba data structure.
12211 *
12212 * The routine initializes the hba_eq_hdl array structure
12213 */
12214static void
12215lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
12216{
12217 struct lpfc_hba_eq_hdl *eqhdl;
12218 int i;
12219
12220 for (i = 0; i < phba->cfg_irq_chann; i++) {
12221 eqhdl = lpfc_get_eq_hdl(i);
12222 eqhdl->irq = LPFC_VECTOR_MAP_EMPTY;
12223 eqhdl->phba = phba;
12224 }
12225}
12226
James Smart6a828b02019-01-28 11:14:31 -080012227/**
James Smart895427b2017-02-12 13:52:30 -080012228 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040012229 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080012230 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040012231 *
James Smart895427b2017-02-12 13:52:30 -080012232 * The routine will figure out the CPU affinity assignment for every
James Smart6a828b02019-01-28 11:14:31 -080012233 * MSI-X vector allocated for the HBA.
James Smart895427b2017-02-12 13:52:30 -080012234 * In addition, the CPU to IO channel mapping will be calculated
12235 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040012236 */
James Smart895427b2017-02-12 13:52:30 -080012237static void
12238lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040012239{
James Smart3ad348d2019-08-14 16:56:43 -070012240 int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
James Smart6a828b02019-01-28 11:14:31 -080012241 int max_phys_id, min_phys_id;
12242 int max_core_id, min_core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040012243 struct lpfc_vector_map_info *cpup;
James Smartd9954a22019-05-21 17:49:05 -070012244 struct lpfc_vector_map_info *new_cpup;
James Smart7bb03bb2013-04-17 20:19:16 -040012245#ifdef CONFIG_X86
12246 struct cpuinfo_x86 *cpuinfo;
12247#endif
James Smart840eda92020-03-22 11:13:00 -070012248#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12249 struct lpfc_hdwq_stat *c_stat;
12250#endif
James Smart7bb03bb2013-04-17 20:19:16 -040012251
James Smart6a828b02019-01-28 11:14:31 -080012252 max_phys_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070012253 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
James Smart6a828b02019-01-28 11:14:31 -080012254 max_core_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070012255 min_core_id = LPFC_VECTOR_MAP_EMPTY;
James Smart7bb03bb2013-04-17 20:19:16 -040012256
12257 /* Update CPU map with physical id and core id of each CPU */
James Smart222e9232019-01-28 11:14:35 -080012258 for_each_present_cpu(cpu) {
12259 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart7bb03bb2013-04-17 20:19:16 -040012260#ifdef CONFIG_X86
12261 cpuinfo = &cpu_data(cpu);
12262 cpup->phys_id = cpuinfo->phys_proc_id;
12263 cpup->core_id = cpuinfo->cpu_core_id;
James Smartd9954a22019-05-21 17:49:05 -070012264 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
12265 cpup->flag |= LPFC_CPU_MAP_HYPER;
James Smart7bb03bb2013-04-17 20:19:16 -040012266#else
12267 /* No distinction between CPUs for other platforms */
12268 cpup->phys_id = 0;
James Smart6a828b02019-01-28 11:14:31 -080012269 cpup->core_id = cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040012270#endif
James Smart7bb03bb2013-04-17 20:19:16 -040012271
James Smartb3295c22019-01-28 11:14:30 -080012272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart3ad348d2019-08-14 16:56:43 -070012273 "3328 CPU %d physid %d coreid %d flag x%x\n",
12274 cpu, cpup->phys_id, cpup->core_id, cpup->flag);
James Smart6a828b02019-01-28 11:14:31 -080012275
12276 if (cpup->phys_id > max_phys_id)
12277 max_phys_id = cpup->phys_id;
12278 if (cpup->phys_id < min_phys_id)
12279 min_phys_id = cpup->phys_id;
12280
12281 if (cpup->core_id > max_core_id)
12282 max_core_id = cpup->core_id;
12283 if (cpup->core_id < min_core_id)
12284 min_core_id = cpup->core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040012285 }
James Smartb3295c22019-01-28 11:14:30 -080012286
James Smartd9954a22019-05-21 17:49:05 -070012287 /* After looking at each irq vector assigned to this pcidev, its
12288 * possible to see that not ALL CPUs have been accounted for.
James Smart657add42019-05-21 17:49:06 -070012289 * Next we will set any unassigned (unaffinitized) cpu map
12290 * entries to a IRQ on the same phys_id.
James Smartd9954a22019-05-21 17:49:05 -070012291 */
12292 first_cpu = cpumask_first(cpu_present_mask);
12293 start_cpu = first_cpu;
12294
12295 for_each_present_cpu(cpu) {
12296 cpup = &phba->sli4_hba.cpu_map[cpu];
12297
12298 /* Is this CPU entry unassigned */
12299 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12300 /* Mark CPU as IRQ not assigned by the kernel */
12301 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12302
James Smart657add42019-05-21 17:49:06 -070012303 /* If so, find a new_cpup thats on the the SAME
James Smartd9954a22019-05-21 17:49:05 -070012304 * phys_id as cpup. start_cpu will start where we
12305 * left off so all unassigned entries don't get assgined
12306 * the IRQ of the first entry.
12307 */
12308 new_cpu = start_cpu;
12309 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12310 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12311 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
James Smartdcaa2132019-11-04 16:57:06 -080012312 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
James Smartd9954a22019-05-21 17:49:05 -070012313 (new_cpup->phys_id == cpup->phys_id))
12314 goto found_same;
12315 new_cpu = cpumask_next(
12316 new_cpu, cpu_present_mask);
12317 if (new_cpu == nr_cpumask_bits)
12318 new_cpu = first_cpu;
12319 }
12320 /* At this point, we leave the CPU as unassigned */
12321 continue;
12322found_same:
12323 /* We found a matching phys_id, so copy the IRQ info */
12324 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070012325
12326 /* Bump start_cpu to the next slot to minmize the
12327 * chance of having multiple unassigned CPU entries
12328 * selecting the same IRQ.
12329 */
12330 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12331 if (start_cpu == nr_cpumask_bits)
12332 start_cpu = first_cpu;
12333
James Smart657add42019-05-21 17:49:06 -070012334 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070012335 "3337 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080012336 "eq %d from peer cpu %d same "
James Smartd9954a22019-05-21 17:49:05 -070012337 "phys_id (%d)\n",
James Smartdcaa2132019-11-04 16:57:06 -080012338 cpu, cpup->eq, new_cpu,
12339 cpup->phys_id);
James Smartd9954a22019-05-21 17:49:05 -070012340 }
12341 }
12342
12343 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
12344 start_cpu = first_cpu;
12345
12346 for_each_present_cpu(cpu) {
12347 cpup = &phba->sli4_hba.cpu_map[cpu];
12348
12349 /* Is this entry unassigned */
12350 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
12351 /* Mark it as IRQ not assigned by the kernel */
12352 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
12353
James Smart657add42019-05-21 17:49:06 -070012354 /* If so, find a new_cpup thats on ANY phys_id
James Smartd9954a22019-05-21 17:49:05 -070012355 * as the cpup. start_cpu will start where we
12356 * left off so all unassigned entries don't get
12357 * assigned the IRQ of the first entry.
12358 */
12359 new_cpu = start_cpu;
12360 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12361 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12362 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
James Smartdcaa2132019-11-04 16:57:06 -080012363 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
James Smartd9954a22019-05-21 17:49:05 -070012364 goto found_any;
12365 new_cpu = cpumask_next(
12366 new_cpu, cpu_present_mask);
12367 if (new_cpu == nr_cpumask_bits)
12368 new_cpu = first_cpu;
12369 }
12370 /* We should never leave an entry unassigned */
12371 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12372 "3339 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080012373 "eq %d UNASSIGNED\n",
12374 cpup->hdwq, cpup->eq);
James Smartd9954a22019-05-21 17:49:05 -070012375 continue;
12376found_any:
12377 /* We found an available entry, copy the IRQ info */
12378 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070012379
12380 /* Bump start_cpu to the next slot to minmize the
12381 * chance of having multiple unassigned CPU entries
12382 * selecting the same IRQ.
12383 */
12384 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12385 if (start_cpu == nr_cpumask_bits)
12386 start_cpu = first_cpu;
12387
James Smart657add42019-05-21 17:49:06 -070012388 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070012389 "3338 Set Affinity: CPU %d "
James Smartdcaa2132019-11-04 16:57:06 -080012390 "eq %d from peer cpu %d (%d/%d)\n",
12391 cpu, cpup->eq, new_cpu,
James Smartd9954a22019-05-21 17:49:05 -070012392 new_cpup->phys_id, new_cpup->core_id);
12393 }
12394 }
James Smart657add42019-05-21 17:49:06 -070012395
James Smart3ad348d2019-08-14 16:56:43 -070012396 /* Assign hdwq indices that are unique across all cpus in the map
12397 * that are also FIRST_CPUs.
12398 */
12399 idx = 0;
12400 for_each_present_cpu(cpu) {
12401 cpup = &phba->sli4_hba.cpu_map[cpu];
12402
12403 /* Only FIRST IRQs get a hdwq index assignment. */
12404 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12405 continue;
12406
12407 /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
12408 cpup->hdwq = idx;
12409 idx++;
Anton Blanchardbc2736e2020-07-13 18:39:08 +100012410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart3ad348d2019-08-14 16:56:43 -070012411 "3333 Set Affinity: CPU %d (phys %d core %d): "
James Smartdcaa2132019-11-04 16:57:06 -080012412 "hdwq %d eq %d flg x%x\n",
James Smart3ad348d2019-08-14 16:56:43 -070012413 cpu, cpup->phys_id, cpup->core_id,
James Smartdcaa2132019-11-04 16:57:06 -080012414 cpup->hdwq, cpup->eq, cpup->flag);
James Smart3ad348d2019-08-14 16:56:43 -070012415 }
James Smartbc227dd2019-11-11 15:03:59 -080012416 /* Associate a hdwq with each cpu_map entry
James Smart657add42019-05-21 17:49:06 -070012417 * This will be 1 to 1 - hdwq to cpu, unless there are less
12418 * hardware queues then CPUs. For that case we will just round-robin
12419 * the available hardware queues as they get assigned to CPUs.
James Smart3ad348d2019-08-14 16:56:43 -070012420 * The next_idx is the idx from the FIRST_CPU loop above to account
12421 * for irq_chann < hdwq. The idx is used for round-robin assignments
12422 * and needs to start at 0.
James Smart657add42019-05-21 17:49:06 -070012423 */
James Smart3ad348d2019-08-14 16:56:43 -070012424 next_idx = idx;
James Smart657add42019-05-21 17:49:06 -070012425 start_cpu = 0;
James Smart3ad348d2019-08-14 16:56:43 -070012426 idx = 0;
James Smart657add42019-05-21 17:49:06 -070012427 for_each_present_cpu(cpu) {
12428 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070012429
James Smart3ad348d2019-08-14 16:56:43 -070012430 /* FIRST cpus are already mapped. */
12431 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
12432 continue;
James Smart657add42019-05-21 17:49:06 -070012433
James Smart3ad348d2019-08-14 16:56:43 -070012434 /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
12435 * of the unassigned cpus to the next idx so that all
12436 * hdw queues are fully utilized.
12437 */
12438 if (next_idx < phba->cfg_hdw_queue) {
12439 cpup->hdwq = next_idx;
12440 next_idx++;
12441 continue;
James Smart657add42019-05-21 17:49:06 -070012442 }
James Smart3ad348d2019-08-14 16:56:43 -070012443
12444 /* Not a First CPU and all hdw_queues are used. Reuse a
12445 * Hardware Queue for another CPU, so be smart about it
12446 * and pick one that has its IRQ/EQ mapped to the same phys_id
12447 * (CPU package) and core_id.
12448 */
12449 new_cpu = start_cpu;
12450 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12451 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12452 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12453 new_cpup->phys_id == cpup->phys_id &&
12454 new_cpup->core_id == cpup->core_id) {
12455 goto found_hdwq;
12456 }
12457 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12458 if (new_cpu == nr_cpumask_bits)
12459 new_cpu = first_cpu;
12460 }
12461
12462 /* If we can't match both phys_id and core_id,
12463 * settle for just a phys_id match.
12464 */
12465 new_cpu = start_cpu;
12466 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
12467 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
12468 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
12469 new_cpup->phys_id == cpup->phys_id)
12470 goto found_hdwq;
12471
12472 new_cpu = cpumask_next(new_cpu, cpu_present_mask);
12473 if (new_cpu == nr_cpumask_bits)
12474 new_cpu = first_cpu;
12475 }
12476
12477 /* Otherwise just round robin on cfg_hdw_queue */
12478 cpup->hdwq = idx % phba->cfg_hdw_queue;
12479 idx++;
12480 goto logit;
12481 found_hdwq:
12482 /* We found an available entry, copy the IRQ info */
12483 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
12484 if (start_cpu == nr_cpumask_bits)
12485 start_cpu = first_cpu;
12486 cpup->hdwq = new_cpup->hdwq;
12487 logit:
Anton Blanchardbc2736e2020-07-13 18:39:08 +100012488 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart657add42019-05-21 17:49:06 -070012489 "3335 Set Affinity: CPU %d (phys %d core %d): "
James Smartdcaa2132019-11-04 16:57:06 -080012490 "hdwq %d eq %d flg x%x\n",
James Smart657add42019-05-21 17:49:06 -070012491 cpu, cpup->phys_id, cpup->core_id,
James Smartdcaa2132019-11-04 16:57:06 -080012492 cpup->hdwq, cpup->eq, cpup->flag);
James Smart657add42019-05-21 17:49:06 -070012493 }
12494
James Smartbc227dd2019-11-11 15:03:59 -080012495 /*
12496 * Initialize the cpu_map slots for not-present cpus in case
12497 * a cpu is hot-added. Perform a simple hdwq round robin assignment.
12498 */
12499 idx = 0;
12500 for_each_possible_cpu(cpu) {
12501 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart840eda92020-03-22 11:13:00 -070012502#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12503 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
12504 c_stat->hdwq_no = cpup->hdwq;
12505#endif
James Smartbc227dd2019-11-11 15:03:59 -080012506 if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
12507 continue;
12508
12509 cpup->hdwq = idx++ % phba->cfg_hdw_queue;
James Smart840eda92020-03-22 11:13:00 -070012510#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12511 c_stat->hdwq_no = cpup->hdwq;
12512#endif
James Smartbc227dd2019-11-11 15:03:59 -080012513 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12514 "3340 Set Affinity: not present "
12515 "CPU %d hdwq %d\n",
12516 cpu, cpup->hdwq);
James Smart657add42019-05-21 17:49:06 -070012517 }
12518
12519 /* The cpu_map array will be used later during initialization
12520 * when EQ / CQ / WQs are allocated and configured.
12521 */
James Smartb3295c22019-01-28 11:14:30 -080012522 return;
James Smart7bb03bb2013-04-17 20:19:16 -040012523}
James Smart7bb03bb2013-04-17 20:19:16 -040012524
12525/**
James Smart93a4d6f2019-11-04 16:57:05 -080012526 * lpfc_cpuhp_get_eq
12527 *
12528 * @phba: pointer to lpfc hba data structure.
12529 * @cpu: cpu going offline
Lee Jonesfe614ac2020-07-23 13:24:22 +010012530 * @eqlist: eq list to append to
James Smart93a4d6f2019-11-04 16:57:05 -080012531 */
James Smarta99c8072020-01-27 16:23:06 -080012532static int
James Smart93a4d6f2019-11-04 16:57:05 -080012533lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
12534 struct list_head *eqlist)
12535{
James Smart93a4d6f2019-11-04 16:57:05 -080012536 const struct cpumask *maskp;
12537 struct lpfc_queue *eq;
James Smarta99c8072020-01-27 16:23:06 -080012538 struct cpumask *tmp;
James Smart93a4d6f2019-11-04 16:57:05 -080012539 u16 idx;
12540
James Smarta99c8072020-01-27 16:23:06 -080012541 tmp = kzalloc(cpumask_size(), GFP_KERNEL);
12542 if (!tmp)
12543 return -ENOMEM;
12544
James Smart93a4d6f2019-11-04 16:57:05 -080012545 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12546 maskp = pci_irq_get_affinity(phba->pcidev, idx);
12547 if (!maskp)
12548 continue;
12549 /*
12550 * if irq is not affinitized to the cpu going
12551 * then we don't need to poll the eq attached
12552 * to it.
12553 */
James Smarta99c8072020-01-27 16:23:06 -080012554 if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
James Smart93a4d6f2019-11-04 16:57:05 -080012555 continue;
12556 /* get the cpus that are online and are affini-
12557 * tized to this irq vector. If the count is
12558 * more than 1 then cpuhp is not going to shut-
12559 * down this vector. Since this cpu has not
12560 * gone offline yet, we need >1.
12561 */
James Smarta99c8072020-01-27 16:23:06 -080012562 cpumask_and(tmp, maskp, cpu_online_mask);
12563 if (cpumask_weight(tmp) > 1)
James Smart93a4d6f2019-11-04 16:57:05 -080012564 continue;
12565
12566 /* Now that we have an irq to shutdown, get the eq
12567 * mapped to this irq. Note: multiple hdwq's in
12568 * the software can share an eq, but eventually
12569 * only eq will be mapped to this vector
12570 */
James Smartdcaa2132019-11-04 16:57:06 -080012571 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
12572 list_add(&eq->_poll_list, eqlist);
James Smart93a4d6f2019-11-04 16:57:05 -080012573 }
James Smarta99c8072020-01-27 16:23:06 -080012574 kfree(tmp);
12575 return 0;
James Smart93a4d6f2019-11-04 16:57:05 -080012576}
12577
12578static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
12579{
12580 if (phba->sli_rev != LPFC_SLI_REV4)
12581 return;
12582
12583 cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
12584 &phba->cpuhp);
12585 /*
12586 * unregistering the instance doesn't stop the polling
12587 * timer. Wait for the poll timer to retire.
12588 */
12589 synchronize_rcu();
12590 del_timer_sync(&phba->cpuhp_poll_timer);
12591}
12592
12593static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
12594{
12595 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
12596 return;
12597
12598 __lpfc_cpuhp_remove(phba);
12599}
12600
12601static void lpfc_cpuhp_add(struct lpfc_hba *phba)
12602{
12603 if (phba->sli_rev != LPFC_SLI_REV4)
12604 return;
12605
12606 rcu_read_lock();
12607
James Smartf861f592020-03-22 11:12:54 -070012608 if (!list_empty(&phba->poll_list))
James Smart93a4d6f2019-11-04 16:57:05 -080012609 mod_timer(&phba->cpuhp_poll_timer,
12610 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
James Smart93a4d6f2019-11-04 16:57:05 -080012611
12612 rcu_read_unlock();
12613
12614 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
12615 &phba->cpuhp);
12616}
12617
12618static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
12619{
12620 if (phba->pport->load_flag & FC_UNLOADING) {
12621 *retval = -EAGAIN;
12622 return true;
12623 }
12624
12625 if (phba->sli_rev != LPFC_SLI_REV4) {
12626 *retval = 0;
12627 return true;
12628 }
12629
12630 /* proceed with the hotplug */
12631 return false;
12632}
12633
James Smartdcaa2132019-11-04 16:57:06 -080012634/**
12635 * lpfc_irq_set_aff - set IRQ affinity
12636 * @eqhdl: EQ handle
12637 * @cpu: cpu to set affinity
12638 *
12639 **/
12640static inline void
12641lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
12642{
12643 cpumask_clear(&eqhdl->aff_mask);
12644 cpumask_set_cpu(cpu, &eqhdl->aff_mask);
12645 irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
12646 irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask);
12647}
12648
12649/**
12650 * lpfc_irq_clear_aff - clear IRQ affinity
12651 * @eqhdl: EQ handle
12652 *
12653 **/
12654static inline void
12655lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
12656{
12657 cpumask_clear(&eqhdl->aff_mask);
12658 irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
James Smartdcaa2132019-11-04 16:57:06 -080012659}
12660
12661/**
12662 * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
12663 * @phba: pointer to HBA context object.
12664 * @cpu: cpu going offline/online
12665 * @offline: true, cpu is going offline. false, cpu is coming online.
12666 *
12667 * If cpu is going offline, we'll try our best effort to find the next
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012668 * online cpu on the phba's original_mask and migrate all offlining IRQ
12669 * affinities.
James Smartdcaa2132019-11-04 16:57:06 -080012670 *
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012671 * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
James Smartdcaa2132019-11-04 16:57:06 -080012672 *
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012673 * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
James Smartdcaa2132019-11-04 16:57:06 -080012674 * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
12675 *
12676 **/
12677static void
12678lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
12679{
12680 struct lpfc_vector_map_info *cpup;
12681 struct cpumask *aff_mask;
12682 unsigned int cpu_select, cpu_next, idx;
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012683 const struct cpumask *orig_mask;
James Smartdcaa2132019-11-04 16:57:06 -080012684
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012685 if (phba->irq_chann_mode == NORMAL_MODE)
James Smartdcaa2132019-11-04 16:57:06 -080012686 return;
12687
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012688 orig_mask = &phba->sli4_hba.irq_aff_mask;
James Smartdcaa2132019-11-04 16:57:06 -080012689
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012690 if (!cpumask_test_cpu(cpu, orig_mask))
James Smartdcaa2132019-11-04 16:57:06 -080012691 return;
12692
12693 cpup = &phba->sli4_hba.cpu_map[cpu];
12694
12695 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
12696 return;
12697
12698 if (offline) {
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012699 /* Find next online CPU on original mask */
12700 cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
12701 cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
James Smartdcaa2132019-11-04 16:57:06 -080012702
12703 /* Found a valid CPU */
12704 if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
12705 /* Go through each eqhdl and ensure offlining
12706 * cpu aff_mask is migrated
12707 */
12708 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
12709 aff_mask = lpfc_get_aff_mask(idx);
12710
12711 /* Migrate affinity */
12712 if (cpumask_test_cpu(cpu, aff_mask))
12713 lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
12714 cpu_select);
12715 }
12716 } else {
12717 /* Rely on irqbalance if no online CPUs left on NUMA */
12718 for (idx = 0; idx < phba->cfg_irq_chann; idx++)
12719 lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
12720 }
12721 } else {
12722 /* Migrate affinity back to this CPU */
12723 lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
12724 }
12725}
12726
James Smart93a4d6f2019-11-04 16:57:05 -080012727static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
12728{
12729 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12730 struct lpfc_queue *eq, *next;
12731 LIST_HEAD(eqlist);
12732 int retval;
12733
12734 if (!phba) {
12735 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12736 return 0;
12737 }
12738
12739 if (__lpfc_cpuhp_checks(phba, &retval))
12740 return retval;
12741
James Smartdcaa2132019-11-04 16:57:06 -080012742 lpfc_irq_rebalance(phba, cpu, true);
12743
James Smarta99c8072020-01-27 16:23:06 -080012744 retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
12745 if (retval)
12746 return retval;
James Smart93a4d6f2019-11-04 16:57:05 -080012747
12748 /* start polling on these eq's */
12749 list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
12750 list_del_init(&eq->_poll_list);
12751 lpfc_sli4_start_polling(eq);
12752 }
12753
12754 return 0;
12755}
12756
12757static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
12758{
12759 struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
12760 struct lpfc_queue *eq, *next;
12761 unsigned int n;
12762 int retval;
12763
12764 if (!phba) {
12765 WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
12766 return 0;
12767 }
12768
12769 if (__lpfc_cpuhp_checks(phba, &retval))
12770 return retval;
12771
James Smartdcaa2132019-11-04 16:57:06 -080012772 lpfc_irq_rebalance(phba, cpu, false);
12773
James Smart93a4d6f2019-11-04 16:57:05 -080012774 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
12775 n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
12776 if (n == cpu)
12777 lpfc_sli4_stop_polling(eq);
12778 }
12779
12780 return 0;
12781}
12782
12783/**
James Smartda0436e2009-05-22 14:51:39 -040012784 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
12785 * @phba: pointer to lpfc hba data structure.
12786 *
12787 * This routine is invoked to enable the MSI-X interrupt vectors to device
James Smartdcaa2132019-11-04 16:57:06 -080012788 * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
12789 * to cpus on the system.
12790 *
12791 * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
12792 * the number of cpus on the same numa node as this adapter. The vectors are
12793 * allocated without requesting OS affinity mapping. A vector will be
12794 * allocated and assigned to each online and offline cpu. If the cpu is
12795 * online, then affinity will be set to that cpu. If the cpu is offline, then
12796 * affinity will be set to the nearest peer cpu within the numa node that is
12797 * online. If there are no online cpus within the numa node, affinity is not
12798 * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
12799 * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
12800 * configured.
12801 *
12802 * If numa mode is not enabled and there is more than 1 vector allocated, then
12803 * the driver relies on the managed irq interface where the OS assigns vector to
12804 * cpu affinity. The driver will then use that affinity mapping to setup its
12805 * cpu mapping table.
James Smartda0436e2009-05-22 14:51:39 -040012806 *
12807 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020012808 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040012809 * other values - error
12810 **/
12811static int
12812lpfc_sli4_enable_msix(struct lpfc_hba *phba)
12813{
James Smart75baf692010-06-08 18:31:21 -040012814 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070012815 char *name;
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012816 const struct cpumask *aff_mask = NULL;
James Smartdcaa2132019-11-04 16:57:06 -080012817 unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
Dick Kennedy17105d92020-07-06 13:42:30 -070012818 struct lpfc_vector_map_info *cpup;
James Smartdcaa2132019-11-04 16:57:06 -080012819 struct lpfc_hba_eq_hdl *eqhdl;
12820 const struct cpumask *maskp;
James Smartdcaa2132019-11-04 16:57:06 -080012821 unsigned int flags = PCI_IRQ_MSIX;
James Smartda0436e2009-05-22 14:51:39 -040012822
12823 /* Set up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080012824 vectors = phba->cfg_irq_chann;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080012825
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012826 if (phba->irq_chann_mode != NORMAL_MODE)
12827 aff_mask = &phba->sli4_hba.irq_aff_mask;
12828
12829 if (aff_mask) {
12830 cpu_cnt = cpumask_weight(aff_mask);
James Smartdcaa2132019-11-04 16:57:06 -080012831 vectors = min(phba->cfg_irq_chann, cpu_cnt);
12832
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012833 /* cpu: iterates over aff_mask including offline or online
12834 * cpu_select: iterates over online aff_mask to set affinity
James Smartdcaa2132019-11-04 16:57:06 -080012835 */
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012836 cpu = cpumask_first(aff_mask);
12837 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
James Smartdcaa2132019-11-04 16:57:06 -080012838 } else {
12839 flags |= PCI_IRQ_AFFINITY;
12840 }
12841
12842 rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040012843 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040012844 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12845 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020012846 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040012847 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040012848 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040012849
James Smart7bb03bb2013-04-17 20:19:16 -040012850 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040012851 for (index = 0; index < vectors; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080012852 eqhdl = lpfc_get_eq_hdl(index);
12853 name = eqhdl->handler_name;
James Smartb83d0052017-06-01 21:07:05 -070012854 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
12855 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040012856 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040012857
James Smartdcaa2132019-11-04 16:57:06 -080012858 eqhdl->idx = index;
James Smart7370d102019-01-28 11:14:20 -080012859 rc = request_irq(pci_irq_vector(phba->pcidev, index),
12860 &lpfc_sli4_hba_intr_handler, 0,
James Smartdcaa2132019-11-04 16:57:06 -080012861 name, eqhdl);
James Smartda0436e2009-05-22 14:51:39 -040012862 if (rc) {
12863 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12864 "0486 MSI-X fast-path (%d) "
12865 "request_irq failed (%d)\n", index, rc);
12866 goto cfg_fail_out;
12867 }
James Smartdcaa2132019-11-04 16:57:06 -080012868
12869 eqhdl->irq = pci_irq_vector(phba->pcidev, index);
12870
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012871 if (aff_mask) {
James Smartdcaa2132019-11-04 16:57:06 -080012872 /* If found a neighboring online cpu, set affinity */
12873 if (cpu_select < nr_cpu_ids)
12874 lpfc_irq_set_aff(eqhdl, cpu_select);
12875
12876 /* Assign EQ to cpu_map */
12877 lpfc_assign_eq_map_info(phba, index,
12878 LPFC_CPU_FIRST_IRQ,
12879 cpu);
12880
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012881 /* Iterate to next offline or online cpu in aff_mask */
12882 cpu = cpumask_next(cpu, aff_mask);
James Smartdcaa2132019-11-04 16:57:06 -080012883
Dick Kennedy3048e3e2020-05-01 14:43:06 -070012884 /* Find next online cpu in aff_mask to set affinity */
12885 cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
James Smartdcaa2132019-11-04 16:57:06 -080012886 } else if (vectors == 1) {
12887 cpu = cpumask_first(cpu_present_mask);
12888 lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
12889 cpu);
12890 } else {
12891 maskp = pci_irq_get_affinity(phba->pcidev, index);
12892
James Smartdcaa2132019-11-04 16:57:06 -080012893 /* Loop through all CPUs associated with vector index */
12894 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
Dick Kennedy17105d92020-07-06 13:42:30 -070012895 cpup = &phba->sli4_hba.cpu_map[cpu];
12896
James Smartdcaa2132019-11-04 16:57:06 -080012897 /* If this is the first CPU thats assigned to
12898 * this vector, set LPFC_CPU_FIRST_IRQ.
Dick Kennedy17105d92020-07-06 13:42:30 -070012899 *
12900 * With certain platforms its possible that irq
12901 * vectors are affinitized to all the cpu's.
12902 * This can result in each cpu_map.eq to be set
12903 * to the last vector, resulting in overwrite
12904 * of all the previous cpu_map.eq. Ensure that
12905 * each vector receives a place in cpu_map.
12906 * Later call to lpfc_cpu_affinity_check will
12907 * ensure we are nicely balanced out.
James Smartdcaa2132019-11-04 16:57:06 -080012908 */
Dick Kennedy17105d92020-07-06 13:42:30 -070012909 if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
12910 continue;
James Smartdcaa2132019-11-04 16:57:06 -080012911 lpfc_assign_eq_map_info(phba, index,
Dick Kennedy17105d92020-07-06 13:42:30 -070012912 LPFC_CPU_FIRST_IRQ,
James Smartdcaa2132019-11-04 16:57:06 -080012913 cpu);
Dick Kennedy17105d92020-07-06 13:42:30 -070012914 break;
James Smartdcaa2132019-11-04 16:57:06 -080012915 }
12916 }
James Smartda0436e2009-05-22 14:51:39 -040012917 }
12918
James Smart6a828b02019-01-28 11:14:31 -080012919 if (vectors != phba->cfg_irq_chann) {
Dick Kennedy372c1872020-06-30 14:50:00 -070012920 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart82c3e9b2012-09-29 11:29:50 -040012921 "3238 Reducing IO channels to match number of "
12922 "MSI-X vectors, requested %d got %d\n",
James Smart6a828b02019-01-28 11:14:31 -080012923 phba->cfg_irq_chann, vectors);
12924 if (phba->cfg_irq_chann > vectors)
12925 phba->cfg_irq_chann = vectors;
James Smart82c3e9b2012-09-29 11:29:50 -040012926 }
James Smart7bb03bb2013-04-17 20:19:16 -040012927
James Smartda0436e2009-05-22 14:51:39 -040012928 return rc;
12929
12930cfg_fail_out:
12931 /* free the irq already requested */
James Smartdcaa2132019-11-04 16:57:06 -080012932 for (--index; index >= 0; index--) {
12933 eqhdl = lpfc_get_eq_hdl(index);
12934 lpfc_irq_clear_aff(eqhdl);
12935 irq_set_affinity_hint(eqhdl->irq, NULL);
12936 free_irq(eqhdl->irq, eqhdl);
12937 }
James Smartda0436e2009-05-22 14:51:39 -040012938
James Smartda0436e2009-05-22 14:51:39 -040012939 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080012940 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020012941
12942vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040012943 return rc;
12944}
12945
12946/**
James Smartda0436e2009-05-22 14:51:39 -040012947 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
12948 * @phba: pointer to lpfc hba data structure.
12949 *
12950 * This routine is invoked to enable the MSI interrupt mode to device with
James Smart07b1b912019-08-14 16:56:58 -070012951 * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
12952 * called to enable the MSI vector. The device driver is responsible for
12953 * calling the request_irq() to register MSI vector with a interrupt the
12954 * handler, which is done in this function.
James Smartda0436e2009-05-22 14:51:39 -040012955 *
12956 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020012957 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040012958 * other values - error
12959 **/
12960static int
12961lpfc_sli4_enable_msi(struct lpfc_hba *phba)
12962{
12963 int rc, index;
James Smartdcaa2132019-11-04 16:57:06 -080012964 unsigned int cpu;
12965 struct lpfc_hba_eq_hdl *eqhdl;
James Smartda0436e2009-05-22 14:51:39 -040012966
James Smart07b1b912019-08-14 16:56:58 -070012967 rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
12968 PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
12969 if (rc > 0)
James Smartda0436e2009-05-22 14:51:39 -040012970 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12971 "0487 PCI enable MSI mode success.\n");
12972 else {
12973 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12974 "0488 PCI enable MSI mode failed (%d)\n", rc);
James Smart07b1b912019-08-14 16:56:58 -070012975 return rc ? rc : -1;
James Smartda0436e2009-05-22 14:51:39 -040012976 }
12977
12978 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040012979 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040012980 if (rc) {
James Smart07b1b912019-08-14 16:56:58 -070012981 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040012982 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
12983 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040012984 return rc;
James Smartda0436e2009-05-22 14:51:39 -040012985 }
12986
James Smartdcaa2132019-11-04 16:57:06 -080012987 eqhdl = lpfc_get_eq_hdl(0);
12988 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
12989
12990 cpu = cpumask_first(cpu_present_mask);
12991 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
12992
James Smart6a828b02019-01-28 11:14:31 -080012993 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080012994 eqhdl = lpfc_get_eq_hdl(index);
12995 eqhdl->idx = index;
James Smartda0436e2009-05-22 14:51:39 -040012996 }
12997
James Smart75baf692010-06-08 18:31:21 -040012998 return 0;
James Smartda0436e2009-05-22 14:51:39 -040012999}
13000
13001/**
James Smartda0436e2009-05-22 14:51:39 -040013002 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
13003 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010013004 * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
James Smartda0436e2009-05-22 14:51:39 -040013005 *
13006 * This routine is invoked to enable device interrupt and associate driver's
13007 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
13008 * interface spec. Depends on the interrupt mode configured to the driver,
13009 * the driver will try to fallback from the configured interrupt mode to an
13010 * interrupt mode which is supported by the platform, kernel, and device in
13011 * the order of:
13012 * MSI-X -> MSI -> IRQ.
13013 *
13014 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020013015 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040013016 * other values - error
13017 **/
13018static uint32_t
13019lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
13020{
13021 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080013022 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040013023
13024 if (cfg_mode == 2) {
13025 /* Preparation before conf_msi mbox cmd */
13026 retval = 0;
13027 if (!retval) {
13028 /* Now, try to enable MSI-X interrupt mode */
13029 retval = lpfc_sli4_enable_msix(phba);
13030 if (!retval) {
13031 /* Indicate initialization to MSI-X mode */
13032 phba->intr_type = MSIX;
13033 intr_mode = 2;
13034 }
13035 }
13036 }
13037
13038 /* Fallback to MSI if MSI-X initialization failed */
13039 if (cfg_mode >= 1 && phba->intr_type == NONE) {
13040 retval = lpfc_sli4_enable_msi(phba);
13041 if (!retval) {
13042 /* Indicate initialization to MSI mode */
13043 phba->intr_type = MSI;
13044 intr_mode = 1;
13045 }
13046 }
13047
13048 /* Fallback to INTx if both MSI-X/MSI initalization failed */
13049 if (phba->intr_type == NONE) {
13050 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
13051 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
13052 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080013053 struct lpfc_hba_eq_hdl *eqhdl;
James Smartdcaa2132019-11-04 16:57:06 -080013054 unsigned int cpu;
James Smart895427b2017-02-12 13:52:30 -080013055
James Smartda0436e2009-05-22 14:51:39 -040013056 /* Indicate initialization to INTx mode */
13057 phba->intr_type = INTx;
13058 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080013059
James Smartdcaa2132019-11-04 16:57:06 -080013060 eqhdl = lpfc_get_eq_hdl(0);
13061 eqhdl->irq = pci_irq_vector(phba->pcidev, 0);
13062
13063 cpu = cpumask_first(cpu_present_mask);
13064 lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
13065 cpu);
James Smart6a828b02019-01-28 11:14:31 -080013066 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smartdcaa2132019-11-04 16:57:06 -080013067 eqhdl = lpfc_get_eq_hdl(idx);
James Smart895427b2017-02-12 13:52:30 -080013068 eqhdl->idx = idx;
James Smart1ba981f2014-02-20 09:56:45 -050013069 }
James Smartda0436e2009-05-22 14:51:39 -040013070 }
13071 }
13072 return intr_mode;
13073}
13074
13075/**
13076 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
13077 * @phba: pointer to lpfc hba data structure.
13078 *
13079 * This routine is invoked to disable device interrupt and disassociate
13080 * the driver's interrupt handler(s) from interrupt vector(s) to device
13081 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
13082 * will release the interrupt vector(s) for the message signaled interrupt.
13083 **/
13084static void
13085lpfc_sli4_disable_intr(struct lpfc_hba *phba)
13086{
13087 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080013088 if (phba->intr_type == MSIX) {
13089 int index;
James Smartdcaa2132019-11-04 16:57:06 -080013090 struct lpfc_hba_eq_hdl *eqhdl;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080013091
13092 /* Free up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080013093 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartdcaa2132019-11-04 16:57:06 -080013094 eqhdl = lpfc_get_eq_hdl(index);
13095 lpfc_irq_clear_aff(eqhdl);
13096 irq_set_affinity_hint(eqhdl->irq, NULL);
13097 free_irq(eqhdl->irq, eqhdl);
James Smartb3295c22019-01-28 11:14:30 -080013098 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080013099 } else {
James Smartda0436e2009-05-22 14:51:39 -040013100 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080013101 }
13102
13103 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040013104
13105 /* Reset interrupt management states */
13106 phba->intr_type = NONE;
13107 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040013108}
13109
13110/**
James Smart3772a992009-05-22 14:50:54 -040013111 * lpfc_unset_hba - Unset SLI3 hba device initialization
13112 * @phba: pointer to lpfc hba data structure.
13113 *
13114 * This routine is invoked to unset the HBA device initialization steps to
13115 * a device with SLI-3 interface spec.
13116 **/
13117static void
13118lpfc_unset_hba(struct lpfc_hba *phba)
13119{
13120 struct lpfc_vport *vport = phba->pport;
13121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
13122
13123 spin_lock_irq(shost->host_lock);
13124 vport->load_flag |= FC_UNLOADING;
13125 spin_unlock_irq(shost->host_lock);
13126
James Smart72859902012-01-18 16:25:38 -050013127 kfree(phba->vpi_bmask);
13128 kfree(phba->vpi_ids);
13129
James Smart3772a992009-05-22 14:50:54 -040013130 lpfc_stop_hba_timers(phba);
13131
13132 phba->pport->work_port_events = 0;
13133
13134 lpfc_sli_hba_down(phba);
13135
13136 lpfc_sli_brdrestart(phba);
13137
13138 lpfc_sli_disable_intr(phba);
13139
13140 return;
13141}
13142
13143/**
James Smart5af5eee2010-10-22 11:06:38 -040013144 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
13145 * @phba: Pointer to HBA context object.
13146 *
13147 * This function is called in the SLI4 code path to wait for completion
13148 * of device's XRIs exchange busy. It will check the XRI exchange busy
13149 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
13150 * that, it will check the XRI exchange busy on outstanding FCP and ELS
13151 * I/Os every 30 seconds, log error message, and wait forever. Only when
13152 * all XRI exchange busy complete, the driver unload shall proceed with
13153 * invoking the function reset ioctl mailbox command to the CNA and the
13154 * the rest of the driver unload resource release.
13155 **/
13156static void
13157lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
13158{
James Smart5e5b5112019-01-28 11:14:22 -080013159 struct lpfc_sli4_hdw_queue *qp;
James Smartc00f62e2019-08-14 16:57:11 -070013160 int idx, ccnt;
James Smart5af5eee2010-10-22 11:06:38 -040013161 int wait_time = 0;
James Smart5e5b5112019-01-28 11:14:22 -080013162 int io_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070013163 int nvmet_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040013164 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
13165
James Smartc3725bd2017-11-20 16:00:42 -080013166 /* Driver just aborted IOs during the hba_unset process. Pause
13167 * here to give the HBA time to complete the IO and get entries
13168 * into the abts lists.
13169 */
13170 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
13171
13172 /* Wait for NVME pending IO to flush back to transport. */
13173 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
13174 lpfc_nvme_wait_for_io_drain(phba);
13175
James Smart5e5b5112019-01-28 11:14:22 -080013176 ccnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -080013177 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13178 qp = &phba->sli4_hba.hdwq[idx];
James Smartc00f62e2019-08-14 16:57:11 -070013179 io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
13180 if (!io_xri_cmpl) /* if list is NOT empty */
13181 ccnt++;
James Smart5e5b5112019-01-28 11:14:22 -080013182 }
13183 if (ccnt)
13184 io_xri_cmpl = 0;
James Smart5e5b5112019-01-28 11:14:22 -080013185
James Smart86c67372017-04-21 16:05:04 -070013186 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070013187 nvmet_xri_cmpl =
13188 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13189 }
James Smart895427b2017-02-12 13:52:30 -080013190
James Smartc00f62e2019-08-14 16:57:11 -070013191 while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040013192 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070013193 if (!nvmet_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070013194 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart68c9b552018-06-26 08:24:25 -070013195 "6424 NVMET XRI exchange busy "
13196 "wait time: %d seconds.\n",
13197 wait_time/1000);
James Smart5e5b5112019-01-28 11:14:22 -080013198 if (!io_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070013199 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartc00f62e2019-08-14 16:57:11 -070013200 "6100 IO XRI exchange busy "
James Smart5af5eee2010-10-22 11:06:38 -040013201 "wait time: %d seconds.\n",
13202 wait_time/1000);
13203 if (!els_xri_cmpl)
Dick Kennedy372c1872020-06-30 14:50:00 -070013204 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5af5eee2010-10-22 11:06:38 -040013205 "2878 ELS XRI exchange busy "
13206 "wait time: %d seconds.\n",
13207 wait_time/1000);
13208 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
13209 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
13210 } else {
13211 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
13212 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
13213 }
James Smart5e5b5112019-01-28 11:14:22 -080013214
13215 ccnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -080013216 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
13217 qp = &phba->sli4_hba.hdwq[idx];
James Smartc00f62e2019-08-14 16:57:11 -070013218 io_xri_cmpl = list_empty(
13219 &qp->lpfc_abts_io_buf_list);
13220 if (!io_xri_cmpl) /* if list is NOT empty */
13221 ccnt++;
James Smart5e5b5112019-01-28 11:14:22 -080013222 }
13223 if (ccnt)
13224 io_xri_cmpl = 0;
James Smart5e5b5112019-01-28 11:14:22 -080013225
James Smart86c67372017-04-21 16:05:04 -070013226 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070013227 nvmet_xri_cmpl = list_empty(
13228 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
13229 }
James Smart5af5eee2010-10-22 11:06:38 -040013230 els_xri_cmpl =
13231 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080013232
James Smart5af5eee2010-10-22 11:06:38 -040013233 }
13234}
13235
13236/**
James Smartda0436e2009-05-22 14:51:39 -040013237 * lpfc_sli4_hba_unset - Unset the fcoe hba
13238 * @phba: Pointer to HBA context object.
13239 *
13240 * This function is called in the SLI4 code path to reset the HBA's FCoE
13241 * function. The caller is not required to hold any lock. This routine
13242 * issues PCI function reset mailbox command to reset the FCoE function.
13243 * At the end of the function, it calls lpfc_hba_down_post function to
13244 * free any pending commands.
13245 **/
13246static void
13247lpfc_sli4_hba_unset(struct lpfc_hba *phba)
13248{
13249 int wait_cnt = 0;
13250 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040013251 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040013252
13253 lpfc_stop_hba_timers(phba);
James Smart02243832021-08-16 09:28:54 -070013254 hrtimer_cancel(&phba->cmf_timer);
13255
James Smartcdb42be2019-01-28 11:14:21 -080013256 if (phba->pport)
13257 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -040013258
13259 /*
13260 * Gracefully wait out the potential current outstanding asynchronous
13261 * mailbox command.
13262 */
13263
13264 /* First, block any pending async mailbox command from posted */
13265 spin_lock_irq(&phba->hbalock);
13266 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13267 spin_unlock_irq(&phba->hbalock);
13268 /* Now, trying to wait it out if we can */
13269 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13270 msleep(10);
13271 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
13272 break;
13273 }
13274 /* Forcefully release the outstanding mailbox command if timed out */
13275 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
13276 spin_lock_irq(&phba->hbalock);
13277 mboxq = phba->sli.mbox_active;
13278 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
13279 __lpfc_mbox_cmpl_put(phba, mboxq);
13280 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13281 phba->sli.mbox_active = NULL;
13282 spin_unlock_irq(&phba->hbalock);
13283 }
13284
James Smart5af5eee2010-10-22 11:06:38 -040013285 /* Abort all iocbs associated with the hba */
13286 lpfc_sli_hba_iocb_abort(phba);
13287
13288 /* Wait for completion of device XRI exchange busy */
13289 lpfc_sli4_xri_exchange_busy_wait(phba);
13290
James Smart93a4d6f2019-11-04 16:57:05 -080013291 /* per-phba callback de-registration for hotplug event */
SeongJae Park46da5472020-06-23 10:41:22 +020013292 if (phba->pport)
13293 lpfc_cpuhp_remove(phba);
James Smart93a4d6f2019-11-04 16:57:05 -080013294
James Smartda0436e2009-05-22 14:51:39 -040013295 /* Disable PCI subsystem interrupt */
13296 lpfc_sli4_disable_intr(phba);
13297
James Smart912e3ac2011-05-24 11:42:11 -040013298 /* Disable SR-IOV if enabled */
13299 if (phba->cfg_sriov_nr_virtfn)
13300 pci_disable_sriov(pdev);
13301
James Smartda0436e2009-05-22 14:51:39 -040013302 /* Stop kthread signal shall trigger work_done one more time */
13303 kthread_stop(phba->worker_thread);
13304
James Smartd2cc9bc2018-09-10 10:30:50 -070013305 /* Disable FW logging to host memory */
James Smart1165a5c2018-11-29 16:09:39 -080013306 lpfc_ras_stop_fwlog(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070013307
James Smartd1f525a2017-04-21 16:04:55 -070013308 /* Unset the queues shared with the hardware then release all
13309 * allocated resources.
13310 */
13311 lpfc_sli4_queue_unset(phba);
13312 lpfc_sli4_queue_destroy(phba);
13313
James Smart3677a3a2010-09-29 11:19:14 -040013314 /* Reset SLI4 HBA FCoE function */
13315 lpfc_pci_function_reset(phba);
13316
James Smart1165a5c2018-11-29 16:09:39 -080013317 /* Free RAS DMA memory */
13318 if (phba->ras_fwlog.ras_enabled)
13319 lpfc_sli4_ras_dma_free(phba);
13320
James Smartda0436e2009-05-22 14:51:39 -040013321 /* Stop the SLI4 device port */
James Smart1ffdd2c2019-03-04 15:27:51 -080013322 if (phba->pport)
13323 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -040013324}
13325
James Smart7481811c2021-08-16 09:28:56 -070013326static uint32_t
13327lpfc_cgn_crc32(uint32_t crc, u8 byte)
13328{
13329 uint32_t msb = 0;
13330 uint32_t bit;
13331
13332 for (bit = 0; bit < 8; bit++) {
13333 msb = (crc >> 31) & 1;
13334 crc <<= 1;
13335
13336 if (msb ^ (byte & 1)) {
13337 crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
13338 crc |= 1;
13339 }
13340 byte >>= 1;
13341 }
13342 return crc;
13343}
13344
13345static uint32_t
13346lpfc_cgn_reverse_bits(uint32_t wd)
13347{
13348 uint32_t result = 0;
13349 uint32_t i;
13350
13351 for (i = 0; i < 32; i++) {
13352 result <<= 1;
13353 result |= (1 & (wd >> i));
13354 }
13355 return result;
13356}
13357
13358/*
13359 * The routine corresponds with the algorithm the HBA firmware
13360 * uses to validate the data integrity.
13361 */
13362uint32_t
13363lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
13364{
13365 uint32_t i;
13366 uint32_t result;
13367 uint8_t *data = (uint8_t *)ptr;
13368
13369 for (i = 0; i < byteLen; ++i)
13370 crc = lpfc_cgn_crc32(crc, data[i]);
13371
13372 result = ~lpfc_cgn_reverse_bits(crc);
13373 return result;
13374}
13375
James Smart8c42a652021-08-16 09:28:51 -070013376void
13377lpfc_init_congestion_buf(struct lpfc_hba *phba)
13378{
James Smart7481811c2021-08-16 09:28:56 -070013379 struct lpfc_cgn_info *cp;
13380 struct timespec64 cmpl_time;
13381 struct tm broken;
13382 uint16_t size;
13383 uint32_t crc;
13384
James Smart8c42a652021-08-16 09:28:51 -070013385 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13386 "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
13387
13388 if (!phba->cgn_i)
13389 return;
James Smart7481811c2021-08-16 09:28:56 -070013390 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
James Smart8c42a652021-08-16 09:28:51 -070013391
13392 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
13393 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
13394 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
13395 atomic_set(&phba->cgn_sync_warn_cnt, 0);
13396
13397 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
13398 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
13399 atomic_set(&phba->cgn_driver_evt_cnt, 0);
13400 atomic_set(&phba->cgn_latency_evt_cnt, 0);
13401 atomic64_set(&phba->cgn_latency_evt, 0);
13402 phba->cgn_evt_minute = 0;
James Smart7481811c2021-08-16 09:28:56 -070013403 phba->hba_flag &= ~HBA_CGN_DAY_WRAP;
13404
13405 memset(cp, 0xff, LPFC_CGN_DATA_SIZE);
13406 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
13407 cp->cgn_info_version = LPFC_CGN_INFO_V3;
13408
13409 /* cgn parameters */
13410 cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
13411 cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
13412 cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
13413 cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
13414
13415 ktime_get_real_ts64(&cmpl_time);
13416 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13417
13418 cp->cgn_info_month = broken.tm_mon + 1;
13419 cp->cgn_info_day = broken.tm_mday;
13420 cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */
13421 cp->cgn_info_hour = broken.tm_hour;
13422 cp->cgn_info_minute = broken.tm_min;
13423 cp->cgn_info_second = broken.tm_sec;
13424
13425 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13426 "2643 CGNInfo Init: Start Time "
13427 "%d/%d/%d %d:%d:%d\n",
13428 cp->cgn_info_day, cp->cgn_info_month,
13429 cp->cgn_info_year, cp->cgn_info_hour,
13430 cp->cgn_info_minute, cp->cgn_info_second);
13431
13432 /* Fill in default LUN qdepth */
13433 if (phba->pport) {
13434 size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
13435 cp->cgn_lunq = cpu_to_le16(size);
13436 }
13437
13438 /* last used Index initialized to 0xff already */
13439
13440 cp->cgn_warn_freq = LPFC_FPIN_INIT_FREQ;
13441 cp->cgn_alarm_freq = LPFC_FPIN_INIT_FREQ;
13442 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13443 cp->cgn_info_crc = cpu_to_le32(crc);
James Smart8c42a652021-08-16 09:28:51 -070013444
13445 phba->cgn_evt_timestamp = jiffies +
13446 msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
13447}
13448
13449void
13450lpfc_init_congestion_stat(struct lpfc_hba *phba)
13451{
James Smart7481811c2021-08-16 09:28:56 -070013452 struct lpfc_cgn_info *cp;
13453 struct timespec64 cmpl_time;
13454 struct tm broken;
13455 uint32_t crc;
13456
James Smart8c42a652021-08-16 09:28:51 -070013457 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
13458 "6236 INIT Congestion Stat %p\n", phba->cgn_i);
13459
13460 if (!phba->cgn_i)
13461 return;
James Smart7481811c2021-08-16 09:28:56 -070013462
13463 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
13464 memset(&cp->cgn_stat_npm, 0, LPFC_CGN_STAT_SIZE);
13465
13466 ktime_get_real_ts64(&cmpl_time);
13467 time64_to_tm(cmpl_time.tv_sec, 0, &broken);
13468
13469 cp->cgn_stat_month = broken.tm_mon + 1;
13470 cp->cgn_stat_day = broken.tm_mday;
13471 cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */
13472 cp->cgn_stat_hour = broken.tm_hour;
13473 cp->cgn_stat_minute = broken.tm_min;
13474
13475 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
13476 "2647 CGNstat Init: Start Time "
13477 "%d/%d/%d %d:%d\n",
13478 cp->cgn_stat_day, cp->cgn_stat_month,
13479 cp->cgn_stat_year, cp->cgn_stat_hour,
13480 cp->cgn_stat_minute);
13481
13482 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
13483 cp->cgn_info_crc = cpu_to_le32(crc);
James Smart8c42a652021-08-16 09:28:51 -070013484}
13485
13486/**
13487 * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
13488 * @phba: Pointer to hba context object.
13489 * @reg: flag to determine register or unregister.
13490 */
13491static int
13492__lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
13493{
13494 struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
13495 union lpfc_sli4_cfg_shdr *shdr;
13496 uint32_t shdr_status, shdr_add_status;
13497 LPFC_MBOXQ_t *mboxq;
13498 int length, rc;
13499
13500 if (!phba->cgn_i)
13501 return -ENXIO;
13502
13503 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13504 if (!mboxq) {
13505 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13506 "2641 REG_CONGESTION_BUF mbox allocation fail: "
13507 "HBA state x%x reg %d\n",
13508 phba->pport->port_state, reg);
13509 return -ENOMEM;
13510 }
13511
13512 length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
13513 sizeof(struct lpfc_sli4_cfg_mhdr));
13514 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13515 LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
13516 LPFC_SLI4_MBX_EMBED);
13517 reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
13518 bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
13519 if (reg > 0)
13520 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
13521 else
13522 bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
13523 reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
13524 reg_congestion_buf->addr_lo =
13525 putPaddrLow(phba->cgn_i->phys);
13526 reg_congestion_buf->addr_hi =
13527 putPaddrHigh(phba->cgn_i->phys);
13528
13529 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
13530 shdr = (union lpfc_sli4_cfg_shdr *)
13531 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
13532 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13533 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
13534 &shdr->response);
13535 mempool_free(mboxq, phba->mbox_mem_pool);
13536 if (shdr_status || shdr_add_status || rc) {
13537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13538 "2642 REG_CONGESTION_BUF mailbox "
13539 "failed with status x%x add_status x%x,"
13540 " mbx status x%x reg %d\n",
13541 shdr_status, shdr_add_status, rc, reg);
13542 return -ENXIO;
13543 }
13544 return 0;
13545}
13546
James Smart02243832021-08-16 09:28:54 -070013547int
James Smart8c42a652021-08-16 09:28:51 -070013548lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
13549{
James Smart02243832021-08-16 09:28:54 -070013550 lpfc_cmf_stop(phba);
James Smart8c42a652021-08-16 09:28:51 -070013551 return __lpfc_reg_congestion_buf(phba, 0);
13552}
13553
13554int
13555lpfc_reg_congestion_buf(struct lpfc_hba *phba)
13556{
13557 return __lpfc_reg_congestion_buf(phba, 1);
13558}
13559
James Smartda0436e2009-05-22 14:51:39 -040013560/**
James Smartfedd3b72011-02-16 12:39:24 -050013561 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
13562 * @phba: Pointer to HBA context object.
13563 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
13564 *
13565 * This function is called in the SLI4 code path to read the port's
13566 * sli4 capabilities.
13567 *
13568 * This function may be be called from any context that can block-wait
13569 * for the completion. The expectation is that this routine is called
13570 * typically from probe_one or from the online routine.
13571 **/
13572int
13573lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
13574{
13575 int rc;
13576 struct lpfc_mqe *mqe = &mboxq->u.mqe;
13577 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040013578 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050013579 int length;
James Smartbf316c72018-04-09 14:24:28 -070013580 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050013581 struct lpfc_sli4_parameters *mbx_sli4_parameters;
13582
James Smart6d368e52011-05-24 11:44:12 -040013583 /*
13584 * By default, the driver assumes the SLI4 port requires RPI
13585 * header postings. The SLI4_PARAM response will correct this
13586 * assumption.
13587 */
13588 phba->sli4_hba.rpi_hdrs_in_use = 1;
13589
James Smartfedd3b72011-02-16 12:39:24 -050013590 /* Read the port's SLI4 Config Parameters */
13591 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
13592 sizeof(struct lpfc_sli4_cfg_mhdr));
13593 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
13594 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
13595 length, LPFC_SLI4_MBX_EMBED);
13596 if (!phba->sli4_hba.intr_enable)
13597 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040013598 else {
13599 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
13600 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
13601 }
James Smartfedd3b72011-02-16 12:39:24 -050013602 if (unlikely(rc))
13603 return rc;
13604 sli4_params = &phba->sli4_hba.pc_sli4_params;
13605 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
13606 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
13607 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
13608 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
13609 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
13610 mbx_sli4_parameters);
13611 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
13612 mbx_sli4_parameters);
13613 if (bf_get(cfg_phwq, mbx_sli4_parameters))
13614 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
13615 else
13616 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
13617 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
James Smartb62232b2021-04-11 18:31:22 -070013618 sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
13619 mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050013620 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050013621 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
13622 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
13623 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
13624 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080013625 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
13626 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040013627 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070013628 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smart83c6cb12019-10-18 14:18:30 -070013629 sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050013630 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
13631 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080013632 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050013633 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
13634 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040013635 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
13636 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080013637
James Smartd79c9e92019-08-14 16:57:09 -070013638 /* Check for Extended Pre-Registered SGL support */
13639 phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
13640
James Smartc15e0702019-05-21 17:49:02 -070013641 /* Check for firmware nvme support */
13642 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
13643 bf_get(cfg_xib, mbx_sli4_parameters));
James Smart895427b2017-02-12 13:52:30 -080013644
James Smartc15e0702019-05-21 17:49:02 -070013645 if (rc) {
13646 /* Save this to indicate the Firmware supports NVME */
13647 sli4_params->nvme = 1;
13648
13649 /* Firmware NVME support, check driver FC4 NVME support */
13650 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
13651 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
13652 "6133 Disabling NVME support: "
13653 "FC4 type not supported: x%x\n",
13654 phba->cfg_enable_fc4_type);
13655 goto fcponly;
13656 }
13657 } else {
13658 /* No firmware NVME support, check driver FC4 NVME support */
13659 sli4_params->nvme = 0;
13660 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
13662 "6101 Disabling NVME support: Not "
13663 "supported by firmware (%d %d) x%x\n",
13664 bf_get(cfg_nvme, mbx_sli4_parameters),
13665 bf_get(cfg_xib, mbx_sli4_parameters),
13666 phba->cfg_enable_fc4_type);
13667fcponly:
James Smartc15e0702019-05-21 17:49:02 -070013668 phba->nvmet_support = 0;
13669 phba->cfg_nvmet_mrq = 0;
James Smart6a224b42019-08-14 16:56:57 -070013670 phba->cfg_nvme_seg_cnt = 0;
James Smartc15e0702019-05-21 17:49:02 -070013671
13672 /* If no FC4 type support, move to just SCSI support */
13673 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
13674 return -ENODEV;
13675 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
13676 }
James Smart895427b2017-02-12 13:52:30 -080013677 }
James Smart05580562011-05-24 11:40:48 -040013678
James Smartc26c2652019-08-14 16:56:49 -070013679 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
James Smarta5f73372019-09-21 20:58:50 -070013680 * accommodate 512K and 1M IOs in a single nvme buf.
James Smartc26c2652019-08-14 16:56:49 -070013681 */
James Smarta5f73372019-09-21 20:58:50 -070013682 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
James Smartc26c2652019-08-14 16:56:49 -070013683 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
James Smartc26c2652019-08-14 16:56:49 -070013684
James Smart137ddf02021-07-07 11:43:44 -070013685 /* Enable embedded Payload BDE if support is indicated */
13686 if (bf_get(cfg_pbde, mbx_sli4_parameters))
13687 phba->cfg_enable_pbde = 1;
13688 else
James Smart414abe02018-06-26 08:24:26 -070013689 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080013690
James Smart20aefac2018-01-30 15:58:58 -080013691 /*
13692 * To support Suppress Response feature we must satisfy 3 conditions.
13693 * lpfc_suppress_rsp module parameter must be set (default).
13694 * In SLI4-Parameters Descriptor:
13695 * Extended Inline Buffers (XIB) must be supported.
13696 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
13697 * (double negative).
13698 */
13699 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
13700 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080013701 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080013702 else
13703 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080013704
James Smart0cf07f842017-06-01 21:07:10 -070013705 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
13706 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
13707
James Smart05580562011-05-24 11:40:48 -040013708 /* Make sure that sge_supp_len can be handled by the driver */
13709 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
13710 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
13711
James Smartb5c53952016-03-31 14:12:30 -070013712 /*
James Smartc176ffa2018-01-30 15:58:46 -080013713 * Check whether the adapter supports an embedded copy of the
13714 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
13715 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070013716 */
13717 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
13718 phba->fcp_embed_io = 1;
13719 else
13720 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070013721
James Smart0bc2b7c2018-02-22 08:18:48 -080013722 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070013723 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080013724 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070013725 phba->cfg_enable_pbde,
James Smartae463b62021-07-07 11:43:32 -070013726 phba->fcp_embed_io, sli4_params->nvme,
James Smart4e565cf2018-02-22 08:18:50 -080013727 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080013728
James Smartbf316c72018-04-09 14:24:28 -070013729 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
13730 LPFC_SLI_INTF_IF_TYPE_2) &&
13731 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070013732 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070013733 exp_wqcq_pages = false;
13734
James Smartc176ffa2018-01-30 15:58:46 -080013735 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
13736 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070013737 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080013738 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
13739 phba->enab_exp_wqcq_pages = 1;
13740 else
13741 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070013742 /*
13743 * Check if the SLI port supports MDS Diagnostics
13744 */
13745 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
13746 phba->mds_diags_support = 1;
13747 else
13748 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070013749
James Smart0d8af092019-08-14 16:57:10 -070013750 /*
13751 * Check if the SLI port supports NSLER
13752 */
13753 if (bf_get(cfg_nsler, mbx_sli4_parameters))
13754 phba->nsler = 1;
13755 else
13756 phba->nsler = 0;
13757
James Smartfedd3b72011-02-16 12:39:24 -050013758 return 0;
13759}
13760
13761/**
James Smart3772a992009-05-22 14:50:54 -040013762 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
13763 * @pdev: pointer to PCI device
13764 * @pid: pointer to PCI device identifier
13765 *
13766 * This routine is to be called to attach a device with SLI-3 interface spec
13767 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13768 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
13769 * information of the device and driver to see if the driver state that it can
13770 * support this kind of device. If the match is successful, the driver core
13771 * invokes this routine. If this routine determines it can claim the HBA, it
13772 * does all the initialization that it needs to do to handle the HBA properly.
13773 *
13774 * Return code
13775 * 0 - driver can claim the device
13776 * negative value - driver can not claim the device
13777 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013778static int
James Smart3772a992009-05-22 14:50:54 -040013779lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
13780{
13781 struct lpfc_hba *phba;
13782 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040013783 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040013784 int error;
13785 uint32_t cfg_mode, intr_mode;
13786
13787 /* Allocate memory for HBA structure */
13788 phba = lpfc_hba_alloc(pdev);
13789 if (!phba)
13790 return -ENOMEM;
13791
13792 /* Perform generic PCI device enabling operation */
13793 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040013794 if (error)
James Smart3772a992009-05-22 14:50:54 -040013795 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040013796
13797 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
13798 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
13799 if (error)
13800 goto out_disable_pci_dev;
13801
13802 /* Set up SLI-3 specific device PCI memory space */
13803 error = lpfc_sli_pci_mem_setup(phba);
13804 if (error) {
13805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13806 "1402 Failed to set up pci memory space.\n");
13807 goto out_disable_pci_dev;
13808 }
13809
James Smart3772a992009-05-22 14:50:54 -040013810 /* Set up SLI-3 specific device driver resources */
13811 error = lpfc_sli_driver_resource_setup(phba);
13812 if (error) {
13813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13814 "1404 Failed to set up driver resource.\n");
13815 goto out_unset_pci_mem_s3;
13816 }
13817
13818 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070013819
James Smart3772a992009-05-22 14:50:54 -040013820 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
13821 if (error) {
13822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13823 "1405 Failed to initialize iocb list.\n");
13824 goto out_unset_driver_resource_s3;
13825 }
13826
13827 /* Set up common device driver resources */
13828 error = lpfc_setup_driver_resource_phase2(phba);
13829 if (error) {
13830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13831 "1406 Failed to set up driver resource.\n");
13832 goto out_free_iocb_list;
13833 }
13834
James Smart079b5c92011-08-21 21:48:49 -040013835 /* Get the default values for Model Name and Description */
13836 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
13837
James Smart3772a992009-05-22 14:50:54 -040013838 /* Create SCSI host to the physical port */
13839 error = lpfc_create_shost(phba);
13840 if (error) {
13841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13842 "1407 Failed to create scsi host.\n");
13843 goto out_unset_driver_resource;
13844 }
13845
13846 /* Configure sysfs attributes */
13847 vport = phba->pport;
13848 error = lpfc_alloc_sysfs_attr(vport);
13849 if (error) {
13850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13851 "1476 Failed to allocate sysfs attr\n");
13852 goto out_destroy_shost;
13853 }
13854
James Smart6669f9b2009-10-02 15:16:45 -040013855 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040013856 /* Now, trying to enable interrupt and bring up the device */
13857 cfg_mode = phba->cfg_use_msi;
13858 while (true) {
13859 /* Put device to a known state before enabling interrupt */
13860 lpfc_stop_port(phba);
13861 /* Configure and enable interrupt */
13862 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
13863 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013864 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013865 "0431 Failed to enable interrupt.\n");
13866 error = -ENODEV;
13867 goto out_free_sysfs_attr;
13868 }
13869 /* SLI-3 HBA setup */
13870 if (lpfc_sli_hba_setup(phba)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070013871 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040013872 "1477 Failed to set up hba\n");
13873 error = -ENODEV;
13874 goto out_remove_device;
13875 }
13876
13877 /* Wait 50ms for the interrupts of previous mailbox commands */
13878 msleep(50);
13879 /* Check active interrupts on message signaled interrupts */
13880 if (intr_mode == 0 ||
13881 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
13882 /* Log the current active interrupt mode */
13883 phba->intr_mode = intr_mode;
13884 lpfc_log_intr_mode(phba, intr_mode);
13885 break;
13886 } else {
13887 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
13888 "0447 Configure interrupt mode (%d) "
13889 "failed active interrupt test.\n",
13890 intr_mode);
13891 /* Disable the current interrupt mode */
13892 lpfc_sli_disable_intr(phba);
13893 /* Try next level of interrupt mode */
13894 cfg_mode = --intr_mode;
13895 }
13896 }
13897
13898 /* Perform post initialization setup */
13899 lpfc_post_init_setup(phba);
13900
13901 /* Check if there are static vports to be created. */
13902 lpfc_create_static_vport(phba);
13903
13904 return 0;
13905
13906out_remove_device:
13907 lpfc_unset_hba(phba);
13908out_free_sysfs_attr:
13909 lpfc_free_sysfs_attr(vport);
13910out_destroy_shost:
13911 lpfc_destroy_shost(phba);
13912out_unset_driver_resource:
13913 lpfc_unset_driver_resource_phase2(phba);
13914out_free_iocb_list:
13915 lpfc_free_iocb_list(phba);
13916out_unset_driver_resource_s3:
13917 lpfc_sli_driver_resource_unset(phba);
13918out_unset_pci_mem_s3:
13919 lpfc_sli_pci_mem_unset(phba);
13920out_disable_pci_dev:
13921 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040013922 if (shost)
13923 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040013924out_free_phba:
13925 lpfc_hba_free(phba);
13926 return error;
13927}
13928
13929/**
13930 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040013931 * @pdev: pointer to PCI device
13932 *
James Smart3772a992009-05-22 14:50:54 -040013933 * This routine is to be called to disattach a device with SLI-3 interface
13934 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
13935 * removed from PCI bus, it performs all the necessary cleanup for the HBA
13936 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040013937 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013938static void
James Smart3772a992009-05-22 14:50:54 -040013939lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050013940{
James Smart2e0fef82007-06-17 19:56:36 -050013941 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13942 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050013943 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050013944 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050013945 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050013946
James Smart549e55c2007-08-02 11:09:51 -040013947 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040013948 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040013949 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050013950
James Smart858c9f62007-06-17 19:56:39 -050013951 lpfc_free_sysfs_attr(vport);
13952
James Smarteada2722008-12-04 22:39:13 -050013953 /* Release all the vports against this physical port */
13954 vports = lpfc_create_vport_work_array(phba);
13955 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040013956 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
13957 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
13958 continue;
James Smarteada2722008-12-04 22:39:13 -050013959 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040013960 }
James Smarteada2722008-12-04 22:39:13 -050013961 lpfc_destroy_vport_work_array(phba, vports);
13962
James Smart95f0ef82020-11-15 11:26:32 -080013963 /* Remove FC host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050013964 fc_remove_host(shost);
James Smarte9b11082020-11-15 11:26:33 -080013965 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080013966
James Smart95f0ef82020-11-15 11:26:32 -080013967 /* Clean up all nodes, mailboxes and IOs. */
James Smart87af33f2007-10-27 13:37:43 -040013968 lpfc_cleanup(vport);
13969
James Smart2e0fef82007-06-17 19:56:36 -050013970 /*
13971 * Bring down the SLI Layer. This step disable all interrupts,
13972 * clears the rings, discards all mailbox commands, and resets
13973 * the HBA.
13974 */
James Smarta257bf92009-04-06 18:48:10 -040013975
Justin P. Mattock48e34d02010-12-30 15:07:58 -080013976 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050013977 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040013978 /* Stop kthread signal shall trigger work_done one more time */
13979 kthread_stop(phba->worker_thread);
13980 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050013981 lpfc_sli_brdrestart(phba);
13982
James Smart72859902012-01-18 16:25:38 -050013983 kfree(phba->vpi_bmask);
13984 kfree(phba->vpi_ids);
13985
James Smart3772a992009-05-22 14:50:54 -040013986 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070013987 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050013988 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070013989 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050013990
James Smart858c9f62007-06-17 19:56:39 -050013991 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050013992
James Smart912e3ac2011-05-24 11:42:11 -040013993 /* Disable SR-IOV if enabled */
13994 if (phba->cfg_sriov_nr_virtfn)
13995 pci_disable_sriov(pdev);
13996
James Smart5b75da22008-12-04 22:39:35 -050013997 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040013998 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050013999
James Smart858c9f62007-06-17 19:56:39 -050014000 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050014001
14002 /*
14003 * Call scsi_free before mem_free since scsi bufs are released to their
14004 * corresponding pools here.
14005 */
14006 lpfc_scsi_free(phba);
James Smart0794d602019-01-28 11:14:19 -080014007 lpfc_free_iocb_list(phba);
14008
James Smart3772a992009-05-22 14:50:54 -040014009 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050014010
James Smart34b02dc2008-08-24 21:49:55 -040014011 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
14012 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050014013
James Smart2e0fef82007-06-17 19:56:36 -050014014 /* Free resources associated with SLI2 interface */
14015 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040014016 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050014017
14018 /* unmap adapter SLIM and Control Registers */
14019 iounmap(phba->ctrl_regs_memmap_p);
14020 iounmap(phba->slim_memmap_p);
14021
James Smart3772a992009-05-22 14:50:54 -040014022 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050014023
Johannes Thumshirne0c04832016-06-07 09:44:03 +020014024 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050014025 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050014026}
14027
Linas Vepstas8d63f372007-02-14 14:28:36 -060014028/**
James Smart3772a992009-05-22 14:50:54 -040014029 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014030 * @dev_d: pointer to device
James Smart3a55b532008-12-04 22:38:54 -050014031 *
James Smart3772a992009-05-22 14:50:54 -040014032 * This routine is to be called from the kernel's PCI subsystem to support
14033 * system Power Management (PM) to device with SLI-3 interface spec. When
14034 * PM invokes this method, it quiesces the device by stopping the driver's
14035 * worker thread for the device, turning off device's interrupt and DMA,
14036 * and bring the device offline. Note that as the driver implements the
14037 * minimum PM requirements to a power-aware driver's PM support for the
14038 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14039 * to the suspend() method call will be treated as SUSPEND and the driver will
14040 * fully reinitialize its device during resume() method call, the driver will
14041 * set device to PCI_D3hot state in PCI config space instead of setting it
14042 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050014043 *
14044 * Return code
James Smart3772a992009-05-22 14:50:54 -040014045 * 0 - driver suspended the device
14046 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050014047 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014048static int __maybe_unused
14049lpfc_pci_suspend_one_s3(struct device *dev_d)
James Smart3a55b532008-12-04 22:38:54 -050014050{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014051 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smart3a55b532008-12-04 22:38:54 -050014052 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14053
14054 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14055 "0473 PCI device Power Management suspend.\n");
14056
14057 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040014058 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050014059 lpfc_offline(phba);
14060 kthread_stop(phba->worker_thread);
14061
14062 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040014063 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050014064
James Smart3a55b532008-12-04 22:38:54 -050014065 return 0;
14066}
14067
14068/**
James Smart3772a992009-05-22 14:50:54 -040014069 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014070 * @dev_d: pointer to device
James Smart3a55b532008-12-04 22:38:54 -050014071 *
James Smart3772a992009-05-22 14:50:54 -040014072 * This routine is to be called from the kernel's PCI subsystem to support
14073 * system Power Management (PM) to device with SLI-3 interface spec. When PM
14074 * invokes this method, it restores the device's PCI config space state and
14075 * fully reinitializes the device and brings it online. Note that as the
14076 * driver implements the minimum PM requirements to a power-aware driver's
14077 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
14078 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
14079 * driver will fully reinitialize its device during resume() method call,
14080 * the device will be set to PCI_D0 directly in PCI config space before
14081 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050014082 *
14083 * Return code
James Smart3772a992009-05-22 14:50:54 -040014084 * 0 - driver suspended the device
14085 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050014086 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014087static int __maybe_unused
14088lpfc_pci_resume_one_s3(struct device *dev_d)
James Smart3a55b532008-12-04 22:38:54 -050014089{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014090 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smart3a55b532008-12-04 22:38:54 -050014091 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050014092 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050014093 int error;
14094
14095 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14096 "0452 PCI device Power Management resume.\n");
14097
James Smart3a55b532008-12-04 22:38:54 -050014098 /* Startup the kernel thread for this host adapter. */
14099 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14100 "lpfc_worker_%d", phba->brd_no);
14101 if (IS_ERR(phba->worker_thread)) {
14102 error = PTR_ERR(phba->worker_thread);
14103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14104 "0434 PM resume failed to start worker "
14105 "thread: error=x%x.\n", error);
14106 return error;
14107 }
14108
James Smart25ac2c972021-09-10 16:31:54 -070014109 /* Init cpu_map array */
14110 lpfc_cpu_map_array_init(phba);
14111 /* Init hba_eq_hdl array */
14112 lpfc_hba_eq_hdl_array_init(phba);
James Smart5b75da22008-12-04 22:39:35 -050014113 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040014114 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050014115 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014116 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -050014117 "0430 PM resume Failed to enable interrupt\n");
14118 return -EIO;
14119 } else
14120 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050014121
14122 /* Restart HBA and bring it online */
14123 lpfc_sli_brdrestart(phba);
14124 lpfc_online(phba);
14125
James Smart5b75da22008-12-04 22:39:35 -050014126 /* Log the current active interrupt mode */
14127 lpfc_log_intr_mode(phba, phba->intr_mode);
14128
James Smart3a55b532008-12-04 22:38:54 -050014129 return 0;
14130}
14131
14132/**
James Smart891478a2009-11-18 15:40:23 -050014133 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
14134 * @phba: pointer to lpfc hba data structure.
14135 *
14136 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040014137 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050014138 **/
14139static void
14140lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
14141{
Dick Kennedy372c1872020-06-30 14:50:00 -070014142 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050014143 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040014144
14145 /*
14146 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14147 * and let the SCSI mid-layer to retry them to recover.
14148 */
James Smartdb55fba2014-04-04 13:52:02 -040014149 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050014150}
14151
14152/**
James Smart0d878412009-10-02 15:16:56 -040014153 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
14154 * @phba: pointer to lpfc hba data structure.
14155 *
14156 * This routine is called to prepare the SLI3 device for PCI slot reset. It
14157 * disables the device interrupt and pci device, and aborts the internal FCP
14158 * pending I/Os.
14159 **/
14160static void
14161lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
14162{
Dick Kennedy372c1872020-06-30 14:50:00 -070014163 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050014164 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040014165
James Smart75baf692010-06-08 18:31:21 -040014166 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040014167 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040014168
James Smarte2af0d22010-03-15 11:25:32 -040014169 /* Block all SCSI devices' I/Os on the host */
14170 lpfc_scsi_dev_block(phba);
14171
James Smartea714f32013-04-17 20:18:47 -040014172 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
James Smartc00f62e2019-08-14 16:57:11 -070014173 lpfc_sli_flush_io_rings(phba);
James Smartea714f32013-04-17 20:18:47 -040014174
James Smarte2af0d22010-03-15 11:25:32 -040014175 /* stop all timers */
14176 lpfc_stop_hba_timers(phba);
14177
James Smart0d878412009-10-02 15:16:56 -040014178 /* Disable interrupt and pci device */
14179 lpfc_sli_disable_intr(phba);
14180 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040014181}
14182
14183/**
14184 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
14185 * @phba: pointer to lpfc hba data structure.
14186 *
14187 * This routine is called to prepare the SLI3 device for PCI slot permanently
14188 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
14189 * pending I/Os.
14190 **/
14191static void
James Smart75baf692010-06-08 18:31:21 -040014192lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040014193{
Dick Kennedy372c1872020-06-30 14:50:00 -070014194 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart891478a2009-11-18 15:40:23 -050014195 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040014196 /* Block all SCSI devices' I/Os on the host */
14197 lpfc_scsi_dev_block(phba);
14198
14199 /* stop all timers */
14200 lpfc_stop_hba_timers(phba);
14201
James Smart0d878412009-10-02 15:16:56 -040014202 /* Clean up all driver's outstanding SCSI I/Os */
James Smartc00f62e2019-08-14 16:57:11 -070014203 lpfc_sli_flush_io_rings(phba);
James Smart0d878412009-10-02 15:16:56 -040014204}
14205
14206/**
James Smart3772a992009-05-22 14:50:54 -040014207 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040014208 * @pdev: pointer to PCI device.
14209 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060014210 *
James Smart3772a992009-05-22 14:50:54 -040014211 * This routine is called from the PCI subsystem for I/O error handling to
14212 * device with SLI-3 interface spec. This function is called by the PCI
14213 * subsystem after a PCI bus error affecting this device has been detected.
14214 * When this function is invoked, it will need to stop all the I/Os and
14215 * interrupt(s) to the device. Once that is done, it will return
14216 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
14217 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040014218 *
14219 * Return codes
James Smart0d878412009-10-02 15:16:56 -040014220 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040014221 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
14222 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040014223 **/
James Smart3772a992009-05-22 14:50:54 -040014224static pci_ers_result_t
14225lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060014226{
James Smart51ef4c22007-08-02 11:10:31 -040014227 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14228 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060014229
James Smart0d878412009-10-02 15:16:56 -040014230 switch (state) {
14231 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050014232 /* Non-fatal error, prepare for recovery */
14233 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040014234 return PCI_ERS_RESULT_CAN_RECOVER;
14235 case pci_channel_io_frozen:
14236 /* Fatal error, prepare for slot reset */
14237 lpfc_sli_prep_dev_for_reset(phba);
14238 return PCI_ERS_RESULT_NEED_RESET;
14239 case pci_channel_io_perm_failure:
14240 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040014241 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060014242 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040014243 default:
14244 /* Unknown state, prepare and request slot reset */
Dick Kennedy372c1872020-06-30 14:50:00 -070014245 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0d878412009-10-02 15:16:56 -040014246 "0472 Unknown PCI error state: x%x\n", state);
14247 lpfc_sli_prep_dev_for_reset(phba);
14248 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040014249 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060014250}
14251
14252/**
James Smart3772a992009-05-22 14:50:54 -040014253 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040014254 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060014255 *
James Smart3772a992009-05-22 14:50:54 -040014256 * This routine is called from the PCI subsystem for error handling to
14257 * device with SLI-3 interface spec. This is called after PCI bus has been
14258 * reset to restart the PCI card from scratch, as if from a cold-boot.
14259 * During the PCI subsystem error recovery, after driver returns
14260 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
14261 * recovery and then call this routine before calling the .resume method
14262 * to recover the device. This function will initialize the HBA device,
14263 * enable the interrupt, but it will just put the HBA to offline state
14264 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040014265 *
14266 * Return codes
James Smart3772a992009-05-22 14:50:54 -040014267 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
14268 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060014269 */
James Smart3772a992009-05-22 14:50:54 -040014270static pci_ers_result_t
14271lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060014272{
James Smart51ef4c22007-08-02 11:10:31 -040014273 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14274 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060014275 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050014276 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060014277
14278 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110014279 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060014280 printk(KERN_ERR "lpfc: Cannot re-enable "
14281 "PCI device after reset.\n");
14282 return PCI_ERS_RESULT_DISCONNECT;
14283 }
14284
James Smart97207482008-12-04 22:39:19 -050014285 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050014286
14287 /*
14288 * As the new kernel behavior of pci_restore_state() API call clears
14289 * device saved_state flag, need to save the restored state again.
14290 */
14291 pci_save_state(pdev);
14292
James Smart97207482008-12-04 22:39:19 -050014293 if (pdev->is_busmaster)
14294 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060014295
James Smart92d7f7b2007-06-17 19:56:38 -050014296 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040014297 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050014298 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060014299
James Smart5b75da22008-12-04 22:39:35 -050014300 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040014301 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050014302 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014303 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5b75da22008-12-04 22:39:35 -050014304 "0427 Cannot re-enable interrupt after "
14305 "slot reset.\n");
14306 return PCI_ERS_RESULT_DISCONNECT;
14307 } else
14308 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060014309
James Smart75baf692010-06-08 18:31:21 -040014310 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040014311 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060014312 lpfc_offline(phba);
14313 lpfc_sli_brdrestart(phba);
14314
James Smart5b75da22008-12-04 22:39:35 -050014315 /* Log the current active interrupt mode */
14316 lpfc_log_intr_mode(phba, phba->intr_mode);
14317
Linas Vepstas8d63f372007-02-14 14:28:36 -060014318 return PCI_ERS_RESULT_RECOVERED;
14319}
14320
14321/**
James Smart3772a992009-05-22 14:50:54 -040014322 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040014323 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060014324 *
James Smart3772a992009-05-22 14:50:54 -040014325 * This routine is called from the PCI subsystem for error handling to device
14326 * with SLI-3 interface spec. It is called when kernel error recovery tells
14327 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
14328 * error recovery. After this call, traffic can start to flow from this device
14329 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060014330 */
James Smart3772a992009-05-22 14:50:54 -040014331static void
14332lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060014333{
James Smart51ef4c22007-08-02 11:10:31 -040014334 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14335 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060014336
James Smarte2af0d22010-03-15 11:25:32 -040014337 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040014338 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060014339}
14340
James Smart3772a992009-05-22 14:50:54 -040014341/**
James Smartda0436e2009-05-22 14:51:39 -040014342 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
14343 * @phba: pointer to lpfc hba data structure.
14344 *
14345 * returns the number of ELS/CT IOCBs to reserve
14346 **/
14347int
14348lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
14349{
14350 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
14351
James Smartf1126682009-06-10 17:22:44 -040014352 if (phba->sli_rev == LPFC_SLI_REV4) {
14353 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040014354 return 10;
James Smartf1126682009-06-10 17:22:44 -040014355 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040014356 return 25;
James Smartf1126682009-06-10 17:22:44 -040014357 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040014358 return 50;
James Smartf1126682009-06-10 17:22:44 -040014359 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040014360 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040014361 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040014362 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040014363 else if (max_xri <= 2048)
14364 return 200;
14365 else
14366 return 250;
James Smartf1126682009-06-10 17:22:44 -040014367 } else
14368 return 0;
James Smartda0436e2009-05-22 14:51:39 -040014369}
14370
14371/**
James Smart895427b2017-02-12 13:52:30 -080014372 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
14373 * @phba: pointer to lpfc hba data structure.
14374 *
James Smartf358dd02017-02-12 13:52:34 -080014375 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080014376 **/
14377int
14378lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
14379{
14380 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
14381
James Smartf358dd02017-02-12 13:52:34 -080014382 if (phba->nvmet_support)
14383 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080014384 return max_xri;
14385}
14386
14387
James Smart0a5ce732019-10-18 14:18:18 -070014388static int
James Smart1feb8202018-02-22 08:18:47 -080014389lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
14390 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
14391 const struct firmware *fw)
14392{
James Smart0a5ce732019-10-18 14:18:18 -070014393 int rc;
James Smartf6c5e6c2021-07-22 15:17:18 -070014394 u8 sli_family;
James Smart1feb8202018-02-22 08:18:47 -080014395
James Smartf6c5e6c2021-07-22 15:17:18 -070014396 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
James Smart0a5ce732019-10-18 14:18:18 -070014397 /* Three cases: (1) FW was not supported on the detected adapter.
14398 * (2) FW update has been locked out administratively.
14399 * (3) Some other error during FW update.
14400 * In each case, an unmaskable message is written to the console
14401 * for admin diagnosis.
14402 */
14403 if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
James Smartf6c5e6c2021-07-22 15:17:18 -070014404 (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
James Smart5792a0e2019-10-25 11:43:42 -070014405 magic_number != MAGIC_NUMBER_G6) ||
James Smartf6c5e6c2021-07-22 15:17:18 -070014406 (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
14407 magic_number != MAGIC_NUMBER_G7) ||
14408 (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
14409 magic_number != MAGIC_NUMBER_G7P)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014410 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070014411 "3030 This firmware version is not supported on"
14412 " this HBA model. Device:%x Magic:%x Type:%x "
14413 "ID:%x Size %d %zd\n",
14414 phba->pcidev->device, magic_number, ftype, fid,
14415 fsize, fw->size);
14416 rc = -EINVAL;
14417 } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014418 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070014419 "3021 Firmware downloads have been prohibited "
14420 "by a system configuration setting on "
14421 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14422 "%zd\n",
14423 phba->pcidev->device, magic_number, ftype, fid,
14424 fsize, fw->size);
14425 rc = -EACCES;
14426 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -070014427 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070014428 "3022 FW Download failed. Add Status x%x "
14429 "Device:%x Magic:%x Type:%x ID:%x Size %d "
14430 "%zd\n",
14431 offset, phba->pcidev->device, magic_number,
14432 ftype, fid, fsize, fw->size);
14433 rc = -EIO;
14434 }
14435 return rc;
James Smart1feb8202018-02-22 08:18:47 -080014436}
James Smart1feb8202018-02-22 08:18:47 -080014437
James Smart895427b2017-02-12 13:52:30 -080014438/**
James Smart52d52442011-05-24 11:42:45 -040014439 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040014440 * @fw: pointer to firmware image returned from request_firmware.
James Smart0a5ce732019-10-18 14:18:18 -070014441 * @context: pointer to firmware image returned from request_firmware.
James Smart52d52442011-05-24 11:42:45 -040014442 *
James Smart52d52442011-05-24 11:42:45 -040014443 **/
James Smartce396282012-09-29 11:30:56 -040014444static void
14445lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040014446{
James Smartce396282012-09-29 11:30:56 -040014447 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050014448 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040014449 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040014450 struct list_head dma_buffer_list;
14451 int i, rc = 0;
14452 struct lpfc_dmabuf *dmabuf, *next;
14453 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070014454 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040014455
James Smartc71ab862012-10-31 14:44:33 -040014456 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040014457 if (!fw) {
14458 rc = -ENXIO;
14459 goto out;
14460 }
14461 image = (struct lpfc_grp_hdr *)fw->data;
14462
James Smart6b6ef5d2016-10-13 15:06:17 -070014463 magic_number = be32_to_cpu(image->magic_number);
14464 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080014465 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070014466 fsize = be32_to_cpu(image->size);
14467
James Smart52d52442011-05-24 11:42:45 -040014468 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040014469 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040014470 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014471 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartce396282012-09-29 11:30:56 -040014472 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040014473 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040014474 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040014475 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
14476 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
14477 GFP_KERNEL);
14478 if (!dmabuf) {
14479 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040014480 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040014481 }
14482 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14483 SLI4_PAGE_SIZE,
14484 &dmabuf->phys,
14485 GFP_KERNEL);
14486 if (!dmabuf->virt) {
14487 kfree(dmabuf);
14488 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040014489 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040014490 }
14491 list_add_tail(&dmabuf->list, &dma_buffer_list);
14492 }
14493 while (offset < fw->size) {
14494 temp_offset = offset;
14495 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040014496 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040014497 memcpy(dmabuf->virt,
14498 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040014499 fw->size - temp_offset);
14500 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040014501 break;
14502 }
James Smart52d52442011-05-24 11:42:45 -040014503 memcpy(dmabuf->virt, fw->data + temp_offset,
14504 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040014505 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040014506 }
14507 rc = lpfc_wr_object(phba, &dma_buffer_list,
14508 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080014509 if (rc) {
James Smart0a5ce732019-10-18 14:18:18 -070014510 rc = lpfc_log_write_firmware_error(phba, offset,
14511 magic_number,
14512 ftype,
14513 fid,
14514 fsize,
14515 fw);
James Smartce396282012-09-29 11:30:56 -040014516 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080014517 }
James Smart52d52442011-05-24 11:42:45 -040014518 }
14519 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080014520 } else
Dick Kennedy372c1872020-06-30 14:50:00 -070014521 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart1feb8202018-02-22 08:18:47 -080014522 "3029 Skipped Firmware update, Current "
14523 "Version:%s New Version:%s\n",
14524 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040014525
14526release_out:
James Smart52d52442011-05-24 11:42:45 -040014527 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
14528 list_del(&dmabuf->list);
14529 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
14530 dmabuf->virt, dmabuf->phys);
14531 kfree(dmabuf);
14532 }
James Smartce396282012-09-29 11:30:56 -040014533 release_firmware(fw);
14534out:
James Smart0a5ce732019-10-18 14:18:18 -070014535 if (rc < 0)
Dick Kennedy372c1872020-06-30 14:50:00 -070014536 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070014537 "3062 Firmware update error, status %d.\n", rc);
14538 else
Dick Kennedy372c1872020-06-30 14:50:00 -070014539 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0a5ce732019-10-18 14:18:18 -070014540 "3024 Firmware update success: size %d.\n", rc);
James Smart52d52442011-05-24 11:42:45 -040014541}
14542
14543/**
James Smartc71ab862012-10-31 14:44:33 -040014544 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
14545 * @phba: pointer to lpfc hba data structure.
Lee Jonesfe614ac2020-07-23 13:24:22 +010014546 * @fw_upgrade: which firmware to update.
James Smartc71ab862012-10-31 14:44:33 -040014547 *
14548 * This routine is called to perform Linux generic firmware upgrade on device
14549 * that supports such feature.
14550 **/
14551int
14552lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
14553{
14554 uint8_t file_name[ELX_MODEL_NAME_SIZE];
14555 int ret;
14556 const struct firmware *fw;
14557
14558 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080014559 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040014560 LPFC_SLI_INTF_IF_TYPE_2)
14561 return -EPERM;
14562
14563 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
14564
14565 if (fw_upgrade == INT_FW_UPGRADE) {
Shawn Guo0733d832021-04-25 10:00:24 +080014566 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
James Smartc71ab862012-10-31 14:44:33 -040014567 file_name, &phba->pcidev->dev,
14568 GFP_KERNEL, (void *)phba,
14569 lpfc_write_firmware);
14570 } else if (fw_upgrade == RUN_FW_UPGRADE) {
14571 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
14572 if (!ret)
14573 lpfc_write_firmware(fw, (void *)phba);
14574 } else {
14575 ret = -EINVAL;
14576 }
14577
14578 return ret;
14579}
14580
14581/**
James Smartda0436e2009-05-22 14:51:39 -040014582 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
14583 * @pdev: pointer to PCI device
14584 * @pid: pointer to PCI device identifier
14585 *
14586 * This routine is called from the kernel's PCI subsystem to device with
14587 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14588 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
14589 * information of the device and driver to see if the driver state that it
14590 * can support this kind of device. If the match is successful, the driver
14591 * core invokes this routine. If this routine determines it can claim the HBA,
14592 * it does all the initialization that it needs to do to handle the HBA
14593 * properly.
14594 *
14595 * Return code
14596 * 0 - driver can claim the device
14597 * negative value - driver can not claim the device
14598 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080014599static int
James Smartda0436e2009-05-22 14:51:39 -040014600lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
14601{
14602 struct lpfc_hba *phba;
14603 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040014604 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070014605 int error;
James Smartda0436e2009-05-22 14:51:39 -040014606 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040014607
14608 /* Allocate memory for HBA structure */
14609 phba = lpfc_hba_alloc(pdev);
14610 if (!phba)
14611 return -ENOMEM;
14612
Ewan D. Milne9977d882021-08-09 11:09:47 -040014613 INIT_LIST_HEAD(&phba->poll_list);
14614
James Smartda0436e2009-05-22 14:51:39 -040014615 /* Perform generic PCI device enabling operation */
14616 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040014617 if (error)
James Smartda0436e2009-05-22 14:51:39 -040014618 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040014619
14620 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
14621 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
14622 if (error)
14623 goto out_disable_pci_dev;
14624
14625 /* Set up SLI-4 specific device PCI memory space */
14626 error = lpfc_sli4_pci_mem_setup(phba);
14627 if (error) {
14628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14629 "1410 Failed to set up pci memory space.\n");
14630 goto out_disable_pci_dev;
14631 }
14632
James Smartda0436e2009-05-22 14:51:39 -040014633 /* Set up SLI-4 Specific device driver resources */
14634 error = lpfc_sli4_driver_resource_setup(phba);
14635 if (error) {
14636 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14637 "1412 Failed to set up driver resource.\n");
14638 goto out_unset_pci_mem_s4;
14639 }
14640
James Smart19ca7602010-11-20 23:11:55 -050014641 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040014642 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050014643
James Smartda0436e2009-05-22 14:51:39 -040014644 /* Set up common device driver resources */
14645 error = lpfc_setup_driver_resource_phase2(phba);
14646 if (error) {
14647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14648 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070014649 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040014650 }
14651
James Smart079b5c92011-08-21 21:48:49 -040014652 /* Get the default values for Model Name and Description */
14653 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
14654
James Smartda0436e2009-05-22 14:51:39 -040014655 /* Now, trying to enable interrupt and bring up the device */
14656 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040014657
James Smart7b15db32013-01-03 15:43:29 -050014658 /* Put device to a known state before enabling interrupt */
James Smartcdb42be2019-01-28 11:14:21 -080014659 phba->pport = NULL;
James Smart7b15db32013-01-03 15:43:29 -050014660 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080014661
James Smartdcaa2132019-11-04 16:57:06 -080014662 /* Init cpu_map array */
14663 lpfc_cpu_map_array_init(phba);
14664
14665 /* Init hba_eq_hdl array */
14666 lpfc_hba_eq_hdl_array_init(phba);
14667
James Smart7b15db32013-01-03 15:43:29 -050014668 /* Configure and enable interrupt */
14669 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
14670 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014671 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7b15db32013-01-03 15:43:29 -050014672 "0426 Failed to enable interrupt.\n");
14673 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080014674 goto out_unset_driver_resource;
James Smartda0436e2009-05-22 14:51:39 -040014675 }
James Smart7b15db32013-01-03 15:43:29 -050014676 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080014677 if (phba->intr_type != MSIX) {
James Smart6a828b02019-01-28 11:14:31 -080014678 phba->cfg_irq_chann = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080014679 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -080014680 if (phba->nvmet_support)
14681 phba->cfg_nvmet_mrq = 1;
14682 }
James Smartcdb42be2019-01-28 11:14:21 -080014683 }
James Smart6a828b02019-01-28 11:14:31 -080014684 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
James Smartcdb42be2019-01-28 11:14:21 -080014685
14686 /* Create SCSI host to the physical port */
14687 error = lpfc_create_shost(phba);
14688 if (error) {
14689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14690 "1415 Failed to create scsi host.\n");
14691 goto out_disable_intr;
14692 }
14693 vport = phba->pport;
14694 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
14695
14696 /* Configure sysfs attributes */
14697 error = lpfc_alloc_sysfs_attr(vport);
14698 if (error) {
14699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14700 "1416 Failed to allocate sysfs attr\n");
14701 goto out_destroy_shost;
James Smart895427b2017-02-12 13:52:30 -080014702 }
14703
James Smart7b15db32013-01-03 15:43:29 -050014704 /* Set up SLI-4 HBA */
14705 if (lpfc_sli4_hba_setup(phba)) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014706 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart7b15db32013-01-03 15:43:29 -050014707 "1421 Failed to set up hba\n");
14708 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080014709 goto out_free_sysfs_attr;
James Smart7b15db32013-01-03 15:43:29 -050014710 }
14711
14712 /* Log the current active interrupt mode */
14713 phba->intr_mode = intr_mode;
14714 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040014715
14716 /* Perform post initialization setup */
14717 lpfc_post_init_setup(phba);
14718
James Smart01649562017-02-12 13:52:32 -080014719 /* NVME support in FW earlier in the driver load corrects the
14720 * FC4 type making a check for nvme_support unnecessary.
14721 */
James Smart0794d602019-01-28 11:14:19 -080014722 if (phba->nvmet_support == 0) {
14723 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14724 /* Create NVME binding with nvme_fc_transport. This
14725 * ensures the vport is initialized. If the localport
14726 * create fails, it should not unload the driver to
14727 * support field issues.
14728 */
14729 error = lpfc_nvme_create_localport(vport);
14730 if (error) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014731 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0794d602019-01-28 11:14:19 -080014732 "6004 NVME registration "
14733 "failed, error x%x\n",
14734 error);
14735 }
James Smart01649562017-02-12 13:52:32 -080014736 }
14737 }
James Smart895427b2017-02-12 13:52:30 -080014738
James Smartc71ab862012-10-31 14:44:33 -040014739 /* check for firmware upgrade or downgrade */
14740 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040014741 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040014742
James Smart1c6834a2009-07-19 10:01:26 -040014743 /* Check if there are static vports to be created. */
14744 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070014745
14746 /* Enable RAS FW log support */
14747 lpfc_sli4_ras_setup(phba);
14748
James Smartf861f592020-03-22 11:12:54 -070014749 timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
James Smart93a4d6f2019-11-04 16:57:05 -080014750 cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
14751
James Smartda0436e2009-05-22 14:51:39 -040014752 return 0;
14753
James Smartda0436e2009-05-22 14:51:39 -040014754out_free_sysfs_attr:
14755 lpfc_free_sysfs_attr(vport);
14756out_destroy_shost:
14757 lpfc_destroy_shost(phba);
James Smartcdb42be2019-01-28 11:14:21 -080014758out_disable_intr:
14759 lpfc_sli4_disable_intr(phba);
James Smartda0436e2009-05-22 14:51:39 -040014760out_unset_driver_resource:
14761 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040014762out_unset_driver_resource_s4:
14763 lpfc_sli4_driver_resource_unset(phba);
14764out_unset_pci_mem_s4:
14765 lpfc_sli4_pci_mem_unset(phba);
14766out_disable_pci_dev:
14767 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040014768 if (shost)
14769 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040014770out_free_phba:
14771 lpfc_hba_free(phba);
14772 return error;
14773}
14774
14775/**
14776 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
14777 * @pdev: pointer to PCI device
14778 *
14779 * This routine is called from the kernel's PCI subsystem to device with
14780 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
14781 * removed from PCI bus, it performs all the necessary cleanup for the HBA
14782 * device to be removed from the PCI subsystem properly.
14783 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080014784static void
James Smartda0436e2009-05-22 14:51:39 -040014785lpfc_pci_remove_one_s4(struct pci_dev *pdev)
14786{
14787 struct Scsi_Host *shost = pci_get_drvdata(pdev);
14788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
14789 struct lpfc_vport **vports;
14790 struct lpfc_hba *phba = vport->phba;
14791 int i;
14792
14793 /* Mark the device unloading flag */
14794 spin_lock_irq(&phba->hbalock);
14795 vport->load_flag |= FC_UNLOADING;
14796 spin_unlock_irq(&phba->hbalock);
James Smart02243832021-08-16 09:28:54 -070014797 if (phba->cgn_i)
14798 lpfc_unreg_congestion_buf(phba);
James Smartda0436e2009-05-22 14:51:39 -040014799
James Smartda0436e2009-05-22 14:51:39 -040014800 lpfc_free_sysfs_attr(vport);
14801
14802 /* Release all the vports against this physical port */
14803 vports = lpfc_create_vport_work_array(phba);
14804 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040014805 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
14806 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
14807 continue;
James Smartda0436e2009-05-22 14:51:39 -040014808 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040014809 }
James Smartda0436e2009-05-22 14:51:39 -040014810 lpfc_destroy_vport_work_array(phba, vports);
14811
James Smart95f0ef82020-11-15 11:26:32 -080014812 /* Remove FC host with the physical port */
James Smartda0436e2009-05-22 14:51:39 -040014813 fc_remove_host(shost);
James Smarte9b11082020-11-15 11:26:33 -080014814 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040014815
James Smartda0436e2009-05-22 14:51:39 -040014816 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
14817 * localports are destroyed after to cleanup all transport memory.
14818 */
14819 lpfc_cleanup(vport);
14820 lpfc_nvmet_destroy_targetport(phba);
14821 lpfc_nvme_destroy_localport(vport);
14822
James Smartc4908502019-01-28 11:14:28 -080014823 /* De-allocate multi-XRI pools */
14824 if (phba->cfg_xri_rebalancing)
14825 lpfc_destroy_multixri_pools(phba);
14826
James Smart281d6192018-01-30 15:58:47 -080014827 /*
14828 * Bring down the SLI Layer. This step disables all interrupts,
14829 * clears the rings, discards all mailbox commands, and resets
14830 * the HBA FCoE function.
14831 */
14832 lpfc_debugfs_terminate(vport);
James Smartda0436e2009-05-22 14:51:39 -040014833
Dick Kennedy19017622017-09-29 17:34:27 -070014834 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070014835 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040014836 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070014837 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040014838
James Smart3677a3a2010-09-29 11:19:14 -040014839 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040014840 * buffers are released to their corresponding pools here.
14841 */
James Smart5e5b5112019-01-28 11:14:22 -080014842 lpfc_io_free(phba);
James Smart01649562017-02-12 13:52:32 -080014843 lpfc_free_iocb_list(phba);
James Smart5e5b5112019-01-28 11:14:22 -080014844 lpfc_sli4_hba_unset(phba);
James Smart67d12732012-08-03 12:36:13 -040014845
James Smart0cdb84e2018-04-09 14:24:26 -070014846 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040014847 lpfc_sli4_driver_resource_unset(phba);
14848
14849 /* Unmap adapter Control and Doorbell registers */
14850 lpfc_sli4_pci_mem_unset(phba);
14851
14852 /* Release PCI resources and disable device's PCI function */
14853 scsi_host_put(shost);
14854 lpfc_disable_pci_dev(phba);
14855
14856 /* Finally, free the driver's device data structure */
14857 lpfc_hba_free(phba);
14858
14859 return;
14860}
14861
14862/**
14863 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014864 * @dev_d: pointer to device
James Smartda0436e2009-05-22 14:51:39 -040014865 *
14866 * This routine is called from the kernel's PCI subsystem to support system
14867 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
14868 * this method, it quiesces the device by stopping the driver's worker
14869 * thread for the device, turning off device's interrupt and DMA, and bring
14870 * the device offline. Note that as the driver implements the minimum PM
14871 * requirements to a power-aware driver's PM support for suspend/resume -- all
14872 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
14873 * method call will be treated as SUSPEND and the driver will fully
14874 * reinitialize its device during resume() method call, the driver will set
14875 * device to PCI_D3hot state in PCI config space instead of setting it
14876 * according to the @msg provided by the PM.
14877 *
14878 * Return code
14879 * 0 - driver suspended the device
14880 * Error otherwise
14881 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014882static int __maybe_unused
14883lpfc_pci_suspend_one_s4(struct device *dev_d)
James Smartda0436e2009-05-22 14:51:39 -040014884{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014885 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smartda0436e2009-05-22 14:51:39 -040014886 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14887
14888 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040014889 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040014890
14891 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040014892 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040014893 lpfc_offline(phba);
14894 kthread_stop(phba->worker_thread);
14895
14896 /* Disable interrupt from device */
14897 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040014898 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040014899
James Smartda0436e2009-05-22 14:51:39 -040014900 return 0;
14901}
14902
14903/**
14904 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014905 * @dev_d: pointer to device
James Smartda0436e2009-05-22 14:51:39 -040014906 *
14907 * This routine is called from the kernel's PCI subsystem to support system
14908 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
14909 * this method, it restores the device's PCI config space state and fully
14910 * reinitializes the device and brings it online. Note that as the driver
14911 * implements the minimum PM requirements to a power-aware driver's PM for
14912 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
14913 * to the suspend() method call will be treated as SUSPEND and the driver
14914 * will fully reinitialize its device during resume() method call, the device
14915 * will be set to PCI_D0 directly in PCI config space before restoring the
14916 * state.
14917 *
14918 * Return code
14919 * 0 - driver suspended the device
14920 * Error otherwise
14921 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014922static int __maybe_unused
14923lpfc_pci_resume_one_s4(struct device *dev_d)
James Smartda0436e2009-05-22 14:51:39 -040014924{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053014925 struct Scsi_Host *shost = dev_get_drvdata(dev_d);
James Smartda0436e2009-05-22 14:51:39 -040014926 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
14927 uint32_t intr_mode;
14928 int error;
14929
14930 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14931 "0292 PCI device Power Management resume.\n");
14932
James Smartda0436e2009-05-22 14:51:39 -040014933 /* Startup the kernel thread for this host adapter. */
14934 phba->worker_thread = kthread_run(lpfc_do_work, phba,
14935 "lpfc_worker_%d", phba->brd_no);
14936 if (IS_ERR(phba->worker_thread)) {
14937 error = PTR_ERR(phba->worker_thread);
14938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14939 "0293 PM resume failed to start worker "
14940 "thread: error=x%x.\n", error);
14941 return error;
14942 }
14943
14944 /* Configure and enable interrupt */
14945 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
14946 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070014947 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartda0436e2009-05-22 14:51:39 -040014948 "0294 PM resume Failed to enable interrupt\n");
14949 return -EIO;
14950 } else
14951 phba->intr_mode = intr_mode;
14952
14953 /* Restart HBA and bring it online */
14954 lpfc_sli_brdrestart(phba);
14955 lpfc_online(phba);
14956
14957 /* Log the current active interrupt mode */
14958 lpfc_log_intr_mode(phba, phba->intr_mode);
14959
14960 return 0;
14961}
14962
14963/**
James Smart75baf692010-06-08 18:31:21 -040014964 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
14965 * @phba: pointer to lpfc hba data structure.
14966 *
14967 * This routine is called to prepare the SLI4 device for PCI slot recover. It
14968 * aborts all the outstanding SCSI I/Os to the pci device.
14969 **/
14970static void
14971lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
14972{
Dick Kennedy372c1872020-06-30 14:50:00 -070014973 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040014974 "2828 PCI channel I/O abort preparing for recovery\n");
14975 /*
14976 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
14977 * and let the SCSI mid-layer to retry them to recover.
14978 */
James Smartdb55fba2014-04-04 13:52:02 -040014979 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040014980}
14981
14982/**
14983 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
14984 * @phba: pointer to lpfc hba data structure.
14985 *
14986 * This routine is called to prepare the SLI4 device for PCI slot reset. It
14987 * disables the device interrupt and pci device, and aborts the internal FCP
14988 * pending I/Os.
14989 **/
14990static void
14991lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
14992{
Dick Kennedy372c1872020-06-30 14:50:00 -070014993 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040014994 "2826 PCI channel disable preparing for reset\n");
14995
14996 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040014997 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040014998
14999 /* Block all SCSI devices' I/Os on the host */
15000 lpfc_scsi_dev_block(phba);
15001
James Smartc00f62e2019-08-14 16:57:11 -070015002 /* Flush all driver's outstanding I/Os as we are to reset */
15003 lpfc_sli_flush_io_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080015004
James Smart75baf692010-06-08 18:31:21 -040015005 /* stop all timers */
15006 lpfc_stop_hba_timers(phba);
15007
15008 /* Disable interrupt and pci device */
15009 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040015010 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040015011 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040015012}
15013
15014/**
15015 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
15016 * @phba: pointer to lpfc hba data structure.
15017 *
15018 * This routine is called to prepare the SLI4 device for PCI slot permanently
15019 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
15020 * pending I/Os.
15021 **/
15022static void
15023lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
15024{
Dick Kennedy372c1872020-06-30 14:50:00 -070015025 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040015026 "2827 PCI channel permanent disable for failure\n");
15027
15028 /* Block all SCSI devices' I/Os on the host */
15029 lpfc_scsi_dev_block(phba);
15030
15031 /* stop all timers */
15032 lpfc_stop_hba_timers(phba);
15033
James Smartc00f62e2019-08-14 16:57:11 -070015034 /* Clean up all driver's outstanding I/Os */
15035 lpfc_sli_flush_io_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040015036}
15037
15038/**
James Smartda0436e2009-05-22 14:51:39 -040015039 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
15040 * @pdev: pointer to PCI device.
15041 * @state: the current PCI connection state.
15042 *
15043 * This routine is called from the PCI subsystem for error handling to device
15044 * with SLI-4 interface spec. This function is called by the PCI subsystem
15045 * after a PCI bus error affecting this device has been detected. When this
15046 * function is invoked, it will need to stop all the I/Os and interrupt(s)
15047 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
15048 * for the PCI subsystem to perform proper recovery as desired.
15049 *
15050 * Return codes
15051 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15052 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15053 **/
15054static pci_ers_result_t
15055lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
15056{
James Smart75baf692010-06-08 18:31:21 -040015057 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15058 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15059
15060 switch (state) {
15061 case pci_channel_io_normal:
15062 /* Non-fatal error, prepare for recovery */
15063 lpfc_sli4_prep_dev_for_recover(phba);
15064 return PCI_ERS_RESULT_CAN_RECOVER;
15065 case pci_channel_io_frozen:
James Smart25ac2c972021-09-10 16:31:54 -070015066 phba->hba_flag |= HBA_PCI_ERR;
James Smart75baf692010-06-08 18:31:21 -040015067 /* Fatal error, prepare for slot reset */
15068 lpfc_sli4_prep_dev_for_reset(phba);
15069 return PCI_ERS_RESULT_NEED_RESET;
15070 case pci_channel_io_perm_failure:
James Smart25ac2c972021-09-10 16:31:54 -070015071 phba->hba_flag |= HBA_PCI_ERR;
James Smart75baf692010-06-08 18:31:21 -040015072 /* Permanent failure, prepare for device down */
15073 lpfc_sli4_prep_dev_for_perm_failure(phba);
15074 return PCI_ERS_RESULT_DISCONNECT;
15075 default:
James Smart25ac2c972021-09-10 16:31:54 -070015076 phba->hba_flag |= HBA_PCI_ERR;
James Smart75baf692010-06-08 18:31:21 -040015077 /* Unknown state, prepare and request slot reset */
Dick Kennedy372c1872020-06-30 14:50:00 -070015078 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040015079 "2825 Unknown PCI error state: x%x\n", state);
15080 lpfc_sli4_prep_dev_for_reset(phba);
15081 return PCI_ERS_RESULT_NEED_RESET;
15082 }
James Smartda0436e2009-05-22 14:51:39 -040015083}
15084
15085/**
15086 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
15087 * @pdev: pointer to PCI device.
15088 *
15089 * This routine is called from the PCI subsystem for error handling to device
15090 * with SLI-4 interface spec. It is called after PCI bus has been reset to
15091 * restart the PCI card from scratch, as if from a cold-boot. During the
15092 * PCI subsystem error recovery, after the driver returns
15093 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
15094 * recovery and then call this routine before calling the .resume method to
15095 * recover the device. This function will initialize the HBA device, enable
15096 * the interrupt, but it will just put the HBA to offline state without
15097 * passing any I/O traffic.
15098 *
15099 * Return codes
15100 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15101 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15102 */
15103static pci_ers_result_t
15104lpfc_io_slot_reset_s4(struct pci_dev *pdev)
15105{
James Smart75baf692010-06-08 18:31:21 -040015106 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15107 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15108 struct lpfc_sli *psli = &phba->sli;
15109 uint32_t intr_mode;
15110
15111 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
15112 if (pci_enable_device_mem(pdev)) {
15113 printk(KERN_ERR "lpfc: Cannot re-enable "
15114 "PCI device after reset.\n");
15115 return PCI_ERS_RESULT_DISCONNECT;
15116 }
15117
15118 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040015119
James Smart25ac2c972021-09-10 16:31:54 -070015120 phba->hba_flag &= ~HBA_PCI_ERR;
James Smart0a96e972011-07-22 18:37:28 -040015121 /*
15122 * As the new kernel behavior of pci_restore_state() API call clears
15123 * device saved_state flag, need to save the restored state again.
15124 */
15125 pci_save_state(pdev);
15126
James Smart75baf692010-06-08 18:31:21 -040015127 if (pdev->is_busmaster)
15128 pci_set_master(pdev);
15129
15130 spin_lock_irq(&phba->hbalock);
15131 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
15132 spin_unlock_irq(&phba->hbalock);
15133
15134 /* Configure and enable interrupt */
15135 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
15136 if (intr_mode == LPFC_INTR_ERROR) {
Dick Kennedy372c1872020-06-30 14:50:00 -070015137 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart75baf692010-06-08 18:31:21 -040015138 "2824 Cannot re-enable interrupt after "
15139 "slot reset.\n");
15140 return PCI_ERS_RESULT_DISCONNECT;
15141 } else
15142 phba->intr_mode = intr_mode;
James Smart25ac2c972021-09-10 16:31:54 -070015143 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
James Smart75baf692010-06-08 18:31:21 -040015144
15145 /* Log the current active interrupt mode */
15146 lpfc_log_intr_mode(phba, phba->intr_mode);
15147
James Smartda0436e2009-05-22 14:51:39 -040015148 return PCI_ERS_RESULT_RECOVERED;
15149}
15150
15151/**
15152 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
15153 * @pdev: pointer to PCI device
15154 *
15155 * This routine is called from the PCI subsystem for error handling to device
15156 * with SLI-4 interface spec. It is called when kernel error recovery tells
15157 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
15158 * error recovery. After this call, traffic can start to flow from this device
15159 * again.
15160 **/
15161static void
15162lpfc_io_resume_s4(struct pci_dev *pdev)
15163{
James Smart75baf692010-06-08 18:31:21 -040015164 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15165 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15166
15167 /*
15168 * In case of slot reset, as function reset is performed through
15169 * mailbox command which needs DMA to be enabled, this operation
15170 * has to be moved to the io resume phase. Taking device offline
15171 * will perform the necessary cleanup.
15172 */
15173 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
15174 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040015175 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040015176 lpfc_offline(phba);
15177 lpfc_sli_brdrestart(phba);
15178 /* Bring the device back online */
15179 lpfc_online(phba);
15180 }
James Smartda0436e2009-05-22 14:51:39 -040015181}
15182
15183/**
James Smart3772a992009-05-22 14:50:54 -040015184 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
15185 * @pdev: pointer to PCI device
15186 * @pid: pointer to PCI device identifier
15187 *
15188 * This routine is to be registered to the kernel's PCI subsystem. When an
15189 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
15190 * at PCI device-specific information of the device and driver to see if the
15191 * driver state that it can support this kind of device. If the match is
15192 * successful, the driver core invokes this routine. This routine dispatches
15193 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
15194 * do all the initialization that it needs to do to handle the HBA device
15195 * properly.
15196 *
15197 * Return code
15198 * 0 - driver can claim the device
15199 * negative value - driver can not claim the device
15200 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080015201static int
James Smart3772a992009-05-22 14:50:54 -040015202lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
15203{
15204 int rc;
James Smart8fa38512009-07-19 10:01:03 -040015205 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040015206
James Smart28baac72010-02-12 14:42:03 -050015207 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040015208 return -ENODEV;
15209
James Smart8fa38512009-07-19 10:01:03 -040015210 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050015211 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040015212 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040015213 else
James Smart3772a992009-05-22 14:50:54 -040015214 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040015215
James Smart3772a992009-05-22 14:50:54 -040015216 return rc;
15217}
15218
15219/**
15220 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
15221 * @pdev: pointer to PCI device
15222 *
15223 * This routine is to be registered to the kernel's PCI subsystem. When an
15224 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
15225 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
15226 * remove routine, which will perform all the necessary cleanup for the
15227 * device to be removed from the PCI subsystem properly.
15228 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080015229static void
James Smart3772a992009-05-22 14:50:54 -040015230lpfc_pci_remove_one(struct pci_dev *pdev)
15231{
15232 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15233 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15234
15235 switch (phba->pci_dev_grp) {
15236 case LPFC_PCI_DEV_LP:
15237 lpfc_pci_remove_one_s3(pdev);
15238 break;
James Smartda0436e2009-05-22 14:51:39 -040015239 case LPFC_PCI_DEV_OC:
15240 lpfc_pci_remove_one_s4(pdev);
15241 break;
James Smart3772a992009-05-22 14:50:54 -040015242 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015243 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015244 "1424 Invalid PCI device group: 0x%x\n",
15245 phba->pci_dev_grp);
15246 break;
15247 }
15248 return;
15249}
15250
15251/**
15252 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015253 * @dev: pointer to device
James Smart3772a992009-05-22 14:50:54 -040015254 *
15255 * This routine is to be registered to the kernel's PCI subsystem to support
15256 * system Power Management (PM). When PM invokes this method, it dispatches
15257 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
15258 * suspend the device.
15259 *
15260 * Return code
15261 * 0 - driver suspended the device
15262 * Error otherwise
15263 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015264static int __maybe_unused
15265lpfc_pci_suspend_one(struct device *dev)
James Smart3772a992009-05-22 14:50:54 -040015266{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015267 struct Scsi_Host *shost = dev_get_drvdata(dev);
James Smart3772a992009-05-22 14:50:54 -040015268 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15269 int rc = -ENODEV;
15270
15271 switch (phba->pci_dev_grp) {
15272 case LPFC_PCI_DEV_LP:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015273 rc = lpfc_pci_suspend_one_s3(dev);
James Smart3772a992009-05-22 14:50:54 -040015274 break;
James Smartda0436e2009-05-22 14:51:39 -040015275 case LPFC_PCI_DEV_OC:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015276 rc = lpfc_pci_suspend_one_s4(dev);
James Smartda0436e2009-05-22 14:51:39 -040015277 break;
James Smart3772a992009-05-22 14:50:54 -040015278 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015280 "1425 Invalid PCI device group: 0x%x\n",
15281 phba->pci_dev_grp);
15282 break;
15283 }
15284 return rc;
15285}
15286
15287/**
15288 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015289 * @dev: pointer to device
James Smart3772a992009-05-22 14:50:54 -040015290 *
15291 * This routine is to be registered to the kernel's PCI subsystem to support
15292 * system Power Management (PM). When PM invokes this method, it dispatches
15293 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
15294 * resume the device.
15295 *
15296 * Return code
15297 * 0 - driver suspended the device
15298 * Error otherwise
15299 **/
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015300static int __maybe_unused
15301lpfc_pci_resume_one(struct device *dev)
James Smart3772a992009-05-22 14:50:54 -040015302{
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015303 struct Scsi_Host *shost = dev_get_drvdata(dev);
James Smart3772a992009-05-22 14:50:54 -040015304 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15305 int rc = -ENODEV;
15306
15307 switch (phba->pci_dev_grp) {
15308 case LPFC_PCI_DEV_LP:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015309 rc = lpfc_pci_resume_one_s3(dev);
James Smart3772a992009-05-22 14:50:54 -040015310 break;
James Smartda0436e2009-05-22 14:51:39 -040015311 case LPFC_PCI_DEV_OC:
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015312 rc = lpfc_pci_resume_one_s4(dev);
James Smartda0436e2009-05-22 14:51:39 -040015313 break;
James Smart3772a992009-05-22 14:50:54 -040015314 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015315 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015316 "1426 Invalid PCI device group: 0x%x\n",
15317 phba->pci_dev_grp);
15318 break;
15319 }
15320 return rc;
15321}
15322
15323/**
15324 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
15325 * @pdev: pointer to PCI device.
15326 * @state: the current PCI connection state.
15327 *
15328 * This routine is registered to the PCI subsystem for error handling. This
15329 * function is called by the PCI subsystem after a PCI bus error affecting
15330 * this device has been detected. When this routine is invoked, it dispatches
15331 * the action to the proper SLI-3 or SLI-4 device error detected handling
15332 * routine, which will perform the proper error detected operation.
15333 *
15334 * Return codes
15335 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
15336 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15337 **/
15338static pci_ers_result_t
15339lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
15340{
15341 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15342 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15343 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15344
James Smart25ac2c972021-09-10 16:31:54 -070015345 if (phba->link_state == LPFC_HBA_ERROR &&
15346 phba->hba_flag & HBA_IOQ_FLUSH)
15347 return PCI_ERS_RESULT_NEED_RESET;
15348
James Smart3772a992009-05-22 14:50:54 -040015349 switch (phba->pci_dev_grp) {
15350 case LPFC_PCI_DEV_LP:
15351 rc = lpfc_io_error_detected_s3(pdev, state);
15352 break;
James Smartda0436e2009-05-22 14:51:39 -040015353 case LPFC_PCI_DEV_OC:
15354 rc = lpfc_io_error_detected_s4(pdev, state);
15355 break;
James Smart3772a992009-05-22 14:50:54 -040015356 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015357 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015358 "1427 Invalid PCI device group: 0x%x\n",
15359 phba->pci_dev_grp);
15360 break;
15361 }
15362 return rc;
15363}
15364
15365/**
15366 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
15367 * @pdev: pointer to PCI device.
15368 *
15369 * This routine is registered to the PCI subsystem for error handling. This
15370 * function is called after PCI bus has been reset to restart the PCI card
15371 * from scratch, as if from a cold-boot. When this routine is invoked, it
15372 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
15373 * routine, which will perform the proper device reset.
15374 *
15375 * Return codes
15376 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
15377 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
15378 **/
15379static pci_ers_result_t
15380lpfc_io_slot_reset(struct pci_dev *pdev)
15381{
15382 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15383 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15384 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
15385
15386 switch (phba->pci_dev_grp) {
15387 case LPFC_PCI_DEV_LP:
15388 rc = lpfc_io_slot_reset_s3(pdev);
15389 break;
James Smartda0436e2009-05-22 14:51:39 -040015390 case LPFC_PCI_DEV_OC:
15391 rc = lpfc_io_slot_reset_s4(pdev);
15392 break;
James Smart3772a992009-05-22 14:50:54 -040015393 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015394 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015395 "1428 Invalid PCI device group: 0x%x\n",
15396 phba->pci_dev_grp);
15397 break;
15398 }
15399 return rc;
15400}
15401
15402/**
15403 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
15404 * @pdev: pointer to PCI device
15405 *
15406 * This routine is registered to the PCI subsystem for error handling. It
15407 * is called when kernel error recovery tells the lpfc driver that it is
15408 * OK to resume normal PCI operation after PCI bus error recovery. When
15409 * this routine is invoked, it dispatches the action to the proper SLI-3
15410 * or SLI-4 device io_resume routine, which will resume the device operation.
15411 **/
15412static void
15413lpfc_io_resume(struct pci_dev *pdev)
15414{
15415 struct Scsi_Host *shost = pci_get_drvdata(pdev);
15416 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
15417
15418 switch (phba->pci_dev_grp) {
15419 case LPFC_PCI_DEV_LP:
15420 lpfc_io_resume_s3(pdev);
15421 break;
James Smartda0436e2009-05-22 14:51:39 -040015422 case LPFC_PCI_DEV_OC:
15423 lpfc_io_resume_s4(pdev);
15424 break;
James Smart3772a992009-05-22 14:50:54 -040015425 default:
Dick Kennedy372c1872020-06-30 14:50:00 -070015426 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3772a992009-05-22 14:50:54 -040015427 "1429 Invalid PCI device group: 0x%x\n",
15428 phba->pci_dev_grp);
15429 break;
15430 }
15431 return;
15432}
15433
James Smart1ba981f2014-02-20 09:56:45 -050015434/**
15435 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
15436 * @phba: pointer to lpfc hba data structure.
15437 *
15438 * This routine checks to see if OAS is supported for this adapter. If
15439 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
15440 * the enable oas flag is cleared and the pool created for OAS device data
15441 * is destroyed.
15442 *
15443 **/
YueHaibingc7092972019-04-17 23:05:54 +080015444static void
James Smart1ba981f2014-02-20 09:56:45 -050015445lpfc_sli4_oas_verify(struct lpfc_hba *phba)
15446{
15447
15448 if (!phba->cfg_EnableXLane)
15449 return;
15450
15451 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
15452 phba->cfg_fof = 1;
15453 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040015454 phba->cfg_fof = 0;
Saurav Girepunjec3e5aac2019-10-27 01:17:17 +053015455 mempool_destroy(phba->device_data_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -050015456 phba->device_data_mem_pool = NULL;
15457 }
15458
15459 return;
15460}
15461
15462/**
James Smartd2cc9bc2018-09-10 10:30:50 -070015463 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
15464 * @phba: pointer to lpfc hba data structure.
15465 *
15466 * This routine checks to see if RAS is supported by the adapter. Check the
15467 * function through which RAS support enablement is to be done.
15468 **/
15469void
15470lpfc_sli4_ras_init(struct lpfc_hba *phba)
15471{
James Smartf6c5e6c2021-07-22 15:17:18 -070015472 /* if ASIC_GEN_NUM >= 0xC) */
15473 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
15474 LPFC_SLI_INTF_IF_TYPE_6) ||
15475 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
15476 LPFC_SLI_INTF_FAMILY_G6)) {
James Smartd2cc9bc2018-09-10 10:30:50 -070015477 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080015478 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
15479 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070015480 phba->ras_fwlog.ras_enabled = true;
15481 else
15482 phba->ras_fwlog.ras_enabled = false;
James Smartf6c5e6c2021-07-22 15:17:18 -070015483 } else {
James Smartd2cc9bc2018-09-10 10:30:50 -070015484 phba->ras_fwlog.ras_hwsupport = false;
15485 }
15486}
15487
James Smart1ba981f2014-02-20 09:56:45 -050015488
dea31012005-04-17 16:05:31 -050015489MODULE_DEVICE_TABLE(pci, lpfc_id_table);
15490
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070015491static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060015492 .error_detected = lpfc_io_error_detected,
15493 .slot_reset = lpfc_io_slot_reset,
15494 .resume = lpfc_io_resume,
15495};
15496
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015497static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
15498 lpfc_pci_suspend_one,
15499 lpfc_pci_resume_one);
15500
dea31012005-04-17 16:05:31 -050015501static struct pci_driver lpfc_driver = {
15502 .name = LPFC_DRIVER_NAME,
15503 .id_table = lpfc_id_table,
15504 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080015505 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110015506 .shutdown = lpfc_pci_remove_one,
Vaibhav Guptaef6fa162020-11-02 22:17:18 +053015507 .driver.pm = &lpfc_pci_pm_ops_one,
James Smart2e0fef82007-06-17 19:56:36 -050015508 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050015509};
15510
James Smart3ef6d242012-01-18 16:23:48 -050015511static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040015512 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050015513};
15514
15515static struct miscdevice lpfc_mgmt_dev = {
15516 .minor = MISC_DYNAMIC_MINOR,
15517 .name = "lpfcmgmt",
15518 .fops = &lpfc_mgmt_fop,
15519};
15520
James Smarte59058c2008-08-24 21:49:00 -040015521/**
James Smart3621a712009-04-06 18:47:14 -040015522 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040015523 *
15524 * This routine is to be invoked when the lpfc module is loaded into the
15525 * kernel. The special kernel macro module_init() is used to indicate the
15526 * role of this routine to the kernel as lpfc module entry point.
15527 *
15528 * Return codes
15529 * 0 - successful
15530 * -ENOMEM - FC attach transport failed
15531 * all others - failed
15532 */
dea31012005-04-17 16:05:31 -050015533static int __init
15534lpfc_init(void)
15535{
15536 int error = 0;
15537
Anton Blanchardbc2736e2020-07-13 18:39:08 +100015538 pr_info(LPFC_MODULE_DESC "\n");
15539 pr_info(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050015540
James Smart3ef6d242012-01-18 16:23:48 -050015541 error = misc_register(&lpfc_mgmt_dev);
15542 if (error)
15543 printk(KERN_ERR "Could not register lpfcmgmt device, "
15544 "misc_register returned with status %d", error);
15545
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080015546 error = -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070015547 lpfc_transport_functions.vport_create = lpfc_vport_create;
15548 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050015549 lpfc_transport_template =
15550 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040015551 if (lpfc_transport_template == NULL)
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080015552 goto unregister;
James Smart458c0832016-07-06 12:36:07 -070015553 lpfc_vport_transport_template =
15554 fc_attach_transport(&lpfc_vport_transport_functions);
15555 if (lpfc_vport_transport_template == NULL) {
15556 fc_release_transport(lpfc_transport_template);
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080015557 goto unregister;
James Smart7ee5d432007-10-27 13:37:17 -040015558 }
James Smart840a4702020-11-15 11:26:40 -080015559 lpfc_wqe_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080015560 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040015561
15562 /* Initialize in case vector mapping is needed */
James Smart2ea259e2017-02-12 13:52:27 -080015563 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040015564
James Smart93a4d6f2019-11-04 16:57:05 -080015565 error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
15566 "lpfc/sli4:online",
15567 lpfc_cpu_online, lpfc_cpu_offline);
15568 if (error < 0)
15569 goto cpuhp_failure;
15570 lpfc_cpuhp_state = error;
15571
dea31012005-04-17 16:05:31 -050015572 error = pci_register_driver(&lpfc_driver);
James Smart93a4d6f2019-11-04 16:57:05 -080015573 if (error)
15574 goto unwind;
15575
15576 return error;
15577
15578unwind:
15579 cpuhp_remove_multi_state(lpfc_cpuhp_state);
15580cpuhp_failure:
15581 fc_release_transport(lpfc_transport_template);
15582 fc_release_transport(lpfc_vport_transport_template);
Jing Xiangfeng1eaff532020-07-31 14:56:39 +080015583unregister:
15584 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050015585
15586 return error;
15587}
15588
Dick Kennedy372c1872020-06-30 14:50:00 -070015589void lpfc_dmp_dbg(struct lpfc_hba *phba)
15590{
15591 unsigned int start_idx;
15592 unsigned int dbg_cnt;
15593 unsigned int temp_idx;
15594 int i;
15595 int j = 0;
James Smarte8613082021-07-07 11:43:33 -070015596 unsigned long rem_nsec, iflags;
15597 bool log_verbose = false;
15598 struct lpfc_vport *port_iterator;
Dick Kennedy372c1872020-06-30 14:50:00 -070015599
James Smart0b3ad322021-01-04 10:02:39 -080015600 /* Don't dump messages if we explicitly set log_verbose for the
15601 * physical port or any vport.
15602 */
Dick Kennedy372c1872020-06-30 14:50:00 -070015603 if (phba->cfg_log_verbose)
15604 return;
15605
James Smarte8613082021-07-07 11:43:33 -070015606 spin_lock_irqsave(&phba->port_list_lock, iflags);
15607 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
15608 if (port_iterator->load_flag & FC_UNLOADING)
15609 continue;
15610 if (scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
15611 if (port_iterator->cfg_log_verbose)
15612 log_verbose = true;
15613
15614 scsi_host_put(lpfc_shost_from_vport(port_iterator));
15615
15616 if (log_verbose) {
15617 spin_unlock_irqrestore(&phba->port_list_lock,
15618 iflags);
James Smart0b3ad322021-01-04 10:02:39 -080015619 return;
15620 }
15621 }
15622 }
James Smarte8613082021-07-07 11:43:33 -070015623 spin_unlock_irqrestore(&phba->port_list_lock, iflags);
James Smart0b3ad322021-01-04 10:02:39 -080015624
Dick Kennedy372c1872020-06-30 14:50:00 -070015625 if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
15626 return;
15627
15628 start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
15629 dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
James Smart0b3ad322021-01-04 10:02:39 -080015630 if (!dbg_cnt)
15631 goto out;
Dick Kennedy372c1872020-06-30 14:50:00 -070015632 temp_idx = start_idx;
15633 if (dbg_cnt >= DBG_LOG_SZ) {
15634 dbg_cnt = DBG_LOG_SZ;
15635 temp_idx -= 1;
15636 } else {
15637 if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
15638 temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
15639 } else {
Dick Kennedy77dd7d72020-07-06 13:42:46 -070015640 if (start_idx < dbg_cnt)
Dick Kennedy372c1872020-06-30 14:50:00 -070015641 start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
Dick Kennedy77dd7d72020-07-06 13:42:46 -070015642 else
Dick Kennedy372c1872020-06-30 14:50:00 -070015643 start_idx -= dbg_cnt;
Dick Kennedy372c1872020-06-30 14:50:00 -070015644 }
15645 }
15646 dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
15647 start_idx, temp_idx, dbg_cnt);
15648
15649 for (i = 0; i < dbg_cnt; i++) {
15650 if ((start_idx + i) < DBG_LOG_SZ)
Dick Kennedy77dd7d72020-07-06 13:42:46 -070015651 temp_idx = (start_idx + i) % DBG_LOG_SZ;
Dick Kennedy372c1872020-06-30 14:50:00 -070015652 else
15653 temp_idx = j++;
15654 rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
15655 dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
15656 temp_idx,
15657 (unsigned long)phba->dbg_log[temp_idx].t_ns,
15658 rem_nsec / 1000,
15659 phba->dbg_log[temp_idx].log);
15660 }
James Smart0b3ad322021-01-04 10:02:39 -080015661out:
Dick Kennedy372c1872020-06-30 14:50:00 -070015662 atomic_set(&phba->dbg_log_cnt, 0);
15663 atomic_set(&phba->dbg_log_dmping, 0);
15664}
15665
Lee Jones7fa03c72020-07-23 13:24:21 +010015666__printf(2, 3)
Dick Kennedy372c1872020-06-30 14:50:00 -070015667void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
15668{
15669 unsigned int idx;
15670 va_list args;
15671 int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
15672 struct va_format vaf;
15673
15674
15675 va_start(args, fmt);
15676 if (unlikely(dbg_dmping)) {
15677 vaf.fmt = fmt;
15678 vaf.va = &args;
15679 dev_info(&phba->pcidev->dev, "%pV", &vaf);
15680 va_end(args);
15681 return;
15682 }
15683 idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
15684 DBG_LOG_SZ;
15685
15686 atomic_inc(&phba->dbg_log_cnt);
15687
15688 vscnprintf(phba->dbg_log[idx].log,
15689 sizeof(phba->dbg_log[idx].log), fmt, args);
15690 va_end(args);
15691
15692 phba->dbg_log[idx].t_ns = local_clock();
15693}
15694
James Smarte59058c2008-08-24 21:49:00 -040015695/**
James Smart3621a712009-04-06 18:47:14 -040015696 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040015697 *
15698 * This routine is invoked when the lpfc module is removed from the kernel.
15699 * The special kernel macro module_exit() is used to indicate the role of
15700 * this routine to the kernel as lpfc module exit point.
15701 */
dea31012005-04-17 16:05:31 -050015702static void __exit
15703lpfc_exit(void)
15704{
James Smart3ef6d242012-01-18 16:23:48 -050015705 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050015706 pci_unregister_driver(&lpfc_driver);
James Smart93a4d6f2019-11-04 16:57:05 -080015707 cpuhp_remove_multi_state(lpfc_cpuhp_state);
dea31012005-04-17 16:05:31 -050015708 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070015709 fc_release_transport(lpfc_vport_transport_template);
Johannes Thumshirn79739672015-08-31 16:48:11 -040015710 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050015711}
15712
15713module_init(lpfc_init);
15714module_exit(lpfc_exit);
15715MODULE_LICENSE("GPL");
15716MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080015717MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050015718MODULE_VERSION("0:" LPFC_DRIVER_VERSION);