blob: d04d00dea90195ed06aa7522a074f83e0697b5e2 [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 Smart0d041212019-01-28 11:14:41 -08004 * Copyright (C) 2017-2019 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>
dea31012005-04-17 16:05:31 -050043
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040044#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050045#include <scsi/scsi_device.h>
46#include <scsi/scsi_host.h>
47#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070048#include <scsi/scsi_tcq.h>
49#include <scsi/fc/fc_fs.h>
50
51#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050052
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"
James Smart86c67372017-04-21 16:05:04 -070062#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050063#include "lpfc_logmsg.h"
64#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050065#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050066#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070067#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050068
James Smart81301a92008-12-04 22:39:46 -050069char *_dump_buf_data;
70unsigned long _dump_buf_data_order;
71char *_dump_buf_dif;
72unsigned long _dump_buf_dif_order;
73spinlock_t _dump_buf_lock;
74
James Smart7bb03bb2013-04-17 20:19:16 -040075/* Used when mapping IRQ vectors in a driver centric manner */
YueHaibingd7b761b2019-05-31 23:28:41 +080076static uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040077
dea31012005-04-17 16:05:31 -050078static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
79static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040080static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040081static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
82static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040083static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040084static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080085static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040086static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040087static int lpfc_init_active_sgl_array(struct lpfc_hba *);
88static void lpfc_free_active_sgl(struct lpfc_hba *);
89static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
90static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
91static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
93static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040094static void lpfc_sli4_disable_intr(struct lpfc_hba *);
95static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050096static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
James Smart6a828b02019-01-28 11:14:31 -080097static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
James Smartaa6ff302019-05-21 17:49:09 -070098static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
dea31012005-04-17 16:05:31 -050099
100static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500101static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -0500102static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800103#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500104
James Smarte59058c2008-08-24 21:49:00 -0400105/**
James Smart3621a712009-04-06 18:47:14 -0400106 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400107 * @phba: pointer to lpfc hba data structure.
108 *
109 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
110 * mailbox command. It retrieves the revision information from the HBA and
111 * collects the Vital Product Data (VPD) about the HBA for preparing the
112 * configuration of the HBA.
113 *
114 * Return codes:
115 * 0 - success.
116 * -ERESTART - requests the SLI layer to reset the HBA and try again.
117 * Any other value - indicates an error.
118 **/
dea31012005-04-17 16:05:31 -0500119int
James Smart2e0fef82007-06-17 19:56:36 -0500120lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500121{
122 lpfc_vpd_t *vp = &phba->vpd;
123 int i = 0, rc;
124 LPFC_MBOXQ_t *pmb;
125 MAILBOX_t *mb;
126 char *lpfc_vpd_data = NULL;
127 uint16_t offset = 0;
128 static char licensed[56] =
129 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400130 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500131
132 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
133 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500134 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500135 return -ENOMEM;
136 }
137
James Smart04c68492009-05-22 14:52:52 -0400138 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500139 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500140
141 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400142 if (init_key) {
143 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500144
James Smart65a29c12006-07-06 15:50:50 -0400145 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
146 *ptext = cpu_to_be32(*ptext);
147 init_key = 0;
148 }
dea31012005-04-17 16:05:31 -0500149
150 lpfc_read_nv(phba, pmb);
151 memset((char*)mb->un.varRDnvp.rsvd3, 0,
152 sizeof (mb->un.varRDnvp.rsvd3));
153 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
154 sizeof (licensed));
155
156 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
157
158 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500159 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400160 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500161 "error, mbxCmd x%x READ_NVPARM, "
162 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500163 mb->mbxCommand, mb->mbxStatus);
164 mempool_free(pmb, phba->mbox_mem_pool);
165 return -ERESTART;
166 }
167 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500168 sizeof(phba->wwnn));
169 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
170 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500171 }
172
Martin Wilckdfb75132018-11-12 09:58:37 +0100173 /*
174 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
175 * which was already set in lpfc_get_cfgparam()
176 */
177 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500178
dea31012005-04-17 16:05:31 -0500179 /* Setup and issue mailbox READ REV command */
180 lpfc_read_rev(phba, pmb);
181 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
182 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400184 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500185 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500186 mb->mbxCommand, mb->mbxStatus);
187 mempool_free( pmb, phba->mbox_mem_pool);
188 return -ERESTART;
189 }
190
James Smart92d7f7b2007-06-17 19:56:38 -0500191
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500192 /*
193 * The value of rr must be 1 since the driver set the cv field to 1.
194 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500195 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500196 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500197 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400199 "0440 Adapter failed to init, READ_REV has "
200 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500201 mempool_free(pmb, phba->mbox_mem_pool);
202 return -ERESTART;
dea31012005-04-17 16:05:31 -0500203 }
204
James Smart495a7142008-06-14 22:52:59 -0400205 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
206 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500207 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400208 }
James Smarted957682007-06-17 19:56:37 -0500209
dea31012005-04-17 16:05:31 -0500210 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500211 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500212 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500213 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
214 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
215 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
216 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500217 vp->rev.biuRev = mb->un.varRdRev.biuRev;
218 vp->rev.smRev = mb->un.varRdRev.smRev;
219 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
220 vp->rev.endecRev = mb->un.varRdRev.endecRev;
221 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
222 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
223 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
224 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
225 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
226 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
227
James Smart92d7f7b2007-06-17 19:56:38 -0500228 /* If the sli feature level is less then 9, we must
229 * tear down all RPIs and VPIs on link down if NPIV
230 * is enabled.
231 */
232 if (vp->rev.feaLevelHigh < 9)
233 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
234
dea31012005-04-17 16:05:31 -0500235 if (lpfc_is_LC_HBA(phba->pcidev->device))
236 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
237 sizeof (phba->RandomData));
238
dea31012005-04-17 16:05:31 -0500239 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500240 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
241 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400242 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500243 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400244 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500245 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
246
247 if (rc != MBX_SUCCESS) {
248 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400249 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500250 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500251 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500253 }
James Smart04c68492009-05-22 14:52:52 -0400254 /* dump mem may return a zero when finished or we got a
255 * mailbox error, either way we are done.
256 */
257 if (mb->un.varDmp.word_cnt == 0)
258 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500259 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,
262 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500263 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500264 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500265 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
266 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500267
268 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500269out_free_mbox:
270 mempool_free(pmb, phba->mbox_mem_pool);
271 return 0;
272}
273
James Smarte59058c2008-08-24 21:49:00 -0400274/**
James Smart3621a712009-04-06 18:47:14 -0400275 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400276 * @phba: pointer to lpfc hba data structure.
277 * @pmboxq: pointer to the driver internal queue element for mailbox command.
278 *
279 * This is the completion handler for driver's configuring asynchronous event
280 * mailbox command to the device. If the mailbox command returns successfully,
281 * it will set internal async event support flag to 1; otherwise, it will
282 * set internal async event support flag to 0.
283 **/
James Smart57127f12007-10-27 13:37:05 -0400284static void
285lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
286{
James Smart04c68492009-05-22 14:52:52 -0400287 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400288 phba->temp_sensor_support = 1;
289 else
290 phba->temp_sensor_support = 0;
291 mempool_free(pmboxq, phba->mbox_mem_pool);
292 return;
293}
294
James Smarte59058c2008-08-24 21:49:00 -0400295/**
James Smart3621a712009-04-06 18:47:14 -0400296 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500297 * @phba: pointer to lpfc hba data structure.
298 * @pmboxq: pointer to the driver internal queue element for mailbox command.
299 *
300 * This is the completion handler for dump mailbox command for getting
301 * wake up parameters. When this command complete, the response contain
302 * Option rom version of the HBA. This function translate the version number
303 * into a human readable string and store it in OptionROMVersion.
304 **/
305static void
306lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
307{
308 struct prog_id *prg;
309 uint32_t prog_id_word;
310 char dist = ' ';
311 /* character array used for decoding dist type. */
312 char dist_char[] = "nabx";
313
James Smart04c68492009-05-22 14:52:52 -0400314 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500315 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500316 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500317 }
James Smart97207482008-12-04 22:39:19 -0500318
319 prg = (struct prog_id *) &prog_id_word;
320
321 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400322 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500323
324 /* Decode the Option rom version word to a readable string */
325 if (prg->dist < 4)
326 dist = dist_char[prg->dist];
327
328 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400329 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500330 prg->ver, prg->rev, prg->lev);
331 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400332 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500333 prg->ver, prg->rev, prg->lev,
334 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500335 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500336 return;
337}
338
339/**
James Smart05580562011-05-24 11:40:48 -0400340 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
341 * cfg_soft_wwnn, cfg_soft_wwpn
342 * @vport: pointer to lpfc vport data structure.
343 *
344 *
345 * Return codes
346 * None.
347 **/
348void
349lpfc_update_vport_wwn(struct lpfc_vport *vport)
350{
James Smartaeb3c812017-04-21 16:05:02 -0700351 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
352 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
353
James Smart05580562011-05-24 11:40:48 -0400354 /* If the soft name exists then update it using the service params */
355 if (vport->phba->cfg_soft_wwnn)
356 u64_to_wwn(vport->phba->cfg_soft_wwnn,
357 vport->fc_sparam.nodeName.u.wwn);
358 if (vport->phba->cfg_soft_wwpn)
359 u64_to_wwn(vport->phba->cfg_soft_wwpn,
360 vport->fc_sparam.portName.u.wwn);
361
362 /*
363 * If the name is empty or there exists a soft name
364 * then copy the service params name, otherwise use the fc name
365 */
366 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
367 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
368 sizeof(struct lpfc_name));
369 else
370 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
371 sizeof(struct lpfc_name));
372
James Smartaeb3c812017-04-21 16:05:02 -0700373 /*
374 * If the port name has changed, then set the Param changes flag
375 * to unreg the login
376 */
377 if (vport->fc_portname.u.wwn[0] != 0 &&
378 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
379 sizeof(struct lpfc_name)))
380 vport->vport_flag |= FAWWPN_PARAM_CHG;
381
382 if (vport->fc_portname.u.wwn[0] == 0 ||
383 vport->phba->cfg_soft_wwpn ||
384 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
385 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400386 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
387 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700388 vport->vport_flag &= ~FAWWPN_SET;
389 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
390 vport->vport_flag |= FAWWPN_SET;
391 }
James Smart05580562011-05-24 11:40:48 -0400392 else
393 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
394 sizeof(struct lpfc_name));
395}
396
397/**
James Smart3621a712009-04-06 18:47:14 -0400398 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400399 * @phba: pointer to lpfc hba data structure.
400 *
401 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
402 * command call. It performs all internal resource and state setups on the
403 * port: post IOCB buffers, enable appropriate host interrupt attentions,
404 * ELS ring timers, etc.
405 *
406 * Return codes
407 * 0 - success.
408 * Any other value - error.
409 **/
dea31012005-04-17 16:05:31 -0500410int
James Smart2e0fef82007-06-17 19:56:36 -0500411lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500412{
James Smart2e0fef82007-06-17 19:56:36 -0500413 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500415 LPFC_MBOXQ_t *pmb;
416 MAILBOX_t *mb;
417 struct lpfc_dmabuf *mp;
418 struct lpfc_sli *psli = &phba->sli;
419 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500420 int i, j;
421 int rc;
dea31012005-04-17 16:05:31 -0500422
James Smart7af67052007-10-27 13:38:11 -0400423 spin_lock_irq(&phba->hbalock);
424 /*
425 * If the Config port completed correctly the HBA is not
426 * over heated any more.
427 */
428 if (phba->over_temp_state == HBA_OVER_TEMP)
429 phba->over_temp_state = HBA_NORMAL_TEMP;
430 spin_unlock_irq(&phba->hbalock);
431
dea31012005-04-17 16:05:31 -0500432 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
433 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500434 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500435 return -ENOMEM;
436 }
James Smart04c68492009-05-22 14:52:52 -0400437 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500438
dea31012005-04-17 16:05:31 -0500439 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500440 rc = lpfc_read_sparam(phba, pmb, 0);
441 if (rc) {
442 mempool_free(pmb, phba->mbox_mem_pool);
443 return -ENOMEM;
444 }
445
James Smarted957682007-06-17 19:56:37 -0500446 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500447 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400449 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500450 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500451 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500452 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800453 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -0500454 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500455 lpfc_mbuf_free(phba, mp->virt, mp->phys);
456 kfree(mp);
457 return -EIO;
458 }
459
James Smart3e1f0712018-11-29 16:09:29 -0800460 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500461
James Smart2e0fef82007-06-17 19:56:36 -0500462 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500463 lpfc_mbuf_free(phba, mp->virt, mp->phys);
464 kfree(mp);
James Smart3e1f0712018-11-29 16:09:29 -0800465 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400466 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400467
468 /* Update the fc_host data structures with new wwn. */
469 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
470 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400471 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400472
dea31012005-04-17 16:05:31 -0500473 /* If no serial number in VPD data, use low 6 bytes of WWNN */
474 /* This should be consolidated into parse_vpd ? - mr */
475 if (phba->SerialNumber[0] == 0) {
476 uint8_t *outptr;
477
James Smart2e0fef82007-06-17 19:56:36 -0500478 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500479 for (i = 0; i < 12; i++) {
480 status = *outptr++;
481 j = ((status & 0xf0) >> 4);
482 if (j <= 9)
483 phba->SerialNumber[i] =
484 (char)((uint8_t) 0x30 + (uint8_t) j);
485 else
486 phba->SerialNumber[i] =
487 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
488 i++;
489 j = (status & 0xf);
490 if (j <= 9)
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x30 + (uint8_t) j);
493 else
494 phba->SerialNumber[i] =
495 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
496 }
497 }
498
dea31012005-04-17 16:05:31 -0500499 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500500 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500501 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400503 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500504 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500505 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500506 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500507 mempool_free( pmb, phba->mbox_mem_pool);
508 return -EIO;
509 }
510
James Smarta0c87cb2009-07-19 10:01:10 -0400511 /* Check if the port is disabled */
512 lpfc_sli_read_link_ste(phba);
513
dea31012005-04-17 16:05:31 -0500514 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400515 i = (mb->un.varRdConfig.max_xri + 1);
516 if (phba->cfg_hba_queue_depth > i) {
517 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
518 "3359 HBA queue depth changed from %d to %d\n",
519 phba->cfg_hba_queue_depth, i);
520 phba->cfg_hba_queue_depth = i;
521 }
522
523 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
524 i = (mb->un.varRdConfig.max_xri >> 3);
525 if (phba->pport->cfg_lun_queue_depth > i) {
526 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
527 "3360 LUN queue depth changed from %d to %d\n",
528 phba->pport->cfg_lun_queue_depth, i);
529 phba->pport->cfg_lun_queue_depth = i;
530 }
dea31012005-04-17 16:05:31 -0500531
532 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500533
534 /* Get the default values for Model Name and Description */
535 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
536
James Smart2e0fef82007-06-17 19:56:36 -0500537 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500538
James Smart0b727fe2007-10-27 13:37:25 -0400539 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800540 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
541 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
542 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
543 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500544
545 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500546 if (phba->sli_rev != 3)
547 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500548
James Smart93996272008-08-24 21:50:30 -0400549 /*
550 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
551 */
552 if (phba->intr_type == MSIX) {
553 rc = lpfc_config_msi(phba, pmb);
554 if (rc) {
555 mempool_free(pmb, phba->mbox_mem_pool);
556 return -EIO;
557 }
558 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
559 if (rc != MBX_SUCCESS) {
560 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
561 "0352 Config MSI mailbox command "
562 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400563 pmb->u.mb.mbxCommand,
564 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400565 mempool_free(pmb, phba->mbox_mem_pool);
566 return -EIO;
567 }
568 }
569
James Smart04c68492009-05-22 14:52:52 -0400570 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400571 /* Initialize ERATT handling flag */
572 phba->hba_flag &= ~HBA_ERATT_HANDLED;
573
dea31012005-04-17 16:05:31 -0500574 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500575 if (lpfc_readl(phba->HCregaddr, &status)) {
576 spin_unlock_irq(&phba->hbalock);
577 return -EIO;
578 }
dea31012005-04-17 16:05:31 -0500579 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
580 if (psli->num_rings > 0)
581 status |= HC_R0INT_ENA;
582 if (psli->num_rings > 1)
583 status |= HC_R1INT_ENA;
584 if (psli->num_rings > 2)
585 status |= HC_R2INT_ENA;
586 if (psli->num_rings > 3)
587 status |= HC_R3INT_ENA;
588
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500589 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
590 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400591 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500592
dea31012005-04-17 16:05:31 -0500593 writel(status, phba->HCregaddr);
594 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500595 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500596
James Smart93996272008-08-24 21:50:30 -0400597 /* Set up ring-0 (ELS) timer */
598 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400599 mod_timer(&vport->els_tmofunc,
600 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400601 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400602 mod_timer(&phba->hb_tmofunc,
603 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500604 phba->hb_outstanding = 0;
605 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400606 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400607 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700608 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500609
James Smarta0c87cb2009-07-19 10:01:10 -0400610 if (phba->hba_flag & LINK_DISABLED) {
611 lpfc_printf_log(phba,
612 KERN_ERR, LOG_INIT,
613 "2598 Adapter Link is disabled.\n");
614 lpfc_down_link(phba, pmb);
615 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
616 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
617 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
618 lpfc_printf_log(phba,
619 KERN_ERR, LOG_INIT,
620 "2599 Adapter failed to issue DOWN_LINK"
621 " mbox command rc 0x%x\n", rc);
622
623 mempool_free(pmb, phba->mbox_mem_pool);
624 return -EIO;
625 }
James Smarte40a02c2010-02-26 14:13:54 -0500626 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500627 mempool_free(pmb, phba->mbox_mem_pool);
628 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
629 if (rc)
630 return rc;
dea31012005-04-17 16:05:31 -0500631 }
632 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400633 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500634 if (!pmb) {
635 phba->link_state = LPFC_HBA_ERROR;
636 return -ENOMEM;
637 }
638
James Smart57127f12007-10-27 13:37:05 -0400639 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
640 pmb->mbox_cmpl = lpfc_config_async_cmpl;
641 pmb->vport = phba->pport;
642 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500643
James Smart57127f12007-10-27 13:37:05 -0400644 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
645 lpfc_printf_log(phba,
646 KERN_ERR,
647 LOG_INIT,
648 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400649 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400650 rc);
651 mempool_free(pmb, phba->mbox_mem_pool);
652 }
James Smart97207482008-12-04 22:39:19 -0500653
654 /* Get Option rom version */
655 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500656 if (!pmb) {
657 phba->link_state = LPFC_HBA_ERROR;
658 return -ENOMEM;
659 }
660
James Smart97207482008-12-04 22:39:19 -0500661 lpfc_dump_wakeup_param(phba, pmb);
662 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
663 pmb->vport = phba->pport;
664 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
665
666 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400668 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500669 mempool_free(pmb, phba->mbox_mem_pool);
670 }
671
James Smartd7c255b2008-08-24 21:50:00 -0400672 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400673}
674
James Smarte59058c2008-08-24 21:49:00 -0400675/**
James Smart84d1b002010-02-12 14:42:33 -0500676 * lpfc_hba_init_link - Initialize the FC link
677 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400678 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500679 *
680 * This routine will issue the INIT_LINK mailbox command call.
681 * It is available to other drivers through the lpfc_hba data
682 * structure for use as a delayed link up mechanism with the
683 * module parameter lpfc_suppress_link_up.
684 *
685 * Return code
686 * 0 - success
687 * Any other value - error
688 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400689static int
James Smart6e7288d2010-06-07 15:23:35 -0400690lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500691{
James Smart1b511972011-12-13 13:23:09 -0500692 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
693}
694
695/**
696 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
697 * @phba: pointer to lpfc hba data structure.
698 * @fc_topology: desired fc topology.
699 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
700 *
701 * This routine will issue the INIT_LINK mailbox command call.
702 * It is available to other drivers through the lpfc_hba data
703 * structure for use as a delayed link up mechanism with the
704 * module parameter lpfc_suppress_link_up.
705 *
706 * Return code
707 * 0 - success
708 * Any other value - error
709 **/
710int
711lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
712 uint32_t flag)
713{
James Smart84d1b002010-02-12 14:42:33 -0500714 struct lpfc_vport *vport = phba->pport;
715 LPFC_MBOXQ_t *pmb;
716 MAILBOX_t *mb;
717 int rc;
718
719 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
720 if (!pmb) {
721 phba->link_state = LPFC_HBA_ERROR;
722 return -ENOMEM;
723 }
724 mb = &pmb->u.mb;
725 pmb->vport = vport;
726
James Smart026abb82011-12-13 13:20:45 -0500727 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
728 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
729 !(phba->lmt & LMT_1Gb)) ||
730 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
731 !(phba->lmt & LMT_2Gb)) ||
732 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
733 !(phba->lmt & LMT_4Gb)) ||
734 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
735 !(phba->lmt & LMT_8Gb)) ||
736 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
737 !(phba->lmt & LMT_10Gb)) ||
738 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400739 !(phba->lmt & LMT_16Gb)) ||
740 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800741 !(phba->lmt & LMT_32Gb)) ||
742 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
743 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500744 /* Reset link speed to auto */
745 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
746 "1302 Invalid speed for this board:%d "
747 "Reset link speed to auto.\n",
748 phba->cfg_link_speed);
749 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
750 }
James Smart1b511972011-12-13 13:23:09 -0500751 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500752 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500753 if (phba->sli_rev < LPFC_SLI_REV4)
754 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400755 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500756 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
758 "0498 Adapter failed to init, mbxCmd x%x "
759 "INIT_LINK, mbxStatus x%x\n",
760 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500761 if (phba->sli_rev <= LPFC_SLI_REV3) {
762 /* Clear all interrupt enable conditions */
763 writel(0, phba->HCregaddr);
764 readl(phba->HCregaddr); /* flush */
765 /* Clear all pending interrupts */
766 writel(0xffffffff, phba->HAregaddr);
767 readl(phba->HAregaddr); /* flush */
768 }
James Smart84d1b002010-02-12 14:42:33 -0500769 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400770 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500771 mempool_free(pmb, phba->mbox_mem_pool);
772 return -EIO;
773 }
James Smarte40a02c2010-02-26 14:13:54 -0500774 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400775 if (flag == MBX_POLL)
776 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500777
778 return 0;
779}
780
781/**
782 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400783 * @phba: pointer to lpfc hba data structure.
784 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500785 *
786 * This routine will issue the DOWN_LINK mailbox command call.
787 * It is available to other drivers through the lpfc_hba data
788 * structure for use to stop the link.
789 *
790 * Return code
791 * 0 - success
792 * Any other value - error
793 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400794static int
James Smart6e7288d2010-06-07 15:23:35 -0400795lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500796{
797 LPFC_MBOXQ_t *pmb;
798 int rc;
799
800 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
801 if (!pmb) {
802 phba->link_state = LPFC_HBA_ERROR;
803 return -ENOMEM;
804 }
805
806 lpfc_printf_log(phba,
807 KERN_ERR, LOG_INIT,
808 "0491 Adapter Link is disabled.\n");
809 lpfc_down_link(phba, pmb);
810 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400811 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500812 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
813 lpfc_printf_log(phba,
814 KERN_ERR, LOG_INIT,
815 "2522 Adapter failed to issue DOWN_LINK"
816 " mbox command rc 0x%x\n", rc);
817
818 mempool_free(pmb, phba->mbox_mem_pool);
819 return -EIO;
820 }
James Smart6e7288d2010-06-07 15:23:35 -0400821 if (flag == MBX_POLL)
822 mempool_free(pmb, phba->mbox_mem_pool);
823
James Smart84d1b002010-02-12 14:42:33 -0500824 return 0;
825}
826
827/**
James Smart3621a712009-04-06 18:47:14 -0400828 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400829 * @phba: pointer to lpfc HBA data structure.
830 *
831 * This routine will do LPFC uninitialization before the HBA is reset when
832 * bringing down the SLI Layer.
833 *
834 * Return codes
835 * 0 - success.
836 * Any other value - error.
837 **/
dea31012005-04-17 16:05:31 -0500838int
James Smart2e0fef82007-06-17 19:56:36 -0500839lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500840{
James Smart1b32f6a2008-02-08 18:49:39 -0500841 struct lpfc_vport **vports;
842 int i;
James Smart3772a992009-05-22 14:50:54 -0400843
844 if (phba->sli_rev <= LPFC_SLI_REV3) {
845 /* Disable interrupts */
846 writel(0, phba->HCregaddr);
847 readl(phba->HCregaddr); /* flush */
848 }
dea31012005-04-17 16:05:31 -0500849
James Smart1b32f6a2008-02-08 18:49:39 -0500850 if (phba->pport->load_flag & FC_UNLOADING)
851 lpfc_cleanup_discovery_resources(phba->pport);
852 else {
853 vports = lpfc_create_vport_work_array(phba);
854 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400855 for (i = 0; i <= phba->max_vports &&
856 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500857 lpfc_cleanup_discovery_resources(vports[i]);
858 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500859 }
860 return 0;
dea31012005-04-17 16:05:31 -0500861}
862
James Smarte59058c2008-08-24 21:49:00 -0400863/**
James Smart68e814f2014-05-21 08:04:59 -0400864 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
865 * rspiocb which got deferred
866 *
867 * @phba: pointer to lpfc HBA data structure.
868 *
869 * This routine will cleanup completed slow path events after HBA is reset
870 * when bringing down the SLI Layer.
871 *
872 *
873 * Return codes
874 * void.
875 **/
876static void
877lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
878{
879 struct lpfc_iocbq *rspiocbq;
880 struct hbq_dmabuf *dmabuf;
881 struct lpfc_cq_event *cq_event;
882
883 spin_lock_irq(&phba->hbalock);
884 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
885 spin_unlock_irq(&phba->hbalock);
886
887 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
888 /* Get the response iocb from the head of work queue */
889 spin_lock_irq(&phba->hbalock);
890 list_remove_head(&phba->sli4_hba.sp_queue_event,
891 cq_event, struct lpfc_cq_event, list);
892 spin_unlock_irq(&phba->hbalock);
893
894 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
895 case CQE_CODE_COMPL_WQE:
896 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
897 cq_event);
898 lpfc_sli_release_iocbq(phba, rspiocbq);
899 break;
900 case CQE_CODE_RECEIVE:
901 case CQE_CODE_RECEIVE_V1:
902 dmabuf = container_of(cq_event, struct hbq_dmabuf,
903 cq_event);
904 lpfc_in_buf_free(phba, &dmabuf->dbuf);
905 }
906 }
907}
908
909/**
James Smartbcece5f2014-04-04 13:51:34 -0400910 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
911 * @phba: pointer to lpfc HBA data structure.
912 *
913 * This routine will cleanup posted ELS buffers after the HBA is reset
914 * when bringing down the SLI Layer.
915 *
916 *
917 * Return codes
918 * void.
919 **/
920static void
921lpfc_hba_free_post_buf(struct lpfc_hba *phba)
922{
923 struct lpfc_sli *psli = &phba->sli;
924 struct lpfc_sli_ring *pring;
925 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400926 LIST_HEAD(buflist);
927 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400928
929 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
930 lpfc_sli_hbqbuf_free_all(phba);
931 else {
932 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800933 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400934 spin_lock_irq(&phba->hbalock);
935 list_splice_init(&pring->postbufq, &buflist);
936 spin_unlock_irq(&phba->hbalock);
937
938 count = 0;
939 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400940 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400941 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400942 lpfc_mbuf_free(phba, mp->virt, mp->phys);
943 kfree(mp);
944 }
James Smart07eab622014-04-04 13:51:44 -0400945
946 spin_lock_irq(&phba->hbalock);
947 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400948 spin_unlock_irq(&phba->hbalock);
949 }
950}
951
952/**
953 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
954 * @phba: pointer to lpfc HBA data structure.
955 *
956 * This routine will cleanup the txcmplq after the HBA is reset when bringing
957 * down the SLI Layer.
958 *
959 * Return codes
960 * void
961 **/
962static void
963lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
964{
965 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800966 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400967 struct lpfc_sli_ring *pring;
968 LIST_HEAD(completions);
969 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800970 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400971
James Smart895427b2017-02-12 13:52:30 -0800972 if (phba->sli_rev != LPFC_SLI_REV4) {
973 for (i = 0; i < psli->num_rings; i++) {
974 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400975 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800976 /* At this point in time the HBA is either reset or DOA
977 * Nothing should be on txcmplq as it will
978 * NEVER complete.
979 */
980 list_splice_init(&pring->txcmplq, &completions);
981 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400982 spin_unlock_irq(&phba->hbalock);
983
James Smart895427b2017-02-12 13:52:30 -0800984 lpfc_sli_abort_iocb_ring(phba, pring);
985 }
James Smartbcece5f2014-04-04 13:51:34 -0400986 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800987 lpfc_sli_cancel_iocbs(phba, &completions,
988 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
989 return;
990 }
991 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
992 pring = qp->pring;
993 if (!pring)
994 continue;
995 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800996 list_for_each_entry_safe(piocb, next_iocb,
997 &pring->txcmplq, list)
998 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800999 list_splice_init(&pring->txcmplq, &completions);
1000 pring->txcmplq_cnt = 0;
1001 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -04001002 lpfc_sli_abort_iocb_ring(phba, pring);
1003 }
James Smart895427b2017-02-12 13:52:30 -08001004 /* Cancel all the IOCBs from the completions list */
1005 lpfc_sli_cancel_iocbs(phba, &completions,
1006 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001007}
1008
1009/**
James Smart3772a992009-05-22 14:50:54 -04001010 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001011 int i;
James Smarte59058c2008-08-24 21:49:00 -04001012 * @phba: pointer to lpfc HBA data structure.
1013 *
1014 * This routine will do uninitialization after the HBA is reset when bring
1015 * down the SLI Layer.
1016 *
1017 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001018 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001019 * Any other value - error.
1020 **/
James Smart3772a992009-05-22 14:50:54 -04001021static int
1022lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001023{
James Smartbcece5f2014-04-04 13:51:34 -04001024 lpfc_hba_free_post_buf(phba);
1025 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001026 return 0;
1027}
James Smart5af5eee2010-10-22 11:06:38 -04001028
James Smartda0436e2009-05-22 14:51:39 -04001029/**
1030 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1031 * @phba: pointer to lpfc HBA data structure.
1032 *
1033 * This routine will do uninitialization after the HBA is reset when bring
1034 * down the SLI Layer.
1035 *
1036 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001037 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001038 * Any other value - error.
1039 **/
1040static int
1041lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1042{
James Smartc4908502019-01-28 11:14:28 -08001043 struct lpfc_io_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001044 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smart5e5b5112019-01-28 11:14:22 -08001045 struct lpfc_sli4_hdw_queue *qp;
James Smartda0436e2009-05-22 14:51:39 -04001046 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001047 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001048 LIST_HEAD(nvmet_aborts);
James Smart0f65ff62010-02-26 14:14:23 -05001049 struct lpfc_sglq *sglq_entry = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08001050 int cnt, idx;
James Smart0f65ff62010-02-26 14:14:23 -05001051
James Smart895427b2017-02-12 13:52:30 -08001052
1053 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001054 lpfc_hba_clean_txcmplq(phba);
1055
James Smartda0436e2009-05-22 14:51:39 -04001056 /* At this point in time the HBA is either reset or DOA. Either
1057 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001058 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001059 * driver is unloading or reposted if the driver is restarting
1060 * the port.
1061 */
James Smart895427b2017-02-12 13:52:30 -08001062 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001063 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001064 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001065 * list.
1066 */
James Smart895427b2017-02-12 13:52:30 -08001067 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001068 list_for_each_entry(sglq_entry,
1069 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1070 sglq_entry->state = SGL_FREED;
1071
James Smartda0436e2009-05-22 14:51:39 -04001072 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001073 &phba->sli4_hba.lpfc_els_sgl_list);
1074
James Smartf358dd02017-02-12 13:52:34 -08001075
James Smart895427b2017-02-12 13:52:30 -08001076 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001077
1078 /* abts_xxxx_buf_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001079 * list.
1080 */
James Smart5e5b5112019-01-28 11:14:22 -08001081 cnt = 0;
1082 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1083 qp = &phba->sli4_hba.hdwq[idx];
1084
1085 spin_lock(&qp->abts_scsi_buf_list_lock);
1086 list_splice_init(&qp->lpfc_abts_scsi_buf_list,
James Smart895427b2017-02-12 13:52:30 -08001087 &aborts);
James Smart895427b2017-02-12 13:52:30 -08001088
James Smart0794d602019-01-28 11:14:19 -08001089 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
James Smart86c67372017-04-21 16:05:04 -07001090 psb->pCmd = NULL;
1091 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001092 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001093 }
James Smart5e5b5112019-01-28 11:14:22 -08001094 spin_lock(&qp->io_buf_list_put_lock);
1095 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1096 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1097 qp->abts_scsi_io_bufs = 0;
1098 spin_unlock(&qp->io_buf_list_put_lock);
1099 spin_unlock(&qp->abts_scsi_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001100
James Smart5e5b5112019-01-28 11:14:22 -08001101 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1102 spin_lock(&qp->abts_nvme_buf_list_lock);
1103 list_splice_init(&qp->lpfc_abts_nvme_buf_list,
1104 &nvme_aborts);
1105 list_for_each_entry_safe(psb, psb_next, &nvme_aborts,
1106 list) {
1107 psb->pCmd = NULL;
1108 psb->status = IOSTAT_SUCCESS;
1109 cnt++;
1110 }
1111 spin_lock(&qp->io_buf_list_put_lock);
1112 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1113 qp->abts_nvme_io_bufs = 0;
1114 list_splice_init(&nvme_aborts,
1115 &qp->lpfc_io_buf_list_put);
1116 spin_unlock(&qp->io_buf_list_put_lock);
1117 spin_unlock(&qp->abts_nvme_buf_list_lock);
1118
1119 }
1120 }
James Smart731eedc2019-03-12 16:30:12 -07001121 spin_unlock_irq(&phba->hbalock);
James Smart5e5b5112019-01-28 11:14:22 -08001122
1123 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart731eedc2019-03-12 16:30:12 -07001124 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001125 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1126 &nvmet_aborts);
James Smart731eedc2019-03-12 16:30:12 -07001127 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001128 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1129 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001130 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001131 }
James Smart895427b2017-02-12 13:52:30 -08001132 }
James Smart895427b2017-02-12 13:52:30 -08001133
James Smart68e814f2014-05-21 08:04:59 -04001134 lpfc_sli4_free_sp_events(phba);
James Smart5e5b5112019-01-28 11:14:22 -08001135 return cnt;
James Smartda0436e2009-05-22 14:51:39 -04001136}
1137
1138/**
1139 * lpfc_hba_down_post - Wrapper func for hba down post routine
1140 * @phba: pointer to lpfc HBA data structure.
1141 *
1142 * This routine wraps the actual SLI3 or SLI4 routine for performing
1143 * uninitialization after the HBA is reset when bring down the SLI Layer.
1144 *
1145 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001146 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001147 * Any other value - error.
1148 **/
1149int
1150lpfc_hba_down_post(struct lpfc_hba *phba)
1151{
1152 return (*phba->lpfc_hba_down_post)(phba);
1153}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001154
James Smarte59058c2008-08-24 21:49:00 -04001155/**
James Smart3621a712009-04-06 18:47:14 -04001156 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001157 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1158 *
1159 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1160 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1161 * work-port-events bitmap and the worker thread is notified. This timeout
1162 * event will be used by the worker thread to invoke the actual timeout
1163 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1164 * be performed in the timeout handler and the HBA timeout event bit shall
1165 * be cleared by the worker thread after it has taken the event bitmap out.
1166 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001167static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001168lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001169{
1170 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001171 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001172 unsigned long iflag;
1173
Kees Cookf22eb4d2017-09-06 20:24:26 -07001174 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001175
1176 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001177 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001178 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1179 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001180 phba->pport->work_port_events |= WORKER_HB_TMO;
1181 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1182
James Smart93996272008-08-24 21:50:30 -04001183 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001184 if (!tmo_posted)
1185 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001186 return;
1187}
1188
James Smarte59058c2008-08-24 21:49:00 -04001189/**
James Smart19ca7602010-11-20 23:11:55 -05001190 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1191 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1192 *
1193 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1194 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1195 * work-port-events bitmap and the worker thread is notified. This timeout
1196 * event will be used by the worker thread to invoke the actual timeout
1197 * handler routine, lpfc_rrq_handler. Any periodical operations will
1198 * be performed in the timeout handler and the RRQ timeout event bit shall
1199 * be cleared by the worker thread after it has taken the event bitmap out.
1200 **/
1201static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001202lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001203{
1204 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001205 unsigned long iflag;
1206
Kees Cookf22eb4d2017-09-06 20:24:26 -07001207 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001208 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001209 if (!(phba->pport->load_flag & FC_UNLOADING))
1210 phba->hba_flag |= HBA_RRQ_ACTIVE;
1211 else
1212 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001213 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001214
1215 if (!(phba->pport->load_flag & FC_UNLOADING))
1216 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001217}
1218
1219/**
James Smart3621a712009-04-06 18:47:14 -04001220 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001221 * @phba: pointer to lpfc hba data structure.
1222 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1223 *
1224 * This is the callback function to the lpfc heart-beat mailbox command.
1225 * If configured, the lpfc driver issues the heart-beat mailbox command to
1226 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1227 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1228 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1229 * heart-beat outstanding state. Once the mailbox command comes back and
1230 * no error conditions detected, the heart-beat mailbox command timer is
1231 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1232 * state is cleared for the next heart-beat. If the timer expired with the
1233 * heart-beat outstanding state set, the driver will put the HBA offline.
1234 **/
James Smart858c9f62007-06-17 19:56:39 -05001235static void
1236lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1237{
1238 unsigned long drvr_flag;
1239
1240 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1241 phba->hb_outstanding = 0;
1242 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1243
James Smart93996272008-08-24 21:50:30 -04001244 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001245 mempool_free(pmboxq, phba->mbox_mem_pool);
1246 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1247 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001248 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001249 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001250 jiffies +
1251 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001252 return;
1253}
1254
James Smart32517fc2019-01-28 11:14:33 -08001255static void
1256lpfc_hb_eq_delay_work(struct work_struct *work)
1257{
1258 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1259 struct lpfc_hba, eq_delay_work);
1260 struct lpfc_eq_intr_info *eqi, *eqi_new;
1261 struct lpfc_queue *eq, *eq_next;
1262 unsigned char *eqcnt = NULL;
1263 uint32_t usdelay;
1264 int i;
James Smart8d34a592019-08-14 16:56:35 -07001265 bool update = false;
James Smart32517fc2019-01-28 11:14:33 -08001266
1267 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1268 return;
1269
1270 if (phba->link_state == LPFC_HBA_ERROR ||
1271 phba->pport->fc_flag & FC_OFFLINE_MODE)
1272 goto requeue;
1273
1274 eqcnt = kcalloc(num_possible_cpus(), sizeof(unsigned char),
1275 GFP_KERNEL);
1276 if (!eqcnt)
1277 goto requeue;
1278
James Smart8d34a592019-08-14 16:56:35 -07001279 if (phba->cfg_irq_chann > 1) {
1280 /* Loop thru all IRQ vectors */
1281 for (i = 0; i < phba->cfg_irq_chann; i++) {
1282 /* Get the EQ corresponding to the IRQ vector */
1283 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
1284 if (!eq)
1285 continue;
1286 if (eq->q_mode) {
1287 update = true;
1288 break;
1289 }
1290 if (eqcnt[eq->last_cpu] < 2)
1291 eqcnt[eq->last_cpu]++;
1292 }
1293 } else
1294 update = true;
James Smart32517fc2019-01-28 11:14:33 -08001295
1296 for_each_present_cpu(i) {
James Smart32517fc2019-01-28 11:14:33 -08001297 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
James Smart8d34a592019-08-14 16:56:35 -07001298 if (!update && eqcnt[i] < 2) {
1299 eqi->icnt = 0;
1300 continue;
1301 }
James Smart32517fc2019-01-28 11:14:33 -08001302
1303 usdelay = (eqi->icnt / LPFC_IMAX_THRESHOLD) *
1304 LPFC_EQ_DELAY_STEP;
1305 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1306 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1307
1308 eqi->icnt = 0;
1309
1310 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1311 if (eq->last_cpu != i) {
1312 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1313 eq->last_cpu);
1314 list_move_tail(&eq->cpu_list, &eqi_new->list);
1315 continue;
1316 }
1317 if (usdelay != eq->q_mode)
1318 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1319 usdelay);
1320 }
1321 }
1322
1323 kfree(eqcnt);
1324
1325requeue:
1326 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1327 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1328}
1329
James Smarte59058c2008-08-24 21:49:00 -04001330/**
James Smartc4908502019-01-28 11:14:28 -08001331 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1332 * @phba: pointer to lpfc hba data structure.
1333 *
1334 * For each heartbeat, this routine does some heuristic methods to adjust
1335 * XRI distribution. The goal is to fully utilize free XRIs.
1336 **/
1337static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1338{
1339 u32 i;
1340 u32 hwq_count;
1341
1342 hwq_count = phba->cfg_hdw_queue;
1343 for (i = 0; i < hwq_count; i++) {
1344 /* Adjust XRIs in private pool */
1345 lpfc_adjust_pvt_pool_count(phba, i);
1346
1347 /* Adjust high watermark */
1348 lpfc_adjust_high_watermark(phba, i);
1349
1350#ifdef LPFC_MXP_STAT
1351 /* Snapshot pbl, pvt and busy count */
1352 lpfc_snapshot_mxp(phba, i);
1353#endif
1354 }
1355}
1356
James Smarte59058c2008-08-24 21:49:00 -04001357/**
James Smart3621a712009-04-06 18:47:14 -04001358 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001359 * @phba: pointer to lpfc hba data structure.
1360 *
1361 * This is the actual HBA-timer timeout handler to be invoked by the worker
1362 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1363 * handler performs any periodic operations needed for the device. If such
1364 * periodic event has already been attended to either in the interrupt handler
1365 * or by processing slow-ring or fast-ring events within the HBA-timer
1366 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1367 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1368 * is configured and there is no heart-beat mailbox command outstanding, a
1369 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1370 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1371 * to offline.
1372 **/
James Smart858c9f62007-06-17 19:56:39 -05001373void
1374lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1375{
James Smart45ed1192009-10-02 15:17:02 -04001376 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001377 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001378 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001379 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001380 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001381 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001382
James Smartc4908502019-01-28 11:14:28 -08001383 if (phba->cfg_xri_rebalancing) {
1384 /* Multi-XRI pools handler */
1385 lpfc_hb_mxp_handler(phba);
1386 }
James Smart858c9f62007-06-17 19:56:39 -05001387
James Smart45ed1192009-10-02 15:17:02 -04001388 vports = lpfc_create_vport_work_array(phba);
1389 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001390 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001391 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001392 lpfc_fdmi_num_disc_check(vports[i]);
1393 }
James Smart45ed1192009-10-02 15:17:02 -04001394 lpfc_destroy_vport_work_array(phba, vports);
1395
James Smart858c9f62007-06-17 19:56:39 -05001396 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001397 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001398 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1399 return;
1400
1401 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001402
James Smart256ec0d2013-04-17 20:14:58 -04001403 if (time_after(phba->last_completion_time +
1404 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1405 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001406 spin_unlock_irq(&phba->pport->work_port_lock);
1407 if (!phba->hb_outstanding)
1408 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001409 jiffies +
1410 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001411 else
1412 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001413 jiffies +
1414 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001415 return;
1416 }
1417 spin_unlock_irq(&phba->pport->work_port_lock);
1418
James Smart0ff10d42008-01-11 01:52:36 -05001419 if (phba->elsbuf_cnt &&
1420 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1421 spin_lock_irq(&phba->hbalock);
1422 list_splice_init(&phba->elsbuf, &completions);
1423 phba->elsbuf_cnt = 0;
1424 phba->elsbuf_prev_cnt = 0;
1425 spin_unlock_irq(&phba->hbalock);
1426
1427 while (!list_empty(&completions)) {
1428 list_remove_head(&completions, buf_ptr,
1429 struct lpfc_dmabuf, list);
1430 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1431 kfree(buf_ptr);
1432 }
1433 }
1434 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1435
James Smart858c9f62007-06-17 19:56:39 -05001436 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001437 if (phba->cfg_enable_hba_heartbeat) {
1438 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001439 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1440 (list_empty(&psli->mboxq))) {
1441 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1442 GFP_KERNEL);
1443 if (!pmboxq) {
1444 mod_timer(&phba->hb_tmofunc,
1445 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001446 msecs_to_jiffies(1000 *
1447 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001448 return;
1449 }
James Smart13815c82008-01-11 01:52:48 -05001450
James Smartbc739052010-08-04 16:11:18 -04001451 lpfc_heart_beat(phba, pmboxq);
1452 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1453 pmboxq->vport = phba->pport;
1454 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1455 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001456
James Smartbc739052010-08-04 16:11:18 -04001457 if (retval != MBX_BUSY &&
1458 retval != MBX_SUCCESS) {
1459 mempool_free(pmboxq,
1460 phba->mbox_mem_pool);
1461 mod_timer(&phba->hb_tmofunc,
1462 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001463 msecs_to_jiffies(1000 *
1464 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001465 return;
1466 }
1467 phba->skipped_hb = 0;
1468 phba->hb_outstanding = 1;
1469 } else if (time_before_eq(phba->last_completion_time,
1470 phba->skipped_hb)) {
1471 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1472 "2857 Last completion time not "
1473 " updated in %d ms\n",
1474 jiffies_to_msecs(jiffies
1475 - phba->last_completion_time));
1476 } else
1477 phba->skipped_hb = jiffies;
1478
James Smart858c9f62007-06-17 19:56:39 -05001479 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001480 jiffies +
1481 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001482 return;
James Smart13815c82008-01-11 01:52:48 -05001483 } else {
1484 /*
1485 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001486 * we need to give the hb mailbox cmd a chance to
1487 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001488 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001489 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1490 "0459 Adapter heartbeat still out"
1491 "standing:last compl time was %d ms.\n",
1492 jiffies_to_msecs(jiffies
1493 - phba->last_completion_time));
1494 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001495 jiffies +
1496 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001497 }
James Smart4258e982015-12-16 18:11:58 -05001498 } else {
1499 mod_timer(&phba->hb_tmofunc,
1500 jiffies +
1501 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001502 }
1503}
1504
James Smarte59058c2008-08-24 21:49:00 -04001505/**
James Smart3621a712009-04-06 18:47:14 -04001506 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001507 * @phba: pointer to lpfc hba data structure.
1508 *
1509 * This routine is called to bring the HBA offline when HBA hardware error
1510 * other than Port Error 6 has been detected.
1511 **/
James Smart09372822008-01-11 01:52:54 -05001512static void
1513lpfc_offline_eratt(struct lpfc_hba *phba)
1514{
1515 struct lpfc_sli *psli = &phba->sli;
1516
1517 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001518 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001519 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001520 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001521
1522 lpfc_offline(phba);
1523 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001524 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001525 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001526 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001527 lpfc_hba_down_post(phba);
1528 lpfc_sli_brdready(phba, HS_MBRDY);
1529 lpfc_unblock_mgmt_io(phba);
1530 phba->link_state = LPFC_HBA_ERROR;
1531 return;
1532}
1533
James Smarte59058c2008-08-24 21:49:00 -04001534/**
James Smartda0436e2009-05-22 14:51:39 -04001535 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1536 * @phba: pointer to lpfc hba data structure.
1537 *
1538 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1539 * other than Port Error 6 has been detected.
1540 **/
James Smarta88dbb62013-04-17 20:18:39 -04001541void
James Smartda0436e2009-05-22 14:51:39 -04001542lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1543{
James Smart946727d2015-04-07 15:07:09 -04001544 spin_lock_irq(&phba->hbalock);
1545 phba->link_state = LPFC_HBA_ERROR;
1546 spin_unlock_irq(&phba->hbalock);
1547
James Smart618a5232012-06-12 13:54:36 -04001548 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001549 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001550 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001551 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001552}
1553
1554/**
James Smarta257bf92009-04-06 18:48:10 -04001555 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1556 * @phba: pointer to lpfc hba data structure.
1557 *
1558 * This routine is invoked to handle the deferred HBA hardware error
1559 * conditions. This type of error is indicated by HBA by setting ER1
1560 * and another ER bit in the host status register. The driver will
1561 * wait until the ER1 bit clears before handling the error condition.
1562 **/
1563static void
1564lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1565{
1566 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001567 struct lpfc_sli *psli = &phba->sli;
1568
James Smartf4b4c682009-05-22 14:53:12 -04001569 /* If the pci channel is offline, ignore possible errors,
1570 * since we cannot communicate with the pci card anyway.
1571 */
1572 if (pci_channel_offline(phba->pcidev)) {
1573 spin_lock_irq(&phba->hbalock);
1574 phba->hba_flag &= ~DEFER_ERATT;
1575 spin_unlock_irq(&phba->hbalock);
1576 return;
1577 }
1578
James Smarta257bf92009-04-06 18:48:10 -04001579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1580 "0479 Deferred Adapter Hardware Error "
1581 "Data: x%x x%x x%x\n",
1582 phba->work_hs,
1583 phba->work_status[0], phba->work_status[1]);
1584
1585 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001586 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001587 spin_unlock_irq(&phba->hbalock);
1588
1589
1590 /*
1591 * Firmware stops when it triggred erratt. That could cause the I/Os
1592 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1593 * SCSI layer retry it after re-establishing link.
1594 */
James Smartdb55fba2014-04-04 13:52:02 -04001595 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001596
1597 /*
1598 * There was a firmware error. Take the hba offline and then
1599 * attempt to restart it.
1600 */
James Smart618a5232012-06-12 13:54:36 -04001601 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001602 lpfc_offline(phba);
1603
1604 /* Wait for the ER1 bit to clear.*/
1605 while (phba->work_hs & HS_FFER1) {
1606 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001607 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1608 phba->work_hs = UNPLUG_ERR ;
1609 break;
1610 }
James Smarta257bf92009-04-06 18:48:10 -04001611 /* If driver is unloading let the worker thread continue */
1612 if (phba->pport->load_flag & FC_UNLOADING) {
1613 phba->work_hs = 0;
1614 break;
1615 }
1616 }
1617
1618 /*
1619 * This is to ptrotect against a race condition in which
1620 * first write to the host attention register clear the
1621 * host status register.
1622 */
1623 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1624 phba->work_hs = old_host_status & ~HS_FFER1;
1625
James Smart3772a992009-05-22 14:50:54 -04001626 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001627 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001628 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001629 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1630 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1631}
1632
James Smart3772a992009-05-22 14:50:54 -04001633static void
1634lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1635{
1636 struct lpfc_board_event_header board_event;
1637 struct Scsi_Host *shost;
1638
1639 board_event.event_type = FC_REG_BOARD_EVENT;
1640 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1641 shost = lpfc_shost_from_vport(phba->pport);
1642 fc_host_post_vendor_event(shost, fc_get_event_number(),
1643 sizeof(board_event),
1644 (char *) &board_event,
1645 LPFC_NL_VENDOR_ID);
1646}
1647
James Smarta257bf92009-04-06 18:48:10 -04001648/**
James Smart3772a992009-05-22 14:50:54 -04001649 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001650 * @phba: pointer to lpfc hba data structure.
1651 *
1652 * This routine is invoked to handle the following HBA hardware error
1653 * conditions:
1654 * 1 - HBA error attention interrupt
1655 * 2 - DMA ring index out of range
1656 * 3 - Mailbox command came back as unknown
1657 **/
James Smart3772a992009-05-22 14:50:54 -04001658static void
1659lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001660{
James Smart2e0fef82007-06-17 19:56:36 -05001661 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001662 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001663 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001664 unsigned long temperature;
1665 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001666 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001667
Linas Vepstas8d63f372007-02-14 14:28:36 -06001668 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001669 * since we cannot communicate with the pci card anyway.
1670 */
1671 if (pci_channel_offline(phba->pcidev)) {
1672 spin_lock_irq(&phba->hbalock);
1673 phba->hba_flag &= ~DEFER_ERATT;
1674 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001675 return;
James Smart3772a992009-05-22 14:50:54 -04001676 }
1677
James Smart13815c82008-01-11 01:52:48 -05001678 /* If resets are disabled then leave the HBA alone and return */
1679 if (!phba->cfg_enable_hba_reset)
1680 return;
dea31012005-04-17 16:05:31 -05001681
James Smartea2151b2008-09-07 11:52:10 -04001682 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001683 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001684
James Smarta257bf92009-04-06 18:48:10 -04001685 if (phba->hba_flag & DEFER_ERATT)
1686 lpfc_handle_deferred_eratt(phba);
1687
James Smartdcf2a4e2010-09-29 11:18:53 -04001688 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1689 if (phba->work_hs & HS_FFER6)
1690 /* Re-establishing Link */
1691 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1692 "1301 Re-establishing Link "
1693 "Data: x%x x%x x%x\n",
1694 phba->work_hs, phba->work_status[0],
1695 phba->work_status[1]);
1696 if (phba->work_hs & HS_FFER8)
1697 /* Device Zeroization */
1698 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1699 "2861 Host Authentication device "
1700 "zeroization Data:x%x x%x x%x\n",
1701 phba->work_hs, phba->work_status[0],
1702 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001703
James Smart92d7f7b2007-06-17 19:56:38 -05001704 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001705 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001706 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001707
1708 /*
1709 * Firmware stops when it triggled erratt with HS_FFER6.
1710 * That could cause the I/Os dropped by the firmware.
1711 * Error iocb (I/O) on txcmplq and let the SCSI layer
1712 * retry it after re-establishing link.
1713 */
James Smartdb55fba2014-04-04 13:52:02 -04001714 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001715
dea31012005-04-17 16:05:31 -05001716 /*
1717 * There was a firmware error. Take the hba offline and then
1718 * attempt to restart it.
1719 */
James Smart618a5232012-06-12 13:54:36 -04001720 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001721 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001722 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001723 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001724 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001725 return;
1726 }
James Smart46fa3112007-04-25 09:51:45 -04001727 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001728 } else if (phba->work_hs & HS_CRIT_TEMP) {
1729 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1730 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1731 temp_event_data.event_code = LPFC_CRIT_TEMP;
1732 temp_event_data.data = (uint32_t)temperature;
1733
1734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001735 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001736 "(%ld), taking this port offline "
1737 "Data: x%x x%x x%x\n",
1738 temperature, phba->work_hs,
1739 phba->work_status[0], phba->work_status[1]);
1740
1741 shost = lpfc_shost_from_vport(phba->pport);
1742 fc_host_post_vendor_event(shost, fc_get_event_number(),
1743 sizeof(temp_event_data),
1744 (char *) &temp_event_data,
1745 SCSI_NL_VID_TYPE_PCI
1746 | PCI_VENDOR_ID_EMULEX);
1747
James Smart7af67052007-10-27 13:38:11 -04001748 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001749 phba->over_temp_state = HBA_OVER_TEMP;
1750 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001751 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001752
dea31012005-04-17 16:05:31 -05001753 } else {
1754 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001755 * failure is a value other than FFER6. Do not call the offline
1756 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001757 */
1758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001759 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001760 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001761 phba->work_hs,
dea31012005-04-17 16:05:31 -05001762 phba->work_status[0], phba->work_status[1]);
1763
James Smartd2873e42006-08-18 17:46:43 -04001764 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001765 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001766 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001767 sizeof(event_data), (char *) &event_data,
1768 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1769
James Smart09372822008-01-11 01:52:54 -05001770 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001771 }
James Smart93996272008-08-24 21:50:30 -04001772 return;
dea31012005-04-17 16:05:31 -05001773}
1774
James Smarte59058c2008-08-24 21:49:00 -04001775/**
James Smart618a5232012-06-12 13:54:36 -04001776 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1777 * @phba: pointer to lpfc hba data structure.
1778 * @mbx_action: flag for mailbox shutdown action.
1779 *
1780 * This routine is invoked to perform an SLI4 port PCI function reset in
1781 * response to port status register polling attention. It waits for port
1782 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1783 * During this process, interrupt vectors are freed and later requested
1784 * for handling possible port resource change.
1785 **/
1786static int
James Smarte10b2022014-02-20 09:57:43 -05001787lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1788 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001789{
1790 int rc;
1791 uint32_t intr_mode;
1792
James Smart27d6ac02018-02-22 08:18:42 -08001793 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001794 LPFC_SLI_INTF_IF_TYPE_2) {
1795 /*
1796 * On error status condition, driver need to wait for port
1797 * ready before performing reset.
1798 */
1799 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001800 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001801 return rc;
James Smart618a5232012-06-12 13:54:36 -04001802 }
James Smart0e916ee2016-07-06 12:36:06 -07001803
James Smart65791f12016-07-06 12:35:56 -07001804 /* need reset: attempt for port recovery */
1805 if (en_rn_msg)
1806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1807 "2887 Reset Needed: Attempting Port "
1808 "Recovery...\n");
1809 lpfc_offline_prep(phba, mbx_action);
1810 lpfc_offline(phba);
1811 /* release interrupt for possible resource change */
1812 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001813 rc = lpfc_sli_brdrestart(phba);
1814 if (rc) {
1815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1816 "6309 Failed to restart board\n");
1817 return rc;
1818 }
James Smart65791f12016-07-06 12:35:56 -07001819 /* request and enable interrupt */
1820 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1821 if (intr_mode == LPFC_INTR_ERROR) {
1822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1823 "3175 Failed to enable interrupt\n");
1824 return -EIO;
1825 }
1826 phba->intr_mode = intr_mode;
1827 rc = lpfc_online(phba);
1828 if (rc == 0)
1829 lpfc_unblock_mgmt_io(phba);
1830
James Smart618a5232012-06-12 13:54:36 -04001831 return rc;
1832}
1833
1834/**
James Smartda0436e2009-05-22 14:51:39 -04001835 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1836 * @phba: pointer to lpfc hba data structure.
1837 *
1838 * This routine is invoked to handle the SLI4 HBA hardware error attention
1839 * conditions.
1840 **/
1841static void
1842lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1843{
1844 struct lpfc_vport *vport = phba->pport;
1845 uint32_t event_data;
1846 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001847 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001848 struct lpfc_register portstat_reg = {0};
1849 uint32_t reg_err1, reg_err2;
1850 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001851 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001852 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001853 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001854 struct lpfc_register portsmphr_reg;
1855 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001856
1857 /* If the pci channel is offline, ignore possible errors, since
1858 * we cannot communicate with the pci card anyway.
1859 */
James Smart32a93102019-03-12 16:30:13 -07001860 if (pci_channel_offline(phba->pcidev)) {
1861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1862 "3166 pci channel is offline\n");
1863 lpfc_sli4_offline_eratt(phba);
James Smartda0436e2009-05-22 14:51:39 -04001864 return;
James Smart32a93102019-03-12 16:30:13 -07001865 }
James Smartda0436e2009-05-22 14:51:39 -04001866
James Smart65791f12016-07-06 12:35:56 -07001867 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001868 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1869 switch (if_type) {
1870 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001871 pci_rd_rc1 = lpfc_readl(
1872 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1873 &uerrlo_reg);
1874 pci_rd_rc2 = lpfc_readl(
1875 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1876 &uemasklo_reg);
1877 /* consider PCI bus read error as pci_channel_offline */
1878 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1879 return;
James Smart65791f12016-07-06 12:35:56 -07001880 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1881 lpfc_sli4_offline_eratt(phba);
1882 return;
1883 }
1884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1885 "7623 Checking UE recoverable");
1886
1887 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1888 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1889 &portsmphr_reg.word0))
1890 continue;
1891
1892 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1893 &portsmphr_reg);
1894 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1895 LPFC_PORT_SEM_UE_RECOVERABLE)
1896 break;
1897 /*Sleep for 1Sec, before checking SEMAPHORE */
1898 msleep(1000);
1899 }
1900
1901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1902 "4827 smphr_port_status x%x : Waited %dSec",
1903 smphr_port_status, i);
1904
1905 /* Recoverable UE, reset the HBA device */
1906 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1907 LPFC_PORT_SEM_UE_RECOVERABLE) {
1908 for (i = 0; i < 20; i++) {
1909 msleep(1000);
1910 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1911 &portsmphr_reg.word0) &&
1912 (LPFC_POST_STAGE_PORT_READY ==
1913 bf_get(lpfc_port_smphr_port_status,
1914 &portsmphr_reg))) {
1915 rc = lpfc_sli4_port_sta_fn_reset(phba,
1916 LPFC_MBX_NO_WAIT, en_rn_msg);
1917 if (rc == 0)
1918 return;
1919 lpfc_printf_log(phba,
1920 KERN_ERR, LOG_INIT,
1921 "4215 Failed to recover UE");
1922 break;
1923 }
1924 }
1925 }
1926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1927 "7624 Firmware not ready: Failing UE recovery,"
1928 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001929 lpfc_sli4_offline_eratt(phba);
1930 break;
James Smart946727d2015-04-07 15:07:09 -04001931
James Smart2fcee4b2010-12-15 17:57:46 -05001932 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001933 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001934 pci_rd_rc1 = lpfc_readl(
1935 phba->sli4_hba.u.if_type2.STATUSregaddr,
1936 &portstat_reg.word0);
1937 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001938 if (pci_rd_rc1 == -EIO) {
1939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1940 "3151 PCI bus read access failure: x%x\n",
1941 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart32a93102019-03-12 16:30:13 -07001942 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001943 return;
James Smart6b5151f2012-01-18 16:24:06 -05001944 }
James Smart2e90f4b2011-12-13 13:22:37 -05001945 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1946 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001947 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1949 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001950 "taking port offline Data: x%x x%x\n",
1951 reg_err1, reg_err2);
1952
James Smart310429e2016-07-06 12:35:54 -07001953 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001954 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1955 temp_event_data.event_code = LPFC_CRIT_TEMP;
1956 temp_event_data.data = 0xFFFFFFFF;
1957
1958 shost = lpfc_shost_from_vport(phba->pport);
1959 fc_host_post_vendor_event(shost, fc_get_event_number(),
1960 sizeof(temp_event_data),
1961 (char *)&temp_event_data,
1962 SCSI_NL_VID_TYPE_PCI
1963 | PCI_VENDOR_ID_EMULEX);
1964
James Smart2fcee4b2010-12-15 17:57:46 -05001965 spin_lock_irq(&phba->hbalock);
1966 phba->over_temp_state = HBA_OVER_TEMP;
1967 spin_unlock_irq(&phba->hbalock);
1968 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001969 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001970 }
James Smart2e90f4b2011-12-13 13:22:37 -05001971 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001972 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001973 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001974 "3143 Port Down: Firmware Update "
1975 "Detected\n");
1976 en_rn_msg = false;
1977 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001978 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1980 "3144 Port Down: Debug Dump\n");
1981 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1982 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1984 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001985
James Smart946727d2015-04-07 15:07:09 -04001986 /* If resets are disabled then leave the HBA alone and return */
1987 if (!phba->cfg_enable_hba_reset)
1988 return;
1989
James Smart618a5232012-06-12 13:54:36 -04001990 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001991 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1992 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001993 if (rc == 0) {
1994 /* don't report event on forced debug dump */
1995 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1996 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1997 return;
1998 else
1999 break;
James Smart2fcee4b2010-12-15 17:57:46 -05002000 }
James Smart618a5232012-06-12 13:54:36 -04002001 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05002002 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2003 "3152 Unrecoverable error, bring the port "
2004 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05002005 lpfc_sli4_offline_eratt(phba);
2006 break;
2007 case LPFC_SLI_INTF_IF_TYPE_1:
2008 default:
2009 break;
2010 }
James Smart2e90f4b2011-12-13 13:22:37 -05002011 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2012 "3123 Report dump event to upper layer\n");
2013 /* Send an internal error event to mgmt application */
2014 lpfc_board_errevt_to_mgmt(phba);
2015
2016 event_data = FC_REG_DUMP_EVENT;
2017 shost = lpfc_shost_from_vport(vport);
2018 fc_host_post_vendor_event(shost, fc_get_event_number(),
2019 sizeof(event_data), (char *) &event_data,
2020 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002021}
2022
2023/**
2024 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2025 * @phba: pointer to lpfc HBA data structure.
2026 *
2027 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2028 * routine from the API jump table function pointer from the lpfc_hba struct.
2029 *
2030 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002031 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002032 * Any other value - error.
2033 **/
2034void
2035lpfc_handle_eratt(struct lpfc_hba *phba)
2036{
2037 (*phba->lpfc_handle_eratt)(phba);
2038}
2039
2040/**
James Smart3621a712009-04-06 18:47:14 -04002041 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002042 * @phba: pointer to lpfc hba data structure.
2043 *
2044 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002045 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002046 **/
dea31012005-04-17 16:05:31 -05002047void
James Smart2e0fef82007-06-17 19:56:36 -05002048lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002049{
James Smart2e0fef82007-06-17 19:56:36 -05002050 struct lpfc_vport *vport = phba->pport;
2051 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002052 LPFC_MBOXQ_t *pmb;
2053 volatile uint32_t control;
2054 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002055 int rc = 0;
dea31012005-04-17 16:05:31 -05002056
2057 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002058 if (!pmb) {
2059 rc = 1;
dea31012005-04-17 16:05:31 -05002060 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002061 }
dea31012005-04-17 16:05:31 -05002062
2063 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002064 if (!mp) {
2065 rc = 2;
dea31012005-04-17 16:05:31 -05002066 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002067 }
dea31012005-04-17 16:05:31 -05002068
2069 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002070 if (!mp->virt) {
2071 rc = 3;
dea31012005-04-17 16:05:31 -05002072 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002073 }
dea31012005-04-17 16:05:31 -05002074
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002075 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002076 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002077
2078 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002079 lpfc_read_topology(phba, pmb, mp);
2080 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002081 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002082 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002083 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002084 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002085 if (rc == MBX_NOT_FINISHED) {
2086 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002087 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002088 }
dea31012005-04-17 16:05:31 -05002089
2090 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002091 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002092 writel(HA_LATT, phba->HAregaddr);
2093 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002094 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002095
2096 return;
2097
James Smart14691152006-12-02 13:34:28 -05002098lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002099 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002101lpfc_handle_latt_free_mp:
2102 kfree(mp);
2103lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002104 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002105lpfc_handle_latt_err_exit:
2106 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002107 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002108 psli->sli_flag |= LPFC_PROCESS_LA;
2109 control = readl(phba->HCregaddr);
2110 control |= HC_LAINT_ENA;
2111 writel(control, phba->HCregaddr);
2112 readl(phba->HCregaddr); /* flush */
2113
2114 /* Clear Link Attention in HA REG */
2115 writel(HA_LATT, phba->HAregaddr);
2116 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002117 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002118 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002119 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002120
James Smart09372822008-01-11 01:52:54 -05002121 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2122 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002123
2124 return;
2125}
2126
James Smarte59058c2008-08-24 21:49:00 -04002127/**
James Smart3621a712009-04-06 18:47:14 -04002128 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002129 * @phba: pointer to lpfc hba data structure.
2130 * @vpd: pointer to the vital product data.
2131 * @len: length of the vital product data in bytes.
2132 *
2133 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2134 * an array of characters. In this routine, the ModelName, ProgramType, and
2135 * ModelDesc, etc. fields of the phba data structure will be populated.
2136 *
2137 * Return codes
2138 * 0 - pointer to the VPD passed in is NULL
2139 * 1 - success
2140 **/
James Smart3772a992009-05-22 14:50:54 -04002141int
James Smart2e0fef82007-06-17 19:56:36 -05002142lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002143{
2144 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002145 int Length;
dea31012005-04-17 16:05:31 -05002146 int i, j;
2147 int finished = 0;
2148 int index = 0;
2149
2150 if (!vpd)
2151 return 0;
2152
2153 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002154 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002155 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002156 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2157 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002158 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002159 switch (vpd[index]) {
2160 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002161 case 0x91:
dea31012005-04-17 16:05:31 -05002162 index += 1;
2163 lenlo = vpd[index];
2164 index += 1;
2165 lenhi = vpd[index];
2166 index += 1;
2167 i = ((((unsigned short)lenhi) << 8) + lenlo);
2168 index += i;
2169 break;
2170 case 0x90:
2171 index += 1;
2172 lenlo = vpd[index];
2173 index += 1;
2174 lenhi = vpd[index];
2175 index += 1;
2176 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002177 if (Length > len - index)
2178 Length = len - index;
dea31012005-04-17 16:05:31 -05002179 while (Length > 0) {
2180 /* Look for Serial Number */
2181 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2182 index += 2;
2183 i = vpd[index];
2184 index += 1;
2185 j = 0;
2186 Length -= (3+i);
2187 while(i--) {
2188 phba->SerialNumber[j++] = vpd[index++];
2189 if (j == 31)
2190 break;
2191 }
2192 phba->SerialNumber[j] = 0;
2193 continue;
2194 }
2195 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2196 phba->vpd_flag |= VPD_MODEL_DESC;
2197 index += 2;
2198 i = vpd[index];
2199 index += 1;
2200 j = 0;
2201 Length -= (3+i);
2202 while(i--) {
2203 phba->ModelDesc[j++] = vpd[index++];
2204 if (j == 255)
2205 break;
2206 }
2207 phba->ModelDesc[j] = 0;
2208 continue;
2209 }
2210 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2211 phba->vpd_flag |= VPD_MODEL_NAME;
2212 index += 2;
2213 i = vpd[index];
2214 index += 1;
2215 j = 0;
2216 Length -= (3+i);
2217 while(i--) {
2218 phba->ModelName[j++] = vpd[index++];
2219 if (j == 79)
2220 break;
2221 }
2222 phba->ModelName[j] = 0;
2223 continue;
2224 }
2225 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2226 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2227 index += 2;
2228 i = vpd[index];
2229 index += 1;
2230 j = 0;
2231 Length -= (3+i);
2232 while(i--) {
2233 phba->ProgramType[j++] = vpd[index++];
2234 if (j == 255)
2235 break;
2236 }
2237 phba->ProgramType[j] = 0;
2238 continue;
2239 }
2240 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2241 phba->vpd_flag |= VPD_PORT;
2242 index += 2;
2243 i = vpd[index];
2244 index += 1;
2245 j = 0;
2246 Length -= (3+i);
2247 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002248 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2249 (phba->sli4_hba.pport_name_sta ==
2250 LPFC_SLI4_PPNAME_GET)) {
2251 j++;
2252 index++;
2253 } else
2254 phba->Port[j++] = vpd[index++];
2255 if (j == 19)
2256 break;
dea31012005-04-17 16:05:31 -05002257 }
James Smartcd1c8302011-10-10 21:33:25 -04002258 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2259 (phba->sli4_hba.pport_name_sta ==
2260 LPFC_SLI4_PPNAME_NON))
2261 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002262 continue;
2263 }
2264 else {
2265 index += 2;
2266 i = vpd[index];
2267 index += 1;
2268 index += i;
2269 Length -= (3 + i);
2270 }
2271 }
2272 finished = 0;
2273 break;
2274 case 0x78:
2275 finished = 1;
2276 break;
2277 default:
2278 index ++;
2279 break;
2280 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002281 }
dea31012005-04-17 16:05:31 -05002282
2283 return(1);
2284}
2285
James Smarte59058c2008-08-24 21:49:00 -04002286/**
James Smart3621a712009-04-06 18:47:14 -04002287 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002288 * @phba: pointer to lpfc hba data structure.
2289 * @mdp: pointer to the data structure to hold the derived model name.
2290 * @descp: pointer to the data structure to hold the derived description.
2291 *
2292 * This routine retrieves HBA's description based on its registered PCI device
2293 * ID. The @descp passed into this function points to an array of 256 chars. It
2294 * shall be returned with the model name, maximum speed, and the host bus type.
2295 * The @mdp passed into this function points to an array of 80 chars. When the
2296 * function returns, the @mdp will be filled with the model name.
2297 **/
dea31012005-04-17 16:05:31 -05002298static void
James Smart2e0fef82007-06-17 19:56:36 -05002299lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002300{
2301 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002302 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002303 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002304 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002305 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002306 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002307 char *name;
2308 char *bus;
2309 char *function;
2310 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002311
2312 if (mdp && mdp[0] != '\0'
2313 && descp && descp[0] != '\0')
2314 return;
2315
James Smartfbd8a6b2018-02-22 08:18:45 -08002316 if (phba->lmt & LMT_64Gb)
2317 max_speed = 64;
2318 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002319 max_speed = 32;
2320 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002321 max_speed = 16;
2322 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002323 max_speed = 10;
2324 else if (phba->lmt & LMT_8Gb)
2325 max_speed = 8;
2326 else if (phba->lmt & LMT_4Gb)
2327 max_speed = 4;
2328 else if (phba->lmt & LMT_2Gb)
2329 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002330 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002331 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002332 else
2333 max_speed = 0;
dea31012005-04-17 16:05:31 -05002334
2335 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002336
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002337 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002338 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002339 m = (typeof(m)){"LP6000", "PCI",
2340 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002341 break;
dea31012005-04-17 16:05:31 -05002342 case PCI_DEVICE_ID_SUPERFLY:
2343 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002344 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002345 else
James Smart12222f42014-05-21 08:05:19 -04002346 m = (typeof(m)){"LP7000E", "PCI", ""};
2347 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002348 break;
2349 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002350 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002351 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002352 break;
2353 case PCI_DEVICE_ID_CENTAUR:
2354 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002355 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002356 else
James Smart12222f42014-05-21 08:05:19 -04002357 m = (typeof(m)){"LP9000", "PCI", ""};
2358 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002359 break;
2360 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002361 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002362 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002363 break;
2364 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002365 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002366 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002367 break;
2368 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002369 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002370 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002371 break;
2372 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002373 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002374 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002375 break;
2376 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002377 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002378 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002379 break;
2380 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002381 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002382 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002383 break;
2384 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002385 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002386 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002387 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002388 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002389 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002390 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002391 break;
2392 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002393 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002394 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002395 break;
2396 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002397 m = (typeof(m)){"LPe1000", "PCIe",
2398 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002399 break;
2400 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002401 m = (typeof(m)){"LPe1000-SP", "PCIe",
2402 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002403 break;
2404 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002405 m = (typeof(m)){"LPe1002-SP", "PCIe",
2406 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002407 break;
dea31012005-04-17 16:05:31 -05002408 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002409 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002410 break;
2411 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002412 m = (typeof(m)){"LP111", "PCI-X2",
2413 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002414 break;
2415 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002416 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002417 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002418 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002419 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002420 break;
2421 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002422 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002423 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002424 break;
dea31012005-04-17 16:05:31 -05002425 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002426 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002427 break;
2428 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002429 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002430 break;
2431 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002432 m = (typeof(m)){"LP101", "PCI-X",
2433 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002434 break;
2435 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002436 m = (typeof(m)){"LP10000-S", "PCI",
2437 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002438 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002439 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002440 m = (typeof(m)){"LP11000-S", "PCI-X2",
2441 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002442 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002443 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002444 m = (typeof(m)){"LPe11000-S", "PCIe",
2445 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002446 break;
James Smartb87eab32007-04-25 09:53:28 -04002447 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002448 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002449 break;
2450 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002451 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002452 break;
2453 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002454 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002455 break;
2456 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002457 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002458 break;
2459 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002460 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002461 break;
2462 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002463 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002464 break;
James Smart84774a42008-08-24 21:50:06 -04002465 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002466 m = (typeof(m)){"LP21000", "PCIe",
2467 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002468 GE = 1;
2469 break;
2470 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002471 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002472 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002473 break;
2474 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002475 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002476 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002477 break;
2478 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002479 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002480 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002481 break;
James Smartda0436e2009-05-22 14:51:39 -04002482 case PCI_DEVICE_ID_TIGERSHARK:
2483 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002484 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002485 break;
James Smarta747c9c2009-11-18 15:41:10 -05002486 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002487 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002488 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2489 break;
2490 case PCI_DEVICE_ID_FALCON:
2491 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2492 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002493 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002494 case PCI_DEVICE_ID_BALIUS:
2495 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002496 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002497 break;
James Smart085c6472010-11-20 23:11:37 -05002498 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002499 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002500 break;
James Smart12222f42014-05-21 08:05:19 -04002501 case PCI_DEVICE_ID_LANCER_FC_VF:
2502 m = (typeof(m)){"LPe16000", "PCIe",
2503 "Obsolete, Unsupported Fibre Channel Adapter"};
2504 break;
James Smart085c6472010-11-20 23:11:37 -05002505 case PCI_DEVICE_ID_LANCER_FCOE:
2506 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002507 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002508 break;
James Smart12222f42014-05-21 08:05:19 -04002509 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2510 oneConnect = 1;
2511 m = (typeof(m)){"OCe15100", "PCIe",
2512 "Obsolete, Unsupported FCoE"};
2513 break;
James Smartd38dd522015-08-31 16:48:17 -04002514 case PCI_DEVICE_ID_LANCER_G6_FC:
2515 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2516 break;
James Smartc238b9b2018-02-22 08:18:44 -08002517 case PCI_DEVICE_ID_LANCER_G7_FC:
2518 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2519 break;
James Smartf8cafd32012-08-03 12:42:51 -04002520 case PCI_DEVICE_ID_SKYHAWK:
2521 case PCI_DEVICE_ID_SKYHAWK_VF:
2522 oneConnect = 1;
2523 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2524 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002525 default:
James Smarta747c9c2009-11-18 15:41:10 -05002526 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002527 break;
dea31012005-04-17 16:05:31 -05002528 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002529
2530 if (mdp && mdp[0] == '\0')
2531 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002532 /*
2533 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002534 * and we put the port number on the end
2535 */
2536 if (descp && descp[0] == '\0') {
2537 if (oneConnect)
2538 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002539 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002540 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002541 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002542 else if (max_speed == 0)
2543 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002544 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002545 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002546 else
2547 snprintf(descp, 255,
2548 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002549 m.name, max_speed, (GE) ? "GE" : "Gb",
2550 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002551 }
dea31012005-04-17 16:05:31 -05002552}
2553
James Smarte59058c2008-08-24 21:49:00 -04002554/**
James Smart3621a712009-04-06 18:47:14 -04002555 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002556 * @phba: pointer to lpfc hba data structure.
2557 * @pring: pointer to a IOCB ring.
2558 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2559 *
2560 * This routine posts a given number of IOCBs with the associated DMA buffer
2561 * descriptors specified by the cnt argument to the given IOCB ring.
2562 *
2563 * Return codes
2564 * The number of IOCBs NOT able to be posted to the IOCB ring.
2565 **/
dea31012005-04-17 16:05:31 -05002566int
James Smart495a7142008-06-14 22:52:59 -04002567lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002568{
2569 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002570 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002571 struct lpfc_dmabuf *mp1, *mp2;
2572
2573 cnt += pring->missbufcnt;
2574
2575 /* While there are buffers to post */
2576 while (cnt > 0) {
2577 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002578 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002579 if (iocb == NULL) {
2580 pring->missbufcnt = cnt;
2581 return cnt;
2582 }
dea31012005-04-17 16:05:31 -05002583 icmd = &iocb->iocb;
2584
2585 /* 2 buffers can be posted per command */
2586 /* Allocate buffer to post */
2587 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2588 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002589 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2590 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002591 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002592 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002593 pring->missbufcnt = cnt;
2594 return cnt;
2595 }
2596
2597 INIT_LIST_HEAD(&mp1->list);
2598 /* Allocate buffer to post */
2599 if (cnt > 1) {
2600 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2601 if (mp2)
2602 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2603 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002604 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002605 kfree(mp2);
dea31012005-04-17 16:05:31 -05002606 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2607 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002608 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002609 pring->missbufcnt = cnt;
2610 return cnt;
2611 }
2612
2613 INIT_LIST_HEAD(&mp2->list);
2614 } else {
2615 mp2 = NULL;
2616 }
2617
2618 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2619 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2620 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2621 icmd->ulpBdeCount = 1;
2622 cnt--;
2623 if (mp2) {
2624 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2625 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2626 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2627 cnt--;
2628 icmd->ulpBdeCount = 2;
2629 }
2630
2631 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2632 icmd->ulpLe = 1;
2633
James Smart3772a992009-05-22 14:50:54 -04002634 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2635 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002636 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2637 kfree(mp1);
2638 cnt++;
2639 if (mp2) {
2640 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2641 kfree(mp2);
2642 cnt++;
2643 }
James Bottomley604a3e32005-10-29 10:28:33 -05002644 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002645 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002646 return cnt;
2647 }
dea31012005-04-17 16:05:31 -05002648 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002649 if (mp2)
dea31012005-04-17 16:05:31 -05002650 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002651 }
2652 pring->missbufcnt = 0;
2653 return 0;
2654}
2655
James Smarte59058c2008-08-24 21:49:00 -04002656/**
James Smart3621a712009-04-06 18:47:14 -04002657 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002658 * @phba: pointer to lpfc hba data structure.
2659 *
2660 * This routine posts initial receive IOCB buffers to the ELS ring. The
2661 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002662 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002663 *
2664 * Return codes
2665 * 0 - success (currently always success)
2666 **/
dea31012005-04-17 16:05:31 -05002667static int
James Smart2e0fef82007-06-17 19:56:36 -05002668lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002669{
2670 struct lpfc_sli *psli = &phba->sli;
2671
2672 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002673 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002674 /* Ring 2 - FCP no buffers needed */
2675
2676 return 0;
2677}
2678
2679#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2680
James Smarte59058c2008-08-24 21:49:00 -04002681/**
James Smart3621a712009-04-06 18:47:14 -04002682 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002683 * @HashResultPointer: pointer to an array as hash table.
2684 *
2685 * This routine sets up the initial values to the array of hash table entries
2686 * for the LC HBAs.
2687 **/
dea31012005-04-17 16:05:31 -05002688static void
2689lpfc_sha_init(uint32_t * HashResultPointer)
2690{
2691 HashResultPointer[0] = 0x67452301;
2692 HashResultPointer[1] = 0xEFCDAB89;
2693 HashResultPointer[2] = 0x98BADCFE;
2694 HashResultPointer[3] = 0x10325476;
2695 HashResultPointer[4] = 0xC3D2E1F0;
2696}
2697
James Smarte59058c2008-08-24 21:49:00 -04002698/**
James Smart3621a712009-04-06 18:47:14 -04002699 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002700 * @HashResultPointer: pointer to an initial/result hash table.
2701 * @HashWorkingPointer: pointer to an working hash table.
2702 *
2703 * This routine iterates an initial hash table pointed by @HashResultPointer
2704 * with the values from the working hash table pointeed by @HashWorkingPointer.
2705 * The results are putting back to the initial hash table, returned through
2706 * the @HashResultPointer as the result hash table.
2707 **/
dea31012005-04-17 16:05:31 -05002708static void
2709lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2710{
2711 int t;
2712 uint32_t TEMP;
2713 uint32_t A, B, C, D, E;
2714 t = 16;
2715 do {
2716 HashWorkingPointer[t] =
2717 S(1,
2718 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2719 8] ^
2720 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2721 } while (++t <= 79);
2722 t = 0;
2723 A = HashResultPointer[0];
2724 B = HashResultPointer[1];
2725 C = HashResultPointer[2];
2726 D = HashResultPointer[3];
2727 E = HashResultPointer[4];
2728
2729 do {
2730 if (t < 20) {
2731 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2732 } else if (t < 40) {
2733 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2734 } else if (t < 60) {
2735 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2736 } else {
2737 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2738 }
2739 TEMP += S(5, A) + E + HashWorkingPointer[t];
2740 E = D;
2741 D = C;
2742 C = S(30, B);
2743 B = A;
2744 A = TEMP;
2745 } while (++t <= 79);
2746
2747 HashResultPointer[0] += A;
2748 HashResultPointer[1] += B;
2749 HashResultPointer[2] += C;
2750 HashResultPointer[3] += D;
2751 HashResultPointer[4] += E;
2752
2753}
2754
James Smarte59058c2008-08-24 21:49:00 -04002755/**
James Smart3621a712009-04-06 18:47:14 -04002756 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002757 * @RandomChallenge: pointer to the entry of host challenge random number array.
2758 * @HashWorking: pointer to the entry of the working hash array.
2759 *
2760 * This routine calculates the working hash array referred by @HashWorking
2761 * from the challenge random numbers associated with the host, referred by
2762 * @RandomChallenge. The result is put into the entry of the working hash
2763 * array and returned by reference through @HashWorking.
2764 **/
dea31012005-04-17 16:05:31 -05002765static void
2766lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2767{
2768 *HashWorking = (*RandomChallenge ^ *HashWorking);
2769}
2770
James Smarte59058c2008-08-24 21:49:00 -04002771/**
James Smart3621a712009-04-06 18:47:14 -04002772 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002773 * @phba: pointer to lpfc hba data structure.
2774 * @hbainit: pointer to an array of unsigned 32-bit integers.
2775 *
2776 * This routine performs the special handling for LC HBA initialization.
2777 **/
dea31012005-04-17 16:05:31 -05002778void
2779lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2780{
2781 int t;
2782 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002783 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002784
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002785 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002786 if (!HashWorking)
2787 return;
2788
dea31012005-04-17 16:05:31 -05002789 HashWorking[0] = HashWorking[78] = *pwwnn++;
2790 HashWorking[1] = HashWorking[79] = *pwwnn;
2791
2792 for (t = 0; t < 7; t++)
2793 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2794
2795 lpfc_sha_init(hbainit);
2796 lpfc_sha_iterate(hbainit, HashWorking);
2797 kfree(HashWorking);
2798}
2799
James Smarte59058c2008-08-24 21:49:00 -04002800/**
James Smart3621a712009-04-06 18:47:14 -04002801 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002802 * @vport: pointer to a virtual N_Port data structure.
2803 *
2804 * This routine performs the necessary cleanups before deleting the @vport.
2805 * It invokes the discovery state machine to perform necessary state
2806 * transitions and to release the ndlps associated with the @vport. Note,
2807 * the physical port is treated as @vport 0.
2808 **/
James Smart87af33f2007-10-27 13:37:43 -04002809void
James Smart2e0fef82007-06-17 19:56:36 -05002810lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002811{
James Smart87af33f2007-10-27 13:37:43 -04002812 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002813 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002814 int i = 0;
dea31012005-04-17 16:05:31 -05002815
James Smart87af33f2007-10-27 13:37:43 -04002816 if (phba->link_state > LPFC_LINK_DOWN)
2817 lpfc_port_link_failure(vport);
2818
2819 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002820 if (!NLP_CHK_NODE_ACT(ndlp)) {
2821 ndlp = lpfc_enable_node(vport, ndlp,
2822 NLP_STE_UNUSED_NODE);
2823 if (!ndlp)
2824 continue;
2825 spin_lock_irq(&phba->ndlp_lock);
2826 NLP_SET_FREE_REQ(ndlp);
2827 spin_unlock_irq(&phba->ndlp_lock);
2828 /* Trigger the release of the ndlp memory */
2829 lpfc_nlp_put(ndlp);
2830 continue;
2831 }
2832 spin_lock_irq(&phba->ndlp_lock);
2833 if (NLP_CHK_FREE_REQ(ndlp)) {
2834 /* The ndlp should not be in memory free mode already */
2835 spin_unlock_irq(&phba->ndlp_lock);
2836 continue;
2837 } else
2838 /* Indicate request for freeing ndlp memory */
2839 NLP_SET_FREE_REQ(ndlp);
2840 spin_unlock_irq(&phba->ndlp_lock);
2841
James Smart58da1ff2008-04-07 10:15:56 -04002842 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2843 ndlp->nlp_DID == Fabric_DID) {
2844 /* Just free up ndlp with Fabric_DID for vports */
2845 lpfc_nlp_put(ndlp);
2846 continue;
2847 }
2848
James Smarteff4a012012-01-18 16:25:25 -05002849 /* take care of nodes in unused state before the state
2850 * machine taking action.
2851 */
2852 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2853 lpfc_nlp_put(ndlp);
2854 continue;
2855 }
2856
James Smart87af33f2007-10-27 13:37:43 -04002857 if (ndlp->nlp_type & NLP_FABRIC)
2858 lpfc_disc_state_machine(vport, ndlp, NULL,
2859 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002860
James Smart87af33f2007-10-27 13:37:43 -04002861 lpfc_disc_state_machine(vport, ndlp, NULL,
2862 NLP_EVT_DEVICE_RM);
2863 }
2864
James Smarta8adb832007-10-27 13:37:53 -04002865 /* At this point, ALL ndlp's should be gone
2866 * because of the previous NLP_EVT_DEVICE_RM.
2867 * Lets wait for this to happen, if needed.
2868 */
James Smart87af33f2007-10-27 13:37:43 -04002869 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002870 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002871 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002872 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002873 list_for_each_entry_safe(ndlp, next_ndlp,
2874 &vport->fc_nodes, nlp_listp) {
2875 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2876 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002877 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002878 "usgmap:x%x refcnt:%d\n",
2879 ndlp->nlp_DID, (void *)ndlp,
2880 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002881 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002882 }
James Smarta8adb832007-10-27 13:37:53 -04002883 break;
James Smart87af33f2007-10-27 13:37:43 -04002884 }
James Smarta8adb832007-10-27 13:37:53 -04002885
2886 /* Wait for any activity on ndlps to settle */
2887 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002888 }
James Smart1151e3e2011-02-16 12:39:35 -05002889 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002890}
2891
James Smarte59058c2008-08-24 21:49:00 -04002892/**
James Smart3621a712009-04-06 18:47:14 -04002893 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002894 * @vport: pointer to a virtual N_Port data structure.
2895 *
2896 * This routine stops all the timers associated with a @vport. This function
2897 * is invoked before disabling or deleting a @vport. Note that the physical
2898 * port is treated as @vport 0.
2899 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002900void
2901lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002902{
James Smart92d7f7b2007-06-17 19:56:38 -05002903 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002904 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002905 lpfc_can_disctmo(vport);
2906 return;
dea31012005-04-17 16:05:31 -05002907}
2908
James Smarte59058c2008-08-24 21:49:00 -04002909/**
James Smartecfd03c2010-02-12 14:41:27 -05002910 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2911 * @phba: pointer to lpfc hba data structure.
2912 *
2913 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2914 * caller of this routine should already hold the host lock.
2915 **/
2916void
2917__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2918{
James Smart5ac6b302010-10-22 11:05:36 -04002919 /* Clear pending FCF rediscovery wait flag */
2920 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2921
James Smartecfd03c2010-02-12 14:41:27 -05002922 /* Now, try to stop the timer */
2923 del_timer(&phba->fcf.redisc_wait);
2924}
2925
2926/**
2927 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2928 * @phba: pointer to lpfc hba data structure.
2929 *
2930 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2931 * checks whether the FCF rediscovery wait timer is pending with the host
2932 * lock held before proceeding with disabling the timer and clearing the
2933 * wait timer pendig flag.
2934 **/
2935void
2936lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2937{
2938 spin_lock_irq(&phba->hbalock);
2939 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2940 /* FCF rediscovery timer already fired or stopped */
2941 spin_unlock_irq(&phba->hbalock);
2942 return;
2943 }
2944 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002945 /* Clear failover in progress flags */
2946 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002947 spin_unlock_irq(&phba->hbalock);
2948}
2949
2950/**
James Smart3772a992009-05-22 14:50:54 -04002951 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002952 * @phba: pointer to lpfc hba data structure.
2953 *
2954 * This routine stops all the timers associated with a HBA. This function is
2955 * invoked before either putting a HBA offline or unloading the driver.
2956 **/
James Smart3772a992009-05-22 14:50:54 -04002957void
2958lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002959{
James Smartcdb42be2019-01-28 11:14:21 -08002960 if (phba->pport)
2961 lpfc_stop_vport_timers(phba->pport);
James Smart32517fc2019-01-28 11:14:33 -08002962 cancel_delayed_work_sync(&phba->eq_delay_work);
James Smart2e0fef82007-06-17 19:56:36 -05002963 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002964 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002965 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002966 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002967 if (phba->sli_rev == LPFC_SLI_REV4) {
2968 del_timer_sync(&phba->rrq_tmr);
2969 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2970 }
James Smart3772a992009-05-22 14:50:54 -04002971 phba->hb_outstanding = 0;
2972
2973 switch (phba->pci_dev_grp) {
2974 case LPFC_PCI_DEV_LP:
2975 /* Stop any LightPulse device specific driver timers */
2976 del_timer_sync(&phba->fcp_poll_timer);
2977 break;
2978 case LPFC_PCI_DEV_OC:
Paul Walmsleycc0e5f12019-07-11 20:52:33 -07002979 /* Stop any OneConnect device specific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002980 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002981 break;
2982 default:
2983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2984 "0297 Invalid device group (x%x)\n",
2985 phba->pci_dev_grp);
2986 break;
2987 }
James Smart2e0fef82007-06-17 19:56:36 -05002988 return;
dea31012005-04-17 16:05:31 -05002989}
2990
James Smarte59058c2008-08-24 21:49:00 -04002991/**
James Smart3621a712009-04-06 18:47:14 -04002992 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002993 * @phba: pointer to lpfc hba data structure.
2994 *
2995 * This routine marks a HBA's management interface as blocked. Once the HBA's
2996 * management interface is marked as blocked, all the user space access to
2997 * the HBA, whether they are from sysfs interface or libdfc interface will
2998 * all be blocked. The HBA is set to block the management interface when the
2999 * driver prepares the HBA interface for online or offline.
3000 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01003001static void
James Smart618a5232012-06-12 13:54:36 -04003002lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01003003{
3004 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04003005 uint8_t actcmd = MBX_HEARTBEAT;
3006 unsigned long timeout;
3007
Adrian Bunka6ababd2007-11-05 18:07:33 +01003008 spin_lock_irqsave(&phba->hbalock, iflag);
3009 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04003010 spin_unlock_irqrestore(&phba->hbalock, iflag);
3011 if (mbx_action == LPFC_MBX_NO_WAIT)
3012 return;
3013 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3014 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003015 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04003016 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04003017 /* Determine how long we might wait for the active mailbox
3018 * command to be gracefully completed by firmware.
3019 */
3020 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3021 phba->sli.mbox_active) * 1000) + jiffies;
3022 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003023 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003024
James Smart6e7288d2010-06-07 15:23:35 -04003025 /* Wait for the outstnading mailbox command to complete */
3026 while (phba->sli.mbox_active) {
3027 /* Check active mailbox complete status every 2ms */
3028 msleep(2);
3029 if (time_after(jiffies, timeout)) {
3030 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3031 "2813 Mgmt IO is Blocked %x "
3032 "- mbox cmd %x still active\n",
3033 phba->sli.sli_flag, actcmd);
3034 break;
3035 }
3036 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003037}
3038
James Smarte59058c2008-08-24 21:49:00 -04003039/**
James Smart6b5151f2012-01-18 16:24:06 -05003040 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3041 * @phba: pointer to lpfc hba data structure.
3042 *
3043 * Allocate RPIs for all active remote nodes. This is needed whenever
3044 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3045 * is to fixup the temporary rpi assignments.
3046 **/
3047void
3048lpfc_sli4_node_prep(struct lpfc_hba *phba)
3049{
3050 struct lpfc_nodelist *ndlp, *next_ndlp;
3051 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003052 int i, rpi;
3053 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003054
3055 if (phba->sli_rev != LPFC_SLI_REV4)
3056 return;
3057
3058 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003059 if (vports == NULL)
3060 return;
James Smart6b5151f2012-01-18 16:24:06 -05003061
James Smart9d3d3402017-04-21 16:05:00 -07003062 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3063 if (vports[i]->load_flag & FC_UNLOADING)
3064 continue;
3065
3066 list_for_each_entry_safe(ndlp, next_ndlp,
3067 &vports[i]->fc_nodes,
3068 nlp_listp) {
3069 if (!NLP_CHK_NODE_ACT(ndlp))
3070 continue;
3071 rpi = lpfc_sli4_alloc_rpi(phba);
3072 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3073 spin_lock_irqsave(&phba->ndlp_lock, flags);
3074 NLP_CLR_NODE_ACT(ndlp);
3075 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3076 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003077 }
James Smart9d3d3402017-04-21 16:05:00 -07003078 ndlp->nlp_rpi = rpi;
3079 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3080 "0009 rpi:%x DID:%x "
3081 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3082 ndlp->nlp_DID, ndlp->nlp_flag,
3083 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003084 }
3085 }
3086 lpfc_destroy_vport_work_array(phba, vports);
3087}
3088
3089/**
James Smartc4908502019-01-28 11:14:28 -08003090 * lpfc_create_expedite_pool - create expedite pool
3091 * @phba: pointer to lpfc hba data structure.
3092 *
3093 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3094 * to expedite pool. Mark them as expedite.
3095 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003096static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003097{
3098 struct lpfc_sli4_hdw_queue *qp;
3099 struct lpfc_io_buf *lpfc_ncmd;
3100 struct lpfc_io_buf *lpfc_ncmd_next;
3101 struct lpfc_epd_pool *epd_pool;
3102 unsigned long iflag;
3103
3104 epd_pool = &phba->epd_pool;
3105 qp = &phba->sli4_hba.hdwq[0];
3106
3107 spin_lock_init(&epd_pool->lock);
3108 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3109 spin_lock(&epd_pool->lock);
3110 INIT_LIST_HEAD(&epd_pool->list);
3111 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3112 &qp->lpfc_io_buf_list_put, list) {
3113 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3114 lpfc_ncmd->expedite = true;
3115 qp->put_io_bufs--;
3116 epd_pool->count++;
3117 if (epd_pool->count >= XRI_BATCH)
3118 break;
3119 }
3120 spin_unlock(&epd_pool->lock);
3121 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3122}
3123
3124/**
3125 * lpfc_destroy_expedite_pool - destroy expedite pool
3126 * @phba: pointer to lpfc hba data structure.
3127 *
3128 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3129 * of HWQ 0. Clear the mark.
3130 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003131static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003132{
3133 struct lpfc_sli4_hdw_queue *qp;
3134 struct lpfc_io_buf *lpfc_ncmd;
3135 struct lpfc_io_buf *lpfc_ncmd_next;
3136 struct lpfc_epd_pool *epd_pool;
3137 unsigned long iflag;
3138
3139 epd_pool = &phba->epd_pool;
3140 qp = &phba->sli4_hba.hdwq[0];
3141
3142 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3143 spin_lock(&epd_pool->lock);
3144 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3145 &epd_pool->list, list) {
3146 list_move_tail(&lpfc_ncmd->list,
3147 &qp->lpfc_io_buf_list_put);
3148 lpfc_ncmd->flags = false;
3149 qp->put_io_bufs++;
3150 epd_pool->count--;
3151 }
3152 spin_unlock(&epd_pool->lock);
3153 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3154}
3155
3156/**
3157 * lpfc_create_multixri_pools - create multi-XRI pools
3158 * @phba: pointer to lpfc hba data structure.
3159 *
3160 * This routine initialize public, private per HWQ. Then, move XRIs from
3161 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3162 * Initialized.
3163 **/
3164void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3165{
3166 u32 i, j;
3167 u32 hwq_count;
3168 u32 count_per_hwq;
3169 struct lpfc_io_buf *lpfc_ncmd;
3170 struct lpfc_io_buf *lpfc_ncmd_next;
3171 unsigned long iflag;
3172 struct lpfc_sli4_hdw_queue *qp;
3173 struct lpfc_multixri_pool *multixri_pool;
3174 struct lpfc_pbl_pool *pbl_pool;
3175 struct lpfc_pvt_pool *pvt_pool;
3176
3177 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3178 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3179 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3180 phba->sli4_hba.io_xri_cnt);
3181
3182 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3183 lpfc_create_expedite_pool(phba);
3184
3185 hwq_count = phba->cfg_hdw_queue;
3186 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3187
3188 for (i = 0; i < hwq_count; i++) {
3189 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3190
3191 if (!multixri_pool) {
3192 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3193 "1238 Failed to allocate memory for "
3194 "multixri_pool\n");
3195
3196 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3197 lpfc_destroy_expedite_pool(phba);
3198
3199 j = 0;
3200 while (j < i) {
3201 qp = &phba->sli4_hba.hdwq[j];
3202 kfree(qp->p_multixri_pool);
3203 j++;
3204 }
3205 phba->cfg_xri_rebalancing = 0;
3206 return;
3207 }
3208
3209 qp = &phba->sli4_hba.hdwq[i];
3210 qp->p_multixri_pool = multixri_pool;
3211
3212 multixri_pool->xri_limit = count_per_hwq;
3213 multixri_pool->rrb_next_hwqid = i;
3214
3215 /* Deal with public free xri pool */
3216 pbl_pool = &multixri_pool->pbl_pool;
3217 spin_lock_init(&pbl_pool->lock);
3218 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3219 spin_lock(&pbl_pool->lock);
3220 INIT_LIST_HEAD(&pbl_pool->list);
3221 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3222 &qp->lpfc_io_buf_list_put, list) {
3223 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3224 qp->put_io_bufs--;
3225 pbl_pool->count++;
3226 }
3227 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3228 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3229 pbl_pool->count, i);
3230 spin_unlock(&pbl_pool->lock);
3231 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3232
3233 /* Deal with private free xri pool */
3234 pvt_pool = &multixri_pool->pvt_pool;
3235 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3236 pvt_pool->low_watermark = XRI_BATCH;
3237 spin_lock_init(&pvt_pool->lock);
3238 spin_lock_irqsave(&pvt_pool->lock, iflag);
3239 INIT_LIST_HEAD(&pvt_pool->list);
3240 pvt_pool->count = 0;
3241 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3242 }
3243}
3244
3245/**
3246 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3247 * @phba: pointer to lpfc hba data structure.
3248 *
3249 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3250 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003251static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003252{
3253 u32 i;
3254 u32 hwq_count;
3255 struct lpfc_io_buf *lpfc_ncmd;
3256 struct lpfc_io_buf *lpfc_ncmd_next;
3257 unsigned long iflag;
3258 struct lpfc_sli4_hdw_queue *qp;
3259 struct lpfc_multixri_pool *multixri_pool;
3260 struct lpfc_pbl_pool *pbl_pool;
3261 struct lpfc_pvt_pool *pvt_pool;
3262
3263 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3264 lpfc_destroy_expedite_pool(phba);
3265
James Smartc66a9192019-03-12 16:30:19 -07003266 if (!(phba->pport->load_flag & FC_UNLOADING)) {
3267 lpfc_sli_flush_fcp_rings(phba);
3268
3269 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3270 lpfc_sli_flush_nvme_rings(phba);
3271 }
3272
James Smartc4908502019-01-28 11:14:28 -08003273 hwq_count = phba->cfg_hdw_queue;
3274
3275 for (i = 0; i < hwq_count; i++) {
3276 qp = &phba->sli4_hba.hdwq[i];
3277 multixri_pool = qp->p_multixri_pool;
3278 if (!multixri_pool)
3279 continue;
3280
3281 qp->p_multixri_pool = NULL;
3282
3283 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3284
3285 /* Deal with public free xri pool */
3286 pbl_pool = &multixri_pool->pbl_pool;
3287 spin_lock(&pbl_pool->lock);
3288
3289 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3290 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3291 pbl_pool->count, i);
3292
3293 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3294 &pbl_pool->list, list) {
3295 list_move_tail(&lpfc_ncmd->list,
3296 &qp->lpfc_io_buf_list_put);
3297 qp->put_io_bufs++;
3298 pbl_pool->count--;
3299 }
3300
3301 INIT_LIST_HEAD(&pbl_pool->list);
3302 pbl_pool->count = 0;
3303
3304 spin_unlock(&pbl_pool->lock);
3305
3306 /* Deal with private free xri pool */
3307 pvt_pool = &multixri_pool->pvt_pool;
3308 spin_lock(&pvt_pool->lock);
3309
3310 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3311 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3312 pvt_pool->count, i);
3313
3314 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3315 &pvt_pool->list, list) {
3316 list_move_tail(&lpfc_ncmd->list,
3317 &qp->lpfc_io_buf_list_put);
3318 qp->put_io_bufs++;
3319 pvt_pool->count--;
3320 }
3321
3322 INIT_LIST_HEAD(&pvt_pool->list);
3323 pvt_pool->count = 0;
3324
3325 spin_unlock(&pvt_pool->lock);
3326 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3327
3328 kfree(multixri_pool);
3329 }
3330}
3331
3332/**
James Smart3621a712009-04-06 18:47:14 -04003333 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003334 * @phba: pointer to lpfc hba data structure.
3335 *
3336 * This routine initializes the HBA and brings a HBA online. During this
3337 * process, the management interface is blocked to prevent user space access
3338 * to the HBA interfering with the driver initialization.
3339 *
3340 * Return codes
3341 * 0 - successful
3342 * 1 - failed
3343 **/
dea31012005-04-17 16:05:31 -05003344int
James Smart2e0fef82007-06-17 19:56:36 -05003345lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003346{
Julia Lawall372bd282008-12-16 16:15:08 +01003347 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003348 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003349 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003350 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003351
dea31012005-04-17 16:05:31 -05003352 if (!phba)
3353 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003354 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003355
James Smart2e0fef82007-06-17 19:56:36 -05003356 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003357 return 0;
3358
James Smarted957682007-06-17 19:56:37 -05003359 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003360 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003361
James Smart618a5232012-06-12 13:54:36 -04003362 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003363
James Smartda0436e2009-05-22 14:51:39 -04003364 if (phba->sli_rev == LPFC_SLI_REV4) {
3365 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3366 lpfc_unblock_mgmt_io(phba);
3367 return 1;
3368 }
James Smart16a3a202013-04-17 20:14:38 -04003369 spin_lock_irq(&phba->hbalock);
3370 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3371 vpis_cleared = true;
3372 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003373
3374 /* Reestablish the local initiator port.
3375 * The offline process destroyed the previous lport.
3376 */
3377 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3378 !phba->nvmet_support) {
3379 error = lpfc_nvme_create_localport(phba->pport);
3380 if (error)
3381 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3382 "6132 NVME restore reg failed "
3383 "on nvmei error x%x\n", error);
3384 }
James Smartda0436e2009-05-22 14:51:39 -04003385 } else {
James Smart895427b2017-02-12 13:52:30 -08003386 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003387 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3388 lpfc_unblock_mgmt_io(phba);
3389 return 1;
3390 }
James Smart46fa3112007-04-25 09:51:45 -04003391 }
dea31012005-04-17 16:05:31 -05003392
James Smart549e55c2007-08-02 11:09:51 -04003393 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003394 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003395 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003396 struct Scsi_Host *shost;
3397 shost = lpfc_shost_from_vport(vports[i]);
3398 spin_lock_irq(shost->host_lock);
3399 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3400 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3401 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003402 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003403 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003404 if ((vpis_cleared) &&
3405 (vports[i]->port_type !=
3406 LPFC_PHYSICAL_PORT))
3407 vports[i]->vpi = 0;
3408 }
James Smart549e55c2007-08-02 11:09:51 -04003409 spin_unlock_irq(shost->host_lock);
3410 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003411 }
3412 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003413
James Smartc4908502019-01-28 11:14:28 -08003414 if (phba->cfg_xri_rebalancing)
3415 lpfc_create_multixri_pools(phba);
3416
James Smart46fa3112007-04-25 09:51:45 -04003417 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003418 return 0;
3419}
3420
James Smarte59058c2008-08-24 21:49:00 -04003421/**
James Smart3621a712009-04-06 18:47:14 -04003422 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003423 * @phba: pointer to lpfc hba data structure.
3424 *
3425 * This routine marks a HBA's management interface as not blocked. Once the
3426 * HBA's management interface is marked as not blocked, all the user space
3427 * access to the HBA, whether they are from sysfs interface or libdfc
3428 * interface will be allowed. The HBA is set to block the management interface
3429 * when the driver prepares the HBA interface for online or offline and then
3430 * set to unblock the management interface afterwards.
3431 **/
James Smart46fa3112007-04-25 09:51:45 -04003432void
James Smart46fa3112007-04-25 09:51:45 -04003433lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3434{
3435 unsigned long iflag;
3436
James Smart2e0fef82007-06-17 19:56:36 -05003437 spin_lock_irqsave(&phba->hbalock, iflag);
3438 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3439 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003440}
3441
James Smarte59058c2008-08-24 21:49:00 -04003442/**
James Smart3621a712009-04-06 18:47:14 -04003443 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003444 * @phba: pointer to lpfc hba data structure.
3445 *
3446 * This routine is invoked to prepare a HBA to be brought offline. It performs
3447 * unregistration login to all the nodes on all vports and flushes the mailbox
3448 * queue to make it ready to be brought offline.
3449 **/
James Smart46fa3112007-04-25 09:51:45 -04003450void
James Smart618a5232012-06-12 13:54:36 -04003451lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003452{
James Smart2e0fef82007-06-17 19:56:36 -05003453 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003454 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003455 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003456 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003457 int i;
dea31012005-04-17 16:05:31 -05003458
James Smart2e0fef82007-06-17 19:56:36 -05003459 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003460 return;
dea31012005-04-17 16:05:31 -05003461
James Smart618a5232012-06-12 13:54:36 -04003462 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003463
3464 lpfc_linkdown(phba);
3465
James Smart87af33f2007-10-27 13:37:43 -04003466 /* Issue an unreg_login to all nodes on all vports */
3467 vports = lpfc_create_vport_work_array(phba);
3468 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003469 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003470 if (vports[i]->load_flag & FC_UNLOADING)
3471 continue;
James Smart72100cc2010-02-12 14:43:01 -05003472 shost = lpfc_shost_from_vport(vports[i]);
3473 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003474 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003475 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3476 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003477 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003478
James Smart87af33f2007-10-27 13:37:43 -04003479 shost = lpfc_shost_from_vport(vports[i]);
3480 list_for_each_entry_safe(ndlp, next_ndlp,
3481 &vports[i]->fc_nodes,
3482 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003483 if (!NLP_CHK_NODE_ACT(ndlp))
3484 continue;
James Smart87af33f2007-10-27 13:37:43 -04003485 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3486 continue;
3487 if (ndlp->nlp_type & NLP_FABRIC) {
3488 lpfc_disc_state_machine(vports[i], ndlp,
3489 NULL, NLP_EVT_DEVICE_RECOVERY);
3490 lpfc_disc_state_machine(vports[i], ndlp,
3491 NULL, NLP_EVT_DEVICE_RM);
3492 }
3493 spin_lock_irq(shost->host_lock);
3494 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003495 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003496 /*
3497 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003498 * RPI. Get a new RPI when the adapter port
3499 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003500 */
James Smartbe6bb942015-04-07 15:07:22 -04003501 if (phba->sli_rev == LPFC_SLI_REV4) {
3502 lpfc_printf_vlog(ndlp->vport,
3503 KERN_INFO, LOG_NODE,
3504 "0011 lpfc_offline: "
3505 "ndlp:x%p did %x "
3506 "usgmap:x%x rpi:%x\n",
3507 ndlp, ndlp->nlp_DID,
3508 ndlp->nlp_usg_map,
3509 ndlp->nlp_rpi);
3510
James Smart6b5151f2012-01-18 16:24:06 -05003511 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003512 }
James Smart87af33f2007-10-27 13:37:43 -04003513 lpfc_unreg_rpi(vports[i], ndlp);
3514 }
3515 }
3516 }
James Smart09372822008-01-11 01:52:54 -05003517 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003518
James Smart618a5232012-06-12 13:54:36 -04003519 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003520
3521 if (phba->wq)
3522 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003523}
3524
James Smarte59058c2008-08-24 21:49:00 -04003525/**
James Smart3621a712009-04-06 18:47:14 -04003526 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003527 * @phba: pointer to lpfc hba data structure.
3528 *
3529 * This routine actually brings a HBA offline. It stops all the timers
3530 * associated with the HBA, brings down the SLI layer, and eventually
3531 * marks the HBA as in offline state for the upper layer protocol.
3532 **/
James Smart46fa3112007-04-25 09:51:45 -04003533void
James Smart2e0fef82007-06-17 19:56:36 -05003534lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003535{
James Smart549e55c2007-08-02 11:09:51 -04003536 struct Scsi_Host *shost;
3537 struct lpfc_vport **vports;
3538 int i;
James Smart46fa3112007-04-25 09:51:45 -04003539
James Smart549e55c2007-08-02 11:09:51 -04003540 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003541 return;
James Smart688a8862006-07-06 15:49:56 -04003542
James Smartda0436e2009-05-22 14:51:39 -04003543 /* stop port and all timers associated with this hba */
3544 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003545
3546 /* Tear down the local and target port registrations. The
3547 * nvme transports need to cleanup.
3548 */
3549 lpfc_nvmet_destroy_targetport(phba);
3550 lpfc_nvme_destroy_localport(phba->pport);
3551
James Smart51ef4c22007-08-02 11:10:31 -04003552 vports = lpfc_create_vport_work_array(phba);
3553 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003554 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003555 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003556 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003557 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003558 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003559 /* Bring down the SLI Layer and cleanup. The HBA is offline
3560 now. */
3561 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003562 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003563 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003564 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003565 vports = lpfc_create_vport_work_array(phba);
3566 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003567 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003568 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003569 spin_lock_irq(shost->host_lock);
3570 vports[i]->work_port_events = 0;
3571 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3572 spin_unlock_irq(shost->host_lock);
3573 }
James Smart09372822008-01-11 01:52:54 -05003574 lpfc_destroy_vport_work_array(phba, vports);
James Smartc4908502019-01-28 11:14:28 -08003575
3576 if (phba->cfg_xri_rebalancing)
3577 lpfc_destroy_multixri_pools(phba);
dea31012005-04-17 16:05:31 -05003578}
3579
James Smarte59058c2008-08-24 21:49:00 -04003580/**
James Smart3621a712009-04-06 18:47:14 -04003581 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003582 * @phba: pointer to lpfc hba data structure.
3583 *
3584 * This routine is to free all the SCSI buffers and IOCBs from the driver
3585 * list back to kernel. It is called from lpfc_pci_remove_one to free
3586 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003587 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003588static void
James Smart2e0fef82007-06-17 19:56:36 -05003589lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003590{
James Smartc4908502019-01-28 11:14:28 -08003591 struct lpfc_io_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003592
James Smart895427b2017-02-12 13:52:30 -08003593 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3594 return;
3595
James Smart2e0fef82007-06-17 19:56:36 -05003596 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003597
dea31012005-04-17 16:05:31 -05003598 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003599
3600 spin_lock(&phba->scsi_buf_list_put_lock);
3601 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3602 list) {
dea31012005-04-17 16:05:31 -05003603 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003604 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003605 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003606 kfree(sb);
3607 phba->total_scsi_bufs--;
3608 }
James Smarta40fc5f2013-04-17 20:17:40 -04003609 spin_unlock(&phba->scsi_buf_list_put_lock);
3610
3611 spin_lock(&phba->scsi_buf_list_get_lock);
3612 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3613 list) {
3614 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003615 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003616 sb->dma_handle);
3617 kfree(sb);
3618 phba->total_scsi_bufs--;
3619 }
3620 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003621 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003622}
James Smart0794d602019-01-28 11:14:19 -08003623
James Smart8a9d2e82012-05-09 21:16:12 -04003624/**
James Smart5e5b5112019-01-28 11:14:22 -08003625 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
James Smart895427b2017-02-12 13:52:30 -08003626 * @phba: pointer to lpfc hba data structure.
3627 *
James Smart0794d602019-01-28 11:14:19 -08003628 * This routine is to free all the IO buffers and IOCBs from the driver
James Smart895427b2017-02-12 13:52:30 -08003629 * list back to kernel. It is called from lpfc_pci_remove_one to free
3630 * the internal resources before the device is removed from the system.
3631 **/
James Smartc4908502019-01-28 11:14:28 -08003632void
James Smart5e5b5112019-01-28 11:14:22 -08003633lpfc_io_free(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08003634{
James Smartc4908502019-01-28 11:14:28 -08003635 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart5e5b5112019-01-28 11:14:22 -08003636 struct lpfc_sli4_hdw_queue *qp;
3637 int idx;
James Smart895427b2017-02-12 13:52:30 -08003638
James Smart5e5b5112019-01-28 11:14:22 -08003639 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3640 qp = &phba->sli4_hba.hdwq[idx];
3641 /* Release all the lpfc_nvme_bufs maintained by this host. */
3642 spin_lock(&qp->io_buf_list_put_lock);
3643 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3644 &qp->lpfc_io_buf_list_put,
3645 list) {
3646 list_del(&lpfc_ncmd->list);
3647 qp->put_io_bufs--;
3648 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3649 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3650 kfree(lpfc_ncmd);
3651 qp->total_io_bufs--;
3652 }
3653 spin_unlock(&qp->io_buf_list_put_lock);
James Smart895427b2017-02-12 13:52:30 -08003654
James Smart5e5b5112019-01-28 11:14:22 -08003655 spin_lock(&qp->io_buf_list_get_lock);
3656 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3657 &qp->lpfc_io_buf_list_get,
3658 list) {
3659 list_del(&lpfc_ncmd->list);
3660 qp->get_io_bufs--;
3661 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3662 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3663 kfree(lpfc_ncmd);
3664 qp->total_io_bufs--;
3665 }
3666 spin_unlock(&qp->io_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003667 }
James Smart895427b2017-02-12 13:52:30 -08003668}
James Smart0794d602019-01-28 11:14:19 -08003669
James Smart895427b2017-02-12 13:52:30 -08003670/**
3671 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003672 * @phba: pointer to lpfc hba data structure.
3673 *
3674 * This routine first calculates the sizes of the current els and allocated
3675 * scsi sgl lists, and then goes through all sgls to updates the physical
3676 * XRIs assigned due to port function reset. During port initialization, the
3677 * current els and allocated scsi sgl lists are 0s.
3678 *
3679 * Return codes
3680 * 0 - successful (for now, it always returns 0)
3681 **/
3682int
James Smart895427b2017-02-12 13:52:30 -08003683lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003684{
3685 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003686 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003687 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003688 int rc;
3689
3690 /*
3691 * update on pci function's els xri-sgl list
3692 */
3693 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003694
James Smart8a9d2e82012-05-09 21:16:12 -04003695 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3696 /* els xri-sgl expanded */
3697 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3698 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3699 "3157 ELS xri-sgl count increased from "
3700 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3701 els_xri_cnt);
3702 /* allocate the additional els sgls */
3703 for (i = 0; i < xri_cnt; i++) {
3704 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3705 GFP_KERNEL);
3706 if (sglq_entry == NULL) {
3707 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3708 "2562 Failure to allocate an "
3709 "ELS sgl entry:%d\n", i);
3710 rc = -ENOMEM;
3711 goto out_free_mem;
3712 }
3713 sglq_entry->buff_type = GEN_BUFF_TYPE;
3714 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3715 &sglq_entry->phys);
3716 if (sglq_entry->virt == NULL) {
3717 kfree(sglq_entry);
3718 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3719 "2563 Failure to allocate an "
3720 "ELS mbuf:%d\n", i);
3721 rc = -ENOMEM;
3722 goto out_free_mem;
3723 }
3724 sglq_entry->sgl = sglq_entry->virt;
3725 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3726 sglq_entry->state = SGL_FREED;
3727 list_add_tail(&sglq_entry->list, &els_sgl_list);
3728 }
James Smart38c20672013-03-01 16:37:44 -05003729 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003730 spin_lock(&phba->sli4_hba.sgl_list_lock);
3731 list_splice_init(&els_sgl_list,
3732 &phba->sli4_hba.lpfc_els_sgl_list);
3733 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003734 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003735 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3736 /* els xri-sgl shrinked */
3737 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3738 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3739 "3158 ELS xri-sgl count decreased from "
3740 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3741 els_xri_cnt);
3742 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003743 spin_lock(&phba->sli4_hba.sgl_list_lock);
3744 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3745 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003746 /* release extra els sgls from list */
3747 for (i = 0; i < xri_cnt; i++) {
3748 list_remove_head(&els_sgl_list,
3749 sglq_entry, struct lpfc_sglq, list);
3750 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003751 __lpfc_mbuf_free(phba, sglq_entry->virt,
3752 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003753 kfree(sglq_entry);
3754 }
3755 }
James Smart895427b2017-02-12 13:52:30 -08003756 list_splice_init(&els_sgl_list,
3757 &phba->sli4_hba.lpfc_els_sgl_list);
3758 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003759 spin_unlock_irq(&phba->hbalock);
3760 } else
3761 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3762 "3163 ELS xri-sgl count unchanged: %d\n",
3763 els_xri_cnt);
3764 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3765
3766 /* update xris to els sgls on the list */
3767 sglq_entry = NULL;
3768 sglq_entry_next = NULL;
3769 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003770 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003771 lxri = lpfc_sli4_next_xritag(phba);
3772 if (lxri == NO_XRI) {
3773 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3774 "2400 Failed to allocate xri for "
3775 "ELS sgl\n");
3776 rc = -ENOMEM;
3777 goto out_free_mem;
3778 }
3779 sglq_entry->sli4_lxritag = lxri;
3780 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3781 }
James Smart895427b2017-02-12 13:52:30 -08003782 return 0;
3783
3784out_free_mem:
3785 lpfc_free_els_sgl_list(phba);
3786 return rc;
3787}
3788
3789/**
James Smartf358dd02017-02-12 13:52:34 -08003790 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3791 * @phba: pointer to lpfc hba data structure.
3792 *
3793 * This routine first calculates the sizes of the current els and allocated
3794 * scsi sgl lists, and then goes through all sgls to updates the physical
3795 * XRIs assigned due to port function reset. During port initialization, the
3796 * current els and allocated scsi sgl lists are 0s.
3797 *
3798 * Return codes
3799 * 0 - successful (for now, it always returns 0)
3800 **/
3801int
3802lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3803{
3804 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3805 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003806 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003807 LIST_HEAD(nvmet_sgl_list);
3808 int rc;
3809
3810 /*
3811 * update on pci function's nvmet xri-sgl list
3812 */
3813 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003814
James Smart6c621a22017-05-15 15:20:45 -07003815 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3816 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003817 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3818 /* els xri-sgl expanded */
3819 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3820 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3821 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3822 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3823 /* allocate the additional nvmet sgls */
3824 for (i = 0; i < xri_cnt; i++) {
3825 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3826 GFP_KERNEL);
3827 if (sglq_entry == NULL) {
3828 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3829 "6303 Failure to allocate an "
3830 "NVMET sgl entry:%d\n", i);
3831 rc = -ENOMEM;
3832 goto out_free_mem;
3833 }
3834 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3835 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3836 &sglq_entry->phys);
3837 if (sglq_entry->virt == NULL) {
3838 kfree(sglq_entry);
3839 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3840 "6304 Failure to allocate an "
3841 "NVMET buf:%d\n", i);
3842 rc = -ENOMEM;
3843 goto out_free_mem;
3844 }
3845 sglq_entry->sgl = sglq_entry->virt;
3846 memset(sglq_entry->sgl, 0,
3847 phba->cfg_sg_dma_buf_size);
3848 sglq_entry->state = SGL_FREED;
3849 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3850 }
3851 spin_lock_irq(&phba->hbalock);
3852 spin_lock(&phba->sli4_hba.sgl_list_lock);
3853 list_splice_init(&nvmet_sgl_list,
3854 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3855 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3856 spin_unlock_irq(&phba->hbalock);
3857 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3858 /* nvmet xri-sgl shrunk */
3859 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3860 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3861 "6305 NVMET xri-sgl count decreased from "
3862 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3863 nvmet_xri_cnt);
3864 spin_lock_irq(&phba->hbalock);
3865 spin_lock(&phba->sli4_hba.sgl_list_lock);
3866 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3867 &nvmet_sgl_list);
3868 /* release extra nvmet sgls from list */
3869 for (i = 0; i < xri_cnt; i++) {
3870 list_remove_head(&nvmet_sgl_list,
3871 sglq_entry, struct lpfc_sglq, list);
3872 if (sglq_entry) {
3873 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3874 sglq_entry->phys);
3875 kfree(sglq_entry);
3876 }
3877 }
3878 list_splice_init(&nvmet_sgl_list,
3879 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3880 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3881 spin_unlock_irq(&phba->hbalock);
3882 } else
3883 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3884 "6306 NVMET xri-sgl count unchanged: %d\n",
3885 nvmet_xri_cnt);
3886 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3887
3888 /* update xris to nvmet sgls on the list */
3889 sglq_entry = NULL;
3890 sglq_entry_next = NULL;
3891 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3892 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3893 lxri = lpfc_sli4_next_xritag(phba);
3894 if (lxri == NO_XRI) {
3895 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3896 "6307 Failed to allocate xri for "
3897 "NVMET sgl\n");
3898 rc = -ENOMEM;
3899 goto out_free_mem;
3900 }
3901 sglq_entry->sli4_lxritag = lxri;
3902 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3903 }
3904 return 0;
3905
3906out_free_mem:
3907 lpfc_free_nvmet_sgl_list(phba);
3908 return rc;
3909}
3910
James Smart5e5b5112019-01-28 11:14:22 -08003911int
3912lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
3913{
3914 LIST_HEAD(blist);
3915 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08003916 struct lpfc_io_buf *lpfc_cmd;
3917 struct lpfc_io_buf *iobufp, *prev_iobufp;
James Smart5e5b5112019-01-28 11:14:22 -08003918 int idx, cnt, xri, inserted;
3919
3920 cnt = 0;
3921 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3922 qp = &phba->sli4_hba.hdwq[idx];
3923 spin_lock_irq(&qp->io_buf_list_get_lock);
3924 spin_lock(&qp->io_buf_list_put_lock);
3925
3926 /* Take everything off the get and put lists */
3927 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
3928 list_splice(&qp->lpfc_io_buf_list_put, &blist);
3929 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
3930 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
3931 cnt += qp->get_io_bufs + qp->put_io_bufs;
3932 qp->get_io_bufs = 0;
3933 qp->put_io_bufs = 0;
3934 qp->total_io_bufs = 0;
3935 spin_unlock(&qp->io_buf_list_put_lock);
3936 spin_unlock_irq(&qp->io_buf_list_get_lock);
3937 }
3938
3939 /*
3940 * Take IO buffers off blist and put on cbuf sorted by XRI.
3941 * This is because POST_SGL takes a sequential range of XRIs
3942 * to post to the firmware.
3943 */
3944 for (idx = 0; idx < cnt; idx++) {
James Smartc4908502019-01-28 11:14:28 -08003945 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08003946 if (!lpfc_cmd)
3947 return cnt;
3948 if (idx == 0) {
3949 list_add_tail(&lpfc_cmd->list, cbuf);
3950 continue;
3951 }
3952 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
3953 inserted = 0;
3954 prev_iobufp = NULL;
3955 list_for_each_entry(iobufp, cbuf, list) {
3956 if (xri < iobufp->cur_iocbq.sli4_xritag) {
3957 if (prev_iobufp)
3958 list_add(&lpfc_cmd->list,
3959 &prev_iobufp->list);
3960 else
3961 list_add(&lpfc_cmd->list, cbuf);
3962 inserted = 1;
3963 break;
3964 }
3965 prev_iobufp = iobufp;
3966 }
3967 if (!inserted)
3968 list_add_tail(&lpfc_cmd->list, cbuf);
3969 }
3970 return cnt;
3971}
3972
3973int
3974lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
3975{
3976 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08003977 struct lpfc_io_buf *lpfc_cmd;
James Smart5e5b5112019-01-28 11:14:22 -08003978 int idx, cnt;
3979
3980 qp = phba->sli4_hba.hdwq;
3981 cnt = 0;
3982 while (!list_empty(cbuf)) {
3983 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3984 list_remove_head(cbuf, lpfc_cmd,
James Smartc4908502019-01-28 11:14:28 -08003985 struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08003986 if (!lpfc_cmd)
3987 return cnt;
3988 cnt++;
3989 qp = &phba->sli4_hba.hdwq[idx];
James Smart1fbf9742019-01-28 11:14:26 -08003990 lpfc_cmd->hdwq_no = idx;
3991 lpfc_cmd->hdwq = qp;
James Smart5e5b5112019-01-28 11:14:22 -08003992 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
3993 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
3994 spin_lock(&qp->io_buf_list_put_lock);
3995 list_add_tail(&lpfc_cmd->list,
3996 &qp->lpfc_io_buf_list_put);
3997 qp->put_io_bufs++;
3998 qp->total_io_bufs++;
3999 spin_unlock(&qp->io_buf_list_put_lock);
4000 }
4001 }
4002 return cnt;
4003}
4004
James Smartf358dd02017-02-12 13:52:34 -08004005/**
James Smart5e5b5112019-01-28 11:14:22 -08004006 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
James Smart895427b2017-02-12 13:52:30 -08004007 * @phba: pointer to lpfc hba data structure.
4008 *
4009 * This routine first calculates the sizes of the current els and allocated
4010 * scsi sgl lists, and then goes through all sgls to updates the physical
4011 * XRIs assigned due to port function reset. During port initialization, the
4012 * current els and allocated scsi sgl lists are 0s.
4013 *
4014 * Return codes
4015 * 0 - successful (for now, it always returns 0)
4016 **/
4017int
James Smart5e5b5112019-01-28 11:14:22 -08004018lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08004019{
James Smartc4908502019-01-28 11:14:28 -08004020 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
James Smart0794d602019-01-28 11:14:19 -08004021 uint16_t i, lxri, els_xri_cnt;
James Smart5e5b5112019-01-28 11:14:22 -08004022 uint16_t io_xri_cnt, io_xri_max;
4023 LIST_HEAD(io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004024 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08004025
4026 /*
James Smart0794d602019-01-28 11:14:19 -08004027 * update on pci function's allocated nvme xri-sgl list
James Smart895427b2017-02-12 13:52:30 -08004028 */
James Smart0794d602019-01-28 11:14:19 -08004029
4030 /* maximum number of xris available for nvme buffers */
James Smart895427b2017-02-12 13:52:30 -08004031 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart5e5b5112019-01-28 11:14:22 -08004032 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4033 phba->sli4_hba.io_xri_max = io_xri_max;
James Smart8a9d2e82012-05-09 21:16:12 -04004034
James Smarte8c0a772017-04-21 16:04:49 -07004035 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004036 "6074 Current allocated XRI sgl count:%d, "
4037 "maximum XRI count:%d\n",
James Smart5e5b5112019-01-28 11:14:22 -08004038 phba->sli4_hba.io_xri_cnt,
4039 phba->sli4_hba.io_xri_max);
James Smarte8c0a772017-04-21 16:04:49 -07004040
James Smart5e5b5112019-01-28 11:14:22 -08004041 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004042
James Smart5e5b5112019-01-28 11:14:22 -08004043 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
James Smart0794d602019-01-28 11:14:19 -08004044 /* max nvme xri shrunk below the allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004045 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4046 phba->sli4_hba.io_xri_max;
James Smart0794d602019-01-28 11:14:19 -08004047 /* release the extra allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004048 for (i = 0; i < io_xri_cnt; i++) {
4049 list_remove_head(&io_sgl_list, lpfc_ncmd,
James Smartc4908502019-01-28 11:14:28 -08004050 struct lpfc_io_buf, list);
James Smart0794d602019-01-28 11:14:19 -08004051 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02004052 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart0794d602019-01-28 11:14:19 -08004053 lpfc_ncmd->data,
4054 lpfc_ncmd->dma_handle);
4055 kfree(lpfc_ncmd);
James Smarta2fc4aef2014-09-03 12:57:55 -04004056 }
James Smart8a9d2e82012-05-09 21:16:12 -04004057 }
James Smart5e5b5112019-01-28 11:14:22 -08004058 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04004059 }
4060
James Smart0794d602019-01-28 11:14:19 -08004061 /* update xris associated to remaining allocated nvme buffers */
4062 lpfc_ncmd = NULL;
4063 lpfc_ncmd_next = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08004064 phba->sli4_hba.io_xri_cnt = cnt;
James Smart0794d602019-01-28 11:14:19 -08004065 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
James Smart5e5b5112019-01-28 11:14:22 -08004066 &io_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04004067 lxri = lpfc_sli4_next_xritag(phba);
4068 if (lxri == NO_XRI) {
4069 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004070 "6075 Failed to allocate xri for "
4071 "nvme buffer\n");
James Smart8a9d2e82012-05-09 21:16:12 -04004072 rc = -ENOMEM;
4073 goto out_free_mem;
4074 }
James Smart0794d602019-01-28 11:14:19 -08004075 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4076 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
James Smart8a9d2e82012-05-09 21:16:12 -04004077 }
James Smart5e5b5112019-01-28 11:14:22 -08004078 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
dea31012005-04-17 16:05:31 -05004079 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04004080
4081out_free_mem:
James Smart5e5b5112019-01-28 11:14:22 -08004082 lpfc_io_free(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04004083 return rc;
dea31012005-04-17 16:05:31 -05004084}
4085
James Smart0794d602019-01-28 11:14:19 -08004086/**
James Smart5e5b5112019-01-28 11:14:22 -08004087 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
James Smart0794d602019-01-28 11:14:19 -08004088 * @vport: The virtual port for which this call being executed.
4089 * @num_to_allocate: The requested number of buffers to allocate.
4090 *
4091 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4092 * the nvme buffer contains all the necessary information needed to initiate
4093 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4094 * them on a list, it post them to the port by using SGL block post.
4095 *
4096 * Return codes:
James Smart5e5b5112019-01-28 11:14:22 -08004097 * int - number of IO buffers that were allocated and posted.
James Smart0794d602019-01-28 11:14:19 -08004098 * 0 = failure, less than num_to_alloc is a partial failure.
4099 **/
4100int
James Smart5e5b5112019-01-28 11:14:22 -08004101lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
James Smart0794d602019-01-28 11:14:19 -08004102{
James Smartc4908502019-01-28 11:14:28 -08004103 struct lpfc_io_buf *lpfc_ncmd;
James Smart0794d602019-01-28 11:14:19 -08004104 struct lpfc_iocbq *pwqeq;
4105 uint16_t iotag, lxri = 0;
4106 int bcnt, num_posted;
4107 LIST_HEAD(prep_nblist);
4108 LIST_HEAD(post_nblist);
4109 LIST_HEAD(nvme_nblist);
4110
4111 /* Sanity check to ensure our sizing is right for both SCSI and NVME */
James Smartc4908502019-01-28 11:14:28 -08004112 if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) {
James Smart0794d602019-01-28 11:14:19 -08004113 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
Arnd Bergmannf9968612019-03-04 20:39:09 +01004114 "6426 Common buffer size %zd exceeds %d\n",
James Smartc4908502019-01-28 11:14:28 -08004115 sizeof(struct lpfc_io_buf),
4116 LPFC_COMMON_IO_BUF_SZ);
James Smart0794d602019-01-28 11:14:19 -08004117 return 0;
4118 }
4119
James Smart5e5b5112019-01-28 11:14:22 -08004120 phba->sli4_hba.io_xri_cnt = 0;
James Smart0794d602019-01-28 11:14:19 -08004121 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4122 lpfc_ncmd = kzalloc(LPFC_COMMON_IO_BUF_SZ, GFP_KERNEL);
4123 if (!lpfc_ncmd)
4124 break;
4125 /*
4126 * Get memory from the pci pool to map the virt space to
4127 * pci bus space for an I/O. The DMA buffer includes the
4128 * number of SGE's necessary to support the sg_tablesize.
4129 */
Thomas Meyera5c990e2019-05-29 22:21:36 +02004130 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4131 GFP_KERNEL,
4132 &lpfc_ncmd->dma_handle);
James Smart0794d602019-01-28 11:14:19 -08004133 if (!lpfc_ncmd->data) {
4134 kfree(lpfc_ncmd);
4135 break;
4136 }
James Smart0794d602019-01-28 11:14:19 -08004137
4138 /*
4139 * 4K Page alignment is CRITICAL to BlockGuard, double check
4140 * to be sure.
4141 */
4142 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4143 (((unsigned long)(lpfc_ncmd->data) &
4144 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4145 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
4146 "3369 Memory alignment err: addr=%lx\n",
4147 (unsigned long)lpfc_ncmd->data);
4148 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4149 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4150 kfree(lpfc_ncmd);
4151 break;
4152 }
4153
4154 lxri = lpfc_sli4_next_xritag(phba);
4155 if (lxri == NO_XRI) {
4156 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4157 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4158 kfree(lpfc_ncmd);
4159 break;
4160 }
4161 pwqeq = &lpfc_ncmd->cur_iocbq;
4162
4163 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4164 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4165 if (iotag == 0) {
4166 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4167 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4168 kfree(lpfc_ncmd);
4169 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
4170 "6121 Failed to allocate IOTAG for"
4171 " XRI:0x%x\n", lxri);
4172 lpfc_sli4_free_xri(phba, lxri);
4173 break;
4174 }
4175 pwqeq->sli4_lxritag = lxri;
4176 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4177 pwqeq->context1 = lpfc_ncmd;
4178
4179 /* Initialize local short-hand pointers. */
4180 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4181 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4182 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
James Smartc2017262019-01-28 11:14:37 -08004183 spin_lock_init(&lpfc_ncmd->buf_lock);
James Smart0794d602019-01-28 11:14:19 -08004184
4185 /* add the nvme buffer to a post list */
4186 list_add_tail(&lpfc_ncmd->list, &post_nblist);
James Smart5e5b5112019-01-28 11:14:22 -08004187 phba->sli4_hba.io_xri_cnt++;
James Smart0794d602019-01-28 11:14:19 -08004188 }
4189 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4190 "6114 Allocate %d out of %d requested new NVME "
4191 "buffers\n", bcnt, num_to_alloc);
4192
4193 /* post the list of nvme buffer sgls to port if available */
4194 if (!list_empty(&post_nblist))
James Smart5e5b5112019-01-28 11:14:22 -08004195 num_posted = lpfc_sli4_post_io_sgl_list(
James Smart0794d602019-01-28 11:14:19 -08004196 phba, &post_nblist, bcnt);
4197 else
4198 num_posted = 0;
4199
4200 return num_posted;
4201}
4202
James Smart96418b52017-03-04 09:30:31 -08004203static uint64_t
4204lpfc_get_wwpn(struct lpfc_hba *phba)
4205{
4206 uint64_t wwn;
4207 int rc;
4208 LPFC_MBOXQ_t *mboxq;
4209 MAILBOX_t *mb;
4210
James Smart96418b52017-03-04 09:30:31 -08004211 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4212 GFP_KERNEL);
4213 if (!mboxq)
4214 return (uint64_t)-1;
4215
4216 /* First get WWN of HBA instance */
4217 lpfc_read_nv(phba, mboxq);
4218 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4219 if (rc != MBX_SUCCESS) {
4220 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4221 "6019 Mailbox failed , mbxCmd x%x "
4222 "READ_NV, mbxStatus x%x\n",
4223 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4224 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4225 mempool_free(mboxq, phba->mbox_mem_pool);
4226 return (uint64_t) -1;
4227 }
4228 mb = &mboxq->u.mb;
4229 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4230 /* wwn is WWPN of HBA instance */
4231 mempool_free(mboxq, phba->mbox_mem_pool);
4232 if (phba->sli_rev == LPFC_SLI_REV4)
4233 return be64_to_cpu(wwn);
4234 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07004235 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08004236}
4237
James Smarte59058c2008-08-24 21:49:00 -04004238/**
James Smart3621a712009-04-06 18:47:14 -04004239 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04004240 * @phba: pointer to lpfc hba data structure.
4241 * @instance: a unique integer ID to this FC port.
4242 * @dev: pointer to the device data structure.
4243 *
4244 * This routine creates a FC port for the upper layer protocol. The FC port
4245 * can be created on top of either a physical port or a virtual port provided
4246 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4247 * and associates the FC port created before adding the shost into the SCSI
4248 * layer.
4249 *
4250 * Return codes
4251 * @vport - pointer to the virtual N_Port data structure.
4252 * NULL - port create failed.
4253 **/
James Smart2e0fef82007-06-17 19:56:36 -05004254struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04004255lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04004256{
James Smart2e0fef82007-06-17 19:56:36 -05004257 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08004258 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004259 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08004260 int i;
4261 uint64_t wwn;
4262 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07004263 int rc;
James Smart96418b52017-03-04 09:30:31 -08004264
James Smart56bc8022017-06-15 22:56:43 -07004265 if (lpfc_no_hba_reset_cnt) {
4266 if (phba->sli_rev < LPFC_SLI_REV4 &&
4267 dev == &phba->pcidev->dev) {
4268 /* Reset the port first */
4269 lpfc_sli_brdrestart(phba);
4270 rc = lpfc_sli_chipset_init(phba);
4271 if (rc)
4272 return NULL;
4273 }
4274 wwn = lpfc_get_wwpn(phba);
4275 }
James Smart96418b52017-03-04 09:30:31 -08004276
4277 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4278 if (wwn == lpfc_no_hba_reset[i]) {
4279 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4280 "6020 Setting use_no_reset port=%llx\n",
4281 wwn);
4282 use_no_reset_hba = true;
4283 break;
4284 }
4285 }
James Smart47a86172007-04-25 09:53:22 -04004286
James Smart895427b2017-02-12 13:52:30 -08004287 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4288 if (dev != &phba->pcidev->dev) {
4289 shost = scsi_host_alloc(&lpfc_vport_template,
4290 sizeof(struct lpfc_vport));
4291 } else {
James Smart96418b52017-03-04 09:30:31 -08004292 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08004293 shost = scsi_host_alloc(&lpfc_template,
4294 sizeof(struct lpfc_vport));
4295 else
James Smart96418b52017-03-04 09:30:31 -08004296 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08004297 sizeof(struct lpfc_vport));
4298 }
4299 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
4300 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04004301 sizeof(struct lpfc_vport));
4302 }
James Smart2e0fef82007-06-17 19:56:36 -05004303 if (!shost)
4304 goto out;
James Smart47a86172007-04-25 09:53:22 -04004305
James Smart2e0fef82007-06-17 19:56:36 -05004306 vport = (struct lpfc_vport *) shost->hostdata;
4307 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05004308 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05004309 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05004310 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04004311 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08004312
James Smartf6e84792019-01-28 11:14:38 -08004313 /* Adjust value in vport */
4314 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4315
James Smart2e0fef82007-06-17 19:56:36 -05004316 shost->unique_id = instance;
4317 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04004318 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05004319 shost->this_id = -1;
4320 shost->max_cmd_len = 16;
James Smart6a828b02019-01-28 11:14:31 -08004321
James Smartda0436e2009-05-22 14:51:39 -04004322 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6a828b02019-01-28 11:14:31 -08004323 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ)
4324 shost->nr_hw_queues = phba->cfg_hdw_queue;
4325 else
4326 shost->nr_hw_queues = phba->sli4_hba.num_present_cpu;
4327
James Smart28baac72010-02-12 14:42:03 -05004328 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04004329 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07004330 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartace44e42019-01-28 11:14:27 -08004331 } else
4332 /* SLI-3 has a limited number of hardware queues (3),
4333 * thus there is only one for FCP processing.
4334 */
4335 shost->nr_hw_queues = 1;
James Smart81301a92008-12-04 22:39:46 -05004336
James Smart47a86172007-04-25 09:53:22 -04004337 /*
James Smart2e0fef82007-06-17 19:56:36 -05004338 * Set initial can_queue value since 0 is no longer supported and
4339 * scsi_add_host will fail. This will be adjusted later based on the
4340 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04004341 */
James Smart2e0fef82007-06-17 19:56:36 -05004342 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04004343 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05004344 shost->transportt = lpfc_vport_transport_template;
4345 vport->port_type = LPFC_NPIV_PORT;
4346 } else {
4347 shost->transportt = lpfc_transport_template;
4348 vport->port_type = LPFC_PHYSICAL_PORT;
4349 }
James Smart47a86172007-04-25 09:53:22 -04004350
James Smart2e0fef82007-06-17 19:56:36 -05004351 /* Initialize all internally managed lists. */
4352 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04004353 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05004354 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04004355
Kees Cookf22eb4d2017-09-06 20:24:26 -07004356 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04004357
Kees Cookf22eb4d2017-09-06 20:24:26 -07004358 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05004359
Kees Cookf22eb4d2017-09-06 20:24:26 -07004360 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05004361
James Smartaa6ff302019-05-21 17:49:09 -07004362 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4363 lpfc_setup_bg(phba, shost);
4364
James Bottomleyd139b9b2009-11-05 13:33:12 -06004365 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05004366 if (error)
4367 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04004368
James Smart523128e2018-09-10 10:30:46 -07004369 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004370 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07004371 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004372 return vport;
James Smart47a86172007-04-25 09:53:22 -04004373
James Smart2e0fef82007-06-17 19:56:36 -05004374out_put_shost:
4375 scsi_host_put(shost);
4376out:
4377 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004378}
4379
James Smarte59058c2008-08-24 21:49:00 -04004380/**
James Smart3621a712009-04-06 18:47:14 -04004381 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004382 * @vport: pointer to an lpfc virtual N_Port data structure.
4383 *
4384 * This routine destroys a FC port from the upper layer protocol. All the
4385 * resources associated with the port are released.
4386 **/
James Smart2e0fef82007-06-17 19:56:36 -05004387void
4388destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004389{
James Smart92d7f7b2007-06-17 19:56:38 -05004390 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4391 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004392
James Smart858c9f62007-06-17 19:56:39 -05004393 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004394 fc_remove_host(shost);
4395 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004396
James Smart523128e2018-09-10 10:30:46 -07004397 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004398 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004399 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004400
James Smart92d7f7b2007-06-17 19:56:38 -05004401 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004402 return;
James Smart47a86172007-04-25 09:53:22 -04004403}
4404
James Smarte59058c2008-08-24 21:49:00 -04004405/**
James Smart3621a712009-04-06 18:47:14 -04004406 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004407 *
4408 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4409 * uses the kernel idr facility to perform the task.
4410 *
4411 * Return codes:
4412 * instance - a unique integer ID allocated as the new instance.
4413 * -1 - lpfc get instance failed.
4414 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004415int
4416lpfc_get_instance(void)
4417{
Tejun Heoab516032013-02-27 17:04:44 -08004418 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004419
Tejun Heoab516032013-02-27 17:04:44 -08004420 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4421 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004422}
4423
James Smarte59058c2008-08-24 21:49:00 -04004424/**
James Smart3621a712009-04-06 18:47:14 -04004425 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004426 * @shost: pointer to SCSI host data structure.
4427 * @time: elapsed time of the scan in jiffies.
4428 *
4429 * This routine is called by the SCSI layer with a SCSI host to determine
4430 * whether the scan host is finished.
4431 *
4432 * Note: there is no scan_start function as adapter initialization will have
4433 * asynchronously kicked off the link initialization.
4434 *
4435 * Return codes
4436 * 0 - SCSI host scan is not over yet.
4437 * 1 - SCSI host scan is over.
4438 **/
James Smart47a86172007-04-25 09:53:22 -04004439int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4440{
James Smart2e0fef82007-06-17 19:56:36 -05004441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4442 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004443 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004444
James Smart858c9f62007-06-17 19:56:39 -05004445 spin_lock_irq(shost->host_lock);
4446
James Smart51ef4c22007-08-02 11:10:31 -04004447 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004448 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004449 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004450 }
James Smart256ec0d2013-04-17 20:14:58 -04004451 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004452 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004453 "0461 Scanning longer than 30 "
4454 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004455 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004456 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004457 }
James Smart256ec0d2013-04-17 20:14:58 -04004458 if (time >= msecs_to_jiffies(15 * 1000) &&
4459 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004461 "0465 Link down longer than 15 "
4462 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004463 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004464 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004465 }
4466
James Smart2e0fef82007-06-17 19:56:36 -05004467 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004468 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004469 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004470 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004471 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004472 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004473 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004474 goto finished;
4475
4476 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004477
4478finished:
James Smart858c9f62007-06-17 19:56:39 -05004479 spin_unlock_irq(shost->host_lock);
4480 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004481}
4482
Bart Van Assche3999df72019-03-28 11:06:16 -07004483static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
James Smartcd713482018-10-23 13:41:01 -07004484{
4485 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4486 struct lpfc_hba *phba = vport->phba;
4487
4488 fc_host_supported_speeds(shost) = 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004489 if (phba->lmt & LMT_128Gb)
4490 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004491 if (phba->lmt & LMT_64Gb)
4492 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4493 if (phba->lmt & LMT_32Gb)
4494 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4495 if (phba->lmt & LMT_16Gb)
4496 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4497 if (phba->lmt & LMT_10Gb)
4498 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4499 if (phba->lmt & LMT_8Gb)
4500 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4501 if (phba->lmt & LMT_4Gb)
4502 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4503 if (phba->lmt & LMT_2Gb)
4504 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4505 if (phba->lmt & LMT_1Gb)
4506 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4507}
4508
James Smarte59058c2008-08-24 21:49:00 -04004509/**
James Smart3621a712009-04-06 18:47:14 -04004510 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004511 * @shost: pointer to SCSI host data structure.
4512 *
4513 * This routine initializes a given SCSI host attributes on a FC port. The
4514 * SCSI host can be either on top of a physical port or a virtual port.
4515 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004516void lpfc_host_attrib_init(struct Scsi_Host *shost)
4517{
4518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4519 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004520 /*
James Smart2e0fef82007-06-17 19:56:36 -05004521 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004522 */
4523
James Smart2e0fef82007-06-17 19:56:36 -05004524 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4525 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004526 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4527
4528 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004529 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004530 fc_host_supported_fc4s(shost)[2] = 1;
4531 fc_host_supported_fc4s(shost)[7] = 1;
4532
James Smart92d7f7b2007-06-17 19:56:38 -05004533 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4534 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004535
James Smartcd713482018-10-23 13:41:01 -07004536 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004537
4538 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004539 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4540 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004541
Mike Christie0af5d702010-09-15 16:52:31 -05004542 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4543
James Smart47a86172007-04-25 09:53:22 -04004544 /* This value is also unchanging */
4545 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004546 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004547 fc_host_active_fc4s(shost)[2] = 1;
4548 fc_host_active_fc4s(shost)[7] = 1;
4549
James Smart92d7f7b2007-06-17 19:56:38 -05004550 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004551 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004552 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004553 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004554}
dea31012005-04-17 16:05:31 -05004555
James Smarte59058c2008-08-24 21:49:00 -04004556/**
James Smartda0436e2009-05-22 14:51:39 -04004557 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004558 * @phba: pointer to lpfc hba data structure.
4559 *
James Smartda0436e2009-05-22 14:51:39 -04004560 * This routine is invoked to stop an SLI3 device port, it stops the device
4561 * from generating interrupts and stops the device driver's timers for the
4562 * device.
James Smarte59058c2008-08-24 21:49:00 -04004563 **/
James Smartdb2378e2008-02-08 18:49:51 -05004564static void
James Smartda0436e2009-05-22 14:51:39 -04004565lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004566{
James Smartda0436e2009-05-22 14:51:39 -04004567 /* Clear all interrupt enable conditions */
4568 writel(0, phba->HCregaddr);
4569 readl(phba->HCregaddr); /* flush */
4570 /* Clear all pending interrupts */
4571 writel(0xffffffff, phba->HAregaddr);
4572 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004573
James Smartda0436e2009-05-22 14:51:39 -04004574 /* Reset some HBA SLI setup states */
4575 lpfc_stop_hba_timers(phba);
4576 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004577}
4578
James Smarte59058c2008-08-24 21:49:00 -04004579/**
James Smartda0436e2009-05-22 14:51:39 -04004580 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004581 * @phba: pointer to lpfc hba data structure.
4582 *
James Smartda0436e2009-05-22 14:51:39 -04004583 * This routine is invoked to stop an SLI4 device port, it stops the device
4584 * from generating interrupts and stops the device driver's timers for the
4585 * device.
4586 **/
4587static void
4588lpfc_stop_port_s4(struct lpfc_hba *phba)
4589{
4590 /* Reset some HBA SLI4 setup states */
4591 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -08004592 if (phba->pport)
4593 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -04004594 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004595}
4596
4597/**
4598 * lpfc_stop_port - Wrapper function for stopping hba port
4599 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004600 *
James Smartda0436e2009-05-22 14:51:39 -04004601 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4602 * the API jump table function pointer from the lpfc_hba struct.
4603 **/
4604void
4605lpfc_stop_port(struct lpfc_hba *phba)
4606{
4607 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004608
4609 if (phba->wq)
4610 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004611}
4612
4613/**
James Smartecfd03c2010-02-12 14:41:27 -05004614 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4615 * @phba: Pointer to hba for which this call is being executed.
4616 *
4617 * This routine starts the timer waiting for the FCF rediscovery to complete.
4618 **/
4619void
4620lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4621{
4622 unsigned long fcf_redisc_wait_tmo =
4623 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4624 /* Start fcf rediscovery wait period timer */
4625 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4626 spin_lock_irq(&phba->hbalock);
4627 /* Allow action to new fcf asynchronous event */
4628 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4629 /* Mark the FCF rediscovery pending state */
4630 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4631 spin_unlock_irq(&phba->hbalock);
4632}
4633
4634/**
4635 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4636 * @ptr: Map to lpfc_hba data structure pointer.
4637 *
4638 * This routine is invoked when waiting for FCF table rediscover has been
4639 * timed out. If new FCF record(s) has (have) been discovered during the
4640 * wait period, a new FCF event shall be added to the FCOE async event
4641 * list, and then worker thread shall be waked up for processing from the
4642 * worker thread context.
4643 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004644static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004645lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004646{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004647 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004648
4649 /* Don't send FCF rediscovery event if timer cancelled */
4650 spin_lock_irq(&phba->hbalock);
4651 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4652 spin_unlock_irq(&phba->hbalock);
4653 return;
4654 }
4655 /* Clear FCF rediscovery timer pending flag */
4656 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4657 /* FCF rediscovery event to worker thread */
4658 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4659 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004660 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004661 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004662 /* wake up worker thread */
4663 lpfc_worker_wake_up(phba);
4664}
4665
4666/**
James Smartda0436e2009-05-22 14:51:39 -04004667 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4668 * @phba: pointer to lpfc hba data structure.
4669 * @acqe_link: pointer to the async link completion queue entry.
4670 *
James Smart23288b72018-05-04 20:37:53 -07004671 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004672 **/
James Smart23288b72018-05-04 20:37:53 -07004673static void
James Smartda0436e2009-05-22 14:51:39 -04004674lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4675 struct lpfc_acqe_link *acqe_link)
4676{
James Smartda0436e2009-05-22 14:51:39 -04004677 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4678 case LPFC_ASYNC_LINK_FAULT_NONE:
4679 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4680 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004681 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004682 break;
4683 default:
4684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004685 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004686 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004687 break;
4688 }
James Smartda0436e2009-05-22 14:51:39 -04004689}
4690
4691/**
4692 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4693 * @phba: pointer to lpfc hba data structure.
4694 * @acqe_link: pointer to the async link completion queue entry.
4695 *
4696 * This routine is to parse the SLI4 link attention type and translate it
4697 * into the base driver's link attention type coding.
4698 *
4699 * Return: Link attention type in terms of base driver's coding.
4700 **/
4701static uint8_t
4702lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4703 struct lpfc_acqe_link *acqe_link)
4704{
4705 uint8_t att_type;
4706
4707 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4708 case LPFC_ASYNC_LINK_STATUS_DOWN:
4709 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004710 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004711 break;
4712 case LPFC_ASYNC_LINK_STATUS_UP:
4713 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004714 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004715 break;
4716 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004717 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004718 break;
4719 default:
4720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4721 "0399 Invalid link attention type: x%x\n",
4722 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004723 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004724 break;
4725 }
4726 return att_type;
4727}
4728
4729/**
James Smart8b68cd52012-09-29 11:32:37 -04004730 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4731 * @phba: pointer to lpfc hba data structure.
4732 *
4733 * This routine is to get an SLI3 FC port's link speed in Mbps.
4734 *
4735 * Return: link speed in terms of Mbps.
4736 **/
4737uint32_t
4738lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4739{
4740 uint32_t link_speed;
4741
4742 if (!lpfc_is_link_up(phba))
4743 return 0;
4744
James Smarta085e872015-12-16 18:12:02 -05004745 if (phba->sli_rev <= LPFC_SLI_REV3) {
4746 switch (phba->fc_linkspeed) {
4747 case LPFC_LINK_SPEED_1GHZ:
4748 link_speed = 1000;
4749 break;
4750 case LPFC_LINK_SPEED_2GHZ:
4751 link_speed = 2000;
4752 break;
4753 case LPFC_LINK_SPEED_4GHZ:
4754 link_speed = 4000;
4755 break;
4756 case LPFC_LINK_SPEED_8GHZ:
4757 link_speed = 8000;
4758 break;
4759 case LPFC_LINK_SPEED_10GHZ:
4760 link_speed = 10000;
4761 break;
4762 case LPFC_LINK_SPEED_16GHZ:
4763 link_speed = 16000;
4764 break;
4765 default:
4766 link_speed = 0;
4767 }
4768 } else {
4769 if (phba->sli4_hba.link_state.logical_speed)
4770 link_speed =
4771 phba->sli4_hba.link_state.logical_speed;
4772 else
4773 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004774 }
4775 return link_speed;
4776}
4777
4778/**
4779 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4780 * @phba: pointer to lpfc hba data structure.
4781 * @evt_code: asynchronous event code.
4782 * @speed_code: asynchronous event link speed code.
4783 *
4784 * This routine is to parse the giving SLI4 async event link speed code into
4785 * value of Mbps for the link speed.
4786 *
4787 * Return: link speed in terms of Mbps.
4788 **/
4789static uint32_t
4790lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4791 uint8_t speed_code)
4792{
4793 uint32_t port_speed;
4794
4795 switch (evt_code) {
4796 case LPFC_TRAILER_CODE_LINK:
4797 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004798 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004799 port_speed = 0;
4800 break;
James Smart26d830e2015-04-07 15:07:17 -04004801 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004802 port_speed = 10;
4803 break;
James Smart26d830e2015-04-07 15:07:17 -04004804 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004805 port_speed = 100;
4806 break;
James Smart26d830e2015-04-07 15:07:17 -04004807 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004808 port_speed = 1000;
4809 break;
James Smart26d830e2015-04-07 15:07:17 -04004810 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004811 port_speed = 10000;
4812 break;
James Smart26d830e2015-04-07 15:07:17 -04004813 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4814 port_speed = 20000;
4815 break;
4816 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4817 port_speed = 25000;
4818 break;
4819 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4820 port_speed = 40000;
4821 break;
James Smart8b68cd52012-09-29 11:32:37 -04004822 default:
4823 port_speed = 0;
4824 }
4825 break;
4826 case LPFC_TRAILER_CODE_FC:
4827 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004828 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004829 port_speed = 0;
4830 break;
James Smart26d830e2015-04-07 15:07:17 -04004831 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004832 port_speed = 1000;
4833 break;
James Smart26d830e2015-04-07 15:07:17 -04004834 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004835 port_speed = 2000;
4836 break;
James Smart26d830e2015-04-07 15:07:17 -04004837 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004838 port_speed = 4000;
4839 break;
James Smart26d830e2015-04-07 15:07:17 -04004840 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004841 port_speed = 8000;
4842 break;
James Smart26d830e2015-04-07 15:07:17 -04004843 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004844 port_speed = 10000;
4845 break;
James Smart26d830e2015-04-07 15:07:17 -04004846 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004847 port_speed = 16000;
4848 break;
James Smartd38dd522015-08-31 16:48:17 -04004849 case LPFC_FC_LA_SPEED_32G:
4850 port_speed = 32000;
4851 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004852 case LPFC_FC_LA_SPEED_64G:
4853 port_speed = 64000;
4854 break;
James Smart1dc5ec22018-10-23 13:41:11 -07004855 case LPFC_FC_LA_SPEED_128G:
4856 port_speed = 128000;
4857 break;
James Smart8b68cd52012-09-29 11:32:37 -04004858 default:
4859 port_speed = 0;
4860 }
4861 break;
4862 default:
4863 port_speed = 0;
4864 }
4865 return port_speed;
4866}
4867
4868/**
James Smart70f3c072010-12-15 17:57:33 -05004869 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004870 * @phba: pointer to lpfc hba data structure.
4871 * @acqe_link: pointer to the async link completion queue entry.
4872 *
James Smart70f3c072010-12-15 17:57:33 -05004873 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004874 **/
4875static void
4876lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4877 struct lpfc_acqe_link *acqe_link)
4878{
4879 struct lpfc_dmabuf *mp;
4880 LPFC_MBOXQ_t *pmb;
4881 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004882 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004883 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004884 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004885
4886 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004887 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004888 return;
James Smart32b97932009-07-19 10:01:21 -04004889 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004890 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4891 if (!pmb) {
4892 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4893 "0395 The mboxq allocation failed\n");
4894 return;
4895 }
4896 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4897 if (!mp) {
4898 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4899 "0396 The lpfc_dmabuf allocation failed\n");
4900 goto out_free_pmb;
4901 }
4902 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4903 if (!mp->virt) {
4904 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4905 "0397 The mbuf allocation failed\n");
4906 goto out_free_dmabuf;
4907 }
4908
4909 /* Cleanup any outstanding ELS commands */
4910 lpfc_els_flush_all_cmd(phba);
4911
4912 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004913 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004914
4915 /* Update link event statistics */
4916 phba->sli.slistat.link_event++;
4917
James Smart76a95d72010-11-20 23:11:48 -05004918 /* Create lpfc_handle_latt mailbox command from link ACQE */
4919 lpfc_read_topology(phba, pmb, mp);
4920 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004921 pmb->vport = phba->pport;
4922
James Smartda0436e2009-05-22 14:51:39 -04004923 /* Keep the link status for extra SLI4 state machine reference */
4924 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004925 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4926 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004927 phba->sli4_hba.link_state.duplex =
4928 bf_get(lpfc_acqe_link_duplex, acqe_link);
4929 phba->sli4_hba.link_state.status =
4930 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004931 phba->sli4_hba.link_state.type =
4932 bf_get(lpfc_acqe_link_type, acqe_link);
4933 phba->sli4_hba.link_state.number =
4934 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004935 phba->sli4_hba.link_state.fault =
4936 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004937 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004938 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4939
James Smart70f3c072010-12-15 17:57:33 -05004940 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004941 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4942 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4943 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004944 phba->sli4_hba.link_state.speed,
4945 phba->sli4_hba.link_state.topology,
4946 phba->sli4_hba.link_state.status,
4947 phba->sli4_hba.link_state.type,
4948 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004949 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004950 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004951 /*
4952 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4953 * topology info. Note: Optional for non FC-AL ports.
4954 */
4955 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4956 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4957 if (rc == MBX_NOT_FINISHED)
4958 goto out_free_dmabuf;
4959 return;
4960 }
4961 /*
4962 * For FCoE Mode: fill in all the topology information we need and call
4963 * the READ_TOPOLOGY completion routine to continue without actually
4964 * sending the READ_TOPOLOGY mailbox command to the port.
4965 */
James Smart23288b72018-05-04 20:37:53 -07004966 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004967 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004968 mb->mbxStatus = MBX_SUCCESS;
4969
4970 /* Parse port fault information field */
4971 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004972
4973 /* Parse and translate link attention fields */
4974 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4975 la->eventTag = acqe_link->event_tag;
4976 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4977 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004978 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004979
4980 /* Fake the the following irrelvant fields */
4981 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4982 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4983 bf_set(lpfc_mbx_read_top_il, la, 0);
4984 bf_set(lpfc_mbx_read_top_pb, la, 0);
4985 bf_set(lpfc_mbx_read_top_fa, la, 0);
4986 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004987
4988 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004989 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004990
4991 return;
4992
4993out_free_dmabuf:
4994 kfree(mp);
4995out_free_pmb:
4996 mempool_free(pmb, phba->mbox_mem_pool);
4997}
4998
4999/**
James Smart1dc5ec22018-10-23 13:41:11 -07005000 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
5001 * topology.
5002 * @phba: pointer to lpfc hba data structure.
5003 * @evt_code: asynchronous event code.
5004 * @speed_code: asynchronous event link speed code.
5005 *
5006 * This routine is to parse the giving SLI4 async event link speed code into
5007 * value of Read topology link speed.
5008 *
5009 * Return: link speed in terms of Read topology.
5010 **/
5011static uint8_t
5012lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5013{
5014 uint8_t port_speed;
5015
5016 switch (speed_code) {
5017 case LPFC_FC_LA_SPEED_1G:
5018 port_speed = LPFC_LINK_SPEED_1GHZ;
5019 break;
5020 case LPFC_FC_LA_SPEED_2G:
5021 port_speed = LPFC_LINK_SPEED_2GHZ;
5022 break;
5023 case LPFC_FC_LA_SPEED_4G:
5024 port_speed = LPFC_LINK_SPEED_4GHZ;
5025 break;
5026 case LPFC_FC_LA_SPEED_8G:
5027 port_speed = LPFC_LINK_SPEED_8GHZ;
5028 break;
5029 case LPFC_FC_LA_SPEED_16G:
5030 port_speed = LPFC_LINK_SPEED_16GHZ;
5031 break;
5032 case LPFC_FC_LA_SPEED_32G:
5033 port_speed = LPFC_LINK_SPEED_32GHZ;
5034 break;
5035 case LPFC_FC_LA_SPEED_64G:
5036 port_speed = LPFC_LINK_SPEED_64GHZ;
5037 break;
5038 case LPFC_FC_LA_SPEED_128G:
5039 port_speed = LPFC_LINK_SPEED_128GHZ;
5040 break;
5041 case LPFC_FC_LA_SPEED_256G:
5042 port_speed = LPFC_LINK_SPEED_256GHZ;
5043 break;
5044 default:
5045 port_speed = 0;
5046 break;
5047 }
5048
5049 return port_speed;
5050}
5051
5052#define trunk_link_status(__idx)\
5053 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5054 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5055 "Link up" : "Link down") : "NA"
5056/* Did port __idx reported an error */
5057#define trunk_port_fault(__idx)\
5058 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5059 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5060
5061static void
5062lpfc_update_trunk_link_status(struct lpfc_hba *phba,
5063 struct lpfc_acqe_fc_la *acqe_fc)
5064{
5065 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
5066 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
5067
5068 phba->sli4_hba.link_state.speed =
5069 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5070 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5071
5072 phba->sli4_hba.link_state.logical_speed =
James Smartb8e6f132019-05-21 17:49:04 -07005073 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart1dc5ec22018-10-23 13:41:11 -07005074 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5075 phba->fc_linkspeed =
5076 lpfc_async_link_speed_to_read_top(
5077 phba,
5078 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5079
5080 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
5081 phba->trunk_link.link0.state =
5082 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
5083 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005084 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005085 }
5086 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
5087 phba->trunk_link.link1.state =
5088 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
5089 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005090 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005091 }
5092 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
5093 phba->trunk_link.link2.state =
5094 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
5095 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005096 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005097 }
5098 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
5099 phba->trunk_link.link3.state =
5100 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
5101 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005102 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005103 }
5104
5105 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5106 "2910 Async FC Trunking Event - Speed:%d\n"
5107 "\tLogical speed:%d "
5108 "port0: %s port1: %s port2: %s port3: %s\n",
5109 phba->sli4_hba.link_state.speed,
5110 phba->sli4_hba.link_state.logical_speed,
5111 trunk_link_status(0), trunk_link_status(1),
5112 trunk_link_status(2), trunk_link_status(3));
5113
5114 if (port_fault)
5115 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5116 "3202 trunk error:0x%x (%s) seen on port0:%s "
5117 /*
5118 * SLI-4: We have only 0xA error codes
5119 * defined as of now. print an appropriate
5120 * message in case driver needs to be updated.
5121 */
5122 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
5123 "UNDEFINED. update driver." : trunk_errmsg[err],
5124 trunk_port_fault(0), trunk_port_fault(1),
5125 trunk_port_fault(2), trunk_port_fault(3));
5126}
5127
5128
5129/**
James Smart70f3c072010-12-15 17:57:33 -05005130 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5131 * @phba: pointer to lpfc hba data structure.
5132 * @acqe_fc: pointer to the async fc completion queue entry.
5133 *
5134 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5135 * that the event was received and then issue a read_topology mailbox command so
5136 * that the rest of the driver will treat it the same as SLI3.
5137 **/
5138static void
5139lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
5140{
5141 struct lpfc_dmabuf *mp;
5142 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07005143 MAILBOX_t *mb;
5144 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05005145 int rc;
5146
5147 if (bf_get(lpfc_trailer_type, acqe_fc) !=
5148 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
5149 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5150 "2895 Non FC link Event detected.(%d)\n",
5151 bf_get(lpfc_trailer_type, acqe_fc));
5152 return;
5153 }
James Smart1dc5ec22018-10-23 13:41:11 -07005154
5155 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5156 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
5157 lpfc_update_trunk_link_status(phba, acqe_fc);
5158 return;
5159 }
5160
James Smart70f3c072010-12-15 17:57:33 -05005161 /* Keep the link status for extra SLI4 state machine reference */
5162 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04005163 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5164 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05005165 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
5166 phba->sli4_hba.link_state.topology =
5167 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
5168 phba->sli4_hba.link_state.status =
5169 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
5170 phba->sli4_hba.link_state.type =
5171 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
5172 phba->sli4_hba.link_state.number =
5173 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
5174 phba->sli4_hba.link_state.fault =
5175 bf_get(lpfc_acqe_link_fault, acqe_fc);
James Smartb8e6f132019-05-21 17:49:04 -07005176
5177 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5178 LPFC_FC_LA_TYPE_LINK_DOWN)
5179 phba->sli4_hba.link_state.logical_speed = 0;
5180 else if (!phba->sli4_hba.conf_trunk)
5181 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005182 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smartb8e6f132019-05-21 17:49:04 -07005183
James Smart70f3c072010-12-15 17:57:33 -05005184 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5185 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5186 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5187 "%dMbps Fault:%d\n",
5188 phba->sli4_hba.link_state.speed,
5189 phba->sli4_hba.link_state.topology,
5190 phba->sli4_hba.link_state.status,
5191 phba->sli4_hba.link_state.type,
5192 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04005193 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05005194 phba->sli4_hba.link_state.fault);
5195 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5196 if (!pmb) {
5197 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5198 "2897 The mboxq allocation failed\n");
5199 return;
5200 }
5201 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5202 if (!mp) {
5203 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5204 "2898 The lpfc_dmabuf allocation failed\n");
5205 goto out_free_pmb;
5206 }
5207 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5208 if (!mp->virt) {
5209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5210 "2899 The mbuf allocation failed\n");
5211 goto out_free_dmabuf;
5212 }
5213
5214 /* Cleanup any outstanding ELS commands */
5215 lpfc_els_flush_all_cmd(phba);
5216
5217 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08005218 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05005219
5220 /* Update link event statistics */
5221 phba->sli.slistat.link_event++;
5222
5223 /* Create lpfc_handle_latt mailbox command from link ACQE */
5224 lpfc_read_topology(phba, pmb, mp);
5225 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5226 pmb->vport = phba->pport;
5227
James Smart7bdedb32016-07-06 12:36:00 -07005228 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07005229 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
5230
5231 switch (phba->sli4_hba.link_state.status) {
5232 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
5233 phba->link_flag |= LS_MDS_LINK_DOWN;
5234 break;
5235 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
5236 phba->link_flag |= LS_MDS_LOOPBACK;
5237 break;
5238 default:
5239 break;
5240 }
5241
James Smart23288b72018-05-04 20:37:53 -07005242 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07005243 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07005244 mb->mbxStatus = MBX_SUCCESS;
5245
5246 /* Parse port fault information field */
5247 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07005248
5249 /* Parse and translate link attention fields */
5250 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
5251 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07005252
James Smartaeb3c812017-04-21 16:05:02 -07005253 if (phba->sli4_hba.link_state.status ==
5254 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
5255 bf_set(lpfc_mbx_read_top_att_type, la,
5256 LPFC_FC_LA_TYPE_UNEXP_WWPN);
5257 } else {
5258 bf_set(lpfc_mbx_read_top_att_type, la,
5259 LPFC_FC_LA_TYPE_LINK_DOWN);
5260 }
James Smart7bdedb32016-07-06 12:36:00 -07005261 /* Invoke the mailbox command callback function */
5262 lpfc_mbx_cmpl_read_topology(phba, pmb);
5263
5264 return;
5265 }
5266
James Smart70f3c072010-12-15 17:57:33 -05005267 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5268 if (rc == MBX_NOT_FINISHED)
5269 goto out_free_dmabuf;
5270 return;
5271
5272out_free_dmabuf:
5273 kfree(mp);
5274out_free_pmb:
5275 mempool_free(pmb, phba->mbox_mem_pool);
5276}
5277
5278/**
5279 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5280 * @phba: pointer to lpfc hba data structure.
5281 * @acqe_fc: pointer to the async SLI completion queue entry.
5282 *
5283 * This routine is to handle the SLI4 asynchronous SLI events.
5284 **/
5285static void
5286lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
5287{
James Smart4b8bae02012-06-12 13:55:07 -04005288 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04005289 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04005290 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04005291 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05005292 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04005293 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04005294 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04005295 struct Scsi_Host *shost;
James Smartcd713482018-10-23 13:41:01 -07005296 struct lpfc_vport **vports;
5297 int rc, i;
James Smart4b8bae02012-06-12 13:55:07 -04005298
James Smart946727d2015-04-07 15:07:09 -04005299 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
5300
James Smart448193b2015-12-16 18:12:05 -05005301 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5302 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
5303 "x%08x SLI Event Type:%d\n",
5304 acqe_sli->event_data1, acqe_sli->event_data2,
5305 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005306
5307 port_name = phba->Port[0];
5308 if (port_name == 0x00)
5309 port_name = '?'; /* get port name is empty */
5310
James Smart946727d2015-04-07 15:07:09 -04005311 switch (evt_type) {
5312 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
5313 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5314 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
5315 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5316
5317 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5318 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5319 acqe_sli->event_data1, port_name);
5320
James Smart310429e2016-07-06 12:35:54 -07005321 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04005322 shost = lpfc_shost_from_vport(phba->pport);
5323 fc_host_post_vendor_event(shost, fc_get_event_number(),
5324 sizeof(temp_event_data),
5325 (char *)&temp_event_data,
5326 SCSI_NL_VID_TYPE_PCI
5327 | PCI_VENDOR_ID_EMULEX);
5328 break;
5329 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
5330 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5331 temp_event_data.event_code = LPFC_NORMAL_TEMP;
5332 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5333
5334 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5335 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5336 acqe_sli->event_data1, port_name);
5337
5338 shost = lpfc_shost_from_vport(phba->pport);
5339 fc_host_post_vendor_event(shost, fc_get_event_number(),
5340 sizeof(temp_event_data),
5341 (char *)&temp_event_data,
5342 SCSI_NL_VID_TYPE_PCI
5343 | PCI_VENDOR_ID_EMULEX);
5344 break;
5345 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
5346 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04005347 &acqe_sli->event_data1;
5348
James Smart946727d2015-04-07 15:07:09 -04005349 /* fetch the status for this port */
5350 switch (phba->sli4_hba.lnk_info.lnk_no) {
5351 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05005352 status = bf_get(lpfc_sli_misconfigured_port0_state,
5353 &misconfigured->theEvent);
5354 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04005355 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005356 break;
5357 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05005358 status = bf_get(lpfc_sli_misconfigured_port1_state,
5359 &misconfigured->theEvent);
5360 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04005361 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005362 break;
5363 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05005364 status = bf_get(lpfc_sli_misconfigured_port2_state,
5365 &misconfigured->theEvent);
5366 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04005367 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005368 break;
5369 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05005370 status = bf_get(lpfc_sli_misconfigured_port3_state,
5371 &misconfigured->theEvent);
5372 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04005373 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005374 break;
5375 default:
James Smart448193b2015-12-16 18:12:05 -05005376 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5377 "3296 "
5378 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5379 "event: Invalid link %d",
5380 phba->sli4_hba.lnk_info.lnk_no);
5381 return;
James Smart946727d2015-04-07 15:07:09 -04005382 }
James Smart4b8bae02012-06-12 13:55:07 -04005383
James Smart448193b2015-12-16 18:12:05 -05005384 /* Skip if optic state unchanged */
5385 if (phba->sli4_hba.lnk_info.optic_state == status)
5386 return;
5387
James Smart946727d2015-04-07 15:07:09 -04005388 switch (status) {
5389 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05005390 sprintf(message, "Physical Link is functional");
5391 break;
James Smart946727d2015-04-07 15:07:09 -04005392 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5393 sprintf(message, "Optics faulted/incorrectly "
5394 "installed/not installed - Reseat optics, "
5395 "if issue not resolved, replace.");
5396 break;
5397 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5398 sprintf(message,
5399 "Optics of two types installed - Remove one "
5400 "optic or install matching pair of optics.");
5401 break;
5402 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5403 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04005404 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04005405 break;
James Smart448193b2015-12-16 18:12:05 -05005406 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5407 sprintf(message, "Unqualified optics - Replace with "
5408 "Avago optics for Warranty and Technical "
5409 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005410 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005411 break;
5412 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5413 sprintf(message, "Uncertified optics - Replace with "
5414 "Avago-certified optics to enable link "
5415 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005416 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005417 break;
James Smart946727d2015-04-07 15:07:09 -04005418 default:
5419 /* firmware is reporting a status we don't know about */
5420 sprintf(message, "Unknown event status x%02x", status);
5421 break;
5422 }
James Smartcd713482018-10-23 13:41:01 -07005423
5424 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5425 rc = lpfc_sli4_read_config(phba);
James Smart3952e912018-10-23 13:41:02 -07005426 if (rc) {
James Smartcd713482018-10-23 13:41:01 -07005427 phba->lmt = 0;
5428 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5429 "3194 Unable to retrieve supported "
James Smart3952e912018-10-23 13:41:02 -07005430 "speeds, rc = 0x%x\n", rc);
James Smartcd713482018-10-23 13:41:01 -07005431 }
5432 vports = lpfc_create_vport_work_array(phba);
5433 if (vports != NULL) {
5434 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5435 i++) {
5436 shost = lpfc_shost_from_vport(vports[i]);
5437 lpfc_host_supported_speeds_set(shost);
5438 }
5439 }
5440 lpfc_destroy_vport_work_array(phba, vports);
5441
James Smart448193b2015-12-16 18:12:05 -05005442 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04005443 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05005444 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04005445 break;
5446 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5447 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5448 "3192 Remote DPort Test Initiated - "
5449 "Event Data1:x%08x Event Data2: x%08x\n",
5450 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04005451 break;
5452 default:
James Smart946727d2015-04-07 15:07:09 -04005453 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5454 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
5455 "x%08x SLI Event Type:%d\n",
5456 acqe_sli->event_data1, acqe_sli->event_data2,
5457 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005458 break;
5459 }
James Smart70f3c072010-12-15 17:57:33 -05005460}
5461
5462/**
James Smartfc2b9892010-02-26 14:15:29 -05005463 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5464 * @vport: pointer to vport data structure.
5465 *
5466 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5467 * response to a CVL event.
5468 *
5469 * Return the pointer to the ndlp with the vport if successful, otherwise
5470 * return NULL.
5471 **/
5472static struct lpfc_nodelist *
5473lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
5474{
5475 struct lpfc_nodelist *ndlp;
5476 struct Scsi_Host *shost;
5477 struct lpfc_hba *phba;
5478
5479 if (!vport)
5480 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05005481 phba = vport->phba;
5482 if (!phba)
5483 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04005484 ndlp = lpfc_findnode_did(vport, Fabric_DID);
5485 if (!ndlp) {
5486 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07005487 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04005488 if (!ndlp)
5489 return 0;
James Smart78730cf2010-04-06 15:06:30 -04005490 /* Set the node type */
5491 ndlp->nlp_type |= NLP_FABRIC;
5492 /* Put ndlp onto node list */
5493 lpfc_enqueue_node(vport, ndlp);
5494 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5495 /* re-setup ndlp without removing from node list */
5496 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5497 if (!ndlp)
5498 return 0;
5499 }
James Smart63e801c2010-11-20 23:14:19 -05005500 if ((phba->pport->port_state < LPFC_FLOGI) &&
5501 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005502 return NULL;
5503 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05005504 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
5505 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005506 return NULL;
5507 shost = lpfc_shost_from_vport(vport);
5508 if (!shost)
5509 return NULL;
5510 lpfc_linkdown_port(vport);
5511 lpfc_cleanup_pending_mbox(vport);
5512 spin_lock_irq(shost->host_lock);
5513 vport->fc_flag |= FC_VPORT_CVL_RCVD;
5514 spin_unlock_irq(shost->host_lock);
5515
5516 return ndlp;
5517}
5518
5519/**
5520 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
5521 * @vport: pointer to lpfc hba data structure.
5522 *
5523 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5524 * response to a FCF dead event.
5525 **/
5526static void
5527lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
5528{
5529 struct lpfc_vport **vports;
5530 int i;
5531
5532 vports = lpfc_create_vport_work_array(phba);
5533 if (vports)
5534 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
5535 lpfc_sli4_perform_vport_cvl(vports[i]);
5536 lpfc_destroy_vport_work_array(phba, vports);
5537}
5538
5539/**
James Smart76a95d72010-11-20 23:11:48 -05005540 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04005541 * @phba: pointer to lpfc hba data structure.
5542 * @acqe_link: pointer to the async fcoe completion queue entry.
5543 *
5544 * This routine is to handle the SLI4 asynchronous fcoe event.
5545 **/
5546static void
James Smart76a95d72010-11-20 23:11:48 -05005547lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05005548 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04005549{
James Smart70f3c072010-12-15 17:57:33 -05005550 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005551 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04005552 struct lpfc_vport *vport;
5553 struct lpfc_nodelist *ndlp;
5554 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05005555 int active_vlink_present;
5556 struct lpfc_vport **vports;
5557 int i;
James Smartda0436e2009-05-22 14:51:39 -04005558
James Smart70f3c072010-12-15 17:57:33 -05005559 phba->fc_eventTag = acqe_fip->event_tag;
5560 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005561 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005562 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5563 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5564 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04005565 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5566 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005567 "2546 New FCF event, evt_tag:x%x, "
5568 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005569 acqe_fip->event_tag,
5570 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005571 else
5572 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5573 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005574 "2788 FCF param modified event, "
5575 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005576 acqe_fip->event_tag,
5577 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005578 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005579 /*
5580 * During period of FCF discovery, read the FCF
5581 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005582 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005583 */
5584 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5585 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005586 "2779 Read FCF (x%x) for updating "
5587 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005588 acqe_fip->index);
5589 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005590 }
James Smart38b92ef2010-08-04 16:11:39 -04005591
5592 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005593 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005594 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005595 spin_unlock_irq(&phba->hbalock);
5596 break;
5597 }
5598 /* If fast FCF failover rescan event is pending, do nothing */
James Smart036cad12018-10-23 13:41:06 -07005599 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
James Smart38b92ef2010-08-04 16:11:39 -04005600 spin_unlock_irq(&phba->hbalock);
5601 break;
5602 }
5603
James Smartc2b97122013-05-31 17:05:36 -04005604 /* If the FCF has been in discovered state, do nothing. */
5605 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005606 spin_unlock_irq(&phba->hbalock);
5607 break;
5608 }
5609 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005610
James Smart0c9ab6f2010-02-26 14:15:57 -05005611 /* Otherwise, scan the entire FCF table and re-discover SAN */
5612 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005613 "2770 Start FCF table scan per async FCF "
5614 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005615 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005616 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5617 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005618 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005619 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5620 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005621 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005622 break;
5623
James Smart70f3c072010-12-15 17:57:33 -05005624 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005625 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005626 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005627 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5628 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005629 break;
5630
James Smart70f3c072010-12-15 17:57:33 -05005631 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005632 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005633 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005634 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005635 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005636 /*
5637 * If we are in the middle of FCF failover process, clear
5638 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005639 */
James Smartfc2b9892010-02-26 14:15:29 -05005640 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005641 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5642 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005643 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005644 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005645 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005646 break;
5647 }
James Smart38b92ef2010-08-04 16:11:39 -04005648 spin_unlock_irq(&phba->hbalock);
5649
5650 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005651 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005652 break;
5653
5654 /*
5655 * Otherwise, request the port to rediscover the entire FCF
5656 * table for a fast recovery from case that the current FCF
5657 * is no longer valid as we are not in the middle of FCF
5658 * failover process already.
5659 */
James Smartc2b97122013-05-31 17:05:36 -04005660 spin_lock_irq(&phba->hbalock);
5661 /* Mark the fast failover process in progress */
5662 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5663 spin_unlock_irq(&phba->hbalock);
5664
5665 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5666 "2771 Start FCF fast failover process due to "
5667 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5668 "\n", acqe_fip->event_tag, acqe_fip->index);
5669 rc = lpfc_sli4_redisc_fcf_table(phba);
5670 if (rc) {
5671 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5672 LOG_DISCOVERY,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005673 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005674 "command failed, fail through to FCF "
5675 "dead event\n");
5676 spin_lock_irq(&phba->hbalock);
5677 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5678 spin_unlock_irq(&phba->hbalock);
5679 /*
5680 * Last resort will fail over by treating this
5681 * as a link down to FCF registration.
5682 */
5683 lpfc_sli4_fcf_dead_failthrough(phba);
5684 } else {
5685 /* Reset FCF roundrobin bmask for new discovery */
5686 lpfc_sli4_clear_fcf_rr_bmask(phba);
5687 /*
5688 * Handling fast FCF failover to a DEAD FCF event is
5689 * considered equalivant to receiving CVL to all vports.
5690 */
5691 lpfc_sli4_perform_all_vport_cvl(phba);
5692 }
James Smartda0436e2009-05-22 14:51:39 -04005693 break;
James Smart70f3c072010-12-15 17:57:33 -05005694 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005695 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005696 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005697 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005698 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005699
James Smart6669f9b2009-10-02 15:16:45 -04005700 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005701 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005702 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005703 if (!ndlp)
5704 break;
James Smart695a8142010-01-26 23:08:03 -05005705 active_vlink_present = 0;
5706
5707 vports = lpfc_create_vport_work_array(phba);
5708 if (vports) {
5709 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5710 i++) {
5711 if ((!(vports[i]->fc_flag &
5712 FC_VPORT_CVL_RCVD)) &&
5713 (vports[i]->port_state > LPFC_FDISC)) {
5714 active_vlink_present = 1;
5715 break;
5716 }
5717 }
5718 lpfc_destroy_vport_work_array(phba, vports);
5719 }
5720
James Smartcc823552015-05-21 13:55:26 -04005721 /*
5722 * Don't re-instantiate if vport is marked for deletion.
5723 * If we are here first then vport_delete is going to wait
5724 * for discovery to complete.
5725 */
5726 if (!(vport->load_flag & FC_UNLOADING) &&
5727 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005728 /*
5729 * If there are other active VLinks present,
5730 * re-instantiate the Vlink using FDISC.
5731 */
James Smart256ec0d2013-04-17 20:14:58 -04005732 mod_timer(&ndlp->nlp_delayfunc,
5733 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005734 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005735 spin_lock_irq(shost->host_lock);
5736 ndlp->nlp_flag |= NLP_DELAY_TMO;
5737 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005738 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5739 vport->port_state = LPFC_FDISC;
5740 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005741 /*
5742 * Otherwise, we request port to rediscover
5743 * the entire FCF table for a fast recovery
5744 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005745 * is no longer valid if we are not already
5746 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005747 */
James Smartfc2b9892010-02-26 14:15:29 -05005748 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005749 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005750 spin_unlock_irq(&phba->hbalock);
5751 break;
5752 }
5753 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005754 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005755 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005756 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5757 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005758 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005759 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005760 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005761 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005762 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5763 LOG_DISCOVERY,
5764 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005765 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005766 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005767 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005768 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005769 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005770 /*
5771 * Last resort will be re-try on the
5772 * the current registered FCF entry.
5773 */
5774 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005775 } else
5776 /*
5777 * Reset FCF roundrobin bmask for new
5778 * discovery.
5779 */
James Smart7d791df2011-07-22 18:37:52 -04005780 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005781 }
5782 break;
James Smartda0436e2009-05-22 14:51:39 -04005783 default:
5784 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5785 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005786 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005787 break;
5788 }
5789}
5790
5791/**
5792 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5793 * @phba: pointer to lpfc hba data structure.
5794 * @acqe_link: pointer to the async dcbx completion queue entry.
5795 *
5796 * This routine is to handle the SLI4 asynchronous dcbx event.
5797 **/
5798static void
5799lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5800 struct lpfc_acqe_dcbx *acqe_dcbx)
5801{
James Smart4d9ab992009-10-02 15:16:39 -04005802 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005803 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5804 "0290 The SLI4 DCBX asynchronous event is not "
5805 "handled yet\n");
5806}
5807
5808/**
James Smartb19a0612010-04-06 14:48:51 -04005809 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5810 * @phba: pointer to lpfc hba data structure.
5811 * @acqe_link: pointer to the async grp5 completion queue entry.
5812 *
5813 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5814 * is an asynchronous notified of a logical link speed change. The Port
5815 * reports the logical link speed in units of 10Mbps.
5816 **/
5817static void
5818lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5819 struct lpfc_acqe_grp5 *acqe_grp5)
5820{
5821 uint16_t prev_ll_spd;
5822
5823 phba->fc_eventTag = acqe_grp5->event_tag;
5824 phba->fcoe_eventtag = acqe_grp5->event_tag;
5825 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5826 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005827 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005828 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5829 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005830 "from %dMbps to %dMbps\n", prev_ll_spd,
5831 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005832}
5833
5834/**
James Smartda0436e2009-05-22 14:51:39 -04005835 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5836 * @phba: pointer to lpfc hba data structure.
5837 *
5838 * This routine is invoked by the worker thread to process all the pending
5839 * SLI4 asynchronous events.
5840 **/
5841void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5842{
5843 struct lpfc_cq_event *cq_event;
5844
5845 /* First, declare the async event has been handled */
5846 spin_lock_irq(&phba->hbalock);
5847 phba->hba_flag &= ~ASYNC_EVENT;
5848 spin_unlock_irq(&phba->hbalock);
5849 /* Now, handle all the async events */
5850 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5851 /* Get the first event from the head of the event queue */
5852 spin_lock_irq(&phba->hbalock);
5853 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5854 cq_event, struct lpfc_cq_event, list);
5855 spin_unlock_irq(&phba->hbalock);
5856 /* Process the asynchronous event */
5857 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5858 case LPFC_TRAILER_CODE_LINK:
5859 lpfc_sli4_async_link_evt(phba,
5860 &cq_event->cqe.acqe_link);
5861 break;
5862 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005863 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005864 break;
5865 case LPFC_TRAILER_CODE_DCBX:
5866 lpfc_sli4_async_dcbx_evt(phba,
5867 &cq_event->cqe.acqe_dcbx);
5868 break;
James Smartb19a0612010-04-06 14:48:51 -04005869 case LPFC_TRAILER_CODE_GRP5:
5870 lpfc_sli4_async_grp5_evt(phba,
5871 &cq_event->cqe.acqe_grp5);
5872 break;
James Smart70f3c072010-12-15 17:57:33 -05005873 case LPFC_TRAILER_CODE_FC:
5874 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5875 break;
5876 case LPFC_TRAILER_CODE_SLI:
5877 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5878 break;
James Smartda0436e2009-05-22 14:51:39 -04005879 default:
5880 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5881 "1804 Invalid asynchrous event code: "
5882 "x%x\n", bf_get(lpfc_trailer_code,
5883 &cq_event->cqe.mcqe_cmpl));
5884 break;
5885 }
5886 /* Free the completion event processed to the free pool */
5887 lpfc_sli4_cq_event_release(phba, cq_event);
5888 }
5889}
5890
5891/**
James Smartecfd03c2010-02-12 14:41:27 -05005892 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5893 * @phba: pointer to lpfc hba data structure.
5894 *
5895 * This routine is invoked by the worker thread to process FCF table
5896 * rediscovery pending completion event.
5897 **/
5898void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5899{
5900 int rc;
5901
5902 spin_lock_irq(&phba->hbalock);
5903 /* Clear FCF rediscovery timeout event */
5904 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5905 /* Clear driver fast failover FCF record flag */
5906 phba->fcf.failover_rec.flag = 0;
5907 /* Set state for FCF fast failover */
5908 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5909 spin_unlock_irq(&phba->hbalock);
5910
5911 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005912 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005913 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005914 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005915 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005916 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5917 "2747 Issue FCF scan read FCF mailbox "
5918 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005919}
5920
5921/**
James Smartda0436e2009-05-22 14:51:39 -04005922 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5923 * @phba: pointer to lpfc hba data structure.
5924 * @dev_grp: The HBA PCI-Device group number.
5925 *
5926 * This routine is invoked to set up the per HBA PCI-Device group function
5927 * API jump table entries.
5928 *
5929 * Return: 0 if success, otherwise -ENODEV
5930 **/
5931int
5932lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005933{
5934 int rc;
5935
James Smartda0436e2009-05-22 14:51:39 -04005936 /* Set up lpfc PCI-device group */
5937 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005938
James Smartda0436e2009-05-22 14:51:39 -04005939 /* The LPFC_PCI_DEV_OC uses SLI4 */
5940 if (dev_grp == LPFC_PCI_DEV_OC)
5941 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005942
James Smartda0436e2009-05-22 14:51:39 -04005943 /* Set up device INIT API function jump table */
5944 rc = lpfc_init_api_table_setup(phba, dev_grp);
5945 if (rc)
5946 return -ENODEV;
5947 /* Set up SCSI API function jump table */
5948 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5949 if (rc)
5950 return -ENODEV;
5951 /* Set up SLI API function jump table */
5952 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5953 if (rc)
5954 return -ENODEV;
5955 /* Set up MBOX API function jump table */
5956 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5957 if (rc)
5958 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005959
James Smartda0436e2009-05-22 14:51:39 -04005960 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005961}
5962
5963/**
James Smart3621a712009-04-06 18:47:14 -04005964 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005965 * @phba: pointer to lpfc hba data structure.
5966 * @intr_mode: active interrupt mode adopted.
5967 *
5968 * This routine it invoked to log the currently used active interrupt mode
5969 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005970 **/
5971static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005972{
5973 switch (intr_mode) {
5974 case 0:
5975 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5976 "0470 Enable INTx interrupt mode.\n");
5977 break;
5978 case 1:
5979 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5980 "0481 Enabled MSI interrupt mode.\n");
5981 break;
5982 case 2:
5983 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5984 "0480 Enabled MSI-X interrupt mode.\n");
5985 break;
5986 default:
5987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5988 "0482 Illegal interrupt mode.\n");
5989 break;
5990 }
5991 return;
5992}
5993
James Smart5b75da22008-12-04 22:39:35 -05005994/**
James Smart3772a992009-05-22 14:50:54 -04005995 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005996 * @phba: pointer to lpfc hba data structure.
5997 *
James Smart3772a992009-05-22 14:50:54 -04005998 * This routine is invoked to enable the PCI device that is common to all
5999 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05006000 *
6001 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006002 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006003 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05006004 **/
James Smart3772a992009-05-22 14:50:54 -04006005static int
6006lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05006007{
James Smart3772a992009-05-22 14:50:54 -04006008 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05006009
James Smart3772a992009-05-22 14:50:54 -04006010 /* Obtain PCI device reference */
6011 if (!phba->pcidev)
6012 goto out_error;
6013 else
6014 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006015 /* Enable PCI device */
6016 if (pci_enable_device_mem(pdev))
6017 goto out_error;
6018 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006019 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04006020 goto out_disable_device;
6021 /* Set up device as PCI master and save state for EEH */
6022 pci_set_master(pdev);
6023 pci_try_set_mwi(pdev);
6024 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006025
James Smart05580562011-05-24 11:40:48 -04006026 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07006027 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04006028 pdev->needs_freset = 1;
6029
James Smart3772a992009-05-22 14:50:54 -04006030 return 0;
James Smart5b75da22008-12-04 22:39:35 -05006031
James Smart3772a992009-05-22 14:50:54 -04006032out_disable_device:
6033 pci_disable_device(pdev);
6034out_error:
James Smart079b5c92011-08-21 21:48:49 -04006035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006036 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04006037 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05006038}
6039
6040/**
James Smart3772a992009-05-22 14:50:54 -04006041 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05006042 * @phba: pointer to lpfc hba data structure.
6043 *
James Smart3772a992009-05-22 14:50:54 -04006044 * This routine is invoked to disable the PCI device that is common to all
6045 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05006046 **/
6047static void
James Smart3772a992009-05-22 14:50:54 -04006048lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05006049{
James Smart3772a992009-05-22 14:50:54 -04006050 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05006051
James Smart3772a992009-05-22 14:50:54 -04006052 /* Obtain PCI device reference */
6053 if (!phba->pcidev)
6054 return;
6055 else
6056 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006057 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006058 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04006059 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006060
6061 return;
6062}
6063
6064/**
James Smart3772a992009-05-22 14:50:54 -04006065 * lpfc_reset_hba - Reset a hba
6066 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04006067 *
James Smart3772a992009-05-22 14:50:54 -04006068 * This routine is invoked to reset a hba device. It brings the HBA
6069 * offline, performs a board restart, and then brings the board back
6070 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6071 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04006072 **/
James Smart3772a992009-05-22 14:50:54 -04006073void
6074lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05006075{
James Smart3772a992009-05-22 14:50:54 -04006076 /* If resets are disabled then set error state and return. */
6077 if (!phba->cfg_enable_hba_reset) {
6078 phba->link_state = LPFC_HBA_ERROR;
6079 return;
6080 }
James Smartee620212014-04-04 13:51:53 -04006081 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
6082 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6083 else
6084 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04006085 lpfc_offline(phba);
6086 lpfc_sli_brdrestart(phba);
6087 lpfc_online(phba);
6088 lpfc_unblock_mgmt_io(phba);
6089}
dea31012005-04-17 16:05:31 -05006090
James Smart3772a992009-05-22 14:50:54 -04006091/**
James Smart0a96e972011-07-22 18:37:28 -04006092 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6093 * @phba: pointer to lpfc hba data structure.
6094 *
6095 * This function enables the PCI SR-IOV virtual functions to a physical
6096 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6097 * enable the number of virtual functions to the physical function. As
6098 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6099 * API call does not considered as an error condition for most of the device.
6100 **/
6101uint16_t
6102lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
6103{
6104 struct pci_dev *pdev = phba->pcidev;
6105 uint16_t nr_virtfn;
6106 int pos;
6107
James Smart0a96e972011-07-22 18:37:28 -04006108 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6109 if (pos == 0)
6110 return 0;
6111
6112 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
6113 return nr_virtfn;
6114}
6115
6116/**
James Smart912e3ac2011-05-24 11:42:11 -04006117 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6118 * @phba: pointer to lpfc hba data structure.
6119 * @nr_vfn: number of virtual functions to be enabled.
6120 *
6121 * This function enables the PCI SR-IOV virtual functions to a physical
6122 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6123 * enable the number of virtual functions to the physical function. As
6124 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6125 * API call does not considered as an error condition for most of the device.
6126 **/
6127int
6128lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
6129{
6130 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04006131 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04006132 int rc;
6133
James Smart0a96e972011-07-22 18:37:28 -04006134 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
6135 if (nr_vfn > max_nr_vfn) {
6136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6137 "3057 Requested vfs (%d) greater than "
6138 "supported vfs (%d)", nr_vfn, max_nr_vfn);
6139 return -EINVAL;
6140 }
6141
James Smart912e3ac2011-05-24 11:42:11 -04006142 rc = pci_enable_sriov(pdev, nr_vfn);
6143 if (rc) {
6144 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6145 "2806 Failed to enable sriov on this device "
6146 "with vfn number nr_vf:%d, rc:%d\n",
6147 nr_vfn, rc);
6148 } else
6149 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6150 "2807 Successful enable sriov on this device "
6151 "with vfn number nr_vf:%d\n", nr_vfn);
6152 return rc;
6153}
6154
6155/**
James Smart895427b2017-02-12 13:52:30 -08006156 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04006157 * @phba: pointer to lpfc hba data structure.
6158 *
James Smart895427b2017-02-12 13:52:30 -08006159 * This routine is invoked to set up the driver internal resources before the
6160 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04006161 *
6162 * Return codes
James Smart895427b2017-02-12 13:52:30 -08006163 * 0 - successful
6164 * other values - error
James Smart3772a992009-05-22 14:50:54 -04006165 **/
6166static int
James Smart895427b2017-02-12 13:52:30 -08006167lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04006168{
James Smart895427b2017-02-12 13:52:30 -08006169 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05006170
James Smart3772a992009-05-22 14:50:54 -04006171 /*
James Smart895427b2017-02-12 13:52:30 -08006172 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04006173 */
James Smart895427b2017-02-12 13:52:30 -08006174 atomic_set(&phba->fast_event_count, 0);
6175 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006176
James Smart895427b2017-02-12 13:52:30 -08006177 /* Initialize ndlp management spinlock */
6178 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04006179
James Smart523128e2018-09-10 10:30:46 -07006180 /* Initialize port_list spinlock */
6181 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08006182 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07006183
James Smart895427b2017-02-12 13:52:30 -08006184 INIT_LIST_HEAD(&phba->work_list);
6185 init_waitqueue_head(&phba->wait_4_mlo_m_q);
6186
6187 /* Initialize the wait queue head for the kernel thread */
6188 init_waitqueue_head(&phba->work_waitq);
6189
6190 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08006191 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08006192 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
6193 "SCSI" : " "),
6194 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08006195 "NVME" : " "),
6196 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08006197
James Smart0794d602019-01-28 11:14:19 -08006198 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
6199 spin_lock_init(&phba->scsi_buf_list_get_lock);
6200 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
6201 spin_lock_init(&phba->scsi_buf_list_put_lock);
6202 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart895427b2017-02-12 13:52:30 -08006203
6204 /* Initialize the fabric iocb list */
6205 INIT_LIST_HEAD(&phba->fabric_iocb_list);
6206
6207 /* Initialize list to save ELS buffers */
6208 INIT_LIST_HEAD(&phba->elsbuf);
6209
6210 /* Initialize FCF connection rec list */
6211 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
6212
6213 /* Initialize OAS configuration list */
6214 spin_lock_init(&phba->devicelock);
6215 INIT_LIST_HEAD(&phba->luns);
6216
James Smart3772a992009-05-22 14:50:54 -04006217 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006218 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006219 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006220 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006221 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006222 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08006223 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006224 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08006225
James Smart32517fc2019-01-28 11:14:33 -08006226 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
6227
James Smart895427b2017-02-12 13:52:30 -08006228 return 0;
6229}
6230
6231/**
6232 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
6233 * @phba: pointer to lpfc hba data structure.
6234 *
6235 * This routine is invoked to set up the driver internal resources specific to
6236 * support the SLI-3 HBA device it attached to.
6237 *
6238 * Return codes
6239 * 0 - successful
6240 * other values - error
6241 **/
6242static int
6243lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
6244{
James Smart0794d602019-01-28 11:14:19 -08006245 int rc, entry_sz;
James Smart895427b2017-02-12 13:52:30 -08006246
6247 /*
6248 * Initialize timers used by driver
6249 */
6250
6251 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006252 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006253
6254 /* Host attention work mask setup */
6255 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
6256 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
6257
6258 /* Get all the module params for configuring this host */
6259 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08006260 /* Set up phase-1 common device driver resources */
6261
6262 rc = lpfc_setup_driver_resource_phase1(phba);
6263 if (rc)
6264 return -ENODEV;
6265
James Smart49198b32010-04-06 15:04:33 -04006266 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
6267 phba->menlo_flag |= HBA_MENLO_SUPPORT;
6268 /* check for menlo minimum sg count */
6269 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
6270 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
6271 }
6272
James Smart895427b2017-02-12 13:52:30 -08006273 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07006274 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
6275 sizeof(struct lpfc_sli_ring),
6276 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006277 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04006278 return -ENOMEM;
6279
James Smart3772a992009-05-22 14:50:54 -04006280 /*
James Smart96f70772013-04-17 20:16:15 -04006281 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04006282 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04006283 */
James Smart3772a992009-05-22 14:50:54 -04006284
James Smart96f70772013-04-17 20:16:15 -04006285 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04006286 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08006287 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
6288 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04006289
James Smart0794d602019-01-28 11:14:19 -08006290 if (phba->sli_rev == LPFC_SLI_REV4)
6291 entry_sz = sizeof(struct sli4_sge);
6292 else
6293 entry_sz = sizeof(struct ulp_bde64);
6294
James Smart96f70772013-04-17 20:16:15 -04006295 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
6296 if (phba->cfg_enable_bg) {
6297 /*
6298 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
6299 * the FCP rsp, and a BDE for each. Sice we have no control
6300 * over how many protection data segments the SCSI Layer
6301 * will hand us (ie: there could be one for every block
6302 * in the IO), we just allocate enough BDEs to accomidate
6303 * our max amount and we need to limit lpfc_sg_seg_cnt to
6304 * minimize the risk of running out.
6305 */
6306 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6307 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006308 (LPFC_MAX_SG_SEG_CNT * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006309
6310 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
6311 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
6312
6313 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
6314 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
6315 } else {
6316 /*
6317 * The scsi_buf for a regular I/O will hold the FCP cmnd,
6318 * the FCP rsp, a BDE for each, and a BDE for up to
6319 * cfg_sg_seg_cnt data segments.
6320 */
6321 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6322 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006323 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006324
6325 /* Total BDEs in BPL for scsi_sg_list */
6326 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
6327 }
6328
6329 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
6330 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
6331 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6332 phba->cfg_total_seg_cnt);
6333
James Smart3772a992009-05-22 14:50:54 -04006334 phba->max_vpi = LPFC_MAX_VPI;
6335 /* This will be set to correct value after config_port mbox */
6336 phba->max_vports = 0;
6337
6338 /*
6339 * Initialize the SLI Layer to run with lpfc HBAs.
6340 */
6341 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08006342 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04006343
6344 /* Allocate device driver memory */
6345 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
6346 return -ENOMEM;
6347
James Smart912e3ac2011-05-24 11:42:11 -04006348 /*
6349 * Enable sr-iov virtual functions if supported and configured
6350 * through the module parameter.
6351 */
6352 if (phba->cfg_sriov_nr_virtfn > 0) {
6353 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6354 phba->cfg_sriov_nr_virtfn);
6355 if (rc) {
6356 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6357 "2808 Requested number of SR-IOV "
6358 "virtual functions (%d) is not "
6359 "supported\n",
6360 phba->cfg_sriov_nr_virtfn);
6361 phba->cfg_sriov_nr_virtfn = 0;
6362 }
6363 }
6364
James Smart3772a992009-05-22 14:50:54 -04006365 return 0;
6366}
6367
6368/**
6369 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6370 * @phba: pointer to lpfc hba data structure.
6371 *
6372 * This routine is invoked to unset the driver internal resources set up
6373 * specific for supporting the SLI-3 HBA device it attached to.
6374 **/
6375static void
6376lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
6377{
6378 /* Free device driver memory allocated */
6379 lpfc_mem_free_all(phba);
6380
6381 return;
6382}
6383
6384/**
James Smartda0436e2009-05-22 14:51:39 -04006385 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6386 * @phba: pointer to lpfc hba data structure.
6387 *
6388 * This routine is invoked to set up the driver internal resources specific to
6389 * support the SLI-4 HBA device it attached to.
6390 *
6391 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006392 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04006393 * other values - error
6394 **/
6395static int
6396lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
6397{
James Smart28baac72010-02-12 14:42:03 -05006398 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08006399 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08006400 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05006401 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
6402 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04006403 int longs;
James Smart81e6a632017-11-20 16:00:43 -08006404 int extra;
James Smartf358dd02017-02-12 13:52:34 -08006405 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07006406 u32 if_type;
6407 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04006408
James Smart895427b2017-02-12 13:52:30 -08006409 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart222e9232019-01-28 11:14:35 -08006410 phba->sli4_hba.num_possible_cpu = num_possible_cpus();
James Smart895427b2017-02-12 13:52:30 -08006411 phba->sli4_hba.curr_disp_cpu = 0;
6412
James Smart716d3bc2013-09-06 12:18:28 -04006413 /* Get all the module params for configuring this host */
6414 lpfc_get_cfgparam(phba);
6415
James Smart895427b2017-02-12 13:52:30 -08006416 /* Set up phase-1 common device driver resources */
6417 rc = lpfc_setup_driver_resource_phase1(phba);
6418 if (rc)
6419 return -ENODEV;
6420
James Smartda0436e2009-05-22 14:51:39 -04006421 /* Before proceed, wait for POST done and device ready */
6422 rc = lpfc_sli4_post_status_check(phba);
6423 if (rc)
6424 return -ENODEV;
6425
James Smart3cee98d2019-08-14 16:56:34 -07006426 /* Allocate all driver workqueues here */
6427
6428 /* The lpfc_wq workqueue for deferred irq use */
6429 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6430
James Smartda0436e2009-05-22 14:51:39 -04006431 /*
6432 * Initialize timers used by driver
6433 */
6434
Kees Cookf22eb4d2017-09-06 20:24:26 -07006435 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04006436
James Smartecfd03c2010-02-12 14:41:27 -05006437 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006438 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05006439
James Smartda0436e2009-05-22 14:51:39 -04006440 /*
James Smart7ad20aa2011-05-24 11:44:28 -04006441 * Control structure for handling external multi-buffer mailbox
6442 * command pass-through.
6443 */
6444 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
6445 sizeof(struct lpfc_mbox_ext_buf_ctx));
6446 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
6447
James Smartda0436e2009-05-22 14:51:39 -04006448 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04006449
James Smartda0436e2009-05-22 14:51:39 -04006450 /* This will be set to correct value after the read_config mbox */
6451 phba->max_vports = 0;
6452
6453 /* Program the default value of vlan_id and fc_map */
6454 phba->valid_vlan = 0;
6455 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
6456 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
6457 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
6458
6459 /*
James Smart2a76a282012-08-03 12:35:54 -04006460 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08006461 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6462 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04006463 */
James Smart085c6472010-11-20 23:11:37 -05006464
James Smart09294d42013-04-17 20:16:05 -04006465 /*
James Smart81e6a632017-11-20 16:00:43 -08006466 * 1 for cmd, 1 for rsp, NVME adds an extra one
6467 * for boundary conditions in its max_sgl_segment template.
6468 */
6469 extra = 2;
6470 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
6471 extra++;
6472
6473 /*
James Smart09294d42013-04-17 20:16:05 -04006474 * It doesn't matter what family our adapter is in, we are
6475 * limited to 2 Pages, 512 SGEs, for our SGL.
6476 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6477 */
6478 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart09294d42013-04-17 20:16:05 -04006479
James Smartda0436e2009-05-22 14:51:39 -04006480 /*
James Smart895427b2017-02-12 13:52:30 -08006481 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6482 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05006483 */
James Smartf44ac122018-03-05 12:04:08 -08006484 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
James Smart96f70772013-04-17 20:16:15 -04006485 /*
James Smart895427b2017-02-12 13:52:30 -08006486 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6487 * the FCP rsp, and a SGE. Sice we have no control
6488 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04006489 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08006490 * in the IO), just allocate enough SGEs to accomidate
6491 * our max amount and we need to limit lpfc_sg_seg_cnt
6492 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04006493 */
6494 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006495 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04006496
6497 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6498 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
6499
James Smart5b9e70b2018-09-10 10:30:42 -07006500 /*
6501 * If supporting DIF, reduce the seg count for scsi to
6502 * allow room for the DIF sges.
6503 */
6504 if (phba->cfg_enable_bg &&
6505 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
6506 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
6507 else
6508 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6509
James Smart96f70772013-04-17 20:16:15 -04006510 } else {
6511 /*
James Smart895427b2017-02-12 13:52:30 -08006512 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04006513 * the FCP rsp, a SGE for each, and a SGE for up to
6514 * cfg_sg_seg_cnt data segments.
6515 */
6516 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006517 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08006518 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08006519 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04006520
6521 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08006522 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart5b9e70b2018-09-10 10:30:42 -07006523 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
James Smart895427b2017-02-12 13:52:30 -08006524
James Smart96f70772013-04-17 20:16:15 -04006525 /*
James Smart81e6a632017-11-20 16:00:43 -08006526 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08006527 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04006528 */
James Smart085c6472010-11-20 23:11:37 -05006529 }
James Smartacd68592012-01-18 16:25:09 -05006530
James Smart5b9e70b2018-09-10 10:30:42 -07006531 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6532 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6533 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
6534 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
6535 "6300 Reducing NVME sg segment "
6536 "cnt to %d\n",
6537 LPFC_MAX_NVME_SEG_CNT);
6538 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6539 } else
6540 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
6541 }
6542
James Smart96f70772013-04-17 20:16:15 -04006543 /* Initialize the host templates with the updated values. */
James Smart5b9e70b2018-09-10 10:30:42 -07006544 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6545 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6546 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04006547
6548 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
6549 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6550 else
6551 phba->cfg_sg_dma_buf_size =
6552 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6553
6554 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smart5b9e70b2018-09-10 10:30:42 -07006555 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6556 "total:%d scsi:%d nvme:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006557 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
James Smart5b9e70b2018-09-10 10:30:42 -07006558 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6559 phba->cfg_nvme_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04006560
6561 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006562 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006563 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6564 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6565
6566 /*
6567 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6568 */
James Smart895427b2017-02-12 13:52:30 -08006569 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6570 /* Initialize the Abort scsi buffer list used by driver */
6571 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6572 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6573 }
6574
6575 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6576 /* Initialize the Abort nvme buffer list used by driver */
James Smart5e5b5112019-01-28 11:14:22 -08006577 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07006578 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006579 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart79d8c4c2019-05-21 17:48:56 -07006580 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
6581 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
James Smart895427b2017-02-12 13:52:30 -08006582 }
6583
James Smartda0436e2009-05-22 14:51:39 -04006584 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006585 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006586 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04006587
6588 /*
James Smart6d368e52011-05-24 11:44:12 -04006589 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006590 */
6591
6592 /* Driver internel slow-path CQ Event pool */
6593 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6594 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006595 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006596 /* Asynchronous event CQ Event work queue list */
6597 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6598 /* Fast-path XRI aborted CQ Event work queue list */
6599 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6600 /* Slow-path XRI aborted CQ Event work queue list */
6601 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6602 /* Receive queue CQ Event work queue list */
6603 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6604
James Smart6d368e52011-05-24 11:44:12 -04006605 /* Initialize extent block lists. */
6606 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6607 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6608 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6609 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6610
James Smartd1f525a2017-04-21 16:04:55 -07006611 /* Initialize mboxq lists. If the early init routines fail
6612 * these lists need to be correctly initialized.
6613 */
6614 INIT_LIST_HEAD(&phba->sli.mboxq);
6615 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6616
James Smart448193b2015-12-16 18:12:05 -05006617 /* initialize optic_state to 0xFF */
6618 phba->sli4_hba.lnk_info.optic_state = 0xff;
6619
James Smartda0436e2009-05-22 14:51:39 -04006620 /* Allocate device driver memory */
6621 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6622 if (rc)
6623 return -ENOMEM;
6624
James Smart2fcee4b2010-12-15 17:57:46 -05006625 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006626 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006627 LPFC_SLI_INTF_IF_TYPE_2) {
6628 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006629 if (unlikely(rc)) {
6630 rc = -ENODEV;
6631 goto out_free_mem;
6632 }
James Smart946727d2015-04-07 15:07:09 -04006633 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006634 }
6635
James Smartda0436e2009-05-22 14:51:39 -04006636 /* Create the bootstrap mailbox command */
6637 rc = lpfc_create_bootstrap_mbox(phba);
6638 if (unlikely(rc))
6639 goto out_free_mem;
6640
6641 /* Set up the host's endian order with the device. */
6642 rc = lpfc_setup_endian_order(phba);
6643 if (unlikely(rc))
6644 goto out_free_bsmbx;
6645
6646 /* Set up the hba's configuration parameters. */
6647 rc = lpfc_sli4_read_config(phba);
6648 if (unlikely(rc))
6649 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006650 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6651 if (unlikely(rc))
6652 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006653
James Smart2fcee4b2010-12-15 17:57:46 -05006654 /* IF Type 0 ports get initialized now. */
6655 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6656 LPFC_SLI_INTF_IF_TYPE_0) {
6657 rc = lpfc_pci_function_reset(phba);
6658 if (unlikely(rc))
6659 goto out_free_bsmbx;
6660 }
James Smartda0436e2009-05-22 14:51:39 -04006661
James Smartcb5172e2010-03-15 11:25:07 -04006662 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6663 GFP_KERNEL);
6664 if (!mboxq) {
6665 rc = -ENOMEM;
6666 goto out_free_bsmbx;
6667 }
6668
James Smartf358dd02017-02-12 13:52:34 -08006669 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006670 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006671 if (lpfc_enable_nvmet_cnt) {
6672
6673 /* First get WWN of HBA instance */
6674 lpfc_read_nv(phba, mboxq);
6675 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6676 if (rc != MBX_SUCCESS) {
6677 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6678 "6016 Mailbox failed , mbxCmd x%x "
6679 "READ_NV, mbxStatus x%x\n",
6680 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6681 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006682 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006683 rc = -EIO;
6684 goto out_free_bsmbx;
6685 }
6686 mb = &mboxq->u.mb;
6687 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6688 sizeof(uint64_t));
6689 wwn = cpu_to_be64(wwn);
6690 phba->sli4_hba.wwnn.u.name = wwn;
6691 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6692 sizeof(uint64_t));
6693 /* wwn is WWPN of HBA instance */
6694 wwn = cpu_to_be64(wwn);
6695 phba->sli4_hba.wwpn.u.name = wwn;
6696
6697 /* Check to see if it matches any module parameter */
6698 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6699 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006700#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006701 if (lpfc_nvmet_mem_alloc(phba))
6702 break;
6703
6704 phba->nvmet_support = 1; /* a match */
6705
James Smartf358dd02017-02-12 13:52:34 -08006706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6707 "6017 NVME Target %016llx\n",
6708 wwn);
James Smart7d708032017-03-08 14:36:01 -08006709#else
6710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6711 "6021 Can't enable NVME Target."
6712 " NVME_TARGET_FC infrastructure"
6713 " is not in kernel\n");
6714#endif
James Smartc4908502019-01-28 11:14:28 -08006715 /* Not supported for NVMET */
6716 phba->cfg_xri_rebalancing = 0;
James Smart3c603be2017-05-15 15:20:44 -07006717 break;
James Smartf358dd02017-02-12 13:52:34 -08006718 }
6719 }
6720 }
James Smart895427b2017-02-12 13:52:30 -08006721
6722 lpfc_nvme_mod_param_dep(phba);
6723
James Smartfedd3b72011-02-16 12:39:24 -05006724 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006725 lpfc_supported_pages(mboxq);
6726 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006727 if (!rc) {
6728 mqe = &mboxq->u.mqe;
6729 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6730 LPFC_MAX_SUPPORTED_PAGES);
6731 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6732 switch (pn_page[i]) {
6733 case LPFC_SLI4_PARAMETERS:
6734 phba->sli4_hba.pc_sli4_params.supported = 1;
6735 break;
6736 default:
6737 break;
6738 }
6739 }
6740 /* Read the port's SLI4 Parameters capabilities if supported. */
6741 if (phba->sli4_hba.pc_sli4_params.supported)
6742 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6743 if (rc) {
6744 mempool_free(mboxq, phba->mbox_mem_pool);
6745 rc = -EIO;
6746 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006747 }
6748 }
James Smart65791f12016-07-06 12:35:56 -07006749
James Smartfedd3b72011-02-16 12:39:24 -05006750 /*
6751 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006752 * If this call fails, it isn't critical unless the SLI4 parameters come
6753 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006754 */
James Smart6d368e52011-05-24 11:44:12 -04006755 rc = lpfc_get_sli4_parameters(phba, mboxq);
6756 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006757 if_type = bf_get(lpfc_sli_intf_if_type,
6758 &phba->sli4_hba.sli_intf);
6759 if_fam = bf_get(lpfc_sli_intf_sli_family,
6760 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006761 if (phba->sli4_hba.extents_in_use &&
6762 phba->sli4_hba.rpi_hdrs_in_use) {
6763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6764 "2999 Unsupported SLI4 Parameters "
6765 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006766 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6767 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6768 mempool_free(mboxq, phba->mbox_mem_pool);
6769 rc = -EIO;
6770 goto out_free_bsmbx;
6771 }
James Smart6d368e52011-05-24 11:44:12 -04006772 }
James Smartb92dc722018-05-24 21:09:01 -07006773 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6774 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6775 mempool_free(mboxq, phba->mbox_mem_pool);
6776 rc = -EIO;
6777 goto out_free_bsmbx;
6778 }
James Smart6d368e52011-05-24 11:44:12 -04006779 }
James Smart895427b2017-02-12 13:52:30 -08006780
James Smartcb5172e2010-03-15 11:25:07 -04006781 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006782
6783 /* Verify OAS is supported */
6784 lpfc_sli4_oas_verify(phba);
James Smart1ba981f2014-02-20 09:56:45 -05006785
James Smartd2cc9bc2018-09-10 10:30:50 -07006786 /* Verify RAS support on adapter */
6787 lpfc_sli4_ras_init(phba);
6788
James Smart5350d872011-10-10 21:33:49 -04006789 /* Verify all the SLI4 queues */
6790 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006791 if (rc)
6792 goto out_free_bsmbx;
6793
6794 /* Create driver internal CQE event pool */
6795 rc = lpfc_sli4_cq_event_pool_create(phba);
6796 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006797 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006798
James Smart8a9d2e82012-05-09 21:16:12 -04006799 /* Initialize sgl lists per host */
6800 lpfc_init_sgl_list(phba);
6801
6802 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006803 rc = lpfc_init_active_sgl_array(phba);
6804 if (rc) {
6805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6806 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006807 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006808 }
James Smartda0436e2009-05-22 14:51:39 -04006809 rc = lpfc_sli4_init_rpi_hdrs(phba);
6810 if (rc) {
6811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6812 "1432 Failed to initialize rpi headers.\n");
6813 goto out_free_active_sgl;
6814 }
6815
James Smarta93ff372010-10-22 11:06:08 -04006816 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006817 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006818 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006819 GFP_KERNEL);
6820 if (!phba->fcf.fcf_rr_bmask) {
6821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6822 "2759 Failed allocate memory for FCF round "
6823 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006824 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006825 goto out_remove_rpi_hdrs;
6826 }
6827
James Smart6a828b02019-01-28 11:14:31 -08006828 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08006829 sizeof(struct lpfc_hba_eq_hdl),
6830 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006831 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6833 "2572 Failed allocate memory for "
6834 "fast-path per-EQ handle array\n");
6835 rc = -ENOMEM;
6836 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006837 }
6838
James Smart222e9232019-01-28 11:14:35 -08006839 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
James Smart895427b2017-02-12 13:52:30 -08006840 sizeof(struct lpfc_vector_map_info),
6841 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006842 if (!phba->sli4_hba.cpu_map) {
6843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6844 "3327 Failed allocate memory for msi-x "
6845 "interrupt vector mapping\n");
6846 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006847 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006848 }
James Smartb246de12013-05-31 17:03:07 -04006849
James Smart32517fc2019-01-28 11:14:33 -08006850 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
6851 if (!phba->sli4_hba.eq_info) {
6852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6853 "3321 Failed allocation for per_cpu stats\n");
6854 rc = -ENOMEM;
6855 goto out_free_hba_cpu_map;
6856 }
James Smart912e3ac2011-05-24 11:42:11 -04006857 /*
6858 * Enable sr-iov virtual functions if supported and configured
6859 * through the module parameter.
6860 */
6861 if (phba->cfg_sriov_nr_virtfn > 0) {
6862 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6863 phba->cfg_sriov_nr_virtfn);
6864 if (rc) {
6865 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6866 "3020 Requested number of SR-IOV "
6867 "virtual functions (%d) is not "
6868 "supported\n",
6869 phba->cfg_sriov_nr_virtfn);
6870 phba->cfg_sriov_nr_virtfn = 0;
6871 }
6872 }
6873
James Smart5248a742011-07-22 18:37:06 -04006874 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006875
James Smart32517fc2019-01-28 11:14:33 -08006876out_free_hba_cpu_map:
6877 kfree(phba->sli4_hba.cpu_map);
James Smart895427b2017-02-12 13:52:30 -08006878out_free_hba_eq_hdl:
6879 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006880out_free_fcf_rr_bmask:
6881 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006882out_remove_rpi_hdrs:
6883 lpfc_sli4_remove_rpi_hdrs(phba);
6884out_free_active_sgl:
6885 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006886out_destroy_cq_event_pool:
6887 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006888out_free_bsmbx:
6889 lpfc_destroy_bootstrap_mbox(phba);
6890out_free_mem:
6891 lpfc_mem_free(phba);
6892 return rc;
6893}
6894
6895/**
6896 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6897 * @phba: pointer to lpfc hba data structure.
6898 *
6899 * This routine is invoked to unset the driver internal resources set up
6900 * specific for supporting the SLI-4 HBA device it attached to.
6901 **/
6902static void
6903lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6904{
6905 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6906
James Smart32517fc2019-01-28 11:14:33 -08006907 free_percpu(phba->sli4_hba.eq_info);
6908
James Smart7bb03bb2013-04-17 20:19:16 -04006909 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6910 kfree(phba->sli4_hba.cpu_map);
James Smart222e9232019-01-28 11:14:35 -08006911 phba->sli4_hba.num_possible_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006912 phba->sli4_hba.num_present_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006913 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006914
James Smartda0436e2009-05-22 14:51:39 -04006915 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006916 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006917
6918 /* Free the allocated rpi headers. */
6919 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006920 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006921
James Smart0c9ab6f2010-02-26 14:15:57 -05006922 /* Free eligible FCF index bmask */
6923 kfree(phba->fcf.fcf_rr_bmask);
6924
James Smartda0436e2009-05-22 14:51:39 -04006925 /* Free the ELS sgl list */
6926 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006927 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006928 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006929
James Smartda0436e2009-05-22 14:51:39 -04006930 /* Free the completion queue EQ event pool */
6931 lpfc_sli4_cq_event_release_all(phba);
6932 lpfc_sli4_cq_event_pool_destroy(phba);
6933
James Smart6d368e52011-05-24 11:44:12 -04006934 /* Release resource identifiers. */
6935 lpfc_sli4_dealloc_resource_identifiers(phba);
6936
James Smartda0436e2009-05-22 14:51:39 -04006937 /* Free the bsmbx region. */
6938 lpfc_destroy_bootstrap_mbox(phba);
6939
6940 /* Free the SLI Layer memory with SLI4 HBAs */
6941 lpfc_mem_free_all(phba);
6942
6943 /* Free the current connect table */
6944 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006945 &phba->fcf_conn_rec_list, list) {
6946 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006947 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006948 }
James Smartda0436e2009-05-22 14:51:39 -04006949
6950 return;
6951}
6952
6953/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006954 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006955 * @phba: The hba struct for which this call is being executed.
6956 * @dev_grp: The HBA PCI-Device group number.
6957 *
6958 * This routine sets up the device INIT interface API function jump table
6959 * in @phba struct.
6960 *
6961 * Returns: 0 - success, -ENODEV - failure.
6962 **/
6963int
6964lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6965{
James Smart84d1b002010-02-12 14:42:33 -05006966 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6967 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006968 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006969 switch (dev_grp) {
6970 case LPFC_PCI_DEV_LP:
6971 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6972 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6973 phba->lpfc_stop_port = lpfc_stop_port_s3;
6974 break;
James Smartda0436e2009-05-22 14:51:39 -04006975 case LPFC_PCI_DEV_OC:
6976 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6977 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6978 phba->lpfc_stop_port = lpfc_stop_port_s4;
6979 break;
James Smart3772a992009-05-22 14:50:54 -04006980 default:
6981 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6982 "1431 Invalid HBA PCI-device group: 0x%x\n",
6983 dev_grp);
6984 return -ENODEV;
6985 break;
6986 }
6987 return 0;
6988}
6989
6990/**
James Smart3772a992009-05-22 14:50:54 -04006991 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6992 * @phba: pointer to lpfc hba data structure.
6993 *
6994 * This routine is invoked to set up the driver internal resources after the
6995 * device specific resource setup to support the HBA device it attached to.
6996 *
6997 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006998 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006999 * other values - error
7000 **/
7001static int
7002lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
7003{
7004 int error;
7005
7006 /* Startup the kernel thread for this host adapter. */
7007 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7008 "lpfc_worker_%d", phba->brd_no);
7009 if (IS_ERR(phba->worker_thread)) {
7010 error = PTR_ERR(phba->worker_thread);
7011 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007012 }
7013
James Smart3772a992009-05-22 14:50:54 -04007014 return 0;
7015}
7016
7017/**
7018 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7019 * @phba: pointer to lpfc hba data structure.
7020 *
7021 * This routine is invoked to unset the driver internal resources set up after
7022 * the device specific resource setup for supporting the HBA device it
7023 * attached to.
7024 **/
7025static void
7026lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
7027{
Dick Kennedyf485c182017-09-29 17:34:34 -07007028 if (phba->wq) {
7029 flush_workqueue(phba->wq);
7030 destroy_workqueue(phba->wq);
7031 phba->wq = NULL;
7032 }
7033
James Smart3772a992009-05-22 14:50:54 -04007034 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07007035 if (phba->worker_thread)
7036 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04007037}
7038
7039/**
7040 * lpfc_free_iocb_list - Free iocb list.
7041 * @phba: pointer to lpfc hba data structure.
7042 *
7043 * This routine is invoked to free the driver's IOCB list and memory.
7044 **/
James Smart6c621a22017-05-15 15:20:45 -07007045void
James Smart3772a992009-05-22 14:50:54 -04007046lpfc_free_iocb_list(struct lpfc_hba *phba)
7047{
7048 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
7049
7050 spin_lock_irq(&phba->hbalock);
7051 list_for_each_entry_safe(iocbq_entry, iocbq_next,
7052 &phba->lpfc_iocb_list, list) {
7053 list_del(&iocbq_entry->list);
7054 kfree(iocbq_entry);
7055 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007056 }
James Smart3772a992009-05-22 14:50:54 -04007057 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007058
James Smart3772a992009-05-22 14:50:54 -04007059 return;
7060}
dea31012005-04-17 16:05:31 -05007061
James Smart3772a992009-05-22 14:50:54 -04007062/**
7063 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7064 * @phba: pointer to lpfc hba data structure.
7065 *
7066 * This routine is invoked to allocate and initizlize the driver's IOCB
7067 * list and set up the IOCB tag array accordingly.
7068 *
7069 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007070 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007071 * other values - error
7072 **/
James Smart6c621a22017-05-15 15:20:45 -07007073int
James Smart3772a992009-05-22 14:50:54 -04007074lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
7075{
7076 struct lpfc_iocbq *iocbq_entry = NULL;
7077 uint16_t iotag;
7078 int i;
dea31012005-04-17 16:05:31 -05007079
7080 /* Initialize and populate the iocb list per host. */
7081 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04007082 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07007083 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05007084 if (iocbq_entry == NULL) {
7085 printk(KERN_ERR "%s: only allocated %d iocbs of "
7086 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07007087 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05007088 goto out_free_iocbq;
7089 }
7090
James Bottomley604a3e32005-10-29 10:28:33 -05007091 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
7092 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04007093 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05007094 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04007095 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05007096 goto out_free_iocbq;
7097 }
James Smart6d368e52011-05-24 11:44:12 -04007098 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04007099 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05007100
7101 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007102 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
7103 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05007104 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007105 }
7106
James Smart3772a992009-05-22 14:50:54 -04007107 return 0;
7108
7109out_free_iocbq:
7110 lpfc_free_iocb_list(phba);
7111
7112 return -ENOMEM;
7113}
7114
7115/**
James Smart8a9d2e82012-05-09 21:16:12 -04007116 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007117 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04007118 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007119 *
James Smart8a9d2e82012-05-09 21:16:12 -04007120 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04007121 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007122void
7123lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04007124{
7125 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04007126
7127 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
7128 list_del(&sglq_entry->list);
7129 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
7130 kfree(sglq_entry);
7131 }
7132}
7133
7134/**
7135 * lpfc_free_els_sgl_list - Free els sgl list.
7136 * @phba: pointer to lpfc hba data structure.
7137 *
7138 * This routine is invoked to free the driver's els sgl list and memory.
7139 **/
7140static void
7141lpfc_free_els_sgl_list(struct lpfc_hba *phba)
7142{
James Smartda0436e2009-05-22 14:51:39 -04007143 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007144
James Smart8a9d2e82012-05-09 21:16:12 -04007145 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04007146 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007147 spin_lock(&phba->sli4_hba.sgl_list_lock);
7148 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
7149 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04007150 spin_unlock_irq(&phba->hbalock);
7151
James Smart8a9d2e82012-05-09 21:16:12 -04007152 /* Now free the sgl list */
7153 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007154}
7155
7156/**
James Smartf358dd02017-02-12 13:52:34 -08007157 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
7158 * @phba: pointer to lpfc hba data structure.
7159 *
7160 * This routine is invoked to free the driver's nvmet sgl list and memory.
7161 **/
7162static void
7163lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
7164{
7165 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7166 LIST_HEAD(sglq_list);
7167
7168 /* Retrieve all nvmet sgls from driver list */
7169 spin_lock_irq(&phba->hbalock);
7170 spin_lock(&phba->sli4_hba.sgl_list_lock);
7171 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
7172 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7173 spin_unlock_irq(&phba->hbalock);
7174
7175 /* Now free the sgl list */
7176 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
7177 list_del(&sglq_entry->list);
7178 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
7179 kfree(sglq_entry);
7180 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07007181
7182 /* Update the nvmet_xri_cnt to reflect no current sgls.
7183 * The next initialization cycle sets the count and allocates
7184 * the sgls over again.
7185 */
7186 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08007187}
7188
7189/**
James Smartda0436e2009-05-22 14:51:39 -04007190 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
7191 * @phba: pointer to lpfc hba data structure.
7192 *
7193 * This routine is invoked to allocate the driver's active sgl memory.
7194 * This array will hold the sglq_entry's for active IOs.
7195 **/
7196static int
7197lpfc_init_active_sgl_array(struct lpfc_hba *phba)
7198{
7199 int size;
7200 size = sizeof(struct lpfc_sglq *);
7201 size *= phba->sli4_hba.max_cfg_param.max_xri;
7202
7203 phba->sli4_hba.lpfc_sglq_active_list =
7204 kzalloc(size, GFP_KERNEL);
7205 if (!phba->sli4_hba.lpfc_sglq_active_list)
7206 return -ENOMEM;
7207 return 0;
7208}
7209
7210/**
7211 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
7212 * @phba: pointer to lpfc hba data structure.
7213 *
7214 * This routine is invoked to walk through the array of active sglq entries
7215 * and free all of the resources.
7216 * This is just a place holder for now.
7217 **/
7218static void
7219lpfc_free_active_sgl(struct lpfc_hba *phba)
7220{
7221 kfree(phba->sli4_hba.lpfc_sglq_active_list);
7222}
7223
7224/**
7225 * lpfc_init_sgl_list - Allocate and initialize sgl list.
7226 * @phba: pointer to lpfc hba data structure.
7227 *
7228 * This routine is invoked to allocate and initizlize the driver's sgl
7229 * list and set up the sgl xritag tag array accordingly.
7230 *
James Smartda0436e2009-05-22 14:51:39 -04007231 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007232static void
James Smartda0436e2009-05-22 14:51:39 -04007233lpfc_init_sgl_list(struct lpfc_hba *phba)
7234{
James Smartda0436e2009-05-22 14:51:39 -04007235 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08007236 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04007237 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08007238 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07007239 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04007240
James Smart8a9d2e82012-05-09 21:16:12 -04007241 /* els xri-sgl book keeping */
7242 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007243
James Smart895427b2017-02-12 13:52:30 -08007244 /* nvme xri-buffer book keeping */
James Smart5e5b5112019-01-28 11:14:22 -08007245 phba->sli4_hba.io_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007246}
7247
7248/**
7249 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
7250 * @phba: pointer to lpfc hba data structure.
7251 *
7252 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04007253 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04007254 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04007255 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
7256 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04007257 *
7258 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007259 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04007260 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04007261 **/
7262int
7263lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
7264{
7265 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007266 struct lpfc_rpi_hdr *rpi_hdr;
7267
7268 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05007269 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04007270 return rc;
James Smart6d368e52011-05-24 11:44:12 -04007271 if (phba->sli4_hba.extents_in_use)
7272 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04007273
7274 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
7275 if (!rpi_hdr) {
7276 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7277 "0391 Error during rpi post operation\n");
7278 lpfc_sli4_remove_rpis(phba);
7279 rc = -ENODEV;
7280 }
7281
7282 return rc;
7283}
7284
7285/**
7286 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
7287 * @phba: pointer to lpfc hba data structure.
7288 *
7289 * This routine is invoked to allocate a single 4KB memory region to
7290 * support rpis and stores them in the phba. This single region
7291 * provides support for up to 64 rpis. The region is used globally
7292 * by the device.
7293 *
7294 * Returns:
7295 * A valid rpi hdr on success.
7296 * A NULL pointer on any failure.
7297 **/
7298struct lpfc_rpi_hdr *
7299lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
7300{
7301 uint16_t rpi_limit, curr_rpi_range;
7302 struct lpfc_dmabuf *dmabuf;
7303 struct lpfc_rpi_hdr *rpi_hdr;
7304
James Smart6d368e52011-05-24 11:44:12 -04007305 /*
7306 * If the SLI4 port supports extents, posting the rpi header isn't
7307 * required. Set the expected maximum count and let the actual value
7308 * get set when extents are fully allocated.
7309 */
7310 if (!phba->sli4_hba.rpi_hdrs_in_use)
7311 return NULL;
7312 if (phba->sli4_hba.extents_in_use)
7313 return NULL;
7314
7315 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07007316 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007317
7318 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007319 /*
7320 * Establish the starting RPI in this header block. The starting
7321 * rpi is normalized to a zero base because the physical rpi is
7322 * port based.
7323 */
James Smart97f2ecf2012-03-01 22:35:23 -05007324 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007325 spin_unlock_irq(&phba->hbalock);
7326
James Smart845d9e82017-05-15 15:20:38 -07007327 /* Reached full RPI range */
7328 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04007329 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07007330
James Smartda0436e2009-05-22 14:51:39 -04007331 /*
7332 * First allocate the protocol header region for the port. The
7333 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
7334 */
7335 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7336 if (!dmabuf)
7337 return NULL;
7338
Luis Chamberlain750afb02019-01-04 09:23:09 +01007339 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
7340 LPFC_HDR_TEMPLATE_SIZE,
7341 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007342 if (!dmabuf->virt) {
7343 rpi_hdr = NULL;
7344 goto err_free_dmabuf;
7345 }
7346
James Smartda0436e2009-05-22 14:51:39 -04007347 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
7348 rpi_hdr = NULL;
7349 goto err_free_coherent;
7350 }
7351
7352 /* Save the rpi header data for cleanup later. */
7353 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
7354 if (!rpi_hdr)
7355 goto err_free_coherent;
7356
7357 rpi_hdr->dmabuf = dmabuf;
7358 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
7359 rpi_hdr->page_count = 1;
7360 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007361
7362 /* The rpi_hdr stores the logical index only. */
7363 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07007364 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04007365 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
7366
James Smartda0436e2009-05-22 14:51:39 -04007367 spin_unlock_irq(&phba->hbalock);
7368 return rpi_hdr;
7369
7370 err_free_coherent:
7371 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
7372 dmabuf->virt, dmabuf->phys);
7373 err_free_dmabuf:
7374 kfree(dmabuf);
7375 return NULL;
7376}
7377
7378/**
7379 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7380 * @phba: pointer to lpfc hba data structure.
7381 *
7382 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04007383 * to support rpis for SLI4 ports not supporting extents. This routine
7384 * presumes the caller has released all rpis consumed by fabric or port
7385 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04007386 **/
7387void
7388lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
7389{
7390 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
7391
James Smart6d368e52011-05-24 11:44:12 -04007392 if (!phba->sli4_hba.rpi_hdrs_in_use)
7393 goto exit;
7394
James Smartda0436e2009-05-22 14:51:39 -04007395 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
7396 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
7397 list_del(&rpi_hdr->list);
7398 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
7399 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
7400 kfree(rpi_hdr->dmabuf);
7401 kfree(rpi_hdr);
7402 }
James Smart6d368e52011-05-24 11:44:12 -04007403 exit:
7404 /* There are no rpis available to the port now. */
7405 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04007406}
7407
7408/**
James Smart3772a992009-05-22 14:50:54 -04007409 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7410 * @pdev: pointer to pci device data structure.
7411 *
7412 * This routine is invoked to allocate the driver hba data structure for an
7413 * HBA device. If the allocation is successful, the phba reference to the
7414 * PCI device data structure is set.
7415 *
7416 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007417 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04007418 * NULL - error
7419 **/
7420static struct lpfc_hba *
7421lpfc_hba_alloc(struct pci_dev *pdev)
7422{
7423 struct lpfc_hba *phba;
7424
7425 /* Allocate memory for HBA structure */
7426 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
7427 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02007428 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04007429 return NULL;
7430 }
7431
7432 /* Set reference to PCI device in HBA structure */
7433 phba->pcidev = pdev;
7434
7435 /* Assign an unused board number */
7436 phba->brd_no = lpfc_get_instance();
7437 if (phba->brd_no < 0) {
7438 kfree(phba);
7439 return NULL;
7440 }
James Smart65791f12016-07-06 12:35:56 -07007441 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04007442
James Smart4fede782010-01-26 23:08:55 -05007443 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04007444 INIT_LIST_HEAD(&phba->ct_ev_waiters);
7445
James Smart3772a992009-05-22 14:50:54 -04007446 return phba;
7447}
7448
7449/**
7450 * lpfc_hba_free - Free driver hba data structure with a device.
7451 * @phba: pointer to lpfc hba data structure.
7452 *
7453 * This routine is invoked to free the driver hba data structure with an
7454 * HBA device.
7455 **/
7456static void
7457lpfc_hba_free(struct lpfc_hba *phba)
7458{
James Smart5e5b5112019-01-28 11:14:22 -08007459 if (phba->sli_rev == LPFC_SLI_REV4)
7460 kfree(phba->sli4_hba.hdwq);
7461
James Smart3772a992009-05-22 14:50:54 -04007462 /* Release the driver assigned board number */
7463 idr_remove(&lpfc_hba_index, phba->brd_no);
7464
James Smart895427b2017-02-12 13:52:30 -08007465 /* Free memory allocated with sli3 rings */
7466 kfree(phba->sli.sli3_ring);
7467 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04007468
James Smart3772a992009-05-22 14:50:54 -04007469 kfree(phba);
7470 return;
7471}
7472
7473/**
7474 * lpfc_create_shost - Create hba physical port with associated scsi host.
7475 * @phba: pointer to lpfc hba data structure.
7476 *
7477 * This routine is invoked to create HBA physical port and associate a SCSI
7478 * host with it.
7479 *
7480 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007481 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007482 * other values - error
7483 **/
7484static int
7485lpfc_create_shost(struct lpfc_hba *phba)
7486{
7487 struct lpfc_vport *vport;
7488 struct Scsi_Host *shost;
7489
7490 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05007491 phba->fc_edtov = FF_DEF_EDTOV;
7492 phba->fc_ratov = FF_DEF_RATOV;
7493 phba->fc_altov = FF_DEF_ALTOV;
7494 phba->fc_arbtov = FF_DEF_ARBTOV;
7495
James Smartd7c47992010-06-08 18:31:54 -04007496 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04007497 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05007498 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04007499 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05007500
7501 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05007502 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08007503
James Smartf358dd02017-02-12 13:52:34 -08007504 if (phba->nvmet_support) {
7505 /* Only 1 vport (pport) will support NVME target */
7506 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02007507 phba->txrdy_payload_pool = dma_pool_create(
7508 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08007509 TXRDY_PAYLOAD_LEN, 16, 0);
7510 if (phba->txrdy_payload_pool) {
7511 phba->targetport = NULL;
7512 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
7513 lpfc_printf_log(phba, KERN_INFO,
7514 LOG_INIT | LOG_NVME_DISC,
7515 "6076 NVME Target Found\n");
7516 }
7517 }
7518 }
7519
James Smart858c9f62007-06-17 19:56:39 -05007520 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04007521 /* Put reference to SCSI host to driver's device private data */
7522 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05007523
James Smart4258e982015-12-16 18:11:58 -05007524 /*
7525 * At this point we are fully registered with PSA. In addition,
7526 * any initial discovery should be completed.
7527 */
7528 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07007529 if (phba->cfg_enable_SmartSAN ||
7530 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05007531
7532 /* Setup appropriate attribute masks */
7533 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07007534 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05007535 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
7536 else
7537 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7538 }
James Smart3772a992009-05-22 14:50:54 -04007539 return 0;
7540}
dea31012005-04-17 16:05:31 -05007541
James Smart3772a992009-05-22 14:50:54 -04007542/**
7543 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7544 * @phba: pointer to lpfc hba data structure.
7545 *
7546 * This routine is invoked to destroy HBA physical port and the associated
7547 * SCSI host.
7548 **/
7549static void
7550lpfc_destroy_shost(struct lpfc_hba *phba)
7551{
7552 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007553
James Smart3772a992009-05-22 14:50:54 -04007554 /* Destroy physical port that associated with the SCSI host */
7555 destroy_port(vport);
7556
7557 return;
7558}
7559
7560/**
7561 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7562 * @phba: pointer to lpfc hba data structure.
7563 * @shost: the shost to be used to detect Block guard settings.
7564 *
7565 * This routine sets up the local Block guard protocol settings for @shost.
7566 * This routine also allocates memory for debugging bg buffers.
7567 **/
7568static void
7569lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7570{
James Smartbbeb79b2012-06-12 13:54:27 -04007571 uint32_t old_mask;
7572 uint32_t old_guard;
7573
James Smart3772a992009-05-22 14:50:54 -04007574 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07007575 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007576 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7577 "1478 Registering BlockGuard with the "
7578 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007579
James Smartb3b98b72016-10-13 15:06:06 -07007580 old_mask = phba->cfg_prot_mask;
7581 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007582
7583 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007584 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007585 SHOST_DIX_TYPE0_PROTECTION |
7586 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007587 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7588 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007589
7590 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007591 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7592 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007593
James Smartb3b98b72016-10-13 15:06:06 -07007594 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7595 if ((old_mask != phba->cfg_prot_mask) ||
7596 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7598 "1475 Registering BlockGuard with the "
7599 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007600 phba->cfg_prot_mask,
7601 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007602
James Smartb3b98b72016-10-13 15:06:06 -07007603 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7604 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007605 } else
7606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7607 "1479 Not Registering BlockGuard with the SCSI "
7608 "layer, Bad protection parameters: %d %d\n",
7609 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007610 }
James Smartbbeb79b2012-06-12 13:54:27 -04007611
James Smart81301a92008-12-04 22:39:46 -05007612 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007613 while (pagecnt) {
7614 spin_lock_init(&_dump_buf_lock);
7615 _dump_buf_data =
7616 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7617 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007618 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7619 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007620 "_dump_buf_data at 0x%p\n",
7621 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007622 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007623 memset(_dump_buf_data, 0,
7624 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007625 break;
James Smart3772a992009-05-22 14:50:54 -04007626 } else
James Smart81301a92008-12-04 22:39:46 -05007627 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007628 }
James Smart81301a92008-12-04 22:39:46 -05007629 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007630 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7631 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007632 "memory for hexdump\n");
7633 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007634 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7635 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007636 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007637 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007638 while (pagecnt) {
7639 _dump_buf_dif =
7640 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7641 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007642 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7643 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007644 "_dump_buf_dif at 0x%p\n",
7645 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007646 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007647 memset(_dump_buf_dif, 0,
7648 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007649 break;
James Smart3772a992009-05-22 14:50:54 -04007650 } else
James Smart81301a92008-12-04 22:39:46 -05007651 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007652 }
James Smart81301a92008-12-04 22:39:46 -05007653 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007654 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7655 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007656 "memory for hexdump\n");
7657 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007658 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7659 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007660 _dump_buf_dif);
7661}
7662
7663/**
7664 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7665 * @phba: pointer to lpfc hba data structure.
7666 *
7667 * This routine is invoked to perform all the necessary post initialization
7668 * setup for the device.
7669 **/
7670static void
7671lpfc_post_init_setup(struct lpfc_hba *phba)
7672{
7673 struct Scsi_Host *shost;
7674 struct lpfc_adapter_event_header adapter_event;
7675
7676 /* Get the default values for Model Name and Description */
7677 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7678
7679 /*
7680 * hba setup may have changed the hba_queue_depth so we need to
7681 * adjust the value of can_queue.
7682 */
7683 shost = pci_get_drvdata(phba->pcidev);
7684 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart858c9f62007-06-17 19:56:39 -05007685
7686 lpfc_host_attrib_init(shost);
7687
James Smart2e0fef82007-06-17 19:56:36 -05007688 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7689 spin_lock_irq(shost->host_lock);
7690 lpfc_poll_start_timer(phba);
7691 spin_unlock_irq(shost->host_lock);
7692 }
James Smart8f6d98d2006-08-01 07:34:00 -04007693
James Smart93996272008-08-24 21:50:30 -04007694 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7695 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007696 /* Send board arrival event to upper layer */
7697 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7698 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7699 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007700 sizeof(adapter_event),
7701 (char *) &adapter_event,
7702 LPFC_NL_VENDOR_ID);
7703 return;
7704}
7705
7706/**
7707 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7708 * @phba: pointer to lpfc hba data structure.
7709 *
7710 * This routine is invoked to set up the PCI device memory space for device
7711 * with SLI-3 interface spec.
7712 *
7713 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007714 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007715 * other values - error
7716 **/
7717static int
7718lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7719{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007720 struct pci_dev *pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007721 unsigned long bar0map_len, bar2map_len;
7722 int i, hbq_count;
7723 void *ptr;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007724 int error;
James Smart3772a992009-05-22 14:50:54 -04007725
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007726 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01007727 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007728
7729 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01007730 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7731 if (error)
7732 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7733 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007734 return error;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007735 error = -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007736
7737 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7738 * required by each mapping.
7739 */
7740 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7741 bar0map_len = pci_resource_len(pdev, 0);
7742
7743 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7744 bar2map_len = pci_resource_len(pdev, 2);
7745
7746 /* Map HBA SLIM to a kernel virtual address. */
7747 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7748 if (!phba->slim_memmap_p) {
7749 dev_printk(KERN_ERR, &pdev->dev,
7750 "ioremap failed for SLIM memory.\n");
7751 goto out;
7752 }
7753
7754 /* Map HBA Control Registers to a kernel virtual address. */
7755 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7756 if (!phba->ctrl_regs_memmap_p) {
7757 dev_printk(KERN_ERR, &pdev->dev,
7758 "ioremap failed for HBA control registers.\n");
7759 goto out_iounmap_slim;
7760 }
7761
7762 /* Allocate memory for SLI-2 structures */
Luis Chamberlain750afb02019-01-04 09:23:09 +01007763 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7764 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007765 if (!phba->slim2p.virt)
7766 goto out_iounmap;
7767
James Smart3772a992009-05-22 14:50:54 -04007768 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007769 phba->mbox_ext = (phba->slim2p.virt +
7770 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007771 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7772 phba->IOCBs = (phba->slim2p.virt +
7773 offsetof(struct lpfc_sli2_slim, IOCBs));
7774
7775 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7776 lpfc_sli_hbq_size(),
7777 &phba->hbqslimp.phys,
7778 GFP_KERNEL);
7779 if (!phba->hbqslimp.virt)
7780 goto out_free_slim;
7781
7782 hbq_count = lpfc_sli_hbq_count();
7783 ptr = phba->hbqslimp.virt;
7784 for (i = 0; i < hbq_count; ++i) {
7785 phba->hbqs[i].hbq_virt = ptr;
7786 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7787 ptr += (lpfc_hbq_defs[i]->entry_count *
7788 sizeof(struct lpfc_hbq_entry));
7789 }
7790 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7791 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7792
7793 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7794
James Smart3772a992009-05-22 14:50:54 -04007795 phba->MBslimaddr = phba->slim_memmap_p;
7796 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7797 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7798 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7799 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007800
dea31012005-04-17 16:05:31 -05007801 return 0;
7802
dea31012005-04-17 16:05:31 -05007803out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007804 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7805 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007806out_iounmap:
7807 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007808out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007809 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007810out:
7811 return error;
7812}
7813
James Smarte59058c2008-08-24 21:49:00 -04007814/**
James Smart3772a992009-05-22 14:50:54 -04007815 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7816 * @phba: pointer to lpfc hba data structure.
7817 *
7818 * This routine is invoked to unset the PCI device memory space for device
7819 * with SLI-3 interface spec.
7820 **/
7821static void
7822lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7823{
7824 struct pci_dev *pdev;
7825
7826 /* Obtain PCI device reference */
7827 if (!phba->pcidev)
7828 return;
7829 else
7830 pdev = phba->pcidev;
7831
7832 /* Free coherent DMA memory allocated */
7833 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7834 phba->hbqslimp.virt, phba->hbqslimp.phys);
7835 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7836 phba->slim2p.virt, phba->slim2p.phys);
7837
7838 /* I/O memory unmap */
7839 iounmap(phba->ctrl_regs_memmap_p);
7840 iounmap(phba->slim_memmap_p);
7841
7842 return;
7843}
7844
7845/**
James Smartda0436e2009-05-22 14:51:39 -04007846 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7847 * @phba: pointer to lpfc hba data structure.
7848 *
7849 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7850 * done and check status.
7851 *
7852 * Return 0 if successful, otherwise -ENODEV.
7853 **/
7854int
7855lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7856{
James Smart2fcee4b2010-12-15 17:57:46 -05007857 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7858 struct lpfc_register reg_data;
7859 int i, port_error = 0;
7860 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007861
James Smart9940b972011-03-11 16:06:12 -05007862 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7863 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007864 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007865 return -ENODEV;
7866
James Smartda0436e2009-05-22 14:51:39 -04007867 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7868 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007869 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7870 &portsmphr_reg.word0) ||
7871 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007872 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007873 port_error = -ENODEV;
7874 break;
7875 }
James Smart2fcee4b2010-12-15 17:57:46 -05007876 if (LPFC_POST_STAGE_PORT_READY ==
7877 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007878 break;
James Smartda0436e2009-05-22 14:51:39 -04007879 msleep(10);
7880 }
7881
James Smart2fcee4b2010-12-15 17:57:46 -05007882 /*
7883 * If there was a port error during POST, then don't proceed with
7884 * other register reads as the data may not be valid. Just exit.
7885 */
7886 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007887 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007888 "1408 Port Failed POST - portsmphr=0x%x, "
7889 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7890 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7891 portsmphr_reg.word0,
7892 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7893 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7894 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7895 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7896 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7897 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7898 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7899 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7900 } else {
James Smart28baac72010-02-12 14:42:03 -05007901 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007902 "2534 Device Info: SLIFamily=0x%x, "
7903 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7904 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007905 bf_get(lpfc_sli_intf_sli_family,
7906 &phba->sli4_hba.sli_intf),
7907 bf_get(lpfc_sli_intf_slirev,
7908 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007909 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007910 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007911 bf_get(lpfc_sli_intf_sli_hint1,
7912 &phba->sli4_hba.sli_intf),
7913 bf_get(lpfc_sli_intf_sli_hint2,
7914 &phba->sli4_hba.sli_intf),
7915 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007916 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007917 /*
7918 * Check for other Port errors during the initialization
7919 * process. Fail the load if the port did not come up
7920 * correctly.
7921 */
7922 if_type = bf_get(lpfc_sli_intf_if_type,
7923 &phba->sli4_hba.sli_intf);
7924 switch (if_type) {
7925 case LPFC_SLI_INTF_IF_TYPE_0:
7926 phba->sli4_hba.ue_mask_lo =
7927 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7928 phba->sli4_hba.ue_mask_hi =
7929 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7930 uerrlo_reg.word0 =
7931 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7932 uerrhi_reg.word0 =
7933 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7934 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7935 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7937 "1422 Unrecoverable Error "
7938 "Detected during POST "
7939 "uerr_lo_reg=0x%x, "
7940 "uerr_hi_reg=0x%x, "
7941 "ue_mask_lo_reg=0x%x, "
7942 "ue_mask_hi_reg=0x%x\n",
7943 uerrlo_reg.word0,
7944 uerrhi_reg.word0,
7945 phba->sli4_hba.ue_mask_lo,
7946 phba->sli4_hba.ue_mask_hi);
7947 port_error = -ENODEV;
7948 }
7949 break;
7950 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007951 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007952 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007953 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7954 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007955 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7956 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007957 phba->work_status[0] =
7958 readl(phba->sli4_hba.u.if_type2.
7959 ERR1regaddr);
7960 phba->work_status[1] =
7961 readl(phba->sli4_hba.u.if_type2.
7962 ERR2regaddr);
7963 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007964 "2888 Unrecoverable port error "
7965 "following POST: port status reg "
7966 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007967 "error 1=0x%x, error 2=0x%x\n",
7968 reg_data.word0,
7969 portsmphr_reg.word0,
7970 phba->work_status[0],
7971 phba->work_status[1]);
7972 port_error = -ENODEV;
7973 }
7974 break;
7975 case LPFC_SLI_INTF_IF_TYPE_1:
7976 default:
7977 break;
7978 }
James Smart28baac72010-02-12 14:42:03 -05007979 }
James Smartda0436e2009-05-22 14:51:39 -04007980 return port_error;
7981}
7982
7983/**
7984 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7985 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007986 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007987 *
7988 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7989 * memory map.
7990 **/
7991static void
James Smart2fcee4b2010-12-15 17:57:46 -05007992lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007993{
James Smart2fcee4b2010-12-15 17:57:46 -05007994 switch (if_type) {
7995 case LPFC_SLI_INTF_IF_TYPE_0:
7996 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7997 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7998 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7999 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
8000 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
8001 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
8002 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
8003 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
8004 phba->sli4_hba.SLIINTFregaddr =
8005 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8006 break;
8007 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07008008 phba->sli4_hba.u.if_type2.EQDregaddr =
8009 phba->sli4_hba.conf_regs_memmap_p +
8010 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008011 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008012 phba->sli4_hba.conf_regs_memmap_p +
8013 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008014 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008015 phba->sli4_hba.conf_regs_memmap_p +
8016 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008017 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008018 phba->sli4_hba.conf_regs_memmap_p +
8019 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008020 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008021 phba->sli4_hba.conf_regs_memmap_p +
8022 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008023 phba->sli4_hba.SLIINTFregaddr =
8024 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8025 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008026 phba->sli4_hba.conf_regs_memmap_p +
8027 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008028 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008029 phba->sli4_hba.conf_regs_memmap_p +
8030 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05008031 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008032 phba->sli4_hba.conf_regs_memmap_p +
8033 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008034 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05008035 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008036 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05008037 phba->sli4_hba.MQDBregaddr =
8038 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
8039 phba->sli4_hba.BMBXregaddr =
8040 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8041 break;
James Smart27d6ac02018-02-22 08:18:42 -08008042 case LPFC_SLI_INTF_IF_TYPE_6:
8043 phba->sli4_hba.u.if_type2.EQDregaddr =
8044 phba->sli4_hba.conf_regs_memmap_p +
8045 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8046 phba->sli4_hba.u.if_type2.ERR1regaddr =
8047 phba->sli4_hba.conf_regs_memmap_p +
8048 LPFC_CTL_PORT_ER1_OFFSET;
8049 phba->sli4_hba.u.if_type2.ERR2regaddr =
8050 phba->sli4_hba.conf_regs_memmap_p +
8051 LPFC_CTL_PORT_ER2_OFFSET;
8052 phba->sli4_hba.u.if_type2.CTRLregaddr =
8053 phba->sli4_hba.conf_regs_memmap_p +
8054 LPFC_CTL_PORT_CTL_OFFSET;
8055 phba->sli4_hba.u.if_type2.STATUSregaddr =
8056 phba->sli4_hba.conf_regs_memmap_p +
8057 LPFC_CTL_PORT_STA_OFFSET;
8058 phba->sli4_hba.PSMPHRregaddr =
8059 phba->sli4_hba.conf_regs_memmap_p +
8060 LPFC_CTL_PORT_SEM_OFFSET;
8061 phba->sli4_hba.BMBXregaddr =
8062 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8063 break;
James Smart2fcee4b2010-12-15 17:57:46 -05008064 case LPFC_SLI_INTF_IF_TYPE_1:
8065 default:
8066 dev_printk(KERN_ERR, &phba->pcidev->dev,
8067 "FATAL - unsupported SLI4 interface type - %d\n",
8068 if_type);
8069 break;
8070 }
James Smartda0436e2009-05-22 14:51:39 -04008071}
8072
8073/**
8074 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8075 * @phba: pointer to lpfc hba data structure.
8076 *
James Smart27d6ac02018-02-22 08:18:42 -08008077 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04008078 **/
8079static void
James Smart27d6ac02018-02-22 08:18:42 -08008080lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04008081{
James Smart27d6ac02018-02-22 08:18:42 -08008082 switch (if_type) {
8083 case LPFC_SLI_INTF_IF_TYPE_0:
8084 phba->sli4_hba.PSMPHRregaddr =
8085 phba->sli4_hba.ctrl_regs_memmap_p +
8086 LPFC_SLIPORT_IF0_SMPHR;
8087 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8088 LPFC_HST_ISR0;
8089 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8090 LPFC_HST_IMR0;
8091 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8092 LPFC_HST_ISCR0;
8093 break;
8094 case LPFC_SLI_INTF_IF_TYPE_6:
8095 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8096 LPFC_IF6_RQ_DOORBELL;
8097 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8098 LPFC_IF6_WQ_DOORBELL;
8099 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8100 LPFC_IF6_CQ_DOORBELL;
8101 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8102 LPFC_IF6_EQ_DOORBELL;
8103 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8104 LPFC_IF6_MQ_DOORBELL;
8105 break;
8106 case LPFC_SLI_INTF_IF_TYPE_2:
8107 case LPFC_SLI_INTF_IF_TYPE_1:
8108 default:
8109 dev_err(&phba->pcidev->dev,
8110 "FATAL - unsupported SLI4 interface type - %d\n",
8111 if_type);
8112 break;
8113 }
James Smartda0436e2009-05-22 14:51:39 -04008114}
8115
8116/**
8117 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8118 * @phba: pointer to lpfc hba data structure.
8119 * @vf: virtual function number
8120 *
8121 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8122 * based on the given viftual function number, @vf.
8123 *
8124 * Return 0 if successful, otherwise -ENODEV.
8125 **/
8126static int
8127lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
8128{
8129 if (vf > LPFC_VIR_FUNC_MAX)
8130 return -ENODEV;
8131
8132 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008133 vf * LPFC_VFR_PAGE_SIZE +
8134 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04008135 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008136 vf * LPFC_VFR_PAGE_SIZE +
8137 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08008138 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8139 vf * LPFC_VFR_PAGE_SIZE +
8140 LPFC_EQCQ_DOORBELL);
8141 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04008142 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8143 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
8144 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8145 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
8146 return 0;
8147}
8148
8149/**
8150 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
8151 * @phba: pointer to lpfc hba data structure.
8152 *
8153 * This routine is invoked to create the bootstrap mailbox
8154 * region consistent with the SLI-4 interface spec. This
8155 * routine allocates all memory necessary to communicate
8156 * mailbox commands to the port and sets up all alignment
8157 * needs. No locks are expected to be held when calling
8158 * this routine.
8159 *
8160 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008161 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04008162 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04008163 **/
8164static int
8165lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
8166{
8167 uint32_t bmbx_size;
8168 struct lpfc_dmabuf *dmabuf;
8169 struct dma_address *dma_address;
8170 uint32_t pa_addr;
8171 uint64_t phys_addr;
8172
8173 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8174 if (!dmabuf)
8175 return -ENOMEM;
8176
8177 /*
8178 * The bootstrap mailbox region is comprised of 2 parts
8179 * plus an alignment restriction of 16 bytes.
8180 */
8181 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Luis Chamberlain750afb02019-01-04 09:23:09 +01008182 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
8183 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04008184 if (!dmabuf->virt) {
8185 kfree(dmabuf);
8186 return -ENOMEM;
8187 }
James Smartda0436e2009-05-22 14:51:39 -04008188
8189 /*
8190 * Initialize the bootstrap mailbox pointers now so that the register
8191 * operations are simple later. The mailbox dma address is required
8192 * to be 16-byte aligned. Also align the virtual memory as each
8193 * maibox is copied into the bmbx mailbox region before issuing the
8194 * command to the port.
8195 */
8196 phba->sli4_hba.bmbx.dmabuf = dmabuf;
8197 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
8198
8199 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
8200 LPFC_ALIGN_16_BYTE);
8201 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
8202 LPFC_ALIGN_16_BYTE);
8203
8204 /*
8205 * Set the high and low physical addresses now. The SLI4 alignment
8206 * requirement is 16 bytes and the mailbox is posted to the port
8207 * as two 30-bit addresses. The other data is a bit marking whether
8208 * the 30-bit address is the high or low address.
8209 * Upcast bmbx aphys to 64bits so shift instruction compiles
8210 * clean on 32 bit machines.
8211 */
8212 dma_address = &phba->sli4_hba.bmbx.dma_address;
8213 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
8214 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
8215 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
8216 LPFC_BMBX_BIT1_ADDR_HI);
8217
8218 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
8219 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
8220 LPFC_BMBX_BIT1_ADDR_LO);
8221 return 0;
8222}
8223
8224/**
8225 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
8226 * @phba: pointer to lpfc hba data structure.
8227 *
8228 * This routine is invoked to teardown the bootstrap mailbox
8229 * region and release all host resources. This routine requires
8230 * the caller to ensure all mailbox commands recovered, no
8231 * additional mailbox comands are sent, and interrupts are disabled
8232 * before calling this routine.
8233 *
8234 **/
8235static void
8236lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
8237{
8238 dma_free_coherent(&phba->pcidev->dev,
8239 phba->sli4_hba.bmbx.bmbx_size,
8240 phba->sli4_hba.bmbx.dmabuf->virt,
8241 phba->sli4_hba.bmbx.dmabuf->phys);
8242
8243 kfree(phba->sli4_hba.bmbx.dmabuf);
8244 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
8245}
8246
8247/**
8248 * lpfc_sli4_read_config - Get the config parameters.
8249 * @phba: pointer to lpfc hba data structure.
8250 *
8251 * This routine is invoked to read the configuration parameters from the HBA.
8252 * The configuration parameters are used to set the base and maximum values
8253 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
8254 * allocation for the port.
8255 *
8256 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008257 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008258 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008259 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008260 **/
James Smartff78d8f2011-12-13 13:21:35 -05008261int
James Smartda0436e2009-05-22 14:51:39 -04008262lpfc_sli4_read_config(struct lpfc_hba *phba)
8263{
8264 LPFC_MBOXQ_t *pmb;
8265 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04008266 union lpfc_sli4_cfg_shdr *shdr;
8267 uint32_t shdr_status, shdr_add_status;
8268 struct lpfc_mbx_get_func_cfg *get_func_cfg;
8269 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04008270 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07008271 uint16_t forced_link_speed;
James Smart6a828b02019-01-28 11:14:31 -08008272 uint32_t if_type, qmin;
James Smart8aa134a2012-08-14 14:25:29 -04008273 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04008274
8275 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8276 if (!pmb) {
8277 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8278 "2011 Unable to allocate memory for issuing "
8279 "SLI_CONFIG_SPECIAL mailbox command\n");
8280 return -ENOMEM;
8281 }
8282
8283 lpfc_read_config(phba, pmb);
8284
8285 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8286 if (rc != MBX_SUCCESS) {
8287 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8288 "2012 Mailbox failed , mbxCmd x%x "
8289 "READ_CONFIG, mbxStatus x%x\n",
8290 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8291 bf_get(lpfc_mqe_status, &pmb->u.mqe));
8292 rc = -EIO;
8293 } else {
8294 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05008295 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
8296 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
8297 phba->sli4_hba.lnk_info.lnk_tp =
8298 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
8299 phba->sli4_hba.lnk_info.lnk_no =
8300 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
8301 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8302 "3081 lnk_type:%d, lnk_numb:%d\n",
8303 phba->sli4_hba.lnk_info.lnk_tp,
8304 phba->sli4_hba.lnk_info.lnk_no);
8305 } else
8306 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8307 "3082 Mailbox (x%x) returned ldv:x0\n",
8308 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07008309 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
8310 phba->bbcredit_support = 1;
8311 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
8312 }
8313
James Smart1dc5ec22018-10-23 13:41:11 -07008314 phba->sli4_hba.conf_trunk =
8315 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04008316 phba->sli4_hba.extents_in_use =
8317 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008318 phba->sli4_hba.max_cfg_param.max_xri =
8319 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
James Smart31f06d22019-08-14 16:56:31 -07008320 /* Reduce resource usage in kdump environment */
8321 if (is_kdump_kernel() &&
8322 phba->sli4_hba.max_cfg_param.max_xri > 512)
8323 phba->sli4_hba.max_cfg_param.max_xri = 512;
James Smartda0436e2009-05-22 14:51:39 -04008324 phba->sli4_hba.max_cfg_param.xri_base =
8325 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
8326 phba->sli4_hba.max_cfg_param.max_vpi =
8327 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08008328 /* Limit the max we support */
8329 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
8330 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04008331 phba->sli4_hba.max_cfg_param.vpi_base =
8332 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
8333 phba->sli4_hba.max_cfg_param.max_rpi =
8334 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
8335 phba->sli4_hba.max_cfg_param.rpi_base =
8336 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
8337 phba->sli4_hba.max_cfg_param.max_vfi =
8338 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
8339 phba->sli4_hba.max_cfg_param.vfi_base =
8340 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
8341 phba->sli4_hba.max_cfg_param.max_fcfi =
8342 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008343 phba->sli4_hba.max_cfg_param.max_eq =
8344 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
8345 phba->sli4_hba.max_cfg_param.max_rq =
8346 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
8347 phba->sli4_hba.max_cfg_param.max_wq =
8348 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
8349 phba->sli4_hba.max_cfg_param.max_cq =
8350 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
8351 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
8352 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
8353 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
8354 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05008355 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
8356 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04008357 phba->max_vports = phba->max_vpi;
8358 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04008359 "2003 cfg params Extents? %d "
8360 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04008361 "VPI(B:%d M:%d) "
8362 "VFI(B:%d M:%d) "
8363 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08008364 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04008365 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04008366 phba->sli4_hba.max_cfg_param.xri_base,
8367 phba->sli4_hba.max_cfg_param.max_xri,
8368 phba->sli4_hba.max_cfg_param.vpi_base,
8369 phba->sli4_hba.max_cfg_param.max_vpi,
8370 phba->sli4_hba.max_cfg_param.vfi_base,
8371 phba->sli4_hba.max_cfg_param.max_vfi,
8372 phba->sli4_hba.max_cfg_param.rpi_base,
8373 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08008374 phba->sli4_hba.max_cfg_param.max_fcfi,
8375 phba->sli4_hba.max_cfg_param.max_eq,
8376 phba->sli4_hba.max_cfg_param.max_cq,
8377 phba->sli4_hba.max_cfg_param.max_wq,
8378 phba->sli4_hba.max_cfg_param.max_rq);
8379
James Smartd38f33b2018-05-04 20:37:54 -07008380 /*
James Smart6a828b02019-01-28 11:14:31 -08008381 * Calculate queue resources based on how
8382 * many WQ/CQ/EQs are available.
James Smartd38f33b2018-05-04 20:37:54 -07008383 */
James Smart6a828b02019-01-28 11:14:31 -08008384 qmin = phba->sli4_hba.max_cfg_param.max_wq;
8385 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
8386 qmin = phba->sli4_hba.max_cfg_param.max_cq;
8387 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
8388 qmin = phba->sli4_hba.max_cfg_param.max_eq;
8389 /*
8390 * Whats left after this can go toward NVME / FCP.
8391 * The minus 4 accounts for ELS, NVME LS, MBOX
8392 * plus one extra. When configured for
8393 * NVMET, FCP io channel WQs are not created.
8394 */
8395 qmin -= 4;
James Smartd38f33b2018-05-04 20:37:54 -07008396
James Smart6a828b02019-01-28 11:14:31 -08008397 /* If NVME is configured, double the number of CQ/WQs needed */
8398 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
8399 !phba->nvmet_support)
8400 qmin /= 2;
James Smartd38f33b2018-05-04 20:37:54 -07008401
James Smart6a828b02019-01-28 11:14:31 -08008402 /* Check to see if there is enough for NVME */
8403 if ((phba->cfg_irq_chann > qmin) ||
8404 (phba->cfg_hdw_queue > qmin)) {
8405 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8406 "2005 Reducing Queues: "
8407 "WQ %d CQ %d EQ %d: min %d: "
8408 "IRQ %d HDWQ %d\n",
James Smartd38f33b2018-05-04 20:37:54 -07008409 phba->sli4_hba.max_cfg_param.max_wq,
8410 phba->sli4_hba.max_cfg_param.max_cq,
James Smart6a828b02019-01-28 11:14:31 -08008411 phba->sli4_hba.max_cfg_param.max_eq,
8412 qmin, phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08008413 phba->cfg_hdw_queue);
James Smartd38f33b2018-05-04 20:37:54 -07008414
James Smart6a828b02019-01-28 11:14:31 -08008415 if (phba->cfg_irq_chann > qmin)
8416 phba->cfg_irq_chann = qmin;
8417 if (phba->cfg_hdw_queue > qmin)
8418 phba->cfg_hdw_queue = qmin;
James Smartd38f33b2018-05-04 20:37:54 -07008419 }
James Smartda0436e2009-05-22 14:51:39 -04008420 }
James Smart912e3ac2011-05-24 11:42:11 -04008421
8422 if (rc)
8423 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04008424
James Smartc6918162016-10-13 15:06:16 -07008425 /* Update link speed if forced link speed is supported */
8426 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08008427 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07008428 forced_link_speed =
8429 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8430 if (forced_link_speed) {
8431 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8432
8433 switch (forced_link_speed) {
8434 case LINK_SPEED_1G:
8435 phba->cfg_link_speed =
8436 LPFC_USER_LINK_SPEED_1G;
8437 break;
8438 case LINK_SPEED_2G:
8439 phba->cfg_link_speed =
8440 LPFC_USER_LINK_SPEED_2G;
8441 break;
8442 case LINK_SPEED_4G:
8443 phba->cfg_link_speed =
8444 LPFC_USER_LINK_SPEED_4G;
8445 break;
8446 case LINK_SPEED_8G:
8447 phba->cfg_link_speed =
8448 LPFC_USER_LINK_SPEED_8G;
8449 break;
8450 case LINK_SPEED_10G:
8451 phba->cfg_link_speed =
8452 LPFC_USER_LINK_SPEED_10G;
8453 break;
8454 case LINK_SPEED_16G:
8455 phba->cfg_link_speed =
8456 LPFC_USER_LINK_SPEED_16G;
8457 break;
8458 case LINK_SPEED_32G:
8459 phba->cfg_link_speed =
8460 LPFC_USER_LINK_SPEED_32G;
8461 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08008462 case LINK_SPEED_64G:
8463 phba->cfg_link_speed =
8464 LPFC_USER_LINK_SPEED_64G;
8465 break;
James Smartc6918162016-10-13 15:06:16 -07008466 case 0xffff:
8467 phba->cfg_link_speed =
8468 LPFC_USER_LINK_SPEED_AUTO;
8469 break;
8470 default:
8471 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8472 "0047 Unrecognized link "
8473 "speed : %d\n",
8474 forced_link_speed);
8475 phba->cfg_link_speed =
8476 LPFC_USER_LINK_SPEED_AUTO;
8477 }
8478 }
8479 }
8480
James Smartda0436e2009-05-22 14:51:39 -04008481 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04008482 length = phba->sli4_hba.max_cfg_param.max_xri -
8483 lpfc_sli4_get_els_iocb_cnt(phba);
8484 if (phba->cfg_hba_queue_depth > length) {
8485 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8486 "3361 HBA queue depth changed from %d to %d\n",
8487 phba->cfg_hba_queue_depth, length);
8488 phba->cfg_hba_queue_depth = length;
8489 }
James Smart912e3ac2011-05-24 11:42:11 -04008490
James Smart27d6ac02018-02-22 08:18:42 -08008491 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04008492 LPFC_SLI_INTF_IF_TYPE_2)
8493 goto read_cfg_out;
8494
8495 /* get the pf# and vf# for SLI4 if_type 2 port */
8496 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8497 sizeof(struct lpfc_sli4_cfg_mhdr));
8498 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8499 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8500 length, LPFC_SLI4_MBX_EMBED);
8501
James Smart8aa134a2012-08-14 14:25:29 -04008502 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04008503 shdr = (union lpfc_sli4_cfg_shdr *)
8504 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8505 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8506 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04008507 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04008508 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8509 "3026 Mailbox failed , mbxCmd x%x "
8510 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8511 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8512 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04008513 goto read_cfg_out;
8514 }
8515
8516 /* search for fc_fcoe resrouce descriptor */
8517 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04008518
James Smart8aa134a2012-08-14 14:25:29 -04008519 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8520 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8521 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8522 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8523 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8524 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8525 goto read_cfg_out;
8526
James Smart912e3ac2011-05-24 11:42:11 -04008527 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04008528 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04008529 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04008530 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04008531 phba->sli4_hba.iov.pf_number =
8532 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8533 phba->sli4_hba.iov.vf_number =
8534 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8535 break;
8536 }
8537 }
8538
8539 if (i < LPFC_RSRC_DESC_MAX_NUM)
8540 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8541 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8542 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8543 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04008544 else
James Smart912e3ac2011-05-24 11:42:11 -04008545 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8546 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008547 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008548 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008549
8550read_cfg_out:
8551 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008552 return rc;
8553}
8554
8555/**
James Smart2fcee4b2010-12-15 17:57:46 -05008556 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008557 * @phba: pointer to lpfc hba data structure.
8558 *
James Smart2fcee4b2010-12-15 17:57:46 -05008559 * This routine is invoked to setup the port-side endian order when
8560 * the port if_type is 0. This routine has no function for other
8561 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008562 *
8563 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008564 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008565 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008566 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008567 **/
8568static int
8569lpfc_setup_endian_order(struct lpfc_hba *phba)
8570{
8571 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008572 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008573 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8574 HOST_ENDIAN_HIGH_WORD1};
8575
James Smart2fcee4b2010-12-15 17:57:46 -05008576 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8577 switch (if_type) {
8578 case LPFC_SLI_INTF_IF_TYPE_0:
8579 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8580 GFP_KERNEL);
8581 if (!mboxq) {
8582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8583 "0492 Unable to allocate memory for "
8584 "issuing SLI_CONFIG_SPECIAL mailbox "
8585 "command\n");
8586 return -ENOMEM;
8587 }
James Smartda0436e2009-05-22 14:51:39 -04008588
James Smart2fcee4b2010-12-15 17:57:46 -05008589 /*
8590 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8591 * two words to contain special data values and no other data.
8592 */
8593 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8594 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8595 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8596 if (rc != MBX_SUCCESS) {
8597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8598 "0493 SLI_CONFIG_SPECIAL mailbox "
8599 "failed with status x%x\n",
8600 rc);
8601 rc = -EIO;
8602 }
8603 mempool_free(mboxq, phba->mbox_mem_pool);
8604 break;
James Smart27d6ac02018-02-22 08:18:42 -08008605 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008606 case LPFC_SLI_INTF_IF_TYPE_2:
8607 case LPFC_SLI_INTF_IF_TYPE_1:
8608 default:
8609 break;
James Smartda0436e2009-05-22 14:51:39 -04008610 }
James Smartda0436e2009-05-22 14:51:39 -04008611 return rc;
8612}
8613
8614/**
James Smart895427b2017-02-12 13:52:30 -08008615 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008616 * @phba: pointer to lpfc hba data structure.
8617 *
James Smart895427b2017-02-12 13:52:30 -08008618 * This routine is invoked to check the user settable queue counts for EQs.
8619 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008620 * adhere to the constraints of the system's interrupt vectors and the port's
8621 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008622 *
8623 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008624 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008625 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008626 **/
8627static int
James Smart5350d872011-10-10 21:33:49 -04008628lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008629{
James Smartda0436e2009-05-22 14:51:39 -04008630 /*
James Smart67d12732012-08-03 12:36:13 -04008631 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008632 * device parameters
8633 */
8634
James Smartbcb24f62017-11-20 16:00:36 -08008635 if (phba->nvmet_support) {
James Smart6a828b02019-01-28 11:14:31 -08008636 if (phba->cfg_irq_chann < phba->cfg_nvmet_mrq)
8637 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
James Smart982ab122019-03-12 16:30:10 -07008638 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8639 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smartbcb24f62017-11-20 16:00:36 -08008640 }
James Smart895427b2017-02-12 13:52:30 -08008641
8642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -08008643 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
8644 phba->cfg_hdw_queue, phba->cfg_irq_chann,
8645 phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008646
James Smartda0436e2009-05-22 14:51:39 -04008647 /* Get EQ depth from module parameter, fake the default for now */
8648 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8649 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8650
James Smart5350d872011-10-10 21:33:49 -04008651 /* Get CQ depth from module parameter, fake the default for now */
8652 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8653 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008654 return 0;
James Smart895427b2017-02-12 13:52:30 -08008655}
8656
8657static int
8658lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8659{
8660 struct lpfc_queue *qdesc;
James Smartc1a21eb2019-03-12 16:30:29 -07008661 int cpu;
James Smart895427b2017-02-12 13:52:30 -08008662
James Smartc1a21eb2019-03-12 16:30:29 -07008663 cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ);
James Smarta51e41b2017-12-08 17:18:06 -08008664 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008665 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008666 LPFC_CQE_EXP_COUNT, cpu);
James Smart895427b2017-02-12 13:52:30 -08008667 if (!qdesc) {
8668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8669 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8670 wqidx);
8671 return 1;
8672 }
James Smart7365f6f2018-02-22 08:18:46 -08008673 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008674 qdesc->hdwq = wqidx;
James Smartc1a21eb2019-03-12 16:30:29 -07008675 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008676 phba->sli4_hba.hdwq[wqidx].nvme_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008677
James Smarta51e41b2017-12-08 17:18:06 -08008678 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc1a21eb2019-03-12 16:30:29 -07008679 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT,
8680 cpu);
James Smart895427b2017-02-12 13:52:30 -08008681 if (!qdesc) {
8682 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8683 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8684 wqidx);
8685 return 1;
8686 }
James Smart5e5b5112019-01-28 11:14:22 -08008687 qdesc->hdwq = wqidx;
James Smart6a828b02019-01-28 11:14:31 -08008688 qdesc->chann = wqidx;
James Smartcdb42be2019-01-28 11:14:21 -08008689 phba->sli4_hba.hdwq[wqidx].nvme_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008690 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8691 return 0;
8692}
8693
8694static int
8695lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8696{
8697 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008698 uint32_t wqesize;
James Smartc1a21eb2019-03-12 16:30:29 -07008699 int cpu;
James Smart895427b2017-02-12 13:52:30 -08008700
James Smartc1a21eb2019-03-12 16:30:29 -07008701 cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ);
James Smart895427b2017-02-12 13:52:30 -08008702 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008703 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008704 /* Increase the CQ size when WQEs contain an embedded cdb */
8705 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8706 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008707 LPFC_CQE_EXP_COUNT, cpu);
James Smarta51e41b2017-12-08 17:18:06 -08008708
8709 else
8710 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8711 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008712 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08008713 if (!qdesc) {
8714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8715 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8716 return 1;
8717 }
James Smart7365f6f2018-02-22 08:18:46 -08008718 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008719 qdesc->hdwq = wqidx;
James Smartc1a21eb2019-03-12 16:30:29 -07008720 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008721 phba->sli4_hba.hdwq[wqidx].fcp_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008722
8723 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008724 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008725 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008726 wqesize = (phba->fcp_embed_io) ?
8727 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008728 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008729 wqesize,
James Smartc1a21eb2019-03-12 16:30:29 -07008730 LPFC_WQE_EXP_COUNT, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008731 } else
James Smarta51e41b2017-12-08 17:18:06 -08008732 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8733 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008734 phba->sli4_hba.wq_ecount, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008735
James Smart895427b2017-02-12 13:52:30 -08008736 if (!qdesc) {
8737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8738 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8739 wqidx);
8740 return 1;
8741 }
James Smart5e5b5112019-01-28 11:14:22 -08008742 qdesc->hdwq = wqidx;
James Smart6a828b02019-01-28 11:14:31 -08008743 qdesc->chann = wqidx;
James Smartcdb42be2019-01-28 11:14:21 -08008744 phba->sli4_hba.hdwq[wqidx].fcp_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008745 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8746 return 0;
James Smart5350d872011-10-10 21:33:49 -04008747}
8748
8749/**
8750 * lpfc_sli4_queue_create - Create all the SLI4 queues
8751 * @phba: pointer to lpfc hba data structure.
8752 *
8753 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8754 * operation. For each SLI4 queue type, the parameters such as queue entry
8755 * count (queue depth) shall be taken from the module parameter. For now,
8756 * we just use some constant number as place holder.
8757 *
8758 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008759 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008760 * -ENOMEM - No availble memory
8761 * -EIO - The mailbox failed to complete successfully.
8762 **/
8763int
8764lpfc_sli4_queue_create(struct lpfc_hba *phba)
8765{
8766 struct lpfc_queue *qdesc;
James Smart657add42019-05-21 17:49:06 -07008767 int idx, cpu, eqcpu;
James Smart5e5b5112019-01-28 11:14:22 -08008768 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07008769 struct lpfc_vector_map_info *cpup;
8770 struct lpfc_vector_map_info *eqcpup;
James Smart32517fc2019-01-28 11:14:33 -08008771 struct lpfc_eq_intr_info *eqi;
James Smart5350d872011-10-10 21:33:49 -04008772
8773 /*
James Smart67d12732012-08-03 12:36:13 -04008774 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008775 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008776 */
James Smart67d12732012-08-03 12:36:13 -04008777 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8778 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8779 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8780 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8781 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8782 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008783 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8784 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8785 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8786 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008787
James Smartcdb42be2019-01-28 11:14:21 -08008788 if (!phba->sli4_hba.hdwq) {
James Smart5e5b5112019-01-28 11:14:22 -08008789 phba->sli4_hba.hdwq = kcalloc(
8790 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
8791 GFP_KERNEL);
8792 if (!phba->sli4_hba.hdwq) {
James Smart895427b2017-02-12 13:52:30 -08008793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5e5b5112019-01-28 11:14:22 -08008794 "6427 Failed allocate memory for "
8795 "fast-path Hardware Queue array\n");
James Smart895427b2017-02-12 13:52:30 -08008796 goto out_error;
8797 }
James Smart5e5b5112019-01-28 11:14:22 -08008798 /* Prepare hardware queues to take IO buffers */
8799 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
8800 qp = &phba->sli4_hba.hdwq[idx];
8801 spin_lock_init(&qp->io_buf_list_get_lock);
8802 spin_lock_init(&qp->io_buf_list_put_lock);
8803 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
8804 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
8805 qp->get_io_bufs = 0;
8806 qp->put_io_bufs = 0;
8807 qp->total_io_bufs = 0;
8808 spin_lock_init(&qp->abts_scsi_buf_list_lock);
8809 INIT_LIST_HEAD(&qp->lpfc_abts_scsi_buf_list);
8810 qp->abts_scsi_io_bufs = 0;
8811 spin_lock_init(&qp->abts_nvme_buf_list_lock);
8812 INIT_LIST_HEAD(&qp->lpfc_abts_nvme_buf_list);
8813 qp->abts_nvme_io_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08008814 }
James Smart67d12732012-08-03 12:36:13 -04008815 }
8816
James Smartcdb42be2019-01-28 11:14:21 -08008817 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -08008818 if (phba->nvmet_support) {
8819 phba->sli4_hba.nvmet_cqset = kcalloc(
8820 phba->cfg_nvmet_mrq,
8821 sizeof(struct lpfc_queue *),
8822 GFP_KERNEL);
8823 if (!phba->sli4_hba.nvmet_cqset) {
8824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8825 "3121 Fail allocate memory for "
8826 "fast-path CQ set array\n");
8827 goto out_error;
8828 }
8829 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8830 phba->cfg_nvmet_mrq,
8831 sizeof(struct lpfc_queue *),
8832 GFP_KERNEL);
8833 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8834 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8835 "3122 Fail allocate memory for "
8836 "fast-path RQ set hdr array\n");
8837 goto out_error;
8838 }
8839 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8840 phba->cfg_nvmet_mrq,
8841 sizeof(struct lpfc_queue *),
8842 GFP_KERNEL);
8843 if (!phba->sli4_hba.nvmet_mrq_data) {
8844 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8845 "3124 Fail allocate memory for "
8846 "fast-path RQ set data array\n");
8847 goto out_error;
8848 }
8849 }
James Smart67d12732012-08-03 12:36:13 -04008850 }
James Smartda0436e2009-05-22 14:51:39 -04008851
James Smart895427b2017-02-12 13:52:30 -08008852 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008853
James Smart895427b2017-02-12 13:52:30 -08008854 /* Create HBA Event Queues (EQs) */
James Smart657add42019-05-21 17:49:06 -07008855 for_each_present_cpu(cpu) {
8856 /* We only want to create 1 EQ per vector, even though
8857 * multiple CPUs might be using that vector. so only
8858 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
James Smart6a828b02019-01-28 11:14:31 -08008859 */
James Smart657add42019-05-21 17:49:06 -07008860 cpup = &phba->sli4_hba.cpu_map[cpu];
8861 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
James Smart6a828b02019-01-28 11:14:31 -08008862 continue;
James Smart657add42019-05-21 17:49:06 -07008863
8864 /* Get a ptr to the Hardware Queue associated with this CPU */
8865 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8866
8867 /* Allocate an EQ */
James Smart81b96ed2017-11-20 16:00:29 -08008868 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8869 phba->sli4_hba.eq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008870 phba->sli4_hba.eq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008871 if (!qdesc) {
8872 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart657add42019-05-21 17:49:06 -07008873 "0497 Failed allocate EQ (%d)\n",
8874 cpup->hdwq);
James Smart67d12732012-08-03 12:36:13 -04008875 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008876 }
James Smart7365f6f2018-02-22 08:18:46 -08008877 qdesc->qe_valid = 1;
James Smart657add42019-05-21 17:49:06 -07008878 qdesc->hdwq = cpup->hdwq;
8879 qdesc->chann = cpu; /* First CPU this EQ is affinitised to */
James Smart32517fc2019-01-28 11:14:33 -08008880 qdesc->last_cpu = qdesc->chann;
James Smart657add42019-05-21 17:49:06 -07008881
8882 /* Save the allocated EQ in the Hardware Queue */
8883 qp->hba_eq = qdesc;
8884
James Smart32517fc2019-01-28 11:14:33 -08008885 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
8886 list_add(&qdesc->cpu_list, &eqi->list);
James Smartda0436e2009-05-22 14:51:39 -04008887 }
8888
James Smart657add42019-05-21 17:49:06 -07008889 /* Now we need to populate the other Hardware Queues, that share
8890 * an IRQ vector, with the associated EQ ptr.
8891 */
8892 for_each_present_cpu(cpu) {
8893 cpup = &phba->sli4_hba.cpu_map[cpu];
8894
8895 /* Check for EQ already allocated in previous loop */
8896 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
8897 continue;
8898
8899 /* Check for multiple CPUs per hdwq */
8900 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8901 if (qp->hba_eq)
8902 continue;
8903
8904 /* We need to share an EQ for this hdwq */
8905 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
8906 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
8907 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
8908 }
James Smart895427b2017-02-12 13:52:30 -08008909
James Smartcdb42be2019-01-28 11:14:21 -08008910 /* Allocate SCSI SLI4 CQ/WQs */
James Smart6a828b02019-01-28 11:14:31 -08008911 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smart895427b2017-02-12 13:52:30 -08008912 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8913 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -08008914 }
James Smart895427b2017-02-12 13:52:30 -08008915
James Smartcdb42be2019-01-28 11:14:21 -08008916 /* Allocate NVME SLI4 CQ/WQs */
8917 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart6a828b02019-01-28 11:14:31 -08008918 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smartcdb42be2019-01-28 11:14:21 -08008919 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8920 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -08008921 }
James Smart67d12732012-08-03 12:36:13 -04008922
James Smartcdb42be2019-01-28 11:14:21 -08008923 if (phba->nvmet_support) {
8924 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -07008925 cpu = lpfc_find_cpu_handle(phba, idx,
8926 LPFC_FIND_BY_HDWQ);
James Smartcdb42be2019-01-28 11:14:21 -08008927 qdesc = lpfc_sli4_queue_alloc(
8928 phba,
James Smart81b96ed2017-11-20 16:00:29 -08008929 LPFC_DEFAULT_PAGE_SIZE,
8930 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008931 phba->sli4_hba.cq_ecount,
8932 cpu);
James Smartcdb42be2019-01-28 11:14:21 -08008933 if (!qdesc) {
8934 lpfc_printf_log(
8935 phba, KERN_ERR, LOG_INIT,
8936 "3142 Failed allocate NVME "
8937 "CQ Set (%d)\n", idx);
8938 goto out_error;
8939 }
8940 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008941 qdesc->hdwq = idx;
James Smartc1a21eb2019-03-12 16:30:29 -07008942 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008943 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
James Smart2d7dbc42017-02-12 13:52:35 -08008944 }
James Smart2d7dbc42017-02-12 13:52:35 -08008945 }
8946 }
8947
James Smartda0436e2009-05-22 14:51:39 -04008948 /*
James Smart67d12732012-08-03 12:36:13 -04008949 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008950 */
8951
James Smartc1a21eb2019-03-12 16:30:29 -07008952 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
James Smartda0436e2009-05-22 14:51:39 -04008953 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008954 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8955 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008956 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008957 if (!qdesc) {
8958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8959 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008960 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008961 }
James Smart7365f6f2018-02-22 08:18:46 -08008962 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008963 phba->sli4_hba.mbx_cq = qdesc;
8964
8965 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008966 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8967 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008968 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008969 if (!qdesc) {
8970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8971 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008972 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008973 }
James Smart7365f6f2018-02-22 08:18:46 -08008974 qdesc->qe_valid = 1;
James Smart6a828b02019-01-28 11:14:31 -08008975 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04008976 phba->sli4_hba.els_cq = qdesc;
8977
James Smartda0436e2009-05-22 14:51:39 -04008978
James Smart5350d872011-10-10 21:33:49 -04008979 /*
James Smart67d12732012-08-03 12:36:13 -04008980 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008981 */
James Smartda0436e2009-05-22 14:51:39 -04008982
8983 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008984
James Smart81b96ed2017-11-20 16:00:29 -08008985 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8986 phba->sli4_hba.mq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008987 phba->sli4_hba.mq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008988 if (!qdesc) {
8989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8990 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008991 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008992 }
James Smart6a828b02019-01-28 11:14:31 -08008993 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04008994 phba->sli4_hba.mbx_wq = qdesc;
8995
8996 /*
James Smart67d12732012-08-03 12:36:13 -04008997 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008998 */
James Smartda0436e2009-05-22 14:51:39 -04008999
9000 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009001 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9002 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009003 phba->sli4_hba.wq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009004 if (!qdesc) {
9005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9006 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04009007 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009008 }
James Smart6a828b02019-01-28 11:14:31 -08009009 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04009010 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08009011 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9012
9013 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9014 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009015 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9016 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009017 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009018 if (!qdesc) {
9019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9020 "6079 Failed allocate NVME LS CQ\n");
9021 goto out_error;
9022 }
James Smart6a828b02019-01-28 11:14:31 -08009023 qdesc->chann = 0;
James Smart7365f6f2018-02-22 08:18:46 -08009024 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08009025 phba->sli4_hba.nvmels_cq = qdesc;
9026
9027 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009028 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9029 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009030 phba->sli4_hba.wq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009031 if (!qdesc) {
9032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9033 "6080 Failed allocate NVME LS WQ\n");
9034 goto out_error;
9035 }
James Smart6a828b02019-01-28 11:14:31 -08009036 qdesc->chann = 0;
James Smart895427b2017-02-12 13:52:30 -08009037 phba->sli4_hba.nvmels_wq = qdesc;
9038 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9039 }
James Smartda0436e2009-05-22 14:51:39 -04009040
James Smartda0436e2009-05-22 14:51:39 -04009041 /*
9042 * Create Receive Queue (RQ)
9043 */
James Smartda0436e2009-05-22 14:51:39 -04009044
9045 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08009046 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9047 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009048 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009049 if (!qdesc) {
9050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9051 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009052 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009053 }
9054 phba->sli4_hba.hdr_rq = qdesc;
9055
9056 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08009057 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9058 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009059 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009060 if (!qdesc) {
9061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9062 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009063 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009064 }
9065 phba->sli4_hba.dat_rq = qdesc;
9066
James Smartcdb42be2019-01-28 11:14:21 -08009067 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
9068 phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08009069 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -07009070 cpu = lpfc_find_cpu_handle(phba, idx,
9071 LPFC_FIND_BY_HDWQ);
James Smart2d7dbc42017-02-12 13:52:35 -08009072 /* Create NVMET Receive Queue for header */
9073 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009074 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009075 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009076 LPFC_NVMET_RQE_DEF_COUNT,
9077 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009078 if (!qdesc) {
9079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9080 "3146 Failed allocate "
9081 "receive HRQ\n");
9082 goto out_error;
9083 }
James Smart5e5b5112019-01-28 11:14:22 -08009084 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009085 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
9086
9087 /* Only needed for header of RQ pair */
James Smartc1a21eb2019-03-12 16:30:29 -07009088 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
9089 GFP_KERNEL,
9090 cpu_to_node(cpu));
James Smart2d7dbc42017-02-12 13:52:35 -08009091 if (qdesc->rqbp == NULL) {
9092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9093 "6131 Failed allocate "
9094 "Header RQBP\n");
9095 goto out_error;
9096 }
9097
Dick Kennedy4b40d022017-08-23 16:55:38 -07009098 /* Put list in known state in case driver load fails. */
9099 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
9100
James Smart2d7dbc42017-02-12 13:52:35 -08009101 /* Create NVMET Receive Queue for data */
9102 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009103 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009104 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009105 LPFC_NVMET_RQE_DEF_COUNT,
9106 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009107 if (!qdesc) {
9108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9109 "3156 Failed allocate "
9110 "receive DRQ\n");
9111 goto out_error;
9112 }
James Smart5e5b5112019-01-28 11:14:22 -08009113 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009114 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
9115 }
9116 }
9117
James Smart4c47efc2019-01-28 11:14:25 -08009118#if defined(BUILD_NVME)
9119 /* Clear NVME stats */
9120 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9121 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9122 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
9123 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
9124 }
9125 }
9126#endif
9127
9128 /* Clear SCSI stats */
9129 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
9130 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9131 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
9132 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
9133 }
9134 }
9135
James Smartda0436e2009-05-22 14:51:39 -04009136 return 0;
9137
James Smartda0436e2009-05-22 14:51:39 -04009138out_error:
James Smart67d12732012-08-03 12:36:13 -04009139 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009140 return -ENOMEM;
9141}
9142
James Smart895427b2017-02-12 13:52:30 -08009143static inline void
9144__lpfc_sli4_release_queue(struct lpfc_queue **qp)
9145{
9146 if (*qp != NULL) {
9147 lpfc_sli4_queue_free(*qp);
9148 *qp = NULL;
9149 }
9150}
9151
9152static inline void
9153lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
9154{
9155 int idx;
9156
9157 if (*qs == NULL)
9158 return;
9159
9160 for (idx = 0; idx < max; idx++)
9161 __lpfc_sli4_release_queue(&(*qs)[idx]);
9162
9163 kfree(*qs);
9164 *qs = NULL;
9165}
9166
9167static inline void
James Smart6a828b02019-01-28 11:14:31 -08009168lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08009169{
James Smart6a828b02019-01-28 11:14:31 -08009170 struct lpfc_sli4_hdw_queue *hdwq;
James Smart657add42019-05-21 17:49:06 -07009171 struct lpfc_queue *eq;
James Smartcdb42be2019-01-28 11:14:21 -08009172 uint32_t idx;
9173
James Smart6a828b02019-01-28 11:14:31 -08009174 hdwq = phba->sli4_hba.hdwq;
James Smart6a828b02019-01-28 11:14:31 -08009175
James Smart657add42019-05-21 17:49:06 -07009176 /* Loop thru all Hardware Queues */
9177 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9178 /* Free the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009179 lpfc_sli4_queue_free(hdwq[idx].fcp_cq);
9180 lpfc_sli4_queue_free(hdwq[idx].nvme_cq);
9181 lpfc_sli4_queue_free(hdwq[idx].fcp_wq);
9182 lpfc_sli4_queue_free(hdwq[idx].nvme_wq);
James Smart657add42019-05-21 17:49:06 -07009183 hdwq[idx].hba_eq = NULL;
James Smartcdb42be2019-01-28 11:14:21 -08009184 hdwq[idx].fcp_cq = NULL;
9185 hdwq[idx].nvme_cq = NULL;
9186 hdwq[idx].fcp_wq = NULL;
9187 hdwq[idx].nvme_wq = NULL;
James Smart895427b2017-02-12 13:52:30 -08009188 }
James Smart657add42019-05-21 17:49:06 -07009189 /* Loop thru all IRQ vectors */
9190 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
9191 /* Free the EQ corresponding to the IRQ vector */
9192 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
9193 lpfc_sli4_queue_free(eq);
9194 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
9195 }
James Smart895427b2017-02-12 13:52:30 -08009196}
9197
James Smartda0436e2009-05-22 14:51:39 -04009198/**
9199 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
9200 * @phba: pointer to lpfc hba data structure.
9201 *
9202 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
9203 * operation.
9204 *
9205 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009206 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009207 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009208 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009209 **/
James Smart5350d872011-10-10 21:33:49 -04009210void
James Smartda0436e2009-05-22 14:51:39 -04009211lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
9212{
James Smart4645f7b2019-03-12 16:30:14 -07009213 /*
9214 * Set FREE_INIT before beginning to free the queues.
9215 * Wait until the users of queues to acknowledge to
9216 * release queues by clearing FREE_WAIT.
9217 */
9218 spin_lock_irq(&phba->hbalock);
9219 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
9220 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
9221 spin_unlock_irq(&phba->hbalock);
9222 msleep(20);
9223 spin_lock_irq(&phba->hbalock);
9224 }
9225 spin_unlock_irq(&phba->hbalock);
9226
James Smart895427b2017-02-12 13:52:30 -08009227 /* Release HBA eqs */
James Smartcdb42be2019-01-28 11:14:21 -08009228 if (phba->sli4_hba.hdwq)
James Smart6a828b02019-01-28 11:14:31 -08009229 lpfc_sli4_release_hdwq(phba);
James Smartda0436e2009-05-22 14:51:39 -04009230
James Smartbcb24f62017-11-20 16:00:36 -08009231 if (phba->nvmet_support) {
9232 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
9233 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08009234
James Smartbcb24f62017-11-20 16:00:36 -08009235 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
9236 phba->cfg_nvmet_mrq);
9237 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
9238 phba->cfg_nvmet_mrq);
9239 }
James Smart2d7dbc42017-02-12 13:52:35 -08009240
James Smartda0436e2009-05-22 14:51:39 -04009241 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009242 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04009243
9244 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08009245 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
9246
9247 /* Release ELS work queue */
9248 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04009249
9250 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009251 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
9252 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04009253
James Smartda0436e2009-05-22 14:51:39 -04009254 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009255 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
9256
9257 /* Release NVME LS complete queue */
9258 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04009259
9260 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009261 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
9262
9263 /* Everything on this list has been freed */
9264 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart4645f7b2019-03-12 16:30:14 -07009265
9266 /* Done with freeing the queues */
9267 spin_lock_irq(&phba->hbalock);
9268 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
9269 spin_unlock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08009270}
9271
9272int
James Smart895427b2017-02-12 13:52:30 -08009273lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
9274{
9275 struct lpfc_rqb *rqbp;
9276 struct lpfc_dmabuf *h_buf;
9277 struct rqb_dmabuf *rqb_buffer;
9278
9279 rqbp = rq->rqbp;
9280 while (!list_empty(&rqbp->rqb_buffer_list)) {
9281 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
9282 struct lpfc_dmabuf, list);
9283
9284 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
9285 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
9286 rqbp->buffer_count--;
9287 }
9288 return 1;
9289}
9290
9291static int
9292lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
9293 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
9294 int qidx, uint32_t qtype)
9295{
9296 struct lpfc_sli_ring *pring;
9297 int rc;
9298
9299 if (!eq || !cq || !wq) {
9300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9301 "6085 Fast-path %s (%d) not allocated\n",
9302 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
9303 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009304 }
James Smartda0436e2009-05-22 14:51:39 -04009305
James Smart895427b2017-02-12 13:52:30 -08009306 /* create the Cq first */
9307 rc = lpfc_cq_create(phba, cq, eq,
9308 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
9309 if (rc) {
9310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9311 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
9312 qidx, (uint32_t)rc);
9313 return rc;
9314 }
9315
9316 if (qtype != LPFC_MBOX) {
James Smartcdb42be2019-01-28 11:14:21 -08009317 /* Setup cq_map for fast lookup */
James Smart895427b2017-02-12 13:52:30 -08009318 if (cq_map)
9319 *cq_map = cq->queue_id;
9320
9321 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9322 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
9323 qidx, cq->queue_id, qidx, eq->queue_id);
9324
9325 /* create the wq */
9326 rc = lpfc_wq_create(phba, wq, cq, qtype);
9327 if (rc) {
9328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc835c082019-03-12 16:30:30 -07009329 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -08009330 qidx, (uint32_t)rc);
9331 /* no need to tear down cq - caller will do so */
9332 return rc;
9333 }
9334
9335 /* Bind this CQ/WQ to the NVME ring */
9336 pring = wq->pring;
9337 pring->sli.sli4.wqp = (void *)wq;
9338 cq->pring = pring;
9339
9340 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9341 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
9342 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
9343 } else {
9344 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
9345 if (rc) {
9346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9347 "0539 Failed setup of slow-path MQ: "
9348 "rc = 0x%x\n", rc);
9349 /* no need to tear down cq - caller will do so */
9350 return rc;
9351 }
9352
9353 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9354 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
9355 phba->sli4_hba.mbx_wq->queue_id,
9356 phba->sli4_hba.mbx_cq->queue_id);
9357 }
9358
9359 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009360}
9361
9362/**
James Smart6a828b02019-01-28 11:14:31 -08009363 * lpfc_setup_cq_lookup - Setup the CQ lookup table
9364 * @phba: pointer to lpfc hba data structure.
9365 *
9366 * This routine will populate the cq_lookup table by all
9367 * available CQ queue_id's.
9368 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07009369static void
James Smart6a828b02019-01-28 11:14:31 -08009370lpfc_setup_cq_lookup(struct lpfc_hba *phba)
9371{
9372 struct lpfc_queue *eq, *childq;
James Smart6a828b02019-01-28 11:14:31 -08009373 int qidx;
9374
James Smart6a828b02019-01-28 11:14:31 -08009375 memset(phba->sli4_hba.cq_lookup, 0,
9376 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
James Smart657add42019-05-21 17:49:06 -07009377 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009378 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009379 /* Get the EQ corresponding to the IRQ vector */
9380 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
James Smart6a828b02019-01-28 11:14:31 -08009381 if (!eq)
9382 continue;
James Smart657add42019-05-21 17:49:06 -07009383 /* Loop through all CQs associated with that EQ */
James Smart6a828b02019-01-28 11:14:31 -08009384 list_for_each_entry(childq, &eq->child_list, list) {
9385 if (childq->queue_id > phba->sli4_hba.cq_max)
9386 continue;
9387 if ((childq->subtype == LPFC_FCP) ||
9388 (childq->subtype == LPFC_NVME))
9389 phba->sli4_hba.cq_lookup[childq->queue_id] =
9390 childq;
9391 }
9392 }
9393}
9394
9395/**
James Smartda0436e2009-05-22 14:51:39 -04009396 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
9397 * @phba: pointer to lpfc hba data structure.
9398 *
9399 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
9400 * operation.
9401 *
9402 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009403 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009404 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009405 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009406 **/
9407int
9408lpfc_sli4_queue_setup(struct lpfc_hba *phba)
9409{
James Smart962bc512013-01-03 15:44:00 -05009410 uint32_t shdr_status, shdr_add_status;
9411 union lpfc_sli4_cfg_shdr *shdr;
James Smart657add42019-05-21 17:49:06 -07009412 struct lpfc_vector_map_info *cpup;
James Smartcdb42be2019-01-28 11:14:21 -08009413 struct lpfc_sli4_hdw_queue *qp;
James Smart962bc512013-01-03 15:44:00 -05009414 LPFC_MBOXQ_t *mboxq;
James Smart657add42019-05-21 17:49:06 -07009415 int qidx, cpu;
James Smartcb733e32019-01-28 11:14:32 -08009416 uint32_t length, usdelay;
James Smart895427b2017-02-12 13:52:30 -08009417 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05009418
9419 /* Check for dual-ULP support */
9420 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9421 if (!mboxq) {
9422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9423 "3249 Unable to allocate memory for "
9424 "QUERY_FW_CFG mailbox command\n");
9425 return -ENOMEM;
9426 }
9427 length = (sizeof(struct lpfc_mbx_query_fw_config) -
9428 sizeof(struct lpfc_sli4_cfg_mhdr));
9429 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9430 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
9431 length, LPFC_SLI4_MBX_EMBED);
9432
9433 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9434
9435 shdr = (union lpfc_sli4_cfg_shdr *)
9436 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9437 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9438 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9439 if (shdr_status || shdr_add_status || rc) {
9440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9441 "3250 QUERY_FW_CFG mailbox failed with status "
9442 "x%x add_status x%x, mbx status x%x\n",
9443 shdr_status, shdr_add_status, rc);
9444 if (rc != MBX_TIMEOUT)
9445 mempool_free(mboxq, phba->mbox_mem_pool);
9446 rc = -ENXIO;
9447 goto out_error;
9448 }
9449
9450 phba->sli4_hba.fw_func_mode =
9451 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9452 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9453 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04009454 phba->sli4_hba.physical_port =
9455 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05009456 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9457 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9458 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9459 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9460
9461 if (rc != MBX_TIMEOUT)
9462 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04009463
9464 /*
James Smart67d12732012-08-03 12:36:13 -04009465 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04009466 */
James Smartcdb42be2019-01-28 11:14:21 -08009467 qp = phba->sli4_hba.hdwq;
James Smartda0436e2009-05-22 14:51:39 -04009468
James Smart67d12732012-08-03 12:36:13 -04009469 /* Set up HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -08009470 if (!qp) {
James Smart2e90f4b2011-12-13 13:22:37 -05009471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9472 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009473 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009474 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05009475 }
James Smart657add42019-05-21 17:49:06 -07009476
9477 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009478 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009479 /* Create HBA Event Queues (EQs) in order */
9480 for_each_present_cpu(cpu) {
9481 cpup = &phba->sli4_hba.cpu_map[cpu];
9482
9483 /* Look for the CPU thats using that vector with
9484 * LPFC_CPU_FIRST_IRQ set.
9485 */
9486 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
9487 continue;
9488 if (qidx != cpup->eq)
9489 continue;
9490
9491 /* Create an EQ for that vector */
9492 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
9493 phba->cfg_fcp_imax);
9494 if (rc) {
9495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9496 "0523 Failed setup of fast-path"
9497 " EQ (%d), rc = 0x%x\n",
9498 cpup->eq, (uint32_t)rc);
9499 goto out_destroy;
9500 }
9501
9502 /* Save the EQ for that vector in the hba_eq_hdl */
9503 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
9504 qp[cpup->hdwq].hba_eq;
9505
9506 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9507 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9508 cpup->eq,
9509 qp[cpup->hdwq].hba_eq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04009510 }
James Smartda0436e2009-05-22 14:51:39 -04009511 }
9512
James Smart657add42019-05-21 17:49:06 -07009513 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009514 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9515 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009516 cpu = lpfc_find_cpu_handle(phba, qidx,
9517 LPFC_FIND_BY_HDWQ);
9518 cpup = &phba->sli4_hba.cpu_map[cpu];
9519
9520 /* Create the CQ/WQ corresponding to the
9521 * Hardware Queue
9522 */
James Smart895427b2017-02-12 13:52:30 -08009523 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -07009524 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartcdb42be2019-01-28 11:14:21 -08009525 qp[qidx].nvme_cq,
9526 qp[qidx].nvme_wq,
9527 &phba->sli4_hba.hdwq[qidx].nvme_cq_map,
James Smart895427b2017-02-12 13:52:30 -08009528 qidx, LPFC_NVME);
9529 if (rc) {
9530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9531 "6123 Failed to setup fastpath "
9532 "NVME WQ/CQ (%d), rc = 0x%x\n",
9533 qidx, (uint32_t)rc);
9534 goto out_destroy;
9535 }
9536 }
James Smart67d12732012-08-03 12:36:13 -04009537 }
9538
James Smartcdb42be2019-01-28 11:14:21 -08009539 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009540 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
9541 cpup = &phba->sli4_hba.cpu_map[cpu];
9542
9543 /* Create the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009544 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -07009545 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartcdb42be2019-01-28 11:14:21 -08009546 qp[qidx].fcp_cq,
9547 qp[qidx].fcp_wq,
9548 &phba->sli4_hba.hdwq[qidx].fcp_cq_map,
9549 qidx, LPFC_FCP);
9550 if (rc) {
James Smart67d12732012-08-03 12:36:13 -04009551 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009552 "0535 Failed to setup fastpath "
9553 "FCP WQ/CQ (%d), rc = 0x%x\n",
9554 qidx, (uint32_t)rc);
James Smartcdb42be2019-01-28 11:14:21 -08009555 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009556 }
James Smart67d12732012-08-03 12:36:13 -04009557 }
James Smartda0436e2009-05-22 14:51:39 -04009558
9559 /*
James Smart895427b2017-02-12 13:52:30 -08009560 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009561 */
9562
James Smart895427b2017-02-12 13:52:30 -08009563 /* Set up slow-path MBOX CQ/MQ */
9564
9565 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009567 "0528 %s not allocated\n",
9568 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07009569 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05009570 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009571 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009572 }
James Smart895427b2017-02-12 13:52:30 -08009573
James Smartcdb42be2019-01-28 11:14:21 -08009574 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
James Smartd1f525a2017-04-21 16:04:55 -07009575 phba->sli4_hba.mbx_cq,
9576 phba->sli4_hba.mbx_wq,
9577 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04009578 if (rc) {
9579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009580 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9581 (uint32_t)rc);
9582 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009583 }
James Smart2d7dbc42017-02-12 13:52:35 -08009584 if (phba->nvmet_support) {
9585 if (!phba->sli4_hba.nvmet_cqset) {
9586 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9587 "3165 Fast-path NVME CQ Set "
9588 "array not allocated\n");
9589 rc = -ENOMEM;
9590 goto out_destroy;
9591 }
9592 if (phba->cfg_nvmet_mrq > 1) {
9593 rc = lpfc_cq_create_set(phba,
9594 phba->sli4_hba.nvmet_cqset,
James Smartcdb42be2019-01-28 11:14:21 -08009595 qp,
James Smart2d7dbc42017-02-12 13:52:35 -08009596 LPFC_WCQ, LPFC_NVMET);
9597 if (rc) {
9598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9599 "3164 Failed setup of NVME CQ "
9600 "Set, rc = 0x%x\n",
9601 (uint32_t)rc);
9602 goto out_destroy;
9603 }
9604 } else {
9605 /* Set up NVMET Receive Complete Queue */
9606 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
James Smartcdb42be2019-01-28 11:14:21 -08009607 qp[0].hba_eq,
James Smart2d7dbc42017-02-12 13:52:35 -08009608 LPFC_WCQ, LPFC_NVMET);
9609 if (rc) {
9610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9611 "6089 Failed setup NVMET CQ: "
9612 "rc = 0x%x\n", (uint32_t)rc);
9613 goto out_destroy;
9614 }
James Smart81b96ed2017-11-20 16:00:29 -08009615 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9616
James Smart2d7dbc42017-02-12 13:52:35 -08009617 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9618 "6090 NVMET CQ setup: cq-id=%d, "
9619 "parent eq-id=%d\n",
9620 phba->sli4_hba.nvmet_cqset[0]->queue_id,
James Smartcdb42be2019-01-28 11:14:21 -08009621 qp[0].hba_eq->queue_id);
James Smart2d7dbc42017-02-12 13:52:35 -08009622 }
9623 }
James Smartda0436e2009-05-22 14:51:39 -04009624
James Smart895427b2017-02-12 13:52:30 -08009625 /* Set up slow-path ELS WQ/CQ */
9626 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009627 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009628 "0530 ELS %s not allocated\n",
9629 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009630 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009631 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009632 }
James Smartcdb42be2019-01-28 11:14:21 -08009633 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9634 phba->sli4_hba.els_cq,
9635 phba->sli4_hba.els_wq,
9636 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009637 if (rc) {
9638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartcdb42be2019-01-28 11:14:21 -08009639 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9640 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009641 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009642 }
9643 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9644 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9645 phba->sli4_hba.els_wq->queue_id,
9646 phba->sli4_hba.els_cq->queue_id);
9647
James Smartcdb42be2019-01-28 11:14:21 -08009648 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -08009649 /* Set up NVME LS Complete Queue */
9650 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9652 "6091 LS %s not allocated\n",
9653 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9654 rc = -ENOMEM;
9655 goto out_destroy;
9656 }
James Smartcdb42be2019-01-28 11:14:21 -08009657 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9658 phba->sli4_hba.nvmels_cq,
9659 phba->sli4_hba.nvmels_wq,
9660 NULL, 0, LPFC_NVME_LS);
James Smart895427b2017-02-12 13:52:30 -08009661 if (rc) {
9662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartcdb42be2019-01-28 11:14:21 -08009663 "0526 Failed setup of NVVME LS WQ/CQ: "
9664 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009665 goto out_destroy;
9666 }
9667
9668 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9669 "6096 ELS WQ setup: wq-id=%d, "
9670 "parent cq-id=%d\n",
9671 phba->sli4_hba.nvmels_wq->queue_id,
9672 phba->sli4_hba.nvmels_cq->queue_id);
9673 }
9674
James Smart2d7dbc42017-02-12 13:52:35 -08009675 /*
9676 * Create NVMET Receive Queue (RQ)
9677 */
9678 if (phba->nvmet_support) {
9679 if ((!phba->sli4_hba.nvmet_cqset) ||
9680 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9681 (!phba->sli4_hba.nvmet_mrq_data)) {
9682 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9683 "6130 MRQ CQ Queues not "
9684 "allocated\n");
9685 rc = -ENOMEM;
9686 goto out_destroy;
9687 }
9688 if (phba->cfg_nvmet_mrq > 1) {
9689 rc = lpfc_mrq_create(phba,
9690 phba->sli4_hba.nvmet_mrq_hdr,
9691 phba->sli4_hba.nvmet_mrq_data,
9692 phba->sli4_hba.nvmet_cqset,
9693 LPFC_NVMET);
9694 if (rc) {
9695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9696 "6098 Failed setup of NVMET "
9697 "MRQ: rc = 0x%x\n",
9698 (uint32_t)rc);
9699 goto out_destroy;
9700 }
9701
9702 } else {
9703 rc = lpfc_rq_create(phba,
9704 phba->sli4_hba.nvmet_mrq_hdr[0],
9705 phba->sli4_hba.nvmet_mrq_data[0],
9706 phba->sli4_hba.nvmet_cqset[0],
9707 LPFC_NVMET);
9708 if (rc) {
9709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9710 "6057 Failed setup of NVMET "
9711 "Receive Queue: rc = 0x%x\n",
9712 (uint32_t)rc);
9713 goto out_destroy;
9714 }
9715
9716 lpfc_printf_log(
9717 phba, KERN_INFO, LOG_INIT,
9718 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9719 "dat-rq-id=%d parent cq-id=%d\n",
9720 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9721 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9722 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9723
9724 }
9725 }
9726
James Smartda0436e2009-05-22 14:51:39 -04009727 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9729 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009730 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009731 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009732 }
James Smart73d91e52011-10-10 21:32:10 -04009733
James Smartda0436e2009-05-22 14:51:39 -04009734 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009735 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009736 if (rc) {
9737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9738 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009739 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009740 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009741 }
James Smart73d91e52011-10-10 21:32:10 -04009742
James Smartda0436e2009-05-22 14:51:39 -04009743 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9744 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9745 "parent cq-id=%d\n",
9746 phba->sli4_hba.hdr_rq->queue_id,
9747 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009748 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009749
James Smartcb733e32019-01-28 11:14:32 -08009750 if (phba->cfg_fcp_imax)
9751 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
9752 else
9753 usdelay = 0;
9754
James Smart6a828b02019-01-28 11:14:31 -08009755 for (qidx = 0; qidx < phba->cfg_irq_chann;
James Smartcdb42be2019-01-28 11:14:21 -08009756 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009757 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -08009758 usdelay);
James Smart43140ca2017-03-04 09:30:34 -08009759
James Smart6a828b02019-01-28 11:14:31 -08009760 if (phba->sli4_hba.cq_max) {
9761 kfree(phba->sli4_hba.cq_lookup);
9762 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
9763 sizeof(struct lpfc_queue *), GFP_KERNEL);
9764 if (!phba->sli4_hba.cq_lookup) {
James Smart1ba981f2014-02-20 09:56:45 -05009765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -08009766 "0549 Failed setup of CQ Lookup table: "
9767 "size 0x%x\n", phba->sli4_hba.cq_max);
Dan Carpenterfad28e32019-02-11 21:43:00 +03009768 rc = -ENOMEM;
James Smart1ba981f2014-02-20 09:56:45 -05009769 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009770 }
James Smart6a828b02019-01-28 11:14:31 -08009771 lpfc_setup_cq_lookup(phba);
James Smart1ba981f2014-02-20 09:56:45 -05009772 }
James Smartda0436e2009-05-22 14:51:39 -04009773 return 0;
9774
James Smart895427b2017-02-12 13:52:30 -08009775out_destroy:
9776 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009777out_error:
9778 return rc;
9779}
9780
9781/**
9782 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9783 * @phba: pointer to lpfc hba data structure.
9784 *
9785 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9786 * operation.
9787 *
9788 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009789 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009790 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009791 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009792 **/
9793void
9794lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9795{
James Smartcdb42be2019-01-28 11:14:21 -08009796 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07009797 struct lpfc_queue *eq;
James Smart895427b2017-02-12 13:52:30 -08009798 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009799
9800 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009801 if (phba->sli4_hba.mbx_wq)
9802 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9803
9804 /* Unset NVME LS work queue */
9805 if (phba->sli4_hba.nvmels_wq)
9806 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9807
James Smartda0436e2009-05-22 14:51:39 -04009808 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009809 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009810 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9811
James Smartda0436e2009-05-22 14:51:39 -04009812 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009813 if (phba->sli4_hba.hdr_rq)
9814 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9815 phba->sli4_hba.dat_rq);
9816
James Smartda0436e2009-05-22 14:51:39 -04009817 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009818 if (phba->sli4_hba.mbx_cq)
9819 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9820
James Smartda0436e2009-05-22 14:51:39 -04009821 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009822 if (phba->sli4_hba.els_cq)
9823 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9824
9825 /* Unset NVME LS complete queue */
9826 if (phba->sli4_hba.nvmels_cq)
9827 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9828
James Smartbcb24f62017-11-20 16:00:36 -08009829 if (phba->nvmet_support) {
9830 /* Unset NVMET MRQ queue */
9831 if (phba->sli4_hba.nvmet_mrq_hdr) {
9832 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9833 lpfc_rq_destroy(
9834 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009835 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9836 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009837 }
James Smart2d7dbc42017-02-12 13:52:35 -08009838
James Smartbcb24f62017-11-20 16:00:36 -08009839 /* Unset NVMET CQ Set complete queue */
9840 if (phba->sli4_hba.nvmet_cqset) {
9841 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9842 lpfc_cq_destroy(
9843 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9844 }
James Smart2d7dbc42017-02-12 13:52:35 -08009845 }
9846
James Smartcdb42be2019-01-28 11:14:21 -08009847 /* Unset fast-path SLI4 queues */
9848 if (phba->sli4_hba.hdwq) {
James Smart657add42019-05-21 17:49:06 -07009849 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009850 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009851 /* Destroy the CQ/WQ corresponding to Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009852 qp = &phba->sli4_hba.hdwq[qidx];
9853 lpfc_wq_destroy(phba, qp->fcp_wq);
9854 lpfc_wq_destroy(phba, qp->nvme_wq);
9855 lpfc_cq_destroy(phba, qp->fcp_cq);
9856 lpfc_cq_destroy(phba, qp->nvme_cq);
James Smart657add42019-05-21 17:49:06 -07009857 }
9858 /* Loop thru all IRQ vectors */
9859 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
9860 /* Destroy the EQ corresponding to the IRQ vector */
9861 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
9862 lpfc_eq_destroy(phba, eq);
James Smartcdb42be2019-01-28 11:14:21 -08009863 }
9864 }
James Smart895427b2017-02-12 13:52:30 -08009865
James Smart6a828b02019-01-28 11:14:31 -08009866 kfree(phba->sli4_hba.cq_lookup);
9867 phba->sli4_hba.cq_lookup = NULL;
9868 phba->sli4_hba.cq_max = 0;
James Smartda0436e2009-05-22 14:51:39 -04009869}
9870
9871/**
9872 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9873 * @phba: pointer to lpfc hba data structure.
9874 *
9875 * This routine is invoked to allocate and set up a pool of completion queue
9876 * events. The body of the completion queue event is a completion queue entry
9877 * CQE. For now, this pool is used for the interrupt service routine to queue
9878 * the following HBA completion queue events for the worker thread to process:
9879 * - Mailbox asynchronous events
9880 * - Receive queue completion unsolicited events
9881 * Later, this can be used for all the slow-path events.
9882 *
9883 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009884 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009885 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009886 **/
9887static int
9888lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9889{
9890 struct lpfc_cq_event *cq_event;
9891 int i;
9892
9893 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9894 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9895 if (!cq_event)
9896 goto out_pool_create_fail;
9897 list_add_tail(&cq_event->list,
9898 &phba->sli4_hba.sp_cqe_event_pool);
9899 }
9900 return 0;
9901
9902out_pool_create_fail:
9903 lpfc_sli4_cq_event_pool_destroy(phba);
9904 return -ENOMEM;
9905}
9906
9907/**
9908 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9909 * @phba: pointer to lpfc hba data structure.
9910 *
9911 * This routine is invoked to free the pool of completion queue events at
9912 * driver unload time. Note that, it is the responsibility of the driver
9913 * cleanup routine to free all the outstanding completion-queue events
9914 * allocated from this pool back into the pool before invoking this routine
9915 * to destroy the pool.
9916 **/
9917static void
9918lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9919{
9920 struct lpfc_cq_event *cq_event, *next_cq_event;
9921
9922 list_for_each_entry_safe(cq_event, next_cq_event,
9923 &phba->sli4_hba.sp_cqe_event_pool, list) {
9924 list_del(&cq_event->list);
9925 kfree(cq_event);
9926 }
9927}
9928
9929/**
9930 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9931 * @phba: pointer to lpfc hba data structure.
9932 *
9933 * This routine is the lock free version of the API invoked to allocate a
9934 * completion-queue event from the free pool.
9935 *
9936 * Return: Pointer to the newly allocated completion-queue event if successful
9937 * NULL otherwise.
9938 **/
9939struct lpfc_cq_event *
9940__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9941{
9942 struct lpfc_cq_event *cq_event = NULL;
9943
9944 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9945 struct lpfc_cq_event, list);
9946 return cq_event;
9947}
9948
9949/**
9950 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9951 * @phba: pointer to lpfc hba data structure.
9952 *
9953 * This routine is the lock version of the API invoked to allocate a
9954 * completion-queue event from the free pool.
9955 *
9956 * Return: Pointer to the newly allocated completion-queue event if successful
9957 * NULL otherwise.
9958 **/
9959struct lpfc_cq_event *
9960lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9961{
9962 struct lpfc_cq_event *cq_event;
9963 unsigned long iflags;
9964
9965 spin_lock_irqsave(&phba->hbalock, iflags);
9966 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9967 spin_unlock_irqrestore(&phba->hbalock, iflags);
9968 return cq_event;
9969}
9970
9971/**
9972 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9973 * @phba: pointer to lpfc hba data structure.
9974 * @cq_event: pointer to the completion queue event to be freed.
9975 *
9976 * This routine is the lock free version of the API invoked to release a
9977 * completion-queue event back into the free pool.
9978 **/
9979void
9980__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9981 struct lpfc_cq_event *cq_event)
9982{
9983 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9984}
9985
9986/**
9987 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9988 * @phba: pointer to lpfc hba data structure.
9989 * @cq_event: pointer to the completion queue event to be freed.
9990 *
9991 * This routine is the lock version of the API invoked to release a
9992 * completion-queue event back into the free pool.
9993 **/
9994void
9995lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9996 struct lpfc_cq_event *cq_event)
9997{
9998 unsigned long iflags;
9999 spin_lock_irqsave(&phba->hbalock, iflags);
10000 __lpfc_sli4_cq_event_release(phba, cq_event);
10001 spin_unlock_irqrestore(&phba->hbalock, iflags);
10002}
10003
10004/**
10005 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
10006 * @phba: pointer to lpfc hba data structure.
10007 *
10008 * This routine is to free all the pending completion-queue events to the
10009 * back into the free pool for device reset.
10010 **/
10011static void
10012lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
10013{
10014 LIST_HEAD(cqelist);
10015 struct lpfc_cq_event *cqe;
10016 unsigned long iflags;
10017
10018 /* Retrieve all the pending WCQEs from pending WCQE lists */
10019 spin_lock_irqsave(&phba->hbalock, iflags);
10020 /* Pending FCP XRI abort events */
10021 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
10022 &cqelist);
10023 /* Pending ELS XRI abort events */
10024 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10025 &cqelist);
10026 /* Pending asynnc events */
10027 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
10028 &cqelist);
10029 spin_unlock_irqrestore(&phba->hbalock, iflags);
10030
10031 while (!list_empty(&cqelist)) {
10032 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
10033 lpfc_sli4_cq_event_release(phba, cqe);
10034 }
10035}
10036
10037/**
10038 * lpfc_pci_function_reset - Reset pci function.
10039 * @phba: pointer to lpfc hba data structure.
10040 *
10041 * This routine is invoked to request a PCI function reset. It will destroys
10042 * all resources assigned to the PCI function which originates this request.
10043 *
10044 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010045 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010046 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010047 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010048 **/
10049int
10050lpfc_pci_function_reset(struct lpfc_hba *phba)
10051{
10052 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -050010053 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -040010054 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -040010055 uint32_t rdy_chk;
10056 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -040010057 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -050010058 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -050010059 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -040010060
James Smart2fcee4b2010-12-15 17:57:46 -050010061 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10062 switch (if_type) {
10063 case LPFC_SLI_INTF_IF_TYPE_0:
10064 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10065 GFP_KERNEL);
10066 if (!mboxq) {
10067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10068 "0494 Unable to allocate memory for "
10069 "issuing SLI_FUNCTION_RESET mailbox "
10070 "command\n");
10071 return -ENOMEM;
10072 }
10073
10074 /* Setup PCI function reset mailbox-ioctl command */
10075 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10076 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
10077 LPFC_SLI4_MBX_EMBED);
10078 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10079 shdr = (union lpfc_sli4_cfg_shdr *)
10080 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10081 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10082 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
10083 &shdr->response);
10084 if (rc != MBX_TIMEOUT)
10085 mempool_free(mboxq, phba->mbox_mem_pool);
10086 if (shdr_status || shdr_add_status || rc) {
10087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10088 "0495 SLI_FUNCTION_RESET mailbox "
10089 "failed with status x%x add_status x%x,"
10090 " mbx status x%x\n",
10091 shdr_status, shdr_add_status, rc);
10092 rc = -ENXIO;
10093 }
10094 break;
10095 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -080010096 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -040010097wait:
10098 /*
10099 * Poll the Port Status Register and wait for RDY for
10100 * up to 30 seconds. If the port doesn't respond, treat
10101 * it as an error.
10102 */
James Smart77d093f2015-04-07 15:07:08 -040010103 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -040010104 if (lpfc_readl(phba->sli4_hba.u.if_type2.
10105 STATUSregaddr, &reg_data.word0)) {
10106 rc = -ENODEV;
10107 goto out;
10108 }
10109 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
10110 break;
10111 msleep(20);
10112 }
10113
10114 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
10115 phba->work_status[0] = readl(
10116 phba->sli4_hba.u.if_type2.ERR1regaddr);
10117 phba->work_status[1] = readl(
10118 phba->sli4_hba.u.if_type2.ERR2regaddr);
10119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10120 "2890 Port not ready, port status reg "
10121 "0x%x error 1=0x%x, error 2=0x%x\n",
10122 reg_data.word0,
10123 phba->work_status[0],
10124 phba->work_status[1]);
10125 rc = -ENODEV;
10126 goto out;
10127 }
10128
10129 if (!port_reset) {
10130 /*
10131 * Reset the port now
10132 */
James Smart2fcee4b2010-12-15 17:57:46 -050010133 reg_data.word0 = 0;
10134 bf_set(lpfc_sliport_ctrl_end, &reg_data,
10135 LPFC_SLIPORT_LITTLE_ENDIAN);
10136 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
10137 LPFC_SLIPORT_INIT_PORT);
10138 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
10139 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -050010140 /* flush */
James Smart2b81f942012-03-01 22:37:18 -050010141 pci_read_config_word(phba->pcidev,
10142 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -050010143
James Smart2f6fa2c2014-09-03 12:57:08 -040010144 port_reset = 1;
10145 msleep(20);
10146 goto wait;
10147 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
10148 rc = -ENODEV;
10149 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -050010150 }
10151 break;
James Smart2f6fa2c2014-09-03 12:57:08 -040010152
James Smart2fcee4b2010-12-15 17:57:46 -050010153 case LPFC_SLI_INTF_IF_TYPE_1:
10154 default:
10155 break;
James Smartda0436e2009-05-22 14:51:39 -040010156 }
10157
James Smart73d91e52011-10-10 21:32:10 -040010158out:
James Smart2fcee4b2010-12-15 17:57:46 -050010159 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -040010160 if (rc) {
James Smart229adb02013-04-17 20:16:51 -040010161 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10162 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -040010163 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -050010164 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -040010165 }
James Smart2fcee4b2010-12-15 17:57:46 -050010166
James Smartda0436e2009-05-22 14:51:39 -040010167 return rc;
10168}
10169
10170/**
James Smartda0436e2009-05-22 14:51:39 -040010171 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
10172 * @phba: pointer to lpfc hba data structure.
10173 *
10174 * This routine is invoked to set up the PCI device memory space for device
10175 * with SLI-4 interface spec.
10176 *
10177 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010178 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010179 * other values - error
10180 **/
10181static int
10182lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10183{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010184 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010185 unsigned long bar0map_len, bar1map_len, bar2map_len;
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010186 int error;
James Smart2fcee4b2010-12-15 17:57:46 -050010187 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -040010188
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010189 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +010010190 return -ENODEV;
James Smartda0436e2009-05-22 14:51:39 -040010191
10192 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +010010193 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
10194 if (error)
10195 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10196 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010197 return error;
James Smartda0436e2009-05-22 14:51:39 -040010198
James Smart2fcee4b2010-12-15 17:57:46 -050010199 /*
10200 * The BARs and register set definitions and offset locations are
10201 * dependent on the if_type.
10202 */
10203 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
10204 &phba->sli4_hba.sli_intf.word0)) {
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010205 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010206 }
10207
10208 /* There is no SLI3 failback for SLI4 devices. */
10209 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
10210 LPFC_SLI_INTF_VALID) {
10211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10212 "2894 SLI_INTF reg contents invalid "
10213 "sli_intf reg 0x%x\n",
10214 phba->sli4_hba.sli_intf.word0);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010215 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010216 }
10217
10218 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10219 /*
10220 * Get the bus address of SLI4 device Bar regions and the
10221 * number of bytes required by each mapping. The mapping of the
10222 * particular PCI BARs regions is dependent on the type of
10223 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -040010224 */
James Smartf5ca6f22013-09-06 12:21:09 -040010225 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
10226 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
10227 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -050010228
10229 /*
10230 * Map SLI4 PCI Config Space Register base to a kernel virtual
10231 * addr
10232 */
10233 phba->sli4_hba.conf_regs_memmap_p =
10234 ioremap(phba->pci_bar0_map, bar0map_len);
10235 if (!phba->sli4_hba.conf_regs_memmap_p) {
10236 dev_printk(KERN_ERR, &pdev->dev,
10237 "ioremap failed for SLI4 PCI config "
10238 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010239 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010240 }
James Smartf5ca6f22013-09-06 12:21:09 -040010241 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -050010242 /* Set up BAR0 PCI config space register memory map */
10243 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -050010244 } else {
10245 phba->pci_bar0_map = pci_resource_start(pdev, 1);
10246 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -080010247 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -050010248 dev_printk(KERN_ERR, &pdev->dev,
10249 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010250 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010251 }
10252 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -040010253 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -050010254 if (!phba->sli4_hba.conf_regs_memmap_p) {
10255 dev_printk(KERN_ERR, &pdev->dev,
10256 "ioremap failed for SLI4 PCI config "
10257 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010258 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010259 }
10260 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -040010261 }
10262
James Smarte4b97942017-11-20 16:00:31 -080010263 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10264 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
10265 /*
10266 * Map SLI4 if type 0 HBA Control Register base to a
10267 * kernel virtual address and setup the registers.
10268 */
10269 phba->pci_bar1_map = pci_resource_start(pdev,
10270 PCI_64BIT_BAR2);
10271 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10272 phba->sli4_hba.ctrl_regs_memmap_p =
10273 ioremap(phba->pci_bar1_map,
10274 bar1map_len);
10275 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
10276 dev_err(&pdev->dev,
10277 "ioremap failed for SLI4 HBA "
10278 "control registers.\n");
10279 error = -ENOMEM;
10280 goto out_iounmap_conf;
10281 }
10282 phba->pci_bar2_memmap_p =
10283 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -080010284 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -080010285 } else {
10286 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010287 goto out_iounmap_conf;
10288 }
James Smartda0436e2009-05-22 14:51:39 -040010289 }
10290
James Smart27d6ac02018-02-22 08:18:42 -080010291 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
10292 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
10293 /*
10294 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
10295 * virtual address and setup the registers.
10296 */
10297 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
10298 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10299 phba->sli4_hba.drbl_regs_memmap_p =
10300 ioremap(phba->pci_bar1_map, bar1map_len);
10301 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10302 dev_err(&pdev->dev,
10303 "ioremap failed for SLI4 HBA doorbell registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010304 error = -ENOMEM;
James Smart27d6ac02018-02-22 08:18:42 -080010305 goto out_iounmap_conf;
10306 }
10307 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
10308 lpfc_sli4_bar1_register_memmap(phba, if_type);
10309 }
10310
James Smarte4b97942017-11-20 16:00:31 -080010311 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10312 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10313 /*
10314 * Map SLI4 if type 0 HBA Doorbell Register base to
10315 * a kernel virtual address and setup the registers.
10316 */
10317 phba->pci_bar2_map = pci_resource_start(pdev,
10318 PCI_64BIT_BAR4);
10319 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10320 phba->sli4_hba.drbl_regs_memmap_p =
10321 ioremap(phba->pci_bar2_map,
10322 bar2map_len);
10323 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10324 dev_err(&pdev->dev,
10325 "ioremap failed for SLI4 HBA"
10326 " doorbell registers.\n");
10327 error = -ENOMEM;
10328 goto out_iounmap_ctrl;
10329 }
10330 phba->pci_bar4_memmap_p =
10331 phba->sli4_hba.drbl_regs_memmap_p;
10332 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
10333 if (error)
10334 goto out_iounmap_all;
10335 } else {
10336 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010337 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -080010338 }
James Smartda0436e2009-05-22 14:51:39 -040010339 }
10340
James Smart1351e692018-02-22 08:18:43 -080010341 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
10342 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10343 /*
10344 * Map SLI4 if type 6 HBA DPP Register base to a kernel
10345 * virtual address and setup the registers.
10346 */
10347 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
10348 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10349 phba->sli4_hba.dpp_regs_memmap_p =
10350 ioremap(phba->pci_bar2_map, bar2map_len);
10351 if (!phba->sli4_hba.dpp_regs_memmap_p) {
10352 dev_err(&pdev->dev,
10353 "ioremap failed for SLI4 HBA dpp registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010354 error = -ENOMEM;
James Smart1351e692018-02-22 08:18:43 -080010355 goto out_iounmap_ctrl;
10356 }
10357 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
10358 }
10359
James Smartb71413d2018-02-22 08:18:40 -080010360 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -080010361 switch (if_type) {
10362 case LPFC_SLI_INTF_IF_TYPE_0:
10363 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -080010364 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010365 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
10366 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010367 break;
10368 case LPFC_SLI_INTF_IF_TYPE_6:
10369 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010370 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
10371 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010372 break;
10373 default:
10374 break;
James Smartb71413d2018-02-22 08:18:40 -080010375 }
10376
James Smartda0436e2009-05-22 14:51:39 -040010377 return 0;
10378
10379out_iounmap_all:
10380 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10381out_iounmap_ctrl:
10382 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10383out_iounmap_conf:
10384 iounmap(phba->sli4_hba.conf_regs_memmap_p);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010385
James Smartda0436e2009-05-22 14:51:39 -040010386 return error;
10387}
10388
10389/**
10390 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
10391 * @phba: pointer to lpfc hba data structure.
10392 *
10393 * This routine is invoked to unset the PCI device memory space for device
10394 * with SLI-4 interface spec.
10395 **/
10396static void
10397lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
10398{
James Smart2e90f4b2011-12-13 13:22:37 -050010399 uint32_t if_type;
10400 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -040010401
James Smart2e90f4b2011-12-13 13:22:37 -050010402 switch (if_type) {
10403 case LPFC_SLI_INTF_IF_TYPE_0:
10404 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10405 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10406 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10407 break;
10408 case LPFC_SLI_INTF_IF_TYPE_2:
10409 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10410 break;
James Smart27d6ac02018-02-22 08:18:42 -080010411 case LPFC_SLI_INTF_IF_TYPE_6:
10412 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10413 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10414 break;
James Smart2e90f4b2011-12-13 13:22:37 -050010415 case LPFC_SLI_INTF_IF_TYPE_1:
10416 default:
10417 dev_printk(KERN_ERR, &phba->pcidev->dev,
10418 "FATAL - unsupported SLI4 interface type - %d\n",
10419 if_type);
10420 break;
10421 }
James Smartda0436e2009-05-22 14:51:39 -040010422}
10423
10424/**
James Smart3772a992009-05-22 14:50:54 -040010425 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
10426 * @phba: pointer to lpfc hba data structure.
10427 *
10428 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010429 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -040010430 *
10431 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010432 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010433 * other values - error
10434 **/
10435static int
10436lpfc_sli_enable_msix(struct lpfc_hba *phba)
10437{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010438 int rc;
James Smart3772a992009-05-22 14:50:54 -040010439 LPFC_MBOXQ_t *pmb;
10440
10441 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010442 rc = pci_alloc_irq_vectors(phba->pcidev,
10443 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
10444 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -040010445 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10446 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010447 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -040010448 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010449
James Smart3772a992009-05-22 14:50:54 -040010450 /*
10451 * Assign MSI-X vectors to interrupt handlers
10452 */
10453
10454 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010455 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040010456 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010457 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10458 if (rc) {
10459 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10460 "0421 MSI-X slow-path request_irq failed "
10461 "(%d)\n", rc);
10462 goto msi_fail_out;
10463 }
10464
10465 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010466 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040010467 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010468 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10469
10470 if (rc) {
10471 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10472 "0429 MSI-X fast-path request_irq failed "
10473 "(%d)\n", rc);
10474 goto irq_fail_out;
10475 }
10476
10477 /*
10478 * Configure HBA MSI-X attention conditions to messages
10479 */
10480 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10481
10482 if (!pmb) {
10483 rc = -ENOMEM;
10484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10485 "0474 Unable to allocate memory for issuing "
10486 "MBOX_CONFIG_MSI command\n");
10487 goto mem_fail_out;
10488 }
10489 rc = lpfc_config_msi(phba, pmb);
10490 if (rc)
10491 goto mbx_fail_out;
10492 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10493 if (rc != MBX_SUCCESS) {
10494 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10495 "0351 Config MSI mailbox command failed, "
10496 "mbxCmd x%x, mbxStatus x%x\n",
10497 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10498 goto mbx_fail_out;
10499 }
10500
10501 /* Free memory allocated for mailbox command */
10502 mempool_free(pmb, phba->mbox_mem_pool);
10503 return rc;
10504
10505mbx_fail_out:
10506 /* Free memory allocated for mailbox command */
10507 mempool_free(pmb, phba->mbox_mem_pool);
10508
10509mem_fail_out:
10510 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010511 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040010512
10513irq_fail_out:
10514 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010515 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040010516
10517msi_fail_out:
10518 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010519 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010520
10521vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040010522 return rc;
10523}
10524
10525/**
James Smart3772a992009-05-22 14:50:54 -040010526 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10527 * @phba: pointer to lpfc hba data structure.
10528 *
10529 * This routine is invoked to enable the MSI interrupt mode to device with
10530 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10531 * enable the MSI vector. The device driver is responsible for calling the
10532 * request_irq() to register MSI vector with a interrupt the handler, which
10533 * is done in this function.
10534 *
10535 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010536 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010537 * other values - error
10538 */
10539static int
10540lpfc_sli_enable_msi(struct lpfc_hba *phba)
10541{
10542 int rc;
10543
10544 rc = pci_enable_msi(phba->pcidev);
10545 if (!rc)
10546 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10547 "0462 PCI enable MSI mode success.\n");
10548 else {
10549 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10550 "0471 PCI enable MSI mode failed (%d)\n", rc);
10551 return rc;
10552 }
10553
10554 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010555 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040010556 if (rc) {
10557 pci_disable_msi(phba->pcidev);
10558 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10559 "0478 MSI request_irq failed (%d)\n", rc);
10560 }
10561 return rc;
10562}
10563
10564/**
James Smart3772a992009-05-22 14:50:54 -040010565 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10566 * @phba: pointer to lpfc hba data structure.
10567 *
10568 * This routine is invoked to enable device interrupt and associate driver's
10569 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10570 * spec. Depends on the interrupt mode configured to the driver, the driver
10571 * will try to fallback from the configured interrupt mode to an interrupt
10572 * mode which is supported by the platform, kernel, and device in the order
10573 * of:
10574 * MSI-X -> MSI -> IRQ.
10575 *
10576 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010577 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010578 * other values - error
10579 **/
10580static uint32_t
10581lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10582{
10583 uint32_t intr_mode = LPFC_INTR_ERROR;
10584 int retval;
10585
10586 if (cfg_mode == 2) {
10587 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10588 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10589 if (!retval) {
10590 /* Now, try to enable MSI-X interrupt mode */
10591 retval = lpfc_sli_enable_msix(phba);
10592 if (!retval) {
10593 /* Indicate initialization to MSI-X mode */
10594 phba->intr_type = MSIX;
10595 intr_mode = 2;
10596 }
10597 }
10598 }
10599
10600 /* Fallback to MSI if MSI-X initialization failed */
10601 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10602 retval = lpfc_sli_enable_msi(phba);
10603 if (!retval) {
10604 /* Indicate initialization to MSI mode */
10605 phba->intr_type = MSI;
10606 intr_mode = 1;
10607 }
10608 }
10609
10610 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10611 if (phba->intr_type == NONE) {
10612 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10613 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10614 if (!retval) {
10615 /* Indicate initialization to INTx mode */
10616 phba->intr_type = INTx;
10617 intr_mode = 0;
10618 }
10619 }
10620 return intr_mode;
10621}
10622
10623/**
10624 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10625 * @phba: pointer to lpfc hba data structure.
10626 *
10627 * This routine is invoked to disable device interrupt and disassociate the
10628 * driver's interrupt handler(s) from interrupt vector(s) to device with
10629 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10630 * release the interrupt vector(s) for the message signaled interrupt.
10631 **/
10632static void
10633lpfc_sli_disable_intr(struct lpfc_hba *phba)
10634{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010635 int nr_irqs, i;
10636
James Smart3772a992009-05-22 14:50:54 -040010637 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010638 nr_irqs = LPFC_MSIX_VECTORS;
10639 else
10640 nr_irqs = 1;
10641
10642 for (i = 0; i < nr_irqs; i++)
10643 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10644 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010645
10646 /* Reset interrupt management states */
10647 phba->intr_type = NONE;
10648 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010649}
10650
10651/**
James Smart657add42019-05-21 17:49:06 -070010652 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
James Smart6a828b02019-01-28 11:14:31 -080010653 * @phba: pointer to lpfc hba data structure.
10654 * @id: EQ vector index or Hardware Queue index
10655 * @match: LPFC_FIND_BY_EQ = match by EQ
10656 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
James Smart657add42019-05-21 17:49:06 -070010657 * Return the CPU that matches the selection criteria
James Smart6a828b02019-01-28 11:14:31 -080010658 */
10659static uint16_t
10660lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
10661{
10662 struct lpfc_vector_map_info *cpup;
10663 int cpu;
10664
James Smart657add42019-05-21 17:49:06 -070010665 /* Loop through all CPUs */
James Smart222e9232019-01-28 11:14:35 -080010666 for_each_present_cpu(cpu) {
10667 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070010668
10669 /* If we are matching by EQ, there may be multiple CPUs using
10670 * using the same vector, so select the one with
10671 * LPFC_CPU_FIRST_IRQ set.
10672 */
James Smart6a828b02019-01-28 11:14:31 -080010673 if ((match == LPFC_FIND_BY_EQ) &&
James Smart657add42019-05-21 17:49:06 -070010674 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
James Smart6a828b02019-01-28 11:14:31 -080010675 (cpup->irq != LPFC_VECTOR_MAP_EMPTY) &&
10676 (cpup->eq == id))
10677 return cpu;
James Smart657add42019-05-21 17:49:06 -070010678
10679 /* If matching by HDWQ, select the first CPU that matches */
James Smart6a828b02019-01-28 11:14:31 -080010680 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
10681 return cpu;
James Smart6a828b02019-01-28 11:14:31 -080010682 }
10683 return 0;
10684}
10685
James Smart6a828b02019-01-28 11:14:31 -080010686#ifdef CONFIG_X86
10687/**
10688 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
10689 * @phba: pointer to lpfc hba data structure.
10690 * @cpu: CPU map index
10691 * @phys_id: CPU package physical id
10692 * @core_id: CPU core id
10693 */
10694static int
10695lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
10696 uint16_t phys_id, uint16_t core_id)
10697{
10698 struct lpfc_vector_map_info *cpup;
10699 int idx;
10700
James Smart222e9232019-01-28 11:14:35 -080010701 for_each_present_cpu(idx) {
10702 cpup = &phba->sli4_hba.cpu_map[idx];
James Smart6a828b02019-01-28 11:14:31 -080010703 /* Does the cpup match the one we are looking for */
10704 if ((cpup->phys_id == phys_id) &&
10705 (cpup->core_id == core_id) &&
James Smart222e9232019-01-28 11:14:35 -080010706 (cpu != idx))
James Smart6a828b02019-01-28 11:14:31 -080010707 return 1;
James Smart6a828b02019-01-28 11:14:31 -080010708 }
10709 return 0;
10710}
10711#endif
10712
10713/**
James Smart895427b2017-02-12 13:52:30 -080010714 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010715 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010716 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010717 *
James Smart895427b2017-02-12 13:52:30 -080010718 * The routine will figure out the CPU affinity assignment for every
James Smart6a828b02019-01-28 11:14:31 -080010719 * MSI-X vector allocated for the HBA.
James Smart895427b2017-02-12 13:52:30 -080010720 * In addition, the CPU to IO channel mapping will be calculated
10721 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010722 */
James Smart895427b2017-02-12 13:52:30 -080010723static void
10724lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010725{
James Smartd9954a22019-05-21 17:49:05 -070010726 int i, cpu, idx, new_cpu, start_cpu, first_cpu;
James Smart6a828b02019-01-28 11:14:31 -080010727 int max_phys_id, min_phys_id;
10728 int max_core_id, min_core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010729 struct lpfc_vector_map_info *cpup;
James Smartd9954a22019-05-21 17:49:05 -070010730 struct lpfc_vector_map_info *new_cpup;
James Smart75508a82019-01-28 11:14:34 -080010731 const struct cpumask *maskp;
James Smart7bb03bb2013-04-17 20:19:16 -040010732#ifdef CONFIG_X86
10733 struct cpuinfo_x86 *cpuinfo;
10734#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010735
10736 /* Init cpu_map array */
James Smartd9954a22019-05-21 17:49:05 -070010737 for_each_possible_cpu(cpu) {
10738 cpup = &phba->sli4_hba.cpu_map[cpu];
10739 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
10740 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
10741 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
10742 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
10743 cpup->irq = LPFC_VECTOR_MAP_EMPTY;
10744 cpup->flag = 0;
10745 }
James Smart7bb03bb2013-04-17 20:19:16 -040010746
James Smart6a828b02019-01-28 11:14:31 -080010747 max_phys_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010748 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
James Smart6a828b02019-01-28 11:14:31 -080010749 max_core_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010750 min_core_id = LPFC_VECTOR_MAP_EMPTY;
James Smart7bb03bb2013-04-17 20:19:16 -040010751
10752 /* Update CPU map with physical id and core id of each CPU */
James Smart222e9232019-01-28 11:14:35 -080010753 for_each_present_cpu(cpu) {
10754 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart7bb03bb2013-04-17 20:19:16 -040010755#ifdef CONFIG_X86
10756 cpuinfo = &cpu_data(cpu);
10757 cpup->phys_id = cpuinfo->phys_proc_id;
10758 cpup->core_id = cpuinfo->cpu_core_id;
James Smartd9954a22019-05-21 17:49:05 -070010759 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
10760 cpup->flag |= LPFC_CPU_MAP_HYPER;
James Smart7bb03bb2013-04-17 20:19:16 -040010761#else
10762 /* No distinction between CPUs for other platforms */
10763 cpup->phys_id = 0;
James Smart6a828b02019-01-28 11:14:31 -080010764 cpup->core_id = cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010765#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010766
James Smartb3295c22019-01-28 11:14:30 -080010767 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10768 "3328 CPU physid %d coreid %d\n",
10769 cpup->phys_id, cpup->core_id);
James Smart6a828b02019-01-28 11:14:31 -080010770
10771 if (cpup->phys_id > max_phys_id)
10772 max_phys_id = cpup->phys_id;
10773 if (cpup->phys_id < min_phys_id)
10774 min_phys_id = cpup->phys_id;
10775
10776 if (cpup->core_id > max_core_id)
10777 max_core_id = cpup->core_id;
10778 if (cpup->core_id < min_core_id)
10779 min_core_id = cpup->core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010780 }
James Smartb3295c22019-01-28 11:14:30 -080010781
James Smart32517fc2019-01-28 11:14:33 -080010782 for_each_possible_cpu(i) {
10783 struct lpfc_eq_intr_info *eqi =
10784 per_cpu_ptr(phba->sli4_hba.eq_info, i);
10785
10786 INIT_LIST_HEAD(&eqi->list);
10787 eqi->icnt = 0;
10788 }
10789
James Smartd9954a22019-05-21 17:49:05 -070010790 /* This loop sets up all CPUs that are affinitized with a
10791 * irq vector assigned to the driver. All affinitized CPUs
James Smart657add42019-05-21 17:49:06 -070010792 * will get a link to that vectors IRQ and EQ.
James Smartd9954a22019-05-21 17:49:05 -070010793 */
James Smart75508a82019-01-28 11:14:34 -080010794 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smart657add42019-05-21 17:49:06 -070010795 /* Get a CPU mask for all CPUs affinitized to this vector */
James Smart75508a82019-01-28 11:14:34 -080010796 maskp = pci_irq_get_affinity(phba->pcidev, idx);
10797 if (!maskp)
10798 continue;
10799
James Smart657add42019-05-21 17:49:06 -070010800 i = 0;
10801 /* Loop through all CPUs associated with vector idx */
James Smart75508a82019-01-28 11:14:34 -080010802 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
James Smart657add42019-05-21 17:49:06 -070010803 /* Set the EQ index and IRQ for that vector */
James Smart75508a82019-01-28 11:14:34 -080010804 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart6a828b02019-01-28 11:14:31 -080010805 cpup->eq = idx;
James Smart6a828b02019-01-28 11:14:31 -080010806 cpup->irq = pci_irq_vector(phba->pcidev, idx);
James Smartb3295c22019-01-28 11:14:30 -080010807
James Smart657add42019-05-21 17:49:06 -070010808 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -080010809 "3336 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010810 "irq %d eq %d\n",
10811 cpu, cpup->irq, cpup->eq);
10812
10813 /* If this is the first CPU thats assigned to this
10814 * vector, set LPFC_CPU_FIRST_IRQ.
10815 */
10816 if (!i)
10817 cpup->flag |= LPFC_CPU_FIRST_IRQ;
10818 i++;
James Smart6a828b02019-01-28 11:14:31 -080010819 }
James Smartb3295c22019-01-28 11:14:30 -080010820 }
James Smartd9954a22019-05-21 17:49:05 -070010821
10822 /* After looking at each irq vector assigned to this pcidev, its
10823 * possible to see that not ALL CPUs have been accounted for.
James Smart657add42019-05-21 17:49:06 -070010824 * Next we will set any unassigned (unaffinitized) cpu map
10825 * entries to a IRQ on the same phys_id.
James Smartd9954a22019-05-21 17:49:05 -070010826 */
10827 first_cpu = cpumask_first(cpu_present_mask);
10828 start_cpu = first_cpu;
10829
10830 for_each_present_cpu(cpu) {
10831 cpup = &phba->sli4_hba.cpu_map[cpu];
10832
10833 /* Is this CPU entry unassigned */
10834 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10835 /* Mark CPU as IRQ not assigned by the kernel */
10836 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10837
James Smart657add42019-05-21 17:49:06 -070010838 /* If so, find a new_cpup thats on the the SAME
James Smartd9954a22019-05-21 17:49:05 -070010839 * phys_id as cpup. start_cpu will start where we
10840 * left off so all unassigned entries don't get assgined
10841 * the IRQ of the first entry.
10842 */
10843 new_cpu = start_cpu;
10844 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10845 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10846 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10847 (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY) &&
10848 (new_cpup->phys_id == cpup->phys_id))
10849 goto found_same;
10850 new_cpu = cpumask_next(
10851 new_cpu, cpu_present_mask);
10852 if (new_cpu == nr_cpumask_bits)
10853 new_cpu = first_cpu;
10854 }
10855 /* At this point, we leave the CPU as unassigned */
10856 continue;
10857found_same:
10858 /* We found a matching phys_id, so copy the IRQ info */
10859 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070010860 cpup->irq = new_cpup->irq;
10861
10862 /* Bump start_cpu to the next slot to minmize the
10863 * chance of having multiple unassigned CPU entries
10864 * selecting the same IRQ.
10865 */
10866 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10867 if (start_cpu == nr_cpumask_bits)
10868 start_cpu = first_cpu;
10869
James Smart657add42019-05-21 17:49:06 -070010870 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070010871 "3337 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010872 "irq %d from id %d same "
James Smartd9954a22019-05-21 17:49:05 -070010873 "phys_id (%d)\n",
James Smart657add42019-05-21 17:49:06 -070010874 cpu, cpup->irq, new_cpu, cpup->phys_id);
James Smartd9954a22019-05-21 17:49:05 -070010875 }
10876 }
10877
10878 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
10879 start_cpu = first_cpu;
10880
10881 for_each_present_cpu(cpu) {
10882 cpup = &phba->sli4_hba.cpu_map[cpu];
10883
10884 /* Is this entry unassigned */
10885 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10886 /* Mark it as IRQ not assigned by the kernel */
10887 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10888
James Smart657add42019-05-21 17:49:06 -070010889 /* If so, find a new_cpup thats on ANY phys_id
James Smartd9954a22019-05-21 17:49:05 -070010890 * as the cpup. start_cpu will start where we
10891 * left off so all unassigned entries don't get
10892 * assigned the IRQ of the first entry.
10893 */
10894 new_cpu = start_cpu;
10895 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10896 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10897 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10898 (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY))
10899 goto found_any;
10900 new_cpu = cpumask_next(
10901 new_cpu, cpu_present_mask);
10902 if (new_cpu == nr_cpumask_bits)
10903 new_cpu = first_cpu;
10904 }
10905 /* We should never leave an entry unassigned */
10906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10907 "3339 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010908 "irq %d UNASSIGNED\n",
10909 cpup->hdwq, cpup->irq);
James Smartd9954a22019-05-21 17:49:05 -070010910 continue;
10911found_any:
10912 /* We found an available entry, copy the IRQ info */
10913 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070010914 cpup->irq = new_cpup->irq;
10915
10916 /* Bump start_cpu to the next slot to minmize the
10917 * chance of having multiple unassigned CPU entries
10918 * selecting the same IRQ.
10919 */
10920 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10921 if (start_cpu == nr_cpumask_bits)
10922 start_cpu = first_cpu;
10923
James Smart657add42019-05-21 17:49:06 -070010924 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070010925 "3338 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010926 "irq %d from id %d (%d/%d)\n",
10927 cpu, cpup->irq, new_cpu,
James Smartd9954a22019-05-21 17:49:05 -070010928 new_cpup->phys_id, new_cpup->core_id);
10929 }
10930 }
James Smart657add42019-05-21 17:49:06 -070010931
10932 /* Finally we need to associate a hdwq with each cpu_map entry
10933 * This will be 1 to 1 - hdwq to cpu, unless there are less
10934 * hardware queues then CPUs. For that case we will just round-robin
10935 * the available hardware queues as they get assigned to CPUs.
10936 */
10937 idx = 0;
10938 start_cpu = 0;
10939 for_each_present_cpu(cpu) {
10940 cpup = &phba->sli4_hba.cpu_map[cpu];
10941 if (idx >= phba->cfg_hdw_queue) {
10942 /* We need to reuse a Hardware Queue for another CPU,
10943 * so be smart about it and pick one that has its
10944 * IRQ/EQ mapped to the same phys_id (CPU package).
10945 * and core_id.
10946 */
10947 new_cpu = start_cpu;
10948 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10949 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10950 if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) &&
10951 (new_cpup->phys_id == cpup->phys_id) &&
10952 (new_cpup->core_id == cpup->core_id))
10953 goto found_hdwq;
10954 new_cpu = cpumask_next(
10955 new_cpu, cpu_present_mask);
10956 if (new_cpu == nr_cpumask_bits)
10957 new_cpu = first_cpu;
10958 }
10959
10960 /* If we can't match both phys_id and core_id,
10961 * settle for just a phys_id match.
10962 */
10963 new_cpu = start_cpu;
10964 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10965 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10966 if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) &&
10967 (new_cpup->phys_id == cpup->phys_id))
10968 goto found_hdwq;
10969 new_cpu = cpumask_next(
10970 new_cpu, cpu_present_mask);
10971 if (new_cpu == nr_cpumask_bits)
10972 new_cpu = first_cpu;
10973 }
10974
10975 /* Otherwise just round robin on cfg_hdw_queue */
10976 cpup->hdwq = idx % phba->cfg_hdw_queue;
10977 goto logit;
10978found_hdwq:
10979 /* We found an available entry, copy the IRQ info */
10980 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10981 if (start_cpu == nr_cpumask_bits)
10982 start_cpu = first_cpu;
10983 cpup->hdwq = new_cpup->hdwq;
10984 } else {
10985 /* 1 to 1, CPU to hdwq */
10986 cpup->hdwq = idx;
10987 }
10988logit:
10989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10990 "3335 Set Affinity: CPU %d (phys %d core %d): "
10991 "hdwq %d eq %d irq %d flg x%x\n",
10992 cpu, cpup->phys_id, cpup->core_id,
10993 cpup->hdwq, cpup->eq, cpup->irq, cpup->flag);
10994 idx++;
10995 }
10996
10997 /* The cpu_map array will be used later during initialization
10998 * when EQ / CQ / WQs are allocated and configured.
10999 */
James Smartb3295c22019-01-28 11:14:30 -080011000 return;
James Smart7bb03bb2013-04-17 20:19:16 -040011001}
James Smart7bb03bb2013-04-17 20:19:16 -040011002
11003/**
James Smartda0436e2009-05-22 14:51:39 -040011004 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
11005 * @phba: pointer to lpfc hba data structure.
11006 *
11007 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011008 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040011009 *
11010 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011011 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011012 * other values - error
11013 **/
11014static int
11015lpfc_sli4_enable_msix(struct lpfc_hba *phba)
11016{
James Smart75baf692010-06-08 18:31:21 -040011017 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070011018 char *name;
James Smartda0436e2009-05-22 14:51:39 -040011019
11020 /* Set up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011021 vectors = phba->cfg_irq_chann;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011022
James Smartf358dd02017-02-12 13:52:34 -080011023 rc = pci_alloc_irq_vectors(phba->pcidev,
James Smart75508a82019-01-28 11:14:34 -080011024 1,
James Smartf358dd02017-02-12 13:52:34 -080011025 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011026 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040011027 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11028 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011029 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040011030 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011031 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040011032
James Smart7bb03bb2013-04-17 20:19:16 -040011033 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040011034 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070011035 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
11036 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
11037 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040011038 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040011039
James Smart895427b2017-02-12 13:52:30 -080011040 phba->sli4_hba.hba_eq_hdl[index].idx = index;
11041 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart7370d102019-01-28 11:14:20 -080011042 rc = request_irq(pci_irq_vector(phba->pcidev, index),
11043 &lpfc_sli4_hba_intr_handler, 0,
11044 name,
11045 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040011046 if (rc) {
11047 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11048 "0486 MSI-X fast-path (%d) "
11049 "request_irq failed (%d)\n", index, rc);
11050 goto cfg_fail_out;
11051 }
11052 }
11053
James Smart6a828b02019-01-28 11:14:31 -080011054 if (vectors != phba->cfg_irq_chann) {
James Smart82c3e9b2012-09-29 11:29:50 -040011055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11056 "3238 Reducing IO channels to match number of "
11057 "MSI-X vectors, requested %d got %d\n",
James Smart6a828b02019-01-28 11:14:31 -080011058 phba->cfg_irq_chann, vectors);
11059 if (phba->cfg_irq_chann > vectors)
11060 phba->cfg_irq_chann = vectors;
James Smart982ab122019-03-12 16:30:10 -070011061 if (phba->nvmet_support && (phba->cfg_nvmet_mrq > vectors))
James Smartcdb42be2019-01-28 11:14:21 -080011062 phba->cfg_nvmet_mrq = vectors;
James Smart82c3e9b2012-09-29 11:29:50 -040011063 }
James Smart7bb03bb2013-04-17 20:19:16 -040011064
James Smartda0436e2009-05-22 14:51:39 -040011065 return rc;
11066
11067cfg_fail_out:
11068 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080011069 for (--index; index >= 0; index--)
11070 free_irq(pci_irq_vector(phba->pcidev, index),
11071 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040011072
James Smartda0436e2009-05-22 14:51:39 -040011073 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011074 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011075
11076vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040011077 return rc;
11078}
11079
11080/**
James Smartda0436e2009-05-22 14:51:39 -040011081 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
11082 * @phba: pointer to lpfc hba data structure.
11083 *
11084 * This routine is invoked to enable the MSI interrupt mode to device with
11085 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
11086 * to enable the MSI vector. The device driver is responsible for calling
11087 * the request_irq() to register MSI vector with a interrupt the handler,
11088 * which is done in this function.
11089 *
11090 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011091 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011092 * other values - error
11093 **/
11094static int
11095lpfc_sli4_enable_msi(struct lpfc_hba *phba)
11096{
11097 int rc, index;
11098
11099 rc = pci_enable_msi(phba->pcidev);
11100 if (!rc)
11101 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11102 "0487 PCI enable MSI mode success.\n");
11103 else {
11104 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11105 "0488 PCI enable MSI mode failed (%d)\n", rc);
11106 return rc;
11107 }
11108
11109 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040011110 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040011111 if (rc) {
11112 pci_disable_msi(phba->pcidev);
11113 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11114 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040011115 return rc;
James Smartda0436e2009-05-22 14:51:39 -040011116 }
11117
James Smart6a828b02019-01-28 11:14:31 -080011118 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smart895427b2017-02-12 13:52:30 -080011119 phba->sli4_hba.hba_eq_hdl[index].idx = index;
11120 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040011121 }
11122
James Smart75baf692010-06-08 18:31:21 -040011123 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011124}
11125
11126/**
James Smartda0436e2009-05-22 14:51:39 -040011127 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
11128 * @phba: pointer to lpfc hba data structure.
11129 *
11130 * This routine is invoked to enable device interrupt and associate driver's
11131 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
11132 * interface spec. Depends on the interrupt mode configured to the driver,
11133 * the driver will try to fallback from the configured interrupt mode to an
11134 * interrupt mode which is supported by the platform, kernel, and device in
11135 * the order of:
11136 * MSI-X -> MSI -> IRQ.
11137 *
11138 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011139 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011140 * other values - error
11141 **/
11142static uint32_t
11143lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
11144{
11145 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080011146 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040011147
11148 if (cfg_mode == 2) {
11149 /* Preparation before conf_msi mbox cmd */
11150 retval = 0;
11151 if (!retval) {
11152 /* Now, try to enable MSI-X interrupt mode */
11153 retval = lpfc_sli4_enable_msix(phba);
11154 if (!retval) {
11155 /* Indicate initialization to MSI-X mode */
11156 phba->intr_type = MSIX;
11157 intr_mode = 2;
11158 }
11159 }
11160 }
11161
11162 /* Fallback to MSI if MSI-X initialization failed */
11163 if (cfg_mode >= 1 && phba->intr_type == NONE) {
11164 retval = lpfc_sli4_enable_msi(phba);
11165 if (!retval) {
11166 /* Indicate initialization to MSI mode */
11167 phba->intr_type = MSI;
11168 intr_mode = 1;
11169 }
11170 }
11171
11172 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11173 if (phba->intr_type == NONE) {
11174 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
11175 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
11176 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080011177 struct lpfc_hba_eq_hdl *eqhdl;
11178
James Smartda0436e2009-05-22 14:51:39 -040011179 /* Indicate initialization to INTx mode */
11180 phba->intr_type = INTx;
11181 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080011182
James Smart6a828b02019-01-28 11:14:31 -080011183 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smart895427b2017-02-12 13:52:30 -080011184 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
11185 eqhdl->idx = idx;
11186 eqhdl->phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050011187 }
James Smartda0436e2009-05-22 14:51:39 -040011188 }
11189 }
11190 return intr_mode;
11191}
11192
11193/**
11194 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
11195 * @phba: pointer to lpfc hba data structure.
11196 *
11197 * This routine is invoked to disable device interrupt and disassociate
11198 * the driver's interrupt handler(s) from interrupt vector(s) to device
11199 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
11200 * will release the interrupt vector(s) for the message signaled interrupt.
11201 **/
11202static void
11203lpfc_sli4_disable_intr(struct lpfc_hba *phba)
11204{
11205 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011206 if (phba->intr_type == MSIX) {
11207 int index;
11208
11209 /* Free up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011210 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartb3295c22019-01-28 11:14:30 -080011211 irq_set_affinity_hint(
11212 pci_irq_vector(phba->pcidev, index),
11213 NULL);
James Smart895427b2017-02-12 13:52:30 -080011214 free_irq(pci_irq_vector(phba->pcidev, index),
11215 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartb3295c22019-01-28 11:14:30 -080011216 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011217 } else {
James Smartda0436e2009-05-22 14:51:39 -040011218 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011219 }
11220
11221 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040011222
11223 /* Reset interrupt management states */
11224 phba->intr_type = NONE;
11225 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040011226}
11227
11228/**
James Smart3772a992009-05-22 14:50:54 -040011229 * lpfc_unset_hba - Unset SLI3 hba device initialization
11230 * @phba: pointer to lpfc hba data structure.
11231 *
11232 * This routine is invoked to unset the HBA device initialization steps to
11233 * a device with SLI-3 interface spec.
11234 **/
11235static void
11236lpfc_unset_hba(struct lpfc_hba *phba)
11237{
11238 struct lpfc_vport *vport = phba->pport;
11239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11240
11241 spin_lock_irq(shost->host_lock);
11242 vport->load_flag |= FC_UNLOADING;
11243 spin_unlock_irq(shost->host_lock);
11244
James Smart72859902012-01-18 16:25:38 -050011245 kfree(phba->vpi_bmask);
11246 kfree(phba->vpi_ids);
11247
James Smart3772a992009-05-22 14:50:54 -040011248 lpfc_stop_hba_timers(phba);
11249
11250 phba->pport->work_port_events = 0;
11251
11252 lpfc_sli_hba_down(phba);
11253
11254 lpfc_sli_brdrestart(phba);
11255
11256 lpfc_sli_disable_intr(phba);
11257
11258 return;
11259}
11260
11261/**
James Smart5af5eee2010-10-22 11:06:38 -040011262 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
11263 * @phba: Pointer to HBA context object.
11264 *
11265 * This function is called in the SLI4 code path to wait for completion
11266 * of device's XRIs exchange busy. It will check the XRI exchange busy
11267 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
11268 * that, it will check the XRI exchange busy on outstanding FCP and ELS
11269 * I/Os every 30 seconds, log error message, and wait forever. Only when
11270 * all XRI exchange busy complete, the driver unload shall proceed with
11271 * invoking the function reset ioctl mailbox command to the CNA and the
11272 * the rest of the driver unload resource release.
11273 **/
11274static void
11275lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
11276{
James Smart5e5b5112019-01-28 11:14:22 -080011277 struct lpfc_sli4_hdw_queue *qp;
11278 int idx, ccnt, fcnt;
James Smart5af5eee2010-10-22 11:06:38 -040011279 int wait_time = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011280 int io_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070011281 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080011282 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040011283 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
11284
James Smartc3725bd2017-11-20 16:00:42 -080011285 /* Driver just aborted IOs during the hba_unset process. Pause
11286 * here to give the HBA time to complete the IO and get entries
11287 * into the abts lists.
11288 */
11289 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
11290
11291 /* Wait for NVME pending IO to flush back to transport. */
11292 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11293 lpfc_nvme_wait_for_io_drain(phba);
11294
James Smart5e5b5112019-01-28 11:14:22 -080011295 ccnt = 0;
11296 fcnt = 0;
11297 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11298 qp = &phba->sli4_hba.hdwq[idx];
11299 fcp_xri_cmpl = list_empty(
11300 &qp->lpfc_abts_scsi_buf_list);
11301 if (!fcp_xri_cmpl) /* if list is NOT empty */
11302 fcnt++;
11303 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11304 io_xri_cmpl = list_empty(
11305 &qp->lpfc_abts_nvme_buf_list);
11306 if (!io_xri_cmpl) /* if list is NOT empty */
11307 ccnt++;
11308 }
11309 }
11310 if (ccnt)
11311 io_xri_cmpl = 0;
11312 if (fcnt)
11313 fcp_xri_cmpl = 0;
11314
James Smart86c67372017-04-21 16:05:04 -070011315 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011316 nvmet_xri_cmpl =
11317 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11318 }
James Smart895427b2017-02-12 13:52:30 -080011319
James Smart5e5b5112019-01-28 11:14:22 -080011320 while (!fcp_xri_cmpl || !els_xri_cmpl || !io_xri_cmpl ||
James Smartf358dd02017-02-12 13:52:34 -080011321 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040011322 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070011323 if (!nvmet_xri_cmpl)
11324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11325 "6424 NVMET XRI exchange busy "
11326 "wait time: %d seconds.\n",
11327 wait_time/1000);
James Smart5e5b5112019-01-28 11:14:22 -080011328 if (!io_xri_cmpl)
James Smart895427b2017-02-12 13:52:30 -080011329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11330 "6100 NVME XRI exchange busy "
11331 "wait time: %d seconds.\n",
11332 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040011333 if (!fcp_xri_cmpl)
11334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11335 "2877 FCP XRI exchange busy "
11336 "wait time: %d seconds.\n",
11337 wait_time/1000);
11338 if (!els_xri_cmpl)
11339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11340 "2878 ELS XRI exchange busy "
11341 "wait time: %d seconds.\n",
11342 wait_time/1000);
11343 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
11344 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
11345 } else {
11346 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
11347 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
11348 }
James Smart5e5b5112019-01-28 11:14:22 -080011349
11350 ccnt = 0;
11351 fcnt = 0;
11352 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11353 qp = &phba->sli4_hba.hdwq[idx];
11354 fcp_xri_cmpl = list_empty(
11355 &qp->lpfc_abts_scsi_buf_list);
11356 if (!fcp_xri_cmpl) /* if list is NOT empty */
11357 fcnt++;
11358 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11359 io_xri_cmpl = list_empty(
11360 &qp->lpfc_abts_nvme_buf_list);
11361 if (!io_xri_cmpl) /* if list is NOT empty */
11362 ccnt++;
11363 }
11364 }
11365 if (ccnt)
11366 io_xri_cmpl = 0;
11367 if (fcnt)
11368 fcp_xri_cmpl = 0;
11369
James Smart86c67372017-04-21 16:05:04 -070011370 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011371 nvmet_xri_cmpl = list_empty(
11372 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11373 }
James Smart5af5eee2010-10-22 11:06:38 -040011374 els_xri_cmpl =
11375 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080011376
James Smart5af5eee2010-10-22 11:06:38 -040011377 }
11378}
11379
11380/**
James Smartda0436e2009-05-22 14:51:39 -040011381 * lpfc_sli4_hba_unset - Unset the fcoe hba
11382 * @phba: Pointer to HBA context object.
11383 *
11384 * This function is called in the SLI4 code path to reset the HBA's FCoE
11385 * function. The caller is not required to hold any lock. This routine
11386 * issues PCI function reset mailbox command to reset the FCoE function.
11387 * At the end of the function, it calls lpfc_hba_down_post function to
11388 * free any pending commands.
11389 **/
11390static void
11391lpfc_sli4_hba_unset(struct lpfc_hba *phba)
11392{
11393 int wait_cnt = 0;
11394 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040011395 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040011396
11397 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -080011398 if (phba->pport)
11399 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -040011400
11401 /*
11402 * Gracefully wait out the potential current outstanding asynchronous
11403 * mailbox command.
11404 */
11405
11406 /* First, block any pending async mailbox command from posted */
11407 spin_lock_irq(&phba->hbalock);
11408 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
11409 spin_unlock_irq(&phba->hbalock);
11410 /* Now, trying to wait it out if we can */
11411 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11412 msleep(10);
11413 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
11414 break;
11415 }
11416 /* Forcefully release the outstanding mailbox command if timed out */
11417 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11418 spin_lock_irq(&phba->hbalock);
11419 mboxq = phba->sli.mbox_active;
11420 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
11421 __lpfc_mbox_cmpl_put(phba, mboxq);
11422 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11423 phba->sli.mbox_active = NULL;
11424 spin_unlock_irq(&phba->hbalock);
11425 }
11426
James Smart5af5eee2010-10-22 11:06:38 -040011427 /* Abort all iocbs associated with the hba */
11428 lpfc_sli_hba_iocb_abort(phba);
11429
11430 /* Wait for completion of device XRI exchange busy */
11431 lpfc_sli4_xri_exchange_busy_wait(phba);
11432
James Smartda0436e2009-05-22 14:51:39 -040011433 /* Disable PCI subsystem interrupt */
11434 lpfc_sli4_disable_intr(phba);
11435
James Smart912e3ac2011-05-24 11:42:11 -040011436 /* Disable SR-IOV if enabled */
11437 if (phba->cfg_sriov_nr_virtfn)
11438 pci_disable_sriov(pdev);
11439
James Smartda0436e2009-05-22 14:51:39 -040011440 /* Stop kthread signal shall trigger work_done one more time */
11441 kthread_stop(phba->worker_thread);
11442
James Smartd2cc9bc2018-09-10 10:30:50 -070011443 /* Disable FW logging to host memory */
James Smart1165a5c2018-11-29 16:09:39 -080011444 lpfc_ras_stop_fwlog(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070011445
James Smartd1f525a2017-04-21 16:04:55 -070011446 /* Unset the queues shared with the hardware then release all
11447 * allocated resources.
11448 */
11449 lpfc_sli4_queue_unset(phba);
11450 lpfc_sli4_queue_destroy(phba);
11451
James Smart3677a3a2010-09-29 11:19:14 -040011452 /* Reset SLI4 HBA FCoE function */
11453 lpfc_pci_function_reset(phba);
11454
James Smart1165a5c2018-11-29 16:09:39 -080011455 /* Free RAS DMA memory */
11456 if (phba->ras_fwlog.ras_enabled)
11457 lpfc_sli4_ras_dma_free(phba);
11458
James Smartda0436e2009-05-22 14:51:39 -040011459 /* Stop the SLI4 device port */
James Smart1ffdd2c2019-03-04 15:27:51 -080011460 if (phba->pport)
11461 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -040011462}
11463
James Smart28baac72010-02-12 14:42:03 -050011464 /**
11465 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
11466 * @phba: Pointer to HBA context object.
11467 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11468 *
11469 * This function is called in the SLI4 code path to read the port's
11470 * sli4 capabilities.
11471 *
11472 * This function may be be called from any context that can block-wait
11473 * for the completion. The expectation is that this routine is called
11474 * typically from probe_one or from the online routine.
11475 **/
11476int
11477lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11478{
11479 int rc;
11480 struct lpfc_mqe *mqe;
11481 struct lpfc_pc_sli4_params *sli4_params;
11482 uint32_t mbox_tmo;
11483
11484 rc = 0;
11485 mqe = &mboxq->u.mqe;
11486
11487 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050011488 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050011489 if (!phba->sli4_hba.intr_enable)
11490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11491 else {
James Smarta183a152011-10-10 21:32:43 -040011492 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050011493 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11494 }
11495
11496 if (unlikely(rc))
11497 return 1;
11498
11499 sli4_params = &phba->sli4_hba.pc_sli4_params;
11500 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
11501 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
11502 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
11503 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
11504 &mqe->un.sli4_params);
11505 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
11506 &mqe->un.sli4_params);
11507 sli4_params->proto_types = mqe->un.sli4_params.word3;
11508 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
11509 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
11510 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
11511 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
11512 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
11513 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
11514 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
11515 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
11516 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
11517 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
11518 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
11519 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
11520 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
11521 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
11522 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
11523 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
11524 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
11525 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
11526 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
11527 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040011528
11529 /* Make sure that sge_supp_len can be handled by the driver */
11530 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
11531 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
11532
James Smart28baac72010-02-12 14:42:03 -050011533 return rc;
11534}
11535
James Smartda0436e2009-05-22 14:51:39 -040011536/**
James Smartfedd3b72011-02-16 12:39:24 -050011537 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
11538 * @phba: Pointer to HBA context object.
11539 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11540 *
11541 * This function is called in the SLI4 code path to read the port's
11542 * sli4 capabilities.
11543 *
11544 * This function may be be called from any context that can block-wait
11545 * for the completion. The expectation is that this routine is called
11546 * typically from probe_one or from the online routine.
11547 **/
11548int
11549lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11550{
11551 int rc;
11552 struct lpfc_mqe *mqe = &mboxq->u.mqe;
11553 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040011554 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050011555 int length;
James Smartbf316c72018-04-09 14:24:28 -070011556 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050011557 struct lpfc_sli4_parameters *mbx_sli4_parameters;
11558
James Smart6d368e52011-05-24 11:44:12 -040011559 /*
11560 * By default, the driver assumes the SLI4 port requires RPI
11561 * header postings. The SLI4_PARAM response will correct this
11562 * assumption.
11563 */
11564 phba->sli4_hba.rpi_hdrs_in_use = 1;
11565
James Smartfedd3b72011-02-16 12:39:24 -050011566 /* Read the port's SLI4 Config Parameters */
11567 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
11568 sizeof(struct lpfc_sli4_cfg_mhdr));
11569 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11570 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
11571 length, LPFC_SLI4_MBX_EMBED);
11572 if (!phba->sli4_hba.intr_enable)
11573 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040011574 else {
11575 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
11576 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11577 }
James Smartfedd3b72011-02-16 12:39:24 -050011578 if (unlikely(rc))
11579 return rc;
11580 sli4_params = &phba->sli4_hba.pc_sli4_params;
11581 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
11582 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
11583 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
11584 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
11585 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
11586 mbx_sli4_parameters);
11587 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
11588 mbx_sli4_parameters);
11589 if (bf_get(cfg_phwq, mbx_sli4_parameters))
11590 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
11591 else
11592 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
11593 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
11594 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050011595 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011596 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
11597 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
11598 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
11599 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080011600 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
11601 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040011602 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070011603 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011604 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
11605 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080011606 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011607 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
11608 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040011609 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
11610 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080011611
James Smartc15e0702019-05-21 17:49:02 -070011612 /* Check for firmware nvme support */
11613 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
11614 bf_get(cfg_xib, mbx_sli4_parameters));
James Smart895427b2017-02-12 13:52:30 -080011615
James Smartc15e0702019-05-21 17:49:02 -070011616 if (rc) {
11617 /* Save this to indicate the Firmware supports NVME */
11618 sli4_params->nvme = 1;
11619
11620 /* Firmware NVME support, check driver FC4 NVME support */
11621 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
11622 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
11623 "6133 Disabling NVME support: "
11624 "FC4 type not supported: x%x\n",
11625 phba->cfg_enable_fc4_type);
11626 goto fcponly;
11627 }
11628 } else {
11629 /* No firmware NVME support, check driver FC4 NVME support */
11630 sli4_params->nvme = 0;
11631 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
11633 "6101 Disabling NVME support: Not "
11634 "supported by firmware (%d %d) x%x\n",
11635 bf_get(cfg_nvme, mbx_sli4_parameters),
11636 bf_get(cfg_xib, mbx_sli4_parameters),
11637 phba->cfg_enable_fc4_type);
11638fcponly:
11639 phba->nvme_support = 0;
11640 phba->nvmet_support = 0;
11641 phba->cfg_nvmet_mrq = 0;
11642
11643 /* If no FC4 type support, move to just SCSI support */
11644 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
11645 return -ENODEV;
11646 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
11647 }
James Smart895427b2017-02-12 13:52:30 -080011648 }
James Smart05580562011-05-24 11:40:48 -040011649
James Smart414abe02018-06-26 08:24:26 -070011650 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
11651 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
11652 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
11653 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080011654
James Smart20aefac2018-01-30 15:58:58 -080011655 /*
11656 * To support Suppress Response feature we must satisfy 3 conditions.
11657 * lpfc_suppress_rsp module parameter must be set (default).
11658 * In SLI4-Parameters Descriptor:
11659 * Extended Inline Buffers (XIB) must be supported.
11660 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
11661 * (double negative).
11662 */
11663 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
11664 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080011665 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080011666 else
11667 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080011668
James Smart0cf07f842017-06-01 21:07:10 -070011669 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
11670 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
11671
James Smart05580562011-05-24 11:40:48 -040011672 /* Make sure that sge_supp_len can be handled by the driver */
11673 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
11674 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
11675
James Smartb5c53952016-03-31 14:12:30 -070011676 /*
James Smartc176ffa2018-01-30 15:58:46 -080011677 * Check whether the adapter supports an embedded copy of the
11678 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
11679 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070011680 */
11681 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
11682 phba->fcp_embed_io = 1;
11683 else
11684 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070011685
James Smart0bc2b7c2018-02-22 08:18:48 -080011686 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070011687 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080011688 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070011689 phba->cfg_enable_pbde,
11690 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080011691 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080011692
James Smartbf316c72018-04-09 14:24:28 -070011693 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
11694 LPFC_SLI_INTF_IF_TYPE_2) &&
11695 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070011696 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070011697 exp_wqcq_pages = false;
11698
James Smartc176ffa2018-01-30 15:58:46 -080011699 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
11700 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070011701 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080011702 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
11703 phba->enab_exp_wqcq_pages = 1;
11704 else
11705 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070011706 /*
11707 * Check if the SLI port supports MDS Diagnostics
11708 */
11709 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
11710 phba->mds_diags_support = 1;
11711 else
11712 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070011713
James Smartfedd3b72011-02-16 12:39:24 -050011714 return 0;
11715}
11716
11717/**
James Smart3772a992009-05-22 14:50:54 -040011718 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
11719 * @pdev: pointer to PCI device
11720 * @pid: pointer to PCI device identifier
11721 *
11722 * This routine is to be called to attach a device with SLI-3 interface spec
11723 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11724 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11725 * information of the device and driver to see if the driver state that it can
11726 * support this kind of device. If the match is successful, the driver core
11727 * invokes this routine. If this routine determines it can claim the HBA, it
11728 * does all the initialization that it needs to do to handle the HBA properly.
11729 *
11730 * Return code
11731 * 0 - driver can claim the device
11732 * negative value - driver can not claim the device
11733 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011734static int
James Smart3772a992009-05-22 14:50:54 -040011735lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
11736{
11737 struct lpfc_hba *phba;
11738 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011739 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040011740 int error;
11741 uint32_t cfg_mode, intr_mode;
11742
11743 /* Allocate memory for HBA structure */
11744 phba = lpfc_hba_alloc(pdev);
11745 if (!phba)
11746 return -ENOMEM;
11747
11748 /* Perform generic PCI device enabling operation */
11749 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011750 if (error)
James Smart3772a992009-05-22 14:50:54 -040011751 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040011752
11753 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
11754 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
11755 if (error)
11756 goto out_disable_pci_dev;
11757
11758 /* Set up SLI-3 specific device PCI memory space */
11759 error = lpfc_sli_pci_mem_setup(phba);
11760 if (error) {
11761 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11762 "1402 Failed to set up pci memory space.\n");
11763 goto out_disable_pci_dev;
11764 }
11765
James Smart3772a992009-05-22 14:50:54 -040011766 /* Set up SLI-3 specific device driver resources */
11767 error = lpfc_sli_driver_resource_setup(phba);
11768 if (error) {
11769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11770 "1404 Failed to set up driver resource.\n");
11771 goto out_unset_pci_mem_s3;
11772 }
11773
11774 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070011775
James Smart3772a992009-05-22 14:50:54 -040011776 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
11777 if (error) {
11778 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11779 "1405 Failed to initialize iocb list.\n");
11780 goto out_unset_driver_resource_s3;
11781 }
11782
11783 /* Set up common device driver resources */
11784 error = lpfc_setup_driver_resource_phase2(phba);
11785 if (error) {
11786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11787 "1406 Failed to set up driver resource.\n");
11788 goto out_free_iocb_list;
11789 }
11790
James Smart079b5c92011-08-21 21:48:49 -040011791 /* Get the default values for Model Name and Description */
11792 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11793
James Smart3772a992009-05-22 14:50:54 -040011794 /* Create SCSI host to the physical port */
11795 error = lpfc_create_shost(phba);
11796 if (error) {
11797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11798 "1407 Failed to create scsi host.\n");
11799 goto out_unset_driver_resource;
11800 }
11801
11802 /* Configure sysfs attributes */
11803 vport = phba->pport;
11804 error = lpfc_alloc_sysfs_attr(vport);
11805 if (error) {
11806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11807 "1476 Failed to allocate sysfs attr\n");
11808 goto out_destroy_shost;
11809 }
11810
James Smart6669f9b2009-10-02 15:16:45 -040011811 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040011812 /* Now, trying to enable interrupt and bring up the device */
11813 cfg_mode = phba->cfg_use_msi;
11814 while (true) {
11815 /* Put device to a known state before enabling interrupt */
11816 lpfc_stop_port(phba);
11817 /* Configure and enable interrupt */
11818 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
11819 if (intr_mode == LPFC_INTR_ERROR) {
11820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11821 "0431 Failed to enable interrupt.\n");
11822 error = -ENODEV;
11823 goto out_free_sysfs_attr;
11824 }
11825 /* SLI-3 HBA setup */
11826 if (lpfc_sli_hba_setup(phba)) {
11827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11828 "1477 Failed to set up hba\n");
11829 error = -ENODEV;
11830 goto out_remove_device;
11831 }
11832
11833 /* Wait 50ms for the interrupts of previous mailbox commands */
11834 msleep(50);
11835 /* Check active interrupts on message signaled interrupts */
11836 if (intr_mode == 0 ||
11837 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
11838 /* Log the current active interrupt mode */
11839 phba->intr_mode = intr_mode;
11840 lpfc_log_intr_mode(phba, intr_mode);
11841 break;
11842 } else {
11843 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11844 "0447 Configure interrupt mode (%d) "
11845 "failed active interrupt test.\n",
11846 intr_mode);
11847 /* Disable the current interrupt mode */
11848 lpfc_sli_disable_intr(phba);
11849 /* Try next level of interrupt mode */
11850 cfg_mode = --intr_mode;
11851 }
11852 }
11853
11854 /* Perform post initialization setup */
11855 lpfc_post_init_setup(phba);
11856
11857 /* Check if there are static vports to be created. */
11858 lpfc_create_static_vport(phba);
11859
11860 return 0;
11861
11862out_remove_device:
11863 lpfc_unset_hba(phba);
11864out_free_sysfs_attr:
11865 lpfc_free_sysfs_attr(vport);
11866out_destroy_shost:
11867 lpfc_destroy_shost(phba);
11868out_unset_driver_resource:
11869 lpfc_unset_driver_resource_phase2(phba);
11870out_free_iocb_list:
11871 lpfc_free_iocb_list(phba);
11872out_unset_driver_resource_s3:
11873 lpfc_sli_driver_resource_unset(phba);
11874out_unset_pci_mem_s3:
11875 lpfc_sli_pci_mem_unset(phba);
11876out_disable_pci_dev:
11877 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011878 if (shost)
11879 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040011880out_free_phba:
11881 lpfc_hba_free(phba);
11882 return error;
11883}
11884
11885/**
11886 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040011887 * @pdev: pointer to PCI device
11888 *
James Smart3772a992009-05-22 14:50:54 -040011889 * This routine is to be called to disattach a device with SLI-3 interface
11890 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11891 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11892 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040011893 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011894static void
James Smart3772a992009-05-22 14:50:54 -040011895lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050011896{
James Smart2e0fef82007-06-17 19:56:36 -050011897 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11898 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050011899 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050011900 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050011901 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050011902
James Smart549e55c2007-08-02 11:09:51 -040011903 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040011904 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040011905 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050011906
James Smart858c9f62007-06-17 19:56:39 -050011907 lpfc_free_sysfs_attr(vport);
11908
James Smarteada2722008-12-04 22:39:13 -050011909 /* Release all the vports against this physical port */
11910 vports = lpfc_create_vport_work_array(phba);
11911 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011912 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11913 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11914 continue;
James Smarteada2722008-12-04 22:39:13 -050011915 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011916 }
James Smarteada2722008-12-04 22:39:13 -050011917 lpfc_destroy_vport_work_array(phba, vports);
11918
11919 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050011920 fc_remove_host(shost);
11921 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080011922
James Smart87af33f2007-10-27 13:37:43 -040011923 lpfc_cleanup(vport);
11924
James Smart2e0fef82007-06-17 19:56:36 -050011925 /*
11926 * Bring down the SLI Layer. This step disable all interrupts,
11927 * clears the rings, discards all mailbox commands, and resets
11928 * the HBA.
11929 */
James Smarta257bf92009-04-06 18:48:10 -040011930
Justin P. Mattock48e34d02010-12-30 15:07:58 -080011931 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050011932 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040011933 /* Stop kthread signal shall trigger work_done one more time */
11934 kthread_stop(phba->worker_thread);
11935 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050011936 lpfc_sli_brdrestart(phba);
11937
James Smart72859902012-01-18 16:25:38 -050011938 kfree(phba->vpi_bmask);
11939 kfree(phba->vpi_ids);
11940
James Smart3772a992009-05-22 14:50:54 -040011941 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011942 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011943 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011944 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011945
James Smart858c9f62007-06-17 19:56:39 -050011946 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050011947
James Smart912e3ac2011-05-24 11:42:11 -040011948 /* Disable SR-IOV if enabled */
11949 if (phba->cfg_sriov_nr_virtfn)
11950 pci_disable_sriov(pdev);
11951
James Smart5b75da22008-12-04 22:39:35 -050011952 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011953 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011954
James Smart858c9f62007-06-17 19:56:39 -050011955 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011956
11957 /*
11958 * Call scsi_free before mem_free since scsi bufs are released to their
11959 * corresponding pools here.
11960 */
11961 lpfc_scsi_free(phba);
James Smart0794d602019-01-28 11:14:19 -080011962 lpfc_free_iocb_list(phba);
11963
James Smart3772a992009-05-22 14:50:54 -040011964 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011965
James Smart34b02dc2008-08-24 21:49:55 -040011966 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11967 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011968
James Smart2e0fef82007-06-17 19:56:36 -050011969 /* Free resources associated with SLI2 interface */
11970 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011971 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011972
11973 /* unmap adapter SLIM and Control Registers */
11974 iounmap(phba->ctrl_regs_memmap_p);
11975 iounmap(phba->slim_memmap_p);
11976
James Smart3772a992009-05-22 14:50:54 -040011977 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011978
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011979 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011980 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011981}
11982
Linas Vepstas8d63f372007-02-14 14:28:36 -060011983/**
James Smart3772a992009-05-22 14:50:54 -040011984 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011985 * @pdev: pointer to PCI device
11986 * @msg: power management message
11987 *
James Smart3772a992009-05-22 14:50:54 -040011988 * This routine is to be called from the kernel's PCI subsystem to support
11989 * system Power Management (PM) to device with SLI-3 interface spec. When
11990 * PM invokes this method, it quiesces the device by stopping the driver's
11991 * worker thread for the device, turning off device's interrupt and DMA,
11992 * and bring the device offline. Note that as the driver implements the
11993 * minimum PM requirements to a power-aware driver's PM support for the
11994 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11995 * to the suspend() method call will be treated as SUSPEND and the driver will
11996 * fully reinitialize its device during resume() method call, the driver will
11997 * set device to PCI_D3hot state in PCI config space instead of setting it
11998 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050011999 *
12000 * Return code
James Smart3772a992009-05-22 14:50:54 -040012001 * 0 - driver suspended the device
12002 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012003 **/
12004static int
James Smart3772a992009-05-22 14:50:54 -040012005lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050012006{
12007 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12008 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12009
12010 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12011 "0473 PCI device Power Management suspend.\n");
12012
12013 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012014 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050012015 lpfc_offline(phba);
12016 kthread_stop(phba->worker_thread);
12017
12018 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040012019 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050012020
12021 /* Save device state to PCI config space */
12022 pci_save_state(pdev);
12023 pci_set_power_state(pdev, PCI_D3hot);
12024
12025 return 0;
12026}
12027
12028/**
James Smart3772a992009-05-22 14:50:54 -040012029 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050012030 * @pdev: pointer to PCI device
12031 *
James Smart3772a992009-05-22 14:50:54 -040012032 * This routine is to be called from the kernel's PCI subsystem to support
12033 * system Power Management (PM) to device with SLI-3 interface spec. When PM
12034 * invokes this method, it restores the device's PCI config space state and
12035 * fully reinitializes the device and brings it online. Note that as the
12036 * driver implements the minimum PM requirements to a power-aware driver's
12037 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
12038 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
12039 * driver will fully reinitialize its device during resume() method call,
12040 * the device will be set to PCI_D0 directly in PCI config space before
12041 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050012042 *
12043 * Return code
James Smart3772a992009-05-22 14:50:54 -040012044 * 0 - driver suspended the device
12045 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012046 **/
12047static int
James Smart3772a992009-05-22 14:50:54 -040012048lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050012049{
12050 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12051 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050012052 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012053 int error;
12054
12055 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12056 "0452 PCI device Power Management resume.\n");
12057
12058 /* Restore device state from PCI config space */
12059 pci_set_power_state(pdev, PCI_D0);
12060 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040012061
James Smart1dfb5a42010-02-12 14:40:50 -050012062 /*
12063 * As the new kernel behavior of pci_restore_state() API call clears
12064 * device saved_state flag, need to save the restored state again.
12065 */
12066 pci_save_state(pdev);
12067
James Smart3a55b532008-12-04 22:38:54 -050012068 if (pdev->is_busmaster)
12069 pci_set_master(pdev);
12070
12071 /* Startup the kernel thread for this host adapter. */
12072 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12073 "lpfc_worker_%d", phba->brd_no);
12074 if (IS_ERR(phba->worker_thread)) {
12075 error = PTR_ERR(phba->worker_thread);
12076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12077 "0434 PM resume failed to start worker "
12078 "thread: error=x%x.\n", error);
12079 return error;
12080 }
12081
James Smart5b75da22008-12-04 22:39:35 -050012082 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012083 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012084 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050012085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050012086 "0430 PM resume Failed to enable interrupt\n");
12087 return -EIO;
12088 } else
12089 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012090
12091 /* Restart HBA and bring it online */
12092 lpfc_sli_brdrestart(phba);
12093 lpfc_online(phba);
12094
James Smart5b75da22008-12-04 22:39:35 -050012095 /* Log the current active interrupt mode */
12096 lpfc_log_intr_mode(phba, phba->intr_mode);
12097
James Smart3a55b532008-12-04 22:38:54 -050012098 return 0;
12099}
12100
12101/**
James Smart891478a2009-11-18 15:40:23 -050012102 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
12103 * @phba: pointer to lpfc hba data structure.
12104 *
12105 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040012106 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050012107 **/
12108static void
12109lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
12110{
12111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12112 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040012113
12114 /*
12115 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12116 * and let the SCSI mid-layer to retry them to recover.
12117 */
James Smartdb55fba2014-04-04 13:52:02 -040012118 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050012119}
12120
12121/**
James Smart0d878412009-10-02 15:16:56 -040012122 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
12123 * @phba: pointer to lpfc hba data structure.
12124 *
12125 * This routine is called to prepare the SLI3 device for PCI slot reset. It
12126 * disables the device interrupt and pci device, and aborts the internal FCP
12127 * pending I/Os.
12128 **/
12129static void
12130lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
12131{
James Smart0d878412009-10-02 15:16:56 -040012132 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050012133 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040012134
James Smart75baf692010-06-08 18:31:21 -040012135 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012136 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012137
James Smarte2af0d22010-03-15 11:25:32 -040012138 /* Block all SCSI devices' I/Os on the host */
12139 lpfc_scsi_dev_block(phba);
12140
James Smartea714f32013-04-17 20:18:47 -040012141 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12142 lpfc_sli_flush_fcp_rings(phba);
12143
James Smarte2af0d22010-03-15 11:25:32 -040012144 /* stop all timers */
12145 lpfc_stop_hba_timers(phba);
12146
James Smart0d878412009-10-02 15:16:56 -040012147 /* Disable interrupt and pci device */
12148 lpfc_sli_disable_intr(phba);
12149 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040012150}
12151
12152/**
12153 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
12154 * @phba: pointer to lpfc hba data structure.
12155 *
12156 * This routine is called to prepare the SLI3 device for PCI slot permanently
12157 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12158 * pending I/Os.
12159 **/
12160static void
James Smart75baf692010-06-08 18:31:21 -040012161lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040012162{
12163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050012164 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040012165 /* Block all SCSI devices' I/Os on the host */
12166 lpfc_scsi_dev_block(phba);
12167
12168 /* stop all timers */
12169 lpfc_stop_hba_timers(phba);
12170
James Smart0d878412009-10-02 15:16:56 -040012171 /* Clean up all driver's outstanding SCSI I/Os */
12172 lpfc_sli_flush_fcp_rings(phba);
12173}
12174
12175/**
James Smart3772a992009-05-22 14:50:54 -040012176 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040012177 * @pdev: pointer to PCI device.
12178 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012179 *
James Smart3772a992009-05-22 14:50:54 -040012180 * This routine is called from the PCI subsystem for I/O error handling to
12181 * device with SLI-3 interface spec. This function is called by the PCI
12182 * subsystem after a PCI bus error affecting this device has been detected.
12183 * When this function is invoked, it will need to stop all the I/Os and
12184 * interrupt(s) to the device. Once that is done, it will return
12185 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
12186 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040012187 *
12188 * Return codes
James Smart0d878412009-10-02 15:16:56 -040012189 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040012190 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12191 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040012192 **/
James Smart3772a992009-05-22 14:50:54 -040012193static pci_ers_result_t
12194lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012195{
James Smart51ef4c22007-08-02 11:10:31 -040012196 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12197 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012198
James Smart0d878412009-10-02 15:16:56 -040012199 switch (state) {
12200 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050012201 /* Non-fatal error, prepare for recovery */
12202 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040012203 return PCI_ERS_RESULT_CAN_RECOVER;
12204 case pci_channel_io_frozen:
12205 /* Fatal error, prepare for slot reset */
12206 lpfc_sli_prep_dev_for_reset(phba);
12207 return PCI_ERS_RESULT_NEED_RESET;
12208 case pci_channel_io_perm_failure:
12209 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040012210 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012211 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040012212 default:
12213 /* Unknown state, prepare and request slot reset */
12214 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12215 "0472 Unknown PCI error state: x%x\n", state);
12216 lpfc_sli_prep_dev_for_reset(phba);
12217 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040012218 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060012219}
12220
12221/**
James Smart3772a992009-05-22 14:50:54 -040012222 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040012223 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012224 *
James Smart3772a992009-05-22 14:50:54 -040012225 * This routine is called from the PCI subsystem for error handling to
12226 * device with SLI-3 interface spec. This is called after PCI bus has been
12227 * reset to restart the PCI card from scratch, as if from a cold-boot.
12228 * During the PCI subsystem error recovery, after driver returns
12229 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12230 * recovery and then call this routine before calling the .resume method
12231 * to recover the device. This function will initialize the HBA device,
12232 * enable the interrupt, but it will just put the HBA to offline state
12233 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040012234 *
12235 * Return codes
James Smart3772a992009-05-22 14:50:54 -040012236 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12237 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060012238 */
James Smart3772a992009-05-22 14:50:54 -040012239static pci_ers_result_t
12240lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012241{
James Smart51ef4c22007-08-02 11:10:31 -040012242 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12243 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012244 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050012245 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012246
12247 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110012248 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012249 printk(KERN_ERR "lpfc: Cannot re-enable "
12250 "PCI device after reset.\n");
12251 return PCI_ERS_RESULT_DISCONNECT;
12252 }
12253
James Smart97207482008-12-04 22:39:19 -050012254 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012255
12256 /*
12257 * As the new kernel behavior of pci_restore_state() API call clears
12258 * device saved_state flag, need to save the restored state again.
12259 */
12260 pci_save_state(pdev);
12261
James Smart97207482008-12-04 22:39:19 -050012262 if (pdev->is_busmaster)
12263 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012264
James Smart92d7f7b2007-06-17 19:56:38 -050012265 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040012266 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050012267 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012268
James Smart5b75da22008-12-04 22:39:35 -050012269 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012270 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012271 if (intr_mode == LPFC_INTR_ERROR) {
12272 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12273 "0427 Cannot re-enable interrupt after "
12274 "slot reset.\n");
12275 return PCI_ERS_RESULT_DISCONNECT;
12276 } else
12277 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012278
James Smart75baf692010-06-08 18:31:21 -040012279 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040012280 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012281 lpfc_offline(phba);
12282 lpfc_sli_brdrestart(phba);
12283
James Smart5b75da22008-12-04 22:39:35 -050012284 /* Log the current active interrupt mode */
12285 lpfc_log_intr_mode(phba, phba->intr_mode);
12286
Linas Vepstas8d63f372007-02-14 14:28:36 -060012287 return PCI_ERS_RESULT_RECOVERED;
12288}
12289
12290/**
James Smart3772a992009-05-22 14:50:54 -040012291 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040012292 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060012293 *
James Smart3772a992009-05-22 14:50:54 -040012294 * This routine is called from the PCI subsystem for error handling to device
12295 * with SLI-3 interface spec. It is called when kernel error recovery tells
12296 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12297 * error recovery. After this call, traffic can start to flow from this device
12298 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012299 */
James Smart3772a992009-05-22 14:50:54 -040012300static void
12301lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012302{
James Smart51ef4c22007-08-02 11:10:31 -040012303 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12304 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012305
James Smarte2af0d22010-03-15 11:25:32 -040012306 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040012307 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012308}
12309
James Smart3772a992009-05-22 14:50:54 -040012310/**
James Smartda0436e2009-05-22 14:51:39 -040012311 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
12312 * @phba: pointer to lpfc hba data structure.
12313 *
12314 * returns the number of ELS/CT IOCBs to reserve
12315 **/
12316int
12317lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
12318{
12319 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
12320
James Smartf1126682009-06-10 17:22:44 -040012321 if (phba->sli_rev == LPFC_SLI_REV4) {
12322 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040012323 return 10;
James Smartf1126682009-06-10 17:22:44 -040012324 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040012325 return 25;
James Smartf1126682009-06-10 17:22:44 -040012326 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040012327 return 50;
James Smartf1126682009-06-10 17:22:44 -040012328 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040012329 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040012330 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040012331 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040012332 else if (max_xri <= 2048)
12333 return 200;
12334 else
12335 return 250;
James Smartf1126682009-06-10 17:22:44 -040012336 } else
12337 return 0;
James Smartda0436e2009-05-22 14:51:39 -040012338}
12339
12340/**
James Smart895427b2017-02-12 13:52:30 -080012341 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
12342 * @phba: pointer to lpfc hba data structure.
12343 *
James Smartf358dd02017-02-12 13:52:34 -080012344 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080012345 **/
12346int
12347lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
12348{
12349 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
12350
James Smartf358dd02017-02-12 13:52:34 -080012351 if (phba->nvmet_support)
12352 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080012353 return max_xri;
12354}
12355
12356
James Smart1feb8202018-02-22 08:18:47 -080012357static void
12358lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
12359 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
12360 const struct firmware *fw)
12361{
James Smarta72d56b2018-05-04 20:37:52 -070012362 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
12363 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
12364 magic_number != MAGIC_NUMER_G6) ||
12365 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
12366 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080012367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12368 "3030 This firmware version is not supported on "
12369 "this HBA model. Device:%x Magic:%x Type:%x "
12370 "ID:%x Size %d %zd\n",
12371 phba->pcidev->device, magic_number, ftype, fid,
12372 fsize, fw->size);
12373 else
12374 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12375 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
12376 "ID:%x Size %d %zd\n",
12377 phba->pcidev->device, magic_number, ftype, fid,
12378 fsize, fw->size);
12379}
12380
12381
James Smart895427b2017-02-12 13:52:30 -080012382/**
James Smart52d52442011-05-24 11:42:45 -040012383 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040012384 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040012385 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040012386 *
James Smart52d52442011-05-24 11:42:45 -040012387 **/
James Smartce396282012-09-29 11:30:56 -040012388static void
12389lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040012390{
James Smartce396282012-09-29 11:30:56 -040012391 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050012392 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040012393 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040012394 struct list_head dma_buffer_list;
12395 int i, rc = 0;
12396 struct lpfc_dmabuf *dmabuf, *next;
12397 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070012398 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040012399
James Smartc71ab862012-10-31 14:44:33 -040012400 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040012401 if (!fw) {
12402 rc = -ENXIO;
12403 goto out;
12404 }
12405 image = (struct lpfc_grp_hdr *)fw->data;
12406
James Smart6b6ef5d2016-10-13 15:06:17 -070012407 magic_number = be32_to_cpu(image->magic_number);
12408 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080012409 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070012410 fsize = be32_to_cpu(image->size);
12411
James Smart52d52442011-05-24 11:42:45 -040012412 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040012413 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040012414 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040012415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040012416 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040012417 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040012418 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040012419 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
12420 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
12421 GFP_KERNEL);
12422 if (!dmabuf) {
12423 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040012424 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040012425 }
12426 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
12427 SLI4_PAGE_SIZE,
12428 &dmabuf->phys,
12429 GFP_KERNEL);
12430 if (!dmabuf->virt) {
12431 kfree(dmabuf);
12432 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040012433 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040012434 }
12435 list_add_tail(&dmabuf->list, &dma_buffer_list);
12436 }
12437 while (offset < fw->size) {
12438 temp_offset = offset;
12439 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040012440 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040012441 memcpy(dmabuf->virt,
12442 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040012443 fw->size - temp_offset);
12444 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040012445 break;
12446 }
James Smart52d52442011-05-24 11:42:45 -040012447 memcpy(dmabuf->virt, fw->data + temp_offset,
12448 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040012449 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040012450 }
12451 rc = lpfc_wr_object(phba, &dma_buffer_list,
12452 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080012453 if (rc) {
12454 lpfc_log_write_firmware_error(phba, offset,
12455 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040012456 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080012457 }
James Smart52d52442011-05-24 11:42:45 -040012458 }
12459 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080012460 } else
12461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12462 "3029 Skipped Firmware update, Current "
12463 "Version:%s New Version:%s\n",
12464 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040012465
12466release_out:
James Smart52d52442011-05-24 11:42:45 -040012467 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
12468 list_del(&dmabuf->list);
12469 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
12470 dmabuf->virt, dmabuf->phys);
12471 kfree(dmabuf);
12472 }
James Smartce396282012-09-29 11:30:56 -040012473 release_firmware(fw);
12474out:
12475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040012476 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040012477 return;
James Smart52d52442011-05-24 11:42:45 -040012478}
12479
12480/**
James Smartc71ab862012-10-31 14:44:33 -040012481 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
12482 * @phba: pointer to lpfc hba data structure.
12483 *
12484 * This routine is called to perform Linux generic firmware upgrade on device
12485 * that supports such feature.
12486 **/
12487int
12488lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
12489{
12490 uint8_t file_name[ELX_MODEL_NAME_SIZE];
12491 int ret;
12492 const struct firmware *fw;
12493
12494 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080012495 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040012496 LPFC_SLI_INTF_IF_TYPE_2)
12497 return -EPERM;
12498
12499 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
12500
12501 if (fw_upgrade == INT_FW_UPGRADE) {
12502 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
12503 file_name, &phba->pcidev->dev,
12504 GFP_KERNEL, (void *)phba,
12505 lpfc_write_firmware);
12506 } else if (fw_upgrade == RUN_FW_UPGRADE) {
12507 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
12508 if (!ret)
12509 lpfc_write_firmware(fw, (void *)phba);
12510 } else {
12511 ret = -EINVAL;
12512 }
12513
12514 return ret;
12515}
12516
12517/**
James Smartda0436e2009-05-22 14:51:39 -040012518 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
12519 * @pdev: pointer to PCI device
12520 * @pid: pointer to PCI device identifier
12521 *
12522 * This routine is called from the kernel's PCI subsystem to device with
12523 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
12524 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12525 * information of the device and driver to see if the driver state that it
12526 * can support this kind of device. If the match is successful, the driver
12527 * core invokes this routine. If this routine determines it can claim the HBA,
12528 * it does all the initialization that it needs to do to handle the HBA
12529 * properly.
12530 *
12531 * Return code
12532 * 0 - driver can claim the device
12533 * negative value - driver can not claim the device
12534 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012535static int
James Smartda0436e2009-05-22 14:51:39 -040012536lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
12537{
12538 struct lpfc_hba *phba;
12539 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040012540 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070012541 int error;
James Smartda0436e2009-05-22 14:51:39 -040012542 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040012543
12544 /* Allocate memory for HBA structure */
12545 phba = lpfc_hba_alloc(pdev);
12546 if (!phba)
12547 return -ENOMEM;
12548
12549 /* Perform generic PCI device enabling operation */
12550 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040012551 if (error)
James Smartda0436e2009-05-22 14:51:39 -040012552 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040012553
12554 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
12555 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
12556 if (error)
12557 goto out_disable_pci_dev;
12558
12559 /* Set up SLI-4 specific device PCI memory space */
12560 error = lpfc_sli4_pci_mem_setup(phba);
12561 if (error) {
12562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12563 "1410 Failed to set up pci memory space.\n");
12564 goto out_disable_pci_dev;
12565 }
12566
James Smartda0436e2009-05-22 14:51:39 -040012567 /* Set up SLI-4 Specific device driver resources */
12568 error = lpfc_sli4_driver_resource_setup(phba);
12569 if (error) {
12570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12571 "1412 Failed to set up driver resource.\n");
12572 goto out_unset_pci_mem_s4;
12573 }
12574
James Smart19ca7602010-11-20 23:11:55 -050012575 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040012576 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050012577
James Smartda0436e2009-05-22 14:51:39 -040012578 /* Set up common device driver resources */
12579 error = lpfc_setup_driver_resource_phase2(phba);
12580 if (error) {
12581 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12582 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070012583 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040012584 }
12585
James Smart079b5c92011-08-21 21:48:49 -040012586 /* Get the default values for Model Name and Description */
12587 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
12588
James Smartda0436e2009-05-22 14:51:39 -040012589 /* Now, trying to enable interrupt and bring up the device */
12590 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040012591
James Smart7b15db32013-01-03 15:43:29 -050012592 /* Put device to a known state before enabling interrupt */
James Smartcdb42be2019-01-28 11:14:21 -080012593 phba->pport = NULL;
James Smart7b15db32013-01-03 15:43:29 -050012594 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080012595
James Smart7b15db32013-01-03 15:43:29 -050012596 /* Configure and enable interrupt */
12597 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
12598 if (intr_mode == LPFC_INTR_ERROR) {
12599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12600 "0426 Failed to enable interrupt.\n");
12601 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080012602 goto out_unset_driver_resource;
James Smartda0436e2009-05-22 14:51:39 -040012603 }
James Smart7b15db32013-01-03 15:43:29 -050012604 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080012605 if (phba->intr_type != MSIX) {
James Smart6a828b02019-01-28 11:14:31 -080012606 phba->cfg_irq_chann = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080012607 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -080012608 if (phba->nvmet_support)
12609 phba->cfg_nvmet_mrq = 1;
12610 }
James Smartcdb42be2019-01-28 11:14:21 -080012611 }
James Smart6a828b02019-01-28 11:14:31 -080012612 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
James Smartcdb42be2019-01-28 11:14:21 -080012613
12614 /* Create SCSI host to the physical port */
12615 error = lpfc_create_shost(phba);
12616 if (error) {
12617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12618 "1415 Failed to create scsi host.\n");
12619 goto out_disable_intr;
12620 }
12621 vport = phba->pport;
12622 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
12623
12624 /* Configure sysfs attributes */
12625 error = lpfc_alloc_sysfs_attr(vport);
12626 if (error) {
12627 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12628 "1416 Failed to allocate sysfs attr\n");
12629 goto out_destroy_shost;
James Smart895427b2017-02-12 13:52:30 -080012630 }
12631
James Smart7b15db32013-01-03 15:43:29 -050012632 /* Set up SLI-4 HBA */
12633 if (lpfc_sli4_hba_setup(phba)) {
12634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12635 "1421 Failed to set up hba\n");
12636 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080012637 goto out_free_sysfs_attr;
James Smart7b15db32013-01-03 15:43:29 -050012638 }
12639
12640 /* Log the current active interrupt mode */
12641 phba->intr_mode = intr_mode;
12642 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040012643
12644 /* Perform post initialization setup */
12645 lpfc_post_init_setup(phba);
12646
James Smart01649562017-02-12 13:52:32 -080012647 /* NVME support in FW earlier in the driver load corrects the
12648 * FC4 type making a check for nvme_support unnecessary.
12649 */
James Smart0794d602019-01-28 11:14:19 -080012650 if (phba->nvmet_support == 0) {
12651 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12652 /* Create NVME binding with nvme_fc_transport. This
12653 * ensures the vport is initialized. If the localport
12654 * create fails, it should not unload the driver to
12655 * support field issues.
12656 */
12657 error = lpfc_nvme_create_localport(vport);
12658 if (error) {
12659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12660 "6004 NVME registration "
12661 "failed, error x%x\n",
12662 error);
12663 }
James Smart01649562017-02-12 13:52:32 -080012664 }
12665 }
James Smart895427b2017-02-12 13:52:30 -080012666
James Smartc71ab862012-10-31 14:44:33 -040012667 /* check for firmware upgrade or downgrade */
12668 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040012669 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040012670
James Smart1c6834a2009-07-19 10:01:26 -040012671 /* Check if there are static vports to be created. */
12672 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070012673
12674 /* Enable RAS FW log support */
12675 lpfc_sli4_ras_setup(phba);
12676
James Smartda0436e2009-05-22 14:51:39 -040012677 return 0;
12678
James Smartda0436e2009-05-22 14:51:39 -040012679out_free_sysfs_attr:
12680 lpfc_free_sysfs_attr(vport);
12681out_destroy_shost:
12682 lpfc_destroy_shost(phba);
James Smartcdb42be2019-01-28 11:14:21 -080012683out_disable_intr:
12684 lpfc_sli4_disable_intr(phba);
James Smartda0436e2009-05-22 14:51:39 -040012685out_unset_driver_resource:
12686 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040012687out_unset_driver_resource_s4:
12688 lpfc_sli4_driver_resource_unset(phba);
12689out_unset_pci_mem_s4:
12690 lpfc_sli4_pci_mem_unset(phba);
12691out_disable_pci_dev:
12692 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040012693 if (shost)
12694 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040012695out_free_phba:
12696 lpfc_hba_free(phba);
12697 return error;
12698}
12699
12700/**
12701 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
12702 * @pdev: pointer to PCI device
12703 *
12704 * This routine is called from the kernel's PCI subsystem to device with
12705 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
12706 * removed from PCI bus, it performs all the necessary cleanup for the HBA
12707 * device to be removed from the PCI subsystem properly.
12708 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012709static void
James Smartda0436e2009-05-22 14:51:39 -040012710lpfc_pci_remove_one_s4(struct pci_dev *pdev)
12711{
12712 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
12714 struct lpfc_vport **vports;
12715 struct lpfc_hba *phba = vport->phba;
12716 int i;
12717
12718 /* Mark the device unloading flag */
12719 spin_lock_irq(&phba->hbalock);
12720 vport->load_flag |= FC_UNLOADING;
12721 spin_unlock_irq(&phba->hbalock);
12722
12723 /* Free the HBA sysfs attributes */
12724 lpfc_free_sysfs_attr(vport);
12725
12726 /* Release all the vports against this physical port */
12727 vports = lpfc_create_vport_work_array(phba);
12728 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040012729 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
12730 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
12731 continue;
James Smartda0436e2009-05-22 14:51:39 -040012732 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040012733 }
James Smartda0436e2009-05-22 14:51:39 -040012734 lpfc_destroy_vport_work_array(phba, vports);
12735
12736 /* Remove FC host and then SCSI host with the physical port */
12737 fc_remove_host(shost);
12738 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040012739
James Smartda0436e2009-05-22 14:51:39 -040012740 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
12741 * localports are destroyed after to cleanup all transport memory.
12742 */
12743 lpfc_cleanup(vport);
12744 lpfc_nvmet_destroy_targetport(phba);
12745 lpfc_nvme_destroy_localport(vport);
12746
James Smartc4908502019-01-28 11:14:28 -080012747 /* De-allocate multi-XRI pools */
12748 if (phba->cfg_xri_rebalancing)
12749 lpfc_destroy_multixri_pools(phba);
12750
James Smart281d6192018-01-30 15:58:47 -080012751 /*
12752 * Bring down the SLI Layer. This step disables all interrupts,
12753 * clears the rings, discards all mailbox commands, and resets
12754 * the HBA FCoE function.
12755 */
12756 lpfc_debugfs_terminate(vport);
James Smartda0436e2009-05-22 14:51:39 -040012757
Dick Kennedy19017622017-09-29 17:34:27 -070012758 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070012759 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040012760 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070012761 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040012762
James Smart3677a3a2010-09-29 11:19:14 -040012763 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040012764 * buffers are released to their corresponding pools here.
12765 */
James Smart5e5b5112019-01-28 11:14:22 -080012766 lpfc_io_free(phba);
James Smart01649562017-02-12 13:52:32 -080012767 lpfc_free_iocb_list(phba);
James Smart5e5b5112019-01-28 11:14:22 -080012768 lpfc_sli4_hba_unset(phba);
James Smart67d12732012-08-03 12:36:13 -040012769
James Smart0cdb84e2018-04-09 14:24:26 -070012770 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040012771 lpfc_sli4_driver_resource_unset(phba);
12772
12773 /* Unmap adapter Control and Doorbell registers */
12774 lpfc_sli4_pci_mem_unset(phba);
12775
12776 /* Release PCI resources and disable device's PCI function */
12777 scsi_host_put(shost);
12778 lpfc_disable_pci_dev(phba);
12779
12780 /* Finally, free the driver's device data structure */
12781 lpfc_hba_free(phba);
12782
12783 return;
12784}
12785
12786/**
12787 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
12788 * @pdev: pointer to PCI device
12789 * @msg: power management message
12790 *
12791 * This routine is called from the kernel's PCI subsystem to support system
12792 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
12793 * this method, it quiesces the device by stopping the driver's worker
12794 * thread for the device, turning off device's interrupt and DMA, and bring
12795 * the device offline. Note that as the driver implements the minimum PM
12796 * requirements to a power-aware driver's PM support for suspend/resume -- all
12797 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
12798 * method call will be treated as SUSPEND and the driver will fully
12799 * reinitialize its device during resume() method call, the driver will set
12800 * device to PCI_D3hot state in PCI config space instead of setting it
12801 * according to the @msg provided by the PM.
12802 *
12803 * Return code
12804 * 0 - driver suspended the device
12805 * Error otherwise
12806 **/
12807static int
12808lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
12809{
12810 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12811 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12812
12813 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040012814 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040012815
12816 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012817 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040012818 lpfc_offline(phba);
12819 kthread_stop(phba->worker_thread);
12820
12821 /* Disable interrupt from device */
12822 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012823 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040012824
12825 /* Save device state to PCI config space */
12826 pci_save_state(pdev);
12827 pci_set_power_state(pdev, PCI_D3hot);
12828
12829 return 0;
12830}
12831
12832/**
12833 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
12834 * @pdev: pointer to PCI device
12835 *
12836 * This routine is called from the kernel's PCI subsystem to support system
12837 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
12838 * this method, it restores the device's PCI config space state and fully
12839 * reinitializes the device and brings it online. Note that as the driver
12840 * implements the minimum PM requirements to a power-aware driver's PM for
12841 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12842 * to the suspend() method call will be treated as SUSPEND and the driver
12843 * will fully reinitialize its device during resume() method call, the device
12844 * will be set to PCI_D0 directly in PCI config space before restoring the
12845 * state.
12846 *
12847 * Return code
12848 * 0 - driver suspended the device
12849 * Error otherwise
12850 **/
12851static int
12852lpfc_pci_resume_one_s4(struct pci_dev *pdev)
12853{
12854 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12855 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12856 uint32_t intr_mode;
12857 int error;
12858
12859 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12860 "0292 PCI device Power Management resume.\n");
12861
12862 /* Restore device state from PCI config space */
12863 pci_set_power_state(pdev, PCI_D0);
12864 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012865
12866 /*
12867 * As the new kernel behavior of pci_restore_state() API call clears
12868 * device saved_state flag, need to save the restored state again.
12869 */
12870 pci_save_state(pdev);
12871
James Smartda0436e2009-05-22 14:51:39 -040012872 if (pdev->is_busmaster)
12873 pci_set_master(pdev);
12874
12875 /* Startup the kernel thread for this host adapter. */
12876 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12877 "lpfc_worker_%d", phba->brd_no);
12878 if (IS_ERR(phba->worker_thread)) {
12879 error = PTR_ERR(phba->worker_thread);
12880 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12881 "0293 PM resume failed to start worker "
12882 "thread: error=x%x.\n", error);
12883 return error;
12884 }
12885
12886 /* Configure and enable interrupt */
12887 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12888 if (intr_mode == LPFC_INTR_ERROR) {
12889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12890 "0294 PM resume Failed to enable interrupt\n");
12891 return -EIO;
12892 } else
12893 phba->intr_mode = intr_mode;
12894
12895 /* Restart HBA and bring it online */
12896 lpfc_sli_brdrestart(phba);
12897 lpfc_online(phba);
12898
12899 /* Log the current active interrupt mode */
12900 lpfc_log_intr_mode(phba, phba->intr_mode);
12901
12902 return 0;
12903}
12904
12905/**
James Smart75baf692010-06-08 18:31:21 -040012906 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
12907 * @phba: pointer to lpfc hba data structure.
12908 *
12909 * This routine is called to prepare the SLI4 device for PCI slot recover. It
12910 * aborts all the outstanding SCSI I/Os to the pci device.
12911 **/
12912static void
12913lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
12914{
James Smart75baf692010-06-08 18:31:21 -040012915 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12916 "2828 PCI channel I/O abort preparing for recovery\n");
12917 /*
12918 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12919 * and let the SCSI mid-layer to retry them to recover.
12920 */
James Smartdb55fba2014-04-04 13:52:02 -040012921 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012922}
12923
12924/**
12925 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
12926 * @phba: pointer to lpfc hba data structure.
12927 *
12928 * This routine is called to prepare the SLI4 device for PCI slot reset. It
12929 * disables the device interrupt and pci device, and aborts the internal FCP
12930 * pending I/Os.
12931 **/
12932static void
12933lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
12934{
12935 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12936 "2826 PCI channel disable preparing for reset\n");
12937
12938 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012939 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012940
12941 /* Block all SCSI devices' I/Os on the host */
12942 lpfc_scsi_dev_block(phba);
12943
James Smartea714f32013-04-17 20:18:47 -040012944 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12945 lpfc_sli_flush_fcp_rings(phba);
12946
James Smartc3725bd2017-11-20 16:00:42 -080012947 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12948 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12949 lpfc_sli_flush_nvme_rings(phba);
12950
James Smart75baf692010-06-08 18:31:21 -040012951 /* stop all timers */
12952 lpfc_stop_hba_timers(phba);
12953
12954 /* Disable interrupt and pci device */
12955 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012956 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012957 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012958}
12959
12960/**
12961 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12962 * @phba: pointer to lpfc hba data structure.
12963 *
12964 * This routine is called to prepare the SLI4 device for PCI slot permanently
12965 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12966 * pending I/Os.
12967 **/
12968static void
12969lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12970{
12971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12972 "2827 PCI channel permanent disable for failure\n");
12973
12974 /* Block all SCSI devices' I/Os on the host */
12975 lpfc_scsi_dev_block(phba);
12976
12977 /* stop all timers */
12978 lpfc_stop_hba_timers(phba);
12979
12980 /* Clean up all driver's outstanding SCSI I/Os */
12981 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012982
12983 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12984 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12985 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012986}
12987
12988/**
James Smartda0436e2009-05-22 14:51:39 -040012989 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12990 * @pdev: pointer to PCI device.
12991 * @state: the current PCI connection state.
12992 *
12993 * This routine is called from the PCI subsystem for error handling to device
12994 * with SLI-4 interface spec. This function is called by the PCI subsystem
12995 * after a PCI bus error affecting this device has been detected. When this
12996 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12997 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12998 * for the PCI subsystem to perform proper recovery as desired.
12999 *
13000 * Return codes
13001 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13002 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13003 **/
13004static pci_ers_result_t
13005lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
13006{
James Smart75baf692010-06-08 18:31:21 -040013007 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13008 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13009
13010 switch (state) {
13011 case pci_channel_io_normal:
13012 /* Non-fatal error, prepare for recovery */
13013 lpfc_sli4_prep_dev_for_recover(phba);
13014 return PCI_ERS_RESULT_CAN_RECOVER;
13015 case pci_channel_io_frozen:
13016 /* Fatal error, prepare for slot reset */
13017 lpfc_sli4_prep_dev_for_reset(phba);
13018 return PCI_ERS_RESULT_NEED_RESET;
13019 case pci_channel_io_perm_failure:
13020 /* Permanent failure, prepare for device down */
13021 lpfc_sli4_prep_dev_for_perm_failure(phba);
13022 return PCI_ERS_RESULT_DISCONNECT;
13023 default:
13024 /* Unknown state, prepare and request slot reset */
13025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13026 "2825 Unknown PCI error state: x%x\n", state);
13027 lpfc_sli4_prep_dev_for_reset(phba);
13028 return PCI_ERS_RESULT_NEED_RESET;
13029 }
James Smartda0436e2009-05-22 14:51:39 -040013030}
13031
13032/**
13033 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
13034 * @pdev: pointer to PCI device.
13035 *
13036 * This routine is called from the PCI subsystem for error handling to device
13037 * with SLI-4 interface spec. It is called after PCI bus has been reset to
13038 * restart the PCI card from scratch, as if from a cold-boot. During the
13039 * PCI subsystem error recovery, after the driver returns
13040 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13041 * recovery and then call this routine before calling the .resume method to
13042 * recover the device. This function will initialize the HBA device, enable
13043 * the interrupt, but it will just put the HBA to offline state without
13044 * passing any I/O traffic.
13045 *
13046 * Return codes
13047 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13048 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13049 */
13050static pci_ers_result_t
13051lpfc_io_slot_reset_s4(struct pci_dev *pdev)
13052{
James Smart75baf692010-06-08 18:31:21 -040013053 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13054 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13055 struct lpfc_sli *psli = &phba->sli;
13056 uint32_t intr_mode;
13057
13058 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
13059 if (pci_enable_device_mem(pdev)) {
13060 printk(KERN_ERR "lpfc: Cannot re-enable "
13061 "PCI device after reset.\n");
13062 return PCI_ERS_RESULT_DISCONNECT;
13063 }
13064
13065 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040013066
13067 /*
13068 * As the new kernel behavior of pci_restore_state() API call clears
13069 * device saved_state flag, need to save the restored state again.
13070 */
13071 pci_save_state(pdev);
13072
James Smart75baf692010-06-08 18:31:21 -040013073 if (pdev->is_busmaster)
13074 pci_set_master(pdev);
13075
13076 spin_lock_irq(&phba->hbalock);
13077 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
13078 spin_unlock_irq(&phba->hbalock);
13079
13080 /* Configure and enable interrupt */
13081 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13082 if (intr_mode == LPFC_INTR_ERROR) {
13083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13084 "2824 Cannot re-enable interrupt after "
13085 "slot reset.\n");
13086 return PCI_ERS_RESULT_DISCONNECT;
13087 } else
13088 phba->intr_mode = intr_mode;
13089
13090 /* Log the current active interrupt mode */
13091 lpfc_log_intr_mode(phba, phba->intr_mode);
13092
James Smartda0436e2009-05-22 14:51:39 -040013093 return PCI_ERS_RESULT_RECOVERED;
13094}
13095
13096/**
13097 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
13098 * @pdev: pointer to PCI device
13099 *
13100 * This routine is called from the PCI subsystem for error handling to device
13101 * with SLI-4 interface spec. It is called when kernel error recovery tells
13102 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13103 * error recovery. After this call, traffic can start to flow from this device
13104 * again.
13105 **/
13106static void
13107lpfc_io_resume_s4(struct pci_dev *pdev)
13108{
James Smart75baf692010-06-08 18:31:21 -040013109 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13110 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13111
13112 /*
13113 * In case of slot reset, as function reset is performed through
13114 * mailbox command which needs DMA to be enabled, this operation
13115 * has to be moved to the io resume phase. Taking device offline
13116 * will perform the necessary cleanup.
13117 */
13118 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
13119 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040013120 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040013121 lpfc_offline(phba);
13122 lpfc_sli_brdrestart(phba);
13123 /* Bring the device back online */
13124 lpfc_online(phba);
13125 }
James Smartda0436e2009-05-22 14:51:39 -040013126}
13127
13128/**
James Smart3772a992009-05-22 14:50:54 -040013129 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
13130 * @pdev: pointer to PCI device
13131 * @pid: pointer to PCI device identifier
13132 *
13133 * This routine is to be registered to the kernel's PCI subsystem. When an
13134 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
13135 * at PCI device-specific information of the device and driver to see if the
13136 * driver state that it can support this kind of device. If the match is
13137 * successful, the driver core invokes this routine. This routine dispatches
13138 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
13139 * do all the initialization that it needs to do to handle the HBA device
13140 * properly.
13141 *
13142 * Return code
13143 * 0 - driver can claim the device
13144 * negative value - driver can not claim the device
13145 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013146static int
James Smart3772a992009-05-22 14:50:54 -040013147lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
13148{
13149 int rc;
James Smart8fa38512009-07-19 10:01:03 -040013150 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040013151
James Smart28baac72010-02-12 14:42:03 -050013152 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040013153 return -ENODEV;
13154
James Smart8fa38512009-07-19 10:01:03 -040013155 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050013156 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040013157 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013158 else
James Smart3772a992009-05-22 14:50:54 -040013159 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013160
James Smart3772a992009-05-22 14:50:54 -040013161 return rc;
13162}
13163
13164/**
13165 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
13166 * @pdev: pointer to PCI device
13167 *
13168 * This routine is to be registered to the kernel's PCI subsystem. When an
13169 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
13170 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
13171 * remove routine, which will perform all the necessary cleanup for the
13172 * device to be removed from the PCI subsystem properly.
13173 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013174static void
James Smart3772a992009-05-22 14:50:54 -040013175lpfc_pci_remove_one(struct pci_dev *pdev)
13176{
13177 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13178 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13179
13180 switch (phba->pci_dev_grp) {
13181 case LPFC_PCI_DEV_LP:
13182 lpfc_pci_remove_one_s3(pdev);
13183 break;
James Smartda0436e2009-05-22 14:51:39 -040013184 case LPFC_PCI_DEV_OC:
13185 lpfc_pci_remove_one_s4(pdev);
13186 break;
James Smart3772a992009-05-22 14:50:54 -040013187 default:
13188 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13189 "1424 Invalid PCI device group: 0x%x\n",
13190 phba->pci_dev_grp);
13191 break;
13192 }
13193 return;
13194}
13195
13196/**
13197 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
13198 * @pdev: pointer to PCI device
13199 * @msg: power management message
13200 *
13201 * This routine is to be registered to the kernel's PCI subsystem to support
13202 * system Power Management (PM). When PM invokes this method, it dispatches
13203 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
13204 * suspend the device.
13205 *
13206 * Return code
13207 * 0 - driver suspended the device
13208 * Error otherwise
13209 **/
13210static int
13211lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
13212{
13213 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13214 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13215 int rc = -ENODEV;
13216
13217 switch (phba->pci_dev_grp) {
13218 case LPFC_PCI_DEV_LP:
13219 rc = lpfc_pci_suspend_one_s3(pdev, msg);
13220 break;
James Smartda0436e2009-05-22 14:51:39 -040013221 case LPFC_PCI_DEV_OC:
13222 rc = lpfc_pci_suspend_one_s4(pdev, msg);
13223 break;
James Smart3772a992009-05-22 14:50:54 -040013224 default:
13225 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13226 "1425 Invalid PCI device group: 0x%x\n",
13227 phba->pci_dev_grp);
13228 break;
13229 }
13230 return rc;
13231}
13232
13233/**
13234 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
13235 * @pdev: pointer to PCI device
13236 *
13237 * This routine is to be registered to the kernel's PCI subsystem to support
13238 * system Power Management (PM). When PM invokes this method, it dispatches
13239 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
13240 * resume the device.
13241 *
13242 * Return code
13243 * 0 - driver suspended the device
13244 * Error otherwise
13245 **/
13246static int
13247lpfc_pci_resume_one(struct pci_dev *pdev)
13248{
13249 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13250 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13251 int rc = -ENODEV;
13252
13253 switch (phba->pci_dev_grp) {
13254 case LPFC_PCI_DEV_LP:
13255 rc = lpfc_pci_resume_one_s3(pdev);
13256 break;
James Smartda0436e2009-05-22 14:51:39 -040013257 case LPFC_PCI_DEV_OC:
13258 rc = lpfc_pci_resume_one_s4(pdev);
13259 break;
James Smart3772a992009-05-22 14:50:54 -040013260 default:
13261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13262 "1426 Invalid PCI device group: 0x%x\n",
13263 phba->pci_dev_grp);
13264 break;
13265 }
13266 return rc;
13267}
13268
13269/**
13270 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
13271 * @pdev: pointer to PCI device.
13272 * @state: the current PCI connection state.
13273 *
13274 * This routine is registered to the PCI subsystem for error handling. This
13275 * function is called by the PCI subsystem after a PCI bus error affecting
13276 * this device has been detected. When this routine is invoked, it dispatches
13277 * the action to the proper SLI-3 or SLI-4 device error detected handling
13278 * routine, which will perform the proper error detected operation.
13279 *
13280 * Return codes
13281 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13282 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13283 **/
13284static pci_ers_result_t
13285lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
13286{
13287 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13288 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13289 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13290
13291 switch (phba->pci_dev_grp) {
13292 case LPFC_PCI_DEV_LP:
13293 rc = lpfc_io_error_detected_s3(pdev, state);
13294 break;
James Smartda0436e2009-05-22 14:51:39 -040013295 case LPFC_PCI_DEV_OC:
13296 rc = lpfc_io_error_detected_s4(pdev, state);
13297 break;
James Smart3772a992009-05-22 14:50:54 -040013298 default:
13299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13300 "1427 Invalid PCI device group: 0x%x\n",
13301 phba->pci_dev_grp);
13302 break;
13303 }
13304 return rc;
13305}
13306
13307/**
13308 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
13309 * @pdev: pointer to PCI device.
13310 *
13311 * This routine is registered to the PCI subsystem for error handling. This
13312 * function is called after PCI bus has been reset to restart the PCI card
13313 * from scratch, as if from a cold-boot. When this routine is invoked, it
13314 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
13315 * routine, which will perform the proper device reset.
13316 *
13317 * Return codes
13318 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13319 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13320 **/
13321static pci_ers_result_t
13322lpfc_io_slot_reset(struct pci_dev *pdev)
13323{
13324 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13325 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13326 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13327
13328 switch (phba->pci_dev_grp) {
13329 case LPFC_PCI_DEV_LP:
13330 rc = lpfc_io_slot_reset_s3(pdev);
13331 break;
James Smartda0436e2009-05-22 14:51:39 -040013332 case LPFC_PCI_DEV_OC:
13333 rc = lpfc_io_slot_reset_s4(pdev);
13334 break;
James Smart3772a992009-05-22 14:50:54 -040013335 default:
13336 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13337 "1428 Invalid PCI device group: 0x%x\n",
13338 phba->pci_dev_grp);
13339 break;
13340 }
13341 return rc;
13342}
13343
13344/**
13345 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
13346 * @pdev: pointer to PCI device
13347 *
13348 * This routine is registered to the PCI subsystem for error handling. It
13349 * is called when kernel error recovery tells the lpfc driver that it is
13350 * OK to resume normal PCI operation after PCI bus error recovery. When
13351 * this routine is invoked, it dispatches the action to the proper SLI-3
13352 * or SLI-4 device io_resume routine, which will resume the device operation.
13353 **/
13354static void
13355lpfc_io_resume(struct pci_dev *pdev)
13356{
13357 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13358 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13359
13360 switch (phba->pci_dev_grp) {
13361 case LPFC_PCI_DEV_LP:
13362 lpfc_io_resume_s3(pdev);
13363 break;
James Smartda0436e2009-05-22 14:51:39 -040013364 case LPFC_PCI_DEV_OC:
13365 lpfc_io_resume_s4(pdev);
13366 break;
James Smart3772a992009-05-22 14:50:54 -040013367 default:
13368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13369 "1429 Invalid PCI device group: 0x%x\n",
13370 phba->pci_dev_grp);
13371 break;
13372 }
13373 return;
13374}
13375
James Smart1ba981f2014-02-20 09:56:45 -050013376/**
13377 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
13378 * @phba: pointer to lpfc hba data structure.
13379 *
13380 * This routine checks to see if OAS is supported for this adapter. If
13381 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
13382 * the enable oas flag is cleared and the pool created for OAS device data
13383 * is destroyed.
13384 *
13385 **/
YueHaibingc7092972019-04-17 23:05:54 +080013386static void
James Smart1ba981f2014-02-20 09:56:45 -050013387lpfc_sli4_oas_verify(struct lpfc_hba *phba)
13388{
13389
13390 if (!phba->cfg_EnableXLane)
13391 return;
13392
13393 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
13394 phba->cfg_fof = 1;
13395 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040013396 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050013397 if (phba->device_data_mem_pool)
13398 mempool_destroy(phba->device_data_mem_pool);
13399 phba->device_data_mem_pool = NULL;
13400 }
13401
13402 return;
13403}
13404
13405/**
James Smartd2cc9bc2018-09-10 10:30:50 -070013406 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
13407 * @phba: pointer to lpfc hba data structure.
13408 *
13409 * This routine checks to see if RAS is supported by the adapter. Check the
13410 * function through which RAS support enablement is to be done.
13411 **/
13412void
13413lpfc_sli4_ras_init(struct lpfc_hba *phba)
13414{
13415 switch (phba->pcidev->device) {
13416 case PCI_DEVICE_ID_LANCER_G6_FC:
13417 case PCI_DEVICE_ID_LANCER_G7_FC:
13418 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080013419 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
13420 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070013421 phba->ras_fwlog.ras_enabled = true;
13422 else
13423 phba->ras_fwlog.ras_enabled = false;
13424 break;
13425 default:
13426 phba->ras_fwlog.ras_hwsupport = false;
13427 }
13428}
13429
James Smart1ba981f2014-02-20 09:56:45 -050013430
dea31012005-04-17 16:05:31 -050013431MODULE_DEVICE_TABLE(pci, lpfc_id_table);
13432
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070013433static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060013434 .error_detected = lpfc_io_error_detected,
13435 .slot_reset = lpfc_io_slot_reset,
13436 .resume = lpfc_io_resume,
13437};
13438
dea31012005-04-17 16:05:31 -050013439static struct pci_driver lpfc_driver = {
13440 .name = LPFC_DRIVER_NAME,
13441 .id_table = lpfc_id_table,
13442 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013443 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110013444 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050013445 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040013446 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050013447 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050013448};
13449
James Smart3ef6d242012-01-18 16:23:48 -050013450static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040013451 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050013452};
13453
13454static struct miscdevice lpfc_mgmt_dev = {
13455 .minor = MISC_DYNAMIC_MINOR,
13456 .name = "lpfcmgmt",
13457 .fops = &lpfc_mgmt_fop,
13458};
13459
James Smarte59058c2008-08-24 21:49:00 -040013460/**
James Smart3621a712009-04-06 18:47:14 -040013461 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040013462 *
13463 * This routine is to be invoked when the lpfc module is loaded into the
13464 * kernel. The special kernel macro module_init() is used to indicate the
13465 * role of this routine to the kernel as lpfc module entry point.
13466 *
13467 * Return codes
13468 * 0 - successful
13469 * -ENOMEM - FC attach transport failed
13470 * all others - failed
13471 */
dea31012005-04-17 16:05:31 -050013472static int __init
13473lpfc_init(void)
13474{
13475 int error = 0;
13476
13477 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040013478 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050013479
James Smart3ef6d242012-01-18 16:23:48 -050013480 error = misc_register(&lpfc_mgmt_dev);
13481 if (error)
13482 printk(KERN_ERR "Could not register lpfcmgmt device, "
13483 "misc_register returned with status %d", error);
13484
James Smart458c0832016-07-06 12:36:07 -070013485 lpfc_transport_functions.vport_create = lpfc_vport_create;
13486 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050013487 lpfc_transport_template =
13488 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040013489 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050013490 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070013491 lpfc_vport_transport_template =
13492 fc_attach_transport(&lpfc_vport_transport_functions);
13493 if (lpfc_vport_transport_template == NULL) {
13494 fc_release_transport(lpfc_transport_template);
13495 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040013496 }
James Smart5fd11082018-03-05 12:04:04 -080013497 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080013498 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040013499
13500 /* Initialize in case vector mapping is needed */
James Smart2ea259e2017-02-12 13:52:27 -080013501 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040013502
dea31012005-04-17 16:05:31 -050013503 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050013504 if (error) {
dea31012005-04-17 16:05:31 -050013505 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070013506 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050013507 }
dea31012005-04-17 16:05:31 -050013508
13509 return error;
13510}
13511
James Smarte59058c2008-08-24 21:49:00 -040013512/**
James Smart3621a712009-04-06 18:47:14 -040013513 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040013514 *
13515 * This routine is invoked when the lpfc module is removed from the kernel.
13516 * The special kernel macro module_exit() is used to indicate the role of
13517 * this routine to the kernel as lpfc module exit point.
13518 */
dea31012005-04-17 16:05:31 -050013519static void __exit
13520lpfc_exit(void)
13521{
James Smart3ef6d242012-01-18 16:23:48 -050013522 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050013523 pci_unregister_driver(&lpfc_driver);
13524 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070013525 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050013526 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040013527 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
13528 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050013529 (1L << _dump_buf_data_order), _dump_buf_data);
13530 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
13531 }
13532
13533 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040013534 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
13535 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050013536 (1L << _dump_buf_dif_order), _dump_buf_dif);
13537 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
13538 }
Johannes Thumshirn79739672015-08-31 16:48:11 -040013539 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050013540}
13541
13542module_init(lpfc_init);
13543module_exit(lpfc_exit);
13544MODULE_LICENSE("GPL");
13545MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080013546MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050013547MODULE_VERSION("0:" LPFC_DRIVER_VERSION);