blob: a7549ae32542738cce6a8c4011911f1462ff09d1 [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>
dea31012005-04-17 16:05:31 -050042
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040043#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050044#include <scsi/scsi_device.h>
45#include <scsi/scsi_host.h>
46#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070047#include <scsi/scsi_tcq.h>
48#include <scsi/fc/fc_fs.h>
49
50#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050051
James Smartda0436e2009-05-22 14:51:39 -040052#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050053#include "lpfc_hw.h"
54#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040055#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040056#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050058#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080059#include "lpfc_scsi.h"
60#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070061#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050062#include "lpfc_logmsg.h"
63#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050064#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050065#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070066#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050067
James Smart81301a92008-12-04 22:39:46 -050068char *_dump_buf_data;
69unsigned long _dump_buf_data_order;
70char *_dump_buf_dif;
71unsigned long _dump_buf_dif_order;
72spinlock_t _dump_buf_lock;
73
James Smart7bb03bb2013-04-17 20:19:16 -040074/* Used when mapping IRQ vectors in a driver centric manner */
YueHaibingd7b761b2019-05-31 23:28:41 +080075static uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040076
dea31012005-04-17 16:05:31 -050077static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040079static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040082static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080084static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040085static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040086static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87static void lpfc_free_active_sgl(struct lpfc_hba *);
88static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040093static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050095static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
James Smart6a828b02019-01-28 11:14:31 -080096static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
James Smartaa6ff302019-05-21 17:49:09 -070097static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
dea31012005-04-17 16:05:31 -050098
99static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500100static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -0500101static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800102#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500103
James Smarte59058c2008-08-24 21:49:00 -0400104/**
James Smart3621a712009-04-06 18:47:14 -0400105 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400106 * @phba: pointer to lpfc hba data structure.
107 *
108 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
109 * mailbox command. It retrieves the revision information from the HBA and
110 * collects the Vital Product Data (VPD) about the HBA for preparing the
111 * configuration of the HBA.
112 *
113 * Return codes:
114 * 0 - success.
115 * -ERESTART - requests the SLI layer to reset the HBA and try again.
116 * Any other value - indicates an error.
117 **/
dea31012005-04-17 16:05:31 -0500118int
James Smart2e0fef82007-06-17 19:56:36 -0500119lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500120{
121 lpfc_vpd_t *vp = &phba->vpd;
122 int i = 0, rc;
123 LPFC_MBOXQ_t *pmb;
124 MAILBOX_t *mb;
125 char *lpfc_vpd_data = NULL;
126 uint16_t offset = 0;
127 static char licensed[56] =
128 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400129 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500130
131 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
132 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500133 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500134 return -ENOMEM;
135 }
136
James Smart04c68492009-05-22 14:52:52 -0400137 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500138 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500139
140 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400141 if (init_key) {
142 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500143
James Smart65a29c12006-07-06 15:50:50 -0400144 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
145 *ptext = cpu_to_be32(*ptext);
146 init_key = 0;
147 }
dea31012005-04-17 16:05:31 -0500148
149 lpfc_read_nv(phba, pmb);
150 memset((char*)mb->un.varRDnvp.rsvd3, 0,
151 sizeof (mb->un.varRDnvp.rsvd3));
152 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
153 sizeof (licensed));
154
155 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
156
157 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500158 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400159 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500160 "error, mbxCmd x%x READ_NVPARM, "
161 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500162 mb->mbxCommand, mb->mbxStatus);
163 mempool_free(pmb, phba->mbox_mem_pool);
164 return -ERESTART;
165 }
166 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500167 sizeof(phba->wwnn));
168 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
169 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500170 }
171
Martin Wilckdfb75132018-11-12 09:58:37 +0100172 /*
173 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
174 * which was already set in lpfc_get_cfgparam()
175 */
176 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500177
dea31012005-04-17 16:05:31 -0500178 /* Setup and issue mailbox READ REV command */
179 lpfc_read_rev(phba, pmb);
180 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
181 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500182 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400183 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500184 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500185 mb->mbxCommand, mb->mbxStatus);
186 mempool_free( pmb, phba->mbox_mem_pool);
187 return -ERESTART;
188 }
189
James Smart92d7f7b2007-06-17 19:56:38 -0500190
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 /*
192 * The value of rr must be 1 since the driver set the cv field to 1.
193 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500194 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500195 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500196 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400198 "0440 Adapter failed to init, READ_REV has "
199 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500200 mempool_free(pmb, phba->mbox_mem_pool);
201 return -ERESTART;
dea31012005-04-17 16:05:31 -0500202 }
203
James Smart495a7142008-06-14 22:52:59 -0400204 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
205 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500206 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400207 }
James Smarted957682007-06-17 19:56:37 -0500208
dea31012005-04-17 16:05:31 -0500209 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500210 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500211 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500212 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
213 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
214 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
215 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500216 vp->rev.biuRev = mb->un.varRdRev.biuRev;
217 vp->rev.smRev = mb->un.varRdRev.smRev;
218 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
219 vp->rev.endecRev = mb->un.varRdRev.endecRev;
220 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
221 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
222 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
223 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
224 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
225 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
226
James Smart92d7f7b2007-06-17 19:56:38 -0500227 /* If the sli feature level is less then 9, we must
228 * tear down all RPIs and VPIs on link down if NPIV
229 * is enabled.
230 */
231 if (vp->rev.feaLevelHigh < 9)
232 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
233
dea31012005-04-17 16:05:31 -0500234 if (lpfc_is_LC_HBA(phba->pcidev->device))
235 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
236 sizeof (phba->RandomData));
237
dea31012005-04-17 16:05:31 -0500238 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500239 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
240 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400241 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500242 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400243 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500244 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
245
246 if (rc != MBX_SUCCESS) {
247 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400248 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500249 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500250 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500251 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500252 }
James Smart04c68492009-05-22 14:52:52 -0400253 /* dump mem may return a zero when finished or we got a
254 * mailbox error, either way we are done.
255 */
256 if (mb->un.varDmp.word_cnt == 0)
257 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500258 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
259 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400260 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
261 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500262 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500263 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500264 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
265 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500266
267 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500268out_free_mbox:
269 mempool_free(pmb, phba->mbox_mem_pool);
270 return 0;
271}
272
James Smarte59058c2008-08-24 21:49:00 -0400273/**
James Smart3621a712009-04-06 18:47:14 -0400274 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400275 * @phba: pointer to lpfc hba data structure.
276 * @pmboxq: pointer to the driver internal queue element for mailbox command.
277 *
278 * This is the completion handler for driver's configuring asynchronous event
279 * mailbox command to the device. If the mailbox command returns successfully,
280 * it will set internal async event support flag to 1; otherwise, it will
281 * set internal async event support flag to 0.
282 **/
James Smart57127f12007-10-27 13:37:05 -0400283static void
284lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
285{
James Smart04c68492009-05-22 14:52:52 -0400286 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400287 phba->temp_sensor_support = 1;
288 else
289 phba->temp_sensor_support = 0;
290 mempool_free(pmboxq, phba->mbox_mem_pool);
291 return;
292}
293
James Smarte59058c2008-08-24 21:49:00 -0400294/**
James Smart3621a712009-04-06 18:47:14 -0400295 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500296 * @phba: pointer to lpfc hba data structure.
297 * @pmboxq: pointer to the driver internal queue element for mailbox command.
298 *
299 * This is the completion handler for dump mailbox command for getting
300 * wake up parameters. When this command complete, the response contain
301 * Option rom version of the HBA. This function translate the version number
302 * into a human readable string and store it in OptionROMVersion.
303 **/
304static void
305lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
306{
307 struct prog_id *prg;
308 uint32_t prog_id_word;
309 char dist = ' ';
310 /* character array used for decoding dist type. */
311 char dist_char[] = "nabx";
312
James Smart04c68492009-05-22 14:52:52 -0400313 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500314 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500315 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500316 }
James Smart97207482008-12-04 22:39:19 -0500317
318 prg = (struct prog_id *) &prog_id_word;
319
320 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400321 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500322
323 /* Decode the Option rom version word to a readable string */
324 if (prg->dist < 4)
325 dist = dist_char[prg->dist];
326
327 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400328 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500329 prg->ver, prg->rev, prg->lev);
330 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400331 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500332 prg->ver, prg->rev, prg->lev,
333 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500334 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500335 return;
336}
337
338/**
James Smart05580562011-05-24 11:40:48 -0400339 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
340 * cfg_soft_wwnn, cfg_soft_wwpn
341 * @vport: pointer to lpfc vport data structure.
342 *
343 *
344 * Return codes
345 * None.
346 **/
347void
348lpfc_update_vport_wwn(struct lpfc_vport *vport)
349{
James Smartaeb3c812017-04-21 16:05:02 -0700350 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
351 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
352
James Smart05580562011-05-24 11:40:48 -0400353 /* If the soft name exists then update it using the service params */
354 if (vport->phba->cfg_soft_wwnn)
355 u64_to_wwn(vport->phba->cfg_soft_wwnn,
356 vport->fc_sparam.nodeName.u.wwn);
357 if (vport->phba->cfg_soft_wwpn)
358 u64_to_wwn(vport->phba->cfg_soft_wwpn,
359 vport->fc_sparam.portName.u.wwn);
360
361 /*
362 * If the name is empty or there exists a soft name
363 * then copy the service params name, otherwise use the fc name
364 */
365 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
366 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
367 sizeof(struct lpfc_name));
368 else
369 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
370 sizeof(struct lpfc_name));
371
James Smartaeb3c812017-04-21 16:05:02 -0700372 /*
373 * If the port name has changed, then set the Param changes flag
374 * to unreg the login
375 */
376 if (vport->fc_portname.u.wwn[0] != 0 &&
377 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
378 sizeof(struct lpfc_name)))
379 vport->vport_flag |= FAWWPN_PARAM_CHG;
380
381 if (vport->fc_portname.u.wwn[0] == 0 ||
382 vport->phba->cfg_soft_wwpn ||
383 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
384 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400385 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
386 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700387 vport->vport_flag &= ~FAWWPN_SET;
388 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
389 vport->vport_flag |= FAWWPN_SET;
390 }
James Smart05580562011-05-24 11:40:48 -0400391 else
392 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
393 sizeof(struct lpfc_name));
394}
395
396/**
James Smart3621a712009-04-06 18:47:14 -0400397 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400398 * @phba: pointer to lpfc hba data structure.
399 *
400 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
401 * command call. It performs all internal resource and state setups on the
402 * port: post IOCB buffers, enable appropriate host interrupt attentions,
403 * ELS ring timers, etc.
404 *
405 * Return codes
406 * 0 - success.
407 * Any other value - error.
408 **/
dea31012005-04-17 16:05:31 -0500409int
James Smart2e0fef82007-06-17 19:56:36 -0500410lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500414 LPFC_MBOXQ_t *pmb;
415 MAILBOX_t *mb;
416 struct lpfc_dmabuf *mp;
417 struct lpfc_sli *psli = &phba->sli;
418 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500419 int i, j;
420 int rc;
dea31012005-04-17 16:05:31 -0500421
James Smart7af67052007-10-27 13:38:11 -0400422 spin_lock_irq(&phba->hbalock);
423 /*
424 * If the Config port completed correctly the HBA is not
425 * over heated any more.
426 */
427 if (phba->over_temp_state == HBA_OVER_TEMP)
428 phba->over_temp_state = HBA_NORMAL_TEMP;
429 spin_unlock_irq(&phba->hbalock);
430
dea31012005-04-17 16:05:31 -0500431 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
432 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500433 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500434 return -ENOMEM;
435 }
James Smart04c68492009-05-22 14:52:52 -0400436 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500437
dea31012005-04-17 16:05:31 -0500438 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500439 rc = lpfc_read_sparam(phba, pmb, 0);
440 if (rc) {
441 mempool_free(pmb, phba->mbox_mem_pool);
442 return -ENOMEM;
443 }
444
James Smarted957682007-06-17 19:56:37 -0500445 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500446 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400448 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500449 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500450 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500451 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800452 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -0500453 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500454 lpfc_mbuf_free(phba, mp->virt, mp->phys);
455 kfree(mp);
456 return -EIO;
457 }
458
James Smart3e1f0712018-11-29 16:09:29 -0800459 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500460
James Smart2e0fef82007-06-17 19:56:36 -0500461 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500462 lpfc_mbuf_free(phba, mp->virt, mp->phys);
463 kfree(mp);
James Smart3e1f0712018-11-29 16:09:29 -0800464 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400465 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400466
467 /* Update the fc_host data structures with new wwn. */
468 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
469 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400470 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400471
dea31012005-04-17 16:05:31 -0500472 /* If no serial number in VPD data, use low 6 bytes of WWNN */
473 /* This should be consolidated into parse_vpd ? - mr */
474 if (phba->SerialNumber[0] == 0) {
475 uint8_t *outptr;
476
James Smart2e0fef82007-06-17 19:56:36 -0500477 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500478 for (i = 0; i < 12; i++) {
479 status = *outptr++;
480 j = ((status & 0xf0) >> 4);
481 if (j <= 9)
482 phba->SerialNumber[i] =
483 (char)((uint8_t) 0x30 + (uint8_t) j);
484 else
485 phba->SerialNumber[i] =
486 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
487 i++;
488 j = (status & 0xf);
489 if (j <= 9)
490 phba->SerialNumber[i] =
491 (char)((uint8_t) 0x30 + (uint8_t) j);
492 else
493 phba->SerialNumber[i] =
494 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
495 }
496 }
497
dea31012005-04-17 16:05:31 -0500498 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500499 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500500 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400502 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500503 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500504 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500505 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500506 mempool_free( pmb, phba->mbox_mem_pool);
507 return -EIO;
508 }
509
James Smarta0c87cb2009-07-19 10:01:10 -0400510 /* Check if the port is disabled */
511 lpfc_sli_read_link_ste(phba);
512
dea31012005-04-17 16:05:31 -0500513 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400514 i = (mb->un.varRdConfig.max_xri + 1);
515 if (phba->cfg_hba_queue_depth > i) {
516 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
517 "3359 HBA queue depth changed from %d to %d\n",
518 phba->cfg_hba_queue_depth, i);
519 phba->cfg_hba_queue_depth = i;
520 }
521
522 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
523 i = (mb->un.varRdConfig.max_xri >> 3);
524 if (phba->pport->cfg_lun_queue_depth > i) {
525 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
526 "3360 LUN queue depth changed from %d to %d\n",
527 phba->pport->cfg_lun_queue_depth, i);
528 phba->pport->cfg_lun_queue_depth = i;
529 }
dea31012005-04-17 16:05:31 -0500530
531 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500532
533 /* Get the default values for Model Name and Description */
534 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
535
James Smart2e0fef82007-06-17 19:56:36 -0500536 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500537
James Smart0b727fe2007-10-27 13:37:25 -0400538 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800539 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
540 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
541 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
542 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500543
544 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500545 if (phba->sli_rev != 3)
546 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500547
James Smart93996272008-08-24 21:50:30 -0400548 /*
549 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
550 */
551 if (phba->intr_type == MSIX) {
552 rc = lpfc_config_msi(phba, pmb);
553 if (rc) {
554 mempool_free(pmb, phba->mbox_mem_pool);
555 return -EIO;
556 }
557 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
558 if (rc != MBX_SUCCESS) {
559 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
560 "0352 Config MSI mailbox command "
561 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400562 pmb->u.mb.mbxCommand,
563 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400564 mempool_free(pmb, phba->mbox_mem_pool);
565 return -EIO;
566 }
567 }
568
James Smart04c68492009-05-22 14:52:52 -0400569 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400570 /* Initialize ERATT handling flag */
571 phba->hba_flag &= ~HBA_ERATT_HANDLED;
572
dea31012005-04-17 16:05:31 -0500573 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500574 if (lpfc_readl(phba->HCregaddr, &status)) {
575 spin_unlock_irq(&phba->hbalock);
576 return -EIO;
577 }
dea31012005-04-17 16:05:31 -0500578 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
579 if (psli->num_rings > 0)
580 status |= HC_R0INT_ENA;
581 if (psli->num_rings > 1)
582 status |= HC_R1INT_ENA;
583 if (psli->num_rings > 2)
584 status |= HC_R2INT_ENA;
585 if (psli->num_rings > 3)
586 status |= HC_R3INT_ENA;
587
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500588 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
589 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400590 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500591
dea31012005-04-17 16:05:31 -0500592 writel(status, phba->HCregaddr);
593 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500594 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500595
James Smart93996272008-08-24 21:50:30 -0400596 /* Set up ring-0 (ELS) timer */
597 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400598 mod_timer(&vport->els_tmofunc,
599 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400600 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400601 mod_timer(&phba->hb_tmofunc,
602 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500603 phba->hb_outstanding = 0;
604 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400605 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400606 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700607 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500608
James Smarta0c87cb2009-07-19 10:01:10 -0400609 if (phba->hba_flag & LINK_DISABLED) {
610 lpfc_printf_log(phba,
611 KERN_ERR, LOG_INIT,
612 "2598 Adapter Link is disabled.\n");
613 lpfc_down_link(phba, pmb);
614 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
615 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
616 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
617 lpfc_printf_log(phba,
618 KERN_ERR, LOG_INIT,
619 "2599 Adapter failed to issue DOWN_LINK"
620 " mbox command rc 0x%x\n", rc);
621
622 mempool_free(pmb, phba->mbox_mem_pool);
623 return -EIO;
624 }
James Smarte40a02c2010-02-26 14:13:54 -0500625 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500626 mempool_free(pmb, phba->mbox_mem_pool);
627 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
628 if (rc)
629 return rc;
dea31012005-04-17 16:05:31 -0500630 }
631 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400632 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500633 if (!pmb) {
634 phba->link_state = LPFC_HBA_ERROR;
635 return -ENOMEM;
636 }
637
James Smart57127f12007-10-27 13:37:05 -0400638 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
639 pmb->mbox_cmpl = lpfc_config_async_cmpl;
640 pmb->vport = phba->pport;
641 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500642
James Smart57127f12007-10-27 13:37:05 -0400643 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
644 lpfc_printf_log(phba,
645 KERN_ERR,
646 LOG_INIT,
647 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400648 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400649 rc);
650 mempool_free(pmb, phba->mbox_mem_pool);
651 }
James Smart97207482008-12-04 22:39:19 -0500652
653 /* Get Option rom version */
654 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500655 if (!pmb) {
656 phba->link_state = LPFC_HBA_ERROR;
657 return -ENOMEM;
658 }
659
James Smart97207482008-12-04 22:39:19 -0500660 lpfc_dump_wakeup_param(phba, pmb);
661 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
662 pmb->vport = phba->pport;
663 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
664
665 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400667 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500668 mempool_free(pmb, phba->mbox_mem_pool);
669 }
670
James Smartd7c255b2008-08-24 21:50:00 -0400671 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400672}
673
James Smarte59058c2008-08-24 21:49:00 -0400674/**
James Smart84d1b002010-02-12 14:42:33 -0500675 * lpfc_hba_init_link - Initialize the FC link
676 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400677 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500678 *
679 * This routine will issue the INIT_LINK mailbox command call.
680 * It is available to other drivers through the lpfc_hba data
681 * structure for use as a delayed link up mechanism with the
682 * module parameter lpfc_suppress_link_up.
683 *
684 * Return code
685 * 0 - success
686 * Any other value - error
687 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400688static int
James Smart6e7288d2010-06-07 15:23:35 -0400689lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500690{
James Smart1b511972011-12-13 13:23:09 -0500691 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
692}
693
694/**
695 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
696 * @phba: pointer to lpfc hba data structure.
697 * @fc_topology: desired fc topology.
698 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
699 *
700 * This routine will issue the INIT_LINK mailbox command call.
701 * It is available to other drivers through the lpfc_hba data
702 * structure for use as a delayed link up mechanism with the
703 * module parameter lpfc_suppress_link_up.
704 *
705 * Return code
706 * 0 - success
707 * Any other value - error
708 **/
709int
710lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
711 uint32_t flag)
712{
James Smart84d1b002010-02-12 14:42:33 -0500713 struct lpfc_vport *vport = phba->pport;
714 LPFC_MBOXQ_t *pmb;
715 MAILBOX_t *mb;
716 int rc;
717
718 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
719 if (!pmb) {
720 phba->link_state = LPFC_HBA_ERROR;
721 return -ENOMEM;
722 }
723 mb = &pmb->u.mb;
724 pmb->vport = vport;
725
James Smart026abb82011-12-13 13:20:45 -0500726 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
728 !(phba->lmt & LMT_1Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
730 !(phba->lmt & LMT_2Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
732 !(phba->lmt & LMT_4Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
734 !(phba->lmt & LMT_8Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
736 !(phba->lmt & LMT_10Gb)) ||
737 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400738 !(phba->lmt & LMT_16Gb)) ||
739 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800740 !(phba->lmt & LMT_32Gb)) ||
741 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
742 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500743 /* Reset link speed to auto */
744 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
745 "1302 Invalid speed for this board:%d "
746 "Reset link speed to auto.\n",
747 phba->cfg_link_speed);
748 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
749 }
James Smart1b511972011-12-13 13:23:09 -0500750 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500751 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500752 if (phba->sli_rev < LPFC_SLI_REV4)
753 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400754 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500755 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
757 "0498 Adapter failed to init, mbxCmd x%x "
758 "INIT_LINK, mbxStatus x%x\n",
759 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500760 if (phba->sli_rev <= LPFC_SLI_REV3) {
761 /* Clear all interrupt enable conditions */
762 writel(0, phba->HCregaddr);
763 readl(phba->HCregaddr); /* flush */
764 /* Clear all pending interrupts */
765 writel(0xffffffff, phba->HAregaddr);
766 readl(phba->HAregaddr); /* flush */
767 }
James Smart84d1b002010-02-12 14:42:33 -0500768 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400769 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500770 mempool_free(pmb, phba->mbox_mem_pool);
771 return -EIO;
772 }
James Smarte40a02c2010-02-26 14:13:54 -0500773 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400774 if (flag == MBX_POLL)
775 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500776
777 return 0;
778}
779
780/**
781 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400782 * @phba: pointer to lpfc hba data structure.
783 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500784 *
785 * This routine will issue the DOWN_LINK mailbox command call.
786 * It is available to other drivers through the lpfc_hba data
787 * structure for use to stop the link.
788 *
789 * Return code
790 * 0 - success
791 * Any other value - error
792 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400793static int
James Smart6e7288d2010-06-07 15:23:35 -0400794lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500795{
796 LPFC_MBOXQ_t *pmb;
797 int rc;
798
799 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
800 if (!pmb) {
801 phba->link_state = LPFC_HBA_ERROR;
802 return -ENOMEM;
803 }
804
805 lpfc_printf_log(phba,
806 KERN_ERR, LOG_INIT,
807 "0491 Adapter Link is disabled.\n");
808 lpfc_down_link(phba, pmb);
809 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400810 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500811 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
812 lpfc_printf_log(phba,
813 KERN_ERR, LOG_INIT,
814 "2522 Adapter failed to issue DOWN_LINK"
815 " mbox command rc 0x%x\n", rc);
816
817 mempool_free(pmb, phba->mbox_mem_pool);
818 return -EIO;
819 }
James Smart6e7288d2010-06-07 15:23:35 -0400820 if (flag == MBX_POLL)
821 mempool_free(pmb, phba->mbox_mem_pool);
822
James Smart84d1b002010-02-12 14:42:33 -0500823 return 0;
824}
825
826/**
James Smart3621a712009-04-06 18:47:14 -0400827 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400828 * @phba: pointer to lpfc HBA data structure.
829 *
830 * This routine will do LPFC uninitialization before the HBA is reset when
831 * bringing down the SLI Layer.
832 *
833 * Return codes
834 * 0 - success.
835 * Any other value - error.
836 **/
dea31012005-04-17 16:05:31 -0500837int
James Smart2e0fef82007-06-17 19:56:36 -0500838lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500839{
James Smart1b32f6a2008-02-08 18:49:39 -0500840 struct lpfc_vport **vports;
841 int i;
James Smart3772a992009-05-22 14:50:54 -0400842
843 if (phba->sli_rev <= LPFC_SLI_REV3) {
844 /* Disable interrupts */
845 writel(0, phba->HCregaddr);
846 readl(phba->HCregaddr); /* flush */
847 }
dea31012005-04-17 16:05:31 -0500848
James Smart1b32f6a2008-02-08 18:49:39 -0500849 if (phba->pport->load_flag & FC_UNLOADING)
850 lpfc_cleanup_discovery_resources(phba->pport);
851 else {
852 vports = lpfc_create_vport_work_array(phba);
853 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400854 for (i = 0; i <= phba->max_vports &&
855 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500856 lpfc_cleanup_discovery_resources(vports[i]);
857 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500858 }
859 return 0;
dea31012005-04-17 16:05:31 -0500860}
861
James Smarte59058c2008-08-24 21:49:00 -0400862/**
James Smart68e814f2014-05-21 08:04:59 -0400863 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
864 * rspiocb which got deferred
865 *
866 * @phba: pointer to lpfc HBA data structure.
867 *
868 * This routine will cleanup completed slow path events after HBA is reset
869 * when bringing down the SLI Layer.
870 *
871 *
872 * Return codes
873 * void.
874 **/
875static void
876lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
877{
878 struct lpfc_iocbq *rspiocbq;
879 struct hbq_dmabuf *dmabuf;
880 struct lpfc_cq_event *cq_event;
881
882 spin_lock_irq(&phba->hbalock);
883 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
884 spin_unlock_irq(&phba->hbalock);
885
886 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
887 /* Get the response iocb from the head of work queue */
888 spin_lock_irq(&phba->hbalock);
889 list_remove_head(&phba->sli4_hba.sp_queue_event,
890 cq_event, struct lpfc_cq_event, list);
891 spin_unlock_irq(&phba->hbalock);
892
893 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
894 case CQE_CODE_COMPL_WQE:
895 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
896 cq_event);
897 lpfc_sli_release_iocbq(phba, rspiocbq);
898 break;
899 case CQE_CODE_RECEIVE:
900 case CQE_CODE_RECEIVE_V1:
901 dmabuf = container_of(cq_event, struct hbq_dmabuf,
902 cq_event);
903 lpfc_in_buf_free(phba, &dmabuf->dbuf);
904 }
905 }
906}
907
908/**
James Smartbcece5f2014-04-04 13:51:34 -0400909 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
910 * @phba: pointer to lpfc HBA data structure.
911 *
912 * This routine will cleanup posted ELS buffers after the HBA is reset
913 * when bringing down the SLI Layer.
914 *
915 *
916 * Return codes
917 * void.
918 **/
919static void
920lpfc_hba_free_post_buf(struct lpfc_hba *phba)
921{
922 struct lpfc_sli *psli = &phba->sli;
923 struct lpfc_sli_ring *pring;
924 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400925 LIST_HEAD(buflist);
926 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400927
928 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
929 lpfc_sli_hbqbuf_free_all(phba);
930 else {
931 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800932 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400933 spin_lock_irq(&phba->hbalock);
934 list_splice_init(&pring->postbufq, &buflist);
935 spin_unlock_irq(&phba->hbalock);
936
937 count = 0;
938 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400939 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400940 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400941 lpfc_mbuf_free(phba, mp->virt, mp->phys);
942 kfree(mp);
943 }
James Smart07eab622014-04-04 13:51:44 -0400944
945 spin_lock_irq(&phba->hbalock);
946 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400947 spin_unlock_irq(&phba->hbalock);
948 }
949}
950
951/**
952 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
953 * @phba: pointer to lpfc HBA data structure.
954 *
955 * This routine will cleanup the txcmplq after the HBA is reset when bringing
956 * down the SLI Layer.
957 *
958 * Return codes
959 * void
960 **/
961static void
962lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
963{
964 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800965 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400966 struct lpfc_sli_ring *pring;
967 LIST_HEAD(completions);
968 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800969 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400970
James Smart895427b2017-02-12 13:52:30 -0800971 if (phba->sli_rev != LPFC_SLI_REV4) {
972 for (i = 0; i < psli->num_rings; i++) {
973 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400974 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800975 /* At this point in time the HBA is either reset or DOA
976 * Nothing should be on txcmplq as it will
977 * NEVER complete.
978 */
979 list_splice_init(&pring->txcmplq, &completions);
980 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400981 spin_unlock_irq(&phba->hbalock);
982
James Smart895427b2017-02-12 13:52:30 -0800983 lpfc_sli_abort_iocb_ring(phba, pring);
984 }
James Smartbcece5f2014-04-04 13:51:34 -0400985 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800986 lpfc_sli_cancel_iocbs(phba, &completions,
987 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
988 return;
989 }
990 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
991 pring = qp->pring;
992 if (!pring)
993 continue;
994 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800995 list_for_each_entry_safe(piocb, next_iocb,
996 &pring->txcmplq, list)
997 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800998 list_splice_init(&pring->txcmplq, &completions);
999 pring->txcmplq_cnt = 0;
1000 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -04001001 lpfc_sli_abort_iocb_ring(phba, pring);
1002 }
James Smart895427b2017-02-12 13:52:30 -08001003 /* Cancel all the IOCBs from the completions list */
1004 lpfc_sli_cancel_iocbs(phba, &completions,
1005 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001006}
1007
1008/**
James Smart3772a992009-05-22 14:50:54 -04001009 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001010 int i;
James Smarte59058c2008-08-24 21:49:00 -04001011 * @phba: pointer to lpfc HBA data structure.
1012 *
1013 * This routine will do uninitialization after the HBA is reset when bring
1014 * down the SLI Layer.
1015 *
1016 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001017 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001018 * Any other value - error.
1019 **/
James Smart3772a992009-05-22 14:50:54 -04001020static int
1021lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001022{
James Smartbcece5f2014-04-04 13:51:34 -04001023 lpfc_hba_free_post_buf(phba);
1024 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001025 return 0;
1026}
James Smart5af5eee2010-10-22 11:06:38 -04001027
James Smartda0436e2009-05-22 14:51:39 -04001028/**
1029 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1030 * @phba: pointer to lpfc HBA data structure.
1031 *
1032 * This routine will do uninitialization after the HBA is reset when bring
1033 * down the SLI Layer.
1034 *
1035 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001036 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001037 * Any other value - error.
1038 **/
1039static int
1040lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1041{
James Smartc4908502019-01-28 11:14:28 -08001042 struct lpfc_io_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001043 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smart5e5b5112019-01-28 11:14:22 -08001044 struct lpfc_sli4_hdw_queue *qp;
James Smartda0436e2009-05-22 14:51:39 -04001045 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001046 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001047 LIST_HEAD(nvmet_aborts);
James Smart0f65ff62010-02-26 14:14:23 -05001048 struct lpfc_sglq *sglq_entry = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08001049 int cnt, idx;
James Smart0f65ff62010-02-26 14:14:23 -05001050
James Smart895427b2017-02-12 13:52:30 -08001051
1052 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001053 lpfc_hba_clean_txcmplq(phba);
1054
James Smartda0436e2009-05-22 14:51:39 -04001055 /* At this point in time the HBA is either reset or DOA. Either
1056 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001057 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001058 * driver is unloading or reposted if the driver is restarting
1059 * the port.
1060 */
James Smart895427b2017-02-12 13:52:30 -08001061 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001062 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001063 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001064 * list.
1065 */
James Smart895427b2017-02-12 13:52:30 -08001066 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001067 list_for_each_entry(sglq_entry,
1068 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1069 sglq_entry->state = SGL_FREED;
1070
James Smartda0436e2009-05-22 14:51:39 -04001071 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001072 &phba->sli4_hba.lpfc_els_sgl_list);
1073
James Smartf358dd02017-02-12 13:52:34 -08001074
James Smart895427b2017-02-12 13:52:30 -08001075 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001076
1077 /* abts_xxxx_buf_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001078 * list.
1079 */
James Smart5e5b5112019-01-28 11:14:22 -08001080 cnt = 0;
1081 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
1082 qp = &phba->sli4_hba.hdwq[idx];
1083
1084 spin_lock(&qp->abts_scsi_buf_list_lock);
1085 list_splice_init(&qp->lpfc_abts_scsi_buf_list,
James Smart895427b2017-02-12 13:52:30 -08001086 &aborts);
James Smart895427b2017-02-12 13:52:30 -08001087
James Smart0794d602019-01-28 11:14:19 -08001088 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
James Smart86c67372017-04-21 16:05:04 -07001089 psb->pCmd = NULL;
1090 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001091 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001092 }
James Smart5e5b5112019-01-28 11:14:22 -08001093 spin_lock(&qp->io_buf_list_put_lock);
1094 list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
1095 qp->put_io_bufs += qp->abts_scsi_io_bufs;
1096 qp->abts_scsi_io_bufs = 0;
1097 spin_unlock(&qp->io_buf_list_put_lock);
1098 spin_unlock(&qp->abts_scsi_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001099
James Smart5e5b5112019-01-28 11:14:22 -08001100 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1101 spin_lock(&qp->abts_nvme_buf_list_lock);
1102 list_splice_init(&qp->lpfc_abts_nvme_buf_list,
1103 &nvme_aborts);
1104 list_for_each_entry_safe(psb, psb_next, &nvme_aborts,
1105 list) {
1106 psb->pCmd = NULL;
1107 psb->status = IOSTAT_SUCCESS;
1108 cnt++;
1109 }
1110 spin_lock(&qp->io_buf_list_put_lock);
1111 qp->put_io_bufs += qp->abts_nvme_io_bufs;
1112 qp->abts_nvme_io_bufs = 0;
1113 list_splice_init(&nvme_aborts,
1114 &qp->lpfc_io_buf_list_put);
1115 spin_unlock(&qp->io_buf_list_put_lock);
1116 spin_unlock(&qp->abts_nvme_buf_list_lock);
1117
1118 }
1119 }
James Smart731eedc2019-03-12 16:30:12 -07001120 spin_unlock_irq(&phba->hbalock);
James Smart5e5b5112019-01-28 11:14:22 -08001121
1122 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart731eedc2019-03-12 16:30:12 -07001123 spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart5e5b5112019-01-28 11:14:22 -08001124 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1125 &nvmet_aborts);
James Smart731eedc2019-03-12 16:30:12 -07001126 spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001127 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1128 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001129 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001130 }
James Smart895427b2017-02-12 13:52:30 -08001131 }
James Smart895427b2017-02-12 13:52:30 -08001132
James Smart68e814f2014-05-21 08:04:59 -04001133 lpfc_sli4_free_sp_events(phba);
James Smart5e5b5112019-01-28 11:14:22 -08001134 return cnt;
James Smartda0436e2009-05-22 14:51:39 -04001135}
1136
1137/**
1138 * lpfc_hba_down_post - Wrapper func for hba down post routine
1139 * @phba: pointer to lpfc HBA data structure.
1140 *
1141 * This routine wraps the actual SLI3 or SLI4 routine for performing
1142 * uninitialization after the HBA is reset when bring down the SLI Layer.
1143 *
1144 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001145 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001146 * Any other value - error.
1147 **/
1148int
1149lpfc_hba_down_post(struct lpfc_hba *phba)
1150{
1151 return (*phba->lpfc_hba_down_post)(phba);
1152}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001153
James Smarte59058c2008-08-24 21:49:00 -04001154/**
James Smart3621a712009-04-06 18:47:14 -04001155 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001156 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1157 *
1158 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1159 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1160 * work-port-events bitmap and the worker thread is notified. This timeout
1161 * event will be used by the worker thread to invoke the actual timeout
1162 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1163 * be performed in the timeout handler and the HBA timeout event bit shall
1164 * be cleared by the worker thread after it has taken the event bitmap out.
1165 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001166static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001167lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001168{
1169 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001170 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001171 unsigned long iflag;
1172
Kees Cookf22eb4d2017-09-06 20:24:26 -07001173 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001174
1175 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001176 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001177 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1178 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001179 phba->pport->work_port_events |= WORKER_HB_TMO;
1180 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1181
James Smart93996272008-08-24 21:50:30 -04001182 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001183 if (!tmo_posted)
1184 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001185 return;
1186}
1187
James Smarte59058c2008-08-24 21:49:00 -04001188/**
James Smart19ca7602010-11-20 23:11:55 -05001189 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1190 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1191 *
1192 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1193 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1194 * work-port-events bitmap and the worker thread is notified. This timeout
1195 * event will be used by the worker thread to invoke the actual timeout
1196 * handler routine, lpfc_rrq_handler. Any periodical operations will
1197 * be performed in the timeout handler and the RRQ timeout event bit shall
1198 * be cleared by the worker thread after it has taken the event bitmap out.
1199 **/
1200static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001201lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001202{
1203 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001204 unsigned long iflag;
1205
Kees Cookf22eb4d2017-09-06 20:24:26 -07001206 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001207 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001208 if (!(phba->pport->load_flag & FC_UNLOADING))
1209 phba->hba_flag |= HBA_RRQ_ACTIVE;
1210 else
1211 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001212 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001213
1214 if (!(phba->pport->load_flag & FC_UNLOADING))
1215 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001216}
1217
1218/**
James Smart3621a712009-04-06 18:47:14 -04001219 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001220 * @phba: pointer to lpfc hba data structure.
1221 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1222 *
1223 * This is the callback function to the lpfc heart-beat mailbox command.
1224 * If configured, the lpfc driver issues the heart-beat mailbox command to
1225 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1226 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1227 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1228 * heart-beat outstanding state. Once the mailbox command comes back and
1229 * no error conditions detected, the heart-beat mailbox command timer is
1230 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1231 * state is cleared for the next heart-beat. If the timer expired with the
1232 * heart-beat outstanding state set, the driver will put the HBA offline.
1233 **/
James Smart858c9f62007-06-17 19:56:39 -05001234static void
1235lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1236{
1237 unsigned long drvr_flag;
1238
1239 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1240 phba->hb_outstanding = 0;
1241 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1242
James Smart93996272008-08-24 21:50:30 -04001243 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001244 mempool_free(pmboxq, phba->mbox_mem_pool);
1245 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1246 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001247 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001248 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001249 jiffies +
1250 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001251 return;
1252}
1253
James Smart32517fc2019-01-28 11:14:33 -08001254static void
1255lpfc_hb_eq_delay_work(struct work_struct *work)
1256{
1257 struct lpfc_hba *phba = container_of(to_delayed_work(work),
1258 struct lpfc_hba, eq_delay_work);
1259 struct lpfc_eq_intr_info *eqi, *eqi_new;
1260 struct lpfc_queue *eq, *eq_next;
1261 unsigned char *eqcnt = NULL;
1262 uint32_t usdelay;
1263 int i;
1264
1265 if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
1266 return;
1267
1268 if (phba->link_state == LPFC_HBA_ERROR ||
1269 phba->pport->fc_flag & FC_OFFLINE_MODE)
1270 goto requeue;
1271
1272 eqcnt = kcalloc(num_possible_cpus(), sizeof(unsigned char),
1273 GFP_KERNEL);
1274 if (!eqcnt)
1275 goto requeue;
1276
James Smart657add42019-05-21 17:49:06 -07001277 /* Loop thru all IRQ vectors */
James Smart32517fc2019-01-28 11:14:33 -08001278 for (i = 0; i < phba->cfg_irq_chann; i++) {
James Smart657add42019-05-21 17:49:06 -07001279 /* Get the EQ corresponding to the IRQ vector */
1280 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
James Smart32517fc2019-01-28 11:14:33 -08001281 if (eq && eqcnt[eq->last_cpu] < 2)
1282 eqcnt[eq->last_cpu]++;
1283 continue;
1284 }
1285
1286 for_each_present_cpu(i) {
1287 if (phba->cfg_irq_chann > 1 && eqcnt[i] < 2)
1288 continue;
1289
1290 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
1291
1292 usdelay = (eqi->icnt / LPFC_IMAX_THRESHOLD) *
1293 LPFC_EQ_DELAY_STEP;
1294 if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
1295 usdelay = LPFC_MAX_AUTO_EQ_DELAY;
1296
1297 eqi->icnt = 0;
1298
1299 list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
1300 if (eq->last_cpu != i) {
1301 eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
1302 eq->last_cpu);
1303 list_move_tail(&eq->cpu_list, &eqi_new->list);
1304 continue;
1305 }
1306 if (usdelay != eq->q_mode)
1307 lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
1308 usdelay);
1309 }
1310 }
1311
1312 kfree(eqcnt);
1313
1314requeue:
1315 queue_delayed_work(phba->wq, &phba->eq_delay_work,
1316 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
1317}
1318
James Smarte59058c2008-08-24 21:49:00 -04001319/**
James Smartc4908502019-01-28 11:14:28 -08001320 * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
1321 * @phba: pointer to lpfc hba data structure.
1322 *
1323 * For each heartbeat, this routine does some heuristic methods to adjust
1324 * XRI distribution. The goal is to fully utilize free XRIs.
1325 **/
1326static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
1327{
1328 u32 i;
1329 u32 hwq_count;
1330
1331 hwq_count = phba->cfg_hdw_queue;
1332 for (i = 0; i < hwq_count; i++) {
1333 /* Adjust XRIs in private pool */
1334 lpfc_adjust_pvt_pool_count(phba, i);
1335
1336 /* Adjust high watermark */
1337 lpfc_adjust_high_watermark(phba, i);
1338
1339#ifdef LPFC_MXP_STAT
1340 /* Snapshot pbl, pvt and busy count */
1341 lpfc_snapshot_mxp(phba, i);
1342#endif
1343 }
1344}
1345
James Smarte59058c2008-08-24 21:49:00 -04001346/**
James Smart3621a712009-04-06 18:47:14 -04001347 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001348 * @phba: pointer to lpfc hba data structure.
1349 *
1350 * This is the actual HBA-timer timeout handler to be invoked by the worker
1351 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1352 * handler performs any periodic operations needed for the device. If such
1353 * periodic event has already been attended to either in the interrupt handler
1354 * or by processing slow-ring or fast-ring events within the HBA-timer
1355 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1356 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1357 * is configured and there is no heart-beat mailbox command outstanding, a
1358 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1359 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1360 * to offline.
1361 **/
James Smart858c9f62007-06-17 19:56:39 -05001362void
1363lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1364{
James Smart45ed1192009-10-02 15:17:02 -04001365 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001366 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001367 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001368 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001369 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001370 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001371
James Smartc4908502019-01-28 11:14:28 -08001372 if (phba->cfg_xri_rebalancing) {
1373 /* Multi-XRI pools handler */
1374 lpfc_hb_mxp_handler(phba);
1375 }
James Smart858c9f62007-06-17 19:56:39 -05001376
James Smart45ed1192009-10-02 15:17:02 -04001377 vports = lpfc_create_vport_work_array(phba);
1378 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001379 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001380 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001381 lpfc_fdmi_num_disc_check(vports[i]);
1382 }
James Smart45ed1192009-10-02 15:17:02 -04001383 lpfc_destroy_vport_work_array(phba, vports);
1384
James Smart858c9f62007-06-17 19:56:39 -05001385 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001386 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001387 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1388 return;
1389
1390 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001391
James Smart256ec0d2013-04-17 20:14:58 -04001392 if (time_after(phba->last_completion_time +
1393 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1394 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001395 spin_unlock_irq(&phba->pport->work_port_lock);
1396 if (!phba->hb_outstanding)
1397 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001398 jiffies +
1399 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001400 else
1401 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001402 jiffies +
1403 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001404 return;
1405 }
1406 spin_unlock_irq(&phba->pport->work_port_lock);
1407
James Smart0ff10d42008-01-11 01:52:36 -05001408 if (phba->elsbuf_cnt &&
1409 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1410 spin_lock_irq(&phba->hbalock);
1411 list_splice_init(&phba->elsbuf, &completions);
1412 phba->elsbuf_cnt = 0;
1413 phba->elsbuf_prev_cnt = 0;
1414 spin_unlock_irq(&phba->hbalock);
1415
1416 while (!list_empty(&completions)) {
1417 list_remove_head(&completions, buf_ptr,
1418 struct lpfc_dmabuf, list);
1419 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1420 kfree(buf_ptr);
1421 }
1422 }
1423 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1424
James Smart858c9f62007-06-17 19:56:39 -05001425 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001426 if (phba->cfg_enable_hba_heartbeat) {
1427 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001428 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1429 (list_empty(&psli->mboxq))) {
1430 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1431 GFP_KERNEL);
1432 if (!pmboxq) {
1433 mod_timer(&phba->hb_tmofunc,
1434 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001435 msecs_to_jiffies(1000 *
1436 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001437 return;
1438 }
James Smart13815c82008-01-11 01:52:48 -05001439
James Smartbc739052010-08-04 16:11:18 -04001440 lpfc_heart_beat(phba, pmboxq);
1441 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1442 pmboxq->vport = phba->pport;
1443 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1444 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001445
James Smartbc739052010-08-04 16:11:18 -04001446 if (retval != MBX_BUSY &&
1447 retval != MBX_SUCCESS) {
1448 mempool_free(pmboxq,
1449 phba->mbox_mem_pool);
1450 mod_timer(&phba->hb_tmofunc,
1451 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001452 msecs_to_jiffies(1000 *
1453 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001454 return;
1455 }
1456 phba->skipped_hb = 0;
1457 phba->hb_outstanding = 1;
1458 } else if (time_before_eq(phba->last_completion_time,
1459 phba->skipped_hb)) {
1460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1461 "2857 Last completion time not "
1462 " updated in %d ms\n",
1463 jiffies_to_msecs(jiffies
1464 - phba->last_completion_time));
1465 } else
1466 phba->skipped_hb = jiffies;
1467
James Smart858c9f62007-06-17 19:56:39 -05001468 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001469 jiffies +
1470 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001471 return;
James Smart13815c82008-01-11 01:52:48 -05001472 } else {
1473 /*
1474 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001475 * we need to give the hb mailbox cmd a chance to
1476 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001477 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001478 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1479 "0459 Adapter heartbeat still out"
1480 "standing:last compl time was %d ms.\n",
1481 jiffies_to_msecs(jiffies
1482 - phba->last_completion_time));
1483 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001484 jiffies +
1485 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001486 }
James Smart4258e982015-12-16 18:11:58 -05001487 } else {
1488 mod_timer(&phba->hb_tmofunc,
1489 jiffies +
1490 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001491 }
1492}
1493
James Smarte59058c2008-08-24 21:49:00 -04001494/**
James Smart3621a712009-04-06 18:47:14 -04001495 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001496 * @phba: pointer to lpfc hba data structure.
1497 *
1498 * This routine is called to bring the HBA offline when HBA hardware error
1499 * other than Port Error 6 has been detected.
1500 **/
James Smart09372822008-01-11 01:52:54 -05001501static void
1502lpfc_offline_eratt(struct lpfc_hba *phba)
1503{
1504 struct lpfc_sli *psli = &phba->sli;
1505
1506 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001507 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001508 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001509 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001510
1511 lpfc_offline(phba);
1512 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001513 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001514 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001515 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001516 lpfc_hba_down_post(phba);
1517 lpfc_sli_brdready(phba, HS_MBRDY);
1518 lpfc_unblock_mgmt_io(phba);
1519 phba->link_state = LPFC_HBA_ERROR;
1520 return;
1521}
1522
James Smarte59058c2008-08-24 21:49:00 -04001523/**
James Smartda0436e2009-05-22 14:51:39 -04001524 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1525 * @phba: pointer to lpfc hba data structure.
1526 *
1527 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1528 * other than Port Error 6 has been detected.
1529 **/
James Smarta88dbb62013-04-17 20:18:39 -04001530void
James Smartda0436e2009-05-22 14:51:39 -04001531lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1532{
James Smart946727d2015-04-07 15:07:09 -04001533 spin_lock_irq(&phba->hbalock);
1534 phba->link_state = LPFC_HBA_ERROR;
1535 spin_unlock_irq(&phba->hbalock);
1536
James Smart618a5232012-06-12 13:54:36 -04001537 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001538 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001539 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001540 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001541}
1542
1543/**
James Smarta257bf92009-04-06 18:48:10 -04001544 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1545 * @phba: pointer to lpfc hba data structure.
1546 *
1547 * This routine is invoked to handle the deferred HBA hardware error
1548 * conditions. This type of error is indicated by HBA by setting ER1
1549 * and another ER bit in the host status register. The driver will
1550 * wait until the ER1 bit clears before handling the error condition.
1551 **/
1552static void
1553lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1554{
1555 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001556 struct lpfc_sli *psli = &phba->sli;
1557
James Smartf4b4c682009-05-22 14:53:12 -04001558 /* If the pci channel is offline, ignore possible errors,
1559 * since we cannot communicate with the pci card anyway.
1560 */
1561 if (pci_channel_offline(phba->pcidev)) {
1562 spin_lock_irq(&phba->hbalock);
1563 phba->hba_flag &= ~DEFER_ERATT;
1564 spin_unlock_irq(&phba->hbalock);
1565 return;
1566 }
1567
James Smarta257bf92009-04-06 18:48:10 -04001568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1569 "0479 Deferred Adapter Hardware Error "
1570 "Data: x%x x%x x%x\n",
1571 phba->work_hs,
1572 phba->work_status[0], phba->work_status[1]);
1573
1574 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001575 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001576 spin_unlock_irq(&phba->hbalock);
1577
1578
1579 /*
1580 * Firmware stops when it triggred erratt. That could cause the I/Os
1581 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1582 * SCSI layer retry it after re-establishing link.
1583 */
James Smartdb55fba2014-04-04 13:52:02 -04001584 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001585
1586 /*
1587 * There was a firmware error. Take the hba offline and then
1588 * attempt to restart it.
1589 */
James Smart618a5232012-06-12 13:54:36 -04001590 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001591 lpfc_offline(phba);
1592
1593 /* Wait for the ER1 bit to clear.*/
1594 while (phba->work_hs & HS_FFER1) {
1595 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001596 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1597 phba->work_hs = UNPLUG_ERR ;
1598 break;
1599 }
James Smarta257bf92009-04-06 18:48:10 -04001600 /* If driver is unloading let the worker thread continue */
1601 if (phba->pport->load_flag & FC_UNLOADING) {
1602 phba->work_hs = 0;
1603 break;
1604 }
1605 }
1606
1607 /*
1608 * This is to ptrotect against a race condition in which
1609 * first write to the host attention register clear the
1610 * host status register.
1611 */
1612 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1613 phba->work_hs = old_host_status & ~HS_FFER1;
1614
James Smart3772a992009-05-22 14:50:54 -04001615 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001616 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001617 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001618 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1619 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1620}
1621
James Smart3772a992009-05-22 14:50:54 -04001622static void
1623lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1624{
1625 struct lpfc_board_event_header board_event;
1626 struct Scsi_Host *shost;
1627
1628 board_event.event_type = FC_REG_BOARD_EVENT;
1629 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1630 shost = lpfc_shost_from_vport(phba->pport);
1631 fc_host_post_vendor_event(shost, fc_get_event_number(),
1632 sizeof(board_event),
1633 (char *) &board_event,
1634 LPFC_NL_VENDOR_ID);
1635}
1636
James Smarta257bf92009-04-06 18:48:10 -04001637/**
James Smart3772a992009-05-22 14:50:54 -04001638 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001639 * @phba: pointer to lpfc hba data structure.
1640 *
1641 * This routine is invoked to handle the following HBA hardware error
1642 * conditions:
1643 * 1 - HBA error attention interrupt
1644 * 2 - DMA ring index out of range
1645 * 3 - Mailbox command came back as unknown
1646 **/
James Smart3772a992009-05-22 14:50:54 -04001647static void
1648lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001649{
James Smart2e0fef82007-06-17 19:56:36 -05001650 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001651 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001652 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001653 unsigned long temperature;
1654 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001655 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001656
Linas Vepstas8d63f372007-02-14 14:28:36 -06001657 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001658 * since we cannot communicate with the pci card anyway.
1659 */
1660 if (pci_channel_offline(phba->pcidev)) {
1661 spin_lock_irq(&phba->hbalock);
1662 phba->hba_flag &= ~DEFER_ERATT;
1663 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001664 return;
James Smart3772a992009-05-22 14:50:54 -04001665 }
1666
James Smart13815c82008-01-11 01:52:48 -05001667 /* If resets are disabled then leave the HBA alone and return */
1668 if (!phba->cfg_enable_hba_reset)
1669 return;
dea31012005-04-17 16:05:31 -05001670
James Smartea2151b2008-09-07 11:52:10 -04001671 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001672 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001673
James Smarta257bf92009-04-06 18:48:10 -04001674 if (phba->hba_flag & DEFER_ERATT)
1675 lpfc_handle_deferred_eratt(phba);
1676
James Smartdcf2a4e2010-09-29 11:18:53 -04001677 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1678 if (phba->work_hs & HS_FFER6)
1679 /* Re-establishing Link */
1680 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1681 "1301 Re-establishing Link "
1682 "Data: x%x x%x x%x\n",
1683 phba->work_hs, phba->work_status[0],
1684 phba->work_status[1]);
1685 if (phba->work_hs & HS_FFER8)
1686 /* Device Zeroization */
1687 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1688 "2861 Host Authentication device "
1689 "zeroization Data:x%x x%x x%x\n",
1690 phba->work_hs, phba->work_status[0],
1691 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001692
James Smart92d7f7b2007-06-17 19:56:38 -05001693 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001694 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001695 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001696
1697 /*
1698 * Firmware stops when it triggled erratt with HS_FFER6.
1699 * That could cause the I/Os dropped by the firmware.
1700 * Error iocb (I/O) on txcmplq and let the SCSI layer
1701 * retry it after re-establishing link.
1702 */
James Smartdb55fba2014-04-04 13:52:02 -04001703 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001704
dea31012005-04-17 16:05:31 -05001705 /*
1706 * There was a firmware error. Take the hba offline and then
1707 * attempt to restart it.
1708 */
James Smart618a5232012-06-12 13:54:36 -04001709 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001710 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001711 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001712 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001713 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001714 return;
1715 }
James Smart46fa3112007-04-25 09:51:45 -04001716 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001717 } else if (phba->work_hs & HS_CRIT_TEMP) {
1718 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1719 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1720 temp_event_data.event_code = LPFC_CRIT_TEMP;
1721 temp_event_data.data = (uint32_t)temperature;
1722
1723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001724 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001725 "(%ld), taking this port offline "
1726 "Data: x%x x%x x%x\n",
1727 temperature, phba->work_hs,
1728 phba->work_status[0], phba->work_status[1]);
1729
1730 shost = lpfc_shost_from_vport(phba->pport);
1731 fc_host_post_vendor_event(shost, fc_get_event_number(),
1732 sizeof(temp_event_data),
1733 (char *) &temp_event_data,
1734 SCSI_NL_VID_TYPE_PCI
1735 | PCI_VENDOR_ID_EMULEX);
1736
James Smart7af67052007-10-27 13:38:11 -04001737 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001738 phba->over_temp_state = HBA_OVER_TEMP;
1739 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001740 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001741
dea31012005-04-17 16:05:31 -05001742 } else {
1743 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001744 * failure is a value other than FFER6. Do not call the offline
1745 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001746 */
1747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001748 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001749 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001750 phba->work_hs,
dea31012005-04-17 16:05:31 -05001751 phba->work_status[0], phba->work_status[1]);
1752
James Smartd2873e42006-08-18 17:46:43 -04001753 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001754 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001755 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001756 sizeof(event_data), (char *) &event_data,
1757 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1758
James Smart09372822008-01-11 01:52:54 -05001759 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001760 }
James Smart93996272008-08-24 21:50:30 -04001761 return;
dea31012005-04-17 16:05:31 -05001762}
1763
James Smarte59058c2008-08-24 21:49:00 -04001764/**
James Smart618a5232012-06-12 13:54:36 -04001765 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1766 * @phba: pointer to lpfc hba data structure.
1767 * @mbx_action: flag for mailbox shutdown action.
1768 *
1769 * This routine is invoked to perform an SLI4 port PCI function reset in
1770 * response to port status register polling attention. It waits for port
1771 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1772 * During this process, interrupt vectors are freed and later requested
1773 * for handling possible port resource change.
1774 **/
1775static int
James Smarte10b2022014-02-20 09:57:43 -05001776lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1777 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001778{
1779 int rc;
1780 uint32_t intr_mode;
1781
James Smart27d6ac02018-02-22 08:18:42 -08001782 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001783 LPFC_SLI_INTF_IF_TYPE_2) {
1784 /*
1785 * On error status condition, driver need to wait for port
1786 * ready before performing reset.
1787 */
1788 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001789 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001790 return rc;
James Smart618a5232012-06-12 13:54:36 -04001791 }
James Smart0e916ee2016-07-06 12:36:06 -07001792
James Smart65791f12016-07-06 12:35:56 -07001793 /* need reset: attempt for port recovery */
1794 if (en_rn_msg)
1795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1796 "2887 Reset Needed: Attempting Port "
1797 "Recovery...\n");
1798 lpfc_offline_prep(phba, mbx_action);
1799 lpfc_offline(phba);
1800 /* release interrupt for possible resource change */
1801 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001802 rc = lpfc_sli_brdrestart(phba);
1803 if (rc) {
1804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1805 "6309 Failed to restart board\n");
1806 return rc;
1807 }
James Smart65791f12016-07-06 12:35:56 -07001808 /* request and enable interrupt */
1809 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1810 if (intr_mode == LPFC_INTR_ERROR) {
1811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1812 "3175 Failed to enable interrupt\n");
1813 return -EIO;
1814 }
1815 phba->intr_mode = intr_mode;
1816 rc = lpfc_online(phba);
1817 if (rc == 0)
1818 lpfc_unblock_mgmt_io(phba);
1819
James Smart618a5232012-06-12 13:54:36 -04001820 return rc;
1821}
1822
1823/**
James Smartda0436e2009-05-22 14:51:39 -04001824 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1825 * @phba: pointer to lpfc hba data structure.
1826 *
1827 * This routine is invoked to handle the SLI4 HBA hardware error attention
1828 * conditions.
1829 **/
1830static void
1831lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1832{
1833 struct lpfc_vport *vport = phba->pport;
1834 uint32_t event_data;
1835 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001836 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001837 struct lpfc_register portstat_reg = {0};
1838 uint32_t reg_err1, reg_err2;
1839 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001840 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001841 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001842 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001843 struct lpfc_register portsmphr_reg;
1844 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001845
1846 /* If the pci channel is offline, ignore possible errors, since
1847 * we cannot communicate with the pci card anyway.
1848 */
James Smart32a93102019-03-12 16:30:13 -07001849 if (pci_channel_offline(phba->pcidev)) {
1850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1851 "3166 pci channel is offline\n");
1852 lpfc_sli4_offline_eratt(phba);
James Smartda0436e2009-05-22 14:51:39 -04001853 return;
James Smart32a93102019-03-12 16:30:13 -07001854 }
James Smartda0436e2009-05-22 14:51:39 -04001855
James Smart65791f12016-07-06 12:35:56 -07001856 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001857 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1858 switch (if_type) {
1859 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001860 pci_rd_rc1 = lpfc_readl(
1861 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1862 &uerrlo_reg);
1863 pci_rd_rc2 = lpfc_readl(
1864 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1865 &uemasklo_reg);
1866 /* consider PCI bus read error as pci_channel_offline */
1867 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1868 return;
James Smart65791f12016-07-06 12:35:56 -07001869 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1870 lpfc_sli4_offline_eratt(phba);
1871 return;
1872 }
1873 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1874 "7623 Checking UE recoverable");
1875
1876 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1877 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1878 &portsmphr_reg.word0))
1879 continue;
1880
1881 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1882 &portsmphr_reg);
1883 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1884 LPFC_PORT_SEM_UE_RECOVERABLE)
1885 break;
1886 /*Sleep for 1Sec, before checking SEMAPHORE */
1887 msleep(1000);
1888 }
1889
1890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1891 "4827 smphr_port_status x%x : Waited %dSec",
1892 smphr_port_status, i);
1893
1894 /* Recoverable UE, reset the HBA device */
1895 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1896 LPFC_PORT_SEM_UE_RECOVERABLE) {
1897 for (i = 0; i < 20; i++) {
1898 msleep(1000);
1899 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1900 &portsmphr_reg.word0) &&
1901 (LPFC_POST_STAGE_PORT_READY ==
1902 bf_get(lpfc_port_smphr_port_status,
1903 &portsmphr_reg))) {
1904 rc = lpfc_sli4_port_sta_fn_reset(phba,
1905 LPFC_MBX_NO_WAIT, en_rn_msg);
1906 if (rc == 0)
1907 return;
1908 lpfc_printf_log(phba,
1909 KERN_ERR, LOG_INIT,
1910 "4215 Failed to recover UE");
1911 break;
1912 }
1913 }
1914 }
1915 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1916 "7624 Firmware not ready: Failing UE recovery,"
1917 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001918 lpfc_sli4_offline_eratt(phba);
1919 break;
James Smart946727d2015-04-07 15:07:09 -04001920
James Smart2fcee4b2010-12-15 17:57:46 -05001921 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001922 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001923 pci_rd_rc1 = lpfc_readl(
1924 phba->sli4_hba.u.if_type2.STATUSregaddr,
1925 &portstat_reg.word0);
1926 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001927 if (pci_rd_rc1 == -EIO) {
1928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1929 "3151 PCI bus read access failure: x%x\n",
1930 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart32a93102019-03-12 16:30:13 -07001931 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001932 return;
James Smart6b5151f2012-01-18 16:24:06 -05001933 }
James Smart2e90f4b2011-12-13 13:22:37 -05001934 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1935 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001936 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1938 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001939 "taking port offline Data: x%x x%x\n",
1940 reg_err1, reg_err2);
1941
James Smart310429e2016-07-06 12:35:54 -07001942 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001943 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1944 temp_event_data.event_code = LPFC_CRIT_TEMP;
1945 temp_event_data.data = 0xFFFFFFFF;
1946
1947 shost = lpfc_shost_from_vport(phba->pport);
1948 fc_host_post_vendor_event(shost, fc_get_event_number(),
1949 sizeof(temp_event_data),
1950 (char *)&temp_event_data,
1951 SCSI_NL_VID_TYPE_PCI
1952 | PCI_VENDOR_ID_EMULEX);
1953
James Smart2fcee4b2010-12-15 17:57:46 -05001954 spin_lock_irq(&phba->hbalock);
1955 phba->over_temp_state = HBA_OVER_TEMP;
1956 spin_unlock_irq(&phba->hbalock);
1957 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001958 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001959 }
James Smart2e90f4b2011-12-13 13:22:37 -05001960 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001961 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001962 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001963 "3143 Port Down: Firmware Update "
1964 "Detected\n");
1965 en_rn_msg = false;
1966 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001967 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1969 "3144 Port Down: Debug Dump\n");
1970 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1971 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1973 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001974
James Smart946727d2015-04-07 15:07:09 -04001975 /* If resets are disabled then leave the HBA alone and return */
1976 if (!phba->cfg_enable_hba_reset)
1977 return;
1978
James Smart618a5232012-06-12 13:54:36 -04001979 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001980 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1981 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001982 if (rc == 0) {
1983 /* don't report event on forced debug dump */
1984 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1985 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1986 return;
1987 else
1988 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001989 }
James Smart618a5232012-06-12 13:54:36 -04001990 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1992 "3152 Unrecoverable error, bring the port "
1993 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001994 lpfc_sli4_offline_eratt(phba);
1995 break;
1996 case LPFC_SLI_INTF_IF_TYPE_1:
1997 default:
1998 break;
1999 }
James Smart2e90f4b2011-12-13 13:22:37 -05002000 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2001 "3123 Report dump event to upper layer\n");
2002 /* Send an internal error event to mgmt application */
2003 lpfc_board_errevt_to_mgmt(phba);
2004
2005 event_data = FC_REG_DUMP_EVENT;
2006 shost = lpfc_shost_from_vport(vport);
2007 fc_host_post_vendor_event(shost, fc_get_event_number(),
2008 sizeof(event_data), (char *) &event_data,
2009 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002010}
2011
2012/**
2013 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2014 * @phba: pointer to lpfc HBA data structure.
2015 *
2016 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2017 * routine from the API jump table function pointer from the lpfc_hba struct.
2018 *
2019 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002020 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002021 * Any other value - error.
2022 **/
2023void
2024lpfc_handle_eratt(struct lpfc_hba *phba)
2025{
2026 (*phba->lpfc_handle_eratt)(phba);
2027}
2028
2029/**
James Smart3621a712009-04-06 18:47:14 -04002030 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002031 * @phba: pointer to lpfc hba data structure.
2032 *
2033 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002034 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002035 **/
dea31012005-04-17 16:05:31 -05002036void
James Smart2e0fef82007-06-17 19:56:36 -05002037lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002038{
James Smart2e0fef82007-06-17 19:56:36 -05002039 struct lpfc_vport *vport = phba->pport;
2040 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002041 LPFC_MBOXQ_t *pmb;
2042 volatile uint32_t control;
2043 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002044 int rc = 0;
dea31012005-04-17 16:05:31 -05002045
2046 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002047 if (!pmb) {
2048 rc = 1;
dea31012005-04-17 16:05:31 -05002049 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002050 }
dea31012005-04-17 16:05:31 -05002051
2052 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002053 if (!mp) {
2054 rc = 2;
dea31012005-04-17 16:05:31 -05002055 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002056 }
dea31012005-04-17 16:05:31 -05002057
2058 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002059 if (!mp->virt) {
2060 rc = 3;
dea31012005-04-17 16:05:31 -05002061 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002062 }
dea31012005-04-17 16:05:31 -05002063
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002064 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002065 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002066
2067 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002068 lpfc_read_topology(phba, pmb, mp);
2069 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002070 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002071 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002072 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002073 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002074 if (rc == MBX_NOT_FINISHED) {
2075 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002076 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002077 }
dea31012005-04-17 16:05:31 -05002078
2079 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002080 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002081 writel(HA_LATT, phba->HAregaddr);
2082 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002084
2085 return;
2086
James Smart14691152006-12-02 13:34:28 -05002087lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002088 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002089 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002090lpfc_handle_latt_free_mp:
2091 kfree(mp);
2092lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002093 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002094lpfc_handle_latt_err_exit:
2095 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002097 psli->sli_flag |= LPFC_PROCESS_LA;
2098 control = readl(phba->HCregaddr);
2099 control |= HC_LAINT_ENA;
2100 writel(control, phba->HCregaddr);
2101 readl(phba->HCregaddr); /* flush */
2102
2103 /* Clear Link Attention in HA REG */
2104 writel(HA_LATT, phba->HAregaddr);
2105 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002106 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002107 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002108 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002109
James Smart09372822008-01-11 01:52:54 -05002110 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2111 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002112
2113 return;
2114}
2115
James Smarte59058c2008-08-24 21:49:00 -04002116/**
James Smart3621a712009-04-06 18:47:14 -04002117 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002118 * @phba: pointer to lpfc hba data structure.
2119 * @vpd: pointer to the vital product data.
2120 * @len: length of the vital product data in bytes.
2121 *
2122 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2123 * an array of characters. In this routine, the ModelName, ProgramType, and
2124 * ModelDesc, etc. fields of the phba data structure will be populated.
2125 *
2126 * Return codes
2127 * 0 - pointer to the VPD passed in is NULL
2128 * 1 - success
2129 **/
James Smart3772a992009-05-22 14:50:54 -04002130int
James Smart2e0fef82007-06-17 19:56:36 -05002131lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002132{
2133 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002134 int Length;
dea31012005-04-17 16:05:31 -05002135 int i, j;
2136 int finished = 0;
2137 int index = 0;
2138
2139 if (!vpd)
2140 return 0;
2141
2142 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002143 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002144 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002145 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2146 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002147 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002148 switch (vpd[index]) {
2149 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002150 case 0x91:
dea31012005-04-17 16:05:31 -05002151 index += 1;
2152 lenlo = vpd[index];
2153 index += 1;
2154 lenhi = vpd[index];
2155 index += 1;
2156 i = ((((unsigned short)lenhi) << 8) + lenlo);
2157 index += i;
2158 break;
2159 case 0x90:
2160 index += 1;
2161 lenlo = vpd[index];
2162 index += 1;
2163 lenhi = vpd[index];
2164 index += 1;
2165 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002166 if (Length > len - index)
2167 Length = len - index;
dea31012005-04-17 16:05:31 -05002168 while (Length > 0) {
2169 /* Look for Serial Number */
2170 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2171 index += 2;
2172 i = vpd[index];
2173 index += 1;
2174 j = 0;
2175 Length -= (3+i);
2176 while(i--) {
2177 phba->SerialNumber[j++] = vpd[index++];
2178 if (j == 31)
2179 break;
2180 }
2181 phba->SerialNumber[j] = 0;
2182 continue;
2183 }
2184 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2185 phba->vpd_flag |= VPD_MODEL_DESC;
2186 index += 2;
2187 i = vpd[index];
2188 index += 1;
2189 j = 0;
2190 Length -= (3+i);
2191 while(i--) {
2192 phba->ModelDesc[j++] = vpd[index++];
2193 if (j == 255)
2194 break;
2195 }
2196 phba->ModelDesc[j] = 0;
2197 continue;
2198 }
2199 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2200 phba->vpd_flag |= VPD_MODEL_NAME;
2201 index += 2;
2202 i = vpd[index];
2203 index += 1;
2204 j = 0;
2205 Length -= (3+i);
2206 while(i--) {
2207 phba->ModelName[j++] = vpd[index++];
2208 if (j == 79)
2209 break;
2210 }
2211 phba->ModelName[j] = 0;
2212 continue;
2213 }
2214 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2215 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2216 index += 2;
2217 i = vpd[index];
2218 index += 1;
2219 j = 0;
2220 Length -= (3+i);
2221 while(i--) {
2222 phba->ProgramType[j++] = vpd[index++];
2223 if (j == 255)
2224 break;
2225 }
2226 phba->ProgramType[j] = 0;
2227 continue;
2228 }
2229 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2230 phba->vpd_flag |= VPD_PORT;
2231 index += 2;
2232 i = vpd[index];
2233 index += 1;
2234 j = 0;
2235 Length -= (3+i);
2236 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002237 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2238 (phba->sli4_hba.pport_name_sta ==
2239 LPFC_SLI4_PPNAME_GET)) {
2240 j++;
2241 index++;
2242 } else
2243 phba->Port[j++] = vpd[index++];
2244 if (j == 19)
2245 break;
dea31012005-04-17 16:05:31 -05002246 }
James Smartcd1c8302011-10-10 21:33:25 -04002247 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2248 (phba->sli4_hba.pport_name_sta ==
2249 LPFC_SLI4_PPNAME_NON))
2250 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002251 continue;
2252 }
2253 else {
2254 index += 2;
2255 i = vpd[index];
2256 index += 1;
2257 index += i;
2258 Length -= (3 + i);
2259 }
2260 }
2261 finished = 0;
2262 break;
2263 case 0x78:
2264 finished = 1;
2265 break;
2266 default:
2267 index ++;
2268 break;
2269 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002270 }
dea31012005-04-17 16:05:31 -05002271
2272 return(1);
2273}
2274
James Smarte59058c2008-08-24 21:49:00 -04002275/**
James Smart3621a712009-04-06 18:47:14 -04002276 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002277 * @phba: pointer to lpfc hba data structure.
2278 * @mdp: pointer to the data structure to hold the derived model name.
2279 * @descp: pointer to the data structure to hold the derived description.
2280 *
2281 * This routine retrieves HBA's description based on its registered PCI device
2282 * ID. The @descp passed into this function points to an array of 256 chars. It
2283 * shall be returned with the model name, maximum speed, and the host bus type.
2284 * The @mdp passed into this function points to an array of 80 chars. When the
2285 * function returns, the @mdp will be filled with the model name.
2286 **/
dea31012005-04-17 16:05:31 -05002287static void
James Smart2e0fef82007-06-17 19:56:36 -05002288lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002289{
2290 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002291 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002292 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002293 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002294 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002295 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002296 char *name;
2297 char *bus;
2298 char *function;
2299 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002300
2301 if (mdp && mdp[0] != '\0'
2302 && descp && descp[0] != '\0')
2303 return;
2304
James Smartfbd8a6b2018-02-22 08:18:45 -08002305 if (phba->lmt & LMT_64Gb)
2306 max_speed = 64;
2307 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002308 max_speed = 32;
2309 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002310 max_speed = 16;
2311 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002312 max_speed = 10;
2313 else if (phba->lmt & LMT_8Gb)
2314 max_speed = 8;
2315 else if (phba->lmt & LMT_4Gb)
2316 max_speed = 4;
2317 else if (phba->lmt & LMT_2Gb)
2318 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002319 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002320 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002321 else
2322 max_speed = 0;
dea31012005-04-17 16:05:31 -05002323
2324 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002325
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002326 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002327 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002328 m = (typeof(m)){"LP6000", "PCI",
2329 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002330 break;
dea31012005-04-17 16:05:31 -05002331 case PCI_DEVICE_ID_SUPERFLY:
2332 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002333 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002334 else
James Smart12222f42014-05-21 08:05:19 -04002335 m = (typeof(m)){"LP7000E", "PCI", ""};
2336 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002337 break;
2338 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002339 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002340 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002341 break;
2342 case PCI_DEVICE_ID_CENTAUR:
2343 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002344 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002345 else
James Smart12222f42014-05-21 08:05:19 -04002346 m = (typeof(m)){"LP9000", "PCI", ""};
2347 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002348 break;
2349 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002350 m = (typeof(m)){"LP952", "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_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002354 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002355 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002356 break;
2357 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002358 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002359 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002360 break;
2361 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002362 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002363 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002364 break;
2365 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002366 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002367 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002368 break;
2369 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002370 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002371 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002372 break;
2373 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002374 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002375 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002376 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002377 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002378 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002379 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002380 break;
2381 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002382 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002383 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002384 break;
2385 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002386 m = (typeof(m)){"LPe1000", "PCIe",
2387 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002388 break;
2389 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002390 m = (typeof(m)){"LPe1000-SP", "PCIe",
2391 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002392 break;
2393 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002394 m = (typeof(m)){"LPe1002-SP", "PCIe",
2395 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002396 break;
dea31012005-04-17 16:05:31 -05002397 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002398 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002399 break;
2400 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002401 m = (typeof(m)){"LP111", "PCI-X2",
2402 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002403 break;
2404 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002405 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002406 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002407 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002408 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002409 break;
2410 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002411 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002412 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002413 break;
dea31012005-04-17 16:05:31 -05002414 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002415 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002416 break;
2417 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002418 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002419 break;
2420 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002421 m = (typeof(m)){"LP101", "PCI-X",
2422 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002423 break;
2424 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002425 m = (typeof(m)){"LP10000-S", "PCI",
2426 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002427 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002428 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002429 m = (typeof(m)){"LP11000-S", "PCI-X2",
2430 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002431 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002432 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002433 m = (typeof(m)){"LPe11000-S", "PCIe",
2434 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002435 break;
James Smartb87eab32007-04-25 09:53:28 -04002436 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002437 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002438 break;
2439 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002440 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002441 break;
2442 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002443 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002444 break;
2445 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002446 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002447 break;
2448 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002449 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002450 break;
2451 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002452 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002453 break;
James Smart84774a42008-08-24 21:50:06 -04002454 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002455 m = (typeof(m)){"LP21000", "PCIe",
2456 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002457 GE = 1;
2458 break;
2459 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002460 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002461 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002462 break;
2463 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002464 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002465 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002466 break;
2467 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002468 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002469 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002470 break;
James Smartda0436e2009-05-22 14:51:39 -04002471 case PCI_DEVICE_ID_TIGERSHARK:
2472 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002473 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002474 break;
James Smarta747c9c2009-11-18 15:41:10 -05002475 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002476 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002477 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2478 break;
2479 case PCI_DEVICE_ID_FALCON:
2480 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2481 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002482 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002483 case PCI_DEVICE_ID_BALIUS:
2484 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002485 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002486 break;
James Smart085c6472010-11-20 23:11:37 -05002487 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002488 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002489 break;
James Smart12222f42014-05-21 08:05:19 -04002490 case PCI_DEVICE_ID_LANCER_FC_VF:
2491 m = (typeof(m)){"LPe16000", "PCIe",
2492 "Obsolete, Unsupported Fibre Channel Adapter"};
2493 break;
James Smart085c6472010-11-20 23:11:37 -05002494 case PCI_DEVICE_ID_LANCER_FCOE:
2495 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002496 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002497 break;
James Smart12222f42014-05-21 08:05:19 -04002498 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2499 oneConnect = 1;
2500 m = (typeof(m)){"OCe15100", "PCIe",
2501 "Obsolete, Unsupported FCoE"};
2502 break;
James Smartd38dd522015-08-31 16:48:17 -04002503 case PCI_DEVICE_ID_LANCER_G6_FC:
2504 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2505 break;
James Smartc238b9b2018-02-22 08:18:44 -08002506 case PCI_DEVICE_ID_LANCER_G7_FC:
2507 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2508 break;
James Smartf8cafd32012-08-03 12:42:51 -04002509 case PCI_DEVICE_ID_SKYHAWK:
2510 case PCI_DEVICE_ID_SKYHAWK_VF:
2511 oneConnect = 1;
2512 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2513 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002514 default:
James Smarta747c9c2009-11-18 15:41:10 -05002515 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002516 break;
dea31012005-04-17 16:05:31 -05002517 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002518
2519 if (mdp && mdp[0] == '\0')
2520 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002521 /*
2522 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002523 * and we put the port number on the end
2524 */
2525 if (descp && descp[0] == '\0') {
2526 if (oneConnect)
2527 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002528 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002529 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002530 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002531 else if (max_speed == 0)
2532 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002533 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002534 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002535 else
2536 snprintf(descp, 255,
2537 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002538 m.name, max_speed, (GE) ? "GE" : "Gb",
2539 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002540 }
dea31012005-04-17 16:05:31 -05002541}
2542
James Smarte59058c2008-08-24 21:49:00 -04002543/**
James Smart3621a712009-04-06 18:47:14 -04002544 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002545 * @phba: pointer to lpfc hba data structure.
2546 * @pring: pointer to a IOCB ring.
2547 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2548 *
2549 * This routine posts a given number of IOCBs with the associated DMA buffer
2550 * descriptors specified by the cnt argument to the given IOCB ring.
2551 *
2552 * Return codes
2553 * The number of IOCBs NOT able to be posted to the IOCB ring.
2554 **/
dea31012005-04-17 16:05:31 -05002555int
James Smart495a7142008-06-14 22:52:59 -04002556lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002557{
2558 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002559 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002560 struct lpfc_dmabuf *mp1, *mp2;
2561
2562 cnt += pring->missbufcnt;
2563
2564 /* While there are buffers to post */
2565 while (cnt > 0) {
2566 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002567 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002568 if (iocb == NULL) {
2569 pring->missbufcnt = cnt;
2570 return cnt;
2571 }
dea31012005-04-17 16:05:31 -05002572 icmd = &iocb->iocb;
2573
2574 /* 2 buffers can be posted per command */
2575 /* Allocate buffer to post */
2576 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2577 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002578 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2579 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002580 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002581 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002582 pring->missbufcnt = cnt;
2583 return cnt;
2584 }
2585
2586 INIT_LIST_HEAD(&mp1->list);
2587 /* Allocate buffer to post */
2588 if (cnt > 1) {
2589 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2590 if (mp2)
2591 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2592 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002593 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002594 kfree(mp2);
dea31012005-04-17 16:05:31 -05002595 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2596 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002597 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002598 pring->missbufcnt = cnt;
2599 return cnt;
2600 }
2601
2602 INIT_LIST_HEAD(&mp2->list);
2603 } else {
2604 mp2 = NULL;
2605 }
2606
2607 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2608 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2609 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2610 icmd->ulpBdeCount = 1;
2611 cnt--;
2612 if (mp2) {
2613 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2614 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2615 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2616 cnt--;
2617 icmd->ulpBdeCount = 2;
2618 }
2619
2620 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2621 icmd->ulpLe = 1;
2622
James Smart3772a992009-05-22 14:50:54 -04002623 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2624 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002625 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2626 kfree(mp1);
2627 cnt++;
2628 if (mp2) {
2629 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2630 kfree(mp2);
2631 cnt++;
2632 }
James Bottomley604a3e32005-10-29 10:28:33 -05002633 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002634 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002635 return cnt;
2636 }
dea31012005-04-17 16:05:31 -05002637 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002638 if (mp2)
dea31012005-04-17 16:05:31 -05002639 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002640 }
2641 pring->missbufcnt = 0;
2642 return 0;
2643}
2644
James Smarte59058c2008-08-24 21:49:00 -04002645/**
James Smart3621a712009-04-06 18:47:14 -04002646 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002647 * @phba: pointer to lpfc hba data structure.
2648 *
2649 * This routine posts initial receive IOCB buffers to the ELS ring. The
2650 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002651 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002652 *
2653 * Return codes
2654 * 0 - success (currently always success)
2655 **/
dea31012005-04-17 16:05:31 -05002656static int
James Smart2e0fef82007-06-17 19:56:36 -05002657lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002658{
2659 struct lpfc_sli *psli = &phba->sli;
2660
2661 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002662 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002663 /* Ring 2 - FCP no buffers needed */
2664
2665 return 0;
2666}
2667
2668#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2669
James Smarte59058c2008-08-24 21:49:00 -04002670/**
James Smart3621a712009-04-06 18:47:14 -04002671 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002672 * @HashResultPointer: pointer to an array as hash table.
2673 *
2674 * This routine sets up the initial values to the array of hash table entries
2675 * for the LC HBAs.
2676 **/
dea31012005-04-17 16:05:31 -05002677static void
2678lpfc_sha_init(uint32_t * HashResultPointer)
2679{
2680 HashResultPointer[0] = 0x67452301;
2681 HashResultPointer[1] = 0xEFCDAB89;
2682 HashResultPointer[2] = 0x98BADCFE;
2683 HashResultPointer[3] = 0x10325476;
2684 HashResultPointer[4] = 0xC3D2E1F0;
2685}
2686
James Smarte59058c2008-08-24 21:49:00 -04002687/**
James Smart3621a712009-04-06 18:47:14 -04002688 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002689 * @HashResultPointer: pointer to an initial/result hash table.
2690 * @HashWorkingPointer: pointer to an working hash table.
2691 *
2692 * This routine iterates an initial hash table pointed by @HashResultPointer
2693 * with the values from the working hash table pointeed by @HashWorkingPointer.
2694 * The results are putting back to the initial hash table, returned through
2695 * the @HashResultPointer as the result hash table.
2696 **/
dea31012005-04-17 16:05:31 -05002697static void
2698lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2699{
2700 int t;
2701 uint32_t TEMP;
2702 uint32_t A, B, C, D, E;
2703 t = 16;
2704 do {
2705 HashWorkingPointer[t] =
2706 S(1,
2707 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2708 8] ^
2709 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2710 } while (++t <= 79);
2711 t = 0;
2712 A = HashResultPointer[0];
2713 B = HashResultPointer[1];
2714 C = HashResultPointer[2];
2715 D = HashResultPointer[3];
2716 E = HashResultPointer[4];
2717
2718 do {
2719 if (t < 20) {
2720 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2721 } else if (t < 40) {
2722 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2723 } else if (t < 60) {
2724 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2725 } else {
2726 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2727 }
2728 TEMP += S(5, A) + E + HashWorkingPointer[t];
2729 E = D;
2730 D = C;
2731 C = S(30, B);
2732 B = A;
2733 A = TEMP;
2734 } while (++t <= 79);
2735
2736 HashResultPointer[0] += A;
2737 HashResultPointer[1] += B;
2738 HashResultPointer[2] += C;
2739 HashResultPointer[3] += D;
2740 HashResultPointer[4] += E;
2741
2742}
2743
James Smarte59058c2008-08-24 21:49:00 -04002744/**
James Smart3621a712009-04-06 18:47:14 -04002745 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002746 * @RandomChallenge: pointer to the entry of host challenge random number array.
2747 * @HashWorking: pointer to the entry of the working hash array.
2748 *
2749 * This routine calculates the working hash array referred by @HashWorking
2750 * from the challenge random numbers associated with the host, referred by
2751 * @RandomChallenge. The result is put into the entry of the working hash
2752 * array and returned by reference through @HashWorking.
2753 **/
dea31012005-04-17 16:05:31 -05002754static void
2755lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2756{
2757 *HashWorking = (*RandomChallenge ^ *HashWorking);
2758}
2759
James Smarte59058c2008-08-24 21:49:00 -04002760/**
James Smart3621a712009-04-06 18:47:14 -04002761 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002762 * @phba: pointer to lpfc hba data structure.
2763 * @hbainit: pointer to an array of unsigned 32-bit integers.
2764 *
2765 * This routine performs the special handling for LC HBA initialization.
2766 **/
dea31012005-04-17 16:05:31 -05002767void
2768lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2769{
2770 int t;
2771 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002772 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002773
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002774 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002775 if (!HashWorking)
2776 return;
2777
dea31012005-04-17 16:05:31 -05002778 HashWorking[0] = HashWorking[78] = *pwwnn++;
2779 HashWorking[1] = HashWorking[79] = *pwwnn;
2780
2781 for (t = 0; t < 7; t++)
2782 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2783
2784 lpfc_sha_init(hbainit);
2785 lpfc_sha_iterate(hbainit, HashWorking);
2786 kfree(HashWorking);
2787}
2788
James Smarte59058c2008-08-24 21:49:00 -04002789/**
James Smart3621a712009-04-06 18:47:14 -04002790 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002791 * @vport: pointer to a virtual N_Port data structure.
2792 *
2793 * This routine performs the necessary cleanups before deleting the @vport.
2794 * It invokes the discovery state machine to perform necessary state
2795 * transitions and to release the ndlps associated with the @vport. Note,
2796 * the physical port is treated as @vport 0.
2797 **/
James Smart87af33f2007-10-27 13:37:43 -04002798void
James Smart2e0fef82007-06-17 19:56:36 -05002799lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002800{
James Smart87af33f2007-10-27 13:37:43 -04002801 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002802 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002803 int i = 0;
dea31012005-04-17 16:05:31 -05002804
James Smart87af33f2007-10-27 13:37:43 -04002805 if (phba->link_state > LPFC_LINK_DOWN)
2806 lpfc_port_link_failure(vport);
2807
2808 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002809 if (!NLP_CHK_NODE_ACT(ndlp)) {
2810 ndlp = lpfc_enable_node(vport, ndlp,
2811 NLP_STE_UNUSED_NODE);
2812 if (!ndlp)
2813 continue;
2814 spin_lock_irq(&phba->ndlp_lock);
2815 NLP_SET_FREE_REQ(ndlp);
2816 spin_unlock_irq(&phba->ndlp_lock);
2817 /* Trigger the release of the ndlp memory */
2818 lpfc_nlp_put(ndlp);
2819 continue;
2820 }
2821 spin_lock_irq(&phba->ndlp_lock);
2822 if (NLP_CHK_FREE_REQ(ndlp)) {
2823 /* The ndlp should not be in memory free mode already */
2824 spin_unlock_irq(&phba->ndlp_lock);
2825 continue;
2826 } else
2827 /* Indicate request for freeing ndlp memory */
2828 NLP_SET_FREE_REQ(ndlp);
2829 spin_unlock_irq(&phba->ndlp_lock);
2830
James Smart58da1ff2008-04-07 10:15:56 -04002831 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2832 ndlp->nlp_DID == Fabric_DID) {
2833 /* Just free up ndlp with Fabric_DID for vports */
2834 lpfc_nlp_put(ndlp);
2835 continue;
2836 }
2837
James Smarteff4a012012-01-18 16:25:25 -05002838 /* take care of nodes in unused state before the state
2839 * machine taking action.
2840 */
2841 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2842 lpfc_nlp_put(ndlp);
2843 continue;
2844 }
2845
James Smart87af33f2007-10-27 13:37:43 -04002846 if (ndlp->nlp_type & NLP_FABRIC)
2847 lpfc_disc_state_machine(vport, ndlp, NULL,
2848 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002849
James Smart87af33f2007-10-27 13:37:43 -04002850 lpfc_disc_state_machine(vport, ndlp, NULL,
2851 NLP_EVT_DEVICE_RM);
2852 }
2853
James Smarta8adb832007-10-27 13:37:53 -04002854 /* At this point, ALL ndlp's should be gone
2855 * because of the previous NLP_EVT_DEVICE_RM.
2856 * Lets wait for this to happen, if needed.
2857 */
James Smart87af33f2007-10-27 13:37:43 -04002858 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002859 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002860 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002861 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002862 list_for_each_entry_safe(ndlp, next_ndlp,
2863 &vport->fc_nodes, nlp_listp) {
2864 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2865 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002866 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002867 "usgmap:x%x refcnt:%d\n",
2868 ndlp->nlp_DID, (void *)ndlp,
2869 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002870 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002871 }
James Smarta8adb832007-10-27 13:37:53 -04002872 break;
James Smart87af33f2007-10-27 13:37:43 -04002873 }
James Smarta8adb832007-10-27 13:37:53 -04002874
2875 /* Wait for any activity on ndlps to settle */
2876 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002877 }
James Smart1151e3e2011-02-16 12:39:35 -05002878 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002879}
2880
James Smarte59058c2008-08-24 21:49:00 -04002881/**
James Smart3621a712009-04-06 18:47:14 -04002882 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002883 * @vport: pointer to a virtual N_Port data structure.
2884 *
2885 * This routine stops all the timers associated with a @vport. This function
2886 * is invoked before disabling or deleting a @vport. Note that the physical
2887 * port is treated as @vport 0.
2888 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002889void
2890lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002891{
James Smart92d7f7b2007-06-17 19:56:38 -05002892 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002893 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002894 lpfc_can_disctmo(vport);
2895 return;
dea31012005-04-17 16:05:31 -05002896}
2897
James Smarte59058c2008-08-24 21:49:00 -04002898/**
James Smartecfd03c2010-02-12 14:41:27 -05002899 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2900 * @phba: pointer to lpfc hba data structure.
2901 *
2902 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2903 * caller of this routine should already hold the host lock.
2904 **/
2905void
2906__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2907{
James Smart5ac6b302010-10-22 11:05:36 -04002908 /* Clear pending FCF rediscovery wait flag */
2909 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2910
James Smartecfd03c2010-02-12 14:41:27 -05002911 /* Now, try to stop the timer */
2912 del_timer(&phba->fcf.redisc_wait);
2913}
2914
2915/**
2916 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2917 * @phba: pointer to lpfc hba data structure.
2918 *
2919 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2920 * checks whether the FCF rediscovery wait timer is pending with the host
2921 * lock held before proceeding with disabling the timer and clearing the
2922 * wait timer pendig flag.
2923 **/
2924void
2925lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2926{
2927 spin_lock_irq(&phba->hbalock);
2928 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2929 /* FCF rediscovery timer already fired or stopped */
2930 spin_unlock_irq(&phba->hbalock);
2931 return;
2932 }
2933 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002934 /* Clear failover in progress flags */
2935 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002936 spin_unlock_irq(&phba->hbalock);
2937}
2938
2939/**
James Smart3772a992009-05-22 14:50:54 -04002940 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002941 * @phba: pointer to lpfc hba data structure.
2942 *
2943 * This routine stops all the timers associated with a HBA. This function is
2944 * invoked before either putting a HBA offline or unloading the driver.
2945 **/
James Smart3772a992009-05-22 14:50:54 -04002946void
2947lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002948{
James Smartcdb42be2019-01-28 11:14:21 -08002949 if (phba->pport)
2950 lpfc_stop_vport_timers(phba->pport);
James Smart32517fc2019-01-28 11:14:33 -08002951 cancel_delayed_work_sync(&phba->eq_delay_work);
James Smart2e0fef82007-06-17 19:56:36 -05002952 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002953 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002954 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002955 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002956 if (phba->sli_rev == LPFC_SLI_REV4) {
2957 del_timer_sync(&phba->rrq_tmr);
2958 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2959 }
James Smart3772a992009-05-22 14:50:54 -04002960 phba->hb_outstanding = 0;
2961
2962 switch (phba->pci_dev_grp) {
2963 case LPFC_PCI_DEV_LP:
2964 /* Stop any LightPulse device specific driver timers */
2965 del_timer_sync(&phba->fcp_poll_timer);
2966 break;
2967 case LPFC_PCI_DEV_OC:
Paul Walmsleycc0e5f12019-07-11 20:52:33 -07002968 /* Stop any OneConnect device specific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002969 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002970 break;
2971 default:
2972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2973 "0297 Invalid device group (x%x)\n",
2974 phba->pci_dev_grp);
2975 break;
2976 }
James Smart2e0fef82007-06-17 19:56:36 -05002977 return;
dea31012005-04-17 16:05:31 -05002978}
2979
James Smarte59058c2008-08-24 21:49:00 -04002980/**
James Smart3621a712009-04-06 18:47:14 -04002981 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002982 * @phba: pointer to lpfc hba data structure.
2983 *
2984 * This routine marks a HBA's management interface as blocked. Once the HBA's
2985 * management interface is marked as blocked, all the user space access to
2986 * the HBA, whether they are from sysfs interface or libdfc interface will
2987 * all be blocked. The HBA is set to block the management interface when the
2988 * driver prepares the HBA interface for online or offline.
2989 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002990static void
James Smart618a5232012-06-12 13:54:36 -04002991lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002992{
2993 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002994 uint8_t actcmd = MBX_HEARTBEAT;
2995 unsigned long timeout;
2996
Adrian Bunka6ababd2007-11-05 18:07:33 +01002997 spin_lock_irqsave(&phba->hbalock, iflag);
2998 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002999 spin_unlock_irqrestore(&phba->hbalock, iflag);
3000 if (mbx_action == LPFC_MBX_NO_WAIT)
3001 return;
3002 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
3003 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003004 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04003005 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04003006 /* Determine how long we might wait for the active mailbox
3007 * command to be gracefully completed by firmware.
3008 */
3009 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3010 phba->sli.mbox_active) * 1000) + jiffies;
3011 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003012 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003013
James Smart6e7288d2010-06-07 15:23:35 -04003014 /* Wait for the outstnading mailbox command to complete */
3015 while (phba->sli.mbox_active) {
3016 /* Check active mailbox complete status every 2ms */
3017 msleep(2);
3018 if (time_after(jiffies, timeout)) {
3019 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3020 "2813 Mgmt IO is Blocked %x "
3021 "- mbox cmd %x still active\n",
3022 phba->sli.sli_flag, actcmd);
3023 break;
3024 }
3025 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003026}
3027
James Smarte59058c2008-08-24 21:49:00 -04003028/**
James Smart6b5151f2012-01-18 16:24:06 -05003029 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3030 * @phba: pointer to lpfc hba data structure.
3031 *
3032 * Allocate RPIs for all active remote nodes. This is needed whenever
3033 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3034 * is to fixup the temporary rpi assignments.
3035 **/
3036void
3037lpfc_sli4_node_prep(struct lpfc_hba *phba)
3038{
3039 struct lpfc_nodelist *ndlp, *next_ndlp;
3040 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003041 int i, rpi;
3042 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003043
3044 if (phba->sli_rev != LPFC_SLI_REV4)
3045 return;
3046
3047 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003048 if (vports == NULL)
3049 return;
James Smart6b5151f2012-01-18 16:24:06 -05003050
James Smart9d3d3402017-04-21 16:05:00 -07003051 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3052 if (vports[i]->load_flag & FC_UNLOADING)
3053 continue;
3054
3055 list_for_each_entry_safe(ndlp, next_ndlp,
3056 &vports[i]->fc_nodes,
3057 nlp_listp) {
3058 if (!NLP_CHK_NODE_ACT(ndlp))
3059 continue;
3060 rpi = lpfc_sli4_alloc_rpi(phba);
3061 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3062 spin_lock_irqsave(&phba->ndlp_lock, flags);
3063 NLP_CLR_NODE_ACT(ndlp);
3064 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3065 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003066 }
James Smart9d3d3402017-04-21 16:05:00 -07003067 ndlp->nlp_rpi = rpi;
3068 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3069 "0009 rpi:%x DID:%x "
3070 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3071 ndlp->nlp_DID, ndlp->nlp_flag,
3072 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003073 }
3074 }
3075 lpfc_destroy_vport_work_array(phba, vports);
3076}
3077
3078/**
James Smartc4908502019-01-28 11:14:28 -08003079 * lpfc_create_expedite_pool - create expedite pool
3080 * @phba: pointer to lpfc hba data structure.
3081 *
3082 * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
3083 * to expedite pool. Mark them as expedite.
3084 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003085static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003086{
3087 struct lpfc_sli4_hdw_queue *qp;
3088 struct lpfc_io_buf *lpfc_ncmd;
3089 struct lpfc_io_buf *lpfc_ncmd_next;
3090 struct lpfc_epd_pool *epd_pool;
3091 unsigned long iflag;
3092
3093 epd_pool = &phba->epd_pool;
3094 qp = &phba->sli4_hba.hdwq[0];
3095
3096 spin_lock_init(&epd_pool->lock);
3097 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3098 spin_lock(&epd_pool->lock);
3099 INIT_LIST_HEAD(&epd_pool->list);
3100 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3101 &qp->lpfc_io_buf_list_put, list) {
3102 list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
3103 lpfc_ncmd->expedite = true;
3104 qp->put_io_bufs--;
3105 epd_pool->count++;
3106 if (epd_pool->count >= XRI_BATCH)
3107 break;
3108 }
3109 spin_unlock(&epd_pool->lock);
3110 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3111}
3112
3113/**
3114 * lpfc_destroy_expedite_pool - destroy expedite pool
3115 * @phba: pointer to lpfc hba data structure.
3116 *
3117 * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
3118 * of HWQ 0. Clear the mark.
3119 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003120static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003121{
3122 struct lpfc_sli4_hdw_queue *qp;
3123 struct lpfc_io_buf *lpfc_ncmd;
3124 struct lpfc_io_buf *lpfc_ncmd_next;
3125 struct lpfc_epd_pool *epd_pool;
3126 unsigned long iflag;
3127
3128 epd_pool = &phba->epd_pool;
3129 qp = &phba->sli4_hba.hdwq[0];
3130
3131 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3132 spin_lock(&epd_pool->lock);
3133 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3134 &epd_pool->list, list) {
3135 list_move_tail(&lpfc_ncmd->list,
3136 &qp->lpfc_io_buf_list_put);
3137 lpfc_ncmd->flags = false;
3138 qp->put_io_bufs++;
3139 epd_pool->count--;
3140 }
3141 spin_unlock(&epd_pool->lock);
3142 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3143}
3144
3145/**
3146 * lpfc_create_multixri_pools - create multi-XRI pools
3147 * @phba: pointer to lpfc hba data structure.
3148 *
3149 * This routine initialize public, private per HWQ. Then, move XRIs from
3150 * lpfc_io_buf_list_put to public pool. High and low watermark are also
3151 * Initialized.
3152 **/
3153void lpfc_create_multixri_pools(struct lpfc_hba *phba)
3154{
3155 u32 i, j;
3156 u32 hwq_count;
3157 u32 count_per_hwq;
3158 struct lpfc_io_buf *lpfc_ncmd;
3159 struct lpfc_io_buf *lpfc_ncmd_next;
3160 unsigned long iflag;
3161 struct lpfc_sli4_hdw_queue *qp;
3162 struct lpfc_multixri_pool *multixri_pool;
3163 struct lpfc_pbl_pool *pbl_pool;
3164 struct lpfc_pvt_pool *pvt_pool;
3165
3166 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3167 "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
3168 phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
3169 phba->sli4_hba.io_xri_cnt);
3170
3171 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3172 lpfc_create_expedite_pool(phba);
3173
3174 hwq_count = phba->cfg_hdw_queue;
3175 count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
3176
3177 for (i = 0; i < hwq_count; i++) {
3178 multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
3179
3180 if (!multixri_pool) {
3181 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3182 "1238 Failed to allocate memory for "
3183 "multixri_pool\n");
3184
3185 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3186 lpfc_destroy_expedite_pool(phba);
3187
3188 j = 0;
3189 while (j < i) {
3190 qp = &phba->sli4_hba.hdwq[j];
3191 kfree(qp->p_multixri_pool);
3192 j++;
3193 }
3194 phba->cfg_xri_rebalancing = 0;
3195 return;
3196 }
3197
3198 qp = &phba->sli4_hba.hdwq[i];
3199 qp->p_multixri_pool = multixri_pool;
3200
3201 multixri_pool->xri_limit = count_per_hwq;
3202 multixri_pool->rrb_next_hwqid = i;
3203
3204 /* Deal with public free xri pool */
3205 pbl_pool = &multixri_pool->pbl_pool;
3206 spin_lock_init(&pbl_pool->lock);
3207 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3208 spin_lock(&pbl_pool->lock);
3209 INIT_LIST_HEAD(&pbl_pool->list);
3210 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3211 &qp->lpfc_io_buf_list_put, list) {
3212 list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
3213 qp->put_io_bufs--;
3214 pbl_pool->count++;
3215 }
3216 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3217 "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
3218 pbl_pool->count, i);
3219 spin_unlock(&pbl_pool->lock);
3220 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3221
3222 /* Deal with private free xri pool */
3223 pvt_pool = &multixri_pool->pvt_pool;
3224 pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
3225 pvt_pool->low_watermark = XRI_BATCH;
3226 spin_lock_init(&pvt_pool->lock);
3227 spin_lock_irqsave(&pvt_pool->lock, iflag);
3228 INIT_LIST_HEAD(&pvt_pool->list);
3229 pvt_pool->count = 0;
3230 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
3231 }
3232}
3233
3234/**
3235 * lpfc_destroy_multixri_pools - destroy multi-XRI pools
3236 * @phba: pointer to lpfc hba data structure.
3237 *
3238 * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
3239 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07003240static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
James Smartc4908502019-01-28 11:14:28 -08003241{
3242 u32 i;
3243 u32 hwq_count;
3244 struct lpfc_io_buf *lpfc_ncmd;
3245 struct lpfc_io_buf *lpfc_ncmd_next;
3246 unsigned long iflag;
3247 struct lpfc_sli4_hdw_queue *qp;
3248 struct lpfc_multixri_pool *multixri_pool;
3249 struct lpfc_pbl_pool *pbl_pool;
3250 struct lpfc_pvt_pool *pvt_pool;
3251
3252 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3253 lpfc_destroy_expedite_pool(phba);
3254
James Smartc66a9192019-03-12 16:30:19 -07003255 if (!(phba->pport->load_flag & FC_UNLOADING)) {
3256 lpfc_sli_flush_fcp_rings(phba);
3257
3258 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3259 lpfc_sli_flush_nvme_rings(phba);
3260 }
3261
James Smartc4908502019-01-28 11:14:28 -08003262 hwq_count = phba->cfg_hdw_queue;
3263
3264 for (i = 0; i < hwq_count; i++) {
3265 qp = &phba->sli4_hba.hdwq[i];
3266 multixri_pool = qp->p_multixri_pool;
3267 if (!multixri_pool)
3268 continue;
3269
3270 qp->p_multixri_pool = NULL;
3271
3272 spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
3273
3274 /* Deal with public free xri pool */
3275 pbl_pool = &multixri_pool->pbl_pool;
3276 spin_lock(&pbl_pool->lock);
3277
3278 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3279 "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
3280 pbl_pool->count, i);
3281
3282 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3283 &pbl_pool->list, list) {
3284 list_move_tail(&lpfc_ncmd->list,
3285 &qp->lpfc_io_buf_list_put);
3286 qp->put_io_bufs++;
3287 pbl_pool->count--;
3288 }
3289
3290 INIT_LIST_HEAD(&pbl_pool->list);
3291 pbl_pool->count = 0;
3292
3293 spin_unlock(&pbl_pool->lock);
3294
3295 /* Deal with private free xri pool */
3296 pvt_pool = &multixri_pool->pvt_pool;
3297 spin_lock(&pvt_pool->lock);
3298
3299 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3300 "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
3301 pvt_pool->count, i);
3302
3303 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3304 &pvt_pool->list, list) {
3305 list_move_tail(&lpfc_ncmd->list,
3306 &qp->lpfc_io_buf_list_put);
3307 qp->put_io_bufs++;
3308 pvt_pool->count--;
3309 }
3310
3311 INIT_LIST_HEAD(&pvt_pool->list);
3312 pvt_pool->count = 0;
3313
3314 spin_unlock(&pvt_pool->lock);
3315 spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
3316
3317 kfree(multixri_pool);
3318 }
3319}
3320
3321/**
James Smart3621a712009-04-06 18:47:14 -04003322 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003323 * @phba: pointer to lpfc hba data structure.
3324 *
3325 * This routine initializes the HBA and brings a HBA online. During this
3326 * process, the management interface is blocked to prevent user space access
3327 * to the HBA interfering with the driver initialization.
3328 *
3329 * Return codes
3330 * 0 - successful
3331 * 1 - failed
3332 **/
dea31012005-04-17 16:05:31 -05003333int
James Smart2e0fef82007-06-17 19:56:36 -05003334lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003335{
Julia Lawall372bd282008-12-16 16:15:08 +01003336 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003337 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003338 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003339 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003340
dea31012005-04-17 16:05:31 -05003341 if (!phba)
3342 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003343 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003344
James Smart2e0fef82007-06-17 19:56:36 -05003345 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003346 return 0;
3347
James Smarted957682007-06-17 19:56:37 -05003348 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003349 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003350
James Smart618a5232012-06-12 13:54:36 -04003351 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003352
James Smartda0436e2009-05-22 14:51:39 -04003353 if (phba->sli_rev == LPFC_SLI_REV4) {
3354 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3355 lpfc_unblock_mgmt_io(phba);
3356 return 1;
3357 }
James Smart16a3a202013-04-17 20:14:38 -04003358 spin_lock_irq(&phba->hbalock);
3359 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3360 vpis_cleared = true;
3361 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003362
3363 /* Reestablish the local initiator port.
3364 * The offline process destroyed the previous lport.
3365 */
3366 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3367 !phba->nvmet_support) {
3368 error = lpfc_nvme_create_localport(phba->pport);
3369 if (error)
3370 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3371 "6132 NVME restore reg failed "
3372 "on nvmei error x%x\n", error);
3373 }
James Smartda0436e2009-05-22 14:51:39 -04003374 } else {
James Smart895427b2017-02-12 13:52:30 -08003375 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003376 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3377 lpfc_unblock_mgmt_io(phba);
3378 return 1;
3379 }
James Smart46fa3112007-04-25 09:51:45 -04003380 }
dea31012005-04-17 16:05:31 -05003381
James Smart549e55c2007-08-02 11:09:51 -04003382 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003383 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003384 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003385 struct Scsi_Host *shost;
3386 shost = lpfc_shost_from_vport(vports[i]);
3387 spin_lock_irq(shost->host_lock);
3388 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3389 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3390 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003391 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003392 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003393 if ((vpis_cleared) &&
3394 (vports[i]->port_type !=
3395 LPFC_PHYSICAL_PORT))
3396 vports[i]->vpi = 0;
3397 }
James Smart549e55c2007-08-02 11:09:51 -04003398 spin_unlock_irq(shost->host_lock);
3399 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003400 }
3401 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003402
James Smartc4908502019-01-28 11:14:28 -08003403 if (phba->cfg_xri_rebalancing)
3404 lpfc_create_multixri_pools(phba);
3405
James Smart46fa3112007-04-25 09:51:45 -04003406 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003407 return 0;
3408}
3409
James Smarte59058c2008-08-24 21:49:00 -04003410/**
James Smart3621a712009-04-06 18:47:14 -04003411 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003412 * @phba: pointer to lpfc hba data structure.
3413 *
3414 * This routine marks a HBA's management interface as not blocked. Once the
3415 * HBA's management interface is marked as not blocked, all the user space
3416 * access to the HBA, whether they are from sysfs interface or libdfc
3417 * interface will be allowed. The HBA is set to block the management interface
3418 * when the driver prepares the HBA interface for online or offline and then
3419 * set to unblock the management interface afterwards.
3420 **/
James Smart46fa3112007-04-25 09:51:45 -04003421void
James Smart46fa3112007-04-25 09:51:45 -04003422lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3423{
3424 unsigned long iflag;
3425
James Smart2e0fef82007-06-17 19:56:36 -05003426 spin_lock_irqsave(&phba->hbalock, iflag);
3427 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3428 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003429}
3430
James Smarte59058c2008-08-24 21:49:00 -04003431/**
James Smart3621a712009-04-06 18:47:14 -04003432 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003433 * @phba: pointer to lpfc hba data structure.
3434 *
3435 * This routine is invoked to prepare a HBA to be brought offline. It performs
3436 * unregistration login to all the nodes on all vports and flushes the mailbox
3437 * queue to make it ready to be brought offline.
3438 **/
James Smart46fa3112007-04-25 09:51:45 -04003439void
James Smart618a5232012-06-12 13:54:36 -04003440lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003441{
James Smart2e0fef82007-06-17 19:56:36 -05003442 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003443 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003444 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003445 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003446 int i;
dea31012005-04-17 16:05:31 -05003447
James Smart2e0fef82007-06-17 19:56:36 -05003448 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003449 return;
dea31012005-04-17 16:05:31 -05003450
James Smart618a5232012-06-12 13:54:36 -04003451 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003452
3453 lpfc_linkdown(phba);
3454
James Smart87af33f2007-10-27 13:37:43 -04003455 /* Issue an unreg_login to all nodes on all vports */
3456 vports = lpfc_create_vport_work_array(phba);
3457 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003458 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003459 if (vports[i]->load_flag & FC_UNLOADING)
3460 continue;
James Smart72100cc2010-02-12 14:43:01 -05003461 shost = lpfc_shost_from_vport(vports[i]);
3462 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003463 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003464 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3465 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003466 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003467
James Smart87af33f2007-10-27 13:37:43 -04003468 shost = lpfc_shost_from_vport(vports[i]);
3469 list_for_each_entry_safe(ndlp, next_ndlp,
3470 &vports[i]->fc_nodes,
3471 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003472 if (!NLP_CHK_NODE_ACT(ndlp))
3473 continue;
James Smart87af33f2007-10-27 13:37:43 -04003474 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3475 continue;
3476 if (ndlp->nlp_type & NLP_FABRIC) {
3477 lpfc_disc_state_machine(vports[i], ndlp,
3478 NULL, NLP_EVT_DEVICE_RECOVERY);
3479 lpfc_disc_state_machine(vports[i], ndlp,
3480 NULL, NLP_EVT_DEVICE_RM);
3481 }
3482 spin_lock_irq(shost->host_lock);
3483 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003484 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003485 /*
3486 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003487 * RPI. Get a new RPI when the adapter port
3488 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003489 */
James Smartbe6bb942015-04-07 15:07:22 -04003490 if (phba->sli_rev == LPFC_SLI_REV4) {
3491 lpfc_printf_vlog(ndlp->vport,
3492 KERN_INFO, LOG_NODE,
3493 "0011 lpfc_offline: "
3494 "ndlp:x%p did %x "
3495 "usgmap:x%x rpi:%x\n",
3496 ndlp, ndlp->nlp_DID,
3497 ndlp->nlp_usg_map,
3498 ndlp->nlp_rpi);
3499
James Smart6b5151f2012-01-18 16:24:06 -05003500 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003501 }
James Smart87af33f2007-10-27 13:37:43 -04003502 lpfc_unreg_rpi(vports[i], ndlp);
3503 }
3504 }
3505 }
James Smart09372822008-01-11 01:52:54 -05003506 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003507
James Smart618a5232012-06-12 13:54:36 -04003508 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003509
3510 if (phba->wq)
3511 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003512}
3513
James Smarte59058c2008-08-24 21:49:00 -04003514/**
James Smart3621a712009-04-06 18:47:14 -04003515 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003516 * @phba: pointer to lpfc hba data structure.
3517 *
3518 * This routine actually brings a HBA offline. It stops all the timers
3519 * associated with the HBA, brings down the SLI layer, and eventually
3520 * marks the HBA as in offline state for the upper layer protocol.
3521 **/
James Smart46fa3112007-04-25 09:51:45 -04003522void
James Smart2e0fef82007-06-17 19:56:36 -05003523lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003524{
James Smart549e55c2007-08-02 11:09:51 -04003525 struct Scsi_Host *shost;
3526 struct lpfc_vport **vports;
3527 int i;
James Smart46fa3112007-04-25 09:51:45 -04003528
James Smart549e55c2007-08-02 11:09:51 -04003529 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003530 return;
James Smart688a8862006-07-06 15:49:56 -04003531
James Smartda0436e2009-05-22 14:51:39 -04003532 /* stop port and all timers associated with this hba */
3533 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003534
3535 /* Tear down the local and target port registrations. The
3536 * nvme transports need to cleanup.
3537 */
3538 lpfc_nvmet_destroy_targetport(phba);
3539 lpfc_nvme_destroy_localport(phba->pport);
3540
James Smart51ef4c22007-08-02 11:10:31 -04003541 vports = lpfc_create_vport_work_array(phba);
3542 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003543 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003544 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003545 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003546 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003547 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003548 /* Bring down the SLI Layer and cleanup. The HBA is offline
3549 now. */
3550 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003551 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003552 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003553 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003554 vports = lpfc_create_vport_work_array(phba);
3555 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003556 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003557 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003558 spin_lock_irq(shost->host_lock);
3559 vports[i]->work_port_events = 0;
3560 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3561 spin_unlock_irq(shost->host_lock);
3562 }
James Smart09372822008-01-11 01:52:54 -05003563 lpfc_destroy_vport_work_array(phba, vports);
James Smartc4908502019-01-28 11:14:28 -08003564
3565 if (phba->cfg_xri_rebalancing)
3566 lpfc_destroy_multixri_pools(phba);
dea31012005-04-17 16:05:31 -05003567}
3568
James Smarte59058c2008-08-24 21:49:00 -04003569/**
James Smart3621a712009-04-06 18:47:14 -04003570 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003571 * @phba: pointer to lpfc hba data structure.
3572 *
3573 * This routine is to free all the SCSI buffers and IOCBs from the driver
3574 * list back to kernel. It is called from lpfc_pci_remove_one to free
3575 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003576 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003577static void
James Smart2e0fef82007-06-17 19:56:36 -05003578lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003579{
James Smartc4908502019-01-28 11:14:28 -08003580 struct lpfc_io_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003581
James Smart895427b2017-02-12 13:52:30 -08003582 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3583 return;
3584
James Smart2e0fef82007-06-17 19:56:36 -05003585 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003586
dea31012005-04-17 16:05:31 -05003587 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003588
3589 spin_lock(&phba->scsi_buf_list_put_lock);
3590 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3591 list) {
dea31012005-04-17 16:05:31 -05003592 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003593 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003594 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003595 kfree(sb);
3596 phba->total_scsi_bufs--;
3597 }
James Smarta40fc5f2013-04-17 20:17:40 -04003598 spin_unlock(&phba->scsi_buf_list_put_lock);
3599
3600 spin_lock(&phba->scsi_buf_list_get_lock);
3601 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3602 list) {
3603 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003604 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003605 sb->dma_handle);
3606 kfree(sb);
3607 phba->total_scsi_bufs--;
3608 }
3609 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003610 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003611}
James Smart0794d602019-01-28 11:14:19 -08003612
James Smart8a9d2e82012-05-09 21:16:12 -04003613/**
James Smart5e5b5112019-01-28 11:14:22 -08003614 * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
James Smart895427b2017-02-12 13:52:30 -08003615 * @phba: pointer to lpfc hba data structure.
3616 *
James Smart0794d602019-01-28 11:14:19 -08003617 * This routine is to free all the IO buffers and IOCBs from the driver
James Smart895427b2017-02-12 13:52:30 -08003618 * list back to kernel. It is called from lpfc_pci_remove_one to free
3619 * the internal resources before the device is removed from the system.
3620 **/
James Smartc4908502019-01-28 11:14:28 -08003621void
James Smart5e5b5112019-01-28 11:14:22 -08003622lpfc_io_free(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08003623{
James Smartc4908502019-01-28 11:14:28 -08003624 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart5e5b5112019-01-28 11:14:22 -08003625 struct lpfc_sli4_hdw_queue *qp;
3626 int idx;
James Smart895427b2017-02-12 13:52:30 -08003627
James Smart5e5b5112019-01-28 11:14:22 -08003628 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3629 qp = &phba->sli4_hba.hdwq[idx];
3630 /* Release all the lpfc_nvme_bufs maintained by this host. */
3631 spin_lock(&qp->io_buf_list_put_lock);
3632 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3633 &qp->lpfc_io_buf_list_put,
3634 list) {
3635 list_del(&lpfc_ncmd->list);
3636 qp->put_io_bufs--;
3637 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3638 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3639 kfree(lpfc_ncmd);
3640 qp->total_io_bufs--;
3641 }
3642 spin_unlock(&qp->io_buf_list_put_lock);
James Smart895427b2017-02-12 13:52:30 -08003643
James Smart5e5b5112019-01-28 11:14:22 -08003644 spin_lock(&qp->io_buf_list_get_lock);
3645 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3646 &qp->lpfc_io_buf_list_get,
3647 list) {
3648 list_del(&lpfc_ncmd->list);
3649 qp->get_io_bufs--;
3650 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
3651 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
3652 kfree(lpfc_ncmd);
3653 qp->total_io_bufs--;
3654 }
3655 spin_unlock(&qp->io_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003656 }
James Smart895427b2017-02-12 13:52:30 -08003657}
James Smart0794d602019-01-28 11:14:19 -08003658
James Smart895427b2017-02-12 13:52:30 -08003659/**
3660 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003661 * @phba: pointer to lpfc hba data structure.
3662 *
3663 * This routine first calculates the sizes of the current els and allocated
3664 * scsi sgl lists, and then goes through all sgls to updates the physical
3665 * XRIs assigned due to port function reset. During port initialization, the
3666 * current els and allocated scsi sgl lists are 0s.
3667 *
3668 * Return codes
3669 * 0 - successful (for now, it always returns 0)
3670 **/
3671int
James Smart895427b2017-02-12 13:52:30 -08003672lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003673{
3674 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003675 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003676 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003677 int rc;
3678
3679 /*
3680 * update on pci function's els xri-sgl list
3681 */
3682 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003683
James Smart8a9d2e82012-05-09 21:16:12 -04003684 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3685 /* els xri-sgl expanded */
3686 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3687 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3688 "3157 ELS xri-sgl count increased from "
3689 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3690 els_xri_cnt);
3691 /* allocate the additional els sgls */
3692 for (i = 0; i < xri_cnt; i++) {
3693 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3694 GFP_KERNEL);
3695 if (sglq_entry == NULL) {
3696 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3697 "2562 Failure to allocate an "
3698 "ELS sgl entry:%d\n", i);
3699 rc = -ENOMEM;
3700 goto out_free_mem;
3701 }
3702 sglq_entry->buff_type = GEN_BUFF_TYPE;
3703 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3704 &sglq_entry->phys);
3705 if (sglq_entry->virt == NULL) {
3706 kfree(sglq_entry);
3707 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3708 "2563 Failure to allocate an "
3709 "ELS mbuf:%d\n", i);
3710 rc = -ENOMEM;
3711 goto out_free_mem;
3712 }
3713 sglq_entry->sgl = sglq_entry->virt;
3714 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3715 sglq_entry->state = SGL_FREED;
3716 list_add_tail(&sglq_entry->list, &els_sgl_list);
3717 }
James Smart38c20672013-03-01 16:37:44 -05003718 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003719 spin_lock(&phba->sli4_hba.sgl_list_lock);
3720 list_splice_init(&els_sgl_list,
3721 &phba->sli4_hba.lpfc_els_sgl_list);
3722 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003723 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003724 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3725 /* els xri-sgl shrinked */
3726 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3727 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3728 "3158 ELS xri-sgl count decreased from "
3729 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3730 els_xri_cnt);
3731 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003732 spin_lock(&phba->sli4_hba.sgl_list_lock);
3733 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3734 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003735 /* release extra els sgls from list */
3736 for (i = 0; i < xri_cnt; i++) {
3737 list_remove_head(&els_sgl_list,
3738 sglq_entry, struct lpfc_sglq, list);
3739 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003740 __lpfc_mbuf_free(phba, sglq_entry->virt,
3741 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003742 kfree(sglq_entry);
3743 }
3744 }
James Smart895427b2017-02-12 13:52:30 -08003745 list_splice_init(&els_sgl_list,
3746 &phba->sli4_hba.lpfc_els_sgl_list);
3747 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003748 spin_unlock_irq(&phba->hbalock);
3749 } else
3750 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3751 "3163 ELS xri-sgl count unchanged: %d\n",
3752 els_xri_cnt);
3753 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3754
3755 /* update xris to els sgls on the list */
3756 sglq_entry = NULL;
3757 sglq_entry_next = NULL;
3758 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003759 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003760 lxri = lpfc_sli4_next_xritag(phba);
3761 if (lxri == NO_XRI) {
3762 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3763 "2400 Failed to allocate xri for "
3764 "ELS sgl\n");
3765 rc = -ENOMEM;
3766 goto out_free_mem;
3767 }
3768 sglq_entry->sli4_lxritag = lxri;
3769 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3770 }
James Smart895427b2017-02-12 13:52:30 -08003771 return 0;
3772
3773out_free_mem:
3774 lpfc_free_els_sgl_list(phba);
3775 return rc;
3776}
3777
3778/**
James Smartf358dd02017-02-12 13:52:34 -08003779 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3780 * @phba: pointer to lpfc hba data structure.
3781 *
3782 * This routine first calculates the sizes of the current els and allocated
3783 * scsi sgl lists, and then goes through all sgls to updates the physical
3784 * XRIs assigned due to port function reset. During port initialization, the
3785 * current els and allocated scsi sgl lists are 0s.
3786 *
3787 * Return codes
3788 * 0 - successful (for now, it always returns 0)
3789 **/
3790int
3791lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3792{
3793 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3794 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003795 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003796 LIST_HEAD(nvmet_sgl_list);
3797 int rc;
3798
3799 /*
3800 * update on pci function's nvmet xri-sgl list
3801 */
3802 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003803
James Smart6c621a22017-05-15 15:20:45 -07003804 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3805 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003806 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3807 /* els xri-sgl expanded */
3808 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3809 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3810 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3811 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3812 /* allocate the additional nvmet sgls */
3813 for (i = 0; i < xri_cnt; i++) {
3814 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3815 GFP_KERNEL);
3816 if (sglq_entry == NULL) {
3817 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3818 "6303 Failure to allocate an "
3819 "NVMET sgl entry:%d\n", i);
3820 rc = -ENOMEM;
3821 goto out_free_mem;
3822 }
3823 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3824 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3825 &sglq_entry->phys);
3826 if (sglq_entry->virt == NULL) {
3827 kfree(sglq_entry);
3828 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3829 "6304 Failure to allocate an "
3830 "NVMET buf:%d\n", i);
3831 rc = -ENOMEM;
3832 goto out_free_mem;
3833 }
3834 sglq_entry->sgl = sglq_entry->virt;
3835 memset(sglq_entry->sgl, 0,
3836 phba->cfg_sg_dma_buf_size);
3837 sglq_entry->state = SGL_FREED;
3838 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3839 }
3840 spin_lock_irq(&phba->hbalock);
3841 spin_lock(&phba->sli4_hba.sgl_list_lock);
3842 list_splice_init(&nvmet_sgl_list,
3843 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3844 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3845 spin_unlock_irq(&phba->hbalock);
3846 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3847 /* nvmet xri-sgl shrunk */
3848 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3849 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3850 "6305 NVMET xri-sgl count decreased from "
3851 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3852 nvmet_xri_cnt);
3853 spin_lock_irq(&phba->hbalock);
3854 spin_lock(&phba->sli4_hba.sgl_list_lock);
3855 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3856 &nvmet_sgl_list);
3857 /* release extra nvmet sgls from list */
3858 for (i = 0; i < xri_cnt; i++) {
3859 list_remove_head(&nvmet_sgl_list,
3860 sglq_entry, struct lpfc_sglq, list);
3861 if (sglq_entry) {
3862 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3863 sglq_entry->phys);
3864 kfree(sglq_entry);
3865 }
3866 }
3867 list_splice_init(&nvmet_sgl_list,
3868 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3869 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3870 spin_unlock_irq(&phba->hbalock);
3871 } else
3872 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3873 "6306 NVMET xri-sgl count unchanged: %d\n",
3874 nvmet_xri_cnt);
3875 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3876
3877 /* update xris to nvmet sgls on the list */
3878 sglq_entry = NULL;
3879 sglq_entry_next = NULL;
3880 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3881 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3882 lxri = lpfc_sli4_next_xritag(phba);
3883 if (lxri == NO_XRI) {
3884 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3885 "6307 Failed to allocate xri for "
3886 "NVMET sgl\n");
3887 rc = -ENOMEM;
3888 goto out_free_mem;
3889 }
3890 sglq_entry->sli4_lxritag = lxri;
3891 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3892 }
3893 return 0;
3894
3895out_free_mem:
3896 lpfc_free_nvmet_sgl_list(phba);
3897 return rc;
3898}
3899
James Smart5e5b5112019-01-28 11:14:22 -08003900int
3901lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
3902{
3903 LIST_HEAD(blist);
3904 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08003905 struct lpfc_io_buf *lpfc_cmd;
3906 struct lpfc_io_buf *iobufp, *prev_iobufp;
James Smart5e5b5112019-01-28 11:14:22 -08003907 int idx, cnt, xri, inserted;
3908
3909 cnt = 0;
3910 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3911 qp = &phba->sli4_hba.hdwq[idx];
3912 spin_lock_irq(&qp->io_buf_list_get_lock);
3913 spin_lock(&qp->io_buf_list_put_lock);
3914
3915 /* Take everything off the get and put lists */
3916 list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
3917 list_splice(&qp->lpfc_io_buf_list_put, &blist);
3918 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
3919 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
3920 cnt += qp->get_io_bufs + qp->put_io_bufs;
3921 qp->get_io_bufs = 0;
3922 qp->put_io_bufs = 0;
3923 qp->total_io_bufs = 0;
3924 spin_unlock(&qp->io_buf_list_put_lock);
3925 spin_unlock_irq(&qp->io_buf_list_get_lock);
3926 }
3927
3928 /*
3929 * Take IO buffers off blist and put on cbuf sorted by XRI.
3930 * This is because POST_SGL takes a sequential range of XRIs
3931 * to post to the firmware.
3932 */
3933 for (idx = 0; idx < cnt; idx++) {
James Smartc4908502019-01-28 11:14:28 -08003934 list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08003935 if (!lpfc_cmd)
3936 return cnt;
3937 if (idx == 0) {
3938 list_add_tail(&lpfc_cmd->list, cbuf);
3939 continue;
3940 }
3941 xri = lpfc_cmd->cur_iocbq.sli4_xritag;
3942 inserted = 0;
3943 prev_iobufp = NULL;
3944 list_for_each_entry(iobufp, cbuf, list) {
3945 if (xri < iobufp->cur_iocbq.sli4_xritag) {
3946 if (prev_iobufp)
3947 list_add(&lpfc_cmd->list,
3948 &prev_iobufp->list);
3949 else
3950 list_add(&lpfc_cmd->list, cbuf);
3951 inserted = 1;
3952 break;
3953 }
3954 prev_iobufp = iobufp;
3955 }
3956 if (!inserted)
3957 list_add_tail(&lpfc_cmd->list, cbuf);
3958 }
3959 return cnt;
3960}
3961
3962int
3963lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
3964{
3965 struct lpfc_sli4_hdw_queue *qp;
James Smartc4908502019-01-28 11:14:28 -08003966 struct lpfc_io_buf *lpfc_cmd;
James Smart5e5b5112019-01-28 11:14:22 -08003967 int idx, cnt;
3968
3969 qp = phba->sli4_hba.hdwq;
3970 cnt = 0;
3971 while (!list_empty(cbuf)) {
3972 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
3973 list_remove_head(cbuf, lpfc_cmd,
James Smartc4908502019-01-28 11:14:28 -08003974 struct lpfc_io_buf, list);
James Smart5e5b5112019-01-28 11:14:22 -08003975 if (!lpfc_cmd)
3976 return cnt;
3977 cnt++;
3978 qp = &phba->sli4_hba.hdwq[idx];
James Smart1fbf9742019-01-28 11:14:26 -08003979 lpfc_cmd->hdwq_no = idx;
3980 lpfc_cmd->hdwq = qp;
James Smart5e5b5112019-01-28 11:14:22 -08003981 lpfc_cmd->cur_iocbq.wqe_cmpl = NULL;
3982 lpfc_cmd->cur_iocbq.iocb_cmpl = NULL;
3983 spin_lock(&qp->io_buf_list_put_lock);
3984 list_add_tail(&lpfc_cmd->list,
3985 &qp->lpfc_io_buf_list_put);
3986 qp->put_io_bufs++;
3987 qp->total_io_bufs++;
3988 spin_unlock(&qp->io_buf_list_put_lock);
3989 }
3990 }
3991 return cnt;
3992}
3993
James Smartf358dd02017-02-12 13:52:34 -08003994/**
James Smart5e5b5112019-01-28 11:14:22 -08003995 * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
James Smart895427b2017-02-12 13:52:30 -08003996 * @phba: pointer to lpfc hba data structure.
3997 *
3998 * This routine first calculates the sizes of the current els and allocated
3999 * scsi sgl lists, and then goes through all sgls to updates the physical
4000 * XRIs assigned due to port function reset. During port initialization, the
4001 * current els and allocated scsi sgl lists are 0s.
4002 *
4003 * Return codes
4004 * 0 - successful (for now, it always returns 0)
4005 **/
4006int
James Smart5e5b5112019-01-28 11:14:22 -08004007lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08004008{
James Smartc4908502019-01-28 11:14:28 -08004009 struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
James Smart0794d602019-01-28 11:14:19 -08004010 uint16_t i, lxri, els_xri_cnt;
James Smart5e5b5112019-01-28 11:14:22 -08004011 uint16_t io_xri_cnt, io_xri_max;
4012 LIST_HEAD(io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004013 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08004014
4015 /*
James Smart0794d602019-01-28 11:14:19 -08004016 * update on pci function's allocated nvme xri-sgl list
James Smart895427b2017-02-12 13:52:30 -08004017 */
James Smart0794d602019-01-28 11:14:19 -08004018
4019 /* maximum number of xris available for nvme buffers */
James Smart895427b2017-02-12 13:52:30 -08004020 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart5e5b5112019-01-28 11:14:22 -08004021 io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4022 phba->sli4_hba.io_xri_max = io_xri_max;
James Smart8a9d2e82012-05-09 21:16:12 -04004023
James Smarte8c0a772017-04-21 16:04:49 -07004024 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004025 "6074 Current allocated XRI sgl count:%d, "
4026 "maximum XRI count:%d\n",
James Smart5e5b5112019-01-28 11:14:22 -08004027 phba->sli4_hba.io_xri_cnt,
4028 phba->sli4_hba.io_xri_max);
James Smarte8c0a772017-04-21 16:04:49 -07004029
James Smart5e5b5112019-01-28 11:14:22 -08004030 cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
James Smart0794d602019-01-28 11:14:19 -08004031
James Smart5e5b5112019-01-28 11:14:22 -08004032 if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
James Smart0794d602019-01-28 11:14:19 -08004033 /* max nvme xri shrunk below the allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004034 io_xri_cnt = phba->sli4_hba.io_xri_cnt -
4035 phba->sli4_hba.io_xri_max;
James Smart0794d602019-01-28 11:14:19 -08004036 /* release the extra allocated nvme buffers */
James Smart5e5b5112019-01-28 11:14:22 -08004037 for (i = 0; i < io_xri_cnt; i++) {
4038 list_remove_head(&io_sgl_list, lpfc_ncmd,
James Smartc4908502019-01-28 11:14:28 -08004039 struct lpfc_io_buf, list);
James Smart0794d602019-01-28 11:14:19 -08004040 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02004041 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart0794d602019-01-28 11:14:19 -08004042 lpfc_ncmd->data,
4043 lpfc_ncmd->dma_handle);
4044 kfree(lpfc_ncmd);
James Smarta2fc4aef2014-09-03 12:57:55 -04004045 }
James Smart8a9d2e82012-05-09 21:16:12 -04004046 }
James Smart5e5b5112019-01-28 11:14:22 -08004047 phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04004048 }
4049
James Smart0794d602019-01-28 11:14:19 -08004050 /* update xris associated to remaining allocated nvme buffers */
4051 lpfc_ncmd = NULL;
4052 lpfc_ncmd_next = NULL;
James Smart5e5b5112019-01-28 11:14:22 -08004053 phba->sli4_hba.io_xri_cnt = cnt;
James Smart0794d602019-01-28 11:14:19 -08004054 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
James Smart5e5b5112019-01-28 11:14:22 -08004055 &io_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04004056 lxri = lpfc_sli4_next_xritag(phba);
4057 if (lxri == NO_XRI) {
4058 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart0794d602019-01-28 11:14:19 -08004059 "6075 Failed to allocate xri for "
4060 "nvme buffer\n");
James Smart8a9d2e82012-05-09 21:16:12 -04004061 rc = -ENOMEM;
4062 goto out_free_mem;
4063 }
James Smart0794d602019-01-28 11:14:19 -08004064 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
4065 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
James Smart8a9d2e82012-05-09 21:16:12 -04004066 }
James Smart5e5b5112019-01-28 11:14:22 -08004067 cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
dea31012005-04-17 16:05:31 -05004068 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04004069
4070out_free_mem:
James Smart5e5b5112019-01-28 11:14:22 -08004071 lpfc_io_free(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04004072 return rc;
dea31012005-04-17 16:05:31 -05004073}
4074
James Smart0794d602019-01-28 11:14:19 -08004075/**
James Smart5e5b5112019-01-28 11:14:22 -08004076 * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
James Smart0794d602019-01-28 11:14:19 -08004077 * @vport: The virtual port for which this call being executed.
4078 * @num_to_allocate: The requested number of buffers to allocate.
4079 *
4080 * This routine allocates nvme buffers for device with SLI-4 interface spec,
4081 * the nvme buffer contains all the necessary information needed to initiate
4082 * an I/O. After allocating up to @num_to_allocate IO buffers and put
4083 * them on a list, it post them to the port by using SGL block post.
4084 *
4085 * Return codes:
James Smart5e5b5112019-01-28 11:14:22 -08004086 * int - number of IO buffers that were allocated and posted.
James Smart0794d602019-01-28 11:14:19 -08004087 * 0 = failure, less than num_to_alloc is a partial failure.
4088 **/
4089int
James Smart5e5b5112019-01-28 11:14:22 -08004090lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
James Smart0794d602019-01-28 11:14:19 -08004091{
James Smartc4908502019-01-28 11:14:28 -08004092 struct lpfc_io_buf *lpfc_ncmd;
James Smart0794d602019-01-28 11:14:19 -08004093 struct lpfc_iocbq *pwqeq;
4094 uint16_t iotag, lxri = 0;
4095 int bcnt, num_posted;
4096 LIST_HEAD(prep_nblist);
4097 LIST_HEAD(post_nblist);
4098 LIST_HEAD(nvme_nblist);
4099
4100 /* Sanity check to ensure our sizing is right for both SCSI and NVME */
James Smartc4908502019-01-28 11:14:28 -08004101 if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) {
James Smart0794d602019-01-28 11:14:19 -08004102 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
Arnd Bergmannf9968612019-03-04 20:39:09 +01004103 "6426 Common buffer size %zd exceeds %d\n",
James Smartc4908502019-01-28 11:14:28 -08004104 sizeof(struct lpfc_io_buf),
4105 LPFC_COMMON_IO_BUF_SZ);
James Smart0794d602019-01-28 11:14:19 -08004106 return 0;
4107 }
4108
James Smart5e5b5112019-01-28 11:14:22 -08004109 phba->sli4_hba.io_xri_cnt = 0;
James Smart0794d602019-01-28 11:14:19 -08004110 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
4111 lpfc_ncmd = kzalloc(LPFC_COMMON_IO_BUF_SZ, GFP_KERNEL);
4112 if (!lpfc_ncmd)
4113 break;
4114 /*
4115 * Get memory from the pci pool to map the virt space to
4116 * pci bus space for an I/O. The DMA buffer includes the
4117 * number of SGE's necessary to support the sg_tablesize.
4118 */
Thomas Meyera5c990e2019-05-29 22:21:36 +02004119 lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
4120 GFP_KERNEL,
4121 &lpfc_ncmd->dma_handle);
James Smart0794d602019-01-28 11:14:19 -08004122 if (!lpfc_ncmd->data) {
4123 kfree(lpfc_ncmd);
4124 break;
4125 }
James Smart0794d602019-01-28 11:14:19 -08004126
4127 /*
4128 * 4K Page alignment is CRITICAL to BlockGuard, double check
4129 * to be sure.
4130 */
4131 if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
4132 (((unsigned long)(lpfc_ncmd->data) &
4133 (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
4134 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
4135 "3369 Memory alignment err: addr=%lx\n",
4136 (unsigned long)lpfc_ncmd->data);
4137 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4138 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4139 kfree(lpfc_ncmd);
4140 break;
4141 }
4142
4143 lxri = lpfc_sli4_next_xritag(phba);
4144 if (lxri == NO_XRI) {
4145 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4146 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4147 kfree(lpfc_ncmd);
4148 break;
4149 }
4150 pwqeq = &lpfc_ncmd->cur_iocbq;
4151
4152 /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
4153 iotag = lpfc_sli_next_iotag(phba, pwqeq);
4154 if (iotag == 0) {
4155 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
4156 lpfc_ncmd->data, lpfc_ncmd->dma_handle);
4157 kfree(lpfc_ncmd);
4158 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
4159 "6121 Failed to allocate IOTAG for"
4160 " XRI:0x%x\n", lxri);
4161 lpfc_sli4_free_xri(phba, lxri);
4162 break;
4163 }
4164 pwqeq->sli4_lxritag = lxri;
4165 pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
4166 pwqeq->context1 = lpfc_ncmd;
4167
4168 /* Initialize local short-hand pointers. */
4169 lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
4170 lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
4171 lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd;
James Smartc2017262019-01-28 11:14:37 -08004172 spin_lock_init(&lpfc_ncmd->buf_lock);
James Smart0794d602019-01-28 11:14:19 -08004173
4174 /* add the nvme buffer to a post list */
4175 list_add_tail(&lpfc_ncmd->list, &post_nblist);
James Smart5e5b5112019-01-28 11:14:22 -08004176 phba->sli4_hba.io_xri_cnt++;
James Smart0794d602019-01-28 11:14:19 -08004177 }
4178 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
4179 "6114 Allocate %d out of %d requested new NVME "
4180 "buffers\n", bcnt, num_to_alloc);
4181
4182 /* post the list of nvme buffer sgls to port if available */
4183 if (!list_empty(&post_nblist))
James Smart5e5b5112019-01-28 11:14:22 -08004184 num_posted = lpfc_sli4_post_io_sgl_list(
James Smart0794d602019-01-28 11:14:19 -08004185 phba, &post_nblist, bcnt);
4186 else
4187 num_posted = 0;
4188
4189 return num_posted;
4190}
4191
James Smart96418b52017-03-04 09:30:31 -08004192static uint64_t
4193lpfc_get_wwpn(struct lpfc_hba *phba)
4194{
4195 uint64_t wwn;
4196 int rc;
4197 LPFC_MBOXQ_t *mboxq;
4198 MAILBOX_t *mb;
4199
James Smart96418b52017-03-04 09:30:31 -08004200 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4201 GFP_KERNEL);
4202 if (!mboxq)
4203 return (uint64_t)-1;
4204
4205 /* First get WWN of HBA instance */
4206 lpfc_read_nv(phba, mboxq);
4207 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4208 if (rc != MBX_SUCCESS) {
4209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4210 "6019 Mailbox failed , mbxCmd x%x "
4211 "READ_NV, mbxStatus x%x\n",
4212 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
4213 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
4214 mempool_free(mboxq, phba->mbox_mem_pool);
4215 return (uint64_t) -1;
4216 }
4217 mb = &mboxq->u.mb;
4218 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
4219 /* wwn is WWPN of HBA instance */
4220 mempool_free(mboxq, phba->mbox_mem_pool);
4221 if (phba->sli_rev == LPFC_SLI_REV4)
4222 return be64_to_cpu(wwn);
4223 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07004224 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08004225}
4226
James Smarte59058c2008-08-24 21:49:00 -04004227/**
James Smart3621a712009-04-06 18:47:14 -04004228 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04004229 * @phba: pointer to lpfc hba data structure.
4230 * @instance: a unique integer ID to this FC port.
4231 * @dev: pointer to the device data structure.
4232 *
4233 * This routine creates a FC port for the upper layer protocol. The FC port
4234 * can be created on top of either a physical port or a virtual port provided
4235 * by the HBA. This routine also allocates a SCSI host data structure (shost)
4236 * and associates the FC port created before adding the shost into the SCSI
4237 * layer.
4238 *
4239 * Return codes
4240 * @vport - pointer to the virtual N_Port data structure.
4241 * NULL - port create failed.
4242 **/
James Smart2e0fef82007-06-17 19:56:36 -05004243struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04004244lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04004245{
James Smart2e0fef82007-06-17 19:56:36 -05004246 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08004247 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004248 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08004249 int i;
4250 uint64_t wwn;
4251 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07004252 int rc;
James Smart96418b52017-03-04 09:30:31 -08004253
James Smart56bc8022017-06-15 22:56:43 -07004254 if (lpfc_no_hba_reset_cnt) {
4255 if (phba->sli_rev < LPFC_SLI_REV4 &&
4256 dev == &phba->pcidev->dev) {
4257 /* Reset the port first */
4258 lpfc_sli_brdrestart(phba);
4259 rc = lpfc_sli_chipset_init(phba);
4260 if (rc)
4261 return NULL;
4262 }
4263 wwn = lpfc_get_wwpn(phba);
4264 }
James Smart96418b52017-03-04 09:30:31 -08004265
4266 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
4267 if (wwn == lpfc_no_hba_reset[i]) {
4268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4269 "6020 Setting use_no_reset port=%llx\n",
4270 wwn);
4271 use_no_reset_hba = true;
4272 break;
4273 }
4274 }
James Smart47a86172007-04-25 09:53:22 -04004275
James Smart895427b2017-02-12 13:52:30 -08004276 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
4277 if (dev != &phba->pcidev->dev) {
4278 shost = scsi_host_alloc(&lpfc_vport_template,
4279 sizeof(struct lpfc_vport));
4280 } else {
James Smart96418b52017-03-04 09:30:31 -08004281 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08004282 shost = scsi_host_alloc(&lpfc_template,
4283 sizeof(struct lpfc_vport));
4284 else
James Smart96418b52017-03-04 09:30:31 -08004285 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08004286 sizeof(struct lpfc_vport));
4287 }
4288 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
4289 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04004290 sizeof(struct lpfc_vport));
4291 }
James Smart2e0fef82007-06-17 19:56:36 -05004292 if (!shost)
4293 goto out;
James Smart47a86172007-04-25 09:53:22 -04004294
James Smart2e0fef82007-06-17 19:56:36 -05004295 vport = (struct lpfc_vport *) shost->hostdata;
4296 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05004297 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05004298 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05004299 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04004300 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08004301
James Smartf6e84792019-01-28 11:14:38 -08004302 /* Adjust value in vport */
4303 vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
4304
James Smart2e0fef82007-06-17 19:56:36 -05004305 shost->unique_id = instance;
4306 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04004307 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05004308 shost->this_id = -1;
4309 shost->max_cmd_len = 16;
James Smart6a828b02019-01-28 11:14:31 -08004310
James Smartda0436e2009-05-22 14:51:39 -04004311 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart6a828b02019-01-28 11:14:31 -08004312 if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ)
4313 shost->nr_hw_queues = phba->cfg_hdw_queue;
4314 else
4315 shost->nr_hw_queues = phba->sli4_hba.num_present_cpu;
4316
James Smart28baac72010-02-12 14:42:03 -05004317 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04004318 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07004319 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartace44e42019-01-28 11:14:27 -08004320 } else
4321 /* SLI-3 has a limited number of hardware queues (3),
4322 * thus there is only one for FCP processing.
4323 */
4324 shost->nr_hw_queues = 1;
James Smart81301a92008-12-04 22:39:46 -05004325
James Smart47a86172007-04-25 09:53:22 -04004326 /*
James Smart2e0fef82007-06-17 19:56:36 -05004327 * Set initial can_queue value since 0 is no longer supported and
4328 * scsi_add_host will fail. This will be adjusted later based on the
4329 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04004330 */
James Smart2e0fef82007-06-17 19:56:36 -05004331 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04004332 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05004333 shost->transportt = lpfc_vport_transport_template;
4334 vport->port_type = LPFC_NPIV_PORT;
4335 } else {
4336 shost->transportt = lpfc_transport_template;
4337 vport->port_type = LPFC_PHYSICAL_PORT;
4338 }
James Smart47a86172007-04-25 09:53:22 -04004339
James Smart2e0fef82007-06-17 19:56:36 -05004340 /* Initialize all internally managed lists. */
4341 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04004342 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05004343 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04004344
Kees Cookf22eb4d2017-09-06 20:24:26 -07004345 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04004346
Kees Cookf22eb4d2017-09-06 20:24:26 -07004347 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05004348
Kees Cookf22eb4d2017-09-06 20:24:26 -07004349 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05004350
James Smartaa6ff302019-05-21 17:49:09 -07004351 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4352 lpfc_setup_bg(phba, shost);
4353
James Bottomleyd139b9b2009-11-05 13:33:12 -06004354 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05004355 if (error)
4356 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04004357
James Smart523128e2018-09-10 10:30:46 -07004358 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004359 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07004360 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004361 return vport;
James Smart47a86172007-04-25 09:53:22 -04004362
James Smart2e0fef82007-06-17 19:56:36 -05004363out_put_shost:
4364 scsi_host_put(shost);
4365out:
4366 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004367}
4368
James Smarte59058c2008-08-24 21:49:00 -04004369/**
James Smart3621a712009-04-06 18:47:14 -04004370 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004371 * @vport: pointer to an lpfc virtual N_Port data structure.
4372 *
4373 * This routine destroys a FC port from the upper layer protocol. All the
4374 * resources associated with the port are released.
4375 **/
James Smart2e0fef82007-06-17 19:56:36 -05004376void
4377destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004378{
James Smart92d7f7b2007-06-17 19:56:38 -05004379 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4380 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004381
James Smart858c9f62007-06-17 19:56:39 -05004382 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004383 fc_remove_host(shost);
4384 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004385
James Smart523128e2018-09-10 10:30:46 -07004386 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004387 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004388 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004389
James Smart92d7f7b2007-06-17 19:56:38 -05004390 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004391 return;
James Smart47a86172007-04-25 09:53:22 -04004392}
4393
James Smarte59058c2008-08-24 21:49:00 -04004394/**
James Smart3621a712009-04-06 18:47:14 -04004395 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004396 *
4397 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4398 * uses the kernel idr facility to perform the task.
4399 *
4400 * Return codes:
4401 * instance - a unique integer ID allocated as the new instance.
4402 * -1 - lpfc get instance failed.
4403 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004404int
4405lpfc_get_instance(void)
4406{
Tejun Heoab516032013-02-27 17:04:44 -08004407 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004408
Tejun Heoab516032013-02-27 17:04:44 -08004409 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4410 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004411}
4412
James Smarte59058c2008-08-24 21:49:00 -04004413/**
James Smart3621a712009-04-06 18:47:14 -04004414 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004415 * @shost: pointer to SCSI host data structure.
4416 * @time: elapsed time of the scan in jiffies.
4417 *
4418 * This routine is called by the SCSI layer with a SCSI host to determine
4419 * whether the scan host is finished.
4420 *
4421 * Note: there is no scan_start function as adapter initialization will have
4422 * asynchronously kicked off the link initialization.
4423 *
4424 * Return codes
4425 * 0 - SCSI host scan is not over yet.
4426 * 1 - SCSI host scan is over.
4427 **/
James Smart47a86172007-04-25 09:53:22 -04004428int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4429{
James Smart2e0fef82007-06-17 19:56:36 -05004430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4431 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004432 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004433
James Smart858c9f62007-06-17 19:56:39 -05004434 spin_lock_irq(shost->host_lock);
4435
James Smart51ef4c22007-08-02 11:10:31 -04004436 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004437 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004438 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004439 }
James Smart256ec0d2013-04-17 20:14:58 -04004440 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004441 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004442 "0461 Scanning longer than 30 "
4443 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004444 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004445 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004446 }
James Smart256ec0d2013-04-17 20:14:58 -04004447 if (time >= msecs_to_jiffies(15 * 1000) &&
4448 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004449 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004450 "0465 Link down longer than 15 "
4451 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004452 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004453 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004454 }
4455
James Smart2e0fef82007-06-17 19:56:36 -05004456 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004457 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004458 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004459 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004460 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004461 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004462 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004463 goto finished;
4464
4465 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004466
4467finished:
James Smart858c9f62007-06-17 19:56:39 -05004468 spin_unlock_irq(shost->host_lock);
4469 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004470}
4471
Bart Van Assche3999df72019-03-28 11:06:16 -07004472static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
James Smartcd713482018-10-23 13:41:01 -07004473{
4474 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4475 struct lpfc_hba *phba = vport->phba;
4476
4477 fc_host_supported_speeds(shost) = 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004478 if (phba->lmt & LMT_128Gb)
4479 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004480 if (phba->lmt & LMT_64Gb)
4481 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4482 if (phba->lmt & LMT_32Gb)
4483 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4484 if (phba->lmt & LMT_16Gb)
4485 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4486 if (phba->lmt & LMT_10Gb)
4487 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4488 if (phba->lmt & LMT_8Gb)
4489 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4490 if (phba->lmt & LMT_4Gb)
4491 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4492 if (phba->lmt & LMT_2Gb)
4493 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4494 if (phba->lmt & LMT_1Gb)
4495 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4496}
4497
James Smarte59058c2008-08-24 21:49:00 -04004498/**
James Smart3621a712009-04-06 18:47:14 -04004499 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004500 * @shost: pointer to SCSI host data structure.
4501 *
4502 * This routine initializes a given SCSI host attributes on a FC port. The
4503 * SCSI host can be either on top of a physical port or a virtual port.
4504 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004505void lpfc_host_attrib_init(struct Scsi_Host *shost)
4506{
4507 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4508 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004509 /*
James Smart2e0fef82007-06-17 19:56:36 -05004510 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004511 */
4512
James Smart2e0fef82007-06-17 19:56:36 -05004513 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4514 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004515 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4516
4517 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004518 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004519 fc_host_supported_fc4s(shost)[2] = 1;
4520 fc_host_supported_fc4s(shost)[7] = 1;
4521
James Smart92d7f7b2007-06-17 19:56:38 -05004522 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4523 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004524
James Smartcd713482018-10-23 13:41:01 -07004525 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004526
4527 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004528 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4529 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004530
Mike Christie0af5d702010-09-15 16:52:31 -05004531 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4532
James Smart47a86172007-04-25 09:53:22 -04004533 /* This value is also unchanging */
4534 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004535 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004536 fc_host_active_fc4s(shost)[2] = 1;
4537 fc_host_active_fc4s(shost)[7] = 1;
4538
James Smart92d7f7b2007-06-17 19:56:38 -05004539 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004540 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004541 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004542 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004543}
dea31012005-04-17 16:05:31 -05004544
James Smarte59058c2008-08-24 21:49:00 -04004545/**
James Smartda0436e2009-05-22 14:51:39 -04004546 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004547 * @phba: pointer to lpfc hba data structure.
4548 *
James Smartda0436e2009-05-22 14:51:39 -04004549 * This routine is invoked to stop an SLI3 device port, it stops the device
4550 * from generating interrupts and stops the device driver's timers for the
4551 * device.
James Smarte59058c2008-08-24 21:49:00 -04004552 **/
James Smartdb2378e2008-02-08 18:49:51 -05004553static void
James Smartda0436e2009-05-22 14:51:39 -04004554lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004555{
James Smartda0436e2009-05-22 14:51:39 -04004556 /* Clear all interrupt enable conditions */
4557 writel(0, phba->HCregaddr);
4558 readl(phba->HCregaddr); /* flush */
4559 /* Clear all pending interrupts */
4560 writel(0xffffffff, phba->HAregaddr);
4561 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004562
James Smartda0436e2009-05-22 14:51:39 -04004563 /* Reset some HBA SLI setup states */
4564 lpfc_stop_hba_timers(phba);
4565 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004566}
4567
James Smarte59058c2008-08-24 21:49:00 -04004568/**
James Smartda0436e2009-05-22 14:51:39 -04004569 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004570 * @phba: pointer to lpfc hba data structure.
4571 *
James Smartda0436e2009-05-22 14:51:39 -04004572 * This routine is invoked to stop an SLI4 device port, it stops the device
4573 * from generating interrupts and stops the device driver's timers for the
4574 * device.
4575 **/
4576static void
4577lpfc_stop_port_s4(struct lpfc_hba *phba)
4578{
4579 /* Reset some HBA SLI4 setup states */
4580 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -08004581 if (phba->pport)
4582 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -04004583 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004584}
4585
4586/**
4587 * lpfc_stop_port - Wrapper function for stopping hba port
4588 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004589 *
James Smartda0436e2009-05-22 14:51:39 -04004590 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4591 * the API jump table function pointer from the lpfc_hba struct.
4592 **/
4593void
4594lpfc_stop_port(struct lpfc_hba *phba)
4595{
4596 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004597
4598 if (phba->wq)
4599 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004600}
4601
4602/**
James Smartecfd03c2010-02-12 14:41:27 -05004603 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4604 * @phba: Pointer to hba for which this call is being executed.
4605 *
4606 * This routine starts the timer waiting for the FCF rediscovery to complete.
4607 **/
4608void
4609lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4610{
4611 unsigned long fcf_redisc_wait_tmo =
4612 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4613 /* Start fcf rediscovery wait period timer */
4614 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4615 spin_lock_irq(&phba->hbalock);
4616 /* Allow action to new fcf asynchronous event */
4617 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4618 /* Mark the FCF rediscovery pending state */
4619 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4620 spin_unlock_irq(&phba->hbalock);
4621}
4622
4623/**
4624 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4625 * @ptr: Map to lpfc_hba data structure pointer.
4626 *
4627 * This routine is invoked when waiting for FCF table rediscover has been
4628 * timed out. If new FCF record(s) has (have) been discovered during the
4629 * wait period, a new FCF event shall be added to the FCOE async event
4630 * list, and then worker thread shall be waked up for processing from the
4631 * worker thread context.
4632 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004633static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004634lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004635{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004636 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004637
4638 /* Don't send FCF rediscovery event if timer cancelled */
4639 spin_lock_irq(&phba->hbalock);
4640 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4641 spin_unlock_irq(&phba->hbalock);
4642 return;
4643 }
4644 /* Clear FCF rediscovery timer pending flag */
4645 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4646 /* FCF rediscovery event to worker thread */
4647 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4648 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004649 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004650 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004651 /* wake up worker thread */
4652 lpfc_worker_wake_up(phba);
4653}
4654
4655/**
James Smartda0436e2009-05-22 14:51:39 -04004656 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4657 * @phba: pointer to lpfc hba data structure.
4658 * @acqe_link: pointer to the async link completion queue entry.
4659 *
James Smart23288b72018-05-04 20:37:53 -07004660 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004661 **/
James Smart23288b72018-05-04 20:37:53 -07004662static void
James Smartda0436e2009-05-22 14:51:39 -04004663lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4664 struct lpfc_acqe_link *acqe_link)
4665{
James Smartda0436e2009-05-22 14:51:39 -04004666 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4667 case LPFC_ASYNC_LINK_FAULT_NONE:
4668 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4669 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004670 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004671 break;
4672 default:
4673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004674 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004675 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004676 break;
4677 }
James Smartda0436e2009-05-22 14:51:39 -04004678}
4679
4680/**
4681 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4682 * @phba: pointer to lpfc hba data structure.
4683 * @acqe_link: pointer to the async link completion queue entry.
4684 *
4685 * This routine is to parse the SLI4 link attention type and translate it
4686 * into the base driver's link attention type coding.
4687 *
4688 * Return: Link attention type in terms of base driver's coding.
4689 **/
4690static uint8_t
4691lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4692 struct lpfc_acqe_link *acqe_link)
4693{
4694 uint8_t att_type;
4695
4696 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4697 case LPFC_ASYNC_LINK_STATUS_DOWN:
4698 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004699 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004700 break;
4701 case LPFC_ASYNC_LINK_STATUS_UP:
4702 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004703 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004704 break;
4705 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004706 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004707 break;
4708 default:
4709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4710 "0399 Invalid link attention type: x%x\n",
4711 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004712 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004713 break;
4714 }
4715 return att_type;
4716}
4717
4718/**
James Smart8b68cd52012-09-29 11:32:37 -04004719 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4720 * @phba: pointer to lpfc hba data structure.
4721 *
4722 * This routine is to get an SLI3 FC port's link speed in Mbps.
4723 *
4724 * Return: link speed in terms of Mbps.
4725 **/
4726uint32_t
4727lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4728{
4729 uint32_t link_speed;
4730
4731 if (!lpfc_is_link_up(phba))
4732 return 0;
4733
James Smarta085e872015-12-16 18:12:02 -05004734 if (phba->sli_rev <= LPFC_SLI_REV3) {
4735 switch (phba->fc_linkspeed) {
4736 case LPFC_LINK_SPEED_1GHZ:
4737 link_speed = 1000;
4738 break;
4739 case LPFC_LINK_SPEED_2GHZ:
4740 link_speed = 2000;
4741 break;
4742 case LPFC_LINK_SPEED_4GHZ:
4743 link_speed = 4000;
4744 break;
4745 case LPFC_LINK_SPEED_8GHZ:
4746 link_speed = 8000;
4747 break;
4748 case LPFC_LINK_SPEED_10GHZ:
4749 link_speed = 10000;
4750 break;
4751 case LPFC_LINK_SPEED_16GHZ:
4752 link_speed = 16000;
4753 break;
4754 default:
4755 link_speed = 0;
4756 }
4757 } else {
4758 if (phba->sli4_hba.link_state.logical_speed)
4759 link_speed =
4760 phba->sli4_hba.link_state.logical_speed;
4761 else
4762 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004763 }
4764 return link_speed;
4765}
4766
4767/**
4768 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4769 * @phba: pointer to lpfc hba data structure.
4770 * @evt_code: asynchronous event code.
4771 * @speed_code: asynchronous event link speed code.
4772 *
4773 * This routine is to parse the giving SLI4 async event link speed code into
4774 * value of Mbps for the link speed.
4775 *
4776 * Return: link speed in terms of Mbps.
4777 **/
4778static uint32_t
4779lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4780 uint8_t speed_code)
4781{
4782 uint32_t port_speed;
4783
4784 switch (evt_code) {
4785 case LPFC_TRAILER_CODE_LINK:
4786 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004787 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004788 port_speed = 0;
4789 break;
James Smart26d830e2015-04-07 15:07:17 -04004790 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004791 port_speed = 10;
4792 break;
James Smart26d830e2015-04-07 15:07:17 -04004793 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004794 port_speed = 100;
4795 break;
James Smart26d830e2015-04-07 15:07:17 -04004796 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004797 port_speed = 1000;
4798 break;
James Smart26d830e2015-04-07 15:07:17 -04004799 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004800 port_speed = 10000;
4801 break;
James Smart26d830e2015-04-07 15:07:17 -04004802 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4803 port_speed = 20000;
4804 break;
4805 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4806 port_speed = 25000;
4807 break;
4808 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4809 port_speed = 40000;
4810 break;
James Smart8b68cd52012-09-29 11:32:37 -04004811 default:
4812 port_speed = 0;
4813 }
4814 break;
4815 case LPFC_TRAILER_CODE_FC:
4816 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004817 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004818 port_speed = 0;
4819 break;
James Smart26d830e2015-04-07 15:07:17 -04004820 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004821 port_speed = 1000;
4822 break;
James Smart26d830e2015-04-07 15:07:17 -04004823 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004824 port_speed = 2000;
4825 break;
James Smart26d830e2015-04-07 15:07:17 -04004826 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004827 port_speed = 4000;
4828 break;
James Smart26d830e2015-04-07 15:07:17 -04004829 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004830 port_speed = 8000;
4831 break;
James Smart26d830e2015-04-07 15:07:17 -04004832 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004833 port_speed = 10000;
4834 break;
James Smart26d830e2015-04-07 15:07:17 -04004835 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004836 port_speed = 16000;
4837 break;
James Smartd38dd522015-08-31 16:48:17 -04004838 case LPFC_FC_LA_SPEED_32G:
4839 port_speed = 32000;
4840 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004841 case LPFC_FC_LA_SPEED_64G:
4842 port_speed = 64000;
4843 break;
James Smart1dc5ec22018-10-23 13:41:11 -07004844 case LPFC_FC_LA_SPEED_128G:
4845 port_speed = 128000;
4846 break;
James Smart8b68cd52012-09-29 11:32:37 -04004847 default:
4848 port_speed = 0;
4849 }
4850 break;
4851 default:
4852 port_speed = 0;
4853 }
4854 return port_speed;
4855}
4856
4857/**
James Smart70f3c072010-12-15 17:57:33 -05004858 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004859 * @phba: pointer to lpfc hba data structure.
4860 * @acqe_link: pointer to the async link completion queue entry.
4861 *
James Smart70f3c072010-12-15 17:57:33 -05004862 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004863 **/
4864static void
4865lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4866 struct lpfc_acqe_link *acqe_link)
4867{
4868 struct lpfc_dmabuf *mp;
4869 LPFC_MBOXQ_t *pmb;
4870 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004871 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004872 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004873 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004874
4875 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004876 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004877 return;
James Smart32b97932009-07-19 10:01:21 -04004878 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004879 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4880 if (!pmb) {
4881 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4882 "0395 The mboxq allocation failed\n");
4883 return;
4884 }
4885 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4886 if (!mp) {
4887 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4888 "0396 The lpfc_dmabuf allocation failed\n");
4889 goto out_free_pmb;
4890 }
4891 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4892 if (!mp->virt) {
4893 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4894 "0397 The mbuf allocation failed\n");
4895 goto out_free_dmabuf;
4896 }
4897
4898 /* Cleanup any outstanding ELS commands */
4899 lpfc_els_flush_all_cmd(phba);
4900
4901 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004902 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004903
4904 /* Update link event statistics */
4905 phba->sli.slistat.link_event++;
4906
James Smart76a95d72010-11-20 23:11:48 -05004907 /* Create lpfc_handle_latt mailbox command from link ACQE */
4908 lpfc_read_topology(phba, pmb, mp);
4909 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004910 pmb->vport = phba->pport;
4911
James Smartda0436e2009-05-22 14:51:39 -04004912 /* Keep the link status for extra SLI4 state machine reference */
4913 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004914 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4915 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004916 phba->sli4_hba.link_state.duplex =
4917 bf_get(lpfc_acqe_link_duplex, acqe_link);
4918 phba->sli4_hba.link_state.status =
4919 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004920 phba->sli4_hba.link_state.type =
4921 bf_get(lpfc_acqe_link_type, acqe_link);
4922 phba->sli4_hba.link_state.number =
4923 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004924 phba->sli4_hba.link_state.fault =
4925 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004926 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004927 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4928
James Smart70f3c072010-12-15 17:57:33 -05004929 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004930 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4931 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4932 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004933 phba->sli4_hba.link_state.speed,
4934 phba->sli4_hba.link_state.topology,
4935 phba->sli4_hba.link_state.status,
4936 phba->sli4_hba.link_state.type,
4937 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004938 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004939 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004940 /*
4941 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4942 * topology info. Note: Optional for non FC-AL ports.
4943 */
4944 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4945 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4946 if (rc == MBX_NOT_FINISHED)
4947 goto out_free_dmabuf;
4948 return;
4949 }
4950 /*
4951 * For FCoE Mode: fill in all the topology information we need and call
4952 * the READ_TOPOLOGY completion routine to continue without actually
4953 * sending the READ_TOPOLOGY mailbox command to the port.
4954 */
James Smart23288b72018-05-04 20:37:53 -07004955 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004956 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004957 mb->mbxStatus = MBX_SUCCESS;
4958
4959 /* Parse port fault information field */
4960 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004961
4962 /* Parse and translate link attention fields */
4963 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4964 la->eventTag = acqe_link->event_tag;
4965 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4966 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004967 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004968
4969 /* Fake the the following irrelvant fields */
4970 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4971 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4972 bf_set(lpfc_mbx_read_top_il, la, 0);
4973 bf_set(lpfc_mbx_read_top_pb, la, 0);
4974 bf_set(lpfc_mbx_read_top_fa, la, 0);
4975 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004976
4977 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004978 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004979
4980 return;
4981
4982out_free_dmabuf:
4983 kfree(mp);
4984out_free_pmb:
4985 mempool_free(pmb, phba->mbox_mem_pool);
4986}
4987
4988/**
James Smart1dc5ec22018-10-23 13:41:11 -07004989 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
4990 * topology.
4991 * @phba: pointer to lpfc hba data structure.
4992 * @evt_code: asynchronous event code.
4993 * @speed_code: asynchronous event link speed code.
4994 *
4995 * This routine is to parse the giving SLI4 async event link speed code into
4996 * value of Read topology link speed.
4997 *
4998 * Return: link speed in terms of Read topology.
4999 **/
5000static uint8_t
5001lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
5002{
5003 uint8_t port_speed;
5004
5005 switch (speed_code) {
5006 case LPFC_FC_LA_SPEED_1G:
5007 port_speed = LPFC_LINK_SPEED_1GHZ;
5008 break;
5009 case LPFC_FC_LA_SPEED_2G:
5010 port_speed = LPFC_LINK_SPEED_2GHZ;
5011 break;
5012 case LPFC_FC_LA_SPEED_4G:
5013 port_speed = LPFC_LINK_SPEED_4GHZ;
5014 break;
5015 case LPFC_FC_LA_SPEED_8G:
5016 port_speed = LPFC_LINK_SPEED_8GHZ;
5017 break;
5018 case LPFC_FC_LA_SPEED_16G:
5019 port_speed = LPFC_LINK_SPEED_16GHZ;
5020 break;
5021 case LPFC_FC_LA_SPEED_32G:
5022 port_speed = LPFC_LINK_SPEED_32GHZ;
5023 break;
5024 case LPFC_FC_LA_SPEED_64G:
5025 port_speed = LPFC_LINK_SPEED_64GHZ;
5026 break;
5027 case LPFC_FC_LA_SPEED_128G:
5028 port_speed = LPFC_LINK_SPEED_128GHZ;
5029 break;
5030 case LPFC_FC_LA_SPEED_256G:
5031 port_speed = LPFC_LINK_SPEED_256GHZ;
5032 break;
5033 default:
5034 port_speed = 0;
5035 break;
5036 }
5037
5038 return port_speed;
5039}
5040
5041#define trunk_link_status(__idx)\
5042 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5043 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
5044 "Link up" : "Link down") : "NA"
5045/* Did port __idx reported an error */
5046#define trunk_port_fault(__idx)\
5047 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
5048 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
5049
5050static void
5051lpfc_update_trunk_link_status(struct lpfc_hba *phba,
5052 struct lpfc_acqe_fc_la *acqe_fc)
5053{
5054 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
5055 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
5056
5057 phba->sli4_hba.link_state.speed =
5058 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5059 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5060
5061 phba->sli4_hba.link_state.logical_speed =
James Smartb8e6f132019-05-21 17:49:04 -07005062 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart1dc5ec22018-10-23 13:41:11 -07005063 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
5064 phba->fc_linkspeed =
5065 lpfc_async_link_speed_to_read_top(
5066 phba,
5067 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
5068
5069 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
5070 phba->trunk_link.link0.state =
5071 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
5072 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005073 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005074 }
5075 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
5076 phba->trunk_link.link1.state =
5077 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
5078 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005079 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005080 }
5081 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
5082 phba->trunk_link.link2.state =
5083 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
5084 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005085 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005086 }
5087 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
5088 phba->trunk_link.link3.state =
5089 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
5090 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08005091 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07005092 }
5093
5094 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5095 "2910 Async FC Trunking Event - Speed:%d\n"
5096 "\tLogical speed:%d "
5097 "port0: %s port1: %s port2: %s port3: %s\n",
5098 phba->sli4_hba.link_state.speed,
5099 phba->sli4_hba.link_state.logical_speed,
5100 trunk_link_status(0), trunk_link_status(1),
5101 trunk_link_status(2), trunk_link_status(3));
5102
5103 if (port_fault)
5104 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5105 "3202 trunk error:0x%x (%s) seen on port0:%s "
5106 /*
5107 * SLI-4: We have only 0xA error codes
5108 * defined as of now. print an appropriate
5109 * message in case driver needs to be updated.
5110 */
5111 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
5112 "UNDEFINED. update driver." : trunk_errmsg[err],
5113 trunk_port_fault(0), trunk_port_fault(1),
5114 trunk_port_fault(2), trunk_port_fault(3));
5115}
5116
5117
5118/**
James Smart70f3c072010-12-15 17:57:33 -05005119 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
5120 * @phba: pointer to lpfc hba data structure.
5121 * @acqe_fc: pointer to the async fc completion queue entry.
5122 *
5123 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
5124 * that the event was received and then issue a read_topology mailbox command so
5125 * that the rest of the driver will treat it the same as SLI3.
5126 **/
5127static void
5128lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
5129{
5130 struct lpfc_dmabuf *mp;
5131 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07005132 MAILBOX_t *mb;
5133 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05005134 int rc;
5135
5136 if (bf_get(lpfc_trailer_type, acqe_fc) !=
5137 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
5138 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5139 "2895 Non FC link Event detected.(%d)\n",
5140 bf_get(lpfc_trailer_type, acqe_fc));
5141 return;
5142 }
James Smart1dc5ec22018-10-23 13:41:11 -07005143
5144 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5145 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
5146 lpfc_update_trunk_link_status(phba, acqe_fc);
5147 return;
5148 }
5149
James Smart70f3c072010-12-15 17:57:33 -05005150 /* Keep the link status for extra SLI4 state machine reference */
5151 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04005152 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
5153 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05005154 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
5155 phba->sli4_hba.link_state.topology =
5156 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
5157 phba->sli4_hba.link_state.status =
5158 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
5159 phba->sli4_hba.link_state.type =
5160 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
5161 phba->sli4_hba.link_state.number =
5162 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
5163 phba->sli4_hba.link_state.fault =
5164 bf_get(lpfc_acqe_link_fault, acqe_fc);
James Smartb8e6f132019-05-21 17:49:04 -07005165
5166 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
5167 LPFC_FC_LA_TYPE_LINK_DOWN)
5168 phba->sli4_hba.link_state.logical_speed = 0;
5169 else if (!phba->sli4_hba.conf_trunk)
5170 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005171 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smartb8e6f132019-05-21 17:49:04 -07005172
James Smart70f3c072010-12-15 17:57:33 -05005173 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5174 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
5175 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
5176 "%dMbps Fault:%d\n",
5177 phba->sli4_hba.link_state.speed,
5178 phba->sli4_hba.link_state.topology,
5179 phba->sli4_hba.link_state.status,
5180 phba->sli4_hba.link_state.type,
5181 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04005182 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05005183 phba->sli4_hba.link_state.fault);
5184 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5185 if (!pmb) {
5186 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5187 "2897 The mboxq allocation failed\n");
5188 return;
5189 }
5190 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5191 if (!mp) {
5192 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5193 "2898 The lpfc_dmabuf allocation failed\n");
5194 goto out_free_pmb;
5195 }
5196 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
5197 if (!mp->virt) {
5198 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5199 "2899 The mbuf allocation failed\n");
5200 goto out_free_dmabuf;
5201 }
5202
5203 /* Cleanup any outstanding ELS commands */
5204 lpfc_els_flush_all_cmd(phba);
5205
5206 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08005207 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05005208
5209 /* Update link event statistics */
5210 phba->sli.slistat.link_event++;
5211
5212 /* Create lpfc_handle_latt mailbox command from link ACQE */
5213 lpfc_read_topology(phba, pmb, mp);
5214 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
5215 pmb->vport = phba->pport;
5216
James Smart7bdedb32016-07-06 12:36:00 -07005217 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07005218 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
5219
5220 switch (phba->sli4_hba.link_state.status) {
5221 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
5222 phba->link_flag |= LS_MDS_LINK_DOWN;
5223 break;
5224 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
5225 phba->link_flag |= LS_MDS_LOOPBACK;
5226 break;
5227 default:
5228 break;
5229 }
5230
James Smart23288b72018-05-04 20:37:53 -07005231 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07005232 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07005233 mb->mbxStatus = MBX_SUCCESS;
5234
5235 /* Parse port fault information field */
5236 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07005237
5238 /* Parse and translate link attention fields */
5239 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
5240 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07005241
James Smartaeb3c812017-04-21 16:05:02 -07005242 if (phba->sli4_hba.link_state.status ==
5243 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
5244 bf_set(lpfc_mbx_read_top_att_type, la,
5245 LPFC_FC_LA_TYPE_UNEXP_WWPN);
5246 } else {
5247 bf_set(lpfc_mbx_read_top_att_type, la,
5248 LPFC_FC_LA_TYPE_LINK_DOWN);
5249 }
James Smart7bdedb32016-07-06 12:36:00 -07005250 /* Invoke the mailbox command callback function */
5251 lpfc_mbx_cmpl_read_topology(phba, pmb);
5252
5253 return;
5254 }
5255
James Smart70f3c072010-12-15 17:57:33 -05005256 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5257 if (rc == MBX_NOT_FINISHED)
5258 goto out_free_dmabuf;
5259 return;
5260
5261out_free_dmabuf:
5262 kfree(mp);
5263out_free_pmb:
5264 mempool_free(pmb, phba->mbox_mem_pool);
5265}
5266
5267/**
5268 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
5269 * @phba: pointer to lpfc hba data structure.
5270 * @acqe_fc: pointer to the async SLI completion queue entry.
5271 *
5272 * This routine is to handle the SLI4 asynchronous SLI events.
5273 **/
5274static void
5275lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
5276{
James Smart4b8bae02012-06-12 13:55:07 -04005277 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04005278 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04005279 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04005280 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05005281 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04005282 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04005283 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04005284 struct Scsi_Host *shost;
James Smartcd713482018-10-23 13:41:01 -07005285 struct lpfc_vport **vports;
5286 int rc, i;
James Smart4b8bae02012-06-12 13:55:07 -04005287
James Smart946727d2015-04-07 15:07:09 -04005288 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
5289
James Smart448193b2015-12-16 18:12:05 -05005290 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5291 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
5292 "x%08x SLI Event Type:%d\n",
5293 acqe_sli->event_data1, acqe_sli->event_data2,
5294 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005295
5296 port_name = phba->Port[0];
5297 if (port_name == 0x00)
5298 port_name = '?'; /* get port name is empty */
5299
James Smart946727d2015-04-07 15:07:09 -04005300 switch (evt_type) {
5301 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
5302 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5303 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
5304 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5305
5306 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5307 "3190 Over Temperature:%d Celsius- Port Name %c\n",
5308 acqe_sli->event_data1, port_name);
5309
James Smart310429e2016-07-06 12:35:54 -07005310 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04005311 shost = lpfc_shost_from_vport(phba->pport);
5312 fc_host_post_vendor_event(shost, fc_get_event_number(),
5313 sizeof(temp_event_data),
5314 (char *)&temp_event_data,
5315 SCSI_NL_VID_TYPE_PCI
5316 | PCI_VENDOR_ID_EMULEX);
5317 break;
5318 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
5319 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
5320 temp_event_data.event_code = LPFC_NORMAL_TEMP;
5321 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
5322
5323 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5324 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
5325 acqe_sli->event_data1, port_name);
5326
5327 shost = lpfc_shost_from_vport(phba->pport);
5328 fc_host_post_vendor_event(shost, fc_get_event_number(),
5329 sizeof(temp_event_data),
5330 (char *)&temp_event_data,
5331 SCSI_NL_VID_TYPE_PCI
5332 | PCI_VENDOR_ID_EMULEX);
5333 break;
5334 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
5335 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04005336 &acqe_sli->event_data1;
5337
James Smart946727d2015-04-07 15:07:09 -04005338 /* fetch the status for this port */
5339 switch (phba->sli4_hba.lnk_info.lnk_no) {
5340 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05005341 status = bf_get(lpfc_sli_misconfigured_port0_state,
5342 &misconfigured->theEvent);
5343 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04005344 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005345 break;
5346 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05005347 status = bf_get(lpfc_sli_misconfigured_port1_state,
5348 &misconfigured->theEvent);
5349 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04005350 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005351 break;
5352 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05005353 status = bf_get(lpfc_sli_misconfigured_port2_state,
5354 &misconfigured->theEvent);
5355 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04005356 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005357 break;
5358 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05005359 status = bf_get(lpfc_sli_misconfigured_port3_state,
5360 &misconfigured->theEvent);
5361 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04005362 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04005363 break;
5364 default:
James Smart448193b2015-12-16 18:12:05 -05005365 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5366 "3296 "
5367 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5368 "event: Invalid link %d",
5369 phba->sli4_hba.lnk_info.lnk_no);
5370 return;
James Smart946727d2015-04-07 15:07:09 -04005371 }
James Smart4b8bae02012-06-12 13:55:07 -04005372
James Smart448193b2015-12-16 18:12:05 -05005373 /* Skip if optic state unchanged */
5374 if (phba->sli4_hba.lnk_info.optic_state == status)
5375 return;
5376
James Smart946727d2015-04-07 15:07:09 -04005377 switch (status) {
5378 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05005379 sprintf(message, "Physical Link is functional");
5380 break;
James Smart946727d2015-04-07 15:07:09 -04005381 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5382 sprintf(message, "Optics faulted/incorrectly "
5383 "installed/not installed - Reseat optics, "
5384 "if issue not resolved, replace.");
5385 break;
5386 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5387 sprintf(message,
5388 "Optics of two types installed - Remove one "
5389 "optic or install matching pair of optics.");
5390 break;
5391 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5392 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04005393 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04005394 break;
James Smart448193b2015-12-16 18:12:05 -05005395 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5396 sprintf(message, "Unqualified optics - Replace with "
5397 "Avago optics for Warranty and Technical "
5398 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005399 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005400 break;
5401 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5402 sprintf(message, "Uncertified optics - Replace with "
5403 "Avago-certified optics to enable link "
5404 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005405 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005406 break;
James Smart946727d2015-04-07 15:07:09 -04005407 default:
5408 /* firmware is reporting a status we don't know about */
5409 sprintf(message, "Unknown event status x%02x", status);
5410 break;
5411 }
James Smartcd713482018-10-23 13:41:01 -07005412
5413 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5414 rc = lpfc_sli4_read_config(phba);
James Smart3952e912018-10-23 13:41:02 -07005415 if (rc) {
James Smartcd713482018-10-23 13:41:01 -07005416 phba->lmt = 0;
5417 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5418 "3194 Unable to retrieve supported "
James Smart3952e912018-10-23 13:41:02 -07005419 "speeds, rc = 0x%x\n", rc);
James Smartcd713482018-10-23 13:41:01 -07005420 }
5421 vports = lpfc_create_vport_work_array(phba);
5422 if (vports != NULL) {
5423 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5424 i++) {
5425 shost = lpfc_shost_from_vport(vports[i]);
5426 lpfc_host_supported_speeds_set(shost);
5427 }
5428 }
5429 lpfc_destroy_vport_work_array(phba, vports);
5430
James Smart448193b2015-12-16 18:12:05 -05005431 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04005432 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05005433 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04005434 break;
5435 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5436 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5437 "3192 Remote DPort Test Initiated - "
5438 "Event Data1:x%08x Event Data2: x%08x\n",
5439 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04005440 break;
5441 default:
James Smart946727d2015-04-07 15:07:09 -04005442 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5443 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
5444 "x%08x SLI Event Type:%d\n",
5445 acqe_sli->event_data1, acqe_sli->event_data2,
5446 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005447 break;
5448 }
James Smart70f3c072010-12-15 17:57:33 -05005449}
5450
5451/**
James Smartfc2b9892010-02-26 14:15:29 -05005452 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5453 * @vport: pointer to vport data structure.
5454 *
5455 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5456 * response to a CVL event.
5457 *
5458 * Return the pointer to the ndlp with the vport if successful, otherwise
5459 * return NULL.
5460 **/
5461static struct lpfc_nodelist *
5462lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
5463{
5464 struct lpfc_nodelist *ndlp;
5465 struct Scsi_Host *shost;
5466 struct lpfc_hba *phba;
5467
5468 if (!vport)
5469 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05005470 phba = vport->phba;
5471 if (!phba)
5472 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04005473 ndlp = lpfc_findnode_did(vport, Fabric_DID);
5474 if (!ndlp) {
5475 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07005476 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04005477 if (!ndlp)
5478 return 0;
James Smart78730cf2010-04-06 15:06:30 -04005479 /* Set the node type */
5480 ndlp->nlp_type |= NLP_FABRIC;
5481 /* Put ndlp onto node list */
5482 lpfc_enqueue_node(vport, ndlp);
5483 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5484 /* re-setup ndlp without removing from node list */
5485 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5486 if (!ndlp)
5487 return 0;
5488 }
James Smart63e801c2010-11-20 23:14:19 -05005489 if ((phba->pport->port_state < LPFC_FLOGI) &&
5490 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005491 return NULL;
5492 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05005493 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
5494 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005495 return NULL;
5496 shost = lpfc_shost_from_vport(vport);
5497 if (!shost)
5498 return NULL;
5499 lpfc_linkdown_port(vport);
5500 lpfc_cleanup_pending_mbox(vport);
5501 spin_lock_irq(shost->host_lock);
5502 vport->fc_flag |= FC_VPORT_CVL_RCVD;
5503 spin_unlock_irq(shost->host_lock);
5504
5505 return ndlp;
5506}
5507
5508/**
5509 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
5510 * @vport: pointer to lpfc hba data structure.
5511 *
5512 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5513 * response to a FCF dead event.
5514 **/
5515static void
5516lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
5517{
5518 struct lpfc_vport **vports;
5519 int i;
5520
5521 vports = lpfc_create_vport_work_array(phba);
5522 if (vports)
5523 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
5524 lpfc_sli4_perform_vport_cvl(vports[i]);
5525 lpfc_destroy_vport_work_array(phba, vports);
5526}
5527
5528/**
James Smart76a95d72010-11-20 23:11:48 -05005529 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04005530 * @phba: pointer to lpfc hba data structure.
5531 * @acqe_link: pointer to the async fcoe completion queue entry.
5532 *
5533 * This routine is to handle the SLI4 asynchronous fcoe event.
5534 **/
5535static void
James Smart76a95d72010-11-20 23:11:48 -05005536lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05005537 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04005538{
James Smart70f3c072010-12-15 17:57:33 -05005539 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005540 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04005541 struct lpfc_vport *vport;
5542 struct lpfc_nodelist *ndlp;
5543 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05005544 int active_vlink_present;
5545 struct lpfc_vport **vports;
5546 int i;
James Smartda0436e2009-05-22 14:51:39 -04005547
James Smart70f3c072010-12-15 17:57:33 -05005548 phba->fc_eventTag = acqe_fip->event_tag;
5549 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005550 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005551 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5552 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5553 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04005554 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5555 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005556 "2546 New FCF event, evt_tag:x%x, "
5557 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005558 acqe_fip->event_tag,
5559 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005560 else
5561 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5562 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005563 "2788 FCF param modified event, "
5564 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005565 acqe_fip->event_tag,
5566 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005567 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005568 /*
5569 * During period of FCF discovery, read the FCF
5570 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005571 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005572 */
5573 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5574 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005575 "2779 Read FCF (x%x) for updating "
5576 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005577 acqe_fip->index);
5578 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005579 }
James Smart38b92ef2010-08-04 16:11:39 -04005580
5581 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005582 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005583 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005584 spin_unlock_irq(&phba->hbalock);
5585 break;
5586 }
5587 /* If fast FCF failover rescan event is pending, do nothing */
James Smart036cad12018-10-23 13:41:06 -07005588 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
James Smart38b92ef2010-08-04 16:11:39 -04005589 spin_unlock_irq(&phba->hbalock);
5590 break;
5591 }
5592
James Smartc2b97122013-05-31 17:05:36 -04005593 /* If the FCF has been in discovered state, do nothing. */
5594 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005595 spin_unlock_irq(&phba->hbalock);
5596 break;
5597 }
5598 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005599
James Smart0c9ab6f2010-02-26 14:15:57 -05005600 /* Otherwise, scan the entire FCF table and re-discover SAN */
5601 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005602 "2770 Start FCF table scan per async FCF "
5603 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005604 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005605 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5606 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005607 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005608 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5609 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005610 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005611 break;
5612
James Smart70f3c072010-12-15 17:57:33 -05005613 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005614 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005615 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005616 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5617 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005618 break;
5619
James Smart70f3c072010-12-15 17:57:33 -05005620 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005621 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005622 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005623 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005624 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005625 /*
5626 * If we are in the middle of FCF failover process, clear
5627 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005628 */
James Smartfc2b9892010-02-26 14:15:29 -05005629 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005630 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5631 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005632 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005633 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005634 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005635 break;
5636 }
James Smart38b92ef2010-08-04 16:11:39 -04005637 spin_unlock_irq(&phba->hbalock);
5638
5639 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005640 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005641 break;
5642
5643 /*
5644 * Otherwise, request the port to rediscover the entire FCF
5645 * table for a fast recovery from case that the current FCF
5646 * is no longer valid as we are not in the middle of FCF
5647 * failover process already.
5648 */
James Smartc2b97122013-05-31 17:05:36 -04005649 spin_lock_irq(&phba->hbalock);
5650 /* Mark the fast failover process in progress */
5651 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5652 spin_unlock_irq(&phba->hbalock);
5653
5654 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5655 "2771 Start FCF fast failover process due to "
5656 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5657 "\n", acqe_fip->event_tag, acqe_fip->index);
5658 rc = lpfc_sli4_redisc_fcf_table(phba);
5659 if (rc) {
5660 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5661 LOG_DISCOVERY,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005662 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005663 "command failed, fail through to FCF "
5664 "dead event\n");
5665 spin_lock_irq(&phba->hbalock);
5666 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5667 spin_unlock_irq(&phba->hbalock);
5668 /*
5669 * Last resort will fail over by treating this
5670 * as a link down to FCF registration.
5671 */
5672 lpfc_sli4_fcf_dead_failthrough(phba);
5673 } else {
5674 /* Reset FCF roundrobin bmask for new discovery */
5675 lpfc_sli4_clear_fcf_rr_bmask(phba);
5676 /*
5677 * Handling fast FCF failover to a DEAD FCF event is
5678 * considered equalivant to receiving CVL to all vports.
5679 */
5680 lpfc_sli4_perform_all_vport_cvl(phba);
5681 }
James Smartda0436e2009-05-22 14:51:39 -04005682 break;
James Smart70f3c072010-12-15 17:57:33 -05005683 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005684 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005685 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005686 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005687 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005688
James Smart6669f9b2009-10-02 15:16:45 -04005689 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005690 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005691 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005692 if (!ndlp)
5693 break;
James Smart695a8142010-01-26 23:08:03 -05005694 active_vlink_present = 0;
5695
5696 vports = lpfc_create_vport_work_array(phba);
5697 if (vports) {
5698 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5699 i++) {
5700 if ((!(vports[i]->fc_flag &
5701 FC_VPORT_CVL_RCVD)) &&
5702 (vports[i]->port_state > LPFC_FDISC)) {
5703 active_vlink_present = 1;
5704 break;
5705 }
5706 }
5707 lpfc_destroy_vport_work_array(phba, vports);
5708 }
5709
James Smartcc823552015-05-21 13:55:26 -04005710 /*
5711 * Don't re-instantiate if vport is marked for deletion.
5712 * If we are here first then vport_delete is going to wait
5713 * for discovery to complete.
5714 */
5715 if (!(vport->load_flag & FC_UNLOADING) &&
5716 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005717 /*
5718 * If there are other active VLinks present,
5719 * re-instantiate the Vlink using FDISC.
5720 */
James Smart256ec0d2013-04-17 20:14:58 -04005721 mod_timer(&ndlp->nlp_delayfunc,
5722 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005723 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005724 spin_lock_irq(shost->host_lock);
5725 ndlp->nlp_flag |= NLP_DELAY_TMO;
5726 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005727 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5728 vport->port_state = LPFC_FDISC;
5729 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005730 /*
5731 * Otherwise, we request port to rediscover
5732 * the entire FCF table for a fast recovery
5733 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005734 * is no longer valid if we are not already
5735 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005736 */
James Smartfc2b9892010-02-26 14:15:29 -05005737 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005738 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005739 spin_unlock_irq(&phba->hbalock);
5740 break;
5741 }
5742 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005743 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005744 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005745 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5746 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005747 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005748 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005749 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005750 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005751 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5752 LOG_DISCOVERY,
5753 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005754 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005755 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005756 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005757 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005758 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005759 /*
5760 * Last resort will be re-try on the
5761 * the current registered FCF entry.
5762 */
5763 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005764 } else
5765 /*
5766 * Reset FCF roundrobin bmask for new
5767 * discovery.
5768 */
James Smart7d791df2011-07-22 18:37:52 -04005769 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005770 }
5771 break;
James Smartda0436e2009-05-22 14:51:39 -04005772 default:
5773 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5774 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005775 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005776 break;
5777 }
5778}
5779
5780/**
5781 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5782 * @phba: pointer to lpfc hba data structure.
5783 * @acqe_link: pointer to the async dcbx completion queue entry.
5784 *
5785 * This routine is to handle the SLI4 asynchronous dcbx event.
5786 **/
5787static void
5788lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5789 struct lpfc_acqe_dcbx *acqe_dcbx)
5790{
James Smart4d9ab992009-10-02 15:16:39 -04005791 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005792 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5793 "0290 The SLI4 DCBX asynchronous event is not "
5794 "handled yet\n");
5795}
5796
5797/**
James Smartb19a0612010-04-06 14:48:51 -04005798 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5799 * @phba: pointer to lpfc hba data structure.
5800 * @acqe_link: pointer to the async grp5 completion queue entry.
5801 *
5802 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5803 * is an asynchronous notified of a logical link speed change. The Port
5804 * reports the logical link speed in units of 10Mbps.
5805 **/
5806static void
5807lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5808 struct lpfc_acqe_grp5 *acqe_grp5)
5809{
5810 uint16_t prev_ll_spd;
5811
5812 phba->fc_eventTag = acqe_grp5->event_tag;
5813 phba->fcoe_eventtag = acqe_grp5->event_tag;
5814 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5815 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005816 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005817 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5818 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005819 "from %dMbps to %dMbps\n", prev_ll_spd,
5820 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005821}
5822
5823/**
James Smartda0436e2009-05-22 14:51:39 -04005824 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5825 * @phba: pointer to lpfc hba data structure.
5826 *
5827 * This routine is invoked by the worker thread to process all the pending
5828 * SLI4 asynchronous events.
5829 **/
5830void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5831{
5832 struct lpfc_cq_event *cq_event;
5833
5834 /* First, declare the async event has been handled */
5835 spin_lock_irq(&phba->hbalock);
5836 phba->hba_flag &= ~ASYNC_EVENT;
5837 spin_unlock_irq(&phba->hbalock);
5838 /* Now, handle all the async events */
5839 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5840 /* Get the first event from the head of the event queue */
5841 spin_lock_irq(&phba->hbalock);
5842 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5843 cq_event, struct lpfc_cq_event, list);
5844 spin_unlock_irq(&phba->hbalock);
5845 /* Process the asynchronous event */
5846 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5847 case LPFC_TRAILER_CODE_LINK:
5848 lpfc_sli4_async_link_evt(phba,
5849 &cq_event->cqe.acqe_link);
5850 break;
5851 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005852 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005853 break;
5854 case LPFC_TRAILER_CODE_DCBX:
5855 lpfc_sli4_async_dcbx_evt(phba,
5856 &cq_event->cqe.acqe_dcbx);
5857 break;
James Smartb19a0612010-04-06 14:48:51 -04005858 case LPFC_TRAILER_CODE_GRP5:
5859 lpfc_sli4_async_grp5_evt(phba,
5860 &cq_event->cqe.acqe_grp5);
5861 break;
James Smart70f3c072010-12-15 17:57:33 -05005862 case LPFC_TRAILER_CODE_FC:
5863 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5864 break;
5865 case LPFC_TRAILER_CODE_SLI:
5866 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5867 break;
James Smartda0436e2009-05-22 14:51:39 -04005868 default:
5869 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5870 "1804 Invalid asynchrous event code: "
5871 "x%x\n", bf_get(lpfc_trailer_code,
5872 &cq_event->cqe.mcqe_cmpl));
5873 break;
5874 }
5875 /* Free the completion event processed to the free pool */
5876 lpfc_sli4_cq_event_release(phba, cq_event);
5877 }
5878}
5879
5880/**
James Smartecfd03c2010-02-12 14:41:27 -05005881 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5882 * @phba: pointer to lpfc hba data structure.
5883 *
5884 * This routine is invoked by the worker thread to process FCF table
5885 * rediscovery pending completion event.
5886 **/
5887void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5888{
5889 int rc;
5890
5891 spin_lock_irq(&phba->hbalock);
5892 /* Clear FCF rediscovery timeout event */
5893 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5894 /* Clear driver fast failover FCF record flag */
5895 phba->fcf.failover_rec.flag = 0;
5896 /* Set state for FCF fast failover */
5897 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5898 spin_unlock_irq(&phba->hbalock);
5899
5900 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005901 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005902 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005903 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005904 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005905 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5906 "2747 Issue FCF scan read FCF mailbox "
5907 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005908}
5909
5910/**
James Smartda0436e2009-05-22 14:51:39 -04005911 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5912 * @phba: pointer to lpfc hba data structure.
5913 * @dev_grp: The HBA PCI-Device group number.
5914 *
5915 * This routine is invoked to set up the per HBA PCI-Device group function
5916 * API jump table entries.
5917 *
5918 * Return: 0 if success, otherwise -ENODEV
5919 **/
5920int
5921lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005922{
5923 int rc;
5924
James Smartda0436e2009-05-22 14:51:39 -04005925 /* Set up lpfc PCI-device group */
5926 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005927
James Smartda0436e2009-05-22 14:51:39 -04005928 /* The LPFC_PCI_DEV_OC uses SLI4 */
5929 if (dev_grp == LPFC_PCI_DEV_OC)
5930 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005931
James Smartda0436e2009-05-22 14:51:39 -04005932 /* Set up device INIT API function jump table */
5933 rc = lpfc_init_api_table_setup(phba, dev_grp);
5934 if (rc)
5935 return -ENODEV;
5936 /* Set up SCSI API function jump table */
5937 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5938 if (rc)
5939 return -ENODEV;
5940 /* Set up SLI API function jump table */
5941 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5942 if (rc)
5943 return -ENODEV;
5944 /* Set up MBOX API function jump table */
5945 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5946 if (rc)
5947 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005948
James Smartda0436e2009-05-22 14:51:39 -04005949 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005950}
5951
5952/**
James Smart3621a712009-04-06 18:47:14 -04005953 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005954 * @phba: pointer to lpfc hba data structure.
5955 * @intr_mode: active interrupt mode adopted.
5956 *
5957 * This routine it invoked to log the currently used active interrupt mode
5958 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005959 **/
5960static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005961{
5962 switch (intr_mode) {
5963 case 0:
5964 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5965 "0470 Enable INTx interrupt mode.\n");
5966 break;
5967 case 1:
5968 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5969 "0481 Enabled MSI interrupt mode.\n");
5970 break;
5971 case 2:
5972 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5973 "0480 Enabled MSI-X interrupt mode.\n");
5974 break;
5975 default:
5976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5977 "0482 Illegal interrupt mode.\n");
5978 break;
5979 }
5980 return;
5981}
5982
James Smart5b75da22008-12-04 22:39:35 -05005983/**
James Smart3772a992009-05-22 14:50:54 -04005984 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005985 * @phba: pointer to lpfc hba data structure.
5986 *
James Smart3772a992009-05-22 14:50:54 -04005987 * This routine is invoked to enable the PCI device that is common to all
5988 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005989 *
5990 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005991 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005992 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005993 **/
James Smart3772a992009-05-22 14:50:54 -04005994static int
5995lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005996{
James Smart3772a992009-05-22 14:50:54 -04005997 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005998
James Smart3772a992009-05-22 14:50:54 -04005999 /* Obtain PCI device reference */
6000 if (!phba->pcidev)
6001 goto out_error;
6002 else
6003 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006004 /* Enable PCI device */
6005 if (pci_enable_device_mem(pdev))
6006 goto out_error;
6007 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006008 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04006009 goto out_disable_device;
6010 /* Set up device as PCI master and save state for EEH */
6011 pci_set_master(pdev);
6012 pci_try_set_mwi(pdev);
6013 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006014
James Smart05580562011-05-24 11:40:48 -04006015 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07006016 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04006017 pdev->needs_freset = 1;
6018
James Smart3772a992009-05-22 14:50:54 -04006019 return 0;
James Smart5b75da22008-12-04 22:39:35 -05006020
James Smart3772a992009-05-22 14:50:54 -04006021out_disable_device:
6022 pci_disable_device(pdev);
6023out_error:
James Smart079b5c92011-08-21 21:48:49 -04006024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006025 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04006026 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05006027}
6028
6029/**
James Smart3772a992009-05-22 14:50:54 -04006030 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05006031 * @phba: pointer to lpfc hba data structure.
6032 *
James Smart3772a992009-05-22 14:50:54 -04006033 * This routine is invoked to disable the PCI device that is common to all
6034 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05006035 **/
6036static void
James Smart3772a992009-05-22 14:50:54 -04006037lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05006038{
James Smart3772a992009-05-22 14:50:54 -04006039 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05006040
James Smart3772a992009-05-22 14:50:54 -04006041 /* Obtain PCI device reference */
6042 if (!phba->pcidev)
6043 return;
6044 else
6045 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04006046 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02006047 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04006048 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05006049
6050 return;
6051}
6052
6053/**
James Smart3772a992009-05-22 14:50:54 -04006054 * lpfc_reset_hba - Reset a hba
6055 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04006056 *
James Smart3772a992009-05-22 14:50:54 -04006057 * This routine is invoked to reset a hba device. It brings the HBA
6058 * offline, performs a board restart, and then brings the board back
6059 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
6060 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04006061 **/
James Smart3772a992009-05-22 14:50:54 -04006062void
6063lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05006064{
James Smart3772a992009-05-22 14:50:54 -04006065 /* If resets are disabled then set error state and return. */
6066 if (!phba->cfg_enable_hba_reset) {
6067 phba->link_state = LPFC_HBA_ERROR;
6068 return;
6069 }
James Smartee620212014-04-04 13:51:53 -04006070 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
6071 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
6072 else
6073 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04006074 lpfc_offline(phba);
6075 lpfc_sli_brdrestart(phba);
6076 lpfc_online(phba);
6077 lpfc_unblock_mgmt_io(phba);
6078}
dea31012005-04-17 16:05:31 -05006079
James Smart3772a992009-05-22 14:50:54 -04006080/**
James Smart0a96e972011-07-22 18:37:28 -04006081 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
6082 * @phba: pointer to lpfc hba data structure.
6083 *
6084 * This function enables the PCI SR-IOV virtual functions to a physical
6085 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6086 * enable the number of virtual functions to the physical function. As
6087 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6088 * API call does not considered as an error condition for most of the device.
6089 **/
6090uint16_t
6091lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
6092{
6093 struct pci_dev *pdev = phba->pcidev;
6094 uint16_t nr_virtfn;
6095 int pos;
6096
James Smart0a96e972011-07-22 18:37:28 -04006097 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6098 if (pos == 0)
6099 return 0;
6100
6101 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
6102 return nr_virtfn;
6103}
6104
6105/**
James Smart912e3ac2011-05-24 11:42:11 -04006106 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
6107 * @phba: pointer to lpfc hba data structure.
6108 * @nr_vfn: number of virtual functions to be enabled.
6109 *
6110 * This function enables the PCI SR-IOV virtual functions to a physical
6111 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
6112 * enable the number of virtual functions to the physical function. As
6113 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
6114 * API call does not considered as an error condition for most of the device.
6115 **/
6116int
6117lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
6118{
6119 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04006120 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04006121 int rc;
6122
James Smart0a96e972011-07-22 18:37:28 -04006123 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
6124 if (nr_vfn > max_nr_vfn) {
6125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6126 "3057 Requested vfs (%d) greater than "
6127 "supported vfs (%d)", nr_vfn, max_nr_vfn);
6128 return -EINVAL;
6129 }
6130
James Smart912e3ac2011-05-24 11:42:11 -04006131 rc = pci_enable_sriov(pdev, nr_vfn);
6132 if (rc) {
6133 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6134 "2806 Failed to enable sriov on this device "
6135 "with vfn number nr_vf:%d, rc:%d\n",
6136 nr_vfn, rc);
6137 } else
6138 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6139 "2807 Successful enable sriov on this device "
6140 "with vfn number nr_vf:%d\n", nr_vfn);
6141 return rc;
6142}
6143
6144/**
James Smart895427b2017-02-12 13:52:30 -08006145 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04006146 * @phba: pointer to lpfc hba data structure.
6147 *
James Smart895427b2017-02-12 13:52:30 -08006148 * This routine is invoked to set up the driver internal resources before the
6149 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04006150 *
6151 * Return codes
James Smart895427b2017-02-12 13:52:30 -08006152 * 0 - successful
6153 * other values - error
James Smart3772a992009-05-22 14:50:54 -04006154 **/
6155static int
James Smart895427b2017-02-12 13:52:30 -08006156lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04006157{
James Smart895427b2017-02-12 13:52:30 -08006158 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05006159
James Smart3772a992009-05-22 14:50:54 -04006160 /*
James Smart895427b2017-02-12 13:52:30 -08006161 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04006162 */
James Smart895427b2017-02-12 13:52:30 -08006163 atomic_set(&phba->fast_event_count, 0);
6164 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006165
James Smart895427b2017-02-12 13:52:30 -08006166 /* Initialize ndlp management spinlock */
6167 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04006168
James Smart523128e2018-09-10 10:30:46 -07006169 /* Initialize port_list spinlock */
6170 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08006171 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07006172
James Smart895427b2017-02-12 13:52:30 -08006173 INIT_LIST_HEAD(&phba->work_list);
6174 init_waitqueue_head(&phba->wait_4_mlo_m_q);
6175
6176 /* Initialize the wait queue head for the kernel thread */
6177 init_waitqueue_head(&phba->work_waitq);
6178
6179 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08006180 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08006181 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
6182 "SCSI" : " "),
6183 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08006184 "NVME" : " "),
6185 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08006186
James Smart0794d602019-01-28 11:14:19 -08006187 /* Initialize the IO buffer list used by driver for SLI3 SCSI */
6188 spin_lock_init(&phba->scsi_buf_list_get_lock);
6189 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
6190 spin_lock_init(&phba->scsi_buf_list_put_lock);
6191 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart895427b2017-02-12 13:52:30 -08006192
6193 /* Initialize the fabric iocb list */
6194 INIT_LIST_HEAD(&phba->fabric_iocb_list);
6195
6196 /* Initialize list to save ELS buffers */
6197 INIT_LIST_HEAD(&phba->elsbuf);
6198
6199 /* Initialize FCF connection rec list */
6200 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
6201
6202 /* Initialize OAS configuration list */
6203 spin_lock_init(&phba->devicelock);
6204 INIT_LIST_HEAD(&phba->luns);
6205
James Smart3772a992009-05-22 14:50:54 -04006206 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006207 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006208 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006209 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006210 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006211 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08006212 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006213 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08006214
James Smart32517fc2019-01-28 11:14:33 -08006215 INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
6216
James Smart895427b2017-02-12 13:52:30 -08006217 return 0;
6218}
6219
6220/**
6221 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
6222 * @phba: pointer to lpfc hba data structure.
6223 *
6224 * This routine is invoked to set up the driver internal resources specific to
6225 * support the SLI-3 HBA device it attached to.
6226 *
6227 * Return codes
6228 * 0 - successful
6229 * other values - error
6230 **/
6231static int
6232lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
6233{
James Smart0794d602019-01-28 11:14:19 -08006234 int rc, entry_sz;
James Smart895427b2017-02-12 13:52:30 -08006235
6236 /*
6237 * Initialize timers used by driver
6238 */
6239
6240 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006241 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04006242
6243 /* Host attention work mask setup */
6244 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
6245 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
6246
6247 /* Get all the module params for configuring this host */
6248 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08006249 /* Set up phase-1 common device driver resources */
6250
6251 rc = lpfc_setup_driver_resource_phase1(phba);
6252 if (rc)
6253 return -ENODEV;
6254
James Smart49198b32010-04-06 15:04:33 -04006255 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
6256 phba->menlo_flag |= HBA_MENLO_SUPPORT;
6257 /* check for menlo minimum sg count */
6258 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
6259 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
6260 }
6261
James Smart895427b2017-02-12 13:52:30 -08006262 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07006263 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
6264 sizeof(struct lpfc_sli_ring),
6265 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006266 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04006267 return -ENOMEM;
6268
James Smart3772a992009-05-22 14:50:54 -04006269 /*
James Smart96f70772013-04-17 20:16:15 -04006270 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04006271 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04006272 */
James Smart3772a992009-05-22 14:50:54 -04006273
James Smart96f70772013-04-17 20:16:15 -04006274 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04006275 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08006276 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
6277 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04006278
James Smart0794d602019-01-28 11:14:19 -08006279 if (phba->sli_rev == LPFC_SLI_REV4)
6280 entry_sz = sizeof(struct sli4_sge);
6281 else
6282 entry_sz = sizeof(struct ulp_bde64);
6283
James Smart96f70772013-04-17 20:16:15 -04006284 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
6285 if (phba->cfg_enable_bg) {
6286 /*
6287 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
6288 * the FCP rsp, and a BDE for each. Sice we have no control
6289 * over how many protection data segments the SCSI Layer
6290 * will hand us (ie: there could be one for every block
6291 * in the IO), we just allocate enough BDEs to accomidate
6292 * our max amount and we need to limit lpfc_sg_seg_cnt to
6293 * minimize the risk of running out.
6294 */
6295 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6296 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006297 (LPFC_MAX_SG_SEG_CNT * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006298
6299 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
6300 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
6301
6302 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
6303 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
6304 } else {
6305 /*
6306 * The scsi_buf for a regular I/O will hold the FCP cmnd,
6307 * the FCP rsp, a BDE for each, and a BDE for up to
6308 * cfg_sg_seg_cnt data segments.
6309 */
6310 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
6311 sizeof(struct fcp_rsp) +
James Smart0794d602019-01-28 11:14:19 -08006312 ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
James Smart96f70772013-04-17 20:16:15 -04006313
6314 /* Total BDEs in BPL for scsi_sg_list */
6315 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
6316 }
6317
6318 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
6319 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
6320 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
6321 phba->cfg_total_seg_cnt);
6322
James Smart3772a992009-05-22 14:50:54 -04006323 phba->max_vpi = LPFC_MAX_VPI;
6324 /* This will be set to correct value after config_port mbox */
6325 phba->max_vports = 0;
6326
6327 /*
6328 * Initialize the SLI Layer to run with lpfc HBAs.
6329 */
6330 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08006331 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04006332
6333 /* Allocate device driver memory */
6334 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
6335 return -ENOMEM;
6336
James Smart912e3ac2011-05-24 11:42:11 -04006337 /*
6338 * Enable sr-iov virtual functions if supported and configured
6339 * through the module parameter.
6340 */
6341 if (phba->cfg_sriov_nr_virtfn > 0) {
6342 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6343 phba->cfg_sriov_nr_virtfn);
6344 if (rc) {
6345 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6346 "2808 Requested number of SR-IOV "
6347 "virtual functions (%d) is not "
6348 "supported\n",
6349 phba->cfg_sriov_nr_virtfn);
6350 phba->cfg_sriov_nr_virtfn = 0;
6351 }
6352 }
6353
James Smart3772a992009-05-22 14:50:54 -04006354 return 0;
6355}
6356
6357/**
6358 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6359 * @phba: pointer to lpfc hba data structure.
6360 *
6361 * This routine is invoked to unset the driver internal resources set up
6362 * specific for supporting the SLI-3 HBA device it attached to.
6363 **/
6364static void
6365lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
6366{
6367 /* Free device driver memory allocated */
6368 lpfc_mem_free_all(phba);
6369
6370 return;
6371}
6372
6373/**
James Smartda0436e2009-05-22 14:51:39 -04006374 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6375 * @phba: pointer to lpfc hba data structure.
6376 *
6377 * This routine is invoked to set up the driver internal resources specific to
6378 * support the SLI-4 HBA device it attached to.
6379 *
6380 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006381 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04006382 * other values - error
6383 **/
6384static int
6385lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
6386{
James Smart28baac72010-02-12 14:42:03 -05006387 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08006388 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08006389 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05006390 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
6391 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04006392 int longs;
James Smart81e6a632017-11-20 16:00:43 -08006393 int extra;
James Smartf358dd02017-02-12 13:52:34 -08006394 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07006395 u32 if_type;
6396 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04006397
James Smart895427b2017-02-12 13:52:30 -08006398 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart222e9232019-01-28 11:14:35 -08006399 phba->sli4_hba.num_possible_cpu = num_possible_cpus();
James Smart895427b2017-02-12 13:52:30 -08006400 phba->sli4_hba.curr_disp_cpu = 0;
6401
James Smart716d3bc2013-09-06 12:18:28 -04006402 /* Get all the module params for configuring this host */
6403 lpfc_get_cfgparam(phba);
6404
James Smart895427b2017-02-12 13:52:30 -08006405 /* Set up phase-1 common device driver resources */
6406 rc = lpfc_setup_driver_resource_phase1(phba);
6407 if (rc)
6408 return -ENODEV;
6409
James Smartda0436e2009-05-22 14:51:39 -04006410 /* Before proceed, wait for POST done and device ready */
6411 rc = lpfc_sli4_post_status_check(phba);
6412 if (rc)
6413 return -ENODEV;
6414
6415 /*
6416 * Initialize timers used by driver
6417 */
6418
Kees Cookf22eb4d2017-09-06 20:24:26 -07006419 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04006420
James Smartecfd03c2010-02-12 14:41:27 -05006421 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006422 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05006423
James Smartda0436e2009-05-22 14:51:39 -04006424 /*
James Smart7ad20aa2011-05-24 11:44:28 -04006425 * Control structure for handling external multi-buffer mailbox
6426 * command pass-through.
6427 */
6428 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
6429 sizeof(struct lpfc_mbox_ext_buf_ctx));
6430 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
6431
James Smartda0436e2009-05-22 14:51:39 -04006432 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04006433
James Smartda0436e2009-05-22 14:51:39 -04006434 /* This will be set to correct value after the read_config mbox */
6435 phba->max_vports = 0;
6436
6437 /* Program the default value of vlan_id and fc_map */
6438 phba->valid_vlan = 0;
6439 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
6440 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
6441 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
6442
6443 /*
James Smart2a76a282012-08-03 12:35:54 -04006444 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08006445 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6446 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04006447 */
James Smart085c6472010-11-20 23:11:37 -05006448
James Smart09294d42013-04-17 20:16:05 -04006449 /*
James Smart81e6a632017-11-20 16:00:43 -08006450 * 1 for cmd, 1 for rsp, NVME adds an extra one
6451 * for boundary conditions in its max_sgl_segment template.
6452 */
6453 extra = 2;
6454 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
6455 extra++;
6456
6457 /*
James Smart09294d42013-04-17 20:16:05 -04006458 * It doesn't matter what family our adapter is in, we are
6459 * limited to 2 Pages, 512 SGEs, for our SGL.
6460 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6461 */
6462 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart09294d42013-04-17 20:16:05 -04006463
James Smartda0436e2009-05-22 14:51:39 -04006464 /*
James Smart895427b2017-02-12 13:52:30 -08006465 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6466 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05006467 */
James Smartf44ac122018-03-05 12:04:08 -08006468 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
James Smart96f70772013-04-17 20:16:15 -04006469 /*
James Smart895427b2017-02-12 13:52:30 -08006470 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6471 * the FCP rsp, and a SGE. Sice we have no control
6472 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04006473 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08006474 * in the IO), just allocate enough SGEs to accomidate
6475 * our max amount and we need to limit lpfc_sg_seg_cnt
6476 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04006477 */
6478 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006479 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04006480
6481 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6482 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
6483
James Smart5b9e70b2018-09-10 10:30:42 -07006484 /*
6485 * If supporting DIF, reduce the seg count for scsi to
6486 * allow room for the DIF sges.
6487 */
6488 if (phba->cfg_enable_bg &&
6489 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
6490 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
6491 else
6492 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6493
James Smart96f70772013-04-17 20:16:15 -04006494 } else {
6495 /*
James Smart895427b2017-02-12 13:52:30 -08006496 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04006497 * the FCP rsp, a SGE for each, and a SGE for up to
6498 * cfg_sg_seg_cnt data segments.
6499 */
6500 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006501 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08006502 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08006503 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04006504
6505 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08006506 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart5b9e70b2018-09-10 10:30:42 -07006507 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
James Smart895427b2017-02-12 13:52:30 -08006508
James Smart96f70772013-04-17 20:16:15 -04006509 /*
James Smart81e6a632017-11-20 16:00:43 -08006510 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08006511 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04006512 */
James Smart085c6472010-11-20 23:11:37 -05006513 }
James Smartacd68592012-01-18 16:25:09 -05006514
James Smart5b9e70b2018-09-10 10:30:42 -07006515 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6516 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6517 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
6518 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
6519 "6300 Reducing NVME sg segment "
6520 "cnt to %d\n",
6521 LPFC_MAX_NVME_SEG_CNT);
6522 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6523 } else
6524 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
6525 }
6526
James Smart96f70772013-04-17 20:16:15 -04006527 /* Initialize the host templates with the updated values. */
James Smart5b9e70b2018-09-10 10:30:42 -07006528 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6529 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6530 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04006531
6532 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
6533 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6534 else
6535 phba->cfg_sg_dma_buf_size =
6536 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6537
6538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smart5b9e70b2018-09-10 10:30:42 -07006539 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6540 "total:%d scsi:%d nvme:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006541 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
James Smart5b9e70b2018-09-10 10:30:42 -07006542 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6543 phba->cfg_nvme_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04006544
6545 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006546 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006547 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6548 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6549
6550 /*
6551 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6552 */
James Smart895427b2017-02-12 13:52:30 -08006553 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6554 /* Initialize the Abort scsi buffer list used by driver */
6555 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6556 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6557 }
6558
6559 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6560 /* Initialize the Abort nvme buffer list used by driver */
James Smart5e5b5112019-01-28 11:14:22 -08006561 spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07006562 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006563 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart79d8c4c2019-05-21 17:48:56 -07006564 spin_lock_init(&phba->sli4_hba.t_active_list_lock);
6565 INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
James Smart895427b2017-02-12 13:52:30 -08006566 }
6567
James Smartda0436e2009-05-22 14:51:39 -04006568 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006569 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006570 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04006571
6572 /*
James Smart6d368e52011-05-24 11:44:12 -04006573 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006574 */
6575
6576 /* Driver internel slow-path CQ Event pool */
6577 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6578 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006579 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006580 /* Asynchronous event CQ Event work queue list */
6581 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6582 /* Fast-path XRI aborted CQ Event work queue list */
6583 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6584 /* Slow-path XRI aborted CQ Event work queue list */
6585 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6586 /* Receive queue CQ Event work queue list */
6587 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6588
James Smart6d368e52011-05-24 11:44:12 -04006589 /* Initialize extent block lists. */
6590 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6591 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6592 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6593 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6594
James Smartd1f525a2017-04-21 16:04:55 -07006595 /* Initialize mboxq lists. If the early init routines fail
6596 * these lists need to be correctly initialized.
6597 */
6598 INIT_LIST_HEAD(&phba->sli.mboxq);
6599 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6600
James Smart448193b2015-12-16 18:12:05 -05006601 /* initialize optic_state to 0xFF */
6602 phba->sli4_hba.lnk_info.optic_state = 0xff;
6603
James Smartda0436e2009-05-22 14:51:39 -04006604 /* Allocate device driver memory */
6605 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6606 if (rc)
6607 return -ENOMEM;
6608
James Smart2fcee4b2010-12-15 17:57:46 -05006609 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006610 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006611 LPFC_SLI_INTF_IF_TYPE_2) {
6612 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006613 if (unlikely(rc)) {
6614 rc = -ENODEV;
6615 goto out_free_mem;
6616 }
James Smart946727d2015-04-07 15:07:09 -04006617 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006618 }
6619
James Smartda0436e2009-05-22 14:51:39 -04006620 /* Create the bootstrap mailbox command */
6621 rc = lpfc_create_bootstrap_mbox(phba);
6622 if (unlikely(rc))
6623 goto out_free_mem;
6624
6625 /* Set up the host's endian order with the device. */
6626 rc = lpfc_setup_endian_order(phba);
6627 if (unlikely(rc))
6628 goto out_free_bsmbx;
6629
6630 /* Set up the hba's configuration parameters. */
6631 rc = lpfc_sli4_read_config(phba);
6632 if (unlikely(rc))
6633 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006634 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6635 if (unlikely(rc))
6636 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006637
James Smart2fcee4b2010-12-15 17:57:46 -05006638 /* IF Type 0 ports get initialized now. */
6639 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6640 LPFC_SLI_INTF_IF_TYPE_0) {
6641 rc = lpfc_pci_function_reset(phba);
6642 if (unlikely(rc))
6643 goto out_free_bsmbx;
6644 }
James Smartda0436e2009-05-22 14:51:39 -04006645
James Smartcb5172e2010-03-15 11:25:07 -04006646 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6647 GFP_KERNEL);
6648 if (!mboxq) {
6649 rc = -ENOMEM;
6650 goto out_free_bsmbx;
6651 }
6652
James Smartf358dd02017-02-12 13:52:34 -08006653 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006654 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006655 if (lpfc_enable_nvmet_cnt) {
6656
6657 /* First get WWN of HBA instance */
6658 lpfc_read_nv(phba, mboxq);
6659 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6660 if (rc != MBX_SUCCESS) {
6661 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6662 "6016 Mailbox failed , mbxCmd x%x "
6663 "READ_NV, mbxStatus x%x\n",
6664 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6665 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006666 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006667 rc = -EIO;
6668 goto out_free_bsmbx;
6669 }
6670 mb = &mboxq->u.mb;
6671 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6672 sizeof(uint64_t));
6673 wwn = cpu_to_be64(wwn);
6674 phba->sli4_hba.wwnn.u.name = wwn;
6675 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6676 sizeof(uint64_t));
6677 /* wwn is WWPN of HBA instance */
6678 wwn = cpu_to_be64(wwn);
6679 phba->sli4_hba.wwpn.u.name = wwn;
6680
6681 /* Check to see if it matches any module parameter */
6682 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6683 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006684#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006685 if (lpfc_nvmet_mem_alloc(phba))
6686 break;
6687
6688 phba->nvmet_support = 1; /* a match */
6689
James Smartf358dd02017-02-12 13:52:34 -08006690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6691 "6017 NVME Target %016llx\n",
6692 wwn);
James Smart7d708032017-03-08 14:36:01 -08006693#else
6694 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6695 "6021 Can't enable NVME Target."
6696 " NVME_TARGET_FC infrastructure"
6697 " is not in kernel\n");
6698#endif
James Smartc4908502019-01-28 11:14:28 -08006699 /* Not supported for NVMET */
6700 phba->cfg_xri_rebalancing = 0;
James Smart3c603be2017-05-15 15:20:44 -07006701 break;
James Smartf358dd02017-02-12 13:52:34 -08006702 }
6703 }
6704 }
James Smart895427b2017-02-12 13:52:30 -08006705
6706 lpfc_nvme_mod_param_dep(phba);
6707
James Smartfedd3b72011-02-16 12:39:24 -05006708 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006709 lpfc_supported_pages(mboxq);
6710 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006711 if (!rc) {
6712 mqe = &mboxq->u.mqe;
6713 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6714 LPFC_MAX_SUPPORTED_PAGES);
6715 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6716 switch (pn_page[i]) {
6717 case LPFC_SLI4_PARAMETERS:
6718 phba->sli4_hba.pc_sli4_params.supported = 1;
6719 break;
6720 default:
6721 break;
6722 }
6723 }
6724 /* Read the port's SLI4 Parameters capabilities if supported. */
6725 if (phba->sli4_hba.pc_sli4_params.supported)
6726 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6727 if (rc) {
6728 mempool_free(mboxq, phba->mbox_mem_pool);
6729 rc = -EIO;
6730 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006731 }
6732 }
James Smart65791f12016-07-06 12:35:56 -07006733
James Smartfedd3b72011-02-16 12:39:24 -05006734 /*
6735 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006736 * If this call fails, it isn't critical unless the SLI4 parameters come
6737 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006738 */
James Smart6d368e52011-05-24 11:44:12 -04006739 rc = lpfc_get_sli4_parameters(phba, mboxq);
6740 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006741 if_type = bf_get(lpfc_sli_intf_if_type,
6742 &phba->sli4_hba.sli_intf);
6743 if_fam = bf_get(lpfc_sli_intf_sli_family,
6744 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006745 if (phba->sli4_hba.extents_in_use &&
6746 phba->sli4_hba.rpi_hdrs_in_use) {
6747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6748 "2999 Unsupported SLI4 Parameters "
6749 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006750 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6751 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6752 mempool_free(mboxq, phba->mbox_mem_pool);
6753 rc = -EIO;
6754 goto out_free_bsmbx;
6755 }
James Smart6d368e52011-05-24 11:44:12 -04006756 }
James Smartb92dc722018-05-24 21:09:01 -07006757 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6758 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6759 mempool_free(mboxq, phba->mbox_mem_pool);
6760 rc = -EIO;
6761 goto out_free_bsmbx;
6762 }
James Smart6d368e52011-05-24 11:44:12 -04006763 }
James Smart895427b2017-02-12 13:52:30 -08006764
James Smartcb5172e2010-03-15 11:25:07 -04006765 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006766
6767 /* Verify OAS is supported */
6768 lpfc_sli4_oas_verify(phba);
James Smart1ba981f2014-02-20 09:56:45 -05006769
James Smartd2cc9bc2018-09-10 10:30:50 -07006770 /* Verify RAS support on adapter */
6771 lpfc_sli4_ras_init(phba);
6772
James Smart5350d872011-10-10 21:33:49 -04006773 /* Verify all the SLI4 queues */
6774 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006775 if (rc)
6776 goto out_free_bsmbx;
6777
6778 /* Create driver internal CQE event pool */
6779 rc = lpfc_sli4_cq_event_pool_create(phba);
6780 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006781 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006782
James Smart8a9d2e82012-05-09 21:16:12 -04006783 /* Initialize sgl lists per host */
6784 lpfc_init_sgl_list(phba);
6785
6786 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006787 rc = lpfc_init_active_sgl_array(phba);
6788 if (rc) {
6789 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6790 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006791 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006792 }
James Smartda0436e2009-05-22 14:51:39 -04006793 rc = lpfc_sli4_init_rpi_hdrs(phba);
6794 if (rc) {
6795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6796 "1432 Failed to initialize rpi headers.\n");
6797 goto out_free_active_sgl;
6798 }
6799
James Smarta93ff372010-10-22 11:06:08 -04006800 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006801 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006802 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006803 GFP_KERNEL);
6804 if (!phba->fcf.fcf_rr_bmask) {
6805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6806 "2759 Failed allocate memory for FCF round "
6807 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006808 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006809 goto out_remove_rpi_hdrs;
6810 }
6811
James Smart6a828b02019-01-28 11:14:31 -08006812 phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08006813 sizeof(struct lpfc_hba_eq_hdl),
6814 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08006815 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006816 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6817 "2572 Failed allocate memory for "
6818 "fast-path per-EQ handle array\n");
6819 rc = -ENOMEM;
6820 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006821 }
6822
James Smart222e9232019-01-28 11:14:35 -08006823 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
James Smart895427b2017-02-12 13:52:30 -08006824 sizeof(struct lpfc_vector_map_info),
6825 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006826 if (!phba->sli4_hba.cpu_map) {
6827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6828 "3327 Failed allocate memory for msi-x "
6829 "interrupt vector mapping\n");
6830 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006831 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006832 }
James Smartb246de12013-05-31 17:03:07 -04006833
James Smart32517fc2019-01-28 11:14:33 -08006834 phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
6835 if (!phba->sli4_hba.eq_info) {
6836 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6837 "3321 Failed allocation for per_cpu stats\n");
6838 rc = -ENOMEM;
6839 goto out_free_hba_cpu_map;
6840 }
James Smart912e3ac2011-05-24 11:42:11 -04006841 /*
6842 * Enable sr-iov virtual functions if supported and configured
6843 * through the module parameter.
6844 */
6845 if (phba->cfg_sriov_nr_virtfn > 0) {
6846 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6847 phba->cfg_sriov_nr_virtfn);
6848 if (rc) {
6849 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6850 "3020 Requested number of SR-IOV "
6851 "virtual functions (%d) is not "
6852 "supported\n",
6853 phba->cfg_sriov_nr_virtfn);
6854 phba->cfg_sriov_nr_virtfn = 0;
6855 }
6856 }
6857
James Smart5248a742011-07-22 18:37:06 -04006858 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006859
James Smart32517fc2019-01-28 11:14:33 -08006860out_free_hba_cpu_map:
6861 kfree(phba->sli4_hba.cpu_map);
James Smart895427b2017-02-12 13:52:30 -08006862out_free_hba_eq_hdl:
6863 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006864out_free_fcf_rr_bmask:
6865 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006866out_remove_rpi_hdrs:
6867 lpfc_sli4_remove_rpi_hdrs(phba);
6868out_free_active_sgl:
6869 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006870out_destroy_cq_event_pool:
6871 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006872out_free_bsmbx:
6873 lpfc_destroy_bootstrap_mbox(phba);
6874out_free_mem:
6875 lpfc_mem_free(phba);
6876 return rc;
6877}
6878
6879/**
6880 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6881 * @phba: pointer to lpfc hba data structure.
6882 *
6883 * This routine is invoked to unset the driver internal resources set up
6884 * specific for supporting the SLI-4 HBA device it attached to.
6885 **/
6886static void
6887lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6888{
6889 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6890
James Smart32517fc2019-01-28 11:14:33 -08006891 free_percpu(phba->sli4_hba.eq_info);
6892
James Smart7bb03bb2013-04-17 20:19:16 -04006893 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6894 kfree(phba->sli4_hba.cpu_map);
James Smart222e9232019-01-28 11:14:35 -08006895 phba->sli4_hba.num_possible_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006896 phba->sli4_hba.num_present_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006897 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006898
James Smartda0436e2009-05-22 14:51:39 -04006899 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006900 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006901
6902 /* Free the allocated rpi headers. */
6903 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006904 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006905
James Smart0c9ab6f2010-02-26 14:15:57 -05006906 /* Free eligible FCF index bmask */
6907 kfree(phba->fcf.fcf_rr_bmask);
6908
James Smartda0436e2009-05-22 14:51:39 -04006909 /* Free the ELS sgl list */
6910 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006911 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006912 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006913
James Smartda0436e2009-05-22 14:51:39 -04006914 /* Free the completion queue EQ event pool */
6915 lpfc_sli4_cq_event_release_all(phba);
6916 lpfc_sli4_cq_event_pool_destroy(phba);
6917
James Smart6d368e52011-05-24 11:44:12 -04006918 /* Release resource identifiers. */
6919 lpfc_sli4_dealloc_resource_identifiers(phba);
6920
James Smartda0436e2009-05-22 14:51:39 -04006921 /* Free the bsmbx region. */
6922 lpfc_destroy_bootstrap_mbox(phba);
6923
6924 /* Free the SLI Layer memory with SLI4 HBAs */
6925 lpfc_mem_free_all(phba);
6926
6927 /* Free the current connect table */
6928 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006929 &phba->fcf_conn_rec_list, list) {
6930 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006931 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006932 }
James Smartda0436e2009-05-22 14:51:39 -04006933
6934 return;
6935}
6936
6937/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006938 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006939 * @phba: The hba struct for which this call is being executed.
6940 * @dev_grp: The HBA PCI-Device group number.
6941 *
6942 * This routine sets up the device INIT interface API function jump table
6943 * in @phba struct.
6944 *
6945 * Returns: 0 - success, -ENODEV - failure.
6946 **/
6947int
6948lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6949{
James Smart84d1b002010-02-12 14:42:33 -05006950 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6951 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006952 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006953 switch (dev_grp) {
6954 case LPFC_PCI_DEV_LP:
6955 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6956 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6957 phba->lpfc_stop_port = lpfc_stop_port_s3;
6958 break;
James Smartda0436e2009-05-22 14:51:39 -04006959 case LPFC_PCI_DEV_OC:
6960 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6961 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6962 phba->lpfc_stop_port = lpfc_stop_port_s4;
6963 break;
James Smart3772a992009-05-22 14:50:54 -04006964 default:
6965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6966 "1431 Invalid HBA PCI-device group: 0x%x\n",
6967 dev_grp);
6968 return -ENODEV;
6969 break;
6970 }
6971 return 0;
6972}
6973
6974/**
James Smart3772a992009-05-22 14:50:54 -04006975 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6976 * @phba: pointer to lpfc hba data structure.
6977 *
6978 * This routine is invoked to set up the driver internal resources after the
6979 * device specific resource setup to support the HBA device it attached to.
6980 *
6981 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006982 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006983 * other values - error
6984 **/
6985static int
6986lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6987{
6988 int error;
6989
6990 /* Startup the kernel thread for this host adapter. */
6991 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6992 "lpfc_worker_%d", phba->brd_no);
6993 if (IS_ERR(phba->worker_thread)) {
6994 error = PTR_ERR(phba->worker_thread);
6995 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006996 }
6997
James Smart0cdb84e2018-04-09 14:24:26 -07006998 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6999 if (phba->sli_rev == LPFC_SLI_REV4)
7000 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
7001 else
7002 phba->wq = NULL;
Dick Kennedyf485c182017-09-29 17:34:34 -07007003
James Smart3772a992009-05-22 14:50:54 -04007004 return 0;
7005}
7006
7007/**
7008 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
7009 * @phba: pointer to lpfc hba data structure.
7010 *
7011 * This routine is invoked to unset the driver internal resources set up after
7012 * the device specific resource setup for supporting the HBA device it
7013 * attached to.
7014 **/
7015static void
7016lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
7017{
Dick Kennedyf485c182017-09-29 17:34:34 -07007018 if (phba->wq) {
7019 flush_workqueue(phba->wq);
7020 destroy_workqueue(phba->wq);
7021 phba->wq = NULL;
7022 }
7023
James Smart3772a992009-05-22 14:50:54 -04007024 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07007025 if (phba->worker_thread)
7026 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04007027}
7028
7029/**
7030 * lpfc_free_iocb_list - Free iocb list.
7031 * @phba: pointer to lpfc hba data structure.
7032 *
7033 * This routine is invoked to free the driver's IOCB list and memory.
7034 **/
James Smart6c621a22017-05-15 15:20:45 -07007035void
James Smart3772a992009-05-22 14:50:54 -04007036lpfc_free_iocb_list(struct lpfc_hba *phba)
7037{
7038 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
7039
7040 spin_lock_irq(&phba->hbalock);
7041 list_for_each_entry_safe(iocbq_entry, iocbq_next,
7042 &phba->lpfc_iocb_list, list) {
7043 list_del(&iocbq_entry->list);
7044 kfree(iocbq_entry);
7045 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007046 }
James Smart3772a992009-05-22 14:50:54 -04007047 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007048
James Smart3772a992009-05-22 14:50:54 -04007049 return;
7050}
dea31012005-04-17 16:05:31 -05007051
James Smart3772a992009-05-22 14:50:54 -04007052/**
7053 * lpfc_init_iocb_list - Allocate and initialize iocb list.
7054 * @phba: pointer to lpfc hba data structure.
7055 *
7056 * This routine is invoked to allocate and initizlize the driver's IOCB
7057 * list and set up the IOCB tag array accordingly.
7058 *
7059 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007060 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007061 * other values - error
7062 **/
James Smart6c621a22017-05-15 15:20:45 -07007063int
James Smart3772a992009-05-22 14:50:54 -04007064lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
7065{
7066 struct lpfc_iocbq *iocbq_entry = NULL;
7067 uint16_t iotag;
7068 int i;
dea31012005-04-17 16:05:31 -05007069
7070 /* Initialize and populate the iocb list per host. */
7071 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04007072 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07007073 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05007074 if (iocbq_entry == NULL) {
7075 printk(KERN_ERR "%s: only allocated %d iocbs of "
7076 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07007077 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05007078 goto out_free_iocbq;
7079 }
7080
James Bottomley604a3e32005-10-29 10:28:33 -05007081 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
7082 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04007083 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05007084 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04007085 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05007086 goto out_free_iocbq;
7087 }
James Smart6d368e52011-05-24 11:44:12 -04007088 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04007089 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05007090
7091 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007092 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
7093 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05007094 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05007095 }
7096
James Smart3772a992009-05-22 14:50:54 -04007097 return 0;
7098
7099out_free_iocbq:
7100 lpfc_free_iocb_list(phba);
7101
7102 return -ENOMEM;
7103}
7104
7105/**
James Smart8a9d2e82012-05-09 21:16:12 -04007106 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007107 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04007108 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04007109 *
James Smart8a9d2e82012-05-09 21:16:12 -04007110 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04007111 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007112void
7113lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04007114{
7115 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04007116
7117 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
7118 list_del(&sglq_entry->list);
7119 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
7120 kfree(sglq_entry);
7121 }
7122}
7123
7124/**
7125 * lpfc_free_els_sgl_list - Free els sgl list.
7126 * @phba: pointer to lpfc hba data structure.
7127 *
7128 * This routine is invoked to free the driver's els sgl list and memory.
7129 **/
7130static void
7131lpfc_free_els_sgl_list(struct lpfc_hba *phba)
7132{
James Smartda0436e2009-05-22 14:51:39 -04007133 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007134
James Smart8a9d2e82012-05-09 21:16:12 -04007135 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04007136 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007137 spin_lock(&phba->sli4_hba.sgl_list_lock);
7138 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
7139 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04007140 spin_unlock_irq(&phba->hbalock);
7141
James Smart8a9d2e82012-05-09 21:16:12 -04007142 /* Now free the sgl list */
7143 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04007144}
7145
7146/**
James Smartf358dd02017-02-12 13:52:34 -08007147 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
7148 * @phba: pointer to lpfc hba data structure.
7149 *
7150 * This routine is invoked to free the driver's nvmet sgl list and memory.
7151 **/
7152static void
7153lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
7154{
7155 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7156 LIST_HEAD(sglq_list);
7157
7158 /* Retrieve all nvmet sgls from driver list */
7159 spin_lock_irq(&phba->hbalock);
7160 spin_lock(&phba->sli4_hba.sgl_list_lock);
7161 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
7162 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7163 spin_unlock_irq(&phba->hbalock);
7164
7165 /* Now free the sgl list */
7166 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
7167 list_del(&sglq_entry->list);
7168 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
7169 kfree(sglq_entry);
7170 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07007171
7172 /* Update the nvmet_xri_cnt to reflect no current sgls.
7173 * The next initialization cycle sets the count and allocates
7174 * the sgls over again.
7175 */
7176 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08007177}
7178
7179/**
James Smartda0436e2009-05-22 14:51:39 -04007180 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
7181 * @phba: pointer to lpfc hba data structure.
7182 *
7183 * This routine is invoked to allocate the driver's active sgl memory.
7184 * This array will hold the sglq_entry's for active IOs.
7185 **/
7186static int
7187lpfc_init_active_sgl_array(struct lpfc_hba *phba)
7188{
7189 int size;
7190 size = sizeof(struct lpfc_sglq *);
7191 size *= phba->sli4_hba.max_cfg_param.max_xri;
7192
7193 phba->sli4_hba.lpfc_sglq_active_list =
7194 kzalloc(size, GFP_KERNEL);
7195 if (!phba->sli4_hba.lpfc_sglq_active_list)
7196 return -ENOMEM;
7197 return 0;
7198}
7199
7200/**
7201 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
7202 * @phba: pointer to lpfc hba data structure.
7203 *
7204 * This routine is invoked to walk through the array of active sglq entries
7205 * and free all of the resources.
7206 * This is just a place holder for now.
7207 **/
7208static void
7209lpfc_free_active_sgl(struct lpfc_hba *phba)
7210{
7211 kfree(phba->sli4_hba.lpfc_sglq_active_list);
7212}
7213
7214/**
7215 * lpfc_init_sgl_list - Allocate and initialize sgl list.
7216 * @phba: pointer to lpfc hba data structure.
7217 *
7218 * This routine is invoked to allocate and initizlize the driver's sgl
7219 * list and set up the sgl xritag tag array accordingly.
7220 *
James Smartda0436e2009-05-22 14:51:39 -04007221 **/
James Smart8a9d2e82012-05-09 21:16:12 -04007222static void
James Smartda0436e2009-05-22 14:51:39 -04007223lpfc_init_sgl_list(struct lpfc_hba *phba)
7224{
James Smartda0436e2009-05-22 14:51:39 -04007225 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08007226 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04007227 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08007228 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07007229 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04007230
James Smart8a9d2e82012-05-09 21:16:12 -04007231 /* els xri-sgl book keeping */
7232 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007233
James Smart895427b2017-02-12 13:52:30 -08007234 /* nvme xri-buffer book keeping */
James Smart5e5b5112019-01-28 11:14:22 -08007235 phba->sli4_hba.io_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04007236}
7237
7238/**
7239 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
7240 * @phba: pointer to lpfc hba data structure.
7241 *
7242 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04007243 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04007244 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04007245 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
7246 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04007247 *
7248 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007249 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04007250 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04007251 **/
7252int
7253lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
7254{
7255 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007256 struct lpfc_rpi_hdr *rpi_hdr;
7257
7258 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05007259 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04007260 return rc;
James Smart6d368e52011-05-24 11:44:12 -04007261 if (phba->sli4_hba.extents_in_use)
7262 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04007263
7264 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
7265 if (!rpi_hdr) {
7266 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7267 "0391 Error during rpi post operation\n");
7268 lpfc_sli4_remove_rpis(phba);
7269 rc = -ENODEV;
7270 }
7271
7272 return rc;
7273}
7274
7275/**
7276 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
7277 * @phba: pointer to lpfc hba data structure.
7278 *
7279 * This routine is invoked to allocate a single 4KB memory region to
7280 * support rpis and stores them in the phba. This single region
7281 * provides support for up to 64 rpis. The region is used globally
7282 * by the device.
7283 *
7284 * Returns:
7285 * A valid rpi hdr on success.
7286 * A NULL pointer on any failure.
7287 **/
7288struct lpfc_rpi_hdr *
7289lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
7290{
7291 uint16_t rpi_limit, curr_rpi_range;
7292 struct lpfc_dmabuf *dmabuf;
7293 struct lpfc_rpi_hdr *rpi_hdr;
7294
James Smart6d368e52011-05-24 11:44:12 -04007295 /*
7296 * If the SLI4 port supports extents, posting the rpi header isn't
7297 * required. Set the expected maximum count and let the actual value
7298 * get set when extents are fully allocated.
7299 */
7300 if (!phba->sli4_hba.rpi_hdrs_in_use)
7301 return NULL;
7302 if (phba->sli4_hba.extents_in_use)
7303 return NULL;
7304
7305 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07007306 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007307
7308 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007309 /*
7310 * Establish the starting RPI in this header block. The starting
7311 * rpi is normalized to a zero base because the physical rpi is
7312 * port based.
7313 */
James Smart97f2ecf2012-03-01 22:35:23 -05007314 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04007315 spin_unlock_irq(&phba->hbalock);
7316
James Smart845d9e82017-05-15 15:20:38 -07007317 /* Reached full RPI range */
7318 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04007319 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07007320
James Smartda0436e2009-05-22 14:51:39 -04007321 /*
7322 * First allocate the protocol header region for the port. The
7323 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
7324 */
7325 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7326 if (!dmabuf)
7327 return NULL;
7328
Luis Chamberlain750afb02019-01-04 09:23:09 +01007329 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
7330 LPFC_HDR_TEMPLATE_SIZE,
7331 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007332 if (!dmabuf->virt) {
7333 rpi_hdr = NULL;
7334 goto err_free_dmabuf;
7335 }
7336
James Smartda0436e2009-05-22 14:51:39 -04007337 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
7338 rpi_hdr = NULL;
7339 goto err_free_coherent;
7340 }
7341
7342 /* Save the rpi header data for cleanup later. */
7343 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
7344 if (!rpi_hdr)
7345 goto err_free_coherent;
7346
7347 rpi_hdr->dmabuf = dmabuf;
7348 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
7349 rpi_hdr->page_count = 1;
7350 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04007351
7352 /* The rpi_hdr stores the logical index only. */
7353 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07007354 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04007355 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
7356
James Smartda0436e2009-05-22 14:51:39 -04007357 spin_unlock_irq(&phba->hbalock);
7358 return rpi_hdr;
7359
7360 err_free_coherent:
7361 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
7362 dmabuf->virt, dmabuf->phys);
7363 err_free_dmabuf:
7364 kfree(dmabuf);
7365 return NULL;
7366}
7367
7368/**
7369 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7370 * @phba: pointer to lpfc hba data structure.
7371 *
7372 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04007373 * to support rpis for SLI4 ports not supporting extents. This routine
7374 * presumes the caller has released all rpis consumed by fabric or port
7375 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04007376 **/
7377void
7378lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
7379{
7380 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
7381
James Smart6d368e52011-05-24 11:44:12 -04007382 if (!phba->sli4_hba.rpi_hdrs_in_use)
7383 goto exit;
7384
James Smartda0436e2009-05-22 14:51:39 -04007385 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
7386 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
7387 list_del(&rpi_hdr->list);
7388 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
7389 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
7390 kfree(rpi_hdr->dmabuf);
7391 kfree(rpi_hdr);
7392 }
James Smart6d368e52011-05-24 11:44:12 -04007393 exit:
7394 /* There are no rpis available to the port now. */
7395 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04007396}
7397
7398/**
James Smart3772a992009-05-22 14:50:54 -04007399 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7400 * @pdev: pointer to pci device data structure.
7401 *
7402 * This routine is invoked to allocate the driver hba data structure for an
7403 * HBA device. If the allocation is successful, the phba reference to the
7404 * PCI device data structure is set.
7405 *
7406 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007407 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04007408 * NULL - error
7409 **/
7410static struct lpfc_hba *
7411lpfc_hba_alloc(struct pci_dev *pdev)
7412{
7413 struct lpfc_hba *phba;
7414
7415 /* Allocate memory for HBA structure */
7416 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
7417 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02007418 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04007419 return NULL;
7420 }
7421
7422 /* Set reference to PCI device in HBA structure */
7423 phba->pcidev = pdev;
7424
7425 /* Assign an unused board number */
7426 phba->brd_no = lpfc_get_instance();
7427 if (phba->brd_no < 0) {
7428 kfree(phba);
7429 return NULL;
7430 }
James Smart65791f12016-07-06 12:35:56 -07007431 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04007432
James Smart4fede782010-01-26 23:08:55 -05007433 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04007434 INIT_LIST_HEAD(&phba->ct_ev_waiters);
7435
James Smart3772a992009-05-22 14:50:54 -04007436 return phba;
7437}
7438
7439/**
7440 * lpfc_hba_free - Free driver hba data structure with a device.
7441 * @phba: pointer to lpfc hba data structure.
7442 *
7443 * This routine is invoked to free the driver hba data structure with an
7444 * HBA device.
7445 **/
7446static void
7447lpfc_hba_free(struct lpfc_hba *phba)
7448{
James Smart5e5b5112019-01-28 11:14:22 -08007449 if (phba->sli_rev == LPFC_SLI_REV4)
7450 kfree(phba->sli4_hba.hdwq);
7451
James Smart3772a992009-05-22 14:50:54 -04007452 /* Release the driver assigned board number */
7453 idr_remove(&lpfc_hba_index, phba->brd_no);
7454
James Smart895427b2017-02-12 13:52:30 -08007455 /* Free memory allocated with sli3 rings */
7456 kfree(phba->sli.sli3_ring);
7457 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04007458
James Smart3772a992009-05-22 14:50:54 -04007459 kfree(phba);
7460 return;
7461}
7462
7463/**
7464 * lpfc_create_shost - Create hba physical port with associated scsi host.
7465 * @phba: pointer to lpfc hba data structure.
7466 *
7467 * This routine is invoked to create HBA physical port and associate a SCSI
7468 * host with it.
7469 *
7470 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007471 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007472 * other values - error
7473 **/
7474static int
7475lpfc_create_shost(struct lpfc_hba *phba)
7476{
7477 struct lpfc_vport *vport;
7478 struct Scsi_Host *shost;
7479
7480 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05007481 phba->fc_edtov = FF_DEF_EDTOV;
7482 phba->fc_ratov = FF_DEF_RATOV;
7483 phba->fc_altov = FF_DEF_ALTOV;
7484 phba->fc_arbtov = FF_DEF_ARBTOV;
7485
James Smartd7c47992010-06-08 18:31:54 -04007486 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04007487 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05007488 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04007489 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05007490
7491 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05007492 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08007493
James Smartf358dd02017-02-12 13:52:34 -08007494 if (phba->nvmet_support) {
7495 /* Only 1 vport (pport) will support NVME target */
7496 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02007497 phba->txrdy_payload_pool = dma_pool_create(
7498 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08007499 TXRDY_PAYLOAD_LEN, 16, 0);
7500 if (phba->txrdy_payload_pool) {
7501 phba->targetport = NULL;
7502 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
7503 lpfc_printf_log(phba, KERN_INFO,
7504 LOG_INIT | LOG_NVME_DISC,
7505 "6076 NVME Target Found\n");
7506 }
7507 }
7508 }
7509
James Smart858c9f62007-06-17 19:56:39 -05007510 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04007511 /* Put reference to SCSI host to driver's device private data */
7512 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05007513
James Smart4258e982015-12-16 18:11:58 -05007514 /*
7515 * At this point we are fully registered with PSA. In addition,
7516 * any initial discovery should be completed.
7517 */
7518 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07007519 if (phba->cfg_enable_SmartSAN ||
7520 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05007521
7522 /* Setup appropriate attribute masks */
7523 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07007524 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05007525 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
7526 else
7527 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7528 }
James Smart3772a992009-05-22 14:50:54 -04007529 return 0;
7530}
dea31012005-04-17 16:05:31 -05007531
James Smart3772a992009-05-22 14:50:54 -04007532/**
7533 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7534 * @phba: pointer to lpfc hba data structure.
7535 *
7536 * This routine is invoked to destroy HBA physical port and the associated
7537 * SCSI host.
7538 **/
7539static void
7540lpfc_destroy_shost(struct lpfc_hba *phba)
7541{
7542 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007543
James Smart3772a992009-05-22 14:50:54 -04007544 /* Destroy physical port that associated with the SCSI host */
7545 destroy_port(vport);
7546
7547 return;
7548}
7549
7550/**
7551 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7552 * @phba: pointer to lpfc hba data structure.
7553 * @shost: the shost to be used to detect Block guard settings.
7554 *
7555 * This routine sets up the local Block guard protocol settings for @shost.
7556 * This routine also allocates memory for debugging bg buffers.
7557 **/
7558static void
7559lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7560{
James Smartbbeb79b2012-06-12 13:54:27 -04007561 uint32_t old_mask;
7562 uint32_t old_guard;
7563
James Smart3772a992009-05-22 14:50:54 -04007564 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07007565 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007566 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7567 "1478 Registering BlockGuard with the "
7568 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007569
James Smartb3b98b72016-10-13 15:06:06 -07007570 old_mask = phba->cfg_prot_mask;
7571 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007572
7573 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007574 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007575 SHOST_DIX_TYPE0_PROTECTION |
7576 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007577 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7578 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007579
7580 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007581 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7582 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007583
James Smartb3b98b72016-10-13 15:06:06 -07007584 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7585 if ((old_mask != phba->cfg_prot_mask) ||
7586 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7588 "1475 Registering BlockGuard with the "
7589 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007590 phba->cfg_prot_mask,
7591 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007592
James Smartb3b98b72016-10-13 15:06:06 -07007593 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7594 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007595 } else
7596 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7597 "1479 Not Registering BlockGuard with the SCSI "
7598 "layer, Bad protection parameters: %d %d\n",
7599 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007600 }
James Smartbbeb79b2012-06-12 13:54:27 -04007601
James Smart81301a92008-12-04 22:39:46 -05007602 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007603 while (pagecnt) {
7604 spin_lock_init(&_dump_buf_lock);
7605 _dump_buf_data =
7606 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7607 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007608 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7609 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007610 "_dump_buf_data at 0x%p\n",
7611 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007612 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007613 memset(_dump_buf_data, 0,
7614 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007615 break;
James Smart3772a992009-05-22 14:50:54 -04007616 } else
James Smart81301a92008-12-04 22:39:46 -05007617 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007618 }
James Smart81301a92008-12-04 22:39:46 -05007619 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007620 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7621 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007622 "memory for hexdump\n");
7623 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007624 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7625 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007626 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007627 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007628 while (pagecnt) {
7629 _dump_buf_dif =
7630 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7631 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007632 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7633 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007634 "_dump_buf_dif at 0x%p\n",
7635 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007636 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007637 memset(_dump_buf_dif, 0,
7638 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007639 break;
James Smart3772a992009-05-22 14:50:54 -04007640 } else
James Smart81301a92008-12-04 22:39:46 -05007641 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007642 }
James Smart81301a92008-12-04 22:39:46 -05007643 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007644 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7645 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007646 "memory for hexdump\n");
7647 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007648 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7649 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007650 _dump_buf_dif);
7651}
7652
7653/**
7654 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7655 * @phba: pointer to lpfc hba data structure.
7656 *
7657 * This routine is invoked to perform all the necessary post initialization
7658 * setup for the device.
7659 **/
7660static void
7661lpfc_post_init_setup(struct lpfc_hba *phba)
7662{
7663 struct Scsi_Host *shost;
7664 struct lpfc_adapter_event_header adapter_event;
7665
7666 /* Get the default values for Model Name and Description */
7667 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7668
7669 /*
7670 * hba setup may have changed the hba_queue_depth so we need to
7671 * adjust the value of can_queue.
7672 */
7673 shost = pci_get_drvdata(phba->pcidev);
7674 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart858c9f62007-06-17 19:56:39 -05007675
7676 lpfc_host_attrib_init(shost);
7677
James Smart2e0fef82007-06-17 19:56:36 -05007678 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7679 spin_lock_irq(shost->host_lock);
7680 lpfc_poll_start_timer(phba);
7681 spin_unlock_irq(shost->host_lock);
7682 }
James Smart8f6d98d2006-08-01 07:34:00 -04007683
James Smart93996272008-08-24 21:50:30 -04007684 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7685 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007686 /* Send board arrival event to upper layer */
7687 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7688 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7689 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007690 sizeof(adapter_event),
7691 (char *) &adapter_event,
7692 LPFC_NL_VENDOR_ID);
7693 return;
7694}
7695
7696/**
7697 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7698 * @phba: pointer to lpfc hba data structure.
7699 *
7700 * This routine is invoked to set up the PCI device memory space for device
7701 * with SLI-3 interface spec.
7702 *
7703 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007704 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007705 * other values - error
7706 **/
7707static int
7708lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7709{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007710 struct pci_dev *pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007711 unsigned long bar0map_len, bar2map_len;
7712 int i, hbq_count;
7713 void *ptr;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007714 int error;
James Smart3772a992009-05-22 14:50:54 -04007715
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007716 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01007717 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007718
7719 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01007720 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7721 if (error)
7722 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7723 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007724 return error;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007725 error = -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007726
7727 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7728 * required by each mapping.
7729 */
7730 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7731 bar0map_len = pci_resource_len(pdev, 0);
7732
7733 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7734 bar2map_len = pci_resource_len(pdev, 2);
7735
7736 /* Map HBA SLIM to a kernel virtual address. */
7737 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7738 if (!phba->slim_memmap_p) {
7739 dev_printk(KERN_ERR, &pdev->dev,
7740 "ioremap failed for SLIM memory.\n");
7741 goto out;
7742 }
7743
7744 /* Map HBA Control Registers to a kernel virtual address. */
7745 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7746 if (!phba->ctrl_regs_memmap_p) {
7747 dev_printk(KERN_ERR, &pdev->dev,
7748 "ioremap failed for HBA control registers.\n");
7749 goto out_iounmap_slim;
7750 }
7751
7752 /* Allocate memory for SLI-2 structures */
Luis Chamberlain750afb02019-01-04 09:23:09 +01007753 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7754 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007755 if (!phba->slim2p.virt)
7756 goto out_iounmap;
7757
James Smart3772a992009-05-22 14:50:54 -04007758 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007759 phba->mbox_ext = (phba->slim2p.virt +
7760 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007761 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7762 phba->IOCBs = (phba->slim2p.virt +
7763 offsetof(struct lpfc_sli2_slim, IOCBs));
7764
7765 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7766 lpfc_sli_hbq_size(),
7767 &phba->hbqslimp.phys,
7768 GFP_KERNEL);
7769 if (!phba->hbqslimp.virt)
7770 goto out_free_slim;
7771
7772 hbq_count = lpfc_sli_hbq_count();
7773 ptr = phba->hbqslimp.virt;
7774 for (i = 0; i < hbq_count; ++i) {
7775 phba->hbqs[i].hbq_virt = ptr;
7776 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7777 ptr += (lpfc_hbq_defs[i]->entry_count *
7778 sizeof(struct lpfc_hbq_entry));
7779 }
7780 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7781 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7782
7783 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7784
James Smart3772a992009-05-22 14:50:54 -04007785 phba->MBslimaddr = phba->slim_memmap_p;
7786 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7787 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7788 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7789 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007790
dea31012005-04-17 16:05:31 -05007791 return 0;
7792
dea31012005-04-17 16:05:31 -05007793out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007794 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7795 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007796out_iounmap:
7797 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007798out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007799 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007800out:
7801 return error;
7802}
7803
James Smarte59058c2008-08-24 21:49:00 -04007804/**
James Smart3772a992009-05-22 14:50:54 -04007805 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7806 * @phba: pointer to lpfc hba data structure.
7807 *
7808 * This routine is invoked to unset the PCI device memory space for device
7809 * with SLI-3 interface spec.
7810 **/
7811static void
7812lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7813{
7814 struct pci_dev *pdev;
7815
7816 /* Obtain PCI device reference */
7817 if (!phba->pcidev)
7818 return;
7819 else
7820 pdev = phba->pcidev;
7821
7822 /* Free coherent DMA memory allocated */
7823 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7824 phba->hbqslimp.virt, phba->hbqslimp.phys);
7825 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7826 phba->slim2p.virt, phba->slim2p.phys);
7827
7828 /* I/O memory unmap */
7829 iounmap(phba->ctrl_regs_memmap_p);
7830 iounmap(phba->slim_memmap_p);
7831
7832 return;
7833}
7834
7835/**
James Smartda0436e2009-05-22 14:51:39 -04007836 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7837 * @phba: pointer to lpfc hba data structure.
7838 *
7839 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7840 * done and check status.
7841 *
7842 * Return 0 if successful, otherwise -ENODEV.
7843 **/
7844int
7845lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7846{
James Smart2fcee4b2010-12-15 17:57:46 -05007847 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7848 struct lpfc_register reg_data;
7849 int i, port_error = 0;
7850 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007851
James Smart9940b972011-03-11 16:06:12 -05007852 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7853 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007854 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007855 return -ENODEV;
7856
James Smartda0436e2009-05-22 14:51:39 -04007857 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7858 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007859 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7860 &portsmphr_reg.word0) ||
7861 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007862 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007863 port_error = -ENODEV;
7864 break;
7865 }
James Smart2fcee4b2010-12-15 17:57:46 -05007866 if (LPFC_POST_STAGE_PORT_READY ==
7867 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007868 break;
James Smartda0436e2009-05-22 14:51:39 -04007869 msleep(10);
7870 }
7871
James Smart2fcee4b2010-12-15 17:57:46 -05007872 /*
7873 * If there was a port error during POST, then don't proceed with
7874 * other register reads as the data may not be valid. Just exit.
7875 */
7876 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007878 "1408 Port Failed POST - portsmphr=0x%x, "
7879 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7880 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7881 portsmphr_reg.word0,
7882 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7883 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7884 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7885 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7886 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7887 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7888 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7889 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7890 } else {
James Smart28baac72010-02-12 14:42:03 -05007891 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007892 "2534 Device Info: SLIFamily=0x%x, "
7893 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7894 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007895 bf_get(lpfc_sli_intf_sli_family,
7896 &phba->sli4_hba.sli_intf),
7897 bf_get(lpfc_sli_intf_slirev,
7898 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007899 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007900 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007901 bf_get(lpfc_sli_intf_sli_hint1,
7902 &phba->sli4_hba.sli_intf),
7903 bf_get(lpfc_sli_intf_sli_hint2,
7904 &phba->sli4_hba.sli_intf),
7905 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007906 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007907 /*
7908 * Check for other Port errors during the initialization
7909 * process. Fail the load if the port did not come up
7910 * correctly.
7911 */
7912 if_type = bf_get(lpfc_sli_intf_if_type,
7913 &phba->sli4_hba.sli_intf);
7914 switch (if_type) {
7915 case LPFC_SLI_INTF_IF_TYPE_0:
7916 phba->sli4_hba.ue_mask_lo =
7917 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7918 phba->sli4_hba.ue_mask_hi =
7919 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7920 uerrlo_reg.word0 =
7921 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7922 uerrhi_reg.word0 =
7923 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7924 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7925 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7927 "1422 Unrecoverable Error "
7928 "Detected during POST "
7929 "uerr_lo_reg=0x%x, "
7930 "uerr_hi_reg=0x%x, "
7931 "ue_mask_lo_reg=0x%x, "
7932 "ue_mask_hi_reg=0x%x\n",
7933 uerrlo_reg.word0,
7934 uerrhi_reg.word0,
7935 phba->sli4_hba.ue_mask_lo,
7936 phba->sli4_hba.ue_mask_hi);
7937 port_error = -ENODEV;
7938 }
7939 break;
7940 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007941 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007942 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007943 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7944 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007945 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7946 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007947 phba->work_status[0] =
7948 readl(phba->sli4_hba.u.if_type2.
7949 ERR1regaddr);
7950 phba->work_status[1] =
7951 readl(phba->sli4_hba.u.if_type2.
7952 ERR2regaddr);
7953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007954 "2888 Unrecoverable port error "
7955 "following POST: port status reg "
7956 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007957 "error 1=0x%x, error 2=0x%x\n",
7958 reg_data.word0,
7959 portsmphr_reg.word0,
7960 phba->work_status[0],
7961 phba->work_status[1]);
7962 port_error = -ENODEV;
7963 }
7964 break;
7965 case LPFC_SLI_INTF_IF_TYPE_1:
7966 default:
7967 break;
7968 }
James Smart28baac72010-02-12 14:42:03 -05007969 }
James Smartda0436e2009-05-22 14:51:39 -04007970 return port_error;
7971}
7972
7973/**
7974 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7975 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007976 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007977 *
7978 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7979 * memory map.
7980 **/
7981static void
James Smart2fcee4b2010-12-15 17:57:46 -05007982lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007983{
James Smart2fcee4b2010-12-15 17:57:46 -05007984 switch (if_type) {
7985 case LPFC_SLI_INTF_IF_TYPE_0:
7986 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7987 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7988 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7989 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7990 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7991 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7992 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7993 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7994 phba->sli4_hba.SLIINTFregaddr =
7995 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7996 break;
7997 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007998 phba->sli4_hba.u.if_type2.EQDregaddr =
7999 phba->sli4_hba.conf_regs_memmap_p +
8000 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008001 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008002 phba->sli4_hba.conf_regs_memmap_p +
8003 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008004 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008005 phba->sli4_hba.conf_regs_memmap_p +
8006 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008007 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008008 phba->sli4_hba.conf_regs_memmap_p +
8009 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008010 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008011 phba->sli4_hba.conf_regs_memmap_p +
8012 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008013 phba->sli4_hba.SLIINTFregaddr =
8014 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
8015 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04008016 phba->sli4_hba.conf_regs_memmap_p +
8017 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05008018 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008019 phba->sli4_hba.conf_regs_memmap_p +
8020 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05008021 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05008022 phba->sli4_hba.conf_regs_memmap_p +
8023 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008024 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05008025 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08008026 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05008027 phba->sli4_hba.MQDBregaddr =
8028 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
8029 phba->sli4_hba.BMBXregaddr =
8030 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8031 break;
James Smart27d6ac02018-02-22 08:18:42 -08008032 case LPFC_SLI_INTF_IF_TYPE_6:
8033 phba->sli4_hba.u.if_type2.EQDregaddr =
8034 phba->sli4_hba.conf_regs_memmap_p +
8035 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
8036 phba->sli4_hba.u.if_type2.ERR1regaddr =
8037 phba->sli4_hba.conf_regs_memmap_p +
8038 LPFC_CTL_PORT_ER1_OFFSET;
8039 phba->sli4_hba.u.if_type2.ERR2regaddr =
8040 phba->sli4_hba.conf_regs_memmap_p +
8041 LPFC_CTL_PORT_ER2_OFFSET;
8042 phba->sli4_hba.u.if_type2.CTRLregaddr =
8043 phba->sli4_hba.conf_regs_memmap_p +
8044 LPFC_CTL_PORT_CTL_OFFSET;
8045 phba->sli4_hba.u.if_type2.STATUSregaddr =
8046 phba->sli4_hba.conf_regs_memmap_p +
8047 LPFC_CTL_PORT_STA_OFFSET;
8048 phba->sli4_hba.PSMPHRregaddr =
8049 phba->sli4_hba.conf_regs_memmap_p +
8050 LPFC_CTL_PORT_SEM_OFFSET;
8051 phba->sli4_hba.BMBXregaddr =
8052 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
8053 break;
James Smart2fcee4b2010-12-15 17:57:46 -05008054 case LPFC_SLI_INTF_IF_TYPE_1:
8055 default:
8056 dev_printk(KERN_ERR, &phba->pcidev->dev,
8057 "FATAL - unsupported SLI4 interface type - %d\n",
8058 if_type);
8059 break;
8060 }
James Smartda0436e2009-05-22 14:51:39 -04008061}
8062
8063/**
8064 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
8065 * @phba: pointer to lpfc hba data structure.
8066 *
James Smart27d6ac02018-02-22 08:18:42 -08008067 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04008068 **/
8069static void
James Smart27d6ac02018-02-22 08:18:42 -08008070lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04008071{
James Smart27d6ac02018-02-22 08:18:42 -08008072 switch (if_type) {
8073 case LPFC_SLI_INTF_IF_TYPE_0:
8074 phba->sli4_hba.PSMPHRregaddr =
8075 phba->sli4_hba.ctrl_regs_memmap_p +
8076 LPFC_SLIPORT_IF0_SMPHR;
8077 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8078 LPFC_HST_ISR0;
8079 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8080 LPFC_HST_IMR0;
8081 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
8082 LPFC_HST_ISCR0;
8083 break;
8084 case LPFC_SLI_INTF_IF_TYPE_6:
8085 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8086 LPFC_IF6_RQ_DOORBELL;
8087 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8088 LPFC_IF6_WQ_DOORBELL;
8089 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8090 LPFC_IF6_CQ_DOORBELL;
8091 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8092 LPFC_IF6_EQ_DOORBELL;
8093 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
8094 LPFC_IF6_MQ_DOORBELL;
8095 break;
8096 case LPFC_SLI_INTF_IF_TYPE_2:
8097 case LPFC_SLI_INTF_IF_TYPE_1:
8098 default:
8099 dev_err(&phba->pcidev->dev,
8100 "FATAL - unsupported SLI4 interface type - %d\n",
8101 if_type);
8102 break;
8103 }
James Smartda0436e2009-05-22 14:51:39 -04008104}
8105
8106/**
8107 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
8108 * @phba: pointer to lpfc hba data structure.
8109 * @vf: virtual function number
8110 *
8111 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
8112 * based on the given viftual function number, @vf.
8113 *
8114 * Return 0 if successful, otherwise -ENODEV.
8115 **/
8116static int
8117lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
8118{
8119 if (vf > LPFC_VIR_FUNC_MAX)
8120 return -ENODEV;
8121
8122 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008123 vf * LPFC_VFR_PAGE_SIZE +
8124 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04008125 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05008126 vf * LPFC_VFR_PAGE_SIZE +
8127 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08008128 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8129 vf * LPFC_VFR_PAGE_SIZE +
8130 LPFC_EQCQ_DOORBELL);
8131 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04008132 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8133 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
8134 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
8135 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
8136 return 0;
8137}
8138
8139/**
8140 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
8141 * @phba: pointer to lpfc hba data structure.
8142 *
8143 * This routine is invoked to create the bootstrap mailbox
8144 * region consistent with the SLI-4 interface spec. This
8145 * routine allocates all memory necessary to communicate
8146 * mailbox commands to the port and sets up all alignment
8147 * needs. No locks are expected to be held when calling
8148 * this routine.
8149 *
8150 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008151 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04008152 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04008153 **/
8154static int
8155lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
8156{
8157 uint32_t bmbx_size;
8158 struct lpfc_dmabuf *dmabuf;
8159 struct dma_address *dma_address;
8160 uint32_t pa_addr;
8161 uint64_t phys_addr;
8162
8163 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
8164 if (!dmabuf)
8165 return -ENOMEM;
8166
8167 /*
8168 * The bootstrap mailbox region is comprised of 2 parts
8169 * plus an alignment restriction of 16 bytes.
8170 */
8171 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Luis Chamberlain750afb02019-01-04 09:23:09 +01008172 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
8173 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04008174 if (!dmabuf->virt) {
8175 kfree(dmabuf);
8176 return -ENOMEM;
8177 }
James Smartda0436e2009-05-22 14:51:39 -04008178
8179 /*
8180 * Initialize the bootstrap mailbox pointers now so that the register
8181 * operations are simple later. The mailbox dma address is required
8182 * to be 16-byte aligned. Also align the virtual memory as each
8183 * maibox is copied into the bmbx mailbox region before issuing the
8184 * command to the port.
8185 */
8186 phba->sli4_hba.bmbx.dmabuf = dmabuf;
8187 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
8188
8189 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
8190 LPFC_ALIGN_16_BYTE);
8191 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
8192 LPFC_ALIGN_16_BYTE);
8193
8194 /*
8195 * Set the high and low physical addresses now. The SLI4 alignment
8196 * requirement is 16 bytes and the mailbox is posted to the port
8197 * as two 30-bit addresses. The other data is a bit marking whether
8198 * the 30-bit address is the high or low address.
8199 * Upcast bmbx aphys to 64bits so shift instruction compiles
8200 * clean on 32 bit machines.
8201 */
8202 dma_address = &phba->sli4_hba.bmbx.dma_address;
8203 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
8204 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
8205 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
8206 LPFC_BMBX_BIT1_ADDR_HI);
8207
8208 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
8209 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
8210 LPFC_BMBX_BIT1_ADDR_LO);
8211 return 0;
8212}
8213
8214/**
8215 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
8216 * @phba: pointer to lpfc hba data structure.
8217 *
8218 * This routine is invoked to teardown the bootstrap mailbox
8219 * region and release all host resources. This routine requires
8220 * the caller to ensure all mailbox commands recovered, no
8221 * additional mailbox comands are sent, and interrupts are disabled
8222 * before calling this routine.
8223 *
8224 **/
8225static void
8226lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
8227{
8228 dma_free_coherent(&phba->pcidev->dev,
8229 phba->sli4_hba.bmbx.bmbx_size,
8230 phba->sli4_hba.bmbx.dmabuf->virt,
8231 phba->sli4_hba.bmbx.dmabuf->phys);
8232
8233 kfree(phba->sli4_hba.bmbx.dmabuf);
8234 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
8235}
8236
8237/**
8238 * lpfc_sli4_read_config - Get the config parameters.
8239 * @phba: pointer to lpfc hba data structure.
8240 *
8241 * This routine is invoked to read the configuration parameters from the HBA.
8242 * The configuration parameters are used to set the base and maximum values
8243 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
8244 * allocation for the port.
8245 *
8246 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008247 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008248 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008249 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008250 **/
James Smartff78d8f2011-12-13 13:21:35 -05008251int
James Smartda0436e2009-05-22 14:51:39 -04008252lpfc_sli4_read_config(struct lpfc_hba *phba)
8253{
8254 LPFC_MBOXQ_t *pmb;
8255 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04008256 union lpfc_sli4_cfg_shdr *shdr;
8257 uint32_t shdr_status, shdr_add_status;
8258 struct lpfc_mbx_get_func_cfg *get_func_cfg;
8259 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04008260 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07008261 uint16_t forced_link_speed;
James Smart6a828b02019-01-28 11:14:31 -08008262 uint32_t if_type, qmin;
James Smart8aa134a2012-08-14 14:25:29 -04008263 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04008264
8265 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8266 if (!pmb) {
8267 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8268 "2011 Unable to allocate memory for issuing "
8269 "SLI_CONFIG_SPECIAL mailbox command\n");
8270 return -ENOMEM;
8271 }
8272
8273 lpfc_read_config(phba, pmb);
8274
8275 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8276 if (rc != MBX_SUCCESS) {
8277 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8278 "2012 Mailbox failed , mbxCmd x%x "
8279 "READ_CONFIG, mbxStatus x%x\n",
8280 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8281 bf_get(lpfc_mqe_status, &pmb->u.mqe));
8282 rc = -EIO;
8283 } else {
8284 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05008285 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
8286 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
8287 phba->sli4_hba.lnk_info.lnk_tp =
8288 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
8289 phba->sli4_hba.lnk_info.lnk_no =
8290 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
8291 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8292 "3081 lnk_type:%d, lnk_numb:%d\n",
8293 phba->sli4_hba.lnk_info.lnk_tp,
8294 phba->sli4_hba.lnk_info.lnk_no);
8295 } else
8296 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
8297 "3082 Mailbox (x%x) returned ldv:x0\n",
8298 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07008299 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
8300 phba->bbcredit_support = 1;
8301 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
8302 }
8303
James Smart1dc5ec22018-10-23 13:41:11 -07008304 phba->sli4_hba.conf_trunk =
8305 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04008306 phba->sli4_hba.extents_in_use =
8307 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008308 phba->sli4_hba.max_cfg_param.max_xri =
8309 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
8310 phba->sli4_hba.max_cfg_param.xri_base =
8311 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
8312 phba->sli4_hba.max_cfg_param.max_vpi =
8313 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08008314 /* Limit the max we support */
8315 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
8316 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04008317 phba->sli4_hba.max_cfg_param.vpi_base =
8318 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
8319 phba->sli4_hba.max_cfg_param.max_rpi =
8320 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
8321 phba->sli4_hba.max_cfg_param.rpi_base =
8322 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
8323 phba->sli4_hba.max_cfg_param.max_vfi =
8324 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
8325 phba->sli4_hba.max_cfg_param.vfi_base =
8326 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
8327 phba->sli4_hba.max_cfg_param.max_fcfi =
8328 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04008329 phba->sli4_hba.max_cfg_param.max_eq =
8330 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
8331 phba->sli4_hba.max_cfg_param.max_rq =
8332 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
8333 phba->sli4_hba.max_cfg_param.max_wq =
8334 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
8335 phba->sli4_hba.max_cfg_param.max_cq =
8336 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
8337 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
8338 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
8339 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
8340 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05008341 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
8342 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04008343 phba->max_vports = phba->max_vpi;
8344 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04008345 "2003 cfg params Extents? %d "
8346 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04008347 "VPI(B:%d M:%d) "
8348 "VFI(B:%d M:%d) "
8349 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08008350 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04008351 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04008352 phba->sli4_hba.max_cfg_param.xri_base,
8353 phba->sli4_hba.max_cfg_param.max_xri,
8354 phba->sli4_hba.max_cfg_param.vpi_base,
8355 phba->sli4_hba.max_cfg_param.max_vpi,
8356 phba->sli4_hba.max_cfg_param.vfi_base,
8357 phba->sli4_hba.max_cfg_param.max_vfi,
8358 phba->sli4_hba.max_cfg_param.rpi_base,
8359 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08008360 phba->sli4_hba.max_cfg_param.max_fcfi,
8361 phba->sli4_hba.max_cfg_param.max_eq,
8362 phba->sli4_hba.max_cfg_param.max_cq,
8363 phba->sli4_hba.max_cfg_param.max_wq,
8364 phba->sli4_hba.max_cfg_param.max_rq);
8365
James Smartd38f33b2018-05-04 20:37:54 -07008366 /*
James Smart6a828b02019-01-28 11:14:31 -08008367 * Calculate queue resources based on how
8368 * many WQ/CQ/EQs are available.
James Smartd38f33b2018-05-04 20:37:54 -07008369 */
James Smart6a828b02019-01-28 11:14:31 -08008370 qmin = phba->sli4_hba.max_cfg_param.max_wq;
8371 if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
8372 qmin = phba->sli4_hba.max_cfg_param.max_cq;
8373 if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
8374 qmin = phba->sli4_hba.max_cfg_param.max_eq;
8375 /*
8376 * Whats left after this can go toward NVME / FCP.
8377 * The minus 4 accounts for ELS, NVME LS, MBOX
8378 * plus one extra. When configured for
8379 * NVMET, FCP io channel WQs are not created.
8380 */
8381 qmin -= 4;
James Smartd38f33b2018-05-04 20:37:54 -07008382
James Smart6a828b02019-01-28 11:14:31 -08008383 /* If NVME is configured, double the number of CQ/WQs needed */
8384 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
8385 !phba->nvmet_support)
8386 qmin /= 2;
James Smartd38f33b2018-05-04 20:37:54 -07008387
James Smart6a828b02019-01-28 11:14:31 -08008388 /* Check to see if there is enough for NVME */
8389 if ((phba->cfg_irq_chann > qmin) ||
8390 (phba->cfg_hdw_queue > qmin)) {
8391 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8392 "2005 Reducing Queues: "
8393 "WQ %d CQ %d EQ %d: min %d: "
8394 "IRQ %d HDWQ %d\n",
James Smartd38f33b2018-05-04 20:37:54 -07008395 phba->sli4_hba.max_cfg_param.max_wq,
8396 phba->sli4_hba.max_cfg_param.max_cq,
James Smart6a828b02019-01-28 11:14:31 -08008397 phba->sli4_hba.max_cfg_param.max_eq,
8398 qmin, phba->cfg_irq_chann,
James Smartcdb42be2019-01-28 11:14:21 -08008399 phba->cfg_hdw_queue);
James Smartd38f33b2018-05-04 20:37:54 -07008400
James Smart6a828b02019-01-28 11:14:31 -08008401 if (phba->cfg_irq_chann > qmin)
8402 phba->cfg_irq_chann = qmin;
8403 if (phba->cfg_hdw_queue > qmin)
8404 phba->cfg_hdw_queue = qmin;
James Smartd38f33b2018-05-04 20:37:54 -07008405 }
James Smartda0436e2009-05-22 14:51:39 -04008406 }
James Smart912e3ac2011-05-24 11:42:11 -04008407
8408 if (rc)
8409 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04008410
James Smartc6918162016-10-13 15:06:16 -07008411 /* Update link speed if forced link speed is supported */
8412 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08008413 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07008414 forced_link_speed =
8415 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8416 if (forced_link_speed) {
8417 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8418
8419 switch (forced_link_speed) {
8420 case LINK_SPEED_1G:
8421 phba->cfg_link_speed =
8422 LPFC_USER_LINK_SPEED_1G;
8423 break;
8424 case LINK_SPEED_2G:
8425 phba->cfg_link_speed =
8426 LPFC_USER_LINK_SPEED_2G;
8427 break;
8428 case LINK_SPEED_4G:
8429 phba->cfg_link_speed =
8430 LPFC_USER_LINK_SPEED_4G;
8431 break;
8432 case LINK_SPEED_8G:
8433 phba->cfg_link_speed =
8434 LPFC_USER_LINK_SPEED_8G;
8435 break;
8436 case LINK_SPEED_10G:
8437 phba->cfg_link_speed =
8438 LPFC_USER_LINK_SPEED_10G;
8439 break;
8440 case LINK_SPEED_16G:
8441 phba->cfg_link_speed =
8442 LPFC_USER_LINK_SPEED_16G;
8443 break;
8444 case LINK_SPEED_32G:
8445 phba->cfg_link_speed =
8446 LPFC_USER_LINK_SPEED_32G;
8447 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08008448 case LINK_SPEED_64G:
8449 phba->cfg_link_speed =
8450 LPFC_USER_LINK_SPEED_64G;
8451 break;
James Smartc6918162016-10-13 15:06:16 -07008452 case 0xffff:
8453 phba->cfg_link_speed =
8454 LPFC_USER_LINK_SPEED_AUTO;
8455 break;
8456 default:
8457 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8458 "0047 Unrecognized link "
8459 "speed : %d\n",
8460 forced_link_speed);
8461 phba->cfg_link_speed =
8462 LPFC_USER_LINK_SPEED_AUTO;
8463 }
8464 }
8465 }
8466
James Smartda0436e2009-05-22 14:51:39 -04008467 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04008468 length = phba->sli4_hba.max_cfg_param.max_xri -
8469 lpfc_sli4_get_els_iocb_cnt(phba);
8470 if (phba->cfg_hba_queue_depth > length) {
8471 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8472 "3361 HBA queue depth changed from %d to %d\n",
8473 phba->cfg_hba_queue_depth, length);
8474 phba->cfg_hba_queue_depth = length;
8475 }
James Smart912e3ac2011-05-24 11:42:11 -04008476
James Smart27d6ac02018-02-22 08:18:42 -08008477 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04008478 LPFC_SLI_INTF_IF_TYPE_2)
8479 goto read_cfg_out;
8480
8481 /* get the pf# and vf# for SLI4 if_type 2 port */
8482 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8483 sizeof(struct lpfc_sli4_cfg_mhdr));
8484 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8485 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8486 length, LPFC_SLI4_MBX_EMBED);
8487
James Smart8aa134a2012-08-14 14:25:29 -04008488 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04008489 shdr = (union lpfc_sli4_cfg_shdr *)
8490 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8491 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8492 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04008493 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04008494 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8495 "3026 Mailbox failed , mbxCmd x%x "
8496 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8497 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8498 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04008499 goto read_cfg_out;
8500 }
8501
8502 /* search for fc_fcoe resrouce descriptor */
8503 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04008504
James Smart8aa134a2012-08-14 14:25:29 -04008505 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8506 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8507 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8508 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8509 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8510 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8511 goto read_cfg_out;
8512
James Smart912e3ac2011-05-24 11:42:11 -04008513 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04008514 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04008515 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04008516 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04008517 phba->sli4_hba.iov.pf_number =
8518 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8519 phba->sli4_hba.iov.vf_number =
8520 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8521 break;
8522 }
8523 }
8524
8525 if (i < LPFC_RSRC_DESC_MAX_NUM)
8526 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8527 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8528 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8529 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04008530 else
James Smart912e3ac2011-05-24 11:42:11 -04008531 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8532 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008533 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008534 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008535
8536read_cfg_out:
8537 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008538 return rc;
8539}
8540
8541/**
James Smart2fcee4b2010-12-15 17:57:46 -05008542 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008543 * @phba: pointer to lpfc hba data structure.
8544 *
James Smart2fcee4b2010-12-15 17:57:46 -05008545 * This routine is invoked to setup the port-side endian order when
8546 * the port if_type is 0. This routine has no function for other
8547 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008548 *
8549 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008550 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008551 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008552 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008553 **/
8554static int
8555lpfc_setup_endian_order(struct lpfc_hba *phba)
8556{
8557 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008558 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008559 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8560 HOST_ENDIAN_HIGH_WORD1};
8561
James Smart2fcee4b2010-12-15 17:57:46 -05008562 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8563 switch (if_type) {
8564 case LPFC_SLI_INTF_IF_TYPE_0:
8565 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8566 GFP_KERNEL);
8567 if (!mboxq) {
8568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8569 "0492 Unable to allocate memory for "
8570 "issuing SLI_CONFIG_SPECIAL mailbox "
8571 "command\n");
8572 return -ENOMEM;
8573 }
James Smartda0436e2009-05-22 14:51:39 -04008574
James Smart2fcee4b2010-12-15 17:57:46 -05008575 /*
8576 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8577 * two words to contain special data values and no other data.
8578 */
8579 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8580 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8581 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8582 if (rc != MBX_SUCCESS) {
8583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8584 "0493 SLI_CONFIG_SPECIAL mailbox "
8585 "failed with status x%x\n",
8586 rc);
8587 rc = -EIO;
8588 }
8589 mempool_free(mboxq, phba->mbox_mem_pool);
8590 break;
James Smart27d6ac02018-02-22 08:18:42 -08008591 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008592 case LPFC_SLI_INTF_IF_TYPE_2:
8593 case LPFC_SLI_INTF_IF_TYPE_1:
8594 default:
8595 break;
James Smartda0436e2009-05-22 14:51:39 -04008596 }
James Smartda0436e2009-05-22 14:51:39 -04008597 return rc;
8598}
8599
8600/**
James Smart895427b2017-02-12 13:52:30 -08008601 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008602 * @phba: pointer to lpfc hba data structure.
8603 *
James Smart895427b2017-02-12 13:52:30 -08008604 * This routine is invoked to check the user settable queue counts for EQs.
8605 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008606 * adhere to the constraints of the system's interrupt vectors and the port's
8607 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008608 *
8609 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008610 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008611 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008612 **/
8613static int
James Smart5350d872011-10-10 21:33:49 -04008614lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008615{
James Smartda0436e2009-05-22 14:51:39 -04008616 /*
James Smart67d12732012-08-03 12:36:13 -04008617 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008618 * device parameters
8619 */
8620
James Smartbcb24f62017-11-20 16:00:36 -08008621 if (phba->nvmet_support) {
James Smart6a828b02019-01-28 11:14:31 -08008622 if (phba->cfg_irq_chann < phba->cfg_nvmet_mrq)
8623 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
James Smart982ab122019-03-12 16:30:10 -07008624 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8625 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smartbcb24f62017-11-20 16:00:36 -08008626 }
James Smart895427b2017-02-12 13:52:30 -08008627
8628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -08008629 "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
8630 phba->cfg_hdw_queue, phba->cfg_irq_chann,
8631 phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008632
James Smartda0436e2009-05-22 14:51:39 -04008633 /* Get EQ depth from module parameter, fake the default for now */
8634 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8635 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8636
James Smart5350d872011-10-10 21:33:49 -04008637 /* Get CQ depth from module parameter, fake the default for now */
8638 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8639 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008640 return 0;
James Smart895427b2017-02-12 13:52:30 -08008641}
8642
8643static int
8644lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8645{
8646 struct lpfc_queue *qdesc;
James Smartc1a21eb2019-03-12 16:30:29 -07008647 int cpu;
James Smart895427b2017-02-12 13:52:30 -08008648
James Smartc1a21eb2019-03-12 16:30:29 -07008649 cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ);
James Smarta51e41b2017-12-08 17:18:06 -08008650 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008651 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008652 LPFC_CQE_EXP_COUNT, cpu);
James Smart895427b2017-02-12 13:52:30 -08008653 if (!qdesc) {
8654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8655 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8656 wqidx);
8657 return 1;
8658 }
James Smart7365f6f2018-02-22 08:18:46 -08008659 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008660 qdesc->hdwq = wqidx;
James Smartc1a21eb2019-03-12 16:30:29 -07008661 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008662 phba->sli4_hba.hdwq[wqidx].nvme_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008663
James Smarta51e41b2017-12-08 17:18:06 -08008664 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc1a21eb2019-03-12 16:30:29 -07008665 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT,
8666 cpu);
James Smart895427b2017-02-12 13:52:30 -08008667 if (!qdesc) {
8668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8669 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8670 wqidx);
8671 return 1;
8672 }
James Smart5e5b5112019-01-28 11:14:22 -08008673 qdesc->hdwq = wqidx;
James Smart6a828b02019-01-28 11:14:31 -08008674 qdesc->chann = wqidx;
James Smartcdb42be2019-01-28 11:14:21 -08008675 phba->sli4_hba.hdwq[wqidx].nvme_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008676 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8677 return 0;
8678}
8679
8680static int
8681lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8682{
8683 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008684 uint32_t wqesize;
James Smartc1a21eb2019-03-12 16:30:29 -07008685 int cpu;
James Smart895427b2017-02-12 13:52:30 -08008686
James Smartc1a21eb2019-03-12 16:30:29 -07008687 cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ);
James Smart895427b2017-02-12 13:52:30 -08008688 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008689 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008690 /* Increase the CQ size when WQEs contain an embedded cdb */
8691 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8692 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008693 LPFC_CQE_EXP_COUNT, cpu);
James Smarta51e41b2017-12-08 17:18:06 -08008694
8695 else
8696 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8697 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008698 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08008699 if (!qdesc) {
8700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8701 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8702 return 1;
8703 }
James Smart7365f6f2018-02-22 08:18:46 -08008704 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008705 qdesc->hdwq = wqidx;
James Smartc1a21eb2019-03-12 16:30:29 -07008706 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008707 phba->sli4_hba.hdwq[wqidx].fcp_cq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008708
8709 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008710 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008711 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008712 wqesize = (phba->fcp_embed_io) ?
8713 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008714 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008715 wqesize,
James Smartc1a21eb2019-03-12 16:30:29 -07008716 LPFC_WQE_EXP_COUNT, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008717 } else
James Smarta51e41b2017-12-08 17:18:06 -08008718 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8719 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008720 phba->sli4_hba.wq_ecount, cpu);
James Smartc176ffa2018-01-30 15:58:46 -08008721
James Smart895427b2017-02-12 13:52:30 -08008722 if (!qdesc) {
8723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8724 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8725 wqidx);
8726 return 1;
8727 }
James Smart5e5b5112019-01-28 11:14:22 -08008728 qdesc->hdwq = wqidx;
James Smart6a828b02019-01-28 11:14:31 -08008729 qdesc->chann = wqidx;
James Smartcdb42be2019-01-28 11:14:21 -08008730 phba->sli4_hba.hdwq[wqidx].fcp_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008731 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8732 return 0;
James Smart5350d872011-10-10 21:33:49 -04008733}
8734
8735/**
8736 * lpfc_sli4_queue_create - Create all the SLI4 queues
8737 * @phba: pointer to lpfc hba data structure.
8738 *
8739 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8740 * operation. For each SLI4 queue type, the parameters such as queue entry
8741 * count (queue depth) shall be taken from the module parameter. For now,
8742 * we just use some constant number as place holder.
8743 *
8744 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008745 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008746 * -ENOMEM - No availble memory
8747 * -EIO - The mailbox failed to complete successfully.
8748 **/
8749int
8750lpfc_sli4_queue_create(struct lpfc_hba *phba)
8751{
8752 struct lpfc_queue *qdesc;
James Smart657add42019-05-21 17:49:06 -07008753 int idx, cpu, eqcpu;
James Smart5e5b5112019-01-28 11:14:22 -08008754 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07008755 struct lpfc_vector_map_info *cpup;
8756 struct lpfc_vector_map_info *eqcpup;
James Smart32517fc2019-01-28 11:14:33 -08008757 struct lpfc_eq_intr_info *eqi;
James Smart5350d872011-10-10 21:33:49 -04008758
8759 /*
James Smart67d12732012-08-03 12:36:13 -04008760 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008761 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008762 */
James Smart67d12732012-08-03 12:36:13 -04008763 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8764 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8765 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8766 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8767 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8768 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008769 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8770 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8771 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8772 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008773
James Smartcdb42be2019-01-28 11:14:21 -08008774 if (!phba->sli4_hba.hdwq) {
James Smart5e5b5112019-01-28 11:14:22 -08008775 phba->sli4_hba.hdwq = kcalloc(
8776 phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
8777 GFP_KERNEL);
8778 if (!phba->sli4_hba.hdwq) {
James Smart895427b2017-02-12 13:52:30 -08008779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5e5b5112019-01-28 11:14:22 -08008780 "6427 Failed allocate memory for "
8781 "fast-path Hardware Queue array\n");
James Smart895427b2017-02-12 13:52:30 -08008782 goto out_error;
8783 }
James Smart5e5b5112019-01-28 11:14:22 -08008784 /* Prepare hardware queues to take IO buffers */
8785 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
8786 qp = &phba->sli4_hba.hdwq[idx];
8787 spin_lock_init(&qp->io_buf_list_get_lock);
8788 spin_lock_init(&qp->io_buf_list_put_lock);
8789 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
8790 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
8791 qp->get_io_bufs = 0;
8792 qp->put_io_bufs = 0;
8793 qp->total_io_bufs = 0;
8794 spin_lock_init(&qp->abts_scsi_buf_list_lock);
8795 INIT_LIST_HEAD(&qp->lpfc_abts_scsi_buf_list);
8796 qp->abts_scsi_io_bufs = 0;
8797 spin_lock_init(&qp->abts_nvme_buf_list_lock);
8798 INIT_LIST_HEAD(&qp->lpfc_abts_nvme_buf_list);
8799 qp->abts_nvme_io_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08008800 }
James Smart67d12732012-08-03 12:36:13 -04008801 }
8802
James Smartcdb42be2019-01-28 11:14:21 -08008803 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -08008804 if (phba->nvmet_support) {
8805 phba->sli4_hba.nvmet_cqset = kcalloc(
8806 phba->cfg_nvmet_mrq,
8807 sizeof(struct lpfc_queue *),
8808 GFP_KERNEL);
8809 if (!phba->sli4_hba.nvmet_cqset) {
8810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8811 "3121 Fail allocate memory for "
8812 "fast-path CQ set array\n");
8813 goto out_error;
8814 }
8815 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8816 phba->cfg_nvmet_mrq,
8817 sizeof(struct lpfc_queue *),
8818 GFP_KERNEL);
8819 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8821 "3122 Fail allocate memory for "
8822 "fast-path RQ set hdr array\n");
8823 goto out_error;
8824 }
8825 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8826 phba->cfg_nvmet_mrq,
8827 sizeof(struct lpfc_queue *),
8828 GFP_KERNEL);
8829 if (!phba->sli4_hba.nvmet_mrq_data) {
8830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8831 "3124 Fail allocate memory for "
8832 "fast-path RQ set data array\n");
8833 goto out_error;
8834 }
8835 }
James Smart67d12732012-08-03 12:36:13 -04008836 }
James Smartda0436e2009-05-22 14:51:39 -04008837
James Smart895427b2017-02-12 13:52:30 -08008838 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008839
James Smart895427b2017-02-12 13:52:30 -08008840 /* Create HBA Event Queues (EQs) */
James Smart657add42019-05-21 17:49:06 -07008841 for_each_present_cpu(cpu) {
8842 /* We only want to create 1 EQ per vector, even though
8843 * multiple CPUs might be using that vector. so only
8844 * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
James Smart6a828b02019-01-28 11:14:31 -08008845 */
James Smart657add42019-05-21 17:49:06 -07008846 cpup = &phba->sli4_hba.cpu_map[cpu];
8847 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
James Smart6a828b02019-01-28 11:14:31 -08008848 continue;
James Smart657add42019-05-21 17:49:06 -07008849
8850 /* Get a ptr to the Hardware Queue associated with this CPU */
8851 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8852
8853 /* Allocate an EQ */
James Smart81b96ed2017-11-20 16:00:29 -08008854 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8855 phba->sli4_hba.eq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008856 phba->sli4_hba.eq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008857 if (!qdesc) {
8858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart657add42019-05-21 17:49:06 -07008859 "0497 Failed allocate EQ (%d)\n",
8860 cpup->hdwq);
James Smart67d12732012-08-03 12:36:13 -04008861 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008862 }
James Smart7365f6f2018-02-22 08:18:46 -08008863 qdesc->qe_valid = 1;
James Smart657add42019-05-21 17:49:06 -07008864 qdesc->hdwq = cpup->hdwq;
8865 qdesc->chann = cpu; /* First CPU this EQ is affinitised to */
James Smart32517fc2019-01-28 11:14:33 -08008866 qdesc->last_cpu = qdesc->chann;
James Smart657add42019-05-21 17:49:06 -07008867
8868 /* Save the allocated EQ in the Hardware Queue */
8869 qp->hba_eq = qdesc;
8870
James Smart32517fc2019-01-28 11:14:33 -08008871 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
8872 list_add(&qdesc->cpu_list, &eqi->list);
James Smartda0436e2009-05-22 14:51:39 -04008873 }
8874
James Smart657add42019-05-21 17:49:06 -07008875 /* Now we need to populate the other Hardware Queues, that share
8876 * an IRQ vector, with the associated EQ ptr.
8877 */
8878 for_each_present_cpu(cpu) {
8879 cpup = &phba->sli4_hba.cpu_map[cpu];
8880
8881 /* Check for EQ already allocated in previous loop */
8882 if (cpup->flag & LPFC_CPU_FIRST_IRQ)
8883 continue;
8884
8885 /* Check for multiple CPUs per hdwq */
8886 qp = &phba->sli4_hba.hdwq[cpup->hdwq];
8887 if (qp->hba_eq)
8888 continue;
8889
8890 /* We need to share an EQ for this hdwq */
8891 eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
8892 eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
8893 qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
8894 }
James Smart895427b2017-02-12 13:52:30 -08008895
James Smartcdb42be2019-01-28 11:14:21 -08008896 /* Allocate SCSI SLI4 CQ/WQs */
James Smart6a828b02019-01-28 11:14:31 -08008897 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smart895427b2017-02-12 13:52:30 -08008898 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8899 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -08008900 }
James Smart895427b2017-02-12 13:52:30 -08008901
James Smartcdb42be2019-01-28 11:14:21 -08008902 /* Allocate NVME SLI4 CQ/WQs */
8903 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart6a828b02019-01-28 11:14:31 -08008904 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
James Smartcdb42be2019-01-28 11:14:21 -08008905 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8906 goto out_error;
James Smart6a828b02019-01-28 11:14:31 -08008907 }
James Smart67d12732012-08-03 12:36:13 -04008908
James Smartcdb42be2019-01-28 11:14:21 -08008909 if (phba->nvmet_support) {
8910 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -07008911 cpu = lpfc_find_cpu_handle(phba, idx,
8912 LPFC_FIND_BY_HDWQ);
James Smartcdb42be2019-01-28 11:14:21 -08008913 qdesc = lpfc_sli4_queue_alloc(
8914 phba,
James Smart81b96ed2017-11-20 16:00:29 -08008915 LPFC_DEFAULT_PAGE_SIZE,
8916 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008917 phba->sli4_hba.cq_ecount,
8918 cpu);
James Smartcdb42be2019-01-28 11:14:21 -08008919 if (!qdesc) {
8920 lpfc_printf_log(
8921 phba, KERN_ERR, LOG_INIT,
8922 "3142 Failed allocate NVME "
8923 "CQ Set (%d)\n", idx);
8924 goto out_error;
8925 }
8926 qdesc->qe_valid = 1;
James Smart5e5b5112019-01-28 11:14:22 -08008927 qdesc->hdwq = idx;
James Smartc1a21eb2019-03-12 16:30:29 -07008928 qdesc->chann = cpu;
James Smartcdb42be2019-01-28 11:14:21 -08008929 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
James Smart2d7dbc42017-02-12 13:52:35 -08008930 }
James Smart2d7dbc42017-02-12 13:52:35 -08008931 }
8932 }
8933
James Smartda0436e2009-05-22 14:51:39 -04008934 /*
James Smart67d12732012-08-03 12:36:13 -04008935 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008936 */
8937
James Smartc1a21eb2019-03-12 16:30:29 -07008938 cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
James Smartda0436e2009-05-22 14:51:39 -04008939 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008940 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8941 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008942 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008943 if (!qdesc) {
8944 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8945 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008946 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008947 }
James Smart7365f6f2018-02-22 08:18:46 -08008948 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008949 phba->sli4_hba.mbx_cq = qdesc;
8950
8951 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008952 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8953 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008954 phba->sli4_hba.cq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008955 if (!qdesc) {
8956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8957 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008958 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008959 }
James Smart7365f6f2018-02-22 08:18:46 -08008960 qdesc->qe_valid = 1;
James Smart6a828b02019-01-28 11:14:31 -08008961 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04008962 phba->sli4_hba.els_cq = qdesc;
8963
James Smartda0436e2009-05-22 14:51:39 -04008964
James Smart5350d872011-10-10 21:33:49 -04008965 /*
James Smart67d12732012-08-03 12:36:13 -04008966 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008967 */
James Smartda0436e2009-05-22 14:51:39 -04008968
8969 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008970
James Smart81b96ed2017-11-20 16:00:29 -08008971 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8972 phba->sli4_hba.mq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008973 phba->sli4_hba.mq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008974 if (!qdesc) {
8975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8976 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008977 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008978 }
James Smart6a828b02019-01-28 11:14:31 -08008979 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04008980 phba->sli4_hba.mbx_wq = qdesc;
8981
8982 /*
James Smart67d12732012-08-03 12:36:13 -04008983 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008984 */
James Smartda0436e2009-05-22 14:51:39 -04008985
8986 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008987 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8988 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07008989 phba->sli4_hba.wq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04008990 if (!qdesc) {
8991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8992 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008993 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008994 }
James Smart6a828b02019-01-28 11:14:31 -08008995 qdesc->chann = 0;
James Smartda0436e2009-05-22 14:51:39 -04008996 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008997 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8998
8999 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9000 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009001 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9002 phba->sli4_hba.cq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009003 phba->sli4_hba.cq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009004 if (!qdesc) {
9005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9006 "6079 Failed allocate NVME LS CQ\n");
9007 goto out_error;
9008 }
James Smart6a828b02019-01-28 11:14:31 -08009009 qdesc->chann = 0;
James Smart7365f6f2018-02-22 08:18:46 -08009010 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08009011 phba->sli4_hba.nvmels_cq = qdesc;
9012
9013 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08009014 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9015 phba->sli4_hba.wq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009016 phba->sli4_hba.wq_ecount, cpu);
James Smart895427b2017-02-12 13:52:30 -08009017 if (!qdesc) {
9018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9019 "6080 Failed allocate NVME LS WQ\n");
9020 goto out_error;
9021 }
James Smart6a828b02019-01-28 11:14:31 -08009022 qdesc->chann = 0;
James Smart895427b2017-02-12 13:52:30 -08009023 phba->sli4_hba.nvmels_wq = qdesc;
9024 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
9025 }
James Smartda0436e2009-05-22 14:51:39 -04009026
James Smartda0436e2009-05-22 14:51:39 -04009027 /*
9028 * Create Receive Queue (RQ)
9029 */
James Smartda0436e2009-05-22 14:51:39 -04009030
9031 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08009032 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9033 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009034 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009035 if (!qdesc) {
9036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9037 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009038 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009039 }
9040 phba->sli4_hba.hdr_rq = qdesc;
9041
9042 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08009043 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
9044 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009045 phba->sli4_hba.rq_ecount, cpu);
James Smartda0436e2009-05-22 14:51:39 -04009046 if (!qdesc) {
9047 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9048 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04009049 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04009050 }
9051 phba->sli4_hba.dat_rq = qdesc;
9052
James Smartcdb42be2019-01-28 11:14:21 -08009053 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
9054 phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08009055 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
James Smartc1a21eb2019-03-12 16:30:29 -07009056 cpu = lpfc_find_cpu_handle(phba, idx,
9057 LPFC_FIND_BY_HDWQ);
James Smart2d7dbc42017-02-12 13:52:35 -08009058 /* Create NVMET Receive Queue for header */
9059 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009060 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009061 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009062 LPFC_NVMET_RQE_DEF_COUNT,
9063 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009064 if (!qdesc) {
9065 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9066 "3146 Failed allocate "
9067 "receive HRQ\n");
9068 goto out_error;
9069 }
James Smart5e5b5112019-01-28 11:14:22 -08009070 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009071 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
9072
9073 /* Only needed for header of RQ pair */
James Smartc1a21eb2019-03-12 16:30:29 -07009074 qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
9075 GFP_KERNEL,
9076 cpu_to_node(cpu));
James Smart2d7dbc42017-02-12 13:52:35 -08009077 if (qdesc->rqbp == NULL) {
9078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9079 "6131 Failed allocate "
9080 "Header RQBP\n");
9081 goto out_error;
9082 }
9083
Dick Kennedy4b40d022017-08-23 16:55:38 -07009084 /* Put list in known state in case driver load fails. */
9085 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
9086
James Smart2d7dbc42017-02-12 13:52:35 -08009087 /* Create NVMET Receive Queue for data */
9088 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08009089 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08009090 phba->sli4_hba.rq_esize,
James Smartc1a21eb2019-03-12 16:30:29 -07009091 LPFC_NVMET_RQE_DEF_COUNT,
9092 cpu);
James Smart2d7dbc42017-02-12 13:52:35 -08009093 if (!qdesc) {
9094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9095 "3156 Failed allocate "
9096 "receive DRQ\n");
9097 goto out_error;
9098 }
James Smart5e5b5112019-01-28 11:14:22 -08009099 qdesc->hdwq = idx;
James Smart2d7dbc42017-02-12 13:52:35 -08009100 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
9101 }
9102 }
9103
James Smart4c47efc2019-01-28 11:14:25 -08009104#if defined(BUILD_NVME)
9105 /* Clear NVME stats */
9106 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9107 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9108 memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
9109 sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
9110 }
9111 }
9112#endif
9113
9114 /* Clear SCSI stats */
9115 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
9116 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9117 memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
9118 sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
9119 }
9120 }
9121
James Smartda0436e2009-05-22 14:51:39 -04009122 return 0;
9123
James Smartda0436e2009-05-22 14:51:39 -04009124out_error:
James Smart67d12732012-08-03 12:36:13 -04009125 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009126 return -ENOMEM;
9127}
9128
James Smart895427b2017-02-12 13:52:30 -08009129static inline void
9130__lpfc_sli4_release_queue(struct lpfc_queue **qp)
9131{
9132 if (*qp != NULL) {
9133 lpfc_sli4_queue_free(*qp);
9134 *qp = NULL;
9135 }
9136}
9137
9138static inline void
9139lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
9140{
9141 int idx;
9142
9143 if (*qs == NULL)
9144 return;
9145
9146 for (idx = 0; idx < max; idx++)
9147 __lpfc_sli4_release_queue(&(*qs)[idx]);
9148
9149 kfree(*qs);
9150 *qs = NULL;
9151}
9152
9153static inline void
James Smart6a828b02019-01-28 11:14:31 -08009154lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
James Smart895427b2017-02-12 13:52:30 -08009155{
James Smart6a828b02019-01-28 11:14:31 -08009156 struct lpfc_sli4_hdw_queue *hdwq;
James Smart657add42019-05-21 17:49:06 -07009157 struct lpfc_queue *eq;
James Smartcdb42be2019-01-28 11:14:21 -08009158 uint32_t idx;
9159
James Smart6a828b02019-01-28 11:14:31 -08009160 hdwq = phba->sli4_hba.hdwq;
James Smart6a828b02019-01-28 11:14:31 -08009161
James Smart657add42019-05-21 17:49:06 -07009162 /* Loop thru all Hardware Queues */
9163 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
9164 /* Free the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009165 lpfc_sli4_queue_free(hdwq[idx].fcp_cq);
9166 lpfc_sli4_queue_free(hdwq[idx].nvme_cq);
9167 lpfc_sli4_queue_free(hdwq[idx].fcp_wq);
9168 lpfc_sli4_queue_free(hdwq[idx].nvme_wq);
James Smart657add42019-05-21 17:49:06 -07009169 hdwq[idx].hba_eq = NULL;
James Smartcdb42be2019-01-28 11:14:21 -08009170 hdwq[idx].fcp_cq = NULL;
9171 hdwq[idx].nvme_cq = NULL;
9172 hdwq[idx].fcp_wq = NULL;
9173 hdwq[idx].nvme_wq = NULL;
James Smart895427b2017-02-12 13:52:30 -08009174 }
James Smart657add42019-05-21 17:49:06 -07009175 /* Loop thru all IRQ vectors */
9176 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
9177 /* Free the EQ corresponding to the IRQ vector */
9178 eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
9179 lpfc_sli4_queue_free(eq);
9180 phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
9181 }
James Smart895427b2017-02-12 13:52:30 -08009182}
9183
James Smartda0436e2009-05-22 14:51:39 -04009184/**
9185 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
9186 * @phba: pointer to lpfc hba data structure.
9187 *
9188 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
9189 * operation.
9190 *
9191 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009192 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009193 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009194 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009195 **/
James Smart5350d872011-10-10 21:33:49 -04009196void
James Smartda0436e2009-05-22 14:51:39 -04009197lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
9198{
James Smart4645f7b2019-03-12 16:30:14 -07009199 /*
9200 * Set FREE_INIT before beginning to free the queues.
9201 * Wait until the users of queues to acknowledge to
9202 * release queues by clearing FREE_WAIT.
9203 */
9204 spin_lock_irq(&phba->hbalock);
9205 phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
9206 while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
9207 spin_unlock_irq(&phba->hbalock);
9208 msleep(20);
9209 spin_lock_irq(&phba->hbalock);
9210 }
9211 spin_unlock_irq(&phba->hbalock);
9212
James Smart895427b2017-02-12 13:52:30 -08009213 /* Release HBA eqs */
James Smartcdb42be2019-01-28 11:14:21 -08009214 if (phba->sli4_hba.hdwq)
James Smart6a828b02019-01-28 11:14:31 -08009215 lpfc_sli4_release_hdwq(phba);
James Smartda0436e2009-05-22 14:51:39 -04009216
James Smartbcb24f62017-11-20 16:00:36 -08009217 if (phba->nvmet_support) {
9218 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
9219 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08009220
James Smartbcb24f62017-11-20 16:00:36 -08009221 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
9222 phba->cfg_nvmet_mrq);
9223 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
9224 phba->cfg_nvmet_mrq);
9225 }
James Smart2d7dbc42017-02-12 13:52:35 -08009226
James Smartda0436e2009-05-22 14:51:39 -04009227 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009228 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04009229
9230 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08009231 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
9232
9233 /* Release ELS work queue */
9234 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04009235
9236 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009237 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
9238 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04009239
James Smartda0436e2009-05-22 14:51:39 -04009240 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009241 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
9242
9243 /* Release NVME LS complete queue */
9244 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04009245
9246 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009247 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
9248
9249 /* Everything on this list has been freed */
9250 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart4645f7b2019-03-12 16:30:14 -07009251
9252 /* Done with freeing the queues */
9253 spin_lock_irq(&phba->hbalock);
9254 phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
9255 spin_unlock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08009256}
9257
9258int
James Smart895427b2017-02-12 13:52:30 -08009259lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
9260{
9261 struct lpfc_rqb *rqbp;
9262 struct lpfc_dmabuf *h_buf;
9263 struct rqb_dmabuf *rqb_buffer;
9264
9265 rqbp = rq->rqbp;
9266 while (!list_empty(&rqbp->rqb_buffer_list)) {
9267 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
9268 struct lpfc_dmabuf, list);
9269
9270 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
9271 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
9272 rqbp->buffer_count--;
9273 }
9274 return 1;
9275}
9276
9277static int
9278lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
9279 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
9280 int qidx, uint32_t qtype)
9281{
9282 struct lpfc_sli_ring *pring;
9283 int rc;
9284
9285 if (!eq || !cq || !wq) {
9286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9287 "6085 Fast-path %s (%d) not allocated\n",
9288 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
9289 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009290 }
James Smartda0436e2009-05-22 14:51:39 -04009291
James Smart895427b2017-02-12 13:52:30 -08009292 /* create the Cq first */
9293 rc = lpfc_cq_create(phba, cq, eq,
9294 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
9295 if (rc) {
9296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9297 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
9298 qidx, (uint32_t)rc);
9299 return rc;
9300 }
9301
9302 if (qtype != LPFC_MBOX) {
James Smartcdb42be2019-01-28 11:14:21 -08009303 /* Setup cq_map for fast lookup */
James Smart895427b2017-02-12 13:52:30 -08009304 if (cq_map)
9305 *cq_map = cq->queue_id;
9306
9307 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9308 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
9309 qidx, cq->queue_id, qidx, eq->queue_id);
9310
9311 /* create the wq */
9312 rc = lpfc_wq_create(phba, wq, cq, qtype);
9313 if (rc) {
9314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc835c082019-03-12 16:30:30 -07009315 "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
James Smart895427b2017-02-12 13:52:30 -08009316 qidx, (uint32_t)rc);
9317 /* no need to tear down cq - caller will do so */
9318 return rc;
9319 }
9320
9321 /* Bind this CQ/WQ to the NVME ring */
9322 pring = wq->pring;
9323 pring->sli.sli4.wqp = (void *)wq;
9324 cq->pring = pring;
9325
9326 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9327 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
9328 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
9329 } else {
9330 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
9331 if (rc) {
9332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9333 "0539 Failed setup of slow-path MQ: "
9334 "rc = 0x%x\n", rc);
9335 /* no need to tear down cq - caller will do so */
9336 return rc;
9337 }
9338
9339 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9340 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
9341 phba->sli4_hba.mbx_wq->queue_id,
9342 phba->sli4_hba.mbx_cq->queue_id);
9343 }
9344
9345 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009346}
9347
9348/**
James Smart6a828b02019-01-28 11:14:31 -08009349 * lpfc_setup_cq_lookup - Setup the CQ lookup table
9350 * @phba: pointer to lpfc hba data structure.
9351 *
9352 * This routine will populate the cq_lookup table by all
9353 * available CQ queue_id's.
9354 **/
Bart Van Assche3999df72019-03-28 11:06:16 -07009355static void
James Smart6a828b02019-01-28 11:14:31 -08009356lpfc_setup_cq_lookup(struct lpfc_hba *phba)
9357{
9358 struct lpfc_queue *eq, *childq;
James Smart6a828b02019-01-28 11:14:31 -08009359 int qidx;
9360
James Smart6a828b02019-01-28 11:14:31 -08009361 memset(phba->sli4_hba.cq_lookup, 0,
9362 (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
James Smart657add42019-05-21 17:49:06 -07009363 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009364 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009365 /* Get the EQ corresponding to the IRQ vector */
9366 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
James Smart6a828b02019-01-28 11:14:31 -08009367 if (!eq)
9368 continue;
James Smart657add42019-05-21 17:49:06 -07009369 /* Loop through all CQs associated with that EQ */
James Smart6a828b02019-01-28 11:14:31 -08009370 list_for_each_entry(childq, &eq->child_list, list) {
9371 if (childq->queue_id > phba->sli4_hba.cq_max)
9372 continue;
9373 if ((childq->subtype == LPFC_FCP) ||
9374 (childq->subtype == LPFC_NVME))
9375 phba->sli4_hba.cq_lookup[childq->queue_id] =
9376 childq;
9377 }
9378 }
9379}
9380
9381/**
James Smartda0436e2009-05-22 14:51:39 -04009382 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
9383 * @phba: pointer to lpfc hba data structure.
9384 *
9385 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
9386 * operation.
9387 *
9388 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009389 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009390 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009391 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009392 **/
9393int
9394lpfc_sli4_queue_setup(struct lpfc_hba *phba)
9395{
James Smart962bc512013-01-03 15:44:00 -05009396 uint32_t shdr_status, shdr_add_status;
9397 union lpfc_sli4_cfg_shdr *shdr;
James Smart657add42019-05-21 17:49:06 -07009398 struct lpfc_vector_map_info *cpup;
James Smartcdb42be2019-01-28 11:14:21 -08009399 struct lpfc_sli4_hdw_queue *qp;
James Smart962bc512013-01-03 15:44:00 -05009400 LPFC_MBOXQ_t *mboxq;
James Smart657add42019-05-21 17:49:06 -07009401 int qidx, cpu;
James Smartcb733e32019-01-28 11:14:32 -08009402 uint32_t length, usdelay;
James Smart895427b2017-02-12 13:52:30 -08009403 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05009404
9405 /* Check for dual-ULP support */
9406 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9407 if (!mboxq) {
9408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9409 "3249 Unable to allocate memory for "
9410 "QUERY_FW_CFG mailbox command\n");
9411 return -ENOMEM;
9412 }
9413 length = (sizeof(struct lpfc_mbx_query_fw_config) -
9414 sizeof(struct lpfc_sli4_cfg_mhdr));
9415 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9416 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
9417 length, LPFC_SLI4_MBX_EMBED);
9418
9419 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9420
9421 shdr = (union lpfc_sli4_cfg_shdr *)
9422 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9423 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9424 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9425 if (shdr_status || shdr_add_status || rc) {
9426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9427 "3250 QUERY_FW_CFG mailbox failed with status "
9428 "x%x add_status x%x, mbx status x%x\n",
9429 shdr_status, shdr_add_status, rc);
9430 if (rc != MBX_TIMEOUT)
9431 mempool_free(mboxq, phba->mbox_mem_pool);
9432 rc = -ENXIO;
9433 goto out_error;
9434 }
9435
9436 phba->sli4_hba.fw_func_mode =
9437 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9438 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9439 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04009440 phba->sli4_hba.physical_port =
9441 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05009442 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9443 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9444 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9445 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9446
9447 if (rc != MBX_TIMEOUT)
9448 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04009449
9450 /*
James Smart67d12732012-08-03 12:36:13 -04009451 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04009452 */
James Smartcdb42be2019-01-28 11:14:21 -08009453 qp = phba->sli4_hba.hdwq;
James Smartda0436e2009-05-22 14:51:39 -04009454
James Smart67d12732012-08-03 12:36:13 -04009455 /* Set up HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -08009456 if (!qp) {
James Smart2e90f4b2011-12-13 13:22:37 -05009457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9458 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009459 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009460 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05009461 }
James Smart657add42019-05-21 17:49:06 -07009462
9463 /* Loop thru all IRQ vectors */
James Smart6a828b02019-01-28 11:14:31 -08009464 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009465 /* Create HBA Event Queues (EQs) in order */
9466 for_each_present_cpu(cpu) {
9467 cpup = &phba->sli4_hba.cpu_map[cpu];
9468
9469 /* Look for the CPU thats using that vector with
9470 * LPFC_CPU_FIRST_IRQ set.
9471 */
9472 if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
9473 continue;
9474 if (qidx != cpup->eq)
9475 continue;
9476
9477 /* Create an EQ for that vector */
9478 rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
9479 phba->cfg_fcp_imax);
9480 if (rc) {
9481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9482 "0523 Failed setup of fast-path"
9483 " EQ (%d), rc = 0x%x\n",
9484 cpup->eq, (uint32_t)rc);
9485 goto out_destroy;
9486 }
9487
9488 /* Save the EQ for that vector in the hba_eq_hdl */
9489 phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
9490 qp[cpup->hdwq].hba_eq;
9491
9492 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9493 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9494 cpup->eq,
9495 qp[cpup->hdwq].hba_eq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04009496 }
James Smartda0436e2009-05-22 14:51:39 -04009497 }
9498
James Smart657add42019-05-21 17:49:06 -07009499 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009500 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9501 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009502 cpu = lpfc_find_cpu_handle(phba, qidx,
9503 LPFC_FIND_BY_HDWQ);
9504 cpup = &phba->sli4_hba.cpu_map[cpu];
9505
9506 /* Create the CQ/WQ corresponding to the
9507 * Hardware Queue
9508 */
James Smart895427b2017-02-12 13:52:30 -08009509 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -07009510 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartcdb42be2019-01-28 11:14:21 -08009511 qp[qidx].nvme_cq,
9512 qp[qidx].nvme_wq,
9513 &phba->sli4_hba.hdwq[qidx].nvme_cq_map,
James Smart895427b2017-02-12 13:52:30 -08009514 qidx, LPFC_NVME);
9515 if (rc) {
9516 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9517 "6123 Failed to setup fastpath "
9518 "NVME WQ/CQ (%d), rc = 0x%x\n",
9519 qidx, (uint32_t)rc);
9520 goto out_destroy;
9521 }
9522 }
James Smart67d12732012-08-03 12:36:13 -04009523 }
9524
James Smartcdb42be2019-01-28 11:14:21 -08009525 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009526 cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
9527 cpup = &phba->sli4_hba.cpu_map[cpu];
9528
9529 /* Create the CQ/WQ corresponding to the Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009530 rc = lpfc_create_wq_cq(phba,
James Smart657add42019-05-21 17:49:06 -07009531 phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
James Smartcdb42be2019-01-28 11:14:21 -08009532 qp[qidx].fcp_cq,
9533 qp[qidx].fcp_wq,
9534 &phba->sli4_hba.hdwq[qidx].fcp_cq_map,
9535 qidx, LPFC_FCP);
9536 if (rc) {
James Smart67d12732012-08-03 12:36:13 -04009537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009538 "0535 Failed to setup fastpath "
9539 "FCP WQ/CQ (%d), rc = 0x%x\n",
9540 qidx, (uint32_t)rc);
James Smartcdb42be2019-01-28 11:14:21 -08009541 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009542 }
James Smart67d12732012-08-03 12:36:13 -04009543 }
James Smartda0436e2009-05-22 14:51:39 -04009544
9545 /*
James Smart895427b2017-02-12 13:52:30 -08009546 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009547 */
9548
James Smart895427b2017-02-12 13:52:30 -08009549 /* Set up slow-path MBOX CQ/MQ */
9550
9551 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009553 "0528 %s not allocated\n",
9554 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07009555 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05009556 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009557 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009558 }
James Smart895427b2017-02-12 13:52:30 -08009559
James Smartcdb42be2019-01-28 11:14:21 -08009560 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
James Smartd1f525a2017-04-21 16:04:55 -07009561 phba->sli4_hba.mbx_cq,
9562 phba->sli4_hba.mbx_wq,
9563 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04009564 if (rc) {
9565 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009566 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9567 (uint32_t)rc);
9568 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009569 }
James Smart2d7dbc42017-02-12 13:52:35 -08009570 if (phba->nvmet_support) {
9571 if (!phba->sli4_hba.nvmet_cqset) {
9572 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9573 "3165 Fast-path NVME CQ Set "
9574 "array not allocated\n");
9575 rc = -ENOMEM;
9576 goto out_destroy;
9577 }
9578 if (phba->cfg_nvmet_mrq > 1) {
9579 rc = lpfc_cq_create_set(phba,
9580 phba->sli4_hba.nvmet_cqset,
James Smartcdb42be2019-01-28 11:14:21 -08009581 qp,
James Smart2d7dbc42017-02-12 13:52:35 -08009582 LPFC_WCQ, LPFC_NVMET);
9583 if (rc) {
9584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9585 "3164 Failed setup of NVME CQ "
9586 "Set, rc = 0x%x\n",
9587 (uint32_t)rc);
9588 goto out_destroy;
9589 }
9590 } else {
9591 /* Set up NVMET Receive Complete Queue */
9592 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
James Smartcdb42be2019-01-28 11:14:21 -08009593 qp[0].hba_eq,
James Smart2d7dbc42017-02-12 13:52:35 -08009594 LPFC_WCQ, LPFC_NVMET);
9595 if (rc) {
9596 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9597 "6089 Failed setup NVMET CQ: "
9598 "rc = 0x%x\n", (uint32_t)rc);
9599 goto out_destroy;
9600 }
James Smart81b96ed2017-11-20 16:00:29 -08009601 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9602
James Smart2d7dbc42017-02-12 13:52:35 -08009603 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9604 "6090 NVMET CQ setup: cq-id=%d, "
9605 "parent eq-id=%d\n",
9606 phba->sli4_hba.nvmet_cqset[0]->queue_id,
James Smartcdb42be2019-01-28 11:14:21 -08009607 qp[0].hba_eq->queue_id);
James Smart2d7dbc42017-02-12 13:52:35 -08009608 }
9609 }
James Smartda0436e2009-05-22 14:51:39 -04009610
James Smart895427b2017-02-12 13:52:30 -08009611 /* Set up slow-path ELS WQ/CQ */
9612 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009614 "0530 ELS %s not allocated\n",
9615 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009616 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009617 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009618 }
James Smartcdb42be2019-01-28 11:14:21 -08009619 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9620 phba->sli4_hba.els_cq,
9621 phba->sli4_hba.els_wq,
9622 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009623 if (rc) {
9624 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartcdb42be2019-01-28 11:14:21 -08009625 "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9626 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009627 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009628 }
9629 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9630 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9631 phba->sli4_hba.els_wq->queue_id,
9632 phba->sli4_hba.els_cq->queue_id);
9633
James Smartcdb42be2019-01-28 11:14:21 -08009634 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -08009635 /* Set up NVME LS Complete Queue */
9636 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9638 "6091 LS %s not allocated\n",
9639 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9640 rc = -ENOMEM;
9641 goto out_destroy;
9642 }
James Smartcdb42be2019-01-28 11:14:21 -08009643 rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
9644 phba->sli4_hba.nvmels_cq,
9645 phba->sli4_hba.nvmels_wq,
9646 NULL, 0, LPFC_NVME_LS);
James Smart895427b2017-02-12 13:52:30 -08009647 if (rc) {
9648 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartcdb42be2019-01-28 11:14:21 -08009649 "0526 Failed setup of NVVME LS WQ/CQ: "
9650 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009651 goto out_destroy;
9652 }
9653
9654 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9655 "6096 ELS WQ setup: wq-id=%d, "
9656 "parent cq-id=%d\n",
9657 phba->sli4_hba.nvmels_wq->queue_id,
9658 phba->sli4_hba.nvmels_cq->queue_id);
9659 }
9660
James Smart2d7dbc42017-02-12 13:52:35 -08009661 /*
9662 * Create NVMET Receive Queue (RQ)
9663 */
9664 if (phba->nvmet_support) {
9665 if ((!phba->sli4_hba.nvmet_cqset) ||
9666 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9667 (!phba->sli4_hba.nvmet_mrq_data)) {
9668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9669 "6130 MRQ CQ Queues not "
9670 "allocated\n");
9671 rc = -ENOMEM;
9672 goto out_destroy;
9673 }
9674 if (phba->cfg_nvmet_mrq > 1) {
9675 rc = lpfc_mrq_create(phba,
9676 phba->sli4_hba.nvmet_mrq_hdr,
9677 phba->sli4_hba.nvmet_mrq_data,
9678 phba->sli4_hba.nvmet_cqset,
9679 LPFC_NVMET);
9680 if (rc) {
9681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9682 "6098 Failed setup of NVMET "
9683 "MRQ: rc = 0x%x\n",
9684 (uint32_t)rc);
9685 goto out_destroy;
9686 }
9687
9688 } else {
9689 rc = lpfc_rq_create(phba,
9690 phba->sli4_hba.nvmet_mrq_hdr[0],
9691 phba->sli4_hba.nvmet_mrq_data[0],
9692 phba->sli4_hba.nvmet_cqset[0],
9693 LPFC_NVMET);
9694 if (rc) {
9695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9696 "6057 Failed setup of NVMET "
9697 "Receive Queue: rc = 0x%x\n",
9698 (uint32_t)rc);
9699 goto out_destroy;
9700 }
9701
9702 lpfc_printf_log(
9703 phba, KERN_INFO, LOG_INIT,
9704 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9705 "dat-rq-id=%d parent cq-id=%d\n",
9706 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9707 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9708 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9709
9710 }
9711 }
9712
James Smartda0436e2009-05-22 14:51:39 -04009713 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9715 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009716 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009717 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009718 }
James Smart73d91e52011-10-10 21:32:10 -04009719
James Smartda0436e2009-05-22 14:51:39 -04009720 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009721 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009722 if (rc) {
9723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9724 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009725 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009726 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009727 }
James Smart73d91e52011-10-10 21:32:10 -04009728
James Smartda0436e2009-05-22 14:51:39 -04009729 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9730 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9731 "parent cq-id=%d\n",
9732 phba->sli4_hba.hdr_rq->queue_id,
9733 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009734 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009735
James Smartcb733e32019-01-28 11:14:32 -08009736 if (phba->cfg_fcp_imax)
9737 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
9738 else
9739 usdelay = 0;
9740
James Smart6a828b02019-01-28 11:14:31 -08009741 for (qidx = 0; qidx < phba->cfg_irq_chann;
James Smartcdb42be2019-01-28 11:14:21 -08009742 qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009743 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -08009744 usdelay);
James Smart43140ca2017-03-04 09:30:34 -08009745
James Smart6a828b02019-01-28 11:14:31 -08009746 if (phba->sli4_hba.cq_max) {
9747 kfree(phba->sli4_hba.cq_lookup);
9748 phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
9749 sizeof(struct lpfc_queue *), GFP_KERNEL);
9750 if (!phba->sli4_hba.cq_lookup) {
James Smart1ba981f2014-02-20 09:56:45 -05009751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -08009752 "0549 Failed setup of CQ Lookup table: "
9753 "size 0x%x\n", phba->sli4_hba.cq_max);
Dan Carpenterfad28e32019-02-11 21:43:00 +03009754 rc = -ENOMEM;
James Smart1ba981f2014-02-20 09:56:45 -05009755 goto out_destroy;
James Smart895427b2017-02-12 13:52:30 -08009756 }
James Smart6a828b02019-01-28 11:14:31 -08009757 lpfc_setup_cq_lookup(phba);
James Smart1ba981f2014-02-20 09:56:45 -05009758 }
James Smartda0436e2009-05-22 14:51:39 -04009759 return 0;
9760
James Smart895427b2017-02-12 13:52:30 -08009761out_destroy:
9762 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009763out_error:
9764 return rc;
9765}
9766
9767/**
9768 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9769 * @phba: pointer to lpfc hba data structure.
9770 *
9771 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9772 * operation.
9773 *
9774 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009775 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009776 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009777 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009778 **/
9779void
9780lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9781{
James Smartcdb42be2019-01-28 11:14:21 -08009782 struct lpfc_sli4_hdw_queue *qp;
James Smart657add42019-05-21 17:49:06 -07009783 struct lpfc_queue *eq;
James Smart895427b2017-02-12 13:52:30 -08009784 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009785
9786 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009787 if (phba->sli4_hba.mbx_wq)
9788 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9789
9790 /* Unset NVME LS work queue */
9791 if (phba->sli4_hba.nvmels_wq)
9792 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9793
James Smartda0436e2009-05-22 14:51:39 -04009794 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009795 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009796 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9797
James Smartda0436e2009-05-22 14:51:39 -04009798 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009799 if (phba->sli4_hba.hdr_rq)
9800 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9801 phba->sli4_hba.dat_rq);
9802
James Smartda0436e2009-05-22 14:51:39 -04009803 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009804 if (phba->sli4_hba.mbx_cq)
9805 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9806
James Smartda0436e2009-05-22 14:51:39 -04009807 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009808 if (phba->sli4_hba.els_cq)
9809 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9810
9811 /* Unset NVME LS complete queue */
9812 if (phba->sli4_hba.nvmels_cq)
9813 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9814
James Smartbcb24f62017-11-20 16:00:36 -08009815 if (phba->nvmet_support) {
9816 /* Unset NVMET MRQ queue */
9817 if (phba->sli4_hba.nvmet_mrq_hdr) {
9818 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9819 lpfc_rq_destroy(
9820 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009821 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9822 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009823 }
James Smart2d7dbc42017-02-12 13:52:35 -08009824
James Smartbcb24f62017-11-20 16:00:36 -08009825 /* Unset NVMET CQ Set complete queue */
9826 if (phba->sli4_hba.nvmet_cqset) {
9827 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9828 lpfc_cq_destroy(
9829 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9830 }
James Smart2d7dbc42017-02-12 13:52:35 -08009831 }
9832
James Smartcdb42be2019-01-28 11:14:21 -08009833 /* Unset fast-path SLI4 queues */
9834 if (phba->sli4_hba.hdwq) {
James Smart657add42019-05-21 17:49:06 -07009835 /* Loop thru all Hardware Queues */
James Smartcdb42be2019-01-28 11:14:21 -08009836 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smart657add42019-05-21 17:49:06 -07009837 /* Destroy the CQ/WQ corresponding to Hardware Queue */
James Smartcdb42be2019-01-28 11:14:21 -08009838 qp = &phba->sli4_hba.hdwq[qidx];
9839 lpfc_wq_destroy(phba, qp->fcp_wq);
9840 lpfc_wq_destroy(phba, qp->nvme_wq);
9841 lpfc_cq_destroy(phba, qp->fcp_cq);
9842 lpfc_cq_destroy(phba, qp->nvme_cq);
James Smart657add42019-05-21 17:49:06 -07009843 }
9844 /* Loop thru all IRQ vectors */
9845 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
9846 /* Destroy the EQ corresponding to the IRQ vector */
9847 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
9848 lpfc_eq_destroy(phba, eq);
James Smartcdb42be2019-01-28 11:14:21 -08009849 }
9850 }
James Smart895427b2017-02-12 13:52:30 -08009851
James Smart6a828b02019-01-28 11:14:31 -08009852 kfree(phba->sli4_hba.cq_lookup);
9853 phba->sli4_hba.cq_lookup = NULL;
9854 phba->sli4_hba.cq_max = 0;
James Smartda0436e2009-05-22 14:51:39 -04009855}
9856
9857/**
9858 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9859 * @phba: pointer to lpfc hba data structure.
9860 *
9861 * This routine is invoked to allocate and set up a pool of completion queue
9862 * events. The body of the completion queue event is a completion queue entry
9863 * CQE. For now, this pool is used for the interrupt service routine to queue
9864 * the following HBA completion queue events for the worker thread to process:
9865 * - Mailbox asynchronous events
9866 * - Receive queue completion unsolicited events
9867 * Later, this can be used for all the slow-path events.
9868 *
9869 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009870 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009871 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009872 **/
9873static int
9874lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9875{
9876 struct lpfc_cq_event *cq_event;
9877 int i;
9878
9879 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9880 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9881 if (!cq_event)
9882 goto out_pool_create_fail;
9883 list_add_tail(&cq_event->list,
9884 &phba->sli4_hba.sp_cqe_event_pool);
9885 }
9886 return 0;
9887
9888out_pool_create_fail:
9889 lpfc_sli4_cq_event_pool_destroy(phba);
9890 return -ENOMEM;
9891}
9892
9893/**
9894 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9895 * @phba: pointer to lpfc hba data structure.
9896 *
9897 * This routine is invoked to free the pool of completion queue events at
9898 * driver unload time. Note that, it is the responsibility of the driver
9899 * cleanup routine to free all the outstanding completion-queue events
9900 * allocated from this pool back into the pool before invoking this routine
9901 * to destroy the pool.
9902 **/
9903static void
9904lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9905{
9906 struct lpfc_cq_event *cq_event, *next_cq_event;
9907
9908 list_for_each_entry_safe(cq_event, next_cq_event,
9909 &phba->sli4_hba.sp_cqe_event_pool, list) {
9910 list_del(&cq_event->list);
9911 kfree(cq_event);
9912 }
9913}
9914
9915/**
9916 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9917 * @phba: pointer to lpfc hba data structure.
9918 *
9919 * This routine is the lock free version of the API invoked to allocate a
9920 * completion-queue event from the free pool.
9921 *
9922 * Return: Pointer to the newly allocated completion-queue event if successful
9923 * NULL otherwise.
9924 **/
9925struct lpfc_cq_event *
9926__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9927{
9928 struct lpfc_cq_event *cq_event = NULL;
9929
9930 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9931 struct lpfc_cq_event, list);
9932 return cq_event;
9933}
9934
9935/**
9936 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9937 * @phba: pointer to lpfc hba data structure.
9938 *
9939 * This routine is the lock version of the API invoked to allocate a
9940 * completion-queue event from the free pool.
9941 *
9942 * Return: Pointer to the newly allocated completion-queue event if successful
9943 * NULL otherwise.
9944 **/
9945struct lpfc_cq_event *
9946lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9947{
9948 struct lpfc_cq_event *cq_event;
9949 unsigned long iflags;
9950
9951 spin_lock_irqsave(&phba->hbalock, iflags);
9952 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9953 spin_unlock_irqrestore(&phba->hbalock, iflags);
9954 return cq_event;
9955}
9956
9957/**
9958 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9959 * @phba: pointer to lpfc hba data structure.
9960 * @cq_event: pointer to the completion queue event to be freed.
9961 *
9962 * This routine is the lock free version of the API invoked to release a
9963 * completion-queue event back into the free pool.
9964 **/
9965void
9966__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9967 struct lpfc_cq_event *cq_event)
9968{
9969 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9970}
9971
9972/**
9973 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9974 * @phba: pointer to lpfc hba data structure.
9975 * @cq_event: pointer to the completion queue event to be freed.
9976 *
9977 * This routine is the lock version of the API invoked to release a
9978 * completion-queue event back into the free pool.
9979 **/
9980void
9981lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9982 struct lpfc_cq_event *cq_event)
9983{
9984 unsigned long iflags;
9985 spin_lock_irqsave(&phba->hbalock, iflags);
9986 __lpfc_sli4_cq_event_release(phba, cq_event);
9987 spin_unlock_irqrestore(&phba->hbalock, iflags);
9988}
9989
9990/**
9991 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9992 * @phba: pointer to lpfc hba data structure.
9993 *
9994 * This routine is to free all the pending completion-queue events to the
9995 * back into the free pool for device reset.
9996 **/
9997static void
9998lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9999{
10000 LIST_HEAD(cqelist);
10001 struct lpfc_cq_event *cqe;
10002 unsigned long iflags;
10003
10004 /* Retrieve all the pending WCQEs from pending WCQE lists */
10005 spin_lock_irqsave(&phba->hbalock, iflags);
10006 /* Pending FCP XRI abort events */
10007 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
10008 &cqelist);
10009 /* Pending ELS XRI abort events */
10010 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
10011 &cqelist);
10012 /* Pending asynnc events */
10013 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
10014 &cqelist);
10015 spin_unlock_irqrestore(&phba->hbalock, iflags);
10016
10017 while (!list_empty(&cqelist)) {
10018 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
10019 lpfc_sli4_cq_event_release(phba, cqe);
10020 }
10021}
10022
10023/**
10024 * lpfc_pci_function_reset - Reset pci function.
10025 * @phba: pointer to lpfc hba data structure.
10026 *
10027 * This routine is invoked to request a PCI function reset. It will destroys
10028 * all resources assigned to the PCI function which originates this request.
10029 *
10030 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010031 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010032 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -040010033 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -040010034 **/
10035int
10036lpfc_pci_function_reset(struct lpfc_hba *phba)
10037{
10038 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -050010039 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -040010040 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -040010041 uint32_t rdy_chk;
10042 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -040010043 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -050010044 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -050010045 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -040010046
James Smart2fcee4b2010-12-15 17:57:46 -050010047 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10048 switch (if_type) {
10049 case LPFC_SLI_INTF_IF_TYPE_0:
10050 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
10051 GFP_KERNEL);
10052 if (!mboxq) {
10053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10054 "0494 Unable to allocate memory for "
10055 "issuing SLI_FUNCTION_RESET mailbox "
10056 "command\n");
10057 return -ENOMEM;
10058 }
10059
10060 /* Setup PCI function reset mailbox-ioctl command */
10061 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10062 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
10063 LPFC_SLI4_MBX_EMBED);
10064 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10065 shdr = (union lpfc_sli4_cfg_shdr *)
10066 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
10067 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
10068 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
10069 &shdr->response);
10070 if (rc != MBX_TIMEOUT)
10071 mempool_free(mboxq, phba->mbox_mem_pool);
10072 if (shdr_status || shdr_add_status || rc) {
10073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10074 "0495 SLI_FUNCTION_RESET mailbox "
10075 "failed with status x%x add_status x%x,"
10076 " mbx status x%x\n",
10077 shdr_status, shdr_add_status, rc);
10078 rc = -ENXIO;
10079 }
10080 break;
10081 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -080010082 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -040010083wait:
10084 /*
10085 * Poll the Port Status Register and wait for RDY for
10086 * up to 30 seconds. If the port doesn't respond, treat
10087 * it as an error.
10088 */
James Smart77d093f2015-04-07 15:07:08 -040010089 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -040010090 if (lpfc_readl(phba->sli4_hba.u.if_type2.
10091 STATUSregaddr, &reg_data.word0)) {
10092 rc = -ENODEV;
10093 goto out;
10094 }
10095 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
10096 break;
10097 msleep(20);
10098 }
10099
10100 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
10101 phba->work_status[0] = readl(
10102 phba->sli4_hba.u.if_type2.ERR1regaddr);
10103 phba->work_status[1] = readl(
10104 phba->sli4_hba.u.if_type2.ERR2regaddr);
10105 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10106 "2890 Port not ready, port status reg "
10107 "0x%x error 1=0x%x, error 2=0x%x\n",
10108 reg_data.word0,
10109 phba->work_status[0],
10110 phba->work_status[1]);
10111 rc = -ENODEV;
10112 goto out;
10113 }
10114
10115 if (!port_reset) {
10116 /*
10117 * Reset the port now
10118 */
James Smart2fcee4b2010-12-15 17:57:46 -050010119 reg_data.word0 = 0;
10120 bf_set(lpfc_sliport_ctrl_end, &reg_data,
10121 LPFC_SLIPORT_LITTLE_ENDIAN);
10122 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
10123 LPFC_SLIPORT_INIT_PORT);
10124 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
10125 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -050010126 /* flush */
James Smart2b81f942012-03-01 22:37:18 -050010127 pci_read_config_word(phba->pcidev,
10128 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -050010129
James Smart2f6fa2c2014-09-03 12:57:08 -040010130 port_reset = 1;
10131 msleep(20);
10132 goto wait;
10133 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
10134 rc = -ENODEV;
10135 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -050010136 }
10137 break;
James Smart2f6fa2c2014-09-03 12:57:08 -040010138
James Smart2fcee4b2010-12-15 17:57:46 -050010139 case LPFC_SLI_INTF_IF_TYPE_1:
10140 default:
10141 break;
James Smartda0436e2009-05-22 14:51:39 -040010142 }
10143
James Smart73d91e52011-10-10 21:32:10 -040010144out:
James Smart2fcee4b2010-12-15 17:57:46 -050010145 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -040010146 if (rc) {
James Smart229adb02013-04-17 20:16:51 -040010147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10148 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -040010149 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -050010150 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -040010151 }
James Smart2fcee4b2010-12-15 17:57:46 -050010152
James Smartda0436e2009-05-22 14:51:39 -040010153 return rc;
10154}
10155
10156/**
James Smartda0436e2009-05-22 14:51:39 -040010157 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
10158 * @phba: pointer to lpfc hba data structure.
10159 *
10160 * This routine is invoked to set up the PCI device memory space for device
10161 * with SLI-4 interface spec.
10162 *
10163 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010164 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010165 * other values - error
10166 **/
10167static int
10168lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10169{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010170 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010171 unsigned long bar0map_len, bar1map_len, bar2map_len;
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010172 int error;
James Smart2fcee4b2010-12-15 17:57:46 -050010173 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -040010174
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010175 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +010010176 return -ENODEV;
James Smartda0436e2009-05-22 14:51:39 -040010177
10178 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +010010179 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
10180 if (error)
10181 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10182 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +020010183 return error;
James Smartda0436e2009-05-22 14:51:39 -040010184
James Smart2fcee4b2010-12-15 17:57:46 -050010185 /*
10186 * The BARs and register set definitions and offset locations are
10187 * dependent on the if_type.
10188 */
10189 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
10190 &phba->sli4_hba.sli_intf.word0)) {
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010191 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010192 }
10193
10194 /* There is no SLI3 failback for SLI4 devices. */
10195 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
10196 LPFC_SLI_INTF_VALID) {
10197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10198 "2894 SLI_INTF reg contents invalid "
10199 "sli_intf reg 0x%x\n",
10200 phba->sli4_hba.sli_intf.word0);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010201 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010202 }
10203
10204 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
10205 /*
10206 * Get the bus address of SLI4 device Bar regions and the
10207 * number of bytes required by each mapping. The mapping of the
10208 * particular PCI BARs regions is dependent on the type of
10209 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -040010210 */
James Smartf5ca6f22013-09-06 12:21:09 -040010211 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
10212 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
10213 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -050010214
10215 /*
10216 * Map SLI4 PCI Config Space Register base to a kernel virtual
10217 * addr
10218 */
10219 phba->sli4_hba.conf_regs_memmap_p =
10220 ioremap(phba->pci_bar0_map, bar0map_len);
10221 if (!phba->sli4_hba.conf_regs_memmap_p) {
10222 dev_printk(KERN_ERR, &pdev->dev,
10223 "ioremap failed for SLI4 PCI config "
10224 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010225 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010226 }
James Smartf5ca6f22013-09-06 12:21:09 -040010227 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -050010228 /* Set up BAR0 PCI config space register memory map */
10229 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -050010230 } else {
10231 phba->pci_bar0_map = pci_resource_start(pdev, 1);
10232 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -080010233 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -050010234 dev_printk(KERN_ERR, &pdev->dev,
10235 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010236 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010237 }
10238 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -040010239 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -050010240 if (!phba->sli4_hba.conf_regs_memmap_p) {
10241 dev_printk(KERN_ERR, &pdev->dev,
10242 "ioremap failed for SLI4 PCI config "
10243 "registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010244 return -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -050010245 }
10246 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -040010247 }
10248
James Smarte4b97942017-11-20 16:00:31 -080010249 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10250 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
10251 /*
10252 * Map SLI4 if type 0 HBA Control Register base to a
10253 * kernel virtual address and setup the registers.
10254 */
10255 phba->pci_bar1_map = pci_resource_start(pdev,
10256 PCI_64BIT_BAR2);
10257 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10258 phba->sli4_hba.ctrl_regs_memmap_p =
10259 ioremap(phba->pci_bar1_map,
10260 bar1map_len);
10261 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
10262 dev_err(&pdev->dev,
10263 "ioremap failed for SLI4 HBA "
10264 "control registers.\n");
10265 error = -ENOMEM;
10266 goto out_iounmap_conf;
10267 }
10268 phba->pci_bar2_memmap_p =
10269 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -080010270 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -080010271 } else {
10272 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010273 goto out_iounmap_conf;
10274 }
James Smartda0436e2009-05-22 14:51:39 -040010275 }
10276
James Smart27d6ac02018-02-22 08:18:42 -080010277 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
10278 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
10279 /*
10280 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
10281 * virtual address and setup the registers.
10282 */
10283 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
10284 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
10285 phba->sli4_hba.drbl_regs_memmap_p =
10286 ioremap(phba->pci_bar1_map, bar1map_len);
10287 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10288 dev_err(&pdev->dev,
10289 "ioremap failed for SLI4 HBA doorbell registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010290 error = -ENOMEM;
James Smart27d6ac02018-02-22 08:18:42 -080010291 goto out_iounmap_conf;
10292 }
10293 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
10294 lpfc_sli4_bar1_register_memmap(phba, if_type);
10295 }
10296
James Smarte4b97942017-11-20 16:00:31 -080010297 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
10298 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10299 /*
10300 * Map SLI4 if type 0 HBA Doorbell Register base to
10301 * a kernel virtual address and setup the registers.
10302 */
10303 phba->pci_bar2_map = pci_resource_start(pdev,
10304 PCI_64BIT_BAR4);
10305 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10306 phba->sli4_hba.drbl_regs_memmap_p =
10307 ioremap(phba->pci_bar2_map,
10308 bar2map_len);
10309 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10310 dev_err(&pdev->dev,
10311 "ioremap failed for SLI4 HBA"
10312 " doorbell registers.\n");
10313 error = -ENOMEM;
10314 goto out_iounmap_ctrl;
10315 }
10316 phba->pci_bar4_memmap_p =
10317 phba->sli4_hba.drbl_regs_memmap_p;
10318 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
10319 if (error)
10320 goto out_iounmap_all;
10321 } else {
10322 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -050010323 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -080010324 }
James Smartda0436e2009-05-22 14:51:39 -040010325 }
10326
James Smart1351e692018-02-22 08:18:43 -080010327 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
10328 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
10329 /*
10330 * Map SLI4 if type 6 HBA DPP Register base to a kernel
10331 * virtual address and setup the registers.
10332 */
10333 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
10334 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
10335 phba->sli4_hba.dpp_regs_memmap_p =
10336 ioremap(phba->pci_bar2_map, bar2map_len);
10337 if (!phba->sli4_hba.dpp_regs_memmap_p) {
10338 dev_err(&pdev->dev,
10339 "ioremap failed for SLI4 HBA dpp registers.\n");
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010340 error = -ENOMEM;
James Smart1351e692018-02-22 08:18:43 -080010341 goto out_iounmap_ctrl;
10342 }
10343 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
10344 }
10345
James Smartb71413d2018-02-22 08:18:40 -080010346 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -080010347 switch (if_type) {
10348 case LPFC_SLI_INTF_IF_TYPE_0:
10349 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -080010350 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010351 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
10352 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010353 break;
10354 case LPFC_SLI_INTF_IF_TYPE_6:
10355 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
James Smart32517fc2019-01-28 11:14:33 -080010356 phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
10357 phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
James Smart27d6ac02018-02-22 08:18:42 -080010358 break;
10359 default:
10360 break;
James Smartb71413d2018-02-22 08:18:40 -080010361 }
10362
James Smartda0436e2009-05-22 14:51:39 -040010363 return 0;
10364
10365out_iounmap_all:
10366 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10367out_iounmap_ctrl:
10368 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10369out_iounmap_conf:
10370 iounmap(phba->sli4_hba.conf_regs_memmap_p);
Dan Carpenter3a487ff2019-03-07 08:33:44 +030010371
James Smartda0436e2009-05-22 14:51:39 -040010372 return error;
10373}
10374
10375/**
10376 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
10377 * @phba: pointer to lpfc hba data structure.
10378 *
10379 * This routine is invoked to unset the PCI device memory space for device
10380 * with SLI-4 interface spec.
10381 **/
10382static void
10383lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
10384{
James Smart2e90f4b2011-12-13 13:22:37 -050010385 uint32_t if_type;
10386 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -040010387
James Smart2e90f4b2011-12-13 13:22:37 -050010388 switch (if_type) {
10389 case LPFC_SLI_INTF_IF_TYPE_0:
10390 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10391 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10392 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10393 break;
10394 case LPFC_SLI_INTF_IF_TYPE_2:
10395 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10396 break;
James Smart27d6ac02018-02-22 08:18:42 -080010397 case LPFC_SLI_INTF_IF_TYPE_6:
10398 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
10399 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10400 break;
James Smart2e90f4b2011-12-13 13:22:37 -050010401 case LPFC_SLI_INTF_IF_TYPE_1:
10402 default:
10403 dev_printk(KERN_ERR, &phba->pcidev->dev,
10404 "FATAL - unsupported SLI4 interface type - %d\n",
10405 if_type);
10406 break;
10407 }
James Smartda0436e2009-05-22 14:51:39 -040010408}
10409
10410/**
James Smart3772a992009-05-22 14:50:54 -040010411 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
10412 * @phba: pointer to lpfc hba data structure.
10413 *
10414 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010415 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -040010416 *
10417 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010418 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010419 * other values - error
10420 **/
10421static int
10422lpfc_sli_enable_msix(struct lpfc_hba *phba)
10423{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010424 int rc;
James Smart3772a992009-05-22 14:50:54 -040010425 LPFC_MBOXQ_t *pmb;
10426
10427 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010428 rc = pci_alloc_irq_vectors(phba->pcidev,
10429 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
10430 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -040010431 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10432 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010433 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -040010434 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010435
James Smart3772a992009-05-22 14:50:54 -040010436 /*
10437 * Assign MSI-X vectors to interrupt handlers
10438 */
10439
10440 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010441 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040010442 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010443 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10444 if (rc) {
10445 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10446 "0421 MSI-X slow-path request_irq failed "
10447 "(%d)\n", rc);
10448 goto msi_fail_out;
10449 }
10450
10451 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010452 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040010453 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010454 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10455
10456 if (rc) {
10457 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10458 "0429 MSI-X fast-path request_irq failed "
10459 "(%d)\n", rc);
10460 goto irq_fail_out;
10461 }
10462
10463 /*
10464 * Configure HBA MSI-X attention conditions to messages
10465 */
10466 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10467
10468 if (!pmb) {
10469 rc = -ENOMEM;
10470 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10471 "0474 Unable to allocate memory for issuing "
10472 "MBOX_CONFIG_MSI command\n");
10473 goto mem_fail_out;
10474 }
10475 rc = lpfc_config_msi(phba, pmb);
10476 if (rc)
10477 goto mbx_fail_out;
10478 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10479 if (rc != MBX_SUCCESS) {
10480 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10481 "0351 Config MSI mailbox command failed, "
10482 "mbxCmd x%x, mbxStatus x%x\n",
10483 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10484 goto mbx_fail_out;
10485 }
10486
10487 /* Free memory allocated for mailbox command */
10488 mempool_free(pmb, phba->mbox_mem_pool);
10489 return rc;
10490
10491mbx_fail_out:
10492 /* Free memory allocated for mailbox command */
10493 mempool_free(pmb, phba->mbox_mem_pool);
10494
10495mem_fail_out:
10496 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010497 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040010498
10499irq_fail_out:
10500 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010501 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040010502
10503msi_fail_out:
10504 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010505 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010506
10507vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040010508 return rc;
10509}
10510
10511/**
James Smart3772a992009-05-22 14:50:54 -040010512 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10513 * @phba: pointer to lpfc hba data structure.
10514 *
10515 * This routine is invoked to enable the MSI interrupt mode to device with
10516 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10517 * enable the MSI vector. The device driver is responsible for calling the
10518 * request_irq() to register MSI vector with a interrupt the handler, which
10519 * is done in this function.
10520 *
10521 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010522 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010523 * other values - error
10524 */
10525static int
10526lpfc_sli_enable_msi(struct lpfc_hba *phba)
10527{
10528 int rc;
10529
10530 rc = pci_enable_msi(phba->pcidev);
10531 if (!rc)
10532 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10533 "0462 PCI enable MSI mode success.\n");
10534 else {
10535 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10536 "0471 PCI enable MSI mode failed (%d)\n", rc);
10537 return rc;
10538 }
10539
10540 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010541 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040010542 if (rc) {
10543 pci_disable_msi(phba->pcidev);
10544 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10545 "0478 MSI request_irq failed (%d)\n", rc);
10546 }
10547 return rc;
10548}
10549
10550/**
James Smart3772a992009-05-22 14:50:54 -040010551 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10552 * @phba: pointer to lpfc hba data structure.
10553 *
10554 * This routine is invoked to enable device interrupt and associate driver's
10555 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10556 * spec. Depends on the interrupt mode configured to the driver, the driver
10557 * will try to fallback from the configured interrupt mode to an interrupt
10558 * mode which is supported by the platform, kernel, and device in the order
10559 * of:
10560 * MSI-X -> MSI -> IRQ.
10561 *
10562 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010563 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010564 * other values - error
10565 **/
10566static uint32_t
10567lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10568{
10569 uint32_t intr_mode = LPFC_INTR_ERROR;
10570 int retval;
10571
10572 if (cfg_mode == 2) {
10573 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10574 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10575 if (!retval) {
10576 /* Now, try to enable MSI-X interrupt mode */
10577 retval = lpfc_sli_enable_msix(phba);
10578 if (!retval) {
10579 /* Indicate initialization to MSI-X mode */
10580 phba->intr_type = MSIX;
10581 intr_mode = 2;
10582 }
10583 }
10584 }
10585
10586 /* Fallback to MSI if MSI-X initialization failed */
10587 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10588 retval = lpfc_sli_enable_msi(phba);
10589 if (!retval) {
10590 /* Indicate initialization to MSI mode */
10591 phba->intr_type = MSI;
10592 intr_mode = 1;
10593 }
10594 }
10595
10596 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10597 if (phba->intr_type == NONE) {
10598 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10599 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10600 if (!retval) {
10601 /* Indicate initialization to INTx mode */
10602 phba->intr_type = INTx;
10603 intr_mode = 0;
10604 }
10605 }
10606 return intr_mode;
10607}
10608
10609/**
10610 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10611 * @phba: pointer to lpfc hba data structure.
10612 *
10613 * This routine is invoked to disable device interrupt and disassociate the
10614 * driver's interrupt handler(s) from interrupt vector(s) to device with
10615 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10616 * release the interrupt vector(s) for the message signaled interrupt.
10617 **/
10618static void
10619lpfc_sli_disable_intr(struct lpfc_hba *phba)
10620{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010621 int nr_irqs, i;
10622
James Smart3772a992009-05-22 14:50:54 -040010623 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010624 nr_irqs = LPFC_MSIX_VECTORS;
10625 else
10626 nr_irqs = 1;
10627
10628 for (i = 0; i < nr_irqs; i++)
10629 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10630 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010631
10632 /* Reset interrupt management states */
10633 phba->intr_type = NONE;
10634 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010635}
10636
10637/**
James Smart657add42019-05-21 17:49:06 -070010638 * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
James Smart6a828b02019-01-28 11:14:31 -080010639 * @phba: pointer to lpfc hba data structure.
10640 * @id: EQ vector index or Hardware Queue index
10641 * @match: LPFC_FIND_BY_EQ = match by EQ
10642 * LPFC_FIND_BY_HDWQ = match by Hardware Queue
James Smart657add42019-05-21 17:49:06 -070010643 * Return the CPU that matches the selection criteria
James Smart6a828b02019-01-28 11:14:31 -080010644 */
10645static uint16_t
10646lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
10647{
10648 struct lpfc_vector_map_info *cpup;
10649 int cpu;
10650
James Smart657add42019-05-21 17:49:06 -070010651 /* Loop through all CPUs */
James Smart222e9232019-01-28 11:14:35 -080010652 for_each_present_cpu(cpu) {
10653 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart657add42019-05-21 17:49:06 -070010654
10655 /* If we are matching by EQ, there may be multiple CPUs using
10656 * using the same vector, so select the one with
10657 * LPFC_CPU_FIRST_IRQ set.
10658 */
James Smart6a828b02019-01-28 11:14:31 -080010659 if ((match == LPFC_FIND_BY_EQ) &&
James Smart657add42019-05-21 17:49:06 -070010660 (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
James Smart6a828b02019-01-28 11:14:31 -080010661 (cpup->irq != LPFC_VECTOR_MAP_EMPTY) &&
10662 (cpup->eq == id))
10663 return cpu;
James Smart657add42019-05-21 17:49:06 -070010664
10665 /* If matching by HDWQ, select the first CPU that matches */
James Smart6a828b02019-01-28 11:14:31 -080010666 if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
10667 return cpu;
James Smart6a828b02019-01-28 11:14:31 -080010668 }
10669 return 0;
10670}
10671
James Smart6a828b02019-01-28 11:14:31 -080010672#ifdef CONFIG_X86
10673/**
10674 * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
10675 * @phba: pointer to lpfc hba data structure.
10676 * @cpu: CPU map index
10677 * @phys_id: CPU package physical id
10678 * @core_id: CPU core id
10679 */
10680static int
10681lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
10682 uint16_t phys_id, uint16_t core_id)
10683{
10684 struct lpfc_vector_map_info *cpup;
10685 int idx;
10686
James Smart222e9232019-01-28 11:14:35 -080010687 for_each_present_cpu(idx) {
10688 cpup = &phba->sli4_hba.cpu_map[idx];
James Smart6a828b02019-01-28 11:14:31 -080010689 /* Does the cpup match the one we are looking for */
10690 if ((cpup->phys_id == phys_id) &&
10691 (cpup->core_id == core_id) &&
James Smart222e9232019-01-28 11:14:35 -080010692 (cpu != idx))
James Smart6a828b02019-01-28 11:14:31 -080010693 return 1;
James Smart6a828b02019-01-28 11:14:31 -080010694 }
10695 return 0;
10696}
10697#endif
10698
10699/**
James Smart895427b2017-02-12 13:52:30 -080010700 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010701 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010702 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010703 *
James Smart895427b2017-02-12 13:52:30 -080010704 * The routine will figure out the CPU affinity assignment for every
James Smart6a828b02019-01-28 11:14:31 -080010705 * MSI-X vector allocated for the HBA.
James Smart895427b2017-02-12 13:52:30 -080010706 * In addition, the CPU to IO channel mapping will be calculated
10707 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010708 */
James Smart895427b2017-02-12 13:52:30 -080010709static void
10710lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010711{
James Smartd9954a22019-05-21 17:49:05 -070010712 int i, cpu, idx, new_cpu, start_cpu, first_cpu;
James Smart6a828b02019-01-28 11:14:31 -080010713 int max_phys_id, min_phys_id;
10714 int max_core_id, min_core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010715 struct lpfc_vector_map_info *cpup;
James Smartd9954a22019-05-21 17:49:05 -070010716 struct lpfc_vector_map_info *new_cpup;
James Smart75508a82019-01-28 11:14:34 -080010717 const struct cpumask *maskp;
James Smart7bb03bb2013-04-17 20:19:16 -040010718#ifdef CONFIG_X86
10719 struct cpuinfo_x86 *cpuinfo;
10720#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010721
10722 /* Init cpu_map array */
James Smartd9954a22019-05-21 17:49:05 -070010723 for_each_possible_cpu(cpu) {
10724 cpup = &phba->sli4_hba.cpu_map[cpu];
10725 cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
10726 cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
10727 cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
10728 cpup->eq = LPFC_VECTOR_MAP_EMPTY;
10729 cpup->irq = LPFC_VECTOR_MAP_EMPTY;
10730 cpup->flag = 0;
10731 }
James Smart7bb03bb2013-04-17 20:19:16 -040010732
James Smart6a828b02019-01-28 11:14:31 -080010733 max_phys_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010734 min_phys_id = LPFC_VECTOR_MAP_EMPTY;
James Smart6a828b02019-01-28 11:14:31 -080010735 max_core_id = 0;
James Smartd9954a22019-05-21 17:49:05 -070010736 min_core_id = LPFC_VECTOR_MAP_EMPTY;
James Smart7bb03bb2013-04-17 20:19:16 -040010737
10738 /* Update CPU map with physical id and core id of each CPU */
James Smart222e9232019-01-28 11:14:35 -080010739 for_each_present_cpu(cpu) {
10740 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart7bb03bb2013-04-17 20:19:16 -040010741#ifdef CONFIG_X86
10742 cpuinfo = &cpu_data(cpu);
10743 cpup->phys_id = cpuinfo->phys_proc_id;
10744 cpup->core_id = cpuinfo->cpu_core_id;
James Smartd9954a22019-05-21 17:49:05 -070010745 if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
10746 cpup->flag |= LPFC_CPU_MAP_HYPER;
James Smart7bb03bb2013-04-17 20:19:16 -040010747#else
10748 /* No distinction between CPUs for other platforms */
10749 cpup->phys_id = 0;
James Smart6a828b02019-01-28 11:14:31 -080010750 cpup->core_id = cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010751#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010752
James Smartb3295c22019-01-28 11:14:30 -080010753 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10754 "3328 CPU physid %d coreid %d\n",
10755 cpup->phys_id, cpup->core_id);
James Smart6a828b02019-01-28 11:14:31 -080010756
10757 if (cpup->phys_id > max_phys_id)
10758 max_phys_id = cpup->phys_id;
10759 if (cpup->phys_id < min_phys_id)
10760 min_phys_id = cpup->phys_id;
10761
10762 if (cpup->core_id > max_core_id)
10763 max_core_id = cpup->core_id;
10764 if (cpup->core_id < min_core_id)
10765 min_core_id = cpup->core_id;
James Smart7bb03bb2013-04-17 20:19:16 -040010766 }
James Smartb3295c22019-01-28 11:14:30 -080010767
James Smart32517fc2019-01-28 11:14:33 -080010768 for_each_possible_cpu(i) {
10769 struct lpfc_eq_intr_info *eqi =
10770 per_cpu_ptr(phba->sli4_hba.eq_info, i);
10771
10772 INIT_LIST_HEAD(&eqi->list);
10773 eqi->icnt = 0;
10774 }
10775
James Smartd9954a22019-05-21 17:49:05 -070010776 /* This loop sets up all CPUs that are affinitized with a
10777 * irq vector assigned to the driver. All affinitized CPUs
James Smart657add42019-05-21 17:49:06 -070010778 * will get a link to that vectors IRQ and EQ.
James Smarta86c71b2019-08-02 13:26:12 -070010779 *
10780 * NULL affinity mask handling:
10781 * If irq count is greater than one, log an error message.
10782 * If the null mask is received for the first irq, find the
10783 * first present cpu, and assign the eq index to ensure at
10784 * least one EQ is assigned.
James Smartd9954a22019-05-21 17:49:05 -070010785 */
James Smart75508a82019-01-28 11:14:34 -080010786 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smart657add42019-05-21 17:49:06 -070010787 /* Get a CPU mask for all CPUs affinitized to this vector */
James Smart75508a82019-01-28 11:14:34 -080010788 maskp = pci_irq_get_affinity(phba->pcidev, idx);
James Smarta86c71b2019-08-02 13:26:12 -070010789 if (!maskp) {
10790 if (phba->cfg_irq_chann > 1)
10791 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10792 "3329 No affinity mask found "
10793 "for vector %d (%d)\n",
10794 idx, phba->cfg_irq_chann);
10795 if (!idx) {
10796 cpu = cpumask_first(cpu_present_mask);
10797 cpup = &phba->sli4_hba.cpu_map[cpu];
10798 cpup->eq = idx;
10799 cpup->irq = pci_irq_vector(phba->pcidev, idx);
10800 cpup->flag |= LPFC_CPU_FIRST_IRQ;
10801 }
10802 break;
10803 }
James Smart75508a82019-01-28 11:14:34 -080010804
James Smart657add42019-05-21 17:49:06 -070010805 i = 0;
10806 /* Loop through all CPUs associated with vector idx */
James Smart75508a82019-01-28 11:14:34 -080010807 for_each_cpu_and(cpu, maskp, cpu_present_mask) {
James Smart657add42019-05-21 17:49:06 -070010808 /* Set the EQ index and IRQ for that vector */
James Smart75508a82019-01-28 11:14:34 -080010809 cpup = &phba->sli4_hba.cpu_map[cpu];
James Smart6a828b02019-01-28 11:14:31 -080010810 cpup->eq = idx;
James Smart6a828b02019-01-28 11:14:31 -080010811 cpup->irq = pci_irq_vector(phba->pcidev, idx);
James Smartb3295c22019-01-28 11:14:30 -080010812
James Smart657add42019-05-21 17:49:06 -070010813 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart6a828b02019-01-28 11:14:31 -080010814 "3336 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010815 "irq %d eq %d\n",
10816 cpu, cpup->irq, cpup->eq);
10817
10818 /* If this is the first CPU thats assigned to this
10819 * vector, set LPFC_CPU_FIRST_IRQ.
10820 */
10821 if (!i)
10822 cpup->flag |= LPFC_CPU_FIRST_IRQ;
10823 i++;
James Smart6a828b02019-01-28 11:14:31 -080010824 }
James Smartb3295c22019-01-28 11:14:30 -080010825 }
James Smartd9954a22019-05-21 17:49:05 -070010826
10827 /* After looking at each irq vector assigned to this pcidev, its
10828 * possible to see that not ALL CPUs have been accounted for.
James Smart657add42019-05-21 17:49:06 -070010829 * Next we will set any unassigned (unaffinitized) cpu map
10830 * entries to a IRQ on the same phys_id.
James Smartd9954a22019-05-21 17:49:05 -070010831 */
10832 first_cpu = cpumask_first(cpu_present_mask);
10833 start_cpu = first_cpu;
10834
10835 for_each_present_cpu(cpu) {
10836 cpup = &phba->sli4_hba.cpu_map[cpu];
10837
10838 /* Is this CPU entry unassigned */
10839 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10840 /* Mark CPU as IRQ not assigned by the kernel */
10841 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10842
James Smart657add42019-05-21 17:49:06 -070010843 /* If so, find a new_cpup thats on the the SAME
James Smartd9954a22019-05-21 17:49:05 -070010844 * phys_id as cpup. start_cpu will start where we
10845 * left off so all unassigned entries don't get assgined
10846 * the IRQ of the first entry.
10847 */
10848 new_cpu = start_cpu;
10849 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10850 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10851 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10852 (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY) &&
10853 (new_cpup->phys_id == cpup->phys_id))
10854 goto found_same;
10855 new_cpu = cpumask_next(
10856 new_cpu, cpu_present_mask);
10857 if (new_cpu == nr_cpumask_bits)
10858 new_cpu = first_cpu;
10859 }
10860 /* At this point, we leave the CPU as unassigned */
10861 continue;
10862found_same:
10863 /* We found a matching phys_id, so copy the IRQ info */
10864 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070010865 cpup->irq = new_cpup->irq;
10866
10867 /* Bump start_cpu to the next slot to minmize the
10868 * chance of having multiple unassigned CPU entries
10869 * selecting the same IRQ.
10870 */
10871 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10872 if (start_cpu == nr_cpumask_bits)
10873 start_cpu = first_cpu;
10874
James Smart657add42019-05-21 17:49:06 -070010875 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070010876 "3337 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010877 "irq %d from id %d same "
James Smartd9954a22019-05-21 17:49:05 -070010878 "phys_id (%d)\n",
James Smart657add42019-05-21 17:49:06 -070010879 cpu, cpup->irq, new_cpu, cpup->phys_id);
James Smartd9954a22019-05-21 17:49:05 -070010880 }
10881 }
10882
10883 /* Set any unassigned cpu map entries to a IRQ on any phys_id */
10884 start_cpu = first_cpu;
10885
10886 for_each_present_cpu(cpu) {
10887 cpup = &phba->sli4_hba.cpu_map[cpu];
10888
10889 /* Is this entry unassigned */
10890 if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
10891 /* Mark it as IRQ not assigned by the kernel */
10892 cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
10893
James Smart657add42019-05-21 17:49:06 -070010894 /* If so, find a new_cpup thats on ANY phys_id
James Smartd9954a22019-05-21 17:49:05 -070010895 * as the cpup. start_cpu will start where we
10896 * left off so all unassigned entries don't get
10897 * assigned the IRQ of the first entry.
10898 */
10899 new_cpu = start_cpu;
10900 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10901 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10902 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
10903 (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY))
10904 goto found_any;
10905 new_cpu = cpumask_next(
10906 new_cpu, cpu_present_mask);
10907 if (new_cpu == nr_cpumask_bits)
10908 new_cpu = first_cpu;
10909 }
10910 /* We should never leave an entry unassigned */
10911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10912 "3339 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010913 "irq %d UNASSIGNED\n",
10914 cpup->hdwq, cpup->irq);
James Smartd9954a22019-05-21 17:49:05 -070010915 continue;
10916found_any:
10917 /* We found an available entry, copy the IRQ info */
10918 cpup->eq = new_cpup->eq;
James Smartd9954a22019-05-21 17:49:05 -070010919 cpup->irq = new_cpup->irq;
10920
10921 /* Bump start_cpu to the next slot to minmize the
10922 * chance of having multiple unassigned CPU entries
10923 * selecting the same IRQ.
10924 */
10925 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10926 if (start_cpu == nr_cpumask_bits)
10927 start_cpu = first_cpu;
10928
James Smart657add42019-05-21 17:49:06 -070010929 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartd9954a22019-05-21 17:49:05 -070010930 "3338 Set Affinity: CPU %d "
James Smart657add42019-05-21 17:49:06 -070010931 "irq %d from id %d (%d/%d)\n",
10932 cpu, cpup->irq, new_cpu,
James Smartd9954a22019-05-21 17:49:05 -070010933 new_cpup->phys_id, new_cpup->core_id);
10934 }
10935 }
James Smart657add42019-05-21 17:49:06 -070010936
10937 /* Finally we need to associate a hdwq with each cpu_map entry
10938 * This will be 1 to 1 - hdwq to cpu, unless there are less
10939 * hardware queues then CPUs. For that case we will just round-robin
10940 * the available hardware queues as they get assigned to CPUs.
10941 */
10942 idx = 0;
10943 start_cpu = 0;
10944 for_each_present_cpu(cpu) {
10945 cpup = &phba->sli4_hba.cpu_map[cpu];
10946 if (idx >= phba->cfg_hdw_queue) {
10947 /* We need to reuse a Hardware Queue for another CPU,
10948 * so be smart about it and pick one that has its
10949 * IRQ/EQ mapped to the same phys_id (CPU package).
10950 * and core_id.
10951 */
10952 new_cpu = start_cpu;
10953 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10954 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10955 if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) &&
10956 (new_cpup->phys_id == cpup->phys_id) &&
10957 (new_cpup->core_id == cpup->core_id))
10958 goto found_hdwq;
10959 new_cpu = cpumask_next(
10960 new_cpu, cpu_present_mask);
10961 if (new_cpu == nr_cpumask_bits)
10962 new_cpu = first_cpu;
10963 }
10964
10965 /* If we can't match both phys_id and core_id,
10966 * settle for just a phys_id match.
10967 */
10968 new_cpu = start_cpu;
10969 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
10970 new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
10971 if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) &&
10972 (new_cpup->phys_id == cpup->phys_id))
10973 goto found_hdwq;
10974 new_cpu = cpumask_next(
10975 new_cpu, cpu_present_mask);
10976 if (new_cpu == nr_cpumask_bits)
10977 new_cpu = first_cpu;
10978 }
10979
10980 /* Otherwise just round robin on cfg_hdw_queue */
10981 cpup->hdwq = idx % phba->cfg_hdw_queue;
10982 goto logit;
10983found_hdwq:
10984 /* We found an available entry, copy the IRQ info */
10985 start_cpu = cpumask_next(new_cpu, cpu_present_mask);
10986 if (start_cpu == nr_cpumask_bits)
10987 start_cpu = first_cpu;
10988 cpup->hdwq = new_cpup->hdwq;
10989 } else {
10990 /* 1 to 1, CPU to hdwq */
10991 cpup->hdwq = idx;
10992 }
10993logit:
10994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10995 "3335 Set Affinity: CPU %d (phys %d core %d): "
10996 "hdwq %d eq %d irq %d flg x%x\n",
10997 cpu, cpup->phys_id, cpup->core_id,
10998 cpup->hdwq, cpup->eq, cpup->irq, cpup->flag);
10999 idx++;
11000 }
11001
11002 /* The cpu_map array will be used later during initialization
11003 * when EQ / CQ / WQs are allocated and configured.
11004 */
James Smartb3295c22019-01-28 11:14:30 -080011005 return;
James Smart7bb03bb2013-04-17 20:19:16 -040011006}
James Smart7bb03bb2013-04-17 20:19:16 -040011007
11008/**
James Smartda0436e2009-05-22 14:51:39 -040011009 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
11010 * @phba: pointer to lpfc hba data structure.
11011 *
11012 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011013 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040011014 *
11015 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011016 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011017 * other values - error
11018 **/
11019static int
11020lpfc_sli4_enable_msix(struct lpfc_hba *phba)
11021{
James Smart75baf692010-06-08 18:31:21 -040011022 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070011023 char *name;
James Smartda0436e2009-05-22 14:51:39 -040011024
11025 /* Set up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011026 vectors = phba->cfg_irq_chann;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011027
James Smartf358dd02017-02-12 13:52:34 -080011028 rc = pci_alloc_irq_vectors(phba->pcidev,
James Smart75508a82019-01-28 11:14:34 -080011029 1,
James Smartf358dd02017-02-12 13:52:34 -080011030 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011031 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040011032 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11033 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011034 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040011035 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040011036 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040011037
James Smart7bb03bb2013-04-17 20:19:16 -040011038 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040011039 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070011040 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
11041 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
11042 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040011043 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040011044
James Smart895427b2017-02-12 13:52:30 -080011045 phba->sli4_hba.hba_eq_hdl[index].idx = index;
11046 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart7370d102019-01-28 11:14:20 -080011047 rc = request_irq(pci_irq_vector(phba->pcidev, index),
11048 &lpfc_sli4_hba_intr_handler, 0,
11049 name,
11050 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040011051 if (rc) {
11052 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11053 "0486 MSI-X fast-path (%d) "
11054 "request_irq failed (%d)\n", index, rc);
11055 goto cfg_fail_out;
11056 }
11057 }
11058
James Smart6a828b02019-01-28 11:14:31 -080011059 if (vectors != phba->cfg_irq_chann) {
James Smart82c3e9b2012-09-29 11:29:50 -040011060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11061 "3238 Reducing IO channels to match number of "
11062 "MSI-X vectors, requested %d got %d\n",
James Smart6a828b02019-01-28 11:14:31 -080011063 phba->cfg_irq_chann, vectors);
11064 if (phba->cfg_irq_chann > vectors)
11065 phba->cfg_irq_chann = vectors;
James Smart982ab122019-03-12 16:30:10 -070011066 if (phba->nvmet_support && (phba->cfg_nvmet_mrq > vectors))
James Smartcdb42be2019-01-28 11:14:21 -080011067 phba->cfg_nvmet_mrq = vectors;
James Smart82c3e9b2012-09-29 11:29:50 -040011068 }
James Smart7bb03bb2013-04-17 20:19:16 -040011069
James Smartda0436e2009-05-22 14:51:39 -040011070 return rc;
11071
11072cfg_fail_out:
11073 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080011074 for (--index; index >= 0; index--)
11075 free_irq(pci_irq_vector(phba->pcidev, index),
11076 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040011077
James Smartda0436e2009-05-22 14:51:39 -040011078 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011079 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020011080
11081vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040011082 return rc;
11083}
11084
11085/**
James Smartda0436e2009-05-22 14:51:39 -040011086 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
11087 * @phba: pointer to lpfc hba data structure.
11088 *
11089 * This routine is invoked to enable the MSI interrupt mode to device with
11090 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
11091 * to enable the MSI vector. The device driver is responsible for calling
11092 * the request_irq() to register MSI vector with a interrupt the handler,
11093 * which is done in this function.
11094 *
11095 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011096 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011097 * other values - error
11098 **/
11099static int
11100lpfc_sli4_enable_msi(struct lpfc_hba *phba)
11101{
11102 int rc, index;
11103
11104 rc = pci_enable_msi(phba->pcidev);
11105 if (!rc)
11106 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11107 "0487 PCI enable MSI mode success.\n");
11108 else {
11109 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11110 "0488 PCI enable MSI mode failed (%d)\n", rc);
11111 return rc;
11112 }
11113
11114 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040011115 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040011116 if (rc) {
11117 pci_disable_msi(phba->pcidev);
11118 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
11119 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040011120 return rc;
James Smartda0436e2009-05-22 14:51:39 -040011121 }
11122
James Smart6a828b02019-01-28 11:14:31 -080011123 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smart895427b2017-02-12 13:52:30 -080011124 phba->sli4_hba.hba_eq_hdl[index].idx = index;
11125 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040011126 }
11127
James Smart75baf692010-06-08 18:31:21 -040011128 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011129}
11130
11131/**
James Smartda0436e2009-05-22 14:51:39 -040011132 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
11133 * @phba: pointer to lpfc hba data structure.
11134 *
11135 * This routine is invoked to enable device interrupt and associate driver's
11136 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
11137 * interface spec. Depends on the interrupt mode configured to the driver,
11138 * the driver will try to fallback from the configured interrupt mode to an
11139 * interrupt mode which is supported by the platform, kernel, and device in
11140 * the order of:
11141 * MSI-X -> MSI -> IRQ.
11142 *
11143 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020011144 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040011145 * other values - error
11146 **/
11147static uint32_t
11148lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
11149{
11150 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080011151 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040011152
11153 if (cfg_mode == 2) {
11154 /* Preparation before conf_msi mbox cmd */
11155 retval = 0;
11156 if (!retval) {
11157 /* Now, try to enable MSI-X interrupt mode */
11158 retval = lpfc_sli4_enable_msix(phba);
11159 if (!retval) {
11160 /* Indicate initialization to MSI-X mode */
11161 phba->intr_type = MSIX;
11162 intr_mode = 2;
11163 }
11164 }
11165 }
11166
11167 /* Fallback to MSI if MSI-X initialization failed */
11168 if (cfg_mode >= 1 && phba->intr_type == NONE) {
11169 retval = lpfc_sli4_enable_msi(phba);
11170 if (!retval) {
11171 /* Indicate initialization to MSI mode */
11172 phba->intr_type = MSI;
11173 intr_mode = 1;
11174 }
11175 }
11176
11177 /* Fallback to INTx if both MSI-X/MSI initalization failed */
11178 if (phba->intr_type == NONE) {
11179 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
11180 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
11181 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080011182 struct lpfc_hba_eq_hdl *eqhdl;
11183
James Smartda0436e2009-05-22 14:51:39 -040011184 /* Indicate initialization to INTx mode */
11185 phba->intr_type = INTx;
11186 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080011187
James Smart6a828b02019-01-28 11:14:31 -080011188 for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
James Smart895427b2017-02-12 13:52:30 -080011189 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
11190 eqhdl->idx = idx;
11191 eqhdl->phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050011192 }
James Smartda0436e2009-05-22 14:51:39 -040011193 }
11194 }
11195 return intr_mode;
11196}
11197
11198/**
11199 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
11200 * @phba: pointer to lpfc hba data structure.
11201 *
11202 * This routine is invoked to disable device interrupt and disassociate
11203 * the driver's interrupt handler(s) from interrupt vector(s) to device
11204 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
11205 * will release the interrupt vector(s) for the message signaled interrupt.
11206 **/
11207static void
11208lpfc_sli4_disable_intr(struct lpfc_hba *phba)
11209{
11210 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011211 if (phba->intr_type == MSIX) {
11212 int index;
11213
11214 /* Free up MSI-X multi-message vectors */
James Smart6a828b02019-01-28 11:14:31 -080011215 for (index = 0; index < phba->cfg_irq_chann; index++) {
James Smartb3295c22019-01-28 11:14:30 -080011216 irq_set_affinity_hint(
11217 pci_irq_vector(phba->pcidev, index),
11218 NULL);
James Smart895427b2017-02-12 13:52:30 -080011219 free_irq(pci_irq_vector(phba->pcidev, index),
11220 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartb3295c22019-01-28 11:14:30 -080011221 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011222 } else {
James Smartda0436e2009-05-22 14:51:39 -040011223 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080011224 }
11225
11226 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040011227
11228 /* Reset interrupt management states */
11229 phba->intr_type = NONE;
11230 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040011231}
11232
11233/**
James Smart3772a992009-05-22 14:50:54 -040011234 * lpfc_unset_hba - Unset SLI3 hba device initialization
11235 * @phba: pointer to lpfc hba data structure.
11236 *
11237 * This routine is invoked to unset the HBA device initialization steps to
11238 * a device with SLI-3 interface spec.
11239 **/
11240static void
11241lpfc_unset_hba(struct lpfc_hba *phba)
11242{
11243 struct lpfc_vport *vport = phba->pport;
11244 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11245
11246 spin_lock_irq(shost->host_lock);
11247 vport->load_flag |= FC_UNLOADING;
11248 spin_unlock_irq(shost->host_lock);
11249
James Smart72859902012-01-18 16:25:38 -050011250 kfree(phba->vpi_bmask);
11251 kfree(phba->vpi_ids);
11252
James Smart3772a992009-05-22 14:50:54 -040011253 lpfc_stop_hba_timers(phba);
11254
11255 phba->pport->work_port_events = 0;
11256
11257 lpfc_sli_hba_down(phba);
11258
11259 lpfc_sli_brdrestart(phba);
11260
11261 lpfc_sli_disable_intr(phba);
11262
11263 return;
11264}
11265
11266/**
James Smart5af5eee2010-10-22 11:06:38 -040011267 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
11268 * @phba: Pointer to HBA context object.
11269 *
11270 * This function is called in the SLI4 code path to wait for completion
11271 * of device's XRIs exchange busy. It will check the XRI exchange busy
11272 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
11273 * that, it will check the XRI exchange busy on outstanding FCP and ELS
11274 * I/Os every 30 seconds, log error message, and wait forever. Only when
11275 * all XRI exchange busy complete, the driver unload shall proceed with
11276 * invoking the function reset ioctl mailbox command to the CNA and the
11277 * the rest of the driver unload resource release.
11278 **/
11279static void
11280lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
11281{
James Smart5e5b5112019-01-28 11:14:22 -080011282 struct lpfc_sli4_hdw_queue *qp;
11283 int idx, ccnt, fcnt;
James Smart5af5eee2010-10-22 11:06:38 -040011284 int wait_time = 0;
James Smart5e5b5112019-01-28 11:14:22 -080011285 int io_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070011286 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080011287 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040011288 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
11289
James Smartc3725bd2017-11-20 16:00:42 -080011290 /* Driver just aborted IOs during the hba_unset process. Pause
11291 * here to give the HBA time to complete the IO and get entries
11292 * into the abts lists.
11293 */
11294 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
11295
11296 /* Wait for NVME pending IO to flush back to transport. */
11297 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11298 lpfc_nvme_wait_for_io_drain(phba);
11299
James Smart5e5b5112019-01-28 11:14:22 -080011300 ccnt = 0;
11301 fcnt = 0;
11302 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11303 qp = &phba->sli4_hba.hdwq[idx];
11304 fcp_xri_cmpl = list_empty(
11305 &qp->lpfc_abts_scsi_buf_list);
11306 if (!fcp_xri_cmpl) /* if list is NOT empty */
11307 fcnt++;
11308 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11309 io_xri_cmpl = list_empty(
11310 &qp->lpfc_abts_nvme_buf_list);
11311 if (!io_xri_cmpl) /* if list is NOT empty */
11312 ccnt++;
11313 }
11314 }
11315 if (ccnt)
11316 io_xri_cmpl = 0;
11317 if (fcnt)
11318 fcp_xri_cmpl = 0;
11319
James Smart86c67372017-04-21 16:05:04 -070011320 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011321 nvmet_xri_cmpl =
11322 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11323 }
James Smart895427b2017-02-12 13:52:30 -080011324
James Smart5e5b5112019-01-28 11:14:22 -080011325 while (!fcp_xri_cmpl || !els_xri_cmpl || !io_xri_cmpl ||
James Smartf358dd02017-02-12 13:52:34 -080011326 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040011327 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070011328 if (!nvmet_xri_cmpl)
11329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11330 "6424 NVMET XRI exchange busy "
11331 "wait time: %d seconds.\n",
11332 wait_time/1000);
James Smart5e5b5112019-01-28 11:14:22 -080011333 if (!io_xri_cmpl)
James Smart895427b2017-02-12 13:52:30 -080011334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11335 "6100 NVME XRI exchange busy "
11336 "wait time: %d seconds.\n",
11337 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040011338 if (!fcp_xri_cmpl)
11339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11340 "2877 FCP XRI exchange busy "
11341 "wait time: %d seconds.\n",
11342 wait_time/1000);
11343 if (!els_xri_cmpl)
11344 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11345 "2878 ELS XRI exchange busy "
11346 "wait time: %d seconds.\n",
11347 wait_time/1000);
11348 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
11349 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
11350 } else {
11351 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
11352 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
11353 }
James Smart5e5b5112019-01-28 11:14:22 -080011354
11355 ccnt = 0;
11356 fcnt = 0;
11357 for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
11358 qp = &phba->sli4_hba.hdwq[idx];
11359 fcp_xri_cmpl = list_empty(
11360 &qp->lpfc_abts_scsi_buf_list);
11361 if (!fcp_xri_cmpl) /* if list is NOT empty */
11362 fcnt++;
11363 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11364 io_xri_cmpl = list_empty(
11365 &qp->lpfc_abts_nvme_buf_list);
11366 if (!io_xri_cmpl) /* if list is NOT empty */
11367 ccnt++;
11368 }
11369 }
11370 if (ccnt)
11371 io_xri_cmpl = 0;
11372 if (fcnt)
11373 fcp_xri_cmpl = 0;
11374
James Smart86c67372017-04-21 16:05:04 -070011375 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart86c67372017-04-21 16:05:04 -070011376 nvmet_xri_cmpl = list_empty(
11377 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
11378 }
James Smart5af5eee2010-10-22 11:06:38 -040011379 els_xri_cmpl =
11380 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080011381
James Smart5af5eee2010-10-22 11:06:38 -040011382 }
11383}
11384
11385/**
James Smartda0436e2009-05-22 14:51:39 -040011386 * lpfc_sli4_hba_unset - Unset the fcoe hba
11387 * @phba: Pointer to HBA context object.
11388 *
11389 * This function is called in the SLI4 code path to reset the HBA's FCoE
11390 * function. The caller is not required to hold any lock. This routine
11391 * issues PCI function reset mailbox command to reset the FCoE function.
11392 * At the end of the function, it calls lpfc_hba_down_post function to
11393 * free any pending commands.
11394 **/
11395static void
11396lpfc_sli4_hba_unset(struct lpfc_hba *phba)
11397{
11398 int wait_cnt = 0;
11399 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040011400 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040011401
11402 lpfc_stop_hba_timers(phba);
James Smartcdb42be2019-01-28 11:14:21 -080011403 if (phba->pport)
11404 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -040011405
11406 /*
11407 * Gracefully wait out the potential current outstanding asynchronous
11408 * mailbox command.
11409 */
11410
11411 /* First, block any pending async mailbox command from posted */
11412 spin_lock_irq(&phba->hbalock);
11413 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
11414 spin_unlock_irq(&phba->hbalock);
11415 /* Now, trying to wait it out if we can */
11416 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11417 msleep(10);
11418 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
11419 break;
11420 }
11421 /* Forcefully release the outstanding mailbox command if timed out */
11422 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
11423 spin_lock_irq(&phba->hbalock);
11424 mboxq = phba->sli.mbox_active;
11425 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
11426 __lpfc_mbox_cmpl_put(phba, mboxq);
11427 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11428 phba->sli.mbox_active = NULL;
11429 spin_unlock_irq(&phba->hbalock);
11430 }
11431
James Smart5af5eee2010-10-22 11:06:38 -040011432 /* Abort all iocbs associated with the hba */
11433 lpfc_sli_hba_iocb_abort(phba);
11434
11435 /* Wait for completion of device XRI exchange busy */
11436 lpfc_sli4_xri_exchange_busy_wait(phba);
11437
James Smartda0436e2009-05-22 14:51:39 -040011438 /* Disable PCI subsystem interrupt */
11439 lpfc_sli4_disable_intr(phba);
11440
James Smart912e3ac2011-05-24 11:42:11 -040011441 /* Disable SR-IOV if enabled */
11442 if (phba->cfg_sriov_nr_virtfn)
11443 pci_disable_sriov(pdev);
11444
James Smartda0436e2009-05-22 14:51:39 -040011445 /* Stop kthread signal shall trigger work_done one more time */
11446 kthread_stop(phba->worker_thread);
11447
James Smartd2cc9bc2018-09-10 10:30:50 -070011448 /* Disable FW logging to host memory */
James Smart1165a5c2018-11-29 16:09:39 -080011449 lpfc_ras_stop_fwlog(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070011450
James Smartd1f525a2017-04-21 16:04:55 -070011451 /* Unset the queues shared with the hardware then release all
11452 * allocated resources.
11453 */
11454 lpfc_sli4_queue_unset(phba);
11455 lpfc_sli4_queue_destroy(phba);
11456
James Smart3677a3a2010-09-29 11:19:14 -040011457 /* Reset SLI4 HBA FCoE function */
11458 lpfc_pci_function_reset(phba);
11459
James Smart1165a5c2018-11-29 16:09:39 -080011460 /* Free RAS DMA memory */
11461 if (phba->ras_fwlog.ras_enabled)
11462 lpfc_sli4_ras_dma_free(phba);
11463
James Smartda0436e2009-05-22 14:51:39 -040011464 /* Stop the SLI4 device port */
James Smart1ffdd2c2019-03-04 15:27:51 -080011465 if (phba->pport)
11466 phba->pport->work_port_events = 0;
James Smartda0436e2009-05-22 14:51:39 -040011467}
11468
James Smart28baac72010-02-12 14:42:03 -050011469 /**
11470 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
11471 * @phba: Pointer to HBA context object.
11472 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11473 *
11474 * This function is called in the SLI4 code path to read the port's
11475 * sli4 capabilities.
11476 *
11477 * This function may be be called from any context that can block-wait
11478 * for the completion. The expectation is that this routine is called
11479 * typically from probe_one or from the online routine.
11480 **/
11481int
11482lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11483{
11484 int rc;
11485 struct lpfc_mqe *mqe;
11486 struct lpfc_pc_sli4_params *sli4_params;
11487 uint32_t mbox_tmo;
11488
11489 rc = 0;
11490 mqe = &mboxq->u.mqe;
11491
11492 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050011493 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050011494 if (!phba->sli4_hba.intr_enable)
11495 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
11496 else {
James Smarta183a152011-10-10 21:32:43 -040011497 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050011498 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11499 }
11500
11501 if (unlikely(rc))
11502 return 1;
11503
11504 sli4_params = &phba->sli4_hba.pc_sli4_params;
11505 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
11506 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
11507 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
11508 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
11509 &mqe->un.sli4_params);
11510 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
11511 &mqe->un.sli4_params);
11512 sli4_params->proto_types = mqe->un.sli4_params.word3;
11513 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
11514 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
11515 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
11516 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
11517 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
11518 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
11519 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
11520 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
11521 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
11522 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
11523 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
11524 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
11525 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
11526 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
11527 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
11528 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
11529 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
11530 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
11531 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
11532 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040011533
11534 /* Make sure that sge_supp_len can be handled by the driver */
11535 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
11536 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
11537
James Smart28baac72010-02-12 14:42:03 -050011538 return rc;
11539}
11540
James Smartda0436e2009-05-22 14:51:39 -040011541/**
James Smartfedd3b72011-02-16 12:39:24 -050011542 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
11543 * @phba: Pointer to HBA context object.
11544 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
11545 *
11546 * This function is called in the SLI4 code path to read the port's
11547 * sli4 capabilities.
11548 *
11549 * This function may be be called from any context that can block-wait
11550 * for the completion. The expectation is that this routine is called
11551 * typically from probe_one or from the online routine.
11552 **/
11553int
11554lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
11555{
11556 int rc;
11557 struct lpfc_mqe *mqe = &mboxq->u.mqe;
11558 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040011559 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050011560 int length;
James Smartbf316c72018-04-09 14:24:28 -070011561 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050011562 struct lpfc_sli4_parameters *mbx_sli4_parameters;
11563
James Smart6d368e52011-05-24 11:44:12 -040011564 /*
11565 * By default, the driver assumes the SLI4 port requires RPI
11566 * header postings. The SLI4_PARAM response will correct this
11567 * assumption.
11568 */
11569 phba->sli4_hba.rpi_hdrs_in_use = 1;
11570
James Smartfedd3b72011-02-16 12:39:24 -050011571 /* Read the port's SLI4 Config Parameters */
11572 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
11573 sizeof(struct lpfc_sli4_cfg_mhdr));
11574 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
11575 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
11576 length, LPFC_SLI4_MBX_EMBED);
11577 if (!phba->sli4_hba.intr_enable)
11578 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040011579 else {
11580 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
11581 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
11582 }
James Smartfedd3b72011-02-16 12:39:24 -050011583 if (unlikely(rc))
11584 return rc;
11585 sli4_params = &phba->sli4_hba.pc_sli4_params;
11586 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
11587 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
11588 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
11589 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
11590 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
11591 mbx_sli4_parameters);
11592 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
11593 mbx_sli4_parameters);
11594 if (bf_get(cfg_phwq, mbx_sli4_parameters))
11595 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
11596 else
11597 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
11598 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
11599 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050011600 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011601 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
11602 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
11603 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
11604 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080011605 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
11606 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040011607 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070011608 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011609 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
11610 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080011611 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050011612 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
11613 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040011614 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
11615 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080011616
James Smartc15e0702019-05-21 17:49:02 -070011617 /* Check for firmware nvme support */
11618 rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
11619 bf_get(cfg_xib, mbx_sli4_parameters));
James Smart895427b2017-02-12 13:52:30 -080011620
James Smartc15e0702019-05-21 17:49:02 -070011621 if (rc) {
11622 /* Save this to indicate the Firmware supports NVME */
11623 sli4_params->nvme = 1;
11624
11625 /* Firmware NVME support, check driver FC4 NVME support */
11626 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
11627 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
11628 "6133 Disabling NVME support: "
11629 "FC4 type not supported: x%x\n",
11630 phba->cfg_enable_fc4_type);
11631 goto fcponly;
11632 }
11633 } else {
11634 /* No firmware NVME support, check driver FC4 NVME support */
11635 sli4_params->nvme = 0;
11636 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
11638 "6101 Disabling NVME support: Not "
11639 "supported by firmware (%d %d) x%x\n",
11640 bf_get(cfg_nvme, mbx_sli4_parameters),
11641 bf_get(cfg_xib, mbx_sli4_parameters),
11642 phba->cfg_enable_fc4_type);
11643fcponly:
11644 phba->nvme_support = 0;
11645 phba->nvmet_support = 0;
11646 phba->cfg_nvmet_mrq = 0;
11647
11648 /* If no FC4 type support, move to just SCSI support */
11649 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
11650 return -ENODEV;
11651 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
11652 }
James Smart895427b2017-02-12 13:52:30 -080011653 }
James Smart05580562011-05-24 11:40:48 -040011654
James Smart414abe02018-06-26 08:24:26 -070011655 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
11656 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
11657 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
11658 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080011659
James Smart20aefac2018-01-30 15:58:58 -080011660 /*
11661 * To support Suppress Response feature we must satisfy 3 conditions.
11662 * lpfc_suppress_rsp module parameter must be set (default).
11663 * In SLI4-Parameters Descriptor:
11664 * Extended Inline Buffers (XIB) must be supported.
11665 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
11666 * (double negative).
11667 */
11668 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
11669 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080011670 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080011671 else
11672 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080011673
James Smart0cf07f842017-06-01 21:07:10 -070011674 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
11675 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
11676
James Smart05580562011-05-24 11:40:48 -040011677 /* Make sure that sge_supp_len can be handled by the driver */
11678 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
11679 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
11680
James Smartb5c53952016-03-31 14:12:30 -070011681 /*
James Smartc176ffa2018-01-30 15:58:46 -080011682 * Check whether the adapter supports an embedded copy of the
11683 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
11684 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070011685 */
11686 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
11687 phba->fcp_embed_io = 1;
11688 else
11689 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070011690
James Smart0bc2b7c2018-02-22 08:18:48 -080011691 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070011692 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080011693 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070011694 phba->cfg_enable_pbde,
11695 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080011696 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080011697
James Smartbf316c72018-04-09 14:24:28 -070011698 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
11699 LPFC_SLI_INTF_IF_TYPE_2) &&
11700 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070011701 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070011702 exp_wqcq_pages = false;
11703
James Smartc176ffa2018-01-30 15:58:46 -080011704 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
11705 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070011706 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080011707 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
11708 phba->enab_exp_wqcq_pages = 1;
11709 else
11710 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070011711 /*
11712 * Check if the SLI port supports MDS Diagnostics
11713 */
11714 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
11715 phba->mds_diags_support = 1;
11716 else
11717 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070011718
James Smartfedd3b72011-02-16 12:39:24 -050011719 return 0;
11720}
11721
11722/**
James Smart3772a992009-05-22 14:50:54 -040011723 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
11724 * @pdev: pointer to PCI device
11725 * @pid: pointer to PCI device identifier
11726 *
11727 * This routine is to be called to attach a device with SLI-3 interface spec
11728 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11729 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11730 * information of the device and driver to see if the driver state that it can
11731 * support this kind of device. If the match is successful, the driver core
11732 * invokes this routine. If this routine determines it can claim the HBA, it
11733 * does all the initialization that it needs to do to handle the HBA properly.
11734 *
11735 * Return code
11736 * 0 - driver can claim the device
11737 * negative value - driver can not claim the device
11738 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011739static int
James Smart3772a992009-05-22 14:50:54 -040011740lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
11741{
11742 struct lpfc_hba *phba;
11743 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011744 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040011745 int error;
11746 uint32_t cfg_mode, intr_mode;
11747
11748 /* Allocate memory for HBA structure */
11749 phba = lpfc_hba_alloc(pdev);
11750 if (!phba)
11751 return -ENOMEM;
11752
11753 /* Perform generic PCI device enabling operation */
11754 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011755 if (error)
James Smart3772a992009-05-22 14:50:54 -040011756 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040011757
11758 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
11759 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
11760 if (error)
11761 goto out_disable_pci_dev;
11762
11763 /* Set up SLI-3 specific device PCI memory space */
11764 error = lpfc_sli_pci_mem_setup(phba);
11765 if (error) {
11766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11767 "1402 Failed to set up pci memory space.\n");
11768 goto out_disable_pci_dev;
11769 }
11770
James Smart3772a992009-05-22 14:50:54 -040011771 /* Set up SLI-3 specific device driver resources */
11772 error = lpfc_sli_driver_resource_setup(phba);
11773 if (error) {
11774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11775 "1404 Failed to set up driver resource.\n");
11776 goto out_unset_pci_mem_s3;
11777 }
11778
11779 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070011780
James Smart3772a992009-05-22 14:50:54 -040011781 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
11782 if (error) {
11783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11784 "1405 Failed to initialize iocb list.\n");
11785 goto out_unset_driver_resource_s3;
11786 }
11787
11788 /* Set up common device driver resources */
11789 error = lpfc_setup_driver_resource_phase2(phba);
11790 if (error) {
11791 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11792 "1406 Failed to set up driver resource.\n");
11793 goto out_free_iocb_list;
11794 }
11795
James Smart079b5c92011-08-21 21:48:49 -040011796 /* Get the default values for Model Name and Description */
11797 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11798
James Smart3772a992009-05-22 14:50:54 -040011799 /* Create SCSI host to the physical port */
11800 error = lpfc_create_shost(phba);
11801 if (error) {
11802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11803 "1407 Failed to create scsi host.\n");
11804 goto out_unset_driver_resource;
11805 }
11806
11807 /* Configure sysfs attributes */
11808 vport = phba->pport;
11809 error = lpfc_alloc_sysfs_attr(vport);
11810 if (error) {
11811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11812 "1476 Failed to allocate sysfs attr\n");
11813 goto out_destroy_shost;
11814 }
11815
James Smart6669f9b2009-10-02 15:16:45 -040011816 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040011817 /* Now, trying to enable interrupt and bring up the device */
11818 cfg_mode = phba->cfg_use_msi;
11819 while (true) {
11820 /* Put device to a known state before enabling interrupt */
11821 lpfc_stop_port(phba);
11822 /* Configure and enable interrupt */
11823 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
11824 if (intr_mode == LPFC_INTR_ERROR) {
11825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11826 "0431 Failed to enable interrupt.\n");
11827 error = -ENODEV;
11828 goto out_free_sysfs_attr;
11829 }
11830 /* SLI-3 HBA setup */
11831 if (lpfc_sli_hba_setup(phba)) {
11832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11833 "1477 Failed to set up hba\n");
11834 error = -ENODEV;
11835 goto out_remove_device;
11836 }
11837
11838 /* Wait 50ms for the interrupts of previous mailbox commands */
11839 msleep(50);
11840 /* Check active interrupts on message signaled interrupts */
11841 if (intr_mode == 0 ||
11842 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
11843 /* Log the current active interrupt mode */
11844 phba->intr_mode = intr_mode;
11845 lpfc_log_intr_mode(phba, intr_mode);
11846 break;
11847 } else {
11848 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11849 "0447 Configure interrupt mode (%d) "
11850 "failed active interrupt test.\n",
11851 intr_mode);
11852 /* Disable the current interrupt mode */
11853 lpfc_sli_disable_intr(phba);
11854 /* Try next level of interrupt mode */
11855 cfg_mode = --intr_mode;
11856 }
11857 }
11858
11859 /* Perform post initialization setup */
11860 lpfc_post_init_setup(phba);
11861
11862 /* Check if there are static vports to be created. */
11863 lpfc_create_static_vport(phba);
11864
11865 return 0;
11866
11867out_remove_device:
11868 lpfc_unset_hba(phba);
11869out_free_sysfs_attr:
11870 lpfc_free_sysfs_attr(vport);
11871out_destroy_shost:
11872 lpfc_destroy_shost(phba);
11873out_unset_driver_resource:
11874 lpfc_unset_driver_resource_phase2(phba);
11875out_free_iocb_list:
11876 lpfc_free_iocb_list(phba);
11877out_unset_driver_resource_s3:
11878 lpfc_sli_driver_resource_unset(phba);
11879out_unset_pci_mem_s3:
11880 lpfc_sli_pci_mem_unset(phba);
11881out_disable_pci_dev:
11882 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011883 if (shost)
11884 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040011885out_free_phba:
11886 lpfc_hba_free(phba);
11887 return error;
11888}
11889
11890/**
11891 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040011892 * @pdev: pointer to PCI device
11893 *
James Smart3772a992009-05-22 14:50:54 -040011894 * This routine is to be called to disattach a device with SLI-3 interface
11895 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11896 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11897 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040011898 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011899static void
James Smart3772a992009-05-22 14:50:54 -040011900lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050011901{
James Smart2e0fef82007-06-17 19:56:36 -050011902 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11903 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050011904 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050011905 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050011906 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050011907
James Smart549e55c2007-08-02 11:09:51 -040011908 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040011909 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040011910 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050011911
James Smart858c9f62007-06-17 19:56:39 -050011912 lpfc_free_sysfs_attr(vport);
11913
James Smarteada2722008-12-04 22:39:13 -050011914 /* Release all the vports against this physical port */
11915 vports = lpfc_create_vport_work_array(phba);
11916 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011917 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11918 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11919 continue;
James Smarteada2722008-12-04 22:39:13 -050011920 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011921 }
James Smarteada2722008-12-04 22:39:13 -050011922 lpfc_destroy_vport_work_array(phba, vports);
11923
11924 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050011925 fc_remove_host(shost);
11926 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080011927
James Smart87af33f2007-10-27 13:37:43 -040011928 lpfc_cleanup(vport);
11929
James Smart2e0fef82007-06-17 19:56:36 -050011930 /*
11931 * Bring down the SLI Layer. This step disable all interrupts,
11932 * clears the rings, discards all mailbox commands, and resets
11933 * the HBA.
11934 */
James Smarta257bf92009-04-06 18:48:10 -040011935
Justin P. Mattock48e34d02010-12-30 15:07:58 -080011936 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050011937 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040011938 /* Stop kthread signal shall trigger work_done one more time */
11939 kthread_stop(phba->worker_thread);
11940 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050011941 lpfc_sli_brdrestart(phba);
11942
James Smart72859902012-01-18 16:25:38 -050011943 kfree(phba->vpi_bmask);
11944 kfree(phba->vpi_ids);
11945
James Smart3772a992009-05-22 14:50:54 -040011946 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011947 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011948 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011949 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011950
James Smart858c9f62007-06-17 19:56:39 -050011951 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050011952
James Smart912e3ac2011-05-24 11:42:11 -040011953 /* Disable SR-IOV if enabled */
11954 if (phba->cfg_sriov_nr_virtfn)
11955 pci_disable_sriov(pdev);
11956
James Smart5b75da22008-12-04 22:39:35 -050011957 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011958 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011959
James Smart858c9f62007-06-17 19:56:39 -050011960 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011961
11962 /*
11963 * Call scsi_free before mem_free since scsi bufs are released to their
11964 * corresponding pools here.
11965 */
11966 lpfc_scsi_free(phba);
James Smart0794d602019-01-28 11:14:19 -080011967 lpfc_free_iocb_list(phba);
11968
James Smart3772a992009-05-22 14:50:54 -040011969 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011970
James Smart34b02dc2008-08-24 21:49:55 -040011971 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11972 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011973
James Smart2e0fef82007-06-17 19:56:36 -050011974 /* Free resources associated with SLI2 interface */
11975 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011976 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011977
11978 /* unmap adapter SLIM and Control Registers */
11979 iounmap(phba->ctrl_regs_memmap_p);
11980 iounmap(phba->slim_memmap_p);
11981
James Smart3772a992009-05-22 14:50:54 -040011982 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011983
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011984 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011985 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011986}
11987
Linas Vepstas8d63f372007-02-14 14:28:36 -060011988/**
James Smart3772a992009-05-22 14:50:54 -040011989 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011990 * @pdev: pointer to PCI device
11991 * @msg: power management message
11992 *
James Smart3772a992009-05-22 14:50:54 -040011993 * This routine is to be called from the kernel's PCI subsystem to support
11994 * system Power Management (PM) to device with SLI-3 interface spec. When
11995 * PM invokes this method, it quiesces the device by stopping the driver's
11996 * worker thread for the device, turning off device's interrupt and DMA,
11997 * and bring the device offline. Note that as the driver implements the
11998 * minimum PM requirements to a power-aware driver's PM support for the
11999 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12000 * to the suspend() method call will be treated as SUSPEND and the driver will
12001 * fully reinitialize its device during resume() method call, the driver will
12002 * set device to PCI_D3hot state in PCI config space instead of setting it
12003 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050012004 *
12005 * Return code
James Smart3772a992009-05-22 14:50:54 -040012006 * 0 - driver suspended the device
12007 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012008 **/
12009static int
James Smart3772a992009-05-22 14:50:54 -040012010lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050012011{
12012 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12013 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12014
12015 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12016 "0473 PCI device Power Management suspend.\n");
12017
12018 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012019 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050012020 lpfc_offline(phba);
12021 kthread_stop(phba->worker_thread);
12022
12023 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040012024 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050012025
12026 /* Save device state to PCI config space */
12027 pci_save_state(pdev);
12028 pci_set_power_state(pdev, PCI_D3hot);
12029
12030 return 0;
12031}
12032
12033/**
James Smart3772a992009-05-22 14:50:54 -040012034 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050012035 * @pdev: pointer to PCI device
12036 *
James Smart3772a992009-05-22 14:50:54 -040012037 * This routine is to be called from the kernel's PCI subsystem to support
12038 * system Power Management (PM) to device with SLI-3 interface spec. When PM
12039 * invokes this method, it restores the device's PCI config space state and
12040 * fully reinitializes the device and brings it online. Note that as the
12041 * driver implements the minimum PM requirements to a power-aware driver's
12042 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
12043 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
12044 * driver will fully reinitialize its device during resume() method call,
12045 * the device will be set to PCI_D0 directly in PCI config space before
12046 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050012047 *
12048 * Return code
James Smart3772a992009-05-22 14:50:54 -040012049 * 0 - driver suspended the device
12050 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050012051 **/
12052static int
James Smart3772a992009-05-22 14:50:54 -040012053lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050012054{
12055 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12056 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050012057 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012058 int error;
12059
12060 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12061 "0452 PCI device Power Management resume.\n");
12062
12063 /* Restore device state from PCI config space */
12064 pci_set_power_state(pdev, PCI_D0);
12065 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040012066
James Smart1dfb5a42010-02-12 14:40:50 -050012067 /*
12068 * As the new kernel behavior of pci_restore_state() API call clears
12069 * device saved_state flag, need to save the restored state again.
12070 */
12071 pci_save_state(pdev);
12072
James Smart3a55b532008-12-04 22:38:54 -050012073 if (pdev->is_busmaster)
12074 pci_set_master(pdev);
12075
12076 /* Startup the kernel thread for this host adapter. */
12077 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12078 "lpfc_worker_%d", phba->brd_no);
12079 if (IS_ERR(phba->worker_thread)) {
12080 error = PTR_ERR(phba->worker_thread);
12081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12082 "0434 PM resume failed to start worker "
12083 "thread: error=x%x.\n", error);
12084 return error;
12085 }
12086
James Smart5b75da22008-12-04 22:39:35 -050012087 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012088 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012089 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050012090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050012091 "0430 PM resume Failed to enable interrupt\n");
12092 return -EIO;
12093 } else
12094 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050012095
12096 /* Restart HBA and bring it online */
12097 lpfc_sli_brdrestart(phba);
12098 lpfc_online(phba);
12099
James Smart5b75da22008-12-04 22:39:35 -050012100 /* Log the current active interrupt mode */
12101 lpfc_log_intr_mode(phba, phba->intr_mode);
12102
James Smart3a55b532008-12-04 22:38:54 -050012103 return 0;
12104}
12105
12106/**
James Smart891478a2009-11-18 15:40:23 -050012107 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
12108 * @phba: pointer to lpfc hba data structure.
12109 *
12110 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040012111 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050012112 **/
12113static void
12114lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
12115{
12116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12117 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040012118
12119 /*
12120 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12121 * and let the SCSI mid-layer to retry them to recover.
12122 */
James Smartdb55fba2014-04-04 13:52:02 -040012123 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050012124}
12125
12126/**
James Smart0d878412009-10-02 15:16:56 -040012127 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
12128 * @phba: pointer to lpfc hba data structure.
12129 *
12130 * This routine is called to prepare the SLI3 device for PCI slot reset. It
12131 * disables the device interrupt and pci device, and aborts the internal FCP
12132 * pending I/Os.
12133 **/
12134static void
12135lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
12136{
James Smart0d878412009-10-02 15:16:56 -040012137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050012138 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040012139
James Smart75baf692010-06-08 18:31:21 -040012140 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012141 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012142
James Smarte2af0d22010-03-15 11:25:32 -040012143 /* Block all SCSI devices' I/Os on the host */
12144 lpfc_scsi_dev_block(phba);
12145
James Smartea714f32013-04-17 20:18:47 -040012146 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12147 lpfc_sli_flush_fcp_rings(phba);
12148
James Smarte2af0d22010-03-15 11:25:32 -040012149 /* stop all timers */
12150 lpfc_stop_hba_timers(phba);
12151
James Smart0d878412009-10-02 15:16:56 -040012152 /* Disable interrupt and pci device */
12153 lpfc_sli_disable_intr(phba);
12154 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040012155}
12156
12157/**
12158 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
12159 * @phba: pointer to lpfc hba data structure.
12160 *
12161 * This routine is called to prepare the SLI3 device for PCI slot permanently
12162 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12163 * pending I/Os.
12164 **/
12165static void
James Smart75baf692010-06-08 18:31:21 -040012166lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040012167{
12168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050012169 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040012170 /* Block all SCSI devices' I/Os on the host */
12171 lpfc_scsi_dev_block(phba);
12172
12173 /* stop all timers */
12174 lpfc_stop_hba_timers(phba);
12175
James Smart0d878412009-10-02 15:16:56 -040012176 /* Clean up all driver's outstanding SCSI I/Os */
12177 lpfc_sli_flush_fcp_rings(phba);
12178}
12179
12180/**
James Smart3772a992009-05-22 14:50:54 -040012181 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040012182 * @pdev: pointer to PCI device.
12183 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012184 *
James Smart3772a992009-05-22 14:50:54 -040012185 * This routine is called from the PCI subsystem for I/O error handling to
12186 * device with SLI-3 interface spec. This function is called by the PCI
12187 * subsystem after a PCI bus error affecting this device has been detected.
12188 * When this function is invoked, it will need to stop all the I/Os and
12189 * interrupt(s) to the device. Once that is done, it will return
12190 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
12191 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040012192 *
12193 * Return codes
James Smart0d878412009-10-02 15:16:56 -040012194 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040012195 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12196 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040012197 **/
James Smart3772a992009-05-22 14:50:54 -040012198static pci_ers_result_t
12199lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012200{
James Smart51ef4c22007-08-02 11:10:31 -040012201 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12202 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012203
James Smart0d878412009-10-02 15:16:56 -040012204 switch (state) {
12205 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050012206 /* Non-fatal error, prepare for recovery */
12207 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040012208 return PCI_ERS_RESULT_CAN_RECOVER;
12209 case pci_channel_io_frozen:
12210 /* Fatal error, prepare for slot reset */
12211 lpfc_sli_prep_dev_for_reset(phba);
12212 return PCI_ERS_RESULT_NEED_RESET;
12213 case pci_channel_io_perm_failure:
12214 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040012215 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012216 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040012217 default:
12218 /* Unknown state, prepare and request slot reset */
12219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12220 "0472 Unknown PCI error state: x%x\n", state);
12221 lpfc_sli_prep_dev_for_reset(phba);
12222 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040012223 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060012224}
12225
12226/**
James Smart3772a992009-05-22 14:50:54 -040012227 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040012228 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012229 *
James Smart3772a992009-05-22 14:50:54 -040012230 * This routine is called from the PCI subsystem for error handling to
12231 * device with SLI-3 interface spec. This is called after PCI bus has been
12232 * reset to restart the PCI card from scratch, as if from a cold-boot.
12233 * During the PCI subsystem error recovery, after driver returns
12234 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12235 * recovery and then call this routine before calling the .resume method
12236 * to recover the device. This function will initialize the HBA device,
12237 * enable the interrupt, but it will just put the HBA to offline state
12238 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040012239 *
12240 * Return codes
James Smart3772a992009-05-22 14:50:54 -040012241 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12242 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060012243 */
James Smart3772a992009-05-22 14:50:54 -040012244static pci_ers_result_t
12245lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012246{
James Smart51ef4c22007-08-02 11:10:31 -040012247 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12248 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012249 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050012250 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012251
12252 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110012253 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012254 printk(KERN_ERR "lpfc: Cannot re-enable "
12255 "PCI device after reset.\n");
12256 return PCI_ERS_RESULT_DISCONNECT;
12257 }
12258
James Smart97207482008-12-04 22:39:19 -050012259 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012260
12261 /*
12262 * As the new kernel behavior of pci_restore_state() API call clears
12263 * device saved_state flag, need to save the restored state again.
12264 */
12265 pci_save_state(pdev);
12266
James Smart97207482008-12-04 22:39:19 -050012267 if (pdev->is_busmaster)
12268 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012269
James Smart92d7f7b2007-06-17 19:56:38 -050012270 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040012271 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050012272 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012273
James Smart5b75da22008-12-04 22:39:35 -050012274 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040012275 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050012276 if (intr_mode == LPFC_INTR_ERROR) {
12277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12278 "0427 Cannot re-enable interrupt after "
12279 "slot reset.\n");
12280 return PCI_ERS_RESULT_DISCONNECT;
12281 } else
12282 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012283
James Smart75baf692010-06-08 18:31:21 -040012284 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040012285 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012286 lpfc_offline(phba);
12287 lpfc_sli_brdrestart(phba);
12288
James Smart5b75da22008-12-04 22:39:35 -050012289 /* Log the current active interrupt mode */
12290 lpfc_log_intr_mode(phba, phba->intr_mode);
12291
Linas Vepstas8d63f372007-02-14 14:28:36 -060012292 return PCI_ERS_RESULT_RECOVERED;
12293}
12294
12295/**
James Smart3772a992009-05-22 14:50:54 -040012296 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040012297 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060012298 *
James Smart3772a992009-05-22 14:50:54 -040012299 * This routine is called from the PCI subsystem for error handling to device
12300 * with SLI-3 interface spec. It is called when kernel error recovery tells
12301 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12302 * error recovery. After this call, traffic can start to flow from this device
12303 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060012304 */
James Smart3772a992009-05-22 14:50:54 -040012305static void
12306lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060012307{
James Smart51ef4c22007-08-02 11:10:31 -040012308 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12309 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060012310
James Smarte2af0d22010-03-15 11:25:32 -040012311 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040012312 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060012313}
12314
James Smart3772a992009-05-22 14:50:54 -040012315/**
James Smartda0436e2009-05-22 14:51:39 -040012316 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
12317 * @phba: pointer to lpfc hba data structure.
12318 *
12319 * returns the number of ELS/CT IOCBs to reserve
12320 **/
12321int
12322lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
12323{
12324 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
12325
James Smartf1126682009-06-10 17:22:44 -040012326 if (phba->sli_rev == LPFC_SLI_REV4) {
12327 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040012328 return 10;
James Smartf1126682009-06-10 17:22:44 -040012329 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040012330 return 25;
James Smartf1126682009-06-10 17:22:44 -040012331 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040012332 return 50;
James Smartf1126682009-06-10 17:22:44 -040012333 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040012334 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040012335 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040012336 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040012337 else if (max_xri <= 2048)
12338 return 200;
12339 else
12340 return 250;
James Smartf1126682009-06-10 17:22:44 -040012341 } else
12342 return 0;
James Smartda0436e2009-05-22 14:51:39 -040012343}
12344
12345/**
James Smart895427b2017-02-12 13:52:30 -080012346 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
12347 * @phba: pointer to lpfc hba data structure.
12348 *
James Smartf358dd02017-02-12 13:52:34 -080012349 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080012350 **/
12351int
12352lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
12353{
12354 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
12355
James Smartf358dd02017-02-12 13:52:34 -080012356 if (phba->nvmet_support)
12357 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080012358 return max_xri;
12359}
12360
12361
James Smart1feb8202018-02-22 08:18:47 -080012362static void
12363lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
12364 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
12365 const struct firmware *fw)
12366{
James Smarta72d56b2018-05-04 20:37:52 -070012367 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
12368 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
12369 magic_number != MAGIC_NUMER_G6) ||
12370 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
12371 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080012372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12373 "3030 This firmware version is not supported on "
12374 "this HBA model. Device:%x Magic:%x Type:%x "
12375 "ID:%x Size %d %zd\n",
12376 phba->pcidev->device, magic_number, ftype, fid,
12377 fsize, fw->size);
12378 else
12379 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12380 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
12381 "ID:%x Size %d %zd\n",
12382 phba->pcidev->device, magic_number, ftype, fid,
12383 fsize, fw->size);
12384}
12385
12386
James Smart895427b2017-02-12 13:52:30 -080012387/**
James Smart52d52442011-05-24 11:42:45 -040012388 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040012389 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040012390 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040012391 *
James Smart52d52442011-05-24 11:42:45 -040012392 **/
James Smartce396282012-09-29 11:30:56 -040012393static void
12394lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040012395{
James Smartce396282012-09-29 11:30:56 -040012396 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050012397 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040012398 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040012399 struct list_head dma_buffer_list;
12400 int i, rc = 0;
12401 struct lpfc_dmabuf *dmabuf, *next;
12402 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070012403 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040012404
James Smartc71ab862012-10-31 14:44:33 -040012405 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040012406 if (!fw) {
12407 rc = -ENXIO;
12408 goto out;
12409 }
12410 image = (struct lpfc_grp_hdr *)fw->data;
12411
James Smart6b6ef5d2016-10-13 15:06:17 -070012412 magic_number = be32_to_cpu(image->magic_number);
12413 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080012414 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070012415 fsize = be32_to_cpu(image->size);
12416
James Smart52d52442011-05-24 11:42:45 -040012417 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040012418 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040012419 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040012420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040012421 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040012422 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040012423 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040012424 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
12425 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
12426 GFP_KERNEL);
12427 if (!dmabuf) {
12428 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040012429 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040012430 }
12431 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
12432 SLI4_PAGE_SIZE,
12433 &dmabuf->phys,
12434 GFP_KERNEL);
12435 if (!dmabuf->virt) {
12436 kfree(dmabuf);
12437 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040012438 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040012439 }
12440 list_add_tail(&dmabuf->list, &dma_buffer_list);
12441 }
12442 while (offset < fw->size) {
12443 temp_offset = offset;
12444 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040012445 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040012446 memcpy(dmabuf->virt,
12447 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040012448 fw->size - temp_offset);
12449 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040012450 break;
12451 }
James Smart52d52442011-05-24 11:42:45 -040012452 memcpy(dmabuf->virt, fw->data + temp_offset,
12453 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040012454 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040012455 }
12456 rc = lpfc_wr_object(phba, &dma_buffer_list,
12457 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080012458 if (rc) {
12459 lpfc_log_write_firmware_error(phba, offset,
12460 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040012461 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080012462 }
James Smart52d52442011-05-24 11:42:45 -040012463 }
12464 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080012465 } else
12466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12467 "3029 Skipped Firmware update, Current "
12468 "Version:%s New Version:%s\n",
12469 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040012470
12471release_out:
James Smart52d52442011-05-24 11:42:45 -040012472 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
12473 list_del(&dmabuf->list);
12474 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
12475 dmabuf->virt, dmabuf->phys);
12476 kfree(dmabuf);
12477 }
James Smartce396282012-09-29 11:30:56 -040012478 release_firmware(fw);
12479out:
12480 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040012481 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040012482 return;
James Smart52d52442011-05-24 11:42:45 -040012483}
12484
12485/**
James Smartc71ab862012-10-31 14:44:33 -040012486 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
12487 * @phba: pointer to lpfc hba data structure.
12488 *
12489 * This routine is called to perform Linux generic firmware upgrade on device
12490 * that supports such feature.
12491 **/
12492int
12493lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
12494{
12495 uint8_t file_name[ELX_MODEL_NAME_SIZE];
12496 int ret;
12497 const struct firmware *fw;
12498
12499 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080012500 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040012501 LPFC_SLI_INTF_IF_TYPE_2)
12502 return -EPERM;
12503
12504 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
12505
12506 if (fw_upgrade == INT_FW_UPGRADE) {
12507 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
12508 file_name, &phba->pcidev->dev,
12509 GFP_KERNEL, (void *)phba,
12510 lpfc_write_firmware);
12511 } else if (fw_upgrade == RUN_FW_UPGRADE) {
12512 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
12513 if (!ret)
12514 lpfc_write_firmware(fw, (void *)phba);
12515 } else {
12516 ret = -EINVAL;
12517 }
12518
12519 return ret;
12520}
12521
12522/**
James Smartda0436e2009-05-22 14:51:39 -040012523 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
12524 * @pdev: pointer to PCI device
12525 * @pid: pointer to PCI device identifier
12526 *
12527 * This routine is called from the kernel's PCI subsystem to device with
12528 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
12529 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
12530 * information of the device and driver to see if the driver state that it
12531 * can support this kind of device. If the match is successful, the driver
12532 * core invokes this routine. If this routine determines it can claim the HBA,
12533 * it does all the initialization that it needs to do to handle the HBA
12534 * properly.
12535 *
12536 * Return code
12537 * 0 - driver can claim the device
12538 * negative value - driver can not claim the device
12539 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012540static int
James Smartda0436e2009-05-22 14:51:39 -040012541lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
12542{
12543 struct lpfc_hba *phba;
12544 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040012545 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070012546 int error;
James Smartda0436e2009-05-22 14:51:39 -040012547 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040012548
12549 /* Allocate memory for HBA structure */
12550 phba = lpfc_hba_alloc(pdev);
12551 if (!phba)
12552 return -ENOMEM;
12553
12554 /* Perform generic PCI device enabling operation */
12555 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040012556 if (error)
James Smartda0436e2009-05-22 14:51:39 -040012557 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040012558
12559 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
12560 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
12561 if (error)
12562 goto out_disable_pci_dev;
12563
12564 /* Set up SLI-4 specific device PCI memory space */
12565 error = lpfc_sli4_pci_mem_setup(phba);
12566 if (error) {
12567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12568 "1410 Failed to set up pci memory space.\n");
12569 goto out_disable_pci_dev;
12570 }
12571
James Smartda0436e2009-05-22 14:51:39 -040012572 /* Set up SLI-4 Specific device driver resources */
12573 error = lpfc_sli4_driver_resource_setup(phba);
12574 if (error) {
12575 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12576 "1412 Failed to set up driver resource.\n");
12577 goto out_unset_pci_mem_s4;
12578 }
12579
James Smart19ca7602010-11-20 23:11:55 -050012580 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040012581 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050012582
James Smartda0436e2009-05-22 14:51:39 -040012583 /* Set up common device driver resources */
12584 error = lpfc_setup_driver_resource_phase2(phba);
12585 if (error) {
12586 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12587 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070012588 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040012589 }
12590
James Smart079b5c92011-08-21 21:48:49 -040012591 /* Get the default values for Model Name and Description */
12592 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
12593
James Smartda0436e2009-05-22 14:51:39 -040012594 /* Now, trying to enable interrupt and bring up the device */
12595 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040012596
James Smart7b15db32013-01-03 15:43:29 -050012597 /* Put device to a known state before enabling interrupt */
James Smartcdb42be2019-01-28 11:14:21 -080012598 phba->pport = NULL;
James Smart7b15db32013-01-03 15:43:29 -050012599 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080012600
James Smart7b15db32013-01-03 15:43:29 -050012601 /* Configure and enable interrupt */
12602 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
12603 if (intr_mode == LPFC_INTR_ERROR) {
12604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12605 "0426 Failed to enable interrupt.\n");
12606 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080012607 goto out_unset_driver_resource;
James Smartda0436e2009-05-22 14:51:39 -040012608 }
James Smart7b15db32013-01-03 15:43:29 -050012609 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080012610 if (phba->intr_type != MSIX) {
James Smart6a828b02019-01-28 11:14:31 -080012611 phba->cfg_irq_chann = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080012612 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart2d7dbc42017-02-12 13:52:35 -080012613 if (phba->nvmet_support)
12614 phba->cfg_nvmet_mrq = 1;
12615 }
James Smartcdb42be2019-01-28 11:14:21 -080012616 }
James Smart6a828b02019-01-28 11:14:31 -080012617 lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
James Smartcdb42be2019-01-28 11:14:21 -080012618
12619 /* Create SCSI host to the physical port */
12620 error = lpfc_create_shost(phba);
12621 if (error) {
12622 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12623 "1415 Failed to create scsi host.\n");
12624 goto out_disable_intr;
12625 }
12626 vport = phba->pport;
12627 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
12628
12629 /* Configure sysfs attributes */
12630 error = lpfc_alloc_sysfs_attr(vport);
12631 if (error) {
12632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12633 "1416 Failed to allocate sysfs attr\n");
12634 goto out_destroy_shost;
James Smart895427b2017-02-12 13:52:30 -080012635 }
12636
James Smart7b15db32013-01-03 15:43:29 -050012637 /* Set up SLI-4 HBA */
12638 if (lpfc_sli4_hba_setup(phba)) {
12639 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12640 "1421 Failed to set up hba\n");
12641 error = -ENODEV;
James Smartcdb42be2019-01-28 11:14:21 -080012642 goto out_free_sysfs_attr;
James Smart7b15db32013-01-03 15:43:29 -050012643 }
12644
12645 /* Log the current active interrupt mode */
12646 phba->intr_mode = intr_mode;
12647 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040012648
12649 /* Perform post initialization setup */
12650 lpfc_post_init_setup(phba);
12651
James Smart01649562017-02-12 13:52:32 -080012652 /* NVME support in FW earlier in the driver load corrects the
12653 * FC4 type making a check for nvme_support unnecessary.
12654 */
James Smart0794d602019-01-28 11:14:19 -080012655 if (phba->nvmet_support == 0) {
12656 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
12657 /* Create NVME binding with nvme_fc_transport. This
12658 * ensures the vport is initialized. If the localport
12659 * create fails, it should not unload the driver to
12660 * support field issues.
12661 */
12662 error = lpfc_nvme_create_localport(vport);
12663 if (error) {
12664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12665 "6004 NVME registration "
12666 "failed, error x%x\n",
12667 error);
12668 }
James Smart01649562017-02-12 13:52:32 -080012669 }
12670 }
James Smart895427b2017-02-12 13:52:30 -080012671
James Smartc71ab862012-10-31 14:44:33 -040012672 /* check for firmware upgrade or downgrade */
12673 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040012674 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040012675
James Smart1c6834a2009-07-19 10:01:26 -040012676 /* Check if there are static vports to be created. */
12677 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070012678
12679 /* Enable RAS FW log support */
12680 lpfc_sli4_ras_setup(phba);
12681
James Smartda0436e2009-05-22 14:51:39 -040012682 return 0;
12683
James Smartda0436e2009-05-22 14:51:39 -040012684out_free_sysfs_attr:
12685 lpfc_free_sysfs_attr(vport);
12686out_destroy_shost:
12687 lpfc_destroy_shost(phba);
James Smartcdb42be2019-01-28 11:14:21 -080012688out_disable_intr:
12689 lpfc_sli4_disable_intr(phba);
James Smartda0436e2009-05-22 14:51:39 -040012690out_unset_driver_resource:
12691 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040012692out_unset_driver_resource_s4:
12693 lpfc_sli4_driver_resource_unset(phba);
12694out_unset_pci_mem_s4:
12695 lpfc_sli4_pci_mem_unset(phba);
12696out_disable_pci_dev:
12697 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040012698 if (shost)
12699 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040012700out_free_phba:
12701 lpfc_hba_free(phba);
12702 return error;
12703}
12704
12705/**
12706 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
12707 * @pdev: pointer to PCI device
12708 *
12709 * This routine is called from the kernel's PCI subsystem to device with
12710 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
12711 * removed from PCI bus, it performs all the necessary cleanup for the HBA
12712 * device to be removed from the PCI subsystem properly.
12713 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012714static void
James Smartda0436e2009-05-22 14:51:39 -040012715lpfc_pci_remove_one_s4(struct pci_dev *pdev)
12716{
12717 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12718 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
12719 struct lpfc_vport **vports;
12720 struct lpfc_hba *phba = vport->phba;
12721 int i;
12722
12723 /* Mark the device unloading flag */
12724 spin_lock_irq(&phba->hbalock);
12725 vport->load_flag |= FC_UNLOADING;
12726 spin_unlock_irq(&phba->hbalock);
12727
12728 /* Free the HBA sysfs attributes */
12729 lpfc_free_sysfs_attr(vport);
12730
12731 /* Release all the vports against this physical port */
12732 vports = lpfc_create_vport_work_array(phba);
12733 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040012734 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
12735 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
12736 continue;
James Smartda0436e2009-05-22 14:51:39 -040012737 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040012738 }
James Smartda0436e2009-05-22 14:51:39 -040012739 lpfc_destroy_vport_work_array(phba, vports);
12740
12741 /* Remove FC host and then SCSI host with the physical port */
12742 fc_remove_host(shost);
12743 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040012744
James Smartda0436e2009-05-22 14:51:39 -040012745 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
12746 * localports are destroyed after to cleanup all transport memory.
12747 */
12748 lpfc_cleanup(vport);
12749 lpfc_nvmet_destroy_targetport(phba);
12750 lpfc_nvme_destroy_localport(vport);
12751
James Smartc4908502019-01-28 11:14:28 -080012752 /* De-allocate multi-XRI pools */
12753 if (phba->cfg_xri_rebalancing)
12754 lpfc_destroy_multixri_pools(phba);
12755
James Smart281d6192018-01-30 15:58:47 -080012756 /*
12757 * Bring down the SLI Layer. This step disables all interrupts,
12758 * clears the rings, discards all mailbox commands, and resets
12759 * the HBA FCoE function.
12760 */
12761 lpfc_debugfs_terminate(vport);
James Smartda0436e2009-05-22 14:51:39 -040012762
Dick Kennedy19017622017-09-29 17:34:27 -070012763 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070012764 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040012765 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070012766 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040012767
James Smart3677a3a2010-09-29 11:19:14 -040012768 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040012769 * buffers are released to their corresponding pools here.
12770 */
James Smart5e5b5112019-01-28 11:14:22 -080012771 lpfc_io_free(phba);
James Smart01649562017-02-12 13:52:32 -080012772 lpfc_free_iocb_list(phba);
James Smart5e5b5112019-01-28 11:14:22 -080012773 lpfc_sli4_hba_unset(phba);
James Smart67d12732012-08-03 12:36:13 -040012774
James Smart0cdb84e2018-04-09 14:24:26 -070012775 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040012776 lpfc_sli4_driver_resource_unset(phba);
12777
12778 /* Unmap adapter Control and Doorbell registers */
12779 lpfc_sli4_pci_mem_unset(phba);
12780
12781 /* Release PCI resources and disable device's PCI function */
12782 scsi_host_put(shost);
12783 lpfc_disable_pci_dev(phba);
12784
12785 /* Finally, free the driver's device data structure */
12786 lpfc_hba_free(phba);
12787
12788 return;
12789}
12790
12791/**
12792 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
12793 * @pdev: pointer to PCI device
12794 * @msg: power management message
12795 *
12796 * This routine is called from the kernel's PCI subsystem to support system
12797 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
12798 * this method, it quiesces the device by stopping the driver's worker
12799 * thread for the device, turning off device's interrupt and DMA, and bring
12800 * the device offline. Note that as the driver implements the minimum PM
12801 * requirements to a power-aware driver's PM support for suspend/resume -- all
12802 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
12803 * method call will be treated as SUSPEND and the driver will fully
12804 * reinitialize its device during resume() method call, the driver will set
12805 * device to PCI_D3hot state in PCI config space instead of setting it
12806 * according to the @msg provided by the PM.
12807 *
12808 * Return code
12809 * 0 - driver suspended the device
12810 * Error otherwise
12811 **/
12812static int
12813lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
12814{
12815 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12816 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12817
12818 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040012819 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040012820
12821 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012822 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040012823 lpfc_offline(phba);
12824 kthread_stop(phba->worker_thread);
12825
12826 /* Disable interrupt from device */
12827 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012828 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040012829
12830 /* Save device state to PCI config space */
12831 pci_save_state(pdev);
12832 pci_set_power_state(pdev, PCI_D3hot);
12833
12834 return 0;
12835}
12836
12837/**
12838 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
12839 * @pdev: pointer to PCI device
12840 *
12841 * This routine is called from the kernel's PCI subsystem to support system
12842 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
12843 * this method, it restores the device's PCI config space state and fully
12844 * reinitializes the device and brings it online. Note that as the driver
12845 * implements the minimum PM requirements to a power-aware driver's PM for
12846 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12847 * to the suspend() method call will be treated as SUSPEND and the driver
12848 * will fully reinitialize its device during resume() method call, the device
12849 * will be set to PCI_D0 directly in PCI config space before restoring the
12850 * state.
12851 *
12852 * Return code
12853 * 0 - driver suspended the device
12854 * Error otherwise
12855 **/
12856static int
12857lpfc_pci_resume_one_s4(struct pci_dev *pdev)
12858{
12859 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12860 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12861 uint32_t intr_mode;
12862 int error;
12863
12864 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12865 "0292 PCI device Power Management resume.\n");
12866
12867 /* Restore device state from PCI config space */
12868 pci_set_power_state(pdev, PCI_D0);
12869 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012870
12871 /*
12872 * As the new kernel behavior of pci_restore_state() API call clears
12873 * device saved_state flag, need to save the restored state again.
12874 */
12875 pci_save_state(pdev);
12876
James Smartda0436e2009-05-22 14:51:39 -040012877 if (pdev->is_busmaster)
12878 pci_set_master(pdev);
12879
12880 /* Startup the kernel thread for this host adapter. */
12881 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12882 "lpfc_worker_%d", phba->brd_no);
12883 if (IS_ERR(phba->worker_thread)) {
12884 error = PTR_ERR(phba->worker_thread);
12885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12886 "0293 PM resume failed to start worker "
12887 "thread: error=x%x.\n", error);
12888 return error;
12889 }
12890
12891 /* Configure and enable interrupt */
12892 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12893 if (intr_mode == LPFC_INTR_ERROR) {
12894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12895 "0294 PM resume Failed to enable interrupt\n");
12896 return -EIO;
12897 } else
12898 phba->intr_mode = intr_mode;
12899
12900 /* Restart HBA and bring it online */
12901 lpfc_sli_brdrestart(phba);
12902 lpfc_online(phba);
12903
12904 /* Log the current active interrupt mode */
12905 lpfc_log_intr_mode(phba, phba->intr_mode);
12906
12907 return 0;
12908}
12909
12910/**
James Smart75baf692010-06-08 18:31:21 -040012911 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
12912 * @phba: pointer to lpfc hba data structure.
12913 *
12914 * This routine is called to prepare the SLI4 device for PCI slot recover. It
12915 * aborts all the outstanding SCSI I/Os to the pci device.
12916 **/
12917static void
12918lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
12919{
James Smart75baf692010-06-08 18:31:21 -040012920 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12921 "2828 PCI channel I/O abort preparing for recovery\n");
12922 /*
12923 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12924 * and let the SCSI mid-layer to retry them to recover.
12925 */
James Smartdb55fba2014-04-04 13:52:02 -040012926 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012927}
12928
12929/**
12930 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
12931 * @phba: pointer to lpfc hba data structure.
12932 *
12933 * This routine is called to prepare the SLI4 device for PCI slot reset. It
12934 * disables the device interrupt and pci device, and aborts the internal FCP
12935 * pending I/Os.
12936 **/
12937static void
12938lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
12939{
12940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12941 "2826 PCI channel disable preparing for reset\n");
12942
12943 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012944 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012945
12946 /* Block all SCSI devices' I/Os on the host */
12947 lpfc_scsi_dev_block(phba);
12948
James Smartea714f32013-04-17 20:18:47 -040012949 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12950 lpfc_sli_flush_fcp_rings(phba);
12951
James Smartc3725bd2017-11-20 16:00:42 -080012952 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12953 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12954 lpfc_sli_flush_nvme_rings(phba);
12955
James Smart75baf692010-06-08 18:31:21 -040012956 /* stop all timers */
12957 lpfc_stop_hba_timers(phba);
12958
12959 /* Disable interrupt and pci device */
12960 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012961 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012962 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012963}
12964
12965/**
12966 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12967 * @phba: pointer to lpfc hba data structure.
12968 *
12969 * This routine is called to prepare the SLI4 device for PCI slot permanently
12970 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12971 * pending I/Os.
12972 **/
12973static void
12974lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12975{
12976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12977 "2827 PCI channel permanent disable for failure\n");
12978
12979 /* Block all SCSI devices' I/Os on the host */
12980 lpfc_scsi_dev_block(phba);
12981
12982 /* stop all timers */
12983 lpfc_stop_hba_timers(phba);
12984
12985 /* Clean up all driver's outstanding SCSI I/Os */
12986 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012987
12988 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12989 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12990 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012991}
12992
12993/**
James Smartda0436e2009-05-22 14:51:39 -040012994 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12995 * @pdev: pointer to PCI device.
12996 * @state: the current PCI connection state.
12997 *
12998 * This routine is called from the PCI subsystem for error handling to device
12999 * with SLI-4 interface spec. This function is called by the PCI subsystem
13000 * after a PCI bus error affecting this device has been detected. When this
13001 * function is invoked, it will need to stop all the I/Os and interrupt(s)
13002 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
13003 * for the PCI subsystem to perform proper recovery as desired.
13004 *
13005 * Return codes
13006 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13007 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13008 **/
13009static pci_ers_result_t
13010lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
13011{
James Smart75baf692010-06-08 18:31:21 -040013012 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13013 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13014
13015 switch (state) {
13016 case pci_channel_io_normal:
13017 /* Non-fatal error, prepare for recovery */
13018 lpfc_sli4_prep_dev_for_recover(phba);
13019 return PCI_ERS_RESULT_CAN_RECOVER;
13020 case pci_channel_io_frozen:
13021 /* Fatal error, prepare for slot reset */
13022 lpfc_sli4_prep_dev_for_reset(phba);
13023 return PCI_ERS_RESULT_NEED_RESET;
13024 case pci_channel_io_perm_failure:
13025 /* Permanent failure, prepare for device down */
13026 lpfc_sli4_prep_dev_for_perm_failure(phba);
13027 return PCI_ERS_RESULT_DISCONNECT;
13028 default:
13029 /* Unknown state, prepare and request slot reset */
13030 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13031 "2825 Unknown PCI error state: x%x\n", state);
13032 lpfc_sli4_prep_dev_for_reset(phba);
13033 return PCI_ERS_RESULT_NEED_RESET;
13034 }
James Smartda0436e2009-05-22 14:51:39 -040013035}
13036
13037/**
13038 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
13039 * @pdev: pointer to PCI device.
13040 *
13041 * This routine is called from the PCI subsystem for error handling to device
13042 * with SLI-4 interface spec. It is called after PCI bus has been reset to
13043 * restart the PCI card from scratch, as if from a cold-boot. During the
13044 * PCI subsystem error recovery, after the driver returns
13045 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
13046 * recovery and then call this routine before calling the .resume method to
13047 * recover the device. This function will initialize the HBA device, enable
13048 * the interrupt, but it will just put the HBA to offline state without
13049 * passing any I/O traffic.
13050 *
13051 * Return codes
13052 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13053 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13054 */
13055static pci_ers_result_t
13056lpfc_io_slot_reset_s4(struct pci_dev *pdev)
13057{
James Smart75baf692010-06-08 18:31:21 -040013058 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13059 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13060 struct lpfc_sli *psli = &phba->sli;
13061 uint32_t intr_mode;
13062
13063 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
13064 if (pci_enable_device_mem(pdev)) {
13065 printk(KERN_ERR "lpfc: Cannot re-enable "
13066 "PCI device after reset.\n");
13067 return PCI_ERS_RESULT_DISCONNECT;
13068 }
13069
13070 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040013071
13072 /*
13073 * As the new kernel behavior of pci_restore_state() API call clears
13074 * device saved_state flag, need to save the restored state again.
13075 */
13076 pci_save_state(pdev);
13077
James Smart75baf692010-06-08 18:31:21 -040013078 if (pdev->is_busmaster)
13079 pci_set_master(pdev);
13080
13081 spin_lock_irq(&phba->hbalock);
13082 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
13083 spin_unlock_irq(&phba->hbalock);
13084
13085 /* Configure and enable interrupt */
13086 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
13087 if (intr_mode == LPFC_INTR_ERROR) {
13088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13089 "2824 Cannot re-enable interrupt after "
13090 "slot reset.\n");
13091 return PCI_ERS_RESULT_DISCONNECT;
13092 } else
13093 phba->intr_mode = intr_mode;
13094
13095 /* Log the current active interrupt mode */
13096 lpfc_log_intr_mode(phba, phba->intr_mode);
13097
James Smartda0436e2009-05-22 14:51:39 -040013098 return PCI_ERS_RESULT_RECOVERED;
13099}
13100
13101/**
13102 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
13103 * @pdev: pointer to PCI device
13104 *
13105 * This routine is called from the PCI subsystem for error handling to device
13106 * with SLI-4 interface spec. It is called when kernel error recovery tells
13107 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
13108 * error recovery. After this call, traffic can start to flow from this device
13109 * again.
13110 **/
13111static void
13112lpfc_io_resume_s4(struct pci_dev *pdev)
13113{
James Smart75baf692010-06-08 18:31:21 -040013114 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13116
13117 /*
13118 * In case of slot reset, as function reset is performed through
13119 * mailbox command which needs DMA to be enabled, this operation
13120 * has to be moved to the io resume phase. Taking device offline
13121 * will perform the necessary cleanup.
13122 */
13123 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
13124 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040013125 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040013126 lpfc_offline(phba);
13127 lpfc_sli_brdrestart(phba);
13128 /* Bring the device back online */
13129 lpfc_online(phba);
13130 }
James Smartda0436e2009-05-22 14:51:39 -040013131}
13132
13133/**
James Smart3772a992009-05-22 14:50:54 -040013134 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
13135 * @pdev: pointer to PCI device
13136 * @pid: pointer to PCI device identifier
13137 *
13138 * This routine is to be registered to the kernel's PCI subsystem. When an
13139 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
13140 * at PCI device-specific information of the device and driver to see if the
13141 * driver state that it can support this kind of device. If the match is
13142 * successful, the driver core invokes this routine. This routine dispatches
13143 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
13144 * do all the initialization that it needs to do to handle the HBA device
13145 * properly.
13146 *
13147 * Return code
13148 * 0 - driver can claim the device
13149 * negative value - driver can not claim the device
13150 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013151static int
James Smart3772a992009-05-22 14:50:54 -040013152lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
13153{
13154 int rc;
James Smart8fa38512009-07-19 10:01:03 -040013155 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040013156
James Smart28baac72010-02-12 14:42:03 -050013157 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040013158 return -ENODEV;
13159
James Smart8fa38512009-07-19 10:01:03 -040013160 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050013161 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040013162 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013163 else
James Smart3772a992009-05-22 14:50:54 -040013164 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040013165
James Smart3772a992009-05-22 14:50:54 -040013166 return rc;
13167}
13168
13169/**
13170 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
13171 * @pdev: pointer to PCI device
13172 *
13173 * This routine is to be registered to the kernel's PCI subsystem. When an
13174 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
13175 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
13176 * remove routine, which will perform all the necessary cleanup for the
13177 * device to be removed from the PCI subsystem properly.
13178 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013179static void
James Smart3772a992009-05-22 14:50:54 -040013180lpfc_pci_remove_one(struct pci_dev *pdev)
13181{
13182 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13183 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13184
13185 switch (phba->pci_dev_grp) {
13186 case LPFC_PCI_DEV_LP:
13187 lpfc_pci_remove_one_s3(pdev);
13188 break;
James Smartda0436e2009-05-22 14:51:39 -040013189 case LPFC_PCI_DEV_OC:
13190 lpfc_pci_remove_one_s4(pdev);
13191 break;
James Smart3772a992009-05-22 14:50:54 -040013192 default:
13193 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13194 "1424 Invalid PCI device group: 0x%x\n",
13195 phba->pci_dev_grp);
13196 break;
13197 }
13198 return;
13199}
13200
13201/**
13202 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
13203 * @pdev: pointer to PCI device
13204 * @msg: power management message
13205 *
13206 * This routine is to be registered to the kernel's PCI subsystem to support
13207 * system Power Management (PM). When PM invokes this method, it dispatches
13208 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
13209 * suspend the device.
13210 *
13211 * Return code
13212 * 0 - driver suspended the device
13213 * Error otherwise
13214 **/
13215static int
13216lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
13217{
13218 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13219 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13220 int rc = -ENODEV;
13221
13222 switch (phba->pci_dev_grp) {
13223 case LPFC_PCI_DEV_LP:
13224 rc = lpfc_pci_suspend_one_s3(pdev, msg);
13225 break;
James Smartda0436e2009-05-22 14:51:39 -040013226 case LPFC_PCI_DEV_OC:
13227 rc = lpfc_pci_suspend_one_s4(pdev, msg);
13228 break;
James Smart3772a992009-05-22 14:50:54 -040013229 default:
13230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13231 "1425 Invalid PCI device group: 0x%x\n",
13232 phba->pci_dev_grp);
13233 break;
13234 }
13235 return rc;
13236}
13237
13238/**
13239 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
13240 * @pdev: pointer to PCI device
13241 *
13242 * This routine is to be registered to the kernel's PCI subsystem to support
13243 * system Power Management (PM). When PM invokes this method, it dispatches
13244 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
13245 * resume the device.
13246 *
13247 * Return code
13248 * 0 - driver suspended the device
13249 * Error otherwise
13250 **/
13251static int
13252lpfc_pci_resume_one(struct pci_dev *pdev)
13253{
13254 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13255 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13256 int rc = -ENODEV;
13257
13258 switch (phba->pci_dev_grp) {
13259 case LPFC_PCI_DEV_LP:
13260 rc = lpfc_pci_resume_one_s3(pdev);
13261 break;
James Smartda0436e2009-05-22 14:51:39 -040013262 case LPFC_PCI_DEV_OC:
13263 rc = lpfc_pci_resume_one_s4(pdev);
13264 break;
James Smart3772a992009-05-22 14:50:54 -040013265 default:
13266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13267 "1426 Invalid PCI device group: 0x%x\n",
13268 phba->pci_dev_grp);
13269 break;
13270 }
13271 return rc;
13272}
13273
13274/**
13275 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
13276 * @pdev: pointer to PCI device.
13277 * @state: the current PCI connection state.
13278 *
13279 * This routine is registered to the PCI subsystem for error handling. This
13280 * function is called by the PCI subsystem after a PCI bus error affecting
13281 * this device has been detected. When this routine is invoked, it dispatches
13282 * the action to the proper SLI-3 or SLI-4 device error detected handling
13283 * routine, which will perform the proper error detected operation.
13284 *
13285 * Return codes
13286 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
13287 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13288 **/
13289static pci_ers_result_t
13290lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
13291{
13292 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13293 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13294 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13295
13296 switch (phba->pci_dev_grp) {
13297 case LPFC_PCI_DEV_LP:
13298 rc = lpfc_io_error_detected_s3(pdev, state);
13299 break;
James Smartda0436e2009-05-22 14:51:39 -040013300 case LPFC_PCI_DEV_OC:
13301 rc = lpfc_io_error_detected_s4(pdev, state);
13302 break;
James Smart3772a992009-05-22 14:50:54 -040013303 default:
13304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13305 "1427 Invalid PCI device group: 0x%x\n",
13306 phba->pci_dev_grp);
13307 break;
13308 }
13309 return rc;
13310}
13311
13312/**
13313 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
13314 * @pdev: pointer to PCI device.
13315 *
13316 * This routine is registered to the PCI subsystem for error handling. This
13317 * function is called after PCI bus has been reset to restart the PCI card
13318 * from scratch, as if from a cold-boot. When this routine is invoked, it
13319 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
13320 * routine, which will perform the proper device reset.
13321 *
13322 * Return codes
13323 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
13324 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
13325 **/
13326static pci_ers_result_t
13327lpfc_io_slot_reset(struct pci_dev *pdev)
13328{
13329 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13330 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13331 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
13332
13333 switch (phba->pci_dev_grp) {
13334 case LPFC_PCI_DEV_LP:
13335 rc = lpfc_io_slot_reset_s3(pdev);
13336 break;
James Smartda0436e2009-05-22 14:51:39 -040013337 case LPFC_PCI_DEV_OC:
13338 rc = lpfc_io_slot_reset_s4(pdev);
13339 break;
James Smart3772a992009-05-22 14:50:54 -040013340 default:
13341 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13342 "1428 Invalid PCI device group: 0x%x\n",
13343 phba->pci_dev_grp);
13344 break;
13345 }
13346 return rc;
13347}
13348
13349/**
13350 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
13351 * @pdev: pointer to PCI device
13352 *
13353 * This routine is registered to the PCI subsystem for error handling. It
13354 * is called when kernel error recovery tells the lpfc driver that it is
13355 * OK to resume normal PCI operation after PCI bus error recovery. When
13356 * this routine is invoked, it dispatches the action to the proper SLI-3
13357 * or SLI-4 device io_resume routine, which will resume the device operation.
13358 **/
13359static void
13360lpfc_io_resume(struct pci_dev *pdev)
13361{
13362 struct Scsi_Host *shost = pci_get_drvdata(pdev);
13363 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
13364
13365 switch (phba->pci_dev_grp) {
13366 case LPFC_PCI_DEV_LP:
13367 lpfc_io_resume_s3(pdev);
13368 break;
James Smartda0436e2009-05-22 14:51:39 -040013369 case LPFC_PCI_DEV_OC:
13370 lpfc_io_resume_s4(pdev);
13371 break;
James Smart3772a992009-05-22 14:50:54 -040013372 default:
13373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13374 "1429 Invalid PCI device group: 0x%x\n",
13375 phba->pci_dev_grp);
13376 break;
13377 }
13378 return;
13379}
13380
James Smart1ba981f2014-02-20 09:56:45 -050013381/**
13382 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
13383 * @phba: pointer to lpfc hba data structure.
13384 *
13385 * This routine checks to see if OAS is supported for this adapter. If
13386 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
13387 * the enable oas flag is cleared and the pool created for OAS device data
13388 * is destroyed.
13389 *
13390 **/
YueHaibingc7092972019-04-17 23:05:54 +080013391static void
James Smart1ba981f2014-02-20 09:56:45 -050013392lpfc_sli4_oas_verify(struct lpfc_hba *phba)
13393{
13394
13395 if (!phba->cfg_EnableXLane)
13396 return;
13397
13398 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
13399 phba->cfg_fof = 1;
13400 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040013401 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050013402 if (phba->device_data_mem_pool)
13403 mempool_destroy(phba->device_data_mem_pool);
13404 phba->device_data_mem_pool = NULL;
13405 }
13406
13407 return;
13408}
13409
13410/**
James Smartd2cc9bc2018-09-10 10:30:50 -070013411 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
13412 * @phba: pointer to lpfc hba data structure.
13413 *
13414 * This routine checks to see if RAS is supported by the adapter. Check the
13415 * function through which RAS support enablement is to be done.
13416 **/
13417void
13418lpfc_sli4_ras_init(struct lpfc_hba *phba)
13419{
13420 switch (phba->pcidev->device) {
13421 case PCI_DEVICE_ID_LANCER_G6_FC:
13422 case PCI_DEVICE_ID_LANCER_G7_FC:
13423 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080013424 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
13425 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070013426 phba->ras_fwlog.ras_enabled = true;
13427 else
13428 phba->ras_fwlog.ras_enabled = false;
13429 break;
13430 default:
13431 phba->ras_fwlog.ras_hwsupport = false;
13432 }
13433}
13434
James Smart1ba981f2014-02-20 09:56:45 -050013435
dea31012005-04-17 16:05:31 -050013436MODULE_DEVICE_TABLE(pci, lpfc_id_table);
13437
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070013438static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060013439 .error_detected = lpfc_io_error_detected,
13440 .slot_reset = lpfc_io_slot_reset,
13441 .resume = lpfc_io_resume,
13442};
13443
dea31012005-04-17 16:05:31 -050013444static struct pci_driver lpfc_driver = {
13445 .name = LPFC_DRIVER_NAME,
13446 .id_table = lpfc_id_table,
13447 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080013448 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110013449 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050013450 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040013451 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050013452 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050013453};
13454
James Smart3ef6d242012-01-18 16:23:48 -050013455static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040013456 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050013457};
13458
13459static struct miscdevice lpfc_mgmt_dev = {
13460 .minor = MISC_DYNAMIC_MINOR,
13461 .name = "lpfcmgmt",
13462 .fops = &lpfc_mgmt_fop,
13463};
13464
James Smarte59058c2008-08-24 21:49:00 -040013465/**
James Smart3621a712009-04-06 18:47:14 -040013466 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040013467 *
13468 * This routine is to be invoked when the lpfc module is loaded into the
13469 * kernel. The special kernel macro module_init() is used to indicate the
13470 * role of this routine to the kernel as lpfc module entry point.
13471 *
13472 * Return codes
13473 * 0 - successful
13474 * -ENOMEM - FC attach transport failed
13475 * all others - failed
13476 */
dea31012005-04-17 16:05:31 -050013477static int __init
13478lpfc_init(void)
13479{
13480 int error = 0;
13481
13482 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040013483 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050013484
James Smart3ef6d242012-01-18 16:23:48 -050013485 error = misc_register(&lpfc_mgmt_dev);
13486 if (error)
13487 printk(KERN_ERR "Could not register lpfcmgmt device, "
13488 "misc_register returned with status %d", error);
13489
James Smart458c0832016-07-06 12:36:07 -070013490 lpfc_transport_functions.vport_create = lpfc_vport_create;
13491 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050013492 lpfc_transport_template =
13493 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040013494 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050013495 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070013496 lpfc_vport_transport_template =
13497 fc_attach_transport(&lpfc_vport_transport_functions);
13498 if (lpfc_vport_transport_template == NULL) {
13499 fc_release_transport(lpfc_transport_template);
13500 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040013501 }
James Smart5fd11082018-03-05 12:04:04 -080013502 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080013503 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040013504
13505 /* Initialize in case vector mapping is needed */
James Smart2ea259e2017-02-12 13:52:27 -080013506 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040013507
dea31012005-04-17 16:05:31 -050013508 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050013509 if (error) {
dea31012005-04-17 16:05:31 -050013510 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070013511 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050013512 }
dea31012005-04-17 16:05:31 -050013513
13514 return error;
13515}
13516
James Smarte59058c2008-08-24 21:49:00 -040013517/**
James Smart3621a712009-04-06 18:47:14 -040013518 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040013519 *
13520 * This routine is invoked when the lpfc module is removed from the kernel.
13521 * The special kernel macro module_exit() is used to indicate the role of
13522 * this routine to the kernel as lpfc module exit point.
13523 */
dea31012005-04-17 16:05:31 -050013524static void __exit
13525lpfc_exit(void)
13526{
James Smart3ef6d242012-01-18 16:23:48 -050013527 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050013528 pci_unregister_driver(&lpfc_driver);
13529 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070013530 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050013531 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040013532 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
13533 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050013534 (1L << _dump_buf_data_order), _dump_buf_data);
13535 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
13536 }
13537
13538 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040013539 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
13540 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050013541 (1L << _dump_buf_dif_order), _dump_buf_dif);
13542 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
13543 }
Johannes Thumshirn79739672015-08-31 16:48:11 -040013544 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050013545}
13546
13547module_init(lpfc_init);
13548module_exit(lpfc_exit);
13549MODULE_LICENSE("GPL");
13550MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080013551MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050013552MODULE_VERSION("0:" LPFC_DRIVER_VERSION);